Ipfs swarm connect: connect failure: dial attempt failed: context deadline exceeded

I am using IPFS version 0.4.4.

My goal is to connect two peers in order to prevent IPFS peer to halt on reading an IPFS-hash from the shared peer. In order to achieve it, I am using ipfs swarm connect to connect peer-A to peer-B, where peer-B can access ipfs-file on peer-A.

My question is related to:

ipfs swarm connect /ip4/x.x.x.x/tcp/4003/ipfs/QmXXXXXXXXXXXXXXXXXXX

When I try to connect my laptop to another IPFS-peer, I face with following error:

But when I try on an Amazon AWS where all the ports are open, it works, hence swarm connect ended as success.

[Q] In order to make ipfs swarm connect work should API and Gateway port should be open? or should I do something else?

For example should: port 5001 and 8080 be open no matter what?

.ipfs/config file:

"API": "/ip4/127.0.0.1/tcp/5001",
"Gateway": "/ip4/127.0.0.1/tcp/8080",

In order to connect to the peer you should only need the swarm address (not the API or Gateway address) to be open. By default on my nodes it’s using port 4001, but you can check your config file (or use ipfs config Addresses.Swarm) for which port the daemon is configured to listen on.

There’s more discussion on this here: How should I configure my firewall?

It’s possible there might be something else you need to do if you’re using a more complicated network setup than simply opening the swam port

I’d recommend updating IPFS to 0.4.13 as it has many enhancements and fixes not present in earlier versions. 0.4.14 is also pretty close to being released. 0.4.4 was released more than a year ago in Oct 2016.

1 Like

@leerspace , by default my node is using 4001 as well but I am not still convinced. I have tested on a node (port 4001 was not open) but given port for Gateway and API was open, it was able to connect another IPFS-node. But when I give port# for Gateaway and API that is not open, it was not able to connect to the IPFS-node.

So it may listen on default port but I guess Gateway and API should be open no matter what in order to establish a successful connection to a IPFS-node.

Please don’t open up the connection for the API to the public as with that endpoint exposed, anyone can control your node. It’s not needed to have ports open for the gateway or API for the node to be able to connect to other nodes, only the swarm port is needed for that.

Try to open up the port and also upgrade your go-ipfs version, as there have been many new releases with lots of improvements since the version you’re using.

1 Like

@VictorBjelkholm ipfs swarm connect still returns an error with the latest version. failure: dial attempt failed: context deadline exceeded.

How could I detect the error, or why this is happening? I could not understand the reason :frowning:

I can provide you the node’s ipfs-address for you to try to connect?

Can you try to connect using netcat? If the port is open and the connection works correctly, you should see /multistream/1.0.0 as the first message

This example shows connecting the public gateways (you can do CTRL+C after seeing the multistream message)

$ nc gateway-int.ipfs.io 4001
/multistream/1.0.0

Replace gateway-int.ipfs.io 4001 with your IP and your port (defaults to 4001, only use 4003 if you made a choice to change it by changing the config)

1 Like

I tried my two different nodes, one returned /multistream/1.0.0 other returned an empty string. So can I conclude that if $ nc gateway-int.ipfs.io 4001 returns /multistream/1.0.0 , I can connect to that node, but if it returns an empty line I cannot. @VictorBjelkholm

Basically, if you don’t see the initial multistream message, you’re connecting to something that is not IPFS swarm, so your IPFS node won’t be able to connect to it.

1 Like

If my node returns an empty string for nc gateway-int.ipfs.io 4001 command, and timeout for ipfs swarm connect what should I do for it to return /multistream/1.0.0. I have double checked that its IP address and port number (default #= 4001) is correct and ipfs daemon is running on the background. @VictorBjelkholm

For anyone who might read through this discussion in the future, the solution is in this discussion: About IPFS establish connection