Skip to content

Commit

Permalink
Merge pull request #103 from libp2p/update-transport-upgrader
Browse files Browse the repository at this point in the history
chore: update go-libp2p-transport-upgrader and go-libp2p-core
  • Loading branch information
marten-seemann authored Jul 24, 2021
2 parents 830023a + cdd2cf7 commit 2e25e49
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
16 changes: 13 additions & 3 deletions p2p/transport/websocket/browser_integration_browser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,32 @@ import (
"testing"
"time"

"github.com/libp2p/go-libp2p-core/sec/insecure"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/test"
mplex "github.com/libp2p/go-libp2p-mplex"
tptu "github.com/libp2p/go-libp2p-transport-upgrader"
ma "github.com/multiformats/go-multiaddr"
)

func TestInBrowser(t *testing.T) {
priv, _, err := test.RandTestKeyPair(crypto.Ed25519, 256)
if err != nil {
t.Fatal(err)
}
id, err := peer.IDFromPrivateKey(priv)
if err != nil {
t.Fatal(err)
}
tpt := New(&tptu.Upgrader{
Secure: insecure.New("browserPeer"),
Secure: newSecureMuxer(t, id),
Muxer: new(mplex.Transport),
})
addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/5555/ws")
if err != nil {
t.Fatal("could not parse multiaddress:" + err.Error())
}
conn, err := tpt.Dial(context.Background(), addr, "serverPeer")
conn, err := tpt.Dial(context.Background(), addr, id)
if err != nil {
t.Fatal("could not dial server:" + err.Error())
}
Expand Down
3 changes: 1 addition & 2 deletions p2p/transport/websocket/browser_integration_native_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"
"testing"

"github.com/libp2p/go-libp2p-core/sec/insecure"
mplex "github.com/libp2p/go-libp2p-mplex"
tptu "github.com/libp2p/go-libp2p-transport-upgrader"
ma "github.com/multiformats/go-multiaddr"
Expand Down Expand Up @@ -53,7 +52,7 @@ func TestInBrowser(t *testing.T) {
close(serverDoneSignal)
}()
tpt := New(&tptu.Upgrader{
Secure: insecure.New("serverPeer"),
Secure: newSecureMuxer(t, "serverPeer"),
Muxer: new(mplex.Transport),
})
addr, err := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/5555/ws")
Expand Down
23 changes: 23 additions & 0 deletions p2p/transport/websocket/muxer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package websocket

import (
"testing"

csms "github.com/libp2p/go-conn-security-multistream"
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/sec"
"github.com/libp2p/go-libp2p-core/sec/insecure"
"github.com/libp2p/go-libp2p-core/test"
)

func newSecureMuxer(t *testing.T, id peer.ID) sec.SecureMuxer {
t.Helper()
priv, _, err := test.RandTestKeyPair(crypto.Ed25519, 256)
if err != nil {
t.Fatal(err)
}
var secMuxer csms.SSMuxer
secMuxer.AddTransport(insecure.ID, insecure.NewWithIdentity(id, priv))
return &secMuxer
}
5 changes: 2 additions & 3 deletions p2p/transport/websocket/websocket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"
"testing/iotest"

"github.com/libp2p/go-libp2p-core/sec/insecure"
mplex "github.com/libp2p/go-libp2p-mplex"
ttransport "github.com/libp2p/go-libp2p-testing/suites/transport"
tptu "github.com/libp2p/go-libp2p-transport-upgrader"
Expand Down Expand Up @@ -44,11 +43,11 @@ 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: insecure.New("peerA"),
Secure: newSecureMuxer(t, "peerA"),
Muxer: new(mplex.Transport),
})
tb := New(&tptu.Upgrader{
Secure: insecure.New("peerB"),
Secure: newSecureMuxer(t, "peerB"),
Muxer: new(mplex.Transport),
})

Expand Down

0 comments on commit 2e25e49

Please sign in to comment.