Prechádzať zdrojové kódy

Add new BridgeDistribution config option

Bridge relays can use it to add a "bridge-distribution-request" line
to their bridge descriptor, which tells BridgeDB how they'd like their
bridge address to be given out.

Implements tickets 18329.
Roger Dingledine 7 rokov pred
rodič
commit
ebab521525
5 zmenil súbory, kde vykonal 31 pridanie a 0 odobranie
  1. 6 0
      changes/feature18329
  2. 6 0
      doc/tor.1.txt
  3. 7 0
      src/or/config.c
  4. 4 0
      src/or/or.h
  5. 8 0
      src/or/router.c

+ 6 - 0
changes/feature18329

@@ -0,0 +1,6 @@
+  o Minor features:
+    - Bridge relays can now set the BridgeDistribution config option to
+      add a "bridge-distribution-request" line to their bridge descriptor,
+      which tells BridgeDB how they'd like their bridge address to be
+      given out. Implements tickets 18329.
+

+ 6 - 0
doc/tor.1.txt

@@ -1647,6 +1647,12 @@ is non-zero):
     server descriptor to the bridge database, rather than
     server descriptor to the bridge database, rather than
     to the public directory authorities.
     to the public directory authorities.
 
 
+[[BridgeDistribution]] **BridgeDistribution** __string__::
+    If set along with BridgeRelay, Tor will include a new line in its
+    bridge descriptor which indicates to the BridgeDB service how it
+    would like its bridge address to be given out. Set it to "none" if
+    you want BridgeDB to avoid distributing your bridge address.
+
 [[ContactInfo]] **ContactInfo** __email_address__::
 [[ContactInfo]] **ContactInfo** __email_address__::
     Administrative contact information for this relay or bridge. This line
     Administrative contact information for this relay or bridge. This line
     can be used to contact you if your relay or bridge is misconfigured or
     can be used to contact you if your relay or bridge is misconfigured or

+ 7 - 0
src/or/config.c

@@ -182,6 +182,7 @@ static config_var_t option_vars_[] = {
   V(BridgePassword,              STRING,   NULL),
   V(BridgePassword,              STRING,   NULL),
   V(BridgeRecordUsageByCountry,  BOOL,     "1"),
   V(BridgeRecordUsageByCountry,  BOOL,     "1"),
   V(BridgeRelay,                 BOOL,     "0"),
   V(BridgeRelay,                 BOOL,     "0"),
+  V(BridgeDistribution,          STRING,   NULL),
   V(CellStatistics,              BOOL,     "0"),
   V(CellStatistics,              BOOL,     "0"),
   V(LearnCircuitBuildTimeout,    BOOL,     "1"),
   V(LearnCircuitBuildTimeout,    BOOL,     "1"),
   V(CircuitBuildTimeout,         INTERVAL, "0"),
   V(CircuitBuildTimeout,         INTERVAL, "0"),
@@ -3346,6 +3347,10 @@ options_validate(or_options_t *old_options, or_options_t *options,
     options->DirPort_set = 0;
     options->DirPort_set = 0;
   }
   }
 
 
+  if (options->BridgeDistribution && !options->BridgeRelay) {
+    REJECT("You have set BridgeDistribution, yet you didn't set BridgeRelay!");
+  }
+
   if (options->MinUptimeHidServDirectoryV2 < 0) {
   if (options->MinUptimeHidServDirectoryV2 < 0) {
     log_warn(LD_CONFIG, "MinUptimeHidServDirectoryV2 option must be at "
     log_warn(LD_CONFIG, "MinUptimeHidServDirectoryV2 option must be at "
                         "least 0 seconds. Changing to 0.");
                         "least 0 seconds. Changing to 0.");
@@ -4497,6 +4502,8 @@ options_transition_affects_descriptor(const or_options_t *old_options,
       get_effective_bwburst(old_options) !=
       get_effective_bwburst(old_options) !=
         get_effective_bwburst(new_options) ||
         get_effective_bwburst(new_options) ||
       !opt_streq(old_options->ContactInfo, new_options->ContactInfo) ||
       !opt_streq(old_options->ContactInfo, new_options->ContactInfo) ||
+      !opt_streq(old_options->BridgeDistribution,
+                 new_options->BridgeDistribution) ||
       !opt_streq(old_options->MyFamily, new_options->MyFamily) ||
       !opt_streq(old_options->MyFamily, new_options->MyFamily) ||
       !opt_streq(old_options->AccountingStart, new_options->AccountingStart) ||
       !opt_streq(old_options->AccountingStart, new_options->AccountingStart) ||
       old_options->AccountingMax != new_options->AccountingMax ||
       old_options->AccountingMax != new_options->AccountingMax ||

+ 4 - 0
src/or/or.h

@@ -3638,6 +3638,10 @@ typedef struct {
   int BridgeAuthoritativeDir; /**< Boolean: is this an authoritative directory
   int BridgeAuthoritativeDir; /**< Boolean: is this an authoritative directory
                                * that aggregates bridge descriptors? */
                                * that aggregates bridge descriptors? */
 
 
+  /** If set on a bridge relay, it will include this value on a new
+   * "bridge-distribution-request" line in its bridge descriptor. */
+  char *BridgeDistribution;
+
   /** If set on a bridge authority, it will answer requests on its dirport
   /** If set on a bridge authority, it will answer requests on its dirport
    * for bridge statuses -- but only if the requests use this password. */
    * for bridge statuses -- but only if the requests use this password. */
   char *BridgePassword;
   char *BridgePassword;

+ 8 - 0
src/or/router.c

@@ -2867,6 +2867,14 @@ router_dump_router_to_string(routerinfo_t *router,
     smartlist_add_asprintf(chunks, "contact %s\n", ci);
     smartlist_add_asprintf(chunks, "contact %s\n", ci);
   }
   }
 
 
+  if (options->BridgeRelay && options->BridgeDistribution &&
+      strlen(options->BridgeDistribution)) {
+    const char *bd = options->BridgeDistribution;
+    if (strchr(bd, '\n') || strchr(bd, '\r'))
+      bd = escaped(bd);
+    smartlist_add_asprintf(chunks, "bridge-distribution-request %s\n", bd);
+  }
+
   if (router->onion_curve25519_pkey) {
   if (router->onion_curve25519_pkey) {
     char kbuf[128];
     char kbuf[128];
     base64_encode(kbuf, sizeof(kbuf),
     base64_encode(kbuf, sizeof(kbuf),