-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsave-hash.js
85 lines (74 loc) · 2.37 KB
/
save-hash.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/** 通过http web 打印 */
const http = require('http');
// const spider = new (require('./lib/spider'))
// spider.on('ensureHash', (hash, addr) => {
// let content = JSON.stringify({
// hash,
// name: 'test'
// })
// let options = {
// hostname: 'localhost',
// path: '/bt/create',
// port: 8888,
// method: 'POST',
// // secureProtocol: 'SSLv3_method',
// headers: {
// 'Content-Type': 'application/json;charset=UTF-8',
// 'Content-Length': content.length
// }
// };
// let req = http.request(options, res => {
// res.setEncoding('utf8');
// res.on('data', (chunk) => {
// // console.log(`响应主体: ${chunk}`);
// });
// })
// req.write(content);
// })
// spider.listen(6339)
/** download torrent */
// const util = require('util');
// const download = require('./common/download.js');
// let _infohash = 'd2474e86c95b19b8bcfdb92bc12c9d44667cfa36';
// _infohash = _infohash.toUpperCase();
// let url = util.format('http://torrage.com/torrent/%s.torrent', _infohash);
// console.log(url)
// download(url, (err, data) => {
// console.log('err:', err)
// console.log('data:', data);
// })
/** decode torrent */
// const fs = require('fs');
// const torrent = require('./common/torrent.js');
// torrentData = torrent(fs.readFileSync('./assets/01.torrent'));
// console.log(torrentData);
// join DHT request
const spider = new (require('./lib/spider'))
// spider.on('ensureHash', (hash, addr)=> console.log(`magnet:?xt=urn:btih:${hash}`))
// spider.on('unensureHash', (hash)=> console.log(hash))
// spider.on('nodes', (nodes)=>console.log('foundNodes'))
spider.on('ensureHash', (hash, addr) => {
let content = JSON.stringify({
content: hash,
type: 'BT'
})
let options = {
hostname: '119.96.189.81',
path: '/powerful/bt',
port: 8877,
method: 'POST',
// secureProtocol: 'SSLv3_method',
headers: {
'Content-Type': 'application/json;charset=UTF-8',
'Content-Length': content.length
}
};
let req = http.request(options, res => {
// res.setEncoding('utf8');
// res.on('data', (chunk) => {
// // console.log(`响应主体: ${chunk}`);
// });
})
req.write(content);
})
spider.listen(6339)