Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "github.com/rs/zerolog" splitterNetwork "github.com/onflow/flow-go/engine/common/splitter/network" "github.com/onflow/flow-go/model/flow" "github.com/onflow/flow-go/network/channels" testnet "github.com/onflow/flow-go/utils/unittest/network" ) func main() { // create a mock network net := testnet.NewNetwork() // create a splitter network logger := zerolog.Nop() splitterNet := splitterNetwork.NewNetwork(net, logger) // generate an origin ID id, err := flow.HexStringToIdentifier("0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d0b75") if err != nil { fmt.Println(err) } // create engines engineProcessFunc := func(engineID int) testnet.EngineProcessFunc { return func(channel channels.Channel, originID flow.Identifier, event interface{}) error { fmt.Printf("Engine %d received message: channel=%v, originID=%v, event=%v\n", engineID, channel, originID, event) return nil } } engine1 := testnet.NewEngine().OnProcess(engineProcessFunc(1)) engine2 := testnet.NewEngine().OnProcess(engineProcessFunc(2)) engine3 := testnet.NewEngine().OnProcess(engineProcessFunc(3)) // register engines with splitter network channel := channels.Channel("foo-channel") _, err = splitterNet.Register(channel, engine1) if err != nil { fmt.Println(err) } _, err = splitterNet.Register(channel, engine2) if err != nil { fmt.Println(err) } _, err = splitterNet.Register(channel, engine3) if err != nil { fmt.Println(err) } // send message to network err = net.Send(channel, id, "foo") if err != nil { fmt.Println(err) } }
Output: Engine 1 received message: channel=foo-channel, originID=0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d0b75, event=foo Engine 2 received message: channel=foo-channel, originID=0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d0b75, event=foo Engine 3 received message: channel=foo-channel, originID=0194fdc2fa2ffcc041d3ff12045b73c86e4ff95ff662a5eee82abdf44a2d0b75, event=foo
Index ¶
- type Network
- func (n *Network) Register(channel channels.Channel, engine network.MessageProcessor) (network.Conduit, error)
- func (n *Network) RegisterBlobService(channel channels.Channel, store datastore.Batching, ...) (network.BlobService, error)
- func (n *Network) RegisterPingService(pid protocol.ID, provider network.PingInfoProvider) (network.PingService, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Network ¶
type Network struct { *component.ComponentManager // contains filtered or unexported fields }
Network is the splitter network. It is a wrapper around the default network implementation and should be passed in to engine constructors that require a network to register with. When an engine is registered with the splitter network, a splitter engine is created for the given channel (if one doesn't already exist) and the engine is registered with that splitter engine. As a result, multiple engines can register with the splitter network on the same channel and will each receive all events on that channel.
func NewNetwork ¶
NewNetwork returns a new splitter network.
func (*Network) Register ¶
func (n *Network) Register(channel channels.Channel, engine network.MessageProcessor) (network.Conduit, error)
Register will subscribe the given engine with the spitter on the given channel, and all registered engines will be notified with incoming messages on the channel. The returned Conduit can be used to send messages to engines on other nodes subscribed to the same channel
func (*Network) RegisterBlobService ¶ added in v0.23.9
func (n *Network) RegisterBlobService(channel channels.Channel, store datastore.Batching, opts ...network.BlobServiceOption) (network.BlobService, error)
func (*Network) RegisterPingService ¶ added in v0.23.9
func (n *Network) RegisterPingService(pid protocol.ID, provider network.PingInfoProvider) (network.PingService, error)