dumpRumorMill 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env node
  2. /* -*- Mode:Js */
  3. /* vim: set expandtab ts=4 sw=4: */
  4. /*
  5. * You may redistribute this program and/or modify it under the terms of
  6. * the GNU General Public License as published by the Free Software Foundation,
  7. * either version 3 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. var Cjdns = require('./lib/cjdnsadmin/cjdnsadmin');
  18. var nThen = require('nthen');
  19. var dump = function (millName) {
  20. var cjdns;
  21. nThen(function (waitFor) {
  22. Cjdns.connectWithAdminInfo(waitFor(function (x) { cjdns = x; }));
  23. }).nThen(function (waitFor) {
  24. var list = [];
  25. var again = function (i) {
  26. cjdns.Janitor_dumpRumorMill(i, millName, function (err, out) {
  27. if (err) { throw err; }
  28. list.push.apply(list, out.addresses);
  29. if (out.addresses.length) {
  30. again(i+1);
  31. } else {
  32. list.sort();
  33. list.forEach(function (addr) { console.log(addr); });
  34. console.log("total " + out.total);
  35. cjdns.disconnect();
  36. }
  37. });
  38. };
  39. again(0);
  40. });
  41. };
  42. var MILLS = ['externalMill','linkMill','nodeMill','dhtMill','splitMill'];
  43. var main = function (args) {
  44. if (MILLS.indexOf(args[args.length-1]) !== -1) {
  45. dump(args[args.length-1]);
  46. return;
  47. }
  48. console.log("Usage:");
  49. console.log(" dumpRumorMill externalMill # dump external mill (highest priority)");
  50. console.log(" dumpRumorMill linkMill # dump high-priority mill for improving routes");
  51. console.log(" dumpRumorMill nodeMill # dump new node discovery mill");
  52. console.log(" dumpRumorMill dhtMill # dump DHT maintanence mill");
  53. console.log(" dumpRumorMill splitMill # dump link splitting mill");
  54. };
  55. main(process.argv);