lightningnetwork / lnd

Lightning Network Daemon ⚡️
MIT License
7.63k stars 2.07k forks source link

[feature-request] option for network type priority (ipv4, ipv6, onion) for outbound connections #6081

Open xmrk-btc opened 2 years ago

xmrk-btc commented 2 years ago

The title should be self-explanatory, I imagine an option like --network_priority=ipv6,onion,ipv4 This would mean that ipv6 is tried first, then onion address, and only then ipv4.

Similar issue: https://github.com/lightningnetwork/lnd/issues/2387 , but it is about totally forbidding some network types, while I want to prioritize. Perhaps both feature requests could be satisfied by omitting some network, so for example --network_priority=ipv6,onion would mean to prefer ipv6, then try onion, but never try ipv4.

Tor has similar options, for example ClientPreferIPv6ORPort.

Note that this is orthogonal to tor.skip-proxy-for-clearnet-targets, we can prefer ipv6 address, but then connect through clearnet or through tor . But I do not see this new network_priority option useful with tor.skip-proxy-for-clearnet-targets=0.

Motivation

I am trying to minimize number of outbound IPv4 connections, because they have to go through NAT, and my router seems to have problems with too many of such connections. So I want to prefer IPv6 when possible (no NAT needed). I am using tor.skip-proxy-for-clearnet-targets=1, mostly because I encountered a node which only has ipv4 address and does not allow connecting via tor.

xmrk-btc commented 2 years ago

Note that I am no longer interested in this feature request, as I placed my node directly on IPv4 network (no router, no NAT, public IPv4 address). And my primary motivation was to solve #6097, which now seems to be lnd bug (I may be wrong).

But it still may be interesting for someone else. For example, I had an ISP-provided router which stopped working and had to be restarted when certain number (I guess 50-100) of simultaneous TCP connections were made. That ISP was IPv4-only, so I would have to use tor, but combination of IPv6-ready ISP and similar router would make the proposed feature interesting.

C-Otto commented 2 years ago

I run a node that announces IPv4, IPv6, and tor. Of currently 270 connected peers, 0 use IPv6 and 22 are connected via tor. Strangely, 115 peers are connected via tor exit nodes in the 185.220.0.0/24 subnet.

Based on this I believe IPv6 is not attempted if IPv4 is available (which is the case on virtuall all systems). I also believe tor is not prioritized even if the local node is tor-only. It might be better (faster? more reliable?) to use a tor-to-tor connection instead of tor-to-IPv4.

kroese commented 2 years ago

@C-Otto Tor-to-tor is 6 hops and tor-to-IPv4 is only 3 hops, so the latency is a lot lower on the latter. But since exit-nodes have a limited bandwith the throughput can be higher on tor-to-tor in some cases.

I really wonder how the current priority works, because in the code I cannot find any rules for it. It just connects to addresses in an array, and it seems more of a coincidence that ipv4 comes first in that array.

Maybe @Roasbeef or one of the other devs can shed some light on this?