github.com/koko1123/flow-go-1@v0.29.6/network/p2p/subscription.go (about) 1 package p2p 2 3 import "github.com/libp2p/go-libp2p/core/peer" 4 5 // SubscriptionProvider provides a list of topics a peer is subscribed to. 6 type SubscriptionProvider interface { 7 // GetSubscribedTopics returns all the subscriptions of a peer within the pubsub network. 8 // Note that the current peer must be subscribed to the topic for it to the same topics in order 9 // to query for other peers, e.g., if current peer has subscribed to topics A and B, and peer1 10 // has subscribed to topics A, B, and C, then GetSubscribedTopics(peer1) will return A and B. Since this peer 11 // has not subscribed to topic C, it will not be able to query for other peers subscribed to topic C. 12 GetSubscribedTopics(pid peer.ID) []string 13 } 14 15 // TopicProvider provides a low-level abstraction for pubsub to perform topic-related queries. 16 // This abstraction is provided to encapsulate the pubsub implementation details from the rest of the codebase. 17 type TopicProvider interface { 18 // GetTopics returns all the topics within the pubsub network that the current peer has subscribed to. 19 GetTopics() []string 20 21 // ListPeers returns all the peers subscribed to a topic. 22 // Note that the current peer must be subscribed to the topic for it to query for other peers. 23 // If the current peer is not subscribed to the topic, an empty list is returned. 24 // For example, if current peer has subscribed to topics A and B, then ListPeers only return 25 // subscribed peers for topics A and B, and querying for topic C will return an empty list. 26 ListPeers(topic string) []peer.ID 27 }