diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index 65c9bf7b7..092356b3d 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -209,7 +209,7 @@ func (conn *Conn) Close() { conn.ctxCancel() if !conn.opened { - log.Infof("IGNORE close connection to peer") + log.Debugf("ignore close connection to peer") return } @@ -247,24 +247,7 @@ func (conn *Conn) Close() { conn.onDisconnected(conn.config.WgConfig.RemoteKey, conn.config.WgConfig.AllowedIps) } - conn.statusRelay = StatusDisconnected - conn.statusICE = StatusDisconnected - - peerState := State{ - PubKey: conn.config.Key, - ConnStatus: StatusDisconnected, - ConnStatusUpdate: time.Now(), - Mux: new(sync.RWMutex), - } - err = conn.statusRecorder.UpdatePeerState(peerState) - if err != nil { - // pretty common error because by that time Engine can already remove the peer and status won't be available. - // todo rethink status updates - conn.log.Debugf("error while updating peer's state, err: %v", err) - } - if err := conn.statusRecorder.UpdateWireGuardPeerState(conn.config.Key, iface.WGStats{}); err != nil { - conn.log.Debugf("failed to reset wireguard stats for peer: %s", err) - } + conn.setStatusToDisconnected() } // OnRemoteAnswer handles an offer from the remote peer and returns true if the message was accepted, false otherwise @@ -662,6 +645,27 @@ func (conn *Conn) updateIceState(iceConnInfo ICEConnInfo) { } } +func (conn *Conn) setStatusToDisconnected() { + conn.statusRelay = StatusDisconnected + conn.statusICE = StatusDisconnected + + peerState := State{ + PubKey: conn.config.Key, + ConnStatus: StatusDisconnected, + ConnStatusUpdate: time.Now(), + Mux: new(sync.RWMutex), + } + err := conn.statusRecorder.UpdatePeerState(peerState) + if err != nil { + // pretty common error because by that time Engine can already remove the peer and status won't be available. + // todo rethink status updates + conn.log.Debugf("error while updating peer's state, err: %v", err) + } + if err := conn.statusRecorder.UpdateWireGuardPeerState(conn.config.Key, iface.WGStats{}); err != nil { + conn.log.Debugf("failed to reset wireguard stats for peer: %s", err) + } +} + func (conn *Conn) doOnConnected(remoteRosenpassPubKey []byte, remoteRosenpassAddr string) { if runtime.GOOS == "ios" { runtime.GC()