Skip to content

Commit

Permalink
chore: update aegir
Browse files Browse the repository at this point in the history
  • Loading branch information
vasco-santos committed Mar 27, 2021
1 parent 3193fbe commit 09fb967
Show file tree
Hide file tree
Showing 29 changed files with 150 additions and 60 deletions.
38 changes: 20 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,17 @@
},
"dependencies": {
"@motrix/nat-api": "^0.3.1",
"@types/varint": "^6.0.0",
"abort-controller": "^3.0.0",
"aggregate-error": "^3.1.0",
"any-signal": "^2.1.1",
"bignumber.js": "^9.0.1",
"cids": "^1.1.5",
"class-is": "^1.1.0",
"debug": "^4.3.1",
"err-code": "^2.0.0",
"err-code": "^3.0.0",
"es6-promisify": "^6.1.1",
"events": "^3.2.0",
"events": "^3.3.0",
"hashlru": "^2.3.0",
"interface-datastore": "^3.0.3",
"ipfs-utils": "^6.0.0",
Expand All @@ -83,41 +84,41 @@
"it-take": "1.0.0",
"libp2p-crypto": "^0.19.0",
"libp2p-interfaces": "libp2p/js-libp2p-interfaces#chore/update-types",
"libp2p-utils": "^0.2.2",
"libp2p-utils": "libp2p/js-libp2p-utils#feat/add-types",
"mafmt": "^8.0.0",
"merge-options": "^3.0.4",
"moving-average": "^1.0.0",
"multiaddr": "^8.1.0",
"multicodec": "^2.1.0",
"multihashing-async": "^2.0.1",
"multicodec": "^3.0.1",
"multihashing-async": "^2.1.2",
"multistream-select": "^1.0.0",
"mutable-proxy": "^1.0.0",
"node-forge": "^0.10.0",
"p-any": "^3.0.0",
"p-fifo": "^1.0.0",
"p-retry": "^4.2.0",
"p-settle": "^4.0.1",
"p-retry": "^4.4.0",
"p-settle": "^4.1.1",
"peer-id": "^0.14.2",
"private-ip": "^2.0.0",
"private-ip": "^2.1.0",
"protons": "^2.0.0",
"retimer": "^2.0.0",
"retimer": "^3.0.0",
"sanitize-filename": "^1.6.3",
"set-delayed-interval": "^1.0.0",
"streaming-iterables": "^5.0.2",
"timeout-abort-controller": "^1.1.1",
"varint": "^6.0.0",
"xsalsa20": "^1.0.2"
"xsalsa20": "^1.1.0"
},
"devDependencies": {
"@nodeutils/defaults-deep": "^1.1.0",
"abortable-iterator": "^3.0.0",
"aegir": "^29.2.0",
"aegir": "^32.1.0",
"chai-bytes": "^0.1.2",
"chai-string": "^1.5.0",
"delay": "^4.4.0",
"delay": "^5.0.0",
"interop-libp2p": "^0.3.0",
"into-stream": "^6.0.0",
"ipfs-http-client": "^48.2.2",
"ipfs-http-client": "^49.0.4",
"it-concat": "^1.0.0",
"it-pair": "^1.0.0",
"it-pushable": "^1.4.0",
Expand All @@ -127,22 +128,23 @@
"libp2p-delegated-peer-routing": "^0.8.0",
"libp2p-floodsub": "^0.24.0",
"libp2p-gossipsub": "^0.8.0",
"libp2p-kad-dht": "^0.20.5",
"libp2p-kad-dht": "^0.21.0",
"libp2p-mdns": "^0.15.0",
"libp2p-mplex": "^0.10.1",
"libp2p-noise": "^2.0.0",
"libp2p-secio": "^0.13.1",
"libp2p-tcp": "^0.15.1",
"libp2p-webrtc-star": "^0.20.0",
"libp2p-webrtc-star": "^0.21.2",
"libp2p-websockets": "^0.15.0",
"multihashes": "^3.0.1",
"multihashes": "^4.0.2",
"nock": "^13.0.3",
"p-defer": "^3.0.0",
"p-times": "^3.0.0",
"p-wait-for": "^3.2.0",
"rimraf": "^3.0.2",
"sinon": "^9.2.4",
"uint8arrays": "^2.0.5"
"sinon": "^10.0.0",
"uint8arrays": "^2.1.3",
"util": "^0.12.3"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
Expand Down
2 changes: 2 additions & 0 deletions src/circuit/protocol/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
'use strict'

// @ts-ignore protons does not have types
const protobuf = require('protons')

/** @type {{CircuitRelay: import('../../types').CircuitMessageProto}} */
Expand Down
15 changes: 15 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const mergeOptions = require('merge-options')
// @ts-ignore no types in multiaddr
const { dnsaddrResolver } = require('multiaddr/src/resolvers')

const Constants = require('./constants')
Expand All @@ -10,6 +11,17 @@ const RelayConstants = require('./circuit/constants')
const { publicAddressesFirst } = require('libp2p-utils/src/address-sort')
const { FaultTolerance } = require('./transport-manager')

/**
* @typedef {import('.').Libp2pOptions} Libp2pOptions
* @typedef {import('.').constructorOptions} constructorOptions
* @typedef {import('.').Libp2pModules} Libp2pModules
*/

/**
* @typedef {Object} Libp2pResultingConfig
* @property {Libp2pModules} modules libp2p modules to use
*/

const DefaultConfig = {
addresses: {
listen: [],
Expand Down Expand Up @@ -95,6 +107,9 @@ const DefaultConfig = {
}
}

/**
* @param {Object} opts // TODO
*/
module.exports.validate = (opts) => {
opts = mergeOptions(DefaultConfig, opts)

Expand Down
1 change: 1 addition & 0 deletions src/connection-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const log = Object.assign(debug('libp2p:connection-manager'), {
const errcode = require('err-code')
const mergeOptions = require('merge-options')
const LatencyMonitor = require('./latency-monitor')
// @ts-ignore retimer does not have types
const retimer = require('retimer')

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

/**
Expand All @@ -31,6 +32,7 @@ class ContentRouting {
*/
constructor (libp2p) {
this.libp2p = libp2p
/** @type {ContentRoutingModule[]} */
this.routers = libp2p._modules.contentRouting || []
this.dht = libp2p._dht

Expand Down
5 changes: 4 additions & 1 deletion src/identify/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const log = Object.assign(debug('libp2p:identify'), {
error: debug('libp2p:identify:err')
})
const errCode = require('err-code')
// @ts-ignore it-protocol-buffers does not have types
const pb = require('it-protocol-buffers')
const lp = require('it-length-prefixed')
const { pipe } = require('it-pipe')
Expand All @@ -13,6 +14,7 @@ const uint8ArrayFromString = require('uint8arrays/from-string')

const PeerId = require('peer-id')
const multiaddr = require('multiaddr')
// @ts-ignore it-buffer does not have types
const { toBuffer } = require('it-buffer')

const Message = require('./message')
Expand Down Expand Up @@ -312,7 +314,8 @@ class IdentifyService {

// LEGACY: Update peers data in PeerStore
try {
this.peerStore.addressBook.set(id, message.listenAddrs.map((addr) => multiaddr(addr)))
this.peerStore.addressBook.set(id,
message.listenAddrs.map((/** @type {string} */ addr) => multiaddr(addr)))
} catch (err) {
log.error('received invalid addrs', err)
}
Expand Down
1 change: 1 addition & 0 deletions src/identify/message.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

// @ts-ignore protons does not have types
const protons = require('protons')
const schema = `
message Identify {
Expand Down
41 changes: 28 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ const { updateSelfPeerRecord } = require('./record/utils')
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
* @typedef {import('libp2p-interfaces/src/transport/types').TransportFactory} TransportFactory
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxerFactory} MuxerFactory
* @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRouting
* @typedef {import('libp2p-interfaces/src/peer-discovery/types').PeerDiscovery} PeerDiscovery
* @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRouting
* @typedef {import('libp2p-interfaces/src/content-routing/types').ContentRouting} ContentRoutingModule
* @typedef {import('libp2p-interfaces/src/peer-discovery/types').PeerDiscovery} PeerDiscoveryModule
* @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 @@ -94,9 +94,9 @@ const { updateSelfPeerRecord } = require('./record/utils')
* @property {TransportFactory[]} transport
* @property {MuxerFactory[]} streamMuxer
* @property {Crypto[]} connEncryption
* @property {PeerDiscovery[]} [peerDiscovery]
* @property {PeerRouting[]} [peerRouting]
* @property {ContentRouting[]} [contentRouting]
* @property {PeerDiscoveryModule[]} [peerDiscovery]
* @property {PeerRoutingModule[]} [peerRouting]
* @property {ContentRoutingModule[]} [contentRouting]
* @property {Object} [dht]
* @property {Pubsub} [pubsub]
*
Expand Down Expand Up @@ -455,7 +455,7 @@ class Libp2p extends EventEmitter {
* @returns {Promise<Connection>}
*/
dial (peer, options) {
return this.dialProtocol(peer, [], options)
return this._dial(peer, options)
}

/**
Expand All @@ -468,9 +468,26 @@ class Libp2p extends EventEmitter {
* @param {string[]|string} protocols
* @param {object} [options]
* @param {AbortSignal} [options.signal]
* @returns {Promise<Connection|*>}
* @returns {Promise<Connection|{ stream: MuxedStream; protocol: string; }>}
*/
async dialProtocol (peer, protocols, options) {
const connection = await this._dial(peer, options)

// If a protocol was provided, create a new stream
if (protocols && protocols.length) {
return connection.newStream(protocols)
}

return connection
}

/**
* @async
* @param {PeerId|Multiaddr|string} peer - The peer to dial
* @param {object} [options]
* @returns {Promise<Connection>}
*/
async _dial (peer, options) {
const { id, multiaddrs } = getPeer(peer)

if (id.equals(this.peerId)) {
Expand All @@ -485,11 +502,6 @@ class Libp2p extends EventEmitter {
this.peerStore.addressBook.add(id, multiaddrs)
}

// If a protocol was provided, create a new stream
if (protocols && protocols.length) {
return connection.newStream(protocols)
}

return connection
}

Expand Down Expand Up @@ -698,6 +710,9 @@ class Libp2p extends EventEmitter {
* @private
*/
async _setupPeerDiscovery () {
/**
* @param {PeerDiscoveryModule} DiscoveryService
*/
const setupService = (DiscoveryService) => {
let config = {
enabled: true // on by default
Expand Down
20 changes: 18 additions & 2 deletions src/insecure/plaintext.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ const debug = require('debug')
const log = Object.assign(debug('libp2p:plaintext'), {
error: debug('libp2p:plaintext:err')
})
// @ts-ignore it-handshake do not export types
const handshake = require('it-handshake')
const lp = require('it-length-prefixed')
const PeerId = require('peer-id')
const { UnexpectedPeerError, InvalidCryptoExchangeError } = require('libp2p-interfaces/src/crypto/errors')

// @ts-ignore protons do not export types
const { Exchange, KeyType } = require('./proto')
const protocol = '/plaintext/2.0.0'

/**
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
*/


/**
* @param {{ id: Uint8Array; pubkey: { Type: any, Data: Uint8Array; }; }} exchange
*/
function lpEncodeExchange (exchange) {
const pb = Exchange.encode(exchange)
return lp.encode.single(pb)
Expand Down Expand Up @@ -68,11 +73,22 @@ async function encrypt (localId, conn, remoteId) {
}
}

module.exports = {
module.exports =
{
protocol,
/**
* @param {PeerId} localId
* @param {Connection} conn
* @param {PeerId | undefined} remoteId
*/
secureInbound: (localId, conn, remoteId) => {
return encrypt(localId, conn, remoteId)
},
/**
* @param {PeerId} localId
* @param {Connection} conn
* @param {PeerId | undefined} remoteId
*/
secureOutbound: (localId, conn, remoteId) => {
return encrypt(localId, conn, remoteId)
}
Expand Down
1 change: 1 addition & 0 deletions src/insecure/proto.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

// @ts-ignore protons do not export types
const protobuf = require('protons')

module.exports = protobuf(`
Expand Down
4 changes: 4 additions & 0 deletions src/peer-routing.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ const filter = require('it-filter')
const {
setDelayedInterval,
clearDelayedInterval
// @ts-ignore module with no types
} = require('set-delayed-interval')
const PeerId = require('peer-id')

/**
* @typedef {import('multiaddr')} Multiaddr
* @typedef {import('libp2p-interfaces/src/peer-routing/types').PeerRouting} PeerRoutingModule
*/

/**
Expand All @@ -44,6 +46,7 @@ class PeerRouting {
constructor (libp2p) {
this._peerId = libp2p.peerId
this._peerStore = libp2p.peerStore
/** @type {PeerRoutingModule[]} */
this._routers = libp2p._modules.peerRouting || []

// If we have the dht, add it to the available peer routers
Expand Down Expand Up @@ -132,6 +135,7 @@ class PeerRouting {

yield * pipe(
merge(
// @ts-ignore TODO: This is not part of the interface! This should be!!
...this._routers.map(router => router.getClosestPeers(key, options))
),
(source) => storeAddresses(source, this._peerStore),
Expand Down
3 changes: 2 additions & 1 deletion src/peer-store/address-book.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AddressBook extends Book {
if (!data.addresses) {
return []
}
return data.addresses.map((address) => address.multiaddr)
return data.addresses.map((/** @type {Address} */ address) => address.multiaddr)
}
})

Expand Down Expand Up @@ -295,6 +295,7 @@ class AddressBook extends Book {
}

// create Address for each address
/** @type {Address[]} */
const addresses = []
multiaddrs.forEach((addr) => {
if (!multiaddr.isMultiaddr(addr)) {
Expand Down
3 changes: 3 additions & 0 deletions src/peer-store/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const {
codes: { ERR_INVALID_PARAMETERS }
} = require('../errors')

/**
* @param {any} data
*/
const passthrough = data => data

/**
Expand Down
Loading

0 comments on commit 09fb967

Please sign in to comment.