Console: UI-changes only (no logging)

This commit is contained in:
dr|z3d 2021-09-12 18:06:35 +00:00
parent e054c6e82c
commit 182e78b145
2 changed files with 1357 additions and 487 deletions

File diff suppressed because it is too large Load diff

View file

@ -46,7 +46,7 @@ namespace tunnel
const int numRecords = numHops <= STANDARD_NUM_RECORDS ? STANDARD_NUM_RECORDS : MAX_NUM_RECORDS;
auto msg = numRecords <= STANDARD_NUM_RECORDS ? NewI2NPShortMessage () : NewI2NPMessage ();
*msg->GetPayload () = numRecords;
const size_t recordSize = m_Config->IsShort () ? SHORT_TUNNEL_BUILD_RECORD_SIZE : TUNNEL_BUILD_RECORD_SIZE;
const size_t recordSize = m_Config->IsShort () ? SHORT_TUNNEL_BUILD_RECORD_SIZE : TUNNEL_BUILD_RECORD_SIZE;
msg->len += numRecords*recordSize + 1;
// shuffle records
std::vector<int> recordIndicies;
@ -97,13 +97,13 @@ namespace tunnel
{
auto ident = m_Config->GetFirstHop () ? m_Config->GetFirstHop ()->ident : nullptr;
if (ident && ident->GetIdentHash () != outboundTunnel->GetNextIdentHash ()) // don't encrypt if IBGW = OBEP
{
{
auto msg1 = i2p::garlic::WrapECIESX25519MessageForRouter (msg, ident->GetEncryptionPublicKey ());
if (msg1) msg = msg1;
}
}
}
}
outboundTunnel->SendTunnelDataMsg (GetNextIdentHash (), 0, msg);
}
}
else
{
if (m_Config->IsShort () && m_Config->GetLastHop () &&
@ -114,11 +114,11 @@ namespace tunnel
uint64_t tag = m_Config->GetLastHop ()->GetGarlicKey (key);
if (m_Pool && m_Pool->GetLocalDestination ())
m_Pool->GetLocalDestination ()->AddECIESx25519Key (key, tag);
else
else
i2p::context.AddECIESx25519Key (key, tag);
}
}
i2p::transport::transports.SendMessage (GetNextIdentHash (), msg);
}
}
}
bool Tunnel::HandleTunnelBuildResponse (uint8_t * msg, size_t len)
@ -133,14 +133,14 @@ namespace tunnel
{
if (!hop->DecryptBuildResponseRecord (msg + 1))
return false;
}
}
else
{
LogPrint (eLogWarning, "Tunnel: hop index ", hop->recordIndex, " is out of range");
LogPrint (eLogWarning, "Tunnel: Hop index ", hop->recordIndex, " is out of range");
return false;
}
// decrypt records before current hop
}
// decrypt records before current hop
TunnelHopConfig * hop1 = hop->prev;
while (hop1)
{
@ -148,7 +148,7 @@ namespace tunnel
if (idx >= 0 && idx < msg[0])
hop->DecryptRecord (msg + 1, idx);
else
LogPrint (eLogWarning, "Tunnel: hop index ", idx, " is out of range");
LogPrint (eLogWarning, "Tunnel: Hop index ", idx, " is out of range");
hop1 = hop1->prev;
}
hop = hop->prev;
@ -235,8 +235,9 @@ namespace tunnel
// hops are in inverted order, we must print in direct order
for (auto it = m_Hops.rbegin (); it != m_Hops.rend (); it++)
{
s << " &#8658; ";
s << " <span class=\"arrowright\">&#8658;</span> <span class=\"hop\">";
s << i2p::data::GetIdentHashAbbreviation ((*it)->ident->GetIdentHash ());
s << "</span>";
}
}
@ -251,8 +252,12 @@ namespace tunnel
void InboundTunnel::Print (std::stringstream& s) const
{
s << "<span class=\"hops\">";
PrintHops (s);
s << " &#8658; " << GetTunnelID () << ":me";
s << " <span class=\"arrowright zerohop\">&#8658;</span> ";
s << " <span class=\"tunnelid local\" data-tooltip=\"";
s << GetTunnelID () << "\">Local</span></span>";
s << "<span class=\"tunnelid\">" << GetTunnelID () << "</span>";
}
ZeroHopsInboundTunnel::ZeroHopsInboundTunnel ():
@ -273,7 +278,10 @@ namespace tunnel
void ZeroHopsInboundTunnel::Print (std::stringstream& s) const
{
s << " &#8658; " << GetTunnelID () << ":me";
s << "<span class=\"hops\">";
s << "<span class=\"arrowright zerohop\">&#8658;</span> <span class=\"tunnelid local\" data-tooltip=\""
<< GetTunnelID () << "\">Local</span></span>";
s << "<span class=\"tunnelid\">" << GetTunnelID () << "</span>";
}
void OutboundTunnel::SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, std::shared_ptr<i2p::I2NPMessage> msg)
@ -307,14 +315,15 @@ namespace tunnel
void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
{
LogPrint (eLogError, "Tunnel: incoming message for outbound tunnel ", GetTunnelID ());
LogPrint (eLogError, "Tunnel: Incoming message for outbound tunnel ", GetTunnelID ());
}
void OutboundTunnel::Print (std::stringstream& s) const
{
s << GetTunnelID () << ":me";
s << "<span class=\"hops\">";
s << "<span class=\"tunnelid local\" data-tooltip=\"" << GetTunnelID () << "\">Local</span>";
PrintHops (s);
s << " &#8658; ";
s << "</span> <span class=\"tunnelid\">" << GetTunnelID () << "</span>";
}
ZeroHopsOutboundTunnel::ZeroHopsOutboundTunnel ():
@ -348,7 +357,11 @@ namespace tunnel
void ZeroHopsOutboundTunnel::Print (std::stringstream& s) const
{
s << GetTunnelID () << ":me &#8658; ";
s << "<span class=\"hops\">";
s << "<span class=\"arrowright\">&#8658;</span> ";
s << "<span class=\"tunnelid local\" data-tooltip=\""
<< GetTunnelID () << "\">" << GetTunnelID () << "\">Local</span></span>";
s << "<span class=\"tunnelid\">" << GetTunnelID () << "</span>";
}
Tunnels tunnels;
@ -460,7 +473,7 @@ namespace tunnel
if (m_Tunnels.emplace (tunnel->GetTunnelID (), tunnel).second)
m_TransitTunnels.push_back (tunnel);
else
LogPrint (eLogError, "Tunnel: tunnel with id ", tunnel->GetTunnelID (), " already exists");
LogPrint (eLogError, "Tunnel: Tunnel with id ", tunnel->GetTunnelID (), " already exists");
}
void Tunnels::Start ()
@ -521,7 +534,7 @@ namespace tunnel
HandleTunnelGatewayMsg (tunnel, msg);
}
else
LogPrint (eLogWarning, "Tunnel: tunnel not found, tunnelID=", tunnelID, " previousTunnelID=", prevTunnelID, " type=", (int)typeID);
LogPrint (eLogWarning, "Tunnel: Tunnel not found, tunnelID=", tunnelID, " previousTunnelID=", prevTunnelID, " type=", (int)typeID);
break;
}
@ -530,11 +543,11 @@ namespace tunnel
case eI2NPShortTunnelBuild:
case eI2NPShortTunnelBuildReply:
case eI2NPTunnelBuild:
case eI2NPTunnelBuildReply:
case eI2NPTunnelBuildReply:
HandleI2NPMessage (msg->GetBuffer (), msg->GetLength ());
break;
default:
LogPrint (eLogWarning, "Tunnel: unexpected message type ", (int) typeID);
LogPrint (eLogWarning, "Tunnel: Unexpected message type ", (int) typeID);
}
msg = m_Queue.Get ();
@ -561,12 +574,12 @@ namespace tunnel
{
ManageTunnelPools (ts);
lastPoolsTs = ts;
}
}
}
}
}
catch (std::exception& ex)
{
LogPrint (eLogError, "Tunnel: runtime exception: ", ex.what ());
LogPrint (eLogError, "Tunnel: Runtime exception: ", ex.what ());
}
}
}
@ -575,7 +588,7 @@ namespace tunnel
{
if (!tunnel)
{
LogPrint (eLogError, "Tunnel: missing tunnel for gateway");
LogPrint (eLogError, "Tunnel: Missing tunnel for gateway");
return;
}
const uint8_t * payload = msg->GetPayload ();
@ -584,12 +597,12 @@ namespace tunnel
msg->offset += I2NP_HEADER_SIZE + TUNNEL_GATEWAY_HEADER_SIZE;
if (msg->offset + len > msg->len)
{
LogPrint (eLogError, "Tunnel: gateway payload ", (int)len, " exceeds message length ", (int)msg->len);
LogPrint (eLogError, "Tunnel: Gateway payload ", (int)len, " exceeds message length ", (int)msg->len);
return;
}
msg->len = msg->offset + len;
auto typeID = msg->GetTypeID ();
LogPrint (eLogDebug, "Tunnel: gateway of ", (int) len, " bytes for tunnel ", tunnel->GetTunnelID (), ", msg type ", (int)typeID);
LogPrint (eLogDebug, "Tunnel: Gateway of ", (int) len, " bytes for tunnel ", tunnel->GetTunnelID (), ", msg type ", (int)typeID);
if (IsRouterInfoMsg (msg) || typeID == eI2NPDatabaseSearchReply)
// transit DatabaseStore my contain new/updated RI
@ -625,7 +638,7 @@ namespace tunnel
case eTunnelStatePending:
if (ts > tunnel->GetCreationTime () + TUNNEL_CREATION_TIMEOUT)
{
LogPrint (eLogDebug, "Tunnel: pending build request ", it->first, " timeout, deleted");
LogPrint (eLogDebug, "Tunnel: Pending build request ", it->first, " timeout, deleted");
// update stats
auto config = tunnel->GetTunnelConfig ();
if (config)
@ -650,7 +663,7 @@ namespace tunnel
++it;
break;
case eTunnelStateBuildFailed:
LogPrint (eLogDebug, "Tunnel: pending build request ", it->first, " failed, deleted");
LogPrint (eLogDebug, "Tunnel: Pending build request ", it->first, " failed, deleted");
it = pendingTunnels.erase (it);
m_NumFailedTunnelCreations++;
break;
@ -675,7 +688,7 @@ namespace tunnel
auto tunnel = *it;
if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
{
LogPrint (eLogDebug, "Tunnel: tunnel with id ", tunnel->GetTunnelID (), " expired");
LogPrint (eLogDebug, "Tunnel: Tunnel with id ", tunnel->GetTunnelID (), " expired");
auto pool = tunnel->GetTunnelPool ();
if (pool)
pool->TunnelExpired (tunnel);
@ -712,7 +725,7 @@ namespace tunnel
i2p::transport::transports.GetRestrictedPeer() :
i2p::data::netdb.GetRandomRouter (i2p::context.GetSharedRouterInfo (), false); // reachable by us
if (!inboundTunnel || !router) return;
LogPrint (eLogDebug, "Tunnel: creating one hop outbound tunnel");
LogPrint (eLogDebug, "Tunnel: Creating one hop outbound tunnel");
CreateTunnel<OutboundTunnel> (
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () },
inboundTunnel->GetNextTunnelID (), inboundTunnel->GetNextIdentHash ()), nullptr
@ -729,7 +742,7 @@ namespace tunnel
auto tunnel = *it;
if (ts > tunnel->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
{
LogPrint (eLogDebug, "Tunnel: tunnel with id ", tunnel->GetTunnelID (), " expired");
LogPrint (eLogDebug, "Tunnel: Tunnel with id ", tunnel->GetTunnelID (), " expired");
auto pool = tunnel->GetTunnelPool ();
if (pool)
pool->TunnelExpired (tunnel);
@ -763,7 +776,7 @@ namespace tunnel
if (m_InboundTunnels.empty ())
{
LogPrint (eLogDebug, "Tunnel: Creating zero hops inbound tunnel");
LogPrint (eLogDebug, "Tunnel: Creating zero hop inbound tunnel");
CreateZeroHopsInboundTunnel (nullptr);
CreateZeroHopsOutboundTunnel (nullptr);
if (!m_ExploratoryPool)
@ -786,10 +799,10 @@ namespace tunnel
// should be reachable by us because we send build request directly
i2p::data::netdb.GetRandomRouter (i2p::context.GetSharedRouterInfo (), false);
if (!router) {
LogPrint (eLogWarning, "Tunnel: can't find any router, skip creating tunnel");
LogPrint (eLogWarning, "Tunnel: Can't find any router, skipping tunnel creation");
return;
}
LogPrint (eLogDebug, "Tunnel: creating one hop inbound tunnel");
LogPrint (eLogDebug, "Tunnel: Creating one hop inbound tunnel");
CreateTunnel<InboundTunnel> (
std::make_shared<TunnelConfig> (std::vector<std::shared_ptr<const i2p::data::IdentityEx> > { router->GetRouterIdentity () }), nullptr
);
@ -837,7 +850,7 @@ namespace tunnel
}
template<class TTunnel>
std::shared_ptr<TTunnel> Tunnels::CreateTunnel (std::shared_ptr<TunnelConfig> config,
std::shared_ptr<TTunnel> Tunnels::CreateTunnel (std::shared_ptr<TunnelConfig> config,
std::shared_ptr<TunnelPool> pool, std::shared_ptr<OutboundTunnel> outboundTunnel)
{
auto newTunnel = std::make_shared<TTunnel> (config);
@ -849,7 +862,7 @@ namespace tunnel
return newTunnel;
}
std::shared_ptr<InboundTunnel> Tunnels::CreateInboundTunnel (std::shared_ptr<TunnelConfig> config,
std::shared_ptr<InboundTunnel> Tunnels::CreateInboundTunnel (std::shared_ptr<TunnelConfig> config,
std::shared_ptr<TunnelPool> pool, std::shared_ptr<OutboundTunnel> outboundTunnel)
{
if (config)
@ -913,7 +926,7 @@ namespace tunnel
}
std::shared_ptr<ZeroHopsInboundTunnel> Tunnels::CreateZeroHopsInboundTunnel (std::shared_ptr<TunnelPool> pool)
std::shared_ptr<ZeroHopsInboundTunnel> Tunnels::CreateZeroHopsInboundTunnel (std::shared_ptr<TunnelPool> pool)
{
auto inboundTunnel = std::make_shared<ZeroHopsInboundTunnel> ();
inboundTunnel->SetTunnelPool (pool);