1
0
mirror of https://github.com/PurpleI2P/i2pd.git synced 2025-01-11 13:27:52 +00:00

enable SSU2 server

This commit is contained in:
orignal 2022-03-13 21:34:11 -04:00
parent 6d7d71bb16
commit 21c1ec9c8c
5 changed files with 31 additions and 11 deletions

View File

@ -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

View File

@ -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)

View File

@ -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;
}
}

View File

@ -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));

View File

@ -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; }