From f22bb6dc7bab9b70293d854722db8869bb29bde7 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Thu, 30 Jan 2025 15:09:34 -0500 Subject: [PATCH 01/19] add connection as new dial option --- rpc/dial_options.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/rpc/dial_options.go b/rpc/dial_options.go index df847ebb..c29da6c6 100644 --- a/rpc/dial_options.go +++ b/rpc/dial_options.go @@ -64,6 +64,9 @@ type dialOptions struct { // interceptors unaryInterceptor grpc.UnaryClientInterceptor streamInterceptor grpc.StreamClientInterceptor + + // conn can be used to force the webrtcSignalingAnswerer to use a preexisting connection instead of dialing and managing its own. + conn ClientConn } // DialMulticastDNSOptions dictate any special settings to apply while dialing via mDNS. From 3a4a9d03d80a0a09dc5d99a785a0c930030dd221 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Thu, 30 Jan 2025 15:13:49 -0500 Subject: [PATCH 02/19] expose connection option --- rpc/dial_options.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/rpc/dial_options.go b/rpc/dial_options.go index c29da6c6..eeefe2a4 100644 --- a/rpc/dial_options.go +++ b/rpc/dial_options.go @@ -283,3 +283,10 @@ func WithForceDirectGRPC() DialOption { o.disableDirect = false }) } + +// WithConn provides a preexisting connection to use. This option forces the webrtcSignalingAnswerer to not dial or manage a connection +func WithConn(conn ClientConn) DialOption { + return newFuncDialOption(func(o *dialOptions) { + o.conn = conn + }) +} From 503332bdf9c32d4cb4844c87860144968269d611 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Thu, 30 Jan 2025 15:31:49 -0500 Subject: [PATCH 03/19] use preexisting connection in constructor if it's provided --- rpc/wrtc_signaling_answerer.go | 58 ++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/rpc/wrtc_signaling_answerer.go b/rpc/wrtc_signaling_answerer.go index 99545c7f..9b6acf7e 100644 --- a/rpc/wrtc_signaling_answerer.go +++ b/rpc/wrtc_signaling_answerer.go @@ -40,8 +40,9 @@ type webrtcSignalingAnswerer struct { // conn is used to share the direct gRPC connection used by the answerer workers. As direct gRPC connections // reconnect on their own, custom reconnect logic is not needed. However, keepalives are necessary for the connection // to realize it's been disconnected quickly and start reconnecting. - connMu sync.Mutex - conn ClientConn + connMu sync.Mutex + conn ClientConn + sharedConn bool logger utils.ZapCompatibleLogger } @@ -61,8 +62,12 @@ func newWebRTCSignalingAnswerer( dialOptsCopy := make([]DialOption, len(dialOpts)) copy(dialOptsCopy, dialOpts) dialOptsCopy = append(dialOptsCopy, WithWebRTCOptions(DialWebRTCOptions{Disable: true})) + options := &dialOptions{} + for _, opt := range dialOptsCopy { + opt.apply(options) + } bgWorkers := utils.NewBackgroundStoppableWorkers() - return &webrtcSignalingAnswerer{ + ans := &webrtcSignalingAnswerer{ address: address, hosts: hosts, server: server, @@ -71,6 +76,11 @@ func newWebRTCSignalingAnswerer( bgWorkers: bgWorkers, logger: logger, } + if options.conn != nil { + ans.conn = options.conn + ans.sharedConn = true + } + return ans } const ( @@ -88,28 +98,30 @@ func (ans *webrtcSignalingAnswerer) Start() { // attempt to make connection in a loop ans.bgWorkers.Add(func(ctx context.Context) { - for ans.conn == nil { - if ctx.Err() != nil { - return - } + if ans.sharedConn == false { + for ans.conn == nil { + if ctx.Err() != nil { + return + } - timeout := answererConnectTimeout - // Bump timeout from 10 seconds to 1 minute if behind a SOCKS proxy. It - // may take longer to connect to the signaling server in that case. - if proxyAddr := os.Getenv(SocksProxyEnvVar); proxyAddr != "" { - timeout = answererConnectTimeoutBehindProxy - } - setupCtx, timeoutCancel := context.WithTimeout(ctx, timeout) - conn, err := Dial(setupCtx, ans.address, ans.logger, ans.dialOpts...) - timeoutCancel() - if err != nil { - ans.logger.Errorw("error connecting answer client", "error", err) - utils.SelectContextOrWait(ctx, answererReconnectWait) - continue + timeout := answererConnectTimeout + // Bump timeout from 10 seconds to 1 minute if behind a SOCKS proxy. It + // may take longer to connect to the signaling server in that case. + if proxyAddr := os.Getenv(SocksProxyEnvVar); proxyAddr != "" { + timeout = answererConnectTimeoutBehindProxy + } + setupCtx, timeoutCancel := context.WithTimeout(ctx, timeout) + conn, err := Dial(setupCtx, ans.address, ans.logger, ans.dialOpts...) + timeoutCancel() + if err != nil { + ans.logger.Errorw("error connecting answer client", "error", err) + utils.SelectContextOrWait(ctx, answererReconnectWait) + continue + } + ans.connMu.Lock() + ans.conn = conn + ans.connMu.Unlock() } - ans.connMu.Lock() - ans.conn = conn - ans.connMu.Unlock() } // spin off the actual answerer workers for i := 0; i < defaultMaxAnswerers; i++ { From e0818f7025a259cb5f1c4ac9205731223c0ddea7 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Thu, 30 Jan 2025 16:27:46 -0500 Subject: [PATCH 04/19] revert constructor --- rpc/wrtc_signaling_answerer.go | 42 ++++++++++++++++------------------ 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/rpc/wrtc_signaling_answerer.go b/rpc/wrtc_signaling_answerer.go index 9b6acf7e..dd432496 100644 --- a/rpc/wrtc_signaling_answerer.go +++ b/rpc/wrtc_signaling_answerer.go @@ -98,30 +98,28 @@ func (ans *webrtcSignalingAnswerer) Start() { // attempt to make connection in a loop ans.bgWorkers.Add(func(ctx context.Context) { - if ans.sharedConn == false { - for ans.conn == nil { - if ctx.Err() != nil { - return - } + for ans.conn == nil { + if ctx.Err() != nil { + return + } - timeout := answererConnectTimeout - // Bump timeout from 10 seconds to 1 minute if behind a SOCKS proxy. It - // may take longer to connect to the signaling server in that case. - if proxyAddr := os.Getenv(SocksProxyEnvVar); proxyAddr != "" { - timeout = answererConnectTimeoutBehindProxy - } - setupCtx, timeoutCancel := context.WithTimeout(ctx, timeout) - conn, err := Dial(setupCtx, ans.address, ans.logger, ans.dialOpts...) - timeoutCancel() - if err != nil { - ans.logger.Errorw("error connecting answer client", "error", err) - utils.SelectContextOrWait(ctx, answererReconnectWait) - continue - } - ans.connMu.Lock() - ans.conn = conn - ans.connMu.Unlock() + timeout := answererConnectTimeout + // Bump timeout from 10 seconds to 1 minute if behind a SOCKS proxy. It + // may take longer to connect to the signaling server in that case. + if proxyAddr := os.Getenv(SocksProxyEnvVar); proxyAddr != "" { + timeout = answererConnectTimeoutBehindProxy + } + setupCtx, timeoutCancel := context.WithTimeout(ctx, timeout) + conn, err := Dial(setupCtx, ans.address, ans.logger, ans.dialOpts...) + timeoutCancel() + if err != nil { + ans.logger.Errorw("error connecting answer client", "error", err) + utils.SelectContextOrWait(ctx, answererReconnectWait) + continue } + ans.connMu.Lock() + ans.conn = conn + ans.connMu.Unlock() } // spin off the actual answerer workers for i := 0; i < defaultMaxAnswerers; i++ { From 933dcafb5a5d2f49b3a5dd205237306a3ad4e789 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Thu, 30 Jan 2025 16:28:44 -0500 Subject: [PATCH 05/19] lint --- rpc/dial_options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/dial_options.go b/rpc/dial_options.go index eeefe2a4..02953390 100644 --- a/rpc/dial_options.go +++ b/rpc/dial_options.go @@ -284,7 +284,7 @@ func WithForceDirectGRPC() DialOption { }) } -// WithConn provides a preexisting connection to use. This option forces the webrtcSignalingAnswerer to not dial or manage a connection +// WithConn provides a preexisting connection to use. This option forces the webrtcSignalingAnswerer to not dial or manage a connection. func WithConn(conn ClientConn) DialOption { return newFuncDialOption(func(o *dialOptions) { o.conn = conn From 33b1814bc7f7d5094cb89d757e12dc516dba1c33 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Thu, 30 Jan 2025 16:39:33 -0500 Subject: [PATCH 06/19] only close if connection is not shared --- rpc/wrtc_signaling_answerer.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/rpc/wrtc_signaling_answerer.go b/rpc/wrtc_signaling_answerer.go index dd432496..176fba8d 100644 --- a/rpc/wrtc_signaling_answerer.go +++ b/rpc/wrtc_signaling_answerer.go @@ -270,9 +270,11 @@ func (ans *webrtcSignalingAnswerer) Stop() { ans.connMu.Lock() defer ans.connMu.Unlock() if ans.conn != nil { - err := ans.conn.Close() - if isNetworkError(err) { - ans.logger.Errorw("error closing signaling connection", "error", err) + if !ans.sharedConn { + err := ans.conn.Close() + if isNetworkError(err) { + ans.logger.Errorw("error closing signaling connection", "error", err) + } } ans.conn = nil } From f2cdf28dda8c2c1263a2d43f37a007f39849db70 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Fri, 31 Jan 2025 13:21:35 -0500 Subject: [PATCH 07/19] rename signaler connection --- rpc/dial_options.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rpc/dial_options.go b/rpc/dial_options.go index 02953390..5a79a14f 100644 --- a/rpc/dial_options.go +++ b/rpc/dial_options.go @@ -66,7 +66,7 @@ type dialOptions struct { streamInterceptor grpc.StreamClientInterceptor // conn can be used to force the webrtcSignalingAnswerer to use a preexisting connection instead of dialing and managing its own. - conn ClientConn + externalSignalerConn ClientConn } // DialMulticastDNSOptions dictate any special settings to apply while dialing via mDNS. @@ -285,8 +285,8 @@ func WithForceDirectGRPC() DialOption { } // WithConn provides a preexisting connection to use. This option forces the webrtcSignalingAnswerer to not dial or manage a connection. -func WithConn(conn ClientConn) DialOption { +func WithConn(externalSignalerConn ClientConn) DialOption { return newFuncDialOption(func(o *dialOptions) { - o.conn = conn + o.externalSignalerConn = externalSignalerConn }) } From c979ad2adfd875d5dd54746f4aad13690539430a Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Fri, 31 Jan 2025 14:18:08 -0500 Subject: [PATCH 08/19] rename external signaling connection again --- rpc/dial_options.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rpc/dial_options.go b/rpc/dial_options.go index 5a79a14f..51455958 100644 --- a/rpc/dial_options.go +++ b/rpc/dial_options.go @@ -66,7 +66,7 @@ type dialOptions struct { streamInterceptor grpc.StreamClientInterceptor // conn can be used to force the webrtcSignalingAnswerer to use a preexisting connection instead of dialing and managing its own. - externalSignalerConn ClientConn + externalSignalingConn ClientConn } // DialMulticastDNSOptions dictate any special settings to apply while dialing via mDNS. @@ -284,9 +284,9 @@ func WithForceDirectGRPC() DialOption { }) } -// WithConn provides a preexisting connection to use. This option forces the webrtcSignalingAnswerer to not dial or manage a connection. -func WithConn(externalSignalerConn ClientConn) DialOption { +// WithExternalSignalingConn provides a preexisting connection to use. This option forces the webrtcSignalingAnswerer to not dial or manage a connection. +func WithExternalSignalingConn(externalSignalingConn ClientConn) DialOption { return newFuncDialOption(func(o *dialOptions) { - o.externalSignalerConn = externalSignalerConn + o.externalSignalingConn = externalSignalingConn }) } From 771c7076e35eb4eb70e545277909c27270b8b065 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Fri, 31 Jan 2025 14:19:55 -0500 Subject: [PATCH 09/19] lint --- rpc/wrtc_signaling_answerer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rpc/wrtc_signaling_answerer.go b/rpc/wrtc_signaling_answerer.go index 176fba8d..193b9398 100644 --- a/rpc/wrtc_signaling_answerer.go +++ b/rpc/wrtc_signaling_answerer.go @@ -76,8 +76,8 @@ func newWebRTCSignalingAnswerer( bgWorkers: bgWorkers, logger: logger, } - if options.conn != nil { - ans.conn = options.conn + if options.externalSignalingConn != nil { + ans.conn = options.externalSignalingConn ans.sharedConn = true } return ans From 8e637a5f2287c9342ae4a8dc4c67d93559a1dc0e Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Fri, 31 Jan 2025 14:20:59 -0500 Subject: [PATCH 10/19] lint again --- rpc/dial_options.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rpc/dial_options.go b/rpc/dial_options.go index 51455958..b150fe5f 100644 --- a/rpc/dial_options.go +++ b/rpc/dial_options.go @@ -284,7 +284,8 @@ func WithForceDirectGRPC() DialOption { }) } -// WithExternalSignalingConn provides a preexisting connection to use. This option forces the webrtcSignalingAnswerer to not dial or manage a connection. +// WithExternalSignalingConn provides a preexisting connection to use. This option forces the webrtcSignalingAnswerer to not dial or manage +// a connection. func WithExternalSignalingConn(externalSignalingConn ClientConn) DialOption { return newFuncDialOption(func(o *dialOptions) { o.externalSignalingConn = externalSignalingConn From 80539b332c04b85826ab95700b03874738cc2610 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Tue, 4 Feb 2025 17:45:20 -0500 Subject: [PATCH 11/19] update answerer comment --- rpc/wrtc_signaling_answerer.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/rpc/wrtc_signaling_answerer.go b/rpc/wrtc_signaling_answerer.go index 193b9398..21b26ea3 100644 --- a/rpc/wrtc_signaling_answerer.go +++ b/rpc/wrtc_signaling_answerer.go @@ -39,7 +39,11 @@ type webrtcSignalingAnswerer struct { // conn is used to share the direct gRPC connection used by the answerer workers. As direct gRPC connections // reconnect on their own, custom reconnect logic is not needed. However, keepalives are necessary for the connection - // to realize it's been disconnected quickly and start reconnecting. + // to realize it's been disconnected quickly and start reconnecting. conn can be set to a pre-existing gRPC connection that's used by + // other consumers via a dial option. In this scenario, sharedConn will be true, and the answerer will not attempt to establish a new + // connection to the signaling server. If this option is not set, the answerer will oversee the lifecycle of its own connection by + // continuosly dialing in the background until a successful connection emerges and closing said connection when done. In the shared + // connection case, the answerer will not close the connection. connMu sync.Mutex conn ClientConn sharedConn bool @@ -230,7 +234,10 @@ func (ans *webrtcSignalingAnswerer) startAnswerer() { initStage, ok := incomingCallerReq.GetStage().(*webrtcpb.AnswerRequest_Init) if !ok { - err := fmt.Errorf("expected first stage to be init or heartbeat; got %T", incomingCallerReq.GetStage()) + err := fmt.Errorf( + "expected first stage to be init or heartbeat; got %T", + incomingCallerReq.GetStage(), + ) aa.sendError(err) ans.logger.Warn(err.Error()) continue @@ -489,7 +496,11 @@ func (aa *answerAttempt) connect(ctx context.Context) (err error) { ansResp, err := aa.client.Recv() if err != nil { if !errors.Is(err, io.EOF) { - aa.logger.Warn("Error receiving initial message from signaling server", "err", err) + aa.logger.Warn( + "Error receiving initial message from signaling server", + "err", + err, + ) } return } @@ -529,7 +540,9 @@ func (aa *answerAttempt) connect(ctx context.Context) (err error) { // Happy path successful = true aa.server.counters.PeersConnected.Add(1) - aa.server.counters.TotalTimeConnectingMillis.Add(time.Since(connectionStartTime).Milliseconds()) + aa.server.counters.TotalTimeConnectingMillis.Add( + time.Since(connectionStartTime).Milliseconds(), + ) case <-ctx.Done(): // Timed out or signaling server was closed. serverChannel.Close() @@ -554,7 +567,11 @@ func (aa *answerAttempt) sendDone() { if sendErr != nil { // Errors communicating with the signaling server have no bearing on whether the // PeerConnection is usable. Log and ignore the send error. - aa.logger.Warnw("Failed to send connection success message to signaling server", "sendErr", sendErr) + aa.logger.Warnw( + "Failed to send connection success message to signaling server", + "sendErr", + sendErr, + ) } }) } From 7813ed23754043a187705d3498312cdd50bdb71b Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Tue, 4 Feb 2025 17:54:51 -0500 Subject: [PATCH 12/19] rename shared connection variable name --- rpc/dial_options.go | 6 +++--- rpc/wrtc_signaling_answerer.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/rpc/dial_options.go b/rpc/dial_options.go index b150fe5f..a41ca030 100644 --- a/rpc/dial_options.go +++ b/rpc/dial_options.go @@ -66,7 +66,7 @@ type dialOptions struct { streamInterceptor grpc.StreamClientInterceptor // conn can be used to force the webrtcSignalingAnswerer to use a preexisting connection instead of dialing and managing its own. - externalSignalingConn ClientConn + signalingConn ClientConn } // DialMulticastDNSOptions dictate any special settings to apply while dialing via mDNS. @@ -286,8 +286,8 @@ func WithForceDirectGRPC() DialOption { // WithExternalSignalingConn provides a preexisting connection to use. This option forces the webrtcSignalingAnswerer to not dial or manage // a connection. -func WithExternalSignalingConn(externalSignalingConn ClientConn) DialOption { +func withSignalingConn(signalingConn ClientConn) DialOption { return newFuncDialOption(func(o *dialOptions) { - o.externalSignalingConn = externalSignalingConn + o.signalingConn = signalingConn }) } diff --git a/rpc/wrtc_signaling_answerer.go b/rpc/wrtc_signaling_answerer.go index 21b26ea3..b6220bb7 100644 --- a/rpc/wrtc_signaling_answerer.go +++ b/rpc/wrtc_signaling_answerer.go @@ -80,8 +80,8 @@ func newWebRTCSignalingAnswerer( bgWorkers: bgWorkers, logger: logger, } - if options.externalSignalingConn != nil { - ans.conn = options.externalSignalingConn + if options.signalingConn != nil { + ans.conn = options.signalingConn ans.sharedConn = true } return ans From dc8946d95058b7aa8ed6c69e6078b19c455a6247 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Tue, 4 Feb 2025 17:56:06 -0500 Subject: [PATCH 13/19] add descriptive comment when creating internal answerer --- rpc/server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rpc/server.go b/rpc/server.go index 79843ac0..05e6847c 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -656,6 +656,8 @@ func NewServer(logger utils.ZapCompatibleLogger, opts ...ServerOption) (Server, if !sOpts.unauthenticated { answererDialOpts = append(answererDialOpts, WithEntityCredentials(server.internalUUID, server.internalCreds)) } + // this answerer uses an internal signaling server that runs locally as a separate process and so does not get a shared + // connection to App as a dial option server.webrtcAnswerers = append(server.webrtcAnswerers, newWebRTCSignalingAnswerer( address, internalSignalingHosts, From cd80af832887ac00dfdc65a4ccafdafec39823e2 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Tue, 4 Feb 2025 18:04:05 -0500 Subject: [PATCH 14/19] revert linter --- rpc/wrtc_signaling_answerer.go | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/rpc/wrtc_signaling_answerer.go b/rpc/wrtc_signaling_answerer.go index b6220bb7..8395201f 100644 --- a/rpc/wrtc_signaling_answerer.go +++ b/rpc/wrtc_signaling_answerer.go @@ -43,8 +43,7 @@ type webrtcSignalingAnswerer struct { // other consumers via a dial option. In this scenario, sharedConn will be true, and the answerer will not attempt to establish a new // connection to the signaling server. If this option is not set, the answerer will oversee the lifecycle of its own connection by // continuosly dialing in the background until a successful connection emerges and closing said connection when done. In the shared - // connection case, the answerer will not close the connection. - connMu sync.Mutex + // connection case, the answerer will not close the connection. connMu sync.Mutex conn ClientConn sharedConn bool @@ -80,8 +79,8 @@ func newWebRTCSignalingAnswerer( bgWorkers: bgWorkers, logger: logger, } - if options.signalingConn != nil { - ans.conn = options.signalingConn + if options.externalSignalingConn != nil { + ans.conn = options.externalSignalingConn ans.sharedConn = true } return ans @@ -234,10 +233,7 @@ func (ans *webrtcSignalingAnswerer) startAnswerer() { initStage, ok := incomingCallerReq.GetStage().(*webrtcpb.AnswerRequest_Init) if !ok { - err := fmt.Errorf( - "expected first stage to be init or heartbeat; got %T", - incomingCallerReq.GetStage(), - ) + err := fmt.Errorf("expected first stage to be init or heartbeat; got %T", incomingCallerReq.GetStage()) aa.sendError(err) ans.logger.Warn(err.Error()) continue @@ -496,11 +492,7 @@ func (aa *answerAttempt) connect(ctx context.Context) (err error) { ansResp, err := aa.client.Recv() if err != nil { if !errors.Is(err, io.EOF) { - aa.logger.Warn( - "Error receiving initial message from signaling server", - "err", - err, - ) + aa.logger.Warn("Error receiving initial message from signaling server", "err", err) } return } @@ -540,9 +532,7 @@ func (aa *answerAttempt) connect(ctx context.Context) (err error) { // Happy path successful = true aa.server.counters.PeersConnected.Add(1) - aa.server.counters.TotalTimeConnectingMillis.Add( - time.Since(connectionStartTime).Milliseconds(), - ) + aa.server.counters.TotalTimeConnectingMillis.Add(time.Since(connectionStartTime).Milliseconds()) case <-ctx.Done(): // Timed out or signaling server was closed. serverChannel.Close() @@ -567,11 +557,7 @@ func (aa *answerAttempt) sendDone() { if sendErr != nil { // Errors communicating with the signaling server have no bearing on whether the // PeerConnection is usable. Log and ignore the send error. - aa.logger.Warnw( - "Failed to send connection success message to signaling server", - "sendErr", - sendErr, - ) + aa.logger.Warnw("Failed to send connection success message to signaling server", "sendErr", sendErr) } }) } From 8a03b7066ffb567f7acd2eaa9505c3152252ed59 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Tue, 4 Feb 2025 18:04:44 -0500 Subject: [PATCH 15/19] lint --- rpc/wrtc_signaling_answerer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rpc/wrtc_signaling_answerer.go b/rpc/wrtc_signaling_answerer.go index 8395201f..513eb823 100644 --- a/rpc/wrtc_signaling_answerer.go +++ b/rpc/wrtc_signaling_answerer.go @@ -79,8 +79,8 @@ func newWebRTCSignalingAnswerer( bgWorkers: bgWorkers, logger: logger, } - if options.externalSignalingConn != nil { - ans.conn = options.externalSignalingConn + if options.signalingConn != nil { + ans.conn = options.signalingConn ans.sharedConn = true } return ans From 2e66377c2799c12e863b07bb3d72b2d7ad1978dc Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Tue, 4 Feb 2025 18:05:30 -0500 Subject: [PATCH 16/19] lint again --- rpc/wrtc_signaling_answerer.go | 1 + 1 file changed, 1 insertion(+) diff --git a/rpc/wrtc_signaling_answerer.go b/rpc/wrtc_signaling_answerer.go index 513eb823..03ba783a 100644 --- a/rpc/wrtc_signaling_answerer.go +++ b/rpc/wrtc_signaling_answerer.go @@ -44,6 +44,7 @@ type webrtcSignalingAnswerer struct { // connection to the signaling server. If this option is not set, the answerer will oversee the lifecycle of its own connection by // continuosly dialing in the background until a successful connection emerges and closing said connection when done. In the shared // connection case, the answerer will not close the connection. connMu sync.Mutex + connMu sync.Mutex conn ClientConn sharedConn bool From 321abff63dce69282300161fc8e8b52d38f2d579 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Tue, 4 Feb 2025 18:06:38 -0500 Subject: [PATCH 17/19] lint again again --- rpc/dial_options.go | 2 +- rpc/wrtc_signaling_answerer.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rpc/dial_options.go b/rpc/dial_options.go index a41ca030..ada81691 100644 --- a/rpc/dial_options.go +++ b/rpc/dial_options.go @@ -286,7 +286,7 @@ func WithForceDirectGRPC() DialOption { // WithExternalSignalingConn provides a preexisting connection to use. This option forces the webrtcSignalingAnswerer to not dial or manage // a connection. -func withSignalingConn(signalingConn ClientConn) DialOption { +func WithSignalingConn(signalingConn ClientConn) DialOption { return newFuncDialOption(func(o *dialOptions) { o.signalingConn = signalingConn }) diff --git a/rpc/wrtc_signaling_answerer.go b/rpc/wrtc_signaling_answerer.go index 03ba783a..eb9f801f 100644 --- a/rpc/wrtc_signaling_answerer.go +++ b/rpc/wrtc_signaling_answerer.go @@ -42,7 +42,7 @@ type webrtcSignalingAnswerer struct { // to realize it's been disconnected quickly and start reconnecting. conn can be set to a pre-existing gRPC connection that's used by // other consumers via a dial option. In this scenario, sharedConn will be true, and the answerer will not attempt to establish a new // connection to the signaling server. If this option is not set, the answerer will oversee the lifecycle of its own connection by - // continuosly dialing in the background until a successful connection emerges and closing said connection when done. In the shared + // continuously dialing in the background until a successful connection emerges and closing said connection when done. In the shared // connection case, the answerer will not close the connection. connMu sync.Mutex connMu sync.Mutex conn ClientConn From e55a28f542202825e273be9c389424fae52a8fc5 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Tue, 4 Feb 2025 18:07:13 -0500 Subject: [PATCH 18/19] lint again again again --- rpc/dial_options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rpc/dial_options.go b/rpc/dial_options.go index ada81691..96a56def 100644 --- a/rpc/dial_options.go +++ b/rpc/dial_options.go @@ -284,7 +284,7 @@ func WithForceDirectGRPC() DialOption { }) } -// WithExternalSignalingConn provides a preexisting connection to use. This option forces the webrtcSignalingAnswerer to not dial or manage +// WithSignalingConn provides a preexisting connection to use. This option forces the webrtcSignalingAnswerer to not dial or manage // a connection. func WithSignalingConn(signalingConn ClientConn) DialOption { return newFuncDialOption(func(o *dialOptions) { From 19572b970ca64ce85d45e72f876748612589ce02 Mon Sep 17 00:00:00 2001 From: Bashar Eid Date: Wed, 5 Feb 2025 10:14:05 -0500 Subject: [PATCH 19/19] update comment --- rpc/dial_options.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rpc/dial_options.go b/rpc/dial_options.go index 96a56def..f6c4c633 100644 --- a/rpc/dial_options.go +++ b/rpc/dial_options.go @@ -65,7 +65,7 @@ type dialOptions struct { unaryInterceptor grpc.UnaryClientInterceptor streamInterceptor grpc.StreamClientInterceptor - // conn can be used to force the webrtcSignalingAnswerer to use a preexisting connection instead of dialing and managing its own. + // signalingConn can be used to force the webrtcSignalingAnswerer to use a preexisting connection instead of dialing and managing its own. signalingConn ClientConn } @@ -268,7 +268,10 @@ func WithUnaryClientInterceptor(interceptor grpc.UnaryClientInterceptor) DialOpt func WithStreamClientInterceptor(interceptor grpc.StreamClientInterceptor) DialOption { return newFuncDialOption(func(o *dialOptions) { if o.streamInterceptor != nil { - o.streamInterceptor = grpc_middleware.ChainStreamClient(o.streamInterceptor, interceptor) + o.streamInterceptor = grpc_middleware.ChainStreamClient( + o.streamInterceptor, + interceptor, + ) } else { o.streamInterceptor = interceptor }