From 68ac115f3e1acd93b8d913d4850f75188f151f86 Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Fri, 31 Jan 2020 09:01:38 +0100 Subject: [PATCH] added montoring api call for getting peers info, but it is not working right now --- src/cadet/test_cadet.c | 92 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 6 deletions(-) diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c index 7b5fc6022..d58f76cdb 100644 --- a/src/cadet/test_cadet.c +++ b/src/cadet/test_cadet.c @@ -77,6 +77,16 @@ struct CadetTestChannelWrapper #define REOPEN 11 #define DESTROY 12 +/** + * Active peer listing operation. + */ +static struct GNUNET_CADET_PeersLister *plo; + +/* + * Task called to check for existing tunnel and depending on that reopen channel + */ +static struct GNUNET_SCHEDULER_Task *get_peers_task; + /** * Which test are we running? */ @@ -640,6 +650,71 @@ reopen_channel () send_test_message (outgoing_ch); } +static void +peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple); + +/** + * We ask the monitoring api for all the peers. + */ +static void +get_peers(void *cls) +{ + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "requesting peers info!\n"); + plo = GNUNET_CADET_list_peers (get_from_cadets(), &peers_callback, NULL); + +} + +/** + * Method called to retrieve information about all peers in CADET, called + * once per peer. + * + * After last peer has been reported, an additional call with NULL is done. + * + * We check the peer we are interested in, if we have a tunnel. If not, we + * reopen the channel + * + * @param cls Closure. + * @param ple information about peer, or NULL on "EOF". + */ +static void +peers_callback (void *cls, const struct GNUNET_CADET_PeerListEntry *ple) +{ + + const struct GNUNET_PeerIdentity *p_id; + + if (NULL == ple) + { + plo = NULL; + return; + } + p_id = get_from_p_ids(); + + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "peer %s equal to peer %s?", + GNUNET_i2s_full (&ple->peer), + GNUNET_i2s_full (&ple->peer)); + + if (p_id == &ple->peer && ple->have_tunnel) + { + + if (NULL != get_peers_task) + { + GNUNET_SCHEDULER_cancel (get_peers_task); + plo = NULL; + get_peers_task = GNUNET_SCHEDULER_add_now (&get_peers, + NULL); + } + } + else if (p_id == &ple->peer) + { + + reopen_channel (); + + } +} + /** * Function called whenever an MQ-channel is destroyed, unless the destruction * was requested by #GNUNET_CADET_channel_destroy. @@ -665,8 +740,12 @@ disconnect_handler (void *cls, if ((NULL != disconnect_task) && (DESTROY == test) && (3 == ok)) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Reopen channel!\n"); - reopen_channel (); + "Reopen channel task!\n"); + if (NULL == get_peers_task) + { + get_peers_task = GNUNET_SCHEDULER_add_now (&get_peers, + NULL); + } return; } @@ -984,7 +1063,7 @@ handle_data (void *cls, if (get_target_channel () == channel) /* Got "data" */ { GNUNET_log (GNUNET_ERROR_TYPE_INFO, " received data %u\n", data_received); - if ((SPEED != test) || ( (ok_goal - 2) == ok) ) + if ((DESTROY != test) && ((SPEED != test) || ( (ok_goal - 2) == ok)) ) { /* Send ACK */ send_test_message (channel); @@ -1072,7 +1151,7 @@ connect_handler (void *cls, (long) cls); GNUNET_assert (0); } - if ((NULL != disconnect_task) && (REOPEN != test)) + if ((NULL != disconnect_task) && (REOPEN != test) && (DESTROY != test)) { GNUNET_SCHEDULER_cancel (disconnect_task); disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, @@ -1155,7 +1234,8 @@ start_test (void *cls) ch->ch = outgoing_ch; - disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, + //if (DESTROY != test) + disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, &gather_stats_and_exit, (void *) __LINE__); if (KEEPALIVE == test) @@ -1186,7 +1266,7 @@ start_test (void *cls) /** * Callback to be called when the requested peer information is available * - * @param cls the closure from GNUNET_TESTBED_peer_get_information() + * @param cls the closure from GNUNET_TESTBED_peer_getinformation() * @param op the operation this callback corresponds to * @param pinfo the result; will be NULL if the operation has failed * @param emsg error message if the operation has failed; -- 2.25.1