Initial heartbeat subsystem commit.

Sets:
* Documentation
* Logging domain
* Configuration option
* Scheduled event
* Makefile
It also creates status.c and the log_heartbeat() function.

All code was written by Sebastian Hahn. Commit message was
written by me (George Kadianakis).
This commit is contained in:
Sebastian Hahn 2010-12-01 03:24:03 +02:00 committed by Nick Mathewson
parent 0ba69714b4
commit 098b6ba72d
7 changed files with 59 additions and 2 deletions

View File

@ -928,6 +928,10 @@ is non-zero):
seconds, we exit. If we get a second SIGINT, we exit immedi-
ately. (Default: 30 seconds)
**HeartbeatPeriod** __N__ **minutes**|**hours**|**days**|**weeks**::
Log a heartbeat message every **HeartbeatPeriod** seconds. This is
a log level __info__ message, designed to let you know your Tor
instance is still alive and doing useful things. (Default: 6 hours)
**AccountingMax** __N__ **bytes**|**KB**|**MB**|**GB**|**TB**::
Never send more than the specified number of bytes in a given accounting

View File

@ -92,8 +92,10 @@
#define LD_HIST (1u<<18)
/** OR handshaking */
#define LD_HANDSHAKE (1u<<19)
/** Heartbeat messages */
#define LD_HEARTBEAT (1u<<20)
/** Number of logging domains in the code. */
#define N_LOGGING_DOMAINS 20
#define N_LOGGING_DOMAINS 21
/** This log message is not safe to send to a callback-based logger
* immediately. Used as a flag, not a log domain. */

View File

@ -52,7 +52,8 @@ libtor_a_SOURCES = \
routerparse.c \
$(evdns_source) \
$(tor_platform_source) \
config_codedigest.c
config_codedigest.c \
status.c
#libtor_a_LIBADD = ../common/libor.a ../common/libor-crypto.a \
# ../common/libor-event.a

View File

@ -267,6 +267,7 @@ static config_var_t _option_vars[] = {
#endif
OBSOLETE("Group"),
V(HardwareAccel, BOOL, "0"),
V(HeartbeatPeriod, INTERVAL, "6 hours"),
V(AccelName, STRING, NULL),
V(AccelDir, FILENAME, NULL),
V(HashedControlPassword, LINELIST, NULL),
@ -2915,6 +2916,10 @@ compute_publishserverdescriptor(or_options_t *options)
* will generate too many circuits and potentially overload the network. */
#define MIN_CIRCUIT_STREAM_TIMEOUT 10
/** Lowest allowable value for HeartbeatPeriod; if this is too low, we might
* expose more information than we're comfortable with. */
#define MIN_HEARTBEAT_PERIOD (30*60)
/** Return 0 if every setting in <b>options</b> is reasonable, and a
* permissible transition from <b>old_options</b>. Else return -1.
* Should have no side effects, except for normalizing the contents of
@ -3376,6 +3381,14 @@ options_validate(or_options_t *old_options, or_options_t *options,
"raising to %d seconds.", MIN_CIRCUIT_STREAM_TIMEOUT);
options->CircuitStreamTimeout = MIN_CIRCUIT_STREAM_TIMEOUT;
}
if (options->HeartbeatPeriod &&
options->HeartbeatPeriod < MIN_HEARTBEAT_PERIOD) {
log_warn(LD_CONFIG, "HeartbeatPeriod option is too short; "
"raising to %d seconds.", MIN_HEARTBEAT_PERIOD);
options->HeartbeatPeriod = MIN_HEARTBEAT_PERIOD;
}
if (options->KeepalivePeriod < 1)
REJECT("KeepalivePeriod option must be positive.");

View File

@ -1050,6 +1050,7 @@ run_scheduled_events(time_t now)
static time_t time_to_check_port_forwarding = 0;
static int should_init_bridge_stats = 1;
static time_t time_to_retry_dns_init = 0;
static time_t time_last_written_heartbeat = 0;
or_options_t *options = get_options();
int is_server = server_mode(options);
int i;
@ -1440,6 +1441,12 @@ run_scheduled_events(time_t now)
now);
time_to_check_port_forwarding = now+PORT_FORWARDING_CHECK_INTERVAL;
}
/** 11. write the heartbeat message */
if (options->HeartbeatPeriod &&
time_last_written_heartbeat + options->HeartbeatPeriod < now)
log_heartbeat(now);
time_last_written_heartbeat = now;
}
/** Timer: used to invoke second_elapsed_callback() once per second. */

View File

@ -2718,6 +2718,9 @@ typedef struct {
config_line_t *HidServAuth; /**< List of configuration lines for client-side
* authorizations for hidden services */
char *ContactInfo; /**< Contact info to be published in the directory. */
int HeartbeatPeriod; /**< Log heartbeat messages after this many seconds
* have passed. */
char *HTTPProxy; /**< hostname[:port] to use as http proxy, if any. */
tor_addr_t HTTPProxyAddr; /**< Parsed IPv4 addr for http proxy, if any. */

27
src/or/status.c Normal file
View File

@ -0,0 +1,27 @@
/* Copyright (c) 2010, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file status.c
* \brief Keep status information and log the heartbeat messages.
**/
#include "or.h"
/****************************************************************************/
#define BEAT(x) log_fn(LOG_NOTICE, LD_HEARTBEAT, (x) )
void
log_heartbeat(time_t now) {
or_options_t *opt = get_options();
(void) now;
log_fn(LOG_NOTICE, LD_HEARTBEAT, "This is the Tor heartbeat message.");
if (!server_mode(opt))
BEAT("you are a client, hahaha");
}