mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-23 20:03:31 +01:00
Make tor build on win32 again; handle locking for server
svn:r1948
This commit is contained in:
parent
42569ffd0f
commit
17b5b3685f
@ -66,7 +66,7 @@ LINK32=link.exe
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\src\win32" /I "D:\openssl\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "..\..\src\win32" /I "D:\openssl\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /YX /FD /GZ /c
|
||||
# ADD BASE RSC /l 0x409 /d "_DEBUG"
|
||||
# ADD RSC /l 0x409 /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
@ -95,7 +95,15 @@ SOURCE=..\..\src\or\buffers.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\or\circuit.c
|
||||
SOURCE=..\..\src\or\circuitbuild.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\or\circuitlist.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\or\circuituse.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
@ -155,6 +163,10 @@ SOURCE=..\..\src\or\onion.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\or\relay.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\or\rendclient.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
@ -183,6 +195,10 @@ SOURCE=..\..\src\or\routerlist.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\or\routerparse.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\src\or\tor_main.c
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
@ -11,6 +11,9 @@
|
||||
#include "orconfig.h"
|
||||
#include "fakepoll.h"
|
||||
|
||||
#define MAXCONNECTIONS 10000 /* XXXX copied from or.h */
|
||||
#define FD_SETSIZE MAXCONNECTIONS
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
@ -47,8 +50,6 @@ tor_poll(struct pollfd *ufds, unsigned int nfds, int timeout)
|
||||
}
|
||||
#else
|
||||
|
||||
#define FD_SETSIZE MAXCONNECTIONS
|
||||
|
||||
int
|
||||
tor_poll(struct pollfd *ufds, unsigned int nfds, int timeout)
|
||||
{
|
||||
|
@ -1730,6 +1730,56 @@ int tor_lookup_hostname(const char *name, uint32_t *addr)
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef MS_WINDOWS
|
||||
struct tor_mutex_t {
|
||||
};
|
||||
tor_mutex_t *tor_mutex_new(void) { return NULL; }
|
||||
void tor_mutex_acquire(tor_mutex_t *m) { }
|
||||
void tor_mutex_release(tor_mutex_t *m) { }
|
||||
void tor_mutex_free(tor_mutex_t *m) { }
|
||||
#else
|
||||
struct tor_mutex_t {
|
||||
HANDLE handle;
|
||||
};
|
||||
tor_mutex_t *tor_mutex_new(void)
|
||||
{
|
||||
tor_mutex_t *m;
|
||||
m = tor_malloc_zero(sizeof(tor_mutex_t));
|
||||
m->handle = CreateMutex(NULL, FALSE, NULL);
|
||||
tor_assert(m->handle != NULL);
|
||||
return m;
|
||||
}
|
||||
void tor_mutex_free(tor_mutex_t *m)
|
||||
{
|
||||
CloseHandle(m->handle);
|
||||
tor_free(m);
|
||||
}
|
||||
void tor_mutex_acquire(tor_mutex_t *m)
|
||||
{
|
||||
DWORD r;
|
||||
r = WaitForSingleObject(m->handle, INFINITE);
|
||||
switch (r) {
|
||||
case WAIT_ABANDONED: /* holding thread exited. */
|
||||
case WAIT_OBJECT_0: /* we got the mutex normally. */
|
||||
break;
|
||||
case WAIT_TIMEOUT: /* Should never happen. */
|
||||
tor_assert(0);
|
||||
break;
|
||||
case WAIT_FAILED:
|
||||
log_fn(LOG_WARN, "Failed to acquire mutex: %d", GetLastError());
|
||||
}
|
||||
}
|
||||
void tor_mutex_release(tor_mutex_t *m)
|
||||
{
|
||||
BOOL r;
|
||||
r = ReleaseMutex(m->handle);
|
||||
if (!r) {
|
||||
log_fn(LOG_WARN, "Failed to release mutex: %d", GetLastError());
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
Local Variables:
|
||||
mode:c
|
||||
|
@ -221,6 +221,14 @@ int parse_line_from_file(char *line, int maxlen, FILE *f, char **key_out, char *
|
||||
int spawn_func(int (*func)(void *), void *data);
|
||||
void spawn_exit();
|
||||
|
||||
/* Because we use threads instead of processes on Windows, we need locking on Windows.
|
||||
* On Unixy platforms, these functions are no-ops. */
|
||||
typedef struct tor_mutex_t tor_mutex_t;
|
||||
tor_mutex_t *tor_mutex_new(void);
|
||||
void tor_mutex_acquire(tor_mutex_t *m);
|
||||
void tor_mutex_release(tor_mutex_t *m);
|
||||
void tor_mutex_free(tor_mutex_t *m);
|
||||
|
||||
int tor_socketpair(int family, int type, int protocol, int fd[2]);
|
||||
|
||||
int is_internal_IP(uint32_t ip);
|
||||
|
@ -333,7 +333,7 @@ static int connection_create_listener(const char *bindaddress, uint16_t bindport
|
||||
|
||||
memset(&bindaddr,0,sizeof(struct sockaddr_in));
|
||||
bindaddr.sin_family = AF_INET;
|
||||
bindaddr.sin_port = htons(usePort);
|
||||
bindaddr.sin_port = htons((uint16_t) usePort);
|
||||
if(tor_lookup_hostname(hostname, &(bindaddr.sin_addr.s_addr)) != 0) {
|
||||
log_fn(LOG_WARN,"Can't resolve BindAddress %s",hostname);
|
||||
tor_free(hostname);
|
||||
|
@ -202,10 +202,7 @@ static int cpuworker_main(void *data) {
|
||||
connection_free_all(); /* so the child doesn't hold the parent's fd's open */
|
||||
#endif
|
||||
|
||||
/* XXXX WINDOWS lock here. */
|
||||
onion_key = crypto_pk_dup_key(get_onion_key());
|
||||
if (get_previous_onion_key())
|
||||
last_onion_key = crypto_pk_dup_key(get_previous_onion_key());
|
||||
dup_onion_keys(&onion_key, &last_onion_key);
|
||||
|
||||
for(;;) {
|
||||
|
||||
|
@ -1279,6 +1279,7 @@ crypto_pk_env_t *get_previous_onion_key(void);
|
||||
time_t get_onion_key_set_at(void);
|
||||
void set_identity_key(crypto_pk_env_t *k);
|
||||
crypto_pk_env_t *get_identity_key(void);
|
||||
void dup_onion_keys(crypto_pk_env_t **key, crypto_pk_env_t **last);
|
||||
int init_keys(void);
|
||||
crypto_pk_env_t *init_key_from_file(const char *fname);
|
||||
void rotate_onion_key(void);
|
||||
|
@ -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);
|
||||
|
@ -180,6 +180,9 @@ ine to the address where bug reports for this package should be sent. */
|
||||
/* The size of a `uint8_t', as computed by sizeof. */
|
||||
#undef SIZEOF_UINT8_T
|
||||
|
||||
/* The size of a `void *', as computed by sizeof. */
|
||||
#define SIZEOF_VOID_P 4
|
||||
|
||||
/* The size of a `__int64', as computed by sizeof. */
|
||||
#define SIZEOF___INT64 8
|
||||
|
||||
@ -190,4 +193,4 @@ ine to the address where bug reports for this package should be sent. */
|
||||
#define UNALIGNED_INT_ACCESS_OK
|
||||
|
||||
/* Version number of package */
|
||||
#define VERSION "0.0.6"
|
||||
#define VERSION "0.0.7rc1-cvs"
|
||||
|
Loading…
Reference in New Issue
Block a user