tor  0.4.2.0-alpha-dev
circpathbias.c
Go to the documentation of this file.
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 
24 #include "core/or/or.h"
25 #include "core/or/channel.h"
26 #include "feature/client/circpathbias.h"
27 #include "core/or/circuitbuild.h"
28 #include "core/or/circuitlist.h"
29 #include "core/or/circuituse.h"
30 #include "core/or/circuitstats.h"
32 #include "app/config/config.h"
36 #include "core/or/relay.h"
37 #include "lib/math/fp.h"
38 #include "lib/math/laplace.h"
39 
40 #include "core/or/cell_st.h"
41 #include "core/or/cpath_build_state_st.h"
42 #include "core/or/crypt_path_st.h"
43 #include "core/or/extend_info_st.h"
44 #include "core/or/origin_circuit_st.h"
45 
47 static void pathbias_count_collapse(origin_circuit_t *circ);
49 static void pathbias_measure_use_rate(entry_guard_t *guard);
50 static void pathbias_measure_close_rate(entry_guard_t *guard);
51 static void pathbias_scale_use_rates(entry_guard_t *guard);
52 static void pathbias_scale_close_rates(entry_guard_t *guard);
53 static int entry_guard_inc_circ_attempt_count(entry_guard_t *guard);
54 
60 static int
62 {
64 
66 
68 
69  if (pb->path_bias_disabled)
70  return -1;
71 
73  pb->circ_attempts++;
74 
75  log_info(LD_CIRC, "Got success count %f/%f for guard %s",
77  entry_guard_describe(guard));
78  return 0;
79 }
80 
83 static int
85 {
86 #define DFLT_PATH_BIAS_MIN_CIRC 150
87  if (options->PathBiasCircThreshold >= 5)
88  return options->PathBiasCircThreshold;
89  else
90  return networkstatus_get_param(NULL, "pb_mincircs",
91  DFLT_PATH_BIAS_MIN_CIRC,
92  5, INT32_MAX);
93 }
94 
96 static double
98 {
99 #define DFLT_PATH_BIAS_NOTICE_PCT 70
100  if (options->PathBiasNoticeRate >= 0.0)
101  return options->PathBiasNoticeRate;
102  else
103  return networkstatus_get_param(NULL, "pb_noticepct",
104  DFLT_PATH_BIAS_NOTICE_PCT, 0, 100)/100.0;
105 }
106 
108 static double
110 {
111 #define DFLT_PATH_BIAS_WARN_PCT 50
112  if (options->PathBiasWarnRate >= 0.0)
113  return options->PathBiasWarnRate;
114  else
115  return networkstatus_get_param(NULL, "pb_warnpct",
116  DFLT_PATH_BIAS_WARN_PCT, 0, 100)/100.0;
117 }
118 
119 /* XXXX I'd like to have this be static again, but entrynodes.c needs it. */
124 double
126 {
127 #define DFLT_PATH_BIAS_EXTREME_PCT 30
128  if (options->PathBiasExtremeRate >= 0.0)
129  return options->PathBiasExtremeRate;
130  else
131  return networkstatus_get_param(NULL, "pb_extremepct",
132  DFLT_PATH_BIAS_EXTREME_PCT, 0, 100)/100.0;
133 }
134 
135 /* XXXX I'd like to have this be static again, but entrynodes.c needs it. */
140 int
142 {
143 #define DFLT_PATH_BIAS_DROP_GUARDS 0
144  if (options->PathBiasDropGuards >= 0)
145  return options->PathBiasDropGuards;
146  else
147  return networkstatus_get_param(NULL, "pb_dropguards",
148  DFLT_PATH_BIAS_DROP_GUARDS, 0, 1);
149 }
150 
157 static int
159 {
160 #define DFLT_PATH_BIAS_SCALE_THRESHOLD 300
161  if (options->PathBiasScaleThreshold >= 10)
162  return options->PathBiasScaleThreshold;
163  else
164  return networkstatus_get_param(NULL, "pb_scalecircs",
165  DFLT_PATH_BIAS_SCALE_THRESHOLD, 10,
166  INT32_MAX);
167 }
168 
176 static double
178 {
179  (void) options;
180  /*
181  * The scale factor is the denominator for our scaling
182  * of circuit counts for our path bias window.
183  *
184  * Note that our use of doubles for the path bias state
185  * file means that powers of 2 work best here.
186  */
187  int denominator = networkstatus_get_param(NULL, "pb_scalefactor",
188  2, 2, INT32_MAX);
189  tor_assert(denominator > 0);
190 
196  return networkstatus_get_param(NULL, "pb_multfactor",
197  1, 1, denominator)/((double)denominator);
198 }
199 
202 static int
204 {
205 #define DFLT_PATH_BIAS_MIN_USE 20
206  if (options->PathBiasUseThreshold >= 3)
207  return options->PathBiasUseThreshold;
208  else
209  return networkstatus_get_param(NULL, "pb_minuse",
210  DFLT_PATH_BIAS_MIN_USE,
211  3, INT32_MAX);
212 }
213 
215 static double
217 {
218 #define DFLT_PATH_BIAS_NOTICE_USE_PCT 80
219  if (options->PathBiasNoticeUseRate >= 0.0)
220  return options->PathBiasNoticeUseRate;
221  else
222  return networkstatus_get_param(NULL, "pb_noticeusepct",
223  DFLT_PATH_BIAS_NOTICE_USE_PCT,
224  0, 100)/100.0;
225 }
226 
231 double
233 {
234 #define DFLT_PATH_BIAS_EXTREME_USE_PCT 60
235  if (options->PathBiasExtremeUseRate >= 0.0)
236  return options->PathBiasExtremeUseRate;
237  else
238  return networkstatus_get_param(NULL, "pb_extremeusepct",
239  DFLT_PATH_BIAS_EXTREME_USE_PCT,
240  0, 100)/100.0;
241 }
242 
249 static int
251 {
252 #define DFLT_PATH_BIAS_SCALE_USE_THRESHOLD 100
253  if (options->PathBiasScaleUseThreshold >= 10)
254  return options->PathBiasScaleUseThreshold;
255  else
256  return networkstatus_get_param(NULL, "pb_scaleuse",
257  DFLT_PATH_BIAS_SCALE_USE_THRESHOLD,
258  10, INT32_MAX);
259 }
260 
264 const char *
265 pathbias_state_to_string(path_state_t state)
266 {
267  switch (state) {
268  case PATH_STATE_NEW_CIRC:
269  return "new";
270  case PATH_STATE_BUILD_ATTEMPTED:
271  return "build attempted";
272  case PATH_STATE_BUILD_SUCCEEDED:
273  return "build succeeded";
274  case PATH_STATE_USE_ATTEMPTED:
275  return "use attempted";
276  case PATH_STATE_USE_SUCCEEDED:
277  return "use succeeded";
278  case PATH_STATE_USE_FAILED:
279  return "use failed";
280  case PATH_STATE_ALREADY_COUNTED:
281  return "already counted";
282  }
283 
284  return "unknown";
285 }
286 
295 static int
297 {
298 #define N2N_TAGGING_IS_POSSIBLE
299 #ifdef N2N_TAGGING_IS_POSSIBLE
300  /* cpath is a circular list. We want circs with more than one hop,
301  * and the second hop must be waiting for keys still (it's just
302  * about to get them). */
303  return circ->cpath &&
304  circ->cpath->next != circ->cpath &&
305  circ->cpath->next->state == CPATH_STATE_AWAITING_KEYS;
306 #else /* !(defined(N2N_TAGGING_IS_POSSIBLE)) */
307  /* If tagging attacks are no longer possible, we probably want to
308  * count bias from the first hop. However, one could argue that
309  * timing-based tagging is still more useful than per-hop failure.
310  * In which case, we'd never want to use this.
311  */
312  return circ->cpath &&
313  circ->cpath->state == CPATH_STATE_AWAITING_KEYS;
314 #endif /* defined(N2N_TAGGING_IS_POSSIBLE) */
315 }
316 
322 static int
324 {
325 #define PATHBIAS_COUNT_INTERVAL (600)
326  static ratelim_t count_limit =
327  RATELIM_INIT(PATHBIAS_COUNT_INTERVAL);
328  char *rate_msg = NULL;
329 
330  /* We can't do path bias accounting without entry guards.
331  * Testing and controller circuits also have no guards.
332  *
333  * We also don't count server-side rends, because their
334  * endpoint could be chosen maliciously.
335  * Similarly, we can't count client-side intro attempts,
336  * because clients can be manipulated into connecting to
337  * malicious intro points. */
338  if (get_options()->UseEntryGuards == 0 ||
339  circ->base_.purpose == CIRCUIT_PURPOSE_TESTING ||
340  circ->base_.purpose == CIRCUIT_PURPOSE_CONTROLLER ||
341  circ->base_.purpose == CIRCUIT_PURPOSE_S_CONNECT_REND ||
342  circ->base_.purpose == CIRCUIT_PURPOSE_S_REND_JOINED ||
343  (circ->base_.purpose >= CIRCUIT_PURPOSE_C_INTRODUCING &&
344  circ->base_.purpose <= CIRCUIT_PURPOSE_C_INTRODUCE_ACKED)) {
345 
346  /* Check to see if the shouldcount result has changed due to a
347  * unexpected purpose change that would affect our results.
348  *
349  * The reason we check the path state too here is because for the
350  * cannibalized versions of these purposes, we count them as successful
351  * before their purpose change.
352  */
353  if (circ->pathbias_shouldcount == PATHBIAS_SHOULDCOUNT_COUNTED
354  && circ->path_state != PATH_STATE_ALREADY_COUNTED) {
355  log_info(LD_BUG,
356  "Circuit %d is now being ignored despite being counted "
357  "in the past. Purpose is %s, path state is %s",
358  circ->global_identifier,
359  circuit_purpose_to_string(circ->base_.purpose),
361  }
362  circ->pathbias_shouldcount = PATHBIAS_SHOULDCOUNT_IGNORED;
363  return 0;
364  }
365 
366  /* Completely ignore one hop circuits */
367  if (circ->build_state->onehop_tunnel ||
368  circ->build_state->desired_path_len == 1) {
369  /* Check for inconsistency */
370  if (circ->build_state->desired_path_len != 1 ||
371  !circ->build_state->onehop_tunnel) {
372  if ((rate_msg = rate_limit_log(&count_limit, approx_time()))) {
373  log_info(LD_BUG,
374  "One-hop circuit %d has length %d. Path state is %s. "
375  "Circuit is a %s currently %s.%s",
376  circ->global_identifier,
379  circuit_purpose_to_string(circ->base_.purpose),
380  circuit_state_to_string(circ->base_.state),
381  rate_msg);
382  tor_free(rate_msg);
383  }
385  }
386 
387  /* Check to see if the shouldcount result has changed due to a
388  * unexpected change that would affect our results */
389  if (circ->pathbias_shouldcount == PATHBIAS_SHOULDCOUNT_COUNTED) {
390  log_info(LD_BUG,
391  "One-hop circuit %d is now being ignored despite being counted "
392  "in the past. Purpose is %s, path state is %s",
393  circ->global_identifier,
394  circuit_purpose_to_string(circ->base_.purpose),
396  }
397  circ->pathbias_shouldcount = PATHBIAS_SHOULDCOUNT_IGNORED;
398  return 0;
399  }
400 
401  /* Check to see if the shouldcount result has changed due to a
402  * unexpected purpose change that would affect our results */
403  if (circ->pathbias_shouldcount == PATHBIAS_SHOULDCOUNT_IGNORED) {
404  log_info(LD_CIRC,
405  "Circuit %d is not being counted by pathbias because it was "
406  "ignored in the past. Purpose is %s, path state is %s",
407  circ->global_identifier,
408  circuit_purpose_to_string(circ->base_.purpose),
410  return 0;
411  }
412  circ->pathbias_shouldcount = PATHBIAS_SHOULDCOUNT_COUNTED;
413 
414  return 1;
415 }
416 
423 int
425 {
426 #define CIRC_ATTEMPT_NOTICE_INTERVAL (600)
427  static ratelim_t circ_attempt_notice_limit =
428  RATELIM_INIT(CIRC_ATTEMPT_NOTICE_INTERVAL);
429  char *rate_msg = NULL;
430 
431  if (!pathbias_should_count(circ)) {
432  return 0;
433  }
434 
435  if (pathbias_is_new_circ_attempt(circ)) {
436  /* Help track down the real cause of bug #6475: */
437  if (circ->has_opened && circ->path_state != PATH_STATE_BUILD_ATTEMPTED) {
438  if ((rate_msg = rate_limit_log(&circ_attempt_notice_limit,
439  approx_time()))) {
440  log_info(LD_BUG,
441  "Opened circuit %d is in strange path state %s. "
442  "Circuit is a %s currently %s.%s",
443  circ->global_identifier,
445  circuit_purpose_to_string(circ->base_.purpose),
446  circuit_state_to_string(circ->base_.state),
447  rate_msg);
448  tor_free(rate_msg);
449  }
450  }
451 
452  /* Don't re-count cannibalized circs.. */
453  if (!circ->has_opened) {
454  entry_guard_t *guard = NULL;
455 
456  if (circ->cpath && circ->cpath->extend_info) {
459  } else if (circ->base_.n_chan) {
460  guard =
462  }
463 
464  if (guard) {
465  if (circ->path_state == PATH_STATE_NEW_CIRC) {
466  circ->path_state = PATH_STATE_BUILD_ATTEMPTED;
467 
468  if (entry_guard_inc_circ_attempt_count(guard) < 0) {
469  /* Bogus guard; we already warned. */
470  return -END_CIRC_REASON_TORPROTOCOL;
471  }
472  } else {
473  if ((rate_msg = rate_limit_log(&circ_attempt_notice_limit,
474  approx_time()))) {
475  log_info(LD_BUG,
476  "Unopened circuit %d has strange path state %s. "
477  "Circuit is a %s currently %s.%s",
478  circ->global_identifier,
480  circuit_purpose_to_string(circ->base_.purpose),
481  circuit_state_to_string(circ->base_.state),
482  rate_msg);
483  tor_free(rate_msg);
484  }
485  }
486  } else {
487  if ((rate_msg = rate_limit_log(&circ_attempt_notice_limit,
488  approx_time()))) {
489  log_info(LD_CIRC,
490  "Unopened circuit has no known guard. "
491  "Circuit is a %s currently %s.%s",
492  circuit_purpose_to_string(circ->base_.purpose),
493  circuit_state_to_string(circ->base_.state),
494  rate_msg);
495  tor_free(rate_msg);
496  }
497  }
498  }
499  }
500 
501  return 0;
502 }
503 
511 void
513 {
514 #define SUCCESS_NOTICE_INTERVAL (600)
515  static ratelim_t success_notice_limit =
516  RATELIM_INIT(SUCCESS_NOTICE_INTERVAL);
517  char *rate_msg = NULL;
518  entry_guard_t *guard = NULL;
519 
520  if (!pathbias_should_count(circ)) {
521  return;
522  }
523 
524  /* Don't count cannibalized/reused circs for path bias
525  * "build" success, since they get counted under "use" success. */
526  if (!circ->has_opened) {
527  if (circ->cpath && circ->cpath->extend_info) {
530  }
531 
532  if (guard) {
534 
535  if (circ->path_state == PATH_STATE_BUILD_ATTEMPTED) {
536  circ->path_state = PATH_STATE_BUILD_SUCCEEDED;
537  pb->circ_successes++;
539 
540  log_info(LD_CIRC, "Got success count %f/%f for guard %s",
541  pb->circ_successes, pb->circ_attempts,
542  entry_guard_describe(guard));
543  } else {
544  if ((rate_msg = rate_limit_log(&success_notice_limit,
545  approx_time()))) {
546  log_info(LD_BUG,
547  "Succeeded circuit %d is in strange path state %s. "
548  "Circuit is a %s currently %s.%s",
549  circ->global_identifier,
551  circuit_purpose_to_string(circ->base_.purpose),
552  circuit_state_to_string(circ->base_.state),
553  rate_msg);
554  tor_free(rate_msg);
555  }
556  }
557 
558  if (pb->circ_attempts < pb->circ_successes) {
559  log_notice(LD_BUG, "Unexpectedly high successes counts (%f/%f) "
560  "for guard %s",
561  pb->circ_successes, pb->circ_attempts,
562  entry_guard_describe(guard));
563  }
564  /* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
565  * CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT and have no guards here.
566  * No need to log that case. */
567  } else if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
568  if ((rate_msg = rate_limit_log(&success_notice_limit,
569  approx_time()))) {
570  log_info(LD_CIRC,
571  "Completed circuit has no known guard. "
572  "Circuit is a %s currently %s.%s",
573  circuit_purpose_to_string(circ->base_.purpose),
574  circuit_state_to_string(circ->base_.state),
575  rate_msg);
576  tor_free(rate_msg);
577  }
578  }
579  } else {
580  if (circ->path_state < PATH_STATE_BUILD_SUCCEEDED) {
581  if ((rate_msg = rate_limit_log(&success_notice_limit,
582  approx_time()))) {
583  log_info(LD_BUG,
584  "Opened circuit %d is in strange path state %s. "
585  "Circuit is a %s currently %s.%s",
586  circ->global_identifier,
588  circuit_purpose_to_string(circ->base_.purpose),
589  circuit_state_to_string(circ->base_.state),
590  rate_msg);
591  tor_free(rate_msg);
592  }
593  }
594  }
595 }
596 
603 void
605 {
606  if (!pathbias_should_count(circ)) {
607  return;
608  }
609 
610  if (circ->path_state < PATH_STATE_BUILD_SUCCEEDED) {
611  log_notice(LD_BUG,
612  "Used circuit %d is in strange path state %s. "
613  "Circuit is a %s currently %s.",
614  circ->global_identifier,
616  circuit_purpose_to_string(circ->base_.purpose),
617  circuit_state_to_string(circ->base_.state));
618  } else if (circ->path_state < PATH_STATE_USE_ATTEMPTED) {
619  entry_guard_t *guard = entry_guard_get_by_id_digest(
621  if (guard) {
623 
626  pb->use_attempts++;
628 
629  log_debug(LD_CIRC,
630  "Marked circuit %d (%f/%f) as used for guard %s.",
631  circ->global_identifier,
632  pb->use_successes, pb->use_attempts,
633  entry_guard_describe(guard));
634  }
635 
636  circ->path_state = PATH_STATE_USE_ATTEMPTED;
637  } else {
638  /* Harmless but educational log message */
639  log_info(LD_CIRC,
640  "Used circuit %d is already in path state %s. "
641  "Circuit is a %s currently %s.",
642  circ->global_identifier,
644  circuit_purpose_to_string(circ->base_.purpose),
645  circuit_state_to_string(circ->base_.state));
646  }
647 
648  return;
649 }
650 
660 void
662 {
663  if (!pathbias_should_count(circ)) {
664  return;
665  }
666 
667  if (circ->path_state < PATH_STATE_USE_ATTEMPTED) {
668  log_notice(LD_BUG,
669  "Used circuit %d is in strange path state %s. "
670  "Circuit is a %s currently %s.",
671  circ->global_identifier,
673  circuit_purpose_to_string(circ->base_.purpose),
674  circuit_state_to_string(circ->base_.state));
675 
677  }
678 
679  /* We don't do any accounting at the guard until actual circuit close */
680  circ->path_state = PATH_STATE_USE_SUCCEEDED;
681 
682  return;
683 }
684 
699 void
701 {
702  if (circ->path_state == PATH_STATE_USE_SUCCEEDED) {
703  log_info(LD_CIRC,
704  "Rolling back pathbias use state to 'attempted' for detached "
705  "circuit %d", circ->global_identifier);
706  circ->path_state = PATH_STATE_USE_ATTEMPTED;
707  }
708 }
709 
714 static void
716 {
717  entry_guard_t *guard;
718 
719  if (!pathbias_should_count(circ)) {
720  return;
721  }
722 
723  if (circ->path_state != PATH_STATE_USE_SUCCEEDED) {
724  log_notice(LD_BUG,
725  "Successfully used circuit %d is in strange path state %s. "
726  "Circuit is a %s currently %s.",
727  circ->global_identifier,
729  circuit_purpose_to_string(circ->base_.purpose),
730  circuit_state_to_string(circ->base_.state));
731  } else {
734  if (guard) {
736 
737  pb->use_successes++;
739 
740  if (pb->use_attempts < pb->use_successes) {
741  log_notice(LD_BUG, "Unexpectedly high use successes counts (%f/%f) "
742  "for guard %s",
743  pb->use_successes, pb->use_attempts,
744  entry_guard_describe(guard));
745  }
746 
747  log_debug(LD_CIRC,
748  "Marked circuit %d (%f/%f) as used successfully for guard %s",
749  circ->global_identifier, pb->use_successes,
750  pb->use_attempts,
751  entry_guard_describe(guard));
752  }
753  }
754 
755  return;
756 }
757 
775 static int
777 {
778  /* Based on connection_ap_handshake_send_begin() */
779  char payload[CELL_PAYLOAD_SIZE];
780  int payload_len;
781  origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
782  crypt_path_t *cpath_layer = NULL;
783  char *probe_nonce = NULL;
784 
785  tor_assert(ocirc);
786 
787  cpath_layer = ocirc->cpath->prev;
788 
789  if (cpath_layer->state != CPATH_STATE_OPEN) {
790  /* This can happen for cannibalized circuits. Their
791  * last hop isn't yet open */
792  log_info(LD_CIRC,
793  "Got pathbias probe request for unopened circuit %d. "
794  "Opened %d, len %d", ocirc->global_identifier,
795  ocirc->has_opened, ocirc->build_state->desired_path_len);
796  return -1;
797  }
798 
799  /* We already went down this road. */
801  ocirc->pathbias_probe_id) {
802  log_info(LD_CIRC,
803  "Got pathbias probe request for circuit %d with "
804  "outstanding probe", ocirc->global_identifier);
805  return -1;
806  }
807 
808  /* Can't probe if the channel isn't open */
809  if (circ->n_chan == NULL ||
810  (!CHANNEL_IS_OPEN(circ->n_chan)
811  && !CHANNEL_IS_MAINT(circ->n_chan))) {
812  log_info(LD_CIRC,
813  "Skipping pathbias probe for circuit %d: Channel is not open.",
814  ocirc->global_identifier);
815  return -1;
816  }
817 
819 
820  /* Update timestamp for when circuit_expire_building() should kill us */
821  tor_gettimeofday(&circ->timestamp_began);
822 
823  /* Generate a random address for the nonce */
824  crypto_rand((char*)&ocirc->pathbias_probe_nonce,
825  sizeof(ocirc->pathbias_probe_nonce));
826  ocirc->pathbias_probe_nonce &= 0x00ffffff;
827  probe_nonce = tor_dup_ip(ocirc->pathbias_probe_nonce);
828 
829  tor_snprintf(payload,RELAY_PAYLOAD_SIZE, "%s:25", probe_nonce);
830  payload_len = (int)strlen(payload)+1;
831 
832  // XXX: need this? Can we assume ipv4 will always be supported?
833  // If not, how do we tell?
834  //if (payload_len <= RELAY_PAYLOAD_SIZE - 4 && edge_conn->begincell_flags) {
835  // set_uint32(payload + payload_len, htonl(edge_conn->begincell_flags));
836  // payload_len += 4;
837  //}
838 
839  /* Generate+Store stream id, make sure it's non-zero */
841 
842  if (ocirc->pathbias_probe_id==0) {
843  log_warn(LD_CIRC,
844  "Ran out of stream IDs on circuit %u during "
845  "pathbias probe attempt.", ocirc->global_identifier);
846  tor_free(probe_nonce);
847  return -1;
848  }
849 
850  log_info(LD_CIRC,
851  "Sending pathbias testing cell to %s:25 on stream %d for circ %d.",
852  probe_nonce, ocirc->pathbias_probe_id, ocirc->global_identifier);
853  tor_free(probe_nonce);
854 
855  /* Send a test relay cell */
856  if (relay_send_command_from_edge(ocirc->pathbias_probe_id, circ,
857  RELAY_COMMAND_BEGIN, payload,
858  payload_len, cpath_layer) < 0) {
859  log_notice(LD_CIRC,
860  "Failed to send pathbias probe cell on circuit %d.",
861  ocirc->global_identifier);
862  return -1;
863  }
864 
865  /* Mark it freshly dirty so it doesn't get expired in the meantime */
866  circ->timestamp_dirty = time(NULL);
867 
868  return 0;
869 }
870 
878 int
880 {
881  /* Based on connection_edge_process_relay_cell() */
882  relay_header_t rh;
883  int reason;
884  uint32_t ipv4_host;
885  origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
886 
887  tor_assert(cell);
888  tor_assert(ocirc);
890 
891  relay_header_unpack(&rh, cell->payload);
892 
893  reason = rh.length > 0 ?
894  get_uint8(cell->payload+RELAY_HEADER_SIZE) : END_STREAM_REASON_MISC;
895 
896  if (rh.command == RELAY_COMMAND_END &&
897  reason == END_STREAM_REASON_EXITPOLICY &&
898  ocirc->pathbias_probe_id == rh.stream_id) {
899 
900  /* Check length+extract host: It is in network order after the reason code.
901  * See connection_edge_end(). */
902  if (rh.length < 9) { /* reason+ipv4+dns_ttl */
903  log_notice(LD_PROTOCOL,
904  "Short path bias probe response length field (%d).", rh.length);
905  return - END_CIRC_REASON_TORPROTOCOL;
906  }
907 
908  ipv4_host = ntohl(get_uint32(cell->payload+RELAY_HEADER_SIZE+1));
909 
910  /* Check nonce */
911  if (ipv4_host == ocirc->pathbias_probe_nonce) {
913  circuit_read_valid_data(ocirc, rh.length);
914  circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
915  log_info(LD_CIRC,
916  "Got valid path bias probe back for circ %d, stream %d.",
917  ocirc->global_identifier, ocirc->pathbias_probe_id);
918  return 0;
919  } else {
920  log_notice(LD_CIRC,
921  "Got strange probe value 0x%x vs 0x%x back for circ %d, "
922  "stream %d.", ipv4_host, ocirc->pathbias_probe_nonce,
923  ocirc->global_identifier, ocirc->pathbias_probe_id);
924  return -1;
925  }
926  }
927  log_info(LD_CIRC,
928  "Got another cell back back on pathbias probe circuit %d: "
929  "Command: %d, Reason: %d, Stream-id: %d",
930  ocirc->global_identifier, rh.command, reason, rh.stream_id);
931  return -1;
932 }
933 
938 void
940 {
941  origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
942  relay_header_t rh;
943 
944  relay_header_unpack(&rh, cell->payload);
945 
946  /* Check to see if this is a cell from a previous connection,
947  * or is a request to close the circuit. */
948  switch (rh.command) {
949  case RELAY_COMMAND_TRUNCATED:
950  /* Truncated cells can arrive on path bias circs. When they do,
951  * just process them. This closes the circ, but it was junk anyway.
952  * No reason to wait for the probe. */
953  circuit_read_valid_data(ocirc, rh.length);
955  get_uint8(cell->payload + RELAY_HEADER_SIZE));
956 
957  break;
958 
959  case RELAY_COMMAND_END:
961  rh.stream_id)) {
963  }
964  break;
965 
966  case RELAY_COMMAND_DATA:
968  rh.stream_id)) {
970  }
971  break;
972 
973  case RELAY_COMMAND_SENDME:
975  rh.stream_id)) {
977  }
978  break;
979 
980  case RELAY_COMMAND_CONNECTED:
982  rh.stream_id)) {
984  }
985  break;
986 
987  case RELAY_COMMAND_RESOLVED:
989  rh.stream_id)) {
991  }
992  break;
993  }
994 }
995 
1009 int
1011 {
1012  circuit_t *circ = &ocirc->base_;
1013 
1014  if (!pathbias_should_count(ocirc)) {
1015  return 0;
1016  }
1017 
1018  switch (ocirc->path_state) {
1019  /* If the circuit was closed after building, but before use, we need
1020  * to ensure we were the ones who tried to close it (and not a remote
1021  * actor). */
1022  case PATH_STATE_BUILD_SUCCEEDED:
1023  if (reason & END_CIRC_REASON_FLAG_REMOTE) {
1024  /* Remote circ close reasons on an unused circuit all could be bias */
1025  log_info(LD_CIRC,
1026  "Circuit %d remote-closed without successful use for reason %d. "
1027  "Circuit purpose %d currently %d,%s. Len %d.",
1028  ocirc->global_identifier,
1029  reason, circ->purpose, ocirc->has_opened,
1031  ocirc->build_state->desired_path_len);
1032  pathbias_count_collapse(ocirc);
1033  } else if ((reason & ~END_CIRC_REASON_FLAG_REMOTE)
1034  == END_CIRC_REASON_CHANNEL_CLOSED &&
1035  circ->n_chan &&
1036  circ->n_chan->reason_for_closing
1037  != CHANNEL_CLOSE_REQUESTED) {
1038  /* If we didn't close the channel ourselves, it could be bias */
1039  /* XXX: Only count bias if the network is live?
1040  * What about clock jumps/suspends? */
1041  log_info(LD_CIRC,
1042  "Circuit %d's channel closed without successful use for reason "
1043  "%d, channel reason %d. Circuit purpose %d currently %d,%s. Len "
1044  "%d.", ocirc->global_identifier,
1045  reason, circ->n_chan->reason_for_closing,
1046  circ->purpose, ocirc->has_opened,
1048  ocirc->build_state->desired_path_len);
1049  pathbias_count_collapse(ocirc);
1050  } else {
1052  }
1053  break;
1054 
1055  /* If we tried to use a circuit but failed, we should probe it to ensure
1056  * it has not been tampered with. */
1057  case PATH_STATE_USE_ATTEMPTED:
1058  /* XXX: Only probe and/or count failure if the network is live?
1059  * What about clock jumps/suspends? */
1060  if (pathbias_send_usable_probe(circ) == 0)
1061  return -1;
1062  else
1064 
1065  /* Any circuit where there were attempted streams but no successful
1066  * streams could be bias */
1067  log_info(LD_CIRC,
1068  "Circuit %d closed without successful use for reason %d. "
1069  "Circuit purpose %d currently %d,%s. Len %d.",
1070  ocirc->global_identifier,
1071  reason, circ->purpose, ocirc->has_opened,
1073  ocirc->build_state->desired_path_len);
1074  break;
1075 
1076  case PATH_STATE_USE_SUCCEEDED:
1079  break;
1080 
1081  case PATH_STATE_USE_FAILED:
1083  break;
1084 
1085  case PATH_STATE_NEW_CIRC:
1086  case PATH_STATE_BUILD_ATTEMPTED:
1087  case PATH_STATE_ALREADY_COUNTED:
1088  default:
1089  // Other states are uninteresting. No stats to count.
1090  break;
1091  }
1092 
1093  ocirc->path_state = PATH_STATE_ALREADY_COUNTED;
1094 
1095  return 0;
1096 }
1097 
1101 static void
1103 {
1104  entry_guard_t *guard = NULL;
1105  if (!pathbias_should_count(circ)) {
1106  return;
1107  }
1108 
1109  if (circ->cpath && circ->cpath->extend_info) {
1112  }
1113 
1114  if (guard) {
1116 
1117  /* In the long run: circuit_success ~= successful_circuit_close +
1118  * circ_failure + stream_failure */
1121  } else if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
1122  /* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
1123  * CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT and have no guards here.
1124  * No need to log that case. */
1125  log_info(LD_CIRC,
1126  "Successfully closed circuit has no known guard. "
1127  "Circuit is a %s currently %s",
1128  circuit_purpose_to_string(circ->base_.purpose),
1129  circuit_state_to_string(circ->base_.state));
1130  }
1131 }
1132 
1141 static void
1143 {
1144  entry_guard_t *guard = NULL;
1145 
1146  if (!pathbias_should_count(circ)) {
1147  return;
1148  }
1149 
1150  if (circ->cpath && circ->cpath->extend_info) {
1153  }
1154 
1155  if (guard) {
1157 
1158  pb->collapsed_circuits++;
1160  } else if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
1161  /* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
1162  * CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT and have no guards here.
1163  * No need to log that case. */
1164  log_info(LD_CIRC,
1165  "Destroyed circuit has no known guard. "
1166  "Circuit is a %s currently %s",
1167  circuit_purpose_to_string(circ->base_.purpose),
1168  circuit_state_to_string(circ->base_.state));
1169  }
1170 }
1171 
1177 static void
1179 {
1180  entry_guard_t *guard = NULL;
1181  if (!pathbias_should_count(circ)) {
1182  return;
1183  }
1184 
1185  if (circ->cpath && circ->cpath->extend_info) {
1188  }
1189 
1190  if (guard) {
1192 
1193  pb->unusable_circuits++;
1195  } else if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
1196  /* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
1197  * CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT and have no guards here.
1198  * No need to log that case. */
1199  /* XXX note cut-and-paste code in this function compared to nearby
1200  * functions. Would be nice to refactor. -RD */
1201  log_info(LD_CIRC,
1202  "Stream-failing circuit has no known guard. "
1203  "Circuit is a %s currently %s",
1204  circuit_purpose_to_string(circ->base_.purpose),
1205  circuit_state_to_string(circ->base_.state));
1206  }
1207 }
1208 
1214 void
1216 {
1217  entry_guard_t *guard = NULL;
1218 
1219  if (!pathbias_should_count(circ)) {
1220  return;
1221  }
1222 
1223  /* For hidden service circs, they can actually be used
1224  * successfully and then time out later (because
1225  * the other side declines to use them). */
1226  if (circ->path_state == PATH_STATE_USE_SUCCEEDED) {
1227  return;
1228  }
1229 
1230  if (circ->cpath && circ->cpath->extend_info) {
1233  }
1234 
1235  if (guard) {
1237 
1238  pb->timeouts++;
1240  }
1241 }
1242 
1248 static int
1249 pathbias_count_circs_in_states(entry_guard_t *guard,
1250  path_state_t from,
1251  path_state_t to)
1252 {
1253  int open_circuits = 0;
1254 
1255  /* Count currently open circuits. Give them the benefit of the doubt. */
1256  SMARTLIST_FOREACH_BEGIN(circuit_get_global_list(), circuit_t *, circ) {
1257  origin_circuit_t *ocirc = NULL;
1258  if (!CIRCUIT_IS_ORIGIN(circ) || /* didn't originate here */
1259  circ->marked_for_close) /* already counted */
1260  continue;
1261 
1262  ocirc = TO_ORIGIN_CIRCUIT(circ);
1263 
1264  if (!ocirc->cpath || !ocirc->cpath->extend_info)
1265  continue;
1266 
1267  if (ocirc->path_state >= from &&
1268  ocirc->path_state <= to &&
1269  pathbias_should_count(ocirc) &&
1270  fast_memeq(entry_guard_get_rsa_id_digest(guard),
1272  DIGEST_LEN)) {
1273  log_debug(LD_CIRC, "Found opened circuit %d in path_state %s",
1274  ocirc->global_identifier,
1276  open_circuits++;
1277  }
1278  }
1279  SMARTLIST_FOREACH_END(circ);
1280 
1281  return open_circuits;
1282 }
1283 
1291 double
1293 {
1295 
1296  return pb->successful_circuits_closed +
1298  PATH_STATE_BUILD_SUCCEEDED,
1299  PATH_STATE_USE_SUCCEEDED);
1300 }
1301 
1309 double
1310 pathbias_get_use_success_count(entry_guard_t *guard)
1311 {
1313 
1314  return pb->use_successes +
1316  PATH_STATE_USE_ATTEMPTED,
1317  PATH_STATE_USE_SUCCEEDED);
1318 }
1319 
1328 static void
1329 pathbias_measure_use_rate(entry_guard_t *guard)
1330 {
1331  const or_options_t *options = get_options();
1333 
1334  if (pb->use_attempts > pathbias_get_min_use(options)) {
1335  /* Note: We rely on the < comparison here to allow us to set a 0
1336  * rate and disable the feature entirely. If refactoring, don't
1337  * change to <= */
1339  < pathbias_get_extreme_use_rate(options)) {
1340  /* Dropping is currently disabled by default. */
1341  if (pathbias_get_dropguards(options)) {
1342  if (!pb->path_bias_disabled) {
1343  log_warn(LD_CIRC,
1344  "Guard %s is failing to carry an extremely large "
1345  "amount of stream on its circuits. "
1346  "To avoid potential route manipulation attacks, Tor has "
1347  "disabled use of this guard. "
1348  "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1349  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1350  "and %ld timed out. "
1351  "For reference, your timeout cutoff is %ld seconds.",
1352  entry_guard_describe(guard),
1354  tor_lround(pb->use_attempts),
1360  tor_lround(pb->timeouts),
1362  pb->path_bias_disabled = 1;
1363  return;
1364  }
1365  } else if (!pb->path_bias_use_extreme) {
1366  pb->path_bias_use_extreme = 1;
1367  log_warn(LD_CIRC,
1368  "Guard %s is failing to carry an extremely large "
1369  "amount of streams on its circuits. "
1370  "This could indicate a route manipulation attack, network "
1371  "overload, bad local network connectivity, or a bug. "
1372  "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1373  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1374  "and %ld timed out. "
1375  "For reference, your timeout cutoff is %ld seconds.",
1376  entry_guard_describe(guard),
1378  tor_lround(pb->use_attempts),
1384  tor_lround(pb->timeouts),
1386  }
1387  } else if (pathbias_get_use_success_count(guard)/pb->use_attempts
1388  < pathbias_get_notice_use_rate(options)) {
1389  if (!pb->path_bias_use_noticed) {
1390  pb->path_bias_use_noticed = 1;
1391  log_notice(LD_CIRC,
1392  "Guard %s is failing to carry more streams on its "
1393  "circuits than usual. "
1394  "Most likely this means the Tor network is overloaded "
1395  "or your network connection is poor. "
1396  "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1397  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1398  "and %ld timed out. "
1399  "For reference, your timeout cutoff is %ld seconds.",
1400  entry_guard_describe(guard),
1402  tor_lround(pb->use_attempts),
1408  tor_lround(pb->timeouts),
1410  }
1411  }
1412  }
1413 }
1414 
1433 static void
1434 pathbias_measure_close_rate(entry_guard_t *guard)
1435 {
1436  const or_options_t *options = get_options();
1438 
1439  if (pb->circ_attempts > pathbias_get_min_circs(options)) {
1440  /* Note: We rely on the < comparison here to allow us to set a 0
1441  * rate and disable the feature entirely. If refactoring, don't
1442  * change to <= */
1444  < pathbias_get_extreme_rate(options)) {
1445  /* Dropping is currently disabled by default. */
1446  if (pathbias_get_dropguards(options)) {
1447  if (!pb->path_bias_disabled) {
1448  log_warn(LD_CIRC,
1449  "Guard %s is failing an extremely large "
1450  "amount of circuits. "
1451  "To avoid potential route manipulation attacks, Tor has "
1452  "disabled use of this guard. "
1453  "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1454  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1455  "and %ld timed out. "
1456  "For reference, your timeout cutoff is %ld seconds.",
1457  entry_guard_describe(guard),
1461  tor_lround(pb->use_attempts),
1465  tor_lround(pb->timeouts),
1467  pb->path_bias_disabled = 1;
1468  return;
1469  }
1470  } else if (!pb->path_bias_extreme) {
1471  pb->path_bias_extreme = 1;
1472  log_warn(LD_CIRC,
1473  "Guard %s is failing an extremely large "
1474  "amount of circuits. "
1475  "This could indicate a route manipulation attack, "
1476  "extreme network overload, or a bug. "
1477  "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1478  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1479  "and %ld timed out. "
1480  "For reference, your timeout cutoff is %ld seconds.",
1481  entry_guard_describe(guard),
1485  tor_lround(pb->use_attempts),
1489  tor_lround(pb->timeouts),
1491  }
1492  } else if (pathbias_get_close_success_count(guard)/pb->circ_attempts
1493  < pathbias_get_warn_rate(options)) {
1494  if (!pb->path_bias_warned) {
1495  pb->path_bias_warned = 1;
1496  log_warn(LD_CIRC,
1497  "Guard %s is failing a very large "
1498  "amount of circuits. "
1499  "Most likely this means the Tor network is "
1500  "overloaded, but it could also mean an attack against "
1501  "you or potentially the guard itself. "
1502  "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1503  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1504  "and %ld timed out. "
1505  "For reference, your timeout cutoff is %ld seconds.",
1506  entry_guard_describe(guard),
1510  tor_lround(pb->use_attempts),
1514  tor_lround(pb->timeouts),
1516  }
1517  } else if (pathbias_get_close_success_count(guard)/pb->circ_attempts
1518  < pathbias_get_notice_rate(options)) {
1519  if (!pb->path_bias_noticed) {
1520  pb->path_bias_noticed = 1;
1521  log_notice(LD_CIRC,
1522  "Guard %s is failing more circuits than "
1523  "usual. "
1524  "Most likely this means the Tor network is overloaded. "
1525  "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1526  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1527  "and %ld timed out. "
1528  "For reference, your timeout cutoff is %ld seconds.",
1529  entry_guard_describe(guard),
1533  tor_lround(pb->use_attempts),
1537  tor_lround(pb->timeouts),
1539  }
1540  }
1541  }
1542 }
1543 
1553 static void
1554 pathbias_scale_close_rates(entry_guard_t *guard)
1555 {
1556  const or_options_t *options = get_options();
1558 
1559  /* If we get a ton of circuits, just scale everything down */
1560  if (pb->circ_attempts > pathbias_get_scale_threshold(options)) {
1561  double scale_ratio = pathbias_get_scale_ratio(options);
1562  int opened_attempts = pathbias_count_circs_in_states(guard,
1563  PATH_STATE_BUILD_ATTEMPTED, PATH_STATE_BUILD_ATTEMPTED);
1564  int opened_built = pathbias_count_circs_in_states(guard,
1565  PATH_STATE_BUILD_SUCCEEDED,
1566  PATH_STATE_USE_FAILED);
1567  /* Verify that the counts are sane before and after scaling */
1568  int counts_are_sane = (pb->circ_attempts >= pb->circ_successes);
1569 
1570  pb->circ_attempts -= (opened_attempts+opened_built);
1571  pb->circ_successes -= opened_built;
1572 
1573  pb->circ_attempts *= scale_ratio;
1574  pb->circ_successes *= scale_ratio;
1575  pb->timeouts *= scale_ratio;
1576  pb->successful_circuits_closed *= scale_ratio;
1577  pb->collapsed_circuits *= scale_ratio;
1578  pb->unusable_circuits *= scale_ratio;
1579 
1580  pb->circ_attempts += (opened_attempts+opened_built);
1581  pb->circ_successes += opened_built;
1582 
1584 
1585  log_info(LD_CIRC,
1586  "Scaled pathbias counts to (%f,%f)/%f (%d/%d open) for guard "
1587  "%s",
1589  pb->circ_attempts, opened_built, opened_attempts,
1590  entry_guard_describe(guard));
1591 
1592  /* Have the counts just become invalid by this scaling attempt? */
1593  if (counts_are_sane && pb->circ_attempts < pb->circ_successes) {
1594  log_notice(LD_BUG,
1595  "Scaling has mangled pathbias counts to %f/%f (%d/%d open) "
1596  "for guard %s",
1597  pb->circ_successes, pb->circ_attempts, opened_built,
1598  opened_attempts,
1599  entry_guard_describe(guard));
1600  }
1601  }
1602 }
1603 
1613 void
1614 pathbias_scale_use_rates(entry_guard_t *guard)
1615 {
1616  const or_options_t *options = get_options();
1618 
1619  /* If we get a ton of circuits, just scale everything down */
1620  if (pb->use_attempts > pathbias_get_scale_use_threshold(options)) {
1621  double scale_ratio = pathbias_get_scale_ratio(options);
1622  int opened_attempts = pathbias_count_circs_in_states(guard,
1623  PATH_STATE_USE_ATTEMPTED, PATH_STATE_USE_SUCCEEDED);
1624  /* Verify that the counts are sane before and after scaling */
1625  int counts_are_sane = (pb->use_attempts >= pb->use_successes);
1626 
1627  pb->use_attempts -= opened_attempts;
1628 
1629  pb->use_attempts *= scale_ratio;
1630  pb->use_successes *= scale_ratio;
1631 
1632  pb->use_attempts += opened_attempts;
1633 
1634  log_info(LD_CIRC,
1635  "Scaled pathbias use counts to %f/%f (%d open) for guard %s",
1636  pb->use_successes, pb->use_attempts, opened_attempts,
1637  entry_guard_describe(guard));
1638 
1639  /* Have the counts just become invalid by this scaling attempt? */
1640  if (counts_are_sane && pb->use_attempts < pb->use_successes) {
1641  log_notice(LD_BUG,
1642  "Scaling has mangled pathbias usage counts to %f/%f "
1643  "(%d open) for guard %s",
1644  pb->circ_successes, pb->circ_attempts,
1645  opened_attempts, entry_guard_describe(guard));
1646  }
1647 
1649  }
1650 }
#define RELAY_PAYLOAD_SIZE
Definition: or.h:605
#define CIRCUIT_PURPOSE_C_INTRODUCING
Definition: circuitlist.h:74
unsigned int path_bias_disabled
Definition: entrynodes.h:42
Header file for circuitstats.c.
unsigned int path_bias_extreme
Definition: entrynodes.h:40
static int pathbias_count_circs_in_states(entry_guard_t *guard, path_state_t from, path_state_t to)
#define CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT
Definition: circuitlist.h:94
static int entry_guard_inc_circ_attempt_count(entry_guard_t *guard)
Definition: circpathbias.c:61
void pathbias_count_build_success(origin_circuit_t *circ)
Definition: circpathbias.c:512
static int pathbias_is_new_circ_attempt(origin_circuit_t *circ)
Definition: circpathbias.c:296
Header file for circuitbuild.c.
uint8_t payload[CELL_PAYLOAD_SIZE]
Definition: cell_st.h:16
Common functions for using (pseudo-)random number generators.
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
path_state_bitfield_t path_state
double collapsed_circuits
Definition: entrynodes.h:54
Header for laplace.c.
static double pathbias_get_warn_rate(const or_options_t *options)
Definition: circpathbias.c:109
struct crypt_path_t * next
Definition: crypt_path_st.h:67
void pathbias_count_timeout(origin_circuit_t *circ)
double successful_circuits_closed
Definition: entrynodes.h:52
static void pathbias_count_use_success(origin_circuit_t *circ)
Definition: circpathbias.c:715
Definition: cell_st.h:12
static void pathbias_scale_close_rates(entry_guard_t *guard)
#define CIRCUIT_IS_ORIGIN(c)
Definition: circuitlist.h:145
const char * circuit_purpose_to_string(uint8_t purpose)
Definition: circuitlist.c:898
streamid_t get_unique_stream_id_by_circ(origin_circuit_t *circ)
crypt_path_t * cpath
void relay_header_unpack(relay_header_t *dest, const uint8_t *src)
Definition: relay.c:487
uint32_t pathbias_probe_nonce
int pathbias_get_dropguards(const or_options_t *options)
Definition: circpathbias.c:141
char * rate_limit_log(ratelim_t *lim, time_t now)
Definition: ratelim.c:41
int circuit_truncated(origin_circuit_t *circ, int reason)
Header file for config.c.
static void pathbias_measure_close_rate(entry_guard_t *guard)
double unusable_circuits
Definition: entrynodes.h:57
#define tor_free(p)
Definition: malloc.h:52
static double pathbias_get_notice_rate(const or_options_t *options)
Definition: circpathbias.c:97
static int pathbias_get_min_circs(const or_options_t *options)
Definition: circpathbias.c:84
#define tor_fragile_assert()
Definition: util_bug.h:241
unsigned int path_bias_noticed
Definition: entrynodes.h:36
int PathBiasCircThreshold
static int pathbias_get_scale_use_threshold(const or_options_t *options)
Definition: circpathbias.c:250
static void pathbias_scale_use_rates(entry_guard_t *guard)
uint8_t purpose
Definition: circuit_st.h:100
double circ_attempts
Definition: entrynodes.h:49
double use_successes
Definition: entrynodes.h:62
#define END_CIRC_REASON_FLAG_REMOTE
Definition: or.h:328
static uint32_t get_uint32(const void *cp)
Definition: bytes.h:49
streamid_t stream_id
Definition: or.h:640
const char * entry_guard_describe(const entry_guard_t *guard)
Definition: entrynodes.c:315
static double pathbias_get_notice_use_rate(const or_options_t *options)
Definition: circpathbias.c:216
#define CIRCUIT_PURPOSE_CONTROLLER
Definition: circuitlist.h:119
double pathbias_get_extreme_use_rate(const or_options_t *options)
Definition: circpathbias.c:232
void entry_guards_changed(void)
Definition: entrynodes.c:3426
Header file for channel.c.
tor_assert(buffer)
int connection_half_edge_is_valid_sendme(const smartlist_t *half_conns, streamid_t stream_id)
Header for fp.c.
time_t timestamp_dirty
Definition: circuit_st.h:176
#define LD_CIRC
Definition: log.h:79
uint8_t state
Definition: circuit_st.h:99
double circ_successes
Definition: entrynodes.h:50
long tor_lround(double d)
Definition: fp.c:31
unsigned int path_bias_use_extreme
Definition: entrynodes.h:46
#define DIGEST_LEN
Definition: digest_sizes.h:20
#define CIRCUIT_PURPOSE_C_INTRODUCE_ACKED
Definition: circuitlist.h:80
streamid_t pathbias_probe_id
#define CIRCUIT_PURPOSE_TESTING
Definition: circuitlist.h:117
Master header file for Tor-specific functionality.
int PathBiasUseThreshold
Header file for circuitbuild.c.
static void pathbias_measure_use_rate(entry_guard_t *guard)
static void pathbias_count_collapse(origin_circuit_t *circ)
void pathbias_mark_use_rollback(origin_circuit_t *circ)
Definition: circpathbias.c:700
entry_guard_t * entry_guard_get_by_id_digest(const char *digest)
Definition: entrynodes.c:3219
Header file for circuituse.c.
double pathbias_get_close_success_count(entry_guard_t *guard)
smartlist_t * half_streams
int pathbias_check_probe_response(circuit_t *circ, const cell_t *cell)
Definition: circpathbias.c:879
#define CIRCUIT_PURPOSE_S_CONNECT_REND
Definition: circuitlist.h:108
Header file for circuitlist.c.
#define CIRCUIT_PURPOSE_PATH_BIAS_TESTING
Definition: circuitlist.h:121
double pathbias_get_extreme_rate(const or_options_t *options)
Definition: circpathbias.c:125
int pathbias_check_close(origin_circuit_t *ocirc, int reason)
static double pathbias_get_scale_ratio(const or_options_t *options)
Definition: circpathbias.c:177
uint16_t length
Definition: or.h:642
uint8_t command
Definition: or.h:638
struct crypt_path_t * prev
Definition: crypt_path_st.h:70
cpath_build_state_t * build_state
Header file for connection_edge.c.
static int pathbias_get_scale_threshold(const or_options_t *options)
Definition: circpathbias.c:158
static int pathbias_send_usable_probe(circuit_t *circ)
Definition: circpathbias.c:776
origin_circuit_t * TO_ORIGIN_CIRCUIT(circuit_t *x)
Definition: circuitlist.c:163
static int pathbias_should_count(origin_circuit_t *circ)
Definition: circpathbias.c:323
const char * circuit_state_to_string(int state)
Definition: circuitlist.c:757
int tor_snprintf(char *str, size_t size, const char *format,...)
Definition: printf.c:27
#define CELL_PAYLOAD_SIZE
Definition: or.h:576
Header file for relay.c.
char identity_digest[DIGEST_LEN]
unsigned int has_opened
enum channel_s::@9 reason_for_closing
uint8_t state
Definition: crypt_path_st.h:63
struct timeval timestamp_began
Definition: circuit_st.h:154
int connection_half_edge_is_valid_end(smartlist_t *half_conns, streamid_t stream_id)
unsigned int path_bias_use_noticed
Definition: entrynodes.h:44
double get_circuit_build_close_time_ms(void)
Definition: circuitstats.c:97
time_t approx_time(void)
Definition: approx_time.c:32
const char * pathbias_state_to_string(path_state_t state)
Definition: circpathbias.c:265
void pathbias_count_use_attempt(origin_circuit_t *circ)
Definition: circpathbias.c:604
extend_info_t * extend_info
Definition: crypt_path_st.h:56
void circuit_change_purpose(circuit_t *circ, uint8_t new_purpose)
Definition: circuituse.c:3062
double use_attempts
Definition: entrynodes.h:61
int connection_half_edge_is_valid_resolved(smartlist_t *half_conns, streamid_t stream_id)
int pathbias_count_build_attempt(origin_circuit_t *circ)
Definition: circpathbias.c:424
void circuit_read_valid_data(origin_circuit_t *circ, uint16_t relay_body_len)
Definition: circuituse.c:3151
double pathbias_get_use_success_count(entry_guard_t *guard)
static void pathbias_count_successful_close(origin_circuit_t *circ)
char identity_digest[DIGEST_LEN]
Definition: channel.h:384
void pathbias_count_valid_cells(circuit_t *circ, const cell_t *cell)
Definition: circpathbias.c:939
#define CIRCUIT_PURPOSE_S_REND_JOINED
Definition: circuitlist.h:111
#define LD_PROTOCOL
Definition: log.h:69
static int pathbias_get_min_use(const or_options_t *options)
Definition: circpathbias.c:203
#define RELAY_HEADER_SIZE
Definition: or.h:603
void pathbias_mark_use_success(origin_circuit_t *circ)
Definition: circpathbias.c:661
unsigned int path_bias_warned
Definition: entrynodes.h:38
guard_pathbias_t * entry_guard_get_pathbias_state(entry_guard_t *guard)
Definition: entrynodes.c:334
Header file for networkstatus.c.
#define LD_BUG
Definition: log.h:83
static void pathbias_count_use_failed(origin_circuit_t *circ)
channel_t * n_chan
Definition: circuit_st.h:58
int connection_half_edge_is_valid_connected(const smartlist_t *half_conns, streamid_t stream_id)
int connection_half_edge_is_valid_data(const smartlist_t *half_conns, streamid_t stream_id)
const char * entry_guard_get_rsa_id_digest(const entry_guard_t *guard)
Definition: entrynodes.c:327
char * tor_dup_ip(uint32_t addr)
Definition: address.c:1890