-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(networking): get relay number of connections from protocol conn…
…s/streams (#1609)
- Loading branch information
1 parent
b2dcb07
commit 73cbafa
Showing
5 changed files
with
176 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
when (NimMajor, NimMinor) < (1, 4): | ||
{.push raises: [Defect].} | ||
else: | ||
{.push raises: [].} | ||
|
||
import std/sequtils | ||
|
||
proc flatten*[T](a: seq[seq[T]]): seq[T] = | ||
var aFlat = newSeq[T](0) | ||
for subseq in a: | ||
aFlat &= subseq | ||
return aFlat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
when (NimMajor, NimMinor) < (1, 4): | ||
{.push raises: [Defect].} | ||
else: | ||
{.push raises: [].} | ||
|
||
import sequtils | ||
import chronos, chronicles | ||
|
||
# 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: | ||
body | ||
|
||
nextHeartbeat += interval | ||
let now = Moment.now() | ||
if nextHeartbeat < now: | ||
let | ||
delay = now - nextHeartbeat | ||
itv = interval | ||
if delay > itv: | ||
info "Missed multiple heartbeats", heartbeat = name, | ||
delay = delay, hinterval = itv | ||
else: | ||
debug "Missed heartbeat", heartbeat = name, | ||
delay = delay, hinterval = itv | ||
nextHeartbeat = now + itv | ||
await sleepAsync(nextHeartbeat - now) |