@waku/core 0.0.23 → 0.0.25-a42b7be.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/bundle/{base_protocol-84d9b670.js → base_protocol-4bcf7514.js} +194 -134
- package/bundle/{browser-bde977a3.js → browser-90197c87.js} +26 -1
- package/bundle/index-27b91e3b.js +31 -0
- package/bundle/index.js +19384 -2421
- package/bundle/lib/base_protocol.js +3 -2
- package/bundle/lib/message/version_0.js +3 -2
- package/bundle/lib/predefined_bootstrap_nodes.js +2 -0
- package/bundle/{version_0-74b4b9db.js → version_0-2f1176e3.js} +36 -24
- package/dist/.tsbuildinfo +1 -1
- package/dist/lib/connection_manager.d.ts +17 -4
- package/dist/lib/connection_manager.js +111 -45
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/index.js +53 -37
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/keep_alive_manager.d.ts +1 -0
- package/dist/lib/keep_alive_manager.js +42 -18
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.js +60 -38
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/push_rpc.d.ts +1 -1
- package/dist/lib/light_push/push_rpc.js +2 -2
- package/dist/lib/message/version_0.d.ts +13 -13
- package/dist/lib/message/version_0.js +22 -20
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/store/history_rpc.d.ts +1 -1
- package/dist/lib/store/history_rpc.js +1 -1
- package/dist/lib/store/index.d.ts +1 -1
- package/dist/lib/store/index.js +43 -17
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/stream_manager.d.ts +1 -1
- package/dist/lib/stream_manager.js +8 -5
- package/dist/lib/stream_manager.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.d.ts +2 -2
- package/dist/lib/wait_for_remote_peer.js +13 -11
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/dist/lib/waku.d.ts +4 -3
- package/dist/lib/waku.js +13 -11
- package/dist/lib/waku.js.map +1 -1
- package/package.json +1 -137
- package/src/lib/connection_manager.ts +156 -51
- package/src/lib/filter/index.ts +76 -40
- package/src/lib/keep_alive_manager.ts +53 -20
- package/src/lib/light_push/index.ts +74 -38
- package/src/lib/light_push/push_rpc.ts +2 -2
- package/src/lib/message/version_0.ts +25 -17
- package/src/lib/store/history_rpc.ts +2 -2
- package/src/lib/store/index.ts +60 -23
- package/src/lib/stream_manager.ts +12 -7
- package/src/lib/wait_for_remote_peer.ts +13 -11
- package/src/lib/waku.ts +12 -9
- package/dist/lib/push_or_init_map.d.ts +0 -1
- package/dist/lib/push_or_init_map.js +0 -9
- package/dist/lib/push_or_init_map.js.map +0 -1
- package/src/lib/push_or_init_map.ts +0 -13
@@ -2,19 +2,19 @@ import type { PeerUpdate } from "@libp2p/interface";
|
|
2
2
|
import type { Stream } from "@libp2p/interface/connection";
|
3
3
|
import { Peer } from "@libp2p/interface/peer-store";
|
4
4
|
import { Libp2p } from "@waku/interfaces";
|
5
|
+
import { Logger } from "@waku/utils";
|
5
6
|
import { selectConnection } from "@waku/utils/libp2p";
|
6
|
-
import debug from "debug";
|
7
7
|
|
8
8
|
export class StreamManager {
|
9
|
-
private streamPool: Map<string, Promise<Stream>>;
|
10
|
-
private log:
|
9
|
+
private streamPool: Map<string, Promise<Stream | void>>;
|
10
|
+
private readonly log: Logger;
|
11
11
|
|
12
12
|
constructor(
|
13
13
|
public multicodec: string,
|
14
14
|
public getConnections: Libp2p["getConnections"],
|
15
15
|
public addEventListener: Libp2p["addEventListener"]
|
16
16
|
) {
|
17
|
-
this.log =
|
17
|
+
this.log = new Logger(`stream-manager:${multicodec}`);
|
18
18
|
this.addEventListener(
|
19
19
|
"peer:update",
|
20
20
|
this.handlePeerUpdateStreamPool.bind(this)
|
@@ -38,7 +38,7 @@ export class StreamManager {
|
|
38
38
|
|
39
39
|
const stream = await streamPromise;
|
40
40
|
|
41
|
-
if (stream.status === "closed") {
|
41
|
+
if (!stream || stream.status === "closed") {
|
42
42
|
return this.newStream(peer); // fallback by creating a new stream on the spot
|
43
43
|
}
|
44
44
|
|
@@ -55,14 +55,19 @@ export class StreamManager {
|
|
55
55
|
}
|
56
56
|
|
57
57
|
private prepareNewStream(peer: Peer): void {
|
58
|
-
const streamPromise = this.newStream(peer)
|
58
|
+
const streamPromise = this.newStream(peer).catch(() => {
|
59
|
+
// No error thrown as this call is not triggered by the user
|
60
|
+
this.log.error(
|
61
|
+
`Failed to prepare a new stream for ${peer.id.toString()}`
|
62
|
+
);
|
63
|
+
});
|
59
64
|
this.streamPool.set(peer.id.toString(), streamPromise);
|
60
65
|
}
|
61
66
|
|
62
67
|
private handlePeerUpdateStreamPool = (evt: CustomEvent<PeerUpdate>): void => {
|
63
68
|
const peer = evt.detail.peer;
|
64
69
|
if (peer.protocols.includes(this.multicodec)) {
|
65
|
-
this.log(`Preemptively opening a stream to ${peer.id.toString()}`);
|
70
|
+
this.log.info(`Preemptively opening a stream to ${peer.id.toString()}`);
|
66
71
|
this.prepareNewStream(peer);
|
67
72
|
}
|
68
73
|
};
|
@@ -1,16 +1,16 @@
|
|
1
1
|
import type { IdentifyResult } from "@libp2p/interface";
|
2
2
|
import type { IBaseProtocol, IRelay, Waku } from "@waku/interfaces";
|
3
3
|
import { Protocols } from "@waku/interfaces";
|
4
|
-
import
|
4
|
+
import { Logger } from "@waku/utils";
|
5
5
|
import { pEvent } from "p-event";
|
6
6
|
|
7
|
-
const log =
|
7
|
+
const log = new Logger("wait-for-remote-peer");
|
8
8
|
|
9
9
|
/**
|
10
10
|
* Wait for a remote peer to be ready given the passed protocols.
|
11
11
|
* Must be used after attempting to connect to nodes, using
|
12
|
-
* {@link @waku/core
|
13
|
-
* {@link @waku/sdk
|
12
|
+
* {@link @waku/core!WakuNode.dial} or a bootstrap method with
|
13
|
+
* {@link @waku/sdk!createLightNode}.
|
14
14
|
*
|
15
15
|
* If the passed protocols is a GossipSub protocol, then it resolves only once
|
16
16
|
* a peer is in a mesh, to help ensure that other peers will send and receive
|
@@ -79,14 +79,13 @@ async function waitForConnectedPeer(protocol: IBaseProtocol): Promise<void> {
|
|
79
79
|
const peers = await protocol.peers();
|
80
80
|
|
81
81
|
if (peers.length) {
|
82
|
-
log(`${codec} peer found: `, peers[0].id.toString());
|
82
|
+
log.info(`${codec} peer found: `, peers[0].id.toString());
|
83
83
|
return;
|
84
84
|
}
|
85
85
|
|
86
86
|
await new Promise<void>((resolve) => {
|
87
87
|
const cb = (evt: CustomEvent<IdentifyResult>): void => {
|
88
88
|
if (evt.detail?.protocols?.includes(codec)) {
|
89
|
-
log("Resolving for", codec, evt.detail.protocols);
|
90
89
|
protocol.removeLibp2pEventListener("peer:identify", cb);
|
91
90
|
resolve();
|
92
91
|
}
|
@@ -96,15 +95,18 @@ async function waitForConnectedPeer(protocol: IBaseProtocol): Promise<void> {
|
|
96
95
|
}
|
97
96
|
|
98
97
|
/**
|
99
|
-
* Wait for
|
100
|
-
* mesh.
|
98
|
+
* Wait for at least one peer with the given protocol to be connected and in the gossipsub
|
99
|
+
* mesh for all pubsubTopics.
|
101
100
|
*/
|
102
101
|
async function waitForGossipSubPeerInMesh(waku: IRelay): Promise<void> {
|
103
102
|
let peers = waku.getMeshPeers();
|
103
|
+
const pubsubTopics = waku.pubsubTopics;
|
104
104
|
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
for (const topic of pubsubTopics) {
|
106
|
+
while (peers.length == 0) {
|
107
|
+
await pEvent(waku.gossipSub, "gossipsub:heartbeat");
|
108
|
+
peers = waku.getMeshPeers(topic);
|
109
|
+
}
|
108
110
|
}
|
109
111
|
}
|
110
112
|
|
package/src/lib/waku.ts
CHANGED
@@ -7,18 +7,19 @@ import type {
|
|
7
7
|
IRelay,
|
8
8
|
IStore,
|
9
9
|
Libp2p,
|
10
|
+
PubSubTopic,
|
10
11
|
Waku
|
11
12
|
} from "@waku/interfaces";
|
12
13
|
import { Protocols } from "@waku/interfaces";
|
13
|
-
import
|
14
|
+
import { Logger } from "@waku/utils";
|
14
15
|
|
15
16
|
import { ConnectionManager } from "./connection_manager.js";
|
16
17
|
|
17
|
-
export const DefaultPingKeepAliveValueSecs =
|
18
|
+
export const DefaultPingKeepAliveValueSecs = 5 * 60;
|
18
19
|
export const DefaultRelayKeepAliveValueSecs = 5 * 60;
|
19
20
|
export const DefaultUserAgent = "js-waku";
|
20
21
|
|
21
|
-
const log =
|
22
|
+
const log = new Logger("waku");
|
22
23
|
|
23
24
|
export interface WakuOptions {
|
24
25
|
/**
|
@@ -52,6 +53,7 @@ export class WakuNode implements Waku {
|
|
52
53
|
|
53
54
|
constructor(
|
54
55
|
options: WakuOptions,
|
56
|
+
public readonly pubsubTopics: PubSubTopic[],
|
55
57
|
libp2p: Libp2p,
|
56
58
|
store?: (libp2p: Libp2p) => IStore,
|
57
59
|
lightPush?: (libp2p: Libp2p) => ILightPush,
|
@@ -86,10 +88,11 @@ export class WakuNode implements Waku {
|
|
86
88
|
peerId,
|
87
89
|
libp2p,
|
88
90
|
{ pingKeepAlive, relayKeepAlive },
|
91
|
+
pubsubTopics,
|
89
92
|
this.relay
|
90
93
|
);
|
91
94
|
|
92
|
-
log(
|
95
|
+
log.info(
|
93
96
|
"Waku node created",
|
94
97
|
peerId,
|
95
98
|
`relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this
|
@@ -124,7 +127,7 @@ export class WakuNode implements Waku {
|
|
124
127
|
codecs.push(codec)
|
125
128
|
);
|
126
129
|
} else {
|
127
|
-
log(
|
130
|
+
log.error(
|
128
131
|
"Relay codec not included in dial codec: protocol not mounted locally"
|
129
132
|
);
|
130
133
|
}
|
@@ -133,7 +136,7 @@ export class WakuNode implements Waku {
|
|
133
136
|
if (this.store) {
|
134
137
|
codecs.push(this.store.multicodec);
|
135
138
|
} else {
|
136
|
-
log(
|
139
|
+
log.error(
|
137
140
|
"Store codec not included in dial codec: protocol not mounted locally"
|
138
141
|
);
|
139
142
|
}
|
@@ -142,7 +145,7 @@ export class WakuNode implements Waku {
|
|
142
145
|
if (this.lightPush) {
|
143
146
|
codecs.push(this.lightPush.multicodec);
|
144
147
|
} else {
|
145
|
-
log(
|
148
|
+
log.error(
|
146
149
|
"Light Push codec not included in dial codec: protocol not mounted locally"
|
147
150
|
);
|
148
151
|
}
|
@@ -151,13 +154,13 @@ export class WakuNode implements Waku {
|
|
151
154
|
if (this.filter) {
|
152
155
|
codecs.push(this.filter.multicodec);
|
153
156
|
} else {
|
154
|
-
log(
|
157
|
+
log.error(
|
155
158
|
"Filter codec not included in dial codec: protocol not mounted locally"
|
156
159
|
);
|
157
160
|
}
|
158
161
|
}
|
159
162
|
|
160
|
-
log(`Dialing to ${peerId.toString()} with protocols ${_protocols}`);
|
163
|
+
log.info(`Dialing to ${peerId.toString()} with protocols ${_protocols}`);
|
161
164
|
|
162
165
|
return this.libp2p.dialProtocol(peerId, codecs);
|
163
166
|
}
|
@@ -1 +0,0 @@
|
|
1
|
-
export declare function pushOrInitMapSet<K, V>(map: Map<K, Set<V>>, key: K, newValue: V): void;
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"push_or_init_map.js","sourceRoot":"","sources":["../../src/lib/push_or_init_map.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,gBAAgB,CAC9B,GAAmB,EACnB,GAAM,EACN,QAAW;IAEX,IAAI,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,IAAI,OAAO,GAAG,KAAK,WAAW,EAAE;QAC9B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QACxB,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAW,CAAC;KAC9B;IAED,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;AACpB,CAAC"}
|