Browse Source

Split control_connection_t into its own header.

This one was actually fairly simple.
Nick Mathewson 6 years ago
parent
commit
3b917b2408
8 changed files with 63 additions and 40 deletions
  1. 1 0
      src/or/connection.c
  2. 10 0
      src/or/control.c
  3. 2 0
      src/or/control.h
  4. 45 0
      src/or/control_connection_st.h
  5. 1 0
      src/or/dnsserv.c
  6. 1 0
      src/or/include.am
  7. 1 40
      src/or/or.h
  8. 2 0
      src/test/test_controller.c

+ 1 - 0
src/or/connection.c

@@ -113,6 +113,7 @@
 #include <sys/un.h>
 #endif
 
+#include "control_connection_st.h"
 #include "entry_connection_st.h"
 #include "port_cfg_st.h"
 

+ 10 - 0
src/or/control.c

@@ -81,6 +81,7 @@
 #include "routerparse.h"
 #include "shared_random_client.h"
 
+#include "control_connection_st.h"
 #include "entry_connection_st.h"
 
 #ifndef _WIN32
@@ -228,6 +229,15 @@ static void flush_queued_events_cb(mainloop_event_t *event, void *arg);
 static char * download_status_to_string(const download_status_t *dl);
 static void control_get_bytes_rw_last_sec(uint64_t *r, uint64_t *w);
 
+/** Convert a connection_t* to an control_connection_t*; assert if the cast is
+ * invalid. */
+control_connection_t *
+TO_CONTROL_CONN(connection_t *c)
+{
+  tor_assert(c->magic == CONTROL_CONNECTION_MAGIC);
+  return DOWNCAST(control_connection_t, c);
+}
+
 /** Given a control event code for a message event, return the corresponding
  * log severity. */
 static inline int

+ 2 - 0
src/or/control.h

@@ -12,6 +12,8 @@
 #ifndef TOR_CONTROL_H
 #define TOR_CONTROL_H
 
+control_connection_t *TO_CONTROL_CONN(connection_t *);
+
 void control_initialize_event_queue(void);
 
 void control_update_global_event_mask(void);

+ 45 - 0
src/or/control_connection_st.h

@@ -0,0 +1,45 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2017, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+#ifndef CONTROL_CONNECTION_ST_H
+#define CONTROL_CONNECTION_ST_H
+
+#include "or.h"
+
+/** Subtype of connection_t for an connection to a controller. */
+struct control_connection_t {
+  connection_t base_;
+
+  uint64_t event_mask; /**< Bitfield: which events does this controller
+                        * care about?
+                        * EVENT_MAX_ is >31, so we need a 64 bit mask */
+
+  /** True if we have sent a protocolinfo reply on this connection. */
+  unsigned int have_sent_protocolinfo:1;
+  /** True if we have received a takeownership command on this
+   * connection. */
+  unsigned int is_owning_control_connection:1;
+
+  /** List of ephemeral onion services belonging to this connection. */
+  smartlist_t *ephemeral_onion_services;
+
+  /** If we have sent an AUTHCHALLENGE reply on this connection and
+   * have not received a successful AUTHENTICATE command, points to
+   * the value which the client must send to authenticate itself;
+   * otherwise, NULL. */
+  char *safecookie_client_hash;
+
+  /** Amount of space allocated in incoming_cmd. */
+  uint32_t incoming_cmd_len;
+  /** Number of bytes currently stored in incoming_cmd. */
+  uint32_t incoming_cmd_cur_len;
+  /** A control command that we're reading from the inbuf, but which has not
+   * yet arrived completely. */
+  char *incoming_cmd;
+};
+
+#endif
+

+ 1 - 0
src/or/dnsserv.c

@@ -30,6 +30,7 @@
 #include "main.h"
 #include "policies.h"
 
+#include "control_connection_st.h"
 #include "entry_connection_st.h"
 
 #include <event2/dns.h>

+ 1 - 0
src/or/include.am

@@ -202,6 +202,7 @@ ORHEADERS = \
 	src/or/conscache.h				\
 	src/or/consdiff.h				\
 	src/or/consdiffmgr.h				\
+	src/or/control_connection_st.h			\
 	src/or/control.h				\
 	src/or/cpuworker.h				\
 	src/or/directory.h				\

+ 1 - 40
src/or/or.h

@@ -1639,6 +1639,7 @@ typedef struct or_connection_t {
   uint64_t bytes_xmitted, bytes_xmitted_by_tls;
 } or_connection_t;
 
+typedef struct control_connection_t control_connection_t;
 typedef struct edge_connection_t edge_connection_t;
 typedef struct entry_connection_t entry_connection_t;
 
@@ -1695,38 +1696,6 @@ typedef struct dir_connection_t {
 #endif /* defined(MEASUREMENTS_21206) */
 } dir_connection_t;
 
-/** Subtype of connection_t for an connection to a controller. */
-typedef struct control_connection_t {
-  connection_t base_;
-
-  uint64_t event_mask; /**< Bitfield: which events does this controller
-                        * care about?
-                        * EVENT_MAX_ is >31, so we need a 64 bit mask */
-
-  /** True if we have sent a protocolinfo reply on this connection. */
-  unsigned int have_sent_protocolinfo:1;
-  /** True if we have received a takeownership command on this
-   * connection. */
-  unsigned int is_owning_control_connection:1;
-
-  /** List of ephemeral onion services belonging to this connection. */
-  smartlist_t *ephemeral_onion_services;
-
-  /** If we have sent an AUTHCHALLENGE reply on this connection and
-   * have not received a successful AUTHENTICATE command, points to
-   * the value which the client must send to authenticate itself;
-   * otherwise, NULL. */
-  char *safecookie_client_hash;
-
-  /** Amount of space allocated in incoming_cmd. */
-  uint32_t incoming_cmd_len;
-  /** Number of bytes currently stored in incoming_cmd. */
-  uint32_t incoming_cmd_cur_len;
-  /** A control command that we're reading from the inbuf, but which has not
-   * yet arrived completely. */
-  char *incoming_cmd;
-} control_connection_t;
-
 /** Cast a connection_t subtype pointer to a connection_t **/
 #define TO_CONN(c) (&(((c)->base_)))
 
@@ -1739,9 +1708,6 @@ static or_connection_t *TO_OR_CONN(connection_t *);
 /** Convert a connection_t* to a dir_connection_t*; assert if the cast is
  * invalid. */
 static dir_connection_t *TO_DIR_CONN(connection_t *);
-/** Convert a connection_t* to an control_connection_t*; assert if the cast is
- * invalid. */
-static control_connection_t *TO_CONTROL_CONN(connection_t *);
 /** Convert a connection_t* to an listener_connection_t*; assert if the cast is
  * invalid. */
 static listener_connection_t *TO_LISTENER_CONN(connection_t *);
@@ -1756,11 +1722,6 @@ static inline dir_connection_t *TO_DIR_CONN(connection_t *c)
   tor_assert(c->magic == DIR_CONNECTION_MAGIC);
   return DOWNCAST(dir_connection_t, c);
 }
-static inline control_connection_t *TO_CONTROL_CONN(connection_t *c)
-{
-  tor_assert(c->magic == CONTROL_CONNECTION_MAGIC);
-  return DOWNCAST(control_connection_t, c);
-}
 static inline listener_connection_t *TO_LISTENER_CONN(connection_t *c)
 {
   tor_assert(c->magic == LISTENER_CONNECTION_MAGIC);

+ 2 - 0
src/test/test_controller.c

@@ -13,6 +13,8 @@
 #include "test.h"
 #include "test_helpers.h"
 
+#include "control_connection_st.h"
+
 static void
 test_add_onion_helper_keyarg_v3(void *arg)
 {