Fix relay mode evaulation

This commit is contained in:
Zoltán Papp 2024-06-18 11:10:17 +02:00
parent deb8203f06
commit 5b86a7f3f2
5 changed files with 17 additions and 15 deletions

View File

@ -212,7 +212,7 @@ func NewEngineWithProbes(
clientCtx: clientCtx,
clientCancel: clientCancel,
signal: signalClient,
signaler: NewSignaler(signalClient, config.WgPrivateKey),
signaler: peer.NewSignaler(signalClient, config.WgPrivateKey),
mgmClient: mgmClient,
relayManager: relayManager,
peerConns: make(map[string]*peer.Conn),

View File

@ -152,7 +152,7 @@ func (conn *Conn) Open() {
log.Warnf("error while updating the state of peer %s,err: %v", conn.config.Key, err)
}
*/
relayIsSupportedLocally := conn.connectorRelay.RelayIsSupported()
relayIsSupportedLocally := conn.connectorRelay.RelayIsSupportedLocally()
if relayIsSupportedLocally {
go conn.connectorRelay.SetupRelayConnection()
}

View File

@ -97,16 +97,7 @@ func NewConnectorICE(ctx context.Context, log *log.Entry, config ConnConfig, con
// If the relay mode is supported then try to connect in p2p way only.
// It is trying to reconnection in a loop until the context is canceled.
// In case of success connection it will call the onICEConnReady callback.
func (conn *ConnectorICE) SetupICEConnection(relayMode bool) {
var preferredCandidateTypes []ice.CandidateType
if relayMode {
conn.connPriority = connPriorityICEP2P
preferredCandidateTypes = candidateTypesP2P()
} else {
conn.connPriority = connPriorityICETurn
preferredCandidateTypes = candidateTypes()
}
func (conn *ConnectorICE) SetupICEConnection(hasRelayOnLocally bool) {
for {
if !conn.waitForReconnectTry() {
return
@ -120,6 +111,15 @@ func (conn *ConnectorICE) SetupICEConnection(relayMode bool) {
continue
}
var preferredCandidateTypes []ice.CandidateType
if hasRelayOnLocally && remoteOfferAnswer.RelaySrvAddress != "" {
conn.connPriority = connPriorityICEP2P
preferredCandidateTypes = candidateTypesP2P()
} else {
conn.connPriority = connPriorityICETurn
preferredCandidateTypes = candidateTypes()
}
ctx, ctxCancel := context.WithCancel(conn.ctx)
agent, err := conn.reCreateAgent(ctxCancel, preferredCandidateTypes)
if err != nil {

View File

@ -78,6 +78,8 @@ func (conn *ConnectorRelay) SetupRelayConnection() {
rosenpassPubKey: remoteOfferAnswer.RosenpassPubKey,
rosenpassAddr: remoteOfferAnswer.RosenpassAddr,
})
// todo: waitForDisconnection()
}
}
@ -97,8 +99,8 @@ func (conn *ConnectorRelay) preferredRelayServer(myRelayAddress, remoteRelayAddr
return remoteRelayAddress
}
func (conn *ConnectorRelay) RelayIsSupported() bool {
return conn.relayManager.IsSupported()
func (conn *ConnectorRelay) RelayIsSupportedLocally() bool {
return conn.relayManager.HasRelayAddress()
}
// waitForReconnectTry waits for a random duration before trying to reconnect

View File

@ -108,7 +108,7 @@ func (m *Manager) RelayAddress() (net.Addr, error) {
return m.relayClient.RelayRemoteAddress()
}
func (m *Manager) IsSupported() bool {
func (m *Manager) HasRelayAddress() bool {
return m.srvAddress != ""
}