Skip to content

Commit

Permalink
net/proxy rename listeners to handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
iceboy233 committed Sep 4, 2023
1 parent 0fedfba commit 91658f1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ miracle-proxy --config miracle.conf
### Socks 5 server

```
listeners {
handlers {
"" {
listen 127.0.0.1:1080
type socks
Expand All @@ -44,7 +44,7 @@ listeners {
### Shadowsocks server

```
listeners {
handlers {
"" {
listen [::]:8388
type shadowsocks
Expand All @@ -57,7 +57,7 @@ listeners {
### Socks 5 server, shadowsocks client (ss-local)

```
listeners {
handlers {
"" {
listen 127.0.0.1:1080
type socks
Expand Down
16 changes: 12 additions & 4 deletions net/proxy/proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,26 @@ Proxy::Proxy(const any_io_executor &executor)
: executor_(executor) {}

void Proxy::load_config(const boost::property_tree::ptree &config) {
listeners_config_ = config.get_child("listeners", {});
handlers_config_ = config.get_child("handlers", {});
auto listeners_config = config.get_child("listeners", {});
if (!listeners_config.empty()) {
LOG(warning) << "listeners is deprecated, rename to handlers instead";
handlers_config_.insert(
handlers_config_.end(),
listeners_config.begin(),
listeners_config.end());
}
connectors_config_ = config.get_child("connectors", {});
if (connectors_config_.find("") == connectors_config_.not_found()) {
boost::property_tree::ptree default_connector;
default_connector.put("type", "system");
connectors_config_.push_back({"", default_connector});
}
create_listeners();
create_handlers();
}

void Proxy::create_listeners() {
for (const auto &pair : listeners_config_) {
void Proxy::create_handlers() {
for (const auto &pair : handlers_config_) {
const auto &config = pair.second;
std::string listen_str = config.get<std::string>("listen", "");
auto listen_endpoint = Endpoint::from_string(listen_str);
Expand Down
4 changes: 2 additions & 2 deletions net/proxy/proxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ class Proxy {
const any_io_executor &executor() const { return executor_; }

private:
void create_listeners();
void create_handlers();

any_io_executor executor_;
boost::property_tree::ptree listeners_config_;
boost::property_tree::ptree handlers_config_;
boost::property_tree::ptree connectors_config_;
std::vector<std::unique_ptr<system::Listener>> listeners_;
std::vector<std::unique_ptr<Handler>> handlers_;
Expand Down

0 comments on commit 91658f1

Please sign in to comment.