diff --git a/p2p/transport/websocket/browser_integration_native_test.go b/p2p/transport/websocket/browser_integration_native_test.go index 01486142b6..6934fb14f2 100644 --- a/p2p/transport/websocket/browser_integration_native_test.go +++ b/p2p/transport/websocket/browser_integration_native_test.go @@ -58,33 +58,33 @@ func TestInBrowser(t *testing.T) { }) addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/5555/ws") if err != nil { - t.Fatal("SERVER:", err) + t.Error("SERVER:", err) } listener, err := tpt.Listen(addr) if err != nil { - t.Fatal("SERVER:", err) + t.Error("SERVER:", err) } conn, err := listener.Accept() if err != nil { - t.Fatal("SERVER:", err) + t.Error("SERVER:", err) } defer conn.Close() stream, err := conn.OpenStream(context.Background()) if err != nil { - t.Fatal("SERVER: could not open stream:", err) + t.Error("SERVER: could not open stream:", err) } defer stream.Close() buf := bufio.NewReader(stream) if _, err := stream.Write([]byte("ping\n")); err != nil { - t.Fatal("SERVER:", err) + t.Error("SERVER:", err) } msg, err := buf.ReadString('\n') if err != nil { - t.Fatal("SERVER: could not read pong message:" + err.Error()) + t.Error("SERVER: could not read pong message:" + err.Error()) } expected := "pong\n" if msg != expected { - t.Fatalf("SERVER: Received wrong message. Expected %q but got %q", expected, msg) + t.Errorf("SERVER: Received wrong message. Expected %q but got %q", expected, msg) } }() diff --git a/p2p/transport/websocket/tools/go.mod b/p2p/transport/websocket/tools/go.mod index d34d7385b2..011649b66f 100644 --- a/p2p/transport/websocket/tools/go.mod +++ b/p2p/transport/websocket/tools/go.mod @@ -1,5 +1,5 @@ module github.com/libp2p/go-ws-transport/tools -go 1.13 +go 1.15 -require github.com/agnivade/wasmbrowsertest v0.3.1 +require github.com/agnivade/wasmbrowsertest v0.3.5 diff --git a/p2p/transport/websocket/tools/go.sum b/p2p/transport/websocket/tools/go.sum index 94b9c35ab1..164a43e812 100644 --- a/p2p/transport/websocket/tools/go.sum +++ b/p2p/transport/websocket/tools/go.sum @@ -1,5 +1,5 @@ -github.com/agnivade/wasmbrowsertest v0.3.1 h1:bA9aA+bcp7KuqGvmCuBdnMqy6PXxFjYP7FxsaT+JSqc= -github.com/agnivade/wasmbrowsertest v0.3.1/go.mod h1:zQt6ZTdl338xxRaMW395qccVE2eQm0SjC/SDz0mPWQI= +github.com/agnivade/wasmbrowsertest v0.3.5 h1:U8ICR7Xa3LBGQb57HtbbXf5KAMjQhiWrCWlr1kD77Cw= +github.com/agnivade/wasmbrowsertest v0.3.5/go.mod h1:zQt6ZTdl338xxRaMW395qccVE2eQm0SjC/SDz0mPWQI= github.com/chromedp/cdproto v0.0.0-20190614062957-d6d2f92b486d/go.mod h1:S8mB5wY3vV+vRIzf39xDXsw3XKYewW9X6rW2aEmkrSw= github.com/chromedp/cdproto v0.0.0-20190621002710-8cbd498dd7a0 h1:4Wocv9f+KWF4GtZudyrn8JSBTgHQbGp86mcsoH7j1iQ= github.com/chromedp/cdproto v0.0.0-20190621002710-8cbd498dd7a0/go.mod h1:S8mB5wY3vV+vRIzf39xDXsw3XKYewW9X6rW2aEmkrSw= diff --git a/p2p/transport/websocket/websocket.go b/p2p/transport/websocket/websocket.go index 5e7dc9989c..77d522deb4 100644 --- a/p2p/transport/websocket/websocket.go +++ b/p2p/transport/websocket/websocket.go @@ -20,20 +20,13 @@ var WsProtocol = ma.ProtocolWithCode(ma.P_WS) // WsFmt is multiaddr formatter for WsProtocol var WsFmt = mafmt.And(mafmt.TCP, mafmt.Base(ma.P_WS)) -// WsCodec is the multiaddr-net codec definition for the websocket transport -var WsCodec = &manet.NetCodec{ - NetAddrNetworks: []string{"websocket"}, - ProtocolName: "ws", - ConvertMultiaddr: ConvertWebsocketMultiaddrToNetAddr, - ParseNetAddr: ParseWebsocketNetAddr, -} - // This is _not_ WsFmt because we want the transport to stick to dialing fully // resolved addresses. var dialMatcher = mafmt.And(mafmt.IP, mafmt.Base(ma.P_TCP), mafmt.Base(ma.P_WS)) func init() { - manet.RegisterNetCodec(WsCodec) + manet.RegisterFromNetAddr(ParseWebsocketNetAddr, "websocket") + manet.RegisterToNetAddr(ConvertWebsocketMultiaddrToNetAddr, "ws") } var _ transport.Transport = (*WebsocketTransport)(nil) diff --git a/p2p/transport/websocket/websocket_test.go b/p2p/transport/websocket/websocket_test.go index aa51b74326..1082722e86 100644 --- a/p2p/transport/websocket/websocket_test.go +++ b/p2p/transport/websocket/websocket_test.go @@ -164,11 +164,11 @@ func TestWriteZero(t *testing.T) { go func() { c, err := tpt.maDial(context.Background(), l.Multiaddr()) - defer c.Close() if err != nil { t.Error(err) return } + defer c.Close() for i := 0; i < 100; i++ { n, err := c.Write(msg) @@ -183,10 +183,10 @@ func TestWriteZero(t *testing.T) { }() c, err := l.Accept() - defer c.Close() if err != nil { t.Fatal(err) } + defer c.Close() buf := make([]byte, 100) n, err := c.Read(buf) if n != 0 {