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