libp2p 0.42.2 → 0.43.0
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.
- package/README.md +4 -4
- package/dist/index.min.js +29 -29
- package/dist/src/address-manager/index.d.ts +1 -10
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +46 -29
- package/dist/src/address-manager/index.js.map +1 -1
- package/dist/src/autonat/constants.d.ts +4 -0
- package/dist/src/autonat/constants.d.ts.map +1 -0
- package/dist/src/autonat/constants.js +4 -0
- package/dist/src/autonat/constants.js.map +1 -0
- package/dist/src/autonat/index.d.ts +64 -0
- package/dist/src/autonat/index.d.ts.map +1 -0
- package/dist/src/autonat/index.js +417 -0
- package/dist/src/autonat/index.js.map +1 -0
- package/dist/src/autonat/pb/index.d.ts +57 -0
- package/dist/src/autonat/pb/index.d.ts.map +1 -0
- package/dist/src/autonat/pb/index.js +250 -0
- package/dist/src/autonat/pb/index.js.map +1 -0
- package/dist/src/circuit/constants.d.ts +31 -6
- package/dist/src/circuit/constants.d.ts.map +1 -1
- package/dist/src/circuit/constants.js +37 -7
- package/dist/src/circuit/constants.js.map +1 -1
- package/dist/src/circuit/index.d.ts +16 -61
- package/dist/src/circuit/index.d.ts.map +1 -1
- package/dist/src/circuit/index.js +2 -68
- package/dist/src/circuit/index.js.map +1 -1
- package/dist/src/circuit/pb/index.d.ts +83 -43
- package/dist/src/circuit/pb/index.d.ts.map +1 -1
- package/dist/src/circuit/pb/index.js +363 -127
- package/dist/src/circuit/pb/index.js.map +1 -1
- package/dist/src/circuit/server/advert-service.d.ts +43 -0
- package/dist/src/circuit/server/advert-service.d.ts.map +1 -0
- package/dist/src/circuit/server/advert-service.js +69 -0
- package/dist/src/circuit/server/advert-service.js.map +1 -0
- package/dist/src/circuit/server/index.d.ts +60 -0
- package/dist/src/circuit/server/index.d.ts.map +1 -0
- package/dist/src/circuit/server/index.js +287 -0
- package/dist/src/circuit/server/index.js.map +1 -0
- package/dist/src/circuit/server/reservation-store.d.ts +49 -0
- package/dist/src/circuit/server/reservation-store.d.ts.map +1 -0
- package/dist/src/circuit/server/reservation-store.js +57 -0
- package/dist/src/circuit/server/reservation-store.js.map +1 -0
- package/dist/src/circuit/server/reservation-voucher.d.ts +18 -0
- package/dist/src/circuit/server/reservation-voucher.d.ts.map +1 -0
- package/dist/src/circuit/server/reservation-voucher.js +33 -0
- package/dist/src/circuit/server/reservation-voucher.js.map +1 -0
- package/dist/src/circuit/transport/discovery.d.ts +45 -0
- package/dist/src/circuit/transport/discovery.d.ts.map +1 -0
- package/dist/src/circuit/transport/discovery.js +82 -0
- package/dist/src/circuit/transport/discovery.js.map +1 -0
- package/dist/src/circuit/transport/index.d.ts +33 -0
- package/dist/src/circuit/transport/index.d.ts.map +1 -0
- package/dist/src/circuit/transport/index.js +225 -0
- package/dist/src/circuit/transport/index.js.map +1 -0
- package/dist/src/circuit/transport/listener.d.ts +9 -0
- package/dist/src/circuit/transport/listener.d.ts.map +1 -0
- package/dist/src/circuit/transport/listener.js +76 -0
- package/dist/src/circuit/transport/listener.js.map +1 -0
- package/dist/src/circuit/transport/reservation-store.d.ts +60 -0
- package/dist/src/circuit/transport/reservation-store.d.ts.map +1 -0
- package/dist/src/circuit/transport/reservation-store.js +165 -0
- package/dist/src/circuit/transport/reservation-store.js.map +1 -0
- package/dist/src/circuit/utils.d.ts +7 -0
- package/dist/src/circuit/utils.d.ts.map +1 -1
- package/dist/src/circuit/utils.js +87 -0
- package/dist/src/circuit/utils.js.map +1 -1
- package/dist/src/components.d.ts +2 -1
- package/dist/src/components.d.ts.map +1 -1
- package/dist/src/components.js +13 -13
- package/dist/src/components.js.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +21 -25
- package/dist/src/config.js.map +1 -1
- package/dist/src/connection/index.d.ts +2 -2
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +4 -4
- package/dist/src/connection/index.js.map +1 -1
- package/dist/src/connection-manager/auto-dialler.d.ts +0 -4
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dialler.js +18 -18
- package/dist/src/connection-manager/auto-dialler.js.map +1 -1
- package/dist/src/connection-manager/dialer/dial-request.d.ts.map +1 -1
- package/dist/src/connection-manager/dialer/dial-request.js +13 -6
- package/dist/src/connection-manager/dialer/dial-request.js.map +1 -1
- package/dist/src/connection-manager/dialer/index.d.ts +10 -1
- package/dist/src/connection-manager/dialer/index.d.ts.map +1 -1
- package/dist/src/connection-manager/dialer/index.js +24 -9
- package/dist/src/connection-manager/dialer/index.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts +1 -4
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +8 -5
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/connection-manager/latency-monitor.d.ts.map +1 -1
- package/dist/src/connection-manager/latency-monitor.js +1 -1
- package/dist/src/connection-manager/latency-monitor.js.map +1 -1
- package/dist/src/connection-manager/visibility-change-emitter.d.ts.map +1 -1
- package/dist/src/content-routing/index.d.ts +6 -4
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +9 -9
- package/dist/src/content-routing/index.js.map +1 -1
- package/dist/src/content-routing/utils.d.ts +3 -3
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/content-routing/utils.js +2 -2
- package/dist/src/content-routing/utils.js.map +1 -1
- package/dist/src/dht/dht-content-routing.d.ts +2 -1
- package/dist/src/dht/dht-content-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-content-routing.js +2 -2
- package/dist/src/dht/dht-content-routing.js.map +1 -1
- package/dist/src/dht/dht-peer-routing.d.ts +3 -2
- package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-peer-routing.js +2 -2
- package/dist/src/dht/dht-peer-routing.js.map +1 -1
- package/dist/src/dht/dummy-dht.d.ts +1 -1
- package/dist/src/dht/dummy-dht.d.ts.map +1 -1
- package/dist/src/dht/dummy-dht.js +12 -12
- package/dist/src/dht/dummy-dht.js.map +1 -1
- package/dist/src/errors.d.ts +2 -1
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +1 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +6 -6
- package/dist/src/fetch/index.js.map +1 -1
- package/dist/src/fetch/pb/proto.d.ts +3 -3
- package/dist/src/fetch/pb/proto.d.ts.map +1 -1
- package/dist/src/fetch/pb/proto.js +4 -3
- package/dist/src/fetch/pb/proto.js.map +1 -1
- package/dist/src/get-peer.js +2 -2
- package/dist/src/get-peer.js.map +1 -1
- package/dist/src/identify/index.d.ts +3 -1
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +19 -14
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/identify/pb/message.d.ts +2 -2
- package/dist/src/identify/pb/message.d.ts.map +1 -1
- package/dist/src/identify/pb/message.js +1 -0
- package/dist/src/identify/pb/message.js.map +1 -1
- package/dist/src/index.d.ts +14 -8
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/insecure/index.d.ts.map +1 -1
- package/dist/src/insecure/index.js.map +1 -1
- package/dist/src/insecure/pb/proto.d.ts +3 -3
- package/dist/src/insecure/pb/proto.d.ts.map +1 -1
- package/dist/src/insecure/pb/proto.js +4 -5
- package/dist/src/insecure/pb/proto.js.map +1 -1
- package/dist/src/libp2p.d.ts +7 -3
- package/dist/src/libp2p.d.ts.map +1 -1
- package/dist/src/libp2p.js +35 -35
- package/dist/src/libp2p.js.map +1 -1
- package/dist/src/nat-manager.d.ts.map +1 -1
- package/dist/src/nat-manager.js +5 -3
- package/dist/src/nat-manager.js.map +1 -1
- package/dist/src/peer-record-updater.d.ts.map +1 -1
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +5 -5
- package/dist/src/peer-routing.js.map +1 -1
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +2 -2
- package/dist/src/ping/index.js.map +1 -1
- package/dist/src/pnet/crypto.d.ts +1 -1
- package/dist/src/pnet/crypto.d.ts.map +1 -1
- package/dist/src/pnet/crypto.js +1 -1
- package/dist/src/pnet/crypto.js.map +1 -1
- package/dist/src/pnet/index.js +3 -3
- package/dist/src/pnet/index.js.map +1 -1
- package/dist/src/pnet/key-generator.d.ts.map +1 -1
- package/dist/src/pubsub/dummy-pubsub.js +9 -9
- package/dist/src/pubsub/dummy-pubsub.js.map +1 -1
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +4 -4
- package/dist/src/registrar.js.map +1 -1
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +8 -9
- package/dist/src/transport-manager.js.map +1 -1
- package/dist/src/upgrader.d.ts +2 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +38 -33
- package/dist/src/upgrader.js.map +1 -1
- package/dist/typedoc-urls.json +19 -6
- package/package.json +36 -33
- package/src/address-manager/index.ts +62 -35
- package/src/autonat/constants.ts +4 -0
- package/src/autonat/index.ts +567 -0
- package/src/autonat/pb/index.proto +35 -0
- package/src/autonat/pb/index.ts +320 -0
- package/src/circuit/constants.ts +48 -7
- package/src/circuit/index.ts +17 -129
- package/src/circuit/pb/index.proto +57 -32
- package/src/circuit/pb/index.ts +448 -138
- package/src/circuit/server/advert-service.ts +108 -0
- package/src/circuit/server/index.ts +421 -0
- package/src/circuit/server/reservation-store.ts +111 -0
- package/src/circuit/server/reservation-voucher.ts +51 -0
- package/src/circuit/transport/discovery.ts +127 -0
- package/src/circuit/transport/index.ts +325 -0
- package/src/circuit/transport/listener.ts +99 -0
- package/src/circuit/transport/reservation-store.ts +249 -0
- package/src/circuit/utils.ts +108 -0
- package/src/components.ts +22 -21
- package/src/config.ts +21 -25
- package/src/connection/index.ts +10 -10
- package/src/connection-manager/auto-dialler.ts +36 -40
- package/src/connection-manager/dialer/dial-request.ts +13 -6
- package/src/connection-manager/dialer/index.ts +34 -15
- package/src/connection-manager/index.ts +22 -23
- package/src/connection-manager/latency-monitor.ts +9 -9
- package/src/connection-manager/visibility-change-emitter.ts +4 -4
- package/src/content-routing/index.ts +18 -16
- package/src/content-routing/utils.ts +5 -5
- package/src/dht/dht-content-routing.ts +5 -4
- package/src/dht/dht-peer-routing.ts +5 -4
- package/src/dht/dummy-dht.ts +13 -13
- package/src/errors.ts +2 -1
- package/src/fetch/index.ts +13 -13
- package/src/fetch/pb/proto.ts +8 -7
- package/src/get-peer.ts +3 -3
- package/src/identify/index.ts +29 -24
- package/src/identify/pb/message.ts +3 -2
- package/src/index.ts +15 -8
- package/src/insecure/index.ts +2 -1
- package/src/insecure/pb/proto.ts +8 -9
- package/src/libp2p.ts +52 -46
- package/src/nat-manager.ts +11 -9
- package/src/peer-record-updater.ts +4 -4
- package/src/peer-routing.ts +9 -9
- package/src/ping/index.ts +6 -6
- package/src/pnet/crypto.ts +3 -3
- package/src/pnet/index.ts +3 -3
- package/src/pnet/key-generator.ts +1 -1
- package/src/pubsub/dummy-pubsub.ts +9 -9
- package/src/registrar.ts +12 -12
- package/src/transport-manager.ts +17 -18
- package/src/upgrader.ts +43 -42
- package/src/version.ts +1 -1
- package/dist/src/circuit/auto-relay.d.ts +0 -46
- package/dist/src/circuit/auto-relay.d.ts.map +0 -1
- package/dist/src/circuit/auto-relay.js +0 -220
- package/dist/src/circuit/auto-relay.js.map +0 -1
- package/dist/src/circuit/circuit/hop.d.ts +0 -42
- package/dist/src/circuit/circuit/hop.d.ts.map +0 -1
- package/dist/src/circuit/circuit/hop.js +0 -142
- package/dist/src/circuit/circuit/hop.js.map +0 -1
- package/dist/src/circuit/circuit/stop.d.ts +0 -24
- package/dist/src/circuit/circuit/stop.d.ts.map +0 -1
- package/dist/src/circuit/circuit/stop.js +0 -51
- package/dist/src/circuit/circuit/stop.js.map +0 -1
- package/dist/src/circuit/circuit/stream-handler.d.ts +0 -40
- package/dist/src/circuit/circuit/stream-handler.d.ts.map +0 -1
- package/dist/src/circuit/circuit/stream-handler.js +0 -59
- package/dist/src/circuit/circuit/stream-handler.js.map +0 -1
- package/dist/src/circuit/circuit/utils.d.ts +0 -7
- package/dist/src/circuit/circuit/utils.d.ts.map +0 -1
- package/dist/src/circuit/circuit/utils.js +0 -43
- package/dist/src/circuit/circuit/utils.js.map +0 -1
- package/dist/src/circuit/listener.d.ts +0 -9
- package/dist/src/circuit/listener.d.ts.map +0 -1
- package/dist/src/circuit/listener.js +0 -62
- package/dist/src/circuit/listener.js.map +0 -1
- package/dist/src/circuit/multicodec.d.ts +0 -2
- package/dist/src/circuit/multicodec.d.ts.map +0 -1
- package/dist/src/circuit/multicodec.js +0 -2
- package/dist/src/circuit/multicodec.js.map +0 -1
- package/dist/src/circuit/transport.d.ts +0 -51
- package/dist/src/circuit/transport.d.ts.map +0 -1
- package/dist/src/circuit/transport.js +0 -223
- package/dist/src/circuit/transport.js.map +0 -1
- package/dist/src/keychain/cms.d.ts +0 -33
- package/dist/src/keychain/cms.d.ts.map +0 -1
- package/dist/src/keychain/cms.js +0 -129
- package/dist/src/keychain/cms.js.map +0 -1
- package/dist/src/keychain/index.d.ts +0 -151
- package/dist/src/keychain/index.d.ts.map +0 -1
- package/dist/src/keychain/index.js +0 -519
- package/dist/src/keychain/index.js.map +0 -1
- package/dist/src/keychain/util.d.ts +0 -21
- package/dist/src/keychain/util.d.ts.map +0 -1
- package/dist/src/keychain/util.js +0 -79
- package/dist/src/keychain/util.js.map +0 -1
- package/src/circuit/IMPLEMENTATION_NOTES.md +0 -128
- package/src/circuit/README.md +0 -111
- package/src/circuit/auto-relay.ts +0 -292
- package/src/circuit/circuit/hop.ts +0 -220
- package/src/circuit/circuit/stop.ts +0 -83
- package/src/circuit/circuit/stream-handler.ts +0 -87
- package/src/circuit/circuit/utils.ts +0 -44
- package/src/circuit/listener.ts +0 -83
- package/src/circuit/multicodec.ts +0 -2
- package/src/circuit/transport.ts +0 -278
- package/src/keychain/README.md +0 -55
- package/src/keychain/cms.ts +0 -150
- package/src/keychain/doc/private-key.png +0 -0
- package/src/keychain/doc/private-key.xml +0 -1
- package/src/keychain/index.ts +0 -629
- package/src/keychain/util.ts +0 -82
|
@@ -60,7 +60,7 @@ export class VisibilityChangeEmitter extends EventEmitter<VisibilityChangeEmitte
|
|
|
60
60
|
*
|
|
61
61
|
* @private
|
|
62
62
|
*/
|
|
63
|
-
_initializeVisibilityVarNames () {
|
|
63
|
+
_initializeVisibilityVarNames (): void {
|
|
64
64
|
let hidden: Hidden = 'hidden'
|
|
65
65
|
let visibilityChange = 'visibilitychange'
|
|
66
66
|
|
|
@@ -91,7 +91,7 @@ export class VisibilityChangeEmitter extends EventEmitter<VisibilityChangeEmitte
|
|
|
91
91
|
*
|
|
92
92
|
* @private
|
|
93
93
|
*/
|
|
94
|
-
_addVisibilityChangeListener () {
|
|
94
|
+
_addVisibilityChangeListener (): void {
|
|
95
95
|
// @ts-expect-error cannot index document object with string key
|
|
96
96
|
if (typeof globalThis.document.addEventListener === 'undefined' || typeof document[this.hidden] === 'undefined') {
|
|
97
97
|
log('Checking page visibility requires a browser that supports the Page Visibility API.')
|
|
@@ -105,7 +105,7 @@ export class VisibilityChangeEmitter extends EventEmitter<VisibilityChangeEmitte
|
|
|
105
105
|
* The function returns ```true``` if the page is visible or ```false``` if the page is not visible and
|
|
106
106
|
* ```undefined``` if the page visibility API is not supported by the browser.
|
|
107
107
|
*/
|
|
108
|
-
isVisible () {
|
|
108
|
+
isVisible (): boolean | undefined {
|
|
109
109
|
// @ts-expect-error cannot index document object with string key
|
|
110
110
|
if (this.hidden === undefined || document[this.hidden] === undefined) {
|
|
111
111
|
return undefined
|
|
@@ -122,7 +122,7 @@ export class VisibilityChangeEmitter extends EventEmitter<VisibilityChangeEmitte
|
|
|
122
122
|
*
|
|
123
123
|
* @private
|
|
124
124
|
*/
|
|
125
|
-
_handleVisibilityChange () {
|
|
125
|
+
_handleVisibilityChange (): void {
|
|
126
126
|
// @ts-expect-error cannot index document object with string key
|
|
127
127
|
const visible = globalThis.document[this.hidden] === false
|
|
128
128
|
log(visible ? 'Page Visible' : 'Page Hidden')
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
2
2
|
import { messages, codes } from '../errors.js'
|
|
3
3
|
import {
|
|
4
4
|
storeAddresses,
|
|
@@ -14,6 +14,8 @@ import type { Startable } from '@libp2p/interfaces/startable'
|
|
|
14
14
|
import type { CID } from 'multiformats/cid'
|
|
15
15
|
import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
16
16
|
import type { DualDHT } from '@libp2p/interface-dht'
|
|
17
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
18
|
+
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
17
19
|
|
|
18
20
|
export interface CompoundContentRoutingInit {
|
|
19
21
|
routers: ContentRouting[]
|
|
@@ -35,24 +37,24 @@ export class CompoundContentRouting implements ContentRouting, Startable {
|
|
|
35
37
|
this.components = components
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
isStarted () {
|
|
40
|
+
isStarted (): boolean {
|
|
39
41
|
return this.started
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
async start () {
|
|
44
|
+
async start (): Promise<void> {
|
|
43
45
|
this.started = true
|
|
44
46
|
}
|
|
45
47
|
|
|
46
|
-
async stop () {
|
|
48
|
+
async stop (): Promise<void> {
|
|
47
49
|
this.started = false
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
/**
|
|
51
53
|
* Iterates over all content routers in parallel to find providers of the given key
|
|
52
54
|
*/
|
|
53
|
-
async * findProviders (key: CID, options: AbortOptions = {}) {
|
|
55
|
+
async * findProviders (key: CID, options: AbortOptions = {}): AsyncIterable<PeerInfo> {
|
|
54
56
|
if (this.routers.length === 0) {
|
|
55
|
-
throw
|
|
57
|
+
throw new CodeError('No content this.routers available', codes.ERR_NO_ROUTERS_AVAILABLE)
|
|
56
58
|
}
|
|
57
59
|
|
|
58
60
|
yield * pipe(
|
|
@@ -69,20 +71,20 @@ export class CompoundContentRouting implements ContentRouting, Startable {
|
|
|
69
71
|
* Iterates over all content routers in parallel to notify it is
|
|
70
72
|
* a provider of the given key
|
|
71
73
|
*/
|
|
72
|
-
async provide (key: CID, options: AbortOptions = {}) {
|
|
74
|
+
async provide (key: CID, options: AbortOptions = {}): Promise<void> {
|
|
73
75
|
if (this.routers.length === 0) {
|
|
74
|
-
throw
|
|
76
|
+
throw new CodeError('No content routers available', codes.ERR_NO_ROUTERS_AVAILABLE)
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
await Promise.all(this.routers.map(async (router) => await router.provide(key, options)))
|
|
79
|
+
await Promise.all(this.routers.map(async (router) => { await router.provide(key, options) }))
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
/**
|
|
81
83
|
* Store the given key/value pair in the available content routings
|
|
82
84
|
*/
|
|
83
|
-
async put (key: Uint8Array, value: Uint8Array, options?: AbortOptions) {
|
|
85
|
+
async put (key: Uint8Array, value: Uint8Array, options?: AbortOptions): Promise<void> {
|
|
84
86
|
if (!this.isStarted()) {
|
|
85
|
-
throw
|
|
87
|
+
throw new CodeError(messages.NOT_STARTED_YET, codes.DHT_NOT_STARTED)
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
const dht = this.components.dht
|
|
@@ -98,7 +100,7 @@ export class CompoundContentRouting implements ContentRouting, Startable {
|
|
|
98
100
|
*/
|
|
99
101
|
async get (key: Uint8Array, options?: AbortOptions): Promise<Uint8Array> {
|
|
100
102
|
if (!this.isStarted()) {
|
|
101
|
-
throw
|
|
103
|
+
throw new CodeError(messages.NOT_STARTED_YET, codes.DHT_NOT_STARTED)
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
const dht = this.components.dht
|
|
@@ -111,15 +113,15 @@ export class CompoundContentRouting implements ContentRouting, Startable {
|
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
throw
|
|
116
|
+
throw new CodeError(messages.NOT_FOUND, codes.ERR_NOT_FOUND)
|
|
115
117
|
}
|
|
116
118
|
|
|
117
119
|
/**
|
|
118
120
|
* Get the `n` values to the given key without sorting
|
|
119
121
|
*/
|
|
120
|
-
async * getMany (key: Uint8Array, nVals: number, options: AbortOptions) {
|
|
122
|
+
async * getMany (key: Uint8Array, nVals: number, options: AbortOptions): AsyncIterable<{ from: PeerId, val: Uint8Array }> {
|
|
121
123
|
if (!this.isStarted()) {
|
|
122
|
-
throw
|
|
124
|
+
throw new CodeError(messages.NOT_STARTED_YET, codes.DHT_NOT_STARTED)
|
|
123
125
|
}
|
|
124
126
|
|
|
125
127
|
if (nVals == null || nVals === 0) {
|
|
@@ -144,7 +146,7 @@ export class CompoundContentRouting implements ContentRouting, Startable {
|
|
|
144
146
|
}
|
|
145
147
|
|
|
146
148
|
if (gotValues === 0) {
|
|
147
|
-
throw
|
|
149
|
+
throw new CodeError(messages.NOT_FOUND, codes.ERR_NOT_FOUND)
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
2
2
|
import filter from 'it-filter'
|
|
3
3
|
import map from 'it-map'
|
|
4
4
|
import type { Source } from 'it-stream-types'
|
|
@@ -8,7 +8,7 @@ import type { PeerStore } from '@libp2p/interface-peer-store'
|
|
|
8
8
|
/**
|
|
9
9
|
* Store the multiaddrs from every peer in the passed peer store
|
|
10
10
|
*/
|
|
11
|
-
export async function * storeAddresses (source: Source<PeerInfo>, peerStore: PeerStore) {
|
|
11
|
+
export async function * storeAddresses (source: Source<PeerInfo>, peerStore: PeerStore): AsyncIterable<PeerInfo> {
|
|
12
12
|
yield * map(source, async (peer) => {
|
|
13
13
|
// ensure we have the addresses for a given peer
|
|
14
14
|
await peerStore.addressBook.add(peer.id, peer.multiaddrs)
|
|
@@ -20,7 +20,7 @@ export async function * storeAddresses (source: Source<PeerInfo>, peerStore: Pee
|
|
|
20
20
|
/**
|
|
21
21
|
* Filter peers by unique peer id
|
|
22
22
|
*/
|
|
23
|
-
export function uniquePeers (source: Source<PeerInfo>) {
|
|
23
|
+
export function uniquePeers (source: Source<PeerInfo>): AsyncIterable<PeerInfo> {
|
|
24
24
|
/** @type Set<string> */
|
|
25
25
|
const seen = new Set()
|
|
26
26
|
|
|
@@ -39,7 +39,7 @@ export function uniquePeers (source: Source<PeerInfo>) {
|
|
|
39
39
|
/**
|
|
40
40
|
* Require at least `min` peers to be yielded from `source`
|
|
41
41
|
*/
|
|
42
|
-
export async function * requirePeers (source: Source<PeerInfo>, min: number = 1) {
|
|
42
|
+
export async function * requirePeers (source: Source<PeerInfo>, min: number = 1): AsyncIterable<PeerInfo> {
|
|
43
43
|
let seen = 0
|
|
44
44
|
|
|
45
45
|
for await (const peer of source) {
|
|
@@ -49,6 +49,6 @@ export async function * requirePeers (source: Source<PeerInfo>, min: number = 1)
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
if (seen < min) {
|
|
52
|
-
throw
|
|
52
|
+
throw new CodeError('not found', 'NOT_FOUND')
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import drain from 'it-drain'
|
|
2
|
-
import
|
|
2
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
3
3
|
import type { DHT } from '@libp2p/interface-dht'
|
|
4
4
|
import type { ContentRouting } from '@libp2p/interface-content-routing'
|
|
5
5
|
import type { CID } from 'multiformats/cid'
|
|
6
6
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
7
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Wrapper class to convert events into returned values
|
|
@@ -15,11 +16,11 @@ export class DHTContentRouting implements ContentRouting {
|
|
|
15
16
|
this.dht = dht
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
async provide (cid: CID) {
|
|
19
|
+
async provide (cid: CID): Promise<void> {
|
|
19
20
|
await drain(this.dht.provide(cid))
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
async * findProviders (cid: CID, options: AbortOptions = {}) {
|
|
23
|
+
async * findProviders (cid: CID, options: AbortOptions = {}): AsyncGenerator<PeerInfo, void, undefined> {
|
|
23
24
|
for await (const event of this.dht.findProviders(cid, options)) {
|
|
24
25
|
if (event.name === 'PROVIDER') {
|
|
25
26
|
yield * event.providers
|
|
@@ -38,6 +39,6 @@ export class DHTContentRouting implements ContentRouting {
|
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
throw
|
|
42
|
+
throw new CodeError('Not found', 'ERR_NOT_FOUND')
|
|
42
43
|
}
|
|
43
44
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
2
2
|
import { messages, codes } from '../errors.js'
|
|
3
3
|
import type { PeerRouting } from '@libp2p/interface-peer-routing'
|
|
4
4
|
import type { DHT } from '@libp2p/interface-dht'
|
|
5
5
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
6
6
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
7
|
+
import type { PeerInfo } from '@libp2p/interface-peer-info'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Wrapper class to convert events into returned values
|
|
@@ -15,17 +16,17 @@ export class DHTPeerRouting implements PeerRouting {
|
|
|
15
16
|
this.dht = dht
|
|
16
17
|
}
|
|
17
18
|
|
|
18
|
-
async findPeer (peerId: PeerId, options: AbortOptions = {}) {
|
|
19
|
+
async findPeer (peerId: PeerId, options: AbortOptions = {}): Promise<PeerInfo> {
|
|
19
20
|
for await (const event of this.dht.findPeer(peerId, options)) {
|
|
20
21
|
if (event.name === 'FINAL_PEER') {
|
|
21
22
|
return event.peer
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
throw
|
|
26
|
+
throw new CodeError(messages.NOT_FOUND, codes.ERR_NOT_FOUND)
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
async * getClosestPeers (key: Uint8Array, options: AbortOptions = {}) {
|
|
29
|
+
async * getClosestPeers (key: Uint8Array, options: AbortOptions = {}): AsyncIterable<PeerInfo> {
|
|
29
30
|
for await (const event of this.dht.getClosestPeers(key, options)) {
|
|
30
31
|
if (event.name === 'FINAL_PEER') {
|
|
31
32
|
yield event.peer
|
package/src/dht/dummy-dht.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { DualDHT, QueryEvent, SingleDHT } from '@libp2p/interface-dht'
|
|
2
2
|
import type { PeerDiscoveryEvents } from '@libp2p/interface-peer-discovery'
|
|
3
|
-
import
|
|
3
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
4
4
|
import { messages, codes } from '../errors.js'
|
|
5
5
|
import { EventEmitter } from '@libp2p/interfaces/events'
|
|
6
6
|
import { symbol } from '@libp2p/interface-peer-discovery'
|
|
@@ -10,51 +10,51 @@ export class DummyDHT extends EventEmitter<PeerDiscoveryEvents> implements DualD
|
|
|
10
10
|
return true
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
get [Symbol.toStringTag] () {
|
|
13
|
+
get [Symbol.toStringTag] (): '@libp2p/dummy-dht' {
|
|
14
14
|
return '@libp2p/dummy-dht'
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
get wan (): SingleDHT {
|
|
18
|
-
throw
|
|
18
|
+
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED)
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
get lan (): SingleDHT {
|
|
22
|
-
throw
|
|
22
|
+
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
get (): AsyncIterable<QueryEvent> {
|
|
26
|
-
throw
|
|
26
|
+
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
findProviders (): AsyncIterable<QueryEvent> {
|
|
30
|
-
throw
|
|
30
|
+
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
findPeer (): AsyncIterable<QueryEvent> {
|
|
34
|
-
throw
|
|
34
|
+
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
getClosestPeers (): AsyncIterable<QueryEvent> {
|
|
38
|
-
throw
|
|
38
|
+
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
provide (): AsyncIterable<QueryEvent> {
|
|
42
|
-
throw
|
|
42
|
+
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
put (): AsyncIterable<QueryEvent> {
|
|
46
|
-
throw
|
|
46
|
+
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
async getMode (): Promise<'client' | 'server'> {
|
|
50
|
-
throw
|
|
50
|
+
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED)
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
async setMode (): Promise<void> {
|
|
54
|
-
throw
|
|
54
|
+
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED)
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
async refreshRoutingTable (): Promise<void> {
|
|
58
|
-
throw
|
|
58
|
+
throw new CodeError(messages.DHT_DISABLED, codes.DHT_DISABLED)
|
|
59
59
|
}
|
|
60
60
|
}
|
package/src/errors.ts
CHANGED
|
@@ -74,5 +74,6 @@ export enum codes {
|
|
|
74
74
|
ERR_NO_HANDLER_FOR_PROTOCOL = 'ERR_NO_HANDLER_FOR_PROTOCOL',
|
|
75
75
|
ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS = 'ERR_TOO_MANY_OUTBOUND_PROTOCOL_STREAMS',
|
|
76
76
|
ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS = 'ERR_TOO_MANY_INBOUND_PROTOCOL_STREAMS',
|
|
77
|
-
ERR_CONNECTION_DENIED = 'ERR_CONNECTION_DENIED'
|
|
77
|
+
ERR_CONNECTION_DENIED = 'ERR_CONNECTION_DENIED',
|
|
78
|
+
ERR_TRANSFER_LIMIT_EXCEEDED = 'ERR_TRANSFER_LIMIT_EXCEEDED',
|
|
78
79
|
}
|
package/src/fetch/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
|
-
import
|
|
2
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
3
3
|
import { codes } from '../errors.js'
|
|
4
4
|
import * as lp from 'it-length-prefixed'
|
|
5
5
|
import { FetchRequest, FetchResponse } from './pb/proto.js'
|
|
@@ -67,7 +67,7 @@ export class FetchService implements Startable {
|
|
|
67
67
|
this.init = init
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
async start () {
|
|
70
|
+
async start (): Promise<void> {
|
|
71
71
|
await this.components.registrar.handle(this.protocol, (data) => {
|
|
72
72
|
void this.handleMessage(data)
|
|
73
73
|
.catch(err => {
|
|
@@ -83,12 +83,12 @@ export class FetchService implements Startable {
|
|
|
83
83
|
this.started = true
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
async stop () {
|
|
86
|
+
async stop (): Promise<void> {
|
|
87
87
|
await this.components.registrar.unhandle(this.protocol)
|
|
88
88
|
this.started = false
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
isStarted () {
|
|
91
|
+
isStarted (): boolean {
|
|
92
92
|
return this.started
|
|
93
93
|
}
|
|
94
94
|
|
|
@@ -134,7 +134,7 @@ export class FetchService implements Startable {
|
|
|
134
134
|
const buf = await first(source)
|
|
135
135
|
|
|
136
136
|
if (buf == null) {
|
|
137
|
-
throw
|
|
137
|
+
throw new CodeError('No data received', codes.ERR_INVALID_MESSAGE)
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
const response = FetchResponse.decode(buf)
|
|
@@ -151,11 +151,11 @@ export class FetchService implements Startable {
|
|
|
151
151
|
case (FetchResponse.StatusCode.ERROR): {
|
|
152
152
|
log('received status for %s error', key)
|
|
153
153
|
const errmsg = uint8arrayToString(response.data)
|
|
154
|
-
throw
|
|
154
|
+
throw new CodeError('Error in fetch protocol response: ' + errmsg, codes.ERR_INVALID_PARAMETERS)
|
|
155
155
|
}
|
|
156
156
|
default: {
|
|
157
157
|
log('received status for %s unknown', key)
|
|
158
|
-
throw
|
|
158
|
+
throw new CodeError('Unknown response status', codes.ERR_INVALID_MESSAGE)
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
}
|
|
@@ -178,7 +178,7 @@ export class FetchService implements Startable {
|
|
|
178
178
|
* responds based on looking up the key in the request via the lookup callback that corresponds
|
|
179
179
|
* to the key's prefix.
|
|
180
180
|
*/
|
|
181
|
-
async handleMessage (data: IncomingStreamData) {
|
|
181
|
+
async handleMessage (data: IncomingStreamData): Promise<void> {
|
|
182
182
|
const { stream } = data
|
|
183
183
|
const self = this
|
|
184
184
|
|
|
@@ -189,7 +189,7 @@ export class FetchService implements Startable {
|
|
|
189
189
|
const buf = await first(source)
|
|
190
190
|
|
|
191
191
|
if (buf == null) {
|
|
192
|
-
throw
|
|
192
|
+
throw new CodeError('No data received', codes.ERR_INVALID_MESSAGE)
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
// for await (const buf of source) {
|
|
@@ -224,7 +224,7 @@ export class FetchService implements Startable {
|
|
|
224
224
|
* Given a key, finds the appropriate function for looking up its corresponding value, based on
|
|
225
225
|
* the key's prefix.
|
|
226
226
|
*/
|
|
227
|
-
_getLookupFunction (key: string) {
|
|
227
|
+
_getLookupFunction (key: string): LookupFunction | undefined {
|
|
228
228
|
for (const prefix of this.lookupFunctions.keys()) {
|
|
229
229
|
if (key.startsWith(prefix)) {
|
|
230
230
|
return this.lookupFunctions.get(prefix)
|
|
@@ -243,9 +243,9 @@ export class FetchService implements Startable {
|
|
|
243
243
|
* libp2p.fetchService.registerLookupFunction('/prefix', (key) => { ... })
|
|
244
244
|
* ```
|
|
245
245
|
*/
|
|
246
|
-
registerLookupFunction (prefix: string, lookup: LookupFunction) {
|
|
246
|
+
registerLookupFunction (prefix: string, lookup: LookupFunction): void {
|
|
247
247
|
if (this.lookupFunctions.has(prefix)) {
|
|
248
|
-
throw
|
|
248
|
+
throw new CodeError(`Fetch protocol handler for key prefix '${prefix}' already registered`, codes.ERR_KEY_ALREADY_EXISTS)
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
this.lookupFunctions.set(prefix, lookup)
|
|
@@ -262,7 +262,7 @@ export class FetchService implements Startable {
|
|
|
262
262
|
* libp2p.fetchService.unregisterLookupFunction('/prefix')
|
|
263
263
|
* ```
|
|
264
264
|
*/
|
|
265
|
-
unregisterLookupFunction (prefix: string, lookup?: LookupFunction) {
|
|
265
|
+
unregisterLookupFunction (prefix: string, lookup?: LookupFunction): void {
|
|
266
266
|
if (lookup != null) {
|
|
267
267
|
const existingLookup = this.lookupFunctions.get(prefix)
|
|
268
268
|
|
package/src/fetch/pb/proto.ts
CHANGED
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
/* eslint-disable complexity */
|
|
3
3
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
4
4
|
/* eslint-disable @typescript-eslint/no-unnecessary-boolean-literal-compare */
|
|
5
|
+
/* eslint-disable @typescript-eslint/no-empty-interface */
|
|
5
6
|
|
|
6
7
|
import { encodeMessage, decodeMessage, message, enumeration } from 'protons-runtime'
|
|
7
|
-
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
8
8
|
import type { Codec } from 'protons-runtime'
|
|
9
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
9
10
|
|
|
10
11
|
export interface FetchRequest {
|
|
11
12
|
identifier: string
|
|
@@ -21,7 +22,7 @@ export namespace FetchRequest {
|
|
|
21
22
|
w.fork()
|
|
22
23
|
}
|
|
23
24
|
|
|
24
|
-
if (
|
|
25
|
+
if ((obj.identifier != null && obj.identifier !== '')) {
|
|
25
26
|
w.uint32(10)
|
|
26
27
|
w.string(obj.identifier)
|
|
27
28
|
}
|
|
@@ -56,7 +57,7 @@ export namespace FetchRequest {
|
|
|
56
57
|
return _codec
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
export const encode = (obj: FetchRequest): Uint8Array => {
|
|
60
|
+
export const encode = (obj: Partial<FetchRequest>): Uint8Array => {
|
|
60
61
|
return encodeMessage(obj, FetchRequest.codec())
|
|
61
62
|
}
|
|
62
63
|
|
|
@@ -84,7 +85,7 @@ export namespace FetchResponse {
|
|
|
84
85
|
}
|
|
85
86
|
|
|
86
87
|
export namespace StatusCode {
|
|
87
|
-
export const codec = () => {
|
|
88
|
+
export const codec = (): Codec<StatusCode> => {
|
|
88
89
|
return enumeration<StatusCode>(__StatusCodeValues)
|
|
89
90
|
}
|
|
90
91
|
}
|
|
@@ -98,12 +99,12 @@ export namespace FetchResponse {
|
|
|
98
99
|
w.fork()
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
if (
|
|
102
|
+
if (obj.status != null && __StatusCodeValues[obj.status] !== 0) {
|
|
102
103
|
w.uint32(8)
|
|
103
104
|
FetchResponse.StatusCode.codec().encode(obj.status, w)
|
|
104
105
|
}
|
|
105
106
|
|
|
106
|
-
if (
|
|
107
|
+
if ((obj.data != null && obj.data.byteLength > 0)) {
|
|
107
108
|
w.uint32(18)
|
|
108
109
|
w.bytes(obj.data)
|
|
109
110
|
}
|
|
@@ -142,7 +143,7 @@ export namespace FetchResponse {
|
|
|
142
143
|
return _codec
|
|
143
144
|
}
|
|
144
145
|
|
|
145
|
-
export const encode = (obj: FetchResponse): Uint8Array => {
|
|
146
|
+
export const encode = (obj: Partial<FetchResponse>): Uint8Array => {
|
|
146
147
|
return encodeMessage(obj, FetchResponse.codec())
|
|
147
148
|
}
|
|
148
149
|
|
package/src/get-peer.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { peerIdFromString } from '@libp2p/peer-id'
|
|
2
2
|
import type { Multiaddr } from '@multiformats/multiaddr'
|
|
3
3
|
import { isMultiaddr } from '@multiformats/multiaddr'
|
|
4
|
-
import
|
|
4
|
+
import { CodeError } from '@libp2p/interfaces/errors'
|
|
5
5
|
import { codes } from './errors.js'
|
|
6
6
|
import { isPeerId } from '@libp2p/interface-peer-id'
|
|
7
7
|
import type { PeerId } from '@libp2p/interface-peer-id'
|
|
@@ -25,8 +25,8 @@ export function getPeerAddress (peer: PeerId | Multiaddr): { peerId?: PeerId, mu
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
throw
|
|
29
|
-
|
|
28
|
+
throw new CodeError(
|
|
29
|
+
`${peer} is not a PeerId or a Multiaddr`, // eslint-disable-line @typescript-eslint/restrict-template-expressions
|
|
30
30
|
codes.ERR_INVALID_MULTIADDR
|
|
31
31
|
)
|
|
32
32
|
}
|