Merge pull request #51 from zixuanzh/zx-new-node

implement new_node
This commit is contained in:
Robert Zajac 2018-11-11 20:43:52 -05:00 committed by GitHub
commit a0ad0b5ef7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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