Hi,
I am trying to test the python libp2p implement to see if I can interoperate with a go-based libp2p swarm. I wrote the attached pretty dumb code that I run with this command:
python3 ./p2pctl ping /ip4/152.228.215.158/tcp/4001/p2p/QmRVKwsrdjjXBjf6o2SyavVmYS9PkSVx7XGUNGFFyvEy34
(the above multiaddr is the address of a running test node using go-libp2p).
I know I am not going to do much with the remote node because it implements a set of custom protocols but I was hoping to be able to at least establish a noise connection to this node. What happens when I run this code is this:
I am QmYfkik6m8CqXFxeJFfgGMHkJhSuHVQPziGPUDp5Y8uDB2
libp2p.exceptions.MultiError: [SwarmException('failed to upgrade mux for peer QmSh5LAWMAMESCGxQbx18nkxeZqrR4MdPucqns1cErcC9C')]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/mathieu/code/agent-swarm/./p2pctl", line 56, in <module>
main()
File "/home/mathieu/code/agent-swarm/./p2pctl", line 53, in main
args.func(args)
File "/home/mathieu/code/agent-swarm/./p2pctl", line 32, in _ping_function
trio.run(_run, args.maddr)
File "/usr/lib/python3.12/site-packages/trio/_core/_run.py", line 2010, in run
raise runner.main_task_outcome.error
File "/home/mathieu/code/agent-swarm/./p2pctl", line 29, in _run
await host.connect(info)
File "/home/mathieu/code-oss/py-libp2p/libp2p/host/basic_host.py", line 213, in connect
await self._network.dial_peer(peer_info.peer_id)
File "/home/mathieu/code-oss/py-libp2p/libp2p/network/swarm.py", line 180, in dial_peer
raise SwarmException(
libp2p.network.exceptions.SwarmException: unable to connect to QmSh5LAWMAMESCGxQbx18nkxeZqrR4MdPucqns1cErcC9C, no addresses established a successful connection (with exceptions)
I tracked this down to fact that the remote is telling me it does not support mplex/6.7.0 (I get a PROTOCOL_NOT_FOUND_MSG)
The remote is running go-libp2p v0.29.2 which, as far as I can tell, is the last version that was released with support for mplex so, I was hoping this would work. Is there something special that might need to be done to enable mplex in that version of go-libp2p ?
#!/usr/bin/env python3
import argparse
import sys
import random
import trio
import multiaddr
import libp2p
import libp2p.security.noise.transport as noise
def _ping_function(args):
async def _run(maddr):
key_pair = libp2p.crypto.rsa.create_new_key_pair() # this is what the remote is using.
noise_privkey = libp2p.crypto.ed25519.create_new_key_pair().private_key
host = libp2p.new_host(
key_pair=key_pair,
sec_opt={noise.PROTOCOL_ID: noise.Transport(
libp2p_keypair=key_pair,
noise_privkey=key_pair.private_key
)}
)
listen_addr = multiaddr.Multiaddr(f"/ip4/0.0.0.0/tcp/0")
async with host.run(listen_addrs=[listen_addr]):
print(f"I am {host.get_id().to_string()}")
maddr = multiaddr.Multiaddr(args.maddr)
info = libp2p.peer.peerinfo.info_from_p2p_addr(maddr)
await host.connect(info)
try:
trio.run(_run, args.maddr)
except KeyboardInterrupt:
pass
def main():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(required=True)
ping = subparsers.add_parser('ping', help='Check health')
ping.add_argument('maddr', help='Multiaddr of the remote host to ping')
ping.set_defaults(func=_ping_function)
args = parser.parse_args()
args.func(args)
main()
Mathieu