From faf6fc865e0964435b0079278c35c9d397d614f0 Mon Sep 17 00:00:00 2001 From: Bart Polot Date: Mon, 18 Apr 2011 10:52:49 +0000 Subject: WiP --- src/mesh/gnunet-service-mesh.c | 84 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 16 deletions(-) (limited to 'src/mesh') diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 1bc740512..e119e6fc6 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c @@ -541,6 +541,20 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = { /********************* MESH LOCAL HANDLES **************************/ /******************************************************************************/ +/** + * Client exisits + * @param client the client to check + * @return non-zero if client exists in the global DLL + */ +int +client_exists (struct GNUNET_SERVER_Client *client) { + struct Client *c; + for (c = clients_head; c != clients_head; c = c->next) { + if(c->handle == client) return 1; + } + return 0; +} + /** * Handler for client disconnection * @@ -633,16 +647,11 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { - struct Client *c; struct GNUNET_MESH_TunnelMessage *tunnel_msg; struct MESH_tunnel *t; /* Sanity check for client registration */ - /* TODO: refactor into new function */ - for (c = clients_head; c != clients_head; c = c->next) { - if(c->handle == client) break; - } - if(c->handle != client) { /* Client hasn't registered, not a good thing */ + if(!client_exists(client)) { GNUNET_break(0); GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); return; @@ -684,7 +693,7 @@ handle_local_tunnel_create (void *cls, t->in_tail = NULL; t->out_head = NULL; t->out_tail = NULL; - + GNUNET_SERVER_receive_done(client, GNUNET_OK); return; } @@ -701,6 +710,12 @@ handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client, const struct GNUNET_MessageHeader *message) { + /* Sanity check for client registration */ + if(!client_exists(client)) { + GNUNET_break(0); + GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); + return; + } return; } @@ -709,16 +724,55 @@ handle_local_tunnel_destroy (void *cls, * * @param cls closure * @param client identification of the client - * @param message the actual message + * @param message the actual message (PeerControl) */ static void -handle_local_connect (void *cls, - struct GNUNET_SERVER_Client *client, - const struct GNUNET_MessageHeader *message) +handle_local_connect_add (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) { + /* Sanity check for client registration */ + if(!client_exists(client)) { + GNUNET_break(0); + GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); + return; + } return; } + +/** + * Handler for disconnection requests of peers in a tunnel + * + * @param cls closure + * @param client identification of the client + * @param message the actual message (PeerControl) + */ +static void +handle_local_connect_del (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + return; +} + + +/** + * Handler for connection requests to new peers by type + * + * @param cls closure + * @param client identification of the client + * @param message the actual message (ConnectPeerByType) + */ +static void +handle_local_connect_by_type (void *cls, + struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + return; +} + + /** * Handler for client traffic * @@ -743,15 +797,13 @@ static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE, 0}, {&handle_local_tunnel_destroy, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY, 0}, - {&handle_local_connect, NULL, + {&handle_local_connect_add, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_ADD, 0}, - {&handle_local_connect, NULL, + {&handle_local_connect_del, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_DEL, 0}, - {&handle_local_connect, NULL, + {&handle_local_connect_by_type, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_BY_TYPE, sizeof(struct GNUNET_MESH_ConnectPeerByType)}, - {&handle_local_connect, NULL, - GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT_PEER_CANCEL, 0}, {&handle_local_network_traffic, NULL, GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA, 0}, /* FIXME needed? */ {&handle_local_network_traffic, NULL, -- cgit v1.2.3