py-libp2p/libp2p/libp2p.py

35 lines
934 B
Python
Raw Normal View History

2018-11-11 22:56:44 +08:00
from .config import Config
from ..peer.peerstore import PeerStore
2018-11-11 23:43:03 +08:00
from ..network.swarm import Swarm
from ..host.basic_host import BasicHost
from ..transport.upgrader import TransportUpgrader
2018-11-11 22:56:44 +08:00
class Libp2p(object):
def __init__(self, idOpt, \
transportOpt = ["/ip4/0.0.0.0/tcp/0"], \
muxerOpt = ["mplex/6.7.0"], \
secOpt = ["secio"], \
2018-11-11 23:43:03 +08:00
peerstore = PeerStore()):
2018-11-11 22:56:44 +08:00
if idOpt:
self.idOpt = idOpt
else:
# TODO generate RSA public key pair
2018-11-11 23:43:03 +08:00
self.transportOpt = transportOpt
self.muxerOpt = muxerOpt
self.secOpt = secOpt
self.peerstore = peerstore
def new_node(self):
swarm = Swarm(self.id, self.peerstore)
host = BasicHost(swarm)
upgrader = TransportUpgrader(self.secOpt, self.transportOpt)
# TODO transport upgrade
# TODO listen on addrs
# TODO swarm add transports