Skip to content

Commit a3a2f15

Browse files
committed
chore: update aegir
1 parent cec3ce7 commit a3a2f15

Some content is hidden

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

59 files changed

+590
-267
lines changed

.aegir.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

3+
const path = require('path')
34
const Libp2p = require('./src')
45
const { MULTIADDRS_WEBSOCKETS } = require('./test/fixtures/browser')
56
const Peers = require('./test/fixtures/peers')
@@ -47,16 +48,23 @@ const after = async () => {
4748
await libp2p.stop()
4849
}
4950

51+
/** @type {import('aegir').Options["build"]["config"]} */
52+
const esbuild = {
53+
inject: [path.join(__dirname, './scripts/node-globals.js')]
54+
}
55+
56+
/** @type {import('aegir').PartialOptions} */
5057
module.exports = {
51-
bundlesize: { maxSize: '225kB' },
52-
hooks: {
53-
pre: before,
54-
post: after
58+
build: {
59+
bundlesizeMax: '225kB'
5560
},
56-
webpack: {
57-
node: {
58-
// needed by bcrypto
59-
Buffer: true
61+
test: {
62+
before,
63+
after,
64+
browser: {
65+
config: {
66+
buildConfig: esbuild
67+
}
6068
}
6169
}
6270
}

package.json

+28-18
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,25 @@
5454
"browser": {
5555
"@motrix/nat-api": false
5656
},
57+
"eslintConfig": {
58+
"extends": "ipfs",
59+
"ignorePatterns": [
60+
"!.aegir.js"
61+
]
62+
},
5763
"dependencies": {
5864
"@motrix/nat-api": "^0.3.1",
65+
"@types/varint": "^6.0.0",
5966
"abort-controller": "^3.0.0",
6067
"aggregate-error": "^3.1.0",
6168
"any-signal": "^2.1.1",
6269
"bignumber.js": "^9.0.1",
6370
"cids": "^1.1.5",
6471
"class-is": "^1.1.0",
6572
"debug": "^4.3.1",
66-
"err-code": "^2.0.0",
73+
"err-code": "^3.0.0",
6774
"es6-promisify": "^6.1.1",
68-
"events": "^3.2.0",
75+
"events": "^3.3.0",
6976
"hashlru": "^2.3.0",
7077
"interface-datastore": "^3.0.3",
7178
"ipfs-utils": "^6.0.0",
@@ -83,42 +90,43 @@
8390
"it-take": "1.0.0",
8491
"libp2p-crypto": "^0.19.0",
8592
"libp2p-interfaces": "libp2p/js-libp2p-interfaces#chore/update-types",
86-
"libp2p-utils": "^0.2.2",
93+
"libp2p-utils": "libp2p/js-libp2p-utils#feat/add-types",
8794
"mafmt": "^8.0.0",
8895
"merge-options": "^3.0.4",
8996
"moving-average": "^1.0.0",
9097
"multiaddr": "^8.1.0",
91-
"multicodec": "^2.1.0",
92-
"multihashing-async": "^2.0.1",
98+
"multicodec": "^3.0.1",
99+
"multihashing-async": "^2.1.2",
93100
"multistream-select": "^1.0.0",
94101
"mutable-proxy": "^1.0.0",
95102
"node-forge": "^0.10.0",
96103
"p-any": "^3.0.0",
97104
"p-fifo": "^1.0.0",
98-
"p-retry": "^4.2.0",
99-
"p-settle": "^4.0.1",
105+
"p-retry": "^4.4.0",
106+
"p-settle": "^4.1.1",
100107
"peer-id": "^0.14.2",
101-
"private-ip": "^2.0.0",
108+
"private-ip": "^2.1.0",
102109
"protons": "^2.0.0",
103-
"retimer": "^2.0.0",
110+
"retimer": "^3.0.0",
104111
"sanitize-filename": "^1.6.3",
105112
"set-delayed-interval": "^1.0.0",
106113
"streaming-iterables": "^5.0.2",
107114
"timeout-abort-controller": "^1.1.1",
108115
"varint": "^6.0.0",
109-
"xsalsa20": "^1.0.2"
116+
"xsalsa20": "^1.1.0"
110117
},
111118
"devDependencies": {
112119
"@nodeutils/defaults-deep": "^1.1.0",
113120
"@types/es6-promisify": "^6.0.0",
121+
"@types/node-forge": "^0.9.7",
114122
"abortable-iterator": "^3.0.0",
115-
"aegir": "^29.2.0",
123+
"aegir": "^32.1.0",
116124
"chai-bytes": "^0.1.2",
117125
"chai-string": "^1.5.0",
118-
"delay": "^4.4.0",
126+
"delay": "^5.0.0",
119127
"interop-libp2p": "^0.3.0",
120128
"into-stream": "^6.0.0",
121-
"ipfs-http-client": "^48.2.2",
129+
"ipfs-http-client": "^49.0.4",
122130
"it-concat": "^1.0.0",
123131
"it-pair": "^1.0.0",
124132
"it-pushable": "^1.4.0",
@@ -128,22 +136,24 @@
128136
"libp2p-delegated-peer-routing": "^0.8.0",
129137
"libp2p-floodsub": "^0.24.0",
130138
"libp2p-gossipsub": "^0.8.0",
131-
"libp2p-kad-dht": "^0.20.5",
139+
"libp2p-kad-dht": "^0.21.0",
132140
"libp2p-mdns": "^0.15.0",
133141
"libp2p-mplex": "^0.10.1",
134142
"libp2p-noise": "^2.0.0",
135143
"libp2p-secio": "^0.13.1",
136144
"libp2p-tcp": "^0.15.1",
137-
"libp2p-webrtc-star": "^0.20.0",
145+
"libp2p-webrtc-star": "^0.21.2",
138146
"libp2p-websockets": "^0.15.0",
139-
"multihashes": "^3.0.1",
147+
"multihashes": "^4.0.2",
140148
"nock": "^13.0.3",
141149
"p-defer": "^3.0.0",
142150
"p-times": "^3.0.0",
143151
"p-wait-for": "^3.2.0",
144152
"rimraf": "^3.0.2",
145-
"sinon": "^9.2.4",
146-
"uint8arrays": "^2.0.5"
153+
"sinon": "^10.0.0",
154+
"uint8arrays": "^2.1.3",
155+
"url": "^0.11.0",
156+
"util": "^0.12.3"
147157
},
148158
"contributors": [
149159
"David Dias <[email protected]>",

scripts/node-globals.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @ts-nocheck
2+
export const { Buffer } = require('buffer')
3+
export const url = require('url')

src/circuit/circuit/hop.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ const multicodec = require('./../multicodec')
2020
/**
2121
* @typedef {import('../../types').CircuitRequest} CircuitRequest
2222
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
23-
* @typedef {import('./stream-handler')<CircuitRequest>} StreamHandlerT
23+
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
2424
* @typedef {import('../transport')} Transport
2525
*/
2626

2727
/**
2828
* @typedef {Object} HopRequest
2929
* @property {Connection} connection
3030
* @property {CircuitRequest} request
31-
* @property {StreamHandlerT} streamHandler
31+
* @property {StreamHandler} streamHandler
3232
* @property {Transport} circuit
3333
*/
3434

@@ -58,6 +58,11 @@ async function handleHop ({
5858
return log.error('invalid hop request via peer %s', connection.remotePeer.toB58String(), err)
5959
}
6060

61+
if (!request.dstPeer) {
62+
log('HOP request received but we do not receive a dstPeer')
63+
return
64+
}
65+
6166
// Get the connection to the destination (stop) peer
6267
const destinationPeer = new PeerId(request.dstPeer.id)
6368

@@ -114,7 +119,7 @@ async function handleHop ({
114119
* @param {object} options
115120
* @param {Connection} options.connection - Connection to the relay
116121
* @param {CircuitRequest} options.request
117-
* @returns {Promise<Connection>}
122+
* @returns {Promise<MuxedStream>}
118123
*/
119124
async function hop ({
120125
connection,
@@ -128,6 +133,10 @@ async function hop ({
128133

129134
const response = await streamHandler.read()
130135

136+
if (!response) {
137+
throw errCode(new Error('HOP request had no response'), Errors.ERR_HOP_REQUEST_FAILED)
138+
}
139+
131140
if (response.code === CircuitPB.Status.SUCCESS) {
132141
log('hop request was successful')
133142
return streamHandler.rest()
@@ -159,7 +168,7 @@ async function canHop ({
159168
const response = await streamHandler.read()
160169
await streamHandler.close()
161170

162-
if (response.code !== CircuitPB.Status.SUCCESS) {
171+
if (!response || response.code !== CircuitPB.Status.SUCCESS) {
163172
return false
164173
}
165174

@@ -171,7 +180,7 @@ async function canHop ({
171180
*
172181
* @param {Object} options
173182
* @param {Connection} options.connection
174-
* @param {StreamHandlerT} options.streamHandler
183+
* @param {StreamHandler} options.streamHandler
175184
* @param {Transport} options.circuit
176185
* @private
177186
*/

src/circuit/circuit/stop.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const { validateAddrs } = require('./utils')
1414
* @typedef {import('libp2p-interfaces/src/connection').Connection} Connection
1515
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
1616
* @typedef {import('../../types').CircuitRequest} CircuitRequest
17-
* @typedef {import('./stream-handler')<CircuitRequest>} StreamHandlerT
17+
* @typedef {import('./stream-handler')} StreamHandlerT
1818
*/
1919

2020
/**
@@ -68,6 +68,10 @@ module.exports.stop = async function stop ({
6868
streamHandler.write(request)
6969
const response = await streamHandler.read()
7070

71+
if (!response) {
72+
return streamHandler.close()
73+
}
74+
7175
if (response.code === CircuitPB.Status.SUCCESS) {
7276
log('stop request to %s was successful', connection.remotePeer.toB58String())
7377
return streamHandler.rest()

src/circuit/circuit/stream-handler.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@ const log = Object.assign(debug('libp2p:circuit:stream-handler'), {
66
})
77

88
const lp = require('it-length-prefixed')
9+
// @ts-ignore it-handshake does not export types
910
const handshake = require('it-handshake')
1011
const { CircuitRelay: CircuitPB } = require('../protocol')
1112

1213
/**
1314
* @typedef {import('libp2p-interfaces/src/stream-muxer/types').MuxedStream} MuxedStream
15+
* @typedef {import('../../types').CircuitRequest} CircuitRequest
1416
*/
1517

16-
/**
17-
* @template T
18-
*/
1918
class StreamHandler {
2019
/**
2120
* Create a stream handler for connection
@@ -36,7 +35,7 @@ class StreamHandler {
3635
* Read and decode message
3736
*
3837
* @async
39-
* @returns {Promise<T|undefined>}
38+
* @returns {Promise<CircuitRequest|undefined>}
4039
*/
4140
async read () {
4241
const msg = await this.decoder.next()
@@ -54,7 +53,7 @@ class StreamHandler {
5453
/**
5554
* Encode and write array of buffers
5655
*
57-
* @param {CircuitPB} msg - An unencoded CircuitRelay protobuf message
56+
* @param {CircuitRequest} msg - An unencoded CircuitRelay protobuf message
5857
* @returns {void}
5958
*/
6059
write (msg) {
@@ -73,6 +72,9 @@ class StreamHandler {
7372
return this.shake.stream
7473
}
7574

75+
/**
76+
* @param {CircuitRequest} msg - An unencoded CircuitRelay protobuf message
77+
*/
7678
end (msg) {
7779
this.write(msg)
7880
this.close()

src/circuit/circuit/utils.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function writeResponse (streamHandler, status) {
2929
*/
3030
function validateAddrs (msg, streamHandler) {
3131
try {
32-
msg.dstPeer.addrs.forEach((addr) => {
32+
msg.dstPeer.addrs.forEach((/** @type {string} */ addr) => {
3333
return multiaddr(addr)
3434
})
3535
} catch (err) {
@@ -40,7 +40,7 @@ function validateAddrs (msg, streamHandler) {
4040
}
4141

4242
try {
43-
msg.srcPeer.addrs.forEach((addr) => {
43+
msg.srcPeer.addrs.forEach((/** @type {string} */ addr) => {
4444
return multiaddr(addr)
4545
})
4646
} catch (err) {

src/circuit/index.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ const log = Object.assign(debug('libp2p:relay'), {
88
const {
99
setDelayedInterval,
1010
clearDelayedInterval
11+
// @ts-ignore set-delayed-interval does not export types
1112
} = require('set-delayed-interval')
1213

1314
const AutoRelay = require('./auto-relay')
1415
const { namespaceToCid } = require('./utils')
1516
const {
16-
ADVERTISE_BOOT_DELAY,
17-
ADVERTISE_TTL,
1817
RELAY_RENDEZVOUS_NS
1918
} = require('./constants')
2019

@@ -45,12 +44,6 @@ class Relay {
4544
constructor (libp2p) {
4645
this._libp2p = libp2p
4746
this._options = {
48-
advertise: {
49-
bootDelay: ADVERTISE_BOOT_DELAY,
50-
enabled: true,
51-
ttl: ADVERTISE_TTL,
52-
...libp2p._config.relay.advertise
53-
},
5447
...libp2p._config.relay
5548
}
5649

src/circuit/protocol/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
'use strict'
2+
3+
// @ts-ignore protons does not have types
24
const protobuf = require('protons')
35

46
/** @type {{CircuitRelay: import('../../types').CircuitMessageProto}} */

src/circuit/transport.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Circuit {
5454
* @param {MuxedStream} props.stream
5555
*/
5656
async _onProtocol ({ connection, stream }) {
57-
/** @type {import('./circuit/stream-handler')<CircuitRequest>} */
57+
/** @type {import('./circuit/stream-handler')} */
5858
const streamHandler = new StreamHandler({ stream })
5959
const request = await streamHandler.read()
6060

@@ -96,7 +96,9 @@ class Circuit {
9696
}
9797

9898
if (virtualConnection) {
99+
// @ts-ignore dst peer will not be undefined
99100
const remoteAddr = multiaddr(request.dstPeer.addrs[0])
101+
// @ts-ignore src peer will not be undefined
100102
const localAddr = multiaddr(request.srcPeer.addrs[0])
101103
const maConn = toConnection({
102104
stream: virtualConnection,

0 commit comments

Comments
 (0)