aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2016-07-20 12:07:05 +0000
committerBart Polot <bart@net.in.tum.de>2016-07-20 12:07:05 +0000
commitdbb12b0c0216846ec0cfa30ed2760c221434eaee (patch)
tree140b649ad916e45f17faa42a5ba5cdf3563b2e52 /src/cadet
parentcaa4196867da8684c5b1fd2e747ecb9d21cbba8b (diff)
downloadgnunet-dbb12b0c0216846ec0cfa30ed2760c221434eaee.tar.gz
gnunet-dbb12b0c0216846ec0cfa30ed2760c221434eaee.zip
- adapt test cases / framework to new port system
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/cadet_test_lib.c16
-rw-r--r--src/cadet/cadet_test_lib.h4
-rw-r--r--src/cadet/gnunet-cadet-profiler.c11
-rw-r--r--src/cadet/gnunet-service-cadet_channel.c2
-rw-r--r--src/cadet/gnunet-service-cadet_local.c2
-rw-r--r--src/cadet/gnunet-service-cadet_local.h2
-rw-r--r--src/cadet/test_cadet.c23
-rw-r--r--src/cadet/test_cadet_local.c21
-rw-r--r--src/cadet/test_cadet_single.c21
9 files changed, 59 insertions, 43 deletions
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
80 /** 80 /**
81 * Application ports. 81 * Application ports.
82 */ 82 */
83 const uint32_t *ports; 83 const struct GNUNET_HashCode **ports;
84 84
85}; 85};
86 86
@@ -94,7 +94,7 @@ struct GNUNET_CADET_TEST_AdapterContext
94 * Peer number for the particular peer. 94 * Peer number for the particular peer.
95 */ 95 */
96 unsigned int peer; 96 unsigned int peer;
97 97
98 /** 98 /**
99 * General context. 99 * General context.
100 */ 100 */
@@ -124,6 +124,16 @@ cadet_connect_adapter (void *cls,
124 (void *) (long) actx->peer, 124 (void *) (long) actx->peer,
125 ctx->cleaner, 125 ctx->cleaner,
126 ctx->handlers); 126 ctx->handlers);
127 if (NULL == ctx->ports)
128 return h;
129
130 for (int i = 0; NULL != ctx->ports[i]; i++)
131 {
132 (void ) GNUNET_CADET_open_port (h, ctx->ports[i],
133 ctx->new_channel,
134 (void *) (long) actx->peer);
135 }
136
127 return h; 137 return h;
128} 138}
129 139
@@ -269,7 +279,7 @@ GNUNET_CADET_TEST_run (const char *testname,
269 GNUNET_CADET_InboundChannelNotificationHandler new_channel, 279 GNUNET_CADET_InboundChannelNotificationHandler new_channel,
270 GNUNET_CADET_ChannelEndHandler cleaner, 280 GNUNET_CADET_ChannelEndHandler cleaner,
271 struct GNUNET_CADET_MessageHandler* handlers, 281 struct GNUNET_CADET_MessageHandler* handlers,
272 const uint32_t *ports) 282 const struct GNUNET_HashCode **ports)
273{ 283{
274 struct GNUNET_CADET_TEST_Context *ctx; 284 struct GNUNET_CADET_TEST_Context *ctx;
275 285
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,
71 * @param new_channel Handler for incoming tunnels. 71 * @param new_channel Handler for incoming tunnels.
72 * @param cleaner Cleaner for destroyed incoming tunnels. 72 * @param cleaner Cleaner for destroyed incoming tunnels.
73 * @param handlers Message handlers. 73 * @param handlers Message handlers.
74 * @param ports Ports the peers offer. 74 * @param ports Ports the peers offer, NULL-terminated.
75 */ 75 */
76void 76void
77GNUNET_CADET_TEST_run (const char *testname, 77GNUNET_CADET_TEST_run (const char *testname,
@@ -82,7 +82,7 @@ GNUNET_CADET_TEST_run (const char *testname,
82 GNUNET_CADET_InboundChannelNotificationHandler new_channel, 82 GNUNET_CADET_InboundChannelNotificationHandler new_channel,
83 GNUNET_CADET_ChannelEndHandler cleaner, 83 GNUNET_CADET_ChannelEndHandler cleaner,
84 struct GNUNET_CADET_MessageHandler* handlers, 84 struct GNUNET_CADET_MessageHandler* handlers,
85 const uint32_t* ports); 85 const struct GNUNET_HashCode **ports);
86 86
87 87
88/** 88/**
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[] = {
816static void * 816static void *
817incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel, 817incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
818 const struct GNUNET_PeerIdentity *initiator, 818 const struct GNUNET_PeerIdentity *initiator,
819 uint32_t port, enum GNUNET_CADET_ChannelOption options) 819 const struct GNUNET_HashCode *port,
820 enum GNUNET_CADET_ChannelOption options)
820{ 821{
821 long n = (long) cls; 822 long n = (long) cls;
822 struct CadetPeer *peer; 823 struct CadetPeer *peer;
@@ -921,7 +922,7 @@ start_test (void *cls)
921 peers[i].dest = select_random_peer (&peers[i]); 922 peers[i].dest = select_random_peer (&peers[i]);
922 peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL, 923 peers[i].ch = GNUNET_CADET_channel_create (peers[i].cadet, NULL,
923 &peers[i].dest->id, 924 &peers[i].dest->id,
924 1, flags); 925 GC_u2h (1), flags);
925 if (NULL == peers[i].ch) 926 if (NULL == peers[i].ch)
926 { 927 {
927 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i); 928 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Channel %lu failed\n", i);
@@ -966,7 +967,7 @@ warmup (void)
966 i, get_index (peer)); 967 i, get_index (peer));
967 peers[i].warmup_ch = 968 peers[i].warmup_ch =
968 GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id, 969 GNUNET_CADET_channel_create (peers[i].cadet, NULL, &peer->id,
969 1, GNUNET_CADET_OPTION_DEFAULT); 970 GC_u2h (1), GNUNET_CADET_OPTION_DEFAULT);
970 if (NULL == peers[i].warmup_ch) 971 if (NULL == peers[i].warmup_ch)
971 { 972 {
972 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i); 973 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Warmup %u failed\n", i);
@@ -1083,7 +1084,7 @@ tmain (void *cls,
1083int 1084int
1084main (int argc, char *argv[]) 1085main (int argc, char *argv[])
1085{ 1086{
1086 static uint32_t ports[2]; 1087 static const struct GNUNET_HashCode *ports[2];
1087 const char *config_file; 1088 const char *config_file;
1088 1089
1089 config_file = ".profiler.conf"; 1090 config_file = ".profiler.conf";
@@ -1135,7 +1136,7 @@ main (int argc, char *argv[])
1135 GNUNET_assert (NULL != ids); 1136 GNUNET_assert (NULL != ids);
1136 p_ids = 0; 1137 p_ids = 0;
1137 test_finished = GNUNET_NO; 1138 test_finished = GNUNET_NO;
1138 ports[0] = 1; 1139 ports[0] = GC_u2h (1);
1139 ports[1] = 0; 1140 ports[1] = 0;
1140 GNUNET_CADET_TEST_run ("cadet-profiler", config_file, peers_total, 1141 GNUNET_CADET_TEST_run ("cadet-profiler", config_file, peers_total,
1141 &tmain, NULL, /* tmain cls */ 1142 &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,
2149 struct CadetChannel *ch; 2149 struct CadetChannel *ch;
2150 struct CadetClient *c; 2150 struct CadetClient *c;
2151 int new_channel; 2151 int new_channel;
2152 struct GNUNET_HashCode *port; 2152 const struct GNUNET_HashCode *port;
2153 2153
2154 chid = ntohl (msg->chid); 2154 chid = ntohl (msg->chid);
2155 2155
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)
1312 * @return non-NULL if a client has the port. 1312 * @return non-NULL if a client has the port.
1313 */ 1313 */
1314struct CadetClient * 1314struct CadetClient *
1315GML_client_get_by_port (struct GNUNET_HashCode *port) 1315GML_client_get_by_port (const struct GNUNET_HashCode *port)
1316{ 1316{
1317 return GNUNET_CONTAINER_multihashmap_get (ports, port); 1317 return GNUNET_CONTAINER_multihashmap_get (ports, port);
1318} 1318}
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);
134 * @return non-NULL if a client has the port. 134 * @return non-NULL if a client has the port.
135 */ 135 */
136struct CadetClient * 136struct CadetClient *
137GML_client_get_by_port (struct GNUNET_HashCode *port); 137GML_client_get_by_port (const struct GNUNET_HashCode *port);
138 138
139/** 139/**
140 * Deletes a tunnel from a client (either owner or destination). 140 * 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
@@ -97,6 +97,11 @@ struct GNUNET_TESTBED_Operation *t_op[2];
97struct GNUNET_PeerIdentity *p_id[2]; 97struct GNUNET_PeerIdentity *p_id[2];
98 98
99/** 99/**
100 * Port ID
101 */
102struct GNUNET_HashCode port;
103
104/**
100 * Peer ids counter. 105 * Peer ids counter.
101 */ 106 */
102unsigned int p_ids; 107unsigned int p_ids;
@@ -761,12 +766,13 @@ static struct GNUNET_CADET_MessageHandler handlers[] = {
761static void * 766static void *
762incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel, 767incoming_channel (void *cls, struct GNUNET_CADET_Channel *channel,
763 const struct GNUNET_PeerIdentity *initiator, 768 const struct GNUNET_PeerIdentity *initiator,
764 uint32_t port, enum GNUNET_CADET_ChannelOption options) 769 const struct GNUNET_HashCode *port,
770 enum GNUNET_CADET_ChannelOption options)
765{ 771{
766 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 772 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
767 "Incoming channel from %s to peer %d\n", 773 "Incoming channel from %s to peer %d:%s\n",
768 GNUNET_i2s (initiator), 774 GNUNET_i2s (initiator),
769 (int) (long) cls); 775 (int) (long) cls, GNUNET_h2s (port));
770 ok++; 776 ok++;
771 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok); 777 GNUNET_log (GNUNET_ERROR_TYPE_INFO, " ok: %d\n", ok);
772 if ((long) cls == peers_requested - 1) 778 if ((long) cls == peers_requested - 1)
@@ -865,7 +871,8 @@ do_test (void *cls)
865 test = SPEED; 871 test = SPEED;
866 flags |= GNUNET_CADET_OPTION_RELIABLE; 872 flags |= GNUNET_CADET_OPTION_RELIABLE;
867 } 873 }
868 ch = GNUNET_CADET_channel_create (h1, NULL, p_id[1], 1, flags); 874
875 ch = GNUNET_CADET_channel_create (h1, NULL, p_id[1], &port, flags);
869 876
870 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, 877 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
871 &gather_stats_and_exit, 878 &gather_stats_and_exit,
@@ -965,8 +972,10 @@ int
965main (int argc, char *argv[]) 972main (int argc, char *argv[])
966{ 973{
967 initialized = GNUNET_NO; 974 initialized = GNUNET_NO;
968 static uint32_t ports[2]; 975 static const struct GNUNET_HashCode *ports[2];
969 const char *config_file; 976 const char *config_file;
977 char port_id[] = "test port";
978 GNUNET_CRYPTO_hash (port_id, sizeof (port_id), &port);
970 979
971 GNUNET_log_setup ("test", "DEBUG", NULL); 980 GNUNET_log_setup ("test", "DEBUG", NULL);
972 config_file = "test_cadet.conf"; 981 config_file = "test_cadet.conf";
@@ -1066,8 +1075,8 @@ main (int argc, char *argv[])
1066 } 1075 }
1067 1076
1068 p_ids = 0; 1077 p_ids = 0;
1069 ports[0] = 1; 1078 ports[0] = &port;
1070 ports[1] = 0; 1079 ports[1] = NULL;
1071 GNUNET_CADET_TEST_run ("test_cadet_small", 1080 GNUNET_CADET_TEST_run ("test_cadet_small",
1072 config_file, 1081 config_file,
1073 peers_requested, 1082 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 *
149inbound_channel (void *cls, 149inbound_channel (void *cls,
150 struct GNUNET_CADET_Channel *channel, 150 struct GNUNET_CADET_Channel *channel,
151 const struct GNUNET_PeerIdentity *initiator, 151 const struct GNUNET_PeerIdentity *initiator,
152 uint32_t port, 152 const struct GNUNET_HashCode *port,
153 enum GNUNET_CADET_ChannelOption options) 153 enum GNUNET_CADET_ChannelOption options)
154{ 154{
155 long id = (long) cls; 155 long id = (long) cls;
156 156
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
158 "received incoming channel on peer %d, port %u\n", 158 "received incoming channel on peer %d, port %s\n",
159 (int) id, 159 (int) id,
160 (unsigned int) port); 160 GNUNET_h2s (port));
161 if (id != 2L) 161 if (id != 2L)
162 { 162 {
163 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 163 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
@@ -259,7 +259,7 @@ do_connect (void *cls)
259 connect_task = NULL; 259 connect_task = NULL;
260 GNUNET_TESTING_peer_get_identity (me, &id); 260 GNUNET_TESTING_peer_get_identity (me, &id);
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n"); 261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
262 ch = GNUNET_CADET_channel_create (cadet_peer_1, NULL, &id, 1, 262 ch = GNUNET_CADET_channel_create (cadet_peer_1, NULL, &id, GC_u2h (1),
263 GNUNET_CADET_OPTION_DEFAULT); 263 GNUNET_CADET_OPTION_DEFAULT);
264 mth = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO, 264 mth = GNUNET_CADET_notify_transmit_ready (ch, GNUNET_NO,
265 GNUNET_TIME_UNIT_FOREVER_REL, 265 GNUNET_TIME_UNIT_FOREVER_REL,
@@ -280,8 +280,6 @@ run (void *cls,
280 const struct GNUNET_CONFIGURATION_Handle *cfg, 280 const struct GNUNET_CONFIGURATION_Handle *cfg,
281 struct GNUNET_TESTING_Peer *peer) 281 struct GNUNET_TESTING_Peer *peer)
282{ 282{
283 static uint32_t ports[] = {1, 0};
284
285 me = peer; 283 me = peer;
286 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 284 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
287 abort_task = 285 abort_task =
@@ -291,17 +289,16 @@ run (void *cls,
291 NULL); 289 NULL);
292 cadet_peer_1 = GNUNET_CADET_connect (cfg, /* configuration */ 290 cadet_peer_1 = GNUNET_CADET_connect (cfg, /* configuration */
293 (void *) 1L, /* cls */ 291 (void *) 1L, /* cls */
294 NULL, /* inbound new hndlr */
295 &channel_end, /* channel end hndlr */ 292 &channel_end, /* channel end hndlr */
296 handlers1, /* traffic handlers */ 293 handlers1); /* traffic handlers */
297 NULL); /* ports offered */
298 294
299 cadet_peer_2 = GNUNET_CADET_connect (cfg, /* configuration */ 295 cadet_peer_2 = GNUNET_CADET_connect (cfg, /* configuration */
300 (void *) 2L, /* cls */ 296 (void *) 2L, /* cls */
301 &inbound_channel, /* inbound new hndlr */
302 &channel_end, /* channel end hndlr */ 297 &channel_end, /* channel end hndlr */
303 handlers2, /* traffic handlers */ 298 handlers2); /* traffic handlers */
304 ports); /* ports offered */ 299 GNUNET_CADET_open_port (cadet_peer_2, GC_u2h (1),
300 &inbound_channel, (void *) 2L);
301
305 if (NULL == cadet_peer_1 || NULL == cadet_peer_2) 302 if (NULL == cadet_peer_1 || NULL == cadet_peer_2)
306 { 303 {
307 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 304 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,
160 */ 160 */
161static void * 161static void *
162inbound_channel (void *cls, struct GNUNET_CADET_Channel *channel, 162inbound_channel (void *cls, struct GNUNET_CADET_Channel *channel,
163 const struct GNUNET_PeerIdentity *initiator, 163 const struct GNUNET_PeerIdentity *initiator,
164 uint32_t port, enum GNUNET_CADET_ChannelOption options) 164 const struct GNUNET_HashCode *port,
165 enum GNUNET_CADET_ChannelOption options)
165{ 166{
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
167 "received incoming channel on port %u\n", 168 "received incoming channel on port %s\n",
168 port); 169 GNUNET_h2s (port));
169 ch2 = channel; 170 ch2 = channel;
170 return NULL; 171 return NULL;
171} 172}
@@ -249,8 +250,8 @@ do_connect (void *cls)
249 connect_task = NULL; 250 connect_task = NULL;
250 GNUNET_TESTING_peer_get_identity (me, &id); 251 GNUNET_TESTING_peer_get_identity (me, &id);
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n"); 252 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
252 ch1 = GNUNET_CADET_channel_create (cadet, NULL, &id, 1, 253 ch1 = GNUNET_CADET_channel_create (cadet, NULL, &id, GC_u2h (1),
253 GNUNET_CADET_OPTION_DEFAULT); 254 GNUNET_CADET_OPTION_DEFAULT);
254 GNUNET_CADET_notify_transmit_ready (ch1, GNUNET_NO, 255 GNUNET_CADET_notify_transmit_ready (ch1, GNUNET_NO,
255 GNUNET_TIME_UNIT_FOREVER_REL, 256 GNUNET_TIME_UNIT_FOREVER_REL,
256 size, &do_send, NULL); 257 size, &do_send, NULL);
@@ -269,8 +270,6 @@ run (void *cls,
269 const struct GNUNET_CONFIGURATION_Handle *cfg, 270 const struct GNUNET_CONFIGURATION_Handle *cfg,
270 struct GNUNET_TESTING_Peer *peer) 271 struct GNUNET_TESTING_Peer *peer)
271{ 272{
272 static uint32_t ports[] = {1, 0};
273
274 me = peer; 273 me = peer;
275 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 274 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
276 abort_task = 275 abort_task =
@@ -279,10 +278,10 @@ run (void *cls,
279 NULL); 278 NULL);
280 cadet = GNUNET_CADET_connect (cfg, /* configuration */ 279 cadet = GNUNET_CADET_connect (cfg, /* configuration */
281 (void *) 1L, /* cls */ 280 (void *) 1L, /* cls */
282 &inbound_channel, /* inbound new hndlr */
283 &channel_end, /* inbound end hndlr */ 281 &channel_end, /* inbound end hndlr */
284 handlers1, /* traffic handlers */ 282 handlers1); /* traffic handlers */
285 ports); /* ports offered */ 283 GNUNET_CADET_open_port (cadet, GC_u2h (1), &inbound_channel, (void *) 1L);
284
286 285
287 if (NULL == cadet) 286 if (NULL == cadet)
288 { 287 {