peerStats 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 PublicToIp6 = require('./lib/publicToIp6');
  19. Cjdns.connectAsAnon(function (cjdns) {
  20. var again = function (i) {
  21. cjdns.InterfaceController_peerStats(i, function (err, ret) {
  22. if (err) { throw err; }
  23. ret.peers.forEach(function (peer) {
  24. p = peer['addr'] + ' ' + peer['state'] +
  25. ' in ' + peer['bytesIn'] + ' out ' + peer['bytesOut'];
  26. if (Number(peer['duplicates']) !== 0) {
  27. p += ' ' + ' DUP ' + peer['duplicates'];
  28. }
  29. if (Number(peer['lostPackets']) !== 0) {
  30. p += ' ' + ' LOS ' + peer['lostPackets'];
  31. }
  32. if (Number(peer['receivedOutOfRange']) !== 0) {
  33. p += ' ' + ' OOR ' + peer['receivedOutOfRange'];
  34. }
  35. if (typeof(peer.user) === 'string') {
  36. p += ' "' + peer['user'] + '"';
  37. }
  38. console.log(p);
  39. });
  40. if (typeof(ret.more) !== 'undefined') {
  41. again(i+1);
  42. } else {
  43. cjdns.disconnect();
  44. }
  45. });
  46. };
  47. again(0);
  48. });