mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-16 15:26:40 +00:00
fix: do Connection.Open() in goroutine to avoid blocking other peers
This commit is contained in:
@@ -82,7 +82,7 @@ func (conn *Connection) Open() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// create an ice Agent that will be responsible for negotiating and establishing actual peer-to-peer connection
|
||||
// create an ice.Agent that will be responsible for negotiating and establishing actual peer-to-peer connection
|
||||
conn.agent, err = ice.NewAgent(&ice.AgentConfig{
|
||||
NetworkTypes: []ice.NetworkType{ice.NetworkTypeUDP4},
|
||||
Urls: conn.Config.StunTurnURLS,
|
||||
@@ -193,8 +193,8 @@ func (conn *Connection) signalCredentials() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// listenOnLocalCandidates registers callback of an ICE Agent to new local connection candidates and
|
||||
// signal them to the remote peer
|
||||
// listenOnLocalCandidates registers callback of an ICE Agent to receive new local connection candidates and then
|
||||
// signals them to the remote peer
|
||||
func (conn *Connection) listenOnLocalCandidates() error {
|
||||
err := conn.agent.OnCandidate(func(candidate ice.Candidate) {
|
||||
if candidate != nil {
|
||||
@@ -238,8 +238,8 @@ func (conn *Connection) listenOnConnectionStateChanges() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// createWireguardProxy opens connection to the local Wireguard instance (proxy) and sets peer endpoint of Wireguard to point
|
||||
// to the local address of a proxy
|
||||
// createWireguardProxy opens connection to a local Wireguard instance (proxy) and sets Wireguard's peer endpoint to point
|
||||
// to a local address of a proxy
|
||||
func (conn *Connection) createWireguardProxy() (*net.Conn, error) {
|
||||
wgConn, err := net.Dial("udp", conn.Config.WgListenAddr)
|
||||
if err != nil {
|
||||
|
||||
@@ -89,11 +89,13 @@ func (e *Engine) Start(privateKey string, peers []string) error {
|
||||
conn := NewConnection(*connConfig, signalCandidate, signalOffer, signalAnswer)
|
||||
e.conns[myPubKey] = conn
|
||||
|
||||
err = conn.Open()
|
||||
if err != nil {
|
||||
log.Errorf("error openning connection to a remote peer %s %s", remoteKey.String(), err.Error())
|
||||
return err
|
||||
}
|
||||
go func() {
|
||||
err = conn.Open()
|
||||
if err != nil {
|
||||
log.Errorf("error openning connection to a remote peer %s %s", remoteKey.String(), err.Error())
|
||||
//todo
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user