Show / Hide Table of Contents

Class Bitswap

Exchange blocks with other peers.

Inheritance
Object
Bitswap
Implements
IService
Inherited Members
Object.Equals(Object)
Object.Equals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()
Object.ReferenceEquals(Object, Object)
Object.ToString()
Namespace: Ipfs.Engine.BlockExchange
Assembly: Ipfs.Engine.dll
Syntax
public class Bitswap : IService

Constructors

| Improve this Doc View Source

Bitswap()

Creates a new instance of the Bitswap class.

Declaration
public Bitswap()

Fields

| Improve this Doc View Source

Protocols

The supported bitswap protocols.

Declaration
public IBitswapProtocol[] Protocols
Field Value
Type Description
IBitswapProtocol[]

Defaults to Bitswap11 and Bitswap1.

Properties

| Improve this Doc View Source

BlockService

Provides access to blocks of data.

Declaration
public IBlockApi BlockService { get; set; }
Property Value
Type Description
IBlockApi
| Improve this Doc View Source

Statistics

Statistics on the bitswap component.

Declaration
public BitswapData Statistics { get; }
Property Value
Type Description
BitswapData
See Also
IStatsApi
| Improve this Doc View Source

Swarm

Provides access to other peers.

Declaration
public Swarm Swarm { get; set; }
Property Value
Type Description
Swarm

Methods

| Improve this Doc View Source

Found(IDataBlock)

Indicate that a block is found.

Declaration
public int Found(IDataBlock block)
Parameters
Type Name Description
IDataBlock block

The block that was found.

Returns
Type Description
Int32

The number of consumers waiting for the block.

Remarks

Found should be called whenever a new block is discovered. It will continue any Task that is waiting for the block and remove the block from the want list.

| Improve this Doc View Source

OnBlockReceivedAsync(Peer, Byte[])

Indicate that a remote peer sent a block.

Declaration
public Task OnBlockReceivedAsync(Peer remote, byte[] block)
Parameters
Type Name Description
Peer remote

The peer that sent the block.

Byte[] block

The data for the block.

Returns
Type Description
Task

A task that represents the asynchronous operation.

Remarks

Updates the statistics.

If the block is acceptable then the block is added to local cache via the BlockService.

| Improve this Doc View Source

OnBlockReceivedAsync(Peer, Byte[], String, String)

Indicate that a remote peer sent a block.

Declaration
public Task OnBlockReceivedAsync(Peer remote, byte[] block, string contentType, string multiHash)
Parameters
Type Name Description
Peer remote

The peer that sent the block.

Byte[] block

The data for the block.

String contentType

The ContentType of the block.

String multiHash

The multihash algorithm name of the block.

Returns
Type Description
Task

A task that represents the asynchronous operation.

Remarks

Updates the statistics.

If the block is acceptable then the block is added to local cache via the BlockService.

| Improve this Doc View Source

OnBlockSentAsync(Peer, IDataBlock)

Indicate that the local peer sent a block to a remote peer.

Declaration
public Task OnBlockSentAsync(Peer remote, IDataBlock block)
Parameters
Type Name Description
Peer remote

The peer that sent the block.

IDataBlock block

The data for the block.

Returns
Type Description
Task

A task that represents the asynchronous operation.

| Improve this Doc View Source

PeerLedger(Peer)

Gets the bitswap ledger for the specified peer.

Declaration
public BitswapLedger PeerLedger(Peer peer)
Parameters
Type Name Description
Peer peer

The peer to get information on. If the peer is unknown, then a ledger with zeros is returned.

Returns
Type Description
BitswapLedger

Statistics on the bitswap blocks exchanged with the peer.

See Also
LedgerAsync(Peer, CancellationToken)
| Improve this Doc View Source

PeerWants(MultiHash)

The blocks needed by the peer.

Declaration
public IEnumerable<Cid> PeerWants(MultiHash peer)
Parameters
Type Name Description
MultiHash peer

The unique ID of the peer.

Returns
Type Description
IEnumerable<Cid>

The sequence of CIDs need by the peer.

| Improve this Doc View Source

StartAsync()

Declaration
public Task StartAsync()
Returns
Type Description
Task
| Improve this Doc View Source

StopAsync()

Declaration
public Task StopAsync()
Returns
Type Description
Task
| Improve this Doc View Source

Unwant(Cid)

Removes the block from the want list.

Declaration
public void Unwant(Cid id)
Parameters
Type Name Description
Cid id

The CID of the block to remove from the want list.

Remarks

Any tasks waiting for the block are cancelled.

No exception is thrown if the id is not on the want list.

| Improve this Doc View Source

WantAsync(Cid, MultiHash, CancellationToken)

Adds a block to the want list.

Declaration
public Task<IDataBlock> WantAsync(Cid id, MultiHash peer, CancellationToken cancel)
Parameters
Type Name Description
Cid id

The CID of the block to add to the want list.

MultiHash peer

The unique ID of the peer that wants the block. This is for information purposes only.

CancellationToken cancel

Is used to stop the task. When cancelled, the TaskCanceledException is raised.

Returns
Type Description
Task<IDataBlock>

A task that represents the asynchronous operation. The task's result is the contents of block.

Remarks

Other peers are informed that the block is needed by this peer. Hopefully, someone will forward it to us.

Besides using cancel for cancellation, the Unwant(Cid) method will also cancel the operation.

Events

| Improve this Doc View Source

BlockNeeded

Raised when a blocked is needed.

Declaration
public event EventHandler<CidEventArgs> BlockNeeded
Event Type
Type Description
EventHandler<CidEventArgs>
Remarks

Only raised when a block is first requested.

Implements

IService
  • Improve this Doc
  • View Source
Back to top Generated by DocFX