commit 4bfd04672ac0c3bc04ac89edf7856421e343bfe4 Author: George Kadianakis desnacked@gmail.com Date: Sun Jun 5 23:52:31 2011 +0200
Code quality improvements.
* Fixed a small bug. * Updated documentation in protocol.c. --- src/main.c | 3 +++ src/protocol.c | 44 +++++++++++++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/src/main.c b/src/main.c index 7b67988..cb70c44 100644 --- a/src/main.c +++ b/src/main.c @@ -162,6 +162,9 @@ main(int argc, const char **argv) /* This is the number of options of this protocol. */ n_options = end-start+1;
+ if (start >= end) + usage(); + /* First option should be protocol_name. See if we support it. */ if (!is_supported_protocol(argv[start])) { printf("We don't support crappy protocols, son.\n"); diff --git a/src/protocol.c b/src/protocol.c index 1c93150..57c0c23 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -9,33 +9,37 @@ #include "protocols/obfs2.h" #include "protocols/dummy.h"
+/** + All supported protocols should be put in this array. + It's used by main.c. +*/ char *supported_protocols[] = { "obfs2", "dummy" }; int n_supported_protocols = 2;
/** - This function initializes <protocol>. - It's called once in the runtime of the program for each proto. + This function figures out which protocol we want to set up, and + gives 'n_options', 'options' and 'params' to the appropriate + protocol-specific initalization function. + This function is called once for every listener through the runtime + of obfsproxy. */ int set_up_protocol(int n_options, char **options, struct protocol_params_t *params) { - char **name = options; - while (!strncmp(*name,"--",2)) - name++; - if (!strcmp(*name,"dummy")) + if (!strcmp(*options,"dummy")) return dummy_init(n_options, options, params); - else if (!strcmp(*name,"obfs2")) + else if (!strcmp(*options,"obfs2")) return obfs2_init(n_options, options, params); else return -1; }
/** - This function creates a protocol object. It's called once - for every connection. It creates a new protocol_t structure - and fills it's vtable etc. - Return the protocol_t if successful, NULL otherwise. + This function creates a protocol object. + It's called once per connection. + It creates a new protocol_t structure and fills it's vtable etc. + Return a 'protocol_t' if successful, NULL otherwise. */ struct protocol_t * proto_new(protocol_params_t *params) { @@ -51,6 +55,10 @@ proto_new(protocol_params_t *params) { return proto->state ? proto : NULL; }
+/** + This function does the protocol handshake. + Not all protocols have a handshake. +*/ int proto_handshake(struct protocol_t *proto, void *buf) { assert(proto); @@ -60,6 +68,9 @@ proto_handshake(struct protocol_t *proto, void *buf) { return 0; }
+/** + This function is responsible for sending protocol data. +*/ int proto_send(struct protocol_t *proto, void *source, void *dest) { assert(proto); @@ -69,6 +80,9 @@ proto_send(struct protocol_t *proto, void *source, void *dest) { return -1; }
+/** + This function is responsible for receiving protocol data. +*/ int proto_recv(struct protocol_t *proto, void *source, void *dest) { assert(proto); @@ -78,6 +92,10 @@ proto_recv(struct protocol_t *proto, void *source, void *dest) { return -1; }
+/** + This function destroys 'proto'. + It's called everytime we close a connection. +*/ void proto_destroy(struct protocol_t *proto) { assert(proto); @@ -89,6 +107,10 @@ proto_destroy(struct protocol_t *proto) { free(proto); }
+/** + This function destroys 'params'. + It's called everytime we free a listener. +*/ void proto_params_free(protocol_params_t *params) {
tor-commits@lists.torproject.org