What would cause an "all dials failed" or "connected to wrong peer" error?

I’m trying to connect to a node, but getting the error:

failed to dial : all dials failed
          * [/ip4/40.117.153.33/tcp/30363] dial tcp4 40.117.153.33:30363: connect: connection refused

When trying to connect to another node, I get:

 p2p_test.go:209: failed to dial : all dials failed
          * [/ip4/104.211.48.247/tcp/30363] failed to negotiate security protocol: connected to wrong peer

In my code, I create a host, then connect to a node:

	ip := "0.0.0.0"

	addr, err := ma.NewMultiaddr(fmt.Sprintf("/ip4/%s/tcp/%d", ip, sc.Port))
	if err != nil {
		return nil, err
	}

	ctx := context.Background()
    opts := []libp2p.Option{
		libp2p.ListenAddrs(addr),
	}
	h, err := libp2p.New(ctx, opts...)
	if err != nil {
		return nil, err
	}

	nodeAddr, err := ma.NewMultiaddr("/ip4/40.117.153.33/tcp/30363/p2p/QmPiGU1jwL9UDw2FMyMQFr9FdpF9hURKxkfy6PWw6aLsur")
	if err != nil {
		t.Fatal(err)
	}
	addrInfo, err := peer.AddrInfoFromP2pAddr(nodeAddr)
	if err != nil {
		t.Fatal(err)
	}
	err = h.Connect(ctx, *addrInfo)
	if err != nil {
		t.Fatal(err)
	}

Searching the error didn’t seem to give me anything relevant. Any pointers would be appreciated! Not sure if I’m just missing something obvious. If it makes a difference, the node I’m trying to connect to is using rust-libp2p.

Hey @noot! Thanks for using the libp2p discussion forums.

I’m having the same issue when connecting to that node. It looks like it’s running in Azure. Are you sure you’ve opened up that port for inbound traffic? You should also disable the firewall on that machine, or add an exception to whitelist that port.

What’s the full multiaddr you’re using to connect to that peer? I don’t see it in your test code. It may contain the wrong peer ID – as the error message indicates.

Hey @raul :slight_smile: I don’t actually have control of the first node, but I’ll ask and see.

For these two addresses, I get “connect to wrong peer”:

"/ip4/104.211.48.51/tcp/30363/p2p/QmYWrEtg4iQYwV9PG37PhfLHLATQJUTYiZRyoUvSYny9ba"     
 "/ip4/104.211.48.247/tcp/30363/p2p/QmYT3p4qGj1jwb7hDx1A6cDzAPtaHp3VR34vmw5BsXXB8D"

That’s because you have wrong peer IDs for these nodes:

  • peer ID of 104.211.48.247: 16Uiu2HAkyhNWHTPcA2dVKzMnLpFebXqsDQMpkuGnS9SqjJyDyULi
  • peer ID of 104.211.48.51: 16Uiu2HAmJqVCtF5oMvu1rbJvqWubMMRuWiKJtpoM8KSQ3JNnL5Ec

I suggest double-checking with the operator of those nodes.

Weird, ok, thanks for your help. I will double-check. How did you figure out the correct peer ID for the nodes?

Also @raul, how do I access the protocols/stream protocols that are supported by peers? I tried using host.Peerstore().ProtoBook but that doesn’t seem to be accessible.

By enabling the DEBUG level (env variable IPFS_LOGGING=DEBUG // TODO: need to change var name), you should see this log statement from the secio logger:

Both peers need to support the Identify protocol. You need to wait a little until that completes (once merge the stabilize branch which emits the EvtPeerIdentificationCompleted event on the eventbus once identify completes, you will be able to subscribe to that). Then you can query the Peerstore via host.Peerstore().GetProtocols(id).

Great, thank you! The debug logs are really helpful. I’m also using the DHT to discover peers, any idea what this means?
16:27:06.566 DEBUG dht: discarding dialled peer because of error: context canceled dial_queue.go:328
Seeing it a lot, wondering if it’s an issue.

When do you expect the stabilize branch to be merged?

You might be passing in a too short-lived context.Context. What’s the deadline?

When do you expect the stabilize branch to be merged?

Hopefully soon – in the next weeks.

I’m using context.Background which shouldn’t have a deadline. It looks like it’s finding peers okay though, so I don’t think it’s a huge issue.

Is there a function for the DHT that triggers upon discovering a new peer? I’d like to do something like dht.OnPeerFound( // do something). Would it be best to use dht.GetClosestPeers()?