mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
moving hid_serv_get_responsible_directories and hid_serv_acting_as_directory from routerlist.c to rendcommon.c
This commit is contained in:
parent
ffc25bc908
commit
b1917a0614
@ -13,6 +13,7 @@
|
|||||||
#include "rephist.h"
|
#include "rephist.h"
|
||||||
#include "routerlist.h"
|
#include "routerlist.h"
|
||||||
#include "routerparse.h"
|
#include "routerparse.h"
|
||||||
|
#include "rendcommon.h"
|
||||||
|
|
||||||
/** Map from service id (as generated by rend_get_service_id) to
|
/** Map from service id (as generated by rend_get_service_id) to
|
||||||
* rend_cache_entry_t. */
|
* rend_cache_entry_t. */
|
||||||
|
@ -17,8 +17,10 @@
|
|||||||
#include "rendmid.h"
|
#include "rendmid.h"
|
||||||
#include "rendservice.h"
|
#include "rendservice.h"
|
||||||
#include "rephist.h"
|
#include "rephist.h"
|
||||||
|
#include "router.h"
|
||||||
#include "routerlist.h"
|
#include "routerlist.h"
|
||||||
#include "routerparse.h"
|
#include "routerparse.h"
|
||||||
|
#include "networkstatus.h"
|
||||||
|
|
||||||
/** Return 0 if one and two are the same service ids, else -1 or 1 */
|
/** Return 0 if one and two are the same service ids, else -1 or 1 */
|
||||||
int
|
int
|
||||||
@ -935,3 +937,75 @@ rend_data_client_create(const char *onion_address, const char *desc_id,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Determine the routers that are responsible for <b>id</b> (binary) and
|
||||||
|
* add pointers to those routers' routerstatus_t to <b>responsible_dirs</b>.
|
||||||
|
* Return -1 if we're returning an empty smartlist, else return 0.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
|
||||||
|
const char *id)
|
||||||
|
{
|
||||||
|
int start, found, n_added = 0, i;
|
||||||
|
networkstatus_t *c = networkstatus_get_latest_consensus();
|
||||||
|
if (!c || !smartlist_len(c->routerstatus_list)) {
|
||||||
|
log_warn(LD_REND, "We don't have a consensus, so we can't perform v2 "
|
||||||
|
"rendezvous operations.");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
tor_assert(id);
|
||||||
|
start = networkstatus_vote_find_entry_idx(c, id, &found);
|
||||||
|
if (start == smartlist_len(c->routerstatus_list)) start = 0;
|
||||||
|
i = start;
|
||||||
|
do {
|
||||||
|
routerstatus_t *r = smartlist_get(c->routerstatus_list, i);
|
||||||
|
if (r->is_hs_dir) {
|
||||||
|
smartlist_add(responsible_dirs, r);
|
||||||
|
if (++n_added == REND_NUMBER_OF_CONSECUTIVE_REPLICAS)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (++i == smartlist_len(c->routerstatus_list))
|
||||||
|
i = 0;
|
||||||
|
} while (i != start);
|
||||||
|
|
||||||
|
/* Even though we don't have the desired number of hidden service
|
||||||
|
* directories, be happy if we got any. */
|
||||||
|
return smartlist_len(responsible_dirs) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return true if this node is currently acting as hidden service
|
||||||
|
* directory, false otherwise. */
|
||||||
|
int
|
||||||
|
hid_serv_acting_as_directory(void)
|
||||||
|
{
|
||||||
|
const routerinfo_t *me = router_get_my_routerinfo();
|
||||||
|
if (!me)
|
||||||
|
return 0;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return true if this node is responsible for storing the descriptor ID
|
||||||
|
* in <b>query</b> and false otherwise. */
|
||||||
|
MOCK_IMPL(int, hid_serv_responsible_for_desc_id,
|
||||||
|
(const char *query))
|
||||||
|
{
|
||||||
|
const routerinfo_t *me;
|
||||||
|
routerstatus_t *last_rs;
|
||||||
|
const char *my_id, *last_id;
|
||||||
|
int result;
|
||||||
|
smartlist_t *responsible;
|
||||||
|
if (!hid_serv_acting_as_directory())
|
||||||
|
return 0;
|
||||||
|
if (!(me = router_get_my_routerinfo()))
|
||||||
|
return 0; /* This is redundant, but let's be paranoid. */
|
||||||
|
my_id = me->cache_info.identity_digest;
|
||||||
|
responsible = smartlist_new();
|
||||||
|
if (hid_serv_get_responsible_directories(responsible, query) < 0) {
|
||||||
|
smartlist_free(responsible);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
last_rs = smartlist_get(responsible, smartlist_len(responsible)-1);
|
||||||
|
last_id = last_rs->identity_digest;
|
||||||
|
result = rend_id_is_in_interval(my_id, query, last_id);
|
||||||
|
smartlist_free(responsible);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -57,6 +57,10 @@ int rend_id_is_in_interval(const char *a, const char *b, const char *c);
|
|||||||
void rend_get_descriptor_id_bytes(char *descriptor_id_out,
|
void rend_get_descriptor_id_bytes(char *descriptor_id_out,
|
||||||
const char *service_id,
|
const char *service_id,
|
||||||
const char *secret_id_part);
|
const char *secret_id_part);
|
||||||
|
int hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
|
||||||
|
const char *id);
|
||||||
|
int hid_serv_acting_as_directory(void);
|
||||||
|
MOCK_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
|
||||||
|
|
||||||
rend_data_t *rend_data_dup(const rend_data_t *data);
|
rend_data_t *rend_data_dup(const rend_data_t *data);
|
||||||
rend_data_t *rend_data_client_create(const char *onion_address,
|
rend_data_t *rend_data_client_create(const char *onion_address,
|
||||||
|
@ -5395,77 +5395,3 @@ refresh_all_country_info(void)
|
|||||||
|
|
||||||
nodelist_refresh_countries();
|
nodelist_refresh_countries();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Determine the routers that are responsible for <b>id</b> (binary) and
|
|
||||||
* add pointers to those routers' routerstatus_t to <b>responsible_dirs</b>.
|
|
||||||
* Return -1 if we're returning an empty smartlist, else return 0.
|
|
||||||
*/
|
|
||||||
int
|
|
||||||
hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
|
|
||||||
const char *id)
|
|
||||||
{
|
|
||||||
int start, found, n_added = 0, i;
|
|
||||||
networkstatus_t *c = networkstatus_get_latest_consensus();
|
|
||||||
if (!c || !smartlist_len(c->routerstatus_list)) {
|
|
||||||
log_warn(LD_REND, "We don't have a consensus, so we can't perform v2 "
|
|
||||||
"rendezvous operations.");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
tor_assert(id);
|
|
||||||
start = networkstatus_vote_find_entry_idx(c, id, &found);
|
|
||||||
if (start == smartlist_len(c->routerstatus_list)) start = 0;
|
|
||||||
i = start;
|
|
||||||
do {
|
|
||||||
routerstatus_t *r = smartlist_get(c->routerstatus_list, i);
|
|
||||||
if (r->is_hs_dir) {
|
|
||||||
smartlist_add(responsible_dirs, r);
|
|
||||||
if (++n_added == REND_NUMBER_OF_CONSECUTIVE_REPLICAS)
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (++i == smartlist_len(c->routerstatus_list))
|
|
||||||
i = 0;
|
|
||||||
} while (i != start);
|
|
||||||
|
|
||||||
/* Even though we don't have the desired number of hidden service
|
|
||||||
* directories, be happy if we got any. */
|
|
||||||
return smartlist_len(responsible_dirs) ? 0 : -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return true if this node is currently acting as hidden service
|
|
||||||
* directory, false otherwise. */
|
|
||||||
int
|
|
||||||
hid_serv_acting_as_directory(void)
|
|
||||||
{
|
|
||||||
const routerinfo_t *me = router_get_my_routerinfo();
|
|
||||||
if (!me)
|
|
||||||
return 0;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Return true if this node is responsible for storing the descriptor ID
|
|
||||||
* in <b>query</b> and false otherwise. */
|
|
||||||
MOCK_IMPL(int, hid_serv_responsible_for_desc_id,
|
|
||||||
(const char *query))
|
|
||||||
{
|
|
||||||
const routerinfo_t *me;
|
|
||||||
routerstatus_t *last_rs;
|
|
||||||
const char *my_id, *last_id;
|
|
||||||
int result;
|
|
||||||
smartlist_t *responsible;
|
|
||||||
if (!hid_serv_acting_as_directory())
|
|
||||||
return 0;
|
|
||||||
if (!(me = router_get_my_routerinfo()))
|
|
||||||
return 0; /* This is redundant, but let's be paranoid. */
|
|
||||||
my_id = me->cache_info.identity_digest;
|
|
||||||
responsible = smartlist_new();
|
|
||||||
if (hid_serv_get_responsible_directories(responsible, query) < 0) {
|
|
||||||
smartlist_free(responsible);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
last_rs = smartlist_get(responsible, smartlist_len(responsible)-1);
|
|
||||||
last_id = last_rs->identity_digest;
|
|
||||||
result = rend_id_is_in_interval(my_id, query, last_id);
|
|
||||||
smartlist_free(responsible);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -202,11 +202,6 @@ void routers_sort_by_identity(smartlist_t *routers);
|
|||||||
|
|
||||||
void refresh_all_country_info(void);
|
void refresh_all_country_info(void);
|
||||||
|
|
||||||
int hid_serv_get_responsible_directories(smartlist_t *responsible_dirs,
|
|
||||||
const char *id);
|
|
||||||
int hid_serv_acting_as_directory(void);
|
|
||||||
MOCK_DECL(int, hid_serv_responsible_for_desc_id, (const char *id));
|
|
||||||
|
|
||||||
void list_pending_microdesc_downloads(digest256map_t *result);
|
void list_pending_microdesc_downloads(digest256map_t *result);
|
||||||
void launch_descriptor_downloads(int purpose,
|
void launch_descriptor_downloads(int purpose,
|
||||||
smartlist_t *downloadable,
|
smartlist_t *downloadable,
|
||||||
|
Loading…
Reference in New Issue
Block a user