[tor-commits] [obfsproxy/master] Merge remote-tracking branch 'asn-http/bug3301'

nickm at torproject.org nickm at torproject.org
Thu Jul 14 16:05:40 UTC 2011


commit e4d0a1f0c79405a930dfb308a7847d066f1d0ff2
Merge: 77c04c2 4676284
Author: Nick Mathewson <nickm at torproject.org>
Date:   Thu Jul 14 12:05:21 2011 -0400

    Merge remote-tracking branch 'asn-http/bug3301'
    
    Conflicts:
    	src/main.c
    	src/network.c
    	src/socks.c

 src/main.c                  |    6 ++--
 src/network.c               |   47 ++++++++++++++++++++++---
 src/protocol.c              |    5 +--
 src/protocols/dummy.c       |   29 +++++++++++++--
 src/protocols/obfs2.c       |    3 ++
 src/protocols/obfs2_crypt.c |   42 +++++++++++++++++++++++
 src/socks.c                 |   79 +++++++++++++++++++++++++++++++-----------
 src/util.c                  |   16 +++++++++
 8 files changed, 190 insertions(+), 37 deletions(-)

diff --cc src/main.c
index 893f9eb,9399783..ee2a802
--- a/src/main.c
+++ b/src/main.c
@@@ -118,9 -80,9 +118,9 @@@ populate_options(char **options_string
  }
  
  /**
-    Returns 0 if 'name' is the nmae of a supported protocol, otherwise
-    it returns -1.
- */ 
 -   Returns 1 if 'name' is the name of a supported protocol, otherwise
 -   it returns 0.
 -*/ 
++   Return 0 if 'name' is the nmae of a supported protocol, otherwise
++   return -1.
++*/
  static int
  is_supported_protocol(const char *name) {
    int f;
diff --cc src/network.c
index 8b19418,a0ab6e9..b76ac8e
--- a/src/network.c
+++ b/src/network.c
@@@ -55,54 -36,9 +55,52 @@@ static void input_event_cb(struct buffe
  static void output_event_cb(struct bufferevent *bev, short what, void *arg);
  
  /**
 +   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.
 +
 +   If 'barbaric' is set, we forcefully close all open connections and
 +   finish shutdown.
 +   
 +   (Only called by signal handlers)
 +*/
 +void
 +start_shutdown(int barbaric)
 +{
 +  if (!shutting_down)
 +    shutting_down=1;
 +
 +  if (!n_connections) {
 +    finish_shutdown();
 +    return;
 +  }
 +
 +  if (barbaric) {
 +    if (n_connections)
 +      close_all_connections();
 +    return;
 +  }
 +}  
 +
 +/**
 +   Closes all open connections.
 +*/ 
 +static void
 +close_all_connections(void)
 +{
 +  /** Traverse the dll and close all connections */
 +  while (conn_list.head) {
 +    conn_t *conn = UPCAST(conn_t, dll_node, conn_list.head);
 +    conn_free(conn); /* removes it */
 +
 +    return; /* connections are now all closed. */
 +  }
 +  assert(!n_connections);
 +}
-   
 +/**
-    This function sets up the protocol defined by 'options' and
-    attempts to bind a new listener for it.
+    This function spawns a listener according to the 'proto_params'.
  
-    Returns the listener on success, NULL on fail. 
 -   Returns the listener on success and NULL on fail. 
++   Returns the listener on success and NULL on fail.
  */
  listener_t *
  listener_new(struct event_base *base,
@@@ -153,30 -86,15 +154,37 @@@ listener_free(listener_t *lsn
  }
  
  /**
 +   Frees all active listeners.
 +*/
 +void
 +free_all_listeners(void)
 +{
 +  static int called_already=0;
 +
 +  if (called_already)
 +    return;
 +
 +  log_info("Closing all listeners.");
 +
 +  /* Iterate listener doubly linked list and free them all. */
 +  while (listener_list.head) {
 +    listener_t *listener = UPCAST(listener_t, dll_node, listener_list.head);
 +    listener_free(listener);
 +  }
 +
 +  called_already++;
 +}
 +
++/**
+    This function is called when a new connection is received.
+ 
+    It initializes the protocol we are using, sets up the necessary
+    callbacks for input/output and does the protocol handshake.
 -*/   
++*/
  static void
  simple_listener_cb(struct evconnlistener *evcl,
-     evutil_socket_t fd, struct sockaddr *sourceaddr, int socklen, void *arg)
+                    evutil_socket_t fd, struct sockaddr *sourceaddr, 
+                    int socklen, void *arg)
  {
    listener_t *lsn = arg;
    struct event_base *base;
@@@ -288,25 -197,14 +299,29 @@@ conn_free(conn_t *conn
      bufferevent_free(conn->input);
    if (conn->output)
      bufferevent_free(conn->output);
 +
 +  /* remove conn from the linked list of connections */
 +  dll_remove(&conn_list, &conn->dll_node);
 +  n_connections--;
 +
    memset(conn, 0x99, sizeof(conn_t));
    free(conn);
 +
 +  assert(n_connections>=0);
 +  log_debug("Connection destroyed. "
 +            "We currently have %d connections!", n_connections);
 +
 +  /** If this was the last connection AND we are shutting down,
 +      finish shutdown. */
 +  if (!n_connections && shutting_down) {
 +    finish_shutdown();
 +  }
  }
  
+ /**
+    Closes associated connection if the output evbuffer of 'bev' is
+    empty.
+ */ 
  static void
  close_conn_on_flush(struct bufferevent *bev, void *arg)
  {
diff --cc src/protocols/dummy.c
index dea8cfc,be4c287..eaf921c
--- a/src/protocols/dummy.c
+++ b/src/protocols/dummy.c
@@@ -53,9 -54,12 +54,12 @@@ dummy_init(int n_options, char **option
    vtable->send = dummy_send;
    vtable->recv = dummy_recv;
  
 -  return 1;
 +  return 0;
  }
  
+ /**
+    Helper: Parses 'options' and fills 'params'.
+ */ 
  static int
  parse_and_set_options(int n_options, char **options, 
                        struct protocol_params_t *params)
@@@ -93,9 -97,12 +97,12 @@@
    memcpy(&params->on_address, sa_listen, sl_listen);
    params->on_address_len = sl_listen;
    
 -  return 1;
 +  return 0;
  }
  
+ /**
+    Prints dummy protocol usage information.
+ */
  static void
  usage(void)
  {
diff --cc src/protocols/obfs2.c
index 5447e7b,f4302a2..f9beee5
--- a/src/protocols/obfs2.c
+++ b/src/protocols/obfs2.c
@@@ -58,9 -58,12 +58,12 @@@ obfs2_init(int n_options, char **option
      return -1;
    }
  
 -  return 1;
 +  return 0;
  }
  
+ /**
+    Helper: Parses 'options' and fills 'params'.
+ */
  int
  parse_and_set_options(int n_options, char **options, 
                        struct protocol_params_t *params)
diff --cc src/socks.c
index 6873683,d3c69f2..f175a8e
--- a/src/socks.c
+++ b/src/socks.c
@@@ -430,7 -440,11 +445,11 @@@ socks4_read_request(struct evbuffer *so
    return SOCKS_GOOD;
  }
  
+ /**
+    This sends the appropriate SOCKS4 reply to the client on
+    'reply_dest', according to 'status'.
+ */
 -int
 +void
  socks4_send_reply(struct evbuffer *dest, socks_state_t *state, int status)
  {
    uint16_t portnum;
@@@ -590,9 -624,9 +627,9 @@@ socks_state_set_address(socks_state_t *
     operation (normally a CONNECT with no errors means that the
     connect() was successful).
     If 'error' is not 0, it means that an error was encountered and
-    error carries the errno(3) of the error.
+    error carries the errno(3).
  */
 -int
 +void
  socks_send_reply(socks_state_t *state, struct evbuffer *dest, int error)
  {
    int status = socks_errno_to_reply(state, error);
diff --cc src/util.c
index 6106b0c,1d44a52..4517f95
--- a/src/util.c
+++ b/src/util.c
@@@ -517,5 -414,5 +532,6 @@@ log_debug(const char *format, ...
  
    va_end(ap);
  }
+ 
  #endif
 +



More information about the tor-commits mailing list