Skip to content

Commit 58bf45e

Browse files
committed
chore: update interfaces and multiaddr
1 parent 2bff878 commit 58bf45e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+208
-197
lines changed

package.json

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,23 @@
9494
"it-drain": "^1.0.3",
9595
"it-filter": "^1.0.1",
9696
"it-first": "^1.0.4",
97-
"it-handshake": "^1.0.2",
98-
"it-length-prefixed": "^4.0.0",
97+
"it-handshake": "^2.0.0",
98+
"it-length-prefixed": "^5.0.2",
9999
"it-map": "^1.0.4",
100100
"it-merge": "1.0.0",
101101
"it-pipe": "^1.1.0",
102102
"it-protocol-buffers": "^0.2.0",
103103
"it-take": "1.0.0",
104104
"libp2p-crypto": "^0.19.0",
105-
"libp2p-interfaces": "^0.9.0",
106-
"libp2p-utils": "^0.3.0",
107-
"mafmt": "^8.0.0",
105+
"libp2p-interfaces": "^0.10.0",
106+
"libp2p-utils": "^0.3.1",
107+
"mafmt": "^9.0.0",
108108
"merge-options": "^3.0.4",
109109
"moving-average": "^1.0.0",
110-
"multiaddr": "^8.1.2",
110+
"multiaddr": "^9.0.1",
111111
"multicodec": "^3.0.1",
112112
"multihashing-async": "^2.1.2",
113-
"multistream-select": "^1.0.0",
113+
"multistream-select": "^2.0.0",
114114
"mutable-proxy": "^1.0.0",
115115
"node-forge": "^0.10.0",
116116
"p-any": "^3.0.0",
@@ -149,13 +149,12 @@
149149
"libp2p-bootstrap": "^0.12.0",
150150
"libp2p-delegated-content-routing": "^0.9.0",
151151
"libp2p-delegated-peer-routing": "^0.8.0",
152-
"libp2p-floodsub": "^0.24.0",
153-
"libp2p-gossipsub": "^0.8.0",
152+
"libp2p-floodsub": "libp2p/js-libp2p-floodsub#chore/update-deps-and-remove-protons",
153+
"libp2p-gossipsub": "ChainSafe/js-libp2p-gossipsub#chore/update-deps-and-remove-protons",
154154
"libp2p-kad-dht": "^0.21.0",
155155
"libp2p-mdns": "^0.15.0",
156156
"libp2p-mplex": "^0.10.1",
157157
"libp2p-noise": "^2.0.0",
158-
"libp2p-secio": "^0.13.1",
159158
"libp2p-tcp": "^0.15.1",
160159
"libp2p-webrtc-star": "^0.21.2",
161160
"libp2p-websockets": "^0.15.0",

src/address-manager/index.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
/** @typedef {import('../types').EventEmitterFactory} Events */
44
/** @type Events */
55
const EventEmitter = require('events')
6-
const multiaddr = require('multiaddr')
6+
const { Multiaddr } = require('multiaddr')
77
const PeerId = require('peer-id')
88

9-
/**
10-
* @typedef {import('multiaddr')} Multiaddr
11-
*/
12-
139
/**
1410
* @typedef {Object} AddressManagerOptions
1511
* @property {string[]} [listen = []] - list of multiaddrs string representation to listen.
@@ -47,7 +43,7 @@ class AddressManager extends EventEmitter {
4743
* @returns {Multiaddr[]}
4844
*/
4945
getListenAddrs () {
50-
return Array.from(this.listen).map((a) => multiaddr(a))
46+
return Array.from(this.listen).map((a) => new Multiaddr(a))
5147
}
5248

5349
/**
@@ -56,7 +52,7 @@ class AddressManager extends EventEmitter {
5652
* @returns {Multiaddr[]}
5753
*/
5854
getAnnounceAddrs () {
59-
return Array.from(this.announce).map((a) => multiaddr(a))
55+
return Array.from(this.announce).map((a) => new Multiaddr(a))
6056
}
6157

6258
/**
@@ -65,7 +61,7 @@ class AddressManager extends EventEmitter {
6561
* @returns {Array<Multiaddr>}
6662
*/
6763
getObservedAddrs () {
68-
return Array.from(this.observed).map((a) => multiaddr(a))
64+
return Array.from(this.observed).map((a) => new Multiaddr(a))
6965
}
7066

7167
/**
@@ -74,7 +70,7 @@ class AddressManager extends EventEmitter {
7470
* @param {string | Multiaddr} addr
7571
*/
7672
addObservedAddr (addr) {
77-
let ma = multiaddr(addr)
73+
let ma = new Multiaddr(addr)
7874
const remotePeer = ma.getPeerId()
7975

8076
// strip our peer id if it has been passed
@@ -83,7 +79,7 @@ class AddressManager extends EventEmitter {
8379

8480
// use same encoding for comparison
8581
if (remotePeerId.equals(this.peerId)) {
86-
ma = ma.decapsulate(multiaddr(`/p2p/${this.peerId}`))
82+
ma = ma.decapsulate(new Multiaddr(`/p2p/${this.peerId}`))
8783
}
8884
}
8985

src/circuit/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Libp2p circuit configuration can be seen at [Setup with Relay](../../doc/CONFIGU
3737
Once you have a circuit relay node running, you can configure other nodes to use it as a relay as follows:
3838

3939
```js
40-
const multiaddr = require('multiaddr')
40+
const { Multiaddr } = require('multiaddr')
4141
const Libp2p = require('libp2p')
4242
const TCP = require('libp2p-tcp')
4343
const MPLEX = require('libp2p-mplex')
@@ -47,7 +47,7 @@ const relayAddr = ...
4747

4848
const node = await Libp2p.create({
4949
addresses: {
50-
listen: [multiaddr(`${relayAddr}/p2p-circuit`)]
50+
listen: [new Multiaddr(`${relayAddr}/p2p-circuit`)]
5151
},
5252
modules: {
5353
transport: [TCP],

src/circuit/auto-relay.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const log = Object.assign(debug('libp2p:auto-relay'), {
77

88
const uint8ArrayFromString = require('uint8arrays/from-string')
99
const uint8ArrayToString = require('uint8arrays/to-string')
10-
const multiaddr = require('multiaddr')
10+
const { Multiaddr } = require('multiaddr')
1111
const PeerId = require('peer-id')
1212

1313
const { relay: multicodec } = require('./multicodec')
@@ -157,7 +157,7 @@ class AutoRelay {
157157

158158
// Attempt to listen on relay
159159
try {
160-
await this._transportManager.listen([multiaddr(listenAddr)])
160+
await this._transportManager.listen([new Multiaddr(listenAddr)])
161161
// Announce multiaddrs will update on listen success by TransportManager event being triggered
162162
} catch (err) {
163163
log.error(err)

src/circuit/circuit/stream-handler.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class StreamHandler {
2828
this.stream = stream
2929

3030
this.shake = handshake(this.stream)
31+
// @ts-ignore options are not optional
3132
this.decoder = lp.decode.fromReader(this.shake.reader, { maxDataLength: maxLength })
3233
}
3334

src/circuit/circuit/utils.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const multiaddr = require('multiaddr')
3+
const { Multiaddr } = require('multiaddr')
44
const { CircuitRelay } = require('../protocol')
55

66
/**
@@ -31,7 +31,7 @@ function validateAddrs (msg, streamHandler) {
3131
try {
3232
if (msg.dstPeer && msg.dstPeer.addrs) {
3333
msg.dstPeer.addrs.forEach((addr) => {
34-
return multiaddr(addr)
34+
return new Multiaddr(addr)
3535
})
3636
}
3737
} catch (err) {
@@ -44,7 +44,7 @@ function validateAddrs (msg, streamHandler) {
4444
try {
4545
if (msg.srcPeer && msg.srcPeer.addrs) {
4646
msg.srcPeer.addrs.forEach((addr) => {
47-
return multiaddr(addr)
47+
return new Multiaddr(addr)
4848
})
4949
}
5050
} catch (err) {

src/circuit/listener.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
'use strict'
22

33
const { EventEmitter } = require('events')
4-
const multiaddr = require('multiaddr')
4+
const { Multiaddr } = require('multiaddr')
55

66
/**
7-
* @typedef {import('multiaddr')} Multiaddr
87
* @typedef {import('libp2p-interfaces/src/transport/types').Listener} Listener
98
*/
109

@@ -24,7 +23,7 @@ module.exports = (libp2p) => {
2423
async function listen (addr) {
2524
const addrString = String(addr).split('/p2p-circuit').find(a => a !== '')
2625

27-
const relayConn = await libp2p.dial(multiaddr(addrString))
26+
const relayConn = await libp2p.dial(new Multiaddr(addrString))
2827
const relayedAddr = relayConn.remoteAddr.encapsulate('/p2p-circuit')
2928

3029
listeningAddrs.set(relayConn.remotePeer.toB58String(), relayedAddr)

src/circuit/transport.js

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ const log = Object.assign(debug('libp2p:circuit'), {
55
error: debug('libp2p:circuit:err')
66
})
77

8+
const errCode = require('err-code')
89
const mafmt = require('mafmt')
9-
const multiaddr = require('multiaddr')
10+
const { Multiaddr } = require('multiaddr')
1011
const PeerId = require('peer-id')
1112
const { CircuitRelay: CircuitPB } = require('./protocol')
13+
const { codes } = require('../errors')
1214

1315
const toConnection = require('libp2p-utils/src/stream-to-ma-conn')
1416

@@ -21,7 +23,6 @@ const StreamHandler = require('./circuit/stream-handler')
2123
const transportSymbol = Symbol.for('@libp2p/js-libp2p-circuit/circuit')
2224

2325
/**
24-
* @typedef {import('multiaddr')} Multiaddr
2526
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
2627
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
2728
*/
@@ -96,9 +97,9 @@ class Circuit {
9697

9798
if (virtualConnection) {
9899
// @ts-ignore dst peer will not be undefined
99-
const remoteAddr = multiaddr(request.dstPeer.addrs[0])
100+
const remoteAddr = new Multiaddr(request.dstPeer.addrs[0])
100101
// @ts-ignore src peer will not be undefined
101-
const localAddr = multiaddr(request.srcPeer.addrs[0])
102+
const localAddr = new Multiaddr(request.srcPeer.addrs[0])
102103
const maConn = toConnection({
103104
stream: virtualConnection,
104105
remoteAddr,
@@ -124,10 +125,19 @@ class Circuit {
124125
async dial (ma, options) {
125126
// Check the multiaddr to see if it contains a relay and a destination peer
126127
const addrs = ma.toString().split('/p2p-circuit')
127-
const relayAddr = multiaddr(addrs[0])
128-
const destinationAddr = multiaddr(addrs[addrs.length - 1])
129-
const relayPeer = PeerId.createFromCID(relayAddr.getPeerId())
130-
const destinationPeer = PeerId.createFromCID(destinationAddr.getPeerId())
128+
const relayAddr = new Multiaddr(addrs[0])
129+
const destinationAddr = new Multiaddr(addrs[addrs.length - 1])
130+
const relayId = relayAddr.getPeerId()
131+
const destinationId = destinationAddr.getPeerId()
132+
133+
if (!relayId || !destinationId) {
134+
const errMsg = 'Circuit relay dial failed as addresses did not have peer id'
135+
log.error(errMsg)
136+
throw errCode(new Error(errMsg), codes.ERR_RELAYED_DIAL)
137+
}
138+
139+
const relayPeer = PeerId.createFromCID(relayId)
140+
const destinationPeer = PeerId.createFromCID(destinationId)
131141

132142
let disconnectOnFailure = false
133143
let relayConnection = this._connectionManager.get(relayPeer)
@@ -147,7 +157,7 @@ class Circuit {
147157
},
148158
dstPeer: {
149159
id: destinationPeer.toBytes(),
150-
addrs: [multiaddr(destinationAddr).bytes]
160+
addrs: [new Multiaddr(destinationAddr).bytes]
151161
}
152162
}
153163
})

src/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { publicAddressesFirst } = require('libp2p-utils/src/address-sort')
1212
const { FaultTolerance } = require('./transport-manager')
1313

1414
/**
15-
* @typedef {import('multiaddr')} Multiaddr
15+
* @typedef {import('multiaddr').Multiaddr} Multiaddr
1616
* @typedef {import('.').Libp2pOptions} Libp2pOptions
1717
* @typedef {import('.').constructorOptions} constructorOptions
1818
*/

src/content-routing/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const { pipe } = require('it-pipe')
1414

1515
/**
1616
* @typedef {import('peer-id')} PeerId
17-
* @typedef {import('multiaddr')} Multiaddr
17+
* @typedef {import('multiaddr').Multiaddr} Multiaddr
1818
* @typedef {import('cids')} CID
1919
* @typedef {import('libp2p-interfaces/src/content-routing/types')} ContentRoutingModule
2020
*/

0 commit comments

Comments
 (0)