aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-10-19 12:01:31 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-10-19 12:01:31 +0000
commit4394539dca8d91edb2be740bd139e2e267899a30 (patch)
tree0563067ab24d72fe9d9364f1eebdda8e0ab11208 /src
parent98d9b3a2eed2893dd2f5db717d49bbb7bd72e170 (diff)
downloadgnunet-4394539dca8d91edb2be740bd139e2e267899a30.tar.gz
gnunet-4394539dca8d91edb2be740bd139e2e267899a30.zip
remove remote peers upon destroy
Diffstat (limited to 'src')
-rw-r--r--src/testbed/gnunet-service-testbed.c85
1 files changed, 56 insertions, 29 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index 2371d2825..90ff87235 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -269,27 +269,6 @@ struct RegisteredHostContext
269 269
270 270
271/** 271/**
272 * Function to generate the hashcode corresponding to a RegisteredHostContext
273 *
274 * @param reg_host the host which is being registered in RegisteredHostContext
275 * @param host the host of the controller which has to connect to the above rhost
276 * @return the hashcode
277 */
278static struct GNUNET_HashCode
279hash_hosts (struct GNUNET_TESTBED_Host *reg_host,
280 struct GNUNET_TESTBED_Host *host)
281{
282 struct GNUNET_HashCode hash;
283 uint32_t host_ids[2];
284
285 host_ids[0] = GNUNET_TESTBED_host_get_id_ (reg_host);
286 host_ids[1] = GNUNET_TESTBED_host_get_id_ (host);
287 GNUNET_CRYPTO_hash (host_ids, sizeof (host_ids), &hash);
288 return hash;
289}
290
291
292/**
293 * Structure representing a connected(directly-linked) controller 272 * Structure representing a connected(directly-linked) controller
294 */ 273 */
295struct Slave 274struct Slave
@@ -440,6 +419,7 @@ struct LCFContextQueue
440 */ 419 */
441struct Peer 420struct Peer
442{ 421{
422
443 union 423 union
444 { 424 {
445 struct 425 struct
@@ -2126,8 +2106,8 @@ peer_create_forward_timeout (void *cls,
2126 2106
2127 2107
2128/** 2108/**
2129 * Callback to be called when forwarded peer create operation is 2109 * Callback to be called when forwarded peer create operation is successfull. We
2130 * successfull. We have to relay the reply msg back to the client 2110 * have to relay the reply msg back to the client
2131 * 2111 *
2132 * @param cls ForwardedOperationContext 2112 * @param cls ForwardedOperationContext
2133 * @param msg the peer create success message 2113 * @param msg the peer create success message
@@ -2138,7 +2118,6 @@ peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
2138 struct ForwardedOperationContext *fo_ctxt = cls; 2118 struct ForwardedOperationContext *fo_ctxt = cls;
2139 struct GNUNET_MessageHeader *dup_msg; 2119 struct GNUNET_MessageHeader *dup_msg;
2140 struct Peer *remote_peer; 2120 struct Peer *remote_peer;
2141 uint16_t msize;
2142 2121
2143 GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task); 2122 GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task);
2144 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS) 2123 if (ntohs (msg->type) == GNUNET_MESSAGE_TYPE_TESTBED_PEERCREATESUCCESS)
@@ -2147,9 +2126,35 @@ peer_create_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
2147 remote_peer = fo_ctxt->cls; 2126 remote_peer = fo_ctxt->cls;
2148 peer_list_add (remote_peer); 2127 peer_list_add (remote_peer);
2149 } 2128 }
2150 msize = ntohs (msg->size); 2129 dup_msg = GNUNET_copy_message (msg);
2151 dup_msg = GNUNET_malloc (msize); 2130 queue_message (fo_ctxt->client, dup_msg);
2152 (void) memcpy (dup_msg, msg, msize); 2131 GNUNET_SERVER_client_drop (fo_ctxt->client);
2132 GNUNET_free (fo_ctxt);
2133}
2134
2135
2136/**
2137 * Callback to be called when forwarded peer destroy operation is successfull. We
2138 * have to relay the reply msg back to the client
2139 *
2140 * @param cls ForwardedOperationContext
2141 * @param msg the peer create success message
2142 */
2143static void
2144peer_destroy_success_cb (void *cls, const struct GNUNET_MessageHeader *msg)
2145{
2146 struct ForwardedOperationContext *fo_ctxt = cls;
2147 struct GNUNET_MessageHeader *dup_msg;
2148 struct Peer *remote_peer;
2149
2150 GNUNET_SCHEDULER_cancel (fo_ctxt->timeout_task);
2151 if (GNUNET_MESSAGE_TYPE_TESTBED_GENERICOPSUCCESS == ntohs (msg->type))
2152 {
2153 remote_peer = fo_ctxt->cls;
2154 GNUNET_assert (NULL != remote_peer);
2155 peer_list_remove (remote_peer);
2156 }
2157 dup_msg = GNUNET_copy_message (msg);
2153 queue_message (fo_ctxt->client, dup_msg); 2158 queue_message (fo_ctxt->client, dup_msg);
2154 GNUNET_SERVER_client_drop (fo_ctxt->client); 2159 GNUNET_SERVER_client_drop (fo_ctxt->client);
2155 GNUNET_free (fo_ctxt); 2160 GNUNET_free (fo_ctxt);
@@ -2336,11 +2341,12 @@ handle_peer_destroy (void *cls, struct GNUNET_SERVER_Client *client,
2336 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext)); 2341 fopc = GNUNET_malloc (sizeof (struct ForwardedOperationContext));
2337 GNUNET_SERVER_client_keep (client); 2342 GNUNET_SERVER_client_keep (client);
2338 fopc->client = client; 2343 fopc->client = client;
2339 fopc->operation_id = GNUNET_ntohll (msg->operation_id); 2344 fopc->cls = peer;
2345 fopc->operation_id = GNUNET_ntohll (msg->operation_id);
2340 fopc->opc = 2346 fopc->opc =
2341 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.slave->controller, 2347 GNUNET_TESTBED_forward_operation_msg_ (peer->details.remote.slave->controller,
2342 fopc->operation_id, &msg->header, 2348 fopc->operation_id, &msg->header,
2343 &forwarded_operation_reply_relay, 2349 &peer_destroy_success_cb,
2344 fopc); 2350 fopc);
2345 fopc->timeout_task = 2351 fopc->timeout_task =
2346 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout, 2352 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &forwarded_operation_timeout,
@@ -2984,6 +2990,27 @@ reghost_match_iterator (void *cls,
2984 2990
2985 2991
2986/** 2992/**
2993 * Function to generate the hashcode corresponding to a RegisteredHostContext
2994 *
2995 * @param reg_host the host which is being registered in RegisteredHostContext
2996 * @param host the host of the controller which has to connect to the above rhost
2997 * @return the hashcode
2998 */
2999static struct GNUNET_HashCode
3000hash_hosts (struct GNUNET_TESTBED_Host *reg_host,
3001 struct GNUNET_TESTBED_Host *host)
3002{
3003 struct GNUNET_HashCode hash;
3004 uint32_t host_ids[2];
3005
3006 host_ids[0] = GNUNET_TESTBED_host_get_id_ (reg_host);
3007 host_ids[1] = GNUNET_TESTBED_host_get_id_ (host);
3008 GNUNET_CRYPTO_hash (host_ids, sizeof (host_ids), &hash);
3009 return hash;
3010}
3011
3012
3013/**
2987 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages 3014 * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages
2988 * 3015 *
2989 * @param cls NULL 3016 * @param cls NULL