aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-27 12:20:31 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-27 12:20:31 +0000
commit6549574748c9583f86fc35dbb47d7709cafe671d (patch)
treef2b714ca6969633fa1f50a76614a5655dead19bf /src
parentd3834ca8024608b1dc7df467405d8a6ed31e8c05 (diff)
downloadgnunet-6549574748c9583f86fc35dbb47d7709cafe671d.tar.gz
gnunet-6549574748c9583f86fc35dbb47d7709cafe671d.zip
-misc fixes to DHT tests
Diffstat (limited to 'src')
-rw-r--r--src/dht/dht_api.c4
-rw-r--r--src/dht/dht_test_lib.c11
-rw-r--r--src/dht/gnunet-service-dht.c11
-rw-r--r--src/dht/gnunet-service-dht.h5
-rw-r--r--src/dht/gnunet-service-dht_clients.c46
-rw-r--r--src/dht/gnunet-service-dht_clients.h4
-rw-r--r--src/dht/gnunet-service-dht_neighbours.c153
-rw-r--r--src/dht/test_dht_2dtorus.conf8
-rw-r--r--src/dht/test_dht_line.conf10
-rw-r--r--src/dht/test_dht_multipeer.conf13
-rw-r--r--src/dht/test_dht_topo.c231
11 files changed, 362 insertions, 134 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index de1043ca9..f67c1075f 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -993,6 +993,10 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
993 } 993 }
994 if (NULL == handle->mq) 994 if (NULL == handle->mq)
995 return NULL; 995 return NULL;
996 LOG (GNUNET_ERROR_TYPE_DEBUG,
997 "Sending PUT for %s to DHT via %p\n",
998 GNUNET_h2s (key),
999 handle);
996 ph = GNUNET_new (struct GNUNET_DHT_PutHandle); 1000 ph = GNUNET_new (struct GNUNET_DHT_PutHandle);
997 ph->dht_handle = handle; 1001 ph->dht_handle = handle;
998 ph->cont = cont; 1002 ph->cont = cont;
diff --git a/src/dht/dht_test_lib.c b/src/dht/dht_test_lib.c
index a395ce58b..4c1bd3057 100644
--- a/src/dht/dht_test_lib.c
+++ b/src/dht/dht_test_lib.c
@@ -118,7 +118,8 @@ dht_connect_cb (void *cls,
118 118
119 if (NULL != emsg) 119 if (NULL != emsg)
120 { 120 {
121 fprintf (stderr, "Failed to connect to DHT service: %s\n", 121 fprintf (stderr,
122 "Failed to connect to DHT service: %s\n",
122 emsg); 123 emsg);
123 GNUNET_SCHEDULER_shutdown (); 124 GNUNET_SCHEDULER_shutdown ();
124 return; 125 return;
@@ -134,7 +135,7 @@ dht_connect_cb (void *cls,
134 ctx, 135 ctx,
135 ctx->num_peers, 136 ctx->num_peers,
136 ctx->peers, 137 ctx->peers,
137 ctx->dhts); 138 ctx->dhts);
138} 139}
139 140
140 141
@@ -203,8 +204,10 @@ GNUNET_DHT_TEST_run (const char *testname,
203 204
204 ctx = GNUNET_new (struct GNUNET_DHT_TEST_Context); 205 ctx = GNUNET_new (struct GNUNET_DHT_TEST_Context);
205 ctx->num_peers = num_peers; 206 ctx->num_peers = num_peers;
206 ctx->ops = GNUNET_malloc (num_peers * sizeof (struct GNUNET_TESTBED_Operation *)); 207 ctx->ops = GNUNET_new_array (num_peers,
207 ctx->dhts = GNUNET_malloc (num_peers * sizeof (struct GNUNET_DHT_Handle *)); 208 struct GNUNET_TESTBED_Operation *);
209 ctx->dhts = GNUNET_new_array (num_peers,
210 struct GNUNET_DHT_Handle *);
208 ctx->app_main = tmain; 211 ctx->app_main = tmain;
209 ctx->app_main_cls = tmain_cls; 212 ctx->app_main_cls = tmain_cls;
210 (void) GNUNET_TESTBED_test_run (testname, 213 (void) GNUNET_TESTBED_test_run (testname,
diff --git a/src/dht/gnunet-service-dht.c b/src/dht/gnunet-service-dht.c
index a44be2dfe..abdd77548 100644
--- a/src/dht/gnunet-service-dht.c
+++ b/src/dht/gnunet-service-dht.c
@@ -57,6 +57,11 @@ struct GNUNET_BLOCK_Context *GDS_block_context;
57const struct GNUNET_CONFIGURATION_Handle *GDS_cfg; 57const struct GNUNET_CONFIGURATION_Handle *GDS_cfg;
58 58
59/** 59/**
60 * Handle to our server.
61 */
62struct GNUNET_SERVER_Handle *GDS_server;
63
64/**
60 * Our HELLO 65 * Our HELLO
61 */ 66 */
62struct GNUNET_MessageHeader *GDS_my_hello; 67struct GNUNET_MessageHeader *GDS_my_hello;
@@ -140,10 +145,13 @@ shutdown_task (void *cls)
140 * @param c configuration to use 145 * @param c configuration to use
141 */ 146 */
142static void 147static void
143run (void *cls, struct GNUNET_SERVER_Handle *server, 148run (void *cls,
149 struct GNUNET_SERVER_Handle *server,
144 const struct GNUNET_CONFIGURATION_Handle *c) 150 const struct GNUNET_CONFIGURATION_Handle *c)
145{ 151{
146 GDS_cfg = c; 152 GDS_cfg = c;
153 GDS_server = server;
154 GNUNET_SERVER_suspend (server);
147 if (GNUNET_OK != 155 if (GNUNET_OK !=
148 GNUNET_CONFIGURATION_get_value_time (c, "transport", "HELLO_EXPIRATION", &hello_expiration)) 156 GNUNET_CONFIGURATION_get_value_time (c, "transport", "HELLO_EXPIRATION", &hello_expiration))
149 { 157 {
@@ -155,7 +163,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
155 GDS_NSE_init (); 163 GDS_NSE_init ();
156 GDS_DATACACHE_init (); 164 GDS_DATACACHE_init ();
157 GDS_HELLO_init (); 165 GDS_HELLO_init ();
158 GDS_CLIENTS_init (server);
159 if (GNUNET_OK != GDS_NEIGHBOURS_init ()) 166 if (GNUNET_OK != GDS_NEIGHBOURS_init ())
160 { 167 {
161 shutdown_task (NULL); 168 shutdown_task (NULL);
diff --git a/src/dht/gnunet-service-dht.h b/src/dht/gnunet-service-dht.h
index 86e866666..6f641cb96 100644
--- a/src/dht/gnunet-service-dht.h
+++ b/src/dht/gnunet-service-dht.h
@@ -48,6 +48,11 @@ extern struct GNUNET_BLOCK_Context *GDS_block_context;
48extern struct GNUNET_STATISTICS_Handle *GDS_stats; 48extern struct GNUNET_STATISTICS_Handle *GDS_stats;
49 49
50/** 50/**
51 * Handle to our server.
52 */
53extern struct GNUNET_SERVER_Handle *GDS_server;
54
55/**
51 * Our HELLO 56 * Our HELLO
52 */ 57 */
53extern struct GNUNET_MessageHeader *GDS_my_hello; 58extern struct GNUNET_MessageHeader *GDS_my_hello;
diff --git a/src/dht/gnunet-service-dht_clients.c b/src/dht/gnunet-service-dht_clients.c
index 305826aec..b508df68a 100644
--- a/src/dht/gnunet-service-dht_clients.c
+++ b/src/dht/gnunet-service-dht_clients.c
@@ -974,7 +974,7 @@ process_pending_messages (struct ClientList *client)
974 974
975 975
976/** 976/**
977 * Closure for 'forward_reply' 977 * Closure for #forward_reply()
978 */ 978 */
979struct ForwardReplyContext 979struct ForwardReplyContext
980{ 980{
@@ -1000,7 +1000,7 @@ struct ForwardReplyContext
1000 size_t data_size; 1000 size_t data_size;
1001 1001
1002 /** 1002 /**
1003 * Do we need to copy 'pm' because it was already used? 1003 * Do we need to copy @a pm because it was already used?
1004 */ 1004 */
1005 int do_copy; 1005 int do_copy;
1006 1006
@@ -1015,11 +1015,13 @@ struct ForwardReplyContext
1015 * @param cls the 'struct ForwardReplyContext' 1015 * @param cls the 'struct ForwardReplyContext'
1016 * @param key current key 1016 * @param key current key
1017 * @param value value in the hash map, a ClientQueryRecord 1017 * @param value value in the hash map, a ClientQueryRecord
1018 * @return GNUNET_YES (we should continue to iterate), 1018 * @return #GNUNET_YES (we should continue to iterate),
1019 * if the result is mal-formed, GNUNET_NO 1019 * if the result is mal-formed, #GNUNET_NO
1020 */ 1020 */
1021static int 1021static int
1022forward_reply (void *cls, const struct GNUNET_HashCode * key, void *value) 1022forward_reply (void *cls,
1023 const struct GNUNET_HashCode *key,
1024 void *value)
1023{ 1025{
1024 struct ForwardReplyContext *frc = cls; 1026 struct ForwardReplyContext *frc = cls;
1025 struct ClientQueryRecord *record = value; 1027 struct ClientQueryRecord *record = value;
@@ -1167,12 +1169,11 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
1167 struct GNUNET_PeerIdentity *paths; 1169 struct GNUNET_PeerIdentity *paths;
1168 size_t msize; 1170 size_t msize;
1169 1171
1170 LOG (GNUNET_ERROR_TYPE_DEBUG,
1171 "reply for key %s\n",
1172 GNUNET_h2s (key));
1173
1174 if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, key)) 1172 if (NULL == GNUNET_CONTAINER_multihashmap_get (forward_map, key))
1175 { 1173 {
1174 LOG (GNUNET_ERROR_TYPE_DEBUG,
1175 "No matching client for reply for key %s\n",
1176 GNUNET_h2s (key));
1176 GNUNET_STATISTICS_update (GDS_stats, 1177 GNUNET_STATISTICS_update (GDS_stats,
1177 gettext_noop 1178 gettext_noop
1178 ("# REPLIES ignored for CLIENTS (no match)"), 1, 1179 ("# REPLIES ignored for CLIENTS (no match)"), 1,
@@ -1184,10 +1185,13 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
1184 (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); 1185 (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity);
1185 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1186 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1186 { 1187 {
1187 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1188 GNUNET_break (0);
1188 _("Could not pass reply to client, message too big!\n"));
1189 return; 1189 return;
1190 } 1190 }
1191 LOG (GNUNET_ERROR_TYPE_DEBUG,
1192 "Forwarding reply for key %s to client\n",
1193 GNUNET_h2s (key));
1194
1191 pm = GNUNET_malloc (msize + sizeof (struct PendingMessage)); 1195 pm = GNUNET_malloc (msize + sizeof (struct PendingMessage));
1192 reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; 1196 reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1];
1193 pm->msg = &reply->header; 1197 pm->msg = &reply->header;
@@ -1210,7 +1214,9 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
1210 frc.data = data; 1214 frc.data = data;
1211 frc.data_size = data_size; 1215 frc.data_size = data_size;
1212 frc.type = type; 1216 frc.type = type;
1213 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map, key, &forward_reply, 1217 GNUNET_CONTAINER_multihashmap_get_multiple (forward_map,
1218 key,
1219 &forward_reply,
1214 &frc); 1220 &frc);
1215 1221
1216 if (GNUNET_NO == frc.do_copy) 1222 if (GNUNET_NO == frc.do_copy)
@@ -1309,7 +1315,7 @@ GDS_CLIENTS_process_get (uint32_t options,
1309 * @param exp Expiration time of the data. 1315 * @param exp Expiration time of the data.
1310 * @param key Key of the data. 1316 * @param key Key of the data.
1311 * @param data Pointer to the result data. 1317 * @param data Pointer to the result data.
1312 * @param size Number of bytes in data. 1318 * @param size Number of bytes in @a data.
1313 */ 1319 */
1314void 1320void
1315GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type, 1321GDS_CLIENTS_process_get_resp (enum GNUNET_BLOCK_Type type,
@@ -1452,7 +1458,8 @@ GDS_CLIENTS_process_put (uint32_t options,
1452 msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1]; 1458 msg_path = (struct GNUNET_PeerIdentity *) &mmsg[1];
1453 if (path_length > 0) 1459 if (path_length > 0)
1454 { 1460 {
1455 memcpy (msg_path, path, 1461 memcpy (msg_path,
1462 path,
1456 path_length * sizeof (struct GNUNET_PeerIdentity)); 1463 path_length * sizeof (struct GNUNET_PeerIdentity));
1457 } 1464 }
1458 mmsg->expiration_time = GNUNET_TIME_absolute_hton(exp); 1465 mmsg->expiration_time = GNUNET_TIME_absolute_hton(exp);
@@ -1472,7 +1479,7 @@ GDS_CLIENTS_process_put (uint32_t options,
1472 * @param server the initialized server 1479 * @param server the initialized server
1473 */ 1480 */
1474void 1481void
1475GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server) 1482GDS_CLIENTS_init ()
1476{ 1483{
1477 static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = { 1484 static struct GNUNET_SERVER_MessageHandler plugin_handlers[] = {
1478 {&handle_dht_local_put, NULL, 1485 {&handle_dht_local_put, NULL,
@@ -1492,10 +1499,15 @@ GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server)
1492 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, 0}, 1499 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, 0},
1493 {NULL, NULL, 0, 0} 1500 {NULL, NULL, 0, 0}
1494 }; 1501 };
1502
1495 forward_map = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); 1503 forward_map = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO);
1496 retry_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 1504 retry_heap = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
1497 GNUNET_SERVER_add_handlers (server, plugin_handlers); 1505 GNUNET_SERVER_resume (GDS_server);
1498 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 1506 GNUNET_SERVER_add_handlers (GDS_server,
1507 plugin_handlers);
1508 GNUNET_SERVER_disconnect_notify (GDS_server,
1509 &handle_client_disconnect,
1510 NULL);
1499} 1511}
1500 1512
1501 1513
diff --git a/src/dht/gnunet-service-dht_clients.h b/src/dht/gnunet-service-dht_clients.h
index 2e1b1b89a..d8e1c184d 100644
--- a/src/dht/gnunet-service-dht_clients.h
+++ b/src/dht/gnunet-service-dht_clients.h
@@ -133,11 +133,9 @@ GDS_CLIENTS_process_put (uint32_t options,
133 133
134/** 134/**
135 * Initialize client subsystem. 135 * Initialize client subsystem.
136 *
137 * @param server the initialized server
138 */ 136 */
139void 137void
140GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server); 138GDS_CLIENTS_init (void);
141 139
142 140
143/** 141/**
diff --git a/src/dht/gnunet-service-dht_neighbours.c b/src/dht/gnunet-service-dht_neighbours.c
index 773ad8983..7b1efff1f 100644
--- a/src/dht/gnunet-service-dht_neighbours.c
+++ b/src/dht/gnunet-service-dht_neighbours.c
@@ -870,6 +870,11 @@ handle_core_disconnect (void *cls,
870 GNUNET_CONTAINER_multipeermap_remove (all_connected_peers, 870 GNUNET_CONTAINER_multipeermap_remove (all_connected_peers,
871 peer, 871 peer,
872 to_remove)); 872 to_remove));
873 if (0 == GNUNET_CONTAINER_multipeermap_size (all_connected_peers))
874 {
875 GNUNET_SCHEDULER_cancel (find_peer_task);
876 find_peer_task = NULL;
877 }
873 GNUNET_CRYPTO_hash (peer, 878 GNUNET_CRYPTO_hash (peer,
874 sizeof (struct GNUNET_PeerIdentity), 879 sizeof (struct GNUNET_PeerIdentity),
875 &phash); 880 &phash);
@@ -894,6 +899,9 @@ handle_core_disconnect (void *cls,
894 GNUNET_CONTAINER_DLL_remove (to_remove->head, 899 GNUNET_CONTAINER_DLL_remove (to_remove->head,
895 to_remove->tail, 900 to_remove->tail,
896 pos); 901 pos);
902 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
903 "Dropping message of type %u due to disconnect\n",
904 ntohs (pos->msg->type));
897 discarded++; 905 discarded++;
898 GNUNET_free (pos); 906 GNUNET_free (pos);
899 } 907 }
@@ -927,6 +935,9 @@ core_transmit_notify (void *cls,
927 size_t off; 935 size_t off;
928 size_t msize; 936 size_t msize;
929 937
938 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
939 "DHT ctn called with buffer of %u bytes\n",
940 (unsigned int) size);
930 peer->th = NULL; 941 peer->th = NULL;
931 while ((NULL != (pending = peer->head)) && 942 while ((NULL != (pending = peer->head)) &&
932 (0 == GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value_us)) 943 (0 == GNUNET_TIME_absolute_get_remaining (pending->timeout).rel_value_us))
@@ -936,24 +947,35 @@ core_transmit_notify (void *cls,
936 ("# Messages dropped (CORE timeout)"), 947 ("# Messages dropped (CORE timeout)"),
937 1, 948 1,
938 GNUNET_NO); 949 GNUNET_NO);
950 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
951 "Dropping message of type %u due to timeout\n",
952 ntohs (pending->msg->type));
939 peer->pending_count--; 953 peer->pending_count--;
940 GNUNET_CONTAINER_DLL_remove (peer->head, peer->tail, pending); 954 GNUNET_CONTAINER_DLL_remove (peer->head,
955 peer->tail,
956 pending);
941 GNUNET_free (pending); 957 GNUNET_free (pending);
942 } 958 }
943 if (NULL == pending) 959 if (NULL == pending)
944 { 960 {
945 /* no messages pending */ 961 /* no messages pending */
962 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
963 "No messages pending\n");
946 return 0; 964 return 0;
947 } 965 }
948 if (NULL == buf) 966 if (NULL == buf)
949 { 967 {
968 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
969 "Got NULL buffer, trying again\n");
950 peer->th = 970 peer->th =
951 GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO, 971 GNUNET_CORE_notify_transmit_ready (core_api, GNUNET_NO,
952 GNUNET_CORE_PRIO_BEST_EFFORT, 972 GNUNET_CORE_PRIO_BEST_EFFORT,
953 GNUNET_TIME_absolute_get_remaining 973 GNUNET_TIME_absolute_get_remaining
954 (pending->timeout), &peer->id, 974 (pending->timeout),
975 &peer->id,
955 ntohs (pending->msg->size), 976 ntohs (pending->msg->size),
956 &core_transmit_notify, peer); 977 &core_transmit_notify,
978 peer);
957 GNUNET_break (NULL != peer->th); 979 GNUNET_break (NULL != peer->th);
958 return 0; 980 return 0;
959 } 981 }
@@ -965,7 +987,13 @@ core_transmit_notify (void *cls,
965 gettext_noop 987 gettext_noop
966 ("# Bytes transmitted to other peers"), msize, 988 ("# Bytes transmitted to other peers"), msize,
967 GNUNET_NO); 989 GNUNET_NO);
968 memcpy (&cbuf[off], pending->msg, msize); 990 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
991 "Transmitting message of type %u to %s\n",
992 ntohs (pending->msg->type),
993 GNUNET_i2s (&peer->id));
994 memcpy (&cbuf[off],
995 pending->msg,
996 msize);
969 off += msize; 997 off += msize;
970 peer->pending_count--; 998 peer->pending_count--;
971 GNUNET_CONTAINER_DLL_remove (peer->head, 999 GNUNET_CONTAINER_DLL_remove (peer->head,
@@ -973,6 +1001,11 @@ core_transmit_notify (void *cls,
973 pending); 1001 pending);
974 GNUNET_free (pending); 1002 GNUNET_free (pending);
975 } 1003 }
1004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1005 "%u bytes fit in %u bytes available, next message is %u bytes\n",
1006 (unsigned int) off,
1007 (unsigned int) size,
1008 (NULL != peer->head) ? ntohs (peer->head->msg->size) : 0);
976 if (NULL != (pending = peer->head)) 1009 if (NULL != (pending = peer->head))
977 { 1010 {
978 /* technically redundant, but easier to read and 1011 /* technically redundant, but easier to read and
@@ -1006,7 +1039,10 @@ process_peer_queue (struct PeerInfo *peer)
1006 if (NULL == (pending = peer->head)) 1039 if (NULL == (pending = peer->head))
1007 return; 1040 return;
1008 if (NULL != peer->th) 1041 if (NULL != peer->th)
1009 return; 1042 {
1043 GNUNET_CORE_notify_transmit_ready_cancel (peer->th);
1044 peer->th = NULL;
1045 }
1010 GNUNET_STATISTICS_update (GDS_stats, 1046 GNUNET_STATISTICS_update (GDS_stats,
1011 gettext_noop 1047 gettext_noop
1012 ("# Bytes of bandwidth requested from core"), 1048 ("# Bytes of bandwidth requested from core"),
@@ -1445,7 +1481,8 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1445 GNUNET_assert (NULL != bf); 1481 GNUNET_assert (NULL != bf);
1446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1447 "Adding myself (%s) to PUT bloomfilter for %s\n", 1483 "Adding myself (%s) to PUT bloomfilter for %s\n",
1448 GNUNET_i2s (&my_identity), GNUNET_h2s (key)); 1484 GNUNET_i2s (&my_identity),
1485 GNUNET_h2s (key));
1449 GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity_hash); 1486 GNUNET_CONTAINER_bloomfilter_add (bf, &my_identity_hash);
1450 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# PUT requests routed"), 1487 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# PUT requests routed"),
1451 1, GNUNET_NO); 1488 1, GNUNET_NO);
@@ -1492,8 +1529,10 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1492 continue; 1529 continue;
1493 } 1530 }
1494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1495 "Routing PUT for %s after %u hops to %s\n", GNUNET_h2s (key), 1532 "Routing PUT for %s after %u hops to %s\n",
1496 (unsigned int) hop_count, GNUNET_i2s (&target->id)); 1533 GNUNET_h2s (key),
1534 (unsigned int) hop_count,
1535 GNUNET_i2s (&target->id));
1497 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1536 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1498 pending->importance = 0; /* FIXME */ 1537 pending->importance = 0; /* FIXME */
1499 pending->timeout = expiration_time; 1538 pending->timeout = expiration_time;
@@ -1521,10 +1560,15 @@ GDS_NEIGHBOURS_handle_put (enum GNUNET_BLOCK_Type type,
1521 pp = (struct GNUNET_PeerIdentity *) &ppm[1]; 1560 pp = (struct GNUNET_PeerIdentity *) &ppm[1];
1522 memcpy (pp, put_path, 1561 memcpy (pp, put_path,
1523 sizeof (struct GNUNET_PeerIdentity) * put_path_length); 1562 sizeof (struct GNUNET_PeerIdentity) * put_path_length);
1524 memcpy (&pp[put_path_length], data, data_size); 1563 memcpy (&pp[put_path_length],
1525 GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending); 1564 data,
1565 data_size);
1566 GNUNET_CONTAINER_DLL_insert_tail (target->head,
1567 target->tail,
1568 pending);
1526 target->pending_count++; 1569 target->pending_count++;
1527 process_peer_queue (target); 1570 if (pending == target->head)
1571 process_peer_queue (target);
1528 } 1572 }
1529 GNUNET_free (targets); 1573 GNUNET_free (targets);
1530 return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; 1574 return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
@@ -1579,8 +1623,10 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1579 &targets); 1623 &targets);
1580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1624 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1581 "Adding myself (%s) to GET bloomfilter for %s\n", 1625 "Adding myself (%s) to GET bloomfilter for %s\n",
1582 GNUNET_i2s (&my_identity), GNUNET_h2s (key)); 1626 GNUNET_i2s (&my_identity),
1583 GNUNET_CONTAINER_bloomfilter_add (peer_bf, &my_identity_hash); 1627 GNUNET_h2s (key));
1628 GNUNET_CONTAINER_bloomfilter_add (peer_bf,
1629 &my_identity_hash);
1584 if (0 == target_count) 1630 if (0 == target_count)
1585 { 1631 {
1586 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1616,8 +1662,10 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1616 continue; 1662 continue;
1617 } 1663 }
1618 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1619 "Routing GET for %s after %u hops to %s\n", GNUNET_h2s (key), 1665 "Routing GET for %s after %u hops to %s\n",
1620 (unsigned int) hop_count, GNUNET_i2s (&target->id)); 1666 GNUNET_h2s (key),
1667 (unsigned int) hop_count,
1668 GNUNET_i2s (&target->id));
1621 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 1669 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
1622 pending->importance = 0; /* FIXME */ 1670 pending->importance = 0; /* FIXME */
1623 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT); 1671 pending->timeout = GNUNET_TIME_relative_to_absolute (GET_TIMEOUT);
@@ -1650,9 +1698,12 @@ GDS_NEIGHBOURS_handle_get (enum GNUNET_BLOCK_Type type,
1650 &xq 1698 &xq
1651 [xquery_size], 1699 [xquery_size],
1652 reply_bf_size)); 1700 reply_bf_size));
1653 GNUNET_CONTAINER_DLL_insert_tail (target->head, target->tail, pending); 1701 GNUNET_CONTAINER_DLL_insert_tail (target->head,
1702 target->tail,
1703 pending);
1654 target->pending_count++; 1704 target->pending_count++;
1655 process_peer_queue (target); 1705 if (pending == target->head)
1706 process_peer_queue (target);
1656 } 1707 }
1657 GNUNET_free (targets); 1708 GNUNET_free (targets);
1658 return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO; 1709 return (skip_count < target_count) ? GNUNET_OK : GNUNET_NO;
@@ -1712,16 +1763,28 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
1712 if (NULL == pi) 1763 if (NULL == pi)
1713 { 1764 {
1714 /* peer disconnected in the meantime, drop reply */ 1765 /* peer disconnected in the meantime, drop reply */
1766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1767 "No matching peer for reply for key %s\n",
1768 GNUNET_h2s (key));
1715 return; 1769 return;
1716 } 1770 }
1717 if (pi->pending_count >= MAXIMUM_PENDING_PER_PEER) 1771 if (pi->pending_count >= MAXIMUM_PENDING_PER_PEER)
1718 { 1772 {
1719 /* skip */ 1773 /* skip */
1720 GNUNET_STATISTICS_update (GDS_stats, gettext_noop ("# P2P messages dropped due to full queue"), 1774 GNUNET_STATISTICS_update (GDS_stats,
1721 1, GNUNET_NO); 1775 gettext_noop ("# P2P messages dropped due to full queue"),
1776 1,
1777 GNUNET_NO);
1778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1779 "Peer queue full, ignoring reply for key %s\n",
1780 GNUNET_h2s (key));
1722 return; 1781 return;
1723 } 1782 }
1724 1783
1784 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1785 "Forwarding reply for key %s to peer %s\n",
1786 GNUNET_h2s (key),
1787 GNUNET_i2s (target));
1725 GNUNET_STATISTICS_update (GDS_stats, 1788 GNUNET_STATISTICS_update (GDS_stats,
1726 gettext_noop 1789 gettext_noop
1727 ("# RESULT messages queued for transmission"), 1, 1790 ("# RESULT messages queued for transmission"), 1,
@@ -1739,12 +1802,18 @@ GDS_NEIGHBOURS_handle_reply (const struct GNUNET_PeerIdentity *target,
1739 prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time); 1802 prm->expiration_time = GNUNET_TIME_absolute_hton (expiration_time);
1740 prm->key = *key; 1803 prm->key = *key;
1741 paths = (struct GNUNET_PeerIdentity *) &prm[1]; 1804 paths = (struct GNUNET_PeerIdentity *) &prm[1];
1742 memcpy (paths, put_path, 1805 memcpy (paths,
1806 put_path,
1743 put_path_length * sizeof (struct GNUNET_PeerIdentity)); 1807 put_path_length * sizeof (struct GNUNET_PeerIdentity));
1744 memcpy (&paths[put_path_length], get_path, 1808 memcpy (&paths[put_path_length],
1809 get_path,
1745 get_path_length * sizeof (struct GNUNET_PeerIdentity)); 1810 get_path_length * sizeof (struct GNUNET_PeerIdentity));
1746 memcpy (&paths[put_path_length + get_path_length], data, data_size); 1811 memcpy (&paths[put_path_length + get_path_length],
1747 GNUNET_CONTAINER_DLL_insert (pi->head, pi->tail, pending); 1812 data,
1813 data_size);
1814 GNUNET_CONTAINER_DLL_insert (pi->head,
1815 pi->tail,
1816 pending);
1748 pi->pending_count++; 1817 pi->pending_count++;
1749 process_peer_queue (pi); 1818 process_peer_queue (pi);
1750} 1819}
@@ -1760,10 +1829,14 @@ static void
1760core_init (void *cls, 1829core_init (void *cls,
1761 const struct GNUNET_PeerIdentity *identity) 1830 const struct GNUNET_PeerIdentity *identity)
1762{ 1831{
1832 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1833 "CORE called, I am %s\n",
1834 GNUNET_i2s (identity));
1763 my_identity = *identity; 1835 my_identity = *identity;
1764 GNUNET_CRYPTO_hash (identity, 1836 GNUNET_CRYPTO_hash (identity,
1765 sizeof (struct GNUNET_PeerIdentity), 1837 sizeof (struct GNUNET_PeerIdentity),
1766 &my_identity_hash); 1838 &my_identity_hash);
1839 GDS_CLIENTS_init ();
1767} 1840}
1768 1841
1769 1842
@@ -1778,7 +1851,8 @@ core_init (void *cls,
1778 * #GNUNET_SYSERR to close it (signal serious error) 1851 * #GNUNET_SYSERR to close it (signal serious error)
1779 */ 1852 */
1780static int 1853static int
1781handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer, 1854handle_dht_p2p_put (void *cls,
1855 const struct GNUNET_PeerIdentity *peer,
1782 const struct GNUNET_MessageHeader *message) 1856 const struct GNUNET_MessageHeader *message)
1783{ 1857{
1784 const struct PeerPutMessage *put; 1858 const struct PeerPutMessage *put;
@@ -1811,10 +1885,12 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
1811 return GNUNET_YES; 1885 return GNUNET_YES;
1812 } 1886 }
1813 GNUNET_STATISTICS_update (GDS_stats, 1887 GNUNET_STATISTICS_update (GDS_stats,
1814 gettext_noop ("# P2P PUT requests received"), 1, 1888 gettext_noop ("# P2P PUT requests received"),
1889 1,
1815 GNUNET_NO); 1890 GNUNET_NO);
1816 GNUNET_STATISTICS_update (GDS_stats, 1891 GNUNET_STATISTICS_update (GDS_stats,
1817 gettext_noop ("# P2P PUT bytes received"), msize, 1892 gettext_noop ("# P2P PUT bytes received"),
1893 msize,
1818 GNUNET_NO); 1894 GNUNET_NO);
1819 put_path = (const struct GNUNET_PeerIdentity *) &put[1]; 1895 put_path = (const struct GNUNET_PeerIdentity *) &put[1];
1820 payload = &put_path[putlen]; 1896 payload = &put_path[putlen];
@@ -1833,10 +1909,14 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
1833 tmp = GNUNET_strdup (GNUNET_i2s (&my_identity)); 1909 tmp = GNUNET_strdup (GNUNET_i2s (&my_identity));
1834 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, 1910 LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG,
1835 "R5N PUT %s: %s->%s (%u, %u=>%u)\n", 1911 "R5N PUT %s: %s->%s (%u, %u=>%u)\n",
1836 GNUNET_h2s (&put->key), GNUNET_i2s (peer), tmp, 1912 GNUNET_h2s (&put->key),
1913 GNUNET_i2s (peer),
1914 tmp,
1837 ntohl(put->hop_count), 1915 ntohl(put->hop_count),
1838 GNUNET_CRYPTO_hash_matching_bits (&phash, &put->key), 1916 GNUNET_CRYPTO_hash_matching_bits (&phash,
1839 GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash, &put->key) 1917 &put->key),
1918 GNUNET_CRYPTO_hash_matching_bits (&my_identity_hash,
1919 &put->key)
1840 ); 1920 );
1841 GNUNET_free (tmp); 1921 GNUNET_free (tmp);
1842 } 1922 }
@@ -1848,6 +1928,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
1848 if (0 != memcmp (&test_key, &put->key, sizeof (struct GNUNET_HashCode))) 1928 if (0 != memcmp (&test_key, &put->key, sizeof (struct GNUNET_HashCode)))
1849 { 1929 {
1850 char *put_s = GNUNET_strdup (GNUNET_h2s_full (&put->key)); 1930 char *put_s = GNUNET_strdup (GNUNET_h2s_full (&put->key));
1931
1851 GNUNET_break_op (0); 1932 GNUNET_break_op (0);
1852 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1933 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1853 "PUT with key `%s' for block with key %s\n", 1934 "PUT with key `%s' for block with key %s\n",
@@ -1889,7 +1970,8 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
1889 } 1970 }
1890 } 1971 }
1891 1972
1892 bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter, DHT_BLOOM_SIZE, 1973 bf = GNUNET_CONTAINER_bloomfilter_init (put->bloomfilter,
1974 DHT_BLOOM_SIZE,
1893 GNUNET_CONSTANTS_BLOOMFILTER_K); 1975 GNUNET_CONSTANTS_BLOOMFILTER_K);
1894 GNUNET_break_op (GNUNET_YES == 1976 GNUNET_break_op (GNUNET_YES ==
1895 GNUNET_CONTAINER_bloomfilter_test (bf, &phash)); 1977 GNUNET_CONTAINER_bloomfilter_test (bf, &phash));
@@ -2025,8 +2107,12 @@ handle_find_peer (const struct GNUNET_PeerIdentity *sender,
2025 return; /* no non-masked peer available */ 2107 return; /* no non-masked peer available */
2026 if (peer == NULL) 2108 if (peer == NULL)
2027 peer = bucket->head; 2109 peer = bucket->head;
2028 GNUNET_CRYPTO_hash (&peer->id, sizeof (struct GNUNET_PeerIdentity), &phash); 2110 GNUNET_CRYPTO_hash (&peer->id,
2029 GNUNET_BLOCK_mingle_hash (&phash, bf_mutator, &mhash); 2111 sizeof (struct GNUNET_PeerIdentity),
2112 &phash);
2113 GNUNET_BLOCK_mingle_hash (&phash,
2114 bf_mutator,
2115 &mhash);
2030 hello = GDS_HELLO_get (&peer->id); 2116 hello = GDS_HELLO_get (&peer->id);
2031 } 2117 }
2032 while ((hello == NULL) || 2118 while ((hello == NULL) ||
@@ -2067,7 +2153,8 @@ handle_dht_p2p_get (void *cls,
2067 int forwarded; 2153 int forwarded;
2068 2154
2069 GNUNET_break (0 != 2155 GNUNET_break (0 !=
2070 memcmp (peer, &my_identity, 2156 memcmp (peer,
2157 &my_identity,
2071 sizeof (struct GNUNET_PeerIdentity))); 2158 sizeof (struct GNUNET_PeerIdentity)));
2072 /* parse and validate message */ 2159 /* parse and validate message */
2073 msize = ntohs (message->size); 2160 msize = ntohs (message->size);
diff --git a/src/dht/test_dht_2dtorus.conf b/src/dht/test_dht_2dtorus.conf
index 2a7f75b9f..844f20431 100644
--- a/src/dht/test_dht_2dtorus.conf
+++ b/src/dht/test_dht_2dtorus.conf
@@ -1,6 +1,11 @@
1@INLINE@ ../../contrib/no_forcestart.conf
2@INLINE@ ../../contrib/no_autostart_above_core.conf
1[PATHS] 3[PATHS]
2GNUNET_TEST_HOME = /tmp/test_dht_2dtorus/ 4GNUNET_TEST_HOME = /tmp/test_dht_2dtorus/
3 5
6[dht]
7AUTOSTART = YES
8
4[dhtcache] 9[dhtcache]
5QUOTA = 1 MB 10QUOTA = 1 MB
6DATABASE = heap 11DATABASE = heap
@@ -22,7 +27,10 @@ WAN_QUOTA_OUT = 1 GB
22OVERLAY_TOPOLOGY = 2D_TORUS 27OVERLAY_TOPOLOGY = 2D_TORUS
23 28
24[nse] 29[nse]
30AUTOSTART = YES
25WORKDELAY = 500 ms 31WORKDELAY = 500 ms
26INTERVAL = 60 s 32INTERVAL = 60 s
27WORKBITS = 0 33WORKBITS = 0
28 34
35[transport]
36PLUGINS = unix
diff --git a/src/dht/test_dht_line.conf b/src/dht/test_dht_line.conf
index 024ff2770..45badfae0 100644
--- a/src/dht/test_dht_line.conf
+++ b/src/dht/test_dht_line.conf
@@ -1,5 +1,11 @@
1@INLINE@ ../../contrib/no_forcestart.conf
2@INLINE@ ../../contrib/no_autostart_above_core.conf
1[PATHS] 3[PATHS]
2GNUNET_TEST_HOME = /tmp/test_dht_line/ 4GNUNET_TEST_HOME = /tmp/test_dht_line/
5
6[dht]
7AUTOSTART = YES
8
3[dhtcache] 9[dhtcache]
4QUOTA = 1 MB 10QUOTA = 1 MB
5DATABASE = heap 11DATABASE = heap
@@ -22,10 +28,10 @@ WAN_QUOTA_OUT = 1 GB
22OVERLAY_TOPOLOGY = LINE 28OVERLAY_TOPOLOGY = LINE
23 29
24[transport] 30[transport]
25plugins = tcp 31plugins = unix
26 32
27[nse] 33[nse]
34AUTOSTART = YES
28WORKDELAY = 500 ms 35WORKDELAY = 500 ms
29INTERVAL = 60 s 36INTERVAL = 60 s
30WORKBITS = 0 37WORKBITS = 0
31
diff --git a/src/dht/test_dht_multipeer.conf b/src/dht/test_dht_multipeer.conf
index b6e1646d3..f113aa0f8 100644
--- a/src/dht/test_dht_multipeer.conf
+++ b/src/dht/test_dht_multipeer.conf
@@ -1,9 +1,15 @@
1@INLINE@ ../../contrib/no_forcestart.conf
2@INLINE@ ../../contrib/no_autostart_above_core.conf
3
4[dht]
5AUTOSTART = YES
6
1[dhtcache] 7[dhtcache]
2QUOTA = 1 MB 8QUOTA = 1 MB
3DATABASE = heap 9DATABASE = heap
4 10
5[transport] 11[transport]
6PLUGINS = tcp 12PLUGINS = unix
7 13
8[ats] 14[ats]
9WAN_QUOTA_IN = 1 GB 15WAN_QUOTA_IN = 1 GB
@@ -26,3 +32,8 @@ INTERNAL_ADDRESS = 127.0.0.1
26EXTERNAL_ADDRESS = 127.0.0.1 32EXTERNAL_ADDRESS = 127.0.0.1
27USE_LOCALADDR = YES 33USE_LOCALADDR = YES
28 34
35[nse]
36AUTOSTART = YES
37WORKDELAY = 500 ms
38INTERVAL = 60 s
39WORKBITS = 0
diff --git a/src/dht/test_dht_topo.c b/src/dht/test_dht_topo.c
index 205f6b99a..8be3064f7 100644
--- a/src/dht/test_dht_topo.c
+++ b/src/dht/test_dht_topo.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V. 3 Copyright (C) 2012, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -71,12 +71,17 @@ static int ok = 1;
71/** 71/**
72 * Task to do DHT_puts 72 * Task to do DHT_puts
73 */ 73 */
74static struct GNUNET_SCHEDULER_Task * put_task; 74static struct GNUNET_SCHEDULER_Task *put_task;
75
76/**
77 * Task to do DHT_gets
78 */
79static struct GNUNET_SCHEDULER_Task *get_task;
75 80
76/** 81/**
77 * Task to time out / regular shutdown. 82 * Task to time out / regular shutdown.
78 */ 83 */
79static struct GNUNET_SCHEDULER_Task * timeout_task; 84static struct GNUNET_SCHEDULER_Task *timeout_task;
80 85
81/** 86/**
82 * Head of list of active GET operations. 87 * Head of list of active GET operations.
@@ -147,6 +152,39 @@ static struct
147}; 152};
148 153
149 154
155static struct GNUNET_DHT_TEST_Context *
156stop_ops ()
157{
158 struct GetOperation *get_op;
159 struct GNUNET_DHT_TEST_Context *ctx = NULL;
160
161 if (NULL != timeout_task)
162 {
163 ctx = GNUNET_SCHEDULER_cancel (timeout_task);
164 timeout_task = NULL;
165 }
166 if (NULL != put_task)
167 {
168 GNUNET_SCHEDULER_cancel (put_task);
169 put_task = NULL;
170 }
171 if (NULL != get_task)
172 {
173 GNUNET_SCHEDULER_cancel (get_task);
174 get_task = NULL;
175 }
176 while (NULL != (get_op = get_tail))
177 {
178 GNUNET_DHT_get_stop (get_op->get);
179 GNUNET_CONTAINER_DLL_remove (get_head,
180 get_tail,
181 get_op);
182 GNUNET_free (get_op);
183 }
184 return ctx;
185}
186
187
150/** 188/**
151 * Function called once we're done processing stats. 189 * Function called once we're done processing stats.
152 * 190 *
@@ -163,10 +201,11 @@ stats_finished (void *cls,
163 unsigned int i; 201 unsigned int i;
164 202
165 if (NULL != op) 203 if (NULL != op)
166 GNUNET_TESTBED_operation_done (op); // needed? 204 GNUNET_TESTBED_operation_done (op);
167 if (NULL != emsg) 205 if (NULL != emsg)
168 { 206 {
169 fprintf (stderr, _("Gathering statistics failed: %s\n"), 207 fprintf (stderr,
208 _("Gathering statistics failed: %s\n"),
170 emsg); 209 emsg);
171 GNUNET_SCHEDULER_cancel (put_task); 210 GNUNET_SCHEDULER_cancel (put_task);
172 GNUNET_DHT_TEST_cleanup (ctx); 211 GNUNET_DHT_TEST_cleanup (ctx);
@@ -178,8 +217,8 @@ stats_finished (void *cls,
178 stats[i].subsystem, 217 stats[i].subsystem,
179 stats[i].name, 218 stats[i].name,
180 stats[i].total); 219 stats[i].total);
181 GNUNET_SCHEDULER_cancel (put_task);
182 GNUNET_DHT_TEST_cleanup (ctx); 220 GNUNET_DHT_TEST_cleanup (ctx);
221 GNUNET_SCHEDULER_shutdown ();
183} 222}
184 223
185 224
@@ -191,8 +230,8 @@ stats_finished (void *cls,
191 * @param subsystem name of subsystem that created the statistic 230 * @param subsystem name of subsystem that created the statistic
192 * @param name the name of the datum 231 * @param name the name of the datum
193 * @param value the current value 232 * @param value the current value
194 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not 233 * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not
195 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration 234 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
196 */ 235 */
197static int 236static int
198handle_stats (void *cls, 237handle_stats (void *cls,
@@ -215,32 +254,31 @@ handle_stats (void *cls,
215 254
216 255
217/** 256/**
218 * Task run on success or timeout to clean up. 257 * Task run on shutdown to clean up. Terminates active get operations
219 * Terminates active get operations and shuts down 258 * and shuts down the testbed.
220 * the testbed.
221 * 259 *
222 * @param cls the 'struct GNUNET_DHT_TestContext' 260 * @param cls the 'struct GNUNET_DHT_TestContext'
223 */ 261 */
224static void 262static void
225shutdown_task (void *cls) 263shutdown_task (void *cls)
226{ 264{
227 struct GNUNET_DHT_TEST_Context *ctx = cls; 265 (void) stop_ops ();
228 struct GetOperation *get_op; 266}
229 267
230 while (NULL != (get_op = get_tail)) 268
231 { 269/**
232 GNUNET_DHT_get_stop (get_op->get); 270 * Task run on timeout to clean up. Terminates active get operations
233 GNUNET_CONTAINER_DLL_remove (get_head, 271 * and shuts down the testbed.
234 get_tail, 272 *
235 get_op); 273 * @param cls the `struct GNUNET_DHT_TestContext`
236 GNUNET_free (get_op); 274 */
237 } 275static void
238 (void) GNUNET_TESTBED_get_statistics (NUM_PEERS, 276timeout_cb (void *cls)
239 my_peers, 277{
240 NULL, NULL, 278 timeout_task = NULL;
241 &handle_stats, 279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
242 &stats_finished, 280 "Timeout\n");
243 ctx); 281 GNUNET_SCHEDULER_shutdown ();
244} 282}
245 283
246 284
@@ -252,33 +290,40 @@ shutdown_task (void *cls)
252 * @param exp when will this value expire 290 * @param exp when will this value expire
253 * @param key key of the result 291 * @param key key of the result
254 * @param get_path peers on reply path (or NULL if not recorded) 292 * @param get_path peers on reply path (or NULL if not recorded)
255 * @param get_path_length number of entries in get_path 293 * @param get_path_length number of entries in @a get_path
256 * @param put_path peers on the PUT path (or NULL if not recorded) 294 * @param put_path peers on the PUT path (or NULL if not recorded)
257 * @param put_path_length number of entries in get_path 295 * @param put_path_length number of entries in @a put_path
258 * @param type type of the result 296 * @param type type of the result
259 * @param size number of bytes in data 297 * @param size number of bytes in @a data
260 * @param data pointer to the result data 298 * @param data pointer to the result data
261 */ 299 */
262static void 300static void
263dht_get_handler (void *cls, struct GNUNET_TIME_Absolute exp, 301dht_get_handler (void *cls,
264 const struct GNUNET_HashCode * key, 302 struct GNUNET_TIME_Absolute exp,
303 const struct GNUNET_HashCode *key,
265 const struct GNUNET_PeerIdentity *get_path, 304 const struct GNUNET_PeerIdentity *get_path,
266 unsigned int get_path_length, 305 unsigned int get_path_length,
267 const struct GNUNET_PeerIdentity *put_path, 306 const struct GNUNET_PeerIdentity *put_path,
268 unsigned int put_path_length, enum GNUNET_BLOCK_Type type, 307 unsigned int put_path_length,
269 size_t size, const void *data) 308 enum GNUNET_BLOCK_Type type,
309 size_t size,
310 const void *data)
270{ 311{
271 struct GetOperation *get_op = cls; 312 struct GetOperation *get_op = cls;
272 struct GNUNET_HashCode want; 313 struct GNUNET_HashCode want;
273 struct GNUNET_DHT_TestContext *ctx; 314 struct GNUNET_DHT_TEST_Context *ctx;
274 315
275 if (sizeof (struct GNUNET_HashCode) != size) 316 if (sizeof (struct GNUNET_HashCode) != size)
276 { 317 {
277 GNUNET_break (0); 318 GNUNET_break (0);
278 return; 319 return;
279 } 320 }
280 GNUNET_CRYPTO_hash (key, sizeof (*key), &want); 321 GNUNET_CRYPTO_hash (key,
281 if (0 != memcmp (&want, data, sizeof (want))) 322 sizeof (*key),
323 &want);
324 if (0 != memcmp (&want,
325 data,
326 sizeof (want)))
282 { 327 {
283 GNUNET_break (0); 328 GNUNET_break (0);
284 return; 329 return;
@@ -289,14 +334,19 @@ dht_get_handler (void *cls, struct GNUNET_TIME_Absolute exp,
289 { 334 {
290 int i; 335 int i;
291 336
292 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "PATH: (get %u, put %u)\n", 337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
293 get_path_length, put_path_length); 338 "PATH: (get %u, put %u)\n",
294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " LOCAL\n"); 339 get_path_length,
340 put_path_length);
341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
342 " LOCAL\n");
295 for (i = get_path_length - 1; i >= 0; i--) 343 for (i = get_path_length - 1; i >= 0; i--)
296 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %s\n", 344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
345 " %s\n",
297 GNUNET_i2s (&get_path[i])); 346 GNUNET_i2s (&get_path[i]));
298 for (i = put_path_length - 1; i >= 0; i--) 347 for (i = put_path_length - 1; i >= 0; i--)
299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " %s\n", 348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
349 " %s\n",
300 GNUNET_i2s (&put_path[i])); 350 GNUNET_i2s (&put_path[i]));
301 } 351 }
302#endif 352#endif
@@ -307,10 +357,18 @@ dht_get_handler (void *cls, struct GNUNET_TIME_Absolute exp,
307 GNUNET_free (get_op); 357 GNUNET_free (get_op);
308 if (NULL != get_head) 358 if (NULL != get_head)
309 return; 359 return;
310 /* all DHT GET operations successful; terminate! */ 360 /* all DHT GET operations successful; get stats! */
361 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
362 "All DHT operations successful. Obtaining stats!\n");
311 ok = 0; 363 ok = 0;
312 ctx = GNUNET_SCHEDULER_cancel (timeout_task); 364 ctx = stop_ops ();
313 timeout_task = GNUNET_SCHEDULER_add_now (&shutdown_task, ctx); 365 GNUNET_assert (NULL != ctx);
366 (void) GNUNET_TESTBED_get_statistics (NUM_PEERS,
367 my_peers,
368 NULL, NULL,
369 &handle_stats,
370 &stats_finished,
371 ctx);
314} 372}
315 373
316 374
@@ -328,55 +386,52 @@ do_puts (void *cls)
328 struct GNUNET_HashCode value; 386 struct GNUNET_HashCode value;
329 unsigned int i; 387 unsigned int i;
330 388
389 put_task = NULL;
331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
332 "Putting values into DHT\n"); 391 "Putting values into DHT\n");
333 for (i = 0; i < NUM_PEERS; i++) 392 for (i = 0; i < NUM_PEERS; i++)
334 { 393 {
335 GNUNET_CRYPTO_hash (&i, sizeof (i), &key); 394 GNUNET_CRYPTO_hash (&i,
336 GNUNET_CRYPTO_hash (&key, sizeof (key), &value); 395 sizeof (i),
337 GNUNET_DHT_put (hs[i], &key, 10U, 396 &key);
397 GNUNET_CRYPTO_hash (&key,
398 sizeof (key),
399 &value);
400 GNUNET_DHT_put (hs[i],
401 &key,
402 10U,
338 GNUNET_DHT_RO_RECORD_ROUTE | 403 GNUNET_DHT_RO_RECORD_ROUTE |
339 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 404 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
340 GNUNET_BLOCK_TYPE_TEST, 405 GNUNET_BLOCK_TYPE_TEST,
341 sizeof (value), &value, 406 sizeof (value),
407 &value,
342 GNUNET_TIME_UNIT_FOREVER_ABS, 408 GNUNET_TIME_UNIT_FOREVER_ABS,
343 NULL, NULL); 409 NULL,
410 NULL);
344 } 411 }
345 put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY, 412 put_task = GNUNET_SCHEDULER_add_delayed (PUT_FREQUENCY,
346 &do_puts, hs); 413 &do_puts,
414 hs);
347} 415}
348 416
349 417
350/** 418/**
351 * Main function of the test. 419 * Start GET operations.
352 *
353 * @param cls closure (NULL)
354 * @param ctx argument to give to GNUNET_DHT_TEST_cleanup on test end
355 * @param num_peers number of peers that are running
356 * @param peers array of peers
357 * @param dhts handle to each of the DHTs of the peers
358 */ 420 */
359static void 421static void
360run (void *cls, 422start_get (void *cls)
361 struct GNUNET_DHT_TEST_Context *ctx,
362 unsigned int num_peers,
363 struct GNUNET_TESTBED_Peer **peers,
364 struct GNUNET_DHT_Handle **dhts)
365{ 423{
424 struct GNUNET_DHT_Handle **dhts = cls;
366 unsigned int i; 425 unsigned int i;
367 unsigned int j; 426 unsigned int j;
368 struct GNUNET_HashCode key; 427 struct GNUNET_HashCode key;
369 struct GetOperation *get_op; 428 struct GetOperation *get_op;
370 429
371 GNUNET_assert (NUM_PEERS == num_peers); 430 get_task = NULL;
372 my_peers = peers; 431 for (i=0;i<NUM_PEERS;i++)
373 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
374 "Peers setup, starting test\n");
375 put_task = GNUNET_SCHEDULER_add_now (&do_puts, dhts);
376 for (i=0;i<num_peers;i++)
377 { 432 {
378 GNUNET_CRYPTO_hash (&i, sizeof (i), &key); 433 GNUNET_CRYPTO_hash (&i, sizeof (i), &key);
379 for (j=0;j<num_peers;j++) 434 for (j=0;j<NUM_PEERS;j++)
380 { 435 {
381 get_op = GNUNET_new (struct GetOperation); 436 get_op = GNUNET_new (struct GetOperation);
382 GNUNET_CONTAINER_DLL_insert (get_head, 437 GNUNET_CONTAINER_DLL_insert (get_head,
@@ -389,11 +444,43 @@ run (void *cls,
389 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, 444 GNUNET_DHT_RO_RECORD_ROUTE | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
390 NULL, /* xquery */ 445 NULL, /* xquery */
391 0, /* xquery bits */ 446 0, /* xquery bits */
392 &dht_get_handler, get_op); 447 &dht_get_handler,
448 get_op);
393 } 449 }
394 } 450 }
451}
452
453
454/**
455 * Main function of the test.
456 *
457 * @param cls closure (NULL)
458 * @param ctx argument to give to #GNUNET_DHT_TEST_cleanup on test end
459 * @param num_peers number of @a peers that are running
460 * @param peers array of peers
461 * @param dhts handle to each of the DHTs of the peers
462 */
463static void
464run (void *cls,
465 struct GNUNET_DHT_TEST_Context *ctx,
466 unsigned int num_peers,
467 struct GNUNET_TESTBED_Peer **peers,
468 struct GNUNET_DHT_Handle **dhts)
469{
470 GNUNET_assert (NUM_PEERS == num_peers);
471 my_peers = peers;
472 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
473 "Peers setup, starting test\n");
474 put_task = GNUNET_SCHEDULER_add_now (&do_puts,
475 dhts);
476 get_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
477 &start_get,
478 dhts);
395 timeout_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT, 479 timeout_task = GNUNET_SCHEDULER_add_delayed (GET_TIMEOUT,
396 &shutdown_task, ctx); 480 &timeout_cb,
481 ctx);
482 GNUNET_SCHEDULER_add_shutdown (&shutdown_task,
483 ctx);
397} 484}
398 485
399 486