Bitcoin Core  24.99.0
P2P Digital Currency
i2p_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2021-2022 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <i2p.h>
6 #include <logging.h>
7 #include <netaddress.h>
8 #include <test/util/logging.h>
9 #include <test/util/net.h>
10 #include <test/util/setup_common.h>
11 #include <util/system.h>
12 #include <util/threadinterrupt.h>
13 
14 #include <boost/test/unit_test.hpp>
15 
16 #include <memory>
17 #include <string>
18 
19 BOOST_FIXTURE_TEST_SUITE(i2p_tests, BasicTestingSetup)
20 
21 BOOST_AUTO_TEST_CASE(unlimited_recv)
22 {
23  const auto prev_log_level{LogInstance().LogLevel()};
25  auto CreateSockOrig = CreateSock;
26 
27  // Mock CreateSock() to create MockSock.
28  CreateSock = [](const CService&) {
29  return std::make_unique<StaticContentsSock>(std::string(i2p::sam::MAX_MSG_SIZE + 1, 'a'));
30  };
31 
32  CThreadInterrupt interrupt;
33  i2p::sam::Session session(gArgs.GetDataDirNet() / "test_i2p_private_key", CService{}, &interrupt);
34 
35  {
36  ASSERT_DEBUG_LOG("Creating persistent SAM session");
37  ASSERT_DEBUG_LOG("too many bytes without a terminator");
38 
39  i2p::Connection conn;
40  bool proxy_error;
41  BOOST_REQUIRE(!session.Connect(CService{}, conn, proxy_error));
42  }
43 
44  CreateSock = CreateSockOrig;
45  LogInstance().SetLogLevel(prev_log_level);
46 }
47 
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
Definition: system.h:289
void SetLogLevel(Level level)
Definition: logging.h:171
Level LogLevel() const
Definition: logging.h:170
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:520
I2P SAM session.
Definition: i2p.h:56
bool Connect(const CService &to, Connection &conn, bool &proxy_error) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Connect to an I2P peer.
Definition: i2p.cpp:184
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(unlimited_recv)
Definition: i2p_tests.cpp:21
BCLog::Logger & LogInstance()
Definition: logging.cpp:20
static constexpr size_t MAX_MSG_SIZE
The maximum size of an incoming message from the I2P SAM proxy (in bytes).
Definition: i2p.h:50
std::function< std::unique_ptr< Sock >const CService &)> CreateSock
Socket factory.
Definition: netbase.cpp:534
Basic testing setup.
Definition: setup_common.h:79
An established connection with another peer.
Definition: i2p.h:31
#define ASSERT_DEBUG_LOG(message)
Definition: logging.h:39
ArgsManager gArgs
Definition: system.cpp:73