Documentation ¶
Overview ¶
Package mux provides a RPC implementation with connection multiplexing.
Index ¶
- Variables
- func FindNodeInBP(id *proto.RawNodeID) (node *proto.Node, err error)
- func GetCurrentBP() (bpNodeID proto.NodeID, err error)
- func GetNodeAddr(id *proto.RawNodeID) (addr string, err error)
- func GetNodeInfo(id *proto.RawNodeID) (nodeInfo *proto.Node, err error)
- func NewDirectResolver() naconn.Resolver
- func NewOneOffMuxConn(conn net.Conn) (net.Conn, error)
- func NewResolver() naconn.Resolver
- func PingBP(node *proto.Node, BPNodeID proto.NodeID) (err error)
- func RegisterNodeToBP(timeout time.Duration) (err error)
- func RequestBP(method string, req interface{}, resp interface{}) (err error)
- func ServeMux(ctx context.Context, server *nrpc.Server, rawStream io.ReadWriteCloser, ...)
- func SetCurrentBP(bpNodeID proto.NodeID)
- type Caller
- type PersistentCaller
- type RawCaller
- type Resolver
- type Server
- type ServiceMap
- type Session
- type SessionPool
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoChiefBlockProducerAvailable defines failure on find chief block producer. ErrNoChiefBlockProducerAvailable = errors.New("no chief block producer found") )
Functions ¶
func FindNodeInBP ¶
FindNodeInBP find node in block producer dht service.
func GetCurrentBP ¶
GetCurrentBP returns nearest hash distance block producer as current node chief block producer.
func GetNodeAddr ¶
GetNodeAddr tries best to get node addr.
func GetNodeInfo ¶
GetNodeInfo tries best to get node info.
func NewDirectResolver ¶
NewDirectResolver returns a Resolver which resolves the direct RPC server address of the target node ID.
func NewOneOffMuxConn ¶
NewOneOffMuxConn wraps a raw conn as a mux.Stream to access a rpc/mux.Server.
Combine this with rpc.NewClient:
Dial conn with a corresponding dialer of RPC server Wrap conn as stream with NewOneOffMuxConn Call rpc.NewClient(stream) to get client.
func NewResolver ¶
NewResolver returns a Resolver which resolves the mux-RPC server address of the target node ID.
func RegisterNodeToBP ¶
RegisterNodeToBP registers the current node to bp network.
func ServeMux ¶
func ServeMux( ctx context.Context, server *nrpc.Server, rawStream io.ReadWriteCloser, remote *proto.RawNodeID, )
ServeMux takes conn and serves as a multiplexing server.
func SetCurrentBP ¶
SetCurrentBP sets current node chief block producer.
Types ¶
type PersistentCaller ¶
type PersistentCaller struct {
*rpc.PersistentCaller
}
PersistentCaller is a wrapper for session pooling and RPC calling.
func NewPersistentCaller ¶
func NewPersistentCaller(target proto.NodeID) *PersistentCaller
NewPersistentCaller returns a persistent RPCCaller.
IMPORTANT: If a PersistentCaller is firstly used by a DHT.Ping, which is an anonymous ETLS connection. It should not be used by any other RPC except DHT.Ping.
func (*PersistentCaller) New ¶
func (c *PersistentCaller) New() rpc.PCaller
New returns brand new persistent caller.
type RawCaller ¶
RawCaller defines a raw rpc caller without any encryption.
func NewRawCaller ¶
NewRawCaller creates the raw rpc caller to target node.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver implements the node ID resolver using BP network with mux-RPC protocol.
type Server ¶
Server is the RPC server struct.
func NewServerWithService ¶
func NewServerWithService(serviceMap ServiceMap) (server *Server, err error)
NewServerWithService returns a new Server and registers the Server.ServiceMap.
func (*Server) WithAcceptConnFunc ¶
func (s *Server) WithAcceptConnFunc(f rpc.AcceptConn) *Server
WithAcceptConnFunc resets the AcceptConn function of server.
type Session ¶
Session is the Session type of SessionPool.
type SessionPool ¶
SessionPool is the struct type of session pool.
func GetSessionPoolInstance ¶
func GetSessionPoolInstance() *SessionPool
GetSessionPoolInstance return default SessionPool instance with rpc.DefaultDialer.
func (*SessionPool) Close ¶
func (p *SessionPool) Close() error
Close closes all sessions in the pool.
func (*SessionPool) Get ¶
Get returns existing session to the node, if not exist try best to create one.
func (*SessionPool) GetEx ¶
GetEx returns an one-off connection if it's anonymous, otherwise returns existing session with Get.
func (*SessionPool) Len ¶
func (p *SessionPool) Len() (total int)
Len returns the session counts in the pool.
func (*SessionPool) Remove ¶
func (p *SessionPool) Remove(id proto.NodeID)
Remove the node sessions in the pool.