diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-06-05 01:50:35 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-06-05 01:50:35 +0000 |
commit | 17b5b3685f5f2f27b05d4e7f5b1dc78939a9f5e8 (patch) | |
tree | a98d7127db6e9a733e0978668f539d211b2638c5 | |
parent | 42569ffd0fc659d81093bc1d7b0fe5171e5738cf (diff) | |
download | tor-17b5b3685f5f2f27b05d4e7f5b1dc78939a9f5e8.tar.gz tor-17b5b3685f5f2f27b05d4e7f5b1dc78939a9f5e8.zip |
Make tor build on win32 again; handle locking for server
svn:r1948
-rw-r--r-- | Win32Build/or/or.dsp | 20 | ||||
-rw-r--r-- | src/common/fakepoll.c | 5 | ||||
-rw-r--r-- | src/common/util.c | 50 | ||||
-rw-r--r-- | src/common/util.h | 8 | ||||
-rw-r--r-- | src/or/connection.c | 2 | ||||
-rw-r--r-- | src/or/cpuworker.c | 5 | ||||
-rw-r--r-- | src/or/or.h | 1 | ||||
-rw-r--r-- | src/or/router.c | 24 | ||||
-rw-r--r-- | src/win32/orconfig.h | 5 |
9 files changed, 107 insertions, 13 deletions
diff --git a/Win32Build/or/or.dsp b/Win32Build/or/or.dsp index b88f88fa5d..b52f69b044 100644 --- a/Win32Build/or/or.dsp +++ b/Win32Build/or/or.dsp @@ -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
diff --git a/src/common/fakepoll.c b/src/common/fakepoll.c index 46dbe85e2d..f23c20e652 100644 --- a/src/common/fakepoll.c +++ b/src/common/fakepoll.c @@ -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) { diff --git a/src/common/util.c b/src/common/util.c index 2db99d6c05..89d2000132 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -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 diff --git a/src/common/util.h b/src/common/util.h index 6f707ca729..40154e8bfa 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -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); diff --git a/src/or/connection.c b/src/or/connection.c index b7d2c52e04..aaafbe3068 100644 --- a/src/or/connection.c +++ b/src/or/connection.c @@ -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); diff --git a/src/or/cpuworker.c b/src/or/cpuworker.c index 94a2238b62..1b55822a5f 100644 --- a/src/or/cpuworker.c +++ b/src/or/cpuworker.c @@ -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(;;) { diff --git a/src/or/or.h b/src/or/or.h index 7eee5a789b..e121266bd5 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -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); diff --git a/src/or/router.c b/src/or/router.c index dc91797101..9c263ecd2e 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); diff --git a/src/win32/orconfig.h b/src/win32/orconfig.h index 04629861b9..4aa1b7809e 100644 --- a/src/win32/orconfig.h +++ b/src/win32/orconfig.h @@ -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" |