-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathcrawlDHT.js
executable file
·37 lines (27 loc) · 900 Bytes
/
crawlDHT.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"use strict";
const config = require('./config/database');
const DHT = require('bittorrent-dht');
const redis = require("redis");
const client = redis.createClient(config.redis.port, config.redis.host, config.redis.options);
const bunyan = require("bunyan");
const logger = bunyan.createLogger({name: "crawler"});
const dht = new DHT();
dht.listen(6881, () => {
logger.info('now listening');
logger.info(dht.address());
});
dht.on('ready', () => {
logger.info('now ready');
});
dht.on('announce', (peer, infoHash) => {
logger.info(`announce : ${peer.host}:${peer.port} : ${infoHash.toString('hex')}`);
dht.lookup(infoHash);
client.publish("DHTS", infoHash.toString('hex'));
});
dht.on('peer', (peer, infoHash, from) => {
logger.debug(`peer : ${peer.host}:${peer.port} : ${infoHash.toString('hex')}`);
});
dht.on('error', (err) => {
logger.error(err);
dht.destroy();
});