[tor-commits] [tor/master] Record the number of INTRODUCE2 cells each intro point has received
nickm at torproject.org
nickm at torproject.org
Wed Nov 30 01:55:00 UTC 2011
commit 6f035cb2b450e8779bff50d6ed83e4822a49f0fe
Author: Robert Ransom <rransom.8774 at gmail.com>
Date: Wed Oct 5 23:52:14 2011 -0700
Record the number of INTRODUCE2 cells each intro point has received
---
src/or/or.h | 4 ++++
src/or/rendservice.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/src/or/or.h b/src/or/or.h
index cf241a6..215bde2 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3481,6 +3481,10 @@ typedef struct rend_intro_point_t {
* circuit-build timeout. See also MAX_INTRO_POINT_REACHABILITY_FAILURES. */
unsigned int unreachable_count : 3;
+ /** (Service side only) The number of INTRODUCE2 cells this intro
+ * point's circuit has received. */
+ unsigned int introduction_count : 24;
+
/** (Service side only) The time at which this intro point was first
* published, or -1 if this intro point has not yet been
* published. */
diff --git a/src/or/rendservice.c b/src/or/rendservice.c
index d21fdcc..a341dd6 100644
--- a/src/or/rendservice.c
+++ b/src/or/rendservice.c
@@ -25,6 +25,7 @@
static origin_circuit_t *find_intro_circuit(rend_intro_point_t *intro,
const char *pk_digest);
+static rend_intro_point_t *find_intro_point(origin_circuit_t *circ);
/** Represents the mapping from a virtual port of a rendezvous service to
* a real port on some IP.
@@ -899,6 +900,7 @@ rend_service_introduce(origin_circuit_t *circuit, const uint8_t *request,
char buf[RELAY_PAYLOAD_SIZE];
char keys[DIGEST_LEN+CPATH_KEY_MATERIAL_LEN]; /* Holds KH, Df, Db, Kf, Kb */
rend_service_t *service;
+ rend_intro_point_t *intro_point;
int r, i, v3_shift = 0;
size_t len, keylen;
crypto_dh_env_t *dh = NULL;
@@ -971,6 +973,14 @@ rend_service_introduce(origin_circuit_t *circuit, const uint8_t *request,
return -1;
}
+ intro_point = find_intro_point(circuit);
+ if (intro_point == NULL) {
+ log_warn(LD_BUG, "Internal error: Got an INTRODUCE2 cell on an intro circ "
+ "(for service %s) with no corresponding rend_intro_point_t.",
+ escaped(serviceid));
+ return -1;
+ }
+
if (!service->accepted_intros)
service->accepted_intros = digestmap_new();
@@ -993,6 +1003,13 @@ rend_service_introduce(origin_circuit_t *circuit, const uint8_t *request,
digestmap_set(service->accepted_intros, pkpart_digest, access_time);
}
+ /* Record that we've received another INTRODUCE2 cell through this
+ * intro point. */
+ ++(intro_point->introduction_count);
+ if (intro_point->introduction_count == 0) {
+ --(intro_point->introduction_count);
+ }
+
/* Next N bytes is encrypted with service key */
note_crypto_pk_op(REND_SERVER);
r = crypto_pk_private_hybrid_decrypt(
@@ -1647,6 +1664,35 @@ find_intro_circuit(rend_intro_point_t *intro, const char *pk_digest)
return NULL;
}
+/** Return a pointer to the rend_intro_point_t corresponding to the
+ * service-side introduction circuit <b>circ</b>. */
+static rend_intro_point_t *
+find_intro_point(origin_circuit_t *circ)
+{
+ const char *serviceid;
+ rend_service_t *service = NULL;
+
+ tor_assert(TO_CIRCUIT(circ)->purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO ||
+ TO_CIRCUIT(circ)->purpose == CIRCUIT_PURPOSE_S_INTRO);
+ tor_assert(circ->rend_data);
+ serviceid = circ->rend_data->onion_address;
+
+ SMARTLIST_FOREACH(rend_service_list, rend_service_t *, s,
+ if (tor_memeq(s->service_id, serviceid, REND_SERVICE_ID_LEN_BASE32)) {
+ service = s;
+ break;
+ });
+
+ if (service == NULL) return NULL;
+
+ SMARTLIST_FOREACH(service->intro_nodes, rend_intro_point_t *, intro_point,
+ if (crypto_pk_cmp_keys(intro_point->intro_key, circ->intro_key) == 0) {
+ return intro_point;
+ });
+
+ return NULL;
+}
+
/** Determine the responsible hidden service directories for the
* rend_encoded_v2_service_descriptor_t's in <b>descs</b> and upload them;
* <b>service_id</b> and <b>seconds_valid</b> are only passed for logging
More information about the tor-commits
mailing list