Added socks proxy (tor/i2pd/kovri) support to wallet

This commit is contained in:
Lee Clagett
2019-01-23 21:37:43 +00:00
parent e4b049da05
commit 7acfa9f3cc
21 changed files with 505 additions and 98 deletions

View File

@@ -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