2014-12-31 14:14:53 +00:00
|
|
|
#include <string.h>
|
2014-01-09 19:56:07 +00:00
|
|
|
#include "I2PEndian.h"
|
2014-01-09 22:55:53 +00:00
|
|
|
#include <thread>
|
2014-08-16 18:35:35 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
2016-05-11 19:12:38 +00:00
|
|
|
#include "Crypto.h"
|
2013-12-07 00:02:49 +00:00
|
|
|
#include "RouterContext.h"
|
|
|
|
#include "Log.h"
|
|
|
|
#include "Timestamp.h"
|
|
|
|
#include "I2NPProtocol.h"
|
|
|
|
#include "Transports.h"
|
2017-04-22 00:04:16 +00:00
|
|
|
#include "NetDb.hpp"
|
2017-02-28 20:58:53 +00:00
|
|
|
#include "Config.h"
|
2013-12-07 00:02:49 +00:00
|
|
|
#include "Tunnel.h"
|
2016-11-01 14:26:40 +00:00
|
|
|
#include "TunnelPool.h"
|
2016-11-02 19:17:05 +00:00
|
|
|
#ifdef WITH_EVENTS
|
|
|
|
#include "Event.h"
|
|
|
|
#endif
|
2013-12-07 00:02:49 +00:00
|
|
|
|
|
|
|
namespace i2p
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2013-12-07 00:02:49 +00:00
|
|
|
namespace tunnel
|
2017-01-01 19:29:39 +00:00
|
|
|
{
|
2015-05-06 20:17:48 +00:00
|
|
|
Tunnel::Tunnel (std::shared_ptr<const TunnelConfig> config):
|
2015-11-03 14:15:49 +00:00
|
|
|
TunnelBase (config->GetTunnelID (), config->GetNextTunnelID (), config->GetNextIdentHash ()),
|
2017-01-01 19:29:39 +00:00
|
|
|
m_Config (config), m_Pool (nullptr), m_State (eTunnelStatePending), m_IsRecreated (false),
|
|
|
|
m_Latency (0)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
|
|
|
|
Tunnel::~Tunnel ()
|
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
|
2015-01-27 19:55:46 +00:00
|
|
|
void Tunnel::Build (uint32_t replyMsgID, std::shared_ptr<OutboundTunnel> outboundTunnel)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-10-20 16:14:32 +00:00
|
|
|
#ifdef WITH_EVENTS
|
2016-11-01 14:26:40 +00:00
|
|
|
std::string peers = i2p::context.GetIdentity()->GetIdentHash().ToBase64();
|
2016-10-20 16:14:32 +00:00
|
|
|
#endif
|
2014-08-16 18:35:35 +00:00
|
|
|
auto numHops = m_Config->GetNumHops ();
|
|
|
|
int numRecords = numHops <= STANDARD_NUM_RECORDS ? STANDARD_NUM_RECORDS : numHops;
|
2015-06-19 18:38:31 +00:00
|
|
|
auto msg = NewI2NPShortMessage ();
|
2013-12-07 00:02:49 +00:00
|
|
|
*msg->GetPayload () = numRecords;
|
2016-08-11 09:25:26 +00:00
|
|
|
msg->len += numRecords*TUNNEL_BUILD_RECORD_SIZE + 1;
|
2014-08-16 18:35:35 +00:00
|
|
|
// shuffle records
|
|
|
|
std::vector<int> recordIndicies;
|
|
|
|
for (int i = 0; i < numRecords; i++) recordIndicies.push_back(i);
|
|
|
|
std::random_shuffle (recordIndicies.begin(), recordIndicies.end());
|
2013-12-07 00:02:49 +00:00
|
|
|
|
2014-08-16 18:35:35 +00:00
|
|
|
// create real records
|
2015-01-03 21:31:44 +00:00
|
|
|
uint8_t * records = msg->GetPayload () + 1;
|
2013-12-07 00:02:49 +00:00
|
|
|
TunnelHopConfig * hop = m_Config->GetFirstHop ();
|
|
|
|
int i = 0;
|
2017-03-11 21:48:54 +00:00
|
|
|
BN_CTX * ctx = BN_CTX_new ();
|
2013-12-07 00:02:49 +00:00
|
|
|
while (hop)
|
|
|
|
{
|
2015-11-03 14:15:49 +00:00
|
|
|
uint32_t msgID;
|
|
|
|
if (hop->next) // we set replyMsgID for last hop only
|
|
|
|
RAND_bytes ((uint8_t *)&msgID, 4);
|
|
|
|
else
|
|
|
|
msgID = replyMsgID;
|
2014-08-16 18:35:35 +00:00
|
|
|
int idx = recordIndicies[i];
|
2017-03-11 21:48:54 +00:00
|
|
|
hop->CreateBuildRequestRecord (records + idx*TUNNEL_BUILD_RECORD_SIZE, msgID, ctx);
|
2014-08-16 18:35:35 +00:00
|
|
|
hop->recordIndex = idx;
|
2013-12-07 00:02:49 +00:00
|
|
|
i++;
|
2016-10-20 16:14:32 +00:00
|
|
|
#ifdef WITH_EVENTS
|
2016-11-01 14:26:40 +00:00
|
|
|
peers += ":" + hop->ident->GetIdentHash().ToBase64();
|
2016-10-20 16:14:32 +00:00
|
|
|
#endif
|
2013-12-07 00:02:49 +00:00
|
|
|
hop = hop->next;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2017-03-11 21:48:54 +00:00
|
|
|
BN_CTX_free (ctx);
|
2016-10-20 16:14:32 +00:00
|
|
|
#ifdef WITH_EVENTS
|
2016-11-01 14:26:40 +00:00
|
|
|
EmitTunnelEvent("tunnel.build", this, peers);
|
2016-10-20 16:14:32 +00:00
|
|
|
#endif
|
2016-08-11 09:25:26 +00:00
|
|
|
// fill up fake records with random data
|
2014-08-16 18:35:35 +00:00
|
|
|
for (int i = numHops; i < numRecords; i++)
|
2014-06-19 01:24:24 +00:00
|
|
|
{
|
2014-08-16 18:35:35 +00:00
|
|
|
int idx = recordIndicies[i];
|
2015-11-03 14:15:49 +00:00
|
|
|
RAND_bytes (records + idx*TUNNEL_BUILD_RECORD_SIZE, TUNNEL_BUILD_RECORD_SIZE);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-08-16 18:35:35 +00:00
|
|
|
|
|
|
|
// decrypt real records
|
2014-05-15 22:58:26 +00:00
|
|
|
i2p::crypto::CBCDecryption decryption;
|
2013-12-07 00:02:49 +00:00
|
|
|
hop = m_Config->GetLastHop ()->prev;
|
|
|
|
while (hop)
|
|
|
|
{
|
2014-05-15 22:58:26 +00:00
|
|
|
decryption.SetKey (hop->replyKey);
|
2014-06-18 23:38:21 +00:00
|
|
|
// decrypt records after current hop
|
|
|
|
TunnelHopConfig * hop1 = hop->next;
|
|
|
|
while (hop1)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2014-06-24 23:33:30 +00:00
|
|
|
decryption.SetIV (hop->replyIV);
|
2015-01-03 21:31:44 +00:00
|
|
|
uint8_t * record = records + hop1->recordIndex*TUNNEL_BUILD_RECORD_SIZE;
|
|
|
|
decryption.Decrypt(record, TUNNEL_BUILD_RECORD_SIZE, record);
|
2014-06-18 23:38:21 +00:00
|
|
|
hop1 = hop1->next;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
hop = hop->prev;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2015-07-03 15:11:07 +00:00
|
|
|
msg->FillI2NPMessageHeader (eI2NPVariableTunnelBuild);
|
2014-08-16 18:35:35 +00:00
|
|
|
|
|
|
|
// send message
|
2013-12-07 00:02:49 +00:00
|
|
|
if (outboundTunnel)
|
2016-08-11 09:25:26 +00:00
|
|
|
outboundTunnel->SendTunnelDataMsg (GetNextIdentHash (), 0, msg);
|
2013-12-07 00:02:49 +00:00
|
|
|
else
|
2015-11-24 18:09:12 +00:00
|
|
|
i2p::transport::transports.SendMessage (GetNextIdentHash (), msg);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
|
2013-12-07 00:02:49 +00:00
|
|
|
bool Tunnel::HandleTunnelBuildResponse (uint8_t * msg, size_t len)
|
|
|
|
{
|
2015-12-18 06:20:06 +00:00
|
|
|
LogPrint (eLogDebug, "Tunnel: TunnelBuildResponse ", (int)msg[0], " records.");
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2014-05-15 22:58:26 +00:00
|
|
|
i2p::crypto::CBCDecryption decryption;
|
2013-12-07 00:02:49 +00:00
|
|
|
TunnelHopConfig * hop = m_Config->GetLastHop ();
|
|
|
|
while (hop)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2014-05-15 22:58:26 +00:00
|
|
|
decryption.SetKey (hop->replyKey);
|
2014-06-18 23:38:21 +00:00
|
|
|
// decrypt records before and including current hop
|
|
|
|
TunnelHopConfig * hop1 = hop;
|
|
|
|
while (hop1)
|
|
|
|
{
|
2014-06-19 01:24:24 +00:00
|
|
|
auto idx = hop1->recordIndex;
|
|
|
|
if (idx >= 0 && idx < msg[0])
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2015-01-03 14:47:24 +00:00
|
|
|
uint8_t * record = msg + 1 + idx*TUNNEL_BUILD_RECORD_SIZE;
|
2014-06-24 23:33:30 +00:00
|
|
|
decryption.SetIV (hop->replyIV);
|
2015-01-03 14:47:24 +00:00
|
|
|
decryption.Decrypt(record, TUNNEL_BUILD_RECORD_SIZE, record);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-06-19 01:24:24 +00:00
|
|
|
else
|
2015-12-18 06:20:06 +00:00
|
|
|
LogPrint (eLogWarning, "Tunnel: hop index ", idx, " is out of range");
|
2014-06-18 23:38:21 +00:00
|
|
|
hop1 = hop1->prev;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
hop = hop->prev;
|
|
|
|
}
|
|
|
|
|
2014-07-27 00:56:42 +00:00
|
|
|
bool established = true;
|
2014-06-19 01:24:24 +00:00
|
|
|
hop = m_Config->GetFirstHop ();
|
|
|
|
while (hop)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2015-01-03 14:47:24 +00:00
|
|
|
const uint8_t * record = msg + 1 + hop->recordIndex*TUNNEL_BUILD_RECORD_SIZE;
|
|
|
|
uint8_t ret = record[BUILD_RESPONSE_RECORD_RET_OFFSET];
|
2015-12-18 06:20:06 +00:00
|
|
|
LogPrint (eLogDebug, "Tunnel: Build response ret code=", (int)ret);
|
2015-11-03 14:15:49 +00:00
|
|
|
auto profile = i2p::data::netdb.FindRouterProfile (hop->ident->GetIdentHash ());
|
|
|
|
if (profile)
|
|
|
|
profile->TunnelBuildResponse (ret);
|
2015-01-03 14:47:24 +00:00
|
|
|
if (ret)
|
2013-12-07 00:02:49 +00:00
|
|
|
// if any of participants declined the tunnel is not established
|
2014-07-27 00:56:42 +00:00
|
|
|
established = false;
|
2014-06-19 01:24:24 +00:00
|
|
|
hop = hop->next;
|
2013-12-07 00:02:49 +00:00
|
|
|
}
|
2014-07-27 00:56:42 +00:00
|
|
|
if (established)
|
2014-05-09 23:34:12 +00:00
|
|
|
{
|
2015-11-03 14:15:49 +00:00
|
|
|
// create tunnel decryptions from layer and iv keys in reverse order
|
|
|
|
hop = m_Config->GetLastHop ();
|
2014-05-09 23:34:12 +00:00
|
|
|
while (hop)
|
|
|
|
{
|
2015-11-06 14:01:02 +00:00
|
|
|
auto tunnelHop = new TunnelHop;
|
|
|
|
tunnelHop->ident = hop->ident;
|
2015-11-03 14:15:49 +00:00
|
|
|
tunnelHop->decryption.SetKeys (hop->layerKey, hop->ivKey);
|
|
|
|
m_Hops.push_back (std::unique_ptr<TunnelHop>(tunnelHop));
|
|
|
|
hop = hop->prev;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2015-11-03 14:15:49 +00:00
|
|
|
m_Config = nullptr;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-07-27 00:56:42 +00:00
|
|
|
if (established) m_State = eTunnelStateEstablished;
|
|
|
|
return established;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
|
2016-11-15 15:20:09 +00:00
|
|
|
bool Tunnel::LatencyFitsRange(uint64_t lower, uint64_t upper) const
|
|
|
|
{
|
|
|
|
auto latency = GetMeanLatency();
|
|
|
|
return latency >= lower && latency <= upper;
|
|
|
|
}
|
|
|
|
|
2015-06-25 02:19:56 +00:00
|
|
|
void Tunnel::EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2015-06-25 02:19:56 +00:00
|
|
|
const uint8_t * inPayload = in->GetPayload () + 4;
|
|
|
|
uint8_t * outPayload = out->GetPayload () + 4;
|
2015-11-03 14:15:49 +00:00
|
|
|
for (auto& it: m_Hops)
|
|
|
|
{
|
|
|
|
it->decryption.Decrypt (inPayload, outPayload);
|
2015-06-25 02:19:56 +00:00
|
|
|
inPayload = outPayload;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-23 21:26:39 +00:00
|
|
|
|
2015-06-19 18:38:31 +00:00
|
|
|
void Tunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg)
|
2015-01-23 21:26:39 +00:00
|
|
|
{
|
2016-01-18 00:00:00 +00:00
|
|
|
LogPrint (eLogWarning, "Tunnel: Can't send I2NP messages without delivery instructions");
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2015-01-23 21:26:39 +00:00
|
|
|
|
2015-11-03 14:15:49 +00:00
|
|
|
std::vector<std::shared_ptr<const i2p::data::IdentityEx> > Tunnel::GetPeers () const
|
|
|
|
{
|
|
|
|
auto peers = GetInvertedPeers ();
|
2016-08-11 09:25:26 +00:00
|
|
|
std::reverse (peers.begin (), peers.end ());
|
2015-11-03 14:15:49 +00:00
|
|
|
return peers;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2015-11-03 14:15:49 +00:00
|
|
|
|
|
|
|
std::vector<std::shared_ptr<const i2p::data::IdentityEx> > Tunnel::GetInvertedPeers () const
|
|
|
|
{
|
|
|
|
// hops are in inverted order
|
|
|
|
std::vector<std::shared_ptr<const i2p::data::IdentityEx> > ret;
|
|
|
|
for (auto& it: m_Hops)
|
|
|
|
ret.push_back (it->ident);
|
2016-08-11 09:25:26 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2015-12-10 00:07:12 +00:00
|
|
|
|
2016-11-01 14:26:40 +00:00
|
|
|
void Tunnel::SetState(TunnelState state)
|
|
|
|
{
|
|
|
|
m_State = state;
|
2016-11-02 19:17:05 +00:00
|
|
|
#ifdef WITH_EVENTS
|
2016-11-01 14:26:40 +00:00
|
|
|
EmitTunnelEvent("tunnel.state", this, state);
|
2016-11-02 19:17:05 +00:00
|
|
|
#endif
|
2016-11-01 14:26:40 +00:00
|
|
|
}
|
|
|
|
|
2016-10-20 16:14:32 +00:00
|
|
|
|
2015-12-10 00:07:12 +00:00
|
|
|
void Tunnel::PrintHops (std::stringstream& s) const
|
|
|
|
{
|
2016-10-31 19:13:43 +00:00
|
|
|
// hops are in inverted order, we must print in direct order
|
|
|
|
for (auto it = m_Hops.rbegin (); it != m_Hops.rend (); it++)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
|
|
|
s << " ⇒ ";
|
2016-10-31 19:13:43 +00:00
|
|
|
s << i2p::data::GetIdentHashAbbreviation ((*it)->ident->GetIdentHash ());
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 01:49:16 +00:00
|
|
|
void InboundTunnel::HandleTunnelDataMsg (std::shared_ptr<const I2NPMessage> msg)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
if (IsFailed ()) SetState (eTunnelStateEstablished); // incoming messages means a tunnel is alive
|
2015-06-26 01:49:16 +00:00
|
|
|
auto newMsg = CreateEmptyTunnelDataMsg ();
|
|
|
|
EncryptTunnelMsg (msg, newMsg);
|
|
|
|
newMsg->from = shared_from_this ();
|
2016-08-11 09:25:26 +00:00
|
|
|
m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg);
|
|
|
|
}
|
2015-12-09 23:01:42 +00:00
|
|
|
|
2016-03-03 03:41:53 +00:00
|
|
|
void InboundTunnel::Print (std::stringstream& s) const
|
|
|
|
{
|
|
|
|
PrintHops (s);
|
2016-08-11 09:25:26 +00:00
|
|
|
s << " ⇒ " << GetTunnelID () << ":me";
|
|
|
|
}
|
2016-03-03 03:41:53 +00:00
|
|
|
|
|
|
|
ZeroHopsInboundTunnel::ZeroHopsInboundTunnel ():
|
2016-03-03 12:30:38 +00:00
|
|
|
InboundTunnel (std::make_shared<ZeroHopsTunnelConfig> ()),
|
|
|
|
m_NumReceivedBytes (0)
|
2016-03-03 03:41:53 +00:00
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
|
2016-03-03 03:41:53 +00:00
|
|
|
void ZeroHopsInboundTunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg)
|
2016-03-02 21:12:02 +00:00
|
|
|
{
|
2016-03-03 12:30:38 +00:00
|
|
|
if (msg)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2016-03-03 12:30:38 +00:00
|
|
|
m_NumReceivedBytes += msg->GetLength ();
|
2016-06-30 01:37:17 +00:00
|
|
|
msg->from = shared_from_this ();
|
2016-03-03 12:30:38 +00:00
|
|
|
HandleI2NPMessage (msg);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
2016-03-02 21:12:02 +00:00
|
|
|
|
2016-03-03 03:41:53 +00:00
|
|
|
void ZeroHopsInboundTunnel::Print (std::stringstream& s) const
|
2015-12-09 23:01:42 +00:00
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
s << " ⇒ " << GetTunnelID () << ":me";
|
|
|
|
}
|
|
|
|
|
2015-06-22 02:29:50 +00:00
|
|
|
void OutboundTunnel::SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, std::shared_ptr<i2p::I2NPMessage> msg)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2014-02-20 03:08:57 +00:00
|
|
|
TunnelMessageBlock block;
|
|
|
|
if (gwHash)
|
|
|
|
{
|
|
|
|
block.hash = gwHash;
|
|
|
|
if (gwTunnel)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2014-02-20 03:08:57 +00:00
|
|
|
block.deliveryType = eDeliveryTypeTunnel;
|
|
|
|
block.tunnelID = gwTunnel;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-02-20 03:08:57 +00:00
|
|
|
else
|
|
|
|
block.deliveryType = eDeliveryTypeRouter;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
else
|
2014-02-20 03:08:57 +00:00
|
|
|
block.deliveryType = eDeliveryTypeLocal;
|
2015-06-22 02:29:50 +00:00
|
|
|
block.data = msg;
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2016-03-03 21:24:13 +00:00
|
|
|
SendTunnelDataMsg ({block});
|
2013-12-07 00:02:49 +00:00
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2014-10-07 14:33:17 +00:00
|
|
|
void OutboundTunnel::SendTunnelDataMsg (const std::vector<TunnelMessageBlock>& msgs)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2014-04-03 16:19:12 +00:00
|
|
|
std::unique_lock<std::mutex> l(m_SendMutex);
|
2014-01-20 23:37:51 +00:00
|
|
|
for (auto& it : msgs)
|
2014-02-20 02:24:55 +00:00
|
|
|
m_Gateway.PutTunnelDataMsg (it);
|
2014-01-20 23:37:51 +00:00
|
|
|
m_Gateway.SendBuffer ();
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
|
2015-06-26 01:49:16 +00:00
|
|
|
void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
|
2015-01-21 19:40:48 +00:00
|
|
|
{
|
2016-01-18 00:00:00 +00:00
|
|
|
LogPrint (eLogError, "Tunnel: incoming message for outbound tunnel ", GetTunnelID ());
|
2015-01-21 19:40:48 +00:00
|
|
|
}
|
2015-12-09 23:01:42 +00:00
|
|
|
|
|
|
|
void OutboundTunnel::Print (std::stringstream& s) const
|
|
|
|
{
|
2015-12-10 00:07:12 +00:00
|
|
|
s << GetTunnelID () << ":me";
|
|
|
|
PrintHops (s);
|
2016-08-11 09:25:26 +00:00
|
|
|
s << " ⇒ ";
|
|
|
|
}
|
|
|
|
|
2016-03-03 21:24:13 +00:00
|
|
|
ZeroHopsOutboundTunnel::ZeroHopsOutboundTunnel ():
|
|
|
|
OutboundTunnel (std::make_shared<ZeroHopsTunnelConfig> ()),
|
|
|
|
m_NumSentBytes (0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZeroHopsOutboundTunnel::SendTunnelDataMsg (const std::vector<TunnelMessageBlock>& msgs)
|
|
|
|
{
|
|
|
|
for (auto& msg : msgs)
|
|
|
|
{
|
|
|
|
switch (msg.deliveryType)
|
|
|
|
{
|
|
|
|
case eDeliveryTypeLocal:
|
|
|
|
i2p::HandleI2NPMessage (msg.data);
|
|
|
|
break;
|
|
|
|
case eDeliveryTypeTunnel:
|
|
|
|
i2p::transport::transports.SendMessage (msg.hash, i2p::CreateTunnelGatewayMsg (msg.tunnelID, msg.data));
|
|
|
|
break;
|
2016-08-11 09:25:26 +00:00
|
|
|
case eDeliveryTypeRouter:
|
2016-03-03 21:24:13 +00:00
|
|
|
i2p::transport::transports.SendMessage (msg.hash, msg.data);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LogPrint (eLogError, "Tunnel: Unknown delivery type ", (int)msg.deliveryType);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2016-03-03 21:24:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ZeroHopsOutboundTunnel::Print (std::stringstream& s) const
|
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
s << GetTunnelID () << ":me ⇒ ";
|
2016-03-03 21:24:13 +00:00
|
|
|
}
|
|
|
|
|
2013-12-07 00:02:49 +00:00
|
|
|
Tunnels tunnels;
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2015-02-28 12:59:34 +00:00
|
|
|
Tunnels::Tunnels (): m_IsRunning (false), m_Thread (nullptr),
|
|
|
|
m_NumSuccesiveTunnelCreations (0), m_NumFailedTunnelCreations (0)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
|
|
|
|
Tunnels::~Tunnels ()
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2016-03-02 01:48:56 +00:00
|
|
|
|
|
|
|
std::shared_ptr<TunnelBase> Tunnels::GetTunnel (uint32_t tunnelID)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-03-02 01:48:56 +00:00
|
|
|
auto it = m_Tunnels.find(tunnelID);
|
|
|
|
if (it != m_Tunnels.end ())
|
2013-12-07 00:02:49 +00:00
|
|
|
return it->second;
|
|
|
|
return nullptr;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 19:55:46 +00:00
|
|
|
std::shared_ptr<InboundTunnel> Tunnels::GetPendingInboundTunnel (uint32_t replyMsgID)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
return GetPendingTunnel (replyMsgID, m_PendingInboundTunnels);
|
2015-01-26 16:56:10 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 19:55:46 +00:00
|
|
|
std::shared_ptr<OutboundTunnel> Tunnels::GetPendingOutboundTunnel (uint32_t replyMsgID)
|
2015-01-26 16:56:10 +00:00
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
return GetPendingTunnel (replyMsgID, m_PendingOutboundTunnels);
|
|
|
|
}
|
2015-01-26 16:56:10 +00:00
|
|
|
|
2016-08-11 09:25:26 +00:00
|
|
|
template<class TTunnel>
|
2015-01-27 19:55:46 +00:00
|
|
|
std::shared_ptr<TTunnel> Tunnels::GetPendingTunnel (uint32_t replyMsgID, const std::map<uint32_t, std::shared_ptr<TTunnel> >& pendingTunnels)
|
2015-01-26 16:56:10 +00:00
|
|
|
{
|
|
|
|
auto it = pendingTunnels.find(replyMsgID);
|
|
|
|
if (it != pendingTunnels.end () && it->second->GetState () == eTunnelStatePending)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
|
|
|
it->second->SetState (eTunnelStateBuildReplyReceived);
|
2014-08-18 18:37:19 +00:00
|
|
|
return it->second;
|
2014-09-26 14:15:34 +00:00
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
return nullptr;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
|
2015-01-27 19:55:46 +00:00
|
|
|
std::shared_ptr<InboundTunnel> Tunnels::GetNextInboundTunnel ()
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2015-01-27 19:55:46 +00:00
|
|
|
std::shared_ptr<InboundTunnel> tunnel;
|
2013-12-07 00:02:49 +00:00
|
|
|
size_t minReceived = 0;
|
2016-08-09 22:16:24 +00:00
|
|
|
for (const auto& it : m_InboundTunnels)
|
2014-03-21 19:54:55 +00:00
|
|
|
{
|
2016-03-02 16:58:52 +00:00
|
|
|
if (!it->IsEstablished ()) continue;
|
|
|
|
if (!tunnel || it->GetNumReceivedBytes () < minReceived)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-03-02 16:58:52 +00:00
|
|
|
tunnel = it;
|
|
|
|
minReceived = it->GetNumReceivedBytes ();
|
2014-03-21 19:54:55 +00:00
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
return tunnel;
|
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2015-01-27 19:55:46 +00:00
|
|
|
std::shared_ptr<OutboundTunnel> Tunnels::GetNextOutboundTunnel ()
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-06-01 00:00:00 +00:00
|
|
|
if (m_OutboundTunnels.empty ()) return nullptr;
|
2015-11-03 14:15:49 +00:00
|
|
|
uint32_t ind = rand () % m_OutboundTunnels.size (), i = 0;
|
2015-01-27 19:55:46 +00:00
|
|
|
std::shared_ptr<OutboundTunnel> tunnel;
|
2016-08-09 22:16:24 +00:00
|
|
|
for (const auto& it: m_OutboundTunnels)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2014-08-26 14:31:32 +00:00
|
|
|
if (it->IsEstablished ())
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
|
|
|
tunnel = it;
|
2014-03-21 19:54:55 +00:00
|
|
|
i++;
|
|
|
|
}
|
2014-08-29 11:44:12 +00:00
|
|
|
if (i > ind && tunnel) break;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-03-21 19:54:55 +00:00
|
|
|
return tunnel;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-03-15 00:24:12 +00:00
|
|
|
|
2015-12-16 19:52:48 +00:00
|
|
|
std::shared_ptr<TunnelPool> Tunnels::CreateTunnelPool (int numInboundHops,
|
|
|
|
int numOutboundHops, int numInboundTunnels, int numOutboundTunnels)
|
2014-03-15 00:24:12 +00:00
|
|
|
{
|
2015-12-16 19:52:48 +00:00
|
|
|
auto pool = std::make_shared<TunnelPool> (numInboundHops, numOutboundHops, numInboundTunnels, numOutboundTunnels);
|
2014-10-05 15:01:12 +00:00
|
|
|
std::unique_lock<std::mutex> l(m_PoolsMutex);
|
2014-12-10 02:07:54 +00:00
|
|
|
m_Pools.push_back (pool);
|
2014-03-15 00:51:51 +00:00
|
|
|
return pool;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-03-15 00:51:51 +00:00
|
|
|
|
2015-01-20 03:28:13 +00:00
|
|
|
void Tunnels::DeleteTunnelPool (std::shared_ptr<TunnelPool> pool)
|
2014-03-15 00:51:51 +00:00
|
|
|
{
|
2014-10-11 13:47:24 +00:00
|
|
|
if (pool)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2014-10-13 15:21:57 +00:00
|
|
|
StopTunnelPool (pool);
|
2014-12-10 02:07:54 +00:00
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> l(m_PoolsMutex);
|
|
|
|
m_Pools.remove (pool);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-10-13 15:21:57 +00:00
|
|
|
|
2015-01-20 03:28:13 +00:00
|
|
|
void Tunnels::StopTunnelPool (std::shared_ptr<TunnelPool> pool)
|
2014-10-13 15:21:57 +00:00
|
|
|
{
|
|
|
|
if (pool)
|
|
|
|
{
|
|
|
|
pool->SetActive (false);
|
2014-10-11 13:47:24 +00:00
|
|
|
pool->DetachTunnels ();
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-01 20:22:36 +00:00
|
|
|
void Tunnels::AddTransitTunnel (std::shared_ptr<TransitTunnel> tunnel)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-03-02 01:48:56 +00:00
|
|
|
if (m_Tunnels.emplace (tunnel->GetTunnelID (), tunnel).second)
|
|
|
|
m_TransitTunnels.push_back (tunnel);
|
|
|
|
else
|
|
|
|
LogPrint (eLogError, "Tunnel: tunnel with id ", tunnel->GetTunnelID (), " already exists");
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
|
|
|
|
void Tunnels::Start ()
|
|
|
|
{
|
|
|
|
m_IsRunning = true;
|
|
|
|
m_Thread = new std::thread (std::bind (&Tunnels::Run, this));
|
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2013-12-07 00:02:49 +00:00
|
|
|
void Tunnels::Stop ()
|
|
|
|
{
|
|
|
|
m_IsRunning = false;
|
|
|
|
m_Queue.WakeUp ();
|
|
|
|
if (m_Thread)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2013-12-07 00:02:49 +00:00
|
|
|
m_Thread->join ();
|
|
|
|
delete m_Thread;
|
|
|
|
m_Thread = 0;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
|
|
|
|
void Tunnels::Run ()
|
|
|
|
{
|
2014-01-09 22:55:53 +00:00
|
|
|
std::this_thread::sleep_for (std::chrono::seconds(1)); // wait for other parts are ready
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2014-01-09 19:56:07 +00:00
|
|
|
uint64_t lastTs = 0;
|
2013-12-07 00:02:49 +00:00
|
|
|
while (m_IsRunning)
|
|
|
|
{
|
|
|
|
try
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2015-06-19 18:38:31 +00:00
|
|
|
auto msg = m_Queue.GetNextWithTimeout (1000); // 1 sec
|
2015-01-22 02:50:46 +00:00
|
|
|
if (msg)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2015-01-27 01:49:16 +00:00
|
|
|
uint32_t prevTunnelID = 0, tunnelID = 0;
|
2016-06-29 14:11:14 +00:00
|
|
|
std::shared_ptr<TunnelBase> prevTunnel;
|
2015-01-22 02:50:46 +00:00
|
|
|
do
|
2015-01-21 20:13:46 +00:00
|
|
|
{
|
2016-03-01 20:22:36 +00:00
|
|
|
std::shared_ptr<TunnelBase> tunnel;
|
2015-01-27 01:49:16 +00:00
|
|
|
uint8_t typeID = msg->GetTypeID ();
|
|
|
|
switch (typeID)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2015-01-27 01:49:16 +00:00
|
|
|
case eI2NPTunnelData:
|
|
|
|
case eI2NPTunnelGateway:
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2015-01-27 01:49:16 +00:00
|
|
|
tunnelID = bufbe32toh (msg->GetPayload ());
|
|
|
|
if (tunnelID == prevTunnelID)
|
|
|
|
tunnel = prevTunnel;
|
|
|
|
else if (prevTunnel)
|
|
|
|
prevTunnel->FlushTunnelDataMsgs ();
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2015-01-27 01:49:16 +00:00
|
|
|
if (!tunnel)
|
2016-03-02 01:48:56 +00:00
|
|
|
tunnel = GetTunnel (tunnelID);
|
2015-01-27 01:49:16 +00:00
|
|
|
if (tunnel)
|
|
|
|
{
|
|
|
|
if (typeID == eI2NPTunnelData)
|
|
|
|
tunnel->HandleTunnelDataMsg (msg);
|
|
|
|
else // tunnel gateway assumed
|
|
|
|
HandleTunnelGatewayMsg (tunnel, msg);
|
|
|
|
}
|
2016-06-29 13:37:21 +00:00
|
|
|
else
|
2016-06-29 14:11:14 +00:00
|
|
|
LogPrint (eLogWarning, "Tunnel: tunnel not found, tunnelID=", tunnelID, " previousTunnelID=", prevTunnelID, " type=", (int)typeID);
|
|
|
|
|
2015-01-27 01:49:16 +00:00
|
|
|
break;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
case eI2NPVariableTunnelBuild:
|
2015-01-27 01:49:16 +00:00
|
|
|
case eI2NPVariableTunnelBuildReply:
|
|
|
|
case eI2NPTunnelBuild:
|
2016-08-11 09:25:26 +00:00
|
|
|
case eI2NPTunnelBuildReply:
|
2015-01-27 01:49:16 +00:00
|
|
|
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ());
|
2016-08-11 09:25:26 +00:00
|
|
|
break;
|
2015-01-27 01:49:16 +00:00
|
|
|
default:
|
2016-01-28 02:54:42 +00:00
|
|
|
LogPrint (eLogWarning, "Tunnel: unexpected messsage type ", (int) typeID);
|
2015-01-23 21:26:39 +00:00
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2015-01-22 02:50:46 +00:00
|
|
|
msg = m_Queue.Get ();
|
|
|
|
if (msg)
|
|
|
|
{
|
|
|
|
prevTunnelID = tunnelID;
|
|
|
|
prevTunnel = tunnel;
|
|
|
|
}
|
|
|
|
else if (tunnel)
|
|
|
|
tunnel->FlushTunnelDataMsgs ();
|
2015-01-21 20:13:46 +00:00
|
|
|
}
|
2015-01-22 02:50:46 +00:00
|
|
|
while (msg);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
|
2014-01-09 19:56:07 +00:00
|
|
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
2013-12-07 00:02:49 +00:00
|
|
|
if (ts - lastTs >= 15) // manage tunnels every 15 seconds
|
|
|
|
{
|
|
|
|
ManageTunnels ();
|
|
|
|
lastTs = ts;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (std::exception& ex)
|
|
|
|
{
|
2015-12-18 06:20:06 +00:00
|
|
|
LogPrint (eLogError, "Tunnel: runtime exception: ", ex.what ());
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
|
2016-03-01 20:22:36 +00:00
|
|
|
void Tunnels::HandleTunnelGatewayMsg (std::shared_ptr<TunnelBase> tunnel, std::shared_ptr<I2NPMessage> msg)
|
2015-01-23 21:26:39 +00:00
|
|
|
{
|
|
|
|
if (!tunnel)
|
|
|
|
{
|
2016-01-18 00:00:00 +00:00
|
|
|
LogPrint (eLogError, "Tunnel: missing tunnel for gateway");
|
2015-01-23 21:26:39 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
const uint8_t * payload = msg->GetPayload ();
|
|
|
|
uint16_t len = bufbe16toh(payload + TUNNEL_GATEWAY_HEADER_LENGTH_OFFSET);
|
|
|
|
// we make payload as new I2NP message to send
|
|
|
|
msg->offset += I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE;
|
2016-01-25 19:31:51 +00:00
|
|
|
if (msg->offset + len > msg->len)
|
|
|
|
{
|
|
|
|
LogPrint (eLogError, "Tunnel: gateway payload ", (int)len, " exceeds message length ", (int)msg->len);
|
|
|
|
return;
|
|
|
|
}
|
2015-01-23 21:26:39 +00:00
|
|
|
msg->len = msg->offset + len;
|
|
|
|
auto typeID = msg->GetTypeID ();
|
2016-01-18 00:00:00 +00:00
|
|
|
LogPrint (eLogDebug, "Tunnel: gateway of ", (int) len, " bytes for tunnel ", tunnel->GetTunnelID (), ", msg type ", (int)typeID);
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2016-01-05 00:56:46 +00:00
|
|
|
if (IsRouterInfoMsg (msg) || typeID == eI2NPDatabaseSearchReply)
|
2015-01-23 21:26:39 +00:00
|
|
|
// transit DatabaseStore my contain new/updated RI
|
|
|
|
// or DatabaseSearchReply with new routers
|
2016-01-31 23:27:47 +00:00
|
|
|
i2p::data::netdb.PostI2NPMsg (CopyI2NPMessage (msg));
|
2015-01-23 21:26:39 +00:00
|
|
|
tunnel->SendTunnelDataMsg (msg);
|
|
|
|
}
|
|
|
|
|
2013-12-07 00:02:49 +00:00
|
|
|
void Tunnels::ManageTunnels ()
|
2014-10-06 16:50:36 +00:00
|
|
|
{
|
|
|
|
ManagePendingTunnels ();
|
|
|
|
ManageInboundTunnels ();
|
|
|
|
ManageOutboundTunnels ();
|
|
|
|
ManageTransitTunnels ();
|
|
|
|
ManageTunnelPools ();
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-10-06 16:50:36 +00:00
|
|
|
|
|
|
|
void Tunnels::ManagePendingTunnels ()
|
2015-01-26 16:56:10 +00:00
|
|
|
{
|
|
|
|
ManagePendingTunnels (m_PendingInboundTunnels);
|
|
|
|
ManagePendingTunnels (m_PendingOutboundTunnels);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class PendingTunnels>
|
|
|
|
void Tunnels::ManagePendingTunnels (PendingTunnels& pendingTunnels)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2014-09-26 14:15:34 +00:00
|
|
|
// check pending tunnel. delete failed or timeout
|
2014-08-18 18:37:19 +00:00
|
|
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
2015-01-26 16:56:10 +00:00
|
|
|
for (auto it = pendingTunnels.begin (); it != pendingTunnels.end ();)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2014-09-26 14:15:34 +00:00
|
|
|
auto tunnel = it->second;
|
2016-11-15 20:40:09 +00:00
|
|
|
auto pool = tunnel->GetTunnelPool();
|
2014-09-26 14:15:34 +00:00
|
|
|
switch (tunnel->GetState ())
|
2014-08-18 18:37:19 +00:00
|
|
|
{
|
2014-09-26 14:15:34 +00:00
|
|
|
case eTunnelStatePending:
|
|
|
|
if (ts > tunnel->GetCreationTime () + TUNNEL_CREATION_TIMEOUT)
|
|
|
|
{
|
2016-05-26 00:00:00 +00:00
|
|
|
LogPrint (eLogDebug, "Tunnel: pending build request ", it->first, " timeout, deleted");
|
2015-03-28 20:09:34 +00:00
|
|
|
// update stats
|
|
|
|
auto config = tunnel->GetTunnelConfig ();
|
|
|
|
if (config)
|
|
|
|
{
|
|
|
|
auto hop = config->GetFirstHop ();
|
|
|
|
while (hop)
|
|
|
|
{
|
2015-11-03 14:15:49 +00:00
|
|
|
if (hop->ident)
|
|
|
|
{
|
|
|
|
auto profile = i2p::data::netdb.FindRouterProfile (hop->ident->GetIdentHash ());
|
|
|
|
if (profile)
|
|
|
|
profile->TunnelNonReplied ();
|
|
|
|
}
|
2015-03-28 20:09:34 +00:00
|
|
|
hop = hop->next;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-02 19:17:05 +00:00
|
|
|
#ifdef WITH_EVENTS
|
2016-11-01 14:26:40 +00:00
|
|
|
EmitTunnelEvent("tunnel.state", tunnel.get(), eTunnelStateBuildFailed);
|
2016-11-02 19:17:05 +00:00
|
|
|
#endif
|
2016-11-15 20:40:09 +00:00
|
|
|
// for i2lua
|
|
|
|
if(pool) pool->OnTunnelBuildResult(tunnel, eBuildResultTimeout);
|
2015-03-28 20:09:34 +00:00
|
|
|
// delete
|
2015-01-26 16:56:10 +00:00
|
|
|
it = pendingTunnels.erase (it);
|
2015-02-28 12:59:34 +00:00
|
|
|
m_NumFailedTunnelCreations++;
|
2014-09-26 14:15:34 +00:00
|
|
|
}
|
|
|
|
else
|
2016-08-09 22:16:24 +00:00
|
|
|
++it;
|
2014-09-26 14:15:34 +00:00
|
|
|
break;
|
|
|
|
case eTunnelStateBuildFailed:
|
2016-05-26 00:00:00 +00:00
|
|
|
LogPrint (eLogDebug, "Tunnel: pending build request ", it->first, " failed, deleted");
|
2016-11-02 19:17:05 +00:00
|
|
|
#ifdef WITH_EVENTS
|
2016-11-01 14:26:40 +00:00
|
|
|
EmitTunnelEvent("tunnel.state", tunnel.get(), eTunnelStateBuildFailed);
|
2016-11-02 19:17:05 +00:00
|
|
|
#endif
|
2016-11-15 20:40:09 +00:00
|
|
|
// for i2lua
|
|
|
|
if(pool) pool->OnTunnelBuildResult(tunnel, eBuildResultRejected);
|
|
|
|
|
2015-01-26 16:56:10 +00:00
|
|
|
it = pendingTunnels.erase (it);
|
2015-02-28 12:59:34 +00:00
|
|
|
m_NumFailedTunnelCreations++;
|
2014-09-26 14:15:34 +00:00
|
|
|
break;
|
|
|
|
case eTunnelStateBuildReplyReceived:
|
2015-01-27 19:55:46 +00:00
|
|
|
// intermediate state, will be either established of build failed
|
2016-08-09 22:16:24 +00:00
|
|
|
++it;
|
2016-08-11 09:25:26 +00:00
|
|
|
break;
|
2014-09-26 14:15:34 +00:00
|
|
|
default:
|
2015-02-28 12:59:34 +00:00
|
|
|
// success
|
2015-01-26 16:56:10 +00:00
|
|
|
it = pendingTunnels.erase (it);
|
2015-02-28 12:59:34 +00:00
|
|
|
m_NumSuccesiveTunnelCreations++;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
2014-10-06 16:50:36 +00:00
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
|
|
|
|
void Tunnels::ManageOutboundTunnels ()
|
|
|
|
{
|
2014-01-09 19:56:07 +00:00
|
|
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2014-08-31 12:56:03 +00:00
|
|
|
for (auto it = m_OutboundTunnels.begin (); it != m_OutboundTunnels.end ();)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2014-09-13 23:43:25 +00:00
|
|
|
auto tunnel = *it;
|
|
|
|
if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
2014-08-31 12:56:03 +00:00
|
|
|
{
|
2016-01-18 00:00:00 +00:00
|
|
|
LogPrint (eLogDebug, "Tunnel: tunnel with id ", tunnel->GetTunnelID (), " expired");
|
2015-04-15 01:37:21 +00:00
|
|
|
auto pool = tunnel->GetTunnelPool ();
|
|
|
|
if (pool)
|
|
|
|
pool->TunnelExpired (tunnel);
|
2016-03-02 01:48:56 +00:00
|
|
|
// we don't have outbound tunnels in m_Tunnels
|
2015-01-27 01:49:16 +00:00
|
|
|
it = m_OutboundTunnels.erase (it);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-08-31 12:56:03 +00:00
|
|
|
else
|
|
|
|
{
|
2015-04-17 15:36:42 +00:00
|
|
|
if (tunnel->IsEstablished ())
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2015-04-17 15:36:42 +00:00
|
|
|
if (!tunnel->IsRecreated () && ts + TUNNEL_RECREATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
tunnel->SetIsRecreated ();
|
2015-04-17 15:36:42 +00:00
|
|
|
auto pool = tunnel->GetTunnelPool ();
|
|
|
|
if (pool)
|
|
|
|
pool->RecreateOutboundTunnel (tunnel);
|
|
|
|
}
|
|
|
|
if (ts + TUNNEL_EXPIRATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
|
|
|
tunnel->SetState (eTunnelStateExpiring);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2016-08-09 22:16:24 +00:00
|
|
|
++it;
|
2014-08-31 12:56:03 +00:00
|
|
|
}
|
2014-08-26 14:31:32 +00:00
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-02 19:17:05 +00:00
|
|
|
if (m_OutboundTunnels.size () < 3)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
|
|
|
// trying to create one more oubound tunnel
|
2015-01-27 19:55:46 +00:00
|
|
|
auto inboundTunnel = GetNextInboundTunnel ();
|
2016-10-28 16:50:26 +00:00
|
|
|
auto router = i2p::transport::transports.RoutesRestricted() ?
|
|
|
|
i2p::transport::transports.GetRestrictedPeer() :
|
|
|
|
i2p::data::netdb.GetRandomRouter ();
|
2015-04-03 14:02:45 +00:00
|
|
|
if (!inboundTunnel || !router) return;
|
2016-01-18 00:00:00 +00:00
|
|
|
LogPrint (eLogDebug, "Tunnel: creating one hop outbound tunnel");
|
2014-04-03 00:42:02 +00:00
|
|
|
CreateTunnel<OutboundTunnel> (
|
2016-08-11 09:25:26 +00:00
|
|
|
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () },
|
|
|
|
inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ())
|
|
|
|
);
|
2013-12-07 00:02:49 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2013-12-07 00:02:49 +00:00
|
|
|
void Tunnels::ManageInboundTunnels ()
|
|
|
|
{
|
2014-01-09 19:56:07 +00:00
|
|
|
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2014-08-31 12:56:03 +00:00
|
|
|
for (auto it = m_InboundTunnels.begin (); it != m_InboundTunnels.end ();)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-03-02 16:58:52 +00:00
|
|
|
auto tunnel = *it;
|
2014-09-13 23:43:25 +00:00
|
|
|
if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
2014-08-31 12:56:03 +00:00
|
|
|
{
|
2016-01-18 00:00:00 +00:00
|
|
|
LogPrint (eLogDebug, "Tunnel: tunnel with id ", tunnel->GetTunnelID (), " expired");
|
2015-04-15 01:37:21 +00:00
|
|
|
auto pool = tunnel->GetTunnelPool ();
|
|
|
|
if (pool)
|
|
|
|
pool->TunnelExpired (tunnel);
|
2016-03-02 01:48:56 +00:00
|
|
|
m_Tunnels.erase (tunnel->GetTunnelID ());
|
2015-01-27 01:49:16 +00:00
|
|
|
it = m_InboundTunnels.erase (it);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-08-31 12:56:03 +00:00
|
|
|
else
|
|
|
|
{
|
2015-04-17 15:36:42 +00:00
|
|
|
if (tunnel->IsEstablished ())
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2015-04-17 15:36:42 +00:00
|
|
|
if (!tunnel->IsRecreated () && ts + TUNNEL_RECREATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
tunnel->SetIsRecreated ();
|
2015-04-17 15:36:42 +00:00
|
|
|
auto pool = tunnel->GetTunnelPool ();
|
|
|
|
if (pool)
|
|
|
|
pool->RecreateInboundTunnel (tunnel);
|
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2015-04-17 15:36:42 +00:00
|
|
|
if (ts + TUNNEL_EXPIRATION_THRESHOLD > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
|
|
|
tunnel->SetState (eTunnelStateExpiring);
|
2016-11-09 19:51:55 +00:00
|
|
|
else // we don't need to cleanup expiring tunnels
|
|
|
|
tunnel->Cleanup ();
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-08-31 12:56:03 +00:00
|
|
|
it++;
|
|
|
|
}
|
2014-08-26 14:31:32 +00:00
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2013-12-10 13:10:49 +00:00
|
|
|
|
|
|
|
if (m_InboundTunnels.empty ())
|
|
|
|
{
|
2016-01-18 00:00:00 +00:00
|
|
|
LogPrint (eLogDebug, "Tunnel: Creating zero hops inbound tunnel");
|
2013-12-10 13:10:49 +00:00
|
|
|
CreateZeroHopsInboundTunnel ();
|
2016-03-03 21:24:13 +00:00
|
|
|
CreateZeroHopsOutboundTunnel ();
|
2014-04-03 00:42:02 +00:00
|
|
|
if (!m_ExploratoryPool)
|
2015-12-16 19:52:48 +00:00
|
|
|
{
|
2017-02-28 20:58:53 +00:00
|
|
|
int ibLen; i2p::config::GetOption("exploratory.inbound.length", ibLen);
|
|
|
|
int obLen; i2p::config::GetOption("exploratory.outbound.length", obLen);
|
|
|
|
int ibNum; i2p::config::GetOption("exploratory.inbound.quantity", ibNum);
|
|
|
|
int obNum; i2p::config::GetOption("exploratory.outbound.quantity", obNum);
|
|
|
|
m_ExploratoryPool = CreateTunnelPool (ibLen, obLen, ibNum, obNum);
|
2015-12-16 19:52:48 +00:00
|
|
|
m_ExploratoryPool->SetLocalDestination (i2p::context.GetSharedDestination ());
|
|
|
|
}
|
2013-12-10 13:10:49 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
|
2016-11-02 19:17:05 +00:00
|
|
|
if (m_OutboundTunnels.empty () || m_InboundTunnels.size () < 3)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
// trying to create one more inbound tunnel
|
2016-10-28 16:50:26 +00:00
|
|
|
auto router = i2p::transport::transports.RoutesRestricted() ?
|
|
|
|
i2p::transport::transports.GetRestrictedPeer() :
|
|
|
|
i2p::data::netdb.GetRandomRouter ();
|
2016-06-28 18:24:18 +00:00
|
|
|
if (!router) {
|
2016-02-10 00:00:00 +00:00
|
|
|
LogPrint (eLogWarning, "Tunnel: can't find any router, skip creating tunnel");
|
|
|
|
return;
|
|
|
|
}
|
2016-01-18 00:00:00 +00:00
|
|
|
LogPrint (eLogDebug, "Tunnel: creating one hop inbound tunnel");
|
2014-04-03 00:42:02 +00:00
|
|
|
CreateTunnel<InboundTunnel> (
|
2015-11-03 14:15:49 +00:00
|
|
|
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () })
|
2016-08-11 09:25:26 +00:00
|
|
|
);
|
2013-12-07 00:02:49 +00:00
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-01-04 03:56:28 +00:00
|
|
|
|
|
|
|
void Tunnels::ManageTransitTunnels ()
|
|
|
|
{
|
|
|
|
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
|
|
|
|
for (auto it = m_TransitTunnels.begin (); it != m_TransitTunnels.end ();)
|
|
|
|
{
|
2016-03-02 01:48:56 +00:00
|
|
|
auto tunnel = *it;
|
|
|
|
if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
2014-01-04 03:56:28 +00:00
|
|
|
{
|
2016-03-02 01:48:56 +00:00
|
|
|
LogPrint (eLogDebug, "Tunnel: Transit tunnel with id ", tunnel->GetTunnelID (), " expired");
|
|
|
|
m_Tunnels.erase (tunnel->GetTunnelID ());
|
|
|
|
it = m_TransitTunnels.erase (it);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-01-04 03:56:28 +00:00
|
|
|
else
|
2016-11-09 19:51:55 +00:00
|
|
|
{
|
|
|
|
tunnel->Cleanup ();
|
2014-01-04 03:56:28 +00:00
|
|
|
it++;
|
2016-11-09 19:51:55 +00:00
|
|
|
}
|
2014-01-04 03:56:28 +00:00
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-03-15 00:24:12 +00:00
|
|
|
|
|
|
|
void Tunnels::ManageTunnelPools ()
|
|
|
|
{
|
2014-10-05 15:01:12 +00:00
|
|
|
std::unique_lock<std::mutex> l(m_PoolsMutex);
|
2016-08-09 22:16:24 +00:00
|
|
|
for (auto& pool : m_Pools)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2015-01-20 03:28:13 +00:00
|
|
|
if (pool && pool->IsActive ())
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2014-10-11 13:01:08 +00:00
|
|
|
pool->CreateTunnels ();
|
|
|
|
pool->TestTunnels ();
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2014-03-17 20:50:03 +00:00
|
|
|
}
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 18:38:31 +00:00
|
|
|
void Tunnels::PostTunnelData (std::shared_ptr<I2NPMessage> msg)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-08-11 09:25:26 +00:00
|
|
|
if (msg) m_Queue.Put (msg);
|
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
|
2015-06-19 18:38:31 +00:00
|
|
|
void Tunnels::PostTunnelData (const std::vector<std::shared_ptr<I2NPMessage> >& msgs)
|
2015-01-23 03:00:41 +00:00
|
|
|
{
|
|
|
|
m_Queue.Put (msgs);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
|
2013-12-07 00:02:49 +00:00
|
|
|
template<class TTunnel>
|
2015-05-06 20:17:48 +00:00
|
|
|
std::shared_ptr<TTunnel> Tunnels::CreateTunnel (std::shared_ptr<TunnelConfig> config, std::shared_ptr<OutboundTunnel> outboundTunnel)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2015-01-27 19:55:46 +00:00
|
|
|
auto newTunnel = std::make_shared<TTunnel> (config);
|
2015-11-03 14:15:49 +00:00
|
|
|
uint32_t replyMsgID;
|
|
|
|
RAND_bytes ((uint8_t *)&replyMsgID, 4);
|
2015-01-26 16:56:10 +00:00
|
|
|
AddPendingTunnel (replyMsgID, newTunnel);
|
2014-09-27 21:51:55 +00:00
|
|
|
newTunnel->Build (replyMsgID, outboundTunnel);
|
2013-12-07 00:02:49 +00:00
|
|
|
return newTunnel;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
|
2016-06-29 15:26:46 +00:00
|
|
|
std::shared_ptr<InboundTunnel> Tunnels::CreateInboundTunnel (std::shared_ptr<TunnelConfig> config, std::shared_ptr<OutboundTunnel> outboundTunnel)
|
|
|
|
{
|
2016-10-20 16:14:32 +00:00
|
|
|
if (config)
|
2016-06-29 15:26:46 +00:00
|
|
|
return CreateTunnel<InboundTunnel>(config, outboundTunnel);
|
2016-11-01 14:26:40 +00:00
|
|
|
else
|
2016-06-30 16:24:26 +00:00
|
|
|
return CreateZeroHopsInboundTunnel ();
|
2016-06-29 15:26:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<OutboundTunnel> Tunnels::CreateOutboundTunnel (std::shared_ptr<TunnelConfig> config)
|
|
|
|
{
|
2016-06-30 16:24:26 +00:00
|
|
|
if (config)
|
2016-06-29 15:26:46 +00:00
|
|
|
return CreateTunnel<OutboundTunnel>(config);
|
2016-06-30 16:24:26 +00:00
|
|
|
else
|
|
|
|
return CreateZeroHopsOutboundTunnel ();
|
2016-06-29 15:26:46 +00:00
|
|
|
}
|
|
|
|
|
2015-01-27 19:55:46 +00:00
|
|
|
void Tunnels::AddPendingTunnel (uint32_t replyMsgID, std::shared_ptr<InboundTunnel> tunnel)
|
2015-01-26 16:56:10 +00:00
|
|
|
{
|
|
|
|
m_PendingInboundTunnels[replyMsgID] = tunnel;
|
|
|
|
}
|
|
|
|
|
2015-01-27 19:55:46 +00:00
|
|
|
void Tunnels::AddPendingTunnel (uint32_t replyMsgID, std::shared_ptr<OutboundTunnel> tunnel)
|
2015-01-26 16:56:10 +00:00
|
|
|
{
|
|
|
|
m_PendingOutboundTunnels[replyMsgID] = tunnel;
|
|
|
|
}
|
|
|
|
|
2015-01-27 19:55:46 +00:00
|
|
|
void Tunnels::AddOutboundTunnel (std::shared_ptr<OutboundTunnel> newTunnel)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-03-02 01:48:56 +00:00
|
|
|
// we don't need to insert it to m_Tunnels
|
2013-12-10 13:10:49 +00:00
|
|
|
m_OutboundTunnels.push_back (newTunnel);
|
2014-03-16 20:03:20 +00:00
|
|
|
auto pool = newTunnel->GetTunnelPool ();
|
2014-10-13 15:21:57 +00:00
|
|
|
if (pool && pool->IsActive ())
|
2014-03-16 20:03:20 +00:00
|
|
|
pool->TunnelCreated (newTunnel);
|
2014-10-13 15:21:57 +00:00
|
|
|
else
|
|
|
|
newTunnel->SetTunnelPool (nullptr);
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
|
2015-01-27 19:55:46 +00:00
|
|
|
void Tunnels::AddInboundTunnel (std::shared_ptr<InboundTunnel> newTunnel)
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-03-02 01:48:56 +00:00
|
|
|
if (m_Tunnels.emplace (newTunnel->GetTunnelID (), newTunnel).second)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2016-03-02 16:58:52 +00:00
|
|
|
m_InboundTunnels.push_back (newTunnel);
|
2016-03-02 01:48:56 +00:00
|
|
|
auto pool = newTunnel->GetTunnelPool ();
|
|
|
|
if (!pool)
|
2016-08-11 09:25:26 +00:00
|
|
|
{
|
2016-03-02 01:48:56 +00:00
|
|
|
// build symmetric outbound tunnel
|
|
|
|
CreateTunnel<OutboundTunnel> (std::make_shared<TunnelConfig>(newTunnel->GetInvertedPeers (),
|
|
|
|
newTunnel->GetNextTunnelID (), newTunnel->GetNextIdentHash ()),
|
2016-08-11 09:25:26 +00:00
|
|
|
GetNextOutboundTunnel ());
|
2016-03-02 01:48:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (pool->IsActive ())
|
|
|
|
pool->TunnelCreated (newTunnel);
|
|
|
|
else
|
|
|
|
newTunnel->SetTunnelPool (nullptr);
|
|
|
|
}
|
2014-03-14 19:13:34 +00:00
|
|
|
}
|
2014-03-15 00:24:12 +00:00
|
|
|
else
|
2016-03-02 01:48:56 +00:00
|
|
|
LogPrint (eLogError, "Tunnel: tunnel with id ", newTunnel->GetTunnelID (), " already exists");
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
|
|
|
|
2013-12-07 00:02:49 +00:00
|
|
|
|
2016-06-29 15:26:46 +00:00
|
|
|
std::shared_ptr<ZeroHopsInboundTunnel> Tunnels::CreateZeroHopsInboundTunnel ()
|
2013-12-07 00:02:49 +00:00
|
|
|
{
|
2016-03-03 03:41:53 +00:00
|
|
|
auto inboundTunnel = std::make_shared<ZeroHopsInboundTunnel> ();
|
2016-03-03 22:57:15 +00:00
|
|
|
inboundTunnel->SetState (eTunnelStateEstablished);
|
2016-03-03 03:41:53 +00:00
|
|
|
m_InboundTunnels.push_back (inboundTunnel);
|
|
|
|
m_Tunnels[inboundTunnel->GetTunnelID ()] = inboundTunnel;
|
2016-06-29 15:26:46 +00:00
|
|
|
return inboundTunnel;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2015-01-10 03:27:52 +00:00
|
|
|
|
2016-06-29 15:26:46 +00:00
|
|
|
std::shared_ptr<ZeroHopsOutboundTunnel> Tunnels::CreateZeroHopsOutboundTunnel ()
|
2016-03-03 21:24:13 +00:00
|
|
|
{
|
2016-03-03 22:57:15 +00:00
|
|
|
auto outboundTunnel = std::make_shared<ZeroHopsOutboundTunnel> ();
|
|
|
|
outboundTunnel->SetState (eTunnelStateEstablished);
|
|
|
|
m_OutboundTunnels.push_back (outboundTunnel);
|
2016-03-03 21:24:13 +00:00
|
|
|
// we don't insert into m_Tunnels
|
2016-06-29 15:26:46 +00:00
|
|
|
return outboundTunnel;
|
2016-03-03 21:24:13 +00:00
|
|
|
}
|
|
|
|
|
2015-01-10 03:27:52 +00:00
|
|
|
int Tunnels::GetTransitTunnelsExpirationTimeout ()
|
|
|
|
{
|
|
|
|
int timeout = 0;
|
|
|
|
uint32_t ts = i2p::util::GetSecondsSinceEpoch ();
|
2016-03-02 01:48:56 +00:00
|
|
|
// TODO: possible race condition with I2PControl
|
2016-08-09 22:16:24 +00:00
|
|
|
for (const auto& it : m_TransitTunnels)
|
2015-01-10 03:27:52 +00:00
|
|
|
{
|
2016-03-02 01:48:56 +00:00
|
|
|
int t = it->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT - ts;
|
2015-01-10 03:27:52 +00:00
|
|
|
if (t > timeout) timeout = t;
|
2016-08-11 09:25:26 +00:00
|
|
|
}
|
2015-01-10 03:27:52 +00:00
|
|
|
return timeout;
|
2016-03-02 14:41:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-02 16:58:52 +00:00
|
|
|
size_t Tunnels::CountTransitTunnels() const
|
|
|
|
{
|
2016-03-02 15:05:26 +00:00
|
|
|
// TODO: locking
|
|
|
|
return m_TransitTunnels.size();
|
|
|
|
}
|
|
|
|
|
2016-03-02 16:58:52 +00:00
|
|
|
size_t Tunnels::CountInboundTunnels() const
|
|
|
|
{
|
2016-03-02 15:05:26 +00:00
|
|
|
// TODO: locking
|
|
|
|
return m_InboundTunnels.size();
|
|
|
|
}
|
|
|
|
|
2016-03-02 16:58:52 +00:00
|
|
|
size_t Tunnels::CountOutboundTunnels() const
|
|
|
|
{
|
2016-03-02 15:05:26 +00:00
|
|
|
// TODO: locking
|
|
|
|
return m_OutboundTunnels.size();
|
|
|
|
}
|
2013-12-07 00:02:49 +00:00
|
|
|
}
|
|
|
|
}
|