@libp2p/utils 6.7.2 → 7.0.0-55b7e5fea

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 (160) hide show
  1. package/README.md +16 -1
  2. package/dist/index.min.js +7 -1
  3. package/dist/index.min.js.map +4 -4
  4. package/dist/src/abstract-message-stream.d.ts +129 -0
  5. package/dist/src/abstract-message-stream.d.ts.map +1 -0
  6. package/dist/src/abstract-message-stream.js +393 -0
  7. package/dist/src/abstract-message-stream.js.map +1 -0
  8. package/dist/src/abstract-multiaddr-connection.d.ts +26 -0
  9. package/dist/src/abstract-multiaddr-connection.d.ts.map +1 -0
  10. package/dist/src/abstract-multiaddr-connection.js +66 -0
  11. package/dist/src/abstract-multiaddr-connection.js.map +1 -0
  12. package/dist/src/abstract-stream-muxer.d.ts +53 -0
  13. package/dist/src/abstract-stream-muxer.d.ts.map +1 -0
  14. package/dist/src/abstract-stream-muxer.js +169 -0
  15. package/dist/src/abstract-stream-muxer.js.map +1 -0
  16. package/dist/src/abstract-stream.d.ts +14 -130
  17. package/dist/src/abstract-stream.d.ts.map +1 -1
  18. package/dist/src/abstract-stream.js +39 -321
  19. package/dist/src/abstract-stream.js.map +1 -1
  20. package/dist/src/errors.d.ts +8 -0
  21. package/dist/src/errors.d.ts.map +1 -1
  22. package/dist/src/errors.js +8 -0
  23. package/dist/src/errors.js.map +1 -1
  24. package/dist/src/get-thin-waist-addresses.browser.d.ts +1 -1
  25. package/dist/src/get-thin-waist-addresses.browser.d.ts.map +1 -1
  26. package/dist/src/get-thin-waist-addresses.browser.js +4 -3
  27. package/dist/src/get-thin-waist-addresses.browser.js.map +1 -1
  28. package/dist/src/get-thin-waist-addresses.d.ts +1 -1
  29. package/dist/src/get-thin-waist-addresses.d.ts.map +1 -1
  30. package/dist/src/get-thin-waist-addresses.js +7 -9
  31. package/dist/src/get-thin-waist-addresses.js.map +1 -1
  32. package/dist/src/index.d.ts +31 -1
  33. package/dist/src/index.d.ts.map +1 -1
  34. package/dist/src/index.js +31 -1
  35. package/dist/src/index.js.map +1 -1
  36. package/dist/src/length-prefixed-decoder.d.ts +37 -0
  37. package/dist/src/length-prefixed-decoder.d.ts.map +1 -0
  38. package/dist/src/length-prefixed-decoder.js +64 -0
  39. package/dist/src/length-prefixed-decoder.js.map +1 -0
  40. package/dist/src/message-queue.d.ts +61 -0
  41. package/dist/src/message-queue.d.ts.map +1 -0
  42. package/dist/src/message-queue.js +93 -0
  43. package/dist/src/message-queue.js.map +1 -0
  44. package/dist/src/mock-muxer.d.ts +57 -0
  45. package/dist/src/mock-muxer.d.ts.map +1 -0
  46. package/dist/src/mock-muxer.js +204 -0
  47. package/dist/src/mock-muxer.js.map +1 -0
  48. package/dist/src/mock-stream.d.ts +31 -0
  49. package/dist/src/mock-stream.d.ts.map +1 -0
  50. package/dist/src/mock-stream.js +69 -0
  51. package/dist/src/mock-stream.js.map +1 -0
  52. package/dist/src/multiaddr/get-net-config.d.ts +55 -0
  53. package/dist/src/multiaddr/get-net-config.d.ts.map +1 -0
  54. package/dist/src/multiaddr/get-net-config.js +54 -0
  55. package/dist/src/multiaddr/get-net-config.js.map +1 -0
  56. package/dist/src/multiaddr/index.d.ts +7 -0
  57. package/dist/src/multiaddr/index.d.ts.map +1 -0
  58. package/dist/src/multiaddr/index.js +7 -0
  59. package/dist/src/multiaddr/index.js.map +1 -0
  60. package/dist/src/multiaddr/is-global-unicast.d.ts.map +1 -1
  61. package/dist/src/multiaddr/is-global-unicast.js +8 -9
  62. package/dist/src/multiaddr/is-global-unicast.js.map +1 -1
  63. package/dist/src/multiaddr/is-link-local.d.ts.map +1 -1
  64. package/dist/src/multiaddr/is-link-local.js +11 -16
  65. package/dist/src/multiaddr/is-link-local.js.map +1 -1
  66. package/dist/src/multiaddr/is-loopback.d.ts.map +1 -1
  67. package/dist/src/multiaddr/is-loopback.js +12 -5
  68. package/dist/src/multiaddr/is-loopback.js.map +1 -1
  69. package/dist/src/multiaddr/is-network-address.d.ts.map +1 -1
  70. package/dist/src/multiaddr/is-network-address.js +4 -16
  71. package/dist/src/multiaddr/is-network-address.js.map +1 -1
  72. package/dist/src/multiaddr/is-private.d.ts.map +1 -1
  73. package/dist/src/multiaddr/is-private.js +9 -10
  74. package/dist/src/multiaddr/is-private.js.map +1 -1
  75. package/dist/src/multiaddr/utils.d.ts +5 -0
  76. package/dist/src/multiaddr/utils.d.ts.map +1 -0
  77. package/dist/src/multiaddr/utils.js +32 -0
  78. package/dist/src/multiaddr/utils.js.map +1 -0
  79. package/dist/src/multiaddr-connection-pair.d.ts +25 -0
  80. package/dist/src/multiaddr-connection-pair.d.ts.map +1 -0
  81. package/dist/src/multiaddr-connection-pair.js +103 -0
  82. package/dist/src/multiaddr-connection-pair.js.map +1 -0
  83. package/dist/src/queue/index.d.ts +3 -6
  84. package/dist/src/queue/index.d.ts.map +1 -1
  85. package/dist/src/queue/index.js +20 -4
  86. package/dist/src/queue/index.js.map +1 -1
  87. package/dist/src/rate-limiter.d.ts +1 -15
  88. package/dist/src/rate-limiter.d.ts.map +1 -1
  89. package/dist/src/rate-limiter.js +1 -14
  90. package/dist/src/rate-limiter.js.map +1 -1
  91. package/dist/src/stream-pair.d.ts +42 -0
  92. package/dist/src/stream-pair.d.ts.map +1 -0
  93. package/dist/src/stream-pair.js +40 -0
  94. package/dist/src/stream-pair.js.map +1 -0
  95. package/dist/src/stream-utils.d.ts +191 -0
  96. package/dist/src/stream-utils.d.ts.map +1 -0
  97. package/dist/src/stream-utils.js +371 -0
  98. package/dist/src/stream-utils.js.map +1 -0
  99. package/package.json +15 -162
  100. package/src/abstract-message-stream.ts +553 -0
  101. package/src/abstract-multiaddr-connection.ts +93 -0
  102. package/src/abstract-stream-muxer.ts +239 -0
  103. package/src/abstract-stream.ts +51 -464
  104. package/src/errors.ts +10 -0
  105. package/src/get-thin-waist-addresses.browser.ts +5 -4
  106. package/src/get-thin-waist-addresses.ts +8 -12
  107. package/src/index.ts +31 -1
  108. package/src/length-prefixed-decoder.ts +98 -0
  109. package/src/message-queue.ts +156 -0
  110. package/src/mock-muxer.ts +304 -0
  111. package/src/mock-stream.ts +101 -0
  112. package/src/multiaddr/get-net-config.ts +112 -0
  113. package/src/multiaddr/index.ts +6 -0
  114. package/src/multiaddr/is-global-unicast.ts +8 -11
  115. package/src/multiaddr/is-link-local.ts +11 -20
  116. package/src/multiaddr/is-loopback.ts +12 -7
  117. package/src/multiaddr/is-network-address.ts +4 -19
  118. package/src/multiaddr/is-private.ts +9 -14
  119. package/src/multiaddr/utils.ts +46 -0
  120. package/src/multiaddr-connection-pair.ts +147 -0
  121. package/src/queue/index.ts +24 -11
  122. package/src/rate-limiter.ts +3 -30
  123. package/src/stream-pair.ts +90 -0
  124. package/src/stream-utils.ts +866 -0
  125. package/dist/src/abort-options.d.ts +0 -7
  126. package/dist/src/abort-options.d.ts.map +0 -1
  127. package/dist/src/abort-options.js +0 -14
  128. package/dist/src/abort-options.js.map +0 -1
  129. package/dist/src/array-equals.d.ts +0 -24
  130. package/dist/src/array-equals.d.ts.map +0 -1
  131. package/dist/src/array-equals.js +0 -31
  132. package/dist/src/array-equals.js.map +0 -1
  133. package/dist/src/close-source.d.ts +0 -4
  134. package/dist/src/close-source.d.ts.map +0 -1
  135. package/dist/src/close-source.js +0 -11
  136. package/dist/src/close-source.js.map +0 -1
  137. package/dist/src/close.d.ts +0 -21
  138. package/dist/src/close.d.ts.map +0 -1
  139. package/dist/src/close.js +0 -49
  140. package/dist/src/close.js.map +0 -1
  141. package/dist/src/merge-options.d.ts +0 -7
  142. package/dist/src/merge-options.d.ts.map +0 -1
  143. package/dist/src/merge-options.js +0 -128
  144. package/dist/src/merge-options.js.map +0 -1
  145. package/dist/src/multiaddr/is-ip-based.d.ts +0 -6
  146. package/dist/src/multiaddr/is-ip-based.d.ts.map +0 -1
  147. package/dist/src/multiaddr/is-ip-based.js +0 -18
  148. package/dist/src/multiaddr/is-ip-based.js.map +0 -1
  149. package/dist/src/stream-to-ma-conn.d.ts +0 -23
  150. package/dist/src/stream-to-ma-conn.d.ts.map +0 -1
  151. package/dist/src/stream-to-ma-conn.js +0 -75
  152. package/dist/src/stream-to-ma-conn.js.map +0 -1
  153. package/dist/typedoc-urls.json +0 -147
  154. package/src/abort-options.ts +0 -20
  155. package/src/array-equals.ts +0 -34
  156. package/src/close-source.ts +0 -14
  157. package/src/close.ts +0 -65
  158. package/src/merge-options.ts +0 -161
  159. package/src/multiaddr/is-ip-based.ts +0 -21
  160. package/src/stream-to-ma-conn.ts +0 -106
@@ -1,147 +0,0 @@
1
- {
2
- "createTimeoutOptions": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.abort-options.createTimeoutOptions.html",
3
- "./abort-options:createTimeoutOptions": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.abort-options.createTimeoutOptions.html",
4
- "AbstractStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.abstract-stream.AbstractStream.html",
5
- "./abstract-stream:AbstractStream": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.abstract-stream.AbstractStream.html",
6
- "AbstractStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.abstract-stream.AbstractStreamInit.html",
7
- "./abstract-stream:AbstractStreamInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.abstract-stream.AbstractStreamInit.html",
8
- "AdaptiveTimeout": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.adaptive-timeout.AdaptiveTimeout.html",
9
- "./adaptive-timeout:AdaptiveTimeout": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.adaptive-timeout.AdaptiveTimeout.html",
10
- "AdaptiveTimeoutInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive-timeout.AdaptiveTimeoutInit.html",
11
- "./adaptive-timeout:AdaptiveTimeoutInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive-timeout.AdaptiveTimeoutInit.html",
12
- "AdaptiveTimeoutSignal": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive-timeout.AdaptiveTimeoutSignal.html",
13
- "./adaptive-timeout:AdaptiveTimeoutSignal": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive-timeout.AdaptiveTimeoutSignal.html",
14
- "GetTimeoutSignalOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive-timeout.GetTimeoutSignalOptions.html",
15
- "./adaptive-timeout:GetTimeoutSignalOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.adaptive-timeout.GetTimeoutSignalOptions.html",
16
- "DEFAULT_FAILURE_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_FAILURE_MULTIPLIER.html",
17
- "./adaptive-timeout:DEFAULT_FAILURE_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_FAILURE_MULTIPLIER.html",
18
- "DEFAULT_INTERVAL": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_INTERVAL.html",
19
- "./adaptive-timeout:DEFAULT_INTERVAL": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_INTERVAL.html",
20
- "DEFAULT_MAX_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_MAX_TIMEOUT.html",
21
- "./adaptive-timeout:DEFAULT_MAX_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_MAX_TIMEOUT.html",
22
- "DEFAULT_MIN_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_MIN_TIMEOUT.html",
23
- "./adaptive-timeout:DEFAULT_MIN_TIMEOUT": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_MIN_TIMEOUT.html",
24
- "DEFAULT_TIMEOUT_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_TIMEOUT_MULTIPLIER.html",
25
- "./adaptive-timeout:DEFAULT_TIMEOUT_MULTIPLIER": "https://libp2p.github.io/js-libp2p/variables/_libp2p_utils.adaptive-timeout.DEFAULT_TIMEOUT_MULTIPLIER.html",
26
- "arrayEquals": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.array-equals.arrayEquals.html",
27
- "./array-equals:arrayEquals": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.array-equals.arrayEquals.html",
28
- "SafelyCloseConnectionOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.close.SafelyCloseConnectionOptions.html",
29
- "./close:SafelyCloseConnectionOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.close.SafelyCloseConnectionOptions.html",
30
- "safelyCloseConnectionIfUnused": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseConnectionIfUnused.html",
31
- "./close:safelyCloseConnectionIfUnused": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseConnectionIfUnused.html",
32
- "safelyCloseStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseStream.html",
33
- "./close:safelyCloseStream": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close.safelyCloseStream.html",
34
- "closeSource": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close-source.closeSource.html",
35
- "./close-source:closeSource": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.close-source.closeSource.html",
36
- "DebouncedFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.debounce.DebouncedFunction.html",
37
- "./debounce:DebouncedFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.debounce.DebouncedFunction.html",
38
- "debounce": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.debounce.debounce.html",
39
- "./debounce:debounce": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.debounce.debounce.html",
40
- "BloomFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.BloomFilter.html",
41
- "CuckooFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.CuckooFilter.html",
42
- "ScalableCuckooFilter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.filters.ScalableCuckooFilter.html",
43
- "BloomFilterOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.BloomFilterOptions.html",
44
- "Bucket": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.Bucket.html",
45
- "CuckooFilterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.CuckooFilterInit.html",
46
- "Filter": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.Filter.html",
47
- "./filters:Filter": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.Filter.html",
48
- "Fingerprint": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.Fingerprint.html",
49
- "Hash": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.Hash.html",
50
- "ScalableCuckooFilterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.filters.ScalableCuckooFilterInit.html",
51
- "createBloomFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.filters.createBloomFilter.html",
52
- "createCuckooFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.filters.createCuckooFilter.html",
53
- "createScalableCuckooFilter": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.filters.createScalableCuckooFilter.html",
54
- "getThinWaistAddresses": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.get-thin-waist-addresses.getThinWaistAddresses.html",
55
- "./get-thin-waist-addresses:getThinWaistAddresses": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.get-thin-waist-addresses.getThinWaistAddresses.html",
56
- "isGlobalUnicastIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.global-unicast-ip.isGlobalUnicastIp.html",
57
- "./global-unicast-ip:isGlobalUnicastIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.global-unicast-ip.isGlobalUnicastIp.html",
58
- "ipPortToMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.ip-port-to-multiaddr.ipPortToMultiaddr.html",
59
- "./ip-port-to-multiaddr:ipPortToMultiaddr": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.ip-port-to-multiaddr.ipPortToMultiaddr.html",
60
- "isAsyncGenerator": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is-async-generator.isAsyncGenerator.html",
61
- "./is-async-generator:isAsyncGenerator": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is-async-generator.isAsyncGenerator.html",
62
- "isGenerator": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is-generator.isGenerator.html",
63
- "./is-generator:isGenerator": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is-generator.isGenerator.html",
64
- "isPromise": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is-promise.isPromise.html",
65
- "./is-promise:isPromise": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.is-promise.isPromise.html",
66
- "isLinkLocalIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.link-local-ip.isLinkLocalIp.html",
67
- "./link-local-ip:isLinkLocalIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.link-local-ip.isLinkLocalIp.html",
68
- "mergeOptions": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.merge-options.mergeOptions.html",
69
- "./merge-options:mergeOptions": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.merge-options.mergeOptions.html",
70
- "MovingAverage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.moving-average.MovingAverage.html",
71
- "./moving-average:MovingAverage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.moving-average.MovingAverage.html",
72
- "isGlobalUnicast": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-global-unicast.isGlobalUnicast.html",
73
- "./multiaddr/is-global-unicast:isGlobalUnicast": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-global-unicast.isGlobalUnicast.html",
74
- "isIpBased": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-ip-based.isIpBased.html",
75
- "./multiaddr/is-ip-based:isIpBased": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-ip-based.isIpBased.html",
76
- "isLinkLocal": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-link-local.isLinkLocal.html",
77
- "./multiaddr/is-link-local:isLinkLocal": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-link-local.isLinkLocal.html",
78
- "isLoopback": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-loopback.isLoopback.html",
79
- "./multiaddr/is-loopback:isLoopback": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-loopback.isLoopback.html",
80
- "isNetworkAddress": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-network-address.isNetworkAddress.html",
81
- "./multiaddr/is-network-address:isNetworkAddress": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-network-address.isNetworkAddress.html",
82
- "isPrivate": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-private.isPrivate.html",
83
- "./multiaddr/is-private:isPrivate": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.multiaddr_is-private.isPrivate.html",
84
- "PeerQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.peer-queue.PeerQueue.html",
85
- "./peer-queue:PeerQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.peer-queue.PeerQueue.html",
86
- "PeerQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.peer-queue.PeerQueueJobOptions.html",
87
- "./peer-queue:PeerQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.peer-queue.PeerQueueJobOptions.html",
88
- "PriorityQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.priority-queue.PriorityQueue.html",
89
- "./priority-queue:PriorityQueue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.priority-queue.PriorityQueue.html",
90
- "PriorityQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.priority-queue.PriorityQueueJobOptions.html",
91
- "./priority-queue:PriorityQueueJobOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.priority-queue.PriorityQueueJobOptions.html",
92
- "isPrivateIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.private-ip.isPrivateIp.html",
93
- "./private-ip:isPrivateIp": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.private-ip.isPrivateIp.html",
94
- "Queue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.Queue.html",
95
- "./queue:Queue": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.queue.Queue.html",
96
- "Comparator": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.Comparator.html",
97
- "./queue:Comparator": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.Comparator.html",
98
- "Job": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.Job.html",
99
- "JobMatcher": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobMatcher.html",
100
- "./queue:JobMatcher": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobMatcher.html",
101
- "JobRecipient": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobRecipient.html",
102
- "JobTimeline": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.JobTimeline.html",
103
- "QueueEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueEvents.html",
104
- "./queue:QueueEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueEvents.html",
105
- "QueueInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueInit.html",
106
- "./queue:QueueInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueInit.html",
107
- "QueueJobFailure": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobFailure.html",
108
- "./queue:QueueJobFailure": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobFailure.html",
109
- "QueueJobSuccess": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobSuccess.html",
110
- "./queue:QueueJobSuccess": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.QueueJobSuccess.html",
111
- "RunFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.RunFunction.html",
112
- "./queue:RunFunction": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.queue.RunFunction.html",
113
- "JobStatus": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.queue.JobStatus.html",
114
- "./queue:JobStatus": "https://libp2p.github.io/js-libp2p/types/_libp2p_utils.queue.JobStatus.html",
115
- "MemoryStorage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate-limiter.MemoryStorage.html",
116
- "./rate-limiter:MemoryStorage": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate-limiter.MemoryStorage.html",
117
- "RateLimiter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate-limiter.RateLimiter.html",
118
- "./rate-limiter:RateLimiter": "https://libp2p.github.io/js-libp2p/classes/_libp2p_utils.rate-limiter.RateLimiter.html",
119
- "GetKeySecDurationOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.GetKeySecDurationOptions.html",
120
- "./rate-limiter:GetKeySecDurationOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.GetKeySecDurationOptions.html",
121
- "RateLimiterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.RateLimiterInit.html",
122
- "./rate-limiter:RateLimiterInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.RateLimiterInit.html",
123
- "RateLimiterResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.RateLimiterResult.html",
124
- "./rate-limiter:RateLimiterResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.RateLimiterResult.html",
125
- "RateRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.RateRecord.html",
126
- "./rate-limiter:RateRecord": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.rate-limiter.RateRecord.html",
127
- "RepeatingTask": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.repeating-task.RepeatingTask.html",
128
- "./repeating-task:RepeatingTask": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.repeating-task.RepeatingTask.html",
129
- "RepeatingTaskOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.repeating-task.RepeatingTaskOptions.html",
130
- "./repeating-task:RepeatingTaskOptions": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.repeating-task.RepeatingTaskOptions.html",
131
- "repeatingTask": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.repeating-task.repeatingTask.html",
132
- "./repeating-task:repeatingTask": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.repeating-task.repeatingTask.html",
133
- "StreamProperties": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.stream-to-ma-conn.StreamProperties.html",
134
- "./stream-to-ma-conn:StreamProperties": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.stream-to-ma-conn.StreamProperties.html",
135
- "streamToMaConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.stream-to-ma-conn.streamToMaConnection.html",
136
- "./stream-to-ma-conn:streamToMaConnection": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.stream-to-ma-conn.streamToMaConnection.html",
137
- "CreateTrackedListInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked-list.CreateTrackedListInit.html",
138
- "./tracked-list:CreateTrackedListInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked-list.CreateTrackedListInit.html",
139
- "trackedList": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked-list.trackedList.html",
140
- "./tracked-list:trackedList": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked-list.trackedList.html",
141
- "CreateTrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked-map.CreateTrackedMapInit.html",
142
- "./tracked-map:CreateTrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked-map.CreateTrackedMapInit.html",
143
- "TrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked-map.TrackedMapInit.html",
144
- "./tracked-map:TrackedMapInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_utils.tracked-map.TrackedMapInit.html",
145
- "trackedMap": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked-map.trackedMap.html",
146
- "./tracked-map:trackedMap": "https://libp2p.github.io/js-libp2p/functions/_libp2p_utils.tracked-map.trackedMap.html"
147
- }
@@ -1,20 +0,0 @@
1
- import { anySignal } from 'any-signal'
2
- import { setMaxListeners } from 'main-event'
3
- import type { AbortOptions } from '@libp2p/interface'
4
- import type { ClearableSignal } from 'any-signal'
5
-
6
- export function createTimeoutOptions (timeout: number): AbortOptions
7
- export function createTimeoutOptions (timeout: number, ...existingSignals: AbortSignal[]): { signal: ClearableSignal }
8
- export function createTimeoutOptions (timeout: number, ...existingSignals: AbortSignal[]): AbortOptions {
9
- let signal = AbortSignal.timeout(timeout)
10
- setMaxListeners(Infinity, signal)
11
-
12
- if (existingSignals.length > 0) {
13
- signal = anySignal([signal, ...existingSignals])
14
- setMaxListeners(Infinity, signal)
15
- }
16
-
17
- return {
18
- signal
19
- }
20
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * @packageDocumentation
3
- *
4
- * Provides strategies ensure arrays are equivalent.
5
- *
6
- * @example
7
- *
8
- * ```typescript
9
- * import { arrayEquals } from '@libp2p/utils/array-equals'
10
- * import { multiaddr } from '@multformats/multiaddr'
11
- *
12
- * const ma1 = multiaddr('/ip4/127.0.0.1/tcp/9000'),
13
- * const ma2 = multiaddr('/ip4/82.41.53.1/tcp/9000')
14
- *
15
- * console.info(arrayEquals([ma1], [ma1])) // true
16
- * console.info(arrayEquals([ma1], [ma2])) // false
17
- * ```
18
- */
19
-
20
- /**
21
- * Verify if two arrays of non primitive types with the "equals" function are equal.
22
- * Compatible with multiaddr, peer-id and others.
23
- */
24
- export function arrayEquals (a: any[], b: any[]): boolean {
25
- const sort = (a: any, b: any): number => a.toString().localeCompare(b.toString())
26
-
27
- if (a.length !== b.length) {
28
- return false
29
- }
30
-
31
- b.sort(sort)
32
-
33
- return a.sort(sort).every((item, index) => b[index].equals(item))
34
- }
@@ -1,14 +0,0 @@
1
- import { getIterator } from 'get-iterator'
2
- import { isPromise } from './is-promise.js'
3
- import type { Logger } from '@libp2p/logger'
4
- import type { Source } from 'it-stream-types'
5
-
6
- export function closeSource (source: Source<unknown>, log: Logger): void {
7
- const res = getIterator(source).return?.()
8
-
9
- if (isPromise(res)) {
10
- res.catch(err => {
11
- log.error('could not cause iterator to return', err)
12
- })
13
- }
14
- }
package/src/close.ts DELETED
@@ -1,65 +0,0 @@
1
- import type { Connection, Stream, AbortOptions } from '@libp2p/interface'
2
-
3
- /**
4
- * Close the passed stream, falling back to aborting the stream if closing
5
- * cleanly fails.
6
- */
7
- export async function safelyCloseStream (stream?: Stream, options?: AbortOptions): Promise<void> {
8
- try {
9
- await stream?.close(options)
10
- } catch (err: any) {
11
- stream?.abort(err)
12
- }
13
- }
14
-
15
- /**
16
- * These are speculative protocols that are run automatically on connection open
17
- * so are usually not the reason the connection was opened.
18
- *
19
- * Consequently when requested it should be safe to close connections that only
20
- * have these protocol streams open.
21
- */
22
- const DEFAULT_CLOSABLE_PROTOCOLS = [
23
- // identify
24
- '/ipfs/id/1.0.0',
25
-
26
- // identify-push
27
- '/ipfs/id/push/1.0.0',
28
-
29
- // autonat
30
- '/libp2p/autonat/1.0.0',
31
-
32
- // dcutr
33
- '/libp2p/dcutr'
34
- ]
35
-
36
- export interface SafelyCloseConnectionOptions extends AbortOptions {
37
- /**
38
- * Only close the stream if it either has no protocol streams open or only
39
- * ones in this list.
40
- *
41
- * @default ['/ipfs/id/1.0.0']
42
- */
43
- closableProtocols?: string[]
44
- }
45
-
46
- /**
47
- * Close the passed connection if it has no streams, or only closable protocol
48
- * streams, falling back to aborting the connection if closing it cleanly fails.
49
- */
50
- export async function safelyCloseConnectionIfUnused (connection?: Connection, options?: SafelyCloseConnectionOptions): Promise<void> {
51
- const streamProtocols = connection?.streams?.map(stream => stream.protocol) ?? []
52
- const closableProtocols = options?.closableProtocols ?? DEFAULT_CLOSABLE_PROTOCOLS
53
-
54
- // if the connection has protocols not in the closable protocols list, do not
55
- // close the connection
56
- if (streamProtocols.filter(proto => proto != null && !closableProtocols.includes(proto)).length > 0) {
57
- return
58
- }
59
-
60
- try {
61
- await connection?.close(options)
62
- } catch (err: any) {
63
- connection?.abort(err)
64
- }
65
- }
@@ -1,161 +0,0 @@
1
- import isOptionObject from 'is-plain-obj'
2
-
3
- const { hasOwnProperty } = Object.prototype
4
- const { propertyIsEnumerable } = Object
5
- const defineProperty = (object: any, name: any, value: any): void => {
6
- Object.defineProperty(object, name, {
7
- value,
8
- writable: true,
9
- enumerable: true,
10
- configurable: true
11
- })
12
- }
13
-
14
- const globalThis = this
15
- const defaultMergeOptions = {
16
- concatArrays: false,
17
- ignoreUndefined: false
18
- }
19
-
20
- const getEnumerableOwnPropertyKeys = (value: any): any[] => {
21
- const keys = []
22
-
23
- for (const key in value) {
24
- if (hasOwnProperty.call(value, key)) {
25
- keys.push(key)
26
- }
27
- }
28
-
29
- /* istanbul ignore else */
30
- if (Object.getOwnPropertySymbols) {
31
- const symbols = Object.getOwnPropertySymbols(value)
32
-
33
- for (const symbol of symbols) {
34
- if (propertyIsEnumerable.call(value, symbol)) {
35
- keys.push(symbol)
36
- }
37
- }
38
- }
39
-
40
- return keys
41
- }
42
-
43
- function clone <T> (value: T): T
44
- function clone <T> (value: T[]): T[]
45
- function clone (value: any): any {
46
- if (Array.isArray(value)) {
47
- return cloneArray(value)
48
- }
49
-
50
- if (isOptionObject(value)) {
51
- return cloneOptionObject(value)
52
- }
53
-
54
- return value
55
- }
56
-
57
- function cloneArray <T> (array: T[]): T[] {
58
- const result = array.slice(0, 0)
59
-
60
- getEnumerableOwnPropertyKeys(array).forEach(key => {
61
- defineProperty(result, key, clone(array[key]))
62
- })
63
-
64
- return result
65
- }
66
-
67
- function cloneOptionObject (object: any): any {
68
- const result = Object.getPrototypeOf(object) === null ? Object.create(null) : {}
69
-
70
- getEnumerableOwnPropertyKeys(object).forEach(key => {
71
- defineProperty(result, key, clone(object[key]))
72
- })
73
-
74
- return result
75
- }
76
-
77
- const mergeKeys = (merged: any, source: any, keys: any[], config: any): any => {
78
- keys.forEach(key => {
79
- if (typeof source[key] === 'undefined' && config.ignoreUndefined) {
80
- return
81
- }
82
-
83
- // Do not recurse into prototype chain of merged
84
- if (key in merged && merged[key] !== Object.getPrototypeOf(merged)) {
85
- defineProperty(merged, key, merge(merged[key], source[key], config))
86
- } else {
87
- defineProperty(merged, key, clone(source[key]))
88
- }
89
- })
90
-
91
- return merged
92
- }
93
-
94
- /**
95
- * see [Array.prototype.concat ( ...arguments )](http://www.ecma-international.org/ecma-262/6.0/#sec-array.prototype.concat)
96
- */
97
- const concatArrays = (merged: any, source: any, config: any): any => {
98
- let result = merged.slice(0, 0)
99
- let resultIndex = 0;
100
-
101
- [merged, source].forEach(array => {
102
- const indices: any[] = []
103
-
104
- // `result.concat(array)` with cloning
105
- for (let k = 0; k < array.length; k++) {
106
- if (!hasOwnProperty.call(array, k)) {
107
- continue
108
- }
109
-
110
- indices.push(String(k))
111
-
112
- if (array === merged) {
113
- // Already cloned
114
- defineProperty(result, resultIndex++, array[k])
115
- } else {
116
- defineProperty(result, resultIndex++, clone(array[k]))
117
- }
118
- }
119
-
120
- // Merge non-index keys
121
- result = mergeKeys(result, array, getEnumerableOwnPropertyKeys(array).filter(key => !indices.includes(key)), config)
122
- })
123
-
124
- return result
125
- }
126
-
127
- function merge (merged: any, source: any, config: any): any {
128
- if (config.concatArrays && Array.isArray(merged) && Array.isArray(source)) {
129
- return concatArrays(merged, source, config)
130
- }
131
-
132
- if (!isOptionObject(source) || !isOptionObject(merged)) {
133
- return clone(source)
134
- }
135
-
136
- return mergeKeys(merged, source, getEnumerableOwnPropertyKeys(source), config)
137
- }
138
-
139
- /**
140
- * Port of `merge-options` to typescript
141
- *
142
- * @see https://github.com/schnittstabil/merge-options/pull/28
143
- */
144
- export function mergeOptions (this: any, ...options: any[]): any {
145
- const config = merge(clone(defaultMergeOptions), (this !== globalThis && this) || {}, defaultMergeOptions)
146
- let merged = { _: {} }
147
-
148
- for (const option of options) {
149
- if (option === undefined) {
150
- continue
151
- }
152
-
153
- if (!isOptionObject(option)) {
154
- throw new TypeError('`' + option + '` is not an Option Object')
155
- }
156
-
157
- merged = merge(merged, { _: option }, config)
158
- }
159
-
160
- return merged._
161
- }
@@ -1,21 +0,0 @@
1
- import { CODE_IP4, CODE_IP6, CODE_IP6ZONE } from '@multiformats/multiaddr'
2
- import type { Multiaddr } from '@multiformats/multiaddr'
3
-
4
- /**
5
- * Check if a given multiaddr is IP-based
6
- */
7
- export function isIpBased (ma: Multiaddr): boolean {
8
- try {
9
- for (const { code } of ma.getComponents()) {
10
- if (code === CODE_IP6ZONE) {
11
- continue
12
- }
13
-
14
- return code === CODE_IP4 || code === CODE_IP6
15
- }
16
- } catch {
17
-
18
- }
19
-
20
- return false
21
- }
@@ -1,106 +0,0 @@
1
- import forEach from 'it-foreach'
2
- import { pipe } from 'it-pipe'
3
- import type { Logger, MultiaddrConnection, Stream } from '@libp2p/interface'
4
- import type { Multiaddr } from '@multiformats/multiaddr'
5
- import type { Uint8ArrayList } from 'uint8arraylist'
6
-
7
- export interface StreamProperties {
8
- stream: Stream
9
- remoteAddr: Multiaddr
10
- localAddr: Multiaddr
11
- log: Logger
12
-
13
- /**
14
- * A callback invoked when data is read from the stream
15
- */
16
- onDataRead?(buf: Uint8ArrayList | Uint8Array): void
17
-
18
- /**
19
- * A callback invoked when data is written to the stream
20
- */
21
- onDataWrite?(buf: Uint8ArrayList | Uint8Array): void
22
- }
23
-
24
- /**
25
- * Convert a duplex iterable into a MultiaddrConnection.
26
- * https://github.com/libp2p/interface-transport#multiaddrconnection
27
- */
28
- export function streamToMaConnection (props: StreamProperties): MultiaddrConnection {
29
- const { stream, remoteAddr, log, onDataRead, onDataWrite } = props
30
-
31
- let closedRead = false
32
- let closedWrite = false
33
-
34
- // piggyback on `stream.close` invocations to close multiaddr connection
35
- const streamClose = stream.close.bind(stream)
36
- stream.close = async (options): Promise<void> => {
37
- await streamClose(options)
38
- close(true)
39
- }
40
-
41
- // piggyback on `stream.abort` invocations to close multiaddr connection
42
- const streamAbort = stream.abort.bind(stream)
43
- stream.abort = (err): void => {
44
- streamAbort(err)
45
- close(true)
46
- }
47
-
48
- // piggyback on `stream.sink` invocations to close multiaddr connection
49
- const streamSink = stream.sink.bind(stream)
50
- stream.sink = async (source): Promise<void> => {
51
- try {
52
- await streamSink(
53
- pipe(
54
- source,
55
- (source) => forEach(source, buf => onDataWrite?.(buf))
56
- )
57
- )
58
- } catch (err: any) {
59
- maConn.log.error('errored - %e', err)
60
-
61
- // If aborted we can safely ignore
62
- if (err.type !== 'aborted') {
63
- // If the source errored the socket will already have been destroyed by
64
- // toIterable.duplex(). If the socket errored it will already be
65
- // destroyed. There's nothing to do here except log the error & return.
66
- maConn.log.error('%s error in sink - %e', remoteAddr, err)
67
- }
68
- } finally {
69
- closedWrite = true
70
- close()
71
- }
72
- }
73
-
74
- const maConn: MultiaddrConnection = {
75
- log: log.newScope('stream-to-maconn'),
76
- sink: stream.sink,
77
- source: (async function * (): AsyncGenerator<Uint8ArrayList> {
78
- try {
79
- for await (const buf of stream.source) {
80
- onDataRead?.(buf)
81
- yield buf
82
- }
83
- } finally {
84
- closedRead = true
85
- close()
86
- }
87
- }()),
88
- remoteAddr,
89
- timeline: { open: Date.now(), close: undefined },
90
- close: stream.close,
91
- abort: stream.abort
92
- }
93
-
94
- function close (force?: boolean): void {
95
- if (force === true) {
96
- closedRead = true
97
- closedWrite = true
98
- }
99
-
100
- if (closedRead && closedWrite && maConn.timeline.close == null) {
101
- maConn.timeline.close = Date.now()
102
- }
103
- }
104
-
105
- return maConn
106
- }