mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-11 23:51:07 +00:00
Improve relay selection to prioritize active reservations
Signed-off-by: varun-r-mallya <varunrmallya@gmail.com>
This commit is contained in:
@ -219,11 +219,25 @@ class CircuitV2Transport(ITransport):
|
|||||||
# Get a relay from the list of discovered relays
|
# Get a relay from the list of discovered relays
|
||||||
relays = self.discovery.get_relays()
|
relays = self.discovery.get_relays()
|
||||||
if relays:
|
if relays:
|
||||||
# TODO: Implement more sophisticated relay selection
|
# Prioritize relays with active reservations
|
||||||
# For now, just return the first available relay
|
relays_with_reservations = []
|
||||||
return relays[0]
|
other_relays = []
|
||||||
|
|
||||||
|
for relay_id in relays:
|
||||||
|
relay_info = self.discovery.get_relay_info(relay_id)
|
||||||
|
if relay_info and relay_info.has_reservation:
|
||||||
|
relays_with_reservations.append(relay_id)
|
||||||
|
else:
|
||||||
|
other_relays.append(relay_id)
|
||||||
|
|
||||||
|
# Return first available relay with reservation, or fallback to others
|
||||||
|
if relays_with_reservations:
|
||||||
|
return relays_with_reservations[
|
||||||
|
attempts % len(relays_with_reservations)
|
||||||
|
]
|
||||||
|
elif other_relays:
|
||||||
|
return other_relays[attempts % len(other_relays)]
|
||||||
|
|
||||||
# Wait and try discovery
|
|
||||||
await trio.sleep(1)
|
await trio.sleep(1)
|
||||||
attempts += 1
|
attempts += 1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user