Skip to content

Commit

Permalink
Query random key to collect more DHT neighbors
Browse files Browse the repository at this point in the history
  • Loading branch information
borzunov committed Jan 12, 2023
1 parent 17dcbbb commit b58c900
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/petals/server/reachability.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import time
from contextlib import asynccontextmanager
from functools import partial
from secrets import token_hex
from typing import Optional

import requests
Expand Down Expand Up @@ -51,11 +52,14 @@ def validate_reachability(peer_id, wait_time: float = 7 * 60, retry_delay: float
)


def check_direct_reachability(max_peers: int = 5, threshold: float = 0.5, **kwargs) -> Optional[bool]:
def check_direct_reachability(max_peers: int = 7, threshold: float = 0.5, **kwargs) -> Optional[bool]:
"""test if your peer is accessible by others in the swarm with the specified network options in **kwargs"""

async def _check_direct_reachability():
target_dht = await DHTNode.create(client_mode=True, **kwargs)
target_dht.get(f"fake_{token_hex(16)}", latest=True) # Query random key to collect more DHT neighbors
logger.debug(f"DHT neighbor count: {len(target_dht.protocol.routing_table.peer_id_to_uid)}")

try:
protocol = ReachabilityProtocol(target_dht.protocol.p2p)
async with protocol.serve():
Expand Down

0 comments on commit b58c900

Please sign in to comment.