Documentation ¶
Index ¶
- Constants
- func NewRPCBlock(lb *blockchain.DomainBlock) *pb.RpcBlock
- func NewRPCBlockHeader(lb *blockchain.DomainBlock) *pb.RpcBlockHeader
- func NewRPCBlockLevelParents(lb *blockchain.DomainBlock) []*pb.RpcBlockLevelParents
- func P2PServer(listen []string, mc *domain.Metchain, bc *blockchain.Blockchain) (*p2pServer, error)
- func RPCServer(listen []string, maxc int, mc *domain.Metchain, bc *blockchain.Blockchain) (*rpcServer, error)
- type Connection
- type GRPCClient
- type NetAdapter
- func (na *NetAdapter) ID() *id.ID
- func (na *NetAdapter) P2PBroadcast(netConnections []*NetConnection, message appmessage.Message) error
- func (na *NetAdapter) P2PConnect(address string) error
- func (na *NetAdapter) P2PConnectionCount() int
- func (na *NetAdapter) P2PConnections() []*NetConnection
- func (na *NetAdapter) SetP2PRouterInitializer(routerInitializer RouterInitializer)
- func (na *NetAdapter) SetRPCRouterInitializer(routerInitializer RouterInitializer)
- func (na *NetAdapter) Start() error
- func (na *NetAdapter) Stop() error
- type NetConnection
- func (c *NetConnection) Address() string
- func (c *NetConnection) Disconnect()
- func (c *NetConnection) ID() *id.ID
- func (c *NetConnection) IsOutbound() bool
- func (c *NetConnection) NetAddress() *appmessage.NetAddress
- func (c *NetConnection) SetID(peerID *id.ID)
- func (c *NetConnection) SetOnInvalidMessageHandler(onInvalidMessageHandler server.OnInvalidMessageHandler)
- func (c *NetConnection) String() string
- type OnConnectedHandler
- type OnDisconnectedHandler
- type OnInvalidMessageHandler
- type RPCClient
- type RPC_MessageStreamClient
- type RouterInitializer
- type Server
Constants ¶
const RPCMaxMessageSize = 1024 * 1024 * 1024 // 1 GB
RPCMaxMessageSize is the max message size for the RPC server to send and receive
Variables ¶
This section is empty.
Functions ¶
func NewRPCBlock ¶
func NewRPCBlock(lb *blockchain.DomainBlock) *pb.RpcBlock
func NewRPCBlockHeader ¶
func NewRPCBlockHeader(lb *blockchain.DomainBlock) *pb.RpcBlockHeader
func NewRPCBlockLevelParents ¶
func NewRPCBlockLevelParents(lb *blockchain.DomainBlock) []*pb.RpcBlockLevelParents
func P2PServer ¶
func P2PServer(listen []string, mc *domain.Metchain, bc *blockchain.Blockchain) (*p2pServer, error)
func RPCServer ¶
func RPCServer(listen []string, maxc int, mc *domain.Metchain, bc *blockchain.Blockchain) (*rpcServer, error)
Types ¶
type Connection ¶
type Connection interface { fmt.Stringer Start(router *routerpkg.Router) Disconnect() IsConnected() bool IsOutbound() bool SetOnDisconnectedHandler(onDisconnectedHandler OnDisconnectedHandler) SetOnInvalidMessageHandler(onInvalidMessageHandler OnInvalidMessageHandler) Address() *net.TCPAddr }
Connection represents a server connection.
type GRPCClient ¶
type GRPCClient struct {
// contains filtered or unexported fields
}
GRPCClient is a gRPC-based RPC client
func Connect ¶
func Connect(address string) (*GRPCClient, error)
Connect connects to the RPC server with the given address
type NetAdapter ¶
type NetAdapter struct {
// contains filtered or unexported fields
}
NetAdapter is an abstraction layer over networking. This type expects a RouteInitializer function. This function weaves together the various "routes" (messages and message handlers) without exposing anything related to networking internals.
func NewNetAdapter ¶
func NewNetAdapter(cfg *infraconfig.Config, bc *blockchain.Blockchain) (*NetAdapter, error)
NewNetAdapter creates and starts a new NetAdapter on the given listeningPort
func (*NetAdapter) ID ¶
func (na *NetAdapter) ID() *id.ID
ID returns this netAdapter's ID in the network
func (*NetAdapter) P2PBroadcast ¶
func (na *NetAdapter) P2PBroadcast(netConnections []*NetConnection, message appmessage.Message) error
P2PBroadcast sends the given `message` to every peer corresponding to each NetConnection in the given netConnections
func (*NetAdapter) P2PConnect ¶
func (na *NetAdapter) P2PConnect(address string) error
P2PConnect tells the NetAdapter's underlying p2p server to initiate a connection to the given address
func (*NetAdapter) P2PConnectionCount ¶
func (na *NetAdapter) P2PConnectionCount() int
P2PConnectionCount returns the count of the connected p2p connections
func (*NetAdapter) P2PConnections ¶
func (na *NetAdapter) P2PConnections() []*NetConnection
P2PConnections returns a list of p2p connections currently connected and active
func (*NetAdapter) SetP2PRouterInitializer ¶
func (na *NetAdapter) SetP2PRouterInitializer(routerInitializer RouterInitializer)
SetP2PRouterInitializer sets the p2pRouterInitializer function for the net adapter
func (*NetAdapter) SetRPCRouterInitializer ¶
func (na *NetAdapter) SetRPCRouterInitializer(routerInitializer RouterInitializer)
SetRPCRouterInitializer sets the rpcRouterInitializer function for the net adapter
func (*NetAdapter) Start ¶
func (na *NetAdapter) Start() error
type NetConnection ¶
type NetConnection struct {
// contains filtered or unexported fields
}
NetConnection is a wrapper to a server connection for use by services external to NetAdapter
func (*NetConnection) Address ¶
func (c *NetConnection) Address() string
Address returns the address associated with this connection
func (*NetConnection) Disconnect ¶
func (c *NetConnection) Disconnect()
Disconnect disconnects the given connection
func (*NetConnection) ID ¶
func (c *NetConnection) ID() *id.ID
ID returns the ID associated with this connection
func (*NetConnection) IsOutbound ¶
func (c *NetConnection) IsOutbound() bool
IsOutbound returns whether the connection is outbound
func (*NetConnection) NetAddress ¶
func (c *NetConnection) NetAddress() *appmessage.NetAddress
NetAddress returns the NetAddress associated with this connection
func (*NetConnection) SetID ¶
func (c *NetConnection) SetID(peerID *id.ID)
SetID sets the ID associated with this connection
func (*NetConnection) SetOnInvalidMessageHandler ¶
func (c *NetConnection) SetOnInvalidMessageHandler(onInvalidMessageHandler server.OnInvalidMessageHandler)
SetOnInvalidMessageHandler sets the invalid message handler for this connection
func (*NetConnection) String ¶
func (c *NetConnection) String() string
type OnConnectedHandler ¶
type OnConnectedHandler func(connection Connection) error
type OnDisconnectedHandler ¶
type OnDisconnectedHandler func()
OnDisconnectedHandler is a function that is to be called once a Connection has been disconnected.
type OnInvalidMessageHandler ¶
type OnInvalidMessageHandler func(err error)
OnInvalidMessageHandler is a function that is to be called when an invalid message (cannot be parsed/doesn't have a route) was received from a connection.
type RPCClient ¶
type RPCClient interface {
MessageStream(ctx context.Context, opts ...grpc.CallOption) (RPC_MessageStreamClient, error)
}
RPCClient is the client API for RPC service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
func NewRPCClient ¶
func NewRPCClient(cc grpc.ClientConnInterface) RPCClient
type RPC_MessageStreamClient ¶
type RPC_MessageStreamClient interface { Send(message *proto.MetchainMessage) error Recv() (*proto.MetchainMessage, error) grpc.ClientStream }
type RouterInitializer ¶
type RouterInitializer func(*routerpkg.Router, *NetConnection)
type Server ¶
type Server interface { Start() error Stop() error SetOnConnectedHandler(onConnectedHandler OnConnectedHandler) Connect(address string) (Connection, error) }