Documentation ¶
Index ¶
- Constants
- Variables
- func NewRPCClient(network, address string, timeout time.Duration, ...) (*rpc.Client, error)
- type Backend
- type BackendConfig
- type Client
- func (c *Client) Close() error
- func (c *Client) FastForward(ctx context.Context, req *FastForwardRequest, resp *FastForwardResponse) error
- func (c *Client) ForceSync(ctx context.Context, req *ForceSyncRequest, resp *ForceSyncResponse) error
- func (c *Client) Sync(ctx context.Context, req *SyncRequest, resp *SyncResponse) error
- type ClientProducer
- type CreateListenerFunc
- type CreateNetConnFunc
- type CreateSyncClientFunc
- type FastForwardRequest
- type FastForwardResponse
- type ForceSyncRequest
- type ForceSyncResponse
- type Lachesis
- type NewSyncClientFunc
- type Peer
- func (tr *Peer) Close() error
- func (tr *Peer) FastForward(ctx context.Context, target string, req *FastForwardRequest, ...) error
- func (tr *Peer) ForceSync(ctx context.Context, target string, req *ForceSyncRequest, ...) error
- func (tr *Peer) ReceiverChannel() <-chan *RPC
- func (tr *Peer) Sync(ctx context.Context, target string, req *SyncRequest, resp *SyncResponse) error
- type Producer
- type RPC
- type RPCClient
- type RPCResponse
- type SyncClient
- type SyncPeer
- type SyncRequest
- type SyncResponse
- type SyncServer
Constants ¶
const ( MethodSync = "Lachesis.Sync" MethodForceSync = "Lachesis.ForceSync" MethodFastForward = "Lachesis.FastForward" )
RPC Methods.
const (
// TCP is a Transmission Control Protocol.
TCP = "tcp"
)
Variables ¶
var ( ErrTransportStopped = errors.New("transport stopped") ErrClientProducerStopped = errors.New("client producer stopped") ErrReceiverIsBusy = errors.New("receiver is busy") ErrProcessingTimeout = errors.New("processing timeout") ErrBadResult = errors.New("bad result") ErrServerAlreadyRunning = errors.New("server already running") )
Errors.
Functions ¶
func NewRPCClient ¶
func NewRPCClient( network, address string, timeout time.Duration, createNetConnFunc CreateNetConnFunc) (*rpc.Client, error)
NewRPCClient creates new RPC client.
Types ¶
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend is sync server.
func NewBackend ¶
func NewBackend(conf *BackendConfig, logger logrus.FieldLogger, listenerFunc CreateListenerFunc) *Backend
NewBackend creates new sync Backend.
func (*Backend) ListenAndServe ¶
ListenAndServe starts sync server.
func (*Backend) ReceiverChannel ¶
ReceiverChannel returns a receiver channel.
type BackendConfig ¶
type BackendConfig struct { ReceiveTimeout time.Duration ProcessTimeout time.Duration IdleTimeout time.Duration }
BackendConfig is a configuration for a sync server.
func NewBackendConfig ¶
func NewBackendConfig() *BackendConfig
NewBackendConfig creates a default a sync server config.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a sync client.
func (*Client) FastForward ¶
func (c *Client) FastForward(ctx context.Context, req *FastForwardRequest, resp *FastForwardResponse) error
FastForward sends a fast forward request.
func (*Client) ForceSync ¶
func (c *Client) ForceSync(ctx context.Context, req *ForceSyncRequest, resp *ForceSyncResponse) error
ForceSync sends a force sync request.
func (*Client) Sync ¶
func (c *Client) Sync(ctx context.Context, req *SyncRequest, resp *SyncResponse) error
Sync sends a sync request.
type ClientProducer ¶
type ClientProducer interface { Pop(target string) (SyncClient, error) Push(target string, client SyncClient) Close() }
ClientProducer is an interface representing methods for producer of sync clients.
type CreateListenerFunc ¶
CreateListenerFunc creates a new network listener.
type CreateNetConnFunc ¶
CreateNetConnFunc is a function to create new network connection.
type CreateSyncClientFunc ¶
type CreateSyncClientFunc func(target string, timeout time.Duration) (SyncClient, error)
CreateSyncClientFunc is a function to create a sync client.
type FastForwardRequest ¶
type FastForwardRequest struct {
FromID uint64
}
FastForwardRequest request to start a fast forward catch up.
type FastForwardResponse ¶
type FastForwardResponse struct { FromID uint64 Block poset.Block Frame poset.Frame Snapshot []byte }
FastForwardResponse response with the snapshot data for fast forward request.
type ForceSyncRequest ¶
ForceSyncRequest after an initial sync to quickly catch up.
type ForceSyncResponse ¶
ForceSyncResponse response to an ForceSyncRequest.
type Lachesis ¶
type Lachesis struct {
// contains filtered or unexported fields
}
Lachesis implements Lachesis synchronization methods.
func NewLachesis ¶
func NewLachesis(done chan struct{}, receiver chan *RPC, receiveTimeout, processTimeout time.Duration) *Lachesis
NewLachesis creates new Lachesis RPC handler.
func (*Lachesis) FastForward ¶
func (r *Lachesis) FastForward( req *FastForwardRequest, resp *FastForwardResponse) error
FastForward handles fast forward requests.
func (*Lachesis) ForceSync ¶
func (r *Lachesis) ForceSync( req *ForceSyncRequest, resp *ForceSyncResponse) error
ForceSync handles force sync requests.
func (*Lachesis) Sync ¶
func (r *Lachesis) Sync( req *SyncRequest, resp *SyncResponse) error
Sync handles sync requests.
type NewSyncClientFunc ¶
type NewSyncClientFunc func(target string) (SyncClient, error)
NewSyncClientFunc creates a new sync client.
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer implements SyncPeer interface.
func NewTransport ¶
func NewTransport(logger logrus.FieldLogger, clientProducer ClientProducer, server SyncServer) *Peer
NewTransport creates a net transport.
func (*Peer) FastForward ¶
func (tr *Peer) FastForward(ctx context.Context, target string, req *FastForwardRequest, resp *FastForwardResponse) error
FastForward creates a fast forward request to a specific node.
func (*Peer) ForceSync ¶
func (tr *Peer) ForceSync(ctx context.Context, target string, req *ForceSyncRequest, resp *ForceSyncResponse) error
ForceSync creates a force sync request to a specific node.
func (*Peer) ReceiverChannel ¶
ReceiverChannel returns a sync server receiver channel.
func (*Peer) Sync ¶
func (tr *Peer) Sync(ctx context.Context, target string, req *SyncRequest, resp *SyncResponse) error
Sync creates a sync request to a specific node.
type Producer ¶
type Producer struct {
// contains filtered or unexported fields
}
Producer creates new sync clients. Stores a limited number of clients in a pool for reuse.
func NewProducer ¶
func NewProducer(poolSize int, connectTimeout time.Duration, createClientFunc CreateSyncClientFunc) *Producer
NewProducer creates new producer of sync clients.
func (*Producer) ConnLen ¶
ConnLen returns the number of connections in a pool for a specific target.
func (*Producer) Pop ¶
func (p *Producer) Pop(target string) (SyncClient, error)
Pop creates a new connection for a target or re-uses an existing connection.
func (*Producer) Push ¶
func (p *Producer) Push(target string, client SyncClient)
Push saves a connection in a pool.
type RPC ¶
type RPC struct { Command interface{} RespChan chan<- *RPCResponse }
RPC has a command, and provides a response mechanism.
func (*RPC) SendResult ¶
func (rpc *RPC) SendResult(ctx context.Context, logger logrus.FieldLogger, result interface{}, err error)
SendResult sends a result of a request.
type RPCClient ¶
type RPCClient interface { Go(serviceMethod string, args interface{}, reply interface{}, done chan *rpc.Call) *rpc.Call Close() error }
RPCClient is an interface representing methods for a RPC Client.
type RPCResponse ¶
type RPCResponse struct { Response interface{} Error error }
RPCResponse captures both a response and a potential error.
type SyncClient ¶
type SyncClient interface { Sync(ctx context.Context, req *SyncRequest, resp *SyncResponse) error ForceSync(ctx context.Context, req *ForceSyncRequest, resp *ForceSyncResponse) error FastForward(ctx context.Context, req *FastForwardRequest, resp *FastForwardResponse) error Close() error }
SyncClient is an interface representing methods for sync client.
type SyncPeer ¶
type SyncPeer interface { Sync(ctx context.Context, target string, req *SyncRequest, resp *SyncResponse) error ForceSync(ctx context.Context, target string, req *ForceSyncRequest, resp *ForceSyncResponse) error FastForward(ctx context.Context, target string, req *FastForwardRequest, resp *FastForwardResponse) error ReceiverChannel() <-chan *RPC Close() error }
SyncPeer is an interface representing methods for sync transport.
type SyncRequest ¶
SyncRequest initiates a synchronization request.