Skip to content

Commit

Permalink
Merge pull request #36 from saul-jb/chore/update-packages
Browse files Browse the repository at this point in the history
chore!: Update packages.
  • Loading branch information
tabcat authored Jan 9, 2024
2 parents 73998b3 + 4129df2 commit 50ffd30
Show file tree
Hide file tree
Showing 13 changed files with 20,906 additions and 14,548 deletions.
35,316 changes: 20,837 additions & 14,479 deletions package-lock.json

Large diffs are not rendered by default.

69 changes: 35 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,47 +76,48 @@
"url": "https://github.com/tabcat/zzzync/issues"
},
"homepage": "https://github.com/tabcat/zzzync#readme",
"typedoc": {
"entryPoint": "./src/index.ts"
},
"browser": {
"./dist/test/utils/create-libp2p.js": "./dist/test/utils/create-libp2p.browser.js"
},
"devDependencies": {
"@chainsafe/libp2p-noise": "^12.0.1",
"@chainsafe/libp2p-yamux": "^5.0.0",
"@libp2p/peer-id-factory": "^2.0.3",
"@libp2p/tcp": "^7.0.1",
"@libp2p/webrtc": "^2.0.6",
"aegir": "^39.0.5",
"blockstore-core": "^4.2.0",
"go-ipfs": "^0.20.0",
"helia": "^2.0.1",
"@chainsafe/libp2p-noise": "^14.1.0",
"@chainsafe/libp2p-yamux": "^6.0.1",
"@libp2p/circuit-relay-v2": "^1.0.10",
"@libp2p/identify": "^1.0.9",
"@libp2p/peer-id-factory": "^4.0.3",
"@libp2p/tcp": "^9.0.10",
"@libp2p/webrtc": "^4.0.14",
"aegir": "^42.1.0",
"blockstore-core": "^4.3.10",
"go-ipfs": "^0.22.0",
"helia": "^3.0.0",
"ipfsd-ctl": "^13.0.0",
"ipns": "^6.0.0",
"kubo-rpc-client": "^3.0.1",
"kubo-rpc-client": "^3.0.2",
"merge-options": "^3.0.4",
"wherearewe": "^2.0.1"
},
"typedoc": {
"entryPoint": "./src/index.ts"
},
"dependencies": {
"@helia/interface": "^2.0.0",
"@helia/ipns": "^1.1.3",
"@ipld/car": "^5.2.2",
"@libp2p/interface": "^0.1.2",
"@libp2p/kad-dht": "^10.0.5",
"@libp2p/websockets": "^6.0.1",
"@multiformats/multiaddr": "^12.1.3",
"datastore-core": "^9.1.1",
"interface-blockstore": "^5.2.6",
"interface-blockstore-tests": "^6.1.5",
"interface-datastore": "^8.2.2",
"interface-store": "^5.1.4",
"it-drain": "^3.0.3",
"libp2p": "^0.46.9",
"libp2p-crypto": "^0.21.2",
"multiformats": "^11.0.2",
"uint8arrays": "^4.0.6",
"@helia/interface": "^3.0.0",
"@helia/ipns": "^4.0.0",
"@ipld/car": "^5.2.5",
"@libp2p/crypto": "^3.0.4",
"@libp2p/interface": "^1.1.1",
"@libp2p/kad-dht": "^12.0.2",
"@libp2p/websockets": "^8.0.10",
"@multiformats/multiaddr": "^12.1.12",
"datastore-core": "^9.2.7",
"interface-blockstore": "^5.2.9",
"interface-blockstore-tests": "^6.1.9",
"interface-datastore": "^8.2.10",
"interface-store": "^5.1.7",
"it-drain": "^3.0.5",
"libp2p": "^1.1.1",
"multiformats": "^13.0.0",
"uint8arrays": "^5.0.1",
"w3name": "^1.0.8",
"web3.storage": "^4.5.5"
},
"browser": {
"./dist/test/utils/create-libp2p.js": "./dist/test/utils/create-libp2p.browser.js"
}
}
17 changes: 7 additions & 10 deletions src/advertisers/dht.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import drain from 'it-drain'
import type { Advertiser } from '../index.js'
import type { ContentRouting } from '@libp2p/interface/content-routing'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { KadDHT } from '@libp2p/kad-dht'
import type { CID } from 'multiformats/cid'

export interface CreateEphemeralKadDHT {
(provider: PeerId): Promise<{ dht: KadDHT, stop?: () => Promise<void> }>
(provider: PeerId): Promise<{ dht: KadDHT, stop?(): Promise<void> }>
}

const collaborate = (createEphemeralKadDHT: CreateEphemeralKadDHT): Advertiser['collaborate'] =>
Expand All @@ -21,25 +22,21 @@ const collaborate = (createEphemeralKadDHT: CreateEphemeralKadDHT): Advertiser['
}
}

const findCollaborators = (dht: KadDHT): Advertiser['findCollaborators'] =>
const findCollaborators = (libp2p: { contentRouting: ContentRouting }): Advertiser['findCollaborators'] =>
async function * (dcid: CID): AsyncIterable<PeerId> {
try {
for await (const event of dht.findProviders(dcid)) {
if (event.name === 'PROVIDER' || event.name === 'PEER_RESPONSE') {
for (const { id: peerId } of event.providers) {
yield peerId
}
}
for await (const peerInfo of libp2p.contentRouting.findProviders(dcid)) {
yield peerInfo.id
}
} catch (e) {
// eslint-disable-next-line no-console
console.error(e)
}
}

export function dhtAdvertiser (dht: KadDHT, createEphemeralKadDHT: CreateEphemeralKadDHT): Advertiser {
export function dhtAdvertiser (libp2p: { contentRouting: ContentRouting }, createEphemeralKadDHT: CreateEphemeralKadDHT): Advertiser {
return {
collaborate: collaborate(createEphemeralKadDHT),
findCollaborators: findCollaborators(dht)
findCollaborators: findCollaborators(libp2p)
}
}
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import type { CID } from 'multiformats/cid'
export { toDcid } from './dcid.js'

export interface Advertiser {
collaborate: (dcid: CID, provider: PeerId) => Promise<void>
findCollaborators: (dcid: CID) => AsyncIterable<PeerId>
collaborate(dcid: CID, provider: PeerId): Promise<void>
findCollaborators(dcid: CID): AsyncIterable<PeerId>
}

export interface Namer {
publish: (key: Ed25519PeerId, value: CID) => Promise<void>
resolve: (key: Ed25519PeerId) => Promise<CID>
publish(key: Ed25519PeerId, value: CID): Promise<void>
resolve(key: Ed25519PeerId): Promise<CID>
}

export interface Pinner extends Blockstore {}
Expand Down
4 changes: 2 additions & 2 deletions src/namers/ipns.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ipns, type IPNS } from '@helia/ipns'
import { dht } from '@helia/ipns/routing'
import { libp2p } from '@helia/ipns/routing'
import type { Namer } from '../index.js'
import type { Helia } from '@helia/interface'
import type { Ed25519PeerId } from '@libp2p/interface/peer-id'
Expand All @@ -12,7 +12,7 @@ const resolve = (ipns: IPNS): Namer['resolve'] =>
async (peerId: Ed25519PeerId) => ipns.resolve(peerId)

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

return {
publish: publish(ns),
Expand Down
4 changes: 2 additions & 2 deletions src/namers/w3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import type { Await } from 'interface-store'
import type W3NameService from 'w3name/service'

export interface RevisionState {
get: (peerId: Ed25519PeerId) => Await<Name.Revision | undefined>
set: (peerId: Ed25519PeerId, revision: Name.Revision) => Await<void>
get(peerId: Ed25519PeerId): Await<Name.Revision | undefined>
set(peerId: Ed25519PeerId, revision: Name.Revision): Await<void>
}

const ipfsPrefix = '/ipfs/'
Expand Down
2 changes: 1 addition & 1 deletion test/advertisers/dht.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('advertisers/dht.ts', () => {
server = await createLibp2pNode()
addrs = server.getMultiaddrs()
await client.dialProtocol(addrs, lanKadProtocol)
advertiser = dhtAdvertiser(client.services.dht, createEphemeralKadDHT)
advertiser = dhtAdvertiser(client, createEphemeralKadDHT)
provider = await createEd25519PeerId()
dcid = CID.parse('bafyreihypffwyzhujryetatiy5imqq3p4mokuz36xmgp7wfegnhnjhwrsq')
})
Expand Down
8 changes: 4 additions & 4 deletions test/aegir.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { readFileSync } from 'fs'
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { circuitRelayServer } from '@libp2p/circuit-relay-v2'
import { type Identify, identify } from '@libp2p/identify'
import { type KadDHT, kadDHT } from '@libp2p/kad-dht'
import { tcp } from '@libp2p/tcp'
import { webSockets } from '@libp2p/websockets'
Expand All @@ -12,8 +14,6 @@ import { createHelia } from 'helia'
import { ipnsSelector } from 'ipns/selector'
import { ipnsValidator } from 'ipns/validator'
import { type Libp2pOptions, createLibp2p, type Libp2p } from 'libp2p'
import { circuitRelayServer } from 'libp2p/circuit-relay'
import { type IdentifyService, identifyService } from 'libp2p/identify'
// import w3nameServer from './mocks/w3name.js'
import type { Helia } from '@helia/interface'
import type { ServiceMap } from '@libp2p/interface'
Expand All @@ -29,7 +29,7 @@ try {
}

interface Services extends ServiceMap {
identify: IdentifyService
identify: Identify
dht: KadDHT
}

Expand All @@ -55,7 +55,7 @@ async function createLibp2pNode (): Promise<Libp2p<Services>> {
],
datastore,
services: {
identify: identifyService(),
identify: identify(),
dht: kadDHT({
validators: { ipns: ipnsValidator },
selectors: { ipns: ipnsSelector }
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/w3name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const server = http.createServer((req, res) => {
entry = ipns.unmarshal(record)
res.write(
JSON.stringify({
value: uint8arrays.toString(entry.value, 'base64pad'),
value: entry.value,
record: db.get(key)
})
)
Expand Down
2 changes: 0 additions & 2 deletions test/utils/create-kubo.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

// @ts-expect-error no types
import * as goIpfs from 'go-ipfs'
import { type Controller, type ControllerOptions, createController } from 'ipfsd-ctl'
import * as kuboRpcClient from 'kubo-rpc-client'
Expand Down
2 changes: 1 addition & 1 deletion test/utils/create-libp2p.browser.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
import { webRTC, webRTCDirect } from '@libp2p/webrtc'
import { webSockets } from '@libp2p/websockets'
import * as filters from '@libp2p/websockets/filters'
import { multiaddr } from '@multiformats/multiaddr'
import { MemoryDatastore } from 'datastore-core'
import { createLibp2p, type Libp2p, type Libp2pOptions } from 'libp2p'
import { circuitRelayTransport } from 'libp2p/circuit-relay'
import services, { type Services } from './services.js'

export async function createLibp2pNode (options?: Libp2pOptions<any>): Promise<Libp2p<Services>> {
Expand Down
2 changes: 1 addition & 1 deletion test/utils/create-libp2p.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { noise } from '@chainsafe/libp2p-noise'
import { yamux } from '@chainsafe/libp2p-yamux'
import { circuitRelayServer, type CircuitRelayService } from '@libp2p/circuit-relay-v2'
import { tcp } from '@libp2p/tcp'
import { webSockets } from '@libp2p/websockets'
import * as filters from '@libp2p/websockets/filters'
import { MemoryDatastore } from 'datastore-core'
import { createLibp2p, type Libp2p } from 'libp2p'
import { circuitRelayServer, type CircuitRelayService } from 'libp2p/circuit-relay'
import services, { type Services } from './services.js'
import type { PeerId } from '@libp2p/interface/peer-id'

Expand Down
18 changes: 11 additions & 7 deletions test/utils/services.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { type KadDHT, kadDHT } from '@libp2p/kad-dht'
import { ipnsSelector } from 'ipns/selector'
import { ipnsValidator } from 'ipns/validator'
import { type IdentifyService, identifyService } from 'libp2p/identify'
import { ipnsSelector, ipnsValidator } from '@helia/ipns'
import { type Identify, identify } from '@libp2p/identify'
import { type KadDHT, kadDHT, removePublicAddressesMapper } from '@libp2p/kad-dht'
import { lanKadProtocol } from './protocols.js'
import type { ServiceMap } from '@libp2p/interface'

export interface Services extends ServiceMap {
identify: IdentifyService
identify: Identify
dht: KadDHT
}

const services = {
identify: identifyService(),
identify: identify(),

dht: kadDHT({
protocol: lanKadProtocol,
peerInfoMapper: removePublicAddressesMapper,
validators: { ipns: ipnsValidator },
selectors: { ipns: ipnsSelector }
selectors: { ipns: ipnsSelector },
clientMode: false
})
}

Expand Down

0 comments on commit 50ffd30

Please sign in to comment.