Skip to content

Commit 354fbdc

Browse files
committed
remove multistream test
The type ErrNotSupported introduced in multiformats/go-multistream#114 handles the lazy handshake fail correctly.
1 parent cce849c commit 354fbdc

File tree

3 files changed

+4
-36
lines changed

3 files changed

+4
-36
lines changed

p2p/host/basic/basic_host.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I
717717
}
718718
defer func() {
719719
if strErr != nil && s != nil {
720-
s.Reset()
720+
s.ResetWithError(network.StreamProtocolNegotiationFailed)
721721
}
722722
}()
723723

@@ -761,13 +761,13 @@ func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.I
761761
return nil, fmt.Errorf("failed to negotiate protocol: %w", err)
762762
}
763763
case <-ctx.Done():
764-
s.ResetWithError(network.StreamProtocolNegotiationFailed)
765764
// wait for `SelectOneOf` to error out because of resetting the stream.
766765
<-errCh
767766
return nil, fmt.Errorf("failed to negotiate protocol: %w", ctx.Err())
768767
}
769768

770769
if err := s.SetProtocol(selected); err != nil {
770+
s.ResetWithError(network.StreamResourceLimitExceeded)
771771
return nil, err
772772
}
773773
_ = h.Peerstore().AddProtocols(p, selected) // adding the protocol to the peerstore isn't critical

p2p/host/basic/basic_host_test.go

-32
Original file line numberDiff line numberDiff line change
@@ -995,35 +995,3 @@ func TestHostTimeoutNewStream(t *testing.T) {
995995
require.Error(t, err)
996996
require.ErrorContains(t, err, "context deadline exceeded")
997997
}
998-
999-
func TestMultistreamFailure(t *testing.T) {
1000-
h1, err := NewHost(swarmt.GenSwarm(t), nil)
1001-
require.NoError(t, err)
1002-
h1.Start()
1003-
defer h1.Close()
1004-
1005-
h2, err := NewHost(swarmt.GenSwarm(t), nil)
1006-
require.NoError(t, err)
1007-
h2.Start()
1008-
defer h2.Close()
1009-
1010-
h2.Peerstore().AddProtocols(h1.ID(), "/test")
1011-
1012-
err = h2.Connect(context.Background(), h1.Peerstore().PeerInfo(h1.ID()))
1013-
require.NoError(t, err)
1014-
h2.Peerstore().AddProtocols(h1.ID(), "/test")
1015-
s, err := h2.NewStream(context.Background(), h1.ID(), "/test")
1016-
require.NoError(t, err)
1017-
// Special string to make the other side fail multistream and reset
1018-
buf := make([]byte, 1024)
1019-
for i := 0; i < len(buf); i++ {
1020-
buf[i] = 0xff
1021-
}
1022-
_, err = s.Write(buf)
1023-
require.NoError(t, err)
1024-
_, err = s.Read(buf)
1025-
var se *network.StreamError
1026-
require.ErrorAs(t, err, &se)
1027-
require.True(t, se.Remote)
1028-
require.Equal(t, network.StreamProtocolNegotiationFailed, se.ErrorCode)
1029-
}

p2p/net/connmgr/connmgr_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@ func TestErrorCode(t *testing.T) {
10241024
}
10251025
c21 = conns[0]
10261026
return true
1027-
}, 5*time.Second, 100*time.Millisecond)
1027+
}, 10*time.Second, 100*time.Millisecond)
10281028

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

10421042
cm.TrimOpenConns(context.Background())
10431043

0 commit comments

Comments
 (0)