• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 10 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

BitTorrent Extension for Peers to Send Metadata Files (BEP 9)

ut_metadata ci npm downloads javascript style guide

BitTorrent Extension for Peers to Send Metadata Files (BEP 9)

JavaScript 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).

Works in the browser with browserify! This module is used by WebTorrent.

install

npm install ut_metadata

usage

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:

import Protocol from 'bittorrent-protocol'
import net from 'net'

net.createServer(socket => {
  var wire = new Protocol()
  socket.pipe(wire).pipe(socket)

  // handle handshake
  wire.on('handshake', (infoHash, peerId) => {
    wire.handshake(new Buffer('my info hash'), new Buffer('my peer id'))
  })

}).listen(6881)

To add support for BEP 9, simply modify your code like this:

import Protocol from 'bittorrent-protocol'
import net from 'net'
import ut_metadata from 'ut_metadata'

net.createServer(socket => {
  const wire = new Protocol()
  socket.pipe(wire).pipe(socket)

  // initialize the extension
  wire.use(ut_metadata())

  // all `ut_metadata` functionality can now be accessed at wire.ut_metadata

  // ask the peer to send us metadata
  wire.ut_metadata.fetch()

  // 'metadata' event will fire when the metadata arrives and is verified to be correct!
  wire.ut_metadata.on('metadata', metadata => {
    // got metadata!

    // 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.
  })

  // optionally, listen to the 'warning' event if you want to know that metadata is
  // probably not going to arrive for one of the above reasons.
  wire.ut_metadata.on('warning', err => {
    console.log(err.message)
  })

  // handle handshake
  wire.on('handshake', (infoHash, peerId) => {
    wire.handshake(new Buffer('my info hash'), new Buffer('my peer id'))
  })

}).listen(6881)

api

ut_metadata([metadata])

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.

const metadata = fs.readFileSync(__dirname + '/file.torrent')
wire.use(ut_metadata(metadata))

ut_metadata.fetch()

Ask the peer to send metadata.

ut_metadata.cancel()

Stop asking the peer to send metadata.

ut_metadata.setMetadata(metadata)

Set the metadata. If you didn't have the metadata at the time ut_metadata was initialized, but you end up getting it from another peer (or somewhere else), you should call setMetadata so the metadata will be available to the peer.

ut_metadata.on('metadata', function (metadata) {})

Fired when metadata is available and verified to be correct. Called with a single parameter of type Buffer.

wire.ut_metadata.on('metadata', metadata => {
  console.log(Buffer.isBuffer(metadata)) // true
})

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.

ut_metadata.on('warning', function (err) {})

Fired if:

  • the peer does not support ut_metadata
  • the peer doesn't have metadata yet
  • the peer repeatedly sent invalid data
wire.ut_metadata.on('warning', err => {
  console.log(err.message)
})

license

MIT. Copyright (c) Feross Aboukhadijeh and WebTorrent, LLC.

More Repositories

1

webtorrent

⚡️ Streaming torrent client for the web
JavaScript
29,385
star
2

webtorrent-desktop

❤️ Streaming torrent app for Mac, Windows, and Linux
JavaScript
9,659
star
3

instant.io

🚀 Streaming file transfer over WebTorrent (torrents on the web)
JavaScript
3,423
star
4

bittorrent-tracker

🌊 Simple, robust, BitTorrent tracker (client & server) implementation
JavaScript
1,744
star
5

bittorrent-dht

🕸 Simple, robust, BitTorrent DHT implementation
JavaScript
1,216
star
6

webtorrent-cli

WebTorrent, the streaming torrent client. For the command line.
JavaScript
1,154
star
7

webtorrent-hybrid

WebTorrent (with WebRTC support in Node.js)
JavaScript
518
star
8

parse-torrent

Parse a torrent identifier (magnet uri, .torrent file, info hash)
JavaScript
438
star
9

create-torrent

Create .torrent files
JavaScript
342
star
10

bittorrent-protocol

Simple, robust, BitTorrent peer wire protocol implementation
JavaScript
342
star
11

magnet-uri

Parse a magnet URI and return an object of keys/values
JavaScript
221
star
12

torrent-discovery

Discover BitTorrent and WebTorrent peers
JavaScript
216
star
13

node-bencode

bencode de/encoder for nodejs
JavaScript
165
star
14

webtorrent.io

The code that runs the WebTorrent website
JavaScript
125
star
15

bittorrent-peerid

Map a BitTorrent peer ID to a human-readable client name and version
JavaScript
65
star
16

parse-torrent-file

DEPRECATED: Parse a .torrent file and return an object of keys/values
JavaScript
63
star
17

ut_pex

Implementation of ut_pex bittorrent protocol (PEX) for webtorrent
JavaScript
58
star
18

workshop

Learn WebTorrent and WebRTC in a guided workshop!
48
star
19

bittorrent-lsd

Local Service Discovery (BEP14) implementation
JavaScript
35
star
20

fs-chunk-store

Filesystem (fs) chunk store that is abstract-chunk-store compliant
JavaScript
33
star
21

torrent-piece

Torrent piece abstraction
JavaScript
23
star
22

webtorrent-fixtures

Sample torrent files for the WebTorrent test suite
JavaScript
22
star
23

load-ip-set

download and parse ip-set (blocklist) files
JavaScript
22
star
24

lt_donthave

The BitTorrent lt_donthave extension (BEP 54)
JavaScript
11
star
25

addr-to-ip-port

Convert an "address:port" string to an array [address:string, port:number]
JavaScript
10
star
26

bep53-range

Parse and compose Magnet URI extension (BEP53) ranges
JavaScript
9
star
27

string2compact

Convert 'hostname:port' strings to BitTorrent's compact ip/host binary returned by Trackers
JavaScript
9
star
28

renovate-config

Renovate's config
1
star
29

semantic-release-config

JavaScript
1
star
30

.github

1
star