dumpRumorMill 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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('../contrib/nodejs/cjdnsadmin/cjdnsadmin');
  18. var nThen = require('../contrib/nodejs/cjdnsadmin/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 main = function (args) {
  43. if (['externalMill','linkMill','nodeMill','dhtMill'].indexOf(args[args.length-1]) !== -1) {
  44. dump(args[args.length-1]);
  45. return;
  46. }
  47. console.log("Usage:");
  48. console.log(" dumpRumorMill externalMill # dump externally accessable mill");
  49. console.log(" dumpRumorMill linkMill # dump high-priority mill for improving routes");
  50. console.log(" dumpRumorMill nodeMill # dump new node discovery mill");
  51. console.log(" dumpRumorMill dhtMill # dump DHT maintanence mill");
  52. };
  53. main(process.argv);