瀏覽代碼

fix an assert trigger: when we have the rare case of accepting
a conn on 0.0.0.0:0, then when we look through the connection array,
we'll find any of the workers. this is no good.


svn:r4027

Roger Dingledine 20 年之前
父節點
當前提交
9cbaf4603d
共有 4 個文件被更改,包括 11 次插入19 次删除
  1. 6 3
      src/or/connection.c
  2. 4 4
      src/or/cpuworker.c
  3. 0 11
      src/or/main.c
  4. 1 1
      src/or/or.h

+ 6 - 3
src/or/connection.c

@@ -440,7 +440,7 @@ static int connection_create_listener(const char *bindaddress, uint16_t bindport
 #ifndef MS_WINDOWS
   /* REUSEADDR on normal places means you can rebind to the port
    * right after somebody else has let it go. But REUSEADDR on win32
-   * means to let you bind to the port _even when somebody else
+   * means you can bind to the port _even when somebody else
    * already has it bound_. So, don't do that on Win32. */
   setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (void*) &one, sizeof(one));
 #endif
@@ -1223,7 +1223,7 @@ void connection_write_to_buf(const char *string, size_t len, connection_t *conn)
 
 /** Return the conn to addr/port that has the most recent
  * timestamp_created, or NULL if no such conn exists. */
-connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port) {
+connection_t *connection_or_exact_get_by_addr_port(uint32_t addr, uint16_t port) {
   int i, n;
   connection_t *conn, *best=NULL;
   connection_t **carray;
@@ -1231,7 +1231,10 @@ connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port) {
   get_connection_array(&carray,&n);
   for (i=0;i<n;i++) {
     conn = carray[i];
-    if (conn->addr == addr && conn->port == port && !conn->marked_for_close &&
+    if (conn->type == CONN_TYPE_OR &&
+        conn->addr == addr &&
+        conn->port == port &&
+        !conn->marked_for_close &&
         (!best || best->timestamp_created < conn->timestamp_created))
       best = conn;
   }

+ 4 - 4
src/or/cpuworker.c

@@ -141,10 +141,10 @@ int connection_cpu_process_inbuf(connection_t *conn) {
     /* parse out the circ it was talking about */
     tag_unpack(buf, &addr, &port, &circ_id);
     circ = NULL;
-    /* (Here we use connection_exact_get_by_addr_port rather than
+    /* (Here we use connection_or_exact_get_by_addr_port rather than
      * 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);
+    p_conn = connection_or_exact_get_by_addr_port(addr,port);
     if (p_conn)
       circ = circuit_get_by_circid_orconn(circ_id, p_conn);
 
@@ -356,8 +356,8 @@ static void process_pending_task(connection_t *cpuworker) {
     log_fn(LOG_WARN,"assign_to_cpuworker failed. Ignoring.");
 }
 
-/** if cpuworker is defined, assert that he's idle, and use him. else,
- * look for an idle cpuworker and use him. if none idle, queue task onto
+/** If cpuworker is defined, assert that he's idle, and use him. Else,
+ * look for an idle cpuworker and use him. If none idle, queue task onto
  * the pending onion list and return.
  * If question_type is CPUWORKER_TASK_ONION then task is a circ.
  * No other question_types are allowed.

+ 0 - 11
src/or/main.c

@@ -838,17 +838,6 @@ static void second_elapsed_callback(int fd, short event, void *args)
 
   current_second = now.tv_sec; /* remember which second it is, for next time */
 
-#if 0
-  for (i=0;i<nfds;i++) {
-    conn = connection_array[i];
-    if (connection_has_pending_tls_data(conn) &&
-        connection_is_reading(conn)) {
-      log_fn(LOG_DEBUG,"sock %d has pending bytes.",conn->s);
-      return; /* has pending bytes to read; don't let poll wait. */
-    }
-  }
-#endif
-
   if (evtimer_add(timeout_event, &one_second))
     log_fn(LOG_ERR,
            "Error from libevent when setting one-second timeout event");

+ 1 - 1
src/or/or.h

@@ -1286,7 +1286,7 @@ int connection_outbuf_too_full(connection_t *conn);
 int connection_handle_write(connection_t *conn);
 void connection_write_to_buf(const char *string, size_t len, connection_t *conn);
 
-connection_t *connection_exact_get_by_addr_port(uint32_t addr, uint16_t port);
+connection_t *connection_or_exact_get_by_addr_port(uint32_t addr, uint16_t port);
 connection_t *connection_get_by_identity_digest(const char *digest, int type);
 connection_t *connection_get_by_global_id(uint32_t id);