From df9aa6bb04f8a95f83b2b57c6c3e86deb457b85a Mon Sep 17 00:00:00 2001 From: Jeffro256 Date: Mon, 27 Feb 2023 00:30:12 -0600 Subject: [PATCH] epee: remove dead code in net_helper --- contrib/epee/include/net/net_helper.h | 166 -------------------------- contrib/epee/src/net_ssl.cpp | 3 +- src/p2p/net_node.inl | 3 - 3 files changed, 2 insertions(+), 170 deletions(-) diff --git a/contrib/epee/include/net/net_helper.h b/contrib/epee/include/net/net_helper.h index ee344561d..3cb3d8c66 100644 --- a/contrib/epee/include/net/net_helper.h +++ b/contrib/epee/include/net/net_helper.h @@ -29,8 +29,6 @@ #pragma once -//#include -//#include #include #include #include @@ -52,11 +50,6 @@ #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "net" -#ifndef MAKE_IP -#define MAKE_IP( a1, a2, a3, a4 ) (a1|(a2<<8)|(a3<<16)|(a4<<24)) -#endif - - namespace epee { namespace net_utils @@ -106,7 +99,6 @@ namespace net_utils m_ssl_socket(new boost::asio::ssl::stream(m_io_service, m_ctx)), m_connector(direct_connect{}), m_ssl_options(epee::net_utils::ssl_support_t::e_ssl_support_autodetect), - m_initialized(true), m_connected(false), m_deadline(m_io_service, std::chrono::steady_clock::time_point::max()), m_shutdowned(false), @@ -149,12 +141,6 @@ namespace net_utils m_ssl_options = std::move(ssl_options); } - inline - bool connect(const std::string& addr, int port, std::chrono::milliseconds timeout) - { - return connect(addr, std::to_string(port), timeout); - } - inline try_connect_result_t try_connect(const std::string& addr, const std::string& port, std::chrono::milliseconds timeout) { @@ -333,64 +319,6 @@ namespace net_utils return true; } - inline - bool send(const void* data, size_t sz) - { - try - { - /* - m_deadline.expires_from_now(boost::posix_time::milliseconds(m_reciev_timeout)); - - // Set up the variable that receives the result of the asynchronous - // operation. The error code is set to would_block to signal that the - // operation is incomplete. Asio guarantees that its asynchronous - // operations will never fail with would_block, so any other value in - // ec indicates completion. - boost::system::error_code ec = boost::asio::error::would_block; - - // Start the asynchronous operation itself. The boost::lambda function - // object is used as a callback and will update the ec variable when the - // operation completes. The blocking_udp_client.cpp example shows how you - // can use boost::bind rather than boost::lambda. - boost::asio::async_write(m_socket, boost::asio::buffer(data, sz), boost::lambda::var(ec) = boost::lambda::_1); - - // Block until the asynchronous operation has completed. - while (ec == boost::asio::error::would_block) - { - m_io_service.run_one(); - } - */ - boost::system::error_code ec; - - size_t writen = write(data, sz, ec); - - if (!writen || ec) - { - LOG_PRINT_L3("Problems at write: " << ec.message()); - m_connected = false; - return false; - }else - { - m_deadline.expires_at(std::chrono::steady_clock::time_point::max()); - m_bytes_sent += sz; - } - } - - catch(const boost::system::system_error& er) - { - LOG_ERROR("Some problems at send, message: " << er.what()); - m_connected = false; - return false; - } - catch(...) - { - LOG_ERROR("Some fatal problems."); - return false; - } - - return true; - } - bool is_connected(bool *ssl = NULL) { if (!m_connected || !m_ssl_socket->next_layer().is_open()) @@ -487,79 +415,6 @@ namespace net_utils } - inline bool recv_n(std::string& buff, int64_t sz, std::chrono::milliseconds timeout) - { - - try - { - // Set a deadline for the asynchronous operation. Since this function uses - // a composed operation (async_read_until), the deadline applies to the - // entire operation, rather than individual reads from the socket. - m_deadline.expires_from_now(timeout); - - // Set up the variable that receives the result of the asynchronous - // operation. The error code is set to would_block to signal that the - // operation is incomplete. Asio guarantees that its asynchronous - // operations will never fail with would_block, so any other value in - // ec indicates completion. - //boost::system::error_code ec = boost::asio::error::would_block; - - // Start the asynchronous operation itself. The boost::lambda function - // object is used as a callback and will update the ec variable when the - // operation completes. The blocking_udp_client.cpp example shows how you - // can use boost::bind rather than boost::lambda. - - buff.resize(static_cast(sz)); - boost::system::error_code ec = boost::asio::error::would_block; - size_t bytes_transfered = 0; - - - handler_obj hndlr(ec, bytes_transfered); - async_read((char*)buff.data(), buff.size(), boost::asio::transfer_at_least(buff.size()), hndlr); - - // Block until the asynchronous operation has completed. - while (ec == boost::asio::error::would_block && !m_shutdowned) - { - m_io_service.run_one(); - } - - if (ec) - { - LOG_PRINT_L3("Problems at read: " << ec.message()); - m_connected = false; - return false; - }else - { - m_deadline.expires_at(std::chrono::steady_clock::time_point::max()); - } - - m_bytes_received += bytes_transfered; - if(bytes_transfered != buff.size()) - { - LOG_ERROR("Transferred mismatch with transfer_at_least value: m_bytes_transferred=" << bytes_transfered << " at_least value=" << buff.size()); - return false; - } - - return true; - } - - catch(const boost::system::system_error& er) - { - LOG_ERROR("Some problems at read, message: " << er.what()); - m_connected = false; - return false; - } - catch(...) - { - LOG_ERROR("Some fatal problems at read."); - return false; - } - - - - return false; - } - bool shutdown() { m_deadline.cancel(); @@ -579,16 +434,6 @@ namespace net_utils m_connected = false; return true; } - - boost::asio::io_service& get_io_service() - { - return m_io_service; - } - - boost::asio::ip::tcp::socket& get_socket() - { - return m_ssl_socket->next_layer(); - } uint64_t get_bytes_sent() const { @@ -648,16 +493,6 @@ namespace net_utils } protected: - bool write(const void* data, size_t sz, boost::system::error_code& ec) - { - bool success; - if(m_ssl_options.support != ssl_support_t::e_ssl_support_disabled) - success = boost::asio::write(*m_ssl_socket, boost::asio::buffer(data, sz), ec); - else - success = boost::asio::write(m_ssl_socket->next_layer(), boost::asio::buffer(data, sz), ec); - return success; - } - void async_write(const void* data, size_t sz, boost::system::error_code& ec) { if(m_ssl_options.support != ssl_support_t::e_ssl_support_disabled) @@ -681,7 +516,6 @@ namespace net_utils std::shared_ptr> m_ssl_socket; std::function m_connector; ssl_options_t m_ssl_options; - bool m_initialized; bool m_connected; boost::asio::steady_timer m_deadline; std::atomic m_shutdowned; diff --git a/contrib/epee/src/net_ssl.cpp b/contrib/epee/src/net_ssl.cpp index 2d0b7d791..39a4fde54 100644 --- a/contrib/epee/src/net_ssl.cpp +++ b/contrib/epee/src/net_ssl.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -38,8 +39,8 @@ #include #include #include "misc_log_ex.h" -#include "net/net_helper.h" #include "net/net_ssl.h" +#include "net/net_utils_base.h" #include "file_io_utils.h" // to validate .crt and .key paths #undef MONERO_DEFAULT_LOG_CATEGORY diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index ee6bd8b19..b8e11656b 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -51,7 +51,6 @@ #include "common/dns_utils.h" #include "common/pruning.h" #include "net/error.h" -#include "net/net_helper.h" #include "math_helper.h" #include "misc_log_ex.h" #include "p2p_protocol_defs.h" @@ -67,8 +66,6 @@ #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "net.p2p" -#define NET_MAKE_IP(b1,b2,b3,b4) ((LPARAM)(((DWORD)(b1)<<24)+((DWORD)(b2)<<16)+((DWORD)(b3)<<8)+((DWORD)(b4)))) - #define MIN_WANTED_SEED_NODES 12 static inline boost::asio::ip::address_v4 make_address_v4_from_v6(const boost::asio::ip::address_v6& a)