1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-26 15:53:26 +01:00

add option to not connect to the DHT network

This commit is contained in:
Jfreegman 2014-08-12 18:59:27 -04:00
parent d6aaa95b25
commit a318bdb034
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
2 changed files with 30 additions and 19 deletions

View File

@ -339,6 +339,9 @@ int init_connection(Tox *m)
static void do_connection(Tox *m, ToxWindow *prompt) static void do_connection(Tox *m, ToxWindow *prompt)
{ {
if (arg_opts.no_connect == 1)
return;
char msg[MAX_STR_SIZE] = {0}; char msg[MAX_STR_SIZE] = {0};
static int conn_err = 0; static int conn_err = 0;
@ -500,13 +503,14 @@ void *thread_winref(void *data)
static void print_usage(void) static void print_usage(void)
{ {
fprintf(stderr, "usage: toxic [OPTION] [FILE ...]\n"); fprintf(stderr, "usage: toxic [OPTION] [FILE ...]\n");
fprintf(stderr, " -f, --file Use specified data file\n");
fprintf(stderr, " -x, --nodata Ignore data file\n");
fprintf(stderr, " -4, --ipv4 Force IPv4 connection\n"); fprintf(stderr, " -4, --ipv4 Force IPv4 connection\n");
fprintf(stderr, " -d, --default_locale Use default locale\n");
fprintf(stderr, " -c, --config Use specified config file\n"); fprintf(stderr, " -c, --config Use specified config file\n");
fprintf(stderr, " -n, --nodes Use specified DHTnodes file\n"); fprintf(stderr, " -d, --default_locale Use default locale\n");
fprintf(stderr, " -f, --file Use specified data file\n");
fprintf(stderr, " -h, --help Show this message and exit\n"); fprintf(stderr, " -h, --help Show this message and exit\n");
fprintf(stderr, " -n, --nodes Use specified DHTnodes file\n");
fprintf(stderr, " -o, --noconnect Do not connect to the DHT network\n");
fprintf(stderr, " -x, --nodata Ignore data file\n");
} }
static void set_default_opts(void) static void set_default_opts(void)
@ -515,6 +519,7 @@ static void set_default_opts(void)
arg_opts.ignore_data_file = 0; arg_opts.ignore_data_file = 0;
arg_opts.default_locale = 0; arg_opts.default_locale = 0;
arg_opts.use_custom_data = 0; arg_opts.use_custom_data = 0;
arg_opts.no_connect = 0;
} }
static void parse_args(int argc, char *argv[]) static void parse_args(int argc, char *argv[])
@ -529,13 +534,26 @@ static void parse_args(int argc, char *argv[])
{"config", required_argument, 0, 'c'}, {"config", required_argument, 0, 'c'},
{"nodes", required_argument, 0, 'n'}, {"nodes", required_argument, 0, 'n'},
{"help", no_argument, 0, 'h'}, {"help", no_argument, 0, 'h'},
{"noconnect", no_argument, 0, 'o'},
}; };
const char *opts_str = "4xdf:c:n:h"; const char *opts_str = "o4xdf:c:n:h";
int opt, indexptr; int opt, indexptr;
while ((opt = getopt_long(argc, argv, opts_str, long_opts, &indexptr)) != -1) { while ((opt = getopt_long(argc, argv, opts_str, long_opts, &indexptr)) != -1) {
switch (opt) { switch (opt) {
case '4':
arg_opts.use_ipv4 = 1;
break;
case 'c':
snprintf(arg_opts.config_path, sizeof(arg_opts.config_path), "%s", optarg);
break;
case 'd':
arg_opts.default_locale = 1;
break;
case 'f': case 'f':
arg_opts.use_custom_data = 1; arg_opts.use_custom_data = 1;
DATA_FILE = strdup(optarg); DATA_FILE = strdup(optarg);
@ -548,24 +566,16 @@ static void parse_args(int argc, char *argv[])
strcat(BLOCK_FILE, "-blocklist"); strcat(BLOCK_FILE, "-blocklist");
break; break;
case 'x':
arg_opts.ignore_data_file = 1;
break;
case '4':
arg_opts.use_ipv4 = 1;
break;
case 'c':
snprintf(arg_opts.config_path, sizeof(arg_opts.config_path), "%s", optarg);
break;
case 'n': case 'n':
snprintf(arg_opts.nodes_path, sizeof(arg_opts.nodes_path), "%s", optarg); snprintf(arg_opts.nodes_path, sizeof(arg_opts.nodes_path), "%s", optarg);
break; break;
case 'd': case 'o':
arg_opts.default_locale = 1; arg_opts.no_connect = 1;
break;
case 'x':
arg_opts.ignore_data_file = 1;
break; break;
case 'h': case 'h':

View File

@ -76,6 +76,7 @@ struct arg_opts {
int use_ipv4; int use_ipv4;
int default_locale; int default_locale;
int use_custom_data; int use_custom_data;
int no_connect;
char config_path[MAX_STR_SIZE]; char config_path[MAX_STR_SIZE];
char nodes_path[MAX_STR_SIZE]; char nodes_path[MAX_STR_SIZE];
}; };