Skip to content

Commit

Permalink
Merge pull request #84 from libp2p/update-deps
Browse files Browse the repository at this point in the history
chore: update go-libp2p-transport-upgrader and go-reuseport-transport
  • Loading branch information
Stebalien committed Jul 25, 2021
2 parents 66cb18e + 302c1b5 commit 501872d
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions p2p/transport/tcp/tcp_test.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package tcp

import (
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
"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"
mplex "github.com/libp2p/go-libp2p-mplex"
tptu "github.com/libp2p/go-libp2p-transport-upgrader"

ttransport "github.com/libp2p/go-libp2p-testing/suites/transport"
tptu "github.com/libp2p/go-libp2p-transport-upgrader"

ma "github.com/multiformats/go-multiaddr"
)

func TestTcpTransport(t *testing.T) {
for i := 0; i < 2; i++ {
ia := makeInsecureTransport(t)
ib := makeInsecureTransport(t)
peerA, ia := makeInsecureMuxer(t)
_, ib := makeInsecureMuxer(t)

ta := NewTCPTransport(&tptu.Upgrader{
Secure: ia,
Expand All @@ -29,7 +30,7 @@ func TestTcpTransport(t *testing.T) {
})

zero := "/ip4/127.0.0.1/tcp/0"
ttransport.SubtestTransport(t, ta, tb, zero, ia.LocalPeer())
ttransport.SubtestTransport(t, ta, tb, zero, peerA)

envReuseportVal = false
}
Expand All @@ -43,8 +44,9 @@ func TestTcpTransportCantDialDNS(t *testing.T) {
t.Fatal(err)
}

_, sm := makeInsecureMuxer(t)
tpt := NewTCPTransport(&tptu.Upgrader{
Secure: makeInsecureTransport(t),
Secure: sm,
Muxer: new(mplex.Transport),
})

Expand All @@ -64,8 +66,9 @@ func TestTcpTransportCantListenUtp(t *testing.T) {
t.Fatal(err)
}

_, sm := makeInsecureMuxer(t)
tpt := NewTCPTransport(&tptu.Upgrader{
Secure: makeInsecureTransport(t),
Secure: sm,
Muxer: new(mplex.Transport),
})

Expand All @@ -79,14 +82,17 @@ func TestTcpTransportCantListenUtp(t *testing.T) {
envReuseportVal = true
}

func makeInsecureTransport(t *testing.T) *insecure.Transport {
priv, pub, err := crypto.GenerateKeyPair(crypto.Ed25519, 256)
func makeInsecureMuxer(t *testing.T) (peer.ID, sec.SecureMuxer) {
t.Helper()
priv, _, err := crypto.GenerateKeyPair(crypto.Ed25519, 256)
if err != nil {
t.Fatal(err)
}
id, err := peer.IDFromPublicKey(pub)
id, err := peer.IDFromPrivateKey(priv)
if err != nil {
t.Fatal(err)
}
return insecure.NewWithIdentity(id, priv)
var secMuxer csms.SSMuxer
secMuxer.AddTransport(insecure.ID, insecure.NewWithIdentity(id, priv))
return id, &secMuxer
}

0 comments on commit 501872d

Please sign in to comment.