github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/p2p/unicast_manager.go (about) 1 package p2p 2 3 import ( 4 "context" 5 6 libp2pnet "github.com/libp2p/go-libp2p/core/network" 7 "github.com/libp2p/go-libp2p/core/peer" 8 9 "github.com/onflow/flow-go/network/p2p/unicast/protocols" 10 ) 11 12 // UnicastManager manages libp2p stream negotiation and creation, which is utilized for unicast dispatches. 13 type UnicastManager interface { 14 // WithDefaultHandler sets the default stream handler for this unicast manager. The default handler is utilized 15 // as the core handler for other unicast protocols, e.g., compressions. 16 SetDefaultHandler(defaultHandler libp2pnet.StreamHandler) 17 // Register registers given protocol name as preferred unicast. Each invocation of register prioritizes the current protocol 18 // over previously registered ones. 19 // All errors returned from this function can be considered benign. 20 Register(unicast protocols.ProtocolName) error 21 // CreateStream tries establishing a libp2p stream to the remote peer id. It tries creating streams in the descending order of preference until 22 // it either creates a successful stream or runs out of options. Creating stream on each protocol is tried at most `maxAttempts`, and then falls 23 // back to the less preferred one. 24 // All errors returned from this function can be considered benign. 25 CreateStream(ctx context.Context, peerID peer.ID) (libp2pnet.Stream, error) 26 }