mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-24 22:58:50 +01:00
Raise the TrackHostExits membership code into its own function
This commit is contained in:
parent
09da83e1e8
commit
ec81d17d0c
2 changed files with 24 additions and 13 deletions
|
@ -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
|
/** If an exit wasn't specifically chosen, save the history for future
|
||||||
* use. */
|
* use. */
|
||||||
static void
|
static void
|
||||||
consider_recording_trackhost(edge_connection_t *conn, origin_circuit_t *circ)
|
consider_recording_trackhost(edge_connection_t *conn, origin_circuit_t *circ)
|
||||||
{
|
{
|
||||||
int found_needle = 0;
|
|
||||||
or_options_t *options = get_options();
|
or_options_t *options = get_options();
|
||||||
size_t len;
|
size_t len;
|
||||||
char *new_address;
|
char *new_address;
|
||||||
|
@ -1503,18 +1522,8 @@ consider_recording_trackhost(edge_connection_t *conn, origin_circuit_t *circ)
|
||||||
options->TrackHostExitsExpire))
|
options->TrackHostExitsExpire))
|
||||||
return; /* nothing to track, or already mapped */
|
return; /* nothing to track, or already mapped */
|
||||||
|
|
||||||
SMARTLIST_FOREACH(options->TrackHostExits, const char *, cp, {
|
if (!hostname_in_track_host_exits(options, conn->socks_request->address) ||
|
||||||
if (cp[0] == '.') { /* match end */
|
!circ->build_state->chosen_exit)
|
||||||
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)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* write down the fingerprint of the chosen exit, not the nickname,
|
/* write down the fingerprint of the chosen exit, not the nickname,
|
||||||
|
|
|
@ -51,5 +51,7 @@ int connection_ap_handshake_attach_chosen_circuit(edge_connection_t *conn,
|
||||||
crypt_path_t *cpath);
|
crypt_path_t *cpath);
|
||||||
int connection_ap_handshake_attach_circuit(edge_connection_t *conn);
|
int connection_ap_handshake_attach_circuit(edge_connection_t *conn);
|
||||||
|
|
||||||
|
int hostname_in_track_host_exits(or_options_t *options, const char *address);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue