peerStats.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env node
  2. /* vim: set expandtab ts=4 sw=4: */
  3. /*
  4. * You may redistribute this program and/or modify it under the terms of
  5. * the GNU General Public License as published by the Free Software Foundation,
  6. * either version 3 of the License, or (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. var Cjdns = require('../cjdnsadmin/cjdnsadmin');
  17. var PublicToIp6 = require('./lib/publicToIp6');
  18. Cjdns.connectWithAdminInfo(function (cjdns) {
  19. var again = function (i) {
  20. cjdns.InterfaceController_peerStats(i, function (err, ret) {
  21. if (err) { throw err; }
  22. ret.peers.forEach(function (peer) {
  23. p = (PublicToIp6.convert(peer['publicKey']) + '\t' + peer['switchLabel'] +
  24. '\tin ' + peer['bytesIn'] + '\tout ' + peer['bytesOut'] + '\t' +
  25. peer['state'] +
  26. '\tdup ' + peer['duplicates'] +
  27. ' los ' + peer['lostPackets'] +
  28. ' oor ' + peer['receivedOutOfRange']);
  29. if (typeof(peer.user) === 'string') {
  30. p += ' "' + peer['user'] + '"';
  31. }
  32. console.log(p);
  33. });
  34. if (typeof(ret.more) !== 'undefined') {
  35. again(i+1);
  36. } else {
  37. cjdns.disconnect();
  38. }
  39. });
  40. };
  41. again(0);
  42. });