aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSree Harsha Totakura <totakura@in.tum.de>2012-10-15 21:30:22 +0000
committerSree Harsha Totakura <totakura@in.tum.de>2012-10-15 21:30:22 +0000
commit49e04f7da6bf4a60e0ca2b49fba18939bfdead25 (patch)
tree78a0decd1f7a31719870088a8aa98b87ca0d2ce0 /src
parent64e4113edf152f6b0a6572057867a3d60f3779c2 (diff)
downloadgnunet-49e04f7da6bf4a60e0ca2b49fba18939bfdead25.tar.gz
gnunet-49e04f7da6bf4a60e0ca2b49fba18939bfdead25.zip
host registration queues in slave handles
Diffstat (limited to 'src')
-rw-r--r--src/testbed/gnunet-service-testbed.c164
1 files changed, 124 insertions, 40 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c
index ad00f276d..f38473e1c 100644
--- a/src/testbed/gnunet-service-testbed.c
+++ b/src/testbed/gnunet-service-testbed.c
@@ -188,7 +188,6 @@ struct HostRegistration
188 * The host that has to be registered 188 * The host that has to be registered
189 */ 189 */
190 struct GNUNET_TESTBED_Host *host; 190 struct GNUNET_TESTBED_Host *host;
191
192}; 191};
193 192
194 193
@@ -229,6 +228,11 @@ struct Slave
229 struct HostRegistration *hr_dll_tail; 228 struct HostRegistration *hr_dll_tail;
230 229
231 /** 230 /**
231 * The current host registration handle
232 */
233 struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
234
235 /**
232 * The id of the host this controller is running on 236 * The id of the host this controller is running on
233 */ 237 */
234 uint32_t host_id; 238 uint32_t host_id;
@@ -284,11 +288,6 @@ struct LCFContext
284 struct GNUNET_SERVER_Client *client; 288 struct GNUNET_SERVER_Client *client;
285 289
286 /** 290 /**
287 * The host registration handle while registered hosts in this context
288 */
289 struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
290
291 /**
292 * The id of the operation which created this context 291 * The id of the operation which created this context
293 */ 292 */
294 uint64_t operation_id; 293 uint64_t operation_id;
@@ -588,14 +587,14 @@ struct LinkControllersContext
588struct ForwardedOverlayConnectContext 587struct ForwardedOverlayConnectContext
589{ 588{
590 /** 589 /**
591 * The gateway controller to which this operation is forwarded to 590 * The gateway to which this operation is forwarded to
592 */ 591 */
593 struct GNUNET_TESTBED_Controller *gateway; 592 struct Slave *gateway;
594 593
595 /** 594 /**
596 * The gateway controller through which peer2's controller can be reached 595 * The gateway through which peer2's controller can be reached
597 */ 596 */
598 struct GNUNET_TESTBED_Controller *gateway2; 597 struct Slave *gateway2;
599 598
600 /** 599 /**
601 * Handle for sub-operations 600 * Handle for sub-operations
@@ -613,11 +612,6 @@ struct ForwardedOverlayConnectContext
613 struct GNUNET_MessageHeader *orig_msg; 612 struct GNUNET_MessageHeader *orig_msg;
614 613
615 /** 614 /**
616 * The host registration handle while registered hosts in this context
617 */
618 struct GNUNET_TESTBED_HostRegistrationHandle *rhandle;
619
620 /**
621 * The id of the operation which created this context information 615 * The id of the operation which created this context information
622 */ 616 */
623 uint64_t operation_id; 617 uint64_t operation_id;
@@ -1105,6 +1099,94 @@ send_operation_success_msg (struct GNUNET_SERVER_Client *client,
1105 1099
1106 1100
1107/** 1101/**
1102 * Callback which will be called to after a host registration succeeded or failed
1103 *
1104 * @param cls the handle to the slave at which the registration is completed
1105 * @param emsg the error message; NULL if host registration is successful
1106 */
1107static void
1108hr_completion (void *cls, const char *emsg);
1109
1110
1111/**
1112 * Attempts to register the next host in the host registration queue
1113 *
1114 * @param slave the slave controller whose host registration queue is checked
1115 * for host registrations
1116 */
1117static void
1118register_next_host (struct Slave *slave)
1119{
1120 struct HostRegistration *hr;
1121
1122 hr = slave->hr_dll_head;
1123 GNUNET_assert (NULL != hr);
1124 GNUNET_assert (NULL == slave->rhandle);
1125 slave->rhandle = GNUNET_TESTBED_register_host (slave->controller,
1126 hr->host,
1127 hr_completion,
1128 slave);
1129}
1130
1131
1132/**
1133 * Callback which will be called to after a host registration succeeded or failed
1134 *
1135 * @param cls the handle to the slave at which the registration is completed
1136 * @param emsg the error message; NULL if host registration is successful
1137 */
1138static void
1139hr_completion (void *cls, const char *emsg)
1140{
1141 struct Slave *slave = cls;
1142 struct HostRegistration *hr;
1143
1144 slave->rhandle = NULL;
1145 hr = slave->hr_dll_head;
1146 GNUNET_assert (NULL != hr);
1147 GNUNET_CONTAINER_DLL_remove (slave->hr_dll_head,
1148 slave->hr_dll_tail,
1149 hr);
1150 if (NULL != hr->cb)
1151 hr->cb (hr->cb_cls, emsg);
1152 GNUNET_free (hr);
1153 if ((NULL == slave->rhandle) && (NULL != slave->hr_dll_head))
1154 register_next_host (slave);
1155}
1156
1157
1158/**
1159 * Adds a host registration's request to a slave's registration queue
1160 *
1161 * @param slave the slave controller at which the given host has to be
1162 * registered
1163 * @param cb the host registration completion callback
1164 * @param cb_cls the closure for the host registration completion callback
1165 * @param host the host which has to be registered
1166 */
1167static void
1168queue_host_registration (struct Slave *slave,
1169 GNUNET_TESTBED_HostRegistrationCompletion cb,
1170 void *cb_cls,
1171 struct GNUNET_TESTBED_Host *host)
1172{
1173 struct HostRegistration *hr;
1174 int call_register;
1175
1176 hr = GNUNET_malloc (sizeof (struct HostRegistration));
1177 hr->cb = cb;
1178 hr->cb_cls = cb_cls;
1179 hr->host = host;
1180 call_register = (NULL == slave->hr_dll_head) ? GNUNET_YES : GNUNET_NO;
1181 GNUNET_CONTAINER_DLL_insert_tail (slave->hr_dll_head,
1182 slave->hr_dll_tail,
1183 hr);
1184 if (GNUNET_YES == call_register)
1185 register_next_host (slave);
1186}
1187
1188
1189/**
1108 * The Link Controller forwarding task 1190 * The Link Controller forwarding task
1109 * 1191 *
1110 * @param cls the LCFContext 1192 * @param cls the LCFContext
@@ -1125,7 +1207,6 @@ lcf_proc_cc (void *cls, const char *emsg)
1125{ 1207{
1126 struct LCFContext *lcf = cls; 1208 struct LCFContext *lcf = cls;
1127 1209
1128 lcf->rhandle = NULL;
1129 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id); 1210 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
1130 switch (lcf->state) 1211 switch (lcf->state)
1131 { 1212 {
@@ -1222,10 +1303,9 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1222 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->delegated_host_id], 1303 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->delegated_host_id],
1223 lcf->gateway->controller)) 1304 lcf->gateway->controller))
1224 { 1305 {
1225 lcf->rhandle = 1306 queue_host_registration (lcf->gateway,
1226 GNUNET_TESTBED_register_host (lcf->gateway->controller, 1307 lcf_proc_cc, lcf,
1227 host_list[lcf->delegated_host_id], 1308 host_list[lcf->delegated_host_id]);
1228 lcf_proc_cc, lcf);
1229 } 1309 }
1230 else 1310 else
1231 { 1311 {
@@ -1238,10 +1318,9 @@ lcf_proc_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1238 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->slave_host_id], 1318 GNUNET_TESTBED_is_host_registered_ (host_list[lcf->slave_host_id],
1239 lcf->gateway->controller)) 1319 lcf->gateway->controller))
1240 { 1320 {
1241 lcf->rhandle = 1321 queue_host_registration (lcf->gateway,
1242 GNUNET_TESTBED_register_host (lcf->gateway->controller, 1322 lcf_proc_cc, lcf,
1243 host_list[lcf->slave_host_id], 1323 host_list[lcf->slave_host_id]);
1244 lcf_proc_cc, lcf);
1245 } 1324 }
1246 else 1325 else
1247 { 1326 {
@@ -1306,8 +1385,6 @@ cleanup_focc (struct ForwardedOverlayConnectContext *focc)
1306 GNUNET_TESTBED_operation_done (focc->sub_op); 1385 GNUNET_TESTBED_operation_done (focc->sub_op);
1307 if (NULL != focc->client) 1386 if (NULL != focc->client)
1308 GNUNET_SERVER_client_drop (focc->client); 1387 GNUNET_SERVER_client_drop (focc->client);
1309 if (NULL != focc->rhandle)
1310 GNUNET_TESTBED_cancel_registration (focc->rhandle);
1311 GNUNET_free_non_null (focc->orig_msg); 1388 GNUNET_free_non_null (focc->orig_msg);
1312 GNUNET_free (focc); 1389 GNUNET_free (focc);
1313} 1390}
@@ -1350,7 +1427,7 @@ slave_event_callback (void *cls,
1350 old_op = focc->sub_op; 1427 old_op = focc->sub_op;
1351 focc->state = FOCC_LINK; 1428 focc->state = FOCC_LINK;
1352 focc->sub_op = GNUNET_TESTBED_controller_link_ (focc, 1429 focc->sub_op = GNUNET_TESTBED_controller_link_ (focc,
1353 focc->gateway, 1430 focc->gateway->controller,
1354 focc->peer2_host_id, 1431 focc->peer2_host_id,
1355 peer_list[focc->peer1]->details.remote.remote_host_id, 1432 peer_list[focc->peer1]->details.remote.remote_host_id,
1356 slave_cfg, 1433 slave_cfg,
@@ -1368,7 +1445,7 @@ slave_event_callback (void *cls,
1368 fopc->operation_id = focc->operation_id; 1445 fopc->operation_id = focc->operation_id;
1369 fopc->cls = NULL; 1446 fopc->cls = NULL;
1370 fopc->opc = 1447 fopc->opc =
1371 GNUNET_TESTBED_forward_operation_msg_ (focc->gateway, 1448 GNUNET_TESTBED_forward_operation_msg_ (focc->gateway->controller,
1372 focc->operation_id, focc->orig_msg, 1449 focc->operation_id, focc->orig_msg,
1373 &forwarded_operation_reply_relay, 1450 &forwarded_operation_reply_relay,
1374 fopc); 1451 fopc);
@@ -2684,7 +2761,6 @@ focc_reg_completion_cc (void *cls, const char *emsg)
2684 struct GNUNET_CONFIGURATION_Handle *cfg; 2761 struct GNUNET_CONFIGURATION_Handle *cfg;
2685 2762
2686 GNUNET_assert (FOCC_REGISTER == focc->state); 2763 GNUNET_assert (FOCC_REGISTER == focc->state);
2687 focc->rhandle = NULL;
2688 GNUNET_assert (NULL == focc->sub_op); 2764 GNUNET_assert (NULL == focc->sub_op);
2689 LOG_DEBUG ("[%u -> %u] Registering peer2's host successful\n", 2765 LOG_DEBUG ("[%u -> %u] Registering peer2's host successful\n",
2690 focc->peer1, focc->peer2); 2766 focc->peer1, focc->peer2);
@@ -2697,7 +2773,7 @@ focc_reg_completion_cc (void *cls, const char *emsg)
2697 our_config : slave_list[focc->peer2_host_id]->cfg; 2773 our_config : slave_list[focc->peer2_host_id]->cfg;
2698 focc->sub_op = 2774 focc->sub_op =
2699 GNUNET_TESTBED_controller_link_ (focc, 2775 GNUNET_TESTBED_controller_link_ (focc,
2700 focc->gateway, 2776 focc->gateway->controller,
2701 focc->peer2_host_id, 2777 focc->peer2_host_id,
2702 peer_list[focc->peer1]->details.remote.remote_host_id, 2778 peer_list[focc->peer1]->details.remote.remote_host_id,
2703 cfg, 2779 cfg,
@@ -2705,7 +2781,7 @@ focc_reg_completion_cc (void *cls, const char *emsg)
2705 return; 2781 return;
2706 } 2782 }
2707 focc->state = FOCC_GET_CFG; 2783 focc->state = FOCC_GET_CFG;
2708 focc->sub_op = GNUNET_TESTBED_get_slave_config_ (focc, focc->gateway2, 2784 focc->sub_op = GNUNET_TESTBED_get_slave_config_ (focc, focc->gateway2->controller,
2709 focc->peer2_host_id); 2785 focc->peer2_host_id);
2710} 2786}
2711 2787
@@ -2746,11 +2822,10 @@ forwarded_overlay_connect_listener (void *cls,
2746 focc->peer1, focc->peer2, focc->peer2_host_id, 2822 focc->peer1, focc->peer2, focc->peer2_host_id,
2747 peer_list[focc->peer1]->details.remote.remote_host_id); 2823 peer_list[focc->peer1]->details.remote.remote_host_id);
2748 focc->state = FOCC_REGISTER; 2824 focc->state = FOCC_REGISTER;
2749 focc->rhandle = 2825 queue_host_registration (focc->gateway,
2750 GNUNET_TESTBED_register_host (focc->gateway, 2826 focc_reg_completion_cc,
2751 host_list[focc->peer2_host_id], 2827 focc,
2752 focc_reg_completion_cc, focc); 2828 host_list[focc->peer2_host_id]);
2753 GNUNET_assert (NULL != focc->rhandle);
2754 break; 2829 break;
2755 default: 2830 default:
2756 GNUNET_assert (0); 2831 GNUNET_assert (0);
@@ -2843,9 +2918,9 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client,
2843 2918
2844 msize = sizeof (struct GNUNET_TESTBED_OverlayConnectMessage); 2919 msize = sizeof (struct GNUNET_TESTBED_OverlayConnectMessage);
2845 focc = GNUNET_malloc (sizeof (struct ForwardedOverlayConnectContext)); 2920 focc = GNUNET_malloc (sizeof (struct ForwardedOverlayConnectContext));
2846 focc->gateway = peer->details.remote.slave->controller; 2921 focc->gateway = peer->details.remote.slave;
2847 focc->gateway2 = (NULL == route_to_peer2_host) ? NULL : 2922 focc->gateway2 = (NULL == route_to_peer2_host) ? NULL :
2848 slave_list[route_to_peer2_host->dest]->controller; 2923 slave_list[route_to_peer2_host->dest];
2849 focc->peer1 = p1; 2924 focc->peer1 = p1;
2850 focc->peer2 = p2; 2925 focc->peer2 = p2;
2851 focc->peer2_host_id = peer2_host_id; 2926 focc->peer2_host_id = peer2_host_id;
@@ -3228,8 +3303,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3228 GNUNET_SCHEDULER_cancel (lcf_proc_task_id); 3303 GNUNET_SCHEDULER_cancel (lcf_proc_task_id);
3229 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK; 3304 lcf_proc_task_id = GNUNET_SCHEDULER_NO_TASK;
3230 } 3305 }
3231 if (NULL != lcfq_head->lcf->rhandle)
3232 GNUNET_TESTBED_cancel_registration (lcfq_head->lcf->rhandle);
3233 } 3306 }
3234 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id); 3307 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == lcf_proc_task_id);
3235 for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head) 3308 for (lcfq = lcfq_head; NULL != lcfq; lcfq = lcfq_head)
@@ -3267,6 +3340,17 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
3267 for (id = 0; id < slave_list_size; id++) 3340 for (id = 0; id < slave_list_size; id++)
3268 if (NULL != slave_list[id]) 3341 if (NULL != slave_list[id])
3269 { 3342 {
3343 struct HostRegistration *hr_entry;
3344
3345 while (NULL != (hr_entry = slave_list[id]->hr_dll_head))
3346 {
3347 GNUNET_CONTAINER_DLL_remove (slave_list[id]->hr_dll_head,
3348 slave_list[id]->hr_dll_tail,
3349 hr_entry);
3350 GNUNET_free (hr_entry);
3351 }
3352 if (NULL != slave_list[id]->rhandle)
3353 GNUNET_TESTBED_cancel_registration (slave_list[id]->rhandle);
3270 if (NULL != slave_list[id]->cfg) 3354 if (NULL != slave_list[id]->cfg)
3271 GNUNET_CONFIGURATION_destroy (slave_list[id]->cfg); 3355 GNUNET_CONFIGURATION_destroy (slave_list[id]->cfg);
3272 if (NULL != slave_list[id]->controller) 3356 if (NULL != slave_list[id]->controller)