mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-14 07:03:44 +01:00
Make smartlist Do What Arma Expects.
svn:r1401
This commit is contained in:
parent
2d3ac08633
commit
93ab51e9ac
@ -117,10 +117,11 @@ void set_uint32(char *cp, uint32_t v)
|
|||||||
* _add() adds an element, _remove() removes an element if it's there,
|
* _add() adds an element, _remove() removes an element if it's there,
|
||||||
* _choose() returns a random element.
|
* _choose() returns a random element.
|
||||||
*/
|
*/
|
||||||
smartlist_t *smartlist_create(int capacity) {
|
#define SMARTLIST_DEFAULT_CAPACITY 32
|
||||||
|
smartlist_t *smartlist_create() {
|
||||||
smartlist_t *sl = tor_malloc(sizeof(smartlist_t));
|
smartlist_t *sl = tor_malloc(sizeof(smartlist_t));
|
||||||
sl->num_used = 0;
|
sl->num_used = 0;
|
||||||
sl->capacity = capacity;
|
sl->capacity = SMARTLIST_DEFAULT_CAPACITY;
|
||||||
sl->list = tor_malloc(sizeof(void *) * sl->capacity);
|
sl->list = tor_malloc(sizeof(void *) * sl->capacity);
|
||||||
return sl;
|
return sl;
|
||||||
}
|
}
|
||||||
@ -130,8 +131,8 @@ void smartlist_free(smartlist_t *sl) {
|
|||||||
free(sl);
|
free(sl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void smartlist_grow_capacity(smartlist_t *sl, int n) {
|
void smartlist_set_capacity(smartlist_t *sl, int n) {
|
||||||
if (sl->capacity < n) {
|
if (sl->capacity != n && sl->num_used < n) {
|
||||||
sl->capacity = n;
|
sl->capacity = n;
|
||||||
sl->list = tor_realloc(sl->list, sizeof(void*)*sl->capacity);
|
sl->list = tor_realloc(sl->list, sizeof(void*)*sl->capacity);
|
||||||
}
|
}
|
||||||
|
@ -64,9 +64,9 @@ typedef struct {
|
|||||||
int capacity;
|
int capacity;
|
||||||
} smartlist_t;
|
} smartlist_t;
|
||||||
|
|
||||||
smartlist_t *smartlist_create(int capacity);
|
smartlist_t *smartlist_create();
|
||||||
void smartlist_free(smartlist_t *sl);
|
void smartlist_free(smartlist_t *sl);
|
||||||
void smartlist_grow_capacity(smartlist_t *sl, int n);
|
void smartlist_set_capacity(smartlist_t *sl, int n);
|
||||||
void smartlist_add(smartlist_t *sl, void *element);
|
void smartlist_add(smartlist_t *sl, void *element);
|
||||||
void smartlist_remove(smartlist_t *sl, void *element);
|
void smartlist_remove(smartlist_t *sl, void *element);
|
||||||
int smartlist_isin(smartlist_t *sl, void *element);
|
int smartlist_isin(smartlist_t *sl, void *element);
|
||||||
|
@ -946,7 +946,7 @@ void circuit_expire_unused_circuits(void) {
|
|||||||
smartlist_t *unused_open_circs;
|
smartlist_t *unused_open_circs;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
unused_open_circs = smartlist_create(circuitlist_len);
|
unused_open_circs = smartlist_create();
|
||||||
|
|
||||||
for (circ = global_circuitlist; circ; circ = circ->next) {
|
for (circ = global_circuitlist; circ; circ = circ->next) {
|
||||||
if (circ->marked_for_close)
|
if (circ->marked_for_close)
|
||||||
|
@ -300,13 +300,13 @@ static routerinfo_t *choose_good_exit_server(routerlist_t *dir)
|
|||||||
log_fn(LOG_INFO, "Found %d servers that might support %d/%d pending connections.",
|
log_fn(LOG_INFO, "Found %d servers that might support %d/%d pending connections.",
|
||||||
n_best_support, best_support, n_pending_connections);
|
n_best_support, best_support, n_pending_connections);
|
||||||
|
|
||||||
preferredexits = smartlist_create(16);
|
preferredexits = smartlist_create();
|
||||||
add_nickname_list_to_smartlist(preferredexits,options.ExitNodes);
|
add_nickname_list_to_smartlist(preferredexits,options.ExitNodes);
|
||||||
|
|
||||||
excludedexits = smartlist_create(16);
|
excludedexits = smartlist_create();
|
||||||
add_nickname_list_to_smartlist(excludedexits,options.ExcludeNodes);
|
add_nickname_list_to_smartlist(excludedexits,options.ExcludeNodes);
|
||||||
|
|
||||||
sl = smartlist_create(dir->n_routers);
|
sl = smartlist_create();
|
||||||
|
|
||||||
/* If any routers definitely support any pending connections, choose one
|
/* If any routers definitely support any pending connections, choose one
|
||||||
* at random. */
|
* at random. */
|
||||||
@ -450,7 +450,7 @@ int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state, rout
|
|||||||
log_fn(LOG_DEBUG, "Path is %d long; we want %d", cur_len,
|
log_fn(LOG_DEBUG, "Path is %d long; we want %d", cur_len,
|
||||||
state->desired_path_len);
|
state->desired_path_len);
|
||||||
|
|
||||||
excludednodes = smartlist_create(16);
|
excludednodes = smartlist_create();
|
||||||
add_nickname_list_to_smartlist(excludednodes,options.ExcludeNodes);
|
add_nickname_list_to_smartlist(excludednodes,options.ExcludeNodes);
|
||||||
|
|
||||||
if(cur_len == state->desired_path_len - 1) { /* Picking last node */
|
if(cur_len == state->desired_path_len - 1) { /* Picking last node */
|
||||||
@ -465,7 +465,7 @@ int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state, rout
|
|||||||
}
|
}
|
||||||
} else if(cur_len == 0) { /* picking first node */
|
} else if(cur_len == 0) { /* picking first node */
|
||||||
/* try the nodes in EntryNodes first */
|
/* try the nodes in EntryNodes first */
|
||||||
sl = smartlist_create(16);
|
sl = smartlist_create();
|
||||||
add_nickname_list_to_smartlist(sl,options.EntryNodes);
|
add_nickname_list_to_smartlist(sl,options.EntryNodes);
|
||||||
/* XXX one day, consider picking chosen_exit knowing what's in EntryNodes */
|
/* XXX one day, consider picking chosen_exit knowing what's in EntryNodes */
|
||||||
remove_twins_from_smartlist(sl,router_get_by_nickname(state->chosen_exit));
|
remove_twins_from_smartlist(sl,router_get_by_nickname(state->chosen_exit));
|
||||||
@ -473,7 +473,7 @@ int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state, rout
|
|||||||
choice = smartlist_choose(sl);
|
choice = smartlist_choose(sl);
|
||||||
smartlist_free(sl);
|
smartlist_free(sl);
|
||||||
if(!choice) {
|
if(!choice) {
|
||||||
sl = smartlist_create(32);
|
sl = smartlist_create();
|
||||||
router_add_running_routers_to_smartlist(sl);
|
router_add_running_routers_to_smartlist(sl);
|
||||||
remove_twins_from_smartlist(sl,router_get_by_nickname(state->chosen_exit));
|
remove_twins_from_smartlist(sl,router_get_by_nickname(state->chosen_exit));
|
||||||
smartlist_subtract(sl,excludednodes);
|
smartlist_subtract(sl,excludednodes);
|
||||||
@ -487,7 +487,7 @@ int onion_extend_cpath(crypt_path_t **head_ptr, cpath_build_state_t *state, rout
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log_fn(LOG_DEBUG, "Contemplating intermediate hop: random choice.");
|
log_fn(LOG_DEBUG, "Contemplating intermediate hop: random choice.");
|
||||||
sl = smartlist_create(32);
|
sl = smartlist_create();
|
||||||
router_add_running_routers_to_smartlist(sl);
|
router_add_running_routers_to_smartlist(sl);
|
||||||
remove_twins_from_smartlist(sl,router_get_by_nickname(state->chosen_exit));
|
remove_twins_from_smartlist(sl,router_get_by_nickname(state->chosen_exit));
|
||||||
for (i = 0, cpath = *head_ptr; i < cur_len; ++i, cpath=cpath->next) {
|
for (i = 0, cpath = *head_ptr; i < cur_len; ++i, cpath=cpath->next) {
|
||||||
|
@ -164,7 +164,7 @@ static routerinfo_t *router_pick_directory_server_impl(void) {
|
|||||||
if(!routerlist)
|
if(!routerlist)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
sl = smartlist_create(8);
|
sl = smartlist_create();
|
||||||
for(i=0;i<routerlist->n_routers;i++) {
|
for(i=0;i<routerlist->n_routers;i++) {
|
||||||
router = routerlist->routers[i];
|
router = routerlist->routers[i];
|
||||||
if(router->dir_port > 0 && router->is_running)
|
if(router->dir_port > 0 && router->is_running)
|
||||||
@ -605,7 +605,7 @@ router_get_routerlist_from_directory_impl(const char *str,
|
|||||||
end = str + strlen(str);
|
end = str + strlen(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens = smartlist_create(16);
|
tokens = smartlist_create();
|
||||||
if (tokenize_string(str,end,tokens,1)) {
|
if (tokenize_string(str,end,tokens,1)) {
|
||||||
log_fn(LOG_WARN, "Error tokenizing directory"); goto err;
|
log_fn(LOG_WARN, "Error tokenizing directory"); goto err;
|
||||||
}
|
}
|
||||||
@ -671,7 +671,7 @@ router_get_routerlist_from_directory_impl(const char *str,
|
|||||||
token_free((directory_token_t*)tokens->list[i]);
|
token_free((directory_token_t*)tokens->list[i]);
|
||||||
}
|
}
|
||||||
smartlist_free(tokens);
|
smartlist_free(tokens);
|
||||||
tokens = smartlist_create(16);
|
tokens = smartlist_create();
|
||||||
if (tokenize_string(str,str+strlen(str),tokens,1)<0) {
|
if (tokenize_string(str,str+strlen(str),tokens,1)<0) {
|
||||||
log_fn(LOG_WARN, "Error tokenizing signature"); goto err;
|
log_fn(LOG_WARN, "Error tokenizing signature"); goto err;
|
||||||
}
|
}
|
||||||
@ -817,7 +817,7 @@ routerinfo_t *router_get_entry_from_string(const char *s,
|
|||||||
log_fn(LOG_WARN, "Couldn't compute router hash.");
|
log_fn(LOG_WARN, "Couldn't compute router hash.");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
tokens = smartlist_create(16);
|
tokens = smartlist_create();
|
||||||
if (tokenize_string(s,end,tokens,0)) {
|
if (tokenize_string(s,end,tokens,0)) {
|
||||||
log_fn(LOG_WARN, "Error tokeninzing router descriptor."); goto err;
|
log_fn(LOG_WARN, "Error tokeninzing router descriptor."); goto err;
|
||||||
}
|
}
|
||||||
@ -1403,7 +1403,7 @@ find_all_exitpolicy(smartlist_t *s)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
directory_token_t *tok;
|
directory_token_t *tok;
|
||||||
smartlist_t *out = smartlist_create(s->num_used);
|
smartlist_t *out = smartlist_create();
|
||||||
for (i = 0; i < s->num_used; ++i) {
|
for (i = 0; i < s->num_used; ++i) {
|
||||||
tok = (directory_token_t*) s->list[i];
|
tok = (directory_token_t*) s->list[i];
|
||||||
if (tok->tp == K_ACCEPT || tok->tp == K_REJECT) {
|
if (tok->tp == K_ACCEPT || tok->tp == K_REJECT) {
|
||||||
|
Loading…
Reference in New Issue
Block a user