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
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const INVALID_PEER = 'Not a valid peer connection';
|
|
2
|
+
export const INVALID_PSK = 'Your private shared key is invalid';
|
|
3
|
+
export const NO_LOCAL_ID = 'No local private key provided';
|
|
4
|
+
export const NO_HANDSHAKE_CONNECTION = 'No connection for the handshake provided';
|
|
5
|
+
export const STREAM_ENDED = 'Stream ended prematurely';
|
|
6
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/pnet/errors.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,YAAY,GAAG,6BAA6B,CAAA;AACzD,MAAM,CAAC,MAAM,WAAW,GAAG,oCAAoC,CAAA;AAC/D,MAAM,CAAC,MAAM,WAAW,GAAG,+BAA+B,CAAA;AAC1D,MAAM,CAAC,MAAM,uBAAuB,GAAG,0CAA0C,CAAA;AACjF,MAAM,CAAC,MAAM,YAAY,GAAG,0BAA0B,CAAA"}
|
package/dist/src/pnet/index.d.ts
CHANGED
|
@@ -1,32 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { MultiaddrConnection } from '@libp2p/interfaces/transport';
|
|
2
|
+
import type { ConnectionProtector } from '@libp2p/interfaces/connection';
|
|
3
|
+
export interface ProtectorInit {
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
psk: Uint8Array;
|
|
6
|
+
}
|
|
7
|
+
export declare class PreSharedKeyConnectionProtector implements ConnectionProtector {
|
|
8
|
+
tag: string;
|
|
9
|
+
private readonly psk;
|
|
10
|
+
private readonly enabled;
|
|
6
11
|
/**
|
|
7
12
|
* Takes a Private Shared Key (psk) and provides a `protect` method
|
|
8
13
|
* for wrapping existing connections in a private encryption stream.
|
|
9
|
-
*
|
|
10
|
-
* @param {Uint8Array} keyBuffer - The private shared key buffer
|
|
11
|
-
* @class
|
|
12
14
|
*/
|
|
13
|
-
constructor(
|
|
14
|
-
psk: Uint8Array;
|
|
15
|
-
tag: string | undefined;
|
|
15
|
+
constructor(init: ProtectorInit);
|
|
16
16
|
/**
|
|
17
17
|
* Takes a given Connection and creates a private encryption stream
|
|
18
18
|
* between its two peers from the PSK the Protector instance was
|
|
19
19
|
* created with.
|
|
20
|
-
*
|
|
21
|
-
* @param {MultiaddrConnection} connection - The connection to protect
|
|
22
|
-
* @returns {Promise<MultiaddrConnection>} A protected duplex iterable
|
|
23
20
|
*/
|
|
24
21
|
protect(connection: MultiaddrConnection): Promise<MultiaddrConnection>;
|
|
25
22
|
}
|
|
26
|
-
declare namespace Protector {
|
|
27
|
-
export { Errors as errors, generate, MultiaddrConnection };
|
|
28
|
-
}
|
|
29
|
-
type MultiaddrConnection = import('libp2p-interfaces/src/transport/types').MultiaddrConnection;
|
|
30
|
-
import Errors = require("./errors");
|
|
31
|
-
declare var generate: typeof import("./key-generator");
|
|
32
23
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pnet/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pnet/index.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAA;AAIxE,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,GAAG,EAAE,UAAU,CAAA;CAChB;AAED,qBAAa,+BAAgC,YAAW,mBAAmB;IAClE,GAAG,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAY;IAChC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAEjC;;;OAGG;gBACU,IAAI,EAAE,aAAa;IAahC;;;;OAIG;IACG,OAAO,CAAE,UAAU,EAAE,mBAAmB,GAAG,OAAO,CAAC,mBAAmB,CAAC;CA2C9E"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { logger } from '@libp2p/logger';
|
|
2
|
+
import { pipe } from 'it-pipe';
|
|
3
|
+
import errCode from 'err-code';
|
|
4
|
+
import { duplexPair } from 'it-pair/duplex';
|
|
5
|
+
import { randomBytes } from '@libp2p/crypto';
|
|
6
|
+
import * as Errors from './errors.js';
|
|
7
|
+
import { codes } from '../errors.js';
|
|
8
|
+
import { createBoxStream, createUnboxStream, decodeV1PSK } from './crypto.js';
|
|
9
|
+
import { handshake } from 'it-handshake';
|
|
10
|
+
import { NONCE_LENGTH } from './key-generator.js';
|
|
11
|
+
const log = logger('libp2p:pnet');
|
|
12
|
+
export class PreSharedKeyConnectionProtector {
|
|
13
|
+
/**
|
|
14
|
+
* Takes a Private Shared Key (psk) and provides a `protect` method
|
|
15
|
+
* for wrapping existing connections in a private encryption stream.
|
|
16
|
+
*/
|
|
17
|
+
constructor(init) {
|
|
18
|
+
this.enabled = init.enabled !== false;
|
|
19
|
+
if (this.enabled) {
|
|
20
|
+
const decodedPSK = decodeV1PSK(init.psk);
|
|
21
|
+
this.psk = decodedPSK.psk;
|
|
22
|
+
this.tag = decodedPSK.tag ?? '';
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
this.psk = new Uint8Array();
|
|
26
|
+
this.tag = '';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Takes a given Connection and creates a private encryption stream
|
|
31
|
+
* between its two peers from the PSK the Protector instance was
|
|
32
|
+
* created with.
|
|
33
|
+
*/
|
|
34
|
+
async protect(connection) {
|
|
35
|
+
if (!this.enabled) {
|
|
36
|
+
return connection;
|
|
37
|
+
}
|
|
38
|
+
if (connection == null) {
|
|
39
|
+
throw errCode(new Error(Errors.NO_HANDSHAKE_CONNECTION), codes.ERR_INVALID_PARAMETERS);
|
|
40
|
+
}
|
|
41
|
+
// Exchange nonces
|
|
42
|
+
log('protecting the connection');
|
|
43
|
+
const localNonce = randomBytes(NONCE_LENGTH);
|
|
44
|
+
const shake = handshake(connection);
|
|
45
|
+
shake.write(localNonce);
|
|
46
|
+
const result = await shake.reader.next(NONCE_LENGTH);
|
|
47
|
+
if (result.value == null) {
|
|
48
|
+
throw errCode(new Error(Errors.STREAM_ENDED), codes.ERR_INVALID_PARAMETERS);
|
|
49
|
+
}
|
|
50
|
+
const remoteNonce = result.value.slice();
|
|
51
|
+
shake.rest();
|
|
52
|
+
// Create the boxing/unboxing pipe
|
|
53
|
+
log('exchanged nonces');
|
|
54
|
+
const [internal, external] = duplexPair();
|
|
55
|
+
pipe(external,
|
|
56
|
+
// Encrypt all outbound traffic
|
|
57
|
+
createBoxStream(localNonce, this.psk), shake.stream,
|
|
58
|
+
// Decrypt all inbound traffic
|
|
59
|
+
createUnboxStream(remoteNonce, this.psk), external).catch(log.error);
|
|
60
|
+
return {
|
|
61
|
+
...connection,
|
|
62
|
+
...internal
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pnet/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAC9B,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,WAAW,EACZ,MAAM,aAAa,CAAA;AACpB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAIjD,MAAM,GAAG,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AAOjC,MAAM,OAAO,+BAA+B;IAK1C;;;OAGG;IACH,YAAa,IAAmB;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,KAAK,KAAK,CAAA;QAErC,IAAI,IAAI,CAAC,OAAO,EAAE;YAChB,MAAM,UAAU,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACxC,IAAI,CAAC,GAAG,GAAG,UAAU,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I,CAAC,GAAG,CAAC,EACrC,KAAK,CAAC,MAAM;QACZ,8BAA8B;QAC9B,iBAAiB,CAAC,WAAW,EAAE,IAAI,CAAC,GAAG,CAAC,EACxC,QAAQ,CACT,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QAElB,OAAO;YACL,GAAG,UAAU;YACb,GAAG,QAAQ;SACZ,CAAA;IACH,CAAC;CACF"}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
export = generate;
|
|
2
1
|
/**
|
|
3
2
|
* Generates a PSK that can be used in a libp2p-pnet private network
|
|
4
3
|
*
|
|
5
4
|
* @param {Uint8Array} bytes - An object to write the psk into
|
|
6
5
|
* @returns {void}
|
|
7
6
|
*/
|
|
8
|
-
declare function generate(bytes: Uint8Array): void;
|
|
9
|
-
declare
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
declare var NONCE_LENGTH: number;
|
|
13
|
-
declare const KEY_LENGTH: 32;
|
|
7
|
+
export declare function generate(bytes: Uint8Array): void;
|
|
8
|
+
export declare const NONCE_LENGTH = 24;
|
|
9
|
+
export declare const KEY_LENGTH = 32;
|
|
14
10
|
//# sourceMappingURL=key-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-generator.d.ts","sourceRoot":"","sources":["../../../src/pnet/key-generator.
|
|
1
|
+
{"version":3,"file":"key-generator.d.ts","sourceRoot":"","sources":["../../../src/pnet/key-generator.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAE,KAAK,EAAE,UAAU,QAK1C;AAED,eAAO,MAAM,YAAY,KAAK,CAAA;AAC9B,eAAO,MAAM,UAAU,KAAK,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { randomBytes } from '@libp2p/crypto';
|
|
2
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
3
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
4
|
+
/**
|
|
5
|
+
* Generates a PSK that can be used in a libp2p-pnet private network
|
|
6
|
+
*
|
|
7
|
+
* @param {Uint8Array} bytes - An object to write the psk into
|
|
8
|
+
* @returns {void}
|
|
9
|
+
*/
|
|
10
|
+
export function generate(bytes) {
|
|
11
|
+
const psk = uint8ArrayToString(randomBytes(KEY_LENGTH), 'base16');
|
|
12
|
+
const key = uint8ArrayFromString('/key/swarm/psk/1.0.0/\n/base16/\n' + psk);
|
|
13
|
+
bytes.set(key);
|
|
14
|
+
}
|
|
15
|
+
export const NONCE_LENGTH = 24;
|
|
16
|
+
export const KEY_LENGTH = 32;
|
|
17
|
+
try {
|
|
18
|
+
if (require.main === module) {
|
|
19
|
+
// @ts-expect-error
|
|
20
|
+
generate(process.stdout);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=key-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-generator.js","sourceRoot":"","sources":["../../../src/pnet/key-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AACtE,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAE5E;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAE,KAAiB;IACzC,MAAM,GAAG,GAAG,kBAAkB,CAAC,WAAW,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,CAAA;IACjE,MAAM,GAAG,GAAG,oBAAoB,CAAC,mCAAmC,GAAG,GAAG,CAAC,CAAA;IAE3E,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,EAAE,CAAA;AAC9B,MAAM,CAAC,MAAM,UAAU,GAAG,EAAE,CAAA;AAE5B,IAAI;IACF,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE;QAC3B,mBAAmB;QACnB,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;KACzB;CACF;AAAC,OAAO,KAAU,EAAE;CAEpB"}
|
package/dist/src/registrar.d.ts
CHANGED
|
@@ -1,82 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
7
|
-
* @typedef {import('./').HandlerProps} HandlerProps
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
*/
|
|
1
|
+
import { Topology } from '@libp2p/interfaces/topology';
|
|
2
|
+
import type { Registrar, StreamHandler } from '@libp2p/interfaces/registrar';
|
|
3
|
+
import type { PeerProtocolsChangeData } from '@libp2p/interfaces/peer-store';
|
|
4
|
+
import type { Connection } from '@libp2p/interfaces/connection';
|
|
5
|
+
import type { Components } from '@libp2p/interfaces/components';
|
|
12
6
|
/**
|
|
13
7
|
* Responsible for notifying registered protocols of events in the network.
|
|
14
8
|
*/
|
|
15
|
-
declare class Registrar {
|
|
9
|
+
export declare class DefaultRegistrar implements Registrar {
|
|
10
|
+
private readonly topologies;
|
|
11
|
+
private readonly handlers;
|
|
12
|
+
private readonly components;
|
|
13
|
+
constructor(components: Components);
|
|
14
|
+
getProtocols(): string[];
|
|
15
|
+
getHandler(protocol: string): StreamHandler;
|
|
16
|
+
getTopologies(protocol: string): Topology[];
|
|
16
17
|
/**
|
|
17
|
-
*
|
|
18
|
-
* @param {PeerStore} props.peerStore
|
|
19
|
-
* @param {ConnectionManager} props.connectionManager
|
|
20
|
-
* @class
|
|
18
|
+
* Registers the `handler` for each protocol
|
|
21
19
|
*/
|
|
22
|
-
|
|
23
|
-
peerStore: PeerStore;
|
|
24
|
-
connectionManager: ConnectionManager;
|
|
25
|
-
});
|
|
26
|
-
peerStore: import("./peer-store/types").PeerStore;
|
|
27
|
-
connectionManager: import("./connection-manager");
|
|
20
|
+
handle(protocols: string | string[], handler: StreamHandler): Promise<void>;
|
|
28
21
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @type {Map<string, Topology>}
|
|
32
|
-
*/
|
|
33
|
-
topologies: Map<string, Topology>;
|
|
34
|
-
/** @type {(protocols: string[]|string, handler: (props: HandlerProps) => void) => void} */
|
|
35
|
-
_handle: (protocols: string[] | string, handler: (props: HandlerProps) => void) => void;
|
|
36
|
-
/**
|
|
37
|
-
* Remove a disconnected peer from the record
|
|
38
|
-
*
|
|
39
|
-
* @param {Connection} connection
|
|
40
|
-
* @returns {void}
|
|
22
|
+
* Removes the handler for each protocol. The protocol
|
|
23
|
+
* will no longer be supported on streams.
|
|
41
24
|
*/
|
|
42
|
-
|
|
25
|
+
unhandle(protocols: string | string[]): Promise<void>;
|
|
43
26
|
/**
|
|
44
|
-
*
|
|
45
|
-
*/
|
|
46
|
-
set handle(arg: (protocols: string[] | string, handler: (props: HandlerProps) => void) => void);
|
|
47
|
-
/**
|
|
48
|
-
* @returns {(protocols: string[]|string, handler: (props: HandlerProps) => void) => void}
|
|
27
|
+
* Register handlers for a set of multicodecs given
|
|
49
28
|
*/
|
|
50
|
-
|
|
29
|
+
register(protocols: string | string[], topology: Topology): Promise<string>;
|
|
51
30
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @param {PeerId} peerId
|
|
55
|
-
* @returns {Connection | null}
|
|
31
|
+
* Unregister topology
|
|
56
32
|
*/
|
|
57
|
-
|
|
33
|
+
unregister(id: string): void;
|
|
58
34
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* @param {Topology} topology - protocol topology
|
|
62
|
-
* @returns {Promise<string>} registrar identifier
|
|
35
|
+
* Remove a disconnected peer from the record
|
|
63
36
|
*/
|
|
64
|
-
|
|
37
|
+
_onDisconnect(evt: CustomEvent<Connection>): void;
|
|
38
|
+
_onConnect(evt: CustomEvent<Connection>): void;
|
|
65
39
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* @param {string} id - registrar identifier
|
|
69
|
-
* @returns {boolean} unregistered successfully
|
|
40
|
+
* Check if a new peer support the multicodecs for this topology
|
|
70
41
|
*/
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
declare namespace Registrar {
|
|
74
|
-
export { PeerId, PeerStore, ConnectionManager, Connection, HandlerProps };
|
|
42
|
+
_onProtocolChange(evt: CustomEvent<PeerProtocolsChangeData>): void;
|
|
75
43
|
}
|
|
76
|
-
import Topology = require("libp2p-interfaces/src/topology");
|
|
77
|
-
type Connection = import("libp2p-interfaces/src/connection/connection");
|
|
78
|
-
type PeerId = import('peer-id');
|
|
79
|
-
type PeerStore = import('./peer-store/types').PeerStore;
|
|
80
|
-
type ConnectionManager = import('./connection-manager');
|
|
81
|
-
type HandlerProps = import('./').HandlerProps;
|
|
82
44
|
//# sourceMappingURL=registrar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.
|
|
1
|
+
{"version":3,"file":"registrar.d.ts","sourceRoot":"","sources":["../../src/registrar.ts"],"names":[],"mappings":"AAGA,OAAO,EAAc,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAC5E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAA;AAC5E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAc/D;;GAEG;AACH,qBAAa,gBAAiB,YAAW,SAAS;IAChD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAA0D;IACrF,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA4B;IACrD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAY;gBAE1B,UAAU,EAAE,UAAU;IAcnC,YAAY;IAcZ,UAAU,CAAE,QAAQ,EAAE,MAAM;IAU5B,aAAa,CAAE,QAAQ,EAAE,MAAM;IAY/B;;OAEG;IACG,MAAM,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAelF;;;OAGG;IACG,QAAQ,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE;IAW5C;;OAEG;IACG,QAAQ,CAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBlF;;OAEG;IACH,UAAU,CAAE,EAAE,EAAE,MAAM;IAItB;;OAEG;IACH,aAAa,CAAE,GAAG,EAAE,WAAW,CAAC,UAAU,CAAC;IAgB3C,UAAU,CAAE,GAAG,EAAE,WAAW,CAAC,UAAU,CAAC;IAgBxC;;OAEG;IACH,iBAAiB,CAAE,GAAG,EAAE,WAAW,CAAC,uBAAuB,CAAC;CAwB7D"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { logger } from '@libp2p/logger';
|
|
2
|
+
import errCode from 'err-code';
|
|
3
|
+
import { codes } from './errors.js';
|
|
4
|
+
import { isTopology } from '@libp2p/interfaces/topology';
|
|
5
|
+
const log = logger('libp2p:registrar');
|
|
6
|
+
function supportsProtocol(peerProtocols, topologyProtocols) {
|
|
7
|
+
for (const peerProtocol of peerProtocols) {
|
|
8
|
+
if (topologyProtocols.includes(peerProtocol)) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Responsible for notifying registered protocols of events in the network.
|
|
16
|
+
*/
|
|
17
|
+
export class DefaultRegistrar {
|
|
18
|
+
constructor(components) {
|
|
19
|
+
this.topologies = new Map();
|
|
20
|
+
this.handlers = new Map();
|
|
21
|
+
this.components = components;
|
|
22
|
+
this._onDisconnect = this._onDisconnect.bind(this);
|
|
23
|
+
this._onConnect = this._onConnect.bind(this);
|
|
24
|
+
this._onProtocolChange = this._onProtocolChange.bind(this);
|
|
25
|
+
this.components.getConnectionManager().addEventListener('peer:disconnect', this._onDisconnect);
|
|
26
|
+
this.components.getConnectionManager().addEventListener('peer:connect', this._onConnect);
|
|
27
|
+
this.components.getPeerStore().addEventListener('change:protocols', this._onProtocolChange);
|
|
28
|
+
}
|
|
29
|
+
getProtocols() {
|
|
30
|
+
const protocols = new Set();
|
|
31
|
+
for (const topology of this.topologies.values()) {
|
|
32
|
+
topology.protocols.forEach(protocol => protocols.add(protocol));
|
|
33
|
+
}
|
|
34
|
+
for (const protocol of this.handlers.keys()) {
|
|
35
|
+
protocols.add(protocol);
|
|
36
|
+
}
|
|
37
|
+
return Array.from(protocols).sort();
|
|
38
|
+
}
|
|
39
|
+
getHandler(protocol) {
|
|
40
|
+
const handler = this.handlers.get(protocol);
|
|
41
|
+
if (handler == null) {
|
|
42
|
+
throw new Error(`No handler registered for protocol ${protocol}`);
|
|
43
|
+
}
|
|
44
|
+
return handler;
|
|
45
|
+
}
|
|
46
|
+
getTopologies(protocol) {
|
|
47
|
+
const output = [];
|
|
48
|
+
for (const { topology, protocols } of this.topologies.values()) {
|
|
49
|
+
if (protocols.includes(protocol)) {
|
|
50
|
+
output.push(topology);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return output;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Registers the `handler` for each protocol
|
|
57
|
+
*/
|
|
58
|
+
async handle(protocols, handler) {
|
|
59
|
+
const protocolList = Array.isArray(protocols) ? protocols : [protocols];
|
|
60
|
+
for (const protocol of protocolList) {
|
|
61
|
+
if (this.handlers.has(protocol)) {
|
|
62
|
+
throw errCode(new Error(`Handler already registered for protocol ${protocol}`), codes.ERR_PROTOCOL_HANDLER_ALREADY_REGISTERED);
|
|
63
|
+
}
|
|
64
|
+
this.handlers.set(protocol, handler);
|
|
65
|
+
}
|
|
66
|
+
// Add new protocols to self protocols in the Protobook
|
|
67
|
+
await this.components.getPeerStore().protoBook.add(this.components.getPeerId(), protocolList);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Removes the handler for each protocol. The protocol
|
|
71
|
+
* will no longer be supported on streams.
|
|
72
|
+
*/
|
|
73
|
+
async unhandle(protocols) {
|
|
74
|
+
const protocolList = Array.isArray(protocols) ? protocols : [protocols];
|
|
75
|
+
protocolList.forEach(protocol => {
|
|
76
|
+
this.handlers.delete(protocol);
|
|
77
|
+
});
|
|
78
|
+
// Remove protocols from self protocols in the Protobook
|
|
79
|
+
await this.components.getPeerStore().protoBook.remove(this.components.getPeerId(), protocolList);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Register handlers for a set of multicodecs given
|
|
83
|
+
*/
|
|
84
|
+
async register(protocols, topology) {
|
|
85
|
+
if (!isTopology(topology)) {
|
|
86
|
+
log.error('topology must be an instance of interfaces/topology');
|
|
87
|
+
throw errCode(new Error('topology must be an instance of interfaces/topology'), codes.ERR_INVALID_PARAMETERS);
|
|
88
|
+
}
|
|
89
|
+
// Create topology
|
|
90
|
+
const id = `${(Math.random() * 1e9).toString(36)}${Date.now()}`;
|
|
91
|
+
this.topologies.set(id, {
|
|
92
|
+
topology,
|
|
93
|
+
protocols: Array.isArray(protocols) ? protocols : [protocols]
|
|
94
|
+
});
|
|
95
|
+
// Set registrar
|
|
96
|
+
await topology.setRegistrar(this);
|
|
97
|
+
return id;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Unregister topology
|
|
101
|
+
*/
|
|
102
|
+
unregister(id) {
|
|
103
|
+
this.topologies.delete(id);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Remove a disconnected peer from the record
|
|
107
|
+
*/
|
|
108
|
+
_onDisconnect(evt) {
|
|
109
|
+
const connection = evt.detail;
|
|
110
|
+
void this.components.getPeerStore().protoBook.get(connection.remotePeer)
|
|
111
|
+
.then(peerProtocols => {
|
|
112
|
+
for (const { topology, protocols } of this.topologies.values()) {
|
|
113
|
+
if (supportsProtocol(peerProtocols, protocols)) {
|
|
114
|
+
topology.onDisconnect(connection.remotePeer);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
.catch(err => {
|
|
119
|
+
log.error(err);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
_onConnect(evt) {
|
|
123
|
+
const connection = evt.detail;
|
|
124
|
+
void this.components.getPeerStore().protoBook.get(connection.remotePeer)
|
|
125
|
+
.then(peerProtocols => {
|
|
126
|
+
for (const { topology, protocols } of this.topologies.values()) {
|
|
127
|
+
if (supportsProtocol(peerProtocols, protocols)) {
|
|
128
|
+
topology.onConnect(connection.remotePeer, connection);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
.catch(err => {
|
|
133
|
+
log.error(err);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Check if a new peer support the multicodecs for this topology
|
|
138
|
+
*/
|
|
139
|
+
_onProtocolChange(evt) {
|
|
140
|
+
const { peerId, protocols, oldProtocols } = evt.detail;
|
|
141
|
+
const removed = oldProtocols.filter(protocol => !protocols.includes(protocol));
|
|
142
|
+
const added = protocols.filter(protocol => !oldProtocols.includes(protocol));
|
|
143
|
+
for (const { topology, protocols } of this.topologies.values()) {
|
|
144
|
+
if (supportsProtocol(removed, protocols)) {
|
|
145
|
+
topology.onDisconnect(peerId);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
for (const { topology, protocols } of this.topologies.values()) {
|
|
149
|
+
if (supportsProtocol(added, protocols)) {
|
|
150
|
+
const connection = this.components.getConnectionManager().getConnection(peerId);
|
|
151
|
+
if (connection == null) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
topology.onConnect(peerId, connection);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=registrar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registrar.js","sourceRoot":"","sources":["../../src/registrar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,OAAO,MAAM,UAAU,CAAA;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACnC,OAAO,EAAE,UAAU,EAAY,MAAM,6BAA6B,CAAA;AAMlE,MAAM,GAAG,GAAG,MAAM,CAAC,kBAAkB,CAAC,CAAA;AAEtC,SAAS,gBAAgB,CAAE,aAAuB,EAAE,iBAA2B;IAC7E,KAAK,MAAM,YAAY,IAAI,aAAa,EAAE;QACxC,IAAI,iBAAiB,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE;YAC5C,OAAO,IAAI,CAAA;SACZ;KACF;IAED,OAAO,KAAK,CAAA;AACd,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,gBAAgB;IAK3B,YAAa,UAAsB;QACjC,IAAI,CAAC,UAAU,GAAG,IAAI,GAAG,EAAE,CAAA;QAC3B,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAE5B,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAClD,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAC5C,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAE1D,IAAI,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,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IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE;YAC9D,IAAI,gBAAgB,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE;gBACxC,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,CAAA;aAC9B;SACF;QAED,KAAK,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE,EAAE;YAC9D,IAAI,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,EAAE;gBACtC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,oBAAoB,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;gBAE/E,IAAI,UAAU,IAAI,IAAI,EAAE;oBACtB,SAAQ;iBACT;gBAED,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;aACvC;SACF;IACH,CAAC;CACF"}
|
|
@@ -1,85 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @class
|
|
18
|
-
* @param {TransportManagerProperties & TransportManagerOptions} options
|
|
19
|
-
*/
|
|
20
|
-
constructor({ libp2p, upgrader, faultTolerance }: TransportManagerProperties & TransportManagerOptions);
|
|
21
|
-
libp2p: import("./");
|
|
22
|
-
upgrader: import("./upgrader");
|
|
23
|
-
/** @type {Map<string, Transport>} */
|
|
24
|
-
_transports: Map<string, import("libp2p-interfaces/src/transport/types").Transport<any, any>>;
|
|
25
|
-
_listeners: Map<any, any>;
|
|
26
|
-
_listenerOptions: Map<any, any>;
|
|
27
|
-
faultTolerance: number;
|
|
1
|
+
import type { Transport, TransportManager, TransportManagerEvents } from '@libp2p/interfaces/transport';
|
|
2
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
3
|
+
import type { Connection } from '@libp2p/interfaces/connection';
|
|
4
|
+
import { AbortOptions, EventEmitter, Startable } from '@libp2p/interfaces';
|
|
5
|
+
import type { Components } from '@libp2p/interfaces/components';
|
|
6
|
+
export interface TransportManagerInit {
|
|
7
|
+
faultTolerance?: FaultTolerance;
|
|
8
|
+
}
|
|
9
|
+
export declare class DefaultTransportManager extends EventEmitter<TransportManagerEvents> implements TransportManager, Startable {
|
|
10
|
+
private readonly components;
|
|
11
|
+
private readonly transports;
|
|
12
|
+
private readonly listeners;
|
|
13
|
+
private readonly faultTolerance;
|
|
14
|
+
private started;
|
|
15
|
+
constructor(components: Components, init?: TransportManagerInit);
|
|
28
16
|
/**
|
|
29
17
|
* Adds a `Transport` to the manager
|
|
30
|
-
*
|
|
31
|
-
* @param {string} key
|
|
32
|
-
* @param {TransportFactory} Transport
|
|
33
|
-
* @param {*} transportOptions - Additional options to pass to the transport
|
|
34
|
-
* @returns {void}
|
|
35
18
|
*/
|
|
36
|
-
add(
|
|
19
|
+
add(transport: Transport): void;
|
|
20
|
+
isStarted(): boolean;
|
|
21
|
+
start(): Promise<void>;
|
|
37
22
|
/**
|
|
38
23
|
* Stops all listeners
|
|
39
|
-
*
|
|
40
|
-
* @async
|
|
41
24
|
*/
|
|
42
|
-
|
|
25
|
+
stop(): Promise<void>;
|
|
43
26
|
/**
|
|
44
27
|
* Dials the given Multiaddr over it's supported transport
|
|
45
|
-
*
|
|
46
|
-
* @param {Multiaddr} ma
|
|
47
|
-
* @param {*} options
|
|
48
|
-
* @returns {Promise<Connection>}
|
|
49
28
|
*/
|
|
50
|
-
dial(ma: Multiaddr, options
|
|
29
|
+
dial(ma: Multiaddr, options?: AbortOptions): Promise<Connection>;
|
|
51
30
|
/**
|
|
52
31
|
* Returns all Multiaddr's the listeners are using
|
|
53
|
-
*
|
|
54
|
-
* @returns {Multiaddr[]}
|
|
55
32
|
*/
|
|
56
33
|
getAddrs(): Multiaddr[];
|
|
57
34
|
/**
|
|
58
|
-
* Returns all the transports instances
|
|
59
|
-
*
|
|
60
|
-
* @returns {IterableIterator<Transport>}
|
|
35
|
+
* Returns all the transports instances
|
|
61
36
|
*/
|
|
62
|
-
getTransports():
|
|
37
|
+
getTransports(): Transport[];
|
|
63
38
|
/**
|
|
64
39
|
* Finds a transport that matches the given Multiaddr
|
|
65
|
-
*
|
|
66
|
-
* @param {Multiaddr} ma
|
|
67
|
-
* @returns {Transport|null}
|
|
68
40
|
*/
|
|
69
|
-
transportForMultiaddr(ma: Multiaddr):
|
|
41
|
+
transportForMultiaddr(ma: Multiaddr): Transport | undefined;
|
|
70
42
|
/**
|
|
71
|
-
* Starts listeners for each listen Multiaddr
|
|
72
|
-
*
|
|
73
|
-
* @async
|
|
74
|
-
* @param {Multiaddr[]} addrs - addresses to attempt to listen on
|
|
43
|
+
* Starts listeners for each listen Multiaddr
|
|
75
44
|
*/
|
|
76
45
|
listen(addrs: Multiaddr[]): Promise<void>;
|
|
77
46
|
/**
|
|
78
47
|
* Removes the given transport from the manager.
|
|
79
48
|
* If a transport has any running listeners, they will be closed.
|
|
80
|
-
*
|
|
81
|
-
* @async
|
|
82
|
-
* @param {string} key
|
|
83
49
|
*/
|
|
84
50
|
remove(key: string): Promise<void>;
|
|
85
51
|
/**
|
|
@@ -90,31 +56,17 @@ declare class TransportManager {
|
|
|
90
56
|
*/
|
|
91
57
|
removeAll(): Promise<void>;
|
|
92
58
|
}
|
|
93
|
-
declare namespace TransportManager {
|
|
94
|
-
export { FAULT_TOLERANCE as FaultTolerance, Multiaddr, Connection, TransportFactory, Transport, TransportManagerProperties, TransportManagerOptions };
|
|
95
|
-
}
|
|
96
|
-
type Multiaddr = import('multiaddr').Multiaddr;
|
|
97
|
-
type Connection = import("libp2p-interfaces/src/connection/connection");
|
|
98
|
-
type TransportManagerProperties = {
|
|
99
|
-
libp2p: import('./');
|
|
100
|
-
upgrader: import('./upgrader');
|
|
101
|
-
};
|
|
102
|
-
type TransportManagerOptions = {
|
|
103
|
-
/**
|
|
104
|
-
* - Address listen error tolerance.
|
|
105
|
-
*/
|
|
106
|
-
faultTolerance?: number | undefined;
|
|
107
|
-
};
|
|
108
59
|
/**
|
|
109
|
-
* Enum Transport Manager Fault Tolerance values
|
|
110
|
-
* FATAL_ALL should be used for failing in any listen circumstance.
|
|
111
|
-
* NO_FATAL should be used for not failing when not listening.
|
|
60
|
+
* Enum Transport Manager Fault Tolerance values
|
|
112
61
|
*/
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
62
|
+
export declare enum FaultTolerance {
|
|
63
|
+
/**
|
|
64
|
+
* should be used for failing in any listen circumstance
|
|
65
|
+
*/
|
|
66
|
+
FATAL_ALL = 0,
|
|
67
|
+
/**
|
|
68
|
+
* should be used for not failing when not listening
|
|
69
|
+
*/
|
|
70
|
+
NO_FATAL = 1
|
|
117
71
|
}
|
|
118
|
-
type TransportFactory = import('libp2p-interfaces/src/transport/types').TransportFactory<any, any>;
|
|
119
|
-
type Transport = import('libp2p-interfaces/src/transport/types').Transport<any, any>;
|
|
120
72
|
//# sourceMappingURL=transport-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport-manager.d.ts","sourceRoot":"","sources":["../../src/transport-manager.
|
|
1
|
+
{"version":3,"file":"transport-manager.d.ts","sourceRoot":"","sources":["../../src/transport-manager.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAY,SAAS,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAA;AACjH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAAE,YAAY,EAAe,YAAY,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACvF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CA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