libp2p 0.36.1-902f10d → 0.36.2-64bfcee
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 +159 -493
- 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 +78 -0
- package/dist/src/libp2p.d.ts.map +1 -0
- package/dist/src/libp2p.js +372 -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 +17 -31
- 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 +148 -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 +236 -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 +509 -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 -374
- package/src/connection-manager/latency-monitor.js +0 -264
- package/src/constants.js +0 -18
- package/src/content-routing/index.js +0 -163
- package/src/content-routing/utils.js +0 -89
- package/src/dht/dht-content-routing.js +0 -44
- package/src/dht/dht-peer-routing.js +0 -51
- package/src/dialer/index.js +0 -376
- package/src/errors.js +0 -66
- package/src/fetch/constants.js +0 -6
- package/src/get-peer.js +0 -49
- package/src/identify/consts.js +0 -15
- package/src/identify/index.js +0 -384
- package/src/index.js +0 -813
- 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 -84
- package/src/ping/util.js +0 -18
- package/src/pnet/crypto.js +0 -84
- package/src/pnet/errors.js +0 -7
- package/src/pnet/index.js +0 -86
- package/src/pnet/key-generator.js +0 -33
- package/src/pubsub-adapter.js +0 -61
- package/src/record/README.md +0 -130
- package/src/record/envelope/envelope.d.ts +0 -77
- package/src/record/envelope/envelope.js +0 -243
- package/src/record/envelope/envelope.proto +0 -19
- package/src/record/envelope/index.js +0 -183
- package/src/record/peer-record/consts.js +0 -14
- package/src/record/peer-record/index.js +0 -113
- package/src/record/peer-record/peer-record.d.ts +0 -133
- package/src/record/peer-record/peer-record.js +0 -367
- package/src/record/peer-record/peer-record.proto +0 -18
- package/src/record/utils.js +0 -25
- package/src/registrar.js +0 -127
- package/src/transport-manager.js +0 -269
- package/src/types.ts +0 -98
- package/src/upgrader.js +0 -492
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const debug = require('debug')
|
|
4
|
-
const log = Object.assign(debug('libp2p:circuit:stop'), {
|
|
5
|
-
error: debug('libp2p:circuit:stop:err')
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
const { CircuitRelay: CircuitPB } = require('../protocol')
|
|
9
|
-
const multicodec = require('../multicodec')
|
|
10
|
-
const StreamHandler = require('./stream-handler')
|
|
11
|
-
const { validateAddrs } = require('./utils')
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
15
|
-
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
|
|
16
|
-
* @typedef {import('../protocol').ICircuitRelay} ICircuitRelay
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Handles incoming STOP requests
|
|
21
|
-
*
|
|
22
|
-
* @private
|
|
23
|
-
* @param {Object} options
|
|
24
|
-
* @param {Connection} options.connection
|
|
25
|
-
* @param {ICircuitRelay} options.request - The CircuitRelay protobuf request (unencoded)
|
|
26
|
-
* @param {StreamHandler} options.streamHandler
|
|
27
|
-
* @returns {Promise<MuxedStream>|void} Resolves a duplex iterable
|
|
28
|
-
*/
|
|
29
|
-
module.exports.handleStop = function handleStop ({
|
|
30
|
-
connection,
|
|
31
|
-
request,
|
|
32
|
-
streamHandler
|
|
33
|
-
}) {
|
|
34
|
-
// Validate the STOP request has the required input
|
|
35
|
-
try {
|
|
36
|
-
validateAddrs(request, streamHandler)
|
|
37
|
-
} catch (/** @type {any} */ err) {
|
|
38
|
-
return log.error('invalid stop request via peer %s', connection.remotePeer.toB58String(), err)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// The request is valid
|
|
42
|
-
log('stop request is valid')
|
|
43
|
-
streamHandler.write({
|
|
44
|
-
type: CircuitPB.Type.STATUS,
|
|
45
|
-
code: CircuitPB.Status.SUCCESS
|
|
46
|
-
})
|
|
47
|
-
return streamHandler.rest()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Creates a STOP request
|
|
52
|
-
*
|
|
53
|
-
* @private
|
|
54
|
-
* @param {Object} options
|
|
55
|
-
* @param {Connection} options.connection
|
|
56
|
-
* @param {ICircuitRelay} options.request - The CircuitRelay protobuf request (unencoded)
|
|
57
|
-
* @returns {Promise<MuxedStream|void>} Resolves a duplex iterable
|
|
58
|
-
*/
|
|
59
|
-
module.exports.stop = async function stop ({
|
|
60
|
-
connection,
|
|
61
|
-
request
|
|
62
|
-
}) {
|
|
63
|
-
const { stream } = await connection.newStream([multicodec.relay])
|
|
64
|
-
log('starting stop request to %s', connection.remotePeer.toB58String())
|
|
65
|
-
const streamHandler = new StreamHandler({ stream })
|
|
66
|
-
|
|
67
|
-
streamHandler.write(request)
|
|
68
|
-
const response = await streamHandler.read()
|
|
69
|
-
|
|
70
|
-
if (!response) {
|
|
71
|
-
return streamHandler.close()
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (response.code === CircuitPB.Status.SUCCESS) {
|
|
75
|
-
log('stop request to %s was successful', connection.remotePeer.toB58String())
|
|
76
|
-
return streamHandler.rest()
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
log('stop request failed with code %d', response.code)
|
|
80
|
-
streamHandler.close()
|
|
81
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const debug = require('debug')
|
|
4
|
-
const log = Object.assign(debug('libp2p:circuit:stream-handler'), {
|
|
5
|
-
error: debug('libp2p:circuit:stream-handler:err')
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
const lp = require('it-length-prefixed')
|
|
9
|
-
// @ts-ignore it-handshake does not export types
|
|
10
|
-
const handshake = require('it-handshake')
|
|
11
|
-
const { CircuitRelay } = require('../protocol')
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
|
|
15
|
-
* @typedef {import('../protocol').ICircuitRelay} ICircuitRelay
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
class StreamHandler {
|
|
19
|
-
/**
|
|
20
|
-
* Create a stream handler for connection
|
|
21
|
-
*
|
|
22
|
-
* @class
|
|
23
|
-
* @param {object} options
|
|
24
|
-
* @param {MuxedStream} options.stream - A duplex iterable
|
|
25
|
-
* @param {number} [options.maxLength = 4096] - max bytes length of message
|
|
26
|
-
*/
|
|
27
|
-
constructor ({ stream, maxLength = 4096 }) {
|
|
28
|
-
this.stream = stream
|
|
29
|
-
|
|
30
|
-
this.shake = handshake(this.stream)
|
|
31
|
-
// @ts-ignore options are not optional
|
|
32
|
-
this.decoder = lp.decode.fromReader(this.shake.reader, { maxDataLength: maxLength })
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Read and decode message
|
|
37
|
-
*
|
|
38
|
-
* @async
|
|
39
|
-
*/
|
|
40
|
-
async read () {
|
|
41
|
-
const msg = await this.decoder.next()
|
|
42
|
-
if (msg.value) {
|
|
43
|
-
const value = CircuitRelay.decode(msg.value.slice())
|
|
44
|
-
log('read message type', value.type)
|
|
45
|
-
return value
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
log('read received no value, closing stream')
|
|
49
|
-
// End the stream, we didn't get data
|
|
50
|
-
this.close()
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Encode and write array of buffers
|
|
55
|
-
*
|
|
56
|
-
* @param {ICircuitRelay} msg - An unencoded CircuitRelay protobuf message
|
|
57
|
-
* @returns {void}
|
|
58
|
-
*/
|
|
59
|
-
write (msg) {
|
|
60
|
-
log('write message type %s', msg.type)
|
|
61
|
-
// @ts-ignore lp.encode expects type type 'Buffer | BufferList', not 'Uint8Array'
|
|
62
|
-
this.shake.write(lp.encode.single(CircuitRelay.encode(msg).finish()))
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Return the handshake rest stream and invalidate handler
|
|
67
|
-
*
|
|
68
|
-
* @returns {*} A duplex iterable
|
|
69
|
-
*/
|
|
70
|
-
rest () {
|
|
71
|
-
this.shake.rest()
|
|
72
|
-
return this.shake.stream
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* @param {ICircuitRelay} msg - An unencoded CircuitRelay protobuf message
|
|
77
|
-
*/
|
|
78
|
-
end (msg) {
|
|
79
|
-
this.write(msg)
|
|
80
|
-
this.close()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Close the stream
|
|
85
|
-
*
|
|
86
|
-
* @returns {void}
|
|
87
|
-
*/
|
|
88
|
-
close () {
|
|
89
|
-
log('closing the stream')
|
|
90
|
-
this.rest().sink([])
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
module.exports = StreamHandler
|
package/src/circuit/constants.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const minute = 60 * 1000
|
|
4
|
-
|
|
5
|
-
module.exports = {
|
|
6
|
-
ADVERTISE_BOOT_DELAY: 15 * minute, // Delay before HOP relay service is advertised on the network
|
|
7
|
-
ADVERTISE_TTL: 30 * minute, // Delay Between HOP relay service advertisements on the network
|
|
8
|
-
CIRCUIT_PROTO_CODE: 290, // Multicodec code
|
|
9
|
-
HOP_METADATA_KEY: 'hop_relay', // PeerStore metadaBook key for HOP relay service
|
|
10
|
-
HOP_METADATA_VALUE: 'true', // PeerStore metadaBook value for HOP relay service
|
|
11
|
-
RELAY_RENDEZVOUS_NS: '/libp2p/relay' // Relay HOP relay service namespace for discovery
|
|
12
|
-
}
|
package/src/circuit/index.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const debug = require('debug')
|
|
4
|
-
const log = Object.assign(debug('libp2p:relay'), {
|
|
5
|
-
error: debug('libp2p:relay:err')
|
|
6
|
-
})
|
|
7
|
-
const { codes } = require('./../errors')
|
|
8
|
-
const {
|
|
9
|
-
setDelayedInterval,
|
|
10
|
-
clearDelayedInterval
|
|
11
|
-
// @ts-ignore set-delayed-interval does not export types
|
|
12
|
-
} = require('set-delayed-interval')
|
|
13
|
-
|
|
14
|
-
const AutoRelay = require('./auto-relay')
|
|
15
|
-
const { namespaceToCid } = require('./utils')
|
|
16
|
-
const {
|
|
17
|
-
RELAY_RENDEZVOUS_NS
|
|
18
|
-
} = require('./constants')
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @typedef {import('../')} Libp2p
|
|
22
|
-
*
|
|
23
|
-
* @typedef {Object} RelayAdvertiseOptions
|
|
24
|
-
* @property {number} [bootDelay = ADVERTISE_BOOT_DELAY]
|
|
25
|
-
* @property {boolean} [enabled = true]
|
|
26
|
-
* @property {number} [ttl = ADVERTISE_TTL]
|
|
27
|
-
*
|
|
28
|
-
* @typedef {Object} HopOptions
|
|
29
|
-
* @property {boolean} [enabled = false]
|
|
30
|
-
* @property {boolean} [active = false]
|
|
31
|
-
*
|
|
32
|
-
* @typedef {Object} AutoRelayOptions
|
|
33
|
-
* @property {number} [maxListeners = 2] - maximum number of relays to listen.
|
|
34
|
-
* @property {boolean} [enabled = false]
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
class Relay {
|
|
38
|
-
/**
|
|
39
|
-
* Creates an instance of Relay.
|
|
40
|
-
*
|
|
41
|
-
* @class
|
|
42
|
-
* @param {Libp2p} libp2p
|
|
43
|
-
*/
|
|
44
|
-
constructor (libp2p) {
|
|
45
|
-
this._libp2p = libp2p
|
|
46
|
-
this._options = {
|
|
47
|
-
...libp2p._config.relay
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// Create autoRelay if enabled
|
|
51
|
-
this._autoRelay = this._options.autoRelay.enabled && new AutoRelay({ libp2p, ...this._options.autoRelay })
|
|
52
|
-
|
|
53
|
-
this._advertiseService = this._advertiseService.bind(this)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Start Relay service.
|
|
58
|
-
*
|
|
59
|
-
* @returns {void}
|
|
60
|
-
*/
|
|
61
|
-
start () {
|
|
62
|
-
// Advertise service if HOP enabled
|
|
63
|
-
const canHop = this._options.hop.enabled
|
|
64
|
-
|
|
65
|
-
if (canHop && this._options.advertise.enabled) {
|
|
66
|
-
this._timeout = setDelayedInterval(
|
|
67
|
-
this._advertiseService, this._options.advertise.ttl, this._options.advertise.bootDelay
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Stop Relay service.
|
|
74
|
-
*
|
|
75
|
-
* @returns {void}
|
|
76
|
-
*/
|
|
77
|
-
stop () {
|
|
78
|
-
clearDelayedInterval(this._timeout)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Advertise hop relay service in the network.
|
|
83
|
-
*
|
|
84
|
-
* @returns {Promise<void>}
|
|
85
|
-
*/
|
|
86
|
-
async _advertiseService () {
|
|
87
|
-
try {
|
|
88
|
-
const cid = await namespaceToCid(RELAY_RENDEZVOUS_NS)
|
|
89
|
-
await this._libp2p.contentRouting.provide(cid)
|
|
90
|
-
} catch (/** @type {any} */ err) {
|
|
91
|
-
if (err.code === codes.ERR_NO_ROUTERS_AVAILABLE) {
|
|
92
|
-
log.error('a content router, such as a DHT, must be provided in order to advertise the relay service', err)
|
|
93
|
-
// Stop the advertise
|
|
94
|
-
this.stop()
|
|
95
|
-
} else {
|
|
96
|
-
log.error(err)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
module.exports = Relay
|
package/src/circuit/transport.js
DELETED
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const debug = require('debug')
|
|
4
|
-
const log = Object.assign(debug('libp2p:circuit'), {
|
|
5
|
-
error: debug('libp2p:circuit:err')
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
const errCode = require('err-code')
|
|
9
|
-
const mafmt = require('mafmt')
|
|
10
|
-
const { Multiaddr } = require('multiaddr')
|
|
11
|
-
const PeerId = require('peer-id')
|
|
12
|
-
const { CircuitRelay: CircuitPB } = require('./protocol')
|
|
13
|
-
const { codes } = require('../errors')
|
|
14
|
-
|
|
15
|
-
const toConnection = require('libp2p-utils/src/stream-to-ma-conn')
|
|
16
|
-
|
|
17
|
-
const { relay: multicodec } = require('./multicodec')
|
|
18
|
-
const createListener = require('./listener')
|
|
19
|
-
const { handleCanHop, handleHop, hop } = require('./circuit/hop')
|
|
20
|
-
const { handleStop } = require('./circuit/stop')
|
|
21
|
-
const StreamHandler = require('./circuit/stream-handler')
|
|
22
|
-
|
|
23
|
-
const transportSymbol = Symbol.for('@libp2p/js-libp2p-circuit/circuit')
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
|
|
27
|
-
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
class Circuit {
|
|
31
|
-
/**
|
|
32
|
-
* Creates an instance of the Circuit Transport.
|
|
33
|
-
*
|
|
34
|
-
* @class
|
|
35
|
-
* @param {object} options
|
|
36
|
-
* @param {import('../')} options.libp2p
|
|
37
|
-
* @param {import('../upgrader')} options.upgrader
|
|
38
|
-
*/
|
|
39
|
-
constructor ({ libp2p, upgrader }) {
|
|
40
|
-
this._dialer = libp2p.dialer
|
|
41
|
-
this._registrar = libp2p.registrar
|
|
42
|
-
this._connectionManager = libp2p.connectionManager
|
|
43
|
-
this._upgrader = upgrader
|
|
44
|
-
this._options = libp2p._config.relay
|
|
45
|
-
this._libp2p = libp2p
|
|
46
|
-
this.peerId = libp2p.peerId
|
|
47
|
-
|
|
48
|
-
this._registrar.handle(multicodec, this._onProtocol.bind(this))
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @param {Object} props
|
|
53
|
-
* @param {Connection} props.connection
|
|
54
|
-
* @param {MuxedStream} props.stream
|
|
55
|
-
*/
|
|
56
|
-
async _onProtocol ({ connection, stream }) {
|
|
57
|
-
/** @type {import('./circuit/stream-handler')} */
|
|
58
|
-
const streamHandler = new StreamHandler({ stream })
|
|
59
|
-
const request = await streamHandler.read()
|
|
60
|
-
|
|
61
|
-
if (!request) {
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const circuit = this
|
|
66
|
-
let virtualConnection
|
|
67
|
-
|
|
68
|
-
switch (request.type) {
|
|
69
|
-
case CircuitPB.Type.CAN_HOP: {
|
|
70
|
-
log('received CAN_HOP request from %s', connection.remotePeer.toB58String())
|
|
71
|
-
await handleCanHop({ circuit, connection, streamHandler })
|
|
72
|
-
break
|
|
73
|
-
}
|
|
74
|
-
case CircuitPB.Type.HOP: {
|
|
75
|
-
log('received HOP request from %s', connection.remotePeer.toB58String())
|
|
76
|
-
virtualConnection = await handleHop({
|
|
77
|
-
connection,
|
|
78
|
-
request,
|
|
79
|
-
streamHandler,
|
|
80
|
-
circuit
|
|
81
|
-
})
|
|
82
|
-
break
|
|
83
|
-
}
|
|
84
|
-
case CircuitPB.Type.STOP: {
|
|
85
|
-
log('received STOP request from %s', connection.remotePeer.toB58String())
|
|
86
|
-
virtualConnection = await handleStop({
|
|
87
|
-
connection,
|
|
88
|
-
request,
|
|
89
|
-
streamHandler
|
|
90
|
-
})
|
|
91
|
-
break
|
|
92
|
-
}
|
|
93
|
-
default: {
|
|
94
|
-
log('Request of type %s not supported', request.type)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (virtualConnection) {
|
|
99
|
-
// @ts-ignore dst peer will not be undefined
|
|
100
|
-
const remoteAddr = new Multiaddr(request.dstPeer.addrs[0])
|
|
101
|
-
// @ts-ignore src peer will not be undefined
|
|
102
|
-
const localAddr = new Multiaddr(request.srcPeer.addrs[0])
|
|
103
|
-
const maConn = toConnection({
|
|
104
|
-
stream: virtualConnection,
|
|
105
|
-
remoteAddr,
|
|
106
|
-
localAddr
|
|
107
|
-
})
|
|
108
|
-
const type = request.type === CircuitPB.Type.HOP ? 'relay' : 'inbound'
|
|
109
|
-
log('new %s connection %s', type, maConn.remoteAddr)
|
|
110
|
-
|
|
111
|
-
const conn = await this._upgrader.upgradeInbound(maConn)
|
|
112
|
-
log('%s connection %s upgraded', type, maConn.remoteAddr)
|
|
113
|
-
this.handler && this.handler(conn)
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Dial a peer over a relay
|
|
119
|
-
*
|
|
120
|
-
* @param {Multiaddr} ma - the multiaddr of the peer to dial
|
|
121
|
-
* @param {Object} options - dial options
|
|
122
|
-
* @param {AbortSignal} [options.signal] - An optional abort signal
|
|
123
|
-
* @returns {Promise<Connection>} - the connection
|
|
124
|
-
*/
|
|
125
|
-
async dial (ma, options) {
|
|
126
|
-
// Check the multiaddr to see if it contains a relay and a destination peer
|
|
127
|
-
const addrs = ma.toString().split('/p2p-circuit')
|
|
128
|
-
const relayAddr = new Multiaddr(addrs[0])
|
|
129
|
-
const destinationAddr = new Multiaddr(addrs[addrs.length - 1])
|
|
130
|
-
const relayId = relayAddr.getPeerId()
|
|
131
|
-
const destinationId = destinationAddr.getPeerId()
|
|
132
|
-
|
|
133
|
-
if (!relayId || !destinationId) {
|
|
134
|
-
const errMsg = 'Circuit relay dial failed as addresses did not have peer id'
|
|
135
|
-
log.error(errMsg)
|
|
136
|
-
throw errCode(new Error(errMsg), codes.ERR_RELAYED_DIAL)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
const relayPeer = PeerId.createFromB58String(relayId)
|
|
140
|
-
const destinationPeer = PeerId.createFromB58String(destinationId)
|
|
141
|
-
|
|
142
|
-
let disconnectOnFailure = false
|
|
143
|
-
let relayConnection = this._connectionManager.get(relayPeer)
|
|
144
|
-
if (!relayConnection) {
|
|
145
|
-
relayConnection = await this._dialer.connectToPeer(relayAddr, options)
|
|
146
|
-
disconnectOnFailure = true
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
try {
|
|
150
|
-
const virtualConnection = await hop({
|
|
151
|
-
connection: relayConnection,
|
|
152
|
-
request: {
|
|
153
|
-
type: CircuitPB.Type.HOP,
|
|
154
|
-
srcPeer: {
|
|
155
|
-
id: this.peerId.toBytes(),
|
|
156
|
-
addrs: this._libp2p.multiaddrs.map(addr => addr.bytes)
|
|
157
|
-
},
|
|
158
|
-
dstPeer: {
|
|
159
|
-
id: destinationPeer.toBytes(),
|
|
160
|
-
addrs: [new Multiaddr(destinationAddr).bytes]
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
const localAddr = relayAddr.encapsulate(`/p2p-circuit/p2p/${this.peerId.toB58String()}`)
|
|
166
|
-
const maConn = toConnection({
|
|
167
|
-
stream: virtualConnection,
|
|
168
|
-
remoteAddr: ma,
|
|
169
|
-
localAddr
|
|
170
|
-
})
|
|
171
|
-
log('new outbound connection %s', maConn.remoteAddr)
|
|
172
|
-
|
|
173
|
-
return this._upgrader.upgradeOutbound(maConn)
|
|
174
|
-
} catch (/** @type {any} */ err) {
|
|
175
|
-
log.error('Circuit relay dial failed', err)
|
|
176
|
-
disconnectOnFailure && await relayConnection.close()
|
|
177
|
-
throw err
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Create a listener
|
|
183
|
-
*
|
|
184
|
-
* @param {any} options
|
|
185
|
-
* @param {Function} handler
|
|
186
|
-
* @returns {import('libp2p-interfaces/src/transport/types').Listener}
|
|
187
|
-
*/
|
|
188
|
-
createListener (options, handler) {
|
|
189
|
-
if (typeof options === 'function') {
|
|
190
|
-
handler = options
|
|
191
|
-
options = {}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
// Called on successful HOP and STOP requests
|
|
195
|
-
this.handler = handler
|
|
196
|
-
|
|
197
|
-
return createListener(this._libp2p)
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Filter check for all Multiaddrs that this transport can dial on
|
|
202
|
-
*
|
|
203
|
-
* @param {Multiaddr[]} multiaddrs
|
|
204
|
-
* @returns {Multiaddr[]}
|
|
205
|
-
*/
|
|
206
|
-
filter (multiaddrs) {
|
|
207
|
-
multiaddrs = Array.isArray(multiaddrs) ? multiaddrs : [multiaddrs]
|
|
208
|
-
|
|
209
|
-
return multiaddrs.filter((ma) => {
|
|
210
|
-
return mafmt.Circuit.matches(ma)
|
|
211
|
-
})
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
get [Symbol.toStringTag] () {
|
|
215
|
-
return 'Circuit'
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Checks if the given value is a Transport instance.
|
|
220
|
-
*
|
|
221
|
-
* @param {any} other
|
|
222
|
-
* @returns {other is Transport}
|
|
223
|
-
*/
|
|
224
|
-
static isTransport (other) {
|
|
225
|
-
return Boolean(other && other[transportSymbol])
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
module.exports = Circuit
|
package/src/circuit/utils.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { CID } = require('multiformats/cid')
|
|
4
|
-
const { sha256 } = require('multiformats/hashes/sha2')
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Convert a namespace string into a cid.
|
|
8
|
-
*
|
|
9
|
-
* @param {string} namespace
|
|
10
|
-
* @returns {Promise<CID>}
|
|
11
|
-
*/
|
|
12
|
-
module.exports.namespaceToCid = async (namespace) => {
|
|
13
|
-
const bytes = new TextEncoder().encode(namespace)
|
|
14
|
-
const hash = await sha256.digest(bytes)
|
|
15
|
-
|
|
16
|
-
return CID.createV0(hash)
|
|
17
|
-
}
|
package/src/config.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const mergeOptions = require('merge-options')
|
|
4
|
-
// @ts-ignore no types in multiaddr path
|
|
5
|
-
const { dnsaddrResolver } = require('multiaddr/src/resolvers')
|
|
6
|
-
|
|
7
|
-
const Constants = require('./constants')
|
|
8
|
-
const { AGENT_VERSION } = require('./identify/consts')
|
|
9
|
-
const RelayConstants = require('./circuit/constants')
|
|
10
|
-
|
|
11
|
-
const { publicAddressesFirst } = require('libp2p-utils/src/address-sort')
|
|
12
|
-
const { FaultTolerance } = require('./transport-manager')
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @typedef {import('multiaddr').Multiaddr} Multiaddr
|
|
16
|
-
* @typedef {import('./types').ConnectionGater} ConnectionGater
|
|
17
|
-
* @typedef {import('.').Libp2pOptions} Libp2pOptions
|
|
18
|
-
* @typedef {import('.').constructorOptions} constructorOptions
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
const DefaultConfig = {
|
|
22
|
-
addresses: {
|
|
23
|
-
listen: [],
|
|
24
|
-
announce: [],
|
|
25
|
-
noAnnounce: [],
|
|
26
|
-
announceFilter: (/** @type {Multiaddr[]} */ multiaddrs) => multiaddrs
|
|
27
|
-
},
|
|
28
|
-
connectionManager: {
|
|
29
|
-
minConnections: 25
|
|
30
|
-
},
|
|
31
|
-
connectionGater: /** @type {ConnectionGater} */ {},
|
|
32
|
-
transportManager: {
|
|
33
|
-
faultTolerance: FaultTolerance.FATAL_ALL
|
|
34
|
-
},
|
|
35
|
-
dialer: {
|
|
36
|
-
maxParallelDials: Constants.MAX_PARALLEL_DIALS,
|
|
37
|
-
maxDialsPerPeer: Constants.MAX_PER_PEER_DIALS,
|
|
38
|
-
dialTimeout: Constants.DIAL_TIMEOUT,
|
|
39
|
-
resolvers: {
|
|
40
|
-
dnsaddr: dnsaddrResolver
|
|
41
|
-
},
|
|
42
|
-
addressSorter: publicAddressesFirst
|
|
43
|
-
},
|
|
44
|
-
host: {
|
|
45
|
-
agentVersion: AGENT_VERSION
|
|
46
|
-
},
|
|
47
|
-
metrics: {
|
|
48
|
-
enabled: false
|
|
49
|
-
},
|
|
50
|
-
peerStore: {
|
|
51
|
-
persistence: false,
|
|
52
|
-
threshold: 5
|
|
53
|
-
},
|
|
54
|
-
peerRouting: {
|
|
55
|
-
refreshManager: {
|
|
56
|
-
enabled: true,
|
|
57
|
-
interval: 6e5,
|
|
58
|
-
bootDelay: 10e3
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
config: {
|
|
62
|
-
protocolPrefix: 'ipfs',
|
|
63
|
-
dht: {
|
|
64
|
-
enabled: false,
|
|
65
|
-
kBucketSize: 20
|
|
66
|
-
},
|
|
67
|
-
nat: {
|
|
68
|
-
enabled: true,
|
|
69
|
-
ttl: 7200,
|
|
70
|
-
keepAlive: true,
|
|
71
|
-
gateway: null,
|
|
72
|
-
externalIp: null,
|
|
73
|
-
pmp: {
|
|
74
|
-
enabled: false
|
|
75
|
-
}
|
|
76
|
-
},
|
|
77
|
-
peerDiscovery: {
|
|
78
|
-
autoDial: true
|
|
79
|
-
},
|
|
80
|
-
pubsub: {
|
|
81
|
-
enabled: true
|
|
82
|
-
},
|
|
83
|
-
relay: {
|
|
84
|
-
enabled: true,
|
|
85
|
-
advertise: {
|
|
86
|
-
bootDelay: RelayConstants.ADVERTISE_BOOT_DELAY,
|
|
87
|
-
enabled: false,
|
|
88
|
-
ttl: RelayConstants.ADVERTISE_TTL
|
|
89
|
-
},
|
|
90
|
-
hop: {
|
|
91
|
-
enabled: false,
|
|
92
|
-
active: false
|
|
93
|
-
},
|
|
94
|
-
autoRelay: {
|
|
95
|
-
enabled: false,
|
|
96
|
-
maxListeners: 2
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
transport: {}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* @param {Libp2pOptions} opts
|
|
105
|
-
* @returns {DefaultConfig & Libp2pOptions & constructorOptions}
|
|
106
|
-
*/
|
|
107
|
-
module.exports.validate = (opts) => {
|
|
108
|
-
/** @type {DefaultConfig & Libp2pOptions & constructorOptions} */
|
|
109
|
-
const resultingOptions = mergeOptions(DefaultConfig, opts)
|
|
110
|
-
|
|
111
|
-
if (resultingOptions.modules.transport.length < 1) throw new Error("'options.modules.transport' must contain at least 1 transport")
|
|
112
|
-
|
|
113
|
-
return resultingOptions
|
|
114
|
-
}
|