Skip to content

Commit 23d24ce

Browse files
authored
feat: update to typescript version of libp2p (#428)
- Uses libp2p rc built from typescript - Updates to latest aegir - Publishes as ESM only BREAKING CHANGE: this module is now ESM only
1 parent bf7d879 commit 23d24ce

Some content is hidden

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

43 files changed

+399
-398
lines changed

.aegir.cjs

Lines changed: 0 additions & 38 deletions
This file was deleted.

.aegir.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
/** @type {import('aegir').PartialOptions} */
3+
export default {
4+
build: {
5+
bundlesizeMax: '32KB'
6+
}
7+
}

.github/workflows/automerge.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Automatically merge pull requests opened by web3-bot, as soon as (and only if) all tests pass.
2+
# This reduces the friction associated with updating with our workflows.
3+
4+
on: [ pull_request ]
5+
name: Automerge
6+
7+
jobs:
8+
automerge-check:
9+
if: github.event.pull_request.user.login == 'web3-bot'
10+
runs-on: ubuntu-latest
11+
outputs:
12+
status: ${{ steps.should-automerge.outputs.status }}
13+
steps:
14+
- uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
- name: Check if we should automerge
18+
id: should-automerge
19+
run: |
20+
for commit in $(git rev-list --first-parent origin/${{ github.event.pull_request.base.ref }}..${{ github.event.pull_request.head.sha }}); do
21+
committer=$(git show --format=$'%ce' -s $commit)
22+
echo "Committer: $committer"
23+
if [[ "$committer" != "[email protected]" ]]; then
24+
echo "Commit $commit wasn't committed by web3-bot, but by $committer."
25+
echo "::set-output name=status::false"
26+
exit
27+
fi
28+
done
29+
echo "::set-output name=status::true"
30+
automerge:
31+
needs: automerge-check
32+
runs-on: ubuntu-latest
33+
# The check for the user is redundant here, as this job depends on the automerge-check job,
34+
# but it prevents this job from spinning up, just to be skipped shortly after.
35+
if: github.event.pull_request.user.login == 'web3-bot' && needs.automerge-check.outputs.status == 'true'
36+
steps:
37+
- name: Wait on tests
38+
uses: lewagon/wait-on-check-action@bafe56a6863672c681c3cf671f5e10b20abf2eaa # v0.2
39+
with:
40+
ref: ${{ github.event.pull_request.head.sha }}
41+
repo-token: ${{ secrets.GITHUB_TOKEN }}
42+
wait-interval: 10
43+
running-workflow-name: 'automerge' # the name of this job
44+
- name: Merge PR
45+
uses: pascalgn/automerge-action@741c311a47881be9625932b0a0de1b0937aab1ae # v0.13.1
46+
env:
47+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
48+
MERGE_LABELS: ""
49+
MERGE_METHOD: "squash"
50+
MERGE_DELETE_BRANCH: true

package.json

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@
2323
},
2424
"main": "src/index.js",
2525
"type": "module",
26-
"types": "types/src/index.d.ts",
26+
"types": "./dist/src/index.d.ts",
2727
"typesVersions": {
2828
"*": {
2929
"*": [
30-
"types/*",
31-
"types/src/*"
30+
"*",
31+
"dist/*",
32+
"dist/src/*",
33+
"dist/src/*/index"
3234
],
33-
"types/*": [
34-
"types/*",
35-
"types/src/*"
35+
"src/*": [
36+
"*",
37+
"dist/*",
38+
"dist/src/*",
39+
"dist/src/*/index"
3640
]
3741
}
3842
},
@@ -134,47 +138,42 @@
134138
}
135139
],
136140
"@semantic-release/changelog",
137-
[
138-
"@semantic-release/npm",
139-
{
140-
"pkgRoot": "dist"
141-
}
142-
],
141+
"@semantic-release/npm",
143142
"@semantic-release/github",
144143
"@semantic-release/git"
145144
]
146145
},
147146
"scripts": {
148-
"clean": "rimraf dist types",
149-
"prepare": "aegir build --no-bundle && cp -R types dist",
150-
"lint": "aegir ts -p check && aegir lint",
151-
"build": "aegir build --esm-tests",
152-
"release": "semantic-release",
147+
"clean": "aegir clean",
148+
"lint": "aegir lint",
149+
"build": "aegir build",
150+
"release": "aegir release",
153151
"test": "aegir test",
154152
"test:node": "aegir test -t node",
155153
"test:chrome": "aegir test -t browser",
156154
"test:chrome-webworker": "aegir test -t webworker",
157155
"test:firefox": "aegir test -t browser -- --browser firefox",
158156
"test:firefox-webworker": "aegir test -t webworker -- --browser firefox",
159-
"test:electron-main": "aegir test -t electron-main -f dist/cjs/node-test/*js",
160-
"test:electron-renderer": "aegir test -t electron-renderer -f dist/cjs/node-test/*js",
157+
"test:electron-main": "aegir test -t electron-main",
161158
"dep-check": "aegir dep-check -i rimraf",
162159
"generate": "run-s generate:*",
163160
"generate:proto": "pbjs -t static-module -w es6 -r ipfs-bitswap --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/message/message.js src/message/message.proto",
164161
"generate:proto-types": "pbts -o src/message/message.d.ts src/message/message.js"
165162
},
166163
"dependencies": {
164+
"@libp2p/interfaces": "^1.3.18",
165+
"@libp2p/topology": "^1.1.6",
166+
"@libp2p/tracked-map": "^1.0.4",
167+
"@multiformats/multiaddr": "^10.1.8",
167168
"@vascosantos/moving-average": "^1.1.0",
168169
"any-signal": "^3.0.0",
169170
"blockstore-core": "^1.0.2",
170171
"debug": "^4.2.0",
171172
"err-code": "^3.0.1",
172173
"interface-blockstore": "^2.0.2",
173-
"it-length-prefixed": "^5.0.2",
174-
"it-pipe": "^1.1.0",
175-
"just-debounce-it": "^1.1.0",
176-
"libp2p-interfaces": "^4.0.0",
177-
"multiaddr": "^10.0.0",
174+
"it-length-prefixed": "^7.0.1",
175+
"it-pipe": "^2.0.3",
176+
"just-debounce-it": "^3.0.1",
178177
"multiformats": "^9.0.4",
179178
"protobufjs": "^6.10.2",
180179
"readable-stream": "^3.6.0",
@@ -183,40 +182,45 @@
183182
"varint-decoder": "^1.0.0"
184183
},
185184
"devDependencies": {
186-
"@chainsafe/libp2p-noise": "^4.1.0",
185+
"@chainsafe/libp2p-noise": "^6.0.1",
186+
"@libp2p/kad-dht": "^1.0.3",
187+
"@libp2p/mplex": "^1.0.2",
188+
"@libp2p/peer-id": "^1.1.8",
189+
"@libp2p/peer-id-factory": "^1.0.8",
190+
"@libp2p/peer-store": "^1.0.7",
191+
"@libp2p/tcp": "^1.0.6",
187192
"@nodeutils/defaults-deep": "^1.1.0",
188193
"@types/debug": "^4.1.5",
189194
"@types/stats-lite": "^2.2.0",
190195
"@types/varint": "^6.0.0",
191-
"aegir": "^36.0.2",
196+
"aegir": "^37.0.4",
192197
"assert": "^2.0.0",
193198
"benchmark": "^2.1.4",
194-
"datastore-core": "^6.0.7",
199+
"datastore-core": "^7.0.1",
195200
"delay": "^5.0.0",
196201
"interface-datastore": "^6.0.2",
197202
"iso-random-stream": "^2.0.0",
198203
"it-all": "^1.0.5",
199204
"it-drain": "^1.0.4",
200205
"libp2p": "next",
201-
"libp2p-kad-dht": "^0.28.4",
202-
"libp2p-mplex": "^0.10.2",
203-
"libp2p-tcp": "^0.17.1",
204206
"lodash.difference": "^4.5.0",
205207
"lodash.flatten": "^4.4.0",
206208
"lodash.range": "^3.2.0",
207209
"lodash.without": "^4.4.0",
208210
"npm-run-all": "^4.1.5",
209-
"p-defer": "^3.0.0",
210-
"p-event": "^4.2.0",
211-
"p-wait-for": "^3.2.0",
212-
"peer-id": "^0.16.0",
211+
"p-defer": "^4.0.0",
212+
"p-event": "^5.0.1",
213+
"p-wait-for": "^4.1.0",
213214
"process": "^0.11.10",
214215
"promisify-es6": "^1.0.3",
215216
"rimraf": "^3.0.2",
216-
"sinon": "^12.0.1",
217+
"sinon": "^13.0.1",
217218
"stats-lite": "^2.2.0",
218219
"url": "^0.11.0",
219220
"util": "^0.12.3",
220221
"uuid": "^8.3.2"
222+
},
223+
"browser": {
224+
"test/utils/create-libp2p-node.js": false
221225
}
222226
}

scripts/false.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

scripts/node-globals.js

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/bitswap.js

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { CID } from 'multiformats/cid'
1212
* @typedef {import('./types').IPFSBitswap} IPFSBitswap
1313
* @typedef {import('./types').MultihashHasherLoader} MultihashHasherLoader
1414
* @typedef {import('./message').BitswapMessage} BitswapMessage
15-
* @typedef {import('peer-id')} PeerId
15+
* @typedef {import('@libp2p/interfaces/peer-id').PeerId} PeerId
1616
* @typedef {import('interface-blockstore').Blockstore} Blockstore
1717
* @typedef {import('interface-blockstore').Pair} Pair
1818
* @typedef {import('interface-blockstore').Options} Options
@@ -43,9 +43,9 @@ const statsKeys = [
4343
*/
4444
export class Bitswap extends BaseBlockstore {
4545
/**
46-
* @param {import('libp2p')} libp2p
46+
* @param {import('libp2p').Libp2p} libp2p
4747
* @param {Blockstore} blockstore
48-
* @param {Object} [options]
48+
* @param {object} [options]
4949
* @param {boolean} [options.statsEnabled=false]
5050
* @param {number} [options.statsComputeThrottleTimeout=1000]
5151
* @param {number} [options.statsComputeThrottleMaxQueueSize=1000]
@@ -157,7 +157,7 @@ export class Bitswap extends BaseBlockstore {
157157

158158
const has = await this.blockstore.has(cid)
159159

160-
this._updateReceiveCounters(peerId.toB58String(), cid, data, has)
160+
this._updateReceiveCounters(peerId.toString(), cid, data, has)
161161

162162
if (!wasWanted) {
163163
return
@@ -244,13 +244,13 @@ export class Bitswap extends BaseBlockstore {
244244
* blockstore it is returned, otherwise the block is added to the wantlist and returned once another node sends it to us.
245245
*
246246
* @param {CID} cid
247-
* @param {Object} [options]
247+
* @param {object} [options]
248248
* @param {AbortSignal} [options.signal]
249249
*/
250250
async get (cid, options = {}) {
251251
/**
252252
* @param {CID} cid
253-
* @param {Object} options
253+
* @param {object} options
254254
* @param {AbortSignal} options.signal
255255
*/
256256
const fetchFromNetwork = (cid, options) => {
@@ -266,7 +266,7 @@ export class Bitswap extends BaseBlockstore {
266266
/**
267267
*
268268
* @param {CID} cid
269-
* @param {Object} options
269+
* @param {object} options
270270
* @param {AbortSignal} options.signal
271271
*/
272272
const loadOrFetchFromNetwork = async (cid, options) => {
@@ -283,7 +283,7 @@ export class Bitswap extends BaseBlockstore {
283283
if (!promptedNetwork) {
284284
promptedNetwork = true
285285

286-
this.network.findAndConnect(cid)
286+
this.network.findAndConnect(cid, options)
287287
.catch((err) => this._log.error(err))
288288
}
289289

@@ -301,27 +301,29 @@ export class Bitswap extends BaseBlockstore {
301301
? anySignal([options.signal, controller.signal])
302302
: controller.signal
303303

304-
const block = await Promise.race([
305-
this.notifications.wantBlock(cid, {
306-
signal
307-
}),
308-
loadOrFetchFromNetwork(cid, {
309-
signal
310-
})
311-
])
312-
313-
// since we have the block we can now remove our listener
314-
controller.abort()
315-
316-
return block
304+
try {
305+
const block = await Promise.race([
306+
this.notifications.wantBlock(cid, {
307+
signal
308+
}),
309+
loadOrFetchFromNetwork(cid, {
310+
signal
311+
})
312+
])
313+
314+
return block
315+
} finally {
316+
// since we have the block we can now remove our listener
317+
controller.abort()
318+
}
317319
}
318320

319321
/**
320322
* Fetch a a list of blocks by cid. If the blocks are in the local
321323
* blockstore they are returned, otherwise the blocks are added to the wantlist and returned once another node sends them to us.
322324
*
323325
* @param {AsyncIterable<CID>|Iterable<CID>} cids
324-
* @param {Object} [options]
326+
* @param {object} [options]
325327
* @param {AbortSignal} [options.signal]
326328
*/
327329
async * getMany (cids, options = {}) {

0 commit comments

Comments
 (0)