Skip to content

Commit

Permalink
prop264: sometimes check client _and_ server versions.
Browse files Browse the repository at this point in the history
As before, we check server protocols whenever server_mode(options)
is true and we check client protocols whenever server_mode(options)
is false.

Additionally, we now _also_ check client protocols whenever any
client port is set.
  • Loading branch information
nmathewson committed Sep 26, 2016
1 parent afe0419 commit 0a3da5c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
52 changes: 45 additions & 7 deletions src/or/networkstatus.c
Expand Up @@ -125,6 +125,9 @@ static void routerstatus_list_update_named_server_map(void);
static void update_consensus_bootstrap_multiple_downloads(
time_t now,
const or_options_t *options);
static int networkstatus_check_required_protocols(const networkstatus_t *ns,
int client_mode,
char **warning_out);

/** Forget that we've warned about anything networkstatus-related, so we will
* give fresh warnings if the same behavior happens again. */
Expand Down Expand Up @@ -1553,17 +1556,35 @@ networkstatus_set_current_consensus_from_ns(networkstatus_t *c,
}
#endif //TOR_UNIT_TESTS

/** Called when we have received a networkstatus <b>c</b>. If there are
* any _required_ protocols we are missing, log an error and exit
* immediately. If there are any _recommended_ protocols we are missing,
* warn. */
/**
* Return true if any option is set in <b>options</b> to make us behave
* as a client.
*
* XXXX If we need this elsewhere at any point, we should make it nonstatic
* XXXX and move it into another file.
*/
static int
any_client_port_set(const or_options_t *options)
{
return (options->SocksPort_set ||
options->TransPort_set ||
options->NATDPort_set ||
options->ControlPort_set ||
options->DNSPort_set);
}

/**
* Helper for handle_missing_protocol_warning: handles either the
* client case (if <b>is_client</b> is set) or the server case otherwise.
*/
static void
handle_missing_protocol_warning(const networkstatus_t *c,
const or_options_t *options)
handle_missing_protocol_warning_impl(const networkstatus_t *c,
int is_client)
{
char *protocol_warning = NULL;

int should_exit = networkstatus_check_required_protocols(c,
!server_mode(options),
is_client,
&protocol_warning);
if (protocol_warning) {
tor_log(should_exit ? LOG_ERR : LOG_WARN,
Expand All @@ -1578,6 +1599,23 @@ handle_missing_protocol_warning(const networkstatus_t *c,
exit(1);
}

/** Called when we have received a networkstatus <b>c</b>. If there are
* any _required_ protocols we are missing, log an error and exit
* immediately. If there are any _recommended_ protocols we are missing,
* warn. */
static void
handle_missing_protocol_warning(const networkstatus_t *c,
const or_options_t *options)
{
const int is_server = server_mode(options);
const int is_client = any_client_port_set(options) || !is_server;

if (is_server)
handle_missing_protocol_warning_impl(c, 0);
if (is_client)
handle_missing_protocol_warning_impl(c, 1);
}

/** Try to replace the current cached v3 networkstatus with the one in
* <b>consensus</b>. If we don't have enough certificates to validate it,
* store it in consensus_waiting_for_certs and launch a certificate fetch.
Expand Down
3 changes: 0 additions & 3 deletions src/or/networkstatus.h
Expand Up @@ -122,9 +122,6 @@ void document_signature_free(document_signature_t *sig);
document_signature_t *document_signature_dup(const document_signature_t *sig);
void networkstatus_free_all(void);
int networkstatus_get_weight_scale_param(networkstatus_t *ns);
int networkstatus_check_required_protocols(const networkstatus_t *ns,
int client_mode,
char **warning_out);

#ifdef NETWORKSTATUS_PRIVATE
STATIC void vote_routerstatus_free(vote_routerstatus_t *rs);
Expand Down

0 comments on commit 0a3da5c

Please sign in to comment.