Skip to content

Commit

Permalink
feat(ipfs-server): support "bitswap/ledger"
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Jun 17, 2019
1 parent bed212c commit 527791d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions IpfsServer/HttpApi/V0/BitswapController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,37 @@ public class BitswapLinkDto
public string Link;
}

/// <summary>
/// The bitswap ledger with another peer.
/// </summary>
public class BitswapLedgerDto
{
/// <summary>
/// The peer ID.
/// </summary>
public string Peer;

/// <summary>
/// The debt ratio.
/// </summary>
public double Value;

/// <summary>
/// The number of bytes sent.
/// </summary>
public ulong Sent;

/// <summary>
/// The number of bytes received.
/// </summary>
public ulong Recv;

/// <summary>
/// The number blocks exchanged.
/// </summary>
public ulong Exchanged;
}

/// <summary>
/// Data trading module for IPFS. Its purpose is to request blocks from and
/// send blocks to other peers in the network.
Expand Down Expand Up @@ -84,5 +115,25 @@ public async Task Unwants(string arg)
await IpfsCore.Bitswap.UnwantAsync(arg, Cancel);
}

/// <summary>
/// The blocks that are needed by a peer.
/// </summary>
/// <param name="arg">
/// A peer ID or empty for self.
/// </param>
[HttpGet, HttpPost, Route("bitswap/ledger")]
public async Task<BitswapLedgerDto> Ledger(string arg)
{
var peer = new Peer { Id = arg };
var ledger = await IpfsCore.Bitswap.LedgerAsync(peer, Cancel);
return new BitswapLedgerDto
{
Peer = ledger.Peer.Id.ToBase58(),
Exchanged = ledger.BlocksExchanged,
Recv = ledger.DataReceived,
Sent = ledger.DataSent,
Value = ledger.DebtRatio
};
}
}
}

0 comments on commit 527791d

Please sign in to comment.