From 64002acc645ef77cf720ba776f0e67e20ad05010 Mon Sep 17 00:00:00 2001 From: zixuanzh Date: Sun, 11 Nov 2018 20:41:21 -0500 Subject: [PATCH] implement new_node --- libp2p/libp2p.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/libp2p/libp2p.py b/libp2p/libp2p.py index e294411..ba4cacb 100644 --- a/libp2p/libp2p.py +++ b/libp2p/libp2p.py @@ -1,7 +1,8 @@ -from ..peer.peerstore import PeerStore -from ..network.swarm import Swarm -from ..host.basic_host import BasicHost -from ..transport.upgrader import TransportUpgrader +from peer.peerstore import PeerStore +from network.swarm import Swarm +from host.basic_host import BasicHost +from transport.upgrader import TransportUpgrader +from transport.tcp import TCP from Crypto.PublicKey import RSA class Libp2p(object): @@ -15,7 +16,6 @@ class Libp2p(object): if idOpt: self.idOpt = idOpt else: - # TODO generate RSA public key pair new_key = RSA.generate(2048, e=65537) self.idOpt = new_key.publickey().exportKey("PEM") self.private_key = new_key.exportKey("PEM") @@ -27,14 +27,14 @@ class Libp2p(object): def new_node(self): - swarm = Swarm(self.idOpt, self.peerstore) - host = BasicHost(swarm) upgrader = TransportUpgrader(self.secOpt, self.transportOpt) + swarm = Swarm(self.idOpt, self.peerstore, upgrader) + tcp = TCP() + swarm.add_transport(tcp) + swarm.listen(self.transportOpts) + host = BasicHost(swarm) - # TODO transport upgrade + # TODO MuxedConnection currently contains all muxing logic + # TODO routing unimplemented - # TODO listen on addrs - - # TODO swarm add transports - - # TODO: return host + return host