<commit_before>#!/usr/bin/env node
/* vim: set expandtab ts=4 sw=4: */
/*
 * You may redistribute this program and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
var Cjdns = require('./cjdnsadmin');
var PublicToIp6 = require('./publicToIp6');

var peerStats = function(){
  Cjdns.connectWithAdminInfo(function (cjdns) {
    var again = function (i) {
      cjdns.InterfaceController_peerStats(i, function (err, ret) {
        if (err) { throw err; }
          ret.peers.forEach(function (peer) {
            p = (PublicToIp6(peer['publicKey']) + '\t' + peer['switchLabel'] +
              '\tin ' + peer['bytesIn'] + '\tout ' + peer['bytesOut'] + '\t' +
              peer['state'] +
              '\tdup ' + peer['duplicates'] +
              ' los ' + peer['lostPackets'] +
                ' oor ' + peer['receivedOutOfRange']);
            if (typeof(peer.user) === 'string') {
              p += ' "' + peer['user'] + '"';
            }
            console.log(p);
          });
        if (typeof(ret.more) !== 'undefined') {
          again(i+1);
        } else {
          cjdns.disconnect();
        }
      });
    };
    again(0);
  });
};

module.exports = peerStats;<commit_msg>stats are json, accepts a callback<commit_after>#!/usr/bin/env node
/* vim: set expandtab ts=4 sw=4: */
/*
 * You may redistribute this program and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation,
 * either version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
var Cjdns = require('./cjdnsadmin');
var PublicToIp6 = require('./publicToIp6');

var peerStats = function(callback){
  if(typeof callback == 'undefined'){
    callback = console.log;
  }
  Cjdns.connectWithAdminInfo(function (cjdns) {
    var again = function (i) {
    var roster = [];
      cjdns.InterfaceController_peerStats(i, function (err, ret) {
        if (err) { throw err; }
          ret.peers.forEach(function (peer) {
            var stats = {
              key:PublicToIp6(peer['publicKey'])
              ,switchLabel:peer['switchLabel']
              ,bytesIn:peer['bytesIn']
              ,bytesOut:peer['bytesOut']
              ,state:peer['state']
              ,duplicates:peer['duplicates']
              ,receivedOutOfRange:peer['receivedOutOfRange']
              ,user:(typeof(peer.user) === 'string')?peer['user']:""
            };
          roster.push(stats);
          });
        if (typeof(ret.more) !== 'undefined') {
          again(i+1);
        } else {
          callback(roster);
          cjdns.disconnect();
        }
      });
    };
    again(0);
  });
};

module.exports = peerStats;
{'fraction_non_alphanumeric': 0.13210702341137123, 'fraction_numerical': 0.004459308807134894, 'mean_word_length': 2.4709864603481626, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3839015', 'n_tokens_mistral': 1035, 'n_tokens_neox': 1019, 'n_words': 318}