From a1a7ddbce0c780fca844fc144f6cb1af2472bcb3 Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Sun, 1 Jul 2012 22:08:19 +0000 Subject: [PATCH] routing --- src/testbed/gnunet-service-testbed.c | 76 +++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 7 deletions(-) diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 7c0122159..63d28d97b 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c @@ -113,6 +113,29 @@ struct SharedService }; +/** + * A routing entry + */ +struct Route +{ + /** + * The destination host + */ + const struct GNUNET_TESTBED_Host *dest; + + /** + * The forwarding (next hop) host + */ + const struct GNUNET_TESTBED_Host *fhost; + + /** + * The controller handle if we have started the controller at the next hop + * host + */ + struct GNUNET_TESTBED_Controller *fcontroller; +}; + + /** * Wrapped stdin. */ @@ -138,6 +161,16 @@ static struct GNUNET_TESTBED_Host **host_list; */ static uint32_t host_list_size; +/** + * A list of routes + */ +static struct Route **route_list; + +/** + * The size of the route list + */ +static uint32_t route_list_size; + /** * The message queue head */ @@ -497,17 +530,32 @@ handle_link_controllers (void *cls, } msg = (const struct GNUNET_TESTBED_ControllerLinkMessage *) message; delegated_host_id = ntohl (msg->delegated_host_id); + if (delegated_host_id == master_context->host_id) + { + GNUNET_break (0); + LOG (GNUNET_ERROR_TYPE_WARNING, "Trying to link ourselves\n"); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } + if ((delegated_host_id < route_list_size) && + (NULL != route_list[delegated_host_id])) + { + LOG (GNUNET_ERROR_TYPE_WARNING, + "Delegated host has already been linked\n"); + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + return; + } if ((delegated_host_id >= host_list_size) || (NULL == host_list[delegated_host_id])) { - GNUNET_break (0); /* Delegated host not registered with us */ + LOG (GNUNET_ERROR_TYPE_WARNING, "Delegated host not registered with us\n"); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } slave_host_id = ntohl (msg->slave_host_id); if ((slave_host_id >= host_list_size) || (NULL == host_list[slave_host_id])) { - GNUNET_break (0); /* Slave host not registered with us */ + LOG (GNUNET_ERROR_TYPE_WARNING, "Slave host not registered with us\n"); GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); return; } @@ -534,9 +582,14 @@ handle_link_controllers (void *cls, return; } GNUNET_free (config); - /* FIXME: start the slave controller if is_subordinate is yes; else store it - in routing */ - + GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); + /* If we are not the slave controller then we have to route the request + towards the slave controller */ + if (1 == msg->is_subordinate) + { + GNUNET_break (0); /* FIXME: Implement the slave controller + startup */ + } GNUNET_CONFIGURATION_destroy (cfg); } @@ -576,6 +629,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { uint32_t host_id; + uint32_t route_id; shutdown_task_id = GNUNET_SCHEDULER_NO_TASK; GNUNET_SCHEDULER_shutdown (); @@ -583,18 +637,26 @@ shutdown_task (void *cls, (void) GNUNET_CONTAINER_multihashmap_iterate (ss_map, &ss_map_free_iterator, NULL); GNUNET_CONTAINER_multihashmap_destroy (ss_map); - /* Clear host array */ if (NULL != fh) { GNUNET_DISK_file_close (fh); fh = NULL; } + /* Clear host list */ for (host_id = 0; host_id < host_list_size; host_id++) if (NULL != host_list[host_id]) GNUNET_TESTBED_host_destroy (host_list[host_id]); GNUNET_free_non_null (host_list); + /* Clear route list */ + for (route_id = 0; route_id < route_list_size; route_id++) + if (NULL != route_list[route_id]) + { + if (NULL != route_list[route_id]->fcontroller) + GNUNET_TESTBED_controller_stop (route_list[route_id]->fcontroller); + GNUNET_free (route_list[route_id]); + } + GNUNET_free_non_null (route_list); GNUNET_free_non_null (master_context); - master_context = NULL; } -- 2.25.1