Line data Source code
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 0 : bridgeauth_dump_bridge_status_to_file(time_t now) 25 : { 26 0 : char *status; 27 0 : char *fname = NULL; 28 0 : char *thresholds = NULL; 29 0 : char *published_thresholds_and_status = NULL; 30 0 : char published[ISO_TIME_LEN+1]; 31 0 : const routerinfo_t *me = router_get_my_routerinfo(); 32 0 : char fingerprint[FINGERPRINT_LEN+1]; 33 0 : char *fingerprint_line = NULL; 34 : 35 0 : dirserv_set_bridges_running(now); 36 0 : status = networkstatus_getinfo_by_purpose("bridge", now); 37 : 38 0 : if (me && crypto_pk_get_fingerprint(me->identity_pkey, 39 : fingerprint, 0) >= 0) { 40 0 : tor_asprintf(&fingerprint_line, "fingerprint %s\n", fingerprint); 41 : } else { 42 0 : log_warn(LD_BUG, "Error computing fingerprint for bridge status."); 43 : } 44 0 : format_iso_time(published, now); 45 0 : dirserv_compute_bridge_flag_thresholds(); 46 0 : thresholds = dirserv_get_flag_thresholds_line(); 47 0 : tor_asprintf(&published_thresholds_and_status, 48 : "published %s\nflag-thresholds %s\n%s%s", 49 0 : published, thresholds, fingerprint_line ? fingerprint_line : "", 50 : status); 51 0 : fname = get_datadir_fname("networkstatus-bridges"); 52 0 : if (write_str_to_file(fname,published_thresholds_and_status,0)<0) { 53 0 : log_warn(LD_DIRSERV, "Unable to write networkstatus-bridges file."); 54 : } 55 0 : tor_free(thresholds); 56 0 : tor_free(published_thresholds_and_status); 57 0 : tor_free(fname); 58 0 : tor_free(status); 59 0 : tor_free(fingerprint_line); 60 0 : }