Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

fix: Remove active connections when RTC connection is lost #379

Merged
merged 4 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix linting
  • Loading branch information
kylecarbs committed Jul 8, 2021
commit 9771524ae70066f5b8e71fd34395e0454622a7bf
7 changes: 3 additions & 4 deletions wsnet/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ExampleDial_basic() {
// You now have access to the proxied remote port in `conn`.
}

// nolint:gocognit,nestif
// nolint:gocognit
func TestDial(t *testing.T) {
t.Run("Ping", func(t *testing.T) {
connectAddr, listenAddr := createDumbBroker(t)
Expand Down Expand Up @@ -204,12 +204,11 @@ func TestDial(t *testing.T) {
t.Error(err)
return
}
pass := "test"
turnAddr, closeTurn := createTURNServer(t, ice.SchemeTypeTURN, pass)
turnAddr, closeTurn := createTURNServer(t, ice.SchemeTypeTURN)
dialer, err := DialWebsocket(context.Background(), connectAddr, []webrtc.ICEServer{{
URLs: []string{fmt.Sprintf("turn:%s", turnAddr)},
Username: "example",
Credential: pass,
Credential: testPass,
CredentialType: webrtc.ICECredentialTypePassword,
}})
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions wsnet/rtc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ func TestDialICE(t *testing.T) {
t.Run("TURN with TLS", func(t *testing.T) {
t.Parallel()

addr, _ := createTURNServer(t, ice.SchemeTypeTURNS, "test")
addr, _ := createTURNServer(t, ice.SchemeTypeTURNS)
err := DialICE(webrtc.ICEServer{
URLs: []string{fmt.Sprintf("turns:%s", addr)},
Username: "example",
Credential: "test",
Credential: testPass,
CredentialType: webrtc.ICECredentialTypePassword,
}, &DialICEOptions{
Timeout: time.Millisecond,
Expand All @@ -34,11 +34,11 @@ func TestDialICE(t *testing.T) {
t.Run("Protocol mismatch", func(t *testing.T) {
t.Parallel()

addr, _ := createTURNServer(t, ice.SchemeTypeTURNS, "test")
addr, _ := createTURNServer(t, ice.SchemeTypeTURNS)
err := DialICE(webrtc.ICEServer{
URLs: []string{fmt.Sprintf("turn:%s", addr)},
Username: "example",
Credential: "test",
Credential: testPass,
CredentialType: webrtc.ICECredentialTypePassword,
}, &DialICEOptions{
Timeout: time.Millisecond,
Expand All @@ -52,7 +52,7 @@ func TestDialICE(t *testing.T) {
t.Run("Invalid auth", func(t *testing.T) {
t.Parallel()

addr, _ := createTURNServer(t, ice.SchemeTypeTURNS, "test")
addr, _ := createTURNServer(t, ice.SchemeTypeTURNS)
err := DialICE(webrtc.ICEServer{
URLs: []string{fmt.Sprintf("turns:%s", addr)},
Username: "example",
Expand Down
9 changes: 7 additions & 2 deletions wsnet/wsnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ import (
"nhooyr.io/websocket"
)

const (
// Password used connecting to the test TURN server.
testPass = "test"
)

// createDumbBroker proxies sockets between /listen and /connect
// to emulate an authenticated WebSocket pair.
func createDumbBroker(t testing.TB) (connectAddr string, listenAddr string) {
Expand Down Expand Up @@ -86,7 +91,7 @@ func createDumbBroker(t testing.TB) (connectAddr string, listenAddr string) {
}

// createTURNServer allocates a TURN server and returns the address.
func createTURNServer(t *testing.T, server ice.SchemeType, pass string) (string, func()) {
func createTURNServer(t *testing.T, server ice.SchemeType) (string, func()) {
var (
listeners []turn.ListenerConfig
pcListeners []turn.PacketConnConfig
Expand Down Expand Up @@ -136,7 +141,7 @@ func createTURNServer(t *testing.T, server ice.SchemeType, pass string) (string,
ListenerConfigs: listeners,
Realm: "coder",
AuthHandler: func(username, realm string, srcAddr net.Addr) (key []byte, ok bool) {
return turn.GenerateAuthKey(username, realm, pass), true
return turn.GenerateAuthKey(username, realm, testPass), true
},
LoggerFactory: lf,
})
Expand Down