Browse Source

enable SSU2 server

pull/1742/head
orignal 3 years ago
parent
commit
21c1ec9c8c
  1. 5
      daemon/Daemon.cpp
  2. 7
      libi2pd/RouterInfo.cpp
  3. 19
      libi2pd/SSU2.cpp
  4. 9
      libi2pd/Transports.cpp
  5. 2
      libi2pd/Transports.h

5
daemon/Daemon.cpp

@ -1,5 +1,5 @@ @@ -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 @@ -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 @@ -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

7
libi2pd/RouterInfo.cpp

@ -1223,11 +1223,12 @@ namespace data @@ -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)

19
libi2pd/SSU2.cpp

@ -11,6 +11,7 @@ @@ -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 @@ -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;
}
}

9
libi2pd/Transports.cpp

@ -157,7 +157,7 @@ namespace transport @@ -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 @@ -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 @@ -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));

2
libi2pd/Transports.h

@ -87,7 +87,7 @@ namespace transport @@ -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; }

Loading…
Cancel
Save