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
@@ -1,193 +1,128 @@
1
- export = ConnectionManager;
2
- /**
3
- * @typedef {import('../')} Libp2p
4
- * @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
5
- */
6
- /**
7
- * @typedef {Object} ConnectionManagerOptions
8
- * @property {number} [maxConnections = Infinity] - The maximum number of connections allowed.
9
- * @property {number} [minConnections = 0] - The minimum number of connections to avoid pruning.
10
- * @property {number} [maxData = Infinity] - The max data (in and out), per average interval to allow.
11
- * @property {number} [maxSentData = Infinity] - The max outgoing data, per average interval to allow.
12
- * @property {number} [maxReceivedData = Infinity] - The max incoming data, per average interval to allow.
13
- * @property {number} [maxEventLoopDelay = Infinity] - The upper limit the event loop can take to run.
14
- * @property {number} [pollInterval = 2000] - How often, in milliseconds, metrics and latency should be checked.
15
- * @property {number} [movingAverageInterval = 60000] - How often, in milliseconds, to compute averages.
16
- * @property {number} [defaultPeerValue = 1] - The value of the peer.
17
- * @property {boolean} [autoDial = true] - Should preemptively guarantee connections are above the low watermark.
18
- * @property {number} [autoDialInterval = 10000] - How often, in milliseconds, it should preemptively guarantee connections are above the low watermark.
19
- */
20
- /**
21
- *
22
- * @fires ConnectionManager#peer:connect Emitted when a new peer is connected.
23
- * @fires ConnectionManager#peer:disconnect Emitted when a peer is disconnected.
24
- */
25
- declare class ConnectionManager extends EventEmitter {
1
+ import { SummaryObject } from './latency-monitor.js';
2
+ import { EventEmitter, Startable } from '@libp2p/interfaces';
3
+ import { PeerId } from '@libp2p/interfaces/peer-id';
4
+ import type { Connection } from '@libp2p/interfaces/connection';
5
+ import type { ConnectionManager } from '@libp2p/interfaces/registrar';
6
+ import type { Components } from '@libp2p/interfaces/components';
7
+ export interface ConnectionManagerEvents {
8
+ 'peer:connect': CustomEvent<PeerId>;
9
+ 'peer:disconnect': CustomEvent<PeerId>;
10
+ }
11
+ export interface ConnectionManagerInit {
26
12
  /**
27
- * Responsible for managing known connections.
28
- *
29
- * @class
30
- * @param {Libp2p} libp2p
31
- * @param {ConnectionManagerOptions} options
13
+ * The maximum number of connections allowed
32
14
  */
33
- constructor(libp2p: Libp2p, options?: ConnectionManagerOptions);
34
- _libp2p: import("../");
35
- _peerId: string;
36
- _options: any;
15
+ maxConnections?: number;
37
16
  /**
38
- * Map of peer identifiers to their peer value for pruning connections.
39
- *
40
- * @type {Map<string, number>}
17
+ * The minimum number of connections to avoid pruning
41
18
  */
42
- _peerValues: Map<string, number>;
19
+ minConnections?: number;
43
20
  /**
44
- * Map of connections per peer
45
- *
46
- * @type {Map<string, Connection[]>}
21
+ * The max data (in and out), per average interval to allow
47
22
  */
48
- connections: Map<string, Connection[]>;
49
- _started: boolean;
50
- _timer: any;
23
+ maxData?: number;
51
24
  /**
52
- * Checks the libp2p metrics to determine if any values have exceeded
53
- * the configured maximums.
54
- *
55
- * @private
25
+ * The max outgoing data, per average interval to allow
56
26
  */
57
- private _checkMetrics;
58
- _latencyMonitor: LatencyMonitor;
27
+ maxSentData?: number;
59
28
  /**
60
- * Get current number of open connections.
29
+ * The max incoming data, per average interval to allow
61
30
  */
62
- get size(): number;
31
+ maxReceivedData?: number;
63
32
  /**
64
- * Starts the Connection Manager. If Metrics are not enabled on libp2p
65
- * only event loop and connection limits will be monitored.
33
+ * The upper limit the event loop can take to run
66
34
  */
67
- start(): void;
35
+ maxEventLoopDelay?: number;
68
36
  /**
69
- * If the event loop is slow, maybe close a connection
70
- *
71
- * @private
72
- * @param {*} summary - The LatencyMonitor summary
37
+ * How often, in milliseconds, metrics and latency should be checked
73
38
  */
74
- private _onLatencyMeasure;
39
+ pollInterval?: number;
75
40
  /**
76
- * Stops the Connection Manager
77
- *
78
- * @async
41
+ * How often, in milliseconds, to compute averages
79
42
  */
80
- stop(): Promise<void>;
43
+ movingAverageInterval?: number;
81
44
  /**
82
- * Cleans up the connections
83
- *
84
- * @async
45
+ * The value of the peer
85
46
  */
86
- _close(): Promise<void>;
47
+ defaultPeerValue?: number;
87
48
  /**
88
- * Sets the value of the given peer. Peers with lower values
89
- * will be disconnected first.
90
- *
91
- * @param {PeerId} peerId
92
- * @param {number} value - A number between 0 and 1
93
- * @returns {void}
49
+ * Should preemptively guarantee connections are above the low watermark
94
50
  */
95
- setPeerValue(peerId: PeerId, value: number): void;
51
+ autoDial?: boolean;
96
52
  /**
97
- * Tracks the incoming connection and check the connection limit
98
- *
99
- * @param {Connection} connection
53
+ * How often, in milliseconds, it should preemptively guarantee connections are above the low watermark
100
54
  */
101
- onConnect(connection: Connection): Promise<void>;
55
+ autoDialInterval?: number;
56
+ }
57
+ /**
58
+ * Responsible for managing known connections.
59
+ */
60
+ export declare class DefaultConnectionManager extends EventEmitter<ConnectionManagerEvents> implements ConnectionManager, Startable {
61
+ private readonly components;
62
+ private readonly init;
63
+ private readonly peerValues;
64
+ private readonly connections;
65
+ private started;
66
+ private timer?;
67
+ private readonly latencyMonitor;
68
+ constructor(components: Components, init?: ConnectionManagerInit);
69
+ isStarted(): boolean;
102
70
  /**
103
- * Removes the connection from tracking
104
- *
105
- * @param {Connection} connection
106
- * @returns {void}
71
+ * Starts the Connection Manager. If Metrics are not enabled on libp2p
72
+ * only event loop and connection limits will be monitored.
107
73
  */
108
- onDisconnect(connection: Connection): void;
74
+ start(): Promise<void>;
109
75
  /**
110
- * Get a connection with a peer.
111
- *
112
- * @param {PeerId} peerId
113
- * @returns {Connection|null}
76
+ * Stops the Connection Manager
114
77
  */
115
- get(peerId: PeerId): Connection | null;
78
+ stop(): Promise<void>;
116
79
  /**
117
- * Get all open connections with a peer.
118
- *
119
- * @param {PeerId} peerId
120
- * @returns {Connection[]}
80
+ * Cleans up the connections
121
81
  */
122
- getAll(peerId: PeerId): Connection[];
82
+ _close(): Promise<void>;
123
83
  /**
124
- * If the `value` of `name` has exceeded its limit, maybe close a connection
125
- *
126
- * @private
127
- * @param {string} name - The name of the field to check limits for
128
- * @param {number} value - The current value of the field
84
+ * Sets the value of the given peer. Peers with lower values
85
+ * will be disconnected first.
129
86
  */
130
- private _checkMaxLimit;
87
+ setPeerValue(peerId: PeerId, value: number): void;
131
88
  /**
132
- * If we have more connections than our maximum, close a connection
133
- * to the lowest valued peer.
89
+ * Checks the libp2p metrics to determine if any values have exceeded
90
+ * the configured maximums.
134
91
  *
135
92
  * @private
136
93
  */
137
- private _maybeDisconnectOne;
138
- }
139
- declare namespace ConnectionManager {
140
- export { Libp2p, Connection, ConnectionManagerOptions };
141
- }
142
- import { EventEmitter } from "events";
143
- type Connection = import("libp2p-interfaces/src/connection/connection");
144
- import LatencyMonitor = require("./latency-monitor");
145
- import PeerId = require("peer-id");
146
- type Libp2p = import('../');
147
- type ConnectionManagerOptions = {
148
- /**
149
- * - The maximum number of connections allowed.
150
- */
151
- maxConnections?: number | undefined;
152
- /**
153
- * - The minimum number of connections to avoid pruning.
154
- */
155
- minConnections?: number | undefined;
156
- /**
157
- * - The max data (in and out), per average interval to allow.
158
- */
159
- maxData?: number | undefined;
160
- /**
161
- * - The max outgoing data, per average interval to allow.
162
- */
163
- maxSentData?: number | undefined;
94
+ _checkMetrics(): Promise<void>;
164
95
  /**
165
- * - The max incoming data, per average interval to allow.
96
+ * Tracks the incoming connection and check the connection limit
166
97
  */
167
- maxReceivedData?: number | undefined;
98
+ onConnect(evt: CustomEvent<Connection>): Promise<void>;
168
99
  /**
169
- * - The upper limit the event loop can take to run.
100
+ * Removes the connection from tracking
170
101
  */
171
- maxEventLoopDelay?: number | undefined;
102
+ onDisconnect(evt: CustomEvent<Connection>): void;
103
+ getConnectionMap(): Map<string, Connection[]>;
104
+ getConnectionList(): Connection[];
105
+ getConnections(peerId: PeerId): Connection[];
172
106
  /**
173
- * - How often, in milliseconds, metrics and latency should be checked.
107
+ * Get a connection with a peer
174
108
  */
175
- pollInterval?: number | undefined;
109
+ getConnection(peerId: PeerId): Connection | undefined;
176
110
  /**
177
- * - How often, in milliseconds, to compute averages.
111
+ * Get all open connections with a peer
178
112
  */
179
- movingAverageInterval?: number | undefined;
113
+ getAll(peerId: PeerId): Connection[];
180
114
  /**
181
- * - The value of the peer.
115
+ * If the event loop is slow, maybe close a connection
182
116
  */
183
- defaultPeerValue?: number | undefined;
117
+ _onLatencyMeasure(evt: CustomEvent<SummaryObject>): void;
184
118
  /**
185
- * - Should preemptively guarantee connections are above the low watermark.
119
+ * If the `value` of `name` has exceeded its limit, maybe close a connection
186
120
  */
187
- autoDial?: boolean | undefined;
121
+ _checkMaxLimit(name: keyof ConnectionManagerInit, value: number): Promise<void>;
188
122
  /**
189
- * - How often, in milliseconds, it should preemptively guarantee connections are above the low watermark.
123
+ * If we have more connections than our maximum, close a connection
124
+ * to the lowest valued peer.
190
125
  */
191
- autoDialInterval?: number | undefined;
192
- };
126
+ _maybeDisconnectOne(): Promise<void>;
127
+ }
193
128
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection-manager/index.js"],"names":[],"mappings":";AAsCA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;GAIG;AACH;IACE;;;;;;O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MAAM;IAcZ;;;OAGG;IACH,YAAY,CAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAQ3C;;;;;OAKG;IACG,aAAa;IAmBnB;;OAEG;IACG,SAAS,CAAE,GAAG,EAAE,WAAW,CAAC,UAAU,CAAC;IAgC7C;;OAEG;IACH,YAAY,CAAE,GAAG,EAAE,WAAW,CAAC,UAAU,CAAC;IAuB1C,gBAAgB,IAAK,GAAG,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;IAI9C,iBAAiB,IAAK,UAAU,EAAE;IAUlC,cAAc,CAAE,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE;IAI7C;;OAEG;IACH,aAAa,CAAE,MAAM,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAUtD;;OAEG;IACH,MAAM,CAAE,MAAM,EAAE,MAAM,GAAG,UAAU,EAAE;IAgBrC;;OAEG;IACH,iBAAiB,CAAE,GAAG,EAAE,WAAW,CAAC,aAAa,CAAC;IASlD;;OAEG;IACG,cAAc,CAAE,IAAI,EAAE,MAAM,qBAAqB,EAAE,KAAK,EAAE,MAAM;IAStE;;;OAGG;IACG,mBAAmB;CA6B1B"}
@@ -0,0 +1,295 @@
1
+ import { logger } from '@libp2p/logger';
2
+ import errCode from 'err-code';
3
+ import mergeOptions from 'merge-options';
4
+ import { LatencyMonitor } from './latency-monitor.js';
5
+ // @ts-expect-error retimer does not have types
6
+ import retimer from 'retimer';
7
+ import { CustomEvent, EventEmitter } from '@libp2p/interfaces';
8
+ import { trackedMap } from '@libp2p/tracked-map';
9
+ import { codes } from '../errors.js';
10
+ import { isPeerId } from '@libp2p/interfaces/peer-id';
11
+ // @ts-expect-error setMaxListeners is missing from the node 16 types
12
+ import { setMaxListeners } from 'events';
13
+ import * as STATUS from '@libp2p/interfaces/connection/status';
14
+ const log = logger('libp2p:connection-manager');
15
+ const defaultOptions = {
16
+ maxConnections: Infinity,
17
+ minConnections: 0,
18
+ maxData: Infinity,
19
+ maxSentData: Infinity,
20
+ maxReceivedData: Infinity,
21
+ maxEventLoopDelay: Infinity,
22
+ pollInterval: 2000,
23
+ autoDialInterval: 10000,
24
+ movingAverageInterval: 60000,
25
+ defaultPeerValue: 1
26
+ };
27
+ const METRICS_COMPONENT = 'connection-manager';
28
+ const METRICS_PEER_CONNECTIONS = 'peer-connections';
29
+ const METRICS_PEER_VALUES = 'peer-values';
30
+ /**
31
+ * Responsible for managing known connections.
32
+ */
33
+ export class DefaultConnectionManager extends EventEmitter {
34
+ constructor(components, init = {}) {
35
+ super();
36
+ this.components = components;
37
+ this.init = mergeOptions.call({ ignoreUndefined: true }, defaultOptions, init);
38
+ if (this.init.maxConnections < this.init.minConnections) {
39
+ throw errCode(new Error('Connection Manager maxConnections must be greater than minConnections'), codes.ERR_INVALID_PARAMETERS);
40
+ }
41
+ log('options: %o', this.init);
42
+ /**
43
+ * Map of peer identifiers to their peer value for pruning connections.
44
+ *
45
+ * @type {Map<string, number>}
46
+ */
47
+ this.peerValues = trackedMap({
48
+ component: METRICS_COMPONENT,
49
+ metric: METRICS_PEER_VALUES,
50
+ metrics: this.components.getMetrics()
51
+ });
52
+ /**
53
+ * Map of connections per peer
54
+ */
55
+ this.connections = trackedMap({
56
+ component: METRICS_COMPONENT,
57
+ metric: METRICS_PEER_CONNECTIONS,
58
+ metrics: this.components.getMetrics()
59
+ });
60
+ this.started = false;
61
+ this._checkMetrics = this._checkMetrics.bind(this);
62
+ this.latencyMonitor = new LatencyMonitor({
63
+ latencyCheckIntervalMs: init.pollInterval,
64
+ dataEmitIntervalMs: init.pollInterval
65
+ });
66
+ try {
67
+ // This emitter gets listened to a lot
68
+ setMaxListeners?.(Infinity, this);
69
+ }
70
+ catch { }
71
+ this.components.getUpgrader().addEventListener('connection', (evt) => {
72
+ void this.onConnect(evt).catch(err => {
73
+ log.error(err);
74
+ });
75
+ });
76
+ this.components.getUpgrader().addEventListener('connectionEnd', this.onDisconnect.bind(this));
77
+ }
78
+ isStarted() {
79
+ return this.started;
80
+ }
81
+ /**
82
+ * Starts the Connection Manager. If Metrics are not enabled on libp2p
83
+ * only event loop and connection limits will be monitored.
84
+ */
85
+ async start() {
86
+ if (this.components.getMetrics() != null) {
87
+ this.timer = this.timer ?? retimer(this._checkMetrics, this.init.pollInterval);
88
+ }
89
+ // latency monitor
90
+ this.latencyMonitor.start();
91
+ this._onLatencyMeasure = this._onLatencyMeasure.bind(this);
92
+ this.latencyMonitor.addEventListener('data', this._onLatencyMeasure);
93
+ this.started = true;
94
+ log('started');
95
+ }
96
+ /**
97
+ * Stops the Connection Manager
98
+ */
99
+ async stop() {
100
+ this.timer?.clear();
101
+ this.latencyMonitor.removeEventListener('data', this._onLatencyMeasure);
102
+ this.latencyMonitor.stop();
103
+ this.started = false;
104
+ await this._close();
105
+ log('stopped');
106
+ }
107
+ /**
108
+ * Cleans up the connections
109
+ */
110
+ async _close() {
111
+ // Close all connections we're tracking
112
+ const tasks = [];
113
+ for (const connectionList of this.connections.values()) {
114
+ for (const connection of connectionList) {
115
+ tasks.push(connection.close());
116
+ }
117
+ }
118
+ log('closing %d connections', tasks.length);
119
+ await Promise.all(tasks);
120
+ this.connections.clear();
121
+ }
122
+ /**
123
+ * Sets the value of the given peer. Peers with lower values
124
+ * will be disconnected first.
125
+ */
126
+ setPeerValue(peerId, value) {
127
+ if (value < 0 || value > 1) {
128
+ throw new Error('value should be a number between 0 and 1');
129
+ }
130
+ this.peerValues.set(peerId.toString(), value);
131
+ }
132
+ /**
133
+ * Checks the libp2p metrics to determine if any values have exceeded
134
+ * the configured maximums.
135
+ *
136
+ * @private
137
+ */
138
+ async _checkMetrics() {
139
+ const metrics = this.components.getMetrics();
140
+ if (metrics != null) {
141
+ try {
142
+ const movingAverages = metrics.getGlobal().getMovingAverages();
143
+ const received = movingAverages.dataReceived[this.init.movingAverageInterval].movingAverage;
144
+ await this._checkMaxLimit('maxReceivedData', received);
145
+ const sent = movingAverages.dataSent[this.init.movingAverageInterval].movingAverage;
146
+ await this._checkMaxLimit('maxSentData', sent);
147
+ const total = received + sent;
148
+ await this._checkMaxLimit('maxData', total);
149
+ log('metrics update', total);
150
+ }
151
+ finally {
152
+ this.timer = retimer(this._checkMetrics, this.init.pollInterval);
153
+ }
154
+ }
155
+ }
156
+ /**
157
+ * Tracks the incoming connection and check the connection limit
158
+ */
159
+ async onConnect(evt) {
160
+ const { detail: connection } = evt;
161
+ if (!this.started) {
162
+ // This can happen when we are in the process of shutting down the node
163
+ await connection.close();
164
+ return;
165
+ }
166
+ const peerId = connection.remotePeer;
167
+ const peerIdStr = peerId.toString();
168
+ const storedConns = this.connections.get(peerIdStr);
169
+ this.dispatchEvent(new CustomEvent('peer:connect', { detail: connection }));
170
+ if (storedConns != null) {
171
+ storedConns.push(connection);
172
+ }
173
+ else {
174
+ this.connections.set(peerIdStr, [connection]);
175
+ }
176
+ if (peerId.publicKey != null) {
177
+ await this.components.getPeerStore().keyBook.set(peerId, peerId.publicKey);
178
+ }
179
+ if (!this.peerValues.has(peerIdStr)) {
180
+ this.peerValues.set(peerIdStr, this.init.defaultPeerValue);
181
+ }
182
+ await this._checkMaxLimit('maxConnections', this.getConnectionList().length);
183
+ }
184
+ /**
185
+ * Removes the connection from tracking
186
+ */
187
+ onDisconnect(evt) {
188
+ const { detail: connection } = evt;
189
+ if (!this.started) {
190
+ // This can happen when we are in the process of shutting down the node
191
+ return;
192
+ }
193
+ const peerId = connection.remotePeer.toString();
194
+ let storedConn = this.connections.get(peerId);
195
+ if (storedConn != null && storedConn.length > 1) {
196
+ storedConn = storedConn.filter((conn) => conn.id !== connection.id);
197
+ this.connections.set(peerId, storedConn);
198
+ }
199
+ else if (storedConn != null) {
200
+ this.connections.delete(peerId);
201
+ this.peerValues.delete(connection.remotePeer.toString());
202
+ this.dispatchEvent(new CustomEvent('peer:disconnect', { detail: connection }));
203
+ this.components.getMetrics()?.onPeerDisconnected(connection.remotePeer);
204
+ }
205
+ }
206
+ getConnectionMap() {
207
+ return this.connections;
208
+ }
209
+ getConnectionList() {
210
+ let output = [];
211
+ for (const connections of this.connections.values()) {
212
+ output = output.concat(connections);
213
+ }
214
+ return output;
215
+ }
216
+ getConnections(peerId) {
217
+ return this.connections.get(peerId.toString()) ?? [];
218
+ }
219
+ /**
220
+ * Get a connection with a peer
221
+ */
222
+ getConnection(peerId) {
223
+ const connections = this.getAll(peerId);
224
+ if (connections.length > 0) {
225
+ return connections[0];
226
+ }
227
+ return undefined;
228
+ }
229
+ /**
230
+ * Get all open connections with a peer
231
+ */
232
+ getAll(peerId) {
233
+ if (!isPeerId(peerId)) {
234
+ throw errCode(new Error('peerId must be an instance of peer-id'), codes.ERR_INVALID_PARAMETERS);
235
+ }
236
+ const id = peerId.toString();
237
+ const connections = this.connections.get(id);
238
+ // Return all open connections
239
+ if (connections != null) {
240
+ return connections.filter(connection => connection.stat.status === STATUS.OPEN);
241
+ }
242
+ return [];
243
+ }
244
+ /**
245
+ * If the event loop is slow, maybe close a connection
246
+ */
247
+ _onLatencyMeasure(evt) {
248
+ const { detail: summary } = evt;
249
+ this._checkMaxLimit('maxEventLoopDelay', summary.avgMs)
250
+ .catch(err => {
251
+ log.error(err);
252
+ });
253
+ }
254
+ /**
255
+ * If the `value` of `name` has exceeded its limit, maybe close a connection
256
+ */
257
+ async _checkMaxLimit(name, value) {
258
+ const limit = this.init[name];
259
+ log.trace('checking limit of %s. current value: %d of %d', name, value, limit);
260
+ if (value > limit) {
261
+ log('%s: limit exceeded: %p, %d', this.components.getPeerId(), name, value);
262
+ await this._maybeDisconnectOne();
263
+ }
264
+ }
265
+ /**
266
+ * If we have more connections than our maximum, close a connection
267
+ * to the lowest valued peer.
268
+ */
269
+ async _maybeDisconnectOne() {
270
+ if (this.init.minConnections < this.connections.size) {
271
+ const peerValues = Array.from(new Map([...this.peerValues.entries()].sort((a, b) => a[1] - b[1])));
272
+ log('%p: sorted peer values: %j', this.components.getPeerId(), peerValues);
273
+ const disconnectPeer = peerValues[0];
274
+ if (disconnectPeer != null) {
275
+ const peerId = disconnectPeer[0];
276
+ log('%p: lowest value peer is %s', this.components.getPeerId(), peerId);
277
+ log('%p: closing a connection to %j', this.components.getPeerId(), peerId);
278
+ for (const connections of this.connections.values()) {
279
+ if (connections[0].remotePeer.toString() === peerId) {
280
+ void connections[0].close()
281
+ .catch(err => {
282
+ log.error(err);
283
+ });
284
+ // TODO: should not need to invoke this manually
285
+ this.onDisconnect(new CustomEvent('connectionEnd', {
286
+ detail: connections[0]
287
+ }));
288
+ break;
289
+ }
290
+ }
291
+ }
292
+ }
293
+ }
294
+ }
295
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/connection-manager/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,YAAY,MAAM,eAAe,CAAA;AACxC,OAAO,EAAE,cAAc,EAAiB,MAAM,sBAAsB,CAAA;AACpE,+CAA+C;AAC/C,OAAO,OAAO,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,WAAW,EAAE,YAAY,EAAa,MAAM,oBAAoB,CAAA;AACzE,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,QAAQ,EAAU,MAAM,4BAA4B,CAAA;AAC7D,qEAAqE;AACrE,OAAO,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAA;AAIxC,OAAO,KAAK,MAAM,MAAM,sCAAsC,CAAA;AAE9D,MAAM,GAAG,GAAG,MAAM,CAAC,2BAA2B,CAAC,CAAA;AAE/C,MAAM,cAAc,GAAmC;IACrD,cAAc,EAAE,QAAQ;IACxB,cAAc,EAAE,CAAC;IACjB,OAAO,EAAE,QAAQ;IACjB,WAAW,EAAE,QAAQ;IACrB,eAAe,EAAE,QAAQ;IACzB,iBAAi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