diff options
author | xrs <xrs@mail36.net> | 2017-01-29 14:48:48 +0100 |
---|---|---|
committer | xrs <xrs@mail36.net> | 2017-01-29 14:48:48 +0100 |
commit | b97c546ef091428a59e02416cfb53fb4a5953b54 (patch) | |
tree | 141ece4d1675b77c6814a0d2ce45d1a26458661d /src/multicast | |
parent | 271dd457b4b7f42b9353fc94da231a9196ee714a (diff) | |
download | gnunet-b97c546ef091428a59e02416cfb53fb4a5953b54.tar.gz gnunet-b97c546ef091428a59e02416cfb53fb4a5953b54.zip |
fixed callback, still with segfault in configuration.c
Diffstat (limited to 'src/multicast')
-rw-r--r-- | src/multicast/test_multicast_multipeer.c | 131 |
1 files changed, 60 insertions, 71 deletions
diff --git a/src/multicast/test_multicast_multipeer.c b/src/multicast/test_multicast_multipeer.c index e81b63f92..7b7b1407f 100644 --- a/src/multicast/test_multicast_multipeer.c +++ b/src/multicast/test_multicast_multipeer.c | |||
@@ -35,9 +35,10 @@ | |||
35 | 35 | ||
36 | #define NUM_PEERS 2 | 36 | #define NUM_PEERS 2 |
37 | 37 | ||
38 | static struct GNUNET_TESTBED_Operation *op0; | 38 | static struct GNUNET_TESTBED_Operation *op0; |
39 | static struct GNUNET_TESTBED_Operation *op1; | 39 | static struct GNUNET_TESTBED_Operation *op1; |
40 | static struct GNUNET_TESTBED_Peer **peers; | 40 | static struct GNUNET_TESTBED_Peer **peers; |
41 | const struct GNUNET_PeerIdentity *peer_id_origin; | ||
41 | 42 | ||
42 | static struct GNUNET_SCHEDULER_Task *timeout_tid; | 43 | static struct GNUNET_SCHEDULER_Task *timeout_tid; |
43 | 44 | ||
@@ -99,13 +100,6 @@ timeout_task (void *cls) | |||
99 | GNUNET_SCHEDULER_shutdown (); | 100 | GNUNET_SCHEDULER_shutdown (); |
100 | } | 101 | } |
101 | 102 | ||
102 | static void | ||
103 | pi_cb (void *cls, | ||
104 | struct GNUNET_TESTBED_Operation *op, | ||
105 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
106 | const char *emsg) | ||
107 | { | ||
108 | } | ||
109 | 103 | ||
110 | static void | 104 | static void |
111 | member_join_request (void *cls, | 105 | member_join_request (void *cls, |
@@ -211,7 +205,7 @@ service_connect1 (void *cls, | |||
211 | struct GNUNET_MULTICAST_Member *member = ca_result; | 205 | struct GNUNET_MULTICAST_Member *member = ca_result; |
212 | 206 | ||
213 | if (NULL != member) | 207 | if (NULL != member) |
214 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "connected to multicast service of member\n"); | 208 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Connected to multicast service of member\n"); |
215 | else | 209 | else |
216 | result = GNUNET_SYSERR; | 210 | result = GNUNET_SYSERR; |
217 | } | 211 | } |
@@ -230,30 +224,11 @@ multicast_ca1 (void *cls, | |||
230 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 224 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
231 | { | 225 | { |
232 | struct GNUNET_MessageHeader *join_msg; | 226 | struct GNUNET_MessageHeader *join_msg; |
233 | const struct GNUNET_PeerIdentity *peer_id_origin; | ||
234 | struct GNUNET_HashCode pub_hash; | ||
235 | |||
236 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "connecting to multicast service of member...\n"); | ||
237 | 227 | ||
238 | // Get members keys | 228 | // Get members keys |
239 | member_key = GNUNET_CRYPTO_ecdsa_key_create (); | 229 | member_key = GNUNET_CRYPTO_ecdsa_key_create (); |
240 | GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); | 230 | GNUNET_CRYPTO_ecdsa_key_get_public (member_key, &member_pub_key); |
241 | 231 | ||
242 | // Get GNUnet identity of origin | ||
243 | // FIXME: the return value is not a GNUNET_PeerIdentity, it can retrieved in | ||
244 | // pi_cb: pinfo->result.id | ||
245 | peer_id_origin = GNUNET_TESTBED_peer_get_information (peers[0], | ||
246 | GNUNET_TESTBED_PIT_IDENTITY, | ||
247 | pi_cb, | ||
248 | NULL); | ||
249 | |||
250 | GNUNET_assert(NULL != peer_id_origin); | ||
251 | |||
252 | GNUNET_CRYPTO_hash (&peer_id_origin, sizeof (peer_id_origin), &pub_hash); | ||
253 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
254 | "member: id of origin is %s\n", | ||
255 | GNUNET_h2s (&pub_hash)); | ||
256 | |||
257 | char data[] = "Hello Mr. Smith!"; | 232 | char data[] = "Hello Mr. Smith!"; |
258 | uint8_t data_size = strlen (data) + 1; | 233 | uint8_t data_size = strlen (data) + 1; |
259 | join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); | 234 | join_msg = GNUNET_malloc (sizeof (join_msg) + data_size); |
@@ -277,6 +252,40 @@ multicast_ca1 (void *cls, | |||
277 | } | 252 | } |
278 | 253 | ||
279 | 254 | ||
255 | static void | ||
256 | peer_information_cb (void *cls, | ||
257 | struct GNUNET_TESTBED_Operation *op, | ||
258 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
259 | const char *emsg) | ||
260 | { | ||
261 | struct GNUNET_HashCode pub_hash; | ||
262 | |||
263 | if (NULL == pinfo) { | ||
264 | result = GNUNET_SYSERR; | ||
265 | GNUNET_SCHEDULER_shutdown (); | ||
266 | } | ||
267 | |||
268 | GNUNET_CRYPTO_hash (&peer_id_origin, sizeof (peer_id_origin), &pub_hash); | ||
269 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
270 | "Got peer information of origin (%s)\n", GNUNET_h2s (&pub_hash)); | ||
271 | peer_id_origin = pinfo->result.id; | ||
272 | |||
273 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
274 | "Create member peer\n"); | ||
275 | /* connect to multicast service of member */ | ||
276 | op1 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ | ||
277 | peers[1], /* The peer whose service to connect to */ | ||
278 | "multicast", /* The name of the service */ | ||
279 | service_connect1, /* callback to call after a handle to service | ||
280 | is opened */ | ||
281 | NULL, /* closure for the above callback */ | ||
282 | multicast_ca1, /* callback to call with peer's configuration; | ||
283 | this should open the needed service connection */ | ||
284 | multicast_da1, /* callback to be called when closing the | ||
285 | opened service connection */ | ||
286 | NULL); /* closure for the above two callbacks */ | ||
287 | } | ||
288 | |||
280 | /** | 289 | /** |
281 | * Test logic of peer "0" being origin starts here. | 290 | * Test logic of peer "0" being origin starts here. |
282 | * | 291 | * |
@@ -296,7 +305,13 @@ service_connect0 (void *cls, | |||
296 | struct GNUNET_MULTICAST_Origin *origin = ca_result; | 305 | struct GNUNET_MULTICAST_Origin *origin = ca_result; |
297 | 306 | ||
298 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 307 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
299 | "connected to multicast service of origin\n"); | 308 | "Connected to multicast service of origin\n"); |
309 | |||
310 | // Get GNUnet identity of origin | ||
311 | op0 = GNUNET_TESTBED_peer_get_information (peers[0], | ||
312 | GNUNET_TESTBED_PIT_IDENTITY, | ||
313 | peer_information_cb, | ||
314 | NULL); | ||
300 | 315 | ||
301 | /* Connection to service successful. Here we'd usually do something with | 316 | /* Connection to service successful. Here we'd usually do something with |
302 | * the service. */ | 317 | * the service. */ |
@@ -314,9 +329,6 @@ static void * | |||
314 | multicast_ca0 (void *cls, | 329 | multicast_ca0 (void *cls, |
315 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 330 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
316 | { | 331 | { |
317 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
318 | "connecting to multicast service of origin...\n"); | ||
319 | |||
320 | group_key = GNUNET_CRYPTO_eddsa_key_create (); | 332 | group_key = GNUNET_CRYPTO_eddsa_key_create (); |
321 | GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key); | 333 | GNUNET_CRYPTO_eddsa_key_get_public (group_key, &group_pub_key); |
322 | 334 | ||
@@ -340,6 +352,7 @@ multicast_da0 (void *cls, | |||
340 | 352 | ||
341 | } | 353 | } |
342 | 354 | ||
355 | |||
343 | /** | 356 | /** |
344 | * Main function inovked from TESTBED once all of the | 357 | * Main function inovked from TESTBED once all of the |
345 | * peers are up and running. This one then connects | 358 | * peers are up and running. This one then connects |
@@ -366,49 +379,25 @@ testbed_master (void *cls, | |||
366 | { | 379 | { |
367 | /* Testbed is ready with peers running and connected in a pre-defined overlay | 380 | /* Testbed is ready with peers running and connected in a pre-defined overlay |
368 | topology (FIXME) */ | 381 | topology (FIXME) */ |
369 | |||
370 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 382 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
371 | "connected to testbed_master()\n"); | 383 | "Connected to testbed_master()\n"); |
372 | 384 | ||
373 | peers = p; | 385 | peers = p; |
374 | 386 | ||
375 | /** | 387 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
376 | * FIXME: | 388 | "Create origin peer\n"); |
377 | * we can't already GNUNET_TESTBED_service_connect here, because in the | 389 | op0 = GNUNET_TESTBED_service_connect (NULL, /* Closure for operation */ |
378 | * continuation callback multicast_ca1 we need the origin's peer identity | 390 | peers[0], /* The peer whose service to connect to */ |
379 | * which we can retrieve only using the asynchronous | 391 | "multicast", /* The name of the service */ |
380 | * GNUNET_TESTBED_peer_get_information function. | 392 | service_connect0, /* callback to call after a handle to service |
381 | * So we need to call GNUNET_TESTBED_peer_get_information here, and call | 393 | is opened */ |
382 | * GNUNET_TESTBED_service_connect in the result callback. | 394 | NULL, /* closure for the above callback */ |
383 | */ | 395 | multicast_ca0, /* callback to call with peer's configuration; |
384 | 396 | this should open the needed service connection */ | |
385 | /* connect to a peers service */ | 397 | multicast_da0, /* callback to be called when closing the |
386 | op0 = GNUNET_TESTBED_service_connect | 398 | opened service connection */ |
387 | (NULL, /* Closure for operation */ | 399 | NULL); /* closure for the above two callbacks */ |
388 | peers[0], /* The peer whose service to connect to */ | 400 | |
389 | "multicast", /* The name of the service */ | ||
390 | service_connect0, /* callback to call after a handle to service | ||
391 | is opened */ | ||
392 | NULL, /* closure for the above callback */ | ||
393 | multicast_ca0, /* callback to call with peer's configuration; | ||
394 | this should open the needed service connection */ | ||
395 | multicast_da0, /* callback to be called when closing the | ||
396 | opened service connection */ | ||
397 | NULL); /* closure for the above two callbacks */ | ||
398 | |||
399 | op1 = GNUNET_TESTBED_service_connect | ||
400 | (NULL, /* Closure for operation */ | ||
401 | peers[1], /* The peer whose service to connect to */ | ||
402 | "multicast", /* The name of the service */ | ||
403 | service_connect1, /* callback to call after a handle to service | ||
404 | is opened */ | ||
405 | NULL, /* closure for the above callback */ | ||
406 | multicast_ca1, /* callback to call with peer's configuration; | ||
407 | this should open the needed service connection */ | ||
408 | multicast_da1, /* callback to be called when closing the | ||
409 | opened service connection */ | ||
410 | NULL); /* closure for the above two callbacks */ | ||
411 | |||
412 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ | 401 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); /* Schedule a new task on shutdown */ |
413 | 402 | ||
414 | /* Schedule the shutdown task with a delay of a few 1econds */ | 403 | /* Schedule the shutdown task with a delay of a few 1econds */ |