entry point wip

This commit is contained in:
zixuanzh 2018-11-11 10:43:03 -05:00
parent 2bde260f5f
commit af6784546e
3 changed files with 21 additions and 3 deletions

View File

View File

@ -1,5 +1,8 @@
from .config import Config
from ..peer.peerstore import PeerStore
from ..network.swarm import Swarm
from ..host.basic_host import BasicHost
from ..transport.upgrader import TransportUpgrader
class Libp2p(object):
@ -7,11 +10,26 @@ class Libp2p(object):
transportOpt = ["/ip4/0.0.0.0/tcp/0"], \
muxerOpt = ["mplex/6.7.0"], \
secOpt = ["secio"], \
peerstoreOpt = new PeerStore()):
peerstore = PeerStore()):
if idOpt:
self.idOpt = idOpt
else:
# TODO generate RSA public key pair
# TODO initialize
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

View File

@ -4,7 +4,7 @@ from ..connection.raw_connection import RawConnection
class Swarm(INetwork):
def __init__(self, my_peer_id, peer_store):
def __init__(self, my_peer_id, peerstore):
self.my_peer_id = my_peer_id
self.peer_store = peer_store
self.connections = {}