Fix: move heartbeat delay to heartbeat

This commit is contained in:
NIC619 2019-12-02 16:38:48 +08:00
parent 50fd0acf41
commit 0672f5ae6d
No known key found for this signature in database
GPG Key ID: 570C35F5C2D51B17

View File

@ -106,8 +106,6 @@ class GossipSub(IPubsubRouter):
logger.debug("attached to pusub")
# Start heartbeat now that we have a pubsub instance
# Start after a delay. Ref: https://github.com/libp2p/go-libp2p-pubsub/blob/01b9825fbee1848751d90a8469e3f5f43bac8466/gossipsub.go#L410 # Noqa: E501
await asyncio.sleep(0.1)
asyncio.ensure_future(self.heartbeat())
def add_peer(self, peer_id: ID, protocol_id: TProtocol) -> None:
@ -295,6 +293,8 @@ class GossipSub(IPubsubRouter):
Note: the heartbeats are called with awaits because each heartbeat depends on the
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
await asyncio.sleep(0.1)
while True:
await self.mesh_heartbeat()