diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-09-29 21:42:52 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-09-29 21:42:52 +0000 |
commit | bf698bec316cc81861df372d40d81ee32cdfec4a (patch) | |
tree | 877b9132c8d34362063ccf6f66805213d68dcfcc /src/mesh | |
parent | bd62a37da1a7d0936e189c885b6c58866a169663 (diff) | |
download | gnunet-bf698bec316cc81861df372d40d81ee32cdfec4a.tar.gz gnunet-bf698bec316cc81861df372d40d81ee32cdfec4a.zip |
WiP
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/Makefile.am | 12 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 30 | ||||
-rw-r--r-- | src/mesh/small.dat | 21 | ||||
-rw-r--r-- | src/mesh/test_mesh_small.conf | 16 | ||||
-rw-r--r-- | src/mesh/test_mesh_small_unicast.c | 577 |
5 files changed, 641 insertions, 15 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am index a79958832..1f43b66d4 100644 --- a/src/mesh/Makefile.am +++ b/src/mesh/Makefile.am | |||
@@ -53,7 +53,8 @@ check_PROGRAMS = \ | |||
53 | test_mesh_path_api \ | 53 | test_mesh_path_api \ |
54 | test_mesh_local_1 \ | 54 | test_mesh_local_1 \ |
55 | test_mesh_local_2 \ | 55 | test_mesh_local_2 \ |
56 | test_mesh_small | 56 | test_mesh_small \ |
57 | test_mesh_small_unicast | ||
57 | 58 | ||
58 | test_mesh_api_SOURCES = \ | 59 | test_mesh_api_SOURCES = \ |
59 | test_mesh_api.c | 60 | test_mesh_api.c |
@@ -98,6 +99,15 @@ test_mesh_small_LDADD = \ | |||
98 | test_mesh_small_DEPENDENCIES = \ | 99 | test_mesh_small_DEPENDENCIES = \ |
99 | libgnunetmeshnew.la | 100 | libgnunetmeshnew.la |
100 | 101 | ||
102 | test_mesh_small_unicast_SOURCES = \ | ||
103 | test_mesh_small_unicast.c | ||
104 | test_mesh_small_unicast_LDADD = \ | ||
105 | $(top_builddir)/src/mesh/libgnunetmeshnew.la \ | ||
106 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
107 | $(top_builddir)/src/testing/libgnunettesting.la | ||
108 | test_mesh_small_unicast_DEPENDENCIES = \ | ||
109 | libgnunetmeshnew.la | ||
110 | |||
101 | if ENABLE_TEST_RUN | 111 | if ENABLE_TEST_RUN |
102 | if HAVE_EXPERIMENTAL | 112 | if HAVE_EXPERIMENTAL |
103 | TESTS = test_mesh_api test_mesh_path_api test_mesh_local_1 test_mesh_local_2 | 113 | TESTS = test_mesh_api test_mesh_path_api test_mesh_local_1 test_mesh_local_2 |
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 670c2f973..0d3d0211b 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -60,7 +60,7 @@ | |||
60 | 60 | ||
61 | #define ID_ANNOUNCE_TIME GNUNET_TIME_relative_multiply(\ | 61 | #define ID_ANNOUNCE_TIME GNUNET_TIME_relative_multiply(\ |
62 | GNUNET_TIME_UNIT_SECONDS,\ | 62 | GNUNET_TIME_UNIT_SECONDS,\ |
63 | 5) | 63 | 10) |
64 | 64 | ||
65 | 65 | ||
66 | /******************************************************************************/ | 66 | /******************************************************************************/ |
@@ -549,13 +549,15 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
549 | * - Set data expiration in function of X | 549 | * - Set data expiration in function of X |
550 | * - Adapt X to churn | 550 | * - Adapt X to churn |
551 | */ | 551 | */ |
552 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: DHT_put for ID %s started.\n", | ||
553 | GNUNET_h2s_full (&my_full_id.hashPubKey)); | ||
552 | GNUNET_DHT_put (dht_handle, /* DHT handle */ | 554 | GNUNET_DHT_put (dht_handle, /* DHT handle */ |
553 | &my_full_id.hashPubKey, /* Key to use */ | 555 | &my_full_id.hashPubKey, /* Key to use */ |
554 | 10U, /* Replication level */ | 556 | 10U, /* Replication level */ |
555 | GNUNET_DHT_RO_RECORD_ROUTE, /* DHT options */ | 557 | GNUNET_DHT_RO_RECORD_ROUTE, /* DHT options */ |
556 | GNUNET_BLOCK_TYPE_TEST, /* Block type */ | 558 | GNUNET_BLOCK_TYPE_TEST, /* Block type */ |
557 | 0, /* Size of the data */ | 559 | sizeof(my_full_id), /* Size of the data */ |
558 | NULL, /* Data itself */ | 560 | &my_full_id, /* Data itself */ |
559 | GNUNET_TIME_absolute_get_forever (), /* Data expiration */ | 561 | GNUNET_TIME_absolute_get_forever (), /* Data expiration */ |
560 | GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */ | 562 | GNUNET_TIME_UNIT_FOREVER_REL, /* Retry time */ |
561 | #if MESH_DEBUG | 563 | #if MESH_DEBUG |
@@ -2090,13 +2092,16 @@ dht_get_id_handler (void *cls, struct GNUNET_TIME_Absolute exp, | |||
2090 | struct GNUNET_PeerIdentity pi; | 2092 | struct GNUNET_PeerIdentity pi; |
2091 | int i; | 2093 | int i; |
2092 | 2094 | ||
2095 | GNUNET_PEER_resolve (path_info->peer->id, &pi); | ||
2096 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
2097 | "MESH: Got results from DHT for %s\n", | ||
2098 | GNUNET_h2s_full(&pi.hashPubKey)); | ||
2093 | if (NULL == get_path || NULL == put_path) | 2099 | if (NULL == get_path || NULL == put_path) |
2094 | { | 2100 | { |
2095 | if (NULL == path_info->peer->path_head) | 2101 | if (NULL == path_info->peer->path_head) |
2096 | { | 2102 | { |
2097 | // Find ourselves some alternate initial path to the destination: retry | 2103 | // Find ourselves some alternate initial path to the destination: retry |
2098 | GNUNET_DHT_get_stop (path_info->peer->dhtget); | 2104 | GNUNET_DHT_get_stop (path_info->peer->dhtget); |
2099 | GNUNET_PEER_resolve (path_info->peer->id, &pi); | ||
2100 | path_info->peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ | 2105 | path_info->peer->dhtget = GNUNET_DHT_get_start (dht_handle, /* handle */ |
2101 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 2106 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ |
2102 | GNUNET_BLOCK_TYPE_TEST, /* type */ | 2107 | GNUNET_BLOCK_TYPE_TEST, /* type */ |
@@ -2565,7 +2570,7 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client, | |||
2565 | MESH_TunnelNumber tid; | 2570 | MESH_TunnelNumber tid; |
2566 | struct MeshPeerInfo *peer_info; | 2571 | struct MeshPeerInfo *peer_info; |
2567 | 2572 | ||
2568 | 2573 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n"); | |
2569 | /* Sanity check for client registration */ | 2574 | /* Sanity check for client registration */ |
2570 | if (NULL == (c = client_get (client))) | 2575 | if (NULL == (c = client_get (client))) |
2571 | { | 2576 | { |
@@ -2600,7 +2605,8 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client, | |||
2600 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2605 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2601 | return; | 2606 | return; |
2602 | } | 2607 | } |
2603 | 2608 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: for %s\n", | |
2609 | GNUNET_h2s_full(&peer_msg->peer.hashPubKey)); | ||
2604 | peer_info = peer_info_get (&peer_msg->peer); | 2610 | peer_info = peer_info_get (&peer_msg->peer); |
2605 | 2611 | ||
2606 | /* Start DHT search if needed, otherwise just add peer to tunnel. */ | 2612 | /* Start DHT search if needed, otherwise just add peer to tunnel. */ |
@@ -2995,17 +3001,23 @@ static void | |||
2995 | core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | 3001 | core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, |
2996 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 3002 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
2997 | { | 3003 | { |
2998 | // GNUNET_PEER_Id pid; | ||
2999 | struct MeshPeerInfo *peer_info; | 3004 | struct MeshPeerInfo *peer_info; |
3000 | struct MeshPeerPath *path; | 3005 | struct MeshPeerPath *path; |
3001 | 3006 | ||
3002 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n"); | 3007 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: Peer connected\n"); |
3008 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", | ||
3009 | // GNUNET_h2s(&my_full_id.hashPubKey)); | ||
3003 | peer_info = peer_info_get (peer); | 3010 | peer_info = peer_info_get (peer); |
3004 | if (myid == peer_info->id) | 3011 | if (myid == peer_info->id) |
3005 | { | 3012 | { |
3006 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (self)\n"); | 3013 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (self)\n"); |
3007 | return; | 3014 | return; |
3008 | } | 3015 | } |
3016 | else | ||
3017 | { | ||
3018 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: %s\n", | ||
3019 | // GNUNET_h2s(&peer->hashPubKey)); | ||
3020 | } | ||
3009 | path = path_new (2); | 3021 | path = path_new (2); |
3010 | path->peers[0] = myid; | 3022 | path->peers[0] = myid; |
3011 | path->peers[1] = peer_info->id; | 3023 | path->peers[1] = peer_info->id; |
diff --git a/src/mesh/small.dat b/src/mesh/small.dat new file mode 100644 index 000000000..c3805ee80 --- /dev/null +++ b/src/mesh/small.dat | |||
@@ -0,0 +1,21 @@ | |||
1 | 16 | ||
2 | 1:2 | ||
3 | 1:9 | ||
4 | 2:3 | ||
5 | 3:4 | ||
6 | 3:11 | ||
7 | 4:5 | ||
8 | 5:6 | ||
9 | 5:13 | ||
10 | 6:7 | ||
11 | 7:8 | ||
12 | 7:15 | ||
13 | 8:9 | ||
14 | 9:10 | ||
15 | 10:11 | ||
16 | 11:12 | ||
17 | 12:13 | ||
18 | 13:14 | ||
19 | 14:15 | ||
20 | 15:16 | ||
21 | 16:1 | ||
diff --git a/src/mesh/test_mesh_small.conf b/src/mesh/test_mesh_small.conf index 2a834f6bd..84e281bd1 100644 --- a/src/mesh/test_mesh_small.conf +++ b/src/mesh/test_mesh_small.conf | |||
@@ -12,7 +12,11 @@ AUTOSTART = YES | |||
12 | PORT = 10000 | 12 | PORT = 10000 |
13 | 13 | ||
14 | [dht] | 14 | [dht] |
15 | AUTOSTART = NO | 15 | DEBUG = NO |
16 | AUTOSTART = YES | ||
17 | ACCEPT_FROM6 = ::1; | ||
18 | ACCEPT_FROM = 127.0.0.1; | ||
19 | HOSTNAME = localhost | ||
16 | PORT = 10001 | 20 | PORT = 10001 |
17 | 21 | ||
18 | [dns] | 22 | [dns] |
@@ -42,12 +46,14 @@ PORT = 10004 | |||
42 | 46 | ||
43 | [mesh] | 47 | [mesh] |
44 | PORT = 10005 | 48 | PORT = 10005 |
49 | DEBUG=YES | ||
45 | 50 | ||
46 | [testing] | 51 | [testing] |
47 | NUM_PEERS = 16 | 52 | NUM_PEERS = 16 |
48 | WEAKRANDOM = YES | 53 | WEAKRANDOM = YES |
49 | TOPOLOGY = NONE | 54 | TOPOLOGY = CLIQUE |
50 | CONNECT_TOPOLOGY = RING | 55 | CONNECT_TOPOLOGY = NONE |
56 | TOPOLOGY_FILE = small.dat | ||
51 | #CONNECT_TOPOLOGY = ERDOS_RENYI | 57 | #CONNECT_TOPOLOGY = ERDOS_RENYI |
52 | #CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM | 58 | #CONNECT_TOPOLOGY_OPTION = CONNECT_MINIMUM |
53 | #CONNECT_TOPOLOGY_OPTION_MODIFIER = 25 | 59 | #CONNECT_TOPOLOGY_OPTION_MODIFIER = 25 |
@@ -70,6 +76,6 @@ MAX_OUTSTANDING_CONNECTIONS = 75 | |||
70 | DELETE_FILES = YES | 76 | DELETE_FILES = YES |
71 | 77 | ||
72 | [test_mesh_small] | 78 | [test_mesh_small] |
73 | WAIT_TIME = 2 | 79 | WAIT_TIME = 60 |
74 | CONNECTION_LIMIT = 10 | 80 | CONNECTION_LIMIT = 10 |
75 | DATA_OUTPUT_FILE=data_output \ No newline at end of file | 81 | DATA_OUTPUT_FILE=data_output |
diff --git a/src/mesh/test_mesh_small_unicast.c b/src/mesh/test_mesh_small_unicast.c new file mode 100644 index 000000000..4cd07c095 --- /dev/null +++ b/src/mesh/test_mesh_small_unicast.c | |||
@@ -0,0 +1,577 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2011 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 3, 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 mesh/test_mesh_small_unicast.c | ||
22 | * | ||
23 | * @brief Test for the mesh service: retransmission of unicast traffic. | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_testing_lib.h" | ||
27 | #include "gnunet_mesh_service_new.h" | ||
28 | |||
29 | #define VERBOSE GNUNET_YES | ||
30 | #define REMOVE_DIR GNUNET_YES | ||
31 | |||
32 | struct MeshPeer | ||
33 | { | ||
34 | struct MeshPeer *prev; | ||
35 | |||
36 | struct MeshPeer *next; | ||
37 | |||
38 | struct GNUNET_TESTING_Daemon *daemon; | ||
39 | |||
40 | struct GNUNET_MESH_Handle *mesh_handle; | ||
41 | }; | ||
42 | |||
43 | |||
44 | struct StatsContext | ||
45 | { | ||
46 | unsigned long long total_mesh_bytes; | ||
47 | }; | ||
48 | |||
49 | |||
50 | // static struct MeshPeer *peer_head; | ||
51 | // | ||
52 | // static struct MeshPeer *peer_tail; | ||
53 | |||
54 | /** | ||
55 | * How long until we give up on connecting the peers? | ||
56 | */ | ||
57 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1500) | ||
58 | |||
59 | static int ok; | ||
60 | |||
61 | /** | ||
62 | * Be verbose | ||
63 | */ | ||
64 | static int verbose; | ||
65 | |||
66 | /** | ||
67 | * Total number of peers in the test. | ||
68 | */ | ||
69 | static unsigned long long num_peers; | ||
70 | |||
71 | /** | ||
72 | * Global configuration file | ||
73 | */ | ||
74 | static struct GNUNET_CONFIGURATION_Handle *testing_cfg; | ||
75 | |||
76 | /** | ||
77 | * Total number of currently running peers. | ||
78 | */ | ||
79 | static unsigned long long peers_running; | ||
80 | |||
81 | /** | ||
82 | * Total number of connections in the whole network. | ||
83 | */ | ||
84 | static unsigned int total_connections; | ||
85 | |||
86 | /** | ||
87 | * The currently running peer group. | ||
88 | */ | ||
89 | static struct GNUNET_TESTING_PeerGroup *pg; | ||
90 | |||
91 | /** | ||
92 | * File to report results to. | ||
93 | */ | ||
94 | static struct GNUNET_DISK_FileHandle *output_file; | ||
95 | |||
96 | /** | ||
97 | * File to log connection info, statistics to. | ||
98 | */ | ||
99 | static struct GNUNET_DISK_FileHandle *data_file; | ||
100 | |||
101 | /** | ||
102 | * How many data points to capture before triggering next round? | ||
103 | */ | ||
104 | static struct GNUNET_TIME_Relative wait_time; | ||
105 | |||
106 | /** | ||
107 | * Task called to disconnect peers. | ||
108 | */ | ||
109 | static GNUNET_SCHEDULER_TaskIdentifier disconnect_task; | ||
110 | |||
111 | /** | ||
112 | * Task To perform tests | ||
113 | */ | ||
114 | static GNUNET_SCHEDULER_TaskIdentifier test_task; | ||
115 | |||
116 | /** | ||
117 | * Task called to shutdown test. | ||
118 | */ | ||
119 | static GNUNET_SCHEDULER_TaskIdentifier shutdown_handle; | ||
120 | |||
121 | static char *topology_file; | ||
122 | |||
123 | static char *data_filename; | ||
124 | |||
125 | struct GNUNET_TESTING_Daemon *d1; | ||
126 | |||
127 | struct GNUNET_TESTING_Daemon *d2; | ||
128 | |||
129 | struct GNUNET_MESH_Handle *h1; | ||
130 | |||
131 | struct GNUNET_MESH_Handle *h2; | ||
132 | |||
133 | struct GNUNET_MESH_Tunnel *t; | ||
134 | |||
135 | /** | ||
136 | * Check whether peers successfully shut down. | ||
137 | */ | ||
138 | static void | ||
139 | shutdown_callback (void *cls, const char *emsg) | ||
140 | { | ||
141 | if (emsg != NULL) | ||
142 | { | ||
143 | #if VERBOSE | ||
144 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Shutdown of peers failed!\n"); | ||
145 | #endif | ||
146 | ok++; | ||
147 | } | ||
148 | else | ||
149 | { | ||
150 | #if VERBOSE | ||
151 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: All peers successfully shut down!\n"); | ||
152 | #endif | ||
153 | } | ||
154 | } | ||
155 | |||
156 | |||
157 | static void | ||
158 | shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
159 | { | ||
160 | #if VERBOSE | ||
161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Ending test.\n"); | ||
162 | #endif | ||
163 | |||
164 | if (disconnect_task != GNUNET_SCHEDULER_NO_TASK) | ||
165 | { | ||
166 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
167 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
168 | } | ||
169 | |||
170 | if (data_file != NULL) | ||
171 | GNUNET_DISK_file_close (data_file); | ||
172 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
173 | GNUNET_CONFIGURATION_destroy (testing_cfg); | ||
174 | } | ||
175 | |||
176 | |||
177 | /** | ||
178 | * Handlers, for diverse services | ||
179 | */ | ||
180 | static struct GNUNET_MESH_MessageHandler handlers[] = { | ||
181 | // {&callback, 1, 0}, | ||
182 | {NULL, 0, 0} | ||
183 | }; | ||
184 | |||
185 | |||
186 | /** | ||
187 | * Method called whenever another peer has added us to a tunnel | ||
188 | * the other peer initiated. | ||
189 | * | ||
190 | * @param cls closure | ||
191 | * @param tunnel new handle to the tunnel | ||
192 | * @param initiator peer that started the tunnel | ||
193 | * @param atsi performance information for the tunnel | ||
194 | * @return initial tunnel context for the tunnel | ||
195 | * (can be NULL -- that's not an error) | ||
196 | */ | ||
197 | static void * | ||
198 | incoming_tunnel (void *cls, | ||
199 | struct GNUNET_MESH_Tunnel * tunnel, | ||
200 | const struct GNUNET_PeerIdentity * initiator, | ||
201 | const struct GNUNET_TRANSPORT_ATS_Information * atsi) | ||
202 | { | ||
203 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
204 | "test: Incoming tunnel from %s\n", | ||
205 | GNUNET_h2s(&initiator->hashPubKey)); | ||
206 | GNUNET_MESH_tunnel_destroy(t); | ||
207 | ok = 0; | ||
208 | return NULL; | ||
209 | } | ||
210 | |||
211 | /** | ||
212 | * Function called whenever an inbound tunnel is destroyed. Should clean up | ||
213 | * any associated state. | ||
214 | * | ||
215 | * @param cls closure (set from GNUNET_MESH_connect) | ||
216 | * @param tunnel connection to the other end (henceforth invalid) | ||
217 | * @param tunnel_ctx place where local state associated | ||
218 | * with the tunnel is stored | ||
219 | */ | ||
220 | static void | ||
221 | tunnel_cleaner (void *cls, const struct GNUNET_MESH_Tunnel *tunnel, | ||
222 | void *tunnel_ctx) | ||
223 | { | ||
224 | #if VERBOSE | ||
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: tunnel disconnected\n"); | ||
226 | #endif | ||
227 | |||
228 | return; | ||
229 | } | ||
230 | |||
231 | /** | ||
232 | * Method called whenever a tunnel falls apart. | ||
233 | * | ||
234 | * @param cls closure | ||
235 | * @param peer peer identity the tunnel stopped working with | ||
236 | */ | ||
237 | static void | ||
238 | dh (void *cls, const struct GNUNET_PeerIdentity *peer) | ||
239 | { | ||
240 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer disconnected\n"); | ||
241 | return; | ||
242 | } | ||
243 | |||
244 | |||
245 | /** | ||
246 | * Method called whenever a tunnel is established. | ||
247 | * | ||
248 | * @param cls closure | ||
249 | * @param peer peer identity the tunnel was created to, NULL on timeout | ||
250 | * @param atsi performance data for the connection | ||
251 | */ | ||
252 | static void | ||
253 | ch (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
254 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | ||
255 | { | ||
256 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: peer connected\n"); | ||
257 | return; | ||
258 | } | ||
259 | |||
260 | |||
261 | static void | ||
262 | disconnect_mesh_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
263 | { | ||
264 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
265 | "test: disconnecting mesh service of peers\n"); | ||
266 | disconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
267 | GNUNET_MESH_disconnect(h1); | ||
268 | GNUNET_MESH_disconnect(h2); | ||
269 | GNUNET_SCHEDULER_cancel (shutdown_handle); | ||
270 | shutdown_handle = GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); | ||
271 | } | ||
272 | |||
273 | |||
274 | static void | ||
275 | do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
276 | { | ||
277 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: test_task\n"); | ||
278 | GNUNET_MESH_peer_request_connect_add(t, &d2->id); | ||
279 | GNUNET_SCHEDULER_cancel (disconnect_task); | ||
280 | disconnect_task = GNUNET_SCHEDULER_add_delayed( | ||
281 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), | ||
282 | &disconnect_mesh_peers, NULL); | ||
283 | } | ||
284 | |||
285 | |||
286 | /** | ||
287 | * connect_mesh_service: connect to the mesh service of one of the peers | ||
288 | * | ||
289 | */ | ||
290 | static void | ||
291 | connect_mesh_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
292 | { | ||
293 | GNUNET_MESH_ApplicationType app; | ||
294 | |||
295 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connect_mesh_service\n"); | ||
296 | |||
297 | d1 = GNUNET_TESTING_daemon_get (pg, 1); | ||
298 | d2 = GNUNET_TESTING_daemon_get (pg, 13); | ||
299 | app = (GNUNET_MESH_ApplicationType) 0; | ||
300 | |||
301 | #if VERBOSE | ||
302 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
303 | "test: connecting to mesh service of peer %s\n", GNUNET_i2s (&d1->id)); | ||
304 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
305 | "test: connecting to mesh service of peer %s\n", GNUNET_i2s (&d2->id)); | ||
306 | #endif | ||
307 | h1 = GNUNET_MESH_connect (d1->cfg, 10, NULL, NULL, &tunnel_cleaner, handlers, | ||
308 | &app); | ||
309 | h2 = GNUNET_MESH_connect (d2->cfg, | ||
310 | 10, | ||
311 | NULL, | ||
312 | &incoming_tunnel, | ||
313 | &tunnel_cleaner, | ||
314 | handlers, | ||
315 | &app); | ||
316 | #if VERBOSE | ||
317 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connected to mesh service of peer %s\n", | ||
318 | GNUNET_i2s (&d1->id)); | ||
319 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: connected to mesh service of peer %s\n", | ||
320 | GNUNET_i2s (&d2->id)); | ||
321 | #endif | ||
322 | t = GNUNET_MESH_tunnel_create (h1, NULL, &ch, &dh, NULL); | ||
323 | test_task = | ||
324 | GNUNET_SCHEDULER_add_delayed( | ||
325 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10), | ||
326 | &do_test, NULL); | ||
327 | } | ||
328 | |||
329 | |||
330 | |||
331 | /** | ||
332 | * peergroup_ready: start test when all peers are connected | ||
333 | * @param cls closure | ||
334 | * @param emsg error message | ||
335 | */ | ||
336 | static void | ||
337 | peergroup_ready (void *cls, const char *emsg) | ||
338 | { | ||
339 | char *buf; | ||
340 | int buf_len; | ||
341 | |||
342 | if (emsg != NULL) | ||
343 | { | ||
344 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
345 | "test: Peergroup callback called with error, aborting test!\n"); | ||
346 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
347 | "test: Error from testing: `%s'\n", emsg); | ||
348 | ok++; | ||
349 | GNUNET_TESTING_daemons_stop (pg, TIMEOUT, &shutdown_callback, NULL); | ||
350 | return; | ||
351 | } | ||
352 | #if VERBOSE | ||
353 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
354 | "************************************************************\n"); | ||
355 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
356 | "test: Peer Group started successfully!\n"); | ||
357 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
358 | "test: Have %u connections\n", | ||
359 | total_connections); | ||
360 | #endif | ||
361 | |||
362 | if (data_file != NULL) | ||
363 | { | ||
364 | buf = NULL; | ||
365 | buf_len = GNUNET_asprintf (&buf, "CONNECTIONS_0: %u\n", total_connections); | ||
366 | if (buf_len > 0) | ||
367 | GNUNET_DISK_file_write (data_file, buf, buf_len); | ||
368 | GNUNET_free (buf); | ||
369 | } | ||
370 | peers_running = GNUNET_TESTING_daemons_running (pg); | ||
371 | |||
372 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply( | ||
373 | GNUNET_TIME_UNIT_SECONDS, | ||
374 | 5), | ||
375 | &connect_mesh_service, | ||
376 | NULL); | ||
377 | disconnect_task = | ||
378 | GNUNET_SCHEDULER_add_delayed (wait_time, &disconnect_mesh_peers, NULL); | ||
379 | |||
380 | } | ||
381 | |||
382 | |||
383 | /** | ||
384 | * Function that will be called whenever two daemons are connected by | ||
385 | * the testing library. | ||
386 | * | ||
387 | * @param cls closure | ||
388 | * @param first peer id for first daemon | ||
389 | * @param second peer id for the second daemon | ||
390 | * @param distance distance between the connected peers | ||
391 | * @param first_cfg config for the first daemon | ||
392 | * @param second_cfg config for the second daemon | ||
393 | * @param first_daemon handle for the first daemon | ||
394 | * @param second_daemon handle for the second daemon | ||
395 | * @param emsg error message (NULL on success) | ||
396 | */ | ||
397 | static void | ||
398 | connect_cb (void *cls, const struct GNUNET_PeerIdentity *first, | ||
399 | const struct GNUNET_PeerIdentity *second, uint32_t distance, | ||
400 | const struct GNUNET_CONFIGURATION_Handle *first_cfg, | ||
401 | const struct GNUNET_CONFIGURATION_Handle *second_cfg, | ||
402 | struct GNUNET_TESTING_Daemon *first_daemon, | ||
403 | struct GNUNET_TESTING_Daemon *second_daemon, const char *emsg) | ||
404 | { | ||
405 | GNUNET_PEER_Id f; | ||
406 | GNUNET_PEER_Id s; | ||
407 | |||
408 | if (emsg == NULL) | ||
409 | total_connections++; | ||
410 | f = GNUNET_PEER_intern(first); | ||
411 | s = GNUNET_PEER_intern(second); | ||
412 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: New connection!\n"); | ||
413 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
414 | // "test: %s (%u)\n", | ||
415 | // GNUNET_h2s(&first->hashPubKey), | ||
416 | // f); | ||
417 | // GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
418 | // "test: %s (%u)\n", | ||
419 | // GNUNET_h2s(&second->hashPubKey), | ||
420 | // s); | ||
421 | } | ||
422 | |||
423 | |||
424 | /** | ||
425 | * run: load configuration options and schedule test to run (start peergroup) | ||
426 | * @param cls closure | ||
427 | * @param args argv | ||
428 | * @param cfgfile configuration file name (can be NULL) | ||
429 | * @param cfg configuration handle | ||
430 | */ | ||
431 | static void | ||
432 | run (void *cls, char *const *args, const char *cfgfile, | ||
433 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
434 | { | ||
435 | char *temp_str; | ||
436 | unsigned long long temp_wait; | ||
437 | struct GNUNET_TESTING_Host *hosts; | ||
438 | |||
439 | ok = 1; | ||
440 | testing_cfg = GNUNET_CONFIGURATION_dup (cfg); | ||
441 | |||
442 | GNUNET_log_setup ("test_mesh_small_unicast", | ||
443 | #if VERBOSE | ||
444 | "DEBUG", | ||
445 | #else | ||
446 | "WARNING", | ||
447 | #endif | ||
448 | NULL); | ||
449 | |||
450 | #if VERBOSE | ||
451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test: Starting daemons.\n"); | ||
452 | GNUNET_CONFIGURATION_set_value_string (testing_cfg, "testing", | ||
453 | "use_progressbars", "YES"); | ||
454 | #endif | ||
455 | |||
456 | if (GNUNET_OK != | ||
457 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", | ||
458 | "num_peers", &num_peers)) | ||
459 | { | ||
460 | GNUNET_assert (GNUNET_OK == | ||
461 | GNUNET_CONFIGURATION_load (testing_cfg, | ||
462 | "test_mesh_small.conf")); | ||
463 | if (GNUNET_OK != | ||
464 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "testing", | ||
465 | "num_peers", &num_peers)) | ||
466 | { | ||
467 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
468 | "Option TESTING:NUM_PEERS is required!\n"); | ||
469 | return; | ||
470 | } | ||
471 | } | ||
472 | |||
473 | if (GNUNET_OK != | ||
474 | GNUNET_CONFIGURATION_get_value_number (testing_cfg, "test_mesh_small", | ||
475 | "wait_time", &temp_wait)) | ||
476 | { | ||
477 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
478 | "Option test_mesh_small:wait_time is required!\n"); | ||
479 | return; | ||
480 | } | ||
481 | |||
482 | if (GNUNET_OK != | ||
483 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "testing", | ||
484 | "topology_output_file", | ||
485 | &topology_file)) | ||
486 | { | ||
487 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
488 | "Option test_mesh_small:topology_output_file is required!\n"); | ||
489 | return; | ||
490 | } | ||
491 | |||
492 | if (GNUNET_OK != | ||
493 | GNUNET_CONFIGURATION_get_value_string (testing_cfg, "test_mesh_small", | ||
494 | "data_output_file", | ||
495 | &data_filename)) | ||
496 | { | ||
497 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
498 | "Option test_mesh_small:data_output_file is required!\n"); | ||
499 | return; | ||
500 | } | ||
501 | |||
502 | data_file = | ||
503 | GNUNET_DISK_file_open (data_filename, | ||
504 | GNUNET_DISK_OPEN_READWRITE | | ||
505 | GNUNET_DISK_OPEN_CREATE, | ||
506 | GNUNET_DISK_PERM_USER_READ | | ||
507 | GNUNET_DISK_PERM_USER_WRITE); | ||
508 | if (data_file == NULL) | ||
509 | { | ||
510 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", | ||
511 | data_filename); | ||
512 | GNUNET_free (data_filename); | ||
513 | } | ||
514 | |||
515 | wait_time = | ||
516 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, temp_wait); | ||
517 | |||
518 | if (GNUNET_YES == | ||
519 | GNUNET_CONFIGURATION_get_value_string (cfg, "test_mesh_small", | ||
520 | "output_file", &temp_str)) | ||
521 | { | ||
522 | output_file = | ||
523 | GNUNET_DISK_file_open (temp_str, | ||
524 | GNUNET_DISK_OPEN_READWRITE | | ||
525 | GNUNET_DISK_OPEN_CREATE, | ||
526 | GNUNET_DISK_PERM_USER_READ | | ||
527 | GNUNET_DISK_PERM_USER_WRITE); | ||
528 | if (output_file == NULL) | ||
529 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failed to open %s for output!\n", | ||
530 | temp_str); | ||
531 | } | ||
532 | GNUNET_free_non_null (temp_str); | ||
533 | |||
534 | hosts = GNUNET_TESTING_hosts_load (testing_cfg); | ||
535 | |||
536 | pg = GNUNET_TESTING_peergroup_start (testing_cfg, num_peers, TIMEOUT, | ||
537 | &connect_cb, &peergroup_ready, NULL, | ||
538 | hosts); | ||
539 | GNUNET_assert (pg != NULL); | ||
540 | shutdown_handle = | ||
541 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_get_forever (), | ||
542 | &shutdown_task, NULL); | ||
543 | } | ||
544 | |||
545 | |||
546 | |||
547 | /** | ||
548 | * test_mesh_small command line options | ||
549 | */ | ||
550 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
551 | {'V', "verbose", NULL, | ||
552 | gettext_noop ("be verbose (print progress information)"), | ||
553 | 0, &GNUNET_GETOPT_set_one, &verbose}, | ||
554 | GNUNET_GETOPT_OPTION_END | ||
555 | }; | ||
556 | |||
557 | |||
558 | /** | ||
559 | * Main: start test | ||
560 | */ | ||
561 | int | ||
562 | main (int argc, char *argv[]) | ||
563 | { | ||
564 | GNUNET_PROGRAM_run (argc, argv, "test_mesh_small_unicast", | ||
565 | gettext_noop ("Test mesh unicast in a small network."), options, | ||
566 | &run, NULL); | ||
567 | #if REMOVE_DIR | ||
568 | GNUNET_DISK_directory_remove ("/tmp/test_mesh_small_unicast"); | ||
569 | #endif | ||
570 | if (0 != ok) | ||
571 | { | ||
572 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "test: FAILED!\n"); | ||
573 | } | ||
574 | return ok; | ||
575 | } | ||
576 | |||
577 | /* end of test_mesh_small_unicast.c */ | ||