ut_pex

BitTorrent Extension for Peer Discovery (PEX)
Node.js implementation of the ut_pex protocol, 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:
var Protocol = var net = netTo add support for PEX, simply modify your code like this:
var Protocol = var net = var ut_pex = netmethods
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.
wireut_pexstartNote 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.
wireut_pexreset
Stops sending updates to the remote peer and resets internal state of peers seen.
wireut_pexaddPeer
Adds a peer to the locally discovered peer list to send with the next PEX message.
wireut_pexdropPeer
Adds a peer to the locally dropped peer list to send with the next PEX message.
wireut_pexevents
event: 'peer'
Fired for every new peer received from PEX.
wireut_pexNote: 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.
wireut_pexNote: the event will not fire if the peer does not support ut_pex or if they don't respond.
todo
(prioritized highest to lowest)
basic discoverybasic advertisementbasic unit tests- better unit tests
- peer flag support
- destroy wire if peer sends PEX messages too frequently
- ipv6 support
license
MIT. Copyright (c) Travis Fischer and WebTorrent, LLC