diff --git a/CMakeLists.txt b/CMakeLists.txt index 30f4eeda3..b4b8c8089 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1201,6 +1201,7 @@ endif() if(NOT ZMQ_LIB) message(FATAL_ERROR "Could not find required libzmq") endif() +include_directories(${ZMQ_INCLUDE_PATH}) if(PGM_LIBRARY) set(ZMQ_LIB "${ZMQ_LIB};${PGM_LIBRARY}") endif() @@ -1214,7 +1215,15 @@ if(PROTOLIB_LIBRARY) set(ZMQ_LIB "${ZMQ_LIB};${PROTOLIB_LIBRARY}") endif() if(SODIUM_LIBRARY) + message(STATUS "ZMQ_LIB: ${ZMQ_LIB};${SODIUM_LIBRARY}") set(ZMQ_LIB "${ZMQ_LIB};${SODIUM_LIBRARY}") + find_path(SODIUM_INCLUDE_PATH sodium/crypto_verify_32.h) + if (SODIUM_INCLUDE_PATH) + message(STATUS "SODIUM_INCLUDE_PATH: ${SODIUM_INCLUDE_PATH}") + include_directories(${SODIUM_INCLUDE_PATH}) + else() + message(FATAL_ERROR "Could not find required sodium/crypto_verify_32.h") + endif() endif() if(BSD_LIBRARY) set(ZMQ_LIB "${ZMQ_LIB};${BSD_LIBRARY}") diff --git a/contrib/epee/include/byte_stream.h b/contrib/epee/include/byte_stream.h index e7993133a..ec9e5cbca 100644 --- a/contrib/epee/include/byte_stream.h +++ b/contrib/epee/include/byte_stream.h @@ -74,6 +74,7 @@ namespace epee public: using char_type = std::uint8_t; using Ch = char_type; + using value_type = char_type; //! Increase internal buffer by at least `byte_stream_increase` bytes. byte_stream() noexcept @@ -86,6 +87,7 @@ namespace epee ~byte_stream() noexcept = default; byte_stream& operator=(byte_stream&& rhs) noexcept; + std::uint8_t* data() noexcept { return buffer_.get(); } const std::uint8_t* data() const noexcept { return buffer_.get(); } std::uint8_t* tellp() const noexcept { return next_write_; } std::size_t available() const noexcept { return end_ - next_write_; } diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h index ffb3f3b7e..8d68f041b 100644 --- a/contrib/epee/include/net/http_server_handlers_map2.h +++ b/contrib/epee/include/net/http_server_handlers_map2.h @@ -171,6 +171,13 @@ epee::serialization::store_t_to_json(static_cast(rsp), response_info.m_body); \ return true; \ } \ + epee::serialization::storage_entry params_; \ + params_ = epee::serialization::storage_entry(epee::serialization::section()); \ + if(!ps.get_value("params", params_, nullptr)) \ + { \ + epee::serialization::section params_section; \ + ps.set_value("params", std::move(params_section), nullptr); \ + } \ if(false) return true; //just a stub to have "else if" diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h index 7de73cbf5..8b26f49ae 100644 --- a/contrib/epee/include/string_tools.h +++ b/contrib/epee/include/string_tools.h @@ -71,8 +71,6 @@ namespace string_tools std::string get_current_module_path(); #endif void set_module_name_and_folder(const std::string& path_to_process_); - void trim_left(std::string& str); - void trim_right(std::string& str); //---------------------------------------------------------------------------- inline std::string& trim(std::string& str) { diff --git a/contrib/epee/src/byte_slice.cpp b/contrib/epee/src/byte_slice.cpp index 72aa39768..47d440dff 100644 --- a/contrib/epee/src/byte_slice.cpp +++ b/contrib/epee/src/byte_slice.cpp @@ -152,7 +152,11 @@ namespace epee { std::size_t space_needed = 0; for (const auto& source : sources) + { + if (std::numeric_limits::max() - space_needed < source.size()) + throw std::bad_alloc{}; space_needed += source.size(); + } if (space_needed) { @@ -162,9 +166,9 @@ namespace epee for (const auto& source : sources) { + assert(source.size() <= out.size()); // see check above std::memcpy(out.data(), source.data(), source.size()); - if (out.remove_prefix(source.size()) < source.size()) - throw std::bad_alloc{}; // size_t overflow on space_needed + out.remove_prefix(source.size()); } storage_ = std::move(storage); } diff --git a/contrib/epee/src/readline_buffer.cpp b/contrib/epee/src/readline_buffer.cpp index cefde158c..ac68d1fdb 100644 --- a/contrib/epee/src/readline_buffer.cpp +++ b/contrib/epee/src/readline_buffer.cpp @@ -1,5 +1,4 @@ #include "readline_buffer.h" -#include "string_tools.h" #include #include #include @@ -174,7 +173,7 @@ static void handle_line(char* line) line_stat = rdln::full; the_line = line; std::string test_line = line; - epee::string_tools::trim_right(test_line); + boost::trim_right(test_line); if(!test_line.empty()) { if (!same_as_last_line(test_line)) diff --git a/contrib/epee/src/string_tools.cpp b/contrib/epee/src/string_tools.cpp index 43f7aca9d..081cb9464 100644 --- a/contrib/epee/src/string_tools.cpp +++ b/contrib/epee/src/string_tools.cpp @@ -174,19 +174,6 @@ namespace string_tools } //---------------------------------------------------------------------------- - void trim_left(std::string& str) - { - boost::trim_left(str); - return; - } - - //---------------------------------------------------------------------------- - void trim_right(std::string& str) - { - boost::trim_right(str); - return; - } - std::string pad_string(std::string s, size_t n, char c, bool prepend) { if (s.size() < n) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 4b8edadc1..54f3b0f93 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -1242,12 +1242,7 @@ bool Blockchain::switch_to_alternative_blockchain(std::list // just the latter (because the rollback was done above). rollback_blockchain_switching(disconnected_chain, split_height); - // FIXME: Why do we keep invalid blocks around? Possibly in case we hear - // about them again so we can immediately dismiss them, but needs some - // looking into. const crypto::hash blkid = cryptonote::get_block_hash(bei.bl); - add_block_as_invalid(bei, blkid); - MERROR("The block was inserted as invalid while connecting new alternative chain, block_id: " << blkid); m_db->remove_alt_block(blkid); alt_ch_iter++; @@ -1255,7 +1250,6 @@ bool Blockchain::switch_to_alternative_blockchain(std::list { const auto &bei = *alt_ch_to_orph_iter++; const crypto::hash blkid = cryptonote::get_block_hash(bei.bl); - add_block_as_invalid(bei, blkid); m_db->remove_alt_block(blkid); } return false; diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp index 4aeaf4e74..194f9444c 100644 --- a/src/daemon/command_parser_executor.cpp +++ b/src/daemon/command_parser_executor.cpp @@ -696,6 +696,16 @@ bool t_command_parser_executor::ban(const std::vector& args) std::ifstream ifs(ban_list_path.string()); for (std::string line; std::getline(ifs, line); ) { + // ignore comments after '#' character + const size_t pound_idx = line.find('#'); + if (pound_idx != std::string::npos) + line.resize(pound_idx); + + // trim whitespace and ignore empty lines + boost::trim(line); + if (line.empty()) + continue; + auto subnet = net::get_ipv4_subnet_address(line); if (subnet) { diff --git a/src/lmdb/key_stream.h b/src/lmdb/key_stream.h index 11fa284dd..74cb536e5 100644 --- a/src/lmdb/key_stream.h +++ b/src/lmdb/key_stream.h @@ -133,6 +133,7 @@ namespace lmdb //! \pre `!is_end()` \return Current key K get_key() const noexcept { + static_assert(std::is_trivially_copyable(), "key is not memcpy safe"); assert(!is_end()); K out; std::memcpy(std::addressof(out), key.data(), sizeof(out)); diff --git a/src/lmdb/table.h b/src/lmdb/table.h index 4ded4ba54..48b94bc66 100644 --- a/src/lmdb/table.h +++ b/src/lmdb/table.h @@ -55,7 +55,7 @@ namespace lmdb static expect get_value(MDB_val value) noexcept { static_assert(std::is_same(), "bad MONERO_FIELD?"); - static_assert(std::is_pod(), "F must be POD"); + static_assert(std::is_trivially_copyable(), "F must be memcpy safe"); static_assert(sizeof(F) + offset <= sizeof(U), "bad field type and/or offset"); if (value.mv_size != sizeof(U)) diff --git a/src/lmdb/util.h b/src/lmdb/util.h index 392ff2039..038411417 100644 --- a/src/lmdb/util.h +++ b/src/lmdb/util.h @@ -111,6 +111,7 @@ namespace lmdb template inline int less(MDB_val const* left, MDB_val const* right) noexcept { + static_assert(std::is_trivially_copyable(), "memcpy will not work"); if (!left || !right || left->mv_size < sizeof(T) + offset || right->mv_size < sizeof(T) + offset) { assert("invalid use of custom comparison" == 0); diff --git a/src/lmdb/value_stream.h b/src/lmdb/value_stream.h index bd2814ef4..2475ec191 100644 --- a/src/lmdb/value_stream.h +++ b/src/lmdb/value_stream.h @@ -162,8 +162,8 @@ namespace lmdb G get_value() const noexcept { static_assert(std::is_same(), "bad MONERO_FIELD usage?"); - static_assert(std::is_pod(), "value type must be pod"); - static_assert(std::is_pod(), "field type must be pod"); + static_assert(std::is_trivially_copyable(), "value type must be memcpy safe"); + static_assert(std::is_trivially_copyable(), "field type must be memcpy safe"); static_assert(sizeof(G) + uoffset <= sizeof(U), "bad field and/or offset"); assert(sizeof(G) + uoffset <= values.size()); assert(!is_end()); diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 75e1ecf3c..e43237be0 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -531,6 +531,16 @@ namespace nodetool std::istringstream iss(banned_ips); for (std::string line; std::getline(iss, line); ) { + // ignore comments after '#' character + const size_t pound_idx = line.find('#'); + if (pound_idx != std::string::npos) + line.resize(pound_idx); + + // trim whitespace and ignore empty lines + boost::trim(line); + if (line.empty()) + continue; + auto subnet = net::get_ipv4_subnet_address(line); if (subnet) { diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 462c06f0e..e0a08eec0 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -8886,6 +8886,22 @@ bool simple_wallet::show_transfers(const std::vector &args_) PAUSE_READLINE(); + auto formatter = boost::format("%8.8s %6.6s %8.8s %25.25s %20.20s %64.64s %15.15s %14.14s %s %s - %s"); + message_writer(console_color_default, false) << formatter + % "Block" + % "In/Out" + % "Locked?" + % "Timestamp" + % "Amount" + % "Tx Hash" + % "Tx Payment ID" + % "Tx Fee" + % "Destination(s)" + % "Index" + % "Tx Note"; + + formatter = boost::format("%8.8llu %6.6s %8.8s %25.25s %20.20s %64.64s %15.15s %14.14s %s %s - %s"); + for (const auto& transfer : all_transfers) { const auto color = transfer.type == "failed" ? console_color_red : transfer.confirmed ? ((transfer.direction == "in" || transfer.direction == "block") ? console_color_green : console_color_magenta) : console_color_default; @@ -8902,8 +8918,6 @@ bool simple_wallet::show_transfers(const std::vector &args_) } } - auto formatter = boost::format("%8.8llu %6.6s %8.8s %25.25s %20.20s %s %s %14.14s %s %s - %s"); - message_writer(color, false) << formatter % transfer.block % transfer.direction diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index eb9b1ef9d..478101af2 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1280,6 +1280,11 @@ bool wallet2::has_stagenet_option(const boost::program_options::variables_map& v return command_line::get_arg(vm, options().stagenet); } +bool wallet2::has_proxy_option() const +{ + return !m_proxy.empty(); +} + std::string wallet2::device_name_option(const boost::program_options::variables_map& vm) { return command_line::get_arg(vm, options().hw_device); @@ -1364,12 +1369,15 @@ std::unique_ptr wallet2::make_dummy(const boost::program_options::varia } //---------------------------------------------------------------------------------------------------- -bool wallet2::set_daemon(std::string daemon_address, boost::optional daemon_login, bool trusted_daemon, epee::net_utils::ssl_options_t ssl_options) +bool wallet2::set_daemon(std::string daemon_address, boost::optional daemon_login, bool trusted_daemon, epee::net_utils::ssl_options_t ssl_options, const std::string& proxy) { boost::lock_guard lock(m_daemon_rpc_mutex); if(m_http_client->is_connected()) m_http_client->disconnect(); + CHECK_AND_ASSERT_MES2(m_proxy.empty() || proxy.empty() , "It is not possible to set global proxy (--proxy) and daemon specific proxy together."); + if(m_proxy.empty()) + CHECK_AND_ASSERT_MES(set_proxy(proxy), false, "failed to set proxy address"); const bool changed = m_daemon_address != daemon_address; m_daemon_address = std::move(daemon_address); m_daemon_login = std::move(daemon_login); @@ -1404,7 +1412,8 @@ bool wallet2::set_proxy(const std::string &address) //---------------------------------------------------------------------------------------------------- bool wallet2::init(std::string daemon_address, boost::optional daemon_login, const std::string &proxy_address, uint64_t upper_transaction_weight_limit, bool trusted_daemon, epee::net_utils::ssl_options_t ssl_options) { - CHECK_AND_ASSERT_MES(set_proxy(proxy_address), false, "failed to set proxy address"); + m_proxy = proxy_address; + CHECK_AND_ASSERT_MES(set_proxy(m_proxy), false, "failed to set proxy address"); m_checkpoints.init_default_checkpoints(m_nettype); m_is_initialized = true; m_upper_transaction_weight_limit = upper_transaction_weight_limit; @@ -6143,7 +6152,7 @@ void wallet2::load(const std::string& wallet_, const epee::wipeable_string& pass bool r = true; if (use_fs) { - load_from_file(m_wallet_file, cache_file_buf, std::numeric_limits::max()); + r = load_from_file(m_wallet_file, cache_file_buf, std::numeric_limits::max()); THROW_WALLET_EXCEPTION_IF(!r, error::file_read_error, m_wallet_file); } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 75137237b..b620ea265 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -971,6 +971,12 @@ private: std::string path() const; + /*! + * \brief has_proxy_option Check the global proxy (--proxy) has been defined or not. + * \return returns bool representing the global proxy (--proxy). + */ + bool has_proxy_option() const; + /*! * \brief verifies given password is correct for default wallet keys file */ @@ -1001,7 +1007,8 @@ private: epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect); bool set_daemon(std::string daemon_address = "http://localhost:8080", boost::optional daemon_login = boost::none, bool trusted_daemon = true, - epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect); + epee::net_utils::ssl_options_t ssl_options = epee::net_utils::ssl_support_t::e_ssl_support_autodetect, + const std::string &proxy = ""); bool set_proxy(const std::string &address); void stop() { m_run.store(false, std::memory_order_relaxed); m_message_store.stop(); } @@ -1834,6 +1841,7 @@ private: cryptonote::account_base m_account; boost::optional m_daemon_login; std::string m_daemon_address; + std::string m_proxy; std::string m_wallet_file; std::string m_keys_file; std::string m_mms_file; diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index 6fc996299..1c7c45034 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -3465,7 +3465,7 @@ namespace tools if (!wal) { er.code = WALLET_RPC_ERROR_CODE_UNKNOWN_ERROR; - er.message = "Failed to open wallet"; + er.message = "Failed to open wallet : " + (!er.message.empty() ? er.message : "Unknown."); return false; } @@ -4437,6 +4437,13 @@ namespace tools er.message = "Command unavailable in restricted mode."; return false; } + + if (m_wallet->has_proxy_option() && !req.proxy.empty()) + { + er.code = WALLET_RPC_ERROR_CODE_PROXY_ALREADY_DEFINED; + er.message = "It is not possible to set daemon specific proxy when --proxy is defined."; + return false; + } std::vector> ssl_allowed_fingerprints; ssl_allowed_fingerprints.reserve(req.ssl_allowed_fingerprints.size()); @@ -4480,7 +4487,7 @@ namespace tools if (!req.username.empty() || !req.password.empty()) daemon_login.emplace(req.username, req.password); - if (!m_wallet->set_daemon(req.address, daemon_login, req.trusted, std::move(ssl_options))) + if (!m_wallet->set_daemon(req.address, daemon_login, req.trusted, std::move(ssl_options), req.proxy)) { er.code = WALLET_RPC_ERROR_CODE_NO_DAEMON_CONNECTION; er.message = std::string("Unable to set daemon"); diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h index b6098d95c..2ce39f667 100644 --- a/src/wallet/wallet_rpc_server_commands_defs.h +++ b/src/wallet/wallet_rpc_server_commands_defs.h @@ -2598,6 +2598,7 @@ namespace wallet_rpc std::string ssl_ca_file; std::vector ssl_allowed_fingerprints; bool ssl_allow_any_cert; + std::string proxy; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(address) @@ -2610,6 +2611,7 @@ namespace wallet_rpc KV_SERIALIZE(ssl_ca_file) KV_SERIALIZE(ssl_allowed_fingerprints) KV_SERIALIZE_OPT(ssl_allow_any_cert, false) + KV_SERIALIZE_OPT(proxy, (std::string)"") END_KV_SERIALIZE_MAP() }; typedef epee::misc_utils::struct_init request; diff --git a/tests/data/node/banlist_1.txt b/tests/data/node/banlist_1.txt new file mode 100644 index 000000000..7cc94ca62 --- /dev/null +++ b/tests/data/node/banlist_1.txt @@ -0,0 +1,17 @@ +# magicfolk +255.255.255.0 # Saruman the White +128.128.128.0 # Gandalf the Gray +150.75.0.0 # Radagast the Brown +99.98.0.0/16 # All of Misty Mountain + +# personal enemies +1.2.3.4 # this woman used to give me swirlies +6.7.8.9 # I just don't like the cut of his jib +1.0.0.7#Literally James Bond, he wrecked my aston martin +100.98.1.13 # Earl from HOA +100.98.1.0/24 #The rest of the HOA for good measure +# + +#7.7.7.7 +#^^^We're chill now, she's truly an angel + diff --git a/tests/unit_tests/epee_serialization.cpp b/tests/unit_tests/epee_serialization.cpp index f46630615..5e5b6e40f 100644 --- a/tests/unit_tests/epee_serialization.cpp +++ b/tests/unit_tests/epee_serialization.cpp @@ -29,8 +29,11 @@ #include #include +#include +#include "serialization/keyvalue_serialization.h" #include "storages/portable_storage.h" +#include "storages/portable_storage_template_helper.h" #include "span.h" TEST(epee_binary, two_keys) @@ -54,3 +57,68 @@ TEST(epee_binary, duplicate_key) epee::serialization::portable_storage storage{}; EXPECT_FALSE(storage.load_from_binary(data)); } + +namespace +{ + +template +struct ParentObjWithOptChild +{ + t_param params; + + ParentObjWithOptChild(): params{} {} + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(params) + END_KV_SERIALIZE_MAP() +}; + +struct ObjWithOptChild +{ + bool test_value; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE_OPT(test_value, true); + END_KV_SERIALIZE_MAP() +}; +} + +TEST(epee_binary, serialize_deserialize) +{ + ParentObjWithOptChild o; + std::string o_json; + o.params.test_value = true; + + EXPECT_TRUE(epee::serialization::store_t_to_json(o, o_json)); + EXPECT_TRUE(o.params.test_value); + + EXPECT_TRUE(epee::serialization::load_t_from_json(o, o_json)); + EXPECT_TRUE(o.params.test_value); + + ParentObjWithOptChild o2; + std::string o2_json; + o.params.test_value = false; + + EXPECT_TRUE(epee::serialization::store_t_to_json(o2, o2_json)); + EXPECT_FALSE(o2.params.test_value); + + EXPECT_TRUE(epee::serialization::load_t_from_json(o2, o2_json)); + EXPECT_FALSE(o2.params.test_value); + + // compiler sets default value of test_value to false + ParentObjWithOptChild o3; + std::string o3_json; + + EXPECT_TRUE(epee::serialization::store_t_to_json(o3, o3_json)); + EXPECT_FALSE(o3.params.test_value); + + EXPECT_TRUE(epee::serialization::load_t_from_json(o3, o3_json)); + EXPECT_FALSE(o3.params.test_value); + + // test optional field default initialization. + ParentObjWithOptChild o4; + std::string o4_json = "{\"params\": {}}"; + + EXPECT_TRUE(epee::serialization::load_t_from_json(o4, o4_json)); + EXPECT_TRUE(o4.params.test_value); +} diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp index 584f98f7a..6a564e7ed 100644 --- a/tests/unit_tests/node_server.cpp +++ b/tests/unit_tests/node_server.cpp @@ -35,6 +35,7 @@ #include "cryptonote_core/i_core_events.h" #include "cryptonote_protocol/cryptonote_protocol_handler.h" #include "cryptonote_protocol/cryptonote_protocol_handler.inl" +#include "unit_tests_utils.h" #include #define MAKE_IPV4_ADDRESS(a,b,c,d) epee::net_utils::ipv4_network_address{MAKE_IP(a,b,c,d),0} @@ -114,6 +115,18 @@ static bool is_blocked(Server &server, const epee::net_utils::network_address &a return true; } } + + if (address.get_type_id() != epee::net_utils::address_type::ipv4) + return false; + + const epee::net_utils::ipv4_network_address ipv4_address = address.as(); + + // check if in a blocked ipv4 subnet + const std::map subnets = server.get_blocked_subnets(); + for (const auto &subnet : subnets) + if (subnet.first.matches(ipv4_address)) + return true; + return false; } @@ -266,6 +279,78 @@ TEST(ban, ignores_port) ASSERT_FALSE(is_blocked(server,MAKE_IPV4_ADDRESS_PORT(1,2,3,4,6))); } +TEST(ban, file_banlist) +{ + test_core pr_core; + cryptonote::t_cryptonote_protocol_handler cprotocol(pr_core, NULL); + Server server(cprotocol); + cprotocol.set_p2p_endpoint(&server); + + auto create_node_dir = [](){ + boost::system::error_code ec; + auto path = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path("daemon-%%%%%%%%%%%%%%%%", ec); + if (ec) + return boost::filesystem::path{}; + auto success = boost::filesystem::create_directory(path, ec); + if (!ec && success) + return path; + return boost::filesystem::path{}; + }; + const auto node_dir = create_node_dir(); + ASSERT_TRUE(!node_dir.empty()); + auto auto_remove_node_dir = epee::misc_utils::create_scope_leave_handler([&node_dir](){ + boost::filesystem::remove_all(node_dir); + }); + + boost::program_options::variables_map vm; + boost::program_options::store( + boost::program_options::command_line_parser({ + "--data-dir", + node_dir.string(), + "--ban-list", + (unit_test::data_dir / "node" / "banlist_1.txt").string() + }).options([]{ + boost::program_options::options_description options_description{}; + cryptonote::core::init_options(options_description); + Server::init_options(options_description); + return options_description; + }()).run(), + vm + ); + + ASSERT_TRUE(server.init(vm)); + + // Test cases (look in the banlist_1.txt file) + + // magicfolk + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(255,255,255,0,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(128,128,128,0,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(150,75,0,0,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(99,98,0,0,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(99,98,0,255,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(99,98,1,0,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(99,98,1,0,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(99,98,255,255,9999)) ); + EXPECT_FALSE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(99,99,0,0,9999)) ); + + // personal enemies + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(1,2,3,4,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(6,7,8,9,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(1,0,0,7,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(1,0,0,7,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(100,98,1,13,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(100,98,1,0,9999)) ); + EXPECT_TRUE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(100,98,1,255,9999)) ); + EXPECT_FALSE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(100,98,2,0,9999)) ); + EXPECT_FALSE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(100,98,0,255,9999)) ); + + // angel + EXPECT_FALSE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(007,007,007,007,9999)) ); + + // random IP + EXPECT_FALSE( is_blocked(server, MAKE_IPV4_ADDRESS_PORT(145,036,205,235,9999)) ); +} + TEST(node_server, bind_same_p2p_port) { struct test_data_t