aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dv/Makefile.am11
-rw-r--r--src/dv/dv_api.c7
-rw-r--r--src/dv/gnunet-service-dv.c87
-rw-r--r--src/dv/plugin_transport_dv.c10
-rw-r--r--src/dv/test_dv_topology.c752
-rw-r--r--src/dv/test_dv_topology.conf68
-rw-r--r--src/dv/test_transport_api_dv.c386
-rw-r--r--src/dv/test_transport_api_dv_peer4.conf111
8 files changed, 1269 insertions, 163 deletions
diff --git a/src/dv/Makefile.am b/src/dv/Makefile.am
index 0dc4afb08..9d5dc1ab1 100644
--- a/src/dv/Makefile.am
+++ b/src/dv/Makefile.am
@@ -50,7 +50,8 @@ libgnunet_plugin_transport_dv_la_LDFLAGS = \
50 50
51 51
52check_PROGRAMS = \ 52check_PROGRAMS = \
53 test_transport_api_dv 53 test_transport_api_dv \
54 test_dv_topology
54 55
55TESTS = $(check_PROGRAMS) $(check_SCRIPTS) 56TESTS = $(check_PROGRAMS) $(check_SCRIPTS)
56 57
@@ -60,6 +61,14 @@ test_transport_api_dv_LDADD = \
60 $(top_builddir)/src/transport/libgnunettransport.la \ 61 $(top_builddir)/src/transport/libgnunettransport.la \
61 $(top_builddir)/src/util/libgnunetutil.la 62 $(top_builddir)/src/util/libgnunetutil.la
62 63
64test_dv_topology_SOURCES = \
65 test_dv_topology.c
66test_dv_topology_LDADD = \
67 $(top_builddir)/src/transport/libgnunettransport.la \
68 $(top_builddir)/src/util/libgnunetutil.la \
69 $(top_builddir)/src/testing/libgnunettesting.la
70
71
63EXTRA_DIST = \ 72EXTRA_DIST = \
64 test_transport_api_dv_peer1.conf \ 73 test_transport_api_dv_peer1.conf \
65 test_transport_api_dv_peer2.conf \ 74 test_transport_api_dv_peer2.conf \
diff --git a/src/dv/dv_api.c b/src/dv/dv_api.c
index 28bd0dcac..b7337d45c 100644
--- a/src/dv/dv_api.c
+++ b/src/dv/dv_api.c
@@ -345,6 +345,10 @@ void handle_message_receipt (void *cls,
345 GNUNET_HashCode uidhash; 345 GNUNET_HashCode uidhash;
346 struct SendCallbackContext *send_ctx; 346 struct SendCallbackContext *send_ctx;
347 347
348#if DEBUG_DV
349 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "dv api receives message!\n");
350#endif
351
348 if (msg == NULL) 352 if (msg == NULL)
349 { 353 {
350 return; /* Connection closed? */ 354 return; /* Connection closed? */
@@ -474,8 +478,7 @@ int GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle,
474 send_ctx = GNUNET_malloc(sizeof(struct SendCallbackContext)); 478 send_ctx = GNUNET_malloc(sizeof(struct SendCallbackContext));
475 479
476 send_ctx->cont = cont; 480 send_ctx->cont = cont;
477 if (cont == NULL) 481
478 fprintf(stderr, "DV_SEND called with null continuation!\n");
479 send_ctx->cont_cls = cont_cls; 482 send_ctx->cont_cls = cont_cls;
480 memcpy(&send_ctx->target, target, sizeof(struct GNUNET_PeerIdentity)); 483 memcpy(&send_ctx->target, target, sizeof(struct GNUNET_PeerIdentity));
481 484
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index dc92bfa37..3a0d4f936 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -724,7 +724,7 @@ void send_to_plugin(const struct GNUNET_PeerIdentity * sender,
724 } 724 }
725 else 725 else
726 { 726 {
727 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to queue message for plugin, must be one in progress already!!\n"); 727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, must be one in progress already!!\n");
728 } 728 }
729 } 729 }
730} 730}
@@ -754,7 +754,7 @@ size_t core_transmit_notify (void *cls,
754 { 754 {
755 /* client disconnected */ 755 /* client disconnected */
756#if DEBUG_DV 756#if DEBUG_DV
757 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "`%s': buffer was NULL\n", "DHT"); 757 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s': buffer was NULL\n", "DHT");
758#endif 758#endif
759 return 0; 759 return 0;
760 } 760 }
@@ -778,7 +778,6 @@ size_t core_transmit_notify (void *cls,
778 GNUNET_free(reply->send_result); 778 GNUNET_free(reply->send_result);
779 779
780 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, client_reply); 780 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, client_reply);
781 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Queued client send receipt success message!\n");
782 if (client_handle != NULL) 781 if (client_handle != NULL)
783 { 782 {
784 if (plugin_transmit_handle == NULL) 783 if (plugin_transmit_handle == NULL)
@@ -1031,7 +1030,7 @@ static int handle_dv_data_message (void *cls,
1031 { 1030 {
1032#if DEBUG_DV 1031#if DEBUG_DV
1033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1032 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1034 "%s: unknown sender (%d), size of extended_peers is %d!\n", "dv", ntohl(incoming->sender), GNUNET_CONTAINER_multihashmap_size (ctx.extended_neighbors)); 1033 "%s peer %s: unknown sender (%d)!\n", "DV SERVICE", GNUNET_i2s(&my_identity), ntohl(incoming->sender), GNUNET_CONTAINER_multihashmap_size (ctx.extended_neighbors));
1035#endif 1034#endif
1036 /* unknown sender */ 1035 /* unknown sender */
1037 return GNUNET_OK; 1036 return GNUNET_OK;
@@ -1125,7 +1124,7 @@ static int handle_dv_data_message (void *cls,
1125 */ 1124 */
1126static void 1125static void
1127neighbor_send_task (void *cls, 1126neighbor_send_task (void *cls,
1128 const struct GNUNET_SCHEDULER_TaskContext *tc) 1127 const struct GNUNET_SCHEDULER_TaskContext *tc)
1129{ 1128{
1130 struct NeighborSendContext *send_context = cls; 1129 struct NeighborSendContext *send_context = cls;
1131#if DEBUG_DV_GOSSIP_SEND 1130#if DEBUG_DV_GOSSIP_SEND
@@ -1187,7 +1186,7 @@ neighbor_send_task (void *cls,
1187#if DEBUG_DV_GOSSIP_SEND 1186#if DEBUG_DV_GOSSIP_SEND
1188 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&about->identity)); 1187 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&about->identity));
1189 encPeerTo = GNUNET_strdup(GNUNET_i2s(&to->identity)); 1188 encPeerTo = GNUNET_strdup(GNUNET_i2s(&to->identity));
1190 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1191 "%s: Sending info about peer %s to directly connected peer %s\n", 1190 "%s: Sending info about peer %s to directly connected peer %s\n",
1192 GNUNET_i2s(&my_identity), 1191 GNUNET_i2s(&my_identity),
1193 encPeerAbout, encPeerTo); 1192 encPeerAbout, encPeerTo);
@@ -1218,12 +1217,12 @@ neighbor_send_task (void *cls,
1218 1217
1219 if (send_context->fast_gossip_list_head != NULL) /* If there are other peers in the fast list, schedule right away */ 1218 if (send_context->fast_gossip_list_head != NULL) /* If there are other peers in the fast list, schedule right away */
1220 { 1219 {
1221 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: still in fast send mode\n"); 1220 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV SERVICE: still in fast send mode\n");
1222 send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, send_context); 1221 send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, send_context);
1223 } 1222 }
1224 else 1223 else
1225 { 1224 {
1226 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: entering slow send mode\n"); 1225 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV SERVICE: entering slow send mode\n");
1227 send_context->task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_DV_DEFAULT_SEND_INTERVAL, &neighbor_send_task, send_context); 1226 send_context->task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_DV_DEFAULT_SEND_INTERVAL, &neighbor_send_task, send_context);
1228 } 1227 }
1229 1228
@@ -1329,10 +1328,6 @@ void handle_dv_send_message (void *cls,
1329 GNUNET_assert(address_len == sizeof(struct GNUNET_PeerIdentity) * 2); 1328 GNUNET_assert(address_len == sizeof(struct GNUNET_PeerIdentity) * 2);
1330 message_size = ntohl(send_msg->msgbuf_size); 1329 message_size = ntohl(send_msg->msgbuf_size);
1331 1330
1332#if 1
1333 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1334 "%s: Receives %s message size %u!\n\n\n", "dv", "SEND", message_size);
1335#endif
1336 GNUNET_assert(ntohs(message->size) == sizeof(struct GNUNET_DV_SendMessage) + address_len + message_size); 1331 GNUNET_assert(ntohs(message->size) == sizeof(struct GNUNET_DV_SendMessage) + address_len + message_size);
1337 destination = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 1332 destination = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
1338 direct = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 1333 direct = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity));
@@ -1356,10 +1351,10 @@ void handle_dv_send_message (void *cls,
1356 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: asked to send message to `%s', but address is for `%s'!", "DV SERVICE", GNUNET_i2s(&send_msg->target), (const char *)&dest_hash.encoding); 1351 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: asked to send message to `%s', but address is for `%s'!", "DV SERVICE", GNUNET_i2s(&send_msg->target), (const char *)&dest_hash.encoding);
1357 } 1352 }
1358 1353
1359#if 1 1354#if DEBUG_DV
1360 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */ 1355 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1361 dest_hash.encoding[4] = '\0'; 1356 dest_hash.encoding[4] = '\0';
1362 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SEND called with message of size %d type %d, destination `%s' via `%s'\n", message_size, ntohs(message_buf->type), (const char *)&dest_hash.encoding, GNUNET_i2s(direct)); 1357 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV SEND called with message of size %d type %d, destination `%s' via `%s'\n", message_size, ntohs(message_buf->type), (const char *)&dest_hash.encoding, GNUNET_i2s(direct));
1363#endif 1358#endif
1364 send_context = GNUNET_malloc(sizeof(struct DV_SendContext)); 1359 send_context = GNUNET_malloc(sizeof(struct DV_SendContext));
1365 1360
@@ -1823,10 +1818,9 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, struct GNUNET_CRYPTO
1823 "%s: Already know peer %s distance %d, referrer id %d!\n", "dv", GNUNET_i2s(peer), cost, referrer_peer_id); 1818 "%s: Already know peer %s distance %d, referrer id %d!\n", "dv", GNUNET_i2s(peer), cost, referrer_peer_id);
1824#endif 1819#endif
1825 } 1820 }
1826#if DEBUG_DV_GOSSIP 1821#if DEBUG_DV
1827 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1828 "%s: Size of extended_neighbors is %d\n", "dv", GNUNET_CONTAINER_multihashmap_size(ctx.extended_neighbors)); 1823 "%s: Size of extended_neighbors is %d\n", "dv", GNUNET_CONTAINER_multihashmap_size(ctx.extended_neighbors));
1829 GNUNET_CONTAINER_multihashmap_iterate(ctx.extended_neighbors, &print_neighbors, NULL);
1830#endif 1824#endif
1831 GNUNET_free(neighbor_update); 1825 GNUNET_free(neighbor_update);
1832 1826
@@ -1999,7 +1993,6 @@ static int add_all_extended_peers (void *cls,
1999 if (memcmp(&send_context->toNeighbor->identity, &distant->identity, sizeof(struct GNUNET_PeerIdentity)) == 0) 1993 if (memcmp(&send_context->toNeighbor->identity, &distant->identity, sizeof(struct GNUNET_PeerIdentity)) == 0)
2000 return GNUNET_YES; /* Don't gossip to a peer about itself! */ 1994 return GNUNET_YES; /* Don't gossip to a peer about itself! */
2001 1995
2002 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: adding extended neighbor to fast send list\n");
2003#if SUPPORT_HIDING 1996#if SUPPORT_HIDING
2004 if (distant->hidden == GNUNET_YES) 1997 if (distant->hidden == GNUNET_YES)
2005 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */ 1998 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
@@ -2017,6 +2010,55 @@ static int add_all_extended_peers (void *cls,
2017 2010
2018 2011
2019/** 2012/**
2013 * Iterate over all current direct peers, add DISTANT newly connected
2014 * peer to the fast gossip list for that peer so we get DV routing
2015 * information out as fast as possible!
2016 *
2017 * @param cls the newly connected neighbor we will gossip about
2018 * @param key the hashcode of the peer
2019 * @param value the direct neighbor we should gossip to
2020 *
2021 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
2022 */
2023static int add_distant_all_direct_neighbors (void *cls,
2024 const GNUNET_HashCode * key,
2025 void *value)
2026{
2027 struct DirectNeighbor *direct = (struct DirectNeighbor *)value;
2028 struct DistantNeighbor *distant = (struct DistantNeighbor *)cls;
2029 struct NeighborSendContext *send_context = direct->send_context;
2030 struct FastGossipNeighborList *gossip_entry;
2031
2032 if (distant == NULL)
2033 {
2034 return GNUNET_YES;
2035 }
2036
2037 if (memcmp(&direct->identity, &distant->identity, sizeof(struct GNUNET_PeerIdentity)) == 0)
2038 {
2039 return GNUNET_YES; /* Don't gossip to a peer about itself! */
2040 }
2041
2042#if SUPPORT_HIDING
2043 if (distant->hidden == GNUNET_YES)
2044 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
2045#endif
2046 gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList));
2047 gossip_entry->about = distant;
2048
2049 GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head,
2050 send_context->fast_gossip_list_tail,
2051 send_context->fast_gossip_list_tail,
2052 gossip_entry);
2053 if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
2054 GNUNET_SCHEDULER_cancel(sched, send_context->task);
2055
2056 send_context->task = GNUNET_SCHEDULER_add_now(sched, &neighbor_send_task, send_context);
2057 return GNUNET_YES;
2058}
2059
2060
2061/**
2020 * Iterate over all current direct peers, add newly connected peer 2062 * Iterate over all current direct peers, add newly connected peer
2021 * to the fast gossip list for that peer so we get DV routing 2063 * to the fast gossip list for that peer so we get DV routing
2022 * information out as fast as possible! 2064 * information out as fast as possible!
@@ -2039,12 +2081,15 @@ static int add_all_direct_neighbors (void *cls,
2039 2081
2040 distant = GNUNET_CONTAINER_multihashmap_get(ctx.extended_neighbors, &to->identity.hashPubKey); 2082 distant = GNUNET_CONTAINER_multihashmap_get(ctx.extended_neighbors, &to->identity.hashPubKey);
2041 if (distant == NULL) 2083 if (distant == NULL)
2042 return GNUNET_YES; 2084 {
2085 return GNUNET_YES;
2086 }
2043 2087
2044 if (memcmp(&direct->identity, &to->identity, sizeof(struct GNUNET_PeerIdentity)) == 0) 2088 if (memcmp(&direct->identity, &to->identity, sizeof(struct GNUNET_PeerIdentity)) == 0)
2045 return GNUNET_YES; /* Don't gossip to a peer about itself! */ 2089 {
2090 return GNUNET_YES; /* Don't gossip to a peer about itself! */
2091 }
2046 2092
2047 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: adding new DISTANT neighbor to fast send list\n");
2048#if SUPPORT_HIDING 2093#if SUPPORT_HIDING
2049 if (distant->hidden == GNUNET_YES) 2094 if (distant->hidden == GNUNET_YES)
2050 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */ 2095 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
@@ -2147,7 +2192,7 @@ void handle_core_connect (void *cls,
2147 { 2192 {
2148 about = GNUNET_CONTAINER_multihashmap_get(ctx.extended_neighbors, &peer->hashPubKey); 2193 about = GNUNET_CONTAINER_multihashmap_get(ctx.extended_neighbors, &peer->hashPubKey);
2149 if ((GNUNET_CONTAINER_multihashmap_get(ctx.direct_neighbors, &peer->hashPubKey) == NULL) && (about != NULL)) 2194 if ((GNUNET_CONTAINER_multihashmap_get(ctx.direct_neighbors, &peer->hashPubKey) == NULL) && (about != NULL))
2150 GNUNET_CONTAINER_multihashmap_iterate(ctx.direct_neighbors, &add_all_direct_neighbors, about); 2195 GNUNET_CONTAINER_multihashmap_iterate(ctx.direct_neighbors, &add_distant_all_direct_neighbors, about);
2151 2196
2152#if DEBUG_DV 2197#if DEBUG_DV
2153 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2198 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c
index 6932ce34b..a8c05d309 100644
--- a/src/dv/plugin_transport_dv.c
+++ b/src/dv/plugin_transport_dv.c
@@ -139,11 +139,6 @@ struct Plugin
139 struct Session *sessions; 139 struct Session *sessions;
140 140
141 /** 141 /**
142 * Handle for the statistics service.
143 */
144 struct GNUNET_STATISTICS_Handle *statistics;
145
146 /**
147 * Our server. 142 * Our server.
148 */ 143 */
149 //struct GNUNET_SERVER_Handle *server; 144 //struct GNUNET_SERVER_Handle *server;
@@ -243,10 +238,6 @@ dv_plugin_send (void *cls,
243 int ret = 0; 238 int ret = 0;
244 struct Plugin *plugin = cls; 239 struct Plugin *plugin = cls;
245 240
246 /* FIXME: do we want the dv plugin to remember sent messages to call continuation once message actually goes out?
247 * Or do we just call the continuation once we've notified the plugin?
248 */
249 // FIXME: does it make sense for us to use sessions?
250#if DEBUG_DV 241#if DEBUG_DV
251 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Received send request from transport, calling GNUNET_DV_send\n"); 242 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "DV API: Received send request from transport, calling GNUNET_DV_send\n");
252#endif 243#endif
@@ -390,7 +381,6 @@ libgnunet_plugin_transport_dv_init (void *cls)
390 381
391 plugin = GNUNET_malloc (sizeof (struct Plugin)); 382 plugin = GNUNET_malloc (sizeof (struct Plugin));
392 plugin->env = env; 383 plugin->env = env;
393 plugin->statistics = NULL;
394 //plugin->service = service; 384 //plugin->service = service;
395 //plugin->server = GNUNET_SERVICE_get_server (service); 385 //plugin->server = GNUNET_SERVICE_get_server (service);
396 386
diff --git a/src/dv/test_dv_topology.c b/src/dv/test_dv_topology.c
new file mode 100644
index 000000000..c7f213a07
--- /dev/null
+++ b/src/dv/test_dv_topology.c
@@ -0,0 +1,752 @@
1/*
2 This file is part of GNUnet.
3 (C) 2009 Christian Grothoff (and other contributing authors)
4
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
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file testing/test_testing_topology.c
22 * @brief base testcase for testing all the topologies provided
23 */
24#include "platform.h"
25#include "gnunet_testing_lib.h"
26#include "gnunet_core_service.h"
27
28#define VERBOSE GNUNET_YES
29
30/**
31 * How long until we fail the whole testcase?
32 */
33#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
34
35/**
36 * How long until we give up on connecting the peers?
37 */
38#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
39
40#define DEFAULT_NUM_PEERS 4
41
42#define MAX_OUTSTANDING_CONNECTIONS 300
43
44static float fail_percentage = 0.05;
45
46static int ok;
47
48static unsigned long long num_peers;
49
50static unsigned int total_connections;
51
52static unsigned int failed_connections;
53
54static unsigned int total_server_connections;
55
56static unsigned int total_messages_received;
57
58static unsigned int expected_messages;
59
60static unsigned int expected_connections;
61
62static unsigned long long peers_left;
63
64static struct GNUNET_TESTING_PeerGroup *pg;
65
66static struct GNUNET_SCHEDULER_Handle *sched;
67
68const struct GNUNET_CONFIGURATION_Handle *main_cfg;
69
70GNUNET_SCHEDULER_TaskIdentifier die_task;
71
72static char *dotOutFileName;
73
74static FILE *dotOutFile;
75
76static char *topology_string;
77
78static int transmit_ready_scheduled;
79
80static int transmit_ready_failed;
81
82static int transmit_ready_called;
83
84static enum GNUNET_TESTING_Topology topology;
85
86static char *test_directory;
87
88#define MTYPE 12345
89
90struct GNUNET_TestMessage
91{
92 /**
93 * Header of the message
94 */
95 struct GNUNET_MessageHeader header;
96
97 /**
98 * Unique identifier for this message.
99 */
100 uint32_t uid;
101};
102
103struct TestMessageContext
104{
105 /* This is a linked list */
106 struct TestMessageContext *next;
107
108 /* Handle to the sending peer core */
109 struct GNUNET_CORE_Handle *peer1handle;
110
111 /* Handle to the receiving peer core */
112 struct GNUNET_CORE_Handle *peer2handle;
113
114 /* Handle to the sending peer daemon */
115 struct GNUNET_TESTING_Daemon *peer1;
116
117 /* Handle to the receiving peer daemon */
118 struct GNUNET_TESTING_Daemon *peer2;
119
120 /* Identifier for this message, so we don't disconnect other peers! */
121 uint32_t uid;
122
123 /* Task for disconnecting cores, allow task to be cancelled on shutdown */
124 GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
125
126};
127
128static struct TestMessageContext *test_messages;
129
130static void
131finish_testing ()
132{
133 GNUNET_assert (pg != NULL);
134 struct TestMessageContext *pos;
135 struct TestMessageContext *free_pos;
136#if VERBOSE
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
138 "Called finish testing, stopping daemons.\n");
139#endif
140 int count;
141 count = 0;
142 pos = test_messages;
143 while (pos != NULL)
144 {
145 if (pos->peer1handle != NULL)
146 {
147 GNUNET_CORE_disconnect(pos->peer1handle);
148 pos->peer1handle = NULL;
149 }
150 if (pos->peer2handle != NULL)
151 {
152 GNUNET_CORE_disconnect(pos->peer2handle);
153 pos->peer2handle = NULL;
154 }
155 free_pos = pos;
156 pos = pos->next;
157 if (free_pos->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
158 {
159 GNUNET_SCHEDULER_cancel(sched, free_pos->disconnect_task);
160 }
161 GNUNET_free(free_pos);
162 }
163#if VERBOSE
164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
165 "transmit_ready's scheduled %d, failed %d, transmit_ready's called %d\n", transmit_ready_scheduled, transmit_ready_failed, transmit_ready_called);
166#endif
167 sleep(1);
168#if VERBOSE
169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
170 "Calling daemons_stop\n");
171#endif
172 GNUNET_TESTING_daemons_stop (pg, TIMEOUT);
173#if VERBOSE
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
175 "daemons_stop finished\n");
176#endif
177 if (dotOutFile != NULL)
178 {
179 fprintf(dotOutFile, "}");
180 fclose(dotOutFile);
181 }
182
183 ok = 0;
184}
185
186
187static void
188disconnect_cores (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
189{
190 struct TestMessageContext *pos = cls;
191
192 /* Disconnect from the respective cores */
193#if VERBOSE
194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
195 "Disconnecting from peer 1 `%4s'\n", GNUNET_i2s (&pos->peer1->id));
196#endif
197 if (pos->peer1handle != NULL)
198 GNUNET_CORE_disconnect(pos->peer1handle);
199#if VERBOSE
200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
201 "Disconnecting from peer 2 `%4s'\n", GNUNET_i2s (&pos->peer2->id));
202#endif
203 if (pos->peer2handle != NULL)
204 GNUNET_CORE_disconnect(pos->peer2handle);
205 /* Set handles to NULL so test case can be ended properly */
206 pos->peer1handle = NULL;
207 pos->peer2handle = NULL;
208 pos->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
209 /* Decrement total connections so new can be established */
210 total_server_connections -= 2;
211}
212
213static int
214process_mtype (void *cls,
215 const struct GNUNET_PeerIdentity *peer,
216 const struct GNUNET_MessageHeader *message,
217 struct GNUNET_TIME_Relative latency,
218 uint32_t distance)
219{
220 struct TestMessageContext *pos = cls;
221 struct GNUNET_TestMessage *msg = (struct GNUNET_TestMessage *)message;
222
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "Received message from `%4s', type %d, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), distance);
225 if (pos->uid != ntohl(msg->uid))
226 return GNUNET_OK;
227
228 total_messages_received++;
229#if VERBOSE
230 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
231 "Received message from `%4s', type %d, distance %u.\n", GNUNET_i2s (peer), ntohs(message->type), distance);
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
233 "Total messages received %d, expected %d.\n", total_messages_received, expected_messages);
234#endif
235
236 if (total_messages_received == expected_messages)
237 {
238 GNUNET_SCHEDULER_cancel (sched, die_task);
239 GNUNET_SCHEDULER_add_now (sched, &finish_testing, NULL);
240 }
241 else
242 {
243 pos->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &disconnect_cores, pos);
244 }
245
246 return GNUNET_OK;
247}
248
249static void
250end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
251{
252 char *msg = cls;
253 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
254 "End badly was called (%s)... stopping daemons.\n", msg);
255 struct TestMessageContext *pos;
256 struct TestMessageContext *free_pos;
257
258 pos = test_messages;
259 while (pos != NULL)
260 {
261 if (pos->peer1handle != NULL)
262 {
263 GNUNET_CORE_disconnect(pos->peer1handle);
264 pos->peer1handle = NULL;
265 }
266 if (pos->peer2handle != NULL)
267 {
268 GNUNET_CORE_disconnect(pos->peer2handle);
269 pos->peer2handle = NULL;
270 }
271 free_pos = pos;
272 pos = pos->next;
273 GNUNET_free(free_pos);
274 }
275
276 if (pg != NULL)
277 {
278 GNUNET_TESTING_daemons_stop (pg);
279 ok = 7331; /* Opposite of leet */
280 }
281 else
282 ok = 401; /* Never got peers started */
283
284 if (dotOutFile != NULL)
285 {
286 fprintf(dotOutFile, "}");
287 fclose(dotOutFile);
288 }
289}
290
291
292
293static size_t
294transmit_ready (void *cls, size_t size, void *buf)
295{
296 struct GNUNET_TestMessage *m;
297 struct TestMessageContext *pos = cls;
298
299 GNUNET_assert (buf != NULL);
300 m = (struct GNUNET_TestMessage *) buf;
301 m->header.type = htons (MTYPE);
302 m->header.size = htons (sizeof (struct GNUNET_TestMessage));
303 m->uid = htonl(pos->uid);
304 transmit_ready_called++;
305#if VERBOSE
306 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
307 "transmit ready for peer %s\ntransmit_ready's scheduled %d, transmit_ready's called %d\n", GNUNET_i2s(&pos->peer1->id), transmit_ready_scheduled, transmit_ready_called);
308#endif
309 return sizeof (struct GNUNET_TestMessage);
310}
311
312
313static struct GNUNET_CORE_MessageHandler no_handlers[] = {
314 {NULL, 0, 0}
315};
316
317static struct GNUNET_CORE_MessageHandler handlers[] = {
318 {&process_mtype, MTYPE, sizeof (struct GNUNET_TestMessage)},
319 {NULL, 0, 0}
320};
321
322static void
323init_notify_peer2 (void *cls,
324 struct GNUNET_CORE_Handle *server,
325 const struct GNUNET_PeerIdentity *my_identity,
326 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
327{
328 struct TestMessageContext *pos = cls;
329
330#if VERBOSE
331 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
332 "Core connection to `%4s' established, scheduling message send\n",
333 GNUNET_i2s (my_identity));
334#endif
335 total_server_connections++;
336
337 if (NULL == GNUNET_CORE_notify_transmit_ready (pos->peer1handle,
338 0,
339 TIMEOUT,
340 &pos->peer2->id,
341 sizeof (struct GNUNET_TestMessage),
342 &transmit_ready, pos))
343 {
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
345 "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
346 GNUNET_i2s (&pos->peer2->id));
347 transmit_ready_failed++;
348 }
349 else
350 {
351 transmit_ready_scheduled++;
352 }
353}
354
355
356static void
357init_notify_peer1 (void *cls,
358 struct GNUNET_CORE_Handle *server,
359 const struct GNUNET_PeerIdentity *my_identity,
360 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
361{
362 struct TestMessageContext *pos = cls;
363 total_server_connections++;
364
365#if VERBOSE
366 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
367 "Core connection to `%4s' established, setting up handles\n",
368 GNUNET_i2s (my_identity));
369#endif
370
371 /*
372 * Connect to the receiving peer
373 */
374 pos->peer2handle = GNUNET_CORE_connect (sched,
375 pos->peer2->cfg,
376 TIMEOUT,
377 pos,
378 &init_notify_peer2,
379 NULL,
380 NULL,
381 NULL,
382 GNUNET_YES, NULL, GNUNET_YES, handlers);
383
384}
385
386
387static void
388send_test_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
389{
390 struct TestMessageContext *pos = cls;
391
392 if ((tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) || (cls == NULL))
393 return;
394
395 if (die_task == GNUNET_SCHEDULER_NO_TASK)
396 {
397 die_task = GNUNET_SCHEDULER_add_delayed (sched,
398 TEST_TIMEOUT,
399 &end_badly, "from send_test_messages (timeout)");
400 }
401
402 if (total_server_connections >= MAX_OUTSTANDING_CONNECTIONS)
403 {
404 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
405 &send_test_messages, pos);
406 return; /* Otherwise we'll double schedule messages here! */
407 }
408
409 /*
410 * Connect to the sending peer
411 */
412 pos->peer1handle = GNUNET_CORE_connect (sched,
413 pos->peer1->cfg,
414 TIMEOUT,
415 pos,
416 &init_notify_peer1,
417 NULL,
418 NULL,
419 NULL,
420 GNUNET_NO, NULL, GNUNET_NO, no_handlers);
421
422 GNUNET_assert(pos->peer1handle != NULL);
423
424 if (total_server_connections < MAX_OUTSTANDING_CONNECTIONS)
425 {
426 GNUNET_SCHEDULER_add_now (sched,
427 &send_test_messages, pos->next);
428 }
429 else
430 {
431 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1),
432 &send_test_messages, pos->next);
433 }
434}
435
436
437static void
438schedule_dv_messages (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
439{
440 struct TestMessageContext *pos;
441 struct TestMessageContext *new_message;
442 struct TestMessageContext *last;
443 struct TestMessageContext *new_list;
444 int i;
445 int other;
446
447 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
448 return;
449
450 pos = test_messages;
451 last = NULL;
452 while (pos != NULL)
453 {
454 last = pos;
455 pos = pos->next;
456 }
457
458 new_list = NULL;
459 for (i = 0; i < num_peers; i++)
460 {
461 new_message = GNUNET_malloc(sizeof(struct TestMessageContext));
462 other = i + 2;
463 if (other >= num_peers)
464 other = other - num_peers;
465 new_message->peer1 = GNUNET_TESTING_daemon_get(pg, i);
466 new_message->peer2 = GNUNET_TESTING_daemon_get(pg, other);
467
468 new_message->uid = total_connections + i + 1;
469 new_message->next = new_list;
470#if VERBOSE
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
472 "Scheduled message between `%4s' and `%4s'\n",
473 new_message->peer1->shortname, new_message->peer2->shortname);
474#endif
475
476 new_list = new_message;
477 expected_messages++;
478 }
479
480 if (dotOutFile != NULL)
481 {
482 fprintf(dotOutFile, "}");
483 fclose (dotOutFile);
484 dotOutFile = NULL;
485 }
486
487 if (last != NULL)
488 last->next = new_list;
489 else
490 test_messages = new_list;
491
492 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &send_test_messages, test_messages);
493}
494
495
496void
497topology_callback (void *cls,
498 const struct GNUNET_PeerIdentity *first,
499 const struct GNUNET_PeerIdentity *second,
500 const struct GNUNET_CONFIGURATION_Handle *first_cfg,
501 const struct GNUNET_CONFIGURATION_Handle *second_cfg,
502 struct GNUNET_TESTING_Daemon *first_daemon,
503 struct GNUNET_TESTING_Daemon *second_daemon,
504 const char *emsg)
505{
506 //struct TestMessageContext *temp_context;
507 if (emsg == NULL)
508 {
509 total_connections++;
510#if VERBOSE
511 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s\n",
512 first_daemon->shortname,
513 second_daemon->shortname);
514#endif
515 /*temp_context = GNUNET_malloc(sizeof(struct TestMessageContext));
516 temp_context->peer1 = first_daemon;
517 temp_context->peer2 = second_daemon;
518 temp_context->next = test_messages;
519 temp_context->uid = total_connections;
520 temp_context->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
521 test_messages = temp_context;
522
523 expected_messages++;*/
524 if (dotOutFile != NULL)
525 fprintf(dotOutFile, "\tn%s -- n%s;\n", first_daemon->shortname, second_daemon->shortname);
526 }
527#if VERBOSE
528 else
529 {
530 failed_connections++;
531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
532 first_daemon->shortname,
533 second_daemon->shortname, emsg);
534 }
535#endif
536
537 if (total_connections == expected_connections)
538 {
539#if VERBOSE
540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
541 "Created %d total connections, which is our target number! Calling send messages.\n",
542 total_connections);
543#endif
544
545 GNUNET_SCHEDULER_cancel (sched, die_task);
546 die_task = GNUNET_SCHEDULER_NO_TASK;
547 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &schedule_dv_messages, test_messages);
548 }
549 else if (total_connections + failed_connections == expected_connections)
550 {
551 if (failed_connections < (unsigned int)(fail_percentage * total_connections))
552 {
553 GNUNET_SCHEDULER_cancel (sched, die_task);
554 die_task = GNUNET_SCHEDULER_NO_TASK;
555 GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1), &schedule_dv_messages, test_messages);
556 }
557 else
558 {
559 GNUNET_SCHEDULER_cancel (sched, die_task);
560 die_task = GNUNET_SCHEDULER_add_now (sched,
561 &end_badly, "from topology_callback (too many failed connections)");
562 }
563 }
564 else
565 {
566#if VERBOSE
567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
568 "Have %d total connections, %d failed connections, Want %d (at least %d)\n",
569 total_connections, failed_connections, expected_connections, expected_connections - (unsigned int)(fail_percentage * expected_connections));
570#endif
571 }
572}
573
574
575static void
576create_topology ()
577{
578 expected_connections = -1;
579 if ((pg != NULL) && (peers_left == 0))
580 {
581 /* create_topology will read the topology information from
582 the config already contained in the peer group, so should
583 we have create_topology called from start peers? I think
584 maybe this way is best so that the client can know both
585 when peers are started, and when they are connected.
586 */
587 expected_connections = GNUNET_TESTING_create_topology (pg, topology);
588#if VERBOSE
589 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
590 "Have %d expected connections\n", expected_connections);
591#endif
592 }
593
594 GNUNET_SCHEDULER_cancel (sched, die_task);
595 if (expected_connections == GNUNET_SYSERR)
596 {
597 die_task = GNUNET_SCHEDULER_add_now (sched,
598 &end_badly, "from create topology (bad return)");
599 }
600 die_task = GNUNET_SCHEDULER_add_delayed (sched,
601 TEST_TIMEOUT,
602 &end_badly, "from create topology (timeout)");
603}
604
605
606static void
607my_cb (void *cls,
608 const struct GNUNET_PeerIdentity *id,
609 const struct GNUNET_CONFIGURATION_Handle *cfg,
610 struct GNUNET_TESTING_Daemon *d, const char *emsg)
611{
612 GNUNET_assert (id != NULL);
613#if VERBOSE
614 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
615 (num_peers - peers_left) + 1, num_peers);
616#endif
617 peers_left--;
618 if (peers_left == 0)
619 {
620#if VERBOSE
621 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
622 "All %d daemons started, now creating topology!\n",
623 num_peers);
624#endif
625 GNUNET_SCHEDULER_cancel (sched, die_task);
626 /* Set up task in case topology creation doesn't finish
627 * within a reasonable amount of time */
628 die_task = GNUNET_SCHEDULER_add_delayed (sched,
629 GNUNET_TIME_relative_multiply
630 (GNUNET_TIME_UNIT_MINUTES, 5),
631 &end_badly, "from my_cb");
632 create_topology ();
633 ok = 0;
634 }
635}
636
637
638static void
639run (void *cls,
640 struct GNUNET_SCHEDULER_Handle *s,
641 char *const *args,
642 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
643{
644 unsigned long long topology_num;
645 sched = s;
646 ok = 1;
647
648 dotOutFileName = strdup("topology.dot");
649 dotOutFile = fopen (dotOutFileName, "w");
650 if (dotOutFile != NULL)
651 {
652 fprintf (dotOutFile, "strict graph G {\n");
653 }
654
655#if VERBOSE
656 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
657 "Starting daemons based on config file %s\n", cfgfile);
658#endif
659
660 if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
661 {
662 ok = 404;
663 return;
664 }
665
666 if (GNUNET_YES ==
667 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "topology",
668 &topology_num))
669 topology = topology_num;
670
671 if (GNUNET_SYSERR ==
672 GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
673 &num_peers))
674 num_peers = DEFAULT_NUM_PEERS;
675
676 main_cfg = cfg;
677
678 peers_left = num_peers;
679
680 /* Set up a task to end testing if peer start fails */
681 die_task = GNUNET_SCHEDULER_add_delayed (sched,
682 GNUNET_TIME_relative_multiply
683 (GNUNET_TIME_UNIT_MINUTES, 5),
684 &end_badly, "didn't start all daemons in reasonable amount of time!!!");
685
686 pg = GNUNET_TESTING_daemons_start (sched, cfg,
687 peers_left,
688 TIMEOUT,
689 &my_cb, NULL,
690 &topology_callback, NULL, NULL);
691
692}
693
694static int
695check ()
696{
697 char *binary_name;
698 char *config_file_name;
699 GNUNET_asprintf(&binary_name, "test-dv-topology", topology_string);
700 GNUNET_asprintf(&config_file_name, "test_dv_topology.conf", topology_string);
701
702 int ret;
703 char *const argv[] = {binary_name,
704 "-c",
705 config_file_name,
706#if VERBOSE
707 "-L", "DEBUG",
708#endif
709 NULL
710 };
711 struct GNUNET_GETOPT_CommandLineOption options[] = {
712 GNUNET_GETOPT_OPTION_END
713 };
714 ret = GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
715 argv, binary_name, "nohelp",
716 options, &run, &ok);
717 if (ret != GNUNET_OK)
718 {
719 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`test-dv-topology': Failed with error code %d\n", ret);
720 }
721 GNUNET_free(binary_name);
722 GNUNET_free(config_file_name);
723 return ok;
724}
725
726int
727main (int argc, char *argv[])
728{
729 int ret;
730
731 GNUNET_log_setup ("test-dv-topology",
732#if VERBOSE
733 "DEBUG",
734#else
735 "WARNING",
736#endif
737 NULL);
738 ret = check ();
739
740 /**
741 * Need to remove base directory, subdirectories taken care
742 * of by the testing framework.
743 */
744 if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
745 {
746 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
747 }
748
749 return ret;
750}
751
752/* end of test_testing_group.c */
diff --git a/src/dv/test_dv_topology.conf b/src/dv/test_dv_topology.conf
new file mode 100644
index 000000000..4eeee8fe2
--- /dev/null
+++ b/src/dv/test_dv_topology.conf
@@ -0,0 +1,68 @@
1[PATHS]
2SERVICEHOME = /tmp/test-gnunet-dv/
3DEFAULTCONFIG = test_dv_topology.conf
4
5[resolver]
6PORT = 2564
7
8[topology]
9BINARY = gnunet-daemon-topology
10CONFIG = $DEFAULTCONFIG
11FRIENDS = $SERVICEHOME/friends
12AUTOCONNECT = YES
13FRIENDS-ONLY = YES
14
15
16[transport]
17PORT = 2565
18PLUGINS = tcp dv
19#PREFIX = xterm -e xterm -T transport -e gdb --args
20#BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/transport/.libs/gnunet-service-transport
21#PREFIX = valgrind --tool=memcheck --log-file=logs%p
22#DEBUG = YES
23
24[arm]
25PORT = 2566
26DEFAULTSERVICES = topology core dv statistics
27
28[statistics]
29PORT = 2567
30
31[transport-tcp]
32PORT = 2568
33
34[transport-udp]
35PORT = 2568
36
37[peerinfo]
38PORT = 2569
39#DEBUG = YES
40#PREFIX = xterm -e xterm -T peerinfo -e gdb --args
41#BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/peerinfo/.libs/gnunet-service-peerinfo
42#PREFIX = valgrind --tool=memcheck --log-file=peerinfo%p
43
44[core]
45PORT = 2570
46#PREFIX = xterm -e xterm -T CORE -e gdb --args
47#PREFIX = valgrind --tool=memcheck --log-file=logs%p
48#DEBUG = YES
49
50[dv]
51DEBUG = NO
52ALLOW_SHUTDOWN = YES
53ACCEPT_FROM6 = ::1;
54ACCEPT_FROM = 127.0.0.1;
55BINARY = gnunet-service-dv
56#BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/dv/.libs/gnunet-service-dv
57#PREFIX = xterm -T dvservice -e gdb --args
58#PREFIX = valgrind --log-file=dv1-%p --leak-check=full
59CONFIG = $DEFAULTCONFIG
60HOME = $SERVICEHOME
61HOSTNAME = localhost
62PORT = 2571
63
64[testing]
65NUM_PEERS = 6
66WEAKRANDOM = YES
67TOPOLOGY = 3
68F2F = YES
diff --git a/src/dv/test_transport_api_dv.c b/src/dv/test_transport_api_dv.c
index 3beb23a11..50eeeb60c 100644
--- a/src/dv/test_transport_api_dv.c
+++ b/src/dv/test_transport_api_dv.c
@@ -55,13 +55,17 @@
55 55
56#define MTYPE 12345 56#define MTYPE 12345
57 57
58static int num_wanted = 2;
59
60static int num_received = 0;
61
58struct PeerContext 62struct PeerContext
59{ 63{
60 struct GNUNET_CONFIGURATION_Handle *cfg; 64 struct GNUNET_CONFIGURATION_Handle *cfg;
61 struct GNUNET_TRANSPORT_Handle *th; 65 struct GNUNET_TRANSPORT_Handle *th;
62 struct GNUNET_PeerIdentity id; 66 struct GNUNET_PeerIdentity id;
63 const char *cfg_file; 67 const char *cfg_file;
64 const struct GNUNET_HELLO_Message *hello; 68 struct GNUNET_HELLO_Message *hello;
65#if START_ARM 69#if START_ARM
66 pid_t arm_pid; 70 pid_t arm_pid;
67#endif 71#endif
@@ -73,6 +77,8 @@ static struct PeerContext p2;
73 77
74static struct PeerContext p3; 78static struct PeerContext p3;
75 79
80static struct PeerContext p4;
81
76static struct GNUNET_SCHEDULER_Handle *sched; 82static struct GNUNET_SCHEDULER_Handle *sched;
77 83
78static int ok; 84static int ok;
@@ -91,15 +97,38 @@ end ()
91{ 97{
92 /* do work here */ 98 /* do work here */
93 GNUNET_SCHEDULER_cancel (sched, die_task); 99 GNUNET_SCHEDULER_cancel (sched, die_task);
94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 1!\n"); 100
95 GNUNET_TRANSPORT_disconnect (p1.th); 101 if (p1.th != NULL)
96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 2!\n"); 102 {
97 GNUNET_TRANSPORT_disconnect (p2.th); 103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 1!\n");
98 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 3!\n"); 104 GNUNET_TRANSPORT_disconnect (p1.th);
99 GNUNET_TRANSPORT_disconnect (p3.th); 105 p1.th = NULL;
106 }
107
108 if (p2.th != NULL)
109 {
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 2!\n");
111 GNUNET_TRANSPORT_disconnect (p2.th);
112 p2.th = NULL;
113 }
114
115 if (p3.th != NULL)
116 {
117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 3!\n");
118 GNUNET_TRANSPORT_disconnect (p3.th);
119 p3.th = NULL;
120 }
121
122 if (p4.th != NULL)
123 {
124 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transport 4!\n");
125 GNUNET_TRANSPORT_disconnect (p4.th);
126 p4.th = NULL;
127 }
100 128
101 die_task = GNUNET_SCHEDULER_NO_TASK; 129 die_task = GNUNET_SCHEDULER_NO_TASK;
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transports disconnected, returning success!\n"); 130 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transports disconnected, returning success!\n");
131 sleep(2);
103 ok = 0; 132 ok = 0;
104} 133}
105 134
@@ -155,10 +184,30 @@ end_badly ()
155 fprintf(stderr, "Ending on an unhappy note.\n"); 184 fprintf(stderr, "Ending on an unhappy note.\n");
156#endif 185#endif
157 186
158 GNUNET_TRANSPORT_disconnect (p1.th); 187 if (p1.th != NULL)
159 GNUNET_TRANSPORT_disconnect (p2.th); 188 {
160 GNUNET_TRANSPORT_disconnect (p3.th); 189 GNUNET_TRANSPORT_disconnect (p1.th);
190 p1.th = NULL;
191 }
161 192
193 if (p2.th != NULL)
194 {
195 GNUNET_TRANSPORT_disconnect (p2.th);
196 p2.th = NULL;
197 }
198
199 if (p3.th != NULL)
200 {
201 GNUNET_TRANSPORT_disconnect (p3.th);
202 p3.th = NULL;
203 }
204
205 if (p4.th != NULL)
206 {
207 GNUNET_TRANSPORT_disconnect (p4.th);
208 p4.th = NULL;
209 }
210 sleep(2);
162 ok = 1; 211 ok = 1;
163 return; 212 return;
164} 213}
@@ -170,17 +219,22 @@ notify_receive (void *cls,
170 struct GNUNET_TIME_Relative latency, 219 struct GNUNET_TIME_Relative latency,
171 uint32_t distance) 220 uint32_t distance)
172{ 221{
173
174 if (ntohs(message->type) != MTYPE) 222 if (ntohs(message->type) != MTYPE)
175 return; 223 return;
176 224
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer (%p) distance %d!\n", 225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer (%p) distance %d latency %u!\n",
178 ntohs(message->type), cls, distance); 226 ntohs(message->type), cls, distance, latency.value);
179 227
180 GNUNET_assert (MTYPE == ntohs (message->type)); 228 GNUNET_assert (MTYPE == ntohs (message->type));
181 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == 229 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
182 ntohs (message->size)); 230 ntohs (message->size));
183 end (); 231 num_received++;
232 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %d of %d messages.\n", num_received, num_wanted);
233
234 if (num_wanted == num_received)
235 {
236 end ();
237 }
184} 238}
185 239
186 240
@@ -221,6 +275,8 @@ notify_connect (void *cls,
221 peer_num = 2; 275 peer_num = 2;
222 else if (cls == &p3) 276 else if (cls == &p3)
223 peer_num = 3; 277 peer_num = 3;
278 else if (cls == &p4)
279 peer_num = 4;
224 280
225 if (memcmp(peer, &p1.id, sizeof(struct GNUNET_PeerIdentity)) == 0) 281 if (memcmp(peer, &p1.id, sizeof(struct GNUNET_PeerIdentity)) == 0)
226 connect_num = 1; 282 connect_num = 1;
@@ -228,18 +284,31 @@ notify_connect (void *cls,
228 connect_num = 2; 284 connect_num = 2;
229 else if (memcmp(peer, &p3.id, sizeof(struct GNUNET_PeerIdentity)) == 0) 285 else if (memcmp(peer, &p3.id, sizeof(struct GNUNET_PeerIdentity)) == 0)
230 connect_num = 3; 286 connect_num = 3;
287 else if (memcmp(peer, &p4.id, sizeof(struct GNUNET_PeerIdentity)) == 0)
288 connect_num = 4;
289 else
290 connect_num = -1;
231 291
232 if ((cls == &p1) && (memcmp(peer, &p3.id, sizeof(struct GNUNET_PeerIdentity)) == 0)) 292 if ((cls == &p1) && (memcmp(peer, &p3.id, sizeof(struct GNUNET_PeerIdentity)) == 0))
233 { 293 {
234
235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
236 "Peer 1 notified about connection to peer 3, distance %u!\n", distance);
237
238 GNUNET_TRANSPORT_notify_transmit_ready (p1.th, 294 GNUNET_TRANSPORT_notify_transmit_ready (p1.th,
239 &p3.id, 295 &p3.id,
240 256, 0, TIMEOUT, &notify_ready, 296 256, 0, TIMEOUT, &notify_ready,
241 &p1); 297 &p1);
242 } 298 }
299
300 if ((cls == &p4) && (memcmp(peer, &p1.id, sizeof(struct GNUNET_PeerIdentity)) == 0))
301 {
302
303 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
304 "Peer 4 notified about connection to peer 1, distance %u!\n", distance);
305
306 GNUNET_TRANSPORT_notify_transmit_ready (p4.th,
307 &p1.id,
308 256, 0, TIMEOUT, &notify_ready,
309 &p4);
310 }
311
243 GNUNET_asprintf(&from_peer_str, "%s", GNUNET_i2s(&from_peer->id)); 312 GNUNET_asprintf(&from_peer_str, "%s", GNUNET_i2s(&from_peer->id));
244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
245 "Peer `%d' %4s connected to peer `%d' %4s distance %d!\n", peer_num, from_peer_str, connect_num, GNUNET_i2s(peer), distance); 314 "Peer `%d' %4s connected to peer `%d' %4s distance %d!\n", peer_num, from_peer_str, connect_num, GNUNET_i2s(peer), distance);
@@ -272,37 +341,144 @@ setup_peer (struct PeerContext *p, const char *cfgname)
272} 341}
273 342
274 343
344static void blacklist_peer(struct GNUNET_DISK_FileHandle *file, struct PeerContext *peer)
345{
346 struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
347 char *buf;
348 size_t size;
349
350 GNUNET_CRYPTO_hash_to_enc(&peer->id.hashPubKey, &peer_enc);
351 size = GNUNET_asprintf(&buf, "%s:%s\n", "tcp", (char *)&peer_enc);
352 GNUNET_DISK_file_write(file, buf, size);
353 GNUNET_free_non_null(buf);
354}
355
275static void 356static void
276exchange_hello_last (void *cls, 357setup_blacklists (void *cls,
277 const struct GNUNET_MessageHeader *message) 358 const struct GNUNET_SCHEDULER_TaskContext *tc)
278{ 359{
279 struct PeerContext *me = cls; 360 char *blacklist_filename;
361 struct GNUNET_DISK_FileHandle *file;
362 int i;
363
364 for (i = 1; i <= 4; i++)
365 {
366 GNUNET_asprintf(&blacklist_filename, "/tmp/test-gnunetd-transport-peer-%d/blacklist", i);
367 if (blacklist_filename != NULL)
368 {
369 file = GNUNET_DISK_file_open(blacklist_filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | GNUNET_DISK_OPEN_CREATE,
370 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
371 GNUNET_free(blacklist_filename);
372
373 if (file == NULL)
374 {
375 GNUNET_SCHEDULER_cancel(sched, die_task);
376 GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL);
377 return;
378 }
379 switch (i)
380 {
381 case 1:
382 blacklist_peer(file, &p3);
383 blacklist_peer(file, &p4);
384 break;
385 case 2:
386 blacklist_peer(file, &p4);
387 break;
388 case 3:
389 blacklist_peer(file, &p1);
390 break;
391 case 4:
392 blacklist_peer(file, &p1);
393 blacklist_peer(file, &p2);
394 break;
395 }
396 }
397 }
280 398
281 GNUNET_TRANSPORT_get_hello_cancel (p3.th, &exchange_hello_last, me); 399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
400 "Disconnecting transports...\n");
282 401
283 GNUNET_assert (message != NULL); 402 if (p1.th != NULL)
284 GNUNET_assert (GNUNET_OK == 403 {
285 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 404 GNUNET_TRANSPORT_disconnect (p1.th);
286 message, &me->id)); 405 p1.th = NULL;
406 }
407
408 if (p2.th != NULL)
409 {
410 GNUNET_TRANSPORT_disconnect (p2.th);
411 p2.th = NULL;
412 }
413
414 if (p3.th != NULL)
415 {
416 GNUNET_TRANSPORT_disconnect (p3.th);
417 p3.th = NULL;
418 }
419
420 if (p4.th != NULL)
421 {
422 GNUNET_TRANSPORT_disconnect (p4.th);
423 p4.th = NULL;
424 }
425
426 sleep(1);
287 427
288 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
289 "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message)); 429 "Restarting transport service (%p) with gnunet-arm -c %s -L DEBUG -k transport!\n", p1.arm_pid, p1.cfg_file);
430 restart_transport(&p1);
431
432 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
433 "Restarting transport service (%p) with gnunet-arm -c %s -L DEBUG -k transport!\n", p2.arm_pid, p2.cfg_file);
434 restart_transport(&p2);
290 435
291 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
292 "Finished exchanging HELLOs, now waiting for transmission!\n"); 437 "Restarting transport service (%p) with gnunet-arm -c %s -L DEBUG -k transport!\n", p3.arm_pid, p3.cfg_file);
438 restart_transport(&p3);
439
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 "Restarting transport service (%p) with gnunet-arm -c %s -L DEBUG -k transport!\n", p4.arm_pid, p4.cfg_file);
442 restart_transport(&p4);
443
444 p1.th = GNUNET_TRANSPORT_connect (sched, p1.cfg,
445 &p1,
446 &notify_receive,
447 &notify_connect, &notify_disconnect);
448
449 p2.th = GNUNET_TRANSPORT_connect (sched, p2.cfg,
450 &p2,
451 &notify_receive,
452 &notify_connect, &notify_disconnect);
453
454 p3.th = GNUNET_TRANSPORT_connect (sched, p3.cfg,
455 &p3,
456 &notify_receive,
457 &notify_connect, &notify_disconnect);
458
459 p4.th = GNUNET_TRANSPORT_connect (sched, p4.cfg,
460 &p4,
461 &notify_receive,
462 &notify_connect, &notify_disconnect);
463 GNUNET_assert(p1.th != NULL);
464 GNUNET_assert(p2.th != NULL);
465 GNUNET_assert(p3.th != NULL);
466 GNUNET_assert(p4.th != NULL);
467
468 GNUNET_TRANSPORT_offer_hello (p1.th, GNUNET_HELLO_get_header(p2.hello));
469 GNUNET_TRANSPORT_offer_hello (p2.th, GNUNET_HELLO_get_header(p3.hello));
470 GNUNET_TRANSPORT_offer_hello (p3.th, GNUNET_HELLO_get_header(p4.hello));
293 471
294} 472}
295 473
296 474
297static void 475static void
298exchange_hello_next (void *cls, 476get_hello_fourth (void *cls,
299 const struct GNUNET_MessageHeader *message) 477 const struct GNUNET_MessageHeader *message)
300{ 478{
301 struct PeerContext *me = cls; 479 struct PeerContext *me = cls;
302 480
303 GNUNET_TRANSPORT_get_hello_cancel (p2.th, &exchange_hello_next, me); 481 GNUNET_TRANSPORT_get_hello_cancel (me->th, &get_hello_fourth, me);
304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
305 "Exchanging HELLO with peer (%p)!\n", cls);
306 482
307 GNUNET_assert (message != NULL); 483 GNUNET_assert (message != NULL);
308 GNUNET_assert (GNUNET_OK == 484 GNUNET_assert (GNUNET_OK ==
@@ -312,30 +488,23 @@ exchange_hello_next (void *cls,
312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
313 "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message)); 489 "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
314 490
315 GNUNET_TRANSPORT_offer_hello (p3.th, message); 491 me->hello = GNUNET_malloc(GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
316 492 memcpy(me->hello, message, GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
317 GNUNET_TRANSPORT_get_hello (p3.th, &exchange_hello_last, &p3);
318 493
494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
495 "All HELLO's received, setting up blacklists!\n");
319 496
497 GNUNET_SCHEDULER_add_now(sched, &setup_blacklists, NULL);
320} 498}
321 499
322 500
323static void 501static void
324exchange_hello (void *cls, 502get_hello_third (void *cls,
325 const struct GNUNET_MessageHeader *message) 503 const struct GNUNET_MessageHeader *message)
326{ 504{
327 struct PeerContext *me = cls; 505 struct PeerContext *me = cls;
328 506
329 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &exchange_hello, me); 507 GNUNET_TRANSPORT_get_hello_cancel (me->th, &get_hello_third, me);
330 p2.th = GNUNET_TRANSPORT_connect (sched, p2.cfg,
331 &p2,
332 &notify_receive,
333 &notify_connect, &notify_disconnect);
334
335 GNUNET_assert(p2.th != NULL);
336
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
338 "Exchanging HELLO with peer (%p)!\n", cls);
339 508
340 GNUNET_assert (message != NULL); 509 GNUNET_assert (message != NULL);
341 GNUNET_assert (GNUNET_OK == 510 GNUNET_assert (GNUNET_OK ==
@@ -345,118 +514,57 @@ exchange_hello (void *cls,
345 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
346 "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message)); 515 "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
347 516
348 GNUNET_TRANSPORT_offer_hello (p2.th, message); 517 me->hello = GNUNET_malloc(GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
349 GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_next, &p2); 518 memcpy(me->hello, message, GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
519
520 GNUNET_TRANSPORT_get_hello (p4.th, &get_hello_fourth, &p4);
350} 521}
351 522
523
352static void 524static void
353blacklist_setup_third (void *cls, 525get_hello_second (void *cls,
354 const struct GNUNET_MessageHeader *message) 526 const struct GNUNET_MessageHeader *message)
355{ 527{
356 struct PeerContext *me = cls; 528 struct PeerContext *me = cls;
357 char *blacklist_filename;
358 struct GNUNET_DISK_FileHandle *file;
359 struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
360 char *buf;
361 size_t size;
362 529
363 GNUNET_TRANSPORT_get_hello_cancel (p3.th, &blacklist_setup_third, &p3); 530 GNUNET_TRANSPORT_get_hello_cancel (me->th, &get_hello_second, me);
364 531
365 GNUNET_assert (message != NULL); 532 GNUNET_assert (message != NULL);
366 GNUNET_assert (GNUNET_OK == 533 GNUNET_assert (GNUNET_OK ==
367 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 534 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
368 message, &me->id)); 535 message, &me->id));
369 536
370 GNUNET_asprintf(&blacklist_filename, "/tmp/test-gnunetd-transport-peer-1/blacklist");
371 if (blacklist_filename != NULL)
372 {
373 file = GNUNET_DISK_file_open(blacklist_filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | GNUNET_DISK_OPEN_CREATE,
374 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
375 GNUNET_free(blacklist_filename);
376
377 if (file == NULL)
378 {
379 GNUNET_SCHEDULER_cancel(sched, die_task);
380 GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL);
381 return;
382 }
383 GNUNET_CRYPTO_hash_to_enc(&me->id.hashPubKey, &peer_enc);
384 size = GNUNET_asprintf(&buf, "%s:%s\n", "tcp", (char *)&peer_enc);
385 GNUNET_DISK_file_write(file, buf, size);
386 GNUNET_free_non_null(buf);
387 }
388
389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
390 "Restarting transport service (%p) with gnunet-arm -c %s -L DEBUG -k transport!\n", cls, p1.cfg_file); 538 "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
391
392 restart_transport(&p1);
393 539
394 p1.th = GNUNET_TRANSPORT_connect (sched, p1.cfg, 540 me->hello = GNUNET_malloc(GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
395 &p1, 541 memcpy(me->hello, message, GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
396 &notify_receive,
397 &notify_connect, &notify_disconnect);
398 542
399 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); 543 GNUNET_TRANSPORT_get_hello (p3.th, &get_hello_third, &p3);
400} 544}
401 545
546
402static void 547static void
403blacklist_setup_first (void *cls, 548get_hello_first (void *cls,
404 const struct GNUNET_MessageHeader *message) 549 const struct GNUNET_MessageHeader *message)
405{ 550{
406 struct PeerContext *me = cls; 551 struct PeerContext *me = cls;
407 char *blacklist_filename;
408 struct GNUNET_DISK_FileHandle *file;
409 struct GNUNET_CRYPTO_HashAsciiEncoded peer_enc;
410 char *buf;
411 size_t size;
412 552
413 GNUNET_TRANSPORT_get_hello_cancel (p1.th, &blacklist_setup_first, me); 553 GNUNET_TRANSPORT_get_hello_cancel (me->th, &get_hello_first, me);
414 sleep(2);
415 554
416 GNUNET_assert (message != NULL); 555 GNUNET_assert (message != NULL);
417 GNUNET_assert (GNUNET_OK == 556 GNUNET_assert (GNUNET_OK ==
418 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) 557 GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *)
419 message, &me->id)); 558 message, &me->id));
420 559
421 GNUNET_asprintf(&blacklist_filename, "/tmp/test-gnunetd-transport-peer-3/blacklist");
422 if (blacklist_filename != NULL)
423 {
424 file = GNUNET_DISK_file_open(blacklist_filename, GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | GNUNET_DISK_OPEN_CREATE,
425 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
426 GNUNET_free(blacklist_filename);
427
428 if (file == NULL)
429 {
430 GNUNET_SCHEDULER_cancel(sched, die_task);
431 GNUNET_SCHEDULER_add_now(sched, &end_badly, NULL);
432 return;
433 }
434 GNUNET_CRYPTO_hash_to_enc(&me->id.hashPubKey, &peer_enc);
435 size = GNUNET_asprintf(&buf, "%s:%s\n", "tcp", (char *)&peer_enc);
436 GNUNET_DISK_file_write(file, buf, size);
437 GNUNET_free_non_null(buf);
438 }
439
440 GNUNET_TRANSPORT_disconnect(p1.th);
441
442 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 560 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
443 "Restarting transport service (%p) with gnunet-arm -c %s -L DEBUG -k transport!\n", cls, p3.cfg_file); 561 "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
444 restart_transport(&p3);
445 562
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 563 me->hello = GNUNET_malloc(GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
447 "reconnecting to transport (%p)!\n", cls); 564 memcpy(me->hello, message, GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message));
448 p3.th = GNUNET_TRANSPORT_connect (sched, p3.cfg,
449 &p3,
450 &notify_receive,
451 &notify_connect, &notify_disconnect);
452 if (p3.th != NULL)
453 GNUNET_TRANSPORT_get_hello (p3.th, &blacklist_setup_third, &p3);
454 else
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
456 "reconnecting to transport (%p) failed.!\n", cls);
457 //GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
458}
459 565
566 GNUNET_TRANSPORT_get_hello (p2.th, &get_hello_second, &p2);
567}
460 568
461static void 569static void
462run (void *cls, 570run (void *cls,
@@ -474,16 +582,33 @@ run (void *cls,
474 setup_peer (&p1, "test_transport_api_dv_peer1.conf"); 582 setup_peer (&p1, "test_transport_api_dv_peer1.conf");
475 setup_peer (&p2, "test_transport_api_dv_peer2.conf"); 583 setup_peer (&p2, "test_transport_api_dv_peer2.conf");
476 setup_peer (&p3, "test_transport_api_dv_peer3.conf"); 584 setup_peer (&p3, "test_transport_api_dv_peer3.conf");
585 setup_peer (&p4, "test_transport_api_dv_peer4.conf");
477 586
478 p1.th = GNUNET_TRANSPORT_connect (sched, p1.cfg, 587 p1.th = GNUNET_TRANSPORT_connect (sched, p1.cfg,
479 &p1, 588 &p1,
480 &notify_receive, 589 &notify_receive,
481 &notify_connect, &notify_disconnect); 590 &notify_connect, &notify_disconnect);
591
592 p2.th = GNUNET_TRANSPORT_connect (sched, p2.cfg,
593 &p2,
594 &notify_receive,
595 &notify_connect, &notify_disconnect);
596
597 p3.th = GNUNET_TRANSPORT_connect (sched, p3.cfg,
598 &p3,
599 &notify_receive,
600 &notify_connect, &notify_disconnect);
601
602 p4.th = GNUNET_TRANSPORT_connect (sched, p4.cfg,
603 &p4,
604 &notify_receive,
605 &notify_connect, &notify_disconnect);
482 GNUNET_assert(p1.th != NULL); 606 GNUNET_assert(p1.th != NULL);
483 /*GNUNET_assert(p2.th != NULL); 607 GNUNET_assert(p2.th != NULL);
484 GNUNET_assert(p3.th != NULL);*/ 608 GNUNET_assert(p3.th != NULL);
609 GNUNET_assert(p4.th != NULL);
485 610
486 GNUNET_TRANSPORT_get_hello (p1.th, &blacklist_setup_first, &p1); 611 GNUNET_TRANSPORT_get_hello (p1.th, &get_hello_first, &p1);
487} 612}
488 613
489static int 614static int
@@ -510,6 +635,7 @@ check ()
510 stop_arm (&p1); 635 stop_arm (&p1);
511 stop_arm (&p2); 636 stop_arm (&p2);
512 stop_arm (&p3); 637 stop_arm (&p3);
638 stop_arm (&p4);
513 return ok; 639 return ok;
514} 640}
515 641
@@ -533,7 +659,9 @@ main (int argc, char *argv[])
533 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1"); 659 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-1");
534 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2"); 660 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-2");
535 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-3"); 661 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-3");
662 GNUNET_DISK_directory_remove ("/tmp/test-gnunetd-transport-peer-4");
536 return ret; 663 return ret;
537} 664}
538 665
539/* end of test_transport_api_dv.c */ 666/* end of test_transport_api_dv.c */
667
diff --git a/src/dv/test_transport_api_dv_peer4.conf b/src/dv/test_transport_api_dv_peer4.conf
new file mode 100644
index 000000000..4b569f62a
--- /dev/null
+++ b/src/dv/test_transport_api_dv_peer4.conf
@@ -0,0 +1,111 @@
1[topology]
2BINARY = gnunet-daemon-topology
3CONFIG = $DEFAULTCONFIG
4FRIENDS = $SERVICEHOME/friends
5TARGET-CONNECTION-COUNT = 16
6AUTOCONNECT = YES
7FRIENDS-ONLY = NO
8MINIMUM-FRIENDS = 0
9
10[transport]
11PLUGINS = tcp dv
12DEBUG = NO
13ALLOW_SHUTDOWN = YES
14ACCEPT_FROM6 = ::1;
15ACCEPT_FROM = 127.0.0.1;
16NEIGHBOUR_LIMIT = 50
17#BINARY = /root/documents/research/gnunet/gnunet-ng/src/transport/.libs/gnunet-service-transport
18BINARY = gnunet-service-transport
19#BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/transport/.libs/gnunet-service-transport
20CONFIG = $DEFAULTCONFIG
21HOME = $SERVICEHOME
22HOSTNAME = localhost
23PORT = 42365
24#PREFIX = xterm -T transport1 -e gdb --args
25#PREFIX = valgrind --leak-check=full
26BLACKLIST_FILE = $SERVICEHOME/blacklist
27
28[peerinfo]
29TRUST = $SERVICEHOME/data/credit/
30HOSTS = $SERVICEHOME/data/hosts/
31ALLOW_SHUTDOWN = YES
32ACCEPT_FROM6 = ::1;
33ACCEPT_FROM = 127.0.0.1;
34BINARY = gnunet-service-peerinfo
35CONFIG = $DEFAULTCONFIG
36HOME = $SERVICEHOME
37HOSTNAME = localhost
38PORT = 42369
39
40[resolver]
41ALLOW_SHUTDOWN = YES
42ACCEPT_FROM6 = ::1;
43ACCEPT_FROM = 127.0.0.1;
44BINARY = gnunet-service-resolver
45CONFIG = $DEFAULTCONFIG
46HOME = $SERVICEHOME
47HOSTNAME = localhost
48PORT = 42364
49
50[core]
51TOTAL_QUOTA_OUT = 3932160
52TOTAL_QUOTA_IN = 3932160
53ALLOW_SHUTDOWN = YES
54ACCEPT_FROM6 = ::1;
55ACCEPT_FROM = 127.0.0.1;
56BINARY = gnunet-service-core
57CONFIG = $DEFAULTCONFIG
58HOME = $SERVICEHOME
59HOSTNAME = localhost
60PORT = 42092
61
62[statistics]
63ALLOW_SHUTDOWN = YES
64ACCEPT_FROM6 = ::1;
65ACCEPT_FROM = 127.0.0.1;
66BINARY = gnunet-service-statistics
67CONFIG = $DEFAULTCONFIG
68HOME = $SERVICEHOME
69HOSTNAME = localhost
70PORT = 42367
71
72[dv]
73DEBUG = NO
74ALLOW_SHUTDOWN = YES
75ACCEPT_FROM6 = ::1;
76ACCEPT_FROM = 127.0.0.1;
77BINARY = gnunet-service-dv
78BINARY = /home/mrwiggles/documents/research/gnunet/gnunet-ng/src/dv/.libs/gnunet-service-dv
79#PREFIX = xterm -T dvservice4 -e gdb --args
80#PREFIX = valgrind --log-file=dv4-%p --leak-check=full --show-reachable=yes
81CONFIG = $DEFAULTCONFIG
82HOME = $SERVICEHOME
83HOSTNAME = localhost
84PORT = 42370
85
86[arm]
87DEFAULTSERVICES = core dv statistics
88ALLOW_SHUTDOWN = YES
89ACCEPT_FROM6 = ::1;
90ACCEPT_FROM = 127.0.0.1;
91BINARY = gnunet-service-arm
92CONFIG = $DEFAULTCONFIG
93HOME = $SERVICEHOME
94HOSTNAME = localhost
95PORT = 42366
96
97[transport-tcp]
98ALLOW_SHUTDOWN = NO
99TIMEOUT = 300000
100PORT = 42368
101
102[TESTING]
103WEAKRANDOM = YES
104
105[gnunetd]
106HOSTKEY = $SERVICEHOME/.hostkey
107
108[PATHS]
109DEFAULTCONFIG = test_transport_api_dv_peer4.conf
110SERVICEHOME = /tmp/test-gnunetd-transport-peer-4/
111