libp2p 0.36.0 → 0.36.2-1473044
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +3 -21
- package/README.md +13 -10
- package/dist/src/address-manager/index.d.ts +33 -52
- package/dist/src/address-manager/index.d.ts.map +1 -1
- package/dist/src/address-manager/index.js +81 -0
- package/dist/src/address-manager/index.js.map +1 -0
- package/dist/src/circuit/auto-relay.d.ts +24 -85
- package/dist/src/circuit/auto-relay.d.ts.map +1 -1
- package/dist/src/circuit/auto-relay.js +215 -0
- package/dist/src/circuit/auto-relay.js.map +1 -0
- package/dist/src/circuit/circuit/hop.d.ts +26 -53
- package/dist/src/circuit/circuit/hop.d.ts.map +1 -1
- package/dist/src/circuit/circuit/hop.js +138 -0
- package/dist/src/circuit/circuit/hop.js.map +1 -0
- package/dist/src/circuit/circuit/stop.d.ts +18 -10
- package/dist/src/circuit/circuit/stop.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stop.js +49 -0
- package/dist/src/circuit/circuit/stop.js.map +1 -0
- package/dist/src/circuit/circuit/stream-handler.d.ts +19 -38
- package/dist/src/circuit/circuit/stream-handler.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stream-handler.js +59 -0
- package/dist/src/circuit/circuit/stream-handler.js.map +1 -0
- package/dist/src/circuit/circuit/utils.d.ts +3 -6
- package/dist/src/circuit/circuit/utils.d.ts.map +1 -1
- package/dist/src/circuit/circuit/utils.js +43 -0
- package/dist/src/circuit/circuit/utils.js.map +1 -0
- package/dist/src/circuit/constants.d.ts +24 -6
- package/dist/src/circuit/constants.d.ts.map +1 -1
- package/dist/src/circuit/constants.js +26 -0
- package/dist/src/circuit/constants.js.map +1 -0
- package/dist/src/circuit/index.d.ts +41 -74
- package/dist/src/circuit/index.d.ts.map +1 -1
- package/dist/src/circuit/index.js +69 -0
- package/dist/src/circuit/index.js.map +1 -0
- package/dist/src/circuit/listener.d.ts +8 -3
- package/dist/src/circuit/listener.d.ts.map +1 -1
- package/dist/src/circuit/listener.js +54 -0
- package/dist/src/circuit/listener.js.map +1 -0
- package/dist/src/circuit/multicodec.d.ts +1 -1
- package/dist/src/circuit/multicodec.d.ts.map +1 -1
- package/dist/src/circuit/multicodec.js +2 -0
- package/dist/src/circuit/multicodec.js.map +1 -0
- package/dist/src/circuit/pb/index.d.ts +51 -0
- package/dist/src/circuit/pb/index.d.ts.map +1 -0
- package/dist/src/circuit/pb/index.js +72 -0
- package/dist/src/circuit/pb/index.js.map +1 -0
- package/dist/src/circuit/transport.d.ts +18 -78
- package/dist/src/circuit/transport.d.ts.map +1 -1
- package/dist/src/circuit/transport.js +190 -0
- package/dist/src/circuit/transport.js.map +1 -0
- package/dist/src/circuit/utils.d.ts +5 -2
- package/dist/src/circuit/utils.d.ts.map +1 -1
- package/dist/src/circuit/utils.js +11 -0
- package/dist/src/circuit/utils.js.map +1 -0
- package/dist/src/config.d.ts +3 -85
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +93 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/connection-manager/auto-dialler.d.ts +24 -41
- package/dist/src/connection-manager/auto-dialler.d.ts.map +1 -1
- package/dist/src/connection-manager/auto-dialler.js +105 -0
- package/dist/src/connection-manager/auto-dialler.js.map +1 -0
- package/dist/src/connection-manager/index.d.ts +79 -144
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +295 -0
- package/dist/src/connection-manager/index.js.map +1 -0
- package/dist/src/connection-manager/latency-monitor.d.ts +72 -97
- package/dist/src/connection-manager/latency-monitor.d.ts.map +1 -1
- package/dist/src/connection-manager/latency-monitor.js +220 -0
- package/dist/src/connection-manager/latency-monitor.js.map +1 -0
- package/dist/src/connection-manager/visibility-change-emitter.d.ts +15 -16
- package/dist/src/connection-manager/visibility-change-emitter.d.ts.map +1 -1
- package/dist/src/connection-manager/visibility-change-emitter.js +118 -0
- package/dist/src/connection-manager/visibility-change-emitter.js.map +1 -0
- package/dist/src/constants.d.ts +22 -10
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +27 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/content-routing/index.d.ts +26 -81
- package/dist/src/content-routing/index.d.ts.map +1 -1
- package/dist/src/content-routing/index.js +99 -0
- package/dist/src/content-routing/index.js.map +1 -0
- package/dist/src/content-routing/utils.d.ts +6 -49
- package/dist/src/content-routing/utils.d.ts.map +1 -1
- package/dist/src/content-routing/utils.js +42 -0
- package/dist/src/content-routing/utils.js.map +1 -0
- package/dist/src/dht/dht-content-routing.d.ts +10 -24
- package/dist/src/dht/dht-content-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-content-routing.js +32 -0
- package/dist/src/dht/dht-content-routing.js.map +1 -0
- package/dist/src/dht/dht-peer-routing.d.ts +9 -24
- package/dist/src/dht/dht-peer-routing.d.ts.map +1 -1
- package/dist/src/dht/dht-peer-routing.js +26 -0
- package/dist/src/dht/dht-peer-routing.js.map +1 -0
- package/dist/src/dialer/auto-dialer.d.ts +14 -0
- package/dist/src/dialer/auto-dialer.d.ts.map +1 -0
- package/dist/src/dialer/auto-dialer.js +24 -0
- package/dist/src/dialer/auto-dialer.js.map +1 -0
- package/dist/src/dialer/dial-request.d.ts +18 -46
- package/dist/src/dialer/dial-request.d.ts.map +1 -1
- package/dist/src/dialer/dial-request.js +83 -0
- package/dist/src/dialer/dial-request.js.map +1 -0
- package/dist/src/dialer/index.d.ts +41 -148
- package/dist/src/dialer/index.d.ts.map +1 -1
- package/dist/src/dialer/index.js +280 -0
- package/dist/src/dialer/index.js.map +1 -0
- package/dist/src/errors.d.ts +68 -63
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +73 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/fetch/constants.d.ts +1 -1
- package/dist/src/fetch/constants.d.ts.map +1 -1
- package/dist/src/fetch/constants.js +3 -0
- package/dist/src/fetch/constants.js.map +1 -0
- package/dist/src/fetch/index.d.ts +30 -49
- package/dist/src/fetch/index.d.ts.map +1 -1
- package/dist/src/fetch/index.js +129 -0
- package/dist/src/fetch/index.js.map +1 -0
- package/dist/src/fetch/pb/proto.d.ts +26 -0
- package/dist/src/fetch/pb/proto.d.ts.map +1 -0
- package/dist/src/fetch/pb/proto.js +44 -0
- package/dist/src/fetch/pb/proto.js.map +1 -0
- package/dist/src/get-peer.d.ts +4 -11
- package/dist/src/get-peer.d.ts.map +1 -1
- package/dist/src/get-peer.js +43 -0
- package/dist/src/get-peer.js.map +1 -0
- package/dist/src/identify/consts.d.ts +9 -9
- package/dist/src/identify/consts.d.ts.map +1 -1
- package/dist/src/identify/consts.js +11 -0
- package/dist/src/identify/consts.js.map +1 -0
- package/dist/src/identify/index.d.ts +42 -96
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +322 -0
- package/dist/src/identify/index.js.map +1 -0
- package/dist/src/identify/pb/message.d.ts +15 -0
- package/dist/src/identify/pb/message.d.ts.map +1 -0
- package/dist/src/identify/pb/message.js +24 -0
- package/dist/src/identify/pb/message.js.map +1 -0
- package/dist/src/index.d.ts +162 -581
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +9 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/insecure/index.d.ts +9 -0
- package/dist/src/insecure/index.d.ts.map +1 -0
- package/dist/src/insecure/index.js +81 -0
- package/dist/src/insecure/index.js.map +1 -0
- package/dist/src/insecure/pb/proto.d.ts +28 -0
- package/dist/src/insecure/pb/proto.d.ts.map +1 -0
- package/dist/src/insecure/pb/proto.js +46 -0
- package/dist/src/insecure/pb/proto.js.map +1 -0
- package/dist/src/keychain/cms.d.ts +6 -14
- package/dist/src/keychain/cms.d.ts.map +1 -1
- package/dist/src/keychain/cms.js +129 -0
- package/dist/src/keychain/cms.js.map +1 -0
- package/dist/src/keychain/index.d.ts +61 -81
- package/dist/src/keychain/index.d.ts.map +1 -1
- package/dist/src/keychain/index.js +493 -0
- package/dist/src/keychain/index.js.map +1 -0
- package/dist/src/keychain/util.d.ts +3 -6
- package/dist/src/keychain/util.d.ts.map +1 -1
- package/dist/src/keychain/util.js +79 -0
- package/dist/src/keychain/util.js.map +1 -0
- package/dist/src/libp2p.d.ts +78 -0
- package/dist/src/libp2p.d.ts.map +1 -0
- package/dist/src/libp2p.js +375 -0
- package/dist/src/libp2p.js.map +1 -0
- package/dist/src/metrics/index.d.ts +47 -104
- package/dist/src/metrics/index.d.ts.map +1 -1
- package/dist/src/metrics/index.js +231 -0
- package/dist/src/metrics/index.js.map +1 -0
- package/dist/src/metrics/moving-average.d.ts +14 -0
- package/dist/src/metrics/moving-average.d.ts.map +1 -0
- package/dist/src/metrics/moving-average.js +40 -0
- package/dist/src/metrics/moving-average.js.map +1 -0
- package/dist/src/metrics/stats.d.ts +41 -93
- package/dist/src/metrics/stats.d.ts.map +1 -1
- package/dist/src/metrics/stats.js +183 -0
- package/dist/src/metrics/stats.js.map +1 -0
- package/dist/src/nat-manager.d.ts +42 -99
- package/dist/src/nat-manager.d.ts.map +1 -1
- package/dist/src/nat-manager.js +114 -0
- package/dist/src/nat-manager.js.map +1 -0
- package/dist/src/peer-record-updater.d.ts +15 -0
- package/dist/src/peer-record-updater.d.ts.map +1 -0
- package/dist/src/peer-record-updater.js +44 -0
- package/dist/src/peer-record-updater.js.map +1 -0
- package/dist/src/peer-routing.d.ts +39 -84
- package/dist/src/peer-routing.d.ts.map +1 -1
- package/dist/src/peer-routing.js +108 -0
- package/dist/src/peer-routing.js.map +1 -0
- package/dist/src/ping/constants.d.ts +4 -4
- package/dist/src/ping/constants.d.ts.map +1 -1
- package/dist/src/ping/constants.js +5 -0
- package/dist/src/ping/constants.js.map +1 -0
- package/dist/src/ping/index.d.ts +26 -33
- package/dist/src/ping/index.d.ts.map +1 -1
- package/dist/src/ping/index.js +56 -0
- package/dist/src/ping/index.js.map +1 -0
- package/dist/src/pnet/crypto.d.ts +15 -5
- package/dist/src/pnet/crypto.d.ts.map +1 -1
- package/dist/src/pnet/crypto.js +60 -0
- package/dist/src/pnet/crypto.js.map +1 -0
- package/dist/src/pnet/errors.d.ts +5 -5
- package/dist/src/pnet/errors.d.ts.map +1 -1
- package/dist/src/pnet/errors.js +6 -0
- package/dist/src/pnet/errors.js.map +1 -0
- package/dist/src/pnet/index.d.ts +11 -20
- package/dist/src/pnet/index.d.ts.map +1 -1
- package/dist/src/pnet/index.js +66 -0
- package/dist/src/pnet/index.js.map +1 -0
- package/dist/src/pnet/key-generator.d.ts +3 -7
- package/dist/src/pnet/key-generator.d.ts.map +1 -1
- package/dist/src/pnet/key-generator.js +25 -0
- package/dist/src/pnet/key-generator.js.map +1 -0
- package/dist/src/registrar.d.ts +27 -65
- package/dist/src/registrar.d.ts.map +1 -1
- package/dist/src/registrar.js +159 -0
- package/dist/src/registrar.js.map +1 -0
- package/dist/src/transport-manager.d.ts +34 -82
- package/dist/src/transport-manager.d.ts.map +1 -1
- package/dist/src/transport-manager.js +223 -0
- package/dist/src/transport-manager.js.map +1 -0
- package/dist/src/upgrader.d.ts +49 -129
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +402 -0
- package/dist/src/upgrader.js.map +1 -0
- package/dist/src/version.d.ts +3 -0
- package/dist/src/version.d.ts.map +1 -0
- package/dist/src/version.js +3 -0
- package/dist/src/version.js.map +1 -0
- package/package.json +150 -197
- package/src/address-manager/index.ts +129 -0
- package/src/circuit/README.md +16 -11
- package/src/circuit/auto-relay.ts +284 -0
- package/src/circuit/circuit/hop.ts +211 -0
- package/src/circuit/circuit/stop.ts +78 -0
- package/src/circuit/circuit/stream-handler.ts +86 -0
- package/src/circuit/circuit/{utils.js → utils.ts} +9 -25
- package/src/circuit/constants.ts +31 -0
- package/src/circuit/index.ts +120 -0
- package/src/circuit/{listener.js → listener.ts} +21 -27
- package/src/circuit/multicodec.ts +2 -0
- package/src/circuit/{protocol → pb}/index.proto +1 -1
- package/src/circuit/pb/index.ts +88 -0
- package/src/circuit/transport.ts +216 -0
- package/src/circuit/utils.ts +12 -0
- package/src/config.ts +101 -0
- package/src/connection-manager/auto-dialler.ts +154 -0
- package/src/connection-manager/index.ts +422 -0
- package/src/connection-manager/latency-monitor.ts +319 -0
- package/src/connection-manager/{visibility-change-emitter.js → visibility-change-emitter.ts} +48 -38
- package/src/constants.ts +31 -0
- package/src/content-routing/index.ts +143 -0
- package/src/content-routing/utils.ts +54 -0
- package/src/dht/dht-content-routing.ts +43 -0
- package/src/dht/dht-peer-routing.ts +35 -0
- package/src/dialer/auto-dialer.ts +40 -0
- package/src/dialer/{dial-request.js → dial-request.ts} +60 -51
- package/src/dialer/index.ts +371 -0
- package/src/errors.ts +71 -0
- package/src/fetch/README.md +1 -1
- package/src/fetch/constants.ts +3 -0
- package/src/fetch/index.ts +167 -0
- package/src/fetch/{proto.proto → pb/proto.proto} +0 -0
- package/src/fetch/pb/proto.ts +58 -0
- package/src/get-peer.ts +57 -0
- package/src/identify/consts.ts +13 -0
- package/src/identify/index.ts +445 -0
- package/src/identify/{message.proto → pb/message.proto} +0 -0
- package/src/identify/pb/message.ts +36 -0
- package/src/index.ts +242 -0
- package/src/insecure/index.ts +101 -0
- package/src/insecure/{proto.proto → pb/proto.proto} +0 -0
- package/src/insecure/pb/proto.ts +61 -0
- package/src/keychain/{cms.js → cms.ts} +62 -58
- package/src/keychain/index.ts +588 -0
- package/src/keychain/{util.js → util.ts} +7 -17
- package/src/libp2p.ts +513 -0
- package/src/metrics/index.ts +310 -0
- package/src/metrics/moving-average.ts +53 -0
- package/src/metrics/stats.ts +238 -0
- package/src/nat-manager.ts +194 -0
- package/src/peer-record-updater.ts +55 -0
- package/src/peer-routing.ts +185 -0
- package/src/ping/README.md +1 -1
- package/src/ping/constants.ts +5 -0
- package/src/ping/index.ts +83 -0
- package/src/pnet/README.md +2 -2
- package/src/pnet/crypto.ts +67 -0
- package/src/pnet/errors.ts +5 -0
- package/src/pnet/index.ts +95 -0
- package/src/pnet/key-generator.ts +28 -0
- package/src/registrar.ts +205 -0
- package/src/transport-manager.ts +279 -0
- package/src/upgrader.ts +499 -0
- package/src/version.ts +3 -0
- package/dist/index.min.js +0 -55
- package/dist/src/circuit/protocol/index.d.ts +0 -173
- package/dist/src/fetch/proto.d.ts +0 -134
- package/dist/src/identify/message.d.ts +0 -95
- package/dist/src/insecure/plaintext.d.ts +0 -12
- package/dist/src/insecure/plaintext.d.ts.map +0 -1
- package/dist/src/insecure/proto.d.ts +0 -128
- package/dist/src/metrics/old-peers.d.ts +0 -3
- package/dist/src/metrics/old-peers.d.ts.map +0 -1
- package/dist/src/metrics/tracked-map.d.ts +0 -8
- package/dist/src/metrics/tracked-map.d.ts.map +0 -1
- package/dist/src/peer-store/address-book.d.ts +0 -67
- package/dist/src/peer-store/address-book.d.ts.map +0 -1
- package/dist/src/peer-store/index.d.ts +0 -58
- package/dist/src/peer-store/index.d.ts.map +0 -1
- package/dist/src/peer-store/key-book.d.ts +0 -40
- package/dist/src/peer-store/key-book.d.ts.map +0 -1
- package/dist/src/peer-store/metadata-book.d.ts +0 -58
- package/dist/src/peer-store/metadata-book.d.ts.map +0 -1
- package/dist/src/peer-store/pb/peer.d.ts +0 -222
- package/dist/src/peer-store/proto-book.d.ts +0 -43
- package/dist/src/peer-store/proto-book.d.ts.map +0 -1
- package/dist/src/peer-store/store.d.ts +0 -73
- package/dist/src/peer-store/store.d.ts.map +0 -1
- package/dist/src/peer-store/types.d.ts +0 -202
- package/dist/src/peer-store/types.d.ts.map +0 -1
- package/dist/src/ping/util.d.ts +0 -5
- package/dist/src/ping/util.d.ts.map +0 -1
- package/dist/src/pubsub-adapter.d.ts +0 -22
- package/dist/src/pubsub-adapter.d.ts.map +0 -1
- package/dist/src/record/envelope/envelope.d.ts +0 -77
- package/dist/src/record/envelope/index.d.ts +0 -80
- package/dist/src/record/envelope/index.d.ts.map +0 -1
- package/dist/src/record/peer-record/consts.d.ts +0 -4
- package/dist/src/record/peer-record/consts.d.ts.map +0 -1
- package/dist/src/record/peer-record/index.d.ts +0 -60
- package/dist/src/record/peer-record/index.d.ts.map +0 -1
- package/dist/src/record/peer-record/peer-record.d.ts +0 -133
- package/dist/src/record/utils.d.ts +0 -12
- package/dist/src/record/utils.d.ts.map +0 -1
- package/dist/src/types.d.ts +0 -90
- package/dist/src/types.d.ts.map +0 -1
- package/src/address-manager/index.js +0 -96
- package/src/circuit/auto-relay.js +0 -302
- package/src/circuit/circuit/hop.js +0 -205
- package/src/circuit/circuit/stop.js +0 -81
- package/src/circuit/circuit/stream-handler.js +0 -94
- package/src/circuit/constants.js +0 -12
- package/src/circuit/index.js +0 -102
- package/src/circuit/multicodec.js +0 -5
- package/src/circuit/protocol/index.d.ts +0 -173
- package/src/circuit/protocol/index.js +0 -530
- package/src/circuit/transport.js +0 -229
- package/src/circuit/utils.js +0 -17
- package/src/config.js +0 -114
- package/src/connection-manager/auto-dialler.js +0 -132
- package/src/connection-manager/index.js +0 -363
- package/src/connection-manager/latency-monitor.js +0 -264
- package/src/constants.js +0 -18
- package/src/content-routing/index.js +0 -163
- package/src/content-routing/utils.js +0 -89
- package/src/dht/dht-content-routing.js +0 -44
- package/src/dht/dht-peer-routing.js +0 -51
- package/src/dialer/index.js +0 -376
- package/src/errors.js +0 -66
- package/src/fetch/constants.js +0 -6
- package/src/fetch/index.js +0 -159
- package/src/fetch/proto.d.ts +0 -134
- package/src/fetch/proto.js +0 -333
- package/src/get-peer.js +0 -49
- package/src/identify/consts.js +0 -15
- package/src/identify/index.js +0 -384
- package/src/identify/message.d.ts +0 -95
- package/src/identify/message.js +0 -328
- package/src/index.js +0 -811
- package/src/insecure/plaintext.js +0 -95
- package/src/insecure/proto.d.ts +0 -128
- package/src/insecure/proto.js +0 -371
- package/src/keychain/index.js +0 -561
- package/src/metrics/index.js +0 -290
- package/src/metrics/old-peers.js +0 -16
- package/src/metrics/stats.js +0 -270
- package/src/metrics/tracked-map.js +0 -94
- package/src/nat-manager.js +0 -197
- package/src/peer-routing.js +0 -176
- package/src/peer-store/README.md +0 -145
- package/src/peer-store/address-book.js +0 -382
- package/src/peer-store/index.js +0 -121
- package/src/peer-store/key-book.js +0 -141
- package/src/peer-store/metadata-book.js +0 -250
- package/src/peer-store/pb/peer.d.ts +0 -222
- package/src/peer-store/pb/peer.js +0 -643
- package/src/peer-store/pb/peer.proto +0 -31
- package/src/peer-store/proto-book.js +0 -237
- package/src/peer-store/store.js +0 -263
- package/src/peer-store/types.ts +0 -245
- package/src/ping/constants.js +0 -8
- package/src/ping/index.js +0 -85
- package/src/ping/util.js +0 -18
- package/src/pnet/crypto.js +0 -84
- package/src/pnet/errors.js +0 -7
- package/src/pnet/index.js +0 -86
- package/src/pnet/key-generator.js +0 -33
- package/src/pubsub-adapter.js +0 -61
- package/src/record/README.md +0 -130
- package/src/record/envelope/envelope.d.ts +0 -77
- package/src/record/envelope/envelope.js +0 -243
- package/src/record/envelope/envelope.proto +0 -19
- package/src/record/envelope/index.js +0 -183
- package/src/record/peer-record/consts.js +0 -14
- package/src/record/peer-record/index.js +0 -113
- package/src/record/peer-record/peer-record.d.ts +0 -133
- package/src/record/peer-record/peer-record.js +0 -367
- package/src/record/peer-record/peer-record.proto +0 -18
- package/src/record/utils.js +0 -25
- package/src/registrar.js +0 -127
- package/src/transport-manager.js +0 -269
- package/src/types.ts +0 -98
- package/src/upgrader.js +0 -492
|
@@ -1,112 +1,77 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
_peerStats: Map<any, any>;
|
|
31
|
-
_protocolStats: Map<any, any>;
|
|
32
|
-
_oldPeers: any;
|
|
33
|
-
_running: boolean;
|
|
34
|
-
/**
|
|
35
|
-
* Takes the metadata for a message and tracks it in the
|
|
36
|
-
* appropriate categories. If the protocol is present, protocol
|
|
37
|
-
* stats will also be tracked.
|
|
38
|
-
*
|
|
39
|
-
* @private
|
|
40
|
-
* @param {object} params
|
|
41
|
-
* @param {PeerId} params.remotePeer - Remote peer
|
|
42
|
-
* @param {string} [params.protocol] - Protocol string the stream is running
|
|
43
|
-
* @param {string} params.direction - One of ['in','out']
|
|
44
|
-
* @param {number} params.dataLength - Size of the message
|
|
45
|
-
* @returns {void}
|
|
46
|
-
*/
|
|
47
|
-
private _onMessage;
|
|
48
|
-
_systems: Map<any, any>;
|
|
1
|
+
import { DefaultStats } from './stats.js';
|
|
2
|
+
import type { ComponentMetricsUpdate, Metrics, Stats, TrackStreamOptions } from '@libp2p/interfaces/metrics';
|
|
3
|
+
import type { PeerId } from '@libp2p/interfaces/peer-id';
|
|
4
|
+
import type { Startable } from '@libp2p/interfaces';
|
|
5
|
+
import type { Duplex } from 'it-stream-types';
|
|
6
|
+
export interface OnMessageOptions {
|
|
7
|
+
remotePeer: PeerId;
|
|
8
|
+
protocol?: string;
|
|
9
|
+
direction: 'in' | 'out';
|
|
10
|
+
dataLength: number;
|
|
11
|
+
}
|
|
12
|
+
export interface MetricsInit {
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
computeThrottleMaxQueueSize: number;
|
|
15
|
+
computeThrottleTimeout: number;
|
|
16
|
+
movingAverageIntervals: number[];
|
|
17
|
+
maxOldPeersRetention: number;
|
|
18
|
+
}
|
|
19
|
+
export declare class DefaultMetrics implements Metrics, Startable {
|
|
20
|
+
globalStats: DefaultStats;
|
|
21
|
+
private readonly enabled;
|
|
22
|
+
private readonly peerStats;
|
|
23
|
+
private readonly protocolStats;
|
|
24
|
+
private readonly oldPeers;
|
|
25
|
+
private running;
|
|
26
|
+
private readonly systems;
|
|
27
|
+
private readonly statsInit;
|
|
28
|
+
constructor(init: MetricsInit);
|
|
29
|
+
isStarted(): boolean;
|
|
49
30
|
/**
|
|
50
31
|
* Must be called for stats to saved. Any data pushed for tracking
|
|
51
32
|
* will be ignored.
|
|
52
33
|
*/
|
|
53
|
-
start(): void
|
|
34
|
+
start(): Promise<void>;
|
|
54
35
|
/**
|
|
55
36
|
* Stops all averages timers and prevents new data from being tracked.
|
|
56
37
|
* Once `stop` is called, `start` must be called to resume stats tracking.
|
|
57
38
|
*/
|
|
58
|
-
stop(): void
|
|
39
|
+
stop(): Promise<void>;
|
|
59
40
|
/**
|
|
60
41
|
* Gets the global `Stats` object
|
|
61
|
-
*
|
|
62
|
-
* @returns {Stats}
|
|
63
42
|
*/
|
|
64
|
-
|
|
43
|
+
getGlobal(): DefaultStats;
|
|
65
44
|
/**
|
|
66
45
|
* Returns a list of `PeerId` strings currently being tracked
|
|
67
|
-
*
|
|
68
|
-
* @returns {string[]}
|
|
69
46
|
*/
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
*/
|
|
74
|
-
getComponentMetrics(): Map<string, Map<string, Map<string, any>>>;
|
|
75
|
-
updateComponentMetric({ system, component, metric, value }: {
|
|
76
|
-
system?: string | undefined;
|
|
77
|
-
component: any;
|
|
78
|
-
metric: any;
|
|
79
|
-
value: any;
|
|
80
|
-
}): void;
|
|
47
|
+
getPeers(): string[];
|
|
48
|
+
getComponentMetrics(): Map<string, Map<string, Map<string, number>>>;
|
|
49
|
+
updateComponentMetric(update: ComponentMetricsUpdate): void;
|
|
81
50
|
/**
|
|
82
51
|
* Returns the `Stats` object for the given `PeerId` whether it
|
|
83
52
|
* is a live peer, or in the disconnected peer LRU cache.
|
|
84
|
-
*
|
|
85
|
-
* @param {PeerId} peerId
|
|
86
|
-
* @returns {Stats}
|
|
87
53
|
*/
|
|
88
|
-
forPeer(peerId: PeerId): Stats;
|
|
54
|
+
forPeer(peerId: PeerId): Stats | undefined;
|
|
89
55
|
/**
|
|
90
|
-
* Returns a list of all protocol strings currently being tracked
|
|
91
|
-
*
|
|
92
|
-
* @returns {string[]}
|
|
56
|
+
* Returns a list of all protocol strings currently being tracked
|
|
93
57
|
*/
|
|
94
|
-
|
|
58
|
+
getProtocols(): string[];
|
|
95
59
|
/**
|
|
96
|
-
* Returns the `Stats` object for the given `protocol
|
|
97
|
-
*
|
|
98
|
-
* @param {string} protocol
|
|
99
|
-
* @returns {Stats}
|
|
60
|
+
* Returns the `Stats` object for the given `protocol`
|
|
100
61
|
*/
|
|
101
|
-
forProtocol(protocol: string): Stats;
|
|
62
|
+
forProtocol(protocol: string): Stats | undefined;
|
|
102
63
|
/**
|
|
103
64
|
* Should be called when all connections to a given peer
|
|
104
65
|
* have closed. The `Stats` collection for the peer will
|
|
105
66
|
* be stopped and moved to an LRU for temporary retention.
|
|
106
|
-
*
|
|
107
|
-
* @param {PeerId} peerId
|
|
108
67
|
*/
|
|
109
68
|
onPeerDisconnected(peerId: PeerId): void;
|
|
69
|
+
/**
|
|
70
|
+
* Takes the metadata for a message and tracks it in the
|
|
71
|
+
* appropriate categories. If the protocol is present, protocol
|
|
72
|
+
* stats will also be tracked.
|
|
73
|
+
*/
|
|
74
|
+
_onMessage(opts: OnMessageOptions): void;
|
|
110
75
|
/**
|
|
111
76
|
* Replaces the `PeerId` string with the given `peerId`.
|
|
112
77
|
* If stats are already being tracked for the given `peerId`, the
|
|
@@ -123,29 +88,7 @@ declare class Metrics {
|
|
|
123
88
|
* returned. This allows lazy tracking of a peer when the peer is not yet known.
|
|
124
89
|
* When the `PeerId` is known, `Metrics.updatePlaceholder` should be called
|
|
125
90
|
* with the placeholder string returned from here, and the known `PeerId`.
|
|
126
|
-
*
|
|
127
|
-
* @param {Object} options
|
|
128
|
-
* @param {MultiaddrConnection} options.stream - A duplex iterable stream
|
|
129
|
-
* @param {PeerId} [options.remotePeer] - The id of the remote peer that's connected
|
|
130
|
-
* @param {string} [options.protocol] - The protocol the stream is running
|
|
131
|
-
* @returns {MultiaddrConnection} The peerId string or placeholder string
|
|
132
91
|
*/
|
|
133
|
-
trackStream
|
|
134
|
-
stream: MultiaddrConnection;
|
|
135
|
-
remotePeer?: import("peer-id") | undefined;
|
|
136
|
-
protocol?: string | undefined;
|
|
137
|
-
}): MultiaddrConnection;
|
|
138
|
-
}
|
|
139
|
-
declare namespace Metrics {
|
|
140
|
-
export { PeerId, MultiaddrConnection, MetricsOptions };
|
|
92
|
+
trackStream<T extends Duplex<Uint8Array>>(opts: TrackStreamOptions<T>): T;
|
|
141
93
|
}
|
|
142
|
-
import Stats = require("./stats");
|
|
143
|
-
type PeerId = import('peer-id');
|
|
144
|
-
type MultiaddrConnection = import('libp2p-interfaces/src/transport/types').MultiaddrConnection;
|
|
145
|
-
type MetricsOptions = {
|
|
146
|
-
computeThrottleMaxQueueSize?: number | undefined;
|
|
147
|
-
computeThrottleTimeout?: number | undefined;
|
|
148
|
-
movingAverageIntervals?: number[] | undefined;
|
|
149
|
-
maxOldPeersRetention?: number | undefined;
|
|
150
|
-
};
|
|
151
94
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/metrics/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/metrics/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,YAAY,EAAa,MAAM,YAAY,CAAA;AACpD,OAAO,KAAK,EAAE,sBAAsB,EAAE,OAAO,EAAE,KAAK,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAA;AAC5G,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAA;AACxD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;AAY7C,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,MAAM,CAAA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E,MAAM,EAAE,MAAM,EAAE,MAAM;IAwBtD;;;;;;OAMG;IACH,WAAW,CAAE,CAAC,SAAS,MAAM,CAAC,UAAU,CAAC,EAAG,IAAI,EAAE,kBAAkB,CAAC,CAAC,CAAC,GAAG,CAAC;CAiC5E"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { pipe } from 'it-pipe';
|
|
2
|
+
import each from 'it-foreach';
|
|
3
|
+
import LRU from 'hashlru';
|
|
4
|
+
import { METRICS as defaultOptions } from '../constants.js';
|
|
5
|
+
import { DefaultStats } from './stats.js';
|
|
6
|
+
const initialCounters = [
|
|
7
|
+
'dataReceived',
|
|
8
|
+
'dataSent'
|
|
9
|
+
];
|
|
10
|
+
const directionToEvent = {
|
|
11
|
+
in: 'dataReceived',
|
|
12
|
+
out: 'dataSent'
|
|
13
|
+
};
|
|
14
|
+
export class DefaultMetrics {
|
|
15
|
+
constructor(init) {
|
|
16
|
+
this.enabled = init.enabled;
|
|
17
|
+
this.statsInit = {
|
|
18
|
+
...init,
|
|
19
|
+
initialCounters
|
|
20
|
+
};
|
|
21
|
+
this.globalStats = new DefaultStats(this.statsInit);
|
|
22
|
+
this.peerStats = new Map();
|
|
23
|
+
this.protocolStats = new Map();
|
|
24
|
+
this.oldPeers = LRU(init.maxOldPeersRetention ?? defaultOptions.maxOldPeersRetention);
|
|
25
|
+
this.running = false;
|
|
26
|
+
this._onMessage = this._onMessage.bind(this);
|
|
27
|
+
this.systems = new Map();
|
|
28
|
+
}
|
|
29
|
+
isStarted() {
|
|
30
|
+
return this.running;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Must be called for stats to saved. Any data pushed for tracking
|
|
34
|
+
* will be ignored.
|
|
35
|
+
*/
|
|
36
|
+
async start() {
|
|
37
|
+
if (!this.enabled) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
this.running = true;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Stops all averages timers and prevents new data from being tracked.
|
|
44
|
+
* Once `stop` is called, `start` must be called to resume stats tracking.
|
|
45
|
+
*/
|
|
46
|
+
async stop() {
|
|
47
|
+
if (!this.running) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.running = false;
|
|
51
|
+
this.globalStats.stop();
|
|
52
|
+
for (const stats of this.peerStats.values()) {
|
|
53
|
+
stats.stop();
|
|
54
|
+
}
|
|
55
|
+
for (const stats of this.protocolStats.values()) {
|
|
56
|
+
stats.stop();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Gets the global `Stats` object
|
|
61
|
+
*/
|
|
62
|
+
getGlobal() {
|
|
63
|
+
return this.globalStats;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns a list of `PeerId` strings currently being tracked
|
|
67
|
+
*/
|
|
68
|
+
getPeers() {
|
|
69
|
+
return Array.from(this.peerStats.keys());
|
|
70
|
+
}
|
|
71
|
+
getComponentMetrics() {
|
|
72
|
+
return this.systems;
|
|
73
|
+
}
|
|
74
|
+
updateComponentMetric(update) {
|
|
75
|
+
const { system = 'libp2p', component, metric, value } = update;
|
|
76
|
+
if (!this.systems.has(system)) {
|
|
77
|
+
this.systems.set(system, new Map());
|
|
78
|
+
}
|
|
79
|
+
const systemMetrics = this.systems.get(system);
|
|
80
|
+
if (systemMetrics == null) {
|
|
81
|
+
throw new Error('Unknown metric system');
|
|
82
|
+
}
|
|
83
|
+
if (!systemMetrics.has(component)) {
|
|
84
|
+
systemMetrics.set(component, new Map());
|
|
85
|
+
}
|
|
86
|
+
const componentMetrics = systemMetrics.get(component);
|
|
87
|
+
if (componentMetrics == null) {
|
|
88
|
+
throw new Error('Unknown metric component');
|
|
89
|
+
}
|
|
90
|
+
componentMetrics.set(metric, value);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Returns the `Stats` object for the given `PeerId` whether it
|
|
94
|
+
* is a live peer, or in the disconnected peer LRU cache.
|
|
95
|
+
*/
|
|
96
|
+
forPeer(peerId) {
|
|
97
|
+
const idString = peerId.toString();
|
|
98
|
+
return this.peerStats.get(idString) ?? this.oldPeers.get(idString);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Returns a list of all protocol strings currently being tracked
|
|
102
|
+
*/
|
|
103
|
+
getProtocols() {
|
|
104
|
+
return Array.from(this.protocolStats.keys());
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Returns the `Stats` object for the given `protocol`
|
|
108
|
+
*/
|
|
109
|
+
forProtocol(protocol) {
|
|
110
|
+
return this.protocolStats.get(protocol);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Should be called when all connections to a given peer
|
|
114
|
+
* have closed. The `Stats` collection for the peer will
|
|
115
|
+
* be stopped and moved to an LRU for temporary retention.
|
|
116
|
+
*/
|
|
117
|
+
onPeerDisconnected(peerId) {
|
|
118
|
+
const idString = peerId.toString();
|
|
119
|
+
const peerStats = this.peerStats.get(idString);
|
|
120
|
+
if (peerStats != null) {
|
|
121
|
+
peerStats.stop();
|
|
122
|
+
this.peerStats.delete(idString);
|
|
123
|
+
this.oldPeers.set(idString, peerStats);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Takes the metadata for a message and tracks it in the
|
|
128
|
+
* appropriate categories. If the protocol is present, protocol
|
|
129
|
+
* stats will also be tracked.
|
|
130
|
+
*/
|
|
131
|
+
_onMessage(opts) {
|
|
132
|
+
if (!this.running) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const { remotePeer, protocol, direction, dataLength } = opts;
|
|
136
|
+
const key = directionToEvent[direction];
|
|
137
|
+
let peerStats = this.forPeer(remotePeer);
|
|
138
|
+
if (peerStats == null) {
|
|
139
|
+
const stats = new DefaultStats(this.statsInit);
|
|
140
|
+
this.peerStats.set(remotePeer.toString(), stats);
|
|
141
|
+
peerStats = stats;
|
|
142
|
+
}
|
|
143
|
+
// Peer and global stats
|
|
144
|
+
peerStats.push(key, dataLength);
|
|
145
|
+
this.globalStats.push(key, dataLength);
|
|
146
|
+
// Protocol specific stats
|
|
147
|
+
if (protocol != null) {
|
|
148
|
+
let protocolStats = this.forProtocol(protocol);
|
|
149
|
+
if (protocolStats == null) {
|
|
150
|
+
const stats = new DefaultStats(this.statsInit);
|
|
151
|
+
this.protocolStats.set(protocol, stats);
|
|
152
|
+
protocolStats = stats;
|
|
153
|
+
}
|
|
154
|
+
protocolStats.push(key, dataLength);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Replaces the `PeerId` string with the given `peerId`.
|
|
159
|
+
* If stats are already being tracked for the given `peerId`, the
|
|
160
|
+
* placeholder stats will be merged with the existing stats.
|
|
161
|
+
*
|
|
162
|
+
* @param {PeerId} placeholder - A peerId string
|
|
163
|
+
* @param {PeerId} peerId
|
|
164
|
+
* @returns {void}
|
|
165
|
+
*/
|
|
166
|
+
updatePlaceholder(placeholder, peerId) {
|
|
167
|
+
if (!this.running) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
const placeholderString = placeholder.toString();
|
|
171
|
+
const placeholderStats = this.peerStats.get(placeholderString) ?? this.oldPeers.get(placeholderString);
|
|
172
|
+
const peerIdString = peerId.toString();
|
|
173
|
+
const existingStats = this.peerStats.get(peerIdString) ?? this.oldPeers.get(peerIdString);
|
|
174
|
+
let mergedStats = placeholderStats;
|
|
175
|
+
// If we already have stats, merge the two
|
|
176
|
+
if (existingStats != null) {
|
|
177
|
+
// If existing, merge
|
|
178
|
+
mergedStats = mergeStats(existingStats, mergedStats);
|
|
179
|
+
// Attempt to delete from the old peers list just in case it was tracked there
|
|
180
|
+
this.oldPeers.remove(peerIdString);
|
|
181
|
+
}
|
|
182
|
+
this.peerStats.delete(placeholder.toString());
|
|
183
|
+
this.peerStats.set(peerIdString, mergedStats);
|
|
184
|
+
mergedStats.start();
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Tracks data running through a given Duplex Iterable `stream`. If
|
|
188
|
+
* the `peerId` is not provided, a placeholder string will be created and
|
|
189
|
+
* returned. This allows lazy tracking of a peer when the peer is not yet known.
|
|
190
|
+
* When the `PeerId` is known, `Metrics.updatePlaceholder` should be called
|
|
191
|
+
* with the placeholder string returned from here, and the known `PeerId`.
|
|
192
|
+
*/
|
|
193
|
+
trackStream(opts) {
|
|
194
|
+
const { stream, remotePeer, protocol } = opts;
|
|
195
|
+
if (!this.running) {
|
|
196
|
+
return stream;
|
|
197
|
+
}
|
|
198
|
+
const source = stream.source;
|
|
199
|
+
stream.source = each(source, chunk => this._onMessage({
|
|
200
|
+
remotePeer,
|
|
201
|
+
protocol,
|
|
202
|
+
direction: 'in',
|
|
203
|
+
dataLength: chunk.length
|
|
204
|
+
}));
|
|
205
|
+
const sink = stream.sink;
|
|
206
|
+
stream.sink = async (source) => {
|
|
207
|
+
return await pipe(source, (source) => each(source, chunk => {
|
|
208
|
+
this._onMessage({
|
|
209
|
+
remotePeer,
|
|
210
|
+
protocol,
|
|
211
|
+
direction: 'out',
|
|
212
|
+
dataLength: chunk.length
|
|
213
|
+
});
|
|
214
|
+
}), sink);
|
|
215
|
+
};
|
|
216
|
+
return stream;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Merges `other` into `target`. `target` will be modified
|
|
221
|
+
* and returned
|
|
222
|
+
*/
|
|
223
|
+
function mergeStats(target, other) {
|
|
224
|
+
target.stop();
|
|
225
|
+
other.stop();
|
|
226
|
+
// Merge queues
|
|
227
|
+
target.queue = [...target.queue, ...other.queue];
|
|
228
|
+
// TODO: how to merge moving averages?
|
|
229
|
+
return target;
|
|
230
|
+
}
|
|
231
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/metrics/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE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AC,IAAI,GAAG,KAAK,EAAC,MAAM,EAAC,EAAE;YAC3B,OAAO,MAAM,IAAI,CACf,MAAM,EACN,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE;gBAC/B,IAAI,CAAC,UAAU,CAAC;oBACd,UAAU;oBACV,QAAQ;oBACR,SAAS,EAAE,KAAK;oBAChB,UAAU,EAAE,KAAK,CAAC,MAAM;iBACzB,CAAC,CAAA;YACJ,CAAC,CAAC,EACF,IAAI,CACL,CAAA;QACH,CAAC,CAAA;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACF;AAED;;;GAGG;AACH,SAAS,UAAU,CAAE,MAAoB,EAAE,KAAmB;IAC5D,MAAM,CAAC,IAAI,EAAE,CAAA;IACb,KAAK,CAAC,IAAI,EAAE,CAAA;IAEZ,eAAe;IACf,MAAM,CAAC,KAAK,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;IAEhD,sCAAsC;IACtC,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { MovingAverage } from '@libp2p/interfaces/metrics';
|
|
2
|
+
export declare class DefaultMovingAverage {
|
|
3
|
+
movingAverage: number;
|
|
4
|
+
variance: number;
|
|
5
|
+
deviation: number;
|
|
6
|
+
forecast: number;
|
|
7
|
+
private readonly timespan;
|
|
8
|
+
private previousTime?;
|
|
9
|
+
constructor(timespan: number);
|
|
10
|
+
alpha(t: number, pt: number): number;
|
|
11
|
+
push(time: number, value: number): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function createMovingAverage(timespan: number): MovingAverage;
|
|
14
|
+
//# sourceMappingURL=moving-average.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moving-average.d.ts","sourceRoot":"","sources":["../../../src/metrics/moving-average.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAE/D,qBAAa,oBAAoB;IACxB,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,YAAY,CAAC,CAAQ;gBAEhB,QAAQ,EAAE,MAAM;IAgB7B,KAAK,CAAE,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM;IAI5B,IAAI,CAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;CAkBlC;AAED,wBAAgB,mBAAmB,CAAE,QAAQ,EAAE,MAAM,GAAG,aAAa,CAEpE"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export class DefaultMovingAverage {
|
|
2
|
+
constructor(timespan) {
|
|
3
|
+
if (typeof timespan !== 'number') {
|
|
4
|
+
throw new Error('must provide a timespan to the moving average constructor');
|
|
5
|
+
}
|
|
6
|
+
if (timespan <= 0) {
|
|
7
|
+
throw new Error('must provide a timespan > 0 to the moving average constructor');
|
|
8
|
+
}
|
|
9
|
+
this.timespan = timespan;
|
|
10
|
+
this.movingAverage = 0;
|
|
11
|
+
this.variance = 0;
|
|
12
|
+
this.deviation = 0;
|
|
13
|
+
this.forecast = 0;
|
|
14
|
+
}
|
|
15
|
+
alpha(t, pt) {
|
|
16
|
+
return 1 - (Math.exp(-(t - pt) / this.timespan));
|
|
17
|
+
}
|
|
18
|
+
push(time, value) {
|
|
19
|
+
if (this.previousTime != null) {
|
|
20
|
+
// calculate moving average
|
|
21
|
+
const a = this.alpha(time, this.previousTime);
|
|
22
|
+
const diff = value - this.movingAverage;
|
|
23
|
+
const incr = a * diff;
|
|
24
|
+
this.movingAverage = a * value + (1 - a) * this.movingAverage;
|
|
25
|
+
// calculate variance & deviation
|
|
26
|
+
this.variance = (1 - a) * (this.variance + diff * incr);
|
|
27
|
+
this.deviation = Math.sqrt(this.variance);
|
|
28
|
+
// calculate forecast
|
|
29
|
+
this.forecast = this.movingAverage + a * diff;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
this.movingAverage = value;
|
|
33
|
+
}
|
|
34
|
+
this.previousTime = time;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
export function createMovingAverage(timespan) {
|
|
38
|
+
return new DefaultMovingAverage(timespan);
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=moving-average.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"moving-average.js","sourceRoot":"","sources":["../../../src/metrics/moving-average.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,oBAAoB;IAQ/B,YAAa,QAAgB;QAC3B,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;YAChC,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;SAC7E;QAED,IAAI,QAAQ,IAAI,CAAC,EAAE;YACjB,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAA;SACjF;QAED,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,aAAa,GAAG,CAAC,CAAA;QACtB,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAA;QACjB,IAAI,CAAC,SAAS,GAAG,CAAC,CAAA;QAClB,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAA;IACnB,CAAC;IAED,KAAK,CAAE,CAAS,EAAE,EAAU;QAC1B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAA;IAClD,CAAC;IAED,IAAI,CAAE,IAAY,EAAE,KAAa;QAC/B,IAAI,IAAI,CAAC,YAAY,IAAI,IAAI,EAAE;YAC7B,2BAA2B;YAC3B,MAAM,CAAC,GAAG,IAAI,CAA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