From 2828a61f9ccd35fdbddcc19879cf2a2c8b75c89a Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 8 Oct 2021 15:45:15 +0200 Subject: [PATCH 1/2] move circuitv2 tests to the relay package --- examples/go.sum | 1 + examples/ipfs-camp-2019/go.sum | 1 + examples/pubsub/chat/go.sum | 1 + p2p/protocol/circuitv2/{test => relay}/compat_test.go | 2 +- .../circuitv2/{test/e2e_test.go => relay/relay_test.go} | 9 +-------- p2p/protocol/circuitv2/test/empty.go | 1 - 6 files changed, 5 insertions(+), 10 deletions(-) rename p2p/protocol/circuitv2/{test => relay}/compat_test.go (99%) rename p2p/protocol/circuitv2/{test/e2e_test.go => relay/relay_test.go} (97%) delete mode 100644 p2p/protocol/circuitv2/test/empty.go diff --git a/examples/go.sum b/examples/go.sum index d1df34eebb..11473210c3 100644 --- a/examples/go.sum +++ b/examples/go.sum @@ -435,6 +435,7 @@ github.com/libp2p/go-libp2p-autonat v0.5.0 h1:/+3+4NcQV47DQ/duvRyFDP8oxv6CQTvSKY github.com/libp2p/go-libp2p-autonat v0.5.0/go.mod h1:085tmmuXn0nXgFwuF7a2tt4UxgTjuapbuml27v4htKY= github.com/libp2p/go-libp2p-blankhost v0.2.0 h1:3EsGAi0CBGcZ33GwRuXEYJLLPoVWyXJ1bcJzAJjINkk= github.com/libp2p/go-libp2p-blankhost v0.2.0/go.mod h1:eduNKXGTioTuQAUcZ5epXi9vMl+t4d8ugUBRQ4SqaNQ= +github.com/libp2p/go-libp2p-circuit v0.4.0 h1:eqQ3sEYkGTtybWgr6JLqJY6QLtPWRErvFjFDfAOO1wc= github.com/libp2p/go-libp2p-circuit v0.4.0/go.mod h1:t/ktoFIUzM6uLQ+o1G6NuBl2ANhBKN9Bc8jRIk31MoA= github.com/libp2p/go-libp2p-connmgr v0.2.4 h1:TMS0vc0TCBomtQJyWr7fYxcVYYhx+q/2gF++G5Jkl/w= github.com/libp2p/go-libp2p-connmgr v0.2.4/go.mod h1:YV0b/RIm8NGPnnNWM7hG9Q38OeQiQfKhHCCs1++ufn0= diff --git a/examples/ipfs-camp-2019/go.sum b/examples/ipfs-camp-2019/go.sum index 1f2af497ed..ef6d340ddd 100644 --- a/examples/ipfs-camp-2019/go.sum +++ b/examples/ipfs-camp-2019/go.sum @@ -436,6 +436,7 @@ github.com/libp2p/go-libp2p-autonat v0.5.0 h1:/+3+4NcQV47DQ/duvRyFDP8oxv6CQTvSKY github.com/libp2p/go-libp2p-autonat v0.5.0/go.mod h1:085tmmuXn0nXgFwuF7a2tt4UxgTjuapbuml27v4htKY= github.com/libp2p/go-libp2p-blankhost v0.2.0 h1:3EsGAi0CBGcZ33GwRuXEYJLLPoVWyXJ1bcJzAJjINkk= github.com/libp2p/go-libp2p-blankhost v0.2.0/go.mod h1:eduNKXGTioTuQAUcZ5epXi9vMl+t4d8ugUBRQ4SqaNQ= +github.com/libp2p/go-libp2p-circuit v0.4.0 h1:eqQ3sEYkGTtybWgr6JLqJY6QLtPWRErvFjFDfAOO1wc= github.com/libp2p/go-libp2p-circuit v0.4.0/go.mod h1:t/ktoFIUzM6uLQ+o1G6NuBl2ANhBKN9Bc8jRIk31MoA= github.com/libp2p/go-libp2p-connmgr v0.2.4 h1:TMS0vc0TCBomtQJyWr7fYxcVYYhx+q/2gF++G5Jkl/w= github.com/libp2p/go-libp2p-connmgr v0.2.4/go.mod h1:YV0b/RIm8NGPnnNWM7hG9Q38OeQiQfKhHCCs1++ufn0= diff --git a/examples/pubsub/chat/go.sum b/examples/pubsub/chat/go.sum index 16802345d1..a1fb670964 100644 --- a/examples/pubsub/chat/go.sum +++ b/examples/pubsub/chat/go.sum @@ -417,6 +417,7 @@ github.com/libp2p/go-libp2p-autonat v0.5.0 h1:/+3+4NcQV47DQ/duvRyFDP8oxv6CQTvSKY github.com/libp2p/go-libp2p-autonat v0.5.0/go.mod h1:085tmmuXn0nXgFwuF7a2tt4UxgTjuapbuml27v4htKY= github.com/libp2p/go-libp2p-blankhost v0.2.0 h1:3EsGAi0CBGcZ33GwRuXEYJLLPoVWyXJ1bcJzAJjINkk= github.com/libp2p/go-libp2p-blankhost v0.2.0/go.mod h1:eduNKXGTioTuQAUcZ5epXi9vMl+t4d8ugUBRQ4SqaNQ= +github.com/libp2p/go-libp2p-circuit v0.4.0 h1:eqQ3sEYkGTtybWgr6JLqJY6QLtPWRErvFjFDfAOO1wc= github.com/libp2p/go-libp2p-circuit v0.4.0/go.mod h1:t/ktoFIUzM6uLQ+o1G6NuBl2ANhBKN9Bc8jRIk31MoA= github.com/libp2p/go-libp2p-connmgr v0.2.4 h1:TMS0vc0TCBomtQJyWr7fYxcVYYhx+q/2gF++G5Jkl/w= github.com/libp2p/go-libp2p-connmgr v0.2.4/go.mod h1:YV0b/RIm8NGPnnNWM7hG9Q38OeQiQfKhHCCs1++ufn0= diff --git a/p2p/protocol/circuitv2/test/compat_test.go b/p2p/protocol/circuitv2/relay/compat_test.go similarity index 99% rename from p2p/protocol/circuitv2/test/compat_test.go rename to p2p/protocol/circuitv2/relay/compat_test.go index 0cbb1bc9a7..87f5256875 100644 --- a/p2p/protocol/circuitv2/test/compat_test.go +++ b/p2p/protocol/circuitv2/relay/compat_test.go @@ -1,4 +1,4 @@ -package test +package relay_test import ( "bytes" diff --git a/p2p/protocol/circuitv2/test/e2e_test.go b/p2p/protocol/circuitv2/relay/relay_test.go similarity index 97% rename from p2p/protocol/circuitv2/test/e2e_test.go rename to p2p/protocol/circuitv2/relay/relay_test.go index 58a84ef4d9..96ecb1f803 100644 --- a/p2p/protocol/circuitv2/test/e2e_test.go +++ b/p2p/protocol/circuitv2/relay/relay_test.go @@ -1,4 +1,4 @@ -package test +package relay_test import ( "bytes" @@ -18,7 +18,6 @@ import ( "github.com/libp2p/go-libp2p-core/network" "github.com/libp2p/go-libp2p-core/peer" - logging "github.com/ipfs/go-log/v2" bhost "github.com/libp2p/go-libp2p-blankhost" "github.com/libp2p/go-libp2p-core/metrics" "github.com/libp2p/go-libp2p-peerstore/pstoremem" @@ -29,12 +28,6 @@ import ( ma "github.com/multiformats/go-multiaddr" ) -func init() { - // TODO temporary for debugging purposes; to be removed for merge. - logging.SetLogLevel("relay", "DEBUG") - logging.SetLogLevel("p2p-circuit", "DEBUG") -} - func getNetHosts(t *testing.T, ctx context.Context, n int) (hosts []host.Host, upgraders []*tptu.Upgrader) { for i := 0; i < n; i++ { privk, pubk, err := crypto.GenerateKeyPair(crypto.Ed25519, 0) diff --git a/p2p/protocol/circuitv2/test/empty.go b/p2p/protocol/circuitv2/test/empty.go deleted file mode 100644 index 56e5404079..0000000000 --- a/p2p/protocol/circuitv2/test/empty.go +++ /dev/null @@ -1 +0,0 @@ -package test From a157b1bd91af56109f477113b2c2208b1f185632 Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Fri, 8 Oct 2021 15:46:14 +0200 Subject: [PATCH 2/2] move isRelayAddr helper function --- p2p/protocol/circuitv2/relay/relay.go | 9 +++++++-- p2p/protocol/circuitv2/util/ma.go | 10 ---------- 2 files changed, 7 insertions(+), 12 deletions(-) delete mode 100644 p2p/protocol/circuitv2/util/ma.go diff --git a/p2p/protocol/circuitv2/relay/relay.go b/p2p/protocol/circuitv2/relay/relay.go index d4e08d5169..9e836eea12 100644 --- a/p2p/protocol/circuitv2/relay/relay.go +++ b/p2p/protocol/circuitv2/relay/relay.go @@ -139,7 +139,7 @@ func (r *Relay) handleReserve(s network.Stream) { p := s.Conn().RemotePeer() a := s.Conn().RemoteMultiaddr() - if util.IsRelayAddr(a) { + if isRelayAddr(a) { log.Debugf("refusing relay reservation for %s; reservation attempt over relay connection") r.handleError(s, pbv2.Status_PERMISSION_DENIED) return @@ -184,7 +184,7 @@ func (r *Relay) handleConnect(s network.Stream, msg *pbv2.HopMessage) { src := s.Conn().RemotePeer() a := s.Conn().RemoteMultiaddr() - if util.IsRelayAddr(a) { + if isRelayAddr(a) { log.Debugf("refusing connection from %s; connection attempt over relay connection") r.handleError(s, pbv2.Status_PERMISSION_DENIED) return @@ -531,3 +531,8 @@ func (r *Relay) disconnected(n network.Network, c network.Conn) { delete(r.rsvp, p) } + +func isRelayAddr(a ma.Multiaddr) bool { + _, err := a.ValueForProtocol(ma.P_CIRCUIT) + return err == nil +} diff --git a/p2p/protocol/circuitv2/util/ma.go b/p2p/protocol/circuitv2/util/ma.go deleted file mode 100644 index 0dd820e20b..0000000000 --- a/p2p/protocol/circuitv2/util/ma.go +++ /dev/null @@ -1,10 +0,0 @@ -package util - -import ( - ma "github.com/multiformats/go-multiaddr" -) - -func IsRelayAddr(a ma.Multiaddr) bool { - _, err := a.ValueForProtocol(ma.P_CIRCUIT) - return err == nil -}