aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-dht-monitor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-dht-monitor.c')
-rw-r--r--src/dht/gnunet-dht-monitor.c276
1 files changed, 138 insertions, 138 deletions
diff --git a/src/dht/gnunet-dht-monitor.c b/src/dht/gnunet-dht-monitor.c
index 3787b7cfa..26989467c 100644
--- a/src/dht/gnunet-dht-monitor.c
+++ b/src/dht/gnunet-dht-monitor.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file dht/gnunet-dht-monitor.c 21 * @file dht/gnunet-dht-monitor.c
22 * @brief search for data in DHT 22 * @brief search for data in DHT
@@ -39,7 +39,7 @@ static char *query_key;
39/** 39/**
40 * User supplied timeout value (in seconds) 40 * User supplied timeout value (in seconds)
41 */ 41 */
42static struct GNUNET_TIME_Relative timeout_request = {60000}; 42static struct GNUNET_TIME_Relative timeout_request = { 60000 };
43 43
44/** 44/**
45 * Be verbose 45 * Be verbose
@@ -47,7 +47,7 @@ static struct GNUNET_TIME_Relative timeout_request = {60000};
47static int verbose; 47static int verbose;
48 48
49/** 49/**
50* Handle to the DHT 50 * Handle to the DHT
51 */ 51 */
52static struct GNUNET_DHT_Handle *dht_handle; 52static struct GNUNET_DHT_Handle *dht_handle;
53 53
@@ -83,25 +83,25 @@ static struct GNUNET_SCHEDULER_Task *tt;
83 * @param cls closure (unused) 83 * @param cls closure (unused)
84 */ 84 */
85static void 85static void
86cleanup_task (void *cls) 86cleanup_task(void *cls)
87{ 87{
88 if (verbose) 88 if (verbose)
89 fprintf (stderr, "%s", "Cleaning up!\n"); 89 fprintf(stderr, "%s", "Cleaning up!\n");
90 if (NULL != monitor_handle) 90 if (NULL != monitor_handle)
91 { 91 {
92 GNUNET_DHT_monitor_stop (monitor_handle); 92 GNUNET_DHT_monitor_stop(monitor_handle);
93 monitor_handle = NULL; 93 monitor_handle = NULL;
94 } 94 }
95 if (NULL != dht_handle) 95 if (NULL != dht_handle)
96 { 96 {
97 GNUNET_DHT_disconnect (dht_handle); 97 GNUNET_DHT_disconnect(dht_handle);
98 dht_handle = NULL; 98 dht_handle = NULL;
99 } 99 }
100 if (NULL != tt) 100 if (NULL != tt)
101 { 101 {
102 GNUNET_SCHEDULER_cancel (tt); 102 GNUNET_SCHEDULER_cancel(tt);
103 tt = NULL; 103 tt = NULL;
104 } 104 }
105} 105}
106 106
107 107
@@ -111,10 +111,10 @@ cleanup_task (void *cls)
111 * @param cls closure (unused) 111 * @param cls closure (unused)
112 */ 112 */
113static void 113static void
114timeout_task (void *cls) 114timeout_task(void *cls)
115{ 115{
116 tt = NULL; 116 tt = NULL;
117 GNUNET_SCHEDULER_shutdown (); 117 GNUNET_SCHEDULER_shutdown();
118} 118}
119 119
120 120
@@ -131,20 +131,20 @@ timeout_task (void *cls)
131 * @param key Key of the requested data. 131 * @param key Key of the requested data.
132 */ 132 */
133static void 133static void
134get_callback (void *cls, 134get_callback(void *cls,
135 enum GNUNET_DHT_RouteOption options, 135 enum GNUNET_DHT_RouteOption options,
136 enum GNUNET_BLOCK_Type type, 136 enum GNUNET_BLOCK_Type type,
137 uint32_t hop_count, 137 uint32_t hop_count,
138 uint32_t desired_replication_level, 138 uint32_t desired_replication_level,
139 unsigned int path_length, 139 unsigned int path_length,
140 const struct GNUNET_PeerIdentity *path, 140 const struct GNUNET_PeerIdentity *path,
141 const struct GNUNET_HashCode *key) 141 const struct GNUNET_HashCode *key)
142{ 142{
143 fprintf (stdout, 143 fprintf(stdout,
144 "GET #%u: type %d, key `%s'\n", 144 "GET #%u: type %d, key `%s'\n",
145 result_count, 145 result_count,
146 (int) type, 146 (int)type,
147 GNUNET_h2s_full (key)); 147 GNUNET_h2s_full(key));
148 result_count++; 148 result_count++;
149} 149}
150 150
@@ -164,27 +164,27 @@ get_callback (void *cls,
164 * @param size Number of bytes in data. 164 * @param size Number of bytes in data.
165 */ 165 */
166static void 166static void
167get_resp_callback (void *cls, 167get_resp_callback(void *cls,
168 enum GNUNET_BLOCK_Type type, 168 enum GNUNET_BLOCK_Type type,
169 const struct GNUNET_PeerIdentity *get_path, 169 const struct GNUNET_PeerIdentity *get_path,
170 unsigned int get_path_length, 170 unsigned int get_path_length,
171 const struct GNUNET_PeerIdentity *put_path, 171 const struct GNUNET_PeerIdentity *put_path,
172 unsigned int put_path_length, 172 unsigned int put_path_length,
173 struct GNUNET_TIME_Absolute exp, 173 struct GNUNET_TIME_Absolute exp,
174 const struct GNUNET_HashCode *key, 174 const struct GNUNET_HashCode *key,
175 const void *data, 175 const void *data,
176 size_t size) 176 size_t size)
177{ 177{
178 fprintf (stdout, 178 fprintf(stdout,
179 (GNUNET_BLOCK_TYPE_TEST == type) 179 (GNUNET_BLOCK_TYPE_TEST == type)
180 ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n" 180 ? "RESPONSE #%u (%s): type %d, key `%s', data `%.*s'\n"
181 : "RESPONSE #%u (%s): type %d, key `%s'\n", 181 : "RESPONSE #%u (%s): type %d, key `%s'\n",
182 result_count, 182 result_count,
183 GNUNET_STRINGS_absolute_time_to_string (exp), 183 GNUNET_STRINGS_absolute_time_to_string(exp),
184 (int) type, 184 (int)type,
185 GNUNET_h2s_full (key), 185 GNUNET_h2s_full(key),
186 (unsigned int) size, 186 (unsigned int)size,
187 (char *) data); 187 (char *)data);
188 result_count++; 188 result_count++;
189} 189}
190 190
@@ -205,28 +205,28 @@ get_resp_callback (void *cls,
205 * @param size Number of bytes in data. 205 * @param size Number of bytes in data.
206 */ 206 */
207static void 207static void
208put_callback (void *cls, 208put_callback(void *cls,
209 enum GNUNET_DHT_RouteOption options, 209 enum GNUNET_DHT_RouteOption options,
210 enum GNUNET_BLOCK_Type type, 210 enum GNUNET_BLOCK_Type type,
211 uint32_t hop_count, 211 uint32_t hop_count,
212 uint32_t desired_replication_level, 212 uint32_t desired_replication_level,
213 unsigned int path_length, 213 unsigned int path_length,
214 const struct GNUNET_PeerIdentity *path, 214 const struct GNUNET_PeerIdentity *path,
215 struct GNUNET_TIME_Absolute exp, 215 struct GNUNET_TIME_Absolute exp,
216 const struct GNUNET_HashCode *key, 216 const struct GNUNET_HashCode *key,
217 const void *data, 217 const void *data,
218 size_t size) 218 size_t size)
219{ 219{
220 fprintf (stdout, 220 fprintf(stdout,
221 (GNUNET_BLOCK_TYPE_TEST == type) 221 (GNUNET_BLOCK_TYPE_TEST == type)
222 ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n" 222 ? "PUT %u (%s): type %d, key `%s', data `%.*s'\n"
223 : "PUT %u (%s): type %d, key `%s'\n", 223 : "PUT %u (%s): type %d, key `%s'\n",
224 result_count, 224 result_count,
225 GNUNET_STRINGS_absolute_time_to_string (exp), 225 GNUNET_STRINGS_absolute_time_to_string(exp),
226 (int) type, 226 (int)type,
227 GNUNET_h2s_full (key), 227 GNUNET_h2s_full(key),
228 (unsigned int) size, 228 (unsigned int)size,
229 (char *) data); 229 (char *)data);
230 result_count++; 230 result_count++;
231} 231}
232 232
@@ -240,48 +240,48 @@ put_callback (void *cls,
240 * @param c configuration 240 * @param c configuration
241 */ 241 */
242static void 242static void
243run (void *cls, 243run(void *cls,
244 char *const *args, 244 char *const *args,
245 const char *cfgfile, 245 const char *cfgfile,
246 const struct GNUNET_CONFIGURATION_Handle *c) 246 const struct GNUNET_CONFIGURATION_Handle *c)
247{ 247{
248 struct GNUNET_HashCode *key; 248 struct GNUNET_HashCode *key;
249 struct GNUNET_HashCode hc; 249 struct GNUNET_HashCode hc;
250 250
251 cfg = c; 251 cfg = c;
252 252
253 if (NULL == (dht_handle = GNUNET_DHT_connect (cfg, 1))) 253 if (NULL == (dht_handle = GNUNET_DHT_connect(cfg, 1)))
254 { 254 {
255 fprintf (stderr, "%s", _ ("Failed to connect to DHT service!\n")); 255 fprintf(stderr, "%s", _("Failed to connect to DHT service!\n"));
256 ret = 1; 256 ret = 1;
257 return; 257 return;
258 } 258 }
259 if (GNUNET_BLOCK_TYPE_ANY == block_type) /* Type of data not set */ 259 if (GNUNET_BLOCK_TYPE_ANY == block_type) /* Type of data not set */
260 block_type = GNUNET_BLOCK_TYPE_TEST; 260 block_type = GNUNET_BLOCK_TYPE_TEST;
261 if (NULL != query_key) 261 if (NULL != query_key)
262 { 262 {
263 key = &hc; 263 key = &hc;
264 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string (query_key, key)) 264 if (GNUNET_OK != GNUNET_CRYPTO_hash_from_string(query_key, key))
265 GNUNET_CRYPTO_hash (query_key, strlen (query_key), key); 265 GNUNET_CRYPTO_hash(query_key, strlen(query_key), key);
266 } 266 }
267 else 267 else
268 { 268 {
269 key = NULL; 269 key = NULL;
270 } 270 }
271 if (verbose) 271 if (verbose)
272 fprintf (stderr, 272 fprintf(stderr,
273 "Monitoring for %s\n", 273 "Monitoring for %s\n",
274 GNUNET_STRINGS_relative_time_to_string (timeout_request, 274 GNUNET_STRINGS_relative_time_to_string(timeout_request,
275 GNUNET_NO)); 275 GNUNET_NO));
276 tt = GNUNET_SCHEDULER_add_delayed (timeout_request, &timeout_task, NULL); 276 tt = GNUNET_SCHEDULER_add_delayed(timeout_request, &timeout_task, NULL);
277 GNUNET_SCHEDULER_add_shutdown (&cleanup_task, NULL); 277 GNUNET_SCHEDULER_add_shutdown(&cleanup_task, NULL);
278 monitor_handle = GNUNET_DHT_monitor_start (dht_handle, 278 monitor_handle = GNUNET_DHT_monitor_start(dht_handle,
279 block_type, 279 block_type,
280 key, 280 key,
281 &get_callback, 281 &get_callback,
282 &get_resp_callback, 282 &get_resp_callback,
283 &put_callback, 283 &put_callback,
284 NULL); 284 NULL);
285} 285}
286 286
287/** 287/**
@@ -292,52 +292,52 @@ run (void *cls,
292 * @return 0 ok, 1 on error 292 * @return 0 ok, 1 on error
293 */ 293 */
294int 294int
295main (int argc, char *const *argv) 295main(int argc, char *const *argv)
296{ 296{
297 struct GNUNET_GETOPT_CommandLineOption options[] = { 297 struct GNUNET_GETOPT_CommandLineOption options[] = {
298 298 GNUNET_GETOPT_option_string('k',
299 GNUNET_GETOPT_option_string ('k', 299 "key",
300 "key", 300 "KEY",
301 "KEY", 301 gettext_noop("the query key"),
302 gettext_noop ("the query key"), 302 &query_key),
303 &query_key), 303
304 304 GNUNET_GETOPT_option_uint('t',
305 GNUNET_GETOPT_option_uint ('t', 305 "type",
306 "type", 306 "TYPE",
307 "TYPE", 307 gettext_noop("the type of data to look for"),
308 gettext_noop ("the type of data to look for"), 308 &block_type),
309 &block_type), 309
310 310 GNUNET_GETOPT_option_relative_time(
311 GNUNET_GETOPT_option_relative_time (
312 'T', 311 'T',
313 "timeout", 312 "timeout",
314 "TIMEOUT", 313 "TIMEOUT",
315 gettext_noop ("how long should the monitor command run"), 314 gettext_noop("how long should the monitor command run"),
316 &timeout_request), 315 &timeout_request),
317 316
318 GNUNET_GETOPT_option_flag ('V', 317 GNUNET_GETOPT_option_flag('V',
319 "verbose", 318 "verbose",
320 gettext_noop ( 319 gettext_noop(
321 "be verbose (print progress information)"), 320 "be verbose (print progress information)"),
322 &verbose), 321 &verbose),
323 322
324 GNUNET_GETOPT_OPTION_END}; 323 GNUNET_GETOPT_OPTION_END
324 };
325 325
326 326
327 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 327 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
328 return 2; 328 return 2;
329 329
330 return (GNUNET_OK == 330 return (GNUNET_OK ==
331 GNUNET_PROGRAM_run (argc, 331 GNUNET_PROGRAM_run(argc,
332 argv, 332 argv,
333 "gnunet-dht-monitor", 333 "gnunet-dht-monitor",
334 gettext_noop ( 334 gettext_noop(
335 "Prints all packets that go through the DHT."), 335 "Prints all packets that go through the DHT."),
336 options, 336 options,
337 &run, 337 &run,
338 NULL)) 338 NULL))
339 ? ret 339 ? ret
340 : 1; 340 : 1;
341} 341}
342 342
343/* end of gnunet-dht-monitor.c */ 343/* end of gnunet-dht-monitor.c */