Skip to content

Commit

Permalink
[node] Complete fetch_manget test
Browse files Browse the repository at this point in the history
  • Loading branch information
aldenml committed Feb 3, 2016
1 parent 4c553bc commit 9c9b358
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
30 changes: 24 additions & 6 deletions node/fetch_magnet.js
Expand Up @@ -2,14 +2,32 @@ const jlibtorrent = require('./jlibtorrent.js');

console.log("Using libtorrent version: " + jlibtorrent.LibTorrent.fullVersion());

const l = function (a) {
console.log(a.type() + " - " + a.what() + " - " + a.message());
}

const sp = new jlibtorrent.SettingsPack();
const s = new jlibtorrent.Session(sp, false, l);
const s = new jlibtorrent.Session(sp, false);

s.on('alert', function (a) {
if (a.type() === jlibtorrent.swig.metadata_received_alert.alert_type) {
a = jlibtorrent.swig.alert.cast_to_metadata_received_alert(a);
console.log(a)
var th = a.handle;
var ti = th.get_torrent_copy();
var entry = new jlibtorrent.swig.create_torrent(ti).generate();
console.log(entry.to_string());
process.exit(0);
}

if (a.type() === jlibtorrent.swig.metadata_failed_alert.alert_type) {
console.log("Failed to receive the magnet metadata");
process.exit(0);
}
});

function wait_for_nodes() {
s.fetchMagnet("magnet:?xt=urn:btih:a83cc13bf4a07e85b938dcf06aa707955687ca7c");
}

s.fetchMagnet("magnet:?xt=urn:btih:a83cc13bf4a07e85b938dcf06aa707955687ca7c");
console.log("Waiting 3 seconds to request...patience...");
setTimeout(wait_for_nodes, 3000);

process.stdout.write('Press ENTER to exit...');
process.stdin.once('data', function (data) {
Expand Down
4 changes: 4 additions & 0 deletions node/jlibtorrent.js
Expand Up @@ -170,6 +170,10 @@ const swig = require('./jlibtorrent.node');
return this.sp;
}

Session.prototype.postDHTStats = function () {
this.s.post_dht_stats();
}

Session.prototype.fetchMagnet = function (uri) {
var p = swig.add_torrent_params.create_instance_disabled_storage();
var ec = new swig.error_code();
Expand Down

0 comments on commit 9c9b358

Please sign in to comment.