mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-07 06:09:42 +00:00
Compare commits
15 Commits
2.55.0
...
8c555fe592
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c555fe592 | ||
|
|
5f1c599f81 | ||
|
|
f2b5606583 | ||
|
|
08a680b53d | ||
|
|
634ceceb1c | ||
|
|
efd8e6e65b | ||
|
|
915429bb49 | ||
|
|
3e3e0e0a62 | ||
|
|
c023051fe4 | ||
|
|
0b788de627 | ||
|
|
fce4fab071 | ||
|
|
3236de0d5a | ||
|
|
18707dd844 | ||
|
|
fc16a70f7b | ||
|
|
619ec5d9c1 |
2
.github/workflows/build-windows.yml
vendored
2
.github/workflows/build-windows.yml
vendored
@@ -133,6 +133,8 @@ jobs:
|
||||
git clone https://github.com/msys2/MINGW-packages
|
||||
cd MINGW-packages
|
||||
git checkout 4cbb366edf2f268ac3146174b40ce38604646fc5 mingw-w64-boost
|
||||
cd mingw-w64-boost
|
||||
sed -i 's/boostorg.jfrog.io\/artifactory\/main/archives.boost.io/' PKGBUILD
|
||||
|
||||
# headers
|
||||
- name: Get headers package version
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2022, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -152,11 +152,11 @@ namespace data
|
||||
m_BlindedSigType = m_SigType;
|
||||
}
|
||||
|
||||
BlindedPublicKey::BlindedPublicKey (const std::string& b33):
|
||||
BlindedPublicKey::BlindedPublicKey (std::string_view b33):
|
||||
m_SigType (0) // 0 means invalid, we can't blind DSA, set it later
|
||||
{
|
||||
uint8_t addr[40]; // TODO: define length from b33
|
||||
size_t l = i2p::data::Base32ToByteStream (b33.c_str (), b33.length (), addr, 40);
|
||||
size_t l = i2p::data::Base32ToByteStream (b33.data (), b33.length (), addr, 40);
|
||||
if (l < 32)
|
||||
{
|
||||
LogPrint (eLogError, "Blinding: Malformed b33 ", b33);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2020, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
#include "Identity.h"
|
||||
|
||||
@@ -23,7 +24,7 @@ namespace data
|
||||
public:
|
||||
|
||||
BlindedPublicKey (std::shared_ptr<const IdentityEx> identity, bool clientAuth = false);
|
||||
BlindedPublicKey (const std::string& b33); // from b33 without .b32.i2p
|
||||
BlindedPublicKey (std::string_view b33); // from b33 without .b32.i2p
|
||||
std::string ToB33 () const;
|
||||
|
||||
const uint8_t * GetPublicKey () const { return m_PublicKey.data (); };
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -154,6 +154,17 @@ namespace config {
|
||||
("socksproxy.i2p.streaming.profile", value<std::string>()->default_value("1"), "SOCKS Proxy bandwidth usage profile. 1 - bulk(high), 2- interactive(low)")
|
||||
;
|
||||
|
||||
options_description shareddest("Shared local destination options");
|
||||
shareddest.add_options()
|
||||
("shareddest.inbound.length", value<std::string>()->default_value("3"), "Shared local destination inbound tunnel length")
|
||||
("shareddest.outbound.length", value<std::string>()->default_value("3"), "Shared local destination outbound tunnel length")
|
||||
("shareddest.inbound.quantity", value<std::string>()->default_value("3"), "Shared local destination inbound tunnels quantity")
|
||||
("shareddest.outbound.quantity", value<std::string>()->default_value("3"), "Shared local destination outbound tunnels quantity")
|
||||
("shareddest.i2cp.leaseSetType", value<std::string>()->default_value("3"), "Shared local destination's LeaseSet type")
|
||||
("shareddest.i2cp.leaseSetEncType", value<std::string>()->default_value("0,4"), "Shared local destination's LeaseSet encryption type")
|
||||
("shareddest.i2p.streaming.profile", value<std::string>()->default_value("2"), "Shared local destination bandwidth usage profile. 1 - bulk(high), 2- interactive(low)")
|
||||
;
|
||||
|
||||
options_description sam("SAM bridge options");
|
||||
sam.add_options()
|
||||
("sam.enabled", value<bool>()->default_value(true), "Enable or disable SAM Application bridge")
|
||||
@@ -341,6 +352,7 @@ namespace config {
|
||||
.add(httpserver)
|
||||
.add(httpproxy)
|
||||
.add(socksproxy)
|
||||
.add(shareddest)
|
||||
.add(sam)
|
||||
.add(bob)
|
||||
.add(i2cp)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -104,8 +104,7 @@ namespace datagram
|
||||
|
||||
if (verified)
|
||||
{
|
||||
auto h = identity.GetIdentHash();
|
||||
auto session = ObtainSession(h);
|
||||
auto session = ObtainSession (identity.GetIdentHash());
|
||||
session->Ack();
|
||||
auto r = FindReceiver(toPort);
|
||||
if(r)
|
||||
@@ -381,15 +380,19 @@ namespace datagram
|
||||
if (!found)
|
||||
{
|
||||
m_RoutingSession = m_LocalDestination->GetRoutingSession(m_RemoteLeaseSet, true);
|
||||
if (!m_RoutingSession->GetOwner () || !m_RoutingSession->IsReadyToSend ())
|
||||
m_PendingRoutingSessions.push_back (m_RoutingSession);
|
||||
if (m_RoutingSession)
|
||||
{
|
||||
m_RoutingSession->SetAckRequestInterval (DATAGRAM_SESSION_ACK_REQUEST_INTERVAL);
|
||||
if (!m_RoutingSession->GetOwner () || !m_RoutingSession->IsReadyToSend ())
|
||||
m_PendingRoutingSessions.push_back (m_RoutingSession);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto path = m_RoutingSession->GetSharedRoutingPath();
|
||||
if (path && m_RoutingSession->IsRatchets () && (m_RoutingSession->CleanupUnconfirmedTags () ||
|
||||
m_LastUse > m_RoutingSession->GetLastActivityTimestamp ()*1000 + DATAGRAM_SESSION_PATH_TIMEOUT))
|
||||
if (path && m_RoutingSession->IsRatchets () && m_RoutingSession->CleanupUnconfirmedTags ())
|
||||
{
|
||||
LogPrint (eLogDebug, "Datagram: path reset");
|
||||
m_RoutingSession->SetSharedRoutingPath (nullptr);
|
||||
path = nullptr;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -31,8 +31,6 @@ namespace datagram
|
||||
{
|
||||
// milliseconds for max session idle time
|
||||
const uint64_t DATAGRAM_SESSION_MAX_IDLE = 10 * 60 * 1000;
|
||||
// milliseconds for how long we try sticking to a dead routing path before trying to switch
|
||||
const uint64_t DATAGRAM_SESSION_PATH_TIMEOUT = 10 * 1000;
|
||||
// milliseconds interval a routing path is used before switching
|
||||
const uint64_t DATAGRAM_SESSION_PATH_SWITCH_INTERVAL = 20 * 60 * 1000;
|
||||
// milliseconds before lease expire should we try switching leases
|
||||
@@ -44,6 +42,7 @@ namespace datagram
|
||||
// max 64 messages buffered in send queue for each datagram session
|
||||
const size_t DATAGRAM_SEND_QUEUE_MAX_SIZE = 64;
|
||||
const uint64_t DATAGRAM_MAX_FLUSH_INTERVAL = 5; // in milliseconds
|
||||
const int DATAGRAM_SESSION_ACK_REQUEST_INTERVAL = 5500; // in milliseconds
|
||||
|
||||
class DatagramSession : public std::enable_shared_from_this<DatagramSession>
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -597,7 +597,8 @@ namespace client
|
||||
m_ExcludedFloodfills.clear ();
|
||||
m_PublishReplyToken = 0;
|
||||
// schedule verification
|
||||
m_PublishVerificationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_VERIFICATION_TIMEOUT));
|
||||
m_PublishVerificationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_VERIFICATION_TIMEOUT +
|
||||
(m_Pool ? m_Pool->GetRng ()() % PUBLISH_VERIFICATION_TIMEOUT_VARIANCE : 0)));
|
||||
m_PublishVerificationTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishVerificationTimer,
|
||||
shared_from_this (), std::placeholders::_1));
|
||||
}
|
||||
@@ -676,8 +677,8 @@ namespace client
|
||||
m_ExcludedFloodfills.clear ();
|
||||
m_PublishReplyToken = 1; // dummy non-zero value
|
||||
// try again after a while
|
||||
LogPrint (eLogInfo, "Destination: Can't publish LeasetSet because destination is not ready. Try publishing again after ", PUBLISH_CONFIRMATION_TIMEOUT, " seconds");
|
||||
m_PublishConfirmationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_CONFIRMATION_TIMEOUT));
|
||||
LogPrint (eLogInfo, "Destination: Can't publish LeasetSet because destination is not ready. Try publishing again after ", PUBLISH_CONFIRMATION_TIMEOUT, " milliseconds");
|
||||
m_PublishConfirmationTimer.expires_from_now (boost::posix_time::milliseconds(PUBLISH_CONFIRMATION_TIMEOUT));
|
||||
m_PublishConfirmationTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishConfirmationTimer,
|
||||
shared_from_this (), std::placeholders::_1));
|
||||
return;
|
||||
@@ -696,7 +697,7 @@ namespace client
|
||||
s->HandlePublishConfirmationTimer (boost::system::error_code());
|
||||
});
|
||||
};
|
||||
m_PublishConfirmationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_CONFIRMATION_TIMEOUT));
|
||||
m_PublishConfirmationTimer.expires_from_now (boost::posix_time::milliseconds(PUBLISH_CONFIRMATION_TIMEOUT));
|
||||
m_PublishConfirmationTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishConfirmationTimer,
|
||||
shared_from_this (), std::placeholders::_1));
|
||||
outbound->SendTunnelDataMsgTo (floodfill->GetIdentHash (), 0, msg);
|
||||
@@ -712,15 +713,15 @@ namespace client
|
||||
m_PublishReplyToken = 0;
|
||||
if (GetIdentity ()->GetCryptoKeyType () == i2p::data::CRYPTO_KEY_TYPE_ELGAMAL)
|
||||
{
|
||||
LogPrint (eLogWarning, "Destination: Publish confirmation was not received in ", PUBLISH_CONFIRMATION_TIMEOUT, " seconds or failed. will try again");
|
||||
LogPrint (eLogWarning, "Destination: Publish confirmation was not received in ", PUBLISH_CONFIRMATION_TIMEOUT, " milliseconds or failed. will try again");
|
||||
Publish ();
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrint (eLogWarning, "Destination: Publish confirmation was not received in ", PUBLISH_CONFIRMATION_TIMEOUT, " seconds from Java floodfill for crypto type ", (int)GetIdentity ()->GetCryptoKeyType ());
|
||||
LogPrint (eLogWarning, "Destination: Publish confirmation was not received in ", PUBLISH_CONFIRMATION_TIMEOUT, " milliseconds from Java floodfill for crypto type ", (int)GetIdentity ()->GetCryptoKeyType ());
|
||||
// Java floodfill never sends confirmation back for unknown crypto type
|
||||
// assume it successive and try to verify
|
||||
m_PublishVerificationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_VERIFICATION_TIMEOUT));
|
||||
m_PublishVerificationTimer.expires_from_now (boost::posix_time::seconds(PUBLISH_VERIFICATION_TIMEOUT + PUBLISH_VERIFICATION_TIMEOUT_VARIANCE)); // always max
|
||||
m_PublishVerificationTimer.async_wait (std::bind (&LeaseSetDestination::HandlePublishVerificationTimer,
|
||||
shared_from_this (), std::placeholders::_1));
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -36,8 +36,9 @@ namespace client
|
||||
const uint8_t PROTOCOL_TYPE_STREAMING = 6;
|
||||
const uint8_t PROTOCOL_TYPE_DATAGRAM = 17;
|
||||
const uint8_t PROTOCOL_TYPE_RAW = 18;
|
||||
const int PUBLISH_CONFIRMATION_TIMEOUT = 5; // in seconds
|
||||
const int PUBLISH_VERIFICATION_TIMEOUT = 10; // in seconds after successful publish
|
||||
const int PUBLISH_CONFIRMATION_TIMEOUT = 1800; // in milliseconds
|
||||
const int PUBLISH_VERIFICATION_TIMEOUT = 5; // in seconds after successful publish
|
||||
const int PUBLISH_VERIFICATION_TIMEOUT_VARIANCE = 3; // in seconds
|
||||
const int PUBLISH_MIN_INTERVAL = 20; // in seconds
|
||||
const int PUBLISH_REGULAR_VERIFICATION_INTERNAL = 100; // in seconds periodically
|
||||
const int LEASESET_REQUEST_TIMEOUT = 1600; // in milliseconds
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -913,7 +913,7 @@ namespace garlic
|
||||
}
|
||||
}
|
||||
if (!sendAckRequest && !first &&
|
||||
((!m_AckRequestMsgID && ts > m_LastAckRequestSendTime + ECIESX25519_ACK_REQUEST_INTERVAL) || // regular request
|
||||
((!m_AckRequestMsgID && ts > m_LastAckRequestSendTime + m_AckRequestInterval) || // regular request
|
||||
(m_AckRequestMsgID && ts > m_LastAckRequestSendTime + LEASESET_CONFIRMATION_TIMEOUT))) // previous request failed. try again
|
||||
{
|
||||
// not LeaseSet
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -33,7 +33,7 @@ namespace garlic
|
||||
const int ECIESX25519_SESSION_CREATE_TIMEOUT = 3; // in seconds, NSR must be send after NS received
|
||||
const int ECIESX25519_SESSION_ESTABLISH_TIMEOUT = 15; // in seconds
|
||||
const int ECIESX25519_PREVIOUS_TAGSET_EXPIRATION_TIMEOUT = 180; // in seconds
|
||||
const int ECIESX25519_ACK_REQUEST_INTERVAL = 33000; // in milliseconds
|
||||
const int ECIESX25519_DEFAULT_ACK_REQUEST_INTERVAL = 33000; // in milliseconds
|
||||
const int ECIESX25519_ACK_REQUEST_MAX_NUM_ATTEMPTS = 3;
|
||||
const int ECIESX25519_TAGSET_MAX_NUM_TAGS = 8192; // number of tags we request new tagset after
|
||||
const int ECIESX25519_MIN_NUM_GENERATED_TAGS = 24;
|
||||
@@ -164,7 +164,7 @@ namespace garlic
|
||||
~ECIESX25519AEADRatchetSession ();
|
||||
|
||||
bool HandleNextMessage (uint8_t * buf, size_t len, std::shared_ptr<ReceiveRatchetTagSet> receiveTagset, int index = 0);
|
||||
std::shared_ptr<I2NPMessage> WrapSingleMessage (std::shared_ptr<const I2NPMessage> msg);
|
||||
std::shared_ptr<I2NPMessage> WrapSingleMessage (std::shared_ptr<const I2NPMessage> msg) override;
|
||||
std::shared_ptr<I2NPMessage> WrapOneTimeMessage (std::shared_ptr<const I2NPMessage> msg);
|
||||
|
||||
const uint8_t * GetRemoteStaticKey () const { return m_RemoteStaticKey; }
|
||||
@@ -180,11 +180,12 @@ namespace garlic
|
||||
bool CanBeRestarted (uint64_t ts) const { return ts > m_SessionCreatedTimestamp + ECIESX25519_RESTART_TIMEOUT; }
|
||||
bool IsInactive (uint64_t ts) const { return ts > m_LastActivityTimestamp + ECIESX25519_INACTIVITY_TIMEOUT && CanBeRestarted (ts); }
|
||||
|
||||
bool IsRatchets () const { return true; };
|
||||
bool IsReadyToSend () const { return m_State != eSessionStateNewSessionSent; };
|
||||
bool IsTerminated () const { return m_IsTerminated; }
|
||||
uint64_t GetLastActivityTimestamp () const { return m_LastActivityTimestamp; };
|
||||
bool CleanupUnconfirmedTags (); // return true if unaswered Ack requests, called from I2CP
|
||||
bool IsRatchets () const override { return true; };
|
||||
bool IsReadyToSend () const override { return m_State != eSessionStateNewSessionSent; };
|
||||
bool IsTerminated () const override { return m_IsTerminated; }
|
||||
uint64_t GetLastActivityTimestamp () const override { return m_LastActivityTimestamp; };
|
||||
void SetAckRequestInterval (int interval) override { m_AckRequestInterval = interval; };
|
||||
bool CleanupUnconfirmedTags () override; // return true if unaswered Ack requests, called from I2CP
|
||||
|
||||
protected:
|
||||
|
||||
@@ -192,7 +193,7 @@ namespace garlic
|
||||
void SetNoiseState (const i2p::crypto::NoiseSymmetricState& state) { GetNoiseState () = state; };
|
||||
void CreateNonce (uint64_t seqn, uint8_t * nonce);
|
||||
void HandlePayload (const uint8_t * buf, size_t len, const std::shared_ptr<ReceiveRatchetTagSet>& receiveTagset, int index);
|
||||
bool MessageConfirmed (uint32_t msgID);
|
||||
bool MessageConfirmed (uint32_t msgID) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -235,6 +236,7 @@ namespace garlic
|
||||
uint64_t m_LastAckRequestSendTime = 0; // milliseconds
|
||||
uint32_t m_AckRequestMsgID = 0;
|
||||
int m_AckRequestNumAttempts = 0;
|
||||
int m_AckRequestInterval = ECIESX25519_DEFAULT_ACK_REQUEST_INTERVAL; // milliseconds
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -116,7 +116,8 @@ namespace garlic
|
||||
virtual bool IsReadyToSend () const { return true; };
|
||||
virtual bool IsTerminated () const { return !GetOwner (); };
|
||||
virtual uint64_t GetLastActivityTimestamp () const { return 0; }; // non-zero for rathets only
|
||||
|
||||
virtual void SetAckRequestInterval (int interval) {}; // in milliseconds, override in ECIESX25519AEADRatchetSession
|
||||
|
||||
void SetLeaseSetUpdated ()
|
||||
{
|
||||
if (m_LeaseSetUpdateStatus != eLeaseSetDoNotSend) m_LeaseSetUpdateStatus = eLeaseSetUpdated;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -262,11 +262,11 @@ namespace data
|
||||
return fullLen;
|
||||
}
|
||||
|
||||
size_t IdentityEx::FromBase64(const std::string& s)
|
||||
size_t IdentityEx::FromBase64(std::string_view s)
|
||||
{
|
||||
const size_t slen = s.length();
|
||||
std::vector<uint8_t> buf(slen); // binary data can't exceed base64
|
||||
const size_t len = Base64ToByteStream (s.c_str(), slen, buf.data(), slen);
|
||||
const size_t len = Base64ToByteStream (s.data(), slen, buf.data(), slen);
|
||||
return FromBuffer (buf.data(), len);
|
||||
}
|
||||
|
||||
@@ -728,9 +728,7 @@ namespace data
|
||||
case SIGNING_KEY_TYPE_RSA_SHA384_3072:
|
||||
case SIGNING_KEY_TYPE_RSA_SHA512_4096:
|
||||
LogPrint (eLogWarning, "Identity: RSA signature type is not supported. Creating EdDSA");
|
||||
#if (__cplusplus >= 201703L) // C++ 17 or higher
|
||||
[[fallthrough]];
|
||||
#endif
|
||||
// no break here
|
||||
case SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519:
|
||||
i2p::crypto::CreateEDDSA25519RandomKeys (priv, pub);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -12,6 +12,7 @@
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include "Base.h"
|
||||
@@ -99,7 +100,7 @@ namespace data
|
||||
|
||||
size_t FromBuffer (const uint8_t * buf, size_t len);
|
||||
size_t ToBuffer (uint8_t * buf, size_t len) const;
|
||||
size_t FromBase64(const std::string& s);
|
||||
size_t FromBase64(std::string_view s);
|
||||
std::string ToBase64 () const;
|
||||
const Identity& GetStandardIdentity () const { return m_StandardIdentity; };
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -1434,7 +1434,7 @@ namespace i2p
|
||||
i2p::garlic::WrapECIESX25519MessageForRouter (msg, floodfill->GetIdentity ()->GetEncryptionPublicKey ()));
|
||||
}
|
||||
else
|
||||
LogPrint (eLogInfo, "Router: Can't publish our RouterInfo. No tunnles. Try again in ", ROUTER_INFO_CONFIRMATION_TIMEOUT, " seconds");
|
||||
LogPrint (eLogInfo, "Router: Can't publish our RouterInfo. No tunnels. Try again in ", ROUTER_INFO_CONFIRMATION_TIMEOUT, " milliseconds");
|
||||
}
|
||||
m_PublishExcluded.insert (floodfill->GetIdentHash ());
|
||||
m_PublishReplyToken = replyToken;
|
||||
@@ -1448,7 +1448,7 @@ namespace i2p
|
||||
if (m_PublishTimer)
|
||||
{
|
||||
m_PublishTimer->cancel ();
|
||||
m_PublishTimer->expires_from_now (boost::posix_time::seconds(ROUTER_INFO_CONFIRMATION_TIMEOUT));
|
||||
m_PublishTimer->expires_from_now (boost::posix_time::milliseconds(ROUTER_INFO_CONFIRMATION_TIMEOUT));
|
||||
m_PublishTimer->async_wait (std::bind (&RouterContext::HandlePublishResendTimer,
|
||||
this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -34,7 +34,7 @@ namespace garlic
|
||||
const int ROUTER_INFO_PUBLISH_INTERVAL = 39*60; // in seconds
|
||||
const int ROUTER_INFO_INITIAL_PUBLISH_INTERVAL = 10; // in seconds
|
||||
const int ROUTER_INFO_PUBLISH_INTERVAL_VARIANCE = 105;// in seconds
|
||||
const int ROUTER_INFO_CONFIRMATION_TIMEOUT = 5; // in seconds
|
||||
const int ROUTER_INFO_CONFIRMATION_TIMEOUT = 1600; // in milliseconds
|
||||
const int ROUTER_INFO_MAX_PUBLISH_EXCLUDED_FLOODFILLS = 15;
|
||||
const int ROUTER_INFO_CONGESTION_UPDATE_INTERVAL = 12*60; // in seconds
|
||||
const int ROUTER_INFO_CLEANUP_INTERVAL = 102; // in seconds
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2022-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -92,7 +92,7 @@ namespace transport
|
||||
m_RTO (SSU2_INITIAL_RTO), m_RelayTag (0),m_ConnectTimer (server.GetService ()),
|
||||
m_TerminationReason (eSSU2TerminationReasonNormalClose),
|
||||
m_MaxPayloadSize (SSU2_MIN_PACKET_SIZE - IPV6_HEADER_SIZE - UDP_HEADER_SIZE - 32), // min size
|
||||
m_LastResendTime (0), m_LastResendAttemptTime (0)
|
||||
m_LastResendTime (0), m_LastResendAttemptTime (0), m_NumRanges (0)
|
||||
{
|
||||
if (noise)
|
||||
m_NoiseState.reset (new i2p::crypto::NoiseSymmetricState);
|
||||
@@ -1744,6 +1744,7 @@ namespace transport
|
||||
HandleAckRange (firstPacketNum, ackThrough, i2p::util::GetMillisecondsSinceEpoch ()); // acnt
|
||||
// ranges
|
||||
len -= 5;
|
||||
if (!len || m_SentPackets.empty ()) return; // don't handle ranges if nothing to acknowledge
|
||||
const uint8_t * ranges = buf + 5;
|
||||
while (len > 0 && firstPacketNum && ackThrough - firstPacketNum < SSU2_MAX_NUM_ACK_PACKETS)
|
||||
{
|
||||
@@ -2624,17 +2625,17 @@ namespace transport
|
||||
size_t SSU2Session::CreateAckBlock (uint8_t * buf, size_t len)
|
||||
{
|
||||
if (len < 8) return 0;
|
||||
int maxNumRanges = (len - 8) >> 1;
|
||||
if (maxNumRanges > SSU2_MAX_NUM_ACK_RANGES) maxNumRanges = SSU2_MAX_NUM_ACK_RANGES;
|
||||
buf[0] = eSSU2BlkAck;
|
||||
uint32_t ackThrough = m_OutOfSequencePackets.empty () ? m_ReceivePacketNum : *m_OutOfSequencePackets.rbegin ();
|
||||
htobe32buf (buf + 3, ackThrough); // Ack Through
|
||||
uint16_t acnt = 0;
|
||||
int numRanges = 0;
|
||||
if (ackThrough)
|
||||
{
|
||||
if (m_OutOfSequencePackets.empty ())
|
||||
{
|
||||
acnt = std::min ((int)ackThrough, SSU2_MAX_NUM_ACNT); // no gaps
|
||||
m_NumRanges = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
auto it = m_OutOfSequencePackets.rbegin (); it++; // prev packet num
|
||||
@@ -2647,87 +2648,96 @@ namespace transport
|
||||
it++;
|
||||
}
|
||||
// ranges
|
||||
uint32_t lastNum = ackThrough - acnt;
|
||||
if (acnt > SSU2_MAX_NUM_ACNT)
|
||||
{
|
||||
auto d = std::div (acnt - SSU2_MAX_NUM_ACNT, SSU2_MAX_NUM_ACNT);
|
||||
acnt = SSU2_MAX_NUM_ACNT;
|
||||
if (d.quot > maxNumRanges)
|
||||
if (!m_NumRanges)
|
||||
{
|
||||
int maxNumRanges = (len - 8) >> 1;
|
||||
if (maxNumRanges > SSU2_MAX_NUM_ACK_RANGES) maxNumRanges = SSU2_MAX_NUM_ACK_RANGES;
|
||||
int numRanges = 0;
|
||||
uint32_t lastNum = ackThrough - acnt;
|
||||
if (acnt > SSU2_MAX_NUM_ACNT)
|
||||
{
|
||||
d.quot = maxNumRanges;
|
||||
d.rem = 0;
|
||||
}
|
||||
// Acks only ranges for acnt
|
||||
for (int i = 0; i < d.quot; i++)
|
||||
{
|
||||
buf[8 + numRanges*2] = 0; buf[8 + numRanges*2 + 1] = SSU2_MAX_NUM_ACNT; // NACKs 0, Acks 255
|
||||
numRanges++;
|
||||
}
|
||||
if (d.rem > 0)
|
||||
{
|
||||
buf[8 + numRanges*2] = 0; buf[8 + numRanges*2 + 1] = d.rem;
|
||||
numRanges++;
|
||||
}
|
||||
}
|
||||
int numPackets = acnt + numRanges*SSU2_MAX_NUM_ACNT;
|
||||
while (it != m_OutOfSequencePackets.rend () &&
|
||||
numRanges < maxNumRanges && numPackets < SSU2_MAX_NUM_ACK_PACKETS)
|
||||
{
|
||||
if (lastNum - (*it) > SSU2_MAX_NUM_ACNT)
|
||||
{
|
||||
// NACKs only ranges
|
||||
if (lastNum > (*it) + SSU2_MAX_NUM_ACNT*(maxNumRanges - numRanges)) break; // too many NACKs
|
||||
while (lastNum - (*it) > SSU2_MAX_NUM_ACNT)
|
||||
auto d = std::div (acnt - SSU2_MAX_NUM_ACNT, SSU2_MAX_NUM_ACNT);
|
||||
acnt = SSU2_MAX_NUM_ACNT;
|
||||
if (d.quot > maxNumRanges)
|
||||
{
|
||||
buf[8 + numRanges*2] = SSU2_MAX_NUM_ACNT; buf[8 + numRanges*2 + 1] = 0; // NACKs 255, Acks 0
|
||||
lastNum -= SSU2_MAX_NUM_ACNT;
|
||||
d.quot = maxNumRanges;
|
||||
d.rem = 0;
|
||||
}
|
||||
// Acks only ranges for acnt
|
||||
for (int i = 0; i < d.quot; i++)
|
||||
{
|
||||
m_Ranges[numRanges*2] = 0; m_Ranges[numRanges*2 + 1] = SSU2_MAX_NUM_ACNT; // NACKs 0, Acks 255
|
||||
numRanges++;
|
||||
}
|
||||
if (d.rem > 0)
|
||||
{
|
||||
m_Ranges[numRanges*2] = 0; m_Ranges[numRanges*2 + 1] = d.rem;
|
||||
numRanges++;
|
||||
numPackets += SSU2_MAX_NUM_ACNT;
|
||||
}
|
||||
}
|
||||
// NACKs and Acks ranges
|
||||
buf[8 + numRanges*2] = lastNum - (*it) - 1; // NACKs
|
||||
numPackets += buf[8 + numRanges*2];
|
||||
lastNum = *it; it++;
|
||||
int numAcks = 1;
|
||||
while (it != m_OutOfSequencePackets.rend () && lastNum > 0 && *it == lastNum - 1)
|
||||
int numPackets = acnt + numRanges*SSU2_MAX_NUM_ACNT;
|
||||
while (it != m_OutOfSequencePackets.rend () &&
|
||||
numRanges < maxNumRanges && numPackets < SSU2_MAX_NUM_ACK_PACKETS)
|
||||
{
|
||||
numAcks++; lastNum--;
|
||||
it++;
|
||||
}
|
||||
while (numAcks > SSU2_MAX_NUM_ACNT)
|
||||
{
|
||||
// Acks only ranges
|
||||
buf[8 + numRanges*2 + 1] = SSU2_MAX_NUM_ACNT; // Acks 255
|
||||
numAcks -= SSU2_MAX_NUM_ACNT;
|
||||
numRanges++;
|
||||
numPackets += SSU2_MAX_NUM_ACNT;
|
||||
buf[8 + numRanges*2] = 0; // NACKs 0
|
||||
if (numRanges >= maxNumRanges || numPackets >= SSU2_MAX_NUM_ACK_PACKETS) break;
|
||||
}
|
||||
if (numAcks > SSU2_MAX_NUM_ACNT) numAcks = SSU2_MAX_NUM_ACNT;
|
||||
buf[8 + numRanges*2 + 1] = (uint8_t)numAcks; // Acks
|
||||
numPackets += numAcks;
|
||||
numRanges++;
|
||||
}
|
||||
if (it == m_OutOfSequencePackets.rend () &&
|
||||
numRanges < maxNumRanges && numPackets < SSU2_MAX_NUM_ACK_PACKETS)
|
||||
{
|
||||
// add range between out-of-sequence and received
|
||||
int nacks = *m_OutOfSequencePackets.begin () - m_ReceivePacketNum - 1;
|
||||
if (nacks > 0)
|
||||
{
|
||||
if (nacks > SSU2_MAX_NUM_ACNT) nacks = SSU2_MAX_NUM_ACNT;
|
||||
buf[8 + numRanges*2] = nacks;
|
||||
buf[8 + numRanges*2 + 1] = std::min ((int)m_ReceivePacketNum + 1, SSU2_MAX_NUM_ACNT);
|
||||
if (lastNum - (*it) > SSU2_MAX_NUM_ACNT)
|
||||
{
|
||||
// NACKs only ranges
|
||||
if (lastNum > (*it) + SSU2_MAX_NUM_ACNT*(maxNumRanges - numRanges)) break; // too many NACKs
|
||||
while (lastNum - (*it) > SSU2_MAX_NUM_ACNT)
|
||||
{
|
||||
m_Ranges[numRanges*2] = SSU2_MAX_NUM_ACNT; m_Ranges[numRanges*2 + 1] = 0; // NACKs 255, Acks 0
|
||||
lastNum -= SSU2_MAX_NUM_ACNT;
|
||||
numRanges++;
|
||||
numPackets += SSU2_MAX_NUM_ACNT;
|
||||
}
|
||||
}
|
||||
// NACKs and Acks ranges
|
||||
m_Ranges[numRanges*2] = lastNum - (*it) - 1; // NACKs
|
||||
numPackets += m_Ranges[numRanges*2];
|
||||
lastNum = *it; it++;
|
||||
int numAcks = 1;
|
||||
while (it != m_OutOfSequencePackets.rend () && lastNum > 0 && *it == lastNum - 1)
|
||||
{
|
||||
numAcks++; lastNum--;
|
||||
it++;
|
||||
}
|
||||
while (numAcks > SSU2_MAX_NUM_ACNT)
|
||||
{
|
||||
// Acks only ranges
|
||||
m_Ranges[numRanges*2 + 1] = SSU2_MAX_NUM_ACNT; // Acks 255
|
||||
numAcks -= SSU2_MAX_NUM_ACNT;
|
||||
numRanges++;
|
||||
numPackets += SSU2_MAX_NUM_ACNT;
|
||||
m_Ranges[numRanges*2] = 0; // NACKs 0
|
||||
if (numRanges >= maxNumRanges || numPackets >= SSU2_MAX_NUM_ACK_PACKETS) break;
|
||||
}
|
||||
if (numAcks > SSU2_MAX_NUM_ACNT) numAcks = SSU2_MAX_NUM_ACNT;
|
||||
m_Ranges[numRanges*2 + 1] = (uint8_t)numAcks; // Acks
|
||||
numPackets += numAcks;
|
||||
numRanges++;
|
||||
}
|
||||
}
|
||||
if (it == m_OutOfSequencePackets.rend () &&
|
||||
numRanges < maxNumRanges && numPackets < SSU2_MAX_NUM_ACK_PACKETS)
|
||||
{
|
||||
// add range between out-of-sequence and received
|
||||
int nacks = *m_OutOfSequencePackets.begin () - m_ReceivePacketNum - 1;
|
||||
if (nacks > 0)
|
||||
{
|
||||
if (nacks > SSU2_MAX_NUM_ACNT) nacks = SSU2_MAX_NUM_ACNT;
|
||||
m_Ranges[numRanges*2] = nacks;
|
||||
m_Ranges[numRanges*2 + 1] = std::min ((int)m_ReceivePacketNum + 1, SSU2_MAX_NUM_ACNT);
|
||||
numRanges++;
|
||||
}
|
||||
}
|
||||
m_NumRanges = numRanges;
|
||||
}
|
||||
if (m_NumRanges)
|
||||
memcpy (buf + 8, m_Ranges, m_NumRanges*2);
|
||||
}
|
||||
}
|
||||
buf[7] = (uint8_t)acnt; // acnt
|
||||
htobe16buf (buf + 1, 5 + numRanges*2);
|
||||
return 8 + numRanges*2;
|
||||
htobe16buf (buf + 1, 5 + m_NumRanges*2);
|
||||
return 8 + m_NumRanges*2;
|
||||
}
|
||||
|
||||
size_t SSU2Session::CreatePaddingBlock (uint8_t * buf, size_t len, size_t minSize)
|
||||
@@ -2961,11 +2971,17 @@ namespace transport
|
||||
}
|
||||
m_OutOfSequencePackets.erase (m_OutOfSequencePackets.begin (), it);
|
||||
}
|
||||
m_NumRanges = 0; // recalculate ranges when create next Ack
|
||||
}
|
||||
m_ReceivePacketNum = packetNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (m_NumRanges && (m_OutOfSequencePackets.empty () ||
|
||||
packetNum != (*m_OutOfSequencePackets.rbegin ()) + 1))
|
||||
m_NumRanges = 0; // reset ranges if received packet is not next
|
||||
m_OutOfSequencePackets.insert (packetNum);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2022-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2022-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -397,6 +397,8 @@ namespace transport
|
||||
std::unique_ptr<i2p::data::IdentHash> m_PathChallenge;
|
||||
std::unordered_map<uint32_t, uint32_t> m_ReceivedI2NPMsgIDs; // msgID -> timestamp in seconds
|
||||
uint64_t m_LastResendTime, m_LastResendAttemptTime; // in milliseconds
|
||||
int m_NumRanges;
|
||||
uint8_t m_Ranges[SSU2_MAX_NUM_ACK_RANGES*2]; // ranges sent with previous Ack if any
|
||||
};
|
||||
|
||||
inline uint64_t CreateHeaderMask (const uint8_t * kh, const uint8_t * nonce)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2023, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -12,10 +12,14 @@
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <string.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include "Base.h"
|
||||
|
||||
namespace i2p {
|
||||
namespace data {
|
||||
namespace i2p
|
||||
{
|
||||
namespace data
|
||||
{
|
||||
template<size_t sz>
|
||||
class Tag
|
||||
{
|
||||
@@ -70,14 +74,14 @@ namespace data {
|
||||
return std::string (str, str + l);
|
||||
}
|
||||
|
||||
size_t FromBase32 (const std::string& s)
|
||||
size_t FromBase32 (std::string_view s)
|
||||
{
|
||||
return i2p::data::Base32ToByteStream (s.c_str (), s.length (), m_Buf, sz);
|
||||
return i2p::data::Base32ToByteStream (s.data (), s.length (), m_Buf, sz);
|
||||
}
|
||||
|
||||
size_t FromBase64 (const std::string& s)
|
||||
size_t FromBase64 (std::string_view s)
|
||||
{
|
||||
return i2p::data::Base64ToByteStream (s.c_str (), s.length (), m_Buf, sz);
|
||||
return i2p::data::Base64ToByteStream (s.data (), s.length (), m_Buf, sz);
|
||||
}
|
||||
|
||||
uint8_t GetBit (int i) const
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -258,9 +258,8 @@ namespace tunnel
|
||||
void TunnelEndpoint::AddOutOfSequenceFragment (uint32_t msgID, uint8_t fragmentNum,
|
||||
bool isLastFragment, const uint8_t * fragment, size_t size)
|
||||
{
|
||||
std::unique_ptr<Fragment> f(new Fragment (isLastFragment, i2p::util::GetMillisecondsSinceEpoch (), size));
|
||||
memcpy (f->data.data (), fragment, size);
|
||||
if (!m_OutOfSequenceFragments.emplace ((uint64_t)msgID << 32 | fragmentNum, std::move (f)).second)
|
||||
if (!m_OutOfSequenceFragments.try_emplace ((uint64_t)msgID << 32 | fragmentNum,
|
||||
isLastFragment, i2p::util::GetMillisecondsSinceEpoch (), fragment, size).second)
|
||||
LogPrint (eLogInfo, "TunnelMessage: Duplicate out-of-sequence fragment ", fragmentNum, " of message ", msgID);
|
||||
}
|
||||
|
||||
@@ -290,7 +289,7 @@ namespace tunnel
|
||||
if (it != m_OutOfSequenceFragments.end ())
|
||||
{
|
||||
LogPrint (eLogDebug, "TunnelMessage: Out-of-sequence fragment ", (int)msg.nextFragmentNum, " of message ", msgID, " found");
|
||||
size_t size = it->second->data.size ();
|
||||
size_t size = it->second.data.size ();
|
||||
if (msg.data->len + size > msg.data->maxLen)
|
||||
{
|
||||
LogPrint (eLogWarning, "TunnelMessage: Tunnel endpoint I2NP message size ", msg.data->maxLen, " is not enough");
|
||||
@@ -298,9 +297,9 @@ namespace tunnel
|
||||
*newMsg = *(msg.data);
|
||||
msg.data = newMsg;
|
||||
}
|
||||
if (msg.data->Concat (it->second->data.data (), size) < size) // concatenate out-of-sync fragment
|
||||
if (msg.data->Concat (it->second.data.data (), size) < size) // concatenate out-of-sync fragment
|
||||
LogPrint (eLogError, "TunnelMessage: Tunnel endpoint I2NP buffer overflow ", msg.data->maxLen);
|
||||
if (it->second->isLastFragment)
|
||||
if (it->second.isLastFragment)
|
||||
// message complete
|
||||
msg.nextFragmentNum = 0;
|
||||
else
|
||||
@@ -349,7 +348,7 @@ namespace tunnel
|
||||
// out-of-sequence fragments
|
||||
for (auto it = m_OutOfSequenceFragments.begin (); it != m_OutOfSequenceFragments.end ();)
|
||||
{
|
||||
if (ts > it->second->receiveTime + i2p::I2NP_MESSAGE_EXPIRATION_TIMEOUT)
|
||||
if (ts > it->second.receiveTime + i2p::I2NP_MESSAGE_EXPIRATION_TIMEOUT)
|
||||
it = m_OutOfSequenceFragments.erase (it);
|
||||
else
|
||||
++it;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -32,7 +32,8 @@ namespace tunnel
|
||||
|
||||
struct Fragment
|
||||
{
|
||||
Fragment (bool last, uint64_t t, size_t size): isLastFragment (last), receiveTime (t), data (size) {};
|
||||
Fragment (bool last, uint64_t t, const uint8_t * buf, size_t size):
|
||||
isLastFragment (last), receiveTime (t), data (size) { memcpy (data.data(), buf, size); };
|
||||
bool isLastFragment;
|
||||
uint64_t receiveTime; // milliseconds since epoch
|
||||
std::vector<uint8_t> data;
|
||||
@@ -67,7 +68,7 @@ namespace tunnel
|
||||
private:
|
||||
|
||||
std::unordered_map<uint32_t, TunnelMessageBlockEx> m_IncompleteMessages;
|
||||
std::unordered_map<uint64_t, std::unique_ptr<Fragment> > m_OutOfSequenceFragments; // ((msgID << 8) + fragment#)->fragment
|
||||
std::unordered_map<uint64_t, Fragment> m_OutOfSequenceFragments; // ((msgID << 8) + fragment#)->fragment
|
||||
bool m_IsInbound;
|
||||
size_t m_NumReceivedBytes;
|
||||
TunnelMessageBlockEx m_CurrentMessage;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -49,22 +49,22 @@ namespace client
|
||||
if (m_IsPersist)
|
||||
i2p::config::GetOption("addressbook.hostsfile", m_HostsFile);
|
||||
}
|
||||
std::shared_ptr<const i2p::data::IdentityEx> GetAddress (const i2p::data::IdentHash& ident) const;
|
||||
void AddAddress (std::shared_ptr<const i2p::data::IdentityEx> address);
|
||||
void RemoveAddress (const i2p::data::IdentHash& ident);
|
||||
std::shared_ptr<const i2p::data::IdentityEx> GetAddress (const i2p::data::IdentHash& ident) const override;
|
||||
void AddAddress (std::shared_ptr<const i2p::data::IdentityEx> address) override;
|
||||
void RemoveAddress (const i2p::data::IdentHash& ident) override;
|
||||
|
||||
bool Init ();
|
||||
int Load (std::map<std::string, std::shared_ptr<Address> > & addresses);
|
||||
int LoadLocal (std::map<std::string, std::shared_ptr<Address> >& addresses);
|
||||
int Save (const std::map<std::string, std::shared_ptr<Address> >& addresses);
|
||||
bool Init () override;
|
||||
int Load (Addresses& addresses) override;
|
||||
int LoadLocal (Addresses& addresses) override;
|
||||
int Save (const Addresses& addresses) override;
|
||||
|
||||
void SaveEtag (const i2p::data::IdentHash& subsciption, const std::string& etag, const std::string& lastModified);
|
||||
bool GetEtag (const i2p::data::IdentHash& subscription, std::string& etag, std::string& lastModified);
|
||||
void ResetEtags ();
|
||||
void SaveEtag (const i2p::data::IdentHash& subsciption, const std::string& etag, const std::string& lastModified) override;
|
||||
bool GetEtag (const i2p::data::IdentHash& subscription, std::string& etag, std::string& lastModified) override;
|
||||
void ResetEtags () override;
|
||||
|
||||
private:
|
||||
|
||||
int LoadFromFile (const std::string& filename, std::map<std::string, std::shared_ptr<Address> >& addresses); // returns -1 if can't open file, otherwise number of records
|
||||
int LoadFromFile (const std::string& filename, Addresses& addresses); // returns -1 if can't open file, otherwise number of records
|
||||
|
||||
private:
|
||||
|
||||
@@ -142,7 +142,7 @@ namespace client
|
||||
storage.Remove( ident.ToBase32() );
|
||||
}
|
||||
|
||||
int AddressBookFilesystemStorage::LoadFromFile (const std::string& filename, std::map<std::string, std::shared_ptr<Address> >& addresses)
|
||||
int AddressBookFilesystemStorage::LoadFromFile (const std::string& filename, Addresses& addresses)
|
||||
{
|
||||
int num = 0;
|
||||
std::ifstream f (filename, std::ifstream::in); // in text mode
|
||||
@@ -168,7 +168,7 @@ namespace client
|
||||
return num;
|
||||
}
|
||||
|
||||
int AddressBookFilesystemStorage::Load (std::map<std::string, std::shared_ptr<Address> >& addresses)
|
||||
int AddressBookFilesystemStorage::Load (Addresses& addresses)
|
||||
{
|
||||
int num = LoadFromFile (indexPath, addresses);
|
||||
if (num < 0)
|
||||
@@ -182,7 +182,7 @@ namespace client
|
||||
return num;
|
||||
}
|
||||
|
||||
int AddressBookFilesystemStorage::LoadLocal (std::map<std::string, std::shared_ptr<Address> >& addresses)
|
||||
int AddressBookFilesystemStorage::LoadLocal (Addresses& addresses)
|
||||
{
|
||||
int num = LoadFromFile (localPath, addresses);
|
||||
if (num < 0) return 0;
|
||||
@@ -190,7 +190,7 @@ namespace client
|
||||
return num;
|
||||
}
|
||||
|
||||
int AddressBookFilesystemStorage::Save (const std::map<std::string, std::shared_ptr<Address> >& addresses)
|
||||
int AddressBookFilesystemStorage::Save (const Addresses& addresses)
|
||||
{
|
||||
if (addresses.empty())
|
||||
{
|
||||
@@ -283,7 +283,7 @@ namespace client
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
|
||||
Address::Address (const std::string& b32):
|
||||
Address::Address (std::string_view b32):
|
||||
addressType (eAddressInvalid)
|
||||
{
|
||||
if (b32.length () <= B33_ADDRESS_THRESHOLD)
|
||||
@@ -377,7 +377,7 @@ namespace client
|
||||
m_Subscriptions.clear ();
|
||||
}
|
||||
|
||||
std::shared_ptr<const Address> AddressBook::GetAddress (const std::string& address)
|
||||
std::shared_ptr<const Address> AddressBook::GetAddress (std::string_view address)
|
||||
{
|
||||
auto pos = address.find(".b32.i2p");
|
||||
if (pos != std::string::npos)
|
||||
@@ -404,7 +404,7 @@ namespace client
|
||||
return std::make_shared<const Address>(dest.GetIdentHash ());
|
||||
}
|
||||
|
||||
std::shared_ptr<const Address> AddressBook::FindAddress (const std::string& address)
|
||||
std::shared_ptr<const Address> AddressBook::FindAddress (std::string_view address)
|
||||
{
|
||||
auto it = m_Addresses.find (address);
|
||||
if (it != m_Addresses.end ())
|
||||
@@ -609,7 +609,7 @@ namespace client
|
||||
void AddressBook::LoadLocal ()
|
||||
{
|
||||
if (!m_Storage) return;
|
||||
std::map<std::string, std::shared_ptr<Address>> localAddresses;
|
||||
AddressBookStorage::Addresses localAddresses;
|
||||
m_Storage->LoadLocal (localAddresses);
|
||||
for (const auto& it: localAddresses)
|
||||
{
|
||||
@@ -766,7 +766,7 @@ namespace client
|
||||
}
|
||||
}
|
||||
|
||||
void AddressBook::LookupAddress (const std::string& address)
|
||||
void AddressBook::LookupAddress (std::string_view address)
|
||||
{
|
||||
std::shared_ptr<const Address> addr;
|
||||
auto dot = address.find ('.');
|
||||
@@ -796,7 +796,7 @@ namespace client
|
||||
memset (buf, 0, 4);
|
||||
htobe32buf (buf + 4, nonce);
|
||||
buf[8] = address.length ();
|
||||
memcpy (buf + 9, address.c_str (), address.length ());
|
||||
memcpy (buf + 9, address.data (), address.length ());
|
||||
datagram->SendDatagramTo (buf, len, addr->identHash, ADDRESS_RESPONSE_DATAGRAM_PORT, ADDRESS_RESOLVER_DATAGRAM_PORT);
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -47,7 +47,7 @@ namespace client
|
||||
i2p::data::IdentHash identHash;
|
||||
std::shared_ptr<i2p::data::BlindedPublicKey> blindedPublicKey;
|
||||
|
||||
Address (const std::string& b32);
|
||||
Address (std::string_view b32);
|
||||
Address (const i2p::data::IdentHash& hash);
|
||||
bool IsIdentHash () const { return addressType == eAddressIndentHash; };
|
||||
bool IsValid () const { return addressType != eAddressInvalid; };
|
||||
@@ -59,15 +59,17 @@ namespace client
|
||||
{
|
||||
public:
|
||||
|
||||
typedef std::map<std::string, std::shared_ptr<Address>, std::less<> > Addresses;
|
||||
|
||||
virtual ~AddressBookStorage () {};
|
||||
virtual std::shared_ptr<const i2p::data::IdentityEx> GetAddress (const i2p::data::IdentHash& ident) const = 0;
|
||||
virtual void AddAddress (std::shared_ptr<const i2p::data::IdentityEx> address) = 0;
|
||||
virtual void RemoveAddress (const i2p::data::IdentHash& ident) = 0;
|
||||
|
||||
virtual bool Init () = 0;
|
||||
virtual int Load (std::map<std::string, std::shared_ptr<Address> >& addresses) = 0;
|
||||
virtual int LoadLocal (std::map<std::string, std::shared_ptr<Address> >& addresses) = 0;
|
||||
virtual int Save (const std::map<std::string, std::shared_ptr<Address> >& addresses) = 0;
|
||||
virtual int Load (Addresses& addresses) = 0;
|
||||
virtual int LoadLocal (Addresses& addresses) = 0;
|
||||
virtual int Save (const Addresses& addresses) = 0;
|
||||
|
||||
virtual void SaveEtag (const i2p::data::IdentHash& subscription, const std::string& etag, const std::string& lastModified) = 0;
|
||||
virtual bool GetEtag (const i2p::data::IdentHash& subscription, std::string& etag, std::string& lastModified) = 0;
|
||||
@@ -79,16 +81,16 @@ namespace client
|
||||
class AddressBook
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
AddressBook ();
|
||||
~AddressBook ();
|
||||
void Start ();
|
||||
void StartResolvers ();
|
||||
void Stop ();
|
||||
std::shared_ptr<const Address> GetAddress (const std::string& address);
|
||||
std::shared_ptr<const Address> GetAddress (std::string_view address);
|
||||
std::shared_ptr<const i2p::data::IdentityEx> GetFullAddress (const std::string& address);
|
||||
std::shared_ptr<const Address> FindAddress (const std::string& address);
|
||||
void LookupAddress (const std::string& address);
|
||||
std::shared_ptr<const Address> FindAddress (std::string_view address);
|
||||
void LookupAddress (std::string_view address);
|
||||
void InsertAddress (const std::string& address, const std::string& jump); // for jump links
|
||||
void InsertFullAddress (std::shared_ptr<const i2p::data::IdentityEx> address);
|
||||
|
||||
@@ -121,7 +123,7 @@ namespace client
|
||||
private:
|
||||
|
||||
std::mutex m_AddressBookMutex;
|
||||
std::map<std::string, std::shared_ptr<Address> > m_Addresses;
|
||||
AddressBookStorage::Addresses m_Addresses;
|
||||
std::map<i2p::data::IdentHash, std::shared_ptr<AddressResolver> > m_Resolvers; // local destination->resolver
|
||||
std::mutex m_LookupsMutex;
|
||||
std::map<uint32_t, std::string> m_Lookups; // nonce -> address
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -416,15 +416,10 @@ namespace client
|
||||
|
||||
void ClientContext::CreateNewSharedLocalDestination ()
|
||||
{
|
||||
std::map<std::string, std::string> params
|
||||
{
|
||||
{ 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_OUTBOUND_NICKNAME, "SharedDest" },
|
||||
{ I2CP_PARAM_STREAMING_PROFILE, "2" }
|
||||
};
|
||||
std::map<std::string, std::string> params;
|
||||
ReadI2CPOptionsFromConfig ("shareddest.", params);
|
||||
params[I2CP_PARAM_OUTBOUND_NICKNAME] = "SharedDest";
|
||||
|
||||
m_SharedLocalDestination = CreateNewLocalDestination (false, i2p::data::SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519,
|
||||
i2p::data::CRYPTO_KEY_TYPE_ELGAMAL, ¶ms); // non-public, EDDSA
|
||||
m_SharedLocalDestination->Acquire ();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -60,7 +60,7 @@ namespace proxy {
|
||||
"</head>\r\n"
|
||||
;
|
||||
|
||||
static bool str_rmatch(std::string & str, const char *suffix)
|
||||
static bool str_rmatch(std::string_view str, const char *suffix)
|
||||
{
|
||||
auto pos = str.rfind (suffix);
|
||||
if (pos == std::string::npos)
|
||||
@@ -84,16 +84,16 @@ namespace proxy {
|
||||
void SentHTTPFailed(const boost::system::error_code & ecode);
|
||||
void HandleStreamRequestComplete (std::shared_ptr<i2p::stream::Stream> stream);
|
||||
/* error helpers */
|
||||
void GenericProxyError(const std::string& title, const std::string& description);
|
||||
void GenericProxyInfo(const std::string& title, const std::string& description);
|
||||
void HostNotFound(const std::string& host);
|
||||
void SendProxyError(const std::string& content);
|
||||
void GenericProxyError(std::string_view title, std::string_view description);
|
||||
void GenericProxyInfo(std::string_view title, std::string_view description);
|
||||
void HostNotFound(std::string_view host);
|
||||
void SendProxyError(std::string_view content);
|
||||
void SendRedirect(const std::string& address);
|
||||
|
||||
void ForwardToUpstreamProxy();
|
||||
void HandleUpstreamHTTPProxyConnect(const boost::system::error_code & ec);
|
||||
void HandleUpstreamSocksProxyConnect(const boost::system::error_code & ec);
|
||||
void HTTPConnect(const std::string & host, uint16_t port);
|
||||
void HTTPConnect(std::string_view host, uint16_t port);
|
||||
void HandleHTTPConnectStreamRequestComplete(std::shared_ptr<i2p::stream::Stream> stream);
|
||||
|
||||
typedef std::function<void(boost::asio::ip::tcp::endpoint)> ProxyResolvedHandler;
|
||||
@@ -162,23 +162,23 @@ namespace proxy {
|
||||
Done(shared_from_this());
|
||||
}
|
||||
|
||||
void HTTPReqHandler::GenericProxyError(const std::string& title, const std::string& description) {
|
||||
void HTTPReqHandler::GenericProxyError(std::string_view title, std::string_view description)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "<h1>" << tr("Proxy error") << ": " << title << "</h1>\r\n";
|
||||
ss << "<p>" << description << "</p>\r\n";
|
||||
std::string content = ss.str();
|
||||
SendProxyError(content);
|
||||
SendProxyError(ss.str ());
|
||||
}
|
||||
|
||||
void HTTPReqHandler::GenericProxyInfo(const std::string& title, const std::string& description) {
|
||||
void HTTPReqHandler::GenericProxyInfo(std::string_view title, std::string_view description)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "<h1>" << tr("Proxy info") << ": " << title << "</h1>\r\n";
|
||||
ss << "<p>" << description << "</p>\r\n";
|
||||
std::string content = ss.str();
|
||||
SendProxyError(content);
|
||||
SendProxyError(ss.str ());
|
||||
}
|
||||
|
||||
void HTTPReqHandler::HostNotFound(const std::string& host)
|
||||
void HTTPReqHandler::HostNotFound(std::string_view host)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "<h1>" << tr("Proxy error: Host not found") << "</h1>\r\n"
|
||||
@@ -192,11 +192,10 @@ namespace proxy {
|
||||
ss << " <li><a href=\"" << js->second << host << "\">" << js->first << "</a></li>\r\n";
|
||||
}
|
||||
ss << "</ul>\r\n";
|
||||
std::string content = ss.str();
|
||||
SendProxyError(content);
|
||||
SendProxyError(ss.str ());
|
||||
}
|
||||
|
||||
void HTTPReqHandler::SendProxyError(const std::string& content)
|
||||
void HTTPReqHandler::SendProxyError(std::string_view content)
|
||||
{
|
||||
i2p::http::HTTPRes res;
|
||||
res.code = 500;
|
||||
@@ -473,7 +472,7 @@ namespace proxy {
|
||||
if (dest_host != "")
|
||||
{
|
||||
/* absolute url, replace 'Host' header */
|
||||
std::string h = dest_host;
|
||||
std::string h (dest_host);
|
||||
if (dest_port != 0 && dest_port != 80)
|
||||
h += ":" + std::to_string(dest_port);
|
||||
m_ClientRequest.UpdateHeader("Host", h);
|
||||
@@ -513,7 +512,7 @@ namespace proxy {
|
||||
GenericProxyError(tr("Outproxy failure"), tr("Bad outproxy settings"));
|
||||
} else {
|
||||
LogPrint (eLogWarning, "HTTPProxy: Outproxy failure for ", dest_host, ": no outproxy enabled");
|
||||
std::stringstream ss; ss << tr("Host %s is not inside I2P network, but outproxy is not enabled", dest_host.c_str());
|
||||
std::stringstream ss; ss << tr("Host %s is not inside I2P network, but outproxy is not enabled", dest_host.c_str ());
|
||||
GenericProxyError(tr("Outproxy failure"), ss.str());
|
||||
}
|
||||
return true;
|
||||
@@ -653,11 +652,10 @@ namespace proxy {
|
||||
Terminate();
|
||||
}
|
||||
|
||||
void HTTPReqHandler::HTTPConnect(const std::string & host, uint16_t port)
|
||||
void HTTPReqHandler::HTTPConnect(std::string_view host, uint16_t port)
|
||||
{
|
||||
LogPrint(eLogDebug, "HTTPProxy: CONNECT ",host, ":", port);
|
||||
std::string hostname(host);
|
||||
if(str_rmatch(hostname, ".i2p"))
|
||||
if(str_rmatch(host, ".i2p"))
|
||||
GetOwner()->CreateStream (std::bind (&HTTPReqHandler::HandleHTTPConnectStreamRequestComplete,
|
||||
shared_from_this(), std::placeholders::_1), host, port);
|
||||
else
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -555,20 +555,20 @@ namespace client
|
||||
m_IsSending = false;
|
||||
}
|
||||
|
||||
std::string I2CPSession::ExtractString (const uint8_t * buf, size_t len)
|
||||
std::string_view I2CPSession::ExtractString (const uint8_t * buf, size_t len)
|
||||
{
|
||||
uint8_t l = buf[0];
|
||||
if (l > len) l = len;
|
||||
return std::string ((const char *)(buf + 1), l);
|
||||
return { (const char *)(buf + 1), l };
|
||||
}
|
||||
|
||||
size_t I2CPSession::PutString (uint8_t * buf, size_t len, const std::string& str)
|
||||
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.c_str (), l);
|
||||
memcpy (buf + 1, str.data (), l);
|
||||
return l + 1;
|
||||
}
|
||||
|
||||
@@ -578,7 +578,7 @@ namespace client
|
||||
size_t offset = 0;
|
||||
while (offset < len)
|
||||
{
|
||||
std::string param = ExtractString (buf + offset, len - offset);
|
||||
auto param = ExtractString (buf + offset, len - offset);
|
||||
offset += param.length () + 1;
|
||||
if (buf[offset] != '=')
|
||||
{
|
||||
@@ -587,7 +587,7 @@ namespace client
|
||||
}
|
||||
offset++;
|
||||
|
||||
std::string value = ExtractString (buf + offset, len - offset);
|
||||
auto value = ExtractString (buf + offset, len - offset);
|
||||
offset += value.length () + 1;
|
||||
if (buf[offset] != ';')
|
||||
{
|
||||
@@ -595,7 +595,7 @@ namespace client
|
||||
break;
|
||||
}
|
||||
offset++;
|
||||
mapping.insert (std::make_pair (param, value));
|
||||
mapping.emplace (param, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
@@ -191,8 +192,8 @@ namespace client
|
||||
|
||||
void HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||
|
||||
std::string ExtractString (const uint8_t * buf, size_t len);
|
||||
size_t PutString (uint8_t * buf, size_t len, const std::string& str);
|
||||
std::string_view ExtractString (const uint8_t * buf, size_t len);
|
||||
size_t PutString (uint8_t * buf, size_t len, std::string_view str);
|
||||
void ExtractMapping (const uint8_t * buf, size_t len, std::map<std::string, std::string>& mapping);
|
||||
void SendSessionStatusMessage (I2CPSessionStatus status);
|
||||
void SendHostReplyMessage (uint32_t requestID, std::shared_ptr<const i2p::data::IdentityEx> identity);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -107,7 +107,7 @@ namespace client
|
||||
m_ReadyTimerTriggered = false;
|
||||
}
|
||||
|
||||
void I2PService::CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, uint16_t port) {
|
||||
void I2PService::CreateStream (StreamRequestComplete streamRequestComplete, std::string_view dest, uint16_t port) {
|
||||
assert(streamRequestComplete);
|
||||
auto address = i2p::client::context.GetAddressBook ().GetAddress (dest);
|
||||
if (address)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2024, The PurpleI2P Project
|
||||
* Copyright (c) 2013-2025, The PurpleI2P Project
|
||||
*
|
||||
* This file is part of Purple i2pd project and licensed under BSD3
|
||||
*
|
||||
@@ -59,7 +59,7 @@ namespace client
|
||||
if (dest) dest->Acquire ();
|
||||
m_LocalDestination = dest;
|
||||
}
|
||||
void CreateStream (StreamRequestComplete streamRequestComplete, const std::string& dest, uint16_t port = 0);
|
||||
void CreateStream (StreamRequestComplete streamRequestComplete, std::string_view dest, uint16_t port = 0);
|
||||
void CreateStream(StreamRequestComplete complete, std::shared_ptr<const Address> address, uint16_t port);
|
||||
auto& GetService () { return m_LocalDestination->GetService (); }
|
||||
|
||||
|
||||
@@ -43,18 +43,20 @@ uint8_t encrypted[114] =
|
||||
int main ()
|
||||
{
|
||||
uint8_t buf[114+16];
|
||||
i2p::crypto::AEADChaCha20Poly1305Encryptor encryptor;
|
||||
// test encryption
|
||||
i2p::crypto::AEADChaCha20Poly1305 ((uint8_t *)text, 114, ad, 12, key, nonce, buf, 114 + 16, true);
|
||||
encryptor.Encrypt ((uint8_t *)text, 114, ad, 12, key, nonce, buf, 114 + 16);
|
||||
assert (memcmp (buf, encrypted, 114) == 0);
|
||||
assert (memcmp (buf + 114, tag, 16) == 0);
|
||||
// test decryption
|
||||
uint8_t buf1[114];
|
||||
assert (i2p::crypto::AEADChaCha20Poly1305 (buf, 114, ad, 12, key, nonce, buf1, 114, false));
|
||||
i2p::crypto::AEADChaCha20Poly1305Decryptor decryptor;
|
||||
assert (decryptor.Decrypt (buf, 114, ad, 12, key, nonce, buf1, 114));
|
||||
assert (memcmp (buf1, text, 114) == 0);
|
||||
// test encryption of multiple buffers
|
||||
memcpy (buf, text, 114);
|
||||
std::vector<std::pair<uint8_t*, std::size_t> > bufs{ std::make_pair (buf, 20), std::make_pair (buf + 20, 10), std::make_pair (buf + 30, 70), std::make_pair (buf + 100, 14) };
|
||||
i2p::crypto::AEADChaCha20Poly1305Encrypt (bufs, key, nonce, buf + 114);
|
||||
i2p::crypto::AEADChaCha20Poly1305 (buf, 114, nullptr, 0, key, nonce, buf1, 114, false);
|
||||
encryptor.Encrypt (bufs, key, nonce, buf + 114);
|
||||
decryptor.Decrypt (buf, 114, nullptr, 0, key, nonce, buf1, 114);
|
||||
assert (memcmp (buf1, text, 114) == 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user