Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ZerXes
Tor
Commits
4f2d5565
Commit
4f2d5565
authored
Dec 03, 2003
by
Roger Dingledine
Browse files
choose randomly from running dirservers, not always the first one
svn:r881
parent
63f81bdd
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/or/routers.c
View file @
4f2d5565
...
...
@@ -50,31 +50,48 @@ void router_retry_connections(void) {
}
routerinfo_t
*
router_pick_directory_server
(
void
)
{
/* pick
the first
running router with a positive dir_port */
int
i
;
/* pick
a random
running router with a positive dir_port */
int
i
,
j
;
routerinfo_t
*
router
,
*
dirserver
=
NULL
;
int
num_dirservers
=
0
;
if
(
!
directory
)
return
NULL
;
for
(
i
=
0
;
i
<
directory
->
n_routers
;
i
++
)
{
router
=
directory
->
routers
[
i
];
if
(
router
->
dir_port
>
0
&&
router
->
is_running
)
return
router
;
num_dirservers
++
;
}
if
(
!
num_dirservers
)
{
log_fn
(
LOG_INFO
,
"No dirservers are reachable. Trying them all again."
);
/* no running dir servers found? go through and mark them all as up,
* and we'll cycle through the list again. */
for
(
i
=
0
;
i
<
directory
->
n_routers
;
i
++
)
{
router
=
directory
->
routers
[
i
];
if
(
router
->
dir_port
>
0
)
{
router
->
is_running
=
1
;
dirserver
=
router
;
}
}
return
dirserver
;
}
log_fn
(
LOG_INFO
,
"No dirservers are reachable. Trying them all again."
);
/* no running dir servers found? go through and mark them all as up,
* and we'll cycle through the list again. */
for
(
i
=
0
;
i
<
directory
->
n_routers
;
i
++
)
{
j
=
crypto_pseudo_rand_int
(
num_dirservers
);
for
(
i
=
0
;
i
<
directory
->
n_routers
;
i
++
)
{
router
=
directory
->
routers
[
i
];
if
(
router
->
dir_port
>
0
)
{
router
->
is_running
=
1
;
dirserver
=
router
;
if
(
router
->
dir_port
>
0
&&
router
->
is_running
)
{
if
(
j
)
--
j
;
else
{
log_fn
(
LOG_DEBUG
,
"Chose server '%s'"
,
router
->
nickname
);
return
router
;
}
}
}
return
dirserver
;
assert
(
0
);
return
NULL
;
}
routerinfo_t
*
router_pick_randomly_from_running
(
void
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment