Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
with:
directories: ${{ env.CACHE_DIRS }}
- run: npm run --if-present test:node
- uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
- uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
with:
flags: node
files: .coverage/*,packages/*/.coverage/*
Expand All @@ -78,7 +78,7 @@ jobs:
with:
directories: ${{ env.CACHE_DIRS }}
- run: npm run --if-present test:chrome
- uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
- uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
with:
flags: chrome
files: .coverage/*,packages/*/.coverage/*
Expand All @@ -96,7 +96,7 @@ jobs:
with:
directories: ${{ env.CACHE_DIRS }}
- run: npm run --if-present test:chrome-webworker
- uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
- uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
with:
flags: chrome-webworker
files: .coverage/*,packages/*/.coverage/*
Expand All @@ -114,7 +114,7 @@ jobs:
with:
directories: ${{ env.CACHE_DIRS }}
- run: npm run --if-present test:firefox
- uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
- uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
with:
flags: firefox
files: .coverage/*,packages/*/.coverage/*
Expand All @@ -132,7 +132,7 @@ jobs:
with:
directories: ${{ env.CACHE_DIRS }}
- run: npm run --if-present test:firefox-webworker
- uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
- uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
with:
flags: firefox-webworker
files: .coverage/*,packages/*/.coverage/*
Expand All @@ -155,7 +155,7 @@ jobs:
sudo apt-get update
- run: npx playwright install-deps
- run: npm run --if-present test:webkit
- uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
- uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
with:
flags: webkit
files: .coverage/*,packages/*/.coverage/*
Expand All @@ -173,7 +173,7 @@ jobs:
with:
directories: ${{ env.CACHE_DIRS }}
- run: npx xvfb-maybe npm run --if-present test:electron-main
- uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
- uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
with:
flags: electron-main
files: .coverage/*,packages/*/.coverage/*
Expand All @@ -191,7 +191,7 @@ jobs:
with:
directories: ${{ env.CACHE_DIRS }}
- run: npx xvfb-maybe npm run --if-present test:electron-renderer
- uses: codecov/codecov-action@18283e04ce6e62d37312384ff67231eb8fd56d24 # v5.4.3
- uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
with:
flags: electron-renderer
files: .coverage/*,packages/*/.coverage/*
Expand Down
9 changes: 5 additions & 4 deletions packages/integration-tests/test/fixtures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Circuit } from '@multiformats/multiaddr-matcher'
import { detect } from 'detect-browser'
import pWaitFor from 'p-wait-for'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import type { Libp2p, AbortOptions, ContentRouting, PeerId, PeerInfo } from '@libp2p/interface'
import type { Libp2p, AbortOptions, ContentRouting, PeerId, Provider } from '@libp2p/interface'
import type { AddressManager } from '@libp2p/interface-internal'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { CID, Version } from 'multiformats'
Expand Down Expand Up @@ -153,7 +153,7 @@ export interface MockContentRoutingComponents {
}

export class MockContentRouting implements ContentRouting {
static providers = new Map<string, PeerInfo[]>()
static providers = new Map<string, Provider[]>()
static data = new Map<string, Uint8Array>()

static reset (): void {
Expand All @@ -175,7 +175,8 @@ export class MockContentRouting implements ContentRouting {

providers.push({
id: this.peerId,
multiaddrs: this.addressManager.getAddresses()
multiaddrs: this.addressManager.getAddresses(),
routing: 'mock-content-routing'
})

MockContentRouting.providers.set(cid.toString(), providers)
Expand All @@ -185,7 +186,7 @@ export class MockContentRouting implements ContentRouting {

}

async * findProviders (cid: CID<unknown, number, number, Version>, options?: AbortOptions | undefined): AsyncGenerator<PeerInfo, void, undefined> {
async * findProviders (cid: CID<unknown, number, number, Version>, options?: AbortOptions | undefined): AsyncGenerator<Provider, void, undefined> {
yield * MockContentRouting.providers.get(cid.toString()) ?? []
}

Expand Down
9 changes: 8 additions & 1 deletion packages/interface/src/content-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ import type { RoutingOptions } from './index.js'
import type { PeerInfo } from './peer-info.js'
import type { CID } from 'multiformats/cid'

export interface Provider extends PeerInfo {
/**
* Which routing subsystem found the provider
*/
routing: string
}

/**
* Any object that implements this Symbol as a property should return a
* Partial<ContentRouting> instance as the property value, similar to how
Expand Down Expand Up @@ -64,7 +71,7 @@ export interface ContentRouting {
* }
* ```
*/
findProviders(cid: CID, options?: RoutingOptions): AsyncIterable<PeerInfo>
findProviders(cid: CID, options?: RoutingOptions): AsyncIterable<Provider>

/**
* Puts a value corresponding to the passed key in a way that can later be
Expand Down
9 changes: 6 additions & 3 deletions packages/kad-dht/src/kad-dht.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
timeOperationGenerator
} from './utils.js'
import type { KadDHTComponents, KadDHTInit, Validators, Selectors, KadDHT as KadDHTInterface, QueryEvent, PeerInfoMapper, SetModeOptions } from './index.js'
import type { ContentRouting, CounterGroup, Logger, MetricGroup, PeerDiscovery, PeerDiscoveryEvents, PeerId, PeerInfo, PeerRouting, RoutingOptions, Startable } from '@libp2p/interface'
import type { ContentRouting, CounterGroup, Logger, MetricGroup, PeerDiscovery, PeerDiscoveryEvents, PeerId, PeerInfo, PeerRouting, Provider, RoutingOptions, Startable } from '@libp2p/interface'
import type { AbortOptions } from 'it-pushable'
import type { CID } from 'multiformats/cid'

Expand All @@ -46,10 +46,13 @@ class DHTContentRouting implements ContentRouting {
await this.dht.cancelReprovide(key)
}

async * findProviders (cid: CID, options: RoutingOptions = {}): AsyncGenerator<PeerInfo, void, undefined> {
async * findProviders (cid: CID, options: RoutingOptions = {}): AsyncGenerator<Provider, void, undefined> {
for await (const event of this.dht.findProviders(cid, options)) {
if (event.name === 'PROVIDER') {
yield * event.providers
yield * event.providers.map(peer => ({
...peer,
routing: 'kad-dht'
}))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p/src/connection-manager/dial-queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,8 @@ export class DialQueue {
}

return true
} catch (err) {
this.log.trace('error calculating if multiaddr(s) were dialable', err)
} catch {

}

return false
Expand Down
4 changes: 2 additions & 2 deletions packages/libp2p/src/content-routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { PeerSet } from '@libp2p/peer-collections'
import merge from 'it-merge'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { NoContentRoutersError } from './errors.js'
import type { AbortOptions, ComponentLogger, ContentRouting, Metrics, PeerInfo, PeerRouting, PeerStore, RoutingOptions, Startable } from '@libp2p/interface'
import type { AbortOptions, ComponentLogger, ContentRouting, Metrics, PeerRouting, PeerStore, Provider, RoutingOptions, Startable } from '@libp2p/interface'
import type { CID } from 'multiformats/cid'

export interface CompoundContentRoutingInit {
Expand Down Expand Up @@ -95,7 +95,7 @@ export class CompoundContentRouting implements ContentRouting, Startable {
/**
* Iterates over all content routers in parallel to find providers of the given key
*/
async * findProviders (key: CID, options: RoutingOptions = {}): AsyncGenerator<PeerInfo> {
async * findProviders (key: CID, options: RoutingOptions = {}): AsyncGenerator<Provider> {
if (this.routers.length === 0) {
throw new NoContentRoutersError('No content routers available')
}
Expand Down
34 changes: 22 additions & 12 deletions packages/libp2p/test/content-routing/content-routing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import sinon from 'sinon'
import { stubInterface } from 'sinon-ts'
import { createLibp2p } from '../../src/index.js'
import type { Libp2p } from '../../src/index.js'
import type { ContentRouting, PeerInfo } from '@libp2p/interface'
import type { ContentRouting, Provider } from '@libp2p/interface'
import type { StubbedInstance } from 'sinon-ts'

describe('content-routing', () => {
Expand Down Expand Up @@ -87,7 +87,8 @@ describe('content-routing', () => {
id: peerIdFromPrivateKey(await generateKeyPair('Ed25519')),
multiaddrs: [
multiaddr('/ip4/123.123.123.123/tcp/4001')
]
],
routing: 'test'
}
deferred.resolve()
})
Expand Down Expand Up @@ -136,7 +137,8 @@ describe('content-routing', () => {
delegate.findProviders.returns(async function * () {
yield {
id: node.peerId,
multiaddrs: []
multiaddrs: [],
routing: 'test'
}
deferred.resolve()
}())
Expand Down Expand Up @@ -173,7 +175,8 @@ describe('content-routing', () => {
id: peerIdFromString(provider),
multiaddrs: [
multiaddr('/ip4/0.0.0.0/tcp/0')
]
],
routing: 'test'
}
}())

Expand Down Expand Up @@ -224,11 +227,12 @@ describe('content-routing', () => {

it('should store the multiaddrs of a peer', async () => {
const providerPeerId = peerIdFromPrivateKey(await generateKeyPair('Ed25519'))
const result: PeerInfo = {
const result: Provider = {
id: providerPeerId,
multiaddrs: [
multiaddr('/ip4/123.123.123.123/tcp/49320')
]
],
routing: 'test'
}

router.findProviders.callsFake(async function * () {})
Expand All @@ -252,7 +256,8 @@ describe('content-routing', () => {
id: providerPeerId,
multiaddrs: [
multiaddr('/ip4/123.123.123.123/tcp/49320')
]
],
routing: 'test'
}

const defer = pDefer()
Expand All @@ -278,7 +283,8 @@ describe('content-routing', () => {
id: providerPeerId,
multiaddrs: [
multiaddr('/ip4/123.123.123.123/tcp/49320')
]
],
routing: 'test'
}

router.findProviders.callsFake(async function * () {
Expand All @@ -299,13 +305,15 @@ describe('content-routing', () => {
id: providerPeerId,
multiaddrs: [
multiaddr('/ip4/123.123.123.123/tcp/49320')
]
],
routing: 'test'
}
const result2 = {
id: providerPeerId,
multiaddrs: [
multiaddr('/ip4/213.213.213.213/tcp/2344')
]
],
routing: 'test'
}

router.findProviders.callsFake(async function * () {
Expand Down Expand Up @@ -352,7 +360,8 @@ describe('content-routing', () => {
id: providerPeerId,
multiaddrs: [
multiaddr('/ip4/123.123.123.123/tcp/2341')
]
],
routing: 'test'
}]

router.findProviders.callsFake(async function * () {
Expand All @@ -377,7 +386,8 @@ describe('content-routing', () => {
id: providerPeerId,
multiaddrs: [
multiaddr('/ip4/123.123.123.123/tcp/2341')
]
],
routing: 'test'
}]

router.findProviders.callsFake(async function * () {})
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function formatError (v: Error): string {
}

function isAggregateError (err?: any): err is AggregateError {
return err?.name === 'AggregateError'
return err instanceof AggregateError || (err?.name === 'AggregateError' && Array.isArray(err.errors))
}

// Add a formatter for stringifying Errors
Expand Down
9 changes: 5 additions & 4 deletions packages/transport-circuit-relay-v2/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Circuit } from '@multiformats/multiaddr-matcher'
import pWaitFor from 'p-wait-for'
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
import { RELAY_V2_HOP_CODEC } from '../../../packages/transport-circuit-relay-v2/src/constants.js'
import type { Libp2p, AbortOptions, ContentRouting, PeerId, PeerInfo } from '@libp2p/interface'
import type { Libp2p, AbortOptions, ContentRouting, PeerId, Provider } from '@libp2p/interface'
import type { AddressManager } from '@libp2p/interface-internal'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { CID, Version } from 'multiformats'
Expand Down Expand Up @@ -133,7 +133,7 @@ export interface MockContentRoutingComponents {
}

export class MockContentRouting implements ContentRouting {
static providers = new Map<string, PeerInfo[]>()
static providers = new Map<string, Provider[]>()
static data = new Map<string, Uint8Array>()

static reset (): void {
Expand All @@ -155,7 +155,8 @@ export class MockContentRouting implements ContentRouting {

providers.push({
id: this.peerId,
multiaddrs: this.addressManager.getAddresses()
multiaddrs: this.addressManager.getAddresses(),
routing: 'mock-content-routing'
})

MockContentRouting.providers.set(cid.toString(), providers)
Expand All @@ -165,7 +166,7 @@ export class MockContentRouting implements ContentRouting {

}

async * findProviders (cid: CID<unknown, number, number, Version>, options?: AbortOptions | undefined): AsyncGenerator<PeerInfo, void, undefined> {
async * findProviders (cid: CID<unknown, number, number, Version>, options?: AbortOptions | undefined): AsyncGenerator<Provider, void, undefined> {
yield * MockContentRouting.providers.get(cid.toString()) ?? []
}

Expand Down
Loading