libp2p 0.46.21 → 1.0.0-06e6d235f

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 (301) hide show
  1. package/README.md +52 -48
  2. package/dist/index.min.js +40 -28
  3. package/dist/src/address-manager/index.d.ts +4 -5
  4. package/dist/src/address-manager/index.d.ts.map +1 -1
  5. package/dist/src/address-manager/index.js +3 -3
  6. package/dist/src/address-manager/index.js.map +1 -1
  7. package/dist/src/components.d.ts +4 -15
  8. package/dist/src/components.d.ts.map +1 -1
  9. package/dist/src/components.js +2 -2
  10. package/dist/src/components.js.map +1 -1
  11. package/dist/src/config/connection-gater.browser.d.ts +1 -1
  12. package/dist/src/config/connection-gater.browser.d.ts.map +1 -1
  13. package/dist/src/config/connection-gater.browser.js.map +1 -1
  14. package/dist/src/config/connection-gater.d.ts +1 -1
  15. package/dist/src/config/connection-gater.d.ts.map +1 -1
  16. package/dist/src/config.d.ts.map +1 -1
  17. package/dist/src/config.js +1 -2
  18. package/dist/src/config.js.map +1 -1
  19. package/dist/src/connection/index.d.ts +4 -6
  20. package/dist/src/connection/index.d.ts.map +1 -1
  21. package/dist/src/connection/index.js +11 -13
  22. package/dist/src/connection/index.js.map +1 -1
  23. package/dist/src/connection-manager/auto-dial.d.ts +3 -6
  24. package/dist/src/connection-manager/auto-dial.d.ts.map +1 -1
  25. package/dist/src/connection-manager/auto-dial.js +21 -21
  26. package/dist/src/connection-manager/auto-dial.js.map +1 -1
  27. package/dist/src/connection-manager/connection-pruner.d.ts +3 -5
  28. package/dist/src/connection-manager/connection-pruner.d.ts.map +1 -1
  29. package/dist/src/connection-manager/connection-pruner.js +8 -8
  30. package/dist/src/connection-manager/connection-pruner.js.map +1 -1
  31. package/dist/src/connection-manager/constants.defaults.d.ts +0 -4
  32. package/dist/src/connection-manager/constants.defaults.d.ts.map +1 -1
  33. package/dist/src/connection-manager/constants.defaults.js +0 -4
  34. package/dist/src/connection-manager/constants.defaults.js.map +1 -1
  35. package/dist/src/connection-manager/dial-queue.d.ts +3 -10
  36. package/dist/src/connection-manager/dial-queue.d.ts.map +1 -1
  37. package/dist/src/connection-manager/dial-queue.js +30 -38
  38. package/dist/src/connection-manager/dial-queue.js.map +1 -1
  39. package/dist/src/connection-manager/index.d.ts +3 -18
  40. package/dist/src/connection-manager/index.d.ts.map +1 -1
  41. package/dist/src/connection-manager/index.js +17 -19
  42. package/dist/src/connection-manager/index.js.map +1 -1
  43. package/dist/src/connection-manager/utils.js +1 -1
  44. package/dist/src/connection-manager/utils.js.map +1 -1
  45. package/dist/src/content-routing/index.d.ts +1 -5
  46. package/dist/src/content-routing/index.d.ts.map +1 -1
  47. package/dist/src/content-routing/index.js +2 -2
  48. package/dist/src/content-routing/index.js.map +1 -1
  49. package/dist/src/content-routing/utils.d.ts +1 -2
  50. package/dist/src/content-routing/utils.d.ts.map +1 -1
  51. package/dist/src/content-routing/utils.js +1 -1
  52. package/dist/src/content-routing/utils.js.map +1 -1
  53. package/dist/src/errors.d.ts +0 -2
  54. package/dist/src/errors.d.ts.map +1 -1
  55. package/dist/src/errors.js +0 -2
  56. package/dist/src/errors.js.map +1 -1
  57. package/dist/src/get-peer.d.ts +1 -1
  58. package/dist/src/get-peer.d.ts.map +1 -1
  59. package/dist/src/get-peer.js +1 -5
  60. package/dist/src/get-peer.js.map +1 -1
  61. package/dist/src/index.d.ts +5 -16
  62. package/dist/src/index.d.ts.map +1 -1
  63. package/dist/src/index.js.map +1 -1
  64. package/dist/src/libp2p.d.ts +4 -12
  65. package/dist/src/libp2p.d.ts.map +1 -1
  66. package/dist/src/libp2p.js +30 -65
  67. package/dist/src/libp2p.js.map +1 -1
  68. package/dist/src/peer-routing.d.ts +6 -6
  69. package/dist/src/peer-routing.d.ts.map +1 -1
  70. package/dist/src/peer-routing.js +12 -9
  71. package/dist/src/peer-routing.js.map +1 -1
  72. package/dist/src/registrar.d.ts +5 -7
  73. package/dist/src/registrar.d.ts.map +1 -1
  74. package/dist/src/registrar.js +4 -4
  75. package/dist/src/registrar.js.map +1 -1
  76. package/dist/src/transport-manager.d.ts +5 -9
  77. package/dist/src/transport-manager.d.ts.map +1 -1
  78. package/dist/src/transport-manager.js +12 -13
  79. package/dist/src/transport-manager.js.map +1 -1
  80. package/dist/src/upgrader.d.ts +8 -19
  81. package/dist/src/upgrader.d.ts.map +1 -1
  82. package/dist/src/upgrader.js +75 -38
  83. package/dist/src/upgrader.js.map +1 -1
  84. package/dist/src/version.d.ts +1 -1
  85. package/dist/src/version.d.ts.map +1 -1
  86. package/dist/src/version.js +1 -1
  87. package/dist/src/version.js.map +1 -1
  88. package/package.json +41 -110
  89. package/src/address-manager/index.ts +6 -9
  90. package/src/components.ts +5 -16
  91. package/src/config/connection-gater.browser.ts +1 -1
  92. package/src/config/connection-gater.ts +1 -1
  93. package/src/config.ts +1 -2
  94. package/src/connection/index.ts +12 -17
  95. package/src/connection-manager/auto-dial.ts +23 -26
  96. package/src/connection-manager/connection-pruner.ts +10 -12
  97. package/src/connection-manager/constants.defaults.ts +0 -5
  98. package/src/connection-manager/dial-queue.ts +31 -46
  99. package/src/connection-manager/index.ts +19 -37
  100. package/src/connection-manager/utils.ts +1 -1
  101. package/src/content-routing/index.ts +3 -7
  102. package/src/content-routing/utils.ts +2 -3
  103. package/src/errors.ts +0 -2
  104. package/src/get-peer.ts +2 -7
  105. package/src/index.ts +6 -17
  106. package/src/libp2p.ts +32 -80
  107. package/src/peer-routing.ts +16 -15
  108. package/src/registrar.ts +8 -12
  109. package/src/transport-manager.ts +15 -22
  110. package/src/upgrader.ts +110 -64
  111. package/src/version.ts +1 -1
  112. package/dist/src/autonat/constants.d.ts +0 -18
  113. package/dist/src/autonat/constants.d.ts.map +0 -1
  114. package/dist/src/autonat/constants.js +0 -18
  115. package/dist/src/autonat/constants.js.map +0 -1
  116. package/dist/src/autonat/index.d.ts +0 -62
  117. package/dist/src/autonat/index.d.ts.map +0 -1
  118. package/dist/src/autonat/index.js +0 -447
  119. package/dist/src/autonat/index.js.map +0 -1
  120. package/dist/src/autonat/pb/index.d.ts +0 -57
  121. package/dist/src/autonat/pb/index.d.ts.map +0 -1
  122. package/dist/src/autonat/pb/index.js +0 -250
  123. package/dist/src/autonat/pb/index.js.map +0 -1
  124. package/dist/src/circuit-relay/constants.d.ts +0 -50
  125. package/dist/src/circuit-relay/constants.d.ts.map +0 -1
  126. package/dist/src/circuit-relay/constants.js +0 -56
  127. package/dist/src/circuit-relay/constants.js.map +0 -1
  128. package/dist/src/circuit-relay/index.d.ts +0 -55
  129. package/dist/src/circuit-relay/index.d.ts.map +0 -1
  130. package/dist/src/circuit-relay/index.js +0 -38
  131. package/dist/src/circuit-relay/index.js.map +0 -1
  132. package/dist/src/circuit-relay/pb/index.d.ts +0 -93
  133. package/dist/src/circuit-relay/pb/index.d.ts.map +0 -1
  134. package/dist/src/circuit-relay/pb/index.js +0 -425
  135. package/dist/src/circuit-relay/pb/index.js.map +0 -1
  136. package/dist/src/circuit-relay/server/advert-service.d.ts +0 -43
  137. package/dist/src/circuit-relay/server/advert-service.d.ts.map +0 -1
  138. package/dist/src/circuit-relay/server/advert-service.js +0 -73
  139. package/dist/src/circuit-relay/server/advert-service.js.map +0 -1
  140. package/dist/src/circuit-relay/server/index.d.ts +0 -65
  141. package/dist/src/circuit-relay/server/index.d.ts.map +0 -1
  142. package/dist/src/circuit-relay/server/index.js +0 -312
  143. package/dist/src/circuit-relay/server/index.js.map +0 -1
  144. package/dist/src/circuit-relay/server/reservation-store.d.ts +0 -49
  145. package/dist/src/circuit-relay/server/reservation-store.d.ts.map +0 -1
  146. package/dist/src/circuit-relay/server/reservation-store.js +0 -65
  147. package/dist/src/circuit-relay/server/reservation-store.js.map +0 -1
  148. package/dist/src/circuit-relay/server/reservation-voucher.d.ts +0 -18
  149. package/dist/src/circuit-relay/server/reservation-voucher.d.ts.map +0 -1
  150. package/dist/src/circuit-relay/server/reservation-voucher.js +0 -36
  151. package/dist/src/circuit-relay/server/reservation-voucher.js.map +0 -1
  152. package/dist/src/circuit-relay/transport/discovery.d.ts +0 -45
  153. package/dist/src/circuit-relay/transport/discovery.d.ts.map +0 -1
  154. package/dist/src/circuit-relay/transport/discovery.js +0 -97
  155. package/dist/src/circuit-relay/transport/discovery.js.map +0 -1
  156. package/dist/src/circuit-relay/transport/index.d.ts +0 -57
  157. package/dist/src/circuit-relay/transport/index.d.ts.map +0 -1
  158. package/dist/src/circuit-relay/transport/index.js +0 -276
  159. package/dist/src/circuit-relay/transport/index.js.map +0 -1
  160. package/dist/src/circuit-relay/transport/listener.d.ts +0 -9
  161. package/dist/src/circuit-relay/transport/listener.d.ts.map +0 -1
  162. package/dist/src/circuit-relay/transport/listener.js +0 -66
  163. package/dist/src/circuit-relay/transport/listener.js.map +0 -1
  164. package/dist/src/circuit-relay/transport/reservation-store.d.ts +0 -72
  165. package/dist/src/circuit-relay/transport/reservation-store.d.ts.map +0 -1
  166. package/dist/src/circuit-relay/transport/reservation-store.js +0 -209
  167. package/dist/src/circuit-relay/transport/reservation-store.js.map +0 -1
  168. package/dist/src/circuit-relay/utils.d.ts +0 -13
  169. package/dist/src/circuit-relay/utils.d.ts.map +0 -1
  170. package/dist/src/circuit-relay/utils.js +0 -108
  171. package/dist/src/circuit-relay/utils.js.map +0 -1
  172. package/dist/src/dcutr/dcutr.d.ts +0 -43
  173. package/dist/src/dcutr/dcutr.d.ts.map +0 -1
  174. package/dist/src/dcutr/dcutr.js +0 -313
  175. package/dist/src/dcutr/dcutr.js.map +0 -1
  176. package/dist/src/dcutr/index.d.ts +0 -92
  177. package/dist/src/dcutr/index.d.ts.map +0 -1
  178. package/dist/src/dcutr/index.js +0 -63
  179. package/dist/src/dcutr/index.js.map +0 -1
  180. package/dist/src/dcutr/pb/message.d.ts +0 -20
  181. package/dist/src/dcutr/pb/message.d.ts.map +0 -1
  182. package/dist/src/dcutr/pb/message.js +0 -77
  183. package/dist/src/dcutr/pb/message.js.map +0 -1
  184. package/dist/src/dcutr/utils.d.ts +0 -8
  185. package/dist/src/dcutr/utils.d.ts.map +0 -1
  186. package/dist/src/dcutr/utils.js +0 -27
  187. package/dist/src/dcutr/utils.js.map +0 -1
  188. package/dist/src/fetch/constants.d.ts +0 -3
  189. package/dist/src/fetch/constants.d.ts.map +0 -1
  190. package/dist/src/fetch/constants.js +0 -4
  191. package/dist/src/fetch/constants.js.map +0 -1
  192. package/dist/src/fetch/index.d.ts +0 -61
  193. package/dist/src/fetch/index.d.ts.map +0 -1
  194. package/dist/src/fetch/index.js +0 -205
  195. package/dist/src/fetch/index.js.map +0 -1
  196. package/dist/src/fetch/pb/proto.d.ts +0 -28
  197. package/dist/src/fetch/pb/proto.d.ts.map +0 -1
  198. package/dist/src/fetch/pb/proto.js +0 -120
  199. package/dist/src/fetch/pb/proto.js.map +0 -1
  200. package/dist/src/identify/consts.d.ts +0 -10
  201. package/dist/src/identify/consts.d.ts.map +0 -1
  202. package/dist/src/identify/consts.js +0 -11
  203. package/dist/src/identify/consts.js.map +0 -1
  204. package/dist/src/identify/identify.d.ts +0 -54
  205. package/dist/src/identify/identify.d.ts.map +0 -1
  206. package/dist/src/identify/identify.js +0 -447
  207. package/dist/src/identify/identify.js.map +0 -1
  208. package/dist/src/identify/index.d.ts +0 -72
  209. package/dist/src/identify/index.d.ts.map +0 -1
  210. package/dist/src/identify/index.js +0 -15
  211. package/dist/src/identify/index.js.map +0 -1
  212. package/dist/src/identify/pb/message.d.ts +0 -17
  213. package/dist/src/identify/pb/message.d.ts.map +0 -1
  214. package/dist/src/identify/pb/message.js +0 -98
  215. package/dist/src/identify/pb/message.js.map +0 -1
  216. package/dist/src/insecure/index.d.ts +0 -26
  217. package/dist/src/insecure/index.d.ts.map +0 -1
  218. package/dist/src/insecure/index.js +0 -110
  219. package/dist/src/insecure/index.js.map +0 -1
  220. package/dist/src/insecure/pb/proto.d.ts +0 -30
  221. package/dist/src/insecure/pb/proto.d.ts.map +0 -1
  222. package/dist/src/insecure/pb/proto.js +0 -127
  223. package/dist/src/insecure/pb/proto.js.map +0 -1
  224. package/dist/src/ping/constants.d.ts +0 -9
  225. package/dist/src/ping/constants.d.ts.map +0 -1
  226. package/dist/src/ping/constants.js +0 -15
  227. package/dist/src/ping/constants.js.map +0 -1
  228. package/dist/src/ping/index.d.ts +0 -24
  229. package/dist/src/ping/index.d.ts.map +0 -1
  230. package/dist/src/ping/index.js +0 -115
  231. package/dist/src/ping/index.js.map +0 -1
  232. package/dist/src/pnet/crypto.d.ts +0 -18
  233. package/dist/src/pnet/crypto.d.ts.map +0 -1
  234. package/dist/src/pnet/crypto.js +0 -60
  235. package/dist/src/pnet/crypto.js.map +0 -1
  236. package/dist/src/pnet/errors.d.ts +0 -6
  237. package/dist/src/pnet/errors.d.ts.map +0 -1
  238. package/dist/src/pnet/errors.js +0 -6
  239. package/dist/src/pnet/errors.js.map +0 -1
  240. package/dist/src/pnet/index.d.ts +0 -31
  241. package/dist/src/pnet/index.d.ts.map +0 -1
  242. package/dist/src/pnet/index.js +0 -97
  243. package/dist/src/pnet/index.js.map +0 -1
  244. package/dist/src/pnet/key-generator.d.ts +0 -11
  245. package/dist/src/pnet/key-generator.d.ts.map +0 -1
  246. package/dist/src/pnet/key-generator.js +0 -22
  247. package/dist/src/pnet/key-generator.js.map +0 -1
  248. package/dist/src/upnp-nat/index.d.ts +0 -71
  249. package/dist/src/upnp-nat/index.d.ts.map +0 -1
  250. package/dist/src/upnp-nat/index.js +0 -136
  251. package/dist/src/upnp-nat/index.js.map +0 -1
  252. package/dist/src/utils/peer-job-queue.d.ts +0 -33
  253. package/dist/src/utils/peer-job-queue.d.ts.map +0 -1
  254. package/dist/src/utils/peer-job-queue.js +0 -82
  255. package/dist/src/utils/peer-job-queue.js.map +0 -1
  256. package/dist/typedoc-urls.json +0 -71
  257. package/src/autonat/constants.ts +0 -19
  258. package/src/autonat/index.ts +0 -597
  259. package/src/autonat/pb/index.proto +0 -35
  260. package/src/autonat/pb/index.ts +0 -320
  261. package/src/circuit-relay/constants.ts +0 -72
  262. package/src/circuit-relay/index.ts +0 -59
  263. package/src/circuit-relay/pb/index.proto +0 -67
  264. package/src/circuit-relay/pb/index.ts +0 -539
  265. package/src/circuit-relay/server/advert-service.ts +0 -108
  266. package/src/circuit-relay/server/index.ts +0 -443
  267. package/src/circuit-relay/server/reservation-store.ts +0 -116
  268. package/src/circuit-relay/server/reservation-voucher.ts +0 -51
  269. package/src/circuit-relay/transport/discovery.ts +0 -136
  270. package/src/circuit-relay/transport/index.ts +0 -396
  271. package/src/circuit-relay/transport/listener.ts +0 -97
  272. package/src/circuit-relay/transport/reservation-store.ts +0 -312
  273. package/src/circuit-relay/utils.ts +0 -136
  274. package/src/dcutr/dcutr.ts +0 -378
  275. package/src/dcutr/index.ts +0 -102
  276. package/src/dcutr/pb/message.proto +0 -12
  277. package/src/dcutr/pb/message.ts +0 -96
  278. package/src/dcutr/utils.ts +0 -33
  279. package/src/fetch/README.md +0 -41
  280. package/src/fetch/constants.ts +0 -3
  281. package/src/fetch/index.ts +0 -315
  282. package/src/fetch/pb/proto.proto +0 -15
  283. package/src/fetch/pb/proto.ts +0 -153
  284. package/src/identify/README.md +0 -13
  285. package/src/identify/consts.ts +0 -12
  286. package/src/identify/identify.ts +0 -561
  287. package/src/identify/index.ts +0 -90
  288. package/src/identify/pb/message.proto +0 -30
  289. package/src/identify/pb/message.ts +0 -126
  290. package/src/insecure/index.ts +0 -138
  291. package/src/insecure/pb/proto.proto +0 -18
  292. package/src/insecure/pb/proto.ts +0 -161
  293. package/src/ping/constants.ts +0 -15
  294. package/src/ping/index.ts +0 -170
  295. package/src/pnet/README.md +0 -68
  296. package/src/pnet/crypto.ts +0 -67
  297. package/src/pnet/errors.ts +0 -5
  298. package/src/pnet/index.ts +0 -126
  299. package/src/pnet/key-generator.ts +0 -23
  300. package/src/upnp-nat/index.ts +0 -212
  301. package/src/utils/peer-job-queue.ts +0 -119
@@ -1,60 +0,0 @@
1
- import { logger } from '@libp2p/logger';
2
- import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
3
- import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
4
- import xsalsa20 from 'xsalsa20';
5
- import * as Errors from './errors.js';
6
- import { KEY_LENGTH } from './key-generator.js';
7
- const log = logger('libp2p:pnet');
8
- /**
9
- * Creates a stream iterable to encrypt messages in a private network
10
- */
11
- export function createBoxStream(nonce, psk) {
12
- const xor = xsalsa20(nonce, psk);
13
- return (source) => (async function* () {
14
- for await (const chunk of source) {
15
- yield Uint8Array.from(xor.update(chunk.slice()));
16
- }
17
- })();
18
- }
19
- /**
20
- * Creates a stream iterable to decrypt messages in a private network
21
- */
22
- export function createUnboxStream(nonce, psk) {
23
- return (source) => (async function* () {
24
- const xor = xsalsa20(nonce, psk);
25
- log.trace('Decryption enabled');
26
- for await (const chunk of source) {
27
- yield Uint8Array.from(xor.update(chunk.slice()));
28
- }
29
- })();
30
- }
31
- /**
32
- * Decode the version 1 psk from the given Uint8Array
33
- */
34
- export function decodeV1PSK(pskBuffer) {
35
- try {
36
- // This should pull from multibase/multicodec to allow for
37
- // more encoding flexibility. Ideally we'd consume the codecs
38
- // from the buffer line by line to evaluate the next line
39
- // programmatically instead of making assumptions about the
40
- // encodings of each line.
41
- const metadata = uint8ArrayToString(pskBuffer).split(/(?:\r\n|\r|\n)/g);
42
- const pskTag = metadata.shift();
43
- const codec = metadata.shift();
44
- const pskString = metadata.shift();
45
- const psk = uint8ArrayFromString(pskString ?? '', 'base16');
46
- if (psk.byteLength !== KEY_LENGTH) {
47
- throw new Error(Errors.INVALID_PSK);
48
- }
49
- return {
50
- tag: pskTag,
51
- codecName: codec,
52
- psk
53
- };
54
- }
55
- catch (err) {
56
- log.error(err);
57
- throw new Error(Errors.INVALID_PSK);
58
- }
59
- }
60
- //# sourceMappingURL=crypto.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/pnet/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,M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AAqB;IAChD,IAAI;QACF,0DAA0D;QAC1D,6DAA6D;QAC7D,yDAAyD;QACzD,2DAA2D;QAC3D,0BAA0B;QAC1B,MAAM,QAAQ,GAAG,kBAAkB,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAA;QACvE,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAA;QAC/B,MAAM,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAA;QAC9B,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,EAAE,CAAA;QAClC,MAAM,GAAG,GAAG,oBAAoB,CAAC,SAAS,IAAI,EAAE,EAAE,QAAQ,CAAC,CAAA;QAE3D,IAAI,GAAG,CAAC,UAAU,KAAK,UAAU,EAAE;YACjC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;SACpC;QAED,OAAO;YACL,GAAG,EAAE,MAAM;YACX,SAAS,EAAE,KAAK;YAChB,GAAG;SACJ,CAAA;KACF;IAAC,OAAO,GAAQ,EAAE;QACjB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;QACd,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;KACpC;AACH,CAAC"}
@@ -1,6 +0,0 @@
1
- export declare const INVALID_PEER = "Not a valid peer connection";
2
- export declare const INVALID_PSK = "Your private shared key is invalid";
3
- export declare const NO_LOCAL_ID = "No local private key provided";
4
- export declare const NO_HANDSHAKE_CONNECTION = "No connection for the handshake provided";
5
- export declare const STREAM_ENDED = "Stream ended prematurely";
6
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/pnet/errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,gCAAgC,CAAA;AACzD,eAAO,MAAM,WAAW,uCAAuC,CAAA;AAC/D,eAAO,MAAM,WAAW,kCAAkC,CAAA;AAC1D,eAAO,MAAM,uBAAuB,6CAA6C,CAAA;AACjF,eAAO,MAAM,YAAY,6BAA6B,CAAA"}
@@ -1,6 +0,0 @@
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
@@ -1 +0,0 @@
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,31 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Connection protection management for libp2p leveraging PSK encryption via XSalsa20.
5
- *
6
- * @example
7
- *
8
- * ```typescript
9
- * import { createLibp2p } from 'libp2p'
10
- * import { preSharedKey, generateKey } from 'libp2p/pnet'
11
- *
12
- * // Create a Uint8Array and write the swarm key to it
13
- * const swarmKey = new Uint8Array(95)
14
- * generateKey(swarmKey)
15
- *
16
- * const node = await createLibp2p({
17
- * // ...other options
18
- * connectionProtector: preSharedKey({
19
- * psk: swarmKey
20
- * })
21
- * })
22
- * ```
23
- */
24
- import type { ConnectionProtector } from '@libp2p/interface/connection';
25
- export { generateKey } from './key-generator.js';
26
- export interface ProtectorInit {
27
- enabled?: boolean;
28
- psk: Uint8Array;
29
- }
30
- export declare function preSharedKey(init: ProtectorInit): () => ConnectionProtector;
31
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pnet/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAiBH,OAAO,KAAK,EAAE,mBAAmB,EAAuB,MAAM,8BAA8B,CAAA;AAI5F,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAEhD,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE,UAAU,CAAA;CAChB;AA2ED,wBAAgB,YAAY,CAAE,IAAI,EAAE,aAAa,GAAG,MAAM,mBAAmB,CAE5E"}
@@ -1,97 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Connection protection management for libp2p leveraging PSK encryption via XSalsa20.
5
- *
6
- * @example
7
- *
8
- * ```typescript
9
- * import { createLibp2p } from 'libp2p'
10
- * import { preSharedKey, generateKey } from 'libp2p/pnet'
11
- *
12
- * // Create a Uint8Array and write the swarm key to it
13
- * const swarmKey = new Uint8Array(95)
14
- * generateKey(swarmKey)
15
- *
16
- * const node = await createLibp2p({
17
- * // ...other options
18
- * connectionProtector: preSharedKey({
19
- * psk: swarmKey
20
- * })
21
- * })
22
- * ```
23
- */
24
- import { randomBytes } from '@libp2p/crypto';
25
- import { CodeError } from '@libp2p/interface/errors';
26
- import { logger } from '@libp2p/logger';
27
- import { handshake } from 'it-handshake';
28
- import map from 'it-map';
29
- import { duplexPair } from 'it-pair/duplex';
30
- import { pipe } from 'it-pipe';
31
- import { codes } from '../errors.js';
32
- import { createBoxStream, createUnboxStream, decodeV1PSK } from './crypto.js';
33
- import * as Errors from './errors.js';
34
- import { NONCE_LENGTH } from './key-generator.js';
35
- const log = logger('libp2p:pnet');
36
- export { generateKey } from './key-generator.js';
37
- class PreSharedKeyConnectionProtector {
38
- tag;
39
- psk;
40
- enabled;
41
- /**
42
- * Takes a Private Shared Key (psk) and provides a `protect` method
43
- * for wrapping existing connections in a private encryption stream.
44
- */
45
- constructor(init) {
46
- this.enabled = init.enabled !== false;
47
- if (this.enabled) {
48
- const decodedPSK = decodeV1PSK(init.psk);
49
- this.psk = decodedPSK.psk;
50
- this.tag = decodedPSK.tag ?? '';
51
- }
52
- else {
53
- this.psk = new Uint8Array();
54
- this.tag = '';
55
- }
56
- }
57
- /**
58
- * Takes a given Connection and creates a private encryption stream
59
- * between its two peers from the PSK the Protector instance was
60
- * created with.
61
- */
62
- async protect(connection) {
63
- if (!this.enabled) {
64
- return connection;
65
- }
66
- if (connection == null) {
67
- throw new CodeError(Errors.NO_HANDSHAKE_CONNECTION, codes.ERR_INVALID_PARAMETERS);
68
- }
69
- // Exchange nonces
70
- log('protecting the connection');
71
- const localNonce = randomBytes(NONCE_LENGTH);
72
- const shake = handshake(connection);
73
- shake.write(localNonce);
74
- const result = await shake.reader.next(NONCE_LENGTH);
75
- if (result.value == null) {
76
- throw new CodeError(Errors.STREAM_ENDED, codes.ERR_INVALID_PARAMETERS);
77
- }
78
- const remoteNonce = result.value.slice();
79
- shake.rest();
80
- // Create the boxing/unboxing pipe
81
- log('exchanged nonces');
82
- const [internal, external] = duplexPair();
83
- pipe(external,
84
- // Encrypt all outbound traffic
85
- createBoxStream(localNonce, this.psk), shake.stream, (source) => map(source, (buf) => buf.subarray()),
86
- // Decrypt all inbound traffic
87
- createUnboxStream(remoteNonce, this.psk), external).catch(log.error);
88
- return {
89
- ...connection,
90
- ...internal
91
- };
92
- }
93
- }
94
- export function preSharedKey(init) {
95
- return () => new PreSharedKeyConnectionProtector(init);
96
- }
97
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pnet/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAA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AG,EAAE,CAAC,IAAI,+BAA+B,CAAC,IAAI,CAAC,CAAA;AACxD,CAAC"}
@@ -1,11 +0,0 @@
1
- /// <reference types="node" />
2
- /**
3
- * Generates a PSK that can be used in a libp2p-pnet private network
4
- *
5
- * @param {Uint8Array | NodeJS.WriteStream} bytes - An object to write the psk into
6
- * @returns {void}
7
- */
8
- export declare function generateKey(bytes: Uint8Array | NodeJS.WriteStream): void;
9
- export declare const NONCE_LENGTH = 24;
10
- export declare const KEY_LENGTH = 32;
11
- //# sourceMappingURL=key-generator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"key-generator.d.ts","sourceRoot":"","sources":["../../../src/pnet/key-generator.ts"],"names":[],"mappings":";AAIA;;;;;GAKG;AACH,wBAAgB,WAAW,CAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC,WAAW,GAAG,IAAI,CASzE;AAED,eAAO,MAAM,YAAY,KAAK,CAAA;AAC9B,eAAO,MAAM,UAAU,KAAK,CAAA"}
@@ -1,22 +0,0 @@
1
- import { randomBytes } from '@libp2p/crypto';
2
- import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
3
- import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
4
- /**
5
- * Generates a PSK that can be used in a libp2p-pnet private network
6
- *
7
- * @param {Uint8Array | NodeJS.WriteStream} bytes - An object to write the psk into
8
- * @returns {void}
9
- */
10
- export function generateKey(bytes) {
11
- const psk = uint8ArrayToString(randomBytes(KEY_LENGTH), 'base16');
12
- const key = uint8ArrayFromString('/key/swarm/psk/1.0.0/\n/base16/\n' + psk);
13
- if (bytes instanceof Uint8Array) {
14
- bytes.set(key);
15
- }
16
- else {
17
- bytes.write(key);
18
- }
19
- }
20
- export const NONCE_LENGTH = 24;
21
- export const KEY_LENGTH = 32;
22
- //# sourceMappingURL=key-generator.js.map
@@ -1 +0,0 @@
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,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAEtE;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAE,KAAsC;IACjE,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,IAAI,KAAK,YAAY,UAAU,EAAE;QAC/B,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;KACf;SAAM;QACL,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;KACjB;AACH,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAA;AAC9B,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAA"}
@@ -1,71 +0,0 @@
1
- import { type NatAPI } from '@achingbrain/nat-port-mapper';
2
- import type { PeerId } from '@libp2p/interface/peer-id';
3
- import type { Startable } from '@libp2p/interface/startable';
4
- import type { AddressManager } from '@libp2p/interface-internal/address-manager';
5
- import type { TransportManager } from '@libp2p/interface-internal/transport-manager';
6
- export interface PMPOptions {
7
- /**
8
- * Whether to enable PMP as well as UPnP
9
- */
10
- enabled?: boolean;
11
- }
12
- export interface UPnPNATInit {
13
- /**
14
- * Pass a value to use instead of auto-detection
15
- */
16
- externalAddress?: string;
17
- /**
18
- * Pass a value to use instead of auto-detection
19
- */
20
- localAddress?: string;
21
- /**
22
- * A string value to use for the port mapping description on the gateway
23
- */
24
- description?: string;
25
- /**
26
- * How long UPnP port mappings should last for in seconds (minimum 1200)
27
- */
28
- ttl?: number;
29
- /**
30
- * Whether to automatically refresh UPnP port mappings when their TTL is reached
31
- */
32
- keepAlive?: boolean;
33
- /**
34
- * Pass a value to use instead of auto-detection
35
- */
36
- gateway?: string;
37
- }
38
- export interface UPnPNATComponents {
39
- peerId: PeerId;
40
- transportManager: TransportManager;
41
- addressManager: AddressManager;
42
- }
43
- declare class UPnPNAT implements Startable {
44
- private readonly components;
45
- private readonly externalAddress?;
46
- private readonly localAddress?;
47
- private readonly description;
48
- private readonly ttl;
49
- private readonly keepAlive;
50
- private readonly gateway?;
51
- private started;
52
- private client?;
53
- constructor(components: UPnPNATComponents, init: UPnPNATInit);
54
- isStarted(): boolean;
55
- start(): void;
56
- /**
57
- * Attempt to use uPnP to configure port mapping using the current gateway.
58
- *
59
- * Run after start to ensure the transport manager has all addresses configured.
60
- */
61
- afterStart(): void;
62
- _start(): Promise<void>;
63
- _getClient(): NatAPI;
64
- /**
65
- * Stops the NAT manager
66
- */
67
- stop(): Promise<void>;
68
- }
69
- export declare function uPnPNATService(init?: UPnPNATInit): (components: UPnPNATComponents) => UPnPNAT;
70
- export {};
71
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/upnp-nat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,MAAM,EAAE,MAAM,8BAA8B,CAAA;AASnE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAA;AAChF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8CAA8C,CAAA;AASpF,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;IAEnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAA;IACd,gBAAgB,EAAE,gBAAgB,CAAA;IAClC,cAAc,EAAE,cAAc,CAAA;CAC/B;AAED,cAAM,OAAQ,YAAW,SAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;IAC9C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAQ;IACzC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAQ;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAQ;IACpC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAQ;IACjC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,MAAM,CAAC,CAAQ;gBAEV,UAAU,EAAE,iBAAiB,EAAE,IAAI,EAAE,WAAW;IAgB7D,SAAS,IAAK,OAAO;IAIrB,KAAK,IAAK,IAAI;IAId;;;;OAIG;IACH,UAAU,IAAK,IAAI;IAcb,MAAM,IAAK,OAAO,CAAC,IAAI,CAAC;IAuD9B,UAAU,IAAK,MAAM;IAerB;;OAEG;IACG,IAAI,IAAK,OAAO,CAAC,IAAI,CAAC;CAY7B;AAED,wBAAgB,cAAc,CAAE,IAAI,GAAE,WAAgB,GAAG,CAAC,UAAU,EAAE,iBAAiB,KAAK,OAAO,CAIlG"}
@@ -1,136 +0,0 @@
1
- import { upnpNat } from '@achingbrain/nat-port-mapper';
2
- import { CodeError } from '@libp2p/interface/errors';
3
- import { logger } from '@libp2p/logger';
4
- import { isLoopback } from '@libp2p/utils/multiaddr/is-loopback';
5
- import { fromNodeAddress } from '@multiformats/multiaddr';
6
- import isPrivateIp from 'private-ip';
7
- import { isBrowser } from 'wherearewe';
8
- import { codes } from '../errors.js';
9
- import * as pkg from '../version.js';
10
- const log = logger('libp2p:upnp-nat');
11
- const DEFAULT_TTL = 7200;
12
- function highPort(min = 1024, max = 65535) {
13
- return Math.floor(Math.random() * (max - min + 1) + min);
14
- }
15
- class UPnPNAT {
16
- components;
17
- externalAddress;
18
- localAddress;
19
- description;
20
- ttl;
21
- keepAlive;
22
- gateway;
23
- started;
24
- client;
25
- constructor(components, init) {
26
- this.components = components;
27
- this.started = false;
28
- this.externalAddress = init.externalAddress;
29
- this.localAddress = init.localAddress;
30
- this.description = init.description ?? `${pkg.name}@${pkg.version} ${this.components.peerId.toString()}`;
31
- this.ttl = init.ttl ?? DEFAULT_TTL;
32
- this.keepAlive = init.keepAlive ?? true;
33
- this.gateway = init.gateway;
34
- if (this.ttl < DEFAULT_TTL) {
35
- throw new CodeError(`NatManager ttl should be at least ${DEFAULT_TTL} seconds`, codes.ERR_INVALID_PARAMETERS);
36
- }
37
- }
38
- isStarted() {
39
- return this.started;
40
- }
41
- start() {
42
- // #TODO: is there a way to remove this? Seems like a hack
43
- }
44
- /**
45
- * Attempt to use uPnP to configure port mapping using the current gateway.
46
- *
47
- * Run after start to ensure the transport manager has all addresses configured.
48
- */
49
- afterStart() {
50
- if (isBrowser || this.started) {
51
- return;
52
- }
53
- this.started = true;
54
- // done async to not slow down startup
55
- void this._start().catch((err) => {
56
- // hole punching errors are non-fatal
57
- log.error(err);
58
- });
59
- }
60
- async _start() {
61
- const addrs = this.components.transportManager.getAddrs();
62
- for (const addr of addrs) {
63
- // try to open uPnP ports for each thin waist address
64
- const { family, host, port, transport } = addr.toOptions();
65
- if (!addr.isThinWaistAddress() || transport !== 'tcp') {
66
- // only bare tcp addresses
67
- // eslint-disable-next-line no-continue
68
- continue;
69
- }
70
- if (isLoopback(addr)) {
71
- // eslint-disable-next-line no-continue
72
- continue;
73
- }
74
- if (family !== 4) {
75
- // ignore ipv6
76
- // eslint-disable-next-line no-continue
77
- continue;
78
- }
79
- const client = this._getClient();
80
- const publicIp = this.externalAddress ?? await client.externalIp();
81
- const isPrivate = isPrivateIp(publicIp);
82
- if (isPrivate === true) {
83
- throw new Error(`${publicIp} is private - please set config.nat.externalIp to an externally routable IP or ensure you are not behind a double NAT`);
84
- }
85
- if (isPrivate == null) {
86
- throw new Error(`${publicIp} is not an IP address`);
87
- }
88
- const publicPort = highPort();
89
- log(`opening uPnP connection from ${publicIp}:${publicPort} to ${host}:${port}`);
90
- await client.map({
91
- publicPort,
92
- localPort: port,
93
- localAddress: this.localAddress,
94
- protocol: transport.toUpperCase() === 'TCP' ? 'TCP' : 'UDP'
95
- });
96
- this.components.addressManager.addObservedAddr(fromNodeAddress({
97
- family: 4,
98
- address: publicIp,
99
- port: publicPort
100
- }, transport));
101
- }
102
- }
103
- _getClient() {
104
- if (this.client != null) {
105
- return this.client;
106
- }
107
- this.client = upnpNat({
108
- description: this.description,
109
- ttl: this.ttl,
110
- keepAlive: this.keepAlive,
111
- gateway: this.gateway
112
- });
113
- return this.client;
114
- }
115
- /**
116
- * Stops the NAT manager
117
- */
118
- async stop() {
119
- if (isBrowser || this.client == null) {
120
- return;
121
- }
122
- try {
123
- await this.client.close();
124
- this.client = undefined;
125
- }
126
- catch (err) {
127
- log.error(err);
128
- }
129
- }
130
- }
131
- export function uPnPNATService(init = {}) {
132
- return (components) => {
133
- return new UPnPNAT(components, init);
134
- };
135
- }
136
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/upnp-nat/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAe,MAAM,8BAA8B,CAAA;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB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C,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;QAEF,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI;QACR,IAAI,SAAS,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,EAAE;YACpC,OAAM;SACP;QAED,IAAI;YACF,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAA;YACzB,IAAI,CAAC,MAAM,GAAG,SAAS,CAAA;SACxB;QAAC,OAAO,GAAQ,EAAE;YACjB,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;SACf;IACH,CAAC;CACF;AAED,MAAM,UAAU,cAAc,CAAE,OAAoB,EAAE;IACpD,OAAO,CAAC,UAA6B,EAAE,EAAE;QACvC,OAAO,IAAI,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,CAAA;IACtC,CAAC,CAAA;AACH,CAAC"}
@@ -1,33 +0,0 @@
1
- import PQueue from 'p-queue';
2
- import type { PeerId } from '@libp2p/interface/peer-id';
3
- import type { QueueAddOptions, Options, Queue } from 'p-queue';
4
- interface RunFunction {
5
- (): Promise<unknown>;
6
- }
7
- export interface PeerPriorityQueueOptions extends QueueAddOptions {
8
- peerId: PeerId;
9
- }
10
- /**
11
- * Port of https://github.com/sindresorhus/p-queue/blob/main/source/priority-queue.ts
12
- * that adds support for filtering jobs by peer id
13
- */
14
- declare class PeerPriorityQueue implements Queue<RunFunction, PeerPriorityQueueOptions> {
15
- #private;
16
- enqueue(run: RunFunction, options?: Partial<PeerPriorityQueueOptions>): void;
17
- dequeue(): RunFunction | undefined;
18
- filter(options: Readonly<Partial<PeerPriorityQueueOptions>>): RunFunction[];
19
- get size(): number;
20
- }
21
- /**
22
- * Extends PQueue to add support for querying queued jobs by peer id
23
- */
24
- export declare class PeerJobQueue extends PQueue<PeerPriorityQueue, PeerPriorityQueueOptions> {
25
- constructor(options?: Options<PeerPriorityQueue, PeerPriorityQueueOptions>);
26
- /**
27
- * Returns true if this queue has a job for the passed peer id that has not yet
28
- * started to run
29
- */
30
- hasJob(peerId: PeerId): boolean;
31
- }
32
- export {};
33
- //# sourceMappingURL=peer-job-queue.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"peer-job-queue.d.ts","sourceRoot":"","sources":["../../../src/utils/peer-job-queue.ts"],"names":[],"mappings":"AAGA,OAAO,MAAM,MAAM,SAAS,CAAA;AAE5B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAuB9D,UAAU,WAAW;IAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAA;CAAE;AAE9C,MAAM,WAAW,wBAAyB,SAAQ,eAAe;IAC/D,MAAM,EAAE,MAAM,CAAA;CACf;AAQD;;;GAGG;AACH,cAAM,iBAAkB,YAAW,KAAK,CAAC,WAAW,EAAE,wBAAwB,CAAC;;IAG7E,OAAO,CAAE,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,wBAAwB,CAAC,GAAG,IAAI;IA0B7E,OAAO,IAAK,WAAW,GAAG,SAAS;IAKnC,MAAM,CAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC,GAAG,WAAW,EAAE;IAc5E,IAAI,IAAI,IAAK,MAAM,CAElB;CACF;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,MAAM,CAAC,iBAAiB,EAAE,wBAAwB,CAAC;gBACtE,OAAO,GAAE,OAAO,CAAC,iBAAiB,EAAE,wBAAwB,CAAM;IAO/E;;;OAGG;IACH,MAAM,CAAE,MAAM,EAAE,MAAM,GAAG,OAAO;CAKjC"}
@@ -1,82 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
- import { CodeError } from '@libp2p/interface/errors';
3
- import PQueue from 'p-queue';
4
- import { codes } from '../errors.js';
5
- // Port of lower_bound from https://en.cppreference.com/w/cpp/algorithm/lower_bound
6
- // Used to compute insertion index to keep queue sorted after insertion
7
- function lowerBound(array, value, comparator) {
8
- let first = 0;
9
- let count = array.length;
10
- while (count > 0) {
11
- const step = Math.trunc(count / 2);
12
- let it = first + step;
13
- if (comparator(array[it], value) <= 0) {
14
- first = ++it;
15
- count -= step + 1;
16
- }
17
- else {
18
- count = step;
19
- }
20
- }
21
- return first;
22
- }
23
- /**
24
- * Port of https://github.com/sindresorhus/p-queue/blob/main/source/priority-queue.ts
25
- * that adds support for filtering jobs by peer id
26
- */
27
- class PeerPriorityQueue {
28
- #queue = [];
29
- enqueue(run, options) {
30
- const peerId = options?.peerId;
31
- const priority = options?.priority ?? 0;
32
- if (peerId == null) {
33
- throw new CodeError('missing peer id', codes.ERR_INVALID_PARAMETERS);
34
- }
35
- const element = {
36
- priority,
37
- peerId,
38
- run
39
- };
40
- if (this.size > 0 && this.#queue[this.size - 1].priority >= priority) {
41
- this.#queue.push(element);
42
- return;
43
- }
44
- const index = lowerBound(this.#queue, element, (a, b) => b.priority - a.priority);
45
- this.#queue.splice(index, 0, element);
46
- }
47
- dequeue() {
48
- const item = this.#queue.shift();
49
- return item?.run;
50
- }
51
- filter(options) {
52
- if (options.peerId != null) {
53
- const peerId = options.peerId;
54
- return this.#queue.filter((element) => peerId.equals(element.peerId)).map((element) => element.run);
55
- }
56
- return this.#queue.filter((element) => element.priority === options.priority).map((element) => element.run);
57
- }
58
- get size() {
59
- return this.#queue.length;
60
- }
61
- }
62
- /**
63
- * Extends PQueue to add support for querying queued jobs by peer id
64
- */
65
- export class PeerJobQueue extends PQueue {
66
- constructor(options = {}) {
67
- super({
68
- ...options,
69
- queueClass: PeerPriorityQueue
70
- });
71
- }
72
- /**
73
- * Returns true if this queue has a job for the passed peer id that has not yet
74
- * started to run
75
- */
76
- hasJob(peerId) {
77
- return this.sizeBy({
78
- peerId
79
- }) > 0;
80
- }
81
- }
82
- //# sourceMappingURL=peer-job-queue.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"peer-job-queue.js","sourceRoot":"","sources":["../../../src/utils/peer-job-queue.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAE7D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AACpD,OAAO,MAAM,MAAM,SAAS,CAAA;AAC5B,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAIpC,mFAAmF;AACnF,uEAAuE;AACvE,SAAS,UAAU,CAAK,KAAmB,EAAE,KAAQ,EAAE,UAAkC;IACvF,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,KAAK,GAAG,KAAK,CAAC,MAAM,CAAA;IAExB,OAAO,KAAK,GAAG,CAAC,EAAE;QAChB,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAA;QAClC,IAAI,EAAE,GAAG,KAAK,GAAG,IAAI,CAAA;QAErB,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAE,EAAE,KAAK,CAAC,IAAI,CAAC,EAAE;YACtC,KAAK,GAAG,EAAE,EAAE,CAAA;YACZ,KAAK,IAAI,IAAI,GAAG,CAAC,CAAA;SAClB;aAAM;YACL,KAAK,GAAG,IAAI,CAAA;SACb;KACF;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AAcD;;;GAGG;AACH,MAAM,iBAAiB;IACZ,MAAM,GAAc,EAAE,CAAA;IAE/B,OAAO,CAAE,GAAgB,EAAE,OAA2C;QACpE,MAAM,MAAM,GAAG,OAAO,EAAE,MAAM,CAAA;QAC9B,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,CAAC,CAAA;QAEvC,IAAI,MAAM,IAAI,IAAI,EAAE;YAClB,MAAM,IAAI,SAAS,CAAC,iBAAiB,EAAE,KAAK,CAAC,sBAAsB,CAAC,CAAA;SACrE;QAED,MAAM,OAAO,GAAY;YACvB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