shermand100 / PiNodeXMR

Monero Node for Single Board Computers with Web Interface and additional tools pre-configured. Self Installing.
GNU General Public License v3.0
213 stars 40 forks source link

Fix Tor p2p and ipv4 p2p inbound connections #111

Closed ff0255 closed 2 months ago

ff0255 commented 3 months ago

Hello and thank you for this project! o/ There is a lot of info on the Internet on running monerod+Tor, but some is outdated. It seems that up to date info is here: https://github.com/monero-project/monero/blob/master/docs/ANONYMITY_NETWORKS.md I have tested this fix on my node. Before this fix I had only Tor outbound connections (running over a month):

~$ monerod print_cn ...
2024-04-20 20:59:15.591 I Monero 'Fluorine Fermi' (v0.18.3.3-release)
Remote Host                   Type    SSL   Peer id             Support Flags       Recv/Sent (inactive,sec)      State                    Livetime(sec)       Down (kB/s) Down(now)     Up (kB/s) Up(now)      
...
OUT :                         Tor     no    0000000000000001    0                   50543(28)/26294(28)           normal                   116                 0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   91335(44)/28305(44)           normal                   500                 0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   25860(6)/108308(6)            normal                   995                 0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   42655(12)/185927(12)          normal                   1240                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   115865(98)/31131(99)          normal                   1473                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   67408(54)/261855(1)           normal                   2671                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   45416(13)/218755(10)          normal                   3141                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   94632(86)/38137(86)           normal                   2207                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   78833(97)/51313(99)           normal                   3274                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   41499(96)/39763(99)           normal                   4122                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   59340(32)/201207(32)          normal                   4384                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   59832(28)/125200(27)          normal                   4485                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   124484(60)/129687(60)         normal                   4768                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   55347(12)/328956(12)          normal                   6267                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   63382(98)/220825(99)          normal                   6389                0           0             0         0            

Now I have both inbound and outbound (running several hours after fix):

~$ monerod print_cn  ...
2024-04-24 18:49:57.640 I Monero 'Fluorine Fermi' (v0.18.3.3-release)
Remote Host                   Type    SSL   Peer id             Support Flags       Recv/Sent (inactive,sec)      State                    Livetime(sec)       Down (kB/s) Down(now)     Up (kB/s) Up(now)      
...
OUT :                         Tor     no    0000000000000001    0                   10124(16)/38820(16)           normal                   206                 0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   42028(34)/36654(35)           normal                   1582                0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   90156(34)/50926(35)           normal                   5041                0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   138404(34)/49163(35)          normal                   7036                0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   427093(33)/66069(35)          normal                   9190                0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   539080(34)/66982(35)          normal                   9720                0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   160521(33)/67205(35)          normal                   9840                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   80796(19)/425788(19)          normal                   10727               0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   722376(34)/79003(35)          normal                   12403               0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   77600(33)/60961(35)           normal                   15376               0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   162964(34)/448706(4)          normal                   15787               0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   172959(8)/1714826(8)          normal                   16253               0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   158598(34)/1174298(35)        normal                   25843               0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   50970(10)/176461(10)          normal                   3431                0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   206125(34)/91735(35)          normal                   27515               0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   300513(11)/134976(11)         normal                   28364               0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   101010(34)/821576(35)         normal                   28731               0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   1374205(2)/119366(35)         normal                   29349               0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   206652(33)/148356(35)         normal                   38341               0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   166191(10)/1167975(5)         normal                   38859               0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   89877(33)/163304(35)          normal                   7523                0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   1423540(34)/212824(35)        normal                   41607               0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   203133(33)/993344(35)         normal                   43783               0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   1694158(31)/179374(35)        normal                   44090               0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   115996(32)/855318(33)         normal                   41584               0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   294657(31)/2466883(35)        normal                   56300               0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   24822(19)/42765(19)           normal                   1822                0           0             0         0            
OUT :                         Tor     no    0000000000000001    0                   291624(33)/2138483(35)        normal                   66341               0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   206219(0)/40647(35)           normal                   3173                0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   3265856(33)/310923(35)        normal                   78450               0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   4653412(11)/323432(11)        normal                   77778               0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   2505255(33)/264762(35)        normal                   79090               0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   2029381(31)/171994(35)        normal                   58146               0           0             0         0            
INC :                         Tor     no    0000000000000001    0                   3236102(32)/307578(35)        normal                   73592               0           0             0         0            

P.S. This is my first PR, please correct me if I'm doing something wrong. I changed only line 8 in those files but github auto removed whitespaces in line 31 for some reason... And now it looks like I changed it... But I didn't...

UPD Sorry, I didn't realize that my 3rd commit (inbound p2p ipv4) that I made after publishing this PR will be included here too... I need to learn github more...I guess there's no way to revert it on web-version of github. As far as I can see, the option "--p2p-bind-ip 127.0.0.1" is from outdated manuals with torsocks. Now we don't use it. And I doubt that we need "TORSOCKS_ALLOW_INBOUND=1" This fix is also tested on my node, p2p ipv4 INC is working, but I'm not an IT expert, so maybe there are some privacy/security issues related to it?

shermand100 commented 3 months ago

Thanks for looking into this. Yes we have always used the https://github.com/monero-project/monero/blob/master/docs/ANONYMITY_NETWORKS.md manual for our settings in the past and it's understandable the have been updated over the years. I'll also say that the master/docs/ANONYMITY_NETWORKS.md manual was pretty obscure in the past too and it took quite a bit of trial and error testing.

I've got friday evening free to test this. I can't see a reason not to merge this and the tor incoming connections may improve stability overall. I'll use this opportunity to further test/update tor settings and bring things up to date.

ff0255 commented 3 months ago

You're welcome :^) I thought to separate this 3 commits into 2 pull requests (tor and ipv4), but at the moment can't figure out github workflow and division into right branches. Feel free to correct me.

shermand100 commented 3 months ago

Ok, still working on this and reminds me of how slow tor is.

So a slight tweak in using port 28083 (instead of previous 18083 - as used before zmq had greater adoption due to P2Pool mining). This could also allow in future for a tor-ified zmq hidden service rule. I don't see a need for it just yet but best keep the port clear.

This is technically good to merge, as per the PR title but I'm tempted to spend a bit longer researching and optimising anything that can increase connection reliability and speed of Wallet RPC connections? (My Monerujo wallet with Orbot is sketchy and intermittent)

shermand100 commented 2 months ago

@ff0255 Sorry got side-tracked. Will merge this in the next 24 hours unless you have any other input? Then will keep an open issue to try and optimise the RPC connection stability/speed.

ff0255 commented 2 months ago

Sorry got side-tracked.

@shermand100 Sorry, me too. I don't see anything bad in changing port number to 28083, except maybe one suggestion... that somebody might get confused thinking it's testnet node (default ports: 2808* for testnet https://getmonero.dev/infrastructure/networks.html) Аlthough I'm not sure about the relevance of that documentation. Anyway I think it's OK to use 28083. Unfortunately I can't help with optimisation of RPC connection. Usually I test it in Tor browser (it shows stats page if RPC works). I tried to test RPC with Monerujo, but unfortunately Monerujo is crashing on my device. Maybe later when I resolve issues with Monerujo I'll try to test again.

shermand100 commented 2 months ago

Yeah understood. Where possible I try not to deviate from anything in the official Monero project documentation as I don't want us to "do our own thing". When issues arise it helps to be "default" as it massively helps troubleshooting. Currently the Anonymity docs use port 28083 in their examples:

https://github.com/monero-project/monero/blob/master/docs/ANONYMITY_NETWORKS.md#inbound-connections

I'd think it best to mirror their example and change if they do. There's often good reason for it.

I too am struggling with RPC optimisations and wonder if it's the Monerujo app. However I recently learnt that the Cake wallet uses the came core wallet RPC code so unless the base code gets a rework I feel there are limited choices for testing alternative wallets.