aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/src
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee/src')
-rw-r--r--contrib/epee/src/CMakeLists.txt3
-rw-r--r--contrib/epee/src/connection_basic.cpp11
-rw-r--r--contrib/epee/src/net_helper.cpp54
3 files changed, 64 insertions, 4 deletions
diff --git a/contrib/epee/src/CMakeLists.txt b/contrib/epee/src/CMakeLists.txt
index 0787a9d08..2465afebb 100644
--- a/contrib/epee/src/CMakeLists.txt
+++ b/contrib/epee/src/CMakeLists.txt
@@ -26,8 +26,9 @@
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp net_utils_base.cpp string_tools.cpp wipeable_string.cpp memwipe.c
+add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp net_helper.cpp net_utils_base.cpp string_tools.cpp wipeable_string.cpp memwipe.c
connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp mlocker.cpp buffer.cpp net_ssl.cpp)
+
if (USE_READLINE AND GNU_READLINE_FOUND)
add_library(epee_readline STATIC readline_buffer.cpp)
endif()
diff --git a/contrib/epee/src/connection_basic.cpp b/contrib/epee/src/connection_basic.cpp
index 83db171d8..cafc08ead 100644
--- a/contrib/epee/src/connection_basic.cpp
+++ b/contrib/epee/src/connection_basic.cpp
@@ -47,6 +47,12 @@
// TODO:
#include "net/network_throttle-detail.hpp"
+#if BOOST_VERSION >= 107000
+#define GET_IO_SERVICE(s) ((boost::asio::io_context&)(s).get_executor().context())
+#else
+#define GET_IO_SERVICE(s) ((s).get_io_service())
+#endif
+
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "net.conn"
@@ -117,8 +123,8 @@ connection_basic::connection_basic(boost::asio::ip::tcp::socket&& sock, boost::s
:
m_stats(std::move(stats)),
mI( new connection_basic_pimpl("peer") ),
- strand_(sock.get_io_service()),
- socket_(sock.get_io_service(), ssl_context.context),
+ strand_(GET_IO_SERVICE(sock)),
+ socket_(GET_IO_SERVICE(sock), ssl_context.context),
m_want_close_connection(false),
m_was_shutdown(false),
m_ssl_support(ssl_support),
@@ -167,7 +173,6 @@ connection_basic::~connection_basic() noexcept(false) {
std::string remote_addr_str = "?";
try { boost::system::error_code e; remote_addr_str = socket().remote_endpoint(e).address().to_string(); } catch(...){} ;
_note("Destructing connection #"<<mI->m_peer_number << " to " << remote_addr_str);
-try { throw 0; } catch(...){}
}
void connection_basic::set_rate_up_limit(uint64_t limit) {
diff --git a/contrib/epee/src/net_helper.cpp b/contrib/epee/src/net_helper.cpp
new file mode 100644
index 000000000..3543f5716
--- /dev/null
+++ b/contrib/epee/src/net_helper.cpp
@@ -0,0 +1,54 @@
+#include "net/net_helper.h"
+
+namespace epee
+{
+namespace net_utils
+{
+ boost::unique_future<boost::asio::ip::tcp::socket>
+ direct_connect::operator()(const std::string& addr, const std::string& port, boost::asio::steady_timer& timeout) const
+ {
+ // Get a list of endpoints corresponding to the server name.
+ //////////////////////////////////////////////////////////////////////////
+ boost::asio::ip::tcp::resolver resolver(GET_IO_SERVICE(timeout));
+ boost::asio::ip::tcp::resolver::query query(boost::asio::ip::tcp::v4(), addr, port, boost::asio::ip::tcp::resolver::query::canonical_name);
+ boost::asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);
+ boost::asio::ip::tcp::resolver::iterator end;
+ if(iterator == end) // Documentation states that successful call is guaranteed to be non-empty
+ throw boost::system::system_error{boost::asio::error::fault, "Failed to resolve " + addr};
+
+ //////////////////////////////////////////////////////////////////////////
+
+ struct new_connection
+ {
+ boost::promise<boost::asio::ip::tcp::socket> result_;
+ boost::asio::ip::tcp::socket socket_;
+
+ explicit new_connection(boost::asio::io_service& io_service)
+ : result_(), socket_(io_service)
+ {}
+ };
+
+ const auto shared = std::make_shared<new_connection>(GET_IO_SERVICE(timeout));
+ timeout.async_wait([shared] (boost::system::error_code error)
+ {
+ if (error != boost::system::errc::operation_canceled && shared && shared->socket_.is_open())
+ {
+ shared->socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
+ shared->socket_.close();
+ }
+ });
+ shared->socket_.async_connect(*iterator, [shared] (boost::system::error_code error)
+ {
+ if (shared)
+ {
+ if (error)
+ shared->result_.set_exception(boost::system::system_error{error});
+ else
+ shared->result_.set_value(std::move(shared->socket_));
+ }
+ });
+ return shared->result_.get_future();
+ }
+}
+}
+