Correct mdns peer filtering from Udp to Quic

Also adds commented with_quic_config.
This commit is contained in:
Luke Parker 2023-11-26 02:56:20 -05:00
parent 964284e774
commit 01a2c98018
No known key found for this signature in database

View file

@ -275,6 +275,17 @@ impl LibP2p {
let mut swarm = SwarmBuilder::with_existing_identity(throwaway_key_pair) let mut swarm = SwarmBuilder::with_existing_identity(throwaway_key_pair)
.with_tokio() .with_tokio()
.with_quic() .with_quic()
/*
.with_quic_config(|mut config| {
config.max_idle_timeout = 85;
// We send KeepAlive after 80, so this isn't needed
config.keep_alive_interval = Duration::from_secs(config.max_idle_timeout.into() + 1);
// 1 MiB + max message size
config.max_stream_data = (1024 * 1024) + u32::try_from(MAX_LIBP2P_MESSAGE_SIZE).unwrap();
// Support 10 maxed out streams
config.max_connection_data = 10 * config.max_stream_data;
})
*/
.with_behaviour(|_| behavior) .with_behaviour(|_| behavior)
.unwrap() .unwrap()
.build(); .build();
@ -365,8 +376,8 @@ impl LibP2p {
libp2p::mdns::Event::Discovered(list), libp2p::mdns::Event::Discovered(list),
))) => { ))) => {
for (peer, mut addr) in list { for (peer, mut addr) in list {
// Check the port is as expected to prevent trying to peer with Substrate nodes // Only peer with Quic, effectively preventing connecting to Substrate nodes
if addr.pop() == Some(libp2p::multiaddr::Protocol::Udp(PORT)) { if addr.pop() == Some(libp2p::multiaddr::Protocol::QuicV1) {
log::info!("found peer via mdns"); log::info!("found peer via mdns");
swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer); swarm.behaviour_mut().gossipsub.add_explicit_peer(&peer);
} }