Merge branch 'master' into router-refactor

This commit is contained in:
ZX 2019-04-28 14:51:54 -04:00 committed by GitHub
commit 21a99287b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 13 deletions

View File

@ -68,16 +68,18 @@ def initialize_default_swarm(
if not id_opt: if not id_opt:
id_opt = generate_id() id_opt = generate_id()
# TODO parse transport_opt to determine transport
transport_opt = transport_opt or ["/ip4/127.0.0.1/tcp/8001"] transport_opt = transport_opt or ["/ip4/127.0.0.1/tcp/8001"]
transport = [multiaddr.Multiaddr(t) for t in transport_opt] transport = TCP()
# TODO wire muxer up with swarm
# muxer = muxer_opt or ["mplex/6.7.0"] # 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"] sec = sec_opt or ["secio"]
upgrader = TransportUpgrader(sec, muxer)
peerstore = peerstore_opt or PeerStore() peerstore = peerstore_opt or PeerStore()
upgrader = TransportUpgrader(sec, transport) swarm_opt = Swarm(id_opt, peerstore, upgrader, transport)
swarm_opt = Swarm(id_opt, peerstore, upgrader)
tcp = TCP()
swarm_opt.add_transport(tcp)
return swarm_opt return swarm_opt

View File

@ -12,14 +12,14 @@ from .connection.raw_connection import RawConnection
class Swarm(INetwork): class Swarm(INetwork):
# pylint: disable=too-many-instance-attributes, cell-var-from-loop # 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.self_id = peer_id
self.peerstore = peerstore self.peerstore = peerstore
self.upgrader = upgrader self.upgrader = upgrader
self.transport = transport
self.connections = dict() self.connections = dict()
self.listeners = dict() self.listeners = dict()
self.stream_handlers = dict() self.stream_handlers = dict()
self.transport = None
self.router = None self.router = None
# Protocol muxing # Protocol muxing
@ -186,10 +186,6 @@ class Swarm(INetwork):
return True return True
return False return False
def add_transport(self, transport):
# TODO: Support more than one transport
self.transport = transport
def add_router(self, router): def add_router(self, router):
self.router = router self.router = router