diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index ecbf60de..1f85835c 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,5 +1,3 @@ -file(GLOB I2PD_SOURCES "i2pd/daemon/*.cpp" "i2pd/libi2pd/*.cpp" "i2pd/libi2pd_client/*.cpp" "i2pd/i18n/*.cpp") - add_library(quirc STATIC quirc/lib/decode.c quirc/lib/identify.c @@ -9,9 +7,5 @@ add_library(quirc STATIC set_target_properties(quirc PROPERTIES POSITION_INDEPENDENT_CODE ON) target_include_directories(quirc PUBLIC quirc/lib) -add_library(i2pd STATIC - ${I2PD_SOURCES} -) -set_target_properties(i2pd PROPERTIES POSITION_INDEPENDENT_CODE ON) -target_include_directories(i2pd PUBLIC i2pd/daemon i2pd/libi2pd i2pd/libi2pd_client i2pd/i18n) -target_compile_definitions(i2pd PUBLIC WIN32_LEAN_AND_MEAN) \ No newline at end of file +option(WITH_BINARY "" OFF) +add_subdirectory(i2pd/build) diff --git a/pages/settings/SettingsNetwork.qml b/pages/settings/SettingsNetwork.qml index 534b661a..11be437c 100644 --- a/pages/settings/SettingsNetwork.qml +++ b/pages/settings/SettingsNetwork.qml @@ -116,6 +116,7 @@ Rectangle { function startI2PD() { + /* var noSync = false; //these args will be deleted because DaemonManager::start will re-add them later. //removing '--tx-proxy=i2p,...' lets us blindly add '--tx-proxy i2p,...' later without risking duplication. @@ -147,8 +148,9 @@ Rectangle { } var success = daemonManager.start(allArgs.join(" "), persistentSettings.nettype, persistentSettings.blockchainDataDir, persistentSettings.bootstrapNodeAddress, noSync, persistentSettings.pruneBlockchain) if (success) { - i2pdManager.start(); - } + */ + i2pdManager.start(); + //} } function stopI2PD() diff --git a/src/i2pd/CMakeLists.txt b/src/i2pd/CMakeLists.txt index 568d8769..ab402399 100644 --- a/src/i2pd/CMakeLists.txt +++ b/src/i2pd/CMakeLists.txt @@ -1,5 +1,20 @@ add_library(i2p STATIC I2PDManager.cpp ) -find_package(ZLIB) -target_link_libraries(i2p PRIVATE i2pd ZLIB::ZLIB) + +find_package(ZLIB REQUIRED) + +target_include_directories(i2p + PRIVATE + "../../external/i2pd/libi2pd" + "../../external/i2pd/libi2pd_client" + "../../external/i2pd/i18n" +) + +target_link_libraries(i2p + PRIVATE + libi2pdclient + libi2pd + libi2pdlang + ZLIB::ZLIB +) diff --git a/src/i2pd/I2PDManager.cpp b/src/i2pd/I2PDManager.cpp index dcfa33b0..56515a23 100644 --- a/src/i2pd/I2PDManager.cpp +++ b/src/i2pd/I2PDManager.cpp @@ -27,7 +27,23 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "I2PDManager.h" -#include "../../external/i2pd/daemon/Daemon.h" + +#include "../../external/i2pd/libi2pd/Config.h" +#include "../../external/i2pd/libi2pd/FS.h" +#include "../../external/i2pd/libi2pd/Base.h" +#include "../../external/i2pd/libi2pd/version.h" +#include "../../external/i2pd/libi2pd/Transports.h" +#include "../../external/i2pd/libi2pd/RouterInfo.h" +#include "../../external/i2pd/libi2pd/RouterContext.h" +#include "../../external/i2pd/libi2pd/Tunnel.h" +#include "../../external/i2pd/libi2pd/HTTP.h" +#include "../../external/i2pd/libi2pd/NetDb.hpp" +#include "../../external/i2pd/libi2pd/Garlic.h" +#include "../../external/i2pd/libi2pd/Streaming.h" +#include "../../external/i2pd/libi2pd/Destination.h" +#include "../../external/i2pd/libi2pd_client/ClientContext.h" +#include "../../external/i2pd/libi2pd/Crypto.h" + #include #include #include @@ -53,7 +69,7 @@ I2PDManager::I2PDManager(QObject *parent) std::string dataDir = "--datadir=" + m_i2pdDataDir.toStdString(); std::vector argv({"i2pd", dataDir.data()}); - Daemon.init(argv.size(), (char**) argv.data()); + init(argv.size(), (char**) argv.data()); } I2PDManager::~I2PDManager() @@ -61,22 +77,143 @@ I2PDManager::~I2PDManager() } +void I2PDManager::init(int argc, char* argv[]) +{ + i2p::config::Init(); + i2p::config::ParseCmdline(argc, argv); + + std::string datadir; + i2p::config::GetOption("datadir", datadir); + i2p::fs::DetectDataDir(datadir, false); + i2p::fs::Init(); + + i2p::config::Finalize(); + + std::string certsdir; i2p::config::GetOption("certsdir", certsdir); + i2p::fs::SetCertsDir(certsdir); + certsdir = i2p::fs::GetCertsDir(); + + bool precomputation; i2p::config::GetOption("precomputation.elgamal", precomputation); + bool aesni; i2p::config::GetOption("cpuext.aesni", aesni); + bool avx; i2p::config::GetOption("cpuext.avx", avx); + bool forceCpuExt; i2p::config::GetOption("cpuext.force", forceCpuExt); + bool ssu; i2p::config::GetOption("ssu", ssu); + if (!ssu && i2p::config::IsDefault ("precomputation.elgamal")) + precomputation = false; // we don't elgamal table if no ssu, unless it's specified explicitly + i2p::crypto::InitCrypto(precomputation, aesni, avx, forceCpuExt); + + i2p::transport::InitAddressFromIface(); // get address4/6 from interfaces + + int netID; i2p::config::GetOption("netid", netID); + i2p::context.SetNetID(netID); + i2p::context.Init(); + + i2p::transport::InitTransports(); + + bool isFloodfill; i2p::config::GetOption("floodfill", isFloodfill); + if (isFloodfill) + { + i2p::context.SetFloodfill (true); + } + else + i2p::context.SetFloodfill (false); + + bool transit; i2p::config::GetOption("notransit", transit); + i2p::context.SetAcceptsTunnels (!transit); + uint16_t transitTunnels; i2p::config::GetOption("limits.transittunnels", transitTunnels); + if (isFloodfill && i2p::config::IsDefault ("limits.transittunnels")) + transitTunnels *= 2; // double default number of transit tunnels for floodfill + i2p::tunnel::tunnels.SetMaxNumTransitTunnels (transitTunnels); + + /* this section also honors 'floodfill' flag, if set above */ + std::string bandwidth; i2p::config::GetOption("bandwidth", bandwidth); + if (bandwidth.length () > 0) + { + if (bandwidth[0] >= 'K' && bandwidth[0] <= 'X') + { + i2p::context.SetBandwidth (bandwidth[0]); + } + else + { + auto value = std::atoi(bandwidth.c_str()); + if (value > 0) + { + i2p::context.SetBandwidth (value); + } + else + { + i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_LOW_BANDWIDTH2); + } + } + } + else if (isFloodfill) + { + i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_EXTRA_BANDWIDTH2); + } + else + { + i2p::context.SetBandwidth (i2p::data::CAPS_FLAG_LOW_BANDWIDTH2); + } + + int shareRatio; i2p::config::GetOption("share", shareRatio); + i2p::context.SetShareRatio (shareRatio); + + std::string family; i2p::config::GetOption("family", family); + i2p::context.SetFamily(family); +} + void I2PDManager::start() { if (!isRunning()) { - Daemon.start(); - Daemon.running; + i2p::data::netdb.Start(); + + bool nettime; i2p::config::GetOption("nettime.enabled", nettime); + if (nettime) + { + m_NTPSync = std::unique_ptr(new i2p::util::NTPTimeSync); + m_NTPSync->Start(); + } + + bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2); + bool ssu2; i2p::config::GetOption("ssu2.enabled", ssu2); + bool checkInReserved; i2p::config::GetOption("reservedrange", checkInReserved); + + i2p::transport::transports.SetCheckReserved(checkInReserved); + i2p::transport::transports.Start(ntcp2, ssu2); + if (!(i2p::transport::transports.IsBoundSSU2() || i2p::transport::transports.IsBoundNTCP2())) + { + i2p::transport::transports.Stop(); + i2p::data::netdb.Stop(); + return; + } + + i2p::tunnel::tunnels.Start(); + i2p::context.Start(); + i2p::client::context.Start(); } } void I2PDManager::stop() { if (isRunning()) { - Daemon.stop(); + i2p::client::context.Stop(); + i2p::context.Stop(); + i2p::tunnel::tunnels.Stop(); + + if (m_NTPSync) + { + m_NTPSync->Stop (); + m_NTPSync = nullptr; + } + + i2p::transport::transports.Stop(); + i2p::data::netdb.Stop(); + i2p::crypto::TerminateCrypto(); } } bool I2PDManager::isRunning() const { - return Daemon.running; + //return m_isRunning; + return false; } diff --git a/src/i2pd/I2PDManager.h b/src/i2pd/I2PDManager.h index 37ed0170..49e37989 100644 --- a/src/i2pd/I2PDManager.h +++ b/src/i2pd/I2PDManager.h @@ -30,6 +30,7 @@ #define I2PDMANAGER_H #include +#include "../../external/i2pd/libi2pd/Timestamp.h" class I2PDManager : public QObject { @@ -45,7 +46,10 @@ public: Q_INVOKABLE bool isRunning() const; private: + void init(int argc, char* argv[]); QString m_i2pdDataDir; + std::unique_ptr m_NTPSync; + bool m_isRunning; }; #endif // I2PDMANAGER_H