From bf1ff25a4727f16964ddf9717fbc9d2a87a991f6 Mon Sep 17 00:00:00 2001 From: Lorenzo Delgado Date: Wed, 19 Apr 2023 14:27:16 +0200 Subject: [PATCH] chore: add deprecation notice to utils module. move heartbeat to common --- .../heartbeat.nim => common/nimchronos.nim} | 21 ++++++++++++------- waku/common/utils/DEPRECATION_NOTICE.md | 6 ++++++ waku/v2/node/peer_manager/peer_manager.nim | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) rename waku/{v2/utils/heartbeat.nim => common/nimchronos.nim} (67%) create mode 100644 waku/common/utils/DEPRECATION_NOTICE.md diff --git a/waku/v2/utils/heartbeat.nim b/waku/common/nimchronos.nim similarity index 67% rename from waku/v2/utils/heartbeat.nim rename to waku/common/nimchronos.nim index d2af553d9..da9c4a5df 100644 --- a/waku/v2/utils/heartbeat.nim +++ b/waku/common/nimchronos.nim @@ -1,13 +1,19 @@ +## An extension wrapper around nim-chronos when (NimMajor, NimMinor) < (1, 4): {.push raises: [Defect].} else: {.push raises: [].} -import sequtils -import chronos, chronicles +import + chronos, + chronicles + +export chronos + + +## Extension methods # Taken from: https://github.com/status-im/nim-libp2p/blob/master/libp2p/utils/heartbeat.nim - template heartbeat*(name: string, interval: Duration, body: untyped): untyped = var nextHeartbeat = Moment.now() while true: @@ -19,11 +25,12 @@ template heartbeat*(name: string, interval: Duration, body: untyped): untyped = let delay = now - nextHeartbeat itv = interval + if delay > itv: - info "Missed multiple heartbeats", heartbeat = name, - delay = delay, hinterval = itv + info "Missed multiple heartbeats", heartbeat = name, delay = delay, hinterval = itv else: - debug "Missed heartbeat", heartbeat = name, - delay = delay, hinterval = itv + debug "Missed heartbeat", heartbeat = name, delay = delay, hinterval = itv + nextHeartbeat = now + itv + await sleepAsync(nextHeartbeat - now) diff --git a/waku/common/utils/DEPRECATION_NOTICE.md b/waku/common/utils/DEPRECATION_NOTICE.md new file mode 100644 index 000000000..391ec92e6 --- /dev/null +++ b/waku/common/utils/DEPRECATION_NOTICE.md @@ -0,0 +1,6 @@ +# :warning: DEPRECATION NOTICE :warning: + +The `utils` module has been marked as deprecated. +This package submodules are planned to be moved to different modules. + +**No new sub-modules must be added to this folder.** diff --git a/waku/v2/node/peer_manager/peer_manager.nim b/waku/v2/node/peer_manager/peer_manager.nim index 2e48ff27f..d5312d056 100644 --- a/waku/v2/node/peer_manager/peer_manager.nim +++ b/waku/v2/node/peer_manager/peer_manager.nim @@ -12,9 +12,9 @@ import libp2p/multistream, libp2p/muxers/muxer import + ../../../common/nimchronos, ../../waku_relay, ../../utils/peers, - ../../utils/heartbeat, ./peer_store/peer_storage, ./waku_peer_store