diff --git a/connection/connection.go b/connection/connection.go index 1a4006349..ed019b0b5 100644 --- a/connection/connection.go +++ b/connection/connection.go @@ -34,9 +34,8 @@ type ConnConfig struct { } type IceCredentials struct { - uFrag string - pwd string - isControlling bool //todo think of better solution?? + uFrag string + pwd string } type Connection struct { @@ -57,8 +56,6 @@ type Connection struct { agent *ice.Agent wgConn net.Conn - // isActive indicates whether connection is active or not. - isActive bool connected *Cond closeCond *Cond @@ -81,7 +78,6 @@ func NewConnection(config ConnConfig, closeCond: NewCond(), connected: NewCond(), agent: nil, - isActive: false, } } @@ -128,7 +124,8 @@ func (conn *Connection) Open(timeout time.Duration) error { return err } - remoteConn, err := conn.openConnectionToRemote(remoteAuth.isControlling, remoteAuth) + isControlling := conn.Config.WgKey.PublicKey().String() > conn.Config.RemoteWgKey.String() + remoteConn, err := conn.openConnectionToRemote(isControlling, remoteAuth) if err != nil { log.Errorf("failed establishing connection with the remote peer %s %s", conn.Config.RemoteWgKey.String(), err) return err @@ -144,8 +141,6 @@ func (conn *Connection) Open(timeout time.Duration) error { go conn.proxyToLocalWireguard(*wgConn, remoteConn) log.Infof("opened connection to peer %s", conn.Config.RemoteWgKey.String()) - - conn.isActive = true case <-time.After(timeout): err := conn.Close() if err != nil { diff --git a/connection/engine.go b/connection/engine.go index f558eda6a..79ea07c1e 100644 --- a/connection/engine.go +++ b/connection/engine.go @@ -132,7 +132,7 @@ func (e *Engine) openPeerConnection(wgPort int, myKey wgtypes.Key, peer Peer) (* conn := NewConnection(*connConfig, signalCandidate, signalOffer, signalAnswer) e.conns[remoteKey.String()] = conn // blocks until the connection is open (or timeout) - err := conn.Open(20 * time.Second) + err := conn.Open(60 * time.Second) if err != nil { return nil, err } @@ -196,9 +196,8 @@ func (e *Engine) receiveSignal(localKey string) { return err } err = conn.OnOffer(IceCredentials{ - uFrag: remoteCred.UFrag, - pwd: remoteCred.Pwd, - isControlling: false, + uFrag: remoteCred.UFrag, + pwd: remoteCred.Pwd, }) if err != nil { @@ -212,9 +211,8 @@ func (e *Engine) receiveSignal(localKey string) { return err } err = conn.OnAnswer(IceCredentials{ - uFrag: remoteCred.UFrag, - pwd: remoteCred.Pwd, - isControlling: true, + uFrag: remoteCred.UFrag, + pwd: remoteCred.Pwd, }) if err != nil {