Skip to content

Commit

Permalink
use the transport.Upgrader interface
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Jan 4, 2022
1 parent 75dda2b commit 081817c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
9 changes: 5 additions & 4 deletions p2p/transport/websocket/browser_integration_browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ func TestInBrowser(t *testing.T) {
if err != nil {
t.Fatal(err)
}
tpt := New(&tptu.Upgrader{
Secure: newSecureMuxer(t, id),
Muxer: new(mplex.Transport),
})
u, err := tptu.New(newSecureMuxer(t, id), new(mplex.Transport))
if err != nil {
t.Fatal(err)
}
tpt := New(u)
addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/5555/ws")
if err != nil {
t.Fatal("could not parse multiaddress:" + err.Error())
Expand Down
9 changes: 5 additions & 4 deletions p2p/transport/websocket/browser_integration_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ func TestInBrowser(t *testing.T) {
defer func() {
close(serverDoneSignal)
}()
tpt := New(&tptu.Upgrader{
Secure: newSecureMuxer(t, "serverPeer"),
Muxer: new(mplex.Transport),
})
u, err := tptu.New(newSecureMuxer(t, "serverPeer"), new(mplex.Transport))
if err != nil {
t.Error("SERVER:", err)
}
tpt := New(u)
addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/5555/ws")
if err != nil {
t.Error("SERVER:", err)
Expand Down
6 changes: 2 additions & 4 deletions p2p/transport/websocket/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/transport"

tptu "github.com/libp2p/go-libp2p-transport-upgrader"

ma "github.com/multiformats/go-multiaddr"
mafmt "github.com/multiformats/go-multiaddr-fmt"
manet "github.com/multiformats/go-multiaddr/net"
Expand All @@ -31,10 +29,10 @@ var _ transport.Transport = (*WebsocketTransport)(nil)

// WebsocketTransport is the actual go-libp2p transport
type WebsocketTransport struct {
Upgrader *tptu.Upgrader
Upgrader transport.Upgrader
}

func New(u *tptu.Upgrader) *WebsocketTransport {
func New(u transport.Upgrader) *WebsocketTransport {
return &WebsocketTransport{u}
}

Expand Down
18 changes: 10 additions & 8 deletions p2p/transport/websocket/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ func TestCanDial(t *testing.T) {

func TestWebsocketTransport(t *testing.T) {
t.Skip("This test is failing, see https://github.com/libp2p/go-ws-transport/issues/99")
ta := New(&tptu.Upgrader{
Secure: newSecureMuxer(t, "peerA"),
Muxer: new(mplex.Transport),
})
tb := New(&tptu.Upgrader{
Secure: newSecureMuxer(t, "peerB"),
Muxer: new(mplex.Transport),
})
ua, err := tptu.New(newSecureMuxer(t, "peerA"), new(mplex.Transport))
if err != nil {
t.Fatal(err)
}
ta := New(ua)
ub, err := tptu.New(newSecureMuxer(t, "peerB"), new(mplex.Transport))
if err != nil {
t.Fatal(err)
}
tb := New(ub)

zero := "/ip4/127.0.0.1/tcp/0/ws"
ttransport.SubtestTransport(t, ta, tb, zero, "peerA")
Expand Down

0 comments on commit 081817c

Please sign in to comment.