lint network
This commit is contained in:
parent
92867c42a4
commit
f77e7bee95
|
@ -88,7 +88,8 @@ class MultiAddr:
|
||||||
Gives back a dictionary with access to transport information from this multiaddr.
|
Gives back a dictionary with access to transport information from this multiaddr.
|
||||||
Example: MultiAddr('/ip4/127.0.0.1/tcp/4001').to_options()
|
Example: MultiAddr('/ip4/127.0.0.1/tcp/4001').to_options()
|
||||||
= { family: 'ipv4', host: '127.0.0.1', transport: 'tcp', port: '4001' }
|
= { family: 'ipv4', host: '127.0.0.1', transport: 'tcp', port: '4001' }
|
||||||
:return: {{family: String, host: String, transport: String, port: String}} with None if field does not exist
|
:return: {{family: String, host: String, transport: String, port: String}}
|
||||||
|
with None if field does not exist
|
||||||
"""
|
"""
|
||||||
options = dict()
|
options = dict()
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,6 @@ from abc import ABC, abstractmethod
|
||||||
|
|
||||||
class INetwork(ABC):
|
class INetwork(ABC):
|
||||||
|
|
||||||
def __init__(self, my_peer_id, peer_store):
|
|
||||||
self.my_peer_id = my_peer_id
|
|
||||||
self.peer_store = peer_store
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def set_stream_handler(self, stream_handler):
|
def set_stream_handler(self, stream_handler):
|
||||||
"""
|
"""
|
||||||
|
@ -29,4 +25,4 @@ class INetwork(ABC):
|
||||||
:param *args: one or many multiaddrs to start listening on
|
:param *args: one or many multiaddrs to start listening on
|
||||||
:return: True if at least one success
|
:return: True if at least one success
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -17,29 +17,27 @@ class Swarm(INetwork):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def new_stream(self, peer_id, protocol_id):
|
def new_stream(self, peer_id, protocol_id):
|
||||||
"""
|
|
||||||
:param peer_id: peer_id of destination
|
|
||||||
:param protocol_id: protocol id
|
|
||||||
:return: stream instance
|
|
||||||
"""
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Determine if a connection to peer_id already exists
|
Determine if a connection to peer_id already exists
|
||||||
If a connection to peer_id exists, then
|
If a connection to peer_id exists, then
|
||||||
c = existing connection,
|
c = existing connection,
|
||||||
otherwise c = new muxed connection to peer_id
|
otherwise c = new muxed connection to peer_id
|
||||||
s = c.open_stream(protocol_id)
|
s = c.open_stream(protocol_id)
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
:param peer_id: peer_id of destination
|
||||||
|
:param protocol_id: protocol id
|
||||||
|
:return: stream instance
|
||||||
"""
|
"""
|
||||||
muxed_connection = None
|
muxed_connection = None
|
||||||
if peer_id in self.connections:
|
if peer_id in self.connections:
|
||||||
muxed_connection = self.connections[peer_id]
|
muxed_connection = self.connections[peer_id]
|
||||||
else:
|
else:
|
||||||
addrs = self.peer_store.addrs(peer_id)
|
addrs = self.peer_store.addrs(peer_id)
|
||||||
ip = addrs.get_protocol_value("ip")
|
stream_ip = addrs.get_protocol_value("ip")
|
||||||
port = addrs.get_protocol_value("port")
|
stream_port = addrs.get_protocol_value("port")
|
||||||
if len(addrs) > 0:
|
if len(addrs) > 0:
|
||||||
conn = RawConnection(ip, port)
|
conn = RawConnection(stream_ip, stream_port)
|
||||||
muxed_connection = MuxedConnection(conn, True)
|
muxed_connection = MuxedConnection(conn, True)
|
||||||
else:
|
else:
|
||||||
raise Exception("No IP and port in addr")
|
raise Exception("No IP and port in addr")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user