Skip to content

Commit

Permalink
remove multistream test
Browse files Browse the repository at this point in the history
The type ErrNotSupported introduced in
multiformats/go-multistream#114 handles the
lazy handshake fail correctly.
  • Loading branch information
sukunrt committed Jan 27, 2025
1 parent cce849c commit 798258c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 35 deletions.
3 changes: 2 additions & 1 deletion p2p/host/basic/basic_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I
}
defer func() {
if strErr != nil && s != nil {
s.Reset()
s.ResetWithError(network.StreamProtocolNegotiationFailed)
}
}()

Expand Down Expand Up @@ -768,6 +768,7 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I
}

if err := s.SetProtocol(selected); err != nil {
s.ResetWithError(network.StreamResourceLimitExceeded)
return nil, err
}
_ = h.Peerstore().AddProtocols(p, selected) // adding the protocol to the peerstore isn't critical
Expand Down
32 changes: 0 additions & 32 deletions p2p/host/basic/basic_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -995,35 +995,3 @@ func TestHostTimeoutNewStream(t *testing.T) {
require.Error(t, err)
require.ErrorContains(t, err, "context deadline exceeded")
}

func TestMultistreamFailure(t *testing.T) {
h1, err := NewHost(swarmt.GenSwarm(t), nil)
require.NoError(t, err)
h1.Start()
defer h1.Close()

h2, err := NewHost(swarmt.GenSwarm(t), nil)
require.NoError(t, err)
h2.Start()
defer h2.Close()

h2.Peerstore().AddProtocols(h1.ID(), "/test")

err = h2.Connect(context.Background(), h1.Peerstore().PeerInfo(h1.ID()))
require.NoError(t, err)
h2.Peerstore().AddProtocols(h1.ID(), "/test")
s, err := h2.NewStream(context.Background(), h1.ID(), "/test")
require.NoError(t, err)
// Special string to make the other side fail multistream and reset
buf := make([]byte, 1024)
for i := 0; i < len(buf); i++ {
buf[i] = 0xff
}
_, err = s.Write(buf)
require.NoError(t, err)
_, err = s.Read(buf)
var se *network.StreamError
require.ErrorAs(t, err, &se)
require.True(t, se.Remote)
require.Equal(t, network.StreamProtocolNegotiationFailed, se.ErrorCode)
}
4 changes: 2 additions & 2 deletions p2p/net/connmgr/connmgr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1024,7 +1024,7 @@ func TestErrorCode(t *testing.T) {
}
c21 = conns[0]
return true
}, 5*time.Second, 100*time.Millisecond)
}, 10*time.Second, 100*time.Millisecond)

c13, err := sw1.DialPeer(context.Background(), sw3.LocalPeer())
require.NoError(t, err)
Expand All @@ -1037,7 +1037,7 @@ func TestErrorCode(t *testing.T) {
}
c31 = conns[0]
return true
}, 5*time.Second, 100*time.Millisecond)
}, 10*time.Second, 100*time.Millisecond)

cm.TrimOpenConns(context.Background())

Expand Down

0 comments on commit 798258c

Please sign in to comment.