[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

patch for win32



I had some problem getting tor running on windows. I used
FascistFirewall option but this make tor.exe crash (0.1.1.21 from
installer, 0.1.1.22 from downloaded tor and cvs version). I fixed with
crash.diff. To compile I had to apply project.diff to include a new file
and remove old one. Then stopping and starting tor I had a bad assertion
caused by mmap use. You save cached routers writing file textually but
you compute offsets using program size. This cause an assert when you
load from cache cause "\n" character written to file became "\r\n" under
windows (see mmap.diff patch). I used msvc6 which have older headers so
GetVersionEx use a former declaration for structure, I disable code to
parse full version using oldver.diff. Also msvc6 do not support
conversion from uint64 to double and I use badcast.diff patch (but I
don't know if this patch should be applied blindly...)

bye
  Frediano Ziglio

diff -u -1 -0 -r1.569 config.c
--- src/or/config.c	6 Jul 2006 02:44:05 -0000	1.569
+++ src/or/config.c	7 Jul 2006 13:33:29 -0000
@@ -2180,21 +2180,21 @@
     options->_AccountingMaxKB = 0;
   }
 
   if (validate_ports_csv(options->FirewallPorts, "FirewallPorts", msg) < 0)
     return -1;
 
   if (validate_ports_csv(options->LongLivedPorts, "LongLivedPorts", msg) < 0)
     return -1;
 
   if (options->FascistFirewall && !options->ReachableAddresses) {
-    if (smartlist_len(options->FirewallPorts)) {
+    if (options->FirewallPorts && smartlist_len(options->FirewallPorts)) {
       /* We already have firewall ports set, so migrate them to
        * ReachableAddresses, which will set ReachableORAddresses and
        * ReachableDirAddresses if they aren't set explicitly. */
       smartlist_t *instead = smartlist_create();
       config_line_t *new_line = tor_malloc_zero(sizeof(config_line_t));
       new_line->key = tor_strdup("ReachableAddresses");
       /* If we're configured with the old format, we need to prepend some
        * open ports. */
       SMARTLIST_FOREACH(options->FirewallPorts, const char *, portno,
       {
Index: Win32Build/vc6/tor/Tor.dsp
===================================================================
RCS file: /home/or/cvsroot/tor/Win32Build/vc6/tor/Tor.dsp,v
retrieving revision 1.2
diff -u -1 -0 -r1.2 Tor.dsp
--- Win32Build/vc6/tor/Tor.dsp	14 Nov 2004 18:19:28 -0000	1.2
+++ Win32Build/vc6/tor/Tor.dsp	7 Jul 2006 13:33:27 -0000
@@ -99,24 +99,20 @@
 # Begin Source File
 
 SOURCE=..\..\..\src\common\container.c
 # End Source File
 # Begin Source File
 
 SOURCE=..\..\..\src\common\crypto.c
 # End Source File
 # Begin Source File
 
-SOURCE=..\..\..\src\common\fakepoll.c
-# End Source File
-# Begin Source File
-
 SOURCE=..\..\..\src\common\log.c
 # End Source File
 # Begin Source File
 
 SOURCE=..\..\..\src\common\log.h
 # End Source File
 # Begin Source File
 
 SOURCE=..\..\..\src\common\torgzip.c
 # End Source File
@@ -287,20 +283,24 @@
 # Begin Source File
 
 SOURCE=..\..\..\src\or\main.c
 # End Source File
 # Begin Source File
 
 SOURCE=..\..\..\src\or\onion.c
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\..\src\or\policies.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
 
 SOURCE=..\..\..\src\or\rendcommon.c
 # End Source File
Index: src/or/routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.530
diff -u -1 -0 -r1.530 routerlist.c
--- src/or/routerlist.c	28 Jun 2006 15:39:02 -0000	1.530
+++ src/or/routerlist.c	7 Jul 2006 13:33:32 -0000
@@ -174,21 +174,21 @@
   size_t fname_len = strlen(options->DataDirectory)+32;
   char *fname = tor_malloc(fname_len);
   const char *body = signed_descriptor_get_body(desc);
   size_t len = desc->signed_descriptor_len;
 
   tor_snprintf(fname, fname_len, "%s/cached-routers.new",
                options->DataDirectory);
 
   tor_assert(len == strlen(body));
 
-  if (append_bytes_to_file(fname, body, len, 0)) {
+  if (append_bytes_to_file(fname, body, len, 1)) {
     log_warn(LD_FS, "Unable to store router descriptor");
     tor_free(fname);
     return -1;
   }
   desc->saved_location = SAVED_IN_JOURNAL;
   desc->saved_offset = router_journal_len;
 
   tor_free(fname);
   router_journal_len += len;
   return 0;
@@ -264,21 +264,21 @@
         log_warn(LD_BUG, "Bug! No descriptor available for router.");
         smartlist_free(lst);
         goto done;
       }
       c = tor_malloc(sizeof(sized_chunk_t));
       c->bytes = body;
       c->len = sd->signed_descriptor_len;
       smartlist_add(chunk_list, c);
     });
   }
-  if (write_chunks_to_file(fname, chunk_list, 0)<0) {
+  if (write_chunks_to_file(fname, chunk_list, 1)<0) {
     log_warn(LD_FS, "Error writing router store to disk.");
     goto done;
   }
   /* Our mmap is now invalid. */
   if (routerlist->mmap_descriptors) {
     tor_munmap_file(routerlist->mmap_descriptors,
                     routerlist->mmap_descriptors_len);
     routerlist->mmap_descriptors =
       tor_mmap_file(fname, &routerlist->mmap_descriptors_len);
     if (! routerlist->mmap_descriptors)
@@ -301,21 +301,21 @@
       offset += sd->signed_descriptor_len;
       signed_descriptor_get_body(sd);
     });
   }
   smartlist_free(old_routers);
   smartlist_free(routers);
 
   tor_snprintf(fname, fname_len, "%s/cached-routers.new",
                options->DataDirectory);
 
-  write_str_to_file(fname, "", 0);
+  write_str_to_file(fname, "", 1);
 
   r = 0;
   router_store_len = len;
   router_journal_len = 0;
   router_bytes_dropped = 0;
  done:
   tor_free(fname);
   if (chunk_list) {
     SMARTLIST_FOREACH(chunk_list, sized_chunk_t *, c, tor_free(c));
     smartlist_free(chunk_list);
@@ -343,21 +343,21 @@
   routerlist->mmap_descriptors =
     tor_mmap_file(fname, &routerlist->mmap_descriptors_len);
   if (routerlist->mmap_descriptors) {
     router_store_len = routerlist->mmap_descriptors_len;
     router_load_routers_from_string(routerlist->mmap_descriptors,
                                     SAVED_IN_CACHE, NULL);
   }
 
   tor_snprintf(fname, fname_len, "%s/cached-routers.new",
                options->DataDirectory);
-  contents = read_file_to_str(fname, 0);
+  contents = read_file_to_str(fname, 1);
   if (contents) {
     stat(fname, &st);
     router_load_routers_from_string(contents,
                                     SAVED_IN_JOURNAL, NULL);
   }
 
   tor_free(fname);
 
   if (router_journal_len) {
     /* Always clear the journal on startup.*/
Index: src/common/compat.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/common/compat.c,v
retrieving revision 1.91
diff -u -1 -0 -r1.91 compat.c
--- src/common/compat.c	28 Jun 2006 08:54:32 -0000	1.91
+++ src/common/compat.c	7 Jul 2006 13:33:27 -0000
@@ -761,37 +761,39 @@
           { 5, 2, "Windows Server 2003" },
           { 5, 1, "Windows XP" },
           { 5, 0, "Windows 2000" },
           /* { 4, 0, "Windows NT 4.0" }, */
           { 4, 90, "Windows Me" },
           { 4, 10, "Windows 98" },
           /* { 4, 0, "Windows 95" } */
           { 3, 51, "Windows NT 3.51" },
           { -1, -1, NULL }
         };
+#ifdef VER_SUITE_BACKOFFICE
         static struct {
           unsigned int mask; const char *str;
         } win_mask_table[] = {
           { VER_SUITE_BACKOFFICE,         " {backoffice}" },
           { VER_SUITE_BLADE,              " {\"blade\" (2003, web edition)}" },
           { VER_SUITE_DATACENTER,         " {datacenter}" },
           { VER_SUITE_ENTERPRISE,         " {enterprise}" },
           { VER_SUITE_EMBEDDEDNT,         " {embedded}" },
           { VER_SUITE_PERSONAL,           " {personal}" },
           { VER_SUITE_SINGLEUSERTS,
             " {terminal services, single user}" },
           { VER_SUITE_SMALLBUSINESS,      " {small business}" },
           { VER_SUITE_SMALLBUSINESS_RESTRICTED,
             " {small business, restricted}" },
           { VER_SUITE_TERMINAL,           " {terminal services}" },
           { 0, NULL },
         };
+#endif
         memset(&info, 0, sizeof(info));
         info.dwOSVersionInfoSize = sizeof(info);
         if (! GetVersionEx((LPOSVERSIONINFO)&info)) {
           int err = GetLastError();
           strlcpy(uname_result, "Bizarre version of Windows where GetVersionEx"
                   " doesn't work.", sizeof(uname_result));
           uname_result_is_set = 1;
           return uname_result;
         }
         if (info.dwMajorVersion == 4 && info.dwMinorVersion == 0) {
@@ -817,39 +819,41 @@
             tor_snprintf(uname_result, sizeof(uname_result),
                       "Very recent version of Windows [major=%d,minor=%d] %s",
                       (int)info.dwMajorVersion,(int)info.dwMinorVersion,
                       info.szCSDVersion);
           else
             tor_snprintf(uname_result, sizeof(uname_result),
                       "Unrecognized version of Windows [major=%d,minor=%d] %s",
                       (int)info.dwMajorVersion,(int)info.dwMinorVersion,
                       info.szCSDVersion);
         }
+#ifdef VER_SUITE_BACKOFFICE
         if (info.wProductType == VER_NT_DOMAIN_CONTROLLER) {
           strlcat(uname_result, " [domain controller]", sizeof(uname_result));
         } else if (info.wProductType == VER_NT_SERVER) {
           strlcat(uname_result, " [server]", sizeof(uname_result));
         } else if (info.wProductType == VER_NT_WORKSTATION) {
           strlcat(uname_result, " [workstation]", sizeof(uname_result));
         }
         leftover_mask = info.wSuiteMask;
         for (i = 0; win_mask_table[i].mask; ++i) {
           if (info.wSuiteMask & win_mask_table[i].mask) {
             strlcat(uname_result, win_mask_table[i].str, sizeof(uname_result));
             leftover_mask &= ~win_mask_table[i].mask;
           }
         }
         if (leftover_mask) {
           size_t len = strlen(uname_result);
           tor_snprintf(uname_result+len, sizeof(uname_result)-len,
                        " {0x%x}", info.wSuiteMask);
         }
+#endif
 #else
         strlcpy(uname_result, "Unknown platform", sizeof(uname_result));
 #endif
       }
     uname_result_is_set = 1;
   }
   return uname_result;
 }
 
 /*
Index: src/or/hibernate.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/hibernate.c,v
retrieving revision 1.72
diff -u -1 -0 -r1.72 hibernate.c
--- src/or/hibernate.c	24 Jun 2006 04:57:59 -0000	1.72
+++ src/or/hibernate.c	7 Jul 2006 13:33:30 -0000
@@ -676,21 +676,21 @@
     return 0;
   return n_bytes_read_in_interval >= hard_limit
     || n_bytes_written_in_interval >= hard_limit;
 }
 
 /** Return true iff we have sent/received almost all the bytes we are willing
  * to send/receive this interval. */
 static int
 hibernate_soft_limit_reached(void)
 {
-  uint64_t soft_limit = (uint64_t) ((get_options()->AccountingMax) * .95);
+  uint64_t soft_limit = (uint64_t) ((int64_t)(get_options()->AccountingMax) * .95);
   if (!soft_limit)
     return 0;
   return n_bytes_read_in_interval >= soft_limit
     || n_bytes_written_in_interval >= soft_limit;
 }
 
 /** Called when we get a SIGINT, or when bandwidth soft limit is
  * reached. Puts us into "loose hibernation": we don't accept new
  * connections, but we continue handling old ones. */
 static void
Index: src/or/main.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/main.c,v
retrieving revision 1.649
diff -u -1 -0 -r1.649 main.c
--- src/or/main.c	4 Jul 2006 03:31:27 -0000	1.649
+++ src/or/main.c	7 Jul 2006 13:33:31 -0000
@@ -1352,26 +1352,26 @@
       "                 "U64_FORMAT" destroy",
       U64_PRINTF_ARG(stats_n_padding_cells_processed),
       U64_PRINTF_ARG(stats_n_create_cells_processed),
       U64_PRINTF_ARG(stats_n_created_cells_processed),
       U64_PRINTF_ARG(stats_n_relay_cells_processed),
       U64_PRINTF_ARG(stats_n_relay_cells_relayed),
       U64_PRINTF_ARG(stats_n_relay_cells_delivered),
       U64_PRINTF_ARG(stats_n_destroy_cells_processed));
   if (stats_n_data_cells_packaged)
     log(severity,LD_NET,"Average packaged cell fullness: %2.3f%%",
-        100*(((double)stats_n_data_bytes_packaged) /
-             (stats_n_data_cells_packaged*RELAY_PAYLOAD_SIZE)) );
+        100*(((double)(int64_t)stats_n_data_bytes_packaged) /
+             ((int64_t)stats_n_data_cells_packaged*RELAY_PAYLOAD_SIZE)) );
   if (stats_n_data_cells_received)
     log(severity,LD_NET,"Average delivered cell fullness: %2.3f%%",
-        100*(((double)stats_n_data_bytes_received) /
-             (stats_n_data_cells_received*RELAY_PAYLOAD_SIZE)) );
+        100*(((double)(int64_t)stats_n_data_bytes_received) /
+             ((int64_t)stats_n_data_cells_received*RELAY_PAYLOAD_SIZE)) );
 
   if (now - time_of_process_start >= 0)
     elapsed = now - time_of_process_start;
   else
     elapsed = 0;
 
   if (elapsed) {
     log(severity, LD_NET,
         "Average bandwidth: "U64_FORMAT"/%d = %d bytes/sec reading",
         U64_PRINTF_ARG(stats_n_bytes_read),
Index: src/or/rephist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/rephist.c,v
retrieving revision 1.90
diff -u -1 -0 -r1.90 rephist.c
--- src/or/rephist.c	8 Jun 2006 22:36:13 -0000	1.90
+++ src/or/rephist.c	7 Jul 2006 13:33:31 -0000
@@ -566,21 +566,21 @@
 /**
  * Find the largest sums in the past NUM_SECS_BW_SUM_IS_VALID (roughly)
  * seconds. Find one sum for reading and one for writing. They don't have
  * to be at the same time).
  *
  * Return the smaller of these sums, divided by NUM_SECS_ROLLING_MEASURE.
  */
 int
 rep_hist_bandwidth_assess(void)
 {
-  uint64_t w,r;
+  int64_t w,r;
   r = find_largest_max(read_array);
   w = find_largest_max(write_array);
   if (r>w)
     return (int)(w/(double)NUM_SECS_ROLLING_MEASURE);
   else
     return (int)(r/(double)NUM_SECS_ROLLING_MEASURE);
 
   return 0;
 }