mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-07 06:09:42 +00:00
Compare commits
5 Commits
079199c17f
...
3f022b252d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f022b252d | ||
|
|
08a680b53d | ||
|
|
634ceceb1c | ||
|
|
efd8e6e65b | ||
|
|
915429bb49 |
@@ -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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -152,11 +152,11 @@ namespace data
|
|||||||
m_BlindedSigType = m_SigType;
|
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
|
m_SigType (0) // 0 means invalid, we can't blind DSA, set it later
|
||||||
{
|
{
|
||||||
uint8_t addr[40]; // TODO: define length from b33
|
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)
|
if (l < 32)
|
||||||
{
|
{
|
||||||
LogPrint (eLogError, "Blinding: Malformed b33 ", b33);
|
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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Identity.h"
|
#include "Identity.h"
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ namespace data
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
BlindedPublicKey (std::shared_ptr<const IdentityEx> identity, bool clientAuth = false);
|
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;
|
std::string ToB33 () const;
|
||||||
|
|
||||||
const uint8_t * GetPublicKey () const { return m_PublicKey.data (); };
|
const uint8_t * GetPublicKey () const { return m_PublicKey.data (); };
|
||||||
|
|||||||
@@ -390,9 +390,9 @@ namespace datagram
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto path = m_RoutingSession->GetSharedRoutingPath();
|
auto path = m_RoutingSession->GetSharedRoutingPath();
|
||||||
if (path && m_RoutingSession->IsRatchets () && (m_RoutingSession->CleanupUnconfirmedTags () ||
|
if (path && m_RoutingSession->IsRatchets () && m_RoutingSession->CleanupUnconfirmedTags ())
|
||||||
m_LastUse > m_RoutingSession->GetLastActivityTimestamp ()*1000 + DATAGRAM_SESSION_PATH_TIMEOUT))
|
|
||||||
{
|
{
|
||||||
|
LogPrint (eLogDebug, "Datagram: path reset");
|
||||||
m_RoutingSession->SetSharedRoutingPath (nullptr);
|
m_RoutingSession->SetSharedRoutingPath (nullptr);
|
||||||
path = nullptr;
|
path = nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ namespace datagram
|
|||||||
{
|
{
|
||||||
// milliseconds for max session idle time
|
// milliseconds for max session idle time
|
||||||
const uint64_t DATAGRAM_SESSION_MAX_IDLE = 10 * 60 * 1000;
|
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
|
// milliseconds interval a routing path is used before switching
|
||||||
const uint64_t DATAGRAM_SESSION_PATH_SWITCH_INTERVAL = 20 * 60 * 1000;
|
const uint64_t DATAGRAM_SESSION_PATH_SWITCH_INTERVAL = 20 * 60 * 1000;
|
||||||
// milliseconds before lease expire should we try switching leases
|
// milliseconds before lease expire should we try switching leases
|
||||||
|
|||||||
@@ -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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -262,11 +262,11 @@ namespace data
|
|||||||
return fullLen;
|
return fullLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t IdentityEx::FromBase64(const std::string& s)
|
size_t IdentityEx::FromBase64(std::string_view s)
|
||||||
{
|
{
|
||||||
const size_t slen = s.length();
|
const size_t slen = s.length();
|
||||||
std::vector<uint8_t> buf(slen); // binary data can't exceed base64
|
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);
|
return FromBuffer (buf.data(), len);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -728,9 +728,7 @@ namespace data
|
|||||||
case SIGNING_KEY_TYPE_RSA_SHA384_3072:
|
case SIGNING_KEY_TYPE_RSA_SHA384_3072:
|
||||||
case SIGNING_KEY_TYPE_RSA_SHA512_4096:
|
case SIGNING_KEY_TYPE_RSA_SHA512_4096:
|
||||||
LogPrint (eLogWarning, "Identity: RSA signature type is not supported. Creating EdDSA");
|
LogPrint (eLogWarning, "Identity: RSA signature type is not supported. Creating EdDSA");
|
||||||
#if (__cplusplus >= 201703L) // C++ 17 or higher
|
|
||||||
[[fallthrough]];
|
[[fallthrough]];
|
||||||
#endif
|
|
||||||
// no break here
|
// no break here
|
||||||
case SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519:
|
case SIGNING_KEY_TYPE_EDDSA_SHA512_ED25519:
|
||||||
i2p::crypto::CreateEDDSA25519RandomKeys (priv, pub);
|
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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
@@ -99,7 +100,7 @@ namespace data
|
|||||||
|
|
||||||
size_t FromBuffer (const uint8_t * buf, size_t len);
|
size_t FromBuffer (const uint8_t * buf, size_t len);
|
||||||
size_t ToBuffer (uint8_t * buf, size_t len) const;
|
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;
|
std::string ToBase64 () const;
|
||||||
const Identity& GetStandardIdentity () const { return m_StandardIdentity; };
|
const Identity& GetStandardIdentity () const { return m_StandardIdentity; };
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -12,10 +12,14 @@
|
|||||||
#include <boost/static_assert.hpp>
|
#include <boost/static_assert.hpp>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <openssl/rand.h>
|
#include <openssl/rand.h>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
|
|
||||||
namespace i2p {
|
namespace i2p
|
||||||
namespace data {
|
{
|
||||||
|
namespace data
|
||||||
|
{
|
||||||
template<size_t sz>
|
template<size_t sz>
|
||||||
class Tag
|
class Tag
|
||||||
{
|
{
|
||||||
@@ -70,14 +74,14 @@ namespace data {
|
|||||||
return std::string (str, str + l);
|
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
|
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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -49,22 +49,22 @@ namespace client
|
|||||||
if (m_IsPersist)
|
if (m_IsPersist)
|
||||||
i2p::config::GetOption("addressbook.hostsfile", m_HostsFile);
|
i2p::config::GetOption("addressbook.hostsfile", m_HostsFile);
|
||||||
}
|
}
|
||||||
std::shared_ptr<const i2p::data::IdentityEx> GetAddress (const i2p::data::IdentHash& ident) const;
|
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);
|
void AddAddress (std::shared_ptr<const i2p::data::IdentityEx> address) override;
|
||||||
void RemoveAddress (const i2p::data::IdentHash& ident);
|
void RemoveAddress (const i2p::data::IdentHash& ident) override;
|
||||||
|
|
||||||
bool Init ();
|
bool Init () override;
|
||||||
int Load (std::map<std::string, std::shared_ptr<Address> > & addresses);
|
int Load (Addresses& addresses) override;
|
||||||
int LoadLocal (std::map<std::string, std::shared_ptr<Address> >& addresses);
|
int LoadLocal (Addresses& addresses) override;
|
||||||
int Save (const std::map<std::string, std::shared_ptr<Address> >& addresses);
|
int Save (const Addresses& addresses) override;
|
||||||
|
|
||||||
void SaveEtag (const i2p::data::IdentHash& subsciption, const std::string& etag, const std::string& lastModified);
|
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);
|
bool GetEtag (const i2p::data::IdentHash& subscription, std::string& etag, std::string& lastModified) override;
|
||||||
void ResetEtags ();
|
void ResetEtags () override;
|
||||||
|
|
||||||
private:
|
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:
|
private:
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ namespace client
|
|||||||
storage.Remove( ident.ToBase32() );
|
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;
|
int num = 0;
|
||||||
std::ifstream f (filename, std::ifstream::in); // in text mode
|
std::ifstream f (filename, std::ifstream::in); // in text mode
|
||||||
@@ -168,7 +168,7 @@ namespace client
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AddressBookFilesystemStorage::Load (std::map<std::string, std::shared_ptr<Address> >& addresses)
|
int AddressBookFilesystemStorage::Load (Addresses& addresses)
|
||||||
{
|
{
|
||||||
int num = LoadFromFile (indexPath, addresses);
|
int num = LoadFromFile (indexPath, addresses);
|
||||||
if (num < 0)
|
if (num < 0)
|
||||||
@@ -182,7 +182,7 @@ namespace client
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AddressBookFilesystemStorage::LoadLocal (std::map<std::string, std::shared_ptr<Address> >& addresses)
|
int AddressBookFilesystemStorage::LoadLocal (Addresses& addresses)
|
||||||
{
|
{
|
||||||
int num = LoadFromFile (localPath, addresses);
|
int num = LoadFromFile (localPath, addresses);
|
||||||
if (num < 0) return 0;
|
if (num < 0) return 0;
|
||||||
@@ -190,7 +190,7 @@ namespace client
|
|||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AddressBookFilesystemStorage::Save (const std::map<std::string, std::shared_ptr<Address> >& addresses)
|
int AddressBookFilesystemStorage::Save (const Addresses& addresses)
|
||||||
{
|
{
|
||||||
if (addresses.empty())
|
if (addresses.empty())
|
||||||
{
|
{
|
||||||
@@ -283,7 +283,7 @@ namespace client
|
|||||||
|
|
||||||
//---------------------------------------------------------------------
|
//---------------------------------------------------------------------
|
||||||
|
|
||||||
Address::Address (const std::string& b32):
|
Address::Address (std::string_view b32):
|
||||||
addressType (eAddressInvalid)
|
addressType (eAddressInvalid)
|
||||||
{
|
{
|
||||||
if (b32.length () <= B33_ADDRESS_THRESHOLD)
|
if (b32.length () <= B33_ADDRESS_THRESHOLD)
|
||||||
@@ -377,7 +377,7 @@ namespace client
|
|||||||
m_Subscriptions.clear ();
|
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");
|
auto pos = address.find(".b32.i2p");
|
||||||
if (pos != std::string::npos)
|
if (pos != std::string::npos)
|
||||||
@@ -404,7 +404,7 @@ namespace client
|
|||||||
return std::make_shared<const Address>(dest.GetIdentHash ());
|
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);
|
auto it = m_Addresses.find (address);
|
||||||
if (it != m_Addresses.end ())
|
if (it != m_Addresses.end ())
|
||||||
@@ -609,7 +609,7 @@ namespace client
|
|||||||
void AddressBook::LoadLocal ()
|
void AddressBook::LoadLocal ()
|
||||||
{
|
{
|
||||||
if (!m_Storage) return;
|
if (!m_Storage) return;
|
||||||
std::map<std::string, std::shared_ptr<Address>> localAddresses;
|
AddressBookStorage::Addresses localAddresses;
|
||||||
m_Storage->LoadLocal (localAddresses);
|
m_Storage->LoadLocal (localAddresses);
|
||||||
for (const auto& it: 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;
|
std::shared_ptr<const Address> addr;
|
||||||
auto dot = address.find ('.');
|
auto dot = address.find ('.');
|
||||||
@@ -796,7 +796,7 @@ namespace client
|
|||||||
memset (buf, 0, 4);
|
memset (buf, 0, 4);
|
||||||
htobe32buf (buf + 4, nonce);
|
htobe32buf (buf + 4, nonce);
|
||||||
buf[8] = address.length ();
|
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);
|
datagram->SendDatagramTo (buf, len, addr->identHash, ADDRESS_RESPONSE_DATAGRAM_PORT, ADDRESS_RESOLVER_DATAGRAM_PORT);
|
||||||
delete[] buf;
|
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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -47,7 +47,7 @@ namespace client
|
|||||||
i2p::data::IdentHash identHash;
|
i2p::data::IdentHash identHash;
|
||||||
std::shared_ptr<i2p::data::BlindedPublicKey> blindedPublicKey;
|
std::shared_ptr<i2p::data::BlindedPublicKey> blindedPublicKey;
|
||||||
|
|
||||||
Address (const std::string& b32);
|
Address (std::string_view b32);
|
||||||
Address (const i2p::data::IdentHash& hash);
|
Address (const i2p::data::IdentHash& hash);
|
||||||
bool IsIdentHash () const { return addressType == eAddressIndentHash; };
|
bool IsIdentHash () const { return addressType == eAddressIndentHash; };
|
||||||
bool IsValid () const { return addressType != eAddressInvalid; };
|
bool IsValid () const { return addressType != eAddressInvalid; };
|
||||||
@@ -59,15 +59,17 @@ namespace client
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
typedef std::map<std::string, std::shared_ptr<Address>, std::less<> > Addresses;
|
||||||
|
|
||||||
virtual ~AddressBookStorage () {};
|
virtual ~AddressBookStorage () {};
|
||||||
virtual std::shared_ptr<const i2p::data::IdentityEx> GetAddress (const i2p::data::IdentHash& ident) const = 0;
|
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 AddAddress (std::shared_ptr<const i2p::data::IdentityEx> address) = 0;
|
||||||
virtual void RemoveAddress (const i2p::data::IdentHash& ident) = 0;
|
virtual void RemoveAddress (const i2p::data::IdentHash& ident) = 0;
|
||||||
|
|
||||||
virtual bool Init () = 0;
|
virtual bool Init () = 0;
|
||||||
virtual int Load (std::map<std::string, std::shared_ptr<Address> >& addresses) = 0;
|
virtual int Load (Addresses& addresses) = 0;
|
||||||
virtual int LoadLocal (std::map<std::string, std::shared_ptr<Address> >& addresses) = 0;
|
virtual int LoadLocal (Addresses& addresses) = 0;
|
||||||
virtual int Save (const std::map<std::string, std::shared_ptr<Address> >& 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 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;
|
virtual bool GetEtag (const i2p::data::IdentHash& subscription, std::string& etag, std::string& lastModified) = 0;
|
||||||
@@ -79,16 +81,16 @@ namespace client
|
|||||||
class AddressBook
|
class AddressBook
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
AddressBook ();
|
AddressBook ();
|
||||||
~AddressBook ();
|
~AddressBook ();
|
||||||
void Start ();
|
void Start ();
|
||||||
void StartResolvers ();
|
void StartResolvers ();
|
||||||
void Stop ();
|
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 i2p::data::IdentityEx> GetFullAddress (const std::string& address);
|
||||||
std::shared_ptr<const Address> FindAddress (const std::string& address);
|
std::shared_ptr<const Address> FindAddress (std::string_view address);
|
||||||
void LookupAddress (const std::string& address);
|
void LookupAddress (std::string_view address);
|
||||||
void InsertAddress (const std::string& address, const std::string& jump); // for jump links
|
void InsertAddress (const std::string& address, const std::string& jump); // for jump links
|
||||||
void InsertFullAddress (std::shared_ptr<const i2p::data::IdentityEx> address);
|
void InsertFullAddress (std::shared_ptr<const i2p::data::IdentityEx> address);
|
||||||
|
|
||||||
@@ -121,7 +123,7 @@ namespace client
|
|||||||
private:
|
private:
|
||||||
|
|
||||||
std::mutex m_AddressBookMutex;
|
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::map<i2p::data::IdentHash, std::shared_ptr<AddressResolver> > m_Resolvers; // local destination->resolver
|
||||||
std::mutex m_LookupsMutex;
|
std::mutex m_LookupsMutex;
|
||||||
std::map<uint32_t, std::string> m_Lookups; // nonce -> address
|
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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -60,7 +60,7 @@ namespace proxy {
|
|||||||
"</head>\r\n"
|
"</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);
|
auto pos = str.rfind (suffix);
|
||||||
if (pos == std::string::npos)
|
if (pos == std::string::npos)
|
||||||
@@ -84,16 +84,16 @@ namespace proxy {
|
|||||||
void SentHTTPFailed(const boost::system::error_code & ecode);
|
void SentHTTPFailed(const boost::system::error_code & ecode);
|
||||||
void HandleStreamRequestComplete (std::shared_ptr<i2p::stream::Stream> stream);
|
void HandleStreamRequestComplete (std::shared_ptr<i2p::stream::Stream> stream);
|
||||||
/* error helpers */
|
/* error helpers */
|
||||||
void GenericProxyError(const std::string& title, const std::string& description);
|
void GenericProxyError(std::string_view title, std::string_view description);
|
||||||
void GenericProxyInfo(const std::string& title, const std::string& description);
|
void GenericProxyInfo(std::string_view title, std::string_view description);
|
||||||
void HostNotFound(const std::string& host);
|
void HostNotFound(std::string_view host);
|
||||||
void SendProxyError(const std::string& content);
|
void SendProxyError(std::string_view content);
|
||||||
void SendRedirect(const std::string& address);
|
void SendRedirect(const std::string& address);
|
||||||
|
|
||||||
void ForwardToUpstreamProxy();
|
void ForwardToUpstreamProxy();
|
||||||
void HandleUpstreamHTTPProxyConnect(const boost::system::error_code & ec);
|
void HandleUpstreamHTTPProxyConnect(const boost::system::error_code & ec);
|
||||||
void HandleUpstreamSocksProxyConnect(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);
|
void HandleHTTPConnectStreamRequestComplete(std::shared_ptr<i2p::stream::Stream> stream);
|
||||||
|
|
||||||
typedef std::function<void(boost::asio::ip::tcp::endpoint)> ProxyResolvedHandler;
|
typedef std::function<void(boost::asio::ip::tcp::endpoint)> ProxyResolvedHandler;
|
||||||
@@ -162,23 +162,23 @@ namespace proxy {
|
|||||||
Done(shared_from_this());
|
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;
|
std::stringstream ss;
|
||||||
ss << "<h1>" << tr("Proxy error") << ": " << title << "</h1>\r\n";
|
ss << "<h1>" << tr("Proxy error") << ": " << title << "</h1>\r\n";
|
||||||
ss << "<p>" << description << "</p>\r\n";
|
ss << "<p>" << description << "</p>\r\n";
|
||||||
std::string content = ss.str();
|
SendProxyError(ss.str ());
|
||||||
SendProxyError(content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
std::stringstream ss;
|
||||||
ss << "<h1>" << tr("Proxy info") << ": " << title << "</h1>\r\n";
|
ss << "<h1>" << tr("Proxy info") << ": " << title << "</h1>\r\n";
|
||||||
ss << "<p>" << description << "</p>\r\n";
|
ss << "<p>" << description << "</p>\r\n";
|
||||||
std::string content = ss.str();
|
SendProxyError(ss.str ());
|
||||||
SendProxyError(content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPReqHandler::HostNotFound(const std::string& host)
|
void HTTPReqHandler::HostNotFound(std::string_view host)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "<h1>" << tr("Proxy error: Host not found") << "</h1>\r\n"
|
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 << " <li><a href=\"" << js->second << host << "\">" << js->first << "</a></li>\r\n";
|
||||||
}
|
}
|
||||||
ss << "</ul>\r\n";
|
ss << "</ul>\r\n";
|
||||||
std::string content = ss.str();
|
SendProxyError(ss.str ());
|
||||||
SendProxyError(content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HTTPReqHandler::SendProxyError(const std::string& content)
|
void HTTPReqHandler::SendProxyError(std::string_view content)
|
||||||
{
|
{
|
||||||
i2p::http::HTTPRes res;
|
i2p::http::HTTPRes res;
|
||||||
res.code = 500;
|
res.code = 500;
|
||||||
@@ -473,7 +472,7 @@ namespace proxy {
|
|||||||
if (dest_host != "")
|
if (dest_host != "")
|
||||||
{
|
{
|
||||||
/* absolute url, replace 'Host' header */
|
/* absolute url, replace 'Host' header */
|
||||||
std::string h = dest_host;
|
std::string h (dest_host);
|
||||||
if (dest_port != 0 && dest_port != 80)
|
if (dest_port != 0 && dest_port != 80)
|
||||||
h += ":" + std::to_string(dest_port);
|
h += ":" + std::to_string(dest_port);
|
||||||
m_ClientRequest.UpdateHeader("Host", h);
|
m_ClientRequest.UpdateHeader("Host", h);
|
||||||
@@ -513,7 +512,7 @@ namespace proxy {
|
|||||||
GenericProxyError(tr("Outproxy failure"), tr("Bad outproxy settings"));
|
GenericProxyError(tr("Outproxy failure"), tr("Bad outproxy settings"));
|
||||||
} else {
|
} else {
|
||||||
LogPrint (eLogWarning, "HTTPProxy: Outproxy failure for ", dest_host, ": no outproxy enabled");
|
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());
|
GenericProxyError(tr("Outproxy failure"), ss.str());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -653,11 +652,10 @@ namespace proxy {
|
|||||||
Terminate();
|
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);
|
LogPrint(eLogDebug, "HTTPProxy: CONNECT ",host, ":", port);
|
||||||
std::string hostname(host);
|
if(str_rmatch(host, ".i2p"))
|
||||||
if(str_rmatch(hostname, ".i2p"))
|
|
||||||
GetOwner()->CreateStream (std::bind (&HTTPReqHandler::HandleHTTPConnectStreamRequestComplete,
|
GetOwner()->CreateStream (std::bind (&HTTPReqHandler::HandleHTTPConnectStreamRequestComplete,
|
||||||
shared_from_this(), std::placeholders::_1), host, port);
|
shared_from_this(), std::placeholders::_1), host, port);
|
||||||
else
|
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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -555,20 +555,20 @@ namespace client
|
|||||||
m_IsSending = false;
|
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];
|
uint8_t l = buf[0];
|
||||||
if (l > len) l = len;
|
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 ();
|
auto l = str.length ();
|
||||||
if (l + 1 >= len) l = len - 1;
|
if (l + 1 >= len) l = len - 1;
|
||||||
if (l > 255) l = 255; // 1 byte max
|
if (l > 255) l = 255; // 1 byte max
|
||||||
buf[0] = l;
|
buf[0] = l;
|
||||||
memcpy (buf + 1, str.c_str (), l);
|
memcpy (buf + 1, str.data (), l);
|
||||||
return l + 1;
|
return l + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -578,7 +578,7 @@ namespace client
|
|||||||
size_t offset = 0;
|
size_t offset = 0;
|
||||||
while (offset < len)
|
while (offset < len)
|
||||||
{
|
{
|
||||||
std::string param = ExtractString (buf + offset, len - offset);
|
auto param = ExtractString (buf + offset, len - offset);
|
||||||
offset += param.length () + 1;
|
offset += param.length () + 1;
|
||||||
if (buf[offset] != '=')
|
if (buf[offset] != '=')
|
||||||
{
|
{
|
||||||
@@ -587,7 +587,7 @@ namespace client
|
|||||||
}
|
}
|
||||||
offset++;
|
offset++;
|
||||||
|
|
||||||
std::string value = ExtractString (buf + offset, len - offset);
|
auto value = ExtractString (buf + offset, len - offset);
|
||||||
offset += value.length () + 1;
|
offset += value.length () + 1;
|
||||||
if (buf[offset] != ';')
|
if (buf[offset] != ';')
|
||||||
{
|
{
|
||||||
@@ -595,7 +595,7 @@ namespace client
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
offset++;
|
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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@@ -191,8 +192,8 @@ namespace client
|
|||||||
|
|
||||||
void HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
void HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||||
|
|
||||||
std::string ExtractString (const uint8_t * buf, size_t len);
|
std::string_view ExtractString (const uint8_t * buf, size_t len);
|
||||||
size_t PutString (uint8_t * buf, size_t len, const std::string& str);
|
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 ExtractMapping (const uint8_t * buf, size_t len, std::map<std::string, std::string>& mapping);
|
||||||
void SendSessionStatusMessage (I2CPSessionStatus status);
|
void SendSessionStatusMessage (I2CPSessionStatus status);
|
||||||
void SendHostReplyMessage (uint32_t requestID, std::shared_ptr<const i2p::data::IdentityEx> identity);
|
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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -107,7 +107,7 @@ namespace client
|
|||||||
m_ReadyTimerTriggered = false;
|
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);
|
assert(streamRequestComplete);
|
||||||
auto address = i2p::client::context.GetAddressBook ().GetAddress (dest);
|
auto address = i2p::client::context.GetAddressBook ().GetAddress (dest);
|
||||||
if (address)
|
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
|
* This file is part of Purple i2pd project and licensed under BSD3
|
||||||
*
|
*
|
||||||
@@ -59,7 +59,7 @@ namespace client
|
|||||||
if (dest) dest->Acquire ();
|
if (dest) dest->Acquire ();
|
||||||
m_LocalDestination = dest;
|
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);
|
void CreateStream(StreamRequestComplete complete, std::shared_ptr<const Address> address, uint16_t port);
|
||||||
auto& GetService () { return m_LocalDestination->GetService (); }
|
auto& GetService () { return m_LocalDestination->GetService (); }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user