Skip to content

Commit

Permalink
deps: bump @libp2p/interface from 0.1.6 to 1.1.1 (#91)
Browse files Browse the repository at this point in the history
Bumps [@libp2p/interface](https://github.com/libp2p/js-libp2p) from 0.1.6 to 1.1.1.
- [Release notes](https://github.com/libp2p/js-libp2p/releases)
- [Changelog](https://github.com/libp2p/js-libp2p/blob/main/.release-please.json)
- [Commits](libp2p/js-libp2p@interface-v0.1.6...perf-v1.1.1)

---
updated-dependencies:
- dependency-name: "@libp2p/interface"
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: achingbrain <[email protected]>
  • Loading branch information
dependabot[bot] and achingbrain authored Jan 15, 2024
1 parent c9936ca commit 50e4864
Show file tree
Hide file tree
Showing 15 changed files with 142 additions and 94 deletions.
10 changes: 5 additions & 5 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@
"test:node": "aegir test -t node --cov"
},
"dependencies": {
"@libp2p/interface": "^0.1.2",
"@libp2p/logger": "^3.0.2",
"@libp2p/peer-id": "^3.0.3",
"@libp2p/interface": "^1.1.1",
"@libp2p/logger": "^4.0.4",
"@libp2p/peer-id": "^4.0.4",
"@multiformats/multiaddr": "^12.1.3",
"any-signal": "^4.1.1",
"browser-readablestream-to-it": "^2.0.3",
"ipns": "^7.0.1",
"ipns": "^8.0.1",
"it-first": "^3.0.3",
"it-map": "^3.0.4",
"it-ndjson": "^1.0.4",
Expand All @@ -60,7 +60,7 @@
"uint8arrays": "^5.0.1"
},
"devDependencies": {
"@libp2p/peer-id-factory": "^3.0.5",
"@libp2p/peer-id-factory": "^4.0.4",
"aegir": "^42.2.0",
"body-parser": "^1.20.2",
"it-all": "^3.0.2"
Expand Down
62 changes: 47 additions & 15 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { type ContentRouting, contentRouting } from '@libp2p/interface/content-routing'
import { CodeError } from '@libp2p/interface/errors'
import { setMaxListeners } from '@libp2p/interface/events'
import { type PeerRouting, peerRouting } from '@libp2p/interface/peer-routing'
import { contentRoutingSymbol, peerRoutingSymbol, CodeError, setMaxListeners } from '@libp2p/interface'
import { logger } from '@libp2p/logger'
import { peerIdFromString } from '@libp2p/peer-id'
import { multiaddr } from '@multiformats/multiaddr'
Expand All @@ -14,8 +11,7 @@ import defer from 'p-defer'
import PQueue from 'p-queue'
import { DelegatedRoutingV1HttpApiClientContentRouting, DelegatedRoutingV1HttpApiClientPeerRouting } from './routings.js'
import type { DelegatedRoutingV1HttpApiClient, DelegatedRoutingV1HttpApiClientInit, PeerRecord } from './index.js'
import type { AbortOptions } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { ContentRouting, PeerRouting, AbortOptions, PeerId } from '@libp2p/interface'
import type { CID } from 'multiformats'

const log = logger('delegated-routing-v1-http-api-client')
Expand Down Expand Up @@ -50,11 +46,11 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
this.peerRouting = new DelegatedRoutingV1HttpApiClientPeerRouting(this)
}

get [contentRouting] (): ContentRouting {
get [contentRoutingSymbol] (): ContentRouting {
return this.contentRouting
}

get [peerRouting] (): PeerRouting {
get [peerRoutingSymbol] (): PeerRouting {
return this.peerRouting
}

Expand Down Expand Up @@ -92,6 +88,18 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
const getOptions = { headers: { Accept: 'application/x-ndjson' }, signal }
const res = await fetch(resource, getOptions)

if (res.status === 404) {
// https://specs.ipfs.tech/routing/http-routing-v1/#response-status-codes
// 404 (Not Found): must be returned if no matching records are found.
throw new CodeError('No matching records found.', 'ERR_NOT_FOUND')
}

if (res.status === 422) {
// https://specs.ipfs.tech/routing/http-routing-v1/#response-status-codes
// 422 (Unprocessable Entity): request does not conform to schema or semantic constraints.
throw new CodeError('Request does not conform to schema or semantic constraints.', 'ERR_INVALID_REQUEST')
}

if (res.body == null) {
throw new CodeError('Routing response had no body', 'ERR_BAD_RESPONSE')
}
Expand Down Expand Up @@ -143,6 +151,18 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
const getOptions = { headers: { Accept: 'application/x-ndjson' }, signal }
const res = await fetch(resource, getOptions)

if (res.status === 404) {
// https://specs.ipfs.tech/routing/http-routing-v1/#response-status-codes
// 404 (Not Found): must be returned if no matching records are found.
throw new CodeError('No matching records found.', 'ERR_NOT_FOUND')
}

if (res.status === 422) {
// https://specs.ipfs.tech/routing/http-routing-v1/#response-status-codes
// 422 (Unprocessable Entity): request does not conform to schema or semantic constraints.
throw new CodeError('Request does not conform to schema or semantic constraints.', 'ERR_INVALID_REQUEST')
}

if (res.body == null) {
throw new CodeError('Routing response had no body', 'ERR_BAD_RESPONSE')
}
Expand Down Expand Up @@ -194,11 +214,24 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
const getOptions = { headers: { Accept: 'application/vnd.ipfs.ipns-record' }, signal }
const res = await fetch(resource, getOptions)

if (res.status === 404) {
// https://specs.ipfs.tech/routing/http-routing-v1/#response-status-codes
// 404 (Not Found): must be returned if no matching records are found.
throw new CodeError('No matching records found.', 'ERR_NOT_FOUND')
}

if (res.status === 422) {
// https://specs.ipfs.tech/routing/http-routing-v1/#response-status-codes
// 422 (Unprocessable Entity): request does not conform to schema or semantic constraints.
throw new CodeError('Request does not conform to schema or semantic constraints.', 'ERR_INVALID_REQUEST')
}

if (res.body == null) {
throw new CodeError('GET ipns response had no body', 'ERR_BAD_RESPONSE')
}

const body = new Uint8Array(await res.arrayBuffer())

await ipnsValidator(peerIdToRoutingKey(peerId), body)
return unmarshal(body)
} finally {
Expand Down Expand Up @@ -243,8 +276,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
if (record.Schema === 'peer') {
// Peer schema can have additional, user-defined, fields.
record.ID = peerIdFromString(record.ID)
record.Addrs = record.Addrs.map(multiaddr)
record.Protocols = record.Protocols ?? []
record.Addrs = record.Addrs?.map(multiaddr) ?? []
return record
}

Expand All @@ -255,17 +287,17 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
return {
Schema: 'peer',
ID: peerIdFromString(record.ID),
Addrs: record.Addrs.map(multiaddr),
Protocols: record.Protocol != null ? [record.Protocol] : []
Addrs: record.Addrs?.map(multiaddr) ?? [],
Protocol: record.Protocol
}
}

if (record.ID != null && Array.isArray(record.Addrs)) {
return {
Schema: 'peer',
ID: peerIdFromString(record.ID),
Addrs: record.Addrs.map(multiaddr),
Protocols: Array.isArray(record.Protocols) ? record.Protocols : []
Addrs: record.Addrs?.map(multiaddr) ?? [],
Protocol: record.Protocol
}
}
}
Expand All @@ -274,7 +306,7 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
if (record.Schema === 'peer') {
// Peer schema can have additional, user-defined, fields.
record.ID = peerIdFromString(record.ID)
record.Addrs = record.Addrs.map(multiaddr)
record.Addrs = record.Addrs?.map(multiaddr) ?? []
if (peerId.equals(record.ID)) {
return record
}
Expand Down
8 changes: 4 additions & 4 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@
*/

import { DefaultDelegatedRoutingV1HttpApiClient } from './client.js'
import type { AbortOptions } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { AbortOptions, PeerId } from '@libp2p/interface'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { IPNSRecord } from 'ipns'
import type { CID } from 'multiformats/cid'

export interface PeerRecord {
Schema: 'peer'
ID: PeerId
Addrs: Multiaddr[]
Protocols: string[]
Addrs?: Multiaddr[]
Protocol: string
Metadata?: string
}

export interface DelegatedRoutingV1HttpApiClientInit {
Expand Down
14 changes: 4 additions & 10 deletions packages/client/src/routings.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { type ContentRouting } from '@libp2p/interface/content-routing'
import { CodeError } from '@libp2p/interface/errors'
import { type PeerRouting } from '@libp2p/interface/peer-routing'
import { type ContentRouting, type PeerRouting, type AbortOptions, type PeerId, type PeerInfo } from '@libp2p/interface'
import { CodeError } from '@libp2p/interface'
import { peerIdFromBytes } from '@libp2p/peer-id'
import { marshal, unmarshal } from 'ipns'
import first from 'it-first'
import map from 'it-map'
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import type { DelegatedRoutingV1HttpApiClient } from './index.js'
import type { AbortOptions } from '@libp2p/interface'
import type { PeerId } from '@libp2p/interface/peer-id'
import type { PeerInfo } from '@libp2p/interface/peer-info'
import type { CID } from 'multiformats/cid'

const IPNS_PREFIX = uint8ArrayFromString('/ipns/')
Expand All @@ -37,8 +33,7 @@ export class DelegatedRoutingV1HttpApiClientContentRouting implements ContentRou
yield * map(this.client.getProviders(cid, options), (record) => {
return {
id: record.ID,
multiaddrs: record.Addrs ?? [],
protocols: []
multiaddrs: record.Addrs ?? []
}
})
}
Expand Down Expand Up @@ -97,8 +92,7 @@ export class DelegatedRoutingV1HttpApiClientPeerRouting implements PeerRouting {
if (peer != null) {
return {
id: peer.ID,
multiaddrs: peer.Addrs,
protocols: []
multiaddrs: peer.Addrs ?? []
}
}

Expand Down
6 changes: 3 additions & 3 deletions packages/client/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('delegated-routing-v1-http-api-client', () => {
ID: (await createEd25519PeerId()).toString(),
Addrs: ['/ip4/41.41.41.41/tcp/1234']
}, {
Protocols: ['transport-bitswap'],
Protocol: 'transport-bitswap',
Schema: 'peer',
Metadata: 'gBI=',
ID: (await createEd25519PeerId()).toString(),
Expand Down Expand Up @@ -124,13 +124,13 @@ describe('delegated-routing-v1-http-api-client', () => {
ID: peerId.toString(),
Addrs: ['/ip4/41.41.41.41/tcp/1234']
}, {
Protocols: ['transport-bitswap'],
Protocol: 'transport-bitswap',
Schema: 'peer',
Metadata: 'gBI=',
ID: peerId.toString(),
Addrs: ['/ip4/42.42.42.42/tcp/1234']
}, {
Protocols: ['transport-bitswap'],
Protocol: 'transport-bitswap',
Schema: 'peer',
Metadata: 'gBI=',
ID: (await createEd25519PeerId()).toString(),
Expand Down
12 changes: 6 additions & 6 deletions packages/client/test/routings.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable max-nested-callbacks */
/* eslint-env mocha */

import { contentRouting, type ContentRouting } from '@libp2p/interface/content-routing'
import { type PeerRouting, peerRouting } from '@libp2p/interface/peer-routing'
import { contentRoutingSymbol, peerRoutingSymbol } from '@libp2p/interface'
import { createEd25519PeerId } from '@libp2p/peer-id-factory'
import { expect } from 'aegir/chai'
import { create as createIpnsRecord, marshal as marshalIpnsRecord } from 'ipns'
Expand All @@ -11,6 +10,7 @@ import { CID } from 'multiformats/cid'
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
import { createDelegatedRoutingV1HttpApiClient, type DelegatedRoutingV1HttpApiClient } from '../src/index.js'
import type { PeerRouting, ContentRouting } from '@libp2p/interface'

const serverUrl = process.env.ECHO_SERVER

Expand Down Expand Up @@ -54,7 +54,7 @@ describe('libp2p content-routing', () => {
ID: (await createEd25519PeerId()).toString(),
Addrs: ['/ip4/41.41.41.41/tcp/1234']
}, {
Protocols: ['transport-bitswap'],
Protocol: 'transport-bitswap',
Schema: 'peer',
Metadata: 'gBI=',
ID: (await createEd25519PeerId()).toString(),
Expand Down Expand Up @@ -221,7 +221,7 @@ describe('libp2p peer-routing', () => {
const peerId = await createEd25519PeerId()

const records = [{
Protocols: ['transport-bitswap'],
Protocol: 'transport-bitswap',
Schema: 'peer',
Metadata: 'gBI=',
ID: peerId.toString(),
Expand Down Expand Up @@ -253,7 +253,7 @@ describe('libp2p peer-routing', () => {
})

function getContentRouting (obj: any): ContentRouting {
const routing = obj?.[contentRouting]
const routing = obj?.[contentRoutingSymbol]

if (routing == null) {
throw new Error('ContentRouting not found')
Expand All @@ -263,7 +263,7 @@ function getContentRouting (obj: any): ContentRouting {
}

function getPeerRouting (obj: any): PeerRouting {
const routing = obj?.[peerRouting]
const routing = obj?.[peerRoutingSymbol]

if (routing == null) {
throw new Error('PeerRouting not found')
Expand Down
19 changes: 10 additions & 9 deletions packages/interop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,18 @@
"test:node": "aegir test -t node --cov"
},
"devDependencies": {
"@helia/delegated-routing-v1-http-api-client": "^1.0.0",
"@helia/delegated-routing-v1-http-api-server": "^1.0.0",
"@helia/interface": "^2.0.0",
"@helia/ipns": "^2.0.1",
"@libp2p/interface": "^0.1.2",
"@libp2p/kad-dht": "^10.0.6",
"@libp2p/peer-id-factory": "^3.0.5",
"@helia/delegated-routing-v1-http-api-client": "^2.0.0",
"@helia/delegated-routing-v1-http-api-server": "^2.0.0",
"@helia/interface": "^3.0.1",
"@helia/ipns": "^4.0.0",
"@libp2p/identify": "^1.0.10",
"@libp2p/interface": "^1.1.1",
"@libp2p/kad-dht": "^12.0.3",
"@libp2p/peer-id-factory": "^4.0.4",
"aegir": "^42.2.0",
"fastify": "^4.17.0",
"helia": "^2.0.1",
"ipns": "^7.0.1",
"helia": "^3.0.1",
"ipns": "^8.0.1",
"it-first": "^3.0.3",
"multiformats": "^13.0.0"
},
Expand Down
23 changes: 20 additions & 3 deletions packages/interop/test/fixtures/create-helia.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
import { identify } from '@libp2p/identify'
import { kadDHT, removePublicAddressesMapper, type KadDHT } from '@libp2p/kad-dht'
import { createHelia as createNode, type HeliaInit } from 'helia'
import { ipnsSelector } from 'ipns/selector'
import { ipnsValidator } from 'ipns/validator'
import type { Helia } from '@helia/interface'
import type { Libp2p } from '@libp2p/interface'
import type { KadDHT } from '@libp2p/kad-dht'

export async function createHelia (init?: Partial<HeliaInit>): Promise<Helia<Libp2p<{ dht: KadDHT, identify: unknown }>>> {
export async function createHelia (init?: Partial<HeliaInit>): Promise<Helia<Libp2p<{ dht: KadDHT }>>> {
const helia = await createNode({
libp2p: {
peerDiscovery: []
peerDiscovery: [],
services: {
dht: kadDHT({
protocol: '/ipfs/lan/kad/1.0.0',
peerInfoMapper: removePublicAddressesMapper,
clientMode: false,
validators: {
ipns: ipnsValidator
},
selectors: {
ipns: ipnsSelector
}
}),
identify: identify()
}
}
})

Expand Down
Loading

0 comments on commit 50e4864

Please sign in to comment.