rust-libp2p icon indicating copy to clipboard operation
rust-libp2p copied to clipboard

`KeepAliveTimeout` MDNS.

Open Jerrody opened this issue 3 years ago • 1 comments

System: Windows 10.

Problem: From a 1 minute, I get KeepAliveTimeout and Peer expires. What's the problem? Logs are below.

Code:

#![feature(trivial_bounds)]

use async_std::io;
use env_logger::{Builder, Env};
use futures::{prelude::*, select};
use libp2p::gossipsub::MessageId;
use libp2p::gossipsub::{
    GossipsubEvent, GossipsubMessage, IdentTopic as Topic, MessageAuthenticity, ValidationMode,
};
use libp2p::NetworkBehaviour;
use libp2p::{gossipsub, identity, swarm::SwarmEvent, Multiaddr, PeerId};
use libp2p_mdns::{Mdns, MdnsEvent, MdnsConfig};
use libp2p_swarm::{KeepAlive, NetworkBehaviourEventProcess};
use std::collections::hash_map::DefaultHasher;
use std::collections::HashMap;
use std::error::Error;
use std::hash::{Hash, Hasher};
use std::time::Duration;

#[derive(NetworkBehaviour)]
#[behaviour(event_process = true)]
struct Behaviour {
    gossipsub: gossipsub::Gossipsub,
    mdns: Mdns,
    #[behaviour(ignore)]
    _keep_alive: KeepAlive,
    #[behaviour(ignore)]
    peers: HashMap<PeerId, Vec<Multiaddr>>,
}

impl NetworkBehaviourEventProcess<MdnsEvent> for Behaviour {
    // Called when `mdns` produces an event.
    fn inject_event(&mut self, event: MdnsEvent) {
        match event {
            MdnsEvent::Discovered(list) => {
                for (peer_id, address) in list {
                    println!("New Peer | {:?} | {:?}", peer_id, address);
                    let addresses = self.peers.entry(peer_id).or_default();
                    if !addresses.contains(&address) {
                        addresses.push(address);
                        self.gossipsub.add_explicit_peer(&peer_id);
                    }
                }
            }
            MdnsEvent::Expired(list) => {
                for (peer_id, address) in list {
                    println!("Expired Peer | {:?} | {:?}", peer_id, address);
                    if !self.mdns.has_node(&peer_id) {
                        self.peers.remove(&peer_id);
                    }
                }
            }
        }
    }
}

impl NetworkBehaviourEventProcess<GossipsubEvent> for Behaviour {
    fn inject_event(&mut self, event: GossipsubEvent) {
        match event {
            GossipsubEvent::Message {
                propagation_source: peer,
                message: msg,
                ..
            } => {
                println!(
                    "Got message from Peer | {:?} | {:?}",
                    peer,
                    String::from_utf8_lossy(&msg.data)
                );
            }
            _ => (),
        }
    }
}

#[async_std::main]
async fn main() -> Result<(), Box<dyn Error>> {
    Builder::from_env(Env::default().default_filter_or("info")).init();

    // Create a random PeerId
    let local_key = identity::Keypair::generate_ed25519();
    let local_peer_id = PeerId::from(local_key.public());
    println!("Local peer id: {:?}", local_peer_id);

    // Set up an encrypted TCP Transport over the Mplex and Yamux protocols
    let transport = libp2p::development_transport(local_key.clone()).await?;

    // Create a Gossipsub topic
    let topic = Topic::new("test-net");

    // Create a Swarm to manage peers and events
    let mut swarm = {
        // To content-address message, we can take the hash of message and use it as an ID.
        let message_id_fn = |message: &GossipsubMessage| {
            let mut s = DefaultHasher::new();
            message.data.hash(&mut s);
            MessageId::from(s.finish().to_string())
        };

        // Set a custom gossipsub
        let gossipsub_config = gossipsub::GossipsubConfigBuilder::default()
            .heartbeat_interval(Duration::from_secs(10)) // This is set to aid debugging by not cluttering the log space
            .validation_mode(ValidationMode::Strict) // This sets the kind of message validation. The default is Strict (enforce message signing)
            .message_id_fn(message_id_fn) // content-address messages. No two messages of the
            // same content will be propagated.
            .build()
            .expect("Valid config");
        // build a gossipsub network behaviour
        let mut gossipsub: gossipsub::Gossipsub =
            gossipsub::Gossipsub::new(MessageAuthenticity::Signed(local_key), gossipsub_config)
                .expect("Correct configuration");

        // subscribes to our topic
        gossipsub.subscribe(&topic).unwrap();
        
        let mut behaviour = Behaviour {
            gossipsub,
            mdns: Mdns::new(MdnsConfig::default()).await.unwrap(),
            _keep_alive: KeepAlive::Yes,
            peers: Default::default(),
        };
        // add an explicit peer if one was provided
        if let Some(explicit) = std::env::args().nth(2) {
            let explicit = explicit.clone();
            match explicit.parse() {
                Ok(id) => behaviour.gossipsub.add_explicit_peer(&id),
                Err(err) => println!("Failed to parse explicit peer id: {:?}", err),
            }
        }

        // build the swarm
        libp2p::Swarm::new(transport, behaviour, local_peer_id)
    };

    // Listen on all interfaces and whatever port the OS assigns
    swarm
        .listen_on("/ip4/0.0.0.0/tcp/0".parse().unwrap())
        .unwrap();

    // Reach out to another node if specified
    if let Some(to_dial) = std::env::args().nth(1) {
        let address: Multiaddr = to_dial.parse().expect("User to provide valid address.");
        match swarm.dial(address.clone()) {
            Ok(_) => println!("Dialed {:?}.", address),
            Err(e) => println!("Dial {:?} failed: {:?}", address, e),
        }
    }

    // Read full lines from stdin
    let mut stdin = io::BufReader::new(io::stdin()).lines().fuse();

    // Kick it off
    loop {
        select! {
            line = stdin.select_next_some() => {
                if let Err(e) = swarm
                    .behaviour_mut()
                    .gossipsub
                    .publish(topic.clone(), line.expect("Stdin not to close").as_bytes())
                {
                    println!("Publish error: {:?}", e);
                }
            },
            event = swarm.select_next_some() => match event {
                SwarmEvent::NewListenAddr { address, .. } => {
                    println!("Now Listening | {:?}", address);
                }
                SwarmEvent::ConnectionEstablished {
                    peer_id,
                    endpoint,
                    ..
                } => {
                    println!("Peer and ENDPOINT | {:?} | {:?}", peer_id, endpoint);
                }
                _ => (),
            }
        }
    }
}

Logs: peer_01

Local peer id: PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4")
[2022-03-16T18:14:49Z DEBUG libp2p_gossipsub::behaviour] Subscribing to topic: test-net
[2022-03-16T18:14:49Z DEBUG libp2p_gossipsub::behaviour] Running JOIN for topic: TopicHash { hash: "test-net" }  
[2022-03-16T18:14:49Z DEBUG libp2p_gossipsub::behaviour] RANDOM PEERS: Got 0 peers
[2022-03-16T18:14:49Z DEBUG libp2p_gossipsub::behaviour] JOIN: Inserting 0 random peers into the mesh
[2022-03-16T18:14:49Z DEBUG libp2p_gossipsub::behaviour] Completed JOIN for topic: TopicHash { hash: "test-net" }
[2022-03-16T18:14:49Z DEBUG libp2p_gossipsub::behaviour] Subscribed to topic: test-net
[2022-03-16T18:14:49Z DEBUG libp2p_tcp] listening on 0.0.0.0:0
[2022-03-16T18:14:49Z DEBUG libp2p_tcp] New listen address: /ip4/26.191.225.201/tcp/14051
[2022-03-16T18:14:49Z DEBUG libp2p_swarm] Listener ListenerId(1); New address: "/ip4/26.191.225.201/tcp/14051"   
Now Listening | "/ip4/26.191.225.201/tcp/14051"
[2022-03-16T18:14:49Z DEBUG libp2p_tcp] New listen address: /ip4/192.168.0.13/tcp/14051
[2022-03-16T18:14:49Z DEBUG libp2p_swarm] Listener ListenerId(1); New address: "/ip4/192.168.0.13/tcp/14051"     
Now Listening | "/ip4/192.168.0.13/tcp/14051"
[2022-03-16T18:14:49Z DEBUG libp2p_tcp] New listen address: /ip4/127.0.0.1/tcp/14051
[2022-03-16T18:14:49Z DEBUG libp2p_swarm] Listener ListenerId(1); New address: "/ip4/127.0.0.1/tcp/14051"        
Now Listening | "/ip4/127.0.0.1/tcp/14051"
[2022-03-16T18:14:49Z INFO  libp2p_mdns::behaviour::iface] creating instance on iface 26.191.225.201
[2022-03-16T18:14:49Z INFO  libp2p_mdns::behaviour::iface] creating instance on iface 192.168.0.13  
[2022-03-16T18:14:52Z INFO  libp2p_mdns::behaviour] discovered: 12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38 /ip4/26.191.225.201/tcp/14052
[2022-03-16T18:14:52Z INFO  libp2p_mdns::behaviour] discovered: 12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38 /ip4/192.168.0.13/tcp/14052
[2022-03-16T18:14:52Z INFO  libp2p_mdns::behaviour] discovered: 12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38 /ip4/127.0.0.1/tcp/14052
New Peer | PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38") | "/ip4/26.191.225.201/tcp/14052"
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Adding explicit peer 12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Connecting to explicit peer PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38")
New Peer | PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38") | "/ip4/192.168.0.13/tcp/14052"
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Adding explicit peer 12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Connecting to explicit peer PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38")
New Peer | PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38") | "/ip4/127.0.0.1/tcp/14052"
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Adding explicit peer 12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Connecting to explicit peer PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38")
[2022-03-16T18:14:52Z DEBUG libp2p_dns] Dialing /ip4/26.191.225.201/tcp/14052/p2p/12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38
[2022-03-16T18:14:52Z DEBUG libp2p_dns] Dialing /ip4/26.191.225.201/tcp/14052/p2p/12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38
[2022-03-16T18:14:52Z DEBUG libp2p_dns] Dialing /ip4/26.191.225.201/tcp/14052/p2p/12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] dialing 26.191.225.201:14052
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] dialing 26.191.225.201:14052
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] dialing 26.191.225.201:14052
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Proposed protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Received confirmation for protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Proposed protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Proposed protocol: /noise
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] Incoming connection from /ip4/26.191.225.201/tcp/14056 at /ip4/26.191.225.201/tcp/14051
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] Incoming connection from /ip4/26.191.225.201/tcp/14057 at /ip4/26.191.225.201/tcp/14051
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] Incoming connection from /ip4/26.191.225.201/tcp/14058 at /ip4/26.191.225.201/tcp/14051
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Received confirmation for protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Received confirmation for protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: confirming protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: confirming protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: sent confirmed protocol: /noise
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Proposed protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: confirming protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: sent confirmed protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: sent confirmed protocol: /noise
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Proposed protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Proposed protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Received confirmation for protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: confirming protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG yamux::connection] new connection: be6949d6 (Client)
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: sent confirmed protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG yamux::connection] new connection: e12bfb04 (Server)
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG libp2p_swarm] Connection established: PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38") Listener { local_addr: "/ip4/26.191.225.201/tcp/14051", send_back_addr: "/ip4/26.191.225.201/tcp/14057" }; Total (peer): 1. Total non-banned (peer): 1
...
[2022-03-16T18:16:34Z DEBUG libp2p_gossipsub::behaviour] Starting heartbeat
[2022-03-16T18:16:34Z DEBUG libp2p_gossipsub::behaviour] HEARTBEAT: Mesh low. Topic: test-net Contains: 0 needs: 5
[2022-03-16T18:16:34Z DEBUG libp2p_gossipsub::behaviour] RANDOM PEERS: Got 0 peers
[2022-03-16T18:16:34Z DEBUG libp2p_gossipsub::behaviour] Updating mesh, new mesh: {}
[2022-03-16T18:16:34Z DEBUG libp2p_gossipsub::behaviour] Completed Heartbeat
[2022-03-16T18:16:44Z DEBUG libp2p_gossipsub::behaviour] Starting heartbeat
[2022-03-16T18:16:44Z DEBUG libp2p_gossipsub::behaviour] HEARTBEAT: Mesh low. Topic: test-net Contains: 0 needs: 5
[2022-03-16T18:16:44Z DEBUG libp2p_gossipsub::behaviour] RANDOM PEERS: Got 0 peers
[2022-03-16T18:16:44Z DEBUG libp2p_gossipsub::behaviour] Updating mesh, new mesh: {}
[2022-03-16T18:16:44Z DEBUG libp2p_gossipsub::behaviour] Completed Heartbeat
[2022-03-16T18:16:52Z DEBUG libp2p_swarm] Connection closed with error KeepAliveTimeout: Connected { endpoint: Listener { local_addr: "/ip4/26.191.225.201/tcp/14051", send_back_addr: "/ip4/26.191.225.201/tcp/14057" }, peer_id: PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38") }; Total (peer): 1.
[2022-03-16T18:16:52Z DEBUG libp2p_swarm] Connection closed with error KeepAliveTimeout: Connected { endpoint: Dialer { address: "/ip4/26.191.225.201/tcp/14052/p2p/12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38", role_override: Dialer }, peer_id: PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38") }; Total (peer): 0.
[2022-03-16T18:16:52Z DEBUG libp2p_gossipsub::behaviour] Peer disconnected: 12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38
[2022-03-16T18:16:52Z INFO  libp2p_mdns::behaviour] expired: 12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38 /ip4/26.191.225.201/tcp/14052
[2022-03-16T18:16:52Z INFO  libp2p_mdns::behaviour] expired: 12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38 /ip4/192.168.0.13/tcp/14052
[2022-03-16T18:16:52Z INFO  libp2p_mdns::behaviour] expired: 12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38 /ip4/127.0.0.1/tcp/14052
Expired Peer | PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38") | "/ip4/26.191.225.201/tcp/14052"
Expired Peer | PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38") | "/ip4/192.168.0.13/tcp/14052"
Expired Peer | PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38") | "/ip4/127.0.0.1/tcp/14052"
[2022-03-16T18:16:54Z DEBUG libp2p_gossipsub::behaviour] Starting heartbeat
[2022-03-16T18:16:54Z DEBUG libp2p_gossipsub::behaviour] HEARTBEAT: Mesh low. Topic: test-net Contains: 0 needs: 5
[2022-03-16T18:16:54Z DEBUG libp2p_gossipsub::behaviour] RANDOM PEERS: Got 0 peers
[2022-03-16T18:16:54Z DEBUG libp2p_gossipsub::behaviour] Updating mesh, new mesh: {}
[2022-03-16T18:16:54Z DEBUG libp2p_gossipsub::behaviour] Completed Heartbeat
[2022-03-16T18:17:04Z DEBUG libp2p_gossipsub::behaviour] Starting heartbeat

peer_02

Local peer id: PeerId("12D3KooWCmzZ4MuJXdqkmA4vk68kmxQkVyCDQ5KheGpYnrRJKo38")
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Subscribing to topic: test-net
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Running JOIN for topic: TopicHash { hash: "test-net" }  
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] RANDOM PEERS: Got 0 peers
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] JOIN: Inserting 0 random peers into the mesh
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Completed JOIN for topic: TopicHash { hash: "test-net" }
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Subscribed to topic: test-net
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] listening on 0.0.0.0:0
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] New listen address: /ip4/26.191.225.201/tcp/14052
[2022-03-16T18:14:52Z DEBUG libp2p_swarm] Listener ListenerId(1); New address: "/ip4/26.191.225.201/tcp/14052"   
Now Listening | "/ip4/26.191.225.201/tcp/14052"
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] New listen address: /ip4/192.168.0.13/tcp/14052
[2022-03-16T18:14:52Z DEBUG libp2p_swarm] Listener ListenerId(1); New address: "/ip4/192.168.0.13/tcp/14052"     
Now Listening | "/ip4/192.168.0.13/tcp/14052"
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] New listen address: /ip4/127.0.0.1/tcp/14052
[2022-03-16T18:14:52Z DEBUG libp2p_swarm] Listener ListenerId(1); New address: "/ip4/127.0.0.1/tcp/14052"        
Now Listening | "/ip4/127.0.0.1/tcp/14052"
[2022-03-16T18:14:52Z INFO  libp2p_mdns::behaviour::iface] creating instance on iface 26.191.225.201
[2022-03-16T18:14:52Z INFO  libp2p_mdns::behaviour::iface] creating instance on iface 192.168.0.13
[2022-03-16T18:14:52Z INFO  libp2p_mdns::behaviour] discovered: 12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4 /ip4/26.191.225.201/tcp/14051
[2022-03-16T18:14:52Z INFO  libp2p_mdns::behaviour] discovered: 12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4 /ip4/192.168.0.13/tcp/14051  
[2022-03-16T18:14:52Z INFO  libp2p_mdns::behaviour] discovered: 12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4 /ip4/127.0.0.1/tcp/14051
New Peer | PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4") | "/ip4/26.191.225.201/tcp/14051"
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Adding explicit peer 12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Connecting to explicit peer PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4")
New Peer | PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4") | "/ip4/192.168.0.13/tcp/14051"
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Adding explicit peer 12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Connecting to explicit peer PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4")
New Peer | PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4") | "/ip4/127.0.0.1/tcp/14051"
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Adding explicit peer 12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4
[2022-03-16T18:14:52Z DEBUG libp2p_gossipsub::behaviour] Connecting to explicit peer PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4")
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] Incoming connection from /ip4/26.191.225.201/tcp/14053 at /ip4/26.191.225.201/tcp/14052
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: confirming protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: sent confirmed protocol: /noise
[2022-03-16T18:14:52Z DEBUG libp2p_dns] Dialing /ip4/26.191.225.201/tcp/14051/p2p/12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4
[2022-03-16T18:14:52Z DEBUG libp2p_dns] Dialing /ip4/26.191.225.201/tcp/14051/p2p/12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] dialing 26.191.225.201:14051
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] Incoming connection from /ip4/26.191.225.201/tcp/14054 at /ip4/26.191.225.201/tcp/14052
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] dialing 26.191.225.201:14051
[2022-03-16T18:14:52Z DEBUG libp2p_dns] Dialing /ip4/26.191.225.201/tcp/14051/p2p/12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] dialing 26.191.225.201:14051
[2022-03-16T18:14:52Z DEBUG libp2p_tcp] Incoming connection from /ip4/26.191.225.201/tcp/14055 at /ip4/26.191.225.201/tcp/14052
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: confirming protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: confirming protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: sent confirmed protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Proposed protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Proposed protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: sent confirmed protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Proposed protocol: /noise
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Received confirmation for protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Received confirmation for protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Received confirmation for protocol: /noise
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: confirming protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: confirming protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: sent confirmed protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Proposed protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: confirming protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: sent confirmed protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG multistream_select::listener_select] Listener: sent confirmed protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG yamux::connection] new connection: 9f0f0788 (Server)
[2022-03-16T18:14:52Z DEBUG yamux::connection] new connection: 002e49da (Server)
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG yamux::connection] new connection: 4d8ae107 (Server)
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Proposed protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG multistream_select::dialer_select] Dialer: Received confirmation for protocol: /yamux/1.0.0
[2022-03-16T18:14:52Z DEBUG yamux::connection] new connection: 4ad13229 (Client)
[2022-03-16T18:14:52Z DEBUG libp2p_core::upgrade::apply] Successfully applied negotiated protocol
[2022-03-16T18:14:52Z DEBUG libp2p_swarm] Connection established: PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4") Listener { local_addr: "/ip4/26.191.225.201/tcp/14052", send_back_addr: "/ip4/26.191.225.201/tcp/14055" }; Total (peer): 1. Total non-banned (peer): 1
...
[2022-03-16T18:16:47Z DEBUG libp2p_gossipsub::behaviour] HEARTBEAT: Mesh low. Topic: test-net Contains: 0 needs: 5
[2022-03-16T18:16:47Z DEBUG libp2p_gossipsub::behaviour] RANDOM PEERS: Got 0 peers
[2022-03-16T18:16:47Z DEBUG libp2p_gossipsub::behaviour] Updating mesh, new mesh: {}
[2022-03-16T18:16:47Z DEBUG libp2p_gossipsub::behaviour] Completed Heartbeat
[2022-03-16T18:16:52Z DEBUG libp2p_swarm] Connection closed with error KeepAliveTimeout: Connected { endpoint: Dialer { address: "/ip4/26.191.225.201/tcp/14051/p2p/12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4", role_override: Dialer }, peer_id: PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4") }; Total (peer): 1.
[2022-03-16T18:16:52Z DEBUG libp2p_swarm] Connection closed with error KeepAliveTimeout: Connected { endpoint: Listener { local_addr: "/ip4/26.191.225.201/tcp/14052", send_back_addr: "/ip4/26.191.225.201/tcp/14055" }, peer_id: PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4") }; Total (peer): 0.
[2022-03-16T18:16:52Z DEBUG libp2p_gossipsub::behaviour] Peer disconnected: 12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4
[2022-03-16T18:16:52Z INFO  libp2p_mdns::behaviour] expired: 12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4 /ip4/26.191.225.201/tcp/14051
[2022-03-16T18:16:52Z INFO  libp2p_mdns::behaviour] expired: 12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4 /ip4/192.168.0.13/tcp/14051
[2022-03-16T18:16:52Z INFO  libp2p_mdns::behaviour] expired: 12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4 /ip4/127.0.0.1/tcp/14051
Expired Peer | PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4") | "/ip4/26.191.225.201/tcp/14051"
Expired Peer | PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4") | "/ip4/192.168.0.13/tcp/14051"
Expired Peer | PeerId("12D3KooWNvVBGRaGZ2xc1s7yXsvMhcwrJZFMHYyHQMbmUMvQJiH4") | "/ip4/127.0.0.1/tcp/14051"
[2022-03-16T18:16:57Z DEBUG libp2p_gossipsub::behaviour] Starting heartbeat
[2022-03-16T18:16:57Z DEBUG libp2p_gossipsub::behaviour] HEARTBEAT: Mesh low. Topic: test-net Contains: 0 needs: 5
[2022-03-16T18:16:57Z DEBUG libp2p_gossipsub::behaviour] RANDOM PEERS: Got 0 peers
[2022-03-16T18:16:57Z DEBUG libp2p_gossipsub::behaviour] Updating mesh, new mesh: {}
[2022-03-16T18:16:57Z DEBUG libp2p_gossipsub::behaviour] Completed Heartbeat

Update: It seems that I found the reason why from 1 (or 2 minutes?) minute closes the connection. It's idle_timeout of Gossipsub. The time a connection is maintained to a peer without being in the mesh and without send/receiving a message from. Connections that idle beyond this timeout are disconnected. Default is 120 seconds.

So, how can I add a peer to the mesh without dialing? Only dial?

Jerrody avatar Mar 16 '22 18:03 Jerrody

So, how can I add a peer to the mesh without dialing? Only dial?

You should be able to subscribe to the same topic.

mxinden avatar Mar 18 '22 14:03 mxinden

Let me know if still an issue.

thomaseizinger avatar Mar 29 '23 11:03 thomaseizinger