[or-cvs] Resolve several DOCDOCs. Make non-mirrors only launch rout...

Nick Mathewson nickm at seul.org
Fri Sep 30 20:04:57 UTC 2005


Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv1722/src/or

Modified Files:
	control.c directory.c or.h routerlist.c routerparse.c 
Log Message:
Resolve several DOCDOCs.  Make non-mirrors only launch routerdesc downloads when they have more than 16 router descriptors to download, or when 10 minutes have passed since the last download.

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.133
retrieving revision 1.134
diff -u -d -r1.133 -r1.134
--- control.c	29 Sep 2005 20:49:41 -0000	1.133
+++ control.c	30 Sep 2005 20:04:55 -0000	1.134
@@ -182,6 +182,8 @@
   return (cmd<=_CONTROL0_CMD_MAX_RECOGNIZED) ? CONTROL0_COMMANDS[cmd] : "Unknown";
 }
 
+/** Given a control event code for a message event, return the corresponding
+ * log severity. */
 static INLINE int
 event_to_log_severity(int event)
 {
@@ -195,7 +197,7 @@
   }
 }
 
-/** DOCDOC */
+/** Given a log severity, return the corresponding control event code. */
 static INLINE int
 log_severity_to_event(int severity)
 {
@@ -232,7 +234,9 @@
   control_adjust_event_log_severity();
 }
 
-/** DOCDOC */
+/** Adjust the log severities that result in control_event_logmsg being called
+ * to match the severity of log messages that any controllers are interested
+ * in. */
 void
 control_adjust_event_log_severity(void)
 {
@@ -370,7 +374,14 @@
   return outp - *out;
 }
 
-/** DOCDOC; test **/
+/** Given a pointer to a string starting at <b>start</b> containing
+ * <b>in_len_max</b> characters, decode a string beginning with a single
+ * quote, containing any number of non-quote characters or characters escaped
+ * with a backslash, and ending with a final quote.  Place the resulting
+ * string (unquoted, unescaped) into a newly allocated string in *<b>out</b>;
+ * store its length in <b>out_len</b>.  On success, return a pointer to the
+ * character immediately following the escaped string.  On failure, return
+ * NULL. **/
 static const char *
 get_escaped_string(const char *start, size_t in_len_max,
                    char **out, size_t *out_len)
@@ -489,7 +500,9 @@
   }
 }
 
-/** DOCDOC */
+/** Send a "DONE" message down the v0 control message <b>conn</b>, with body
+ * as provided in the <b>len</b> bytes at <b>msg</b>.
+ */
 static void
 send_control_done2(connection_t *conn, const char *msg, size_t len)
 {
@@ -545,7 +558,9 @@
   tor_free(buf);
 }
 
-/* DOCDOC */
+/* Send an event to all v1 controllers that are listening for code
+ * <b>event</b>.  The event's body is created by the printf-style format in
+ * <b>format</b>, and other arguments as provided. */
 static void
 send_control1_event(uint16_t event, const char *format, ...)
 {
@@ -581,6 +596,7 @@
   }
 }
 
+/** Given a text circuit <b>id</b>, return the corresponding circuit. */
 static circuit_t *
 get_circ(const char *id)
 {
@@ -592,6 +608,7 @@
   return circuit_get_by_global_id(n_id);
 }
 
+/** Given a text stream <b>id</b>, return the corresponding AP connection. */
 static connection_t *
 get_stream(const char *id)
 {
@@ -994,7 +1011,8 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Called when we get a SAVECONF command. Try to flush the current options to
+ * disk, and report success or failure. */
 static int
 handle_control_saveconf(connection_t *conn, uint32_t len,
                         const char *body)
@@ -1012,7 +1030,9 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Called when we get a SIGNAL command. React to the provided signal, and
+ * report success or failure. (If the signal results in a shutdown, success
+ * may not be reported.) */
 static int
 handle_control_signal(connection_t *conn, uint32_t len,
                       const char *body)
@@ -1064,7 +1084,8 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Called when we get a MAPADDRESS command; try to bind all listed addresses,
+ * and report success or failrue. */
 static int
 handle_control_mapaddress(connection_t *conn, uint32_t len, const char *body)
 {
@@ -1152,7 +1173,8 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Return a newly allocated string listing all valid GETINFO fields as
+ * required by GETINFO info/names. */
 static char *
 list_getinfo_options(void)
 {
@@ -1340,7 +1362,8 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Called when we receive a GETINFO command.  Try to fetch all requested
+ * information, and reply with information or error message. */
 static int
 handle_control_getinfo(connection_t *conn, uint32_t len, const char *body)
 {
@@ -1431,7 +1454,8 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Callled when we get an EXTENDCIRCUIT message.  Try to extend the listed
+ * circuit, and report succcess or failure. */
 static int
 handle_control_extendcircuit(connection_t *conn, uint32_t len,
                              const char *body)
@@ -1560,7 +1584,8 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Callled when we get an ATTACHSTREAM message.  Try to attach the requested
+ * stream, and report succcess or failure. */
 static int
 handle_control_attachstream(connection_t *conn, uint32_t len,
                             const char *body)
@@ -1652,7 +1677,9 @@
   return 0;
 }
 
-/** DOCDOC */
+
+/** Callled when we get a POSTDESCRIPTORT message.  Try to learn the provided
+ * descriptor, and report succcess or failure. */
 static int
 handle_control_postdescriptor(connection_t *conn, uint32_t len,
                               const char *body)
@@ -1694,7 +1721,8 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Called when we receive a REDIRECTSTERAM command.  Try to change the target
+ * adderess of the named AP steream, and report success or failure. */
 static int
 handle_control_redirectstream(connection_t *conn, uint32_t len,
                               const char *body)
@@ -1745,7 +1773,8 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Called when we get a CLOSESTREAM command; try to close the named stream
+ * and report success or failure. */
 static int
 handle_control_closestream(connection_t *conn, uint32_t len,
                            const char *body)
@@ -1801,7 +1830,8 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Called when we get a CLOSECIRCUIT command; try to close the named circuit
+ * and report success or failure. */
 static int
 handle_control_closecircuit(connection_t *conn, uint32_t len,
                             const char *body)
@@ -1857,7 +1887,11 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Called when we get a v0 FRAGMENTHEADER or FRAGMENT command; try to append
+ * the data to conn->incoming_cmd, setting conn->incoming_(type|len|cur_len)
+ * as appropriate.  If the command is malformed, drop it and all pending
+ * fragments and report failure.
+ */
 static int
 handle_control_fragments(connection_t *conn, uint16_t command_type,
                          uint32_t body_len, char *body)
@@ -1921,7 +1955,9 @@
   return 0;
 }
 
-/* DOCDOC */
+/** Called when data has arrived on a v1 control connection: Try to fetch
+ * commands from conn->inbuf, and execute them.
+ */
 static int
 connection_control_process_inbuf_v1(connection_t *conn)
 {
@@ -2070,7 +2106,9 @@
   goto again;
 }
 
-/* DOCDOC */
+/** Called when data has arrived on a v0 control connection: Try to fetch
+ * commands from conn->inbuf, and execute them.
+ */
 static int
 connection_control_process_inbuf_v0(connection_t *conn)
 {
@@ -2274,7 +2312,10 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Given an AP connection <b>conn</b> and a <b>len</b>-character buffer
+ * <b>buf</b>, determine the address:port combination requested on
+ * <b>conn</b>, and write it to <b>buf</b>.  Return 0 on success, -1 on
+ * failure. */
 static int
 write_stream_target_to_buf(connection_t *conn, char *buf, size_t len)
 {
@@ -2403,14 +2444,17 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Called when we are sending a log message to the controllers: suspend
+ * sending further log messages to the controllers until we're done.  Used by
+ * CONN_LOG_PROTECT. */
 void
 disable_control_logging(void)
 {
   ++disable_log_messages;
 }
 
-/** DOCDOC */
+/** We're done sending a log message to the controllers: re-enable controller
+ * logging.  Used by CONN_LOG_PROTECT. */
 void
 enable_control_logging(void)
 {
@@ -2436,12 +2480,12 @@
 
   if (oldlog || event) {
     size_t len = strlen(msg);
-    disable_log_messages = 1;
+    ++disable_log_messages;
     if (event)
       send_control0_event(event, (uint32_t)(len+1), msg);
     if (oldlog)
       send_control0_event(EVENT_LOG_OBSOLETE, (uint32_t)(len+1), msg);
-    disable_log_messages = 0;
+    --disable_log_messages;
   }
 
   event = log_severity_to_event(severity);
@@ -2463,9 +2507,9 @@
       case LOG_ERR: s = "ERR"; break;
       default: s = "UnknownLogSeverity"; break;
     }
-    disable_log_messages = 1;
+    ++disable_log_messages;
     send_control1_event(event, "650 %s %s\r\n", s, b?b:msg);
-    disable_log_messages = 0;
+    --disable_log_messages;
     tor_free(b);
   }
 }
@@ -2506,7 +2550,8 @@
   return 0;
 }
 
-/** DOCDOC */
+/** Called whenever an address mapping on <b>from<b> from changes to <b>to</b>.
+ * <b>expires</b> values less than 3 are special; see connection_edge.c. */
 int
 control_event_address_mapped(const char *from, const char *to, time_t expires)
 {

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.297
retrieving revision 1.298
diff -u -d -r1.297 -r1.298
--- directory.c	30 Sep 2005 02:08:57 -0000	1.297
+++ directory.c	30 Sep 2005 20:04:55 -0000	1.298
@@ -1008,9 +1008,17 @@
       tor_free(body); tor_free(headers); tor_free(reason);
       return -1;
     }
-    /* as we learn from them, we remove them from 'which' */
-    router_load_routers_from_string(body, 0, which);
-    directory_info_has_arrived(time(NULL), 0);
+    /* Learn the routers, assuming we requested by fingerprint or "all".
+     * Right now, we only use "authority" to fetch ourself, so we don't want
+     * to risk replacing ourself with a router running at the addr:port we
+     * think we have.
+     */
+    if (which || (conn->requested_resource &&
+                  !strcmpstart(conn->requested_resource, "all"))) {
+      /* as we learn from them, we remove them from 'which' */
+      router_load_routers_from_string(body, 0, which);
+      directory_info_has_arrived(time(NULL), 0);
+    }
     if (which) { /* mark remaining ones as failed */
       log_fn(LOG_NOTICE, "Received %d/%d routers.",
              n_asked_for-smartlist_len(which), n_asked_for);
@@ -1627,7 +1635,11 @@
   /* update_router_descriptor_downloads(time(NULL)); */
 }
 
-/* DOCDOC */
+/* Given a directory <b>resource</b> request generated by us, containing zero
+ * or more strings separated by plus signs, followed optionally by ".z", store
+ * the strings, in order, into <b>fp_out</b>.  If <b>compressed_out</b> is
+ * non-NULL, set it to 1 if the resource ends in ".z", else set it to 0.
+ */
 int
 dir_split_resource_into_fingerprints(const char *resource,
                                      smartlist_t *fp_out, int *compressed_out)

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.698
retrieving revision 1.699
diff -u -d -r1.698 -r1.699
--- or.h	30 Sep 2005 04:43:42 -0000	1.698
+++ or.h	30 Sep 2005 20:04:55 -0000	1.699
@@ -1669,6 +1669,12 @@
 void disable_control_logging(void);
 void enable_control_logging(void);
 
+/** Execute the statement <b>stmt</b>, which may log events concerning the
+ * connection <b>conn</b>.  To prevent infinite loops, disable log messages
+ * being stent to controllers if <b>conn</b> is a control connection.
+ *
+ * Stmt must not contain any return or goto statements.
+ */
 #define CONN_LOG_PROTECT(conn, stmt)                                    \
   do {                                                                  \
     int _log_conn_is_control = (conn && conn->type == CONN_TYPE_CONTROL); \
@@ -1679,6 +1685,11 @@
       enable_control_logging();                                         \
   } while (0)
 
+/** Log information about the connection <b>conn</b>, protecting it as with
+ * CONN_LOG_PROTECT. Example:
+ *
+ * LOG_FN_CONN(conn, (LOG_DEBUG, "Socket %d wants to write", conn->s));
+ **/
 #define LOG_FN_CONN(conn, args)                 \
   CONN_LOG_PROTECT(conn, log_fn args)
 

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.317
retrieving revision 1.318
diff -u -d -r1.317 -r1.318
--- routerlist.c	29 Sep 2005 23:03:34 -0000	1.317
+++ routerlist.c	30 Sep 2005 20:04:55 -0000	1.318
@@ -49,9 +49,11 @@
 static smartlist_t *networkstatus_list = NULL;
 /** Global list of routerstatuses_t for each router, known or unknown. */
 static smartlist_t *routerstatus_list = NULL;
-/*DOCDOC */
+/** True iff any member of networkstatus_list has changed since the last time
+ * we called routerstatus_list_update_from_networkstatus(). */
 static int networkstatus_list_has_changed = 0;
-/*DOCDOC */
+/** True iff any element of routerstatus_list has changed since the last
+ * time we called routers_update_all_from_networkstatus().*/
 static int routerstatus_list_has_changed = 0;
 
 /** Repopulate our list of network_status_t objects from the list cached on
@@ -1548,7 +1550,8 @@
                            _compare_digest_to_routerstatus_entry);
 }
 
-/*DOCDOC*/
+/** Return the consensus view of the status of the router whose digest is
+ * <b>digest</b>, or NULL if we don't know about any such router. */
 local_routerstatus_t *
 router_get_combined_status_by_digest(const char *digest)
 {
@@ -2078,7 +2081,11 @@
  * our view of who's running. */
 #define MIN_TO_INFLUENCE_RUNNING 3
 
-/** DOCDOC */
+/** Change the is_recent field of each member of networkstatus_list so that
+ * all members more recent than DEFAULT_RUNNING_INTERVAL are recent, and
+ * at least the MIN_TO_INFLUENCE_RUNNING most recent members are resent, and no
+ * others are recent.  Set networkstatus_list_has_changed if anything happeed.
+ */
 void
 networkstatus_list_update_recent(time_t now)
 {
@@ -2119,7 +2126,11 @@
     networkstatus_list_has_changed = 1;
 }
 
-/* DOCDOC */
+/** Update our view of router status (as stored in routerstatus_list) from
+ * the current set of network status documents (as stored in networkstatus_list).
+ * Do nothing unless the network status list has changed since the last time
+ * this function was called.
+ */
 static void
 routerstatus_list_update_from_networkstatus(time_t now)
 {
@@ -2493,26 +2504,33 @@
 #define MAX_DL_PER_REQUEST 128
 #define MIN_DL_PER_REQUEST 4
 #define MIN_REQUESTS 3
+#define MAX_DL_TO_DELAY 16
+#define MAX_INTERVAL_WITHOUT_REQUEST 10*60
   smartlist_t *downloadable = NULL;
   int get_all = 0;
-  int always_split = !server_mode(get_options()) || !get_options()->DirPort;
+  int mirror = server_mode(get_options()) && get_options()->DirPort;
+  static time_t last_download_attempted = 0;
   if (!networkstatus_list || smartlist_len(networkstatus_list)<2)
     get_all = 1;
 
   if (get_all) {
     log_fn(LOG_NOTICE, "Launching request for all routers");
+    last_download_attempted = now;
     directory_get_from_dirserver(DIR_PURPOSE_FETCH_SERVERDESC,"all.z",1);
     return;
   }
 
   downloadable = router_list_downloadable();
-  if (smartlist_len(downloadable)) {
+  if (smartlist_len(downloadable) >= MAX_DL_TO_DELAY ||
+      (smartlist_len(downloadable) &&
+       (mirror ||
+        last_download_attempted + MAX_INTERVAL_WITHOUT_REQUEST < now))) {
     int i, j, n, n_per_request=MAX_DL_PER_REQUEST;
     size_t r_len = MAX_DL_PER_REQUEST*(HEX_DIGEST_LEN+1)+16;
     char *resource = tor_malloc(r_len);
 
     n = smartlist_len(downloadable);
-    if (always_split) {
+    if (! mirror) {
       n_per_request = (n+MIN_REQUESTS-1) / MIN_REQUESTS;
       if (n_per_request > MAX_DL_PER_REQUEST)
         n_per_request = MAX_DL_PER_REQUEST;
@@ -2532,6 +2550,7 @@
         *cp++ = '+';
       }
       memcpy(cp-1, ".z", 3);
+      last_download_attempted = now;
       directory_get_from_dirserver(DIR_PURPOSE_FETCH_SERVERDESC,resource,1);
     }
     tor_free(resource);
@@ -2556,7 +2575,9 @@
   return smartlist_len(routerlist->routers) > (avg/4);
 }
 
-/** DOCDOC */
+/** Reset the descriptor download failure count on all routers, so that we
+ * can retry any long-failed routers immediately.
+ */
 void
 router_reset_descriptor_download_failures(void)
 {

Index: routerparse.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerparse.c,v
retrieving revision 1.149
retrieving revision 1.150
diff -u -d -r1.149 -r1.150
--- routerparse.c	29 Sep 2005 02:54:09 -0000	1.149
+++ routerparse.c	30 Sep 2005 20:04:55 -0000	1.150
@@ -245,20 +245,19 @@
   return -1;
 }
 
-/** Return 1 if <b>myversion</b> is not in <b>versionlist</b>, and if at least
- * one version of Tor on <b>versionlist</b> is newer than <b>myversion</b>.
-
- * Return 1 if no version from the same series as <b>myversion</b> is
- * in <b>versionlist</b> (and <b>myversion</b> is not the newest
- * version), or if a newer version from the same series is in
- * <b>versionlist</b>.
+/** Return VS_RECOMMENDED if <b>myversion</b> is contained in
+ * <b>versionlist</b>.  Else, return VS_OLD if every member of
+ * <b>versionlist</b> is newer than <b>myversion</b>.  Else, return
+ * VS_NEW_IN_SERIES if there is at least one member of <b>versionlist</b> in
+ * the same series (major.minor.micro) as <b>myversion</b>, but no such member
+ * is newer than <b>myversion.</b>.  Else, return VS_NEW if every memeber of
+ * <b>versionlist</b> is older than <b>myversion</b>.  Else, return
+ * VS_UNRECOMMENDED.
  *
- * Otherwise return 0.
  * (versionlist is a comma-separated list of version strings,
  * optionally prefixed with "Tor".  Versions that can't be parsed are
  * ignored.)
- *
- * DOCDOC interface changed */
+ */
 version_status_t
 tor_version_is_obsolete(const char *myversion, const char *versionlist)
 {
@@ -322,7 +321,17 @@
   return ret;
 }
 
-/** DOCDOC */
+/** Return the combined status of the current version, given that we know of
+ * one set of networkstatuses that give us status <b>a</b>, and another that
+ * gives us status <b>b</b>.
+ *
+ * For example, if one authority thinks that we're NEW, and another thinks
+ * we're OLD, we're simply UNRECOMMENDED.
+ *
+ * This function does not handle calculating whether we're RECOMMENDED; that
+ * follows a simple majority rule.  This function simply calculates *why*
+ * we're not recommended (if we're not).
+ */
 version_status_t
 version_status_join(version_status_t a, version_status_t b)
 {



More information about the tor-commits mailing list