d242c2f37e
Codex changes: delegate hidden service management to the actual Tor backend instead of generating keys the wallet never served. The new AttachToBackendService() reads the hostname Tor creates, and the torrc/process plumbing properly gates HiddenService directives behind the -torhiddenservice flag. Additional fixes: - Back up hs_ed25519_secret_key (96 bytes) to wallet.dat so the onion identity survives deletion of tor_data/ - Restore the key before Tor starts so the same .onion address is regenerated automatically - Add ThreadTorMaintenance: checks Tor health every 30s, auto-restarts with exponential backoff on crash, re-attaches the hidden service and re-registers the onion address with AddLocal() - Seeder maintenance: every 30 min re-announces to peers and refreshes known seeder lists (when -torseeder is enabled) - Clean up ScheduleSeederReannouncement() stub (real work now in thread) - Respect -torsocks port in onion proxy registration Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
72 lines
1.8 KiB
C++
72 lines
1.8 KiB
C++
// Copyright (c) 2024-2025 Triangles developers
|
|
// Tor Process Manager - launches and manages an external Tor binary
|
|
// Distributed under the MIT/X11 software license
|
|
|
|
#ifndef TRIANGLES_TOR_PROCESS_H
|
|
#define TRIANGLES_TOR_PROCESS_H
|
|
|
|
#include <string>
|
|
|
|
#ifdef WIN32
|
|
#include <windows.h>
|
|
#endif
|
|
|
|
// Manages starting/stopping an external Tor process
|
|
// Provides SOCKS5 proxy for .onion connectivity and v3 hidden service
|
|
class CTorProcess
|
|
{
|
|
private:
|
|
std::string torBinaryPath;
|
|
std::string torDataDir;
|
|
std::string torrcPath;
|
|
int socksPort;
|
|
int hiddenServicePort;
|
|
bool hiddenServiceEnabled;
|
|
bool running;
|
|
|
|
#ifdef WIN32
|
|
HANDLE hProcess;
|
|
DWORD processId;
|
|
#else
|
|
pid_t processId;
|
|
#endif
|
|
|
|
// Find the Tor binary in standard locations
|
|
std::string FindTorBinary();
|
|
|
|
// Generate torrc configuration file
|
|
bool WriteTorrc();
|
|
|
|
// Check if SOCKS port is already in use (another Tor running)
|
|
bool IsPortInUse(int port);
|
|
|
|
public:
|
|
CTorProcess();
|
|
~CTorProcess();
|
|
|
|
// Start the Tor process
|
|
// Returns true if Tor was started or is already running
|
|
bool Start(const std::string& dataDir, int socksPort = 19099, int hsPort = 24112, bool enableHiddenService = true);
|
|
|
|
// Stop the Tor process
|
|
void Stop();
|
|
|
|
// Check if Tor is running
|
|
bool IsRunning();
|
|
|
|
// Get the SOCKS proxy address
|
|
std::string GetSocksProxy() const;
|
|
|
|
// Get the Tor binary path (for diagnostics)
|
|
std::string GetBinaryPath() const { return torBinaryPath; }
|
|
|
|
// Singleton access
|
|
static CTorProcess* GetInstance();
|
|
};
|
|
|
|
// Global convenience functions
|
|
bool StartTorProcess(const std::string& dataDir, int socksPort = 19099, int hsPort = 24112, bool enableHiddenService = true);
|
|
void StopTorProcess();
|
|
|
|
#endif // TRIANGLES_TOR_PROCESS_H
|