diff --git a/daemon/Daemon.cpp b/daemon/Daemon.cpp index 2a0e85ee..2f1f7bcb 100644 --- a/daemon/Daemon.cpp +++ b/daemon/Daemon.cpp @@ -1,5 +1,5 @@ /* -* Copyright (c) 2013-2020, The PurpleI2P Project +* Copyright (c) 2013-2022, The PurpleI2P Project * * This file is part of Purple i2pd project and licensed under BSD3 * @@ -377,6 +377,7 @@ namespace util } bool ntcp2; i2p::config::GetOption("ntcp2.enabled", ntcp2); + bool ssu2; i2p::config::GetOption("ssu2.enabled", ssu2); bool ssu; i2p::config::GetOption("ssu", ssu); bool checkInReserved; i2p::config::GetOption("reservedrange", checkInReserved); LogPrint(eLogInfo, "Daemon: Starting Transports"); @@ -384,7 +385,7 @@ namespace util if(!ntcp2) LogPrint(eLogInfo, "Daemon: NTCP2 disabled"); i2p::transport::transports.SetCheckReserved(checkInReserved); - i2p::transport::transports.Start(ntcp2, ssu); + i2p::transport::transports.Start(ntcp2, ssu, ssu2); if (i2p::transport::transports.IsBoundSSU() || i2p::transport::transports.IsBoundNTCP2()) LogPrint(eLogInfo, "Daemon: Transports started"); else diff --git a/libi2pd/RouterInfo.cpp b/libi2pd/RouterInfo.cpp index 4f1338fa..ceabe964 100644 --- a/libi2pd/RouterInfo.cpp +++ b/libi2pd/RouterInfo.cpp @@ -1223,11 +1223,12 @@ namespace data } } - if (address.IsNTCP2 () && isPublished) + if ((address.IsNTCP2 () && isPublished) || address.IsSSU2 ()) { - // publish i for NTCP2 + // publish i for NTCP2 or SSU2 WriteString ("i", properties); properties << '='; - WriteString (address.i.ToBase64 (16), properties); properties << ';'; + size_t len = address.IsSSU2 () ? 32 : 16; + WriteString (address.i.ToBase64 (len), properties); properties << ';'; } if (isPublished || address.ssu) diff --git a/libi2pd/SSU2.cpp b/libi2pd/SSU2.cpp index b1c918b2..cfe5a04c 100644 --- a/libi2pd/SSU2.cpp +++ b/libi2pd/SSU2.cpp @@ -11,6 +11,7 @@ #include "Log.h" #include "RouterContext.h" #include "Transports.h" +#include "Config.h" #include "SSU2.h" namespace i2p @@ -210,9 +211,23 @@ namespace transport for (const auto& address: addresses) { if (!address) continue; - if (address->transportStyle == i2p::data::RouterInfo::eTransportSSU2 && address->port) + if (address->transportStyle == i2p::data::RouterInfo::eTransportSSU2) { - OpenSocket (address->port); + auto port = address->port; + if (!port) + { + uint16_t ssu2Port; i2p::config::GetOption ("ssu2.port", ssu2Port); + if (ssu2Port) port = ssu2Port; + else + { + uint16_t p; i2p::config::GetOption ("port", p); + if (p) port = p; + } + } + if (port) + OpenSocket (port); + else + LogPrint (eLogError, "SSU2: Can't start server because port not specified "); break; } } diff --git a/libi2pd/Transports.cpp b/libi2pd/Transports.cpp index 097c3984..e9d69adf 100644 --- a/libi2pd/Transports.cpp +++ b/libi2pd/Transports.cpp @@ -157,7 +157,7 @@ namespace transport } } - void Transports::Start (bool enableNTCP2, bool enableSSU) + void Transports::Start (bool enableNTCP2, bool enableSSU, bool enableSSU2) { if (!m_Service) { @@ -217,7 +217,9 @@ namespace transport } } } - + // create SSU2 server + if (enableSSU2) m_SSU2Server = new SSU2Server (); + // bind to interfaces bool ipv4; i2p::config::GetOption("ipv4", ipv4); if (ipv4) @@ -282,7 +284,8 @@ namespace transport } if (m_SSUServer) DetectExternalIP (); } - + if (m_SSU2Server) m_SSU2Server->Start (); + m_PeerCleanupTimer->expires_from_now (boost::posix_time::seconds(5*SESSION_CREATION_TIMEOUT)); m_PeerCleanupTimer->async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1)); diff --git a/libi2pd/Transports.h b/libi2pd/Transports.h index 2a8dce15..eb9c5cc9 100644 --- a/libi2pd/Transports.h +++ b/libi2pd/Transports.h @@ -87,7 +87,7 @@ namespace transport Transports (); ~Transports (); - void Start (bool enableNTCP2=true, bool enableSSU=true); + void Start (bool enableNTCP2=true, bool enableSSU=true, bool enableSSU2=false); void Stop (); bool IsBoundSSU() const { return m_SSUServer != nullptr; }