mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-10-23 12:09:03 +01:00
Merge branch 'PurpleI2P:openssl' into main
This commit is contained in:
commit
27807c2c96
3 changed files with 24 additions and 74 deletions
|
@ -167,31 +167,28 @@ namespace client
|
|||
|
||||
bool LeaseSetDestination::Reconfigure(const i2p::util::Mapping& params)
|
||||
{
|
||||
params.Get ("i2cp.dontPublishLeaseSet", m_IsPublic);
|
||||
|
||||
int inLen = 0, outLen = 0, inQuant = 0, outQuant = 0, numTags = 0, minLatency = 0, maxLatency = 0;
|
||||
std::map<std::string_view, int&> intOpts =
|
||||
{
|
||||
{I2CP_PARAM_INBOUND_TUNNEL_LENGTH, inLen},
|
||||
{I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH, outLen},
|
||||
{I2CP_PARAM_INBOUND_TUNNELS_QUANTITY, inQuant},
|
||||
{I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY, outQuant},
|
||||
{I2CP_PARAM_TAGS_TO_SEND, numTags},
|
||||
{I2CP_PARAM_MIN_TUNNEL_LATENCY, minLatency},
|
||||
{I2CP_PARAM_MAX_TUNNEL_LATENCY, maxLatency}
|
||||
};
|
||||
params.Get (I2CP_PARAM_DONT_PUBLISH_LEASESET, m_IsPublic);
|
||||
|
||||
auto numTags = GetNumTags ();
|
||||
params.Get (I2CP_PARAM_TAGS_TO_SEND, numTags);
|
||||
auto numRatchetInboundTags = GetNumRatchetInboundTags ();
|
||||
params.Get (I2CP_PARAM_RATCHET_INBOUND_TAGS, numRatchetInboundTags);
|
||||
auto pool = GetTunnelPool();
|
||||
inLen = pool->GetNumInboundHops();
|
||||
outLen = pool->GetNumOutboundHops();
|
||||
inQuant = pool->GetNumInboundTunnels();
|
||||
outQuant = pool->GetNumOutboundTunnels();
|
||||
minLatency = 0;
|
||||
maxLatency = 0;
|
||||
|
||||
for (auto & opt : intOpts)
|
||||
params.Get (opt.first, opt.second);
|
||||
|
||||
auto inLen = pool->GetNumInboundHops();
|
||||
params.Get (I2CP_PARAM_INBOUND_TUNNEL_LENGTH, inLen);
|
||||
auto outLen = pool->GetNumOutboundHops();
|
||||
params.Get (I2CP_PARAM_OUTBOUND_TUNNEL_LENGTH, outLen);
|
||||
auto inQuant = pool->GetNumInboundTunnels();
|
||||
params.Get (I2CP_PARAM_INBOUND_TUNNELS_QUANTITY, inQuant);
|
||||
auto outQuant = pool->GetNumOutboundTunnels();
|
||||
params.Get (I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY, outQuant);
|
||||
int minLatency = 0;
|
||||
params.Get (I2CP_PARAM_MIN_TUNNEL_LATENCY, minLatency);
|
||||
int maxLatency = 0;
|
||||
params.Get (I2CP_PARAM_MAX_TUNNEL_LATENCY, maxLatency);
|
||||
|
||||
SetNumTags (numTags);
|
||||
SetNumRatchetInboundTags (numRatchetInboundTags);
|
||||
pool->RequireLatency(minLatency, maxLatency);
|
||||
return pool->Reconfigure(inLen, outLen, inQuant, outQuant);
|
||||
}
|
||||
|
|
|
@ -620,50 +620,6 @@ namespace client
|
|||
m_IsSending = false;
|
||||
}
|
||||
|
||||
std::string_view I2CPSession::ExtractString (const uint8_t * buf, size_t len) const
|
||||
{
|
||||
uint8_t l = buf[0];
|
||||
if (l > len) l = len;
|
||||
return { (const char *)(buf + 1), l };
|
||||
}
|
||||
|
||||
size_t I2CPSession::PutString (uint8_t * buf, size_t len, std::string_view str)
|
||||
{
|
||||
auto l = str.length ();
|
||||
if (l + 1 >= len) l = len - 1;
|
||||
if (l > 255) l = 255; // 1 byte max
|
||||
buf[0] = l;
|
||||
memcpy (buf + 1, str.data (), l);
|
||||
return l + 1;
|
||||
}
|
||||
|
||||
void I2CPSession::ExtractMapping (const uint8_t * buf, size_t len, i2p::util::Mapping& mapping) const
|
||||
// TODO: call FromBuffer
|
||||
{
|
||||
size_t offset = 0;
|
||||
while (offset < len)
|
||||
{
|
||||
auto param = ExtractString (buf + offset, len - offset);
|
||||
offset += param.length () + 1;
|
||||
if (buf[offset] != '=')
|
||||
{
|
||||
LogPrint (eLogWarning, "I2CP: Unexpected character ", buf[offset], " instead '=' after ", param);
|
||||
break;
|
||||
}
|
||||
offset++;
|
||||
|
||||
auto value = ExtractString (buf + offset, len - offset);
|
||||
offset += value.length () + 1;
|
||||
if (buf[offset] != ';')
|
||||
{
|
||||
LogPrint (eLogWarning, "I2CP: Unexpected character ", buf[offset], " instead ';' after ", value);
|
||||
break;
|
||||
}
|
||||
offset++;
|
||||
mapping.Insert (param, value);
|
||||
}
|
||||
}
|
||||
|
||||
void I2CPSession::GetDateMessageHandler (const uint8_t * buf, size_t len)
|
||||
{
|
||||
constexpr std::string_view version(I2P_VERSION);
|
||||
|
@ -672,7 +628,7 @@ namespace client
|
|||
auto ts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||
htobe64buf (payload.data(), ts);
|
||||
// send our version back
|
||||
PutString (payload.data() + 8, payload.size() - 8, version);
|
||||
i2p::util::Mapping::WriteString (version, payload.data() + 8, payload.size() - 8);
|
||||
SendI2CPMessage (I2CP_SET_DATE_MESSAGE, payload.data(), payload.size());
|
||||
}
|
||||
|
||||
|
@ -702,7 +658,7 @@ namespace client
|
|||
return;
|
||||
}
|
||||
i2p::util::Mapping params;
|
||||
ExtractMapping (buf + offset, optionsSize, params);
|
||||
params.FromBuffer (optionsSize, buf + offset, len - offset);
|
||||
offset += optionsSize; // options
|
||||
if (params[I2CP_PARAM_MESSAGE_RELIABILITY] == "none") m_IsSendAccepted = false;
|
||||
|
||||
|
@ -768,7 +724,7 @@ namespace client
|
|||
{
|
||||
buf += sizeof(uint16_t);
|
||||
i2p::util::Mapping opts;
|
||||
ExtractMapping(buf, optssize, opts);
|
||||
opts.FromBuffer (optssize, buf, optssize);
|
||||
buf += optssize;
|
||||
//uint64_t date = bufbe64toh(buf);
|
||||
buf += sizeof(uint64_t);
|
||||
|
@ -980,7 +936,7 @@ namespace client
|
|||
break;
|
||||
case 1: // address
|
||||
{
|
||||
auto name = ExtractString (buf + 11, len - 11);
|
||||
auto name = i2p::util::Mapping::ExtractString (buf + 11, len - 11);
|
||||
auto addr = i2p::client::context.GetAddressBook ().GetAddress (name);
|
||||
if (!addr || !addr->IsIdentHash ())
|
||||
{
|
||||
|
|
|
@ -195,9 +195,6 @@ namespace client
|
|||
|
||||
void HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||
|
||||
std::string_view ExtractString (const uint8_t * buf, size_t len) const;
|
||||
size_t PutString (uint8_t * buf, size_t len, std::string_view str);
|
||||
void ExtractMapping (const uint8_t * buf, size_t len, i2p::util::Mapping& mapping) const;
|
||||
void SendSessionStatusMessage (I2CPSessionStatus status);
|
||||
void SendHostReplyMessage (uint32_t requestID, std::shared_ptr<const i2p::data::IdentityEx> identity);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue