All Projects → webtorrent → ut_pex

webtorrent / ut_pex

Licence: MIT license
Implementation of ut_pex bittorrent protocol (PEX) for webtorrent

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ut pex

Create Torrent
Create .torrent files
Stars: ✭ 264 (+388.89%)
Mutual labels:  torrent, bittorrent, webtorrent
Webtorrent
⚡️ Streaming torrent client for the web
Stars: ✭ 25,554 (+47222.22%)
Mutual labels:  torrent, bittorrent, webtorrent
Bittorrent Protocol
Simple, robust, BitTorrent peer wire protocol implementation
Stars: ✭ 279 (+416.67%)
Mutual labels:  torrent, bittorrent, webtorrent
CheckWebPeer
Check WebRTC peers of torrents.
Stars: ✭ 19 (-64.81%)
Mutual labels:  torrent, bittorrent, webtorrent
Wt Tracker
High-performance WebTorrent tracker
Stars: ✭ 144 (+166.67%)
Mutual labels:  torrent, bittorrent, webtorrent
Diffy
🎞️💓🍿 Love streaming - It's always best to watch a movie together ! 🤗
Stars: ✭ 37 (-31.48%)
Mutual labels:  torrent, bittorrent, webtorrent
Webtorrent Hybrid
WebTorrent (with WebRTC support in Node.js)
Stars: ✭ 422 (+681.48%)
Mutual labels:  torrent, bittorrent, webtorrent
parse-torrent-file
DEPRECATED: Parse a .torrent file and return an object of keys/values
Stars: ✭ 62 (+14.81%)
Mutual labels:  torrent, bittorrent, webtorrent
Bittorrent Tracker
🌊 Simple, robust, BitTorrent tracker (client & server) implementation
Stars: ✭ 1,184 (+2092.59%)
Mutual labels:  torrent, bittorrent, webtorrent
Bittorrent Peerid
Map a BitTorrent peer ID to a human-readable client name and version
Stars: ✭ 47 (-12.96%)
Mutual labels:  torrent, bittorrent, webtorrent
Parse Torrent
Parse a torrent identifier (magnet uri, .torrent file, info hash)
Stars: ✭ 325 (+501.85%)
Mutual labels:  torrent, bittorrent, webtorrent
Torrent Discovery
Discover BitTorrent and WebTorrent peers
Stars: ✭ 177 (+227.78%)
Mutual labels:  torrent, bittorrent, webtorrent
Bittorrent Dht
🕸 Simple, robust, BitTorrent DHT implementation
Stars: ✭ 1,004 (+1759.26%)
Mutual labels:  torrent, bittorrent, webtorrent
Torrentpier
Main project repository
Stars: ✭ 166 (+207.41%)
Mutual labels:  torrent, bittorrent, webtorrent
Magnet Uri
Parse a magnet URI and return an object of keys/values
Stars: ✭ 183 (+238.89%)
Mutual labels:  torrent, bittorrent, webtorrent
porla
A high performance BitTorrent client for servers and seedboxes.
Stars: ✭ 83 (+53.7%)
Mutual labels:  torrent, bittorrent
trystero
🤝 Serverless WebRTC matchmaking for painless P2P — Make any site multiplayer in a few lines — Use BitTorrent, IPFS, or Firebase
Stars: ✭ 512 (+848.15%)
Mutual labels:  bittorrent, webtorrent
mad-torrent
Delphi bittorrent protocol implementation
Stars: ✭ 30 (-44.44%)
Mutual labels:  torrent, bittorrent
Katastrophe
Command Line Tool to download torrents
Stars: ✭ 85 (+57.41%)
Mutual labels:  torrent, bittorrent
Cratetorrent
A BitTorrent V1 engine library for Rust (and currently Linux)
Stars: ✭ 233 (+331.48%)
Mutual labels:  torrent, bittorrent

ut_pex ci npm downloads javascript style guide

BitTorrent Extension for Peer Discovery (PEX) (BEP11)

Node.js implementation of the ut_pex protocol (BEP11), which is the most popular PEX (peer exchange) protocol used by bittorrent clients.

The purpose of this extension is to allow peers to exchange known peers directly with each other, thereby facilitating more efficient peer discovery and healthier swarms.

The best description of the (nonstandardized) ut_pex protocol I could find is in section 2.1.4.3 of this paper.

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

install

npm install ut_pex

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:

const Protocol = require('bittorrent-protocol')
const net = require('net')

net.createServer(socket => {
  const 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 PEX, simply modify your code like this:

const Protocol = require('bittorrent-protocol')
const net = require('net')
const ut_pex = require('ut_pex')

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

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

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

  // (optional) start sending peer information to remote peer
  wire.ut_pex.start()

  // 'peer' event will fire for every new peer sent by the remote peer
  wire.ut_pex.on('peer', (peer, flags) => {
    // got a peer
    // probably add it to peer connections queue
  })

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

}).listen(6881)

methods

start

Start sending regular PEX updates to the remote peer. Use addPeer and dropPeer to control the content of PEX messages. PEX messages will be sent once every ~65 seconds.

wire.ut_pex.start()

Note that ut_pex may be used for one-way peer discovery without sending PEX updates to the remote peer, but this use case is discouraged because PEX, like bittorrent is more efficient through altruism.

stop

Stop sending PEX updates to the remote peer.

wire.ut_pex.stop()

reset

Stops sending updates to the remote peer and resets internal state of peers seen.

wire.ut_pex.reset()

addPeer

Adds an IPv4 peer to the locally discovered peer list to send with the next PEX message.

const peer = '127.0.0.1:6889'
const flags = {
  prefersEncryption: false,
  isSender: true,
  supportsUtp: true,
  supportsUtHolepunch: false,
  isReachable: false
}

wire.ut_pex.addPeer(peer, flags)

addPeer6

Adds an IPv6 peer to the locally discovered peer list to send with the next PEX message.

const peer = '[::1]:6889'
const flags = {
  prefersEncryption: false,
  isSender: true,
  supportsUtp: true,
  supportsUtHolepunch: false,
  isReachable: false
}

wire.ut_pex.addPeer6(peer, flags)

dropPeer

Adds an IPv4 peer to the locally dropped peer list to send with the next PEX message.

wire.ut_pex.dropPeer('127.0.0.1:6889')

dropPeer6

Adds an IPv6 peer to the locally dropped peer list to send with the next PEX message.

wire.ut_pex.dropPeer6('[::1]:6889')

events

event: 'peer'

Fired for every new peer received from PEX.

wire.ut_pex.on('peer', (peer, flags) => {
  const parts = peer.split(':')
  const ip = parts[0]
  const port = parts[1]
  // ...
})

Note: the event will not fire if the peer does not support ut_pex or if they don't respond.

event: 'dropped'

Fired for every peer dropped from the swarm notified via PEX.

wire.ut_pex.on('dropped', peer => {
  const parts = peer.split(':')
  const ip = parts[0]
  const port = parts[1]
  // ...
})

Note: the event will not fire if the peer does not support ut_pex or if they don't respond.

flags

In order to handle ut_pex protocol (BEP11) bit-flags in a more humand friendly format, the given boolean based Object has been defined.

const flags = {
  prefersEncryption: Boolean,
  isSender: Boolean,
  supportsUtp: Boolean,
  supportsUtHolepunch: Boolean,
  isReachable: Boolean
}

license

MIT. Copyright (c) Travis Fischer and WebTorrent, LLC

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].