Comparing version
@@ -1,2 +0,2 @@ | ||
import type { AbortOptions, ComponentLogger, ContentRouting, PeerInfo, PeerRouting, PeerStore, RoutingOptions, Startable } from '@libp2p/interface'; | ||
import type { AbortOptions, ComponentLogger, ContentRouting, Metrics, PeerInfo, PeerRouting, PeerStore, RoutingOptions, Startable } from '@libp2p/interface'; | ||
import type { CID } from 'multiformats/cid'; | ||
@@ -10,2 +10,3 @@ export interface CompoundContentRoutingInit { | ||
logger: ComponentLogger; | ||
metrics?: Metrics; | ||
} | ||
@@ -24,3 +25,3 @@ export declare class CompoundContentRouting implements ContentRouting, Startable { | ||
*/ | ||
findProviders(key: CID, options?: RoutingOptions): AsyncIterable<PeerInfo>; | ||
findProviders(key: CID, options?: RoutingOptions): AsyncGenerator<PeerInfo>; | ||
/** | ||
@@ -27,0 +28,0 @@ * Iterates over all content routers in parallel to notify it is |
import { NotStartedError } from '@libp2p/interface'; | ||
import { PeerSet } from '@libp2p/peer-collections'; | ||
import merge from 'it-merge'; | ||
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'; | ||
import { NoContentRoutersError } from './errors.js'; | ||
@@ -13,2 +14,51 @@ export class CompoundContentRouting { | ||
this.components = components; | ||
this.findProviders = components.metrics?.traceFunction('libp2p.contentRouting.findProviders', this.findProviders.bind(this), { | ||
optionsIndex: 1, | ||
getAttributesFromArgs: ([cid], attrs) => { | ||
return { | ||
...attrs, | ||
cid: cid.toString() | ||
}; | ||
}, | ||
getAttributesFromYieldedValue: (value, attrs) => { | ||
return { | ||
...attrs, | ||
providers: [...(Array.isArray(attrs.providers) ? attrs.providers : []), value.id.toString()] | ||
}; | ||
} | ||
}) ?? this.findProviders; | ||
this.provide = components.metrics?.traceFunction('libp2p.contentRouting.provide', this.provide.bind(this), { | ||
optionsIndex: 1, | ||
getAttributesFromArgs: ([cid], attrs) => { | ||
return { | ||
...attrs, | ||
cid: cid.toString() | ||
}; | ||
} | ||
}) ?? this.provide; | ||
this.cancelReprovide = components.metrics?.traceFunction('libp2p.contentRouting.cancelReprovide', this.cancelReprovide.bind(this), { | ||
optionsIndex: 1, | ||
getAttributesFromArgs: ([cid], attrs) => { | ||
return { | ||
...attrs, | ||
cid: cid.toString() | ||
}; | ||
} | ||
}) ?? this.cancelReprovide; | ||
this.put = components.metrics?.traceFunction('libp2p.contentRouting.put', this.put.bind(this), { | ||
optionsIndex: 2, | ||
getAttributesFromArgs: ([key]) => { | ||
return { | ||
key: uint8ArrayToString(key, 'base36') | ||
}; | ||
} | ||
}) ?? this.put; | ||
this.get = components.metrics?.traceFunction('libp2p.contentRouting.get', this.get.bind(this), { | ||
optionsIndex: 1, | ||
getAttributesFromArgs: ([key]) => { | ||
return { | ||
key: uint8ArrayToString(key, 'base36') | ||
}; | ||
} | ||
}) ?? this.get; | ||
} | ||
@@ -15,0 +65,0 @@ [Symbol.toStringTag] = '@libp2p/content-routing'; |
@@ -1,2 +0,2 @@ | ||
import type { PeerId, PeerInfo, PeerRouting, PeerStore, RoutingOptions } from '@libp2p/interface'; | ||
import type { Metrics, PeerId, PeerInfo, PeerRouting, PeerStore, RoutingOptions } from '@libp2p/interface'; | ||
import type { ComponentLogger } from '@libp2p/logger'; | ||
@@ -10,2 +10,3 @@ export interface PeerRoutingInit { | ||
logger: ComponentLogger; | ||
metrics?: Metrics; | ||
} | ||
@@ -26,4 +27,4 @@ export declare class DefaultPeerRouting implements PeerRouting { | ||
*/ | ||
getClosestPeers(key: Uint8Array, options?: RoutingOptions): AsyncIterable<PeerInfo>; | ||
getClosestPeers(key: Uint8Array, options?: RoutingOptions): AsyncGenerator<PeerInfo>; | ||
} | ||
//# sourceMappingURL=peer-routing.d.ts.map |
@@ -5,2 +5,3 @@ import { NotFoundError } from '@libp2p/interface'; | ||
import parallel from 'it-parallel'; | ||
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'; | ||
import { NoPeerRoutersError, QueriedForSelfError } from './errors.js'; | ||
@@ -17,2 +18,26 @@ export class DefaultPeerRouting { | ||
this.routers = init.routers ?? []; | ||
this.findPeer = components.metrics?.traceFunction('libp2p.peerRouting.findPeer', this.findPeer.bind(this), { | ||
optionsIndex: 1, | ||
getAttributesFromArgs: ([peer], attrs) => { | ||
return { | ||
...attrs, | ||
peer: peer.toString() | ||
}; | ||
} | ||
}) ?? this.findPeer; | ||
this.getClosestPeers = components.metrics?.traceFunction('libp2p.peerRouting.getClosestPeers', this.getClosestPeers.bind(this), { | ||
optionsIndex: 1, | ||
getAttributesFromArgs: ([key], attrs) => { | ||
return { | ||
...attrs, | ||
key: uint8ArrayToString(key, 'base36') | ||
}; | ||
}, | ||
getAttributesFromYieldedValue: (value, attrs) => { | ||
return { | ||
...attrs, | ||
peers: [...(Array.isArray(attrs.peers) ? attrs.peers : []), value.id.toString()] | ||
}; | ||
} | ||
}) ?? this.getClosestPeers; | ||
} | ||
@@ -19,0 +44,0 @@ [Symbol.toStringTag] = '@libp2p/peer-routing'; |
@@ -1,3 +0,3 @@ | ||
export declare const version = "2.4.2"; | ||
export declare const version = "2.5.0-06fc82da8"; | ||
export declare const name = "js-libp2p"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -1,3 +0,3 @@ | ||
export const version = '2.4.2'; | ||
export const version = '2.5.0-06fc82da8'; | ||
export const name = 'js-libp2p'; | ||
//# sourceMappingURL=version.js.map |
{ | ||
"name": "libp2p", | ||
"version": "2.4.2", | ||
"version": "2.5.0-06fc82da8", | ||
"description": "JavaScript implementation of libp2p, a modular peer to peer network stack", | ||
@@ -90,11 +90,11 @@ "license": "Apache-2.0 OR MIT", | ||
"@chainsafe/netmask": "^2.0.0", | ||
"@libp2p/crypto": "^5.0.8", | ||
"@libp2p/interface": "^2.3.0", | ||
"@libp2p/interface-internal": "^2.2.1", | ||
"@libp2p/logger": "^5.1.5", | ||
"@libp2p/multistream-select": "^6.0.10", | ||
"@libp2p/peer-collections": "^6.0.13", | ||
"@libp2p/peer-id": "^5.0.9", | ||
"@libp2p/peer-store": "^11.0.13", | ||
"@libp2p/utils": "^6.3.0", | ||
"@libp2p/crypto": "5.0.9-06fc82da8", | ||
"@libp2p/interface": "2.4.0-06fc82da8", | ||
"@libp2p/interface-internal": "2.2.2-06fc82da8", | ||
"@libp2p/logger": "5.1.6-06fc82da8", | ||
"@libp2p/multistream-select": "6.0.11-06fc82da8", | ||
"@libp2p/peer-collections": "6.0.14-06fc82da8", | ||
"@libp2p/peer-id": "5.0.10-06fc82da8", | ||
"@libp2p/peer-store": "11.0.14-06fc82da8", | ||
"@libp2p/utils": "6.3.1-06fc82da8", | ||
"@multiformats/dns": "^1.0.6", | ||
@@ -101,0 +101,0 @@ "@multiformats/multiaddr": "^12.3.3", |
@@ -11,6 +11,35 @@ <h1 align="center"> | ||
[](http://webchat.freenode.net/?channels=%23libp2p) | ||
[](https://discord.com/invite/Ae4TbahHaT) | ||
[](https://discord.com/invite/Ae4TbahHaT) | ||
[](https://codecov.io/gh/libp2p/js-libp2p) | ||
[](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain) | ||
# About | ||
<!-- | ||
!IMPORTANT! | ||
Everything in this README between "# About" and "# Install" is automatically | ||
generated and will be overwritten the next time the doc generator is run. | ||
To make changes to this section, please update the @packageDocumentation section | ||
of src/index.js or src/index.ts | ||
To experiment with formatting, please run "npm run docs" from the root of this | ||
repo and examine the changes made. | ||
--> | ||
Use the `createLibp2p` function to create a libp2p node. | ||
## Example | ||
```typescript | ||
import { createLibp2p } from 'libp2p' | ||
const node = await createLibp2p({ | ||
// ...other options | ||
}) | ||
``` | ||
# Background | ||
@@ -17,0 +46,0 @@ |
import { NotStartedError } from '@libp2p/interface' | ||
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, PeerInfo, PeerRouting, PeerStore, RoutingOptions, Startable } from '@libp2p/interface' | ||
import type { AbortOptions, ComponentLogger, ContentRouting, Metrics, PeerInfo, PeerRouting, PeerStore, RoutingOptions, Startable } from '@libp2p/interface' | ||
import type { CID } from 'multiformats/cid' | ||
@@ -16,2 +17,3 @@ | ||
logger: ComponentLogger | ||
metrics?: Metrics | ||
} | ||
@@ -28,2 +30,52 @@ | ||
this.components = components | ||
this.findProviders = components.metrics?.traceFunction('libp2p.contentRouting.findProviders', this.findProviders.bind(this), { | ||
optionsIndex: 1, | ||
getAttributesFromArgs: ([cid], attrs) => { | ||
return { | ||
...attrs, | ||
cid: cid.toString() | ||
} | ||
}, | ||
getAttributesFromYieldedValue: (value, attrs: { providers?: string[] }) => { | ||
return { | ||
...attrs, | ||
providers: [...(Array.isArray(attrs.providers) ? attrs.providers : []), value.id.toString()] | ||
} | ||
} | ||
}) ?? this.findProviders | ||
this.provide = components.metrics?.traceFunction('libp2p.contentRouting.provide', this.provide.bind(this), { | ||
optionsIndex: 1, | ||
getAttributesFromArgs: ([cid], attrs) => { | ||
return { | ||
...attrs, | ||
cid: cid.toString() | ||
} | ||
} | ||
}) ?? this.provide | ||
this.cancelReprovide = components.metrics?.traceFunction('libp2p.contentRouting.cancelReprovide', this.cancelReprovide.bind(this), { | ||
optionsIndex: 1, | ||
getAttributesFromArgs: ([cid], attrs) => { | ||
return { | ||
...attrs, | ||
cid: cid.toString() | ||
} | ||
} | ||
}) ?? this.cancelReprovide | ||
this.put = components.metrics?.traceFunction('libp2p.contentRouting.put', this.put.bind(this), { | ||
optionsIndex: 2, | ||
getAttributesFromArgs: ([key]) => { | ||
return { | ||
key: uint8ArrayToString(key, 'base36') | ||
} | ||
} | ||
}) ?? this.put | ||
this.get = components.metrics?.traceFunction('libp2p.contentRouting.get', this.get.bind(this), { | ||
optionsIndex: 1, | ||
getAttributesFromArgs: ([key]) => { | ||
return { | ||
key: uint8ArrayToString(key, 'base36') | ||
} | ||
} | ||
}) ?? this.get | ||
} | ||
@@ -48,3 +100,3 @@ | ||
*/ | ||
async * findProviders (key: CID, options: RoutingOptions = {}): AsyncIterable<PeerInfo> { | ||
async * findProviders (key: CID, options: RoutingOptions = {}): AsyncGenerator<PeerInfo> { | ||
if (this.routers.length === 0) { | ||
@@ -51,0 +103,0 @@ throw new NoContentRoutersError('No content routers available') |
@@ -5,4 +5,5 @@ import { NotFoundError } from '@libp2p/interface' | ||
import parallel from 'it-parallel' | ||
import { toString as uint8ArrayToString } from 'uint8arrays/to-string' | ||
import { NoPeerRoutersError, QueriedForSelfError } from './errors.js' | ||
import type { Logger, PeerId, PeerInfo, PeerRouting, PeerStore, RoutingOptions } from '@libp2p/interface' | ||
import type { Logger, Metrics, PeerId, PeerInfo, PeerRouting, PeerStore, RoutingOptions } from '@libp2p/interface' | ||
import type { ComponentLogger } from '@libp2p/logger' | ||
@@ -18,2 +19,3 @@ | ||
logger: ComponentLogger | ||
metrics?: Metrics | ||
} | ||
@@ -32,2 +34,27 @@ | ||
this.routers = init.routers ?? [] | ||
this.findPeer = components.metrics?.traceFunction('libp2p.peerRouting.findPeer', this.findPeer.bind(this), { | ||
optionsIndex: 1, | ||
getAttributesFromArgs: ([peer], attrs) => { | ||
return { | ||
...attrs, | ||
peer: peer.toString() | ||
} | ||
} | ||
}) ?? this.findPeer | ||
this.getClosestPeers = components.metrics?.traceFunction('libp2p.peerRouting.getClosestPeers', this.getClosestPeers.bind(this), { | ||
optionsIndex: 1, | ||
getAttributesFromArgs: ([key], attrs) => { | ||
return { | ||
...attrs, | ||
key: uint8ArrayToString(key, 'base36') | ||
} | ||
}, | ||
getAttributesFromYieldedValue: (value, attrs: { peers?: string[] }) => { | ||
return { | ||
...attrs, | ||
peers: [...(Array.isArray(attrs.peers) ? attrs.peers : []), value.id.toString()] | ||
} | ||
} | ||
}) ?? this.getClosestPeers | ||
} | ||
@@ -81,3 +108,3 @@ | ||
*/ | ||
async * getClosestPeers (key: Uint8Array, options: RoutingOptions = {}): AsyncIterable<PeerInfo> { | ||
async * getClosestPeers (key: Uint8Array, options: RoutingOptions = {}): AsyncGenerator<PeerInfo> { | ||
if (this.routers.length === 0) { | ||
@@ -84,0 +111,0 @@ throw new NoPeerRoutersError('No peer routers available') |
@@ -1,2 +0,2 @@ | ||
export const version = '2.4.2' | ||
export const version = '2.5.0-06fc82da8' | ||
export const name = 'js-libp2p' |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
976986
0.47%12097
1.02%191
17.9%158
-0.63%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed