@waku/core 0.0.6 → 0.0.7
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 -4
- package/bundle/index.js +10871 -3756
- package/bundle/lib/message/topic_only_message.js +33 -0
- package/bundle/lib/message/version_0.js +133 -0
- package/bundle/{message-70dbb19b.js → peer_exchange-53df2b11.js} +2175 -269
- package/dist/index.d.ts +14 -14
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/lib/{waku_filter → filter}/filter_rpc.d.ts +1 -1
- package/dist/lib/{waku_filter → filter}/filter_rpc.js +1 -1
- package/dist/lib/filter/filter_rpc.js.map +1 -0
- package/dist/lib/{waku_filter → filter}/index.d.ts +3 -3
- package/dist/lib/{waku_filter → filter}/index.js +3 -4
- package/dist/lib/filter/index.js.map +1 -0
- package/dist/lib/{waku_light_push → light_push}/index.d.ts +3 -3
- package/dist/lib/{waku_light_push → light_push}/index.js +4 -5
- package/dist/lib/light_push/index.js.map +1 -0
- package/dist/lib/{waku_light_push → light_push}/push_rpc.d.ts +1 -1
- package/dist/lib/{waku_light_push → light_push}/push_rpc.js +1 -1
- package/dist/lib/light_push/push_rpc.js.map +1 -0
- package/dist/lib/message/topic_only_message.d.ts +16 -0
- package/dist/lib/{waku_message → message}/topic_only_message.js +1 -1
- package/dist/lib/message/topic_only_message.js.map +1 -0
- package/dist/lib/message/version_0.d.ts +54 -0
- package/dist/lib/{waku_message → message}/version_0.js +35 -7
- package/dist/lib/message/version_0.js.map +1 -0
- package/dist/lib/predefined_bootstrap_nodes.js.map +1 -1
- package/dist/lib/{waku_relay → relay}/constants.d.ts +0 -0
- package/dist/lib/{waku_relay → relay}/constants.js +0 -0
- package/dist/lib/relay/constants.js.map +1 -0
- package/dist/lib/{waku_relay → relay}/index.d.ts +5 -5
- package/dist/lib/{waku_relay → relay}/index.js +5 -5
- package/dist/lib/relay/index.js.map +1 -0
- package/dist/lib/{waku_store → store}/history_rpc.d.ts +1 -1
- package/dist/lib/{waku_store → store}/history_rpc.js +1 -1
- package/dist/lib/store/history_rpc.js.map +1 -0
- package/dist/lib/{waku_store → store}/index.d.ts +7 -5
- package/dist/lib/{waku_store → store}/index.js +9 -8
- package/dist/lib/store/index.js.map +1 -0
- package/dist/lib/to_proto_message.d.ts +3 -3
- package/dist/lib/to_proto_message.js.map +1 -1
- package/dist/lib/wait_for_remote_peer.js +12 -3
- package/dist/lib/wait_for_remote_peer.js.map +1 -1
- package/dist/lib/waku.d.ts +10 -9
- package/dist/lib/waku.js +19 -9
- package/dist/lib/waku.js.map +1 -1
- package/package.json +18 -19
- package/src/index.ts +19 -14
- package/src/lib/{waku_filter → filter}/filter_rpc.ts +1 -2
- package/src/lib/{waku_filter → filter}/index.ts +26 -26
- package/src/lib/{waku_light_push → light_push}/index.ts +17 -18
- package/src/lib/{waku_light_push → light_push}/push_rpc.ts +1 -2
- package/src/lib/{waku_message → message}/topic_only_message.ts +10 -7
- package/src/lib/{waku_message → message}/version_0.ts +53 -18
- package/src/lib/predefined_bootstrap_nodes.ts +1 -1
- package/src/lib/{waku_relay → relay}/constants.ts +0 -0
- package/src/lib/{waku_relay → relay}/index.ts +20 -26
- package/src/lib/{waku_store → store}/history_rpc.ts +1 -2
- package/src/lib/{waku_store → store}/index.ts +38 -24
- package/src/lib/to_proto_message.ts +4 -5
- package/src/lib/wait_for_remote_peer.ts +17 -5
- package/src/lib/waku.ts +40 -17
- package/bundle/index-925587a4.js +0 -5642
- package/bundle/lib/wait_for_remote_peer.js +0 -324
- package/bundle/lib/waku_message/topic_only_message.js +0 -2
- package/bundle/lib/waku_message/version_0.js +0 -330
- package/bundle/topic_only_message-a80fe8b2.js +0 -82
- package/dist/lib/multiaddr_to_peer_info.d.ts +0 -3
- package/dist/lib/multiaddr_to_peer_info.js +0 -15
- package/dist/lib/multiaddr_to_peer_info.js.map +0 -1
- package/dist/lib/select_connection.d.ts +0 -2
- package/dist/lib/select_connection.js +0 -19
- package/dist/lib/select_connection.js.map +0 -1
- package/dist/lib/select_peer.d.ts +0 -15
- package/dist/lib/select_peer.js +0 -59
- package/dist/lib/select_peer.js.map +0 -1
- package/dist/lib/waku_filter/filter_rpc.js.map +0 -1
- package/dist/lib/waku_filter/index.js.map +0 -1
- package/dist/lib/waku_light_push/index.js.map +0 -1
- package/dist/lib/waku_light_push/push_rpc.js.map +0 -1
- package/dist/lib/waku_message/topic_only_message.d.ts +0 -16
- package/dist/lib/waku_message/topic_only_message.js.map +0 -1
- package/dist/lib/waku_message/version_0.d.ts +0 -30
- package/dist/lib/waku_message/version_0.js.map +0 -1
- package/dist/lib/waku_relay/constants.js.map +0 -1
- package/dist/lib/waku_relay/index.js.map +0 -1
- package/dist/lib/waku_store/history_rpc.js.map +0 -1
- package/dist/lib/waku_store/index.js.map +0 -1
- package/dist/proto/filter.d.ts +0 -66
- package/dist/proto/filter.js +0 -432
- package/dist/proto/filter.js.map +0 -1
- package/dist/proto/light_push.d.ts +0 -58
- package/dist/proto/light_push.js +0 -376
- package/dist/proto/light_push.js.map +0 -1
- package/dist/proto/message.d.ts +0 -30
- package/dist/proto/message.js +0 -222
- package/dist/proto/message.js.map +0 -1
- package/dist/proto/store.d.ts +0 -105
- package/dist/proto/store.js +0 -609
- package/dist/proto/store.js.map +0 -1
- package/dist/proto/topic_only_message.d.ts +0 -10
- package/dist/proto/topic_only_message.js +0 -46
- package/dist/proto/topic_only_message.js.map +0 -1
- package/src/lib/multiaddr_to_peer_info.ts +0 -17
- package/src/lib/select_connection.ts +0 -24
- package/src/lib/select_peer.ts +0 -77
- package/src/proto/filter.ts +0 -611
- package/src/proto/light_push.ts +0 -535
- package/src/proto/message.ts +0 -313
- package/src/proto/store.ts +0 -853
- package/src/proto/topic_only_message.ts +0 -67
@@ -1,22 +1,21 @@
|
|
1
1
|
import type {
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
IDecodedMessage,
|
3
|
+
IDecoder,
|
4
|
+
IEncoder,
|
5
|
+
IMessage,
|
6
|
+
IProtoMessage,
|
7
|
+
IRateLimitProof,
|
8
8
|
} from "@waku/interfaces";
|
9
|
+
import { proto_message as proto } from "@waku/proto";
|
9
10
|
import debug from "debug";
|
10
11
|
|
11
|
-
import * as proto from "../../proto/message";
|
12
|
-
|
13
12
|
const log = debug("waku:message:version-0");
|
14
13
|
const OneMillion = BigInt(1_000_000);
|
15
14
|
|
16
15
|
export const Version = 0;
|
17
16
|
export { proto };
|
18
17
|
|
19
|
-
export class
|
18
|
+
export class DecodedMessage implements IDecodedMessage {
|
20
19
|
constructor(protected proto: proto.WakuMessage) {}
|
21
20
|
|
22
21
|
get _rawPayload(): Uint8Array | undefined {
|
@@ -66,19 +65,19 @@ export class MessageV0 implements DecodedMessage {
|
|
66
65
|
return this.proto.version ?? 0;
|
67
66
|
}
|
68
67
|
|
69
|
-
get rateLimitProof():
|
68
|
+
get rateLimitProof(): IRateLimitProof | undefined {
|
70
69
|
return this.proto.rateLimitProof;
|
71
70
|
}
|
72
71
|
}
|
73
72
|
|
74
|
-
export class
|
73
|
+
export class Encoder implements IEncoder {
|
75
74
|
constructor(public contentTopic: string, public ephemeral: boolean = false) {}
|
76
75
|
|
77
|
-
async toWire(message:
|
76
|
+
async toWire(message: IMessage): Promise<Uint8Array> {
|
78
77
|
return proto.WakuMessage.encode(await this.toProtoObj(message));
|
79
78
|
}
|
80
79
|
|
81
|
-
async toProtoObj(message:
|
80
|
+
async toProtoObj(message: IMessage): Promise<IProtoMessage> {
|
82
81
|
const timestamp = message.timestamp ?? new Date();
|
83
82
|
|
84
83
|
return {
|
@@ -92,10 +91,29 @@ export class EncoderV0 implements Encoder {
|
|
92
91
|
}
|
93
92
|
}
|
94
93
|
|
95
|
-
|
96
|
-
|
94
|
+
/**
|
95
|
+
* Creates an encoder that encode messages without Waku level encryption or signature.
|
96
|
+
*
|
97
|
+
* An encoder is used to encode messages in the [`14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
98
|
+
* format to be sent over the Waku network. The resulting encoder can then be
|
99
|
+
* pass to { @link @waku/interfaces.LightPush.push } or
|
100
|
+
* { @link @waku/interfaces.Relay.send } to automatically encode outgoing
|
101
|
+
* messages.
|
102
|
+
*
|
103
|
+
* @param contentTopic The content topic to set on outgoing messages.
|
104
|
+
* @param ephemeral An optional flag to mark message as ephemeral, ie, not to be stored by Waku Store nodes.
|
105
|
+
*/
|
106
|
+
export function createEncoder(
|
107
|
+
contentTopic: string,
|
108
|
+
ephemeral = false
|
109
|
+
): Encoder {
|
110
|
+
return new Encoder(contentTopic, ephemeral);
|
111
|
+
}
|
97
112
|
|
98
|
-
|
113
|
+
export class Decoder implements IDecoder<DecodedMessage> {
|
114
|
+
constructor(public contentTopic: string) {}
|
115
|
+
|
116
|
+
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
|
99
117
|
const protoMessage = proto.WakuMessage.decode(bytes);
|
100
118
|
log("Message decoded", protoMessage);
|
101
119
|
return Promise.resolve({
|
@@ -108,7 +126,9 @@ export class DecoderV0 implements Decoder<MessageV0> {
|
|
108
126
|
});
|
109
127
|
}
|
110
128
|
|
111
|
-
async fromProtoObj(
|
129
|
+
async fromProtoObj(
|
130
|
+
proto: IProtoMessage
|
131
|
+
): Promise<DecodedMessage | undefined> {
|
112
132
|
// https://github.com/status-im/js-waku/issues/921
|
113
133
|
if (proto.version === undefined) {
|
114
134
|
proto.version = 0;
|
@@ -124,6 +144,21 @@ export class DecoderV0 implements Decoder<MessageV0> {
|
|
124
144
|
return Promise.resolve(undefined);
|
125
145
|
}
|
126
146
|
|
127
|
-
return new
|
147
|
+
return new DecodedMessage(proto);
|
128
148
|
}
|
129
149
|
}
|
150
|
+
|
151
|
+
/**
|
152
|
+
* Creates an decoder that decode messages without Waku level encryption.
|
153
|
+
*
|
154
|
+
* A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
155
|
+
* format when received from the Waku network. The resulting decoder can then be
|
156
|
+
* pass to { @link @waku/interfaces.Filter.subscribe } or
|
157
|
+
* { @link @waku/interfaces.Relay.subscribe } to automatically decode incoming
|
158
|
+
* messages.
|
159
|
+
*
|
160
|
+
* @param contentTopic The resulting decoder will only decode messages with this content topic.
|
161
|
+
*/
|
162
|
+
export function createDecoder(contentTopic: string): Decoder {
|
163
|
+
return new Decoder(contentTopic);
|
164
|
+
}
|
File without changes
|
@@ -4,32 +4,29 @@ import {
|
|
4
4
|
GossipsubMessage,
|
5
5
|
GossipsubOpts,
|
6
6
|
} from "@chainsafe/libp2p-gossipsub";
|
7
|
-
import {
|
8
|
-
PeerIdStr,
|
9
|
-
TopicStr,
|
10
|
-
} from "@chainsafe/libp2p-gossipsub/dist/src/types";
|
7
|
+
import type { PeerIdStr, TopicStr } from "@chainsafe/libp2p-gossipsub/types";
|
11
8
|
import { SignaturePolicy } from "@chainsafe/libp2p-gossipsub/types";
|
12
9
|
import type {
|
13
10
|
Callback,
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
IDecoder,
|
12
|
+
IEncoder,
|
13
|
+
IMessage,
|
14
|
+
IRelay,
|
18
15
|
SendResult,
|
19
16
|
} from "@waku/interfaces";
|
20
|
-
import {
|
17
|
+
import { IDecodedMessage } from "@waku/interfaces";
|
21
18
|
import debug from "debug";
|
22
19
|
|
23
|
-
import { DefaultPubSubTopic } from "../constants";
|
24
|
-
import {
|
25
|
-
import {
|
20
|
+
import { DefaultPubSubTopic } from "../constants.js";
|
21
|
+
import { TopicOnlyDecoder } from "../message/topic_only_message.js";
|
22
|
+
import { pushOrInitMapSet } from "../push_or_init_map.js";
|
26
23
|
|
27
|
-
import * as constants from "./constants";
|
24
|
+
import * as constants from "./constants.js";
|
28
25
|
|
29
26
|
const log = debug("waku:relay");
|
30
27
|
|
31
|
-
export type Observer<T extends
|
32
|
-
decoder:
|
28
|
+
export type Observer<T extends IDecodedMessage> = {
|
29
|
+
decoder: IDecoder<T>;
|
33
30
|
callback: Callback<T>;
|
34
31
|
};
|
35
32
|
|
@@ -56,9 +53,9 @@ export type CreateOptions = {
|
|
56
53
|
*
|
57
54
|
* @implements {require('libp2p-interfaces/src/pubsub')}
|
58
55
|
*/
|
59
|
-
class
|
56
|
+
class Relay extends GossipSub implements IRelay {
|
60
57
|
pubSubTopic: string;
|
61
|
-
defaultDecoder:
|
58
|
+
defaultDecoder: IDecoder<IDecodedMessage>;
|
62
59
|
public static multicodec: string = constants.RelayCodecs[0];
|
63
60
|
|
64
61
|
/**
|
@@ -102,10 +99,7 @@ class WakuRelay extends GossipSub implements Relay {
|
|
102
99
|
/**
|
103
100
|
* Send Waku message.
|
104
101
|
*/
|
105
|
-
public async send(
|
106
|
-
encoder: Encoder,
|
107
|
-
message: Partial<Message>
|
108
|
-
): Promise<SendResult> {
|
102
|
+
public async send(encoder: IEncoder, message: IMessage): Promise<SendResult> {
|
109
103
|
const msg = await encoder.toWire(message);
|
110
104
|
if (!msg) {
|
111
105
|
log("Failed to encode message, aborting publish");
|
@@ -119,8 +113,8 @@ class WakuRelay extends GossipSub implements Relay {
|
|
119
113
|
*
|
120
114
|
* @returns Function to delete the observer
|
121
115
|
*/
|
122
|
-
addObserver<T extends
|
123
|
-
decoder:
|
116
|
+
addObserver<T extends IDecodedMessage>(
|
117
|
+
decoder: IDecoder<T>,
|
124
118
|
callback: Callback<T>
|
125
119
|
): () => void {
|
126
120
|
const observer = {
|
@@ -191,10 +185,10 @@ class WakuRelay extends GossipSub implements Relay {
|
|
191
185
|
}
|
192
186
|
}
|
193
187
|
|
194
|
-
|
188
|
+
Relay.multicodec = constants.RelayCodecs[constants.RelayCodecs.length - 1];
|
195
189
|
|
196
190
|
export function wakuRelay(
|
197
191
|
init: Partial<CreateOptions> = {}
|
198
|
-
): (components: GossipSubComponents) =>
|
199
|
-
return (components: GossipSubComponents) => new
|
192
|
+
): (components: GossipSubComponents) => IRelay {
|
193
|
+
return (components: GossipSubComponents) => new Relay(components, init);
|
200
194
|
}
|
@@ -1,8 +1,7 @@
|
|
1
|
+
import { proto_store as proto } from "@waku/proto";
|
1
2
|
import type { Uint8ArrayList } from "uint8arraylist";
|
2
3
|
import { v4 as uuid } from "uuid";
|
3
4
|
|
4
|
-
import * as proto from "../../proto/store";
|
5
|
-
|
6
5
|
const OneMillion = BigInt(1_000_000);
|
7
6
|
|
8
7
|
export enum PageDirection {
|
@@ -4,20 +4,29 @@ import type { PeerId } from "@libp2p/interface-peer-id";
|
|
4
4
|
import type { Peer, PeerStore } from "@libp2p/interface-peer-store";
|
5
5
|
import { sha256 } from "@noble/hashes/sha256";
|
6
6
|
import { concat, utf8ToBytes } from "@waku/byte-utils";
|
7
|
-
import {
|
7
|
+
import {
|
8
|
+
Cursor,
|
9
|
+
IDecodedMessage,
|
10
|
+
IDecoder,
|
11
|
+
Index,
|
12
|
+
IStore,
|
13
|
+
} from "@waku/interfaces";
|
14
|
+
import {
|
15
|
+
getPeersForProtocol,
|
16
|
+
selectConnection,
|
17
|
+
selectPeerForProtocol,
|
18
|
+
} from "@waku/libp2p-utils";
|
19
|
+
import { proto_store as proto } from "@waku/proto";
|
8
20
|
import debug from "debug";
|
9
21
|
import all from "it-all";
|
10
22
|
import * as lp from "it-length-prefixed";
|
11
23
|
import { pipe } from "it-pipe";
|
12
24
|
import { Uint8ArrayList } from "uint8arraylist";
|
13
25
|
|
14
|
-
import
|
15
|
-
import {
|
16
|
-
import { selectConnection } from "../select_connection";
|
17
|
-
import { getPeersForProtocol, selectPeerForProtocol } from "../select_peer";
|
18
|
-
import { toProtoMessage } from "../to_proto_message";
|
26
|
+
import { DefaultPubSubTopic } from "../constants.js";
|
27
|
+
import { toProtoMessage } from "../to_proto_message.js";
|
19
28
|
|
20
|
-
import { HistoryRPC, PageDirection, Params } from "./history_rpc";
|
29
|
+
import { HistoryRPC, PageDirection, Params } from "./history_rpc.js";
|
21
30
|
|
22
31
|
import HistoryError = proto.HistoryResponse.HistoryError;
|
23
32
|
|
@@ -84,8 +93,10 @@ export interface QueryOptions {
|
|
84
93
|
timeFilter?: TimeFilter;
|
85
94
|
/**
|
86
95
|
* Cursor as an index to start a query from.
|
96
|
+
* The cursor index will be exclusive (i.e. the message at the cursor index will not be included in the result).
|
97
|
+
* If undefined, the query will start from the beginning or end of the history, depending on the page direction.
|
87
98
|
*/
|
88
|
-
cursor?:
|
99
|
+
cursor?: Cursor;
|
89
100
|
}
|
90
101
|
|
91
102
|
/**
|
@@ -93,7 +104,7 @@ export interface QueryOptions {
|
|
93
104
|
*
|
94
105
|
* The Waku Store protocol can be used to retrieved historical messages.
|
95
106
|
*/
|
96
|
-
class
|
107
|
+
class Store implements IStore {
|
97
108
|
pubSubTopic: string;
|
98
109
|
|
99
110
|
constructor(public components: StoreComponents, options?: CreateOptions) {
|
@@ -117,8 +128,8 @@ class WakuStore implements Store {
|
|
117
128
|
* or if an error is encountered when processing the reply,
|
118
129
|
* or if two decoders with the same content topic are passed.
|
119
130
|
*/
|
120
|
-
async queryOrderedCallback<T extends
|
121
|
-
decoders:
|
131
|
+
async queryOrderedCallback<T extends IDecodedMessage>(
|
132
|
+
decoders: IDecoder<T>[],
|
122
133
|
callback: (message: T) => Promise<void | boolean> | boolean | void,
|
123
134
|
options?: QueryOptions
|
124
135
|
): Promise<void> {
|
@@ -166,8 +177,8 @@ class WakuStore implements Store {
|
|
166
177
|
* or if an error is encountered when processing the reply,
|
167
178
|
* or if two decoders with the same content topic are passed.
|
168
179
|
*/
|
169
|
-
async queryCallbackOnPromise<T extends
|
170
|
-
decoders:
|
180
|
+
async queryCallbackOnPromise<T extends IDecodedMessage>(
|
181
|
+
decoders: IDecoder<T>[],
|
171
182
|
callback: (
|
172
183
|
message: Promise<T | undefined>
|
173
184
|
) => Promise<void | boolean> | boolean | void,
|
@@ -204,8 +215,8 @@ class WakuStore implements Store {
|
|
204
215
|
* or if an error is encountered when processing the reply,
|
205
216
|
* or if two decoders with the same content topic are passed.
|
206
217
|
*/
|
207
|
-
async *queryGenerator<T extends
|
208
|
-
decoders:
|
218
|
+
async *queryGenerator<T extends IDecodedMessage>(
|
219
|
+
decoders: IDecoder<T>[],
|
209
220
|
options?: QueryOptions
|
210
221
|
): AsyncGenerator<Promise<T | undefined>[]> {
|
211
222
|
let startTime, endTime;
|
@@ -284,12 +295,12 @@ class WakuStore implements Store {
|
|
284
295
|
}
|
285
296
|
}
|
286
297
|
|
287
|
-
async function* paginate<T extends
|
298
|
+
async function* paginate<T extends IDecodedMessage>(
|
288
299
|
connection: Connection,
|
289
300
|
protocol: string,
|
290
301
|
queryOpts: Params,
|
291
|
-
decoders: Map<string,
|
292
|
-
cursor?:
|
302
|
+
decoders: Map<string, IDecoder<T>>,
|
303
|
+
cursor?: Cursor
|
293
304
|
): AsyncGenerator<Promise<T | undefined>[]> {
|
294
305
|
if (
|
295
306
|
queryOpts.contentTopics.toString() !==
|
@@ -300,8 +311,9 @@ async function* paginate<T extends DecodedMessage>(
|
|
300
311
|
);
|
301
312
|
}
|
302
313
|
|
314
|
+
let currentCursor = cursor;
|
303
315
|
while (true) {
|
304
|
-
queryOpts =
|
316
|
+
queryOpts.cursor = currentCursor;
|
305
317
|
|
306
318
|
const stream = await connection.newStream(protocol);
|
307
319
|
const historyRpcQuery = HistoryRPC.createQuery(queryOpts);
|
@@ -362,8 +374,8 @@ async function* paginate<T extends DecodedMessage>(
|
|
362
374
|
return Promise.resolve(undefined);
|
363
375
|
});
|
364
376
|
|
365
|
-
|
366
|
-
if (typeof
|
377
|
+
const nextCursor = response.pagingInfo?.cursor;
|
378
|
+
if (typeof nextCursor === "undefined") {
|
367
379
|
// If the server does not return cursor then there is an issue,
|
368
380
|
// Need to abort, or we end up in an infinite loop
|
369
381
|
log(
|
@@ -372,6 +384,8 @@ async function* paginate<T extends DecodedMessage>(
|
|
372
384
|
break;
|
373
385
|
}
|
374
386
|
|
387
|
+
currentCursor = nextCursor;
|
388
|
+
|
375
389
|
const responsePageSize = response.pagingInfo?.pageSize;
|
376
390
|
const queryPageSize = historyRpcQuery.query?.pagingInfo?.pageSize;
|
377
391
|
if (
|
@@ -390,7 +404,7 @@ export function isDefined<T>(msg: T | undefined): msg is T {
|
|
390
404
|
}
|
391
405
|
|
392
406
|
export async function createCursor(
|
393
|
-
message:
|
407
|
+
message: IDecodedMessage,
|
394
408
|
pubsubTopic: string = DefaultPubSubTopic
|
395
409
|
): Promise<Index> {
|
396
410
|
if (
|
@@ -418,6 +432,6 @@ export async function createCursor(
|
|
418
432
|
|
419
433
|
export function wakuStore(
|
420
434
|
init: Partial<CreateOptions> = {}
|
421
|
-
): (components: StoreComponents) =>
|
422
|
-
return (components: StoreComponents) => new
|
435
|
+
): (components: StoreComponents) => IStore {
|
436
|
+
return (components: StoreComponents) => new Store(components, init);
|
423
437
|
}
|
@@ -1,8 +1,7 @@
|
|
1
|
-
import {
|
1
|
+
import { IProtoMessage } from "@waku/interfaces";
|
2
|
+
import { WakuMessage as WakuMessageProto } from "@waku/proto";
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
const EmptyMessage: ProtoMessage = {
|
4
|
+
const EmptyMessage: IProtoMessage = {
|
6
5
|
payload: undefined,
|
7
6
|
contentTopic: undefined,
|
8
7
|
version: undefined,
|
@@ -11,6 +10,6 @@ const EmptyMessage: ProtoMessage = {
|
|
11
10
|
ephemeral: undefined,
|
12
11
|
};
|
13
12
|
|
14
|
-
export function toProtoMessage(wire: WakuMessageProto):
|
13
|
+
export function toProtoMessage(wire: WakuMessageProto): IProtoMessage {
|
15
14
|
return { ...EmptyMessage, ...wire };
|
16
15
|
}
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import { PeerProtocolsChangeData } from "@libp2p/interface-peer-store";
|
2
|
-
import type {
|
2
|
+
import type { IRelay, PointToPointProtocol, Waku } from "@waku/interfaces";
|
3
3
|
import { Protocols } from "@waku/interfaces";
|
4
|
+
import { PeerExchangeCodec } from "@waku/peer-exchange";
|
4
5
|
import debug from "debug";
|
5
6
|
import { pEvent } from "p-event";
|
6
7
|
|
7
|
-
import { FilterCodec } from "./
|
8
|
-
import { LightPushCodec } from "./
|
9
|
-
import { StoreCodec } from "./
|
8
|
+
import { FilterCodec } from "./filter/index.js";
|
9
|
+
import { LightPushCodec } from "./light_push/index.js";
|
10
|
+
import { StoreCodec } from "./store/index.js";
|
10
11
|
|
11
12
|
const log = debug("waku:wait-for-remote-peer");
|
12
13
|
|
@@ -64,6 +65,14 @@ export async function waitForRemotePeer(
|
|
64
65
|
promises.push(waitForConnectedPeer(waku.filter, [FilterCodec]));
|
65
66
|
}
|
66
67
|
|
68
|
+
if (protocols.includes(Protocols.PeerExchange)) {
|
69
|
+
if (!waku.peerExchange)
|
70
|
+
throw new Error(
|
71
|
+
"Cannot wait for Peer Exchange peer: protocol not mounted"
|
72
|
+
);
|
73
|
+
promises.push(waitForConnectedPeer(waku.peerExchange, [PeerExchangeCodec]));
|
74
|
+
}
|
75
|
+
|
67
76
|
if (timeoutMs) {
|
68
77
|
await rejectOnTimeout(
|
69
78
|
Promise.all(promises),
|
@@ -108,7 +117,7 @@ async function waitForConnectedPeer(
|
|
108
117
|
* Wait for a peer with the given protocol to be connected and in the gossipsub
|
109
118
|
* mesh.
|
110
119
|
*/
|
111
|
-
async function waitForGossipSubPeerInMesh(waku:
|
120
|
+
async function waitForGossipSubPeerInMesh(waku: IRelay): Promise<void> {
|
112
121
|
let peers = waku.getMeshPeers();
|
113
122
|
|
114
123
|
while (peers.length == 0) {
|
@@ -146,6 +155,9 @@ function getEnabledProtocols(waku: Waku): Protocols[] {
|
|
146
155
|
if (waku.lightPush) {
|
147
156
|
protocols.push(Protocols.LightPush);
|
148
157
|
}
|
158
|
+
if (waku.peerExchange) {
|
159
|
+
protocols.push(Protocols.PeerExchange);
|
160
|
+
}
|
149
161
|
|
150
162
|
return protocols;
|
151
163
|
}
|
package/src/lib/waku.ts
CHANGED
@@ -2,17 +2,26 @@ import type { Stream } from "@libp2p/interface-connection";
|
|
2
2
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
3
3
|
import type { PubSub } from "@libp2p/interface-pubsub";
|
4
4
|
import type { Multiaddr } from "@multiformats/multiaddr";
|
5
|
-
import type {
|
5
|
+
import type {
|
6
|
+
IFilter,
|
7
|
+
ILightPush,
|
8
|
+
IPeerExchange,
|
9
|
+
IRelay,
|
10
|
+
IStore,
|
11
|
+
PeerExchangeComponents,
|
12
|
+
Waku,
|
13
|
+
} from "@waku/interfaces";
|
6
14
|
import { Protocols } from "@waku/interfaces";
|
15
|
+
import { PeerExchangeCodec } from "@waku/peer-exchange";
|
7
16
|
import debug from "debug";
|
8
17
|
import type { Libp2p } from "libp2p";
|
9
18
|
|
10
|
-
import { FilterCodec, FilterComponents } from "./
|
11
|
-
import { LightPushCodec, LightPushComponents } from "./
|
12
|
-
import {
|
13
|
-
import * as relayConstants from "./
|
14
|
-
import { RelayCodecs, RelayPingContentTopic } from "./
|
15
|
-
import { StoreCodec, StoreComponents } from "./
|
19
|
+
import { FilterCodec, FilterComponents } from "./filter/index.js";
|
20
|
+
import { LightPushCodec, LightPushComponents } from "./light_push/index.js";
|
21
|
+
import { createEncoder } from "./message/version_0.js";
|
22
|
+
import * as relayConstants from "./relay/constants.js";
|
23
|
+
import { RelayCodecs, RelayPingContentTopic } from "./relay/constants.js";
|
24
|
+
import { StoreCodec, StoreComponents } from "./store/index.js";
|
16
25
|
|
17
26
|
export const DefaultPingKeepAliveValueSecs = 0;
|
18
27
|
export const DefaultRelayKeepAliveValueSecs = 5 * 60;
|
@@ -44,10 +53,11 @@ export interface WakuOptions {
|
|
44
53
|
|
45
54
|
export class WakuNode implements Waku {
|
46
55
|
public libp2p: Libp2p;
|
47
|
-
public relay?:
|
48
|
-
public store?:
|
49
|
-
public filter?:
|
50
|
-
public lightPush?:
|
56
|
+
public relay?: IRelay;
|
57
|
+
public store?: IStore;
|
58
|
+
public filter?: IFilter;
|
59
|
+
public lightPush?: ILightPush;
|
60
|
+
public peerExchange?: IPeerExchange;
|
51
61
|
|
52
62
|
private pingKeepAliveTimers: {
|
53
63
|
[peer: string]: ReturnType<typeof setInterval>;
|
@@ -59,9 +69,10 @@ export class WakuNode implements Waku {
|
|
59
69
|
constructor(
|
60
70
|
options: WakuOptions,
|
61
71
|
libp2p: Libp2p,
|
62
|
-
store?: (components: StoreComponents) =>
|
63
|
-
lightPush?: (components: LightPushComponents) =>
|
64
|
-
filter?: (components: FilterComponents) =>
|
72
|
+
store?: (components: StoreComponents) => IStore,
|
73
|
+
lightPush?: (components: LightPushComponents) => ILightPush,
|
74
|
+
filter?: (components: FilterComponents) => IFilter,
|
75
|
+
peerExchange?: (components: PeerExchangeComponents) => IPeerExchange
|
65
76
|
) {
|
66
77
|
this.libp2p = libp2p;
|
67
78
|
|
@@ -78,6 +89,10 @@ export class WakuNode implements Waku {
|
|
78
89
|
this.lightPush = lightPush(components);
|
79
90
|
}
|
80
91
|
|
92
|
+
if (peerExchange) {
|
93
|
+
this.peerExchange = peerExchange(components);
|
94
|
+
}
|
95
|
+
|
81
96
|
if (isRelay(libp2p.pubsub)) {
|
82
97
|
this.relay = libp2p.pubsub;
|
83
98
|
}
|
@@ -86,7 +101,8 @@ export class WakuNode implements Waku {
|
|
86
101
|
"Waku node created",
|
87
102
|
this.libp2p.peerId.toString(),
|
88
103
|
`relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this
|
89
|
-
.lightPush}, filter: ${!!this.filter}
|
104
|
+
.lightPush}, filter: ${!!this.filter}, peer exchange: ${!!this
|
105
|
+
.peerExchange} `
|
90
106
|
);
|
91
107
|
|
92
108
|
this.pingKeepAliveTimers = {};
|
@@ -144,6 +160,7 @@ export class WakuNode implements Waku {
|
|
144
160
|
this.store && _protocols.push(Protocols.Store);
|
145
161
|
this.filter && _protocols.push(Protocols.Filter);
|
146
162
|
this.lightPush && _protocols.push(Protocols.LightPush);
|
163
|
+
this.peerExchange && _protocols.push(Protocols.PeerExchange);
|
147
164
|
}
|
148
165
|
|
149
166
|
const codecs: string[] = [];
|
@@ -160,6 +177,12 @@ export class WakuNode implements Waku {
|
|
160
177
|
codecs.push(FilterCodec);
|
161
178
|
}
|
162
179
|
|
180
|
+
if (_protocols.includes(Protocols.PeerExchange)) {
|
181
|
+
codecs.push(PeerExchangeCodec);
|
182
|
+
}
|
183
|
+
|
184
|
+
log(`Dialing to ${peer.toString()} with protocols ${_protocols}`);
|
185
|
+
|
163
186
|
return this.libp2p.dialProtocol(peer, codecs);
|
164
187
|
}
|
165
188
|
|
@@ -211,7 +234,7 @@ export class WakuNode implements Waku {
|
|
211
234
|
|
212
235
|
const relay = this.relay;
|
213
236
|
if (relay && relayPeriodSecs !== 0) {
|
214
|
-
const encoder =
|
237
|
+
const encoder = createEncoder(RelayPingContentTopic);
|
215
238
|
this.relayKeepAliveTimers[peerIdStr] = setInterval(() => {
|
216
239
|
log("Sending Waku Relay ping message");
|
217
240
|
relay
|
@@ -248,7 +271,7 @@ export class WakuNode implements Waku {
|
|
248
271
|
}
|
249
272
|
}
|
250
273
|
|
251
|
-
function isRelay(pubsub: PubSub): pubsub is
|
274
|
+
function isRelay(pubsub: PubSub): pubsub is IRelay {
|
252
275
|
if (pubsub) {
|
253
276
|
try {
|
254
277
|
return pubsub.multicodecs.includes(
|