Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically check data transfer on IPFS

Tags:

ipfs

We are building a desktop app, on Electron, to share media on IPFS. We want to incentivize the people, who either by an IPFS add or pin, make data available to other users and in effect are "seeding" the data. We want to track how much data is being sent and received by each user, programmatically and periodically.

Is there a standard pattern or a service to be able to do this?

TIA!

like image 977
Vishal Chandran Avatar asked Feb 06 '18 10:02

Vishal Chandran


1 Answers

On the CLI you can use the ipfs stats bw -p <peer id> command to see the total bytes sent and recieved between your node and the peer id you pass in.

$ ipfs stats bw -p  QmeMKDA6HbDD8Bwb4WoAQ7s9oKZTBpy55YFKG1RSHnBz6a
Bandwidth
TotalIn: 875 B
TotalOut: 14 kB
RateIn: 0 B/s
RateOut: 0 B/s

See: https://docs.ipfs.io/reference/api/cli/#ipfs-stats-bw

You can use the ipfs.stats.bw method to the data programatically from the js implementation of IPFS js-ipfs or via the js-ipfs-http-client talking to the http api of a locally running ipfs daemon.

ipfs.stats.bw will show all traffic between to peers, which can include dht queries and other traffic that isn't directly related to sharing blocks of data.

If you want info on just blocks of data shared then you can use ipfs bitswap ledger from the command line.

$ ipfs bitswap ledger QmeMKDA6HbDD8Bwb4WoAQ7s9oKZTBpy55YFKG1RSHnBz6a
Ledger for QmeMKDA6HbDD8Bwb4WoAQ7s9oKZTBpy55YFKG1RSHnBz6a
Debt ratio: 0.000000
Exchanges:  0
Bytes sent: 0
Bytes received: 0

See: https://docs.ipfs.io/reference/api/cli/#ipfs-bitswap-ledger

That api is not directly available in js-ipfs or the js-http-api-client yet.

like image 111
olizilla Avatar answered Oct 01 '22 08:10

olizilla