mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-08 22:20:53 +00:00
refactored and moved all interfaces to abc.py (#504)
* 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>
This commit is contained in:
152
README.md
152
README.md
@ -29,94 +29,94 @@ py-libp2p aims for conformity with [the standard libp2p modules](https://libp2p.
|
|||||||
|
|
||||||
> Legend: ✅: Done 🛠️: In Progress 🚫: Missing ❌: Not planned
|
> Legend: ✅: Done 🛠️: In Progress 🚫: Missing ❌: Not planned
|
||||||
|
|
||||||
| libp2p Node | Status |
|
| libp2p Node | Status |
|
||||||
| ------------ | :-----------: |
|
| ------------ | :----: |
|
||||||
| **`libp2p`** | ✅ |
|
| **`libp2p`** | ✅ |
|
||||||
|
|
||||||
| Core Protocols | Status |
|
| Core Protocols | Status |
|
||||||
| -------------- | :-----------: |
|
| -------------- | :----: |
|
||||||
| **`Ping`** | ✅ |
|
| **`Ping`** | ✅ |
|
||||||
| **`Identify`** | ✅ |
|
| **`Identify`** | ✅ |
|
||||||
|
|
||||||
| Transport Protocols | Status |
|
| Transport Protocols | Status |
|
||||||
| ------------------- | :-----------: |
|
| ------------------- | :----: |
|
||||||
| **`TCP`** | ✅|
|
| **`TCP`** | ✅ |
|
||||||
| **`QUIC`** | 🛠️ |
|
| **`QUIC`** | 🛠️ |
|
||||||
| **`UDP`** | 🚫 |
|
| **`UDP`** | 🚫 |
|
||||||
| **`WebSockets`** | ❌ |
|
| **`WebSockets`** | ❌ |
|
||||||
| **`UTP`** | ❌ |
|
| **`UTP`** | ❌ |
|
||||||
| **`WebRTC`** | ❌ |
|
| **`WebRTC`** | ❌ |
|
||||||
| **`SCTP`** | ❌ |
|
| **`SCTP`** | ❌ |
|
||||||
| **`Tor`** | ❌ |
|
| **`Tor`** | ❌ |
|
||||||
| **`i2p`** | ❌ |
|
| **`i2p`** | ❌ |
|
||||||
| **`cjdns`** | ❌ |
|
| **`cjdns`** | ❌ |
|
||||||
| **`Bluetooth LE`** | ❌ |
|
| **`Bluetooth LE`** | ❌ |
|
||||||
| **`Audio TP`** | ❌ |
|
| **`Audio TP`** | ❌ |
|
||||||
| **`Zerotier`** | ❌ |
|
| **`Zerotier`** | ❌ |
|
||||||
|
|
||||||
| Stream Muxers | Status |
|
| Stream Muxers | Status |
|
||||||
| ---------------- | :-----------: |
|
| ---------------- | :----: |
|
||||||
| **`multiplex`** | ✅ |
|
| **`multiplex`** | ✅ |
|
||||||
| **`yamux`** | 🚫 |
|
| **`yamux`** | 🚫 |
|
||||||
| **`benchmarks`** | ❌ |
|
| **`benchmarks`** | ❌ |
|
||||||
| **`muxado`** | ❌ |
|
| **`muxado`** | ❌ |
|
||||||
| **`spdystream`** | ❌ |
|
| **`spdystream`** | ❌ |
|
||||||
| **`spdy`** | ❌ |
|
| **`spdy`** | ❌ |
|
||||||
| **`http2`** | ❌ |
|
| **`http2`** | ❌ |
|
||||||
| **`QUIC`** | ❌ |
|
| **`QUIC`** | ❌ |
|
||||||
|
|
||||||
| Protocol Muxers | Status |
|
| Protocol Muxers | Status |
|
||||||
| ----------------- | :-----------: |
|
| ----------------- | :----: |
|
||||||
| **`multiselect`** | ✅ |
|
| **`multiselect`** | ✅ |
|
||||||
|
|
||||||
| Switch (Swarm) | Status |
|
| Switch (Swarm) | Status |
|
||||||
| ------------------ | :-----------: |
|
| ------------------ | :----: |
|
||||||
| **`Switch`** | ✅ |
|
| **`Switch`** | ✅ |
|
||||||
| **`Dialer stack`** | ✅ |
|
| **`Dialer stack`** | ✅ |
|
||||||
|
|
||||||
| Peer Discovery | Status |
|
| Peer Discovery | Status |
|
||||||
| -------------------- | :--------: |
|
| -------------------- | :----: |
|
||||||
| **`bootstrap list`** | 🚫 |
|
| **`bootstrap list`** | 🚫 |
|
||||||
| **`Kademlia DHT`** | ❌ |
|
| **`Kademlia DHT`** | ❌ |
|
||||||
| **`mDNS`** | ❌ |
|
| **`mDNS`** | ❌ |
|
||||||
| **`PEX`** | ❌ |
|
| **`PEX`** | ❌ |
|
||||||
| **`DNS`** | ❌ |
|
| **`DNS`** | ❌ |
|
||||||
|
|
||||||
| Content Routing | Status |
|
| Content Routing | Status |
|
||||||
| ------------------ | :-----------: |
|
| ------------------ | :----: |
|
||||||
| **`Kademlia DHT`** | ❌ |
|
| **`Kademlia DHT`** | ❌ |
|
||||||
| **`floodsub`** | ✅ |
|
| **`floodsub`** | ✅ |
|
||||||
| **`gossipsub`** | ✅ |
|
| **`gossipsub`** | ✅ |
|
||||||
| **`PHT`** | ❌ |
|
| **`PHT`** | ❌ |
|
||||||
|
|
||||||
| Peer Routing | Status |
|
| Peer Routing | Status |
|
||||||
| ------------------ | :-----------: |
|
| ------------------ | :----: |
|
||||||
| **`Kademlia DHT`** | ❌ |
|
| **`Kademlia DHT`** | ❌ |
|
||||||
| **`floodsub`** | ✅|
|
| **`floodsub`** | ✅ |
|
||||||
| **`gossipsub`** | ✅ |
|
| **`gossipsub`** | ✅ |
|
||||||
| **`PHT`** | ❌ |
|
| **`PHT`** | ❌ |
|
||||||
|
|
||||||
| NAT Traversal | Status |
|
| NAT Traversal | Status |
|
||||||
| ------------------------ | :--------: |
|
| ------------------------ | :----: |
|
||||||
| **`nat-pmp`** | ❌ |
|
| **`nat-pmp`** | ❌ |
|
||||||
| **`upnp`** | ❌ |
|
| **`upnp`** | ❌ |
|
||||||
| **`ext addr discovery`** | ❌ |
|
| **`ext addr discovery`** | ❌ |
|
||||||
| **`STUN-like`** | ❌ |
|
| **`STUN-like`** | ❌ |
|
||||||
| **`line-switch relay`** | ❌ |
|
| **`line-switch relay`** | ❌ |
|
||||||
| **`pkt-switch relay`** | ❌ |
|
| **`pkt-switch relay`** | ❌ |
|
||||||
|
|
||||||
| Exchange | Status |
|
| Exchange | Status |
|
||||||
| ---------------- | :--------: |
|
| ---------------- | :----: |
|
||||||
| **`HTTP`** | ❌ |
|
| **`HTTP`** | ❌ |
|
||||||
| **`Bitswap`** | ❌ |
|
| **`Bitswap`** | ❌ |
|
||||||
| **`Bittorrent`** | ❌ |
|
| **`Bittorrent`** | ❌ |
|
||||||
|
|
||||||
| Consensus | Status |
|
| Consensus | Status |
|
||||||
| -------------- | :--------: |
|
| -------------- | :----: |
|
||||||
| **`Paxos`** | ❌ |
|
| **`Paxos`** | ❌ |
|
||||||
| **`Raft`** | ❌ |
|
| **`Raft`** | ❌ |
|
||||||
| **`PBTF`** | ❌ |
|
| **`PBTF`** | ❌ |
|
||||||
| **`Nakamoto`** | ❌ |
|
| **`Nakamoto`** | ❌ |
|
||||||
|
|
||||||
## Explanation of Basic Two Node Communication
|
## Explanation of Basic Two Node Communication
|
||||||
|
|
||||||
|
|||||||
@ -28,14 +28,6 @@ libp2p.host.exceptions module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.host.host\_interface module
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.host.host_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.host.ping module
|
libp2p.host.ping module
|
||||||
-----------------------
|
-----------------------
|
||||||
|
|
||||||
|
|||||||
@ -12,14 +12,6 @@ libp2p.network.connection.exceptions module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.network.connection.net\_connection\_interface module
|
|
||||||
-----------------------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.network.connection.net_connection_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.network.connection.raw\_connection module
|
libp2p.network.connection.raw\_connection module
|
||||||
------------------------------------------------
|
------------------------------------------------
|
||||||
|
|
||||||
@ -28,14 +20,6 @@ libp2p.network.connection.raw\_connection module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.network.connection.raw\_connection\_interface module
|
|
||||||
-----------------------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.network.connection.raw_connection_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.network.connection.swarm\_connection module
|
libp2p.network.connection.swarm\_connection module
|
||||||
--------------------------------------------------
|
--------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -21,22 +21,6 @@ libp2p.network.exceptions module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.network.network\_interface module
|
|
||||||
----------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.network.network_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.network.notifee\_interface module
|
|
||||||
----------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.network.notifee_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.network.swarm module
|
libp2p.network.swarm module
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
|
|||||||
@ -20,14 +20,6 @@ libp2p.network.stream.net\_stream module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.network.stream.net\_stream\_interface module
|
|
||||||
---------------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.network.stream.net_stream_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
Module contents
|
Module contents
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
|||||||
@ -4,14 +4,6 @@ libp2p.peer package
|
|||||||
Submodules
|
Submodules
|
||||||
----------
|
----------
|
||||||
|
|
||||||
libp2p.peer.addrbook\_interface module
|
|
||||||
--------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.peer.addrbook_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.peer.id module
|
libp2p.peer.id module
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
@ -28,14 +20,6 @@ libp2p.peer.peerdata module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.peer.peerdata\_interface module
|
|
||||||
--------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.peer.peerdata_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.peer.peerinfo module
|
libp2p.peer.peerinfo module
|
||||||
---------------------------
|
---------------------------
|
||||||
|
|
||||||
@ -44,14 +28,6 @@ libp2p.peer.peerinfo module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.peer.peermetadata\_interface module
|
|
||||||
------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.peer.peermetadata_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.peer.peerstore module
|
libp2p.peer.peerstore module
|
||||||
----------------------------
|
----------------------------
|
||||||
|
|
||||||
@ -60,14 +36,6 @@ libp2p.peer.peerstore module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.peer.peerstore\_interface module
|
|
||||||
---------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.peer.peerstore_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
Module contents
|
Module contents
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
|||||||
@ -28,14 +28,6 @@ libp2p.protocol\_muxer.multiselect\_client module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.protocol\_muxer.multiselect\_client\_interface module
|
|
||||||
------------------------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.protocol_muxer.multiselect_client_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.protocol\_muxer.multiselect\_communicator module
|
libp2p.protocol\_muxer.multiselect\_communicator module
|
||||||
-------------------------------------------------------
|
-------------------------------------------------------
|
||||||
|
|
||||||
@ -44,22 +36,6 @@ libp2p.protocol\_muxer.multiselect\_communicator module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.protocol\_muxer.multiselect\_communicator\_interface module
|
|
||||||
------------------------------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.protocol_muxer.multiselect_communicator_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.protocol\_muxer.multiselect\_muxer\_interface module
|
|
||||||
-----------------------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.protocol_muxer.multiselect_muxer_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
Module contents
|
Module contents
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
|
|||||||
@ -12,14 +12,6 @@ Subpackages
|
|||||||
Submodules
|
Submodules
|
||||||
----------
|
----------
|
||||||
|
|
||||||
libp2p.pubsub.abc module
|
|
||||||
------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.pubsub.abc
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.pubsub.exceptions module
|
libp2p.pubsub.exceptions module
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
|
||||||
@ -76,14 +68,6 @@ libp2p.pubsub.subscription module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.pubsub.typing module
|
|
||||||
---------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.pubsub.typing
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.pubsub.validators module
|
libp2p.pubsub.validators module
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -1,21 +0,0 @@
|
|||||||
libp2p.routing package
|
|
||||||
======================
|
|
||||||
|
|
||||||
Submodules
|
|
||||||
----------
|
|
||||||
|
|
||||||
libp2p.routing.interfaces module
|
|
||||||
--------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.routing.interfaces
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
Module contents
|
|
||||||
---------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.routing
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
@ -15,7 +15,6 @@ Subpackages
|
|||||||
libp2p.peer
|
libp2p.peer
|
||||||
libp2p.protocol_muxer
|
libp2p.protocol_muxer
|
||||||
libp2p.pubsub
|
libp2p.pubsub
|
||||||
libp2p.routing
|
|
||||||
libp2p.security
|
libp2p.security
|
||||||
libp2p.stream_muxer
|
libp2p.stream_muxer
|
||||||
libp2p.tools
|
libp2p.tools
|
||||||
@ -24,6 +23,14 @@ Subpackages
|
|||||||
Submodules
|
Submodules
|
||||||
----------
|
----------
|
||||||
|
|
||||||
|
libp2p.abc module
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
.. automodule:: libp2p.abc
|
||||||
|
:members:
|
||||||
|
:undoc-members:
|
||||||
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.exceptions module
|
libp2p.exceptions module
|
||||||
------------------------
|
------------------------
|
||||||
|
|
||||||
@ -39,6 +46,7 @@ libp2p.custom_types module
|
|||||||
:members:
|
:members:
|
||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
:exclude-members: INetStream, IMuxedConn, ISecureTransport
|
||||||
|
|
||||||
libp2p.utils module
|
libp2p.utils module
|
||||||
-------------------
|
-------------------
|
||||||
|
|||||||
@ -38,14 +38,6 @@ libp2p.security.exceptions module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.security.secure\_conn\_interface module
|
|
||||||
----------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.security.secure_conn_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.security.secure\_session module
|
libp2p.security.secure\_session module
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
|
|
||||||
@ -54,14 +46,6 @@ libp2p.security.secure\_session module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.security.secure\_transport\_interface module
|
|
||||||
---------------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.security.secure_transport_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.security.security\_multistream module
|
libp2p.security.security\_multistream module
|
||||||
--------------------------------------------
|
--------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -12,14 +12,6 @@ Subpackages
|
|||||||
Submodules
|
Submodules
|
||||||
----------
|
----------
|
||||||
|
|
||||||
libp2p.stream\_muxer.abc module
|
|
||||||
-------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.stream_muxer.abc
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.stream\_muxer.exceptions module
|
libp2p.stream\_muxer.exceptions module
|
||||||
--------------------------------------
|
--------------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -20,30 +20,6 @@ libp2p.transport.exceptions module
|
|||||||
:undoc-members:
|
:undoc-members:
|
||||||
:show-inheritance:
|
:show-inheritance:
|
||||||
|
|
||||||
libp2p.transport.listener\_interface module
|
|
||||||
-------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.transport.listener_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.transport.transport\_interface module
|
|
||||||
--------------------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.transport.transport_interface
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.transport.typing module
|
|
||||||
------------------------------
|
|
||||||
|
|
||||||
.. automodule:: libp2p.transport.typing
|
|
||||||
:members:
|
|
||||||
:undoc-members:
|
|
||||||
:show-inheritance:
|
|
||||||
|
|
||||||
libp2p.transport.upgrader module
|
libp2p.transport.upgrader module
|
||||||
--------------------------------
|
--------------------------------
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,11 @@
|
|||||||
from importlib.metadata import version as __version
|
from importlib.metadata import version as __version
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IHost,
|
||||||
|
INetworkService,
|
||||||
|
IPeerRouting,
|
||||||
|
IPeerStore,
|
||||||
|
)
|
||||||
from libp2p.crypto.keys import (
|
from libp2p.crypto.keys import (
|
||||||
KeyPair,
|
KeyPair,
|
||||||
)
|
)
|
||||||
@ -7,20 +13,16 @@ from libp2p.crypto.rsa import (
|
|||||||
create_new_key_pair,
|
create_new_key_pair,
|
||||||
)
|
)
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
|
TMuxerOptions,
|
||||||
TProtocol,
|
TProtocol,
|
||||||
|
TSecurityOptions,
|
||||||
)
|
)
|
||||||
from libp2p.host.basic_host import (
|
from libp2p.host.basic_host import (
|
||||||
BasicHost,
|
BasicHost,
|
||||||
)
|
)
|
||||||
from libp2p.host.host_interface import (
|
|
||||||
IHost,
|
|
||||||
)
|
|
||||||
from libp2p.host.routed_host import (
|
from libp2p.host.routed_host import (
|
||||||
RoutedHost,
|
RoutedHost,
|
||||||
)
|
)
|
||||||
from libp2p.network.network_interface import (
|
|
||||||
INetworkService,
|
|
||||||
)
|
|
||||||
from libp2p.network.swarm import (
|
from libp2p.network.swarm import (
|
||||||
Swarm,
|
Swarm,
|
||||||
)
|
)
|
||||||
@ -30,12 +32,6 @@ from libp2p.peer.id import (
|
|||||||
from libp2p.peer.peerstore import (
|
from libp2p.peer.peerstore import (
|
||||||
PeerStore,
|
PeerStore,
|
||||||
)
|
)
|
||||||
from libp2p.peer.peerstore_interface import (
|
|
||||||
IPeerStore,
|
|
||||||
)
|
|
||||||
from libp2p.routing.interfaces import (
|
|
||||||
IPeerRouting,
|
|
||||||
)
|
|
||||||
from libp2p.security.insecure.transport import (
|
from libp2p.security.insecure.transport import (
|
||||||
PLAINTEXT_PROTOCOL_ID,
|
PLAINTEXT_PROTOCOL_ID,
|
||||||
InsecureTransport,
|
InsecureTransport,
|
||||||
@ -48,10 +44,6 @@ from libp2p.stream_muxer.mplex.mplex import (
|
|||||||
from libp2p.transport.tcp.tcp import (
|
from libp2p.transport.tcp.tcp import (
|
||||||
TCP,
|
TCP,
|
||||||
)
|
)
|
||||||
from libp2p.transport.typing import (
|
|
||||||
TMuxerOptions,
|
|
||||||
TSecurityOptions,
|
|
||||||
)
|
|
||||||
from libp2p.transport.upgrader import (
|
from libp2p.transport.upgrader import (
|
||||||
TransportUpgrader,
|
TransportUpgrader,
|
||||||
)
|
)
|
||||||
|
|||||||
1050
libp2p/abc.py
Normal file
1050
libp2p/abc.py
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,15 +1,49 @@
|
|||||||
from collections.abc import (
|
from collections.abc import (
|
||||||
Awaitable,
|
Awaitable,
|
||||||
|
Mapping,
|
||||||
)
|
)
|
||||||
from typing import (
|
from typing import (
|
||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
Callable,
|
Callable,
|
||||||
NewType,
|
NewType,
|
||||||
|
Union,
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from libp2p.network.stream.net_stream_interface import INetStream # noqa: F401
|
from libp2p.abc import (
|
||||||
from libp2p.stream_muxer.abc import IMuxedStream # noqa: F401
|
IMuxedConn,
|
||||||
|
INetStream,
|
||||||
|
ISecureTransport,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
|
||||||
|
class INetStream:
|
||||||
|
pass
|
||||||
|
|
||||||
|
class IMuxedConn:
|
||||||
|
pass
|
||||||
|
|
||||||
|
class ISecureTransport:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
from libp2p.io.abc import (
|
||||||
|
ReadWriteCloser,
|
||||||
|
)
|
||||||
|
from libp2p.peer.id import (
|
||||||
|
ID,
|
||||||
|
)
|
||||||
|
from libp2p.pubsub.pb import (
|
||||||
|
rpc_pb2,
|
||||||
|
)
|
||||||
|
|
||||||
TProtocol = NewType("TProtocol", str)
|
TProtocol = NewType("TProtocol", str)
|
||||||
StreamHandlerFn = Callable[["INetStream"], Awaitable[None]]
|
StreamHandlerFn = Callable[["INetStream"], Awaitable[None]]
|
||||||
|
THandler = Callable[[ReadWriteCloser], Awaitable[None]]
|
||||||
|
TSecurityOptions = Mapping[TProtocol, "ISecureTransport"]
|
||||||
|
TMuxerClass = type["IMuxedConn"]
|
||||||
|
TMuxerOptions = Mapping[TProtocol, TMuxerClass]
|
||||||
|
SyncValidatorFn = Callable[[ID, rpc_pb2.Message], bool]
|
||||||
|
AsyncValidatorFn = Callable[[ID, rpc_pb2.Message], Awaitable[bool]]
|
||||||
|
ValidatorFn = Union[SyncValidatorFn, AsyncValidatorFn]
|
||||||
|
UnsubscribeFn = Callable[[], Awaitable[None]]
|
||||||
|
|||||||
@ -12,6 +12,12 @@ from typing import (
|
|||||||
|
|
||||||
import multiaddr
|
import multiaddr
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IHost,
|
||||||
|
INetStream,
|
||||||
|
INetworkService,
|
||||||
|
IPeerStore,
|
||||||
|
)
|
||||||
from libp2p.crypto.keys import (
|
from libp2p.crypto.keys import (
|
||||||
PrivateKey,
|
PrivateKey,
|
||||||
PublicKey,
|
PublicKey,
|
||||||
@ -26,21 +32,12 @@ from libp2p.host.defaults import (
|
|||||||
from libp2p.host.exceptions import (
|
from libp2p.host.exceptions import (
|
||||||
StreamFailure,
|
StreamFailure,
|
||||||
)
|
)
|
||||||
from libp2p.network.network_interface import (
|
|
||||||
INetworkService,
|
|
||||||
)
|
|
||||||
from libp2p.network.stream.net_stream_interface import (
|
|
||||||
INetStream,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
ID,
|
ID,
|
||||||
)
|
)
|
||||||
from libp2p.peer.peerinfo import (
|
from libp2p.peer.peerinfo import (
|
||||||
PeerInfo,
|
PeerInfo,
|
||||||
)
|
)
|
||||||
from libp2p.peer.peerstore_interface import (
|
|
||||||
IPeerStore,
|
|
||||||
)
|
|
||||||
from libp2p.protocol_muxer.exceptions import (
|
from libp2p.protocol_muxer.exceptions import (
|
||||||
MultiselectClientError,
|
MultiselectClientError,
|
||||||
MultiselectError,
|
MultiselectError,
|
||||||
@ -58,10 +55,6 @@ from libp2p.tools.async_service import (
|
|||||||
background_trio_service,
|
background_trio_service,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .host_interface import (
|
|
||||||
IHost,
|
|
||||||
)
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from collections import (
|
from collections import (
|
||||||
OrderedDict,
|
OrderedDict,
|
||||||
|
|||||||
@ -5,7 +5,7 @@ from typing import (
|
|||||||
TYPE_CHECKING,
|
TYPE_CHECKING,
|
||||||
)
|
)
|
||||||
|
|
||||||
from libp2p.host.host_interface import (
|
from libp2p.abc import (
|
||||||
IHost,
|
IHost,
|
||||||
)
|
)
|
||||||
from libp2p.host.ping import (
|
from libp2p.host.ping import (
|
||||||
|
|||||||
@ -1,133 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
from collections.abc import (
|
|
||||||
Sequence,
|
|
||||||
)
|
|
||||||
from typing import (
|
|
||||||
Any,
|
|
||||||
AsyncContextManager,
|
|
||||||
)
|
|
||||||
|
|
||||||
import multiaddr
|
|
||||||
|
|
||||||
from libp2p.crypto.keys import (
|
|
||||||
PrivateKey,
|
|
||||||
PublicKey,
|
|
||||||
)
|
|
||||||
from libp2p.custom_types import (
|
|
||||||
StreamHandlerFn,
|
|
||||||
TProtocol,
|
|
||||||
)
|
|
||||||
from libp2p.network.network_interface import (
|
|
||||||
INetworkService,
|
|
||||||
)
|
|
||||||
from libp2p.network.stream.net_stream_interface import (
|
|
||||||
INetStream,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import (
|
|
||||||
ID,
|
|
||||||
)
|
|
||||||
from libp2p.peer.peerinfo import (
|
|
||||||
PeerInfo,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class IHost(ABC):
|
|
||||||
@abstractmethod
|
|
||||||
def get_id(self) -> ID:
|
|
||||||
"""
|
|
||||||
:return: peer_id of host
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_public_key(self) -> PublicKey:
|
|
||||||
"""
|
|
||||||
:return: the public key belonging to the peer
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_private_key(self) -> PrivateKey:
|
|
||||||
"""
|
|
||||||
:return: the private key belonging to the peer
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_network(self) -> INetworkService:
|
|
||||||
"""
|
|
||||||
:return: network instance of host
|
|
||||||
"""
|
|
||||||
|
|
||||||
# FIXME: Replace with correct return type
|
|
||||||
@abstractmethod
|
|
||||||
def get_mux(self) -> Any:
|
|
||||||
"""
|
|
||||||
:return: mux instance of host
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_addrs(self) -> list[multiaddr.Multiaddr]:
|
|
||||||
"""
|
|
||||||
:return: all the multiaddr addresses this host is listening to
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_connected_peers(self) -> list[ID]:
|
|
||||||
"""
|
|
||||||
:return: all the ids of peers this host is currently connected to
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def run(
|
|
||||||
self, listen_addrs: Sequence[multiaddr.Multiaddr]
|
|
||||||
) -> AsyncContextManager[None]:
|
|
||||||
"""
|
|
||||||
Run the host instance and listen to ``listen_addrs``.
|
|
||||||
|
|
||||||
:param listen_addrs: a sequence of multiaddrs that we want to listen to
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def set_stream_handler(
|
|
||||||
self, protocol_id: TProtocol, stream_handler: StreamHandlerFn
|
|
||||||
) -> None:
|
|
||||||
"""
|
|
||||||
Set stream handler for host.
|
|
||||||
|
|
||||||
:param protocol_id: protocol id used on stream
|
|
||||||
:param stream_handler: a stream handler function
|
|
||||||
"""
|
|
||||||
|
|
||||||
# protocol_id can be a list of protocol_ids
|
|
||||||
# stream will decide which protocol_id to run on
|
|
||||||
@abstractmethod
|
|
||||||
async def new_stream(
|
|
||||||
self, peer_id: ID, protocol_ids: Sequence[TProtocol]
|
|
||||||
) -> INetStream:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer_id that host is connecting
|
|
||||||
:param protocol_ids: available protocol ids to use for stream
|
|
||||||
:return: stream: new stream created
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def connect(self, peer_info: PeerInfo) -> None:
|
|
||||||
"""
|
|
||||||
Ensure there is a connection between this host and the peer
|
|
||||||
with given peer_info.peer_id. connect will absorb the addresses in
|
|
||||||
peer_info into its internal peerstore. If there is not an active
|
|
||||||
connection, connect will issue a dial, and block until a connection is
|
|
||||||
opened, or an error is returned.
|
|
||||||
|
|
||||||
:param peer_info: peer_info of the peer we want to connect to
|
|
||||||
:type peer_info: peer.peerinfo.PeerInfo
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def disconnect(self, peer_id: ID) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def close(self) -> None:
|
|
||||||
pass
|
|
||||||
@ -4,20 +4,18 @@ import time
|
|||||||
|
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IHost,
|
||||||
|
INetStream,
|
||||||
|
)
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
TProtocol,
|
TProtocol,
|
||||||
)
|
)
|
||||||
from libp2p.host.host_interface import (
|
|
||||||
IHost,
|
|
||||||
)
|
|
||||||
from libp2p.network.stream.exceptions import (
|
from libp2p.network.stream.exceptions import (
|
||||||
StreamClosed,
|
StreamClosed,
|
||||||
StreamEOF,
|
StreamEOF,
|
||||||
StreamReset,
|
StreamReset,
|
||||||
)
|
)
|
||||||
from libp2p.network.stream.net_stream_interface import (
|
|
||||||
INetStream,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import ID as PeerID
|
from libp2p.peer.id import ID as PeerID
|
||||||
|
|
||||||
ID = TProtocol("/ipfs/ping/1.0.0")
|
ID = TProtocol("/ipfs/ping/1.0.0")
|
||||||
|
|||||||
@ -1,18 +1,16 @@
|
|||||||
|
from libp2p.abc import (
|
||||||
|
INetworkService,
|
||||||
|
IPeerRouting,
|
||||||
|
)
|
||||||
from libp2p.host.basic_host import (
|
from libp2p.host.basic_host import (
|
||||||
BasicHost,
|
BasicHost,
|
||||||
)
|
)
|
||||||
from libp2p.host.exceptions import (
|
from libp2p.host.exceptions import (
|
||||||
ConnectionFailure,
|
ConnectionFailure,
|
||||||
)
|
)
|
||||||
from libp2p.network.network_interface import (
|
|
||||||
INetworkService,
|
|
||||||
)
|
|
||||||
from libp2p.peer.peerinfo import (
|
from libp2p.peer.peerinfo import (
|
||||||
PeerInfo,
|
PeerInfo,
|
||||||
)
|
)
|
||||||
from libp2p.routing.interfaces import (
|
|
||||||
IPeerRouting,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# RoutedHost is a p2p Host that includes a routing system.
|
# RoutedHost is a p2p Host that includes a routing system.
|
||||||
|
|||||||
@ -4,19 +4,17 @@ from multiaddr import (
|
|||||||
Multiaddr,
|
Multiaddr,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IHost,
|
||||||
|
INetStream,
|
||||||
|
)
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
StreamHandlerFn,
|
StreamHandlerFn,
|
||||||
TProtocol,
|
TProtocol,
|
||||||
)
|
)
|
||||||
from libp2p.host.host_interface import (
|
|
||||||
IHost,
|
|
||||||
)
|
|
||||||
from libp2p.network.stream.exceptions import (
|
from libp2p.network.stream.exceptions import (
|
||||||
StreamClosed,
|
StreamClosed,
|
||||||
)
|
)
|
||||||
from libp2p.network.stream.net_stream_interface import (
|
|
||||||
INetStream,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .pb.identify_pb2 import (
|
from .pb.identify_pb2 import (
|
||||||
Identify,
|
Identify,
|
||||||
|
|||||||
@ -1,28 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
|
|
||||||
import trio
|
|
||||||
|
|
||||||
from libp2p.io.abc import (
|
|
||||||
Closer,
|
|
||||||
)
|
|
||||||
from libp2p.network.stream.net_stream_interface import (
|
|
||||||
INetStream,
|
|
||||||
)
|
|
||||||
from libp2p.stream_muxer.abc import (
|
|
||||||
IMuxedConn,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class INetConn(Closer):
|
|
||||||
muxed_conn: IMuxedConn
|
|
||||||
event_started: trio.Event
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def new_stream(self) -> INetStream:
|
|
||||||
...
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_streams(self) -> tuple[INetStream, ...]:
|
|
||||||
...
|
|
||||||
@ -1,3 +1,6 @@
|
|||||||
|
from libp2p.abc import (
|
||||||
|
IRawConnection,
|
||||||
|
)
|
||||||
from libp2p.io.abc import (
|
from libp2p.io.abc import (
|
||||||
ReadWriteCloser,
|
ReadWriteCloser,
|
||||||
)
|
)
|
||||||
@ -8,9 +11,6 @@ from libp2p.io.exceptions import (
|
|||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
RawConnError,
|
RawConnError,
|
||||||
)
|
)
|
||||||
from .raw_connection_interface import (
|
|
||||||
IRawConnection,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class RawConnection(IRawConnection):
|
class RawConnection(IRawConnection):
|
||||||
|
|||||||
@ -1,9 +0,0 @@
|
|||||||
from libp2p.io.abc import (
|
|
||||||
ReadWriteCloser,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class IRawConnection(ReadWriteCloser):
|
|
||||||
"""A Raw Connection provides a Reader and a Writer."""
|
|
||||||
|
|
||||||
is_initiator: bool
|
|
||||||
@ -4,16 +4,14 @@ from typing import (
|
|||||||
|
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
from libp2p.network.connection.net_connection_interface import (
|
from libp2p.abc import (
|
||||||
|
IMuxedConn,
|
||||||
|
IMuxedStream,
|
||||||
INetConn,
|
INetConn,
|
||||||
)
|
)
|
||||||
from libp2p.network.stream.net_stream import (
|
from libp2p.network.stream.net_stream import (
|
||||||
NetStream,
|
NetStream,
|
||||||
)
|
)
|
||||||
from libp2p.stream_muxer.abc import (
|
|
||||||
IMuxedConn,
|
|
||||||
IMuxedStream,
|
|
||||||
)
|
|
||||||
from libp2p.stream_muxer.exceptions import (
|
from libp2p.stream_muxer.exceptions import (
|
||||||
MuxedConnUnavailable,
|
MuxedConnUnavailable,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,100 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
from collections.abc import (
|
|
||||||
Sequence,
|
|
||||||
)
|
|
||||||
from typing import (
|
|
||||||
TYPE_CHECKING,
|
|
||||||
)
|
|
||||||
|
|
||||||
from multiaddr import (
|
|
||||||
Multiaddr,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.custom_types import (
|
|
||||||
StreamHandlerFn,
|
|
||||||
)
|
|
||||||
from libp2p.network.connection.net_connection_interface import (
|
|
||||||
INetConn,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import (
|
|
||||||
ID,
|
|
||||||
)
|
|
||||||
from libp2p.peer.peerstore_interface import (
|
|
||||||
IPeerStore,
|
|
||||||
)
|
|
||||||
from libp2p.tools.async_service import (
|
|
||||||
ServiceAPI,
|
|
||||||
)
|
|
||||||
from libp2p.transport.listener_interface import (
|
|
||||||
IListener,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .stream.net_stream_interface import (
|
|
||||||
INetStream,
|
|
||||||
)
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from .notifee_interface import INotifee # noqa: F401
|
|
||||||
|
|
||||||
|
|
||||||
class INetwork(ABC):
|
|
||||||
peerstore: IPeerStore
|
|
||||||
connections: dict[ID, INetConn]
|
|
||||||
listeners: dict[str, IListener]
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_peer_id(self) -> ID:
|
|
||||||
"""
|
|
||||||
:return: the peer id
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def dial_peer(self, peer_id: ID) -> INetConn:
|
|
||||||
"""
|
|
||||||
dial_peer try to create a connection to peer_id.
|
|
||||||
|
|
||||||
:param peer_id: peer if we want to dial
|
|
||||||
:raises SwarmException: raised when an error occurs
|
|
||||||
:return: muxed connection
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def new_stream(self, peer_id: ID) -> INetStream:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer_id of destination
|
|
||||||
:param protocol_ids: available protocol ids to use for stream
|
|
||||||
:return: net stream instance
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def set_stream_handler(self, stream_handler: StreamHandlerFn) -> None:
|
|
||||||
"""Set the stream handler for all incoming streams."""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def listen(self, *multiaddrs: Sequence[Multiaddr]) -> bool:
|
|
||||||
"""
|
|
||||||
:param multiaddrs: one or many multiaddrs to start listening on
|
|
||||||
:return: True if at least one success
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def register_notifee(self, notifee: "INotifee") -> None:
|
|
||||||
"""
|
|
||||||
:param notifee: object implementing Notifee interface
|
|
||||||
:return: true if notifee registered successfully, false otherwise
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def close(self) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def close_peer(self, peer_id: ID) -> None:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class INetworkService(INetwork, ServiceAPI):
|
|
||||||
pass
|
|
||||||
@ -1,65 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
from typing import (
|
|
||||||
TYPE_CHECKING,
|
|
||||||
)
|
|
||||||
|
|
||||||
from multiaddr import (
|
|
||||||
Multiaddr,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.network.connection.net_connection_interface import (
|
|
||||||
INetConn,
|
|
||||||
)
|
|
||||||
from libp2p.network.stream.net_stream_interface import (
|
|
||||||
INetStream,
|
|
||||||
)
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from .network_interface import INetwork # noqa: F401
|
|
||||||
|
|
||||||
|
|
||||||
class INotifee(ABC):
|
|
||||||
@abstractmethod
|
|
||||||
async def opened_stream(self, network: "INetwork", stream: INetStream) -> None:
|
|
||||||
"""
|
|
||||||
:param network: network the stream was opened on
|
|
||||||
:param stream: stream that was opened
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def closed_stream(self, network: "INetwork", stream: INetStream) -> None:
|
|
||||||
"""
|
|
||||||
:param network: network the stream was closed on
|
|
||||||
:param stream: stream that was closed
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def connected(self, network: "INetwork", conn: INetConn) -> None:
|
|
||||||
"""
|
|
||||||
:param network: network the connection was opened on
|
|
||||||
:param conn: connection that was opened
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def disconnected(self, network: "INetwork", conn: INetConn) -> None:
|
|
||||||
"""
|
|
||||||
:param network: network the connection was closed on
|
|
||||||
:param conn: connection that was closed
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def listen(self, network: "INetwork", multiaddr: Multiaddr) -> None:
|
|
||||||
"""
|
|
||||||
:param network: network the listener is listening on
|
|
||||||
:param multiaddr: multiaddress listener is listening on
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def listen_close(self, network: "INetwork", multiaddr: Multiaddr) -> None:
|
|
||||||
"""
|
|
||||||
:param network: network the connection was opened on
|
|
||||||
:param multiaddr: multiaddress listener is no longer listening on
|
|
||||||
"""
|
|
||||||
@ -2,12 +2,13 @@ from typing import (
|
|||||||
Optional,
|
Optional,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IMuxedStream,
|
||||||
|
INetStream,
|
||||||
|
)
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
TProtocol,
|
TProtocol,
|
||||||
)
|
)
|
||||||
from libp2p.stream_muxer.abc import (
|
|
||||||
IMuxedStream,
|
|
||||||
)
|
|
||||||
from libp2p.stream_muxer.exceptions import (
|
from libp2p.stream_muxer.exceptions import (
|
||||||
MuxedStreamClosed,
|
MuxedStreamClosed,
|
||||||
MuxedStreamEOF,
|
MuxedStreamEOF,
|
||||||
@ -19,9 +20,6 @@ from .exceptions import (
|
|||||||
StreamEOF,
|
StreamEOF,
|
||||||
StreamReset,
|
StreamReset,
|
||||||
)
|
)
|
||||||
from .net_stream_interface import (
|
|
||||||
INetStream,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: Handle exceptions from `muxed_stream`
|
# TODO: Handle exceptions from `muxed_stream`
|
||||||
|
|||||||
@ -1,33 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.custom_types import (
|
|
||||||
TProtocol,
|
|
||||||
)
|
|
||||||
from libp2p.io.abc import (
|
|
||||||
ReadWriteCloser,
|
|
||||||
)
|
|
||||||
from libp2p.stream_muxer.abc import (
|
|
||||||
IMuxedConn,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class INetStream(ReadWriteCloser):
|
|
||||||
muxed_conn: IMuxedConn
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_protocol(self) -> TProtocol:
|
|
||||||
"""
|
|
||||||
:return: protocol id that stream runs on
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def set_protocol(self, protocol_id: TProtocol) -> None:
|
|
||||||
"""
|
|
||||||
:param protocol_id: protocol id that stream runs on
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def reset(self) -> None:
|
|
||||||
"""Close both ends of the stream."""
|
|
||||||
@ -8,27 +8,28 @@ from multiaddr import (
|
|||||||
)
|
)
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IListener,
|
||||||
|
IMuxedConn,
|
||||||
|
INetConn,
|
||||||
|
INetStream,
|
||||||
|
INetworkService,
|
||||||
|
INotifee,
|
||||||
|
IPeerStore,
|
||||||
|
ITransport,
|
||||||
|
)
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
StreamHandlerFn,
|
StreamHandlerFn,
|
||||||
)
|
)
|
||||||
from libp2p.io.abc import (
|
from libp2p.io.abc import (
|
||||||
ReadWriteCloser,
|
ReadWriteCloser,
|
||||||
)
|
)
|
||||||
from libp2p.network.connection.net_connection_interface import (
|
|
||||||
INetConn,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
ID,
|
ID,
|
||||||
)
|
)
|
||||||
from libp2p.peer.peerstore import (
|
from libp2p.peer.peerstore import (
|
||||||
PeerStoreError,
|
PeerStoreError,
|
||||||
)
|
)
|
||||||
from libp2p.peer.peerstore_interface import (
|
|
||||||
IPeerStore,
|
|
||||||
)
|
|
||||||
from libp2p.stream_muxer.abc import (
|
|
||||||
IMuxedConn,
|
|
||||||
)
|
|
||||||
from libp2p.tools.async_service import (
|
from libp2p.tools.async_service import (
|
||||||
Service,
|
Service,
|
||||||
)
|
)
|
||||||
@ -37,12 +38,6 @@ from libp2p.transport.exceptions import (
|
|||||||
OpenConnectionError,
|
OpenConnectionError,
|
||||||
SecurityUpgradeFailure,
|
SecurityUpgradeFailure,
|
||||||
)
|
)
|
||||||
from libp2p.transport.listener_interface import (
|
|
||||||
IListener,
|
|
||||||
)
|
|
||||||
from libp2p.transport.transport_interface import (
|
|
||||||
ITransport,
|
|
||||||
)
|
|
||||||
from libp2p.transport.upgrader import (
|
from libp2p.transport.upgrader import (
|
||||||
TransportUpgrader,
|
TransportUpgrader,
|
||||||
)
|
)
|
||||||
@ -59,15 +54,6 @@ from .connection.swarm_connection import (
|
|||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
SwarmException,
|
SwarmException,
|
||||||
)
|
)
|
||||||
from .network_interface import (
|
|
||||||
INetworkService,
|
|
||||||
)
|
|
||||||
from .notifee_interface import (
|
|
||||||
INotifee,
|
|
||||||
)
|
|
||||||
from .stream.net_stream_interface import (
|
|
||||||
INetStream,
|
|
||||||
)
|
|
||||||
|
|
||||||
logger = logging.getLogger("libp2p.network.swarm")
|
logger = logging.getLogger("libp2p.network.swarm")
|
||||||
|
|
||||||
|
|||||||
@ -1,61 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
from collections.abc import (
|
|
||||||
Sequence,
|
|
||||||
)
|
|
||||||
|
|
||||||
from multiaddr import (
|
|
||||||
Multiaddr,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .id import (
|
|
||||||
ID,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class IAddrBook(ABC):
|
|
||||||
@abstractmethod
|
|
||||||
def add_addr(self, peer_id: ID, addr: Multiaddr, ttl: int) -> None:
|
|
||||||
"""
|
|
||||||
Calls add_addrs(peer_id, [addr], ttl)
|
|
||||||
|
|
||||||
:param peer_id: the peer to add address for
|
|
||||||
:param addr: multiaddress of the peer
|
|
||||||
:param ttl: time-to-live for the address (after this time, address is no longer valid)
|
|
||||||
""" # noqa: E501
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_addrs(self, peer_id: ID, addrs: Sequence[Multiaddr], ttl: int) -> None:
|
|
||||||
"""
|
|
||||||
Adds addresses for a given peer all with the same time-to-live. If one
|
|
||||||
of the addresses already exists for the peer and has a longer TTL, no
|
|
||||||
operation should take place. If one of the addresses exists with a
|
|
||||||
shorter TTL, extend the TTL to equal param ttl.
|
|
||||||
|
|
||||||
:param peer_id: the peer to add address for
|
|
||||||
:param addr: multiaddresses of the peer
|
|
||||||
:param ttl: time-to-live for the address (after this time, address is no longer valid
|
|
||||||
""" # noqa: E501
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def addrs(self, peer_id: ID) -> list[Multiaddr]:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer to get addresses of
|
|
||||||
:return: all known (and valid) addresses for the given peer
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def clear_addrs(self, peer_id: ID) -> None:
|
|
||||||
"""
|
|
||||||
Removes all previously stored addresses.
|
|
||||||
|
|
||||||
:param peer_id: peer to remove addresses of
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def peers_with_addrs(self) -> list[ID]:
|
|
||||||
"""
|
|
||||||
:return: all of the peer IDs stored with addresses
|
|
||||||
"""
|
|
||||||
@ -9,15 +9,14 @@ from multiaddr import (
|
|||||||
Multiaddr,
|
Multiaddr,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IPeerData,
|
||||||
|
)
|
||||||
from libp2p.crypto.keys import (
|
from libp2p.crypto.keys import (
|
||||||
PrivateKey,
|
PrivateKey,
|
||||||
PublicKey,
|
PublicKey,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .peerdata_interface import (
|
|
||||||
IPeerData,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class PeerData(IPeerData):
|
class PeerData(IPeerData):
|
||||||
pubkey: PublicKey
|
pubkey: PublicKey
|
||||||
|
|||||||
@ -1,100 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
from collections.abc import (
|
|
||||||
Sequence,
|
|
||||||
)
|
|
||||||
from typing import (
|
|
||||||
Any,
|
|
||||||
)
|
|
||||||
|
|
||||||
from multiaddr import (
|
|
||||||
Multiaddr,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.crypto.keys import (
|
|
||||||
PrivateKey,
|
|
||||||
PublicKey,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .peermetadata_interface import (
|
|
||||||
IPeerMetadata,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class IPeerData(ABC):
|
|
||||||
@abstractmethod
|
|
||||||
def get_protocols(self) -> list[str]:
|
|
||||||
"""
|
|
||||||
:return: all protocols associated with given peer
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_protocols(self, protocols: Sequence[str]) -> None:
|
|
||||||
"""
|
|
||||||
:param protocols: protocols to add
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def set_protocols(self, protocols: Sequence[str]) -> None:
|
|
||||||
"""
|
|
||||||
:param protocols: protocols to set
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_addrs(self, addrs: Sequence[Multiaddr]) -> None:
|
|
||||||
"""
|
|
||||||
:param addrs: multiaddresses to add
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_addrs(self) -> list[Multiaddr]:
|
|
||||||
"""
|
|
||||||
:return: all multiaddresses
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def clear_addrs(self) -> None:
|
|
||||||
"""Clear all addresses."""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def put_metadata(self, key: str, val: Any) -> None:
|
|
||||||
"""
|
|
||||||
:param key: key in KV pair
|
|
||||||
:param val: val to associate with key
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_metadata(self, key: str) -> IPeerMetadata:
|
|
||||||
"""
|
|
||||||
:param key: key in KV pair
|
|
||||||
:return: val for key
|
|
||||||
:raise PeerDataError: key not found
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_pubkey(self, pubkey: PublicKey) -> None:
|
|
||||||
"""
|
|
||||||
:param pubkey:
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_pubkey(self) -> PublicKey:
|
|
||||||
"""
|
|
||||||
:return: public key of the peer
|
|
||||||
:raise PeerDataError: if public key not found
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_privkey(self, privkey: PrivateKey) -> None:
|
|
||||||
"""
|
|
||||||
:param privkey:
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_privkey(self) -> PrivateKey:
|
|
||||||
"""
|
|
||||||
:return: private key of the peer
|
|
||||||
:raise PeerDataError: if private key not found
|
|
||||||
"""
|
|
||||||
@ -1,31 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
from typing import (
|
|
||||||
Any,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .id import (
|
|
||||||
ID,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class IPeerMetadata(ABC):
|
|
||||||
@abstractmethod
|
|
||||||
def get(self, peer_id: ID, key: str) -> Any:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to lookup key for
|
|
||||||
:param key: key to look up
|
|
||||||
:return: value at key for given peer
|
|
||||||
:raise Exception: peer ID not found
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def put(self, peer_id: ID, key: str, val: Any) -> None:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to lookup key for
|
|
||||||
:param key: key to associate with peer
|
|
||||||
:param val: value to associated with key
|
|
||||||
:raise Exception: unsuccessful put
|
|
||||||
"""
|
|
||||||
@ -12,6 +12,9 @@ from multiaddr import (
|
|||||||
Multiaddr,
|
Multiaddr,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IPeerStore,
|
||||||
|
)
|
||||||
from libp2p.crypto.keys import (
|
from libp2p.crypto.keys import (
|
||||||
KeyPair,
|
KeyPair,
|
||||||
PrivateKey,
|
PrivateKey,
|
||||||
@ -28,9 +31,6 @@ from .peerdata import (
|
|||||||
from .peerinfo import (
|
from .peerinfo import (
|
||||||
PeerInfo,
|
PeerInfo,
|
||||||
)
|
)
|
||||||
from .peerstore_interface import (
|
|
||||||
IPeerStore,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class PeerStore(IPeerStore):
|
class PeerStore(IPeerStore):
|
||||||
|
|||||||
@ -1,161 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
from collections.abc import (
|
|
||||||
Sequence,
|
|
||||||
)
|
|
||||||
from typing import (
|
|
||||||
Any,
|
|
||||||
)
|
|
||||||
|
|
||||||
from multiaddr import (
|
|
||||||
Multiaddr,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.crypto.keys import (
|
|
||||||
KeyPair,
|
|
||||||
PrivateKey,
|
|
||||||
PublicKey,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .addrbook_interface import (
|
|
||||||
IAddrBook,
|
|
||||||
)
|
|
||||||
from .id import (
|
|
||||||
ID,
|
|
||||||
)
|
|
||||||
from .peerinfo import (
|
|
||||||
PeerInfo,
|
|
||||||
)
|
|
||||||
from .peermetadata_interface import (
|
|
||||||
IPeerMetadata,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class IPeerStore(IAddrBook, IPeerMetadata):
|
|
||||||
@abstractmethod
|
|
||||||
def peer_info(self, peer_id: ID) -> PeerInfo:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to get info for
|
|
||||||
:return: peer info object
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_protocols(self, peer_id: ID) -> list[str]:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to get protocols for
|
|
||||||
:return: protocols (as list of strings)
|
|
||||||
:raise PeerStoreError: if peer ID not found
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_protocols(self, peer_id: ID, protocols: Sequence[str]) -> None:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to add protocols for
|
|
||||||
:param protocols: protocols to add
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def set_protocols(self, peer_id: ID, protocols: Sequence[str]) -> None:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to set protocols for
|
|
||||||
:param protocols: protocols to set
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def peer_ids(self) -> list[ID]:
|
|
||||||
"""
|
|
||||||
:return: all of the peer IDs stored in peer store
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get(self, peer_id: ID, key: str) -> Any:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to get peer data for
|
|
||||||
:param key: the key to search value for
|
|
||||||
:return: value corresponding to the key
|
|
||||||
:raise PeerStoreError: if peer ID or value not found
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def put(self, peer_id: ID, key: str, val: Any) -> None:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to put peer data for
|
|
||||||
:param key:
|
|
||||||
:param value:
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_addr(self, peer_id: ID, addr: Multiaddr, ttl: int) -> None:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to add address for
|
|
||||||
:param addr:
|
|
||||||
:param ttl: time-to-live for the this record
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_addrs(self, peer_id: ID, addrs: Sequence[Multiaddr], ttl: int) -> None:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to add address for
|
|
||||||
:param addrs:
|
|
||||||
:param ttl: time-to-live for the this record
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def addrs(self, peer_id: ID) -> list[Multiaddr]:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to get addrs for
|
|
||||||
:return: list of addrs
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def clear_addrs(self, peer_id: ID) -> None:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to clear addrs for
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def peers_with_addrs(self) -> list[ID]:
|
|
||||||
"""
|
|
||||||
:return: all of the peer IDs which has addrs stored in peer store
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_pubkey(self, peer_id: ID, pubkey: PublicKey) -> None:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to add public key for
|
|
||||||
:param pubkey:
|
|
||||||
:raise PeerStoreError: if peer ID already has pubkey set
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def pubkey(self, peer_id: ID) -> PublicKey:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to get public key for
|
|
||||||
:return: public key of the peer
|
|
||||||
:raise PeerStoreError: if peer ID not found
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_privkey(self, peer_id: ID, privkey: PrivateKey) -> None:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to add private key for
|
|
||||||
:param privkey:
|
|
||||||
:raise PeerStoreError: if peer ID already has privkey set
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def privkey(self, peer_id: ID) -> PrivateKey:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to get private key for
|
|
||||||
:return: private key of the peer
|
|
||||||
:raise PeerStoreError: if peer ID not found
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_key_pair(self, peer_id: ID, key_pair: KeyPair) -> None:
|
|
||||||
"""
|
|
||||||
:param peer_id: peer ID to add private key for
|
|
||||||
:param key_pair:
|
|
||||||
:raise PeerStoreError: if peer ID already has pubkey or privkey set
|
|
||||||
"""
|
|
||||||
@ -1,3 +1,7 @@
|
|||||||
|
from libp2p.abc import (
|
||||||
|
IMultiselectCommunicator,
|
||||||
|
IMultiselectMuxer,
|
||||||
|
)
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
StreamHandlerFn,
|
StreamHandlerFn,
|
||||||
TProtocol,
|
TProtocol,
|
||||||
@ -7,12 +11,6 @@ from .exceptions import (
|
|||||||
MultiselectCommunicatorError,
|
MultiselectCommunicatorError,
|
||||||
MultiselectError,
|
MultiselectError,
|
||||||
)
|
)
|
||||||
from .multiselect_communicator_interface import (
|
|
||||||
IMultiselectCommunicator,
|
|
||||||
)
|
|
||||||
from .multiselect_muxer_interface import (
|
|
||||||
IMultiselectMuxer,
|
|
||||||
)
|
|
||||||
|
|
||||||
MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0"
|
MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0"
|
||||||
PROTOCOL_NOT_FOUND_MSG = "na"
|
PROTOCOL_NOT_FOUND_MSG = "na"
|
||||||
|
|||||||
@ -2,6 +2,10 @@ from collections.abc import (
|
|||||||
Sequence,
|
Sequence,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IMultiselectClient,
|
||||||
|
IMultiselectCommunicator,
|
||||||
|
)
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
TProtocol,
|
TProtocol,
|
||||||
)
|
)
|
||||||
@ -10,12 +14,6 @@ from .exceptions import (
|
|||||||
MultiselectClientError,
|
MultiselectClientError,
|
||||||
MultiselectCommunicatorError,
|
MultiselectCommunicatorError,
|
||||||
)
|
)
|
||||||
from .multiselect_client_interface import (
|
|
||||||
IMultiselectClient,
|
|
||||||
)
|
|
||||||
from .multiselect_communicator_interface import (
|
|
||||||
IMultiselectCommunicator,
|
|
||||||
)
|
|
||||||
|
|
||||||
MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0"
|
MULTISELECT_PROTOCOL_ID = "/multistream/1.0.0"
|
||||||
PROTOCOL_NOT_FOUND_MSG = "na"
|
PROTOCOL_NOT_FOUND_MSG = "na"
|
||||||
|
|||||||
@ -1,58 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
from collections.abc import (
|
|
||||||
Sequence,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.custom_types import (
|
|
||||||
TProtocol,
|
|
||||||
)
|
|
||||||
from libp2p.protocol_muxer.multiselect_communicator_interface import (
|
|
||||||
IMultiselectCommunicator,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class IMultiselectClient(ABC):
|
|
||||||
"""
|
|
||||||
Client for communicating with receiver's multiselect module in order to
|
|
||||||
select a protocol id to communicate over.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def handshake(self, communicator: IMultiselectCommunicator) -> None:
|
|
||||||
"""
|
|
||||||
Ensure that the client and multiselect are both using the same
|
|
||||||
multiselect protocol.
|
|
||||||
|
|
||||||
:param stream: stream to communicate with multiselect over
|
|
||||||
:raise Exception: multiselect protocol ID mismatch
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def select_one_of(
|
|
||||||
self, protocols: Sequence[TProtocol], communicator: IMultiselectCommunicator
|
|
||||||
) -> TProtocol:
|
|
||||||
"""
|
|
||||||
For each protocol, send message to multiselect selecting protocol and
|
|
||||||
fail if multiselect does not return same protocol. Returns first
|
|
||||||
protocol that multiselect agrees on (i.e. that multiselect selects)
|
|
||||||
|
|
||||||
:param protocol: protocol to select
|
|
||||||
:param stream: stream to communicate with multiselect over
|
|
||||||
:return: selected protocol
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def try_select(
|
|
||||||
self, communicator: IMultiselectCommunicator, protocol: TProtocol
|
|
||||||
) -> TProtocol:
|
|
||||||
"""
|
|
||||||
Try to select the given protocol or raise exception if fails.
|
|
||||||
|
|
||||||
:param communicator: communicator to use to communicate with counterparty
|
|
||||||
:param protocol: protocol to select
|
|
||||||
:raise Exception: error in protocol selection
|
|
||||||
:return: selected protocol
|
|
||||||
"""
|
|
||||||
@ -1,3 +1,6 @@
|
|||||||
|
from libp2p.abc import (
|
||||||
|
IMultiselectCommunicator,
|
||||||
|
)
|
||||||
from libp2p.exceptions import (
|
from libp2p.exceptions import (
|
||||||
ParseError,
|
ParseError,
|
||||||
)
|
)
|
||||||
@ -15,9 +18,6 @@ from libp2p.utils import (
|
|||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
MultiselectCommunicatorError,
|
MultiselectCommunicatorError,
|
||||||
)
|
)
|
||||||
from .multiselect_communicator_interface import (
|
|
||||||
IMultiselectCommunicator,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class MultiselectCommunicator(IMultiselectCommunicator):
|
class MultiselectCommunicator(IMultiselectCommunicator):
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class IMultiselectCommunicator(ABC):
|
|
||||||
"""
|
|
||||||
Communicator helper class that ensures both the client and multistream
|
|
||||||
module will follow the same multistream protocol, which is necessary for
|
|
||||||
them to work.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def write(self, msg_str: str) -> None:
|
|
||||||
"""
|
|
||||||
Write message to stream.
|
|
||||||
|
|
||||||
:param msg_str: message to write
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def read(self) -> str:
|
|
||||||
"""Reads message from stream until EOF."""
|
|
||||||
@ -1,47 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.custom_types import (
|
|
||||||
StreamHandlerFn,
|
|
||||||
TProtocol,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .multiselect_communicator_interface import (
|
|
||||||
IMultiselectCommunicator,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class IMultiselectMuxer(ABC):
|
|
||||||
"""
|
|
||||||
Multiselect module that is responsible for responding to a multiselect
|
|
||||||
client and deciding on a specific protocol and handler pair to use for
|
|
||||||
communication.
|
|
||||||
"""
|
|
||||||
|
|
||||||
handlers: dict[TProtocol, StreamHandlerFn]
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_handler(self, protocol: TProtocol, handler: StreamHandlerFn) -> None:
|
|
||||||
"""
|
|
||||||
Store the handler with the given protocol.
|
|
||||||
|
|
||||||
:param protocol: protocol name
|
|
||||||
:param handler: handler function
|
|
||||||
"""
|
|
||||||
|
|
||||||
def get_protocols(self) -> tuple[TProtocol, ...]:
|
|
||||||
return tuple(self.handlers.keys())
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def negotiate(
|
|
||||||
self, communicator: IMultiselectCommunicator
|
|
||||||
) -> tuple[TProtocol, StreamHandlerFn]:
|
|
||||||
"""
|
|
||||||
Negotiate performs protocol selection.
|
|
||||||
|
|
||||||
:param stream: stream to negotiate on
|
|
||||||
:return: selected protocol name, handler function
|
|
||||||
:raise Exception: negotiation failed exception
|
|
||||||
"""
|
|
||||||
@ -1,158 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
from collections.abc import (
|
|
||||||
AsyncIterable,
|
|
||||||
KeysView,
|
|
||||||
)
|
|
||||||
from typing import (
|
|
||||||
TYPE_CHECKING,
|
|
||||||
AsyncContextManager,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.custom_types import (
|
|
||||||
TProtocol,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import (
|
|
||||||
ID,
|
|
||||||
)
|
|
||||||
from libp2p.tools.async_service import (
|
|
||||||
ServiceAPI,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .pb import (
|
|
||||||
rpc_pb2,
|
|
||||||
)
|
|
||||||
from .typing import (
|
|
||||||
ValidatorFn,
|
|
||||||
)
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from .pubsub import Pubsub # noqa: F401
|
|
||||||
|
|
||||||
|
|
||||||
class ISubscriptionAPI(
|
|
||||||
AsyncContextManager["ISubscriptionAPI"], AsyncIterable[rpc_pb2.Message]
|
|
||||||
):
|
|
||||||
@abstractmethod
|
|
||||||
async def unsubscribe(self) -> None:
|
|
||||||
...
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def get(self) -> rpc_pb2.Message:
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
class IPubsubRouter(ABC):
|
|
||||||
@abstractmethod
|
|
||||||
def get_protocols(self) -> list[TProtocol]:
|
|
||||||
"""
|
|
||||||
:return: the list of protocols supported by the router
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def attach(self, pubsub: "Pubsub") -> None:
|
|
||||||
"""
|
|
||||||
Attach is invoked by the PubSub constructor to attach the router to a
|
|
||||||
freshly initialized PubSub instance.
|
|
||||||
|
|
||||||
:param pubsub: pubsub instance to attach to
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def add_peer(self, peer_id: ID, protocol_id: TProtocol) -> None:
|
|
||||||
"""
|
|
||||||
Notifies the router that a new peer has been connected.
|
|
||||||
|
|
||||||
:param peer_id: id of peer to add
|
|
||||||
:param protocol_id: router protocol the peer speaks, e.g., floodsub, gossipsub
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def remove_peer(self, peer_id: ID) -> None:
|
|
||||||
"""
|
|
||||||
Notifies the router that a peer has been disconnected.
|
|
||||||
|
|
||||||
:param peer_id: id of peer to remove
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def handle_rpc(self, rpc: rpc_pb2.RPC, sender_peer_id: ID) -> None:
|
|
||||||
"""
|
|
||||||
Invoked to process control messages in the RPC envelope.
|
|
||||||
It is invoked after subscriptions and payload messages have been processed
|
|
||||||
|
|
||||||
:param rpc: RPC message
|
|
||||||
:param sender_peer_id: id of the peer who sent the message
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def publish(self, msg_forwarder: ID, pubsub_msg: rpc_pb2.Message) -> None:
|
|
||||||
"""
|
|
||||||
Invoked to forward a new message that has been validated.
|
|
||||||
|
|
||||||
:param msg_forwarder: peer_id of message sender
|
|
||||||
:param pubsub_msg: pubsub message to forward
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def join(self, topic: str) -> None:
|
|
||||||
"""
|
|
||||||
Join notifies the router that we want to receive and forward messages
|
|
||||||
in a topic. It is invoked after the subscription announcement.
|
|
||||||
|
|
||||||
:param topic: topic to join
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def leave(self, topic: str) -> None:
|
|
||||||
"""
|
|
||||||
Leave notifies the router that we are no longer interested in a topic.
|
|
||||||
It is invoked after the unsubscription announcement.
|
|
||||||
|
|
||||||
:param topic: topic to leave
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class IPubsub(ServiceAPI):
|
|
||||||
@property
|
|
||||||
@abstractmethod
|
|
||||||
def my_id(self) -> ID:
|
|
||||||
...
|
|
||||||
|
|
||||||
@property
|
|
||||||
@abstractmethod
|
|
||||||
def protocols(self) -> tuple[TProtocol, ...]:
|
|
||||||
...
|
|
||||||
|
|
||||||
@property
|
|
||||||
@abstractmethod
|
|
||||||
def topic_ids(self) -> KeysView[str]:
|
|
||||||
...
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def set_topic_validator(
|
|
||||||
self, topic: str, validator: ValidatorFn, is_async_validator: bool
|
|
||||||
) -> None:
|
|
||||||
...
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def remove_topic_validator(self, topic: str) -> None:
|
|
||||||
...
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def wait_until_ready(self) -> None:
|
|
||||||
...
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def subscribe(self, topic_id: str) -> ISubscriptionAPI:
|
|
||||||
...
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def unsubscribe(self, topic_id: str) -> None:
|
|
||||||
...
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def publish(self, topic_id: str, data: bytes) -> None:
|
|
||||||
...
|
|
||||||
@ -6,6 +6,9 @@ import logging
|
|||||||
|
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IPubsubRouter,
|
||||||
|
)
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
TProtocol,
|
TProtocol,
|
||||||
)
|
)
|
||||||
@ -19,9 +22,6 @@ from libp2p.utils import (
|
|||||||
encode_varint_prefixed,
|
encode_varint_prefixed,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .abc import (
|
|
||||||
IPubsubRouter,
|
|
||||||
)
|
|
||||||
from .pb import (
|
from .pb import (
|
||||||
rpc_pb2,
|
rpc_pb2,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -17,6 +17,9 @@ from typing import (
|
|||||||
|
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IPubsubRouter,
|
||||||
|
)
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
TProtocol,
|
TProtocol,
|
||||||
)
|
)
|
||||||
@ -36,9 +39,6 @@ from libp2p.utils import (
|
|||||||
encode_varint_prefixed,
|
encode_varint_prefixed,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .abc import (
|
|
||||||
IPubsubRouter,
|
|
||||||
)
|
|
||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
NoPubsubAttached,
|
NoPubsubAttached,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -23,19 +23,25 @@ from lru import (
|
|||||||
)
|
)
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IHost,
|
||||||
|
INetStream,
|
||||||
|
IPubsub,
|
||||||
|
ISubscriptionAPI,
|
||||||
|
)
|
||||||
from libp2p.crypto.keys import (
|
from libp2p.crypto.keys import (
|
||||||
PrivateKey,
|
PrivateKey,
|
||||||
)
|
)
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
|
AsyncValidatorFn,
|
||||||
|
SyncValidatorFn,
|
||||||
TProtocol,
|
TProtocol,
|
||||||
|
ValidatorFn,
|
||||||
)
|
)
|
||||||
from libp2p.exceptions import (
|
from libp2p.exceptions import (
|
||||||
ParseError,
|
ParseError,
|
||||||
ValidationError,
|
ValidationError,
|
||||||
)
|
)
|
||||||
from libp2p.host.host_interface import (
|
|
||||||
IHost,
|
|
||||||
)
|
|
||||||
from libp2p.io.exceptions import (
|
from libp2p.io.exceptions import (
|
||||||
IncompleteReadError,
|
IncompleteReadError,
|
||||||
)
|
)
|
||||||
@ -47,9 +53,6 @@ from libp2p.network.stream.exceptions import (
|
|||||||
StreamEOF,
|
StreamEOF,
|
||||||
StreamReset,
|
StreamReset,
|
||||||
)
|
)
|
||||||
from libp2p.network.stream.net_stream_interface import (
|
|
||||||
INetStream,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
ID,
|
ID,
|
||||||
)
|
)
|
||||||
@ -61,10 +64,6 @@ from libp2p.utils import (
|
|||||||
read_varint_prefixed_bytes,
|
read_varint_prefixed_bytes,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .abc import (
|
|
||||||
IPubsub,
|
|
||||||
ISubscriptionAPI,
|
|
||||||
)
|
|
||||||
from .pb import (
|
from .pb import (
|
||||||
rpc_pb2,
|
rpc_pb2,
|
||||||
)
|
)
|
||||||
@ -74,11 +73,6 @@ from .pubsub_notifee import (
|
|||||||
from .subscription import (
|
from .subscription import (
|
||||||
TrioSubscriptionAPI,
|
TrioSubscriptionAPI,
|
||||||
)
|
)
|
||||||
from .typing import (
|
|
||||||
AsyncValidatorFn,
|
|
||||||
SyncValidatorFn,
|
|
||||||
ValidatorFn,
|
|
||||||
)
|
|
||||||
from .validators import (
|
from .validators import (
|
||||||
PUBSUB_SIGNING_PREFIX,
|
PUBSUB_SIGNING_PREFIX,
|
||||||
signature_validator,
|
signature_validator,
|
||||||
|
|||||||
@ -7,17 +7,11 @@ from multiaddr import (
|
|||||||
)
|
)
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
from libp2p.network.connection.net_connection_interface import (
|
from libp2p.abc import (
|
||||||
INetConn,
|
INetConn,
|
||||||
)
|
|
||||||
from libp2p.network.network_interface import (
|
|
||||||
INetwork,
|
|
||||||
)
|
|
||||||
from libp2p.network.notifee_interface import (
|
|
||||||
INotifee,
|
|
||||||
)
|
|
||||||
from libp2p.network.stream.net_stream_interface import (
|
|
||||||
INetStream,
|
INetStream,
|
||||||
|
INetwork,
|
||||||
|
INotifee,
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|||||||
@ -11,15 +11,16 @@ from typing import (
|
|||||||
|
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
from .abc import (
|
from libp2p.abc import (
|
||||||
ISubscriptionAPI,
|
ISubscriptionAPI,
|
||||||
)
|
)
|
||||||
|
from libp2p.custom_types import (
|
||||||
|
UnsubscribeFn,
|
||||||
|
)
|
||||||
|
|
||||||
from .pb import (
|
from .pb import (
|
||||||
rpc_pb2,
|
rpc_pb2,
|
||||||
)
|
)
|
||||||
from .typing import (
|
|
||||||
UnsubscribeFn,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class BaseSubscriptionAPI(ISubscriptionAPI):
|
class BaseSubscriptionAPI(ISubscriptionAPI):
|
||||||
|
|||||||
@ -1,21 +0,0 @@
|
|||||||
from collections.abc import (
|
|
||||||
Awaitable,
|
|
||||||
)
|
|
||||||
from typing import (
|
|
||||||
Callable,
|
|
||||||
Union,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.peer.id import (
|
|
||||||
ID,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .pb import (
|
|
||||||
rpc_pb2,
|
|
||||||
)
|
|
||||||
|
|
||||||
SyncValidatorFn = Callable[[ID, rpc_pb2.Message], bool]
|
|
||||||
AsyncValidatorFn = Callable[[ID, rpc_pb2.Message], Awaitable[bool]]
|
|
||||||
ValidatorFn = Union[SyncValidatorFn, AsyncValidatorFn]
|
|
||||||
|
|
||||||
UnsubscribeFn = Callable[[], Awaitable[None]]
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
from collections.abc import (
|
|
||||||
Iterable,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.peer.id import (
|
|
||||||
ID,
|
|
||||||
)
|
|
||||||
from libp2p.peer.peerinfo import (
|
|
||||||
PeerInfo,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class IContentRouting(ABC):
|
|
||||||
@abstractmethod
|
|
||||||
def provide(self, cid: bytes, announce: bool = True) -> None:
|
|
||||||
"""
|
|
||||||
Provide adds the given cid to the content routing system.
|
|
||||||
|
|
||||||
If announce is True, it also announces it, otherwise it is just
|
|
||||||
kept in the local accounting of which objects are being
|
|
||||||
provided.
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def find_provider_iter(self, cid: bytes, count: int) -> Iterable[PeerInfo]:
|
|
||||||
"""
|
|
||||||
Search for peers who are able to provide a given key returns an
|
|
||||||
iterator of peer.PeerInfo.
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class IPeerRouting(ABC):
|
|
||||||
@abstractmethod
|
|
||||||
async def find_peer(self, peer_id: ID) -> PeerInfo:
|
|
||||||
"""
|
|
||||||
Find specific Peer FindPeer searches for a peer with given peer_id,
|
|
||||||
returns a peer.PeerInfo with relevant addresses.
|
|
||||||
"""
|
|
||||||
@ -2,6 +2,9 @@ from typing import (
|
|||||||
Optional,
|
Optional,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
ISecureConn,
|
||||||
|
)
|
||||||
from libp2p.crypto.keys import (
|
from libp2p.crypto.keys import (
|
||||||
PrivateKey,
|
PrivateKey,
|
||||||
PublicKey,
|
PublicKey,
|
||||||
@ -9,9 +12,6 @@ from libp2p.crypto.keys import (
|
|||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
ID,
|
ID,
|
||||||
)
|
)
|
||||||
from libp2p.security.secure_conn_interface import (
|
|
||||||
ISecureConn,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class BaseSession(ISecureConn):
|
class BaseSession(ISecureConn):
|
||||||
|
|||||||
@ -3,15 +3,15 @@ from typing import (
|
|||||||
Callable,
|
Callable,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
ISecureTransport,
|
||||||
|
)
|
||||||
from libp2p.crypto.keys import (
|
from libp2p.crypto.keys import (
|
||||||
KeyPair,
|
KeyPair,
|
||||||
)
|
)
|
||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
ID,
|
ID,
|
||||||
)
|
)
|
||||||
from libp2p.security.secure_transport_interface import (
|
|
||||||
ISecureTransport,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def default_secure_bytes_provider(n: int) -> bytes:
|
def default_secure_bytes_provider(n: int) -> bytes:
|
||||||
|
|||||||
@ -1,3 +1,7 @@
|
|||||||
|
from libp2p.abc import (
|
||||||
|
IRawConnection,
|
||||||
|
ISecureConn,
|
||||||
|
)
|
||||||
from libp2p.crypto.exceptions import (
|
from libp2p.crypto.exceptions import (
|
||||||
MissingDeserializerError,
|
MissingDeserializerError,
|
||||||
)
|
)
|
||||||
@ -23,9 +27,6 @@ from libp2p.io.msgio import (
|
|||||||
from libp2p.network.connection.exceptions import (
|
from libp2p.network.connection.exceptions import (
|
||||||
RawConnError,
|
RawConnError,
|
||||||
)
|
)
|
||||||
from libp2p.network.connection.raw_connection_interface import (
|
|
||||||
IRawConnection,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
ID,
|
ID,
|
||||||
)
|
)
|
||||||
@ -38,9 +39,6 @@ from libp2p.security.base_transport import (
|
|||||||
from libp2p.security.exceptions import (
|
from libp2p.security.exceptions import (
|
||||||
HandshakeFailure,
|
HandshakeFailure,
|
||||||
)
|
)
|
||||||
from libp2p.security.secure_conn_interface import (
|
|
||||||
ISecureConn,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .pb import (
|
from .pb import (
|
||||||
plaintext_pb2,
|
plaintext_pb2,
|
||||||
|
|||||||
@ -4,6 +4,9 @@ from typing import (
|
|||||||
|
|
||||||
from noise.connection import NoiseConnection as NoiseState
|
from noise.connection import NoiseConnection as NoiseState
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IRawConnection,
|
||||||
|
)
|
||||||
from libp2p.io.abc import (
|
from libp2p.io.abc import (
|
||||||
EncryptedMsgReadWriter,
|
EncryptedMsgReadWriter,
|
||||||
MsgReadWriteCloser,
|
MsgReadWriteCloser,
|
||||||
@ -12,9 +15,6 @@ from libp2p.io.abc import (
|
|||||||
from libp2p.io.msgio import (
|
from libp2p.io.msgio import (
|
||||||
FixedSizeLenMsgReadWriter,
|
FixedSizeLenMsgReadWriter,
|
||||||
)
|
)
|
||||||
from libp2p.network.connection.raw_connection_interface import (
|
|
||||||
IRawConnection,
|
|
||||||
)
|
|
||||||
|
|
||||||
SIZE_NOISE_MESSAGE_LEN = 2
|
SIZE_NOISE_MESSAGE_LEN = 2
|
||||||
MAX_NOISE_MESSAGE_LEN = 2 ** (8 * SIZE_NOISE_MESSAGE_LEN) - 1
|
MAX_NOISE_MESSAGE_LEN = 2 ** (8 * SIZE_NOISE_MESSAGE_LEN) - 1
|
||||||
|
|||||||
@ -10,6 +10,10 @@ from noise.backends.default.keypairs import KeyPair as NoiseKeyPair
|
|||||||
from noise.connection import Keypair as NoiseKeypairEnum
|
from noise.connection import Keypair as NoiseKeypairEnum
|
||||||
from noise.connection import NoiseConnection as NoiseState
|
from noise.connection import NoiseConnection as NoiseState
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IRawConnection,
|
||||||
|
ISecureConn,
|
||||||
|
)
|
||||||
from libp2p.crypto.ed25519 import (
|
from libp2p.crypto.ed25519 import (
|
||||||
Ed25519PublicKey,
|
Ed25519PublicKey,
|
||||||
)
|
)
|
||||||
@ -17,15 +21,9 @@ from libp2p.crypto.keys import (
|
|||||||
PrivateKey,
|
PrivateKey,
|
||||||
PublicKey,
|
PublicKey,
|
||||||
)
|
)
|
||||||
from libp2p.network.connection.raw_connection_interface import (
|
|
||||||
IRawConnection,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
ID,
|
ID,
|
||||||
)
|
)
|
||||||
from libp2p.security.secure_conn_interface import (
|
|
||||||
ISecureConn,
|
|
||||||
)
|
|
||||||
from libp2p.security.secure_session import (
|
from libp2p.security.secure_session import (
|
||||||
SecureSession,
|
SecureSession,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,3 +1,8 @@
|
|||||||
|
from libp2p.abc import (
|
||||||
|
IRawConnection,
|
||||||
|
ISecureConn,
|
||||||
|
ISecureTransport,
|
||||||
|
)
|
||||||
from libp2p.crypto.keys import (
|
from libp2p.crypto.keys import (
|
||||||
KeyPair,
|
KeyPair,
|
||||||
PrivateKey,
|
PrivateKey,
|
||||||
@ -5,18 +10,9 @@ from libp2p.crypto.keys import (
|
|||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
TProtocol,
|
TProtocol,
|
||||||
)
|
)
|
||||||
from libp2p.network.connection.raw_connection_interface import (
|
|
||||||
IRawConnection,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
ID,
|
ID,
|
||||||
)
|
)
|
||||||
from libp2p.security.secure_conn_interface import (
|
|
||||||
ISecureConn,
|
|
||||||
)
|
|
||||||
from libp2p.security.secure_transport_interface import (
|
|
||||||
ISecureTransport,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .patterns import (
|
from .patterns import (
|
||||||
IPattern,
|
IPattern,
|
||||||
|
|||||||
@ -8,6 +8,10 @@ from typing import (
|
|||||||
|
|
||||||
import multihash
|
import multihash
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IRawConnection,
|
||||||
|
ISecureConn,
|
||||||
|
)
|
||||||
from libp2p.crypto.authenticated_encryption import (
|
from libp2p.crypto.authenticated_encryption import (
|
||||||
EncryptionParameters as AuthenticatedEncryptionParameters,
|
EncryptionParameters as AuthenticatedEncryptionParameters,
|
||||||
)
|
)
|
||||||
@ -47,16 +51,10 @@ from libp2p.io.exceptions import (
|
|||||||
from libp2p.io.msgio import (
|
from libp2p.io.msgio import (
|
||||||
FixedSizeLenMsgReadWriter,
|
FixedSizeLenMsgReadWriter,
|
||||||
)
|
)
|
||||||
from libp2p.network.connection.raw_connection_interface import (
|
|
||||||
IRawConnection,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import ID as PeerID
|
from libp2p.peer.id import ID as PeerID
|
||||||
from libp2p.security.base_transport import (
|
from libp2p.security.base_transport import (
|
||||||
BaseSecureTransport,
|
BaseSecureTransport,
|
||||||
)
|
)
|
||||||
from libp2p.security.secure_conn_interface import (
|
|
||||||
ISecureConn,
|
|
||||||
)
|
|
||||||
from libp2p.security.secure_session import (
|
from libp2p.security.secure_session import (
|
||||||
SecureSession,
|
SecureSession,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,44 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.crypto.keys import (
|
|
||||||
PrivateKey,
|
|
||||||
PublicKey,
|
|
||||||
)
|
|
||||||
from libp2p.network.connection.raw_connection_interface import (
|
|
||||||
IRawConnection,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import (
|
|
||||||
ID,
|
|
||||||
)
|
|
||||||
|
|
||||||
"""
|
|
||||||
Represents a secured connection object, which includes a connection and details about
|
|
||||||
the security involved in the secured connection
|
|
||||||
|
|
||||||
Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interface.go
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractSecureConn(ABC):
|
|
||||||
@abstractmethod
|
|
||||||
def get_local_peer(self) -> ID:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_local_private_key(self) -> PrivateKey:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_remote_peer(self) -> ID:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_remote_public_key(self) -> PublicKey:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class ISecureConn(AbstractSecureConn, IRawConnection):
|
|
||||||
pass
|
|
||||||
@ -1,42 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.network.connection.raw_connection_interface import (
|
|
||||||
IRawConnection,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import (
|
|
||||||
ID,
|
|
||||||
)
|
|
||||||
from libp2p.security.secure_conn_interface import (
|
|
||||||
ISecureConn,
|
|
||||||
)
|
|
||||||
|
|
||||||
"""
|
|
||||||
Transport that is used to secure a connection. This transport is
|
|
||||||
chosen by a security transport multistream module.
|
|
||||||
|
|
||||||
Relevant go repo: https://github.com/libp2p/go-conn-security/blob/master/interface.go
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class ISecureTransport(ABC):
|
|
||||||
@abstractmethod
|
|
||||||
async def secure_inbound(self, conn: IRawConnection) -> ISecureConn:
|
|
||||||
"""
|
|
||||||
Secure the connection, either locally or by communicating with opposing
|
|
||||||
node via conn, for an inbound connection (i.e. we are not the
|
|
||||||
initiator)
|
|
||||||
|
|
||||||
:return: secure connection object (that implements secure_conn_interface)
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def secure_outbound(self, conn: IRawConnection, peer_id: ID) -> ISecureConn:
|
|
||||||
"""
|
|
||||||
Secure the connection, either locally or by communicating with opposing
|
|
||||||
node via conn, for an inbound connection (i.e. we are the initiator)
|
|
||||||
|
|
||||||
:return: secure connection object (that implements secure_conn_interface)
|
|
||||||
"""
|
|
||||||
@ -5,11 +5,14 @@ from collections import (
|
|||||||
OrderedDict,
|
OrderedDict,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IRawConnection,
|
||||||
|
ISecureConn,
|
||||||
|
ISecureTransport,
|
||||||
|
)
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
TProtocol,
|
TProtocol,
|
||||||
)
|
TSecurityOptions,
|
||||||
from libp2p.network.connection.raw_connection_interface import (
|
|
||||||
IRawConnection,
|
|
||||||
)
|
)
|
||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
ID,
|
ID,
|
||||||
@ -23,15 +26,6 @@ from libp2p.protocol_muxer.multiselect_client import (
|
|||||||
from libp2p.protocol_muxer.multiselect_communicator import (
|
from libp2p.protocol_muxer.multiselect_communicator import (
|
||||||
MultiselectCommunicator,
|
MultiselectCommunicator,
|
||||||
)
|
)
|
||||||
from libp2p.security.secure_conn_interface import (
|
|
||||||
ISecureConn,
|
|
||||||
)
|
|
||||||
from libp2p.security.secure_transport_interface import (
|
|
||||||
ISecureTransport,
|
|
||||||
)
|
|
||||||
from libp2p.transport.typing import (
|
|
||||||
TSecurityOptions,
|
|
||||||
)
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Represents a secured connection object, which includes a connection and details about
|
Represents a secured connection object, which includes a connection and details about
|
||||||
|
|||||||
@ -1,85 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
|
|
||||||
import trio
|
|
||||||
|
|
||||||
from libp2p.io.abc import (
|
|
||||||
ReadWriteCloser,
|
|
||||||
)
|
|
||||||
from libp2p.peer.id import (
|
|
||||||
ID,
|
|
||||||
)
|
|
||||||
from libp2p.security.secure_conn_interface import (
|
|
||||||
ISecureConn,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class IMuxedConn(ABC):
|
|
||||||
"""
|
|
||||||
reference: https://github.com/libp2p/go-stream-muxer/blob/master/muxer.go
|
|
||||||
"""
|
|
||||||
|
|
||||||
peer_id: ID
|
|
||||||
event_started: trio.Event
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def __init__(self, conn: ISecureConn, peer_id: ID) -> None:
|
|
||||||
"""
|
|
||||||
Create a new muxed connection.
|
|
||||||
|
|
||||||
:param conn: an instance of secured connection
|
|
||||||
for new muxed streams
|
|
||||||
:param peer_id: peer_id of peer the connection is to
|
|
||||||
"""
|
|
||||||
|
|
||||||
@property
|
|
||||||
@abstractmethod
|
|
||||||
def is_initiator(self) -> bool:
|
|
||||||
"""If this connection is the initiator."""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def start(self) -> None:
|
|
||||||
"""Start the multiplexer."""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def close(self) -> None:
|
|
||||||
"""Close connection."""
|
|
||||||
|
|
||||||
@property
|
|
||||||
@abstractmethod
|
|
||||||
def is_closed(self) -> bool:
|
|
||||||
"""
|
|
||||||
Check connection is fully closed.
|
|
||||||
|
|
||||||
:return: true if successful
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def open_stream(self) -> "IMuxedStream":
|
|
||||||
"""
|
|
||||||
Create a new muxed_stream.
|
|
||||||
|
|
||||||
:return: a new ``IMuxedStream`` stream
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def accept_stream(self) -> "IMuxedStream":
|
|
||||||
"""Accept a muxed stream opened by the other end."""
|
|
||||||
|
|
||||||
|
|
||||||
class IMuxedStream(ReadWriteCloser):
|
|
||||||
muxed_conn: IMuxedConn
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def reset(self) -> None:
|
|
||||||
"""Close both ends of the stream tells this remote side to hang up."""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def set_deadline(self, ttl: int) -> bool:
|
|
||||||
"""
|
|
||||||
Set deadline for muxed stream.
|
|
||||||
|
|
||||||
:return: a new stream
|
|
||||||
"""
|
|
||||||
@ -5,6 +5,11 @@ from typing import (
|
|||||||
|
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IMuxedConn,
|
||||||
|
IMuxedStream,
|
||||||
|
ISecureConn,
|
||||||
|
)
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
TProtocol,
|
TProtocol,
|
||||||
)
|
)
|
||||||
@ -20,13 +25,6 @@ from libp2p.network.connection.exceptions import (
|
|||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
ID,
|
ID,
|
||||||
)
|
)
|
||||||
from libp2p.security.secure_conn_interface import (
|
|
||||||
ISecureConn,
|
|
||||||
)
|
|
||||||
from libp2p.stream_muxer.abc import (
|
|
||||||
IMuxedConn,
|
|
||||||
IMuxedStream,
|
|
||||||
)
|
|
||||||
from libp2p.utils import (
|
from libp2p.utils import (
|
||||||
decode_uvarint_from_stream,
|
decode_uvarint_from_stream,
|
||||||
encode_uvarint,
|
encode_uvarint,
|
||||||
|
|||||||
@ -4,7 +4,7 @@ from typing import (
|
|||||||
|
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
from libp2p.stream_muxer.abc import (
|
from libp2p.abc import (
|
||||||
IMuxedStream,
|
IMuxedStream,
|
||||||
)
|
)
|
||||||
from libp2p.stream_muxer.exceptions import (
|
from libp2p.stream_muxer.exceptions import (
|
||||||
|
|||||||
@ -2,11 +2,15 @@ from collections import (
|
|||||||
OrderedDict,
|
OrderedDict,
|
||||||
)
|
)
|
||||||
|
|
||||||
from libp2p.custom_types import (
|
from libp2p.abc import (
|
||||||
TProtocol,
|
IMuxedConn,
|
||||||
)
|
|
||||||
from libp2p.network.connection.raw_connection_interface import (
|
|
||||||
IRawConnection,
|
IRawConnection,
|
||||||
|
ISecureConn,
|
||||||
|
)
|
||||||
|
from libp2p.custom_types import (
|
||||||
|
TMuxerClass,
|
||||||
|
TMuxerOptions,
|
||||||
|
TProtocol,
|
||||||
)
|
)
|
||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
ID,
|
ID,
|
||||||
@ -20,17 +24,6 @@ from libp2p.protocol_muxer.multiselect_client import (
|
|||||||
from libp2p.protocol_muxer.multiselect_communicator import (
|
from libp2p.protocol_muxer.multiselect_communicator import (
|
||||||
MultiselectCommunicator,
|
MultiselectCommunicator,
|
||||||
)
|
)
|
||||||
from libp2p.security.secure_conn_interface import (
|
|
||||||
ISecureConn,
|
|
||||||
)
|
|
||||||
from libp2p.transport.typing import (
|
|
||||||
TMuxerClass,
|
|
||||||
TMuxerOptions,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .abc import (
|
|
||||||
IMuxedConn,
|
|
||||||
)
|
|
||||||
|
|
||||||
# FIXME: add negotiate timeout to `MuxerMultistream`
|
# FIXME: add negotiate timeout to `MuxerMultistream`
|
||||||
DEFAULT_NEGOTIATE_TIMEOUT = 60
|
DEFAULT_NEGOTIATE_TIMEOUT = 60
|
||||||
|
|||||||
@ -22,6 +22,15 @@ from libp2p import (
|
|||||||
generate_new_rsa_identity,
|
generate_new_rsa_identity,
|
||||||
generate_peer_id_from,
|
generate_peer_id_from,
|
||||||
)
|
)
|
||||||
|
from libp2p.abc import (
|
||||||
|
IHost,
|
||||||
|
INetStream,
|
||||||
|
IPeerRouting,
|
||||||
|
IPubsubRouter,
|
||||||
|
IRawConnection,
|
||||||
|
ISecureConn,
|
||||||
|
ISecureTransport,
|
||||||
|
)
|
||||||
from libp2p.crypto.ed25519 import create_new_key_pair as create_ed25519_key_pair
|
from libp2p.crypto.ed25519 import create_new_key_pair as create_ed25519_key_pair
|
||||||
from libp2p.crypto.keys import (
|
from libp2p.crypto.keys import (
|
||||||
KeyPair,
|
KeyPair,
|
||||||
@ -29,14 +38,13 @@ from libp2p.crypto.keys import (
|
|||||||
)
|
)
|
||||||
from libp2p.crypto.secp256k1 import create_new_key_pair as create_secp256k1_key_pair
|
from libp2p.crypto.secp256k1 import create_new_key_pair as create_secp256k1_key_pair
|
||||||
from libp2p.custom_types import (
|
from libp2p.custom_types import (
|
||||||
|
TMuxerOptions,
|
||||||
TProtocol,
|
TProtocol,
|
||||||
|
TSecurityOptions,
|
||||||
)
|
)
|
||||||
from libp2p.host.basic_host import (
|
from libp2p.host.basic_host import (
|
||||||
BasicHost,
|
BasicHost,
|
||||||
)
|
)
|
||||||
from libp2p.host.host_interface import (
|
|
||||||
IHost,
|
|
||||||
)
|
|
||||||
from libp2p.host.routed_host import (
|
from libp2p.host.routed_host import (
|
||||||
RoutedHost,
|
RoutedHost,
|
||||||
)
|
)
|
||||||
@ -46,15 +54,9 @@ from libp2p.io.abc import (
|
|||||||
from libp2p.network.connection.raw_connection import (
|
from libp2p.network.connection.raw_connection import (
|
||||||
RawConnection,
|
RawConnection,
|
||||||
)
|
)
|
||||||
from libp2p.network.connection.raw_connection_interface import (
|
|
||||||
IRawConnection,
|
|
||||||
)
|
|
||||||
from libp2p.network.connection.swarm_connection import (
|
from libp2p.network.connection.swarm_connection import (
|
||||||
SwarmConn,
|
SwarmConn,
|
||||||
)
|
)
|
||||||
from libp2p.network.stream.net_stream_interface import (
|
|
||||||
INetStream,
|
|
||||||
)
|
|
||||||
from libp2p.network.swarm import (
|
from libp2p.network.swarm import (
|
||||||
Swarm,
|
Swarm,
|
||||||
)
|
)
|
||||||
@ -67,9 +69,6 @@ from libp2p.peer.peerinfo import (
|
|||||||
from libp2p.peer.peerstore import (
|
from libp2p.peer.peerstore import (
|
||||||
PeerStore,
|
PeerStore,
|
||||||
)
|
)
|
||||||
from libp2p.pubsub.abc import (
|
|
||||||
IPubsubRouter,
|
|
||||||
)
|
|
||||||
from libp2p.pubsub.floodsub import (
|
from libp2p.pubsub.floodsub import (
|
||||||
FloodSub,
|
FloodSub,
|
||||||
)
|
)
|
||||||
@ -81,9 +80,6 @@ from libp2p.pubsub.pubsub import (
|
|||||||
Pubsub,
|
Pubsub,
|
||||||
get_peer_and_seqno_msg_id,
|
get_peer_and_seqno_msg_id,
|
||||||
)
|
)
|
||||||
from libp2p.routing.interfaces import (
|
|
||||||
IPeerRouting,
|
|
||||||
)
|
|
||||||
from libp2p.security.insecure.transport import (
|
from libp2p.security.insecure.transport import (
|
||||||
PLAINTEXT_PROTOCOL_ID,
|
PLAINTEXT_PROTOCOL_ID,
|
||||||
InsecureTransport,
|
InsecureTransport,
|
||||||
@ -95,12 +91,6 @@ from libp2p.security.noise.messages import (
|
|||||||
from libp2p.security.noise.transport import PROTOCOL_ID as NOISE_PROTOCOL_ID
|
from libp2p.security.noise.transport import PROTOCOL_ID as NOISE_PROTOCOL_ID
|
||||||
from libp2p.security.noise.transport import Transport as NoiseTransport
|
from libp2p.security.noise.transport import Transport as NoiseTransport
|
||||||
import libp2p.security.secio.transport as secio
|
import libp2p.security.secio.transport as secio
|
||||||
from libp2p.security.secure_conn_interface import (
|
|
||||||
ISecureConn,
|
|
||||||
)
|
|
||||||
from libp2p.security.secure_transport_interface import (
|
|
||||||
ISecureTransport,
|
|
||||||
)
|
|
||||||
from libp2p.stream_muxer.mplex.mplex import (
|
from libp2p.stream_muxer.mplex.mplex import (
|
||||||
MPLEX_PROTOCOL_ID,
|
MPLEX_PROTOCOL_ID,
|
||||||
Mplex,
|
Mplex,
|
||||||
@ -117,10 +107,6 @@ from libp2p.tools.constants import (
|
|||||||
from libp2p.transport.tcp.tcp import (
|
from libp2p.transport.tcp.tcp import (
|
||||||
TCP,
|
TCP,
|
||||||
)
|
)
|
||||||
from libp2p.transport.typing import (
|
|
||||||
TMuxerOptions,
|
|
||||||
TSecurityOptions,
|
|
||||||
)
|
|
||||||
from libp2p.transport.upgrader import (
|
from libp2p.transport.upgrader import (
|
||||||
TransportUpgrader,
|
TransportUpgrader,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -6,7 +6,7 @@ from contextlib import (
|
|||||||
asynccontextmanager,
|
asynccontextmanager,
|
||||||
)
|
)
|
||||||
|
|
||||||
from libp2p.host.host_interface import (
|
from libp2p.abc import (
|
||||||
IHost,
|
IHost,
|
||||||
)
|
)
|
||||||
from libp2p.pubsub.pubsub import (
|
from libp2p.pubsub.pubsub import (
|
||||||
|
|||||||
@ -2,7 +2,7 @@ from collections.abc import (
|
|||||||
Sequence,
|
Sequence,
|
||||||
)
|
)
|
||||||
|
|
||||||
from libp2p.host.host_interface import (
|
from libp2p.abc import (
|
||||||
IHost,
|
IHost,
|
||||||
)
|
)
|
||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
|
|||||||
@ -5,15 +5,13 @@ from typing import (
|
|||||||
Callable,
|
Callable,
|
||||||
)
|
)
|
||||||
|
|
||||||
from libp2p.host.host_interface import (
|
from libp2p.abc import (
|
||||||
IHost,
|
IHost,
|
||||||
|
INetStream,
|
||||||
)
|
)
|
||||||
from libp2p.network.stream.exceptions import (
|
from libp2p.network.stream.exceptions import (
|
||||||
StreamError,
|
StreamError,
|
||||||
)
|
)
|
||||||
from libp2p.network.stream.net_stream_interface import (
|
|
||||||
INetStream,
|
|
||||||
)
|
|
||||||
from libp2p.network.swarm import (
|
from libp2p.network.swarm import (
|
||||||
Swarm,
|
Swarm,
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,32 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
|
|
||||||
from multiaddr import (
|
|
||||||
Multiaddr,
|
|
||||||
)
|
|
||||||
import trio
|
|
||||||
|
|
||||||
|
|
||||||
class IListener(ABC):
|
|
||||||
@abstractmethod
|
|
||||||
async def listen(self, maddr: Multiaddr, nursery: trio.Nursery) -> bool:
|
|
||||||
"""
|
|
||||||
Put listener in listening mode and wait for incoming connections.
|
|
||||||
|
|
||||||
:param maddr: multiaddr of peer
|
|
||||||
:return: return True if successful
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def get_addrs(self) -> tuple[Multiaddr, ...]:
|
|
||||||
"""
|
|
||||||
Retrieve list of addresses the listener is listening on.
|
|
||||||
|
|
||||||
:return: return list of addrs
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
async def close(self) -> None:
|
|
||||||
...
|
|
||||||
@ -15,27 +15,23 @@ from trio_typing import (
|
|||||||
TaskStatus,
|
TaskStatus,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from libp2p.abc import (
|
||||||
|
IListener,
|
||||||
|
IRawConnection,
|
||||||
|
ITransport,
|
||||||
|
)
|
||||||
|
from libp2p.custom_types import (
|
||||||
|
THandler,
|
||||||
|
)
|
||||||
from libp2p.io.trio import (
|
from libp2p.io.trio import (
|
||||||
TrioTCPStream,
|
TrioTCPStream,
|
||||||
)
|
)
|
||||||
from libp2p.network.connection.raw_connection import (
|
from libp2p.network.connection.raw_connection import (
|
||||||
RawConnection,
|
RawConnection,
|
||||||
)
|
)
|
||||||
from libp2p.network.connection.raw_connection_interface import (
|
|
||||||
IRawConnection,
|
|
||||||
)
|
|
||||||
from libp2p.transport.exceptions import (
|
from libp2p.transport.exceptions import (
|
||||||
OpenConnectionError,
|
OpenConnectionError,
|
||||||
)
|
)
|
||||||
from libp2p.transport.listener_interface import (
|
|
||||||
IListener,
|
|
||||||
)
|
|
||||||
from libp2p.transport.transport_interface import (
|
|
||||||
ITransport,
|
|
||||||
)
|
|
||||||
from libp2p.transport.typing import (
|
|
||||||
THandler,
|
|
||||||
)
|
|
||||||
|
|
||||||
logger = logging.getLogger("libp2p.transport.tcp")
|
logger = logging.getLogger("libp2p.transport.tcp")
|
||||||
|
|
||||||
|
|||||||
@ -1,41 +0,0 @@
|
|||||||
from abc import (
|
|
||||||
ABC,
|
|
||||||
abstractmethod,
|
|
||||||
)
|
|
||||||
|
|
||||||
from multiaddr import (
|
|
||||||
Multiaddr,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.network.connection.raw_connection_interface import (
|
|
||||||
IRawConnection,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .listener_interface import (
|
|
||||||
IListener,
|
|
||||||
)
|
|
||||||
from .typing import (
|
|
||||||
THandler,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class ITransport(ABC):
|
|
||||||
@abstractmethod
|
|
||||||
async def dial(self, maddr: Multiaddr) -> IRawConnection:
|
|
||||||
"""
|
|
||||||
Dial a transport to peer listening on multiaddr.
|
|
||||||
|
|
||||||
:param multiaddr: multiaddr of peer
|
|
||||||
:param self_id: peer_id of the dialer (to send to receiver)
|
|
||||||
:return: list of multiaddrs
|
|
||||||
"""
|
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def create_listener(self, handler_function: THandler) -> IListener:
|
|
||||||
"""
|
|
||||||
Create listener on transport.
|
|
||||||
|
|
||||||
:param handler_function: a function called when a new conntion is received
|
|
||||||
that takes a connection as argument which implements interface-connection
|
|
||||||
:return: a listener object that implements listener_interface.py
|
|
||||||
"""
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
from collections.abc import (
|
|
||||||
Awaitable,
|
|
||||||
Mapping,
|
|
||||||
)
|
|
||||||
from typing import (
|
|
||||||
Callable,
|
|
||||||
)
|
|
||||||
|
|
||||||
from libp2p.custom_types import (
|
|
||||||
TProtocol,
|
|
||||||
)
|
|
||||||
from libp2p.io.abc import (
|
|
||||||
ReadWriteCloser,
|
|
||||||
)
|
|
||||||
from libp2p.security.secure_transport_interface import (
|
|
||||||
ISecureTransport,
|
|
||||||
)
|
|
||||||
from libp2p.stream_muxer.abc import (
|
|
||||||
IMuxedConn,
|
|
||||||
)
|
|
||||||
|
|
||||||
THandler = Callable[[ReadWriteCloser], Awaitable[None]]
|
|
||||||
TSecurityOptions = Mapping[TProtocol, ISecureTransport]
|
|
||||||
TMuxerClass = type[IMuxedConn]
|
|
||||||
TMuxerOptions = Mapping[TProtocol, TMuxerClass]
|
|
||||||
@ -1,5 +1,13 @@
|
|||||||
from libp2p.network.connection.raw_connection_interface import (
|
from libp2p.abc import (
|
||||||
|
IListener,
|
||||||
|
IMuxedConn,
|
||||||
IRawConnection,
|
IRawConnection,
|
||||||
|
ISecureConn,
|
||||||
|
ITransport,
|
||||||
|
)
|
||||||
|
from libp2p.custom_types import (
|
||||||
|
TMuxerOptions,
|
||||||
|
TSecurityOptions,
|
||||||
)
|
)
|
||||||
from libp2p.peer.id import (
|
from libp2p.peer.id import (
|
||||||
ID,
|
ID,
|
||||||
@ -11,15 +19,9 @@ from libp2p.protocol_muxer.exceptions import (
|
|||||||
from libp2p.security.exceptions import (
|
from libp2p.security.exceptions import (
|
||||||
HandshakeFailure,
|
HandshakeFailure,
|
||||||
)
|
)
|
||||||
from libp2p.security.secure_conn_interface import (
|
|
||||||
ISecureConn,
|
|
||||||
)
|
|
||||||
from libp2p.security.security_multistream import (
|
from libp2p.security.security_multistream import (
|
||||||
SecurityMultistream,
|
SecurityMultistream,
|
||||||
)
|
)
|
||||||
from libp2p.stream_muxer.abc import (
|
|
||||||
IMuxedConn,
|
|
||||||
)
|
|
||||||
from libp2p.stream_muxer.muxer_multistream import (
|
from libp2p.stream_muxer.muxer_multistream import (
|
||||||
MuxerMultistream,
|
MuxerMultistream,
|
||||||
)
|
)
|
||||||
@ -27,17 +29,6 @@ from libp2p.transport.exceptions import (
|
|||||||
MuxerUpgradeFailure,
|
MuxerUpgradeFailure,
|
||||||
SecurityUpgradeFailure,
|
SecurityUpgradeFailure,
|
||||||
)
|
)
|
||||||
from libp2p.transport.typing import (
|
|
||||||
TMuxerOptions,
|
|
||||||
TSecurityOptions,
|
|
||||||
)
|
|
||||||
|
|
||||||
from .listener_interface import (
|
|
||||||
IListener,
|
|
||||||
)
|
|
||||||
from .transport_interface import (
|
|
||||||
ITransport,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class TransportUpgrader:
|
class TransportUpgrader:
|
||||||
|
|||||||
1
newsfragments/228.internal.rst
Normal file
1
newsfragments/228.internal.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
moved all interfaces to ``libp2p.abc`` along with all libp2p custom types to ``libp2p.custom_types``.
|
||||||
@ -13,7 +13,7 @@ import enum
|
|||||||
import pytest
|
import pytest
|
||||||
import trio
|
import trio
|
||||||
|
|
||||||
from libp2p.network.notifee_interface import (
|
from libp2p.abc import (
|
||||||
INotifee,
|
INotifee,
|
||||||
)
|
)
|
||||||
from libp2p.tools.async_service import (
|
from libp2p.tools.async_service import (
|
||||||
|
|||||||
Reference in New Issue
Block a user