Parcourir la source

client: add --threads option, default to zero threads

ambrop7 il y a 15 ans
Parent
commit
da0a122b53
2 fichiers modifiés avec 20 ajouts et 1 suppressions
  1. 8 0
      badvpn-client.8
  2. 12 1
      client/client.c

+ 8 - 0
badvpn-client.8

@@ -25,6 +25,8 @@ badvpn-client \- VPN node daemon for the BadVPN peer-to-peer VPN system
 .br
 .RB "[" --channel-loglevel " <channel-name> <0-5/none/error/warning/notice/info/debug>] ..."
 .br
+.RB "[" --threads " <integer>]"
+.br
 .RB "[" --ssl " " --nssdb " <string> " --client-cert-name " <string>]"
 .br
 .RB "[" --server-name " <string>]"
@@ -120,6 +122,12 @@ Set the default logging level.
 .BR --channel-loglevel " <channel-name> <0-5/none/error/warning/notice/info/debug>"
 Set the logging level for a specific logging channel.
 .TP
+.BR --threads " <integer>"
+Hint for the number of additional threads to use for potentionally long computations (such as
+encryption and OTP generation). If zero (0) (default), additional threads will be disabled and all
+computations will be done in the event loop. If negative (<0), a guess will be made, possibly
+based on the number of CPUs. If positive (>0), the given number of threads will be used.
+.TP
 .BR --ssl
 Use TLS. Requires --nssdb and --server-cert-name.
 .TP

+ 12 - 1
client/client.c

@@ -86,6 +86,7 @@ struct {
     #endif
     int loglevel;
     int loglevels[BLOG_NUM_CHANNELS];
+    int threads;
     int ssl;
     char *nssdb;
     char *client_cert_name;
@@ -433,7 +434,7 @@ int main (int argc, char *argv[])
     }
     
     // init thread work dispatcher
-    if (!BThreadWorkDispatcher_Init(&twd, &ss, -1)) {
+    if (!BThreadWorkDispatcher_Init(&twd, &ss, options.threads)) {
         BLog(BLOG_ERROR, "BThreadWorkDispatcher_Init failed");
         goto fail2a;
     }
@@ -652,6 +653,7 @@ void print_help (const char *name)
         #endif
         "        [--loglevel <0-5/none/error/warning/notice/info/debug>]\n"
         "        [--channel-loglevel <channel-name> <0-5/none/error/warning/notice/info/debug>] ...\n"
+        "        [--threads <integer>]\n"
         "        [--ssl --nssdb <string> --client-cert-name <string>]\n"
         "        [--server-name <string>]\n"
         "        --server-addr <addr>\n"
@@ -705,6 +707,7 @@ int parse_arguments (int argc, char *argv[])
     for (int i = 0; i < BLOG_NUM_CHANNELS; i++) {
         options.loglevels[i] = -1;
     }
+    options.threads = 0;
     options.ssl = 0;
     options.nssdb = NULL;
     options.client_cert_name = NULL;
@@ -804,6 +807,14 @@ int parse_arguments (int argc, char *argv[])
             options.loglevels[channel] = loglevel;
             i += 2;
         }
+        else if (!strcmp(arg, "--threads")) {
+            if (1 >= argc - i) {
+                fprintf(stderr, "%s: requires an argument\n", arg);
+                return 0;
+            }
+            options.threads = atoi(argv[i + 1]);
+            i++;
+        }
         else if (!strcmp(arg, "--ssl")) {
             options.ssl = 1;
         }