Pārlūkot izejas kodu

Change how OR conns get removed from the identity map; fix some warnings on shutdown.

svn:r5509
Nick Mathewson 20 gadi atpakaļ
vecāks
revīzija
b03e8733f3
3 mainītis faili ar 28 papildinājumiem un 0 dzēšanām
  1. 6 0
      src/or/connection.c
  2. 21 0
      src/or/connection_or.c
  3. 1 0
      src/or/or.h

+ 6 - 0
src/or/connection.c

@@ -257,6 +257,9 @@ connection_free(connection_t *conn)
   if (connection_speaks_cells(conn)) {
     if (conn->state == OR_CONN_STATE_OPEN)
       directory_set_dirty();
+    if (!tor_digest_is_zero(conn->identity_digest)) {
+      connection_or_remove_from_identity_map(conn);
+    }
   }
   if (conn->type == CONN_TYPE_CONTROL) {
     conn->event_mask = 0;
@@ -288,6 +291,9 @@ connection_free_all(void)
       carray[i]->event_mask = 0;
   control_update_global_event_mask();
 
+  /* Unlink everything from the identity map. */
+  connection_or_clear_identity_map();
+
   for (i=0;i<n;i++)
     _connection_free(carray[i]);
 

+ 21 - 0
src/or/connection_or.c

@@ -59,6 +59,27 @@ connection_or_remove_from_identity_map(connection_t *conn)
   conn->next_with_same_id = NULL;
 }
 
+/** Remove all entries from the identity-to-orconn map, and clear
+ * all identities in OR conns.*/
+void
+connection_or_clear_identity_map(void)
+{
+  int i, n;
+  connection_t **carray;
+
+  get_connection_array(&carray,&n);
+  for (i = 0; i < n; ++i) {
+    connection_t* conn = carray[i];
+    if (conn->type == CONN_TYPE_OR) {
+      memset(conn->identity_digest, 0, DIGEST_LEN);
+      conn->next_with_same_id = NULL;
+    }
+  }
+
+  digestmap_free(orconn_identity_map, NULL);
+  orconn_identity_map = NULL;
+}
+
 /** Change conn->identity_digest to digest, and add conn into
  * orconn_digest_map. */
 static void

+ 1 - 0
src/or/or.h

@@ -1663,6 +1663,7 @@ hostname_type_t parse_extended_hostname(char *address);
 /********************************* connection_or.c ***************************/
 
 void connection_or_remove_from_identity_map(connection_t *conn);
+void connection_or_clear_identity_map(void);
 connection_t *connection_or_get_by_identity_digest(const char *digest);
 
 int connection_or_reached_eof(connection_t *conn);