[tor-commits] [obfsproxy/master] Add some managed proxy stuff in {network, protocol}.[ch].

nickm at torproject.org nickm at torproject.org
Fri Sep 9 17:08:59 UTC 2011


commit b20922a55c97a82d88b0edd05083d1149522fc92
Author: George Kadianakis <desnacked at gmail.com>
Date:   Sat Aug 20 06:35:44 2011 +0200

    Add some managed proxy stuff in {network,protocol}.[ch].
---
 src/network.c  |   23 ++++++++++++++++++++---
 src/network.h  |    9 +++++++++
 src/protocol.c |   33 +++++++++++++++++++++++++++++++++
 src/protocol.h |    9 +++++++++
 4 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/src/network.c b/src/network.c
index 62a45b8..0fd5e4d 100644
--- a/src/network.c
+++ b/src/network.c
@@ -4,6 +4,7 @@
 
 #include "util.h"
 
+#define NETWORK_PRIVATE
 #include "network.h"
 
 #include "container.h"
@@ -81,7 +82,6 @@ static void simple_server_listener_cb(conn_t *conn);
 static void conn_free(conn_t *conn);
 static void conn_free_on_flush(struct bufferevent *bev, void *arg);
 
-static int circuit_create(conn_t *up, conn_t *down);
 static void circuit_create_socks(conn_t *up);
 static int circuit_add_down(circuit_t *circuit, conn_t *down);
 static void circuit_free(circuit_t *circuit);
@@ -97,6 +97,22 @@ static void pending_conn_cb(struct bufferevent *bev, short what, void *arg);
 static void pending_socks_cb(struct bufferevent *bev, short what, void *arg);
 
 /**
+   Return the evconnlistener that uses 'cfg'.
+*/
+struct evconnlistener *
+get_evconnlistener_by_config(config_t *cfg)
+{
+  obfs_assert(listeners); /* ? */
+
+  SMARTLIST_FOREACH_BEGIN(listeners, listener_t *, l) {
+    if (l->cfg == cfg)
+      return l->listener;
+  } SMARTLIST_FOREACH_END(l);
+
+  return NULL;
+}
+
+/**
    Puts obfsproxy's networking subsystem on "closing time" mode. This
    means that we stop accepting new connections and we shutdown when
    the last connection is closed.
@@ -128,7 +144,8 @@ start_shutdown(int barbaric)
 
 /**
    This function opens listening sockets configured according to the
-   provided 'config_t'.  Returns 1 on success, 0 on failure.
+   provided 'config_t'.
+   Returns 1 on success, 0 on failure.
  */
 int
 open_listeners(struct event_base *base, config_t *cfg)
@@ -355,7 +372,7 @@ conn_free_on_flush(struct bufferevent *bev, void *arg)
     conn_free(conn);
 }
 
-static int
+int
 circuit_create(conn_t *up, conn_t *down)
 {
   if (!up || !down)
diff --git a/src/network.h b/src/network.h
index fa15f48..97e3d8c 100644
--- a/src/network.h
+++ b/src/network.h
@@ -9,6 +9,8 @@
 int open_listeners(struct event_base *base, config_t *cfg);
 void close_all_listeners(void);
 
+struct evconnlistener *get_evconnlistener_by_config(config_t *cfg);
+
 void start_shutdown(int barbaric);
 
 /**
@@ -58,4 +60,11 @@ struct circuit_t {
   unsigned int        is_flushing : 1;
 };
 
+#ifdef NETWORK_PRIVATE
+
+int circuit_create(conn_t *up, conn_t *down);
+
+#endif
+
+
 #endif
diff --git a/src/protocol.c b/src/protocol.c
index 65eacf8..14437e6 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -39,6 +39,39 @@ config_create(int n_options, const char *const *options)
 }
 
 /**
+   Return the transport name for 'cfg'.
+*/
+const char *
+get_transport_name_from_config(config_t *cfg)
+{
+  obfs_assert(cfg);
+  obfs_assert(cfg->vtable);
+  obfs_assert(cfg->vtable->name);
+
+  return cfg->vtable->name;
+}
+
+/**
+   Create a config_t for a managed proxy listener.
+*/
+config_t *
+config_create_managed(int is_server, const char *protocol,
+                      const char *bindaddr, const char *orport)
+{
+  size_t i;
+  for (i = 0; i < n_supported_protocols; i++)
+    if (!strcmp(protocol, supported_protocols[i]->name)) {
+      /* Remove the first element of 'options' (which is always the
+         protocol name) from the list passed to the init method. */
+      return supported_protocols[i]->config_create_managed(is_server,
+                                                           protocol,
+                                                           bindaddr, orport);
+    }
+
+  return NULL;
+}
+
+/**
    This function destroys the protocol-specific part of a listener object.
 */
 void
diff --git a/src/protocol.h b/src/protocol.h
index 989b6db..ede91f1 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -17,6 +17,8 @@ struct config_t
   const struct protocol_vtable *vtable;
 };
 
+const char *get_transport_name_from_config(config_t *cfg);
+
 /**
    This struct defines a protocol and its methods; note that not all
    of them are methods on the same object in the C++ sense.
@@ -34,6 +36,9 @@ struct protocol_vtable
       'options' array. */
   config_t *(*config_create)(int n_options, const char *const *options);
 
+  config_t *(*config_create_managed)(int is_server, const char *protocol,
+                                     const char *bindaddr, const char *orport);
+
   /** Destroy the provided 'config_t' object.  */
   void (*config_free)(config_t *cfg);
 
@@ -81,6 +86,7 @@ struct protocol_vtable
   const protocol_vtable name##_vtable = {       \
     #name,                                      \
     name##_config_create,                       \
+    name##_config_create_managed,               \
     name##_config_free,                         \
     name##_config_get_listen_addrs,             \
     name##_config_get_target_addr,              \
@@ -90,6 +96,9 @@ struct protocol_vtable
   }
 
 config_t *config_create(int n_options, const char *const *options);
+config_t *config_create_managed(int is_server, const char *protocol,
+                                const char *bindaddr, const char *orport);
+
 void config_free(config_t *cfg);
 
 struct evutil_addrinfo *config_get_listen_addrs(config_t *cfg, size_t n);





More information about the tor-commits mailing list