aboutsummaryrefslogtreecommitdiff
path: root/src/or/router.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-06-05 01:50:35 +0000
committerNick Mathewson <nickm@torproject.org>2004-06-05 01:50:35 +0000
commit17b5b3685f5f2f27b05d4e7f5b1dc78939a9f5e8 (patch)
treea98d7127db6e9a733e0978668f539d211b2638c5 /src/or/router.c
parent42569ffd0fc659d81093bc1d7b0fe5171e5738cf (diff)
downloadtor-17b5b3685f5f2f27b05d4e7f5b1dc78939a9f5e8.tar
tor-17b5b3685f5f2f27b05d4e7f5b1dc78939a9f5e8.tar.gz
Make tor build on win32 again; handle locking for server
svn:r1948
Diffstat (limited to 'src/or/router.c')
-rw-r--r--src/or/router.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/or/router.c b/src/or/router.c
index dc9179710..9c263ecd2 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -22,6 +22,7 @@ extern or_options_t options; /* command-line and config-file options */
/** Private keys for this OR. There is also an SSL key managed by tortls.c.
*/
+static tor_mutex_t *key_lock=NULL;
static time_t onionkey_set_at=0; /* When was onionkey last changed? */
static crypto_pk_env_t *onionkey=NULL;
static crypto_pk_env_t *lastonionkey=NULL;
@@ -31,8 +32,10 @@ static crypto_pk_env_t *identitykey=NULL;
* to update onionkey correctly, call rotate_onion_key().
*/
void set_onion_key(crypto_pk_env_t *k) {
+ tor_mutex_acquire(key_lock);
onionkey = k;
onionkey_set_at = time(NULL);
+ tor_mutex_release(key_lock);
}
/** Return the current onion key. Requires that the onion key has been
@@ -50,6 +53,18 @@ crypto_pk_env_t *get_previous_onion_key(void) {
return lastonionkey;
}
+void dup_onion_keys(crypto_pk_env_t **key, crypto_pk_env_t **last)
+{
+ tor_assert(key && last);
+ tor_mutex_acquire(key_lock);
+ *key = crypto_pk_dup_key(onionkey);
+ if (lastonionkey)
+ *last = crypto_pk_dup_key(lastonionkey);
+ else
+ *last = NULL;
+ tor_mutex_release(key_lock);
+}
+
/** Return the time when the onion key was last set. This is either the time
* when the process launched, or the time of the most recent key rotation since
* the process launched.
@@ -96,13 +111,13 @@ void rotate_onion_key(void)
log(LOG_ERR, "Couldn't write generated key to %s.", fname);
goto error;
}
+ tor_mutex_acquire(key_lock);
if (lastonionkey)
crypto_free_pk_env(lastonionkey);
- /* XXXX WINDOWS on windows, we need to protect this next bit with a lock.
- */
log_fn(LOG_INFO, "Rotating onion key");
lastonionkey = onionkey;
set_onion_key(prkey);
+ tor_mutex_release(key_lock);
return;
error:
log_fn(LOG_WARN, "Couldn't rotate onion key.");
@@ -171,6 +186,9 @@ int init_keys(void) {
const char *tmp, *mydesc;
crypto_pk_env_t *prkey;
+ if (!key_lock)
+ key_lock = tor_mutex_new();
+
/* OP's don't need keys. Just initialize the TLS context.*/
if (!options.ORPort) {
tor_assert(!options.DirPort);
@@ -418,7 +436,7 @@ int router_rebuild_descriptor(void) {
ri->socks_port = options.SocksPort;
ri->dir_port = options.DirPort;
ri->published_on = time(NULL);
- ri->onion_pkey = crypto_pk_dup_key(get_onion_key());
+ ri->onion_pkey = crypto_pk_dup_key(get_onion_key()); /* must invoke from main thread */
ri->identity_pkey = crypto_pk_dup_key(get_identity_key());
get_platform_str(platform, sizeof(platform));
ri->platform = tor_strdup(platform);