mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
* added basic structure for direct peers * added direct connect heartbeat * added logic to reject GRAFT from direct peers * added invocation of direct_connect_heartbeat * updated _get_peers_to_send to include direct peers * fixed failing gossipsub core and demo tests * fixed failing test_examples.py * add tests for peer management * fix lint * update tests * fixed direct_peers type and peer_records test * fixed failing gossipsub direct peers test * added reject graft test * updated reconnection test * added newsfragment * improved reject graft test * updated default value for direct peers * renamed direct_connect_init_delay parameter * reverted back to direct_connect_initial_delay param name --------- Co-authored-by: Khwahish Patel <khwahish.p1@ahduni.edu.in>
46 lines
984 B
Python
46 lines
984 B
Python
from collections.abc import (
|
|
Sequence,
|
|
)
|
|
from typing import (
|
|
NamedTuple,
|
|
)
|
|
|
|
import multiaddr
|
|
|
|
from libp2p.peer.peerinfo import (
|
|
PeerInfo,
|
|
)
|
|
from libp2p.pubsub import (
|
|
floodsub,
|
|
gossipsub,
|
|
)
|
|
|
|
# Just a arbitrary large number.
|
|
# It is used when calling `MplexStream.read(MAX_READ_LEN)`,
|
|
# to avoid `MplexStream.read()`, which blocking reads until EOF.
|
|
MAX_READ_LEN = 65535
|
|
|
|
|
|
LISTEN_MADDR = multiaddr.Multiaddr("/ip4/127.0.0.1/tcp/0")
|
|
|
|
|
|
FLOODSUB_PROTOCOL_ID = floodsub.PROTOCOL_ID
|
|
GOSSIPSUB_PROTOCOL_ID = gossipsub.PROTOCOL_ID
|
|
|
|
|
|
class GossipsubParams(NamedTuple):
|
|
degree: int = 10
|
|
degree_low: int = 9
|
|
degree_high: int = 11
|
|
direct_peers: Sequence[PeerInfo] = None
|
|
time_to_live: int = 30
|
|
gossip_window: int = 3
|
|
gossip_history: int = 5
|
|
heartbeat_initial_delay: float = 0.1
|
|
heartbeat_interval: float = 0.5
|
|
direct_connect_initial_delay: float = 0.1
|
|
direct_connect_interval: int = 300
|
|
|
|
|
|
GOSSIPSUB_PARAMS = GossipsubParams()
|