mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-24 04:51:56 +00:00
Compare commits
1 Commits
v0.30.1
...
chore/use-
Author | SHA1 | Date | |
---|---|---|---|
|
3d2511db7b |
@@ -1,12 +1,3 @@
|
||||
## [0.30.1](https://github.com/libp2p/js-libp2p/compare/v0.30.0...v0.30.1) (2021-01-18)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* event emitter types with local types ([#864](https://github.com/libp2p/js-libp2p/issues/864)) ([6c41e30](https://github.com/libp2p/js-libp2p/commit/6c41e3045608bcae8061d20501be5751dad8157a))
|
||||
|
||||
|
||||
|
||||
# [0.30.0](https://github.com/libp2p/js-libp2p/compare/v0.29.4...v0.30.0) (2020-12-16)
|
||||
|
||||
|
||||
|
13
package.json
13
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "libp2p",
|
||||
"version": "0.30.1",
|
||||
"version": "0.30.0",
|
||||
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack",
|
||||
"leadMaintainer": "Jacob Heun <jacobheun@gmail.com>",
|
||||
"main": "src/index.js",
|
||||
@@ -58,6 +58,7 @@
|
||||
"cids": "^1.0.0",
|
||||
"class-is": "^1.1.0",
|
||||
"debug": "^4.1.1",
|
||||
"emittery": "^0.8.1",
|
||||
"err-code": "^2.0.0",
|
||||
"events": "^3.1.0",
|
||||
"hashlru": "^2.3.0",
|
||||
@@ -153,7 +154,7 @@
|
||||
"Thomas Eizinger <thomas@eizinger.io>",
|
||||
"ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com>",
|
||||
"Didrik Nordström <didrik@betamos.se>",
|
||||
"Fei Liu <liu.feiwood@gmail.com>",
|
||||
"Irakli Gozalishvili <rfobic@gmail.com>",
|
||||
"Ethan Lam <elmemphis2000@gmail.com>",
|
||||
"Joel Gustafson <joelg@mit.edu>",
|
||||
"Julien Bouquillon <contact@revolunet.com>",
|
||||
@@ -166,20 +167,20 @@
|
||||
"Smite Chow <xiaopengyou@live.com>",
|
||||
"Soeren <nikorpoulsen@gmail.com>",
|
||||
"Sönke Hahn <soenkehahn@gmail.com>",
|
||||
"robertkiel <robert.kiel@validitylabs.org>",
|
||||
"Tiago Alves <alvesjtiago@gmail.com>",
|
||||
"Daijiro Wachi <daijiro.wachi@gmail.com>",
|
||||
"Yusef Napora <yusef@napora.org>",
|
||||
"Zane Starr <zcstarr@gmail.com>",
|
||||
"robertkiel <robert.kiel@validitylabs.org>",
|
||||
"Cindy Wu <ciindy.wu@gmail.com>",
|
||||
"Chris Bratlien <chrisbratlien@gmail.com>",
|
||||
"ebinks <elizabethjbinks@gmail.com>",
|
||||
"Bernd Strehl <bernd.strehl@gmail.com>",
|
||||
"Florian-Merle <florian.david.merle@gmail.com>",
|
||||
"Francis Gulotta <wizard@roborooter.com>",
|
||||
"Felipe Martins <felipebrasil93@gmail.com>",
|
||||
"Bernd Strehl <bernd.strehl@gmail.com>",
|
||||
"Henrique Dias <hacdias@gmail.com>",
|
||||
"isan_rivkin <isanrivkin@gmail.com>",
|
||||
"Irakli Gozalishvili <rfobic@gmail.com>"
|
||||
"Henrique Dias <hacdias@gmail.com>",
|
||||
"Fei Liu <liu.feiwood@gmail.com>"
|
||||
]
|
||||
}
|
||||
|
@@ -10,9 +10,7 @@ const mergeOptions = require('merge-options')
|
||||
const LatencyMonitor = require('./latency-monitor')
|
||||
const retimer = require('retimer')
|
||||
|
||||
/** @typedef {import('../types').EventEmitterFactory} Events */
|
||||
/** @type Events */
|
||||
const EventEmitter = require('events')
|
||||
const Emittery = require('emittery')
|
||||
|
||||
const PeerId = require('peer-id')
|
||||
|
||||
@@ -58,7 +56,7 @@ const defaultOptions = {
|
||||
* @fires ConnectionManager#peer:connect Emitted when a new peer is connected.
|
||||
* @fires ConnectionManager#peer:disconnect Emitted when a peer is disconnected.
|
||||
*/
|
||||
class ConnectionManager extends EventEmitter {
|
||||
class ConnectionManager extends Emittery {
|
||||
/**
|
||||
* Responsible for managing known connections.
|
||||
*
|
||||
@@ -139,7 +137,7 @@ class ConnectionManager extends EventEmitter {
|
||||
async stop () {
|
||||
this._autoDialTimeout && this._autoDialTimeout.clear()
|
||||
this._timer && this._timer.clear()
|
||||
this._latencyMonitor && this._latencyMonitor.removeListener('data', this._onLatencyMeasure)
|
||||
this._latencyMonitor && this._latencyMonitor.off('data', this._onLatencyMeasure)
|
||||
|
||||
this._started = false
|
||||
await this._close()
|
||||
|
@@ -7,9 +7,7 @@
|
||||
|
||||
/* global window */
|
||||
const globalThis = require('ipfs-utils/src/globalthis')
|
||||
/** @typedef {import('../types').EventEmitterFactory} Events */
|
||||
/** @type Events */
|
||||
const EventEmitter = require('events')
|
||||
const Emittery = require('emittery')
|
||||
const VisibilityChangeEmitter = require('./visibility-change-emitter')
|
||||
const debug = require('debug')('latency-monitor:LatencyMonitor')
|
||||
|
||||
@@ -33,7 +31,7 @@ const debug = require('debug')('latency-monitor:LatencyMonitor')
|
||||
* the asyncTestFn and timing how long it takes the callback to be called. It can also periodically emit stats about this.
|
||||
* This can be disabled and stats can be pulled via setting dataEmitIntervalMs = 0.
|
||||
*
|
||||
* @extends {EventEmitter}
|
||||
* @extends {Emittery}
|
||||
*
|
||||
* The default implementation is an event loop latency monitor. This works by firing periodic events into the event loop
|
||||
* and timing how long it takes to get back.
|
||||
@@ -46,7 +44,7 @@ const debug = require('debug')('latency-monitor:LatencyMonitor')
|
||||
* const monitor = new LatencyMonitor({latencyCheckIntervalMs: 1000, dataEmitIntervalMs: 60000, asyncTestFn:ping});
|
||||
* monitor.on('data', (summary) => console.log('Ping Pong Latency: %O', summary));
|
||||
*/
|
||||
class LatencyMonitor extends EventEmitter {
|
||||
class LatencyMonitor extends Emittery {
|
||||
/**
|
||||
* @class
|
||||
* @param {LatencyMonitorOptions} [options]
|
||||
|
@@ -6,9 +6,7 @@
|
||||
*/
|
||||
'use strict'
|
||||
|
||||
/** @typedef {import('../types').EventEmitterFactory} Events */
|
||||
/** @type Events */
|
||||
const EventEmitter = require('events')
|
||||
const Emittery = require('emittery')
|
||||
|
||||
const debug = require('debug')('latency-monitor:VisibilityChangeEmitter')
|
||||
|
||||
@@ -34,7 +32,7 @@ const debug = require('debug')('latency-monitor:VisibilityChangeEmitter')
|
||||
* // To access the visibility state directly, call:
|
||||
* console.log('Am I focused now? ' + myVisibilityEmitter.isVisible());
|
||||
*/
|
||||
class VisibilityChangeEmitter extends EventEmitter {
|
||||
class VisibilityChangeEmitter extends Emittery {
|
||||
/**
|
||||
* Creates a VisibilityChangeEmitter
|
||||
*
|
||||
|
28
src/index.js
28
src/index.js
@@ -4,9 +4,7 @@ const debug = require('debug')
|
||||
const log = Object.assign(debug('libp2p'), {
|
||||
error: debug('libp2p:err')
|
||||
})
|
||||
/** @typedef {import('./types').EventEmitterFactory} Events */
|
||||
/** @type Events */
|
||||
const EventEmitter = require('events')
|
||||
const Emittery = require('emittery')
|
||||
const globalThis = require('ipfs-utils/src/globalthis')
|
||||
|
||||
const errCode = require('err-code')
|
||||
@@ -85,11 +83,11 @@ const IDENTIFY_PROTOCOLS = IdentifyService.multicodecs
|
||||
* @typedef {Object} CreateOptions
|
||||
* @property {PeerId} peerId
|
||||
*
|
||||
* @extends {EventEmitter}
|
||||
* @extends {Emittery}
|
||||
* @fires Libp2p#error Emitted when an error occurs
|
||||
* @fires Libp2p#peer:discovery Emitted when a peer is discovered
|
||||
*/
|
||||
class Libp2p extends EventEmitter {
|
||||
class Libp2p extends Emittery {
|
||||
/**
|
||||
* Like `new Libp2p(options)` except it will create a `PeerId`
|
||||
* instance if one is not provided in options.
|
||||
@@ -286,17 +284,19 @@ class Libp2p extends EventEmitter {
|
||||
*
|
||||
* @param {string} eventName
|
||||
* @param {...any} args
|
||||
* @returns {boolean}
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
emit (eventName, ...args) {
|
||||
// TODO: do we still need this?
|
||||
// @ts-ignore _events does not exist in libp2p
|
||||
if (eventName === 'error' && !this._events.error) {
|
||||
log.error(args)
|
||||
return false
|
||||
} else {
|
||||
return super.emit(eventName, ...args)
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
// TODO: do we still need this?
|
||||
// @ts-ignore _events does not exist in libp2p
|
||||
if (eventName === 'error' && !this._events.error) {
|
||||
log.error(args)
|
||||
resolve()
|
||||
} else {
|
||||
super.emit(eventName, args).then(resolve)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,14 +1,12 @@
|
||||
// @ts-nocheck
|
||||
'use strict'
|
||||
|
||||
/** @typedef {import('../types').EventEmitterFactory} Events */
|
||||
/** @type Events */
|
||||
const EventEmitter = require('events')
|
||||
const Emittery = require('emittery')
|
||||
const Big = require('bignumber.js')
|
||||
const MovingAverage = require('moving-average')
|
||||
const retimer = require('retimer')
|
||||
|
||||
class Stats extends EventEmitter {
|
||||
class Stats extends Emittery {
|
||||
/**
|
||||
* A queue based manager for stat processing
|
||||
*
|
||||
|
@@ -2,9 +2,7 @@
|
||||
|
||||
const errcode = require('err-code')
|
||||
|
||||
/** @typedef {import('../types').EventEmitterFactory} Events */
|
||||
/** @type Events */
|
||||
const EventEmitter = require('events')
|
||||
const Emittery = require('emittery')
|
||||
const PeerId = require('peer-id')
|
||||
|
||||
const AddressBook = require('./address-book')
|
||||
@@ -21,7 +19,7 @@ const {
|
||||
*/
|
||||
|
||||
/**
|
||||
* @extends {EventEmitter}
|
||||
* @extends {Emittery}
|
||||
*
|
||||
* @fires PeerStore#peer Emitted when a new peer is added.
|
||||
* @fires PeerStore#change:protocols Emitted when a known peer supports a different set of protocols.
|
||||
@@ -29,7 +27,7 @@ const {
|
||||
* @fires PeerStore#change:pubkey Emitted emitted when a peer's public key is known.
|
||||
* @fires PeerStore#change:metadata Emitted when the known metadata of a peer change.
|
||||
*/
|
||||
class PeerStore extends EventEmitter {
|
||||
class PeerStore extends Emittery {
|
||||
/**
|
||||
* Peer object
|
||||
*
|
||||
|
@@ -91,7 +91,7 @@ class PersistentPeerStore extends PeerStore {
|
||||
*/
|
||||
async stop () {
|
||||
log('PeerStore is stopping')
|
||||
this.removeAllListeners()
|
||||
this.clearListeners()
|
||||
await this._commitData()
|
||||
log('PeerStore stopped')
|
||||
}
|
||||
|
19
src/types.ts
19
src/types.ts
@@ -82,22 +82,3 @@ export type CircuitMessageProto = {
|
||||
CAN_HOP: CAN_HOP
|
||||
}
|
||||
}
|
||||
|
||||
export interface EventEmitterFactory {
|
||||
new(): EventEmitter;
|
||||
}
|
||||
|
||||
export interface EventEmitter {
|
||||
addListener(event: string | symbol, listener: (...args: any[]) => void);
|
||||
on(event: string | symbol, listener: (...args: any[]) => void);
|
||||
once(event: string | symbol, listener: (...args: any[]) => void);
|
||||
removeListener(event: string | symbol, listener: (...args: any[]) => void);
|
||||
off(event: string | symbol, listener: (...args: any[]) => void);
|
||||
removeAllListeners(event?: string | symbol);
|
||||
setMaxListeners(n: number);
|
||||
getMaxListeners(): number;
|
||||
listeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types
|
||||
rawListeners(event: string | symbol): Function[]; // eslint-disable-line @typescript-eslint/ban-types
|
||||
emit(event: string | symbol, ...args: any[]): boolean;
|
||||
listenerCount(event: string | symbol): number;
|
||||
}
|
||||
|
Reference in New Issue
Block a user