Bittorrent Command

1200

BTFS 2.3 adds a new command/API to downloads the files of a specific bittorrent seed or a magnet URI scheme based on BTIP-1

Overview

BTFS integrated with the Bittorrent libs to serve as a Bittorrent client, and communicate with the tracker, DHT, webseed or Bittorrent peers, and then downloads the content, after downloading completed, stop the communications with those p2p.

Command

1.download a bittorrent file

btfs bittorrent download -t torrent-file.torrent

2.download a magnet url

btfs bittorrent download 'magnet:?xt=urn:btih:KRWPCX3SJUM4IMM4YF5RPHL6ANPYTQPU'

3.show metainfo for the specified bittorrent file

btfs bittorrent metainfo -t xxx.torrent

4.show metainfo for the specified magnet URL

btfs bittorrent metainfo -m 'magnet:?xt=urn:btih:KRWPCX3SJUM4IMM4YF5RPHL6ANPYTQPU'

5.fetch swarm metrics for info-hashes from tracker

# -t tracker url, -i pieces of info-hashes which separated by commas
btfs bittorrent scrape -t '' -i ''

6.transfer the bencoded data to the person-readable json (according to BEP-3)

btfs bittorrent bencode -f xxx.torrent

7.serve as a bittorrent client with the specified files

# -f files which you want to share with the bittorrent network,separated by commas
btfs bittorrent serve -f 'xxx.mp4,xxx.jpeg'

📘

NOTE:

This command will start a daemon to serve as a client and output the magnet url every file you tap in.

Rationale

BTFS is dirrent from BitTorrent but they have something same such as they are all distributed network and decentralized.When we integrate with bittorrent, we consider the following steps:

  1. Parsing the magnetic links to bittorrent metadata if the target is a magnet url.
  2. Parsing the bittorrent file to bittorrent metadata if the target is a bittorrent seed file.
  3. Judge by the bittorrent metadata and choose how to get peers by tracker/dht/webseed/peer.
  4. Split the bittorrent metadata into a list of pieces and download all this pieces independently from the peers.
  5. We can see the process of downloading in the console.
  6. When downloading is finished, add this file to the local BTFS node by
btfs add file
  1. Maybe we can add a more user-interactive friendly dashboard to view this process.