Fix msg encoding

- Change varint-prefix encode to fixedint-prefix(4 bytes) encode.
This commit is contained in:
mhchia
2019-08-17 21:41:17 +08:00
parent 22b1a5395d
commit bb7d37fd4f
4 changed files with 38 additions and 15 deletions

View File

@ -177,8 +177,8 @@ class Swarm(INetwork):
Call listener listen with the multiaddr
Map multiaddr to listener
"""
for multiaddr in multiaddrs:
if str(multiaddr) in self.listeners:
for maddr in multiaddrs:
if str(maddr) in self.listeners:
return True
async def conn_handler(
@ -187,8 +187,8 @@ class Swarm(INetwork):
# Upgrade reader/write to a net_stream and pass \
# to appropriate stream handler (using multiaddr)
raw_conn = RawConnection(
multiaddr.value_for_protocol("ip4"),
multiaddr.value_for_protocol("tcp"),
maddr.value_for_protocol("ip4"),
maddr.value_for_protocol("tcp"),
reader,
writer,
False,
@ -215,19 +215,19 @@ class Swarm(INetwork):
try:
# Success
listener = self.transport.create_listener(conn_handler)
self.listeners[str(multiaddr)] = listener
await listener.listen(multiaddr)
self.listeners[str(maddr)] = listener
await listener.listen(maddr)
# Call notifiers since event occurred
for notifee in self.notifees:
await notifee.listen(self, multiaddr)
await notifee.listen(self, maddr)
return True
except IOError:
# Failed. Continue looping.
print("Failed to connect to: " + str(multiaddr))
print("Failed to connect to: " + str(maddr))
# No multiaddr succeeded
# No maddr succeeded
return False
def notify(self, notifee: INotifee) -> bool: