Skip to content

Commit 50ffd30

Browse files
authored
Merge pull request #36 from saul-jb/chore/update-packages
chore!: Update packages.
2 parents 73998b3 + 4129df2 commit 50ffd30

13 files changed

+20906
-14548
lines changed

package-lock.json

+20,837-14,479
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+35-34
Original file line numberDiff line numberDiff line change
@@ -76,47 +76,48 @@
7676
"url": "https://github.com/tabcat/zzzync/issues"
7777
},
7878
"homepage": "https://github.com/tabcat/zzzync#readme",
79+
"typedoc": {
80+
"entryPoint": "./src/index.ts"
81+
},
82+
"browser": {
83+
"./dist/test/utils/create-libp2p.js": "./dist/test/utils/create-libp2p.browser.js"
84+
},
7985
"devDependencies": {
80-
"@chainsafe/libp2p-noise": "^12.0.1",
81-
"@chainsafe/libp2p-yamux": "^5.0.0",
82-
"@libp2p/peer-id-factory": "^2.0.3",
83-
"@libp2p/tcp": "^7.0.1",
84-
"@libp2p/webrtc": "^2.0.6",
85-
"aegir": "^39.0.5",
86-
"blockstore-core": "^4.2.0",
87-
"go-ipfs": "^0.20.0",
88-
"helia": "^2.0.1",
86+
"@chainsafe/libp2p-noise": "^14.1.0",
87+
"@chainsafe/libp2p-yamux": "^6.0.1",
88+
"@libp2p/circuit-relay-v2": "^1.0.10",
89+
"@libp2p/identify": "^1.0.9",
90+
"@libp2p/peer-id-factory": "^4.0.3",
91+
"@libp2p/tcp": "^9.0.10",
92+
"@libp2p/webrtc": "^4.0.14",
93+
"aegir": "^42.1.0",
94+
"blockstore-core": "^4.3.10",
95+
"go-ipfs": "^0.22.0",
96+
"helia": "^3.0.0",
8997
"ipfsd-ctl": "^13.0.0",
90-
"ipns": "^6.0.0",
91-
"kubo-rpc-client": "^3.0.1",
98+
"kubo-rpc-client": "^3.0.2",
9299
"merge-options": "^3.0.4",
93100
"wherearewe": "^2.0.1"
94101
},
95-
"typedoc": {
96-
"entryPoint": "./src/index.ts"
97-
},
98102
"dependencies": {
99-
"@helia/interface": "^2.0.0",
100-
"@helia/ipns": "^1.1.3",
101-
"@ipld/car": "^5.2.2",
102-
"@libp2p/interface": "^0.1.2",
103-
"@libp2p/kad-dht": "^10.0.5",
104-
"@libp2p/websockets": "^6.0.1",
105-
"@multiformats/multiaddr": "^12.1.3",
106-
"datastore-core": "^9.1.1",
107-
"interface-blockstore": "^5.2.6",
108-
"interface-blockstore-tests": "^6.1.5",
109-
"interface-datastore": "^8.2.2",
110-
"interface-store": "^5.1.4",
111-
"it-drain": "^3.0.3",
112-
"libp2p": "^0.46.9",
113-
"libp2p-crypto": "^0.21.2",
114-
"multiformats": "^11.0.2",
115-
"uint8arrays": "^4.0.6",
103+
"@helia/interface": "^3.0.0",
104+
"@helia/ipns": "^4.0.0",
105+
"@ipld/car": "^5.2.5",
106+
"@libp2p/crypto": "^3.0.4",
107+
"@libp2p/interface": "^1.1.1",
108+
"@libp2p/kad-dht": "^12.0.2",
109+
"@libp2p/websockets": "^8.0.10",
110+
"@multiformats/multiaddr": "^12.1.12",
111+
"datastore-core": "^9.2.7",
112+
"interface-blockstore": "^5.2.9",
113+
"interface-blockstore-tests": "^6.1.9",
114+
"interface-datastore": "^8.2.10",
115+
"interface-store": "^5.1.7",
116+
"it-drain": "^3.0.5",
117+
"libp2p": "^1.1.1",
118+
"multiformats": "^13.0.0",
119+
"uint8arrays": "^5.0.1",
116120
"w3name": "^1.0.8",
117121
"web3.storage": "^4.5.5"
118-
},
119-
"browser": {
120-
"./dist/test/utils/create-libp2p.js": "./dist/test/utils/create-libp2p.browser.js"
121122
}
122123
}

src/advertisers/dht.ts

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import drain from 'it-drain'
22
import type { Advertiser } from '../index.js'
3+
import type { ContentRouting } from '@libp2p/interface/content-routing'
34
import type { PeerId } from '@libp2p/interface/peer-id'
45
import type { KadDHT } from '@libp2p/kad-dht'
56
import type { CID } from 'multiformats/cid'
67

78
export interface CreateEphemeralKadDHT {
8-
(provider: PeerId): Promise<{ dht: KadDHT, stop?: () => Promise<void> }>
9+
(provider: PeerId): Promise<{ dht: KadDHT, stop?(): Promise<void> }>
910
}
1011

1112
const collaborate = (createEphemeralKadDHT: CreateEphemeralKadDHT): Advertiser['collaborate'] =>
@@ -21,25 +22,21 @@ const collaborate = (createEphemeralKadDHT: CreateEphemeralKadDHT): Advertiser['
2122
}
2223
}
2324

24-
const findCollaborators = (dht: KadDHT): Advertiser['findCollaborators'] =>
25+
const findCollaborators = (libp2p: { contentRouting: ContentRouting }): Advertiser['findCollaborators'] =>
2526
async function * (dcid: CID): AsyncIterable<PeerId> {
2627
try {
27-
for await (const event of dht.findProviders(dcid)) {
28-
if (event.name === 'PROVIDER' || event.name === 'PEER_RESPONSE') {
29-
for (const { id: peerId } of event.providers) {
30-
yield peerId
31-
}
32-
}
28+
for await (const peerInfo of libp2p.contentRouting.findProviders(dcid)) {
29+
yield peerInfo.id
3330
}
3431
} catch (e) {
3532
// eslint-disable-next-line no-console
3633
console.error(e)
3734
}
3835
}
3936

40-
export function dhtAdvertiser (dht: KadDHT, createEphemeralKadDHT: CreateEphemeralKadDHT): Advertiser {
37+
export function dhtAdvertiser (libp2p: { contentRouting: ContentRouting }, createEphemeralKadDHT: CreateEphemeralKadDHT): Advertiser {
4138
return {
4239
collaborate: collaborate(createEphemeralKadDHT),
43-
findCollaborators: findCollaborators(dht)
40+
findCollaborators: findCollaborators(libp2p)
4441
}
4542
}

src/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ import type { CID } from 'multiformats/cid'
1414
export { toDcid } from './dcid.js'
1515

1616
export interface Advertiser {
17-
collaborate: (dcid: CID, provider: PeerId) => Promise<void>
18-
findCollaborators: (dcid: CID) => AsyncIterable<PeerId>
17+
collaborate(dcid: CID, provider: PeerId): Promise<void>
18+
findCollaborators(dcid: CID): AsyncIterable<PeerId>
1919
}
2020

2121
export interface Namer {
22-
publish: (key: Ed25519PeerId, value: CID) => Promise<void>
23-
resolve: (key: Ed25519PeerId) => Promise<CID>
22+
publish(key: Ed25519PeerId, value: CID): Promise<void>
23+
resolve(key: Ed25519PeerId): Promise<CID>
2424
}
2525

2626
export interface Pinner extends Blockstore {}

src/namers/ipns.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ipns, type IPNS } from '@helia/ipns'
2-
import { dht } from '@helia/ipns/routing'
2+
import { libp2p } from '@helia/ipns/routing'
33
import type { Namer } from '../index.js'
44
import type { Helia } from '@helia/interface'
55
import type { Ed25519PeerId } from '@libp2p/interface/peer-id'
@@ -12,7 +12,7 @@ const resolve = (ipns: IPNS): Namer['resolve'] =>
1212
async (peerId: Ed25519PeerId) => ipns.resolve(peerId)
1313

1414
export function ipnsNamer (helia: Helia): Namer {
15-
const ns = ipns(helia, [dht(helia)])
15+
const ns = ipns(helia, { routers: [libp2p(helia)] })
1616

1717
return {
1818
publish: publish(ns),

src/namers/w3.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import type { Await } from 'interface-store'
99
import type W3NameService from 'w3name/service'
1010

1111
export interface RevisionState {
12-
get: (peerId: Ed25519PeerId) => Await<Name.Revision | undefined>
13-
set: (peerId: Ed25519PeerId, revision: Name.Revision) => Await<void>
12+
get(peerId: Ed25519PeerId): Await<Name.Revision | undefined>
13+
set(peerId: Ed25519PeerId, revision: Name.Revision): Await<void>
1414
}
1515

1616
const ipfsPrefix = '/ipfs/'

test/advertisers/dht.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe('advertisers/dht.ts', () => {
3838
server = await createLibp2pNode()
3939
addrs = server.getMultiaddrs()
4040
await client.dialProtocol(addrs, lanKadProtocol)
41-
advertiser = dhtAdvertiser(client.services.dht, createEphemeralKadDHT)
41+
advertiser = dhtAdvertiser(client, createEphemeralKadDHT)
4242
provider = await createEd25519PeerId()
4343
dcid = CID.parse('bafyreihypffwyzhujryetatiy5imqq3p4mokuz36xmgp7wfegnhnjhwrsq')
4444
})

test/aegir.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { readFileSync } from 'fs'
22
import { noise } from '@chainsafe/libp2p-noise'
33
import { yamux } from '@chainsafe/libp2p-yamux'
4+
import { circuitRelayServer } from '@libp2p/circuit-relay-v2'
5+
import { type Identify, identify } from '@libp2p/identify'
46
import { type KadDHT, kadDHT } from '@libp2p/kad-dht'
57
import { tcp } from '@libp2p/tcp'
68
import { webSockets } from '@libp2p/websockets'
@@ -12,8 +14,6 @@ import { createHelia } from 'helia'
1214
import { ipnsSelector } from 'ipns/selector'
1315
import { ipnsValidator } from 'ipns/validator'
1416
import { type Libp2pOptions, createLibp2p, type Libp2p } from 'libp2p'
15-
import { circuitRelayServer } from 'libp2p/circuit-relay'
16-
import { type IdentifyService, identifyService } from 'libp2p/identify'
1717
// import w3nameServer from './mocks/w3name.js'
1818
import type { Helia } from '@helia/interface'
1919
import type { ServiceMap } from '@libp2p/interface'
@@ -29,7 +29,7 @@ try {
2929
}
3030

3131
interface Services extends ServiceMap {
32-
identify: IdentifyService
32+
identify: Identify
3333
dht: KadDHT
3434
}
3535

@@ -55,7 +55,7 @@ async function createLibp2pNode (): Promise<Libp2p<Services>> {
5555
],
5656
datastore,
5757
services: {
58-
identify: identifyService(),
58+
identify: identify(),
5959
dht: kadDHT({
6060
validators: { ipns: ipnsValidator },
6161
selectors: { ipns: ipnsSelector }

test/mocks/w3name.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ const server = http.createServer((req, res) => {
5555
entry = ipns.unmarshal(record)
5656
res.write(
5757
JSON.stringify({
58-
value: uint8arrays.toString(entry.value, 'base64pad'),
58+
value: entry.value,
5959
record: db.get(key)
6060
})
6161
)

test/utils/create-kubo.ts

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
// @ts-expect-error no types
31
import * as goIpfs from 'go-ipfs'
42
import { type Controller, type ControllerOptions, createController } from 'ipfsd-ctl'
53
import * as kuboRpcClient from 'kubo-rpc-client'

test/utils/create-libp2p.browser.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { noise } from '@chainsafe/libp2p-noise'
22
import { yamux } from '@chainsafe/libp2p-yamux'
3+
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
34
import { webRTC, webRTCDirect } from '@libp2p/webrtc'
45
import { webSockets } from '@libp2p/websockets'
56
import * as filters from '@libp2p/websockets/filters'
67
import { multiaddr } from '@multiformats/multiaddr'
78
import { MemoryDatastore } from 'datastore-core'
89
import { createLibp2p, type Libp2p, type Libp2pOptions } from 'libp2p'
9-
import { circuitRelayTransport } from 'libp2p/circuit-relay'
1010
import services, { type Services } from './services.js'
1111

1212
export async function createLibp2pNode (options?: Libp2pOptions<any>): Promise<Libp2p<Services>> {

test/utils/create-libp2p.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { noise } from '@chainsafe/libp2p-noise'
22
import { yamux } from '@chainsafe/libp2p-yamux'
3+
import { circuitRelayServer, type CircuitRelayService } from '@libp2p/circuit-relay-v2'
34
import { tcp } from '@libp2p/tcp'
45
import { webSockets } from '@libp2p/websockets'
56
import * as filters from '@libp2p/websockets/filters'
67
import { MemoryDatastore } from 'datastore-core'
78
import { createLibp2p, type Libp2p } from 'libp2p'
8-
import { circuitRelayServer, type CircuitRelayService } from 'libp2p/circuit-relay'
99
import services, { type Services } from './services.js'
1010
import type { PeerId } from '@libp2p/interface/peer-id'
1111

test/utils/services.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
1-
import { type KadDHT, kadDHT } from '@libp2p/kad-dht'
2-
import { ipnsSelector } from 'ipns/selector'
3-
import { ipnsValidator } from 'ipns/validator'
4-
import { type IdentifyService, identifyService } from 'libp2p/identify'
1+
import { ipnsSelector, ipnsValidator } from '@helia/ipns'
2+
import { type Identify, identify } from '@libp2p/identify'
3+
import { type KadDHT, kadDHT, removePublicAddressesMapper } from '@libp2p/kad-dht'
4+
import { lanKadProtocol } from './protocols.js'
55
import type { ServiceMap } from '@libp2p/interface'
66

77
export interface Services extends ServiceMap {
8-
identify: IdentifyService
8+
identify: Identify
99
dht: KadDHT
1010
}
1111

1212
const services = {
13-
identify: identifyService(),
13+
identify: identify(),
14+
1415
dht: kadDHT({
16+
protocol: lanKadProtocol,
17+
peerInfoMapper: removePublicAddressesMapper,
1518
validators: { ipns: ipnsValidator },
16-
selectors: { ipns: ipnsSelector }
19+
selectors: { ipns: ipnsSelector },
20+
clientMode: false
1721
})
1822
}
1923

0 commit comments

Comments
 (0)