From 2b49830e0f8809e498491f2400e7f32653817a64 Mon Sep 17 00:00:00 2001 From: DanielBujnik Date: Thu, 13 Aug 2015 15:40:27 +0100 Subject: [PATCH 01/10] Update request.hpp --- boost/network/protocol/http/impl/request.hpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/boost/network/protocol/http/impl/request.hpp b/boost/network/protocol/http/impl/request.hpp index 7c55db85d..efddc26a4 100644 --- a/boost/network/protocol/http/impl/request.hpp +++ b/boost/network/protocol/http/impl/request.hpp @@ -55,6 +55,7 @@ template struct basic_request : public basic_message { mutable boost::network::uri::uri uri_; + unsigned short source_port_; typedef basic_message base_type; public: @@ -62,18 +63,18 @@ struct basic_request : public basic_message { typedef typename string::type string_type; typedef boost::uint16_t port_type; - explicit basic_request(string_type const& uri_) : uri_(uri_) {} + explicit basic_request(string_type const& uri_) : uri_(uri_), source_port_(0) {} - explicit basic_request(boost::network::uri::uri const& uri_) : uri_(uri_) {} + explicit basic_request(boost::network::uri::uri const& uri_) : uri_(uri_), source_port_(0) {} void uri(string_type const& new_uri) { uri_ = new_uri; } void uri(boost::network::uri::uri const& new_uri) { uri_ = new_uri; } - basic_request() : base_type() {} + basic_request() : base_type(), source_port_(0) {} basic_request(basic_request const& other) - : base_type(other), uri_(other.uri_) {} + : base_type(other), uri_(other.uri_), source_port_(other.source_port_) {} basic_request& operator=(basic_request rhs) { rhs.swap(*this); @@ -85,6 +86,7 @@ struct basic_request : public basic_message { basic_request& this_ref(*this); base_ref.swap(this_ref); boost::swap(other.uri_, this->uri_); + boost::swap(other.source_port_, this->source_port_); } string_type const host() const { return uri_.host(); } @@ -110,6 +112,10 @@ struct basic_request : public basic_message { void uri(string_type const& new_uri) const { uri_ = new_uri; } boost::network::uri::uri const& uri() const { return uri_; } + + void setSourcePort(const unsigned short port) { source_port_ = port; } + + unsigned short getSourcePort() const { return source_port_; } }; /** This is the implementation of a POD request type From a3dfcdbc8f91d70696f6ff08706e4f1db152ece1 Mon Sep 17 00:00:00 2001 From: DanielBujnik Date: Thu, 13 Aug 2015 15:46:07 +0100 Subject: [PATCH 02/10] Update async_normal.hpp --- .../http/client/connection/async_normal.hpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/boost/network/protocol/http/client/connection/async_normal.hpp b/boost/network/protocol/http/client/connection/async_normal.hpp index f8238e688..75a037b40 100644 --- a/boost/network/protocol/http/client/connection/async_normal.hpp +++ b/boost/network/protocol/http/client/connection/async_normal.hpp @@ -95,10 +95,12 @@ struct http_async_connection this->method = method; boost::uint16_t port_ = port(request); string_type host_ = host(request); + boost::uint16_t source_port = request.getSourcePort(); + resolve_(resolver_, host_, port_, request_strand_.wrap(boost::bind( &this_type::handle_resolved, this_type::shared_from_this(), - host_, port_, get_body, callback, + host_, port_, source_port, get_body, callback, generator, boost::arg<1>(), boost::arg<2>()))); if (timeout_ > 0) { timer_.expires_from_now(boost::posix_time::seconds(timeout_)); @@ -129,7 +131,7 @@ struct http_async_connection is_timedout_ = true; } - void handle_resolved(string_type host, boost::uint16_t port, bool get_body, + void handle_resolved(string_type host, boost::uint16_t port, boost::uint16_t source_port, bool get_body, body_callback_function_type callback, body_generator_function_type generator, boost::system::error_code const& ec, @@ -141,10 +143,10 @@ struct http_async_connection resolver_iterator iter = boost::begin(endpoint_range); asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port); delegate_->connect( - endpoint, host, + endpoint, host, source_port, request_strand_.wrap(boost::bind( &this_type::handle_connected, this_type::shared_from_this(), host, - port, get_body, callback, generator, + port, source_port, get_body, callback, generator, std::make_pair(++iter, resolver_iterator()), placeholders::error))); } else { @@ -154,7 +156,7 @@ struct http_async_connection } } - void handle_connected(string_type host, boost::uint16_t port, bool get_body, + void handle_connected(string_type host, boost::uint16_t port, boost::uint16_t source_port, bool get_body, body_callback_function_type callback, body_generator_function_type generator, resolver_iterator_pair endpoint_range, @@ -174,10 +176,10 @@ struct http_async_connection resolver_iterator iter = boost::begin(endpoint_range); asio::ip::tcp::endpoint endpoint(iter->endpoint().address(), port); delegate_->connect( - endpoint, host, + endpoint, host, source_port, request_strand_.wrap(boost::bind( &this_type::handle_connected, this_type::shared_from_this(), - host, port, get_body, callback, generator, + host, port, source_port, get_body, callback, generator, std::make_pair(++iter, resolver_iterator()), placeholders::error))); } else { From 562f8141ced52cbfce0dd569ada71b6a67a240fa Mon Sep 17 00:00:00 2001 From: DanielBujnik Date: Thu, 13 Aug 2015 15:46:45 +0100 Subject: [PATCH 03/10] Update connection_delegate.hpp --- .../protocol/http/client/connection/connection_delegate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boost/network/protocol/http/client/connection/connection_delegate.hpp b/boost/network/protocol/http/client/connection/connection_delegate.hpp index 45d8874f1..79fa1ca4d 100644 --- a/boost/network/protocol/http/client/connection/connection_delegate.hpp +++ b/boost/network/protocol/http/client/connection/connection_delegate.hpp @@ -13,7 +13,7 @@ namespace http { namespace impl { struct connection_delegate { - virtual void connect(asio::ip::tcp::endpoint &endpoint, std::string host, + virtual void connect(asio::ip::tcp::endpoint &endpoint, std::string host, boost::uint16_t source_port, function handler) = 0; virtual void write( asio::streambuf &command_streambuf, From 2d69fefc3ebf820d73b6867bd9a54efee708f3ba Mon Sep 17 00:00:00 2001 From: DanielBujnik Date: Thu, 13 Aug 2015 15:47:17 +0100 Subject: [PATCH 04/10] Update normal_delegate.hpp --- .../network/protocol/http/client/connection/normal_delegate.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boost/network/protocol/http/client/connection/normal_delegate.hpp b/boost/network/protocol/http/client/connection/normal_delegate.hpp index f04457f08..ae6ace333 100644 --- a/boost/network/protocol/http/client/connection/normal_delegate.hpp +++ b/boost/network/protocol/http/client/connection/normal_delegate.hpp @@ -19,7 +19,7 @@ namespace impl { struct normal_delegate : connection_delegate { normal_delegate(asio::io_service &service); - virtual void connect(asio::ip::tcp::endpoint &endpoint, std::string host, + virtual void connect(asio::ip::tcp::endpoint &endpoint, std::string host, boost::uint16_t source_port, function handler); virtual void write( asio::streambuf &command_streambuf, From e76bb29fd618df8c79479712837db6accce222d7 Mon Sep 17 00:00:00 2001 From: DanielBujnik Date: Thu, 13 Aug 2015 15:48:05 +0100 Subject: [PATCH 05/10] Update normal_delegate.ipp --- .../protocol/http/client/connection/normal_delegate.ipp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boost/network/protocol/http/client/connection/normal_delegate.ipp b/boost/network/protocol/http/client/connection/normal_delegate.ipp index 167601959..ae52fd870 100644 --- a/boost/network/protocol/http/client/connection/normal_delegate.ipp +++ b/boost/network/protocol/http/client/connection/normal_delegate.ipp @@ -19,13 +19,13 @@ boost::network::http::impl::normal_delegate::normal_delegate( : service_(service) {} void boost::network::http::impl::normal_delegate::connect( - asio::ip::tcp::endpoint &endpoint, std::string host, + asio::ip::tcp::endpoint &endpoint, std::string host, boost::uint16_t source_port, function handler) { // TODO(dberris): review parameter necessity. (void)host; - - socket_.reset(new asio::ip::tcp::socket(service_)); + + socket_.reset(new asio::ip::tcp::socket(service_, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), source_port))); socket_->async_connect(endpoint, handler); } From c5aca73db2f4ad2d868c8b45f53e66ccc5e8b1ec Mon Sep 17 00:00:00 2001 From: DanielBujnik Date: Thu, 13 Aug 2015 15:48:54 +0100 Subject: [PATCH 06/10] Update ssl_delegate.hpp --- .../network/protocol/http/client/connection/ssl_delegate.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/boost/network/protocol/http/client/connection/ssl_delegate.hpp b/boost/network/protocol/http/client/connection/ssl_delegate.hpp index 768349348..712fc5173 100644 --- a/boost/network/protocol/http/client/connection/ssl_delegate.hpp +++ b/boost/network/protocol/http/client/connection/ssl_delegate.hpp @@ -29,7 +29,7 @@ struct ssl_delegate : connection_delegate, optional private_key_file, optional ciphers, long ssl_options); - virtual void connect(asio::ip::tcp::endpoint &endpoint, std::string host, + virtual void connect(asio::ip::tcp::endpoint &endpoint, std::string host, boost::uint16_t source_port, function handler); virtual void write( asio::streambuf &command_streambuf, @@ -49,7 +49,8 @@ struct ssl_delegate : connection_delegate, optional ciphers_; long ssl_options_; scoped_ptr context_; - scoped_ptr > socket_; + scoped_ptr tcp_socket_; + scoped_ptr > socket_; bool always_verify_peer_; ssl_delegate(ssl_delegate const &); // = delete From 9b0930a9e0da759a49cf33bab79259ac14c4433d Mon Sep 17 00:00:00 2001 From: DanielBujnik Date: Thu, 13 Aug 2015 15:50:44 +0100 Subject: [PATCH 07/10] Update ssl_delegate.ipp --- .../protocol/http/client/connection/ssl_delegate.ipp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/boost/network/protocol/http/client/connection/ssl_delegate.ipp b/boost/network/protocol/http/client/connection/ssl_delegate.ipp index ca0edf477..71161ba46 100644 --- a/boost/network/protocol/http/client/connection/ssl_delegate.ipp +++ b/boost/network/protocol/http/client/connection/ssl_delegate.ipp @@ -29,7 +29,7 @@ boost::network::http::impl::ssl_delegate::ssl_delegate( always_verify_peer_(always_verify_peer) {} void boost::network::http::impl::ssl_delegate::connect( - asio::ip::tcp::endpoint &endpoint, std::string host, + asio::ip::tcp::endpoint &endpoint, std::string host, boost::uint16_t source_port, function handler) { context_.reset( new asio::ssl::context(service_, asio::ssl::context::sslv23_client)); @@ -59,8 +59,11 @@ void boost::network::http::impl::ssl_delegate::connect( if (private_key_file_) context_->use_private_key_file(*private_key_file_, boost::asio::ssl::context::pem); + + tcp_socket_.reset(new asio::ip::tcp::socket(service_, asio::ip::tcp::endpoint(asio::ip::tcp::v4(), source_port))); socket_.reset( - new asio::ssl::stream(service_, *context_)); + new asio::ssl::stream(*(tcp_socket_.get()), *context_)); + if (always_verify_peer_) socket_->set_verify_callback(boost::asio::ssl::rfc2818_verification(host)); socket_->lowest_layer().async_connect( From 5eb7289e2fe71c80a072ef440b3fea4b82f1cfea Mon Sep 17 00:00:00 2001 From: DanielBujnik Date: Wed, 19 Aug 2015 10:21:53 +0100 Subject: [PATCH 08/10] Update async_normal.hpp --- boost/network/protocol/http/client/connection/async_normal.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boost/network/protocol/http/client/connection/async_normal.hpp b/boost/network/protocol/http/client/connection/async_normal.hpp index 75a037b40..f5590d7fc 100644 --- a/boost/network/protocol/http/client/connection/async_normal.hpp +++ b/boost/network/protocol/http/client/connection/async_normal.hpp @@ -95,7 +95,7 @@ struct http_async_connection this->method = method; boost::uint16_t port_ = port(request); string_type host_ = host(request); - boost::uint16_t source_port = request.getSourcePort(); + boost::uint16_t source_port = request.source_port(); resolve_(resolver_, host_, port_, request_strand_.wrap(boost::bind( From 63b3b7b8d92a0317f1bea50452cbb67978907ee5 Mon Sep 17 00:00:00 2001 From: DanielBujnik Date: Wed, 19 Aug 2015 10:23:26 +0100 Subject: [PATCH 09/10] Update request.hpp --- boost/network/protocol/http/impl/request.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boost/network/protocol/http/impl/request.hpp b/boost/network/protocol/http/impl/request.hpp index efddc26a4..3b64a1517 100644 --- a/boost/network/protocol/http/impl/request.hpp +++ b/boost/network/protocol/http/impl/request.hpp @@ -113,9 +113,9 @@ struct basic_request : public basic_message { boost::network::uri::uri const& uri() const { return uri_; } - void setSourcePort(const unsigned short port) { source_port_ = port; } + void source_port(const unsigned short port) { source_port_ = port; } - unsigned short getSourcePort() const { return source_port_; } + unsigned short source_port() const { return source_port_; } }; /** This is the implementation of a POD request type From 87f6482a20d013f3d8d776dbd49dfbd483ba2663 Mon Sep 17 00:00:00 2001 From: DanielBujnik Date: Thu, 20 Aug 2015 08:49:45 +0100 Subject: [PATCH 10/10] Update request.hpp --- boost/network/protocol/http/impl/request.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boost/network/protocol/http/impl/request.hpp b/boost/network/protocol/http/impl/request.hpp index 3b64a1517..29608f8a7 100644 --- a/boost/network/protocol/http/impl/request.hpp +++ b/boost/network/protocol/http/impl/request.hpp @@ -55,7 +55,7 @@ template struct basic_request : public basic_message { mutable boost::network::uri::uri uri_; - unsigned short source_port_; + boost::uint16_t source_port_; typedef basic_message base_type; public: @@ -113,9 +113,9 @@ struct basic_request : public basic_message { boost::network::uri::uri const& uri() const { return uri_; } - void source_port(const unsigned short port) { source_port_ = port; } + void source_port(const boost::uint16_t port) { source_port_ = port; } - unsigned short source_port() const { return source_port_; } + boost::uint16_t source_port() const { return source_port_; } }; /** This is the implementation of a POD request type