## Walking all peers manually on a node using the common 3x5x8 switch scheme.
## We're exclusively using the 8 form because it's easier to stick to one form
## The node is 0015 to us, therefor all paths end in 5.
## The first entry in the 8 form is 0400

user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/splice.js 0000.0000.0000.0400 0000.0000.0000.0015
0000.0000.0000.4005

## After splicing that with the path to our peer, we clearly see that everything
## will have a 5 added to the end.

user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4005", 3000, 1)'
{
  "data": "",
  "key": "xp2f7m98uw24664ngwl47k8uyx59sblgp8qsbpk24sh10ppu9fz0.k",
  "ms": "382",
  "path": "0000.0000.0000.4005",
  "result": "pong",
  "txid": "824920922",
  "version": "8"
}

## 0400 is analogus to 0013 (the first peer)

user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.0135", 3000, 1)'
{
  "data": "",
  "key": "xp2f7m98uw24664ngwl47k8uyx59sblgp8qsbpk24sh10ppu9fz0.k",
  "ms": "407",
  "path": "0000.0000.0000.0135",
  "result": "pong",
  "txid": "1322201729",
  "version": "8"
}

## Since the lowest 2 bits are reserved for specifying the encoding form (they're both 0)
## numbers count 400, 404, 408, 40c, 410, 414, 418, 41c, 420 ...

user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4045", 3000, 1)'
{
  "data": "",
  "key": "2v6dt6f841hzhq2wsqwt263w2dswkt6fz82vcyxqptk88mtp8y50.k",
  "ms": "897",
  "path": "0000.0000.0000.4045",
  "result": "pong",
  "txid": "3621711461",
  "version": "8"
}

## This is us, wow, we have slot 3, what luck!
## the shortest version of this route is 0017
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4085", 3000, 1)'
{
  "data": "",
  "key": "b8xn6kv9279k7mjdmg08ut6yc4n3d2lp3s3juq39qz83z9bzxgz0.k",
  "ms": "638",
  "path": "0000.0000.0000.4085",
  "result": "pong",
  "txid": "1345867629",
  "version": "8"
}

## Oops! If you use a number which is not in the sequence you get a
## switch error (or perhaps it will be interpreted and end up at another node)
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.40d5", 3000, 1)'
{
  "data": "",
  "ms": "539",
  "path": "0000.0000.0000.40d5",
  "result": "err_switch",
  "txid": "3599763113",
  "version": "0"
}

user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.40c5", 3000, 1)'
{
  "data": "",
  "key": "lpcvt3u85q837u402dlu3rfg107x92j5xlzd77tftsjy88zx0yf0.k",
  "ms": "408",
  "path": "0000.0000.0000.40c5",
  "result": "pong",
  "txid": "259944377",
  "version": "7"
}
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4105", 3000, 1)'
{
  "data": "",
  "key": "wb0hdx8vu6khpfj32qzhvykjk7gq8bc691czhx3yp7zn04bh5gy0.k",
  "ms": "363",
  "path": "0000.0000.0000.4105",
  "result": "pong",
  "txid": "1099356221",
  "version": "8"
}
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4145", 3000, 1)'
{
  "data": "",
  "key": "6q09l149vz0bqtx51jy557juj39wxmupmfd52h9w5xsdnsns1qj0.k",
  "ms": "223",
  "path": "0000.0000.0000.4145",
  "result": "pong",
  "txid": "542004376",
  "version": "7"
}
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4185", 3000, 1)'
{
  "data": "",
  "key": "1cgrz7hmc4wzg7pu284u5b77y2mdzt261tr0rj0qf7j2vsqf5150.k",
  "ms": "312",
  "path": "0000.0000.0000.4185",
  "result": "pong",
  "txid": "87763052",
  "version": "7"
}
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.41c5", 3000, 1)'
{
  "data": "",
  "key": "w7xvbpmgwuwkv8x9wrpfmydtfxv6ydfmpktgc6tt8v8d3c9bn580.k",
  "ms": "394",
  "path": "0000.0000.0000.41c5",
  "result": "pong",
  "txid": "1682459805",
  "version": "8"
}
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4205", 3000, 1)'
{
  "data": "",
  "key": "11sfkq2clbv4dgzgx8hm47p4ld9pwy82y7jluvjh91cyl1n7bwf0.k",
  "ms": "329",
  "path": "0000.0000.0000.4205",
  "result": "pong",
  "txid": "3712296271",
  "version": "7"
}
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4245", 3000, 1)'
{
  "data": "",
  "key": "c94sls20x5shql6r4z4nvqlrs9pcppgj2h41m1bntzk60j5wrs40.k",
  "ms": "362",
  "path": "0000.0000.0000.4245",
  "result": "pong",
  "txid": "1883792007",
  "version": "7"
}
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4285", 3000, 1)'
{
  "data": "",
  "key": "08pdl5mbcpx2b0uh6wj6wktq5v47kv9gpy40rnqr52t1ugctr430.k",
  "ms": "252",
  "path": "0000.0000.0000.4285",
  "result": "pong",
  "txid": "711411764",
  "version": "7"
}
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.42c5", 3000, 1)'
{
  "data": "",
  "key": "r5tmqf72mjzht1grqm34l1ldrx9tdubyzw33ucng6bfqp1y0mux0.k",
  "ms": "452",
  "path": "0000.0000.0000.42c5",
  "result": "pong",
  "txid": "2970256056",
  "version": "7"
}


## This seems to be a node which is supposed to be connected but is not responding.
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4305", 3000, 1)'
{
  "ms": "3003",
  "path": "0000.0000.0000.4305",
  "result": "timeout",
  "txid": "1014318430",
  "version": "7"
}
## Try again for good measure
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4305", 3000, 1)'
{
  "ms": "3002",
  "path": "0000.0000.0000.4305",
  "result": "timeout",
  "txid": "2282909610",
  "version": "7"
}


user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.42c5", 3000, 1)'
{
  "data": "",
  "key": "r5tmqf72mjzht1grqm34l1ldrx9tdubyzw33ucng6bfqp1y0mux0.k",
  "ms": "181",
  "path": "0000.0000.0000.42c5",
  "result": "pong",
  "txid": "2432582962",
  "version": "7"
}
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4345", 3000, 1)'
{
  "data": "",
  "key": "fj9q4s6fg8mjdjfks8lc8bp7ly05qm11z54crlb7tz1pl01fg3r0.k",
  "ms": "329",
  "path": "0000.0000.0000.4345",
  "result": "pong",
  "txid": "1698617630",
  "version": "7"
}


## We have either reached the top of the list or there is an empty slot left by a node which
## disconnected, we can't know for sure so lets ping a few more nodes in order to check.
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4385", 3000, 1)'
{
  "data": "",
  "ms": "158",
  "path": "0000.0000.0000.4385",
  "result": "err_switch",
  "txid": "880013604",
  "version": "0"
}
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.43c5", 3000, 1)'
{
  "data": "",
  "ms": "444",
  "path": "0000.0000.0000.43c5",
  "result": "err_switch",
  "txid": "1175469204",
  "version": "0"
}
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4405", 3000, 1)'
{
  "data": "",
  "ms": "347",
  "path": "0000.0000.0000.4405",
  "result": "err_switch",
  "txid": "3258844093",
  "version": "0"
}
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4445", 3000, 1)'
{
  "data": "",
  "ms": "321",
  "path": "0000.0000.0000.4445",
  "result": "err_switch",
  "txid": "869243597",
  "version": "0"
}
user@toshitba:~/wrk/cjdns$ 







## Recall from above that we're 0408 aka 0017 (because we can be represented using the small encoding)
## ping selves
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.0175", 3000, 1)'{
  "data": "",
  "key": "b8xn6kv9279k7mjdmg08ut6yc4n3d2lp3s3juq39qz83z9bzxgz0.k",
  "ms": "619",
  "path": "0000.0000.0000.0175",
  "result": "pong",
  "txid": "1099734707",
  "version": "8"
}
## just to verify that it's working, we'll create a loop packet
## us->them->us->them and it works.
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.1575", 3000, 1)'
{
  "data": "",
  "key": "nx6k81p1nxw1b5ry8ub5u63hu0tlskp1t2fytcbrbf1709xh11g0.k",
  "ms": "1251",
  "path": "0000.0000.0000.1575",
  "result": "pong",
  "txid": "3109463617",
  "version": "8"
}
## We can make it loop more but the latency gets very big!
user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0001.7575.7575", 3000, 1)'
{
  "data": "",
  "key": "b8xn6kv9279k7mjdmg08ut6yc4n3d2lp3s3juq39qz83z9bzxgz0.k",
  "ms": "1900",
  "path": "0000.0001.7575.7575",
  "result": "pong",
  "txid": "2807636566",
  "version": "8"
}

## This only works because we and our peer are both using 3x5x8 encoding, if they were using
## something different, it would still be possible but more complex to craft paths.
## nodes describe their encoding schemes to one another so even the most complex encoding
## schemes are supported by cjdns which has to craft paths through the network much like
## we did here.
