client

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2023 License: Apache-2.0, MIT Imports: 32 Imported by: 10

Documentation

Overview

Package bitswap implements the IPFS exchange interface with the BitSwap bilateral exchange protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockReceivedNotifier

type BlockReceivedNotifier interface {
	// ReceivedBlocks notifies the decision engine that a peer is well-behaving
	// and gave us useful data, potentially increasing its score and making us
	// send them more data in exchange.
	ReceivedBlocks(peer.ID, []blocks.Block)
}

type Client

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

Client instances implement the bitswap protocol.

func New

func New(parent context.Context, network bsnet.BitSwapNetwork, bstore blockstore.Blockstore, options ...Option) *Client

New initializes a Bitswap client that runs until client.Close is called.

func (*Client) Close

func (bs *Client) Close() error

Close is called to shutdown the Client

func (*Client) GetBlock

func (bs *Client) GetBlock(ctx context.Context, k cid.Cid) (blocks.Block, error)

GetBlock attempts to retrieve a particular block from peers within the deadline enforced by the context.

func (*Client) GetBlocks

func (bs *Client) GetBlocks(ctx context.Context, keys []cid.Cid) (<-chan blocks.Block, error)

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 (*Client) GetWantBlocks

func (bs *Client) GetWantBlocks() []cid.Cid

GetWantBlocks returns the current list of want-blocks.

func (*Client) GetWantHaves

func (bs *Client) GetWantHaves() []cid.Cid

GetWanthaves returns the current list of want-haves.

func (*Client) GetWantlist

func (bs *Client) GetWantlist() []cid.Cid

GetWantlist returns the current local wantlist (both want-blocks and want-haves).

func (*Client) IsOnline

func (bs *Client) IsOnline() bool

IsOnline is needed to match go-ipfs-exchange-interface

func (*Client) NewSession

func (bs *Client) NewSession(ctx context.Context) exchange.Fetcher

NewSession generates a new Bitswap session. You should use this, rather that calling Client.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 (*Client) NotifyNewBlocks

func (bs *Client) NotifyNewBlocks(ctx context.Context, blks ...blocks.Block) error

NotifyNewBlocks announces the existence of blocks to this bitswap service. Bitswap itself doesn't store new blocks. It's the caller responsibility to ensure that those blocks are available in the blockstore before calling this function.

func (*Client) PeerConnected

func (bs *Client) PeerConnected(p peer.ID)

PeerConnected is called by the network interface when a peer initiates a new connection to bitswap.

func (*Client) PeerDisconnected

func (bs *Client) PeerDisconnected(p peer.ID)

PeerDisconnected is called by the network interface when a peer closes a connection

func (*Client) ReceiveError

func (bs *Client) ReceiveError(err error)

ReceiveError is called by the network interface when an error happens at the network layer. Currently just logs error.

func (*Client) ReceiveMessage

func (bs *Client) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg.BitSwapMessage)

ReceiveMessage is called by the network interface when a new message is received.

func (*Client) Stat

func (bs *Client) Stat() (st Stat, err error)

Stat returns aggregated statistics about bitswap operations

type Option

type Option func(*Client)

Option defines the functional option type that can be used to configure bitswap instances

func ProviderSearchDelay

func ProviderSearchDelay(newProvSearchDelay time.Duration) Option

ProviderSearchDelay overwrites the global provider search delay

func RebroadcastDelay

func RebroadcastDelay(newRebroadcastDelay delay.D) Option

RebroadcastDelay overwrites the global provider rebroadcast delay

func SetSimulateDontHavesOnTimeout

func SetSimulateDontHavesOnTimeout(send bool) Option

func WithBlockReceivedNotifier

func WithBlockReceivedNotifier(brn BlockReceivedNotifier) Option

func WithTracer

func WithTracer(tap tracer.Tracer) Option

Configures the Client to use given tracer. This provides methods to access all messages sent and received by the Client. This interface can be used to implement various statistics (this is original intent).

type Stat

type Stat struct {
	Wantlist         []cid.Cid
	BlocksReceived   uint64
	DataReceived     uint64
	DupBlksReceived  uint64
	DupDataReceived  uint64
	MessagesReceived uint64
}

Stat is a struct that provides various statistics on bitswap operations

Directories

Path Synopsis
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.

Jump to

Keyboard shortcuts

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