Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AutoNAT doesn't work in ipfs when using swarm key #7067

Closed
aloknerurkar opened this issue Apr 1, 2020 · 15 comments
Closed

AutoNAT doesn't work in ipfs when using swarm key #7067

aloknerurkar opened this issue Apr 1, 2020 · 15 comments
Labels
kind/bug A bug in existing code (including security flaws)

Comments

@aloknerurkar
Copy link

aloknerurkar commented Apr 1, 2020

Version information:

ipfs version --all
go-ipfs version: 0.4.23-6ce9a35
Repo version: 7
System version: amd64/darwin
Golang version: go1.13.8

config file. Enabled AutoNAT. Also enabled quic.

{
  "Identity": {
    "PeerID": "QmatWUFpQZo1ZUb7tvhQom8tA8QutiPby9uaeuWf7qbRcx",
    "PrivKey": "XXX"
  },
  "Datastore": {
    "StorageMax": "10GB",
    "StorageGCWatermark": 90,
    "GCPeriod": "1h",
    "Spec": {
      "mounts": [
        {
          "child": {
            "path": "blocks",
            "shardFunc": "/repo/flatfs/shard/v1/next-to-last/2",
            "sync": true,
            "type": "flatfs"
          },
          "mountpoint": "/blocks",
          "prefix": "flatfs.datastore",
          "type": "measure"
        },
        {
          "child": {
            "compression": "none",
            "path": "datastore",
            "type": "levelds"
          },
          "mountpoint": "/",
          "prefix": "leveldb.datastore",
          "type": "measure"
        }
      ],
      "type": "mount"
    },
    "HashOnRead": false,
    "BloomFilterSize": 0
  },
  "Addresses": {
    "Swarm": [
      "/ip4/0.0.0.0/tcp/4001",
      "/ip6/::/tcp/4001"
    ],
    "Announce": [],
    "NoAnnounce": [],
    "API": "/ip4/127.0.0.1/tcp/5001",
    "Gateway": "/ip4/127.0.0.1/tcp/8080"
  },
  "Mounts": {
    "IPFS": "/ipfs",
    "IPNS": "/ipns",
    "FuseAllowOther": false
  },
  "Discovery": {
    "MDNS": {
      "Enabled": true,
      "Interval": 10
    }
  },
  "Routing": {
    "Type": "dht"
  },
  "Ipns": {
    "RepublishPeriod": "",
    "RecordLifetime": "",
    "ResolveCacheSize": 128
  },
  "Bootstrap": [
    "/dnsaddr/bootstrap.libp2p.io/ipfs/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN",
    "/dnsaddr/bootstrap.libp2p.io/ipfs/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa",
    "/dnsaddr/bootstrap.libp2p.io/ipfs/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb",
    "/dnsaddr/bootstrap.libp2p.io/ipfs/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt",
    "/ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3N8SzbUtfsmvsqQLuvuJ",
    "/ip4/104.236.179.241/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
    "/ip4/128.199.219.111/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
    "/ip4/104.236.76.40/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
    "/ip4/178.62.158.247/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd",
    "/ip6/2604:a880:1:20::203:d001/tcp/4001/ipfs/QmSoLPppuBtQSGwKDZT2M73ULpjvfd3aZ6ha4oFGL1KrGM",
    "/ip6/2400:6180:0:d0::151:6001/tcp/4001/ipfs/QmSoLSafTMBsPKadTEgaXctDQVcqN88CNLHXMkTNwMKPnu",
    "/ip6/2604:a880:800:10::4a:5001/tcp/4001/ipfs/QmSoLV4Bbm51jM9C4gDYZQ9Cy3U6aXMJDAbzgu2fzaDs64",
    "/ip6/2a03:b0c0:0:1010::23:1001/tcp/4001/ipfs/QmSoLer265NRgSp2LA3dPaeykiS1J6DifTC88f5uVQKNAd"
  ],
  "Gateway": {
    "HTTPHeaders": {
      "Access-Control-Allow-Headers": [
        "X-Requested-With",
        "Range",
        "User-Agent"
      ],
      "Access-Control-Allow-Methods": [
        "GET"
      ],
      "Access-Control-Allow-Origin": [
        "*"
      ]
    },
    "RootRedirect": "",
    "Writable": false,
    "PathPrefixes": [],
    "APICommands": [],
    "NoFetch": false
  },
  "API": {
    "HTTPHeaders": {}
  },
  "Swarm": {
    "AddrFilters": null,
    "DisableBandwidthMetrics": false,
    "DisableNatPortMap": false,
    "DisableRelay": false,
    "EnableRelayHop": false,
    "EnableAutoRelay": false,
    "EnableAutoNATService": true,
    "ConnMgr": {
      "Type": "basic",
      "LowWater": 600,
      "HighWater": 900,
      "GracePeriod": "20s"
    }
  },
  "Pubsub": {
    "Router": "",
    "DisableSigning": false,
    "StrictSignatureVerification": false
  },
  "Reprovider": {
    "Interval": "12h",
    "Strategy": "all"
  },
  "Experimental": {
    "FilestoreEnabled": false,
    "UrlstoreEnabled": false,
    "ShardingEnabled": false,
    "Libp2pStreamMounting": false,
    "P2pHttpProxy": false,
    "QUIC": true,
    "PreferTLS": false
  }
}

Description:

According to bug 6251, AutoNAT should work when using a swarm key. However, I don't see this happening.

LIBP2P_FORCE_PNET=1 ipfs daemon                                                            
Initializing daemon...                                                                                                                         
go-ipfs version: 0.4.23-6ce9a35                                                                                                                
Repo version: 7                                                                                                                                
System version: amd64/darwin                                                                                                                   
Golang version: go1.13.8                                                                                                                       
Swarm is limited to private network of peers with the swarm key                                                                                
Swarm key fingerprint: d4574a64137198e7c6c8366f77e37e46                                                                                        
Swarm listening on /ip4/127.0.0.1/tcp/4001                                                                                                     
Swarm listening on /ip4/192.168.0.98/tcp/4001                                                                                                  
Swarm listening on /ip6/::1/tcp/4001                                                                                                           
Swarm listening on /ip6/fd01::18eb:9ca2:8968:d339/tcp/4001                                                                                     
Swarm listening on /ip6/fd01::39c2:943c:4774:db16/tcp/4001                                                                                     
Swarm listening on /p2p-circuit                                                                                                                
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/192.168.0.98/tcp/4001
Swarm announcing /ip6/::1/tcp/4001
Swarm announcing /ip6/fd01::18eb:9ca2:8968:d339/tcp/4001
Swarm announcing /ip6/fd01::39c2:943c:4774:db16/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
WebUI: http://127.0.0.1:5001/webui
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready

Whereas when I don't use swarm key, I see the NAT traversal happening.

ipfs daemon         
Initializing daemon...
go-ipfs version: 0.4.23-6ce9a35
Repo version: 7
System version: amd64/darwin
Golang version: go1.13.8
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/192.168.0.98/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /ip6/fd01::18eb:9ca2:8968:d339/tcp/4001
Swarm listening on /ip6/fd01::39c2:943c:4774:db16/tcp/4001
Swarm listening on /p2p-circuit
Swarm announcing /ip4/106.51.29.204/tcp/21683 => The public IP announced
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/192.168.0.98/tcp/4001
Swarm announcing /ip6/::1/tcp/4001
Swarm announcing /ip6/fd01::18eb:9ca2:8968:d339/tcp/4001
Swarm announcing /ip6/fd01::39c2:943c:4774:db16/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
WebUI: http://127.0.0.1:5001/webui
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready

Please try to include:

  • What you were doing when you experienced the bug.
  • Any error messages you saw, where you saw them, and what you believe may have caused them (if you have any ideas).
  • When possible, steps to reliably produce the bug.
    -->
    I was using an older version to get this feature working for p2p file sharing. I tried updating to the latest public release and still doesn't work. Let me know if you need any other information.
@aloknerurkar aloknerurkar added the kind/bug A bug in existing code (including security flaws) label Apr 1, 2020
@Stebalien
Copy link
Member

With swarm key:

LIBP2P_FORCE_PNET=1 ipfs daemon                                                            
Initializing daemon...                                                                                                                         
go-ipfs version: 0.4.23-6ce9a35                                                                                                                
Repo version: 7                                                                                                                                
System version: amd64/darwin                                                                                                                   
Golang version: go1.13.8                                                                                                                       
Swarm is limited to private network of peers with the swarm key                                                                                
Swarm key fingerprint: d4574a64137198e7c6c8366f77e37e46                                                                                        
Swarm listening on /ip4/127.0.0.1/tcp/4001                                                                                                     
Swarm listening on /ip4/192.168.0.98/tcp/4001                                                                                                  
Swarm listening on /ip6/::1/tcp/4001                                                                                                           
Swarm listening on /ip6/fd01::18eb:9ca2:8968:d339/tcp/4001                                                                                     
Swarm listening on /ip6/fd01::39c2:943c:4774:db16/tcp/4001                                                                                     
Swarm listening on /p2p-circuit                                                                                                                
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/192.168.0.98/tcp/4001
Swarm announcing /ip6/::1/tcp/4001
Swarm announcing /ip6/fd01::18eb:9ca2:8968:d339/tcp/4001
Swarm announcing /ip6/fd01::39c2:943c:4774:db16/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
WebUI: http://127.0.0.1:5001/webui
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready

Without swarm key:

ipfs daemon         
Initializing daemon...
go-ipfs version: 0.4.23-6ce9a35
Repo version: 7
System version: amd64/darwin
Golang version: go1.13.8
Swarm listening on /ip4/127.0.0.1/tcp/4001
Swarm listening on /ip4/192.168.0.98/tcp/4001
Swarm listening on /ip6/::1/tcp/4001
Swarm listening on /ip6/fd01::18eb:9ca2:8968:d339/tcp/4001
Swarm listening on /ip6/fd01::39c2:943c:4774:db16/tcp/4001
Swarm listening on /p2p-circuit
Swarm announcing /ip4/106.51.29.204/tcp/21683 => The public IP announced
Swarm announcing /ip4/127.0.0.1/tcp/4001
Swarm announcing /ip4/192.168.0.98/tcp/4001
Swarm announcing /ip6/::1/tcp/4001
Swarm announcing /ip6/fd01::18eb:9ca2:8968:d339/tcp/4001
Swarm announcing /ip6/fd01::39c2:943c:4774:db16/tcp/4001
API server listening on /ip4/127.0.0.1/tcp/5001
WebUI: http://127.0.0.1:5001/webui
Gateway (readonly) server listening on /ip4/127.0.0.1/tcp/8080
Daemon is ready

@Stebalien
Copy link
Member

Note: QUIC does not work with private networks at the moment.

@Stebalien
Copy link
Member

Which version worked?

@aloknerurkar
Copy link
Author

Both the experiments are on the same version. Its the latest version. I updated using homebrew.
go-ipfs version: 0.4.23-6ce9a35

I was able to bind to /ip4/106.51.29.204/tcp/21683 without the swarm key.

But with the swarm key, it was not able to bind to this address.

QUIC I just enabled to check if it makes any difference. Without the swarm key, its able to bind using TCP. So I am guessing this shouldn't make a difference?

@Stebalien
Copy link
Member

You said you upgraded from a previous version and it worked there, that's why I asked. Did this not work before?

@aloknerurkar
Copy link
Author

No.. sorry for the confusion... It was not working in the older version (v0.4.21) also. I tried updating to see if the latest version (v0.4.23) has this fixed. But no luck.

Before the lockdown, we did not have too many problems connecting while working together. Since the lockdown; the true power of P2P is being tested. Now we are not able to directly connect to each other. We have to work around this by using a relay. But then, we don't want other nodes to use their bandwidth for transfers ideally.

Since filing this bug, I just tried cloning the master and building from scratch. And that seems to work as expected. I can see NAT traversal happening. Not sure if the autonat_svc has some fixes which might have solved this.

@RubenKelevra
Copy link
Contributor

Now we are not able to directly connect to each other. We have to work around this by using a relay. But then, we don't want other nodes to use their bandwidth for transfers ideally.

A quick fix would be a static forwarding of a port to a private network IP and adding the public IP or a DynDNS hostname with the static forwarding port to the bootstrap-list. :)

@Stebalien
Copy link
Member

The autonat service does have some fixes, but I don't actually think that's related. We discover the external address through a different mechanism (observed addresses sent back in the "identify" handshake). AutoNAT is just used to determine if your node can actually be reached at one of your guessed addresses.

Note: It could also have to do with how many nodes you have running. We require that three peers observe the same external address before we start advertising it.

@aloknerurkar
Copy link
Author

@Stebalien I think that's the problem. We don't have enough bootstrap nodes it seems! The problem goes away when we bootstrap with IPFS bootstrap addresses.

With the swarm key, as we don't connect to the bootstrap peers, we just don't have enough peers. That's why we are not able to see the address. I could not find this in the documentation anywhere. I was not completely aware of how this works.

One thing I have observed is the EnableAutoNATService enabled/disabled doesn't really affect the behavior? Maybe a good time to clarify the use of this config param.

Closing the issue

@Stebalien
Copy link
Member

Yep: libp2p/go-libp2p#559

@aloknerurkar
Copy link
Author

@Stebalien so after setting up more bootstrap nodes, I was able to get my node to advertise the public IP. But I am still not able to connect with other peers directly. My home router shows its public IP as 10.243... This means there is another level of NAT between me and my service provider. Even after setting up port forwarding rules in my router, I have the same result.

Been reading about this, and it seems ipfs has still not solved this problem completely? I am able to connect using the alternative, which is p2p-circuit, but this is not the ideal solution for us.

Is there anything else I can try to make this work? My config doesn't have the websocket listener. Will the ws transport in libp2p help solve this? I want to use go-ipfs and not the js version.

I am living in India... The extra level of NAT seems to be a common problem here. This would be a huge blocker for us. Any help would be highly appreciated!

@aloknerurkar
Copy link
Author

Now we are not able to directly connect to each other. We have to work around this by using a relay. But then, we don't want other nodes to use their bandwidth for transfers ideally.

A quick fix would be a static forwarding of a port to a private network IP and adding the public IP or a DynDNS hostname with the static forwarding port to the bootstrap-list. :)

Is there some kind of doc for this? Or even example project?

@Stebalien
Copy link
Member

Been reading about this, and it seems ipfs has still not solved this problem completely? I am able to connect using the alternative, which is p2p-circuit, but this is not the ideal solution for us.

Correct. The ideal solution would be for ISPs to not do that but that's harder. However, you might be able to convince your ISP to give you a public address, or convince them to forward a port for you. However, that depends on your ISP.

Alternatively, IPv6 may work (if supported by your ISP). You may be able to open a port in your router for IPv6. Our current port-forwarding protocols don't support ipv6 but a contributor has been working on that (libp2p/go-nat#17).

We've been slowly working towards a middle-ground where one would use a relay to setup the connection then switch to a direct connection. However, we have a ways to go there. For example, our relay transport really doesn't scale well.

Is there anything else I can try to make this work? My config doesn't have the websocket listener. Will the ws transport in libp2p help solve this? I want to use go-ipfs and not the js version.

Unfortunately, it won't help.

@susarlanikhilesh
Copy link
Contributor

Note: QUIC does not work with private networks at the moment.

I'm using go-ipfs version: 0.6.0 (ipfs.exe version). When I start ipfs daemon, I can see the list addresses along with quic addresses too. But when I add my swarm.key for private connection and then run the ipfs daemon, I don't find the quic addresses listening.

In version 0.5.0 then mentioned that QUIC still doesn't work with private networks. But in version 0.6.0, I didn't find any particular details if it fixed or still the same as version 0.5.0.

Can you please clarify on this?

Thank you

@Stebalien
Copy link
Member

But when I add my swarm.key for private connection and then run the ipfs daemon, I don't find the quic addresses listening.

Our QUIC transport does not currently support private networks, and will be disabled when private networks are enabled. A change to this will be noted in the release notes when it happens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws)
Projects
None yet
Development

No branches or pull requests

4 participants