switch to deque
This commit is contained in:
parent
20ea5b5a40
commit
129e54a70b
|
@ -12,7 +12,7 @@ when (NimMajor, NimMinor) < (1, 4):
|
|||
else:
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[tables, sequtils, sets, algorithm]
|
||||
import std/[tables, sequtils, sets, algorithm, deques]
|
||||
import chronos, chronicles, metrics
|
||||
import "."/[types, scoring]
|
||||
import ".."/[pubsubpeer, peertable, timedcache, mcache, floodsub, pubsub]
|
||||
|
@ -625,10 +625,9 @@ proc onHeartbeat(g: GossipSub) {.raises: [Defect].} =
|
|||
# reset IHAVE cap
|
||||
block:
|
||||
for peer in g.peers.values:
|
||||
if peer.sentIHaves.len >= g.parameters.historyLength:
|
||||
peer.sentIHaves = default(HashSet[MessageId]) & peer.sentIHaves[0..^2]
|
||||
else:
|
||||
peer.sentIHaves.insert(default(HashSet[MessageId]), 0)
|
||||
peer.sentIHaves.addFirst(default(HashSet[MessageId]))
|
||||
if peer.sentIHaves.len > g.parameters.historyLength:
|
||||
discard peer.sentIHaves.popLast()
|
||||
peer.iHaveBudget = IHavePeerBudget
|
||||
|
||||
var meshMetrics = MeshMetrics()
|
||||
|
|
|
@ -12,7 +12,7 @@ when (NimMajor, NimMinor) < (1, 4):
|
|||
else:
|
||||
{.push raises: [].}
|
||||
|
||||
import std/[sequtils, strutils, tables, hashes, options, sets]
|
||||
import std/[sequtils, strutils, tables, hashes, options, sets, deques]
|
||||
import stew/results
|
||||
import chronos, chronicles, nimcrypto/sha2, metrics
|
||||
import rpc/[messages, message, protobuf],
|
||||
|
@ -62,7 +62,7 @@ type
|
|||
observers*: ref seq[PubSubObserver] # ref as in smart_ptr
|
||||
|
||||
score*: float64
|
||||
sentIHaves*: seq[HashSet[MessageId]]
|
||||
sentIHaves*: Deque[HashSet[MessageId]]
|
||||
iHaveBudget*: int
|
||||
maxMessageSize: int
|
||||
appScore*: float64 # application specific score
|
||||
|
@ -301,12 +301,12 @@ proc new*(
|
|||
codec: string,
|
||||
maxMessageSize: int): T =
|
||||
|
||||
T(
|
||||
result = T(
|
||||
getConn: getConn,
|
||||
onEvent: onEvent,
|
||||
codec: codec,
|
||||
peerId: peerId,
|
||||
sentIHaves: newSeq[HashSet[MessageId]](1),
|
||||
connectedFut: newFuture[void](),
|
||||
maxMessageSize: maxMessageSize
|
||||
)
|
||||
result.sentIHaves.addFirst(default(HashSet[MessageId]))
|
||||
|
|
|
@ -2,7 +2,7 @@ include ../../libp2p/protocols/pubsub/gossipsub
|
|||
|
||||
{.used.}
|
||||
|
||||
import options
|
||||
import std/[options, deques]
|
||||
import stew/byteutils
|
||||
import ../../libp2p/builders
|
||||
import ../../libp2p/errors
|
||||
|
|
Loading…
Reference in New Issue