16 #include <boost/test/unit_test.hpp>
26 const std::vector<const char*>& extra_args = {})
55 const std::optional<CService> addr{
Lookup(
"127.0.0.1", 9000,
false)};
56 const Proxy sam_proxy(addr.value(),
false);
71 size_t num_sockets{0};
72 CreateSock = [&num_sockets](
const sa_family_t&) {
76 if (num_sockets == 1) {
77 return std::make_unique<StaticContentsSock>(
79 "HELLO REPLY RESULT=OK VERSION=3.1\n"
81 "DEST REPLY PUB=WnGOLXRBqHQhdVjFlWqRxJwz9hxx~2~wGc2Vplta1KhacY4tdEGodCF1WMWVapHEnDP2HHH~b~AZzZWmW1rUqFpxji10Qah0IXVYxZVqkcScM~Yccf9v8BnNlaZbWtSoWnGOLXRBqHQhdVjFlWqRxJwz9hxx~2~wGc2Vplta1KhacY4tdEGodCF1WMWVapHEnDP2HHH~b~AZzZWmW1rUqFpxji10Qah0IXVYxZVqkcScM~Yccf9v8BnNlaZbWtSoWnGOLXRBqHQhdVjFlWqRxJwz9hxx~2~wGc2Vplta1KhacY4tdEGodCF1WMWVapHEnDP2HHH~b~AZzZWmW1rUqFpxji10Qah0IXVYxZVqkcScM~Yccf9v8BnNlaZbWtSoWnGOLXRBqHQhdVjFlWqRxJwz9hxx~2~wGc2Vplta1KhacY4tdEGodCF1WMWVapHEnDP2HHH~b~AZzZWmW1rUqLE4SD-yjT48UNI7qiTUfIPiDitCoiTTz2cr4QGfw89rBQAEAAcAAA== PRIV=WnGOLXRBqHQhdVjFlWqRxJwz9hxx~2~wGc2Vplta1KhacY4tdEGodCF1WMWVapHEnDP2HHH~b~AZzZWmW1rUqFpxji10Qah0IXVYxZVqkcScM~Yccf9v8BnNlaZbWtSoWnGOLXRBqHQhdVjFlWqRxJwz9hxx~2~wGc2Vplta1KhacY4tdEGodCF1WMWVapHEnDP2HHH~b~AZzZWmW1rUqFpxji10Qah0IXVYxZVqkcScM~Yccf9v8BnNlaZbWtSoWnGOLXRBqHQhdVjFlWqRxJwz9hxx~2~wGc2Vplta1KhacY4tdEGodCF1WMWVapHEnDP2HHH~b~AZzZWmW1rUqFpxji10Qah0IXVYxZVqkcScM~Yccf9v8BnNlaZbWtSoWnGOLXRBqHQhdVjFlWqRxJwz9hxx~2~wGc2Vplta1KhacY4tdEGodCF1WMWVapHEnDP2HHH~b~AZzZWmW1rUqLE4SD-yjT48UNI7qiTUfIPiDitCoiTTz2cr4QGfw89rBQAEAAcAAOvuCIKTyv5f~1QgGq7XQl-IqBULTB5WzB3gw5yGPtd1p0AeoADrq1ccZggLPQ4ZLUsGK-HVw373rcTfvxrcuwenqVjiN4tbbYLWtP7xXGWj6fM6HyORhU63GphrjEePpMUHDHXd3o7pWGM-ieVVQSK~1MzF9P93pQWI3Do52EeNAayz4HbpPjNhVBzG1hUEFwznfPmUZBPuaOR4-uBm1NEWEuONlNOCctE4-U0Ukh94z-Qb55U5vXjR5G4apmBblr68t6Wm1TKlzpgFHzSqLryh3stWqrOKY1H0z9eZ2z1EkHFOpD5LyF6nf51e-lV7HLMl44TYzoEHK8RRVodtLcW9lacVdBpv~tOzlZERIiDziZODPETENZMz5oy9DQ7UUw==\n"
83 "SESSION STATUS RESULT=OK\n"
89 if (num_sockets % 2 == 0) {
91 return std::make_unique<StaticContentsSock>(
93 "HELLO REPLY RESULT=OK VERSION=3.1\n"
95 "STREAM STATUS RESULT=OK\n"
100 "STREAM STATUS RESULT=I2P_ERROR MESSAGE=\"Session was closed\"\n"
104 return std::make_unique<StaticContentsSock>(
106 "HELLO REPLY RESULT=OK VERSION=3.1\n"
108 "SESSION STATUS RESULT=OK\n"
117 const CService addr{in6_addr(IN6ADDR_LOOPBACK_INIT), 7656};
118 const Proxy sam_proxy(addr,
false);
124 for (
size_t i = 0; i < 5; ++i) {
129 BOOST_REQUIRE(session.
Listen(conn));
130 BOOST_REQUIRE(!session.
Accept(conn));
139 return std::make_unique<StaticContentsSock>(
"HELLO REPLY RESULT=OK VERSION=3.1\n"
140 "SESSION STATUS RESULT=OK DESTINATION=\n");
143 const auto i2p_private_key_file = m_args.GetDataDirNet() /
"test_i2p_private_key_damaged";
145 for (
const auto& [file_contents, expected_error] : std::vector<std::tuple<std::string, std::string>>{
146 {
"",
"The private key is too short (0 < 387)"},
148 {
"abcd",
"The private key is too short (4 < 387)"},
150 {std::string(386,
'\0'),
"The private key is too short (386 < 387)"},
152 {std::string(385,
'\0') +
'\0' +
'\1',
153 "Certificate length (1) designates that the private key should be 388 bytes, but it is only "
156 {std::string(385,
'\0') +
'\0' +
'\5' +
"abcd",
157 "Certificate length (5) designates that the private key should be 392 bytes, but it is only "
162 const CService addr{in6_addr(IN6ADDR_LOOPBACK_INIT), 7656};
163 const Proxy sam_proxy{addr,
false};
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
void SetLogLevel(Level level)
A combination of a network address (CNetAddr) and a (TCP) port.
A helper class for interruptible sleeps.
Save the log level and the value of CreateSock and restore them when the test ends.
EnvTestingSetup(const ChainType chainType=ChainType::MAIN, const std::vector< const char * > &extra_args={})
const BCLog::Level m_prev_log_level
const std::function< std::unique_ptr< Sock >const sa_family_t &)> m_create_sock_orig
bool Listen(Connection &conn) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Start listening for an incoming connection.
bool Connect(const CService &to, Connection &conn, bool &proxy_error) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Connect to an I2P peer.
bool Accept(Connection &conn) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Wait for and accept a new incoming connection.
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(unlimited_recv)
BCLog::Logger & LogInstance()
static constexpr size_t MAX_MSG_SIZE
The maximum size of an incoming message from the I2P SAM proxy (in bytes).
std::vector< CService > Lookup(const std::string &name, uint16_t portDefault, bool fAllowLookup, unsigned int nMaxSolutions, DNSLookupFn dns_lookup_function)
Resolve a service string to its corresponding service.
std::function< std::unique_ptr< Sock >const sa_family_t &)> CreateSock
Socket factory.
#define BOOST_CHECK(expr)
bool WriteBinaryFile(const fs::path &filename, const std::string &data)
Write contents of std::string to a file.
An established connection with another peer.
#define ASSERT_DEBUG_LOG(message)