Skip to content
This repository was archived by the owner on Aug 19, 2019. It is now read-only.
2 changes: 1 addition & 1 deletion lib/cpp-netlib
Submodule cpp-netlib updated 414 files
31 changes: 19 additions & 12 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
LIBDIR=../lib
CPP_NETLIB_DIR=$(LIBDIR)/cpp-netlib
CPP_NETLIB_LIBDIR=$(CPP_NETLIB_DIR)/libs/network/src
NETWORK_URI_DIR=$(CPP_NETLIB_DIR)/deps/uri
NETWORK_URI_LIBDIR=$(NETWORK_URI_DIR)/src
YAML_CPP_DIR=$(LIBDIR)/yaml-cpp
YAML_CPP_LIBDIR=$(YAML_CPP_DIR)
SUBMODULE_DIRS=$(CPP_NETLIB_DIR) $(YAML_CPP_DIR)

SED_I=/usr/bin/env sed -i
CMAKE=cmake
CXXFLAGS=\
-std=c++11 -g -Wno-deprecated \
-std=c++11 -g -Wno-write-strings -Wno-deprecated \
-DENABLE_DOCKER_METADATA -DENABLE_KUBERNETES_METADATA \
-I$(CPP_NETLIB_DIR) -I$(YAML_CPP_DIR)/include
LDFLAGS=-L$(CPP_NETLIB_LIBDIR) -L$(YAML_CPP_LIBDIR)
LDLIBS=-lcppnetlib-uri -lcppnetlib-client-connections -lboost_program_options \
-lboost_system -lboost_thread -lpthread -lyajl -lssl -lcrypto -lyaml-cpp
SED_EXTRA=
-I$(CPP_NETLIB_DIR) -I$(NETWORK_URI_DIR)/include -I$(YAML_CPP_DIR)/include
LDFLAGS=-L$(CPP_NETLIB_LIBDIR) -L$(NETWORK_URI_LIBDIR) -L$(YAML_CPP_LIBDIR)
LDLIBS=\
-lcppnetlib-client-connections -lcppnetlib-server-parsers -lnetwork-uri \
-lboost_program_options -lboost_system -lboost_thread \
-lpthread -lyajl -lssl -lcrypto -lyaml-cpp
SED_EXTRA=-e 's/-Wall/-Wall -Wno-deprecated/'

UNAME_S=$(shell uname -s)
ifeq ($(UNAME_S),Darwin)
CXXFLAGS+= -Wno-deprecated-declarations -I/usr/local/include
CXXFLAGS+= -Wno-deprecated-declarations -Wno-c++14-extensions \
-I/usr/local/include
LDFLAGS+= -L/usr/local/lib
SED_I+= ''
SED_EXTRA+=-e \
SED_EXTRA+= -e \
's/-Wall/-Wall -Wno-deprecated-declarations -Wno-unused-local-typedef/'
endif

Expand All @@ -46,8 +51,9 @@ SRCS=\
OBJS=$(SRCS:%.cc=%.o)

CPP_NETLIB_LIBS=\
$(CPP_NETLIB_LIBDIR)/libcppnetlib-uri.a \
$(CPP_NETLIB_LIBDIR)/libcppnetlib-client-connections.a
$(CPP_NETLIB_LIBDIR)/libcppnetlib-client-connections.a \
$(CPP_NETLIB_LIBDIR)/libcppnetlib-server-parsers.a \
$(NETWORK_URI_LIBDIR)/libnetwork-uri.a
YAML_CPP_LIBS=\
$(YAML_CPP_LIBDIR)/libyaml-cpp.a
LIBS=$(CPP_NETLIB_LIBS) $(YAML_CPP_LIBS)
Expand Down Expand Up @@ -135,15 +141,16 @@ purge: clean
git submodule deinit -f $(SUBMODULE_DIRS)

init-submodules:
git submodule update --init $(SUBMODULE_DIRS)
git submodule update --init --recursive $(SUBMODULE_DIRS)
touch init-submodules

$(CPP_NETLIB_DIR)/Makefile: init-submodules
cd $(CPP_NETLIB_DIR) && \
$(SED_I) -e 's/unit_test_framework //' $(SED_EXTRA) CMakeLists.txt && \
$(CMAKE) -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS=-std=c++11 \
-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ \
-DCPP-NETLIB_BUILD_TESTS=OFF -DCPP-NETLIB_BUILD_EXAMPLES=OFF
-DCPP-NETLIB_BUILD_TESTS=OFF -DCPP-NETLIB_BUILD_EXAMPLES=OFF \
-DUri_BUILD_TESTS=OFF -DUri_BUILD_DOCS=OFF

$(CPP_NETLIB_LIBS): build-cpp-netlib

Expand Down
12 changes: 6 additions & 6 deletions src/api_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <boost/network/protocol/http/client.hpp>
#include <boost/network/protocol/http/server.hpp>
#include <boost/range/irange.hpp>
#include <memory>
#include <ostream>
#include <thread>

Expand Down Expand Up @@ -53,7 +54,7 @@ class MetadataApiServer {
public:
Handler(const MetadataAgent& agent);
void operator()(const HttpServer::request& request,
HttpServer::response& response);
std::shared_ptr<HttpServer::connection> conn);
void log(const HttpServer::string_type& info);
private:
const MetadataAgent& agent_;
Expand Down Expand Up @@ -90,7 +91,7 @@ MetadataApiServer::Handler::Handler(const MetadataAgent& agent)
: agent_(agent) {}

void MetadataApiServer::Handler::operator()(const HttpServer::request& request,
HttpServer::response& response) {
std::shared_ptr<HttpServer::connection> conn) {
static const std::string kPrefix = "/monitoredResource/";
// The format for the local metadata API request is:
// {host}:{port}/monitoredResource/{id}
Expand All @@ -111,15 +112,14 @@ void MetadataApiServer::Handler::operator()(const HttpServer::request& request,
if (agent_.config_.VerboseLogging()) {
LOG(WARNING) << "No matching resource for " << id;
}
response = HttpServer::response::stock_reply(
HttpServer::response::not_found, "");
conn->set_status(HttpServer::connection::not_found);
} else {
const MonitoredResource& resource = result->second;
if (agent_.config_.VerboseLogging()) {
LOG(INFO) << "Found resource for " << id << ": " << resource;
}
response = HttpServer::response::stock_reply(
HttpServer::response::ok, resource.ToJSON()->ToString());
conn->set_status(HttpServer::connection::ok);
conn->write(resource.ToJSON()->ToString());
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/asio/local_resolve_op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
#include <boost/asio/detail/operation.hpp>
#include <boost/asio/detail/socket_ops.hpp>
#include <boost/asio/detail/resolve_op.hpp>
#include <boost/network/uri.hpp>
#include <network/uri/detail/decode.hpp>
#include <sstream>
#include <sys/stat.h>

#include "../logging.h"
Expand Down Expand Up @@ -85,7 +86,7 @@ class resolve_op<Protocol, Handler> : public operation
o->ec_ = boost::asio::error::operation_aborted;
else {
//LOG(ERROR) << "async_resolve() " << o->query_.host_name();
std::string path = boost::network::uri::decoded(o->query_.host_name());
std::string path = ::network::detail::decode(o->query_.host_name());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nooby question, can you point me to docs that explain the :: prefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//LOG(ERROR) << "decoded " << path;
struct stat buffer;
int result = stat(path.c_str(), &buffer);
Expand Down Expand Up @@ -120,7 +121,7 @@ class resolve_op<Protocol, Handler> : public operation
p.h = boost::asio::detail::addressof(handler.handler_);
if (!o->ec_)
{
std::string path = boost::network::uri::decoded(o->query_.host_name());
std::string path = ::network::detail::decode(o->query_.host_name());
handler.arg2_ = iterator_type::create(
Protocol::endpoint(path),
path, o->query_.service_name());
Expand Down
4 changes: 2 additions & 2 deletions src/asio/local_resolver_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <boost/asio/detail/resolver_service_base.hpp>
#include <boost/asio/detail/resolver_service.hpp>
#include <boost/asio/detail/socket_ops.hpp>
#include <boost/network/uri.hpp>
#include <network/uri/detail/decode.hpp>
#include <sys/stat.h>

#include "../logging.h"
Expand Down Expand Up @@ -72,7 +72,7 @@ class resolver_service<Protocol> : public resolver_service_base
boost::system::error_code& ec)
{
//LOG(ERROR) << "resolve() " << query.host_name();
std::string path = boost::network::uri::decoded(query.host_name());
std::string path = ::network::detail::decode(query.host_name());
//LOG(ERROR) << "decoded " << path;
struct stat buffer;
int result = stat(path.c_str(), &buffer);
Expand Down
35 changes: 19 additions & 16 deletions src/http/local_async_connection_base.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_IMPL_LOCAL_ASYNC_CONNECTION_BASE_20170307
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this commit only comments on 6 out of the 10 files under src/http. Please add the provenance comments to the remaining 4 files, including "src/http/traits/local_resolver.hpp"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files that don't have the comments aren't replicas -- they are complete reimplementations that don't share enough code with the originals. The reason these files needed to be copied is because they weren't designed to be specialized -- I'll fix that upstream in a separate refactoring.

Copy link
Contributor

@supriyagarg supriyagarg Mar 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Since all names start with local_ it sounded like they were all copies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. local_ refers to "local sockets" (a.k.a., Unix domain sockets), rather than a "local copy".

#define BOOST_NETWORK_PROTOCOL_HTTP_IMPL_LOCAL_ASYNC_CONNECTION_BASE_20170307

// Note: This file is mostly a copy of
// boost/network/protocol/http/client/connection/async_base.hpp,
// except for the specialized bits.

// Copyright 2017 Igor Peshansky (igorp@google.com).
// Copyright 2013-2017 Google, Inc.
// Copyright 2010 Dean Michael Berris <dberris@google.com>
Expand All @@ -9,18 +13,18 @@
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <boost/network/traits/string.hpp>
#include <boost/network/protocol/http/response.hpp>
#include <boost/network/protocol/http/traits/delegate_factory.hpp>
#include "traits/local_resolver.hpp"
#include <boost/network/protocol/http/traits/resolver_policy.hpp>
#include <boost/network/traits/string.hpp>

namespace boost {
namespace network {
namespace http {
namespace impl {

template<class Tag, unsigned int version_major, unsigned int version_minor>
template <class Tag, unsigned version_major, unsigned version_minor>
struct async_connection_base;

template<class Tag, unsigned int version_major, unsigned int version_minor>
Expand All @@ -32,30 +36,32 @@ struct http_async_connection;

template<> struct async_connection_base<Tag, version_major, version_minor> {
typedef async_connection_base<Tag, version_major, version_minor> this_type;
typedef resolver_policy<Tag>::type resolver_base;
typedef resolver_base::resolver_type resolver_type;
typedef resolver_base::resolve_function resolve_function;
typedef string<Tag>::type string_type;
typedef typename resolver_policy<Tag>::type resolver_base;
typedef typename resolver_base::resolver_type resolver_type;
typedef typename resolver_base::resolve_function resolve_function;
typedef typename string<Tag>::type string_type;
typedef basic_request<Tag> request;
typedef basic_response<Tag> response;
typedef iterator_range<char const *> char_const_range;
typedef function<void(char_const_range const &, system::error_code const &)>
typedef typename std::array<typename char_<Tag>::type, 1024>::const_iterator const_iterator;
typedef iterator_range<const_iterator> char_const_range;
typedef std::function<void(char_const_range const &, boost::system::error_code const &)>
body_callback_function_type;
typedef function<bool(string_type &)> body_generator_function_type;
typedef shared_ptr<this_type> connection_ptr;
typedef std::function<bool(string_type &)> body_generator_function_type;
typedef std::shared_ptr<this_type> connection_ptr;

// This is the factory function which constructs the appropriate async
// connection implementation with the correct delegate chosen based on
// the
// connection implementation with the correct delegate chosen based on the
// tag.
static connection_ptr new_connection(
resolve_function resolve, resolver_type &resolver, bool follow_redirect,
bool always_verify_peer, bool https, int timeout,
bool remove_chunk_markers,
optional<string_type> certificate_filename = optional<string_type>(),
optional<string_type> const &verify_path = optional<string_type>(),
optional<string_type> certificate_file = optional<string_type>(),
optional<string_type> private_key_file = optional<string_type>(),
optional<string_type> ciphers = optional<string_type>(),
optional<string_type> sni_hostname = optional<string_type>(),
long ssl_options = 0);

// This is the pure virtual entry-point for all asynchronous
Expand All @@ -64,19 +70,16 @@ template<> struct async_connection_base<Tag, version_major, version_minor> {
bool get_body, body_callback_function_type callback,
body_generator_function_type generator) = 0;

virtual ~async_connection_base() {}
virtual ~async_connection_base() = default;
};

#undef version_minor
#undef version_major
#undef Tag

} // namespace impl

} // namespace http

} // namespace network

} // namespace boost

#endif // BOOST_NETWORK_PROTOCOL_HTTP_IMPL_LOCAL_ASYNC_CONNECTION_BASE_20170307
25 changes: 14 additions & 11 deletions src/http/local_async_connection_base.ipp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#ifndef BOOST_NETWORK_PROTOCOL_HTTP_IMPL_LOCAL_ASYNC_CONNECTION_BASE_IPP_20170307
#define BOOST_NETWORK_PROTOCOL_HTTP_IMPL_LOCAL_ASYNC_CONNECTION_BASE_IPP_20170307

// Note: This file is mostly a copy of
// boost/network/protocol/http/client/connection/async_base.hpp,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hpp -> ipp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, hpp is correct. The upstream library only has a single file. For various linker-related reasons, we had to split out the specialized function into its own implementation file.

// except for the specialized bits.

// Copyright 2017 Igor Peshansky (igorp@google.com).
// Copryight 2013-2017 Google, Inc.
// Copyright 2010 Dean Michael Berris <dberris@google.com>
Expand All @@ -27,23 +31,25 @@ using acb = async_connection_base<Tag, version_major, version_minor>;
acb::connection_ptr acb::new_connection(
acb::resolve_function resolve, acb::resolver_type &resolver,
bool follow_redirect, bool always_verify_peer, bool https, int timeout,
bool remove_chunk_markers,
optional<acb::string_type> certificate_filename,
optional<acb::string_type> const &verify_path,
optional<acb::string_type> certificate_file,
optional<acb::string_type> private_key_file,
optional<acb::string_type> ciphers,
optional<string_type> sni_hostname,
long ssl_options) {
typedef http_async_connection<Tag, version_major, version_minor>
async_connection;
typedef typename delegate_factory<Tag>::type delegate_factory_type;
connection_ptr temp;
temp.reset(new async_connection(
resolver, resolve, follow_redirect, timeout,
delegate_factory_type::new_connection_delegate(
resolver.get_io_service(), https, always_verify_peer,
certificate_filename, verify_path, certificate_file,
private_key_file, ciphers, ssl_options)));
BOOST_ASSERT(temp.get() != 0);
auto delegate = delegate_factory_type::new_connection_delegate(
resolver.get_io_service(), https, always_verify_peer,
certificate_filename, verify_path, certificate_file, private_key_file,
ciphers, sni_hostname, ssl_options);
auto temp = std::make_shared<async_connection>(
resolver, resolve, follow_redirect, timeout, remove_chunk_markers,
std::move(delegate));
BOOST_ASSERT(temp != nullptr);
return temp;
}

Expand All @@ -52,11 +58,8 @@ acb::connection_ptr acb::new_connection(
#undef Tag

} // namespace impl

} // namespace http

} // namespace network

} // namespace boost

#endif // BOOST_NETWORK_PROTOCOL_HTTP_IMPL_LOCAL_ASYNC_CONNECTION_BASE_IPP_20170307
Loading