From adf6aa21e7d083a596e1f85a01630f7f16e30a9c Mon Sep 17 00:00:00 2001 From: Swaggg Pickle Date: Mon, 3 May 2021 18:12:24 -0700 Subject: [PATCH 1/4] Add check for transportation protocol before attempting to connect via UDP. --- gather.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gather.go b/gather.go index b005a3d4..11e3dc5e 100644 --- a/gather.go +++ b/gather.go @@ -352,6 +352,11 @@ func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*URL, networkT go func(url URL, network string) { defer wg.Done() + // if transport protocol is TCP assume UDP calls will fail/timeout. + if url.Proto == ProtoTypeTCP { + return + } + hostPort := fmt.Sprintf("%s:%d", url.Host, url.Port) serverAddr, err := a.net.ResolveUDPAddr(network, hostPort) if err != nil { From 5bc2f65b1a9c345f493eedee6a0a008657f3c728 Mon Sep 17 00:00:00 2001 From: Swaggg Pickle Date: Mon, 3 May 2021 19:42:34 -0700 Subject: [PATCH 2/4] Added self to readme. Added to unit tests to ensure coverage of new code. --- README.md | 1 + gather_test.go | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/README.md b/README.md index 55bc037e..5bf1cc3c 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ Check out the **[contributing wiki](https://github.com/pion/webrtc/wiki/Contribu * [David Zhao](https://github.com/davidzhao) * [Juliusz Chroboczek](https://github.com/jech) * [Jin Gong](https://github.com/cgojin) +* [swagggpickle](https://github.com/swagggpickle) ### License MIT License - see [LICENSE](LICENSE) for full text diff --git a/gather_test.go b/gather_test.go index e69d9875..242c0835 100644 --- a/gather_test.go +++ b/gather_test.go @@ -317,6 +317,14 @@ func TestSTUNTURNConcurrency(t *testing.T) { Username: "username", Password: "password", }) + urls = append(urls, &URL{ + Scheme: SchemeTypeTURN, + Proto: ProtoTypeTCP, + Host: "127.0.0.1", + Port: serverPort, + Username: "username", + Password: "password", + }) a, err := NewAgent(&AgentConfig{ NetworkTypes: supportedNetworkTypes(), From 8338a093aa7c2cd77b0937a0445da58d933758ff Mon Sep 17 00:00:00 2001 From: Swaggg Pickle Date: Thu, 6 May 2021 13:51:34 -0700 Subject: [PATCH 3/4] Prevent goroutine from starting if url protocol is TCP --- gather.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/gather.go b/gather.go index 11e3dc5e..4c9dad97 100644 --- a/gather.go +++ b/gather.go @@ -348,15 +348,14 @@ func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*URL, networkT } for i := range urls { + // if transport protocol is TCP assume UDP calls will fail/timeout. + if urls[i].Proto == ProtoTypeTCP { + return + } wg.Add(1) go func(url URL, network string) { defer wg.Done() - // if transport protocol is TCP assume UDP calls will fail/timeout. - if url.Proto == ProtoTypeTCP { - return - } - hostPort := fmt.Sprintf("%s:%d", url.Host, url.Port) serverAddr, err := a.net.ResolveUDPAddr(network, hostPort) if err != nil { From b8c659fd7483ddb595de3b700f4b19a792ef61e2 Mon Sep 17 00:00:00 2001 From: Swaggg Pickle Date: Thu, 6 May 2021 13:54:17 -0700 Subject: [PATCH 4/4] switch to continue to try all urls --- gather.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gather.go b/gather.go index 4c9dad97..2fa6610a 100644 --- a/gather.go +++ b/gather.go @@ -350,7 +350,7 @@ func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*URL, networkT for i := range urls { // if transport protocol is TCP assume UDP calls will fail/timeout. if urls[i].Proto == ProtoTypeTCP { - return + continue } wg.Add(1) go func(url URL, network string) {