Commit dd0775df authored by Aarsh Shah's avatar Aarsh Shah

changes for the new interface

parent 7a58f873
...@@ -97,6 +97,8 @@ github.com/libp2p/go-libp2p-core v0.5.1 h1:6Cu7WljPQtGY2krBlMoD8L/zH3tMUsCbqNFH7 ...@@ -97,6 +97,8 @@ github.com/libp2p/go-libp2p-core v0.5.1 h1:6Cu7WljPQtGY2krBlMoD8L/zH3tMUsCbqNFH7
github.com/libp2p/go-libp2p-core v0.5.1/go.mod h1:uN7L2D4EvPCvzSH5SrhR72UWbnSGpt5/a35Sm4upn4Y= github.com/libp2p/go-libp2p-core v0.5.1/go.mod h1:uN7L2D4EvPCvzSH5SrhR72UWbnSGpt5/a35Sm4upn4Y=
github.com/libp2p/go-libp2p-core v0.5.4-0.20200508062439-98b95a487749 h1:G0zRpRnpZ8sAZ5E5IRB6x7np9iuulPIWE+y3I/xGNfo= github.com/libp2p/go-libp2p-core v0.5.4-0.20200508062439-98b95a487749 h1:G0zRpRnpZ8sAZ5E5IRB6x7np9iuulPIWE+y3I/xGNfo=
github.com/libp2p/go-libp2p-core v0.5.4-0.20200508062439-98b95a487749/go.mod h1:uN7L2D4EvPCvzSH5SrhR72UWbnSGpt5/a35Sm4upn4Y= github.com/libp2p/go-libp2p-core v0.5.4-0.20200508062439-98b95a487749/go.mod h1:uN7L2D4EvPCvzSH5SrhR72UWbnSGpt5/a35Sm4upn4Y=
github.com/libp2p/go-libp2p-core v0.5.4-0.20200511073005-dabf5bbfb028 h1:nQb4SDWcadn/kpWtMwsWweogIzYviVE5qOMT42bkyNE=
github.com/libp2p/go-libp2p-core v0.5.4-0.20200511073005-dabf5bbfb028/go.mod h1:uN7L2D4EvPCvzSH5SrhR72UWbnSGpt5/a35Sm4upn4Y=
github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ= github.com/libp2p/go-msgio v0.0.4/go.mod h1:63lBBgOTDKQL6EWazRMCwXsEeEeK9O2Cd+0+6OOuipQ=
github.com/libp2p/go-openssl v0.0.4 h1:d27YZvLoTyMhIN4njrkr8zMDOM4lfpHIp6A+TK9fovg= github.com/libp2p/go-openssl v0.0.4 h1:d27YZvLoTyMhIN4njrkr8zMDOM4lfpHIp6A+TK9fovg=
github.com/libp2p/go-openssl v0.0.4/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc= github.com/libp2p/go-openssl v0.0.4/go.mod h1:unDrJpgy3oFr+rqXsarWifmJuNnJR4chtO1HmaZjggc=
......
...@@ -122,9 +122,9 @@ func (pb *dsProtoBook) SupportsProtocols(p peer.ID, protos ...string) ([]string, ...@@ -122,9 +122,9 @@ func (pb *dsProtoBook) SupportsProtocols(p peer.ID, protos ...string) ([]string,
return res, nil return res, nil
} }
func (pb *dsProtoBook) SupportsAnyProtocol(p peer.ID, protos ...string) (bool, error) { func (pb *dsProtoBook) FirstSupportedProtocol(p peer.ID, protos ...string) (string, error) {
if err := p.Validate(); err != nil { if err := p.Validate(); err != nil {
return false, err return "", err
} }
s := pb.segments.get(p) s := pb.segments.get(p)
...@@ -133,15 +133,15 @@ func (pb *dsProtoBook) SupportsAnyProtocol(p peer.ID, protos ...string) (bool, e ...@@ -133,15 +133,15 @@ func (pb *dsProtoBook) SupportsAnyProtocol(p peer.ID, protos ...string) (bool, e
pmap, err := pb.getProtocolMap(p) pmap, err := pb.getProtocolMap(p)
if err != nil { if err != nil {
return false, err return "", err
} }
for _, proto := range protos { for _, proto := range protos {
if _, ok := pmap[proto]; ok { if _, ok := pmap[proto]; ok {
return true, nil return proto, nil
} }
} }
return false, nil return "", nil
} }
func (pb *dsProtoBook) RemoveProtocols(p peer.ID, protos ...string) error { func (pb *dsProtoBook) RemoveProtocols(p peer.ID, protos ...string) error {
......
...@@ -164,9 +164,9 @@ func (pb *memoryProtoBook) SupportsProtocols(p peer.ID, protos ...string) ([]str ...@@ -164,9 +164,9 @@ func (pb *memoryProtoBook) SupportsProtocols(p peer.ID, protos ...string) ([]str
return out, nil return out, nil
} }
func (pb *memoryProtoBook) SupportsAnyProtocol(p peer.ID, protos ...string) (bool, error) { func (pb *memoryProtoBook) FirstSupportedProtocol(p peer.ID, protos ...string) (string, error) {
if err := p.Validate(); err != nil { if err := p.Validate(); err != nil {
return false, err return "", err
} }
s := pb.segments.get(p) s := pb.segments.get(p)
...@@ -175,8 +175,8 @@ func (pb *memoryProtoBook) SupportsAnyProtocol(p peer.ID, protos ...string) (boo ...@@ -175,8 +175,8 @@ func (pb *memoryProtoBook) SupportsAnyProtocol(p peer.ID, protos ...string) (boo
for _, proto := range protos { for _, proto := range protos {
if _, ok := s.protocols[p][proto]; ok { if _, ok := s.protocols[p][proto]; ok {
return true, nil return proto, nil
} }
} }
return false, nil return "", nil
} }
...@@ -243,17 +243,17 @@ func testPeerstoreProtoStore(ps pstore.Peerstore) func(t *testing.T) { ...@@ -243,17 +243,17 @@ func testPeerstoreProtoStore(ps pstore.Peerstore) func(t *testing.T) {
t.Fatal("got wrong supported array: ", supported) t.Fatal("got wrong supported array: ", supported)
} }
b, err := ps.SupportsAnyProtocol(p1, "q", "w", "a", "y", "b") b, err := ps.FirstSupportedProtocol(p1, "q", "w", "a", "y", "b")
require.NoError(t, err) require.NoError(t, err)
require.True(t, b) require.Equal(t, "a", b)
b, err = ps.SupportsAnyProtocol(p1, "a") b, err = ps.FirstSupportedProtocol(p1, "q", "x", "z")
require.NoError(t, err) require.NoError(t, err)
require.True(t, b) require.Empty(t, b)
b, err = ps.SupportsAnyProtocol(p1, "q") b, err = ps.FirstSupportedProtocol(p1, "a")
require.NoError(t, err) require.NoError(t, err)
require.False(t, b) require.Equal(t, "a", b)
protos = []string{"other", "yet another", "one more"} protos = []string{"other", "yet another", "one more"}
err = ps.SetProtocols(p1, protos...) err = ps.SetProtocols(p1, protos...)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment