From af6784546ed907e3f43f8409b17c251ac0dcc0b0 Mon Sep 17 00:00:00 2001 From: zixuanzh Date: Sun, 11 Nov 2018 10:43:03 -0500 Subject: [PATCH] entry point wip --- libp2p/config.py | 0 libp2p/libp2p.py | 22 ++++++++++++++++++++-- network/swarm.py | 2 +- 3 files changed, 21 insertions(+), 3 deletions(-) delete mode 100644 libp2p/config.py diff --git a/libp2p/config.py b/libp2p/config.py deleted file mode 100644 index e69de29..0000000 diff --git a/libp2p/libp2p.py b/libp2p/libp2p.py index cb8c78b..2c0b1eb 100644 --- a/libp2p/libp2p.py +++ b/libp2p/libp2p.py @@ -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 \ No newline at end of file diff --git a/network/swarm.py b/network/swarm.py index 5d570e9..231ee46 100644 --- a/network/swarm.py +++ b/network/swarm.py @@ -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 = {}