@waku/core 0.0.30-e49e728.0 → 0.0.31-04bd518.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 +27 -0
- package/bundle/{base_protocol-DCOj0QWD.js → base_protocol-BM6GbS_d.js} +20 -20
- package/bundle/{browser-zSUobdfj.js → index-DnW8ifxc.js} +616 -5
- package/bundle/index.js +103 -102
- package/bundle/lib/base_protocol.js +2 -3
- package/bundle/lib/message/version_0.js +2 -3
- package/bundle/{version_0-TEIsGmpJ.js → version_0-WhJLc79v.js} +2 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.d.ts +2 -2
- package/dist/lib/base_protocol.js +1 -1
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager.d.ts +4 -3
- package/dist/lib/connection_manager.js +37 -39
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/filter_rpc.js.map +1 -1
- package/dist/lib/filter/index.d.ts +2 -2
- package/dist/lib/filter/index.js +34 -30
- package/dist/lib/filter/index.js.map +1 -1
- package/dist/lib/keep_alive_manager.d.ts +13 -7
- package/dist/lib/keep_alive_manager.js +9 -9
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/push_rpc.js.map +1 -1
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/metadata/index.js +18 -18
- package/dist/lib/metadata/index.js.map +1 -1
- package/dist/lib/store/history_rpc.js.map +1 -1
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/stream_manager/index.d.ts +1 -0
- package/dist/lib/stream_manager/index.js +2 -0
- package/dist/lib/stream_manager/index.js.map +1 -0
- package/dist/lib/{stream_manager.js → stream_manager/stream_manager.js} +1 -1
- package/dist/lib/stream_manager/stream_manager.js.map +1 -0
- package/dist/lib/stream_manager/utils.d.ts +2 -0
- package/dist/lib/stream_manager/utils.js +19 -0
- package/dist/lib/stream_manager/utils.js.map +1 -0
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/lib/base_protocol.ts +4 -3
- package/src/lib/connection_manager.ts +54 -55
- package/src/lib/filter/filter_rpc.ts +21 -19
- package/src/lib/filter/index.ts +54 -45
- package/src/lib/keep_alive_manager.ts +27 -18
- package/src/lib/light_push/index.ts +2 -2
- package/src/lib/light_push/push_rpc.ts +5 -5
- package/src/lib/message/version_0.ts +17 -15
- package/src/lib/metadata/index.ts +33 -33
- package/src/lib/store/history_rpc.ts +5 -5
- package/src/lib/store/index.ts +2 -2
- package/src/lib/stream_manager/index.ts +1 -0
- package/src/lib/{stream_manager.ts → stream_manager/stream_manager.ts} +3 -2
- package/src/lib/stream_manager/utils.ts +22 -0
- package/bundle/index-BcSodzY4.js +0 -614
- package/bundle/lib/predefined_bootstrap_nodes.js +0 -81
- package/dist/lib/predefined_bootstrap_nodes.d.ts +0 -34
- package/dist/lib/predefined_bootstrap_nodes.js +0 -54
- package/dist/lib/predefined_bootstrap_nodes.js.map +0 -1
- package/dist/lib/stream_manager.js.map +0 -1
- package/src/lib/predefined_bootstrap_nodes.ts +0 -68
- /package/dist/lib/{stream_manager.d.ts → stream_manager/stream_manager.d.ts} +0 -0
@@ -20,28 +20,28 @@ export const Version = 0;
|
|
20
20
|
export { proto };
|
21
21
|
|
22
22
|
export class DecodedMessage implements IDecodedMessage {
|
23
|
-
constructor(
|
23
|
+
public constructor(
|
24
24
|
public pubsubTopic: string,
|
25
25
|
protected proto: proto.WakuMessage
|
26
26
|
) {}
|
27
27
|
|
28
|
-
get ephemeral(): boolean {
|
28
|
+
public get ephemeral(): boolean {
|
29
29
|
return Boolean(this.proto.ephemeral);
|
30
30
|
}
|
31
31
|
|
32
|
-
get payload(): Uint8Array {
|
32
|
+
public get payload(): Uint8Array {
|
33
33
|
return this.proto.payload;
|
34
34
|
}
|
35
35
|
|
36
|
-
get contentTopic(): string {
|
36
|
+
public get contentTopic(): string {
|
37
37
|
return this.proto.contentTopic;
|
38
38
|
}
|
39
39
|
|
40
|
-
get _rawTimestamp(): bigint | undefined {
|
40
|
+
public get _rawTimestamp(): bigint | undefined {
|
41
41
|
return this.proto.timestamp;
|
42
42
|
}
|
43
43
|
|
44
|
-
get timestamp(): Date | undefined {
|
44
|
+
public get timestamp(): Date | undefined {
|
45
45
|
// In the case we receive a value that is bigger than JS's max number,
|
46
46
|
// we catch the error and return undefined.
|
47
47
|
try {
|
@@ -56,23 +56,23 @@ export class DecodedMessage implements IDecodedMessage {
|
|
56
56
|
}
|
57
57
|
}
|
58
58
|
|
59
|
-
get meta(): Uint8Array | undefined {
|
59
|
+
public get meta(): Uint8Array | undefined {
|
60
60
|
return this.proto.meta;
|
61
61
|
}
|
62
62
|
|
63
|
-
get version(): number {
|
63
|
+
public get version(): number {
|
64
64
|
// https://rfc.vac.dev/spec/14/
|
65
65
|
// > If omitted, the value SHOULD be interpreted as version 0.
|
66
66
|
return this.proto.version ?? 0;
|
67
67
|
}
|
68
68
|
|
69
|
-
get rateLimitProof(): IRateLimitProof | undefined {
|
69
|
+
public get rateLimitProof(): IRateLimitProof | undefined {
|
70
70
|
return this.proto.rateLimitProof;
|
71
71
|
}
|
72
72
|
}
|
73
73
|
|
74
74
|
export class Encoder implements IEncoder {
|
75
|
-
constructor(
|
75
|
+
public constructor(
|
76
76
|
public contentTopic: string,
|
77
77
|
public ephemeral: boolean = false,
|
78
78
|
public pubsubTopic: PubsubTopic,
|
@@ -83,11 +83,11 @@ export class Encoder implements IEncoder {
|
|
83
83
|
}
|
84
84
|
}
|
85
85
|
|
86
|
-
async toWire(message: IMessage): Promise<Uint8Array> {
|
86
|
+
public async toWire(message: IMessage): Promise<Uint8Array> {
|
87
87
|
return proto.WakuMessage.encode(await this.toProtoObj(message));
|
88
88
|
}
|
89
89
|
|
90
|
-
async toProtoObj(message: IMessage): Promise<IProtoMessage> {
|
90
|
+
public async toProtoObj(message: IMessage): Promise<IProtoMessage> {
|
91
91
|
const timestamp = message.timestamp ?? new Date();
|
92
92
|
|
93
93
|
const protoMessage = {
|
@@ -133,7 +133,7 @@ export function createEncoder({
|
|
133
133
|
}
|
134
134
|
|
135
135
|
export class Decoder implements IDecoder<DecodedMessage> {
|
136
|
-
constructor(
|
136
|
+
public constructor(
|
137
137
|
public pubsubTopic: PubsubTopic,
|
138
138
|
public contentTopic: string
|
139
139
|
) {
|
@@ -142,7 +142,9 @@ export class Decoder implements IDecoder<DecodedMessage> {
|
|
142
142
|
}
|
143
143
|
}
|
144
144
|
|
145
|
-
fromWireToProtoObj(
|
145
|
+
public fromWireToProtoObj(
|
146
|
+
bytes: Uint8Array
|
147
|
+
): Promise<IProtoMessage | undefined> {
|
146
148
|
const protoMessage = proto.WakuMessage.decode(bytes);
|
147
149
|
return Promise.resolve({
|
148
150
|
payload: protoMessage.payload,
|
@@ -155,7 +157,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
|
|
155
157
|
});
|
156
158
|
}
|
157
159
|
|
158
|
-
async fromProtoObj(
|
160
|
+
public async fromProtoObj(
|
159
161
|
pubsubTopic: string,
|
160
162
|
proto: IProtoMessage
|
161
163
|
): Promise<DecodedMessage | undefined> {
|
@@ -23,9 +23,9 @@ export const MetadataCodec = "/vac/waku/metadata/1.0.0";
|
|
23
23
|
|
24
24
|
class Metadata extends BaseProtocol implements IMetadata {
|
25
25
|
private libp2pComponents: Libp2pComponents;
|
26
|
-
handshakesConfirmed: Map<PeerIdStr, ShardInfo> = new Map();
|
26
|
+
protected handshakesConfirmed: Map<PeerIdStr, ShardInfo> = new Map();
|
27
27
|
|
28
|
-
constructor(
|
28
|
+
public constructor(
|
29
29
|
public shardInfo: ShardInfo,
|
30
30
|
libp2p: Libp2pComponents
|
31
31
|
) {
|
@@ -41,40 +41,10 @@ class Metadata extends BaseProtocol implements IMetadata {
|
|
41
41
|
});
|
42
42
|
}
|
43
43
|
|
44
|
-
/**
|
45
|
-
* Handle an incoming metadata request
|
46
|
-
*/
|
47
|
-
private async onRequest(streamData: IncomingStreamData): Promise<void> {
|
48
|
-
try {
|
49
|
-
const { stream, connection } = streamData;
|
50
|
-
const encodedShardInfo = proto_metadata.WakuMetadataResponse.encode(
|
51
|
-
this.shardInfo
|
52
|
-
);
|
53
|
-
|
54
|
-
const encodedResponse = await pipe(
|
55
|
-
[encodedShardInfo],
|
56
|
-
lp.encode,
|
57
|
-
stream,
|
58
|
-
lp.decode,
|
59
|
-
async (source) => await all(source)
|
60
|
-
);
|
61
|
-
|
62
|
-
const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
|
63
|
-
|
64
|
-
if (error) {
|
65
|
-
return;
|
66
|
-
}
|
67
|
-
|
68
|
-
await this.savePeerShardInfo(connection.remotePeer, shardInfo);
|
69
|
-
} catch (error) {
|
70
|
-
log.error("Error handling metadata request", error);
|
71
|
-
}
|
72
|
-
}
|
73
|
-
|
74
44
|
/**
|
75
45
|
* Make a metadata query to a peer
|
76
46
|
*/
|
77
|
-
async query(peerId: PeerId): Promise<MetadataQueryResult> {
|
47
|
+
public async query(peerId: PeerId): Promise<MetadataQueryResult> {
|
78
48
|
const request = proto_metadata.WakuMetadataRequest.encode(this.shardInfo);
|
79
49
|
|
80
50
|
const peer = await this.peerStore.get(peerId);
|
@@ -135,6 +105,36 @@ class Metadata extends BaseProtocol implements IMetadata {
|
|
135
105
|
return await this.query(peerId);
|
136
106
|
}
|
137
107
|
|
108
|
+
/**
|
109
|
+
* Handle an incoming metadata request
|
110
|
+
*/
|
111
|
+
private async onRequest(streamData: IncomingStreamData): Promise<void> {
|
112
|
+
try {
|
113
|
+
const { stream, connection } = streamData;
|
114
|
+
const encodedShardInfo = proto_metadata.WakuMetadataResponse.encode(
|
115
|
+
this.shardInfo
|
116
|
+
);
|
117
|
+
|
118
|
+
const encodedResponse = await pipe(
|
119
|
+
[encodedShardInfo],
|
120
|
+
lp.encode,
|
121
|
+
stream,
|
122
|
+
lp.decode,
|
123
|
+
async (source) => await all(source)
|
124
|
+
);
|
125
|
+
|
126
|
+
const { error, shardInfo } = this.decodeMetadataResponse(encodedResponse);
|
127
|
+
|
128
|
+
if (error) {
|
129
|
+
return;
|
130
|
+
}
|
131
|
+
|
132
|
+
await this.savePeerShardInfo(connection.remotePeer, shardInfo);
|
133
|
+
} catch (error) {
|
134
|
+
log.error("Error handling metadata request", error);
|
135
|
+
}
|
136
|
+
}
|
137
|
+
|
138
138
|
private decodeMetadataResponse(
|
139
139
|
encodedResponse: Uint8ArrayList[]
|
140
140
|
): MetadataQueryResult {
|
@@ -22,18 +22,18 @@ export interface Params {
|
|
22
22
|
export class HistoryRpc {
|
23
23
|
private constructor(public readonly proto: proto.HistoryRpc) {}
|
24
24
|
|
25
|
-
get query(): proto.HistoryQuery | undefined {
|
25
|
+
public get query(): proto.HistoryQuery | undefined {
|
26
26
|
return this.proto.query;
|
27
27
|
}
|
28
28
|
|
29
|
-
get response(): proto.HistoryResponse | undefined {
|
29
|
+
public get response(): proto.HistoryResponse | undefined {
|
30
30
|
return this.proto.response;
|
31
31
|
}
|
32
32
|
|
33
33
|
/**
|
34
34
|
* Create History Query.
|
35
35
|
*/
|
36
|
-
static createQuery(params: Params): HistoryRpc {
|
36
|
+
public static createQuery(params: Params): HistoryRpc {
|
37
37
|
const contentFilters = params.contentTopics.map((contentTopic) => {
|
38
38
|
return { contentTopic };
|
39
39
|
});
|
@@ -69,12 +69,12 @@ export class HistoryRpc {
|
|
69
69
|
});
|
70
70
|
}
|
71
71
|
|
72
|
-
decode(bytes: Uint8ArrayList): HistoryRpc {
|
72
|
+
public decode(bytes: Uint8ArrayList): HistoryRpc {
|
73
73
|
const res = proto.HistoryRpc.decode(bytes);
|
74
74
|
return new HistoryRpc(res);
|
75
75
|
}
|
76
76
|
|
77
|
-
encode(): Uint8Array {
|
77
|
+
public encode(): Uint8Array {
|
78
78
|
return proto.HistoryRpc.encode(this.proto);
|
79
79
|
}
|
80
80
|
}
|
package/src/lib/store/index.ts
CHANGED
@@ -68,11 +68,11 @@ export interface QueryOptions {
|
|
68
68
|
* The Waku Store protocol can be used to retrieved historical messages.
|
69
69
|
*/
|
70
70
|
export class StoreCore extends BaseProtocol implements IStoreCore {
|
71
|
-
constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
|
71
|
+
public constructor(libp2p: Libp2p, options?: ProtocolCreateOptions) {
|
72
72
|
super(StoreCodec, libp2p.components, log, options!.pubsubTopics!, options);
|
73
73
|
}
|
74
74
|
|
75
|
-
async *queryPerPage<T extends IDecodedMessage>(
|
75
|
+
public async *queryPerPage<T extends IDecodedMessage>(
|
76
76
|
queryOpts: Params,
|
77
77
|
decoders: Map<string, IDecoder<T>>,
|
78
78
|
peer: Peer
|
@@ -0,0 +1 @@
|
|
1
|
+
export { StreamManager } from "./stream_manager.js";
|
@@ -2,7 +2,8 @@ import type { PeerUpdate, Stream } from "@libp2p/interface";
|
|
2
2
|
import type { Peer, PeerId } from "@libp2p/interface";
|
3
3
|
import { Libp2p } from "@waku/interfaces";
|
4
4
|
import { Logger } from "@waku/utils";
|
5
|
-
|
5
|
+
|
6
|
+
import { selectConnection } from "./utils.js";
|
6
7
|
|
7
8
|
const CONNECTION_TIMEOUT = 5_000;
|
8
9
|
const RETRY_BACKOFF_BASE = 1_000;
|
@@ -12,7 +13,7 @@ export class StreamManager {
|
|
12
13
|
private readonly streamPool: Map<string, Promise<Stream | void>>;
|
13
14
|
private readonly log: Logger;
|
14
15
|
|
15
|
-
constructor(
|
16
|
+
public constructor(
|
16
17
|
public multicodec: string,
|
17
18
|
public getConnections: Libp2p["getConnections"],
|
18
19
|
public addEventListener: Libp2p["addEventListener"]
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import type { Connection } from "@libp2p/interface";
|
2
|
+
|
3
|
+
export function selectConnection(
|
4
|
+
connections: Connection[]
|
5
|
+
): Connection | undefined {
|
6
|
+
if (!connections.length) return;
|
7
|
+
if (connections.length === 1) return connections[0];
|
8
|
+
|
9
|
+
let latestConnection: Connection | undefined;
|
10
|
+
|
11
|
+
connections.forEach((connection) => {
|
12
|
+
if (connection.status === "open") {
|
13
|
+
if (!latestConnection) {
|
14
|
+
latestConnection = connection;
|
15
|
+
} else if (connection.timeline.open > latestConnection.timeline.open) {
|
16
|
+
latestConnection = connection;
|
17
|
+
}
|
18
|
+
}
|
19
|
+
});
|
20
|
+
|
21
|
+
return latestConnection;
|
22
|
+
}
|