1
0

dumptable 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. Cjdns.connectWithAdminInfo(function (cjdns) {
  19. var list = [];
  20. var again = function (i) {
  21. cjdns.NodeStore_dumpTable(i, function (err, table) {
  22. if (err) { throw err; }
  23. var j;
  24. for (j = 0; j < table.routingTable.length; j++) {
  25. var r = table.routingTable[j];
  26. list.push(r);
  27. }
  28. if (j) {
  29. again(i+1);
  30. } else {
  31. list.sort(function (a,b) { return a.path < b.path ? -1 : 1; });
  32. list.forEach(function (r) {
  33. console.log(r.addr + ' ' + r.link + ' ' + r.time);
  34. });
  35. console.log(table.count + ' nodes ' + table.peers + ' peers');
  36. cjdns.disconnect();
  37. }
  38. });
  39. };
  40. again(0);
  41. });