@waku/core 0.0.16 → 0.0.18
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 +48 -0
- package/bundle/{browser-2f1afe46.js → browser-bde977a3.js} +12 -9
- package/bundle/index.js +4417 -34898
- package/bundle/lib/base_protocol.js +4 -1
- package/bundle/lib/message/version_0.js +2 -3
- package/bundle/{peer_exchange-1229c8b0.js → version_0-c6b47311.js} +172 -45
- package/dist/index.d.ts +1 -3
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/base_protocol.js +3 -0
- package/dist/lib/base_protocol.js.map +1 -1
- package/dist/lib/connection_manager.d.ts +1 -0
- package/dist/lib/connection_manager.js +33 -25
- package/dist/lib/connection_manager.js.map +1 -1
- package/dist/lib/filter/filter_rpc.js +1 -0
- package/dist/lib/filter/filter_rpc.js.map +1 -1
- package/dist/lib/filter/index.js +11 -4
- 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 +5 -1
- package/dist/lib/keep_alive_manager.js.map +1 -1
- package/dist/lib/light_push/index.d.ts +1 -1
- package/dist/lib/light_push/index.js +28 -8
- package/dist/lib/light_push/index.js.map +1 -1
- package/dist/lib/light_push/push_rpc.js +1 -0
- package/dist/lib/light_push/push_rpc.js.map +1 -1
- package/dist/lib/message/index.d.ts +0 -1
- package/dist/lib/message/index.js +0 -1
- package/dist/lib/message/index.js.map +1 -1
- package/dist/lib/message/version_0.d.ts +1 -2
- package/dist/lib/message/version_0.js +12 -0
- package/dist/lib/message/version_0.js.map +1 -1
- package/dist/lib/store/history_rpc.js +1 -0
- package/dist/lib/store/history_rpc.js.map +1 -1
- package/dist/lib/store/index.js +3 -1
- package/dist/lib/store/index.js.map +1 -1
- package/dist/lib/waku.d.ts +2 -2
- package/dist/lib/waku.js +14 -2
- package/dist/lib/waku.js.map +1 -1
- package/package.json +14 -23
- package/src/index.ts +1 -9
- package/src/lib/connection_manager.ts +13 -4
- package/src/lib/filter/index.ts +14 -5
- package/src/lib/keep_alive_manager.ts +1 -2
- package/src/lib/light_push/index.ts +28 -11
- package/src/lib/message/index.ts +0 -1
- package/src/lib/message/version_0.ts +11 -3
- package/src/lib/store/index.ts +2 -2
- package/src/lib/waku.ts +13 -4
- package/bundle/lib/message/topic_only_message.js +0 -3
- package/bundle/topic_only_message-e8406994.js +0 -43
- package/bundle/version_0-e9a6cfb0.js +0 -143
- package/dist/lib/group_by.d.ts +0 -3
- package/dist/lib/group_by.js +0 -13
- package/dist/lib/group_by.js.map +0 -1
- package/dist/lib/message/topic_only_message.d.ts +0 -18
- package/dist/lib/message/topic_only_message.js +0 -35
- package/dist/lib/message/topic_only_message.js.map +0 -1
- package/dist/lib/relay/constants.d.ts +0 -63
- package/dist/lib/relay/constants.js +0 -64
- package/dist/lib/relay/constants.js.map +0 -1
- package/dist/lib/relay/index.d.ts +0 -11
- package/dist/lib/relay/index.js +0 -175
- package/dist/lib/relay/index.js.map +0 -1
- package/dist/lib/relay/message_validator.d.ts +0 -4
- package/dist/lib/relay/message_validator.js +0 -25
- package/dist/lib/relay/message_validator.js.map +0 -1
- package/src/lib/group_by.ts +0 -14
- package/src/lib/message/topic_only_message.ts +0 -51
- package/src/lib/relay/constants.ts +0 -74
- package/src/lib/relay/index.ts +0 -282
- package/src/lib/relay/message_validator.ts +0 -35
@@ -1,14 +1,16 @@
|
|
1
1
|
import type { Libp2p } from "@libp2p/interface-libp2p";
|
2
2
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
3
|
-
import
|
3
|
+
import {
|
4
4
|
IEncoder,
|
5
5
|
ILightPush,
|
6
6
|
IMessage,
|
7
7
|
ProtocolCreateOptions,
|
8
8
|
ProtocolOptions,
|
9
|
+
SendError,
|
9
10
|
SendResult,
|
10
11
|
} from "@waku/interfaces";
|
11
12
|
import { PushResponse } from "@waku/proto";
|
13
|
+
import { isSizeValid } from "@waku/utils";
|
12
14
|
import debug from "debug";
|
13
15
|
import all from "it-all";
|
14
16
|
import * as lp from "it-length-prefixed";
|
@@ -47,19 +49,31 @@ class LightPush extends BaseProtocol implements ILightPush {
|
|
47
49
|
const stream = await this.newStream(peer);
|
48
50
|
|
49
51
|
const recipients: PeerId[] = [];
|
52
|
+
let error: undefined | SendError = undefined;
|
50
53
|
|
51
54
|
try {
|
55
|
+
if (!isSizeValid(message.payload)) {
|
56
|
+
log("Failed to send waku light push: message is bigger that 1MB");
|
57
|
+
return {
|
58
|
+
recipients,
|
59
|
+
error: SendError.SIZE_TOO_BIG,
|
60
|
+
};
|
61
|
+
}
|
62
|
+
|
52
63
|
const protoMessage = await encoder.toProtoObj(message);
|
53
64
|
if (!protoMessage) {
|
54
65
|
log("Failed to encode to protoMessage, aborting push");
|
55
|
-
return {
|
66
|
+
return {
|
67
|
+
recipients,
|
68
|
+
error: SendError.ENCODE_FAILED,
|
69
|
+
};
|
56
70
|
}
|
57
71
|
const query = PushRpc.createRequest(protoMessage, pubSubTopic);
|
58
72
|
const res = await pipe(
|
59
73
|
[query.encode()],
|
60
|
-
lp.encode
|
74
|
+
lp.encode,
|
61
75
|
stream,
|
62
|
-
lp.decode
|
76
|
+
lp.decode,
|
63
77
|
async (source) => await all(source)
|
64
78
|
);
|
65
79
|
try {
|
@@ -70,21 +84,24 @@ class LightPush extends BaseProtocol implements ILightPush {
|
|
70
84
|
|
71
85
|
const response = PushRpc.decode(bytes).response;
|
72
86
|
|
73
|
-
if (
|
74
|
-
log("No response in PushRPC");
|
75
|
-
return { recipients };
|
76
|
-
}
|
77
|
-
|
78
|
-
if (response.isSuccess) {
|
87
|
+
if (response?.isSuccess) {
|
79
88
|
recipients.push(peer.id);
|
89
|
+
} else {
|
90
|
+
log("No response in PushRPC");
|
91
|
+
error = SendError.NO_RPC_RESPONSE;
|
80
92
|
}
|
81
93
|
} catch (err) {
|
82
94
|
log("Failed to decode push reply", err);
|
95
|
+
error = SendError.DECODE_FAILED;
|
83
96
|
}
|
84
97
|
} catch (err) {
|
85
98
|
log("Failed to send waku light push request", err);
|
99
|
+
error = SendError.GENERIC_FAIL;
|
86
100
|
}
|
87
|
-
return {
|
101
|
+
return {
|
102
|
+
error,
|
103
|
+
recipients,
|
104
|
+
};
|
88
105
|
}
|
89
106
|
}
|
90
107
|
|
package/src/lib/message/index.ts
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
import { IMetaSetter } from "@waku/interfaces";
|
2
1
|
import type {
|
3
2
|
EncoderOptions,
|
4
3
|
IDecodedMessage,
|
5
4
|
IDecoder,
|
6
5
|
IEncoder,
|
7
6
|
IMessage,
|
7
|
+
IMetaSetter,
|
8
8
|
IProtoMessage,
|
9
9
|
IRateLimitProof,
|
10
10
|
} from "@waku/interfaces";
|
@@ -71,7 +71,11 @@ export class Encoder implements IEncoder {
|
|
71
71
|
public contentTopic: string,
|
72
72
|
public ephemeral: boolean = false,
|
73
73
|
public metaSetter?: IMetaSetter
|
74
|
-
) {
|
74
|
+
) {
|
75
|
+
if (!contentTopic || contentTopic === "") {
|
76
|
+
throw new Error("Content topic must be specified");
|
77
|
+
}
|
78
|
+
}
|
75
79
|
|
76
80
|
async toWire(message: IMessage): Promise<Uint8Array> {
|
77
81
|
return proto.WakuMessage.encode(await this.toProtoObj(message));
|
@@ -117,7 +121,11 @@ export function createEncoder({
|
|
117
121
|
}
|
118
122
|
|
119
123
|
export class Decoder implements IDecoder<DecodedMessage> {
|
120
|
-
constructor(public contentTopic: string) {
|
124
|
+
constructor(public contentTopic: string) {
|
125
|
+
if (!contentTopic || contentTopic === "") {
|
126
|
+
throw new Error("Content topic must be specified");
|
127
|
+
}
|
128
|
+
}
|
121
129
|
|
122
130
|
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
|
123
131
|
const protoMessage = proto.WakuMessage.decode(bytes);
|
package/src/lib/store/index.ts
CHANGED
package/src/lib/waku.ts
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
import type { Stream } from "@libp2p/interface-connection";
|
2
2
|
import type { Libp2p } from "@libp2p/interface-libp2p";
|
3
3
|
import type { PeerId } from "@libp2p/interface-peer-id";
|
4
|
-
import
|
4
|
+
import { isPeerId } from "@libp2p/interface-peer-id";
|
5
|
+
import type { Multiaddr, MultiaddrInput } from "@multiformats/multiaddr";
|
6
|
+
import { multiaddr } from "@multiformats/multiaddr";
|
5
7
|
import type {
|
6
8
|
IFilter,
|
7
9
|
ILightPush,
|
@@ -104,10 +106,11 @@ export class WakuNode implements Waku {
|
|
104
106
|
* @param protocols Waku protocols we expect from the peer; Defaults to mounted protocols
|
105
107
|
*/
|
106
108
|
async dial(
|
107
|
-
peer: PeerId |
|
109
|
+
peer: PeerId | MultiaddrInput,
|
108
110
|
protocols?: Protocols[]
|
109
111
|
): Promise<Stream> {
|
110
112
|
const _protocols = protocols ?? [];
|
113
|
+
const peerId = mapToPeerIdOrMultiaddr(peer);
|
111
114
|
|
112
115
|
if (typeof protocols === "undefined") {
|
113
116
|
this.relay && _protocols.push(Protocols.Relay);
|
@@ -156,9 +159,9 @@ export class WakuNode implements Waku {
|
|
156
159
|
}
|
157
160
|
}
|
158
161
|
|
159
|
-
log(`Dialing to ${
|
162
|
+
log(`Dialing to ${peerId.toString()} with protocols ${_protocols}`);
|
160
163
|
|
161
|
-
return this.libp2p.dialProtocol(
|
164
|
+
return this.libp2p.dialProtocol(peerId, codecs);
|
162
165
|
}
|
163
166
|
|
164
167
|
async start(): Promise<void> {
|
@@ -189,3 +192,9 @@ export class WakuNode implements Waku {
|
|
189
192
|
return localMultiaddr + "/p2p/" + this.libp2p.peerId.toString();
|
190
193
|
}
|
191
194
|
}
|
195
|
+
|
196
|
+
function mapToPeerIdOrMultiaddr(
|
197
|
+
peerId: PeerId | MultiaddrInput
|
198
|
+
): PeerId | Multiaddr {
|
199
|
+
return isPeerId(peerId) ? peerId : multiaddr(peerId);
|
200
|
+
}
|
@@ -1,43 +0,0 @@
|
|
1
|
-
import { T as TopicOnlyMessage$1 } from './peer_exchange-1229c8b0.js';
|
2
|
-
import { d as debug } from './browser-2f1afe46.js';
|
3
|
-
|
4
|
-
const log = debug("waku:message:topic-only");
|
5
|
-
class TopicOnlyMessage {
|
6
|
-
constructor(pubSubTopic, proto) {
|
7
|
-
this.pubSubTopic = pubSubTopic;
|
8
|
-
this.proto = proto;
|
9
|
-
this.payload = new Uint8Array();
|
10
|
-
}
|
11
|
-
get contentTopic() {
|
12
|
-
return this.proto.contentTopic;
|
13
|
-
}
|
14
|
-
}
|
15
|
-
class TopicOnlyDecoder {
|
16
|
-
constructor() {
|
17
|
-
this.contentTopic = "";
|
18
|
-
}
|
19
|
-
fromWireToProtoObj(bytes) {
|
20
|
-
const protoMessage = TopicOnlyMessage$1.decode(bytes);
|
21
|
-
log("Message decoded", protoMessage);
|
22
|
-
return Promise.resolve({
|
23
|
-
contentTopic: protoMessage.contentTopic,
|
24
|
-
payload: new Uint8Array(),
|
25
|
-
rateLimitProof: undefined,
|
26
|
-
timestamp: undefined,
|
27
|
-
meta: undefined,
|
28
|
-
version: undefined,
|
29
|
-
ephemeral: undefined,
|
30
|
-
});
|
31
|
-
}
|
32
|
-
async fromProtoObj(pubSubTopic, proto) {
|
33
|
-
return new TopicOnlyMessage(pubSubTopic, proto);
|
34
|
-
}
|
35
|
-
}
|
36
|
-
|
37
|
-
var topic_only_message = /*#__PURE__*/Object.freeze({
|
38
|
-
__proto__: null,
|
39
|
-
TopicOnlyDecoder: TopicOnlyDecoder,
|
40
|
-
TopicOnlyMessage: TopicOnlyMessage
|
41
|
-
});
|
42
|
-
|
43
|
-
export { TopicOnlyDecoder as T, TopicOnlyMessage as a, topic_only_message as t };
|
@@ -1,143 +0,0 @@
|
|
1
|
-
import { W as WakuMessage, m as message } from './peer_exchange-1229c8b0.js';
|
2
|
-
import { d as debug } from './browser-2f1afe46.js';
|
3
|
-
|
4
|
-
const log = debug("waku:message:version-0");
|
5
|
-
const OneMillion = BigInt(1000000);
|
6
|
-
const Version = 0;
|
7
|
-
class DecodedMessage {
|
8
|
-
constructor(pubSubTopic, proto) {
|
9
|
-
this.pubSubTopic = pubSubTopic;
|
10
|
-
this.proto = proto;
|
11
|
-
}
|
12
|
-
get ephemeral() {
|
13
|
-
return Boolean(this.proto.ephemeral);
|
14
|
-
}
|
15
|
-
get payload() {
|
16
|
-
return this.proto.payload;
|
17
|
-
}
|
18
|
-
get contentTopic() {
|
19
|
-
return this.proto.contentTopic;
|
20
|
-
}
|
21
|
-
get _rawTimestamp() {
|
22
|
-
return this.proto.timestamp;
|
23
|
-
}
|
24
|
-
get timestamp() {
|
25
|
-
// In the case we receive a value that is bigger than JS's max number,
|
26
|
-
// we catch the error and return undefined.
|
27
|
-
try {
|
28
|
-
if (this.proto.timestamp) {
|
29
|
-
// nanoseconds 10^-9 to milliseconds 10^-3
|
30
|
-
const timestamp = this.proto.timestamp / OneMillion;
|
31
|
-
return new Date(Number(timestamp));
|
32
|
-
}
|
33
|
-
return;
|
34
|
-
}
|
35
|
-
catch (e) {
|
36
|
-
return;
|
37
|
-
}
|
38
|
-
}
|
39
|
-
get meta() {
|
40
|
-
return this.proto.meta;
|
41
|
-
}
|
42
|
-
get version() {
|
43
|
-
// https://rfc.vac.dev/spec/14/
|
44
|
-
// > If omitted, the value SHOULD be interpreted as version 0.
|
45
|
-
return this.proto.version ?? 0;
|
46
|
-
}
|
47
|
-
get rateLimitProof() {
|
48
|
-
return this.proto.rateLimitProof;
|
49
|
-
}
|
50
|
-
}
|
51
|
-
class Encoder {
|
52
|
-
constructor(contentTopic, ephemeral = false, metaSetter) {
|
53
|
-
this.contentTopic = contentTopic;
|
54
|
-
this.ephemeral = ephemeral;
|
55
|
-
this.metaSetter = metaSetter;
|
56
|
-
}
|
57
|
-
async toWire(message$1) {
|
58
|
-
return WakuMessage.encode(await this.toProtoObj(message$1));
|
59
|
-
}
|
60
|
-
async toProtoObj(message) {
|
61
|
-
const timestamp = message.timestamp ?? new Date();
|
62
|
-
const protoMessage = {
|
63
|
-
payload: message.payload,
|
64
|
-
version: Version,
|
65
|
-
contentTopic: this.contentTopic,
|
66
|
-
timestamp: BigInt(timestamp.valueOf()) * OneMillion,
|
67
|
-
meta: undefined,
|
68
|
-
rateLimitProof: message.rateLimitProof,
|
69
|
-
ephemeral: this.ephemeral,
|
70
|
-
};
|
71
|
-
if (this.metaSetter) {
|
72
|
-
const meta = this.metaSetter(protoMessage);
|
73
|
-
return { ...protoMessage, meta };
|
74
|
-
}
|
75
|
-
return protoMessage;
|
76
|
-
}
|
77
|
-
}
|
78
|
-
/**
|
79
|
-
* Creates an encoder that encode messages without Waku level encryption or signature.
|
80
|
-
*
|
81
|
-
* An encoder is used to encode messages in the [`14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
82
|
-
* format to be sent over the Waku network. The resulting encoder can then be
|
83
|
-
* pass to { @link @waku/interfaces.LightPush.push } or
|
84
|
-
* { @link @waku/interfaces.Relay.send } to automatically encode outgoing
|
85
|
-
* messages.
|
86
|
-
*/
|
87
|
-
function createEncoder({ contentTopic, ephemeral, metaSetter, }) {
|
88
|
-
return new Encoder(contentTopic, ephemeral, metaSetter);
|
89
|
-
}
|
90
|
-
class Decoder {
|
91
|
-
constructor(contentTopic) {
|
92
|
-
this.contentTopic = contentTopic;
|
93
|
-
}
|
94
|
-
fromWireToProtoObj(bytes) {
|
95
|
-
const protoMessage = WakuMessage.decode(bytes);
|
96
|
-
log("Message decoded", protoMessage);
|
97
|
-
return Promise.resolve({
|
98
|
-
payload: protoMessage.payload,
|
99
|
-
contentTopic: protoMessage.contentTopic,
|
100
|
-
version: protoMessage.version ?? undefined,
|
101
|
-
timestamp: protoMessage.timestamp ?? undefined,
|
102
|
-
meta: protoMessage.meta ?? undefined,
|
103
|
-
rateLimitProof: protoMessage.rateLimitProof ?? undefined,
|
104
|
-
ephemeral: protoMessage.ephemeral ?? false,
|
105
|
-
});
|
106
|
-
}
|
107
|
-
async fromProtoObj(pubSubTopic, proto) {
|
108
|
-
// https://rfc.vac.dev/spec/14/
|
109
|
-
// > If omitted, the value SHOULD be interpreted as version 0.
|
110
|
-
if (proto.version ?? 0 !== Version) {
|
111
|
-
log("Failed to decode due to incorrect version, expected:", Version, ", actual:", proto.version);
|
112
|
-
return Promise.resolve(undefined);
|
113
|
-
}
|
114
|
-
return new DecodedMessage(pubSubTopic, proto);
|
115
|
-
}
|
116
|
-
}
|
117
|
-
/**
|
118
|
-
* Creates a decoder that decode messages without Waku level encryption.
|
119
|
-
*
|
120
|
-
* A decoder is used to decode messages from the [14/WAKU2-MESSAGE](https://rfc.vac.dev/spec/14/)
|
121
|
-
* format when received from the Waku network. The resulting decoder can then be
|
122
|
-
* pass to { @link @waku/interfaces.Filter.subscribe } or
|
123
|
-
* { @link @waku/interfaces.Relay.subscribe } to automatically decode incoming
|
124
|
-
* messages.
|
125
|
-
*
|
126
|
-
* @param contentTopic The resulting decoder will only decode messages with this content topic.
|
127
|
-
*/
|
128
|
-
function createDecoder(contentTopic) {
|
129
|
-
return new Decoder(contentTopic);
|
130
|
-
}
|
131
|
-
|
132
|
-
var version_0 = /*#__PURE__*/Object.freeze({
|
133
|
-
__proto__: null,
|
134
|
-
DecodedMessage: DecodedMessage,
|
135
|
-
Decoder: Decoder,
|
136
|
-
Encoder: Encoder,
|
137
|
-
Version: Version,
|
138
|
-
createDecoder: createDecoder,
|
139
|
-
createEncoder: createEncoder,
|
140
|
-
proto: message
|
141
|
-
});
|
142
|
-
|
143
|
-
export { DecodedMessage as D, Encoder as E, Version as V, createDecoder as a, Decoder as b, createEncoder as c, version_0 as v };
|
package/dist/lib/group_by.d.ts
DELETED
package/dist/lib/group_by.js
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
export function groupByContentTopic(values) {
|
2
|
-
const groupedDecoders = new Map();
|
3
|
-
values.forEach((value) => {
|
4
|
-
let decs = groupedDecoders.get(value.contentTopic);
|
5
|
-
if (!decs) {
|
6
|
-
groupedDecoders.set(value.contentTopic, []);
|
7
|
-
decs = groupedDecoders.get(value.contentTopic);
|
8
|
-
}
|
9
|
-
decs.push(value);
|
10
|
-
});
|
11
|
-
return groupedDecoders;
|
12
|
-
}
|
13
|
-
//# sourceMappingURL=group_by.js.map
|
package/dist/lib/group_by.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"group_by.js","sourceRoot":"","sources":["../../src/lib/group_by.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,mBAAmB,CACjC,MAAoB;IAEpB,MAAM,eAAe,GAAG,IAAI,GAAG,EAAE,CAAC;IAClC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QACvB,IAAI,IAAI,GAAG,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI,EAAE;YACT,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;YAC5C,IAAI,GAAG,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;SAChD;QACD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnB,CAAC,CAAC,CAAC;IACH,OAAO,eAAe,CAAC;AACzB,CAAC"}
|
@@ -1,18 +0,0 @@
|
|
1
|
-
import type { IDecodedMessage, IDecoder, IProtoMessage } from "@waku/interfaces";
|
2
|
-
import { TopicOnlyMessage as ProtoTopicOnlyMessage } from "@waku/proto";
|
3
|
-
export declare class TopicOnlyMessage implements IDecodedMessage {
|
4
|
-
pubSubTopic: string;
|
5
|
-
private proto;
|
6
|
-
payload: Uint8Array;
|
7
|
-
rateLimitProof: undefined;
|
8
|
-
timestamp: undefined;
|
9
|
-
meta: undefined;
|
10
|
-
ephemeral: undefined;
|
11
|
-
constructor(pubSubTopic: string, proto: ProtoTopicOnlyMessage);
|
12
|
-
get contentTopic(): string;
|
13
|
-
}
|
14
|
-
export declare class TopicOnlyDecoder implements IDecoder<TopicOnlyMessage> {
|
15
|
-
contentTopic: string;
|
16
|
-
fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined>;
|
17
|
-
fromProtoObj(pubSubTopic: string, proto: IProtoMessage): Promise<TopicOnlyMessage | undefined>;
|
18
|
-
}
|
@@ -1,35 +0,0 @@
|
|
1
|
-
import { TopicOnlyMessage as ProtoTopicOnlyMessage } from "@waku/proto";
|
2
|
-
import debug from "debug";
|
3
|
-
const log = debug("waku:message:topic-only");
|
4
|
-
export class TopicOnlyMessage {
|
5
|
-
constructor(pubSubTopic, proto) {
|
6
|
-
this.pubSubTopic = pubSubTopic;
|
7
|
-
this.proto = proto;
|
8
|
-
this.payload = new Uint8Array();
|
9
|
-
}
|
10
|
-
get contentTopic() {
|
11
|
-
return this.proto.contentTopic;
|
12
|
-
}
|
13
|
-
}
|
14
|
-
export class TopicOnlyDecoder {
|
15
|
-
constructor() {
|
16
|
-
this.contentTopic = "";
|
17
|
-
}
|
18
|
-
fromWireToProtoObj(bytes) {
|
19
|
-
const protoMessage = ProtoTopicOnlyMessage.decode(bytes);
|
20
|
-
log("Message decoded", protoMessage);
|
21
|
-
return Promise.resolve({
|
22
|
-
contentTopic: protoMessage.contentTopic,
|
23
|
-
payload: new Uint8Array(),
|
24
|
-
rateLimitProof: undefined,
|
25
|
-
timestamp: undefined,
|
26
|
-
meta: undefined,
|
27
|
-
version: undefined,
|
28
|
-
ephemeral: undefined,
|
29
|
-
});
|
30
|
-
}
|
31
|
-
async fromProtoObj(pubSubTopic, proto) {
|
32
|
-
return new TopicOnlyMessage(pubSubTopic, proto);
|
33
|
-
}
|
34
|
-
}
|
35
|
-
//# sourceMappingURL=topic_only_message.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"topic_only_message.js","sourceRoot":"","sources":["../../../src/lib/message/topic_only_message.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,IAAI,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,GAAG,GAAG,KAAK,CAAC,yBAAyB,CAAC,CAAC;AAE7C,MAAM,OAAO,gBAAgB;IAO3B,YACS,WAAmB,EAClB,KAA4B;QAD7B,gBAAW,GAAX,WAAW,CAAQ;QAClB,UAAK,GAAL,KAAK,CAAuB;QAR/B,YAAO,GAAe,IAAI,UAAU,EAAE,CAAC;IAS3C,CAAC;IAEJ,IAAI,YAAY;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;IACjC,CAAC;CACF;AAED,MAAM,OAAO,gBAAgB;IAA7B;QACS,iBAAY,GAAG,EAAE,CAAC;IAsB3B,CAAC;IApBC,kBAAkB,CAAC,KAAiB;QAClC,MAAM,YAAY,GAAG,qBAAqB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACzD,GAAG,CAAC,iBAAiB,EAAE,YAAY,CAAC,CAAC;QACrC,OAAO,OAAO,CAAC,OAAO,CAAC;YACrB,YAAY,EAAE,YAAY,CAAC,YAAY;YACvC,OAAO,EAAE,IAAI,UAAU,EAAE;YACzB,cAAc,EAAE,SAAS;YACzB,SAAS,EAAE,SAAS;YACpB,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,SAAS;YAClB,SAAS,EAAE,SAAS;SACrB,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,YAAY,CAChB,WAAmB,EACnB,KAAoB;QAEpB,OAAO,IAAI,gBAAgB,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;CACF"}
|
@@ -1,63 +0,0 @@
|
|
1
|
-
export declare const second = 1000;
|
2
|
-
export declare const minute: number;
|
3
|
-
/**
|
4
|
-
* RelayCodec is the libp2p identifier for the waku relay protocol
|
5
|
-
*/
|
6
|
-
export declare const RelayCodecs: string[];
|
7
|
-
export declare const RelayPingContentTopic = "/relay-ping/1/ping/null";
|
8
|
-
/**
|
9
|
-
* RelayGossipFactor affects how many peers we will emit gossip to at each heartbeat.
|
10
|
-
* We will send gossip to RelayGossipFactor * (total number of non-mesh peers), or
|
11
|
-
* RelayDlazy, whichever is greater.
|
12
|
-
*/
|
13
|
-
export declare const RelayGossipFactor = 0.25;
|
14
|
-
/**
|
15
|
-
* GossipsubHeartbeatInitialDelay is the short delay before the heartbeat timer begins
|
16
|
-
* after the router is initialized.
|
17
|
-
*/
|
18
|
-
export declare const RelayHeartbeatInitialDelay = 100;
|
19
|
-
/**
|
20
|
-
* RelayHeartbeatInterval controls the time between heartbeats.
|
21
|
-
*/
|
22
|
-
export declare const RelayHeartbeatInterval = 1000;
|
23
|
-
/**
|
24
|
-
* RelayPrunePeers controls the number of peers to include in prune Peer eXchange.
|
25
|
-
* When we prune a peer that's eligible for PX (has a good score, etc), we will try to
|
26
|
-
* send them signed peer records for up to RelayPrunePeers other peers that we
|
27
|
-
* know of.
|
28
|
-
*/
|
29
|
-
export declare const RelayPrunePeers = 16;
|
30
|
-
/**
|
31
|
-
* RelayPruneBackoff controls the backoff time for pruned peers. This is how long
|
32
|
-
* a peer must wait before attempting to graft into our mesh again after being pruned.
|
33
|
-
* When pruning a peer, we send them our value of RelayPruneBackoff so they know
|
34
|
-
* the minimum time to wait. Peers running older versions may not send a backoff time,
|
35
|
-
* so if we receive a prune message without one, we will wait at least RelayPruneBackoff
|
36
|
-
* before attempting to re-graft.
|
37
|
-
*/
|
38
|
-
export declare const RelayPruneBackoff: number;
|
39
|
-
/**
|
40
|
-
* RelayFanoutTTL controls how long we keep track of the fanout state. If it's been
|
41
|
-
* RelayFanoutTTL since we've published to a topic that we're not subscribed to,
|
42
|
-
* we'll delete the fanout map for that topic.
|
43
|
-
*/
|
44
|
-
export declare const RelayFanoutTTL: number;
|
45
|
-
/**
|
46
|
-
* RelayOpportunisticGraftTicks is the number of heartbeat ticks for attempting to improve the mesh
|
47
|
-
* with opportunistic grafting. Every RelayOpportunisticGraftTicks we will attempt to select some
|
48
|
-
* high-scoring mesh peers to replace lower-scoring ones, if the median score of our mesh peers falls
|
49
|
-
* below a threshold
|
50
|
-
*/
|
51
|
-
export declare const RelayOpportunisticGraftTicks = 60;
|
52
|
-
/**
|
53
|
-
* RelayOpportunisticGraftPeers is the number of peers to opportunistically graft.
|
54
|
-
*/
|
55
|
-
export declare const RelayOpportunisticGraftPeers = 2;
|
56
|
-
/**
|
57
|
-
* RelayMaxIHaveLength is the maximum number of messages to include in an IHAVE message.
|
58
|
-
* Also controls the maximum number of IHAVE ids we will accept and request with IWANT from a
|
59
|
-
* peer within a heartbeat, to protect from IHAVE floods. You should adjust this value from the
|
60
|
-
* default if your system is pushing more than 5000 messages in GossipsubHistoryGossip heartbeats;
|
61
|
-
* with the defaults this is 1666 messages/s.
|
62
|
-
*/
|
63
|
-
export declare const RelayMaxIHaveLength = 5000;
|
@@ -1,64 +0,0 @@
|
|
1
|
-
export const second = 1000;
|
2
|
-
export const minute = 60 * second;
|
3
|
-
/**
|
4
|
-
* RelayCodec is the libp2p identifier for the waku relay protocol
|
5
|
-
*/
|
6
|
-
export const RelayCodecs = ["/vac/waku/relay/2.0.0"];
|
7
|
-
export const RelayPingContentTopic = "/relay-ping/1/ping/null";
|
8
|
-
/**
|
9
|
-
* RelayGossipFactor affects how many peers we will emit gossip to at each heartbeat.
|
10
|
-
* We will send gossip to RelayGossipFactor * (total number of non-mesh peers), or
|
11
|
-
* RelayDlazy, whichever is greater.
|
12
|
-
*/
|
13
|
-
export const RelayGossipFactor = 0.25;
|
14
|
-
/**
|
15
|
-
* GossipsubHeartbeatInitialDelay is the short delay before the heartbeat timer begins
|
16
|
-
* after the router is initialized.
|
17
|
-
*/
|
18
|
-
export const RelayHeartbeatInitialDelay = 100;
|
19
|
-
/**
|
20
|
-
* RelayHeartbeatInterval controls the time between heartbeats.
|
21
|
-
*/
|
22
|
-
export const RelayHeartbeatInterval = second;
|
23
|
-
/**
|
24
|
-
* RelayPrunePeers controls the number of peers to include in prune Peer eXchange.
|
25
|
-
* When we prune a peer that's eligible for PX (has a good score, etc), we will try to
|
26
|
-
* send them signed peer records for up to RelayPrunePeers other peers that we
|
27
|
-
* know of.
|
28
|
-
*/
|
29
|
-
export const RelayPrunePeers = 16;
|
30
|
-
/**
|
31
|
-
* RelayPruneBackoff controls the backoff time for pruned peers. This is how long
|
32
|
-
* a peer must wait before attempting to graft into our mesh again after being pruned.
|
33
|
-
* When pruning a peer, we send them our value of RelayPruneBackoff so they know
|
34
|
-
* the minimum time to wait. Peers running older versions may not send a backoff time,
|
35
|
-
* so if we receive a prune message without one, we will wait at least RelayPruneBackoff
|
36
|
-
* before attempting to re-graft.
|
37
|
-
*/
|
38
|
-
export const RelayPruneBackoff = minute;
|
39
|
-
/**
|
40
|
-
* RelayFanoutTTL controls how long we keep track of the fanout state. If it's been
|
41
|
-
* RelayFanoutTTL since we've published to a topic that we're not subscribed to,
|
42
|
-
* we'll delete the fanout map for that topic.
|
43
|
-
*/
|
44
|
-
export const RelayFanoutTTL = minute;
|
45
|
-
/**
|
46
|
-
* RelayOpportunisticGraftTicks is the number of heartbeat ticks for attempting to improve the mesh
|
47
|
-
* with opportunistic grafting. Every RelayOpportunisticGraftTicks we will attempt to select some
|
48
|
-
* high-scoring mesh peers to replace lower-scoring ones, if the median score of our mesh peers falls
|
49
|
-
* below a threshold
|
50
|
-
*/
|
51
|
-
export const RelayOpportunisticGraftTicks = 60;
|
52
|
-
/**
|
53
|
-
* RelayOpportunisticGraftPeers is the number of peers to opportunistically graft.
|
54
|
-
*/
|
55
|
-
export const RelayOpportunisticGraftPeers = 2;
|
56
|
-
/**
|
57
|
-
* RelayMaxIHaveLength is the maximum number of messages to include in an IHAVE message.
|
58
|
-
* Also controls the maximum number of IHAVE ids we will accept and request with IWANT from a
|
59
|
-
* peer within a heartbeat, to protect from IHAVE floods. You should adjust this value from the
|
60
|
-
* default if your system is pushing more than 5000 messages in GossipsubHistoryGossip heartbeats;
|
61
|
-
* with the defaults this is 1666 messages/s.
|
62
|
-
*/
|
63
|
-
export const RelayMaxIHaveLength = 5000;
|
64
|
-
//# sourceMappingURL=constants.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/lib/relay/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC;AAC3B,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,CAAC;AAElC;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,uBAAuB,CAAC,CAAC;AAErD,MAAM,CAAC,MAAM,qBAAqB,GAAG,yBAAyB,CAAC;AAE/D;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAC;AAEtC;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAE9C;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAElC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAExC;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,EAAE,CAAC;AAE/C;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC"}
|
@@ -1,11 +0,0 @@
|
|
1
|
-
import { GossipSub, GossipSubComponents, GossipsubOpts } from "@chainsafe/libp2p-gossipsub";
|
2
|
-
import type { Libp2p } from "@libp2p/interface-libp2p";
|
3
|
-
import type { Callback, IDecodedMessage, IDecoder, IRelay, ProtocolCreateOptions } from "@waku/interfaces";
|
4
|
-
export type Observer<T extends IDecodedMessage> = {
|
5
|
-
decoder: IDecoder<T>;
|
6
|
-
callback: Callback<T>;
|
7
|
-
};
|
8
|
-
export type RelayCreateOptions = ProtocolCreateOptions & GossipsubOpts;
|
9
|
-
export type ContentTopic = string;
|
10
|
-
export declare function wakuRelay(init?: Partial<ProtocolCreateOptions>): (libp2p: Libp2p) => IRelay;
|
11
|
-
export declare function wakuGossipSub(init?: Partial<RelayCreateOptions>): (components: GossipSubComponents) => GossipSub;
|