github.com/koko1123/flow-go-1@v0.29.6/network/middleware.go (about) 1 // (c) 2019 Dapper Labs - ALL RIGHTS RESERVED 2 3 package network 4 5 import ( 6 "github.com/ipfs/go-datastore" 7 "github.com/libp2p/go-libp2p/core/peer" 8 "github.com/libp2p/go-libp2p/core/protocol" 9 10 "github.com/koko1123/flow-go-1/model/flow" 11 "github.com/koko1123/flow-go-1/module/component" 12 "github.com/koko1123/flow-go-1/network/channels" 13 ) 14 15 // Middleware represents the middleware layer, which manages the connections to 16 // our direct neighbours on the network. It handles the creation & teardown of 17 // connections, as well as reading & writing to/from the connections. 18 type Middleware interface { 19 component.Component 20 21 // SetOverlay sets the overlay used by the middleware. This must be called before the middleware can be Started. 22 SetOverlay(Overlay) 23 24 // SendDirect sends msg on a 1-1 direct connection to the target ID. It models a guaranteed delivery asynchronous 25 // direct one-to-one connection on the underlying network. No intermediate node on the overlay is utilized 26 // as the router. 27 // 28 // Dispatch should be used whenever guaranteed delivery to a specific target is required. Otherwise, Publish is 29 // a more efficient candidate. 30 // All errors returned from this function can be considered benign. 31 SendDirect(msg *OutgoingMessageScope) error 32 33 // Publish publishes a message on the channel. It models a distributed broadcast where the message is meant for all or 34 // a many nodes subscribing to the channel. It does not guarantee the delivery though, and operates on a best 35 // effort. 36 // All errors returned from this function can be considered benign. 37 Publish(msg *OutgoingMessageScope) error 38 39 // Subscribe subscribes the middleware to a channel. 40 // No errors are expected during normal operation. 41 Subscribe(channel channels.Channel) error 42 43 // Unsubscribe unsubscribes the middleware from a channel. 44 // All errors returned from this function can be considered benign. 45 Unsubscribe(channel channels.Channel) error 46 47 // UpdateNodeAddresses fetches and updates the addresses of all the authorized participants 48 // in the Flow protocol. 49 UpdateNodeAddresses() 50 51 // NewBlobService creates a new BlobService for the given channel. 52 NewBlobService(channel channels.Channel, store datastore.Batching, opts ...BlobServiceOption) BlobService 53 54 // NewPingService creates a new PingService for the given ping protocol ID. 55 NewPingService(pingProtocol protocol.ID, provider PingInfoProvider) PingService 56 57 IsConnected(nodeID flow.Identifier) (bool, error) 58 } 59 60 // Overlay represents the interface that middleware uses to interact with the 61 // overlay network layer. 62 type Overlay interface { 63 // Topology returns an identity list of nodes which this node should be directly connected to as peers 64 Topology() flow.IdentityList 65 66 // Identities returns a list of all Flow identities on the network 67 Identities() flow.IdentityList 68 69 // Identity returns the Identity associated with the given peer ID, if it exists 70 Identity(peer.ID) (*flow.Identity, bool) 71 72 Receive(*IncomingMessageScope) error 73 } 74 75 // Connection represents an interface to read from & write to a connection. 76 type Connection interface { 77 Send(msg interface{}) error 78 Receive() (interface{}, error) 79 }