aboutsummaryrefslogtreecommitdiff
path: root/src/nse
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-10-23 15:54:01 +0000
committerChristian Grothoff <christian@grothoff.org>2016-10-23 15:54:01 +0000
commit1358762d69a894017d1be7d3d55367e492deb111 (patch)
tree2ff55e469a590432b46ba4a9d317a4e81d7eabc2 /src/nse
parent5ac30790d29b30c29aeeb163f26dda90d1c63c08 (diff)
downloadgnunet-1358762d69a894017d1be7d3d55367e492deb111.tar.gz
gnunet-1358762d69a894017d1be7d3d55367e492deb111.zip
simplify gnunet-nse to avoid deprecated CLIENT_service_test
Diffstat (limited to 'src/nse')
-rw-r--r--src/nse/gnunet-nse.c90
1 files changed, 23 insertions, 67 deletions
diff --git a/src/nse/gnunet-nse.c b/src/nse/gnunet-nse.c
index 840b8e64d..bd6bcec55 100644
--- a/src/nse/gnunet-nse.c
+++ b/src/nse/gnunet-nse.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2008--2014 GNUnet e.V. 3 Copyright (C) 2008--2014, 2016 GNUnet e.V.
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -28,26 +28,11 @@
28#include "gnunet_nse_service.h" 28#include "gnunet_nse_service.h"
29 29
30/** 30/**
31 * Handle to our configuration
32 */
33static struct GNUNET_CONFIGURATION_Handle *cfg;
34
35/**
36 * The handle to the NSE service 31 * The handle to the NSE service
37 */ 32 */
38static struct GNUNET_NSE_Handle *nse; 33static struct GNUNET_NSE_Handle *nse;
39 34
40/** 35/**
41 * The handle to test if NSE service is running or not
42 */
43static struct GNUNET_CLIENT_TestHandle *test;
44
45/**
46 * Shutdown task
47 */
48static struct GNUNET_SCHEDULER_Task * shutdown_task;
49
50/**
51 * The program status; 0 for success. 36 * The program status; 0 for success.
52 */ 37 */
53static int status; 38static int status;
@@ -61,13 +46,11 @@ static int status;
61static void 46static void
62do_shutdown (void *cls) 47do_shutdown (void *cls)
63{ 48{
64 shutdown_task = NULL;
65 if (NULL != test)
66 GNUNET_CLIENT_service_test_cancel (test);
67 if (NULL != nse) 49 if (NULL != nse)
50 {
68 GNUNET_NSE_disconnect (nse); 51 GNUNET_NSE_disconnect (nse);
69 if (NULL != cfg) 52 nse = NULL;
70 GNUNET_CONFIGURATION_destroy (cfg); 53 }
71} 54}
72 55
73 56
@@ -83,8 +66,10 @@ do_shutdown (void *cls)
83static void 66static void
84handle_estimate (void *cls, 67handle_estimate (void *cls,
85 struct GNUNET_TIME_Absolute timestamp, 68 struct GNUNET_TIME_Absolute timestamp,
86 double estimate, double std_dev) 69 double estimate,
70 double std_dev)
87{ 71{
72 status = 0;
88 FPRINTF (stdout, "%llu %f %f %f\n", 73 FPRINTF (stdout, "%llu %f %f %f\n",
89 (unsigned long long) timestamp.abs_value_us, 74 (unsigned long long) timestamp.abs_value_us,
90 GNUNET_NSE_log_estimate_to_n (estimate), 75 GNUNET_NSE_log_estimate_to_n (estimate),
@@ -94,38 +79,6 @@ handle_estimate (void *cls,
94 79
95 80
96/** 81/**
97 * Function called with the result on the service test for the NSE service
98 *
99 * @param cls NULL
100 * @param result #GNUNET_YES if the service is running,
101 * #GNUNET_NO if the service is not running
102 * #GNUNET_SYSERR if the configuration is invalid
103 */
104static void
105nse_test_result (void *cls, int result)
106{
107 test = NULL;
108 switch (result)
109 {
110 case GNUNET_YES:
111 nse = GNUNET_NSE_connect (cfg, &handle_estimate, NULL);
112 status = 0;
113 break;
114 case GNUNET_NO:
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
116 _("NSE service is not running\n"));
117 GNUNET_SCHEDULER_shutdown ();
118 return;
119 default:
120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
121 _("Error while checking if NSE service is running or not\n"));
122 GNUNET_SCHEDULER_shutdown ();
123 return;
124 }
125}
126
127
128/**
129 * Actual main function that runs the emulation. 82 * Actual main function that runs the emulation.
130 * 83 *
131 * @param cls unused 84 * @param cls unused
@@ -134,17 +87,16 @@ nse_test_result (void *cls, int result)
134 * @param cfg configuration handle 87 * @param cfg configuration handle
135 */ 88 */
136static void 89static void
137run (void *cls, char *const *args, const char *cfgfile, 90run (void *cls,
138 const struct GNUNET_CONFIGURATION_Handle *_cfg) 91 char *const *args,
92 const char *cfgfile,
93 const struct GNUNET_CONFIGURATION_Handle *cfg)
139{ 94{
140 cfg = GNUNET_CONFIGURATION_dup (_cfg); 95 nse = GNUNET_NSE_connect (cfg,
141 test = GNUNET_CLIENT_service_test ("nse", 96 &handle_estimate,
142 cfg, 97 NULL);
143 GNUNET_TIME_UNIT_SECONDS, 98 GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
144 nse_test_result, 99 NULL);
145 NULL);
146 shutdown_task = GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
147 NULL);
148} 100}
149 101
150 102
@@ -154,7 +106,8 @@ run (void *cls, char *const *args, const char *cfgfile,
154 * @return 0 on success 106 * @return 0 on success
155 */ 107 */
156int 108int
157main (int argc, char *const *argv) 109main (int argc,
110 char *const *argv)
158{ 111{
159 static struct GNUNET_GETOPT_CommandLineOption options[] = { 112 static struct GNUNET_GETOPT_CommandLineOption options[] = {
160 GNUNET_GETOPT_OPTION_END 113 GNUNET_GETOPT_OPTION_END
@@ -162,10 +115,13 @@ main (int argc, char *const *argv)
162 115
163 status = 1; 116 status = 1;
164 if (GNUNET_OK != 117 if (GNUNET_OK !=
165 GNUNET_PROGRAM_run (argc, argv, "gnunet-nse", 118 GNUNET_PROGRAM_run (argc,
119 argv,
120 "gnunet-nse",
166 gettext_noop 121 gettext_noop
167 ("Show network size estimates from NSE service."), 122 ("Show network size estimates from NSE service."),
168 options, &run, NULL)) 123 options,
124 &run, NULL))
169 return 2; 125 return 2;
170 return status; 126 return status;
171} 127}