Sia icon indicating copy to clipboard operation
Sia copied to clipboard

Slow UPnP startup

Open lukechampine opened this issue 7 years ago • 8 comments

Currently we call upnp.Discover on each startup to discover our external IP address and/or forward ports. Discover is a slow call that advertises your computer to the whole LAN and waits 2-3 seconds for your router to respond. We can eliminate this delay by using upnp.Load to connect to the router directly.

Building blocks:

  • We call upnp.Discover here in the gateway and here in the host.
  • After each upnp.Discover call, use the d.Location() method to get the address of the router.
  • The address will have to be saved on disk. Ask Sia core team members for help with this part.
  • On startup, first try to call upnp.Load on the saved address. If that fails, fallback to the upnp.Discover code.

lukechampine avatar Sep 08 '17 20:09 lukechampine

While this would speed up startup when UPnP is available, there will still be a failed discover() delay on a network that doesn't support UPnP. It would be nice to also have a --noUPnP flag to indicate that UPnP should be ignored entirely, ideally combined with an option what public IP to use to avoid being dependent on myexternalip.com.

fuffenz avatar Sep 12 '17 22:09 fuffenz

I just had a view into the quoted parts of the code. I was just wondering if there is a technical reason have the host and the gateway on different IP-Addresses or if they are the same anyway.

TobiasKar avatar Oct 24 '17 07:10 TobiasKar

They will typically be the same. The only reason we call Discover twice is that there isn't an easy way to share the result between the host and the gateway. Regardless, once we cache the lookup with Load, the overhead will shrink considerably.

lukechampine avatar Oct 24 '17 20:10 lukechampine

Ok, I will have a look into this feature request. Should only be some small changes. Which mechanism to you propose to the save the router's URL on the disk. Creating a seperate file for this string is like using a sledgehammer to crack a nut.

TobiasKar avatar Oct 29 '17 16:10 TobiasKar

Hi @TobiasKar

Are you still going to work on this? If not, can I takeover?

Cheers, Marc

mharkus avatar Mar 28 '18 22:03 mharkus

@mharkus: I suggest storing the router URL on disk alongside the gateway's node list. However, this will be a bit tricky. Currently, the gateway saves its nodes to a nodes.json file as a JSON array. We should instead save a gateway.json file containing both the array of nodes and the router URL. So we will need to write compatibility code to convert one to the other.

lukechampine avatar Mar 28 '18 22:03 lukechampine

@mharkus @TobiasKar are either of you still working on this issue?

MSevey avatar Jun 15 '18 17:06 MSevey

@mharkus Just go ahead. I have worked on this, but I was not happy with my solution. So I discarded it.

TobiasKar avatar Jun 18 '18 08:06 TobiasKar