From: Bart Polot Date: Wed, 20 Jul 2016 12:07:05 +0000 (+0000) Subject: - adapt test cases / framework to new port system X-Git-Tag: initial-import-from-subversion-38251~521 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=dbb12b0c0216846ec0cfa30ed2760c221434eaee;p=oweals%2Fgnunet.git - adapt test cases / framework to new port system --- diff --git a/src/cadet/cadet_test_lib.c b/src/cadet/cadet_test_lib.c index cd9e47b0b..9a70dad49 100644 --- a/src/cadet/cadet_test_lib.c +++ b/src/cadet/cadet_test_lib.c @@ -80,7 +80,7 @@ struct GNUNET_CADET_TEST_Context /** * Application ports. */ - const uint32_t *ports; + const struct GNUNET_HashCode **ports; }; @@ -94,7 +94,7 @@ struct GNUNET_CADET_TEST_AdapterContext * Peer number for the particular peer. */ unsigned int peer; - + /** * General context. */ @@ -124,6 +124,16 @@ cadet_connect_adapter (void *cls, (void *) (long) actx->peer, ctx->cleaner, ctx->handlers); + if (NULL == ctx->ports) + return h; + + for (int i = 0; NULL != ctx->ports[i]; i++) + { + (void ) GNUNET_CADET_open_port (h, ctx->ports[i], + ctx->new_channel, + (void *) (long) actx->peer); + } + return h; } @@ -269,7 +279,7 @@ GNUNET_CADET_TEST_run (const char *testname, GNUNET_CADET_InboundChannelNotificationHandler new_channel, GNUNET_CADET_ChannelEndHandler cleaner, struct GNUNET_CADET_MessageHandler* handlers, - const uint32_t *ports) + const struct GNUNET_HashCode **ports) { struct GNUNET_CADET_TEST_Context *ctx; diff --git a/src/cadet/cadet_test_lib.h b/src/cadet/cadet_test_lib.h index f517fdd4b..464977d42 100644 --- a/src/cadet/cadet_test_lib.h +++ b/src/cadet/cadet_test_lib.h @@ -71,7 +71,7 @@ typedef void (*GNUNET_CADET_TEST_AppMain) (void *cls, * @param new_channel Handler for incoming tunnels. * @param cleaner Cleaner for destroyed incoming tunnels. * @param handlers Message handlers. - * @param ports Ports the peers offer. + * @param ports Ports the peers offer, NULL-terminated. */ void GNUNET_CADET_TEST_run (const char *testname, @@ -82,7 +82,7 @@ GNUNET_CADET_TEST_run (const char *testname, GNUNET_CADET_InboundChannelNotificationHandler new_channel, GNUNET_CADET_ChannelEndHandler cleaner, struct GNUNET_CADET_MessageHandler* handlers, - const uint32_t* ports); + const struct GNUNET_HashCode **ports); /** diff --git a/src/cadet/gnunet-cadet-profiler.c b/src/cadet/gnunet-cadet-profiler.c index 65e8f3219..d688dc60b 100644 --- a/src/cadet/gnunet-cadet-profiler.c +++ b/src/cadet/gnunet-cadet-profiler.c @@ -816,7 +816,8 @@ static struct GNUNET_CADET_MessageHandler handlers[] = { static void * incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *initiator, - uint32_t port, enum GNUNET_CADET_ChannelOption options) + const struct GNUNET_HashCode *port, + enum GNUNET_CADET_ChannelOption options) { long n = (long) cls; struct CadetPeer *peer; @@ -921,7 +922,7 @@ start_test (void *cls) peers[i].dest = select_random_peer (&peers[i]); peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peers[i].dest->id, - 1, flags); + GC_u2h (1), flags); if (NULL == peers[i].ch) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i); @@ -966,7 +967,7 @@ warmup (void) i, get_index (peer)); peers[i].warmup_ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id, - 1, GNUNET_CADET_OPTION_DEFAULT); + GC_u2h (1), GNUNET_CADET_OPTION_DEFAULT); if (NULL == peers[i].warmup_ch) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i); @@ -1083,7 +1084,7 @@ tmain (void *cls, int main (int argc, char *argv[]) { - static uint32_t ports[2]; + static const struct GNUNET_HashCode *ports[2]; const char *config_file; config_file = ".profiler.conf"; @@ -1135,7 +1136,7 @@ main (int argc, char *argv[]) GNUNET_assert (NULL != ids); p_ids = 0; test_finished = GNUNET_NO; - ports[0] = 1; + ports[0] = GC_u2h (1); ports[1] = 0; GNUNET_CADET_TEST_run ("cadet-profiler", config_file, peers_total, &tmain, NULL, /* tmain cls */ diff --git a/src/cadet/gnunet-service-cadet_channel.c b/src/cadet/gnunet-service-cadet_channel.c index d01356c3a..d1dcfdd2d 100644 --- a/src/cadet/gnunet-service-cadet_channel.c +++ b/src/cadet/gnunet-service-cadet_channel.c @@ -2149,7 +2149,7 @@ GCCH_handle_create (struct CadetTunnel *t, struct CadetChannel *ch; struct CadetClient *c; int new_channel; - struct GNUNET_HashCode *port; + const struct GNUNET_HashCode *port; chid = ntohl (msg->chid); diff --git a/src/cadet/gnunet-service-cadet_local.c b/src/cadet/gnunet-service-cadet_local.c index 5e73887e6..d2efb7bef 100644 --- a/src/cadet/gnunet-service-cadet_local.c +++ b/src/cadet/gnunet-service-cadet_local.c @@ -1312,7 +1312,7 @@ GML_client_get (struct GNUNET_SERVER_Client *client) * @return non-NULL if a client has the port. */ struct CadetClient * -GML_client_get_by_port (struct GNUNET_HashCode *port) +GML_client_get_by_port (const struct GNUNET_HashCode *port) { return GNUNET_CONTAINER_multihashmap_get (ports, port); } diff --git a/src/cadet/gnunet-service-cadet_local.h b/src/cadet/gnunet-service-cadet_local.h index 877f8ad6e..f89745092 100644 --- a/src/cadet/gnunet-service-cadet_local.h +++ b/src/cadet/gnunet-service-cadet_local.h @@ -134,7 +134,7 @@ GML_client_get (struct GNUNET_SERVER_Client *client); * @return non-NULL if a client has the port. */ struct CadetClient * -GML_client_get_by_port (struct GNUNET_HashCode *port); +GML_client_get_by_port (const struct GNUNET_HashCode *port); /** * Deletes a tunnel from a client (either owner or destination). diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c index 557524ca3..e2d3902e5 100644 --- a/src/cadet/test_cadet.c +++ b/src/cadet/test_cadet.c @@ -96,6 +96,11 @@ struct GNUNET_TESTBED_Operation *t_op[2]; */ struct GNUNET_PeerIdentity *p_id[2]; +/** + * Port ID + */ +struct GNUNET_HashCode port; + /** * Peer ids counter. */ @@ -761,12 +766,13 @@ static struct GNUNET_CADET_MessageHandler handlers[] = { static void * incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *initiator, - uint32_t port, enum GNUNET_CADET_ChannelOption options) + const struct GNUNET_HashCode *port, + enum GNUNET_CADET_ChannelOption options) { GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Incoming channel from %s to peer %d\n", + "Incoming channel from %s to peer %d:%s\n", GNUNET_i2s (initiator), - (int) (long) cls); + (int) (long) cls, GNUNET_h2s (port)); ok++; GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); if ((long) cls == peers_requested - 1) @@ -865,7 +871,8 @@ do_test (void *cls) test = SPEED; flags |= GNUNET_CADET_OPTION_RELIABLE; } - ch = GNUNET_CADET_channel_create (h1, NULL, p_id[1], 1, flags); + + ch = GNUNET_CADET_channel_create (h1, NULL, p_id[1], &port, flags); disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, &gather_stats_and_exit, @@ -965,8 +972,10 @@ int main (int argc, char *argv[]) { initialized = GNUNET_NO; - static uint32_t ports[2]; + static const struct GNUNET_HashCode *ports[2]; const char *config_file; + char port_id[] = "test port"; + GNUNET_CRYPTO_hash (port_id, sizeof (port_id), &port); GNUNET_log_setup ("test", "DEBUG", NULL); config_file = "test_cadet.conf"; @@ -1066,8 +1075,8 @@ main (int argc, char *argv[]) } p_ids = 0; - ports[0] = 1; - ports[1] = 0; + ports[0] = &port; + ports[1] = NULL; GNUNET_CADET_TEST_run ("test_cadet_small", config_file, peers_requested, diff --git a/src/cadet/test_cadet_local.c b/src/cadet/test_cadet_local.c index d52e06282..ce6f0b29f 100644 --- a/src/cadet/test_cadet_local.c +++ b/src/cadet/test_cadet_local.c @@ -149,15 +149,15 @@ static void * inbound_channel (void *cls, struct GNUNET_CADET_Channel *channel, const struct GNUNET_PeerIdentity *initiator, - uint32_t port, + const struct GNUNET_HashCode *port, enum GNUNET_CADET_ChannelOption options) { long id = (long) cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "received incoming channel on peer %d, port %u\n", + "received incoming channel on peer %d, port %s\n", (int) id, - (unsigned int) port); + GNUNET_h2s (port)); if (id != 2L) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -259,7 +259,7 @@ do_connect (void *cls) connect_task = NULL; GNUNET_TESTING_peer_get_identity (me, &id); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n"); - ch = GNUNET_CADET_channel_create (cadet_peer_1, NULL, &id, 1, + ch = GNUNET_CADET_channel_create (cadet_peer_1, NULL, &id, GC_u2h (1), GNUNET_CADET_OPTION_DEFAULT); mth = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO, GNUNET_TIME_UNIT_FOREVER_REL, @@ -280,8 +280,6 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { - static uint32_t ports[] = {1, 0}; - me = peer; GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); abort_task = @@ -291,17 +289,16 @@ run (void *cls, NULL); cadet_peer_1 = GNUNET_CADET_connect (cfg, /* configuration */ (void *) 1L, /* cls */ - NULL, /* inbound new hndlr */ &channel_end, /* channel end hndlr */ - handlers1, /* traffic handlers */ - NULL); /* ports offered */ + handlers1); /* traffic handlers */ cadet_peer_2 = GNUNET_CADET_connect (cfg, /* configuration */ (void *) 2L, /* cls */ - &inbound_channel, /* inbound new hndlr */ &channel_end, /* channel end hndlr */ - handlers2, /* traffic handlers */ - ports); /* ports offered */ + handlers2); /* traffic handlers */ + GNUNET_CADET_open_port (cadet_peer_2, GC_u2h (1), + &inbound_channel, (void *) 2L); + if (NULL == cadet_peer_1 || NULL == cadet_peer_2) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, diff --git a/src/cadet/test_cadet_single.c b/src/cadet/test_cadet_single.c index b9ab7e23a..9bfaeda0d 100644 --- a/src/cadet/test_cadet_single.c +++ b/src/cadet/test_cadet_single.c @@ -160,12 +160,13 @@ data_callback (void *cls, struct GNUNET_CADET_Channel *channel, */ static void * inbound_channel (void *cls, struct GNUNET_CADET_Channel *channel, - const struct GNUNET_PeerIdentity *initiator, - uint32_t port, enum GNUNET_CADET_ChannelOption options) + const struct GNUNET_PeerIdentity *initiator, + const struct GNUNET_HashCode *port, + enum GNUNET_CADET_ChannelOption options) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "received incoming channel on port %u\n", - port); + "received incoming channel on port %s\n", + GNUNET_h2s (port)); ch2 = channel; return NULL; } @@ -249,8 +250,8 @@ do_connect (void *cls) connect_task = NULL; GNUNET_TESTING_peer_get_identity (me, &id); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n"); - ch1 = GNUNET_CADET_channel_create (cadet, NULL, &id, 1, - GNUNET_CADET_OPTION_DEFAULT); + ch1 = GNUNET_CADET_channel_create (cadet, NULL, &id, GC_u2h (1), + GNUNET_CADET_OPTION_DEFAULT); GNUNET_CADET_notify_transmit_ready (ch1, GNUNET_NO, GNUNET_TIME_UNIT_FOREVER_REL, size, &do_send, NULL); @@ -269,8 +270,6 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_TESTING_Peer *peer) { - static uint32_t ports[] = {1, 0}; - me = peer; GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); abort_task = @@ -279,10 +278,10 @@ run (void *cls, NULL); cadet = GNUNET_CADET_connect (cfg, /* configuration */ (void *) 1L, /* cls */ - &inbound_channel, /* inbound new hndlr */ &channel_end, /* inbound end hndlr */ - handlers1, /* traffic handlers */ - ports); /* ports offered */ + handlers1); /* traffic handlers */ + GNUNET_CADET_open_port (cadet, GC_u2h (1), &inbound_channel, (void *) 1L); + if (NULL == cadet) {