bridgeauth.c 2.0 KB

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