aboutsummaryrefslogtreecommitdiff
path: root/src/or/routers.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/routers.c')
-rw-r--r--src/or/routers.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/or/routers.c b/src/or/routers.c
index 6405446f57..6d159016cb 100644
--- a/src/or/routers.c
+++ b/src/or/routers.c
@@ -77,6 +77,37 @@ routerinfo_t *router_pick_directory_server(void) {
return dirserver;
}
+routerinfo_t *router_pick_randomly_from_running(void) {
+ int i,j;
+ int num_running=0;
+
+ if(!directory)
+ return NULL;
+
+ for(i=0;i<directory->n_routers;i++) {
+ if(directory->routers[i]->is_running)
+ num_running++;
+ }
+
+ if(!num_running) {
+ log_fn(LOG_INFO,"No routers are running. Returning NULL.");
+ return NULL;
+ }
+ j = crypto_pseudo_rand_int(num_running);
+ for (i=0;i<directory->n_routers;i++) {
+ if (directory->routers[i]->is_running) {
+ if (j)
+ --j;
+ else {
+ log_fn(LOG_DEBUG, "Chose server '%s'", directory->routers[i]->nickname);
+ return directory->routers[i];
+ }
+ }
+ }
+ assert(0);
+ return NULL;
+}
+
void router_upload_desc_to_dirservers(void) {
int i;
routerinfo_t *router;