tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

bridgeauth.c (2064B)


      1 /* Copyright (c) 2001 Matej Pfajfar.
      2 * Copyright (c) 2001-2004, Roger Dingledine.
      3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
      4 * Copyright (c) 2007-2021, The Tor Project, Inc. */
      5 /* See LICENSE for licensing information */
      6 
      7 /**
      8 * @file bridgeauth.c
      9 * @brief Bridge authority code
     10 **/
     11 
     12 #include "core/or/or.h"
     13 #include "feature/dirauth/bridgeauth.h"
     14 #include "feature/dirauth/voteflags.h"
     15 #include "feature/nodelist/networkstatus.h"
     16 #include "feature/relay/router.h"
     17 #include "app/config/config.h"
     18 
     19 #include "feature/nodelist/routerinfo_st.h"
     20 
     21 /** Write out router status entries for all our bridge descriptors. Here, we
     22 * also mark routers as running. */
     23 void
     24 bridgeauth_dump_bridge_status_to_file(time_t now)
     25 {
     26  char *status;
     27  char *fname = NULL;
     28  char *thresholds = NULL;
     29  char *published_thresholds_and_status = NULL;
     30  char published[ISO_TIME_LEN+1];
     31  const routerinfo_t *me = router_get_my_routerinfo();
     32  char fingerprint[FINGERPRINT_LEN+1];
     33  char *fingerprint_line = NULL;
     34 
     35  dirserv_set_bridges_running(now);
     36  status = networkstatus_getinfo_by_purpose("bridge", now);
     37 
     38  if (me && crypto_pk_get_fingerprint(me->identity_pkey,
     39                                      fingerprint, 0) >= 0) {
     40    tor_asprintf(&fingerprint_line, "fingerprint %s\n", fingerprint);
     41  } else {
     42    log_warn(LD_BUG, "Error computing fingerprint for bridge status.");
     43  }
     44  format_iso_time(published, now);
     45  dirserv_compute_bridge_flag_thresholds();
     46  thresholds = dirserv_get_flag_thresholds_line();
     47  tor_asprintf(&published_thresholds_and_status,
     48               "published %s\nflag-thresholds %s\n%s%s",
     49               published, thresholds, fingerprint_line ? fingerprint_line : "",
     50               status);
     51  fname = get_datadir_fname("networkstatus-bridges");
     52  if (write_str_to_file(fname,published_thresholds_and_status,0)<0) {
     53    log_warn(LD_DIRSERV, "Unable to write networkstatus-bridges file.");
     54  }
     55  tor_free(thresholds);
     56  tor_free(published_thresholds_and_status);
     57  tor_free(fname);
     58  tor_free(status);
     59  tor_free(fingerprint_line);
     60 }