Skip to content

Commit

Permalink
replaced GetUseTransient with GetAllowLimitedConn
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumemichel committed Apr 25, 2024
1 parent a105d63 commit e58beb3
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions p2p/net/swarm/swarm_conn.go
Expand Up @@ -194,8 +194,8 @@ func (c *Conn) Stat() network.ConnStats {
// NewStream returns a new Stream from this connection
func (c *Conn) NewStream(ctx context.Context) (network.Stream, error) {
if c.Stat().Limited {
if useTransient, _ := network.GetUseTransient(ctx); !useTransient {
return nil, network.ErrTransientConn
if useLimited, _ := network.GetAllowLimitedConn(ctx); !useLimited {
return nil, network.ErrLimitedConn
}
}

Expand Down
6 changes: 3 additions & 3 deletions p2p/protocol/circuitv2/relay/relay_test.go
Expand Up @@ -158,7 +158,7 @@ func TestBasicRelay(t *testing.T) {
t.Fatal("expected transient connection")
}

s, err := hosts[2].NewStream(network.WithUseTransient(ctx, "test"), hosts[0].ID(), "test")
s, err := hosts[2].NewStream(network.WithAllowLimitedConn(ctx, "test"), hosts[0].ID(), "test")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func TestRelayLimitTime(t *testing.T) {
t.Fatal("expected transient connection")
}

s, err := hosts[2].NewStream(network.WithUseTransient(ctx, "test"), hosts[0].ID(), "test")
s, err := hosts[2].NewStream(network.WithAllowLimitedConn(ctx, "test"), hosts[0].ID(), "test")
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -319,7 +319,7 @@ func TestRelayLimitData(t *testing.T) {
t.Fatal("expected transient connection")
}

s, err := hosts[2].NewStream(network.WithUseTransient(ctx, "test"), hosts[0].ID(), "test")
s, err := hosts[2].NewStream(network.WithAllowLimitedConn(ctx, "test"), hosts[0].ID(), "test")
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/protocol/holepunch/holepunch_test.go
Expand Up @@ -340,7 +340,7 @@ func TestFailuresOnResponder(t *testing.T) {
defer h2.Close()
defer relay.Close()

s, err := h2.NewStream(network.WithUseTransient(context.Background(), "holepunch"), h1.ID(), holepunch.Protocol)
s, err := h2.NewStream(network.WithAllowLimitedConn(context.Background(), "holepunch"), h1.ID(), holepunch.Protocol)
require.NoError(t, err)

go tc.initiator(s)
Expand Down
2 changes: 1 addition & 1 deletion p2p/protocol/holepunch/holepuncher.go
Expand Up @@ -174,7 +174,7 @@ func (hp *holePuncher) directConnect(rp peer.ID) error {
// initiateHolePunch opens a new hole punching coordination stream,
// exchanges the addresses and measures the RTT.
func (hp *holePuncher) initiateHolePunch(rp peer.ID) ([]ma.Multiaddr, []ma.Multiaddr, time.Duration, error) {
hpCtx := network.WithUseTransient(hp.ctx, "hole-punch")
hpCtx := network.WithAllowLimitedConn(hp.ctx, "hole-punch")
sCtx := network.WithNoDial(hpCtx, "hole-punch")

str, err := hp.host.NewStream(sCtx, rp, Protocol)
Expand Down
2 changes: 1 addition & 1 deletion p2p/protocol/identify/id.go
Expand Up @@ -410,7 +410,7 @@ func (ids *idService) IdentifyWait(c network.Conn) <-chan struct{} {
func (ids *idService) identifyConn(c network.Conn) error {
ctx, cancel := context.WithTimeout(context.Background(), Timeout)
defer cancel()
s, err := c.NewStream(network.WithUseTransient(ctx, "identify"))
s, err := c.NewStream(network.WithAllowLimitedConn(ctx, "identify"))
if err != nil {
log.Debugw("error opening identify stream", "peer", c.RemotePeer(), "error", err)
return err
Expand Down
2 changes: 1 addition & 1 deletion p2p/protocol/ping/ping.go
Expand Up @@ -111,7 +111,7 @@ func pingError(err error) chan Result {
// Ping pings the remote peer until the context is canceled, returning a stream
// of RTTs or errors.
func Ping(ctx context.Context, h host.Host, p peer.ID) <-chan Result {
s, err := h.NewStream(network.WithUseTransient(ctx, "ping"), p, ID)
s, err := h.NewStream(network.WithAllowLimitedConn(ctx, "ping"), p, ID)
if err != nil {
return pingError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion p2p/test/basichost/basic_host_test.go
Expand Up @@ -74,7 +74,7 @@ func TestNoStreamOverTransientConnection(t *testing.T) {

require.Error(t, err)

_, err = h1.NewStream(network.WithUseTransient(context.Background(), "test"), h2.ID(), "/testprotocol")
_, err = h1.NewStream(network.WithAllowLimitedConn(context.Background(), "test"), h2.ID(), "/testprotocol")
require.NoError(t, err)
}

Expand Down
6 changes: 3 additions & 3 deletions p2p/test/swarm/swarm_test.go
Expand Up @@ -110,16 +110,16 @@ func TestNewStreamTransientConnection(t *testing.T) {

h1.Peerstore().AddAddr(h2.ID(), relayaddr, peerstore.TempAddrTTL)

// WithUseTransient should succeed
// WithAllowLimitedConn should succeed
ctx, cancel := context.WithTimeout(context.Background(), 200*time.Millisecond)
defer cancel()
ctx = network.WithUseTransient(ctx, "test")
ctx = network.WithAllowLimitedConn(ctx, "test")
s, err := h1.Network().NewStream(ctx, h2.ID())
require.NoError(t, err)
require.NotNil(t, s)
defer s.Close()

// Without WithUseTransient should fail with context deadline exceeded
// Without WithAllowLimitedConn should fail with context deadline exceeded
ctx, cancel = context.WithTimeout(context.Background(), 200*time.Millisecond)
defer cancel()
s, err = h1.Network().NewStream(ctx, h2.ID())
Expand Down

0 comments on commit e58beb3

Please sign in to comment.