From 96f71a1e472143104627739e6572a56a625c185e Mon Sep 17 00:00:00 2001 From: iceboy Date: Wed, 20 Nov 2024 17:10:03 -0800 Subject: [PATCH] net/proxy:interface move to trunk --- WORKSPACE | 2 +- net/proxy/BUILD | 19 +--- net/proxy/ares/BUILD | 4 +- net/proxy/ares/resolver.h | 6 +- net/proxy/ares/socket.cc | 21 +--- net/proxy/ares/socket.h | 6 +- net/proxy/connector.h | 52 --------- net/proxy/datagram.h | 34 ------ net/proxy/handler.h | 23 ---- net/proxy/http/BUILD | 4 +- net/proxy/http/h2-connection.h | 2 +- net/proxy/http/tls-stream.h | 2 +- net/proxy/misc/BUILD | 8 +- net/proxy/misc/echo-handler.h | 2 +- net/proxy/misc/null-handler.h | 2 +- net/proxy/misc/random-handler.h | 2 +- net/proxy/misc/zero-handler.h | 2 +- net/proxy/proxy.h | 4 +- net/proxy/registry.h | 4 +- net/proxy/route/BUILD | 2 +- net/proxy/route/connector.cc | 35 ++---- net/proxy/route/connector.h | 30 ++---- net/proxy/shadowsocks/BUILD | 4 +- net/proxy/shadowsocks/config.cc | 4 +- net/proxy/shadowsocks/connector.cc | 141 ++++++------------------- net/proxy/shadowsocks/connector.h | 27 ++--- net/proxy/shadowsocks/handler.cc | 18 ++-- net/proxy/shadowsocks/handler.h | 10 +- net/proxy/socks/BUILD | 2 +- net/proxy/socks/handler.cc | 22 ++-- net/proxy/socks/handler.h | 10 +- net/proxy/stream.h | 32 ------ net/proxy/system/BUILD | 11 +- net/proxy/system/connector.cc | 45 ++------ net/proxy/system/connector.h | 31 +++--- net/proxy/system/listener.h | 2 +- net/proxy/system/stdio-stream.h | 2 +- net/proxy/system/tcp-socket-stream.h | 2 +- net/proxy/system/udp-socket-datagram.h | 2 +- net/proxy/util/BUILD | 6 +- net/proxy/util/copy.h | 2 +- net/proxy/util/stream-wrapper.h | 2 +- net/proxy/util/write.h | 2 +- net/tools/miracle-proxy.cc | 4 +- 44 files changed, 165 insertions(+), 482 deletions(-) delete mode 100644 net/proxy/connector.h delete mode 100644 net/proxy/datagram.h delete mode 100644 net/proxy/handler.h delete mode 100644 net/proxy/stream.h diff --git a/WORKSPACE b/WORKSPACE index ce21f94..0595b20 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -47,6 +47,6 @@ boost_deps() git_repository( name = "org_iceboy_trunk", - commit = "24fc6171c1512293423d9c2fb093ac2bec86f728", + commit = "ee7aa17695b5b8e65171b23fba3a13a4c6632d64", remote = "https://github.com/iceboy233/trunk.git", ) diff --git a/net/proxy/BUILD b/net/proxy/BUILD index 220db68..2178e67 100644 --- a/net/proxy/BUILD +++ b/net/proxy/BUILD @@ -1,32 +1,17 @@ package(default_visibility = ["//visibility:public"]) -cc_library( - name = "interface", - hdrs = [ - "connector.h", - "datagram.h", - "handler.h", - "stream.h", - ], - deps = [ - "@com_google_absl//absl/functional:any_invocable", - "@com_google_absl//absl/types:span", - "@org_iceboy_trunk//net:asio", - ] -) - cc_library( name = "proxy", srcs = ["proxy.cc"], hdrs = ["proxy.h"], deps = [ - ":interface", ":registry", "//net/proxy/system:listener", "@com_google_absl//absl/container:flat_hash_map", "@org_boost_boost//:property_tree", "@org_iceboy_trunk//base:logging", "@org_iceboy_trunk//net:asio", + "@org_iceboy_trunk//net/interface", ], ) @@ -35,11 +20,11 @@ cc_library( srcs = ["registry.cc"], hdrs = ["registry.h"], deps = [ - ":interface", "@com_google_absl//absl/container:flat_hash_map", "@com_google_absl//absl/functional:any_invocable", "@org_boost_boost//:property_tree", "@org_iceboy_trunk//base:logging", "@org_iceboy_trunk//net:asio", + "@org_iceboy_trunk//net/interface", ], ) diff --git a/net/proxy/ares/BUILD b/net/proxy/ares/BUILD index 8636711..d0ba284 100644 --- a/net/proxy/ares/BUILD +++ b/net/proxy/ares/BUILD @@ -14,7 +14,6 @@ cc_library( deps = [ ":error-category", ":socket", - "//net/proxy:interface", "//third_party/cares", "//util:int-allocator", "@com_google_absl//absl/container:flat_hash_map", @@ -23,6 +22,7 @@ cc_library( "@org_iceboy_trunk//net:asio", "@org_iceboy_trunk//net:endpoint", "@org_iceboy_trunk//net:timer-list", + "@org_iceboy_trunk//net/interface", ], ) @@ -31,10 +31,10 @@ cc_library( srcs = ["socket.cc"], hdrs = ["socket.h"], deps = [ - "//net/proxy:interface", "//net/proxy/util:write", "//third_party/cares", "@org_boost_boost//:smart_ptr", "@org_iceboy_trunk//net:asio", + "@org_iceboy_trunk//net/interface", ], ) diff --git a/net/proxy/ares/resolver.h b/net/proxy/ares/resolver.h index ffbf2e7..f461c68 100644 --- a/net/proxy/ares/resolver.h +++ b/net/proxy/ares/resolver.h @@ -12,9 +12,9 @@ #include "absl/types/span.h" #include "net/asio.h" #include "net/endpoint.h" -#include "net/proxy/ares/socket.h" -#include "net/proxy/connector.h" #include "net/timer-list.h" +#include "net/interface/connector.h" +#include "net/proxy/ares/socket.h" #include "util/int-allocator.h" namespace net { @@ -64,7 +64,7 @@ class Resolver { static const ares_socket_functions funcs_; any_io_executor executor_; - proxy::Connector &connector_; + Connector &connector_; ares_channel channel_ = nullptr; steady_timer wait_timer_; TimerList cache_timer_list_; diff --git a/net/proxy/ares/socket.cc b/net/proxy/ares/socket.cc index d7d6286..27afbac 100644 --- a/net/proxy/ares/socket.cc +++ b/net/proxy/ares/socket.cc @@ -100,13 +100,7 @@ int TcpSocket::connect(const sockaddr *addr, ares_socklen_t addr_len) { } ares_process_fd(socket->channel_, socket->fd_, socket->fd_); }; - if (address.is_v4()) { - connector_.connect_tcp_v4( - address.to_v4(), port, {}, std::move(callback)); - } else { - connector_.connect_tcp_v6( - address.to_v6(), port, {}, std::move(callback)); - } + connector_.connect({address, port}, {}, std::move(callback)); SET_ERRNO(EINPROGRESS); return -1; } @@ -198,16 +192,11 @@ int UdpSocket::connect(const sockaddr *addr, ares_socklen_t addr_len) { SET_ERRNO(EINVAL); return -1; } - if (address.is_v4()) { - if (connector_.bind_udp_v4(datagram_)) { - return -1; - } - } else { - if (connector_.bind_udp_v6(datagram_)) { - return -1; - } + udp::endpoint endpoint(address, port); + if (connector_.bind({endpoint.protocol(), 0}, datagram_)) { + return -1; } - send_endpoint_ = udp::endpoint(address, port); + send_endpoint_ = endpoint; post(executor_, [socket = boost::intrusive_ptr(this)]() { ares_process_fd(socket->channel_, socket->fd_, socket->fd_); }); diff --git a/net/proxy/ares/socket.h b/net/proxy/ares/socket.h index b02f58f..843eefc 100644 --- a/net/proxy/ares/socket.h +++ b/net/proxy/ares/socket.h @@ -8,9 +8,9 @@ #include #include "net/asio.h" -#include "net/proxy/connector.h" -#include "net/proxy/datagram.h" -#include "net/proxy/stream.h" +#include "net/interface/connector.h" +#include "net/interface/datagram.h" +#include "net/interface/stream.h" namespace net { namespace proxy { diff --git a/net/proxy/connector.h b/net/proxy/connector.h deleted file mode 100644 index c258c40..0000000 --- a/net/proxy/connector.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef _NET_PROXY_CONNECTOR_H -#define _NET_PROXY_CONNECTOR_H - -#include -#include -#include -#include - -#include "absl/functional/any_invocable.h" -#include "net/asio.h" -#include "net/proxy/datagram.h" -#include "net/proxy/stream.h" - -namespace net { -namespace proxy { - -class Connector { -public: - virtual ~Connector() = default; - - virtual void connect_tcp_v4( - const address_v4 &address, - uint16_t port, - const_buffer initial_data, - absl::AnyInvocable) &&> callback) = 0; - - virtual void connect_tcp_v6( - const address_v6 &address, - uint16_t port, - const_buffer initial_data, - absl::AnyInvocable) &&> callback) = 0; - - virtual void connect_tcp_host( - std::string_view host, - uint16_t port, - const_buffer initial_data, - absl::AnyInvocable) &&> callback) = 0; - - virtual std::error_code bind_udp_v4( - std::unique_ptr &datagram) = 0; - - virtual std::error_code bind_udp_v6( - std::unique_ptr &datagram) = 0; -}; - -} // namespace proxy -} // namespace net - -#endif // _NET_PROXY_CONNECTOR_H diff --git a/net/proxy/datagram.h b/net/proxy/datagram.h deleted file mode 100644 index 59494e0..0000000 --- a/net/proxy/datagram.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _NET_PROXY_DATAGRAM_H -#define _NET_PROXY_DATAGRAM_H - -#include -#include - -#include "absl/functional/any_invocable.h" -#include "absl/types/span.h" -#include "net/asio.h" - -namespace net { -namespace proxy { - -class Datagram { -public: - virtual ~Datagram() = default; - - virtual void receive_from( - absl::Span buffers, - udp::endpoint &endpoint, - absl::AnyInvocable callback) = 0; - - virtual void send_to( - absl::Span buffers, - const udp::endpoint &endpoint, - absl::AnyInvocable callback) = 0; - - virtual void close() = 0; -}; - -} // namespace proxy -} // namespace net - -#endif // _NET_PROXY_DATAGRAM_H diff --git a/net/proxy/handler.h b/net/proxy/handler.h deleted file mode 100644 index c1956b8..0000000 --- a/net/proxy/handler.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef _NET_PROXY_HANDLER_H -#define _NET_PROXY_HANDLER_H - -#include - -#include "net/proxy/datagram.h" -#include "net/proxy/stream.h" - -namespace net { -namespace proxy { - -class Handler { -public: - virtual ~Handler() = default; - - virtual void handle_stream(std::unique_ptr stream) = 0; - virtual void handle_datagram(std::unique_ptr datagram) = 0; -}; - -} // namespace proxy -} // namespace net - -#endif // _NET_PROXY_HANDLER_H diff --git a/net/proxy/http/BUILD b/net/proxy/http/BUILD index 4ac972e..a39ce6a 100644 --- a/net/proxy/http/BUILD +++ b/net/proxy/http/BUILD @@ -3,7 +3,6 @@ cc_library( srcs = ["h2-connection.cc"], hdrs = ["h2-connection.h"], deps = [ - "//net/proxy:interface", "//net/proxy/util:write", "//third_party/nghttp2", "@com_google_absl//absl/container:fixed_array", @@ -11,6 +10,7 @@ cc_library( "@com_google_absl//absl/functional:any_invocable", "@com_google_absl//absl/types:span", "@org_iceboy_trunk//base:logging", + "@org_iceboy_trunk//net/interface", "@org_iceboy_trunk//util:strings", ], ) @@ -20,9 +20,9 @@ cc_library( srcs = ["tls-stream.cc"], hdrs = ["tls-stream.h"], deps = [ - "//net/proxy:interface", "//net/proxy/util:stream-wrapper", "@boringssl//:ssl", "@com_google_absl//absl/container:fixed_array", + "@org_iceboy_trunk//net/interface", ], ) diff --git a/net/proxy/http/h2-connection.h b/net/proxy/http/h2-connection.h index 93c4b47..9a3f0ca 100644 --- a/net/proxy/http/h2-connection.h +++ b/net/proxy/http/h2-connection.h @@ -13,7 +13,7 @@ #include "absl/container/flat_hash_map.h" #include "absl/functional/any_invocable.h" #include "absl/types/span.h" -#include "net/proxy/stream.h" +#include "net/interface/stream.h" namespace net { namespace proxy { diff --git a/net/proxy/http/tls-stream.h b/net/proxy/http/tls-stream.h index 2d69019..c1eb5fc 100644 --- a/net/proxy/http/tls-stream.h +++ b/net/proxy/http/tls-stream.h @@ -2,7 +2,7 @@ #define _NET_PROXY_HTTP_TLS_STREAM_H #include "boost/asio/ssl.hpp" -#include "net/proxy/stream.h" +#include "net/interface/stream.h" #include "net/proxy/util/stream-wrapper.h" namespace net { diff --git a/net/proxy/misc/BUILD b/net/proxy/misc/BUILD index 7c7d38d..7d261fd 100644 --- a/net/proxy/misc/BUILD +++ b/net/proxy/misc/BUILD @@ -18,9 +18,9 @@ cc_library( srcs = ["echo-handler.cc"], hdrs = ["echo-handler.h"], deps = [ - "//net/proxy:interface", "//net/proxy/util:write", "@com_google_absl//absl/container:fixed_array", + "@org_iceboy_trunk//net/interface", ], ) @@ -29,8 +29,8 @@ cc_library( srcs = ["null-handler.cc"], hdrs = ["null-handler.h"], deps = [ - "//net/proxy:interface", "@com_google_absl//absl/container:fixed_array", + "@org_iceboy_trunk//net/interface", ], ) @@ -39,9 +39,9 @@ cc_library( srcs = ["random-handler.cc"], hdrs = ["random-handler.h"], deps = [ - "//net/proxy:interface", "@boringssl//:crypto", "@com_google_absl//absl/container:fixed_array", + "@org_iceboy_trunk//net/interface", ], ) @@ -50,7 +50,7 @@ cc_library( srcs = ["zero-handler.cc"], hdrs = ["zero-handler.h"], deps = [ - "//net/proxy:interface", "@com_google_absl//absl/container:fixed_array", + "@org_iceboy_trunk//net/interface", ], ) diff --git a/net/proxy/misc/echo-handler.h b/net/proxy/misc/echo-handler.h index b2db891..9a40f06 100644 --- a/net/proxy/misc/echo-handler.h +++ b/net/proxy/misc/echo-handler.h @@ -1,7 +1,7 @@ #ifndef _NET_PROXY_MISC_ECHO_HANDLER_H #define _NET_PROXY_MISC_ECHO_HANDLER_H -#include "net/proxy/handler.h" +#include "net/interface/handler.h" namespace net { namespace proxy { diff --git a/net/proxy/misc/null-handler.h b/net/proxy/misc/null-handler.h index 2d4bfac..be9e406 100644 --- a/net/proxy/misc/null-handler.h +++ b/net/proxy/misc/null-handler.h @@ -1,7 +1,7 @@ #ifndef _NET_PROXY_MISC_NULL_HANDLER_H #define _NET_PROXY_MISC_NULL_HANDLER_H -#include "net/proxy/handler.h" +#include "net/interface/handler.h" namespace net { namespace proxy { diff --git a/net/proxy/misc/random-handler.h b/net/proxy/misc/random-handler.h index b055d9f..6b69824 100644 --- a/net/proxy/misc/random-handler.h +++ b/net/proxy/misc/random-handler.h @@ -1,7 +1,7 @@ #ifndef _NET_PROXY_MISC_RANDOM_HANDLER_H #define _NET_PROXY_MISC_RANDOM_HANDLER_H -#include "net/proxy/handler.h" +#include "net/interface/handler.h" namespace net { namespace proxy { diff --git a/net/proxy/misc/zero-handler.h b/net/proxy/misc/zero-handler.h index ea90572..020a926 100644 --- a/net/proxy/misc/zero-handler.h +++ b/net/proxy/misc/zero-handler.h @@ -1,7 +1,7 @@ #ifndef _NET_PROXY_MISC_ZERO_HANDLER_H #define _NET_PROXY_MISC_ZERO_HANDLER_H -#include "net/proxy/handler.h" +#include "net/interface/handler.h" namespace net { namespace proxy { diff --git a/net/proxy/proxy.h b/net/proxy/proxy.h index 74d9acb..43fe4e7 100644 --- a/net/proxy/proxy.h +++ b/net/proxy/proxy.h @@ -9,8 +9,8 @@ #include "absl/container/flat_hash_map.h" #include "net/asio.h" -#include "net/proxy/connector.h" -#include "net/proxy/handler.h" +#include "net/interface/connector.h" +#include "net/interface/handler.h" #include "net/proxy/system/listener.h" namespace net { diff --git a/net/proxy/registry.h b/net/proxy/registry.h index 3b9028c..4f50b92 100644 --- a/net/proxy/registry.h +++ b/net/proxy/registry.h @@ -8,8 +8,8 @@ #include "absl/container/flat_hash_map.h" #include "absl/functional/any_invocable.h" #include "net/asio.h" -#include "net/proxy/connector.h" -#include "net/proxy/handler.h" +#include "net/interface/connector.h" +#include "net/interface/handler.h" namespace net { namespace proxy { diff --git a/net/proxy/route/BUILD b/net/proxy/route/BUILD index 41921db..c56f686 100644 --- a/net/proxy/route/BUILD +++ b/net/proxy/route/BUILD @@ -18,7 +18,7 @@ cc_library( hdrs = ["connector.h"], deps = [ ":host-matcher", - "//net/proxy:interface", + "@org_iceboy_trunk//net/interface", ], ) diff --git a/net/proxy/route/connector.cc b/net/proxy/route/connector.cc index 4d29e98..1ad7c54 100644 --- a/net/proxy/route/connector.cc +++ b/net/proxy/route/connector.cc @@ -22,25 +22,8 @@ Connector::Connector(absl::Span rules) { host_matcher_.build(); } -void Connector::connect_tcp_v4( - const address_v4 &address, - uint16_t port, - const_buffer initial_data, - absl::AnyInvocable) &&> callback) { - // TODO - auto *connector = default_connector_; - if (!connector) { - std::move(callback)( - make_error_code(std::errc::network_unreachable), nullptr); - return; - } - connector->connect_tcp_v4(address, port, initial_data, std::move(callback)); -} - -void Connector::connect_tcp_v6( - const address_v6 &address, - uint16_t port, +void Connector::connect( + const tcp::endpoint &endpoint, const_buffer initial_data, absl::AnyInvocable) &&> callback) { @@ -51,10 +34,10 @@ void Connector::connect_tcp_v6( make_error_code(std::errc::network_unreachable), nullptr); return; } - connector->connect_tcp_v6(address, port, initial_data, std::move(callback)); + connector->connect(endpoint, initial_data, std::move(callback)); } -void Connector::connect_tcp_host( +void Connector::connect( std::string_view host, uint16_t port, const_buffer initial_data, @@ -67,15 +50,11 @@ void Connector::connect_tcp_host( make_error_code(std::errc::network_unreachable), nullptr); return; } - connector->connect_tcp_host(host, port, initial_data, std::move(callback)); -} - -std::error_code Connector::bind_udp_v4(std::unique_ptr &datagram) { - // TODO - return make_error_code(std::errc::operation_not_supported); + connector->connect(host, port, initial_data, std::move(callback)); } -std::error_code Connector::bind_udp_v6(std::unique_ptr &datagram) { +std::error_code Connector::bind( + const udp::endpoint &endpoint, std::unique_ptr &datagram) { // TODO return make_error_code(std::errc::operation_not_supported); } diff --git a/net/proxy/route/connector.h b/net/proxy/route/connector.h index b68fc5a..4b8aba4 100644 --- a/net/proxy/route/connector.h +++ b/net/proxy/route/connector.h @@ -3,55 +3,45 @@ #include -#include "net/proxy/connector.h" +#include "net/interface/connector.h" #include "net/proxy/route/host-matcher.h" namespace net { namespace proxy { namespace route { -class Connector : public proxy::Connector { +class Connector : public net::Connector { public: struct Rule { std::vector hosts; std::vector host_suffixes; bool is_default = false; - proxy::Connector *connector = nullptr; + net::Connector *connector = nullptr; }; explicit Connector(absl::Span rules); - void connect_tcp_v4( - const address_v4 &address, - uint16_t port, - const_buffer initial_data, - absl::AnyInvocable) &&> callback) override; - - void connect_tcp_v6( - const address_v6 &address, - uint16_t port, + void connect( + const tcp::endpoint &endpoint, const_buffer initial_data, absl::AnyInvocable) &&> callback) override; - void connect_tcp_host( + void connect( std::string_view host, uint16_t port, const_buffer initial_data, absl::AnyInvocable) &&> callback) override; - std::error_code bind_udp_v4( - std::unique_ptr &datagram) override; - - std::error_code bind_udp_v6( + std::error_code bind( + const udp::endpoint &endpoint, std::unique_ptr &datagram) override; private: HostMatcher host_matcher_; - std::vector connectors_; - proxy::Connector *default_connector_ = nullptr; + std::vector connectors_; + net::Connector *default_connector_ = nullptr; }; } // namespace route diff --git a/net/proxy/shadowsocks/BUILD b/net/proxy/shadowsocks/BUILD index f9c0ee9..9952294 100644 --- a/net/proxy/shadowsocks/BUILD +++ b/net/proxy/shadowsocks/BUILD @@ -22,11 +22,11 @@ cc_library( ":encryptor", ":pre-shared-key", ":salt-filter", - "//net/proxy:interface", "//net/proxy/util:write", "@com_google_absl//absl/random", "@org_iceboy_trunk//base:logging", "@org_iceboy_trunk//net:endpoint", + "@org_iceboy_trunk//net/interface", ], ) @@ -65,10 +65,10 @@ cc_library( ":pre-shared-key", ":salt-filter", ":session-subkey", - "//net/proxy:interface", "//net/proxy/util:write", "@com_google_absl//absl/container:fixed_array", "@org_iceboy_trunk//base:logging", + "@org_iceboy_trunk//net/interface", ], ) diff --git a/net/proxy/shadowsocks/config.cc b/net/proxy/shadowsocks/config.cc index 3f2735a..0df2469 100644 --- a/net/proxy/shadowsocks/config.cc +++ b/net/proxy/shadowsocks/config.cc @@ -64,7 +64,7 @@ REGISTER_HANDLER(shadowsocks, []( return nullptr; } options.password = config.password; - proxy::Connector *connector = proxy.get_connector(config.connector); + net::Connector *connector = proxy.get_connector(config.connector); if (!connector) { LOG(error) << "invalid connector: " << config.connector; return nullptr; @@ -97,7 +97,7 @@ REGISTER_CONNECTOR(shadowsocks, []( options.password = config.password; options.min_padding_length = config.min_padding_length; options.max_padding_length = config.max_padding_length; - proxy::Connector *base_connector = proxy.get_connector(config.connector); + net::Connector *base_connector = proxy.get_connector(config.connector); if (!base_connector) { LOG(error) << "invalid connector: " << config.connector; return nullptr; diff --git a/net/proxy/shadowsocks/connector.cc b/net/proxy/shadowsocks/connector.cc index 09db9fb..05d664f 100644 --- a/net/proxy/shadowsocks/connector.cc +++ b/net/proxy/shadowsocks/connector.cc @@ -5,28 +5,21 @@ #include #include "base/logging.h" +#include "net/interface/stream.h" #include "net/proxy/shadowsocks/decryptor.h" #include "net/proxy/shadowsocks/encryptor.h" -#include "net/proxy/stream.h" #include "net/proxy/util/write.h" namespace net { namespace proxy { namespace shadowsocks { -class Connector::TcpStream : public proxy::Stream { +class Connector::TcpStream : public net::Stream { public: explicit TcpStream(Connector &connector); void start( - const net::address_v4 &address, - uint16_t port, - const_buffer initial_data, - absl::AnyInvocable callback); - - void start( - const net::address_v6 &address, - uint16_t port, + const tcp::endpoint &endpoint, const_buffer initial_data, absl::AnyInvocable callback); @@ -84,37 +77,14 @@ bool Connector::init(const InitOptions &options) { return true; } -void Connector::connect_tcp_v4( - const address_v4 &address, - uint16_t port, - const_buffer initial_data, - absl::AnyInvocable) &&> callback) { - auto stream = std::make_unique(*this); - stream->start( - address, - port, - initial_data, - [stream = std::move(stream), callback = std::move(callback)]( - std::error_code ec) mutable { - if (ec) { - std::move(callback)(ec, nullptr); - return; - } - std::move(callback)({}, std::move(stream)); - }); -} - -void Connector::connect_tcp_v6( - const address_v6 &address, - uint16_t port, +void Connector::connect( + const tcp::endpoint &endpoint, const_buffer initial_data, absl::AnyInvocable) &&> callback) { auto stream = std::make_unique(*this); stream->start( - address, - port, + endpoint, initial_data, [stream = std::move(stream), callback = std::move(callback)]( std::error_code ec) mutable { @@ -126,7 +96,7 @@ void Connector::connect_tcp_v6( }); } -void Connector::connect_tcp_host( +void Connector::connect( std::string_view host, uint16_t port, const_buffer initial_data, @@ -147,12 +117,9 @@ void Connector::connect_tcp_host( }); } -std::error_code Connector::bind_udp_v4(std::unique_ptr &datagram) { - // TODO - return make_error_code(std::errc::operation_not_supported); -} - -std::error_code Connector::bind_udp_v6(std::unique_ptr &datagram) { +std::error_code Connector::bind( + const udp::endpoint &endpoint, + std::unique_ptr &datagram) { // TODO return make_error_code(std::errc::operation_not_supported); } @@ -161,8 +128,7 @@ Connector::TcpStream::TcpStream(Connector &connector) : connector_(connector) {} void Connector::TcpStream::start( - const net::address_v4 &address, - uint16_t port, + const tcp::endpoint &endpoint, const_buffer initial_data, absl::AnyInvocable callback) { encryptor_.init(connector_.pre_shared_key_); @@ -170,6 +136,8 @@ void Connector::TcpStream::start( encryptor_.salt(), connector_.pre_shared_key_.method().salt_size()}); // TODO: split chunks if too large encryptor_.start_chunk(); + address address = endpoint.address(); + size_t address_size = address.is_v4() ? 4 : 16; size_t padding_size = absl::Uniform( connector_.bit_gen_, connector_.min_padding_length_, @@ -179,52 +147,21 @@ void Connector::TcpStream::start( encryptor_.push_big_u64( std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()).count()); - encryptor_.push_big_u16(padding_size + initial_data.size() + 9); + encryptor_.push_big_u16( + address_size + padding_size + initial_data.size() + 5); } else { - encryptor_.push_big_u16(initial_data.size() + 7); + encryptor_.push_big_u16(address_size + initial_data.size() + 3); } encryptor_.finish_chunk(); encryptor_.start_chunk(); - encryptor_.push_u8(1); // ipv4 - encryptor_.push_buffer(address.to_bytes()); - encryptor_.push_big_u16(port); - if (connector_.pre_shared_key_.method().is_spec_2022()) { - encryptor_.push_big_u16(padding_size); - encryptor_.push_random(padding_size); - } - encryptor_.push_buffer({initial_data.data(), initial_data.size()}); - encryptor_.finish_chunk(); - connect(std::move(callback)); -} - -void Connector::TcpStream::start( - const net::address_v6 &address, - uint16_t port, - const_buffer initial_data, - absl::AnyInvocable callback) { - encryptor_.init(connector_.pre_shared_key_); - connector_.salt_filter_.insert({ - encryptor_.salt(), connector_.pre_shared_key_.method().salt_size()}); - // TODO: split chunks if too large - encryptor_.start_chunk(); - size_t padding_size = absl::Uniform( - connector_.bit_gen_, - connector_.min_padding_length_, - connector_.max_padding_length_); - if (connector_.pre_shared_key_.method().is_spec_2022()) { - encryptor_.push_u8(0); // request - encryptor_.push_big_u64( - std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()).count()); - encryptor_.push_big_u16(padding_size + initial_data.size() + 21); + if (address.is_v4()) { + encryptor_.push_u8(1); // ipv4 + encryptor_.push_buffer(address.to_v4().to_bytes()); } else { - encryptor_.push_big_u16(initial_data.size() + 19); + encryptor_.push_u8(4); // ipv6 + encryptor_.push_buffer(address.to_v6().to_bytes()); } - encryptor_.finish_chunk(); - encryptor_.start_chunk(); - encryptor_.push_u8(4); // ipv6 - encryptor_.push_buffer(address.to_bytes()); - encryptor_.push_big_u16(port); + encryptor_.push_big_u16(endpoint.port()); if (connector_.pre_shared_key_.method().is_spec_2022()) { encryptor_.push_big_u16(padding_size); encryptor_.push_random(padding_size); @@ -276,32 +213,22 @@ void Connector::TcpStream::start( void Connector::TcpStream::connect( absl::AnyInvocable callback) { ConstBufferSpan write_buffer = encryptor_.buffer(); - auto wrapped_callback = [this, callback = std::move(callback)]( - std::error_code ec, std::unique_ptr stream) mutable { - if (ec) { - std::move(callback)(ec); - return; - } - base_stream_ = std::move(stream); - std::move(callback)({}); - }; const Endpoint &endpoint = *connector_.endpoints_iter_++; if (connector_.endpoints_iter_ == connector_.endpoints_.end()) { connector_.endpoints_iter_ = connector_.endpoints_.begin(); } - if (endpoint.address().is_v4()) { - connector_.base_connector_.connect_tcp_v4( - endpoint.address().to_v4(), - endpoint.port(), - buffer(write_buffer.data(), write_buffer.size()), - std::move(wrapped_callback)); - } else { - connector_.base_connector_.connect_tcp_v6( - endpoint.address().to_v6(), - endpoint.port(), - buffer(write_buffer.data(), write_buffer.size()), - std::move(wrapped_callback)); - } + connector_.base_connector_.connect( + endpoint, + buffer(write_buffer.data(), write_buffer.size()), + [this, callback = std::move(callback)]( + std::error_code ec, std::unique_ptr stream) mutable { + if (ec) { + std::move(callback)(ec); + return; + } + base_stream_ = std::move(stream); + std::move(callback)({}); + }); } void Connector::TcpStream::read( diff --git a/net/proxy/shadowsocks/connector.h b/net/proxy/shadowsocks/connector.h index 42be2af..b76ee2d 100644 --- a/net/proxy/shadowsocks/connector.h +++ b/net/proxy/shadowsocks/connector.h @@ -8,7 +8,7 @@ #include "absl/random/random.h" #include "net/endpoint.h" -#include "net/proxy/connector.h" +#include "net/interface/connector.h" #include "net/proxy/shadowsocks/method.h" #include "net/proxy/shadowsocks/pre-shared-key.h" #include "net/proxy/shadowsocks/salt-filter.h" @@ -17,9 +17,9 @@ namespace net { namespace proxy { namespace shadowsocks { -class Connector : public proxy::Connector { +class Connector : public net::Connector { public: - explicit Connector(proxy::Connector &base_connector) + explicit Connector(net::Connector &base_connector) : base_connector_(base_connector) {} Connector(const Connector &) = delete; @@ -35,34 +35,27 @@ class Connector : public proxy::Connector { bool init(const InitOptions &options); - void connect_tcp_v4( - const address_v4 &address, - uint16_t port, - const_buffer initial_data, - absl::AnyInvocable) &&> callback) override; - - void connect_tcp_v6( - const address_v6 &address, - uint16_t port, + void connect( + const tcp::endpoint &endpoint, const_buffer initial_data, absl::AnyInvocable) &&> callback) override; - void connect_tcp_host( + void connect( std::string_view host, uint16_t port, const_buffer initial_data, absl::AnyInvocable) &&> callback) override; - std::error_code bind_udp_v4(std::unique_ptr &datagram) override; - std::error_code bind_udp_v6(std::unique_ptr &datagram) override; + std::error_code bind( + const udp::endpoint &endpoint, + std::unique_ptr &datagram) override; private: class TcpStream; - proxy::Connector &base_connector_; + net::Connector &base_connector_; std::vector endpoints_; std::vector::iterator endpoints_iter_; PreSharedKey pre_shared_key_; diff --git a/net/proxy/shadowsocks/handler.cc b/net/proxy/shadowsocks/handler.cc index 909f473..4bd6979 100644 --- a/net/proxy/shadowsocks/handler.cc +++ b/net/proxy/shadowsocks/handler.cc @@ -207,10 +207,8 @@ void Handler::TcpConnection::forward_parse_ipv4(size_t header_length) { const_buffer initial_data( decryptor_.pop_buffer(initial_data_length), initial_data_length); - handler_.connector_.connect_tcp_v4( - address_v4(address_bytes), - port, - initial_data, + handler_.connector_.connect( + {address_v4(address_bytes), port}, initial_data, [connection = boost::intrusive_ptr(this)]( std::error_code ec, std::unique_ptr stream) { if (ec) { @@ -259,10 +257,8 @@ void Handler::TcpConnection::forward_parse_ipv6(size_t header_length) { const_buffer initial_data( decryptor_.pop_buffer(initial_data_length), initial_data_length); - handler_.connector_.connect_tcp_v6( - address_v6(address_bytes), - port, - initial_data, + handler_.connector_.connect( + {address_v6(address_bytes), port}, initial_data, [connection = boost::intrusive_ptr(this)]( std::error_code ec, std::unique_ptr stream) { if (ec) { @@ -311,10 +307,8 @@ void Handler::TcpConnection::forward_parse_host(size_t header_length) { const_buffer initial_data( decryptor_.pop_buffer(initial_data_length), initial_data_length); - handler_.connector_.connect_tcp_host( - host, - port, - initial_data, + handler_.connector_.connect( + host, port, initial_data, [connection = boost::intrusive_ptr(this)]( std::error_code ec, std::unique_ptr stream) { if (ec) { diff --git a/net/proxy/shadowsocks/handler.h b/net/proxy/shadowsocks/handler.h index 762268a..5c55caf 100644 --- a/net/proxy/shadowsocks/handler.h +++ b/net/proxy/shadowsocks/handler.h @@ -2,8 +2,8 @@ #define _NET_PROXY_SHADOWSOCKS_HANDLER_H #include "net/asio.h" -#include "net/proxy/connector.h" -#include "net/proxy/handler.h" +#include "net/interface/connector.h" +#include "net/interface/handler.h" #include "net/proxy/shadowsocks/pre-shared-key.h" #include "net/proxy/shadowsocks/salt-filter.h" @@ -11,9 +11,9 @@ namespace net { namespace proxy { namespace shadowsocks { -class Handler : public proxy::Handler { +class Handler : public net::Handler { public: - explicit Handler(proxy::Connector &connector) + explicit Handler(net::Connector &connector) : connector_(connector) {} struct InitOptions { @@ -29,7 +29,7 @@ class Handler : public proxy::Handler { private: class TcpConnection; - proxy::Connector &connector_; + net::Connector &connector_; PreSharedKey pre_shared_key_; SaltFilter salt_filter_; }; diff --git a/net/proxy/socks/BUILD b/net/proxy/socks/BUILD index 32a473f..dee7b7f 100644 --- a/net/proxy/socks/BUILD +++ b/net/proxy/socks/BUILD @@ -17,7 +17,6 @@ cc_library( srcs = ["handler.cc"], hdrs = ["handler.h"], deps = [ - "//net/proxy:interface", "//net/proxy/util:write", "@com_google_absl//absl/algorithm", "@com_google_absl//absl/container:fixed_array", @@ -25,5 +24,6 @@ cc_library( "@org_iceboy_trunk//base:logging", "@org_iceboy_trunk//base:types", "@org_iceboy_trunk//net:asio", + "@org_iceboy_trunk//net/interface", ], ) diff --git a/net/proxy/socks/handler.cc b/net/proxy/socks/handler.cc index b212387..24067eb 100644 --- a/net/proxy/socks/handler.cc +++ b/net/proxy/socks/handler.cc @@ -53,7 +53,7 @@ class Handler::TcpConnection : public boost::intrusive_ref_counter< size_t backward_size_; }; -Handler::Handler(const any_io_executor &executor, proxy::Connector &connector) +Handler::Handler(const any_io_executor &executor, net::Connector &connector) : connector_(connector) {} void Handler::handle_stream(std::unique_ptr stream) { @@ -170,10 +170,9 @@ void Handler::TcpConnection::connect_ipv4(ConstBufferSpan buffer) { buffer.remove_prefix(6); forward_size_ = 0; state_ = State::connect; - handler_.connector_.connect_tcp_v4( - address_v4(address_bytes), - port, - net::buffer(buffer.data(), buffer.size()), + handler_.connector_.connect( + {address_v4(address_bytes), port}, + {buffer.data(), buffer.size()}, [connection = boost::intrusive_ptr(this)]( std::error_code ec, std::unique_ptr stream) { if (ec) { @@ -196,10 +195,9 @@ void Handler::TcpConnection::connect_ipv6(ConstBufferSpan buffer) { buffer.remove_prefix(18); forward_size_ = 0; state_ = State::connect; - handler_.connector_.connect_tcp_v6( - address_v6(address_bytes), - port, - net::buffer(buffer.data(), buffer.size()), + handler_.connector_.connect( + {address_v6(address_bytes), port}, + {buffer.data(), buffer.size()}, [connection = boost::intrusive_ptr(this)]( std::error_code ec, std::unique_ptr stream) { if (ec) { @@ -226,10 +224,8 @@ void Handler::TcpConnection::connect_host(ConstBufferSpan buffer) { buffer.remove_prefix(1 + host_length + 2); forward_size_ = 0; state_ = State::connect; - handler_.connector_.connect_tcp_host( - host, - port, - net::buffer(buffer.data(), buffer.size()), + handler_.connector_.connect( + host, port, {buffer.data(), buffer.size()}, [connection = boost::intrusive_ptr(this)]( std::error_code ec, std::unique_ptr stream) { if (ec) { diff --git a/net/proxy/socks/handler.h b/net/proxy/socks/handler.h index c10f21c..8a75b51 100644 --- a/net/proxy/socks/handler.h +++ b/net/proxy/socks/handler.h @@ -2,16 +2,16 @@ #define _NET_PROXY_SOCKS_HANDLER_H #include "net/asio.h" -#include "net/proxy/connector.h" -#include "net/proxy/handler.h" +#include "net/interface/connector.h" +#include "net/interface/handler.h" namespace net { namespace proxy { namespace socks { -class Handler : public proxy::Handler { +class Handler : public net::Handler { public: - Handler(const any_io_executor &executor, proxy::Connector &connector); + Handler(const any_io_executor &executor, net::Connector &connector); void handle_stream(std::unique_ptr stream) override; void handle_datagram(std::unique_ptr datagram) override; @@ -19,7 +19,7 @@ class Handler : public proxy::Handler { private: class TcpConnection; - proxy::Connector &connector_; + net::Connector &connector_; }; } // namespace socks diff --git a/net/proxy/stream.h b/net/proxy/stream.h deleted file mode 100644 index 366e35f..0000000 --- a/net/proxy/stream.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _NET_PROXY_STREAM_H -#define _NET_PROXY_STREAM_H - -#include -#include - -#include "absl/functional/any_invocable.h" -#include "absl/types/span.h" -#include "net/asio.h" - -namespace net { -namespace proxy { - -class Stream { -public: - virtual ~Stream() = default; - - virtual void read( - absl::Span buffers, - absl::AnyInvocable callback) = 0; - - virtual void write( - absl::Span buffers, - absl::AnyInvocable callback) = 0; - - virtual void close() = 0; -}; - -} // namespace proxy -} // namespace net - -#endif // _NET_PROXY_STREAM_H diff --git a/net/proxy/system/BUILD b/net/proxy/system/BUILD index b8562f7..b66cb6d 100644 --- a/net/proxy/system/BUILD +++ b/net/proxy/system/BUILD @@ -19,12 +19,13 @@ cc_library( deps = [ ":tcp-socket-stream", ":udp-socket-datagram", - "//net/proxy:interface", "//net/proxy/ares:resolver", "//net/proxy/util:write", "@com_google_absl//absl/strings", + "@com_google_absl//absl/types:span", "@org_iceboy_trunk//net:asio", "@org_iceboy_trunk//net:timer-list", + "@org_iceboy_trunk//net/interface", ], ) @@ -35,11 +36,11 @@ cc_library( deps = [ ":tcp-socket-stream", ":udp-socket-datagram", - "//net/proxy:interface", "@org_iceboy_trunk//base:logging", "@org_iceboy_trunk//net:asio", "@org_iceboy_trunk//net:endpoint", "@org_iceboy_trunk//net:timer-list", + "@org_iceboy_trunk//net/interface", ], ) @@ -48,9 +49,9 @@ cc_library( srcs = ["stdio-stream.cc"], hdrs = ["stdio-stream.h"], deps = [ - "//net/proxy:interface", "@com_google_absl//absl/container:fixed_array", "@org_iceboy_trunk//net:asio", + "@org_iceboy_trunk//net/interface", ] + select({ "@platforms//os:windows": [ "@org_iceboy_trunk//io:file-utils", @@ -65,10 +66,10 @@ cc_library( srcs = ["tcp-socket-stream.cc"], hdrs = ["tcp-socket-stream.h"], deps = [ - "//net/proxy:interface", "@com_google_absl//absl/container:fixed_array", "@org_iceboy_trunk//net:asio", "@org_iceboy_trunk//net:timer-list", + "@org_iceboy_trunk//net/interface", ], ) @@ -77,8 +78,8 @@ cc_library( srcs = ["udp-socket-datagram.cc"], hdrs = ["udp-socket-datagram.h"], deps = [ - "//net/proxy:interface", "@com_google_absl//absl/container:fixed_array", "@org_iceboy_trunk//net:asio", + "@org_iceboy_trunk//net/interface", ], ) diff --git a/net/proxy/system/connector.cc b/net/proxy/system/connector.cc index 93e0a04..775d2ce 100644 --- a/net/proxy/system/connector.cc +++ b/net/proxy/system/connector.cc @@ -16,31 +16,15 @@ Connector::Connector(const any_io_executor &executor, const Options &options) timer_list_(executor_, options.timeout), tcp_no_delay_(options.tcp_no_delay) {} -void Connector::connect_tcp_v4( - const address_v4 &address, - uint16_t port, - const_buffer initial_data, - absl::AnyInvocable) &&> callback) { - connect_tcp( - std::array({tcp::endpoint(address, port)}), - initial_data, - std::move(callback)); -} - -void Connector::connect_tcp_v6( - const address_v6 &address, - uint16_t port, +void Connector::connect( + const tcp::endpoint &endpoint, const_buffer initial_data, absl::AnyInvocable) &&> callback) { - connect_tcp( - std::array({tcp::endpoint(address, port)}), - initial_data, - std::move(callback)); + connect_internal({endpoint}, initial_data, std::move(callback)); } -void Connector::connect_tcp_host( +void Connector::connect( std::string_view host, uint16_t port, const_buffer initial_data, @@ -59,25 +43,19 @@ void Connector::connect_tcp_host( for (const auto &address : addresses) { endpoints.push_back(tcp::endpoint(address, port)); } - connect_tcp(endpoints, initial_data, std::move(callback)); + connect_internal(endpoints, initial_data, std::move(callback)); }); } -std::error_code Connector::bind_udp_v4(std::unique_ptr &datagram) { +std::error_code Connector::bind( + const udp::endpoint &endpoint, std::unique_ptr &datagram) { udp::socket socket(executor_); boost::system::error_code ec; - socket.open(udp::v4(), ec); + socket.open(endpoint.protocol(), ec); if (ec) { return ec; } - datagram = std::make_unique(std::move(socket)); - return {}; -} - -std::error_code Connector::bind_udp_v6(std::unique_ptr &datagram) { - udp::socket socket(executor_); - boost::system::error_code ec; - socket.open(udp::v6(), ec); + socket.bind(endpoint, ec); if (ec) { return ec; } @@ -85,9 +63,8 @@ std::error_code Connector::bind_udp_v6(std::unique_ptr &datagram) { return {}; } -template -void Connector::connect_tcp( - const EndpointsT &endpoints, +void Connector::connect_internal( + absl::Span endpoints, const_buffer initial_data, absl::AnyInvocable) &&> callback) { diff --git a/net/proxy/system/connector.h b/net/proxy/system/connector.h index 2adadf4..e2d42dd 100644 --- a/net/proxy/system/connector.h +++ b/net/proxy/system/connector.h @@ -3,17 +3,18 @@ #include +#include "absl/types/span.h" +#include "net/timer-list.h" +#include "net/interface/connector.h" #include "net/proxy/ares/resolver.h" -#include "net/proxy/connector.h" #include "net/proxy/system/tcp-socket-stream.h" #include "net/proxy/system/udp-socket-datagram.h" -#include "net/timer-list.h" namespace net { namespace proxy { namespace system { -class Connector : public proxy::Connector { +class Connector : public net::Connector { public: struct Options { std::chrono::nanoseconds timeout = std::chrono::minutes(5); @@ -26,36 +27,28 @@ class Connector : public proxy::Connector { Connector(const Connector &) = delete; Connector &operator=(const Connector &) = delete; - void connect_tcp_v4( - const address_v4 &address, - uint16_t port, - const_buffer initial_data, - absl::AnyInvocable) &&> callback) override; - - void connect_tcp_v6( - const address_v6 &address, - uint16_t port, + void connect( + const tcp::endpoint &endpoint, const_buffer initial_data, absl::AnyInvocable) &&> callback) override; - void connect_tcp_host( + void connect( std::string_view host, uint16_t port, const_buffer initial_data, absl::AnyInvocable) &&> callback) override; - std::error_code bind_udp_v4(std::unique_ptr &datagram) override; - std::error_code bind_udp_v6(std::unique_ptr &datagram) override; + std::error_code bind( + const udp::endpoint &endpoint, + std::unique_ptr &datagram) override; ares::Resolver &resolver() { return resolver_; } private: - template - void connect_tcp( - const EndpointsT &endpoints, + void connect_internal( + absl::Span endpoints, const_buffer initial_data, absl::AnyInvocable) &&> callback); diff --git a/net/proxy/system/listener.h b/net/proxy/system/listener.h index b7883a0..d87aedf 100644 --- a/net/proxy/system/listener.h +++ b/net/proxy/system/listener.h @@ -5,8 +5,8 @@ #include "net/asio.h" #include "net/endpoint.h" -#include "net/proxy/handler.h" #include "net/timer-list.h" +#include "net/interface/handler.h" namespace net { namespace proxy { diff --git a/net/proxy/system/stdio-stream.h b/net/proxy/system/stdio-stream.h index c5ac03c..8ceb34a 100644 --- a/net/proxy/system/stdio-stream.h +++ b/net/proxy/system/stdio-stream.h @@ -5,7 +5,7 @@ #include "io/native-file.h" #endif #include "net/asio.h" -#include "net/proxy/stream.h" +#include "net/interface/stream.h" namespace net { namespace proxy { diff --git a/net/proxy/system/tcp-socket-stream.h b/net/proxy/system/tcp-socket-stream.h index ed2d036..8746025 100644 --- a/net/proxy/system/tcp-socket-stream.h +++ b/net/proxy/system/tcp-socket-stream.h @@ -2,8 +2,8 @@ #define _NET_PROXY_SYSTEM_TCP_SOCKET_STREAM_H #include "net/asio.h" -#include "net/proxy/stream.h" #include "net/timer-list.h" +#include "net/interface/stream.h" namespace net { namespace proxy { diff --git a/net/proxy/system/udp-socket-datagram.h b/net/proxy/system/udp-socket-datagram.h index 2bae3a4..d11e415 100644 --- a/net/proxy/system/udp-socket-datagram.h +++ b/net/proxy/system/udp-socket-datagram.h @@ -2,7 +2,7 @@ #define _NET_PROXY_SYSTEM_UDP_SOCKET_DATAGRAM_H #include "net/asio.h" -#include "net/proxy/datagram.h" +#include "net/interface/datagram.h" namespace net { namespace proxy { diff --git a/net/proxy/util/BUILD b/net/proxy/util/BUILD index e0b1027..f91196f 100644 --- a/net/proxy/util/BUILD +++ b/net/proxy/util/BUILD @@ -17,9 +17,9 @@ cc_library( hdrs = ["copy.h"], deps = [ ":write", - "//net/proxy:interface", "@com_google_absl//absl/container:fixed_array", "@com_google_absl//absl/functional:any_invocable", + "@org_iceboy_trunk//net/interface", ], ) @@ -27,8 +27,8 @@ cc_library( name = "stream-wrapper", hdrs = ["stream-wrapper.h"], deps = [ - "//net/proxy:interface", "@org_iceboy_trunk//net:asio", + "@org_iceboy_trunk//net/interface", ], ) @@ -37,8 +37,8 @@ cc_library( srcs = ["write.cc"], hdrs = ["write.h"], deps = [ - "//net/proxy:interface", "@com_google_absl//absl/functional:any_invocable", "@org_iceboy_trunk//base:types", + "@org_iceboy_trunk//net/interface", ], ) diff --git a/net/proxy/util/copy.h b/net/proxy/util/copy.h index d4c8ed3..d3e464e 100644 --- a/net/proxy/util/copy.h +++ b/net/proxy/util/copy.h @@ -5,7 +5,7 @@ #include #include "absl/functional/any_invocable.h" -#include "net/proxy/stream.h" +#include "net/interface/stream.h" namespace net { namespace proxy { diff --git a/net/proxy/util/stream-wrapper.h b/net/proxy/util/stream-wrapper.h index f72300f..e923b7a 100644 --- a/net/proxy/util/stream-wrapper.h +++ b/net/proxy/util/stream-wrapper.h @@ -5,7 +5,7 @@ #include "absl/types/span.h" #include "net/asio.h" -#include "net/proxy/stream.h" +#include "net/interface/stream.h" namespace net { namespace proxy { diff --git a/net/proxy/util/write.h b/net/proxy/util/write.h index 5f05bc6..2a04340 100644 --- a/net/proxy/util/write.h +++ b/net/proxy/util/write.h @@ -5,7 +5,7 @@ #include "absl/functional/any_invocable.h" #include "base/types.h" -#include "net/proxy/stream.h" +#include "net/interface/stream.h" namespace net { namespace proxy { diff --git a/net/tools/miracle-proxy.cc b/net/tools/miracle-proxy.cc index ff6b368..65d7348 100644 --- a/net/tools/miracle-proxy.cc +++ b/net/tools/miracle-proxy.cc @@ -48,11 +48,11 @@ bool tcp_connect(Proxy &proxy) { LOG(fatal) << "invalid connector"; return false; } - connector->connect_tcp_host( + connector->connect( host, port, {}, [&proxy](std::error_code ec, std::unique_ptr remote_stream) { if (ec) { - LOG(error) << "connect_tcp_host failed: " << ec; + LOG(error) << "connect failed: " << ec; return; } auto stdio_stream = std::make_unique(