2020-09-07 18:31:43 +00:00
|
|
|
package exchange
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-08-25 18:20:41 +00:00
|
|
|
"github.com/libp2p/go-libp2p/core/network"
|
|
|
|
"github.com/libp2p/go-libp2p/core/peer"
|
2020-09-07 18:31:43 +00:00
|
|
|
|
|
|
|
"github.com/filecoin-project/lotus/chain/store"
|
|
|
|
"github.com/filecoin-project/lotus/chain/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Server is the responder side of the ChainExchange protocol. It accepts
|
|
|
|
// requests from clients and services them by returning the requested
|
|
|
|
// chain data.
|
|
|
|
type Server interface {
|
|
|
|
// HandleStream is the protocol handler to be registered on a libp2p
|
|
|
|
// protocol router.
|
|
|
|
//
|
|
|
|
// In the current version of the protocol, streams are single-use. The
|
|
|
|
// server will read a single Request, and will respond with a single
|
|
|
|
// Response. It will dispose of the stream straight after.
|
|
|
|
HandleStream(stream network.Stream)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Client is the requesting side of the ChainExchange protocol. It acts as
|
|
|
|
// a proxy for other components to request chain data from peers. It is chiefly
|
|
|
|
// used by the Syncer.
|
|
|
|
type Client interface {
|
|
|
|
// GetBlocks fetches block headers from the network, from the provided
|
2024-01-08 20:42:10 +00:00
|
|
|
// tipset *backwards*, returning as many tipsets as the count parameter.
|
|
|
|
// The ONLY case in which we return fewer than `count` tipsets is if we hit genesis.
|
2020-09-07 18:31:43 +00:00
|
|
|
GetBlocks(ctx context.Context, tsk types.TipSetKey, count int) ([]*types.TipSet, error)
|
|
|
|
|
2020-09-21 15:58:52 +00:00
|
|
|
// GetChainMessages fetches messages from the network, starting from the first provided tipset
|
|
|
|
// and returning messages from as many tipsets as requested or less.
|
|
|
|
GetChainMessages(ctx context.Context, tipsets []*types.TipSet) ([]*CompactedMessages, error)
|
2020-09-07 18:31:43 +00:00
|
|
|
|
|
|
|
// GetFullTipSet fetches a full tipset from a given peer. If successful,
|
|
|
|
// the fetched object contains block headers and all messages in full form.
|
|
|
|
GetFullTipSet(ctx context.Context, peer peer.ID, tsk types.TipSetKey) (*store.FullTipSet, error)
|
|
|
|
|
|
|
|
// AddPeer adds a peer to the pool of peers that the Client requests
|
|
|
|
// data from.
|
|
|
|
AddPeer(peer peer.ID)
|
|
|
|
|
|
|
|
// RemovePeer removes a peer from the pool of peers that the Client
|
|
|
|
// requests data from.
|
|
|
|
RemovePeer(peer peer.ID)
|
|
|
|
}
|