diff options
| author | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-13 15:24:10 -0300 |
|---|---|---|
| committer | Nsable-sh <nsable-sh@noreply.git.bitflash.network> | 2026-08-13 15:58:42 -0300 |
| commit | 5309170e567f4a8655b3b622e7b26b6d8b382942 (patch) | |
| tree | 3d7fa8c459fb3b493b878f68b85cb53b7c16659e /src/net.cpp | |
| parent | 8e21e8ca0b8d50c29376bc2f0a89575baa477213 (diff) | |
net: add onion-only btf dial mode
Diffstat (limited to 'src/net.cpp')
| -rw-r--r-- | src/net.cpp | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/net.cpp b/src/net.cpp index 6bc3c1c..997a2bd 100644 --- a/src/net.cpp +++ b/src/net.cpp | |||
| @@ -65,6 +65,8 @@ deque<pair<int64, CInv> > vRelayExpiration; | |||
| 65 | CCriticalSection cs_mapRelay; | 65 | CCriticalSection cs_mapRelay; |
| 66 | map<CInv, int64> mapAlreadyAskedFor; | 66 | map<CInv, int64> mapAlreadyAskedFor; |
| 67 | string strBtfConnect; // .btf peer to keep connected to (from /connectbtf) | 67 | string strBtfConnect; // .btf peer to keep connected to (from /connectbtf) |
| 68 | bool fBtfOnionOnly = false; // require direct onion transport for .btf peers | ||
| 69 | static const int BTF_ONION_CONNECT_TIMEOUT_SECS = 120; | ||
| 68 | 70 | ||
| 69 | int nPeersWatched = 0; | 71 | int nPeersWatched = 0; |
| 70 | int64 nBlocksReceived = 0; | 72 | int64 nBlocksReceived = 0; |
| @@ -1022,7 +1024,8 @@ static CNode* ConnectNodeBtfTail(const string& strBtfAddr, const unsigned char p | |||
| 1022 | if (SplitHostPort(strOnionNorm, strOnionHost, nOnionPort)) | 1024 | if (SplitHostPort(strOnionNorm, strOnionHost, nOnionPort)) |
| 1023 | { | 1025 | { |
| 1024 | BtfChurnNoteDialAttempt(strBtfAddr, strOnionNorm); | 1026 | BtfChurnNoteDialAttempt(strBtfAddr, strOnionNorm); |
| 1025 | SOCKET hOnionSocket = BtfConnectSocket(strOnionHost, nOnionPort, SOCK_ONION_PEER, 20); | 1027 | SOCKET hOnionSocket = BtfConnectSocket(strOnionHost, nOnionPort, SOCK_ONION_PEER, |
| 1028 | BTF_ONION_CONNECT_TIMEOUT_SECS); | ||
| 1026 | if (hOnionSocket != INVALID_SOCKET) | 1029 | if (hOnionSocket != INVALID_SOCKET) |
| 1027 | { | 1030 | { |
| 1028 | if (fDebug) | 1031 | if (fDebug) |
| @@ -1040,12 +1043,23 @@ static CNode* ConnectNodeBtfTail(const string& strBtfAddr, const unsigned char p | |||
| 1040 | return pnode; | 1043 | return pnode; |
| 1041 | } | 1044 | } |
| 1042 | if (fDebug) | 1045 | if (fDebug) |
| 1043 | LogPrint("net", "ConnectNodeBtf: direct onion to %s at %s failed, falling back to rendezvous\n", | 1046 | LogPrint("net", "ConnectNodeBtf: direct onion to %s at %s failed%s\n", |
| 1044 | strBtfAddr.c_str(), strOnionNorm.c_str()); | 1047 | strBtfAddr.c_str(), strOnionNorm.c_str(), |
| 1048 | fBtfOnionOnly ? "" : ", falling back to rendezvous"); | ||
| 1045 | BtfChurnNoteDialResult(strBtfAddr, strOnionNorm, false); | 1049 | BtfChurnNoteDialResult(strBtfAddr, strOnionNorm, false); |
| 1050 | if (fBtfOnionOnly) | ||
| 1051 | return NULL; | ||
| 1046 | } | 1052 | } |
| 1047 | } | 1053 | } |
| 1048 | 1054 | ||
| 1055 | if (fBtfOnionOnly) | ||
| 1056 | { | ||
| 1057 | if (fDebug) | ||
| 1058 | LogPrint("net", "ConnectNodeBtf: onion-only mode refused rendezvous fallback for %s\n", | ||
| 1059 | strBtfAddr.c_str()); | ||
| 1060 | return NULL; | ||
| 1061 | } | ||
| 1062 | |||
| 1049 | BtfChurnNoteDialAttempt(strBtfAddr, strMeeting); | 1063 | BtfChurnNoteDialAttempt(strBtfAddr, strMeeting); |
| 1050 | string strHost; | 1064 | string strHost; |
| 1051 | unsigned short nPort = 0; | 1065 | unsigned short nPort = 0; |
| @@ -2012,6 +2026,11 @@ bool StartNode(string& strError) | |||
| 2012 | // IP address, and port for the socket that is being bound | 2026 | // IP address, and port for the socket that is being bound |
| 2013 | int nRetryLimit = 15; | 2027 | int nRetryLimit = 15; |
| 2014 | struct sockaddr_in sockaddr = addrLocalHost.GetSockAddr(); | 2028 | struct sockaddr_in sockaddr = addrLocalHost.GetSockAddr(); |
| 2029 | // Keep addrLocalHost as this node's advertised address, but listen on all | ||
| 2030 | // local interfaces. Managed Tor forwards hidden-service traffic to | ||
| 2031 | // 127.0.0.1:<port>, and binding only to the LAN address made that onion | ||
| 2032 | // endpoint unreachable even though the P2P listener was running. | ||
| 2033 | sockaddr.sin_addr.s_addr = INADDR_ANY; | ||
| 2015 | if (bind(hListenSocket, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) == SOCKET_ERROR) | 2034 | if (bind(hListenSocket, (struct sockaddr*)&sockaddr, sizeof(sockaddr)) == SOCKET_ERROR) |
| 2016 | { | 2035 | { |
| 2017 | int nErr = WSAGetLastError(); | 2036 | int nErr = WSAGetLastError(); |