From 855128cdf5747d85e2c51c53acc819bae26c0fa9 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Sun, 11 Sep 2022 23:35:35 +0800 Subject: [PATCH] feat: overture struct --- include/common.h | 2 +- include/overture.h | 18 ++++++++++++++++++ src/CMakeLists.txt | 2 +- src/cleardns.c | 36 +++++++++++++++++++++--------------- src/common.c | 4 ---- src/dnsproxy.c | 2 +- src/overture.c | 28 ++++++++++++++++++++++++++++ 7 files changed, 70 insertions(+), 22 deletions(-) create mode 100644 include/overture.h create mode 100644 src/overture.c diff --git a/include/common.h b/include/common.h index 6f7ef33..3b2c6ad 100644 --- a/include/common.h +++ b/include/common.h @@ -8,6 +8,7 @@ #define DOMESTIC_PORT 4053 #define FOREIGN_PORT 6053 +#define DIVERTER_PORT 5353 #define DNSPROXY_BIN "dnsproxy" #define OVERTURE_BIN "overture" @@ -23,7 +24,6 @@ //void load_start_command(char *adguard_workdir, char *overture_config, char *upstream_config, int is_debug); char* show_bool(int value); -char** command_init(char *bin); void save_file(char *file, char *content); #endif diff --git a/include/overture.h b/include/overture.h new file mode 100644 index 0000000..db5877c --- /dev/null +++ b/include/overture.h @@ -0,0 +1,18 @@ +#ifndef _OVERTURE_H_ +#define _OVERTURE_H_ + +typedef struct { + int port; + int timeout; + int foreign_port; + int domestic_port; + char *foreign_ip_file; + char *domestic_ip_file; + char *foreign_domain_file; + char *domestic_domain_file; +} overture; + +overture* overture_init(int port); +void overture_dump(overture *info); + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 027989b..458b539 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,5 +5,5 @@ include_directories(${PROJECT_SOURCE_DIR}/include/utils) add_subdirectory(utils) -add_executable(cleardns cleardns.c dnsproxy.c common.c) +add_executable(cleardns cleardns.c dnsproxy.c common.c overture.c) target_link_libraries(cleardns utils) diff --git a/src/cleardns.c b/src/cleardns.c index 5dc19aa..5b17a87 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -1,6 +1,7 @@ #include "logger.h" #include "common.h" #include "dnsproxy.h" +#include "overture.h" #include "str.h" //#include @@ -32,26 +33,31 @@ int main(int argc, char *argv[]) { // ClearDNS server LOG_LEVEL = LOG_DEBUG; log_info("ClearDNS server start (%s)", VERSION); - dnsproxy *domestic = dnsproxy_init(DOMESTIC_PORT); - - dnsproxy_add_bootstrap(domestic, "1.1.1.1"); - dnsproxy_add_bootstrap(domestic, "8.8.8.8"); - - dnsproxy_add_primary(domestic, "223.5.5.5"); - dnsproxy_add_primary(domestic, "tls://dns.pub"); - - dnsproxy_add_fallback(domestic, "tls://223.6.6.6"); - dnsproxy_add_fallback(domestic, "tls://120.53.53.53"); +// dnsproxy *domestic = dnsproxy_init(DOMESTIC_PORT); +// +// dnsproxy_add_bootstrap(domestic, "1.1.1.1"); +// dnsproxy_add_bootstrap(domestic, "8.8.8.8"); +// +// dnsproxy_add_primary(domestic, "223.5.5.5"); +// dnsproxy_add_primary(domestic, "tls://dns.pub"); +// +// dnsproxy_add_fallback(domestic, "tls://223.6.6.6"); +// dnsproxy_add_fallback(domestic, "tls://120.53.53.53"); // domestic->verify = FALSE; // domestic->parallel = FALSE; - domestic->optimistic = TRUE; +// domestic->optimistic = TRUE; // domestic->cache = 0; - process *p = dnsproxy_load("Domestic", domestic, "domestic.json"); - log_info("cmd -> %s", string_list_dump(p->cmd)); - log_info("env -> %s", string_list_dump(p->env)); - log_info("cwd -> %s", p->cwd); +// process *p = dnsproxy_load("Domestic", domestic, "domestic.json"); +// log_info("cmd -> %s", string_list_dump(p->cmd)); +// log_info("env -> %s", string_list_dump(p->env)); +// log_info("cwd -> %s", p->cwd); + + + overture *diverter = overture_init(DIVERTER_PORT); + + overture_dump(diverter); // int debug_mode = 0; // fprintf(stderr, "[ClearDNS] Server start.\n"); diff --git a/src/common.c b/src/common.c index d3c33ba..e3f3a14 100644 --- a/src/common.c +++ b/src/common.c @@ -11,10 +11,6 @@ char* show_bool(int value) { } } -char** command_init(char *bin) { - return string_list_append(string_list_init(), bin); -} - void save_file(char *file, char *content) { log_debug("Write into `%s` -> \n%s", file, content); FILE* fp = fopen(file , "w"); diff --git a/src/dnsproxy.c b/src/dnsproxy.c index e5967a7..05cded3 100644 --- a/src/dnsproxy.c +++ b/src/dnsproxy.c @@ -55,7 +55,7 @@ process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) { char *option = string_join("--config-path=", file); process *p = (process*)malloc(sizeof(process)); - p->cmd = command_init(DNSPROXY_BIN); + p->cmd = string_list_append(string_list_init(), DNSPROXY_BIN); p->cmd = string_list_append(p->cmd, option); p->env = string_list_init(); p->cwd = WORK_DIR; diff --git a/src/overture.c b/src/overture.c new file mode 100644 index 0000000..478f1db --- /dev/null +++ b/src/overture.c @@ -0,0 +1,28 @@ +#include +#include "overture.h" +#include "common.h" +#include "logger.h" + +overture* overture_init(int port) { // init overture options + overture *info = (overture*)malloc(sizeof(overture)); + info->port = port; + info->timeout = 6; // default timeout -> 6s + info->foreign_port = FOREIGN_PORT; + info->domestic_port = DOMESTIC_PORT; + info->foreign_ip_file = "/dev/null"; + info->domestic_ip_file = "/dev/null"; + info->foreign_domain_file = "/dev/null"; + info->domestic_domain_file = "/dev/null"; + return info; +} + +void overture_dump(overture *info) { // show overture info in debug log + log_debug("Overture port -> %d", info->port); + log_debug("Overture timeout -> %d", info->timeout); + log_debug("Overture foreign port -> %d", info->foreign_port); + log_debug("Overture domestic port -> %d", info->domestic_port); + log_debug("Overture foreign ip file -> %s", info->foreign_ip_file); + log_debug("Overture domestic ip file -> %s", info->domestic_ip_file); + log_debug("Overture foreign domain file -> %s", info->foreign_domain_file); + log_debug("Overture domestic domain file -> %s", info->domestic_domain_file); +}