libp2p 0.36.2 → 0.37.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/LICENSE +3 -21
- package/README.md +13 -10
- package/dist/src/address-manager/index.d.ts +34 -52
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +81 -0
- package/dist/src/address-manager/index.js.map +1 -0
- package/dist/src/circuit/auto-relay.d.ts +24 -85
- package/dist/src/circuit/auto-relay.d.ts.map +1 -1
- package/dist/src/circuit/auto-relay.js +216 -0
- package/dist/src/circuit/auto-relay.js.map +1 -0
- package/dist/src/circuit/circuit/hop.d.ts +26 -53
- package/dist/src/circuit/circuit/hop.d.ts.map +1 -1
- package/dist/src/circuit/circuit/hop.js +138 -0
- package/dist/src/circuit/circuit/hop.js.map +1 -0
- package/dist/src/circuit/circuit/stop.d.ts +18 -10
- package/dist/src/circuit/circuit/stop.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stop.js +49 -0
- package/dist/src/circuit/circuit/stop.js.map +1 -0
- package/dist/src/circuit/circuit/stream-handler.d.ts +19 -38
- package/dist/src/circuit/circuit/stream-handler.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stream-handler.js +59 -0
- package/dist/src/circuit/circuit/stream-handler.js.map +1 -0
- package/dist/src/circuit/circuit/utils.d.ts +3 -6
- package/dist/src/circuit/circuit/utils.d.ts.map +1 -1
- package/dist/src/circuit/circuit/utils.js +43 -0
- package/dist/src/circuit/circuit/utils.js.map +1 -0
- package/dist/src/circuit/constants.d.ts +24 -6
- package/dist/src/circuit/constants.d.ts.map +1 -1
- package/dist/src/circuit/constants.js +26 -0
- package/dist/src/circuit/constants.js.map +1 -0
- package/dist/src/circuit/index.d.ts +41 -74
- package/dist/src/circuit/index.d.ts.map +1 -1
- package/dist/src/circuit/index.js +69 -0
- package/dist/src/circuit/index.js.map +1 -0
- package/dist/src/circuit/listener.d.ts +8 -3
- package/dist/src/circuit/listener.d.ts.map +1 -1
- package/dist/src/circuit/listener.js +62 -0
- package/dist/src/circuit/listener.js.map +1 -0
- package/dist/src/circuit/multicodec.d.ts +1 -1
- package/dist/src/circuit/multicodec.d.ts.map +1 -1
- package/dist/src/circuit/multicodec.js +2 -0
- package/dist/src/circuit/multicodec.js.map +1 -0
- package/dist/src/circuit/pb/index.d.ts +52 -0
- package/dist/src/circuit/pb/index.d.ts.map +1 -0
- package/dist/src/circuit/pb/index.js +98 -0
- package/dist/src/circuit/pb/index.js.map +1 -0
- package/dist/src/circuit/transport.d.ts +18 -78
- package/dist/src/circuit/transport.d.ts.map +1 -1
- package/dist/src/circuit/transport.js +192 -0
- package/dist/src/circuit/transport.js.map +1 -0
- package/dist/src/circuit/utils.d.ts +5 -2
- package/dist/src/circuit/utils.d.ts.map +1 -1
- package/dist/src/circuit/utils.js +11 -0
- package/dist/src/circuit/utils.js.map +1 -0
- package/dist/src/config.d.ts +3 -85
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +91 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/connection-manager/auto-dialler.d.ts +24 -41
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dialler.js +105 -0
- package/dist/src/connection-manager/auto-dialler.js.map +1 -0
- package/dist/src/connection-manager/dialer/auto-dialer.d.ts +16 -0
- package/dist/src/connection-manager/dialer/auto-dialer.d.ts.map +1 -0
- package/dist/src/connection-manager/dialer/auto-dialer.js +37 -0
- package/dist/src/connection-manager/dialer/auto-dialer.js.map +1 -0
- package/dist/src/connection-manager/dialer/dial-request.d.ts +27 -0
- package/dist/src/connection-manager/dialer/dial-request.d.ts.map +1 -0
- package/dist/src/connection-manager/dialer/dial-request.js +83 -0
- package/dist/src/connection-manager/dialer/dial-request.js.map +1 -0
- package/dist/src/connection-manager/dialer/index.d.ts +104 -0
- package/dist/src/connection-manager/dialer/index.d.ts.map +1 -0
- package/dist/src/connection-manager/dialer/index.js +267 -0
- package/dist/src/connection-manager/dialer/index.js.map +1 -0
- package/dist/src/connection-manager/index.d.ts +102 -136
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +333 -0
- package/dist/src/connection-manager/index.js.map +1 -0
- package/dist/src/connection-manager/latency-monitor.d.ts +72 -97
- package/dist/src/connection-manager/latency-monitor.d.ts.map +1 -1
- package/dist/src/connection-manager/latency-monitor.js +220 -0
- package/dist/src/connection-manager/latency-monitor.js.map +1 -0
- package/dist/src/connection-manager/visibility-change-emitter.d.ts +15 -16
- package/dist/src/connection-manager/visibility-change-emitter.d.ts.map +1 -1
- package/dist/src/connection-manager/visibility-change-emitter.js +118 -0
- package/dist/src/connection-manager/visibility-change-emitter.js.map +1 -0
- package/dist/src/constants.d.ts +22 -10
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +27 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/content-routing/index.d.ts +27 -81
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +99 -0
- package/dist/src/content-routing/index.js.map +1 -0
- package/dist/src/content-routing/utils.d.ts +6 -49
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/content-routing/utils.js +42 -0
- package/dist/src/content-routing/utils.js.map +1 -0
- package/dist/src/dht/dht-content-routing.d.ts +10 -24
- package/dist/src/dht/dht-content-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-content-routing.js +32 -0
- package/dist/src/dht/dht-content-routing.js.map +1 -0
- package/dist/src/dht/dht-peer-routing.d.ts +9 -24
- package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-peer-routing.js +26 -0
- package/dist/src/dht/dht-peer-routing.js.map +1 -0
- package/dist/src/dht/dummy-dht.d.ts +20 -0
- package/dist/src/dht/dummy-dht.d.ts.map +1 -0
- package/dist/src/dht/dummy-dht.js +46 -0
- package/dist/src/dht/dummy-dht.js.map +1 -0
- package/dist/src/errors.d.ts +70 -63
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +75 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/fetch/constants.d.ts +1 -1
- package/dist/src/fetch/constants.d.ts.map +1 -1
- package/dist/src/fetch/constants.js +3 -0
- package/dist/src/fetch/constants.js.map +1 -0
- package/dist/src/fetch/index.d.ts +30 -49
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +129 -0
- package/dist/src/fetch/index.js.map +1 -0
- package/dist/src/fetch/pb/proto.d.ts +27 -0
- package/dist/src/fetch/pb/proto.d.ts.map +1 -0
- package/dist/src/fetch/pb/proto.js +50 -0
- package/dist/src/fetch/pb/proto.js.map +1 -0
- package/dist/src/get-peer.d.ts +4 -11
- package/dist/src/get-peer.d.ts.map +1 -1
- package/dist/src/get-peer.js +43 -0
- package/dist/src/get-peer.js.map +1 -0
- package/dist/src/identify/consts.d.ts +9 -9
- package/dist/src/identify/consts.d.ts.map +1 -1
- package/dist/src/identify/consts.js +11 -0
- package/dist/src/identify/consts.js.map +1 -0
- package/dist/src/identify/index.d.ts +42 -96
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +322 -0
- package/dist/src/identify/index.js.map +1 -0
- package/dist/src/identify/pb/message.d.ts +16 -0
- package/dist/src/identify/pb/message.d.ts.map +1 -0
- package/dist/src/identify/pb/message.js +24 -0
- package/dist/src/identify/pb/message.js.map +1 -0
- package/dist/src/index.d.ts +150 -496
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/insecure/index.d.ts +9 -0
- package/dist/src/insecure/index.d.ts.map +1 -0
- package/dist/src/insecure/index.js +81 -0
- package/dist/src/insecure/index.js.map +1 -0
- package/dist/src/insecure/pb/proto.d.ts +29 -0
- package/dist/src/insecure/pb/proto.d.ts.map +1 -0
- package/dist/src/insecure/pb/proto.js +53 -0
- package/dist/src/insecure/pb/proto.js.map +1 -0
- package/dist/src/keychain/cms.d.ts +6 -14
- package/dist/src/keychain/cms.d.ts.map +1 -1
- package/dist/src/keychain/cms.js +129 -0
- package/dist/src/keychain/cms.js.map +1 -0
- package/dist/src/keychain/index.d.ts +60 -81
- package/dist/src/keychain/index.d.ts.map +1 -1
- package/dist/src/keychain/index.js +492 -0
- package/dist/src/keychain/index.js.map +1 -0
- package/dist/src/keychain/util.d.ts +3 -6
- package/dist/src/keychain/util.d.ts.map +1 -1
- package/dist/src/keychain/util.js +79 -0
- package/dist/src/keychain/util.js.map +1 -0
- package/dist/src/libp2p.d.ts +80 -0
- package/dist/src/libp2p.d.ts.map +1 -0
- package/dist/src/libp2p.js +397 -0
- package/dist/src/libp2p.js.map +1 -0
- package/dist/src/metrics/index.d.ts +47 -104
- package/dist/src/metrics/index.d.ts.map +1 -1
- package/dist/src/metrics/index.js +231 -0
- package/dist/src/metrics/index.js.map +1 -0
- package/dist/src/metrics/moving-average.d.ts +14 -0
- package/dist/src/metrics/moving-average.d.ts.map +1 -0
- package/dist/src/metrics/moving-average.js +40 -0
- package/dist/src/metrics/moving-average.js.map +1 -0
- package/dist/src/metrics/stats.d.ts +41 -93
- package/dist/src/metrics/stats.d.ts.map +1 -1
- package/dist/src/metrics/stats.js +183 -0
- package/dist/src/metrics/stats.js.map +1 -0
- package/dist/src/nat-manager.d.ts +42 -99
- package/dist/src/nat-manager.d.ts.map +1 -1
- package/dist/src/nat-manager.js +114 -0
- package/dist/src/nat-manager.js.map +1 -0
- package/dist/src/peer-record-updater.d.ts +15 -0
- package/dist/src/peer-record-updater.d.ts.map +1 -0
- package/dist/src/peer-record-updater.js +44 -0
- package/dist/src/peer-record-updater.js.map +1 -0
- package/dist/src/peer-routing.d.ts +40 -84
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +108 -0
- package/dist/src/peer-routing.js.map +1 -0
- package/dist/src/ping/constants.d.ts +4 -4
- package/dist/src/ping/constants.d.ts.map +1 -1
- package/dist/src/ping/constants.js +5 -0
- package/dist/src/ping/constants.js.map +1 -0
- package/dist/src/ping/index.d.ts +17 -31
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +57 -0
- package/dist/src/ping/index.js.map +1 -0
- package/dist/src/pnet/crypto.d.ts +15 -5
- package/dist/src/pnet/crypto.d.ts.map +1 -1
- package/dist/src/pnet/crypto.js +60 -0
- package/dist/src/pnet/crypto.js.map +1 -0
- package/dist/src/pnet/errors.d.ts +5 -5
- package/dist/src/pnet/errors.d.ts.map +1 -1
- package/dist/src/pnet/errors.js +6 -0
- package/dist/src/pnet/errors.js.map +1 -0
- package/dist/src/pnet/index.d.ts +12 -20
- package/dist/src/pnet/index.d.ts.map +1 -1
- package/dist/src/pnet/index.js +67 -0
- package/dist/src/pnet/index.js.map +1 -0
- package/dist/src/pnet/key-generator.d.ts +3 -7
- package/dist/src/pnet/key-generator.d.ts.map +1 -1
- package/dist/src/pnet/key-generator.js +25 -0
- package/dist/src/pnet/key-generator.js.map +1 -0
- package/dist/src/pubsub/dummy-pubsub.d.ts +17 -0
- package/dist/src/pubsub/dummy-pubsub.d.ts.map +1 -0
- package/dist/src/pubsub/dummy-pubsub.js +37 -0
- package/dist/src/pubsub/dummy-pubsub.js.map +1 -0
- package/dist/src/registrar.d.ts +26 -65
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +144 -0
- package/dist/src/registrar.js.map +1 -0
- package/dist/src/transport-manager.d.ts +36 -82
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +223 -0
- package/dist/src/transport-manager.js.map +1 -0
- package/dist/src/upgrader.d.ts +49 -129
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +402 -0
- package/dist/src/upgrader.js.map +1 -0
- package/dist/src/version.d.ts +3 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/src/version.js +3 -0
- package/dist/src/version.js.map +1 -0
- package/package.json +144 -201
- package/src/address-manager/index.ts +130 -0
- package/src/circuit/README.md +16 -11
- package/src/circuit/auto-relay.ts +286 -0
- package/src/circuit/circuit/hop.ts +211 -0
- package/src/circuit/circuit/stop.ts +78 -0
- package/src/circuit/circuit/stream-handler.ts +86 -0
- package/src/circuit/circuit/{utils.js → utils.ts} +9 -25
- package/src/circuit/constants.ts +31 -0
- package/src/circuit/index.ts +120 -0
- package/src/circuit/listener.ts +82 -0
- package/src/circuit/multicodec.ts +2 -0
- package/src/circuit/{protocol → pb}/index.proto +1 -1
- package/src/circuit/pb/index.ts +117 -0
- package/src/circuit/transport.ts +219 -0
- package/src/circuit/utils.ts +12 -0
- package/src/config.ts +99 -0
- package/src/connection-manager/auto-dialler.ts +154 -0
- package/src/connection-manager/dialer/auto-dialer.ts +59 -0
- package/src/{dialer/dial-request.js → connection-manager/dialer/dial-request.ts} +60 -51
- package/src/connection-manager/dialer/index.ts +382 -0
- package/src/connection-manager/index.ts +508 -0
- package/src/connection-manager/latency-monitor.ts +319 -0
- package/src/connection-manager/{visibility-change-emitter.js → visibility-change-emitter.ts} +48 -38
- package/src/constants.ts +31 -0
- package/src/content-routing/index.ts +144 -0
- package/src/content-routing/utils.ts +54 -0
- package/src/dht/dht-content-routing.ts +43 -0
- package/src/dht/dht-peer-routing.ts +35 -0
- package/src/dht/dummy-dht.ts +60 -0
- package/src/errors.ts +73 -0
- package/src/fetch/README.md +1 -1
- package/src/fetch/constants.ts +3 -0
- package/src/fetch/index.ts +167 -0
- package/src/fetch/{proto.proto → pb/proto.proto} +0 -0
- package/src/fetch/pb/proto.ts +65 -0
- package/src/get-peer.ts +57 -0
- package/src/identify/consts.ts +13 -0
- package/src/identify/index.ts +445 -0
- package/src/identify/{message.proto → pb/message.proto} +0 -0
- package/src/identify/pb/message.ts +37 -0
- package/src/index.ts +220 -0
- package/src/insecure/index.ts +101 -0
- package/src/insecure/{proto.proto → pb/proto.proto} +0 -0
- package/src/insecure/pb/proto.ts +68 -0
- package/src/keychain/{cms.js → cms.ts} +62 -58
- package/src/keychain/index.ts +587 -0
- package/src/keychain/{util.js → util.ts} +7 -17
- package/src/libp2p.ts +538 -0
- package/src/metrics/index.ts +310 -0
- package/src/metrics/moving-average.ts +53 -0
- package/src/metrics/stats.ts +238 -0
- package/src/nat-manager.ts +194 -0
- package/src/peer-record-updater.ts +55 -0
- package/src/peer-routing.ts +186 -0
- package/src/ping/README.md +1 -1
- package/src/ping/constants.ts +5 -0
- package/src/ping/index.ts +84 -0
- package/src/pnet/README.md +2 -2
- package/src/pnet/crypto.ts +67 -0
- package/src/pnet/errors.ts +5 -0
- package/src/pnet/index.ts +97 -0
- package/src/pnet/key-generator.ts +28 -0
- package/src/pubsub/dummy-pubsub.ts +51 -0
- package/src/registrar.ts +189 -0
- package/src/transport-manager.ts +281 -0
- package/src/upgrader.ts +499 -0
- package/src/version.ts +3 -0
- package/dist/index.min.js +0 -55
- package/dist/src/circuit/protocol/index.d.ts +0 -173
- package/dist/src/dialer/dial-request.d.ts +0 -55
- package/dist/src/dialer/dial-request.d.ts.map +0 -1
- package/dist/src/dialer/index.d.ts +0 -182
- package/dist/src/dialer/index.d.ts.map +0 -1
- package/dist/src/fetch/proto.d.ts +0 -134
- package/dist/src/identify/message.d.ts +0 -95
- package/dist/src/insecure/plaintext.d.ts +0 -12
- package/dist/src/insecure/plaintext.d.ts.map +0 -1
- package/dist/src/insecure/proto.d.ts +0 -128
- package/dist/src/metrics/old-peers.d.ts +0 -3
- package/dist/src/metrics/old-peers.d.ts.map +0 -1
- package/dist/src/metrics/tracked-map.d.ts +0 -8
- package/dist/src/metrics/tracked-map.d.ts.map +0 -1
- package/dist/src/peer-store/address-book.d.ts +0 -67
- package/dist/src/peer-store/address-book.d.ts.map +0 -1
- package/dist/src/peer-store/index.d.ts +0 -58
- package/dist/src/peer-store/index.d.ts.map +0 -1
- package/dist/src/peer-store/key-book.d.ts +0 -40
- package/dist/src/peer-store/key-book.d.ts.map +0 -1
- package/dist/src/peer-store/metadata-book.d.ts +0 -58
- package/dist/src/peer-store/metadata-book.d.ts.map +0 -1
- package/dist/src/peer-store/pb/peer.d.ts +0 -222
- package/dist/src/peer-store/proto-book.d.ts +0 -43
- package/dist/src/peer-store/proto-book.d.ts.map +0 -1
- package/dist/src/peer-store/store.d.ts +0 -73
- package/dist/src/peer-store/store.d.ts.map +0 -1
- package/dist/src/peer-store/types.d.ts +0 -202
- package/dist/src/peer-store/types.d.ts.map +0 -1
- package/dist/src/ping/util.d.ts +0 -5
- package/dist/src/ping/util.d.ts.map +0 -1
- package/dist/src/pubsub-adapter.d.ts +0 -22
- package/dist/src/pubsub-adapter.d.ts.map +0 -1
- package/dist/src/record/envelope/envelope.d.ts +0 -77
- package/dist/src/record/envelope/index.d.ts +0 -80
- package/dist/src/record/envelope/index.d.ts.map +0 -1
- package/dist/src/record/peer-record/consts.d.ts +0 -4
- package/dist/src/record/peer-record/consts.d.ts.map +0 -1
- package/dist/src/record/peer-record/index.d.ts +0 -60
- package/dist/src/record/peer-record/index.d.ts.map +0 -1
- package/dist/src/record/peer-record/peer-record.d.ts +0 -133
- package/dist/src/record/utils.d.ts +0 -12
- package/dist/src/record/utils.d.ts.map +0 -1
- package/dist/src/types.d.ts +0 -90
- package/dist/src/types.d.ts.map +0 -1
- package/src/address-manager/index.js +0 -96
- package/src/circuit/auto-relay.js +0 -302
- package/src/circuit/circuit/hop.js +0 -205
- package/src/circuit/circuit/stop.js +0 -81
- package/src/circuit/circuit/stream-handler.js +0 -94
- package/src/circuit/constants.js +0 -12
- package/src/circuit/index.js +0 -102
- package/src/circuit/listener.js +0 -75
- package/src/circuit/multicodec.js +0 -5
- package/src/circuit/protocol/index.d.ts +0 -173
- package/src/circuit/protocol/index.js +0 -530
- package/src/circuit/transport.js +0 -229
- package/src/circuit/utils.js +0 -17
- package/src/config.js +0 -114
- package/src/connection-manager/auto-dialler.js +0 -132
- package/src/connection-manager/index.js +0 -374
- package/src/connection-manager/latency-monitor.js +0 -264
- package/src/constants.js +0 -18
- package/src/content-routing/index.js +0 -163
- package/src/content-routing/utils.js +0 -89
- package/src/dht/dht-content-routing.js +0 -44
- package/src/dht/dht-peer-routing.js +0 -51
- package/src/dialer/index.js +0 -376
- package/src/errors.js +0 -66
- package/src/fetch/constants.js +0 -6
- package/src/fetch/index.js +0 -159
- package/src/fetch/proto.d.ts +0 -134
- package/src/fetch/proto.js +0 -333
- package/src/get-peer.js +0 -49
- package/src/identify/consts.js +0 -15
- package/src/identify/index.js +0 -384
- package/src/identify/message.d.ts +0 -95
- package/src/identify/message.js +0 -328
- package/src/index.js +0 -813
- package/src/insecure/plaintext.js +0 -95
- package/src/insecure/proto.d.ts +0 -128
- package/src/insecure/proto.js +0 -371
- package/src/keychain/index.js +0 -561
- package/src/metrics/index.js +0 -290
- package/src/metrics/old-peers.js +0 -16
- package/src/metrics/stats.js +0 -270
- package/src/metrics/tracked-map.js +0 -94
- package/src/nat-manager.js +0 -197
- package/src/peer-routing.js +0 -176
- package/src/peer-store/README.md +0 -145
- package/src/peer-store/address-book.js +0 -382
- package/src/peer-store/index.js +0 -121
- package/src/peer-store/key-book.js +0 -141
- package/src/peer-store/metadata-book.js +0 -250
- package/src/peer-store/pb/peer.d.ts +0 -222
- package/src/peer-store/pb/peer.js +0 -643
- package/src/peer-store/pb/peer.proto +0 -31
- package/src/peer-store/proto-book.js +0 -237
- package/src/peer-store/store.js +0 -263
- package/src/peer-store/types.ts +0 -245
- package/src/ping/constants.js +0 -8
- package/src/ping/index.js +0 -84
- package/src/ping/util.js +0 -18
- package/src/pnet/crypto.js +0 -84
- package/src/pnet/errors.js +0 -7
- package/src/pnet/index.js +0 -86
- package/src/pnet/key-generator.js +0 -33
- package/src/pubsub-adapter.js +0 -61
- package/src/record/README.md +0 -130
- package/src/record/envelope/envelope.d.ts +0 -77
- package/src/record/envelope/envelope.js +0 -243
- package/src/record/envelope/envelope.proto +0 -19
- package/src/record/envelope/index.js +0 -183
- package/src/record/peer-record/consts.js +0 -14
- package/src/record/peer-record/index.js +0 -113
- package/src/record/peer-record/peer-record.d.ts +0 -133
- package/src/record/peer-record/peer-record.js +0 -367
- package/src/record/peer-record/peer-record.proto +0 -18
- package/src/record/utils.js +0 -25
- package/src/registrar.js +0 -127
- package/src/transport-manager.js +0 -269
- package/src/types.ts +0 -98
- package/src/upgrader.js +0 -492
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"visibility-change-emitter.js","sourceRoot":"","sources":["../../../src/connection-manager/visibility-change-emitter.ts"],"names":[],"mappings":"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"}
|
package/dist/src/constants.d.ts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
/**
|
|
2
|
+
* How long in ms a dial attempt is allowed to take
|
|
3
|
+
*/
|
|
4
|
+
export declare const DIAL_TIMEOUT = 30000;
|
|
5
|
+
/**
|
|
6
|
+
* Maximum allowed concurrent dials
|
|
7
|
+
*/
|
|
8
|
+
export declare const MAX_PARALLEL_DIALS = 100;
|
|
9
|
+
/**
|
|
10
|
+
* Allowed parallel dials per DialRequest
|
|
11
|
+
*/
|
|
12
|
+
export declare const MAX_PER_PEER_DIALS = 4;
|
|
13
|
+
/**
|
|
14
|
+
* Maximum number of allowed addresses to attempt to dial
|
|
15
|
+
*/
|
|
16
|
+
export declare const MAX_ADDRS_TO_DIAL = 25;
|
|
17
|
+
export declare const METRICS: {
|
|
18
|
+
computeThrottleMaxQueueSize: number;
|
|
19
|
+
computeThrottleTimeout: number;
|
|
20
|
+
movingAverageIntervals: number[];
|
|
21
|
+
maxOldPeersRetention: number;
|
|
22
|
+
};
|
|
11
23
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,eAAO,MAAM,YAAY,QAAO,CAAA;AAEhC;;GAEG;AACH,eAAO,MAAM,kBAAkB,MAAM,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,kBAAkB,IAAI,CAAA;AAEnC;;GAEG;AACH,eAAO,MAAM,iBAAiB,KAAK,CAAA;AAEnC,eAAO,MAAM,OAAO;;;;;CASnB,CAAA"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How long in ms a dial attempt is allowed to take
|
|
3
|
+
*/
|
|
4
|
+
export const DIAL_TIMEOUT = 30e3;
|
|
5
|
+
/**
|
|
6
|
+
* Maximum allowed concurrent dials
|
|
7
|
+
*/
|
|
8
|
+
export const MAX_PARALLEL_DIALS = 100;
|
|
9
|
+
/**
|
|
10
|
+
* Allowed parallel dials per DialRequest
|
|
11
|
+
*/
|
|
12
|
+
export const MAX_PER_PEER_DIALS = 4;
|
|
13
|
+
/**
|
|
14
|
+
* Maximum number of allowed addresses to attempt to dial
|
|
15
|
+
*/
|
|
16
|
+
export const MAX_ADDRS_TO_DIAL = 25;
|
|
17
|
+
export const METRICS = {
|
|
18
|
+
computeThrottleMaxQueueSize: 1000,
|
|
19
|
+
computeThrottleTimeout: 2000,
|
|
20
|
+
movingAverageIntervals: [
|
|
21
|
+
60 * 1000,
|
|
22
|
+
5 * 60 * 1000,
|
|
23
|
+
15 * 60 * 1000 // 15 minutes
|
|
24
|
+
],
|
|
25
|
+
maxOldPeersRetention: 50
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AACA;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,IAAI,CAAA;AAEhC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,CAAA;AAErC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,CAAA;AAEnC;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAA;AAEnC,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,2BAA2B,EAAE,IAAI;IACjC,sBAAsB,EAAE,IAAI;IAC5B,sBAAsB,EAAE;QACtB,EAAE,GAAG,IAAI;QACT,CAAC,GAAG,EAAE,GAAG,IAAI;QACb,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,aAAa;KAC7B;IACD,oBAAoB,EAAE,EAAE;CACzB,CAAA"}
|
|
@@ -1,97 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
constructor(libp2p: import('..'));
|
|
19
|
-
libp2p: import("..");
|
|
20
|
-
/** @type {ContentRoutingModule[]} */
|
|
21
|
-
routers: ContentRoutingModule[];
|
|
22
|
-
dht: any;
|
|
1
|
+
import type { ContentRouting } from '@libp2p/interfaces/content-routing';
|
|
2
|
+
import type { AbortOptions } from '@libp2p/interfaces';
|
|
3
|
+
import type { Startable } from '@libp2p/interfaces/startable';
|
|
4
|
+
import type { CID } from 'multiformats/cid';
|
|
5
|
+
import type { Components } from '@libp2p/interfaces/components';
|
|
6
|
+
export interface CompoundContentRoutingInit {
|
|
7
|
+
routers: ContentRouting[];
|
|
8
|
+
}
|
|
9
|
+
export declare class CompoundContentRouting implements ContentRouting, Startable {
|
|
10
|
+
private readonly routers;
|
|
11
|
+
private started;
|
|
12
|
+
private readonly components;
|
|
13
|
+
constructor(components: Components, init: CompoundContentRoutingInit);
|
|
14
|
+
isStarted(): boolean;
|
|
15
|
+
start(): Promise<void>;
|
|
16
|
+
stop(): Promise<void>;
|
|
23
17
|
/**
|
|
24
|
-
* Iterates over all content routers in parallel to find providers of the given key
|
|
25
|
-
*
|
|
26
|
-
* @param {CID} key - The CID key of the content to find
|
|
27
|
-
* @param {object} [options]
|
|
28
|
-
* @param {number} [options.timeout] - How long the query should run
|
|
29
|
-
* @param {number} [options.maxNumProviders] - maximum number of providers to find
|
|
30
|
-
* @returns {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>}
|
|
18
|
+
* Iterates over all content routers in parallel to find providers of the given key
|
|
31
19
|
*/
|
|
32
|
-
findProviders(key: CID, options?:
|
|
33
|
-
timeout?: number | undefined;
|
|
34
|
-
maxNumProviders?: number | undefined;
|
|
35
|
-
} | undefined): AsyncIterable<{
|
|
36
|
-
id: PeerId;
|
|
37
|
-
multiaddrs: Multiaddr[];
|
|
38
|
-
}>;
|
|
20
|
+
findProviders(key: CID, options?: AbortOptions): AsyncGenerator<import("@libp2p/interfaces/dist/src/peer-info").PeerInfo, void, unknown>;
|
|
39
21
|
/**
|
|
40
22
|
* Iterates over all content routers in parallel to notify it is
|
|
41
|
-
* a provider of the given key
|
|
42
|
-
*
|
|
43
|
-
* @param {CID} key - The CID key of the content to find
|
|
44
|
-
* @returns {Promise<void>}
|
|
23
|
+
* a provider of the given key
|
|
45
24
|
*/
|
|
46
|
-
provide(key: CID): Promise<void>;
|
|
25
|
+
provide(key: CID, options?: AbortOptions): Promise<void>;
|
|
47
26
|
/**
|
|
48
|
-
* Store the given key/value pair in the
|
|
49
|
-
*
|
|
50
|
-
* @param {Uint8Array} key
|
|
51
|
-
* @param {Uint8Array} value
|
|
52
|
-
* @param {Object} [options] - put options
|
|
53
|
-
* @param {number} [options.minPeers] - minimum number of peers required to successfully put
|
|
54
|
-
* @returns {Promise<void>}
|
|
27
|
+
* Store the given key/value pair in the available content routings
|
|
55
28
|
*/
|
|
56
|
-
put(key: Uint8Array, value: Uint8Array, options?:
|
|
57
|
-
minPeers?: number | undefined;
|
|
58
|
-
} | undefined): Promise<void>;
|
|
29
|
+
put(key: Uint8Array, value: Uint8Array, options?: AbortOptions): Promise<void>;
|
|
59
30
|
/**
|
|
60
31
|
* Get the value to the given key.
|
|
61
32
|
* Times out after 1 minute by default.
|
|
62
|
-
*
|
|
63
|
-
* @param {Uint8Array} key
|
|
64
|
-
* @param {Object} [options] - get options
|
|
65
|
-
* @param {number} [options.timeout] - optional timeout (default: 60000)
|
|
66
|
-
* @returns {Promise<GetData>}
|
|
67
33
|
*/
|
|
68
|
-
get(key: Uint8Array, options?:
|
|
69
|
-
timeout?: number | undefined;
|
|
70
|
-
} | undefined): Promise<GetData>;
|
|
34
|
+
get(key: Uint8Array, options?: AbortOptions): Promise<Uint8Array>;
|
|
71
35
|
/**
|
|
72
|
-
* Get the `n` values to the given key without sorting
|
|
73
|
-
*
|
|
74
|
-
* @param {Uint8Array} key
|
|
75
|
-
* @param {number} nVals
|
|
76
|
-
* @param {Object} [options] - get options
|
|
77
|
-
* @param {number} [options.timeout] - optional timeout (default: 60000)
|
|
36
|
+
* Get the `n` values to the given key without sorting
|
|
78
37
|
*/
|
|
79
|
-
getMany(key: Uint8Array, nVals: number, options
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
from: any;
|
|
83
|
-
val: any;
|
|
38
|
+
getMany(key: Uint8Array, nVals: number, options: AbortOptions): AsyncGenerator<{
|
|
39
|
+
from: import("@libp2p/interfaces/dist/src/peer-id").PeerId;
|
|
40
|
+
val: Uint8Array;
|
|
84
41
|
}, void, unknown>;
|
|
85
42
|
}
|
|
86
|
-
declare namespace ContentRouting {
|
|
87
|
-
export { PeerId, Multiaddr, CID, ContentRoutingModule, GetData };
|
|
88
|
-
}
|
|
89
|
-
type ContentRoutingModule = import('libp2p-interfaces/src/content-routing/types').ContentRouting;
|
|
90
|
-
type CID = import('multiformats/cid').CID;
|
|
91
|
-
type PeerId = import('peer-id');
|
|
92
|
-
type Multiaddr = import('multiaddr').Multiaddr;
|
|
93
|
-
type GetData = {
|
|
94
|
-
from: PeerId;
|
|
95
|
-
val: Uint8Array;
|
|
96
|
-
};
|
|
97
43
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/content-routing/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/content-routing/index.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAE/D,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,cAAc,EAAE,CAAA;CAC1B;AAED,qBAAa,sBAAuB,YAAW,cAAc,EAAE,SAAS;IACtE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkB;IAC1C,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;gBAE1B,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,0BAA0B;IAMrE,SAAS;IAIH,KAAK;IAIL,IAAI;IAIV;;OAEG;IACK,aAAa,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAiB;IAe3D;;;OAGG;IACG,OAAO,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAiB;IAQnD;;OAEG;IACG,GAAG,CAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY;IAYrE;;;OAGG;IACG,GAAG,CAAE,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;IAkBxE;;OAEG;IACK,OAAO,CAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY;;;;CA8BvE"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import errCode from 'err-code';
|
|
2
|
+
import { messages, codes } from '../errors.js';
|
|
3
|
+
import { storeAddresses, uniquePeers, requirePeers } from './utils.js';
|
|
4
|
+
import drain from 'it-drain';
|
|
5
|
+
import merge from 'it-merge';
|
|
6
|
+
import { pipe } from 'it-pipe';
|
|
7
|
+
export class CompoundContentRouting {
|
|
8
|
+
constructor(components, init) {
|
|
9
|
+
this.routers = init.routers ?? [];
|
|
10
|
+
this.started = false;
|
|
11
|
+
this.components = components;
|
|
12
|
+
}
|
|
13
|
+
isStarted() {
|
|
14
|
+
return this.started;
|
|
15
|
+
}
|
|
16
|
+
async start() {
|
|
17
|
+
this.started = true;
|
|
18
|
+
}
|
|
19
|
+
async stop() {
|
|
20
|
+
this.started = false;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Iterates over all content routers in parallel to find providers of the given key
|
|
24
|
+
*/
|
|
25
|
+
async *findProviders(key, options = {}) {
|
|
26
|
+
if (this.routers.length === 0) {
|
|
27
|
+
throw errCode(new Error('No content this.routers available'), codes.ERR_NO_ROUTERS_AVAILABLE);
|
|
28
|
+
}
|
|
29
|
+
yield* pipe(merge(...this.routers.map(router => router.findProviders(key, options))), (source) => storeAddresses(source, this.components.getPeerStore()), (source) => uniquePeers(source), (source) => requirePeers(source));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Iterates over all content routers in parallel to notify it is
|
|
33
|
+
* a provider of the given key
|
|
34
|
+
*/
|
|
35
|
+
async provide(key, options = {}) {
|
|
36
|
+
if (this.routers.length === 0) {
|
|
37
|
+
throw errCode(new Error('No content routers available'), codes.ERR_NO_ROUTERS_AVAILABLE);
|
|
38
|
+
}
|
|
39
|
+
await Promise.all(this.routers.map(async (router) => await router.provide(key, options)));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Store the given key/value pair in the available content routings
|
|
43
|
+
*/
|
|
44
|
+
async put(key, value, options) {
|
|
45
|
+
if (!this.isStarted()) {
|
|
46
|
+
throw errCode(new Error(messages.NOT_STARTED_YET), codes.DHT_NOT_STARTED);
|
|
47
|
+
}
|
|
48
|
+
const dht = this.components.getDHT();
|
|
49
|
+
if (dht != null) {
|
|
50
|
+
await drain(dht.put(key, value, options));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the value to the given key.
|
|
55
|
+
* Times out after 1 minute by default.
|
|
56
|
+
*/
|
|
57
|
+
async get(key, options) {
|
|
58
|
+
if (!this.isStarted()) {
|
|
59
|
+
throw errCode(new Error(messages.NOT_STARTED_YET), codes.DHT_NOT_STARTED);
|
|
60
|
+
}
|
|
61
|
+
const dht = this.components.getDHT();
|
|
62
|
+
if (dht != null) {
|
|
63
|
+
for await (const event of dht.get(key, options)) {
|
|
64
|
+
if (event.name === 'VALUE') {
|
|
65
|
+
return event.value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
throw errCode(new Error(messages.NOT_FOUND), codes.ERR_NOT_FOUND);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get the `n` values to the given key without sorting
|
|
73
|
+
*/
|
|
74
|
+
async *getMany(key, nVals, options) {
|
|
75
|
+
if (!this.isStarted()) {
|
|
76
|
+
throw errCode(new Error(messages.NOT_STARTED_YET), codes.DHT_NOT_STARTED);
|
|
77
|
+
}
|
|
78
|
+
if (nVals == null || nVals === 0) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
let gotValues = 0;
|
|
82
|
+
const dht = this.components.getDHT();
|
|
83
|
+
if (dht != null) {
|
|
84
|
+
for await (const event of dht.get(key, options)) {
|
|
85
|
+
if (event.name === 'VALUE') {
|
|
86
|
+
yield { from: event.from, val: event.value };
|
|
87
|
+
gotValues++;
|
|
88
|
+
if (gotValues === nVals) {
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (gotValues === 0) {
|
|
95
|
+
throw errCode(new Error(messages.NOT_FOUND), codes.ERR_NOT_FOUND);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/content-routing/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,59 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* @typedef {import('peer-id')} PeerId
|
|
5
|
-
* @typedef {import('multiaddr').Multiaddr} Multiaddr
|
|
6
|
-
*/
|
|
1
|
+
import type { Source } from 'it-stream-types';
|
|
2
|
+
import type { PeerInfo } from '@libp2p/interfaces/peer-info';
|
|
3
|
+
import type { PeerStore } from '@libp2p/interfaces/peer-store';
|
|
7
4
|
/**
|
|
8
5
|
* Store the multiaddrs from every peer in the passed peer store
|
|
9
|
-
*
|
|
10
|
-
* @param {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>} source
|
|
11
|
-
* @param {import('../peer-store/types').PeerStore} peerStore
|
|
12
6
|
*/
|
|
13
|
-
export function storeAddresses(source:
|
|
14
|
-
id: PeerId;
|
|
15
|
-
multiaddrs: Multiaddr[];
|
|
16
|
-
}>, peerStore: import('../peer-store/types').PeerStore): AsyncGenerator<{
|
|
17
|
-
id: PeerId;
|
|
18
|
-
multiaddrs: Multiaddr[];
|
|
19
|
-
}, void, undefined>;
|
|
7
|
+
export declare function storeAddresses(source: Source<PeerInfo>, peerStore: PeerStore): AsyncGenerator<PeerInfo, void, undefined>;
|
|
20
8
|
/**
|
|
21
9
|
* Filter peers by unique peer id
|
|
22
|
-
*
|
|
23
|
-
* @param {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>} source
|
|
24
10
|
*/
|
|
25
|
-
export function uniquePeers(source:
|
|
26
|
-
id: PeerId;
|
|
27
|
-
multiaddrs: Multiaddr[];
|
|
28
|
-
}>): AsyncGenerator<{
|
|
29
|
-
id: PeerId;
|
|
30
|
-
multiaddrs: Multiaddr[];
|
|
31
|
-
}, void, unknown>;
|
|
11
|
+
export declare function uniquePeers(source: Source<PeerInfo>): AsyncGenerator<PeerInfo, void, unknown>;
|
|
32
12
|
/**
|
|
33
13
|
* Require at least `min` peers to be yielded from `source`
|
|
34
|
-
*
|
|
35
|
-
* @param {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>} source
|
|
36
|
-
* @param {number} min
|
|
37
|
-
*/
|
|
38
|
-
export function requirePeers(source: AsyncIterable<{
|
|
39
|
-
id: PeerId;
|
|
40
|
-
multiaddrs: Multiaddr[];
|
|
41
|
-
}>, min?: number): AsyncGenerator<{
|
|
42
|
-
id: PeerId;
|
|
43
|
-
multiaddrs: Multiaddr[];
|
|
44
|
-
}, void, unknown>;
|
|
45
|
-
/**
|
|
46
|
-
* If `max` is passed, only take that number of peers from the source
|
|
47
|
-
* otherwise take all the peers
|
|
48
|
-
*
|
|
49
|
-
* @param {AsyncIterable<{ id: PeerId, multiaddrs: Multiaddr[] }>} source
|
|
50
|
-
* @param {number} [max]
|
|
51
14
|
*/
|
|
52
|
-
export function
|
|
53
|
-
id: PeerId;
|
|
54
|
-
multiaddrs: Multiaddr[];
|
|
55
|
-
}>, max?: number | undefined): AsyncIterable<{
|
|
56
|
-
id: PeerId;
|
|
57
|
-
multiaddrs: Multiaddr[];
|
|
58
|
-
}>;
|
|
15
|
+
export declare function requirePeers(source: Source<PeerInfo>, min?: number): AsyncGenerator<PeerInfo, void, unknown>;
|
|
59
16
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/content-routing/utils.
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/content-routing/utils.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAC7C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAC5D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAE9D;;GAEG;AACH,wBAAwB,cAAc,CAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,SAAS,6CAOrF;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,2CAcpD;AAED;;GAEG;AACH,wBAAwB,YAAY,CAAE,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,GAAG,GAAE,MAAU,2CAY9E"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import errCode from 'err-code';
|
|
2
|
+
import filter from 'it-filter';
|
|
3
|
+
import map from 'it-map';
|
|
4
|
+
/**
|
|
5
|
+
* Store the multiaddrs from every peer in the passed peer store
|
|
6
|
+
*/
|
|
7
|
+
export async function* storeAddresses(source, peerStore) {
|
|
8
|
+
yield* map(source, async (peer) => {
|
|
9
|
+
// ensure we have the addresses for a given peer
|
|
10
|
+
await peerStore.addressBook.add(peer.id, peer.multiaddrs);
|
|
11
|
+
return peer;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Filter peers by unique peer id
|
|
16
|
+
*/
|
|
17
|
+
export function uniquePeers(source) {
|
|
18
|
+
/** @type Set<string> */
|
|
19
|
+
const seen = new Set();
|
|
20
|
+
return filter(source, (peer) => {
|
|
21
|
+
// dedupe by peer id
|
|
22
|
+
if (seen.has(peer.id.toString())) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
seen.add(peer.id.toString());
|
|
26
|
+
return true;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Require at least `min` peers to be yielded from `source`
|
|
31
|
+
*/
|
|
32
|
+
export async function* requirePeers(source, min = 1) {
|
|
33
|
+
let seen = 0;
|
|
34
|
+
for await (const peer of source) {
|
|
35
|
+
seen++;
|
|
36
|
+
yield peer;
|
|
37
|
+
}
|
|
38
|
+
if (seen < min) {
|
|
39
|
+
throw errCode(new Error('not found'), 'NOT_FOUND');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/content-routing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,MAAM,MAAM,WAAW,CAAA;AAC9B,OAAO,GAAG,MAAM,QAAQ,CAAA;AAKxB;;GAEG;AACH,MAAM,CAAC,KAAK,SAAU,CAAC,CAAC,cAAc,CAAE,MAAwB,EAAE,SAAoB;IACpF,KAAM,CAAC,CAAC,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,EAAE;QACjC,gDAAgD;QAChD,MAAM,SAAS,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,UAAU,CAAC,CAAA;QAEzD,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,WAAW,CAAE,MAAwB;IACnD,wBAAwB;IACxB,MAAM,IAAI,GAAG,IAAI,GAAG,EAAE,CAAA;IAEtB,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QAC7B,oBAAoB;QACpB,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,EAAE;YAChC,OAAO,KAAK,CAAA;SACb;QAED,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAA;QAE5B,OAAO,IAAI,CAAA;IACb,CAAC,CAAC,CAAA;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,SAAU,CAAC,CAAC,YAAY,CAAE,MAAwB,EAAE,MAAc,CAAC;IAC7E,IAAI,IAAI,GAAG,CAAC,CAAA;IAEZ,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,EAAE;QAC/B,IAAI,EAAE,CAAA;QAEN,MAAM,IAAI,CAAA;KACX;IAED,IAAI,IAAI,GAAG,GAAG,EAAE;QACd,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,CAAA;KACnD;AACH,CAAC"}
|
|
@@ -1,30 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @typedef {import('peer-id')} PeerId
|
|
6
|
-
* @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRoutingModule
|
|
7
|
-
* @typedef {import('multiformats/cid').CID} CID
|
|
8
|
-
*/
|
|
1
|
+
import type { DHT } from '@libp2p/interfaces/dht';
|
|
2
|
+
import type { ContentRouting } from '@libp2p/interfaces/content-routing';
|
|
3
|
+
import type { CID } from 'multiformats/cid';
|
|
4
|
+
import type { AbortOptions } from '@libp2p/interfaces';
|
|
9
5
|
/**
|
|
10
6
|
* Wrapper class to convert events into returned values
|
|
11
|
-
*
|
|
12
|
-
* @implements {ContentRoutingModule}
|
|
13
7
|
*/
|
|
14
|
-
export class DHTContentRouting implements
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
*/
|
|
18
|
-
constructor(dht: import('libp2p-kad-dht').DHT);
|
|
19
|
-
_dht: import("libp2p-kad-dht/dist/src/types").DHT;
|
|
20
|
-
/**
|
|
21
|
-
* @param {CID} cid
|
|
22
|
-
*/
|
|
8
|
+
export declare class DHTContentRouting implements ContentRouting {
|
|
9
|
+
private readonly dht;
|
|
10
|
+
constructor(dht: DHT);
|
|
23
11
|
provide(cid: CID): Promise<void>;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*/
|
|
28
|
-
findProviders(cid: CID, options: any): AsyncGenerator<import("libp2p-kad-dht/dist/src/types").PeerData, void, undefined>;
|
|
12
|
+
findProviders(cid: CID, options?: AbortOptions): AsyncGenerator<import("@libp2p/interfaces/dist/src/peer-info").PeerInfo, void, undefined>;
|
|
13
|
+
put(key: Uint8Array, value: Uint8Array, options?: AbortOptions): Promise<void>;
|
|
14
|
+
get(key: Uint8Array, options?: AbortOptions): Promise<Uint8Array>;
|
|
29
15
|
}
|
|
30
16
|
//# sourceMappingURL=dht-content-routing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dht-content-routing.d.ts","sourceRoot":"","sources":["../../../src/dht/dht-content-routing.
|
|
1
|
+
{"version":3,"file":"dht-content-routing.d.ts","sourceRoot":"","sources":["../../../src/dht/dht-content-routing.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAA;AACxE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD;;GAEG;AACH,qBAAa,iBAAkB,YAAW,cAAc;IACtD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEZ,GAAG,EAAE,GAAG;IAIf,OAAO,CAAE,GAAG,EAAE,GAAG;IAIf,aAAa,CAAE,GAAG,EAAE,GAAG,EAAE,OAAO,GAAE,YAAiB;IAQrD,GAAG,CAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/E,GAAG,CAAE,GAAG,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,UAAU,CAAC;CASzE"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import drain from 'it-drain';
|
|
2
|
+
import errCode from 'err-code';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper class to convert events into returned values
|
|
5
|
+
*/
|
|
6
|
+
export class DHTContentRouting {
|
|
7
|
+
constructor(dht) {
|
|
8
|
+
this.dht = dht;
|
|
9
|
+
}
|
|
10
|
+
async provide(cid) {
|
|
11
|
+
await drain(this.dht.provide(cid));
|
|
12
|
+
}
|
|
13
|
+
async *findProviders(cid, options = {}) {
|
|
14
|
+
for await (const event of this.dht.findProviders(cid, options)) {
|
|
15
|
+
if (event.name === 'PROVIDER') {
|
|
16
|
+
yield* event.providers;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
async put(key, value, options) {
|
|
21
|
+
await drain(this.dht.put(key, value, options));
|
|
22
|
+
}
|
|
23
|
+
async get(key, options) {
|
|
24
|
+
for await (const event of this.dht.get(key, options)) {
|
|
25
|
+
if (event.name === 'VALUE') {
|
|
26
|
+
return event.value;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
throw errCode(new Error('Not found'), 'ERR_NOT_FOUND');
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=dht-content-routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dht-content-routing.js","sourceRoot":"","sources":["../../../src/dht/dht-content-routing.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,OAAO,MAAM,UAAU,CAAA;AAM9B;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAG5B,YAAa,GAAQ;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,KAAK,CAAC,OAAO,CAAE,GAAQ;QACrB,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAA;IACpC,CAAC;IAED,KAAK,CAAC,CAAE,aAAa,CAAE,GAAQ,EAAE,UAAwB,EAAE;QACzD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE;YAC9D,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,EAAE;gBAC7B,KAAM,CAAC,CAAC,KAAK,CAAC,SAAS,CAAA;aACxB;SACF;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,GAAe,EAAE,KAAiB,EAAE,OAAsB;QACnE,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAA;IAChD,CAAC;IAED,KAAK,CAAC,GAAG,CAAE,GAAe,EAAE,OAAsB;QAChD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE;YACpD,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO,EAAE;gBAC1B,OAAO,KAAK,CAAC,KAAK,CAAA;aACnB;SACF;QAED,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,WAAW,CAAC,EAAE,eAAe,CAAC,CAAA;IACxD,CAAC;CACF"}
|
|
@@ -1,29 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRoutingModule
|
|
6
|
-
*/
|
|
1
|
+
import type { PeerRouting } from '@libp2p/interfaces/peer-routing';
|
|
2
|
+
import type { DHT } from '@libp2p/interfaces/dht';
|
|
3
|
+
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
|
4
|
+
import type { AbortOptions } from '@libp2p/interfaces';
|
|
7
5
|
/**
|
|
8
6
|
* Wrapper class to convert events into returned values
|
|
9
|
-
*
|
|
10
|
-
* @implements {PeerRoutingModule}
|
|
11
7
|
*/
|
|
12
|
-
export class DHTPeerRouting implements
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
_dht: import("libp2p-kad-dht/dist/src/types").DHT;
|
|
18
|
-
/**
|
|
19
|
-
* @param {PeerId} peerId
|
|
20
|
-
* @param {any} options
|
|
21
|
-
*/
|
|
22
|
-
findPeer(peerId: PeerId, options?: any): Promise<import("libp2p-kad-dht/dist/src/types").PeerData>;
|
|
23
|
-
/**
|
|
24
|
-
* @param {Uint8Array} key
|
|
25
|
-
* @param {any} options
|
|
26
|
-
*/
|
|
27
|
-
getClosestPeers(key: Uint8Array, options?: any): AsyncGenerator<import("libp2p-kad-dht/dist/src/types").PeerData, void, undefined>;
|
|
8
|
+
export declare class DHTPeerRouting implements PeerRouting {
|
|
9
|
+
private readonly dht;
|
|
10
|
+
constructor(dht: DHT);
|
|
11
|
+
findPeer(peerId: PeerId, options?: AbortOptions): Promise<import("@libp2p/interfaces/dist/src/peer-info").PeerInfo>;
|
|
12
|
+
getClosestPeers(key: Uint8Array, options?: AbortOptions): AsyncGenerator<import("@libp2p/interfaces/dist/src/peer-info").PeerInfo, void, undefined>;
|
|
28
13
|
}
|
|
29
14
|
//# sourceMappingURL=dht-peer-routing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dht-peer-routing.d.ts","sourceRoot":"","sources":["../../../src/dht/dht-peer-routing.
|
|
1
|
+
{"version":3,"file":"dht-peer-routing.d.ts","sourceRoot":"","sources":["../../../src/dht/dht-peer-routing.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAA;AAClE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,wBAAwB,CAAA;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAEtD;;GAEG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAK;gBAEZ,GAAG,EAAE,GAAG;IAIf,QAAQ,CAAE,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB;IAUlD,eAAe,CAAE,GAAG,EAAE,UAAU,EAAE,OAAO,GAAE,YAAiB;CAOrE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import errCode from 'err-code';
|
|
2
|
+
import { messages, codes } from '../errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* Wrapper class to convert events into returned values
|
|
5
|
+
*/
|
|
6
|
+
export class DHTPeerRouting {
|
|
7
|
+
constructor(dht) {
|
|
8
|
+
this.dht = dht;
|
|
9
|
+
}
|
|
10
|
+
async findPeer(peerId, options = {}) {
|
|
11
|
+
for await (const event of this.dht.findPeer(peerId, options)) {
|
|
12
|
+
if (event.name === 'FINAL_PEER') {
|
|
13
|
+
return event.peer;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
throw errCode(new Error(messages.NOT_FOUND), codes.ERR_NOT_FOUND);
|
|
17
|
+
}
|
|
18
|
+
async *getClosestPeers(key, options = {}) {
|
|
19
|
+
for await (const event of this.dht.getClosestPeers(key, options)) {
|
|
20
|
+
if (event.name === 'PEER_RESPONSE') {
|
|
21
|
+
yield* event.closer;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=dht-peer-routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dht-peer-routing.js","sourceRoot":"","sources":["../../../src/dht/dht-peer-routing.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAM9C;;GAEG;AACH,MAAM,OAAO,cAAc;IAGzB,YAAa,GAAQ;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;IAChB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAE,MAAc,EAAE,UAAwB,EAAE;QACxD,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;YAC5D,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY,EAAE;gBAC/B,OAAO,KAAK,CAAC,IAAI,CAAA;aAClB;SACF;QAED,MAAM,OAAO,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IACnE,CAAC;IAED,KAAK,CAAC,CAAE,eAAe,CAAE,GAAe,EAAE,UAAwB,EAAE;QAClE,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,eAAe,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE;YAChE,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE;gBAClC,KAAM,CAAC,CAAC,KAAK,CAAC,MAAM,CAAA;aACrB;SACF;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DualDHT, QueryEvent, SingleDHT } from '@libp2p/interfaces/dht';
|
|
2
|
+
import type { PeerDiscoveryEvents } from '@libp2p/interfaces/peer-discovery';
|
|
3
|
+
import { EventEmitter } from '@libp2p/interfaces/events';
|
|
4
|
+
import { symbol } from '@libp2p/interfaces/peer-discovery';
|
|
5
|
+
export declare class DummyDHT extends EventEmitter<PeerDiscoveryEvents> implements DualDHT {
|
|
6
|
+
get [symbol](): true;
|
|
7
|
+
get [Symbol.toStringTag](): string;
|
|
8
|
+
get wan(): SingleDHT;
|
|
9
|
+
get lan(): SingleDHT;
|
|
10
|
+
get(): AsyncIterable<QueryEvent>;
|
|
11
|
+
findProviders(): AsyncIterable<QueryEvent>;
|
|
12
|
+
findPeer(): AsyncIterable<QueryEvent>;
|
|
13
|
+
getClosestPeers(): AsyncIterable<QueryEvent>;
|
|
14
|
+
provide(): AsyncIterable<QueryEvent>;
|
|
15
|
+
put(): AsyncIterable<QueryEvent>;
|
|
16
|
+
getMode(): Promise<'client' | 'server'>;
|
|
17
|
+
setMode(): Promise<void>;
|
|
18
|
+
refreshRoutingTable(): Promise<void>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=dummy-dht.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dummy-dht.d.ts","sourceRoot":"","sources":["../../../src/dht/dummy-dht.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAA;AAC5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAA;AAG5E,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAA;AAE1D,qBAAa,QAAS,SAAQ,YAAY,CAAC,mBAAmB,CAAE,YAAW,OAAO;IAChF,IAAI,CAAC,MAAM,CAAC,IAAK,IAAI,CAEpB;IAED,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,WAEvB;IAED,IAAI,GAAG,IAAK,SAAS,CAEpB;IAED,IAAI,GAAG,IAAK,SAAS,CAEpB;IAED,GAAG,IAAK,aAAa,CAAC,UAAU,CAAC;IAIjC,aAAa,IAAK,aAAa,CAAC,UAAU,CAAC;IAI3C,QAAQ,IAAK,aAAa,CAAC,UAAU,CAAC;IAItC,eAAe,IAAK,aAAa,CAAC,UAAU,CAAC;IAI7C,OAAO,IAAK,aAAa,CAAC,UAAU,CAAC;IAIrC,GAAG,IAAK,aAAa,CAAC,UAAU,CAAC;IAI3B,OAAO,IAAK,OAAO,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAIxC,OAAO,IAAK,OAAO,CAAC,IAAI,CAAC;IAIzB,mBAAmB,IAAK,OAAO,CAAC,IAAI,CAAC;CAG5C"}
|