Skip to content

Commit

Permalink
control: Add a key to GETINFO to fetch the circuit onion handshake re…
Browse files Browse the repository at this point in the history
…phist values
  • Loading branch information
neelchauhan authored and dgoulet-tor committed Jul 1, 2020
1 parent 8d8a9d7 commit 4477317
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/feature/control/control_getinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "feature/rend/rendcache.h"
#include "feature/stats/geoip_stats.h"
#include "feature/stats/predict_ports.h"
#include "feature/stats/rephist.h"
#include "lib/version/torversion.h"
#include "lib/encoding/kvline.h"

Expand Down Expand Up @@ -1436,6 +1437,39 @@ getinfo_helper_liveness(control_connection_t *control_conn,
return 0;
}

/** Implementation helper for GETINFO: answers queries about circuit onion
* handshake rephist values */
STATIC int
getinfo_helper_rephist(control_connection_t *control_conn,
const char *question, char **answer,
const char **errmsg)
{
(void) control_conn;
(void) errmsg;
int result;

if (!strcmp(question, "stats/ntor/assigned")) {
result =
rep_hist_get_circuit_handshake_assigned(ONION_HANDSHAKE_TYPE_NTOR);
} else if (!strcmp(question, "stats/ntor/requested")) {
result =
rep_hist_get_circuit_handshake_requested(ONION_HANDSHAKE_TYPE_NTOR);
} else if (!strcmp(question, "stats/tap/assigned")) {
result =
rep_hist_get_circuit_handshake_assigned(ONION_HANDSHAKE_TYPE_TAP);
} else if (!strcmp(question, "stats/tap/requested")) {
result =
rep_hist_get_circuit_handshake_requested(ONION_HANDSHAKE_TYPE_TAP);
} else {
*errmsg = "Unrecognized handshake type";
return -1;
}

tor_asprintf(answer, "%d", result);

return 0;
}

/** Implementation helper for GETINFO: answers queries about shared random
* value. */
static int
Expand Down Expand Up @@ -1660,6 +1694,16 @@ static const getinfo_item_t getinfo_items[] = {
"Onion services detached from the control connection."),
ITEM("sr/current", sr, "Get current shared random value."),
ITEM("sr/previous", sr, "Get previous shared random value."),
PREFIX("stats/ntor/", rephist, "NTor circuit handshake stats."),
ITEM("stats/ntor/assigned", rephist,
"Assigned NTor circuit handshake stats."),
ITEM("stats/ntor/requested", rephist,
"Requested NTor circuit handshake stats."),
PREFIX("stats/tap/", rephist, "TAP circuit handshake stats."),
ITEM("stats/tap/assigned", rephist,
"Assigned TAP circuit handshake stats."),
ITEM("stats/tap/requested", rephist,
"Requested TAP circuit handshake stats."),
{ NULL, NULL, NULL, 0 }
};

Expand Down
4 changes: 4 additions & 0 deletions src/feature/control/control_getinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ STATIC int getinfo_helper_current_time(
control_connection_t *control_conn,
const char *question, char **answer,
const char **errmsg);
STATIC int getinfo_helper_rephist(
control_connection_t *control_conn,
const char *question, char **answer,
const char **errmsg);
#endif /* defined(CONTROL_GETINFO_PRIVATE) */

#endif /* !defined(TOR_CONTROL_GETINFO_H) */
20 changes: 20 additions & 0 deletions src/feature/stats/rephist.c
Original file line number Diff line number Diff line change
Expand Up @@ -2455,6 +2455,26 @@ rep_hist_note_circuit_handshake_assigned(uint16_t type)
onion_handshakes_assigned[type]++;
}

/** Get the circuit handshake value that is requested. */
MOCK_IMPL(int,
rep_hist_get_circuit_handshake_requested, (uint16_t type))
{
if (BUG(type > MAX_ONION_HANDSHAKE_TYPE)) {
return 0;
}
return onion_handshakes_requested[type];
}

/** Get the circuit handshake value that is assigned. */
MOCK_IMPL(int,
rep_hist_get_circuit_handshake_assigned, (uint16_t type))
{
if (BUG(type > MAX_ONION_HANDSHAKE_TYPE)) {
return 0;
}
return onion_handshakes_assigned[type];
}

/** Log our onionskin statistics since the last time we were called. */
void
rep_hist_log_circuit_handshake_stats(time_t now)
Expand Down
3 changes: 3 additions & 0 deletions src/feature/stats/rephist.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ void rep_hist_note_circuit_handshake_requested(uint16_t type);
void rep_hist_note_circuit_handshake_assigned(uint16_t type);
void rep_hist_log_circuit_handshake_stats(time_t now);

MOCK_DECL(int, rep_hist_get_circuit_handshake_requested, (uint16_t type));
MOCK_DECL(int, rep_hist_get_circuit_handshake_assigned, (uint16_t type));

void rep_hist_hs_stats_init(time_t now);
void rep_hist_hs_stats_term(void);
time_t rep_hist_hs_stats_write(time_t now);
Expand Down

0 comments on commit 4477317

Please sign in to comment.