libp2p 0.36.0 → 0.36.2-199395d
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 +25 -52
- 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 +16 -8
- 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 +16 -35
- package/dist/src/circuit/circuit/stream-handler.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stream-handler.js +60 -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/{protocol → pb}/index.d.ts +0 -0
- package/{src/circuit/protocol → dist/src/circuit/pb}/index.js +7 -9
- 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 +281 -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 +130 -0
- package/dist/src/fetch/index.js.map +1 -0
- package/dist/src/fetch/{proto.d.ts → pb/proto.d.ts} +0 -0
- package/{src/fetch → dist/src/fetch/pb}/proto.js +7 -9
- 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 +40 -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/{src/identify → dist/src/identify/pb}/message.d.ts +20 -5
- package/{src/identify → dist/src/identify/pb}/message.js +83 -42
- package/dist/src/index.d.ts +157 -583
- 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 +78 -0
- package/dist/src/insecure/index.js.map +1 -0
- package/dist/src/insecure/{proto.d.ts → pb/proto.d.ts} +7 -1
- package/{src/insecure → dist/src/insecure/pb}/proto.js +39 -22
- 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 +62 -82
- 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 +75 -0
- package/dist/src/libp2p.d.ts.map +1 -0
- package/dist/src/libp2p.js +368 -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 +45 -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 +145 -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 +87 -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.d.ts +0 -0
- package/src/circuit/pb/index.js +528 -0
- package/src/circuit/{protocol → pb}/index.proto +0 -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 +374 -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.js → index.ts} +79 -70
- package/src/fetch/{proto.d.ts → pb/proto.d.ts} +0 -0
- package/src/fetch/pb/proto.js +331 -0
- package/src/fetch/{proto.proto → pb/proto.proto} +0 -0
- package/src/get-peer.ts +57 -0
- package/src/identify/consts.ts +13 -0
- package/src/identify/index.ts +445 -0
- package/{dist/src/identify → src/identify/pb}/message.d.ts +20 -5
- package/src/identify/pb/message.js +369 -0
- package/src/identify/{message.proto → pb/message.proto} +0 -0
- package/src/index.ts +234 -0
- package/src/insecure/index.ts +97 -0
- package/src/insecure/{proto.d.ts → pb/proto.d.ts} +7 -1
- package/src/insecure/pb/proto.js +388 -0
- package/src/insecure/{proto.proto → pb/proto.proto} +0 -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 +501 -0
- package/src/metrics/index.ts +310 -0
- package/src/metrics/moving-average.ts +53 -0
- package/src/metrics/stats.ts +243 -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/insecure/plaintext.d.ts +0 -12
- package/dist/src/insecure/plaintext.d.ts.map +0 -1
- 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/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/get-peer.js +0 -49
- package/src/identify/consts.js +0 -15
- package/src/identify/index.js +0 -384
- package/src/index.js +0 -811
- package/src/insecure/plaintext.js +0 -95
- 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
package/src/errors.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export enum messages {
|
|
2
|
+
NOT_STARTED_YET = 'The libp2p node is not started yet',
|
|
3
|
+
DHT_DISABLED = 'DHT is not available',
|
|
4
|
+
CONN_ENCRYPTION_REQUIRED = 'At least one connection encryption module is required',
|
|
5
|
+
ERR_TRANSPORTS_REQUIRED = 'At least one transport module is required',
|
|
6
|
+
ERR_PROTECTOR_REQUIRED = 'Private network is enforced, but no protector was provided',
|
|
7
|
+
NOT_FOUND = 'Not found'
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export enum codes {
|
|
11
|
+
DHT_DISABLED = 'ERR_DHT_DISABLED',
|
|
12
|
+
PUBSUB_NOT_STARTED = 'ERR_PUBSUB_NOT_STARTED',
|
|
13
|
+
DHT_NOT_STARTED = 'ERR_DHT_NOT_STARTED',
|
|
14
|
+
CONN_ENCRYPTION_REQUIRED = 'ERR_CONN_ENCRYPTION_REQUIRED',
|
|
15
|
+
ERR_TRANSPORTS_REQUIRED = 'ERR_TRANSPORTS_REQUIRED',
|
|
16
|
+
ERR_PROTECTOR_REQUIRED = 'ERR_PROTECTOR_REQUIRED',
|
|
17
|
+
ERR_PEER_DIAL_INTERCEPTED = 'ERR_PEER_DIAL_INTERCEPTED',
|
|
18
|
+
ERR_CONNECTION_INTERCEPTED = 'ERR_CONNECTION_INTERCEPTED',
|
|
19
|
+
ERR_INVALID_PROTOCOLS_FOR_STREAM = 'ERR_INVALID_PROTOCOLS_FOR_STREAM',
|
|
20
|
+
ERR_CONNECTION_ENDED = 'ERR_CONNECTION_ENDED',
|
|
21
|
+
ERR_CONNECTION_FAILED = 'ERR_CONNECTION_FAILED',
|
|
22
|
+
ERR_NODE_NOT_STARTED = 'ERR_NODE_NOT_STARTED',
|
|
23
|
+
ERR_ALREADY_ABORTED = 'ERR_ALREADY_ABORTED',
|
|
24
|
+
ERR_TOO_MANY_ADDRESSES = 'ERR_TOO_MANY_ADDRESSES',
|
|
25
|
+
ERR_NO_VALID_ADDRESSES = 'ERR_NO_VALID_ADDRESSES',
|
|
26
|
+
ERR_RELAYED_DIAL = 'ERR_RELAYED_DIAL',
|
|
27
|
+
ERR_DIALED_SELF = 'ERR_DIALED_SELF',
|
|
28
|
+
ERR_DISCOVERED_SELF = 'ERR_DISCOVERED_SELF',
|
|
29
|
+
ERR_DUPLICATE_TRANSPORT = 'ERR_DUPLICATE_TRANSPORT',
|
|
30
|
+
ERR_ENCRYPTION_FAILED = 'ERR_ENCRYPTION_FAILED',
|
|
31
|
+
ERR_HOP_REQUEST_FAILED = 'ERR_HOP_REQUEST_FAILED',
|
|
32
|
+
ERR_INVALID_KEY = 'ERR_INVALID_KEY',
|
|
33
|
+
ERR_INVALID_MESSAGE = 'ERR_INVALID_MESSAGE',
|
|
34
|
+
ERR_INVALID_PARAMETERS = 'ERR_INVALID_PARAMETERS',
|
|
35
|
+
ERR_INVALID_PEER = 'ERR_INVALID_PEER',
|
|
36
|
+
ERR_MUXER_UNAVAILABLE = 'ERR_MUXER_UNAVAILABLE',
|
|
37
|
+
ERR_NOT_FOUND = 'ERR_NOT_FOUND',
|
|
38
|
+
ERR_TIMEOUT = 'ERR_TIMEOUT',
|
|
39
|
+
ERR_TRANSPORT_UNAVAILABLE = 'ERR_TRANSPORT_UNAVAILABLE',
|
|
40
|
+
ERR_TRANSPORT_DIAL_FAILED = 'ERR_TRANSPORT_DIAL_FAILED',
|
|
41
|
+
ERR_UNSUPPORTED_PROTOCOL = 'ERR_UNSUPPORTED_PROTOCOL',
|
|
42
|
+
ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED = 'ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED',
|
|
43
|
+
ERR_INVALID_MULTIADDR = 'ERR_INVALID_MULTIADDR',
|
|
44
|
+
ERR_SIGNATURE_NOT_VALID = 'ERR_SIGNATURE_NOT_VALID',
|
|
45
|
+
ERR_FIND_SELF = 'ERR_FIND_SELF',
|
|
46
|
+
ERR_NO_ROUTERS_AVAILABLE = 'ERR_NO_ROUTERS_AVAILABLE',
|
|
47
|
+
ERR_CONNECTION_NOT_MULTIPLEXED = 'ERR_CONNECTION_NOT_MULTIPLEXED',
|
|
48
|
+
ERR_NO_DIAL_TOKENS = 'ERR_NO_DIAL_TOKENS',
|
|
49
|
+
ERR_KEYCHAIN_REQUIRED = 'ERR_KEYCHAIN_REQUIRED',
|
|
50
|
+
ERR_INVALID_CMS = 'ERR_INVALID_CMS',
|
|
51
|
+
ERR_MISSING_KEYS = 'ERR_MISSING_KEYS',
|
|
52
|
+
ERR_NO_KEY = 'ERR_NO_KEY',
|
|
53
|
+
ERR_INVALID_KEY_NAME = 'ERR_INVALID_KEY_NAME',
|
|
54
|
+
ERR_INVALID_KEY_TYPE = 'ERR_INVALID_KEY_TYPE',
|
|
55
|
+
ERR_KEY_ALREADY_EXISTS = 'ERR_KEY_ALREADY_EXISTS',
|
|
56
|
+
ERR_INVALID_KEY_SIZE = 'ERR_INVALID_KEY_SIZE',
|
|
57
|
+
ERR_KEY_NOT_FOUND = 'ERR_KEY_NOT_FOUND',
|
|
58
|
+
ERR_OLD_KEY_NAME_INVALID = 'ERR_OLD_KEY_NAME_INVALID',
|
|
59
|
+
ERR_NEW_KEY_NAME_INVALID = 'ERR_NEW_KEY_NAME_INVALID',
|
|
60
|
+
ERR_PASSWORD_REQUIRED = 'ERR_PASSWORD_REQUIRED',
|
|
61
|
+
ERR_PEM_REQUIRED = 'ERR_PEM_REQUIRED',
|
|
62
|
+
ERR_CANNOT_READ_KEY = 'ERR_CANNOT_READ_KEY',
|
|
63
|
+
ERR_MISSING_PRIVATE_KEY = 'ERR_MISSING_PRIVATE_KEY',
|
|
64
|
+
ERR_MISSING_PUBLIC_KEY = 'ERR_MISSING_PUBLIC_KEY',
|
|
65
|
+
ERR_INVALID_OLD_PASS_TYPE = 'ERR_INVALID_OLD_PASS_TYPE',
|
|
66
|
+
ERR_INVALID_NEW_PASS_TYPE = 'ERR_INVALID_NEW_PASS_TYPE',
|
|
67
|
+
ERR_INVALID_PASS_LENGTH = 'ERR_INVALID_PASS_LENGTH',
|
|
68
|
+
ERR_NOT_IMPLEMENTED = 'ERR_NOT_IMPLEMENTED',
|
|
69
|
+
ERR_WRONG_PING_ACK = 'ERR_WRONG_PING_ACK',
|
|
70
|
+
ERR_INVALID_RECORD = 'ERR_INVALID_RECORD'
|
|
71
|
+
}
|
package/src/fetch/README.md
CHANGED
|
@@ -12,7 +12,7 @@ The fetch protocol is a simple protocol for requesting a value corresponding to
|
|
|
12
12
|
## Usage
|
|
13
13
|
|
|
14
14
|
```javascript
|
|
15
|
-
|
|
15
|
+
import { createLibp2p } from 'libp2p'
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Given a key (as a string) returns a value (as a Uint8Array), or null if the key isn't found.
|
|
@@ -1,24 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
+
import type { PeerId } from '@libp2p/interfaces/peer-id'
|
|
9
|
+
import type { Startable } from '@libp2p/interfaces'
|
|
10
|
+
import type { Stream } from '@libp2p/interfaces/connection'
|
|
11
|
+
import type { IncomingStreamData } from '@libp2p/interfaces/registrar'
|
|
12
|
+
import type { Components } from '@libp2p/interfaces/components'
|
|
13
|
+
|
|
14
|
+
const log = logger('libp2p:fetch')
|
|
15
|
+
|
|
16
|
+
export interface FetchInit {
|
|
17
|
+
protocolPrefix: string
|
|
18
|
+
}
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
export interface HandleMessageOptions {
|
|
21
|
+
stream: Stream
|
|
22
|
+
protocol: string
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface LookupFunction {
|
|
26
|
+
(key: string): Promise<Uint8Array | null>
|
|
27
|
+
}
|
|
22
28
|
|
|
23
29
|
/**
|
|
24
30
|
* A simple libp2p protocol for requesting a value corresponding to a key from a peer.
|
|
@@ -26,36 +32,54 @@ const { PROTOCOL } = require('./constants')
|
|
|
26
32
|
* a given key. Each lookup function must act on a distinct part of the overall key space, defined
|
|
27
33
|
* by a fixed prefix that all keys that should be routed to that lookup function will start with.
|
|
28
34
|
*/
|
|
29
|
-
class
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
export class FetchService implements Startable {
|
|
36
|
+
private readonly components: Components
|
|
37
|
+
private readonly lookupFunctions: Map<string, LookupFunction>
|
|
38
|
+
private readonly protocol: string
|
|
39
|
+
private started: boolean
|
|
40
|
+
|
|
41
|
+
constructor (components: Components, init: FetchInit) {
|
|
42
|
+
this.started = false
|
|
43
|
+
this.components = components
|
|
44
|
+
this.protocol = PROTOCOL
|
|
45
|
+
this.lookupFunctions = new Map() // Maps key prefix to value lookup function
|
|
36
46
|
this.handleMessage = this.handleMessage.bind(this)
|
|
37
47
|
}
|
|
38
48
|
|
|
49
|
+
async start () {
|
|
50
|
+
await this.components.getRegistrar().handle(this.protocol, (data) => {
|
|
51
|
+
void this.handleMessage(data).catch(err => {
|
|
52
|
+
log.error(err)
|
|
53
|
+
})
|
|
54
|
+
})
|
|
55
|
+
this.started = true
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async stop () {
|
|
59
|
+
await this.components.getRegistrar().unhandle(this.protocol)
|
|
60
|
+
this.started = false
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
isStarted () {
|
|
64
|
+
return this.started
|
|
65
|
+
}
|
|
66
|
+
|
|
39
67
|
/**
|
|
40
|
-
* Sends a request to fetch the value associated with the given key from the given peer
|
|
41
|
-
*
|
|
42
|
-
* @param {PeerId|Multiaddr} peer
|
|
43
|
-
* @param {string} key
|
|
44
|
-
* @returns {Promise<Uint8Array | null>}
|
|
68
|
+
* Sends a request to fetch the value associated with the given key from the given peer
|
|
45
69
|
*/
|
|
46
|
-
async fetch (peer, key) {
|
|
47
|
-
|
|
48
|
-
log('dialing %s to %s', this._protocol, peer.toB58String ? peer.toB58String() : peer)
|
|
70
|
+
async fetch (peer: PeerId, key: string): Promise<Uint8Array | null> {
|
|
71
|
+
log('dialing %s to %p', this.protocol, peer)
|
|
49
72
|
|
|
50
|
-
const connection = await this.
|
|
51
|
-
const { stream } = await connection.newStream(
|
|
73
|
+
const connection = await this.components.getDialer().dial(peer)
|
|
74
|
+
const { stream } = await connection.newStream([this.protocol])
|
|
52
75
|
const shake = handshake(stream)
|
|
53
76
|
|
|
54
77
|
// send message
|
|
55
78
|
const request = new FetchRequest({ identifier: key })
|
|
56
|
-
shake.write(lp.encode.single(FetchRequest.encode(request).finish()))
|
|
79
|
+
shake.write(lp.encode.single(FetchRequest.encode(request).finish()).slice())
|
|
57
80
|
|
|
58
81
|
// read response
|
|
82
|
+
// @ts-expect-error fromReader returns a Source which has no .next method
|
|
59
83
|
const response = FetchResponse.decode((await lp.decode.fromReader(shake.reader).next()).value.slice())
|
|
60
84
|
switch (response.status) {
|
|
61
85
|
case (FetchResponse.StatusCode.OK): {
|
|
@@ -78,21 +102,18 @@ class FetchProtocol {
|
|
|
78
102
|
* Invoked when a fetch request is received. Reads the request message off the given stream and
|
|
79
103
|
* responds based on looking up the key in the request via the lookup callback that corresponds
|
|
80
104
|
* to the key's prefix.
|
|
81
|
-
*
|
|
82
|
-
* @param {object} options
|
|
83
|
-
* @param {MuxedStream} options.stream
|
|
84
|
-
* @param {string} options.protocol
|
|
85
105
|
*/
|
|
86
|
-
async handleMessage (
|
|
87
|
-
const { stream } =
|
|
106
|
+
async handleMessage (data: IncomingStreamData) {
|
|
107
|
+
const { stream } = data
|
|
88
108
|
const shake = handshake(stream)
|
|
109
|
+
// @ts-expect-error fromReader returns a Source which has no .next method
|
|
89
110
|
const request = FetchRequest.decode((await lp.decode.fromReader(shake.reader).next()).value.slice())
|
|
90
111
|
|
|
91
112
|
let response
|
|
92
113
|
const lookup = this._getLookupFunction(request.identifier)
|
|
93
|
-
if (lookup) {
|
|
114
|
+
if (lookup != null) {
|
|
94
115
|
const data = await lookup(request.identifier)
|
|
95
|
-
if (data) {
|
|
116
|
+
if (data != null) {
|
|
96
117
|
response = new FetchResponse({ status: FetchResponse.StatusCode.OK, data })
|
|
97
118
|
} else {
|
|
98
119
|
response = new FetchResponse({ status: FetchResponse.StatusCode.NOT_FOUND })
|
|
@@ -102,58 +123,46 @@ class FetchProtocol {
|
|
|
102
123
|
response = new FetchResponse({ status: FetchResponse.StatusCode.ERROR, data: errmsg })
|
|
103
124
|
}
|
|
104
125
|
|
|
105
|
-
shake.write(lp.encode.single(FetchResponse.encode(response).finish()))
|
|
126
|
+
shake.write(lp.encode.single(FetchResponse.encode(response).finish()).slice())
|
|
106
127
|
}
|
|
107
128
|
|
|
108
129
|
/**
|
|
109
130
|
* Given a key, finds the appropriate function for looking up its corresponding value, based on
|
|
110
131
|
* the key's prefix.
|
|
111
|
-
*
|
|
112
|
-
* @param {string} key
|
|
113
132
|
*/
|
|
114
|
-
_getLookupFunction (key) {
|
|
115
|
-
for (const prefix of this.
|
|
133
|
+
_getLookupFunction (key: string) {
|
|
134
|
+
for (const prefix of this.lookupFunctions.keys()) {
|
|
116
135
|
if (key.startsWith(prefix)) {
|
|
117
|
-
return this.
|
|
136
|
+
return this.lookupFunctions.get(prefix)
|
|
118
137
|
}
|
|
119
138
|
}
|
|
120
|
-
return null
|
|
121
139
|
}
|
|
122
140
|
|
|
123
141
|
/**
|
|
124
142
|
* Registers a new lookup callback that can map keys to values, for a given set of keys that
|
|
125
|
-
* share the same prefix
|
|
126
|
-
*
|
|
127
|
-
* @param {string} prefix
|
|
128
|
-
* @param {LookupFunction} lookup
|
|
143
|
+
* share the same prefix
|
|
129
144
|
*/
|
|
130
|
-
registerLookupFunction (prefix, lookup) {
|
|
131
|
-
if (this.
|
|
145
|
+
registerLookupFunction (prefix: string, lookup: LookupFunction) {
|
|
146
|
+
if (this.lookupFunctions.has(prefix)) {
|
|
132
147
|
throw errCode(new Error("Fetch protocol handler for key prefix '" + prefix + "' already registered"), codes.ERR_KEY_ALREADY_EXISTS)
|
|
133
148
|
}
|
|
134
|
-
|
|
149
|
+
|
|
150
|
+
this.lookupFunctions.set(prefix, lookup)
|
|
135
151
|
}
|
|
136
152
|
|
|
137
153
|
/**
|
|
138
154
|
* Registers a new lookup callback that can map keys to values, for a given set of keys that
|
|
139
155
|
* share the same prefix.
|
|
140
|
-
*
|
|
141
|
-
* @param {string} prefix
|
|
142
|
-
* @param {LookupFunction} [lookup]
|
|
143
156
|
*/
|
|
144
|
-
unregisterLookupFunction (prefix, lookup) {
|
|
157
|
+
unregisterLookupFunction (prefix: string, lookup?: LookupFunction) {
|
|
145
158
|
if (lookup != null) {
|
|
146
|
-
const existingLookup = this.
|
|
159
|
+
const existingLookup = this.lookupFunctions.get(prefix)
|
|
147
160
|
|
|
148
161
|
if (existingLookup !== lookup) {
|
|
149
162
|
return
|
|
150
163
|
}
|
|
151
164
|
}
|
|
152
165
|
|
|
153
|
-
this.
|
|
166
|
+
this.lookupFunctions.delete(prefix)
|
|
154
167
|
}
|
|
155
168
|
}
|
|
156
|
-
|
|
157
|
-
FetchProtocol.PROTOCOL = PROTOCOL
|
|
158
|
-
|
|
159
|
-
exports = module.exports = FetchProtocol
|
|
File without changes
|
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
/*eslint-disable*/
|
|
2
|
+
import $protobuf from "protobufjs/minimal.js";
|
|
3
|
+
|
|
4
|
+
// Common aliases
|
|
5
|
+
const $Reader = $protobuf.Reader, $Writer = $protobuf.Writer, $util = $protobuf.util;
|
|
6
|
+
|
|
7
|
+
// Exported root namespace
|
|
8
|
+
const $root = $protobuf.roots["libp2p-fetch"] || ($protobuf.roots["libp2p-fetch"] = {});
|
|
9
|
+
|
|
10
|
+
export const FetchRequest = $root.FetchRequest = (() => {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Properties of a FetchRequest.
|
|
14
|
+
* @exports IFetchRequest
|
|
15
|
+
* @interface IFetchRequest
|
|
16
|
+
* @property {string|null} [identifier] FetchRequest identifier
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Constructs a new FetchRequest.
|
|
21
|
+
* @exports FetchRequest
|
|
22
|
+
* @classdesc Represents a FetchRequest.
|
|
23
|
+
* @implements IFetchRequest
|
|
24
|
+
* @constructor
|
|
25
|
+
* @param {IFetchRequest=} [p] Properties to set
|
|
26
|
+
*/
|
|
27
|
+
function FetchRequest(p) {
|
|
28
|
+
if (p)
|
|
29
|
+
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
|
|
30
|
+
if (p[ks[i]] != null)
|
|
31
|
+
this[ks[i]] = p[ks[i]];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* FetchRequest identifier.
|
|
36
|
+
* @member {string} identifier
|
|
37
|
+
* @memberof FetchRequest
|
|
38
|
+
* @instance
|
|
39
|
+
*/
|
|
40
|
+
FetchRequest.prototype.identifier = "";
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Encodes the specified FetchRequest message. Does not implicitly {@link FetchRequest.verify|verify} messages.
|
|
44
|
+
* @function encode
|
|
45
|
+
* @memberof FetchRequest
|
|
46
|
+
* @static
|
|
47
|
+
* @param {IFetchRequest} m FetchRequest message or plain object to encode
|
|
48
|
+
* @param {$protobuf.Writer} [w] Writer to encode to
|
|
49
|
+
* @returns {$protobuf.Writer} Writer
|
|
50
|
+
*/
|
|
51
|
+
FetchRequest.encode = function encode(m, w) {
|
|
52
|
+
if (!w)
|
|
53
|
+
w = $Writer.create();
|
|
54
|
+
if (m.identifier != null && Object.hasOwnProperty.call(m, "identifier"))
|
|
55
|
+
w.uint32(10).string(m.identifier);
|
|
56
|
+
return w;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Decodes a FetchRequest message from the specified reader or buffer.
|
|
61
|
+
* @function decode
|
|
62
|
+
* @memberof FetchRequest
|
|
63
|
+
* @static
|
|
64
|
+
* @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
|
|
65
|
+
* @param {number} [l] Message length if known beforehand
|
|
66
|
+
* @returns {FetchRequest} FetchRequest
|
|
67
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
68
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
69
|
+
*/
|
|
70
|
+
FetchRequest.decode = function decode(r, l) {
|
|
71
|
+
if (!(r instanceof $Reader))
|
|
72
|
+
r = $Reader.create(r);
|
|
73
|
+
var c = l === undefined ? r.len : r.pos + l, m = new $root.FetchRequest();
|
|
74
|
+
while (r.pos < c) {
|
|
75
|
+
var t = r.uint32();
|
|
76
|
+
switch (t >>> 3) {
|
|
77
|
+
case 1:
|
|
78
|
+
m.identifier = r.string();
|
|
79
|
+
break;
|
|
80
|
+
default:
|
|
81
|
+
r.skipType(t & 7);
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return m;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Creates a FetchRequest message from a plain object. Also converts values to their respective internal types.
|
|
90
|
+
* @function fromObject
|
|
91
|
+
* @memberof FetchRequest
|
|
92
|
+
* @static
|
|
93
|
+
* @param {Object.<string,*>} d Plain object
|
|
94
|
+
* @returns {FetchRequest} FetchRequest
|
|
95
|
+
*/
|
|
96
|
+
FetchRequest.fromObject = function fromObject(d) {
|
|
97
|
+
if (d instanceof $root.FetchRequest)
|
|
98
|
+
return d;
|
|
99
|
+
var m = new $root.FetchRequest();
|
|
100
|
+
if (d.identifier != null) {
|
|
101
|
+
m.identifier = String(d.identifier);
|
|
102
|
+
}
|
|
103
|
+
return m;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Creates a plain object from a FetchRequest message. Also converts values to other types if specified.
|
|
108
|
+
* @function toObject
|
|
109
|
+
* @memberof FetchRequest
|
|
110
|
+
* @static
|
|
111
|
+
* @param {FetchRequest} m FetchRequest
|
|
112
|
+
* @param {$protobuf.IConversionOptions} [o] Conversion options
|
|
113
|
+
* @returns {Object.<string,*>} Plain object
|
|
114
|
+
*/
|
|
115
|
+
FetchRequest.toObject = function toObject(m, o) {
|
|
116
|
+
if (!o)
|
|
117
|
+
o = {};
|
|
118
|
+
var d = {};
|
|
119
|
+
if (o.defaults) {
|
|
120
|
+
d.identifier = "";
|
|
121
|
+
}
|
|
122
|
+
if (m.identifier != null && m.hasOwnProperty("identifier")) {
|
|
123
|
+
d.identifier = m.identifier;
|
|
124
|
+
}
|
|
125
|
+
return d;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Converts this FetchRequest to JSON.
|
|
130
|
+
* @function toJSON
|
|
131
|
+
* @memberof FetchRequest
|
|
132
|
+
* @instance
|
|
133
|
+
* @returns {Object.<string,*>} JSON object
|
|
134
|
+
*/
|
|
135
|
+
FetchRequest.prototype.toJSON = function toJSON() {
|
|
136
|
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
return FetchRequest;
|
|
140
|
+
})();
|
|
141
|
+
|
|
142
|
+
export const FetchResponse = $root.FetchResponse = (() => {
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Properties of a FetchResponse.
|
|
146
|
+
* @exports IFetchResponse
|
|
147
|
+
* @interface IFetchResponse
|
|
148
|
+
* @property {FetchResponse.StatusCode|null} [status] FetchResponse status
|
|
149
|
+
* @property {Uint8Array|null} [data] FetchResponse data
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Constructs a new FetchResponse.
|
|
154
|
+
* @exports FetchResponse
|
|
155
|
+
* @classdesc Represents a FetchResponse.
|
|
156
|
+
* @implements IFetchResponse
|
|
157
|
+
* @constructor
|
|
158
|
+
* @param {IFetchResponse=} [p] Properties to set
|
|
159
|
+
*/
|
|
160
|
+
function FetchResponse(p) {
|
|
161
|
+
if (p)
|
|
162
|
+
for (var ks = Object.keys(p), i = 0; i < ks.length; ++i)
|
|
163
|
+
if (p[ks[i]] != null)
|
|
164
|
+
this[ks[i]] = p[ks[i]];
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* FetchResponse status.
|
|
169
|
+
* @member {FetchResponse.StatusCode} status
|
|
170
|
+
* @memberof FetchResponse
|
|
171
|
+
* @instance
|
|
172
|
+
*/
|
|
173
|
+
FetchResponse.prototype.status = 0;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* FetchResponse data.
|
|
177
|
+
* @member {Uint8Array} data
|
|
178
|
+
* @memberof FetchResponse
|
|
179
|
+
* @instance
|
|
180
|
+
*/
|
|
181
|
+
FetchResponse.prototype.data = $util.newBuffer([]);
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Encodes the specified FetchResponse message. Does not implicitly {@link FetchResponse.verify|verify} messages.
|
|
185
|
+
* @function encode
|
|
186
|
+
* @memberof FetchResponse
|
|
187
|
+
* @static
|
|
188
|
+
* @param {IFetchResponse} m FetchResponse message or plain object to encode
|
|
189
|
+
* @param {$protobuf.Writer} [w] Writer to encode to
|
|
190
|
+
* @returns {$protobuf.Writer} Writer
|
|
191
|
+
*/
|
|
192
|
+
FetchResponse.encode = function encode(m, w) {
|
|
193
|
+
if (!w)
|
|
194
|
+
w = $Writer.create();
|
|
195
|
+
if (m.status != null && Object.hasOwnProperty.call(m, "status"))
|
|
196
|
+
w.uint32(8).int32(m.status);
|
|
197
|
+
if (m.data != null && Object.hasOwnProperty.call(m, "data"))
|
|
198
|
+
w.uint32(18).bytes(m.data);
|
|
199
|
+
return w;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Decodes a FetchResponse message from the specified reader or buffer.
|
|
204
|
+
* @function decode
|
|
205
|
+
* @memberof FetchResponse
|
|
206
|
+
* @static
|
|
207
|
+
* @param {$protobuf.Reader|Uint8Array} r Reader or buffer to decode from
|
|
208
|
+
* @param {number} [l] Message length if known beforehand
|
|
209
|
+
* @returns {FetchResponse} FetchResponse
|
|
210
|
+
* @throws {Error} If the payload is not a reader or valid buffer
|
|
211
|
+
* @throws {$protobuf.util.ProtocolError} If required fields are missing
|
|
212
|
+
*/
|
|
213
|
+
FetchResponse.decode = function decode(r, l) {
|
|
214
|
+
if (!(r instanceof $Reader))
|
|
215
|
+
r = $Reader.create(r);
|
|
216
|
+
var c = l === undefined ? r.len : r.pos + l, m = new $root.FetchResponse();
|
|
217
|
+
while (r.pos < c) {
|
|
218
|
+
var t = r.uint32();
|
|
219
|
+
switch (t >>> 3) {
|
|
220
|
+
case 1:
|
|
221
|
+
m.status = r.int32();
|
|
222
|
+
break;
|
|
223
|
+
case 2:
|
|
224
|
+
m.data = r.bytes();
|
|
225
|
+
break;
|
|
226
|
+
default:
|
|
227
|
+
r.skipType(t & 7);
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return m;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Creates a FetchResponse message from a plain object. Also converts values to their respective internal types.
|
|
236
|
+
* @function fromObject
|
|
237
|
+
* @memberof FetchResponse
|
|
238
|
+
* @static
|
|
239
|
+
* @param {Object.<string,*>} d Plain object
|
|
240
|
+
* @returns {FetchResponse} FetchResponse
|
|
241
|
+
*/
|
|
242
|
+
FetchResponse.fromObject = function fromObject(d) {
|
|
243
|
+
if (d instanceof $root.FetchResponse)
|
|
244
|
+
return d;
|
|
245
|
+
var m = new $root.FetchResponse();
|
|
246
|
+
switch (d.status) {
|
|
247
|
+
case "OK":
|
|
248
|
+
case 0:
|
|
249
|
+
m.status = 0;
|
|
250
|
+
break;
|
|
251
|
+
case "NOT_FOUND":
|
|
252
|
+
case 1:
|
|
253
|
+
m.status = 1;
|
|
254
|
+
break;
|
|
255
|
+
case "ERROR":
|
|
256
|
+
case 2:
|
|
257
|
+
m.status = 2;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
if (d.data != null) {
|
|
261
|
+
if (typeof d.data === "string")
|
|
262
|
+
$util.base64.decode(d.data, m.data = $util.newBuffer($util.base64.length(d.data)), 0);
|
|
263
|
+
else if (d.data.length)
|
|
264
|
+
m.data = d.data;
|
|
265
|
+
}
|
|
266
|
+
return m;
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Creates a plain object from a FetchResponse message. Also converts values to other types if specified.
|
|
271
|
+
* @function toObject
|
|
272
|
+
* @memberof FetchResponse
|
|
273
|
+
* @static
|
|
274
|
+
* @param {FetchResponse} m FetchResponse
|
|
275
|
+
* @param {$protobuf.IConversionOptions} [o] Conversion options
|
|
276
|
+
* @returns {Object.<string,*>} Plain object
|
|
277
|
+
*/
|
|
278
|
+
FetchResponse.toObject = function toObject(m, o) {
|
|
279
|
+
if (!o)
|
|
280
|
+
o = {};
|
|
281
|
+
var d = {};
|
|
282
|
+
if (o.defaults) {
|
|
283
|
+
d.status = o.enums === String ? "OK" : 0;
|
|
284
|
+
if (o.bytes === String)
|
|
285
|
+
d.data = "";
|
|
286
|
+
else {
|
|
287
|
+
d.data = [];
|
|
288
|
+
if (o.bytes !== Array)
|
|
289
|
+
d.data = $util.newBuffer(d.data);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (m.status != null && m.hasOwnProperty("status")) {
|
|
293
|
+
d.status = o.enums === String ? $root.FetchResponse.StatusCode[m.status] : m.status;
|
|
294
|
+
}
|
|
295
|
+
if (m.data != null && m.hasOwnProperty("data")) {
|
|
296
|
+
d.data = o.bytes === String ? $util.base64.encode(m.data, 0, m.data.length) : o.bytes === Array ? Array.prototype.slice.call(m.data) : m.data;
|
|
297
|
+
}
|
|
298
|
+
return d;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Converts this FetchResponse to JSON.
|
|
303
|
+
* @function toJSON
|
|
304
|
+
* @memberof FetchResponse
|
|
305
|
+
* @instance
|
|
306
|
+
* @returns {Object.<string,*>} JSON object
|
|
307
|
+
*/
|
|
308
|
+
FetchResponse.prototype.toJSON = function toJSON() {
|
|
309
|
+
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* StatusCode enum.
|
|
314
|
+
* @name FetchResponse.StatusCode
|
|
315
|
+
* @enum {number}
|
|
316
|
+
* @property {number} OK=0 OK value
|
|
317
|
+
* @property {number} NOT_FOUND=1 NOT_FOUND value
|
|
318
|
+
* @property {number} ERROR=2 ERROR value
|
|
319
|
+
*/
|
|
320
|
+
FetchResponse.StatusCode = (function() {
|
|
321
|
+
const valuesById = {}, values = Object.create(valuesById);
|
|
322
|
+
values[valuesById[0] = "OK"] = 0;
|
|
323
|
+
values[valuesById[1] = "NOT_FOUND"] = 1;
|
|
324
|
+
values[valuesById[2] = "ERROR"] = 2;
|
|
325
|
+
return values;
|
|
326
|
+
})();
|
|
327
|
+
|
|
328
|
+
return FetchResponse;
|
|
329
|
+
})();
|
|
330
|
+
|
|
331
|
+
export { $root as default };
|
|
File without changes
|