Sia
Sia copied to clipboard
Slow UPnP startup
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 thed.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 theupnp.Discover
code.
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.
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.
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.
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.
Hi @TobiasKar
Are you still going to work on this? If not, can I takeover?
Cheers, Marc
@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.
@mharkus @TobiasKar are either of you still working on this issue?
@mharkus Just go ahead. I have worked on this, but I was not happy with my solution. So I discarded it.