Skip to content

Commit 803ae7b

Browse files
committed
chore!: bump libp2p dependencies
1 parent 3b4bc8b commit 803ae7b

20 files changed

+23214
-17233
lines changed

package-lock.json

+23,060-17,066
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/core/package.json

+13-14
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,31 @@
7676
"node": ">=16"
7777
},
7878
"dependencies": {
79-
"@chainsafe/libp2p-gossipsub": "^5.2.1",
80-
"@libp2p/interface-connection": "^3.0.3",
81-
"@libp2p/interface-peer-discovery": "^1.0.0",
82-
"@libp2p/interface-peer-id": "^1.0.6",
83-
"@libp2p/interface-peer-info": "^1.0.4",
84-
"@libp2p/interface-peer-store": "^1.2.3",
85-
"@libp2p/interface-pubsub": "^3.0.1",
86-
"@libp2p/interface-registrar": "^2.0.4",
87-
"@libp2p/interfaces": "^3.0.4",
88-
"@libp2p/peer-id": "^1.1.10",
79+
"@chainsafe/libp2p-gossipsub": "^6.1.0",
80+
"@libp2p/interface-connection": "^3.0.8",
81+
"@libp2p/interface-peer-discovery": "^1.0.5",
82+
"@libp2p/interface-peer-id": "^2.0.1",
83+
"@libp2p/interface-peer-info": "^1.0.8",
84+
"@libp2p/interface-peer-store": "^1.2.8",
85+
"@libp2p/interface-pubsub": "^3.0.6",
86+
"@libp2p/interfaces": "^3.3.1",
87+
"@libp2p/peer-id": "^2.0.1",
8988
"@multiformats/multiaddr": "^11.0.6",
9089
"@noble/hashes": "^1.1.3",
91-
"@waku/utils": "*",
9290
"@waku/interfaces": "*",
9391
"@waku/proto": "*",
92+
"@waku/utils": "*",
9493
"debug": "^4.3.4",
9594
"it-all": "^1.0.6",
9695
"it-length-prefixed": "^8.0.2",
9796
"it-pipe": "^2.0.4",
98-
"libp2p": "0.40.0",
9997
"p-event": "^5.0.1",
10098
"uint8arraylist": "^2.3.2",
10199
"uint8arrays": "^4.0.2",
102100
"uuid": "^9.0.0"
103101
},
104102
"devDependencies": {
103+
"@libp2p/interface-libp2p": "^1.1.1",
105104
"@rollup/plugin-commonjs": "^22.0.0",
106105
"@rollup/plugin-json": "^4.1.0",
107106
"@rollup/plugin-node-resolve": "^13.3.0",
@@ -115,13 +114,15 @@
115114
"@typescript-eslint/eslint-plugin": "^5.8.1",
116115
"@typescript-eslint/parser": "^5.8.1",
117116
"app-root-path": "^3.0.0",
117+
"chai": "^4.3.4",
118118
"cspell": "^6.17.0",
119119
"eslint": "^8.6.0",
120120
"eslint-config-prettier": "^8.3.0",
121121
"eslint-plugin-eslint-comments": "^3.2.0",
122122
"eslint-plugin-functional": "^4.0.2",
123123
"eslint-plugin-import": "^2.25.3",
124124
"eslint-plugin-prettier": "^4.0.0",
125+
"fast-check": "^2.14.0",
125126
"gh-pages": "^3.2.3",
126127
"ignore-loader": "^0.1.2",
127128
"isomorphic-fetch": "^3.0.0",
@@ -132,8 +133,6 @@
132133
"karma-mocha": "^2.0.1",
133134
"karma-webpack": "^5.0.0",
134135
"mocha": "^9.1.3",
135-
"chai": "^4.3.4",
136-
"fast-check": "^2.14.0",
137136
"npm-run-all": "^4.1.5",
138137
"p-timeout": "^6.0.0",
139138
"portfinder": "^1.0.28",

packages/core/src/lib/filter/index.ts

+9-21
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import type { Stream } from "@libp2p/interface-connection";
2-
import type { ConnectionManager } from "@libp2p/interface-connection-manager";
2+
import { Libp2p } from "@libp2p/interface-libp2p";
33
import type { PeerId } from "@libp2p/interface-peer-id";
44
import type { PeerStore } from "@libp2p/interface-peer-store";
55
import type { Peer } from "@libp2p/interface-peer-store";
66
import type { IncomingStreamData } from "@libp2p/interface-registrar";
7-
import type { Registrar } from "@libp2p/interface-registrar";
87
import type {
98
Callback,
109
IDecodedMessage,
@@ -38,12 +37,6 @@ export const FilterCodec = "/vac/waku/filter/2.0.0-beta1";
3837

3938
const log = debug("waku:filter");
4039

41-
export interface FilterComponents {
42-
peerStore: PeerStore;
43-
registrar: Registrar;
44-
connectionManager: ConnectionManager;
45-
}
46-
4740
export type UnsubscribeFunction = () => Promise<void>;
4841

4942
/**
@@ -62,15 +55,12 @@ class Filter implements IFilter {
6255
Set<IDecoder<any>>
6356
>;
6457

65-
constructor(
66-
public components: FilterComponents,
67-
options?: ProtocolCreateOptions
68-
) {
58+
constructor(public libp2p: Libp2p, options?: ProtocolCreateOptions) {
6959
this.options = options ?? {};
7060
this.multicodec = FilterCodec;
7161
this.subscriptions = new Map();
7262
this.decoders = new Map();
73-
this.components.registrar
63+
this.libp2p
7464
.handle(FilterCodec, this.onRequest.bind(this))
7565
.catch((e) => log("Failed to register filter protocol", e));
7666
}
@@ -143,7 +133,7 @@ class Filter implements IFilter {
143133
}
144134

145135
get peerStore(): PeerStore {
146-
return this.components.peerStore;
136+
return this.libp2p.peerStore;
147137
}
148138

149139
private onRequest(streamData: IncomingStreamData): void {
@@ -268,9 +258,7 @@ class Filter implements IFilter {
268258
}
269259

270260
private async newStream(peer: Peer): Promise<Stream> {
271-
const connections = this.components.connectionManager.getConnections(
272-
peer.id
273-
);
261+
const connections = this.libp2p.getConnections(peer.id);
274262
const connection = selectConnection(connections);
275263
if (!connection) {
276264
throw new Error("Failed to get a connection to the peer");
@@ -281,7 +269,7 @@ class Filter implements IFilter {
281269

282270
private async getPeer(peerId?: PeerId): Promise<Peer> {
283271
const res = await selectPeerForProtocol(
284-
this.components.peerStore,
272+
this.peerStore,
285273
[FilterCodec],
286274
peerId
287275
);
@@ -292,7 +280,7 @@ class Filter implements IFilter {
292280
}
293281

294282
async peers(): Promise<Peer[]> {
295-
return getPeersForProtocol(this.components.peerStore, [FilterCodec]);
283+
return getPeersForProtocol(this.peerStore, [FilterCodec]);
296284
}
297285

298286
async randomPeer(): Promise<Peer | undefined> {
@@ -302,6 +290,6 @@ class Filter implements IFilter {
302290

303291
export function wakuFilter(
304292
init: Partial<ProtocolCreateOptions> = {}
305-
): (components: FilterComponents) => IFilter {
306-
return (components: FilterComponents) => new Filter(components, init);
293+
): (libp2p: Libp2p) => IFilter {
294+
return (libp2p: Libp2p) => new Filter(libp2p, init);
307295
}

packages/core/src/lib/light_push/index.ts

+8-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ConnectionManager } from "@libp2p/interface-connection-manager";
1+
import type { Libp2p } from "@libp2p/interface-libp2p";
22
import type { PeerId } from "@libp2p/interface-peer-id";
33
import type { Peer } from "@libp2p/interface-peer-store";
44
import type { PeerStore } from "@libp2p/interface-peer-store";
@@ -32,22 +32,14 @@ const log = debug("waku:light-push");
3232
export const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
3333
export { PushResponse };
3434

35-
export interface LightPushComponents {
36-
peerStore: PeerStore;
37-
connectionManager: ConnectionManager;
38-
}
39-
4035
/**
4136
* Implements the [Waku v2 Light Push protocol](https://rfc.vac.dev/spec/19/).
4237
*/
4338
class LightPush implements ILightPush {
4439
multicodec: string;
4540
options: ProtocolCreateOptions;
4641

47-
constructor(
48-
public components: LightPushComponents,
49-
options?: ProtocolCreateOptions
50-
) {
42+
constructor(public libp2p: Libp2p, options?: ProtocolCreateOptions) {
5143
this.multicodec = LightPushCodec;
5244
this.options = options || {};
5345
}
@@ -60,7 +52,7 @@ class LightPush implements ILightPush {
6052
const { pubSubTopic = DefaultPubSubTopic } = this.options;
6153

6254
const res = await selectPeerForProtocol(
63-
this.components.peerStore,
55+
this.peerStore,
6456
[this.multicodec],
6557
opts?.peerId
6658
);
@@ -70,9 +62,7 @@ class LightPush implements ILightPush {
7062
}
7163
const { peer } = res;
7264

73-
const connections = this.components.connectionManager.getConnections(
74-
peer.id
75-
);
65+
const connections = this.libp2p.getConnections(peer.id);
7666
const connection = selectConnection(connections);
7767

7868
if (!connection) throw "Failed to get a connection to the peer";
@@ -126,7 +116,7 @@ class LightPush implements ILightPush {
126116
* peers.
127117
*/
128118
async peers(): Promise<Peer[]> {
129-
return getPeersForProtocol(this.components.peerStore, [LightPushCodec]);
119+
return getPeersForProtocol(this.peerStore, [LightPushCodec]);
130120
}
131121

132122
/**
@@ -139,12 +129,12 @@ class LightPush implements ILightPush {
139129
}
140130

141131
get peerStore(): PeerStore {
142-
return this.components.peerStore;
132+
return this.libp2p.peerStore;
143133
}
144134
}
145135

146136
export function wakuLightPush(
147137
init: Partial<ProtocolCreateOptions> = {}
148-
): (components: LightPushComponents) => ILightPush {
149-
return (components: LightPushComponents) => new LightPush(components, init);
138+
): (libp2p: Libp2p) => ILightPush {
139+
return (libp2p: Libp2p) => new LightPush(libp2p, init);
150140
}

packages/core/src/lib/store/index.ts

+8-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Connection } from "@libp2p/interface-connection";
2-
import type { ConnectionManager } from "@libp2p/interface-connection-manager";
2+
import type { Libp2p } from "@libp2p/interface-libp2p";
33
import type { PeerId } from "@libp2p/interface-peer-id";
44
import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
55
import { sha256 } from "@noble/hashes/sha256";
@@ -40,11 +40,6 @@ export const DefaultPageSize = 10;
4040

4141
export { PageDirection };
4242

43-
export interface StoreComponents {
44-
peerStore: PeerStore;
45-
connectionManager: ConnectionManager;
46-
}
47-
4843
export interface TimeFilter {
4944
startTime: Date;
5045
endTime: Date;
@@ -93,10 +88,7 @@ class Store implements IStore {
9388
multicodec: string;
9489
options: ProtocolCreateOptions;
9590

96-
constructor(
97-
public components: StoreComponents,
98-
options?: ProtocolCreateOptions
99-
) {
91+
constructor(public libp2p: Libp2p, options?: ProtocolCreateOptions) {
10092
this.multicodec = StoreCodec;
10193
this.options = options ?? {};
10294
}
@@ -246,7 +238,7 @@ class Store implements IStore {
246238
});
247239

248240
const res = await selectPeerForProtocol(
249-
this.components.peerStore,
241+
this.peerStore,
250242
[StoreCodec],
251243
options?.peerId
252244
);
@@ -256,9 +248,7 @@ class Store implements IStore {
256248
}
257249
const { peer, protocol } = res;
258250

259-
const connections = this.components.connectionManager.getConnections(
260-
peer.id
261-
);
251+
const connections = this.libp2p.getConnections(peer.id);
262252
const connection = selectConnection(connections);
263253

264254
if (!connection) throw "Failed to get a connection to the peer";
@@ -279,11 +269,11 @@ class Store implements IStore {
279269
* store protocol. Waku may or may not be currently connected to these peers.
280270
*/
281271
async peers(): Promise<Peer[]> {
282-
return getPeersForProtocol(this.components.peerStore, [StoreCodec]);
272+
return getPeersForProtocol(this.peerStore, [StoreCodec]);
283273
}
284274

285275
get peerStore(): PeerStore {
286-
return this.components.peerStore;
276+
return this.libp2p.peerStore;
287277
}
288278
}
289279

@@ -424,6 +414,6 @@ export async function createCursor(
424414

425415
export function wakuStore(
426416
init: Partial<ProtocolCreateOptions> = {}
427-
): (components: StoreComponents) => IStore {
428-
return (components: StoreComponents) => new Store(components, init);
417+
): (libp2p: Libp2p) => IStore {
418+
return (libp2p: Libp2p) => new Store(libp2p, init);
429419
}

packages/core/src/lib/waku.ts

+13-16
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { Stream } from "@libp2p/interface-connection";
2+
import type { Libp2p } from "@libp2p/interface-libp2p";
23
import type { PeerId } from "@libp2p/interface-peer-id";
34
import type { PubSub } from "@libp2p/interface-pubsub";
45
import type { Multiaddr } from "@multiformats/multiaddr";
@@ -13,14 +14,10 @@ import type {
1314
} from "@waku/interfaces";
1415
import { Protocols } from "@waku/interfaces";
1516
import debug from "debug";
16-
import type { Libp2p } from "libp2p";
1717

18-
import { FilterComponents } from "./filter/index.js";
19-
import { LightPushComponents } from "./light_push/index.js";
2018
import { createEncoder } from "./message/version_0.js";
2119
import * as relayConstants from "./relay/constants.js";
2220
import { RelayPingContentTopic } from "./relay/constants.js";
23-
import { StoreComponents } from "./store/index.js";
2421

2522
export const DefaultPingKeepAliveValueSecs = 0;
2623
export const DefaultRelayKeepAliveValueSecs = 5 * 60;
@@ -68,28 +65,28 @@ export class WakuNode implements Waku {
6865
constructor(
6966
options: WakuOptions,
7067
libp2p: Libp2p,
71-
store?: (components: StoreComponents) => IStore,
72-
lightPush?: (components: LightPushComponents) => ILightPush,
73-
filter?: (components: FilterComponents) => IFilter,
68+
store?: (libp2p: Libp2p) => IStore,
69+
lightPush?: (libp2p: Libp2p) => ILightPush,
70+
filter?: (libp2p: Libp2p) => IFilter,
7471
peerExchange?: (components: PeerExchangeComponents) => IPeerExchange
7572
) {
7673
this.libp2p = libp2p;
7774

78-
const { peerStore, connectionManager, registrar } = libp2p;
79-
const components = { peerStore, connectionManager, registrar };
80-
8175
if (store) {
82-
this.store = store(components);
76+
this.store = store(libp2p);
8377
}
8478
if (filter) {
85-
this.filter = filter(components);
79+
this.filter = filter(libp2p);
8680
}
8781
if (lightPush) {
88-
this.lightPush = lightPush(components);
82+
this.lightPush = lightPush(libp2p);
8983
}
9084

9185
if (peerExchange) {
92-
this.peerExchange = peerExchange(components);
86+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
87+
// @ts-ignore: Libp2p is now hiding internal components but peer discovery
88+
// implementation still expect to receive said components.
89+
this.peerExchange = peerExchange(libp2p.components);
9390
}
9491

9592
if (isRelay(libp2p.pubsub)) {
@@ -113,7 +110,7 @@ export class WakuNode implements Waku {
113110
? options.relayKeepAlive || DefaultRelayKeepAliveValueSecs
114111
: 0;
115112

116-
libp2p.connectionManager.addEventListener("peer:connect", (evt) => {
113+
libp2p.addEventListener("peer:connect", (evt) => {
117114
this.startKeepAlive(evt.detail.remotePeer, pingKeepAlive, relayKeepAlive);
118115
});
119116

@@ -128,7 +125,7 @@ export class WakuNode implements Waku {
128125
* >this event will **only** be triggered when the last connection is closed.
129126
* @see https://github.com/libp2p/js-libp2p/blob/bad9e8c0ff58d60a78314077720c82ae331cc55b/doc/API.md?plain=1#L2100
130127
*/
131-
libp2p.connectionManager.addEventListener("peer:disconnect", (evt) => {
128+
libp2p.addEventListener("peer:disconnect", (evt) => {
132129
this.stopKeepAlive(evt.detail.remotePeer);
133130
});
134131

0 commit comments

Comments
 (0)