From 9c9b3580a9f7888746c6c49019a05a1215f0c140 Mon Sep 17 00:00:00 2001 From: Alden Torres Date: Wed, 3 Feb 2016 16:10:09 -0500 Subject: [PATCH] [node] Complete fetch_manget test --- node/fetch_magnet.js | 30 ++++++++++++++++++++++++------ node/jlibtorrent.js | 4 ++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/node/fetch_magnet.js b/node/fetch_magnet.js index 69eb40057..417ff7497 100644 --- a/node/fetch_magnet.js +++ b/node/fetch_magnet.js @@ -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) { diff --git a/node/jlibtorrent.js b/node/jlibtorrent.js index a166f2320..bfcb475a7 100644 --- a/node/jlibtorrent.js +++ b/node/jlibtorrent.js @@ -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();