Skip to content

Commit

Permalink
net/proxy:interface move to trunk
Browse files Browse the repository at this point in the history
  • Loading branch information
iceboy233 committed Nov 21, 2024
1 parent a631019 commit 96f71a1
Show file tree
Hide file tree
Showing 44 changed files with 165 additions and 482 deletions.
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ boost_deps()

git_repository(
name = "org_iceboy_trunk",
commit = "24fc6171c1512293423d9c2fb093ac2bec86f728",
commit = "ee7aa17695b5b8e65171b23fba3a13a4c6632d64",
remote = "https://github.com/iceboy233/trunk.git",
)
19 changes: 2 additions & 17 deletions net/proxy/BUILD
Original file line number Diff line number Diff line change
@@ -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",
],
)

Expand All @@ -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",
],
)
4 changes: 2 additions & 2 deletions net/proxy/ares/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
],
)

Expand All @@ -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",
],
)
6 changes: 3 additions & 3 deletions net/proxy/ares/resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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_;
Expand Down
21 changes: 5 additions & 16 deletions net/proxy/ares/socket.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<UdpSocket>(this)]() {
ares_process_fd(socket->channel_, socket->fd_, socket->fd_);
});
Expand Down
6 changes: 3 additions & 3 deletions net/proxy/ares/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <boost/smart_ptr/intrusive_ref_counter.hpp>

#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 {
Expand Down
52 changes: 0 additions & 52 deletions net/proxy/connector.h

This file was deleted.

34 changes: 0 additions & 34 deletions net/proxy/datagram.h

This file was deleted.

23 changes: 0 additions & 23 deletions net/proxy/handler.h

This file was deleted.

4 changes: 2 additions & 2 deletions net/proxy/http/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ 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",
"@com_google_absl//absl/container:flat_hash_map",
"@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",
],
)
Expand All @@ -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",
],
)
2 changes: 1 addition & 1 deletion net/proxy/http/h2-connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion net/proxy/http/tls-stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions net/proxy/misc/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand All @@ -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",
],
)

Expand All @@ -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",
],
)

Expand All @@ -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",
],
)
2 changes: 1 addition & 1 deletion net/proxy/misc/echo-handler.h
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion net/proxy/misc/null-handler.h
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion net/proxy/misc/random-handler.h
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion net/proxy/misc/zero-handler.h
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions net/proxy/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 96f71a1

Please sign in to comment.