Documentation ¶
Overview ¶
Package bitswap implements the IPFS exchange interface with the BitSwap bilateral exchange protocol.
Index ¶
- Variables
- func New(parent context.Context, network bsnet.BitSwapNetwork, ...) exchange.Interface
- type Bitswap
- func (bs *Bitswap) Close() error
- func (bs *Bitswap) GetBlock(parent context.Context, k cid.Cid) (blocks.Block, error)
- func (bs *Bitswap) GetBlocks(ctx context.Context, keys []cid.Cid) (<-chan blocks.Block, error)
- func (bs *Bitswap) GetWantBlocks() []cid.Cid
- func (bs *Bitswap) GetWantHaves() []cid.Cid
- func (bs *Bitswap) GetWantlist() []cid.Cid
- func (bs *Bitswap) HasBlock(ctx context.Context, blk blocks.Block) error
- func (bs *Bitswap) IsOnline() bool
- func (bs *Bitswap) LedgerForPeer(p peer.ID) *decision.Receipt
- func (bs *Bitswap) NewSession(ctx context.Context) exchange.Fetcher
- func (bs *Bitswap) PeerConnected(p peer.ID)
- func (bs *Bitswap) PeerDisconnected(p peer.ID)
- func (bs *Bitswap) ReceiveError(err error)
- func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg.BitSwapMessage)
- func (bs *Bitswap) Stat() (*Stat, error)
- func (bs *Bitswap) WantlistForPeer(p peer.ID) []cid.Cid
- type Option
- func EngineBlockstoreWorkerCount(count int) Option
- func EngineTaskWorkerCount(count int) Option
- func MaxOutstandingBytesPerPeer(count int) Option
- func ProvideEnabled(enabled bool) Option
- func ProviderSearchDelay(newProvSearchDelay time.Duration) Option
- func RebroadcastDelay(newRebroadcastDelay delay.D) Option
- func SetSendDontHaves(send bool) Option
- func SetSimulateDontHavesOnTimeout(send bool) Option
- func TaskWorkerCount(count int) Option
- func WithScoreLedger(scoreLedger deciface.ScoreLedger) Option
- func WithTaskComparator(comparator TaskComparator) Option
- func WithTracer(tap Tracer) Option
- type Stat
- type TaskComparator
- type TaskInfo
- type Tracer
Constants ¶
This section is empty.
Variables ¶
var ( // HasBlockBufferSize is the buffer size of the channel for new blocks // that need to be provided. They should get pulled over by the // provideCollector even before they are actually provided. // TODO: Does this need to be this large givent that? HasBlockBufferSize = 256 )
Functions ¶
func New ¶
func New(parent context.Context, network bsnet.BitSwapNetwork, bstore blockstore.Blockstore, options ...Option) exchange.Interface
New initializes a BitSwap instance that communicates over the provided BitSwapNetwork. This function registers the returned instance as the network delegate. Runs until context is cancelled or bitswap.Close is called.
Types ¶
type Bitswap ¶
type Bitswap struct {
// contains filtered or unexported fields
}
Bitswap instances implement the bitswap protocol. 块交换实现
func (*Bitswap) GetBlock ¶
GetBlock attempts to retrieve a particular block from peers within the deadline enforced by the context.
func (*Bitswap) GetBlocks ¶
GetBlocks returns a channel where the caller may receive blocks that correspond to the provided |keys|. Returns an error if BitSwap is unable to begin this request within the deadline enforced by the context.
NB: Your request remains open until the context expires. To conserve resources, provide a context with a reasonably short deadline (ie. not one that lasts throughout the lifetime of the server)
func (*Bitswap) GetWantBlocks ¶
func (bs *Bitswap) GetWantBlocks() []cid.Cid
GetWantBlocks returns the current list of want-blocks.
func (*Bitswap) GetWantHaves ¶
func (bs *Bitswap) GetWantHaves() []cid.Cid
GetWanthaves returns the current list of want-haves.
func (*Bitswap) GetWantlist ¶
func (bs *Bitswap) GetWantlist() []cid.Cid
GetWantlist returns the current local wantlist (both want-blocks and want-haves).
func (*Bitswap) HasBlock ¶
HasBlock announces the existence of a block to this bitswap service. The service will potentially notify its peers.
func (*Bitswap) LedgerForPeer ¶
LedgerForPeer returns aggregated data about blocks swapped and communication with a given peer.
func (*Bitswap) NewSession ¶
NewSession generates a new Bitswap session. You should use this, rather that calling Bitswap.GetBlocks, any time you intend to do several related block requests in a row. The session returned will have it's own GetBlocks method, but the session will use the fact that the requests are related to be more efficient in its requests to peers. If you are using a session from go-blockservice, it will create a bitswap session automatically.
func (*Bitswap) PeerConnected ¶
PeerConnected is called by the network interface when a peer initiates a new connection to bitswap.
func (*Bitswap) PeerDisconnected ¶
PeerDisconnected is called by the network interface when a peer closes a connection
func (*Bitswap) ReceiveError ¶
ReceiveError is called by the network interface when an error happens at the network layer. Currently just logs error.
func (*Bitswap) ReceiveMessage ¶
ReceiveMessage is called by the network interface when a new message is received.
func (*Bitswap) WantlistForPeer ¶
WantlistForPeer returns the currently understood list of blocks requested by a given peer. yuvia 获取某peer的wantlist
type Option ¶
type Option func(*Bitswap)
Option defines the functional option type that can be used to configure bitswap instances
func EngineBlockstoreWorkerCount ¶
EngineBlockstoreWorkerCount sets the number of worker threads used for blockstore operations in the decision engine
func EngineTaskWorkerCount ¶
EngineTaskWorkerCount sets the number of worker threads used inside the engine
func MaxOutstandingBytesPerPeer ¶
MaxOutstandingBytesPerPeer describes approximately how much work we are will to have outstanding to a peer at any given time. Setting it to 0 will disable any limiting.
func ProvideEnabled ¶
ProvideEnabled is an option for enabling/disabling provide announcements
func ProviderSearchDelay ¶
ProviderSearchDelay overwrites the global provider search delay
func RebroadcastDelay ¶
RebroadcastDelay overwrites the global provider rebroadcast delay
func SetSendDontHaves ¶
SetSendDontHaves indicates what to do when the engine receives a want-block for a block that is not in the blockstore. Either - Send a DONT_HAVE message - Simply don't respond This option is only used for testing.
func TaskWorkerCount ¶
func WithScoreLedger ¶
func WithScoreLedger(scoreLedger deciface.ScoreLedger) Option
Configures the engine to use the given score decision logic.
func WithTaskComparator ¶
func WithTaskComparator(comparator TaskComparator) Option
WithTaskComparator configures custom task prioritization logic.
type Stat ¶
type Stat struct { ProvideBufLen int Wantlist []cid.Cid Peers []string BlocksReceived uint64 DataReceived uint64 BlocksSent uint64 DataSent uint64 DupBlksReceived uint64 DupDataReceived uint64 MessagesReceived uint64 }
Stat is a struct that provides various statistics on bitswap operations
type TaskComparator ¶
type TaskComparator = decision.TaskComparator
type Tracer ¶
type Tracer interface { MessageReceived(peer.ID, bsmsg.BitSwapMessage) MessageSent(peer.ID, bsmsg.BitSwapMessage) }
Tracer provides methods to access all messages sent and received by Bitswap. This interface can be used to implement various statistics (this is original intent).
Directories ¶
Path | Synopsis |
---|---|
internal
|
|
decision
Package decision implements the decision engine for the bitswap service.
|
Package decision implements the decision engine for the bitswap service. |
Package wantlist implements an object for bitswap that contains the keys that a given peer wants.
|
Package wantlist implements an object for bitswap that contains the keys that a given peer wants. |