CovenantSQL: github.com/CovenantSQL/CovenantSQL/rpc/mux Index | Files

package mux

import "github.com/CovenantSQL/CovenantSQL/rpc/mux"

Package mux provides a RPC implementation with connection multiplexing.

Index

Package Files

doc.go pool.go rawcaller.go resolve.go serve.go wrapper.go

Variables

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

func FindNodeInBP Uses

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

FindNodeInBP find node in block producer dht service.

func GetCurrentBP Uses

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

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

func GetNodeAddr Uses

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

GetNodeAddr tries best to get node addr.

func GetNodeInfo Uses

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

GetNodeInfo tries best to get node info.

func NewDirectResolver Uses

func NewDirectResolver() naconn.Resolver

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

func NewOneOffMuxConn Uses

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 Uses

func NewResolver() naconn.Resolver

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

func PingBP Uses

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

PingBP Send DHT.Ping Request with Anonymous ETLS session.

func RegisterNodeToBP Uses

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

RegisterNodeToBP registers the current node to bp network.

func RequestBP Uses

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

RequestBP sends request to main chain.

func ServeMux Uses

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 Uses

func SetCurrentBP(bpNodeID proto.NodeID)

SetCurrentBP sets current node chief block producer.

type Caller Uses

type Caller struct {
    *rpc.Caller
}

Caller is a wrapper for session pooling and RPC calling.

func NewCaller Uses

func NewCaller() *Caller

NewCaller returns a new RPCCaller.

type PersistentCaller Uses

type PersistentCaller struct {
    *rpc.PersistentCaller
}

PersistentCaller is a wrapper for session pooling and RPC calling.

func NewPersistentCaller Uses

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 Uses

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

New returns brand new persistent caller.

type RawCaller Uses

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

RawCaller defines a raw rpc caller without any encryption.

func NewRawCaller Uses

func NewRawCaller(targetAddr string) *RawCaller

NewRawCaller creates the raw rpc caller to target node.

func (*RawCaller) Call Uses

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

Call issues client rpc call.

func (*RawCaller) Close Uses

func (c *RawCaller) Close()

Close release underlying connection resources.

func (*RawCaller) New Uses

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

New returns brand new caller.

func (*RawCaller) Target Uses

func (c *RawCaller) Target() string

Target returns the request target for logging purpose.

type Resolver Uses

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

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

func (*Resolver) Resolve Uses

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 Uses

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 Uses

type Server struct {
    *rpc.Server
}

Server is the RPC server struct.

func NewServer Uses

func NewServer() *Server

NewServer returns a new Server.

func NewServerWithService Uses

func NewServerWithService(serviceMap ServiceMap) (server *Server, err error)

NewServerWithService returns a new Server and registers the Server.ServiceMap.

func (*Server) WithAcceptConnFunc Uses

func (s *Server) WithAcceptConnFunc(f rpc.AcceptConn) *Server

WithAcceptConnFunc resets the AcceptConn function of server.

type ServiceMap Uses

type ServiceMap rpc.ServiceMap

ServiceMap maps service name to service instance.

type Session Uses

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

Session is the Session type of SessionPool.

func (*Session) Close Uses

func (s *Session) Close() error

Close closes the session.

func (*Session) Get Uses

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

Get returns new connection from session.

func (*Session) Len Uses

func (s *Session) Len() int

Len returns physical connection count.

type SessionPool Uses

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

SessionPool is the struct type of session pool.

func GetSessionPoolInstance Uses

func GetSessionPoolInstance() *SessionPool

GetSessionPoolInstance return default SessionPool instance with rpc.DefaultDialer.

func (*SessionPool) Close Uses

func (p *SessionPool) Close() error

Close closes all sessions in the pool.

func (*SessionPool) Get Uses

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 Uses

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 Uses

func (p *SessionPool) Len() (total int)

Len returns the session counts in the pool.

func (*SessionPool) Remove Uses

func (p *SessionPool) Remove(id proto.NodeID)

Remove the node sessions in the pool.

Package mux imports 18 packages (graph) and is imported by 20 packages. Updated 2019-08-12. Refresh now. Tools for package owners.