rust-libp2p
rust-libp2p copied to clipboard
File sharing example cannot support the sample plot situation
Hi, I am new to libp2p but very interested for this. While surfing through examples, I find the provided file-sharing
example are not so ideal. I run these three scripts at the base directory of the repository in different console to test the sample plot.
In first console:
cargo run --example file-sharing -- --listen-address /ip4/127.0.0.1/tcp/40837 --secret-key-seed 1 provide --path ./Cargo.lock --name lock
for serving Cargo.lock
file with name lock
. It works. The listening multiaddr is /ip4/127.0.0.1/tcp/40837/p2p/12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X
In second console:
cargo run --example file-sharing -- --listen-address /ip4/127.0.0.1/tcp/40800 --peer /ip4/127.0.0.1/tcp/40837/p2p/12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X --secret-key-seed 2 provide --path ./Cargo.toml --name toml
for serving Cargo.toml
file with name toml
and connect to the first console. It also works. The listening multiaddr is /ip4/127.0.0.1/tcp/40800/p2p/12D3KooWH3uVF6wv47WnArKHk5p6cvgCJEb74UTmxztmQDc298L3
.
In thrid console, I connect to the second console and request file lock
in first console:
cargo run --example file-sharing -- --peer /ip4/127.0.0.1/tcp/40800/p2p/12D3KooWH3uVF6wv47WnArKHk5p6cvgCJEb74UTmxztmQDc298L3 get --name toml
Now the third console panics with this informations:
thread 'async-std/runtime' panicked at 'Dialing(PeerId("12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X"))', examples/file-sharing.rs:502:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'Sender not to be dropped.: Canceled', examples/file-sharing.rs:332:28
Meanwhile, the first console also panics with this informations:
thread 'async-std/runtime' panicked at 'IncomingConnectionError { local_addr: "/ip4/127.0.0.1/tcp/40837", send_back_addr: "/ip4/127.0.0.1/tcp/52526", error: Transport(Other(Custom { kind: Other, error: Other(A(B(Select(Failed)))) })) }', examples/file-sharing.rs:502:22
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at 'not yet implemented', examples/file-sharing.rs:141:26
It seems the connection from the third console to the first console fails.
Requesting the toml
file served in the second console from the third console in this situation also fail.
Interesting, mind printing the event that is not expected via the change below?
diff --git a/examples/file-sharing.rs b/examples/file-sharing.rs
index 183bd9d6..2c069175 100644
--- a/examples/file-sharing.rs
+++ b/examples/file-sharing.rs
@@ -138,7 +138,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
network_client.respond_file(file_content, channel).await;
}
}
- _ => todo!(),
+ e => todo!("{:?}", e),
}
}
}
Interesting, mind printing the event that is not expected via the change below?
diff --git a/examples/file-sharing.rs b/examples/file-sharing.rs index 183bd9d6..2c069175 100644 --- a/examples/file-sharing.rs +++ b/examples/file-sharing.rs @@ -138,7 +138,7 @@ async fn main() -> Result<(), Box<dyn Error>> { network_client.respond_file(file_content, channel).await; } } - _ => todo!(), + e => todo!("{:?}", e), } } }
No unexpected network event happens. The file server and the request client both panic during handling swarm event: https://github.com/libp2p/rust-libp2p/blob/a168410dbed0d0941f2e5a14543206044ccb2260/examples/file-sharing.rs#L502
And on which SwarmEvent
are they panicing? When you exclude that event from panic
do things function as expected?
And on which
SwarmEvent
are they panicing? When you exclude that event frompanic
do things function as expected?
I excluded the IncomingConnectionError
and Dialing
SwarmEvent
from panic
and the file-sharing example works as expected. But I wonder why these two events emit. It seems that the client try to connect to the peer which is not directly connected but it fails.
IncomingConnectionError
might be that the node is failing to connect to a private IP address?
I excluded the
IncomingConnectionError
andDialing
SwarmEvent
frompanic
and the file-sharing example works as expected.
Mind creating a pull request?
After the error is solved superficially, I still wonder why the client will dail to a unconnected server. It's a behavior of kadmelia protocol?
Nodes will try to interconnect due to the Kademlia protocol, yes.
Let me know if still an issue.