[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [obfsproxy/master] Trivial improvements over the code:
commit 75ecf16d8342a34357ef39b3fe339590097896fd
Author: George Kadianakis <desnacked@xxxxxxxxx>
Date: Tue May 24 22:32:47 2011 +0200
Trivial improvements over the code:
* typedef'ed protocol_params_t
* we now also free() the protocol_params_t itself
in protocol_params_free().
---
src/network.c | 7 ++++---
src/protocol.c | 2 +-
src/protocol.h | 10 +++++-----
src/protocols/dummy.c | 2 +-
src/protocols/obfs2.c | 8 ++++----
5 files changed, 15 insertions(+), 14 deletions(-)
diff --git a/src/network.c b/src/network.c
index 07efbc4..a2dc410 100644
--- a/src/network.c
+++ b/src/network.c
@@ -29,7 +29,7 @@ struct listener_t {
int target_address_len;
int mode;
int proto; /* Protocol that this listener can speak. */
- struct protocol_params_t *proto_params;
+ protocol_params_t *proto_params;
};
static void simple_listener_cb(struct evconnlistener *evcl,
@@ -68,7 +68,7 @@ listener_new(struct event_base *base,
lsn->proto = protocol;
lsn->mode = mode;
- struct protocol_params_t *proto_params = calloc(1, sizeof(struct protocol_params_t));
+ protocol_params_t *proto_params = calloc(1, sizeof(protocol_params_t));
proto_params->is_initiator = mode != LSN_SIMPLE_SERVER;
proto_params->shared_secret = shared_secret;
proto_params->shared_secret_len = shared_secret_len;
@@ -97,11 +97,12 @@ listener_new(struct event_base *base,
}
static void
-protocol_params_free(struct protocol_params_t *params)
+protocol_params_free(protocol_params_t *params)
{
assert(params);
if (params->shared_secret)
free(¶ms->shared_secret);
+ free(params);
}
void
diff --git a/src/protocol.c b/src/protocol.c
index 4e6ae81..8fff6a3 100644
--- a/src/protocol.c
+++ b/src/protocol.c
@@ -31,7 +31,7 @@ set_up_protocol(int protocol) {
Return the protocol_t if successful, NULL otherwise.
*/
struct protocol_t *
-proto_new(int protocol, struct protocol_params_t *params) {
+proto_new(int protocol, protocol_params_t *params) {
struct protocol_t *proto = calloc(1, sizeof(struct protocol_t));
if (!proto)
return NULL;
diff --git a/src/protocol.h b/src/protocol.h
index 6b609ee..e4c3e0f 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -13,12 +13,12 @@ struct evbuffer;
be inherited by *all* connections opened from the listener_t that
owns this protocol_params_t.
*/
-struct protocol_params_t {
-int is_initiator;
+typedef struct protocol_params_t {
+ int is_initiator;
const char *shared_secret;
size_t shared_secret_len;
-};
+} protocol_params_t;
struct protocol_t {
/* protocol */
@@ -49,7 +49,7 @@ typedef struct protocol_vtable {
/* Constructor: Creates a protocol object. */
void *(*create)(struct protocol_t *proto_struct,
- struct protocol_params_t *parameters);
+ protocol_params_t *parameters);
/* does handshake. Not all protocols have a handshake. */
int (*handshake)(void *state,
@@ -69,7 +69,7 @@ typedef struct protocol_vtable {
int set_up_protocol(int protocol);
struct protocol_t *proto_new(int protocol,
- struct protocol_params_t *params);
+ protocol_params_t *params);
void proto_destroy(struct protocol_t *proto);
int proto_handshake(struct protocol_t *proto, void *buf);
int proto_send(struct protocol_t *proto, void *source, void *dest);
diff --git a/src/protocols/dummy.c b/src/protocols/dummy.c
index 79d40e0..482c927 100644
--- a/src/protocols/dummy.c
+++ b/src/protocols/dummy.c
@@ -37,7 +37,7 @@ dummy_init(void) {
void *
dummy_new(struct protocol_t *proto_struct,
- struct protocol_params_t *params)
+ protocol_params_t *params)
{
proto_struct->vtable = vtable;
diff --git a/src/protocols/obfs2.c b/src/protocols/obfs2.c
index 277ca63..1377dfe 100644
--- a/src/protocols/obfs2.c
+++ b/src/protocols/obfs2.c
@@ -26,7 +26,7 @@ static int obfs2_send(void *state,
struct evbuffer *source, struct evbuffer *dest);
static int obfs2_recv(void *state, struct evbuffer *source,
struct evbuffer *dest);
-static void *obfs2_state_new(struct protocol_params_t *params);
+static void *obfs2_state_new(protocol_params_t *params);
static int obfs2_state_set_shared_secret(void *s,
const char *secret,
size_t secretlen);
@@ -117,7 +117,7 @@ derive_padding_key(void *s, const uchar *seed,
void *
obfs2_new(struct protocol_t *proto_struct,
- struct protocol_params_t *params)
+ protocol_params_t *params)
{
assert(vtable);
proto_struct->vtable = vtable;
@@ -131,7 +131,7 @@ obfs2_new(struct protocol_t *proto_struct,
NULL on failure.
*/
static void *
-obfs2_state_new(struct protocol_params_t *params)
+obfs2_state_new(protocol_params_t *params)
{
obfs2_state_t *state = calloc(1, sizeof(obfs2_state_t));
uchar *seed;
@@ -183,9 +183,9 @@ obfs2_state_set_shared_secret(void *s, const char *secret,
obfs2_state_t *state = s;
digest_t *c = digest_new();
- /* ASN do we like this cast here? */
digest_update(c, (uchar*)secret, secretlen);
digest_getdigest(c, buf, sizeof(buf));
+
memcpy(state->secret_seed, buf, SHARED_SECRET_LENGTH);
memset(buf,0,SHARED_SECRET_LENGTH);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits