Documentation
¶
Index ¶
- Constants
- Variables
- func MemberRaftID(memberID string, clusterConfig *types.ClusterConfig) (uint64, error)
- func NewCatchUpClient(lg *logger.SugarLogger, tlsConfig *tls.Config) *catchUpClient
- func NewCatchupHandler(lg *logger.SugarLogger, ledgerReader LedgerReader, maxResponseBytes int) *catchupHandler
- type Config
- type ConsensusListener
- type HTTPTransport
- func (p *HTTPTransport) ActivePeers(minDuration time.Duration, includeSelf bool) map[string]*types.PeerConfig
- func (p *HTTPTransport) ClientTLSConfig() *tls.Config
- func (p *HTTPTransport) Close()
- func (p *HTTPTransport) PullBlocks(ctx context.Context, startBlock, endBlock, leaderID uint64) ([]*types.Block, error)
- func (p *HTTPTransport) SendConsensus(msgs []raftpb.Message) error
- func (p *HTTPTransport) SetClusterConfig(clusterConfig *types.ClusterConfig) error
- func (p *HTTPTransport) SetConsensusListener(l ConsensusListener) error
- func (p *HTTPTransport) Start() error
- func (p *HTTPTransport) UpdatePeers(added, removed, changed []*types.PeerConfig, ...) error
- type HeightResponse
- type LedgerReader
- type LogAdapter
Constants ¶
const ( BCDBPeerEndpoint = "/bcdb-peer/" GetBlocksPath = BCDBPeerEndpoint + "blocks" GetHeightPath = BCDBPeerEndpoint + "height" )
Variables ¶
var RetryIntervalMax = 10 * time.Second
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 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 LogAdapter ¶
type LogAdapter struct { SugarLogger *logger.SugarLogger Debug bool }