comm

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: Apache-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BCDBPeerEndpoint = "/bcdb-peer/"
	GetBlocksPath    = BCDBPeerEndpoint + "blocks"
	GetHeightPath    = BCDBPeerEndpoint + "height"
)

Variables

View Source
var RetryIntervalMax = 10 * time.Second
View Source
var RetryIntervalMin = 10 * time.Millisecond

Functions

func MemberRaftID

func MemberRaftID(memberID string, clusterConfig *types.ClusterConfig) (uint64, error)

func NewCatchUpClient

func NewCatchUpClient(lg *logger.SugarLogger, tlsConfig *tls.Config) *catchUpClient

func NewCatchupHandler

func NewCatchupHandler(lg *logger.SugarLogger, ledgerReader LedgerReader, maxResponseBytes int) *catchupHandler

Types

type Config

type Config struct {
	LocalConf    *config.LocalConfiguration
	Logger       *logger.SugarLogger
	LedgerReader LedgerReader
}

type ConsensusListener

type ConsensusListener interface {
	rafthttp.Raft
}

type HTTPTransport

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

HTTPTransport provides HTTP-based transport to send and receive message from remote peers that run the Raft cluster. It also provides an HTTP-based "catch-up" service to pull batches of blocks from remote peers in order to do catch-up (i.e. state transfer).

The HTTPTransport is operated in the following way:

  • Create a *HTTPTransport with NewHTTPTransport;
  • Set an initial cluster configuration with SetClusterConfig;
  • Register a listener to receive incoming messages with SetConsensusListener; and finally,
  • Start the component with Start. An HTTP server start serving requests, messages can now be sent and received.
  • Configuration changes to the cluster's peers - adding a peer, removing a peer, or changing a peer's endpoints - are applied using UpdatePeers.
  • To stop the component call Close,

The component is thread safe.

func NewHTTPTransport

func NewHTTPTransport(config *Config) (*HTTPTransport, error)

NewHTTPTransport creates a new instance of HTTPTransport.

func (*HTTPTransport) ActivePeers

func (p *HTTPTransport) ActivePeers(minDuration time.Duration, includeSelf bool) map[string]*types.PeerConfig

ActivePeers returns the peers that are active for more than `minDuration`. The returned peers include the self node if includeSelf==true.

func (*HTTPTransport) ClientTLSConfig

func (p *HTTPTransport) ClientTLSConfig() *tls.Config

func (*HTTPTransport) Close

func (p *HTTPTransport) Close()

func (*HTTPTransport) PullBlocks

func (p *HTTPTransport) PullBlocks(ctx context.Context, startBlock, endBlock, leaderID uint64) ([]*types.Block, error)

PullBlocks tries to pull as many blocks as possible from startBlock to endBlock (inclusive).

The calling go-routine will block until some blocks are retrieved, depending on the availability of remote peers. The underlying implementation will poll the cluster members, starting from the leader hint (if exists), until it can retrieve some blocks. The call may return fewer blocks than requested. The `leaderID` is a hint to the leader's Raft ID, and can be 0. The call maybe canceled using the context `ctx`.

func (*HTTPTransport) SendConsensus

func (p *HTTPTransport) SendConsensus(msgs []raftpb.Message) error

func (*HTTPTransport) SetClusterConfig

func (p *HTTPTransport) SetClusterConfig(clusterConfig *types.ClusterConfig) error

SetClusterConfig sets the initial types.ClusterConfig into the HTTPTransport for the first time. In this invocation the HTTPTransport detects what is its local RaftID by collating its local ID (string) with the member set in the ClusterConfig.

This must be called before the call to Start().

func (*HTTPTransport) SetConsensusListener

func (p *HTTPTransport) SetConsensusListener(l ConsensusListener) error

SetConsensusListener sets the consensus listener which is an interface that is implemented by the replication component that is running the Raft state machine. This is how the transport layer delivers incoming messages from remote peers up to the Raft state machine. This interface is also used to deliver local networking events up to the Raft state machine.

This must be called before the call to Start().

func (*HTTPTransport) Start

func (p *HTTPTransport) Start() error

Start binds to the listening port and start serving requests. SetClusterConfig and SetConsensusListener must be called before start.

func (*HTTPTransport) UpdatePeers

func (p *HTTPTransport) UpdatePeers(added, removed, changed []*types.PeerConfig, updatedClusterConfig *types.ClusterConfig) error

UpdatePeers adds, removes and updates changed peers in the raft http transport; it also refreshes the member list of the catchup client.

type HeightResponse

type HeightResponse struct {
	Height uint64
}

type LedgerReader

type LedgerReader interface {
	Height() (uint64, error)
	Get(blockNumber uint64) (*types.Block, error)
}

type LogAdapter

type LogAdapter struct {
	SugarLogger *logger.SugarLogger
	Debug       bool
}

func (*LogAdapter) Write

func (l *LogAdapter) Write(p []byte) (n int, err error)

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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