[tor-commits] [tor/master] Appease make check-spaces

2016-09-05 Thread andrea
commit 341a159ab4ec9cb0a07a6f3507c4eb5aaf83798a
Author: Andrea Shepard <and...@torproject.org>
Date:   Mon Sep 5 17:47:39 2016 +

Appease make check-spaces
---
 src/or/circuitbuild.c   | 1 +
 src/or/rendservice.c| 1 +
 src/test/log_test_helpers.c | 2 +-
 src/test/test_util.c| 1 -
 4 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index aa2b0b2..12c7553 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -2547,3 +2547,4 @@ extend_info_has_preferred_onion_key(const extend_info_t* 
ei)
   tor_assert(ei);
   return extend_info_supports_ntor(ei);
 }
+
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 4ad3505..12af748 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -3904,3 +3904,4 @@ rend_service_allow_direct_connection(const or_options_t 
*options)
   (void)options;
   return 0;
 }
+
diff --git a/src/test/log_test_helpers.c b/src/test/log_test_helpers.c
index 2c99da8..1ad008a 100644
--- a/src/test/log_test_helpers.c
+++ b/src/test/log_test_helpers.c
@@ -145,7 +145,6 @@ mock_saved_log_has_message_containing(const char *msg)
   return 0;
 }
 
-
 /** Return true iff the saved logs have any messages with severity */
 int
 mock_saved_log_has_severity(int severity)
@@ -210,3 +209,4 @@ mock_saving_logv(int severity, log_domain_mask_t domain,
 
   smartlist_add(saved_logs, e);
 }
+
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 445abb9..6839db9 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -2216,7 +2216,6 @@ test_util_gzip_compression_bomb(void *arg)
   size_t result_len = 0;
   tor_zlib_state_t *state = NULL;
 
-
   /* Make sure we can't produce a compression bomb */
   const int prev_level = setup_full_capture_of_logs(LOG_WARN);
   tt_int_op(-1, OP_EQ, tor_gzip_compress(, _len,

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Keep make check-spaces happy

2016-07-28 Thread andrea
commit 1995328a3d0c98f5a8856f532b20099970afecc2
Author: Andrea Shepard <and...@torproject.org>
Date:   Fri Jul 29 05:05:12 2016 +

Keep make check-spaces happy
---
 src/common/compat.c  | 1 -
 src/common/compat_time.c | 1 +
 src/common/timers.h  | 3 ++-
 src/common/util.h| 1 -
 src/or/control.c | 3 ++-
 5 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/common/compat.c b/src/common/compat.c
index e0807e4..b2ed119 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -2824,7 +2824,6 @@ compute_num_cpus(void)
   return num_cpus;
 }
 
-
 #if !defined(_WIN32)
 /** Defined iff we need to add locks when defining fake versions of reentrant
  * versions of time-related functions. */
diff --git a/src/common/compat_time.c b/src/common/compat_time.c
index 7676e3a..3493ea0 100644
--- a/src/common/compat_time.c
+++ b/src/common/compat_time.c
@@ -626,3 +626,4 @@ monotime_coarse_absolute_msec(void)
   return monotime_coarse_absolute_nsec() / ONE_MILLION;
 }
 #endif
+
diff --git a/src/common/timers.h b/src/common/timers.h
index 2c36af1..5f918f8 100644
--- a/src/common/timers.h
+++ b/src/common/timers.h
@@ -9,7 +9,8 @@
 
 struct monotime_t;
 typedef struct timeout tor_timer_t;
-typedef void (*timer_cb_fn_t)(tor_timer_t *, void *, const struct monotime_t 
*);
+typedef void (*timer_cb_fn_t)(tor_timer_t *, void *,
+  const struct monotime_t *);
 tor_timer_t *timer_new(timer_cb_fn_t cb, void *arg);
 void timer_set_cb(tor_timer_t *t, timer_cb_fn_t cb, void *arg);
 void timer_schedule(tor_timer_t *t, const struct timeval *delay);
diff --git a/src/common/util.h b/src/common/util.h
index 9face0c..7a6203a 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -154,7 +154,6 @@ int n_bits_set_u8(uint8_t v);
 int64_t clamp_double_to_int64(double number);
 void simplify_fraction64(uint64_t *numer, uint64_t *denom);
 
-
 /* Compute the CEIL of a divided by b, for nonnegative a
  * and positive b.  Works on integer types only. Not defined if a+b can
  * overflow. */
diff --git a/src/or/control.c b/src/or/control.c
index ec76ecf..64a980d 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -1865,7 +1865,8 @@ getinfo_helper_dir(control_connection_t *control_conn,
 const routerinfo_t *ri = NULL;
 /* XXX Setting 'warn_if_unnamed' here is a bit silly -- the
  * warning goes to the user, not to the controller. */
-const node_t *node = node_get_by_nickname(question+strlen("desc/name/"), 
1);
+const node_t *node =
+  node_get_by_nickname(question+strlen("desc/name/"), 1);
 if (node)
   ri = node->ri;
 if (ri) {

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Keep make check-spaces happy

2016-07-17 Thread andrea
commit 94c27d4e8fede72b128e0bbdd8b60d77ed23ebe6
Author: Andrea Shepard <and...@torproject.org>
Date:   Sun Jul 17 23:22:29 2016 +

Keep make check-spaces happy
---
 src/or/policies.c   | 10 +-
 src/test/test_address.c |  3 ++-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/or/policies.c b/src/or/policies.c
index f625242..0b8f335 100644
--- a/src/or/policies.c
+++ b/src/or/policies.c
@@ -2866,11 +2866,11 @@ getinfo_helper_policies(control_connection_t *conn,
 }
 
 policies_parse_exit_policy_reject_private(
-  _policy_list,
-  options->IPv6Exit,
-  configured_addresses,
-  options->ExitPolicyRejectLocalInterfaces,
-  
options->ExitPolicyRejectLocalInterfaces);
+  _policy_list,
+  options->IPv6Exit,
+  configured_addresses,
+  options->ExitPolicyRejectLocalInterfaces,
+  options->ExitPolicyRejectLocalInterfaces);
 *answer = policy_dump_to_string(private_policy_list, 1, 1);
 
 addr_policy_list_free(private_policy_list);
diff --git a/src/test/test_address.c b/src/test/test_address.c
index d621ee5..82d6bc7 100644
--- a/src/test/test_address.c
+++ b/src/test/test_address.c
@@ -823,7 +823,8 @@ test_address_get_if_addrs6_list_no_internal(void *arg)
 
   (void)arg;
 
-  int prev_level = setup_capture_of_logs(LOG_ERR); /* We might drop a log_err 
*/
+  /* We might drop a log_err */
+  int prev_level = setup_capture_of_logs(LOG_ERR);
   results = get_interface_address6_list(LOG_ERR, AF_INET6, 0);
   tt_int_op(smartlist_len(mock_saved_logs()), OP_LE, 1);
   teardown_capture_of_logs(prev_level);

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Keep make check-spaces happy

2016-07-01 Thread andrea
commit be78e9ff3782639b9fa72dcfa9bda559cfc83f17
Author: Andrea Shepard <and...@torproject.org>
Date:   Fri Jul 1 21:52:32 2016 +

Keep make check-spaces happy
---
 src/or/dirvote.c  | 3 ++-
 src/or/shared_random.c| 8 +---
 src/or/shared_random.h| 1 +
 src/or/shared_random_state.c  | 1 +
 src/or/shared_random_state.h  | 1 +
 src/test/test_dir.c   | 6 --
 src/test/test_shared_random.c | 1 +
 7 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/or/dirvote.c b/src/or/dirvote.c
index 4399bad..c31894a 100644
--- a/src/or/dirvote.c
+++ b/src/or/dirvote.c
@@ -2648,7 +2648,8 @@ get_voting_schedule(const or_options_t *options, time_t 
now, int severity)
 
   new_voting_schedule->fetch_missing_signatures = start - (dist_delay/2);
   new_voting_schedule->voting_ends = start - dist_delay;
-  new_voting_schedule->fetch_missing_votes = start - dist_delay - 
(vote_delay/2);
+  new_voting_schedule->fetch_missing_votes =
+start - dist_delay - (vote_delay/2);
   new_voting_schedule->voting_starts = start - dist_delay - vote_delay;
 
   {
diff --git a/src/or/shared_random.c b/src/or/shared_random.c
index a7a2238..e9e6cbc 100644
--- a/src/or/shared_random.c
+++ b/src/or/shared_random.c
@@ -327,7 +327,6 @@ reveal_decode(const char *encoded, sr_commit_t *commit)
   return -1;
 }
 
-
 /* Encode a reveal element using a given commit object to dst which is a
  * buffer large enough to put the base64-encoded reveal construction. The
  * format is as follow:
@@ -629,7 +628,8 @@ should_keep_commit(const sr_commit_t *commit, const char 
*voter_key,
   lasts multiple rounds. However if the commitment value changes
   during commit phase, it might be a bug so log more loudly. */
   if (!commitments_are_the_same(commit, saved_commit)) {
-log_info(LD_DIR, "SR: Received altered commit from %s in commit 
phase.",
+log_info(LD_DIR,
+ "SR: Received altered commit from %s in commit phase.",
  sr_commit_get_rsa_fpr(commit));
   } else {
 log_debug(LD_DIR, "SR: Ignoring known commit during commit phase.");
@@ -1348,9 +1348,11 @@ sr_save_and_cleanup(void)
 /* Set the global value of number of SRV agreements so the test can play
  * along by calling specific functions that don't parse the votes prior for
  * the AuthDirNumSRVAgreements value. */
-void set_num_srv_agreements(int32_t value)
+void
+set_num_srv_agreements(int32_t value)
 {
   num_srv_agreements_from_vote = value;
 }
 
 #endif /* TOR_UNIT_TESTS */
+
diff --git a/src/or/shared_random.h b/src/or/shared_random.h
index 3922f33..51f3b55 100644
--- a/src/or/shared_random.h
+++ b/src/or/shared_random.h
@@ -164,3 +164,4 @@ void set_num_srv_agreements(int32_t value);
 #endif /* TOR_UNIT_TESTS */
 
 #endif /* TOR_SHARED_RANDOM_H */
+
diff --git a/src/or/shared_random_state.c b/src/or/shared_random_state.c
index d0cd460..73df9c4 100644
--- a/src/or/shared_random_state.c
+++ b/src/or/shared_random_state.c
@@ -1351,3 +1351,4 @@ get_sr_state(void)
 }
 
 #endif /* TOR_UNIT_TESTS */
+
diff --git a/src/or/shared_random_state.h b/src/or/shared_random_state.h
index e0b6e46..43a7f1d 100644
--- a/src/or/shared_random_state.h
+++ b/src/or/shared_random_state.h
@@ -144,3 +144,4 @@ STATIC sr_state_t *get_sr_state(void);
 #endif /* TOR_UNIT_TESTS */
 
 #endif /* TOR_SHARED_RANDOM_STATE_H */
+
diff --git a/src/test/test_dir.c b/src/test/test_dir.c
index 200cddd..8889ccc 100644
--- a/src/test/test_dir.c
+++ b/src/test/test_dir.c
@@ -1438,7 +1438,8 @@ test_dir_measured_bw_kb_cache(void *arg)
 }
 
 static char *
-my_dirvote_compute_params(smartlist_t *votes, int method, int 
total_authorities)
+my_dirvote_compute_params(smartlist_t *votes, int method,
+  int total_authorities)
 {
   smartlist_t *s = dirvote_compute_params(votes, method, total_authorities);
   tor_assert(s);
@@ -1573,7 +1574,8 @@ test_dir_param_voting_lookup(void *arg)
   tt_int_op(1000,
 OP_EQ, dirvote_get_intermediate_param_value(lst, "ab", 1000));
   tt_int_op(9, OP_EQ, dirvote_get_intermediate_param_value(lst, "abc", 1000));
-  tt_int_op(99, OP_EQ, dirvote_get_intermediate_param_value(lst, "abcd", 
1000));
+  tt_int_op(99, OP_EQ,
+dirvote_get_intermediate_param_value(lst, "abcd", 1000));
 
   /* moomin appears twice. */
   tt_int_op(-100, OP_EQ,
diff --git a/src/test/test_shared_random.c b/src/test/test_shared_random.c
index 95f8198..d001785 100644
--- a/src/test/test_shared_random.c
+++ b/src/test/test_shared_random.c
@@ -1263,3 +1263,4 @@ struct testcase_t sr_tests[] = {
 NULL, NULL },
   END_OF_TESTCASES
 };
+

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Keep make check-spaces happy

2016-06-18 Thread andrea
commit 033cf30b3cb505027c7542bb9b49717065a19fdf
Author: Andrea Shepard <and...@torproject.org>
Date:   Sat Jun 18 16:07:44 2016 +

Keep make check-spaces happy
---
 src/common/util_format.c| 1 -
 src/test/test_util_format.c | 3 +--
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/src/common/util_format.c b/src/common/util_format.c
index f343a9d..e40fe30 100644
--- a/src/common/util_format.c
+++ b/src/common/util_format.c
@@ -21,7 +21,6 @@
 #include 
 #include 
 
-
 /* Return the base32 encoded size in bytes using the source length srclen.
  * The NUL terminated byte is added as well since every base32 encoding
  * requires enough space for it. */
diff --git a/src/test/test_util_format.c b/src/test/test_util_format.c
index c27b3a5..c441037 100644
--- a/src/test/test_util_format.c
+++ b/src/test/test_util_format.c
@@ -318,7 +318,6 @@ test_util_format_base32_encode(void *arg)
 tt_mem_op(expected, OP_EQ, dst, strlen(expected));
   }
 
-
   /* Non multiple of 5 for the source buffer length. */
   {
 /* Length of 8 bytes. */
@@ -375,7 +374,7 @@ test_util_format_base32_decode(void *arg)
 tt_int_op(tor_mem_is_zero(dst, real_dstlen), ==, 1);
   }
 
-done:
+ done:
   tor_free(dst);
 }
 

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Keep make check-spaces happy

2016-06-12 Thread andrea
commit 925f76b486444217035d1cc978cbdd398c17dfb1
Author: Andrea Shepard <and...@torproject.org>
Date:   Sun Jun 12 21:47:14 2016 +

Keep make check-spaces happy
---
 src/common/address.h | 6 --
 src/or/onion.c   | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/common/address.h b/src/common/address.h
index 3f0bb52..51db42c 100644
--- a/src/common/address.h
+++ b/src/common/address.h
@@ -74,7 +74,8 @@ typedef struct tor_addr_port_t
 #define TOR_ADDR_NULL {AF_UNSPEC, {0}}
 
 static inline const struct in6_addr *tor_addr_to_in6(const tor_addr_t *a);
-static inline const struct in6_addr *tor_addr_to_in6_assert(const tor_addr_t 
*a);
+static inline const struct in6_addr *tor_addr_to_in6_assert(
+const tor_addr_t *a);
 static inline uint32_t tor_addr_to_ipv4n(const tor_addr_t *a);
 static inline uint32_t tor_addr_to_ipv4h(const tor_addr_t *a);
 static inline uint32_t tor_addr_to_mapped_ipv4h(const tor_addr_t *a);
@@ -98,7 +99,8 @@ tor_addr_to_in6(const tor_addr_t *a)
   return a->family == AF_INET6 ? >addr.in6_addr : NULL;
 }
 
-/** As tor_addr_to_in6, but assert that the address truly is an IPv6 address. 
*/
+/** As tor_addr_to_in6, but assert that the address truly is an IPv6
+ * address. */
 static inline const struct in6_addr *
 tor_addr_to_in6_assert(const tor_addr_t *a)
 {
diff --git a/src/or/onion.c b/src/or/onion.c
index 28b9787..7c7f97f 100644
--- a/src/or/onion.c
+++ b/src/or/onion.c
@@ -39,8 +39,8 @@ typedef struct onion_queue_t {
 /** Array of queues of circuits waiting for CPU workers. An element is NULL
  * if that queue is empty.*/
 static TOR_TAILQ_HEAD(onion_queue_head_t, onion_queue_t)
-  ol_list[MAX_ONION_HANDSHAKE_TYPE+1] = {
-  TOR_TAILQ_HEAD_INITIALIZER(ol_list[0]), /* tap */
+  ol_list[MAX_ONION_HANDSHAKE_TYPE+1] =
+{ TOR_TAILQ_HEAD_INITIALIZER(ol_list[0]), /* tap */
   TOR_TAILQ_HEAD_INITIALIZER(ol_list[1]), /* fast */
   TOR_TAILQ_HEAD_INITIALIZER(ol_list[2]), /* ntor */
 };

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Reduce make check-spaces noise

2016-06-09 Thread andrea
commit 9eeaeddbb1aa04248841890e244c4714f165522d
Author: Andrea Shepard <and...@torproject.org>
Date:   Thu Jun 9 11:50:25 2016 +

Reduce make check-spaces noise
---
 src/common/di_ops.c  |  1 +
 src/common/di_ops.h  |  3 ++-
 src/common/pubsub.h  |  4 +++-
 src/common/util_bug.h|  4 ++--
 src/or/connection_edge.c |  3 ++-
 src/or/rendcommon.c  |  1 -
 src/or/routerlist.h  |  3 ++-
 src/test/test-timers.c   |  5 +++--
 src/test/test_crypto.c   | 10 ++
 9 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/common/di_ops.c b/src/common/di_ops.c
index e671af6..4ed49e1 100644
--- a/src/common/di_ops.c
+++ b/src/common/di_ops.c
@@ -271,3 +271,4 @@ select_array_member_cumulative_timei(const uint64_t 
*entries, int n_entries,
 
   return i_chosen;
 }
+
diff --git a/src/common/di_ops.h b/src/common/di_ops.h
index f1050a0..0a15430 100644
--- a/src/common/di_ops.h
+++ b/src/common/di_ops.h
@@ -42,7 +42,8 @@ void dimap_add_entry(di_digest256_map_t **map,
  const uint8_t *key, void *val);
 void *dimap_search(const di_digest256_map_t *map, const uint8_t *key,
void *dflt_val);
-int select_array_member_cumulative_timei(const uint64_t *entries, int 
n_entries,
+int select_array_member_cumulative_timei(const uint64_t *entries,
+ int n_entries,
  uint64_t total, uint64_t rand_val);
 
 #endif
diff --git a/src/common/pubsub.h b/src/common/pubsub.h
index 09e492e..bbb4f02 100644
--- a/src/common/pubsub.h
+++ b/src/common/pubsub.h
@@ -21,7 +21,9 @@
  *   unsigned priority);
  * int T_unsubscribe(const T_subscriber_t *)
  *
- * Elsewhere you can say DECLARE_NOTIFY_PUBSUB_TOPIC(static, T), which 
declares:
+ * Elsewhere you can say DECLARE_NOTIFY_PUBSUB_TOPIC(static, T), which
+ * declares:
+ *
  *static int T_notify(T_event_data_t *, unsigned notify_flags);
  *static void T_clear(void);
  *
diff --git a/src/common/util_bug.h b/src/common/util_bug.h
index 36056aa..3f77e0a 100644
--- a/src/common/util_bug.h
+++ b/src/common/util_bug.h
@@ -104,14 +104,14 @@
 
 #ifdef __GNUC__
 #define IF_BUG_ONCE__(cond,var) \
-  if (({\
+  if (( {\
   static int var = 0;   \
   int bool_result = (cond); \
   if (PREDICT_UNLIKELY(bool_result) && !var) {  \
 var = 1;\
 tor_bug_occurred_(SHORT_FILE__, __LINE__, __func__, #cond, 1);  \
   } \
-  PREDICT_UNLIKELY(bool_result); }))
+  PREDICT_UNLIKELY(bool_result); } ))
 #else
 #define IF_BUG_ONCE__(cond,var) \
   static int var = 0;   \
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index c9aced7..799baa2 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -1703,7 +1703,8 @@ 
connection_ap_handshake_rewrite_and_attach(entry_connection_t *conn,
 /* Fill in the rend_data field so we can start doing a connection to
  * a hidden service. */
 rend_data_t *rend_data = ENTRY_TO_EDGE_CONN(conn)->rend_data =
-  rend_data_client_create(socks->address, NULL, (char *) cookie, 
auth_type);
+  rend_data_client_create(socks->address, NULL, (char *) cookie,
+  auth_type);
 if (rend_data == NULL) {
   return -1;
 }
diff --git a/src/or/rendcommon.c b/src/or/rendcommon.c
index 56c49fe..01b0766 100644
--- a/src/or/rendcommon.c
+++ b/src/or/rendcommon.c
@@ -1067,4 +1067,3 @@ rend_auth_decode_cookie(const char *cookie_in, uint8_t 
*cookie_out,
   return res;
 }
 
-
diff --git a/src/or/routerlist.h b/src/or/routerlist.h
index d5a9b77..be242d6 100644
--- a/src/or/routerlist.h
+++ b/src/or/routerlist.h
@@ -221,7 +221,8 @@ int hex_digest_nickname_matches(const char *hexdigest,
 STATIC int choose_array_element_by_weight(const uint64_t *entries,
   int n_entries);
 STATIC void scale_array_elements_to_u64(uint64_t *entries_out,
-const double *entries_in, int 
n_entries,
+const double *entries_in,
+int n_entries,
 uint64_t *total_out);
 STATIC const routerstatus_t *router_pick_directory_server_impl(
dirinfo_type_t auth, int flags,
diff --git a/src/test/test-timers.c b/src/test/test-timers.c
index 8f5ba7b..0196ec1 100644
--- a/src/test/test-timer

[tor-commits] [tor/maint-0.2.7] Do not link tests against both libor.a and libor-testing.a

2016-04-11 Thread andrea
commit 1a065cea46a9c179d64d74d012f051135bc4725a
Author: Nick Mathewson 
Date:   Fri Mar 11 09:53:25 2016 -0500

Do not link tests against both libor.a and libor-testing.a

Also, put libor-testing.a at a better position in the list of
libraries, to avoid linker errors.

This is a fix, or part of a fix, for 18490.

Conflicts:
src/test/include.am
---
 changes/build18490  | 4 
 src/test/include.am | 9 ++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/changes/build18490 b/changes/build18490
new file mode 100644
index 000..466a133
--- /dev/null
+++ b/changes/build18490
@@ -0,0 +1,4 @@
+  o Minor bugfixes (build):
+- Do not link the unit tests against both the testing and non-testing
+  versions of the static libraries. Fixes bug 18490; bugfix on
+  0.2.7.1-alpha.
diff --git a/src/test/include.am b/src/test/include.am
index 7a02a4e..9e0d552 100644
--- a/src/test/include.am
+++ b/src/test/include.am
@@ -128,9 +128,12 @@ src_test_test_workqueue_CFLAGS = $(AM_CFLAGS) 
$(TEST_CFLAGS)
 
 src_test_test_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ \
 @TOR_LDFLAGS_libevent@
-src_test_test_LDADD = src/or/libtor-testing.a src/common/libor-testing.a \
-   src/common/libor-crypto-testing.a $(LIBDONNA) src/common/libor.a \
-   src/common/libor-event-testing.a src/trunnel/libor-trunnel-testing.a \
+src_test_test_LDADD = src/or/libtor-testing.a \
+   src/common/libor-crypto-testing.a \
+   $(LIBDONNA) \
+   src/common/libor-testing.a \
+   src/common/libor-event-testing.a \
+   src/trunnel/libor-trunnel-testing.a \
@TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ @TOR_LIBEVENT_LIBS@ \
@TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@ \
@TOR_SYSTEMD_LIBS@

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.7] Merge branch 'bug15221_027' into maint-0.2.7

2016-03-30 Thread andrea
commit 183d465f0e497cbc5f49c08119dfdf00eb7f8cdd
Merge: 0b45cab 725e0c7
Author: Andrea Shepard <and...@torproject.org>
Date:   Wed Mar 30 12:23:42 2016 +

Merge branch 'bug15221_027' into maint-0.2.7

 changes/bug15221 | 4 
 src/common/sandbox.c | 9 +
 2 files changed, 13 insertions(+)

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.7] Permit setrlimit, prlimit, prlimit64 calls.

2016-03-30 Thread andrea
commit 725e0c76e3df9d3ea4b861b3ff5279b23def4ef9
Author: Nick Mathewson 
Date:   Mon Mar 14 13:21:16 2016 -0400

Permit setrlimit, prlimit, prlimit64 calls.

We call setrlimit under some circumstances, and it can call prlimit
and prlimit64 under the hood.

Fixes bug 15221.
---
 changes/bug15221 | 4 
 src/common/sandbox.c | 9 +
 2 files changed, 13 insertions(+)

diff --git a/changes/bug15221 b/changes/bug15221
new file mode 100644
index 000..ed72309
--- /dev/null
+++ b/changes/bug15221
@@ -0,0 +1,4 @@
+  o Minor bugfixes (sandbox):
+- Allow the setrlimit syscall, and the prlimit and prlimit64 syscalls,
+  which some libc implementations
+  use under the hood.  Fixes bug 15221.  Bugfix on 0.2.5.1-alpha.
diff --git a/src/common/sandbox.c b/src/common/sandbox.c
index 950a92f..bcbb3ce 100644
--- a/src/common/sandbox.c
+++ b/src/common/sandbox.c
@@ -177,11 +177,20 @@ static int filter_nopar_gen[] = {
 SCMP_SYS(mmap),
 #endif
 SCMP_SYS(munmap),
+#ifdef __NR_prlimit
+SCMP_SYS(prlimit),
+#endif
+#ifdef __NR_prlimit64
+SCMP_SYS(prlimit64),
+#endif
 SCMP_SYS(read),
 SCMP_SYS(rt_sigreturn),
 SCMP_SYS(sched_getaffinity),
 SCMP_SYS(sendmsg),
 SCMP_SYS(set_robust_list),
+#ifdef __NR_setrlimit
+SCMP_SYS(setrlimit),
+#endif
 #ifdef __NR_sigreturn
 SCMP_SYS(sigreturn),
 #endif



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.7] Make sure channel_t queues its own copy of incoming cells

2016-03-29 Thread andrea
commit bd87d37a861c541afbeb660b4d8dd62df14d5b45
Author: Andrea Shepard <and...@torproject.org>
Date:   Tue Mar 15 07:40:19 2016 +

Make sure channel_t queues its own copy of incoming cells
---
 src/or/channel.c   | 38 ++
 src/or/channeltls.c| 11 +++
 src/or/connection_or.c | 35 +++
 src/or/connection_or.h |  1 +
 4 files changed, 81 insertions(+), 4 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index 21522a5..62a21be 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -2652,6 +2652,11 @@ channel_process_cells(channel_t *chan)
   /*
* Process cells until we're done or find one we have no current handler
* for.
+   *
+   * We must free the cells here after calling the handler, since custody
+   * of the buffer was given to the channel layer when they were queued;
+   * see comments on memory management in channel_queue_cell() and in
+   * channel_queue_var_cell() below.
*/
   while (NULL != (q = TOR_SIMPLEQ_FIRST(>incoming_queue))) {
 tor_assert(q);
@@ -2669,6 +2674,7 @@ channel_process_cells(channel_t *chan)
 q->u.fixed.cell, chan,
 U64_PRINTF_ARG(chan->global_identifier));
   chan->cell_handler(chan, q->u.fixed.cell);
+  tor_free(q->u.fixed.cell);
   tor_free(q);
 } else if (q->type == CELL_QUEUE_VAR &&
chan->var_cell_handler) {
@@ -2681,6 +2687,7 @@ channel_process_cells(channel_t *chan)
 q->u.var.var_cell, chan,
 U64_PRINTF_ARG(chan->global_identifier));
   chan->var_cell_handler(chan, q->u.var.var_cell);
+  tor_free(q->u.var.var_cell);
   tor_free(q);
 } else {
   /* Can't handle this one */
@@ -2701,6 +2708,7 @@ channel_queue_cell(channel_t *chan, cell_t *cell)
 {
   int need_to_queue = 0;
   cell_queue_entry_t *q;
+  cell_t *cell_copy = NULL;
 
   tor_assert(chan);
   tor_assert(cell);
@@ -2728,8 +2736,19 @@ channel_queue_cell(channel_t *chan, cell_t *cell)
   U64_PRINTF_ARG(chan->global_identifier));
 chan->cell_handler(chan, cell);
   } else {
-/* Otherwise queue it and then process the queue if possible. */
-q = cell_queue_entry_new_fixed(cell);
+/*
+ * Otherwise queue it and then process the queue if possible.
+ *
+ * We queue a copy, not the original pointer - it might have been on the
+ * stack in connection_or_process_cells_from_inbuf() (or another caller
+ * if we ever have a subclass other than channel_tls_t), or be freed
+ * there after we return.  This is the uncommon case; the non-copying
+ * fast path occurs in the if (!need_to_queue) case above when the
+ * upper layer has installed cell handlers.
+ */
+cell_copy = tor_malloc_zero(sizeof(cell_t));
+memcpy(cell_copy, cell, sizeof(cell_t));
+q = cell_queue_entry_new_fixed(cell_copy);
 log_debug(LD_CHANNEL,
   "Queueing incoming cell_t %p for channel %p "
   "(global ID " U64_FORMAT ")",
@@ -2755,6 +2774,7 @@ channel_queue_var_cell(channel_t *chan, var_cell_t 
*var_cell)
 {
   int need_to_queue = 0;
   cell_queue_entry_t *q;
+  var_cell_t *cell_copy = NULL;
 
   tor_assert(chan);
   tor_assert(var_cell);
@@ -2783,8 +2803,18 @@ channel_queue_var_cell(channel_t *chan, var_cell_t 
*var_cell)
   U64_PRINTF_ARG(chan->global_identifier));
 chan->var_cell_handler(chan, var_cell);
   } else {
-/* Otherwise queue it and then process the queue if possible. */
-q = cell_queue_entry_new_var(var_cell);
+/*
+ * Otherwise queue it and then process the queue if possible.
+ *
+ * We queue a copy, not the original pointer - it might have been on the
+ * stack in connection_or_process_cells_from_inbuf() (or another caller
+ * if we ever have a subclass other than channel_tls_t), or be freed
+ * there after we return.  This is the uncommon case; the non-copying
+ * fast path occurs in the if (!need_to_queue) case above when the
+ * upper layer has installed cell handlers.
+ */
+cell_copy = var_cell_copy(var_cell);
+q = cell_queue_entry_new_var(cell_copy);
 log_debug(LD_CHANNEL,
   "Queueing incoming var_cell_t %p for channel %p "
   "(global ID " U64_FORMAT ")",
diff --git a/src/or/channeltls.c b/src/or/channeltls.c
index c90f569..2a84514 100644
--- a/src/or/channeltls.c
+++ b/src/or/channeltls.c
@@ -1009,6 +1009,11 @@ channel_tls_time_process_cell(cell_t *cell, 
channel_tls_t *chan, int *time,
  * for cell types specific to the handshake for this transport protocol and
  * handles them, and queues all other cells to the channel_t layer, which
  * eventually will hand them off to command.c.
+ *
+ * The channel layer itself decides whether the cell should be queued or
+ * can be handed off immedi

[tor-commits] [tor/maint-0.2.7] Merge branch 'bug18570_027' into maint-0.2.7

2016-03-29 Thread andrea
commit 0b45cab1477d93e3065ca2d35e87483688f16bf6
Merge: 1218d73 72ebf41
Author: Andrea Shepard <and...@torproject.org>
Date:   Tue Mar 29 15:01:36 2016 +

Merge branch 'bug18570_027' into maint-0.2.7

 changes/bug18570|   7 +++
 src/or/channel.c|  38 +--
 src/or/channeltls.c |  11 +
 src/or/connection_or.c  |  35 ++
 src/or/connection_or.h  |   1 +
 src/test/test_channel.c | 121 ++--
 6 files changed, 204 insertions(+), 9 deletions(-)

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.7] Add new channel/queue_incoming unit tests; modify channel unit tests for new clarified handling of alloc/free responsibility for queued incoming cells

2016-03-29 Thread andrea
commit 1cdc7fddb2ed10d72f4e65e15d1af4d803a1acdb
Author: Andrea Shepard <and...@torproject.org>
Date:   Tue Mar 15 03:28:04 2016 +

Add new channel/queue_incoming unit tests; modify channel unit tests for 
new clarified handling of alloc/free responsibility for queued incoming cells
---
 src/test/test_channel.c | 121 ++--
 1 file changed, 116 insertions(+), 5 deletions(-)

diff --git a/src/test/test_channel.c b/src/test/test_channel.c
index e11ac3f..b705ee5 100644
--- a/src/test/test_channel.c
+++ b/src/test/test_channel.c
@@ -25,7 +25,9 @@ extern uint64_t estimated_total_queue_size;
 
 static int test_chan_accept_cells = 0;
 static int test_chan_fixed_cells_recved = 0;
+static cell_t * test_chan_last_seen_fixed_cell_ptr = NULL;
 static int test_chan_var_cells_recved = 0;
+static var_cell_t * test_chan_last_seen_var_cell_ptr = NULL;
 static int test_cells_written = 0;
 static int test_destroy_not_pending_calls = 0;
 static int test_doesnt_want_writes_count = 0;
@@ -70,6 +72,7 @@ static void test_channel_flushmux(void *arg);
 static void test_channel_incoming(void *arg);
 static void test_channel_lifecycle(void *arg);
 static void test_channel_multi(void *arg);
+static void test_channel_queue_incoming(void *arg);
 static void test_channel_queue_size(void *arg);
 static void test_channel_write(void *arg);
 
@@ -179,7 +182,7 @@ chan_test_cell_handler(channel_t *ch,
   tt_assert(ch);
   tt_assert(cell);
 
-  tor_free(cell);
+  test_chan_last_seen_fixed_cell_ptr = cell;
   ++test_chan_fixed_cells_recved;
 
  done:
@@ -214,7 +217,7 @@ chan_test_var_cell_handler(channel_t *ch,
   tt_assert(ch);
   tt_assert(var_cell);
 
-  tor_free(var_cell);
+  test_chan_last_seen_var_cell_ptr = var_cell;
   ++test_chan_var_cells_recved;
 
  done:
@@ -608,7 +611,7 @@ test_channel_dumpstats(void *arg)
   make_fake_cell(cell);
   old_count = test_chan_fixed_cells_recved;
   channel_queue_cell(ch, cell);
-  cell = NULL;
+  tor_free(cell);
   tt_int_op(test_chan_fixed_cells_recved, ==, old_count + 1);
   tt_assert(ch->n_bytes_recved > 0);
   tt_assert(ch->n_cells_recved > 0);
@@ -819,7 +822,7 @@ test_channel_incoming(void *arg)
   make_fake_cell(cell);
   old_count = test_chan_fixed_cells_recved;
   channel_queue_cell(ch, cell);
-  cell = NULL;
+  tor_free(cell);
   tt_int_op(test_chan_fixed_cells_recved, ==, old_count + 1);
 
   /* Receive a variable-size cell */
@@ -827,7 +830,7 @@ test_channel_incoming(void *arg)
   make_fake_var_cell(var_cell);
   old_count = test_chan_var_cells_recved;
   channel_queue_var_cell(ch, var_cell);
-  var_cell = NULL;
+  tor_free(cell);
   tt_int_op(test_chan_var_cells_recved, ==, old_count + 1);
 
   /* Close it */
@@ -1423,6 +1426,113 @@ test_channel_queue_impossible(void *arg)
 }
 
 static void
+test_channel_queue_incoming(void *arg)
+{
+  channel_t *ch = NULL;
+  cell_t *cell = NULL;
+  var_cell_t *var_cell = NULL;
+  int old_fixed_count, old_var_count;
+
+  (void)arg;
+
+  /* Mock these for duration of the test */
+  MOCK(scheduler_channel_doesnt_want_writes,
+   scheduler_channel_doesnt_want_writes_mock);
+  MOCK(scheduler_release_channel,
+   scheduler_release_channel_mock);
+
+  /* Accept cells to lower layer */
+  test_chan_accept_cells = 1;
+  /* Use default overhead factor */
+  test_overhead_estimate = 1.0f;
+
+  ch = new_fake_channel();
+  tt_assert(ch);
+  /* Start it off in OPENING */
+  ch->state = CHANNEL_STATE_OPENING;
+  /* We'll need a cmux */
+  ch->cmux = circuitmux_alloc();
+
+  /* Test cell handler getters */
+  tt_ptr_op(channel_get_cell_handler(ch), ==, NULL);
+  tt_ptr_op(channel_get_var_cell_handler(ch), ==, NULL);
+
+  /* Try to register it */
+  channel_register(ch);
+  tt_assert(ch->registered);
+
+  /* Open it */
+  channel_change_state(ch, CHANNEL_STATE_OPEN);
+  tt_int_op(ch->state, ==, CHANNEL_STATE_OPEN);
+
+  /* Assert that the incoming queue is empty */
+  tt_assert(TOR_SIMPLEQ_EMPTY(&(ch->incoming_queue)));
+
+  /* Queue an incoming fixed-length cell */
+  cell = tor_malloc_zero(sizeof(cell_t));
+  make_fake_cell(cell);
+  channel_queue_cell(ch, cell);
+
+  /* Assert that the incoming queue has one entry */
+  tt_int_op(chan_cell_queue_len(&(ch->incoming_queue)), ==, 1);
+
+  /* Queue an incoming var cell */
+  var_cell = tor_malloc_zero(sizeof(var_cell_t) + CELL_PAYLOAD_SIZE);
+  make_fake_var_cell(var_cell);
+  channel_queue_var_cell(ch, var_cell);
+
+  /* Assert that the incoming queue has two entries */
+  tt_int_op(chan_cell_queue_len(&(ch->incoming_queue)), ==, 2);
+
+  /*
+   * Install cell handlers; this will drain the queue, so save the old
+   * cell counters first
+   */
+  old_fixed_count = test_chan_fixed_cells_recved;
+  old_var_count = test_chan_var_cells_recved;
+  channel_set_cell_handlers(ch,
+chan_test_cell_handler,
+chan_test_var_cell_handler);
+  tt_ptr_op(channel_get_cell_han

[tor-commits] [tor/maint-0.2.7] changes file for bug18570

2016-03-29 Thread andrea
commit 72ebf4160412f64fb6ae0cd97dd89d01d89c075a
Author: Nick Mathewson 
Date:   Mon Mar 21 10:19:07 2016 -0400

changes file for bug18570
---
 changes/bug18570 | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/changes/bug18570 b/changes/bug18570
new file mode 100644
index 000..04f72f4
--- /dev/null
+++ b/changes/bug18570
@@ -0,0 +1,7 @@
+  o Minor bugfixes (correctness):
+- Fix a bad memory handling bug that would occur if we had queued
+  a cell on a channel's incoming queue. Fortunately, we can't actually
+  queue a cell like that as our code is constructed today, but it's best
+  to avoid this kind of error, even if there isn't any code that triggers
+  it today. Fixes bug 18570; bugfix on 0.2.4.4-alpha.
+



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.7] Add comments to connection_check_event().

2016-03-29 Thread andrea
commit 307b863556e34f0f1575c8c7ea1dd79e07eff16c
Author: Nick Mathewson 
Date:   Mon Mar 14 12:53:21 2016 -0400

Add comments to connection_check_event().
---
 src/or/main.c | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/src/or/main.c b/src/or/main.c
index f91049b..f17fc90 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -567,14 +567,24 @@ connection_is_reading(connection_t *conn)
 (conn->read_event && event_pending(conn->read_event, EV_READ, NULL));
 }
 
+/** Check whether conn is correct in having (or not having) a
+ * read/write event (passed in evtype == CONN_TYPE_AP && TO_EDGE_CONN(conn)->is_dns_request) {
+/* DNS requests which we launch through the dnsserv.c module do not have
+ * any underlying socket or any underlying linked connection, so they
+ * shouldn't have any attached events either.
+ */
 bad = ev != NULL;
   } else {
+/* Everytyhing else should have an underlying socket, or a linked
+ * connection (which is also tracked with a read_event/write_event pair).
+ */
 bad = ev == NULL;
   }
 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.7] If we start/stop reading on a dnsserv connection, don't assert.

2016-03-29 Thread andrea
commit e79da62645925f3286deb21740bbe91de9dafacc
Author: Nick Mathewson 
Date:   Fri Mar 11 10:33:19 2016 -0500

If we start/stop reading on a dnsserv connection, don't assert.

Fixes bug 16248. Patch from cypherpunks.  Bugfix on 0.2.0.1-alpha.
---
 src/or/main.c | 12 
 1 file changed, 12 insertions(+)

diff --git a/src/or/main.c b/src/or/main.c
index 534a6ac..3fb80e1 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -578,6 +578,12 @@ connection_stop_reading,(connection_t *conn))
   return;
   });
 
+  /* if dummy conn then no socket and no event, nothing to do here */
+  if (conn->type == CONN_TYPE_AP && TO_EDGE_CONN(conn)->is_dns_request) {
+tor_assert(!conn->read_event);
+return;
+  }
+
   tor_assert(conn->read_event);
 
   if (conn->linked) {
@@ -603,6 +609,12 @@ connection_start_reading,(connection_t *conn))
   return;
   });
 
+  /* if dummy conn then no socket and no event, nothing to do here */
+  if (conn->type == CONN_TYPE_AP && TO_EDGE_CONN(conn)->is_dns_request) {
+tor_assert(!conn->read_event);
+return;
+  }
+
   tor_assert(conn->read_event);
 
   if (conn->linked) {



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.7] Merge branch 'bug16248_027' into maint-0.2.7

2016-03-29 Thread andrea
commit 1218d731d1f3c1944a22bba45ef2f6a0853eba5c
Merge: e1e62f9 307b863
Author: Andrea Shepard <and...@torproject.org>
Date:   Tue Mar 29 14:33:45 2016 +

Merge branch 'bug16248_027' into maint-0.2.7

 changes/bug16248 |  8 
 src/or/main.c| 55 +++
 2 files changed, 59 insertions(+), 4 deletions(-)

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.7] Change behavior on missing/present event to warn instead of asserting.

2016-03-29 Thread andrea
commit 91d7cf50c6cb6eb1e2dc2b4a8eab489c10a759a6
Author: Nick Mathewson 
Date:   Fri Mar 11 10:50:36 2016 -0500

Change behavior on missing/present event to warn instead of asserting.

Add a changes file.
---
 changes/bug16248 |  8 
 src/or/main.c| 49 +
 2 files changed, 45 insertions(+), 12 deletions(-)

diff --git a/changes/bug16248 b/changes/bug16248
new file mode 100644
index 000..399b709
--- /dev/null
+++ b/changes/bug16248
@@ -0,0 +1,8 @@
+  o Major bugfixes (dns proxy mode, crash):
+- Avoid crashing when running as a DNS proxy. Closes bug 16248; bugfix on
+  0.2.0.1-alpha. Patch from 'cypherpunks'.
+
+  o Minor features (bug-resistance):
+- Make Tor survive errors involving connections without a corresponding
+  event object. Previously we'd fail with an assertion; now we produce a
+  log message. Related to bug 16248.
diff --git a/src/or/main.c b/src/or/main.c
index 3fb80e1..f91049b 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -567,6 +567,35 @@ connection_is_reading(connection_t *conn)
 (conn->read_event && event_pending(conn->read_event, EV_READ, NULL));
 }
 
+static int
+connection_check_event(connection_t *conn, struct event *ev)
+{
+  int bad;
+
+  if (conn->type == CONN_TYPE_AP && TO_EDGE_CONN(conn)->is_dns_request) {
+bad = ev != NULL;
+  } else {
+bad = ev == NULL;
+  }
+
+  if (bad) {
+log_warn(LD_BUG, "Event missing on connection %p [%s;%s]. "
+ "socket=%d. linked=%d. "
+ "is_dns_request=%d. Marked_for_close=%s:%d",
+ conn,
+ conn_type_to_string(conn->type),
+ conn_state_to_string(conn->type, conn->state),
+ (int)conn->s, (int)conn->linked,
+ (conn->type == CONN_TYPE_AP && 
TO_EDGE_CONN(conn)->is_dns_request),
+ conn->marked_for_close_file ? conn->marked_for_close_file : "-",
+ conn->marked_for_close
+ );
+log_backtrace(LOG_WARN, LD_BUG, "Backtrace attached.");
+return -1;
+  }
+  return 0;
+}
+
 /** Tell the main loop to stop notifying conn of any read events. */
 MOCK_IMPL(void,
 connection_stop_reading,(connection_t *conn))
@@ -578,14 +607,10 @@ connection_stop_reading,(connection_t *conn))
   return;
   });
 
-  /* if dummy conn then no socket and no event, nothing to do here */
-  if (conn->type == CONN_TYPE_AP && TO_EDGE_CONN(conn)->is_dns_request) {
-tor_assert(!conn->read_event);
+  if (connection_check_event(conn, conn->read_event) < 0) {
 return;
   }
 
-  tor_assert(conn->read_event);
-
   if (conn->linked) {
 conn->reading_from_linked_conn = 0;
 connection_stop_reading_from_linked_conn(conn);
@@ -609,14 +634,10 @@ connection_start_reading,(connection_t *conn))
   return;
   });
 
-  /* if dummy conn then no socket and no event, nothing to do here */
-  if (conn->type == CONN_TYPE_AP && TO_EDGE_CONN(conn)->is_dns_request) {
-tor_assert(!conn->read_event);
+  if (connection_check_event(conn, conn->read_event) < 0) {
 return;
   }
 
-  tor_assert(conn->read_event);
-
   if (conn->linked) {
 conn->reading_from_linked_conn = 1;
 if (connection_should_read_from_linked_conn(conn))
@@ -655,7 +676,9 @@ connection_stop_writing,(connection_t *conn))
   return;
   });
 
-  tor_assert(conn->write_event);
+  if (connection_check_event(conn, conn->write_event) < 0) {
+return;
+  }
 
   if (conn->linked) {
 conn->writing_to_linked_conn = 0;
@@ -681,7 +704,9 @@ connection_start_writing,(connection_t *conn))
   return;
   });
 
-  tor_assert(conn->write_event);
+  if (connection_check_event(conn, conn->write_event) < 0) {
+return;
+  }
 
   if (conn->linked) {
 conn->writing_to_linked_conn = 1;



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Appease make check-spaces

2016-02-22 Thread andrea
commit cda238178986e79ff8f783469682f33fa7230a26
Author: Andrea Shepard <and...@torproject.org>
Date:   Tue Feb 23 05:07:29 2016 +

Appease make check-spaces
---
 src/common/util.c  | 4 ++--
 src/or/directory.c | 7 ---
 src/test/test_routerlist.c | 1 -
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/common/util.c b/src/common/util.c
index fda5993..488f1b6 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -2080,7 +2080,7 @@ check_private_dir(const char *dirname, cpd_check_t check,
*/
   tor_assert(dirname);
 
-  /* Open directory. 
+  /* Open directory.
* O_NOFOLLOW to ensure that it does not follow symbolic links */
   fd = open(sandbox_intern_string(dirname), O_NOFOLLOW);
 
@@ -2122,7 +2122,7 @@ check_private_dir(const char *dirname, cpd_check_t check,
 
   if ( fd == -1 ) return -1;
 
-} else if (!(check & CPD_CHECK)) { 
+} else if (!(check & CPD_CHECK)) {
   log_warn(LD_FS, "Directory %s does not exist.", dirname);
   return -1;
 }
diff --git a/src/or/directory.c b/src/or/directory.c
index 6c8b6a2..399752a 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -2363,9 +2363,10 @@ connection_dir_client_reached_eof(dir_connection_t *conn)
 
   if (conn->base_.purpose == DIR_PURPOSE_UPLOAD_RENDDESC_V2) {
 #define SEND_HS_DESC_UPLOAD_FAILED_EVENT(reason) ( \
-  control_event_hs_descriptor_upload_failed(conn->identity_digest, \
-
conn->rend_data->onion_address, \
-reason) )
+  control_event_hs_descriptor_upload_failed( \
+conn->identity_digest, \
+conn->rend_data->onion_address, \
+reason) )
 log_info(LD_REND,"Uploaded rendezvous descriptor (status %d "
  "(%s))",
  status_code, escaped(reason));
diff --git a/src/test/test_routerlist.c b/src/test/test_routerlist.c
index 010dfd6..31533d0 100644
--- a/src/test/test_routerlist.c
+++ b/src/test/test_routerlist.c
@@ -145,7 +145,6 @@ construct_consensus(const char **consensus_text_md)
   tt_int_op(n_vrs, ==, 4);
   tt_int_op(smartlist_len(v1->routerstatus_list), ==, 4);
 
-
   dir_common_construct_vote_2(, cert2, sign_skey_2,
   _common_gen_routerstatus_for_v3ns,
   , _vrs, now, 1);

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/release-0.2.6] Bump version to 0.2.6.9

2015-06-10 Thread andrea
commit b616aea0740e05934fa23d15e127659ca06c2b15
Author: Andrea Shepard and...@persephoneslair.org
Date:   Wed Jun 10 14:58:33 2015 +

Bump version to 0.2.6.9
---
 configure.ac|2 +-
 contrib/win32build/tor-mingw.nsi.in |2 +-
 src/win32/orconfig.h|2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 156bb3f..1496b05 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,7 +3,7 @@ dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
 dnl Copyright (c) 2007-2015, The Tor Project, Inc.
 dnl See LICENSE for licensing information
 
-AC_INIT([tor],[0.2.6.8])
+AC_INIT([tor],[0.2.6.9])
 AC_CONFIG_SRCDIR([src/or/main.c])
 AC_CONFIG_MACRO_DIR([m4])
 AM_INIT_AUTOMAKE
diff --git a/contrib/win32build/tor-mingw.nsi.in 
b/contrib/win32build/tor-mingw.nsi.in
index 1764614..5c5c1bb 100644
--- a/contrib/win32build/tor-mingw.nsi.in
+++ b/contrib/win32build/tor-mingw.nsi.in
@@ -8,7 +8,7 @@
 !include LogicLib.nsh
 !include FileFunc.nsh
 !insertmacro GetParameters
-!define VERSION 0.2.6.8
+!define VERSION 0.2.6.9
 !define INSTALLER tor-${VERSION}-win32.exe
 !define WEBSITE https://www.torproject.org/;
 !define LICENSE LICENSE
diff --git a/src/win32/orconfig.h b/src/win32/orconfig.h
index 466822e..fd59446 100644
--- a/src/win32/orconfig.h
+++ b/src/win32/orconfig.h
@@ -232,7 +232,7 @@
 #define USING_TWOS_COMPLEMENT
 
 /* Version number of package */
-#define VERSION 0.2.6.8
+#define VERSION 0.2.6.9
 
 
 #define HAVE_STRUCT_SOCKADDR_IN6



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/release-0.2.6] Merge branch 'release-0.2.6' of ssh://git-rw.torproject.org/tor into release-0.2.6

2015-06-10 Thread andrea
commit 2f17b91ae2ca622294bf63dec2a6986756685702
Merge: b616aea 3761711
Author: Andrea Shepard and...@persephoneslair.org
Date:   Wed Jun 10 14:59:13 2015 +

Merge branch 'release-0.2.6' of ssh://git-rw.torproject.org/tor into 
release-0.2.6

 ChangeLog |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.6] Bump version to 0.2.6.9

2015-06-10 Thread andrea
commit 1eb2c0cbd3a9be2650419bd07474770629261f56
Author: Andrea Shepard and...@persephoneslair.org
Date:   Wed Jun 10 14:58:33 2015 +

Bump version to 0.2.6.9
---
 configure.ac|2 +-
 contrib/win32build/tor-mingw.nsi.in |2 +-
 src/win32/orconfig.h|2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 156bb3f..1496b05 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,7 +3,7 @@ dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
 dnl Copyright (c) 2007-2015, The Tor Project, Inc.
 dnl See LICENSE for licensing information
 
-AC_INIT([tor],[0.2.6.8])
+AC_INIT([tor],[0.2.6.9])
 AC_CONFIG_SRCDIR([src/or/main.c])
 AC_CONFIG_MACRO_DIR([m4])
 AM_INIT_AUTOMAKE
diff --git a/contrib/win32build/tor-mingw.nsi.in 
b/contrib/win32build/tor-mingw.nsi.in
index 1764614..5c5c1bb 100644
--- a/contrib/win32build/tor-mingw.nsi.in
+++ b/contrib/win32build/tor-mingw.nsi.in
@@ -8,7 +8,7 @@
 !include LogicLib.nsh
 !include FileFunc.nsh
 !insertmacro GetParameters
-!define VERSION 0.2.6.8
+!define VERSION 0.2.6.9
 !define INSTALLER tor-${VERSION}-win32.exe
 !define WEBSITE https://www.torproject.org/;
 !define LICENSE LICENSE
diff --git a/src/win32/orconfig.h b/src/win32/orconfig.h
index c0ab2de..9b2e84d 100644
--- a/src/win32/orconfig.h
+++ b/src/win32/orconfig.h
@@ -232,7 +232,7 @@
 #define USING_TWOS_COMPLEMENT
 
 /* Version number of package */
-#define VERSION 0.2.6.8
+#define VERSION 0.2.6.9
 
 
 

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/release-0.2.6] Bump version to 0.2.6.9

2015-06-10 Thread andrea
commit 1eb2c0cbd3a9be2650419bd07474770629261f56
Author: Andrea Shepard and...@persephoneslair.org
Date:   Wed Jun 10 14:58:33 2015 +

Bump version to 0.2.6.9
---
 configure.ac|2 +-
 contrib/win32build/tor-mingw.nsi.in |2 +-
 src/win32/orconfig.h|2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/configure.ac b/configure.ac
index 156bb3f..1496b05 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3,7 +3,7 @@ dnl Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
 dnl Copyright (c) 2007-2015, The Tor Project, Inc.
 dnl See LICENSE for licensing information
 
-AC_INIT([tor],[0.2.6.8])
+AC_INIT([tor],[0.2.6.9])
 AC_CONFIG_SRCDIR([src/or/main.c])
 AC_CONFIG_MACRO_DIR([m4])
 AM_INIT_AUTOMAKE
diff --git a/contrib/win32build/tor-mingw.nsi.in 
b/contrib/win32build/tor-mingw.nsi.in
index 1764614..5c5c1bb 100644
--- a/contrib/win32build/tor-mingw.nsi.in
+++ b/contrib/win32build/tor-mingw.nsi.in
@@ -8,7 +8,7 @@
 !include LogicLib.nsh
 !include FileFunc.nsh
 !insertmacro GetParameters
-!define VERSION 0.2.6.8
+!define VERSION 0.2.6.9
 !define INSTALLER tor-${VERSION}-win32.exe
 !define WEBSITE https://www.torproject.org/;
 !define LICENSE LICENSE
diff --git a/src/win32/orconfig.h b/src/win32/orconfig.h
index c0ab2de..9b2e84d 100644
--- a/src/win32/orconfig.h
+++ b/src/win32/orconfig.h
@@ -232,7 +232,7 @@
 #define USING_TWOS_COMPLEMENT
 
 /* Version number of package */
-#define VERSION 0.2.6.8
+#define VERSION 0.2.6.9
 
 
 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/release-0.2.6] Fix typo in 0.2.6.9 ChangeLog

2015-06-10 Thread andrea
commit 5dc6f758d60bf1aeca6cc3a1572c6052de14420e
Author: Andrea Shepard and...@persephoneslair.org
Date:   Wed Jun 10 14:43:31 2015 +

Fix typo in 0.2.6.9 ChangeLog
---
 ChangeLog |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 0670977..ea4c86f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -7,7 +7,7 @@ Changes in version 0.2.6.9 - 2015-06-??
   being overwritten by a default value. Fixes bug 16247; bugfix on
   0.2.6.3-alpha. Patch by jojelino.
 
-  o Minor feature (directory aurhorities, security):
+  o Minor feature (directory authorities, security):
 - The HSDir flag given by authorities now requires the Stable flag.
   For the current network, this results in going from 2887 to 2806
   HSDirs. Also, it makes it harder for an attacker to launch a sybil

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/release-0.2.6] Merge branch 'maint-0.2.6' into release-0.2.6

2015-06-10 Thread andrea
commit 0e939c1e0021b40491789a082eec8ddb422ecc2d
Merge: 2f17b91 1eb2c0c
Author: Andrea Shepard and...@persephoneslair.org
Date:   Wed Jun 10 15:03:22 2015 +

Merge branch 'maint-0.2.6' into release-0.2.6

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Update and clarify release checklist

2015-06-10 Thread andrea
commit 95bcd2dc151ba59fe3b9a4ae4725874cf67dc698
Author: Andrea Shepard and...@persephoneslair.org
Date:   Wed Jun 10 15:05:52 2015 +

Update and clarify release checklist
---
 doc/HACKING |5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/doc/HACKING b/doc/HACKING
index 511e3fb..d94e0a9 100644
--- a/doc/HACKING
+++ b/doc/HACKING
@@ -568,8 +568,9 @@ a stable release, add it to the ReleaseNotes file too. If 
we're adding
 to a release-0.2.x branch, manually commit the changelogs to the later
 git branches too.
 
-4) Bump the version number in configure.ac and rebuild.  Then run
-   make update-versions.
+4) In maint-0.2.x, bump the version number in configure.ac and run
+   scripts/maint/updateVersions.pl to update version numbers in other
+   places, and commit.  Then merge maint-0.2.x into release-0.2.x.
 
 5) Make dist, put the tarball up somewhere, and tell #tor about it. Wait
 a while to see if anybody has problems building it. Try to get Sebastian

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Appease make check-spaces

2015-06-01 Thread andrea
commit 0e0b65db4f0f0c67bcbb3f51a9e6061bc4c96c5e
Author: Andrea Shepard and...@torproject.org
Date:   Mon Jun 1 12:59:14 2015 +

Appease make check-spaces
---
 src/common/aes.c   |1 +
 src/common/crypto_ed25519.h|1 -
 src/common/tortls.c|3 ++-
 src/or/channeltls.c|2 +-
 src/or/control.c   |2 +-
 src/or/dircollate.c|6 --
 src/or/dircollate.h|1 +
 src/or/or.h|1 -
 src/or/rendservice.c   |3 ++-
 src/or/routerkeys.c|9 ++---
 src/or/routerlist.c|3 ++-
 src/or/routerparse.c   |6 --
 src/or/torcert.c   |1 +
 src/test/test_buffers.c|1 -
 src/test/test_hs.c |5 +++--
 src/test/test_link_handshake.c |3 +--
 16 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/src/common/aes.c b/src/common/aes.c
index dbc12dc..8b9d81f 100644
--- a/src/common/aes.c
+++ b/src/common/aes.c
@@ -501,3 +501,4 @@ aes_set_iv(aes_cnt_cipher_t *cipher, const char *iv)
 }
 
 #endif
+
diff --git a/src/common/crypto_ed25519.h b/src/common/crypto_ed25519.h
index 8ffb9f2..4d20406 100644
--- a/src/common/crypto_ed25519.h
+++ b/src/common/crypto_ed25519.h
@@ -88,7 +88,6 @@ int ed25519_public_blind(ed25519_public_key_t *out,
  const ed25519_public_key_t *inp,
  const uint8_t *param);
 
-
 /*  move these to crypto_format.h */
 #define ED25519_BASE64_LEN 43
 int ed25519_public_from_base64(ed25519_public_key_t *pkey,
diff --git a/src/common/tortls.c b/src/common/tortls.c
index 098df9d..a4b6c48 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -1810,7 +1810,8 @@ rectify_client_ciphers(SSL *ssl)
   SSL_CIPHER_get_name(cipher));
 ++j;
   } else if (cipher 
- (SSL_CIPHER_get_id(cipher)  0x) == 
CLIENT_CIPHER_INFO_LIST[i].id) {
+ (SSL_CIPHER_get_id(cipher)  0x) ==
+  CLIENT_CIPHER_INFO_LIST[i].id) {
 /* cipher is the cipher we expect. Put it on the list. */
 log_debug(LD_NET, Found cipher %s, SSL_CIPHER_get_name(cipher));
 sk_SSL_CIPHER_push(CLIENT_CIPHER_STACK, cipher);
diff --git a/src/or/channeltls.c b/src/or/channeltls.c
index ecf0218..c90f569 100644
--- a/src/or/channeltls.c
+++ b/src/or/channeltls.c
@@ -2004,7 +2004,7 @@ channel_tls_process_auth_challenge_cell(var_cell_t *cell, 
channel_tls_t *chan)
 goto done;
   }
 
-done:
+ done:
   auth_challenge_cell_free(ac);
 
 #undef ERR
diff --git a/src/or/control.c b/src/or/control.c
index 746dfff..2eaad4e 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -6029,7 +6029,7 @@ get_desc_id_from_query(const rend_data_t *rend_data, 
const char *hsdir_fp)
 } SMARTLIST_FOREACH_END(fingerprint);
   }
 
-end:
+ end:
   return desc_id;
 }
 
diff --git a/src/or/dircollate.c b/src/or/dircollate.c
index 20dfb35..34259ec 100644
--- a/src/or/dircollate.c
+++ b/src/or/dircollate.c
@@ -59,8 +59,10 @@ ddmap_entry_set_digests(ddmap_entry_t *ent,
   memcpy(ent-d + DIGEST_LEN, ed25519, DIGEST256_LEN);
 }
 
-HT_PROTOTYPE(double_digest_map, ddmap_entry_s, node, ddmap_entry_hash, 
ddmap_entry_eq);
-HT_GENERATE2(double_digest_map, ddmap_entry_s, node, ddmap_entry_hash, 
ddmap_entry_eq, 0.6, tor_reallocarray, tor_free_);
+HT_PROTOTYPE(double_digest_map, ddmap_entry_s, node, ddmap_entry_hash,
+ ddmap_entry_eq);
+HT_GENERATE2(double_digest_map, ddmap_entry_s, node, ddmap_entry_hash,
+ ddmap_entry_eq, 0.6, tor_reallocarray, tor_free_);
 static void
 dircollator_add_routerstatus(dircollator_t *dc,
  int vote_num,
diff --git a/src/or/dircollate.h b/src/or/dircollate.h
index 9eba37a..cd1e8ac 100644
--- a/src/or/dircollate.h
+++ b/src/or/dircollate.h
@@ -47,3 +47,4 @@ struct dircollator_s {
 #endif
 
 #endif
+
diff --git a/src/or/or.h b/src/or/or.h
index 81e1c1c..ec5f277 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -4281,7 +4281,6 @@ typedef struct {
*  Eventually, the default will be 0. */
   int ExitRelay;
 
-
   /** For how long (seconds) do we declare our singning keys to be valid? */
   int SigningKeyLifetime;
   /** For how long (seconds) do we declare our link keys to be valid? */
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index d27b06d..c857d4c 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -581,7 +581,8 @@ rend_config_services(const or_options_t *options, int 
validate_only)
 10, 0, 1, ok, NULL);
   if (!ok) {
 log_warn(LD_CONFIG,
- HiddenServiceMaxStreamsCloseCircuit should be 0 or 1, not 
%s,
+ HiddenServiceMaxStreamsCloseCircuit should be 0 or 1, 
+ not %s,
  line-value);
 rend_service_free(service);
 return -1;
diff --git a/src/or/routerkeys.c b/src

[tor-commits] [tor/master] Fix formatting

2015-03-02 Thread andrea
commit d97f43dc8bbc50272f89d26c2bd1a22b1cc6e5d8
Author: Andrea Shepard and...@torproject.org
Date:   Mon Mar 2 10:24:58 2015 +

Fix formatting
---
 src/common/container.h |1 -
 src/test/test_status.c |6 --
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/common/container.h b/src/common/container.h
index d07697f..457b5e4 100644
--- a/src/common/container.h
+++ b/src/common/container.h
@@ -256,7 +256,6 @@ char *smartlist_join_strings2(smartlist_t *sl, const char 
*join,
  --var ## _sl_len;\
   STMT_END
 
-
 /** Helper: While in a SMARTLIST_FOREACH loop over the list bsl/b indexed
  * with the variable bvar/b, replace the current element with bval/b.
  * Does not deallocate the current value of bvar/b.
diff --git a/src/test/test_status.c b/src/test/test_status.c
index 0aa82ca..cb3b4f6 100644
--- a/src/test/test_status.c
+++ b/src/test/test_status.c
@@ -878,7 +878,8 @@ NS(logv)(int severity, log_domain_mask_t domain, const char 
*funcname,
   tt_ptr_op(strstr(funcname, log_heartbeat), OP_NE, NULL);
   tt_ptr_op(suffix, OP_EQ, NULL);
   tt_str_op(format, OP_EQ,
-  Average packaged cell fullness: %2.3f%%. TLS write overhead: 
%.f%%);
+  Average packaged cell fullness: %2.3f%%. 
+  TLS write overhead: %.f%%);
   tt_double_op(fabs(va_arg(ap, double) - 50.0), =, DBL_EPSILON);
   tt_double_op(fabs(va_arg(ap, double) - 0.0), =, DBL_EPSILON);
   break;
@@ -1026,7 +1027,8 @@ NS(logv)(int severity, log_domain_mask_t domain,
   tt_ptr_op(strstr(funcname, log_heartbeat), OP_NE, NULL);
   tt_ptr_op(suffix, OP_EQ, NULL);
   tt_str_op(format, OP_EQ,
-  Average packaged cell fullness: %2.3f%%. TLS write overhead: 
%.f%%);
+  Average packaged cell fullness: %2.3f%%. 
+  TLS write overhead: %.f%%);
   tt_int_op(fabs(va_arg(ap, double) - 100.0) = DBL_EPSILON, OP_EQ, 1);
   tt_double_op(fabs(va_arg(ap, double) - 100.0), =, DBL_EPSILON);
   break;

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.4] Fix bug9309, and n_noncanonical count/continue code

2013-07-23 Thread andrea
commit 1d2e8020b7be5aff08cfde6f94c24b145625c1ad
Author: Nick Mathewson ni...@torproject.org
Date:   Tue Jul 23 11:52:10 2013 +0200

Fix bug9309, and n_noncanonical count/continue code

When we moved channel_matches_target_addr_for_extend() into a separate
function, its sense was inverted from what one might expect, and we
didn't have a ! in one place where we should have.

Found by skruffy.
---
 changes/bug9309 |6 ++
 src/or/channel.c|4 ++--
 src/or/channeltls.c |5 ++---
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/changes/bug9309 b/changes/bug9309
new file mode 100644
index 000..38c462b
--- /dev/null
+++ b/changes/bug9309
@@ -0,0 +1,6 @@
+  o Minor bugfixes:
+- When evaluating whether to use a connection that we haven't
+  decided is canonical using a recent link protocol version,
+  decide that it's canonical only if it used address _does_
+  match the desired address. Fixes bug 9309; bugfix on
+  0.2.4.4-alpha. Reported by skruffy.
diff --git a/src/or/channel.c b/src/or/channel.c
index 4e9086f..602797d 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -3037,7 +3037,7 @@ channel_get_for_extend(const char *digest,
 if (chan-state != CHANNEL_STATE_OPEN) {
   /* If the address matches, don't launch a new connection for this
* circuit. */
-  if (!channel_matches_target_addr_for_extend(chan, target_addr))
+  if (channel_matches_target_addr_for_extend(chan, target_addr))
 ++n_inprogress_goodaddr;
   continue;
 }
@@ -4053,7 +4053,7 @@ channel_matches_extend_info(channel_t *chan, 
extend_info_t *extend_info)
 }
 
 /**
- * Check if a channel matches a given target address
+ * Check if a channel matches a given target address; return true iff we do.
  *
  * This function calls into the lower layer and asks if this channel thinks
  * it matches a given target address for circuit extension purposes.
diff --git a/src/or/channeltls.c b/src/or/channeltls.c
index 60693da..d758d22 100644
--- a/src/or/channeltls.c
+++ b/src/or/channeltls.c
@@ -546,7 +546,7 @@ channel_tls_matches_extend_info_method(channel_t *chan,
 }
 
 /**
- * Check if we match a target address
+ * Check if we match a target address; return true iff we do.
  *
  * This implements the matches_target method for channel_tls t_; the upper
  * layer wants to know if this channel matches a target address when extending
@@ -563,8 +563,7 @@ channel_tls_matches_target_method(channel_t *chan,
   tor_assert(target);
   tor_assert(tlschan-conn);
 
-  return tor_addr_compare((tlschan-conn-real_addr),
-  target, CMP_EXACT);
+  return tor_addr_eq((tlschan-conn-real_addr), target);
 }
 
 /**

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Fix bug9309, and n_noncanonical count/continue code

2013-07-23 Thread andrea
commit 5d4b5018be5d85162d96cc3781acbf892f33bc21
Author: Nick Mathewson ni...@torproject.org
Date:   Tue Jul 23 11:52:10 2013 +0200

Fix bug9309, and n_noncanonical count/continue code

When we moved channel_matches_target_addr_for_extend() into a separate
function, its sense was inverted from what one might expect, and we
didn't have a ! in one place where we should have.

Found by skruffy.
---
 changes/bug9309 |6 ++
 src/or/channel.c|4 ++--
 src/or/channeltls.c |5 ++---
 3 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/changes/bug9309 b/changes/bug9309
new file mode 100644
index 000..38c462b
--- /dev/null
+++ b/changes/bug9309
@@ -0,0 +1,6 @@
+  o Minor bugfixes:
+- When evaluating whether to use a connection that we haven't
+  decided is canonical using a recent link protocol version,
+  decide that it's canonical only if it used address _does_
+  match the desired address. Fixes bug 9309; bugfix on
+  0.2.4.4-alpha. Reported by skruffy.
diff --git a/src/or/channel.c b/src/or/channel.c
index 98c23d9..05f269b 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -3090,7 +3090,7 @@ channel_get_for_extend(const char *digest,
 if (chan-state != CHANNEL_STATE_OPEN) {
   /* If the address matches, don't launch a new connection for this
* circuit. */
-  if (!channel_matches_target_addr_for_extend(chan, target_addr))
+  if (channel_matches_target_addr_for_extend(chan, target_addr))
 ++n_inprogress_goodaddr;
   continue;
 }
@@ -4106,7 +4106,7 @@ channel_matches_extend_info(channel_t *chan, 
extend_info_t *extend_info)
 }
 
 /**
- * Check if a channel matches a given target address
+ * Check if a channel matches a given target address; return true iff we do.
  *
  * This function calls into the lower layer and asks if this channel thinks
  * it matches a given target address for circuit extension purposes.
diff --git a/src/or/channeltls.c b/src/or/channeltls.c
index 60693da..d758d22 100644
--- a/src/or/channeltls.c
+++ b/src/or/channeltls.c
@@ -546,7 +546,7 @@ channel_tls_matches_extend_info_method(channel_t *chan,
 }
 
 /**
- * Check if we match a target address
+ * Check if we match a target address; return true iff we do.
  *
  * This implements the matches_target method for channel_tls t_; the upper
  * layer wants to know if this channel matches a target address when extending
@@ -563,8 +563,7 @@ channel_tls_matches_target_method(channel_t *chan,
   tor_assert(target);
   tor_assert(tlschan-conn);
 
-  return tor_addr_compare((tlschan-conn-real_addr),
-  target, CMP_EXACT);
+  return tor_addr_eq((tlschan-conn-real_addr), target);
 }
 
 /**

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] fix typo

2013-07-23 Thread andrea
commit 2920d670debaaa7a306bedd5fd7ce9c3e72124e6
Author: Roger Dingledine a...@torproject.org
Date:   Thu Jul 18 23:35:20 2013 -0400

fix typo
---
 doc/tor.1.txt |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/doc/tor.1.txt b/doc/tor.1.txt
index bade531..d13ec20 100644
--- a/doc/tor.1.txt
+++ b/doc/tor.1.txt
@@ -1679,7 +1679,7 @@ is non-zero):
 If it hits this threshold, it will begin killing circuits until it
 has recovered at least 10% of this memory.  Do not set this option too
 low, or your relay may be unreliable under load.  This option only
-effects circuit queues, so the actual process size will be larger than
+affects circuit queues, so the actual process size will be larger than
 this. (Default: 8GB)
 
 DIRECTORY SERVER OPTIONS



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.3] Disable middle relay queue overfill detection code due to possible guard discovery attack

2013-06-15 Thread andrea
commit 2a95f3171681ee53c97ccba9d80f4454b462aaa7
Author: Andrea Shepard and...@torproject.org
Date:   Sat Jun 15 02:16:00 2013 -0700

Disable middle relay queue overfill detection code due to possible guard 
discovery attack
---
 changes/bug9072 |3 +++
 src/or/relay.c  |5 +
 2 files changed, 8 insertions(+)

diff --git a/changes/bug9072 b/changes/bug9072
new file mode 100644
index 000..e594a38
--- /dev/null
+++ b/changes/bug9072
@@ -0,0 +1,3 @@
+  o Critical bugfixes:
+- Disable middle relay queue overfill detection code due to possible
+  guard discovery attack, pending further analysis.  Fixes bug #9072.
diff --git a/src/or/relay.c b/src/or/relay.c
index 087459c..fdb4bff 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -2548,6 +2548,10 @@ append_cell_to_circuit_queue(circuit_t *circ, 
or_connection_t *orconn,
 streams_blocked = circ-streams_blocked_on_p_conn;
   }
 
+  /*
+   * Disabling this for now because of a possible guard discovery attack
+   */
+#if 0
   /* Are we a middle circuit about to exceed ORCIRC_MAX_MIDDLE_CELLS? */
   if ((circ-n_conn != NULL)  CIRCUIT_IS_ORCIRC(circ)) {
 orcirc = TO_OR_CIRCUIT(circ);
@@ -2566,6 +2570,7 @@ append_cell_to_circuit_queue(circuit_t *circ, 
or_connection_t *orconn,
   }
 }
   }
+#endif
 
   cell_queue_append_packed_copy(queue, cell);
 

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.4] Merge branch 'bug9072-023' into bug9072-024

2013-06-15 Thread andrea
commit 9e45d940d466bcefcd1490fc2ae0e5a6298a846f
Merge: 8b6d0bd 2a95f31
Author: Andrea Shepard and...@torproject.org
Date:   Sat Jun 15 02:20:19 2013 -0700

Merge branch 'bug9072-023' into bug9072-024

 changes/bug9072 |3 +++
 src/or/relay.c  |5 +
 2 files changed, 8 insertions(+)

diff --cc src/or/relay.c
index a26d418,fdb4bff..0f21663
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@@ -2474,18 -2540,22 +2474,22 @@@ append_cell_to_circuit_queue(circuit_t 
  return;
  
if (direction == CELL_DIRECTION_OUT) {
 -queue = circ-n_conn_cells;
 -streams_blocked = circ-streams_blocked_on_n_conn;
 +queue = circ-n_chan_cells;
 +streams_blocked = circ-streams_blocked_on_n_chan;
} else {
  orcirc = TO_OR_CIRCUIT(circ);
 -queue = orcirc-p_conn_cells;
 -streams_blocked = circ-streams_blocked_on_p_conn;
 +queue = orcirc-p_chan_cells;
 +streams_blocked = circ-streams_blocked_on_p_chan;
}
  
+   /*
+* Disabling this for now because of a possible guard discovery attack
+*/
+ #if 0
/* Are we a middle circuit about to exceed ORCIRC_MAX_MIDDLE_CELLS? */
 -  if ((circ-n_conn != NULL)  CIRCUIT_IS_ORCIRC(circ)) {
 +  if ((circ-n_chan != NULL)  CIRCUIT_IS_ORCIRC(circ)) {
  orcirc = TO_OR_CIRCUIT(circ);
 -if (orcirc-p_conn) {
 +if (orcirc-p_chan) {
if (queue-n + 1 = ORCIRC_MAX_MIDDLE_CELLS) {
  /* Queueing this cell would put queue over the cap */
  log_warn(LD_CIRC,
@@@ -2505,8 -2570,9 +2509,9 @@@
}
  }
}
+ #endif
  
 -  cell_queue_append_packed_copy(queue, cell);
 +  cell_queue_append_packed_copy(queue, cell, chan-wide_circ_ids);
  
/* If we have too many cells on the circuit, we should stop reading from
 * the edge streams for a while. */

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.4] Disable middle relay queue overfill detection code due to possible guard discovery attack

2013-06-15 Thread andrea
commit 2a95f3171681ee53c97ccba9d80f4454b462aaa7
Author: Andrea Shepard and...@torproject.org
Date:   Sat Jun 15 02:16:00 2013 -0700

Disable middle relay queue overfill detection code due to possible guard 
discovery attack
---
 changes/bug9072 |3 +++
 src/or/relay.c  |5 +
 2 files changed, 8 insertions(+)

diff --git a/changes/bug9072 b/changes/bug9072
new file mode 100644
index 000..e594a38
--- /dev/null
+++ b/changes/bug9072
@@ -0,0 +1,3 @@
+  o Critical bugfixes:
+- Disable middle relay queue overfill detection code due to possible
+  guard discovery attack, pending further analysis.  Fixes bug #9072.
diff --git a/src/or/relay.c b/src/or/relay.c
index 087459c..fdb4bff 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -2548,6 +2548,10 @@ append_cell_to_circuit_queue(circuit_t *circ, 
or_connection_t *orconn,
 streams_blocked = circ-streams_blocked_on_p_conn;
   }
 
+  /*
+   * Disabling this for now because of a possible guard discovery attack
+   */
+#if 0
   /* Are we a middle circuit about to exceed ORCIRC_MAX_MIDDLE_CELLS? */
   if ((circ-n_conn != NULL)  CIRCUIT_IS_ORCIRC(circ)) {
 orcirc = TO_OR_CIRCUIT(circ);
@@ -2566,6 +2570,7 @@ append_cell_to_circuit_queue(circuit_t *circ, 
or_connection_t *orconn,
   }
 }
   }
+#endif
 
   cell_queue_append_packed_copy(queue, cell);
 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Merge branch 'bug9072-023' into bug9072-024

2013-06-15 Thread andrea
commit 9e45d940d466bcefcd1490fc2ae0e5a6298a846f
Merge: 8b6d0bd 2a95f31
Author: Andrea Shepard and...@torproject.org
Date:   Sat Jun 15 02:20:19 2013 -0700

Merge branch 'bug9072-023' into bug9072-024

 changes/bug9072 |3 +++
 src/or/relay.c  |5 +
 2 files changed, 8 insertions(+)

diff --cc src/or/relay.c
index a26d418,fdb4bff..0f21663
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@@ -2474,18 -2540,22 +2474,22 @@@ append_cell_to_circuit_queue(circuit_t 
  return;
  
if (direction == CELL_DIRECTION_OUT) {
 -queue = circ-n_conn_cells;
 -streams_blocked = circ-streams_blocked_on_n_conn;
 +queue = circ-n_chan_cells;
 +streams_blocked = circ-streams_blocked_on_n_chan;
} else {
  orcirc = TO_OR_CIRCUIT(circ);
 -queue = orcirc-p_conn_cells;
 -streams_blocked = circ-streams_blocked_on_p_conn;
 +queue = orcirc-p_chan_cells;
 +streams_blocked = circ-streams_blocked_on_p_chan;
}
  
+   /*
+* Disabling this for now because of a possible guard discovery attack
+*/
+ #if 0
/* Are we a middle circuit about to exceed ORCIRC_MAX_MIDDLE_CELLS? */
 -  if ((circ-n_conn != NULL)  CIRCUIT_IS_ORCIRC(circ)) {
 +  if ((circ-n_chan != NULL)  CIRCUIT_IS_ORCIRC(circ)) {
  orcirc = TO_OR_CIRCUIT(circ);
 -if (orcirc-p_conn) {
 +if (orcirc-p_chan) {
if (queue-n + 1 = ORCIRC_MAX_MIDDLE_CELLS) {
  /* Queueing this cell would put queue over the cap */
  log_warn(LD_CIRC,
@@@ -2505,8 -2570,9 +2509,9 @@@
}
  }
}
+ #endif
  
 -  cell_queue_append_packed_copy(queue, cell);
 +  cell_queue_append_packed_copy(queue, cell, chan-wide_circ_ids);
  
/* If we have too many cells on the circuit, we should stop reading from
 * the edge streams for a while. */



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Disable middle relay queue overfill detection code due to possible guard discovery attack

2013-06-15 Thread andrea
commit 2a95f3171681ee53c97ccba9d80f4454b462aaa7
Author: Andrea Shepard and...@torproject.org
Date:   Sat Jun 15 02:16:00 2013 -0700

Disable middle relay queue overfill detection code due to possible guard 
discovery attack
---
 changes/bug9072 |3 +++
 src/or/relay.c  |5 +
 2 files changed, 8 insertions(+)

diff --git a/changes/bug9072 b/changes/bug9072
new file mode 100644
index 000..e594a38
--- /dev/null
+++ b/changes/bug9072
@@ -0,0 +1,3 @@
+  o Critical bugfixes:
+- Disable middle relay queue overfill detection code due to possible
+  guard discovery attack, pending further analysis.  Fixes bug #9072.
diff --git a/src/or/relay.c b/src/or/relay.c
index 087459c..fdb4bff 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -2548,6 +2548,10 @@ append_cell_to_circuit_queue(circuit_t *circ, 
or_connection_t *orconn,
 streams_blocked = circ-streams_blocked_on_p_conn;
   }
 
+  /*
+   * Disabling this for now because of a possible guard discovery attack
+   */
+#if 0
   /* Are we a middle circuit about to exceed ORCIRC_MAX_MIDDLE_CELLS? */
   if ((circ-n_conn != NULL)  CIRCUIT_IS_ORCIRC(circ)) {
 orcirc = TO_OR_CIRCUIT(circ);
@@ -2566,6 +2570,7 @@ append_cell_to_circuit_queue(circuit_t *circ, 
or_connection_t *orconn,
   }
 }
   }
+#endif
 
   cell_queue_append_packed_copy(queue, cell);
 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Merge branch 'bug9072-024' into bug9072-025

2013-06-15 Thread andrea
commit 469bd7a3cfbe6c5ca5c2602a10ee1854714e93c5
Merge: 7f67bec 9e45d94
Author: Andrea Shepard and...@torproject.org
Date:   Sat Jun 15 02:27:23 2013 -0700

Merge branch 'bug9072-024' into bug9072-025

 changes/bug9072 |3 +++
 src/or/relay.c  |   11 +++
 2 files changed, 14 insertions(+)

diff --cc src/or/relay.c
index 58ca4e9,0f21663..38776bc
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@@ -58,7 -58,6 +58,9 @@@ static void adjust_exit_policy_from_exi
entry_connection_t *conn,
node_t *node,
const tor_addr_t *addr);
++#if 0
 +static int get_max_middle_cells(void);
++#endif
  
  /** Stop reading on edge connections when we have this many cells
   * waiting on the appropriate queue. */
@@@ -2473,18 -2459,6 +2475,20 @@@ channel_flush_from_first_active_circuit
return n_flushed;
  }
  
++#if 0
 +/** Indicate the current preferred cap for middle circuits; zero disables
 + * the cap.  Right now it's just a constant, ORCIRC_MAX_MIDDLE_CELLS, but
 + * the logic in append_cell_to_circuit_queue() is written to be correct
 + * if we want to base it on a consensus param or something that might change
 + * in the future.
 + */
 +static int
 +get_max_middle_cells(void)
 +{
 +  return ORCIRC_MAX_MIDDLE_CELLS;
 +}
++#endif
 +
  /** Add bcell/b to the queue of bcirc/b writing to bchan/b
   * transmitting in bdirection/b. */
  void
@@@ -2495,7 -2469,6 +2499,9 @@@ append_cell_to_circuit_queue(circuit_t 
or_circuit_t *orcirc = NULL;
cell_queue_t *queue;
int streams_blocked;
++#if 0
 +  uint32_t tgt_max_middle_cells, p_len, n_len, tmp, hard_max_middle_cells;
++#endif
  
if (circ-marked_for_close)
  return;
@@@ -2585,8 -2509,9 +2595,9 @@@
}
  }
}
+ #endif
  
 -  cell_queue_append_packed_copy(queue, cell, chan-wide_circ_ids);
 +  cell_queue_append_packed_copy(queue, cell, chan-wide_circ_ids, 1);
  
/* If we have too many cells on the circuit, we should stop reading from
 * the edge streams for a while. */

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.4] Clean up ugly constants in connection_dir_download_cert_failed(), and fix a broken one

2013-05-10 Thread andrea
commit c0d96bae666c1dc0c16b4df69190fa126131aa65
Author: Andrea Shepard and...@torproject.org
Date:   Thu May 9 08:23:53 2013 -0700

Clean up ugly constants in connection_dir_download_cert_failed(), and fix a 
broken one
---
 src/or/directory.c |   13 -
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/or/directory.c b/src/or/directory.c
index 8dd5a7c..f65ac87 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -803,6 +803,8 @@ connection_dir_bridge_routerdesc_failed(dir_connection_t 
*conn)
 static void
 connection_dir_download_cert_failed(dir_connection_t *conn, int status)
 {
+  const char *fp_pfx = fp/;
+  const char *fpsk_pfx = fp-sk/;
   smartlist_t *failed;
   tor_assert(conn-_base.purpose == DIR_PURPOSE_FETCH_CERTIFICATE);
 
@@ -814,19 +816,20 @@ connection_dir_download_cert_failed(dir_connection_t 
*conn, int status)
* with fp/) or download by fingerprint/signing key pair
* (resource starts with fp-sk/).
*/
-  if (!strcmpstart(conn-requested_resource, fp/)) {
+  if (!strcmpstart(conn-requested_resource, fp_pfx)) {
 /* Download by fingerprint case */
-dir_split_resource_into_fingerprints(conn-requested_resource + 3,
+dir_split_resource_into_fingerprints(conn-requested_resource +
+ strlen(fp_pfx),
  failed, NULL, DSR_HEX);
 SMARTLIST_FOREACH_BEGIN(failed, char *, cp) {
   /* Null signing key digest indicates download by fp only */
   authority_cert_dl_failed(cp, NULL, status);
   tor_free(cp);
 } SMARTLIST_FOREACH_END(cp);
-  } else if (!strcmpstart(conn-requested_resource, fp-sk/)) {
+  } else if (!strcmpstart(conn-requested_resource, fpsk_pfx)) {
 /* Download by (fp,sk) pairs */
-dir_split_resource_into_fingerprint_pairs(conn-requested_resource + 5,
-  failed);
+dir_split_resource_into_fingerprint_pairs(conn-requested_resource +
+  strlen(fpsk_pfx), failed);
 SMARTLIST_FOREACH_BEGIN(failed, fp_pair_t *, cp) {
   authority_cert_dl_failed(cp-first, cp-second, status);
   tor_free(cp);



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.4] Use tor_asprintf() and clean up string handling in authority_certs_fetch_missing()

2013-05-10 Thread andrea
commit 2824bf3445448fee55a0f302d7ec85a5915e8f18
Author: Andrea Shepard and...@torproject.org
Date:   Thu May 9 09:31:39 2013 -0700

Use tor_asprintf() and clean up string handling in 
authority_certs_fetch_missing()
---
 src/or/routerlist.c |   58 ++
 1 files changed, 30 insertions(+), 28 deletions(-)

diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 15a71e4..8677400 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -791,23 +791,33 @@ authority_certs_fetch_missing(networkstatus_t *status, 
time_t now)
 
   /* Do downloads by identity digest */
   if (smartlist_len(missing_id_digests)  0) {
+int need_plus = 0;
 smartlist_t *fps = smartlist_new();
+
 smartlist_add(fps, tor_strdup(fp/));
 
-SMARTLIST_FOREACH(missing_id_digests, const char *, d, {
-  char *fp;
+SMARTLIST_FOREACH_BEGIN(missing_id_digests, const char *, d) {
+  char *fp = NULL;
+
   if (digestmap_get(pending_id, d))
 continue;
-  fp = tor_malloc(HEX_DIGEST_LEN+2);
-  base16_encode(fp, HEX_DIGEST_LEN+1, d, DIGEST_LEN);
-  fp[HEX_DIGEST_LEN] = '+';
-  fp[HEX_DIGEST_LEN+1] = '\0';
+
+  base16_encode(id_digest_str, sizeof(id_digest_str),
+d, DIGEST_LEN);
+
+  if (need_plus) {
+tor_asprintf(fp, +%s, id_digest_str);
+  } else {
+/* No need for tor_asprintf() in this case; first one gets no '+' */
+fp = tor_strdup(id_digest_str);
+need_plus = 1;
+  }
+
   smartlist_add(fps, fp);
-});
+} SMARTLIST_FOREACH_END(d);
 
 if (smartlist_len(fps)  1) {
   resource = smartlist_join_strings(fps, , 0, NULL);
-  resource[strlen(resource)-1] = '\0';
   directory_get_from_dirserver(DIR_PURPOSE_FETCH_CERTIFICATE, 0,
resource, PDS_RETRY_IF_NO_SERVERS);
   tor_free(resource);
@@ -820,46 +830,38 @@ authority_certs_fetch_missing(networkstatus_t *status, 
time_t now)
 
   /* Do downloads by identity digest/signing key pair */
   if (smartlist_len(missing_cert_digests)  0) {
+int need_plus = 0;
 smartlist_t *fp_pairs = smartlist_new();
-int need_plus = 0, offset = 0;
 
 smartlist_add(fp_pairs, tor_strdup(fp-sk/));
 
 SMARTLIST_FOREACH_BEGIN(missing_cert_digests, const fp_pair_t *, d) {
-  char *fp_pair;
+  char *fp_pair = NULL;
 
   if (fp_pair_map_get(pending_cert, d))
 continue;
 
-  fp_pair = tor_malloc(2*HEX_DIGEST_LEN+3);
-  offset = 0;
+  /* Construct string encodings of the digests */
+  base16_encode(id_digest_str, sizeof(id_digest_str),
+d-first, DIGEST_LEN);
+  base16_encode(sk_digest_str, sizeof(sk_digest_str),
+d-second, DIGEST_LEN);
+
+  /* Now tor_asprintf() */
   if (need_plus) {
-fp_pair[offset++] = '+';
+tor_asprintf(fp_pair, +%s-%s, id_digest_str, sk_digest_str);
   } else {
-/* Prepend a '+' to all but the first in the list */
+/* First one in the list doesn't get a '+' */
+tor_asprintf(fp_pair, %s-%s, id_digest_str, sk_digest_str);
 need_plus = 1;
   }
 
-  /* Encode the first fingerprint */
-  base16_encode(fp_pair + offset, HEX_DIGEST_LEN+1,
-d-first, DIGEST_LEN);
-  offset += HEX_DIGEST_LEN;
-  /* Add a '-' to separate them */
-  fp_pair[offset++] = '-';
-  /* Encode the second fingerprint */
-  base16_encode(fp_pair + offset, HEX_DIGEST_LEN+1,
-d-second, DIGEST_LEN);
-  offset += HEX_DIGEST_LEN;
-  /* Add a NUL */
-  fp_pair[offset++] = '\0';
-
   /* Add it to the list of pairs to request */
   smartlist_add(fp_pairs, fp_pair);
 } SMARTLIST_FOREACH_END(d);
 
 if (smartlist_len(fp_pairs)  1) {
   resource = smartlist_join_strings(fp_pairs, , 0, NULL);
-  resource[strlen(resource)-1] = '\0';
   directory_get_from_dirserver(DIR_PURPOSE_FETCH_CERTIFICATE, 0,
resource, PDS_RETRY_IF_NO_SERVERS);
   tor_free(resource);



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.4] Rephrase comment in trusted_dirs_load_certs_from_string() to reflect 5595 fix

2013-05-10 Thread andrea
commit ac73ceb72858da1b77406988036b15362111b8a1
Author: Andrea Shepard and...@torproject.org
Date:   Thu May 9 09:41:50 2013 -0700

Rephrase comment in trusted_dirs_load_certs_from_string() to reflect 5595 
fix
---
 src/or/routerlist.c |   10 +++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 14c44ec..aa1660f 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -309,9 +309,13 @@ trusted_dirs_load_certs_from_string(const char *contents, 
int source,
from_store ? cached : downloaded,
ds ? ds-nickname : an old or new authority);
 
-  /* a duplicate on a download should be treated as a failure, since it
-   * probably means we wanted a different secret key or we are trying to
-   * replace an expired cert that has not in fact been updated. */
+  /*
+   * A duplicate on download should be treated as a failure, so we call
+   * authority_cert_dl_failed() to reset the download status to make sure
+   * we can't try again.  Since we've implemented the fp-sk mechanism
+   * to download certs by signing key, this should be much rarer than it
+   * was and is perhaps cause for concern.
+   */
   if (!from_store) {
 if (authdir_mode(get_options())) {
   log_warn(LD_DIR,



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.4] Make warning in authority_cert_dl_failed() LD_BUG per NickM code review

2013-05-10 Thread andrea
commit 17692b2fe2f9fd7c33461c981b8d2eb511976758
Author: Andrea Shepard and...@torproject.org
Date:   Thu May 9 09:33:32 2013 -0700

Make warning in authority_cert_dl_failed() LD_BUG per NickM code review
---
 src/or/routerlist.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 8677400..14c44ec 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -593,7 +593,7 @@ authority_cert_dl_failed(const char *id_digest,
 id_digest, DIGEST_LEN);
   base16_encode(sk_digest_str, sizeof(sk_digest_str),
 signing_key_digest, DIGEST_LEN);
-  log_warn(LD_DIR,
+  log_warn(LD_BUG,
Got failure for cert fetch with (fp,sk) = (%s,%s), with 
status %d, but knew nothing about the download.,
id_digest_str, sk_digest_str, status);



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.4] Add some unit tests for fp_pair_map_t to test/containers.c based on the strmap tests

2013-05-10 Thread andrea
commit 54f41d68e9e30ccd0ebd84a3f8e913ea9e923cfd
Author: Andrea Shepard and...@torproject.org
Date:   Thu May 9 10:51:48 2013 -0700

Add some unit tests for fp_pair_map_t to test/containers.c based on the 
strmap tests
---
 src/test/test_containers.c |   84 
 1 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/src/test/test_containers.c b/src/test/test_containers.c
index 45898df..5fee5c9 100644
--- a/src/test/test_containers.c
+++ b/src/test/test_containers.c
@@ -5,6 +5,7 @@
 
 #include orconfig.h
 #include or.h
+#include fp_pair.h
 #include test.h
 
 /** Helper: return a tristate based on comparing the strings in *ba/b and
@@ -782,6 +783,88 @@ test_container_order_functions(void)
   ;
 }
 
+/** Run unit tests for fp_pair-to-void* map functions */
+static void
+test_container_fp_pair_map(void)
+{
+  fp_pair_map_t *map;
+  fp_pair_t fp1, fp2, fp3, fp4, fp5, fp6;
+  void *v;
+  fp_pair_map_iter_t *iter;
+  fp_pair_t k;
+
+  map = fp_pair_map_new();
+  test_assert(map);
+  test_eq(fp_pair_map_size(map), 0);
+  test_assert(fp_pair_map_isempty(map));
+
+  memset(fp1.first, 0x11, DIGEST_LEN);
+  memset(fp1.second, 0x12, DIGEST_LEN);
+  memset(fp2.first, 0x21, DIGEST_LEN);
+  memset(fp2.second, 0x22, DIGEST_LEN);
+  memset(fp3.first, 0x31, DIGEST_LEN);
+  memset(fp3.second, 0x32, DIGEST_LEN);
+  memset(fp4.first, 0x41, DIGEST_LEN);
+  memset(fp4.second, 0x42, DIGEST_LEN);
+  memset(fp5.first, 0x51, DIGEST_LEN);
+  memset(fp5.second, 0x52, DIGEST_LEN);
+  memset(fp6.first, 0x61, DIGEST_LEN);
+  memset(fp6.second, 0x62, DIGEST_LEN);
+
+  v = fp_pair_map_set(map, fp1, (void*)99);
+  test_eq(v, NULL);
+  test_assert(!fp_pair_map_isempty(map));
+  v = fp_pair_map_set(map, fp2, (void*)101);
+  test_eq(v, NULL);
+  v = fp_pair_map_set(map, fp1, (void*)100);
+  test_eq(v, (void*)99);
+  test_eq_ptr(fp_pair_map_get(map, fp1), (void*)100);
+  test_eq_ptr(fp_pair_map_get(map, fp2), (void*)101);
+  test_eq_ptr(fp_pair_map_get(map, fp3), NULL);
+  fp_pair_map_assert_ok(map);
+
+  v = fp_pair_map_remove(map, fp2);
+  fp_pair_map_assert_ok(map);
+  test_eq_ptr(v, (void*)101);
+  test_eq_ptr(fp_pair_map_get(map, fp2), NULL);
+  test_eq_ptr(fp_pair_map_remove(map, fp2), NULL);
+
+  fp_pair_map_set(map, fp2, (void*)101);
+  fp_pair_map_set(map, fp3, (void*)102);
+  fp_pair_map_set(map, fp4, (void*)103);
+  test_eq(fp_pair_map_size(map), 4);
+  fp_pair_map_assert_ok(map);
+  fp_pair_map_set(map, fp5, (void*)104);
+  fp_pair_map_set(map, fp6, (void*)105);
+  fp_pair_map_assert_ok(map);
+
+  /* Test iterator. */
+  iter = fp_pair_map_iter_init(map);
+  while (!fp_pair_map_iter_done(iter)) {
+fp_pair_map_iter_get(iter, k, v);
+test_eq_ptr(v, fp_pair_map_get(map, k));
+
+if (tor_memeq(fp2, k, sizeof(fp2))) {
+  iter = fp_pair_map_iter_next_rmv(map, iter);
+} else {
+  iter = fp_pair_map_iter_next(map, iter);
+}
+  }
+
+  /* Make sure we removed fp2, but not the others. */
+  test_eq_ptr(fp_pair_map_get(map, fp2), NULL);
+  test_eq_ptr(fp_pair_map_get(map, fp5), (void*)104);
+
+  fp_pair_map_assert_ok(map);
+  /* Clean up after ourselves. */
+  fp_pair_map_free(map, NULL);
+  map = NULL;
+
+ done:
+  if (map)
+fp_pair_map_free(map, NULL);
+}
+
 #define CONTAINER_LEGACY(name)  \
   { #name, legacy_test_helper, 0, legacy_setup, test_container_ ## name }
 
@@ -796,6 +879,7 @@ struct testcase_t container_tests[] = {
   CONTAINER_LEGACY(strmap),
   CONTAINER_LEGACY(pqueue),
   CONTAINER_LEGACY(order_functions),
+  CONTAINER_LEGACY(fp_pair_map),
   END_OF_TESTCASES
 };
 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.4] Merge bug5595-v2-squashed into maint-0.2.4

2013-05-10 Thread andrea
commit aaa3a085db05c4d98b7c51b5ef16da166e7c7f0a
Merge: bae5dd6 54f41d6
Author: Andrea Shepard and...@torproject.org
Date:   Fri May 10 19:39:48 2013 -0700

Merge bug5595-v2-squashed into maint-0.2.4

 changes/bug5595|8 +
 src/or/Makefile.nmake  |1 +
 src/or/directory.c |   73 +--
 src/or/dirvote.c   |2 +-
 src/or/fp_pair.c   |  308 ++
 src/or/fp_pair.h   |   45 
 src/or/include.am  |2 +
 src/or/router.c|3 +-
 src/or/routerlist.c|  516 
 src/or/routerlist.h|   18 ++-
 src/test/test_containers.c |   84 +++
 11 files changed, 949 insertions(+), 111 deletions(-)

diff --cc src/or/Makefile.nmake
index d67123a,146866e..3b627b1
--- a/src/or/Makefile.nmake
+++ b/src/or/Makefile.nmake
@@@ -1,74 -1,28 +1,75 @@@
  all: tor.exe
  
 -CFLAGS = /I ..\win32 /I ..\..\..\build-alpha\include /I ..\common
 +CFLAGS = /I ..\win32 /I ..\..\..\build-alpha\include /I ..\common \
 +/I ..\ext
  
 -LIBS = ..\..\..\build-alpha\lib\libevent.a \
 - ..\..\..\build-alpha\lib\libcrypto.a \
 - ..\..\..\build-alpha\lib\libssl.a \
 - ..\..\..\build-alpha\lib\libz.a \
 - ws2_32.lib advapi32.lib shell32.lib
 +LIBS = ..\..\..\build-alpha\lib\libevent.lib \
 + ..\..\..\build-alpha\lib\libcrypto.lib \
 + ..\..\..\build-alpha\lib\libssl.lib \
 + ..\..\..\build-alpha\lib\libz.lib \
 + ws2_32.lib advapi32.lib shell32.lib \
 + crypt32.lib gdi32.lib user32.lib
  
 -LIBTOR_OBJECTS = buffers.obj circuitbuild.obj circuitlist.obj circuituse.obj \
 -  command.obj config.obj connection.obj connection_edge.obj \
 -  connection_or.obj control.obj cpuworker.obj directory.obj \
 -  dirserv.obj dirvote.obj dns.obj dnsserv.obj fp_pair.obj geoip.obj \
 -  hibernate.obj main.obj microdesc.obj networkstatus.obj \
 -  nodelist.obj onion.obj policies.obj reasons.obj relay.obj \
 -  rendclient.obj rendcommon.obj rendmid.obj rendservice.obj \
 -  rephist.obj router.obj routerlist.obj routerparse.obj status.obj \
 -  config_codedigest.obj ntmain.obj
 +LIBTOR_OBJECTS = \
 +  addressmap.obj \
 +  buffers.obj \
 +  channel.obj \
 +  channeltls.obj \
 +  circuitbuild.obj \
 +  circuitlist.obj \
 +  circuitmux.obj \
 +  circuitmux_ewma.obj \
 +  circuitstats.obj \
 +  circuituse.obj \
 +  command.obj \
 +  config.obj \
 +  config_codedigest.obj \
 +  confparse.obj \
 +  connection.obj \
 +  connection_edge.obj \
 +  connection_or.obj \
 +  control.obj \
 +  cpuworker.obj \
 +  directory.obj \
 +  dirserv.obj \
 +  dirvote.obj \
 +  dns.obj \
 +  dnsserv.obj \
++  fp_pair.obj \
 +  entrynodes.obj \
 +  geoip.obj \
 +  hibernate.obj \
 +  main.obj \
 +  microdesc.obj \
 +  networkstatus.obj \
 +  nodelist.obj \
 +  ntmain.obj \
 +  onion.obj \
 +  onion_fast.obj \
 +  onion_ntor.obj \
 +  onion_tap.obj \
 +  policies.obj \
 +  reasons.obj \
 +  relay.obj \
 +  rendclient.obj \
 +  rendcommon.obj \
 +  rendmid.obj \
 +  rendservice.obj \
 +  rephist.obj \
 +  replaycache.obj \
 +  router.obj \
 +  routerlist.obj \
 +  routerparse.obj \
 +  routerset.obj \
 +  statefile.obj \
 +  status.obj \
 +  transports.obj
  
  libtor.lib: $(LIBTOR_OBJECTS)
 -  lib $(LIBTOR_OBJECTS) /out:libtor.lib
 +  lib $(LIBTOR_OBJECTS) /out:$@
  
  tor.exe: libtor.lib tor_main.obj
 -  $(CC) $(CFLAGS) $(LIBS) libtor.lib ..\common\*.lib tor_main.obj
 +  $(CC) $(CFLAGS) $(LIBS) libtor.lib ..\common\*.lib tor_main.obj /Fe$@
  
  clean:
del $(LIBTOR_OBJECTS) *.lib tor.exe
diff --cc src/or/directory.c
index 38a423c,f65ac87..b4381ac
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@@ -856,8 -803,10 +856,10 @@@ connection_dir_bridge_routerdesc_failed
  static void
  connection_dir_download_cert_failed(dir_connection_t *conn, int status)
  {
+   const char *fp_pfx = fp/;
+   const char *fpsk_pfx = fp-sk/;
smartlist_t *failed;
 -  tor_assert(conn-_base.purpose == DIR_PURPOSE_FETCH_CERTIFICATE);
 +  tor_assert(conn-base_.purpose == DIR_PURPOSE_FETCH_CERTIFICATE);
  
if (!conn-requested_resource)
  return;
@@@ -1629,11 -1608,12 +1653,12 @@@ connection_dir_client_reached_eof(dir_c
compress_method_t compression;
int plausible;
int skewed=0;
 -  int allow_partial = (conn-_base.purpose == DIR_PURPOSE_FETCH_SERVERDESC ||
 -   conn-_base.purpose == DIR_PURPOSE_FETCH_EXTRAINFO ||
 -   conn-_base.purpose == DIR_PURPOSE_FETCH_MICRODESC);
 +  int allow_partial = (conn-base_.purpose == DIR_PURPOSE_FETCH_SERVERDESC ||
 +   conn-base_.purpose == DIR_PURPOSE_FETCH_EXTRAINFO ||
 +   conn-base_.purpose == DIR_PURPOSE_FETCH_MICRODESC);
int was_compressed=0;
time_t now = time(NULL);
+   int src_code;
  
switch (connection_fetch_from_buf_http(TO_CONN(conn),
headers, MAX_HEADERS_SIZE,
@@@ -1901,18 -1881,37 +1926,38 @@@
return -1

[tor-commits] [tor/master] Implement fp_pair_map_t

2013-05-10 Thread andrea
commit d5bd4a4763dfa74572ce6ed0b565315c43ff9f87
Author: Andrea Shepard and...@torproject.org
Date:   Fri Mar 22 12:13:25 2013 -0700

Implement fp_pair_map_t
---
 src/or/Makefile.am|2 +
 src/or/Makefile.nmake |2 +-
 src/or/fp_pair.c  |  308 +
 src/or/fp_pair.h  |   45 +++
 4 files changed, 356 insertions(+), 1 deletions(-)

diff --git a/src/or/Makefile.am b/src/or/Makefile.am
index 3cc789a..813227f 100644
--- a/src/or/Makefile.am
+++ b/src/or/Makefile.am
@@ -32,6 +32,7 @@ libtor_a_SOURCES = \
dirvote.c   \
dns.c   \
dnsserv.c   \
+   fp_pair.c   \
geoip.c \
hibernate.c \
main.c  \
@@ -96,6 +97,7 @@ noinst_HEADERS = \
dnsserv.h   \
eventdns.h  \
eventdns_tor.h  \
+   fp_pair.h   \
geoip.h \
hibernate.h \
main.h  \
diff --git a/src/or/Makefile.nmake b/src/or/Makefile.nmake
index 3181e79..146866e 100644
--- a/src/or/Makefile.nmake
+++ b/src/or/Makefile.nmake
@@ -11,7 +11,7 @@ LIBS = ..\..\..\build-alpha\lib\libevent.a \
 LIBTOR_OBJECTS = buffers.obj circuitbuild.obj circuitlist.obj circuituse.obj \
command.obj config.obj connection.obj connection_edge.obj \
connection_or.obj control.obj cpuworker.obj directory.obj \
-   dirserv.obj dirvote.obj dns.obj dnsserv.obj geoip.obj \
+   dirserv.obj dirvote.obj dns.obj dnsserv.obj fp_pair.obj geoip.obj \
hibernate.obj main.obj microdesc.obj networkstatus.obj \
nodelist.obj onion.obj policies.obj reasons.obj relay.obj \
rendclient.obj rendcommon.obj rendmid.obj rendservice.obj \
diff --git a/src/or/fp_pair.c b/src/or/fp_pair.c
new file mode 100644
index 000..4d8a835
--- /dev/null
+++ b/src/or/fp_pair.c
@@ -0,0 +1,308 @@
+/* Copyright (c) 2013, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#include or.h
+#include fp_pair.h
+
+/* Define fp_pair_map_t structures */
+
+struct fp_pair_map_entry_s {
+  HT_ENTRY(fp_pair_map_entry_s) node;
+  void *val;
+  fp_pair_t key;
+};
+
+struct fp_pair_map_s {
+  HT_HEAD(fp_pair_map_impl, fp_pair_map_entry_s) head;
+};
+
+/*
+ * Hash function and equality checker for fp_pair_map_t
+ */
+
+/** Compare fp_pair_entry_t objects by key value. */
+static INLINE int
+fp_pair_map_entries_eq(const fp_pair_map_entry_t *a,
+   const fp_pair_map_entry_t *b)
+{
+  return tor_memeq((a-key), (b-key), sizeof(fp_pair_t));
+}
+
+/** Return a hash value for an fp_pair_entry_t. */
+static INLINE unsigned int
+fp_pair_map_entry_hash(const fp_pair_map_entry_t *a)
+{
+  const uint32_t *p;
+  unsigned int hash;
+
+  p = (const uint32_t *)(a-key.first);
+  /* Hashes are 20 bytes long, so 5 times uint32_t */
+  hash = p[0] ^ p[1] ^ p[2] ^ p[3] ^ p[4];
+  /* Now XOR in the second fingerprint */
+  p = (const uint32_t *)(a-key.second);
+  hash ^= p[0] ^ p[1] ^ p[2] ^ p[3] ^ p[4];
+
+  return hash;
+}
+
+/*
+ * Hash table functions for fp_pair_map_t
+ */
+
+HT_PROTOTYPE(fp_pair_map_impl, fp_pair_map_entry_s, node,
+ fp_pair_map_entry_hash, fp_pair_map_entries_eq)
+HT_GENERATE(fp_pair_map_impl, fp_pair_map_entry_s, node,
+fp_pair_map_entry_hash, fp_pair_map_entries_eq,
+0.6, tor_malloc, tor_realloc, tor_free)
+
+/** Constructor to create a new empty map from fp_pair_t to void *
+ */
+
+fp_pair_map_t *
+fp_pair_map_new(void)
+{
+  fp_pair_map_t *result;
+
+  result = tor_malloc(sizeof(fp_pair_map_t));
+  HT_INIT(fp_pair_map_impl, result-head);
+  return result;
+}
+
+/** Set the current value for key to val; returns the previous
+ * value for key if one was set, or NULL if one was not.
+ */
+
+void *
+fp_pair_map_set(fp_pair_map_t *map, const fp_pair_t *key, void *val)
+{
+  fp_pair_map_entry_t *resolve;
+  fp_pair_map_entry_t search;
+  void *oldval;
+
+  tor_assert(map);
+  tor_assert(key);
+  tor_assert(val);
+
+  memcpy((search.key), key, sizeof(*key));
+  resolve = HT_FIND(fp_pair_map_impl, (map-head), search);
+  if (resolve) {
+oldval = resolve-val;
+resolve-val = val;
+  } else {
+resolve = tor_malloc_zero(sizeof(fp_pair_map_entry_t));
+memcpy((resolve-key), key, sizeof(*key));
+resolve-val = val;
+HT_INSERT(fp_pair_map_impl, (map-head), resolve);
+oldval = NULL;
+  }
+
+  return oldval;
+}
+
+/** Set the current value for the key (first, second) to val; returns
+ * the previous value for key if one was set, or NULL if one was not.
+ */
+
+void *
+fp_pair_map_set_by_digests(fp_pair_map_t *map

[tor-commits] [tor/master] Add some unit tests for fp_pair_map_t to test/containers.c based on the strmap tests

2013-05-10 Thread andrea
commit 54f41d68e9e30ccd0ebd84a3f8e913ea9e923cfd
Author: Andrea Shepard and...@torproject.org
Date:   Thu May 9 10:51:48 2013 -0700

Add some unit tests for fp_pair_map_t to test/containers.c based on the 
strmap tests
---
 src/test/test_containers.c |   84 
 1 files changed, 84 insertions(+), 0 deletions(-)

diff --git a/src/test/test_containers.c b/src/test/test_containers.c
index 45898df..5fee5c9 100644
--- a/src/test/test_containers.c
+++ b/src/test/test_containers.c
@@ -5,6 +5,7 @@
 
 #include orconfig.h
 #include or.h
+#include fp_pair.h
 #include test.h
 
 /** Helper: return a tristate based on comparing the strings in *ba/b and
@@ -782,6 +783,88 @@ test_container_order_functions(void)
   ;
 }
 
+/** Run unit tests for fp_pair-to-void* map functions */
+static void
+test_container_fp_pair_map(void)
+{
+  fp_pair_map_t *map;
+  fp_pair_t fp1, fp2, fp3, fp4, fp5, fp6;
+  void *v;
+  fp_pair_map_iter_t *iter;
+  fp_pair_t k;
+
+  map = fp_pair_map_new();
+  test_assert(map);
+  test_eq(fp_pair_map_size(map), 0);
+  test_assert(fp_pair_map_isempty(map));
+
+  memset(fp1.first, 0x11, DIGEST_LEN);
+  memset(fp1.second, 0x12, DIGEST_LEN);
+  memset(fp2.first, 0x21, DIGEST_LEN);
+  memset(fp2.second, 0x22, DIGEST_LEN);
+  memset(fp3.first, 0x31, DIGEST_LEN);
+  memset(fp3.second, 0x32, DIGEST_LEN);
+  memset(fp4.first, 0x41, DIGEST_LEN);
+  memset(fp4.second, 0x42, DIGEST_LEN);
+  memset(fp5.first, 0x51, DIGEST_LEN);
+  memset(fp5.second, 0x52, DIGEST_LEN);
+  memset(fp6.first, 0x61, DIGEST_LEN);
+  memset(fp6.second, 0x62, DIGEST_LEN);
+
+  v = fp_pair_map_set(map, fp1, (void*)99);
+  test_eq(v, NULL);
+  test_assert(!fp_pair_map_isempty(map));
+  v = fp_pair_map_set(map, fp2, (void*)101);
+  test_eq(v, NULL);
+  v = fp_pair_map_set(map, fp1, (void*)100);
+  test_eq(v, (void*)99);
+  test_eq_ptr(fp_pair_map_get(map, fp1), (void*)100);
+  test_eq_ptr(fp_pair_map_get(map, fp2), (void*)101);
+  test_eq_ptr(fp_pair_map_get(map, fp3), NULL);
+  fp_pair_map_assert_ok(map);
+
+  v = fp_pair_map_remove(map, fp2);
+  fp_pair_map_assert_ok(map);
+  test_eq_ptr(v, (void*)101);
+  test_eq_ptr(fp_pair_map_get(map, fp2), NULL);
+  test_eq_ptr(fp_pair_map_remove(map, fp2), NULL);
+
+  fp_pair_map_set(map, fp2, (void*)101);
+  fp_pair_map_set(map, fp3, (void*)102);
+  fp_pair_map_set(map, fp4, (void*)103);
+  test_eq(fp_pair_map_size(map), 4);
+  fp_pair_map_assert_ok(map);
+  fp_pair_map_set(map, fp5, (void*)104);
+  fp_pair_map_set(map, fp6, (void*)105);
+  fp_pair_map_assert_ok(map);
+
+  /* Test iterator. */
+  iter = fp_pair_map_iter_init(map);
+  while (!fp_pair_map_iter_done(iter)) {
+fp_pair_map_iter_get(iter, k, v);
+test_eq_ptr(v, fp_pair_map_get(map, k));
+
+if (tor_memeq(fp2, k, sizeof(fp2))) {
+  iter = fp_pair_map_iter_next_rmv(map, iter);
+} else {
+  iter = fp_pair_map_iter_next(map, iter);
+}
+  }
+
+  /* Make sure we removed fp2, but not the others. */
+  test_eq_ptr(fp_pair_map_get(map, fp2), NULL);
+  test_eq_ptr(fp_pair_map_get(map, fp5), (void*)104);
+
+  fp_pair_map_assert_ok(map);
+  /* Clean up after ourselves. */
+  fp_pair_map_free(map, NULL);
+  map = NULL;
+
+ done:
+  if (map)
+fp_pair_map_free(map, NULL);
+}
+
 #define CONTAINER_LEGACY(name)  \
   { #name, legacy_test_helper, 0, legacy_setup, test_container_ ## name }
 
@@ -796,6 +879,7 @@ struct testcase_t container_tests[] = {
   CONTAINER_LEGACY(strmap),
   CONTAINER_LEGACY(pqueue),
   CONTAINER_LEGACY(order_functions),
+  CONTAINER_LEGACY(fp_pair_map),
   END_OF_TESTCASES
 };
 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/maint-0.2.4] Use a clearer idiom for node identity in router_counts_toward_thresholds

2013-05-07 Thread andrea
commit a1d7f7ea503f2f739953d6a25ebb5d93981604be
Author: Nick Mathewson ni...@torproject.org
Date:   Sun May 5 18:55:19 2013 -0400

Use a clearer idiom for node identity in router_counts_toward_thresholds
---
 src/or/dirserv.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 16f297a..8f6d9ec 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -1898,7 +1898,7 @@ router_counts_toward_thresholds(const node_t *node, 
time_t now,
   }
 
   return node-ri  router_is_active(node-ri, node, now) 
-!digestmap_get(omit_as_sybil, node-ri-cache_info.identity_digest) 
+!digestmap_get(omit_as_sybil, node-identity) 
 (dirserv_get_credible_bandwidth_kb(node-ri) = min_bw_kb) 
 (have_mbw || !require_mbw);
 }

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Use a clearer idiom for node identity in router_counts_toward_thresholds

2013-05-07 Thread andrea
commit a1d7f7ea503f2f739953d6a25ebb5d93981604be
Author: Nick Mathewson ni...@torproject.org
Date:   Sun May 5 18:55:19 2013 -0400

Use a clearer idiom for node identity in router_counts_toward_thresholds
---
 src/or/dirserv.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 16f297a..8f6d9ec 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -1898,7 +1898,7 @@ router_counts_toward_thresholds(const node_t *node, 
time_t now,
   }
 
   return node-ri  router_is_active(node-ri, node, now) 
-!digestmap_get(omit_as_sybil, node-ri-cache_info.identity_digest) 
+!digestmap_get(omit_as_sybil, node-identity) 
 (dirserv_get_credible_bandwidth_kb(node-ri) = min_bw_kb) 
 (have_mbw || !require_mbw);
 }



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Merge branch 'maint-0.2.4' into master

2013-05-07 Thread andrea
commit 9c58905a2bfd1049613173c27c357e8a20ff066a
Merge: ef83db4 a1d7f7e
Author: Andrea Shepard and...@torproject.org
Date:   Tue May 7 02:24:08 2013 -0700

Merge branch 'maint-0.2.4' into master

 changes/bug8833  |3 +++
 src/or/dirserv.c |6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Fix 8833: crash bug from using NULL node-ri in dirserv.c

2013-05-07 Thread andrea
commit 139d367f297575a59b96b64a633ed2b6988d60e1
Author: Nick Mathewson ni...@torproject.org
Date:   Sun May 5 18:52:53 2013 -0400

Fix 8833: crash bug from using NULL node-ri in dirserv.c

It appears that moria1 crashed because of one instance of this (the
one in router_counts_toward_thresholds).  The other instance I fixed
won't actually have broken anything, but I think it's more clear this
way.

Fixes bug 8833; bugfix on 0.2.4.12-alpha.
---
 changes/bug8833  |3 +++
 src/or/dirserv.c |4 ++--
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/changes/bug8833 b/changes/bug8833
new file mode 100644
index 000..681a861
--- /dev/null
+++ b/changes/bug8833
@@ -0,0 +1,3 @@
+  o Major bugfixes (directory authority):
+- Fix a crash bug when building a consensus using an older consensus as
+  its basis. Fixes bug 8833. Bugfix on 0.2.4.12-alpha.
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 66a2c14..16f297a 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -1889,7 +1889,7 @@ router_counts_toward_thresholds(const node_t *node, 
time_t now,
 {
   /* Have measured bw? */
   int have_mbw =
-dirserv_has_measured_bw(node-ri-cache_info.identity_digest);
+dirserv_has_measured_bw(node-identity);
   uint64_t min_bw_kb = ABSOLUTE_MIN_BW_VALUE_TO_CONSIDER_KB;
   const or_options_t *options = get_options();
 
@@ -1959,7 +1959,7 @@ dirserv_compute_performance_thresholds(routerlist_t *rl,
 if (router_counts_toward_thresholds(node, now, omit_as_sybil,
 require_mbw)) {
   routerinfo_t *ri = node-ri;
-  const char *id = ri-cache_info.identity_digest;
+  const char *id = node-identity;
   uint32_t bw_kb;
   node-is_exit = (!router_exit_policy_rejects_all(ri) 
exit_policy_is_general_exit(ri-exit_policy));



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Don't immediately count cannibalized circs as used.

2013-01-28 Thread andrea
commit a2db17a1aab77c4183f589815800a779a5f24524
Author: Mike Perry mikeperry-...@fscked.org
Date:   Fri Jan 18 19:34:01 2013 -0800

Don't immediately count cannibalized circs as used.

Since they use RELAY_EARLY (which can be seen by all hops on the path),
it's not safe to say they actually count as a successful use.

There are also problems with trying to allow them to finish extending due to
the circuit purpose state machine logic. It is way less complicated (and
possibly more semantically coherent) to simply wait until we actually try to
do something with them before claiming we 'used' them.

Also, we shouldn't call timed out circuits 'used' either, for semantic
consistency.
---
 src/or/circuitbuild.c |7 +--
 src/or/circuituse.c   |   14 +-
 2 files changed, 2 insertions(+), 19 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 435ccd9..8880f14 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -823,9 +823,6 @@ circuit_send_next_onion_skin(origin_circuit_t *circ)
 
   /* We're done with measurement circuits here. Just close them */
   if (circ-base_.purpose == CIRCUIT_PURPOSE_C_MEASURE_TIMEOUT) {
-/* If a measurement circ ever gets back to us, consider it
- * succeeded for path bias */
-circ-path_state = PATH_STATE_USE_SUCCEEDED;
 circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_FINISHED);
   }
   return 0;
@@ -3140,9 +3137,7 @@ circuit_extend_to_new_exit(origin_circuit_t *circ, 
extend_info_t *exit)
 return -1;
   }
 
-  /* Set timestamp_dirty, so we can check it for path use bias */
-  if (!circ-base_.timestamp_dirty)
-circ-base_.timestamp_dirty = time(NULL);
+  // XXX: Should cannibalized circuits be dirty or not? Not easy to say..
 
   return 0;
 }
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index d0b1b49..0b2fe9e 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -668,18 +668,6 @@ circuit_expire_building(void)
   circuit_build_times_set_timeout(circ_times);
 }
   }
-
-  if (TO_ORIGIN_CIRCUIT(victim)-has_opened 
-  victim-purpose != CIRCUIT_PURPOSE_PATH_BIAS_TESTING) {
-/* For path bias: we want to let these guys live for a while
- * so we get a chance to test them. */
-log_info(LD_CIRC,
- Allowing cannibalized circuit %d time to finish building 
- as a pathbias testing circ.,
- TO_ORIGIN_CIRCUIT(victim)-global_identifier);
-circuit_change_purpose(victim, CIRCUIT_PURPOSE_PATH_BIAS_TESTING);
-continue; /* It now should have a longer timeout next time */
-  }
 }
 
 /* If this is a hidden service client circuit which is far enough
@@ -1517,7 +1505,7 @@ circuit_launch_by_extend_info(uint8_t purpose,
  * If we decide to probe the initial portion of these circs,
  * (up to the adversaries final hop), we need to remove this.
  */
-circ-path_state = PATH_STATE_USE_SUCCEEDED;
+
 /* This must be called before the purpose change */
 pathbias_check_close(circ, END_CIRC_REASON_FINISHED);
   }



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Remove a source of error during path bias scaling

2013-01-28 Thread andrea
commit d80b881a52644fc05a65c0ff440449ea4c82c61b
Author: Mike Perry mikeperry-...@fscked.org
Date:   Fri Jan 18 20:17:23 2013 -0800

Remove a source of error during path bias scaling

If any circuits were opened during a scaling event, we were scaling attempts
and successes by different amounts. This leads to rounding error.

The fix is to record how many circuits are in a state that hasn't been fully
counted yet, and subtract that before scaling, and add it back afterwords.
---
 src/or/circuitbuild.c |   98 +---
 1 files changed, 51 insertions(+), 47 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 8880f14..8c7bd87 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -2071,20 +2071,20 @@ pathbias_count_timeout(origin_circuit_t *circ)
 }
 
 /**
- * Return the number of circuits counted as successfully closed for
- * this guard.
- *
- * Also add in the currently open circuits to give them the benefit
- * of the doubt.
+ * Helper function to count all of the currently opened circuits
+ * for a guard that are in a given path state range. The state
+ * range is inclusive on both ends.
  */
-double
-pathbias_get_close_success_count(entry_guard_t *guard)
+static int
+pathbias_count_circs_in_states(entry_guard_t *guard,
+  path_state_t from,
+  path_state_t to)
 {
-  circuit_t *circ;
+  circuit_t *circ = global_circuitlist;
   int open_circuits = 0;
 
-  /* Count currently open circuits. Give them the benefit of the doubt. */
-  for (circ = global_circuitlist; circ; circ = circ-next) {
+  /* Count currently open circuits. Give them the benefit of the doubt */
+  for ( ; circ; circ = circ-next) {
 origin_circuit_t *ocirc = NULL;
 if (!CIRCUIT_IS_ORIGIN(circ) || /* didn't originate here */
 circ-marked_for_close) /* already counted */
@@ -2095,20 +2095,33 @@ pathbias_get_close_success_count(entry_guard_t *guard)
 if (!ocirc-cpath || !ocirc-cpath-extend_info)
   continue;
 
-/* Don't count known failed or already counted circuits */
-if (ocirc-path_state = PATH_STATE_USE_FAILED)
-  continue;
-
-if (ocirc-path_state = PATH_STATE_BUILD_SUCCEEDED 
+if (ocirc-path_state = from 
+ocirc-path_state = to 
 pathbias_should_count(ocirc) 
 fast_memeq(guard-identity,
-   ocirc-cpath-extend_info-identity_digest,
-   DIGEST_LEN)) {
+ocirc-cpath-extend_info-identity_digest,
+DIGEST_LEN)) {
   open_circuits++;
 }
   }
 
-  return guard-successful_circuits_closed + open_circuits;
+  return open_circuits;
+}
+
+/**
+ * Return the number of circuits counted as successfully closed for
+ * this guard.
+ *
+ * Also add in the currently open circuits to give them the benefit
+ * of the doubt.
+ */
+double
+pathbias_get_close_success_count(entry_guard_t *guard)
+{
+  return guard-successful_circuits_closed +
+ pathbias_count_circs_in_states(guard,
+   PATH_STATE_BUILD_SUCCEEDED,
+   PATH_STATE_USE_SUCCEEDED);
 }
 
 /**
@@ -2121,35 +2134,10 @@ pathbias_get_close_success_count(entry_guard_t *guard)
 double
 pathbias_get_use_success_count(entry_guard_t *guard)
 {
-  circuit_t *circ = global_circuitlist;
-  int open_circuits = 0;
-
-  /* Count currently open circuits. Give them the benefit of the doubt */
-  for ( ; circ; circ = circ-next) {
-origin_circuit_t *ocirc = NULL;
-if (!CIRCUIT_IS_ORIGIN(circ) || /* didn't originate here */
-circ-marked_for_close) /* already counted */
-  continue;
-
-ocirc = TO_ORIGIN_CIRCUIT(circ);
-
-if (!ocirc-cpath || !ocirc-cpath-extend_info)
-  continue;
-
-/* Don't count known failed or already counted circuits */
-if (ocirc-path_state = PATH_STATE_USE_FAILED)
-  continue;
-
-if (ocirc-path_state = PATH_STATE_USE_ATTEMPTED 
-pathbias_should_count(ocirc) 
-fast_memeq(guard-identity,
-ocirc-cpath-extend_info-identity_digest,
-DIGEST_LEN)) {
-  open_circuits++;
-}
-  }
-
-  return guard-use_successes + open_circuits;
+  return guard-use_successes +
+ pathbias_count_circs_in_states(guard,
+   PATH_STATE_USE_ATTEMPTED,
+   PATH_STATE_USE_SUCCEEDED);
 }
 
 /**
@@ -2252,6 +2240,10 @@ pathbias_check_use_rate(entry_guard_t *guard)
   if (guard-use_attempts  pathbias_get_scale_use_threshold(options)) {
 const int scale_factor = pathbias_get_scale_factor(options);
 const int mult_factor = pathbias_get_mult_factor(options);
+int opened_attempts = pathbias_count_circs_in_states(guard,
+PATH_STATE_USE_ATTEMPTED, PATH_STATE_USE_ATTEMPTED);
+guard-use_attempts -= opened_attempts;
+
 log_info(LD_CIRC,
  Scaling pathbias use counts to (%f/%f)*(%d/%d) for guard %s=%s,
  

[tor-commits] [tor/master] Document path use bias options in the manpage.

2013-01-28 Thread andrea
commit a678ff9ec1468832042fe4ebe208dd30b772eeeb
Author: Mike Perry mikeperry-...@fscked.org
Date:   Fri Jan 18 20:54:20 2013 -0800

Document path use bias options in the manpage.
---
 doc/tor.1.txt |   31 ---
 1 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/doc/tor.1.txt b/doc/tor.1.txt
index 40cf66d..5b01518 100644
--- a/doc/tor.1.txt
+++ b/doc/tor.1.txt
@@ -1242,16 +1242,11 @@ The following options are useful only for clients (that 
is, if
 
 **PathBiasMultFactor** __NUM__ +
 
-**PathBiasScaleFactor** __NUM__ +
-
-**PathBiasUseCloseCounts** __NUM__::
+**PathBiasScaleFactor** __NUM__::
 These options override the default behavior of Tor's (**currently
 experimental**) path bias detection algorithm. To try to find broken or
 misbehaving guard nodes, Tor looks for nodes where more than a certain
-fraction of circuits through that guard fail to get built. If
-PathBiasUseCloseCounts is set to 1 (the default), usage-based accounting is
-performed, and circuits that fail to carry streams are also counted as
-failures. +
+fraction of circuits through that guard fail to get built.
  +
 The PathBiasCircThreshold option controls how many circuits we need to 
build
 through a guard before we make these checks.  The PathBiasNoticeRate,
@@ -1270,6 +1265,28 @@ The following options are useful only for clients (that 
is, if
 If no defaults are available there, these options default to 150, .70,
 .50, .30, 0, 300, 1, and 2 respectively.
 
+**PathBiasUseThreshold** __NUM__ +
+
+**PathBiasNoticeUseRate** __NUM__ +
+
+**PathBiasExtremeUseRate** __NUM__ +
+
+**PathBiasScaleUseThreshold** __NUM__::
+Similar to the above options, these options override the default behavior
+of Tor's (**currently experimental**) path use bias detection algorithm.
+ +
+Where as the path bias parameters govern thresholds for successfully
+building circuits, these four path use bias parameters govern thresholds
+only for circuit usage. Circuits which receive no stream usage
+are not counted by this detection algorithm. A used circuit is considered
+successful if it is capable of carrying streams or otherwise receiving
+well-formed responses to RELAY cells.
+ +
+By default, or if a negative value is provided for one of these options,
+Tor uses reasonable defaults from the networkstatus consensus document.
+If no defaults are available there, these options default to 20, .90,
+.70, and 100, respectively.
+
 **ClientUseIPv6** **0**|**1**::
 If this option is set to 1, Tor might connect to entry nodes over
 IPv6. Note that clients configured with an IPv6 address in a



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Bug 7802 changes file.

2013-01-28 Thread andrea
commit 38c7195a32dac6f8914ba88a5a19a366e6b8dec7
Author: Mike Perry mikeperry-...@fscked.org
Date:   Fri Jan 18 21:02:57 2013 -0800

Bug 7802 changes file.
---
 changes/bug7802 |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/changes/bug7802 b/changes/bug7802
new file mode 100644
index 000..1d09757
--- /dev/null
+++ b/changes/bug7802
@@ -0,0 +1,10 @@
+  o Minor features:
+- Path Use Bias: Perform separate accounting for successful circuit use.
+  Separate statistics on stream attempt versus success rates are kept
+  for each guard. Configurable thresholds are provided to determine
+  when to emit log messages or disable use of guards that fail too
+  many stream attempts.
+  o Minor bugfixes:
+- Remove a source of rounding error during path bias count scaling.
+- Don't count cannibalized circuits as used for path bias until we
+  actually try to use them.



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] squash! Remove a source of error during path bias scaling

2013-01-28 Thread andrea
commit fb711e6d77cc6b4d4ff2daa506960919626a3f6a
Author: Mike Perry mikeperry-...@fscked.org
Date:   Sat Jan 19 19:56:52 2013 -0800

squash! Remove a source of error during path bias scaling

Move a log message about scaling to after we scale
---
 src/or/circuitbuild.c |   22 +++---
 1 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 8c7bd87..105e1ac 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -2244,12 +2244,6 @@ pathbias_check_use_rate(entry_guard_t *guard)
 PATH_STATE_USE_ATTEMPTED, PATH_STATE_USE_ATTEMPTED);
 guard-use_attempts -= opened_attempts;
 
-log_info(LD_CIRC,
- Scaling pathbias use counts to (%f/%f)*(%d/%d) for guard %s=%s,
- guard-use_successes, guard-use_attempts,
- mult_factor, scale_factor, guard-nickname,
- hex_str(guard-identity, DIGEST_LEN));
-
 guard-use_attempts *= mult_factor;
 guard-use_successes *= mult_factor;
 
@@ -2257,6 +2251,11 @@ pathbias_check_use_rate(entry_guard_t *guard)
 guard-use_successes /= scale_factor;
 
 guard-use_attempts += opened_attempts;
+
+log_info(LD_CIRC,
+ Scaled pathbias use counts to %f/%f for guard %s=%s,
+ guard-use_successes, guard-use_attempts,
+ guard-nickname, hex_str(guard-identity, DIGEST_LEN));
   }
 
   return 0;
@@ -2394,11 +2393,6 @@ pathbias_check_close_rate(entry_guard_t *guard)
 PATH_STATE_USE_FAILED);
 guard-circ_attempts -= opened_attempts;
 guard-circ_successes -= opened_built;
-log_info(LD_CIRC,
- Scaling pathbias counts to (%f/%f)*(%d/%d) for guard %s=%s,
- guard-circ_successes, guard-circ_attempts,
- mult_factor, scale_factor, guard-nickname,
- hex_str(guard-identity, DIGEST_LEN));
 
 guard-circ_attempts *= mult_factor;
 guard-circ_successes *= mult_factor;
@@ -2416,6 +2410,12 @@ pathbias_check_close_rate(entry_guard_t *guard)
 
 guard-circ_attempts += opened_attempts;
 guard-circ_successes += opened_built;
+
+log_info(LD_CIRC,
+ Scaled pathbias counts to (%f,%f)/%f for guard %s=%s,
+ guard-circ_successes, guard-successful_circuits_closed,
+ guard-circ_attempts, guard-nickname,
+ hex_str(guard-identity, DIGEST_LEN));
   }
 
   return 0;



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] squash! Implement Path use bias accounting.

2013-01-28 Thread andrea
commit 06a1d0b0447d3766b6199135f6878c6ce047f3b1
Author: Mike Perry mikeperry-...@fscked.org
Date:   Sun Jan 20 14:24:25 2013 -0800

squash! Implement Path use bias accounting.

Make a debug log more informative.
---
 src/or/circuitbuild.c |   16 ++--
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 105e1ac..a4c67cf 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -1582,9 +1582,11 @@ pathbias_count_use_attempt(origin_circuit_t *circ)
   pathbias_check_use_rate(guard);
   guard-use_attempts++;
 
-  log_debug(LD_CIRC, Marked circuit %d as used for guard %s=%s.,
-   circ-global_identifier, guard-nickname,
-   hex_str(guard-identity, DIGEST_LEN));
+  log_debug(LD_CIRC,
+   Marked circuit %d (%f/%f) as used for guard %s=%s.,
+   circ-global_identifier,
+   guard-use_successes, guard-use_attempts,
+   guard-nickname, hex_str(guard-identity, DIGEST_LEN));
 }
 
 circ-path_state = PATH_STATE_USE_ATTEMPTED;
@@ -1664,9 +1666,11 @@ pathbias_count_use_success(origin_circuit_t *circ)
   guard-use_successes++;
 
   log_debug(LD_CIRC,
-Marked circuit %d as used successfully for guard %s=%s.,
-   circ-global_identifier, guard-nickname,
-   hex_str(guard-identity, DIGEST_LEN));
+Marked circuit %d (%f/%f) as used successfully for guard 
+%s=%s.,
+circ-global_identifier, guard-use_successes,
+guard-use_attempts, guard-nickname,
+hex_str(guard-identity, DIGEST_LEN));
 }
   }
 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] squash! Remove a source of error during path bias scaling

2013-01-28 Thread andrea
commit b810d322bfc55d202dbbd2e8ebe4529cf0778c8b
Author: Mike Perry mikeperry-...@fscked.org
Date:   Sun Jan 20 14:30:02 2013 -0800

squash! Remove a source of error during path bias scaling

Improve debug logs and fix a state fencepost error.
---
 src/or/circuitbuild.c |   16 ++--
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index a4c67cf..97a26dd 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -2105,6 +2105,9 @@ pathbias_count_circs_in_states(entry_guard_t *guard,
 fast_memeq(guard-identity,
 ocirc-cpath-extend_info-identity_digest,
 DIGEST_LEN)) {
+  log_debug(LD_CIRC, Found opened circuit %d in path_state %s,
+ocirc-global_identifier,
+pathbias_state_to_string(ocirc-path_state));
   open_circuits++;
 }
   }
@@ -2245,7 +2248,7 @@ pathbias_check_use_rate(entry_guard_t *guard)
 const int scale_factor = pathbias_get_scale_factor(options);
 const int mult_factor = pathbias_get_mult_factor(options);
 int opened_attempts = pathbias_count_circs_in_states(guard,
-PATH_STATE_USE_ATTEMPTED, PATH_STATE_USE_ATTEMPTED);
+PATH_STATE_USE_ATTEMPTED, PATH_STATE_USE_SUCCEEDED);
 guard-use_attempts -= opened_attempts;
 
 guard-use_attempts *= mult_factor;
@@ -2257,8 +2260,8 @@ pathbias_check_use_rate(entry_guard_t *guard)
 guard-use_attempts += opened_attempts;
 
 log_info(LD_CIRC,
- Scaled pathbias use counts to %f/%f for guard %s=%s,
- guard-use_successes, guard-use_attempts,
+ Scaled pathbias use counts to %f/%f (%d open) for guard %s=%s,
+ guard-use_successes, guard-use_attempts, opened_attempts,
  guard-nickname, hex_str(guard-identity, DIGEST_LEN));
   }
 
@@ -2416,10 +2419,11 @@ pathbias_check_close_rate(entry_guard_t *guard)
 guard-circ_successes += opened_built;
 
 log_info(LD_CIRC,
- Scaled pathbias counts to (%f,%f)/%f for guard %s=%s,
+ Scaled pathbias counts to (%f,%f)/%f (%d/%d open) for guard 
+ %s=%s,
  guard-circ_successes, guard-successful_circuits_closed,
- guard-circ_attempts, guard-nickname,
- hex_str(guard-identity, DIGEST_LEN));
+ guard-circ_attempts, opened_built, opened_attempts,
+ guard-nickname, hex_str(guard-identity, DIGEST_LEN));
   }
 
   return 0;



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Prevent early close of path bias testing circuits.

2013-01-28 Thread andrea
commit f858370233a7d01d89949f79f92e8b67acd69f46
Author: Mike Perry mikeperry-...@fscked.org
Date:   Sat Jan 19 21:16:24 2013 -0800

Prevent early close of path bias testing circuits.

We need to let them live long enough to perform the test.
---
 src/or/circuituse.c  |5 -
 src/or/rendservice.c |3 ++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index 0b2fe9e..48a7743 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -1078,7 +1078,10 @@ circuit_expire_old_circuits_clientside(void)
 purpose %d),
 circ-n_circ_id, (long)(now.tv_sec - circ-timestamp_dirty),
 circ-purpose);
-  circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
+  /* Don't do this magic for testing circuits. Their death is governed
+   * by circuit_expire_building */
+  if (circ-purpose != CIRCUIT_PURPOSE_PATH_BIAS_TESTING)
+circuit_mark_for_close(circ, END_CIRC_REASON_FINISHED);
 } else if (!circ-timestamp_dirty  circ-state == CIRCUIT_STATE_OPEN) {
   if (timercmp(circ-timestamp_began, cutoff, )) {
 if (circ-purpose == CIRCUIT_PURPOSE_C_GENERAL ||
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index 3b2eeb4..f115d8b 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -3068,7 +3068,8 @@ rend_services_introduce(void)
   if (intro-time_expiring + INTRO_POINT_EXPIRATION_GRACE_PERIOD  now) {
 /* This intro point has completely expired.  Remove it, and
  * mark the circuit for close if it's still alive. */
-if (intro_circ != NULL) {
+if (intro_circ != NULL 
+intro_circ-base_.purpose != CIRCUIT_PURPOSE_PATH_BIAS_TESTING) {
   circuit_mark_for_close(TO_CIRCUIT(intro_circ),
  END_CIRC_REASON_FINISHED);
 }



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Bug 8024: Check for null/closed channel before probing.

2013-01-28 Thread andrea
commit a78542f0c30a6d8a25b3a8c92fec61c04c3feeaf
Author: Mike Perry mikeperry-...@fscked.org
Date:   Tue Jan 22 21:03:28 2013 -0800

Bug 8024: Check for null/closed channel before probing.
---
 changes/bug7802   |1 +
 src/or/circuitbuild.c |   10 ++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/changes/bug7802 b/changes/bug7802
index 1d09757..9bc0f36 100644
--- a/changes/bug7802
+++ b/changes/bug7802
@@ -8,3 +8,4 @@
 - Remove a source of rounding error during path bias count scaling.
 - Don't count cannibalized circuits as used for path bias until we
   actually try to use them.
+- Fix circuit_package_relay_cell warning message about n_chan==NULL.
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 97a26dd..e3a9d59 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -1727,6 +1727,16 @@ pathbias_send_usable_probe(circuit_t *circ)
 return -1;
   }
 
+  /* Can't probe if the channel isn't open */
+  if (circ-n_chan == NULL ||
+  (circ-n_chan-state != CHANNEL_STATE_OPEN
+circ-n_chan-state != CHANNEL_STATE_MAINT)) {
+log_info(LD_CIRC,
+ Skipping pathbias probe for circuit %d: Channel is not open.,
+ ocirc-global_identifier);
+return -1;
+  }
+
   circuit_change_purpose(circ, CIRCUIT_PURPOSE_PATH_BIAS_TESTING);
 
   /* Update timestamp for when circuit_expire_building() should kill us */



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Roll back the path_state for circs if we detatch a stream.

2013-01-28 Thread andrea
commit 24b9b9f791defcb6156c587a035fde58c35a46d9
Author: Mike Perry mikeperry-...@fscked.org
Date:   Fri Jan 18 19:29:17 2013 -0800

Roll back the path_state for circs if we detatch a stream.

An adversary could let the first stream request succeed (ie the resolve), 
but
then tag and timeout the remainder (via cell dropping), forcing them on new
circuits.

Rolling back the state will cause us to probe such circuits, which should 
lead
to probe failures in the event of such tagging due to either unrecognized
cells coming in while we wait for the probe, or the cipher state getting out
of sync in the case of dropped cells.
---
 src/or/connection_edge.c |   19 +++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 41795ac..9e2c15d 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -637,6 +637,16 @@ connection_ap_expire_beginning(void)
 }
 if (circ-purpose == CIRCUIT_PURPOSE_C_REND_JOINED) {
   if (seconds_idle = options-SocksTimeout) {
+/* Path bias: We need to probe the circuit to ensure validity.
+ * Roll its state back if it succeeded so that we do so upon close. */
+if (TO_ORIGIN_CIRCUIT(circ)-path_state == PATH_STATE_USE_SUCCEEDED) {
+  log_info(LD_CIRC,
+   Rolling back pathbias use state to 'attempted' for timed 
+   out rend circ %d,
+   TO_ORIGIN_CIRCUIT(circ)-global_identifier);
+  TO_ORIGIN_CIRCUIT(circ)-path_state = PATH_STATE_USE_ATTEMPTED;
+}
+
 log_fn(severity, LD_REND,
Rend stream is %d seconds late. Giving up on address
 '%s.onion'.,
@@ -806,6 +816,15 @@ connection_ap_detach_retriable(entry_connection_t *conn,
   control_event_stream_status(conn, STREAM_EVENT_FAILED_RETRIABLE, reason);
   ENTRY_TO_CONN(conn)-timestamp_lastread = time(NULL);
 
+  /* Path bias: We need to probe the circuit to ensure validity.
+   * Roll its state back if it succeeded so that we do so upon close. */
+  if (circ-path_state == PATH_STATE_USE_SUCCEEDED) {
+log_info(LD_CIRC,
+ Rolling back pathbias use state to 'attempted' for detached 
+ circuit %d, circ-global_identifier);
+circ-path_state = PATH_STATE_USE_ATTEMPTED;
+  }
+
   if (conn-pending_optimistic_data) {
 generic_buffer_set_to_copy(conn-sending_optimistic_data,
conn-pending_optimistic_data);



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Implement Path use bias accounting.

2013-01-28 Thread andrea
commit e13e30221ef6715cafa93bbffc156583c8b58ecf
Author: Mike Perry mikeperry-...@fscked.org
Date:   Fri Jan 18 19:37:16 2013 -0800

Implement Path use bias accounting.

Path use bias measures how often we can actually succeed using the circuits 
we
actually try to use. It is a subset of path bias accounting, but it is
computed as a separate statistic because the rate of client circuit use may
vary depending on use case.
---
 src/or/circuitbuild.c|  551 ++---
 src/or/circuitbuild.h|3 +
 src/or/circuituse.c  |   11 +
 src/or/config.c  |7 +-
 src/or/connection_edge.c |9 +-
 src/or/entrynodes.c  |   48 -
 src/or/entrynodes.h  |7 +-
 src/or/or.h  |   32 +++-
 src/or/relay.c   |2 +-
 src/or/rendclient.c  |9 +-
 src/or/rendservice.c |   13 +-
 11 files changed, 588 insertions(+), 104 deletions(-)

diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index b986243..435ccd9 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -67,7 +67,9 @@ static int entry_guard_inc_circ_attempt_count(entry_guard_t 
*guard);
 static void pathbias_count_build_success(origin_circuit_t *circ);
 static void pathbias_count_successful_close(origin_circuit_t *circ);
 static void pathbias_count_collapse(origin_circuit_t *circ);
-static void pathbias_count_unusable(origin_circuit_t *circ);
+static void pathbias_count_use_failed(origin_circuit_t *circ);
+static int pathbias_check_use_rate(entry_guard_t *guard);
+static int pathbias_check_close_rate(entry_guard_t *guard);
 
 /** This function tries to get a channel to the specified endpoint,
  * and then calls command_setup_channel() to give it the right
@@ -1210,19 +1212,65 @@ pathbias_get_mult_factor(const or_options_t *options)
 pathbias_get_scale_factor(options));
 }
 
+/** The minimum number of circuit usage attempts before we start
+  * thinking about warning about path use bias and dropping guards */
+static int
+pathbias_get_min_use(const or_options_t *options)
+{
+#define DFLT_PATH_BIAS_MIN_USE 20
+  if (options-PathBiasUseThreshold = 3)
+return options-PathBiasUseThreshold;
+  else
+return networkstatus_get_param(NULL, pb_minuse,
+   DFLT_PATH_BIAS_MIN_USE,
+   3, INT32_MAX);
+}
+
+/** The circuit use success rate below which we issue a notice */
+static double
+pathbias_get_notice_use_rate(const or_options_t *options)
+{
+#define DFLT_PATH_BIAS_NOTICE_USE_PCT 90
+  if (options-PathBiasNoticeUseRate = 0.0)
+return options-PathBiasNoticeUseRate;
+  else
+return networkstatus_get_param(NULL, pb_noticeusepct,
+   DFLT_PATH_BIAS_NOTICE_USE_PCT,
+   0, 100)/100.0;
+}
+
 /**
- * If this parameter is set to a true value (default), we use the
- * successful_circuits_closed. Otherwise, we use the success_count.
+ * The extreme use rate is the rate at which we would drop the guard,
+ * if pb_dropguard is also set. Otherwise we just warn.
+ */
+double
+pathbias_get_extreme_use_rate(const or_options_t *options)
+{
+#define DFLT_PATH_BIAS_EXTREME_USE_PCT 70
+  if (options-PathBiasExtremeUseRate = 0.0)
+return options-PathBiasExtremeUseRate;
+  else
+return networkstatus_get_param(NULL, pb_extremeusepct,
+   DFLT_PATH_BIAS_EXTREME_USE_PCT,
+   0, 100)/100.0;
+}
+
+/**
+ * This is the number of circuits at which we scale our
+ * use counts by mult_factor/scale_factor. Note, this count is
+ * not exact, as we only perform the scaling in the event
+ * of no integer truncation.
  */
 static int
-pathbias_use_close_counts(const or_options_t *options)
+pathbias_get_scale_use_threshold(const or_options_t *options)
 {
-#define DFLT_PATH_BIAS_USE_CLOSE_COUNTS 1
-  if (options-PathBiasUseCloseCounts = 0)
-return options-PathBiasUseCloseCounts;
+#define DFLT_PATH_BIAS_SCALE_USE_THRESHOLD 100
+  if (options-PathBiasScaleUseThreshold = 10)
+return options-PathBiasScaleUseThreshold;
   else
-return networkstatus_get_param(NULL, pb_useclosecounts,
-DFLT_PATH_BIAS_USE_CLOSE_COUNTS, 0, 1);
+return networkstatus_get_param(NULL, pb_scaleuse,
+   DFLT_PATH_BIAS_SCALE_USE_THRESHOLD,
+   10, INT32_MAX);
 }
 
 /**
@@ -1238,10 +1286,14 @@ pathbias_state_to_string(path_state_t state)
   return build attempted;
 case PATH_STATE_BUILD_SUCCEEDED:
   return build succeeded;
+case PATH_STATE_USE_ATTEMPTED:
+  return use attempted;
 case PATH_STATE_USE_SUCCEEDED:
   return use succeeded;
 case PATH_STATE_USE_FAILED:
   return use failed;
+case PATH_STATE_ALREADY_COUNTED:
+  return already counted;
   }
 
   return unknown;
@@ -1338,7 +1390,7 @@ 

[tor-commits] [tor/master] Merge branch 'bug7802' of ssh://git-rw.torproject.org/mikeperry/tor

2013-01-28 Thread andrea
commit 123daffb600cb1b581bee9dd576a980a06926f9c
Merge: dfbd19d a78542f
Author: Andrea Shepard and...@torproject.org
Date:   Mon Jan 28 16:16:45 2013 -0800

Merge branch 'bug7802' of ssh://git-rw.torproject.org/mikeperry/tor

 changes/bug7802  |   11 +
 doc/tor.1.txt|   31 ++-
 src/or/circuitbuild.c|  618 +-
 src/or/circuitbuild.h|3 +
 src/or/circuituse.c  |   30 ++-
 src/or/config.c  |7 +-
 src/or/connection_edge.c |   28 ++-
 src/or/entrynodes.c  |   48 -
 src/or/entrynodes.h  |7 +-
 src/or/or.h  |   32 ++-
 src/or/relay.c   |2 +-
 src/or/rendclient.c  |9 +-
 src/or/rendservice.c |   16 +-
 13 files changed, 691 insertions(+), 151 deletions(-)

diff --cc src/or/or.h
index 251512d,409a603..cfcddba
--- a/src/or/or.h
+++ b/src/or/or.h
@@@ -2998,11 -3013,8 +3014,10 @@@ typedef struct origin_circuit_t 
 * ISO_STREAM. */
uint64_t associated_isolated_stream_global_id;
/**@}*/
- 
  } origin_circuit_t;
  
 +struct onion_queue_t;
 +
  /** An or_circuit_t holds information needed to implement a circuit at an
   * OR. */
  typedef struct or_circuit_t {

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Record and report the overhead of how we handle onionskins.

2013-01-24 Thread andrea
commit 30e139389bd8301f62ee24481d0f5484544fc5de
Author: Nick Mathewson ni...@torproject.org
Date:   Thu Jan 3 13:20:20 2013 -0500

Record and report the overhead of how we handle onionskins.
---
 changes/timed_onionqueue |4 +++
 src/or/cpuworker.c   |   48 ++
 src/or/cpuworker.h   |2 +
 src/or/main.c|3 ++
 4 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/changes/timed_onionqueue b/changes/timed_onionqueue
index d0900ba..fe54d78 100644
--- a/changes/timed_onionqueue
+++ b/changes/timed_onionqueue
@@ -5,3 +5,7 @@
   estimate the time it will take to process an onionskin based on average
   processing time of previous onionskins.  Closes ticket 7291. You'll
   never have to configure MaxOnionsPending again.
+
+- We compute the overhead from passing onionskins back and forth to
+  cpuworkers, and report it when dumping statistics in response to
+  SIGUSR1.
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index a626224..42f7b95 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -235,6 +235,54 @@ estimated_usec_for_onionskins(uint32_t n_requests, 
uint16_t onionskin_type)
   }
 }
 
+/** Compute the absolute and relative overhead of using the cpuworker
+ * framework for onionskins of type bonionskin_type/b.*/
+static int
+get_overhead_for_onionskins(uint32_t *usec_out, double *frac_out,
+uint16_t onionskin_type)
+{
+  uint64_t overhead;
+
+  *usec_out = 0;
+  *frac_out = 0.0;
+
+  if (onionskin_type  MAX_ONION_HANDSHAKE_TYPE) /* should be impossible */
+return -1;
+  if (onionskins_n_processed[onionskin_type] == 0 ||
+  onionskins_usec_internal[onionskin_type] == 0 ||
+  onionskins_usec_roundtrip[onionskin_type] == 0)
+return -1;
+
+  overhead = onionskins_usec_roundtrip[onionskin_type] -
+onionskins_usec_internal[onionskin_type];
+
+  *usec_out = (uint32_t)(overhead / onionskins_n_processed[onionskin_type]);
+  *frac_out = U64_TO_DBL(overhead) / onionskins_usec_internal[onionskin_type];
+
+  return 0;
+}
+
+/** If we've measured overhead for onionskins of type bonionskin_type/b,
+ * log it. */
+void
+cpuworker_log_onionskin_overhead(int severity, int onionskin_type,
+ const char *onionskin_type_name)
+{
+  uint32_t overhead;
+  double relative_overhead;
+  int r;
+
+  r = get_overhead_for_onionskins(overhead,  relative_overhead,
+  onionskin_type);
+  if (!overhead || r0)
+return;
+
+  log_fn(severity, LD_OR,
+ %s onionskins have averaged %u usec overhead (%.2f%%) in 
+ cpuworker code ,
+ onionskin_type_name, (unsigned)overhead, relative_overhead*100);
+}
+
 /** Called when we get data from a cpuworker.  If the answer is not complete,
  * wait for a complete answer. If the answer is complete,
  * process it as appropriate.
diff --git a/src/or/cpuworker.h b/src/or/cpuworker.h
index df69172..2da0249 100644
--- a/src/or/cpuworker.h
+++ b/src/or/cpuworker.h
@@ -24,6 +24,8 @@ int assign_onionskin_to_cpuworker(connection_t *cpuworker,
 
 uint64_t estimated_usec_for_onionskins(uint32_t n_requests,
uint16_t onionskin_type);
+void cpuworker_log_onionskin_overhead(int severity, int onionskin_type,
+  const char *onionskin_type_name);
 
 #endif
 
diff --git a/src/or/main.c b/src/or/main.c
index abb1e34..3745ccb 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -2202,6 +2202,9 @@ dumpstats(int severity)
 100*(U64_TO_DBL(stats_n_data_bytes_received) /
  U64_TO_DBL(stats_n_data_cells_received*RELAY_PAYLOAD_SIZE)) );
 
+  cpuworker_log_onionskin_overhead(severity, ONION_HANDSHAKE_TYPE_TAP, TAP);
+  cpuworker_log_onionskin_overhead(severity, ONION_HANDSHAKE_TYPE_NTOR,ntor);
+
   if (now - time_of_process_start = 0)
 elapsed = now - time_of_process_start;
   else



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Use a TAILQ, not a singly-linked queue, for the onion queue.

2013-01-24 Thread andrea
commit b9fb01721a38c2b850f7a0120adc621a9d34b772
Author: Nick Mathewson ni...@torproject.org
Date:   Wed Dec 26 22:08:12 2012 -0500

Use a TAILQ, not a singly-linked queue, for the onion queue.

This makes removing items from the middle of the queue into an O(1)
operation, which could prove important as we let onionqueues grow
longer.

Doing this actually makes the code slightly smaller, too.
---
 src/or/onion.c |  122 ---
 src/or/or.h|5 ++
 2 files changed, 58 insertions(+), 69 deletions(-)

diff --git a/src/or/onion.c b/src/or/onion.c
index 9e22208..4556f7a 100644
--- a/src/or/onion.c
+++ b/src/or/onion.c
@@ -21,29 +21,29 @@
 #include relay.h
 #include rephist.h
 #include router.h
+#include tor_queue.h
 
 /** Type for a linked list of circuits that are waiting for a free CPU worker
  * to process a waiting onion handshake. */
 typedef struct onion_queue_t {
+  TAILQ_ENTRY(onion_queue_t) next;
   or_circuit_t *circ;
   create_cell_t *onionskin;
   time_t when_added;
-  struct onion_queue_t *next;
 } onion_queue_t;
 
 /** 5 seconds on the onion queue til we just send back a destroy */
 #define ONIONQUEUE_WAIT_CUTOFF 5
 
-/** First and last elements in the linked list of circuits waiting for CPU
- * workers, or NULL if the list is empty.
- * @{ */
-static onion_queue_t *ol_list=NULL;
-static onion_queue_t *ol_tail=NULL;
-/**@}*/
+/** Queue of circuits waiting for CPU workers, or NULL if the list is empty.*/
+TAILQ_HEAD(onion_queue_head_t, onion_queue_t) ol_list =
+  TAILQ_HEAD_INITIALIZER(ol_list);
 
 /** Number of entries of each type currently in ol_list. */
 static int ol_entries[MAX_ONION_HANDSHAKE_TYPE+1];
 
+static void onion_queue_entry_remove(onion_queue_t *victim);
+
 /* 024 Check lengths vs MAX_ONIONSKIN_{CHALLENGE,REPLY}_LEN.
  *
  * (By which I think I meant, make sure that no
@@ -101,17 +101,6 @@ onion_pending_add(or_circuit_t *circ, create_cell_t 
*onionskin)
   tmp-onionskin = onionskin;
   tmp-when_added = now;
 
-  if (!ol_tail) {
-tor_assert(!ol_list);
-ol_list = tmp;
-ol_tail = tmp;
-++ol_entries[onionskin-handshake_type];
-return 0;
-  }
-
-  tor_assert(ol_list);
-  tor_assert(!ol_tail-next);
-
   if (!have_room_for_onionskin(onionskin-handshake_type)) {
 #define WARN_TOO_MANY_CIRC_CREATIONS_INTERVAL (60)
 static ratelim_t last_warned =
@@ -130,12 +119,18 @@ onion_pending_add(or_circuit_t *circ, create_cell_t 
*onionskin)
   }
 
   ++ol_entries[onionskin-handshake_type];
-  ol_tail-next = tmp;
-  ol_tail = tmp;
-  while ((int)(now - ol_list-when_added) = ONIONQUEUE_WAIT_CUTOFF) {
-/* cull elderly requests. */
-circ = ol_list-circ;
-onion_pending_remove(ol_list-circ);
+  circ-onionqueue_entry = tmp;
+  TAILQ_INSERT_TAIL(ol_list, tmp, next);
+
+  /* cull elderly requests. */
+  while (1) {
+onion_queue_t *head = TAILQ_FIRST(ol_list);
+if (now - head-when_added  (time_t)ONIONQUEUE_WAIT_CUTOFF)
+  break;
+
+circ = head-circ;
+circ-onionqueue_entry = NULL;
+onion_queue_entry_remove(head);
 log_info(LD_CIRC,
  Circuit create request is too old; canceling due to overload.);
 circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_RESOURCELIMIT);
@@ -150,19 +145,21 @@ or_circuit_t *
 onion_next_task(create_cell_t **onionskin_out)
 {
   or_circuit_t *circ;
+  onion_queue_t *head = TAILQ_FIRST(ol_list);
 
-  if (!ol_list)
+  if (!head)
 return NULL; /* no onions pending, we're done */
 
-  tor_assert(ol_list-circ);
-  tor_assert(ol_list-circ-p_chan); /* make sure it's still valid */
-  circ = ol_list-circ;
-  if (ol_list-onionskin 
-  ol_list-onionskin-handshake_type = MAX_ONION_HANDSHAKE_TYPE)
---ol_entries[ol_list-onionskin-handshake_type];
-  *onionskin_out = ol_list-onionskin;
-  ol_list-onionskin = NULL; /* prevent free. */
-  onion_pending_remove(ol_list-circ);
+  tor_assert(head-circ);
+  tor_assert(head-circ-p_chan); /* make sure it's still valid */
+  circ = head-circ;
+  if (head-onionskin 
+  head-onionskin-handshake_type = MAX_ONION_HANDSHAKE_TYPE)
+--ol_entries[head-onionskin-handshake_type];
+  *onionskin_out = head-onionskin;
+  head-onionskin = NULL; /* prevent free. */
+  circ-onionqueue_entry = NULL;
+  onion_queue_entry_remove(head);
   return circ;
 }
 
@@ -172,40 +169,30 @@ onion_next_task(create_cell_t **onionskin_out)
 void
 onion_pending_remove(or_circuit_t *circ)
 {
-  onion_queue_t *tmpo, *victim;
-
-  if (!ol_list)
-return; /* nothing here. */
-
-  /* first check to see if it's the first entry */
-  tmpo = ol_list;
-  if (tmpo-circ == circ) {
-/* it's the first one. remove it from the list. */
-ol_list = tmpo-next;
-if (!ol_list)
-  ol_tail = NULL;
-victim = tmpo;
-  } else { /* we need to hunt through the rest of the list */
-for ( ;tmpo-next  tmpo-next-circ != circ; tmpo=tmpo-next) ;
-if (!tmpo-next) {
-  log_debug(LD_GENERAL,
-

[tor-commits] [tor/master] Eliminate MaxOnionsPending; replace it with MaxOnionQueueDelay

2013-01-24 Thread andrea
commit b0b3c14c11afe55cd71f9c1b8a89d9e5a65c9799
Author: Nick Mathewson ni...@torproject.org
Date:   Wed Dec 26 18:08:01 2012 -0500

Eliminate MaxOnionsPending; replace it with MaxOnionQueueDelay

The right way to set MaxOnionsPending was to adjust it until the
processing delay was appropriate.  So instead, let's measure how long
it takes to process onionskins (sampling them once we have a big
number), and then limit the queue based on its expected time to
finish.

This change is extra-necessary for ntor, since there is no longer a
reasonable way to set MaxOnionsPending without knowing what mix of
onionskins you'll get.

This patch also reserves 1/3 of the onionskin spots for ntor
handshakes, on the theory that TAP handshakes shouldn't be allowed to
starve their speedier cousins.  We can change this later if need be.

Resolves 7291.
---
 changes/timed_onionqueue |7 +++
 doc/tor.1.txt|6 +-
 src/or/config.c  |3 +-
 src/or/cpuworker.c   |  122 +-
 src/or/cpuworker.h   |3 +
 src/or/onion.c   |   68 +
 src/or/or.h  |5 +-
 7 files changed, 195 insertions(+), 19 deletions(-)

diff --git a/changes/timed_onionqueue b/changes/timed_onionqueue
new file mode 100644
index 000..d0900ba
--- /dev/null
+++ b/changes/timed_onionqueue
@@ -0,0 +1,7 @@
+  o Minor features (relay):
+- Instead of limiting the number of queued onionskins to a configured,
+  hard-to-configure number, we limit the size of the queue based on how
+  many we expect to be able to process in a given amount of time. We
+  estimate the time it will take to process an onionskin based on average
+  processing time of previous onionskins.  Closes ticket 7291. You'll
+  never have to configure MaxOnionsPending again.
diff --git a/doc/tor.1.txt b/doc/tor.1.txt
index 40cf66d..d107fa9 100644
--- a/doc/tor.1.txt
+++ b/doc/tor.1.txt
@@ -1376,9 +1376,9 @@ is non-zero):
 If set, and we are an exit node, allow clients to use us for IPv6
 traffic. (Default: 0)
 
-**MaxOnionsPending** __NUM__::
-If you have more than this number of onionskins queued for decrypt, reject
-new ones. (Default: 100)
+**MaxOnionQueueDelay** __NUM__ [**msec**|**second**]::
+If we have more onionskins queued for processing than we can process in
+this amount of time, reject new ones. (Default: 1750 msec)
 
 **MyFamily** __node__,__node__,__...__::
 Declare that this Tor server is controlled or administered by a group or
diff --git a/src/or/config.c b/src/or/config.c
index 9905a94..4b3937b 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -296,7 +296,8 @@ static config_var_t option_vars_[] = {
   V(MaxAdvertisedBandwidth,  MEMUNIT,  1 GB),
   V(MaxCircuitDirtiness, INTERVAL, 10 minutes),
   V(MaxClientCircuitsPending,UINT, 32),
-  V(MaxOnionsPending,UINT, 100),
+  OBSOLETE(MaxOnionsPending),
+  V(MaxOnionQueueDelay,  MSEC_INTERVAL, 1750 msec),
   OBSOLETE(MonthlyAccountingStart),
   V(MyFamily,STRING,   NULL),
   V(NewCircuitPeriod,INTERVAL, 30 seconds),
diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index 3f8fc94..a626224 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -98,6 +98,11 @@ typedef struct cpuworker_request_t {
   /** Task code. Must be one of CPUWORKER_TASK_* */
   uint8_t task;
 
+  /** Flag: Are we timing this request? */
+  unsigned timed : 1;
+  /** If we're timing this request, when was it sent to the cpuworker? */
+  struct timeval started_at;
+
   /** A create cell for the cpuworker to process. */
   create_cell_t create_cell;
 
@@ -113,6 +118,17 @@ typedef struct cpuworker_reply_t {
   /** True iff we got a successful request. */
   uint8_t success;
 
+  /** Are we timing this request? */
+  unsigned int timed : 1;
+  /** What handshake type was the request? (Used for timing) */
+  uint16_t handshake_type;
+  /** When did we send the request to the cpuworker? */
+  struct timeval started_at;
+  /** Once the cpuworker received the request, how many microseconds did it
+   * take? (This shouldn't overflow; 4 billion micoseconds is over an hour,
+   * and we'll never have an onion handshake that takes so long.) */
+  uint32_t n_usec;
+
   /** Output of processing a create cell
*
* @{
@@ -163,6 +179,62 @@ connection_cpu_reached_eof(connection_t *conn)
   return 0;
 }
 
+/** Indexed by handshake type: how many onionskins have we processed and
+ * counted of that type? */
+static uint64_t onionskins_n_processed[MAX_ONION_HANDSHAKE_TYPE+1];
+/** Indexed by handshake type, corresponding to the onionskins counted in
+ * onionskins_n_processed: how many microseconds have we spent in cpuworkers
+ * processing that kind of onionskin? */
+static uint64_t onionskins_usec_internal[MAX_ONION_HANDSHAKE_TYPE+1];
+/** Indexed by 

[tor-commits] [tor/master] Better handling (I think) for onionskin timing w jumpy clocks

2013-01-24 Thread andrea
commit 677d18278e5b27a43f3f56906d97a9575d26c6f4
Author: Nick Mathewson ni...@torproject.org
Date:   Thu Jan 3 13:26:59 2013 -0500

Better handling (I think) for onionskin timing w jumpy clocks

The fix: Instead of clipping huge/negative times, ignore them as
probably invalid.
---
 src/or/cpuworker.c |   25 -
 1 files changed, 12 insertions(+), 13 deletions(-)

diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index 42f7b95..52a0117 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -320,19 +320,18 @@ connection_cpu_process_inbuf(connection_t *conn)
   tor_gettimeofday(tv_end);
   timersub(tv_end, rpl.started_at, tv_diff);
   usec_roundtrip = ((int64_t)tv_diff.tv_sec)*100 + tv_diff.tv_usec;
-  if (usec_roundtrip  0 ||
-  usec_roundtrip  MAX_BELIEVABLE_ONIONSKIN_DELAY) {
-usec_roundtrip = MAX_BELIEVABLE_ONIONSKIN_DELAY;
-  }
-  ++onionskins_n_processed[rpl.handshake_type];
-  onionskins_usec_internal[rpl.handshake_type] += rpl.n_usec;
-  onionskins_usec_roundtrip[rpl.handshake_type] += usec_roundtrip;
-  if (onionskins_n_processed[rpl.handshake_type] = 50) {
-/* Scale down every 50 handshakes.  On a busy server, that's
- * less impressive than it sounds. */
-onionskins_n_processed[rpl.handshake_type] /= 2;
-onionskins_usec_internal[rpl.handshake_type] /= 2;
-onionskins_usec_roundtrip[rpl.handshake_type] /= 2;
+  if (usec_roundtrip = 0 
+  usec_roundtrip  MAX_BELIEVABLE_ONIONSKIN_DELAY) {
+++onionskins_n_processed[rpl.handshake_type];
+onionskins_usec_internal[rpl.handshake_type] += rpl.n_usec;
+onionskins_usec_roundtrip[rpl.handshake_type] += usec_roundtrip;
+if (onionskins_n_processed[rpl.handshake_type] = 50) {
+  /* Scale down every 50 handshakes.  On a busy server, that's
+   * less impressive than it sounds. */
+  onionskins_n_processed[rpl.handshake_type] /= 2;
+  onionskins_usec_internal[rpl.handshake_type] /= 2;
+  onionskins_usec_roundtrip[rpl.handshake_type] /= 2;
+}
   }
 }
 /* parse out the circ it was talking about */



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Merge branch 'time_based_onionqueue_v2' of ssh://git-rw.torproject.org/nickm/tor

2013-01-24 Thread andrea
commit dfbd19df418347d833df650e68367c96a3aa37ad
Merge: b415aba 677d182
Author: Andrea Shepard and...@torproject.org
Date:   Thu Jan 24 08:10:12 2013 -0800

Merge branch 'time_based_onionqueue_v2' of 
ssh://git-rw.torproject.org/nickm/tor

 changes/timed_onionqueue |   11 +++
 doc/tor.1.txt|6 +-
 src/or/config.c  |3 +-
 src/or/cpuworker.c   |  169 ++-
 src/or/cpuworker.h   |5 ++
 src/or/main.c|3 +
 src/or/onion.c   |  180 +++---
 src/or/or.h  |   10 ++-
 8 files changed, 304 insertions(+), 83 deletions(-)

diff --cc src/or/or.h
index a6f3d3e,01205ee..251512d
--- a/src/or/or.h
+++ b/src/or/or.h
@@@ -2581,9 -2576,10 +2581,10 @@@ typedef enum 
  
  struct fast_handshake_state_t;
  struct ntor_handshake_state_t;
 -#define ONION_HANDSHAKE_TYPE_TAP 0x
 +#define ONION_HANDSHAKE_TYPE_TAP  0x
  #define ONION_HANDSHAKE_TYPE_FAST 0x0001
  #define ONION_HANDSHAKE_TYPE_NTOR 0x0002
+ #define MAX_ONION_HANDSHAKE_TYPE 0x0002
  typedef struct {
uint16_t tag;
union {

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Call channel_mark_for_close() properly in hibernate_go_dormant()

2012-11-13 Thread andrea
commit 7ab3004223bd61f8ad1c573b309c63824e038528
Author: Andrea Shepard and...@torproject.org
Date:   Tue Nov 13 13:45:00 2012 -0800

Call channel_mark_for_close() properly in hibernate_go_dormant()
---
 src/or/hibernate.c |   10 +-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/or/hibernate.c b/src/or/hibernate.c
index b33e5e2..9e54eb4 100644
--- a/src/or/hibernate.c
+++ b/src/or/hibernate.c
@@ -23,6 +23,8 @@ hibernating, phase 2:
 
 #define HIBERNATE_PRIVATE
 #include or.h
+#include channel.h
+#include channeltls.h
 #include config.h
 #include connection.h
 #include connection_edge.h
@@ -846,7 +848,13 @@ hibernate_go_dormant(time_t now)
 if (conn-type == CONN_TYPE_AP) /* send socks failure if needed */
   connection_mark_unattached_ap(TO_ENTRY_CONN(conn),
 END_STREAM_REASON_HIBERNATING);
-else
+else if (conn-type == CONN_TYPE_OR) {
+  if (TO_OR_CONN(conn)-chan) {
+channel_mark_for_close(TLS_CHAN_TO_BASE(TO_OR_CONN(conn)-chan));
+  } else {
+ connection_mark_for_close(conn);
+  }
+} else
   connection_mark_for_close(conn);
   }
 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Add changes file for bug 7267

2012-11-13 Thread andrea
commit 3b517ea5f467fd941cdb0fcefb088e706d8c04d0
Author: Andrea Shepard and...@torproject.org
Date:   Tue Nov 13 13:46:36 2012 -0800

Add changes file for bug 7267
---
 changes/bug7267 |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/changes/bug7267 b/changes/bug7267
new file mode 100644
index 000..7089329
--- /dev/null
+++ b/changes/bug7267
@@ -0,0 +1,4 @@
+ - Major bugfixes
+   o Call channel_mark_for_close() rather than connection_mark_for_close()
+ in hibernate_go_dormant() when closing an or_connection_t.  Fixes bug
+ 7267.



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Add comment explaining different channel close functions

2012-11-13 Thread andrea
commit 3db3daa663e9fe41f87993f4580cf3a8e6bab27c
Author: Andrea Shepard and...@torproject.org
Date:   Tue Nov 13 18:50:37 2012 -0800

Add comment explaining different channel close functions
---
 src/or/channel.c |   13 +
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index 16dd9f9..625d957 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -1057,6 +1057,19 @@ channel_set_cell_handlers(channel_t *chan,
chan-var_cell_handler)) channel_process_cells(chan);
 }
 
+/*
+ * On closing channels
+ *
+ * There are three functions that close channels, for use in
+ * different circumstances:
+ *
+ *  - Use channel_mark_for_close() for most cases
+ *  - Use channel_close_from_lower_layer() if you are connection_or.c
+ *and the other end closes the underlying connection.
+ *  - Use channel_close_for_error() if you are connection_or.c and
+ *some sort of error has occurred.
+ */
+
 /**
  * Mark a channel for closure
  *



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Merge branch 'bug7267' of ssh://git-rw.torproject.org/user/andrea/tor

2012-11-13 Thread andrea
commit 2cb82c33bcb59ce65c9738ff8ff4977f39fa3d9f
Merge: 02a43e5 3db3daa
Author: Andrea Shepard and...@torproject.org
Date:   Tue Nov 13 18:54:24 2012 -0800

Merge branch 'bug7267' of ssh://git-rw.torproject.org/user/andrea/tor

 changes/bug7267|4 
 src/or/channel.c   |   13 +
 src/or/hibernate.c |   10 +-
 3 files changed, 26 insertions(+), 1 deletions(-)

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Check for orconns in connection_mark_for_close and connection_mark_and_flush, and pass the call through channel_close_for_error with a warning to avoid asserts

2012-11-10 Thread andrea
commit 8124398835097c3edfe0200a307092b71acfe0a0
Author: Andrea Shepard and...@torproject.org
Date:   Fri Nov 9 14:06:54 2012 -0800

Check for orconns in connection_mark_for_close and 
connection_mark_and_flush, and pass the call through channel_close_for_error 
with a warning to avoid asserts
---
 src/or/connection.c|   38 +-
 src/or/connection.h|   48 
 src/or/connection_or.c |8 
 3 files changed, 81 insertions(+), 13 deletions(-)

diff --git a/src/or/connection.c b/src/or/connection.c
index 1fbce41..5aac06f 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -688,6 +688,41 @@ connection_mark_for_close_(connection_t *conn, int line, 
const char *file)
   tor_assert(line  116); /* marked_for_close can only fit a uint16_t. */
   tor_assert(file);
 
+  if (conn-type == CONN_TYPE_OR) {
+/*
+ * An or_connection should have been closed through one of the channel-
+ * aware functions in connection_or.c.  We'll assume this is an error
+ * close and do that, and log a bug warning.
+ */
+log_warn(LD_CHANNEL | LD_BUG,
+ Something tried to close an or_connection_t without going 
+ through channels at %s:%d,
+ file, line);
+connection_or_close_for_error(TO_OR_CONN(conn), 0);
+  } else {
+/* Pass it down to the real function */
+connection_mark_for_close_internal_(conn, line, file);
+  }
+}
+
+/** Mark bconn/b to be closed next time we loop through
+ * conn_close_if_marked() in main.c; the _internal version bypasses the
+ * CONN_TYPE_OR checks; this should be called when you either are sure that
+ * if this is an or_connection_t the controlling channel has been notified
+ * (e.g. with connection_or_notify_error()), or you actually are the
+ * connection_or_close_for_error() or connection_or_close_normally function.
+ * For all other cases, use connection_mark_and_flush() instead, which
+ * checks for or_connection_t properly, instead.  See below.
+ */
+void
+connection_mark_for_close_internal_(connection_t *conn,
+int line, const char *file)
+{
+  assert_connection_ok(conn,0);
+  tor_assert(line);
+  tor_assert(line  116); /* marked_for_close can only fit a uint16_t. */
+  tor_assert(file);
+
   if (conn-marked_for_close) {
 log(LOG_WARN,LD_BUG,Duplicate call to connection_mark_for_close at %s:%d
  (first at %s:%d), file, line, conn-marked_for_close_file,
@@ -702,7 +737,8 @@ connection_mark_for_close_(connection_t *conn, int line, 
const char *file)
  * this so we can find things that call this wrongly when the asserts hit.
  */
 log_debug(LD_CHANNEL,
-  Calling connection_mark_for_close on an OR conn at %s:%d,
+  Calling connection_mark_for_close_internal_() on an OR conn 
+  at %s:%d,
   file, line);
   }
 
diff --git a/src/or/connection.h b/src/or/connection.h
index 6ed9e4a..b0c2a42 100644
--- a/src/or/connection.h
+++ b/src/or/connection.h
@@ -31,21 +31,53 @@ void connection_free(connection_t *conn);
 void connection_free_all(void);
 void connection_about_to_close_connection(connection_t *conn);
 void connection_close_immediate(connection_t *conn);
-void connection_mark_for_close_(connection_t *conn,int line, const char *file);
+void connection_mark_for_close_(connection_t *conn,
+int line, const char *file);
+void connection_mark_for_close_internal_(connection_t *conn,
+ int line, const char *file);
 
 #define connection_mark_for_close(c) \
   connection_mark_for_close_((c), __LINE__, SHORT_FILE__)
+#define connection_mark_for_close_internal(c) \
+  connection_mark_for_close_internal_((c), __LINE__, SHORT_FILE__)
 
 /**
  * Mark 'c' for close, but try to hold it open until all the data is written.
+ * Use the _internal versions of connection_mark_for_close; this should be
+ * called when you either are sure that if this is an or_connection_t the
+ * controlling channel has been notified (e.g. with
+ * connection_or_notify_error()), or you actually are the
+ * connection_or_close_for_error() or connection_or_close_normally function.
+ * For all other cases, use connection_mark_and_flush() instead, which
+ * checks for or_connection_t properly, instead.  See below.
  */
-#define connection_mark_and_flush_(c,line,file) \
-  do {  \
-connection_t *tmp_conn_ = (c);  \
-connection_mark_for_close_(tmp_conn_, (line), (file));  \
-tmp_conn_-hold_open_until_flushed = 1; \
-IF_HAS_BUFFEREVENT(tmp_conn_,   \
-   connection_start_writing(tmp_conn_));\
+#define connection_mark_and_flush_internal_(c,line,file

[tor-commits] [tor/master] Make everything in connection.c that uses connection_or_notify_error() also use connection_mark_and_close_internal() to avoid spurious warnings

2012-11-10 Thread andrea
commit 99e82cab30efdacd464deec524ee0da3576e69d9
Author: Andrea Shepard and...@torproject.org
Date:   Fri Nov 9 14:19:45 2012 -0800

Make everything in connection.c that uses connection_or_notify_error() also 
use connection_mark_and_close_internal() to avoid spurious warnings
---
 src/or/connection.c |   30 +-
 1 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/src/or/connection.c b/src/or/connection.c
index 5aac06f..e6755f4 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -2763,7 +2763,11 @@ connection_handle_read_impl(connection_t *conn)
   }
 }
 connection_close_immediate(conn); /* Don't flush; connection is dead. */
-connection_mark_for_close(conn);
+/*
+ * This can bypass normal channel checking since we did
+ * connection_or_notify_error() above.
+ */
+connection_mark_for_close_internal(conn);
 return -1;
   }
   n_read += buf_datalen(conn-inbuf) - before;
@@ -3279,7 +3283,11 @@ connection_handle_write_impl(connection_t *conn, int 
force)
  tor_socket_strerror(e));
 
 connection_close_immediate(conn);
-connection_mark_for_close(conn);
+/*
+ * This can bypass normal channel checking since we did
+ * connection_or_notify_error() above.
+ */
+connection_mark_for_close_internal(conn);
 return -1;
   } else {
 return 0; /* no change, see if next time is better */
@@ -3306,7 +3314,11 @@ connection_handle_write_impl(connection_t *conn, int 
force)
TLS error in connection_tls_
continue_handshake());
 connection_close_immediate(conn);
-connection_mark_for_close(conn);
+/*
+ * This can bypass normal channel checking since we did
+ * connection_or_notify_error() above.
+ */
+connection_mark_for_close_internal(conn);
 return -1;
   }
   return 0;
@@ -3336,7 +3348,11 @@ connection_handle_write_impl(connection_t *conn, int 
force)
  TLS error in during flush :
  TLS closed during flush);
 connection_close_immediate(conn);
-connection_mark_for_close(conn);
+/*
+ * This can bypass normal channel checking since we did
+ * connection_or_notify_error() above.
+ */
+connection_mark_for_close_internal(conn);
 return -1;
   case TOR_TLS_WANTWRITE:
 log_debug(LD_NET,wanted write.);
@@ -3401,7 +3417,11 @@ connection_handle_write_impl(connection_t *conn, int 
force)
connection_flushed_some());
   }
 
-  connection_mark_for_close(conn);
+  /*
+   * This can bypass normal channel checking since we did
+   * connection_or_notify_error() above.
+   */
+  connection_mark_for_close_internal(conn);
 }
   }
 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Add changes file for connection_mark_for_close()/connection_mark_and_flush() or_connection_t checking

2012-11-10 Thread andrea
commit fc1a9a13cf427ec7a319086c820408847fbc189b
Author: Andrea Shepard and...@torproject.org
Date:   Sat Nov 10 02:38:40 2012 -0800

Add changes file for 
connection_mark_for_close()/connection_mark_and_flush() or_connection_t checking
---
 changes/check_for_orconn_on_close |4 
 1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/changes/check_for_orconn_on_close 
b/changes/check_for_orconn_on_close
new file mode 100644
index 000..4d76d5e
--- /dev/null
+++ b/changes/check_for_orconn_on_close
@@ -0,0 +1,4 @@
+  o Minor bugfixes:
+- Check for closing an or_connection_t without going through correct
+  channel functions; emit a warning and then call
+  connection_or_close_for_error() so we don't assert as in 7212 and 7267.



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Merge branch 'check_for_orconn_on_close_squashed' of ssh://git-rw.torproject.org/user/andrea/tor

2012-11-10 Thread andrea
commit 0523c8de7d7f775e9a89134340f88ae00bde158b
Merge: 713736a fc1a9a1
Author: Andrea Shepard and...@torproject.org
Date:   Sat Nov 10 03:24:41 2012 -0800

Merge branch 'check_for_orconn_on_close_squashed' of 
ssh://git-rw.torproject.org/user/andrea/tor

 changes/check_for_orconn_on_close |4 ++
 src/or/connection.c   |   68 +---
 src/or/connection.h   |   48 +
 src/or/connection_or.c|8 ++--
 4 files changed, 110 insertions(+), 18 deletions(-)

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Check for closing channel in channel_send_destroy()

2012-11-07 Thread andrea
commit 688cea7248584b0202fc269a9f009bfa97e598bc
Author: Andrea Shepard and...@torproject.org
Date:   Tue Nov 6 17:52:14 2012 -0800

Check for closing channel in channel_send_destroy()
---
 src/or/channel.c |   32 ++--
 1 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index cbf7f99..16dd9f9 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -2585,17 +2585,29 @@ channel_send_destroy(circid_t circ_id, channel_t *chan, 
int reason)
 
   tor_assert(chan);
 
-  memset(cell, 0, sizeof(cell_t));
-  cell.circ_id = circ_id;
-  cell.command = CELL_DESTROY;
-  cell.payload[0] = (uint8_t) reason;
-  log_debug(LD_OR,
-Sending destroy (circID %d) on channel %p 
-(global ID  U64_FORMAT ),
-circ_id, chan,
-U64_PRINTF_ARG(chan-global_identifier));
+  /* Check to make sure we can send on this channel first */
+  if (!(chan-state == CHANNEL_STATE_CLOSING ||
+chan-state == CHANNEL_STATE_CLOSED ||
+chan-state == CHANNEL_STATE_ERROR)) {
+memset(cell, 0, sizeof(cell_t));
+cell.circ_id = circ_id;
+cell.command = CELL_DESTROY;
+cell.payload[0] = (uint8_t) reason;
+log_debug(LD_OR,
+  Sending destroy (circID %d) on channel %p 
+  (global ID  U64_FORMAT ),
+  circ_id, chan,
+  U64_PRINTF_ARG(chan-global_identifier));
 
-  channel_write_cell(chan, cell);
+channel_write_cell(chan, cell);
+  } else {
+log_warn(LD_BUG,
+ Someone called channel_send_destroy() for circID %d 
+ on a channel  U64_FORMAT  at %p in state %s (%d),
+ circ_id, U64_PRINTF_ARG(chan-global_identifier),
+ chan, channel_state_to_string(chan-state),
+ chan-state);
+  }
 
   return 0;
 }



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Don't call channel_send_destroy() when closing a circuit on a closing channel

2012-11-07 Thread andrea
commit 80eb03ae0a1599f5429789b5a6f2659b8f4cbe4a
Author: Andrea Shepard and...@torproject.org
Date:   Tue Nov 6 17:58:59 2012 -0800

Don't call channel_send_destroy() when closing a circuit on a closing 
channel
---
 src/or/circuitlist.c |   14 --
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/or/circuitlist.c b/src/or/circuitlist.c
index 3ec2bf1..32a478d 100644
--- a/src/or/circuitlist.c
+++ b/src/or/circuitlist.c
@@ -1411,7 +1411,12 @@ circuit_mark_for_close_(circuit_t *circ, int reason, int 
line,
   }
   if (circ-n_chan) {
 circuit_clear_cell_queue(circ, circ-n_chan);
-channel_send_destroy(circ-n_circ_id, circ-n_chan, reason);
+/* Only send destroy if the channel isn't closing anyway */
+if (!(circ-n_chan-state == CHANNEL_STATE_CLOSING ||
+  circ-n_chan-state == CHANNEL_STATE_CLOSED ||
+  circ-n_chan-state == CHANNEL_STATE_ERROR)) {
+  channel_send_destroy(circ-n_circ_id, circ-n_chan, reason);
+}
 circuitmux_detach_circuit(circ-n_chan-cmux, circ);
   }
 
@@ -1439,7 +1444,12 @@ circuit_mark_for_close_(circuit_t *circ, int reason, int 
line,
 
 if (or_circ-p_chan) {
   circuit_clear_cell_queue(circ, or_circ-p_chan);
-  channel_send_destroy(or_circ-p_circ_id, or_circ-p_chan, reason);
+  /* Only send destroy if the channel isn't closing anyway */
+  if (!(or_circ-p_chan-state == CHANNEL_STATE_CLOSING ||
+or_circ-p_chan-state == CHANNEL_STATE_CLOSED ||
+or_circ-p_chan-state == CHANNEL_STATE_ERROR)) {
+channel_send_destroy(or_circ-p_circ_id, or_circ-p_chan, reason);
+  }
   circuitmux_detach_circuit(or_circ-p_chan-cmux, circ);
 }
   } else {



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Add changes file for bug7350

2012-11-07 Thread andrea
commit 3b270e86be0ab8edcda2907f41ca3abb57f8c59a
Author: Andrea Shepard and...@torproject.org
Date:   Wed Nov 7 11:39:49 2012 -0800

Add changes file for bug7350
---
 changes/bug7350 |5 +
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/changes/bug7350 b/changes/bug7350
new file mode 100644
index 000..9c2f20d
--- /dev/null
+++ b/changes/bug7350
@@ -0,0 +1,5 @@
+  o Minor bugfixes:
+- Avoid a possible assert that can occur when channel_send_destroy() is
+  called on a channel in CHANNEL_STATE_CLOSING, CHANNEL_STATE_CLOSED
+  or CHANNEL_STATE_ERROR when the Tor process is resumed after being
+  blocked for a long interval.  Fixes bug 7350.



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Merge branch 'bug7350' of ssh://git-rw.torproject.org/user/andrea/tor

2012-11-07 Thread andrea
commit 9f3f5372b880b3372fd7b9fc98bd3d78f969390a
Merge: cd054ce 3b270e8
Author: Andrea Shepard and...@torproject.org
Date:   Wed Nov 7 11:43:04 2012 -0800

Merge branch 'bug7350' of ssh://git-rw.torproject.org/user/andrea/tor

 changes/bug7350  |5 +
 src/or/channel.c |   32 ++--
 src/or/circuitlist.c |   14 --
 3 files changed, 39 insertions(+), 12 deletions(-)

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Use SIMPLEQ, not smartlist_t, for channel cell queues.

2012-10-30 Thread andrea
commit 7c9954a02abd16e5c74c2a5dea9ed0f65af230be
Author: Nick Mathewson ni...@torproject.org
Date:   Fri Oct 12 17:58:01 2012 -0400

Use SIMPLEQ, not smartlist_t, for channel cell queues.

This lets  us use fewer memory allocations, and avoid O(n^2) iterations
---
 src/or/channel.c |  158 --
 src/or/channel.h |9 +++-
 2 files changed, 66 insertions(+), 101 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index 6527288..b594d05 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -31,6 +31,7 @@
 
 typedef struct cell_queue_entry_s cell_queue_entry_t;
 struct cell_queue_entry_s {
+  SIMPLEQ_ENTRY(cell_queue_entry_s) next;
   enum {
 CELL_QUEUE_FIXED,
 CELL_QUEUE_VAR,
@@ -768,6 +769,10 @@ channel_init(channel_t *chan)
   /* Init next_circ_id */
   chan-next_circ_id = crypto_rand_int(1  15);
 
+  /* Initialize queues. */
+  SIMPLEQ_INIT(chan-incoming_queue);
+  SIMPLEQ_INIT(chan-outgoing_queue);
+
   /* Timestamp it */
   channel_timestamp_created(chan);
 }
@@ -861,6 +866,7 @@ channel_listener_free(channel_listener_t *chan_l)
 static void
 channel_force_free(channel_t *chan)
 {
+  cell_queue_entry_t *cell, *cell_tmp;
   tor_assert(chan);
 
   /* Call a free method if there is one */
@@ -869,26 +875,16 @@ channel_force_free(channel_t *chan)
   channel_clear_remote_end(chan);
 
   /* We might still have a cell queue; kill it */
-  if (chan-incoming_queue) {
-SMARTLIST_FOREACH_BEGIN(chan-incoming_queue,
-cell_queue_entry_t *, q) {
-  cell_queue_entry_free(q, 0);
-} SMARTLIST_FOREACH_END(q);
-
-smartlist_free(chan-incoming_queue);
-chan-incoming_queue = NULL;
+  SIMPLEQ_FOREACH_SAFE(cell, chan-incoming_queue, next, cell_tmp) {
+  cell_queue_entry_free(cell, 0);
   }
+  SIMPLEQ_INIT(chan-incoming_queue);
 
   /* Outgoing cell queue is similar, but we can have to free packed cells */
-  if (chan-outgoing_queue) {
-SMARTLIST_FOREACH_BEGIN(chan-outgoing_queue,
-cell_queue_entry_t *, q) {
-  cell_queue_entry_free(q, 0);
-} SMARTLIST_FOREACH_END(q);
-
-smartlist_free(chan-outgoing_queue);
-chan-outgoing_queue = NULL;
+  SIMPLEQ_FOREACH_SAFE(cell, chan-outgoing_queue, next, cell_tmp) {
+cell_queue_entry_free(cell, 0);
   }
+  SIMPLEQ_INIT(chan-outgoing_queue);
 
   tor_free(chan);
 }
@@ -1046,8 +1042,7 @@ channel_set_cell_handlers(channel_t *chan,
   chan-var_cell_handler = var_cell_handler;
 
   /* Re-run the queue if we have one and there's any reason to */
-  if (chan-incoming_queue 
-  (smartlist_len(chan-incoming_queue)  0) 
+  if (! SIMPLEQ_EMPTY(chan-incoming_queue) 
   try_again 
   (chan-cell_handler ||
chan-var_cell_handler)) channel_process_cells(chan);
@@ -1669,9 +1664,8 @@ channel_write_cell_queue_entry(channel_t *chan, 
cell_queue_entry_t *q)
   }
 
   /* Can we send it right out?  If so, try */
-  if (!(chan-outgoing_queue 
-(smartlist_len(chan-outgoing_queue)  0)) 
-   chan-state == CHANNEL_STATE_OPEN) {
+  if (SIMPLEQ_EMPTY(chan-outgoing_queue) 
+  chan-state == CHANNEL_STATE_OPEN) {
 /* Pick the right write function for this cell type and save the result */
 switch (q-type) {
   case CELL_QUEUE_FIXED:
@@ -1707,14 +1701,12 @@ channel_write_cell_queue_entry(channel_t *chan, 
cell_queue_entry_t *q)
 
   if (!sent) {
 /* Not sent, queue it */
-if (!(chan-outgoing_queue))
-  chan-outgoing_queue = smartlist_new();
 /*
  * We have to copy the queue entry passed in, since the caller probably
  * used the stack.
  */
 tmp = cell_queue_entry_dup(q);
-smartlist_add(chan-outgoing_queue, tmp);
+SIMPLEQ_INSERT_TAIL(chan-outgoing_queue, tmp, next);
 /* Try to process the queue? */
 if (chan-state == CHANNEL_STATE_OPEN) channel_flush_cells(chan);
   }
@@ -1900,19 +1892,15 @@ channel_change_state(channel_t *chan, channel_state_t 
to_state)
 channel_do_open_actions(chan);
 
 /* Check for queued cells to process */
-if (chan-incoming_queue 
-smartlist_len(chan-incoming_queue)  0)
+if (! SIMPLEQ_EMPTY(chan-incoming_queue))
   channel_process_cells(chan);
-if (chan-outgoing_queue 
-smartlist_len(chan-outgoing_queue)  0)
+if (! SIMPLEQ_EMPTY(chan-outgoing_queue))
   channel_flush_cells(chan);
   } else if (to_state == CHANNEL_STATE_CLOSED ||
  to_state == CHANNEL_STATE_ERROR) {
 /* Assert that all queues are empty */
-tor_assert(!(chan-incoming_queue) ||
-smartlist_len(chan-incoming_queue) == 0);
-tor_assert(!(chan-outgoing_queue) ||
-smartlist_len(chan-outgoing_queue) == 0);
+tor_assert(SIMPLEQ_EMPTY(chan-incoming_queue));
+tor_assert(SIMPLEQ_EMPTY(chan-outgoing_queue));
   }
 }
 
@@ -2086,16 +2074,9 @@ channel_flush_some_cells_from_outgoing_queue(channel_t 
*chan,
   /* If we aren't in CHANNEL_STATE_OPEN, nothing goes through 

[tor-commits] [tor/master] Add a copy of OpenBSD's sys/queue.h as tor_queue.h

2012-10-30 Thread andrea
commit b555388dac71696c6a1028805094e16b5e5b2b82
Author: Nick Mathewson ni...@torproject.org
Date:   Fri Oct 12 17:05:06 2012 -0400

Add a copy of OpenBSD's sys/queue.h as tor_queue.h

There are as many divergent implementations of sys/queue.h as there
are operating systems shipping it, it would seem.  They have some code
in common, but have drifted apart, and have added other stuff named
differently.  So I'm taking a relatively sane one, and hoping for the
best.

I'm taking OpenBSD's in particular because of the lack of external
dependencies, the presence of a CIRCLEQ (we could use one of those in
places), and the liberal licensing terms.

I'm naming the file tor_queue.h, since historically we've run into
trouble having headers with the same names as system headers (log.h,
for example.)
---
 LICENSE |   29 +++
 changes/bsd_queue   |7 +
 src/ext/README  |8 +
 src/ext/include.am  |3 +-
 src/ext/tor_queue.h |  568 +++
 5 files changed, 614 insertions(+), 1 deletions(-)

diff --git a/LICENSE b/LICENSE
index 47eaf97..3058377 100644
--- a/LICENSE
+++ b/LICENSE
@@ -70,6 +70,35 @@ under the following license:
  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+===
+src/ext/tor_queue.h is licensed under the following license:
+
+ * Copyright (c) 1991, 1993
+ *  The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ *may be used to endorse or promote products derived from this software
+ *without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
 
 ===
 src/config/geoip is licensed under the following license:
diff --git a/changes/bsd_queue b/changes/bsd_queue
new file mode 100644
index 000..024ca6f
--- /dev/null
+++ b/changes/bsd_queue
@@ -0,0 +1,7 @@
+  o Code simplification and refactoring:
+- Start using OpenBSD's implementation of queue.h, so that we don't
+  need to hand-roll our own pointer and list structures whenever we
+  need them. (We can't rely on a sys/queue.h, since some operating
+  systems don't have them, and the ones that do have them don't all
+  present the same extensions.)
+
diff --git a/src/ext/README b/src/ext/README
index 2c303c1..7aeaba5 100644
--- a/src/ext/README
+++ b/src/ext/README
@@ -29,3 +29,11 @@ tinytest_macros.h
 
 A unit testing framework. https://github.com/nmathewson/tinytest
 
+tor_queue.h
+
+A copy of sys/queue.h from OpenBSD.  We keep our own copy rather
+than using sys/queue.h, since some platforms don't have a
+sys/queue.h, and the ones that do have diverged in incompatible
+ways.  (CIRCLEQ or no CIRCLEQ? SIMPLQ or STAILQ?)
+
+
diff --git a/src/ext/include.am b/src/ext/include.am
index fa9ee94..ea7e58e 100644
--- a/src/ext/include.am
+++ b/src/ext/include.am
@@ -9,7 +9,8 @@ EXTHEADERS = \
   src/ext/tinytest.h   \
   src/ext/strlcat.c\
   src/ext/strlcpy.c\
-  src/ext/tinytest_macros.h
+  src/ext/tinytest_macros.h \
+  src/ext/tor_queue.h
 
 noinst_HEADERS+= $(EXTHEADERS)
 
diff --git a/src/ext/tor_queue.h b/src/ext/tor_queue.h
new file mode 100644
index 000..622301d
--- /dev/null
+++ b/src/ext/tor_queue.h
@@ -0,0 +1,568 @@
+/* $OpenBSD: queue.h,v 1.36 2012/04/11 13:29:14 naddy Exp $*/
+/* $NetBSD: 

[tor-commits] [tor/master] Try refactoring channel list to use HT_ and LIST_ stuff directly

2012-10-30 Thread andrea
commit 2b10e99eb093e1e5e699db355e0c54342fa693b5
Author: Nick Mathewson ni...@torproject.org
Date:   Fri Oct 12 20:16:43 2012 -0400

Try refactoring channel list to use HT_ and LIST_ stuff directly
---
 src/or/channel.c |  191 +-
 src/or/channel.h |4 +-
 2 files changed, 75 insertions(+), 120 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index b594d05..7f3c6f5 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -81,7 +81,37 @@ static uint64_t n_channels_allocated = 0;
  * If more than one channel exists, follow the next_with_same_id pointer
  * as a linked list.
  */
-static digestmap_t *channel_identity_map = NULL;
+HT_HEAD(channel_idmap, channel_idmap_entry_s) channel_identity_map =
+  HT_INITIALIZER();
+
+typedef struct channel_idmap_entry_s {
+  HT_ENTRY(channel_idmap_entry_s) node;
+  uint8_t digest[DIGEST_LEN];
+  LIST_HEAD(channel_list_s, channel_s) channel_list;
+} channel_idmap_entry_t;
+
+static INLINE unsigned
+channel_idmap_hash(const channel_idmap_entry_t *ent)
+{
+  const unsigned *a = (const unsigned *)ent-digest;
+#if SIZEOF_INT == 4
+  return a[0] ^ a[1] ^ a[2] ^ a[3] ^ a[4];
+#elif SIZEOF_INT == 8
+  return a[0] ^ a[1];
+#endif
+}
+
+static INLINE int
+channel_idmap_eq(const channel_idmap_entry_t *a,
+  const channel_idmap_entry_t *b)
+{
+  return tor_memeq(a-digest, b-digest, DIGEST_LEN);
+}
+
+HT_PROTOTYPE(channel_idmap, channel_idmap_entry_s, node, channel_idmap_hash,
+ channel_idmap_eq);
+HT_GENERATE(channel_idmap, channel_idmap_entry_s, node, channel_idmap_hash,
+channel_idmap_eq, 0.5, tor_malloc, tor_realloc, _tor_free);
 
 static cell_queue_entry_t * cell_queue_entry_dup(cell_queue_entry_t *q);
 static void cell_queue_entry_free(cell_queue_entry_t *q, int handed_off);
@@ -505,7 +535,7 @@ channel_listener_unregister(channel_listener_t *chan_l)
 static void
 channel_add_to_digest_map(channel_t *chan)
 {
-  channel_t *tmp;
+  channel_idmap_entry_t *ent, search;
 
   tor_assert(chan);
 
@@ -517,23 +547,15 @@ channel_add_to_digest_map(channel_t *chan)
   /* Assert that there is a digest */
   tor_assert(!tor_digest_is_zero(chan-identity_digest));
 
-  /* Allocate the identity map if we have to */
-  if (!channel_identity_map) channel_identity_map = digestmap_new();
-
-  /* Insert it */
-  tmp = digestmap_set(channel_identity_map,
-  chan-identity_digest,
-  chan);
-  if (tmp) {
-/* There already was one, this goes at the head of the list */
-chan-next_with_same_id = tmp;
-chan-prev_with_same_id = NULL;
-tmp-prev_with_same_id = chan;
-  } else {
-/* First with this digest */
-chan-next_with_same_id = NULL;
-chan-prev_with_same_id = NULL;
+  memcpy(search.digest, chan-identity_digest, DIGEST_LEN);
+  ent = HT_FIND(channel_idmap, channel_identity_map, search);
+  if (! ent) {
+ent = tor_malloc(sizeof(channel_idmap_entry_t));
+memcpy(ent-digest, chan-identity_digest, DIGEST_LEN);
+LIST_INIT(ent-channel_list);
+HT_INSERT(channel_idmap, channel_identity_map, ent);
   }
+  LIST_INSERT_HEAD(ent-channel_list, chan, next_with_same_id);
 
   log_debug(LD_CHANNEL,
 Added channel %p (global ID  U64_FORMAT ) 
@@ -553,13 +575,14 @@ channel_add_to_digest_map(channel_t *chan)
 static void
 channel_remove_from_digest_map(channel_t *chan)
 {
-  channel_t *tmp;
+  channel_idmap_entry_t *ent, search;
 
   tor_assert(chan);
 
   /* Assert that there is a digest */
   tor_assert(!tor_digest_is_zero(chan-identity_digest));
 
+#if 0
   /* Make sure we have a map */
   if (!channel_identity_map) {
 /*
@@ -584,66 +607,29 @@ channel_remove_from_digest_map(channel_t *chan)
 
 return;
   }
+#endif
 
-  /* Look for it in the map */
-  tmp = digestmap_get(channel_identity_map, chan-identity_digest);
-  if (tmp) {
-/* Okay, it's here */
-/* Look for this channel */
-while (tmp  tmp != chan) {
-  tmp = tmp-next_with_same_id;
-}
+  /* Pull it out of its list, wherever that list is */
+  LIST_REMOVE(chan, next_with_same_id);
 
-if (tmp == chan) {
-  /* Found it, good */
-  if (chan-next_with_same_id) {
-chan-next_with_same_id-prev_with_same_id = chan-prev_with_same_id;
-  }
-  /* else we're the tail of the list */
-  if (chan-prev_with_same_id) {
-/* We're not the head of the list, so we can *just* unlink */
-chan-prev_with_same_id-next_with_same_id = chan-next_with_same_id;
-  } else {
-/* We're the head, so we have to point the digest map entry at our
- * next if we have one, or remove it if we're also the tail */
-if (chan-next_with_same_id) {
-  digestmap_set(channel_identity_map,
-chan-identity_digest,
-chan-next_with_same_id);
-} else {
-  digestmap_remove(channel_identity_map,
-   chan-identity_digest);
-  

[tor-commits] [tor/master] Merge branch 'bsd_queue' of ssh://git-rw.torproject.org/nickm/tor

2012-10-30 Thread andrea
commit be371250305b0ac50c1fafda8acd13812894ab92
Merge: 03b3216 2b10e99
Author: Andrea Shepard and...@torproject.org
Date:   Tue Oct 30 14:39:14 2012 -0700

Merge branch 'bsd_queue' of ssh://git-rw.torproject.org/nickm/tor

 LICENSE |   29 +++
 changes/bsd_queue   |7 +
 src/ext/README  |8 +
 src/ext/include.am  |3 +-
 src/ext/tor_queue.h |  568 +++
 src/or/channel.c|  349 ---
 src/or/channel.h|   13 +-
 7 files changed, 755 insertions(+), 222 deletions(-)

diff --cc src/or/channel.c
index 5552d39,7f3c6f5..cd5972f
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@@ -82,7 -81,37 +83,37 @@@ static uint64_t n_channels_allocated = 
   * If more than one channel exists, follow the next_with_same_id pointer
   * as a linked list.
   */
- static digestmap_t *channel_identity_map = NULL;
+ HT_HEAD(channel_idmap, channel_idmap_entry_s) channel_identity_map =
+   HT_INITIALIZER();
+ 
+ typedef struct channel_idmap_entry_s {
+   HT_ENTRY(channel_idmap_entry_s) node;
+   uint8_t digest[DIGEST_LEN];
+   LIST_HEAD(channel_list_s, channel_s) channel_list;
+ } channel_idmap_entry_t;
+ 
+ static INLINE unsigned
+ channel_idmap_hash(const channel_idmap_entry_t *ent)
+ {
+   const unsigned *a = (const unsigned *)ent-digest;
+ #if SIZEOF_INT == 4
+   return a[0] ^ a[1] ^ a[2] ^ a[3] ^ a[4];
+ #elif SIZEOF_INT == 8
+   return a[0] ^ a[1];
+ #endif
+ }
+ 
+ static INLINE int
+ channel_idmap_eq(const channel_idmap_entry_t *a,
+   const channel_idmap_entry_t *b)
+ {
+   return tor_memeq(a-digest, b-digest, DIGEST_LEN);
+ }
+ 
+ HT_PROTOTYPE(channel_idmap, channel_idmap_entry_s, node, channel_idmap_hash,
+  channel_idmap_eq);
+ HT_GENERATE(channel_idmap, channel_idmap_entry_s, node, channel_idmap_hash,
 -channel_idmap_eq, 0.5, tor_malloc, tor_realloc, _tor_free);
++channel_idmap_eq, 0.5, tor_malloc, tor_realloc, tor_free_);
  
  static cell_queue_entry_t * cell_queue_entry_dup(cell_queue_entry_t *q);
  static void cell_queue_entry_free(cell_queue_entry_t *q, int handed_off);
@@@ -881,52 -832,25 +852,43 @@@ channel_listener_free(channel_listener_
  static void
  channel_force_free(channel_t *chan)
  {
+   cell_queue_entry_t *cell, *cell_tmp;
tor_assert(chan);
  
 +  log_debug(LD_CHANNEL,
 +Force-freeing channel  U64_FORMAT  at %p,
 +U64_PRINTF_ARG(chan-global_identifier), chan);
 +
 +  /*
 +   * Get rid of cmux policy before we do anything, so cmux policies don't
 +   * see channels in weird half-freed states.
 +   */
 +  if (chan-cmux) {
 +circuitmux_set_policy(chan-cmux, NULL);
 +  }
 +
/* Call a free method if there is one */
if (chan-free) chan-free(chan);
  
channel_clear_remote_end(chan);
  
 +  /* Get rid of cmux */
 +  if (chan-cmux) {
 +circuitmux_free(chan-cmux);
 +chan-cmux = NULL;
 +  }
 +
/* We might still have a cell queue; kill it */
-   if (chan-incoming_queue) {
- SMARTLIST_FOREACH_BEGIN(chan-incoming_queue,
- cell_queue_entry_t *, q) {
-   cell_queue_entry_free(q, 0);
- } SMARTLIST_FOREACH_END(q);
- 
- smartlist_free(chan-incoming_queue);
- chan-incoming_queue = NULL;
+   SIMPLEQ_FOREACH_SAFE(cell, chan-incoming_queue, next, cell_tmp) {
+   cell_queue_entry_free(cell, 0);
}
+   SIMPLEQ_INIT(chan-incoming_queue);
  
/* Outgoing cell queue is similar, but we can have to free packed cells */
-   if (chan-outgoing_queue) {
- SMARTLIST_FOREACH_BEGIN(chan-outgoing_queue,
- cell_queue_entry_t *, q) {
-   cell_queue_entry_free(q, 0);
- } SMARTLIST_FOREACH_END(q);
- 
- smartlist_free(chan-outgoing_queue);
- chan-outgoing_queue = NULL;
+   SIMPLEQ_FOREACH_SAFE(cell, chan-outgoing_queue, next, cell_tmp) {
+ cell_queue_entry_free(cell, 0);
}
+   SIMPLEQ_INIT(chan-outgoing_queue);
  
tor_free(chan);
  }
diff --cc src/or/channel.h
index d90335c,1e7279a..d210655
--- a/src/or/channel.h
+++ b/src/or/channel.h
@@@ -6,10 -6,11 +6,11 @@@
   * \brief Header file for channel.c
   **/
  
 -#ifndef _TOR_CHANNEL_H
 -#define _TOR_CHANNEL_H
 +#ifndef TOR_CHANNEL_H
 +#define TOR_CHANNEL_H
  
  #include or.h
+ #include tor_queue.h
  #include circuitmux.h
  
  /* Channel handler function pointer typedefs */

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Correctly clear cmux policies and free cmux in channel_free() and channel_force_free()

2012-10-15 Thread andrea
commit 9ef286ec8f10f88a5b30f48efd502b9c87933762
Author: Andrea Shepard and...@torproject.org
Date:   Mon Oct 15 06:32:44 2012 -0700

Correctly clear cmux policies and free cmux in channel_free() and 
channel_force_free()
---
 src/or/channel.c |   23 +++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index 6527288..56e15b4 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -808,11 +808,20 @@ channel_free(channel_t *chan)
   /* It must be deregistered */
   tor_assert(!(chan-registered));
 
+  /*
+   * Get rid of cmux policy before we do anything, so cmux policies don't
+   * see channels in weird half-freed states.
+   */
+  if (chan-cmux) {
+circuitmux_set_policy(chan-cmux, NULL);
+  }
+
   /* Call a free method if there is one */
   if (chan-free) chan-free(chan);
 
   channel_clear_remote_end(chan);
 
+  /* Get rid of cmux */
   if (chan-cmux) {
 circuitmux_detach_all_circuits(chan-cmux);
 circuitmux_free(chan-cmux);
@@ -863,11 +872,25 @@ channel_force_free(channel_t *chan)
 {
   tor_assert(chan);
 
+  /*
+   * Get rid of cmux policy before we do anything, so cmux policies don't
+   * see channels in weird half-freed states.
+   */
+  if (chan-cmux) {
+circuitmux_set_policy(chan-cmux, NULL);
+  }
+
   /* Call a free method if there is one */
   if (chan-free) chan-free(chan);
 
   channel_clear_remote_end(chan);
 
+  /* Get rid of cmux */
+  if (chan-cmux) {
+circuitmux_free(chan-cmux);
+chan-cmux = NULL;
+  }
+
   /* We might still have a cell queue; kill it */
   if (chan-incoming_queue) {
 SMARTLIST_FOREACH_BEGIN(chan-incoming_queue,



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Add debug logging for channel_free() and channel_force_free()

2012-10-15 Thread andrea
commit 3894ca15080e48bc025333df494ab211168c94da
Author: Andrea Shepard and...@torproject.org
Date:   Mon Oct 15 06:46:23 2012 -0700

Add debug logging for channel_free() and channel_force_free()
---
 src/or/channel.c |8 
 1 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index 56e15b4..2642431 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -808,6 +808,10 @@ channel_free(channel_t *chan)
   /* It must be deregistered */
   tor_assert(!(chan-registered));
 
+  log_debug(LD_CHANNEL,
+Freeing channel  U64_FORMAT  at %p,
+U64_PRINTF_ARG(chan-global_identifier), chan);
+
   /*
* Get rid of cmux policy before we do anything, so cmux policies don't
* see channels in weird half-freed states.
@@ -872,6 +876,10 @@ channel_force_free(channel_t *chan)
 {
   tor_assert(chan);
 
+  log_debug(LD_CHANNEL,
+Force-freeing channel  U64_FORMAT  at %p,
+U64_PRINTF_ARG(chan-global_identifier), chan);
+
   /*
* Get rid of cmux policy before we do anything, so cmux policies don't
* see channels in weird half-freed states.



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Add debug logging to channel_listener_free()/channel_listener_force_free()

2012-10-15 Thread andrea
commit 99057014bae3b7a19ae9cf50cad2063a3c085e14
Author: Andrea Shepard and...@torproject.org
Date:   Mon Oct 15 07:56:35 2012 -0700

Add debug logging to channel_listener_free()/channel_listener_force_free()
---
 src/or/channel.c |   10 ++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index 2642431..1a7a988 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -848,6 +848,11 @@ channel_listener_free(channel_listener_t *chan_l)
 {
   if (!chan_l) return;
 
+  log_debug(LD_CHANNEL,
+Freeing channel_listener_t  U64_FORMAT  at %p,
+U64_PRINTF_ARG(chan_l-global_identifier),
+chan_l);
+
   /* It must be closed or errored */
   tor_assert(chan_l-state == CHANNEL_LISTENER_STATE_CLOSED ||
  chan_l-state == CHANNEL_LISTENER_STATE_ERROR);
@@ -935,6 +940,11 @@ channel_listener_force_free(channel_listener_t *chan_l)
 {
   tor_assert(chan_l);
 
+  log_debug(LD_CHANNEL,
+Force-freeing channel_listener_t  U64_FORMAT  at %p,
+U64_PRINTF_ARG(chan_l-global_identifier),
+chan_l);
+
   /* Call a free method if there is one */
   if (chan_l-free) chan_l-free(chan_l);
 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Close and free channel_tls_listener correctly in channel_tls_free_all()

2012-10-15 Thread andrea
commit ac227cf587c17fb2bdd10de4b320ea4df3632cd8
Author: Andrea Shepard and...@torproject.org
Date:   Mon Oct 15 11:37:14 2012 -0700

Close and free channel_tls_listener correctly in channel_tls_free_all()
---
 src/or/channeltls.c |   20 
 1 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/src/or/channeltls.c b/src/or/channeltls.c
index 1a2956b..62bb18b 100644
--- a/src/or/channeltls.c
+++ b/src/or/channeltls.c
@@ -216,14 +216,26 @@ channel_tls_start_listener(void)
 void
 channel_tls_free_all(void)
 {
+  channel_listener_t *old_listener = NULL;
+
   log_debug(LD_CHANNEL,
 Shutting down TLS channels...);
 
   if (channel_tls_listener) {
-channel_listener_unregister(channel_tls_listener);
-channel_listener_mark_for_close(channel_tls_listener);
-channel_listener_free(channel_tls_listener);
-channel_tls_listener = NULL;
+/*
+ * When we close it, channel_tls_listener will get nulled out, so save
+ * a pointer so we can free it.
+ */
+old_listener = channel_tls_listener;
+log_debug(LD_CHANNEL,
+  Closing channel_tls_listener with ID  U64_FORMAT
+   at %p.,
+  U64_PRINTF_ARG(old_listener-global_identifier),
+  old_listener);
+channel_listener_unregister(old_listener);
+channel_listener_mark_for_close(old_listener);
+channel_listener_free(old_listener);
+tor_assert(channel_tls_listener == NULL);
   }
 
   log_debug(LD_CHANNEL,



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Merge branch 'bug7087_2' of ssh://git-rw.torproject.org/user/andrea/tor

2012-10-15 Thread andrea
commit 94a030990986e6c731141da3969aeae3ec0f5ea8
Merge: 7e4c91e ac227cf
Author: Andrea Shepard and...@torproject.org
Date:   Mon Oct 15 13:04:55 2012 -0700

Merge branch 'bug7087_2' of ssh://git-rw.torproject.org/user/andrea/tor

 src/or/channel.c|   10 ++
 src/or/channeltls.c |   20 
 2 files changed, 26 insertions(+), 4 deletions(-)

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Make very sure to handle cells in-order on channels.

2012-10-11 Thread andrea
commit a45760b53b6aef609e3d48f9e0abb5e1550e44fb
Author: Nick Mathewson ni...@torproject.org
Date:   Thu Oct 11 00:35:58 2012 -0400

Make very sure to handle cells in-order on channels.

Fix on code for 6465, not yet in any release.
---
 src/or/channel.c |   23 +--
 1 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/src/or/channel.c b/src/or/channel.c
index b52db40..6527288 100644
--- a/src/or/channel.c
+++ b/src/or/channel.c
@@ -2427,6 +2427,8 @@ channel_listener_queue_incoming(channel_listener_t 
*listener,
 void
 channel_process_cells(channel_t *chan)
 {
+  smartlist_t *queue;
+  int putback = 0;
   tor_assert(chan);
   tor_assert(chan-state == CHANNEL_STATE_CLOSING ||
  chan-state == CHANNEL_STATE_MAINT ||
@@ -2442,17 +2444,20 @@ channel_process_cells(channel_t *chan)
   /* Nothing we can do if we have no cells */
   if (!(chan-incoming_queue)) return;
 
+  queue = chan-incoming_queue;
+  chan-incoming_queue = NULL;
   /*
* Process cells until we're done or find one we have no current handler
* for.
*/
-  SMARTLIST_FOREACH_BEGIN(chan-incoming_queue,
-  cell_queue_entry_t *, q) {
+  SMARTLIST_FOREACH_BEGIN(queue, cell_queue_entry_t *, q) {
 tor_assert(q);
 tor_assert(q-type == CELL_QUEUE_FIXED ||
q-type == CELL_QUEUE_VAR);
 
-if (q-type == CELL_QUEUE_FIXED 
+if (putback) {
+  smartlist_add(chan-incoming_queue, q);
+} else if (q-type == CELL_QUEUE_FIXED 
 chan-cell_handler) {
   /* Handle a fixed-length cell */
   tor_assert(q-u.fixed.cell);
@@ -2462,7 +2467,6 @@ channel_process_cells(channel_t *chan)
 q-u.fixed.cell, chan,
 U64_PRINTF_ARG(chan-global_identifier));
   chan-cell_handler(chan, q-u.fixed.cell);
-  SMARTLIST_DEL_CURRENT(chan-incoming_queue, q);
   tor_free(q);
 } else if (q-type == CELL_QUEUE_VAR 
chan-var_cell_handler) {
@@ -2474,19 +2478,18 @@ channel_process_cells(channel_t *chan)
 q-u.var.var_cell, chan,
 U64_PRINTF_ARG(chan-global_identifier));
   chan-var_cell_handler(chan, q-u.var.var_cell);
-  SMARTLIST_DEL_CURRENT(chan-incoming_queue, q);
   tor_free(q);
 } else {
   /* Can't handle this one */
-  break;
+  if (!chan-incoming_queue)
+chan-incoming_queue = smartlist_new();
+  smartlist_add(chan-incoming_queue, q);
+  putback = 1;
 }
   } SMARTLIST_FOREACH_END(q);
 
   /* If the list is empty, free it */
-  if (smartlist_len(chan-incoming_queue) == 0 ) {
-smartlist_free(chan-incoming_queue);
-chan-incoming_queue = NULL;
-  }
+  smartlist_free(queue);
 }
 
 /**

___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Fix make check-spaces in circuitbuild.c and router.h

2012-10-10 Thread andrea
commit 7f952da55334d3a3693d1c6e8531fd96730265db
Author: Andrea Shepard and...@persephoneslair.org
Date:   Wed Aug 1 02:38:43 2012 -0700

Fix make check-spaces in circuitbuild.c and router.h
---
 src/or/router.h |   11 ---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/src/or/router.h b/src/or/router.h
index c43c308..3964085 100644
--- a/src/or/router.h
+++ b/src/or/router.h
@@ -86,13 +86,18 @@ int router_pick_published_address(const or_options_t 
*options, uint32_t *addr);
 int router_rebuild_descriptor(int force);
 int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router,
  crypto_pk_t *ident_key);
-int extrainfo_dump_to_string(char **s, extrainfo_t *extrainfo,
- crypto_pk_t *ident_key);
 void router_get_prim_orport(const routerinfo_t *router,
-tor_addr_port_t *ap_out);
+tor_addr_port_t *addr_port_out);
+void router_get_pref_orport(const routerinfo_t *router,
+tor_addr_port_t *addr_port_out);
+void router_get_pref_ipv6_orport(const routerinfo_t *router,
+ tor_addr_port_t *addr_port_out);
+int router_ipv6_preferred(const routerinfo_t *router);
 int router_has_addr(const routerinfo_t *router, const tor_addr_t *addr);
 int router_has_orport(const routerinfo_t *router,
   const tor_addr_port_t *orport);
+int extrainfo_dump_to_string(char **s, extrainfo_t *extrainfo,
+ crypto_pk_t *ident_key);
 int is_legal_nickname(const char *s);
 int is_legal_nickname_or_hexdigest(const char *s);
 int is_legal_hexdigest(const char *s);



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Make reachabiity test in dirserv.c use channel_t

2012-10-10 Thread andrea
commit 35924435d22c2469ecbe06156c8069a928859d63
Author: Andrea Shepard and...@persephoneslair.org
Date:   Sat Aug 25 15:27:50 2012 -0700

Make reachabiity test in dirserv.c use channel_t
---
 src/or/dirserv.c |   10 ++
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index 0d98324..1480cb6 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -8,6 +8,8 @@
 #include buffers.h
 #include config.h
 #include confparse.h
+#include channel.h
+#include channeltls.h
 #include connection.h
 #include connection_or.h
 #include control.h
@@ -3410,8 +3412,8 @@ dirserv_single_reachability_test(time_t now, routerinfo_t 
*router)
   log_debug(LD_OR,Testing reachability of %s at %s:%u.,
 router-nickname, router-address, router-or_port);
   tor_addr_from_ipv4h(router_addr, router-addr);
-  connection_or_connect(router_addr, router-or_port,
-router-cache_info.identity_digest);
+  channel_tls_connect(router_addr, router-or_port,
+  router-cache_info.identity_digest);
 
   /* Possible IPv6. */
   if (get_options()-AuthDirHasIPv6Connectivity == 1 
@@ -3421,8 +3423,8 @@ dirserv_single_reachability_test(time_t now, routerinfo_t 
*router)
   router-nickname,
   tor_addr_to_str(addrstr, router-ipv6_addr, sizeof(addrstr), 1),
   router-ipv6_orport);
-connection_or_connect(router-ipv6_addr, router-ipv6_orport,
-  router-cache_info.identity_digest);
+channel_tls_connect(router-ipv6_addr, router-ipv6_orport,
+router-cache_info.identity_digest);
   }
 }
 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Convert relay.c/relay.h to channel_t

2012-10-10 Thread andrea
commit e136f7ccb4e671e33b6c92a48df819082291f5c1
Author: Andrea Shepard and...@persephoneslair.org
Date:   Sat Aug 25 14:30:01 2012 -0700

Convert relay.c/relay.h to channel_t

Note: this is a squashed commit; see branch bug6465_rebased_v2 of 
user/andrea/tor.git for full history of the following 10 commits:

Convert relay.c/relay.h to channel_t
Updating the timestamp if n_flushed  0 at the end of 
channel_flush_from_first_active_circuit() was redundant since 
channel_write_cell() et al. do it themselves.
Get rid of now-unnecessary time parameter in 
channel_flush_from_first_active_circuit()
Get rid of now-unnecessary time parameter in 
channel_flush_from_first_active_circuit() in connection_or.c
Add non-inlined external call for channeltls.c to free a packed_cell_t
Appease make check-spaces in relay.c
Replace channel_get_write_queue_len() with sufficient and easier to 
implement channel_has_queued_writes() in relay.c
Rename channel_touched_by_client() and client_used field for consistency 
with other timestamps in relay.c
Don't double-free packed cells in relay.c (channel_t Tor now bootstraps and 
works as a client)
Rearrange channel_t struct to use a union distinguishing listener from 
cell-bearing channels in relay.c
---
 src/or/connection.c |4 -
 src/or/relay.c  |  405 +--
 src/or/relay.h  |8 +-
 3 files changed, 236 insertions(+), 181 deletions(-)

diff --git a/src/or/connection.c b/src/or/connection.c
index 8e9c701..db234f1 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -265,9 +265,6 @@ or_connection_new(int socket_family)
 
   or_conn-timestamp_last_added_nonpadding = time(NULL);
 
-  or_conn-active_circuit_pqueue = smartlist_new();
-  or_conn-active_circuit_pqueue_last_recalibrated = cell_ewma_get_tick();
-
   return or_conn;
 }
 
@@ -508,7 +505,6 @@ _connection_free(connection_t *conn)
 or_conn-tls = NULL;
 or_handshake_state_free(or_conn-handshake_state);
 or_conn-handshake_state = NULL;
-smartlist_free(or_conn-active_circuit_pqueue);
 tor_free(or_conn-nickname);
   }
   if (conn-type == CONN_TYPE_AP) {
diff --git a/src/or/relay.c b/src/or/relay.c
index 4a50b71..3850562 100644
--- a/src/or/relay.c
+++ b/src/or/relay.c
@@ -14,6 +14,7 @@
 #define RELAY_PRIVATE
 #include or.h
 #include buffers.h
+#include channel.h
 #include circuitbuild.h
 #include circuitlist.h
 #include config.h
@@ -166,7 +167,7 @@ int
 circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
cell_direction_t cell_direction)
 {
-  or_connection_t *or_conn=NULL;
+  channel_t *chan = NULL;
   crypt_path_t *layer_hint=NULL;
   char recognized=0;
   int reason;
@@ -213,17 +214,17 @@ circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
   /* not recognized. pass it on. */
   if (cell_direction == CELL_DIRECTION_OUT) {
 cell-circ_id = circ-n_circ_id; /* switch it */
-or_conn = circ-n_conn;
+chan = circ-n_chan;
   } else if (! CIRCUIT_IS_ORIGIN(circ)) {
 cell-circ_id = TO_OR_CIRCUIT(circ)-p_circ_id; /* switch it */
-or_conn = TO_OR_CIRCUIT(circ)-p_conn;
+chan = TO_OR_CIRCUIT(circ)-p_chan;
   } else {
 log_fn(LOG_PROTOCOL_WARN, LD_OR,
Dropping unrecognized inbound cell on origin circuit.);
 return 0;
   }
 
-  if (!or_conn) {
+  if (!chan) {
 //  Can this splice stuff be done more cleanly?
 if (! CIRCUIT_IS_ORIGIN(circ) 
 TO_OR_CIRCUIT(circ)-rend_splice 
@@ -254,7 +255,7 @@ circuit_receive_relay_cell(cell_t *cell, circuit_t *circ,
   * we might kill the circ before we relay
   * the cells. */
 
-  append_cell_to_circuit_queue(circ, or_conn, cell, cell_direction, 0);
+  append_cell_to_circuit_queue(circ, chan, cell, cell_direction, 0);
   return 0;
 }
 
@@ -353,13 +354,13 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
cell_direction_t cell_direction,
crypt_path_t *layer_hint, streamid_t on_stream)
 {
-  or_connection_t *conn; /* where to send the cell */
+  channel_t *chan; /* where to send the cell */
 
   if (cell_direction == CELL_DIRECTION_OUT) {
 crypt_path_t *thishop; /* counter for repeated crypts */
-conn = circ-n_conn;
-if (!CIRCUIT_IS_ORIGIN(circ) || !conn) {
-  log_warn(LD_BUG,outgoing relay cell has n_conn==NULL. Dropping.);
+chan = circ-n_chan;
+if (!CIRCUIT_IS_ORIGIN(circ) || !chan) {
+  log_warn(LD_BUG,outgoing relay cell has n_chan==NULL. Dropping.);
   return 0; /* just drop it */
 }
 
@@ -388,14 +389,14 @@ circuit_package_relay_cell(cell_t *cell, circuit_t *circ,
   return 0; /* just drop it */
 }
 or_circ = TO_OR_CIRCUIT(circ);
-conn = or_circ-p_conn;
+chan = or_circ-p_chan;
 relay_set_digest(or_circ-p_digest, cell);
 if (relay_crypt_one_payload(or_circ-p_crypto, cell-payload

[tor-commits] [tor/master] Support channel_t in connection_edge.c

2012-10-10 Thread andrea
commit 4768c0efe3e9471cc367c3740d1a4ba0ab79626c
Author: Andrea Shepard and...@persephoneslair.org
Date:   Sat Aug 25 11:55:39 2012 -0700

Support channel_t in connection_edge.c
---
 src/or/connection_edge.c |   50 +++--
 1 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index ade3b48..9bcfca3 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -11,6 +11,7 @@
 
 #include or.h
 #include buffers.h
+#include channel.h
 #include circuitlist.h
 #include circuituse.h
 #include config.h
@@ -3068,27 +3069,30 @@ connection_exit_begin_conn(cell_t *cell, circuit_t 
*circ)
   tor_free(address);
   return 0;
 }
-if (or_circ  or_circ-p_conn  !options-AllowSingleHopExits 
-(or_circ-is_first_hop ||
- (!connection_or_digest_is_known_relay(
-   or_circ-p_conn-identity_digest) 
+if (or_circ  or_circ-p_chan) {
+  tor_assert(!(or_circ-p_chan-is_listener));
+  if (!options-AllowSingleHopExits 
+   (or_circ-is_first_hop ||
+(!connection_or_digest_is_known_relay(
+or_circ-p_chan-u.cell_chan.identity_digest) 
   should_refuse_unknown_exits(options {
-  /* Don't let clients use us as a single-hop proxy, unless the user
-   * has explicitly allowed that in the config. It attracts attackers
-   * and users who'd be better off with, well, single-hop proxies.
-   */
-  log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
- Attempt by %s to open a stream %s. Closing.,
- safe_str(or_circ-p_conn-_base.address),
- or_circ-is_first_hop ? on first hop of circuit :
- from unknown relay);
-  relay_send_end_cell_from_edge(rh.stream_id, circ,
-or_circ-is_first_hop ?
-  END_STREAM_REASON_TORPROTOCOL :
-  END_STREAM_REASON_MISC,
-NULL);
-  tor_free(address);
-  return 0;
+/* Don't let clients use us as a single-hop proxy, unless the user
+ * has explicitly allowed that in the config. It attracts attackers
+ * and users who'd be better off with, well, single-hop proxies.
+ */
+log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
+   Attempt by %s to open a stream %s. Closing.,
+   safe_str(channel_get_canonical_remote_descr(or_circ-p_chan)),
+   or_circ-is_first_hop ? on first hop of circuit :
+   from unknown relay);
+relay_send_end_cell_from_edge(rh.stream_id, circ,
+  or_circ-is_first_hop ?
+END_STREAM_REASON_TORPROTOCOL :
+END_STREAM_REASON_MISC,
+  NULL);
+tor_free(address);
+return 0;
+  }
 }
   } else if (rh.command == RELAY_COMMAND_BEGIN_DIR) {
 if (!directory_permits_begindir_requests(options) ||
@@ -3101,8 +3105,8 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
  * caller might want to know whether his IP address has changed, and
  * we might already have corrected _base.addr[ess] for the relay's
  * canonical IP address. */
-if (or_circ  or_circ-p_conn)
-  address = tor_dup_addr(or_circ-p_conn-real_addr);
+if (or_circ  or_circ-p_chan)
+  address = tor_strdup(channel_get_actual_remote_descr(or_circ-p_chan));
 else
   address = tor_strdup(127.0.0.1);
 port = 1; /*  This value is never actually used anywhere, and there
@@ -3178,8 +3182,6 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
 
   if (rh.command == RELAY_COMMAND_BEGIN_DIR) {
 tor_assert(or_circ);
-if (or_circ-p_conn  !tor_addr_is_null(or_circ-p_conn-real_addr))
-  tor_addr_copy(n_stream-_base.addr, or_circ-p_conn-real_addr);
 return connection_exit_connect_dir(n_stream);
   }
 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Query circuit count from associated channel of or_conn in control.c

2012-10-10 Thread andrea
commit 6cce6241dd4405f6cf21057f9913e07633cf18bb
Author: Andrea Shepard and...@persephoneslair.org
Date:   Thu Aug 30 15:27:55 2012 -0700

Query circuit count from associated channel of or_conn in control.c
---
 src/or/control.c |8 +++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/src/or/control.c b/src/or/control.c
index 74c6acc..5c05fe1 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -12,6 +12,8 @@
 
 #include or.h
 #include buffers.h
+#include channel.h
+#include channeltls.h
 #include circuitbuild.h
 #include circuitlist.h
 #include circuituse.h
@@ -3822,7 +3824,11 @@ control_event_or_conn_status(or_connection_t *conn, 
or_conn_status_event_t tp,
   log_warn(LD_BUG, Unrecognized status code %d, (int)tp);
   return 0;
 }
-  ncircs = circuit_count_pending_on_or_conn(conn);
+  if (conn-chan) {
+ncircs = circuit_count_pending_on_channel(TLS_CHAN_TO_BASE(conn-chan));
+  } else {
+ncircs = 0;
+  }
   ncircs += conn-n_circuits;
   if (ncircs  (tp == OR_CONN_EVENT_FAILED || tp == OR_CONN_EVENT_CLOSED)) {
 tor_snprintf(ncircs_buf, sizeof(ncircs_buf), %sNCIRCS=%d,



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Use channel_t in cpuworker.c

2012-10-10 Thread andrea
commit 77dac97354974e8a819d8e35ad4e7a7619b4
Author: Andrea Shepard and...@persephoneslair.org
Date:   Thu Aug 30 15:47:05 2012 -0700

Use channel_t in cpuworker.c

Note: this is a squashed commit; see branch bug6465_rebased_v2 of 
user/andrea/tor.git for full history of the following 2 commits:

Use channel_t in cpuworker.c
Fix bug in channel_t usage in cpuworker.c that was killing relaying on 
channel_t-ized Tor.  The tags passed to the worker now have a channel ID, not a 
connection ID.
---
 src/or/cpuworker.c |   36 +++-
 1 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c
index 0255227..a78518f 100644
--- a/src/or/cpuworker.c
+++ b/src/or/cpuworker.c
@@ -14,6 +14,8 @@
 
 #include or.h
 #include buffers.h
+#include channel.h
+#include channeltls.h
 #include circuitbuild.h
 #include circuitlist.h
 #include config.h
@@ -68,19 +70,20 @@ connection_cpu_finished_flushing(connection_t *conn)
 /** Pack global_id and circ_id; set *tag to the result. (See note on
  * cpuworker_main for wire format.) */
 static void
-tag_pack(char *tag, uint64_t conn_id, circid_t circ_id)
+tag_pack(char *tag, uint64_t chan_id, circid_t circ_id)
 {
   /* RETHINK THIS WHOLE MESS  !NM NM NM NM*/
-  set_uint64(tag, conn_id);
+  /* DOUBLEPLUSTHIS AS AS AS AS*/
+  set_uint64(tag, chan_id);
   set_uint16(tag+8, circ_id);
 }
 
 /** Unpack btag/b into addr, port, and circ_id.
  */
 static void
-tag_unpack(const char *tag, uint64_t *conn_id, circid_t *circ_id)
+tag_unpack(const char *tag, uint64_t *chan_id, circid_t *circ_id)
 {
-  *conn_id = get_uint64(tag);
+  *chan_id = get_uint64(tag);
   *circ_id = get_uint16(tag+8);
 }
 
@@ -131,10 +134,9 @@ connection_cpu_process_inbuf(connection_t *conn)
 {
   char success;
   char buf[LEN_ONION_RESPONSE];
-  uint64_t conn_id;
+  uint64_t chan_id;
   circid_t circ_id;
-  connection_t *tmp_conn;
-  or_connection_t *p_conn = NULL;
+  channel_t *p_chan = NULL;
   circuit_t *circ;
 
   tor_assert(conn);
@@ -152,15 +154,15 @@ connection_cpu_process_inbuf(connection_t *conn)
 connection_fetch_from_buf(buf,LEN_ONION_RESPONSE-1,conn);
 
 /* parse out the circ it was talking about */
-tag_unpack(buf, conn_id, circ_id);
+tag_unpack(buf, chan_id, circ_id);
 circ = NULL;
-tmp_conn = connection_get_by_global_id(conn_id);
-if (tmp_conn  !tmp_conn-marked_for_close 
-tmp_conn-type == CONN_TYPE_OR)
-  p_conn = TO_OR_CONN(tmp_conn);
+log_debug(LD_OR,
+  Unpacking cpuworker reply, chan_id is %lu, circ_id is %d,
+  chan_id, circ_id);
+p_chan = channel_find_by_global_id(chan_id);
 
-if (p_conn)
-  circ = circuit_get_by_circid_orconn(circ_id, p_conn);
+if (p_chan)
+  circ = circuit_get_by_circid_channel(circ_id, p_chan);
 
 if (success == 0) {
   log_debug(LD_OR,
@@ -475,12 +477,12 @@ assign_onionskin_to_cpuworker(connection_t *cpuworker,
 
 tor_assert(cpuworker);
 
-if (!circ-p_conn) {
-  log_info(LD_OR,circ-p_conn gone. Failing circ.);
+if (!circ-p_chan) {
+  log_info(LD_OR,circ-p_chan gone. Failing circ.);
   tor_free(onionskin);
   return -1;
 }
-tag_pack(tag, circ-p_conn-_base.global_identifier,
+tag_pack(tag, circ-p_chan-global_identifier,
  circ-p_circ_id);
 
 cpuworker-state = CPUWORKER_STATE_BUSY_ONION;



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Switch onion.c over to channel_t

2012-10-10 Thread andrea
commit 8b14db9628f0e8982e894034e86c8efdd78cff32
Author: Andrea Shepard and...@persephoneslair.org
Date:   Sun Sep 2 21:13:25 2012 -0700

Switch onion.c over to channel_t
---
 src/or/onion.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/or/onion.c b/src/or/onion.c
index ff1556c..17d8e77 100644
--- a/src/or/onion.c
+++ b/src/or/onion.c
@@ -106,7 +106,7 @@ onion_next_task(char **onionskin_out)
 return NULL; /* no onions pending, we're done */
 
   tor_assert(ol_list-circ);
-  tor_assert(ol_list-circ-p_conn); /* make sure it's still valid */
+  tor_assert(ol_list-circ-p_chan); /* make sure it's still valid */
   tor_assert(ol_length  0);
   circ = ol_list-circ;
   *onionskin_out = ol_list-onionskin;



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Convert rendmid.c to channel_t

2012-10-10 Thread andrea
commit f0f87cb68a22feaf552a18b521d3313d843f8793
Author: Andrea Shepard and...@persephoneslair.org
Date:   Tue Sep 4 01:44:19 2012 -0700

Convert rendmid.c to channel_t
---
 src/or/rendmid.c |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/or/rendmid.c b/src/or/rendmid.c
index bacd0ef..00bbd28 100644
--- a/src/or/rendmid.c
+++ b/src/or/rendmid.c
@@ -35,7 +35,7 @@ rend_mid_establish_intro(or_circuit_t *circ, const uint8_t 
*request,
Received an ESTABLISH_INTRO request on circuit %d,
circ-p_circ_id);
 
-  if (circ-_base.purpose != CIRCUIT_PURPOSE_OR || circ-_base.n_conn) {
+  if (circ-_base.purpose != CIRCUIT_PURPOSE_OR || circ-_base.n_chan) {
 log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
  Rejecting ESTABLISH_INTRO on non-OR or non-edge circuit.);
 reason = END_CIRC_REASON_TORPROTOCOL;
@@ -142,7 +142,7 @@ rend_mid_introduce(or_circuit_t *circ, const uint8_t 
*request,
   log_info(LD_REND, Received an INTRODUCE1 request on circuit %d,
circ-p_circ_id);
 
-  if (circ-_base.purpose != CIRCUIT_PURPOSE_OR || circ-_base.n_conn) {
+  if (circ-_base.purpose != CIRCUIT_PURPOSE_OR || circ-_base.n_chan) {
 log_warn(LD_PROTOCOL,
  Rejecting INTRODUCE1 on non-OR or non-edge circuit %d.,
  circ-p_circ_id);
@@ -224,7 +224,7 @@ rend_mid_establish_rendezvous(or_circuit_t *circ, const 
uint8_t *request,
   log_info(LD_REND, Received an ESTABLISH_RENDEZVOUS request on circuit %d,
circ-p_circ_id);
 
-  if (circ-_base.purpose != CIRCUIT_PURPOSE_OR || circ-_base.n_conn) {
+  if (circ-_base.purpose != CIRCUIT_PURPOSE_OR || circ-_base.n_chan) {
 log_warn(LD_PROTOCOL,
  Tried to establish rendezvous on non-OR or non-edge circuit.);
 goto err;
@@ -277,7 +277,7 @@ rend_mid_rendezvous(or_circuit_t *circ, const uint8_t 
*request,
   char hexid[9];
   int reason = END_CIRC_REASON_INTERNAL;
 
-  if (circ-_base.purpose != CIRCUIT_PURPOSE_OR || circ-_base.n_conn) {
+  if (circ-_base.purpose != CIRCUIT_PURPOSE_OR || circ-_base.n_chan) {
 log_info(LD_REND,
  Tried to complete rendezvous on non-OR or non-edge circuit %d.,
  circ-p_circ_id);



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Use dirreq_id from channel_t when appropriate

2012-10-10 Thread andrea
commit 28f108bcceab59fcf9f27e33065f64bfdb0f159a
Author: Andrea Shepard and...@persephoneslair.org
Date:   Tue Sep 4 00:33:16 2012 -0700

Use dirreq_id from channel_t when appropriate
---
 src/or/channel.h |5 -
 src/or/connection_edge.c |4 ++--
 src/or/directory.c   |8 
 src/or/geoip.c   |6 +++---
 4 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/src/or/channel.h b/src/or/channel.h
index 242a078..18d9a81 100644
--- a/src/or/channel.h
+++ b/src/or/channel.h
@@ -38,11 +38,6 @@ struct channel_s {
*/
   unsigned int is_listener:1;
 
-  /** Unique ID for measuring direct network status requests;vtunneled ones
-   * come over a circuit_t, which has a dirreq_id field as well, but is a
-   * distinct namespace. */
-  uint64_t dirreq_id;
-
   /** Why did we close?
*/
   enum {
diff --git a/src/or/connection_edge.c b/src/or/connection_edge.c
index 9bcfca3..834f970 100644
--- a/src/or/connection_edge.c
+++ b/src/or/connection_edge.c
@@ -3124,7 +3124,7 @@ connection_exit_begin_conn(cell_t *cell, circuit_t *circ)
 
   /* Remember the tunneled request ID in the new edge connection, so that
* we can measure download times. */
-  TO_CONN(n_stream)-dirreq_id = circ-dirreq_id;
+  n_stream-dirreq_id = circ-dirreq_id;
 
   n_stream-_base.purpose = EXIT_PURPOSE_CONNECT;
 
@@ -3366,7 +3366,7 @@ connection_exit_connect_dir(edge_connection_t *exitconn)
 
   /* Note that the new dir conn belongs to the same tunneled request as
* the edge conn, so that we can measure download times. */
-  TO_CONN(dirconn)-dirreq_id = TO_CONN(exitconn)-dirreq_id;
+  dirconn-dirreq_id = exitconn-dirreq_id;
 
   connection_link_connections(TO_CONN(dirconn), TO_CONN(exitconn));
 
diff --git a/src/or/directory.c b/src/or/directory.c
index 7df91fb..8003444 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -2855,8 +2855,8 @@ directory_handle_command_get(dir_connection_t *conn, 
const char *headers,
 geoip_note_ns_response(act, GEOIP_SUCCESS);
 /* Note that a request for a network status has started, so that we
  * can measure the download time later on. */
-if (TO_CONN(conn)-dirreq_id)
-  geoip_start_dirreq(TO_CONN(conn)-dirreq_id, dlen, act,
+if (conn-dirreq_id)
+  geoip_start_dirreq(conn-dirreq_id, dlen, act,
  DIRREQ_TUNNELED);
 else
   geoip_start_dirreq(TO_CONN(conn)-global_identifier, dlen, act,
@@ -3529,8 +3529,8 @@ connection_dir_finished_flushing(dir_connection_t *conn)
   /* Note that we have finished writing the directory response. For direct
* connections this means we're done, for tunneled connections its only
* an intermediate step. */
-  if (TO_CONN(conn)-dirreq_id)
-geoip_change_dirreq_state(TO_CONN(conn)-dirreq_id, DIRREQ_TUNNELED,
+  if (conn-dirreq_id)
+geoip_change_dirreq_state(conn-dirreq_id, DIRREQ_TUNNELED,
   DIRREQ_FLUSHING_DIR_CONN_FINISHED);
   else
 geoip_change_dirreq_state(TO_CONN(conn)-global_identifier,
diff --git a/src/or/geoip.c b/src/or/geoip.c
index 6b7cc82..a995f8b 100644
--- a/src/or/geoip.c
+++ b/src/or/geoip.c
@@ -578,7 +578,7 @@ _c_hist_compare(const void **_a, const void **_b)
  * failed, the others as still running. */
 #define DIRREQ_TIMEOUT (10*60)
 
-/** Entry in a map from either conn-global_identifier for direct requests
+/** Entry in a map from either chan-global_identifier for direct requests
  * or a unique circuit identifier for tunneled requests to request time,
  * response size, and completion time of a network status request. Used to
  * measure download times of requests to derive average client
@@ -586,7 +586,7 @@ _c_hist_compare(const void **_a, const void **_b)
 typedef struct dirreq_map_entry_t {
   HT_ENTRY(dirreq_map_entry_t) node;
   /** Unique identifier for this network status request; this is either the
-   * conn-global_identifier of the dir conn (direct request) or a new
+   * chan-global_identifier of the dir channel (direct request) or a new
* locally unique identifier of a circuit (tunneled request). This ID is
* only unique among other direct or tunneled requests, respectively. */
   uint64_t dirreq_id;
@@ -705,7 +705,7 @@ geoip_change_dirreq_state(uint64_t dirreq_id, dirreq_type_t 
type,
   if ((type == DIRREQ_DIRECT 
  new_state == DIRREQ_FLUSHING_DIR_CONN_FINISHED) ||
   (type == DIRREQ_TUNNELED 
- new_state == DIRREQ_OR_CONN_BUFFER_FLUSHED)) {
+ new_state == DIRREQ_CHANNEL_BUFFER_FLUSHED)) {
 tor_gettimeofday(ent-completion_time);
 ent-completed = 1;
   }



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Use connection_or_get_num_circuits() in control.c

2012-10-10 Thread andrea
commit 9ad7ba9f2267a9ee34fafda9356f1fa86633f00f
Author: Andrea Shepard and...@persephoneslair.org
Date:   Fri Sep 7 04:40:42 2012 -0700

Use connection_or_get_num_circuits() in control.c
---
 src/or/control.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/or/control.c b/src/or/control.c
index 5c05fe1..75a8f59 100644
--- a/src/or/control.c
+++ b/src/or/control.c
@@ -3829,7 +3829,7 @@ control_event_or_conn_status(or_connection_t *conn, 
or_conn_status_event_t tp,
   } else {
 ncircs = 0;
   }
-  ncircs += conn-n_circuits;
+  ncircs += connection_or_get_num_circuits(conn);
   if (ncircs  (tp == OR_CONN_EVENT_FAILED || tp == OR_CONN_EVENT_CLOSED)) {
 tor_snprintf(ncircs_buf, sizeof(ncircs_buf), %sNCIRCS=%d,
  reason ?   : , ncircs);



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Use channel_is_bad_for_new_circs(), connection_or_get_num_circs() in main.c

2012-10-10 Thread andrea
commit cb62a0b69a7d67b427224ca4c3075b49853a3a1f
Author: Andrea Shepard and...@persephoneslair.org
Date:   Fri Sep 7 04:42:13 2012 -0700

Use channel_is_bad_for_new_circs(), connection_or_get_num_circs() in main.c
---
 src/or/main.c |   10 +++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/or/main.c b/src/or/main.c
index a1b1502..f53bcf3 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -13,6 +13,8 @@
 #define MAIN_PRIVATE
 #include or.h
 #include buffers.h
+#include channel.h
+#include channeltls.h
 #include circuitbuild.h
 #include circuitlist.h
 #include circuituse.h
@@ -1046,7 +1048,8 @@ run_connection_housekeeping(int i, time_t now)
   tor_assert(conn-outbuf);
 #endif
 
-  if (or_conn-is_bad_for_new_circs  !or_conn-n_circuits) {
+  if (channel_is_bad_for_new_circs(TLS_CHAN_TO_BASE(or_conn-chan)) 
+  !connection_or_get_num_circuits(or_conn)) {
 /* It's bad for new circuits, and has no unmarked circuits on it:
  * mark it now. */
 log_info(LD_OR,
@@ -1064,14 +1067,15 @@ run_connection_housekeeping(int i, time_t now)
(int)conn-s,conn-address, conn-port);
   connection_mark_for_close(conn);
 }
-  } else if (we_are_hibernating()  !or_conn-n_circuits 
+  } else if (we_are_hibernating() 
+ !connection_or_get_num_circuits(or_conn) 
  !connection_get_outbuf_len(conn)) {
 /* We're hibernating, there's no circuits, and nothing to flush.*/
 log_info(LD_OR,Expiring non-used OR connection to fd %d (%s:%d) 
  [Hibernating or exiting].,
  (int)conn-s,conn-address, conn-port);
 connection_mark_and_flush(conn);
-  } else if (!or_conn-n_circuits 
+  } else if (!connection_or_get_num_circuits(or_conn) 
  now = or_conn-timestamp_last_added_nonpadding +
  IDLE_OR_CONN_TIMEOUT) {
 log_info(LD_OR,Expiring non-used OR connection to fd %d (%s:%d) 



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


[tor-commits] [tor/master] Add LD_CHANNEL log domain in log.c

2012-10-10 Thread andrea
commit f06880c855a6ac4dd824bed7efcd0bd0436bda32
Author: Andrea Shepard and...@persephoneslair.org
Date:   Fri Sep 7 14:38:16 2012 -0700

Add LD_CHANNEL log domain in log.c
---
 src/common/log.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/src/common/log.c b/src/common/log.c
index 5e2e6b5..ef2e69d 100644
--- a/src/common/log.c
+++ b/src/common/log.c
@@ -907,7 +907,7 @@ log_level_to_string(int level)
 static const char *domain_list[] = {
   GENERAL, CRYPTO, NET, CONFIG, FS, PROTOCOL, MM,
   HTTP, APP, CONTROL, CIRC, REND, BUG, DIR, DIRSERV,
-  OR, EDGE, ACCT, HIST, HANDSHAKE, HEARTBEAT, NULL
+  OR, EDGE, ACCT, HIST, HANDSHAKE, HEARTBEAT, CHANNEL, NULL
 };
 
 /** Return a bitmask for the log domain for which bdomain/b is the name,



___
tor-commits mailing list
tor-commits@lists.torproject.org
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits


  1   2   >