@waku/core 0.0.24 → 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.
Files changed (37) hide show
  1. package/bundle/{base_protocol-2a0c882e.js → base_protocol-4bcf7514.js} +19 -11
  2. package/bundle/index-27b91e3b.js +31 -0
  3. package/bundle/index.js +199 -167
  4. package/bundle/lib/base_protocol.js +2 -1
  5. package/bundle/lib/message/version_0.js +2 -1
  6. package/bundle/lib/predefined_bootstrap_nodes.js +2 -0
  7. package/bundle/{version_0-f4afd324.js → version_0-2f1176e3.js} +4 -4
  8. package/dist/.tsbuildinfo +1 -1
  9. package/dist/lib/connection_manager.d.ts +2 -1
  10. package/dist/lib/connection_manager.js +35 -27
  11. package/dist/lib/connection_manager.js.map +1 -1
  12. package/dist/lib/filter/index.js +28 -17
  13. package/dist/lib/filter/index.js.map +1 -1
  14. package/dist/lib/keep_alive_manager.js +8 -8
  15. package/dist/lib/keep_alive_manager.js.map +1 -1
  16. package/dist/lib/light_push/index.js +16 -12
  17. package/dist/lib/light_push/index.js.map +1 -1
  18. package/dist/lib/message/version_0.js +3 -4
  19. package/dist/lib/message/version_0.js.map +1 -1
  20. package/dist/lib/store/index.js +7 -8
  21. package/dist/lib/store/index.js.map +1 -1
  22. package/dist/lib/stream_manager.js +4 -4
  23. package/dist/lib/stream_manager.js.map +1 -1
  24. package/dist/lib/wait_for_remote_peer.js +3 -4
  25. package/dist/lib/wait_for_remote_peer.js.map +1 -1
  26. package/dist/lib/waku.js +8 -8
  27. package/dist/lib/waku.js.map +1 -1
  28. package/package.json +1 -127
  29. package/src/lib/connection_manager.ts +46 -28
  30. package/src/lib/filter/index.ts +40 -17
  31. package/src/lib/keep_alive_manager.ts +8 -8
  32. package/src/lib/light_push/index.ts +23 -12
  33. package/src/lib/message/version_0.ts +3 -4
  34. package/src/lib/store/index.ts +7 -9
  35. package/src/lib/stream_manager.ts +7 -5
  36. package/src/lib/wait_for_remote_peer.ts +3 -4
  37. package/src/lib/waku.ts +8 -8
@@ -22,7 +22,7 @@ import {
22
22
  groupByContentTopic,
23
23
  toAsyncIterator
24
24
  } from "@waku/utils";
25
- import debug from "debug";
25
+ import { Logger } from "@waku/utils";
26
26
  import all from "it-all";
27
27
  import * as lp from "it-length-prefixed";
28
28
  import { pipe } from "it-pipe";
@@ -36,7 +36,7 @@ import {
36
36
  FilterSubscribeRpc
37
37
  } from "./filter_rpc.js";
38
38
 
39
- const log = debug("waku:filter:v2");
39
+ const log = new Logger("filter:v2");
40
40
 
41
41
  type SubscriptionCallback<T extends IDecodedMessage> = {
42
42
  decoders: IDecoder<T>[];
@@ -74,6 +74,16 @@ class Subscription {
74
74
  callback: Callback<T>
75
75
  ): Promise<void> {
76
76
  const decodersArray = Array.isArray(decoders) ? decoders : [decoders];
77
+
78
+ // check that all decoders are configured for the same pubsub topic as this subscription
79
+ decodersArray.forEach((decoder) => {
80
+ if (decoder.pubsubTopic !== this.pubsubTopic) {
81
+ throw new Error(
82
+ `Pubsub topic not configured: decoder is configured for pubsub topic ${decoder.pubsubTopic} but this subscription is for pubsub topic ${this.pubsubTopic}. Please create a new Subscription for the different pubsub topic.`
83
+ );
84
+ }
85
+ });
86
+
77
87
  const decodersGroupedByCT = groupByContentTopic(decodersArray);
78
88
  const contentTopics = Array.from(decodersGroupedByCT.keys());
79
89
 
@@ -108,7 +118,7 @@ class Subscription {
108
118
  );
109
119
  }
110
120
 
111
- log(
121
+ log.info(
112
122
  "Subscribed to peer ",
113
123
  this.peer.id.toString(),
114
124
  "for content topics",
@@ -174,6 +184,12 @@ class Subscription {
174
184
  async (source) => await all(source)
175
185
  );
176
186
 
187
+ if (!res || !res.length) {
188
+ throw Error(
189
+ `No response received for request ${request.requestId}: ${res}`
190
+ );
191
+ }
192
+
177
193
  const { statusCode, requestId, statusDesc } =
178
194
  FilterSubscribeResponse.decode(res[0].slice());
179
195
 
@@ -183,9 +199,9 @@ class Subscription {
183
199
  );
184
200
  }
185
201
 
186
- log("Ping successful");
202
+ log.info("Ping successful");
187
203
  } catch (error) {
188
- log("Error pinging: ", error);
204
+ log.error("Error pinging: ", error);
189
205
  throw new Error("Error pinging: " + error);
190
206
  }
191
207
  }
@@ -206,6 +222,12 @@ class Subscription {
206
222
  async (source) => await all(source)
207
223
  );
208
224
 
225
+ if (!res || !res.length) {
226
+ throw Error(
227
+ `No response received for request ${request.requestId}: ${res}`
228
+ );
229
+ }
230
+
209
231
  const { statusCode, requestId, statusDesc } =
210
232
  FilterSubscribeResponse.decode(res[0].slice());
211
233
 
@@ -216,7 +238,7 @@ class Subscription {
216
238
  }
217
239
 
218
240
  this.subscriptionCallbacks.clear();
219
- log("Unsubscribed from all content topics");
241
+ log.info("Unsubscribed from all content topics");
220
242
  } catch (error) {
221
243
  throw new Error("Error unsubscribing from all content topics: " + error);
222
244
  }
@@ -226,7 +248,7 @@ class Subscription {
226
248
  const contentTopic = message.contentTopic;
227
249
  const subscriptionCallback = this.subscriptionCallbacks.get(contentTopic);
228
250
  if (!subscriptionCallback) {
229
- log("No subscription callback available for ", contentTopic);
251
+ log.error("No subscription callback available for ", contentTopic);
230
252
  return;
231
253
  }
232
254
  await pushMessage(subscriptionCallback, this.pubsubTopic, message);
@@ -260,7 +282,7 @@ class Filter extends BaseProtocol implements IReceiver {
260
282
  this.pubsubTopics = options?.pubsubTopics || [DefaultPubSubTopic];
261
283
 
262
284
  libp2p.handle(FilterCodecs.PUSH, this.onRequest.bind(this)).catch((e) => {
263
- log("Failed to register ", FilterCodecs.PUSH, e);
285
+ log.error("Failed to register ", FilterCodecs.PUSH, e);
264
286
  });
265
287
 
266
288
  this.activeSubscriptions = new Map();
@@ -332,7 +354,6 @@ class Filter extends BaseProtocol implements IReceiver {
332
354
  }
333
355
 
334
356
  private onRequest(streamData: IncomingStreamData): void {
335
- log("Receiving message push");
336
357
  try {
337
358
  pipe(streamData.stream, lp.decode, async (source) => {
338
359
  for await (const bytes of source) {
@@ -341,12 +362,12 @@ class Filter extends BaseProtocol implements IReceiver {
341
362
  const { pubsubTopic, wakuMessage } = response;
342
363
 
343
364
  if (!wakuMessage) {
344
- log("Received empty message");
365
+ log.error("Received empty message");
345
366
  return;
346
367
  }
347
368
 
348
369
  if (!pubsubTopic) {
349
- log("PubSub topic missing from push message");
370
+ log.error("PubSub topic missing from push message");
350
371
  return;
351
372
  }
352
373
 
@@ -357,7 +378,9 @@ class Filter extends BaseProtocol implements IReceiver {
357
378
  );
358
379
 
359
380
  if (!subscription) {
360
- log(`No subscription locally registered for topic ${pubsubTopic}`);
381
+ log.error(
382
+ `No subscription locally registered for topic ${pubsubTopic}`
383
+ );
361
384
  return;
362
385
  }
363
386
 
@@ -365,14 +388,14 @@ class Filter extends BaseProtocol implements IReceiver {
365
388
  }
366
389
  }).then(
367
390
  () => {
368
- log("Receiving pipe closed.");
391
+ log.info("Receiving pipe closed.");
369
392
  },
370
393
  (e) => {
371
- log("Error with receiving pipe", e);
394
+ log.error("Error with receiving pipe", e);
372
395
  }
373
396
  );
374
397
  } catch (e) {
375
- log("Error decoding message", e);
398
+ log.error("Error decoding message", e);
376
399
  }
377
400
  }
378
401
  }
@@ -392,7 +415,7 @@ async function pushMessage<T extends IDecodedMessage>(
392
415
 
393
416
  const { contentTopic } = message;
394
417
  if (!contentTopic) {
395
- log("Message has no content topic, skipping");
418
+ log.warn("Message has no content topic, skipping");
396
419
  return;
397
420
  }
398
421
 
@@ -407,6 +430,6 @@ async function pushMessage<T extends IDecodedMessage>(
407
430
 
408
431
  await callback(decodedMessage);
409
432
  } catch (e) {
410
- log("Error decoding message", e);
433
+ log.error("Error decoding message", e);
411
434
  }
412
435
  }
@@ -2,14 +2,14 @@ import type { PeerId } from "@libp2p/interface/peer-id";
2
2
  import type { PeerStore } from "@libp2p/interface/peer-store";
3
3
  import type { IRelay, PeerIdStr } from "@waku/interfaces";
4
4
  import type { KeepAliveOptions } from "@waku/interfaces";
5
+ import { Logger } from "@waku/utils";
5
6
  import { utf8ToBytes } from "@waku/utils/bytes";
6
- import debug from "debug";
7
7
  import type { PingService } from "libp2p/ping";
8
8
 
9
9
  import { createEncoder } from "./message/version_0.js";
10
10
 
11
11
  export const RelayPingContentTopic = "/relay-ping/1/ping/null";
12
- const log = debug("waku:keep-alive");
12
+ const log = new Logger("keep-alive");
13
13
 
14
14
  export class KeepAliveManager {
15
15
  private pingKeepAliveTimers: Map<string, ReturnType<typeof setInterval>>;
@@ -48,9 +48,9 @@ export class KeepAliveManager {
48
48
  // also update the peer store with the latency
49
49
  try {
50
50
  ping = await libp2pPing.ping(peerId);
51
- log(`Ping succeeded (${peerIdStr})`, ping);
51
+ log.info(`Ping succeeded (${peerIdStr})`, ping);
52
52
  } catch (error) {
53
- log(`Ping failed for peer (${peerIdStr}).
53
+ log.error(`Ping failed for peer (${peerIdStr}).
54
54
  Next ping will be attempted in ${pingPeriodSecs} seconds.
55
55
  `);
56
56
  return;
@@ -63,10 +63,10 @@ export class KeepAliveManager {
63
63
  }
64
64
  });
65
65
  } catch (e) {
66
- log("Failed to update ping", e);
66
+ log.error("Failed to update ping", e);
67
67
  }
68
68
  } catch (e) {
69
- log(`Ping failed (${peerIdStr})`, e);
69
+ log.error(`Ping failed (${peerIdStr})`, e);
70
70
  }
71
71
  })();
72
72
  }, pingPeriodSecs * 1000);
@@ -128,10 +128,10 @@ export class KeepAliveManager {
128
128
  ephemeral: true
129
129
  });
130
130
  const interval = setInterval(() => {
131
- log("Sending Waku Relay ping message");
131
+ log.info("Sending Waku Relay ping message");
132
132
  relay
133
133
  .send(encoder, { payload: new Uint8Array([1]) })
134
- .catch((e) => log("Failed to send relay ping", e));
134
+ .catch((e) => log.error("Failed to send relay ping", e));
135
135
  }, relayPeriodSecs * 1000);
136
136
  intervals.push(interval);
137
137
  }
@@ -11,8 +11,11 @@ import {
11
11
  SendResult
12
12
  } from "@waku/interfaces";
13
13
  import { PushResponse } from "@waku/proto";
14
- import { ensurePubsubTopicIsConfigured, isSizeValid } from "@waku/utils";
15
- import debug from "debug";
14
+ import {
15
+ ensurePubsubTopicIsConfigured,
16
+ isMessageSizeUnderCap
17
+ } from "@waku/utils";
18
+ import { Logger } from "@waku/utils";
16
19
  import all from "it-all";
17
20
  import * as lp from "it-length-prefixed";
18
21
  import { pipe } from "it-pipe";
@@ -23,7 +26,7 @@ import { DefaultPubSubTopic } from "../constants.js";
23
26
 
24
27
  import { PushRpc } from "./push_rpc.js";
25
28
 
26
- const log = debug("waku:light-push");
29
+ const log = new Logger("light-push");
27
30
 
28
31
  export const LightPushCodec = "/vac/waku/lightpush/2.0.0-beta1";
29
32
  export { PushResponse };
@@ -56,14 +59,19 @@ class LightPush extends BaseProtocol implements ILightPush {
56
59
  pubsubTopic: string
57
60
  ): Promise<PreparePushMessageResult> {
58
61
  try {
59
- if (!isSizeValid(message.payload)) {
60
- log("Failed to send waku light push: message is bigger than 1MB");
62
+ if (!message.payload || message.payload.length === 0) {
63
+ log.error("Failed to send waku light push: payload is empty");
64
+ return { query: null, error: SendError.EMPTY_PAYLOAD };
65
+ }
66
+
67
+ if (!(await isMessageSizeUnderCap(encoder, message))) {
68
+ log.error("Failed to send waku light push: message is bigger than 1MB");
61
69
  return { query: null, error: SendError.SIZE_TOO_BIG };
62
70
  }
63
71
 
64
72
  const protoMessage = await encoder.toProtoObj(message);
65
73
  if (!protoMessage) {
66
- log("Failed to encode to protoMessage, aborting push");
74
+ log.error("Failed to encode to protoMessage, aborting push");
67
75
  return {
68
76
  query: null,
69
77
  error: SendError.ENCODE_FAILED
@@ -73,7 +81,7 @@ class LightPush extends BaseProtocol implements ILightPush {
73
81
  const query = PushRpc.createRequest(protoMessage, pubsubTopic);
74
82
  return { query, error: null };
75
83
  } catch (error) {
76
- log("Failed to prepare push message", error);
84
+ log.error("Failed to prepare push message", error);
77
85
 
78
86
  return {
79
87
  query: null,
@@ -119,7 +127,10 @@ class LightPush extends BaseProtocol implements ILightPush {
119
127
  try {
120
128
  stream = await this.getStream(peer);
121
129
  } catch (err) {
122
- log(`Failed to get a stream for remote peer${peer.id.toString()}`, err);
130
+ log.error(
131
+ `Failed to get a stream for remote peer${peer.id.toString()}`,
132
+ err
133
+ );
123
134
  return { recipients, error: SendError.REMOTE_PEER_FAULT };
124
135
  }
125
136
 
@@ -133,7 +144,7 @@ class LightPush extends BaseProtocol implements ILightPush {
133
144
  async (source) => await all(source)
134
145
  );
135
146
  } catch (err) {
136
- log("Failed to send waku light push request", err);
147
+ log.error("Failed to send waku light push request", err);
137
148
  return { recipients, error: SendError.GENERIC_FAIL };
138
149
  }
139
150
 
@@ -146,17 +157,17 @@ class LightPush extends BaseProtocol implements ILightPush {
146
157
  try {
147
158
  response = PushRpc.decode(bytes).response;
148
159
  } catch (err) {
149
- log("Failed to decode push reply", err);
160
+ log.error("Failed to decode push reply", err);
150
161
  return { recipients, error: SendError.DECODE_FAILED };
151
162
  }
152
163
 
153
164
  if (!response) {
154
- log("Remote peer fault: No response in PushRPC");
165
+ log.error("Remote peer fault: No response in PushRPC");
155
166
  return { recipients, error: SendError.REMOTE_PEER_FAULT };
156
167
  }
157
168
 
158
169
  if (!response.isSuccess) {
159
- log("Remote peer rejected the message: ", response.info);
170
+ log.error("Remote peer rejected the message: ", response.info);
160
171
  return { recipients, error: SendError.REMOTE_PEER_REJECTED };
161
172
  }
162
173
 
@@ -10,11 +10,11 @@ import type {
10
10
  PubSubTopic
11
11
  } from "@waku/interfaces";
12
12
  import { proto_message as proto } from "@waku/proto";
13
- import debug from "debug";
13
+ import { Logger } from "@waku/utils";
14
14
 
15
15
  import { DefaultPubSubTopic } from "../constants.js";
16
16
 
17
- const log = debug("waku:message:version-0");
17
+ const log = new Logger("message:version-0");
18
18
  const OneMillion = BigInt(1_000_000);
19
19
 
20
20
  export const Version = 0;
@@ -139,7 +139,6 @@ export class Decoder implements IDecoder<DecodedMessage> {
139
139
 
140
140
  fromWireToProtoObj(bytes: Uint8Array): Promise<IProtoMessage | undefined> {
141
141
  const protoMessage = proto.WakuMessage.decode(bytes);
142
- log("Message decoded", protoMessage);
143
142
  return Promise.resolve({
144
143
  payload: protoMessage.payload,
145
144
  contentTopic: protoMessage.contentTopic,
@@ -158,7 +157,7 @@ export class Decoder implements IDecoder<DecodedMessage> {
158
157
  // https://rfc.vac.dev/spec/14/
159
158
  // > If omitted, the value SHOULD be interpreted as version 0.
160
159
  if (proto.version ?? 0 !== Version) {
161
- log(
160
+ log.error(
162
161
  "Failed to decode due to incorrect version, expected:",
163
162
  Version,
164
163
  ", actual:",
@@ -11,8 +11,8 @@ import {
11
11
  } from "@waku/interfaces";
12
12
  import { proto_store as proto } from "@waku/proto";
13
13
  import { ensurePubsubTopicIsConfigured, isDefined } from "@waku/utils";
14
+ import { Logger } from "@waku/utils";
14
15
  import { concat, utf8ToBytes } from "@waku/utils/bytes";
15
- import debug from "debug";
16
16
  import all from "it-all";
17
17
  import * as lp from "it-length-prefixed";
18
18
  import { pipe } from "it-pipe";
@@ -26,7 +26,7 @@ import { HistoryRpc, PageDirection, Params } from "./history_rpc.js";
26
26
 
27
27
  import HistoryError = proto.HistoryResponse.HistoryError;
28
28
 
29
- const log = debug("waku:store");
29
+ const log = new Logger("store");
30
30
 
31
31
  export const StoreCodec = "/vac/waku/store/2.0.0-beta4";
32
32
 
@@ -284,8 +284,6 @@ class Store extends BaseProtocol implements IStore {
284
284
  { contentTopics, startTime, endTime }
285
285
  );
286
286
 
287
- log("Querying history with the following options", options);
288
-
289
287
  const peer = (
290
288
  await this.getPeers({
291
289
  numPeers: this.NUM_PEERS_PROTOCOL,
@@ -325,7 +323,7 @@ async function* paginate<T extends IDecodedMessage>(
325
323
 
326
324
  const historyRpcQuery = HistoryRpc.createQuery(queryOpts);
327
325
 
328
- log(
326
+ log.info(
329
327
  "Querying store peer",
330
328
  `for (${queryOpts.pubsubTopic})`,
331
329
  queryOpts.contentTopics
@@ -349,7 +347,7 @@ async function* paginate<T extends IDecodedMessage>(
349
347
  const reply = historyRpcQuery.decode(bytes);
350
348
 
351
349
  if (!reply.response) {
352
- log("Stopping pagination due to store `response` field missing");
350
+ log.warn("Stopping pagination due to store `response` field missing");
353
351
  break;
354
352
  }
355
353
 
@@ -360,13 +358,13 @@ async function* paginate<T extends IDecodedMessage>(
360
358
  }
361
359
 
362
360
  if (!response.messages || !response.messages.length) {
363
- log(
361
+ log.warn(
364
362
  "Stopping pagination due to store `response.messages` field missing or empty"
365
363
  );
366
364
  break;
367
365
  }
368
366
 
369
- log(`${response.messages.length} messages retrieved from store`);
367
+ log.error(`${response.messages.length} messages retrieved from store`);
370
368
 
371
369
  yield response.messages.map((protoMsg) => {
372
370
  const contentTopic = protoMsg.contentTopic;
@@ -386,7 +384,7 @@ async function* paginate<T extends IDecodedMessage>(
386
384
  if (typeof nextCursor === "undefined") {
387
385
  // If the server does not return cursor then there is an issue,
388
386
  // Need to abort, or we end up in an infinite loop
389
- log(
387
+ log.warn(
390
388
  "Stopping pagination due to `response.pagingInfo.cursor` missing from store response"
391
389
  );
392
390
  break;
@@ -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
9
  private streamPool: Map<string, Promise<Stream | void>>;
10
- private readonly log: debug.Debugger;
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 = debug(`waku:stream-manager:${multicodec}`);
17
+ this.log = new Logger(`stream-manager:${multicodec}`);
18
18
  this.addEventListener(
19
19
  "peer:update",
20
20
  this.handlePeerUpdateStreamPool.bind(this)
@@ -57,7 +57,9 @@ export class StreamManager {
57
57
  private prepareNewStream(peer: Peer): void {
58
58
  const streamPromise = this.newStream(peer).catch(() => {
59
59
  // No error thrown as this call is not triggered by the user
60
- this.log(`Failed to prepare a new stream for ${peer.id.toString()}`);
60
+ this.log.error(
61
+ `Failed to prepare a new stream for ${peer.id.toString()}`
62
+ );
61
63
  });
62
64
  this.streamPool.set(peer.id.toString(), streamPromise);
63
65
  }
@@ -65,7 +67,7 @@ export class StreamManager {
65
67
  private handlePeerUpdateStreamPool = (evt: CustomEvent<PeerUpdate>): void => {
66
68
  const peer = evt.detail.peer;
67
69
  if (peer.protocols.includes(this.multicodec)) {
68
- this.log(`Preemptively opening a stream to ${peer.id.toString()}`);
70
+ this.log.info(`Preemptively opening a stream to ${peer.id.toString()}`);
69
71
  this.prepareNewStream(peer);
70
72
  }
71
73
  };
@@ -1,10 +1,10 @@
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 debug from "debug";
4
+ import { Logger } from "@waku/utils";
5
5
  import { pEvent } from "p-event";
6
6
 
7
- const log = debug("waku:wait-for-remote-peer");
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.
@@ -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
  }
package/src/lib/waku.ts CHANGED
@@ -11,7 +11,7 @@ import type {
11
11
  Waku
12
12
  } from "@waku/interfaces";
13
13
  import { Protocols } from "@waku/interfaces";
14
- import debug from "debug";
14
+ import { Logger } from "@waku/utils";
15
15
 
16
16
  import { ConnectionManager } from "./connection_manager.js";
17
17
 
@@ -19,7 +19,7 @@ export const DefaultPingKeepAliveValueSecs = 5 * 60;
19
19
  export const DefaultRelayKeepAliveValueSecs = 5 * 60;
20
20
  export const DefaultUserAgent = "js-waku";
21
21
 
22
- const log = debug("waku:waku");
22
+ const log = new Logger("waku");
23
23
 
24
24
  export interface WakuOptions {
25
25
  /**
@@ -92,7 +92,7 @@ export class WakuNode implements Waku {
92
92
  this.relay
93
93
  );
94
94
 
95
- log(
95
+ log.info(
96
96
  "Waku node created",
97
97
  peerId,
98
98
  `relay: ${!!this.relay}, store: ${!!this.store}, light push: ${!!this
@@ -127,7 +127,7 @@ export class WakuNode implements Waku {
127
127
  codecs.push(codec)
128
128
  );
129
129
  } else {
130
- log(
130
+ log.error(
131
131
  "Relay codec not included in dial codec: protocol not mounted locally"
132
132
  );
133
133
  }
@@ -136,7 +136,7 @@ export class WakuNode implements Waku {
136
136
  if (this.store) {
137
137
  codecs.push(this.store.multicodec);
138
138
  } else {
139
- log(
139
+ log.error(
140
140
  "Store codec not included in dial codec: protocol not mounted locally"
141
141
  );
142
142
  }
@@ -145,7 +145,7 @@ export class WakuNode implements Waku {
145
145
  if (this.lightPush) {
146
146
  codecs.push(this.lightPush.multicodec);
147
147
  } else {
148
- log(
148
+ log.error(
149
149
  "Light Push codec not included in dial codec: protocol not mounted locally"
150
150
  );
151
151
  }
@@ -154,13 +154,13 @@ export class WakuNode implements Waku {
154
154
  if (this.filter) {
155
155
  codecs.push(this.filter.multicodec);
156
156
  } else {
157
- log(
157
+ log.error(
158
158
  "Filter codec not included in dial codec: protocol not mounted locally"
159
159
  );
160
160
  }
161
161
  }
162
162
 
163
- log(`Dialing to ${peerId.toString()} with protocols ${_protocols}`);
163
+ log.info(`Dialing to ${peerId.toString()} with protocols ${_protocols}`);
164
164
 
165
165
  return this.libp2p.dialProtocol(peerId, codecs);
166
166
  }