diff options
-rw-r--r-- | src/mesh/Makefile.am | 24 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 7 | ||||
-rw-r--r-- | src/regex/Makefile.am | 26 | ||||
-rw-r--r-- | src/regex/gnunet-daemon-regexprofiler.c (renamed from src/mesh/gnunet-daemon-regexprofiler.c) | 176 | ||||
-rw-r--r-- | src/regex/gnunet-regex-profiler.c (renamed from src/mesh/gnunet-regex-profiler.c) | 211 |
5 files changed, 260 insertions, 184 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am index 5db9868ab..cc4531ad2 100644 --- a/src/mesh/Makefile.am +++ b/src/mesh/Makefile.am | |||
@@ -108,30 +108,6 @@ gnunet_service_mesh_new_LDFLAGS = -lrt | |||
108 | endif | 108 | endif |
109 | 109 | ||
110 | 110 | ||
111 | noinst_PROGRAMS = \ | ||
112 | gnunet-regex-profiler \ | ||
113 | gnunet-daemon-regexprofiler | ||
114 | |||
115 | gnunet_regex_profiler_SOURCES = \ | ||
116 | gnunet-regex-profiler.c | ||
117 | gnunet_regex_profiler_LDADD = \ | ||
118 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
119 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | ||
120 | $(top_builddir)/src/mesh/libgnunetmesh.la \ | ||
121 | $(top_builddir)/src/regex/libgnunetregex.la \ | ||
122 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
123 | gnunet_regex_profiler_DEPENDENCIES = \ | ||
124 | libgnunetmesh.la | ||
125 | |||
126 | gnunet_daemon_regexprofiler_SOURCES = \ | ||
127 | gnunet-daemon-regexprofiler.c | ||
128 | gnunet_daemon_regexprofiler_LDADD = \ | ||
129 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
130 | $(top_builddir)/src/mesh/libgnunetmesh.la \ | ||
131 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
132 | gnunet_daemon_regexprofiler_DEPENDENCIES = \ | ||
133 | libgnunetmesh.la | ||
134 | |||
135 | noinst_LIBRARIES = libgnunetmeshtest.a | 111 | noinst_LIBRARIES = libgnunetmeshtest.a |
136 | 112 | ||
137 | libgnunetmeshtest_a_SOURCES = \ | 113 | libgnunetmeshtest_a_SOURCES = \ |
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index f5d323a35..2ee5b9d3f 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -8243,13 +8243,6 @@ key_generation_cb (void *cls, | |||
8243 | "Mesh for peer [%s] starting\n", | 8243 | "Mesh for peer [%s] starting\n", |
8244 | GNUNET_i2s(&my_full_id)); | 8244 | GNUNET_i2s(&my_full_id)); |
8245 | 8245 | ||
8246 | // transport_handle = GNUNET_TRANSPORT_connect(c, | ||
8247 | // &my_full_id, | ||
8248 | // NULL, | ||
8249 | // NULL, | ||
8250 | // NULL, | ||
8251 | // NULL); | ||
8252 | |||
8253 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ | 8246 | core_handle = GNUNET_CORE_connect (c, /* Main configuration */ |
8254 | NULL, /* Closure passed to MESH functions */ | 8247 | NULL, /* Closure passed to MESH functions */ |
8255 | &core_init, /* Call core_init once connected */ | 8248 | &core_init, /* Call core_init once connected */ |
diff --git a/src/regex/Makefile.am b/src/regex/Makefile.am index 26f25258e..3fb4e2522 100644 --- a/src/regex/Makefile.am +++ b/src/regex/Makefile.am | |||
@@ -80,7 +80,9 @@ libgnunetregextest_la_DEPENDENCIES = \ | |||
80 | 80 | ||
81 | 81 | ||
82 | noinst_PROGRAMS = $(noinst_mysql_progs) \ | 82 | noinst_PROGRAMS = $(noinst_mysql_progs) \ |
83 | perf-regex | 83 | perf-regex \ |
84 | gnunet-regex-profiler \ | ||
85 | gnunet-daemon-regexprofiler | ||
84 | 86 | ||
85 | perf_regex_SOURCES = \ | 87 | perf_regex_SOURCES = \ |
86 | perf-regex.c | 88 | perf-regex.c |
@@ -92,6 +94,28 @@ perf_regex_DEPENDENCIES = \ | |||
92 | libgnunetregex.la \ | 94 | libgnunetregex.la \ |
93 | libgnunetregextest.la | 95 | libgnunetregextest.la |
94 | 96 | ||
97 | gnunet_regex_profiler_SOURCES = \ | ||
98 | gnunet-regex-profiler.c | ||
99 | gnunet_regex_profiler_LDADD = \ | ||
100 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
101 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | ||
102 | $(top_builddir)/src/regex/libgnunetregex.la \ | ||
103 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
104 | gnunet_regex_profiler_DEPENDENCIES = \ | ||
105 | libgnunetregex.la | ||
106 | |||
107 | gnunet_daemon_regexprofiler_SOURCES = \ | ||
108 | gnunet-daemon-regexprofiler.c | ||
109 | gnunet_daemon_regexprofiler_LDADD = \ | ||
110 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
111 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
112 | $(top_builddir)/src/regex/libgnunetregex.la \ | ||
113 | $(top_builddir)/src/statistics/libgnunetstatistics.la | ||
114 | gnunet_daemon_regexprofiler_DEPENDENCIES = \ | ||
115 | $(top_builddir)/src/dht/libgnunetdht.la \ | ||
116 | libgnunetregex.la | ||
117 | |||
118 | |||
95 | 119 | ||
96 | check_PROGRAMS = \ | 120 | check_PROGRAMS = \ |
97 | test_regex_eval_api \ | 121 | test_regex_eval_api \ |
diff --git a/src/mesh/gnunet-daemon-regexprofiler.c b/src/regex/gnunet-daemon-regexprofiler.c index 84e18b898..75d3f9c7e 100644 --- a/src/mesh/gnunet-daemon-regexprofiler.c +++ b/src/regex/gnunet-daemon-regexprofiler.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | (C) 2010, 2011, 2012 Christian Grothoff | 3 | (C) 2012,2013 Christian Grothoff |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -25,9 +25,12 @@ | |||
25 | * without the need to explicitly connect to the mesh service running on the | 25 | * without the need to explicitly connect to the mesh service running on the |
26 | * peer from within the profiler. | 26 | * peer from within the profiler. |
27 | * @author Maximilian Szengel | 27 | * @author Maximilian Szengel |
28 | * @author Bartlomiej Polot | ||
28 | */ | 29 | */ |
29 | #include "platform.h" | 30 | #include "platform.h" |
30 | #include "gnunet_mesh_service.h" | 31 | #include "gnunet_util_lib.h" |
32 | #include "gnunet_regex_lib.h" | ||
33 | #include "gnunet_dht_service.h" | ||
31 | #include "gnunet_statistics_service.h" | 34 | #include "gnunet_statistics_service.h" |
32 | 35 | ||
33 | /** | 36 | /** |
@@ -46,14 +49,34 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg; | |||
46 | static struct GNUNET_STATISTICS_Handle *stats_handle; | 49 | static struct GNUNET_STATISTICS_Handle *stats_handle; |
47 | 50 | ||
48 | /** | 51 | /** |
49 | * Peer's mesh handle. | 52 | * Peer's dht handle. |
50 | */ | 53 | */ |
51 | struct GNUNET_MESH_Handle *mesh_handle; | 54 | static struct GNUNET_DHT_Handle *dht_handle; |
52 | 55 | ||
53 | /** | 56 | /** |
54 | * Peer's mesh tunnel handle. | 57 | * Peer's regex announce handle. |
55 | */ | 58 | */ |
56 | struct GNUNET_MESH_Tunnel *mesh_tunnel_handle; | 59 | static struct GNUNET_REGEX_announce_handle *announce_handle; |
60 | |||
61 | /** | ||
62 | * Hostkey generation context | ||
63 | */ | ||
64 | static struct GNUNET_CRYPTO_RsaKeyGenerationContext *keygen; | ||
65 | |||
66 | /** | ||
67 | * Periodically reannounce regex. | ||
68 | */ | ||
69 | static GNUNET_SCHEDULER_TaskIdentifier reannounce_task; | ||
70 | |||
71 | /** | ||
72 | * How often reannounce regex. | ||
73 | */ | ||
74 | static struct GNUNET_TIME_Relative reannounce_freq; | ||
75 | |||
76 | /** | ||
77 | * Local peer's PeerID. | ||
78 | */ | ||
79 | static struct GNUNET_PeerIdentity my_full_id; | ||
57 | 80 | ||
58 | /** | 81 | /** |
59 | * Maximal path compression length for regex announcing. | 82 | * Maximal path compression length for regex announcing. |
@@ -72,6 +95,12 @@ static char * policy_filename; | |||
72 | static char * regex_prefix; | 95 | static char * regex_prefix; |
73 | 96 | ||
74 | /** | 97 | /** |
98 | * Regex with prefix. | ||
99 | */ | ||
100 | static char *rx_with_pfx; | ||
101 | |||
102 | |||
103 | /** | ||
75 | * Task run during shutdown. | 104 | * Task run during shutdown. |
76 | * | 105 | * |
77 | * @param cls unused | 106 | * @param cls unused |
@@ -82,16 +111,21 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
82 | { | 111 | { |
83 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n"); | 112 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n"); |
84 | 113 | ||
85 | if (NULL != mesh_tunnel_handle) | 114 | if (NULL != keygen) |
86 | { | 115 | { |
87 | GNUNET_MESH_tunnel_destroy (mesh_tunnel_handle); | 116 | GNUNET_CRYPTO_rsa_key_create_stop (keygen); |
88 | mesh_tunnel_handle = NULL; | 117 | keygen = NULL; |
118 | } | ||
119 | if (NULL != announce_handle) | ||
120 | { | ||
121 | GNUNET_REGEX_announce_cancel (announce_handle); | ||
122 | announce_handle = NULL; | ||
89 | } | 123 | } |
90 | 124 | ||
91 | if (NULL != mesh_handle) | 125 | if (NULL != dht_handle) |
92 | { | 126 | { |
93 | GNUNET_MESH_disconnect (mesh_handle); | 127 | GNUNET_DHT_disconnect (dht_handle); |
94 | mesh_handle = NULL; | 128 | dht_handle = NULL; |
95 | } | 129 | } |
96 | 130 | ||
97 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n"); | 131 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n"); |
@@ -99,6 +133,24 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
99 | 133 | ||
100 | 134 | ||
101 | /** | 135 | /** |
136 | * Announce a previously announced regex re-using cached data. | ||
137 | * | ||
138 | * @param cls Clocuse (not used). | ||
139 | * @param tc TaskContext. | ||
140 | */ | ||
141 | static void | ||
142 | reannounce_regex (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
143 | { | ||
144 | reannounce_task = GNUNET_SCHEDULER_NO_TASK; | ||
145 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | ||
146 | return; | ||
147 | reannounce_task = GNUNET_SCHEDULER_add_delayed(reannounce_freq, | ||
148 | &reannounce_regex, | ||
149 | cls); | ||
150 | } | ||
151 | |||
152 | |||
153 | /** | ||
102 | * Announce the given regular expression using Mesh and the path compression | 154 | * Announce the given regular expression using Mesh and the path compression |
103 | * length read from config. | 155 | * length read from config. |
104 | * | 156 | * |
@@ -115,7 +167,15 @@ announce_regex (const char * regex) | |||
115 | 167 | ||
116 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex); | 168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Announcing regex: %s\n", regex); |
117 | GNUNET_STATISTICS_update (stats_handle, "# regexes announced", 1, GNUNET_NO); | 169 | GNUNET_STATISTICS_update (stats_handle, "# regexes announced", 1, GNUNET_NO); |
118 | GNUNET_MESH_announce_regex (mesh_handle, regex, (unsigned int)max_path_compression); | 170 | announce_handle = GNUNET_REGEX_announce (dht_handle, |
171 | NULL, | ||
172 | regex, | ||
173 | (unsigned int) max_path_compression, | ||
174 | stats_handle); | ||
175 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == reannounce_task); | ||
176 | reannounce_task = GNUNET_SCHEDULER_add_delayed (reannounce_freq, | ||
177 | reannounce_regex, | ||
178 | NULL); | ||
119 | } | 179 | } |
120 | 180 | ||
121 | 181 | ||
@@ -124,7 +184,9 @@ announce_regex (const char * regex) | |||
124 | * | 184 | * |
125 | * @param filename filename of the file containing the regexes, one per line. | 185 | * @param filename filename of the file containing the regexes, one per line. |
126 | * @param rx string with the union of all regular expressions. | 186 | * @param rx string with the union of all regular expressions. |
187 | * | ||
127 | * @return number of regular expressions read from filename and in rxes array. | 188 | * @return number of regular expressions read from filename and in rxes array. |
189 | * FIXME use load regex lib function | ||
128 | */ | 190 | */ |
129 | static unsigned int | 191 | static unsigned int |
130 | load_regexes (const char *filename, char **rx) | 192 | load_regexes (const char *filename, char **rx) |
@@ -179,6 +241,42 @@ load_regexes (const char *filename, char **rx) | |||
179 | 241 | ||
180 | 242 | ||
181 | /** | 243 | /** |
244 | * Callback for hostkey read/generation | ||
245 | * | ||
246 | * @param cls Closure (not used). | ||
247 | * @param pk The private key of the local peer. | ||
248 | * @param emsg Error message if applicable. | ||
249 | */ | ||
250 | static void | ||
251 | key_generation_cb (void *cls, | ||
252 | struct GNUNET_CRYPTO_RsaPrivateKey *pk, | ||
253 | const char *emsg) | ||
254 | { | ||
255 | struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded my_public_key; | ||
256 | |||
257 | keygen = NULL; | ||
258 | if (NULL == pk) | ||
259 | { | ||
260 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
261 | _("Regexprofiler could not access hostkey: %s. Exiting.\n"), | ||
262 | emsg); | ||
263 | GNUNET_SCHEDULER_shutdown (); | ||
264 | return; | ||
265 | } | ||
266 | |||
267 | GNUNET_CRYPTO_rsa_key_get_public (pk, &my_public_key); | ||
268 | GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key), | ||
269 | &my_full_id.hashPubKey); | ||
270 | |||
271 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
272 | "Regexprofiler for peer [%s] starting\n", | ||
273 | GNUNET_i2s(&my_full_id)); | ||
274 | announce_regex (rx_with_pfx); | ||
275 | GNUNET_free (rx_with_pfx); | ||
276 | } | ||
277 | |||
278 | |||
279 | /** | ||
182 | * @brief Main function that will be run by the scheduler. | 280 | * @brief Main function that will be run by the scheduler. |
183 | * | 281 | * |
184 | * @param cls closure | 282 | * @param cls closure |
@@ -192,15 +290,23 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
192 | const struct GNUNET_CONFIGURATION_Handle *cfg_) | 290 | const struct GNUNET_CONFIGURATION_Handle *cfg_) |
193 | { | 291 | { |
194 | char *regex = NULL; | 292 | char *regex = NULL; |
195 | char *rx_with_pfx; | 293 | char *keyfile; |
196 | const GNUNET_MESH_ApplicationType app = (GNUNET_MESH_ApplicationType)0; | ||
197 | static struct GNUNET_MESH_MessageHandler handlers[] = { | ||
198 | {NULL, 0, 0} | ||
199 | }; | ||
200 | 294 | ||
201 | cfg = cfg_; | 295 | cfg = cfg_; |
202 | 296 | ||
203 | if (GNUNET_OK != | 297 | if (GNUNET_OK != |
298 | GNUNET_CONFIGURATION_get_value_filename (cfg, "GNUNETD", "HOSTKEY", | ||
299 | &keyfile)) | ||
300 | { | ||
301 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
302 | _ | ||
303 | ("%s service is lacking key configuration settings (%s). Exiting.\n"), | ||
304 | "regexprofiler", "hostkey"); | ||
305 | GNUNET_SCHEDULER_shutdown (); | ||
306 | return; | ||
307 | } | ||
308 | |||
309 | if (GNUNET_OK != | ||
204 | GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER", "MAX_PATH_COMPRESSION", | 310 | GNUNET_CONFIGURATION_get_value_number (cfg, "REGEXPROFILER", "MAX_PATH_COMPRESSION", |
205 | &max_path_compression)) | 311 | &max_path_compression)) |
206 | { | 312 | { |
@@ -214,8 +320,8 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
214 | } | 320 | } |
215 | 321 | ||
216 | if (GNUNET_OK != | 322 | if (GNUNET_OK != |
217 | GNUNET_CONFIGURATION_get_value_filename (cfg, "REGEXPROFILER", "POLICY_FILE", | 323 | GNUNET_CONFIGURATION_get_value_filename (cfg, "REGEXPROFILER", |
218 | &policy_filename)) | 324 | "POLICY_FILE", &policy_filename)) |
219 | { | 325 | { |
220 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 326 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
221 | _ | 327 | _ |
@@ -227,8 +333,8 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
227 | } | 333 | } |
228 | 334 | ||
229 | if (GNUNET_OK != | 335 | if (GNUNET_OK != |
230 | GNUNET_CONFIGURATION_get_value_string (cfg, "REGEXPROFILER", "REGEX_PREFIX", | 336 | GNUNET_CONFIGURATION_get_value_string (cfg, "REGEXPROFILER", |
231 | ®ex_prefix)) | 337 | "REGEX_PREFIX", ®ex_prefix)) |
232 | { | 338 | { |
233 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 339 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
234 | _ | 340 | _ |
@@ -239,14 +345,25 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
239 | return; | 345 | return; |
240 | } | 346 | } |
241 | 347 | ||
348 | if (GNUNET_OK != | ||
349 | GNUNET_CONFIGURATION_get_value_time (cfg, "REGEXPROFILER", | ||
350 | "REANNOUNCE_FREQ", &reannounce_freq)) | ||
351 | { | ||
352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
353 | "reannounce_freq not given. Using 10 minutes.\n"); | ||
354 | reannounce_freq = | ||
355 | GNUNET_TIME_relative_multiply(GNUNET_TIME_relative_get_minute_(), 10); | ||
356 | |||
357 | } | ||
358 | |||
242 | stats_handle = GNUNET_STATISTICS_create ("regexprofiler", cfg); | 359 | stats_handle = GNUNET_STATISTICS_create ("regexprofiler", cfg); |
243 | 360 | ||
244 | mesh_handle = | 361 | dht_handle = GNUNET_DHT_connect (cfg, 1); |
245 | GNUNET_MESH_connect (cfg, NULL, NULL, NULL, handlers, &app); | ||
246 | 362 | ||
247 | if (NULL == mesh_handle) | 363 | if (NULL == dht_handle) |
248 | { | 364 | { |
249 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not acquire mesh handle. Exiting.\n"); | 365 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
366 | "Could not acquire dht handle. Exiting.\n"); | ||
250 | global_ret = GNUNET_SYSERR; | 367 | global_ret = GNUNET_SYSERR; |
251 | GNUNET_SCHEDULER_shutdown (); | 368 | GNUNET_SCHEDULER_shutdown (); |
252 | return; | 369 | return; |
@@ -265,10 +382,13 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
265 | 382 | ||
266 | /* Announcing regexes from policy_filename */ | 383 | /* Announcing regexes from policy_filename */ |
267 | GNUNET_asprintf (&rx_with_pfx, "%s(%s)", regex_prefix, regex); | 384 | GNUNET_asprintf (&rx_with_pfx, "%s(%s)", regex_prefix, regex); |
268 | announce_regex (rx_with_pfx); | ||
269 | GNUNET_free (rx_with_pfx); | ||
270 | GNUNET_free (regex); | 385 | GNUNET_free (regex); |
271 | 386 | ||
387 | keygen = GNUNET_CRYPTO_rsa_key_create_start (keyfile, | ||
388 | &key_generation_cb, | ||
389 | NULL); | ||
390 | GNUNET_free (keyfile); | ||
391 | |||
272 | /* Scheduled the task to clean up when shutdown is called */ | 392 | /* Scheduled the task to clean up when shutdown is called */ |
273 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, | 393 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, |
274 | NULL); | 394 | NULL); |
diff --git a/src/mesh/gnunet-regex-profiler.c b/src/regex/gnunet-regex-profiler.c index f431d6484..d8990a626 100644 --- a/src/mesh/gnunet-regex-profiler.c +++ b/src/regex/gnunet-regex-profiler.c | |||
@@ -31,8 +31,9 @@ | |||
31 | #include "platform.h" | 31 | #include "platform.h" |
32 | #include "gnunet_applications.h" | 32 | #include "gnunet_applications.h" |
33 | #include "gnunet_util_lib.h" | 33 | #include "gnunet_util_lib.h" |
34 | #include "gnunet_mesh_service.h" | 34 | #include "gnunet_regex_lib.h" |
35 | #include "gnunet_stream_lib.h" | 35 | #include "gnunet_dht_service.h" |
36 | // #include "gnunet_stream_lib.h" | ||
36 | #include "gnunet_testbed_service.h" | 37 | #include "gnunet_testbed_service.h" |
37 | 38 | ||
38 | /** | 39 | /** |
@@ -149,19 +150,19 @@ struct RegexPeer | |||
149 | int search_str_matched; | 150 | int search_str_matched; |
150 | 151 | ||
151 | /** | 152 | /** |
152 | * Peer's mesh handle. | 153 | * Peer's dht handle. |
153 | */ | 154 | */ |
154 | struct GNUNET_MESH_Handle *mesh_handle; | 155 | struct GNUNET_DHT_Handle *dht_handle; |
155 | 156 | ||
156 | /** | 157 | /** |
157 | * Peer's mesh tunnel handle. | 158 | * Handle to a running regex search. |
158 | */ | 159 | */ |
159 | struct GNUNET_MESH_Tunnel *mesh_tunnel_handle; | 160 | struct GNUNET_REGEX_search_handle *search_handle; |
160 | 161 | ||
161 | /** | 162 | /** |
162 | * Testbed operation handle for the mesh service. | 163 | * Testbed operation handle for the dht service. |
163 | */ | 164 | */ |
164 | struct GNUNET_TESTBED_Operation *mesh_op_handle; | 165 | struct GNUNET_TESTBED_Operation *dht_op_handle; |
165 | 166 | ||
166 | /** | 167 | /** |
167 | * Peers's statistics handle. | 168 | * Peers's statistics handle. |
@@ -382,34 +383,25 @@ static char * regex_prefix; | |||
382 | 383 | ||
383 | 384 | ||
384 | /** | 385 | /** |
385 | * Method called whenever a peer has connected to the tunnel. | 386 | * Search callback function. |
386 | * | ||
387 | * @param cls closure | ||
388 | * @param peer_id peer identity the tunnel was created to, NULL on timeout | ||
389 | * @param atsi performance data for the connection | ||
390 | * | 387 | * |
388 | * @param cls Closure provided in GNUNET_REGEX_search. | ||
389 | * @param id Peer providing a regex that matches the string. | ||
390 | * @param get_path Path of the get request. | ||
391 | * @param get_path_length Lenght of get_path. | ||
392 | * @param put_path Path of the put request. | ||
393 | * @param put_path_length Length of the put_path. | ||
391 | */ | 394 | */ |
392 | static void | 395 | static void |
393 | mesh_peer_connect_handler (void *cls, | 396 | mesh_peer_connect_handler (void *cls, |
394 | const struct GNUNET_PeerIdentity* peer_id, | 397 | const struct GNUNET_PeerIdentity *id, |
395 | const struct GNUNET_ATS_Information * atsi); | 398 | const struct GNUNET_PeerIdentity *get_path, |
399 | unsigned int get_path_length, | ||
400 | const struct GNUNET_PeerIdentity *put_path, | ||
401 | unsigned int put_path_length); | ||
396 | 402 | ||
397 | 403 | ||
398 | /** | 404 | /** |
399 | * Method called whenever a peer has disconnected from the tunnel. | ||
400 | * Implementations of this callback must NOT call | ||
401 | * GNUNET_MESH_tunnel_destroy immediately, but instead schedule those | ||
402 | * to run in some other task later. However, calling | ||
403 | * "GNUNET_MESH_notify_transmit_ready_cancel" is allowed. | ||
404 | * | ||
405 | * @param cls closure | ||
406 | * @param peer_id peer identity the tunnel stopped working with | ||
407 | */ | ||
408 | static void | ||
409 | mesh_peer_disconnect_handler (void *cls, | ||
410 | const struct GNUNET_PeerIdentity * peer_id); | ||
411 | |||
412 | /** | ||
413 | * Mesh connect callback. | 405 | * Mesh connect callback. |
414 | * | 406 | * |
415 | * @param cls internal peer id. | 407 | * @param cls internal peer id. |
@@ -418,11 +410,11 @@ mesh_peer_disconnect_handler (void *cls, | |||
418 | * @param emsg error message. | 410 | * @param emsg error message. |
419 | */ | 411 | */ |
420 | static void | 412 | static void |
421 | mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | 413 | dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, |
422 | void *ca_result, const char *emsg); | 414 | void *ca_result, const char *emsg); |
423 | 415 | ||
424 | /** | 416 | /** |
425 | * Mesh connect adapter. | 417 | * DHT connect adapter. |
426 | * | 418 | * |
427 | * @param cls not used. | 419 | * @param cls not used. |
428 | * @param cfg configuration handle. | 420 | * @param cfg configuration handle. |
@@ -430,18 +422,18 @@ mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
430 | * @return | 422 | * @return |
431 | */ | 423 | */ |
432 | static void * | 424 | static void * |
433 | mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg); | 425 | dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg); |
434 | 426 | ||
435 | 427 | ||
436 | /** | 428 | /** |
437 | * Adapter function called to destroy a connection to | 429 | * Adapter function called to destroy a connection to |
438 | * the mesh service | 430 | * the DHT service |
439 | * | 431 | * |
440 | * @param cls closure | 432 | * @param cls closure |
441 | * @param op_result service handle returned from the connect adapter | 433 | * @param op_result service handle returned from the connect adapter |
442 | */ | 434 | */ |
443 | static void | 435 | static void |
444 | mesh_da (void *cls, void *op_result); | 436 | dht_da (void *cls, void *op_result); |
445 | 437 | ||
446 | 438 | ||
447 | /** | 439 | /** |
@@ -532,8 +524,8 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
532 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); | 524 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n"); |
533 | } | 525 | } |
534 | 526 | ||
535 | if (NULL != peers[peer_cnt].mesh_op_handle) | 527 | if (NULL != peers[peer_cnt].dht_op_handle) |
536 | GNUNET_TESTBED_operation_done (peers[peer_cnt].mesh_op_handle); | 528 | GNUNET_TESTBED_operation_done (peers[peer_cnt].dht_op_handle); |
537 | if (NULL != peers[peer_cnt].stats_op_handle) | 529 | if (NULL != peers[peer_cnt].stats_op_handle) |
538 | GNUNET_TESTBED_operation_done (peers[peer_cnt].stats_op_handle); | 530 | GNUNET_TESTBED_operation_done (peers[peer_cnt].stats_op_handle); |
539 | } | 531 | } |
@@ -795,37 +787,23 @@ do_collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
795 | /******************************************************************************/ | 787 | /******************************************************************************/ |
796 | 788 | ||
797 | /** | 789 | /** |
798 | * Method called whenever a peer has disconnected from the tunnel. | 790 | * Method called when we've found a peer that announced a regex |
799 | * Implementations of this callback must NOT call | 791 | * that matches our search string. Now get the statistics. |
800 | * GNUNET_MESH_tunnel_destroy immediately, but instead schedule those | ||
801 | * to run in some other task later. However, calling | ||
802 | * "GNUNET_MESH_notify_transmit_ready_cancel" is allowed. | ||
803 | * | ||
804 | * @param cls closure | ||
805 | * @param peer_id peer identity the tunnel stopped working with | ||
806 | */ | ||
807 | static void | ||
808 | mesh_peer_disconnect_handler (void *cls, | ||
809 | const struct GNUNET_PeerIdentity * peer_id) | ||
810 | { | ||
811 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Mesh peer disconnect handler.\n"); | ||
812 | } | ||
813 | |||
814 | |||
815 | /** | ||
816 | * Method called when the mesh connection succeeded (or timed out), which means | ||
817 | * we've found a peer that announced a regex that matches our search string. Now | ||
818 | * get the statistics. | ||
819 | * | ||
820 | * @param cls closure | ||
821 | * @param peer_id peer identity the tunnel was created to, NULL on timeout | ||
822 | * @param atsi performance data for the connection | ||
823 | * | 792 | * |
793 | * @param cls Closure provided in GNUNET_REGEX_search. | ||
794 | * @param id Peer providing a regex that matches the string. | ||
795 | * @param get_path Path of the get request. | ||
796 | * @param get_path_length Lenght of get_path. | ||
797 | * @param put_path Path of the put request. | ||
798 | * @param put_path_length Length of the put_path. | ||
824 | */ | 799 | */ |
825 | static void | 800 | static void |
826 | mesh_peer_connect_handler (void *cls, | 801 | mesh_peer_connect_handler (void *cls, |
827 | const struct GNUNET_PeerIdentity* peer_id, | 802 | const struct GNUNET_PeerIdentity *id, |
828 | const struct GNUNET_ATS_Information * atsi) | 803 | const struct GNUNET_PeerIdentity *get_path, |
804 | unsigned int get_path_length, | ||
805 | const struct GNUNET_PeerIdentity *put_path, | ||
806 | unsigned int put_path_length) | ||
829 | { | 807 | { |
830 | struct RegexPeer *peer = cls; | 808 | struct RegexPeer *peer = cls; |
831 | char output_buffer[512]; | 809 | char output_buffer[512]; |
@@ -841,7 +819,7 @@ mesh_peer_connect_handler (void *cls, | |||
841 | 819 | ||
842 | peers_found++; | 820 | peers_found++; |
843 | 821 | ||
844 | if (NULL == peer_id) | 822 | if (NULL == id) |
845 | { | 823 | { |
846 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 824 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
847 | "String matching timed out for string %s on peer %u (%i/%i)\n", | 825 | "String matching timed out for string %s on peer %u (%i/%i)\n", |
@@ -889,8 +867,8 @@ mesh_peer_connect_handler (void *cls, | |||
889 | } | 867 | } |
890 | } | 868 | } |
891 | 869 | ||
892 | GNUNET_TESTBED_operation_done (peer->mesh_op_handle); | 870 | GNUNET_TESTBED_operation_done (peer->dht_op_handle); |
893 | peer->mesh_op_handle = NULL; | 871 | peer->dht_op_handle = NULL; |
894 | 872 | ||
895 | if (peers_found == num_search_strings) | 873 | if (peers_found == num_search_strings) |
896 | { | 874 | { |
@@ -959,14 +937,14 @@ do_connect_by_string (void *cls, | |||
959 | 937 | ||
960 | /* First connect to mesh service, then search for string. Next | 938 | /* First connect to mesh service, then search for string. Next |
961 | connect will be in mesh_connect_cb */ | 939 | connect will be in mesh_connect_cb */ |
962 | peers[0].mesh_op_handle = | 940 | peers[0].dht_op_handle = |
963 | GNUNET_TESTBED_service_connect (NULL, | 941 | GNUNET_TESTBED_service_connect (NULL, |
964 | peers[0].peer_handle, | 942 | peers[0].peer_handle, |
965 | "mesh", | 943 | "dht", |
966 | &mesh_connect_cb, | 944 | &dht_connect_cb, |
967 | &peers[0], | 945 | &peers[0], |
968 | &mesh_ca, | 946 | &dht_ca, |
969 | &mesh_da, | 947 | &dht_da, |
970 | &peers[0]); | 948 | &peers[0]); |
971 | 949 | ||
972 | search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout, | 950 | search_timeout_task = GNUNET_SCHEDULER_add_delayed (search_timeout, |
@@ -975,7 +953,7 @@ do_connect_by_string (void *cls, | |||
975 | 953 | ||
976 | 954 | ||
977 | /** | 955 | /** |
978 | * Mesh connect callback. Called when we are connected to the mesh service for | 956 | * DHT connect callback. Called when we are connected to the dht service for |
979 | * the peer in 'cls'. If successfull we connect to the stats service of this | 957 | * the peer in 'cls'. If successfull we connect to the stats service of this |
980 | * peer and then try to match the search string of this peer. | 958 | * peer and then try to match the search string of this peer. |
981 | * | 959 | * |
@@ -985,8 +963,8 @@ do_connect_by_string (void *cls, | |||
985 | * @param emsg error message. | 963 | * @param emsg error message. |
986 | */ | 964 | */ |
987 | static void | 965 | static void |
988 | mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | 966 | dht_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, |
989 | void *ca_result, const char *emsg) | 967 | void *ca_result, const char *emsg) |
990 | { | 968 | { |
991 | struct RegexPeer *peer = (struct RegexPeer *) cls; | 969 | struct RegexPeer *peer = (struct RegexPeer *) cls; |
992 | static unsigned int peer_cnt; | 970 | static unsigned int peer_cnt; |
@@ -994,26 +972,20 @@ mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
994 | 972 | ||
995 | if (NULL != emsg || NULL == op || NULL == ca_result) | 973 | if (NULL != emsg || NULL == op || NULL == ca_result) |
996 | { | 974 | { |
997 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Mesh connect failed: %s\n", emsg); | 975 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "DHT connect failed: %s\n", emsg); |
998 | GNUNET_assert (0); | 976 | GNUNET_abort (); |
999 | } | 977 | } |
1000 | 978 | ||
1001 | GNUNET_assert (NULL != peer->mesh_handle); | 979 | GNUNET_assert (NULL != peer->dht_handle); |
1002 | GNUNET_assert (peer->mesh_op_handle == op); | 980 | GNUNET_assert (peer->dht_op_handle == op); |
1003 | GNUNET_assert (peer->mesh_handle == ca_result); | 981 | GNUNET_assert (peer->dht_handle == ca_result); |
1004 | |||
1005 | peer->mesh_tunnel_handle = | ||
1006 | GNUNET_MESH_tunnel_create (peer->mesh_handle, | ||
1007 | NULL, | ||
1008 | &mesh_peer_connect_handler, | ||
1009 | &mesh_peer_disconnect_handler, | ||
1010 | peer); | ||
1011 | |||
1012 | peer->prof_start_time = GNUNET_TIME_absolute_get (); | ||
1013 | 982 | ||
1014 | peer->search_str_matched = GNUNET_NO; | 983 | peer->search_str_matched = GNUNET_NO; |
1015 | GNUNET_MESH_peer_request_connect_by_string (peer->mesh_tunnel_handle, | 984 | peer->search_handle = |
1016 | peer->search_str); | 985 | GNUNET_REGEX_search (peer->dht_handle, peer->search_str, |
986 | &mesh_peer_connect_handler, NULL, | ||
987 | NULL); | ||
988 | peer->prof_start_time = GNUNET_TIME_absolute_get (); | ||
1017 | 989 | ||
1018 | if (peer_cnt < (num_search_strings - 1)) | 990 | if (peer_cnt < (num_search_strings - 1)) |
1019 | { | 991 | { |
@@ -1024,75 +996,66 @@ mesh_connect_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
1024 | 996 | ||
1025 | peers[next_p].search_str = search_strings[next_p]; | 997 | peers[next_p].search_str = search_strings[next_p]; |
1026 | peers[next_p].search_str_matched = GNUNET_NO; | 998 | peers[next_p].search_str_matched = GNUNET_NO; |
1027 | 999 | ||
1028 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 1000 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
1029 | "Searching for string \"%s\" on peer %d with file %s\n", | 1001 | "Searching for string \"%s\" on peer %d with file %s\n", |
1030 | peers[next_p].search_str, next_p, peers[next_p].policy_file); | 1002 | peers[next_p].search_str, next_p, peers[next_p].policy_file); |
1031 | 1003 | ||
1032 | peers[next_p].mesh_op_handle = | 1004 | peers[next_p].dht_op_handle = |
1033 | GNUNET_TESTBED_service_connect (NULL, | 1005 | GNUNET_TESTBED_service_connect (NULL, |
1034 | peers[next_p].peer_handle, | 1006 | peers[next_p].peer_handle, |
1035 | "mesh", | 1007 | "dht", |
1036 | &mesh_connect_cb, | 1008 | &dht_connect_cb, |
1037 | &peers[next_p], | 1009 | &peers[next_p], |
1038 | &mesh_ca, | 1010 | &dht_ca, |
1039 | &mesh_da, | 1011 | &dht_da, |
1040 | &peers[next_p]); | 1012 | &peers[next_p]); |
1041 | } | 1013 | } |
1042 | } | 1014 | } |
1043 | 1015 | ||
1044 | 1016 | ||
1045 | /** | 1017 | /** |
1046 | * Mesh connect adapter. Opens a connection to the mesh service. | 1018 | * DHT connect adapter. Opens a connection to the dht service. |
1047 | * | 1019 | * |
1048 | * @param cls not used. | 1020 | * @param cls Closure (peer). |
1049 | * @param cfg configuration handle. | 1021 | * @param cfg Configuration handle. |
1050 | * | 1022 | * |
1051 | * @return | 1023 | * @return |
1052 | */ | 1024 | */ |
1053 | static void * | 1025 | static void * |
1054 | mesh_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 1026 | dht_ca (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
1055 | { | 1027 | { |
1056 | GNUNET_MESH_ApplicationType app; | ||
1057 | struct RegexPeer *peer = cls; | 1028 | struct RegexPeer *peer = cls; |
1058 | 1029 | ||
1059 | static struct GNUNET_MESH_MessageHandler handlers[] = { | 1030 | peer->dht_handle = GNUNET_DHT_connect (cfg, 32); |
1060 | {NULL, 0, 0} | ||
1061 | }; | ||
1062 | |||
1063 | app = (GNUNET_MESH_ApplicationType)0; | ||
1064 | 1031 | ||
1065 | peer->mesh_handle = | 1032 | return peer->dht_handle; |
1066 | GNUNET_MESH_connect (cfg, peer, NULL, NULL, handlers, &app); | ||
1067 | |||
1068 | return peer->mesh_handle; | ||
1069 | } | 1033 | } |
1070 | 1034 | ||
1071 | 1035 | ||
1072 | /** | 1036 | /** |
1073 | * Adapter function called to destroy a connection to | 1037 | * Adapter function called to destroy a connection to the dht service. |
1074 | * the mesh service | ||
1075 | * | 1038 | * |
1076 | * @param cls closure | 1039 | * @param cls Closure (peer). |
1077 | * @param op_result service handle returned from the connect adapter | 1040 | * @param op_result Service handle returned from the connect adapter. |
1078 | */ | 1041 | */ |
1079 | static void | 1042 | static void |
1080 | mesh_da (void *cls, void *op_result) | 1043 | dht_da (void *cls, void *op_result) |
1081 | { | 1044 | { |
1082 | struct RegexPeer *peer = (struct RegexPeer *) cls; | 1045 | struct RegexPeer *peer = (struct RegexPeer *) cls; |
1083 | 1046 | ||
1084 | GNUNET_assert (peer->mesh_handle == op_result); | 1047 | GNUNET_assert (peer->dht_handle == op_result); |
1085 | 1048 | ||
1086 | if (NULL != peer->mesh_tunnel_handle) | 1049 | if (NULL != peer->search_handle) |
1087 | { | 1050 | { |
1088 | GNUNET_MESH_tunnel_destroy (peer->mesh_tunnel_handle); | 1051 | GNUNET_REGEX_search_cancel (peer->search_handle); |
1089 | peer->mesh_tunnel_handle = NULL; | 1052 | peer->search_handle = NULL; |
1090 | } | 1053 | } |
1091 | 1054 | ||
1092 | if (NULL != peer->mesh_handle) | 1055 | if (NULL != peer->dht_handle) |
1093 | { | 1056 | { |
1094 | GNUNET_MESH_disconnect (peer->mesh_handle); | 1057 | GNUNET_DHT_disconnect (peer->dht_handle); |
1095 | peer->mesh_handle = NULL; | 1058 | peer->dht_handle = NULL; |
1096 | } | 1059 | } |
1097 | } | 1060 | } |
1098 | 1061 | ||
@@ -1370,8 +1333,8 @@ controller_event_cb (void *cls, | |||
1370 | peer->policy_file = NULL; | 1333 | peer->policy_file = NULL; |
1371 | /* Do not start peers on hosts[0] (master controller) */ | 1334 | /* Do not start peers on hosts[0] (master controller) */ |
1372 | peer->host_handle = hosts[1 + (peer_cnt % (num_hosts -1))]; | 1335 | peer->host_handle = hosts[1 + (peer_cnt % (num_hosts -1))]; |
1373 | peer->mesh_handle = NULL; | 1336 | peer->dht_handle = NULL; |
1374 | peer->mesh_tunnel_handle = NULL; | 1337 | peer->search_handle = NULL; |
1375 | peer->stats_handle = NULL; | 1338 | peer->stats_handle = NULL; |
1376 | peer->stats_op_handle = NULL; | 1339 | peer->stats_op_handle = NULL; |
1377 | peer->search_str = NULL; | 1340 | peer->search_str = NULL; |