mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
* refactored : host_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored : network_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored : notifee_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored : net_connection_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored: raw_connection_interface, secure_conn_interface and stream_muxer abc.py * refactored: addrbook_interface * refactored :peerdata_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :peermetadata_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :multiselect_client_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :multiselect_communicator_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :multiselect_muxer_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :interfaces Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :security_transport_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * refactored :listener_interface Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * moved all interfaces and typing files Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> * fixed documentation and moved pubsub abc.py Co-authored-by: Khwahish Patel <khwahish.p1@ahduni.edu.in> * added exclude-members in custom_types docs * added : newsfragment for moving all interfaces to libp2p.abc --------- Co-authored-by: mystical-prog <jdgt.vd.0405@gmail.com> Co-authored-by: Mystical <125946525+mystical-prog@users.noreply.github.com>
43 lines
1023 B
Python
43 lines
1023 B
Python
from collections.abc import (
|
|
Sequence,
|
|
)
|
|
|
|
from libp2p.abc import (
|
|
IHost,
|
|
)
|
|
from libp2p.peer.id import (
|
|
ID,
|
|
)
|
|
from libp2p.pubsub.pb import (
|
|
rpc_pb2,
|
|
)
|
|
from libp2p.tools.utils import (
|
|
connect,
|
|
)
|
|
|
|
|
|
def make_pubsub_msg(
|
|
origin_id: ID, topic_ids: Sequence[str], data: bytes, seqno: bytes
|
|
) -> rpc_pb2.Message:
|
|
return rpc_pb2.Message(
|
|
from_id=origin_id.to_bytes(), seqno=seqno, data=data, topicIDs=list(topic_ids)
|
|
)
|
|
|
|
|
|
# TODO: Implement sparse connect
|
|
async def dense_connect(hosts: Sequence[IHost]) -> None:
|
|
await connect_some(hosts, 10)
|
|
|
|
|
|
# FIXME: `degree` is not used at all
|
|
async def connect_some(hosts: Sequence[IHost], degree: int) -> None:
|
|
for i, host in enumerate(hosts):
|
|
for host2 in hosts[i + 1 :]:
|
|
await connect(host, host2)
|
|
|
|
|
|
async def one_to_all_connect(hosts: Sequence[IHost], central_host_index: int) -> None:
|
|
for i, host in enumerate(hosts):
|
|
if i != central_host_index:
|
|
await connect(hosts[central_host_index], host)
|