diff --git a/include/overture.h b/include/overture.h index 8533c08..528e1b4 100644 --- a/include/overture.h +++ b/include/overture.h @@ -5,9 +5,13 @@ typedef struct { int port; + int debug; int timeout; + char *ttl_file; + char *host_file; int foreign_port; int domestic_port; + int **reject_type; char *foreign_ip_file; char *domestic_ip_file; char *foreign_domain_file; diff --git a/src/cleardns.c b/src/cleardns.c index 08ce2b1..5c2743a 100644 --- a/src/cleardns.c +++ b/src/cleardns.c @@ -35,61 +35,48 @@ int main(int argc, char *argv[]) { // ClearDNS server LOG_LEVEL = LOG_DEBUG; log_info("ClearDNS server start (%s)", VERSION); -// int **temp = int_list_init(); -// temp = int_list_append(temp, 1232); -// temp = int_list_append(temp, 2342); -// temp = int_list_append(temp, 3435); -// temp = int_list_append(temp, 456); -// temp = int_list_append(temp, 567); -// -// char *str = int_list_dump(temp); -// log_info("`%s`", str); - -// char **temp = string_list_init(); -// temp = string_list_append(temp, "1"); -// temp = string_list_append(temp, ""); -// temp = string_list_append(temp, "3"); -// char *str = string_list_dump(temp); -// log_info("`%s`", str); +// 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"); -// return 0; +// domestic->verify = FALSE; +// domestic->parallel = FALSE; +// domestic->optimistic = TRUE; +// domestic->debug = TRUE; +// domestic->cache = 0; - dnsproxy *domestic = dnsproxy_init(DOMESTIC_PORT); +// 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); - 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"); + overture *diverter = overture_init(DIVERTER_PORT); - dnsproxy_add_fallback(domestic, "tls://223.6.6.6"); - dnsproxy_add_fallback(domestic, "tls://120.53.53.53"); + diverter->timeout = 8; + diverter->domestic_ip_file = "china-ip.txt"; + diverter->domestic_domain_file = "chinalist.txt"; + diverter->foreign_domain_file = "gfwlist.txt"; - domestic->verify = FALSE; - domestic->parallel = FALSE; - domestic->optimistic = TRUE; -// domestic->debug = TRUE; - domestic->cache = 0; + diverter->debug = TRUE; + diverter->ttl_file = "domain_ttl.txt"; + diverter->host_file = "hosts.txt"; + diverter->reject_type = int_list_append(diverter->reject_type, 255); - process *p = dnsproxy_load("Domestic", domestic, "domestic.json"); + process *p = overture_load(diverter, "overture.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); -// -// diverter->timeout = 8; -// diverter->domestic_ip_file = "china-ip.txt"; -// diverter->domestic_domain_file = "chinalist.txt"; -// diverter->foreign_domain_file = "gfwlist.txt"; -// -// process *p = overture_load(diverter, "overture.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); - // int debug_mode = 0; // fprintf(stderr, "[ClearDNS] Server start.\n"); // for (char **p = argv; p < argv + argc; ++p) { diff --git a/src/dnsproxy.c b/src/dnsproxy.c index 436bc90..8e8d023 100644 --- a/src/dnsproxy.c +++ b/src/dnsproxy.c @@ -70,7 +70,7 @@ process* dnsproxy_load(const char *caption, dnsproxy *info, const char *file) { p->cmd = string_list_append(string_list_init(), DNSPROXY_BIN); p->cmd = string_list_append(p->cmd, option); if (info->debug) { - p->cmd = string_list_append(p->cmd, "--verbose"); // dnsproxy into debug mode + p->cmd = string_list_append(p->cmd, "--verbose"); // dnsproxy enable debug mode } p->env = string_list_init(); p->cwd = WORK_DIR; diff --git a/src/overture.c b/src/overture.c index f98f5f5..fdc3f84 100644 --- a/src/overture.c +++ b/src/overture.c @@ -13,9 +13,13 @@ char* overture_gen_config(overture *info); overture* overture_init(int port) { // init overture options overture *info = (overture*)malloc(sizeof(overture)); info->port = port; + info->debug = FALSE; info->timeout = 6; // default timeout -> 6s + info->ttl_file = NULL; + info->host_file = NULL; info->foreign_port = FOREIGN_PORT; info->domestic_port = DOMESTIC_PORT; + info->reject_type = int_list_init(); info->foreign_ip_file = "/dev/null"; info->domestic_ip_file = "/dev/null"; info->foreign_domain_file = "/dev/null"; @@ -24,14 +28,20 @@ overture* overture_init(int port) { // init overture options } void overture_dump(overture *info) { // show overture info in debug log + char *reject_type = int_list_dump(info->reject_type); log_debug("Overture port -> %d", info->port); + log_debug("Overture debug -> %s", show_bool(info->debug)); log_debug("Overture timeout -> %d", info->timeout); + log_debug("Overture ttl file -> %s", info->ttl_file); + log_debug("Overture host file -> %s", info->host_file); log_debug("Overture foreign port -> %d", info->foreign_port); log_debug("Overture domestic port -> %d", info->domestic_port); + log_debug("Overture reject type -> %s", reject_type); 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); + free(reject_type); } process* overture_load(overture *info, const char *file) { @@ -46,6 +56,9 @@ process* overture_load(overture *info, const char *file) { p->cmd = string_list_append(string_list_init(), OVERTURE_BIN); p->cmd = string_list_append(p->cmd, "-c"); p->cmd = string_list_append(p->cmd, file); + if (info->debug) { + p->cmd = string_list_append(p->cmd, "-v"); // overture enable debug mode + } p->env = string_list_init(); p->cwd = WORK_DIR; return p; @@ -97,9 +110,24 @@ char* overture_gen_config(overture *info) { // generate json configure from over cJSON_AddItemToObject(config, "domainFile", domain_file); cJSON *host_file = cJSON_CreateObject(); + if (info->host_file != NULL) { + cJSON_AddStringToObject(host_file, "hostsFile", info->host_file); + } cJSON_AddStringToObject(host_file, "finder", "full-map"); cJSON_AddItemToObject(config, "hostsFile", host_file); + if (info->ttl_file != NULL) { + cJSON_AddStringToObject(config, "domainTTLFile", info->ttl_file); + } + + if (int_list_len(info->reject_type)) { + cJSON *reject_type = cJSON_CreateArray(); + for (int **rr_num = info->reject_type; *rr_num != NULL; ++rr_num) { + cJSON_AddItemToArray(reject_type, cJSON_CreateNumber(**rr_num)); + } + cJSON_AddItemToObject(config, "rejectQType", reject_type); + } + char *config_str = cJSON_Print(config); cJSON_Delete(config); // free json object free(domestic_port);