diff options
author | Riccardo Spagni <ric@spagni.net> | 2019-03-27 14:09:11 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2019-03-27 14:09:11 +0200 |
commit | 1d83ce8f298850f4c16a110b87245377166cb17c (patch) | |
tree | 5d1903ab4b132c137b1bb838037f024d6fb8b0d3 /src/net/socks.cpp | |
parent | Merge pull request #5286 (diff) | |
parent | Added socks proxy (tor/i2pd/kovri) support to wallet (diff) | |
download | monero-1d83ce8f298850f4c16a110b87245377166cb17c.tar.xz |
Merge pull request #5090
7acfa9f3 Added socks proxy (tor/i2pd/kovri) support to wallet (Lee Clagett)
Diffstat (limited to 'src/net/socks.cpp')
-rw-r--r-- | src/net/socks.cpp | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/net/socks.cpp b/src/net/socks.cpp index 53154369b..9b81c6c2e 100644 --- a/src/net/socks.cpp +++ b/src/net/socks.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2018, The Monero Project +// Copyright (c) 2018-2019, The Monero Project // // All rights reserved. // @@ -193,7 +193,7 @@ namespace socks else if (bytes < self.buffer().size()) self.done(socks::error::bad_write, std::move(self_)); else - boost::asio::async_read(self.proxy_, get_buffer(self), completed{std::move(self_)}); + boost::asio::async_read(self.proxy_, get_buffer(self), self.strand_.wrap(completed{std::move(self_)})); } } }; @@ -215,13 +215,13 @@ namespace socks if (error) self.done(error, std::move(self_)); else - boost::asio::async_write(self.proxy_, get_buffer(self), read{std::move(self_)}); + boost::asio::async_write(self.proxy_, get_buffer(self), self.strand_.wrap(read{std::move(self_)})); } } }; client::client(stream_type::socket&& proxy, socks::version ver) - : proxy_(std::move(proxy)), buffer_size_(0), buffer_(), ver_(ver) + : proxy_(std::move(proxy)), strand_(proxy_.get_io_service()), buffer_size_(0), buffer_(), ver_(ver) {} client::~client() {} @@ -296,7 +296,7 @@ namespace socks if (self && !self->buffer().empty()) { client& alias = *self; - alias.proxy_.async_connect(proxy_address, write{std::move(self)}); + alias.proxy_.async_connect(proxy_address, alias.strand_.wrap(write{std::move(self)})); return true; } return false; @@ -307,10 +307,26 @@ namespace socks if (self && !self->buffer().empty()) { client& alias = *self; - boost::asio::async_write(alias.proxy_, write::get_buffer(alias), read{std::move(self)}); + boost::asio::async_write(alias.proxy_, write::get_buffer(alias), alias.strand_.wrap(read{std::move(self)})); return true; } return false; } + + void client::async_close::operator()(boost::system::error_code error) + { + if (self_ && error != boost::system::errc::operation_canceled) + { + const std::shared_ptr<client> self = std::move(self_); + self->strand_.dispatch([self] () + { + if (self && self->proxy_.is_open()) + { + self->proxy_.shutdown(boost::asio::ip::tcp::socket::shutdown_both); + self->proxy_.close(); + } + }); + } + } } // socks } // net |