mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
We cant recognize ourself until we resolve all the routers.
svn:r282
This commit is contained in:
parent
52604afd62
commit
c2e7b5ec3f
@ -117,6 +117,7 @@ void router_get_directory(directory_t **pdirectory) {
|
|||||||
*/
|
*/
|
||||||
int router_is_me(uint32_t addr, uint16_t port)
|
int router_is_me(uint32_t addr, uint16_t port)
|
||||||
{
|
{
|
||||||
|
/* XXXX Should this check the key too? */
|
||||||
struct sockaddr_in me; /* my router identity */
|
struct sockaddr_in me; /* my router identity */
|
||||||
|
|
||||||
if(!options.ORPort) {
|
if(!options.ORPort) {
|
||||||
@ -667,22 +668,8 @@ static int router_get_list_from_string_tok(char **s, directory_t **dest,
|
|||||||
log(LOG_ERR, "Error reading router");
|
log(LOG_ERR, "Error reading router");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
switch(router_is_me(router->addr, router->or_port)) {
|
router->next = routerlist;
|
||||||
case 0: /* it's not me */
|
routerlist = router;
|
||||||
router->next = routerlist;
|
|
||||||
routerlist = router;
|
|
||||||
break;
|
|
||||||
case 1: /* it is me */
|
|
||||||
if(!my_routerinfo) /* save it, so we can use it for directories */
|
|
||||||
my_routerinfo = router;
|
|
||||||
else
|
|
||||||
routerlist_free(router);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
log(LOG_ERR,"router_get_list_from_string(): router_is_me returned error.");
|
|
||||||
routerlist_free(routerlist);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new_router_array = make_rarray(routerlist, &new_rarray_len);
|
new_router_array = make_rarray(routerlist, &new_rarray_len);
|
||||||
@ -717,20 +704,28 @@ router_resolve(routerinfo_t *router)
|
|||||||
int
|
int
|
||||||
router_resolve_directory(directory_t *dir)
|
router_resolve_directory(directory_t *dir)
|
||||||
{
|
{
|
||||||
int i, max;
|
int i, max, remove;
|
||||||
if (!dir)
|
if (!dir)
|
||||||
dir = directory;
|
dir = directory;
|
||||||
|
|
||||||
max = dir->n_routers;
|
max = dir->n_routers;
|
||||||
for (i = 0; i < max; ++i) {
|
for (i = 0; i < max; ++i) {
|
||||||
|
remove = 0;
|
||||||
if (router_resolve(dir->routers[i])) {
|
if (router_resolve(dir->routers[i])) {
|
||||||
log(LOG_INFO, "Couldn\'t resolve router %s; removing",
|
log(LOG_INFO, "Couldn\'t resolve router %s; removing",
|
||||||
dir->routers[i]->address);
|
dir->routers[i]->address);
|
||||||
|
remove = 1;
|
||||||
dir->routers[i]->next = NULL;
|
dir->routers[i]->next = NULL;
|
||||||
routerlist_free(dir->routers[i]);
|
routerlist_free(dir->routers[i]);
|
||||||
|
} else if (router_is_me(dir->routers[i]->addr, dir->routers[i]->or_port)) {
|
||||||
|
my_routerinfo = dir->routers[i];
|
||||||
|
remove = 1;
|
||||||
|
}
|
||||||
|
if (remove) {
|
||||||
dir->routers[i] = dir->routers[--max];
|
dir->routers[i] = dir->routers[--max];
|
||||||
dir->routers[max] = NULL;
|
dir->routers[max] = NULL;
|
||||||
--dir->n_routers;
|
--dir->n_routers;
|
||||||
|
--i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* This is quick-and-dirty, but it keeps stuff consistant. */
|
/* This is quick-and-dirty, but it keeps stuff consistant. */
|
||||||
|
Loading…
Reference in New Issue
Block a user