mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 20:33:31 +01:00
I'm a bad person.
Stop treating the uint16_t's as null-terminated strings, and stop looking at the byte after them to see if it's null, because sometimes you're not allowed to look there. svn:r3108
This commit is contained in:
parent
a2d80ec767
commit
802d374a99
@ -788,19 +788,25 @@ static int new_route_len(double cw, uint8_t purpose, smartlist_t *routers) {
|
|||||||
return routelen;
|
return routelen;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Fetch the list of predicted ports, turn it into a smartlist of
|
/** Fetch the list of predicted ports, dup it into a smartlist of
|
||||||
* strings, remove the ones that are already handled by an
|
* uint16_t's, remove the ones that are already handled by an
|
||||||
* existing circuit, and return it.
|
* existing circuit, and return it.
|
||||||
*/
|
*/
|
||||||
static smartlist_t *
|
static smartlist_t *
|
||||||
circuit_get_unhandled_ports(time_t now) {
|
circuit_get_unhandled_ports(time_t now) {
|
||||||
char *pp = rep_hist_get_predicted_ports(now);
|
smartlist_t *source = rep_hist_get_predicted_ports(now);
|
||||||
smartlist_t *needed_ports = smartlist_create();
|
smartlist_t *dest = smartlist_create();
|
||||||
smartlist_split_string(needed_ports, pp, " ", SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0);
|
uint16_t *tmp;
|
||||||
tor_free(pp);
|
int i;
|
||||||
|
|
||||||
circuit_remove_handled_ports(needed_ports);
|
for (i = 0; i < smartlist_len(source); ++i) {
|
||||||
return needed_ports;
|
tmp = tor_malloc(sizeof(uint16_t));
|
||||||
|
memcpy(tmp, smartlist_get(source, i), sizeof(uint16_t));
|
||||||
|
smartlist_add(dest, tmp);
|
||||||
|
}
|
||||||
|
|
||||||
|
circuit_remove_handled_ports(dest);
|
||||||
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Return 1 if we already have circuits present or on the way for
|
/** Return 1 if we already have circuits present or on the way for
|
||||||
@ -811,7 +817,7 @@ circuit_all_predicted_ports_handled(time_t now) {
|
|||||||
int enough;
|
int enough;
|
||||||
smartlist_t *sl = circuit_get_unhandled_ports(now);
|
smartlist_t *sl = circuit_get_unhandled_ports(now);
|
||||||
enough = (smartlist_len(sl) == 0);
|
enough = (smartlist_len(sl) == 0);
|
||||||
SMARTLIST_FOREACH(sl, char *, cp, tor_free(cp));
|
SMARTLIST_FOREACH(sl, uint16_t *, cp, tor_free(cp));
|
||||||
smartlist_free(sl);
|
smartlist_free(sl);
|
||||||
return enough;
|
return enough;
|
||||||
}
|
}
|
||||||
@ -1000,7 +1006,7 @@ static routerinfo_t *choose_good_exit_server_general(routerlist_t *dir)
|
|||||||
if (router)
|
if (router)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SMARTLIST_FOREACH(needed_ports, char *, cp, tor_free(cp));
|
SMARTLIST_FOREACH(needed_ports, uint16_t *, cp, tor_free(cp));
|
||||||
smartlist_free(needed_ports);
|
smartlist_free(needed_ports);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,19 +255,17 @@ void circuit_expire_building(time_t now) {
|
|||||||
void
|
void
|
||||||
circuit_remove_handled_ports(smartlist_t *needed_ports) {
|
circuit_remove_handled_ports(smartlist_t *needed_ports) {
|
||||||
int i;
|
int i;
|
||||||
uint16_t port;
|
uint16_t *port;
|
||||||
char *portstring;
|
|
||||||
|
|
||||||
for (i = 0; i < smartlist_len(needed_ports); ++i) {
|
for (i = 0; i < smartlist_len(needed_ports); ++i) {
|
||||||
portstring = smartlist_get(needed_ports, i);
|
port = smartlist_get(needed_ports, i);
|
||||||
port = *(uint16_t*)(portstring);
|
tor_assert(*port);
|
||||||
tor_assert(port);
|
if (circuit_stream_is_being_handled(NULL, *port, 2)) {
|
||||||
if (circuit_stream_is_being_handled(NULL, port, 2)) {
|
|
||||||
// log_fn(LOG_DEBUG,"Port %d is already being handled; removing.", port);
|
// log_fn(LOG_DEBUG,"Port %d is already being handled; removing.", port);
|
||||||
smartlist_del(needed_ports, i--);
|
smartlist_del(needed_ports, i--);
|
||||||
tor_free(portstring);
|
tor_free(port);
|
||||||
} else {
|
} else {
|
||||||
log_fn(LOG_DEBUG,"Port %d is not handled.", port);
|
log_fn(LOG_DEBUG,"Port %d is not handled.", *port);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1451,7 +1451,7 @@ int rep_hist_bandwidth_assess(void);
|
|||||||
char *rep_hist_get_bandwidth_lines(void);
|
char *rep_hist_get_bandwidth_lines(void);
|
||||||
void rep_history_clean(time_t before);
|
void rep_history_clean(time_t before);
|
||||||
void rep_hist_note_used_port(uint16_t port, time_t now);
|
void rep_hist_note_used_port(uint16_t port, time_t now);
|
||||||
char *rep_hist_get_predicted_ports(time_t now);
|
smartlist_t *rep_hist_get_predicted_ports(time_t now);
|
||||||
|
|
||||||
/********************************* rendclient.c ***************************/
|
/********************************* rendclient.c ***************************/
|
||||||
|
|
||||||
|
@ -666,12 +666,14 @@ void rep_hist_note_used_port(uint16_t port, time_t now) {
|
|||||||
add_predicted_port(port, now);
|
add_predicted_port(port, now);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define PREFERRED_PORTS_RELEVANCE_TIME (6*3600) /* 6 hours */
|
#define PREDICTED_PORTS_RELEVANCE_TIME (6*3600) /* 6 hours */
|
||||||
|
|
||||||
/** Allocate and return a string of space-separated port numbers that
|
/** Return a pointer to the list of port numbers that
|
||||||
* are likely to be asked for in the near future.
|
* are likely to be asked for in the near future.
|
||||||
|
*
|
||||||
|
* The caller promises not to mess with it.
|
||||||
*/
|
*/
|
||||||
char *rep_hist_get_predicted_ports(time_t now) {
|
smartlist_t *rep_hist_get_predicted_ports(time_t now) {
|
||||||
int i;
|
int i;
|
||||||
uint16_t *tmp_port;
|
uint16_t *tmp_port;
|
||||||
time_t *tmp_time;
|
time_t *tmp_time;
|
||||||
@ -682,8 +684,9 @@ char *rep_hist_get_predicted_ports(time_t now) {
|
|||||||
/* clean out obsolete entries */
|
/* clean out obsolete entries */
|
||||||
for (i = 0; i < smartlist_len(predicted_ports_list); ++i) {
|
for (i = 0; i < smartlist_len(predicted_ports_list); ++i) {
|
||||||
tmp_time = smartlist_get(predicted_ports_times, i);
|
tmp_time = smartlist_get(predicted_ports_times, i);
|
||||||
if (*tmp_time + PREFERRED_PORTS_RELEVANCE_TIME < now) {
|
if (*tmp_time + PREDICTED_PORTS_RELEVANCE_TIME < now) {
|
||||||
tmp_port = smartlist_get(predicted_ports_list, i);
|
tmp_port = smartlist_get(predicted_ports_list, i);
|
||||||
|
log_fn(LOG_DEBUG, "Expiring predicted port %d", *tmp_port);
|
||||||
smartlist_del(predicted_ports_list, i);
|
smartlist_del(predicted_ports_list, i);
|
||||||
smartlist_del(predicted_ports_times, i);
|
smartlist_del(predicted_ports_times, i);
|
||||||
tor_free(tmp_port);
|
tor_free(tmp_port);
|
||||||
@ -691,6 +694,6 @@ char *rep_hist_get_predicted_ports(time_t now) {
|
|||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return smartlist_join_strings(predicted_ports_list, " ", 0, NULL);
|
return predicted_ports_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user