diff options
Diffstat (limited to 'src/testbed/gnunet-service-testbed_oc.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed_oc.c | 106 |
1 files changed, 66 insertions, 40 deletions
diff --git a/src/testbed/gnunet-service-testbed_oc.c b/src/testbed/gnunet-service-testbed_oc.c index 07a9fd0f0..d27c2bbf7 100644 --- a/src/testbed/gnunet-service-testbed_oc.c +++ b/src/testbed/gnunet-service-testbed_oc.c | |||
@@ -150,9 +150,14 @@ struct OverlayConnectContext | |||
150 | struct OperationContext *opc; | 150 | struct OperationContext *opc; |
151 | 151 | ||
152 | /** | 152 | /** |
153 | * Controller of peer 2; NULL if the peer is a local peer | 153 | * Controller of peer 2; NULL if the peer is a local peer or until the |
154 | * connection to the controller is established | ||
154 | */ | 155 | */ |
155 | struct GNUNET_TESTBED_Controller *peer2_controller; | 156 | struct GNUNET_TESTBED_Controller *p2c; |
157 | |||
158 | struct NeighbourConnectNotification *p2_ncn; | ||
159 | |||
160 | struct Neighbour *p2n; | ||
156 | 161 | ||
157 | /** | 162 | /** |
158 | * The transport TryConnectContext. This will be NULL if the second peer is a | 163 | * The transport TryConnectContext. This will be NULL if the second peer is a |
@@ -418,16 +423,23 @@ cleanup_occ (struct OverlayConnectContext *occ) | |||
418 | GST_cache_get_handle_done (occ->cgh_p1th); | 423 | GST_cache_get_handle_done (occ->cgh_p1th); |
419 | if (NULL != occ->tcc.cgh_th) | 424 | if (NULL != occ->tcc.cgh_th) |
420 | GST_cache_get_handle_done (occ->tcc.cgh_th); | 425 | GST_cache_get_handle_done (occ->tcc.cgh_th); |
426 | if (NULL != occ->p2n) | ||
427 | { | ||
428 | if (NULL != occ->p2_ncn) | ||
429 | GST_neighbour_get_connection_cancel (occ->p2_ncn); | ||
430 | if (NULL != occ->p2c) | ||
431 | GST_neighbour_release_connection (occ->p2n); | ||
432 | } | ||
421 | GNUNET_assert (NULL != GST_peer_list); | 433 | GNUNET_assert (NULL != GST_peer_list); |
422 | GNUNET_assert (occ->peer->reference_cnt > 0); | 434 | GNUNET_assert (occ->peer->reference_cnt > 0); |
423 | occ->peer->reference_cnt--; | 435 | occ->peer->reference_cnt--; |
424 | if ( (GNUNET_YES == occ->peer->destroy_flag) && | 436 | if ( (GNUNET_YES == occ->peer->destroy_flag) && |
425 | (0 == occ->peer->reference_cnt) ) | 437 | (0 == occ->peer->reference_cnt) ) |
426 | GST_destroy_peer (occ->peer); | 438 | GST_destroy_peer (occ->peer); |
427 | if (NULL == occ->peer2_controller) | 439 | if ( (occ->other_peer_id < GST_peer_list_size) |
440 | && (NULL != (other_peer = GST_peer_list[occ->other_peer_id])) | ||
441 | && (GNUNET_YES != other_peer->is_remote) ) | ||
428 | { | 442 | { |
429 | other_peer = GST_peer_list[occ->other_peer_id]; | ||
430 | GNUNET_assert (NULL != other_peer); | ||
431 | GNUNET_assert (other_peer->reference_cnt > 0); | 443 | GNUNET_assert (other_peer->reference_cnt > 0); |
432 | other_peer->reference_cnt--; | 444 | other_peer->reference_cnt--; |
433 | if ( (GNUNET_YES == other_peer->destroy_flag) && | 445 | if ( (GNUNET_YES == other_peer->destroy_flag) && |
@@ -675,7 +687,7 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
675 | return; | 687 | return; |
676 | GNUNET_assert (NULL != occ->hello); | 688 | GNUNET_assert (NULL != occ->hello); |
677 | other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity)); | 689 | other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity)); |
678 | if (NULL != occ->peer2_controller) | 690 | if (NULL != occ->p2c) |
679 | { | 691 | { |
680 | struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg; | 692 | struct GNUNET_TESTBED_RemoteOverlayConnectMessage *msg; |
681 | uint16_t msize; | 693 | uint16_t msize; |
@@ -697,7 +709,7 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
697 | (void) memcpy (&msg->peer_identity, &occ->peer_identity, | 709 | (void) memcpy (&msg->peer_identity, &occ->peer_identity, |
698 | sizeof (struct GNUNET_PeerIdentity)); | 710 | sizeof (struct GNUNET_PeerIdentity)); |
699 | memcpy (msg->hello, occ->hello, hello_size); | 711 | memcpy (msg->hello, occ->hello, hello_size); |
700 | GNUNET_TESTBED_queue_message_ (occ->peer2_controller, &msg->header); | 712 | GNUNET_TESTBED_queue_message_ (occ->p2c, &msg->header); |
701 | } | 713 | } |
702 | else | 714 | else |
703 | { | 715 | { |
@@ -767,7 +779,7 @@ p2_transport_connect (struct OverlayConnectContext *occ) | |||
767 | GNUNET_assert (NULL == occ->ghh); | 779 | GNUNET_assert (NULL == occ->ghh); |
768 | GNUNET_assert (NULL == occ->p1th_); | 780 | GNUNET_assert (NULL == occ->p1th_); |
769 | GNUNET_assert (NULL == occ->cgh_p1th); | 781 | GNUNET_assert (NULL == occ->cgh_p1th); |
770 | if (NULL == occ->peer2_controller) | 782 | if (NULL == occ->p2c) |
771 | { | 783 | { |
772 | GNUNET_assert (NULL != GST_peer_list[occ->other_peer_id]); | 784 | GNUNET_assert (NULL != GST_peer_list[occ->other_peer_id]); |
773 | occ->tcc.cgh_th = | 785 | occ->tcc.cgh_th = |
@@ -1069,6 +1081,31 @@ hash_hosts (struct GNUNET_TESTBED_Host *reg_host, | |||
1069 | return hash; | 1081 | return hash; |
1070 | } | 1082 | } |
1071 | 1083 | ||
1084 | static void | ||
1085 | p2_controller_connect_cb (void *cls, struct GNUNET_TESTBED_Controller *c) | ||
1086 | { | ||
1087 | struct OverlayConnectContext *occ = cls; | ||
1088 | struct GNUNET_TESTBED_PeerGetConfigurationMessage cmsg; | ||
1089 | |||
1090 | occ->p2_ncn = NULL; | ||
1091 | occ->p2c = c; | ||
1092 | cmsg.header.size = | ||
1093 | htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); | ||
1094 | cmsg.header.type = | ||
1095 | htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_CONFIGURATION); | ||
1096 | cmsg.peer_id = htonl (occ->other_peer_id); | ||
1097 | cmsg.operation_id = GNUNET_htonll (occ->op_id); | ||
1098 | occ->opc = | ||
1099 | GNUNET_TESTBED_forward_operation_msg_ (occ->p2c, | ||
1100 | occ->op_id, &cmsg.header, | ||
1101 | &overlay_connect_get_config, | ||
1102 | occ); | ||
1103 | GNUNET_free_non_null (occ->emsg); | ||
1104 | GNUNET_asprintf (&occ->emsg, | ||
1105 | "0x%llx: Timeout while getting peer identity of peer " | ||
1106 | "with id: %u", occ->op_id, occ->other_peer_id); | ||
1107 | } | ||
1108 | |||
1072 | 1109 | ||
1073 | /** | 1110 | /** |
1074 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages | 1111 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages |
@@ -1084,7 +1121,7 @@ GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
1084 | const struct GNUNET_TESTBED_OverlayConnectMessage *msg; | 1121 | const struct GNUNET_TESTBED_OverlayConnectMessage *msg; |
1085 | struct Peer *peer; | 1122 | struct Peer *peer; |
1086 | struct OverlayConnectContext *occ; | 1123 | struct OverlayConnectContext *occ; |
1087 | struct GNUNET_TESTBED_Controller *peer2_controller; | 1124 | struct GNUNET_TESTBED_Controller *p2c; |
1088 | uint64_t operation_id; | 1125 | uint64_t operation_id; |
1089 | uint32_t p1; | 1126 | uint32_t p1; |
1090 | uint32_t p2; | 1127 | uint32_t p2; |
@@ -1225,23 +1262,17 @@ GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
1225 | return; | 1262 | return; |
1226 | } | 1263 | } |
1227 | 1264 | ||
1228 | peer2_controller = NULL; | 1265 | struct Neighbour *p2n; |
1266 | p2n = NULL; | ||
1267 | p2c = NULL; | ||
1229 | if ((p2 >= GST_peer_list_size) || (NULL == GST_peer_list[p2])) | 1268 | if ((p2 >= GST_peer_list_size) || (NULL == GST_peer_list[p2])) |
1230 | { | 1269 | { |
1231 | if ((peer2_host_id >= GST_slave_list_size) || | 1270 | if (NULL == (p2n = GST_get_neighbour (peer2_host_id))) |
1232 | (NULL == GST_slave_list[peer2_host_id])) | ||
1233 | { | 1271 | { |
1234 | GNUNET_break (0); | 1272 | GNUNET_break (0); |
1235 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1273 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1236 | "0x%llx: Configuration of peer2's controller missing for connecting peers" | 1274 | "0x%llx: Peer %u's host not in our neighbours list\n", |
1237 | "%u and %u\n", operation_id, p1, p2); | 1275 | operation_id, p2); |
1238 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
1239 | return; | ||
1240 | } | ||
1241 | peer2_controller = GST_slave_list[peer2_host_id]->controller; | ||
1242 | if (NULL == peer2_controller) | ||
1243 | { | ||
1244 | GNUNET_break (0); /* What's going on? */ | ||
1245 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 1276 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
1246 | return; | 1277 | return; |
1247 | } | 1278 | } |
@@ -1249,7 +1280,7 @@ GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
1249 | else | 1280 | else |
1250 | { | 1281 | { |
1251 | if (GNUNET_YES == GST_peer_list[p2]->is_remote) | 1282 | if (GNUNET_YES == GST_peer_list[p2]->is_remote) |
1252 | peer2_controller = GST_peer_list[p2]->details.remote.slave->controller; | 1283 | p2c = GST_peer_list[p2]->details.remote.slave->controller; |
1253 | } | 1284 | } |
1254 | occ = GNUNET_malloc (sizeof (struct OverlayConnectContext)); | 1285 | occ = GNUNET_malloc (sizeof (struct OverlayConnectContext)); |
1255 | GNUNET_CONTAINER_DLL_insert_tail (occq_head, occq_tail, occ); | 1286 | GNUNET_CONTAINER_DLL_insert_tail (occq_head, occq_tail, occ); |
@@ -1258,30 +1289,25 @@ GST_handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
1258 | occ->other_peer_id = p2; | 1289 | occ->other_peer_id = p2; |
1259 | GST_peer_list[p1]->reference_cnt++; | 1290 | GST_peer_list[p1]->reference_cnt++; |
1260 | occ->peer = GST_peer_list[p1]; | 1291 | occ->peer = GST_peer_list[p1]; |
1261 | occ->op_id = GNUNET_ntohll (msg->operation_id); | 1292 | occ->op_id = operation_id; |
1262 | occ->peer2_controller = peer2_controller; | 1293 | occ->p2n = p2n; |
1263 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->timeout_task); | 1294 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == occ->timeout_task); |
1264 | occ->timeout_task = | 1295 | occ->timeout_task = |
1265 | GNUNET_SCHEDULER_add_delayed (GST_timeout, &timeout_overlay_connect, occ); | 1296 | GNUNET_SCHEDULER_add_delayed (GST_timeout, &timeout_overlay_connect, occ); |
1266 | /* Get the identity of the second peer */ | 1297 | /* Get the identity of the second peer */ |
1267 | if (NULL != occ->peer2_controller) | 1298 | if (NULL != p2n) |
1268 | { | 1299 | { |
1269 | struct GNUNET_TESTBED_PeerGetConfigurationMessage cmsg; | ||
1270 | |||
1271 | cmsg.header.size = | ||
1272 | htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); | ||
1273 | cmsg.header.type = | ||
1274 | htons (GNUNET_MESSAGE_TYPE_TESTBED_GET_PEER_CONFIGURATION); | ||
1275 | cmsg.peer_id = msg->peer2; | ||
1276 | cmsg.operation_id = msg->operation_id; | ||
1277 | occ->opc = | ||
1278 | GNUNET_TESTBED_forward_operation_msg_ (occ->peer2_controller, | ||
1279 | occ->op_id, &cmsg.header, | ||
1280 | &overlay_connect_get_config, | ||
1281 | occ); | ||
1282 | GNUNET_asprintf (&occ->emsg, | 1300 | GNUNET_asprintf (&occ->emsg, |
1283 | "0x%llx: Timeout while getting peer identity of peer " | 1301 | "0x%llx: Timeout while acquiring connection to peer %u's " |
1284 | "with id: %u", occ->op_id, occ->other_peer_id); | 1302 | "host: %u\n", occ->op_id, occ->other_peer_id, peer2_host_id); |
1303 | occ->p2_ncn = GST_neighbour_get_connection (p2n, &p2_controller_connect_cb, | ||
1304 | occ); | ||
1305 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
1306 | return; | ||
1307 | } | ||
1308 | if (NULL != p2c) | ||
1309 | { | ||
1310 | p2_controller_connect_cb (occ, p2c); | ||
1285 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 1311 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
1286 | return; | 1312 | return; |
1287 | } | 1313 | } |