mux

package
v0.0.0-...-020e20f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 1, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package mux provides a RPC implementation with connection multiplexing.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoChiefBlockProducerAvailable defines failure on find chief block producer.
	ErrNoChiefBlockProducerAvailable = errors.New("no chief block producer found")
)

Functions

func FindNodeInBP

func FindNodeInBP(id *proto.RawNodeID) (node *proto.Node, err error)

FindNodeInBP find node in block producer dht service.

func GetCurrentBP

func GetCurrentBP() (bpNodeID proto.NodeID, err error)

GetCurrentBP returns nearest hash distance block producer as current node chief block producer.

func GetNodeAddr

func GetNodeAddr(id *proto.RawNodeID) (addr string, err error)

GetNodeAddr tries best to get node addr.

func GetNodeInfo

func GetNodeInfo(id *proto.RawNodeID) (nodeInfo *proto.Node, err error)

GetNodeInfo tries best to get node info.

func NewDirectResolver

func NewDirectResolver() naconn.Resolver

NewDirectResolver returns a Resolver which resolves the direct RPC server address of the target node ID.

func NewOneOffMuxConn

func NewOneOffMuxConn(conn net.Conn) (net.Conn, error)

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

func NewResolver() naconn.Resolver

NewResolver returns a Resolver which resolves the mux-RPC server address of the target node ID.

func PingBP

func PingBP(node *proto.Node, BPNodeID proto.NodeID) (err error)

PingBP Send DHT.Ping Request with Anonymous ETLS session.

func RegisterNodeToBP

func RegisterNodeToBP(timeout time.Duration) (err error)

RegisterNodeToBP registers the current node to bp network.

func RequestBP

func RequestBP(method string, req interface{}, resp interface{}) (err error)

RequestBP sends request to main chain.

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

func SetCurrentBP(bpNodeID proto.NodeID)

SetCurrentBP sets current node chief block producer.

Types

type Caller

type Caller struct {
	*rpc.Caller
}

Caller is a wrapper for session pooling and RPC calling.

func NewCaller

func NewCaller() *Caller

NewCaller returns a new RPCCaller.

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

type RawCaller struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

RawCaller defines a raw rpc caller without any encryption.

func NewRawCaller

func NewRawCaller(targetAddr string) *RawCaller

NewRawCaller creates the raw rpc caller to target node.

func (*RawCaller) Call

func (c *RawCaller) Call(method string, args interface{}, reply interface{}) (err error)

Call issues client rpc call.

func (*RawCaller) Close

func (c *RawCaller) Close()

Close release underlying connection resources.

func (*RawCaller) New

func (c *RawCaller) New() rpc.PCaller

New returns brand new caller.

func (*RawCaller) Target

func (c *RawCaller) Target() string

Target returns the request target for logging purpose.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver implements the node ID resolver using BP network with mux-RPC protocol.

func (*Resolver) Resolve

func (r *Resolver) Resolve(id *proto.RawNodeID) (string, error)

Resolve implements the node ID resolver using the BP network with mux-RPC protocol.

func (*Resolver) ResolveEx

func (r *Resolver) ResolveEx(id *proto.RawNodeID) (*proto.Node, error)

ResolveEx implements the node ID resolver extended method using the BP network with mux-RPC protocol.

type Server

type Server struct {
	*rpc.Server
}

Server is the RPC server struct.

func NewServer

func NewServer() *Server

NewServer returns a new Server.

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 ServiceMap

type ServiceMap rpc.ServiceMap

ServiceMap maps service name to service instance.

type Session

type Session struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Session is the Session type of SessionPool.

func (*Session) Close

func (s *Session) Close() error

Close closes the session.

func (*Session) Get

func (s *Session) Get() (conn rpc.Client, err error)

Get returns new connection from session.

func (*Session) Len

func (s *Session) Len() int

Len returns physical connection count.

type SessionPool

type SessionPool struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

func (p *SessionPool) Get(id proto.NodeID) (conn rpc.Client, err error)

Get returns existing session to the node, if not exist try best to create one.

func (*SessionPool) GetEx

func (p *SessionPool) GetEx(id proto.NodeID, isAnonymous bool) (conn rpc.Client, err error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL