Class Bitswap
Exchange blocks with other peers.
Implements
Inherited Members
Namespace: Ipfs.Engine.BlockExchange
Assembly: Ipfs.Engine.dll
Syntax
public class Bitswap : IService
Constructors
| Improve this Doc View SourceBitswap()
Creates a new instance of the Bitswap class.
Declaration
public Bitswap()
Fields
| Improve this Doc View SourceProtocols
The supported bitswap protocols.
Declaration
public IBitswapProtocol[] Protocols
Field Value
| Type | Description |
|---|---|
| IBitswapProtocol[] |
Properties
| Improve this Doc View SourceBlockService
Provides access to blocks of data.
Declaration
public IBlockApi BlockService { get; set; }
Property Value
| Type | Description |
|---|---|
| IBlockApi |
Statistics
Statistics on the bitswap component.
Declaration
public BitswapData Statistics { get; }
Property Value
| Type | Description |
|---|---|
| BitswapData |
See Also
| Improve this Doc View SourceSwarm
Provides access to other peers.
Declaration
public Swarm Swarm { get; set; }
Property Value
| Type | Description |
|---|---|
| Swarm |
Methods
| Improve this Doc View SourceFound(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 |
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.
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.
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.
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. |
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
| Improve this Doc View SourcePeerWants(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 |
StartAsync()
Declaration
public Task StartAsync()
Returns
| Type | Description |
|---|---|
| Task |
StopAsync()
Declaration
public Task StopAsync()
Returns
| Type | Description |
|---|---|
| Task |
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.
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 SourceBlockNeeded
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.