Repository: libp2p/go-libp2p
Pull request #1183 (2021-09-10 08:56:45)

Use circuitv2 code
This uses the (backwards compatible) circuit v2 client for handling relay connections.

Relay options are removed; relay servers should be explicitly instantiated or use a dedicated daemon (e.g. p2pd or relayd).
Also moves the `circuitv2` code into `p2p/protocol` (see #1177)


Patch:
diff --git a/config/config.go b/config/config.go
index 48df4d20..bbb3914e 100644
--- a/config/config.go
+++ b/config/config.go
@@ -21,11 +21,11 @@ import (
 	bhost "github.com/libp2p/go-libp2p/p2p/host/basic"
 	"github.com/libp2p/go-libp2p/p2p/host/relay"
 	routed "github.com/libp2p/go-libp2p/p2p/host/routed"
+	circuitv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/client"
 	holepunch "github.com/libp2p/go-libp2p/p2p/protocol/holepunch"
 
 	autonat "github.com/libp2p/go-libp2p-autonat"
 	blankhost "github.com/libp2p/go-libp2p-blankhost"
-	circuit "github.com/libp2p/go-libp2p-circuit"
 	discovery "github.com/libp2p/go-libp2p-discovery"
 	swarm "github.com/libp2p/go-libp2p-swarm"
 	tptu "github.com/libp2p/go-libp2p-transport-upgrader"
@@ -76,7 +76,6 @@ type Config struct {
 
 	RelayCustom bool
 	Relay       bool
-	RelayOpts   []circuit.RelayOpt
 
 	ListenAddrs     []ma.Multiaddr
 	AddrsFactory    bhost.AddrsFactory
@@ -173,7 +172,7 @@ func (cfg *Config) addTransports(ctx context.Context, h host.Host) (err error) {
 	}
 
 	if cfg.Relay {
-		err := circuit.AddRelayTransport(ctx, h, upgrader, cfg.RelayOpts...)
+		err := circuitv2.AddTransport(ctx, h, upgrader)
 		if err != nil {
 			h.Close()
 			return err
@@ -259,15 +258,7 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
 			return nil, fmt.Errorf("cannot enable autorelay; relay is not enabled")
 		}
 
-		hop := false
-		for _, opt := range cfg.RelayOpts {
-			if opt == circuit.OptHop {
-				hop = true
-				break
-			}
-		}
-
-		if !hop && len(cfg.StaticRelays) > 0 {
+		if len(cfg.StaticRelays) > 0 {
 			_ = relay.NewAutoRelay(ctx, h, nil, router, cfg.StaticRelays)
 		} else {
 			if router == nil {
@@ -283,12 +274,7 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
 
 			discovery := discovery.NewRoutingDiscovery(crouter)
 
-			if hop {
-				// advertise ourselves
-				relay.Advertise(ctx, discovery)
-			} else {
-				_ = relay.NewAutoRelay(ctx, h, discovery, router, cfg.StaticRelays)
-			}
+			_ = relay.NewAutoRelay(ctx, h, discovery, router, cfg.StaticRelays)
 		}
 	}
 
diff --git a/examples/relay/main.go b/examples/relay/main.go
index 3df5c48a..daf655b1 100644
--- a/examples/relay/main.go
+++ b/examples/relay/main.go
@@ -30,11 +30,16 @@ func run() {
 
 	// Tell the host to relay connections for other peers (The ability to *use*
 	// a relay vs the ability to *be* a relay)
-	h2, err := libp2p.New(context.Background(), libp2p.EnableRelay(circuit.OptHop))
+	h2, err := libp2p.New(context.Background(), libp2p.DisableRelay())
 	if err != nil {
 		log.Printf("Failed to create h2: %v", err)
 		return
 	}
+	_, err = circuit.NewRelay(context.Background(), h2, nil, circuit.OptHop)
+	if err != nil {
+		log.Printf("Failed to instantiate h2 relay: %v", err)
+		return
+	}
 
 	// Zero out the listen addresses for the host, so it can only communicate
 	// via p2p-circuit for our example
diff --git a/options.go b/options.go
index 75549d34..b82236c0 100644
--- a/options.go
+++ b/options.go
@@ -8,7 +8,6 @@ import (
 	"fmt"
 	"time"
 
-	circuit "github.com/libp2p/go-libp2p-circuit"
 	"github.com/libp2p/go-libp2p-core/connmgr"
 	"github.com/libp2p/go-libp2p-core/crypto"
 	"github.com/libp2p/go-libp2p-core/metrics"
@@ -210,17 +209,15 @@ func AddrsFactory(factory config.AddrsFactory) Option {
 	}
 }
 
-// EnableRelay configures libp2p to enable the relay transport with
-// configuration options. By default, this option only configures libp2p to
-// accept inbound connections from relays and make outbound connections
-// _through_ relays when requested by the remote peer. (default: enabled)
-//
-// To _act_ as a relay, pass the circuit.OptHop option.
-func EnableRelay(options ...circuit.RelayOpt) Option {
+// EnableRelay configures libp2p to enable the relay transport.
+// This option only configures libp2p to accept inbound connections from relays
+// and make outbound connections_through_ relays when requested by the remote peer.
+// This option supports both circuit v1 and v2 connections.
+// (default: enabled)
+func EnableRelay() Option {
 	return func(cfg *Config) error {
 		cfg.RelayCustom = true
 		cfg.Relay = true
-		cfg.RelayOpts = options
 		return nil
 	}
 }
@@ -240,14 +237,8 @@ func DisableRelay() Option {
 //  * Relay (enabled by default)
 //  * Routing (to find relays), or StaticRelays/DefaultStaticRelays.
 //
-// This subsystem performs two functions:
-//
-// 1. When this libp2p node is configured to act as a relay "hop"
-//    (circuit.OptHop is passed to EnableRelay), this node will advertise itself
-//    as a public relay using the provided routing system.
-// 2. When this libp2p node is _not_ configured as a relay "hop", it will
-//    automatically detect if it is unreachable (e.g., behind a NAT). If so, it will
-//    find, configure, and announce a set of public relays.
+// This subsystem performs automatic address rewriting to advertise relay addresses when it
+// detects that the node is publicly unreachable (e.g. behind a NAT).
 func EnableAutoRelay() Option {
 	return func(cfg *Config) error {
 		cfg.EnableAutoRelay = true
diff --git a/p2p/host/circuitv2/client/client.go b/p2p/protocol/circuitv2/client/client.go
similarity index 96%
rename from p2p/host/circuitv2/client/client.go
rename to p2p/protocol/circuitv2/client/client.go
index 60d7e758..e6ee5a4b 100644
--- a/p2p/host/circuitv2/client/client.go
+++ b/p2p/protocol/circuitv2/client/client.go
@@ -4,7 +4,7 @@ import (
 	"context"
 	"sync"
 
-	"github.com/libp2p/go-libp2p/p2p/host/circuitv2/proto"
+	"github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/proto"
 
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/peer"
diff --git a/p2p/host/circuitv2/client/conn.go b/p2p/protocol/circuitv2/client/conn.go
similarity index 100%
rename from p2p/host/circuitv2/client/conn.go
rename to p2p/protocol/circuitv2/client/conn.go
diff --git a/p2p/host/circuitv2/client/dial.go b/p2p/protocol/circuitv2/client/dial.go
similarity index 96%
rename from p2p/host/circuitv2/client/dial.go
rename to p2p/protocol/circuitv2/client/dial.go
index 535521fd..0dd9d875 100644
--- a/p2p/host/circuitv2/client/dial.go
+++ b/p2p/protocol/circuitv2/client/dial.go
@@ -6,9 +6,9 @@ import (
 	"time"
 
 	pbv1 "github.com/libp2p/go-libp2p-circuit/pb"
-	pbv2 "github.com/libp2p/go-libp2p/p2p/host/circuitv2/pb"
-	"github.com/libp2p/go-libp2p/p2p/host/circuitv2/proto"
-	"github.com/libp2p/go-libp2p/p2p/host/circuitv2/util"
+	pbv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/pb"
+	"github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/proto"
+	"github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/util"
 
 	"github.com/libp2p/go-libp2p-core/network"
 	"github.com/libp2p/go-libp2p-core/peer"
diff --git a/p2p/host/circuitv2/client/handlers.go b/p2p/protocol/circuitv2/client/handlers.go
similarity index 97%
rename from p2p/host/circuitv2/client/handlers.go
rename to p2p/protocol/circuitv2/client/handlers.go
index 78704846..bda2fcc1 100644
--- a/p2p/host/circuitv2/client/handlers.go
+++ b/p2p/protocol/circuitv2/client/handlers.go
@@ -4,8 +4,8 @@ import (
 	"time"
 
 	pbv1 "github.com/libp2p/go-libp2p-circuit/pb"
-	pbv2 "github.com/libp2p/go-libp2p/p2p/host/circuitv2/pb"
-	"github.com/libp2p/go-libp2p/p2p/host/circuitv2/util"
+	pbv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/pb"
+	"github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/util"
 
 	"github.com/libp2p/go-libp2p-core/network"
 )
diff --git a/p2p/host/circuitv2/client/listen.go b/p2p/protocol/circuitv2/client/listen.go
similarity index 100%
rename from p2p/host/circuitv2/client/listen.go
rename to p2p/protocol/circuitv2/client/listen.go
diff --git a/p2p/host/circuitv2/client/reservation.go b/p2p/protocol/circuitv2/client/reservation.go
similarity index 94%
rename from p2p/host/circuitv2/client/reservation.go
rename to p2p/protocol/circuitv2/client/reservation.go
index 479a1476..36185ecd 100644
--- a/p2p/host/circuitv2/client/reservation.go
+++ b/p2p/protocol/circuitv2/client/reservation.go
@@ -5,9 +5,9 @@ import (
 	"fmt"
 	"time"
 
-	pbv2 "github.com/libp2p/go-libp2p/p2p/host/circuitv2/pb"
-	"github.com/libp2p/go-libp2p/p2p/host/circuitv2/proto"
-	"github.com/libp2p/go-libp2p/p2p/host/circuitv2/util"
+	pbv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/pb"
+	"github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/proto"
+	"github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/util"
 
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/peer"
diff --git a/p2p/host/circuitv2/client/transport.go b/p2p/protocol/circuitv2/client/transport.go
similarity index 100%
rename from p2p/host/circuitv2/client/transport.go
rename to p2p/protocol/circuitv2/client/transport.go
diff --git a/p2p/host/circuitv2/pb/Makefile b/p2p/protocol/circuitv2/pb/Makefile
similarity index 100%
rename from p2p/host/circuitv2/pb/Makefile
rename to p2p/protocol/circuitv2/pb/Makefile
diff --git a/p2p/host/circuitv2/pb/circuit.pb.go b/p2p/protocol/circuitv2/pb/circuit.pb.go
similarity index 100%
rename from p2p/host/circuitv2/pb/circuit.pb.go
rename to p2p/protocol/circuitv2/pb/circuit.pb.go
diff --git a/p2p/host/circuitv2/pb/circuit.proto b/p2p/protocol/circuitv2/pb/circuit.proto
similarity index 100%
rename from p2p/host/circuitv2/pb/circuit.proto
rename to p2p/protocol/circuitv2/pb/circuit.proto
diff --git a/p2p/host/circuitv2/pb/voucher.pb.go b/p2p/protocol/circuitv2/pb/voucher.pb.go
similarity index 100%
rename from p2p/host/circuitv2/pb/voucher.pb.go
rename to p2p/protocol/circuitv2/pb/voucher.pb.go
diff --git a/p2p/host/circuitv2/pb/voucher.proto b/p2p/protocol/circuitv2/pb/voucher.proto
similarity index 100%
rename from p2p/host/circuitv2/pb/voucher.proto
rename to p2p/protocol/circuitv2/pb/voucher.proto
diff --git a/p2p/host/circuitv2/proto/protocol.go b/p2p/protocol/circuitv2/proto/protocol.go
similarity index 100%
rename from p2p/host/circuitv2/proto/protocol.go
rename to p2p/protocol/circuitv2/proto/protocol.go
diff --git a/p2p/host/circuitv2/proto/voucher.go b/p2p/protocol/circuitv2/proto/voucher.go
similarity index 96%
rename from p2p/host/circuitv2/proto/voucher.go
rename to p2p/protocol/circuitv2/proto/voucher.go
index 6b4c24c8..fe8e3aee 100644
--- a/p2p/host/circuitv2/proto/voucher.go
+++ b/p2p/protocol/circuitv2/proto/voucher.go
@@ -3,7 +3,7 @@ package proto
 import (
 	"time"
 
-	pbv2 "github.com/libp2p/go-libp2p/p2p/host/circuitv2/pb"
+	pbv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/pb"
 
 	"github.com/libp2p/go-libp2p-core/peer"
 	"github.com/libp2p/go-libp2p-core/record"
diff --git a/p2p/host/circuitv2/proto/voucher_test.go b/p2p/protocol/circuitv2/proto/voucher_test.go
similarity index 100%
rename from p2p/host/circuitv2/proto/voucher_test.go
rename to p2p/protocol/circuitv2/proto/voucher_test.go
diff --git a/p2p/host/circuitv2/relay/acl.go b/p2p/protocol/circuitv2/relay/acl.go
similarity index 100%
rename from p2p/host/circuitv2/relay/acl.go
rename to p2p/protocol/circuitv2/relay/acl.go
diff --git a/p2p/host/circuitv2/relay/constraints.go b/p2p/protocol/circuitv2/relay/constraints.go
similarity index 100%
rename from p2p/host/circuitv2/relay/constraints.go
rename to p2p/protocol/circuitv2/relay/constraints.go
diff --git a/p2p/host/circuitv2/relay/constraints_test.go b/p2p/protocol/circuitv2/relay/constraints_test.go
similarity index 100%
rename from p2p/host/circuitv2/relay/constraints_test.go
rename to p2p/protocol/circuitv2/relay/constraints_test.go
diff --git a/p2p/host/circuitv2/relay/options.go b/p2p/protocol/circuitv2/relay/options.go
similarity index 100%
rename from p2p/host/circuitv2/relay/options.go
rename to p2p/protocol/circuitv2/relay/options.go
diff --git a/p2p/host/circuitv2/relay/relay.go b/p2p/protocol/circuitv2/relay/relay.go
similarity index 98%
rename from p2p/host/circuitv2/relay/relay.go
rename to p2p/protocol/circuitv2/relay/relay.go
index 8ddddd17..bc52dd89 100644
--- a/p2p/host/circuitv2/relay/relay.go
+++ b/p2p/protocol/circuitv2/relay/relay.go
@@ -8,9 +8,9 @@ import (
 	"sync/atomic"
 	"time"
 
-	pbv2 "github.com/libp2p/go-libp2p/p2p/host/circuitv2/pb"
-	"github.com/libp2p/go-libp2p/p2p/host/circuitv2/proto"
-	"github.com/libp2p/go-libp2p/p2p/host/circuitv2/util"
+	pbv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/pb"
+	"github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/proto"
+	"github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/util"
 
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/network"
diff --git a/p2p/host/circuitv2/test/empty.go b/p2p/protocol/circuitv2/test/empty.go
similarity index 100%
rename from p2p/host/circuitv2/test/empty.go
rename to p2p/protocol/circuitv2/test/empty.go
diff --git a/p2p/host/circuitv2/util/io.go b/p2p/protocol/circuitv2/util/io.go
similarity index 100%
rename from p2p/host/circuitv2/util/io.go
rename to p2p/protocol/circuitv2/util/io.go
diff --git a/p2p/host/circuitv2/util/ma.go b/p2p/protocol/circuitv2/util/ma.go
similarity index 100%
rename from p2p/host/circuitv2/util/ma.go
rename to p2p/protocol/circuitv2/util/ma.go
diff --git a/p2p/host/circuitv2/util/pbconv.go b/p2p/protocol/circuitv2/util/pbconv.go
similarity index 96%
rename from p2p/host/circuitv2/util/pbconv.go
rename to p2p/protocol/circuitv2/util/pbconv.go
index 63074acc..923b2226 100644
--- a/p2p/host/circuitv2/util/pbconv.go
+++ b/p2p/protocol/circuitv2/util/pbconv.go
@@ -4,7 +4,7 @@ import (
 	"errors"
 
 	pbv1 "github.com/libp2p/go-libp2p-circuit/pb"
-	pbv2 "github.com/libp2p/go-libp2p/p2p/host/circuitv2/pb"
+	pbv2 "github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/pb"
 
 	"github.com/libp2p/go-libp2p-core/peer"
 


Test patch:
diff --git a/p2p/host/relay/autorelay_test.go b/p2p/host/relay/autorelay_test.go
index 1b466245..dd3b632d 100644
--- a/p2p/host/relay/autorelay_test.go
+++ b/p2p/host/relay/autorelay_test.go
@@ -11,13 +11,15 @@ import (
 	"github.com/libp2p/go-libp2p"
 	"github.com/libp2p/go-libp2p/p2p/host/relay"
 
-	circuit "github.com/libp2p/go-libp2p-circuit"
 	"github.com/libp2p/go-libp2p-core/event"
 	"github.com/libp2p/go-libp2p-core/host"
 	"github.com/libp2p/go-libp2p-core/network"
 	"github.com/libp2p/go-libp2p-core/peer"
 	"github.com/libp2p/go-libp2p-core/routing"
 
+	circuit "github.com/libp2p/go-libp2p-circuit"
+	discovery "github.com/libp2p/go-libp2p-discovery"
+
 	"github.com/ipfs/go-cid"
 	ma "github.com/multiformats/go-multiaddr"
 	manet "github.com/multiformats/go-multiaddr/net"
@@ -120,21 +122,19 @@ func TestAutoRelay(t *testing.T) {
 	defer cancel()
 
 	mtab := newMockRoutingTable()
-	makeRouting := func(h host.Host) (routing.PeerRouting, error) {
+	makeRouting := func(h host.Host) (*mockRouting, error) {
 		mr := newMockRouting(h, mtab)
 		return mr, nil
 	}
-
-	h1, err := libp2p.New(ctx, libp2p.EnableRelay())
-	if err != nil {
-		t.Fatal(err)
+	makePeerRouting := func(h host.Host) (routing.PeerRouting, error) {
+		return makeRouting(h)
 	}
+
+	// this is the relay host
 	// announce dns addrs because filter out private addresses from relays,
 	// and we consider dns addresses "public".
-	_, err = libp2p.New(ctx,
-		libp2p.EnableRelay(circuit.OptHop),
-		libp2p.EnableAutoRelay(),
-		libp2p.Routing(makeRouting),
+	relayHost, err := libp2p.New(ctx,
+		libp2p.DisableRelay(),
 		libp2p.AddrsFactory(func(addrs []ma.Multiaddr) []ma.Multiaddr {
 			for i, addr := range addrs {
 				saddr := addr.String()
@@ -148,17 +148,38 @@ func TestAutoRelay(t *testing.T) {
 	if err != nil {
 		t.Fatal(err)
 	}
-	h3, err := libp2p.New(ctx, libp2p.EnableRelay(), libp2p.EnableAutoRelay(), libp2p.Routing(makeRouting))
+
+	// instantiate the relay
+	_, err = circuit.NewRelay(ctx, relayHost, nil, circuit.OptHop)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	// advertise the relay
+	relayRouting, err := makeRouting(relayHost)
+	if err != nil {
+		t.Fatal(err)
+	}
+	relayDiscovery := discovery.NewRoutingDiscovery(relayRouting)
+	relay.Advertise(ctx, relayDiscovery)
+
+	// the client hosts
+	h1, err := libp2p.New(ctx, libp2p.EnableRelay())
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	h2, err := libp2p.New(ctx, libp2p.EnableRelay(), libp2p.EnableAutoRelay(), libp2p.Routing(makePeerRouting))
 	if err != nil {
 		t.Fatal(err)
 	}
-	h4, err := libp2p.New(ctx, libp2p.EnableRelay())
+	h3, err := libp2p.New(ctx, libp2p.EnableRelay())
 	if err != nil {
 		t.Fatal(err)
 	}
 
 	// verify that we don't advertise relay addrs initially
-	for _, addr := range h3.Addrs() {
+	for _, addr := range h2.Addrs() {
 		_, err := addr.ValueForProtocol(ma.P_CIRCUIT)
 		if err == nil {
 			t.Fatal("relay addr advertised before auto detection")
@@ -166,9 +187,9 @@ func TestAutoRelay(t *testing.T) {
 	}
 
 	// connect to AutoNAT, have it resolve to private.
-	connect(t, h1, h3)
+	connect(t, h1, h2)
 	time.Sleep(300 * time.Millisecond)
-	privEmitter, _ := h3.EventBus().Emitter(new(event.EvtLocalReachabilityChanged))
+	privEmitter, _ := h2.EventBus().Emitter(new(event.EvtLocalReachabilityChanged))
 	privEmitter.Emit(event.EvtLocalReachabilityChanged{Reachability: network.ReachabilityPrivate})
 	// Wait for detection to do its magic
 	time.Sleep(3000 * time.Millisecond)
@@ -180,7 +201,7 @@ func TestAutoRelay(t *testing.T) {
 	}
 
 	haveRelay := false
-	for _, addr := range h3.Addrs() {
+	for _, addr := range h2.Addrs() {
 		if addr.Equal(unspecificRelay) {
 			t.Fatal("unspecific relay addr advertised")
 		}
@@ -197,21 +218,21 @@ func TestAutoRelay(t *testing.T) {
 
 	// verify that we can connect through the relay
 	var raddrs []ma.Multiaddr
-	for _, addr := range h3.Addrs() {
+	for _, addr := range h2.Addrs() {
 		_, err := addr.ValueForProtocol(ma.P_CIRCUIT)
 		if err == nil {
 			raddrs = append(raddrs, addr)
 		}
 	}
 
-	err = h4.Connect(ctx, peer.AddrInfo{ID: h3.ID(), Addrs: raddrs})
+	err = h3.Connect(ctx, peer.AddrInfo{ID: h2.ID(), Addrs: raddrs})
 	if err != nil {
 		t.Fatal(err)
 	}
 
 	// verify that we have pushed relay addrs to connected peers
 	haveRelay = false
-	for _, addr := range h1.Peerstore().Addrs(h3.ID()) {
+	for _, addr := range h1.Peerstore().Addrs(h2.ID()) {
 		if addr.Equal(unspecificRelay) {
 			t.Fatal("unspecific relay addr advertised")
 		}
diff --git a/p2p/host/circuitv2/relay/resources.go b/p2p/protocol/circuitv2/relay/resources.go
similarity index 100%
rename from p2p/host/circuitv2/relay/resources.go
rename to p2p/protocol/circuitv2/relay/resources.go
diff --git a/p2p/host/circuitv2/test/compat_test.go b/p2p/protocol/circuitv2/test/compat_test.go
similarity index 100%
rename from p2p/host/circuitv2/test/compat_test.go
rename to p2p/protocol/circuitv2/test/compat_test.go
diff --git a/p2p/host/circuitv2/test/e2e_test.go b/p2p/protocol/circuitv2/test/e2e_test.go
similarity index 98%
rename from p2p/host/circuitv2/test/e2e_test.go
rename to p2p/protocol/circuitv2/test/e2e_test.go
index b822f913..cf4c9bd2 100644
--- a/p2p/host/circuitv2/test/e2e_test.go
+++ b/p2p/protocol/circuitv2/test/e2e_test.go
@@ -9,8 +9,8 @@ import (
 	"testing"
 	"time"
 
-	"github.com/libp2p/go-libp2p/p2p/host/circuitv2/client"
-	"github.com/libp2p/go-libp2p/p2p/host/circuitv2/relay"
+	"github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/client"
+	"github.com/libp2p/go-libp2p/p2p/protocol/circuitv2/relay"
 
 	"github.com/libp2p/go-libp2p-core/crypto"
 	"github.com/libp2p/go-libp2p-core/host"
diff --git a/p2p/protocol/holepunch/coordination_test.go b/p2p/protocol/holepunch/coordination_test.go
index 8b332063..c314e17b 100644
--- a/p2p/protocol/holepunch/coordination_test.go
+++ b/p2p/protocol/holepunch/coordination_test.go
@@ -324,9 +324,13 @@ func makeRelayedHosts(t *testing.T, h1Opt holepunch.Option, addHolePuncher bool)
 	var err error
 	relay, err = libp2p.New(context.Background(),
 		libp2p.ListenAddrs(ma.StringCast("/ip4/127.0.0.1/tcp/0"), ma.StringCast("/ip6/::1/tcp/0")),
-		libp2p.EnableRelay(circuit.OptHop),
+		libp2p.DisableRelay(),
 	)
 	require.NoError(t, err)
+
+	_, err = circuit.NewRelay(context.Background(), relay, nil, circuit.OptHop)
+	require.NoError(t, err)
+
 	h2 = mkHostWithStaticAutoRelay(t, context.Background(), relay)
 	if addHolePuncher {
 		hps = addHolePunchService(t, h2)