Browse Source

Merge pull request #1827 from PurpleI2P/openssl

recent changes
pull/1939/head
orignal 2 years ago committed by GitHub
parent
commit
9a2f744630
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      daemon/HTTPServer.cpp
  2. 14
      daemon/I2PControlHandlers.cpp
  3. 2
      daemon/I2PControlHandlers.h
  4. 25
      libi2pd/Identity.cpp
  5. 18
      libi2pd/SSU2.cpp
  6. 7
      libi2pd/SSU2Session.cpp
  7. 63
      libi2pd/Transports.cpp
  8. 17
      libi2pd/Transports.h

6
daemon/HTTPServer.cpp

@ -290,13 +290,13 @@ namespace http {
s << "<b>" << tr("Tunnel creation success rate") << ":</b> " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%<br>\r\n"; s << "<b>" << tr("Tunnel creation success rate") << ":</b> " << i2p::tunnel::tunnels.GetTunnelCreationSuccessRate () << "%<br>\r\n";
s << "<b>" << tr("Received") << ":</b> "; s << "<b>" << tr("Received") << ":</b> ";
ShowTraffic (s, i2p::transport::transports.GetTotalReceivedBytes ()); ShowTraffic (s, i2p::transport::transports.GetTotalReceivedBytes ());
s << " (" << (double) i2p::transport::transports.GetInBandwidth () / 1024 << " " << tr(/* tr: Kibibit/s */ "KiB/s") << ")<br>\r\n"; s << " (" << (double) i2p::transport::transports.GetInBandwidth15s () / 1024 << " " << tr(/* tr: Kibibit/s */ "KiB/s") << ")<br>\r\n";
s << "<b>" << tr("Sent") << ":</b> "; s << "<b>" << tr("Sent") << ":</b> ";
ShowTraffic (s, i2p::transport::transports.GetTotalSentBytes ()); ShowTraffic (s, i2p::transport::transports.GetTotalSentBytes ());
s << " (" << (double) i2p::transport::transports.GetOutBandwidth () / 1024 << " " << tr(/* tr: Kibibit/s */ "KiB/s") << ")<br>\r\n"; s << " (" << (double) i2p::transport::transports.GetOutBandwidth15s () / 1024 << " " << tr(/* tr: Kibibit/s */ "KiB/s") << ")<br>\r\n";
s << "<b>" << tr("Transit") << ":</b> "; s << "<b>" << tr("Transit") << ":</b> ";
ShowTraffic (s, i2p::transport::transports.GetTotalTransitTransmittedBytes ()); ShowTraffic (s, i2p::transport::transports.GetTotalTransitTransmittedBytes ());
s << " (" << (double) i2p::transport::transports.GetTransitBandwidth () / 1024 << " " << tr(/* tr: Kibibit/s */ "KiB/s") << ")<br>\r\n"; s << " (" << (double) i2p::transport::transports.GetTransitBandwidth15s () / 1024 << " " << tr(/* tr: Kibibit/s */ "KiB/s") << ")<br>\r\n";
s << "<b>" << tr("Data path") << ":</b> " << i2p::fs::GetUTF8DataDir() << "<br>\r\n"; s << "<b>" << tr("Data path") << ":</b> " << i2p::fs::GetUTF8DataDir() << "<br>\r\n";
s << "<div class='slide'>"; s << "<div class='slide'>";
if ((outputFormat == OutputFormatEnum::forWebConsole) || !includeHiddenContent) { if ((outputFormat == OutputFormatEnum::forWebConsole) || !includeHiddenContent) {

14
daemon/I2PControlHandlers.cpp

@ -33,7 +33,9 @@ namespace client
m_RouterInfoHandlers["i2p.router.netdb.knownpeers"] = &I2PControlHandlers::NetDbKnownPeersHandler; m_RouterInfoHandlers["i2p.router.netdb.knownpeers"] = &I2PControlHandlers::NetDbKnownPeersHandler;
m_RouterInfoHandlers["i2p.router.netdb.activepeers"] = &I2PControlHandlers::NetDbActivePeersHandler; m_RouterInfoHandlers["i2p.router.netdb.activepeers"] = &I2PControlHandlers::NetDbActivePeersHandler;
m_RouterInfoHandlers["i2p.router.net.bw.inbound.1s"] = &I2PControlHandlers::InboundBandwidth1S; m_RouterInfoHandlers["i2p.router.net.bw.inbound.1s"] = &I2PControlHandlers::InboundBandwidth1S;
m_RouterInfoHandlers["i2p.router.net.bw.inbound.15s"] = &I2PControlHandlers::InboundBandwidth15S;
m_RouterInfoHandlers["i2p.router.net.bw.outbound.1s"] = &I2PControlHandlers::OutboundBandwidth1S; m_RouterInfoHandlers["i2p.router.net.bw.outbound.1s"] = &I2PControlHandlers::OutboundBandwidth1S;
m_RouterInfoHandlers["i2p.router.net.bw.outbound.15s"] = &I2PControlHandlers::OutboundBandwidth15S;
m_RouterInfoHandlers["i2p.router.net.status"] = &I2PControlHandlers::NetStatusHandler; m_RouterInfoHandlers["i2p.router.net.status"] = &I2PControlHandlers::NetStatusHandler;
m_RouterInfoHandlers["i2p.router.net.tunnels.participating"] = &I2PControlHandlers::TunnelsParticipatingHandler; m_RouterInfoHandlers["i2p.router.net.tunnels.participating"] = &I2PControlHandlers::TunnelsParticipatingHandler;
m_RouterInfoHandlers["i2p.router.net.tunnels.successrate"] = &I2PControlHandlers::TunnelsSuccessRateHandler; m_RouterInfoHandlers["i2p.router.net.tunnels.successrate"] = &I2PControlHandlers::TunnelsSuccessRateHandler;
@ -153,12 +155,24 @@ namespace client
InsertParam (results, "i2p.router.net.bw.inbound.1s", bw); InsertParam (results, "i2p.router.net.bw.inbound.1s", bw);
} }
void I2PControlHandlers::InboundBandwidth15S (std::ostringstream& results)
{
double bw = i2p::transport::transports.GetInBandwidth15s ();
InsertParam (results, "i2p.router.net.bw.inbound.15s", bw);
}
void I2PControlHandlers::OutboundBandwidth1S (std::ostringstream& results) void I2PControlHandlers::OutboundBandwidth1S (std::ostringstream& results)
{ {
double bw = i2p::transport::transports.GetOutBandwidth (); double bw = i2p::transport::transports.GetOutBandwidth ();
InsertParam (results, "i2p.router.net.bw.outbound.1s", bw); InsertParam (results, "i2p.router.net.bw.outbound.1s", bw);
} }
void I2PControlHandlers::OutboundBandwidth15S (std::ostringstream& results)
{
double bw = i2p::transport::transports.GetOutBandwidth15s ();
InsertParam (results, "i2p.router.net.bw.outbound.15s", bw);
}
void I2PControlHandlers::NetTotalReceivedBytes (std::ostringstream& results) void I2PControlHandlers::NetTotalReceivedBytes (std::ostringstream& results)
{ {
InsertParam (results, "i2p.router.net.total.received.bytes", (double)i2p::transport::transports.GetTotalReceivedBytes ()); InsertParam (results, "i2p.router.net.total.received.bytes", (double)i2p::transport::transports.GetTotalReceivedBytes ());

2
daemon/I2PControlHandlers.h

@ -50,7 +50,9 @@ namespace client
void TunnelsParticipatingHandler (std::ostringstream& results); void TunnelsParticipatingHandler (std::ostringstream& results);
void TunnelsSuccessRateHandler (std::ostringstream& results); void TunnelsSuccessRateHandler (std::ostringstream& results);
void InboundBandwidth1S (std::ostringstream& results); void InboundBandwidth1S (std::ostringstream& results);
void InboundBandwidth15S (std::ostringstream& results);
void OutboundBandwidth1S (std::ostringstream& results); void OutboundBandwidth1S (std::ostringstream& results);
void OutboundBandwidth15S (std::ostringstream& results);
void NetTotalReceivedBytes (std::ostringstream& results); void NetTotalReceivedBytes (std::ostringstream& results);
void NetTotalSentBytes (std::ostringstream& results); void NetTotalSentBytes (std::ostringstream& results);

25
libi2pd/Identity.cpp

@ -49,29 +49,21 @@ namespace data
IdentityEx::IdentityEx(const uint8_t * publicKey, const uint8_t * signingKey, SigningKeyType type, CryptoKeyType cryptoType) IdentityEx::IdentityEx(const uint8_t * publicKey, const uint8_t * signingKey, SigningKeyType type, CryptoKeyType cryptoType)
{ {
/*uint8_t randomPaddingBlock[32]; uint8_t randomPaddingBlock[32];
RAND_bytes (randomPaddingBlock, 32);*/ RAND_bytes (randomPaddingBlock, 32);
if (cryptoType == CRYPTO_KEY_TYPE_ECIES_X25519_AEAD) if (cryptoType == CRYPTO_KEY_TYPE_ECIES_X25519_AEAD)
{ {
/*memcpy (m_StandardIdentity.publicKey, publicKey ? publicKey : randomPaddingBlock, 32); memcpy (m_StandardIdentity.publicKey, publicKey ? publicKey : randomPaddingBlock, 32);
for (int i = 0; i < 7; i++) // 224 bytes for (int i = 0; i < 7; i++) // 224 bytes
memcpy (m_StandardIdentity.publicKey + 32*(i + 1), randomPaddingBlock, 32);*/ memcpy (m_StandardIdentity.publicKey + 32*(i + 1), randomPaddingBlock, 32);
if (publicKey)
{
memcpy (m_StandardIdentity.publicKey, publicKey, 32);
RAND_bytes (m_StandardIdentity.publicKey + 32, 224);
}
else
RAND_bytes (m_StandardIdentity.publicKey, 256);
} }
else else
{ {
if (publicKey) if (publicKey)
memcpy (m_StandardIdentity.publicKey, publicKey, 256); memcpy (m_StandardIdentity.publicKey, publicKey, 256);
else else
RAND_bytes (m_StandardIdentity.publicKey, 256); for (int i = 0; i < 8; i++) // 256 bytes
/*for (int i = 0; i < 8; i++) // 256 bytes memcpy (m_StandardIdentity.publicKey + 32*i, randomPaddingBlock, 32);
memcpy (m_StandardIdentity.publicKey + 32*i, randomPaddingBlock, 32);*/
} }
if (type != SIGNING_KEY_TYPE_DSA_SHA1) if (type != SIGNING_KEY_TYPE_DSA_SHA1)
{ {
@ -110,9 +102,8 @@ namespace data
case SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519: case SIGNING_KEY_TYPE_REDDSA_SHA512_ED25519:
{ {
size_t padding = 128 - i2p::crypto::EDDSA25519_PUBLIC_KEY_LENGTH; // 96 = 128 - 32 size_t padding = 128 - i2p::crypto::EDDSA25519_PUBLIC_KEY_LENGTH; // 96 = 128 - 32
/*for (int i = 0; i < 3; i++) // 96 bytes for (int i = 0; i < 3; i++) // 96 bytes
memcpy (m_StandardIdentity.signingKey + 32*i, randomPaddingBlock, 32);*/ memcpy (m_StandardIdentity.signingKey + 32*i, randomPaddingBlock, 32);
RAND_bytes (m_StandardIdentity.signingKey, 96);
memcpy (m_StandardIdentity.signingKey + padding, signingKey, i2p::crypto::EDDSA25519_PUBLIC_KEY_LENGTH); memcpy (m_StandardIdentity.signingKey + padding, signingKey, i2p::crypto::EDDSA25519_PUBLIC_KEY_LENGTH);
break; break;
} }

18
libi2pd/SSU2.cpp

@ -236,7 +236,19 @@ namespace transport
void SSU2Server::HandleReceivedFrom (const boost::system::error_code& ecode, size_t bytes_transferred, void SSU2Server::HandleReceivedFrom (const boost::system::error_code& ecode, size_t bytes_transferred,
Packet * packet, boost::asio::ip::udp::socket& socket) Packet * packet, boost::asio::ip::udp::socket& socket)
{ {
if (!ecode) if (!ecode
|| ecode == boost::asio::error::connection_refused
|| ecode == boost::asio::error::connection_reset
|| ecode == boost::asio::error::network_unreachable
|| ecode == boost::asio::error::host_unreachable
#ifdef _WIN32 // windows can throw WinAPI error, which is not handled by ASIO
|| ecode.value() == boost::winapi::ERROR_CONNECTION_REFUSED_
|| ecode.value() == boost::winapi::ERROR_NETWORK_UNREACHABLE_
|| ecode.value() == boost::winapi::ERROR_HOST_UNREACHABLE_
#endif
)
// just try continue reading when received ICMP response otherwise socket can crash,
// but better to find out which host were sent it and mark that router as unreachable
{ {
i2p::transport::transports.UpdateReceivedBytes (bytes_transferred); i2p::transport::transports.UpdateReceivedBytes (bytes_transferred);
packet->len = bytes_transferred; packet->len = bytes_transferred;
@ -522,13 +534,15 @@ namespace transport
else else
it1->second->ProcessRetry (buf, len); it1->second->ProcessRetry (buf, len);
} }
else else if (!i2p::util::net::IsInReservedRange(senderEndpoint.address ()) && senderEndpoint.port ())
{ {
// assume new incoming session // assume new incoming session
auto session = std::make_shared<SSU2Session> (*this); auto session = std::make_shared<SSU2Session> (*this);
session->SetRemoteEndpoint (senderEndpoint); session->SetRemoteEndpoint (senderEndpoint);
session->ProcessFirstIncomingMessage (connID, buf, len); session->ProcessFirstIncomingMessage (connID, buf, len);
} }
else
LogPrint (eLogError, "SSU2: Incoming packet received from invalid endpoint ", senderEndpoint);
} }
} }

7
libi2pd/SSU2Session.cpp

@ -611,7 +611,7 @@ namespace transport
void SSU2Session::ProcessSessionRequest (Header& header, uint8_t * buf, size_t len) void SSU2Session::ProcessSessionRequest (Header& header, uint8_t * buf, size_t len)
{ {
// we are Bob // we are Bob
if (len < 80) if (len < 88)
{ {
LogPrint (eLogWarning, "SSU2: SessionRequest message too short ", len); LogPrint (eLogWarning, "SSU2: SessionRequest message too short ", len);
return; return;
@ -2477,14 +2477,9 @@ namespace transport
size_t paddingSize = rand () & 0x0F; // 0 - 15 size_t paddingSize = rand () & 0x0F; // 0 - 15
if (paddingSize + 3 > len) paddingSize = len - 3; if (paddingSize + 3 > len) paddingSize = len - 3;
else if (paddingSize + 3 < minSize) paddingSize = minSize - 3; else if (paddingSize + 3 < minSize) paddingSize = minSize - 3;
if (paddingSize)
{
buf[0] = eSSU2BlkPadding; buf[0] = eSSU2BlkPadding;
htobe16buf (buf + 1, paddingSize); htobe16buf (buf + 1, paddingSize);
memset (buf + 3, 0, paddingSize); memset (buf + 3, 0, paddingSize);
}
else
return 0;
return paddingSize + 3; return paddingSize + 3;
} }

63
libi2pd/Transports.cpp

@ -136,12 +136,14 @@ namespace transport
Transports::Transports (): Transports::Transports ():
m_IsOnline (true), m_IsRunning (false), m_IsNAT (true), m_CheckReserved(true), m_Thread (nullptr), m_IsOnline (true), m_IsRunning (false), m_IsNAT (true), m_CheckReserved(true), m_Thread (nullptr),
m_Service (nullptr), m_Work (nullptr), m_PeerCleanupTimer (nullptr), m_PeerTestTimer (nullptr), m_Service (nullptr), m_Work (nullptr), m_PeerCleanupTimer (nullptr), m_PeerTestTimer (nullptr),
m_SSU2Server (nullptr), m_NTCP2Server (nullptr), m_UpdateBandwidthTimer (nullptr), m_SSU2Server (nullptr), m_NTCP2Server (nullptr),
m_X25519KeysPairSupplier (15), // 15 pre-generated keys m_X25519KeysPairSupplier (15), // 15 pre-generated keys
m_TotalSentBytes(0), m_TotalReceivedBytes(0), m_TotalTransitTransmittedBytes (0), m_TotalSentBytes (0), m_TotalReceivedBytes (0), m_TotalTransitTransmittedBytes (0),
m_InBandwidth (0), m_OutBandwidth (0), m_TransitBandwidth(0), m_InBandwidth (0), m_OutBandwidth (0), m_TransitBandwidth (0),
m_LastInBandwidthUpdateBytes (0), m_LastOutBandwidthUpdateBytes (0), m_LastInBandwidthUpdateBytes (0), m_LastOutBandwidthUpdateBytes (0), m_LastTransitBandwidthUpdateBytes (0),
m_LastTransitBandwidthUpdateBytes (0), m_LastBandwidthUpdateTime (0) m_InBandwidth15s (0), m_OutBandwidth15s (0), m_TransitBandwidth15s (0),
m_LastInBandwidth15sUpdateBytes (0), m_LastOutBandwidth15sUpdateBytes (0), m_LastTransitBandwidth15sUpdateBytes (0),
m_LastBandwidth15sUpdateTime (0)
{ {
} }
@ -152,6 +154,7 @@ namespace transport
{ {
delete m_PeerCleanupTimer; m_PeerCleanupTimer = nullptr; delete m_PeerCleanupTimer; m_PeerCleanupTimer = nullptr;
delete m_PeerTestTimer; m_PeerTestTimer = nullptr; delete m_PeerTestTimer; m_PeerTestTimer = nullptr;
delete m_UpdateBandwidthTimer; m_UpdateBandwidthTimer = nullptr;
delete m_Work; m_Work = nullptr; delete m_Work; m_Work = nullptr;
delete m_Service; m_Service = nullptr; delete m_Service; m_Service = nullptr;
} }
@ -165,6 +168,7 @@ namespace transport
m_Work = new boost::asio::io_service::work (*m_Service); m_Work = new boost::asio::io_service::work (*m_Service);
m_PeerCleanupTimer = new boost::asio::deadline_timer (*m_Service); m_PeerCleanupTimer = new boost::asio::deadline_timer (*m_Service);
m_PeerTestTimer = new boost::asio::deadline_timer (*m_Service); m_PeerTestTimer = new boost::asio::deadline_timer (*m_Service);
m_UpdateBandwidthTimer = new boost::asio::deadline_timer (*m_Service);
} }
bool ipv4; i2p::config::GetOption("ipv4", ipv4); bool ipv4; i2p::config::GetOption("ipv4", ipv4);
@ -299,9 +303,12 @@ namespace transport
if (m_SSU2Server) m_SSU2Server->Start (); if (m_SSU2Server) m_SSU2Server->Start ();
if (m_SSU2Server) DetectExternalIP (); if (m_SSU2Server) DetectExternalIP ();
m_PeerCleanupTimer->expires_from_now (boost::posix_time::seconds(5*SESSION_CREATION_TIMEOUT)); 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)); m_PeerCleanupTimer->async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1));
m_UpdateBandwidthTimer->expires_from_now (boost::posix_time::seconds(1));
m_UpdateBandwidthTimer->async_wait (std::bind (&Transports::HandleUpdateBandwidthTimer, this, std::placeholders::_1));
if (m_IsNAT) if (m_IsNAT)
{ {
m_PeerTestTimer->expires_from_now (boost::posix_time::minutes(PEER_TEST_INTERVAL)); m_PeerTestTimer->expires_from_now (boost::posix_time::minutes(PEER_TEST_INTERVAL));
@ -357,29 +364,44 @@ namespace transport
} }
} }
void Transports::UpdateBandwidth () void Transports::HandleUpdateBandwidthTimer (const boost::system::error_code& ecode)
{
uint64_t ts = i2p::util::GetMillisecondsSinceEpoch ();
if (m_LastBandwidthUpdateTime > 0)
{ {
auto delta = ts - m_LastBandwidthUpdateTime; if (ecode != boost::asio::error::operation_aborted)
if (delta > 0)
{ {
m_InBandwidth = (m_TotalReceivedBytes - m_LastInBandwidthUpdateBytes)*1000/delta; // per second uint64_t ts = i2p::util::GetMillisecondsSinceEpoch ();
m_OutBandwidth = (m_TotalSentBytes - m_LastOutBandwidthUpdateBytes)*1000/delta; // per second
m_TransitBandwidth = (m_TotalTransitTransmittedBytes - m_LastTransitBandwidthUpdateBytes)*1000/delta; // updated every second
} m_InBandwidth = m_TotalReceivedBytes - m_LastInBandwidthUpdateBytes;
} m_OutBandwidth = m_TotalSentBytes - m_LastOutBandwidthUpdateBytes;
m_LastBandwidthUpdateTime = ts; m_TransitBandwidth = m_TotalTransitTransmittedBytes - m_LastTransitBandwidthUpdateBytes;
m_LastInBandwidthUpdateBytes = m_TotalReceivedBytes; m_LastInBandwidthUpdateBytes = m_TotalReceivedBytes;
m_LastOutBandwidthUpdateBytes = m_TotalSentBytes; m_LastOutBandwidthUpdateBytes = m_TotalSentBytes;
m_LastTransitBandwidthUpdateBytes = m_TotalTransitTransmittedBytes; m_LastTransitBandwidthUpdateBytes = m_TotalTransitTransmittedBytes;
// updated every 15 seconds
auto delta = ts - m_LastBandwidth15sUpdateTime;
if (delta > 15 * 1000)
{
m_InBandwidth15s = (m_TotalReceivedBytes - m_LastInBandwidth15sUpdateBytes) * 1000 / delta;
m_OutBandwidth15s = (m_TotalSentBytes - m_LastOutBandwidth15sUpdateBytes) * 1000 / delta;
m_TransitBandwidth15s = (m_TotalTransitTransmittedBytes - m_LastTransitBandwidth15sUpdateBytes) * 1000 / delta;
m_LastBandwidth15sUpdateTime = ts;
m_LastInBandwidth15sUpdateBytes = m_TotalReceivedBytes;
m_LastOutBandwidth15sUpdateBytes = m_TotalSentBytes;
m_LastTransitBandwidth15sUpdateBytes = m_TotalTransitTransmittedBytes;
}
m_UpdateBandwidthTimer->expires_from_now (boost::posix_time::seconds(1));
m_UpdateBandwidthTimer->async_wait (std::bind (&Transports::HandleUpdateBandwidthTimer, this, std::placeholders::_1));
}
} }
bool Transports::IsBandwidthExceeded () const bool Transports::IsBandwidthExceeded () const
{ {
auto limit = i2p::context.GetBandwidthLimit() * 1024; // convert to bytes auto limit = i2p::context.GetBandwidthLimit() * 1024; // convert to bytes
auto bw = std::max (m_InBandwidth, m_OutBandwidth); auto bw = std::max (m_InBandwidth15s, m_OutBandwidth15s);
return bw > limit; return bw > limit;
} }
@ -772,13 +794,12 @@ namespace transport
++it; ++it;
} }
} }
UpdateBandwidth (); // TODO: use separate timer(s) for it
bool ipv4Testing = i2p::context.GetStatus () == eRouterStatusTesting; bool ipv4Testing = i2p::context.GetStatus () == eRouterStatusTesting;
bool ipv6Testing = i2p::context.GetStatusV6 () == eRouterStatusTesting; bool ipv6Testing = i2p::context.GetStatusV6 () == eRouterStatusTesting;
// if still testing, repeat peer test // if still testing, repeat peer test
if (ipv4Testing || ipv6Testing) if (ipv4Testing || ipv6Testing)
PeerTest (ipv4Testing, ipv6Testing); PeerTest (ipv4Testing, ipv6Testing);
m_PeerCleanupTimer->expires_from_now (boost::posix_time::seconds(3*SESSION_CREATION_TIMEOUT)); m_PeerCleanupTimer->expires_from_now (boost::posix_time::seconds(3 * SESSION_CREATION_TIMEOUT));
m_PeerCleanupTimer->async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1)); m_PeerCleanupTimer->async_wait (std::bind (&Transports::HandlePeerCleanupTimer, this, std::placeholders::_1));
} }
} }

17
libi2pd/Transports.h

@ -124,6 +124,9 @@ namespace transport
uint32_t GetInBandwidth () const { return m_InBandwidth; }; uint32_t GetInBandwidth () const { return m_InBandwidth; };
uint32_t GetOutBandwidth () const { return m_OutBandwidth; }; uint32_t GetOutBandwidth () const { return m_OutBandwidth; };
uint32_t GetTransitBandwidth () const { return m_TransitBandwidth; }; uint32_t GetTransitBandwidth () const { return m_TransitBandwidth; };
uint32_t GetInBandwidth15s () const { return m_InBandwidth15s; };
uint32_t GetOutBandwidth15s () const { return m_OutBandwidth15s; };
uint32_t GetTransitBandwidth15s () const { return m_TransitBandwidth15s; };
bool IsBandwidthExceeded () const; bool IsBandwidthExceeded () const;
bool IsTransitBandwidthExceeded () const; bool IsTransitBandwidthExceeded () const;
size_t GetNumPeers () const { return m_Peers.size (); }; size_t GetNumPeers () const { return m_Peers.size (); };
@ -155,8 +158,8 @@ namespace transport
void SetPriority (Peer& peer) const; void SetPriority (Peer& peer) const;
void HandlePeerCleanupTimer (const boost::system::error_code& ecode); void HandlePeerCleanupTimer (const boost::system::error_code& ecode);
void HandlePeerTestTimer (const boost::system::error_code& ecode); void HandlePeerTestTimer (const boost::system::error_code& ecode);
void HandleUpdateBandwidthTimer (const boost::system::error_code& ecode);
void UpdateBandwidth ();
void DetectExternalIP (); void DetectExternalIP ();
private: private:
@ -166,7 +169,7 @@ namespace transport
std::thread * m_Thread; std::thread * m_Thread;
boost::asio::io_service * m_Service; boost::asio::io_service * m_Service;
boost::asio::io_service::work * m_Work; boost::asio::io_service::work * m_Work;
boost::asio::deadline_timer * m_PeerCleanupTimer, * m_PeerTestTimer; boost::asio::deadline_timer * m_PeerCleanupTimer, * m_PeerTestTimer, * m_UpdateBandwidthTimer;
SSU2Server * m_SSU2Server; SSU2Server * m_SSU2Server;
NTCP2Server * m_NTCP2Server; NTCP2Server * m_NTCP2Server;
@ -176,9 +179,15 @@ namespace transport
X25519KeysPairSupplier m_X25519KeysPairSupplier; X25519KeysPairSupplier m_X25519KeysPairSupplier;
std::atomic<uint64_t> m_TotalSentBytes, m_TotalReceivedBytes, m_TotalTransitTransmittedBytes; std::atomic<uint64_t> m_TotalSentBytes, m_TotalReceivedBytes, m_TotalTransitTransmittedBytes;
uint32_t m_InBandwidth, m_OutBandwidth, m_TransitBandwidth; // bytes per second
// Bandwidth per second
uint32_t m_InBandwidth, m_OutBandwidth, m_TransitBandwidth;
uint64_t m_LastInBandwidthUpdateBytes, m_LastOutBandwidthUpdateBytes, m_LastTransitBandwidthUpdateBytes; uint64_t m_LastInBandwidthUpdateBytes, m_LastOutBandwidthUpdateBytes, m_LastTransitBandwidthUpdateBytes;
uint64_t m_LastBandwidthUpdateTime;
// Bandwidth every 15 seconds
uint32_t m_InBandwidth15s, m_OutBandwidth15s, m_TransitBandwidth15s;
uint64_t m_LastInBandwidth15sUpdateBytes, m_LastOutBandwidth15sUpdateBytes, m_LastTransitBandwidth15sUpdateBytes;
uint64_t m_LastBandwidth15sUpdateTime;
/** which router families to trust for first hops */ /** which router families to trust for first hops */
std::vector<i2p::data::FamilyID> m_TrustedFamilies; std::vector<i2p::data::FamilyID> m_TrustedFamilies;

Loading…
Cancel
Save