Skip to content

Commit

Permalink
Improve WireGuard handshake success rate
Browse files Browse the repository at this point in the history
The controller peer sends WireGuard
handshake requests only
  • Loading branch information
pappz committed Dec 20, 2024
1 parent ddc365f commit 9b1f403
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion client/internal/peer/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,18 @@ func (conn *Conn) listenGuardEvent(ctx context.Context) {
}

func (conn *Conn) configureWGEndpoint(addr *net.UDPAddr) error {
var endpoint *net.UDPAddr

// Force to only one side send handshake request to avoid the handshake congestion in WireGuard connection.
// Configure up the WireGuard endpoint only on the initiator side.
if isWireGuardInitiator(conn.config) {
endpoint = addr
}
return conn.config.WgConfig.WgInterface.UpdatePeer(
conn.config.WgConfig.RemoteKey,
conn.config.WgConfig.AllowedIps,
defaultWgKeepAlive,
addr,
endpoint,
conn.config.WgConfig.PreSharedKey,
)
}
Expand Down Expand Up @@ -756,6 +763,11 @@ func isController(config ConnConfig) bool {
return config.LocalKey > config.Key
}

// isWireGuardInitiator returns true if the local peer is the initiator of the WireGuard connection
func isWireGuardInitiator(config ConnConfig) bool {
return isController(config)
}

func isRosenpassEnabled(remoteRosenpassPubKey []byte) bool {
return remoteRosenpassPubKey != nil
}
Expand Down

0 comments on commit 9b1f403

Please sign in to comment.