mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-12 16:10:57 +00:00
smol fix , adds degree
This commit is contained in:
@ -24,16 +24,22 @@ def make_pubsub_msg(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: Implement sparse connect
|
|
||||||
async def dense_connect(hosts: Sequence[IHost]) -> None:
|
async def dense_connect(hosts: Sequence[IHost]) -> None:
|
||||||
await connect_some(hosts, 10)
|
await connect_some(hosts, 10)
|
||||||
|
|
||||||
|
|
||||||
# FIXME: `degree` is not used at all
|
|
||||||
async def connect_some(hosts: Sequence[IHost], degree: int) -> None:
|
async def connect_some(hosts: Sequence[IHost], degree: int) -> None:
|
||||||
|
"""
|
||||||
|
Connect each host to up to 'degree' number of other hosts.
|
||||||
|
Creates a sparse network topology where each node has limited connections.
|
||||||
|
"""
|
||||||
for i, host in enumerate(hosts):
|
for i, host in enumerate(hosts):
|
||||||
for host2 in hosts[i + 1 :]:
|
connections_made = 0
|
||||||
await connect(host, host2)
|
for j in range(i + 1, len(hosts)):
|
||||||
|
if connections_made >= degree:
|
||||||
|
break
|
||||||
|
await connect(host, hosts[j])
|
||||||
|
connections_made += 1
|
||||||
|
|
||||||
|
|
||||||
async def one_to_all_connect(hosts: Sequence[IHost], central_host_index: int) -> None:
|
async def one_to_all_connect(hosts: Sequence[IHost], central_host_index: int) -> None:
|
||||||
|
|||||||
Reference in New Issue
Block a user