From 9e7aac3a56d41532223d96506edee47652c8ab6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Papp?= Date: Mon, 7 Oct 2024 12:52:55 +0200 Subject: [PATCH] Reducate cognitive complexity --- client/internal/peer/conn.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index e6e863e88..50862c0c6 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -458,16 +458,7 @@ func (conn *Conn) iCEConnectionIsReady(priority ConnPriority, iceConnInfo ICECon } if err = conn.configureWGEndpoint(ep); err != nil { - conn.log.Warnf("Failed to update wg peer configuration: %v", err) - if wgProxy != nil { - if ierr := wgProxy.CloseConn(); ierr != nil { - conn.log.Warnf("Failed to close wg proxy: %v", ierr) - } - } - - if conn.wgProxyRelay != nil { - conn.wgProxyRelay.Work() - } + conn.handleConfigurationFailure(err, wgProxy) return } wgConfigWorkaround() @@ -810,6 +801,18 @@ func (conn *Conn) notifyReconnectLoopICEDisconnected(changed bool) { } } +func (conn *Conn) handleConfigurationFailure(err error, wgProxy wgproxy.Proxy) { + conn.log.Warnf("Failed to update wg peer configuration: %v", err) + if wgProxy != nil { + if ierr := wgProxy.CloseConn(); ierr != nil { + conn.log.Warnf("Failed to close wg proxy: %v", ierr) + } + } + if conn.wgProxyRelay != nil { + conn.wgProxyRelay.Work() + } +} + func isRosenpassEnabled(remoteRosenpassPubKey []byte) bool { return remoteRosenpassPubKey != nil }