libp2p 0.36.0 → 0.36.2-1473044

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (415) hide show
  1. package/LICENSE +3 -21
  2. package/README.md +13 -10
  3. package/dist/src/address-manager/index.d.ts +33 -52
  4. package/dist/src/address-manager/index.d.ts.map +1 -1
  5. package/dist/src/address-manager/index.js +81 -0
  6. package/dist/src/address-manager/index.js.map +1 -0
  7. package/dist/src/circuit/auto-relay.d.ts +24 -85
  8. package/dist/src/circuit/auto-relay.d.ts.map +1 -1
  9. package/dist/src/circuit/auto-relay.js +215 -0
  10. package/dist/src/circuit/auto-relay.js.map +1 -0
  11. package/dist/src/circuit/circuit/hop.d.ts +26 -53
  12. package/dist/src/circuit/circuit/hop.d.ts.map +1 -1
  13. package/dist/src/circuit/circuit/hop.js +138 -0
  14. package/dist/src/circuit/circuit/hop.js.map +1 -0
  15. package/dist/src/circuit/circuit/stop.d.ts +18 -10
  16. package/dist/src/circuit/circuit/stop.d.ts.map +1 -1
  17. package/dist/src/circuit/circuit/stop.js +49 -0
  18. package/dist/src/circuit/circuit/stop.js.map +1 -0
  19. package/dist/src/circuit/circuit/stream-handler.d.ts +19 -38
  20. package/dist/src/circuit/circuit/stream-handler.d.ts.map +1 -1
  21. package/dist/src/circuit/circuit/stream-handler.js +59 -0
  22. package/dist/src/circuit/circuit/stream-handler.js.map +1 -0
  23. package/dist/src/circuit/circuit/utils.d.ts +3 -6
  24. package/dist/src/circuit/circuit/utils.d.ts.map +1 -1
  25. package/dist/src/circuit/circuit/utils.js +43 -0
  26. package/dist/src/circuit/circuit/utils.js.map +1 -0
  27. package/dist/src/circuit/constants.d.ts +24 -6
  28. package/dist/src/circuit/constants.d.ts.map +1 -1
  29. package/dist/src/circuit/constants.js +26 -0
  30. package/dist/src/circuit/constants.js.map +1 -0
  31. package/dist/src/circuit/index.d.ts +41 -74
  32. package/dist/src/circuit/index.d.ts.map +1 -1
  33. package/dist/src/circuit/index.js +69 -0
  34. package/dist/src/circuit/index.js.map +1 -0
  35. package/dist/src/circuit/listener.d.ts +8 -3
  36. package/dist/src/circuit/listener.d.ts.map +1 -1
  37. package/dist/src/circuit/listener.js +54 -0
  38. package/dist/src/circuit/listener.js.map +1 -0
  39. package/dist/src/circuit/multicodec.d.ts +1 -1
  40. package/dist/src/circuit/multicodec.d.ts.map +1 -1
  41. package/dist/src/circuit/multicodec.js +2 -0
  42. package/dist/src/circuit/multicodec.js.map +1 -0
  43. package/dist/src/circuit/pb/index.d.ts +51 -0
  44. package/dist/src/circuit/pb/index.d.ts.map +1 -0
  45. package/dist/src/circuit/pb/index.js +72 -0
  46. package/dist/src/circuit/pb/index.js.map +1 -0
  47. package/dist/src/circuit/transport.d.ts +18 -78
  48. package/dist/src/circuit/transport.d.ts.map +1 -1
  49. package/dist/src/circuit/transport.js +190 -0
  50. package/dist/src/circuit/transport.js.map +1 -0
  51. package/dist/src/circuit/utils.d.ts +5 -2
  52. package/dist/src/circuit/utils.d.ts.map +1 -1
  53. package/dist/src/circuit/utils.js +11 -0
  54. package/dist/src/circuit/utils.js.map +1 -0
  55. package/dist/src/config.d.ts +3 -85
  56. package/dist/src/config.d.ts.map +1 -1
  57. package/dist/src/config.js +93 -0
  58. package/dist/src/config.js.map +1 -0
  59. package/dist/src/connection-manager/auto-dialler.d.ts +24 -41
  60. package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
  61. package/dist/src/connection-manager/auto-dialler.js +105 -0
  62. package/dist/src/connection-manager/auto-dialler.js.map +1 -0
  63. package/dist/src/connection-manager/index.d.ts +79 -144
  64. package/dist/src/connection-manager/index.d.ts.map +1 -1
  65. package/dist/src/connection-manager/index.js +295 -0
  66. package/dist/src/connection-manager/index.js.map +1 -0
  67. package/dist/src/connection-manager/latency-monitor.d.ts +72 -97
  68. package/dist/src/connection-manager/latency-monitor.d.ts.map +1 -1
  69. package/dist/src/connection-manager/latency-monitor.js +220 -0
  70. package/dist/src/connection-manager/latency-monitor.js.map +1 -0
  71. package/dist/src/connection-manager/visibility-change-emitter.d.ts +15 -16
  72. package/dist/src/connection-manager/visibility-change-emitter.d.ts.map +1 -1
  73. package/dist/src/connection-manager/visibility-change-emitter.js +118 -0
  74. package/dist/src/connection-manager/visibility-change-emitter.js.map +1 -0
  75. package/dist/src/constants.d.ts +22 -10
  76. package/dist/src/constants.d.ts.map +1 -1
  77. package/dist/src/constants.js +27 -0
  78. package/dist/src/constants.js.map +1 -0
  79. package/dist/src/content-routing/index.d.ts +26 -81
  80. package/dist/src/content-routing/index.d.ts.map +1 -1
  81. package/dist/src/content-routing/index.js +99 -0
  82. package/dist/src/content-routing/index.js.map +1 -0
  83. package/dist/src/content-routing/utils.d.ts +6 -49
  84. package/dist/src/content-routing/utils.d.ts.map +1 -1
  85. package/dist/src/content-routing/utils.js +42 -0
  86. package/dist/src/content-routing/utils.js.map +1 -0
  87. package/dist/src/dht/dht-content-routing.d.ts +10 -24
  88. package/dist/src/dht/dht-content-routing.d.ts.map +1 -1
  89. package/dist/src/dht/dht-content-routing.js +32 -0
  90. package/dist/src/dht/dht-content-routing.js.map +1 -0
  91. package/dist/src/dht/dht-peer-routing.d.ts +9 -24
  92. package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
  93. package/dist/src/dht/dht-peer-routing.js +26 -0
  94. package/dist/src/dht/dht-peer-routing.js.map +1 -0
  95. package/dist/src/dialer/auto-dialer.d.ts +14 -0
  96. package/dist/src/dialer/auto-dialer.d.ts.map +1 -0
  97. package/dist/src/dialer/auto-dialer.js +24 -0
  98. package/dist/src/dialer/auto-dialer.js.map +1 -0
  99. package/dist/src/dialer/dial-request.d.ts +18 -46
  100. package/dist/src/dialer/dial-request.d.ts.map +1 -1
  101. package/dist/src/dialer/dial-request.js +83 -0
  102. package/dist/src/dialer/dial-request.js.map +1 -0
  103. package/dist/src/dialer/index.d.ts +41 -148
  104. package/dist/src/dialer/index.d.ts.map +1 -1
  105. package/dist/src/dialer/index.js +280 -0
  106. package/dist/src/dialer/index.js.map +1 -0
  107. package/dist/src/errors.d.ts +68 -63
  108. package/dist/src/errors.d.ts.map +1 -1
  109. package/dist/src/errors.js +73 -0
  110. package/dist/src/errors.js.map +1 -0
  111. package/dist/src/fetch/constants.d.ts +1 -1
  112. package/dist/src/fetch/constants.d.ts.map +1 -1
  113. package/dist/src/fetch/constants.js +3 -0
  114. package/dist/src/fetch/constants.js.map +1 -0
  115. package/dist/src/fetch/index.d.ts +30 -49
  116. package/dist/src/fetch/index.d.ts.map +1 -1
  117. package/dist/src/fetch/index.js +129 -0
  118. package/dist/src/fetch/index.js.map +1 -0
  119. package/dist/src/fetch/pb/proto.d.ts +26 -0
  120. package/dist/src/fetch/pb/proto.d.ts.map +1 -0
  121. package/dist/src/fetch/pb/proto.js +44 -0
  122. package/dist/src/fetch/pb/proto.js.map +1 -0
  123. package/dist/src/get-peer.d.ts +4 -11
  124. package/dist/src/get-peer.d.ts.map +1 -1
  125. package/dist/src/get-peer.js +43 -0
  126. package/dist/src/get-peer.js.map +1 -0
  127. package/dist/src/identify/consts.d.ts +9 -9
  128. package/dist/src/identify/consts.d.ts.map +1 -1
  129. package/dist/src/identify/consts.js +11 -0
  130. package/dist/src/identify/consts.js.map +1 -0
  131. package/dist/src/identify/index.d.ts +42 -96
  132. package/dist/src/identify/index.d.ts.map +1 -1
  133. package/dist/src/identify/index.js +322 -0
  134. package/dist/src/identify/index.js.map +1 -0
  135. package/dist/src/identify/pb/message.d.ts +15 -0
  136. package/dist/src/identify/pb/message.d.ts.map +1 -0
  137. package/dist/src/identify/pb/message.js +24 -0
  138. package/dist/src/identify/pb/message.js.map +1 -0
  139. package/dist/src/index.d.ts +162 -581
  140. package/dist/src/index.d.ts.map +1 -1
  141. package/dist/src/index.js +9 -0
  142. package/dist/src/index.js.map +1 -0
  143. package/dist/src/insecure/index.d.ts +9 -0
  144. package/dist/src/insecure/index.d.ts.map +1 -0
  145. package/dist/src/insecure/index.js +81 -0
  146. package/dist/src/insecure/index.js.map +1 -0
  147. package/dist/src/insecure/pb/proto.d.ts +28 -0
  148. package/dist/src/insecure/pb/proto.d.ts.map +1 -0
  149. package/dist/src/insecure/pb/proto.js +46 -0
  150. package/dist/src/insecure/pb/proto.js.map +1 -0
  151. package/dist/src/keychain/cms.d.ts +6 -14
  152. package/dist/src/keychain/cms.d.ts.map +1 -1
  153. package/dist/src/keychain/cms.js +129 -0
  154. package/dist/src/keychain/cms.js.map +1 -0
  155. package/dist/src/keychain/index.d.ts +61 -81
  156. package/dist/src/keychain/index.d.ts.map +1 -1
  157. package/dist/src/keychain/index.js +493 -0
  158. package/dist/src/keychain/index.js.map +1 -0
  159. package/dist/src/keychain/util.d.ts +3 -6
  160. package/dist/src/keychain/util.d.ts.map +1 -1
  161. package/dist/src/keychain/util.js +79 -0
  162. package/dist/src/keychain/util.js.map +1 -0
  163. package/dist/src/libp2p.d.ts +78 -0
  164. package/dist/src/libp2p.d.ts.map +1 -0
  165. package/dist/src/libp2p.js +375 -0
  166. package/dist/src/libp2p.js.map +1 -0
  167. package/dist/src/metrics/index.d.ts +47 -104
  168. package/dist/src/metrics/index.d.ts.map +1 -1
  169. package/dist/src/metrics/index.js +231 -0
  170. package/dist/src/metrics/index.js.map +1 -0
  171. package/dist/src/metrics/moving-average.d.ts +14 -0
  172. package/dist/src/metrics/moving-average.d.ts.map +1 -0
  173. package/dist/src/metrics/moving-average.js +40 -0
  174. package/dist/src/metrics/moving-average.js.map +1 -0
  175. package/dist/src/metrics/stats.d.ts +41 -93
  176. package/dist/src/metrics/stats.d.ts.map +1 -1
  177. package/dist/src/metrics/stats.js +183 -0
  178. package/dist/src/metrics/stats.js.map +1 -0
  179. package/dist/src/nat-manager.d.ts +42 -99
  180. package/dist/src/nat-manager.d.ts.map +1 -1
  181. package/dist/src/nat-manager.js +114 -0
  182. package/dist/src/nat-manager.js.map +1 -0
  183. package/dist/src/peer-record-updater.d.ts +15 -0
  184. package/dist/src/peer-record-updater.d.ts.map +1 -0
  185. package/dist/src/peer-record-updater.js +44 -0
  186. package/dist/src/peer-record-updater.js.map +1 -0
  187. package/dist/src/peer-routing.d.ts +39 -84
  188. package/dist/src/peer-routing.d.ts.map +1 -1
  189. package/dist/src/peer-routing.js +108 -0
  190. package/dist/src/peer-routing.js.map +1 -0
  191. package/dist/src/ping/constants.d.ts +4 -4
  192. package/dist/src/ping/constants.d.ts.map +1 -1
  193. package/dist/src/ping/constants.js +5 -0
  194. package/dist/src/ping/constants.js.map +1 -0
  195. package/dist/src/ping/index.d.ts +26 -33
  196. package/dist/src/ping/index.d.ts.map +1 -1
  197. package/dist/src/ping/index.js +56 -0
  198. package/dist/src/ping/index.js.map +1 -0
  199. package/dist/src/pnet/crypto.d.ts +15 -5
  200. package/dist/src/pnet/crypto.d.ts.map +1 -1
  201. package/dist/src/pnet/crypto.js +60 -0
  202. package/dist/src/pnet/crypto.js.map +1 -0
  203. package/dist/src/pnet/errors.d.ts +5 -5
  204. package/dist/src/pnet/errors.d.ts.map +1 -1
  205. package/dist/src/pnet/errors.js +6 -0
  206. package/dist/src/pnet/errors.js.map +1 -0
  207. package/dist/src/pnet/index.d.ts +11 -20
  208. package/dist/src/pnet/index.d.ts.map +1 -1
  209. package/dist/src/pnet/index.js +66 -0
  210. package/dist/src/pnet/index.js.map +1 -0
  211. package/dist/src/pnet/key-generator.d.ts +3 -7
  212. package/dist/src/pnet/key-generator.d.ts.map +1 -1
  213. package/dist/src/pnet/key-generator.js +25 -0
  214. package/dist/src/pnet/key-generator.js.map +1 -0
  215. package/dist/src/registrar.d.ts +27 -65
  216. package/dist/src/registrar.d.ts.map +1 -1
  217. package/dist/src/registrar.js +159 -0
  218. package/dist/src/registrar.js.map +1 -0
  219. package/dist/src/transport-manager.d.ts +34 -82
  220. package/dist/src/transport-manager.d.ts.map +1 -1
  221. package/dist/src/transport-manager.js +223 -0
  222. package/dist/src/transport-manager.js.map +1 -0
  223. package/dist/src/upgrader.d.ts +49 -129
  224. package/dist/src/upgrader.d.ts.map +1 -1
  225. package/dist/src/upgrader.js +402 -0
  226. package/dist/src/upgrader.js.map +1 -0
  227. package/dist/src/version.d.ts +3 -0
  228. package/dist/src/version.d.ts.map +1 -0
  229. package/dist/src/version.js +3 -0
  230. package/dist/src/version.js.map +1 -0
  231. package/package.json +150 -197
  232. package/src/address-manager/index.ts +129 -0
  233. package/src/circuit/README.md +16 -11
  234. package/src/circuit/auto-relay.ts +284 -0
  235. package/src/circuit/circuit/hop.ts +211 -0
  236. package/src/circuit/circuit/stop.ts +78 -0
  237. package/src/circuit/circuit/stream-handler.ts +86 -0
  238. package/src/circuit/circuit/{utils.js → utils.ts} +9 -25
  239. package/src/circuit/constants.ts +31 -0
  240. package/src/circuit/index.ts +120 -0
  241. package/src/circuit/{listener.js → listener.ts} +21 -27
  242. package/src/circuit/multicodec.ts +2 -0
  243. package/src/circuit/{protocol → pb}/index.proto +1 -1
  244. package/src/circuit/pb/index.ts +88 -0
  245. package/src/circuit/transport.ts +216 -0
  246. package/src/circuit/utils.ts +12 -0
  247. package/src/config.ts +101 -0
  248. package/src/connection-manager/auto-dialler.ts +154 -0
  249. package/src/connection-manager/index.ts +422 -0
  250. package/src/connection-manager/latency-monitor.ts +319 -0
  251. package/src/connection-manager/{visibility-change-emitter.js → visibility-change-emitter.ts} +48 -38
  252. package/src/constants.ts +31 -0
  253. package/src/content-routing/index.ts +143 -0
  254. package/src/content-routing/utils.ts +54 -0
  255. package/src/dht/dht-content-routing.ts +43 -0
  256. package/src/dht/dht-peer-routing.ts +35 -0
  257. package/src/dialer/auto-dialer.ts +40 -0
  258. package/src/dialer/{dial-request.js → dial-request.ts} +60 -51
  259. package/src/dialer/index.ts +371 -0
  260. package/src/errors.ts +71 -0
  261. package/src/fetch/README.md +1 -1
  262. package/src/fetch/constants.ts +3 -0
  263. package/src/fetch/index.ts +167 -0
  264. package/src/fetch/{proto.proto → pb/proto.proto} +0 -0
  265. package/src/fetch/pb/proto.ts +58 -0
  266. package/src/get-peer.ts +57 -0
  267. package/src/identify/consts.ts +13 -0
  268. package/src/identify/index.ts +445 -0
  269. package/src/identify/{message.proto → pb/message.proto} +0 -0
  270. package/src/identify/pb/message.ts +36 -0
  271. package/src/index.ts +242 -0
  272. package/src/insecure/index.ts +101 -0
  273. package/src/insecure/{proto.proto → pb/proto.proto} +0 -0
  274. package/src/insecure/pb/proto.ts +61 -0
  275. package/src/keychain/{cms.js → cms.ts} +62 -58
  276. package/src/keychain/index.ts +588 -0
  277. package/src/keychain/{util.js → util.ts} +7 -17
  278. package/src/libp2p.ts +513 -0
  279. package/src/metrics/index.ts +310 -0
  280. package/src/metrics/moving-average.ts +53 -0
  281. package/src/metrics/stats.ts +238 -0
  282. package/src/nat-manager.ts +194 -0
  283. package/src/peer-record-updater.ts +55 -0
  284. package/src/peer-routing.ts +185 -0
  285. package/src/ping/README.md +1 -1
  286. package/src/ping/constants.ts +5 -0
  287. package/src/ping/index.ts +83 -0
  288. package/src/pnet/README.md +2 -2
  289. package/src/pnet/crypto.ts +67 -0
  290. package/src/pnet/errors.ts +5 -0
  291. package/src/pnet/index.ts +95 -0
  292. package/src/pnet/key-generator.ts +28 -0
  293. package/src/registrar.ts +205 -0
  294. package/src/transport-manager.ts +279 -0
  295. package/src/upgrader.ts +499 -0
  296. package/src/version.ts +3 -0
  297. package/dist/index.min.js +0 -55
  298. package/dist/src/circuit/protocol/index.d.ts +0 -173
  299. package/dist/src/fetch/proto.d.ts +0 -134
  300. package/dist/src/identify/message.d.ts +0 -95
  301. package/dist/src/insecure/plaintext.d.ts +0 -12
  302. package/dist/src/insecure/plaintext.d.ts.map +0 -1
  303. package/dist/src/insecure/proto.d.ts +0 -128
  304. package/dist/src/metrics/old-peers.d.ts +0 -3
  305. package/dist/src/metrics/old-peers.d.ts.map +0 -1
  306. package/dist/src/metrics/tracked-map.d.ts +0 -8
  307. package/dist/src/metrics/tracked-map.d.ts.map +0 -1
  308. package/dist/src/peer-store/address-book.d.ts +0 -67
  309. package/dist/src/peer-store/address-book.d.ts.map +0 -1
  310. package/dist/src/peer-store/index.d.ts +0 -58
  311. package/dist/src/peer-store/index.d.ts.map +0 -1
  312. package/dist/src/peer-store/key-book.d.ts +0 -40
  313. package/dist/src/peer-store/key-book.d.ts.map +0 -1
  314. package/dist/src/peer-store/metadata-book.d.ts +0 -58
  315. package/dist/src/peer-store/metadata-book.d.ts.map +0 -1
  316. package/dist/src/peer-store/pb/peer.d.ts +0 -222
  317. package/dist/src/peer-store/proto-book.d.ts +0 -43
  318. package/dist/src/peer-store/proto-book.d.ts.map +0 -1
  319. package/dist/src/peer-store/store.d.ts +0 -73
  320. package/dist/src/peer-store/store.d.ts.map +0 -1
  321. package/dist/src/peer-store/types.d.ts +0 -202
  322. package/dist/src/peer-store/types.d.ts.map +0 -1
  323. package/dist/src/ping/util.d.ts +0 -5
  324. package/dist/src/ping/util.d.ts.map +0 -1
  325. package/dist/src/pubsub-adapter.d.ts +0 -22
  326. package/dist/src/pubsub-adapter.d.ts.map +0 -1
  327. package/dist/src/record/envelope/envelope.d.ts +0 -77
  328. package/dist/src/record/envelope/index.d.ts +0 -80
  329. package/dist/src/record/envelope/index.d.ts.map +0 -1
  330. package/dist/src/record/peer-record/consts.d.ts +0 -4
  331. package/dist/src/record/peer-record/consts.d.ts.map +0 -1
  332. package/dist/src/record/peer-record/index.d.ts +0 -60
  333. package/dist/src/record/peer-record/index.d.ts.map +0 -1
  334. package/dist/src/record/peer-record/peer-record.d.ts +0 -133
  335. package/dist/src/record/utils.d.ts +0 -12
  336. package/dist/src/record/utils.d.ts.map +0 -1
  337. package/dist/src/types.d.ts +0 -90
  338. package/dist/src/types.d.ts.map +0 -1
  339. package/src/address-manager/index.js +0 -96
  340. package/src/circuit/auto-relay.js +0 -302
  341. package/src/circuit/circuit/hop.js +0 -205
  342. package/src/circuit/circuit/stop.js +0 -81
  343. package/src/circuit/circuit/stream-handler.js +0 -94
  344. package/src/circuit/constants.js +0 -12
  345. package/src/circuit/index.js +0 -102
  346. package/src/circuit/multicodec.js +0 -5
  347. package/src/circuit/protocol/index.d.ts +0 -173
  348. package/src/circuit/protocol/index.js +0 -530
  349. package/src/circuit/transport.js +0 -229
  350. package/src/circuit/utils.js +0 -17
  351. package/src/config.js +0 -114
  352. package/src/connection-manager/auto-dialler.js +0 -132
  353. package/src/connection-manager/index.js +0 -363
  354. package/src/connection-manager/latency-monitor.js +0 -264
  355. package/src/constants.js +0 -18
  356. package/src/content-routing/index.js +0 -163
  357. package/src/content-routing/utils.js +0 -89
  358. package/src/dht/dht-content-routing.js +0 -44
  359. package/src/dht/dht-peer-routing.js +0 -51
  360. package/src/dialer/index.js +0 -376
  361. package/src/errors.js +0 -66
  362. package/src/fetch/constants.js +0 -6
  363. package/src/fetch/index.js +0 -159
  364. package/src/fetch/proto.d.ts +0 -134
  365. package/src/fetch/proto.js +0 -333
  366. package/src/get-peer.js +0 -49
  367. package/src/identify/consts.js +0 -15
  368. package/src/identify/index.js +0 -384
  369. package/src/identify/message.d.ts +0 -95
  370. package/src/identify/message.js +0 -328
  371. package/src/index.js +0 -811
  372. package/src/insecure/plaintext.js +0 -95
  373. package/src/insecure/proto.d.ts +0 -128
  374. package/src/insecure/proto.js +0 -371
  375. package/src/keychain/index.js +0 -561
  376. package/src/metrics/index.js +0 -290
  377. package/src/metrics/old-peers.js +0 -16
  378. package/src/metrics/stats.js +0 -270
  379. package/src/metrics/tracked-map.js +0 -94
  380. package/src/nat-manager.js +0 -197
  381. package/src/peer-routing.js +0 -176
  382. package/src/peer-store/README.md +0 -145
  383. package/src/peer-store/address-book.js +0 -382
  384. package/src/peer-store/index.js +0 -121
  385. package/src/peer-store/key-book.js +0 -141
  386. package/src/peer-store/metadata-book.js +0 -250
  387. package/src/peer-store/pb/peer.d.ts +0 -222
  388. package/src/peer-store/pb/peer.js +0 -643
  389. package/src/peer-store/pb/peer.proto +0 -31
  390. package/src/peer-store/proto-book.js +0 -237
  391. package/src/peer-store/store.js +0 -263
  392. package/src/peer-store/types.ts +0 -245
  393. package/src/ping/constants.js +0 -8
  394. package/src/ping/index.js +0 -85
  395. package/src/ping/util.js +0 -18
  396. package/src/pnet/crypto.js +0 -84
  397. package/src/pnet/errors.js +0 -7
  398. package/src/pnet/index.js +0 -86
  399. package/src/pnet/key-generator.js +0 -33
  400. package/src/pubsub-adapter.js +0 -61
  401. package/src/record/README.md +0 -130
  402. package/src/record/envelope/envelope.d.ts +0 -77
  403. package/src/record/envelope/envelope.js +0 -243
  404. package/src/record/envelope/envelope.proto +0 -19
  405. package/src/record/envelope/index.js +0 -183
  406. package/src/record/peer-record/consts.js +0 -14
  407. package/src/record/peer-record/index.js +0 -113
  408. package/src/record/peer-record/peer-record.d.ts +0 -133
  409. package/src/record/peer-record/peer-record.js +0 -367
  410. package/src/record/peer-record/peer-record.proto +0 -18
  411. package/src/record/utils.js +0 -25
  412. package/src/registrar.js +0 -127
  413. package/src/transport-manager.js +0 -269
  414. package/src/types.ts +0 -98
  415. package/src/upgrader.js +0 -492
@@ -0,0 +1,6 @@
1
+ export const INVALID_PEER = 'Not a valid peer connection';
2
+ export const INVALID_PSK = 'Your private shared key is invalid';
3
+ export const NO_LOCAL_ID = 'No local private key provided';
4
+ export const NO_HANDSHAKE_CONNECTION = 'No connection for the handshake provided';
5
+ export const STREAM_ENDED = 'Stream ended prematurely';
6
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/pnet/errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG,6BAA6B,CAAA;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG,oCAAoC,CAAA;AAC/D,MAAM,CAAC,MAAM,WAAW,GAAG,+BAA+B,CAAA;AAC1D,MAAM,CAAC,MAAM,uBAAuB,GAAG,0CAA0C,CAAA;AACjF,MAAM,CAAC,MAAM,YAAY,GAAG,0BAA0B,CAAA"}
@@ -1,32 +1,23 @@
1
- export = Protector;
2
- /**
3
- * @typedef {import('libp2p-interfaces/src/transport/types').MultiaddrConnection} MultiaddrConnection
4
- */
5
- declare class Protector {
1
+ import type { MultiaddrConnection } from '@libp2p/interfaces/transport';
2
+ import type { ConnectionProtector } from '@libp2p/interfaces/connection';
3
+ export interface ProtectorInit {
4
+ enabled?: boolean;
5
+ psk: Uint8Array;
6
+ }
7
+ export declare class PreSharedKeyConnectionProtector implements ConnectionProtector {
8
+ tag: string;
9
+ private readonly psk;
10
+ private readonly enabled;
6
11
  /**
7
12
  * Takes a Private Shared Key (psk) and provides a `protect` method
8
13
  * for wrapping existing connections in a private encryption stream.
9
- *
10
- * @param {Uint8Array} keyBuffer - The private shared key buffer
11
- * @class
12
14
  */
13
- constructor(keyBuffer: Uint8Array);
14
- psk: Uint8Array;
15
- tag: string | undefined;
15
+ constructor(init: ProtectorInit);
16
16
  /**
17
17
  * Takes a given Connection and creates a private encryption stream
18
18
  * between its two peers from the PSK the Protector instance was
19
19
  * created with.
20
- *
21
- * @param {MultiaddrConnection} connection - The connection to protect
22
- * @returns {Promise<MultiaddrConnection>} A protected duplex iterable
23
20
  */
24
21
  protect(connection: MultiaddrConnection): Promise<MultiaddrConnection>;
25
22
  }
26
- declare namespace Protector {
27
- export { Errors as errors, generate, MultiaddrConnection };
28
- }
29
- type MultiaddrConnection = import('libp2p-interfaces/src/transport/types').MultiaddrConnection;
30
- import Errors = require("./errors");
31
- declare var generate: typeof import("./key-generator");
32
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pnet/index.js"],"names":[],"mappings":";AAwBA;;GAEG;AAEH;IACE;;;;;;OAMG;IACH,uBAHW,UAAU,EAOpB;IAFC,gBAAyB;IACzB,wBAAyB;IAG3B;;;;;;;OAOG;IACH,oBAHW,mBAAmB,GACjB,QAAQ,mBAAmB,CAAC,CAgCxC;CACF;;;;2BAxDY,OAAO,uCAAuC,EAAE,mBAAmB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pnet/index.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAIxE,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE,UAAU,CAAA;CAChB;AAED,qBAAa,+BAAgC,YAAW,mBAAmB;IAClE,GAAG,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAY;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC;;;OAGG;gBACU,IAAI,EAAE,aAAa;IAahC;;;;OAIG;IACG,OAAO,CAAE,UAAU,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CA2C9E"}
@@ -0,0 +1,66 @@
1
+ import { logger } from '@libp2p/logger';
2
+ import { pipe } from 'it-pipe';
3
+ import errCode from 'err-code';
4
+ import { duplexPair } from 'it-pair/duplex';
5
+ import { randomBytes } from '@libp2p/crypto';
6
+ import * as Errors from './errors.js';
7
+ import { codes } from '../errors.js';
8
+ import { createBoxStream, createUnboxStream, decodeV1PSK } from './crypto.js';
9
+ import { handshake } from 'it-handshake';
10
+ import { NONCE_LENGTH } from './key-generator.js';
11
+ const log = logger('libp2p:pnet');
12
+ export class PreSharedKeyConnectionProtector {
13
+ /**
14
+ * Takes a Private Shared Key (psk) and provides a `protect` method
15
+ * for wrapping existing connections in a private encryption stream.
16
+ */
17
+ constructor(init) {
18
+ this.enabled = init.enabled !== false;
19
+ if (this.enabled) {
20
+ const decodedPSK = decodeV1PSK(init.psk);
21
+ this.psk = decodedPSK.psk;
22
+ this.tag = decodedPSK.tag ?? '';
23
+ }
24
+ else {
25
+ this.psk = new Uint8Array();
26
+ this.tag = '';
27
+ }
28
+ }
29
+ /**
30
+ * Takes a given Connection and creates a private encryption stream
31
+ * between its two peers from the PSK the Protector instance was
32
+ * created with.
33
+ */
34
+ async protect(connection) {
35
+ if (!this.enabled) {
36
+ return connection;
37
+ }
38
+ if (connection == null) {
39
+ throw errCode(new Error(Errors.NO_HANDSHAKE_CONNECTION), codes.ERR_INVALID_PARAMETERS);
40
+ }
41
+ // Exchange nonces
42
+ log('protecting the connection');
43
+ const localNonce = randomBytes(NONCE_LENGTH);
44
+ const shake = handshake(connection);
45
+ shake.write(localNonce);
46
+ const result = await shake.reader.next(NONCE_LENGTH);
47
+ if (result.value == null) {
48
+ throw errCode(new Error(Errors.STREAM_ENDED), codes.ERR_INVALID_PARAMETERS);
49
+ }
50
+ const remoteNonce = result.value.slice();
51
+ shake.rest();
52
+ // Create the boxing/unboxing pipe
53
+ log('exchanged nonces');
54
+ const [internal, external] = duplexPair();
55
+ pipe(external,
56
+ // Encrypt all outbound traffic
57
+ createBoxStream(localNonce, this.psk), shake.stream,
58
+ // Decrypt all inbound traffic
59
+ createUnboxStream(remoteNonce, this.psk), external).catch(log.error);
60
+ return {
61
+ ...connection,
62
+ ...internal
63
+ };
64
+ }
65
+ }
66
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pnet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,WAAW,EACZ,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,SAAS,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,OAAO,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAA;SAC5E;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;QACxC,KAAK,CAAC,IAAI,EAAE,CAAA;QAEZ,kCAAkC;QAClC,GAAG,CAAC,kBAAkB,CAAC,CAAA;QACvB,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,UAAU,EAAc,CAAA;QACrD,IAAI,CACF,QAAQ;QACR,+BAA+B;QAC/B,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,EACrC,KAAK,CAAC,MAAM;QACZ,8BAA8B;QAC9B,iBAAiB,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,EACxC,QAAQ,CACT,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAElB,OAAO;YACL,GAAG,UAAU;YACb,GAAG,QAAQ;SACZ,CAAA;IACH,CAAC;CACF"}
@@ -1,14 +1,10 @@
1
- export = generate;
2
1
  /**
3
2
  * Generates a PSK that can be used in a libp2p-pnet private network
4
3
  *
5
4
  * @param {Uint8Array} bytes - An object to write the psk into
6
5
  * @returns {void}
7
6
  */
8
- declare function generate(bytes: Uint8Array): void;
9
- declare namespace generate {
10
- export { NONCE_LENGTH, KEY_LENGTH };
11
- }
12
- declare var NONCE_LENGTH: number;
13
- declare const KEY_LENGTH: 32;
7
+ export declare function generate(bytes: Uint8Array): void;
8
+ export declare const NONCE_LENGTH = 24;
9
+ export declare const KEY_LENGTH = 32;
14
10
  //# sourceMappingURL=key-generator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"key-generator.d.ts","sourceRoot":"","sources":["../../../src/pnet/key-generator.js"],"names":[],"mappings":";AAOA;;;;;GAKG;AACH,iCAHW,UAAU,GACR,IAAI,CAOhB;;;;;AAfD,6BAAqB"}
1
+ {"version":3,"file":"key-generator.d.ts","sourceRoot":"","sources":["../../../src/pnet/key-generator.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAE,KAAK,EAAE,UAAU,QAK1C;AAED,eAAO,MAAM,YAAY,KAAK,CAAA;AAC9B,eAAO,MAAM,UAAU,KAAK,CAAA"}
@@ -0,0 +1,25 @@
1
+ import { randomBytes } from '@libp2p/crypto';
2
+ import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
3
+ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
4
+ /**
5
+ * Generates a PSK that can be used in a libp2p-pnet private network
6
+ *
7
+ * @param {Uint8Array} bytes - An object to write the psk into
8
+ * @returns {void}
9
+ */
10
+ export function generate(bytes) {
11
+ const psk = uint8ArrayToString(randomBytes(KEY_LENGTH), 'base16');
12
+ const key = uint8ArrayFromString('/key/swarm/psk/1.0.0/\n/base16/\n' + psk);
13
+ bytes.set(key);
14
+ }
15
+ export const NONCE_LENGTH = 24;
16
+ export const KEY_LENGTH = 32;
17
+ try {
18
+ if (require.main === module) {
19
+ // @ts-expect-error
20
+ generate(process.stdout);
21
+ }
22
+ }
23
+ catch (error) {
24
+ }
25
+ //# sourceMappingURL=key-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"key-generator.js","sourceRoot":"","sources":["../../../src/pnet/key-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAE5E;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAE,KAAiB;IACzC,MAAM,GAAG,GAAG,kBAAkB,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAA;IACjE,MAAM,GAAG,GAAG,oBAAoB,CAAC,mCAAmC,GAAG,GAAG,CAAC,CAAA;IAE3E,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAA;AAC9B,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAA;AAE5B,IAAI;IACF,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;QAC3B,mBAAmB;QACnB,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;KACzB;CACF;AAAC,OAAO,KAAU,EAAE;CAEpB"}
@@ -1,82 +1,44 @@
1
- export = Registrar;
2
- /**
3
- * @typedef {import('peer-id')} PeerId
4
- * @typedef {import('./peer-store/types').PeerStore} PeerStore
5
- * @typedef {import('./connection-manager')} ConnectionManager
6
- * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
7
- * @typedef {import('./').HandlerProps} HandlerProps
8
- */
9
- /**
10
- *
11
- */
1
+ import { Topology } from '@libp2p/interfaces/topology';
2
+ import type { Registrar, StreamHandler } from '@libp2p/interfaces/registrar';
3
+ import type { PeerProtocolsChangeData } from '@libp2p/interfaces/peer-store';
4
+ import type { Connection } from '@libp2p/interfaces/connection';
5
+ import type { Components } from '@libp2p/interfaces/components';
12
6
  /**
13
7
  * Responsible for notifying registered protocols of events in the network.
14
8
  */
15
- declare class Registrar {
9
+ export declare class DefaultRegistrar implements Registrar {
10
+ private readonly topologies;
11
+ private readonly handlers;
12
+ private readonly components;
13
+ constructor(components: Components);
14
+ getProtocols(): string[];
15
+ getHandler(protocol: string): StreamHandler;
16
+ getTopologies(protocol: string): Topology[];
16
17
  /**
17
- * @param {Object} props
18
- * @param {PeerStore} props.peerStore
19
- * @param {ConnectionManager} props.connectionManager
20
- * @class
18
+ * Registers the `handler` for each protocol
21
19
  */
22
- constructor({ peerStore, connectionManager }: {
23
- peerStore: PeerStore;
24
- connectionManager: ConnectionManager;
25
- });
26
- peerStore: import("./peer-store/types").PeerStore;
27
- connectionManager: import("./connection-manager");
20
+ handle(protocols: string | string[], handler: StreamHandler): Promise<void>;
28
21
  /**
29
- * Map of topologies
30
- *
31
- * @type {Map<string, Topology>}
32
- */
33
- topologies: Map<string, Topology>;
34
- /** @type {(protocols: string[]|string, handler: (props: HandlerProps) => void) => void} */
35
- _handle: (protocols: string[] | string, handler: (props: HandlerProps) => void) => void;
36
- /**
37
- * Remove a disconnected peer from the record
38
- *
39
- * @param {Connection} connection
40
- * @returns {void}
22
+ * Removes the handler for each protocol. The protocol
23
+ * will no longer be supported on streams.
41
24
  */
42
- _onDisconnect(connection: Connection): void;
25
+ unhandle(protocols: string | string[]): Promise<void>;
43
26
  /**
44
- * @param {(protocols: string[]|string, handler: (props: HandlerProps) => void) => void} handle
45
- */
46
- set handle(arg: (protocols: string[] | string, handler: (props: HandlerProps) => void) => void);
47
- /**
48
- * @returns {(protocols: string[]|string, handler: (props: HandlerProps) => void) => void}
27
+ * Register handlers for a set of multicodecs given
49
28
  */
50
- get handle(): (protocols: string[] | string, handler: (props: HandlerProps) => void) => void;
29
+ register(protocols: string | string[], topology: Topology): Promise<string>;
51
30
  /**
52
- * Get a connection with a peer.
53
- *
54
- * @param {PeerId} peerId
55
- * @returns {Connection | null}
31
+ * Unregister topology
56
32
  */
57
- getConnection(peerId: PeerId): Connection | null;
33
+ unregister(id: string): void;
58
34
  /**
59
- * Register handlers for a set of multicodecs given
60
- *
61
- * @param {Topology} topology - protocol topology
62
- * @returns {Promise<string>} registrar identifier
35
+ * Remove a disconnected peer from the record
63
36
  */
64
- register(topology: Topology): Promise<string>;
37
+ _onDisconnect(evt: CustomEvent<Connection>): void;
38
+ _onConnect(evt: CustomEvent<Connection>): void;
65
39
  /**
66
- * Unregister topology.
67
- *
68
- * @param {string} id - registrar identifier
69
- * @returns {boolean} unregistered successfully
40
+ * Check if a new peer support the multicodecs for this topology
70
41
  */
71
- unregister(id: string): boolean;
72
- }
73
- declare namespace Registrar {
74
- export { PeerId, PeerStore, ConnectionManager, Connection, HandlerProps };
42
+ _onProtocolChange(evt: CustomEvent<PeerProtocolsChangeData>): void;
75
43
  }
76
- import Topology = require("libp2p-interfaces/src/topology");
77
- type Connection = import("libp2p-interfaces/src/connection/connection");
78
- type PeerId = import('peer-id');
79
- type PeerStore = import('./peer-store/types').PeerStore;
80
- type ConnectionManager = import('./connection-manager');
81
- type HandlerProps = import('./').HandlerProps;
82
44
  //# sourceMappingURL=registrar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.js"],"names":[],"mappings":";AAaA;;;;;;GAMG;AAEH;;GAEG;AAEH;;GAEG;AACH;IACE;;;;;OAKG;IACH;QAJ4B,SAAS,EAA1B,SAAS;QACgB,iBAAiB,EAA1C,iBAAiB;OAsB3B;IAjBC,kDAA0B;IAE1B,kDAA0C;IAE1C;;;;OAIG;IACH,YAFU,IAAI,MAAM,EAAE,QAAQ,CAAC,CAEJ;IAE3B,2FAA2F;IAE3F,qBAFuB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,CAE/D;IA+D1B;;;;;OAKG;IACH,0BAHW,UAAU,GACR,IAAI,CAMhB;IA5DD;;OAEG;IACH,4BATyB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,EAWxF;IAZD;;OAEG;IACH,0BAFyB,MAAM,EAAE,GAAC,MAAM,mBAAmB,YAAY,KAAK,IAAI,KAAK,IAAI,CAIxF;IASD;;;;;OAKG;IACH,sBAHW,MAAM,GACJ,UAAU,GAAG,IAAI,CAI7B;IAED;;;;;OAKG;IACH,mBAHW,QAAQ,GACN,QAAQ,MAAM,CAAC,CAiB3B;IAED;;;;;OAKG;IACH,eAHW,MAAM,GACJ,OAAO,CAInB;CAaF;;;;;;cA9GY,OAAO,SAAS,CAAC;iBACjB,OAAO,oBAAoB,EAAE,SAAS;yBACtC,OAAO,sBAAsB,CAAC;oBAE9B,OAAO,IAAI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uB,CAAC;CAwB7D"}
@@ -0,0 +1,159 @@
1
+ import { logger } from '@libp2p/logger';
2
+ import errCode from 'err-code';
3
+ import { codes } from './errors.js';
4
+ import { isTopology } from '@libp2p/interfaces/topology';
5
+ const log = logger('libp2p:registrar');
6
+ function supportsProtocol(peerProtocols, topologyProtocols) {
7
+ for (const peerProtocol of peerProtocols) {
8
+ if (topologyProtocols.includes(peerProtocol)) {
9
+ return true;
10
+ }
11
+ }
12
+ return false;
13
+ }
14
+ /**
15
+ * Responsible for notifying registered protocols of events in the network.
16
+ */
17
+ export class DefaultRegistrar {
18
+ constructor(components) {
19
+ this.topologies = new Map();
20
+ this.handlers = new Map();
21
+ this.components = components;
22
+ this._onDisconnect = this._onDisconnect.bind(this);
23
+ this._onConnect = this._onConnect.bind(this);
24
+ this._onProtocolChange = this._onProtocolChange.bind(this);
25
+ this.components.getConnectionManager().addEventListener('peer:disconnect', this._onDisconnect);
26
+ this.components.getConnectionManager().addEventListener('peer:connect', this._onConnect);
27
+ this.components.getPeerStore().addEventListener('change:protocols', this._onProtocolChange);
28
+ }
29
+ getProtocols() {
30
+ const protocols = new Set();
31
+ for (const topology of this.topologies.values()) {
32
+ topology.protocols.forEach(protocol => protocols.add(protocol));
33
+ }
34
+ for (const protocol of this.handlers.keys()) {
35
+ protocols.add(protocol);
36
+ }
37
+ return Array.from(protocols).sort();
38
+ }
39
+ getHandler(protocol) {
40
+ const handler = this.handlers.get(protocol);
41
+ if (handler == null) {
42
+ throw new Error(`No handler registered for protocol ${protocol}`);
43
+ }
44
+ return handler;
45
+ }
46
+ getTopologies(protocol) {
47
+ const output = [];
48
+ for (const { topology, protocols } of this.topologies.values()) {
49
+ if (protocols.includes(protocol)) {
50
+ output.push(topology);
51
+ }
52
+ }
53
+ return output;
54
+ }
55
+ /**
56
+ * Registers the `handler` for each protocol
57
+ */
58
+ async handle(protocols, handler) {
59
+ const protocolList = Array.isArray(protocols) ? protocols : [protocols];
60
+ for (const protocol of protocolList) {
61
+ if (this.handlers.has(protocol)) {
62
+ throw errCode(new Error(`Handler already registered for protocol ${protocol}`), codes.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED);
63
+ }
64
+ this.handlers.set(protocol, handler);
65
+ }
66
+ // Add new protocols to self protocols in the Protobook
67
+ await this.components.getPeerStore().protoBook.add(this.components.getPeerId(), protocolList);
68
+ }
69
+ /**
70
+ * Removes the handler for each protocol. The protocol
71
+ * will no longer be supported on streams.
72
+ */
73
+ async unhandle(protocols) {
74
+ const protocolList = Array.isArray(protocols) ? protocols : [protocols];
75
+ protocolList.forEach(protocol => {
76
+ this.handlers.delete(protocol);
77
+ });
78
+ // Remove protocols from self protocols in the Protobook
79
+ await this.components.getPeerStore().protoBook.remove(this.components.getPeerId(), protocolList);
80
+ }
81
+ /**
82
+ * Register handlers for a set of multicodecs given
83
+ */
84
+ async register(protocols, topology) {
85
+ if (!isTopology(topology)) {
86
+ log.error('topology must be an instance of interfaces/topology');
87
+ throw errCode(new Error('topology must be an instance of interfaces/topology'), codes.ERR_INVALID_PARAMETERS);
88
+ }
89
+ // Create topology
90
+ const id = `${(Math.random() * 1e9).toString(36)}${Date.now()}`;
91
+ this.topologies.set(id, {
92
+ topology,
93
+ protocols: Array.isArray(protocols) ? protocols : [protocols]
94
+ });
95
+ // Set registrar
96
+ await topology.setRegistrar(this);
97
+ return id;
98
+ }
99
+ /**
100
+ * Unregister topology
101
+ */
102
+ unregister(id) {
103
+ this.topologies.delete(id);
104
+ }
105
+ /**
106
+ * Remove a disconnected peer from the record
107
+ */
108
+ _onDisconnect(evt) {
109
+ const connection = evt.detail;
110
+ void this.components.getPeerStore().protoBook.get(connection.remotePeer)
111
+ .then(peerProtocols => {
112
+ for (const { topology, protocols } of this.topologies.values()) {
113
+ if (supportsProtocol(peerProtocols, protocols)) {
114
+ topology.onDisconnect(connection.remotePeer);
115
+ }
116
+ }
117
+ })
118
+ .catch(err => {
119
+ log.error(err);
120
+ });
121
+ }
122
+ _onConnect(evt) {
123
+ const connection = evt.detail;
124
+ void this.components.getPeerStore().protoBook.get(connection.remotePeer)
125
+ .then(peerProtocols => {
126
+ for (const { topology, protocols } of this.topologies.values()) {
127
+ if (supportsProtocol(peerProtocols, protocols)) {
128
+ topology.onConnect(connection.remotePeer, connection);
129
+ }
130
+ }
131
+ })
132
+ .catch(err => {
133
+ log.error(err);
134
+ });
135
+ }
136
+ /**
137
+ * Check if a new peer support the multicodecs for this topology
138
+ */
139
+ _onProtocolChange(evt) {
140
+ const { peerId, protocols, oldProtocols } = evt.detail;
141
+ const removed = oldProtocols.filter(protocol => !protocols.includes(protocol));
142
+ const added = protocols.filter(protocol => !oldProtocols.includes(protocol));
143
+ for (const { topology, protocols } of this.topologies.values()) {
144
+ if (supportsProtocol(removed, protocols)) {
145
+ topology.onDisconnect(peerId);
146
+ }
147
+ }
148
+ for (const { topology, protocols } of this.topologies.values()) {
149
+ if (supportsProtocol(added, protocols)) {
150
+ const connection = this.components.getConnectionManager().getConnection(peerId);
151
+ if (connection == null) {
152
+ continue;
153
+ }
154
+ topology.onConnect(peerId, connection);
155
+ }
156
+ }
157
+ }
158
+ }
159
+ //# sourceMappingURL=registrar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registrar.js","sourceRoot":"","sources":["../../src/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,UAAU,EAAY,MAAM,6BAA6B,CAAA;AAMlE,MAAM,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AAEtC,SAAS,gBAAgB,CAAE,aAAuB,EAAE,iBAA2B;IAC7E,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE;QACxC,IAAI,iBAAiB,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;YAC5C,OAAO,IAAI,CAAA;SAC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-interfaces/src/connection').Connection} Connection
5
- * @typedef {import('libp2p-interfaces/src/transport/types').TransportFactory<any, any>} TransportFactory
6
- * @typedef {import('libp2p-interfaces/src/transport/types').Transport<any, any>} Transport
7
- *
8
- * @typedef {Object} TransportManagerProperties
9
- * @property {import('./')} libp2p
10
- * @property {import('./upgrader')} upgrader
11
- *
12
- * @typedef {Object} TransportManagerOptions
13
- * @property {number} [faultTolerance = FAULT_TOLERANCE.FATAL_ALL] - Address listen error tolerance.
14
- */
15
- declare class TransportManager {
16
- /**
17
- * @class
18
- * @param {TransportManagerProperties & TransportManagerOptions} options
19
- */
20
- constructor({ libp2p, upgrader, faultTolerance }: TransportManagerProperties & TransportManagerOptions);
21
- libp2p: import("./");
22
- upgrader: import("./upgrader");
23
- /** @type {Map<string, Transport>} */
24
- _transports: Map<string, import("libp2p-interfaces/src/transport/types").Transport<any, any>>;
25
- _listeners: Map<any, any>;
26
- _listenerOptions: Map<any, any>;
27
- faultTolerance: number;
1
+ import type { Transport, TransportManager, TransportManagerEvents } from '@libp2p/interfaces/transport';
2
+ import type { Multiaddr } from '@multiformats/multiaddr';
3
+ import type { Connection } from '@libp2p/interfaces/connection';
4
+ import { AbortOptions, EventEmitter, Startable } from '@libp2p/interfaces';
5
+ import type { Components } from '@libp2p/interfaces/components';
6
+ export interface TransportManagerInit {
7
+ faultTolerance?: FaultTolerance;
8
+ }
9
+ export declare class DefaultTransportManager extends EventEmitter<TransportManagerEvents> implements TransportManager, Startable {
10
+ private readonly components;
11
+ private readonly transports;
12
+ private readonly listeners;
13
+ private readonly faultTolerance;
14
+ private started;
15
+ constructor(components: Components, init?: TransportManagerInit);
28
16
  /**
29
17
  * Adds a `Transport` to the manager
30
- *
31
- * @param {string} key
32
- * @param {TransportFactory} Transport
33
- * @param {*} transportOptions - Additional options to pass to the transport
34
- * @returns {void}
35
18
  */
36
- add(key: string, Transport: import("libp2p-interfaces/src/transport/types").TransportFactory<any, any>, transportOptions?: any): void;
19
+ add(transport: Transport): void;
20
+ isStarted(): boolean;
21
+ start(): Promise<void>;
37
22
  /**
38
23
  * Stops all listeners
39
- *
40
- * @async
41
24
  */
42
- close(): Promise<void>;
25
+ stop(): Promise<void>;
43
26
  /**
44
27
  * Dials the given Multiaddr over it's supported transport
45
- *
46
- * @param {Multiaddr} ma
47
- * @param {*} options
48
- * @returns {Promise<Connection>}
49
28
  */
50
- dial(ma: Multiaddr, options: any): Promise<Connection>;
29
+ dial(ma: Multiaddr, options?: AbortOptions): Promise<Connection>;
51
30
  /**
52
31
  * Returns all Multiaddr's the listeners are using
53
- *
54
- * @returns {Multiaddr[]}
55
32
  */
56
33
  getAddrs(): Multiaddr[];
57
34
  /**
58
- * Returns all the transports instances.
59
- *
60
- * @returns {IterableIterator<Transport>}
35
+ * Returns all the transports instances
61
36
  */
62
- getTransports(): IterableIterator<import("libp2p-interfaces/src/transport/types").Transport<any, any>>;
37
+ getTransports(): Transport[];
63
38
  /**
64
39
  * Finds a transport that matches the given Multiaddr
65
- *
66
- * @param {Multiaddr} ma
67
- * @returns {Transport|null}
68
40
  */
69
- transportForMultiaddr(ma: Multiaddr): import("libp2p-interfaces/src/transport/types").Transport<any, any> | null;
41
+ transportForMultiaddr(ma: Multiaddr): Transport | undefined;
70
42
  /**
71
- * Starts listeners for each listen Multiaddr.
72
- *
73
- * @async
74
- * @param {Multiaddr[]} addrs - addresses to attempt to listen on
43
+ * Starts listeners for each listen Multiaddr
75
44
  */
76
45
  listen(addrs: Multiaddr[]): Promise<void>;
77
46
  /**
78
47
  * Removes the given transport from the manager.
79
48
  * If a transport has any running listeners, they will be closed.
80
- *
81
- * @async
82
- * @param {string} key
83
49
  */
84
50
  remove(key: string): Promise<void>;
85
51
  /**
@@ -90,31 +56,17 @@ declare class TransportManager {
90
56
  */
91
57
  removeAll(): Promise<void>;
92
58
  }
93
- declare namespace TransportManager {
94
- export { FAULT_TOLERANCE as FaultTolerance, Multiaddr, Connection, TransportFactory, Transport, TransportManagerProperties, TransportManagerOptions };
95
- }
96
- type Multiaddr = import('multiaddr').Multiaddr;
97
- type Connection = import("libp2p-interfaces/src/connection/connection");
98
- type TransportManagerProperties = {
99
- libp2p: import('./');
100
- upgrader: import('./upgrader');
101
- };
102
- type TransportManagerOptions = {
103
- /**
104
- * - Address listen error tolerance.
105
- */
106
- faultTolerance?: number | undefined;
107
- };
108
59
  /**
109
- * Enum Transport Manager Fault Tolerance values.
110
- * FATAL_ALL should be used for failing in any listen circumstance.
111
- * NO_FATAL should be used for not failing when not listening.
60
+ * Enum Transport Manager Fault Tolerance values
112
61
  */
113
- type FAULT_TOLERANCE = number;
114
- declare namespace FAULT_TOLERANCE {
115
- const FATAL_ALL: number;
116
- const NO_FATAL: number;
62
+ export declare enum FaultTolerance {
63
+ /**
64
+ * should be used for failing in any listen circumstance
65
+ */
66
+ FATAL_ALL = 0,
67
+ /**
68
+ * should be used for not failing when not listening
69
+ */
70
+ NO_FATAL = 1
117
71
  }
118
- type TransportFactory = import('libp2p-interfaces/src/transport/types').TransportFactory<any, any>;
119
- type Transport = import('libp2p-interfaces/src/transport/types').Transport<any, any>;
120
72
  //# sourceMappingURL=transport-manager.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transport-manager.d.ts","sourceRoot":"","sources":["../../src/transport-manager.js"],"names":[],"mappings":";AAaA;;;;;;;;;;;;GAYG;AAEH;IACE;;;OAGG;IACH,kDAFW,0BAA0B,GAAG,uBAAuB,EAU9D;IAPC,qBAAoB;IACpB,+BAAwB;IACxB,qCAAqC;IACrC,aADW,IAAI,MAAM,sEAAY,CACL;IAC5B,0BAA2B;IAC3B,gCAAiC;IACjC,uBAAoC;IAGtC;;;;;;;OAOG;IACH,SALW,MAAM,kHAGJ,IAAI,CAsBhB;IAED;;;;OAIG;IACH,uBAiBC;IAED;;;;;;OAMG;IACH,SAJW,SAAS,iBAEP,QAAQ,UAAU,CAAC,CAc/B;IAED;;;;OAIG;IACH,YAFa,SAAS,EAAE,CAWvB;IAED;;;;OAIG;IACH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