mirror of
https://github.com/libp2p/go-libp2p.git
synced 2026-04-23 00:27:05 +08:00
consistently use protocol.ID instead of strings (#2004)
* Change PeerStore interface to use protocol.ID This reduces the string to protocol.ID translations happening at various places in the code * Fix misc cases of protocol.ID conversion * Merge multistream changes * Use protocol.ID in network.ConnectionState * don't update examples * fix error message tests * merge new go-multistream changes * update test-plans go mod * change transport back to string
This commit is contained in:
@@ -158,8 +158,8 @@ func TestProtocolHandlerEvents(t *testing.T) {
|
||||
|
||||
h.SetStreamHandler(protocol.TestingID, func(s network.Stream) {})
|
||||
assert([]protocol.ID{protocol.TestingID}, nil)
|
||||
h.SetStreamHandler(protocol.ID("foo"), func(s network.Stream) {})
|
||||
assert([]protocol.ID{protocol.ID("foo")}, nil)
|
||||
h.SetStreamHandler("foo", func(s network.Stream) {})
|
||||
assert([]protocol.ID{"foo"}, nil)
|
||||
h.RemoveStreamHandler(protocol.TestingID)
|
||||
assert(nil, []protocol.ID{protocol.TestingID})
|
||||
}
|
||||
@@ -273,9 +273,9 @@ func TestHostProtoPreference(t *testing.T) {
|
||||
defer h2.Close()
|
||||
|
||||
const (
|
||||
protoOld = protocol.ID("/testing")
|
||||
protoNew = protocol.ID("/testing/1.1.0")
|
||||
protoMinor = protocol.ID("/testing/1.2.0")
|
||||
protoOld = "/testing"
|
||||
protoNew = "/testing/1.1.0"
|
||||
protoMinor = "/testing/1.2.0"
|
||||
)
|
||||
|
||||
connectedOn := make(chan protocol.ID)
|
||||
@@ -299,7 +299,7 @@ func TestHostProtoPreference(t *testing.T) {
|
||||
assertWait(t, connectedOn, protoOld)
|
||||
s.Close()
|
||||
|
||||
h2.SetStreamHandlerMatch(protoMinor, func(string) bool { return true }, handler)
|
||||
h2.SetStreamHandlerMatch(protoMinor, func(protocol.ID) bool { return true }, handler)
|
||||
// remembered preference will be chosen first, even when the other side newly supports it
|
||||
s2, err := h1.NewStream(context.Background(), h2.ID(), protoMinor, protoNew, protoOld)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user