Browse Source

feat: overture struct

dev
dnomd343 2 years ago
parent
commit
855128cdf5
  1. 2
      include/common.h
  2. 18
      include/overture.h
  3. 2
      src/CMakeLists.txt
  4. 36
      src/cleardns.c
  5. 4
      src/common.c
  6. 2
      src/dnsproxy.c
  7. 28
      src/overture.c

2
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

18
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

2
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)

36
src/cleardns.c

@ -1,6 +1,7 @@
#include "logger.h"
#include "common.h"
#include "dnsproxy.h"
#include "overture.h"
#include "str.h"
//#include <stdio.h>
@ -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");

4
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");

2
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;

28
src/overture.c

@ -0,0 +1,28 @@
#include <stdlib.h>
#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);
}
Loading…
Cancel
Save