diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-14 14:53:07 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-14 14:53:07 +0000 |
commit | 53ce72be0371bdfb23b0b1be5fed4e742732bdbe (patch) | |
tree | d9791256c6a0d091e5396112834f9888896bcfa6 /src/testbed | |
parent | 18de7414c8f47cd201d7cf580dc6c133f75c954e (diff) | |
download | gnunet-53ce72be0371bdfb23b0b1be5fed4e742732bdbe.tar.gz gnunet-53ce72be0371bdfb23b0b1be5fed4e742732bdbe.zip |
1/2 part - inter-host overlay connect
Diffstat (limited to 'src/testbed')
-rw-r--r-- | src/testbed/gnunet-service-testbed.c | 93 |
1 files changed, 84 insertions, 9 deletions
diff --git a/src/testbed/gnunet-service-testbed.c b/src/testbed/gnunet-service-testbed.c index 02dd24f65..f008405d9 100644 --- a/src/testbed/gnunet-service-testbed.c +++ b/src/testbed/gnunet-service-testbed.c | |||
@@ -379,6 +379,11 @@ struct OverlayConnectContext | |||
379 | char *emsg; | 379 | char *emsg; |
380 | 380 | ||
381 | /** | 381 | /** |
382 | * Operation context for suboperations | ||
383 | */ | ||
384 | struct OperationContext *opc; | ||
385 | |||
386 | /** | ||
382 | * The peer identity of the first peer | 387 | * The peer identity of the first peer |
383 | */ | 388 | */ |
384 | struct GNUNET_PeerIdentity peer_identity; | 389 | struct GNUNET_PeerIdentity peer_identity; |
@@ -1953,6 +1958,8 @@ occ_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1953 | LOG_DEBUG ("Cleaning up occ\n"); | 1958 | LOG_DEBUG ("Cleaning up occ\n"); |
1954 | GNUNET_free_non_null (occ->emsg); | 1959 | GNUNET_free_non_null (occ->emsg); |
1955 | GNUNET_free_non_null (occ->hello); | 1960 | GNUNET_free_non_null (occ->hello); |
1961 | if (NULL != occ->opc) | ||
1962 | GNUNET_TESTBED_forward_operation_msg_cancel_ (occ->opc); | ||
1956 | if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task) | 1963 | if (GNUNET_SCHEDULER_NO_TASK != occ->send_hello_task) |
1957 | GNUNET_SCHEDULER_cancel (occ->send_hello_task); | 1964 | GNUNET_SCHEDULER_cancel (occ->send_hello_task); |
1958 | if (NULL != occ->ch) | 1965 | if (NULL != occ->ch) |
@@ -2072,12 +2079,15 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2072 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 2079 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
2073 | return; | 2080 | return; |
2074 | GNUNET_assert (NULL != occ->hello); | 2081 | GNUNET_assert (NULL != occ->hello); |
2082 | other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity)); | ||
2075 | if (GNUNET_YES == occ->other_peer->is_remote) | 2083 | if (GNUNET_YES == occ->other_peer->is_remote) |
2076 | { | 2084 | { |
2077 | struct GNUNET_TESTBED_RequestConnectMessage *msg; | 2085 | struct GNUNET_TESTBED_RequestConnectMessage *msg; |
2078 | uint16_t msize; | 2086 | uint16_t msize; |
2079 | uint16_t hello_size; | 2087 | uint16_t hello_size; |
2080 | 2088 | ||
2089 | LOG_DEBUG ("Offering HELLO of %s to %s via Remote Overlay Request\n", | ||
2090 | GNUNET_i2s (&occ->peer_identity), other_peer_str); | ||
2081 | hello_size = ntohs (occ->hello->size); | 2091 | hello_size = ntohs (occ->hello->size); |
2082 | msize = sizeof (struct GNUNET_TESTBED_RequestConnectMessage) + hello_size; | 2092 | msize = sizeof (struct GNUNET_TESTBED_RequestConnectMessage) + hello_size; |
2083 | msg = GNUNET_malloc (msize); | 2093 | msg = GNUNET_malloc (msize); |
@@ -2093,13 +2103,12 @@ send_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
2093 | } | 2103 | } |
2094 | else | 2104 | else |
2095 | { | 2105 | { |
2096 | other_peer_str = GNUNET_strdup (GNUNET_i2s (&occ->other_peer_identity)); | ||
2097 | LOG_DEBUG ("Offering HELLO of %s to %s\n", | 2106 | LOG_DEBUG ("Offering HELLO of %s to %s\n", |
2098 | GNUNET_i2s (&occ->peer_identity), other_peer_str); | 2107 | GNUNET_i2s (&occ->peer_identity), other_peer_str); |
2099 | GNUNET_free (other_peer_str); | ||
2100 | GNUNET_TRANSPORT_offer_hello (occ->p2th, occ->hello, NULL, NULL); | 2108 | GNUNET_TRANSPORT_offer_hello (occ->p2th, occ->hello, NULL, NULL); |
2101 | GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity); | 2109 | GNUNET_TRANSPORT_try_connect (occ->p2th, &occ->peer_identity); |
2102 | } | 2110 | } |
2111 | GNUNET_free (other_peer_str); | ||
2103 | occ->send_hello_task = | 2112 | occ->send_hello_task = |
2104 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &send_hello, occ); | 2113 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &send_hello, occ); |
2105 | } | 2114 | } |
@@ -2124,8 +2133,9 @@ test_address (void *cls, const struct GNUNET_HELLO_Address *address, | |||
2124 | 2133 | ||
2125 | 2134 | ||
2126 | /** | 2135 | /** |
2127 | * Function called whenever there is an update to the | 2136 | * Function called whenever there is an update to the HELLO of peers in the |
2128 | * HELLO of peers in the OverlayConnectClosure | 2137 | * OverlayConnectClosure. If we have a valid HELLO, we connect to the peer 2's |
2138 | * transport and offer peer 1's HELLO and ask peer 2 to connect to peer 1 | ||
2129 | * | 2139 | * |
2130 | * @param cls closure | 2140 | * @param cls closure |
2131 | * @param hello our updated HELLO | 2141 | * @param hello our updated HELLO |
@@ -2163,7 +2173,8 @@ hello_update_cb (void *cls, const struct GNUNET_MessageHeader *hello) | |||
2163 | NULL); | 2173 | NULL); |
2164 | if (NULL == occ->p2th) | 2174 | if (NULL == occ->p2th) |
2165 | { | 2175 | { |
2166 | occ->emsg = GNUNET_strdup ("Cannot connect to TRANSPORT of peer B"); | 2176 | GNUNET_asprintf (&occ->emsg, "Cannot connect to TRANSPORT of %s\n", |
2177 | GNUNET_i2s (&occ->other_peer_identity)); | ||
2167 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | 2178 | GNUNET_SCHEDULER_cancel (occ->timeout_task); |
2168 | occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | 2179 | occ->timeout_task = GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); |
2169 | return; | 2180 | return; |
@@ -2196,6 +2207,7 @@ core_startup_cb (void *cls, struct GNUNET_CORE_Handle *server, | |||
2196 | if ((NULL == server) || (NULL == my_identity)) | 2207 | if ((NULL == server) || (NULL == my_identity)) |
2197 | goto error_return; | 2208 | goto error_return; |
2198 | GNUNET_free (occ->emsg); | 2209 | GNUNET_free (occ->emsg); |
2210 | occ->ch = server; | ||
2199 | occ->emsg = NULL; | 2211 | occ->emsg = NULL; |
2200 | memcpy (&occ->peer_identity, my_identity, | 2212 | memcpy (&occ->peer_identity, my_identity, |
2201 | sizeof (struct GNUNET_PeerIdentity)); | 2213 | sizeof (struct GNUNET_PeerIdentity)); |
@@ -2221,6 +2233,47 @@ core_startup_cb (void *cls, struct GNUNET_CORE_Handle *server, | |||
2221 | 2233 | ||
2222 | 2234 | ||
2223 | /** | 2235 | /** |
2236 | * Callback to be called when forwarded get peer config operation as part of | ||
2237 | * overlay connect is successfull. Connection to Peer 1's core is made and is | ||
2238 | * checked for new connection from peer 2 | ||
2239 | * | ||
2240 | * @param cls ForwardedOperationContext | ||
2241 | * @param msg the peer create success message | ||
2242 | */ | ||
2243 | static void | ||
2244 | overlay_connect_get_config (void *cls, const struct GNUNET_MessageHeader *msg) | ||
2245 | { | ||
2246 | struct OverlayConnectContext *occ = cls; | ||
2247 | const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *cmsg; | ||
2248 | const struct GNUNET_CORE_MessageHandler no_handlers[] = { | ||
2249 | {NULL, 0, 0} | ||
2250 | }; | ||
2251 | |||
2252 | occ->opc = NULL; | ||
2253 | if (GNUNET_MESSAGE_TYPE_TESTBED_PEERCONFIG != ntohs (msg->type)) | ||
2254 | goto error_return; | ||
2255 | cmsg = (const struct GNUNET_TESTBED_PeerConfigurationInformationMessage *) | ||
2256 | msg; | ||
2257 | memcpy (&occ->other_peer_identity, &cmsg->peer_identity, | ||
2258 | sizeof (struct GNUNET_PeerIdentity)); | ||
2259 | GNUNET_free_non_null (occ->emsg); | ||
2260 | occ->emsg = GNUNET_strdup ("Timeout while connecting to CORE"); | ||
2261 | occ->ch = | ||
2262 | GNUNET_CORE_connect (occ->peer->details.local.cfg, occ, &core_startup_cb, | ||
2263 | &overlay_connect_notify, NULL, NULL, GNUNET_NO, NULL, | ||
2264 | GNUNET_NO, no_handlers); | ||
2265 | if (NULL == occ->ch) | ||
2266 | goto error_return; | ||
2267 | return; | ||
2268 | |||
2269 | error_return: | ||
2270 | GNUNET_SCHEDULER_cancel (occ->timeout_task); | ||
2271 | occ->timeout_task = | ||
2272 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | ||
2273 | } | ||
2274 | |||
2275 | |||
2276 | /** | ||
2224 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages | 2277 | * Handler for GNUNET_MESSAGE_TYPE_TESTBED_OLCONNECT messages |
2225 | * | 2278 | * |
2226 | * @param cls NULL | 2279 | * @param cls NULL |
@@ -2255,7 +2308,29 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
2255 | occ->peer = peer_list[p1]; | 2308 | occ->peer = peer_list[p1]; |
2256 | occ->other_peer = peer_list[p2]; | 2309 | occ->other_peer = peer_list[p2]; |
2257 | occ->op_id = GNUNET_ntohll (msg->operation_id); | 2310 | occ->op_id = GNUNET_ntohll (msg->operation_id); |
2258 | /* Get the identity of the second peer */ | 2311 | /* Get the identity of the second peer */ |
2312 | if (GNUNET_YES == occ->other_peer->is_remote) | ||
2313 | { | ||
2314 | struct GNUNET_TESTBED_PeerGetConfigurationMessage cmsg; | ||
2315 | |||
2316 | cmsg.header.size = | ||
2317 | htons (sizeof (struct GNUNET_TESTBED_PeerGetConfigurationMessage)); | ||
2318 | cmsg.header.type = htons (GNUNET_MESSAGE_TYPE_TESTBED_GETPEERCONFIG); | ||
2319 | cmsg.peer_id = msg->peer2; | ||
2320 | cmsg.operation_id = msg->operation_id; | ||
2321 | occ->opc = | ||
2322 | GNUNET_TESTBED_forward_operation_msg_ (occ->other_peer->details.remote.controller, | ||
2323 | occ->op_id, &cmsg.header, | ||
2324 | &overlay_connect_get_config, | ||
2325 | occ); | ||
2326 | occ->emsg = | ||
2327 | GNUNET_strdup ("Timeout while getting peer identity of peer B\n"); | ||
2328 | occ->timeout_task = | ||
2329 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
2330 | (GNUNET_TIME_UNIT_SECONDS, 30), | ||
2331 | &timeout_overlay_connect, occ); | ||
2332 | return; | ||
2333 | } | ||
2259 | GNUNET_TESTING_peer_get_identity (occ->other_peer->details.local.peer, | 2334 | GNUNET_TESTING_peer_get_identity (occ->other_peer->details.local.peer, |
2260 | &occ->other_peer_identity); | 2335 | &occ->other_peer_identity); |
2261 | /* Connect to the core of 1st peer and wait for the 2nd peer to connect */ | 2336 | /* Connect to the core of 1st peer and wait for the 2nd peer to connect */ |
@@ -2269,9 +2344,9 @@ handle_overlay_connect (void *cls, struct GNUNET_SERVER_Client *client, | |||
2269 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); | 2344 | GNUNET_SCHEDULER_add_now (&timeout_overlay_connect, occ); |
2270 | else | 2345 | else |
2271 | occ->timeout_task = | 2346 | occ->timeout_task = |
2272 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 2347 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
2273 | (GNUNET_TIME_UNIT_SECONDS, 30), | 2348 | (GNUNET_TIME_UNIT_SECONDS, 30), |
2274 | &timeout_overlay_connect, occ); | 2349 | &timeout_overlay_connect, occ); |
2275 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 2350 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
2276 | } | 2351 | } |
2277 | 2352 | ||