Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #100 from libp2p/chore/cleanup
Browse files Browse the repository at this point in the history
chore: various cleanups required to get vet/staticcheck/test to pass
  • Loading branch information
Stebalien authored Jul 15, 2021
2 parents e4941fa + 861aa30 commit a024c90
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 83 deletions.
14 changes: 7 additions & 7 deletions browser_integration_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}()

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/libp2p/go-libp2p-mplex v0.4.0
github.com/libp2p/go-libp2p-testing v0.4.0
github.com/libp2p/go-libp2p-transport-upgrader v0.2.0
github.com/multiformats/go-multiaddr v0.3.1
github.com/multiformats/go-multiaddr v0.3.3
github.com/multiformats/go-multiaddr-fmt v0.1.0
)

Expand Down
67 changes: 7 additions & 60 deletions go.sum

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tools/go.mod
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tools/go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down
11 changes: 2 additions & 9 deletions websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down

0 comments on commit a024c90

Please sign in to comment.