[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] Make OP work on windows! (Also misc logging tweaks)
Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv3675/src/or
Modified Files:
buffers.c connection.c directory.c main.c or.h routerlist.c
Log Message:
Make OP work on windows! (Also misc logging tweaks)
Index: buffers.c
===================================================================
RCS file: /home/or/cvsroot/src/or/buffers.c,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -d -r1.69 -r1.70
--- buffers.c 9 Mar 2004 22:01:16 -0000 1.69
+++ buffers.c 11 Mar 2004 06:19:08 -0000 1.70
@@ -188,13 +188,13 @@
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;
}
-#ifdef MS_WINDOWS
- e = correct_socket_errno(s);
+#ifdef MS_WINDOWS
+ e = correct_socket_errno(s);
if(!ERRNO_EAGAIN(e)) { /* no, it *is* a real error! */
return -1;
}
@@ -249,14 +249,14 @@
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;
}
-#ifdef MS_WINDOWS
- e = correct_socket_errno(s);
+#ifdef MS_WINDOWS
+ e = correct_socket_errno(s);
if(!ERRNO_EAGAIN(e)) { /* no, it *is* a real error! */
return -1;
}
Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection.c,v
retrieving revision 1.178
retrieving revision 1.179
diff -u -d -r1.178 -r1.179
--- connection.c 9 Mar 2004 22:09:13 -0000 1.178
+++ connection.c 11 Mar 2004 06:19:08 -0000 1.179
@@ -154,8 +154,8 @@
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 @@
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;
}
}
@@ -610,7 +611,7 @@
*/
}
} else {
- if (flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen) < 0) {
+ if (flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen) < 0) {
connection_close_immediate(conn); /* Don't flush; connection is dead. */
connection_mark_for_close(conn, END_STREAM_REASON_MISC);
return -1;
Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/src/or/directory.c,v
retrieving revision 1.61
retrieving revision 1.62
diff -u -d -r1.61 -r1.62
--- directory.c 6 Mar 2004 05:09:33 -0000 1.61
+++ directory.c 11 Mar 2004 06:19:08 -0000 1.62
@@ -46,12 +46,12 @@
}
switch(connection_connect(conn, router->address, router->addr, router->dir_port)) {
- case -1:
+ case -1:
router_mark_as_down(conn->nickname); /* don't try him again */
connection_remove(conn);
connection_free(conn);
return;
- case 0:
+ case 0:
connection_set_poll_socket(conn);
connection_watch_events(conn, POLLIN | POLLOUT | POLLERR);
/* writable indicates finish, readable indicates broken link,
@@ -59,7 +59,7 @@
conn->state = command;
return;
/* case 1: fall through */
- }
+ }
connection_set_poll_socket(conn);
if(directory_send_command(conn, command) < 0) {
@@ -237,7 +237,7 @@
int e, len=sizeof(e);
assert(conn && conn->type == CONN_TYPE_DIR);
-
+
switch(conn->state) {
case DIR_CONN_STATE_CONNECTING_FETCH:
case DIR_CONN_STATE_CONNECTING_UPLOAD:
Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.196
retrieving revision 1.197
diff -u -d -r1.196 -r1.197
--- main.c 10 Mar 2004 06:26:38 -0000 1.196
+++ main.c 11 Mar 2004 06:19:08 -0000 1.197
@@ -69,7 +69,8 @@
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 @@
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
@@ -174,7 +176,7 @@
if(!(poll_array[i].revents & (POLLIN|POLLHUP|POLLERR)))
if(!connection_is_reading(conn) ||
!connection_has_pending_tls_data(conn))
- return; /* this conn should not read */
+ return; /* this conn should not read */
log_fn(LOG_DEBUG,"socket %d wants to read.",conn->s);
@@ -191,7 +193,7 @@
/* 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);
}
}
@@ -202,7 +204,7 @@
connection_t *conn;
if(!(poll_array[i].revents & POLLOUT))
- return; /* this conn doesn't want to write */
+ return; /* this conn doesn't want to write */
conn = connection_array[i];
log_fn(LOG_DEBUG,"socket %d wants to write.",conn->s);
@@ -215,7 +217,7 @@
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 @@
* 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 @@
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);
Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.249
retrieving revision 1.250
diff -u -d -r1.249 -r1.250
--- or.h 11 Mar 2004 05:14:06 -0000 1.249
+++ or.h 11 Mar 2004 06:19:08 -0000 1.250
@@ -3,9 +3,16 @@
/* $Id$ */
#ifndef __OR_H
-#define __OR_H
+#define __OR_H
-#include "orconfig.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
@@ -658,7 +662,12 @@
int config_assign_default_dirservers(void);
int getconfig(int argc, char **argv, or_options_t *options);
-/********************************* connection.c ***************************/
+/********************************* 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);
Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- routerlist.c 9 Mar 2004 22:17:35 -0000 1.36
+++ routerlist.c 11 Mar 2004 06:19:08 -0000 1.37
@@ -390,7 +390,7 @@
if (router_resolve_routerlist(routerlist)) {
log_fn(LOG_WARN, "Error resolving routerlist");
return -1;
- }
+ }
if (compare_recommended_versions(VERSION, routerlist->software_versions) < 0) {
log(options.IgnoreVersion ? LOG_WARN : LOG_ERR,
"You are running Tor version %s, which will not work with this network.\n"
@@ -555,11 +555,11 @@
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;