libp2p 0.36.2 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -21
- package/README.md +13 -10
- package/dist/src/address-manager/index.d.ts +34 -52
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +81 -0
- package/dist/src/address-manager/index.js.map +1 -0
- package/dist/src/circuit/auto-relay.d.ts +24 -85
- package/dist/src/circuit/auto-relay.d.ts.map +1 -1
- package/dist/src/circuit/auto-relay.js +216 -0
- package/dist/src/circuit/auto-relay.js.map +1 -0
- package/dist/src/circuit/circuit/hop.d.ts +26 -53
- package/dist/src/circuit/circuit/hop.d.ts.map +1 -1
- package/dist/src/circuit/circuit/hop.js +138 -0
- package/dist/src/circuit/circuit/hop.js.map +1 -0
- package/dist/src/circuit/circuit/stop.d.ts +18 -10
- package/dist/src/circuit/circuit/stop.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stop.js +49 -0
- package/dist/src/circuit/circuit/stop.js.map +1 -0
- package/dist/src/circuit/circuit/stream-handler.d.ts +19 -38
- package/dist/src/circuit/circuit/stream-handler.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stream-handler.js +59 -0
- package/dist/src/circuit/circuit/stream-handler.js.map +1 -0
- package/dist/src/circuit/circuit/utils.d.ts +3 -6
- package/dist/src/circuit/circuit/utils.d.ts.map +1 -1
- package/dist/src/circuit/circuit/utils.js +43 -0
- package/dist/src/circuit/circuit/utils.js.map +1 -0
- package/dist/src/circuit/constants.d.ts +24 -6
- package/dist/src/circuit/constants.d.ts.map +1 -1
- package/dist/src/circuit/constants.js +26 -0
- package/dist/src/circuit/constants.js.map +1 -0
- package/dist/src/circuit/index.d.ts +41 -74
- package/dist/src/circuit/index.d.ts.map +1 -1
- package/dist/src/circuit/index.js +69 -0
- package/dist/src/circuit/index.js.map +1 -0
- package/dist/src/circuit/listener.d.ts +8 -3
- package/dist/src/circuit/listener.d.ts.map +1 -1
- package/dist/src/circuit/listener.js +62 -0
- package/dist/src/circuit/listener.js.map +1 -0
- package/dist/src/circuit/multicodec.d.ts +1 -1
- package/dist/src/circuit/multicodec.d.ts.map +1 -1
- package/dist/src/circuit/multicodec.js +2 -0
- package/dist/src/circuit/multicodec.js.map +1 -0
- package/dist/src/circuit/pb/index.d.ts +52 -0
- package/dist/src/circuit/pb/index.d.ts.map +1 -0
- package/dist/src/circuit/pb/index.js +98 -0
- package/dist/src/circuit/pb/index.js.map +1 -0
- package/dist/src/circuit/transport.d.ts +18 -78
- package/dist/src/circuit/transport.d.ts.map +1 -1
- package/dist/src/circuit/transport.js +192 -0
- package/dist/src/circuit/transport.js.map +1 -0
- package/dist/src/circuit/utils.d.ts +5 -2
- package/dist/src/circuit/utils.d.ts.map +1 -1
- package/dist/src/circuit/utils.js +11 -0
- package/dist/src/circuit/utils.js.map +1 -0
- package/dist/src/config.d.ts +3 -85
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +91 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/connection-manager/auto-dialler.d.ts +24 -41
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dialler.js +105 -0
- package/dist/src/connection-manager/auto-dialler.js.map +1 -0
- package/dist/src/connection-manager/dialer/auto-dialer.d.ts +16 -0
- package/dist/src/connection-manager/dialer/auto-dialer.d.ts.map +1 -0
- package/dist/src/connection-manager/dialer/auto-dialer.js +37 -0
- package/dist/src/connection-manager/dialer/auto-dialer.js.map +1 -0
- package/dist/src/connection-manager/dialer/dial-request.d.ts +27 -0
- package/dist/src/connection-manager/dialer/dial-request.d.ts.map +1 -0
- package/dist/src/connection-manager/dialer/dial-request.js +83 -0
- package/dist/src/connection-manager/dialer/dial-request.js.map +1 -0
- package/dist/src/connection-manager/dialer/index.d.ts +104 -0
- package/dist/src/connection-manager/dialer/index.d.ts.map +1 -0
- package/dist/src/connection-manager/dialer/index.js +267 -0
- package/dist/src/connection-manager/dialer/index.js.map +1 -0
- package/dist/src/connection-manager/index.d.ts +102 -136
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +333 -0
- package/dist/src/connection-manager/index.js.map +1 -0
- package/dist/src/connection-manager/latency-monitor.d.ts +72 -97
- package/dist/src/connection-manager/latency-monitor.d.ts.map +1 -1
- package/dist/src/connection-manager/latency-monitor.js +220 -0
- package/dist/src/connection-manager/latency-monitor.js.map +1 -0
- package/dist/src/connection-manager/visibility-change-emitter.d.ts +15 -16
- package/dist/src/connection-manager/visibility-change-emitter.d.ts.map +1 -1
- package/dist/src/connection-manager/visibility-change-emitter.js +118 -0
- package/dist/src/connection-manager/visibility-change-emitter.js.map +1 -0
- package/dist/src/constants.d.ts +22 -10
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +27 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/content-routing/index.d.ts +27 -81
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +99 -0
- package/dist/src/content-routing/index.js.map +1 -0
- package/dist/src/content-routing/utils.d.ts +6 -49
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/content-routing/utils.js +42 -0
- package/dist/src/content-routing/utils.js.map +1 -0
- package/dist/src/dht/dht-content-routing.d.ts +10 -24
- package/dist/src/dht/dht-content-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-content-routing.js +32 -0
- package/dist/src/dht/dht-content-routing.js.map +1 -0
- package/dist/src/dht/dht-peer-routing.d.ts +9 -24
- package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-peer-routing.js +26 -0
- package/dist/src/dht/dht-peer-routing.js.map +1 -0
- package/dist/src/dht/dummy-dht.d.ts +20 -0
- package/dist/src/dht/dummy-dht.d.ts.map +1 -0
- package/dist/src/dht/dummy-dht.js +46 -0
- package/dist/src/dht/dummy-dht.js.map +1 -0
- package/dist/src/errors.d.ts +70 -63
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +75 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/fetch/constants.d.ts +1 -1
- package/dist/src/fetch/constants.d.ts.map +1 -1
- package/dist/src/fetch/constants.js +3 -0
- package/dist/src/fetch/constants.js.map +1 -0
- package/dist/src/fetch/index.d.ts +30 -49
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +129 -0
- package/dist/src/fetch/index.js.map +1 -0
- package/dist/src/fetch/pb/proto.d.ts +27 -0
- package/dist/src/fetch/pb/proto.d.ts.map +1 -0
- package/dist/src/fetch/pb/proto.js +50 -0
- package/dist/src/fetch/pb/proto.js.map +1 -0
- package/dist/src/get-peer.d.ts +4 -11
- package/dist/src/get-peer.d.ts.map +1 -1
- package/dist/src/get-peer.js +43 -0
- package/dist/src/get-peer.js.map +1 -0
- package/dist/src/identify/consts.d.ts +9 -9
- package/dist/src/identify/consts.d.ts.map +1 -1
- package/dist/src/identify/consts.js +11 -0
- package/dist/src/identify/consts.js.map +1 -0
- package/dist/src/identify/index.d.ts +42 -96
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +322 -0
- package/dist/src/identify/index.js.map +1 -0
- package/dist/src/identify/pb/message.d.ts +16 -0
- package/dist/src/identify/pb/message.d.ts.map +1 -0
- package/dist/src/identify/pb/message.js +24 -0
- package/dist/src/identify/pb/message.js.map +1 -0
- package/dist/src/index.d.ts +150 -496
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/insecure/index.d.ts +9 -0
- package/dist/src/insecure/index.d.ts.map +1 -0
- package/dist/src/insecure/index.js +81 -0
- package/dist/src/insecure/index.js.map +1 -0
- package/dist/src/insecure/pb/proto.d.ts +29 -0
- package/dist/src/insecure/pb/proto.d.ts.map +1 -0
- package/dist/src/insecure/pb/proto.js +53 -0
- package/dist/src/insecure/pb/proto.js.map +1 -0
- package/dist/src/keychain/cms.d.ts +6 -14
- package/dist/src/keychain/cms.d.ts.map +1 -1
- package/dist/src/keychain/cms.js +129 -0
- package/dist/src/keychain/cms.js.map +1 -0
- package/dist/src/keychain/index.d.ts +60 -81
- package/dist/src/keychain/index.d.ts.map +1 -1
- package/dist/src/keychain/index.js +492 -0
- package/dist/src/keychain/index.js.map +1 -0
- package/dist/src/keychain/util.d.ts +3 -6
- package/dist/src/keychain/util.d.ts.map +1 -1
- package/dist/src/keychain/util.js +79 -0
- package/dist/src/keychain/util.js.map +1 -0
- package/dist/src/libp2p.d.ts +80 -0
- package/dist/src/libp2p.d.ts.map +1 -0
- package/dist/src/libp2p.js +397 -0
- package/dist/src/libp2p.js.map +1 -0
- package/dist/src/metrics/index.d.ts +47 -104
- package/dist/src/metrics/index.d.ts.map +1 -1
- package/dist/src/metrics/index.js +231 -0
- package/dist/src/metrics/index.js.map +1 -0
- package/dist/src/metrics/moving-average.d.ts +14 -0
- package/dist/src/metrics/moving-average.d.ts.map +1 -0
- package/dist/src/metrics/moving-average.js +40 -0
- package/dist/src/metrics/moving-average.js.map +1 -0
- package/dist/src/metrics/stats.d.ts +41 -93
- package/dist/src/metrics/stats.d.ts.map +1 -1
- package/dist/src/metrics/stats.js +183 -0
- package/dist/src/metrics/stats.js.map +1 -0
- package/dist/src/nat-manager.d.ts +42 -99
- package/dist/src/nat-manager.d.ts.map +1 -1
- package/dist/src/nat-manager.js +114 -0
- package/dist/src/nat-manager.js.map +1 -0
- package/dist/src/peer-record-updater.d.ts +15 -0
- package/dist/src/peer-record-updater.d.ts.map +1 -0
- package/dist/src/peer-record-updater.js +44 -0
- package/dist/src/peer-record-updater.js.map +1 -0
- package/dist/src/peer-routing.d.ts +40 -84
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +108 -0
- package/dist/src/peer-routing.js.map +1 -0
- package/dist/src/ping/constants.d.ts +4 -4
- package/dist/src/ping/constants.d.ts.map +1 -1
- package/dist/src/ping/constants.js +5 -0
- package/dist/src/ping/constants.js.map +1 -0
- package/dist/src/ping/index.d.ts +17 -31
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +57 -0
- package/dist/src/ping/index.js.map +1 -0
- package/dist/src/pnet/crypto.d.ts +15 -5
- package/dist/src/pnet/crypto.d.ts.map +1 -1
- package/dist/src/pnet/crypto.js +60 -0
- package/dist/src/pnet/crypto.js.map +1 -0
- package/dist/src/pnet/errors.d.ts +5 -5
- package/dist/src/pnet/errors.d.ts.map +1 -1
- package/dist/src/pnet/errors.js +6 -0
- package/dist/src/pnet/errors.js.map +1 -0
- package/dist/src/pnet/index.d.ts +12 -20
- package/dist/src/pnet/index.d.ts.map +1 -1
- package/dist/src/pnet/index.js +67 -0
- package/dist/src/pnet/index.js.map +1 -0
- package/dist/src/pnet/key-generator.d.ts +3 -7
- package/dist/src/pnet/key-generator.d.ts.map +1 -1
- package/dist/src/pnet/key-generator.js +25 -0
- package/dist/src/pnet/key-generator.js.map +1 -0
- package/dist/src/pubsub/dummy-pubsub.d.ts +17 -0
- package/dist/src/pubsub/dummy-pubsub.d.ts.map +1 -0
- package/dist/src/pubsub/dummy-pubsub.js +37 -0
- package/dist/src/pubsub/dummy-pubsub.js.map +1 -0
- package/dist/src/registrar.d.ts +26 -65
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +144 -0
- package/dist/src/registrar.js.map +1 -0
- package/dist/src/transport-manager.d.ts +36 -82
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +223 -0
- package/dist/src/transport-manager.js.map +1 -0
- package/dist/src/upgrader.d.ts +49 -129
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +402 -0
- package/dist/src/upgrader.js.map +1 -0
- package/dist/src/version.d.ts +3 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/src/version.js +3 -0
- package/dist/src/version.js.map +1 -0
- package/package.json +144 -201
- package/src/address-manager/index.ts +130 -0
- package/src/circuit/README.md +16 -11
- package/src/circuit/auto-relay.ts +286 -0
- package/src/circuit/circuit/hop.ts +211 -0
- package/src/circuit/circuit/stop.ts +78 -0
- package/src/circuit/circuit/stream-handler.ts +86 -0
- package/src/circuit/circuit/{utils.js → utils.ts} +9 -25
- package/src/circuit/constants.ts +31 -0
- package/src/circuit/index.ts +120 -0
- package/src/circuit/listener.ts +82 -0
- package/src/circuit/multicodec.ts +2 -0
- package/src/circuit/{protocol → pb}/index.proto +1 -1
- package/src/circuit/pb/index.ts +117 -0
- package/src/circuit/transport.ts +219 -0
- package/src/circuit/utils.ts +12 -0
- package/src/config.ts +99 -0
- package/src/connection-manager/auto-dialler.ts +154 -0
- package/src/connection-manager/dialer/auto-dialer.ts +59 -0
- package/src/{dialer/dial-request.js → connection-manager/dialer/dial-request.ts} +60 -51
- package/src/connection-manager/dialer/index.ts +382 -0
- package/src/connection-manager/index.ts +508 -0
- package/src/connection-manager/latency-monitor.ts +319 -0
- package/src/connection-manager/{visibility-change-emitter.js → visibility-change-emitter.ts} +48 -38
- package/src/constants.ts +31 -0
- package/src/content-routing/index.ts +144 -0
- package/src/content-routing/utils.ts +54 -0
- package/src/dht/dht-content-routing.ts +43 -0
- package/src/dht/dht-peer-routing.ts +35 -0
- package/src/dht/dummy-dht.ts +60 -0
- package/src/errors.ts +73 -0
- package/src/fetch/README.md +1 -1
- package/src/fetch/constants.ts +3 -0
- package/src/fetch/index.ts +167 -0
- package/src/fetch/{proto.proto → pb/proto.proto} +0 -0
- package/src/fetch/pb/proto.ts +65 -0
- package/src/get-peer.ts +57 -0
- package/src/identify/consts.ts +13 -0
- package/src/identify/index.ts +445 -0
- package/src/identify/{message.proto → pb/message.proto} +0 -0
- package/src/identify/pb/message.ts +37 -0
- package/src/index.ts +220 -0
- package/src/insecure/index.ts +101 -0
- package/src/insecure/{proto.proto → pb/proto.proto} +0 -0
- package/src/insecure/pb/proto.ts +68 -0
- package/src/keychain/{cms.js → cms.ts} +62 -58
- package/src/keychain/index.ts +587 -0
- package/src/keychain/{util.js → util.ts} +7 -17
- package/src/libp2p.ts +538 -0
- package/src/metrics/index.ts +310 -0
- package/src/metrics/moving-average.ts +53 -0
- package/src/metrics/stats.ts +238 -0
- package/src/nat-manager.ts +194 -0
- package/src/peer-record-updater.ts +55 -0
- package/src/peer-routing.ts +186 -0
- package/src/ping/README.md +1 -1
- package/src/ping/constants.ts +5 -0
- package/src/ping/index.ts +84 -0
- package/src/pnet/README.md +2 -2
- package/src/pnet/crypto.ts +67 -0
- package/src/pnet/errors.ts +5 -0
- package/src/pnet/index.ts +97 -0
- package/src/pnet/key-generator.ts +28 -0
- package/src/pubsub/dummy-pubsub.ts +51 -0
- package/src/registrar.ts +189 -0
- package/src/transport-manager.ts +281 -0
- package/src/upgrader.ts +499 -0
- package/src/version.ts +3 -0
- package/dist/index.min.js +0 -55
- package/dist/src/circuit/protocol/index.d.ts +0 -173
- package/dist/src/dialer/dial-request.d.ts +0 -55
- package/dist/src/dialer/dial-request.d.ts.map +0 -1
- package/dist/src/dialer/index.d.ts +0 -182
- package/dist/src/dialer/index.d.ts.map +0 -1
- package/dist/src/fetch/proto.d.ts +0 -134
- package/dist/src/identify/message.d.ts +0 -95
- package/dist/src/insecure/plaintext.d.ts +0 -12
- package/dist/src/insecure/plaintext.d.ts.map +0 -1
- package/dist/src/insecure/proto.d.ts +0 -128
- package/dist/src/metrics/old-peers.d.ts +0 -3
- package/dist/src/metrics/old-peers.d.ts.map +0 -1
- package/dist/src/metrics/tracked-map.d.ts +0 -8
- package/dist/src/metrics/tracked-map.d.ts.map +0 -1
- package/dist/src/peer-store/address-book.d.ts +0 -67
- package/dist/src/peer-store/address-book.d.ts.map +0 -1
- package/dist/src/peer-store/index.d.ts +0 -58
- package/dist/src/peer-store/index.d.ts.map +0 -1
- package/dist/src/peer-store/key-book.d.ts +0 -40
- package/dist/src/peer-store/key-book.d.ts.map +0 -1
- package/dist/src/peer-store/metadata-book.d.ts +0 -58
- package/dist/src/peer-store/metadata-book.d.ts.map +0 -1
- package/dist/src/peer-store/pb/peer.d.ts +0 -222
- package/dist/src/peer-store/proto-book.d.ts +0 -43
- package/dist/src/peer-store/proto-book.d.ts.map +0 -1
- package/dist/src/peer-store/store.d.ts +0 -73
- package/dist/src/peer-store/store.d.ts.map +0 -1
- package/dist/src/peer-store/types.d.ts +0 -202
- package/dist/src/peer-store/types.d.ts.map +0 -1
- package/dist/src/ping/util.d.ts +0 -5
- package/dist/src/ping/util.d.ts.map +0 -1
- package/dist/src/pubsub-adapter.d.ts +0 -22
- package/dist/src/pubsub-adapter.d.ts.map +0 -1
- package/dist/src/record/envelope/envelope.d.ts +0 -77
- package/dist/src/record/envelope/index.d.ts +0 -80
- package/dist/src/record/envelope/index.d.ts.map +0 -1
- package/dist/src/record/peer-record/consts.d.ts +0 -4
- package/dist/src/record/peer-record/consts.d.ts.map +0 -1
- package/dist/src/record/peer-record/index.d.ts +0 -60
- package/dist/src/record/peer-record/index.d.ts.map +0 -1
- package/dist/src/record/peer-record/peer-record.d.ts +0 -133
- package/dist/src/record/utils.d.ts +0 -12
- package/dist/src/record/utils.d.ts.map +0 -1
- package/dist/src/types.d.ts +0 -90
- package/dist/src/types.d.ts.map +0 -1
- package/src/address-manager/index.js +0 -96
- package/src/circuit/auto-relay.js +0 -302
- package/src/circuit/circuit/hop.js +0 -205
- package/src/circuit/circuit/stop.js +0 -81
- package/src/circuit/circuit/stream-handler.js +0 -94
- package/src/circuit/constants.js +0 -12
- package/src/circuit/index.js +0 -102
- package/src/circuit/listener.js +0 -75
- package/src/circuit/multicodec.js +0 -5
- package/src/circuit/protocol/index.d.ts +0 -173
- package/src/circuit/protocol/index.js +0 -530
- package/src/circuit/transport.js +0 -229
- package/src/circuit/utils.js +0 -17
- package/src/config.js +0 -114
- package/src/connection-manager/auto-dialler.js +0 -132
- package/src/connection-manager/index.js +0 -374
- package/src/connection-manager/latency-monitor.js +0 -264
- package/src/constants.js +0 -18
- package/src/content-routing/index.js +0 -163
- package/src/content-routing/utils.js +0 -89
- package/src/dht/dht-content-routing.js +0 -44
- package/src/dht/dht-peer-routing.js +0 -51
- package/src/dialer/index.js +0 -376
- package/src/errors.js +0 -66
- package/src/fetch/constants.js +0 -6
- package/src/fetch/index.js +0 -159
- package/src/fetch/proto.d.ts +0 -134
- package/src/fetch/proto.js +0 -333
- package/src/get-peer.js +0 -49
- package/src/identify/consts.js +0 -15
- package/src/identify/index.js +0 -384
- package/src/identify/message.d.ts +0 -95
- package/src/identify/message.js +0 -328
- package/src/index.js +0 -813
- package/src/insecure/plaintext.js +0 -95
- package/src/insecure/proto.d.ts +0 -128
- package/src/insecure/proto.js +0 -371
- package/src/keychain/index.js +0 -561
- package/src/metrics/index.js +0 -290
- package/src/metrics/old-peers.js +0 -16
- package/src/metrics/stats.js +0 -270
- package/src/metrics/tracked-map.js +0 -94
- package/src/nat-manager.js +0 -197
- package/src/peer-routing.js +0 -176
- package/src/peer-store/README.md +0 -145
- package/src/peer-store/address-book.js +0 -382
- package/src/peer-store/index.js +0 -121
- package/src/peer-store/key-book.js +0 -141
- package/src/peer-store/metadata-book.js +0 -250
- package/src/peer-store/pb/peer.d.ts +0 -222
- package/src/peer-store/pb/peer.js +0 -643
- package/src/peer-store/pb/peer.proto +0 -31
- package/src/peer-store/proto-book.js +0 -237
- package/src/peer-store/store.js +0 -263
- package/src/peer-store/types.ts +0 -245
- package/src/ping/constants.js +0 -8
- package/src/ping/index.js +0 -84
- package/src/ping/util.js +0 -18
- package/src/pnet/crypto.js +0 -84
- package/src/pnet/errors.js +0 -7
- package/src/pnet/index.js +0 -86
- package/src/pnet/key-generator.js +0 -33
- package/src/pubsub-adapter.js +0 -61
- package/src/record/README.md +0 -130
- package/src/record/envelope/envelope.d.ts +0 -77
- package/src/record/envelope/envelope.js +0 -243
- package/src/record/envelope/envelope.proto +0 -19
- package/src/record/envelope/index.js +0 -183
- package/src/record/peer-record/consts.js +0 -14
- package/src/record/peer-record/index.js +0 -113
- package/src/record/peer-record/peer-record.d.ts +0 -133
- package/src/record/peer-record/peer-record.js +0 -367
- package/src/record/peer-record/peer-record.proto +0 -18
- package/src/record/utils.js +0 -25
- package/src/registrar.js +0 -127
- package/src/transport-manager.js +0 -269
- package/src/types.ts +0 -98
- package/src/upgrader.js +0 -492
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import { logger } from '@libp2p/logger'
|
|
2
|
+
import errCode from 'err-code'
|
|
3
|
+
import mergeOptions from 'merge-options'
|
|
4
|
+
import { LatencyMonitor, SummaryObject } from './latency-monitor.js'
|
|
5
|
+
// @ts-expect-error retimer does not have types
|
|
6
|
+
import retimer from 'retimer'
|
|
7
|
+
import type { AbortOptions } from '@libp2p/interfaces'
|
|
8
|
+
import { CustomEvent, EventEmitter } from '@libp2p/interfaces/events'
|
|
9
|
+
import type { Startable } from '@libp2p/interfaces/startable'
|
|
10
|
+
import { trackedMap } from '@libp2p/tracked-map'
|
|
11
|
+
import { codes } from '../errors.js'
|
|
12
|
+
import { isPeerId, PeerId } from '@libp2p/interfaces/peer-id'
|
|
13
|
+
// @ts-expect-error setMaxListeners is missing from the node 16 types
|
|
14
|
+
import { setMaxListeners } from 'events'
|
|
15
|
+
import type { Connection } from '@libp2p/interfaces/connection'
|
|
16
|
+
import type { ConnectionManager } from '@libp2p/interfaces/connection-manager'
|
|
17
|
+
import { Components, Initializable } from '@libp2p/interfaces/components'
|
|
18
|
+
import * as STATUS from '@libp2p/interfaces/connection/status'
|
|
19
|
+
import { Dialer } from './dialer/index.js'
|
|
20
|
+
import type { AddressSorter } from '@libp2p/interfaces/peer-store'
|
|
21
|
+
import type { Resolver } from '@multiformats/multiaddr'
|
|
22
|
+
|
|
23
|
+
const log = logger('libp2p:connection-manager')
|
|
24
|
+
|
|
25
|
+
const defaultOptions: Partial<ConnectionManagerInit> = {
|
|
26
|
+
maxConnections: Infinity,
|
|
27
|
+
minConnections: 0,
|
|
28
|
+
maxData: Infinity,
|
|
29
|
+
maxSentData: Infinity,
|
|
30
|
+
maxReceivedData: Infinity,
|
|
31
|
+
maxEventLoopDelay: Infinity,
|
|
32
|
+
pollInterval: 2000,
|
|
33
|
+
autoDialInterval: 10000,
|
|
34
|
+
movingAverageInterval: 60000,
|
|
35
|
+
defaultPeerValue: 1
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const METRICS_COMPONENT = 'connection-manager'
|
|
39
|
+
const METRICS_PEER_CONNECTIONS = 'peer-connections'
|
|
40
|
+
const METRICS_PEER_VALUES = 'peer-values'
|
|
41
|
+
|
|
42
|
+
export interface ConnectionManagerInit {
|
|
43
|
+
/**
|
|
44
|
+
* The maximum number of connections to keep open
|
|
45
|
+
*/
|
|
46
|
+
maxConnections: number
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The minimum number of connections to keep open
|
|
50
|
+
*/
|
|
51
|
+
minConnections: number
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The max data (in and out), per average interval to allow
|
|
55
|
+
*/
|
|
56
|
+
maxData?: number
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The max outgoing data, per average interval to allow
|
|
60
|
+
*/
|
|
61
|
+
maxSentData?: number
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The max incoming data, per average interval to allow
|
|
65
|
+
*/
|
|
66
|
+
maxReceivedData?: number
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The upper limit the event loop can take to run
|
|
70
|
+
*/
|
|
71
|
+
maxEventLoopDelay?: number
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* How often, in milliseconds, metrics and latency should be checked
|
|
75
|
+
*/
|
|
76
|
+
pollInterval?: number
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* How often, in milliseconds, to compute averages
|
|
80
|
+
*/
|
|
81
|
+
movingAverageInterval?: number
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The value of the peer
|
|
85
|
+
*/
|
|
86
|
+
defaultPeerValue?: number
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* If true, try to connect to all discovered peers up to the connection manager limit
|
|
90
|
+
*/
|
|
91
|
+
autoDial?: boolean
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* How long to wait between attempting to keep our number of concurrent connections
|
|
95
|
+
* above minConnections
|
|
96
|
+
*/
|
|
97
|
+
autoDialInterval: number
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Sort the known addresses of a peer before trying to dial
|
|
101
|
+
*/
|
|
102
|
+
addressSorter?: AddressSorter
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Number of max concurrent dials
|
|
106
|
+
*/
|
|
107
|
+
maxParallelDials?: number
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Number of max addresses to dial for a given peer
|
|
111
|
+
*/
|
|
112
|
+
maxAddrsToDial?: number
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* How long a dial attempt is allowed to take
|
|
116
|
+
*/
|
|
117
|
+
dialTimeout?: number
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Number of max concurrent dials per peer
|
|
121
|
+
*/
|
|
122
|
+
maxDialsPerPeer?: number
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Multiaddr resolvers to use when dialing
|
|
126
|
+
*/
|
|
127
|
+
resolvers?: Record<string, Resolver>
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface ConnectionManagerEvents {
|
|
131
|
+
'peer:connect': CustomEvent<PeerId>
|
|
132
|
+
'peer:disconnect': CustomEvent<PeerId>
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Responsible for managing known connections.
|
|
137
|
+
*/
|
|
138
|
+
export class DefaultConnectionManager extends EventEmitter<ConnectionManagerEvents> implements ConnectionManager, Startable, Initializable {
|
|
139
|
+
public readonly dialer: Dialer
|
|
140
|
+
private components = new Components()
|
|
141
|
+
private readonly opts: Required<ConnectionManagerInit>
|
|
142
|
+
private readonly peerValues: Map<string, number>
|
|
143
|
+
private readonly connections: Map<string, Connection[]>
|
|
144
|
+
private started: boolean
|
|
145
|
+
private timer?: ReturnType<retimer>
|
|
146
|
+
private readonly latencyMonitor: LatencyMonitor
|
|
147
|
+
|
|
148
|
+
constructor (init: ConnectionManagerInit) {
|
|
149
|
+
super()
|
|
150
|
+
|
|
151
|
+
this.opts = mergeOptions.call({ ignoreUndefined: true }, defaultOptions, init)
|
|
152
|
+
|
|
153
|
+
if (this.opts.maxConnections < this.opts.minConnections) {
|
|
154
|
+
throw errCode(new Error('Connection Manager maxConnections must be greater than minConnections'), codes.ERR_INVALID_PARAMETERS)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
log('options: %o', this.opts)
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Map of peer identifiers to their peer value for pruning connections.
|
|
161
|
+
*
|
|
162
|
+
* @type {Map<string, number>}
|
|
163
|
+
*/
|
|
164
|
+
this.peerValues = trackedMap({
|
|
165
|
+
component: METRICS_COMPONENT,
|
|
166
|
+
metric: METRICS_PEER_VALUES,
|
|
167
|
+
metrics: this.components.getMetrics()
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Map of connections per peer
|
|
172
|
+
*/
|
|
173
|
+
this.connections = trackedMap({
|
|
174
|
+
component: METRICS_COMPONENT,
|
|
175
|
+
metric: METRICS_PEER_CONNECTIONS,
|
|
176
|
+
metrics: this.components.getMetrics()
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
this.started = false
|
|
180
|
+
this._checkMetrics = this._checkMetrics.bind(this)
|
|
181
|
+
|
|
182
|
+
this.latencyMonitor = new LatencyMonitor({
|
|
183
|
+
latencyCheckIntervalMs: init.pollInterval,
|
|
184
|
+
dataEmitIntervalMs: init.pollInterval
|
|
185
|
+
})
|
|
186
|
+
|
|
187
|
+
try {
|
|
188
|
+
// This emitter gets listened to a lot
|
|
189
|
+
setMaxListeners?.(Infinity, this)
|
|
190
|
+
} catch {}
|
|
191
|
+
|
|
192
|
+
this.dialer = new Dialer(this.opts)
|
|
193
|
+
|
|
194
|
+
this.onConnect = this.onConnect.bind(this)
|
|
195
|
+
this.onDisconnect = this.onDisconnect.bind(this)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
init (components: Components): void {
|
|
199
|
+
this.components = components
|
|
200
|
+
|
|
201
|
+
this.dialer.init(components)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
isStarted () {
|
|
205
|
+
return this.started
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Starts the Connection Manager. If Metrics are not enabled on libp2p
|
|
210
|
+
* only event loop and connection limits will be monitored.
|
|
211
|
+
*/
|
|
212
|
+
async start () {
|
|
213
|
+
if (this.components.getMetrics() != null) {
|
|
214
|
+
this.timer = this.timer ?? retimer(this._checkMetrics, this.opts.pollInterval)
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// latency monitor
|
|
218
|
+
this.latencyMonitor.start()
|
|
219
|
+
this._onLatencyMeasure = this._onLatencyMeasure.bind(this)
|
|
220
|
+
this.latencyMonitor.addEventListener('data', this._onLatencyMeasure)
|
|
221
|
+
await this.dialer.start()
|
|
222
|
+
|
|
223
|
+
this.started = true
|
|
224
|
+
log('started')
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async afterStart () {
|
|
228
|
+
this.components.getUpgrader().addEventListener('connection', this.onConnect)
|
|
229
|
+
this.components.getUpgrader().addEventListener('connectionEnd', this.onDisconnect)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
async beforeStop () {
|
|
233
|
+
this.components.getUpgrader().removeEventListener('connection', this.onConnect)
|
|
234
|
+
this.components.getUpgrader().removeEventListener('connectionEnd', this.onDisconnect)
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Stops the Connection Manager
|
|
239
|
+
*/
|
|
240
|
+
async stop () {
|
|
241
|
+
this.timer?.clear()
|
|
242
|
+
|
|
243
|
+
this.latencyMonitor.removeEventListener('data', this._onLatencyMeasure)
|
|
244
|
+
this.latencyMonitor.stop()
|
|
245
|
+
await this.dialer.stop()
|
|
246
|
+
|
|
247
|
+
this.started = false
|
|
248
|
+
await this._close()
|
|
249
|
+
log('stopped')
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Cleans up the connections
|
|
254
|
+
*/
|
|
255
|
+
async _close () {
|
|
256
|
+
// Close all connections we're tracking
|
|
257
|
+
const tasks = []
|
|
258
|
+
for (const connectionList of this.connections.values()) {
|
|
259
|
+
for (const connection of connectionList) {
|
|
260
|
+
tasks.push(connection.close())
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
log('closing %d connections', tasks.length)
|
|
265
|
+
await Promise.all(tasks)
|
|
266
|
+
this.connections.clear()
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Sets the value of the given peer. Peers with lower values
|
|
271
|
+
* will be disconnected first.
|
|
272
|
+
*/
|
|
273
|
+
setPeerValue (peerId: PeerId, value: number) {
|
|
274
|
+
if (value < 0 || value > 1) {
|
|
275
|
+
throw new Error('value should be a number between 0 and 1')
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
this.peerValues.set(peerId.toString(), value)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Checks the libp2p metrics to determine if any values have exceeded
|
|
283
|
+
* the configured maximums.
|
|
284
|
+
*
|
|
285
|
+
* @private
|
|
286
|
+
*/
|
|
287
|
+
async _checkMetrics () {
|
|
288
|
+
const metrics = this.components.getMetrics()
|
|
289
|
+
|
|
290
|
+
if (metrics != null) {
|
|
291
|
+
try {
|
|
292
|
+
const movingAverages = metrics.getGlobal().getMovingAverages()
|
|
293
|
+
const received = movingAverages.dataReceived[this.opts.movingAverageInterval].movingAverage
|
|
294
|
+
await this._checkMaxLimit('maxReceivedData', received)
|
|
295
|
+
const sent = movingAverages.dataSent[this.opts.movingAverageInterval].movingAverage
|
|
296
|
+
await this._checkMaxLimit('maxSentData', sent)
|
|
297
|
+
const total = received + sent
|
|
298
|
+
await this._checkMaxLimit('maxData', total)
|
|
299
|
+
log.trace('metrics update', total)
|
|
300
|
+
} finally {
|
|
301
|
+
this.timer = retimer(this._checkMetrics, this.opts.pollInterval)
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
onConnect (evt: CustomEvent<Connection>) {
|
|
307
|
+
void this._onConnect(evt).catch(err => {
|
|
308
|
+
log.error(err)
|
|
309
|
+
})
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Tracks the incoming connection and check the connection limit
|
|
314
|
+
*/
|
|
315
|
+
async _onConnect (evt: CustomEvent<Connection>) {
|
|
316
|
+
const { detail: connection } = evt
|
|
317
|
+
|
|
318
|
+
if (!this.started) {
|
|
319
|
+
// This can happen when we are in the process of shutting down the node
|
|
320
|
+
await connection.close()
|
|
321
|
+
return
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const peerId = connection.remotePeer
|
|
325
|
+
const peerIdStr = peerId.toString()
|
|
326
|
+
const storedConns = this.connections.get(peerIdStr)
|
|
327
|
+
|
|
328
|
+
if (storedConns != null) {
|
|
329
|
+
storedConns.push(connection)
|
|
330
|
+
} else {
|
|
331
|
+
this.connections.set(peerIdStr, [connection])
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
if (peerId.publicKey != null) {
|
|
335
|
+
await this.components.getPeerStore().keyBook.set(peerId, peerId.publicKey)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (!this.peerValues.has(peerIdStr)) {
|
|
339
|
+
this.peerValues.set(peerIdStr, this.opts.defaultPeerValue)
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
await this._checkMaxLimit('maxConnections', this.getConnections().length)
|
|
343
|
+
this.dispatchEvent(new CustomEvent<Connection>('peer:connect', { detail: connection }))
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Removes the connection from tracking
|
|
348
|
+
*/
|
|
349
|
+
onDisconnect (evt: CustomEvent<Connection>) {
|
|
350
|
+
const { detail: connection } = evt
|
|
351
|
+
|
|
352
|
+
if (!this.started) {
|
|
353
|
+
// This can happen when we are in the process of shutting down the node
|
|
354
|
+
return
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const peerId = connection.remotePeer.toString()
|
|
358
|
+
let storedConn = this.connections.get(peerId)
|
|
359
|
+
|
|
360
|
+
if (storedConn != null && storedConn.length > 1) {
|
|
361
|
+
storedConn = storedConn.filter((conn) => conn.id !== connection.id)
|
|
362
|
+
this.connections.set(peerId, storedConn)
|
|
363
|
+
} else if (storedConn != null) {
|
|
364
|
+
this.connections.delete(peerId)
|
|
365
|
+
this.peerValues.delete(connection.remotePeer.toString())
|
|
366
|
+
this.dispatchEvent(new CustomEvent<Connection>('peer:disconnect', { detail: connection }))
|
|
367
|
+
|
|
368
|
+
this.components.getMetrics()?.onPeerDisconnected(connection.remotePeer)
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
getConnections (peerId?: PeerId): Connection[] {
|
|
373
|
+
if (peerId != null) {
|
|
374
|
+
return this.connections.get(peerId.toString()) ?? []
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
let conns: Connection[] = []
|
|
378
|
+
|
|
379
|
+
for (const c of this.connections.values()) {
|
|
380
|
+
conns = conns.concat(c)
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
return conns
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
async openConnection (peerId: PeerId, options?: AbortOptions): Promise<Connection> {
|
|
387
|
+
log('dial to %p', peerId)
|
|
388
|
+
const existingConnections = this.getConnections(peerId)
|
|
389
|
+
|
|
390
|
+
if (existingConnections.length > 0) {
|
|
391
|
+
log('had an existing connection to %p', peerId)
|
|
392
|
+
|
|
393
|
+
return existingConnections[0]
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
const connection = await this.dialer.dial(peerId, options)
|
|
397
|
+
let peerConnections = this.connections.get(peerId.toString())
|
|
398
|
+
|
|
399
|
+
if (peerConnections == null) {
|
|
400
|
+
peerConnections = []
|
|
401
|
+
this.connections.set(peerId.toString(), peerConnections)
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
// we get notified of connections via the Upgrader emitting "connection"
|
|
405
|
+
// events, double check we aren't already tracking this connection before
|
|
406
|
+
// storing it
|
|
407
|
+
let trackedConnection = false
|
|
408
|
+
|
|
409
|
+
for (const conn of peerConnections) {
|
|
410
|
+
if (conn.id === connection.id) {
|
|
411
|
+
trackedConnection = true
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (!trackedConnection) {
|
|
416
|
+
peerConnections.push(connection)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
return connection
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
async closeConnections (peerId: PeerId): Promise<void> {
|
|
423
|
+
const connections = this.connections.get(peerId.toString()) ?? []
|
|
424
|
+
|
|
425
|
+
await Promise.all(
|
|
426
|
+
connections.map(async connection => {
|
|
427
|
+
return await connection.close()
|
|
428
|
+
})
|
|
429
|
+
)
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Get all open connections with a peer
|
|
434
|
+
*/
|
|
435
|
+
getAll (peerId: PeerId): Connection[] {
|
|
436
|
+
if (!isPeerId(peerId)) {
|
|
437
|
+
throw errCode(new Error('peerId must be an instance of peer-id'), codes.ERR_INVALID_PARAMETERS)
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
const id = peerId.toString()
|
|
441
|
+
const connections = this.connections.get(id)
|
|
442
|
+
|
|
443
|
+
// Return all open connections
|
|
444
|
+
if (connections != null) {
|
|
445
|
+
return connections.filter(connection => connection.stat.status === STATUS.OPEN)
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return []
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* If the event loop is slow, maybe close a connection
|
|
453
|
+
*/
|
|
454
|
+
_onLatencyMeasure (evt: CustomEvent<SummaryObject>) {
|
|
455
|
+
const { detail: summary } = evt
|
|
456
|
+
|
|
457
|
+
this._checkMaxLimit('maxEventLoopDelay', summary.avgMs)
|
|
458
|
+
.catch(err => {
|
|
459
|
+
log.error(err)
|
|
460
|
+
})
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* If the `value` of `name` has exceeded its limit, maybe close a connection
|
|
465
|
+
*/
|
|
466
|
+
async _checkMaxLimit (name: keyof ConnectionManagerInit, value: number) {
|
|
467
|
+
const limit = this.opts[name]
|
|
468
|
+
log.trace('checking limit of %s. current value: %d of %d', name, value, limit)
|
|
469
|
+
if (value > limit) {
|
|
470
|
+
log('%s: limit exceeded: %p, %d', this.components.getPeerId(), name, value)
|
|
471
|
+
await this._maybeDisconnectOne()
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* If we have more connections than our maximum, close a connection
|
|
477
|
+
* to the lowest valued peer.
|
|
478
|
+
*/
|
|
479
|
+
async _maybeDisconnectOne () {
|
|
480
|
+
if (this.opts.minConnections < this.connections.size) {
|
|
481
|
+
const peerValues = Array.from(new Map([...this.peerValues.entries()].sort((a, b) => a[1] - b[1])))
|
|
482
|
+
|
|
483
|
+
log('%p: sorted peer values: %j', this.components.getPeerId(), peerValues)
|
|
484
|
+
const disconnectPeer = peerValues[0]
|
|
485
|
+
|
|
486
|
+
if (disconnectPeer != null) {
|
|
487
|
+
const peerId = disconnectPeer[0]
|
|
488
|
+
log('%p: lowest value peer is %s', this.components.getPeerId(), peerId)
|
|
489
|
+
log('%p: closing a connection to %j', this.components.getPeerId(), peerId)
|
|
490
|
+
|
|
491
|
+
for (const connections of this.connections.values()) {
|
|
492
|
+
if (connections[0].remotePeer.toString() === peerId) {
|
|
493
|
+
void connections[0].close()
|
|
494
|
+
.catch(err => {
|
|
495
|
+
log.error(err)
|
|
496
|
+
})
|
|
497
|
+
|
|
498
|
+
// TODO: should not need to invoke this manually
|
|
499
|
+
this.onDisconnect(new CustomEvent<Connection>('connectionEnd', {
|
|
500
|
+
detail: connections[0]
|
|
501
|
+
}))
|
|
502
|
+
break
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
}
|