Add gossipsub heartbeat_initial_delay

This commit is contained in:
NIC619 2019-12-02 16:55:16 +08:00
parent 0672f5ae6d
commit c2d88962c7
No known key found for this signature in database
GPG Key ID: 570C35F5C2D51B17
3 changed files with 6 additions and 1 deletions

View File

@ -43,6 +43,7 @@ class GossipSub(IPubsubRouter):
mcache: MessageCache mcache: MessageCache
heartbeat_initial_delay: float
heartbeat_interval: int heartbeat_interval: int
def __init__( def __init__(
@ -54,6 +55,7 @@ class GossipSub(IPubsubRouter):
time_to_live: int, time_to_live: int,
gossip_window: int = 3, gossip_window: int = 3,
gossip_history: int = 5, gossip_history: int = 5,
heartbeat_initial_delay: int = 0.1,
heartbeat_interval: int = 120, heartbeat_interval: int = 120,
) -> None: ) -> None:
self.protocols = list(protocols) self.protocols = list(protocols)
@ -84,6 +86,7 @@ class GossipSub(IPubsubRouter):
self.mcache = MessageCache(gossip_window, gossip_history) self.mcache = MessageCache(gossip_window, gossip_history)
# Create heartbeat timer # Create heartbeat timer
self.heartbeat_initial_delay = heartbeat_initial_delay
self.heartbeat_interval = heartbeat_interval self.heartbeat_interval = heartbeat_interval
# Interface functions # Interface functions
@ -294,7 +297,7 @@ class GossipSub(IPubsubRouter):
state changes in the preceding heartbeat state changes in the preceding heartbeat
""" """
# Start after a delay. Ref: https://github.com/libp2p/go-libp2p-pubsub/blob/01b9825fbee1848751d90a8469e3f5f43bac8466/gossipsub.go#L410 # Noqa: E501 # Start after a delay. Ref: https://github.com/libp2p/go-libp2p-pubsub/blob/01b9825fbee1848751d90a8469e3f5f43bac8466/gossipsub.go#L410 # Noqa: E501
await asyncio.sleep(0.1) await asyncio.sleep(self.heartbeat_initial_delay)
while True: while True:
await self.mesh_heartbeat() await self.mesh_heartbeat()

View File

@ -24,6 +24,7 @@ class GossipsubParams(NamedTuple):
time_to_live: int = 30 time_to_live: int = 30
gossip_window: int = 3 gossip_window: int = 3
gossip_history: int = 5 gossip_history: int = 5
heartbeat_initial_delay: int = 0.1
heartbeat_interval: float = 0.5 heartbeat_interval: float = 0.5

View File

@ -142,6 +142,7 @@ class GossipsubFactory(factory.Factory):
time_to_live = GOSSIPSUB_PARAMS.time_to_live time_to_live = GOSSIPSUB_PARAMS.time_to_live
gossip_window = GOSSIPSUB_PARAMS.gossip_window gossip_window = GOSSIPSUB_PARAMS.gossip_window
gossip_history = GOSSIPSUB_PARAMS.gossip_history gossip_history = GOSSIPSUB_PARAMS.gossip_history
heartbeat_initial_delay = GOSSIPSUB_PARAMS.heartbeat_initial_delay
heartbeat_interval = GOSSIPSUB_PARAMS.heartbeat_interval heartbeat_interval = GOSSIPSUB_PARAMS.heartbeat_interval