diff options
Diffstat (limited to 'src/testbed/gnunet-service-testbed-logger.c')
-rw-r--r-- | src/testbed/gnunet-service-testbed-logger.c | 66 |
1 files changed, 34 insertions, 32 deletions
diff --git a/src/testbed/gnunet-service-testbed-logger.c b/src/testbed/gnunet-service-testbed-logger.c index ab5b17460..0f9fab01b 100644 --- a/src/testbed/gnunet-service-testbed-logger.c +++ b/src/testbed/gnunet-service-testbed-logger.c | |||
@@ -81,11 +81,6 @@ static struct MessageQueue *mq_tail; | |||
81 | struct GNUNET_BIO_WriteHandle *bio; | 81 | struct GNUNET_BIO_WriteHandle *bio; |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * The shutdown task handle | ||
85 | */ | ||
86 | static struct GNUNET_SCHEDULER_Task * shutdown_task_id; | ||
87 | |||
88 | /** | ||
89 | * The number of connections we have | 84 | * The number of connections we have |
90 | */ | 85 | */ |
91 | static unsigned int nconn; | 86 | static unsigned int nconn; |
@@ -95,15 +90,17 @@ static unsigned int nconn; | |||
95 | */ | 90 | */ |
96 | static int in_shutdown; | 91 | static int in_shutdown; |
97 | 92 | ||
93 | |||
98 | /** | 94 | /** |
99 | * Message handler for GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages | 95 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages |
100 | * | 96 | * |
101 | * @param cls NULL | 97 | * @param cls NULL |
102 | * @param client identification of the client | 98 | * @param client identification of the client |
103 | * @param msg the actual message | 99 | * @param msg the actual message |
104 | */ | 100 | */ |
105 | static void | 101 | static void |
106 | handle_log_msg (void *cls, struct GNUNET_SERVER_Client *client, | 102 | handle_log_msg (void *cls, |
103 | struct GNUNET_SERVER_Client *client, | ||
107 | const struct GNUNET_MessageHeader *msg) | 104 | const struct GNUNET_MessageHeader *msg) |
108 | { | 105 | { |
109 | uint16_t ms; | 106 | uint16_t ms; |
@@ -125,21 +122,20 @@ shutdown_task (void *cls) | |||
125 | { | 122 | { |
126 | struct MessageQueue *mq_entry; | 123 | struct MessageQueue *mq_entry; |
127 | 124 | ||
128 | shutdown_task_id = NULL; | ||
129 | in_shutdown = GNUNET_YES; | 125 | in_shutdown = GNUNET_YES; |
130 | if (0 != nconn) | 126 | if (0 != nconn) |
131 | { | 127 | { |
132 | /* Delay shutdown if there are active connections */ | 128 | /* Delay shutdown if there are active connections */ |
133 | shutdown_task_id = GNUNET_SCHEDULER_add_delayed | 129 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
134 | (GNUNET_TIME_UNIT_FOREVER_REL, | ||
135 | &shutdown_task, NULL); | ||
136 | return; | 130 | return; |
137 | } | 131 | } |
138 | while (NULL != (mq_entry = mq_head)) | 132 | while (NULL != (mq_entry = mq_head)) |
139 | { | 133 | { |
140 | GNUNET_free (mq_entry->msg); | 134 | GNUNET_free (mq_entry->msg); |
141 | GNUNET_SERVER_client_drop (mq_entry->client); | 135 | GNUNET_SERVER_client_drop (mq_entry->client); |
142 | GNUNET_CONTAINER_DLL_remove (mq_head, mq_tail, mq_entry); | 136 | GNUNET_CONTAINER_DLL_remove (mq_head, |
137 | mq_tail, | ||
138 | mq_entry); | ||
143 | GNUNET_free (mq_entry); | 139 | GNUNET_free (mq_entry); |
144 | } | 140 | } |
145 | GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bio)); | 141 | GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bio)); |
@@ -147,7 +143,7 @@ shutdown_task (void *cls) | |||
147 | 143 | ||
148 | 144 | ||
149 | /** | 145 | /** |
150 | * Functions with this signature are called whenever a client | 146 | x * Functions with this signature are called whenever a client |
151 | * is disconnected on the network level. | 147 | * is disconnected on the network level. |
152 | * | 148 | * |
153 | * @param cls closure | 149 | * @param cls closure |
@@ -155,7 +151,8 @@ shutdown_task (void *cls) | |||
155 | * for the last call when the server is destroyed | 151 | * for the last call when the server is destroyed |
156 | */ | 152 | */ |
157 | static void | 153 | static void |
158 | client_disconnected (void *cls, struct GNUNET_SERVER_Client *client) | 154 | client_disconnected (void *cls, |
155 | struct GNUNET_SERVER_Client *client) | ||
159 | { | 156 | { |
160 | if (NULL == client) | 157 | if (NULL == client) |
161 | { | 158 | { |
@@ -163,11 +160,8 @@ client_disconnected (void *cls, struct GNUNET_SERVER_Client *client) | |||
163 | return; | 160 | return; |
164 | } | 161 | } |
165 | nconn--; | 162 | nconn--; |
166 | if (GNUNET_YES != in_shutdown) | 163 | if (GNUNET_YES == in_shutdown) |
167 | return; | 164 | GNUNET_SCHEDULER_shutdown (); |
168 | GNUNET_assert (NULL != shutdown_task_id); | ||
169 | GNUNET_SCHEDULER_cancel (shutdown_task_id); | ||
170 | shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL); | ||
171 | } | 165 | } |
172 | 166 | ||
173 | 167 | ||
@@ -179,7 +173,8 @@ client_disconnected (void *cls, struct GNUNET_SERVER_Client *client) | |||
179 | * @param client identification of the client | 173 | * @param client identification of the client |
180 | */ | 174 | */ |
181 | static void | 175 | static void |
182 | client_connected (void *cls, struct GNUNET_SERVER_Client *client) | 176 | client_connected (void *cls, |
177 | struct GNUNET_SERVER_Client *client) | ||
183 | { | 178 | { |
184 | if (NULL == client) | 179 | if (NULL == client) |
185 | { | 180 | { |
@@ -199,8 +194,9 @@ client_connected (void *cls, struct GNUNET_SERVER_Client *client) | |||
199 | * @param cfg configuration to use | 194 | * @param cfg configuration to use |
200 | */ | 195 | */ |
201 | static void | 196 | static void |
202 | logger_run (void *cls, struct GNUNET_SERVER_Handle *server, | 197 | logger_run (void *cls, |
203 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 198 | struct GNUNET_SERVER_Handle *server, |
199 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
204 | { | 200 | { |
205 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { | 201 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { |
206 | {&handle_log_msg, NULL, GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, 0}, | 202 | {&handle_log_msg, NULL, GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, 0}, |
@@ -213,10 +209,14 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
213 | pid_t pid; | 209 | pid_t pid; |
214 | 210 | ||
215 | if (GNUNET_OK != | 211 | if (GNUNET_OK != |
216 | GNUNET_CONFIGURATION_get_value_filename (cfg, "TESTBED-LOGGER", "DIR", | 212 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
213 | "TESTBED-LOGGER", | ||
214 | "DIR", | ||
217 | &dir)) | 215 | &dir)) |
218 | { | 216 | { |
219 | LOG (GNUNET_ERROR_TYPE_ERROR, "Not logging directory definied. Exiting\n"); | 217 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
218 | "TESTBED-LOGGER", | ||
219 | "DIR"); | ||
220 | GNUNET_SCHEDULER_shutdown (); | 220 | GNUNET_SCHEDULER_shutdown (); |
221 | return; | 221 | return; |
222 | } | 222 | } |
@@ -225,14 +225,19 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
225 | hname = GNUNET_malloc (hname_len); | 225 | hname = GNUNET_malloc (hname_len); |
226 | if (0 != gethostname (hname, hname_len)) | 226 | if (0 != gethostname (hname, hname_len)) |
227 | { | 227 | { |
228 | LOG (GNUNET_ERROR_TYPE_ERROR, "Cannot get hostname. Exiting\n"); | 228 | LOG (GNUNET_ERROR_TYPE_ERROR, |
229 | "Cannot get hostname. Exiting\n"); | ||
229 | GNUNET_free (hname); | 230 | GNUNET_free (hname); |
230 | GNUNET_free (dir); | 231 | GNUNET_free (dir); |
231 | GNUNET_SCHEDULER_shutdown (); | 232 | GNUNET_SCHEDULER_shutdown (); |
232 | return; | 233 | return; |
233 | } | 234 | } |
234 | (void) GNUNET_asprintf (&fn, "%s/%.*s_%jd.dat", dir, hname_len, hname, | 235 | GNUNET_asprintf (&fn, |
235 | (intmax_t) pid); | 236 | "%s/%.*s_%jd.dat", |
237 | dir, | ||
238 | hname_len, | ||
239 | hname, | ||
240 | (intmax_t) pid); | ||
236 | GNUNET_free (hname); | 241 | GNUNET_free (hname); |
237 | GNUNET_free (dir); | 242 | GNUNET_free (dir); |
238 | if (NULL == (bio = GNUNET_BIO_write_open (fn))) | 243 | if (NULL == (bio = GNUNET_BIO_write_open (fn))) |
@@ -245,9 +250,7 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
245 | GNUNET_SERVER_add_handlers (server, message_handlers); | 250 | GNUNET_SERVER_add_handlers (server, message_handlers); |
246 | GNUNET_SERVER_connect_notify (server, &client_connected, NULL); | 251 | GNUNET_SERVER_connect_notify (server, &client_connected, NULL); |
247 | GNUNET_SERVER_disconnect_notify (server, &client_disconnected, NULL); | 252 | GNUNET_SERVER_disconnect_notify (server, &client_disconnected, NULL); |
248 | shutdown_task_id = | 253 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
249 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
250 | &shutdown_task, NULL); | ||
251 | LOG_DEBUG ("TESTBED-LOGGER startup complete\n"); | 254 | LOG_DEBUG ("TESTBED-LOGGER startup complete\n"); |
252 | } | 255 | } |
253 | 256 | ||
@@ -258,11 +261,10 @@ logger_run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
258 | int | 261 | int |
259 | main (int argc, char *const *argv) | 262 | main (int argc, char *const *argv) |
260 | { | 263 | { |
261 | //sleep (15); /* Debugging */ | ||
262 | return (GNUNET_OK == | 264 | return (GNUNET_OK == |
263 | GNUNET_SERVICE_run (argc, argv, "testbed-logger", | 265 | GNUNET_SERVICE_run (argc, argv, "testbed-logger", |
264 | GNUNET_SERVICE_OPTION_NONE, | 266 | GNUNET_SERVICE_OPTION_NONE, |
265 | &logger_run, NULL)) ? 0 : 1; | 267 | &logger_run, NULL)) ? 0 : 1; |
266 | } | 268 | } |
267 | 269 | ||
268 | /* end of gnunet-service-testbed.c */ | 270 | /* end of gnunet-service-testbed-logger.c */ |