Hi! I’m trying to connect libp2p in Rust and JavaScript, but I’m having troubles doing that.
Here’s the code https://github.com/folex/libp2p-multilang
What I’m doing in rust is basically:
let transport = libp2p::build_development_transport(local_key);
let behaviour = Ping::new(PingConfig::new().with_keep_alive(true));
let mut swarm = Swarm::new(transport, behaviour, local_peer_id.clone());
Swarm::listen_on(&mut swarm, addr.clone()).unwrap();
And JS:
class MyBundle extends libp2p {
constructor(_options) {
const defaults = {
modules: {
transport: [TCP],
streamMuxer: [Mplex],
connEncryption: [SECIO],
},
};
super(defaultsDeep(_options, defaults))
}
}
RUST_PEER = "/ip4/127.0.0.1/tcp/30000/p2p/12D3KooWSwNXzEeGjgwEocRJBzbdoDqxbz3LdrwgSuKmKeGvbM4G";
node = new MyBundle(...);
node.dial(RUST_PEER, cb)
Both snippets are heavily simplified, full versions can be seen in the repo
And then there are two different cases:
- If I use PeerID
QmTESkr2vWDCKqiHVsyvf4iRQCBgvNDqBJ6P3yTTDb6haw
, then JS saysdialed to the wrong peer, Ids do not match
- If I use PeerID that JS derives from Rust’s public key
12D3KooWSwNXzEeGjgwEocRJBzbdoDqxbz3LdrwgSuKmKeGvbM4G
, then SecIO handshake hangs.
Tail logs from Rust hanging:
[2019-12-23T15:53:25Z TRACE libp2p_secio::handshake] sending exchange to remote
[2019-12-23T15:53:25Z TRACE tokio_io::framed_read] attempting to decode a frame
[2019-12-23T15:53:45Z DEBUG libp2p_core::transport::timeout] timeout elapsed for connection
[2019-12-23T15:53:45Z DEBUG libp2p_tcp] Dropped TCP connection to V4(127.0.0.1:49760)
Tail logs from JS hanging:
libp2p:secio 1. propose - start +0ms
libp2p:secio 1. propose - writing proposal +0ms
libp2p:secio 1. propose - reading proposal <Buffer 0a 10 e4 45 11 3d 27 24 1c 03 a9 7b 79 ff e8 ef d1 cc 12 24 08 01 12 20 fe 62 28 54 de 53 5d 1a 5d a2 b8 7d fb 93 2d b3 b2 37 6f fc d2 43 ce cd 75 0b ... > +2ms
libp2p:secio 1.1 identify +0ms
libp2p:secio 1.1 identify - QmSAmTQf4nKgQypvNmq2XFvDFhnu4k8j1Jqo2wqUiaivff - identified remote peer as 12D3KooWSwNXzEeGjgwEocRJBzbdoDqxbz3LdrwgSuKmKeGvbM4G +1ms
libp2p:secio 1.2 selection +0ms
libp2p:secio 1. propose - finish +2ms
libp2p:secio 2. exchange - start +0ms
libp2p:secio 2. exchange - writing exchange +0ms
Full logs can be found in README of in the repo https://github.com/folex/libp2p-multilang
To reproduce, simply clone repo and:
- In one terminal, execute
make rust
- In another one execute
make js-rust-peerid
for first case, andmake js
for the second case
So my question is, is it possible to connect libp2p Rust + JS? If so, could you please point where I’m doing that wrong?
Thanks in advance!