From 275d364df69412aaf07875937ae1dc02e28f0c20 Mon Sep 17 00:00:00 2001 From: Misha Bragin Date: Thu, 21 Jul 2022 21:07:38 +0100 Subject: [PATCH] Fix TURN credentials renewal (#394) Update conn config with new TURN credentials Updated Signal connection timeout to 5s --- client/internal/engine.go | 9 ++++++++- client/internal/peer/conn.go | 7 ++++++- signal/client/grpc.go | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/client/internal/engine.go b/client/internal/engine.go index 7e115286d..aa2316784 100644 --- a/client/internal/engine.go +++ b/client/internal/engine.go @@ -657,7 +657,7 @@ func (e *Engine) addNewPeer(peerConfig *mgmProto.RemotePeerConfig) error { return nil } -func (e Engine) connWorker(conn *peer.Conn, peerKey string) { +func (e *Engine) connWorker(conn *peer.Conn, peerKey string) { for { // randomize starting time a bit @@ -676,6 +676,13 @@ func (e Engine) connWorker(conn *peer.Conn, peerKey string) { continue } + // we might have received new STUN and TURN servers meanwhile, so update them + e.syncMsgMux.Lock() + conf := conn.GetConf() + conf.StunTurn = append(e.STUNs, e.TURNs...) + conn.UpdateConf(conf) + e.syncMsgMux.Unlock() + err := conn.Open() if err != nil { log.Debugf("connection to peer %s failed: %v", peerKey, err) diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index 8f4f050ec..a10d8cee3 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -75,6 +75,11 @@ func (conn *Conn) GetConf() ConnConfig { return conn.config } +// UpdateConf updates the connection config +func (conn *Conn) UpdateConf(conf ConnConfig) { + conn.config = conf +} + // NewConn creates a new not opened Conn to the remote peer. // To establish a connection run Conn.Open func NewConn(config ConnConfig, statusRecorder *nbStatus.Status) (*Conn, error) { @@ -415,7 +420,7 @@ func (conn *Conn) SetSignalCandidate(handler func(candidate ice.Candidate) error // and then signals them to the remote peer func (conn *Conn) onICECandidate(candidate ice.Candidate) { if candidate != nil { - // log.Debugf("discovered local candidate %s", candidate.String()) + log.Debugf("discovered local candidate %s", candidate.String()) go func() { err := conn.signalCandidate(candidate) if err != nil { diff --git a/signal/client/grpc.go b/signal/client/grpc.go index 5e23923e0..4a634ebaa 100644 --- a/signal/client/grpc.go +++ b/signal/client/grpc.go @@ -58,7 +58,7 @@ func NewClient(ctx context.Context, addr string, key wgtypes.Key, tlsEnabled boo transportOption = grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})) } - sigCtx, cancel := context.WithTimeout(ctx, time.Second*3) + sigCtx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() conn, err := grpc.DialContext( sigCtx,