[relay-client] Fix Relay disconnection handling (#2680)

* Fix Relay disconnection handling

If has an active P2P connection meanwhile the Relay connection broken with the server then we removed the WireGuard peer configuration.

* Change logs
This commit is contained in:
Zoltan Papp 2024-10-01 16:22:18 +02:00 committed by GitHub
parent 24c0aaa745
commit ee0ea86a0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -586,13 +586,17 @@ func (conn *Conn) onWorkerRelayStateDisconnected() {
return return
} }
if conn.wgProxyRelay != nil { log.Debugf("relay connection is disconnected")
log.Debugf("relayed connection is closed, clean up WireGuard config")
if conn.currentConnPriority == connPriorityRelay {
log.Debugf("clean up WireGuard config")
err := conn.config.WgConfig.WgInterface.RemovePeer(conn.config.WgConfig.RemoteKey) err := conn.config.WgConfig.WgInterface.RemovePeer(conn.config.WgConfig.RemoteKey)
if err != nil { if err != nil {
conn.log.Errorf("failed to remove wg endpoint: %v", err) conn.log.Errorf("failed to remove wg endpoint: %v", err)
} }
}
if conn.wgProxyRelay != nil {
conn.endpointRelay = nil conn.endpointRelay = nil
_ = conn.wgProxyRelay.CloseConn() _ = conn.wgProxyRelay.CloseConn()
conn.wgProxyRelay = nil conn.wgProxyRelay = nil