Security News
New Proposed CISA Mandate Would Require Critical Infrastructure to Report Ransom Payments Within 24 Hours
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
ut_pex
Advanced tools
Extension for Peer Discovery (PEX)
Weekly downloads
Readme
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.
npm install ut_pex
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 => {
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:
import Protocol from 'bittorrent-protocol'
import net from 'net'
import ut_pex from '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)
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 sending PEX updates to the remote peer.
wire.ut_pex.stop()
Stops sending updates to the remote peer and resets internal state of peers seen.
wire.ut_pex.reset()
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)
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)
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')
Adds an IPv6 peer to the locally dropped peer list to send with the next PEX message.
wire.ut_pex.dropPeer6('[::1]:6889')
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.
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.
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
}
MIT. Copyright (c) Travis Fischer and WebTorrent, LLC
FAQs
Extension for Peer Discovery (PEX)
The npm package ut_pex receives a total of 2,531 weekly downloads. As such, ut_pex popularity was classified as popular.
We found that ut_pex demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 10 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISA has proposed a set of new rules that would require critical infrastructure to report cyber incidents and ransom payments.
Security News
Redis is no longer OSS, breaking its explicit commitment to remain under the BSD 3-Clause License forever. This has angered contributors who are now working to fork the software.
Product
Socket AI now enables 'AI detected potential malware' alerts by default, ensuring users benefit from AI-powered state-of-the-art malware detection without needing to opt-in.