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

[tor-commits] [obfsproxy/master] Don't expose listener_t objects outside network.c.



commit 4b8ac430d0c7e7fea6e2ddb1d6ae71f87ac81edd
Author: Zack Weinberg <zackw@xxxxxxxxx>
Date:   Mon Jul 25 15:11:31 2011 -0700

    Don't expose listener_t objects outside network.c.
---
 src/main.c    |   16 +++-------------
 src/network.c |   22 +++++++---------------
 src/network.h |   13 +++++++++----
 3 files changed, 19 insertions(+), 32 deletions(-)

diff --git a/src/main.c b/src/main.c
index 254be94..cc69805 100644
--- a/src/main.c
+++ b/src/main.c
@@ -341,7 +341,6 @@ main(int argc, const char **argv)
 
   /*Let's open a new listener for each protocol. */
   int h;
-  listener_t *temp_listener;
   int n_listeners=0;
   protocol_params_t *proto_params=NULL;
   for (h=0;h<actual_protocols;h++) {
@@ -350,22 +349,13 @@ main(int argc, const char **argv)
     /** normally free'd in listener_free() */
     proto_params = proto_params_init(n_options_array[h],
                                      (const char *const *)protocol_options[h]);
-    if (!proto_params) {
-      free(protocol_options[h]);
-      continue;
+    if (proto_params && create_listener(the_event_base, proto_params)) {
+      log_info("Succesfully created listener %d.", h+1);
+      n_listeners++;
     }
 
-    temp_listener = listener_new(the_event_base, proto_params);
-
     /** Free the space allocated for this protocol's options. */
     free(protocol_options[h]);
-
-    if (!temp_listener)
-      continue;
-
-    log_info("Succesfully created listener %d.", h+1);
-
-    n_listeners++;
   }
 
   log_debug("From the original %d protocols only %d "
diff --git a/src/network.c b/src/network.c
index 9003ea9..c4cf0c7 100644
--- a/src/network.c
+++ b/src/network.c
@@ -58,11 +58,6 @@
 /** All our listeners. */
 static smartlist_t *listeners;
 
-struct listener_t {
-  struct evconnlistener *listener;
-  protocol_params_t *proto_params;
-};
-
 /** All active connections.  */
 static smartlist_t *connections;
 
@@ -135,16 +130,13 @@ close_all_connections(void)
 
 /**
    This function spawns a listener configured according to the
-   provided 'protocol_params_t' object'.  Returns the listener on
-   success, NULL on fail.
+   provided 'protocol_params_t' object'.  Returns 1 on success, 0 on
+   failure.  (No, you can't have the listener object. It's private.)
 
-   If it succeeds, the new listener object takes ownership of the
-   protocol_params_t object provided; if it fails, the protocol_params_t
-   object is deallocated.
+   Regardless of success or failure, the protocol_params_t is consumed.
 */
-listener_t *
-listener_new(struct event_base *base,
-             protocol_params_t *params)
+int
+create_listener(struct event_base *base, protocol_params_t *params)
 {
   const unsigned flags =
     LEV_OPT_CLOSE_ON_FREE|LEV_OPT_CLOSE_ON_EXEC|LEV_OPT_REUSEABLE;
@@ -168,7 +160,7 @@ listener_new(struct event_base *base,
     log_warn("Failed to create listener!");
     proto_params_free(params);
     free(lsn);
-    return NULL;
+    return 0;
   }
 
   /* If we don't have a listener list, create one now. */
@@ -176,7 +168,7 @@ listener_new(struct event_base *base,
     listeners = smartlist_create();
   smartlist_add(listeners, lsn);
 
-  return lsn;
+  return 1;
 }
 
 /**
diff --git a/src/network.h b/src/network.h
index 0d6ef8d..b6aa410 100644
--- a/src/network.h
+++ b/src/network.h
@@ -28,10 +28,8 @@ enum recv_ret {
   RECV_SEND_PENDING
 };
 
-typedef struct listener_t listener_t;
-
-listener_t *listener_new(struct event_base *base,
-                         struct protocol_params_t *params);
+/* returns 1 on success, 0 on failure */
+int create_listener(struct event_base *base, struct protocol_params_t *params);
 void free_all_listeners(void);
 
 void start_shutdown(int barbaric);
@@ -39,8 +37,15 @@ void start_shutdown(int barbaric);
 #ifdef NETWORK_PRIVATE
 
 struct bufferevent;
+struct evconnlistener;
 struct socks_state_t;
 struct protocol_t;
+struct protocol_params_t;
+
+typedef struct listener_t {
+  struct evconnlistener *listener;
+  struct protocol_params_t *proto_params;
+} listener_t;
 
 typedef struct conn_t {
   struct protocol_t *proto;



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits