github.com/koko1123/flow-go-1@v0.29.6/network/network.go (about)

     1  package network
     2  
     3  import (
     4  	"github.com/ipfs/go-datastore"
     5  	"github.com/libp2p/go-libp2p/core/protocol"
     6  
     7  	"github.com/koko1123/flow-go-1/model/flow"
     8  	"github.com/koko1123/flow-go-1/module/component"
     9  	"github.com/koko1123/flow-go-1/network/channels"
    10  )
    11  
    12  // Network represents the network layer of the node. It allows processes that
    13  // work across the peer-to-peer network to register themselves as an engine with
    14  // a unique engine ID. The returned conduit allows the process to communicate to
    15  // the same engine on other nodes across the network in a network-agnostic way.
    16  type Network interface {
    17  	component.Component
    18  	// Register will subscribe to the channel with the given engine and
    19  	// the engine will be notified with incoming messages on the channel.
    20  	// The returned Conduit can be used to send messages to engines on other nodes subscribed to the same channel
    21  	// On a single node, only one engine can be subscribed to a channel at any given time.
    22  	Register(channel channels.Channel, messageProcessor MessageProcessor) (Conduit, error)
    23  
    24  	// RegisterBlobService registers a BlobService on the given channel, using the given datastore to retrieve values.
    25  	// The returned BlobService can be used to request blocks from the network.
    26  	// TODO: We should return a function that can be called to unregister / close the BlobService
    27  	RegisterBlobService(channel channels.Channel, store datastore.Batching, opts ...BlobServiceOption) (BlobService, error)
    28  
    29  	// RegisterPingService registers a ping protocol handler for the given protocol ID
    30  	RegisterPingService(pingProtocolID protocol.ID, pingInfoProvider PingInfoProvider) (PingService, error)
    31  }
    32  
    33  // Adapter is a wrapper around the Network implementation. It only exposes message dissemination functionalities.
    34  // Adapter is meant to be utilized by the Conduit interface to send messages to the Network layer to be
    35  // delivered to the remote targets.
    36  type Adapter interface {
    37  	// UnicastOnChannel sends the message in a reliable way to the given recipient.
    38  	UnicastOnChannel(channels.Channel, interface{}, flow.Identifier) error
    39  
    40  	// PublishOnChannel sends the message in an unreliable way to all the given recipients.
    41  	PublishOnChannel(channels.Channel, interface{}, ...flow.Identifier) error
    42  
    43  	// MulticastOnChannel unreliably sends the specified event over the channel to randomly selected number of recipients
    44  	// selected from the specified targetIDs.
    45  	MulticastOnChannel(channels.Channel, interface{}, uint, ...flow.Identifier) error
    46  
    47  	// UnRegisterChannel unregisters the engine for the specified channel. The engine will no longer be able to send or
    48  	// receive messages from that channel.
    49  	UnRegisterChannel(channel channels.Channel) error
    50  }