mirror of https://github.com/libp2p/py-libp2p.git
Alexander Koshkin
6 years ago
69 changed files with 132 additions and 100 deletions
@ -0,0 +1,38 @@ |
|||
from Crypto.PublicKey import RSA |
|||
|
|||
import multiaddr |
|||
|
|||
from .peer.peerstore import PeerStore |
|||
from .peer.id import id_from_public_key |
|||
from .network.swarm import Swarm |
|||
from .host.basic_host import BasicHost |
|||
from .transport.upgrader import TransportUpgrader |
|||
from .transport.tcp.tcp import TCP |
|||
|
|||
|
|||
async def new_node( |
|||
id_opt=None, transport_opt=None, |
|||
muxer_opt=None, sec_opt=None, peerstore=None): |
|||
|
|||
if id_opt is None: |
|||
new_key = RSA.generate(2048, e=65537) |
|||
id_opt = id_from_public_key(new_key.publickey()) |
|||
# private_key = new_key.exportKey("PEM") |
|||
|
|||
transport_opt = transport_opt or ["/ip4/127.0.0.1/tcp/8001"] |
|||
transport_opt = [multiaddr.Multiaddr(t) for t in transport_opt] |
|||
muxer_opt = muxer_opt or ["mplex/6.7.0"] |
|||
sec_opt = sec_opt or ["secio"] |
|||
peerstore = peerstore or PeerStore() |
|||
|
|||
upgrader = TransportUpgrader(sec_opt, transport_opt) |
|||
swarm = Swarm(id_opt, peerstore, upgrader) |
|||
tcp = TCP() |
|||
swarm.add_transport(tcp) |
|||
await swarm.listen(transport_opt[0]) |
|||
|
|||
# TODO enable support for other host type |
|||
# TODO routing unimplemented |
|||
host = BasicHost(swarm) |
|||
|
|||
return host |
@ -1,35 +0,0 @@ |
|||
from Crypto.PublicKey import RSA |
|||
import multiaddr |
|||
from peer.peerstore import PeerStore |
|||
from peer.id import id_from_public_key |
|||
from network.swarm import Swarm |
|||
from host.basic_host import BasicHost |
|||
from transport.upgrader import TransportUpgrader |
|||
from transport.tcp.tcp import TCP |
|||
|
|||
|
|||
async def new_node(id_opt=None, transport_opt=None, \ |
|||
muxer_opt=None, sec_opt=None, peerstore=None): |
|||
|
|||
if id_opt is None: |
|||
new_key = RSA.generate(2048, e=65537) |
|||
id_opt = id_from_public_key(new_key.publickey()) |
|||
# private_key = new_key.exportKey("PEM") |
|||
|
|||
transport_opt = transport_opt or ["/ip4/127.0.0.1/tcp/8001"] |
|||
transport_opt = [multiaddr.Multiaddr(t) for t in transport_opt] |
|||
muxer_opt = muxer_opt or ["mplex/6.7.0"] |
|||
sec_opt = sec_opt or ["secio"] |
|||
peerstore = peerstore or PeerStore() |
|||
|
|||
upgrader = TransportUpgrader(sec_opt, transport_opt) |
|||
swarm = Swarm(id_opt, peerstore, upgrader) |
|||
tcp = TCP() |
|||
swarm.add_transport(tcp) |
|||
await swarm.listen(transport_opt[0]) |
|||
|
|||
# TODO enable support for other host type |
|||
# TODO routing unimplemented |
|||
host = BasicHost(swarm) |
|||
|
|||
return host |
@ -1,5 +1,6 @@ |
|||
from abc import ABC, abstractmethod |
|||
|
|||
|
|||
class INetStream(ABC): |
|||
|
|||
@abstractmethod |
@ -1,5 +1,7 @@ |
|||
from protocol_muxer.multiselect_client import MultiselectClient |
|||
from protocol_muxer.multiselect import Multiselect |
|||
from libp2p.protocol_muxer.multiselect_client import MultiselectClient |
|||
from libp2p.protocol_muxer.multiselect import Multiselect |
|||
|
|||
|
|||
from .network_interface import INetwork |
|||
from .stream.net_stream import NetStream |
|||
from .connection.raw_connection import RawConnection |
@ -1,5 +1,6 @@ |
|||
from abc import ABC, abstractmethod |
|||
|
|||
|
|||
class IPeerData(ABC): |
|||
|
|||
@abstractmethod |
@ -1,11 +1,12 @@ |
|||
import multiaddr |
|||
import multiaddr.util |
|||
from peer.id import id_b58_decode |
|||
from peer.peerdata import PeerData |
|||
|
|||
from .id import id_b58_decode |
|||
from .peerdata import PeerData |
|||
|
|||
|
|||
class PeerInfo: |
|||
# pylint: disable=too-few-public-methods |
|||
# pylint: disable=too-few-public-methods |
|||
def __init__(self, peer_id, peer_data): |
|||
self.peer_id = peer_id |
|||
self.addrs = peer_data.get_addrs() |
@ -1,7 +1,9 @@ |
|||
from abc import abstractmethod |
|||
|
|||
from .addrbook_interface import IAddrBook |
|||
from .peermetadata_interface import IPeerMetadata |
|||
|
|||
|
|||
class IPeerStore(IAddrBook, IPeerMetadata): |
|||
|
|||
def __init__(self): |
@ -1,5 +1,6 @@ |
|||
from abc import ABC, abstractmethod |
|||
|
|||
|
|||
class IMultiselectClient(ABC): |
|||
""" |
|||
Client for communicating with receiver's multiselect |
@ -1,12 +1,13 @@ |
|||
from .multiselect_communicator_interface import IMultiselectCommunicator |
|||
|
|||
|
|||
class MultiselectCommunicator(IMultiselectCommunicator): |
|||
""" |
|||
Communicator helper class that ensures both the client |
|||
and multistream module will follow the same multistream protocol, |
|||
which is necessary for them to work |
|||
""" |
|||
|
|||
|
|||
def __init__(self, stream): |
|||
self.stream = stream |
|||
|
@ -1,5 +1,6 @@ |
|||
from abc import ABC, abstractmethod |
|||
|
|||
|
|||
class IMultiselectCommunicator(ABC): |
|||
""" |
|||
Communicator helper class that ensures both the client |
@ -1,5 +1,6 @@ |
|||
from abc import ABC, abstractmethod |
|||
|
|||
|
|||
class IMultiselectMuxer(ABC): |
|||
""" |
|||
Multiselect module that is responsible for responding to |
@ -1,4 +1,5 @@ |
|||
import asyncio |
|||
|
|||
from .utils import encode_uvarint, decode_uvarint_from_stream |
|||
from .mplex_stream import MplexStream |
|||
from ..muxed_connection_interface import IMuxedConn |
@ -1,4 +1,5 @@ |
|||
import asyncio |
|||
|
|||
from .constants import HEADER_TAGS |
|||
from ..muxed_stream_interface import IMuxedStream |
|||
|
@ -1,5 +1,6 @@ |
|||
from abc import ABC, abstractmethod |
|||
|
|||
|
|||
class IMuxedStream(ABC): |
|||
|
|||
@abstractmethod |
@ -1,7 +1,7 @@ |
|||
from stream_muxer.mplex.mplex import Mplex |
|||
from libp2p.stream_muxer.mplex.mplex import Mplex |
|||
|
|||
|
|||
class TransportUpgrader(): |
|||
class TransportUpgrader: |
|||
# pylint: disable=no-self-use |
|||
|
|||
def __init__(self, secOpt, muxerOpt): |
Loading…
Reference in new issue