mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-17 17:41:57 +00:00
Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
bbdd559a02 | ||
|
4070dcdf55 | ||
|
cb0d7d6c99 | ||
|
d1c48dcbed | ||
|
c4a442788b | ||
|
70a4bb9451 | ||
|
a0516ebc85 | ||
|
b425fa1230 |
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@@ -19,7 +19,7 @@ jobs:
|
|||||||
- run: npx aegir lint
|
- run: npx aegir lint
|
||||||
- run: npx aegir build
|
- run: npx aegir build
|
||||||
- run: npx aegir dep-check
|
- run: npx aegir dep-check
|
||||||
- uses: ipfs/aegir/actions/bundle-size
|
- uses: ipfs/aegir/actions/bundle-size@master
|
||||||
name: size
|
name: size
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
20
CHANGELOG.md
20
CHANGELOG.md
@@ -1,3 +1,23 @@
|
|||||||
|
## [0.35.7](https://github.com/libp2p/js-libp2p/compare/v0.35.2...v0.35.7) (2021-12-24)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* add tracked map ([#1069](https://github.com/libp2p/js-libp2p/issues/1069)) ([b425fa1](https://github.com/libp2p/js-libp2p/commit/b425fa12304def2a007d43a0aa445c28b766ed02))
|
||||||
|
* clean up pending dial targets ([#1059](https://github.com/libp2p/js-libp2p/issues/1059)) ([bdc9f16](https://github.com/libp2p/js-libp2p/commit/bdc9f16d0cbe56ccf26822f11068e7795bcef046))
|
||||||
|
* fix uncaught promise rejection when finding peers ([#1044](https://github.com/libp2p/js-libp2p/issues/1044)) ([3b683e7](https://github.com/libp2p/js-libp2p/commit/3b683e715686163e229b7b5c3a892327dfd4fc63))
|
||||||
|
* increase the maxlisteners for timeout controllers ([#1065](https://github.com/libp2p/js-libp2p/issues/1065)) ([09a0f94](https://github.com/libp2p/js-libp2p/commit/09a0f940df7fdb4ece34604e85693709df5c213e))
|
||||||
|
* main ci ([#1079](https://github.com/libp2p/js-libp2p/issues/1079)) ([d1c48dc](https://github.com/libp2p/js-libp2p/commit/d1c48dcbeded828f2dd3044cc9aed3f17f02846d))
|
||||||
|
* make error codes consistent ([#1054](https://github.com/libp2p/js-libp2p/issues/1054)) ([b25e0fe](https://github.com/libp2p/js-libp2p/commit/b25e0fe5312db58a06c39500ae84c50fed3a93bd))
|
||||||
|
* type definitions for big dialrequest and persistent peerstore ([#1078](https://github.com/libp2p/js-libp2p/issues/1078)) ([cb0d7d6](https://github.com/libp2p/js-libp2p/commit/cb0d7d6c99d179498f04e76df76e70e4f7d41c4c))
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* allow per-component metrics to be collected ([#1061](https://github.com/libp2p/js-libp2p/issues/1061)) ([2f0b311](https://github.com/libp2p/js-libp2p/commit/2f0b311df7127aa44512c2008142d4ca30268986)), closes [#1060](https://github.com/libp2p/js-libp2p/issues/1060)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## [0.35.6](https://github.com/libp2p/js-libp2p/compare/v0.35.5...v0.35.6) (2021-12-18)
|
## [0.35.6](https://github.com/libp2p/js-libp2p/compare/v0.35.5...v0.35.6) (2021-12-18)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -23,8 +23,8 @@
|
|||||||
<a href="https://david-dm.org/libp2p/js-libp2p"><img src="https://david-dm.org/libp2p/js-libp2p.svg?style=flat-square" /></a>
|
<a href="https://david-dm.org/libp2p/js-libp2p"><img src="https://david-dm.org/libp2p/js-libp2p.svg?style=flat-square" /></a>
|
||||||
<a href="https://github.com/feross/standard"><img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square"></a>
|
<a href="https://github.com/feross/standard"><img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square"></a>
|
||||||
<a href="https://github.com/RichardLitt/standard-readme"><img src="https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square" /></a>
|
<a href="https://github.com/RichardLitt/standard-readme"><img src="https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square" /></a>
|
||||||
<a href=""><img src="https://img.shields.io/badge/npm-%3E%3D6.0.0-orange.svg?style=flat-square" /></a>
|
<a href=""><img src="https://img.shields.io/badge/npm-%3E%3D7.0.0-orange.svg?style=flat-square" /></a>
|
||||||
<a href=""><img src="https://img.shields.io/badge/Node.js-%3E%3D12.0.0-orange.svg?style=flat-square" /></a>
|
<a href=""><img src="https://img.shields.io/badge/Node.js-%3E%3D15.0.0-orange.svg?style=flat-square" /></a>
|
||||||
<br>
|
<br>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@@ -675,15 +675,15 @@ const { NOISE } = require('libp2p-noise')
|
|||||||
const LevelDatastore = require('datastore-level')
|
const LevelDatastore = require('datastore-level')
|
||||||
|
|
||||||
const datastore = new LevelDatastore('path/to/store')
|
const datastore = new LevelDatastore('path/to/store')
|
||||||
const dsInstant = await datastore.open()
|
await datastore.open() // level database must be ready before node boot
|
||||||
|
|
||||||
const node = await Libp2p.create({
|
const node = await Libp2p.create({
|
||||||
|
datastore, // pass the opened datastore
|
||||||
modules: {
|
modules: {
|
||||||
transport: [TCP],
|
transport: [TCP],
|
||||||
streamMuxer: [MPLEX],
|
streamMuxer: [MPLEX],
|
||||||
connEncryption: [NOISE]
|
connEncryption: [NOISE]
|
||||||
},
|
},
|
||||||
datastore: dsInstant,
|
|
||||||
peerStore: {
|
peerStore: {
|
||||||
persistence: true,
|
persistence: true,
|
||||||
threshold: 5
|
threshold: 5
|
||||||
@@ -806,8 +806,8 @@ protocols: [
|
|||||||
|
|
||||||
As libp2p is designed to be a modular networking library, its usage will vary based on individual project needs. We've included links to some existing project configurations for your reference, in case you wish to replicate their configuration:
|
As libp2p is designed to be a modular networking library, its usage will vary based on individual project needs. We've included links to some existing project configurations for your reference, in case you wish to replicate their configuration:
|
||||||
|
|
||||||
- [libp2p-ipfs-nodejs](https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs/src/core/runtime/libp2p-nodejs.js) - libp2p configuration used by js-ipfs when running in Node.js
|
- [libp2p-ipfs-nodejs](https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-core-config/src/libp2p.js) - libp2p configuration used by js-ipfs when running in Node.js
|
||||||
- [libp2p-ipfs-browser](https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs/src/core/runtime/libp2p-browser.js) - libp2p configuration used by js-ipfs when running in a Browser (that supports WebRTC)
|
- [libp2p-ipfs-browser](https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-core-config/src/libp2p.browser.js) - libp2p configuration used by js-ipfs when running in a Browser (that supports WebRTC)
|
||||||
|
|
||||||
If you have developed a project using `js-libp2p`, please consider submitting your configuration to this list so that it can be found easily by other users.
|
If you have developed a project using `js-libp2p`, please consider submitting your configuration to this list so that it can be found easily by other users.
|
||||||
|
|
||||||
|
19
package.json
19
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "libp2p",
|
"name": "libp2p",
|
||||||
"version": "0.35.6",
|
"version": "0.35.7",
|
||||||
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
||||||
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
@@ -181,9 +181,9 @@
|
|||||||
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
|
||||||
"Maciej Krüger <mkg20001@gmail.com>",
|
"Maciej Krüger <mkg20001@gmail.com>",
|
||||||
"Hugo Dias <mail@hugodias.me>",
|
"Hugo Dias <mail@hugodias.me>",
|
||||||
"dirkmc <dirkmdev@gmail.com>",
|
|
||||||
"Chris Dostert <chrisdostert@users.noreply.github.com>",
|
|
||||||
"Volker Mische <volker.mische@gmail.com>",
|
"Volker Mische <volker.mische@gmail.com>",
|
||||||
|
"Chris Dostert <chrisdostert@users.noreply.github.com>",
|
||||||
|
"dirkmc <dirkmdev@gmail.com>",
|
||||||
"Robert Kiel <robert.kiel@hoprnet.org>",
|
"Robert Kiel <robert.kiel@hoprnet.org>",
|
||||||
"Richard Littauer <richard.littauer@gmail.com>",
|
"Richard Littauer <richard.littauer@gmail.com>",
|
||||||
"zeim839 <50573884+zeim839@users.noreply.github.com>",
|
"zeim839 <50573884+zeim839@users.noreply.github.com>",
|
||||||
@@ -193,22 +193,23 @@
|
|||||||
"Andrew Nesbitt <andrewnez@gmail.com>",
|
"Andrew Nesbitt <andrewnez@gmail.com>",
|
||||||
"Franck Royer <franck@royer.one>",
|
"Franck Royer <franck@royer.one>",
|
||||||
"Thomas Eizinger <thomas@eizinger.io>",
|
"Thomas Eizinger <thomas@eizinger.io>",
|
||||||
|
"Vít Habada <vithabada93@gmail.com>",
|
||||||
"Giovanni T. Parra <fiatjaf@gmail.com>",
|
"Giovanni T. Parra <fiatjaf@gmail.com>",
|
||||||
"acolytec3 <17355484+acolytec3@users.noreply.github.com>",
|
"acolytec3 <17355484+acolytec3@users.noreply.github.com>",
|
||||||
"Alan Smithee <ggnore.alan.smithee@gmail.com>",
|
"Alan Smithee <ggnore.alan.smithee@gmail.com>",
|
||||||
"Elven <mon.samuel@qq.com>",
|
"Elven <mon.samuel@qq.com>",
|
||||||
"Samlior <samlior@foxmail.com>",
|
"Samlior <samlior@foxmail.com>",
|
||||||
"Didrik Nordström <didrik.nordstrom@gmail.com>",
|
"Didrik Nordström <didrik.nordstrom@gmail.com>",
|
||||||
"Soeren <nikorpoulsen@gmail.com>",
|
"Aditya Bose <13054902+adbose@users.noreply.github.com>",
|
||||||
"Sönke Hahn <soenkehahn@gmail.com>",
|
|
||||||
"TJKoury <TJKoury@gmail.com>",
|
"TJKoury <TJKoury@gmail.com>",
|
||||||
"TheStarBoys <41286328+TheStarBoys@users.noreply.github.com>",
|
"TheStarBoys <41286328+TheStarBoys@users.noreply.github.com>",
|
||||||
"Tiago Alves <alvesjtiago@gmail.com>",
|
"Tiago Alves <alvesjtiago@gmail.com>",
|
||||||
|
"Tim Daubenschütz <tim@daubenschuetz.de>",
|
||||||
"XiaoZhang <zxinmyth@gmail.com>",
|
"XiaoZhang <zxinmyth@gmail.com>",
|
||||||
"Yusef Napora <yusef@napora.org>",
|
"Yusef Napora <yusef@napora.org>",
|
||||||
"Zane Starr <zcstarr@gmail.com>",
|
"Zane Starr <zcstarr@gmail.com>",
|
||||||
"ebinks <elizabethjbinks@gmail.com>",
|
"ebinks <elizabethjbinks@gmail.com>",
|
||||||
"Aditya Bose <13054902+adbose@users.noreply.github.com>",
|
"greenSnot <greenSnot@users.noreply.github.com>",
|
||||||
"isan_rivkin <isanrivkin@gmail.com>",
|
"isan_rivkin <isanrivkin@gmail.com>",
|
||||||
"mayerwin <mayerwin@users.noreply.github.com>",
|
"mayerwin <mayerwin@users.noreply.github.com>",
|
||||||
"mcclure <andi.m.mcclure@gmail.com>",
|
"mcclure <andi.m.mcclure@gmail.com>",
|
||||||
@@ -217,7 +218,8 @@
|
|||||||
"robertkiel <robert.kiel@validitylabs.org>",
|
"robertkiel <robert.kiel@validitylabs.org>",
|
||||||
"shresthagrawal <34920931+shresthagrawal@users.noreply.github.com>",
|
"shresthagrawal <34920931+shresthagrawal@users.noreply.github.com>",
|
||||||
"swedneck <40505480+swedneck@users.noreply.github.com>",
|
"swedneck <40505480+swedneck@users.noreply.github.com>",
|
||||||
"greenSnot <greenSnot@users.noreply.github.com>",
|
"tuyennhv <vutuyen2636@gmail.com>",
|
||||||
|
"Sönke Hahn <soenkehahn@gmail.com>",
|
||||||
"Aleksei <vozhdb@gmail.com>",
|
"Aleksei <vozhdb@gmail.com>",
|
||||||
"Bernd Strehl <bernd.strehl@gmail.com>",
|
"Bernd Strehl <bernd.strehl@gmail.com>",
|
||||||
"Chris Bratlien <chrisbratlien@gmail.com>",
|
"Chris Bratlien <chrisbratlien@gmail.com>",
|
||||||
@@ -248,6 +250,7 @@
|
|||||||
"Nuno Nogueira <nunofmn@gmail.com>",
|
"Nuno Nogueira <nunofmn@gmail.com>",
|
||||||
"Philipp Muens <raute1337@gmx.de>",
|
"Philipp Muens <raute1337@gmx.de>",
|
||||||
"RasmusErik Voel Jensen <github@solsort.com>",
|
"RasmusErik Voel Jensen <github@solsort.com>",
|
||||||
"Smite Chow <xiaopengyou@live.com>"
|
"Smite Chow <xiaopengyou@live.com>",
|
||||||
|
"Soeren <nikorpoulsen@gmail.com>"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ const LatencyMonitor = require('./latency-monitor')
|
|||||||
const retimer = require('retimer')
|
const retimer = require('retimer')
|
||||||
|
|
||||||
const { EventEmitter } = require('events')
|
const { EventEmitter } = require('events')
|
||||||
|
const trackedMap = require('../metrics/tracked-map')
|
||||||
const PeerId = require('peer-id')
|
const PeerId = require('peer-id')
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -34,7 +34,7 @@ const defaultOptions = {
|
|||||||
|
|
||||||
const METRICS_COMPONENT = 'connection-manager'
|
const METRICS_COMPONENT = 'connection-manager'
|
||||||
const METRICS_PEER_CONNECTIONS = 'peer-connections'
|
const METRICS_PEER_CONNECTIONS = 'peer-connections'
|
||||||
const METRICS_ALL_CONNECTIONS = 'all-connections'
|
const METRICS_PEER_VALUES = 'peer-values'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('../')} Libp2p
|
* @typedef {import('../')} Libp2p
|
||||||
@@ -87,14 +87,14 @@ class ConnectionManager extends EventEmitter {
|
|||||||
*
|
*
|
||||||
* @type {Map<string, number>}
|
* @type {Map<string, number>}
|
||||||
*/
|
*/
|
||||||
this._peerValues = new Map()
|
this._peerValues = trackedMap(METRICS_COMPONENT, METRICS_PEER_VALUES, this._libp2p.metrics)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Map of connections per peer
|
* Map of connections per peer
|
||||||
*
|
*
|
||||||
* @type {Map<string, Connection[]>}
|
* @type {Map<string, Connection[]>}
|
||||||
*/
|
*/
|
||||||
this.connections = new Map()
|
this.connections = trackedMap(METRICS_COMPONENT, METRICS_PEER_CONNECTIONS, this._libp2p.metrics)
|
||||||
|
|
||||||
this._started = false
|
this._started = false
|
||||||
this._timer = null
|
this._timer = null
|
||||||
@@ -164,8 +164,6 @@ class ConnectionManager extends EventEmitter {
|
|||||||
|
|
||||||
await Promise.all(tasks)
|
await Promise.all(tasks)
|
||||||
this.connections.clear()
|
this.connections.clear()
|
||||||
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PEER_CONNECTIONS, 0)
|
|
||||||
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_ALL_CONNECTIONS, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -222,8 +220,6 @@ class ConnectionManager extends EventEmitter {
|
|||||||
storedConn.push(connection)
|
storedConn.push(connection)
|
||||||
} else {
|
} else {
|
||||||
this.connections.set(peerIdStr, [connection])
|
this.connections.set(peerIdStr, [connection])
|
||||||
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PEER_CONNECTIONS, this.connections.size)
|
|
||||||
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_ALL_CONNECTIONS, this.size)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this._libp2p.peerStore.keyBook.set(peerId, peerId.pubKey)
|
this._libp2p.peerStore.keyBook.set(peerId, peerId.pubKey)
|
||||||
@@ -255,9 +251,6 @@ class ConnectionManager extends EventEmitter {
|
|||||||
|
|
||||||
this._libp2p.metrics && this._libp2p.metrics.onPeerDisconnected(connection.remotePeer)
|
this._libp2p.metrics && this._libp2p.metrics.onPeerDisconnected(connection.remotePeer)
|
||||||
}
|
}
|
||||||
|
|
||||||
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PEER_CONNECTIONS, this.connections.size)
|
|
||||||
this._libp2p.metrics && this._libp2p.metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_ALL_CONNECTIONS, this.size)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -14,7 +14,7 @@ const { setMaxListeners } = require('events')
|
|||||||
const DialRequest = require('./dial-request')
|
const DialRequest = require('./dial-request')
|
||||||
const { publicAddressesFirst } = require('libp2p-utils/src/address-sort')
|
const { publicAddressesFirst } = require('libp2p-utils/src/address-sort')
|
||||||
const getPeer = require('../get-peer')
|
const getPeer = require('../get-peer')
|
||||||
|
const trackedMap = require('../metrics/tracked-map')
|
||||||
const { codes } = require('../errors')
|
const { codes } = require('../errors')
|
||||||
const {
|
const {
|
||||||
DIAL_TIMEOUT,
|
DIAL_TIMEOUT,
|
||||||
@@ -56,8 +56,8 @@ const METRICS_PENDING_DIAL_TARGETS = 'pending-dial-targets'
|
|||||||
* @property {Multiaddr[]} addrs
|
* @property {Multiaddr[]} addrs
|
||||||
*
|
*
|
||||||
* @typedef PendingDial
|
* @typedef PendingDial
|
||||||
* @property {DialRequest} dialRequest
|
* @property {import('./dial-request')} dialRequest
|
||||||
* @property {TimeoutController} controller
|
* @property {import('timeout-abort-controller').TimeoutController} controller
|
||||||
* @property {Promise<Connection>} promise
|
* @property {Promise<Connection>} promise
|
||||||
* @property {function():void} destroy
|
* @property {function():void} destroy
|
||||||
*/
|
*/
|
||||||
@@ -86,9 +86,12 @@ class Dialer {
|
|||||||
this.timeout = dialTimeout
|
this.timeout = dialTimeout
|
||||||
this.maxDialsPerPeer = maxDialsPerPeer
|
this.maxDialsPerPeer = maxDialsPerPeer
|
||||||
this.tokens = [...new Array(maxParallelDials)].map((_, index) => index)
|
this.tokens = [...new Array(maxParallelDials)].map((_, index) => index)
|
||||||
this._pendingDials = new Map()
|
|
||||||
this._pendingDialTargets = new Map()
|
/** @type {Map<string, PendingDial>} */
|
||||||
this._metrics = metrics
|
this._pendingDials = trackedMap(METRICS_COMPONENT, METRICS_PENDING_DIALS, metrics)
|
||||||
|
|
||||||
|
/** @type {Map<string, { resolve: (value: any) => void, reject: (err: Error) => void}>} */
|
||||||
|
this._pendingDialTargets = trackedMap(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, metrics)
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(resolvers)) {
|
for (const [key, value] of Object.entries(resolvers)) {
|
||||||
Multiaddr.resolvers.set(key, value)
|
Multiaddr.resolvers.set(key, value)
|
||||||
@@ -112,9 +115,6 @@ class Dialer {
|
|||||||
pendingTarget.reject(new AbortError('Dialer was destroyed'))
|
pendingTarget.reject(new AbortError('Dialer was destroyed'))
|
||||||
}
|
}
|
||||||
this._pendingDialTargets.clear()
|
this._pendingDialTargets.clear()
|
||||||
|
|
||||||
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIALS, 0)
|
|
||||||
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, 0)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -164,7 +164,6 @@ class Dialer {
|
|||||||
const id = `${(parseInt(String(Math.random() * 1e9), 10)).toString() + Date.now()}`
|
const id = `${(parseInt(String(Math.random() * 1e9), 10)).toString() + Date.now()}`
|
||||||
const cancellablePromise = new Promise((resolve, reject) => {
|
const cancellablePromise = new Promise((resolve, reject) => {
|
||||||
this._pendingDialTargets.set(id, { resolve, reject })
|
this._pendingDialTargets.set(id, { resolve, reject })
|
||||||
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, this._pendingDialTargets.size)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -176,7 +175,6 @@ class Dialer {
|
|||||||
return dialTarget
|
return dialTarget
|
||||||
} finally {
|
} finally {
|
||||||
this._pendingDialTargets.delete(id)
|
this._pendingDialTargets.delete(id)
|
||||||
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIAL_TARGETS, this._pendingDialTargets.size)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,13 +267,10 @@ class Dialer {
|
|||||||
destroy: () => {
|
destroy: () => {
|
||||||
timeoutController.clear()
|
timeoutController.clear()
|
||||||
this._pendingDials.delete(dialTarget.id)
|
this._pendingDials.delete(dialTarget.id)
|
||||||
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIALS, this._pendingDials.size)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._pendingDials.set(dialTarget.id, pendingDial)
|
this._pendingDials.set(dialTarget.id, pendingDial)
|
||||||
|
|
||||||
this._metrics && this._metrics.updateComponentMetric(METRICS_COMPONENT, METRICS_PENDING_DIALS, this._pendingDials.size)
|
|
||||||
|
|
||||||
return pendingDial
|
return pendingDial
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
src/index.js
22
src/index.js
@@ -48,6 +48,8 @@ const { updateSelfPeerRecord } = require('./record/utils')
|
|||||||
* @typedef {import('libp2p-interfaces/src/pubsub').PubsubOptions} PubsubOptions
|
* @typedef {import('libp2p-interfaces/src/pubsub').PubsubOptions} PubsubOptions
|
||||||
* @typedef {import('interface-datastore').Datastore} Datastore
|
* @typedef {import('interface-datastore').Datastore} Datastore
|
||||||
* @typedef {import('./pnet')} Protector
|
* @typedef {import('./pnet')} Protector
|
||||||
|
* @typedef {Object} PersistentPeerStoreOptions
|
||||||
|
* @property {number} [threshold]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -110,7 +112,7 @@ const { updateSelfPeerRecord } = require('./record/utils')
|
|||||||
* @property {KeychainOptions & import('./keychain/index').KeychainOptions} [keychain]
|
* @property {KeychainOptions & import('./keychain/index').KeychainOptions} [keychain]
|
||||||
* @property {MetricsOptions & import('./metrics').MetricsOptions} [metrics]
|
* @property {MetricsOptions & import('./metrics').MetricsOptions} [metrics]
|
||||||
* @property {import('./peer-routing').PeerRoutingOptions} [peerRouting]
|
* @property {import('./peer-routing').PeerRoutingOptions} [peerRouting]
|
||||||
* @property {PeerStoreOptions & import('./peer-store/persistent').PersistentPeerStoreOptions} [peerStore]
|
* @property {PeerStoreOptions & PersistentPeerStoreOptions} [peerStore]
|
||||||
* @property {import('./transport-manager').TransportManagerOptions} [transportManager]
|
* @property {import('./transport-manager').TransportManagerOptions} [transportManager]
|
||||||
* @property {Libp2pConfig} [config]
|
* @property {Libp2pConfig} [config]
|
||||||
*
|
*
|
||||||
@@ -161,6 +163,15 @@ class Libp2p extends EventEmitter {
|
|||||||
this.peerId = this._options.peerId
|
this.peerId = this._options.peerId
|
||||||
this.datastore = this._options.datastore
|
this.datastore = this._options.datastore
|
||||||
|
|
||||||
|
// Create Metrics
|
||||||
|
if (this._options.metrics.enabled) {
|
||||||
|
const metrics = new Metrics({
|
||||||
|
...this._options.metrics
|
||||||
|
})
|
||||||
|
|
||||||
|
this.metrics = metrics
|
||||||
|
}
|
||||||
|
|
||||||
this.peerStore = (this.datastore && this._options.peerStore.persistence)
|
this.peerStore = (this.datastore && this._options.peerStore.persistence)
|
||||||
? new PersistentPeerStore({
|
? new PersistentPeerStore({
|
||||||
peerId: this.peerId,
|
peerId: this.peerId,
|
||||||
@@ -195,15 +206,6 @@ class Libp2p extends EventEmitter {
|
|||||||
autoDialInterval: this._options.connectionManager.autoDialInterval
|
autoDialInterval: this._options.connectionManager.autoDialInterval
|
||||||
})
|
})
|
||||||
|
|
||||||
// Create Metrics
|
|
||||||
if (this._options.metrics.enabled) {
|
|
||||||
const metrics = new Metrics({
|
|
||||||
...this._options.metrics
|
|
||||||
})
|
|
||||||
|
|
||||||
this.metrics = metrics
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create keychain
|
// Create keychain
|
||||||
if (this._options.keychain && this._options.keychain.datastore) {
|
if (this._options.keychain && this._options.keychain.datastore) {
|
||||||
log('creating keychain')
|
log('creating keychain')
|
||||||
|
@@ -8,6 +8,7 @@ const retimer = require('retimer')
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {import('@vascosantos/moving-average').IMovingAverage} IMovingAverage
|
* @typedef {import('@vascosantos/moving-average').IMovingAverage} IMovingAverage
|
||||||
|
* @typedef {import('bignumber.js').BigNumber} Big
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Stats extends EventEmitter {
|
class Stats extends EventEmitter {
|
||||||
|
62
src/metrics/tracked-map.js
Normal file
62
src/metrics/tracked-map.js
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template K
|
||||||
|
* @template V
|
||||||
|
*/
|
||||||
|
class TrackedMap extends Map {
|
||||||
|
/**
|
||||||
|
* @param {string} component
|
||||||
|
* @param {string} name
|
||||||
|
* @param {import('.')} metrics
|
||||||
|
*/
|
||||||
|
constructor (component, name, metrics) {
|
||||||
|
super()
|
||||||
|
|
||||||
|
this._component = component
|
||||||
|
this._name = name
|
||||||
|
this._metrics = metrics
|
||||||
|
|
||||||
|
this._metrics.updateComponentMetric(this._component, this._name, this.size)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {K} key
|
||||||
|
* @param {V} value
|
||||||
|
*/
|
||||||
|
set (key, value) {
|
||||||
|
super.set(key, value)
|
||||||
|
this._metrics.updateComponentMetric(this._component, this._name, this.size)
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {K} key
|
||||||
|
*/
|
||||||
|
delete (key) {
|
||||||
|
const deleted = super.delete(key)
|
||||||
|
this._metrics.updateComponentMetric(this._component, this._name, this.size)
|
||||||
|
return deleted
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @template K
|
||||||
|
* @template V
|
||||||
|
* @param {string} component
|
||||||
|
* @param {string} name
|
||||||
|
* @param {import('.')} [metrics]
|
||||||
|
* @returns {Map<K, V>}
|
||||||
|
*/
|
||||||
|
module.exports = (component, name, metrics) => {
|
||||||
|
/** @type {Map<K, V>} */
|
||||||
|
let map
|
||||||
|
|
||||||
|
if (metrics) {
|
||||||
|
map = new TrackedMap(component, name, metrics)
|
||||||
|
} else {
|
||||||
|
map = new Map()
|
||||||
|
}
|
||||||
|
|
||||||
|
return map
|
||||||
|
}
|
Reference in New Issue
Block a user