Browse Source

Destinations: set thread name from tunnel name

Signed-off-by: r4sas <r4sas@i2pmail.org>
pull/2125/head
R4SAS 1 month ago
parent
commit
574d12298b
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 50
      libi2pd/Destination.cpp
  2. 8
      libi2pd/util.h
  3. 21
      libi2pd_client/ClientContext.cpp

50
libi2pd/Destination.cpp

@ -37,7 +37,7 @@ namespace client @@ -37,7 +37,7 @@ namespace client
int inVar = DEFAULT_INBOUND_TUNNELS_LENGTH_VARIANCE;
int outVar = DEFAULT_OUTBOUND_TUNNELS_LENGTH_VARIANCE;
int numTags = DEFAULT_TAGS_TO_SEND;
bool isHighBandwidth = true;
bool isHighBandwidth = true;
std::shared_ptr<std::vector<i2p::data::IdentHash> > explicitPeers;
try
{
@ -471,7 +471,7 @@ namespace client @@ -471,7 +471,7 @@ namespace client
{
auto it2 = m_LeaseSetRequests.find (key);
if (it2 != m_LeaseSetRequests.end ())
{
{
request = it2->second;
m_LeaseSetRequests.erase (it2);
if (request->requestedBlindedKey)
@ -493,14 +493,14 @@ namespace client @@ -493,14 +493,14 @@ namespace client
// publishing verification doesn't have requestedBlindedKey
auto localLeaseSet = GetLeaseSetMt ();
if (localLeaseSet->GetStoreHash () == key)
{
auto ls = std::make_shared<i2p::data::LeaseSet2> (i2p::data::NETDB_STORE_TYPE_ENCRYPTED_LEASESET2,
{
auto ls = std::make_shared<i2p::data::LeaseSet2> (i2p::data::NETDB_STORE_TYPE_ENCRYPTED_LEASESET2,
localLeaseSet->GetBuffer (), localLeaseSet->GetBufferLen (), false);
leaseSet = ls;
}
leaseSet = ls;
}
else
LogPrint (eLogWarning, "Destination: Encrypted LeaseSet2 received for request without blinded key");
}
}
}
else
LogPrint (eLogWarning, "Destination: Couldn't find request for encrypted LeaseSet2");
@ -511,14 +511,14 @@ namespace client @@ -511,14 +511,14 @@ namespace client
}
if (!request)
{
{
auto it1 = m_LeaseSetRequests.find (key);
if (it1 != m_LeaseSetRequests.end ())
{
{
request = it1->second;
m_LeaseSetRequests.erase (it1);
}
}
}
}
if (request)
{
request->requestTimeoutTimer.cancel ();
@ -550,7 +550,7 @@ namespace client @@ -550,7 +550,7 @@ namespace client
LogPrint (eLogWarning, "Destination: Request for ", key.ToBase64 (), " not found");
}
void LeaseSetDestination::SendNextLeaseSetRequest (const i2p::data::IdentHash& key,
void LeaseSetDestination::SendNextLeaseSetRequest (const i2p::data::IdentHash& key,
std::shared_ptr<LeaseSetRequest> request)
{
bool found = false;
@ -570,8 +570,8 @@ namespace client @@ -570,8 +570,8 @@ namespace client
request->Complete (nullptr);
m_LeaseSetRequests.erase (key);
}
}
}
void LeaseSetDestination::HandleDeliveryStatusMessage (uint32_t msgID)
{
if (msgID == m_PublishReplyToken)
@ -592,7 +592,7 @@ namespace client @@ -592,7 +592,7 @@ namespace client
{
if (post)
m_Service.post([s = shared_from_this ()]() { s->UpdateLeaseSet (); });
else
else
UpdateLeaseSet ();
}
@ -631,7 +631,7 @@ namespace client @@ -631,7 +631,7 @@ namespace client
if (!outbound || !inbound)
{
if (!m_Pool->GetInboundTunnels ().empty () && !m_Pool->GetOutboundTunnels ().empty ())
{
{
LogPrint (eLogInfo, "Destination: No compatible tunnels with ", floodfill->GetIdentHash ().ToBase64 (), ". Trying another floodfill");
m_ExcludedFloodfills.insert (floodfill->GetIdentHash ());
floodfill = i2p::data::netdb.GetClosestFloodfill (leaseSet->GetStoreHash (), m_ExcludedFloodfills);
@ -649,10 +649,10 @@ namespace client @@ -649,10 +649,10 @@ namespace client
}
else
LogPrint (eLogError, "Destination: Can't publish LeaseSet, no more floodfills found");
}
}
else
LogPrint (eLogDebug, "Destination: No tunnels in pool");
if (!floodfill || !outbound || !inbound)
{
// we can't publish now
@ -880,8 +880,8 @@ namespace client @@ -880,8 +880,8 @@ namespace client
AddECIESx25519Key (replyKey, replyTag);
else
AddSessionKey (replyKey, replyTag);
auto msg = WrapMessageForRouter (nextFloodfill,
auto msg = WrapMessageForRouter (nextFloodfill,
CreateLeaseSetDatabaseLookupMsg (dest, request->excluded, request->replyTunnel, replyKey, replyTag, isECIES));
auto s = shared_from_this ();
msg->onDrop = [s, dest, request]()
@ -890,7 +890,7 @@ namespace client @@ -890,7 +890,7 @@ namespace client
{
s->SendNextLeaseSetRequest (dest, request);
});
};
};
request->outboundTunnel->SendTunnelDataMsgs (
{
i2p::tunnel::TunnelMessageBlock
@ -988,7 +988,7 @@ namespace client @@ -988,7 +988,7 @@ namespace client
m_Keys (keys), m_StreamingAckDelay (DEFAULT_INITIAL_ACK_DELAY),
m_StreamingOutboundSpeed (DEFAULT_MAX_OUTBOUND_SPEED),
m_StreamingInboundSpeed (DEFAULT_MAX_INBOUND_SPEED),
m_StreamingMaxConcurrentStreams (DEFAULT_MAX_CONCURRENT_STREAMS),
m_StreamingMaxConcurrentStreams (DEFAULT_MAX_CONCURRENT_STREAMS),
m_IsStreamingAnswerPings (DEFAULT_ANSWER_PINGS), m_LastPort (0),
m_DatagramDestination (nullptr), m_RefCounter (0), m_LastPublishedTimestamp (0),
m_ReadyChecker(service)
@ -1441,11 +1441,11 @@ namespace client @@ -1441,11 +1441,11 @@ namespace client
keySections.push_back ({m_StandardEncryptionKey->keyType, (uint16_t)m_StandardEncryptionKey->decryptor->GetPublicKeyLen (), m_StandardEncryptionKey->pub} );
auto publishedTimestamp = i2p::util::GetSecondsSinceEpoch ();
if (publishedTimestamp <= m_LastPublishedTimestamp)
if (publishedTimestamp <= m_LastPublishedTimestamp)
{
LogPrint (eLogDebug, "Destination: LeaseSet update at the same second");
publishedTimestamp++; // force newer timestamp
}
}
bool isPublishedEncrypted = GetLeaseSetType () == i2p::data::NETDB_STORE_TYPE_ENCRYPTED_LEASESET2;
auto ls2 = std::make_shared<i2p::data::LocalLeaseSet2> (i2p::data::NETDB_STORE_TYPE_STANDARD_LEASESET2,
m_Keys, keySections, tunnels, IsPublic (), publishedTimestamp, isPublishedEncrypted);
@ -1517,6 +1517,8 @@ namespace client @@ -1517,6 +1517,8 @@ namespace client
RunnableService ("Destination"),
ClientDestination (GetIOService (), keys, isPublic, params)
{
if (!GetNickname ().empty ())
RunnableService::SetName (GetNickname ());
}
RunnableClientDestination::~RunnableClientDestination ()

8
libi2pd/util.h

@ -137,8 +137,8 @@ namespace util @@ -137,8 +137,8 @@ namespace util
std::lock_guard<std::mutex> l(m_Mutex);
for (size_t i = 0; i < num; i++)
this->Release (arr[i]);
}
}
template<template<typename, typename...>class C, typename... R>
void ReleaseMt(const C<T *, R...>& c)
{
@ -146,7 +146,7 @@ namespace util @@ -146,7 +146,7 @@ namespace util
for (auto& it: c)
this->Release (it);
}
template<typename... TArgs>
std::shared_ptr<T> AcquireSharedMt (TArgs&&... args)
{
@ -183,6 +183,8 @@ namespace util @@ -183,6 +183,8 @@ namespace util
void StartIOService ();
void StopIOService ();
void SetName (std::string_view name) { m_Name = name; };
private:
void Run ();

21
libi2pd_client/ClientContext.cpp

@ -421,7 +421,8 @@ namespace client @@ -421,7 +421,8 @@ namespace client
{ I2CP_PARAM_INBOUND_TUNNELS_QUANTITY, "3" },
{ I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY, "3" },
{ I2CP_PARAM_LEASESET_TYPE, "3" },
{ I2CP_PARAM_LEASESET_ENCRYPTION_TYPE, "0,4" }
{ I2CP_PARAM_LEASESET_ENCRYPTION_TYPE, "0,4" },
{ I2CP_PARAM_OUTBOUND_NICKNAME, "SharedDest" }
};
m_SharedLocalDestination = CreateNewLocalDestination (false, i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519,
i2p::data::CRYPTO_KEY_TYPE_ELGAMAL, &params); // non-public, EDDSA
@ -475,7 +476,7 @@ namespace client @@ -475,7 +476,7 @@ namespace client
options[I2CP_PARAM_STREAMING_MAX_INBOUND_SPEED] = GetI2CPOption(section, I2CP_PARAM_STREAMING_MAX_INBOUND_SPEED, DEFAULT_MAX_INBOUND_SPEED);
options[I2CP_PARAM_STREAMING_MAX_CONCURRENT_STREAMS] = GetI2CPOption(section, I2CP_PARAM_STREAMING_MAX_CONCURRENT_STREAMS, DEFAULT_MAX_CONCURRENT_STREAMS);
options[I2CP_PARAM_STREAMING_ANSWER_PINGS] = GetI2CPOption(section, I2CP_PARAM_STREAMING_ANSWER_PINGS, isServer ? DEFAULT_ANSWER_PINGS : false);
options[I2CP_PARAM_STREAMING_PROFILE] = GetI2CPOption(section, I2CP_PARAM_STREAMING_PROFILE, DEFAULT_STREAMING_PROFILE);
options[I2CP_PARAM_STREAMING_PROFILE] = GetI2CPOption(section, I2CP_PARAM_STREAMING_PROFILE, DEFAULT_STREAMING_PROFILE);
options[I2CP_PARAM_LEASESET_TYPE] = GetI2CPOption(section, I2CP_PARAM_LEASESET_TYPE, DEFAULT_LEASESET_TYPE);
std::string encType = GetI2CPStringOption(section, I2CP_PARAM_LEASESET_ENCRYPTION_TYPE, isServer ? "4" : "0,4");
if (encType.length () > 0) options[I2CP_PARAM_LEASESET_ENCRYPTION_TYPE] = encType;
@ -596,6 +597,11 @@ namespace client @@ -596,6 +597,11 @@ namespace client
std::map<std::string, std::string> options;
ReadI2CPOptions (section, false, options);
// Set I2CP name if not set
auto itopt = options.find (I2CP_PARAM_OUTBOUND_NICKNAME);
if (itopt == options.end ())
options[I2CP_PARAM_OUTBOUND_NICKNAME] = name;
std::shared_ptr<ClientDestination> localDestination = nullptr;
if (keys.length () > 0)
{
@ -668,7 +674,7 @@ namespace client @@ -668,7 +674,7 @@ namespace client
std::string outproxy = section.second.get("outproxy", "");
bool addresshelper = section.second.get("addresshelper", true);
bool senduseragent = section.second.get("senduseragent", false);
auto tun = std::make_shared<i2p::proxy::HTTPProxy>(name, address, port,
auto tun = std::make_shared<i2p::proxy::HTTPProxy>(name, address, port,
outproxy, addresshelper, senduseragent, localDestination);
clientTunnel = tun;
clientEndpoint = tun->GetLocalEndpoint ();
@ -750,6 +756,11 @@ namespace client @@ -750,6 +756,11 @@ namespace client
std::map<std::string, std::string> options;
ReadI2CPOptions (section, true, options);
// Set I2CP name if not set
auto itopt = options.find (I2CP_PARAM_INBOUND_NICKNAME);
if (itopt == options.end ())
options[I2CP_PARAM_INBOUND_NICKNAME] = name;
std::shared_ptr<ClientDestination> localDestination = nullptr;
auto it = destinations.find (keys);
if (it != destinations.end ())
@ -897,6 +908,7 @@ namespace client @@ -897,6 +908,7 @@ namespace client
{
std::map<std::string, std::string> params;
ReadI2CPOptionsFromConfig ("httpproxy.", params);
params[I2CP_PARAM_OUTBOUND_NICKNAME] = "HTTPProxy";
localDestination = CreateNewLocalDestination (keys, false, &params);
if (localDestination) localDestination->Acquire ();
}
@ -905,7 +917,7 @@ namespace client @@ -905,7 +917,7 @@ namespace client
}
try
{
m_HttpProxy = new i2p::proxy::HTTPProxy("HTTP Proxy", httpProxyAddr, httpProxyPort,
m_HttpProxy = new i2p::proxy::HTTPProxy("HTTP Proxy", httpProxyAddr, httpProxyPort,
httpOutProxyURL, httpAddresshelper, httpSendUserAgent, localDestination);
m_HttpProxy->Start();
}
@ -945,6 +957,7 @@ namespace client @@ -945,6 +957,7 @@ namespace client
{
std::map<std::string, std::string> params;
ReadI2CPOptionsFromConfig ("socksproxy.", params);
params[I2CP_PARAM_OUTBOUND_NICKNAME] = "SOCKSProxy";
localDestination = CreateNewLocalDestination (keys, false, &params);
if (localDestination) localDestination->Acquire ();
}

Loading…
Cancel
Save