summaryrefslogtreecommitdiff
path: root/src/or/circuituse.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2011-05-13 16:22:10 -0400
committerNick Mathewson <nickm@torproject.org>2011-05-13 16:22:10 -0400
commitec81d17d0c03d73f4d4acd9102893113b2883d76 (patch)
treec96787d39a8b024f97584505b7fad1045c1408b7 /src/or/circuituse.c
parent09da83e1e8c1f1050fd65af86736abc1f4e5b530 (diff)
downloadtor-ec81d17d0c03d73f4d4acd9102893113b2883d76.tar.gz
tor-ec81d17d0c03d73f4d4acd9102893113b2883d76.zip
Raise the TrackHostExits membership code into its own function
Diffstat (limited to 'src/or/circuituse.c')
-rw-r--r--src/or/circuituse.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/or/circuituse.c b/src/or/circuituse.c
index e68fb4fa82..6e069b1670 100644
--- a/src/or/circuituse.c
+++ b/src/or/circuituse.c
@@ -1485,12 +1485,31 @@ link_apconn_to_circ(edge_connection_t *apconn, origin_circuit_t *circ,
}
}
+/** Return true iff <b>address</b> is matched by one of the entries in
+ * TrackHostExits. */
+int
+hostname_in_track_host_exits(or_options_t *options, const char *address)
+{
+ if (!options->TrackHostExits)
+ return 0;
+ SMARTLIST_FOREACH_BEGIN(options->TrackHostExits, const char *, cp) {
+ if (cp[0] == '.') { /* match end */
+ if (cp[1] == '\0' ||
+ !strcasecmpend(address, cp) ||
+ !strcasecmp(address, &cp[1]))
+ return 1;
+ } else if (strcasecmp(cp, address) == 0) {
+ return 1;
+ }
+ } SMARTLIST_FOREACH_END(cp);
+ return 0;
+}
+
/** If an exit wasn't specifically chosen, save the history for future
* use. */
static void
consider_recording_trackhost(edge_connection_t *conn, origin_circuit_t *circ)
{
- int found_needle = 0;
or_options_t *options = get_options();
size_t len;
char *new_address;
@@ -1503,18 +1522,8 @@ consider_recording_trackhost(edge_connection_t *conn, origin_circuit_t *circ)
options->TrackHostExitsExpire))
return; /* nothing to track, or already mapped */
- SMARTLIST_FOREACH(options->TrackHostExits, const char *, cp, {
- if (cp[0] == '.') { /* match end */
- if (cp[1] == '\0' ||
- !strcasecmpend(conn->socks_request->address, cp) ||
- !strcasecmp(conn->socks_request->address, &cp[1]))
- found_needle = 1;
- } else if (strcasecmp(cp, conn->socks_request->address) == 0) {
- found_needle = 1;
- }
- });
-
- if (!found_needle || !circ->build_state->chosen_exit)
+ if (!hostname_in_track_host_exits(options, conn->socks_request->address) ||
+ !circ->build_state->chosen_exit)
return;
/* write down the fingerprint of the chosen exit, not the nickname,