tor  0.4.0.1-alpha
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  /*
180  * The scale factor is the denominator for our scaling
181  * of circuit counts for our path bias window.
182  *
183  * Note that our use of doubles for the path bias state
184  * file means that powers of 2 work best here.
185  */
186  int denominator = networkstatus_get_param(NULL, "pb_scalefactor",
187  2, 2, INT32_MAX);
188  (void) options;
194  return networkstatus_get_param(NULL, "pb_multfactor",
195  1, 1, denominator)/((double)denominator);
196 }
197 
200 static int
202 {
203 #define DFLT_PATH_BIAS_MIN_USE 20
204  if (options->PathBiasUseThreshold >= 3)
205  return options->PathBiasUseThreshold;
206  else
207  return networkstatus_get_param(NULL, "pb_minuse",
208  DFLT_PATH_BIAS_MIN_USE,
209  3, INT32_MAX);
210 }
211 
213 static double
215 {
216 #define DFLT_PATH_BIAS_NOTICE_USE_PCT 80
217  if (options->PathBiasNoticeUseRate >= 0.0)
218  return options->PathBiasNoticeUseRate;
219  else
220  return networkstatus_get_param(NULL, "pb_noticeusepct",
221  DFLT_PATH_BIAS_NOTICE_USE_PCT,
222  0, 100)/100.0;
223 }
224 
229 double
231 {
232 #define DFLT_PATH_BIAS_EXTREME_USE_PCT 60
233  if (options->PathBiasExtremeUseRate >= 0.0)
234  return options->PathBiasExtremeUseRate;
235  else
236  return networkstatus_get_param(NULL, "pb_extremeusepct",
237  DFLT_PATH_BIAS_EXTREME_USE_PCT,
238  0, 100)/100.0;
239 }
240 
247 static int
249 {
250 #define DFLT_PATH_BIAS_SCALE_USE_THRESHOLD 100
251  if (options->PathBiasScaleUseThreshold >= 10)
252  return options->PathBiasScaleUseThreshold;
253  else
254  return networkstatus_get_param(NULL, "pb_scaleuse",
255  DFLT_PATH_BIAS_SCALE_USE_THRESHOLD,
256  10, INT32_MAX);
257 }
258 
262 const char *
263 pathbias_state_to_string(path_state_t state)
264 {
265  switch (state) {
266  case PATH_STATE_NEW_CIRC:
267  return "new";
268  case PATH_STATE_BUILD_ATTEMPTED:
269  return "build attempted";
270  case PATH_STATE_BUILD_SUCCEEDED:
271  return "build succeeded";
272  case PATH_STATE_USE_ATTEMPTED:
273  return "use attempted";
274  case PATH_STATE_USE_SUCCEEDED:
275  return "use succeeded";
276  case PATH_STATE_USE_FAILED:
277  return "use failed";
278  case PATH_STATE_ALREADY_COUNTED:
279  return "already counted";
280  }
281 
282  return "unknown";
283 }
284 
293 static int
295 {
296 #define N2N_TAGGING_IS_POSSIBLE
297 #ifdef N2N_TAGGING_IS_POSSIBLE
298  /* cpath is a circular list. We want circs with more than one hop,
299  * and the second hop must be waiting for keys still (it's just
300  * about to get them). */
301  return circ->cpath &&
302  circ->cpath->next != circ->cpath &&
303  circ->cpath->next->state == CPATH_STATE_AWAITING_KEYS;
304 #else /* !(defined(N2N_TAGGING_IS_POSSIBLE)) */
305  /* If tagging attacks are no longer possible, we probably want to
306  * count bias from the first hop. However, one could argue that
307  * timing-based tagging is still more useful than per-hop failure.
308  * In which case, we'd never want to use this.
309  */
310  return circ->cpath &&
311  circ->cpath->state == CPATH_STATE_AWAITING_KEYS;
312 #endif /* defined(N2N_TAGGING_IS_POSSIBLE) */
313 }
314 
320 static int
322 {
323 #define PATHBIAS_COUNT_INTERVAL (600)
324  static ratelim_t count_limit =
325  RATELIM_INIT(PATHBIAS_COUNT_INTERVAL);
326  char *rate_msg = NULL;
327 
328  /* We can't do path bias accounting without entry guards.
329  * Testing and controller circuits also have no guards.
330  *
331  * We also don't count server-side rends, because their
332  * endpoint could be chosen maliciously.
333  * Similarly, we can't count client-side intro attempts,
334  * because clients can be manipulated into connecting to
335  * malicious intro points. */
336  if (get_options()->UseEntryGuards == 0 ||
337  circ->base_.purpose == CIRCUIT_PURPOSE_TESTING ||
338  circ->base_.purpose == CIRCUIT_PURPOSE_CONTROLLER ||
339  circ->base_.purpose == CIRCUIT_PURPOSE_S_CONNECT_REND ||
340  circ->base_.purpose == CIRCUIT_PURPOSE_S_REND_JOINED ||
341  (circ->base_.purpose >= CIRCUIT_PURPOSE_C_INTRODUCING &&
342  circ->base_.purpose <= CIRCUIT_PURPOSE_C_INTRODUCE_ACKED)) {
343 
344  /* Check to see if the shouldcount result has changed due to a
345  * unexpected purpose change that would affect our results.
346  *
347  * The reason we check the path state too here is because for the
348  * cannibalized versions of these purposes, we count them as successful
349  * before their purpose change.
350  */
351  if (circ->pathbias_shouldcount == PATHBIAS_SHOULDCOUNT_COUNTED
352  && circ->path_state != PATH_STATE_ALREADY_COUNTED) {
353  log_info(LD_BUG,
354  "Circuit %d is now being ignored despite being counted "
355  "in the past. Purpose is %s, path state is %s",
356  circ->global_identifier,
357  circuit_purpose_to_string(circ->base_.purpose),
359  }
360  circ->pathbias_shouldcount = PATHBIAS_SHOULDCOUNT_IGNORED;
361  return 0;
362  }
363 
364  /* Completely ignore one hop circuits */
365  if (circ->build_state->onehop_tunnel ||
366  circ->build_state->desired_path_len == 1) {
367  /* Check for inconsistency */
368  if (circ->build_state->desired_path_len != 1 ||
369  !circ->build_state->onehop_tunnel) {
370  if ((rate_msg = rate_limit_log(&count_limit, approx_time()))) {
371  log_info(LD_BUG,
372  "One-hop circuit has length %d. Path state is %s. "
373  "Circuit is a %s currently %s.%s",
376  circuit_purpose_to_string(circ->base_.purpose),
377  circuit_state_to_string(circ->base_.state),
378  rate_msg);
379  tor_free(rate_msg);
380  }
382  }
383 
384  /* Check to see if the shouldcount result has changed due to a
385  * unexpected change that would affect our results */
386  if (circ->pathbias_shouldcount == PATHBIAS_SHOULDCOUNT_COUNTED) {
387  log_info(LD_BUG,
388  "One-hop circuit %d is now being ignored despite being counted "
389  "in the past. Purpose is %s, path state is %s",
390  circ->global_identifier,
391  circuit_purpose_to_string(circ->base_.purpose),
393  }
394  circ->pathbias_shouldcount = PATHBIAS_SHOULDCOUNT_IGNORED;
395  return 0;
396  }
397 
398  /* Check to see if the shouldcount result has changed due to a
399  * unexpected purpose change that would affect our results */
400  if (circ->pathbias_shouldcount == PATHBIAS_SHOULDCOUNT_IGNORED) {
401  log_info(LD_BUG,
402  "Circuit %d is now being counted despite being ignored "
403  "in the past. Purpose is %s, path state is %s",
404  circ->global_identifier,
405  circuit_purpose_to_string(circ->base_.purpose),
407  }
408  circ->pathbias_shouldcount = PATHBIAS_SHOULDCOUNT_COUNTED;
409 
410  return 1;
411 }
412 
419 int
421 {
422 #define CIRC_ATTEMPT_NOTICE_INTERVAL (600)
423  static ratelim_t circ_attempt_notice_limit =
424  RATELIM_INIT(CIRC_ATTEMPT_NOTICE_INTERVAL);
425  char *rate_msg = NULL;
426 
427  if (!pathbias_should_count(circ)) {
428  return 0;
429  }
430 
431  if (pathbias_is_new_circ_attempt(circ)) {
432  /* Help track down the real cause of bug #6475: */
433  if (circ->has_opened && circ->path_state != PATH_STATE_BUILD_ATTEMPTED) {
434  if ((rate_msg = rate_limit_log(&circ_attempt_notice_limit,
435  approx_time()))) {
436  log_info(LD_BUG,
437  "Opened circuit is in strange path state %s. "
438  "Circuit is a %s currently %s.%s",
440  circuit_purpose_to_string(circ->base_.purpose),
441  circuit_state_to_string(circ->base_.state),
442  rate_msg);
443  tor_free(rate_msg);
444  }
445  }
446 
447  /* Don't re-count cannibalized circs.. */
448  if (!circ->has_opened) {
449  entry_guard_t *guard = NULL;
450 
451  if (circ->cpath && circ->cpath->extend_info) {
454  } else if (circ->base_.n_chan) {
455  guard =
457  }
458 
459  if (guard) {
460  if (circ->path_state == PATH_STATE_NEW_CIRC) {
461  circ->path_state = PATH_STATE_BUILD_ATTEMPTED;
462 
463  if (entry_guard_inc_circ_attempt_count(guard) < 0) {
464  /* Bogus guard; we already warned. */
465  return -END_CIRC_REASON_TORPROTOCOL;
466  }
467  } else {
468  if ((rate_msg = rate_limit_log(&circ_attempt_notice_limit,
469  approx_time()))) {
470  log_info(LD_BUG,
471  "Unopened circuit has strange path state %s. "
472  "Circuit is a %s currently %s.%s",
474  circuit_purpose_to_string(circ->base_.purpose),
475  circuit_state_to_string(circ->base_.state),
476  rate_msg);
477  tor_free(rate_msg);
478  }
479  }
480  } else {
481  if ((rate_msg = rate_limit_log(&circ_attempt_notice_limit,
482  approx_time()))) {
483  log_info(LD_CIRC,
484  "Unopened circuit has no known guard. "
485  "Circuit is a %s currently %s.%s",
486  circuit_purpose_to_string(circ->base_.purpose),
487  circuit_state_to_string(circ->base_.state),
488  rate_msg);
489  tor_free(rate_msg);
490  }
491  }
492  }
493  }
494 
495  return 0;
496 }
497 
505 void
507 {
508 #define SUCCESS_NOTICE_INTERVAL (600)
509  static ratelim_t success_notice_limit =
510  RATELIM_INIT(SUCCESS_NOTICE_INTERVAL);
511  char *rate_msg = NULL;
512  entry_guard_t *guard = NULL;
513 
514  if (!pathbias_should_count(circ)) {
515  return;
516  }
517 
518  /* Don't count cannibalized/reused circs for path bias
519  * "build" success, since they get counted under "use" success. */
520  if (!circ->has_opened) {
521  if (circ->cpath && circ->cpath->extend_info) {
524  }
525 
526  if (guard) {
528 
529  if (circ->path_state == PATH_STATE_BUILD_ATTEMPTED) {
530  circ->path_state = PATH_STATE_BUILD_SUCCEEDED;
531  pb->circ_successes++;
533 
534  log_info(LD_CIRC, "Got success count %f/%f for guard %s",
535  pb->circ_successes, pb->circ_attempts,
536  entry_guard_describe(guard));
537  } else {
538  if ((rate_msg = rate_limit_log(&success_notice_limit,
539  approx_time()))) {
540  log_info(LD_BUG,
541  "Succeeded circuit is in strange path state %s. "
542  "Circuit is a %s currently %s.%s",
544  circuit_purpose_to_string(circ->base_.purpose),
545  circuit_state_to_string(circ->base_.state),
546  rate_msg);
547  tor_free(rate_msg);
548  }
549  }
550 
551  if (pb->circ_attempts < pb->circ_successes) {
552  log_notice(LD_BUG, "Unexpectedly high successes counts (%f/%f) "
553  "for guard %s",
554  pb->circ_successes, pb->circ_attempts,
555  entry_guard_describe(guard));
556  }
557  /* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
558  * CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT and have no guards here.
559  * No need to log that case. */
560  } else if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
561  if ((rate_msg = rate_limit_log(&success_notice_limit,
562  approx_time()))) {
563  log_info(LD_CIRC,
564  "Completed circuit has no known guard. "
565  "Circuit is a %s currently %s.%s",
566  circuit_purpose_to_string(circ->base_.purpose),
567  circuit_state_to_string(circ->base_.state),
568  rate_msg);
569  tor_free(rate_msg);
570  }
571  }
572  } else {
573  if (circ->path_state < PATH_STATE_BUILD_SUCCEEDED) {
574  if ((rate_msg = rate_limit_log(&success_notice_limit,
575  approx_time()))) {
576  log_info(LD_BUG,
577  "Opened circuit is in strange path state %s. "
578  "Circuit is a %s currently %s.%s",
580  circuit_purpose_to_string(circ->base_.purpose),
581  circuit_state_to_string(circ->base_.state),
582  rate_msg);
583  tor_free(rate_msg);
584  }
585  }
586  }
587 }
588 
595 void
597 {
598  if (!pathbias_should_count(circ)) {
599  return;
600  }
601 
602  if (circ->path_state < PATH_STATE_BUILD_SUCCEEDED) {
603  log_notice(LD_BUG,
604  "Used circuit is in strange path state %s. "
605  "Circuit is a %s currently %s.",
607  circuit_purpose_to_string(circ->base_.purpose),
608  circuit_state_to_string(circ->base_.state));
609  } else if (circ->path_state < PATH_STATE_USE_ATTEMPTED) {
610  entry_guard_t *guard = entry_guard_get_by_id_digest(
612  if (guard) {
614 
617  pb->use_attempts++;
619 
620  log_debug(LD_CIRC,
621  "Marked circuit %d (%f/%f) as used for guard %s.",
622  circ->global_identifier,
623  pb->use_successes, pb->use_attempts,
624  entry_guard_describe(guard));
625  }
626 
627  circ->path_state = PATH_STATE_USE_ATTEMPTED;
628  } else {
629  /* Harmless but educational log message */
630  log_info(LD_CIRC,
631  "Used circuit %d is already in path state %s. "
632  "Circuit is a %s currently %s.",
633  circ->global_identifier,
635  circuit_purpose_to_string(circ->base_.purpose),
636  circuit_state_to_string(circ->base_.state));
637  }
638 
639  return;
640 }
641 
651 void
653 {
654  if (!pathbias_should_count(circ)) {
655  return;
656  }
657 
658  if (circ->path_state < PATH_STATE_USE_ATTEMPTED) {
659  log_notice(LD_BUG,
660  "Used circuit %d is in strange path state %s. "
661  "Circuit is a %s currently %s.",
662  circ->global_identifier,
664  circuit_purpose_to_string(circ->base_.purpose),
665  circuit_state_to_string(circ->base_.state));
666 
668  }
669 
670  /* We don't do any accounting at the guard until actual circuit close */
671  circ->path_state = PATH_STATE_USE_SUCCEEDED;
672 
673  return;
674 }
675 
690 void
692 {
693  if (circ->path_state == PATH_STATE_USE_SUCCEEDED) {
694  log_info(LD_CIRC,
695  "Rolling back pathbias use state to 'attempted' for detached "
696  "circuit %d", circ->global_identifier);
697  circ->path_state = PATH_STATE_USE_ATTEMPTED;
698  }
699 }
700 
705 static void
707 {
708  entry_guard_t *guard;
709 
710  if (!pathbias_should_count(circ)) {
711  return;
712  }
713 
714  if (circ->path_state != PATH_STATE_USE_SUCCEEDED) {
715  log_notice(LD_BUG,
716  "Successfully used circuit %d is in strange path state %s. "
717  "Circuit is a %s currently %s.",
718  circ->global_identifier,
720  circuit_purpose_to_string(circ->base_.purpose),
721  circuit_state_to_string(circ->base_.state));
722  } else {
725  if (guard) {
727 
728  pb->use_successes++;
730 
731  if (pb->use_attempts < pb->use_successes) {
732  log_notice(LD_BUG, "Unexpectedly high use successes counts (%f/%f) "
733  "for guard %s",
734  pb->use_successes, pb->use_attempts,
735  entry_guard_describe(guard));
736  }
737 
738  log_debug(LD_CIRC,
739  "Marked circuit %d (%f/%f) as used successfully for guard %s",
740  circ->global_identifier, pb->use_successes,
741  pb->use_attempts,
742  entry_guard_describe(guard));
743  }
744  }
745 
746  return;
747 }
748 
766 static int
768 {
769  /* Based on connection_ap_handshake_send_begin() */
770  char payload[CELL_PAYLOAD_SIZE];
771  int payload_len;
772  origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
773  crypt_path_t *cpath_layer = NULL;
774  char *probe_nonce = NULL;
775 
776  tor_assert(ocirc);
777 
778  cpath_layer = ocirc->cpath->prev;
779 
780  if (cpath_layer->state != CPATH_STATE_OPEN) {
781  /* This can happen for cannibalized circuits. Their
782  * last hop isn't yet open */
783  log_info(LD_CIRC,
784  "Got pathbias probe request for unopened circuit %d. "
785  "Opened %d, len %d", ocirc->global_identifier,
786  ocirc->has_opened, ocirc->build_state->desired_path_len);
787  return -1;
788  }
789 
790  /* We already went down this road. */
792  ocirc->pathbias_probe_id) {
793  log_info(LD_CIRC,
794  "Got pathbias probe request for circuit %d with "
795  "outstanding probe", ocirc->global_identifier);
796  return -1;
797  }
798 
799  /* Can't probe if the channel isn't open */
800  if (circ->n_chan == NULL ||
801  (!CHANNEL_IS_OPEN(circ->n_chan)
802  && !CHANNEL_IS_MAINT(circ->n_chan))) {
803  log_info(LD_CIRC,
804  "Skipping pathbias probe for circuit %d: Channel is not open.",
805  ocirc->global_identifier);
806  return -1;
807  }
808 
810 
811  /* Update timestamp for when circuit_expire_building() should kill us */
812  tor_gettimeofday(&circ->timestamp_began);
813 
814  /* Generate a random address for the nonce */
815  crypto_rand((char*)&ocirc->pathbias_probe_nonce,
816  sizeof(ocirc->pathbias_probe_nonce));
817  ocirc->pathbias_probe_nonce &= 0x00ffffff;
818  probe_nonce = tor_dup_ip(ocirc->pathbias_probe_nonce);
819 
820  tor_snprintf(payload,RELAY_PAYLOAD_SIZE, "%s:25", probe_nonce);
821  payload_len = (int)strlen(payload)+1;
822 
823  // XXX: need this? Can we assume ipv4 will always be supported?
824  // If not, how do we tell?
825  //if (payload_len <= RELAY_PAYLOAD_SIZE - 4 && edge_conn->begincell_flags) {
826  // set_uint32(payload + payload_len, htonl(edge_conn->begincell_flags));
827  // payload_len += 4;
828  //}
829 
830  /* Generate+Store stream id, make sure it's non-zero */
832 
833  if (ocirc->pathbias_probe_id==0) {
834  log_warn(LD_CIRC,
835  "Ran out of stream IDs on circuit %u during "
836  "pathbias probe attempt.", ocirc->global_identifier);
837  tor_free(probe_nonce);
838  return -1;
839  }
840 
841  log_info(LD_CIRC,
842  "Sending pathbias testing cell to %s:25 on stream %d for circ %d.",
843  probe_nonce, ocirc->pathbias_probe_id, ocirc->global_identifier);
844  tor_free(probe_nonce);
845 
846  /* Send a test relay cell */
847  if (relay_send_command_from_edge(ocirc->pathbias_probe_id, circ,
848  RELAY_COMMAND_BEGIN, payload,
849  payload_len, cpath_layer) < 0) {
850  log_notice(LD_CIRC,
851  "Failed to send pathbias probe cell on circuit %d.",
852  ocirc->global_identifier);
853  return -1;
854  }
855 
856  /* Mark it freshly dirty so it doesn't get expired in the meantime */
857  circ->timestamp_dirty = time(NULL);
858 
859  return 0;
860 }
861 
869 int
871 {
872  /* Based on connection_edge_process_relay_cell() */
873  relay_header_t rh;
874  int reason;
875  uint32_t ipv4_host;
876  origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
877 
878  tor_assert(cell);
879  tor_assert(ocirc);
881 
882  relay_header_unpack(&rh, cell->payload);
883 
884  reason = rh.length > 0 ?
885  get_uint8(cell->payload+RELAY_HEADER_SIZE) : END_STREAM_REASON_MISC;
886 
887  if (rh.command == RELAY_COMMAND_END &&
888  reason == END_STREAM_REASON_EXITPOLICY &&
889  ocirc->pathbias_probe_id == rh.stream_id) {
890 
891  /* Check length+extract host: It is in network order after the reason code.
892  * See connection_edge_end(). */
893  if (rh.length < 9) { /* reason+ipv4+dns_ttl */
894  log_notice(LD_PROTOCOL,
895  "Short path bias probe response length field (%d).", rh.length);
896  return - END_CIRC_REASON_TORPROTOCOL;
897  }
898 
899  ipv4_host = ntohl(get_uint32(cell->payload+RELAY_HEADER_SIZE+1));
900 
901  /* Check nonce */
902  if (ipv4_host == ocirc->pathbias_probe_nonce) {
904  circuit_read_valid_data(ocirc, rh.length);
905  circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
906  log_info(LD_CIRC,
907  "Got valid path bias probe back for circ %d, stream %d.",
908  ocirc->global_identifier, ocirc->pathbias_probe_id);
909  return 0;
910  } else {
911  log_notice(LD_CIRC,
912  "Got strange probe value 0x%x vs 0x%x back for circ %d, "
913  "stream %d.", ipv4_host, ocirc->pathbias_probe_nonce,
914  ocirc->global_identifier, ocirc->pathbias_probe_id);
915  return -1;
916  }
917  }
918  log_info(LD_CIRC,
919  "Got another cell back back on pathbias probe circuit %d: "
920  "Command: %d, Reason: %d, Stream-id: %d",
921  ocirc->global_identifier, rh.command, reason, rh.stream_id);
922  return -1;
923 }
924 
929 void
931 {
932  origin_circuit_t *ocirc = TO_ORIGIN_CIRCUIT(circ);
933  relay_header_t rh;
934 
935  relay_header_unpack(&rh, cell->payload);
936 
937  /* Check to see if this is a cell from a previous connection,
938  * or is a request to close the circuit. */
939  switch (rh.command) {
940  case RELAY_COMMAND_TRUNCATED:
941  /* Truncated cells can arrive on path bias circs. When they do,
942  * just process them. This closes the circ, but it was junk anyway.
943  * No reason to wait for the probe. */
944  circuit_read_valid_data(ocirc, rh.length);
946  get_uint8(cell->payload + RELAY_HEADER_SIZE));
947 
948  break;
949 
950  case RELAY_COMMAND_END:
952  rh.stream_id)) {
954  }
955  break;
956 
957  case RELAY_COMMAND_DATA:
959  rh.stream_id)) {
961  }
962  break;
963 
964  case RELAY_COMMAND_SENDME:
966  rh.stream_id)) {
968  }
969  break;
970 
971  case RELAY_COMMAND_CONNECTED:
973  rh.stream_id)) {
975  }
976  break;
977 
978  case RELAY_COMMAND_RESOLVED:
980  rh.stream_id)) {
982  }
983  break;
984  }
985 }
986 
1000 int
1002 {
1003  circuit_t *circ = &ocirc->base_;
1004 
1005  if (!pathbias_should_count(ocirc)) {
1006  return 0;
1007  }
1008 
1009  switch (ocirc->path_state) {
1010  /* If the circuit was closed after building, but before use, we need
1011  * to ensure we were the ones who tried to close it (and not a remote
1012  * actor). */
1013  case PATH_STATE_BUILD_SUCCEEDED:
1014  if (reason & END_CIRC_REASON_FLAG_REMOTE) {
1015  /* Remote circ close reasons on an unused circuit all could be bias */
1016  log_info(LD_CIRC,
1017  "Circuit %d remote-closed without successful use for reason %d. "
1018  "Circuit purpose %d currently %d,%s. Len %d.",
1019  ocirc->global_identifier,
1020  reason, circ->purpose, ocirc->has_opened,
1022  ocirc->build_state->desired_path_len);
1023  pathbias_count_collapse(ocirc);
1024  } else if ((reason & ~END_CIRC_REASON_FLAG_REMOTE)
1025  == END_CIRC_REASON_CHANNEL_CLOSED &&
1026  circ->n_chan &&
1027  circ->n_chan->reason_for_closing
1028  != CHANNEL_CLOSE_REQUESTED) {
1029  /* If we didn't close the channel ourselves, it could be bias */
1030  /* XXX: Only count bias if the network is live?
1031  * What about clock jumps/suspends? */
1032  log_info(LD_CIRC,
1033  "Circuit %d's channel closed without successful use for reason "
1034  "%d, channel reason %d. Circuit purpose %d currently %d,%s. Len "
1035  "%d.", ocirc->global_identifier,
1036  reason, circ->n_chan->reason_for_closing,
1037  circ->purpose, ocirc->has_opened,
1039  ocirc->build_state->desired_path_len);
1040  pathbias_count_collapse(ocirc);
1041  } else {
1043  }
1044  break;
1045 
1046  /* If we tried to use a circuit but failed, we should probe it to ensure
1047  * it has not been tampered with. */
1048  case PATH_STATE_USE_ATTEMPTED:
1049  /* XXX: Only probe and/or count failure if the network is live?
1050  * What about clock jumps/suspends? */
1051  if (pathbias_send_usable_probe(circ) == 0)
1052  return -1;
1053  else
1055 
1056  /* Any circuit where there were attempted streams but no successful
1057  * streams could be bias */
1058  log_info(LD_CIRC,
1059  "Circuit %d closed without successful use for reason %d. "
1060  "Circuit purpose %d currently %d,%s. Len %d.",
1061  ocirc->global_identifier,
1062  reason, circ->purpose, ocirc->has_opened,
1064  ocirc->build_state->desired_path_len);
1065  break;
1066 
1067  case PATH_STATE_USE_SUCCEEDED:
1070  break;
1071 
1072  case PATH_STATE_USE_FAILED:
1074  break;
1075 
1076  case PATH_STATE_NEW_CIRC:
1077  case PATH_STATE_BUILD_ATTEMPTED:
1078  case PATH_STATE_ALREADY_COUNTED:
1079  default:
1080  // Other states are uninteresting. No stats to count.
1081  break;
1082  }
1083 
1084  ocirc->path_state = PATH_STATE_ALREADY_COUNTED;
1085 
1086  return 0;
1087 }
1088 
1092 static void
1094 {
1095  entry_guard_t *guard = NULL;
1096  if (!pathbias_should_count(circ)) {
1097  return;
1098  }
1099 
1100  if (circ->cpath && circ->cpath->extend_info) {
1103  }
1104 
1105  if (guard) {
1107 
1108  /* In the long run: circuit_success ~= successful_circuit_close +
1109  * circ_failure + stream_failure */
1112  } else if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
1113  /* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
1114  * CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT and have no guards here.
1115  * No need to log that case. */
1116  log_info(LD_CIRC,
1117  "Successfully closed circuit has no known guard. "
1118  "Circuit is a %s currently %s",
1119  circuit_purpose_to_string(circ->base_.purpose),
1120  circuit_state_to_string(circ->base_.state));
1121  }
1122 }
1123 
1132 static void
1134 {
1135  entry_guard_t *guard = NULL;
1136 
1137  if (!pathbias_should_count(circ)) {
1138  return;
1139  }
1140 
1141  if (circ->cpath && circ->cpath->extend_info) {
1144  }
1145 
1146  if (guard) {
1148 
1149  pb->collapsed_circuits++;
1151  } else if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
1152  /* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
1153  * CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT and have no guards here.
1154  * No need to log that case. */
1155  log_info(LD_CIRC,
1156  "Destroyed circuit has no known guard. "
1157  "Circuit is a %s currently %s",
1158  circuit_purpose_to_string(circ->base_.purpose),
1159  circuit_state_to_string(circ->base_.state));
1160  }
1161 }
1162 
1168 static void
1170 {
1171  entry_guard_t *guard = NULL;
1172  if (!pathbias_should_count(circ)) {
1173  return;
1174  }
1175 
1176  if (circ->cpath && circ->cpath->extend_info) {
1179  }
1180 
1181  if (guard) {
1183 
1184  pb->unusable_circuits++;
1186  } else if (circ->base_.purpose != CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
1187  /* In rare cases, CIRCUIT_PURPOSE_TESTING can get converted to
1188  * CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT and have no guards here.
1189  * No need to log that case. */
1190  /* XXX note cut-and-paste code in this function compared to nearby
1191  * functions. Would be nice to refactor. -RD */
1192  log_info(LD_CIRC,
1193  "Stream-failing circuit has no known guard. "
1194  "Circuit is a %s currently %s",
1195  circuit_purpose_to_string(circ->base_.purpose),
1196  circuit_state_to_string(circ->base_.state));
1197  }
1198 }
1199 
1205 void
1207 {
1208  entry_guard_t *guard = NULL;
1209 
1210  if (!pathbias_should_count(circ)) {
1211  return;
1212  }
1213 
1214  /* For hidden service circs, they can actually be used
1215  * successfully and then time out later (because
1216  * the other side declines to use them). */
1217  if (circ->path_state == PATH_STATE_USE_SUCCEEDED) {
1218  return;
1219  }
1220 
1221  if (circ->cpath && circ->cpath->extend_info) {
1224  }
1225 
1226  if (guard) {
1228 
1229  pb->timeouts++;
1231  }
1232 }
1233 
1239 static int
1240 pathbias_count_circs_in_states(entry_guard_t *guard,
1241  path_state_t from,
1242  path_state_t to)
1243 {
1244  int open_circuits = 0;
1245 
1246  /* Count currently open circuits. Give them the benefit of the doubt. */
1247  SMARTLIST_FOREACH_BEGIN(circuit_get_global_list(), circuit_t *, circ) {
1248  origin_circuit_t *ocirc = NULL;
1249  if (!CIRCUIT_IS_ORIGIN(circ) || /* didn't originate here */
1250  circ->marked_for_close) /* already counted */
1251  continue;
1252 
1253  ocirc = TO_ORIGIN_CIRCUIT(circ);
1254 
1255  if (!ocirc->cpath || !ocirc->cpath->extend_info)
1256  continue;
1257 
1258  if (ocirc->path_state >= from &&
1259  ocirc->path_state <= to &&
1260  pathbias_should_count(ocirc) &&
1261  fast_memeq(entry_guard_get_rsa_id_digest(guard),
1263  DIGEST_LEN)) {
1264  log_debug(LD_CIRC, "Found opened circuit %d in path_state %s",
1265  ocirc->global_identifier,
1267  open_circuits++;
1268  }
1269  }
1270  SMARTLIST_FOREACH_END(circ);
1271 
1272  return open_circuits;
1273 }
1274 
1282 double
1284 {
1286 
1287  return pb->successful_circuits_closed +
1289  PATH_STATE_BUILD_SUCCEEDED,
1290  PATH_STATE_USE_SUCCEEDED);
1291 }
1292 
1300 double
1301 pathbias_get_use_success_count(entry_guard_t *guard)
1302 {
1304 
1305  return pb->use_successes +
1307  PATH_STATE_USE_ATTEMPTED,
1308  PATH_STATE_USE_SUCCEEDED);
1309 }
1310 
1319 static void
1320 pathbias_measure_use_rate(entry_guard_t *guard)
1321 {
1322  const or_options_t *options = get_options();
1324 
1325  if (pb->use_attempts > pathbias_get_min_use(options)) {
1326  /* Note: We rely on the < comparison here to allow us to set a 0
1327  * rate and disable the feature entirely. If refactoring, don't
1328  * change to <= */
1330  < pathbias_get_extreme_use_rate(options)) {
1331  /* Dropping is currently disabled by default. */
1332  if (pathbias_get_dropguards(options)) {
1333  if (!pb->path_bias_disabled) {
1334  log_warn(LD_CIRC,
1335  "Guard %s is failing to carry an extremely large "
1336  "amount of stream on its circuits. "
1337  "To avoid potential route manipulation attacks, Tor has "
1338  "disabled use of this guard. "
1339  "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1340  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1341  "and %ld timed out. "
1342  "For reference, your timeout cutoff is %ld seconds.",
1343  entry_guard_describe(guard),
1345  tor_lround(pb->use_attempts),
1351  tor_lround(pb->timeouts),
1353  pb->path_bias_disabled = 1;
1354  return;
1355  }
1356  } else if (!pb->path_bias_use_extreme) {
1357  pb->path_bias_use_extreme = 1;
1358  log_warn(LD_CIRC,
1359  "Guard %s is failing to carry an extremely large "
1360  "amount of streams on its circuits. "
1361  "This could indicate a route manipulation attack, network "
1362  "overload, bad local network connectivity, or a bug. "
1363  "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1364  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1365  "and %ld timed out. "
1366  "For reference, your timeout cutoff is %ld seconds.",
1367  entry_guard_describe(guard),
1369  tor_lround(pb->use_attempts),
1375  tor_lround(pb->timeouts),
1377  }
1378  } else if (pathbias_get_use_success_count(guard)/pb->use_attempts
1379  < pathbias_get_notice_use_rate(options)) {
1380  if (!pb->path_bias_use_noticed) {
1381  pb->path_bias_use_noticed = 1;
1382  log_notice(LD_CIRC,
1383  "Guard %s is failing to carry more streams on its "
1384  "circuits than usual. "
1385  "Most likely this means the Tor network is overloaded "
1386  "or your network connection is poor. "
1387  "Use counts are %ld/%ld. Success counts are %ld/%ld. "
1388  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1389  "and %ld timed out. "
1390  "For reference, your timeout cutoff is %ld seconds.",
1391  entry_guard_describe(guard),
1393  tor_lround(pb->use_attempts),
1399  tor_lround(pb->timeouts),
1401  }
1402  }
1403  }
1404 }
1405 
1424 static void
1425 pathbias_measure_close_rate(entry_guard_t *guard)
1426 {
1427  const or_options_t *options = get_options();
1429 
1430  if (pb->circ_attempts > pathbias_get_min_circs(options)) {
1431  /* Note: We rely on the < comparison here to allow us to set a 0
1432  * rate and disable the feature entirely. If refactoring, don't
1433  * change to <= */
1435  < pathbias_get_extreme_rate(options)) {
1436  /* Dropping is currently disabled by default. */
1437  if (pathbias_get_dropguards(options)) {
1438  if (!pb->path_bias_disabled) {
1439  log_warn(LD_CIRC,
1440  "Guard %s is failing an extremely large "
1441  "amount of circuits. "
1442  "To avoid potential route manipulation attacks, Tor has "
1443  "disabled use of this guard. "
1444  "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1445  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1446  "and %ld timed out. "
1447  "For reference, your timeout cutoff is %ld seconds.",
1448  entry_guard_describe(guard),
1452  tor_lround(pb->use_attempts),
1456  tor_lround(pb->timeouts),
1458  pb->path_bias_disabled = 1;
1459  return;
1460  }
1461  } else if (!pb->path_bias_extreme) {
1462  pb->path_bias_extreme = 1;
1463  log_warn(LD_CIRC,
1464  "Guard %s is failing an extremely large "
1465  "amount of circuits. "
1466  "This could indicate a route manipulation attack, "
1467  "extreme network overload, or a bug. "
1468  "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1469  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1470  "and %ld timed out. "
1471  "For reference, your timeout cutoff is %ld seconds.",
1472  entry_guard_describe(guard),
1476  tor_lround(pb->use_attempts),
1480  tor_lround(pb->timeouts),
1482  }
1483  } else if (pathbias_get_close_success_count(guard)/pb->circ_attempts
1484  < pathbias_get_warn_rate(options)) {
1485  if (!pb->path_bias_warned) {
1486  pb->path_bias_warned = 1;
1487  log_warn(LD_CIRC,
1488  "Guard %s is failing a very large "
1489  "amount of circuits. "
1490  "Most likely this means the Tor network is "
1491  "overloaded, but it could also mean an attack against "
1492  "you or potentially the guard itself. "
1493  "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1494  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1495  "and %ld timed out. "
1496  "For reference, your timeout cutoff is %ld seconds.",
1497  entry_guard_describe(guard),
1501  tor_lround(pb->use_attempts),
1505  tor_lround(pb->timeouts),
1507  }
1508  } else if (pathbias_get_close_success_count(guard)/pb->circ_attempts
1509  < pathbias_get_notice_rate(options)) {
1510  if (!pb->path_bias_noticed) {
1511  pb->path_bias_noticed = 1;
1512  log_notice(LD_CIRC,
1513  "Guard %s is failing more circuits than "
1514  "usual. "
1515  "Most likely this means the Tor network is overloaded. "
1516  "Success counts are %ld/%ld. Use counts are %ld/%ld. "
1517  "%ld circuits completed, %ld were unusable, %ld collapsed, "
1518  "and %ld timed out. "
1519  "For reference, your timeout cutoff is %ld seconds.",
1520  entry_guard_describe(guard),
1524  tor_lround(pb->use_attempts),
1528  tor_lround(pb->timeouts),
1530  }
1531  }
1532  }
1533 }
1534 
1544 static void
1545 pathbias_scale_close_rates(entry_guard_t *guard)
1546 {
1547  const or_options_t *options = get_options();
1549 
1550  /* If we get a ton of circuits, just scale everything down */
1551  if (pb->circ_attempts > pathbias_get_scale_threshold(options)) {
1552  double scale_ratio = pathbias_get_scale_ratio(options);
1553  int opened_attempts = pathbias_count_circs_in_states(guard,
1554  PATH_STATE_BUILD_ATTEMPTED, PATH_STATE_BUILD_ATTEMPTED);
1555  int opened_built = pathbias_count_circs_in_states(guard,
1556  PATH_STATE_BUILD_SUCCEEDED,
1557  PATH_STATE_USE_FAILED);
1558  /* Verify that the counts are sane before and after scaling */
1559  int counts_are_sane = (pb->circ_attempts >= pb->circ_successes);
1560 
1561  pb->circ_attempts -= (opened_attempts+opened_built);
1562  pb->circ_successes -= opened_built;
1563 
1564  pb->circ_attempts *= scale_ratio;
1565  pb->circ_successes *= scale_ratio;
1566  pb->timeouts *= scale_ratio;
1567  pb->successful_circuits_closed *= scale_ratio;
1568  pb->collapsed_circuits *= scale_ratio;
1569  pb->unusable_circuits *= scale_ratio;
1570 
1571  pb->circ_attempts += (opened_attempts+opened_built);
1572  pb->circ_successes += opened_built;
1573 
1575 
1576  log_info(LD_CIRC,
1577  "Scaled pathbias counts to (%f,%f)/%f (%d/%d open) for guard "
1578  "%s",
1580  pb->circ_attempts, opened_built, opened_attempts,
1581  entry_guard_describe(guard));
1582 
1583  /* Have the counts just become invalid by this scaling attempt? */
1584  if (counts_are_sane && pb->circ_attempts < pb->circ_successes) {
1585  log_notice(LD_BUG,
1586  "Scaling has mangled pathbias counts to %f/%f (%d/%d open) "
1587  "for guard %s",
1588  pb->circ_successes, pb->circ_attempts, opened_built,
1589  opened_attempts,
1590  entry_guard_describe(guard));
1591  }
1592  }
1593 }
1594 
1604 void
1605 pathbias_scale_use_rates(entry_guard_t *guard)
1606 {
1607  const or_options_t *options = get_options();
1609 
1610  /* If we get a ton of circuits, just scale everything down */
1611  if (pb->use_attempts > pathbias_get_scale_use_threshold(options)) {
1612  double scale_ratio = pathbias_get_scale_ratio(options);
1613  int opened_attempts = pathbias_count_circs_in_states(guard,
1614  PATH_STATE_USE_ATTEMPTED, PATH_STATE_USE_SUCCEEDED);
1615  /* Verify that the counts are sane before and after scaling */
1616  int counts_are_sane = (pb->use_attempts >= pb->use_successes);
1617 
1618  pb->use_attempts -= opened_attempts;
1619 
1620  pb->use_attempts *= scale_ratio;
1621  pb->use_successes *= scale_ratio;
1622 
1623  pb->use_attempts += opened_attempts;
1624 
1625  log_info(LD_CIRC,
1626  "Scaled pathbias use counts to %f/%f (%d open) for guard %s",
1627  pb->use_successes, pb->use_attempts, opened_attempts,
1628  entry_guard_describe(guard));
1629 
1630  /* Have the counts just become invalid by this scaling attempt? */
1631  if (counts_are_sane && pb->use_attempts < pb->use_successes) {
1632  log_notice(LD_BUG,
1633  "Scaling has mangled pathbias usage counts to %f/%f "
1634  "(%d open) for guard %s",
1635  pb->circ_successes, pb->circ_attempts,
1636  opened_attempts, entry_guard_describe(guard));
1637  }
1638 
1640  }
1641 }
#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)
enum channel_s::@8 reason_for_closing
#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:506
static int pathbias_is_new_circ_attempt(origin_circuit_t *circ)
Definition: circpathbias.c:294
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:58
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:706
Definition: cell_st.h:12
static void pathbias_scale_close_rates(entry_guard_t *guard)
#define CIRCUIT_IS_ORIGIN(c)
Definition: circuitlist.h:143
const char * circuit_purpose_to_string(uint8_t purpose)
Definition: circuitlist.c:896
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:489
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:221
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:248
static void pathbias_scale_use_rates(entry_guard_t *guard)
uint8_t purpose
Definition: circuit_st.h:102
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:214
#define CIRCUIT_PURPOSE_CONTROLLER
Definition: circuitlist.h:117
double pathbias_get_extreme_use_rate(const or_options_t *options)
Definition: circpathbias.c:230
void entry_guards_changed(void)
Definition: entrynodes.c:3423
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:152
#define LD_CIRC
Definition: log.h:78
uint8_t state
Definition: circuit_st.h:101
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:115
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:691
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:870
#define CIRCUIT_PURPOSE_S_CONNECT_REND
Definition: circuitlist.h:106
Header file for circuitlist.c.
#define CIRCUIT_PURPOSE_PATH_BIAS_TESTING
Definition: circuitlist.h:119
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:61
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:767
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:321
const char * circuit_state_to_string(int state)
Definition: circuitlist.c:758
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
uint8_t state
Definition: crypt_path_st.h:54
struct timeval timestamp_began
Definition: circuit_st.h:130
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:96
time_t approx_time(void)
Definition: approx_time.c:32
const char * pathbias_state_to_string(path_state_t state)
Definition: circpathbias.c:263
void pathbias_count_use_attempt(origin_circuit_t *circ)
Definition: circpathbias.c:596
extend_info_t * extend_info
Definition: crypt_path_st.h:47
void circuit_change_purpose(circuit_t *circ, uint8_t new_purpose)
Definition: circuituse.c:3048
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:420
void circuit_read_valid_data(origin_circuit_t *circ, uint16_t relay_body_len)
Definition: circuituse.c:3129
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:930
#define CIRCUIT_PURPOSE_S_REND_JOINED
Definition: circuitlist.h:109
#define LD_PROTOCOL
Definition: log.h:68
static int pathbias_get_min_use(const or_options_t *options)
Definition: circpathbias.c:201
#define RELAY_HEADER_SIZE
Definition: or.h:603
void pathbias_mark_use_success(origin_circuit_t *circ)
Definition: circpathbias.c:652
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:82
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:1879