lbryio / lbry-sdk

The LBRY SDK for building decentralized, censorship resistant, monetized, digital content apps.
https://lbry.com
MIT License
7.2k stars 483 forks source link

Detect if internet connection is through a carrier grade NAT (starlink) #3652

Open jackrobison opened 1 year ago

jackrobison commented 1 year ago

Users who have starlink internet (as well as many mobile networks) are not able to have reliable connectivity because these services use a CGNAT and constantly have their external ip address changing. The sdk can detect this by checking the interface address against the CARRIER_GRADE_NAT_SUBNET ip range. This can be used to disable blob announcement where it won't be effective and to alert the user that they can't be connected to from the outside.

Detection of the CGNAT might be trickier on starlink connections with a wifi network (the default they ship with, vs ethernet with passthrough) as the interface address will appear to be a normal private lan address. I'm not sure if the wifi router will reply to aioupnp - if it does it probably gives the CGNAT address (this can be tested).

jackrobison commented 1 year ago

@shyba pointed out a user on an isp with CGNAT who routes through a remote VPN will be connectable and would be a false positive by this metric.

moodyjon commented 1 year ago

Recently happened across this bit of code:

https://github.com/lbryio/lbry-sdk/blob/f7455600cc03918de0221198053a9246cd69a9e3/lbry/utils.py#L374

It's being used to identify KademliaPeer objects with an invalid IP:

https://github.com/lbryio/lbry-sdk/blob/f7455600cc03918de0221198053a9246cd69a9e3/lbry/dht/peer.py#L179

Some attempt is being made to exclude CGNAT addresses, but I am not clear how the ValueError exception(s) are being handled. These addrs may be kept out of the routing table, but the blob announcer would not know that they're being kept out.