7

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",
alper
  • 2,919
  • 9
  • 53
  • 102

1 Answers1

1

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
Utgarda
  • 686
  • 4
  • 23
  • Does `z.z.z.z` stands for the IP address? Inside `config` file I was not able to find `Announce` section. I guess you put it under `Addresses`. @Utgarda – alper Sep 23 '18 at 16:39
  • Yep, z.z.z.z. is an IP4 address. My IPFS version is `0.4.17`, and I had `Announce` right away in its generated config, it was empty, `"Announce": [],`. Try putting it after `"Swarm":[...],`. What's your IPFS version btw? – Utgarda Sep 23 '18 at 16:42
  • Well, what does your connectivity test show you? Try telnet from your IPFS host and outside it too. – Utgarda Sep 23 '18 at 16:49
  • What does `yyyy` stands for , is it 4001 on your example? `telnet x.x.x.x yyyy` returns `Trying x.x.x.x...` after I added Announce part. Please note that `Gateway` and `API` ports are closed on the machine that I am trying to connect into. @Utgarda – alper Sep 24 '18 at 08:37
  • I think `Swarm` port should be open no matter what in order to perform connection. Such as `4001` on your example. @Utgarda – alper Sep 24 '18 at 09:03
  • Definitely, I had to make sure my 4001 is open, while leaving gateway and API closed. So, if you can't connect to your swarm port from the outside, first check that it's used on the IPFS host - same trick with telnet, but from that same host, and/or `netstat -tulpn | grep 400` – Utgarda Sep 24 '18 at 11:31
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/180660/discussion-between-utgarda-and-alper). – Utgarda Sep 24 '18 at 11:51
  • 1
    Got it. This works as well: `sudo lsof -n -i :4001 | grep LISTEN` @Utgarda – alper Sep 24 '18 at 12:25
  • with the latest version of ipfs their address format is changed, they have something called `p2p`, `quic` and I started to have the same issue, is it possible for you to check the latest ipfs version 0.7.0 – alper Dec 23 '20 at 10:53