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
fixing NAT establish mapping logic #2583
base: master
Are you sure you want to change the base?
Conversation
Please flesh out the PR description, explaining how this fixes the issue you encountered. |
Ready |
I see. Unfortunately, I don't think this is being fixed in the right place. It would be better to:
Otherwise, we'll still fail if, e.g., we fail to detect a NAT on start. |
@Stebalien Perhaps it is not necessary to try to re-set upnp ports if it failed the first time? After all, if it's 4G, it will only load the CPU. For an example on Android, there is such a notification:
|
We need a new method for the host to force upnp ports to be reopened. But about that in the new pr. |
I think it's reasonable to provide some external hook to tell libp2p to go "check for new addresses", but IMO, it's not something we should rely on. For example, laptop users will frequently switch networks without such external input. |
@Stebalien We have to do it this way. That's what all the other systems and known libraries do. For example - https://www.libtorrent.org/single-page-ref.html#reopen-network-sockets. This is a standard. |
Checking once every few minutes? We already do that when a NAT is available. This is likely the least of our concerns. |
@Stebalien Once a minute now. Yes. It's a waste of CPU and energy. I've been using a Libp2p-based music player on my Galaxy S22Ultra phone for about a month now, and I can see that it is only necessary to reduce the Libp2p load. If we increase it, it will already be noticeable for the devices. |
My artificial intelligence tells me that Windows has such a callback too :) And I hope the other systems have it too. |
libp2p in general, and go-libp2p in specific, is not designed to be run on mobile devices. Running a libp2p stack on a phone is not a good idea precisely due to battery considerations (there are further problems that come with the frequent network changes of mobile devices). This is not a use case we are going to optimize for. |
Laptops are mobile devices, too. |
There are many processes in libp2p that run more than once a minute. Even with your patch, NAT detection will continue to run at a regular interval as long as it detects a NAT the first time (e.g., you start your day at home on your home wifi). The only thing I'm asking here is to apply the same retry logic consistently and I'm not interested in accepting a patch that only half-fixes the problem. If you need battery savings, the correct solution is to suspend/stop the entire libp2p process when you don't need networking. This once-a-minute NAT check is nothing compared to the regular heartbeats and background chatter go-libp2p will otherwise produce. |
@Stebalien Your library is very similar in functionality to https://www.libtorrent.org . Why don't you adopt experience of Libtorrent, which has been written and used by billions of people all over the world for a long time? Stopping Libp2p will cause problems with the DHT. Therefore a temporary shutdown is not possible. Ok, I'll see what I can do about the loop, but I don't really like creating a load on the CPU for made up reasons. |
This isn't a made-up reason, please stop and think about why we're asking for this before continuing to argue. If you believe libtorrent will provide you a better experience, I suggest you use it. |
@Stebalien My mobile app has both Libtorrent and Libp2p. And many different, other libraries. Yes. I understand you want to avoid the scenario where discoverGateway fails the first time. That's why I said I'd look into it. It's a very rare case, but it's theoretically possible. |
@Stebalien Good news. In practice, this code is enough. It is not necessary to add new logic. |
If the router's Internet connection is interrupted and then restored, upnp ports are not reopened. With this code, if an error occurs, an attempt is made to retrieve the ip address and all the necessary data to re-announce the upnp ports.
#2502