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

[or-cvs] Normalize space: add one between every control keyword and ...



Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv11426/src/or

Modified Files:
	buffers.c circuitbuild.c circuitlist.c circuituse.c command.c 
	config.c connection.c connection_edge.c connection_or.c 
	control.c cpuworker.c directory.c dirserv.c dns.c hibernate.c 
	main.c onion.c relay.c rendclient.c rendcommon.c rendservice.c 
	rephist.c router.c routerlist.c routerparse.c test.c 
Log Message:
Normalize space: add one between every control keyword and control clause.

Index: buffers.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/buffers.c,v
retrieving revision 1.117
retrieving revision 1.118
diff -u -d -r1.117 -r1.118
--- buffers.c	28 Nov 2004 05:48:02 -0000	1.117
+++ buffers.c	28 Nov 2004 09:05:46 -0000	1.118
@@ -175,17 +175,17 @@
   if (buf_ensure_capacity(buf,buf->datalen+at_most))
     return -1;
 
-  if(at_most + buf->datalen > buf->len)
+  if (at_most + buf->datalen > buf->len)
     at_most = buf->len - buf->datalen; /* take the min of the two */
 
-  if(at_most == 0)
+  if (at_most == 0)
     return 0; /* we shouldn't read anything */
 
 //  log_fn(LOG_DEBUG,"reading at most %d bytes.",at_most);
   read_result = recv(s, buf->mem+buf->datalen, at_most, 0);
   if (read_result < 0) {
     int e = tor_socket_errno(s);
-    if(!ERRNO_IS_EAGAIN(e)) { /* it's a real error */
+    if (!ERRNO_IS_EAGAIN(e)) { /* it's a real error */
       return -1;
     }
     return 0; /* would block. */
@@ -250,13 +250,13 @@
   tor_assert(s>=0);
   tor_assert(*buf_flushlen <= buf->datalen);
 
-  if(*buf_flushlen == 0) /* nothing to flush */
+  if (*buf_flushlen == 0) /* nothing to flush */
     return 0;
 
   write_result = send(s, buf->mem, *buf_flushlen, 0);
   if (write_result < 0) {
     int e = tor_socket_errno(s);
-    if(!ERRNO_IS_EAGAIN(e)) { /* it's a real error */
+    if (!ERRNO_IS_EAGAIN(e)) { /* it's a real error */
       return -1;
     }
     log_fn(LOG_DEBUG,"write() would block, returning.");
@@ -378,12 +378,12 @@
   bodylen = buf->datalen - headerlen;
   log_fn(LOG_DEBUG,"headerlen %d, bodylen %d.", (int)headerlen, (int)bodylen);
 
-  if(max_headerlen <= headerlen) {
+  if (max_headerlen <= headerlen) {
     log_fn(LOG_WARN,"headerlen %d larger than %d. Failing.", (int)headerlen,
            (int)max_headerlen-1);
     return -1;
   }
-  if(max_bodylen <= bodylen) {
+  if (max_bodylen <= bodylen) {
     log_fn(LOG_WARN,"bodylen %d larger than %d. Failing.", (int)bodylen, (int)max_bodylen-1);
     return -1;
   }
@@ -400,22 +400,22 @@
     contentlen = i;
     /* if content-length is malformed, then our body length is 0. fine. */
     log_fn(LOG_DEBUG,"Got a contentlen of %d.",(int)contentlen);
-    if(bodylen < contentlen) {
+    if (bodylen < contentlen) {
       log_fn(LOG_DEBUG,"body not all here yet.");
       return 0; /* not all there yet */
     }
-    if(bodylen > contentlen) {
+    if (bodylen > contentlen) {
       bodylen = contentlen;
       log_fn(LOG_DEBUG,"bodylen reduced to %d.",(int)bodylen);
     }
   }
   /* all happy. copy into the appropriate places, and return 1 */
-  if(headers_out) {
+  if (headers_out) {
     *headers_out = tor_malloc(headerlen+1);
     memcpy(*headers_out,buf->mem,headerlen);
     (*headers_out)[headerlen] = 0; /* null terminate it */
   }
-  if(body_out) {
+  if (body_out) {
     tor_assert(body_used);
     *body_used = bodylen;
     *body_out = tor_malloc(bodylen+1);
@@ -457,18 +457,18 @@
    * then log a warning to let him know that it might be unwise. */
   static int have_warned_about_unsafe_socks = 0;
 
-  if(buf->datalen < 2) /* version and another byte */
+  if (buf->datalen < 2) /* version and another byte */
     return 0;
-  switch(*(buf->mem)) { /* which version of socks? */
+  switch (*(buf->mem)) { /* which version of socks? */
 
     case 5: /* socks5 */
 
-      if(req->socks_version != 5) { /* we need to negotiate a method */
+      if (req->socks_version != 5) { /* we need to negotiate a method */
         unsigned char nummethods = (unsigned char)*(buf->mem+1);
         tor_assert(!req->socks_version);
-        if(buf->datalen < 2u+nummethods)
+        if (buf->datalen < 2u+nummethods)
           return 0;
-        if(!nummethods || !memchr(buf->mem+2, 0, nummethods)) {
+        if (!nummethods || !memchr(buf->mem+2, 0, nummethods)) {
           log_fn(LOG_WARN,"socks5: offered methods don't include 'no auth'. Rejecting.");
           req->replylen = 2; /* 2 bytes of response */
           req->reply[0] = 5; /* socks5 reply */
@@ -486,26 +486,26 @@
       }
       /* we know the method; read in the request */
       log_fn(LOG_DEBUG,"socks5: checking request");
-      if(buf->datalen < 8) /* basic info plus >=2 for addr plus 2 for port */
+      if (buf->datalen < 8) /* basic info plus >=2 for addr plus 2 for port */
         return 0; /* not yet */
       req->command = (unsigned char) *(buf->mem+1);
-      if(req->command != SOCKS_COMMAND_CONNECT &&
+      if (req->command != SOCKS_COMMAND_CONNECT &&
          req->command != SOCKS_COMMAND_RESOLVE) {
         /* not a connect or resolve? we don't support it. */
         log_fn(LOG_WARN,"socks5: command %d not recognized. Rejecting.",
                req->command);
         return -1;
       }
-      switch(*(buf->mem+3)) { /* address type */
+      switch (*(buf->mem+3)) { /* address type */
         case 1: /* IPv4 address */
           log_fn(LOG_DEBUG,"socks5: ipv4 address type");
-          if(buf->datalen < 10) /* ip/port there? */
+          if (buf->datalen < 10) /* ip/port there? */
             return 0; /* not yet */
 
           destip = ntohl(*(uint32_t*)(buf->mem+4));
           in.s_addr = htonl(destip);
           tmpbuf = inet_ntoa(in);
-          if(strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
+          if (strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
             log_fn(LOG_WARN,"socks5 IP takes %d bytes, which doesn't fit in %d. Rejecting.",
                    (int)strlen(tmpbuf)+1,(int)MAX_SOCKS_ADDR_LEN);
             return -1;
@@ -513,7 +513,7 @@
           strlcpy(req->address,tmpbuf,sizeof(req->address));
           req->port = ntohs(*(uint16_t*)(buf->mem+8));
           buf_remove_from_front(buf, 10);
-          if(!have_warned_about_unsafe_socks) {
+          if (!have_warned_about_unsafe_socks) {
             log_fn(LOG_WARN,"Your application (using socks5 on port %d) is giving Tor only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4A (e.g. via privoxy or socat) instead.", req->port);
 //            have_warned_about_unsafe_socks = 1; // (for now, warn every time)
           }
@@ -521,9 +521,9 @@
         case 3: /* fqdn */
           log_fn(LOG_DEBUG,"socks5: fqdn address type");
           len = (unsigned char)*(buf->mem+4);
-          if(buf->datalen < 7u+len) /* addr/port there? */
+          if (buf->datalen < 7u+len) /* addr/port there? */
             return 0; /* not yet */
-          if(len+1 > MAX_SOCKS_ADDR_LEN) {
+          if (len+1 > MAX_SOCKS_ADDR_LEN) {
             log_fn(LOG_WARN,"socks5 hostname is %d bytes, which doesn't fit in %d. Rejecting.",
                    len+1,MAX_SOCKS_ADDR_LEN);
             return -1;
@@ -543,11 +543,11 @@
       /* http://archive.socks.permeo.com/protocol/socks4a.protocol */
 
       req->socks_version = 4;
-      if(buf->datalen < SOCKS4_NETWORK_LEN) /* basic info available? */
+      if (buf->datalen < SOCKS4_NETWORK_LEN) /* basic info available? */
         return 0; /* not yet */
 
       req->command = (unsigned char) *(buf->mem+1);
-      if(req->command != SOCKS_COMMAND_CONNECT &&
+      if (req->command != SOCKS_COMMAND_CONNECT &&
          req->command != SOCKS_COMMAND_RESOLVE) {
         /* not a connect or resolve? we don't support it. */
         log_fn(LOG_WARN,"socks4: command %d not recognized. Rejecting.",
@@ -557,15 +557,15 @@
 
       req->port = ntohs(*(uint16_t*)(buf->mem+2));
       destip = ntohl(*(uint32_t*)(buf->mem+4));
-      if((!req->port && req->command!=SOCKS_COMMAND_RESOLVE) || !destip) {
+      if ((!req->port && req->command!=SOCKS_COMMAND_RESOLVE) || !destip) {
         log_fn(LOG_WARN,"socks4: Port or DestIP is zero. Rejecting.");
         return -1;
       }
-      if(destip >> 8) {
+      if (destip >> 8) {
         log_fn(LOG_DEBUG,"socks4: destip not in form 0.0.0.x.");
         in.s_addr = htonl(destip);
         tmpbuf = inet_ntoa(in);
-        if(strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
+        if (strlen(tmpbuf)+1 > MAX_SOCKS_ADDR_LEN) {
           log_fn(LOG_WARN,"socks4 addr (%d bytes) too long. Rejecting.",
                  (int)strlen(tmpbuf));
           return -1;
@@ -576,25 +576,25 @@
 
       next = memchr(buf->mem+SOCKS4_NETWORK_LEN, 0,
                     buf->datalen-SOCKS4_NETWORK_LEN);
-      if(!next) {
+      if (!next) {
         log_fn(LOG_DEBUG,"socks4: Username not here yet.");
         return 0;
       }
       tor_assert(next < buf->mem+buf->datalen);
 
       startaddr = NULL;
-      if(socks4_prot != socks4a && !have_warned_about_unsafe_socks) {
+      if (socks4_prot != socks4a && !have_warned_about_unsafe_socks) {
         log_fn(LOG_WARN,"Your application (using socks4 on port %d) is giving Tor only an IP address. Applications that do DNS resolves themselves may leak information. Consider using Socks4A (e.g. via privoxy or socat) instead.", req->port);
 //      have_warned_about_unsafe_socks = 1; // (for now, warn every time)
       }
-      if(socks4_prot == socks4a && next+1 < buf->mem+buf->datalen) {
+      if (socks4_prot == socks4a && next+1 < buf->mem+buf->datalen) {
         startaddr = next+1;
         next = memchr(startaddr, 0, buf->mem+buf->datalen-startaddr);
-        if(!next) {
+        if (!next) {
           log_fn(LOG_DEBUG,"socks4: Destaddr not here yet.");
           return 0;
         }
-        if(MAX_SOCKS_ADDR_LEN <= next-startaddr) {
+        if (MAX_SOCKS_ADDR_LEN <= next-startaddr) {
           log_fn(LOG_WARN,"socks4: Destaddr too long. Rejecting.");
           return -1;
         }

Index: circuitbuild.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/circuitbuild.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -d -r1.62 -r1.63
--- circuitbuild.c	26 Nov 2004 04:00:52 -0000	1.62
+++ circuitbuild.c	28 Nov 2004 09:05:46 -0000	1.63
@@ -49,7 +49,7 @@
       test_circ_id = 1;
       conn->next_circ_id = 2;
     }
-    if(++attempts > 1<<15) {
+    if (++attempts > 1<<15) {
       /* Make sure we don't loop forever if all circ_id's are used. This
        * matters because it's an external DoS vulnerability.
        */
@@ -57,7 +57,7 @@
       return 0;
     }
     test_circ_id |= high_bit;
-  } while(circuit_get_by_circ_id_conn(test_circ_id, conn));
+  } while (circuit_get_by_circ_id_conn(test_circ_id, conn));
   return test_circ_id;
 }
 
@@ -144,18 +144,18 @@
   do {
     s = buf + strlen(buf);
     router = router_get_by_digest(hop->identity_digest);
-    if(router) {
+    if (router) {
       tor_snprintf(s, sizeof(buf) - (s - buf), "%s(%s) ",
                router->nickname, states[hop->state]);
     } else {
-      if(circ->purpose == CIRCUIT_PURPOSE_C_REND_JOINED) {
+      if (circ->purpose == CIRCUIT_PURPOSE_C_REND_JOINED) {
         tor_snprintf(s, sizeof(buf) - (s - buf), "(rendjoin hop)");
       } else {
         tor_snprintf(s, sizeof(buf) - (s - buf), "UNKNOWN ");
       }
     }
     hop=hop->next;
-  } while(hop!=circ->cpath);
+  } while (hop!=circ->cpath);
   log_fn(severity,"%s",buf);
 #endif
 }
@@ -170,7 +170,7 @@
   char *prev_digest = NULL;
   routerinfo_t *router;
   hop = circ->cpath;
-  if(!hop) {
+  if (!hop) {
     /* XXX
      * if !hop, then we're not the beginning of this circuit.
      * for now, just forget about it. later, we should remember when
@@ -212,8 +212,8 @@
   log(severity,"Conn %d has %s circuit: circID %d (other side %d), state %d (%s), born %d",
       poll_index, type, this_circid, other_circid, circ->state,
       circuit_state_to_string[circ->state], (int)circ->timestamp_created);
-  if(CIRCUIT_IS_ORIGIN(circ)) { /* circ starts at this node */
-    if(circ->state == CIRCUIT_STATE_BUILDING)
+  if (CIRCUIT_IS_ORIGIN(circ)) { /* circ starts at this node */
+    if (circ->state == CIRCUIT_STATE_BUILDING)
       log(severity,"Building: desired len %d, planned exit node %s.",
           circ->build_state->desired_path_len, circ->build_state->chosen_exit_name);
     hop = circ->cpath;
@@ -234,21 +234,21 @@
   circuit_t *circ;
   connection_t *tmpconn;
 
-  for(circ=global_circuitlist;circ;circ = circ->next) {
-    if(circ->p_conn == conn)
+  for (circ=global_circuitlist;circ;circ = circ->next) {
+    if (circ->p_conn == conn)
       circuit_dump_details(severity, circ, conn->poll_index, "App-ward",
                            circ->p_circ_id, circ->n_circ_id);
-    for(tmpconn=circ->p_streams; tmpconn; tmpconn=tmpconn->next_stream) {
-      if(tmpconn == conn) {
+    for (tmpconn=circ->p_streams; tmpconn; tmpconn=tmpconn->next_stream) {
+      if (tmpconn == conn) {
         circuit_dump_details(severity, circ, conn->poll_index, "App-ward",
                              circ->p_circ_id, circ->n_circ_id);
       }
     }
-    if(circ->n_conn == conn)
+    if (circ->n_conn == conn)
       circuit_dump_details(severity, circ, conn->poll_index, "Exit-ward",
                            circ->n_circ_id, circ->p_circ_id);
-    for(tmpconn=circ->n_streams; tmpconn; tmpconn=tmpconn->next_stream) {
-      if(tmpconn == conn) {
+    for (tmpconn=circ->n_streams; tmpconn; tmpconn=tmpconn->next_stream) {
+      if (tmpconn == conn) {
         circuit_dump_details(severity, circ, conn->poll_index, "Exit-ward",
                              circ->n_circ_id, circ->p_circ_id);
       }
@@ -280,7 +280,7 @@
     return NULL;
   }
 
-  if(onion_extend_cpath(&circ->cpath, circ->build_state, &firsthop)<0 ||
+  if (onion_extend_cpath(&circ->cpath, circ->build_state, &firsthop)<0 ||
      !CIRCUIT_IS_ORIGIN(circ)) {
     log_fn(LOG_INFO,"Generating first cpath hop failed.");
     circuit_mark_for_close(circ);
@@ -298,14 +298,14 @@
   memcpy(circ->n_conn_id_digest, firsthop->identity_digest, DIGEST_LEN);
   n_conn = connection_get_by_identity_digest(firsthop->identity_digest,
                                              CONN_TYPE_OR);
-  if(!n_conn || n_conn->state != OR_CONN_STATE_OPEN) { /* not currently connected */
+  if (!n_conn || n_conn->state != OR_CONN_STATE_OPEN) { /* not currently connected */
     circ->n_addr = firsthop->addr;
     circ->n_port = firsthop->or_port;
 
-    if(!n_conn) { /* launch the connection */
+    if (!n_conn) { /* launch the connection */
       n_conn = connection_or_connect(firsthop->addr, firsthop->or_port,
                                      firsthop->identity_digest);
-      if(!n_conn) { /* connect failed, forget the whole thing */
+      if (!n_conn) { /* connect failed, forget the whole thing */
         log_fn(LOG_INFO,"connect to firsthop failed. Closing.");
         circuit_mark_for_close(circ);
         return NULL;
@@ -322,7 +322,7 @@
     circ->n_port = n_conn->port;
     circ->n_conn = n_conn;
     log_fn(LOG_DEBUG,"Conn open. Delivering first onion skin.");
-    if(circuit_send_next_onion_skin(circ) < 0) {
+    if (circuit_send_next_onion_skin(circ) < 0) {
       log_fn(LOG_INFO,"circuit_send_next_onion_skin failed.");
       circuit_mark_for_close(circ);
       return NULL;
@@ -341,15 +341,15 @@
 
   log_fn(LOG_DEBUG,"or_conn to %s, status=%d", or_conn->nickname, status);
 
-  for(circ=global_circuitlist;circ;circ = circ->next) {
+  for (circ=global_circuitlist;circ;circ = circ->next) {
     if (circ->marked_for_close)
       continue;
-    if(!circ->n_conn &&
+    if (!circ->n_conn &&
        circ->n_addr == or_conn->addr &&
        circ->n_port == or_conn->port &&
        !memcmp(or_conn->identity_digest, circ->n_conn_id_digest, DIGEST_LEN)) {
       tor_assert(circ->state == CIRCUIT_STATE_OR_WAIT);
-      if(!status) { /* or_conn failed; close circ */
+      if (!status) { /* or_conn failed; close circ */
         log_fn(LOG_INFO,"or_conn failed. Closing circ.");
         circuit_mark_for_close(circ);
         continue;
@@ -357,8 +357,8 @@
       log_fn(LOG_DEBUG,"Found circ %d, sending create cell.", circ->n_circ_id);
       circ->n_conn = or_conn;
       memcpy(circ->n_conn_id_digest, or_conn->identity_digest, DIGEST_LEN);
-      if(CIRCUIT_IS_ORIGIN(circ)) {
-        if(circuit_send_next_onion_skin(circ) < 0) {
+      if (CIRCUIT_IS_ORIGIN(circ)) {
+        if (circuit_send_next_onion_skin(circ) < 0) {
           log_fn(LOG_INFO,"send_next_onion_skin failed; circuit marked for closing.");
           circuit_mark_for_close(circ);
           continue;
@@ -366,7 +366,7 @@
         }
       } else {
         /* pull the create cell out of circ->onionskin, and send it */
-        if(circuit_deliver_create_cell(circ, circ->onionskin) < 0) {
+        if (circuit_deliver_create_cell(circ, circ->onionskin) < 0) {
           circuit_mark_for_close(circ);
           continue;
         }
@@ -385,7 +385,7 @@
   tor_assert(payload);
 
   circ->n_circ_id = get_unique_circ_id_by_conn(circ->n_conn);
-  if(!circ->n_circ_id) {
+  if (!circ->n_circ_id) {
     log_fn(LOG_WARN,"failed to get unique circID.");
     return -1;
   }
@@ -423,7 +423,7 @@
   tor_assert(circ);
   tor_assert(CIRCUIT_IS_ORIGIN(circ));
 
-  if(circ->cpath->state == CPATH_STATE_CLOSED) {
+  if (circ->cpath->state == CPATH_STATE_CLOSED) {
     log_fn(LOG_DEBUG,"First skin; sending create cell.");
 
     router = router_get_by_digest(circ->n_conn->identity_digest);
@@ -433,14 +433,14 @@
       return -1;
     }
 
-    if(onion_skin_create(router->onion_pkey,
+    if (onion_skin_create(router->onion_pkey,
                          &(circ->cpath->handshake_state),
                          payload) < 0) {
       log_fn(LOG_WARN,"onion_skin_create (first hop) failed.");
       return -1;
     }
 
-    if(circuit_deliver_create_cell(circ, payload) < 0)
+    if (circuit_deliver_create_cell(circ, payload) < 0)
       return -1;
 
     circ->cpath->state = CPATH_STATE_AWAITING_KEYS;
@@ -456,7 +456,7 @@
       circ->state = CIRCUIT_STATE_OPEN;
       log_fn(LOG_INFO,"circuit built!");
       circuit_reset_failure_count(0);
-      if(!has_completed_circuit) {
+      if (!has_completed_circuit) {
         has_completed_circuit=1;
         log_fn(LOG_NOTICE,"Tor has successfully opened a circuit. Looks like it's working.");
         /* XXX009 Log a count of known routers here */
@@ -477,7 +477,7 @@
     memcpy(payload+2+4+ONIONSKIN_CHALLENGE_LEN, hop->identity_digest, DIGEST_LEN);
     payload_len = 2+4+ONIONSKIN_CHALLENGE_LEN+DIGEST_LEN;
 
-    if(onion_skin_create(router->onion_pkey, &(hop->handshake_state), onionskin) < 0) {
+    if (onion_skin_create(router->onion_pkey, &(hop->handshake_state), onionskin) < 0) {
       log_fn(LOG_WARN,"onion_skin_create failed.");
       return -1;
     }
@@ -485,7 +485,7 @@
     log_fn(LOG_DEBUG,"Sending extend relay cell.");
     /* send it to hop->prev, because it will transfer
      * it to a create cell and then send to hop */
-    if(connection_edge_send_command(NULL, circ, RELAY_COMMAND_EXTEND,
+    if (connection_edge_send_command(NULL, circ, RELAY_COMMAND_EXTEND,
                                payload, payload_len, hop->prev) < 0)
       return 0; /* circuit is closed */
 
@@ -505,7 +505,7 @@
   char *id_digest=NULL;
   routerinfo_t *router;
 
-  if(circ->n_conn) {
+  if (circ->n_conn) {
     log_fn(LOG_WARN,"n_conn already set. Bug/attack. Closing.");
     return -1;
   }
@@ -524,7 +524,7 @@
   id_digest = cell->payload+RELAY_HEADER_SIZE+4+2+ONIONSKIN_CHALLENGE_LEN;
   n_conn = connection_get_by_identity_digest(id_digest, CONN_TYPE_OR);
 
-  if(!n_conn || n_conn->state != OR_CONN_STATE_OPEN) {
+  if (!n_conn || n_conn->state != OR_CONN_STATE_OPEN) {
      /* Note that this will close circuits where the onion has the same
      * router twice in a row in the path. I think that's ok.
      */
@@ -541,13 +541,13 @@
     /* imprint the circuit with its future n_conn->id */
     memcpy(circ->n_conn_id_digest, id_digest, DIGEST_LEN);
 
-    if(n_conn) {
+    if (n_conn) {
       circ->n_addr = n_conn->addr;
       circ->n_port = n_conn->port;
     } else {
      /* we should try to open a connection */
       n_conn = connection_or_connect(circ->n_addr, circ->n_port, id_digest);
-      if(!n_conn) {
+      if (!n_conn) {
         log_fn(LOG_INFO,"Launching n_conn failed. Closing.");
         return -1;
       }
@@ -567,7 +567,7 @@
   memcpy(circ->n_conn_id_digest, n_conn->identity_digest, DIGEST_LEN);
   log_fn(LOG_DEBUG,"n_conn is %s:%u",n_conn->address,n_conn->port);
 
-  if(circuit_deliver_create_cell(circ, onionskin) < 0)
+  if (circuit_deliver_create_cell(circ, onionskin) < 0)
     return -1;
   return 0;
 }
@@ -637,20 +637,20 @@
   crypt_path_t *hop;
 
   tor_assert(CIRCUIT_IS_ORIGIN(circ));
-  if(circ->cpath->state == CPATH_STATE_AWAITING_KEYS)
+  if (circ->cpath->state == CPATH_STATE_AWAITING_KEYS)
     hop = circ->cpath;
   else {
-    for(hop=circ->cpath->next;
+    for (hop=circ->cpath->next;
         hop != circ->cpath && hop->state == CPATH_STATE_OPEN;
         hop=hop->next) ;
-    if(hop == circ->cpath) { /* got an extended when we're all done? */
+    if (hop == circ->cpath) { /* got an extended when we're all done? */
       log_fn(LOG_WARN,"got extended when circ already built? Closing.");
       return -1;
     }
   }
   tor_assert(hop->state == CPATH_STATE_AWAITING_KEYS);
 
-  if(onion_skin_client_handshake(hop->handshake_state, reply, keys,
+  if (onion_skin_client_handshake(hop->handshake_state, reply, keys,
                                  DIGEST_LEN*2+CIPHER_KEY_LEN*2) < 0) {
     log_fn(LOG_WARN,"onion_skin_client_handshake failed.");
     return -1;
@@ -695,13 +695,13 @@
   return 0;
 
 #if 0
-  while(layer->next != circ->cpath) {
+  while (layer->next != circ->cpath) {
     /* we need to clear out layer->next */
     victim = layer->next;
     log_fn(LOG_DEBUG, "Killing a layer of the cpath.");
 
-    for(stream = circ->p_streams; stream; stream=stream->next_stream) {
-      if(stream->cpath_layer == victim) {
+    for (stream = circ->p_streams; stream; stream=stream->next_stream) {
+      if (stream->cpath_layer == victim) {
         log_fn(LOG_INFO, "Marking stream %d for close.", stream->stream_id);
         /* no need to send 'end' relay cells,
          * because the other side's already dead
@@ -777,15 +777,15 @@
 #ifdef TOR_PERF
   routelen = 2;
 #else
-  if(purpose == CIRCUIT_PURPOSE_C_GENERAL)
+  if (purpose == CIRCUIT_PURPOSE_C_GENERAL)
     routelen = 3;
-  else if(purpose == CIRCUIT_PURPOSE_C_INTRODUCING)
+  else if (purpose == CIRCUIT_PURPOSE_C_INTRODUCING)
     routelen = 4;
-  else if(purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND)
+  else if (purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND)
     routelen = 3;
-  else if(purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO)
+  else if (purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO)
     routelen = 3;
-  else if(purpose == CIRCUIT_PURPOSE_S_CONNECT_REND)
+  else if (purpose == CIRCUIT_PURPOSE_S_CONNECT_REND)
     routelen = 4;
   else {
     log_fn(LOG_WARN,"Unhandled purpose %d", purpose);
@@ -793,7 +793,7 @@
   }
 #endif
 #if 0
-  for(routelen = 3; ; routelen++) { /* 3, increment until coinflip says we're done */
+  for (routelen = 3; ; routelen++) { /* 3, increment until coinflip says we're done */
     if (crypto_pseudo_rand_int(255) >= cw*255) /* don't extend */
       break;
   }
@@ -803,13 +803,13 @@
 
   num_acceptable_routers = count_acceptable_routers(routers);
 
-  if(num_acceptable_routers < 2) {
+  if (num_acceptable_routers < 2) {
     log_fn(LOG_INFO,"Not enough acceptable routers (%d). Discarding this circuit.",
            num_acceptable_routers);
     return -1;
   }
 
-  if(num_acceptable_routers < routelen) {
+  if (num_acceptable_routers < routelen) {
     log_fn(LOG_INFO,"Not enough routers: cutting routelen from %d to %d.",
            routelen, num_acceptable_routers);
     routelen = num_acceptable_routers;
@@ -864,7 +864,7 @@
   n_supported = tor_malloc(sizeof(int)*smartlist_len(dir->routers));
   for (i = 0; i < smartlist_len(dir->routers); ++i) { /* iterate over routers */
     router = smartlist_get(dir->routers, i);
-    if(router_is_me(router)) {
+    if (router_is_me(router)) {
       n_supported[i] = -1;
       log_fn(LOG_DEBUG,"Skipping node %s -- it's me.", router->nickname);
       /* XXX there's probably a reverse predecessor attack here, but
@@ -872,13 +872,13 @@
        */
       continue;
     }
-    if(!router->is_running) {
+    if (!router->is_running) {
       n_supported[i] = -1;
       log_fn(LOG_DEBUG,"Skipping node %s (index %d) -- directory says it's not running.",
              router->nickname, i);
       continue; /* skip routers that are known to be down */
     }
-    if(!router->is_verified &&
+    if (!router->is_verified &&
        (!(options->_AllowUnverified & ALLOW_UNVERIFIED_EXIT) ||
          router_is_unreliable_router(router, 1, 1))) {
       /* if it's unverified, and either we don't want it or it's unsuitable */
@@ -887,13 +887,13 @@
              router->nickname, i);
       continue; /* skip unverified routers */
     }
-    if(router_exit_policy_rejects_all(router)) {
+    if (router_exit_policy_rejects_all(router)) {
       n_supported[i] = -1;
       log_fn(LOG_DEBUG,"Skipping node %s (index %d) -- it rejects all.",
              router->nickname, i);
       continue; /* skip routers that reject all */
     }
-    if(smartlist_len(preferredentries)==1 &&
+    if (smartlist_len(preferredentries)==1 &&
        router == (routerinfo_t*)smartlist_get(preferredentries, 0)) {
       n_supported[i] = -1;
       log_fn(LOG_DEBUG,"Skipping node %s (index %d) -- it's our only preferred entry node.", router->nickname, i);
@@ -906,7 +906,7 @@
           carray[j]->marked_for_close ||
           circuit_stream_is_being_handled(carray[j]))
         continue; /* Skip everything but APs in CIRCUIT_WAIT */
-      if(connection_ap_can_use_exit(carray[j], router)) {
+      if (connection_ap_can_use_exit(carray[j], router)) {
         ++n_supported[i];
         log_fn(LOG_DEBUG,"%s is supported. n_supported[%d] now %d.",
                router->nickname, i, n_supported[i]);
@@ -955,8 +955,8 @@
     if (best_support == -1) {
       log(LOG_WARN, "All routers are down or middleman -- choosing a doomed exit at random.");
     }
-    for(i = 0; i < smartlist_len(dir->routers); i++)
-      if(n_supported[i] != -1)
+    for (i = 0; i < smartlist_len(dir->routers); i++)
+      if (n_supported[i] != -1)
         smartlist_add(sl, smartlist_get(dir->routers, i));
 
     smartlist_subtract(sl,excludedexits);
@@ -970,7 +970,7 @@
   smartlist_free(excludedexits);
   smartlist_free(sl);
   tor_free(n_supported);
-  if(router) {
+  if (router) {
     log_fn(LOG_INFO, "Chose exit server '%s'", router->nickname);
     return router;
   }
@@ -994,7 +994,7 @@
 {
   routerinfo_t *r;
   or_options_t *options = get_options();
-  switch(purpose) {
+  switch (purpose) {
     case CIRCUIT_PURPOSE_C_GENERAL:
       return choose_good_exit_server_general(dir);
     case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
@@ -1026,7 +1026,7 @@
     return NULL;
   info = tor_malloc_zero(sizeof(cpath_build_state_t));
   info->desired_path_len = r;
-  if(exit_digest) { /* the circuit-builder pre-requested one */
+  if (exit_digest) { /* the circuit-builder pre-requested one */
     memcpy(info->chosen_exit_digest, exit_digest, DIGEST_LEN);
     exit = router_get_by_digest(exit_digest);
     if (exit) {
@@ -1039,7 +1039,7 @@
     log_fn(LOG_INFO,"Using requested exit node '%s'", info->chosen_exit_name);
   } else { /* we have to decide one */
     exit = choose_good_exit_server(purpose, rl);
-    if(!exit) {
+    if (!exit) {
       log_fn(LOG_WARN,"failed to choose an exit server");
       tor_free(info);
       return NULL;
@@ -1059,15 +1059,15 @@
   routerinfo_t *r;
 
   n = smartlist_len(routers);
-  for(i=0;i<n;i++) {
+  for (i=0;i<n;i++) {
     r = smartlist_get(routers, i);
     log_fn(LOG_DEBUG,"Contemplating whether router %d (%s) is a new option...",
            i, r->nickname);
-    if(r->is_running == 0) {
+    if (r->is_running == 0) {
       log_fn(LOG_DEBUG,"Nope, the directory says %d is not running.",i);
       goto next_i_loop;
     }
-    if(r->is_verified == 0) {
+    if (r->is_verified == 0) {
       log_fn(LOG_DEBUG,"Nope, the directory says %d is not verified.",i);
       /* XXXX009 But unverified routers *are* sometimes acceptable. */
       goto next_i_loop;
@@ -1109,16 +1109,16 @@
 
   log_fn(LOG_DEBUG, "Contemplating intermediate hop: random choice.");
   excluded = smartlist_create();
-  if((r = router_get_by_digest(state->chosen_exit_digest))) {
+  if ((r = router_get_by_digest(state->chosen_exit_digest))) {
     smartlist_add(excluded, r);
     routerlist_add_family(excluded, r);
   }
-  if((r = routerlist_find_my_routerinfo())) {
+  if ((r = routerlist_find_my_routerinfo())) {
     smartlist_add(excluded, r);
     routerlist_add_family(excluded, r);
   }
   for (i = 0, cpath = head; i < cur_len; ++i, cpath=cpath->next) {
-    if((r = router_get_by_digest(cpath->identity_digest))) {
+    if ((r = router_get_by_digest(cpath->identity_digest))) {
       smartlist_add(excluded, r);
       routerlist_add_family(excluded, r);
     }
@@ -1136,24 +1136,24 @@
   or_options_t *options = get_options();
   char buf[16];
 
-  if((r = router_get_by_digest(state->chosen_exit_digest))) {
+  if ((r = router_get_by_digest(state->chosen_exit_digest))) {
     smartlist_add(excluded, r);
     routerlist_add_family(excluded, r);
   }
-  if((r = routerlist_find_my_routerinfo())) {
+  if ((r = routerlist_find_my_routerinfo())) {
     smartlist_add(excluded, r);
     routerlist_add_family(excluded, r);
   }
-  if(options->FascistFirewall) {
+  if (options->FascistFirewall) {
     /* exclude all ORs that listen on the wrong port */
     routerlist_t *rl;
     int i;
 
     router_get_routerlist(&rl);
-    if(!rl)
+    if (!rl)
       return NULL;
 
-    for(i=0; i < smartlist_len(rl->routers); i++) {
+    for (i=0; i < smartlist_len(rl->routers); i++) {
       r = smartlist_get(rl->routers, i);
       tor_snprintf(buf, sizeof(buf), "%d", r->or_port);
       if (!smartlist_string_isin(options->FirewallPorts, buf))
@@ -1202,16 +1202,16 @@
   excludednodes = smartlist_create();
   add_nickname_list_to_smartlist(excludednodes,get_options()->ExcludeNodes,0);
 
-  if(cur_len == state->desired_path_len - 1) { /* Picking last node */
+  if (cur_len == state->desired_path_len - 1) { /* Picking last node */
     choice = router_get_by_digest(state->chosen_exit_digest);
-  } else if(cur_len == 0) { /* picking first node */
+  } else if (cur_len == 0) { /* picking first node */
     choice = choose_good_entry_server(state);
   } else {
     choice = choose_good_middle_server(state, *head_ptr, cur_len);
   }
 
   smartlist_free(excludednodes);
-  if(!choice) {
+  if (!choice) {
     log_fn(LOG_WARN,"Failed to find node for hop %d of our path. Discarding this circuit.", cur_len);
     return -1;
   }

Index: circuitlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/circuitlist.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- circuitlist.c	26 Nov 2004 04:00:52 -0000	1.19
+++ circuitlist.c	28 Nov 2004 09:05:46 -0000	1.20
@@ -34,7 +34,7 @@
  * within circuit_new.
  */
 static void circuit_add(circuit_t *circ) {
-  if(!global_circuitlist) { /* first one */
+  if (!global_circuitlist) { /* first one */
     global_circuitlist = circ;
     circ->next = NULL;
   } else {
@@ -115,7 +115,7 @@
     crypto_free_digest_env(circ->n_digest);
   if (circ->p_digest)
     crypto_free_digest_env(circ->p_digest);
-  if(circ->build_state) {
+  if (circ->build_state) {
     tor_free(circ->build_state->chosen_exit_name);
     if (circ->build_state->pending_final_cpath)
       circuit_free_cpath_node(circ->build_state->pending_final_cpath);
@@ -134,12 +134,12 @@
 static void circuit_free_cpath(crypt_path_t *cpath) {
   crypt_path_t *victim, *head=cpath;
 
-  if(!cpath)
+  if (!cpath)
     return;
 
   /* it's a doubly linked list, so we have to notice when we've
    * gone through it once. */
-  while(cpath->next && cpath->next != head) {
+  while (cpath->next && cpath->next != head) {
     victim = cpath;
     cpath = victim->next;
     circuit_free_cpath_node(victim);
@@ -151,15 +151,15 @@
 /** Deallocate space associated with the cpath node <b>victim</b>. */
 static void
 circuit_free_cpath_node(crypt_path_t *victim) {
-  if(victim->f_crypto)
+  if (victim->f_crypto)
     crypto_free_cipher_env(victim->f_crypto);
-  if(victim->b_crypto)
+  if (victim->b_crypto)
     crypto_free_cipher_env(victim->b_crypto);
-  if(victim->f_digest)
+  if (victim->f_digest)
     crypto_free_digest_env(victim->f_digest);
-  if(victim->b_digest)
+  if (victim->b_digest)
     crypto_free_digest_env(victim->b_digest);
-  if(victim->handshake_state)
+  if (victim->handshake_state)
     crypto_dh_free(victim->handshake_state);
   tor_free(victim);
 }
@@ -174,27 +174,27 @@
   circuit_t *circ;
   connection_t *tmpconn;
 
-  for(circ=global_circuitlist;circ;circ = circ->next) {
+  for (circ=global_circuitlist;circ;circ = circ->next) {
     if (circ->marked_for_close)
       continue;
 
-    if(circ->p_circ_id == circ_id) {
-      if(circ->p_conn == conn)
+    if (circ->p_circ_id == circ_id) {
+      if (circ->p_conn == conn)
         return circ;
-      for(tmpconn = circ->p_streams; tmpconn; tmpconn = tmpconn->next_stream) {
-        if(tmpconn == conn)
+      for (tmpconn = circ->p_streams; tmpconn; tmpconn = tmpconn->next_stream) {
+        if (tmpconn == conn)
           return circ;
       }
     }
-    if(circ->n_circ_id == circ_id) {
-      if(circ->n_conn == conn)
+    if (circ->n_circ_id == circ_id) {
+      if (circ->n_conn == conn)
         return circ;
-      for(tmpconn = circ->n_streams; tmpconn; tmpconn = tmpconn->next_stream) {
-        if(tmpconn == conn)
+      for (tmpconn = circ->n_streams; tmpconn; tmpconn = tmpconn->next_stream) {
+        if (tmpconn == conn)
           return circ;
       }
-      for(tmpconn = circ->resolving_streams; tmpconn; tmpconn = tmpconn->next_stream) {
-        if(tmpconn == conn)
+      for (tmpconn = circ->resolving_streams; tmpconn; tmpconn = tmpconn->next_stream) {
+        if (tmpconn == conn)
           return circ;
       }
     }
@@ -211,22 +211,22 @@
   circuit_t *circ;
   connection_t *tmpconn;
 
-  for(circ=global_circuitlist;circ;circ = circ->next) {
+  for (circ=global_circuitlist;circ;circ = circ->next) {
     if (circ->marked_for_close)
       continue;
 
-    if(circ->p_conn == conn)
+    if (circ->p_conn == conn)
       return circ;
-    if(circ->n_conn == conn)
+    if (circ->n_conn == conn)
       return circ;
-    for(tmpconn = circ->p_streams; tmpconn; tmpconn=tmpconn->next_stream)
-      if(tmpconn == conn)
+    for (tmpconn = circ->p_streams; tmpconn; tmpconn=tmpconn->next_stream)
+      if (tmpconn == conn)
         return circ;
-    for(tmpconn = circ->n_streams; tmpconn; tmpconn=tmpconn->next_stream)
-      if(tmpconn == conn)
+    for (tmpconn = circ->n_streams; tmpconn; tmpconn=tmpconn->next_stream)
+      if (tmpconn == conn)
         return circ;
-    for(tmpconn = circ->resolving_streams; tmpconn; tmpconn=tmpconn->next_stream)
-      if(tmpconn == conn)
+    for (tmpconn = circ->resolving_streams; tmpconn; tmpconn=tmpconn->next_stream)
+      if (tmpconn == conn)
         return circ;
   }
   return NULL;
@@ -265,7 +265,7 @@
   else
     circ = start->next;
 
-  for( ; circ; circ = circ->next) {
+  for ( ; circ; circ = circ->next) {
     if (circ->marked_for_close)
       continue;
     if (circ->purpose != purpose)
@@ -297,8 +297,8 @@
   circuit_t *circ;
   int num=0;
 
-  for(circ=global_circuitlist;circ;circ = circ->next) {
-    if(CIRCUIT_IS_ORIGIN(circ) &&
+  for (circ=global_circuitlist;circ;circ = circ->next) {
+    if (CIRCUIT_IS_ORIGIN(circ) &&
        circ->state != CIRCUIT_STATE_OPEN &&
        circ->purpose == purpose &&
        !circ->marked_for_close)
@@ -316,8 +316,8 @@
   circuit_t *circ;
   circuit_t *youngest=NULL;
 
-  for(circ=global_circuitlist;circ;circ = circ->next) {
-    if(CIRCUIT_IS_ORIGIN(circ) && circ->state == CIRCUIT_STATE_OPEN &&
+  for (circ=global_circuitlist;circ;circ = circ->next) {
+    if (CIRCUIT_IS_ORIGIN(circ) && circ->state == CIRCUIT_STATE_OPEN &&
        !circ->marked_for_close && circ->purpose == purpose &&
        !circ->timestamp_dirty &&
        (!youngest || youngest->timestamp_created < circ->timestamp_created))
@@ -348,7 +348,7 @@
   if (circ->marked_for_close)
     return -1;
 
-  if(circ->state == CIRCUIT_STATE_ONIONSKIN_PENDING) {
+  if (circ->state == CIRCUIT_STATE_ONIONSKIN_PENDING) {
     onion_pending_remove(circ);
   }
   /* If the circuit ever became OPEN, we sent it to the reputation history
@@ -356,7 +356,7 @@
    * links worked and which didn't.
    */
   if (circ->state != CIRCUIT_STATE_OPEN) {
-    if(CIRCUIT_IS_ORIGIN(circ)) {
+    if (CIRCUIT_IS_ORIGIN(circ)) {
       circuit_build_failed(circ); /* take actions if necessary */
     }
     circuit_rep_hist_note_result(circ);
@@ -373,20 +373,20 @@
     rend_client_remove_intro_point(circ->build_state->chosen_exit_name, circ->rend_query);
   }
 
-  if(circ->n_conn)
+  if (circ->n_conn)
     connection_send_destroy(circ->n_circ_id, circ->n_conn);
-  for(conn=circ->n_streams; conn; conn=conn->next_stream)
+  for (conn=circ->n_streams; conn; conn=conn->next_stream)
     connection_edge_destroy(circ->n_circ_id, conn);
-  while(circ->resolving_streams) {
+  while (circ->resolving_streams) {
     conn = circ->resolving_streams;
     circ->resolving_streams = conn->next_stream;
     connection_dns_remove(conn); /* remove it from resolve lists */
     log_fn(LOG_INFO,"Freeing resolving-conn.");
     connection_free(conn);
   }
-  if(circ->p_conn)
+  if (circ->p_conn)
     connection_send_destroy(circ->p_circ_id, circ->p_conn);
-  for(conn=circ->p_streams; conn; conn=conn->next_stream)
+  for (conn=circ->p_streams; conn; conn=conn->next_stream)
     connection_edge_destroy(circ->p_circ_id, conn);
 
   circ->marked_for_close = 1;
@@ -406,7 +406,7 @@
 {
 //  tor_assert(cp->addr); /* these are zero for rendezvous extra-hops */
 //  tor_assert(cp->port);
-  switch(cp->state)
+  switch (cp->state)
     {
     case CPATH_STATE_OPEN:
       tor_assert(cp->f_crypto);

Index: circuituse.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/circuituse.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- circuituse.c	26 Nov 2004 04:00:52 -0000	1.25
+++ circuituse.c	28 Nov 2004 09:05:46 -0000	1.26
@@ -43,8 +43,8 @@
     return 0;
 
   /* if this circ isn't our purpose, skip. */
-  if(purpose == CIRCUIT_PURPOSE_C_REND_JOINED && !must_be_open) {
-    if(circ->purpose != CIRCUIT_PURPOSE_C_ESTABLISH_REND &&
+  if (purpose == CIRCUIT_PURPOSE_C_REND_JOINED && !must_be_open) {
+    if (circ->purpose != CIRCUIT_PURPOSE_C_ESTABLISH_REND &&
        circ->purpose != CIRCUIT_PURPOSE_C_REND_READY &&
        circ->purpose != CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED &&
        circ->purpose != CIRCUIT_PURPOSE_C_REND_JOINED)
@@ -54,16 +54,16 @@
         circ->purpose != CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT)
       return 0;
   } else {
-    if(purpose != circ->purpose)
+    if (purpose != circ->purpose)
       return 0;
   }
 
-  if(purpose == CIRCUIT_PURPOSE_C_GENERAL)
-    if(circ->timestamp_dirty &&
+  if (purpose == CIRCUIT_PURPOSE_C_GENERAL)
+    if (circ->timestamp_dirty &&
        circ->timestamp_dirty+get_options()->NewCircuitPeriod <= now)
       return 0;
 
-  if(conn) {
+  if (conn) {
     /* decide if this circ is suitable for this conn */
 
     /* for rend circs, circ->cpath->prev is not the last router in the
@@ -72,7 +72,7 @@
      */
     exitrouter = router_get_by_digest(circ->build_state->chosen_exit_digest);
 
-    if(!exitrouter) {
+    if (!exitrouter) {
       log_fn(LOG_INFO,"Skipping broken circ (exit router vanished)");
       return 0; /* this circuit is screwed and doesn't know it yet */
     }
@@ -82,13 +82,13 @@
       /* 0.0.8 servers have buggy resolve support. */
       if (!tor_version_as_new_as(exitrouter->platform, "0.0.9pre1"))
         return 0;
-    } else if(purpose == CIRCUIT_PURPOSE_C_GENERAL) {
-      if(!connection_ap_can_use_exit(conn, exitrouter)) {
+    } else if (purpose == CIRCUIT_PURPOSE_C_GENERAL) {
+      if (!connection_ap_can_use_exit(conn, exitrouter)) {
         /* can't exit from this router */
         return 0;
       }
     } else { /* not general */
-      if(rend_cmp_service_ids(conn->rend_query, circ->rend_query) &&
+      if (rend_cmp_service_ids(conn->rend_query, circ->rend_query) &&
          (circ->rend_query[0] || purpose != CIRCUIT_PURPOSE_C_REND_JOINED)) {
         /* this circ is not for this conn, and it's not suitable
          * for cannibalizing either */
@@ -104,29 +104,29 @@
  */
 static int circuit_is_better(circuit_t *a, circuit_t *b, uint8_t purpose)
 {
-  switch(purpose) {
+  switch (purpose) {
     case CIRCUIT_PURPOSE_C_GENERAL:
       /* if it's used but less dirty it's best;
        * else if it's more recently created it's best
        */
-      if(b->timestamp_dirty) {
-        if(a->timestamp_dirty &&
+      if (b->timestamp_dirty) {
+        if (a->timestamp_dirty &&
            a->timestamp_dirty > b->timestamp_dirty)
           return 1;
       } else {
-        if(a->timestamp_dirty ||
+        if (a->timestamp_dirty ||
            a->timestamp_created > b->timestamp_created)
           return 1;
       }
       break;
     case CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT:
       /* the closer it is to ack_wait the better it is */
-      if(a->purpose > b->purpose)
+      if (a->purpose > b->purpose)
         return 1;
       break;
     case CIRCUIT_PURPOSE_C_REND_JOINED:
       /* the closer it is to rend_joined the better it is */
-      if(a->purpose > b->purpose)
+      if (a->purpose > b->purpose)
         return 1;
       break;
   }
@@ -168,7 +168,7 @@
     /* now this is an acceptable circ to hand back. but that doesn't
      * mean it's the *best* circ to hand back. try to decide.
      */
-    if(!best || circuit_is_better(circ,best,purpose))
+    if (!best || circuit_is_better(circ,best,purpose))
       best = circ;
   }
 
@@ -187,20 +187,20 @@
 void circuit_expire_building(time_t now) {
   circuit_t *victim, *circ = global_circuitlist;
 
-  while(circ) {
+  while (circ) {
     victim = circ;
     circ = circ->next;
-    if(!CIRCUIT_IS_ORIGIN(victim))
+    if (!CIRCUIT_IS_ORIGIN(victim))
       continue; /* didn't originate here */
-    if(victim->marked_for_close)
+    if (victim->marked_for_close)
       continue; /* don't mess with marked circs */
-    if(victim->timestamp_created + MIN_SECONDS_BEFORE_EXPIRING_CIRC > now)
+    if (victim->timestamp_created + MIN_SECONDS_BEFORE_EXPIRING_CIRC > now)
       continue; /* it's young still, don't mess with it */
 
     /* some debug logs, to help track bugs */
-    if(victim->purpose >= CIRCUIT_PURPOSE_C_INTRODUCING &&
+    if (victim->purpose >= CIRCUIT_PURPOSE_C_INTRODUCING &&
        victim->purpose <= CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED) {
-      if(!victim->timestamp_dirty)
+      if (!victim->timestamp_dirty)
         log_fn(LOG_DEBUG,"Considering %sopen purp %d to %s (circid %d). (clean).",
                victim->state == CIRCUIT_STATE_OPEN ? "" : "non",
                victim->purpose, victim->build_state->chosen_exit_name,
@@ -215,7 +215,7 @@
 
     /* if circ is !open, or if it's open but purpose is a non-finished
      * intro or rend, then mark it for close */
-    if(victim->state != CIRCUIT_STATE_OPEN ||
+    if (victim->state != CIRCUIT_STATE_OPEN ||
        victim->purpose == CIRCUIT_PURPOSE_C_ESTABLISH_REND ||
        victim->purpose == CIRCUIT_PURPOSE_C_INTRODUCING ||
        victim->purpose == CIRCUIT_PURPOSE_S_ESTABLISH_INTRO ||
@@ -235,7 +235,7 @@
          victim->purpose == CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED ||
          victim->purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) &&
         victim->timestamp_dirty + MIN_SECONDS_BEFORE_EXPIRING_CIRC > now)) {
-      if(victim->n_conn)
+      if (victim->n_conn)
         log_fn(LOG_INFO,"Abandoning circ %s:%d:%d (state %d:%s, purpose %d)",
                victim->n_conn->address, victim->n_port, victim->n_circ_id,
                victim->state, circuit_state_to_string[victim->state], victim->purpose);
@@ -263,14 +263,14 @@
   int num=0;
   time_t now = time(NULL);
 
-  for(circ=global_circuitlist;circ;circ = circ->next) {
-    if(CIRCUIT_IS_ORIGIN(circ) && circ->state != CIRCUIT_STATE_OPEN &&
+  for (circ=global_circuitlist;circ;circ = circ->next) {
+    if (CIRCUIT_IS_ORIGIN(circ) && circ->state != CIRCUIT_STATE_OPEN &&
        !circ->marked_for_close && circ->purpose == CIRCUIT_PURPOSE_C_GENERAL &&
        (!circ->timestamp_dirty ||
         circ->timestamp_dirty + get_options()->NewCircuitPeriod < now)) {
       exitrouter = router_get_by_digest(circ->build_state->chosen_exit_digest);
-      if(exitrouter && connection_ap_can_use_exit(conn, exitrouter))
-        if(++num >= MIN_CIRCUITS_HANDLING_STREAM)
+      if (exitrouter && connection_ap_can_use_exit(conn, exitrouter))
+        if (++num >= MIN_CIRCUITS_HANDLING_STREAM)
           return 1;
     }
   }
@@ -293,19 +293,19 @@
   connection_ap_attach_pending();
 
   /* make sure any hidden services have enough intro points */
-  if(has_fetched_directory)
+  if (has_fetched_directory)
     rend_services_introduce();
 
   circ = circuit_get_youngest_clean_open(CIRCUIT_PURPOSE_C_GENERAL);
 
-  if(time_to_new_circuit < now) {
+  if (time_to_new_circuit < now) {
     circuit_reset_failure_count(1);
     time_to_new_circuit = now + get_options()->NewCircuitPeriod;
-    if(proxy_mode(get_options()))
+    if (proxy_mode(get_options()))
       client_dns_clean();
     circuit_expire_old_circuits();
 
-    if(get_options()->RunTesting && circ &&
+    if (get_options()->RunTesting && circ &&
                circ->timestamp_created + TESTING_CIRCUIT_INTERVAL < now) {
       log_fn(LOG_INFO,"Creating a new testing circuit.");
       circuit_launch_by_identity(CIRCUIT_PURPOSE_C_GENERAL, NULL);
@@ -319,7 +319,7 @@
 #define CIRCUIT_MIN_BUILDING_GENERAL 5
   /* if there's no open circ, and less than 5 are on the way,
    * go ahead and try another. */
-  if(!circ && circuit_count_building(CIRCUIT_PURPOSE_C_GENERAL)
+  if (!circ && circuit_count_building(CIRCUIT_PURPOSE_C_GENERAL)
               < CIRCUIT_MIN_BUILDING_GENERAL) {
     circuit_launch_by_identity(CIRCUIT_PURPOSE_C_GENERAL, NULL);
   }
@@ -338,42 +338,42 @@
 
   conn->cpath_layer = NULL; /* make sure we don't keep a stale pointer */
 
-  if(conn == circ->p_streams) {
+  if (conn == circ->p_streams) {
     circ->p_streams = conn->next_stream;
     return;
   }
-  if(conn == circ->n_streams) {
+  if (conn == circ->n_streams) {
     circ->n_streams = conn->next_stream;
     return;
   }
-  if(conn == circ->resolving_streams) {
+  if (conn == circ->resolving_streams) {
     circ->resolving_streams = conn->next_stream;
     return;
   }
 
-  for(prevconn = circ->p_streams;
+  for (prevconn = circ->p_streams;
       prevconn && prevconn->next_stream && prevconn->next_stream != conn;
       prevconn = prevconn->next_stream)
     ;
-  if(prevconn && prevconn->next_stream) {
+  if (prevconn && prevconn->next_stream) {
     prevconn->next_stream = conn->next_stream;
     return;
   }
 
-  for(prevconn = circ->n_streams;
+  for (prevconn = circ->n_streams;
       prevconn && prevconn->next_stream && prevconn->next_stream != conn;
       prevconn = prevconn->next_stream)
     ;
-  if(prevconn && prevconn->next_stream) {
+  if (prevconn && prevconn->next_stream) {
     prevconn->next_stream = conn->next_stream;
     return;
   }
 
-  for(prevconn = circ->resolving_streams;
+  for (prevconn = circ->resolving_streams;
       prevconn && prevconn->next_stream && prevconn->next_stream != conn;
       prevconn = prevconn->next_stream)
     ;
-  if(prevconn && prevconn->next_stream) {
+  if (prevconn && prevconn->next_stream) {
     prevconn->next_stream = conn->next_stream;
     return;
   }
@@ -397,17 +397,17 @@
    */
   circuit_t *circ;
 
-  switch(conn->type) {
+  switch (conn->type) {
     case CONN_TYPE_OR:
-      if(conn->state != OR_CONN_STATE_OPEN) {
+      if (conn->state != OR_CONN_STATE_OPEN) {
         /* Inform any pending (not attached) circs that they should give up. */
         circuit_n_conn_done(conn, 0);
       }
       /* Now close all the attached circuits on it. */
-      while((circ = circuit_get_by_conn(conn))) {
-        if(circ->n_conn == conn) /* it's closing in front of us */
+      while ((circ = circuit_get_by_conn(conn))) {
+        if (circ->n_conn == conn) /* it's closing in front of us */
           circ->n_conn = NULL;
-        if(circ->p_conn == conn) /* it's closing behind us */
+        if (circ->p_conn == conn) /* it's closing behind us */
           circ->p_conn = NULL;
         circuit_mark_for_close(circ);
       }
@@ -421,7 +421,7 @@
        */
 
       circ = circuit_get_by_conn(conn);
-      if(!circ)
+      if (!circ)
         return;
 
       circuit_detach_stream(circ, conn);
@@ -494,7 +494,7 @@
 
   control_event_circuit_status(circ, CIRC_EVENT_BUILT);
 
-  switch(circ->purpose) {
+  switch (circ->purpose) {
     case CIRCUIT_PURPOSE_C_ESTABLISH_REND:
       rend_client_rendcirc_has_opened(circ);
       break;
@@ -536,7 +536,7 @@
       failed_at_last_hop = 1;
   }
 
-  switch(circ->purpose) {
+  switch (circ->purpose) {
     case CIRCUIT_PURPOSE_C_GENERAL:
       if (circ->state != CIRCUIT_STATE_OPEN) {
         /* If we never built the circuit, note it as a failure. */
@@ -644,7 +644,7 @@
  * stopping again.
  */
 void circuit_reset_failure_count(int timeout) {
-  if(timeout && n_circuit_failures > MAX_CIRCUIT_FAILURES)
+  if (timeout && n_circuit_failures > MAX_CIRCUIT_FAILURES)
     did_circs_fail_last_period = 1;
   else
     did_circs_fail_last_period = 0;
@@ -672,15 +672,15 @@
 
   circ = circuit_get_best(conn, 1, desired_circuit_purpose);
 
-  if(circ) {
+  if (circ) {
     *circp = circ;
     return 1; /* we're happy */
   }
 
   /* Do we need to check exit policy? */
-  if(!is_resolve && !connection_edge_is_rendezvous_stream(conn)) {
+  if (!is_resolve && !connection_edge_is_rendezvous_stream(conn)) {
     addr = client_dns_lookup_entry(conn->socks_request->address);
-    if(router_exit_policy_all_routers_reject(addr, conn->socks_request->port)) {
+    if (router_exit_policy_all_routers_reject(addr, conn->socks_request->port)) {
       log_fn(LOG_WARN,"No Tor server exists that allows exit to %s:%d. Rejecting.",
              conn->socks_request->address, conn->socks_request->port);
       return -1;
@@ -689,19 +689,19 @@
 
   /* is one already on the way? */
   circ = circuit_get_best(conn, 0, desired_circuit_purpose);
-  if(!circ) {
+  if (!circ) {
     char *exitname=NULL;
     uint8_t new_circ_purpose;
 
-    if(desired_circuit_purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) {
+    if (desired_circuit_purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT) {
       /* need to pick an intro point */
       exitname = rend_client_get_random_intro(conn->rend_query);
-      if(!exitname) {
+      if (!exitname) {
         log_fn(LOG_WARN,"Couldn't get an intro point for '%s'. Closing.",
                conn->rend_query);
         return -1;
       }
-      if(!router_get_by_nickname(exitname)) {
+      if (!router_get_by_nickname(exitname)) {
         log_fn(LOG_WARN,"Advertised intro point '%s' is not known. Closing.", exitname);
         return -1;
       }
@@ -709,9 +709,9 @@
       log_fn(LOG_INFO,"Chose %s as intro point for %s.", exitname, conn->rend_query);
     }
 
-    if(desired_circuit_purpose == CIRCUIT_PURPOSE_C_REND_JOINED)
+    if (desired_circuit_purpose == CIRCUIT_PURPOSE_C_REND_JOINED)
       new_circ_purpose = CIRCUIT_PURPOSE_C_ESTABLISH_REND;
-    else if(desired_circuit_purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT)
+    else if (desired_circuit_purpose == CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT)
       new_circ_purpose = CIRCUIT_PURPOSE_C_INTRODUCING;
     else
       new_circ_purpose = desired_circuit_purpose;
@@ -719,13 +719,13 @@
     circ = circuit_launch_by_nickname(new_circ_purpose, exitname);
     tor_free(exitname);
 
-    if(circ &&
+    if (circ &&
        (desired_circuit_purpose != CIRCUIT_PURPOSE_C_GENERAL)) {
       /* then write the service_id into circ */
       strlcpy(circ->rend_query, conn->rend_query, sizeof(circ->rend_query));
     }
   }
-  if(!circ)
+  if (!circ)
     log_fn(LOG_INFO,"No safe circuit (purpose %d) ready for edge connection; delaying.",
            desired_circuit_purpose);
   *circp = circ;
@@ -767,17 +767,17 @@
   tor_assert(conn->socks_request);
 
   conn_age = time(NULL) - conn->timestamp_created;
-  if(conn_age > CONN_AP_MAX_ATTACH_DELAY) {
+  if (conn_age > CONN_AP_MAX_ATTACH_DELAY) {
     log_fn(LOG_WARN,"Giving up on unattached conn (%d sec old).", conn_age);
     return -1;
   }
 
-  if(!connection_edge_is_rendezvous_stream(conn)) { /* we're a general conn */
+  if (!connection_edge_is_rendezvous_stream(conn)) { /* we're a general conn */
     circuit_t *circ=NULL;
 
     /* find the circuit that we should use, if there is one. */
     retval = circuit_get_open_circ_or_launch(conn, CIRCUIT_PURPOSE_C_GENERAL, &circ);
-    if(retval < 1)
+    if (retval < 1)
       return retval;
 
     /* We have found a suitable circuit for our conn. Hurray. */
@@ -788,7 +788,7 @@
     /* here, print the circ's path. so people can figure out which circs are sucking. */
     circuit_log_path(LOG_INFO,circ);
 
-    if(!circ->timestamp_dirty)
+    if (!circ->timestamp_dirty)
       circ->timestamp_dirty = time(NULL);
 
     link_apconn_to_circ(conn, circ);
@@ -807,29 +807,29 @@
     /* start by finding a rendezvous circuit for us */
 
     retval = circuit_get_open_circ_or_launch(conn, CIRCUIT_PURPOSE_C_REND_JOINED, &rendcirc);
-    if(retval < 0) return -1; /* failed */
+    if (retval < 0) return -1; /* failed */
 
-    if(retval > 0) {
+    if (retval > 0) {
       tor_assert(rendcirc);
       /* one is already established, attach */
       log_fn(LOG_INFO,"rend joined circ %d already here. attaching. (stream %d sec old)",
              rendcirc->n_circ_id, conn_age);
       link_apconn_to_circ(conn, rendcirc);
-      if(connection_ap_handshake_send_begin(conn, rendcirc) < 0)
+      if (connection_ap_handshake_send_begin(conn, rendcirc) < 0)
         return 0; /* already marked, let them fade away */
       return 1;
     }
 
-    if(rendcirc && rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED) {
+    if (rendcirc && rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED) {
       log_fn(LOG_INFO,"pending-join circ %d already here, with intro ack. Stalling. (stream %d sec old)", rendcirc->n_circ_id, conn_age);
       return 0;
     }
 
     /* it's on its way. find an intro circ. */
     retval = circuit_get_open_circ_or_launch(conn, CIRCUIT_PURPOSE_C_INTRODUCE_ACK_WAIT, &introcirc);
-    if(retval < 0) return -1; /* failed */
+    if (retval < 0) return -1; /* failed */
 
-    if(retval > 0) {
+    if (retval > 0) {
       /* one has already sent the intro. keep waiting. */
       tor_assert(introcirc);
       log_fn(LOG_INFO,"Intro circ %d present and awaiting ack (rend %d). Stalling. (stream %d sec old)",
@@ -839,16 +839,16 @@
 
     /* now rendcirc and introcirc are each either undefined or not finished */
 
-    if(rendcirc && introcirc && rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY) {
+    if (rendcirc && introcirc && rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY) {
       log_fn(LOG_INFO,"ready rend circ %d already here (no intro-ack yet on intro %d). (stream %d sec old)",
              rendcirc->n_circ_id, introcirc->n_circ_id, conn_age);
 
       tor_assert(introcirc->purpose == CIRCUIT_PURPOSE_C_INTRODUCING);
-      if(introcirc->state == CIRCUIT_STATE_OPEN) {
+      if (introcirc->state == CIRCUIT_STATE_OPEN) {
         log_fn(LOG_INFO,"found open intro circ %d (rend %d); sending introduction. (stream %d sec old)",
                introcirc->n_circ_id, rendcirc->n_circ_id, conn_age);
         /* XXX here we should cannibalize the rend circ if it's a zero service id */
-        if(rend_client_send_introduction(introcirc, rendcirc) < 0) {
+        if (rend_client_send_introduction(introcirc, rendcirc) < 0) {
           return -1;
         }
         rendcirc->timestamp_dirty = time(NULL);

Index: command.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/command.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -d -r1.75 -r1.76
--- command.c	26 Nov 2004 04:00:52 -0000	1.75
+++ command.c	28 Nov 2004 09:05:46 -0000	1.76
@@ -71,7 +71,7 @@
 
   time_t now = time(NULL);
 
-  if(now > current_second) { /* the second has rolled over */
+  if (now > current_second) { /* the second has rolled over */
     /* print stats */
     log(LOG_INFO,"At end of second: %d creates (%d ms), %d createds (%d ms), %d relays (%d ms), %d destroys (%d ms)",
       num_create, create_time/1000,
@@ -87,7 +87,7 @@
     current_second = now;
   }
 
-  switch(cell->command) {
+  switch (cell->command) {
     case CELL_PADDING:
       ++stats_n_padding_cells_processed;
       /* do nothing */
@@ -130,7 +130,7 @@
 static void command_process_create_cell(cell_t *cell, connection_t *conn) {
   circuit_t *circ;
 
-  if(we_are_hibernating()) {
+  if (we_are_hibernating()) {
     log_fn(LOG_INFO,"Received create cell but we're shutting down. Sending back destroy.");
     connection_send_destroy(cell->circ_id, conn);
     return;
@@ -138,7 +138,7 @@
 
   circ = circuit_get_by_circ_id_conn(cell->circ_id, conn);
 
-  if(circ) {
+  if (circ) {
     log_fn(LOG_WARN,"received CREATE cell (circID %d) for known circ. Dropping.", cell->circ_id);
     return;
   }
@@ -166,7 +166,7 @@
   memcpy(circ->onionskin, cell->payload, ONIONSKIN_CHALLENGE_LEN);
 
   /* hand it off to the cpuworkers, and then return */
-  if(assign_to_cpuworker(NULL, CPUWORKER_TASK_ONION, circ) < 0) {
+  if (assign_to_cpuworker(NULL, CPUWORKER_TASK_ONION, circ) < 0) {
     log_fn(LOG_WARN,"Failed to hand off onionskin. Closing.");
     circuit_mark_for_close(circ);
     return;
@@ -186,26 +186,26 @@
 
   circ = circuit_get_by_circ_id_conn(cell->circ_id, conn);
 
-  if(!circ) {
+  if (!circ) {
     log_fn(LOG_INFO,"(circID %d) unknown circ (probably got a destroy earlier). Dropping.", cell->circ_id);
     return;
   }
 
-  if(circ->n_circ_id != cell->circ_id) {
+  if (circ->n_circ_id != cell->circ_id) {
     log_fn(LOG_WARN,"got created cell from OPward? Closing.");
     circuit_mark_for_close(circ);
     return;
   }
 
-  if(CIRCUIT_IS_ORIGIN(circ)) { /* we're the OP. Handshake this. */
+  if (CIRCUIT_IS_ORIGIN(circ)) { /* we're the OP. Handshake this. */
     log_fn(LOG_DEBUG,"at OP. Finishing handshake.");
-    if(circuit_finish_handshake(circ, cell->payload) < 0) {
+    if (circuit_finish_handshake(circ, cell->payload) < 0) {
       log_fn(LOG_WARN,"circuit_finish_handshake failed.");
       circuit_mark_for_close(circ);
       return;
     }
     log_fn(LOG_DEBUG,"Moving to next skin.");
-    if(circuit_send_next_onion_skin(circ) < 0) {
+    if (circuit_send_next_onion_skin(circ) < 0) {
       log_fn(LOG_INFO,"circuit_send_next_onion_skin failed.");
       circuit_mark_for_close(circ); /* XXX push this circuit_close lower */
       return;
@@ -226,26 +226,26 @@
 
   circ = circuit_get_by_circ_id_conn(cell->circ_id, conn);
 
-  if(!circ) {
+  if (!circ) {
     log_fn(LOG_INFO,"unknown circuit %d on connection to %s:%d. Dropping.",
            cell->circ_id, conn->address, conn->port);
     return;
   }
 
-  if(circ->state == CIRCUIT_STATE_ONIONSKIN_PENDING) {
+  if (circ->state == CIRCUIT_STATE_ONIONSKIN_PENDING) {
     log_fn(LOG_WARN,"circuit in create_wait. Closing.");
     circuit_mark_for_close(circ);
     return;
   }
 
-  if(cell->circ_id == circ->p_circ_id) { /* it's an outgoing cell */
-    if(circuit_receive_relay_cell(cell, circ, CELL_DIRECTION_OUT) < 0) {
+  if (cell->circ_id == circ->p_circ_id) { /* it's an outgoing cell */
+    if (circuit_receive_relay_cell(cell, circ, CELL_DIRECTION_OUT) < 0) {
       log_fn(LOG_WARN,"circuit_receive_relay_cell (forward) failed. Closing.");
       circuit_mark_for_close(circ);
       return;
     }
   } else { /* it's an ingoing cell */
-    if(circuit_receive_relay_cell(cell, circ, CELL_DIRECTION_IN) < 0) {
+    if (circuit_receive_relay_cell(cell, circ, CELL_DIRECTION_IN) < 0) {
       log_fn(LOG_WARN,"circuit_receive_relay_cell (backward) failed. Closing.");
       circuit_mark_for_close(circ);
       return;
@@ -271,25 +271,25 @@
 
   circ = circuit_get_by_circ_id_conn(cell->circ_id, conn);
 
-  if(!circ) {
+  if (!circ) {
     log_fn(LOG_INFO,"unknown circuit %d on connection to %s:%d. Dropping.",
            cell->circ_id, conn->address, conn->port);
     return;
   }
 
   log_fn(LOG_INFO,"Received for circID %d.",cell->circ_id);
-  if(circ->state == CIRCUIT_STATE_ONIONSKIN_PENDING) {
+  if (circ->state == CIRCUIT_STATE_ONIONSKIN_PENDING) {
     onion_pending_remove(circ);
   }
 
-  if(cell->circ_id == circ->p_circ_id) {
+  if (cell->circ_id == circ->p_circ_id) {
     /* the destroy came from behind */
     circ->p_conn = NULL;
     circuit_mark_for_close(circ);
   } else { /* the destroy came from ahead */
     circ->n_conn = NULL;
 #if 0
-    if(!CIRCUIT_IS_ORIGIN(circ)) {
+    if (!CIRCUIT_IS_ORIGIN(circ)) {
       log_fn(LOG_DEBUG, "Delivering 'truncated' back.");
       connection_edge_send_command(NULL, circ, RELAY_COMMAND_TRUNCATED,
                                    NULL, 0, NULL);

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.269
retrieving revision 1.270
diff -u -d -r1.269 -r1.270
--- config.c	26 Nov 2004 04:00:52 -0000	1.269
+++ config.c	28 Nov 2004 09:05:46 -0000	1.270
@@ -253,8 +253,8 @@
   }
 
   /* Setuid/setgid as appropriate */
-  if(options->User || options->Group) {
-    if(switch_id(options->User, options->Group) != 0) {
+  if (options->User || options->Group) {
+    if (switch_id(options->User, options->Group) != 0) {
       return -1;
     }
   }
@@ -301,14 +301,14 @@
   }
 
   /* Finish backgrounding the process */
-  if(options->RunAsDaemon) {
+  if (options->RunAsDaemon) {
     /* We may be calling this for the n'th time (on SIGHUP), but it's safe. */
     finish_daemon();
   }
 
   /* Write our pid to the pid file. If we do not have write permissions we
    * will log a warning */
-  if(options->PidFile)
+  if (options->PidFile)
     write_pidfile(options->PidFile);
 
   /* Update address policies. */
@@ -331,7 +331,7 @@
   if (accounting_is_enabled(options))
     configure_accounting(time(NULL));
 
-  if(retry_all_listeners(1) < 0) {
+  if (retry_all_listeners(1) < 0) {
     log_fn(LOG_ERR,"Failed to bind one of the listener ports.");
     return -1;
   }
@@ -401,7 +401,7 @@
     new = tor_malloc(sizeof(struct config_line_t));
     s = argv[i];
 
-    while(*s == '-')
+    while (*s == '-')
       s++;
 
     new->key = tor_strdup(expand_abbrev(s, 1));
@@ -530,7 +530,7 @@
   }
 
   lvalue = ((char*)options) + var->var_offset;
-  switch(var->type) {
+  switch (var->type) {
 
   case CONFIG_TYPE_UINT:
     i = tor_parse_long(c->value, 10, 0, INT_MAX, &ok, NULL);
@@ -668,7 +668,7 @@
 
   result = tor_malloc_zero(sizeof(struct config_line_t));
   result->key = tor_strdup(var->name);
-  switch(var->type)
+  switch (var->type)
     {
     case CONFIG_TYPE_STRING:
       if (*(char**)value) {
@@ -970,7 +970,7 @@
 
   for (i=0; config_vars[i].name; ++i) {
     lvalue = ((char*)options) + config_vars[i].var_offset;
-    switch(config_vars[i].type) {
+    switch (config_vars[i].type) {
       case CONFIG_TYPE_MEMUNIT:
       case CONFIG_TYPE_INTERVAL:
       case CONFIG_TYPE_UINT:
@@ -1037,9 +1037,9 @@
 
   newopts = tor_malloc_zero(sizeof(or_options_t));
   for (i=0; config_vars[i].name; ++i) {
-    if(config_vars[i].type == CONFIG_TYPE_LINELIST_S)
+    if (config_vars[i].type == CONFIG_TYPE_LINELIST_S)
       continue;
-    if(config_vars[i].type == CONFIG_TYPE_OBSOLETE)
+    if (config_vars[i].type == CONFIG_TYPE_OBSOLETE)
       continue;
     line = config_get_assigned_option(old, config_vars[i].name);
     if (line) {
@@ -1064,7 +1064,7 @@
 
   for (i=0; config_vars[i].name; ++i) {
     var = &config_vars[i];
-    if(!var->initvalue)
+    if (!var->initvalue)
       continue; /* defaults to NULL or 0 */
     option_reset(options, var);
   }
@@ -1431,7 +1431,7 @@
 static int
 options_transition_allowed(or_options_t *old, or_options_t *new_val) {
 
-  if(!old)
+  if (!old)
     return 0;
 
   if (!opt_streq(old->PidFile, new_val->PidFile)) {
@@ -2105,7 +2105,7 @@
   return 0;
 #else
   const char *d = options->DataDirectory;
-  if(!d)
+  if (!d)
     d = "~/.tor";
 
  if (strncmp(d,"~/",2) == 0) {
@@ -2293,7 +2293,7 @@
     *ok = 1;
     return v;
   }
-  while(isspace(*cp))
+  while (isspace(*cp))
     ++cp;
   for ( ;u->unit;++u) {
     if (!strcasecmp(u->unit, cp)) {

Index: connection.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection.c,v
retrieving revision 1.300
retrieving revision 1.301
diff -u -d -r1.300 -r1.301
--- connection.c	28 Nov 2004 05:48:02 -0000	1.300
+++ connection.c	28 Nov 2004 09:05:46 -0000	1.301
@@ -118,7 +118,7 @@
   conn->poll_index = -1; /* also default to 'not used' */
 
   conn->type = type;
-  if(!connection_is_listener(conn)) { /* listeners never use their buf */
+  if (!connection_is_listener(conn)) { /* listeners never use their buf */
     conn->inbuf = buf_new();
     conn->outbuf = buf_new();
   }
@@ -143,14 +143,14 @@
   tor_assert(conn);
   tor_assert(conn->magic == CONNECTION_MAGIC);
 
-  if(!connection_is_listener(conn)) {
+  if (!connection_is_listener(conn)) {
     buf_free(conn->inbuf);
     buf_free(conn->outbuf);
   }
   tor_free(conn->address);
 
-  if(connection_speaks_cells(conn)) {
-    if(conn->state == OR_CONN_STATE_OPEN)
+  if (connection_speaks_cells(conn)) {
+    if (conn->state == OR_CONN_STATE_OPEN)
       directory_set_dirty();
     if (conn->tls)
       tor_tls_free(conn->tls);
@@ -161,7 +161,7 @@
   tor_free(conn->nickname);
   tor_free(conn->socks_request);
 
-  if(conn->s >= 0) {
+  if (conn->s >= 0) {
     log_fn(LOG_INFO,"closing fd %d.",conn->s);
     tor_close_socket(conn->s);
   }
@@ -178,7 +178,7 @@
   connection_t **carray;
 
   get_connection_array(&carray,&n);
-  for(i=0;i<n;i++)
+  for (i=0;i<n;i++)
     connection_free(carray[i]);
 }
 
@@ -196,20 +196,20 @@
 
   assert(conn->marked_for_close);
 
-  if(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT) {
-    if(!conn->has_sent_end)
+  if (conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT) {
+    if (!conn->has_sent_end)
       log_fn(LOG_WARN,"Edge connection hasn't sent end yet? Bug.");
   }
 
-  switch(conn->type) {
+  switch (conn->type) {
     case CONN_TYPE_DIR:
-      if(conn->purpose == DIR_PURPOSE_FETCH_RENDDESC)
+      if (conn->purpose == DIR_PURPOSE_FETCH_RENDDESC)
         rend_client_desc_fetched(conn->rend_query, 0);
       break;
     case CONN_TYPE_OR:
       /* Remember why we're closing this connection. */
       if (conn->state != OR_CONN_STATE_OPEN) {
-        if(connection_or_nonopen_was_started_here(conn)) {
+        if (connection_or_nonopen_was_started_here(conn)) {
           rep_hist_note_connect_failed(conn->identity_digest, time(NULL));
           control_event_or_conn_status(conn, OR_CONN_EVENT_FAILED);
         }
@@ -225,7 +225,7 @@
          */
         rep_hist_note_disconnect(conn->identity_digest, time(NULL));
         control_event_or_conn_status(conn, OR_CONN_EVENT_CLOSED);
-      } else if(conn->identity_digest) {
+      } else if (conn->identity_digest) {
         rep_hist_note_connection_died(conn->identity_digest, time(NULL));
         control_event_or_conn_status(conn, OR_CONN_EVENT_CLOSED);
       }
@@ -272,7 +272,7 @@
   }
   tor_close_socket(conn->s);
   conn->s = -1;
-  if(!connection_is_listener(conn)) {
+  if (!connection_is_listener(conn)) {
     buf_clear(conn->outbuf);
     conn->outbuf_flushlen = 0;
   }
@@ -365,13 +365,13 @@
 
   setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*) &one, sizeof(one));
 
-  if(bind(s,(struct sockaddr *)&bindaddr,sizeof(bindaddr)) < 0) {
+  if (bind(s,(struct sockaddr *)&bindaddr,sizeof(bindaddr)) < 0) {
     log_fn(LOG_WARN,"Could not bind to port %u: %s",usePort,
            tor_socket_strerror(tor_socket_errno(s)));
     return -1;
   }
 
-  if(listen(s,SOMAXCONN) < 0) {
+  if (listen(s,SOMAXCONN) < 0) {
     log_fn(LOG_WARN,"Could not listen on port %u: %s",usePort,
            tor_socket_strerror(tor_socket_errno(s)));
     return -1;
@@ -382,7 +382,7 @@
   conn = connection_new(type);
   conn->s = s;
 
-  if(connection_add(conn) < 0) { /* no space, forget it */
+  if (connection_add(conn) < 0) { /* no space, forget it */
     log_fn(LOG_WARN,"connection_add failed. Giving up.");
     connection_free(conn);
     return -1;
@@ -428,18 +428,18 @@
   set_socket_nonblocking(news);
 
   /* process entrance policies here, before we even create the connection */
-  if(new_type == CONN_TYPE_AP) {
+  if (new_type == CONN_TYPE_AP) {
     /* check sockspolicy to see if we should accept it */
-    if(socks_policy_permits_address(ntohl(remote.sin_addr.s_addr)) == 0) {
+    if (socks_policy_permits_address(ntohl(remote.sin_addr.s_addr)) == 0) {
       log_fn(LOG_WARN,"Denying socks connection from untrusted address %s.",
              inet_ntoa(remote.sin_addr));
       tor_close_socket(news);
       return 0;
     }
   }
-  if(new_type == CONN_TYPE_DIR) {
+  if (new_type == CONN_TYPE_DIR) {
     /* check dirpolicy to see if we should accept it */
-    if(dir_policy_permits_address(ntohl(remote.sin_addr.s_addr)) == 0) {
+    if (dir_policy_permits_address(ntohl(remote.sin_addr.s_addr)) == 0) {
       log_fn(LOG_WARN,"Denying dir connection from address %s.",
              inet_ntoa(remote.sin_addr));
       tor_close_socket(news);
@@ -454,12 +454,12 @@
   newconn->addr = ntohl(remote.sin_addr.s_addr);
   newconn->port = ntohs(remote.sin_port);
 
-  if(connection_add(newconn) < 0) { /* no space, forget it */
+  if (connection_add(newconn) < 0) { /* no space, forget it */
     connection_free(newconn);
     return 0; /* no need to tear down the parent */
   }
 
-  if(connection_init_accepted_conn(newconn) < 0) {
+  if (connection_init_accepted_conn(newconn) < 0) {
     connection_mark_for_close(newconn);
     return 0;
   }
@@ -473,7 +473,7 @@
 
   connection_start_reading(conn);
 
-  switch(conn->type) {
+  switch (conn->type) {
     case CONN_TYPE_OR:
       return connection_tls_start_handshake(conn, 1);
     case CONN_TYPE_AP:
@@ -520,7 +520,7 @@
       log_fn(LOG_WARN,"Outbound bind address '%s' didn't parse. Ignoring.",
              options->OutboundBindAddress);
     } else {
-      if(bind(s, (struct sockaddr*)&ext_addr, sizeof(ext_addr)) < 0) {
+      if (bind(s, (struct sockaddr*)&ext_addr, sizeof(ext_addr)) < 0) {
         log_fn(LOG_WARN,"Error binding network socket: %s",
                tor_socket_strerror(tor_socket_errno(s)));
         return -1;
@@ -537,9 +537,9 @@
 
   log_fn(LOG_DEBUG,"Connecting to %s:%u.",address,port);
 
-  if(connect(s,(struct sockaddr *)&dest_addr,sizeof(dest_addr)) < 0) {
+  if (connect(s,(struct sockaddr *)&dest_addr,sizeof(dest_addr)) < 0) {
     int e = tor_socket_errno(s);
-    if(!ERRNO_IS_CONN_EINPROGRESS(e)) {
+    if (!ERRNO_IS_CONN_EINPROGRESS(e)) {
       /* yuck. kill it. */
       log_fn(LOG_INFO,"Connect() to %s:%u failed: %s",address,port,
              tor_socket_strerror(e));
@@ -548,7 +548,7 @@
     } else {
       /* it's in progress. set state appropriately and return. */
       conn->s = s;
-      if(connection_add(conn) < 0) /* no space, forget it */
+      if (connection_add(conn) < 0) /* no space, forget it */
         return -1;
       log_fn(LOG_DEBUG,"connect in progress, socket %d.",s);
       return 0;
@@ -558,7 +558,7 @@
   /* it succeeded. we're connected. */
   log_fn(LOG_INFO,"Connection to %s:%u established.",address,port);
   conn->s = s;
-  if(connection_add(conn) < 0) /* no space, forget it */
+  if (connection_add(conn) < 0) /* no space, forget it */
     return -1;
   return 1;
 }
@@ -575,7 +575,7 @@
              type == CONN_TYPE_DIR_LISTENER ||
              type == CONN_TYPE_CONTROL_LISTENER);
   get_connection_array(&carray,&n);
-  for(i=0;i<n;i++) {
+  for (i=0;i<n;i++) {
     conn = carray[i];
     if (conn->type == type && !conn->marked_for_close) {
       connection_close_immediate(conn);
@@ -618,7 +618,7 @@
     /* How many are there actually? */
     have = 0;
     get_connection_array(&carray,&n_conn);
-    for(i=0;i<n_conn;i++) {
+    for (i=0;i<n_conn;i++) {
       conn = carray[i];
       if (conn->type == type && !conn->marked_for_close)
         ++have;
@@ -681,17 +681,17 @@
   int at_most;
 
   /* do a rudimentary round-robin so one circuit can't hog a connection */
-  if(connection_speaks_cells(conn)) {
+  if (connection_speaks_cells(conn)) {
     at_most = 32*(CELL_NETWORK_SIZE);
   } else {
     at_most = 32*(RELAY_PAYLOAD_SIZE);
   }
 
-  if(at_most > global_read_bucket)
+  if (at_most > global_read_bucket)
     at_most = global_read_bucket;
 
-  if(connection_speaks_cells(conn) && conn->state == OR_CONN_STATE_OPEN)
-    if(at_most > conn->receiver_bucket)
+  if (connection_speaks_cells(conn) && conn->state == OR_CONN_STATE_OPEN)
+    if (at_most > conn->receiver_bucket)
       at_most = conn->receiver_bucket;
 
   return at_most;
@@ -700,19 +700,19 @@
 /** We just read num_read onto conn. Decrement buckets appropriately. */
 static void connection_read_bucket_decrement(connection_t *conn, int num_read) {
   global_read_bucket -= num_read; tor_assert(global_read_bucket >= 0);
-  if(connection_speaks_cells(conn) && conn->state == OR_CONN_STATE_OPEN) {
+  if (connection_speaks_cells(conn) && conn->state == OR_CONN_STATE_OPEN) {
     conn->receiver_bucket -= num_read; tor_assert(conn->receiver_bucket >= 0);
   }
 }
 
 static void connection_consider_empty_buckets(connection_t *conn) {
-  if(global_read_bucket == 0) {
+  if (global_read_bucket == 0) {
     log_fn(LOG_DEBUG,"global bucket exhausted. Pausing.");
     conn->wants_to_read = 1;
     connection_stop_reading(conn);
     return;
   }
-  if(connection_speaks_cells(conn) &&
+  if (connection_speaks_cells(conn) &&
      conn->state == OR_CONN_STATE_OPEN &&
      conn->receiver_bucket == 0) {
       log_fn(LOG_DEBUG,"receiver bucket exhausted. Pausing.");
@@ -737,26 +737,26 @@
   or_options_t *options = get_options();
 
   /* refill the global buckets */
-  if((unsigned)global_read_bucket < options->BandwidthBurst) {
+  if ((unsigned)global_read_bucket < options->BandwidthBurst) {
     global_read_bucket += (int)options->BandwidthRate;
     log_fn(LOG_DEBUG,"global_read_bucket now %d.", global_read_bucket);
   }
-  if((unsigned)global_write_bucket < options->BandwidthBurst) {
+  if ((unsigned)global_write_bucket < options->BandwidthBurst) {
     global_write_bucket += (int)options->BandwidthRate;
     log_fn(LOG_DEBUG,"global_write_bucket now %d.", global_write_bucket);
   }
 
   /* refill the per-connection buckets */
   get_connection_array(&carray,&n);
-  for(i=0;i<n;i++) {
+  for (i=0;i<n;i++) {
     conn = carray[i];
 
-    if(connection_receiver_bucket_should_increase(conn)) {
+    if (connection_receiver_bucket_should_increase(conn)) {
       conn->receiver_bucket += conn->bandwidth;
       //log_fn(LOG_DEBUG,"Receiver bucket %d now %d.", i, conn->receiver_bucket);
     }
 
-    if(conn->wants_to_read == 1 /* it's marked to turn reading back on now */
+    if (conn->wants_to_read == 1 /* it's marked to turn reading back on now */
        && global_read_bucket > 0 /* and we're allowed to read */
        && global_write_bucket > 0 /* and we're allowed to write (XXXX,
                                    * not the best place to check this.) */
@@ -767,7 +767,7 @@
       log_fn(LOG_DEBUG,"waking up conn (fd %d)",conn->s);
       conn->wants_to_read = 0;
       connection_start_reading(conn);
-      if(conn->wants_to_write == 1) {
+      if (conn->wants_to_write == 1) {
         conn->wants_to_write = 0;
         connection_start_writing(conn);
       }
@@ -781,13 +781,13 @@
 static int connection_receiver_bucket_should_increase(connection_t *conn) {
   tor_assert(conn);
 
-  if(!connection_speaks_cells(conn))
+  if (!connection_speaks_cells(conn))
     return 0; /* edge connections don't use receiver_buckets */
-  if(conn->state != OR_CONN_STATE_OPEN)
+  if (conn->state != OR_CONN_STATE_OPEN)
     return 0; /* only open connections play the rate limiting game */
 
   tor_assert(conn->bandwidth > 0);
-  if(conn->receiver_bucket > 9*conn->bandwidth)
+  if (conn->receiver_bucket > 9*conn->bandwidth)
     return 0;
 
   return 1;
@@ -810,7 +810,7 @@
 
   conn->timestamp_lastread = time(NULL);
 
-  switch(conn->type) {
+  switch (conn->type) {
     case CONN_TYPE_OR_LISTENER:
       return connection_handle_listener_read(conn, CONN_TYPE_OR);
     case CONN_TYPE_AP_LISTENER:
@@ -838,7 +838,7 @@
        /* it's a directory server and connecting failed: forget about this router */
        /* XXX I suspect pollerr may make Windows not get to this point. :( */
        router_mark_as_down(conn->identity_digest);
-       if(conn->purpose == DIR_PURPOSE_FETCH_DIR &&
+       if (conn->purpose == DIR_PURPOSE_FETCH_DIR &&
           !all_trusted_directory_servers_down()) {
          log_fn(LOG_INFO,"Giving up on dirserver %s; trying another.", conn->address);
          directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL);
@@ -883,13 +883,13 @@
 static int connection_read_to_buf(connection_t *conn, int *max_to_read) {
   int result, at_most = *max_to_read;
 
-  if(at_most == -1) { /* we need to initialize it */
+  if (at_most == -1) { /* we need to initialize it */
     /* how many bytes are we allowed to read? */
     at_most = connection_bucket_read_limit(conn);
   }
 
-  if(connection_speaks_cells(conn) && conn->state != OR_CONN_STATE_CONNECTING) {
-    if(conn->state == OR_CONN_STATE_HANDSHAKING) {
+  if (connection_speaks_cells(conn) && conn->state != OR_CONN_STATE_CONNECTING) {
+    if (conn->state == OR_CONN_STATE_HANDSHAKING) {
       /* continue handshaking even if global token bucket is empty */
       return connection_tls_continue_handshake(conn);
     }
@@ -900,7 +900,7 @@
     /* else open, or closing */
     result = read_to_buf_tls(conn->tls, at_most, conn->inbuf);
 
-    switch(result) {
+    switch (result) {
       case TOR_TLS_CLOSE:
         log_fn(LOG_INFO,"TLS connection closed on read. Closing. (Nickname %s, address %s",
                conn->nickname ? conn->nickname : "not set", conn->address);
@@ -923,7 +923,7 @@
 
 //  log(LOG_DEBUG,"connection_read_to_buf(): read_to_buf returned %d.",read_result);
 
-    if(result < 0)
+    if (result < 0)
       return -1;
   }
 
@@ -994,9 +994,9 @@
       connection_mark_for_close(conn);
       return -1;
     }
-    if(e) {
+    if (e) {
       /* some sort of error, but maybe just inprogress still */
-      if(!ERRNO_IS_CONN_EINPROGRESS(e)) {
+      if (!ERRNO_IS_CONN_EINPROGRESS(e)) {
         log_fn(LOG_INFO,"in-progress connect failed. Removing.");
         connection_close_immediate(conn);
         connection_mark_for_close(conn);
@@ -1017,7 +1017,7 @@
   if (connection_speaks_cells(conn)) {
     if (conn->state == OR_CONN_STATE_HANDSHAKING) {
       connection_stop_writing(conn);
-      if(connection_tls_continue_handshake(conn) < 0) {
+      if (connection_tls_continue_handshake(conn) < 0) {
         connection_close_immediate(conn); /* Don't flush; connection is dead. */
         connection_mark_for_close(conn);
         return -1;
@@ -1027,7 +1027,7 @@
 
     /* else open, or closing */
     result = flush_buf_tls(conn->tls, conn->outbuf, &conn->outbuf_flushlen);
-    switch(result) {
+    switch (result) {
       case TOR_TLS_ERROR:
       case TOR_TLS_CLOSE:
         log_fn(LOG_INFO,result==TOR_TLS_ERROR?
@@ -1042,7 +1042,7 @@
       case TOR_TLS_WANTREAD:
         /* Make sure to avoid a loop if the receive buckets are empty. */
         log_fn(LOG_DEBUG,"wanted read.");
-        if(!connection_is_reading(conn)) {
+        if (!connection_is_reading(conn)) {
           connection_stop_writing(conn);
           conn->wants_to_write = 1;
           /* we'll start reading again when the next second arrives,
@@ -1066,13 +1066,13 @@
     }
   }
 
-  if(result > 0 && !is_local_IP(conn->addr)) { /* remember it */
+  if (result > 0 && !is_local_IP(conn->addr)) { /* remember it */
     rep_hist_note_bytes_written(result, now);
     global_write_bucket -= result;
   }
 
-  if(!connection_wants_to_flush(conn)) { /* it's done flushing */
-    if(connection_finished_flushing(conn) < 0) {
+  if (!connection_wants_to_flush(conn)) { /* it's done flushing */
+    if (connection_finished_flushing(conn) < 0) {
       /* already marked */
       return -1;
     }
@@ -1086,11 +1086,11 @@
  */
 void connection_write_to_buf(const char *string, size_t len, connection_t *conn) {
 
-  if(!len || conn->marked_for_close)
+  if (!len || conn->marked_for_close)
     return;
 
-  if(write_to_buf(string, len, conn->outbuf) < 0) {
-    if(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT) {
+  if (write_to_buf(string, len, conn->outbuf) < 0) {
+    if (conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT) {
       /* if it failed, it means we have our package/delivery windows set
          wrong compared to our max outbuf size. close the whole circuit. */
       log_fn(LOG_WARN,"write_to_buf failed. Closing circuit (fd %d).", conn->s);
@@ -1114,9 +1114,9 @@
   connection_t **carray;
 
   get_connection_array(&carray,&n);
-  for(i=0;i<n;i++) {
+  for (i=0;i<n;i++) {
     conn = carray[i];
-    if(conn->addr == addr && conn->port == port && !conn->marked_for_close &&
+    if (conn->addr == addr && conn->port == port && !conn->marked_for_close &&
        (!best || best->timestamp_created < conn->timestamp_created))
       best = conn;
   }
@@ -1130,7 +1130,7 @@
   connection_t **carray;
 
   get_connection_array(&carray,&n);
-  for(i=0;i<n;i++) {
+  for (i=0;i<n;i++) {
     conn = carray[i];
     if (conn->type != type)
       continue;
@@ -1151,9 +1151,9 @@
   connection_t **carray;
 
   get_connection_array(&carray,&n);
-  for(i=0;i<n;i++) {
+  for (i=0;i<n;i++) {
     conn = carray[i];
-    if(conn->type == type && !conn->marked_for_close)
+    if (conn->type == type && !conn->marked_for_close)
       return conn;
   }
   return NULL;
@@ -1168,9 +1168,9 @@
   connection_t **carray;
 
   get_connection_array(&carray,&n);
-  for(i=0;i<n;i++) {
+  for (i=0;i<n;i++) {
     conn = carray[i];
-    if(conn->type == type && conn->state == state && !conn->marked_for_close)
+    if (conn->type == type && conn->state == state && !conn->marked_for_close)
       return conn;
   }
   return NULL;
@@ -1186,10 +1186,10 @@
   connection_t **carray;
 
   get_connection_array(&carray,&n);
-  for(i=0;i<n;i++) {
+  for (i=0;i<n;i++) {
     conn = carray[i];
-    if(conn->type == type && conn->state == state && !conn->marked_for_close)
-      if(!best || conn->timestamp_lastwritten < best->timestamp_lastwritten)
+    if (conn->type == type && conn->state == state && !conn->marked_for_close)
+      if (!best || conn->timestamp_lastwritten < best->timestamp_lastwritten)
         best = conn;
   }
   return best;
@@ -1204,9 +1204,9 @@
   connection_t **carray;
 
   get_connection_array(&carray,&n);
-  for(i=0;i<n;i++) {
+  for (i=0;i<n;i++) {
     conn = carray[i];
-    if(conn->type == type &&
+    if (conn->type == type &&
        !conn->marked_for_close &&
        !rend_cmp_service_ids(rendquery, conn->rend_query))
       return conn;
@@ -1216,7 +1216,7 @@
 
 /** Return 1 if <b>conn</b> is a listener conn, else return 0. */
 int connection_is_listener(connection_t *conn) {
-  if(conn->type == CONN_TYPE_OR_LISTENER ||
+  if (conn->type == CONN_TYPE_OR_LISTENER ||
      conn->type == CONN_TYPE_AP_LISTENER ||
      conn->type == CONN_TYPE_DIR_LISTENER ||
      conn->type == CONN_TYPE_CONTROL_LISTENER)
@@ -1230,10 +1230,10 @@
 int connection_state_is_open(connection_t *conn) {
   tor_assert(conn);
 
-  if(conn->marked_for_close)
+  if (conn->marked_for_close)
     return 0;
 
-  if((conn->type == CONN_TYPE_OR && conn->state == OR_CONN_STATE_OPEN) ||
+  if ((conn->type == CONN_TYPE_OR && conn->state == OR_CONN_STATE_OPEN) ||
      (conn->type == CONN_TYPE_AP && conn->state == AP_CONN_STATE_OPEN) ||
      (conn->type == CONN_TYPE_EXIT && conn->state == EXIT_CONN_STATE_OPEN) ||
      (conn->type == CONN_TYPE_CONTROL && conn->state ==CONTROL_CONN_STATE_OPEN))
@@ -1290,7 +1290,7 @@
 
   tor_assert(conn);
 
-  switch(conn->type) {
+  switch (conn->type) {
     case CONN_TYPE_OR:
       return connection_or_process_inbuf(conn);
     case CONN_TYPE_EXIT:
@@ -1322,7 +1322,7 @@
 
 //  log_fn(LOG_DEBUG,"entered. Socket %u.", conn->s);
 
-  switch(conn->type) {
+  switch (conn->type) {
     case CONN_TYPE_OR:
       return connection_or_finished_flushing(conn);
     case CONN_TYPE_AP:
@@ -1397,11 +1397,11 @@
   tor_assert(conn->type >= _CONN_TYPE_MIN);
   tor_assert(conn->type <= _CONN_TYPE_MAX);
 
-  if(conn->outbuf_flushlen > 0) {
+  if (conn->outbuf_flushlen > 0) {
     tor_assert(connection_is_writing(conn) || conn->wants_to_write);
   }
 
-  if(conn->hold_open_until_flushed)
+  if (conn->hold_open_until_flushed)
     tor_assert(conn->marked_for_close);
 
   /* XXX check: wants_to_read, wants_to_write, s, poll_index,
@@ -1422,7 +1422,7 @@
 
   /* XXX Fix this; no longer so.*/
 #if 0
-  if(conn->type != CONN_TYPE_OR && conn->type != CONN_TYPE_DIR)
+  if (conn->type != CONN_TYPE_OR && conn->type != CONN_TYPE_DIR)
     tor_assert(!conn->pkey);
   /* pkey is set if we're a dir client, or if we're an OR in state OPEN
    * connected to another OR.
@@ -1432,7 +1432,7 @@
   if (conn->type != CONN_TYPE_OR) {
     tor_assert(!conn->tls);
   } else {
-    if(conn->state == OR_CONN_STATE_OPEN) {
+    if (conn->state == OR_CONN_STATE_OPEN) {
       /* tor_assert(conn->bandwidth > 0); */
       /* the above isn't necessarily true: if we just did a TLS
        * handshake but we didn't recognize the other peer, or it
@@ -1471,11 +1471,11 @@
   if (conn->type == CONN_TYPE_EXIT) {
     tor_assert(conn->purpose == EXIT_PURPOSE_CONNECT ||
                conn->purpose == EXIT_PURPOSE_RESOLVE);
-  } else if(conn->type != CONN_TYPE_DIR) {
+  } else if (conn->type != CONN_TYPE_DIR) {
     tor_assert(!conn->purpose); /* only used for dir types currently */
   }
 
-  switch(conn->type)
+  switch (conn->type)
     {
     case CONN_TYPE_OR_LISTENER:
     case CONN_TYPE_AP_LISTENER:

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.242
retrieving revision 1.243
diff -u -d -r1.242 -r1.243
--- connection_edge.c	26 Nov 2004 04:00:53 -0000	1.242
+++ connection_edge.c	28 Nov 2004 09:05:46 -0000	1.243
@@ -34,13 +34,13 @@
   }
   return 0;
 #else
-  if(buf_datalen(conn->inbuf)) {
+  if (buf_datalen(conn->inbuf)) {
     /* it still has stuff to process. don't let it die yet. */
     return 0;
   }
   log_fn(LOG_INFO,"conn (fd %d) reached eof (stream size %d). Closing.", conn->s, (int)conn->stream_size);
   connection_edge_end(conn, END_STREAM_REASON_DONE, conn->cpath_layer);
-  if(!conn->marked_for_close) {
+  if (!conn->marked_for_close) {
     /* only mark it if not already marked. it's possible to
      * get the 'end' right around when the client hangs up on us. */
     connection_mark_for_close(conn);
@@ -65,9 +65,9 @@
   tor_assert(conn);
   tor_assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT);
 
-  switch(conn->state) {
+  switch (conn->state) {
     case AP_CONN_STATE_SOCKS_WAIT:
-      if(connection_ap_handshake_process_socks(conn) < 0) {
+      if (connection_ap_handshake_process_socks(conn) < 0) {
         conn->has_sent_end = 1; /* no circ yet */
         connection_mark_for_close(conn);
         conn->hold_open_until_flushed = 1;
@@ -76,12 +76,12 @@
       return 0;
     case AP_CONN_STATE_OPEN:
     case EXIT_CONN_STATE_OPEN:
-      if(conn->package_window <= 0) {
+      if (conn->package_window <= 0) {
         /* XXX this is still getting called rarely :( */
         log_fn(LOG_WARN,"called with package_window %d. Tell Roger.", conn->package_window);
         return 0;
       }
-      if(connection_edge_package_raw_inbuf(conn, package_partial) < 0) {
+      if (connection_edge_package_raw_inbuf(conn, package_partial) < 0) {
         connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
         connection_mark_for_close(conn);
         return -1;
@@ -108,7 +108,7 @@
 int connection_edge_destroy(uint16_t circ_id, connection_t *conn) {
   tor_assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT);
 
-  if(conn->marked_for_close)
+  if (conn->marked_for_close)
     return 0; /* already marked; probably got an 'end' */
   log_fn(LOG_INFO,"CircID %d: At an edge. Marking connection for close.",
          circ_id);
@@ -133,13 +133,13 @@
   size_t payload_len=1;
   circuit_t *circ;
 
-  if(conn->has_sent_end) {
+  if (conn->has_sent_end) {
     log_fn(LOG_WARN,"It appears I've already sent the end. Are you calling me twice?");
     return -1;
   }
 
   payload[0] = reason;
-  if(reason == END_STREAM_REASON_EXITPOLICY) {
+  if (reason == END_STREAM_REASON_EXITPOLICY) {
     /* this is safe even for rend circs, because they never fail
      * because of exitpolicy */
     set_uint32(payload+1, htonl(conn->addr));
@@ -147,7 +147,7 @@
   }
 
   circ = circuit_get_by_conn(conn);
-  if(circ && !circ->marked_for_close) {
+  if (circ && !circ->marked_for_close) {
     log_fn(LOG_DEBUG,"Marking conn (fd %d) and sending end.",conn->s);
     connection_edge_send_command(conn, circ, RELAY_COMMAND_END,
                                  payload, payload_len, cpath_layer);
@@ -173,7 +173,7 @@
   tor_assert(conn);
   tor_assert(conn->type == CONN_TYPE_AP || conn->type == CONN_TYPE_EXIT);
 
-  switch(conn->state) {
+  switch (conn->state) {
     case AP_CONN_STATE_OPEN:
     case EXIT_CONN_STATE_OPEN:
       connection_stop_writing(conn);
@@ -208,16 +208,16 @@
 
   conn->state = EXIT_CONN_STATE_OPEN;
   connection_watch_events(conn, POLLIN); /* stop writing, continue reading */
-  if(connection_wants_to_flush(conn)) /* in case there are any queued relay cells */
+  if (connection_wants_to_flush(conn)) /* in case there are any queued relay cells */
     connection_start_writing(conn);
   /* deliver a 'connected' relay cell back through the circuit. */
-  if(connection_edge_is_rendezvous_stream(conn)) {
-    if(connection_edge_send_command(conn, circuit_get_by_conn(conn),
+  if (connection_edge_is_rendezvous_stream(conn)) {
+    if (connection_edge_send_command(conn, circuit_get_by_conn(conn),
                                     RELAY_COMMAND_CONNECTED, NULL, 0, conn->cpath_layer) < 0)
       return 0; /* circuit is closed, don't continue */
   } else {
     *(uint32_t*)connected_payload = htonl(conn->addr);
-    if(connection_edge_send_command(conn, circuit_get_by_conn(conn),
+    if (connection_edge_send_command(conn, circuit_get_by_conn(conn),
          RELAY_COMMAND_CONNECTED, connected_payload, 4, conn->cpath_layer) < 0)
       return 0; /* circuit is closed, don't continue */
   }
@@ -260,12 +260,12 @@
       continue;
     conn->num_retries++;
     circ = circuit_get_by_conn(conn);
-    if(!circ) { /* it's vanished? */
+    if (!circ) { /* it's vanished? */
       log_fn(LOG_INFO,"Conn is in connect-wait, but lost its circ.");
       connection_mark_for_close(conn);
       continue;
     }
-    if(circ->purpose == CIRCUIT_PURPOSE_C_REND_JOINED) {
+    if (circ->purpose == CIRCUIT_PURPOSE_C_REND_JOINED) {
       if (now - conn->timestamp_lastread > 45) {
         log_fn(LOG_WARN,"Rend stream is %d seconds late. Giving up.",
                (int)(now - conn->timestamp_lastread));
@@ -275,7 +275,7 @@
       continue;
     }
     tor_assert(circ->purpose == CIRCUIT_PURPOSE_C_GENERAL);
-    if(conn->num_retries >= MAX_STREAM_RETRIES) {
+    if (conn->num_retries >= MAX_STREAM_RETRIES) {
       log_fn(LOG_WARN,"Stream is %d seconds late. Giving up.",
              15*conn->num_retries);
       circuit_log_path(LOG_WARN, circ);
@@ -300,7 +300,7 @@
       /* give our stream another 15 seconds to try */
       conn->timestamp_lastread += 15;
       /* attaching to a dirty circuit is fine */
-      if(connection_ap_handshake_attach_circuit(conn)<0) {
+      if (connection_ap_handshake_attach_circuit(conn)<0) {
         /* it will never work */
         /* Don't need to send end -- we're not connected */
         conn->has_sent_end = 1;
@@ -327,7 +327,7 @@
         conn->type != CONN_TYPE_AP ||
         conn->state != AP_CONN_STATE_CIRCUIT_WAIT)
       continue;
-    if(connection_ap_handshake_attach_circuit(conn) < 0) {
+    if (connection_ap_handshake_attach_circuit(conn) < 0) {
       /* -1 means it will never work */
       /* Don't send end; there is no 'other side' yet */
       conn->has_sent_end = 1;
@@ -362,12 +362,12 @@
   log_fn(LOG_DEBUG,"entered.");
 
   sockshere = fetch_from_buf_socks(conn->inbuf, socks);
-  if(sockshere == -1 || sockshere == 0) {
-    if(socks->replylen) { /* we should send reply back */
+  if (sockshere == -1 || sockshere == 0) {
+    if (socks->replylen) { /* we should send reply back */
       log_fn(LOG_DEBUG,"reply is already set for us. Using it.");
       connection_ap_handshake_socks_reply(conn, socks->reply, socks->replylen, 0);
       socks->replylen = 0; /* zero it out so we can do another round of negotiation */
-    } else if(sockshere == -1) { /* send normal reject */
+    } else if (sockshere == -1) { /* send normal reject */
       log_fn(LOG_WARN,"Fetching socks handshake failed. Closing.");
       connection_ap_handshake_socks_reply(conn, NULL, 0, -1);
     } else {
@@ -423,19 +423,19 @@
     log_fn(LOG_INFO,"Got a hidden service request for ID '%s'", conn->rend_query);
     /* see if we already have it cached */
     r = rend_cache_lookup_entry(conn->rend_query, &entry);
-    if(r<0) {
+    if (r<0) {
       log_fn(LOG_WARN,"Invalid service descriptor %s", conn->rend_query);
       return -1;
     }
-    if(r==0) {
+    if (r==0) {
       conn->state = AP_CONN_STATE_RENDDESC_WAIT;
       log_fn(LOG_INFO, "Unknown descriptor %s. Fetching.", conn->rend_query);
       rend_client_refetch_renddesc(conn->rend_query);
       return 0;
     }
-    if(r>0) {
+    if (r>0) {
 #define NUM_SECONDS_BEFORE_REFETCH (60*15)
-      if(time(NULL) - entry->received < NUM_SECONDS_BEFORE_REFETCH) {
+      if (time(NULL) - entry->received < NUM_SECONDS_BEFORE_REFETCH) {
         conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
         log_fn(LOG_INFO, "Descriptor is here and fresh enough. Great.");
         return connection_ap_handshake_attach_circuit(conn);
@@ -460,15 +460,15 @@
 
 again:
   test_stream_id = circ->next_stream_id++;
-  if(++attempts > 1<<16) {
+  if (++attempts > 1<<16) {
     /* Make sure we don't loop forever if all stream_id's are used. */
     log_fn(LOG_WARN,"No unused stream IDs. Failing.");
     return 0;
   }
   if (test_stream_id == 0)
     goto again;
-  for(tmpconn = circ->p_streams; tmpconn; tmpconn=tmpconn->next_stream)
-    if(tmpconn->stream_id == test_stream_id)
+  for (tmpconn = circ->p_streams; tmpconn; tmpconn=tmpconn->next_stream)
+    if (tmpconn->stream_id == test_stream_id)
       goto again;
   return test_stream_id;
 }
@@ -498,7 +498,7 @@
     return -1;
   }
 
-  if(circ->purpose == CIRCUIT_PURPOSE_C_GENERAL) {
+  if (circ->purpose == CIRCUIT_PURPOSE_C_GENERAL) {
     in.s_addr = htonl(client_dns_lookup_entry(ap_conn->socks_request->address));
     string_addr = in.s_addr ? inet_ntoa(in) : NULL;
 
@@ -514,7 +514,7 @@
 
   log_fn(LOG_DEBUG,"Sending relay cell to begin stream %d.",ap_conn->stream_id);
 
-  if(connection_edge_send_command(ap_conn, circ, RELAY_COMMAND_BEGIN,
+  if (connection_edge_send_command(ap_conn, circ, RELAY_COMMAND_BEGIN,
                                payload, payload_len, ap_conn->cpath_layer) < 0)
     return -1; /* circuit is closed, don't continue */
 
@@ -557,7 +557,7 @@
 
   log_fn(LOG_DEBUG,"Sending relay cell to begin stream %d.",ap_conn->stream_id);
 
-  if(connection_edge_send_command(ap_conn, circ, RELAY_COMMAND_RESOLVE,
+  if (connection_edge_send_command(ap_conn, circ, RELAY_COMMAND_RESOLVE,
                            string_addr, payload_len, ap_conn->cpath_layer) < 0)
     return -1; /* circuit is closed, don't continue */
 
@@ -579,7 +579,7 @@
 
   log_fn(LOG_INFO,"Making AP bridge to %s:%d ...",address,port);
 
-  if(tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
+  if (tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
     log(LOG_WARN,"Couldn't construct socketpair (%s). Network down? Delaying.",
         tor_socket_strerror(tor_socket_errno(-1)));
     return -1;
@@ -605,7 +605,7 @@
   conn->addr = 0;
   conn->port = 0;
 
-  if(connection_add(conn) < 0) { /* no space, forget it */
+  if (connection_add(conn) < 0) { /* no space, forget it */
     connection_free(conn); /* this closes fd[0] */
     tor_close_socket(fd[1]);
     return -1;
@@ -637,7 +637,7 @@
 
   if (answer_type == RESOLVED_TYPE_IPV4) {
     uint32_t a = get_uint32(answer);
-    if(a)
+    if (a)
       client_dns_set_entry(conn->socks_request->address, ntohl(a));
   }
 
@@ -696,17 +696,17 @@
                                          size_t replylen, int status) {
   char buf[256];
 
-  if(status) /* it's either 1 or -1 */
+  if (status) /* it's either 1 or -1 */
     control_event_stream_status(conn,
                        status==1 ? STREAM_EVENT_SUCCEEDED : STREAM_EVENT_FAILED);
 
-  if(replylen) { /* we already have a reply in mind */
+  if (replylen) { /* we already have a reply in mind */
     connection_write_to_buf(reply, replylen, conn);
     return;
   }
   tor_assert(conn->socks_request);
   tor_assert(status == 1 || status == -1);
-  if(conn->socks_request->socks_version == 4) {
+  if (conn->socks_request->socks_version == 4) {
     memset(buf,0,SOCKS4_NETWORK_LEN);
 #define SOCKS4_GRANTED          90
 #define SOCKS4_REJECT           91
@@ -714,7 +714,7 @@
     /* leave version, destport, destip zero */
     connection_write_to_buf(buf, SOCKS4_NETWORK_LEN, conn);
   }
-  if(conn->socks_request->socks_version == 5) {
+  if (conn->socks_request->socks_version == 5) {
     buf[0] = 5; /* version 5 */
 #define SOCKS5_SUCCESS          0
 #define SOCKS5_GENERIC_ERROR    1
@@ -759,7 +759,7 @@
    * begin because it's malformed.
    */
 
-  if(!memchr(cell->payload+RELAY_HEADER_SIZE, 0, rh.length)) {
+  if (!memchr(cell->payload+RELAY_HEADER_SIZE, 0, rh.length)) {
     log_fn(LOG_WARN,"relay begin cell has no \\0. Dropping.");
     return 0;
   }
@@ -783,7 +783,7 @@
   n_stream->package_window = STREAMWINDOW_START;
   n_stream->deliver_window = STREAMWINDOW_START;
 
-  if(circ->purpose == CIRCUIT_PURPOSE_S_REND_JOINED) {
+  if (circ->purpose == CIRCUIT_PURPOSE_S_REND_JOINED) {
     log_fn(LOG_DEBUG,"begin is for rendezvous. configuring stream.");
     n_stream->address = tor_strdup("(rendezvous)");
     n_stream->state = EXIT_CONN_STATE_CONNECTING;
@@ -791,7 +791,7 @@
             sizeof(n_stream->rend_query));
     tor_assert(connection_edge_is_rendezvous_stream(n_stream));
     assert_circuit_ok(circ);
-    if(rend_service_set_connection_addr_port(n_stream, circ) < 0) {
+    if (rend_service_set_connection_addr_port(n_stream, circ) < 0) {
       log_fn(LOG_INFO,"Didn't find rendezvous service (port %d)",n_stream->port);
       connection_edge_end(n_stream, END_STREAM_REASON_EXITPOLICY, n_stream->cpath_layer);
       connection_free(n_stream);
@@ -816,13 +816,13 @@
   n_stream->state = EXIT_CONN_STATE_RESOLVEFAILED;
   /* default to failed, change in dns_resolve if it turns out not to fail */
 
-  if(we_are_hibernating()) {
+  if (we_are_hibernating()) {
     connection_edge_end(n_stream, END_STREAM_REASON_EXITPOLICY, n_stream->cpath_layer);
     connection_free(n_stream);
   }
 
   /* send it off to the gethostbyname farm */
-  switch(dns_resolve(n_stream)) {
+  switch (dns_resolve(n_stream)) {
     case 1: /* resolve worked */
 
       /* add it into the linked list of n_streams on this circuit */
@@ -877,7 +877,7 @@
   circ->resolving_streams = dummy_conn;
 
   /* send it off to the gethostbyname farm */
-  switch(dns_resolve(dummy_conn)) {
+  switch (dns_resolve(dummy_conn)) {
     case 1: /* The result was cached; a resolved cell was sent. */
     case -1:
       circuit_detach_stream(circuit_get_by_conn(dummy_conn), dummy_conn);
@@ -933,7 +933,7 @@
   }
 
   log_fn(LOG_DEBUG,"about to try connecting");
-  switch(connection_connect(conn, conn->address, addr, port)) {
+  switch (connection_connect(conn, conn->address, addr, port)) {
     case -1:
       connection_edge_end(conn, END_STREAM_REASON_CONNECTFAILED, conn->cpath_layer);
       circuit_detach_stream(circuit_get_by_conn(conn), conn);
@@ -950,14 +950,14 @@
   }
 
   conn->state = EXIT_CONN_STATE_OPEN;
-  if(connection_wants_to_flush(conn)) { /* in case there are any queued data cells */
+  if (connection_wants_to_flush(conn)) { /* in case there are any queued data cells */
     log_fn(LOG_WARN,"tell roger: newly connected conn had data waiting!");
 //    connection_start_writing(conn);
   }
   connection_watch_events(conn, POLLIN);
 
   /* also, deliver a 'connected' cell back through the circuit. */
-  if(connection_edge_is_rendezvous_stream(conn)) { /* rendezvous stream */
+  if (connection_edge_is_rendezvous_stream(conn)) { /* rendezvous stream */
     /* don't send an address back! */
     connection_edge_send_command(conn, circuit_get_by_conn(conn), RELAY_COMMAND_CONNECTED,
                                  NULL, 0, conn->cpath_layer);
@@ -974,7 +974,7 @@
  */
 int connection_edge_is_rendezvous_stream(connection_t *conn) {
   tor_assert(conn);
-  if(*conn->rend_query) /* XXX */
+  if (*conn->rend_query) /* XXX */
     return 1;
   return 0;
 }
@@ -1000,7 +1000,7 @@
     return tor_version_as_new_as(exit->platform, "0.0.9pre1");
   }
   addr = client_dns_lookup_entry(conn->socks_request->address);
-  if(router_compare_addr_to_addr_policy(addr,
+  if (router_compare_addr_to_addr_policy(addr,
      conn->socks_request->port, exit->exit_policy) < 0)
     return 0;
   return 1;
@@ -1035,7 +1035,7 @@
 {
   int a;
 
-  if(!socks_policy) /* 'no socks policy' means 'accept' */
+  if (!socks_policy) /* 'no socks policy' means 'accept' */
     return 1;
   a = router_compare_addr_to_addr_policy(addr, 1, socks_policy);
   if (a==-1)
@@ -1193,7 +1193,7 @@
 {
   time_t now;
 
-  if(!client_dns_size)
+  if (!client_dns_size)
     return;
   now = time(NULL);
   strmap_foreach(client_dns_map, (strmap_foreach_fn)_remove_if_expired, &now);

Index: connection_or.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_or.c,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -d -r1.146 -r1.147
--- connection_or.c	26 Nov 2004 04:00:53 -0000	1.146
+++ connection_or.c	28 Nov 2004 09:05:46 -0000	1.147
@@ -56,7 +56,7 @@
   tor_assert(conn);
   tor_assert(conn->type == CONN_TYPE_OR);
 
-  if(conn->state != OR_CONN_STATE_OPEN)
+  if (conn->state != OR_CONN_STATE_OPEN)
     return 0; /* don't do anything */
   return connection_or_process_cells_from_inbuf(conn);
 }
@@ -95,7 +95,7 @@
   log_fn(LOG_INFO,"OR connect() to router at %s:%u finished.",
          conn->address,conn->port);
 
-  if(connection_tls_start_handshake(conn, 0) < 0) {
+  if (connection_tls_start_handshake(conn, 0) < 0) {
     /* TLS handshaking error of some kind. */
     connection_mark_for_close(conn);
     return -1;
@@ -207,7 +207,7 @@
 
   tor_assert(id_digest);
 
-  if(server_mode(get_options()) && (me=router_get_my_routerinfo()) &&
+  if (server_mode(get_options()) && (me=router_get_my_routerinfo()) &&
      !memcmp(me->identity_digest, id_digest,DIGEST_LEN)) {
     log_fn(LOG_WARN,"Request to connect to myself! Failing.");
     return NULL;
@@ -217,7 +217,7 @@
    * id_digest, but check first to be sure */
   /*XXX this is getting called, at least by dirservers. */
   conn = connection_get_by_identity_digest(id_digest, CONN_TYPE_OR);
-  if(conn) {
+  if (conn) {
     tor_assert(conn->nickname);
     log_fn(LOG_WARN,"Asked me to connect to router '%s', but there's already a connection.", conn->nickname);
     return conn;
@@ -230,7 +230,7 @@
   conn->state = OR_CONN_STATE_CONNECTING;
   control_event_or_conn_status(conn, OR_CONN_EVENT_LAUNCHED);
 
-  switch(connection_connect(conn, conn->address, addr, port)) {
+  switch (connection_connect(conn, conn->address, addr, port)) {
     case -1:
       router_mark_as_down(conn->identity_digest);
       control_event_or_conn_status(conn, OR_CONN_EVENT_FAILED);
@@ -244,7 +244,7 @@
     /* case 1: fall through */
   }
 
-  if(connection_tls_start_handshake(conn, 0) >= 0)
+  if (connection_tls_start_handshake(conn, 0) >= 0)
     return conn;
 
   /* failure */
@@ -263,13 +263,13 @@
 int connection_tls_start_handshake(connection_t *conn, int receiving) {
   conn->state = OR_CONN_STATE_HANDSHAKING;
   conn->tls = tor_tls_new(conn->s, receiving, 0);
-  if(!conn->tls) {
+  if (!conn->tls) {
     log_fn(LOG_WARN,"tor_tls_new failed. Closing.");
     return -1;
   }
   connection_start_reading(conn);
   log_fn(LOG_DEBUG,"starting the handshake");
-  if(connection_tls_continue_handshake(conn) < 0) {
+  if (connection_tls_continue_handshake(conn) < 0) {
     return -1;
   }
   return 0;
@@ -281,7 +281,7 @@
  * Return -1 if <b>conn</b> is broken, else return 0.
  */
 int connection_tls_continue_handshake(connection_t *conn) {
-  switch(tor_tls_handshake(conn->tls)) {
+  switch (tor_tls_handshake(conn->tls)) {
     case TOR_TLS_ERROR:
     case TOR_TLS_CLOSE:
       log_fn(LOG_INFO,"tls error. breaking.");
@@ -361,13 +361,13 @@
   log_fn(LOG_DEBUG, "Other side (%s:%d) claims to be router '%s'",
          conn->address, conn->port, nickname);
 
-  if(tor_tls_verify(conn->tls, &identity_rcvd) < 0) {
+  if (tor_tls_verify(conn->tls, &identity_rcvd) < 0) {
     log_fn(LOG_WARN,"Other side, which claims to be router '%s' (%s:%d), has a cert but it's invalid. Closing.",
            nickname, conn->address, conn->port);
     return -1;
   }
 #if 0
-  if(tor_tls_check_lifetime(conn->tls, LOOSE_CERT_ALLOW_SKEW)<0) {
+  if (tor_tls_check_lifetime(conn->tls, LOOSE_CERT_ALLOW_SKEW)<0) {
     log_fn(LOG_WARN,"Other side '%s' (%s:%d) has a very highly skewed clock, or an expired certificate.  Closing.",
            nickname, conn->address, conn->port);
     return -1;
@@ -384,7 +384,7 @@
   crypto_free_pk_env(identity_rcvd);
 
   router = router_get_by_nickname(nickname);
-  if(router && /* we know this nickname */
+  if (router && /* we know this nickname */
      router->is_verified && /* make sure it's the right guy */
      memcmp(digest_rcvd, router->identity_digest, DIGEST_LEN) != 0) {
     log_fn(LOG_WARN, "Identity key not as expected for router claiming to be '%s' (%s:%d) ", nickname, conn->address, conn->port);
@@ -392,7 +392,7 @@
   }
   if (router_get_by_digest(digest_rcvd)) {
     /* This is a known router; don't cut it slack with its clock skew. */
-    if(tor_tls_check_lifetime(conn->tls, TIGHT_CERT_ALLOW_SKEW)<0) {
+    if (tor_tls_check_lifetime(conn->tls, TIGHT_CERT_ALLOW_SKEW)<0) {
       log_fn(LOG_WARN,"Router '%s' (%s:%d) has a skewed clock, or an expired certificate; or else our clock is skewed. Closing.",
              nickname, conn->address, conn->port);
       return -1;
@@ -409,7 +409,7 @@
       return -1;
     }
   } else {
-    if((c=connection_get_by_identity_digest(digest_rcvd, CONN_TYPE_OR))) {
+    if ((c=connection_get_by_identity_digest(digest_rcvd, CONN_TYPE_OR))) {
       log_fn(LOG_INFO,"Router '%s' is already connected on fd %d. Dropping fd %d.", nickname, c->s, conn->s);
       return -1;
     }
@@ -454,15 +454,15 @@
  * push data out as soon as we know there's enough for a tls record, so
  * during periods of high load we won't read the entire megabyte from
  * input before pushing any data out. */
-  if(conn->outbuf_flushlen-CELL_NETWORK_SIZE < MIN_TLS_FLUSHLEN &&
+  if (conn->outbuf_flushlen-CELL_NETWORK_SIZE < MIN_TLS_FLUSHLEN &&
      conn->outbuf_flushlen >= MIN_TLS_FLUSHLEN) {
     int extra = conn->outbuf_flushlen - MIN_TLS_FLUSHLEN;
     conn->outbuf_flushlen = MIN_TLS_FLUSHLEN;
-    if(connection_handle_write(conn) < 0) {
+    if (connection_handle_write(conn) < 0) {
       log_fn(LOG_WARN,"flushing failed.");
       return;
     }
-    if(extra) {
+    if (extra) {
       conn->outbuf_flushlen += extra;
       connection_start_writing(conn);
     }
@@ -485,7 +485,7 @@
 loop:
   log_fn(LOG_DEBUG,"%d: starting, inbuf_datalen %d (%d pending in tls object).",
          conn->s,(int)buf_datalen(conn->inbuf),tor_tls_get_pending_bytes(conn->tls));
-  if(buf_datalen(conn->inbuf) < CELL_NETWORK_SIZE) /* entire response available? */
+  if (buf_datalen(conn->inbuf) < CELL_NETWORK_SIZE) /* entire response available? */
     return 0; /* not yet */
 
   connection_fetch_from_buf(buf, CELL_NETWORK_SIZE, conn);

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- control.c	26 Nov 2004 04:00:53 -0000	1.30
+++ control.c	28 Nov 2004 09:05:46 -0000	1.31
@@ -410,7 +410,7 @@
 
  again:
   /* Try to suck a control message from the buffer. */
-  switch(fetch_from_buf_control(conn->inbuf, &body_len, &command_type, &body))
+  switch (fetch_from_buf_control(conn->inbuf, &body_len, &command_type, &body))
     {
     case -1:
       tor_free(body);
@@ -438,7 +438,7 @@
   }
 
   /* Okay, we're willing to process the command. */
-  switch(command_type)
+  switch (command_type)
     {
     case CONTROL_CMD_SETCONF:
       if (handle_control_setconf(conn, body_len, body))

Index: cpuworker.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/cpuworker.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- cpuworker.c	26 Nov 2004 04:00:53 -0000	1.57
+++ cpuworker.c	28 Nov 2004 09:05:46 -0000	1.58
@@ -95,7 +95,7 @@
  * mark it as closed and spawn a new one as needed. */
 int connection_cpu_reached_eof(connection_t *conn) {
   log_fn(LOG_WARN,"Read eof. Worker died unexpectedly.");
-  if(conn->state != CPUWORKER_STATE_IDLE) {
+  if (conn->state != CPUWORKER_STATE_IDLE) {
     /* the circ associated with this cpuworker will have to wait until
      * it gets culled in run_connection_housekeeping(), since we have
      * no way to find out which circ it was. */
@@ -124,8 +124,8 @@
   tor_assert(conn);
   tor_assert(conn->type == CONN_TYPE_CPUWORKER);
 
-  if(conn->state == CPUWORKER_STATE_BUSY_ONION) {
-    if(buf_datalen(conn->inbuf) < LEN_ONION_RESPONSE) /* entire answer available? */
+  if (conn->state == CPUWORKER_STATE_BUSY_ONION) {
+    if (buf_datalen(conn->inbuf) < LEN_ONION_RESPONSE) /* entire answer available? */
       return 0; /* not yet */
     tor_assert(buf_datalen(conn->inbuf) == LEN_ONION_RESPONSE);
 
@@ -139,21 +139,21 @@
      * get_by_identity_digest: we want a specific port here in
      * case there are multiple connections.) */
     p_conn = connection_exact_get_by_addr_port(addr,port);
-    if(p_conn)
+    if (p_conn)
       circ = circuit_get_by_circ_id_conn(circ_id, p_conn);
 
-    if(success == 0) {
+    if (success == 0) {
       log_fn(LOG_WARN,"decoding onionskin failed. Closing.");
-      if(circ)
+      if (circ)
         circuit_mark_for_close(circ);
       goto done_processing;
     }
-    if(!circ) {
+    if (!circ) {
       log_fn(LOG_INFO,"processed onion for a circ that's gone. Dropping.");
       goto done_processing;
     }
     tor_assert(circ->p_conn);
-    if(onionskin_answer(circ, buf+TAG_LEN, buf+TAG_LEN+ONIONSKIN_REPLY_LEN) < 0) {
+    if (onionskin_answer(circ, buf+TAG_LEN, buf+TAG_LEN+ONIONSKIN_REPLY_LEN) < 0) {
       log_fn(LOG_WARN,"onionskin_answer failed. Closing.");
       circuit_mark_for_close(circ);
       goto done_processing;
@@ -214,27 +214,27 @@
 
   dup_onion_keys(&onion_key, &last_onion_key);
 
-  for(;;) {
+  for (;;) {
 
-    if(recv(fd, &question_type, 1, 0) != 1) {
+    if (recv(fd, &question_type, 1, 0) != 1) {
 //      log_fn(LOG_ERR,"read type failed. Exiting.");
       log_fn(LOG_INFO,"cpuworker exiting because tor process closed connection (either rotated keys or died).");
       goto end;
     }
     tor_assert(question_type == CPUWORKER_TASK_ONION);
 
-    if(read_all(fd, tag, TAG_LEN, 1) != TAG_LEN) {
+    if (read_all(fd, tag, TAG_LEN, 1) != TAG_LEN) {
       log_fn(LOG_ERR,"read tag failed. Exiting.");
       goto end;
     }
 
-    if(read_all(fd, question, ONIONSKIN_CHALLENGE_LEN, 1) != ONIONSKIN_CHALLENGE_LEN) {
+    if (read_all(fd, question, ONIONSKIN_CHALLENGE_LEN, 1) != ONIONSKIN_CHALLENGE_LEN) {
       log_fn(LOG_ERR,"read question failed. Exiting.");
       goto end;
     }
 
-    if(question_type == CPUWORKER_TASK_ONION) {
-      if(onion_skin_server_handshake(question, onion_key, last_onion_key,
+    if (question_type == CPUWORKER_TASK_ONION) {
+      if (onion_skin_server_handshake(question, onion_key, last_onion_key,
         reply_to_proxy, keys, 40+32) < 0) {
         /* failure */
         log_fn(LOG_WARN,"onion_skin_server_handshake failed.");
@@ -247,7 +247,7 @@
         memcpy(buf+1+TAG_LEN,reply_to_proxy,ONIONSKIN_REPLY_LEN);
         memcpy(buf+1+TAG_LEN+ONIONSKIN_REPLY_LEN,keys,40+32);
       }
-      if(write_all(fd, buf, LEN_ONION_RESPONSE, 1) != LEN_ONION_RESPONSE) {
+      if (write_all(fd, buf, LEN_ONION_RESPONSE, 1) != LEN_ONION_RESPONSE) {
         log_fn(LOG_ERR,"writing response buf failed. Exiting.");
         spawn_exit();
       }
@@ -269,7 +269,7 @@
   int fd[2];
   connection_t *conn;
 
-  if(tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
+  if (tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
     log(LOG_ERR, "Couldn't construct socketpair: %s",
         tor_socket_strerror(tor_socket_errno(-1)));
     tor_cleanup();
@@ -288,7 +288,7 @@
   conn->s = fd[0];
   conn->address = tor_strdup("localhost");
 
-  if(connection_add(conn) < 0) { /* no space, forget it */
+  if (connection_add(conn) < 0) { /* no space, forget it */
     log_fn(LOG_WARN,"connection_add failed. Giving up.");
     connection_free(conn); /* this closes fd[0] */
     return -1;
@@ -306,13 +306,13 @@
 static void spawn_enough_cpuworkers(void) {
   int num_cpuworkers_needed = get_options()->NumCpus;
 
-  if(num_cpuworkers_needed < MIN_CPUWORKERS)
+  if (num_cpuworkers_needed < MIN_CPUWORKERS)
     num_cpuworkers_needed = MIN_CPUWORKERS;
-  if(num_cpuworkers_needed > MAX_CPUWORKERS)
+  if (num_cpuworkers_needed > MAX_CPUWORKERS)
     num_cpuworkers_needed = MAX_CPUWORKERS;
 
-  while(num_cpuworkers < num_cpuworkers_needed) {
-    if(spawn_cpuworker() < 0) {
+  while (num_cpuworkers < num_cpuworkers_needed) {
+    if (spawn_cpuworker() < 0) {
       log_fn(LOG_WARN,"spawn failed!");
       return;
     }
@@ -329,9 +329,9 @@
   /* for now only process onion tasks */
 
   circ = onion_next_task();
-  if(!circ)
+  if (!circ)
     return;
-  if(assign_to_cpuworker(cpuworker, CPUWORKER_TASK_ONION, circ) < 0)
+  if (assign_to_cpuworker(cpuworker, CPUWORKER_TASK_ONION, circ) < 0)
     log_fn(LOG_WARN,"assign_to_cpuworker failed. Ignoring.");
 }
 
@@ -348,12 +348,12 @@
 
   tor_assert(question_type == CPUWORKER_TASK_ONION);
 
-  if(question_type == CPUWORKER_TASK_ONION) {
+  if (question_type == CPUWORKER_TASK_ONION) {
     circ = task;
 
-    if(num_cpuworkers_busy == num_cpuworkers) {
+    if (num_cpuworkers_busy == num_cpuworkers) {
       log_fn(LOG_DEBUG,"No idle cpuworkers. Queuing.");
-      if(onion_pending_add(circ) < 0)
+      if (onion_pending_add(circ) < 0)
         return -1;
       return 0;
     }
@@ -363,7 +363,7 @@
 
     tor_assert(cpuworker);
 
-    if(!circ->p_conn) {
+    if (!circ->p_conn) {
       log_fn(LOG_INFO,"circ->p_conn gone. Failing circ.");
       return -1;
     }

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.172
retrieving revision 1.173
diff -u -d -r1.172 -r1.173
--- directory.c	26 Nov 2004 04:00:53 -0000	1.172
+++ directory.c	28 Nov 2004 09:05:46 -0000	1.173
@@ -95,7 +95,7 @@
 {
   int a;
 
-  if(!dir_policy) /* 'no dir policy' means 'accept' */
+  if (!dir_policy) /* 'no dir policy' means 'accept' */
     return 1;
   a = router_compare_addr_to_addr_policy(addr, 1, dir_policy);
   if (a==-1)
@@ -259,7 +259,7 @@
   conn->addr = addr;
   conn->port = dir_port;
 
-  if(get_options()->HttpProxy) {
+  if (get_options()->HttpProxy) {
     addr = get_options()->HttpProxyAddr;
     dir_port = get_options()->HttpProxyPort;
   }
@@ -276,14 +276,14 @@
   /* give it an initial state */
   conn->state = DIR_CONN_STATE_CONNECTING;
 
-  if(purpose == DIR_PURPOSE_FETCH_DIR ||
+  if (purpose == DIR_PURPOSE_FETCH_DIR ||
      purpose == DIR_PURPOSE_UPLOAD_DIR ||
      purpose == DIR_PURPOSE_FETCH_RUNNING_LIST) {
     /* then we want to connect directly */
-    switch(connection_connect(conn, conn->address, addr, dir_port)) {
+    switch (connection_connect(conn, conn->address, addr, dir_port)) {
       case -1:
         router_mark_as_down(conn->identity_digest); /* don't try him again */
-        if(purpose == DIR_PURPOSE_FETCH_DIR &&
+        if (purpose == DIR_PURPOSE_FETCH_DIR &&
            !all_trusted_directory_servers_down()) {
           log_fn(LOG_INFO,"Giving up on dirserver '%s'; trying another.", conn->address);
           directory_get_from_dirserver(purpose, NULL);
@@ -307,7 +307,7 @@
      * socketpair and hook up both sides
      */
     conn->s = connection_ap_make_bridge(conn->address, conn->port);
-    if(conn->s < 0) {
+    if (conn->s < 0) {
       log_fn(LOG_WARN,"Making AP bridge to dirserver failed.");
       connection_mark_for_close(conn);
       return;
@@ -342,18 +342,18 @@
   /* If we don't know the platform, assume it's up-to-date. */
   use_newer = platform ? tor_version_as_new_as(platform, "0.0.9pre1"):1;
 
-  if(conn->port == 80) {
+  if (conn->port == 80) {
     strlcpy(hoststring, conn->address, sizeof(hoststring));
   } else {
     tor_snprintf(hoststring, sizeof(hoststring),"%s:%d",conn->address, conn->port);
   }
-  if(get_options()->HttpProxy) {
+  if (get_options()->HttpProxy) {
     tor_snprintf(proxystring, sizeof(proxystring),"http://%s";, hoststring);
   } else {
     proxystring[0] = 0;
   }
 
-  switch(purpose) {
+  switch (purpose) {
     case DIR_PURPOSE_FETCH_DIR:
       tor_assert(!resource);
       tor_assert(!payload);
@@ -403,7 +403,7 @@
            hoststring);
   connection_write_to_buf(tmp, strlen(tmp), conn);
 
-  if(payload) {
+  if (payload) {
     /* then send the payload afterwards too */
     connection_write_to_buf(payload, payload_len, conn);
   }
@@ -432,20 +432,20 @@
   if (!*s) return -1;
 
   /* tolerate the http[s] proxy style of putting the hostname in the url */
-  if(s-start >= 4 && !strcmpstart(start,"http")) {
+  if (s-start >= 4 && !strcmpstart(start,"http")) {
     tmp = start + 4;
-    if(*tmp == 's')
+    if (*tmp == 's')
       tmp++;
-    if(s-tmp >= 3 && !strcmpstart(tmp,"://")) {
+    if (s-tmp >= 3 && !strcmpstart(tmp,"://")) {
       tmp = strchr(tmp+3, '/');
-      if(tmp && tmp < s) {
+      if (tmp && tmp < s) {
         log_fn(LOG_DEBUG,"Skipping over 'http[s]://hostname' string");
         start = tmp;
       }
     }
   }
 
-  if(s-start < 5 || strcmpstart(start,"/tor/")) { /* need to rewrite it */
+  if (s-start < 5 || strcmpstart(start,"/tor/")) { /* need to rewrite it */
     *url = tor_malloc(s - start + 5);
     strlcpy(*url,"/tor", s-start+5);
     strlcat((*url)+4, start, s-start+1);
@@ -472,9 +472,9 @@
   tor_assert(headers);
   tor_assert(code);
 
-  while(isspace((int)*headers)) headers++; /* tolerate leading whitespace */
+  while (isspace((int)*headers)) headers++; /* tolerate leading whitespace */
 
-  if(sscanf(headers, "HTTP/1.%d %d", &n1, &n2) < 2 ||
+  if (sscanf(headers, "HTTP/1.%d %d", &n1, &n2) < 2 ||
      (n1 != 0 && n1 != 1) ||
      (n2 < 100 || n2 >= 600)) {
     log_fn(LOG_WARN,"Failed to parse header '%s'",headers);
@@ -537,7 +537,7 @@
   int delta;
   int compression;
 
-  switch(fetch_from_buf_http(conn->inbuf,
+  switch (fetch_from_buf_http(conn->inbuf,
                              &headers, MAX_HEADERS_SIZE,
                              &body, &body_len, MAX_DIR_SIZE)) {
     case -1: /* overflow */
@@ -549,7 +549,7 @@
     /* case 1, fall through */
   }
 
-  if(parse_http_response(headers, &status_code, &date_header,
+  if (parse_http_response(headers, &status_code, &date_header,
                          &compression) < 0) {
     log_fn(LOG_WARN,"Unparseable headers. Closing.");
     tor_free(body); tor_free(headers);
@@ -580,21 +580,21 @@
     body_len = new_len;
   }
 
-  if(conn->purpose == DIR_PURPOSE_FETCH_DIR) {
+  if (conn->purpose == DIR_PURPOSE_FETCH_DIR) {
     /* fetch/process the directory to learn about new routers. */
     log_fn(LOG_INFO,"Received directory (size %d):\n%s", (int)body_len, body);
-    if(status_code == 503 || body_len == 0) {
+    if (status_code == 503 || body_len == 0) {
       log_fn(LOG_INFO,"Empty directory. Ignoring.");
       tor_free(body); tor_free(headers);
       return 0;
     }
-    if(status_code != 200) {
+    if (status_code != 200) {
       log_fn(LOG_WARN,"Received http status code %d from dirserver. Failing.",
              status_code);
       tor_free(body); tor_free(headers);
       return -1;
     }
-    if(router_load_routerlist_from_directory(body, NULL, 1) < 0) {
+    if (router_load_routerlist_from_directory(body, NULL, 1) < 0) {
       log_fn(LOG_WARN,"I failed to parse the directory I fetched from %s:%d. Ignoring.", conn->address, conn->port);
     } else {
       log_fn(LOG_INFO,"updated routers.");
@@ -602,12 +602,12 @@
     directory_has_arrived(time(NULL)); /* do things we've been waiting to do */
   }
 
-  if(conn->purpose == DIR_PURPOSE_FETCH_RUNNING_LIST) {
+  if (conn->purpose == DIR_PURPOSE_FETCH_RUNNING_LIST) {
     running_routers_t *rrs;
     routerlist_t *rl;
     /* just update our list of running routers, if this list is new info */
     log_fn(LOG_INFO,"Received running-routers list (size %d):\n%s", (int)body_len, body);
-    if(status_code != 200) {
+    if (status_code != 200) {
       log_fn(LOG_WARN,"Received http status code %d from dirserver. Failing.",
              status_code);
       tor_free(body); tor_free(headers);
@@ -624,8 +624,8 @@
     running_routers_free(rrs);
   }
 
-  if(conn->purpose == DIR_PURPOSE_UPLOAD_DIR) {
-    switch(status_code) {
+  if (conn->purpose == DIR_PURPOSE_UPLOAD_DIR) {
+    switch (status_code) {
       case 200:
         log_fn(LOG_INFO,"eof (status 200) after uploading server descriptor: finished.");
         break;
@@ -641,12 +641,12 @@
     }
   }
 
-  if(conn->purpose == DIR_PURPOSE_FETCH_RENDDESC) {
+  if (conn->purpose == DIR_PURPOSE_FETCH_RENDDESC) {
     log_fn(LOG_INFO,"Received rendezvous descriptor (size %d, status code %d)",
            (int)body_len, status_code);
-    switch(status_code) {
+    switch (status_code) {
       case 200:
-        if(rend_cache_store(body, body_len) < 0) {
+        if (rend_cache_store(body, body_len) < 0) {
           log_fn(LOG_WARN,"Failed to store rendezvous descriptor.");
           /* alice's ap_stream will notice when connection_mark_for_close
            * cleans it up */
@@ -666,8 +666,8 @@
     }
   }
 
-  if(conn->purpose == DIR_PURPOSE_UPLOAD_RENDDESC) {
-    switch(status_code) {
+  if (conn->purpose == DIR_PURPOSE_UPLOAD_RENDDESC) {
+    switch (status_code) {
       case 200:
         log_fn(LOG_INFO,"eof (status 200) after uploading rendezvous descriptor: finished.");
         break;
@@ -685,7 +685,7 @@
 
 int connection_dir_reached_eof(connection_t *conn) {
   int retval;
-  if(conn->state != DIR_CONN_STATE_CLIENT_READING) {
+  if (conn->state != DIR_CONN_STATE_CLIENT_READING) {
     log_fn(LOG_INFO,"conn reached eof, not reading. Closing.");
     connection_close_immediate(conn); /* it was an error; give up on flushing */
     connection_mark_for_close(conn);
@@ -712,7 +712,7 @@
    */
 
   /* If we're on the dirserver side, look for a command. */
-  if(conn->state == DIR_CONN_STATE_SERVER_COMMAND_WAIT) {
+  if (conn->state == DIR_CONN_STATE_SERVER_COMMAND_WAIT) {
     if (directory_handle_command(conn) < 0) {
       connection_mark_for_close(conn);
       return -1;
@@ -757,13 +757,13 @@
   }
   log_fn(LOG_INFO,"rewritten url as '%s'.", url);
 
-  if(!strcmp(url,"/tor/") || !strcmp(url,"/tor/dir.z")) { /* directory fetch */
+  if (!strcmp(url,"/tor/") || !strcmp(url,"/tor/dir.z")) { /* directory fetch */
     int deflated = !strcmp(url,"/tor/dir.z");
     dlen = dirserv_get_directory(&cp, deflated);
 
     tor_free(url);
 
-    if(dlen == 0) {
+    if (dlen == 0) {
       log_fn(LOG_WARN,"My directory is empty. Closing.");
       connection_write_to_buf(answer503, strlen(answer503), conn);
       return 0;
@@ -781,17 +781,17 @@
     return 0;
   }
 
-  if(!strcmp(url,"/tor/running-routers") ||
+  if (!strcmp(url,"/tor/running-routers") ||
      !strcmp(url,"/tor/running-routers.z")) { /* running-routers fetch */
     int deflated = !strcmp(url,"/tor/dir.z");
     tor_free(url);
-    if(!authdir_mode(get_options())) {
+    if (!authdir_mode(get_options())) {
       /* For now, we don't cache running-routers. Reject. */
       connection_write_to_buf(answer400, strlen(answer400), conn);
       return 0;
     }
     dlen = dirserv_get_runningrouters(&cp, deflated);
-    if(!dlen) { /* we failed to create/cache cp */
+    if (!dlen) { /* we failed to create/cache cp */
       connection_write_to_buf(answer503, strlen(answer503), conn);
       return 0;
     }
@@ -806,12 +806,12 @@
     return 0;
   }
 
-  if(!strcmpstart(url,"/tor/rendezvous/")) {
+  if (!strcmpstart(url,"/tor/rendezvous/")) {
     /* rendezvous descriptor fetch */
     const char *descp;
     size_t desc_len;
 
-    if(!authdir_mode(get_options())) {
+    if (!authdir_mode(get_options())) {
       /* We don't hand out rend descs. In fact, it could be a security
        * risk, since rend_cache_lookup_desc() below would provide it
        * if we're gone to the site recently, and 404 if we haven't.
@@ -821,7 +821,7 @@
       tor_free(url);
       return 0;
     }
-    switch(rend_cache_lookup_desc(url+strlen("/tor/rendezvous/"), &descp, &desc_len)) {
+    switch (rend_cache_lookup_desc(url+strlen("/tor/rendezvous/"), &descp, &desc_len)) {
       case 1: /* valid */
         format_rfc1123_time(date, time(NULL));
         tor_snprintf(tmp, sizeof(tmp), "HTTP/1.0 200 OK\r\nDate: %s\r\nContent-Length: %d\r\nContent-Type: application/octet-stream\r\n\r\n",
@@ -863,7 +863,7 @@
 
   conn->state = DIR_CONN_STATE_SERVER_WRITING;
 
-  if(!authdir_mode(get_options())) {
+  if (!authdir_mode(get_options())) {
     /* we just provide cached directories; we don't want to
      * receive anything. */
     connection_write_to_buf(answer400, strlen(answer400), conn);
@@ -876,9 +876,9 @@
   }
   log_fn(LOG_INFO,"rewritten url as '%s'.", url);
 
-  if(!strcmp(url,"/tor/")) { /* server descriptor post */
+  if (!strcmp(url,"/tor/")) { /* server descriptor post */
     cp = body;
-    switch(dirserv_add_descriptor(&cp)) {
+    switch (dirserv_add_descriptor(&cp)) {
       case -1:
         /* malformed descriptor, or something wrong */
         connection_write_to_buf(answer400, strlen(answer400), conn);
@@ -896,9 +896,9 @@
     return 0;
   }
 
-  if(!strcmpstart(url,"/tor/rendezvous/publish")) {
+  if (!strcmpstart(url,"/tor/rendezvous/publish")) {
     /* rendezvous descriptor post */
-    if(rend_cache_store(body, body_len) < 0)
+    if (rend_cache_store(body, body_len) < 0)
       connection_write_to_buf(answer400, strlen(answer400), conn);
     else
       connection_write_to_buf(answer200, strlen(answer200), conn);
@@ -925,7 +925,7 @@
   tor_assert(conn);
   tor_assert(conn->type == CONN_TYPE_DIR);
 
-  switch(fetch_from_buf_http(conn->inbuf,
+  switch (fetch_from_buf_http(conn->inbuf,
                              &headers, MAX_HEADERS_SIZE,
                              &body, &body_len, MAX_BODY_SIZE)) {
     case -1: /* overflow */
@@ -939,7 +939,7 @@
 
   log_fn(LOG_DEBUG,"headers '%s', body '%s'.", headers, body);
 
-  if(!strncasecmp(headers,"GET",3))
+  if (!strncasecmp(headers,"GET",3))
     r = directory_handle_command_get(conn, headers, body, body_len);
   else if (!strncasecmp(headers,"POST",4))
     r = directory_handle_command_post(conn, headers, body, body_len);
@@ -961,7 +961,7 @@
   tor_assert(conn);
   tor_assert(conn->type == CONN_TYPE_DIR);
 
-  switch(conn->state) {
+  switch (conn->state) {
     case DIR_CONN_STATE_CLIENT_SENDING:
       log_fn(LOG_DEBUG,"client finished sending command.");
       conn->state = DIR_CONN_STATE_CLIENT_READING;

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.124
retrieving revision 1.125
diff -u -d -r1.124 -r1.125
--- dirserv.c	26 Nov 2004 04:00:53 -0000	1.124
+++ dirserv.c	28 Nov 2004 09:05:46 -0000	1.125
@@ -107,13 +107,13 @@
 
   fingerprint_list_new = smartlist_create();
 
-  for(list=front; list; list=list->next) {
+  for (list=front; list; list=list->next) {
     nickname = list->key; fingerprint = list->value;
     if (strlen(nickname) > MAX_NICKNAME_LEN) {
       log(LOG_WARN, "Nickname '%s' too long in fingerprint file. Skipping.", nickname);
       continue;
     }
-    if(strlen(fingerprint) != FINGERPRINT_LEN ||
+    if (strlen(fingerprint) != FINGERPRINT_LEN ||
        !crypto_pk_check_fingerprint_syntax(fingerprint)) {
       log_fn(LOG_WARN, "Invalid fingerprint (nickname '%s', fingerprint %s). Skipping.",
              nickname, fingerprint);
@@ -134,7 +134,7 @@
         break; /* out of the for. the 'if' below means skip to the next line. */
       }
     }
-    if(i == smartlist_len(fingerprint_list_new)) { /* not a duplicate */
+    if (i == smartlist_len(fingerprint_list_new)) { /* not a duplicate */
       ent = tor_malloc(sizeof(fingerprint_entry_t));
       ent->nickname = tor_strdup(nickname);
       ent->fingerprint = tor_strdup(fingerprint);
@@ -331,13 +331,13 @@
   }
   /* Okay.  Now check whether the fingerprint is recognized. */
   r = dirserv_router_fingerprint_is_known(ri);
-  if(r==-1) {
+  if (r==-1) {
     log_fn(LOG_WARN, "Known nickname '%s', wrong fingerprint. Not adding.", ri->nickname);
     routerinfo_free(ri);
     *desc = end;
     return 0;
   }
-  if(r==0) {
+  if (r==0) {
     char fp[FINGERPRINT_LEN+1];
     log_fn(LOG_INFO, "Unknown nickname '%s' (%s:%d). Adding.",
            ri->nickname, ri->address, ri->or_port);
@@ -437,9 +437,9 @@
 {
   time_t now = time(NULL);
 
-  if(!the_directory_is_dirty)
+  if (!the_directory_is_dirty)
     the_directory_is_dirty = now;
-  if(!runningrouters_is_dirty)
+  if (!runningrouters_is_dirty)
     runningrouters_is_dirty = now;
 }
 
@@ -450,7 +450,7 @@
 dirserv_load_from_directory_string(const char *dir)
 {
   const char *cp = dir;
-  while(1) {
+  while (1) {
     cp = strstr(cp, "\nrouter ");
     if (!cp) break;
     ++cp;
@@ -599,14 +599,14 @@
    * PEM-encoded key instead.
    */
 #if 1
-  if(crypto_pk_DER64_encode_public_key(private_key, &identity_pkey)<0) {
+  if (crypto_pk_DER64_encode_public_key(private_key, &identity_pkey)<0) {
     log_fn(LOG_WARN,"write identity_pkey to string failed!");
     return -1;
   }
 #else
   {
     int l;
-    if(crypto_pk_write_public_key_to_string(private_key,&identity_pkey,&l)<0) {
+    if (crypto_pk_write_public_key_to_string(private_key,&identity_pkey,&l)<0) {
       log_fn(LOG_WARN,"write identity_pkey to string failed!");
       return -1;
     }
@@ -735,7 +735,7 @@
     if (!is_running_routers) {
       char filename[512];
       tor_snprintf(filename,sizeof(filename),"%s/cached-directory", get_options()->DataDirectory);
-      if(write_str_to_file(filename,cached_directory.dir,0) < 0) {
+      if (write_str_to_file(filename,cached_directory.dir,0) < 0) {
         log_fn(LOG_WARN, "Couldn't write cached directory to disk. Ignoring.");
       }
     }
@@ -843,14 +843,14 @@
    * PEM-encoded key instead.
    */
 #if 1
-  if(crypto_pk_DER64_encode_public_key(private_key, &identity_pkey)<0) {
+  if (crypto_pk_DER64_encode_public_key(private_key, &identity_pkey)<0) {
     log_fn(LOG_WARN,"write identity_pkey to string failed!");
     goto err;
   }
 #else
   {
     int l;
-    if(crypto_pk_write_public_key_to_string(private_key,&identity_pkey,&l)<0) {
+    if (crypto_pk_write_public_key_to_string(private_key,&identity_pkey,&l)<0) {
       log_fn(LOG_WARN,"write identity_pkey to string failed!");
       goto err;
     }
@@ -926,7 +926,7 @@
   }
   if (runningrouters_is_dirty &&
       runningrouters_is_dirty + DIR_REGEN_SLACK_TIME < time(NULL)) {
-    if(generate_runningrouters(get_identity_key())) {
+    if (generate_runningrouters(get_identity_key())) {
       log_fn(LOG_ERR, "Couldn't generate running-routers list?");
       return 0;
     }

Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dns.c,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -d -r1.121 -r1.122
--- dns.c	26 Nov 2004 04:00:53 -0000	1.121
+++ dns.c	28 Nov 2004 09:05:46 -0000	1.122
@@ -112,10 +112,10 @@
   /* this is fast because the linked list
    * oldest_cached_resolve is ordered by when they came in.
    */
-  while(oldest_cached_resolve && (oldest_cached_resolve->expire < now)) {
+  while (oldest_cached_resolve && (oldest_cached_resolve->expire < now)) {
     resolve = oldest_cached_resolve;
     log(LOG_DEBUG,"Forgetting old cached resolve (expires %lu)", (unsigned long)resolve->expire);
-    if(resolve->state == CACHE_STATE_PENDING) {
+    if (resolve->state == CACHE_STATE_PENDING) {
       log_fn(LOG_WARN,"Expiring a dns resolve that's still pending. Forgot to cull it?");
     }
     if (resolve->pending_connections) {
@@ -134,7 +134,7 @@
       }
     }
     oldest_cached_resolve = resolve->next;
-    if(!oldest_cached_resolve) /* if there are no more, */
+    if (!oldest_cached_resolve) /* if there are no more, */
       newest_cached_resolve = NULL; /* then make sure the list's tail knows that too */
     SPLAY_REMOVE(cache_tree, &cache_root, resolve);
     tor_free(resolve);
@@ -218,8 +218,8 @@
   /* now check the tree to see if 'address' is already there. */
   strlcpy(search.address, exitconn->address, sizeof(search.address));
   resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
-  if(resolve) { /* already there */
-    switch(resolve->state) {
+  if (resolve) { /* already there */
+    switch (resolve->state) {
       case CACHE_STATE_PENDING:
         /* add us to the pending list */
         pending_connection = tor_malloc_zero(
@@ -277,7 +277,7 @@
 
   dnsconn = connection_get_by_type_state(CONN_TYPE_DNSWORKER, DNSWORKER_STATE_IDLE);
 
-  if(!dnsconn) {
+  if (!dnsconn) {
     log_fn(LOG_WARN,"no idle dns workers. Failing.");
     dns_cancel_pending_resolve(exitconn->address);
     send_resolved_cell(exitconn, RESOLVED_TYPE_ERROR_TRANSIENT);
@@ -314,7 +314,7 @@
   strlcpy(search.address, conn->address, sizeof(search.address));
 
   resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
-  if(!resolve) {
+  if (!resolve) {
     log_fn(LOG_WARN,"Address '%s' is not pending. Dropping.", conn->address);
     return;
   }
@@ -324,15 +324,15 @@
 
   pend = resolve->pending_connections;
 
-  if(pend->conn == conn) {
+  if (pend->conn == conn) {
     resolve->pending_connections = pend->next;
     tor_free(pend);
     log_fn(LOG_DEBUG, "First connection (fd %d) no longer waiting for resolve of '%s'",
            conn->s, conn->address);
     return;
   } else {
-    for( ; pend->next; pend = pend->next) {
-      if(pend->next->conn == conn) {
+    for ( ; pend->next; pend = pend->next) {
+      if (pend->next->conn == conn) {
         victim = pend->next;
         pend->next = victim->next;
         tor_free(victim);
@@ -352,7 +352,7 @@
   struct cached_resolve *resolve;
 
   SPLAY_FOREACH(resolve, cache_tree, &cache_root) {
-    for(pend = resolve->pending_connections;
+    for (pend = resolve->pending_connections;
         pend;
         pend = pend->next) {
       tor_assert(pend->conn != conn);
@@ -367,7 +367,7 @@
   struct cached_resolve *resolve;
 
   SPLAY_FOREACH(resolve, cache_tree, &cache_root) {
-    for(pend = resolve->pending_connections;
+    for (pend = resolve->pending_connections;
         pend;
         pend = pend->next) {
       assert_connection_ok(pend->conn, 0);
@@ -390,7 +390,7 @@
   strlcpy(search.address, address, sizeof(search.address));
 
   resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
-  if(!resolve) {
+  if (!resolve) {
     log_fn(LOG_WARN,"Address '%s' is not pending. Dropping.", address);
     return;
   }
@@ -400,12 +400,12 @@
   /* mark all pending connections to fail */
   log_fn(LOG_DEBUG, "Failing all connections waiting on DNS resolve of '%s'",
          address);
-  while(resolve->pending_connections) {
+  while (resolve->pending_connections) {
     pend = resolve->pending_connections;
     pend->conn->state = EXIT_CONN_STATE_RESOLVEFAILED;
     pendconn = pend->conn;
     tor_assert(pendconn->s == -1);
-    if(!pendconn->marked_for_close) {
+    if (!pendconn->marked_for_close) {
       connection_edge_end(pendconn, END_STREAM_REASON_MISC, pendconn->cpath_layer);
     }
     circuit_detach_stream(circuit_get_by_conn(pendconn), pendconn);
@@ -423,17 +423,17 @@
   struct cached_resolve *tmp;
 
   /* remove resolve from the linked list */
-  if(resolve == oldest_cached_resolve) {
+  if (resolve == oldest_cached_resolve) {
     oldest_cached_resolve = resolve->next;
-    if(oldest_cached_resolve == NULL)
+    if (oldest_cached_resolve == NULL)
       newest_cached_resolve = NULL;
   } else {
     /* FFFF make it a doubly linked list if this becomes too slow */
-    for(tmp=oldest_cached_resolve; tmp && tmp->next != resolve; tmp=tmp->next) ;
+    for (tmp=oldest_cached_resolve; tmp && tmp->next != resolve; tmp=tmp->next) ;
     tor_assert(tmp); /* it's got to be in the list, or we screwed up somewhere else */
     tmp->next = resolve->next; /* unlink it */
 
-    if(newest_cached_resolve == resolve)
+    if (newest_cached_resolve == resolve)
       newest_cached_resolve = tmp;
   }
 
@@ -460,7 +460,7 @@
   strlcpy(search.address, address, sizeof(search.address));
 
   resolve = SPLAY_FIND(cache_tree, &cache_root, &search);
-  if(!resolve) {
+  if (!resolve) {
     log_fn(LOG_INFO,"Resolved unasked address '%s'; caching anyway.", address);
     resolve = tor_malloc_zero(sizeof(struct cached_resolve));
     resolve->state = (outcome == DNS_RESOLVE_SUCCEEDED) ?
@@ -486,19 +486,19 @@
   /* tor_assert(resolve->state == CACHE_STATE_PENDING); */
 
   resolve->addr = addr;
-  if(outcome == DNS_RESOLVE_SUCCEEDED)
+  if (outcome == DNS_RESOLVE_SUCCEEDED)
     resolve->state = CACHE_STATE_VALID;
   else
     resolve->state = CACHE_STATE_FAILED;
 
-  while(resolve->pending_connections) {
+  while (resolve->pending_connections) {
     pend = resolve->pending_connections;
     assert_connection_ok(pend->conn,time(NULL));
     pend->conn->addr = resolve->addr;
     pendconn = pend->conn; /* don't pass complex things to the
                               connection_mark_for_close macro */
 
-    if(resolve->state == CACHE_STATE_FAILED) {
+    if (resolve->state == CACHE_STATE_FAILED) {
       /* prevent double-remove. */
       pendconn->state = EXIT_CONN_STATE_RESOLVEFAILED;
       if (pendconn->purpose == EXIT_PURPOSE_CONNECT) {
@@ -540,7 +540,7 @@
     tor_free(pend);
   }
 
-  if(outcome == DNS_RESOLVE_FAILED_TRANSIENT) { /* remove from cache */
+  if (outcome == DNS_RESOLVE_FAILED_TRANSIENT) { /* remove from cache */
     dns_purge_resolve(resolve);
   }
 }
@@ -561,7 +561,7 @@
 
 int connection_dns_reached_eof(connection_t *conn) {
   log_fn(LOG_WARN,"Read eof. Worker died unexpectedly.");
-  if(conn->state == DNSWORKER_STATE_BUSY) {
+  if (conn->state == DNSWORKER_STATE_BUSY) {
     dns_cancel_pending_resolve(conn->address);
     num_dnsworkers_busy--;
   }
@@ -580,11 +580,11 @@
   tor_assert(conn);
   tor_assert(conn->type == CONN_TYPE_DNSWORKER);
 
-  if(conn->state != DNSWORKER_STATE_BUSY) {
+  if (conn->state != DNSWORKER_STATE_BUSY) {
     log_fn(LOG_WARN,"Bug: poll() indicated than an idle dns worker was readable. Please report.");
     return 0;
   }
-  if(buf_datalen(conn->inbuf) < 5) /* entire answer available? */
+  if (buf_datalen(conn->inbuf) < 5) /* entire answer available? */
     return 0; /* not yet */
   tor_assert(conn->state == DNSWORKER_STATE_BUSY);
   tor_assert(buf_datalen(conn->inbuf) == 5);
@@ -659,14 +659,14 @@
 #endif
   handle_signals(0); /* ignore interrupts from the keyboard, etc */
 
-  for(;;) {
+  for (;;) {
 
-    if(recv(fd, &address_len, 1, 0) != 1) {
+    if (recv(fd, &address_len, 1, 0) != 1) {
       log_fn(LOG_INFO,"dnsworker exiting because tor process closed connection (either pruned idle dnsworker or died).");
       spawn_exit();
     }
 
-    if(address_len && read_all(fd, address, address_len, 1) != address_len) {
+    if (address_len && read_all(fd, address, address_len, 1) != address_len) {
       log_fn(LOG_ERR,"read hostname failed. Child exiting.");
       spawn_exit();
     }
@@ -692,7 +692,7 @@
         break;
     }
     set_uint32(answer+1, ip);
-    if(write_all(fd, answer, 5, 1) != 5) {
+    if (write_all(fd, answer, 5, 1) != 5) {
       log_fn(LOG_ERR,"writing answer failed. Child exiting.");
       spawn_exit();
     }
@@ -706,7 +706,7 @@
   int fd[2];
   connection_t *conn;
 
-  if(tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
+  if (tor_socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0) {
     log(LOG_ERR, "Couldn't construct socketpair: %s",
         tor_socket_strerror(tor_socket_errno(-1)));
     tor_cleanup();
@@ -725,7 +725,7 @@
   conn->s = fd[0];
   conn->address = tor_strdup("<unused>");
 
-  if(connection_add(conn) < 0) { /* no space, forget it */
+  if (connection_add(conn) < 0) { /* no space, forget it */
     log_fn(LOG_WARN,"connection_add failed. Giving up.");
     connection_free(conn); /* this closes fd[0] */
     return -1;
@@ -752,7 +752,7 @@
    *     Maybe we should compromise and only kill if it's been at it for
    *     more than, e.g., 2 seconds. -RD
    */
-  if(num_dnsworkers_busy == MAX_DNSWORKERS) {
+  if (num_dnsworkers_busy == MAX_DNSWORKERS) {
     /* We always want at least one worker idle.
      * So find the oldest busy worker and kill it.
      */
@@ -768,20 +768,20 @@
     num_dnsworkers--;
   }
 
-  if(num_dnsworkers_busy >= MIN_DNSWORKERS)
+  if (num_dnsworkers_busy >= MIN_DNSWORKERS)
     num_dnsworkers_needed = num_dnsworkers_busy+1;
   else
     num_dnsworkers_needed = MIN_DNSWORKERS;
 
-  while(num_dnsworkers < num_dnsworkers_needed) {
-    if(spawn_dnsworker() < 0) {
+  while (num_dnsworkers < num_dnsworkers_needed) {
+    if (spawn_dnsworker() < 0) {
       log(LOG_WARN,"spawn_enough_dnsworkers(): spawn failed!");
       return;
     }
     num_dnsworkers++;
   }
 
-  while(num_dnsworkers > num_dnsworkers_busy+MAX_IDLE_DNSWORKERS) { /* too many idle? */
+  while (num_dnsworkers > num_dnsworkers_busy+MAX_IDLE_DNSWORKERS) { /* too many idle? */
     /* cull excess workers */
     log_fn(LOG_WARN,"%d of %d dnsworkers are idle. Killing one.",
            num_dnsworkers-num_dnsworkers_needed, num_dnsworkers);

Index: hibernate.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/hibernate.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- hibernate.c	23 Nov 2004 22:34:23 -0000	1.32
+++ hibernate.c	28 Nov 2004 09:05:46 -0000	1.33
@@ -640,7 +640,7 @@
 static void hibernate_begin(int new_state, time_t now) {
   connection_t *conn;
 
-  if(hibernate_state == HIBERNATE_STATE_EXITING) {
+  if (hibernate_state == HIBERNATE_STATE_EXITING) {
     /* we've been called twice now. close immediately. */
     log(LOG_NOTICE,"Second sigint received; exiting now.");
     tor_cleanup();
@@ -648,9 +648,9 @@
   }
 
   /* close listeners. leave control listener(s). */
-  while((conn = connection_get_by_type(CONN_TYPE_OR_LISTENER)) ||
-        (conn = connection_get_by_type(CONN_TYPE_AP_LISTENER)) ||
-        (conn = connection_get_by_type(CONN_TYPE_DIR_LISTENER))) {
+  while ((conn = connection_get_by_type(CONN_TYPE_OR_LISTENER)) ||
+         (conn = connection_get_by_type(CONN_TYPE_AP_LISTENER)) ||
+         (conn = connection_get_by_type(CONN_TYPE_DIR_LISTENER))) {
     log_fn(LOG_INFO,"Closing listener type %d", conn->type);
     connection_mark_for_close(conn);
   }
@@ -658,7 +658,7 @@
   /* XXX kill intro point circs */
   /* XXX upload rendezvous service descriptors with no intro points */
 
-  if(new_state == HIBERNATE_STATE_EXITING) {
+  if (new_state == HIBERNATE_STATE_EXITING) {
     log(LOG_NOTICE,"Interrupt: will shut down in %d seconds. Interrupt again to exit now.", SHUTDOWN_WAIT_LENGTH);
     hibernate_end_time = time(NULL) + SHUTDOWN_WAIT_LENGTH;
   } else { /* soft limit reached */
@@ -715,9 +715,9 @@
    * running, and download directories so we can detect if we're obsolete.
    * Leave control conns because we still want to be controllable.
    */
-  while((conn = connection_get_by_type(CONN_TYPE_OR)) ||
-        (conn = connection_get_by_type(CONN_TYPE_AP)) ||
-        (conn = connection_get_by_type(CONN_TYPE_EXIT))) {
+  while ((conn = connection_get_by_type(CONN_TYPE_OR)) ||
+         (conn = connection_get_by_type(CONN_TYPE_AP)) ||
+         (conn = connection_get_by_type(CONN_TYPE_EXIT))) {
     log_fn(LOG_INFO,"Closing conn type %d", conn->type);
     connection_mark_for_close(conn);
   }
@@ -763,7 +763,7 @@
    * elapses. */
   if (hibernate_state == HIBERNATE_STATE_EXITING) {
     tor_assert(hibernate_end_time);
-    if(hibernate_end_time <= now) {
+    if (hibernate_end_time <= now) {
       log(LOG_NOTICE,"Clean shutdown finished. Exiting.");
       tor_cleanup();
       exit(0);
@@ -771,7 +771,7 @@
     return; /* if exiting soon, don't worry about bandwidth limits */
   }
 
-  if(hibernate_state == HIBERNATE_STATE_DORMANT) {
+  if (hibernate_state == HIBERNATE_STATE_DORMANT) {
     /* We've been hibernating because of bandwidth accounting. */
     tor_assert(hibernate_end_time);
     if (hibernate_end_time > now && accounting_enabled) {

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/main.c,v
retrieving revision 1.394
retrieving revision 1.395
diff -u -d -r1.394 -r1.395
--- main.c	28 Nov 2004 05:48:02 -0000	1.394
+++ main.c	28 Nov 2004 09:05:46 -0000	1.395
@@ -97,7 +97,7 @@
   tor_assert(conn);
   tor_assert(conn->s >= 0);
 
-  if(nfds >= get_options()->MaxConn-1) {
+  if (nfds >= get_options()->MaxConn-1) {
     log_fn(LOG_WARN,"failing because nfds is too high.");
     return -1;
   }
@@ -135,7 +135,7 @@
 
   tor_assert(conn->poll_index >= 0);
   current_index = conn->poll_index;
-  if(current_index == nfds-1) { /* this is the end */
+  if (current_index == nfds-1) { /* this is the end */
     nfds--;
     return 0;
   }
@@ -240,7 +240,7 @@
 
   /* see http://www.greenend.org.uk/rjk/2001/06/poll.html for
    * discussion of POLLIN vs POLLHUP */
-  if(!(poll_array[i].revents & (POLLIN|POLLHUP|POLLERR)))
+  if (!(poll_array[i].revents & (POLLIN|POLLHUP|POLLERR)))
     /* Sometimes read events get triggered for things that didn't ask
      * for them (XXX due to unknown poll wonkiness) and sometime we
      * want to read even though there was no read event (due to
@@ -251,7 +251,7 @@
      * something sane may result.  Nick suspects that the || below
      * should be a &&.
      */
-    if(!connection_is_reading(conn) ||
+    if (!connection_is_reading(conn) ||
        !connection_has_pending_tls_data(conn))
       return; /* this conn should not read */
 
@@ -260,7 +260,7 @@
   assert_connection_ok(conn, time(NULL));
   assert_all_pending_dns_resolves_ok();
 
-  if(
+  if (
     /* XXX does POLLHUP also mean it's definitely broken? */
 #ifdef MS_WINDOWS
     (poll_array[i].revents & POLLERR) ||
@@ -284,7 +284,7 @@
 static void conn_write(int i) {
   connection_t *conn;
 
-  if(!(poll_array[i].revents & POLLOUT))
+  if (!(poll_array[i].revents & POLLOUT))
     return; /* this conn doesn't want to write */
 
   conn = connection_array[i];
@@ -325,34 +325,34 @@
   conn = connection_array[i];
   assert_connection_ok(conn, time(NULL));
   assert_all_pending_dns_resolves_ok();
-  if(!conn->marked_for_close)
+  if (!conn->marked_for_close)
     return; /* nothing to see here, move along */
 
   log_fn(LOG_INFO,"Cleaning up connection (fd %d).",conn->s);
-  if(conn->s >= 0 && connection_wants_to_flush(conn)) {
+  if (conn->s >= 0 && connection_wants_to_flush(conn)) {
     /* -1 means it's an incomplete edge connection, or that the socket
      * has already been closed as unflushable. */
-    if(!conn->hold_open_until_flushed)
+    if (!conn->hold_open_until_flushed)
       log_fn(LOG_INFO,
         "Conn (addr %s, fd %d, type %s, state %d) marked, but wants to flush %d bytes. "
         "(Marked at %s:%d)",
         conn->address, conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state,
         (int)conn->outbuf_flushlen, conn->marked_for_close_file, conn->marked_for_close);
-    if(connection_speaks_cells(conn)) {
-      if(conn->state == OR_CONN_STATE_OPEN) {
+    if (connection_speaks_cells(conn)) {
+      if (conn->state == OR_CONN_STATE_OPEN) {
         retval = flush_buf_tls(conn->tls, conn->outbuf, &conn->outbuf_flushlen);
       } else
         retval = -1; /* never flush non-open broken tls connections */
     } else {
       retval = flush_buf(conn->s, conn->outbuf, &conn->outbuf_flushlen);
     }
-    if(retval >= 0 &&
+    if (retval >= 0 &&
        conn->hold_open_until_flushed && connection_wants_to_flush(conn)) {
       log_fn(LOG_INFO,"Holding conn (fd %d) open for more flushing.",conn->s);
       /* XXX should we reset timestamp_lastwritten here? */
       return;
     }
-    if(connection_wants_to_flush(conn)) {
+    if (connection_wants_to_flush(conn)) {
       log_fn(LOG_WARN,"Conn (addr %s, fd %d, type %s, state %d) still wants to flush. Losing %d bytes! (Marked at %s:%d)",
              conn->address, conn->s, CONN_TYPE_TO_STRING(conn->type), conn->state,
              (int)buf_datalen(conn->outbuf), conn->marked_for_close_file,
@@ -366,11 +366,11 @@
   circuit_about_to_close_connection(conn);
   connection_about_to_close_connection(conn);
   connection_remove(conn);
-  if(conn->type == CONN_TYPE_EXIT) {
+  if (conn->type == CONN_TYPE_EXIT) {
     assert_connection_edge_not_dns_pending(conn);
   }
   connection_free(conn);
-  if(i<nfds) { /* we just replaced the one at i with a new one.
+  if (i<nfds) { /* we just replaced the one at i with a new one.
                   process it too. */
     conn_close_if_marked(i);
   }
@@ -389,10 +389,10 @@
   if (!time_to_fetch_directory)
     time_to_fetch_directory = now + options->DirFetchPeriod;
 
-  if(!time_to_force_upload_descriptor)
+  if (!time_to_force_upload_descriptor)
     time_to_force_upload_descriptor = now + options->DirPostPeriod;
 
-  if(!time_to_fetch_running_routers)
+  if (!time_to_fetch_running_routers)
     time_to_fetch_running_routers = now + options->StatusFetchPeriod;
 
   if (server_mode(options) &&
@@ -410,7 +410,7 @@
   or_options_t *options = get_options();
 
   /* Expire any directory connections that haven't sent anything for 5 min */
-  if(conn->type == CONN_TYPE_DIR &&
+  if (conn->type == CONN_TYPE_DIR &&
      !conn->marked_for_close &&
      conn->timestamp_lastwritten + 5*60 < now) {
     log_fn(LOG_INFO,"Expiring wedged directory conn (fd %d, purpose %d)", conn->s, conn->purpose);
@@ -420,10 +420,10 @@
 
   /* If we haven't written to an OR connection for a while, then either nuke
      the connection or send a keepalive, depending. */
-  if(connection_speaks_cells(conn) &&
+  if (connection_speaks_cells(conn) &&
      now >= conn->timestamp_lastwritten + options->KeepalivePeriod) {
     routerinfo_t *router = router_get_by_digest(conn->identity_digest);
-    if((!connection_state_is_open(conn)) ||
+    if ((!connection_state_is_open(conn)) ||
        (we_are_hibernating() && !circuit_get_by_conn(conn)) ||
        (!clique_mode(options) && !circuit_get_by_conn(conn) &&
        (!router || !server_mode(options) || !router_is_clique_mode(router)))) {
@@ -465,24 +465,24 @@
   bw = rep_hist_bandwidth_assess();
   router_set_bandwidth_capacity(bw);
 
-  if(options->ClientOnly)
+  if (options->ClientOnly)
     return 0;
-  if(!options->ORPort)
+  if (!options->ORPort)
     return 0;
 
   /* XXX for now, you're only a server if you're a server */
   return server_mode(options);
 
   /* here, determine if we're reachable */
-  if(0) { /* we've recently failed to reach our IP/ORPort from the outside */
+  if (0) { /* we've recently failed to reach our IP/ORPort from the outside */
     return 0;
   }
 
-  if(bw < MIN_BW_TO_PUBLISH_DESC)
+  if (bw < MIN_BW_TO_PUBLISH_DESC)
     return 0;
-  if(options->AuthoritativeDir)
+  if (options->AuthoritativeDir)
     return 1;
-  if(stats_n_seconds_uptime < MIN_UPTIME_TO_PUBLISH_DESC)
+  if (stats_n_seconds_uptime < MIN_UPTIME_TO_PUBLISH_DESC)
     return 0;
 
   return 1;
@@ -549,7 +549,7 @@
     if (router_rebuild_descriptor(1)<0) {
       log_fn(LOG_WARN, "Couldn't rebuild router descriptor");
     }
-    if(advertised_server_mode())
+    if (advertised_server_mode())
       router_upload_dir_desc_to_dirservers(0);
   }
 
@@ -575,15 +575,15 @@
   /** 2. Periodically, we consider getting a new directory, getting a
    * new running-routers list, and/or force-uploading our descriptor
    * (if we've passed our internal checks). */
-  if(time_to_fetch_directory < now) {
+  if (time_to_fetch_directory < now) {
     /* purge obsolete entries */
     routerlist_remove_old_routers(ROUTER_MAX_AGE);
 
-    if(authdir_mode(options)) {
+    if (authdir_mode(options)) {
       /* We're a directory; dump any old descriptors. */
       dirserv_remove_old_servers(ROUTER_MAX_AGE);
     }
-    if(server_mode(options) && !we_are_hibernating()) {
+    if (server_mode(options) && !we_are_hibernating()) {
       /* dirservers try to reconnect, in case connections have failed;
        * and normal servers try to reconnect to dirservers */
       router_retry_connections();
@@ -607,7 +607,7 @@
   }
 
   if (time_to_force_upload_descriptor < now) {
-    if(decide_if_publishable_server(now)) {
+    if (decide_if_publishable_server(now)) {
       server_is_advertised = 1;
       router_rebuild_descriptor(1);
       router_upload_dir_desc_to_dirservers(1);
@@ -662,11 +662,11 @@
    *    that became dirty more than NewCircuitPeriod seconds ago,
    *    and we make a new circ if there are no clean circuits.
    */
-  if(has_fetched_directory && !we_are_hibernating())
+  if (has_fetched_directory && !we_are_hibernating())
     circuit_build_needed_circs(now);
 
   /** 5. We do housekeeping for each connection... */
-  for(i=0;i<nfds;i++) {
+  for (i=0;i<nfds;i++) {
     run_connection_housekeeping(i, now);
   }
 
@@ -674,14 +674,14 @@
   circuit_close_all_marked();
 
   /** 7. And upload service descriptors if necessary. */
-  if(!we_are_hibernating())
+  if (!we_are_hibernating())
     rend_consider_services_upload(now);
 
   /** 8. and blow away any connections that need to die. have to do this now,
    * because if we marked a conn for close and left its socket -1, then
    * we'll pass it to poll/select and bad things will happen.
    */
-  for(i=0;i<nfds;i++)
+  for (i=0;i<nfds;i++)
     conn_close_if_marked(i);
 }
 
@@ -697,7 +697,7 @@
 
   tor_gettimeofday(&now);
 
-  if(now.tv_sec > current_second) {
+  if (now.tv_sec > current_second) {
     /* the second has rolled over. check more stuff. */
     size_t bytes_written;
     size_t bytes_read;
@@ -724,9 +724,9 @@
     current_second = now.tv_sec; /* remember which second it is, for next time */
   }
 
-  for(i=0;i<nfds;i++) {
+  for (i=0;i<nfds;i++) {
     conn = connection_array[i];
-    if(connection_has_pending_tls_data(conn) &&
+    if (connection_has_pending_tls_data(conn) &&
        connection_is_reading(conn)) {
       log_fn(LOG_DEBUG,"sock %d has pending bytes.",conn->s);
       return 0; /* has pending bytes to read; don't let poll wait. */
@@ -754,17 +754,17 @@
     return -1;
   }
   options = get_options();
-  if(authdir_mode(options)) {
+  if (authdir_mode(options)) {
     /* reload the approved-routers file */
     tor_snprintf(keydir,sizeof(keydir),"%s/approved-routers", options->DataDirectory);
     log_fn(LOG_INFO,"Reloading approved fingerprints from %s...",keydir);
-    if(dirserv_parse_fingerprint_file(keydir) < 0) {
+    if (dirserv_parse_fingerprint_file(keydir) < 0) {
       log_fn(LOG_WARN, "Error reloading fingerprints. Continuing with old list.");
     }
   }
   /* Fetch a new directory. Even authdirservers do this. */
   directory_get_from_dirserver(DIR_PURPOSE_FETCH_DIR, NULL);
-  if(server_mode(options)) {
+  if (server_mode(options)) {
     /* Restart cpuworker and dnsworker processes, so they get up-to-date
      * configuration options. */
     cpuworkers_rotate();
@@ -801,21 +801,21 @@
   stats_prev_global_write_bucket = global_write_bucket;
 
   /* load the routers file, or assign the defaults. */
-  if(router_reload_router_list()) {
+  if (router_reload_router_list()) {
     return -1;
   }
 
-  if(authdir_mode(get_options())) {
+  if (authdir_mode(get_options())) {
     /* the directory is already here, run startup things */
     router_retry_connections();
   }
 
-  if(server_mode(get_options())) {
+  if (server_mode(get_options())) {
     /* launch cpuworkers. Need to do this *after* we've read the onion key. */
     cpu_init();
   }
 
-  for(;;) {
+  for (;;) {
 #ifdef MS_WINDOWS_SERVICE /* Do service stuff only on windows. */
     if (service_status.dwCurrentState == SERVICE_STOP_PENDING) {
       service_status.dwWin32ExitCode = 0;
@@ -826,7 +826,7 @@
 #endif
 #ifndef MS_WINDOWS /* do signal stuff only on unix */
     if (please_shutdown) {
-      if(!server_mode(get_options())) { /* do it now */
+      if (!server_mode(get_options())) { /* do it now */
         log(LOG_NOTICE,"Interrupt: exiting cleanly.");
         tor_cleanup();
         exit(0);
@@ -857,7 +857,7 @@
       please_reset = 0;
     }
     if (please_reap_children) {
-      while(waitpid(-1,NULL,WNOHANG) > 0) ; /* keep reaping until no more zombies */
+      while (waitpid(-1,NULL,WNOHANG) > 0) ; /* keep reaping until no more zombies */
       please_reap_children = 0;
     }
 #endif /* signal stuff */
@@ -871,7 +871,7 @@
     if (poll_result < 0) {
       int e = tor_socket_errno(-1);
       /* let the program survive things like ^z */
-      if(e != EINTR) {
+      if (e != EINTR) {
         log_fn(LOG_ERR,"poll failed: %s [%d]",
                tor_socket_strerror(e), e);
         return -1;
@@ -905,7 +905,7 @@
 static void catch(int the_signal) {
 
 #ifndef MS_WINDOWS /* do signal stuff only on unix */
-  switch(the_signal) {
+  switch (the_signal) {
 //    case SIGABRT:
     case SIGTERM:
       log(LOG_ERR,"Catching signal %d, exiting cleanly.", the_signal);
@@ -952,12 +952,12 @@
 
   log(severity, "Dumping stats:");
 
-  for(i=0;i<nfds;i++) {
+  for (i=0;i<nfds;i++) {
     conn = connection_array[i];
     log(severity, "Conn %d (socket %d) type %d (%s), state %d (%s), created %d secs ago",
       i, conn->s, conn->type, CONN_TYPE_TO_STRING(conn->type),
       conn->state, conn_state_to_string[conn->type][conn->state], (int)(now - conn->timestamp_created));
-    if(!connection_is_listener(conn)) {
+    if (!connection_is_listener(conn)) {
       log(severity,"Conn %d is to '%s:%d'.",i,conn->address, conn->port);
       log(severity,"Conn %d: %d bytes waiting on inbuf (last read %d secs ago)",i,
              (int)buf_datalen(conn->inbuf),
@@ -1050,7 +1050,7 @@
 #ifdef SIGXFSZ
   sigaction(SIGXFSZ, &action, NULL); /* handle file-too-big resource exhaustion */
 #endif
-  if(is_parent)
+  if (is_parent)
     sigaction(SIGCHLD, &action, NULL); /* handle dns/cpu workers that exit */
 #endif /* signal stuff */
 }
@@ -1081,11 +1081,11 @@
   }
 
 #ifndef MS_WINDOWS
-  if(geteuid()==0)
+  if (geteuid()==0)
     log_fn(LOG_WARN,"You are running Tor as root. You don't need to, and you probably shouldn't.");
 #endif
 
-  if(server_mode(get_options())) { /* only spawn dns handlers if we're a router */
+  if (server_mode(get_options())) { /* only spawn dns handlers if we're a router */
     dns_init(); /* initialize the dns resolve tree, and spawn workers */
   }
 
@@ -1101,7 +1101,7 @@
   or_options_t *options = get_options();
   /* Remove our pid file. We don't care if there was an error when we
    * unlink, nothing we could do about it anyways. */
-  if(options->PidFile && options->command == CMD_RUN_TOR)
+  if (options->PidFile && options->command == CMD_RUN_TOR)
     unlink(options->PidFile);
   crypto_global_cleanup();
   if (accounting_is_enabled(options))
@@ -1279,7 +1279,7 @@
     return 0;
   }
 
-  if((hService = CreateService(hSCManager, GENSRV_SERVICENAME, GENSRV_DISPLAYNAME,
+  if ((hService = CreateService(hSCManager, GENSRV_SERVICENAME, GENSRV_DISPLAYNAME,
     SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START,
     SERVICE_ERROR_IGNORE, command, NULL, NULL,
     NULL, NULL, NULL)) == NULL) {
@@ -1319,7 +1319,7 @@
   if (result) {
     while (QueryServiceStatus(hService, &service_status))
     {
-      if(service_status.dwCurrentState == SERVICE_STOP_PENDING)
+      if (service_status.dwCurrentState == SERVICE_STOP_PENDING)
         Sleep(500);
       else
         break;
@@ -1347,9 +1347,9 @@
 #ifdef MS_WINDOWS_SERVICE
   backup_argv = argv;
   backup_argc = argc;
-  if((argc >= 2) && !strcmp(argv[1], "-install"))
+  if ((argc >= 2) && !strcmp(argv[1], "-install"))
     return nt_service_install();
-  if((argc >= 2) && !strcmp(argv[1], "-remove"))
+  if ((argc >= 2) && !strcmp(argv[1], "-remove"))
     return nt_service_remove();
   nt_service_main();
   return 0;

Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/onion.c,v
retrieving revision 1.170
retrieving revision 1.171
diff -u -d -r1.170 -r1.171
--- onion.c	26 Nov 2004 04:00:53 -0000	1.170
+++ onion.c	28 Nov 2004 09:05:46 -0000	1.171
@@ -32,7 +32,7 @@
   tmp = tor_malloc_zero(sizeof(struct onion_queue_t));
   tmp->circ = circ;
 
-  if(!ol_tail) {
+  if (!ol_tail) {
     tor_assert(!ol_list);
     tor_assert(!ol_length);
     ol_list = tmp;
@@ -44,7 +44,7 @@
   tor_assert(ol_list);
   tor_assert(!ol_tail->next);
 
-  if(ol_length >= get_options()->MaxOnionsPending) {
+  if (ol_length >= get_options()->MaxOnionsPending) {
     log_fn(LOG_WARN,"Already have %d onions queued. Closing.", ol_length);
     tor_free(tmp);
     return -1;
@@ -62,7 +62,7 @@
 circuit_t *onion_next_task(void) {
   circuit_t *circ;
 
-  if(!ol_list)
+  if (!ol_list)
     return NULL; /* no onions pending, we're done */
 
   tor_assert(ol_list->circ);
@@ -79,28 +79,28 @@
 void onion_pending_remove(circuit_t *circ) {
   struct onion_queue_t *tmpo, *victim;
 
-  if(!ol_list)
+  if (!ol_list)
     return; /* nothing here. */
 
   /* first check to see if it's the first entry */
   tmpo = ol_list;
-  if(tmpo->circ == circ) {
+  if (tmpo->circ == circ) {
     /* it's the first one. remove it from the list. */
     ol_list = tmpo->next;
-    if(!ol_list)
+    if (!ol_list)
       ol_tail = NULL;
     ol_length--;
     victim = tmpo;
   } else { /* we need to hunt through the rest of the list */
-    for( ;tmpo->next && tmpo->next->circ != circ; tmpo=tmpo->next) ;
-    if(!tmpo->next) {
+    for ( ;tmpo->next && tmpo->next->circ != circ; tmpo=tmpo->next) ;
+    if (!tmpo->next) {
       log_fn(LOG_DEBUG,"circ (p_circ_id %d) not in list, probably at cpuworker.",circ->p_circ_id);
       return;
     }
     /* now we know tmpo->next->circ == circ */
     victim = tmpo->next;
     tmpo->next = victim->next;
-    if(ol_tail == victim)
+    if (ol_tail == victim)
       ol_tail = tmpo;
     ol_length--;
   }
@@ -295,7 +295,7 @@
   if (len < 0)
     return -1;
 
-  if(memcmp(key_material, handshake_reply+DH_KEY_LEN, 20)) {
+  if (memcmp(key_material, handshake_reply+DH_KEY_LEN, 20)) {
     /* H(K) does *not* match. Something fishy. */
     tor_free(key_material);
     log_fn(LOG_WARN,"Digest DOES NOT MATCH on onion handshake. Bug or attack.");

Index: relay.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/relay.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- relay.c	28 Nov 2004 06:33:14 -0000	1.26
+++ relay.c	28 Nov 2004 09:05:46 -0000	1.27
@@ -81,7 +81,7 @@
   crypto_digest_add_bytes(digest, cell->payload, CELL_PAYLOAD_SIZE);
   crypto_digest_get_digest(digest, calculated_integrity, 4);
 
-  if(memcmp(received_integrity, calculated_integrity, 4)) {
+  if (memcmp(received_integrity, calculated_integrity, 4)) {
 //    log_fn(LOG_INFO,"Recognized=0 but bad digest. Not recognizing.");
 // (%d vs %d).", received_integrity, calculated_integrity);
     /* restore digest to its old form */
@@ -110,7 +110,7 @@
 
   relay_header_unpack(&rh, in);
 //  log_fn(LOG_DEBUG,"before crypt: %d",rh.recognized);
-  if(( encrypt_mode && crypto_cipher_encrypt(cipher, out, in, CELL_PAYLOAD_SIZE)) ||
+  if (( encrypt_mode && crypto_cipher_encrypt(cipher, out, in, CELL_PAYLOAD_SIZE)) ||
      (!encrypt_mode && crypto_cipher_decrypt(cipher, out, in, CELL_PAYLOAD_SIZE))) {
     log_fn(LOG_WARN,"Error during relay encryption");
     return -1;
@@ -143,14 +143,14 @@
   if (circ->marked_for_close)
     return 0;
 
-  if(relay_crypt(circ, cell, cell_direction, &layer_hint, &recognized) < 0) {
+  if (relay_crypt(circ, cell, cell_direction, &layer_hint, &recognized) < 0) {
     log_fn(LOG_WARN,"relay crypt failed. Dropping connection.");
     return -1;
   }
 
-  if(recognized) {
+  if (recognized) {
     conn = relay_lookup_conn(circ, cell, cell_direction);
-    if(cell_direction == CELL_DIRECTION_OUT) {
+    if (cell_direction == CELL_DIRECTION_OUT) {
       ++stats_n_relay_cells_delivered;
       log_fn(LOG_DEBUG,"Sending away from origin.");
       if (connection_edge_process_relay_cell(cell, circ, conn, NULL) < 0) {
@@ -158,7 +158,7 @@
         return -1;
       }
     }
-    if(cell_direction == CELL_DIRECTION_IN) {
+    if (cell_direction == CELL_DIRECTION_IN) {
       ++stats_n_relay_cells_delivered;
       log_fn(LOG_DEBUG,"Sending to origin.");
       if (connection_edge_process_relay_cell(cell, circ, conn, layer_hint) < 0) {
@@ -170,7 +170,7 @@
   }
 
   /* not recognized. pass it on. */
-  if(cell_direction == CELL_DIRECTION_OUT) {
+  if (cell_direction == CELL_DIRECTION_OUT) {
     cell->circ_id = circ->n_circ_id; /* switch it */
     conn = circ->n_conn;
   } else {
@@ -178,7 +178,7 @@
     conn = circ->p_conn;
   }
 
-  if(!conn) {
+  if (!conn) {
     if (circ->rend_splice && cell_direction == CELL_DIRECTION_OUT) {
       tor_assert(circ->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED);
       tor_assert(circ->rend_splice->purpose == CIRCUIT_PURPOSE_REND_ESTABLISHED);
@@ -229,25 +229,25 @@
   tor_assert(cell_direction == CELL_DIRECTION_IN ||
              cell_direction == CELL_DIRECTION_OUT);
 
-  if(cell_direction == CELL_DIRECTION_IN) {
-    if(CIRCUIT_IS_ORIGIN(circ)) { /* We're at the beginning of the circuit.
+  if (cell_direction == CELL_DIRECTION_IN) {
+    if (CIRCUIT_IS_ORIGIN(circ)) { /* We're at the beginning of the circuit.
                                      We'll want to do layered decrypts. */
       tor_assert(circ->cpath);
       thishop = circ->cpath;
-      if(thishop->state != CPATH_STATE_OPEN) {
+      if (thishop->state != CPATH_STATE_OPEN) {
         log_fn(LOG_WARN,"Relay cell before first created cell? Closing.");
         return -1;
       }
       do { /* Remember: cpath is in forward order, that is, first hop first. */
         tor_assert(thishop);
 
-        if(relay_crypt_one_payload(thishop->b_crypto, cell->payload, 0) < 0)
+        if (relay_crypt_one_payload(thishop->b_crypto, cell->payload, 0) < 0)
           return -1;
 
         relay_header_unpack(&rh, cell->payload);
-        if(rh.recognized == 0) {
+        if (rh.recognized == 0) {
           /* it's possibly recognized. have to check digest to be sure. */
-          if(relay_digest_matches(thishop->b_digest, cell)) {
+          if (relay_digest_matches(thishop->b_digest, cell)) {
             *recognized = 1;
             *layer_hint = thishop;
             return 0;
@@ -255,24 +255,24 @@
         }
 
         thishop = thishop->next;
-      } while(thishop != circ->cpath && thishop->state == CPATH_STATE_OPEN);
+      } while (thishop != circ->cpath && thishop->state == CPATH_STATE_OPEN);
       log_fn(LOG_WARN,"in-cell at OP not recognized. Closing.");
       return -1;
     } else { /* we're in the middle. Just one crypt. */
-      if(relay_crypt_one_payload(circ->p_crypto, cell->payload, 1) < 0)
+      if (relay_crypt_one_payload(circ->p_crypto, cell->payload, 1) < 0)
         return -1;
 //      log_fn(LOG_DEBUG,"Skipping recognized check, because we're not the OP.");
     }
   } else /* cell_direction == CELL_DIRECTION_OUT */ {
     /* we're in the middle. Just one crypt. */
 
-    if(relay_crypt_one_payload(circ->n_crypto, cell->payload, 0) < 0)
+    if (relay_crypt_one_payload(circ->n_crypto, cell->payload, 0) < 0)
       return -1;
 
     relay_header_unpack(&rh, cell->payload);
     if (rh.recognized == 0) {
       /* it's possibly recognized. have to check digest to be sure. */
-      if(relay_digest_matches(circ->n_digest, cell)) {
+      if (relay_digest_matches(circ->n_digest, cell)) {
         *recognized = 1;
         return 0;
       }
@@ -293,9 +293,9 @@
   connection_t *conn; /* where to send the cell */
   crypt_path_t *thishop; /* counter for repeated crypts */
 
-  if(cell_direction == CELL_DIRECTION_OUT) {
+  if (cell_direction == CELL_DIRECTION_OUT) {
     conn = circ->n_conn;
-    if(!conn) {
+    if (!conn) {
       log_fn(LOG_WARN,"outgoing relay cell has n_conn==NULL. Dropping.");
       return 0; /* just drop it */
     }
@@ -307,7 +307,7 @@
       tor_assert(thishop);
 
       log_fn(LOG_DEBUG,"crypting a layer of the relay cell.");
-      if(relay_crypt_one_payload(thishop->f_crypto, cell->payload, 1) < 0) {
+      if (relay_crypt_one_payload(thishop->f_crypto, cell->payload, 1) < 0) {
         return -1;
       }
 
@@ -316,12 +316,12 @@
 
   } else { /* incoming cell */
     conn = circ->p_conn;
-    if(!conn) {
+    if (!conn) {
       log_fn(LOG_WARN,"incoming relay cell has p_conn==NULL. Dropping.");
       return 0; /* just drop it */
     }
     relay_set_digest(circ->p_digest, cell);
-    if(relay_crypt_one_payload(circ->p_crypto, cell->payload, 1) < 0)
+    if (relay_crypt_one_payload(circ->p_crypto, cell->payload, 1) < 0)
       return -1;
   }
   ++stats_n_relay_cells_relayed;
@@ -340,29 +340,29 @@
 
   relay_header_unpack(&rh, cell->payload);
 
-  if(!rh.stream_id)
+  if (!rh.stream_id)
     return NULL;
 
   /* IN or OUT cells could have come from either direction, now
    * that we allow rendezvous *to* an OP.
    */
 
-  for(tmpconn = circ->n_streams; tmpconn; tmpconn=tmpconn->next_stream) {
-    if(rh.stream_id == tmpconn->stream_id) {
+  for (tmpconn = circ->n_streams; tmpconn; tmpconn=tmpconn->next_stream) {
+    if (rh.stream_id == tmpconn->stream_id) {
       log_fn(LOG_DEBUG,"found conn for stream %d.", rh.stream_id);
-      if(cell_direction == CELL_DIRECTION_OUT ||
+      if (cell_direction == CELL_DIRECTION_OUT ||
          connection_edge_is_rendezvous_stream(tmpconn))
         return tmpconn;
     }
   }
-  for(tmpconn = circ->p_streams; tmpconn; tmpconn=tmpconn->next_stream) {
-    if(rh.stream_id == tmpconn->stream_id) {
+  for (tmpconn = circ->p_streams; tmpconn; tmpconn=tmpconn->next_stream) {
+    if (rh.stream_id == tmpconn->stream_id) {
       log_fn(LOG_DEBUG,"found conn for stream %d.", rh.stream_id);
       return tmpconn;
     }
   }
-  for(tmpconn = circ->resolving_streams; tmpconn; tmpconn=tmpconn->next_stream) {
-    if(rh.stream_id == tmpconn->stream_id) {
+  for (tmpconn = circ->resolving_streams; tmpconn; tmpconn=tmpconn->next_stream) {
+    if (rh.stream_id == tmpconn->stream_id) {
       log_fn(LOG_DEBUG,"found conn for stream %d.", rh.stream_id);
       return tmpconn;
     }
@@ -411,7 +411,7 @@
   relay_header_t rh;
   int cell_direction;
 
-  if(!circ) {
+  if (!circ) {
     log_fn(LOG_WARN,"no circ. Closing conn.");
     tor_assert(fromconn);
     fromconn->has_sent_end = 1; /* no circ to send to */
@@ -421,7 +421,7 @@
 
   memset(&cell, 0, sizeof(cell_t));
   cell.command = CELL_RELAY;
-  if(cpath_layer) {
+  if (cpath_layer) {
     cell.circ_id = circ->n_circ_id;
     cell_direction = CELL_DIRECTION_OUT;
   } else {
@@ -431,17 +431,17 @@
 
   memset(&rh, 0, sizeof(rh));
   rh.command = relay_command;
-  if(fromconn)
+  if (fromconn)
     rh.stream_id = fromconn->stream_id; /* else it's 0 */
   rh.length = payload_len;
   relay_header_pack(cell.payload, &rh);
-  if(payload_len)
+  if (payload_len)
     memcpy(cell.payload+RELAY_HEADER_SIZE, payload, payload_len);
 
   log_fn(LOG_DEBUG,"delivering %d cell %s.", relay_command,
          cell_direction == CELL_DIRECTION_OUT ? "forward" : "backward");
 
-  if(circuit_package_relay_cell(&cell, circ, cell_direction, cpath_layer) < 0) {
+  if (circuit_package_relay_cell(&cell, circ, cell_direction, cpath_layer) < 0) {
     log_fn(LOG_WARN,"circuit_package_relay_cell failed. Closing.");
     circuit_mark_for_close(circ);
     return -1;
@@ -455,15 +455,15 @@
  */
 static const char *
 connection_edge_end_reason(char *payload, uint16_t length) {
-  if(length < 1) {
+  if (length < 1) {
     log_fn(LOG_WARN,"End cell arrived with length 0. Should be at least 1.");
     return "MALFORMED";
   }
-  if(*payload < _MIN_END_STREAM_REASON || *payload > _MAX_END_STREAM_REASON) {
+  if (*payload < _MIN_END_STREAM_REASON || *payload > _MAX_END_STREAM_REASON) {
     log_fn(LOG_WARN,"Reason for ending (%d) not recognized.",*payload);
     return "MALFORMED";
   }
-  switch(*payload) {
+  switch (*payload) {
     case END_STREAM_REASON_MISC:           return "misc error";
     case END_STREAM_REASON_RESOLVEFAILED:  return "resolve failed";
     case END_STREAM_REASON_CONNECTFAILED:  return "connect failed";
@@ -496,16 +496,16 @@
   int reason;
   routerinfo_t *exitrouter;
 
-  if(rh->command == RELAY_COMMAND_END) {
+  if (rh->command == RELAY_COMMAND_END) {
     reason = *(cell->payload+RELAY_HEADER_SIZE);
     /* We have to check this here, since we aren't connected yet. */
     if (rh->length >= 5 && reason == END_STREAM_REASON_EXITPOLICY) {
-      if(conn->type != CONN_TYPE_AP) {
+      if (conn->type != CONN_TYPE_AP) {
         log_fn(LOG_WARN,"Got an end because of exitpolicy, but we're not an AP. Closing.");
         return -1;
       }
       addr = ntohl(get_uint32(cell->payload+RELAY_HEADER_SIZE+1));
-      if(addr) {
+      if (addr) {
         log_fn(LOG_INFO,"Address %s refused due to exit policy. Retrying.",
                conn->socks_request->address);
       } else {
@@ -519,11 +519,11 @@
 
       /* check if he *ought* to have allowed it */
       exitrouter = router_get_by_digest(circ->build_state->chosen_exit_digest);
-      if(!exitrouter) {
+      if (!exitrouter) {
         log_fn(LOG_INFO,"Skipping broken circ (exit router vanished)");
         return 0; /* this circuit is screwed and doesn't know it yet */
       }
-      if(connection_ap_can_use_exit(conn, exitrouter)) {
+      if (connection_ap_can_use_exit(conn, exitrouter)) {
         log_fn(LOG_WARN,"Exitrouter %s seems to be more restrictive than its exit policy. Not using this router as exit for now,", exitrouter->nickname);
         addr_policy_free(exitrouter->exit_policy);
         exitrouter->exit_policy =
@@ -532,7 +532,7 @@
 
       conn->state = AP_CONN_STATE_CIRCUIT_WAIT;
       circuit_detach_stream(circ,conn);
-      if(connection_ap_handshake_attach_circuit(conn) >= 0)
+      if (connection_ap_handshake_attach_circuit(conn) >= 0)
         return 0;
       log_fn(LOG_INFO,"Giving up on retrying (from exitpolicy); conn can't be handled.");
       /* else, conn will get closed below */
@@ -549,7 +549,7 @@
         circ->timestamp_dirty -= get_options()->NewCircuitPeriod;
         /* make sure not to expire/retry the stream quite yet */
         conn->timestamp_lastread = time(NULL);
-        if(connection_ap_handshake_attach_circuit(conn) >= 0)
+        if (connection_ap_handshake_attach_circuit(conn) >= 0)
           return 0;
         /* else, conn will get closed below */
         log_fn(LOG_INFO,"Giving up on retrying (from resolvefailed); conn can't be handled.");
@@ -560,15 +560,15 @@
     }
     log_fn(LOG_INFO,"Edge got end (%s) before we're connected. Marking for close.",
       connection_edge_end_reason(cell->payload+RELAY_HEADER_SIZE, rh->length));
-    if(CIRCUIT_IS_ORIGIN(circ))
+    if (CIRCUIT_IS_ORIGIN(circ))
       circuit_log_path(LOG_INFO,circ);
     conn->has_sent_end = 1; /* we just got an 'end', don't need to send one */
     connection_mark_for_close(conn);
     return 0;
   }
 
-  if(conn->type == CONN_TYPE_AP && rh->command == RELAY_COMMAND_CONNECTED) {
-    if(conn->state != AP_CONN_STATE_CONNECT_WAIT) {
+  if (conn->type == CONN_TYPE_AP && rh->command == RELAY_COMMAND_CONNECTED) {
+    if (conn->state != AP_CONN_STATE_CONNECT_WAIT) {
       log_fn(LOG_WARN,"Got 'connected' while not in state connect_wait. Dropping.");
       return 0;
     }
@@ -578,7 +578,7 @@
            (int)(time(NULL) - conn->timestamp_lastread));
     if (rh->length >= 4) {
       addr = ntohl(get_uint32(cell->payload+RELAY_HEADER_SIZE));
-      if(!addr) {
+      if (!addr) {
         log_fn(LOG_INFO,"...but it claims the IP address was 0.0.0.0. Closing.");
         connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
         connection_mark_for_close(conn);
@@ -597,7 +597,7 @@
     }
     return 0;
   }
-  if(conn->type == CONN_TYPE_AP && rh->command == RELAY_COMMAND_RESOLVED) {
+  if (conn->type == CONN_TYPE_AP && rh->command == RELAY_COMMAND_RESOLVED) {
     if (conn->state != AP_CONN_STATE_RESOLVE_WAIT) {
       log_fn(LOG_WARN,"Got a 'resolved' cell while not in state resolve_wait. Dropping.");
       return 0;
@@ -654,14 +654,14 @@
   /* either conn is NULL, in which case we've got a control cell, or else
    * conn points to the recognized stream. */
 
-  if(conn &&
+  if (conn &&
      conn->state != AP_CONN_STATE_OPEN &&
      conn->state != EXIT_CONN_STATE_OPEN) {
     return connection_edge_process_relay_cell_not_open(
              &rh, cell, circ, conn, layer_hint);
   }
 
-  switch(rh.command) {
+  switch (rh.command) {
     case RELAY_COMMAND_DROP:
       log_fn(LOG_INFO,"Got a relay-level padding cell. Dropping.");
       return 0;
@@ -671,7 +671,7 @@
         log_fn(LOG_WARN,"relay begin request unsupported at AP. Dropping.");
         return 0;
       }
-      if(conn) {
+      if (conn) {
         log_fn(LOG_WARN,"begin cell for known stream. Dropping.");
         return 0;
       }
@@ -679,7 +679,7 @@
       return 0;
     case RELAY_COMMAND_DATA:
       ++stats_n_data_cells_received;
-      if((layer_hint && --layer_hint->deliver_window < 0) ||
+      if ((layer_hint && --layer_hint->deliver_window < 0) ||
          (!layer_hint && --circ->deliver_window < 0)) {
         log_fn(LOG_WARN,"(relay data) circ deliver_window below 0. Killing.");
         connection_edge_end(conn, END_STREAM_REASON_MISC, conn->cpath_layer);
@@ -691,18 +691,18 @@
 
       circuit_consider_sending_sendme(circ, layer_hint);
 
-      if(!conn) {
+      if (!conn) {
         log_fn(LOG_INFO,"data cell dropped, unknown stream.");
         return 0;
       }
 
-      if(--conn->deliver_window < 0) { /* is it below 0 after decrement? */
+      if (--conn->deliver_window < 0) { /* is it below 0 after decrement? */
         log_fn(LOG_WARN,"(relay data) conn deliver_window below 0. Killing.");
         return -1; /* somebody's breaking protocol. kill the whole circuit. */
       }
 
       stats_n_data_bytes_received += rh.length;
-      if(conn->type == CONN_TYPE_AP) {
+      if (conn->type == CONN_TYPE_AP) {
         conn->stream_size += rh.length;
         log_fn(LOG_DEBUG,"%d: stream size now %d.", conn->s, (int)conn->stream_size);
       }
@@ -711,7 +711,7 @@
       connection_edge_consider_sending_sendme(conn);
       return 0;
     case RELAY_COMMAND_END:
-      if(!conn) {
+      if (!conn) {
         log_fn(LOG_INFO,"end cell (%s) dropped, unknown stream.",
           connection_edge_end_reason(cell->payload+RELAY_HEADER_SIZE, rh.length));
         return 0;
@@ -734,7 +734,7 @@
 #else
       /* We just *got* an end; no reason to send one. */
       conn->has_sent_end = 1;
-      if(!conn->marked_for_close) {
+      if (!conn->marked_for_close) {
         /* only mark it if not already marked. it's possible to
          * get the 'end' right around when the client hangs up on us. */
         connection_mark_for_close(conn);
@@ -743,18 +743,18 @@
 #endif
       return 0;
     case RELAY_COMMAND_EXTEND:
-      if(conn) {
+      if (conn) {
         log_fn(LOG_WARN,"'extend' for non-zero stream. Dropping.");
         return 0;
       }
       return circuit_extend(cell, circ);
     case RELAY_COMMAND_EXTENDED:
-      if(!layer_hint) {
+      if (!layer_hint) {
         log_fn(LOG_WARN,"'extended' unsupported at non-origin. Dropping.");
         return 0;
       }
       log_fn(LOG_DEBUG,"Got an extended cell! Yay.");
-      if(circuit_finish_handshake(circ, cell->payload+RELAY_HEADER_SIZE) < 0) {
+      if (circuit_finish_handshake(circ, cell->payload+RELAY_HEADER_SIZE) < 0) {
         log_fn(LOG_WARN,"circuit_finish_handshake failed.");
         return -1;
       }
@@ -764,11 +764,11 @@
       }
       return 0;
     case RELAY_COMMAND_TRUNCATE:
-      if(layer_hint) {
+      if (layer_hint) {
         log_fn(LOG_WARN,"'truncate' unsupported at origin. Dropping.");
         return 0;
       }
-      if(circ->n_conn) {
+      if (circ->n_conn) {
         connection_send_destroy(circ->n_circ_id, circ->n_conn);
         circ->n_conn = NULL;
       }
@@ -777,22 +777,22 @@
                                    NULL, 0, NULL);
       return 0;
     case RELAY_COMMAND_TRUNCATED:
-      if(!layer_hint) {
+      if (!layer_hint) {
         log_fn(LOG_WARN,"'truncated' unsupported at non-origin. Dropping.");
         return 0;
       }
       circuit_truncated(circ, layer_hint);
       return 0;
     case RELAY_COMMAND_CONNECTED:
-      if(conn) {
+      if (conn) {
         log_fn(LOG_WARN,"'connected' unsupported while open. Closing circ.");
         return -1;
       }
       log_fn(LOG_INFO,"'connected' received, no conn attached anymore. Ignoring.");
       return 0;
     case RELAY_COMMAND_SENDME:
-      if(!conn) {
-        if(layer_hint) {
+      if (!conn) {
+        if (layer_hint) {
           layer_hint->package_window += CIRCWINDOW_INCREMENT;
           log_fn(LOG_DEBUG,"circ-level sendme at origin, packagewindow %d.",
                  layer_hint->package_window);
@@ -825,7 +825,7 @@
       connection_exit_begin_resolve(cell, circ);
       return 0;
     case RELAY_COMMAND_RESOLVED:
-      if(conn) {
+      if (conn) {
         log_fn(LOG_WARN,"'resolved' unsupported while open. Closing circ.");
         return -1;
       }
@@ -870,15 +870,15 @@
 repeat_connection_edge_package_raw_inbuf:
 
   circ = circuit_get_by_conn(conn);
-  if(!circ) {
+  if (!circ) {
     log_fn(LOG_INFO,"conn has no circuits! Closing.");
     return -1;
   }
 
-  if(circuit_consider_stop_edge_reading(circ, conn->cpath_layer))
+  if (circuit_consider_stop_edge_reading(circ, conn->cpath_layer))
     return 0;
 
-  if(conn->package_window <= 0) {
+  if (conn->package_window <= 0) {
     log_fn(LOG_INFO,"called with package_window %d. Skipping.", conn->package_window);
     connection_stop_reading(conn);
     return 0;
@@ -909,11 +909,11 @@
     log_fn(LOG_DEBUG,"%d: Stream size now %d.", conn->s, (int)conn->stream_size);
   }
 
-  if(connection_edge_send_command(conn, circ, RELAY_COMMAND_DATA,
+  if (connection_edge_send_command(conn, circ, RELAY_COMMAND_DATA,
                                payload, length, conn->cpath_layer) < 0)
     return 0; /* circuit is closed, don't continue */
 
-  if(!conn->cpath_layer) { /* non-rendezvous exit */
+  if (!conn->cpath_layer) { /* non-rendezvous exit */
     tor_assert(circ->package_window > 0);
     circ->package_window--;
   } else { /* we're an AP, or an exit on a rendezvous circ */
@@ -921,7 +921,7 @@
     conn->cpath_layer->package_window--;
   }
 
-  if(--conn->package_window <= 0) { /* is it 0 after decrement? */
+  if (--conn->package_window <= 0) { /* is it 0 after decrement? */
     connection_stop_reading(conn);
     log_fn(LOG_DEBUG,"conn->package_window reached 0.");
     circuit_consider_stop_edge_reading(circ, conn->cpath_layer);
@@ -942,21 +942,21 @@
 void connection_edge_consider_sending_sendme(connection_t *conn) {
   circuit_t *circ;
 
-  if(connection_outbuf_too_full(conn))
+  if (connection_outbuf_too_full(conn))
     return;
 
   circ = circuit_get_by_conn(conn);
-  if(!circ) {
+  if (!circ) {
     /* this can legitimately happen if the destroy has already
      * arrived and torn down the circuit */
     log_fn(LOG_INFO,"No circuit associated with conn. Skipping.");
     return;
   }
 
-  while(conn->deliver_window < STREAMWINDOW_START - STREAMWINDOW_INCREMENT) {
+  while (conn->deliver_window < STREAMWINDOW_START - STREAMWINDOW_INCREMENT) {
     log_fn(LOG_DEBUG,"Outbuf %d, Queueing stream sendme.", (int)conn->outbuf_flushlen);
     conn->deliver_window += STREAMWINDOW_INCREMENT;
-    if(connection_edge_send_command(conn, circ, RELAY_COMMAND_SENDME,
+    if (connection_edge_send_command(conn, circ, RELAY_COMMAND_SENDME,
                                     NULL, 0, conn->cpath_layer) < 0) {
       log_fn(LOG_WARN,"connection_edge_send_command failed. Returning.");
       return; /* the circuit's closed, don't continue */
@@ -976,7 +976,7 @@
   log_fn(LOG_DEBUG,"resuming");
 
   /* have to check both n_streams and p_streams, to handle rendezvous */
-  if(circuit_resume_edge_reading_helper(circ->n_streams, circ, layer_hint) >= 0)
+  if (circuit_resume_edge_reading_helper(circ->n_streams, circ, layer_hint) >= 0)
     circuit_resume_edge_reading_helper(circ->p_streams, circ, layer_hint);
 }
 
@@ -989,8 +989,8 @@
                                    circuit_t *circ,
                                    crypt_path_t *layer_hint) {
 
-  for( ; conn; conn=conn->next_stream) {
-    if((!layer_hint && conn->package_window > 0) ||
+  for ( ; conn; conn=conn->next_stream) {
+    if ((!layer_hint && conn->package_window > 0) ||
        (layer_hint && conn->package_window > 0 && conn->cpath_layer == layer_hint)) {
       connection_start_reading(conn);
       /* handle whatever might still be on the inbuf */
@@ -999,7 +999,7 @@
       /* If the circuit won't accept any more data, return without looking
        * at any more of the streams. Any connections that should be stopped
        * have already been stopped by connection_edge_package_raw_inbuf. */
-      if(circuit_consider_stop_edge_reading(circ, layer_hint))
+      if (circuit_consider_stop_edge_reading(circ, layer_hint))
         return -1;
     }
   }
@@ -1021,7 +1021,7 @@
     log_fn(LOG_DEBUG,"considering circ->package_window %d", circ->package_window);
     if (circ->package_window <= 0) {
       log_fn(LOG_DEBUG,"yes, not-at-origin. stopped.");
-      for(conn = circ->n_streams; conn; conn=conn->next_stream)
+      for (conn = circ->n_streams; conn; conn=conn->next_stream)
         connection_stop_reading(conn);
       return 1;
     }
@@ -1031,11 +1031,11 @@
   log_fn(LOG_DEBUG,"considering layer_hint->package_window %d", layer_hint->package_window);
   if (layer_hint->package_window <= 0) {
     log_fn(LOG_DEBUG,"yes, at-origin. stopped.");
-    for(conn = circ->n_streams; conn; conn=conn->next_stream)
-      if(conn->cpath_layer == layer_hint)
+    for (conn = circ->n_streams; conn; conn=conn->next_stream)
+      if (conn->cpath_layer == layer_hint)
         connection_stop_reading(conn);
-    for(conn = circ->p_streams; conn; conn=conn->next_stream)
-      if(conn->cpath_layer == layer_hint)
+    for (conn = circ->p_streams; conn; conn=conn->next_stream)
+      if (conn->cpath_layer == layer_hint)
         connection_stop_reading(conn);
     return 1;
   }
@@ -1053,14 +1053,14 @@
 {
 //  log_fn(LOG_INFO,"Considering: layer_hint is %s",
 //         layer_hint ? "defined" : "null");
-  while((layer_hint ? layer_hint->deliver_window : circ->deliver_window) <
+  while ((layer_hint ? layer_hint->deliver_window : circ->deliver_window) <
          CIRCWINDOW_START - CIRCWINDOW_INCREMENT) {
     log_fn(LOG_DEBUG,"Queueing circuit sendme.");
-    if(layer_hint)
+    if (layer_hint)
       layer_hint->deliver_window += CIRCWINDOW_INCREMENT;
     else
       circ->deliver_window += CIRCWINDOW_INCREMENT;
-    if(connection_edge_send_command(NULL, circ, RELAY_COMMAND_SENDME,
+    if (connection_edge_send_command(NULL, circ, RELAY_COMMAND_SENDME,
                                     NULL, 0, layer_hint) < 0) {
       log_fn(LOG_WARN,"connection_edge_send_command failed. Circuit's closed.");
       return; /* the circuit's closed, don't continue */

Index: rendclient.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/rendclient.c,v
retrieving revision 1.65
retrieving revision 1.66
diff -u -d -r1.65 -r1.66
--- rendclient.c	26 Nov 2004 04:00:54 -0000	1.65
+++ rendclient.c	28 Nov 2004 09:05:46 -0000	1.66
@@ -64,7 +64,7 @@
   tor_assert(rendcirc->purpose == CIRCUIT_PURPOSE_C_REND_READY);
   tor_assert(!rend_cmp_service_ids(introcirc->rend_query, rendcirc->rend_query));
 
-  if(rend_cache_lookup_entry(introcirc->rend_query, &entry) < 1) {
+  if (rend_cache_lookup_entry(introcirc->rend_query, &entry) < 1) {
     log_fn(LOG_WARN,"query '%s' didn't have valid rend desc in cache. Failing.",
            introcirc->rend_query);
     goto err;
@@ -191,7 +191,7 @@
     log_fn(LOG_INFO,"Received ack. Telling rend circ.");
     rendcirc = circuit_get_by_rend_query_and_purpose(
                circ->rend_query, CIRCUIT_PURPOSE_C_REND_READY);
-    if(rendcirc) { /* remember the ack */
+    if (rendcirc) { /* remember the ack */
       rendcirc->purpose = CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED;
     }
     /* close the circuit: we won't need it anymore. */
@@ -204,7 +204,7 @@
      * points. If any remain, extend to a new one and try again.
      * If none remain, refetch the service descriptor.
      */
-    if(rend_client_remove_intro_point(circ->build_state->chosen_exit_name,
+    if (rend_client_remove_intro_point(circ->build_state->chosen_exit_name,
                                       circ->rend_query) > 0) {
       /* There are introduction points left. re-extend the circuit to
        * another intro point and try again. */
@@ -242,7 +242,7 @@
 void
 rend_client_refetch_renddesc(const char *query)
 {
-  if(connection_get_by_type_rendquery(CONN_TYPE_DIR, query)) {
+  if (connection_get_by_type_rendquery(CONN_TYPE_DIR, query)) {
     log_fn(LOG_INFO,"Would fetch a new renddesc here (for %s), but one is already in progress.", query);
   } else {
     /* not one already; initiate a dir rend desc lookup */
@@ -282,7 +282,7 @@
     }
   }
 
-  if(!ent->parsed->n_intro_points) {
+  if (!ent->parsed->n_intro_points) {
     log_fn(LOG_INFO,"No more intro points remain for %s. Re-fetching descriptor.", query);
     rend_client_refetch_renddesc(query);
     return 0;
@@ -298,7 +298,7 @@
 rend_client_rendezvous_acked(circuit_t *circ, const char *request, size_t request_len)
 {
   /* we just got an ack for our establish-rendezvous. switch purposes. */
-  if(circ->purpose != CIRCUIT_PURPOSE_C_ESTABLISH_REND) {
+  if (circ->purpose != CIRCUIT_PURPOSE_C_ESTABLISH_REND) {
     log_fn(LOG_WARN,"Got a rendezvous ack when we weren't expecting one. Closing circ.");
     circuit_mark_for_close(circ);
     return -1;
@@ -315,7 +315,7 @@
   crypt_path_t *hop;
   char keys[DIGEST_LEN+CPATH_KEY_MATERIAL_LEN];
 
-  if( (circ->purpose != CIRCUIT_PURPOSE_C_REND_READY &&
+  if ( (circ->purpose != CIRCUIT_PURPOSE_C_REND_READY &&
        circ->purpose != CIRCUIT_PURPOSE_C_REND_READY_INTRO_ACKED)
       || !circ->build_state->pending_final_cpath) {
     log_fn(LOG_WARN,"Got rendezvous2 cell from Bob, but not expecting it. Closing.");
@@ -388,7 +388,7 @@
     if (rend_cmp_service_ids(conn->rend_query, query))
       continue;
     /* great, this guy was waiting */
-    if(status!=0 ||
+    if (status!=0 ||
        rend_cache_lookup_entry(conn->rend_query, &entry) == 1) {
       /* either this fetch worked, or it failed but there was a
        * valid entry from before which we should reuse */
@@ -418,7 +418,7 @@
   char *nickname;
   rend_cache_entry_t *entry;
 
-  if(rend_cache_lookup_entry(query, &entry) < 1) {
+  if (rend_cache_lookup_entry(query, &entry) < 1) {
     log_fn(LOG_WARN,"query '%s' didn't have valid rend desc in cache. Failing.", query);
     return NULL;
   }
@@ -426,11 +426,11 @@
   sl = smartlist_create();
 
   /* add the intro point nicknames */
-  for(i=0;i<entry->parsed->n_intro_points;i++)
+  for (i=0;i<entry->parsed->n_intro_points;i++)
     smartlist_add(sl,entry->parsed->intro_points[i]);
 
   choice = smartlist_choose(sl);
-  if(!choice) {
+  if (!choice) {
     smartlist_free(sl);
     return NULL;
   }
@@ -448,15 +448,15 @@
   char query[REND_SERVICE_ID_LEN+1];
 
   s = strrchr(address,'.');
-  if(!s) return -1; /* no dot */
+  if (!s) return -1; /* no dot */
   if (strcasecmp(s+1,"onion"))
     return -1; /* not .onion */
 
   *s = 0; /* null terminate it */
-  if(strlcpy(query, address, REND_SERVICE_ID_LEN+1) >= REND_SERVICE_ID_LEN+1)
+  if (strlcpy(query, address, REND_SERVICE_ID_LEN+1) >= REND_SERVICE_ID_LEN+1)
     goto failed;
   tor_strlower(query);
-  if(rend_valid_service_id(query)) {
+  if (rend_valid_service_id(query)) {
     tor_strlower(address);
     return 0; /* success */
   }

Index: rendcommon.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/rendcommon.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- rendcommon.c	26 Nov 2004 04:00:54 -0000	1.41
+++ rendcommon.c	28 Nov 2004 09:05:46 -0000	1.42
@@ -196,7 +196,7 @@
 /** Return true iff <b>query</b> is a syntactically valid service ID (as
  * generated by rend_get_service_id).  */
 int rend_valid_service_id(const char *query) {
-  if(strlen(query) != REND_SERVICE_ID_LEN)
+  if (strlen(query) != REND_SERVICE_ID_LEN)
     return 0;
 
   if (strspn(query, BASE32_CHARS) != REND_SERVICE_ID_LEN)
@@ -306,7 +306,7 @@
                              const char *payload)
 {
   int r;
-  switch(command) {
+  switch (command) {
     case RELAY_COMMAND_ESTABLISH_INTRO:
       r = rend_mid_establish_intro(circ,payload,length);
       break;

Index: rendservice.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/rendservice.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -d -r1.107 -r1.108
--- rendservice.c	26 Nov 2004 04:00:54 -0000	1.107
+++ rendservice.c	28 Nov 2004 09:05:46 -0000	1.108
@@ -266,7 +266,7 @@
   d->intro_points = tor_malloc(sizeof(char*)*n);
   for (i=0; i < n; ++i) {
     router = router_get_by_nickname(smartlist_get(service->intro_nodes, i));
-    if(!router) {
+    if (!router) {
       log_fn(LOG_WARN,"Router '%s' not found. Skipping.",
              (char*)smartlist_get(service->intro_nodes, i));
       continue;
@@ -457,12 +457,12 @@
 
   /* Launch a circuit to alice's chosen rendezvous point.
    */
-  for(i=0;i<MAX_REND_FAILURES;i++) {
+  for (i=0;i<MAX_REND_FAILURES;i++) {
     launched = circuit_launch_by_nickname(CIRCUIT_PURPOSE_S_CONNECT_REND, rp_nickname);
     if (launched)
       break;
   }
-  if(!launched) { /* give up */
+  if (!launched) { /* give up */
     log_fn(LOG_WARN,"Giving up launching first hop of circuit to rendezvous point '%s' for service %s",
            rp_nickname, serviceid);
     goto err;
@@ -514,7 +514,7 @@
   oldstate = oldcirc->build_state;
   tor_assert(oldstate);
 
-  if(oldstate->pending_final_cpath == NULL) {
+  if (oldstate->pending_final_cpath == NULL) {
     log_fn(LOG_INFO,"Skipping relaunch of circ that failed on its first hop. Initiator will retry.");
     return;
   }

Index: rephist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/rephist.c,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -d -r1.43 -r1.44
--- rephist.c	26 Nov 2004 04:00:54 -0000	1.43
+++ rephist.c	28 Nov 2004 09:05:46 -0000	1.44
@@ -195,7 +195,7 @@
 void rep_hist_note_connection_died(const char* id, time_t when)
 {
   or_history_t *hist;
-  if(!id) {
+  if (!id) {
     /* XXXX009 Well, everybody has an ID now. Hm. */
     /* If conn has no nickname, it's either an OP, or it is an OR
      * which didn't complete its handshake (or did and was unapproved).

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/router.c,v
retrieving revision 1.128
retrieving revision 1.129
diff -u -d -r1.128 -r1.129
--- router.c	26 Nov 2004 04:00:54 -0000	1.128
+++ router.c	28 Nov 2004 09:05:46 -0000	1.129
@@ -190,7 +190,7 @@
     goto error;
   }
 
-  switch(file_status(fname)) {
+  switch (file_status(fname)) {
   case FN_DIR:
   case FN_ERROR:
     log(LOG_ERR, "Can't read key from %s", fname);
@@ -314,7 +314,7 @@
     log_fn(LOG_ERR, "Error initializing descriptor.");
     return -1;
   }
-  if(authdir_mode(options)) {
+  if (authdir_mode(options)) {
     /* We need to add our own fingerprint so it gets recognized. */
     if (dirserv_add_own_fingerprint(options->Nickname, get_identity_key())) {
       log_fn(LOG_ERR, "Error adding own fingerprint to approved set");
@@ -345,12 +345,12 @@
   strlcat(fingerprint, "\n", sizeof(fingerprint));
   if (write_str_to_file(keydir, fingerprint, 0))
     return -1;
-  if(!authdir_mode(options))
+  if (!authdir_mode(options))
     return 0;
   /* 6. [authdirserver only] load approved-routers file */
   tor_snprintf(keydir,sizeof(keydir),"%s/approved-routers", datadir);
   log_fn(LOG_INFO,"Loading approved fingerprints from %s...",keydir);
-  if(dirserv_parse_fingerprint_file(keydir) < 0) {
+  if (dirserv_parse_fingerprint_file(keydir) < 0) {
     log_fn(LOG_ERR, "Error loading fingerprints");
     return -1;
   }
@@ -363,10 +363,10 @@
   tor_snprintf(keydir,sizeof(keydir),"%s/cached-directory", datadir);
   log_fn(LOG_INFO,"Loading cached directory from %s...",keydir);
   cp = read_file_to_str(keydir,0);
-  if(!cp) {
+  if (!cp) {
     log_fn(LOG_INFO,"Cached directory %s not present. Ok.",keydir);
   } else {
-    if(dirserv_load_from_directory_string(cp) < 0) {
+    if (dirserv_load_from_directory_string(cp) < 0) {
       log_fn(LOG_ERR, "Cached directory %s is corrupt", keydir);
       tor_free(cp);
       return -1;
@@ -397,11 +397,11 @@
   if (!rl) return;
   for (i=0;i < smartlist_len(rl->routers);i++) {
     router = smartlist_get(rl->routers, i);
-    if(router_is_me(router))
+    if (router_is_me(router))
       continue;
-    if(!clique_mode(options) && !router_is_clique_mode(router))
+    if (!clique_mode(options) && !router_is_clique_mode(router))
       continue;
-    if(!connection_get_by_identity_digest(router->identity_digest,
+    if (!connection_get_by_identity_digest(router->identity_digest,
                                           CONN_TYPE_OR)) {
       /* not in the list */
       log_fn(LOG_DEBUG,"connecting to OR at %s:%u.",router->address,router->or_port);
@@ -411,7 +411,7 @@
 }
 
 int router_is_clique_mode(routerinfo_t *router) {
-  if(router_digest_is_trusted_dir(router->identity_digest))
+  if (router_digest_is_trusted_dir(router->identity_digest))
     return 1;
   return 0;
 }
@@ -495,7 +495,7 @@
 {
   routerinfo_t *me = router_get_my_routerinfo();
   tor_assert(router);
-  if(!me || memcmp(me->identity_digest, router->identity_digest, DIGEST_LEN))
+  if (!me || memcmp(me->identity_digest, router->identity_digest, DIGEST_LEN))
     return 0;
   return 1;
 }
@@ -539,7 +539,7 @@
   if (!desc_is_dirty && !force)
     return 0;
 
-  if(resolve_my_address(options->Address, &addr) < 0) {
+  if (resolve_my_address(options->Address, &addr) < 0) {
     log_fn(LOG_WARN,"options->Address didn't resolve into an IP.");
     return -1;
   }
@@ -565,7 +565,7 @@
   ri->bandwidthburst = (int)options->BandwidthBurst;
   ri->bandwidthcapacity = router_get_bandwidth_capacity();
   router_add_exit_policy_from_config(ri);
-  if(desc_routerinfo) /* inherit values */
+  if (desc_routerinfo) /* inherit values */
     ri->is_verified = desc_routerinfo->is_verified;
   if (options->MyFamily) {
     ri->declared_family = smartlist_create();
@@ -649,14 +649,14 @@
   }
 
   /* PEM-encode the onion key */
-  if(crypto_pk_write_public_key_to_string(router->onion_pkey,
+  if (crypto_pk_write_public_key_to_string(router->onion_pkey,
                                           &onion_pkey,&onion_pkeylen)<0) {
     log_fn(LOG_WARN,"write onion_pkey to string failed!");
     return -1;
   }
 
   /* PEM-encode the identity key key */
-  if(crypto_pk_write_public_key_to_string(router->identity_pkey,
+  if (crypto_pk_write_public_key_to_string(router->identity_pkey,
                                           &identity_pkey,&identity_pkeylen)<0) {
     log_fn(LOG_WARN,"write identity_pkey to string failed!");
     tor_free(onion_pkey);
@@ -709,7 +709,7 @@
   tor_free(identity_pkey);
   tor_free(bandwidth_usage);
 
-  if(result < 0 || (size_t)result >= maxlen) {
+  if (result < 0 || (size_t)result >= maxlen) {
     /* apparently different glibcs do different things on tor_snprintf error.. so check both */
     return -1;
   }
@@ -725,13 +725,13 @@
   }
 
   /* Write the exit policy to the end of 's'. */
-  for(tmpe=router->exit_policy; tmpe; tmpe=tmpe->next) {
+  for (tmpe=router->exit_policy; tmpe; tmpe=tmpe->next) {
     in.s_addr = htonl(tmpe->addr);
     /* Write: "accept 1.2.3.4" */
     result = tor_snprintf(s+written, maxlen-written, "%s %s",
         tmpe->policy_type == ADDR_POLICY_ACCEPT ? "accept" : "reject",
         tmpe->msk == 0 ? "*" : inet_ntoa(in));
-    if(result < 0 || result+written > maxlen) {
+    if (result < 0 || result+written > maxlen) {
       /* apparently different glibcs do different things on tor_snprintf error.. so check both */
       return -1;
     }

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.190
retrieving revision 1.191
diff -u -d -r1.190 -r1.191
--- routerlist.c	26 Nov 2004 04:00:54 -0000	1.190
+++ routerlist.c	28 Nov 2004 09:05:46 -0000	1.191
@@ -61,7 +61,7 @@
     if (router_load_routerlist_from_directory(s, NULL, is_recent) < 0) {
       log_fn(LOG_WARN, "Cached directory at '%s' was unparseable; ignoring.", filename);
     }
-    if(routerlist &&
+    if (routerlist &&
        ((routerlist->published_on > time(NULL) - OLD_MIN_ONION_KEY_LIFETIME/2)
         || is_recent)) {
       /* XXX use new onion key lifetime when 0.0.8 servers are obsolete */
@@ -96,7 +96,7 @@
     return NULL;
 
   choice = router_pick_directory_server_impl(requireothers, fascistfirewall);
-  if(choice)
+  if (choice)
     return choice;
 
   log_fn(LOG_INFO,"No reachable router entries for dirservers. Trying them all again.");
@@ -104,13 +104,13 @@
   mark_all_trusteddirservers_up();
   /* try again */
   choice = router_pick_directory_server_impl(requireothers, fascistfirewall);
-  if(choice)
+  if (choice)
     return choice;
 
   log_fn(LOG_INFO,"Still no %s router entries. Reloading and trying again.",
          get_options()->FascistFirewall ? "reachable" : "known");
   has_fetched_directory=0; /* reset it */
-  if(router_reload_router_list()) {
+  if (router_reload_router_list()) {
     return NULL;
   }
   /* give it one last try */
@@ -123,7 +123,7 @@
   trusted_dir_server_t *choice;
 
   choice = router_pick_trusteddirserver_impl(requireothers, fascistfirewall);
-  if(choice)
+  if (choice)
     return choice;
 
   log_fn(LOG_INFO,"No trusted dirservers are reachable. Trying them all again.");
@@ -131,13 +131,13 @@
   mark_all_trusteddirservers_up();
   /* try again */
   choice = router_pick_trusteddirserver_impl(requireothers, fascistfirewall);
-  if(choice)
+  if (choice)
     return choice;
 
   log_fn(LOG_WARN,"Still no dirservers %s. Reloading and trying again.",
          get_options()->FascistFirewall ? "reachable" : "known");
   has_fetched_directory=0; /* reset it */
-  if(router_reload_router_list()) {
+  if (router_reload_router_list()) {
     return NULL;
   }
   /* give it one last try */
@@ -156,21 +156,21 @@
   smartlist_t *sl;
   char buf[16];
 
-  if(!routerlist)
+  if (!routerlist)
     return NULL;
 
-  if(get_options()->HttpProxy)
+  if (get_options()->HttpProxy)
     fascistfirewall = 0;
 
   /* Find all the running dirservers we know about. */
   sl = smartlist_create();
-  for(i=0;i< smartlist_len(routerlist->routers); i++) {
+  for (i=0;i< smartlist_len(routerlist->routers); i++) {
     router = smartlist_get(routerlist->routers, i);
-    if(!router->is_running || !router->dir_port)
+    if (!router->is_running || !router->dir_port)
       continue;
-    if(requireothers && router_is_me(router))
+    if (requireothers && router_is_me(router))
       continue;
-    if(fascistfirewall) {
+    if (fascistfirewall) {
       tor_snprintf(buf,sizeof(buf),"%d",router->dir_port);
       if (!smartlist_string_isin(get_options()->FirewallPorts, buf))
         continue;
@@ -196,7 +196,7 @@
   if (!trusted_dir_servers)
     return NULL;
 
-  if(get_options()->HttpProxy)
+  if (get_options()->HttpProxy)
     fascistfirewall = 0;
 
   SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, d,
@@ -220,9 +220,9 @@
 
 /** Go through and mark the auth dirservers as up */
 static void mark_all_trusteddirservers_up(void) {
-  if(routerlist) {
+  if (routerlist) {
     SMARTLIST_FOREACH(routerlist->routers, routerinfo_t *, router,
-                 if(router_digest_is_trusted_dir(router->identity_digest)) {
+                 if (router_digest_is_trusted_dir(router->identity_digest)) {
                    tor_assert(router->dir_port > 0);
                    router->is_running = 1;
                    router->status_set_at = time(NULL);
@@ -286,7 +286,7 @@
   routerinfo_t *router;
   smartlist_t *nickname_list;
 
-  if(!list)
+  if (!list)
     return; /* nothing to do */
   tor_assert(sl);
 
@@ -324,7 +324,7 @@
   smartlist_t *nickname_list;
   int v = 0;
 
-  if(!list)
+  if (!list)
     return 0; /* definitely not */
   tor_assert(router);
 
@@ -348,12 +348,12 @@
   routerinfo_t *router;
   int i;
 
-  if(!routerlist)
+  if (!routerlist)
     return;
 
-  for(i=0;i<smartlist_len(routerlist->routers);i++) {
+  for (i=0;i<smartlist_len(routerlist->routers);i++) {
     router = smartlist_get(routerlist->routers, i);
-    if(router->is_running &&
+    if (router->is_running &&
        (router->is_verified ||
        (allow_unverified &&
         !router_is_unreliable_router(router, preferuptime, preferbandwidth)))) {
@@ -370,12 +370,12 @@
   routerinfo_t *router;
   int i;
 
-  if(!routerlist)
+  if (!routerlist)
     return NULL;
 
-  for(i=0;i<smartlist_len(routerlist->routers);i++) {
+  for (i=0;i<smartlist_len(routerlist->routers);i++) {
     router = smartlist_get(routerlist->routers, i);
-    if(router_is_me(router))
+    if (router_is_me(router))
       return router;
   }
   return NULL;
@@ -390,9 +390,9 @@
 int
 router_is_unreliable_router(routerinfo_t *router, int need_uptime, int need_bw)
 {
-  if(need_uptime && router->uptime < ROUTER_REQUIRED_MIN_UPTIME)
+  if (need_uptime && router->uptime < ROUTER_REQUIRED_MIN_UPTIME)
     return 1;
-  if(need_bw && router->bandwidthcapacity < ROUTER_REQUIRED_MIN_BANDWIDTH)
+  if (need_bw && router->bandwidthcapacity < ROUTER_REQUIRED_MIN_BANDWIDTH)
     return 1;
   return 0;
 }
@@ -405,7 +405,7 @@
 
   for (i = 0; i < smartlist_len(sl); ++i) {
     router = smartlist_get(sl, i);
-    if(router_is_unreliable_router(router, 1, 0)) {
+    if (router_is_unreliable_router(router, 1, 0)) {
       log(LOG_DEBUG, "Router '%s' has insufficient uptime; deleting.",
           router->nickname);
       smartlist_del(sl, i--);
@@ -427,7 +427,7 @@
     router = smartlist_get(sl, i);
     this_bw = (router->bandwidthcapacity < router->bandwidthrate) ?
                router->bandwidthcapacity : router->bandwidthrate;
-    if(this_bw > 800000)
+    if (this_bw > 800000)
       this_bw = 800000; /* if they claim something huge, don't believe it */
     p = tor_malloc(sizeof(uint32_t));
     *p = this_bw;
@@ -435,18 +435,18 @@
     total_bw += this_bw;
 //    log_fn(LOG_INFO,"Recording bw %d for node %s.", this_bw, router->nickname);
   }
-  if(!total_bw)
+  if (!total_bw)
     return smartlist_choose(sl);
   rand_bw = crypto_pseudo_rand_int(total_bw);
 //  log_fn(LOG_INFO,"Total bw %d. Randomly chose %d.", total_bw, rand_bw);
   tmp = 0;
-  for(i=0; ; i++) {
+  for (i=0; ; i++) {
     tor_assert(i < smartlist_len(sl));
     p = smartlist_get(bandwidths, i);
     tmp += *p;
     router = smartlist_get(sl, i);
 //    log_fn(LOG_INFO,"Considering %s. tmp = %d.", router->nickname, tmp);
-    if(tmp >= rand_bw)
+    if (tmp >= rand_bw)
       break;
   }
   SMARTLIST_FOREACH(bandwidths, uint32_t*, p, tor_free(p));
@@ -479,32 +479,32 @@
   sl = smartlist_create();
   add_nickname_list_to_smartlist(sl,preferred,1);
   smartlist_subtract(sl,excludednodes);
-  if(excludedsmartlist)
+  if (excludedsmartlist)
     smartlist_subtract(sl,excludedsmartlist);
-  if(preferuptime)
+  if (preferuptime)
     routerlist_sl_remove_unreliable_routers(sl);
-  if(preferbandwidth)
+  if (preferbandwidth)
     choice = routerlist_sl_choose_by_bandwidth(sl);
   else
     choice = smartlist_choose(sl);
   smartlist_free(sl);
-  if(!choice && !strict) {
+  if (!choice && !strict) {
     sl = smartlist_create();
     router_add_running_routers_to_smartlist(sl, allow_unverified,
                                             preferuptime, preferbandwidth);
     smartlist_subtract(sl,excludednodes);
-    if(excludedsmartlist)
+    if (excludedsmartlist)
       smartlist_subtract(sl,excludedsmartlist);
-    if(preferuptime)
+    if (preferuptime)
       routerlist_sl_remove_unreliable_routers(sl);
-    if(preferbandwidth)
+    if (preferbandwidth)
       choice = routerlist_sl_choose_by_bandwidth(sl);
     else
       choice = smartlist_choose(sl);
     smartlist_free(sl);
   }
   smartlist_free(excludednodes);
-  if(!choice)
+  if (!choice)
     log_fn(LOG_WARN,"No available nodes when trying to choose node. Failing.");
   return choice;
 }
@@ -519,7 +519,7 @@
   if (!routerlist)
     return NULL;
 
-  for(i=0;i<smartlist_len(routerlist->routers);i++) {
+  for (i=0;i<smartlist_len(routerlist->routers);i++) {
     router = smartlist_get(routerlist->routers, i);
     if ((router->addr == addr) && (router->or_port == port))
       return router;
@@ -577,7 +577,7 @@
   maybedigest = (strlen(nickname) == HEX_DIGEST_LEN) &&
     (base16_decode(digest,DIGEST_LEN,nickname,HEX_DIGEST_LEN) == 0);
 
-  for(i=0;i<smartlist_len(routerlist->routers);i++) {
+  for (i=0;i<smartlist_len(routerlist->routers);i++) {
     router = smartlist_get(routerlist->routers, i);
     if (0 == strcasecmp(router->nickname, nickname) ||
         (maybedigest && 0 == memcmp(digest, router->identity_digest,
@@ -624,7 +624,7 @@
   tor_assert(digest);
   if (!routerlist) return NULL;
 
-  for(i=0;i<smartlist_len(routerlist->routers);i++) {
+  for (i=0;i<smartlist_len(routerlist->routers);i++) {
     router = smartlist_get(routerlist->routers, i);
     if (0 == memcmp(router->identity_digest, digest, DIGEST_LEN))
       return router;
@@ -717,7 +717,7 @@
                       d->is_running = 0);
 
   router = router_get_by_digest(digest);
-  if(!router) /* we don't seem to know about him in the first place */
+  if (!router) /* we don't seem to know about him in the first place */
     return;
   log_fn(LOG_DEBUG,"Marking router '%s' as down.",router->nickname);
   if (router_is_me(router))
@@ -777,8 +777,8 @@
          * make new ones with the new key.
          */
         connection_t *conn;
-        while((conn = connection_get_by_identity_digest(r->identity_digest,
-                                                        CONN_TYPE_OR))) {
+        while ((conn = connection_get_by_identity_digest(r->identity_digest,
+                                                         CONN_TYPE_OR))) {
           log_fn(LOG_INFO,"Closing conn to obsolete router '%s'", r->nickname);
           connection_mark_for_close(conn);
         }
@@ -936,7 +936,7 @@
   struct in_addr in;
   struct addr_policy_t *tmpe;
 
-  for(tmpe=policy; tmpe; tmpe=tmpe->next) {
+  for (tmpe=policy; tmpe; tmpe=tmpe->next) {
 //    log_fn(LOG_DEBUG,"Considering exit policy %s", tmpe->string);
     maybe = 0;
     if (!addr) {
@@ -973,7 +973,7 @@
       in.s_addr = htonl(addr);
       log_fn(LOG_DEBUG,"Address %s:%d matches policy '%s'",
              inet_ntoa(in), port, tmpe->string);
-      if(tmpe->policy_type == ADDR_POLICY_ACCEPT) {
+      if (tmpe->policy_type == ADDR_POLICY_ACCEPT) {
         /* If we already hit a clause that might trigger a 'reject', than we
          * can't be sure of this certain 'accept'.*/
         return maybe_reject ? ADDR_POLICY_UNKNOWN : ADDR_POLICY_ACCEPTED;
@@ -1037,7 +1037,7 @@
     return;
 
   all_routers = smartlist_create();
-  if(me) /* learn if the dirservers think I'm verified */
+  if (me) /* learn if the dirservers think I'm verified */
     smartlist_add(all_routers, me);
 
   smartlist_add_all(all_routers,list->routers);

Index: routerparse.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerparse.c,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- routerparse.c	26 Nov 2004 04:00:54 -0000	1.85
+++ routerparse.c	28 Nov 2004 09:05:46 -0000	1.86
@@ -276,7 +276,7 @@
       VERSION, strchr(v,',') ? "one of " : "", v);
   tor_free(v);
 
-  if(ignoreversion) {
+  if (ignoreversion) {
     log(LOG_WARN, "IgnoreVersion is set. If it breaks, we told you so.");
     return -1;
   } else {
@@ -331,7 +331,7 @@
     log_fn(LOG_WARN, "Unexpected number of tokens in signature"); goto err;
   }
   tok=smartlist_get(tokens,0);
-  if(tok->tp != K_DIRECTORY_SIGNATURE) {
+  if (tok->tp != K_DIRECTORY_SIGNATURE) {
     log_fn(LOG_WARN,"Expected a single directory signature"); goto err;
   }
   declared_key = find_dir_signing_key(str);
@@ -432,8 +432,8 @@
   {
     static int have_warned_about_unverified_status = 0;
     routerinfo_t *me = router_get_my_routerinfo();
-    if(me) {
-      if(router_update_status_from_smartlist(me, published_on,
+    if (me) {
+      if (router_update_status_from_smartlist(me, published_on,
                                              good_nickname_list,
                                           tok->tp==K_RUNNING_ROUTERS)==1 &&
         me->is_verified == 0 && !have_warned_about_unverified_status) {
@@ -612,7 +612,7 @@
     log_fn(LOG_WARN, "Error computing dir-signing-key digest");
     return 0;
   }
-  if(!router_digest_is_trusted_dir(digest)) {
+  if (!router_digest_is_trusted_dir(digest)) {
     log_fn(LOG_WARN, "Listed dir-signing-key is not trusted");
     return 0;
   }
@@ -933,7 +933,7 @@
   if (!bw_set) {
     log_fn(LOG_WARN,"No bandwidth declared; failing."); goto err;
   }
-  if(!router->or_port) {
+  if (!router->or_port) {
     log_fn(LOG_WARN,"or_port unreadable or 0. Failing.");
     goto err;
   }
@@ -1262,7 +1262,7 @@
     }
     *s += i+6;
   }
-  switch(o_syn)
+  switch (o_syn)
     {
     case NO_OBJ:
       if (tok->object_body)
@@ -1298,7 +1298,7 @@
     if (tok->tp == _EOF) fputs("EOF",stdout);
     if (tok->tp == _NIL) fputs("_NIL",stdout);
   }
-  for(i = 0; i < tok->n_args; ++i) {
+  for (i = 0; i < tok->n_args; ++i) {
     fprintf(stdout," \"%s\"", tok->args[i]);
   }
   if (tok->error) { fprintf(stdout," *%s*", tok->error); }
@@ -1408,21 +1408,21 @@
   char *s, *start;
   char tmp[128];
 
-  if(tor_version_parse(cutoff, &cutoff_version)<0) {
+  if (tor_version_parse(cutoff, &cutoff_version)<0) {
     log_fn(LOG_WARN,"Bug: cutoff version '%s' unparsable.",cutoff);
     return 0;
   }
-  if(strcmpstart(platform,"Tor ")) /* nonstandard Tor; be safe and say yes */
+  if (strcmpstart(platform,"Tor ")) /* nonstandard Tor; be safe and say yes */
     return 1;
 
   start = (char *)eat_whitespace(platform+3);
   if (!*start) return 0;
   s = (char *)find_whitespace(start); /* also finds '\0', which is fine */
-  if((size_t)(s-start+1) >= sizeof(tmp)) /* too big, no */
+  if ((size_t)(s-start+1) >= sizeof(tmp)) /* too big, no */
     return 0;
   strlcpy(tmp, start, s-start+1);
 
-  if(tor_version_parse(tmp, &router_version)<0) {
+  if (tor_version_parse(tmp, &router_version)<0) {
     log_fn(LOG_INFO,"Router version '%s' unparsable.",tmp);
     return 1; /* be safe and say yes */
   }

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/test.c,v
retrieving revision 1.150
retrieving revision 1.151
diff -u -d -r1.150 -r1.151
--- test.c	26 Nov 2004 04:00:55 -0000	1.150
+++ test.c	28 Nov 2004 09:05:47 -0000	1.151
@@ -267,7 +267,7 @@
   test_neq(env1, 0);
   test_eq(crypto_cipher_generate_key(env1), 0);
   test_eq(crypto_cipher_encrypt_init_cipher(env1), 0);
-  for(i = 0; i < 1024; ++i) {
+  for (i = 0; i < 1024; ++i) {
     data1[i] = (char) i*73;
   }
   crypto_cipher_encrypt(env1, data2, data1, 1024);
@@ -277,7 +277,7 @@
 
   /* Now, test encryption and decryption with stream cipher. */
   data1[0]='\0';
-  for(i = 1023; i>0; i -= 35)
+  for (i = 1023; i>0; i -= 35)
     strncat(data1, "Now is the time for all good onions", i);
 
   memset(data2, 0, 1024);
@@ -879,7 +879,7 @@
   test_streq(names[1],"bar");
   test_streq(names[2],"baz");
   test_streq(names[3],"quux");
-  for(i=0;i<num;i++)
+  for (i=0;i<num;i++)
     tor_free(names[i]);
   tor_free(names);
 #endif