switchfun.txt 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. ## Walking all peers manually on a node using the common 3x5x8 switch scheme.
  2. ## We're exclusively using the 8 form because it's easier to stick to one form
  3. ## The node is 0015 to us, therefor all paths end in 5.
  4. ## The first entry in the 8 form is 0400
  5. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/splice.js 0000.0000.0000.0400 0000.0000.0000.0015
  6. 0000.0000.0000.4005
  7. ## After splicing that with the path to our peer, we clearly see that everything
  8. ## will have a 5 added to the end.
  9. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4005", 3000, 1)'
  10. {
  11. "data": "",
  12. "key": "xp2f7m98uw24664ngwl47k8uyx59sblgp8qsbpk24sh10ppu9fz0.k",
  13. "ms": "382",
  14. "path": "0000.0000.0000.4005",
  15. "result": "pong",
  16. "txid": "824920922",
  17. "version": "8"
  18. }
  19. ## 0400 is analogus to 0013 (the first peer)
  20. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.0135", 3000, 1)'
  21. {
  22. "data": "",
  23. "key": "xp2f7m98uw24664ngwl47k8uyx59sblgp8qsbpk24sh10ppu9fz0.k",
  24. "ms": "407",
  25. "path": "0000.0000.0000.0135",
  26. "result": "pong",
  27. "txid": "1322201729",
  28. "version": "8"
  29. }
  30. ## Since the lowest 2 bits are reserved for specifying the encoding form (they're both 0)
  31. ## numbers count 400, 404, 408, 40c, 410, 414, 418, 41c, 420 ...
  32. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4045", 3000, 1)'
  33. {
  34. "data": "",
  35. "key": "2v6dt6f841hzhq2wsqwt263w2dswkt6fz82vcyxqptk88mtp8y50.k",
  36. "ms": "897",
  37. "path": "0000.0000.0000.4045",
  38. "result": "pong",
  39. "txid": "3621711461",
  40. "version": "8"
  41. }
  42. ## This is us, wow, we have slot 3, what luck!
  43. ## the shortest version of this route is 0017
  44. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4085", 3000, 1)'
  45. {
  46. "data": "",
  47. "key": "b8xn6kv9279k7mjdmg08ut6yc4n3d2lp3s3juq39qz83z9bzxgz0.k",
  48. "ms": "638",
  49. "path": "0000.0000.0000.4085",
  50. "result": "pong",
  51. "txid": "1345867629",
  52. "version": "8"
  53. }
  54. ## Oops! If you use a number which is not in the sequence you get a
  55. ## switch error (or perhaps it will be interpreted and end up at another node)
  56. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.40d5", 3000, 1)'
  57. {
  58. "data": "",
  59. "ms": "539",
  60. "path": "0000.0000.0000.40d5",
  61. "result": "err_switch",
  62. "txid": "3599763113",
  63. "version": "0"
  64. }
  65. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.40c5", 3000, 1)'
  66. {
  67. "data": "",
  68. "key": "lpcvt3u85q837u402dlu3rfg107x92j5xlzd77tftsjy88zx0yf0.k",
  69. "ms": "408",
  70. "path": "0000.0000.0000.40c5",
  71. "result": "pong",
  72. "txid": "259944377",
  73. "version": "7"
  74. }
  75. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4105", 3000, 1)'
  76. {
  77. "data": "",
  78. "key": "wb0hdx8vu6khpfj32qzhvykjk7gq8bc691czhx3yp7zn04bh5gy0.k",
  79. "ms": "363",
  80. "path": "0000.0000.0000.4105",
  81. "result": "pong",
  82. "txid": "1099356221",
  83. "version": "8"
  84. }
  85. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4145", 3000, 1)'
  86. {
  87. "data": "",
  88. "key": "6q09l149vz0bqtx51jy557juj39wxmupmfd52h9w5xsdnsns1qj0.k",
  89. "ms": "223",
  90. "path": "0000.0000.0000.4145",
  91. "result": "pong",
  92. "txid": "542004376",
  93. "version": "7"
  94. }
  95. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4185", 3000, 1)'
  96. {
  97. "data": "",
  98. "key": "1cgrz7hmc4wzg7pu284u5b77y2mdzt261tr0rj0qf7j2vsqf5150.k",
  99. "ms": "312",
  100. "path": "0000.0000.0000.4185",
  101. "result": "pong",
  102. "txid": "87763052",
  103. "version": "7"
  104. }
  105. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.41c5", 3000, 1)'
  106. {
  107. "data": "",
  108. "key": "w7xvbpmgwuwkv8x9wrpfmydtfxv6ydfmpktgc6tt8v8d3c9bn580.k",
  109. "ms": "394",
  110. "path": "0000.0000.0000.41c5",
  111. "result": "pong",
  112. "txid": "1682459805",
  113. "version": "8"
  114. }
  115. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4205", 3000, 1)'
  116. {
  117. "data": "",
  118. "key": "11sfkq2clbv4dgzgx8hm47p4ld9pwy82y7jluvjh91cyl1n7bwf0.k",
  119. "ms": "329",
  120. "path": "0000.0000.0000.4205",
  121. "result": "pong",
  122. "txid": "3712296271",
  123. "version": "7"
  124. }
  125. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4245", 3000, 1)'
  126. {
  127. "data": "",
  128. "key": "c94sls20x5shql6r4z4nvqlrs9pcppgj2h41m1bntzk60j5wrs40.k",
  129. "ms": "362",
  130. "path": "0000.0000.0000.4245",
  131. "result": "pong",
  132. "txid": "1883792007",
  133. "version": "7"
  134. }
  135. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4285", 3000, 1)'
  136. {
  137. "data": "",
  138. "key": "08pdl5mbcpx2b0uh6wj6wktq5v47kv9gpy40rnqr52t1ugctr430.k",
  139. "ms": "252",
  140. "path": "0000.0000.0000.4285",
  141. "result": "pong",
  142. "txid": "711411764",
  143. "version": "7"
  144. }
  145. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.42c5", 3000, 1)'
  146. {
  147. "data": "",
  148. "key": "r5tmqf72mjzht1grqm34l1ldrx9tdubyzw33ucng6bfqp1y0mux0.k",
  149. "ms": "452",
  150. "path": "0000.0000.0000.42c5",
  151. "result": "pong",
  152. "txid": "2970256056",
  153. "version": "7"
  154. }
  155. ## This seems to be a node which is supposed to be connected but is not responding.
  156. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4305", 3000, 1)'
  157. {
  158. "ms": "3003",
  159. "path": "0000.0000.0000.4305",
  160. "result": "timeout",
  161. "txid": "1014318430",
  162. "version": "7"
  163. }
  164. ## Try again for good measure
  165. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4305", 3000, 1)'
  166. {
  167. "ms": "3002",
  168. "path": "0000.0000.0000.4305",
  169. "result": "timeout",
  170. "txid": "2282909610",
  171. "version": "7"
  172. }
  173. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.42c5", 3000, 1)'
  174. {
  175. "data": "",
  176. "key": "r5tmqf72mjzht1grqm34l1ldrx9tdubyzw33ucng6bfqp1y0mux0.k",
  177. "ms": "181",
  178. "path": "0000.0000.0000.42c5",
  179. "result": "pong",
  180. "txid": "2432582962",
  181. "version": "7"
  182. }
  183. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4345", 3000, 1)'
  184. {
  185. "data": "",
  186. "key": "fj9q4s6fg8mjdjfks8lc8bp7ly05qm11z54crlb7tz1pl01fg3r0.k",
  187. "ms": "329",
  188. "path": "0000.0000.0000.4345",
  189. "result": "pong",
  190. "txid": "1698617630",
  191. "version": "7"
  192. }
  193. ## We have either reached the top of the list or there is an empty slot left by a node which
  194. ## disconnected, we can't know for sure so lets ping a few more nodes in order to check.
  195. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4385", 3000, 1)'
  196. {
  197. "data": "",
  198. "ms": "158",
  199. "path": "0000.0000.0000.4385",
  200. "result": "err_switch",
  201. "txid": "880013604",
  202. "version": "0"
  203. }
  204. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.43c5", 3000, 1)'
  205. {
  206. "data": "",
  207. "ms": "444",
  208. "path": "0000.0000.0000.43c5",
  209. "result": "err_switch",
  210. "txid": "1175469204",
  211. "version": "0"
  212. }
  213. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4405", 3000, 1)'
  214. {
  215. "data": "",
  216. "ms": "347",
  217. "path": "0000.0000.0000.4405",
  218. "result": "err_switch",
  219. "txid": "3258844093",
  220. "version": "0"
  221. }
  222. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.4445", 3000, 1)'
  223. {
  224. "data": "",
  225. "ms": "321",
  226. "path": "0000.0000.0000.4445",
  227. "result": "err_switch",
  228. "txid": "869243597",
  229. "version": "0"
  230. }
  231. user@toshitba:~/wrk/cjdns$
  232. ## Recall from above that we're 0408 aka 0017 (because we can be represented using the small encoding)
  233. ## ping selves
  234. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.0175", 3000, 1)'{
  235. "data": "",
  236. "key": "b8xn6kv9279k7mjdmg08ut6yc4n3d2lp3s3juq39qz83z9bzxgz0.k",
  237. "ms": "619",
  238. "path": "0000.0000.0000.0175",
  239. "result": "pong",
  240. "txid": "1099734707",
  241. "version": "8"
  242. }
  243. ## just to verify that it's working, we'll create a loop packet
  244. ## us->them->us->them and it works.
  245. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0000.0000.1575", 3000, 1)'
  246. {
  247. "data": "",
  248. "key": "nx6k81p1nxw1b5ry8ub5u63hu0tlskp1t2fytcbrbf1709xh11g0.k",
  249. "ms": "1251",
  250. "path": "0000.0000.0000.1575",
  251. "result": "pong",
  252. "txid": "3109463617",
  253. "version": "8"
  254. }
  255. ## We can make it loop more but the latency gets very big!
  256. user@toshitba:~/wrk/cjdns$ ./contrib/nodejs/tools/cexec.js 'SwitchPinger_ping("0000.0001.7575.7575", 3000, 1)'
  257. {
  258. "data": "",
  259. "key": "b8xn6kv9279k7mjdmg08ut6yc4n3d2lp3s3juq39qz83z9bzxgz0.k",
  260. "ms": "1900",
  261. "path": "0000.0001.7575.7575",
  262. "result": "pong",
  263. "txid": "2807636566",
  264. "version": "8"
  265. }
  266. ## This only works because we and our peer are both using 3x5x8 encoding, if they were using
  267. ## something different, it would still be possible but more complex to craft paths.
  268. ## nodes describe their encoding schemes to one another so even the most complex encoding
  269. ## schemes are supported by cjdns which has to craft paths through the network much like
  270. ## we did here.