Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: event emitter and interfaces types for discovery and routing #934

Merged
merged 7 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,11 @@
"it-pipe": "^1.1.0",
"it-take": "1.0.0",
"libp2p-crypto": "^0.19.4",
"libp2p-interfaces": "^0.10.3",
"libp2p-interfaces": "^0.10.4",
"libp2p-utils": "^0.3.1",
"mafmt": "^9.0.0",
"merge-options": "^3.0.4",
"moving-average": "^1.0.0",
"@vascosantos/moving-average": "^1.1.0",
"multiaddr": "^9.0.1",
"multicodec": "^3.0.1",
"multihashing-async": "^2.1.2",
Expand Down
2 changes: 1 addition & 1 deletion src/address-manager/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const EventEmitter = require('events')
const { EventEmitter } = require('events')
const { Multiaddr } = require('multiaddr')
const PeerId = require('peer-id')

Expand Down
2 changes: 1 addition & 1 deletion src/connection-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const LatencyMonitor = require('./latency-monitor')
// @ts-ignore retimer does not have types
const retimer = require('retimer')

const EventEmitter = require('events')
const { EventEmitter } = require('events')

const PeerId = require('peer-id')

Expand Down
2 changes: 1 addition & 1 deletion src/connection-manager/latency-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* This code is based on `latency-monitor` (https://github.com/mlucool/latency-monitor) by `mlucool` (https://github.com/mlucool), available under Apache License 2.0 (https://github.com/mlucool/latency-monitor/blob/master/LICENSE)
*/

const EventEmitter = require('events')
const { EventEmitter } = require('events')
const VisibilityChangeEmitter = require('./visibility-change-emitter')
const debug = require('debug')('latency-monitor:LatencyMonitor')

Expand Down
2 changes: 1 addition & 1 deletion src/connection-manager/visibility-change-emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
'use strict'

const EventEmitter = require('events')
const { EventEmitter } = require('events')

const debug = require('debug')('latency-monitor:VisibilityChangeEmitter')

Expand Down
2 changes: 1 addition & 1 deletion src/content-routing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const { pipe } = require('it-pipe')
* @typedef {import('peer-id')} PeerId
* @typedef {import('multiaddr').Multiaddr} Multiaddr
* @typedef {import('cids')} CID
* @typedef {import('libp2p-interfaces/src/content-routing/types')} ContentRoutingModule
* @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRoutingModule
*/

/**
Expand Down
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const debug = require('debug')
const log = Object.assign(debug('libp2p'), {
error: debug('libp2p:err')
})
const EventEmitter = require('events')
const { EventEmitter } = require('events')

const errCode = require('err-code')
const PeerId = require('peer-id')
Expand Down Expand Up @@ -40,9 +40,9 @@ const { updateSelfPeerRecord } = require('./record/utils')
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
* @typedef {import('libp2p-interfaces/src/transport/types').TransportFactory<any, any>} TransportFactory
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory} MuxerFactory
* @typedef {import('libp2p-interfaces/src/content-routing/types')} ContentRoutingModule
* @typedef {import('libp2p-interfaces/src/peer-discovery/types')} PeerDiscoveryModule
* @typedef {import('libp2p-interfaces/src/peer-routing/types')} PeerRoutingModule
* @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRoutingModule
* @typedef {import('libp2p-interfaces/src/peer-discovery/types').PeerDiscoveryFactory} PeerDiscoveryFactory
* @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRoutingModule
* @typedef {import('libp2p-interfaces/src/crypto/types').Crypto} Crypto
* @typedef {import('libp2p-interfaces/src/pubsub')} Pubsub
* @typedef {import('libp2p-interfaces/src/pubsub').PubsubOptions} PubsubOptions
Expand Down Expand Up @@ -100,7 +100,7 @@ const { updateSelfPeerRecord } = require('./record/utils')
* @property {TransportFactory[]} transport
* @property {MuxerFactory[]} streamMuxer
* @property {Crypto[]} connEncryption
* @property {PeerDiscoveryModule[]} [peerDiscovery]
* @property {PeerDiscoveryFactory[]} [peerDiscovery]
* @property {PeerRoutingModule[]} [peerRouting]
* @property {ContentRoutingModule[]} [contentRouting]
* @property {Object} [dht]
Expand Down Expand Up @@ -714,7 +714,7 @@ class Libp2p extends EventEmitter {
*/
async _setupPeerDiscovery () {
/**
* @param {PeerDiscoveryModule} DiscoveryService
* @param {PeerDiscoveryFactory} DiscoveryService
*/
const setupService = (DiscoveryService) => {
let config = {
Expand Down
4 changes: 2 additions & 2 deletions src/metrics/stats.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-nocheck
'use strict'

const EventEmitter = require('events')
const { EventEmitter } = require('events')
const { BigNumber: Big } = require('bignumber.js')
const MovingAverage = require('moving-average')
const MovingAverage = require('@vascosantos/moving-average')
const retimer = require('retimer')

class Stats extends EventEmitter {
Expand Down
2 changes: 1 addition & 1 deletion src/peer-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const {
/**
* @typedef {import('peer-id')} PeerId
* @typedef {import('multiaddr').Multiaddr} Multiaddr
* @typedef {import('libp2p-interfaces/src/peer-routing/types')} PeerRoutingModule
* @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRoutingModule
*/

/**
Expand Down
2 changes: 1 addition & 1 deletion src/peer-store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const errcode = require('err-code')

const EventEmitter = require('events')
const { EventEmitter } = require('events')
const PeerId = require('peer-id')

const AddressBook = require('./address-book')
Expand Down
7 changes: 6 additions & 1 deletion src/upgrader.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,12 @@ class Upgrader {
* @returns {Promise<Connection>}
*/
async upgradeOutbound (maConn) {
const remotePeerId = PeerId.createFromB58String(maConn.remoteAddr.getPeerId())
const idStr = maConn.remoteAddr.getPeerId()
if (!idStr) {
throw errCode(new Error('outbound connection must have a peer id'), codes.ERR_INVALID_MULTIADDR)
}

const remotePeerId = PeerId.createFromB58String(idStr)

let encryptedConn
let remotePeer
Expand Down