Skip to content

Commit 5e9c17d

Browse files
committed
chore: update aegir
1 parent cec3ce7 commit 5e9c17d

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
-268
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-19
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"src"
1919
],
2020
"scripts": {
21-
"prepare": "aegir build --no-bundle",
2221
"lint": "aegir lint",
2322
"build": "aegir build",
2423
"test": "npm run test:node && npm run test:browser",
@@ -54,18 +53,25 @@
5453
"browser": {
5554
"@motrix/nat-api": false
5655
},
56+
"eslintConfig": {
57+
"extends": "ipfs",
58+
"ignorePatterns": [
59+
"!.aegir.js"
60+
]
61+
},
5762
"dependencies": {
5863
"@motrix/nat-api": "^0.3.1",
64+
"@types/varint": "^6.0.0",
5965
"abort-controller": "^3.0.0",
6066
"aggregate-error": "^3.1.0",
6167
"any-signal": "^2.1.1",
6268
"bignumber.js": "^9.0.1",
6369
"cids": "^1.1.5",
6470
"class-is": "^1.1.0",
6571
"debug": "^4.3.1",
66-
"err-code": "^2.0.0",
72+
"err-code": "^3.0.0",
6773
"es6-promisify": "^6.1.1",
68-
"events": "^3.2.0",
74+
"events": "^3.3.0",
6975
"hashlru": "^2.3.0",
7076
"interface-datastore": "^3.0.3",
7177
"ipfs-utils": "^6.0.0",
@@ -83,42 +89,43 @@
8389
"it-take": "1.0.0",
8490
"libp2p-crypto": "^0.19.0",
8591
"libp2p-interfaces": "libp2p/js-libp2p-interfaces#chore/update-types",
86-
"libp2p-utils": "^0.2.2",
92+
"libp2p-utils": "libp2p/js-libp2p-utils#feat/add-types",
8793
"mafmt": "^8.0.0",
8894
"merge-options": "^3.0.4",
8995
"moving-average": "^1.0.0",
9096
"multiaddr": "^8.1.0",
91-
"multicodec": "^2.1.0",
92-
"multihashing-async": "^2.0.1",
97+
"multicodec": "^3.0.1",
98+
"multihashing-async": "^2.1.2",
9399
"multistream-select": "^1.0.0",
94100
"mutable-proxy": "^1.0.0",
95101
"node-forge": "^0.10.0",
96102
"p-any": "^3.0.0",
97103
"p-fifo": "^1.0.0",
98-
"p-retry": "^4.2.0",
99-
"p-settle": "^4.0.1",
104+
"p-retry": "^4.4.0",
105+
"p-settle": "^4.1.1",
100106
"peer-id": "^0.14.2",
101-
"private-ip": "^2.0.0",
107+
"private-ip": "^2.1.0",
102108
"protons": "^2.0.0",
103-
"retimer": "^2.0.0",
109+
"retimer": "^3.0.0",
104110
"sanitize-filename": "^1.6.3",
105111
"set-delayed-interval": "^1.0.0",
106112
"streaming-iterables": "^5.0.2",
107113
"timeout-abort-controller": "^1.1.1",
108114
"varint": "^6.0.0",
109-
"xsalsa20": "^1.0.2"
115+
"xsalsa20": "^1.1.0"
110116
},
111117
"devDependencies": {
112118
"@nodeutils/defaults-deep": "^1.1.0",
113119
"@types/es6-promisify": "^6.0.0",
120+
"@types/node-forge": "^0.9.7",
114121
"abortable-iterator": "^3.0.0",
115-
"aegir": "^29.2.0",
122+
"aegir": "^32.1.0",
116123
"chai-bytes": "^0.1.2",
117124
"chai-string": "^1.5.0",
118-
"delay": "^4.4.0",
125+
"delay": "^5.0.0",
119126
"interop-libp2p": "^0.3.0",
120127
"into-stream": "^6.0.0",
121-
"ipfs-http-client": "^48.2.2",
128+
"ipfs-http-client": "^49.0.4",
122129
"it-concat": "^1.0.0",
123130
"it-pair": "^1.0.0",
124131
"it-pushable": "^1.4.0",
@@ -128,22 +135,24 @@
128135
"libp2p-delegated-peer-routing": "^0.8.0",
129136
"libp2p-floodsub": "^0.24.0",
130137
"libp2p-gossipsub": "^0.8.0",
131-
"libp2p-kad-dht": "^0.20.5",
138+
"libp2p-kad-dht": "^0.21.0",
132139
"libp2p-mdns": "^0.15.0",
133140
"libp2p-mplex": "^0.10.1",
134141
"libp2p-noise": "^2.0.0",
135142
"libp2p-secio": "^0.13.1",
136143
"libp2p-tcp": "^0.15.1",
137-
"libp2p-webrtc-star": "^0.20.0",
144+
"libp2p-webrtc-star": "^0.21.2",
138145
"libp2p-websockets": "^0.15.0",
139-
"multihashes": "^3.0.1",
146+
"multihashes": "^4.0.2",
140147
"nock": "^13.0.3",
141148
"p-defer": "^3.0.0",
142149
"p-times": "^3.0.0",
143150
"p-wait-for": "^3.2.0",
144151
"rimraf": "^3.0.2",
145-
"sinon": "^9.2.4",
146-
"uint8arrays": "^2.0.5"
152+
"sinon": "^10.0.0",
153+
"uint8arrays": "^2.1.3",
154+
"url": "^0.11.0",
155+
"util": "^0.12.3"
147156
},
148157
"contributors": [
149158
"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)