libp2p 0.36.0 → 0.36.2-1473044
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -21
- package/README.md +13 -10
- package/dist/src/address-manager/index.d.ts +33 -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 +215 -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 +54 -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 +51 -0
- package/dist/src/circuit/pb/index.d.ts.map +1 -0
- package/dist/src/circuit/pb/index.js +72 -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 +190 -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 +93 -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/index.d.ts +79 -144
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +295 -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 +26 -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/dialer/auto-dialer.d.ts +14 -0
- package/dist/src/dialer/auto-dialer.d.ts.map +1 -0
- package/dist/src/dialer/auto-dialer.js +24 -0
- package/dist/src/dialer/auto-dialer.js.map +1 -0
- package/dist/src/dialer/dial-request.d.ts +18 -46
- package/dist/src/dialer/dial-request.d.ts.map +1 -1
- package/dist/src/dialer/dial-request.js +83 -0
- package/dist/src/dialer/dial-request.js.map +1 -0
- package/dist/src/dialer/index.d.ts +41 -148
- package/dist/src/dialer/index.d.ts.map +1 -1
- package/dist/src/dialer/index.js +280 -0
- package/dist/src/dialer/index.js.map +1 -0
- package/dist/src/errors.d.ts +68 -63
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +73 -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 +26 -0
- package/dist/src/fetch/pb/proto.d.ts.map +1 -0
- package/dist/src/fetch/pb/proto.js +44 -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 +15 -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 +162 -581
- 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 +28 -0
- package/dist/src/insecure/pb/proto.d.ts.map +1 -0
- package/dist/src/insecure/pb/proto.js +46 -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 +61 -81
- package/dist/src/keychain/index.d.ts.map +1 -1
- package/dist/src/keychain/index.js +493 -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 +78 -0
- package/dist/src/libp2p.d.ts.map +1 -0
- package/dist/src/libp2p.js +375 -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 +39 -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 +26 -33
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +56 -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 +11 -20
- package/dist/src/pnet/index.d.ts.map +1 -1
- package/dist/src/pnet/index.js +66 -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/registrar.d.ts +27 -65
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +159 -0
- package/dist/src/registrar.js.map +1 -0
- package/dist/src/transport-manager.d.ts +34 -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 +150 -197
- package/src/address-manager/index.ts +129 -0
- package/src/circuit/README.md +16 -11
- package/src/circuit/auto-relay.ts +284 -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.js → listener.ts} +21 -27
- package/src/circuit/multicodec.ts +2 -0
- package/src/circuit/{protocol → pb}/index.proto +1 -1
- package/src/circuit/pb/index.ts +88 -0
- package/src/circuit/transport.ts +216 -0
- package/src/circuit/utils.ts +12 -0
- package/src/config.ts +101 -0
- package/src/connection-manager/auto-dialler.ts +154 -0
- package/src/connection-manager/index.ts +422 -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 +143 -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/dialer/auto-dialer.ts +40 -0
- package/src/dialer/{dial-request.js → dial-request.ts} +60 -51
- package/src/dialer/index.ts +371 -0
- package/src/errors.ts +71 -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 +58 -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 +36 -0
- package/src/index.ts +242 -0
- package/src/insecure/index.ts +101 -0
- package/src/insecure/{proto.proto → pb/proto.proto} +0 -0
- package/src/insecure/pb/proto.ts +61 -0
- package/src/keychain/{cms.js → cms.ts} +62 -58
- package/src/keychain/index.ts +588 -0
- package/src/keychain/{util.js → util.ts} +7 -17
- package/src/libp2p.ts +513 -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 +185 -0
- package/src/ping/README.md +1 -1
- package/src/ping/constants.ts +5 -0
- package/src/ping/index.ts +83 -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 +95 -0
- package/src/pnet/key-generator.ts +28 -0
- package/src/registrar.ts +205 -0
- package/src/transport-manager.ts +279 -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/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/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 -363
- 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 -811
- 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 -85
- 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
|
@@ -1,76 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
|
2
|
+
import type { Startable } from '@libp2p/interfaces';
|
|
3
|
+
import type { Stream } from '@libp2p/interfaces/connection';
|
|
4
|
+
import type { IncomingStreamData } from '@libp2p/interfaces/registrar';
|
|
5
|
+
import type { Components } from '@libp2p/interfaces/components';
|
|
6
|
+
export interface FetchInit {
|
|
7
|
+
protocolPrefix: string;
|
|
8
|
+
}
|
|
9
|
+
export interface HandleMessageOptions {
|
|
10
|
+
stream: Stream;
|
|
11
|
+
protocol: string;
|
|
12
|
+
}
|
|
13
|
+
export interface LookupFunction {
|
|
14
|
+
(key: string): Promise<Uint8Array | null>;
|
|
15
|
+
}
|
|
9
16
|
/**
|
|
10
17
|
* A simple libp2p protocol for requesting a value corresponding to a key from a peer.
|
|
11
18
|
* Developers can register one or more lookup function for retrieving the value corresponding to
|
|
12
19
|
* a given key. Each lookup function must act on a distinct part of the overall key space, defined
|
|
13
20
|
* by a fixed prefix that all keys that should be routed to that lookup function will start with.
|
|
14
21
|
*/
|
|
15
|
-
declare class
|
|
22
|
+
export declare class FetchService implements Startable {
|
|
23
|
+
private readonly components;
|
|
24
|
+
private readonly lookupFunctions;
|
|
25
|
+
private readonly protocol;
|
|
26
|
+
private started;
|
|
27
|
+
constructor(components: Components, init: FetchInit);
|
|
28
|
+
start(): Promise<void>;
|
|
29
|
+
stop(): Promise<void>;
|
|
30
|
+
isStarted(): boolean;
|
|
16
31
|
/**
|
|
17
|
-
*
|
|
32
|
+
* Sends a request to fetch the value associated with the given key from the given peer
|
|
18
33
|
*/
|
|
19
|
-
|
|
20
|
-
_lookupFunctions: Map<any, any>;
|
|
21
|
-
_libp2p: import("../");
|
|
34
|
+
fetch(peer: PeerId, key: string): Promise<Uint8Array | null>;
|
|
22
35
|
/**
|
|
23
36
|
* Invoked when a fetch request is received. Reads the request message off the given stream and
|
|
24
37
|
* responds based on looking up the key in the request via the lookup callback that corresponds
|
|
25
38
|
* to the key's prefix.
|
|
26
|
-
*
|
|
27
|
-
* @param {object} options
|
|
28
|
-
* @param {MuxedStream} options.stream
|
|
29
|
-
* @param {string} options.protocol
|
|
30
39
|
*/
|
|
31
|
-
handleMessage(
|
|
32
|
-
stream: MuxedStream;
|
|
33
|
-
protocol: string;
|
|
34
|
-
}): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Sends a request to fetch the value associated with the given key from the given peer.
|
|
37
|
-
*
|
|
38
|
-
* @param {PeerId|Multiaddr} peer
|
|
39
|
-
* @param {string} key
|
|
40
|
-
* @returns {Promise<Uint8Array | null>}
|
|
41
|
-
*/
|
|
42
|
-
fetch(peer: PeerId | Multiaddr, key: string): Promise<Uint8Array | null>;
|
|
40
|
+
handleMessage(data: IncomingStreamData): Promise<void>;
|
|
43
41
|
/**
|
|
44
42
|
* Given a key, finds the appropriate function for looking up its corresponding value, based on
|
|
45
43
|
* the key's prefix.
|
|
46
|
-
*
|
|
47
|
-
* @param {string} key
|
|
48
44
|
*/
|
|
49
|
-
_getLookupFunction(key: string):
|
|
45
|
+
_getLookupFunction(key: string): LookupFunction | undefined;
|
|
50
46
|
/**
|
|
51
47
|
* Registers a new lookup callback that can map keys to values, for a given set of keys that
|
|
52
|
-
* share the same prefix
|
|
53
|
-
*
|
|
54
|
-
* @param {string} prefix
|
|
55
|
-
* @param {LookupFunction} lookup
|
|
48
|
+
* share the same prefix
|
|
56
49
|
*/
|
|
57
50
|
registerLookupFunction(prefix: string, lookup: LookupFunction): void;
|
|
58
51
|
/**
|
|
59
52
|
* Registers a new lookup callback that can map keys to values, for a given set of keys that
|
|
60
53
|
* share the same prefix.
|
|
61
|
-
*
|
|
62
|
-
* @param {string} prefix
|
|
63
|
-
* @param {LookupFunction} [lookup]
|
|
64
54
|
*/
|
|
65
|
-
unregisterLookupFunction(prefix: string, lookup?: LookupFunction
|
|
66
|
-
}
|
|
67
|
-
declare namespace FetchProtocol {
|
|
68
|
-
export { PROTOCOL, Libp2p, Multiaddr, PeerId, MuxedStream, LookupFunction };
|
|
55
|
+
unregisterLookupFunction(prefix: string, lookup?: LookupFunction): void;
|
|
69
56
|
}
|
|
70
|
-
type MuxedStream = import('libp2p-interfaces/src/stream-muxer/types').MuxedStream;
|
|
71
|
-
type PeerId = import('peer-id');
|
|
72
|
-
type Multiaddr = import('multiaddr').Multiaddr;
|
|
73
|
-
type LookupFunction = (key: string) => Promise<Uint8Array | null>;
|
|
74
|
-
type Libp2p = import('../');
|
|
75
|
-
import { PROTOCOL } from "./constants";
|
|
76
57
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fetch/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fetch/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAA;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAI/D,MAAM,WAAW,SAAS;IACxB,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,cAAc;IAC7B,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAAA;CAC1C;AAED;;;;;GAKG;AACH,qBAAa,YAAa,YAAW,SAAS;IAC5C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA6B;IAC7D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,OAAO,CAAS;gBAEX,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS;IAQ9C,KAAK;IASL,IAAI;IAKV,SAAS;IAIT;;OAEG;IACG,KAAK,CAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;IA8BnE;;;;OAIG;IACG,aAAa,CAAE,IAAI,EAAE,kBAAkB;IAuB7C;;;OAGG;IACH,kBAAkB,CAAE,GAAG,EAAE,MAAM;IAQ/B;;;OAGG;IACH,sBAAsB,CAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc;IAQ9D;;;OAGG;IACH,wBAAwB,CAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc;CAWlE"}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { logger } from '@libp2p/logger';
|
|
2
|
+
import errCode from 'err-code';
|
|
3
|
+
import { codes } from '../errors.js';
|
|
4
|
+
import * as lp from 'it-length-prefixed';
|
|
5
|
+
import { FetchRequest, FetchResponse } from './pb/proto.js';
|
|
6
|
+
import { handshake } from 'it-handshake';
|
|
7
|
+
import { PROTOCOL } from './constants.js';
|
|
8
|
+
const log = logger('libp2p:fetch');
|
|
9
|
+
/**
|
|
10
|
+
* A simple libp2p protocol for requesting a value corresponding to a key from a peer.
|
|
11
|
+
* Developers can register one or more lookup function for retrieving the value corresponding to
|
|
12
|
+
* a given key. Each lookup function must act on a distinct part of the overall key space, defined
|
|
13
|
+
* by a fixed prefix that all keys that should be routed to that lookup function will start with.
|
|
14
|
+
*/
|
|
15
|
+
export class FetchService {
|
|
16
|
+
constructor(components, init) {
|
|
17
|
+
this.started = false;
|
|
18
|
+
this.components = components;
|
|
19
|
+
this.protocol = PROTOCOL;
|
|
20
|
+
this.lookupFunctions = new Map(); // Maps key prefix to value lookup function
|
|
21
|
+
this.handleMessage = this.handleMessage.bind(this);
|
|
22
|
+
}
|
|
23
|
+
async start() {
|
|
24
|
+
await this.components.getRegistrar().handle(this.protocol, (data) => {
|
|
25
|
+
void this.handleMessage(data).catch(err => {
|
|
26
|
+
log.error(err);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
this.started = true;
|
|
30
|
+
}
|
|
31
|
+
async stop() {
|
|
32
|
+
await this.components.getRegistrar().unhandle(this.protocol);
|
|
33
|
+
this.started = false;
|
|
34
|
+
}
|
|
35
|
+
isStarted() {
|
|
36
|
+
return this.started;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Sends a request to fetch the value associated with the given key from the given peer
|
|
40
|
+
*/
|
|
41
|
+
async fetch(peer, key) {
|
|
42
|
+
log('dialing %s to %p', this.protocol, peer);
|
|
43
|
+
const connection = await this.components.getDialer().dial(peer);
|
|
44
|
+
const { stream } = await connection.newStream([this.protocol]);
|
|
45
|
+
const shake = handshake(stream);
|
|
46
|
+
// send message
|
|
47
|
+
shake.write(lp.encode.single(FetchRequest.encode({ identifier: key })).slice());
|
|
48
|
+
// read response
|
|
49
|
+
// @ts-expect-error fromReader returns a Source which has no .next method
|
|
50
|
+
const response = FetchResponse.decode((await lp.decode.fromReader(shake.reader).next()).value.slice());
|
|
51
|
+
switch (response.status) {
|
|
52
|
+
case (FetchResponse.StatusCode.OK): {
|
|
53
|
+
return response.data;
|
|
54
|
+
}
|
|
55
|
+
case (FetchResponse.StatusCode.NOT_FOUND): {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
case (FetchResponse.StatusCode.ERROR): {
|
|
59
|
+
const errmsg = (new TextDecoder()).decode(response.data);
|
|
60
|
+
throw errCode(new Error('Error in fetch protocol response: ' + errmsg), codes.ERR_INVALID_PARAMETERS);
|
|
61
|
+
}
|
|
62
|
+
default: {
|
|
63
|
+
throw errCode(new Error('Unknown response status'), codes.ERR_INVALID_MESSAGE);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Invoked when a fetch request is received. Reads the request message off the given stream and
|
|
69
|
+
* responds based on looking up the key in the request via the lookup callback that corresponds
|
|
70
|
+
* to the key's prefix.
|
|
71
|
+
*/
|
|
72
|
+
async handleMessage(data) {
|
|
73
|
+
const { stream } = data;
|
|
74
|
+
const shake = handshake(stream);
|
|
75
|
+
// @ts-expect-error fromReader returns a Source which has no .next method
|
|
76
|
+
const request = FetchRequest.decode((await lp.decode.fromReader(shake.reader).next()).value.slice());
|
|
77
|
+
let response;
|
|
78
|
+
const lookup = this._getLookupFunction(request.identifier);
|
|
79
|
+
if (lookup != null) {
|
|
80
|
+
const data = await lookup(request.identifier);
|
|
81
|
+
if (data != null) {
|
|
82
|
+
response = { status: FetchResponse.StatusCode.OK, data };
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
response = { status: FetchResponse.StatusCode.NOT_FOUND, data: new Uint8Array(0) };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const errmsg = (new TextEncoder()).encode('No lookup function registered for key: ' + request.identifier);
|
|
90
|
+
response = { status: FetchResponse.StatusCode.ERROR, data: errmsg };
|
|
91
|
+
}
|
|
92
|
+
shake.write(lp.encode.single(FetchResponse.encode(response)).slice());
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Given a key, finds the appropriate function for looking up its corresponding value, based on
|
|
96
|
+
* the key's prefix.
|
|
97
|
+
*/
|
|
98
|
+
_getLookupFunction(key) {
|
|
99
|
+
for (const prefix of this.lookupFunctions.keys()) {
|
|
100
|
+
if (key.startsWith(prefix)) {
|
|
101
|
+
return this.lookupFunctions.get(prefix);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Registers a new lookup callback that can map keys to values, for a given set of keys that
|
|
107
|
+
* share the same prefix
|
|
108
|
+
*/
|
|
109
|
+
registerLookupFunction(prefix, lookup) {
|
|
110
|
+
if (this.lookupFunctions.has(prefix)) {
|
|
111
|
+
throw errCode(new Error("Fetch protocol handler for key prefix '" + prefix + "' already registered"), codes.ERR_KEY_ALREADY_EXISTS);
|
|
112
|
+
}
|
|
113
|
+
this.lookupFunctions.set(prefix, lookup);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Registers a new lookup callback that can map keys to values, for a given set of keys that
|
|
117
|
+
* share the same prefix.
|
|
118
|
+
*/
|
|
119
|
+
unregisterLookupFunction(prefix, lookup) {
|
|
120
|
+
if (lookup != null) {
|
|
121
|
+
const existingLookup = this.lookupFunctions.get(prefix);
|
|
122
|
+
if (existingLookup !== lookup) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
this.lookupFunctions.delete(prefix);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fetch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,KAAK,EAAE,MAAM,oBAAoB,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAOzC,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AAelC;;;;;GAKG;AACH,MAAM,OAAO,YAAY;IAMvB,YAAa,UAAsB,EAAE,IAAe;QAClD,IAAI,CAAC,OAAO,GAAG,KAAK,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,EAAE,CAAA,CAAC,2CAA2C;QAC5E,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACpD,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ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AAA;SACpI;QAED,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC1C,CAAC;IAED;;;OAGG;IACH,wBAAwB,CAAE,MAAc,EAAE,MAAuB;QAC/D,IAAI,MAAM,IAAI,IAAI,EAAE;YAClB,MAAM,cAAc,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;YAEvD,IAAI,cAAc,KAAK,MAAM,EAAE;gBAC7B,OAAM;aACP;SACF;QAED,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export interface FetchRequest {
|
|
2
|
+
identifier: string;
|
|
3
|
+
}
|
|
4
|
+
export declare namespace FetchRequest {
|
|
5
|
+
const codec: () => import("protons-runtime").Codec<FetchRequest>;
|
|
6
|
+
const encode: (obj: FetchRequest) => Uint8Array;
|
|
7
|
+
const decode: (buf: Uint8Array) => FetchRequest;
|
|
8
|
+
}
|
|
9
|
+
export interface FetchResponse {
|
|
10
|
+
status: FetchResponse.StatusCode;
|
|
11
|
+
data: Uint8Array;
|
|
12
|
+
}
|
|
13
|
+
export declare namespace FetchResponse {
|
|
14
|
+
enum StatusCode {
|
|
15
|
+
OK = "OK",
|
|
16
|
+
NOT_FOUND = "NOT_FOUND",
|
|
17
|
+
ERROR = "ERROR"
|
|
18
|
+
}
|
|
19
|
+
namespace StatusCode {
|
|
20
|
+
const codec: () => import("protons-runtime").Codec<typeof StatusCode>;
|
|
21
|
+
}
|
|
22
|
+
const codec: () => import("protons-runtime").Codec<FetchResponse>;
|
|
23
|
+
const encode: (obj: FetchResponse) => Uint8Array;
|
|
24
|
+
const decode: (buf: Uint8Array) => FetchResponse;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=proto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proto.d.ts","sourceRoot":"","sources":["../../../../src/fetch/pb/proto.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,yBAAiB,YAAY,CAAC;IACrB,MAAM,KAAK,qDAIjB,CAAA;IAEM,MAAM,MAAM,QAAS,YAAY,KAAG,UAE1C,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,KAAG,YAExC,CAAA;CACF;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,aAAa,CAAC,UAAU,CAAA;IAChC,IAAI,EAAE,UAAU,CAAA;CACjB;AAED,yBAAiB,aAAa,CAAC;IAC7B,KAAY,UAAU;QACpB,EAAE,OAAO;QACT,SAAS,cAAc;QACvB,KAAK,UAAU;KAChB;IAED,UAAiB,UAAU,CAAC;QACnB,MAAM,KAAK,0DAEjB,CAAA;KACF;IAEM,MAAM,KAAK,sDAKjB,CAAA;IAEM,MAAM,MAAM,QAAS,aAAa,KAAG,UAE3C,CAAA;IAEM,MAAM,MAAM,QAAS,UAAU,KAAG,aAExC,CAAA;CACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* eslint-disable import/export */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
|
+
import { encodeMessage, decodeMessage, message, string, enumeration, bytes } from 'protons-runtime';
|
|
4
|
+
export var FetchRequest;
|
|
5
|
+
(function (FetchRequest) {
|
|
6
|
+
FetchRequest.codec = () => {
|
|
7
|
+
return message({
|
|
8
|
+
1: { name: 'identifier', codec: string }
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
FetchRequest.encode = (obj) => {
|
|
12
|
+
return encodeMessage(obj, FetchRequest.codec());
|
|
13
|
+
};
|
|
14
|
+
FetchRequest.decode = (buf) => {
|
|
15
|
+
return decodeMessage(buf, FetchRequest.codec());
|
|
16
|
+
};
|
|
17
|
+
})(FetchRequest || (FetchRequest = {}));
|
|
18
|
+
export var FetchResponse;
|
|
19
|
+
(function (FetchResponse) {
|
|
20
|
+
let StatusCode;
|
|
21
|
+
(function (StatusCode) {
|
|
22
|
+
StatusCode["OK"] = "OK";
|
|
23
|
+
StatusCode["NOT_FOUND"] = "NOT_FOUND";
|
|
24
|
+
StatusCode["ERROR"] = "ERROR";
|
|
25
|
+
})(StatusCode = FetchResponse.StatusCode || (FetchResponse.StatusCode = {}));
|
|
26
|
+
(function (StatusCode) {
|
|
27
|
+
StatusCode.codec = () => {
|
|
28
|
+
return enumeration(StatusCode);
|
|
29
|
+
};
|
|
30
|
+
})(StatusCode = FetchResponse.StatusCode || (FetchResponse.StatusCode = {}));
|
|
31
|
+
FetchResponse.codec = () => {
|
|
32
|
+
return message({
|
|
33
|
+
1: { name: 'status', codec: FetchResponse.StatusCode.codec() },
|
|
34
|
+
2: { name: 'data', codec: bytes }
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
FetchResponse.encode = (obj) => {
|
|
38
|
+
return encodeMessage(obj, FetchResponse.codec());
|
|
39
|
+
};
|
|
40
|
+
FetchResponse.decode = (buf) => {
|
|
41
|
+
return decodeMessage(buf, FetchResponse.codec());
|
|
42
|
+
};
|
|
43
|
+
})(FetchResponse || (FetchResponse = {}));
|
|
44
|
+
//# sourceMappingURL=proto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proto.js","sourceRoot":"","sources":["../../../../src/fetch/pb/proto.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,oDAAoD;AAEpD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAMnG,MAAM,KAAW,YAAY,CAc5B;AAdD,WAAiB,YAAY;IACd,kBAAK,GAAG,GAAG,EAAE;QACxB,OAAO,OAAO,CAAe;YAC3B,CAAC,EAAE,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE;SACzC,CAAC,CAAA;IAC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CAAC,CAAA;AACH,CAAC,EA3BgB,aAAa,KAAb,aAAa,QA2B7B"}
|
package/dist/src/get-peer.d.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { Multiaddr } from '@multiformats/multiaddr';
|
|
2
|
+
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
|
3
|
+
import type { PeerInfo } from '@libp2p/interfaces/peer-info';
|
|
2
4
|
/**
|
|
3
5
|
* Converts the given `peer` to a `Peer` object.
|
|
4
|
-
* If a multiaddr is received, the addressBook is updated.
|
|
5
|
-
*
|
|
6
|
-
* @param {PeerId|Multiaddr|string} peer
|
|
7
|
-
* @returns {{ id: PeerId, multiaddrs: Multiaddr[]|undefined }}
|
|
8
6
|
*/
|
|
9
|
-
declare function getPeer(peer: PeerId | Multiaddr | string):
|
|
10
|
-
id: PeerId;
|
|
11
|
-
multiaddrs: Multiaddr[] | undefined;
|
|
12
|
-
};
|
|
13
|
-
import PeerId = require("peer-id");
|
|
14
|
-
import { Multiaddr } from "multiaddr";
|
|
7
|
+
export declare function getPeer(peer: PeerId | Multiaddr | string): PeerInfo;
|
|
15
8
|
//# sourceMappingURL=get-peer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-peer.d.ts","sourceRoot":"","sources":["../../src/get-peer.
|
|
1
|
+
{"version":3,"file":"get-peer.d.ts","sourceRoot":"","sources":["../../src/get-peer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAInD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAsB5D;;GAEG;AACH,wBAAgB,OAAO,CAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,CAyBpE"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { peerIdFromString } from '@libp2p/peer-id';
|
|
2
|
+
import { Multiaddr } from '@multiformats/multiaddr';
|
|
3
|
+
import errCode from 'err-code';
|
|
4
|
+
import { codes } from './errors.js';
|
|
5
|
+
import { isPeerId } from '@libp2p/interfaces/peer-id';
|
|
6
|
+
function peerIdFromMultiaddr(ma) {
|
|
7
|
+
const idStr = ma.getPeerId();
|
|
8
|
+
if (idStr == null) {
|
|
9
|
+
throw errCode(new Error(`${ma.toString()} does not have a valid peer type`), codes.ERR_INVALID_MULTIADDR);
|
|
10
|
+
}
|
|
11
|
+
try {
|
|
12
|
+
return peerIdFromString(idStr);
|
|
13
|
+
}
|
|
14
|
+
catch (err) {
|
|
15
|
+
throw errCode(new Error(`${ma.toString()} is not a valid peer type`), codes.ERR_INVALID_MULTIADDR);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Converts the given `peer` to a `Peer` object.
|
|
20
|
+
*/
|
|
21
|
+
export function getPeer(peer) {
|
|
22
|
+
if (isPeerId(peer)) {
|
|
23
|
+
return {
|
|
24
|
+
id: peer,
|
|
25
|
+
multiaddrs: [],
|
|
26
|
+
protocols: []
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
if (typeof peer === 'string') {
|
|
30
|
+
peer = new Multiaddr(peer);
|
|
31
|
+
}
|
|
32
|
+
let addr;
|
|
33
|
+
if (Multiaddr.isMultiaddr(peer)) {
|
|
34
|
+
addr = peer;
|
|
35
|
+
peer = peerIdFromMultiaddr(peer);
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
id: peer,
|
|
39
|
+
multiaddrs: addr != null ? [addr] : [],
|
|
40
|
+
protocols: []
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=get-peer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-peer.js","sourceRoot":"","sources":["../../src/get-peer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE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AAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;QACtC,SAAS,EAAE,EAAE;KACd,CAAA;AACH,CAAC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
1
|
+
export declare const PROTOCOL_VERSION = "ipfs/0.1.0";
|
|
2
|
+
export declare const AGENT_VERSION: string;
|
|
3
|
+
export declare const MULTICODEC_IDENTIFY = "/ipfs/id/1.0.0";
|
|
4
|
+
export declare const MULTICODEC_IDENTIFY_PUSH = "/ipfs/id/push/1.0.0";
|
|
5
|
+
export declare const IDENTIFY_PROTOCOL_VERSION = "0.1.0";
|
|
6
|
+
export declare const MULTICODEC_IDENTIFY_PROTOCOL_NAME = "id";
|
|
7
|
+
export declare const MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME = "id/push";
|
|
8
|
+
export declare const MULTICODEC_IDENTIFY_PROTOCOL_VERSION = "1.0.0";
|
|
9
|
+
export declare const MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION = "1.0.0";
|
|
10
10
|
//# sourceMappingURL=consts.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/identify/consts.
|
|
1
|
+
{"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../../../src/identify/consts.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB,eAAe,CAAA;AAC5C,eAAO,MAAM,aAAa,QAAyB,CAAA;AACnD,eAAO,MAAM,mBAAmB,mBAAmB,CAAA;AACnD,eAAO,MAAM,wBAAwB,wBAAwB,CAAA;AAE7D,eAAO,MAAM,yBAAyB,UAAU,CAAA;AAChD,eAAO,MAAM,iCAAiC,OAAO,CAAA;AACrD,eAAO,MAAM,sCAAsC,YAAY,CAAA;AAC/D,eAAO,MAAM,oCAAoC,UAAU,CAAA;AAC3D,eAAO,MAAM,yCAAyC,UAAU,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { version } from '../version.js';
|
|
2
|
+
export const PROTOCOL_VERSION = 'ipfs/0.1.0'; // deprecated
|
|
3
|
+
export const AGENT_VERSION = `js-libp2p/${version}`;
|
|
4
|
+
export const MULTICODEC_IDENTIFY = '/ipfs/id/1.0.0'; // deprecated
|
|
5
|
+
export const MULTICODEC_IDENTIFY_PUSH = '/ipfs/id/push/1.0.0'; // deprecated
|
|
6
|
+
export const IDENTIFY_PROTOCOL_VERSION = '0.1.0';
|
|
7
|
+
export const MULTICODEC_IDENTIFY_PROTOCOL_NAME = 'id';
|
|
8
|
+
export const MULTICODEC_IDENTIFY_PUSH_PROTOCOL_NAME = 'id/push';
|
|
9
|
+
export const MULTICODEC_IDENTIFY_PROTOCOL_VERSION = '1.0.0';
|
|
10
|
+
export const MULTICODEC_IDENTIFY_PUSH_PROTOCOL_VERSION = '1.0.0';
|
|
11
|
+
//# sourceMappingURL=consts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consts.js","sourceRoot":"","sources":["../../../src/identify/consts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAEvC,MAAM,CAAC,MAAM,gBAAgB,GAAG,YAAY,CAAA,CAAC,aAAa;AAC1D,MAAM,CAAC,MAAM,aAAa,GAAG,aAAa,OAAO,EAAE,CAAA;AACnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAA,CAAC,aAAa;AACjE,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,CAAA,CAAC,aAAa;AAE3E,MAAM,CAAC,MAAM,yBAAyB,GAAG,OAAO,CAAA;AAChD,MAAM,CAAC,MAAM,iCAAiC,GAAG,IAAI,CAAA;AACrD,MAAM,CAAC,MAAM,sCAAsC,GAAG,SAAS,CAAA;AAC/D,MAAM,CAAC,MAAM,oCAAoC,GAAG,OAAO,CAAA;AAC3D,MAAM,CAAC,MAAM,yCAAyC,GAAG,OAAO,CAAA"}
|
|
@@ -1,120 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* @returns {Multiaddr|null}
|
|
23
|
-
*/
|
|
24
|
-
static getCleanMultiaddr(addr: Uint8Array | string): Multiaddr | null;
|
|
25
|
-
/**
|
|
26
|
-
* @class
|
|
27
|
-
* @param {Object} options
|
|
28
|
-
* @param {import('../')} options.libp2p
|
|
29
|
-
*/
|
|
30
|
-
constructor({ libp2p }: {
|
|
31
|
-
libp2p: import('../');
|
|
32
|
-
});
|
|
33
|
-
_libp2p: import("../");
|
|
34
|
-
peerStore: import("../peer-store/types").PeerStore;
|
|
35
|
-
addressManager: import("../address-manager");
|
|
36
|
-
connectionManager: import("../connection-manager");
|
|
37
|
-
peerId: PeerId;
|
|
38
|
-
/**
|
|
39
|
-
* A handler to register with Libp2p to process identify messages.
|
|
40
|
-
*
|
|
41
|
-
* @param {Object} options
|
|
42
|
-
* @param {Connection} options.connection
|
|
43
|
-
* @param {MuxedStream} options.stream
|
|
44
|
-
* @param {string} options.protocol
|
|
45
|
-
* @returns {Promise<void>|undefined}
|
|
46
|
-
*/
|
|
47
|
-
handleMessage({ connection, stream, protocol }: {
|
|
48
|
-
connection: Connection;
|
|
49
|
-
stream: MuxedStream;
|
|
50
|
-
protocol: string;
|
|
51
|
-
}): Promise<void> | undefined;
|
|
52
|
-
identifyProtocolStr: string;
|
|
53
|
-
identifyPushProtocolStr: string;
|
|
54
|
-
_host: {
|
|
55
|
-
agentVersion: string;
|
|
56
|
-
protocolVersion: string;
|
|
57
|
-
};
|
|
1
|
+
import { Multiaddr } from '@multiformats/multiaddr';
|
|
2
|
+
import { Identify } from './pb/message.js';
|
|
3
|
+
import type { IncomingStreamData } from '@libp2p/interfaces/registrar';
|
|
4
|
+
import type { Connection } from '@libp2p/interfaces/connection';
|
|
5
|
+
import type { Startable } from '@libp2p/interfaces';
|
|
6
|
+
import type { Components } from '@libp2p/interfaces/components';
|
|
7
|
+
export interface HostProperties {
|
|
8
|
+
agentVersion: string;
|
|
9
|
+
}
|
|
10
|
+
export interface IdentifyServiceInit {
|
|
11
|
+
protocolPrefix: string;
|
|
12
|
+
host: HostProperties;
|
|
13
|
+
}
|
|
14
|
+
export declare class IdentifyService implements Startable {
|
|
15
|
+
private readonly components;
|
|
16
|
+
private readonly identifyProtocolStr;
|
|
17
|
+
private readonly identifyPushProtocolStr;
|
|
18
|
+
private readonly host;
|
|
19
|
+
private started;
|
|
20
|
+
constructor(components: Components, init: IdentifyServiceInit);
|
|
21
|
+
isStarted(): boolean;
|
|
58
22
|
start(): Promise<void>;
|
|
59
23
|
stop(): Promise<void>;
|
|
60
24
|
/**
|
|
61
25
|
* Send an Identify Push update to the list of connections
|
|
62
|
-
*
|
|
63
|
-
* @param {Connection[]} connections
|
|
64
|
-
* @returns {Promise<void[]>}
|
|
65
26
|
*/
|
|
66
|
-
push(connections: Connection[]): Promise<void
|
|
27
|
+
push(connections: Connection[]): Promise<void>;
|
|
67
28
|
/**
|
|
68
|
-
* Calls `push`
|
|
29
|
+
* Calls `push` on all peer connections
|
|
69
30
|
*/
|
|
70
31
|
pushToPeerStore(): Promise<void>;
|
|
71
32
|
/**
|
|
72
33
|
* Requests the `Identify` message from peer associated with the given `connection`.
|
|
73
34
|
* If the identified peer does not match the `PeerId` associated with the connection,
|
|
74
35
|
* an error will be thrown.
|
|
75
|
-
*
|
|
76
|
-
* @async
|
|
77
|
-
* @param {Connection} connection
|
|
78
|
-
* @returns {Promise<void>}
|
|
79
36
|
*/
|
|
80
37
|
identify(connection: Connection): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* A handler to register with Libp2p to process identify messages
|
|
40
|
+
*/
|
|
41
|
+
handleMessage(data: IncomingStreamData): Promise<void> | undefined;
|
|
81
42
|
/**
|
|
82
43
|
* Sends the `Identify` response with the Signed Peer Record
|
|
83
44
|
* to the requesting peer over the given `connection`
|
|
84
|
-
*
|
|
85
|
-
* @private
|
|
86
|
-
* @param {Object} options
|
|
87
|
-
* @param {MuxedStream} options.stream
|
|
88
|
-
* @param {Connection} options.connection
|
|
89
|
-
* @returns {Promise<void>}
|
|
90
45
|
*/
|
|
91
|
-
|
|
46
|
+
_handleIdentify(data: IncomingStreamData): Promise<void>;
|
|
92
47
|
/**
|
|
93
48
|
* Reads the Identify Push message from the given `connection`
|
|
94
|
-
*
|
|
95
|
-
* @private
|
|
96
|
-
* @param {object} options
|
|
97
|
-
* @param {MuxedStream} options.stream
|
|
98
|
-
* @param {Connection} options.connection
|
|
99
|
-
* @returns {Promise<void>}
|
|
100
49
|
*/
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
import PeerId = require("peer-id");
|
|
107
|
-
type Connection = import("libp2p-interfaces/src/connection/connection");
|
|
108
|
-
import { Multiaddr } from "multiaddr";
|
|
109
|
-
declare namespace multicodecs {
|
|
110
|
-
export { MULTICODEC_IDENTIFY as IDENTIFY };
|
|
111
|
-
export { MULTICODEC_IDENTIFY_PUSH as IDENTIFY_PUSH };
|
|
50
|
+
_handlePush(data: IncomingStreamData): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Takes the `addr` and converts it to a Multiaddr if possible
|
|
53
|
+
*/
|
|
54
|
+
static getCleanMultiaddr(addr: Uint8Array | string | null | undefined): Multiaddr | undefined;
|
|
112
55
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
56
|
+
/**
|
|
57
|
+
* The protocols the IdentifyService supports
|
|
58
|
+
*/
|
|
59
|
+
export declare const multicodecs: {
|
|
60
|
+
IDENTIFY: string;
|
|
61
|
+
IDENTIFY_PUSH: string;
|
|
62
|
+
};
|
|
63
|
+
export declare const Message: {
|
|
64
|
+
Identify: typeof Identify;
|
|
117
65
|
};
|
|
118
|
-
import { MULTICODEC_IDENTIFY } from "./consts";
|
|
119
|
-
import { MULTICODEC_IDENTIFY_PUSH } from "./consts";
|
|
120
66
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/identify/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/identify/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAa,MAAM,yBAAyB,CAAA;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAY1C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAEnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAI/D,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,cAAc,EAAE,MAAM,CAAA;IACtB,IAAI,EAAE,cAAc,CAAA;CACrB;AAED,qBAAa,eAAgB,YAAW,SAAS;IAC/C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAQ;IAC5C,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAQ;IAChD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAGpB;IAED,OAAO,CAAC,OAAO,CAAS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