mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Add getinfo logic for accounting; add options for helper nodes
svn:r4632
This commit is contained in:
parent
76a6cec3f1
commit
5b4e11fa5d
@ -179,6 +179,8 @@ static config_var_t config_vars[] = {
|
|||||||
VAR("SysLog", LINELIST_S, OldLogOptions, NULL),
|
VAR("SysLog", LINELIST_S, OldLogOptions, NULL),
|
||||||
OBSOLETE("TrafficShaping"),
|
OBSOLETE("TrafficShaping"),
|
||||||
VAR("User", STRING, User, NULL),
|
VAR("User", STRING, User, NULL),
|
||||||
|
VAR("UseHelperNodes", BOOL, UseHelperNodes, "0"),
|
||||||
|
VAR("NumHelperNodes", UINT, NumHelperNodes, "3"),
|
||||||
VAR("__LeaveStreamsUnattached", BOOL,LeaveStreamsUnattached, "0"),
|
VAR("__LeaveStreamsUnattached", BOOL,LeaveStreamsUnattached, "0"),
|
||||||
{ NULL, CONFIG_TYPE_OBSOLETE, 0, NULL }
|
{ NULL, CONFIG_TYPE_OBSOLETE, 0, NULL }
|
||||||
};
|
};
|
||||||
@ -1564,6 +1566,11 @@ options_validate(or_options_t *options)
|
|||||||
result = -1;
|
result = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options->UseHelperNodes && ! options->NumHelperNodes) {
|
||||||
|
log_fn(LOG_WARN, "Cannot enable UseHelperNodes with NumHelperNodes set to 0");
|
||||||
|
result = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (check_nickname_list(options->ExitNodes, "ExitNodes"))
|
if (check_nickname_list(options->ExitNodes, "ExitNodes"))
|
||||||
result = -1;
|
result = -1;
|
||||||
if (check_nickname_list(options->EntryNodes, "EntryNodes"))
|
if (check_nickname_list(options->EntryNodes, "EntryNodes"))
|
||||||
|
@ -1121,6 +1121,8 @@ handle_getinfo_helper(const char *question, char **answer)
|
|||||||
*answer = NULL; /* unrecognized key by default */
|
*answer = NULL; /* unrecognized key by default */
|
||||||
if (!strcmp(question, "version")) {
|
if (!strcmp(question, "version")) {
|
||||||
*answer = tor_strdup(VERSION);
|
*answer = tor_strdup(VERSION);
|
||||||
|
} else if (!strcmpstart(question, "accounting/")) {
|
||||||
|
return accounting_getinfo_helper(question, answer);
|
||||||
} else if (!strcmpstart(question, "desc/id/")) {
|
} else if (!strcmpstart(question, "desc/id/")) {
|
||||||
routerinfo_t *ri = router_get_by_hexdigest(question+strlen("desc/id/"));
|
routerinfo_t *ri = router_get_by_hexdigest(question+strlen("desc/id/"));
|
||||||
if (ri && ri->signed_descriptor)
|
if (ri && ri->signed_descriptor)
|
||||||
|
@ -100,6 +100,8 @@ static void accounting_set_wakeup_time(void);
|
|||||||
* Functions for bandwidth accounting.
|
* Functions for bandwidth accounting.
|
||||||
* ************/
|
* ************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Configure accounting start/end time settings based on
|
/** Configure accounting start/end time settings based on
|
||||||
* options->AccountingStart. Return 0 on success, -1 on failure. If
|
* options->AccountingStart. Return 0 on success, -1 on failure. If
|
||||||
* <b>validate_only</b> is true, do not change the current settings. */
|
* <b>validate_only</b> is true, do not change the current settings. */
|
||||||
@ -846,3 +848,41 @@ consider_hibernation(time_t now)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** DOCDOC */
|
||||||
|
int
|
||||||
|
accounting_getinfo_helper(const char *question, char **answer)
|
||||||
|
{
|
||||||
|
if (!strcmp(question, "accounting/enabled")) {
|
||||||
|
*answer = tor_strdup(get_options()->AccountingMax ? "1" : "0");
|
||||||
|
} else if (!strcmp(question, "accounting/hibernating")) {
|
||||||
|
if (hibernate_state == HIBERNATE_STATE_DORMANT)
|
||||||
|
*answer = tor_strdup("hard");
|
||||||
|
else if (hibernate_state == HIBERNATE_STATE_LOWBANDWIDTH)
|
||||||
|
*answer = tor_strdup("soft");
|
||||||
|
else
|
||||||
|
*answer = tor_strdup("awake");
|
||||||
|
} else if (!strcmp(question, "accounting/bytes")) {
|
||||||
|
*answer = tor_malloc(32);
|
||||||
|
tor_snprintf(*answer, 32, U64_FORMAT" "U64_FORMAT,
|
||||||
|
U64_PRINTF_ARG(n_bytes_read_in_interval),
|
||||||
|
U64_PRINTF_ARG(n_bytes_written_in_interval));
|
||||||
|
} else if (!strcmp(question, "accounting/bytes-left")) {
|
||||||
|
*answer = tor_malloc(32);
|
||||||
|
uint64_t limit = get_options()->AccountingMax;
|
||||||
|
tor_snprintf(*answer, 32, U64_FORMAT" "U64_FORMAT,
|
||||||
|
U64_PRINTF_ARG(limit - n_bytes_read_in_interval),
|
||||||
|
U64_PRINTF_ARG(limit - n_bytes_written_in_interval));
|
||||||
|
} else if (!strcmp(question, "accounting/interval-start")) {
|
||||||
|
*answer = tor_malloc(ISO_TIME_LEN+1);
|
||||||
|
format_iso_time(*answer, interval_start_time);
|
||||||
|
} else if (!strcmp(question, "accounting/interval-wake")) {
|
||||||
|
*answer = tor_malloc(ISO_TIME_LEN+1);
|
||||||
|
format_iso_time(*answer, interval_wakeup_time);
|
||||||
|
} else if (!strcmp(question, "accounting/interval-end")) {
|
||||||
|
*answer = tor_malloc(ISO_TIME_LEN+1);
|
||||||
|
format_iso_time(*answer, interval_end_time);
|
||||||
|
} else {
|
||||||
|
*answer = NULL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
@ -1164,6 +1164,9 @@ typedef struct {
|
|||||||
* such as addresses (0), or do we scrub them first (1)? */
|
* such as addresses (0), or do we scrub them first (1)? */
|
||||||
int HardwareAccel; /**< Boolean: Should we enable OpenSSL hardware
|
int HardwareAccel; /**< Boolean: Should we enable OpenSSL hardware
|
||||||
* acceleration where available? */
|
* acceleration where available? */
|
||||||
|
int UseHelperNodes; /**< Boolean: Do we try to enter from a smallish number
|
||||||
|
* of fixed nodes? */
|
||||||
|
int NumHelperNodes; /**< How many helper nodes do we try to establish? */
|
||||||
} or_options_t;
|
} or_options_t;
|
||||||
|
|
||||||
#define MAX_SOCKS_REPLY_LEN 1024
|
#define MAX_SOCKS_REPLY_LEN 1024
|
||||||
@ -1619,6 +1622,8 @@ int accounting_record_bandwidth_usage(time_t now);
|
|||||||
void hibernate_begin_shutdown(void);
|
void hibernate_begin_shutdown(void);
|
||||||
int we_are_hibernating(void);
|
int we_are_hibernating(void);
|
||||||
void consider_hibernation(time_t now);
|
void consider_hibernation(time_t now);
|
||||||
|
int accounting_getinfo_helper(const char *question, char **answer);
|
||||||
|
|
||||||
|
|
||||||
/********************************* main.c ***************************/
|
/********************************* main.c ***************************/
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user