github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/network/converter/network.go (about)

     1  package converter
     2  
     3  import (
     4  	"github.com/onflow/flow-go/network"
     5  	"github.com/onflow/flow-go/network/channels"
     6  )
     7  
     8  type Network struct {
     9  	network.EngineRegistry
    10  	from channels.Channel
    11  	to   channels.Channel
    12  }
    13  
    14  var _ network.EngineRegistry = (*Network)(nil)
    15  
    16  func NewNetwork(net network.EngineRegistry, from channels.Channel, to channels.Channel) *Network {
    17  	return &Network{net, from, to}
    18  }
    19  
    20  func (n *Network) convert(channel channels.Channel) channels.Channel {
    21  	if channel == n.from {
    22  		return n.to
    23  	}
    24  	return channel
    25  }
    26  
    27  func (n *Network) Register(channel channels.Channel, engine network.MessageProcessor) (network.Conduit, error) {
    28  	return n.EngineRegistry.Register(n.convert(channel), engine)
    29  }