mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-07 06:09:42 +00:00
Compare commits
28 Commits
build-test
...
71334e487b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71334e487b | ||
|
|
5f762845f0 | ||
|
|
539e7e988e | ||
|
|
2a4403f1e0 | ||
|
|
dcd15cc244 | ||
|
|
9432202fad | ||
|
|
bf050ac465 | ||
|
|
81dae1997d | ||
|
|
7e3d9649de | ||
|
|
9ba016259d | ||
|
|
7791b3952e | ||
|
|
b97f09cc95 | ||
|
|
aedf59d11a | ||
|
|
d09367d686 | ||
|
|
70f99ccc21 | ||
|
|
ef72ba3f34 | ||
|
|
251605e2b8 | ||
|
|
fa2178ca3e | ||
|
|
3d19fa12f6 | ||
|
|
48aaecacce | ||
|
|
4bb86b6a86 | ||
|
|
0588116489 | ||
|
|
78a37cc00f | ||
|
|
fb90b01f6c | ||
|
|
ea55215668 | ||
|
|
58a86fa2dc | ||
|
|
ff0b6a6a6a | ||
|
|
6e639f0e6a |
10
ChangeLog
10
ChangeLog
@@ -1,7 +1,7 @@
|
||||
# for this file format description,
|
||||
# see https://github.com/olivierlacan/keep-a-changelog
|
||||
|
||||
## [2.56.0] - 2025-02-10
|
||||
## [2.56.0] - 2025-02-11
|
||||
### Added
|
||||
- Config params for shared local destination
|
||||
- AddressBook full addresses cache
|
||||
@@ -12,8 +12,8 @@
|
||||
- Set minimal version for peer test to 0.9.62
|
||||
- Send ack requested flag after second SSU2 resend attempt
|
||||
- Shorter ECIESx25519 ack request interval for datagram and I2CP sessions
|
||||
- Don't change datagram routing path too often if unidirectional data stream
|
||||
- Reduce LeaseSet and local RouterInfo publishing confimation intervals
|
||||
- Don't change datagram routing path too often if unidirectional data stream
|
||||
- Reduce LeaseSet and local RouterInfo publishing confirmation intervals
|
||||
- Don't delete buffer of connected routers or if an update received
|
||||
- Smaller RouterInfo request timeout if sent directly
|
||||
- Persist local RouterInfo in separate thread
|
||||
@@ -85,12 +85,12 @@
|
||||
- Handle i2cp.inboundlimit and i2cp.outboundlimit params in I2CP
|
||||
- Publish LeaseSet with new timestamp update if tunnel was replaced in the same second
|
||||
- Increase max number of generated tags to 800 per tagset
|
||||
- Routing path expiration by time instead num attempts
|
||||
- Routing path expiration by time instead num attempts
|
||||
- Save timestamp from epoch instead local time to profiles
|
||||
- Update introducer's iTag if session to introducer was replaced to new one
|
||||
- RTT, window size and number of NACKs calculation for streaming
|
||||
- Don't select same peer for tunnel too often
|
||||
- Use WinApi for data path UTF-8 conversion for Windows
|
||||
- Use WinApi for data path UTF-8 conversion for Windows
|
||||
### Fixed
|
||||
- Jump link crash if address book is disabled
|
||||
- Race condition if connect through an introducer
|
||||
|
||||
@@ -3,7 +3,7 @@ CXXFLAGS ?= ${CXX_DEBUG} -Wall -Wextra -Wno-unused-parameter -pedantic -Wno-misl
|
||||
DEFINES = -D_GLIBCXX_USE_NANOSLEEP=1
|
||||
INCFLAGS = -I/usr/include/ -I/usr/local/include/
|
||||
LDFLAGS = ${LD_DEBUG} -Wl,-rpath,/usr/local/lib -L/usr/local/lib
|
||||
LDLIBS = -lcrypto -lssl -lz -lpthread -lboost_system -lboost_program_options
|
||||
LDLIBS = -lssl -lcrypto -lz -lpthread -lboost_system -lboost_program_options
|
||||
|
||||
## NOTE: NEEDED_CXXFLAGS is here so that custom CXXFLAGS can be specified at build time
|
||||
## **without** overwriting the CXXFLAGS which we need in order to build.
|
||||
|
||||
@@ -2,7 +2,7 @@ CXX = g++
|
||||
CXXFLAGS := -Wall -std=c++17
|
||||
INCFLAGS = -I/system/develop/headers
|
||||
DEFINES = -D_DEFAULT_SOURCE -D_GNU_SOURCE
|
||||
LDLIBS = -lbe -lbsd -lnetwork -lz -lcrypto -lssl -lboost_system -lboost_program_options -lpthread
|
||||
LDLIBS = -lbe -lbsd -lnetwork -lz -lssl -lcrypto -lboost_system -lboost_program_options -lpthread
|
||||
|
||||
ifeq ($(USE_UPNP),yes)
|
||||
DEFINES += -DUSE_UPNP
|
||||
|
||||
@@ -18,7 +18,7 @@ endif
|
||||
LDLIBS += -lpthread -ldl
|
||||
else
|
||||
LDFLAGS += -L${SSLROOT}/lib -L${BOOSTROOT}/lib
|
||||
LDLIBS = -lz -lcrypto -lssl -lboost_system -lboost_filesystem -lboost_program_options -lpthread
|
||||
LDLIBS = -lz -lssl -lcrypto -lboost_system -lboost_filesystem -lboost_program_options -lpthread
|
||||
ifeq ($(USE_UPNP),yes)
|
||||
LDFLAGS += -L${UPNPROOT}/lib
|
||||
LDLIBS += -lminiupnpc
|
||||
|
||||
@@ -40,7 +40,7 @@ ifeq ($(USE_UPNP),yes)
|
||||
endif
|
||||
LDLIBS += -lpthread -ldl
|
||||
else
|
||||
LDLIBS += -lcrypto -lssl -lz -lboost_program_options -lpthread -latomic
|
||||
LDLIBS += -lssl -lcrypto -lz -lboost_program_options -lpthread -latomic
|
||||
ifeq ($(USE_UPNP),yes)
|
||||
LDLIBS += -lminiupnpc
|
||||
endif
|
||||
|
||||
@@ -7,9 +7,9 @@ LDFLAGS += -Wl,-dead_strip
|
||||
LDFLAGS += -Wl,-dead_strip_dylibs
|
||||
|
||||
ifeq ($(USE_STATIC),yes)
|
||||
LDLIBS = -lz /usr/local/lib/libcrypto.a /usr/local/lib/libssl.a /usr/local/lib/libboost_system.a /usr/local/lib/libboost_filesystem.a /usr/local/lib/libboost_program_options.a -lpthread
|
||||
LDLIBS = -lz /usr/local/lib/libssl.a /usr/local/lib/libcrypto.a /usr/local/lib/libboost_system.a /usr/local/lib/libboost_filesystem.a /usr/local/lib/libboost_program_options.a -lpthread
|
||||
else
|
||||
LDLIBS = -lz -lcrypto -lssl -lboost_system -lboost_filesystem -lboost_program_options -lpthread
|
||||
LDLIBS = -lz -lssl -lcrypto -lboost_system -lboost_filesystem -lboost_program_options -lpthread
|
||||
endif
|
||||
|
||||
ifeq ($(USE_UPNP),yes)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
Description=I2P Router written in C++
|
||||
Documentation=man:i2pd(1) https://i2pd.readthedocs.io/en/latest/
|
||||
After=network.target
|
||||
Wants=yggdrasil.service
|
||||
|
||||
[Service]
|
||||
User=i2pd
|
||||
|
||||
@@ -148,7 +148,7 @@ getent passwd i2pd >/dev/null || \
|
||||
|
||||
|
||||
%changelog
|
||||
* Sun Feb 09 2025 orignal <orignal@i2pmail.org> - 2.56.0
|
||||
* Tue Feb 11 2025 orignal <orignal@i2pmail.org> - 2.56.0
|
||||
- update to 2.56.0
|
||||
|
||||
* Mon Dec 30 2024 orignal <orignal@i2pmail.org> - 2.55.0
|
||||
|
||||
@@ -146,7 +146,7 @@ getent passwd i2pd >/dev/null || \
|
||||
|
||||
|
||||
%changelog
|
||||
* Sun Feb 09 2025 orignal <orignal@i2pmail.org> - 2.56.0
|
||||
* Tue Feb 11 2025 orignal <orignal@i2pmail.org> - 2.56.0
|
||||
- update to 2.56.0
|
||||
|
||||
* Mon Dec 30 2024 orignal <orignal@i2pmail.org> - 2.55.0
|
||||
|
||||
2
debian/changelog
vendored
2
debian/changelog
vendored
@@ -2,7 +2,7 @@ i2pd (2.56.0-1) unstable; urgency=medium
|
||||
|
||||
* updated to version 2.56.0/0.9.65
|
||||
|
||||
-- orignal <orignal@i2pmail.org> Sun, 09 Feb 2025 16:00:00 +0000
|
||||
-- orignal <orignal@i2pmail.org> Tue, 11 Feb 2025 16:00:00 +0000
|
||||
|
||||
i2pd (2.55.0-1) unstable; urgency=medium
|
||||
|
||||
|
||||
@@ -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
|
||||
*
|
||||
@@ -90,10 +90,10 @@ namespace data
|
||||
}
|
||||
|
||||
bool Families::VerifyFamily (const std::string& family, const IdentHash& ident,
|
||||
const char * signature, const char * key) const
|
||||
std::string_view signature, const char * key) const
|
||||
{
|
||||
uint8_t buf[100], signatureBuf[64];
|
||||
size_t len = family.length (), signatureLen = strlen (signature);
|
||||
size_t len = family.length ();
|
||||
if (len + 32 > 100)
|
||||
{
|
||||
LogPrint (eLogError, "Family: ", family, " is too long");
|
||||
@@ -105,7 +105,7 @@ namespace data
|
||||
memcpy (buf, family.c_str (), len);
|
||||
memcpy (buf + len, (const uint8_t *)ident, 32);
|
||||
len += 32;
|
||||
auto signatureBufLen = Base64ToByteStream (signature, signatureLen, signatureBuf, 64);
|
||||
auto signatureBufLen = Base64ToByteStream (signature.data (), signature.length (), signatureBuf, 64);
|
||||
if (signatureBufLen)
|
||||
{
|
||||
EVP_MD_CTX * ctx = EVP_MD_CTX_create ();
|
||||
|
||||
@@ -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 <map>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <memory>
|
||||
#include <openssl/evp.h>
|
||||
#include "Identity.h"
|
||||
@@ -28,7 +29,7 @@ namespace data
|
||||
~Families ();
|
||||
void LoadCertificates ();
|
||||
bool VerifyFamily (const std::string& family, const IdentHash& ident,
|
||||
const char * signature, const char * key = nullptr) const;
|
||||
std::string_view signature, const char * key = nullptr) const;
|
||||
FamilyID GetFamilyID (const std::string& family) const;
|
||||
|
||||
private:
|
||||
|
||||
@@ -675,12 +675,12 @@ namespace i2p
|
||||
|
||||
void RouterContext::SetBandwidth (int limit)
|
||||
{
|
||||
if (limit > 2000) { SetBandwidth('X'); }
|
||||
else if (limit > 256) { SetBandwidth('P'); }
|
||||
else if (limit > 128) { SetBandwidth('O'); }
|
||||
else if (limit > 64) { SetBandwidth('N'); }
|
||||
else if (limit > 48) { SetBandwidth('M'); }
|
||||
else if (limit > 12) { SetBandwidth('L'); }
|
||||
if (limit > (int)i2p::data::EXTRA_BANDWIDTH_LIMIT) { SetBandwidth('X'); }
|
||||
else if (limit > (int)i2p::data::HIGH_BANDWIDTH_LIMIT) { SetBandwidth('P'); }
|
||||
else if (limit > 128) { SetBandwidth('O'); }
|
||||
else if (limit > 64) { SetBandwidth('N'); }
|
||||
else if (limit > (int)i2p::data::LOW_BANDWIDTH_LIMIT) { SetBandwidth('M'); }
|
||||
else if (limit > 12) { SetBandwidth('L'); }
|
||||
else { SetBandwidth('K'); }
|
||||
m_BandwidthLimit = limit; // set precise limit
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
#include "I2PEndian.h"
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <charconv>
|
||||
#include <boost/algorithm/string.hpp> // for boost::to_lower
|
||||
#ifndef __cpp_lib_atomic_shared_ptr
|
||||
#include <boost/atomic.hpp>
|
||||
@@ -106,8 +106,7 @@ namespace data
|
||||
// skip identity
|
||||
size_t identityLen = m_RouterIdentity->GetFullLen ();
|
||||
// read new RI
|
||||
std::stringstream str (std::string ((char *)buf + identityLen, len - identityLen));
|
||||
ReadFromStream (str);
|
||||
ReadFromBuffer (buf + identityLen, len - identityLen);
|
||||
if (!m_IsUnreachable)
|
||||
UpdateBuffer (buf, len); // save buffer
|
||||
// don't delete buffer until saved to the file
|
||||
@@ -195,39 +194,34 @@ namespace data
|
||||
}
|
||||
}
|
||||
// parse RI
|
||||
std::stringstream str;
|
||||
str.write ((const char *)m_Buffer->data () + identityLen, bufferLen - identityLen);
|
||||
ReadFromStream (str);
|
||||
if (!str)
|
||||
if (!ReadFromBuffer (m_Buffer->data () + identityLen, bufferLen - identityLen))
|
||||
{
|
||||
LogPrint (eLogError, "RouterInfo: Malformed message");
|
||||
m_IsUnreachable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RouterInfo::ReadFromStream (std::istream& s)
|
||||
bool RouterInfo::ReadFromBuffer (const uint8_t * buf, size_t len)
|
||||
{
|
||||
if (!s) return;
|
||||
if (len < 9) return false;
|
||||
m_Caps = 0; m_Congestion = eLowCongestion;
|
||||
s.read ((char *)&m_Timestamp, sizeof (m_Timestamp));
|
||||
m_Timestamp = be64toh (m_Timestamp);
|
||||
m_Timestamp = bufbe64toh (buf);
|
||||
size_t offset = 8; // timestamp
|
||||
// read addresses
|
||||
auto addresses = NewAddresses ();
|
||||
uint8_t numAddresses;
|
||||
s.read ((char *)&numAddresses, sizeof (numAddresses));
|
||||
uint8_t numAddresses = buf[offset]; offset++;
|
||||
for (int i = 0; i < numAddresses; i++)
|
||||
{
|
||||
if (offset + 9 > len) return false; // 1 byte cost + 8 bytes date
|
||||
uint8_t supportedTransports = 0;
|
||||
auto address = NewAddress ();
|
||||
uint8_t cost; // ignore
|
||||
s.read ((char *)&cost, sizeof (cost));
|
||||
s.read ((char *)&address->date, sizeof (address->date));
|
||||
offset++; // cost, ignore
|
||||
address->date = bufbe64toh (buf + offset); offset += 8; // date
|
||||
bool isHost = false, isStaticKey = false, isV2 = false, isIntroKey = false;
|
||||
char transportStyle[6];
|
||||
ReadString (transportStyle, 6, s);
|
||||
if (!strncmp (transportStyle, "NTCP", 4)) // NTCP or NTCP2
|
||||
auto transportStyle = ExtractString (buf + offset, len - offset); offset += transportStyle.length () + 1;
|
||||
if (!transportStyle.compare (0, 4, "NTCP")) // NTCP or NTCP2
|
||||
address->transportStyle = eTransportNTCP2;
|
||||
else if (!strncmp (transportStyle, "SSU", 3)) // SSU or SSU2
|
||||
else if (!transportStyle.compare (0, 3, "SSU")) // SSU or SSU2
|
||||
{
|
||||
address->transportStyle = eTransportSSU2;
|
||||
address->ssu.reset (new SSUExt ());
|
||||
@@ -237,24 +231,22 @@ namespace data
|
||||
address->transportStyle = eTransportUnknown;
|
||||
address->caps = 0;
|
||||
address->port = 0;
|
||||
uint16_t size, r = 0;
|
||||
s.read ((char *)&size, sizeof (size)); if (!s) return;
|
||||
size = be16toh (size);
|
||||
if (offset + 2 > len) return false;
|
||||
uint16_t size = bufbe16toh (buf + offset); offset += 2; // size
|
||||
if (offset + size >= len) return false;
|
||||
if (address->transportStyle == eTransportUnknown)
|
||||
{
|
||||
// skip unknown address
|
||||
s.seekg (size, std::ios_base::cur);
|
||||
if (s) continue; else return;
|
||||
offset += size;
|
||||
continue;
|
||||
}
|
||||
size_t r = 0;
|
||||
while (r < size)
|
||||
{
|
||||
char key[255], value[255];
|
||||
r += ReadString (key, 255, s);
|
||||
s.seekg (1, std::ios_base::cur); r++; // =
|
||||
r += ReadString (value, 255, s);
|
||||
s.seekg (1, std::ios_base::cur); r++; // ;
|
||||
if (!s) return;
|
||||
if (!strcmp (key, "host"))
|
||||
auto [key, value, sz] = ExtractParam (buf + offset, len - offset);
|
||||
r += sz; offset += sz;
|
||||
if (key.empty ()) continue;
|
||||
if (key == "host")
|
||||
{
|
||||
boost::system::error_code ecode;
|
||||
address->host = boost::asio::ip::make_address (value, ecode);
|
||||
@@ -268,63 +260,53 @@ namespace data
|
||||
address->transportStyle = eTransportUnknown;
|
||||
}
|
||||
}
|
||||
else if (!strcmp (key, "port"))
|
||||
else if (key == "port")
|
||||
{
|
||||
try
|
||||
{
|
||||
address->port = boost::lexical_cast<int>(value);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
LogPrint (eLogWarning, "RouterInfo: 'port' exception ", ex.what ());
|
||||
}
|
||||
auto res = std::from_chars(value.data(), value.data() + value.size(), address->port);
|
||||
if (res.ec != std::errc())
|
||||
LogPrint (eLogWarning, "RouterInfo: 'port' conversion error: ", std::make_error_code (res.ec).message ());
|
||||
}
|
||||
else if (!strcmp (key, "mtu"))
|
||||
else if (key == "mtu")
|
||||
{
|
||||
if (address->ssu)
|
||||
{
|
||||
try
|
||||
{
|
||||
address->ssu->mtu = boost::lexical_cast<int>(value);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
LogPrint (eLogWarning, "RouterInfo: 'mtu' exception ", ex.what ());
|
||||
}
|
||||
auto res = std::from_chars(value.data(), value.data() + value.size(), address->ssu->mtu);
|
||||
if (res.ec != std::errc())
|
||||
LogPrint (eLogWarning, "RouterInfo: 'mtu' conversion error: ", std::make_error_code (res.ec).message ());
|
||||
}
|
||||
else
|
||||
LogPrint (eLogWarning, "RouterInfo: Unexpected field 'mtu' for NTCP2");
|
||||
}
|
||||
else if (!strcmp (key, "caps"))
|
||||
else if (key == "caps")
|
||||
address->caps = ExtractAddressCaps (value);
|
||||
else if (!strcmp (key, "s")) // ntcp2 or ssu2 static key
|
||||
else if (key == "s") // ntcp2 or ssu2 static key
|
||||
{
|
||||
if (Base64ToByteStream (value, strlen (value), address->s, 32) == 32 &&
|
||||
if (Base64ToByteStream (value.data (), value.length (), address->s, 32) == 32 &&
|
||||
!(address->s[31] & 0x80)) // check if x25519 public key
|
||||
isStaticKey = true;
|
||||
else
|
||||
address->transportStyle = eTransportUnknown; // invalid address
|
||||
}
|
||||
else if (!strcmp (key, "i")) // ntcp2 iv or ssu2 intro
|
||||
else if (key == "i") // ntcp2 iv or ssu2 intro
|
||||
{
|
||||
if (address->IsNTCP2 ())
|
||||
{
|
||||
if (Base64ToByteStream (value, strlen (value), address->i, 16) == 16)
|
||||
if (Base64ToByteStream (value.data (), value.length (), address->i, 16) == 16)
|
||||
address->published = true; // presence of "i" means "published" NTCP2
|
||||
else
|
||||
address->transportStyle = eTransportUnknown; // invalid address
|
||||
}
|
||||
else if (address->IsSSU2 ())
|
||||
{
|
||||
if (Base64ToByteStream (value, strlen (value), address->i, 32) == 32)
|
||||
if (Base64ToByteStream (value.data (), value.length (), address->i, 32) == 32)
|
||||
isIntroKey = true;
|
||||
else
|
||||
address->transportStyle = eTransportUnknown; // invalid address
|
||||
}
|
||||
}
|
||||
else if (!strcmp (key, "v"))
|
||||
else if (key == "v")
|
||||
{
|
||||
if (!strcmp (value, "2"))
|
||||
if (value == "2")
|
||||
isV2 = true;
|
||||
else
|
||||
{
|
||||
@@ -340,13 +322,11 @@ namespace data
|
||||
LogPrint (eLogError, "RouterInfo: Introducer is presented for non-SSU address. Skipped");
|
||||
continue;
|
||||
}
|
||||
size_t l = strlen(key);
|
||||
unsigned char index = key[l-1] - '0'; // TODO:
|
||||
key[l-1] = 0;
|
||||
unsigned char index = key[key.length () - 1] - '0'; // TODO:
|
||||
if (index > 9)
|
||||
{
|
||||
LogPrint (eLogError, "RouterInfo: Unexpected introducer's index ", index, " skipped");
|
||||
if (s) continue; else return;
|
||||
continue;
|
||||
}
|
||||
if (index >= address->ssu->introducers.size ())
|
||||
{
|
||||
@@ -355,34 +335,23 @@ namespace data
|
||||
address->ssu->introducers.resize (index + 1);
|
||||
}
|
||||
Introducer& introducer = address->ssu->introducers.at (index);
|
||||
if (!strcmp (key, "itag"))
|
||||
auto key1 = key.substr(0, key.length () - 1);
|
||||
if (key1 == "itag")
|
||||
{
|
||||
try
|
||||
{
|
||||
introducer.iTag = boost::lexical_cast<uint32_t>(value);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
LogPrint (eLogWarning, "RouterInfo: 'itag' exception ", ex.what ());
|
||||
}
|
||||
auto res = std::from_chars(value.data(), value.data() + value.size(), introducer.iTag);
|
||||
if (res.ec != std::errc())
|
||||
LogPrint (eLogWarning, "RouterInfo: 'itag' conversion error: ", std::make_error_code (res.ec).message ());
|
||||
}
|
||||
else if (!strcmp (key, "ih"))
|
||||
Base64ToByteStream (value, strlen (value), introducer.iH, 32);
|
||||
else if (!strcmp (key, "iexp"))
|
||||
else if (key1 == "ih")
|
||||
Base64ToByteStream (value.data (), value.length (), introducer.iH, 32);
|
||||
else if (key1 == "iexp")
|
||||
{
|
||||
try
|
||||
{
|
||||
introducer.iExp = boost::lexical_cast<uint32_t>(value);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
LogPrint (eLogWarning, "RouterInfo: 'iexp' exception ", ex.what ());
|
||||
}
|
||||
auto res = std::from_chars(value.data(), value.data() + value.size(), introducer.iExp);
|
||||
if (res.ec != std::errc())
|
||||
LogPrint (eLogWarning, "RouterInfo: 'iexp' conversion error: ", std::make_error_code (res.ec).message ());
|
||||
}
|
||||
}
|
||||
if (!s) return;
|
||||
}
|
||||
|
||||
}
|
||||
if (address->transportStyle == eTransportNTCP2)
|
||||
{
|
||||
if (isStaticKey)
|
||||
@@ -446,45 +415,41 @@ namespace data
|
||||
boost::atomic_store (&m_Addresses, addresses);
|
||||
#endif
|
||||
// read peers
|
||||
uint8_t numPeers;
|
||||
s.read ((char *)&numPeers, sizeof (numPeers)); if (!s) return;
|
||||
s.seekg (numPeers*32, std::ios_base::cur); // TODO: read peers
|
||||
if (offset + 1 > len) return false;
|
||||
uint8_t numPeers = buf[offset]; offset++; // num peers
|
||||
offset += numPeers*32; // TODO: read peers
|
||||
// read properties
|
||||
if (offset + 2 > len) return false;
|
||||
m_Version = 0;
|
||||
bool isNetId = false;
|
||||
std::string family;
|
||||
uint16_t size, r = 0;
|
||||
s.read ((char *)&size, sizeof (size)); if (!s) return;
|
||||
size = be16toh (size);
|
||||
uint16_t size = bufbe16toh (buf + offset); offset += 2; // size
|
||||
if (offset + size > len) return false;
|
||||
size_t r = 0;
|
||||
while (r < size)
|
||||
{
|
||||
char key[255], value[255];
|
||||
r += ReadString (key, 255, s);
|
||||
s.seekg (1, std::ios_base::cur); r++; // =
|
||||
r += ReadString (value, 255, s);
|
||||
s.seekg (1, std::ios_base::cur); r++; // ;
|
||||
if (!s) return;
|
||||
auto [key, value, sz] = ExtractParam (buf + offset, len - offset);
|
||||
r += sz; offset += sz;
|
||||
if (key.empty ()) continue;
|
||||
SetProperty (key, value);
|
||||
|
||||
// extract caps
|
||||
if (!strcmp (key, "caps"))
|
||||
if (key == "caps")
|
||||
{
|
||||
ExtractCaps (value);
|
||||
m_IsFloodfill = IsDeclaredFloodfill ();
|
||||
}
|
||||
// extract version
|
||||
else if (!strcmp (key, ROUTER_INFO_PROPERTY_VERSION))
|
||||
else if (key == ROUTER_INFO_PROPERTY_VERSION)
|
||||
{
|
||||
m_Version = 0;
|
||||
char * ch = value;
|
||||
while (*ch)
|
||||
for (auto ch: value)
|
||||
{
|
||||
if (*ch >= '0' && *ch <= '9')
|
||||
if (ch >= '0' && ch <= '9')
|
||||
{
|
||||
m_Version *= 10;
|
||||
m_Version += (*ch - '0');
|
||||
m_Version += (ch - '0');
|
||||
}
|
||||
ch++;
|
||||
}
|
||||
if (m_Version < NETDB_MIN_PEER_TEST_VERSION && (m_SupportedTransports & (eSSU2V4 | eSSU2V6)))
|
||||
{
|
||||
@@ -497,24 +462,26 @@ namespace data
|
||||
}
|
||||
}
|
||||
// check netId
|
||||
else if (!strcmp (key, ROUTER_INFO_PROPERTY_NETID))
|
||||
else if (key == ROUTER_INFO_PROPERTY_NETID)
|
||||
{
|
||||
isNetId = true;
|
||||
if (atoi (value) != i2p::context.GetNetID ())
|
||||
int netID;
|
||||
auto res = std::from_chars(value.data(), value.data() + value.size(), netID);
|
||||
if (res.ec != std::errc() || netID != i2p::context.GetNetID ())
|
||||
{
|
||||
LogPrint (eLogError, "RouterInfo: Unexpected ", ROUTER_INFO_PROPERTY_NETID, "=", value);
|
||||
m_IsUnreachable = true;
|
||||
}
|
||||
}
|
||||
// family
|
||||
else if (!strcmp (key, ROUTER_INFO_PROPERTY_FAMILY))
|
||||
else if (key == ROUTER_INFO_PROPERTY_FAMILY)
|
||||
{
|
||||
family = value;
|
||||
boost::to_lower (family);
|
||||
}
|
||||
else if (!strcmp (key, ROUTER_INFO_PROPERTY_FAMILY_SIG))
|
||||
else if (key == ROUTER_INFO_PROPERTY_FAMILY_SIG)
|
||||
{
|
||||
if (netdb.GetFamilies ().VerifyFamily (family, GetIdentHash (), value))
|
||||
if (netdb.GetFamilies ().VerifyFamily (family, GetIdentHash (), value)) // TODO
|
||||
m_FamilyID = netdb.GetFamilies ().GetFamilyID (family);
|
||||
else
|
||||
{
|
||||
@@ -522,25 +489,24 @@ namespace data
|
||||
SetUnreachable (true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!s) return;
|
||||
}
|
||||
|
||||
if (!m_SupportedTransports || !isNetId || !m_Version)
|
||||
SetUnreachable (true);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RouterInfo::IsFamily (FamilyID famid) const
|
||||
{
|
||||
return m_FamilyID == famid;
|
||||
}
|
||||
|
||||
void RouterInfo::ExtractCaps (const char * value)
|
||||
void RouterInfo::ExtractCaps (std::string_view value)
|
||||
{
|
||||
const char * cap = value;
|
||||
while (*cap)
|
||||
for (auto cap: value)
|
||||
{
|
||||
switch (*cap)
|
||||
switch (cap)
|
||||
{
|
||||
case CAPS_FLAG_FLOODFILL:
|
||||
m_Caps |= Caps::eFloodfill;
|
||||
@@ -549,16 +515,16 @@ namespace data
|
||||
case CAPS_FLAG_LOW_BANDWIDTH2:
|
||||
case CAPS_FLAG_LOW_BANDWIDTH3:
|
||||
case CAPS_FLAG_LOW_BANDWIDTH4:
|
||||
m_BandwidthCap = *cap;
|
||||
m_BandwidthCap = cap;
|
||||
break;
|
||||
case CAPS_FLAG_HIGH_BANDWIDTH:
|
||||
m_Caps |= Caps::eHighBandwidth;
|
||||
m_BandwidthCap = *cap;
|
||||
m_BandwidthCap = cap;
|
||||
break;
|
||||
case CAPS_FLAG_EXTRA_BANDWIDTH1:
|
||||
case CAPS_FLAG_EXTRA_BANDWIDTH2:
|
||||
m_Caps |= Caps::eExtraBandwidth | Caps::eHighBandwidth;
|
||||
m_BandwidthCap = *cap;
|
||||
m_BandwidthCap = cap;
|
||||
break;
|
||||
case CAPS_FLAG_HIDDEN:
|
||||
m_Caps |= Caps::eHidden;
|
||||
@@ -580,17 +546,15 @@ namespace data
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
cap++;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t RouterInfo::ExtractAddressCaps (const char * value) const
|
||||
}
|
||||
|
||||
uint8_t RouterInfo::ExtractAddressCaps (std::string_view value) const
|
||||
{
|
||||
uint8_t caps = 0;
|
||||
const char * cap = value;
|
||||
while (*cap)
|
||||
for (auto cap: value)
|
||||
{
|
||||
switch (*cap)
|
||||
switch (cap)
|
||||
{
|
||||
case CAPS_FLAG_V4:
|
||||
caps |= AddressCaps::eV4;
|
||||
@@ -606,11 +570,10 @@ namespace data
|
||||
break;
|
||||
default: ;
|
||||
}
|
||||
cap++;
|
||||
}
|
||||
return caps;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void RouterInfo::UpdateIntroducers (std::shared_ptr<Address> address, uint64_t ts)
|
||||
{
|
||||
if (!address || !address->ssu) return;
|
||||
@@ -670,25 +633,41 @@ namespace data
|
||||
return SaveToFile (fullPath, m_Buffer);
|
||||
}
|
||||
|
||||
size_t RouterInfo::ReadString (char * str, size_t len, std::istream& s) const
|
||||
std::string_view RouterInfo::ExtractString (const uint8_t * buf, size_t len) const
|
||||
{
|
||||
uint8_t l;
|
||||
s.read ((char *)&l, 1);
|
||||
if (l < len)
|
||||
{
|
||||
s.read (str, l);
|
||||
if (!s) l = 0; // failed, return empty string
|
||||
str[l] = 0;
|
||||
}
|
||||
else
|
||||
uint8_t l = buf[0];
|
||||
if (l > len)
|
||||
{
|
||||
LogPrint (eLogWarning, "RouterInfo: String length ", (int)l, " exceeds buffer size ", len);
|
||||
s.seekg (l, std::ios::cur); // skip
|
||||
str[0] = 0;
|
||||
}
|
||||
return l+1;
|
||||
l = len;
|
||||
}
|
||||
return { (const char *)(buf + 1), l };
|
||||
}
|
||||
|
||||
std::tuple<std::string_view, std::string_view, size_t> RouterInfo::ExtractParam (const uint8_t * buf, size_t len) const
|
||||
{
|
||||
auto key = ExtractString (buf, len);
|
||||
size_t offset = key.length () + 1;
|
||||
if (offset >= len) return { std::string_view(), std::string_view(), len };
|
||||
if (buf[offset] != '=')
|
||||
{
|
||||
LogPrint (eLogWarning, "RouterInfo: Unexpected character ", buf[offset], " instead '=' after ", key);
|
||||
key = std::string_view();
|
||||
}
|
||||
offset++;
|
||||
if (offset >= len) return { key, std::string_view(), len };
|
||||
auto value = ExtractString (buf + offset, len - offset);
|
||||
offset += value.length () + 1;
|
||||
if (offset >= len) return { key, std::string_view(), len };
|
||||
if (buf[offset] != ';')
|
||||
{
|
||||
LogPrint (eLogWarning, "RouterInfo: Unexpected character ", buf[offset], " instead ';' after ", value);
|
||||
value = std::string_view();
|
||||
}
|
||||
offset++;
|
||||
return { key, value, offset };
|
||||
}
|
||||
|
||||
void RouterInfo::AddNTCP2Address (const uint8_t * staticKey, const uint8_t * iv,int port, uint8_t caps)
|
||||
{
|
||||
auto addr = std::make_shared<Address>();
|
||||
@@ -1402,9 +1381,9 @@ namespace data
|
||||
if (!introducer.iTag) continue;
|
||||
if (introducer.iExp) // expiration is specified
|
||||
{
|
||||
WriteString ("iexp" + boost::lexical_cast<std::string>(i), properties);
|
||||
WriteString ("iexp" + std::to_string(i), properties);
|
||||
properties << '=';
|
||||
WriteString (boost::lexical_cast<std::string>(introducer.iExp), properties);
|
||||
WriteString (std::to_string(introducer.iExp), properties);
|
||||
properties << ';';
|
||||
}
|
||||
i++;
|
||||
@@ -1413,7 +1392,7 @@ namespace data
|
||||
for (const auto& introducer: address.ssu->introducers)
|
||||
{
|
||||
if (!introducer.iTag) continue;
|
||||
WriteString ("ih" + boost::lexical_cast<std::string>(i), properties);
|
||||
WriteString ("ih" + std::to_string(i), properties);
|
||||
properties << '=';
|
||||
char value[64];
|
||||
size_t l = ByteStreamToBase64 (introducer.iH, 32, value, 64);
|
||||
@@ -1426,9 +1405,9 @@ namespace data
|
||||
for (const auto& introducer: address.ssu->introducers)
|
||||
{
|
||||
if (!introducer.iTag) continue;
|
||||
WriteString ("itag" + boost::lexical_cast<std::string>(i), properties);
|
||||
WriteString ("itag" + std::to_string(i), properties);
|
||||
properties << '=';
|
||||
WriteString (boost::lexical_cast<std::string>(introducer.iTag), properties);
|
||||
WriteString (std::to_string(introducer.iTag), properties);
|
||||
properties << ';';
|
||||
i++;
|
||||
}
|
||||
@@ -1442,7 +1421,7 @@ namespace data
|
||||
{
|
||||
WriteString ("mtu", properties);
|
||||
properties << '=';
|
||||
WriteString (boost::lexical_cast<std::string>(address.ssu->mtu), properties);
|
||||
WriteString (std::to_string(address.ssu->mtu), properties);
|
||||
properties << ';';
|
||||
}
|
||||
}
|
||||
@@ -1450,7 +1429,7 @@ namespace data
|
||||
{
|
||||
WriteString ("port", properties);
|
||||
properties << '=';
|
||||
WriteString (boost::lexical_cast<std::string>(address.port), properties);
|
||||
WriteString (std::to_string(address.port), properties);
|
||||
properties << ';';
|
||||
}
|
||||
if (address.IsNTCP2 () || address.IsSSU2 ())
|
||||
@@ -1485,9 +1464,11 @@ namespace data
|
||||
s.write (properties.str ().c_str (), properties.str ().size ());
|
||||
}
|
||||
|
||||
void LocalRouterInfo::SetProperty (const std::string& key, const std::string& value)
|
||||
void LocalRouterInfo::SetProperty (std::string_view key, std::string_view value)
|
||||
{
|
||||
m_Properties[key] = value;
|
||||
auto [it, inserted] = m_Properties.emplace (key, value);
|
||||
if (!inserted)
|
||||
it->second = value;
|
||||
}
|
||||
|
||||
void LocalRouterInfo::DeleteProperty (const std::string& key)
|
||||
|
||||
@@ -11,6 +11,8 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <tuple>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <array>
|
||||
@@ -219,7 +221,7 @@ namespace data
|
||||
std::string GetIdentHashBase64 () const { return GetIdentHash ().ToBase64 (); };
|
||||
uint64_t GetTimestamp () const { return m_Timestamp; };
|
||||
int GetVersion () const { return m_Version; };
|
||||
virtual void SetProperty (const std::string& key, const std::string& value) {};
|
||||
virtual void SetProperty (std::string_view key, std::string_view value) {};
|
||||
virtual void ClearProperties () {};
|
||||
AddressesPtr GetAddresses () const; // should be called for local RI only, otherwise must return shared_ptr
|
||||
std::shared_ptr<const Address> GetNTCP2V4Address () const;
|
||||
@@ -333,11 +335,12 @@ namespace data
|
||||
|
||||
bool LoadFile (const std::string& fullPath);
|
||||
void ReadFromFile (const std::string& fullPath);
|
||||
void ReadFromStream (std::istream& s);
|
||||
bool ReadFromBuffer (const uint8_t * buf, size_t len); // return false if malformed
|
||||
void ReadFromBuffer (bool verifySignature);
|
||||
size_t ReadString (char* str, size_t len, std::istream& s) const;
|
||||
void ExtractCaps (const char * value);
|
||||
uint8_t ExtractAddressCaps (const char * value) const;
|
||||
std::string_view ExtractString (const uint8_t * buf, size_t len) const;
|
||||
std::tuple<std::string_view, std::string_view, size_t> ExtractParam (const uint8_t * buf, size_t len) const;
|
||||
void ExtractCaps (std::string_view value);
|
||||
uint8_t ExtractAddressCaps (std::string_view value) const;
|
||||
void UpdateIntroducers (std::shared_ptr<Address> address, uint64_t ts);
|
||||
template<typename Filter>
|
||||
std::shared_ptr<const Address> GetAddress (Filter filter) const;
|
||||
@@ -379,7 +382,7 @@ namespace data
|
||||
void UpdateCaps (uint8_t caps);
|
||||
bool UpdateCongestion (Congestion c); // returns true if updated
|
||||
|
||||
void SetProperty (const std::string& key, const std::string& value) override;
|
||||
void SetProperty (std::string_view key, std::string_view value) override;
|
||||
void DeleteProperty (const std::string& key);
|
||||
std::string GetProperty (const std::string& key) const;
|
||||
void ClearProperties () override { m_Properties.clear (); };
|
||||
|
||||
@@ -1251,18 +1251,21 @@ namespace transport
|
||||
}
|
||||
uint64_t token;
|
||||
RAND_bytes ((uint8_t *)&token, 8);
|
||||
m_IncomingTokens.emplace (ep, std::make_pair (token, uint32_t(ts + SSU2_TOKEN_EXPIRATION_TIMEOUT)));
|
||||
if (!token) token = 1; // token can't be zero
|
||||
m_IncomingTokens.try_emplace (ep, token, uint32_t(ts + SSU2_TOKEN_EXPIRATION_TIMEOUT));
|
||||
return token;
|
||||
}
|
||||
|
||||
std::pair<uint64_t, uint32_t> SSU2Server::NewIncomingToken (const boost::asio::ip::udp::endpoint& ep)
|
||||
{
|
||||
m_IncomingTokens.erase (ep); // drop previous
|
||||
uint64_t token;
|
||||
RAND_bytes ((uint8_t *)&token, 8);
|
||||
auto ret = std::make_pair (token, uint32_t(i2p::util::GetSecondsSinceEpoch () + SSU2_NEXT_TOKEN_EXPIRATION_TIMEOUT));
|
||||
m_IncomingTokens.emplace (ep, ret);
|
||||
return ret;
|
||||
if (!token) token = 1; // token can't be zero
|
||||
uint32_t expires = i2p::util::GetSecondsSinceEpoch () + SSU2_NEXT_TOKEN_EXPIRATION_TIMEOUT;
|
||||
auto [it, inserted] = m_IncomingTokens.try_emplace (ep, token, expires);
|
||||
if (!inserted)
|
||||
it->second = { token, expires }; // override
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<SSU2Session> > SSU2Server::FindIntroducers (int maxNumIntroducers,
|
||||
|
||||
@@ -191,12 +191,7 @@ namespace transport
|
||||
|
||||
void SSU2PeerTestSession::SendPeerTest (uint8_t msg, const uint8_t * signedData, size_t signedDataLen, bool delayed)
|
||||
{
|
||||
#if __cplusplus >= 202002L // C++20
|
||||
m_SignedData.assign (signedData, signedData + signedDataLen);
|
||||
#else
|
||||
m_SignedData.resize (signedDataLen);
|
||||
memcpy (m_SignedData.data (), signedData, signedDataLen);
|
||||
#endif
|
||||
if (!delayed)
|
||||
SendPeerTest (msg);
|
||||
// schedule resend for msgs 5 or 6
|
||||
@@ -257,7 +252,7 @@ namespace transport
|
||||
{
|
||||
// we are Charlie
|
||||
uint64_t destConnID = htobe64 (((uint64_t)nonce << 32) | nonce); // dest id
|
||||
uint32_t sourceConnID = ~destConnID;
|
||||
uint64_t sourceConnID = ~destConnID;
|
||||
SetSourceConnID (sourceConnID);
|
||||
SetDestConnID (destConnID);
|
||||
SetState (eSSU2SessionStateHolePunch);
|
||||
@@ -313,12 +308,7 @@ namespace transport
|
||||
|
||||
void SSU2HolePunchSession::SendHolePunch (const uint8_t * relayResponseBlock, size_t relayResponseBlockLen)
|
||||
{
|
||||
#if __cplusplus >= 202002L // C++20
|
||||
m_RelayResponseBlock.assign (relayResponseBlock, relayResponseBlock + relayResponseBlockLen);
|
||||
#else
|
||||
m_RelayResponseBlock.resize (relayResponseBlockLen);
|
||||
memcpy (m_RelayResponseBlock.data (), relayResponseBlock, relayResponseBlockLen);
|
||||
#endif
|
||||
SendHolePunch ();
|
||||
ScheduleResend ();
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ namespace transport
|
||||
if (!asz) return false;
|
||||
payload[17] = asz;
|
||||
packet->payloadSize = asz + 18;
|
||||
SignedData s;
|
||||
SignedData<128> s;
|
||||
s.Insert ((const uint8_t *)"RelayRequestData", 16); // prologue
|
||||
s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
|
||||
s.Insert (session->GetRemoteIdentity ()->GetIdentHash (), 32); // chash
|
||||
@@ -1965,6 +1965,7 @@ namespace transport
|
||||
void SSU2Session::HandleRelayRequest (const uint8_t * buf, size_t len)
|
||||
{
|
||||
// we are Bob
|
||||
if (len < 9) return;
|
||||
auto mts = i2p::util::GetMillisecondsSinceEpoch ();
|
||||
uint32_t nonce = bufbe32toh (buf + 1); // nonce
|
||||
uint32_t relayTag = bufbe32toh (buf + 5); // relay tag
|
||||
@@ -1998,7 +1999,7 @@ namespace transport
|
||||
packet->payloadSize = r ? CreateRouterInfoBlock (packet->payload, m_MaxPayloadSize - len - 32, r) : 0;
|
||||
if (!packet->payloadSize && r)
|
||||
session->SendFragmentedMessage (CreateDatabaseStoreMsg (r));
|
||||
packet->payloadSize += CreateRelayIntroBlock (packet->payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize, buf + 1, len -1);
|
||||
packet->payloadSize += CreateRelayIntroBlock (packet->payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize, buf + 1, len - 1);
|
||||
if (packet->payloadSize < m_MaxPayloadSize)
|
||||
packet->payloadSize += CreatePaddingBlock (packet->payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize);
|
||||
uint32_t packetNum = session->SendData (packet->payload, packet->payloadSize);
|
||||
@@ -2013,18 +2014,24 @@ namespace transport
|
||||
void SSU2Session::HandleRelayIntro (const uint8_t * buf, size_t len, int attempts)
|
||||
{
|
||||
// we are Charlie
|
||||
if (len < 47) return;
|
||||
SSU2RelayResponseCode code = eSSU2RelayResponseCodeAccept;
|
||||
boost::asio::ip::udp::endpoint ep;
|
||||
std::shared_ptr<const i2p::data::RouterInfo::Address> addr;
|
||||
auto r = i2p::data::netdb.FindRouter (buf + 1); // Alice
|
||||
if (r)
|
||||
{
|
||||
SignedData s;
|
||||
SignedData<128> s;
|
||||
s.Insert ((const uint8_t *)"RelayRequestData", 16); // prologue
|
||||
s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
|
||||
s.Insert (i2p::context.GetIdentHash (), 32); // chash
|
||||
s.Insert (buf + 33, 14); // nonce, relay tag, timestamp, ver, asz
|
||||
uint8_t asz = buf[46];
|
||||
if (asz + 47 + r->GetIdentity ()->GetSignatureLen () > len)
|
||||
{
|
||||
LogPrint (eLogWarning, "SSU2: Malformed RelayIntro len=", len);
|
||||
return;
|
||||
}
|
||||
s.Insert (buf + 47, asz); // Alice Port, Alice IP
|
||||
if (s.Verify (r->GetIdentity (), buf + 47 + asz))
|
||||
{
|
||||
@@ -2113,6 +2120,7 @@ namespace transport
|
||||
|
||||
void SSU2Session::HandleRelayResponse (const uint8_t * buf, size_t len)
|
||||
{
|
||||
if (len < 6) return;
|
||||
uint32_t nonce = bufbe32toh (buf + 2);
|
||||
if (m_State == eSSU2SessionStateIntroduced)
|
||||
{
|
||||
@@ -2133,7 +2141,9 @@ namespace transport
|
||||
auto it = m_RelaySessions.find (nonce);
|
||||
if (it != m_RelaySessions.end ())
|
||||
{
|
||||
if (it->second.first && it->second.first->IsEstablished ())
|
||||
auto relaySession = it->second.first;
|
||||
m_RelaySessions.erase (it);
|
||||
if (relaySession && relaySession->IsEstablished ())
|
||||
{
|
||||
// we are Bob, message from Charlie
|
||||
auto packet = m_Server.GetSentPacketsPool ().AcquireShared ();
|
||||
@@ -2143,12 +2153,12 @@ namespace transport
|
||||
memcpy (payload + 3, buf, len); // forward to Alice as is
|
||||
packet->payloadSize = len + 3;
|
||||
packet->payloadSize += CreatePaddingBlock (payload + packet->payloadSize, m_MaxPayloadSize - packet->payloadSize);
|
||||
uint32_t packetNum = it->second.first->SendData (packet->payload, packet->payloadSize);
|
||||
uint32_t packetNum = relaySession->SendData (packet->payload, packet->payloadSize);
|
||||
if (m_RemoteVersion >= SSU2_MIN_RELAY_RESPONSE_RESEND_VERSION)
|
||||
{
|
||||
// sometimes Alice doesn't ack this RelayResponse in older versions
|
||||
packet->sendTime = i2p::util::GetMillisecondsSinceEpoch ();
|
||||
it->second.first->m_SentPackets.emplace (packetNum, packet);
|
||||
relaySession->m_SentPackets.emplace (packetNum, packet);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -2157,25 +2167,31 @@ namespace transport
|
||||
if (!buf[1]) // status code accepted?
|
||||
{
|
||||
// verify signature
|
||||
uint8_t csz = buf[11];
|
||||
SignedData s;
|
||||
uint8_t csz = (len >= 12) ? buf[11] : 0;
|
||||
if (csz + 12 + relaySession->GetRemoteIdentity ()->GetSignatureLen () > len)
|
||||
{
|
||||
LogPrint (eLogWarning, "SSU2: Malformed RelayResponse len=", len);
|
||||
relaySession->Done ();
|
||||
return;
|
||||
}
|
||||
SignedData<128> s;
|
||||
s.Insert ((const uint8_t *)"RelayAgreementOK", 16); // prologue
|
||||
s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
|
||||
s.Insert (buf + 2, 10 + csz); // nonce, timestamp, ver, csz and Charlie's endpoint
|
||||
if (s.Verify (it->second.first->GetRemoteIdentity (), buf + 12 + csz))
|
||||
if (s.Verify (relaySession->GetRemoteIdentity (), buf + 12 + csz))
|
||||
{
|
||||
if (it->second.first->m_State == eSSU2SessionStateIntroduced) // HolePunch not received yet
|
||||
if (relaySession->m_State == eSSU2SessionStateIntroduced) // HolePunch not received yet
|
||||
{
|
||||
// update Charlie's endpoint
|
||||
if (ExtractEndpoint (buf + 12, csz, it->second.first->m_RemoteEndpoint))
|
||||
if (ExtractEndpoint (buf + 12, csz, relaySession->m_RemoteEndpoint))
|
||||
{
|
||||
// update token
|
||||
uint64_t token;
|
||||
memcpy (&token, buf + len - 8, 8);
|
||||
m_Server.UpdateOutgoingToken (it->second.first->m_RemoteEndpoint,
|
||||
m_Server.UpdateOutgoingToken (relaySession->m_RemoteEndpoint,
|
||||
token, i2p::util::GetSecondsSinceEpoch () + SSU2_TOKEN_EXPIRATION_TIMEOUT);
|
||||
// connect to Charlie, HolePunch will be ignored
|
||||
it->second.first->ConnectAfterIntroduction ();
|
||||
relaySession->ConnectAfterIntroduction ();
|
||||
}
|
||||
else
|
||||
LogPrint (eLogWarning, "SSU2: RelayResponse can't extract endpoint");
|
||||
@@ -2184,16 +2200,15 @@ namespace transport
|
||||
else
|
||||
{
|
||||
LogPrint (eLogWarning, "SSU2: RelayResponse signature verification failed");
|
||||
it->second.first->Done ();
|
||||
relaySession->Done ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrint (eLogInfo, "SSU2: RelayResponse status code=", (int)buf[1], " nonce=", bufbe32toh (buf + 2));
|
||||
it->second.first->Done ();
|
||||
relaySession->Done ();
|
||||
}
|
||||
}
|
||||
m_RelaySessions.erase (it);
|
||||
}
|
||||
else
|
||||
LogPrint (eLogDebug, "SSU2: RelayResponse unknown nonce ", bufbe32toh (buf + 2));
|
||||
@@ -2262,10 +2277,13 @@ namespace transport
|
||||
case 2: // Charlie from Bob
|
||||
{
|
||||
// sign with Charlie's key
|
||||
if (len < offset + 9) return;
|
||||
uint8_t asz = buf[offset + 9];
|
||||
std::vector<uint8_t> newSignedData (asz + 10 + i2p::context.GetIdentity ()->GetSignatureLen ());
|
||||
size_t l = asz + 10 + i2p::context.GetIdentity ()->GetSignatureLen ();
|
||||
if (len < offset + l) return;
|
||||
std::vector<uint8_t> newSignedData (l);
|
||||
memcpy (newSignedData.data (), buf + offset, asz + 10);
|
||||
SignedData s;
|
||||
SignedData<128> s;
|
||||
s.Insert ((const uint8_t *)"PeerTestValidate", 16); // prologue
|
||||
s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
|
||||
s.Insert (buf + 3, 32); // ahash
|
||||
@@ -2373,10 +2391,16 @@ namespace transport
|
||||
if (GetRouterStatus () == eRouterStatusUnknown)
|
||||
SetTestingState (true);
|
||||
auto r = i2p::data::netdb.FindRouter (buf + 3); // find Charlie
|
||||
if (r)
|
||||
if (r && len >= offset + 9)
|
||||
{
|
||||
uint8_t asz = buf[offset + 9];
|
||||
SignedData s;
|
||||
if (len < offset + asz + 10 + r->GetIdentity ()->GetSignatureLen ())
|
||||
{
|
||||
LogPrint (eLogWarning, "Malformed PeerTest 4 len=", len);
|
||||
session->Done ();
|
||||
return;
|
||||
}
|
||||
SignedData<128> s;
|
||||
s.Insert ((const uint8_t *)"PeerTestValidate", 16); // prologue
|
||||
s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
|
||||
s.Insert (i2p::context.GetIdentity ()->GetIdentHash (), 32); // ahash
|
||||
@@ -2762,7 +2786,7 @@ namespace transport
|
||||
size_t SSU2Session::CreatePaddingBlock (uint8_t * buf, size_t len, size_t minSize)
|
||||
{
|
||||
if (len < 3 || len < minSize) return 0;
|
||||
size_t paddingSize = m_Server.GetRng ()() & 0x0F; // 0 - 15
|
||||
size_t paddingSize = m_Server.GetRng ()() & 0x1F; // 0 - 31
|
||||
if (paddingSize + 3 > len) paddingSize = len - 3;
|
||||
else if (paddingSize + 3 < minSize) paddingSize = minSize - 3;
|
||||
buf[0] = eSSU2BlkPadding;
|
||||
@@ -2864,7 +2888,7 @@ namespace transport
|
||||
LogPrint (eLogError, "SSU2: Buffer for RelayResponse signature is too small ", len);
|
||||
return 0;
|
||||
}
|
||||
SignedData s;
|
||||
SignedData<128> s;
|
||||
s.Insert ((const uint8_t *)"RelayAgreementOK", 16); // prologue
|
||||
if (code == eSSU2RelayResponseCodeAccept || code >= 64) // Charlie
|
||||
s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
|
||||
@@ -2926,7 +2950,7 @@ namespace transport
|
||||
size_t asz = CreateEndpoint (signedData + 10, 86, boost::asio::ip::udp::endpoint (localAddress->host, localAddress->port));
|
||||
signedData[9] = asz;
|
||||
// signature
|
||||
SignedData s;
|
||||
SignedData<128> s;
|
||||
s.Insert ((const uint8_t *)"PeerTestValidate", 16); // prologue
|
||||
s.Insert (GetRemoteIdentity ()->GetIdentHash (), 32); // bhash
|
||||
s.Insert (signedData, 10 + asz); // ver, nonce, ts, asz, Alice's endpoint
|
||||
|
||||
@@ -613,10 +613,8 @@ namespace stream
|
||||
if (wasInitial)
|
||||
ScheduleResend ();
|
||||
}
|
||||
if (m_IsClientChoked && ackThrough > m_DropWindowDelaySequenceNumber)
|
||||
{
|
||||
if (m_IsClientChoked && ackThrough >= m_DropWindowDelaySequenceNumber)
|
||||
m_IsClientChoked = false;
|
||||
}
|
||||
if (m_IsWinDropped && ackThrough > m_DropWindowDelaySequenceNumber)
|
||||
{
|
||||
m_IsFirstRttSample = true;
|
||||
@@ -1297,7 +1295,7 @@ namespace stream
|
||||
m_NumPacketsToSend = 1; m_PacingTimeRem = 0;
|
||||
}
|
||||
m_IsSendTime = true;
|
||||
if (m_WindowIncCounter && (m_WindowSize < MAX_WINDOW_SIZE || m_WindowDropTargetSize) && !m_SendBuffer.IsEmpty () && m_PacingTime > m_MinPacingTime)
|
||||
if (m_WindowIncCounter && (m_WindowSize < MAX_WINDOW_SIZE || m_WindowDropTargetSize) && !m_SendBuffer.IsEmpty () && m_PacingTime > m_MinPacingTime && m_RTT <= m_SlowRTT)
|
||||
{
|
||||
for (int i = 0; i < m_NumPacketsToSend; i++)
|
||||
{
|
||||
@@ -1307,7 +1305,7 @@ namespace stream
|
||||
{
|
||||
if (m_LastWindowDropSize && (m_LastWindowDropSize >= m_WindowDropTargetSize))
|
||||
m_WindowDropTargetSize += 1 - (1 / ((m_LastWindowDropSize + PREV_SPEED_KEEP_TIME_COEFF) / m_WindowDropTargetSize)); // some magic here
|
||||
else if (m_LastWindowDropSize && (m_LastWindowDropSize < m_WindowSize))
|
||||
else if (m_LastWindowDropSize && (m_LastWindowDropSize < m_WindowDropTargetSize))
|
||||
m_WindowDropTargetSize += (m_WindowDropTargetSize - (m_LastWindowDropSize - PREV_SPEED_KEEP_TIME_COEFF)) / m_WindowDropTargetSize; // some magic here
|
||||
else
|
||||
m_WindowDropTargetSize += (m_WindowDropTargetSize - (1 - PREV_SPEED_KEEP_TIME_COEFF)) / m_WindowDropTargetSize;
|
||||
@@ -1646,14 +1644,22 @@ namespace stream
|
||||
|
||||
void Stream::ProcessWindowDrop ()
|
||||
{
|
||||
if (m_WindowSize > m_LastWindowDropSize)
|
||||
{
|
||||
m_LastWindowDropSize = (m_LastWindowDropSize + m_WindowSize + m_WindowSizeTail) / 2;
|
||||
if (m_LastWindowDropSize > MAX_WINDOW_SIZE) m_LastWindowDropSize = MAX_WINDOW_SIZE;
|
||||
}
|
||||
if (m_WindowDropTargetSize)
|
||||
m_WindowDropTargetSize = (m_WindowDropTargetSize / 2) * 0.75; // congestion window size and -25% to drain queue
|
||||
else
|
||||
m_LastWindowDropSize = m_WindowSize;
|
||||
m_WindowDropTargetSize = m_LastWindowDropSize - (m_LastWindowDropSize / 4); // -25%;
|
||||
{
|
||||
if (m_WindowSize < m_LastWindowDropSize)
|
||||
{
|
||||
m_LastWindowDropSize = m_WindowSize - (m_LastWindowDropSize - m_WindowSize);
|
||||
if (m_LastWindowDropSize < MIN_WINDOW_SIZE) m_LastWindowDropSize = MIN_WINDOW_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_LastWindowDropSize = (m_LastWindowDropSize + m_WindowSize + m_WindowSizeTail) / 2;
|
||||
if (m_LastWindowDropSize > MAX_WINDOW_SIZE) m_LastWindowDropSize = MAX_WINDOW_SIZE;
|
||||
}
|
||||
m_WindowDropTargetSize = m_LastWindowDropSize * 0.75; // -25% to drain queue
|
||||
}
|
||||
if (m_WindowDropTargetSize < MIN_WINDOW_SIZE)
|
||||
m_WindowDropTargetSize = MIN_WINDOW_SIZE;
|
||||
m_WindowIncCounter = 0; // disable window growth
|
||||
|
||||
@@ -131,27 +131,35 @@ namespace tunnel
|
||||
|
||||
LogPrint (eLogDebug, "TransitTunnel: handle msg for endpoint ", GetTunnelID ());
|
||||
std::lock_guard<std::mutex> l(m_HandleMutex);
|
||||
m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg);
|
||||
if (!m_Endpoint) m_Endpoint = std::make_unique<TunnelEndpoint>(false); // transit endpoint is always outbound
|
||||
m_Endpoint->HandleDecryptedTunnelDataMsg (newMsg);
|
||||
}
|
||||
|
||||
void TransitTunnelEndpoint::FlushTunnelDataMsgs ()
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_HandleMutex);
|
||||
m_Endpoint.FlushI2NPMsgs ();
|
||||
if (m_Endpoint)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_HandleMutex);
|
||||
m_Endpoint->FlushI2NPMsgs ();
|
||||
}
|
||||
}
|
||||
|
||||
void TransitTunnelEndpoint::Cleanup ()
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_HandleMutex);
|
||||
m_Endpoint.Cleanup ();
|
||||
if (m_Endpoint)
|
||||
{
|
||||
std::lock_guard<std::mutex> l(m_HandleMutex);
|
||||
m_Endpoint->Cleanup ();
|
||||
}
|
||||
}
|
||||
|
||||
std::string TransitTunnelEndpoint::GetNextPeerName () const
|
||||
{
|
||||
auto hash = m_Endpoint.GetCurrentHash ();
|
||||
if (!m_Endpoint) return "";
|
||||
auto hash = m_Endpoint->GetCurrentHash ();
|
||||
if (hash)
|
||||
{
|
||||
const auto& sender = m_Endpoint.GetSender ();
|
||||
const auto& sender = m_Endpoint->GetSender ();
|
||||
if (sender)
|
||||
{
|
||||
auto transport = sender->GetCurrentTransport ();
|
||||
|
||||
@@ -97,20 +97,19 @@ namespace tunnel
|
||||
TransitTunnelEndpoint (uint32_t receiveTunnelID,
|
||||
const i2p::data::IdentHash& nextIdent, uint32_t nextTunnelID,
|
||||
const i2p::crypto::AESKey& layerKey, const i2p::crypto::AESKey& ivKey):
|
||||
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID, layerKey, ivKey),
|
||||
m_Endpoint (false) {}; // transit endpoint is always outbound
|
||||
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID, layerKey, ivKey) {};
|
||||
|
||||
void Cleanup () override;
|
||||
|
||||
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg) override;
|
||||
void FlushTunnelDataMsgs () override;
|
||||
size_t GetNumTransmittedBytes () const override { return m_Endpoint.GetNumReceivedBytes (); }
|
||||
size_t GetNumTransmittedBytes () const override { return m_Endpoint ? m_Endpoint->GetNumReceivedBytes () : 0; }
|
||||
std::string GetNextPeerName () const override;
|
||||
|
||||
private:
|
||||
|
||||
std::mutex m_HandleMutex;
|
||||
TunnelEndpoint m_Endpoint;
|
||||
std::unique_ptr<TunnelEndpoint> m_Endpoint;
|
||||
};
|
||||
|
||||
std::shared_ptr<TransitTunnel> CreateTransitTunnel (uint32_t receiveTunnelID,
|
||||
|
||||
@@ -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
|
||||
*
|
||||
@@ -10,7 +10,7 @@
|
||||
#define TRANSPORT_SESSION_H__
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
@@ -28,45 +28,51 @@ namespace transport
|
||||
const size_t IPV6_HEADER_SIZE = 40;
|
||||
const size_t UDP_HEADER_SIZE = 8;
|
||||
|
||||
template<size_t sz>
|
||||
class SignedData
|
||||
{
|
||||
public:
|
||||
|
||||
SignedData () {}
|
||||
SignedData (): m_Size(0) {}
|
||||
SignedData (const SignedData& other)
|
||||
{
|
||||
m_Stream << other.m_Stream.rdbuf ();
|
||||
m_Size = other.m_Size;
|
||||
memcpy (m_Buf, other.m_Buf, m_Size);
|
||||
}
|
||||
|
||||
void Reset ()
|
||||
{
|
||||
m_Stream.str("");
|
||||
m_Size = 0;
|
||||
}
|
||||
|
||||
void Insert (const uint8_t * buf, size_t len)
|
||||
size_t Insert (const uint8_t * buf, size_t len)
|
||||
{
|
||||
m_Stream.write ((char *)buf, len);
|
||||
if (m_Size + len > sz) len = sz - m_Size;
|
||||
memcpy (m_Buf + m_Size, buf, len);
|
||||
m_Size += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Insert (T t)
|
||||
{
|
||||
m_Stream.write ((char *)&t, sizeof (T));
|
||||
Insert ((const uint8_t *)&t, sizeof (T));
|
||||
}
|
||||
|
||||
bool Verify (std::shared_ptr<const i2p::data::IdentityEx> ident, const uint8_t * signature) const
|
||||
{
|
||||
return ident->Verify ((const uint8_t *)m_Stream.str ().c_str (), m_Stream.str ().size (), signature);
|
||||
return ident->Verify (m_Buf, m_Size, signature);
|
||||
}
|
||||
|
||||
void Sign (const i2p::data::PrivateKeys& keys, uint8_t * signature) const
|
||||
{
|
||||
keys.Sign ((const uint8_t *)m_Stream.str ().c_str (), m_Stream.str ().size (), signature);
|
||||
keys.Sign (m_Buf, m_Size, signature);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::stringstream m_Stream;
|
||||
uint8_t m_Buf[sz];
|
||||
size_t m_Size;
|
||||
};
|
||||
|
||||
const int64_t TRANSPORT_SESSION_SLOWNESS_THRESHOLD = 500; // in milliseconds
|
||||
|
||||
@@ -315,22 +315,28 @@ namespace tunnel
|
||||
void OutboundTunnel::SendTunnelDataMsgTo (const uint8_t * gwHash, uint32_t gwTunnel, std::shared_ptr<i2p::I2NPMessage> msg)
|
||||
{
|
||||
TunnelMessageBlock block;
|
||||
block.tunnelID = 0; // Initialize tunnelID to a default value
|
||||
|
||||
if (gwHash)
|
||||
{
|
||||
block.hash = gwHash;
|
||||
if (gwTunnel)
|
||||
{
|
||||
block.deliveryType = eDeliveryTypeTunnel;
|
||||
block.tunnelID = gwTunnel;
|
||||
block.tunnelID = gwTunnel; // Set tunnelID only if gwTunnel is non-zero
|
||||
}
|
||||
else
|
||||
{
|
||||
block.deliveryType = eDeliveryTypeRouter;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
block.deliveryType = eDeliveryTypeLocal;
|
||||
}
|
||||
|
||||
block.data = msg;
|
||||
|
||||
SendTunnelDataMsgs ({block});
|
||||
SendTunnelDataMsgs({block});
|
||||
}
|
||||
|
||||
void OutboundTunnel::SendTunnelDataMsgs (const std::vector<TunnelMessageBlock>& msgs)
|
||||
|
||||
@@ -351,10 +351,13 @@ namespace tunnel
|
||||
{
|
||||
it.second.first->SetState (eTunnelStateFailed);
|
||||
std::unique_lock<std::mutex> l(m_OutboundTunnelsMutex);
|
||||
if (m_OutboundTunnels.size () > 1 || m_NumOutboundTunnels <= 1) // don't fail last tunnel
|
||||
if (m_OutboundTunnels.size () > 1) // don't fail last tunnel
|
||||
m_OutboundTunnels.erase (it.second.first);
|
||||
else
|
||||
{
|
||||
it.second.first->SetState (eTunnelStateTestFailed);
|
||||
CreateOutboundTunnel (); // create new tunnel immediately because last one failed
|
||||
}
|
||||
}
|
||||
else if (it.second.first->GetState () != eTunnelStateExpiring)
|
||||
it.second.first->SetState (eTunnelStateTestFailed);
|
||||
@@ -368,13 +371,16 @@ namespace tunnel
|
||||
bool failed = false;
|
||||
{
|
||||
std::unique_lock<std::mutex> l(m_InboundTunnelsMutex);
|
||||
if (m_InboundTunnels.size () > 1 || m_NumInboundTunnels <= 1) // don't fail last tunnel
|
||||
if (m_InboundTunnels.size () > 1) // don't fail last tunnel
|
||||
{
|
||||
m_InboundTunnels.erase (it.second.second);
|
||||
failed = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
it.second.second->SetState (eTunnelStateTestFailed);
|
||||
CreateInboundTunnel (); // create new tunnel immediately because last one failed
|
||||
}
|
||||
}
|
||||
if (failed && m_LocalDestination)
|
||||
m_LocalDestination->SetLeaseSetUpdated (true);
|
||||
|
||||
@@ -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
|
||||
*
|
||||
@@ -16,6 +16,24 @@ namespace i2p
|
||||
{
|
||||
namespace client
|
||||
{
|
||||
void BOBI2PTunnelIncomingConnection::Established ()
|
||||
{
|
||||
if (m_IsQuiet)
|
||||
StreamReceive ();
|
||||
else
|
||||
{
|
||||
// send destination first like received from I2P
|
||||
std::string dest = GetStream ()->GetRemoteIdentity ()->ToBase64 ();
|
||||
dest += "\n";
|
||||
if (dest.size() <= I2P_TUNNEL_CONNECTION_BUFFER_SIZE)
|
||||
memcpy (GetStreamBuffer (), dest.c_str (), dest.size ());
|
||||
else
|
||||
memset (GetStreamBuffer (), 0, I2P_TUNNEL_CONNECTION_BUFFER_SIZE);
|
||||
HandleStreamReceive (boost::system::error_code (), dest.size ());
|
||||
}
|
||||
Receive ();
|
||||
}
|
||||
|
||||
BOBI2PInboundTunnel::BOBI2PInboundTunnel (const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr<ClientDestination> localDestination):
|
||||
BOBI2PTunnel (localDestination), m_Acceptor (localDestination->GetService (), ep)
|
||||
{
|
||||
@@ -156,7 +174,7 @@ namespace client
|
||||
{
|
||||
if (stream)
|
||||
{
|
||||
auto conn = std::make_shared<I2PTunnelConnection> (this, stream, m_Endpoint, m_IsQuiet);
|
||||
auto conn = std::make_shared<BOBI2PTunnelIncomingConnection> (this, stream, m_Endpoint, m_IsQuiet);
|
||||
AddHandler (conn);
|
||||
conn->Connect ();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
*
|
||||
@@ -71,6 +71,23 @@ namespace client
|
||||
const char BOB_HELP_STATUS[] = "status <NICKNAME> - Display status of a nicknamed tunnel.";
|
||||
const char BOB_HELP_HELP [] = "help <COMMAND> - Get help on a command.";
|
||||
|
||||
class BOBI2PTunnelIncomingConnection: public I2PTunnelConnection
|
||||
{
|
||||
public:
|
||||
|
||||
BOBI2PTunnelIncomingConnection (I2PService * owner, std::shared_ptr<i2p::stream::Stream> stream,
|
||||
const boost::asio::ip::tcp::endpoint& target, bool quiet):
|
||||
I2PTunnelConnection (owner, stream, target), m_IsQuiet (quiet) {};
|
||||
|
||||
protected:
|
||||
|
||||
void Established () override;
|
||||
|
||||
private:
|
||||
|
||||
bool m_IsQuiet; // don't send destination
|
||||
};
|
||||
|
||||
class BOBI2PTunnel: public I2PService
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -297,7 +297,7 @@ namespace client
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrint (eLogCritical, "Clients: Can't open file ", fullPath, " Creating new one with signature type ", sigType, " crypto type ", cryptoType);
|
||||
LogPrint (eLogInfo, "Clients: Can't open file ", fullPath, " Creating new one with signature type ", sigType, " crypto type ", cryptoType);
|
||||
keys = i2p::data::PrivateKeys::CreateRandomKeys (sigType, cryptoType, true);
|
||||
std::ofstream f (fullPath, std::ofstream::binary | std::ofstream::out);
|
||||
size_t len = keys.GetFullLen ();
|
||||
@@ -871,7 +871,7 @@ namespace client
|
||||
|
||||
}
|
||||
else
|
||||
LogPrint (eLogWarning, "Clients: Unknown section type = ", type, " of ", name, " in ", tunConf);
|
||||
LogPrint (eLogError, "Clients: Unknown section type = ", type, " of ", name, " in ", tunConf);
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
|
||||
@@ -29,13 +29,15 @@ namespace client
|
||||
const std::map<std::string, std::string>& params):
|
||||
LeaseSetDestination (service, isPublic, ¶ms),
|
||||
m_Owner (owner), m_Identity (identity), m_EncryptionKeyType (m_Identity->GetCryptoKeyType ()),
|
||||
m_IsCreatingLeaseSet (false), m_IsSameThread (isSameThread), m_LeaseSetCreationTimer (service)
|
||||
m_IsCreatingLeaseSet (false), m_IsSameThread (isSameThread),
|
||||
m_LeaseSetCreationTimer (service), m_ReadinessCheckTimer (service)
|
||||
{
|
||||
}
|
||||
|
||||
void I2CPDestination::Stop ()
|
||||
{
|
||||
m_LeaseSetCreationTimer.cancel ();
|
||||
m_ReadinessCheckTimer.cancel ();
|
||||
LeaseSetDestination::Stop ();
|
||||
m_Owner = nullptr;
|
||||
}
|
||||
@@ -88,7 +90,7 @@ namespace client
|
||||
|
||||
void I2CPDestination::CreateNewLeaseSet (const std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> >& tunnels)
|
||||
{
|
||||
boost::asio::post (GetService (), std::bind (&I2CPDestination::PostCreateNewLeaseSet, this, tunnels));
|
||||
boost::asio::post (GetService (), std::bind (&I2CPDestination::PostCreateNewLeaseSet, GetSharedFromThis (), tunnels));
|
||||
}
|
||||
|
||||
void I2CPDestination::PostCreateNewLeaseSet (std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels)
|
||||
@@ -98,6 +100,20 @@ namespace client
|
||||
LogPrint (eLogInfo, "I2CP: LeaseSet is being created");
|
||||
return;
|
||||
}
|
||||
m_ReadinessCheckTimer.cancel ();
|
||||
auto pool = GetTunnelPool ();
|
||||
if (!pool || pool->GetOutboundTunnels ().empty ())
|
||||
{
|
||||
// try again later
|
||||
m_ReadinessCheckTimer.expires_from_now (boost::posix_time::seconds(I2CP_DESTINATION_READINESS_CHECK_INTERVAL));
|
||||
m_ReadinessCheckTimer.async_wait(
|
||||
[s=GetSharedFromThis (), tunnels=std::move(tunnels)](const boost::system::error_code& ecode)
|
||||
{
|
||||
if (ecode != boost::asio::error::operation_aborted)
|
||||
s->PostCreateNewLeaseSet (tunnels);
|
||||
});
|
||||
return;
|
||||
}
|
||||
uint8_t priv[256] = {0};
|
||||
i2p::data::LocalLeaseSet ls (m_Identity, priv, tunnels); // we don't care about encryption key, we need leases only
|
||||
m_LeaseSetExpirationTime = ls.GetExpirationTime ();
|
||||
@@ -555,7 +571,7 @@ namespace client
|
||||
m_IsSending = false;
|
||||
}
|
||||
|
||||
std::string_view I2CPSession::ExtractString (const uint8_t * buf, size_t len)
|
||||
std::string_view I2CPSession::ExtractString (const uint8_t * buf, size_t len) const
|
||||
{
|
||||
uint8_t l = buf[0];
|
||||
if (l > len) l = len;
|
||||
@@ -572,7 +588,7 @@ namespace client
|
||||
return l + 1;
|
||||
}
|
||||
|
||||
void I2CPSession::ExtractMapping (const uint8_t * buf, size_t len, std::map<std::string, std::string>& mapping)
|
||||
void I2CPSession::ExtractMapping (const uint8_t * buf, size_t len, std::map<std::string, std::string>& mapping) const
|
||||
// TODO: move to Base.cpp
|
||||
{
|
||||
size_t offset = 0;
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace client
|
||||
const size_t I2CP_MAX_MESSAGE_LENGTH = 65535;
|
||||
const size_t I2CP_MAX_SEND_QUEUE_SIZE = 1024*1024; // in bytes, 1M
|
||||
const int I2CP_LEASESET_CREATION_TIMEOUT = 10; // in seconds
|
||||
const int I2CP_DESTINATION_READINESS_CHECK_INTERVAL = 5; // in seconds
|
||||
const int I2CP_SESSION_ACK_REQUEST_INTERVAL = 12100; // in milliseconds
|
||||
|
||||
const size_t I2CP_HEADER_LENGTH_OFFSET = 0;
|
||||
@@ -131,7 +132,7 @@ namespace client
|
||||
uint8_t m_ECIESx25519PrivateKey[32];
|
||||
uint64_t m_LeaseSetExpirationTime;
|
||||
bool m_IsCreatingLeaseSet, m_IsSameThread;
|
||||
boost::asio::deadline_timer m_LeaseSetCreationTimer;
|
||||
boost::asio::deadline_timer m_LeaseSetCreationTimer, m_ReadinessCheckTimer;
|
||||
i2p::util::MemoryPoolMt<I2NPMessageBuffer<I2NP_MAX_MESSAGE_SIZE> > m_I2NPMsgsPool;
|
||||
};
|
||||
|
||||
@@ -193,9 +194,9 @@ namespace client
|
||||
|
||||
void HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||
|
||||
std::string_view ExtractString (const uint8_t * buf, size_t len);
|
||||
std::string_view ExtractString (const uint8_t * buf, size_t len) const;
|
||||
size_t PutString (uint8_t * buf, size_t len, std::string_view str);
|
||||
void ExtractMapping (const uint8_t * buf, size_t len, std::map<std::string, std::string>& mapping);
|
||||
void ExtractMapping (const uint8_t * buf, size_t len, std::map<std::string, std::string>& mapping) const;
|
||||
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
|
||||
*
|
||||
@@ -32,8 +32,7 @@ namespace client
|
||||
|
||||
I2PTunnelConnection::I2PTunnelConnection (I2PService * owner, std::shared_ptr<boost::asio::ip::tcp::socket> socket,
|
||||
std::shared_ptr<const i2p::data::LeaseSet> leaseSet, uint16_t port):
|
||||
I2PServiceHandler(owner), m_Socket (socket), m_RemoteEndpoint (socket->remote_endpoint ()),
|
||||
m_IsQuiet (true)
|
||||
I2PServiceHandler(owner), m_Socket (socket), m_RemoteEndpoint (socket->remote_endpoint ())
|
||||
{
|
||||
m_Stream = GetOwner()->GetLocalDestination ()->CreateStream (leaseSet, port);
|
||||
}
|
||||
@@ -41,14 +40,13 @@ namespace client
|
||||
I2PTunnelConnection::I2PTunnelConnection (I2PService * owner,
|
||||
std::shared_ptr<boost::asio::ip::tcp::socket> socket, std::shared_ptr<i2p::stream::Stream> stream):
|
||||
I2PServiceHandler(owner), m_Socket (socket), m_Stream (stream),
|
||||
m_RemoteEndpoint (socket->remote_endpoint ()), m_IsQuiet (true)
|
||||
m_RemoteEndpoint (socket->remote_endpoint ())
|
||||
{
|
||||
}
|
||||
|
||||
I2PTunnelConnection::I2PTunnelConnection (I2PService * owner, std::shared_ptr<i2p::stream::Stream> stream,
|
||||
const boost::asio::ip::tcp::endpoint& target, bool quiet,
|
||||
std::shared_ptr<boost::asio::ssl::context> sslCtx):
|
||||
I2PServiceHandler(owner), m_Stream (stream), m_RemoteEndpoint (target), m_IsQuiet (quiet)
|
||||
const boost::asio::ip::tcp::endpoint& target,std::shared_ptr<boost::asio::ssl::context> sslCtx):
|
||||
I2PServiceHandler(owner), m_Stream (stream), m_RemoteEndpoint (target)
|
||||
{
|
||||
m_Socket = std::make_shared<boost::asio::ip::tcp::socket> (owner->GetService ());
|
||||
if (sslCtx)
|
||||
@@ -292,18 +290,7 @@ namespace client
|
||||
|
||||
void I2PTunnelConnection::Established ()
|
||||
{
|
||||
if (m_IsQuiet)
|
||||
StreamReceive ();
|
||||
else
|
||||
{
|
||||
// send destination first like received from I2P
|
||||
std::string dest = m_Stream->GetRemoteIdentity ()->ToBase64 ();
|
||||
dest += "\n";
|
||||
if(sizeof(m_StreamBuffer) >= dest.size()) {
|
||||
memcpy (m_StreamBuffer, dest.c_str (), dest.size ());
|
||||
}
|
||||
HandleStreamReceive (boost::system::error_code (), dest.size ());
|
||||
}
|
||||
StreamReceive ();
|
||||
Receive ();
|
||||
}
|
||||
|
||||
@@ -377,7 +364,7 @@ namespace client
|
||||
I2PServerTunnelConnectionHTTP::I2PServerTunnelConnectionHTTP (I2PService * owner, std::shared_ptr<i2p::stream::Stream> stream,
|
||||
const boost::asio::ip::tcp::endpoint& target, const std::string& host, const std::string& XI2P,
|
||||
std::shared_ptr<boost::asio::ssl::context> sslCtx):
|
||||
I2PTunnelConnection (owner, stream, target, true, sslCtx), m_Host (host), m_XI2P (XI2P),
|
||||
I2PTunnelConnection (owner, stream, target, sslCtx), m_Host (host), m_XI2P (XI2P),
|
||||
m_HeaderSent (false), m_ResponseHeaderSent (false)
|
||||
{
|
||||
if (sslCtx)
|
||||
@@ -528,7 +515,7 @@ namespace client
|
||||
I2PTunnelConnectionIRC::I2PTunnelConnectionIRC (I2PService * owner, std::shared_ptr<i2p::stream::Stream> stream,
|
||||
const boost::asio::ip::tcp::endpoint& target, const std::string& webircpass,
|
||||
std::shared_ptr<boost::asio::ssl::context> sslCtx):
|
||||
I2PTunnelConnection (owner, stream, target, true, sslCtx), m_From (stream->GetRemoteIdentity ()),
|
||||
I2PTunnelConnection (owner, stream, target, sslCtx), m_From (stream->GetRemoteIdentity ()),
|
||||
m_NeedsWebIrc (webircpass.length() ? true : false), m_WebircPass (webircpass)
|
||||
{
|
||||
}
|
||||
@@ -857,7 +844,7 @@ namespace client
|
||||
|
||||
std::shared_ptr<I2PTunnelConnection> I2PServerTunnel::CreateI2PConnection (std::shared_ptr<i2p::stream::Stream> stream)
|
||||
{
|
||||
return std::make_shared<I2PTunnelConnection> (this, stream, GetEndpoint (), true, m_SSLCtx);
|
||||
return std::make_shared<I2PTunnelConnection> (this, stream, GetEndpoint (), m_SSLCtx);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
*
|
||||
@@ -27,7 +27,7 @@ namespace i2p
|
||||
{
|
||||
namespace client
|
||||
{
|
||||
const size_t I2P_TUNNEL_CONNECTION_BUFFER_SIZE = 65536;
|
||||
const size_t I2P_TUNNEL_CONNECTION_BUFFER_SIZE = 16384;
|
||||
const int I2P_TUNNEL_CONNECTION_MAX_IDLE = 3600; // in seconds
|
||||
const int I2P_TUNNEL_DESTINATION_REQUEST_TIMEOUT = 10; // in seconds
|
||||
// for HTTP tunnels
|
||||
@@ -45,7 +45,7 @@ namespace client
|
||||
I2PTunnelConnection (I2PService * owner, std::shared_ptr<boost::asio::ip::tcp::socket> socket,
|
||||
std::shared_ptr<i2p::stream::Stream> stream); // to I2P using simplified API
|
||||
I2PTunnelConnection (I2PService * owner, std::shared_ptr<i2p::stream::Stream> stream,
|
||||
const boost::asio::ip::tcp::endpoint& target, bool quiet = true,
|
||||
const boost::asio::ip::tcp::endpoint& target,
|
||||
std::shared_ptr<boost::asio::ssl::context> sslCtx = nullptr); // from I2P
|
||||
~I2PTunnelConnection ();
|
||||
void I2PConnect (const uint8_t * msg = nullptr, size_t len = 0);
|
||||
@@ -54,25 +54,27 @@ namespace client
|
||||
|
||||
protected:
|
||||
|
||||
virtual void Established ();
|
||||
void Terminate ();
|
||||
|
||||
void Receive ();
|
||||
void StreamReceive ();
|
||||
void HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||
virtual void Write (const uint8_t * buf, size_t len); // can be overloaded
|
||||
virtual void WriteToStream (const uint8_t * buf, size_t len); // can be overloaded
|
||||
|
||||
std::shared_ptr<boost::asio::ip::tcp::socket> GetSocket () const { return m_Socket; };
|
||||
std::shared_ptr<i2p::stream::Stream> GetStream () const { return m_Stream; };
|
||||
std::shared_ptr<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&> > GetSSL () const { return m_SSL; };
|
||||
|
||||
uint8_t * GetStreamBuffer () { return m_StreamBuffer; };
|
||||
|
||||
private:
|
||||
|
||||
void HandleConnect (const boost::system::error_code& ecode);
|
||||
void HandleHandshake (const boost::system::error_code& ecode);
|
||||
void Established ();
|
||||
void HandleReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||
void HandleWrite (const boost::system::error_code& ecode);
|
||||
void HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
uint8_t m_Buffer[I2P_TUNNEL_CONNECTION_BUFFER_SIZE], m_StreamBuffer[I2P_TUNNEL_CONNECTION_BUFFER_SIZE];
|
||||
@@ -80,7 +82,6 @@ namespace client
|
||||
std::shared_ptr<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&> > m_SSL;
|
||||
std::shared_ptr<i2p::stream::Stream> m_Stream;
|
||||
boost::asio::ip::tcp::endpoint m_RemoteEndpoint;
|
||||
bool m_IsQuiet; // don't send destination
|
||||
};
|
||||
|
||||
class I2PClientTunnelConnectionHTTP: public I2PTunnelConnection
|
||||
@@ -94,7 +95,7 @@ namespace client
|
||||
|
||||
protected:
|
||||
|
||||
void Write (const uint8_t * buf, size_t len);
|
||||
void Write (const uint8_t * buf, size_t len) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -112,8 +113,8 @@ namespace client
|
||||
|
||||
protected:
|
||||
|
||||
void Write (const uint8_t * buf, size_t len);
|
||||
void WriteToStream (const uint8_t * buf, size_t len);
|
||||
void Write (const uint8_t * buf, size_t len) override;
|
||||
void WriteToStream (const uint8_t * buf, size_t len) override;
|
||||
|
||||
private:
|
||||
|
||||
@@ -132,7 +133,7 @@ namespace client
|
||||
|
||||
protected:
|
||||
|
||||
void Write (const uint8_t * buf, size_t len);
|
||||
void Write (const uint8_t * buf, size_t len) override;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user