Search code examples
ipfs

`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:

connect failure: dial attempt failed: context deadline exceeded.

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",

Solution

  • I believe you don't have to open API and Gateway ports to be able to connect to your peer. Instead, just try checking your connectivity from the outside:

    telnet x.x.x.x yyyy 
    
    #Trying x.x.x.x...
    #Connected to x.x.x.x.
    #Escape character is '^]'.
    #/multistream/1.0.0
    

    You can see the port in Addresses section of IPFS config, in my case it's 4001:

      "Addresses": {
        "Swarm": [
          "/ip4/0.0.0.0/tcp/4001",
          "/ip6/::/tcp/4001"
        ],
    

    but since the host is behind NAT, the actual IP where it can be accessed can't be detected by IPFS daemon, so I had to put it to Announce section, like

    "Announce": ["/ip4/z.z.z.z/tcp/4001"],
    

    After finding the right IP and port, I was able to connect:

    ipfs swarm connect /ip4/z.z.z.z/tcp/4001/ipfs/QmXXX_my_peer_id_XXX
    #connect QmXXX_my_peer_id_XXX success