Skip to content

Commit a488988

Browse files
authored
Implement Waku Store 2.0.0-beta4 (#566)
1 parent b50e211 commit a488988

File tree

18 files changed

+1017
-110
lines changed

18 files changed

+1017
-110
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Changed
1111

1212
- Replaced `rlp` dependency with `@ethersproject/rlp`.
13-
- **breaking**: `staticNoiseKey` changed from `Buffer` to `Uint8Array`.
13+
- **Breaking**: `staticNoiseKey` changed from `Buffer` to `Uint8Array`.
14+
- Implement Waku Store 2.0.0-beta4. The `WakuMessage.timestamp` field now stores nanoseconds over the wire.
15+
- **Breaking**: `HistoryRPC.createQuery` takes `Date` instead of `number` for `startTime` and `endTime`.
1416

1517
### Removed
1618

buf.gen.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ version: v1beta1
33
plugins:
44
- name: ts_proto
55
out: ./src/proto
6-
opt: grpc_js,esModuleInterop=true
6+
strategy: all
7+
opt: grpc_js,esModuleInterop=true,forceLong=long

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"examples:test": "run-s examples:pretest; for d in examples/*/; do (cd $d && npm test;); done",
4444
"proto": "run-s proto:*",
4545
"proto:lint": "buf lint",
46-
"proto:build": "buf generate",
46+
"proto:build": "rimraf ./src/proto && buf generate",
4747
"watch:build": "tsc -p tsconfig.json -w",
4848
"watch:test": "nyc --silent mocha --watch",
4949
"doc": "run-s doc:*",

proto/waku/v2/message.proto

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ message WakuMessage {
66
optional bytes payload = 1;
77
optional string content_topic = 2;
88
optional uint32 version = 3;
9-
optional double timestamp = 4;
9+
optional double timestamp_deprecated = 4;
10+
optional sint64 timestamp = 10;
1011
}

proto/waku/v2/store.proto renamed to proto/waku/v2/store/v2beta3/store.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
syntax = "proto3";
22

3-
package waku.v2;
3+
package waku.v2.store.v2beta3;
44

55
import "waku/v2/message.proto";
66

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
syntax = "proto3";
2+
3+
package waku.v2.store.v2beta4;
4+
5+
import "waku/v2/message.proto";
6+
7+
message Index {
8+
bytes digest = 1;
9+
sint64 received_time = 2;
10+
sint64 sender_time = 3;
11+
}
12+
13+
message PagingInfo {
14+
uint64 page_size = 1;
15+
Index cursor = 2;
16+
enum Direction {
17+
DIRECTION_BACKWARD_UNSPECIFIED = 0;
18+
DIRECTION_FORWARD = 1;
19+
}
20+
Direction direction = 3;
21+
}
22+
23+
message ContentFilter {
24+
string content_topic = 1;
25+
}
26+
27+
message HistoryQuery {
28+
optional string pub_sub_topic = 2;
29+
repeated ContentFilter content_filters = 3;
30+
optional PagingInfo paging_info = 4;
31+
optional sint64 start_time = 5;
32+
optional sint64 end_time = 6;
33+
}
34+
35+
message HistoryResponse {
36+
repeated WakuMessage messages = 2;
37+
PagingInfo paging_info = 3;
38+
enum Error {
39+
ERROR_NONE_UNSPECIFIED = 0;
40+
ERROR_INVALID_CURSOR = 1;
41+
}
42+
Error error = 4;
43+
}
44+
45+
message HistoryRPC {
46+
string request_id = 1;
47+
HistoryQuery query = 2;
48+
HistoryResponse response = 3;
49+
}

src/index.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,4 @@ export * as waku_relay from "./lib/waku_relay";
3030
export { WakuRelay, RelayCodecs } from "./lib/waku_relay";
3131

3232
export * as waku_store from "./lib/waku_store";
33-
export { PageDirection, WakuStore, StoreCodec } from "./lib/waku_store";
34-
35-
export * as proto from "./proto";
33+
export { PageDirection, WakuStore, StoreCodecs } from "./lib/waku_store";

src/lib/select_peer.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,17 @@ export async function selectRandomPeer(
2424
*/
2525
export async function* getPeersForProtocol(
2626
libp2p: Libp2p,
27-
protocol: string
27+
protocols: string[]
2828
): AsyncIterable<Peer> {
2929
for await (const peer of libp2p.peerStore.getPeers()) {
30-
if (!peer.protocols.includes(protocol)) {
30+
let peerFound = false;
31+
for (let i = 0; i < protocols.length; i++) {
32+
if (peer.protocols.includes(protocols[i])) {
33+
peerFound = true;
34+
break;
35+
}
36+
}
37+
if (!peerFound) {
3138
continue;
3239
}
3340
yield peer;

src/lib/waku.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { LightPushCodec, WakuLightPush } from "./waku_light_push";
2121
import { DecryptionMethod, WakuMessage } from "./waku_message";
2222
import { RelayCodecs, WakuRelay } from "./waku_relay";
2323
import { RelayPingContentTopic } from "./waku_relay/constants";
24-
import { StoreCodec, WakuStore } from "./waku_store";
24+
import { StoreCodecs, WakuStore } from "./waku_store";
2525

2626
const websocketsTransportKey = Websockets.prototype[Symbol.toStringTag];
2727

@@ -246,7 +246,9 @@ export class Waku {
246246
RelayCodecs.forEach((codec) => codecs.push(codec));
247247
}
248248
if (_protocols.includes(Protocols.Store)) {
249-
codecs.push(StoreCodec);
249+
for (const codec of Object.values(StoreCodecs)) {
250+
codecs.push(codec);
251+
}
250252
}
251253
if (_protocols.includes(Protocols.LightPush)) {
252254
codecs.push(LightPushCodec);
@@ -364,9 +366,11 @@ export class Waku {
364366
this.libp2p.peerStore.on(
365367
"change:protocols",
366368
({ protocols: connectedPeerProtocols }) => {
367-
if (connectedPeerProtocols.includes(StoreCodec)) {
368-
dbg("Resolving for", StoreCodec, connectedPeerProtocols);
369-
resolve();
369+
for (const codec of Object.values(StoreCodecs)) {
370+
if (connectedPeerProtocols.includes(codec)) {
371+
dbg("Resolving for", codec, connectedPeerProtocols);
372+
resolve();
373+
}
370374
}
371375
}
372376
);

src/lib/waku_light_push/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class WakuLightPush {
100100
* light push protocol. Waku may or may not be currently connected to these peers.
101101
*/
102102
get peers(): AsyncIterable<Peer> {
103-
return getPeersForProtocol(this.libp2p, LightPushCodec);
103+
return getPeersForProtocol(this.libp2p, [LightPushCodec]);
104104
}
105105

106106
/**

0 commit comments

Comments
 (0)