Browse Source

moved nodejs tools to top level

Caleb James DeLisle 9 years ago
parent
commit
43266c9d8c

+ 0 - 62
contrib/nodejs/tools/cjdnslog.js

@@ -1,62 +0,0 @@
-#!/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/cjdnsadmin');
-
-var usage = function () {
-    console.log("Usage: cjdnslog.js [-v <verbosity>] [-f <filename>] [-l <lineNum>]");
-    console.log("cjdnslog.js -v INFO                 <-- log all INFO and higher (WARN, ERROR, or CRITICAL) messages.");
-    console.log("cjdnslog.js                         <-- log everything");
-    console.log("cjdnslog.js -f CryptoAuth.c         <-- log everything in CryptoAuth.c");
-    console.log("cjdnslog.js -v INFO -f CryptoAuth.c <-- log INFO and higher in CryptoAuth.c");
-    console.log("cjdnslog.js -f CryptoAuth.c -l 747  <-- print messages from log statement on line 747 of CryptoAuth.c");
-    console.log("cjdnslog.js -l 747                  <-- print messages from log statements on line 747 of any file at all.");
-};
-
-if (process.argv[process.argv.length-1] === '--help') {
-    usage();
-    process.exit(0);
-}
-
-var printMsg = function (data) {
-    console.log(data['time'] + ' ' + data['level'] + ' ' + data['file'] + ':' + data['line'] + ' ' + data['message']);
-}
-
-Cjdns.connectWithAdminInfo(function (cjdns) {
-
-    var n;
-    var verbosity;
-    var file;
-    var line;
-    if ((n = process.argv.indexOf('-v')) !== -1) { verbosity = process.argv[n+1]; }
-    if ((n = process.argv.indexOf('-f')) !== -1) { file = process.argv[n+1]; }
-    if ((n = process.argv.indexOf('-l')) !== -1) { line = process.argv[n+1]; }
-
-    cjdns.setDefaultHandler(function (err, msg) {
-        if (err) { throw err; }
-        printMsg(msg);
-    });
-    cjdns.AdminLog_subscribe(line, file, verbosity, function (err, ret) {
-        if (err) { throw err; }
-
-        // make sure cjdns doesn't think we've gone missing!
-        setInterval(function () {
-            cjdns.ping(function (err, ret) {
-                if (err) { throw err; }
-            });
-        }, 10000);
-    });
-});

+ 0 - 223
contrib/nodejs/tools/getLinks.js

@@ -1,223 +0,0 @@
-#!/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/cjdnsadmin');
-var nThen = require('../cjdnsadmin/nthen');
-var PublicToIp6 = require('./lib/publicToIp6');
-
-var NodeStore_nodeForAddr = function(cjdns, state, addr, callback) {
-    if (typeof(state['NodeStore_nodeForAddr' + addr]) !== 'undefined') {
-        callback(state['NodeStore_nodeForAddr' + addr]);
-    } else {
-        //console.log('NodeStore_nodeForAddr(' + addr + ');');
-        cjdns.NodeStore_nodeForAddr(addr, function (err, ret) {
-            if (err) { throw err; }
-            state['NodeStore_nodeForAddr' + addr] = ret;
-            callback(ret);
-        });
-    }
-};
-
-var getNode = function (cjdns, next, output, state, parentPath, ipsByReach, nodes, callback) {
-
-    if (next.parent === next.child) { process.nextTick(callback); return; }
-
-    var getNodeRet;
-    var path;
-    nThen(function (waitFor) {
-
-        NodeStore_nodeForAddr(cjdns, state, next.child, waitFor(function (ret) {
-            //console.log('cjdns.NodeStore_nodeForAddr(' + next.child + '); --> ' + JSON.stringify(ret, null, '  '));
-            getNodeRet = ret;
-        }));
-
-    }).nThen(function (waitFor) {
-
-        if (!parentPath) {
-            return;
-        }
-
-        cjdns.NodeStore_getRouteLabel(parentPath, next.cannonicalLabel, waitFor(function (err, ret) {
-            if (err) { throw err; }
-            if (ret.error !== 'none') {
-                throw new Error('cjdns.NodeStore_getRouteLabel(' + parentPath + ', ' + next.cannonicalLabel +
-                    '); --> ' + JSON.stringify(ret, null, '  '));
-            }
-            //console.log('cjdns.NodeStore_getRouteLabel(' + parentPath + ', ' + next.pathParentToChild + ') --> ' + ret.result);
-            if (ret.result !== 'ffff.ffff.ffff.ffff') {
-                path = ret.result;
-            }
-        }));
-
-    }).nThen(function (waitFor) {
-
-        //console.log(spaces + next.child + '  ' + next.cannonicalLabel + " -> " + path);
-        // if next.parent skips the bootstrap route
-        if (next.parent) {
-            var out = {};
-            output.push(out);
-            output = out;
-        }
-        if (output.peers) { /* sanity check */ throw new Error(); }
-        output.addr = next.child;
-        output.cannonicalLabel = next.cannonicalLabel;
-        output.isOneHop = next.isOneHop;
-        output.fullPath = path;
-        output.peers = [];
-
-        if (!path) { return; }
-
-        var links = [];
-        nThen(function (waitFor) {
-
-            for (var i = 0; i < getNodeRet.result.linkCount; i++) {
-                cjdns.NodeStore_getLink(next.child, i, waitFor(function (err, ret) {
-                    if (err) { throw err; }
-                    links.push(ret);
-                }));
-            }
-
-        }).nThen(function (waitFor) {
-
-            if (nodes.indexOf(next.child) > -1) { process.nextTick(callback); return; }
-            nodes.push(next.child);
-
-            //console.log(JSON.stringify(links, null, '  '));
-            links.sort(function (a,b) {
-                if (a.isOneHop !== b.isOneHop) { return a.isOneHop ? -1 : 1; }
-                return (ipsByReach.indexOf(a.result.child) < ipsByReach.indexOf(b.result.child)) ?
-                    -1 : 1;
-            });
-            //console.log(JSON.stringify(links, null, '  '));
-            //console.log(JSON.stringify(ipsByReach, null, '  '));
-            for (var i = 0; i < links.length; i++) {
-                getNode(cjdns, links[i].result, output.peers, state, path, ipsByReach, nodes, waitFor());
-            }
-
-        }).nThen(waitFor());
-
-    }).nThen(function (waitFor) {
-
-        callback();
-
-    });
-};
-
-var dumpOldTable = function (cjdns, callback) {
-    var output = [];
-    var again = function (i) {
-        cjdns.NodeStore_dumpTable(i, function (err, table) {
-            if (err) { throw err; }
-            var j;
-            for (j = 0; j < table.routingTable.length; j++) {
-                var r = table.routingTable[j];
-                output.push(r);
-            }
-            if (j) {
-                again(i+1);
-            } else {
-                callback(output);
-            }
-        });
-    };
-    again(0);
-};
-
-var ipsByReachDesc = function (cjdns, callback) {
-    dumpOldTable(cjdns, function (oldTable) {
-
-        oldTable.sort(function (a, b) {
-            if (a.ip !== b.ip) { return (a.ip > b.ip) ? 1 : -1; }
-            if (a.link !== b.link) { return (Number(a.link) < Number(b.link)) ? 1 : -1; }
-            if (a.path !== b.path) { return (a.path > b.path) ? 1 : -1; }
-            throw new Error("dupe entry");
-        });
-        var bestReaches = [];
-        var last;
-        for (var i = 0; i < oldTable.length; i++) {
-            var r = oldTable[i];
-            if (last !== r.ip) {
-                bestReaches.push({ip:r.ip, link:r.link});
-                last = r.ip;
-            }
-        }
-        bestReaches.sort(function (a, b) { return (a.link > b.link) ? 1 : -1; });
-        var out = [];
-        for (var i = 0; i < bestReaches.length; i++) {
-            out.push(bestReaches[i].ip);
-        }
-        callback(out);
-        //bestReaches.forEach(function (node) { console.log(node.ip + '  ' + node.link); });
-    });
-};
-
-var getTree = function (cjdns, callback) {
-    ipsByReachDesc(cjdns, function (ipsByReach) {
-
-        cjdns.NodeStore_nodeForAddr(undefined, function (err, ret) {
-            if (err) { throw err; }
-            var myIp6 = PublicToIp6.convert(ret['result']['key']);
-            var output = {};
-            var selfRoute = '0000.0000.0000.0001';
-            var initialNode = { child: myIp6, cannonicalLabel: selfRoute };
-            getNode(cjdns, initialNode, output, {}, selfRoute, ipsByReach, [], function () {
-                callback(output);
-            });
-        });
-    });
-};
-
-var printTree = function (cjdns, tree, callback) {
-    var pt = function (tree, spaces, callback) {
-        var nt = nThen(function (waitFor) {
-            process.stdout.write(spaces + tree.addr + '  ' + tree.cannonicalLabel + ' --> ' + tree.fullPath);
-            if (tree.fullPath === '0000.0000.0000.0001') { return; }
-            cjdns.RouterModule_pingNode(tree.fullPath, waitFor(function (err, ret) {
-                if (err) { throw err; }
-                var resp = (ret.result !== 'pong') ? "[" + ret.error + "]" : (ret.ms + 'ms.');
-                if (resp == '[could not find node to ping]') { resp = '[notfound]'; }
-                process.stdout.write('  rp:' + resp);
-            }));
-        }).nThen(function (waitFor) {
-            cjdns.SwitchPinger_ping(tree.fullPath, waitFor(function (err, ret) {
-                if (err) { throw err; }
-                var resp = (ret.result !== 'pong') ? ("["+ret.result+"]") : (ret.ms + 'ms.');
-                process.stdout.write('  sp:' + resp);
-            }));
-        }).nThen(function (waitFor) {
-            process.stdout.write(((tree.isOneHop === '1') ? '  oh' : '') + '\n');
-        }).nThen;
-
-        tree.peers.forEach(function (peer) {
-            nt = nt(function (waitFor) {
-                pt(peer, '  ' + spaces, waitFor());
-            }).nThen;
-        });
-
-        nt(callback);
-    };
-    pt(tree, '', callback);
-};
-
-Cjdns.connectWithAdminInfo(function (cjdns) {
-
-    getTree(cjdns, function (output) {
-        //console.log(JSON.stringify(output, null, '  '));
-        printTree(cjdns, output, function() {
-            cjdns.disconnect();
-        });
-    });
-
-});

+ 0 - 93
contrib/nodejs/tools/netwalker.js

@@ -1,93 +0,0 @@
-#!/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/cjdnsadmin');
-var nThen = require('../cjdnsadmin/nthen');
-
-var getKey = function (nodeId) {
-    return nodeId.replace(/v[0-9]*\.[0-9a-f\.]{20}/, '');
-};
-
-var print = function (map) {
-    var done = [];
-    p = function (key, id, spaces) {
-        var entry = map[key];
-        if (!entry || done.indexOf(key) > -1) { return; }
-        done.push(key);
-        console.log(spaces + id);
-        if (typeof(entry.peers) !== 'undefined') {
-            for (var i = 0; i < entry.peers.length; i++) {
-                var k = getKey(entry.peers[i]);
-                if (k === key || map[k].bestParent != key) { continue; }
-                p(k, entry.peers[i], spaces + '  ');
-            }
-        }
-    };
-    p(getKey(map.selfNode), map.selfNode, '')
-};
-
-Cjdns.connectWithAdminInfo(function (cjdns) {
-
-    var addrs = [];
-    var queried = [];
-
-    var map = {};
-
-    nThen(function (waitFor) {
-
-        cjdns.RouterModule_getPeers('0000.0000.0000.0001', waitFor(function (err, ret) {
-            if (err) { throw err; }
-            if (ret.error !== 'none') { throw new Error(ret.error); }
-            for (var i = 0; i < ret.peers.length; i++) {
-                if (ret.peers[i].indexOf('0000.0000.0000.0001') > -1) {
-                    addrs.push(ret.peers[i]);
-                    map.selfNode = ret.peers[i];
-                    return;
-                }
-            }
-            throw new Error(JSON.stringify(ret, null, '  '));
-        }));
-
-    }).nThen(function (waitFor) {
-        var again = function (addr) {
-            var key = getKey(addr);
-            cjdns.RouterModule_getPeers(addr, 200, waitFor(function (err, ret) {
-                if (err) { throw err; }
-                console.log(addr + ' -> ' + JSON.stringify(ret, null, '  '));
-                if (typeof(ret.peers) === 'undefined') { return; }
-                if (ret.error !== 'none') { throw new Error(ret.error); }
-                for (var i = 0; i < ret.peers.length; i++) {
-                    var ckey = getKey(ret.peers[i]);
-                    if (queried.indexOf(ckey) === -1) {
-                        (map[ckey] = map[ckey] || {}).bestParent = key;
-                        queried.push(ckey);
-                        again(ret.peers[i]);
-                    }
-                //console.log(ret.peers[i]);
-                }
-                (map[key] = map[key] || {}).peers = ret.peers;
-            }));
-        };
-        again(addrs.pop());
-
-    }).nThen(function (waitFor) {
-        console.log(JSON.stringify(map, null, '  '));
-        //var tree = buildTree(map);
-        print(map);
-        cjdns.disconnect();
-    });
-
-});

+ 0 - 40
contrib/nodejs/tools/pingflood.js

@@ -1,40 +0,0 @@
-#!/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/>.
- */
-
-/*
- * test the admin port
- */
-
-
-var Cjdns = require('../cjdnsadmin/cjdnsadmin');
-var nThen = require('../cjdnsadmin/nthen');
-
-Cjdns.connectWithAdminInfo(function (cjdns) {
-
-    nThen(function (waitFor) {
-
-        for (var i = 0; i < 10000; i++) {
-            cjdns.RouterModule_pingNode('0000.0000.0000.0001', waitFor(function (err, ret) {
-                if (err) { throw err; }
-            }));
-        }
-
-    }).nThen(function (waitFor) {
-
-        cjdns.disconnect();
-    });
-
-});

+ 2 - 1
contrib/nodejs/tools/cexec.js → tools/cexec

@@ -1,4 +1,5 @@
 #!/usr/bin/env node
+/* -*- Mode:Js */
 /* vim: set expandtab ts=4 sw=4: */
 /*
  * You may redistribute this program and/or modify it under the terms of
@@ -14,7 +15,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-var Cjdns = require('../cjdnsadmin/cjdnsadmin');
+var Cjdns = require('../contrib/nodejs/cjdnsadmin/cjdnsadmin');
 
 Cjdns.connectWithAdminInfo(function (cjdns) {
     var code = process.argv[process.argv.length-1].replace(/\).*$/, ',cb);');

+ 1 - 1
contrib/nodejs/tools/cjdnslog → tools/cjdnslog

@@ -15,7 +15,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-var Cjdns = require('../cjdnsadmin/cjdnsadmin');
+var Cjdns = require('../contrib/nodejs/cjdnsadmin/cjdnsadmin');
 
 var usage = function () {
     console.log("Usage: cjdnslog.js [-v <verbosity>] [-f <filename>] [-l <lineNum>]");

+ 2 - 1
contrib/nodejs/tools/dumptable.js → tools/dumptable

@@ -1,4 +1,5 @@
 #!/usr/bin/env node
+/* -*- Mode:Js */
 /* vim: set expandtab ts=4 sw=4: */
 /*
  * You may redistribute this program and/or modify it under the terms of
@@ -13,7 +14,7 @@
  * 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/cjdnsadmin');
+var Cjdns = require('../contrib/nodejs/cjdnsadmin/cjdnsadmin');
 
 Cjdns.connectWithAdminInfo(function (cjdns) {
 

+ 0 - 0
contrib/nodejs/tools/lib/publicToIp6.js → tools/lib/publicToIp6.js


+ 3 - 3
contrib/nodejs/tools/pathfinderTree.js → tools/pathfinderTree

@@ -1,4 +1,5 @@
 #!/usr/bin/env node
+/* -*- Mode:Js */
 /* vim: set expandtab ts=4 sw=4: */
 /*
  * You may redistribute this program and/or modify it under the terms of
@@ -13,9 +14,8 @@
  * 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/cjdnsadmin');
-var nThen = require('../cjdnsadmin/nthen');
+var Cjdns = require('../contrib/nodejs/cjdnsadmin/cjdnsadmin');
+var nThen = require('../contrib/nodejs/cjdnsadmin/nthen');
 
 var getAddresses = function (cjdns, callback) {
     var addresses = [];

+ 2 - 1
contrib/nodejs/tools/peerStats.js → tools/peerStats

@@ -1,4 +1,5 @@
 #!/usr/bin/env node
+/* -*- Mode:Js */
 /* vim: set expandtab ts=4 sw=4: */
 /*
  * You may redistribute this program and/or modify it under the terms of
@@ -13,7 +14,7 @@
  * 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/cjdnsadmin');
+var Cjdns = require('../contrib/nodejs/cjdnsadmin/cjdnsadmin');
 var PublicToIp6 = require('./lib/publicToIp6');
 
 Cjdns.connectAsAnon(function (cjdns) {

+ 2 - 2
contrib/nodejs/tools/ping → tools/ping

@@ -14,8 +14,8 @@
  * 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/cjdnsadmin');
-var nThen = require('../cjdnsadmin/nthen');
+var Cjdns = require('../contrib/nodejs/cjdnsadmin/cjdnsadmin');
+var nThen = require('../contrib/nodejs/cjdnsadmin/nthen');
 var Dns =  require('dns');
 
 var WAIT_TIME = 5000;

+ 3 - 2
contrib/nodejs/tools/pingAll.js → tools/pingAll

@@ -1,4 +1,5 @@
 #!/usr/bin/env node
+/* -*- Mode:js */
 /* vim: set expandtab ts=4 sw=4: */
 /*
  * You may redistribute this program and/or modify it under the terms of
@@ -13,8 +14,8 @@
  * 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/cjdnsadmin');
-var nThen = require('../cjdnsadmin/nthen');
+var Cjdns = require('../contrib/nodejs/cjdnsadmin/cjdnsadmin');
+var nThen = require('../contrib/nodejs/cjdnsadmin/nthen');
 
 Cjdns.connectWithAdminInfo(function (cjdns) {
 

+ 1 - 0
contrib/nodejs/tools/splice.js → tools/splice

@@ -1,4 +1,5 @@
 #!/usr/bin/env node
+/* -*- Mode:js */
 /*
  * 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,

+ 2 - 2
contrib/nodejs/tools/traceroute → tools/traceroute

@@ -14,8 +14,8 @@
  * 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/cjdnsadmin');
-var nThen = require('../cjdnsadmin/nthen');
+var Cjdns = require('../contrib/nodejs/cjdnsadmin/cjdnsadmin');
+var nThen = require('../contrib/nodejs/cjdnsadmin/nthen');
 var PubToIp6 = require('./lib/publicToIp6');
 var Dns = require('dns');