Skip to content

Commit

Permalink
Merge pull request #99 from zixuanzh/proper-multiaddr
Browse files Browse the repository at this point in the history
Updating to proper multiaddr dependency
  • Loading branch information
robzajac authored Dec 29, 2018
2 parents f6c6ec2 + 2f33f55 commit 9cfe26f
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion host/basic_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_addrs(self):
"""
:return: all the multiaddr addresses this host is listening too
"""
p2p_part = multiaddr.Multiaddr('/ipfs/{}'.format(self.get_id().pretty()))
p2p_part = multiaddr.Multiaddr('/p2p/{}'.format(self.get_id().pretty()))

addrs = []
for transport in self.network.listeners.values():
Expand Down
10 changes: 5 additions & 5 deletions peer/peerinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def info_from_p2p_addr(addr):
if not parts:
raise InvalidAddrError()

ipfspart = parts[-1]
if ipfspart.protocols()[0].code != multiaddr.protocols.P_IPFS:
p2p_part = parts[-1]
if p2p_part.protocols()[0].code != multiaddr.protocols.P_P2P:
raise InvalidAddrError()

# make sure the /ipfs value parses as a peer.ID
peer_id_str = ipfspart.value_for_protocol(multiaddr.protocols.P_IPFS)
# make sure the /p2p value parses as a peer.ID
peer_id_str = p2p_part.value_for_protocol(multiaddr.protocols.P_P2P)
peer_id = id_b58_decode(peer_id_str)

# we might have received just an / ipfs part, which means there's no addr.
# we might have received just an / p2p part, which means there's no addr.
if len(parts) > 1:
addr = multiaddr.util.join(parts[:-1])

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ pytest-asyncio
click
base58
pymultihash
py-multiaddr
multiaddr
2 changes: 1 addition & 1 deletion tests/libp2p/test_libp2p.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,6 @@ async def test_host_connect():
assert len(node_a.get_peerstore().peers()) == 1

assert node_b.get_id() in node_a.get_peerstore().peers()
ma_node_b = multiaddr.Multiaddr('/ipfs/%s' % node_b.get_id().pretty())
ma_node_b = multiaddr.Multiaddr('/p2p/%s' % node_b.get_id().pretty())
for addr in node_a.get_peerstore().addrs(node_b.get_id()):
assert addr.encapsulate(ma_node_b) in node_b.get_addrs()
2 changes: 1 addition & 1 deletion tests/peer/test_peerinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def test_info_from_p2p_addr():
# pylint: disable=line-too-long
m_addr = multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/8000/ipfs/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ')
m_addr = multiaddr.Multiaddr('/ip4/127.0.0.1/tcp/8000/p2p/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ')
info = info_from_p2p_addr(m_addr)
assert info.peer_id.pretty() == '3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ'
assert len(info.addrs) == 1
Expand Down
2 changes: 1 addition & 1 deletion transport/tcp/tcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async def listen(self, multiaddr):
:return: return True if successful
"""
_multiaddr = multiaddr
_multiaddr = _multiaddr.decapsulate('/ipfs')
_multiaddr = _multiaddr.decapsulate('/p2p')

coroutine = asyncio.start_server(self.handler,
_multiaddr.value_for_protocol('ip4'),
Expand Down

0 comments on commit 9cfe26f

Please sign in to comment.