Procházet zdrojové kódy

Make OP work on windows! (Also misc logging tweaks)

svn:r1258
Nick Mathewson před 21 roky
rodič
revize
9b4203266e
6 změnil soubory, kde provedl 36 přidání a 26 odebrání
  1. 7 9
      src/common/crypto.c
  2. 2 2
      src/or/buffers.c
  3. 4 3
      src/or/connection.c
  4. 9 7
      src/or/main.c
  5. 12 3
      src/or/or.h
  6. 2 2
      src/or/routerlist.c

+ 7 - 9
src/common/crypto.c

@@ -2,6 +2,8 @@
 /* See LICENSE for licensing information */
 /* $Id$ */
 
+#include "../or/or.h"
+
 #include <string.h>
 
 #include <openssl/err.h>
@@ -19,10 +21,13 @@
 #include <limits.h>
 
 #include "crypto.h"
-#include "../or/or.h"
 #include "log.h"
 #include "aes.h"
 
+#ifdef MS_WINDOWS
+#include <wincrypt.h>
+#endif
+
 #if OPENSSL_VERSION_NUMBER < 0x00905000l
 #error "We require openssl >= 0.9.5"
 #elif OPENSSL_VERSION_NUMBER < 0x00906000l
@@ -41,13 +46,6 @@
 #define RETURN_SSL_OUTCOME(exp) return !(exp)
 #endif
 
-#ifdef MS_WINDOWS
-#define WIN32_WINNT 0x400
-#define _WIN32_WINNT 0x400
-#include <windows.h>
-#include <wincrypt.h>
-#endif
-
 struct crypto_pk_env_t
 {
   int type;
@@ -1043,7 +1041,7 @@ void crypto_dh_free(crypto_dh_env_t *dh)
 int crypto_seed_rng()
 {
   static int provider_set = 0;
-  static HCRYPTPROV p;
+  static HCRYPTPROV provider;
   char buf[21];
 
   if (!provider_set) {

+ 2 - 2
src/or/buffers.c

@@ -188,7 +188,7 @@ int read_to_buf(int s, int at_most, buf_t *buf, int *reached_eof) {
     return 0; /* we shouldn't read anything */
 
 //  log_fn(LOG_DEBUG,"reading at most %d bytes.",at_most);
-  read_result = read(s, buf->mem+buf->datalen, at_most);
+  read_result = recv(s, buf->mem+buf->datalen, at_most, 0);
   if (read_result < 0) {
     if(!ERRNO_EAGAIN(errno)) { /* it's a real error */
       return -1;
@@ -250,7 +250,7 @@ int flush_buf(int s, buf_t *buf, int *buf_flushlen)
   if(*buf_flushlen == 0) /* nothing to flush */
     return 0;
 
-  write_result = write(s, buf->mem, *buf_flushlen);
+  write_result = send(s, buf->mem, *buf_flushlen, 0);
   if (write_result < 0) {
     if(!ERRNO_EAGAIN(errno)) { /* it's a real error */
       return -1;

+ 4 - 3
src/or/connection.c

@@ -154,8 +154,8 @@ void connection_close_immediate(connection_t *conn)
     return;
   }
   if (conn->outbuf_flushlen) {
-    log_fn(LOG_INFO,"Closing connection (fd %d, type %d, state %d) with data on outbuf.",
-           conn->s, conn->type, conn->state);
+    log_fn(LOG_INFO,"Closing connection (fd %d, type %s, state %d) with data on outbuf.",
+           conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state);
   }
   close(conn->s);
   conn->s = -1;
@@ -226,7 +226,8 @@ void connection_expire_held_open(void)
     if (conn->hold_open_until_flushed) {
       assert(conn->marked_for_close);
       if (now - conn->timestamp_lastwritten >= 15) {
-        log_fn(LOG_WARN,"Giving up on marked_for_close conn that's been flushing for 15s (fd %d, type %d, state %d).", conn->s, conn->type, conn->state);
+        log_fn(LOG_WARN,"Giving up on marked_for_close conn that's been flushing for 15s (fd %d, type %s, state %d).", 
+			conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state);
         conn->hold_open_until_flushed = 0;
       }
     }

+ 9 - 7
src/or/main.c

@@ -69,7 +69,8 @@ int connection_add(connection_t *conn) {
 
   nfds++;
 
-  log(LOG_INFO,"connection_add(): new conn type %d, socket %d, nfds %d.",conn->type, conn->s, nfds);
+  log(LOG_INFO,"connection_add(): new conn type %s, socket %d, nfds %d.",
+	  CONN_TYPE_TO_STRING(conn->type), conn->s, nfds);
 
   return 0;
 }
@@ -88,7 +89,8 @@ int connection_remove(connection_t *conn) {
   assert(conn);
   assert(nfds>0);
 
-  log(LOG_INFO,"connection_remove(): removing socket %d, nfds now %d",conn->s, nfds-1);
+  log_fn(LOG_INFO,"removing socket %d (type %s), nfds now %d",
+	  conn->s, CONN_TYPE_TO_STRING(conn->type), nfds-1);
   /* if it's an edge conn, remove it from the list
    * of conn's on this circuit. If it's not on an edge,
    * flush and send destroys for all circuits on this conn
@@ -191,7 +193,7 @@ static void conn_read(int i) {
         /* XXX This shouldn't ever happen anymore. */
         /* XXX but it'll clearly happen on MS_WINDOWS from POLLERR, right? */
         log_fn(LOG_ERR,"Unhandled error on read for %s connection (fd %d); removing",
-               conn_type_to_string[conn->type], conn->s);
+               CONN_TYPE_TO_STRING(conn->type), conn->s);
         connection_mark_for_close(conn,0);
       }
     }
@@ -215,7 +217,7 @@ static void conn_write(int i) {
     if (!conn->marked_for_close) {
       /* this connection is broken. remove it. */
       log_fn(LOG_WARN,"Unhandled error on read for %s connection (fd %d); removing",
-             conn_type_to_string[conn->type], conn->s);
+             CONN_TYPE_TO_STRING(conn->type), conn->s);
       conn->has_sent_end = 1; /* otherwise we cry wolf about duplicate close */
       connection_mark_for_close(conn,0);
     }
@@ -238,9 +240,9 @@ static void conn_close_if_marked(int i) {
      * has already been closed as unflushable. */
     if(!conn->hold_open_until_flushed)
       log_fn(LOG_WARN,
-        "Conn (fd %d, type %d, state %d) marked, but wants to flush %d bytes. "
+        "Conn (fd %d, type %s, state %d) marked, but wants to flush %d bytes. "
         "(Marked at %s:%d)",
-        conn->s, conn->type, conn->state,
+        conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state,
         conn->outbuf_flushlen, conn->marked_for_close_file, conn->marked_for_close);
     if(connection_speaks_cells(conn)) {
       if(conn->state == OR_CONN_STATE_OPEN) {
@@ -654,7 +656,7 @@ static void dumpstats(int severity) {
   for(i=0;i<nfds;i++) {
     conn = connection_array[i];
     log(severity, "Conn %d (socket %d) type %d (%s), state %d (%s), created %ld secs ago",
-      i, conn->s, conn->type, conn_type_to_string[conn->type],
+      i, conn->s, conn->type, CONN_TYPE_TO_STRING(conn->type),
       conn->state, conn_state_to_string[conn->type][conn->state], now - conn->timestamp_created);
     if(!connection_is_listener(conn)) {
       log(severity,"Conn %d is to '%s:%d'.",i,conn->address, conn->port);

+ 12 - 3
src/or/or.h

@@ -6,6 +6,13 @@
 #define __OR_H
 
 #include "orconfig.h"
+#ifdef MS_WINDOWS
+#define WIN32_WINNT 0x400
+#define _WIN32_WINNT 0x400
+#define WIN32_LEAN_AND_MEAN
+/* Number of fds that select will accept; default is 64. */
+#define FD_SETSIZE 512
+#endif
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -86,9 +93,6 @@
 #include <io.h>
 #include <process.h>
 #include <direct.h>
-#define WIN32_WINNT 0x400
-#define _WIN32_WINNT 0x400
-#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #define snprintf _snprintf
 #endif
@@ -660,6 +664,11 @@ int getconfig(int argc, char **argv, or_options_t *options);
 
 /********************************* connection.c ***************************/
 
+#define CONN_TYPE_TO_STRING(t) (((t) < _CONN_TYPE_MIN || (t) > _CONN_TYPE_MAX) ? "Unknown" : \
+	                            conn_type_to_string[(t)])
+
+extern char *conn_type_to_string[];
+
 connection_t *connection_new(int type);
 void connection_free(connection_t *conn);
 void connection_free_all(void);

+ 2 - 2
src/or/routerlist.c

@@ -555,11 +555,11 @@ static int parse_time(const char *cp, time_t *t)
 	log_fn(LOG_WARN, "Published time was unparseable"); return -1;
   }
   if (year < 1970 || month < 1 || month > 12 || day < 1 || day > 31 ||
-	  hour > 24 || minute > 61 || second > 62) {
+	  hour > 23 || minute > 59 || second > 61) {
 	log_fn(LOG_WARN, "Published time was nonsensical"); return -1;
   }
   st_tm.tm_year = year;
-  st_tm.tm_mon = month;
+  st_tm.tm_mon = month-1;
   st_tm.tm_mday = day;
   st_tm.tm_hour = hour;
   st_tm.tm_min = minute;