Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
bittorrent-dht-byo
Advanced tools
A middle-level library for interacting with the BitTorrent DHT network. Bring your own transport layer and peer logic.
A middle-level library for interacting with the BitTorrent DHT network. Bring your own transport layer and peer logic.
This library implements all of the parsing, some of the logic, and none of the networking required to talk to the BitTorrent DHT network. It knows how to parse and serialise messages, keep track of nodes and their health, correlate queries and responses, and (currently quite badly) traverse the network to find peers for a specific info_hash.
DHT(options);
var dht = new DHT({
nodeId: Buffer("12345678901234567890"),
nodes: [...],
});
Arguments
DHTNode
-compatible objects - they will be turned
into DHTNode
objects if they're not already (optional)countNodes();
Use this to get the number of known nodes. Using this, you can decide whether or not to bootstrap from a public router or something.
var count = dht.countNodes();
if (count === 0) {
dht.bootstrap(...);
}
bootstrap(node, options, cb);
Use bootstrap
to get your DHT primed and ready for use if you don't know of
any nodes yet. You need to point it at a known-good DHT node. There are a few
floating around that aren't too hard to find.
var node = new DHT.Node({
host: "public.dht.router",
port: 12345,
});
var nodeId = Buffer("01234567890123456789");
dht.bootstrap(node, {nodeId: nodeId}, function(err) {
if (err) {
// there was an error bootstrapping, things probably won't work well
} else {
// you should be good to go!
}
});
Arguments
DHTNode
getPeers(infoHash, options, cb);
Use getPeers
to get a list of peers for a given info_hash.
var hash = Buffer("597a92f6eeed29e6028b70b416c847e51ba76c38", "hex"),
options = {retries: 3};
dht.getPeers(hash, options, function gotPeers(err, peers) {
console.log(err, peers);
});
Arguments
on("outgoing", function(message, node) { ... });
This event tells you when the DHT is trying to send a message to a remote node.
dht.on("outgoing", function(message, node) {
socket.send(message, 0, message.length, node.port, node.host, function(err) { ... });
});
Parameters
DHTNode
object; the intended recipient of the messageon("query", function(query) { ... });
This event is fired when a query is received and parsed correctly.
dht.on("query", function(query) {
console.log(query.method.toString());
});
Parameters
DHTNode
object; the sender of the queryon("unassociatedResponse", function(response) { ... });
This event fires when a response is received that doesn't correlate with a known query of ours. This can happen if a response is sent after a timeout has already fired, for example, or if a remote node is just confused or broken.
dht.on("unassociatedResponse", function(response) {
console.log(response.id);
});
Parameters
DHTNode
object!)on("unassociatedError", function(error) { ... });
This is the same as the unassociatedResponse
event, in that it fires when an
error is received under similar conditions.
dht.on("unassociatedError", function(error) {
console.log(error.id);
});
Parameters
DHTError
object; the error contentDHTNode
object!)new DHT.Node(options);
This object represents a node that the DHT client knows about. It emits some events when important things change.
var node = new DHT.Node({
nodeId: Buffer(...),
host: "1.2.3.4",
port: 12345,
firstSeen: 1234567890,
lastQuery: 1234567890,
lastResponse: 1234567890,
token: Buffer(...),
});
Arguments
toJSON();
Does what it sounds like. Turns the node into an object that's nicely serialisable.
var serialised = JSON.stringify(node);
Returns: object
toPeerInfo();
Get the "compact peer info" representation of the node.
var peerInfo = node.toPeerInfo();
Returns: buffer
toNodeInfo();
Get the "compact node info" representation of the node.
var nodeInfo = node.toNodeInfo();
Returns: buffer
setToken(token);
Set the write token for the node. Causes the node to emit a token
event.
setToken(Buffer("asdfqwer"));
Arguments
setStatus(status);
Set the status of the node. Causes the node to emit a status
event if it
changes.
node.setStatus("good");
Arguments
setLastQuery(time);
Set the last query time of the node. May cause the node to change its status.
node.setLastQuery(1234567890);
Arguments
setLastResponse(time);
Set the last response time of the node. May cause the node to change its status.
node.setLastResponse(1234567890);
Arguments
incrementFailures();
Increment the failure count of the node. May cause the node to change its status.
node.incrementFailures();
resetFailures();
Reset the failure count of the node to 0.
node.resetFailures();
3-clause BSD. A copy is included with the source.
FAQs
A middle-level library for interacting with the BitTorrent DHT network. Bring your own transport layer and peer logic.
The npm package bittorrent-dht-byo receives a total of 0 weekly downloads. As such, bittorrent-dht-byo popularity was classified as not popular.
We found that bittorrent-dht-byo demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.