From fc9c21d8a48130a33fa80da8027afd0ccfa2329a Mon Sep 17 00:00:00 2001 From: t3sserakt Date: Fri, 3 Jan 2020 11:55:26 +0100 Subject: [PATCH] added code to change the peer opening the port, to make the alice_or_betty method happy --- src/cadet/gnunet-service-cadet.c | 2 + src/cadet/test_cadet.c | 75 ++++++++++++++++++++++++-------- 2 files changed, 59 insertions(+), 18 deletions(-) diff --git a/src/cadet/gnunet-service-cadet.c b/src/cadet/gnunet-service-cadet.c index 979bd05ca..251f4f43e 100644 --- a/src/cadet/gnunet-service-cadet.c +++ b/src/cadet/gnunet-service-cadet.c @@ -579,6 +579,7 @@ handle_channel_create (void *cls, if (ntohl (tcm->ccn.channel_of_client) < GNUNET_CADET_LOCAL_CHANNEL_ID_CLI) { /* Channel ID not in allowed range. */ + LOG (GNUNET_ERROR_TYPE_DEBUG,"Channel ID not in allowed range."); GNUNET_break (0); GNUNET_SERVICE_client_drop (c->client); return; @@ -588,6 +589,7 @@ handle_channel_create (void *cls, if (NULL != ch) { /* Channel ID already in use. Not allowed. */ + LOG (GNUNET_ERROR_TYPE_DEBUG,"Channel ID already in use. Not allowed."); GNUNET_break (0); GNUNET_SERVICE_client_drop (c->client); return; diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c index 458f345be..1500af813 100644 --- a/src/cadet/test_cadet.c +++ b/src/cadet/test_cadet.c @@ -196,11 +196,6 @@ static struct GNUNET_SCHEDULER_Task *test_task; */ static struct GNUNET_SCHEDULER_Task *send_next_msg_task; -/** - * Cadet handle for the root peer - */ -static struct GNUNET_CADET_Handle *h1; - /** * Channel handle for the root peer */ @@ -222,6 +217,9 @@ static struct GNUNET_TIME_Absolute start_time; */ static struct GNUNET_TESTBED_Peer **testbed_peers; + +struct GNUNET_CADET_Handle **cadets_running; + /** * Statistics operation handle. */ @@ -522,6 +520,34 @@ static void disconnect_handler (void *cls, const struct GNUNET_CADET_Channel *channel); +static struct GNUNET_PeerIdentity * +get_from_p_ids() +{ + if (0 < GNUNET_memcmp (p_id[0], p_id[1])) + { + return p_id[1]; + }else + { + return p_id[0]; + } +} + +static struct GNUNET_CADET_Handle * +get_from_cadets() +{ + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "1\n"); + if (0 < GNUNET_memcmp (p_id[0], p_id[1])) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "standard peer\n"); + return cadets_running[0]; + }else + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "the other peer\n"); + return cadets_running[peers_running - 1]; + } + +} /** * Task to reconnect to other peer. @@ -540,7 +566,9 @@ reconnect_op (void *cls) }; long l = (long) cls; struct CadetTestChannelWrapper *ch; - + static struct GNUNET_PeerIdentity *p_id; + static struct GNUNET_CADET_Handle *h1; + reconnect_task = NULL; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reconnecting from line %ld\n", @@ -551,9 +579,13 @@ reconnect_op (void *cls) outgoing_ch = NULL; } ch = GNUNET_new (struct CadetTestChannelWrapper); + + p_id = get_from_p_ids(); + h1 = get_from_cadets(); + outgoing_ch = GNUNET_CADET_channel_create (h1, ch, - p_id[1], + p_id, &port, NULL, &disconnect_handler, @@ -1003,6 +1035,8 @@ start_test (void *cls) GNUNET_MQ_handler_end () }; struct CadetTestChannelWrapper *ch; + static struct GNUNET_PeerIdentity *p_id; + static struct GNUNET_CADET_Handle *h1; test_task = NULL; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "start_test: %s\n", test_name); @@ -1017,28 +1051,36 @@ start_test (void *cls) test = SPEED; } + p_id = get_from_p_ids(); + h1 = get_from_cadets(); + ch = GNUNET_new (struct CadetTestChannelWrapper); outgoing_ch = GNUNET_CADET_channel_create (h1, ch, - p_id[1], + p_id, &port, NULL, &disconnect_handler, handlers); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "channel created\n"); ch->ch = outgoing_ch; - /*if (DESTROY == test) + if (DESTROY == test) { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "dropping message\n"); GNUNET_CADET_drop_message (GNUNET_CADET_get_mq (outgoing_ch), outgoing_ch->ccn, GNUNET_MESSAGE_TYPE_CADET_DROP_CADET_MESSAGE); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "destroying channel\n"); GNUNET_CADET_channel_destroy(outgoing_ch); + p_id = get_from_p_ids(); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "creating channel again\n"); outgoing_ch = GNUNET_CADET_channel_create (h1, ch, - p_id[1], + p_id, &port, NULL, &disconnect_handler, @@ -1046,7 +1088,7 @@ start_test (void *cls) ch->ch = outgoing_ch; - }*/ + } disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, @@ -1142,22 +1184,19 @@ tmain (void *cls, peers_running = num_peers; GNUNET_assert (peers_running == peers_requested); testbed_peers = peers; - if (0 < GNUNET_memcmp (p_id[0], p_id[num_peers - 1])) - { - h1 = cadets[0]; - }else - { - h1 = cadets[num_peers - 1]; - } + cadets_running = cadets; + disconnect_task = GNUNET_SCHEDULER_add_delayed (short_time, &disconnect_cadet_peers, (void *) __LINE__); GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); + t_op[0] = GNUNET_TESTBED_peer_get_information (peers[0], GNUNET_TESTBED_PIT_IDENTITY, &pi_cb, (void *) 0L); + t_op[1] = GNUNET_TESTBED_peer_get_information (peers[num_peers - 1], GNUNET_TESTBED_PIT_IDENTITY, &pi_cb, -- 2.25.1