[or-cvs] r13458: Merge connection_or_act_on_netinfo into command.c; remove so (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Sun Feb 10 18:40:24 UTC 2008


Author: nickm
Date: 2008-02-10 13:40:23 -0500 (Sun, 10 Feb 2008)
New Revision: 13458

Modified:
   tor/trunk/
   tor/trunk/src/or/command.c
   tor/trunk/src/or/connection_or.c
   tor/trunk/src/or/or.h
Log:
 r14101 at tombo:  nickm | 2008-02-10 13:24:27 -0500
 Merge connection_or_act_on_netinfo into command.c; remove some fields from or_handshake_state().



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r14101] on 49666b30-7950-49c5-bedf-9dc8f3168102

Modified: tor/trunk/src/or/command.c
===================================================================
--- tor/trunk/src/or/command.c	2008-02-10 18:17:56 UTC (rev 13457)
+++ tor/trunk/src/or/command.c	2008-02-10 18:40:23 UTC (rev 13458)
@@ -503,6 +503,9 @@
   uint8_t n_other_addrs;
   time_t now = time(NULL);
 
+  long apparent_skew = 0;
+  uint32_t my_apparent_addr = 0;
+
   if (conn->link_proto < 2) {
     log_fn(LOG_PROTOCOL_WARN, LD_OR,
            "Received a NETINFO cell on %s connection; dropping.",
@@ -516,15 +519,10 @@
   }
   tor_assert(conn->handshake_state &&
              conn->handshake_state->received_versions);
-  if (conn->handshake_state->received_netinfo) {
-    log_fn(LOG_PROTOCOL_WARN, LD_OR,
-           "Received a duplicate NETINFO cell; dropping.");
-    return;
-  }
   /* Decode the cell. */
   timestamp = ntohl(get_uint32(cell->payload));
   if (abs(now - conn->handshake_state->sent_versions_at) < 180) {
-    conn->handshake_state->apparent_skew = now - timestamp;
+    apparent_skew = now - timestamp;
   }
 
   my_addr_type = (uint8_t) cell->payload[4];
@@ -538,7 +536,7 @@
     connection_mark_for_close(TO_CONN(conn));
     return;
   } else if (my_addr_type == RESOLVED_TYPE_IPV4 && my_addr_len == 4) {
-    conn->handshake_state->my_apparent_addr = ntohl(get_uint32(my_addr_ptr));
+    my_apparent_addr = ntohl(get_uint32(my_addr_ptr));
   }
 
   n_other_addrs = (uint8_t) *cp++;
@@ -556,7 +554,7 @@
     if (other_addr_type == RESOLVED_TYPE_IPV4 && other_addr_len == 4) {
       uint32_t addr = ntohl(get_uint32(cp));
       if (addr == conn->real_addr) {
-        conn->handshake_state->apparently_canonical = 1;
+        conn->is_canonical = 1;
         break;
       }
     }
@@ -564,17 +562,33 @@
     --n_other_addrs;
   }
 
-  conn->handshake_state->received_netinfo = 1;
+  /* Act on apparent skew. */
+  /** Warn when we get a netinfo skew with at least this value. */
+#define NETINFO_NOTICE_SKEW 3600
+  if (abs(apparent_skew) > NETINFO_NOTICE_SKEW &&
+      router_get_by_digest(conn->identity_digest)) {
+    char dbuf[64];
+    /*XXXX020 not always warn!*/
+    format_time_interval(dbuf, sizeof(dbuf), apparent_skew);
+    log_fn(LOG_WARN, LD_HTTP, "Received NETINFO cell with skewed time from "
+           "server at %s:%d.  It seems that our clock is %s by %s, or "
+           "that theirs is %s. Tor requires an accurate clock to work: "
+           "please check your time and date settings.",
+           conn->_base.address, (int)conn->_base.port,
+           apparent_skew>0 ? "ahead" : "behind", dbuf,
+           apparent_skew>0 ? "behind" : "ahead");
+    control_event_general_status(LOG_WARN,
+                        "CLOCK_SKEW SKEW=%ld SOURCE=OR:%s:%d",
+                        apparent_skew, conn->_base.address, conn->_base.port);
+  }
 
-  if (conn->handshake_state->apparently_canonical) {
-    conn->is_canonical = 1;
-  }
-  if (connection_or_act_on_netinfo(conn)<0 ||
-      connection_or_set_state_open(conn)<0)
+  /*XXX020 maybe act on my_apparent_addr */
+
+  if (connection_or_set_state_open(conn)<0)
     connection_mark_for_close(TO_CONN(conn));
-
-  log_info(LD_OR, "Got good NETINFO cell from %s",
-           safe_str(conn->_base.address));
+  else
+    log_info(LD_OR, "Got good NETINFO cell from %s",
+             safe_str(conn->_base.address));
   assert_connection_ok(TO_CONN(conn),time(NULL));
 }
 

Modified: tor/trunk/src/or/connection_or.c
===================================================================
--- tor/trunk/src/or/connection_or.c	2008-02-10 18:17:56 UTC (rev 13457)
+++ tor/trunk/src/or/connection_or.c	2008-02-10 18:40:23 UTC (rev 13458)
@@ -1085,42 +1085,3 @@
   return 0;
 }
 
-/** DOCDOC Called when we're done authenticating; act on stuff we
- * learned in netinfo. */
-int
-connection_or_act_on_netinfo(or_connection_t *conn)
-{
-  long delta;
-  /*XXXX020 merge this into handle_netinfo.*/
-  if (!conn->handshake_state)
-    return -1;
-
-  tor_assert(conn->handshake_state->received_versions != 0);
-
-  delta = conn->handshake_state->apparent_skew;
-/** Warn when we get a netinfo skew with at least this value. */
-#define NETINFO_NOTICE_SKEW 3600
-  if (abs(delta) > NETINFO_NOTICE_SKEW &&
-      router_get_by_digest(conn->identity_digest)) {
-    char dbuf[64];
-    /*XXXX020 not always warn!*/
-    format_time_interval(dbuf, sizeof(dbuf), delta);
-    log_fn(LOG_WARN, LD_HTTP, "Received NETINFO cell with skewed time from "
-           "server at %s:%d.  It seems that our clock is %s by %s, or "
-           "that theirs is %s. Tor requires an accurate clock to work: "
-           "please check your time and date settings.",
-           conn->_base.address, (int)conn->_base.port,
-           delta>0 ? "ahead" : "behind", dbuf,
-           delta>0 ? "behind" : "ahead");
-    control_event_general_status(LOG_WARN,
-                                 "CLOCK_SKEW SKEW=%ld SOURCE=OR:%s:%d",
-                                 delta, conn->_base.address, conn->_base.port);
-  }
-
-  if (conn->handshake_state->apparently_canonical)
-    conn->is_canonical = 1;
-
-  /* XXX020 possibly, learn my address from my_apparent_addr */
-  return 0;
-}
-

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2008-02-10 18:17:56 UTC (rev 13457)
+++ tor/trunk/src/or/or.h	2008-02-10 18:40:23 UTC (rev 13458)
@@ -893,11 +893,6 @@
   unsigned int started_here : 1;
   unsigned int received_versions : 1;
 
-  /* from netinfo: XXXX020 totally useless. */
-  unsigned int received_netinfo : 1;
-  long apparent_skew;
-  uint32_t my_apparent_addr;
-  unsigned int apparently_canonical;
 } or_handshake_state_t;
 
 /** Subtype of connection_t for an "OR connection" -- that is, one that speaks
@@ -2870,7 +2865,6 @@
 void var_cell_pack_header(const var_cell_t *cell, char *hdr_out);
 var_cell_t *var_cell_new(uint16_t payload_len);
 void var_cell_free(var_cell_t *cell);
-int connection_or_act_on_netinfo(or_connection_t *conn);
 
 /********************************* control.c ***************************/
 



More information about the tor-commits mailing list