Extension for Peers to Send Metadata Files (BEP 9)
Node.js implementation of the Extension for Peers to Send Metadata Files (BEP 9). Use with bittorrent-protocol.
The purpose of this extension is to allow clients to join a swarm and complete a download without the need of downloading a .torrent file first. This extension instead allows clients to download the metadata from peers. It makes it possible to support magnet links, a link on a web page only containing enough information to join the swarm (the info hash).
npm install ut_metadata
This package should be used with bittorrent-protocol, which supports a plugin-like system for extending the protocol with additional functionality.
Say you're already using
bittorrent-protocol. Your code might look something like this:
var Protocol =var net =net
To add support for BEP 9, simply modify your code like this:
var Protocol =var net =var ut_metadata =net
Initialize the extension. If you have the torrent metadata (Buffer), pass it into the
ut_metadata constructor so it's made available to the peer.
var metadata = fswire
Ask the peer to send metadata.
Stop asking the peer to send metadata.
Set the metadata. If you didn't have the metadata at the time
initialized, but you end up getting it from another peer (or somewhere else), you should
setMetadata so the metadata will be available to the peer.
Fired when metadata is available and verified to be correct. Called with a single parameter of type Buffer.
Note: the event will not fire if the peer does not support ut_metadata, if they don't have metadata yet either, if they repeatedly send invalid data, or if they simply don't respond.
MIT. Copyright (c) Feross Aboukhadijeh.