From 43dfa5faf448bc07b66ca246fb95edd4a1301dc2 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Fri, 8 May 2020 11:47:54 +0530 Subject: [PATCH 1/3] check if peer supports a protocol without allocation --- peerstore/peerstore.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/peerstore/peerstore.go b/peerstore/peerstore.go index 496d34a..f61a096 100644 --- a/peerstore/peerstore.go +++ b/peerstore/peerstore.go @@ -233,5 +233,12 @@ type ProtoBook interface { AddProtocols(peer.ID, ...string) error SetProtocols(peer.ID, ...string) error RemoveProtocols(peer.ID, ...string) error + + // SupportsProtocols returns the set of protocols the peer supports from among the given protocols. + // If the returned error is not nil, the result is indeterminate. SupportsProtocols(peer.ID, ...string) ([]string, error) + + // IsProtocolSupported returns true if the peer supports the given protocol and false otherwise. + // If the returned error is not nil, the result is indeterminate. + IsProtocolSupported(peer.ID, string) (bool, error) } From 98b95a4877496d4e57871d8d7eac91e53b85ce63 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Fri, 8 May 2020 11:54:39 +0530 Subject: [PATCH 2/3] non alloc version --- peerstore/peerstore.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/peerstore/peerstore.go b/peerstore/peerstore.go index f61a096..3ea50c2 100644 --- a/peerstore/peerstore.go +++ b/peerstore/peerstore.go @@ -238,7 +238,7 @@ type ProtoBook interface { // If the returned error is not nil, the result is indeterminate. SupportsProtocols(peer.ID, ...string) ([]string, error) - // IsProtocolSupported returns true if the peer supports the given protocol and false otherwise. + // SupportsAnyProtocol returns true if the peer supports ATLEAST ONE of the given protocols and false otherwise. // If the returned error is not nil, the result is indeterminate. - IsProtocolSupported(peer.ID, string) (bool, error) + SupportsAnyProtocol(peer.ID, ...string) (bool, error) } From dabf5bbfb028cec2205a10ca3f082d3126ccc017 Mon Sep 17 00:00:00 2001 From: Aarsh Shah Date: Mon, 11 May 2020 13:00:05 +0530 Subject: [PATCH 3/3] changes as per review --- peerstore/peerstore.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/peerstore/peerstore.go b/peerstore/peerstore.go index 3ea50c2..3c621b5 100644 --- a/peerstore/peerstore.go +++ b/peerstore/peerstore.go @@ -238,7 +238,8 @@ type ProtoBook interface { // If the returned error is not nil, the result is indeterminate. SupportsProtocols(peer.ID, ...string) ([]string, error) - // SupportsAnyProtocol returns true if the peer supports ATLEAST ONE of the given protocols and false otherwise. + // FirstSupportedProtocol returns the first protocol that the peer supports among the given protocols. + // If the peer does not support any of the given protocols, this function will return an empty string and a nil error. // If the returned error is not nil, the result is indeterminate. - SupportsAnyProtocol(peer.ID, ...string) (bool, error) + FirstSupportedProtocol(peer.ID, ...string) (string, error) }