move transport to swarm constructor

This commit is contained in:
zixuanzh 2019-04-24 22:36:09 -04:00
parent fc4fc74b87
commit 35f75c4dcd
2 changed files with 11 additions and 13 deletions

View File

@ -67,16 +67,18 @@ def initialize_default_swarm(
if not id_opt:
id_opt = generate_id()
# TODO parse transport_opt to determine transport
transport_opt = transport_opt or ["/ip4/127.0.0.1/tcp/8001"]
transport = [multiaddr.Multiaddr(t) for t in transport_opt]
# TODO wire muxer up with swarm
# muxer = muxer_opt or ["mplex/6.7.0"]
transport = TCP()
# TODO TransportUpgrader is not doing anything really
# TODO parse muxer and sec to pass into TransportUpgrader
muxer = muxer_opt or ["mplex/6.7.0"]
sec = sec_opt or ["secio"]
upgrader = TransportUpgrader(sec, muxer)
peerstore = peerstore_opt or PeerStore()
upgrader = TransportUpgrader(sec, transport)
swarm_opt = Swarm(id_opt, peerstore, upgrader)
tcp = TCP()
swarm_opt.add_transport(tcp)
swarm_opt = Swarm(id_opt, peerstore, upgrader, transport)
return swarm_opt

View File

@ -12,14 +12,14 @@ from .connection.raw_connection import RawConnection
class Swarm(INetwork):
# pylint: disable=too-many-instance-attributes, cell-var-from-loop
def __init__(self, peer_id, peerstore, upgrader):
def __init__(self, peer_id, peerstore, upgrader, transport):
self.self_id = peer_id
self.peerstore = peerstore
self.upgrader = upgrader
self.transport = transport
self.connections = dict()
self.listeners = dict()
self.stream_handlers = dict()
self.transport = None
# Protocol muxing
self.multiselect = Multiselect()
@ -183,10 +183,6 @@ class Swarm(INetwork):
return True
return False
def add_transport(self, transport):
# TODO: Support more than one transport
self.transport = transport
def create_generic_protocol_handler(swarm):
"""
Create a generic protocol handler from the given swarm. We use swarm