peer

package
v0.0.0-...-168a2c3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MethodSync        = "Lachesis.Sync"
	MethodForceSync   = "Lachesis.ForceSync"
	MethodFastForward = "Lachesis.FastForward"
)

RPC Methods.

View Source
const (

	// TCP is a Transmission Control Protocol.
	TCP = "tcp"
)

Variables

View Source
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) Close

func (srv *Backend) Close() error

Close stops sync server.

func (*Backend) ListenAndServe

func (srv *Backend) ListenAndServe(network, address string) error

ListenAndServe starts sync server.

func (*Backend) ReceiverChannel

func (srv *Backend) ReceiverChannel() <-chan *RPC

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 NewClient

func NewClient(rpcClient RPCClient) (*Client, error)

NewClient creates new sync client.

func (*Client) Close

func (c *Client) Close() error

Close closes 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

type CreateListenerFunc func(network, address string) (net.Listener, error)

CreateListenerFunc creates a new network listener.

type CreateNetConnFunc

type CreateNetConnFunc func(network,
	address string, timeout time.Duration) (net.Conn, error)

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

type ForceSyncRequest struct {
	FromID uint64
	Events []poset.WireEvent
}

ForceSyncRequest after an initial sync to quickly catch up.

type ForceSyncResponse

type ForceSyncResponse struct {
	FromID  uint64
	Success bool
}

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) Close

func (tr *Peer) Close() error

Close closes the 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

func (tr *Peer) ReceiverChannel() <-chan *RPC

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) Close

func (p *Producer) Close()

Close closes a producer.

func (*Producer) ConnLen

func (p *Producer) ConnLen(target string) int

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

type SyncRequest struct {
	FromID uint64
	Known  map[uint64]int64
}

SyncRequest initiates a synchronization request.

type SyncResponse

type SyncResponse struct {
	FromID    uint64
	SyncLimit bool
	Events    []poset.WireEvent
	Known     map[uint64]int64
}

SyncResponse is a response to a SyncRequest request.

type SyncServer

type SyncServer interface {
	ReceiverChannel() <-chan *RPC
	ListenAndServe(network, address string) error
	Close() error
}

SyncServer is an interface representing methods for sync server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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