summaryrefslogtreecommitdiff
path: root/src/testbed-logger
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/testbed-logger
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/testbed-logger')
-rw-r--r--src/testbed-logger/gnunet-service-testbed-logger.c196
-rw-r--r--src/testbed-logger/test_testbed_logger_api.c228
-rw-r--r--src/testbed-logger/testbed_logger_api.c183
3 files changed, 303 insertions, 304 deletions
diff --git a/src/testbed-logger/gnunet-service-testbed-logger.c b/src/testbed-logger/gnunet-service-testbed-logger.c
index 25217cdfb..e2f71070b 100644
--- a/src/testbed-logger/gnunet-service-testbed-logger.c
+++ b/src/testbed-logger/gnunet-service-testbed-logger.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2008--2013 GNUnet e.V. 3 Copyright (C) 2008--2013 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
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/** 21/**
22 * @file testbed-logger/gnunet-service-testbed-logger.c 22 * @file testbed-logger/gnunet-service-testbed-logger.c
@@ -31,13 +31,13 @@
31 * Generic logging shorthand 31 * Generic logging shorthand
32 */ 32 */
33#define LOG(type, ...) \ 33#define LOG(type, ...) \
34 GNUNET_log (type, __VA_ARGS__) 34 GNUNET_log(type, __VA_ARGS__)
35 35
36/** 36/**
37 * Debug logging shorthand 37 * Debug logging shorthand
38 */ 38 */
39#define LOG_DEBUG(...) \ 39#define LOG_DEBUG(...) \
40 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) 40 LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
41 41
42/** 42/**
43 * Handle for buffered writing. 43 * Handle for buffered writing.
@@ -63,8 +63,8 @@ static int in_shutdown;
63 * @return #GNUNET_OK (they are all always OK) 63 * @return #GNUNET_OK (they are all always OK)
64 */ 64 */
65static int 65static int
66check_log_msg (void *cls, 66check_log_msg(void *cls,
67 const struct GNUNET_MessageHeader *msg) 67 const struct GNUNET_MessageHeader *msg)
68{ 68{
69 return GNUNET_OK; 69 return GNUNET_OK;
70} 70}
@@ -77,17 +77,17 @@ check_log_msg (void *cls,
77 * @param msg the actual message 77 * @param msg the actual message
78 */ 78 */
79static void 79static void
80handle_log_msg (void *cls, 80handle_log_msg(void *cls,
81 const struct GNUNET_MessageHeader *msg) 81 const struct GNUNET_MessageHeader *msg)
82{ 82{
83 struct GNUNET_SERVICE_Client *client = cls; 83 struct GNUNET_SERVICE_Client *client = cls;
84 uint16_t ms; 84 uint16_t ms;
85 85
86 ms = ntohs (msg->size) - sizeof (struct GNUNET_MessageHeader); 86 ms = ntohs(msg->size) - sizeof(struct GNUNET_MessageHeader);
87 GNUNET_BIO_write (bio, 87 GNUNET_BIO_write(bio,
88 &msg[1], 88 &msg[1],
89 ms); 89 ms);
90 GNUNET_SERVICE_client_continue (client); 90 GNUNET_SERVICE_client_continue(client);
91} 91}
92 92
93 93
@@ -97,18 +97,18 @@ handle_log_msg (void *cls,
97 * @param cls NULL 97 * @param cls NULL
98 */ 98 */
99static void 99static void
100shutdown_task (void *cls) 100shutdown_task(void *cls)
101{ 101{
102 in_shutdown = GNUNET_YES; 102 in_shutdown = GNUNET_YES;
103 if (0 != nconn) 103 if (0 != nconn)
104 { 104 {
105 /* Delay shutdown if there are active connections */ 105 /* Delay shutdown if there are active connections */
106 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 106 GNUNET_SCHEDULER_add_shutdown(&shutdown_task,
107 NULL); 107 NULL);
108 return; 108 return;
109 } 109 }
110 GNUNET_break (GNUNET_OK == 110 GNUNET_break(GNUNET_OK ==
111 GNUNET_BIO_write_close (bio)); 111 GNUNET_BIO_write_close(bio));
112} 112}
113 113
114 114
@@ -121,12 +121,12 @@ shutdown_task (void *cls)
121 * @return @a c 121 * @return @a c
122 */ 122 */
123static void * 123static void *
124client_connect_cb (void *cls, 124client_connect_cb(void *cls,
125 struct GNUNET_SERVICE_Client *c, 125 struct GNUNET_SERVICE_Client *c,
126 struct GNUNET_MQ_Handle *mq) 126 struct GNUNET_MQ_Handle *mq)
127{ 127{
128 /* FIXME: is this really what we want here? */ 128 /* FIXME: is this really what we want here? */
129 GNUNET_SERVICE_client_persist (c); 129 GNUNET_SERVICE_client_persist(c);
130 nconn++; 130 nconn++;
131 return c; 131 return c;
132} 132}
@@ -140,14 +140,14 @@ client_connect_cb (void *cls,
140 * @param internal_cls should be equal to @a c 140 * @param internal_cls should be equal to @a c
141 */ 141 */
142static void 142static void
143client_disconnect_cb (void *cls, 143client_disconnect_cb(void *cls,
144 struct GNUNET_SERVICE_Client *c, 144 struct GNUNET_SERVICE_Client *c,
145 void *internal_cls) 145 void *internal_cls)
146{ 146{
147 nconn--; 147 nconn--;
148 if (GNUNET_YES == in_shutdown) 148 if (GNUNET_YES == in_shutdown)
149 GNUNET_SCHEDULER_shutdown (); 149 GNUNET_SCHEDULER_shutdown();
150 GNUNET_assert (c == internal_cls); 150 GNUNET_assert(c == internal_cls);
151} 151}
152 152
153 153
@@ -159,9 +159,9 @@ client_disconnect_cb (void *cls,
159 * @param service the initialized service 159 * @param service the initialized service
160 */ 160 */
161static void 161static void
162logger_run (void *cls, 162logger_run(void *cls,
163 const struct GNUNET_CONFIGURATION_Handle *cfg, 163 const struct GNUNET_CONFIGURATION_Handle *cfg,
164 struct GNUNET_SERVICE_Handle *service) 164 struct GNUNET_SERVICE_Handle *service)
165{ 165{
166 char *dir; 166 char *dir;
167 char *fn; 167 char *fn;
@@ -170,48 +170,48 @@ logger_run (void *cls,
170 pid_t pid; 170 pid_t pid;
171 171
172 if (GNUNET_OK != 172 if (GNUNET_OK !=
173 GNUNET_CONFIGURATION_get_value_filename (cfg, 173 GNUNET_CONFIGURATION_get_value_filename(cfg,
174 "TESTBED-LOGGER", 174 "TESTBED-LOGGER",
175 "DIR", 175 "DIR",
176 &dir)) 176 &dir))
177 { 177 {
178 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 178 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
179 "TESTBED-LOGGER", 179 "TESTBED-LOGGER",
180 "DIR"); 180 "DIR");
181 GNUNET_SCHEDULER_shutdown (); 181 GNUNET_SCHEDULER_shutdown();
182 return; 182 return;
183 } 183 }
184 pid = getpid (); 184 pid = getpid();
185 hname_len = GNUNET_OS_get_hostname_max_length (); 185 hname_len = GNUNET_OS_get_hostname_max_length();
186 hname = GNUNET_malloc (hname_len); 186 hname = GNUNET_malloc(hname_len);
187 if (0 != gethostname (hname, 187 if (0 != gethostname(hname,
188 hname_len)) 188 hname_len))
189 { 189 {
190 LOG (GNUNET_ERROR_TYPE_ERROR, 190 LOG(GNUNET_ERROR_TYPE_ERROR,
191 "Cannot get hostname. Exiting\n"); 191 "Cannot get hostname. Exiting\n");
192 GNUNET_free (hname); 192 GNUNET_free(hname);
193 GNUNET_free (dir); 193 GNUNET_free(dir);
194 GNUNET_SCHEDULER_shutdown (); 194 GNUNET_SCHEDULER_shutdown();
195 return; 195 return;
196 } 196 }
197 GNUNET_asprintf (&fn, 197 GNUNET_asprintf(&fn,
198 "%s/%.*s_%jd.dat", 198 "%s/%.*s_%jd.dat",
199 dir, 199 dir,
200 hname_len, 200 hname_len,
201 hname, 201 hname,
202 (intmax_t) pid); 202 (intmax_t)pid);
203 GNUNET_free (hname); 203 GNUNET_free(hname);
204 GNUNET_free (dir); 204 GNUNET_free(dir);
205 if (NULL == (bio = GNUNET_BIO_write_open (fn))) 205 if (NULL == (bio = GNUNET_BIO_write_open(fn)))
206 { 206 {
207 GNUNET_free (fn); 207 GNUNET_free(fn);
208 GNUNET_SCHEDULER_shutdown (); 208 GNUNET_SCHEDULER_shutdown();
209 return; 209 return;
210 } 210 }
211 GNUNET_free (fn); 211 GNUNET_free(fn);
212 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 212 GNUNET_SCHEDULER_add_shutdown(&shutdown_task,
213 NULL); 213 NULL);
214 LOG_DEBUG ("TESTBED-LOGGER startup complete\n"); 214 LOG_DEBUG("TESTBED-LOGGER startup complete\n");
215} 215}
216 216
217 217
@@ -219,17 +219,17 @@ logger_run (void *cls,
219 * Define "main" method using service macro. 219 * Define "main" method using service macro.
220 */ 220 */
221GNUNET_SERVICE_MAIN 221GNUNET_SERVICE_MAIN
222("testbed-logger", 222 ("testbed-logger",
223 GNUNET_SERVICE_OPTION_NONE, 223 GNUNET_SERVICE_OPTION_NONE,
224 &logger_run, 224 &logger_run,
225 &client_connect_cb, 225 &client_connect_cb,
226 &client_disconnect_cb, 226 &client_disconnect_cb,
227 NULL, 227 NULL,
228 GNUNET_MQ_hd_var_size (log_msg, 228 GNUNET_MQ_hd_var_size(log_msg,
229 GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, 229 GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG,
230 struct GNUNET_MessageHeader, 230 struct GNUNET_MessageHeader,
231 NULL), 231 NULL),
232 GNUNET_MQ_handler_end ()); 232 GNUNET_MQ_handler_end());
233 233
234 234
235/* end of gnunet-service-testbed-logger.c */ 235/* end of gnunet-service-testbed-logger.c */
diff --git a/src/testbed-logger/test_testbed_logger_api.c b/src/testbed-logger/test_testbed_logger_api.c
index 11c166f25..3d228cdb1 100644
--- a/src/testbed-logger/test_testbed_logger_api.c
+++ b/src/testbed-logger/test_testbed_logger_api.c
@@ -11,7 +11,7 @@
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
@@ -30,14 +30,14 @@
30/** 30/**
31 * Generic logging shortcut 31 * Generic logging shortcut
32 */ 32 */
33#define LOG(kind,...) \ 33#define LOG(kind, ...) \
34 GNUNET_log (kind, __VA_ARGS__) 34 GNUNET_log(kind, __VA_ARGS__)
35 35
36/** 36/**
37 * Relative time seconds shorthand 37 * Relative time seconds shorthand
38 */ 38 */
39#define TIME_REL_SECS(sec) \ 39#define TIME_REL_SECS(sec) \
40 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) 40 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, sec)
41 41
42/** 42/**
43 * Opaque handle for the logging service 43 * Opaque handle for the logging service
@@ -57,23 +57,23 @@ static struct GNUNET_SCHEDULER_Task *write_task;
57static int result; 57static int result;
58 58
59#define CANCEL_TASK(task) do { \ 59#define CANCEL_TASK(task) do { \
60 if (NULL != task) \ 60 if (NULL != task) \
61 { \ 61 { \
62 GNUNET_SCHEDULER_cancel (task); \ 62 GNUNET_SCHEDULER_cancel(task); \
63 task = NULL; \ 63 task = NULL; \
64 } \ 64 } \
65 } while (0) 65 } while (0)
66 66
67/** 67/**
68 * shortcut to exit during failure 68 * shortcut to exit during failure
69 */ 69 */
70#define FAIL_TEST(cond, ret) do { \ 70#define FAIL_TEST(cond, ret) do { \
71 if (!(cond)) { \ 71 if (!(cond)) { \
72 GNUNET_break(0); \ 72 GNUNET_break(0); \
73 CANCEL_TASK (abort_task); \ 73 CANCEL_TASK(abort_task); \
74 abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \ 74 abort_task = GNUNET_SCHEDULER_add_now(&do_abort, NULL); \
75 ret; \ 75 ret; \
76 } \ 76 } \
77 } while (0) 77 } while (0)
78 78
79 79
@@ -84,24 +84,24 @@ static int result;
84 * @param tc the task context 84 * @param tc the task context
85 */ 85 */
86static void 86static void
87shutdown_now () 87shutdown_now()
88{ 88{
89 CANCEL_TASK (abort_task); 89 CANCEL_TASK(abort_task);
90 CANCEL_TASK (write_task); 90 CANCEL_TASK(write_task);
91 GNUNET_free_non_null (search_dir); 91 GNUNET_free_non_null(search_dir);
92 if (NULL != h) 92 if (NULL != h)
93 GNUNET_TESTBED_LOGGER_disconnect (h); 93 GNUNET_TESTBED_LOGGER_disconnect(h);
94 GNUNET_SCHEDULER_shutdown (); 94 GNUNET_SCHEDULER_shutdown();
95} 95}
96 96
97 97
98static void 98static void
99do_abort (void *cls) 99do_abort(void *cls)
100{ 100{
101 LOG (GNUNET_ERROR_TYPE_WARNING, 101 LOG(GNUNET_ERROR_TYPE_WARNING,
102 "Aborting\n"); 102 "Aborting\n");
103 abort_task = NULL; 103 abort_task = NULL;
104 shutdown_now (); 104 shutdown_now();
105} 105}
106 106
107 107
@@ -118,40 +118,40 @@ do_abort (void *cls)
118 * #GNUNET_SYSERR to abort iteration with error! 118 * #GNUNET_SYSERR to abort iteration with error!
119 */ 119 */
120static int 120static int
121iterator_cb (void *cls, 121iterator_cb(void *cls,
122 const char *filename) 122 const char *filename)
123{ 123{
124 const char *fn; 124 const char *fn;
125 size_t len; 125 size_t len;
126 uint64_t fs; 126 uint64_t fs;
127 127
128 LOG (GNUNET_ERROR_TYPE_DEBUG, 128 LOG(GNUNET_ERROR_TYPE_DEBUG,
129 "Iterator sees file %s\n", 129 "Iterator sees file %s\n",
130 filename); 130 filename);
131 len = strlen (filename); 131 len = strlen(filename);
132 fn = filename + len; 132 fn = filename + len;
133 if (0 != strcasecmp (".dat", fn - 4)) 133 if (0 != strcasecmp(".dat", fn - 4))
134 return GNUNET_OK; 134 return GNUNET_OK;
135 if (GNUNET_OK != 135 if (GNUNET_OK !=
136 GNUNET_DISK_file_size (filename, 136 GNUNET_DISK_file_size(filename,
137 &fs, 137 &fs,
138 GNUNET_NO, 138 GNUNET_NO,
139 GNUNET_YES)) 139 GNUNET_YES))
140 { 140 {
141 LOG (GNUNET_ERROR_TYPE_DEBUG, 141 LOG(GNUNET_ERROR_TYPE_DEBUG,
142 "Failed to obtain file size for file %s\n", 142 "Failed to obtain file size for file %s\n",
143 filename); 143 filename);
144 return GNUNET_SYSERR; 144 return GNUNET_SYSERR;
145 } 145 }
146 if ((BSIZE * 2) != fs) 146 if ((BSIZE * 2) != fs)
147 { 147 {
148 LOG (GNUNET_ERROR_TYPE_DEBUG, 148 LOG(GNUNET_ERROR_TYPE_DEBUG,
149 "Unexpected file size for file %s\n", 149 "Unexpected file size for file %s\n",
150 filename); 150 filename);
151 /* The file size should be equal to what we 151 /* The file size should be equal to what we
152 have written */ 152 have written */
153 return GNUNET_SYSERR; 153 return GNUNET_SYSERR;
154 } 154 }
155 result = GNUNET_OK; 155 result = GNUNET_OK;
156 return GNUNET_OK; 156 return GNUNET_OK;
157} 157}
@@ -165,52 +165,52 @@ iterator_cb (void *cls,
165 * @param size the amount of data sent 165 * @param size the amount of data sent
166 */ 166 */
167static void 167static void
168flush_comp (void *cls, 168flush_comp(void *cls,
169 size_t size) 169 size_t size)
170{ 170{
171 LOG (GNUNET_ERROR_TYPE_DEBUG, 171 LOG(GNUNET_ERROR_TYPE_DEBUG,
172 "Flush running\n"); 172 "Flush running\n");
173 FAIL_TEST (&write_task == cls, 173 FAIL_TEST(&write_task == cls,
174 return); 174 return );
175 FAIL_TEST ((BSIZE * 2) == size, 175 FAIL_TEST((BSIZE * 2) == size,
176 return); 176 return );
177 FAIL_TEST (GNUNET_OK == 177 FAIL_TEST(GNUNET_OK ==
178 GNUNET_TESTING_peer_stop (peer), 178 GNUNET_TESTING_peer_stop(peer),
179 return); 179 return );
180 LOG (GNUNET_ERROR_TYPE_DEBUG, 180 LOG(GNUNET_ERROR_TYPE_DEBUG,
181 "Peer stopped, scanning %s\n", 181 "Peer stopped, scanning %s\n",
182 search_dir); 182 search_dir);
183 FAIL_TEST (GNUNET_SYSERR != 183 FAIL_TEST(GNUNET_SYSERR !=
184 GNUNET_DISK_directory_scan (search_dir, 184 GNUNET_DISK_directory_scan(search_dir,
185 &iterator_cb, 185 &iterator_cb,
186 NULL), 186 NULL),
187 return); 187 return );
188 shutdown_now (); 188 shutdown_now();
189} 189}
190 190
191 191
192static void 192static void
193do_write (void *cls) 193do_write(void *cls)
194{ 194{
195 static int i; 195 static int i;
196 char buf[BSIZE]; 196 char buf[BSIZE];
197 197
198 write_task = NULL; 198 write_task = NULL;
199 LOG (GNUNET_ERROR_TYPE_DEBUG, 199 LOG(GNUNET_ERROR_TYPE_DEBUG,
200 "Write task running\n"); 200 "Write task running\n");
201 if (0 == i) 201 if (0 == i)
202 write_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS(1), 202 write_task = GNUNET_SCHEDULER_add_delayed(TIME_REL_SECS(1),
203 &do_write, 203 &do_write,
204 NULL); 204 NULL);
205 (void) memset (buf, i, BSIZE); 205 (void)memset(buf, i, BSIZE);
206 GNUNET_TESTBED_LOGGER_write (h, 206 GNUNET_TESTBED_LOGGER_write(h,
207 buf, 207 buf,
208 BSIZE); 208 BSIZE);
209 if (0 == i++) 209 if (0 == i++)
210 return; 210 return;
211 GNUNET_TESTBED_LOGGER_flush (h, 211 GNUNET_TESTBED_LOGGER_flush(h,
212 &flush_comp, 212 &flush_comp,
213 &write_task); 213 &write_task);
214} 214}
215 215
216 216
@@ -223,26 +223,26 @@ do_write (void *cls)
223 * @param peer identity of the peer that was created 223 * @param peer identity of the peer that was created
224 */ 224 */
225static void 225static void
226test_main (void *cls, 226test_main(void *cls,
227 const struct GNUNET_CONFIGURATION_Handle *cfg, 227 const struct GNUNET_CONFIGURATION_Handle *cfg,
228 struct GNUNET_TESTING_Peer *p) 228 struct GNUNET_TESTING_Peer *p)
229{ 229{
230 LOG (GNUNET_ERROR_TYPE_DEBUG, 230 LOG(GNUNET_ERROR_TYPE_DEBUG,
231 "Connecting to logger\n"); 231 "Connecting to logger\n");
232 FAIL_TEST (NULL != (h = GNUNET_TESTBED_LOGGER_connect (cfg)), 232 FAIL_TEST(NULL != (h = GNUNET_TESTBED_LOGGER_connect(cfg)),
233 return); 233 return );
234 FAIL_TEST (GNUNET_OK == 234 FAIL_TEST(GNUNET_OK ==
235 GNUNET_CONFIGURATION_get_value_filename (cfg, 235 GNUNET_CONFIGURATION_get_value_filename(cfg,
236 "testbed-logger", 236 "testbed-logger",
237 "dir", 237 "dir",
238 &search_dir), 238 &search_dir),
239 return); 239 return );
240 peer = p; 240 peer = p;
241 write_task = GNUNET_SCHEDULER_add_now (&do_write, 241 write_task = GNUNET_SCHEDULER_add_now(&do_write,
242 NULL); 242 NULL);
243 abort_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (10), 243 abort_task = GNUNET_SCHEDULER_add_delayed(TIME_REL_SECS(10),
244 &do_abort, 244 &do_abort,
245 NULL); 245 NULL);
246} 246}
247 247
248 248
@@ -250,23 +250,23 @@ test_main (void *cls,
250 * Main function 250 * Main function
251 */ 251 */
252int 252int
253main (int argc, char **argv) 253main(int argc, char **argv)
254{ 254{
255 int ret; 255 int ret;
256 256
257 result = GNUNET_SYSERR; 257 result = GNUNET_SYSERR;
258 GNUNET_log_setup ("test-testbed-logger-api", 258 GNUNET_log_setup("test-testbed-logger-api",
259 "WARNING", 259 "WARNING",
260 NULL); 260 NULL);
261 GNUNET_break (GNUNET_OK == 261 GNUNET_break(GNUNET_OK ==
262 GNUNET_DISK_directory_remove ("/tmp/test-testbed")); 262 GNUNET_DISK_directory_remove("/tmp/test-testbed"));
263 ret = GNUNET_TESTING_service_run ("test-testbed-logger", 263 ret = GNUNET_TESTING_service_run("test-testbed-logger",
264 "testbed-logger", 264 "testbed-logger",
265 "test_testbed_logger_api.conf", 265 "test_testbed_logger_api.conf",
266 &test_main, 266 &test_main,
267 NULL); 267 NULL);
268 GNUNET_break (GNUNET_OK == 268 GNUNET_break(GNUNET_OK ==
269 GNUNET_DISK_directory_remove ("/tmp/test-testbed")); 269 GNUNET_DISK_directory_remove("/tmp/test-testbed"));
270 if (0 != ret) 270 if (0 != ret)
271 return 1; 271 return 1;
272 if (GNUNET_OK != result) 272 if (GNUNET_OK != result)
diff --git a/src/testbed-logger/testbed_logger_api.c b/src/testbed-logger/testbed_logger_api.c
index 5a550e876..6e383e3c7 100644
--- a/src/testbed-logger/testbed_logger_api.c
+++ b/src/testbed-logger/testbed_logger_api.c
@@ -11,7 +11,7 @@
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
@@ -33,19 +33,18 @@
33 * Generic logging shorthand 33 * Generic logging shorthand
34 */ 34 */
35#define LOG(kind, ...) \ 35#define LOG(kind, ...) \
36 GNUNET_log_from (kind, "testbed-logger-api", __VA_ARGS__) 36 GNUNET_log_from(kind, "testbed-logger-api", __VA_ARGS__)
37 37
38 38
39/** 39/**
40 * The size of the buffer we fill before sending out the message 40 * The size of the buffer we fill before sending out the message
41 */ 41 */
42#define BUFFER_SIZE (GNUNET_MAX_MESSAGE_SIZE - sizeof (struct GNUNET_MessageHeader)) 42#define BUFFER_SIZE (GNUNET_MAX_MESSAGE_SIZE - sizeof(struct GNUNET_MessageHeader))
43 43
44/** 44/**
45 * Connection handle for the logger service 45 * Connection handle for the logger service
46 */ 46 */
47struct GNUNET_TESTBED_LOGGER_Handle 47struct GNUNET_TESTBED_LOGGER_Handle {
48{
49 /** 48 /**
50 * Client connection 49 * Client connection
51 */ 50 */
@@ -99,7 +98,7 @@ struct GNUNET_TESTBED_LOGGER_Handle
99 * @param cls the logger handle 98 * @param cls the logger handle
100 */ 99 */
101static void 100static void
102call_flush_completion (void *cls) 101call_flush_completion(void *cls)
103{ 102{
104 struct GNUNET_TESTBED_LOGGER_Handle *h = cls; 103 struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
105 GNUNET_TESTBED_LOGGER_FlushCompletion cb; 104 GNUNET_TESTBED_LOGGER_FlushCompletion cb;
@@ -114,7 +113,7 @@ call_flush_completion (void *cls)
114 cb_cls = h->cb_cls; 113 cb_cls = h->cb_cls;
115 h->cb_cls = NULL; 114 h->cb_cls = NULL;
116 if (NULL != cb) 115 if (NULL != cb)
117 cb (cb_cls, bw); 116 cb(cb_cls, bw);
118} 117}
119 118
120 119
@@ -124,13 +123,13 @@ call_flush_completion (void *cls)
124 * @param h logger handle 123 * @param h logger handle
125 */ 124 */
126static void 125static void
127trigger_flush_notification (struct GNUNET_TESTBED_LOGGER_Handle *h) 126trigger_flush_notification(struct GNUNET_TESTBED_LOGGER_Handle *h)
128{ 127{
129 if (NULL != h->flush_completion_task) 128 if (NULL != h->flush_completion_task)
130 GNUNET_SCHEDULER_cancel (h->flush_completion_task); 129 GNUNET_SCHEDULER_cancel(h->flush_completion_task);
131 h->flush_completion_task 130 h->flush_completion_task
132 = GNUNET_SCHEDULER_add_now (&call_flush_completion, 131 = GNUNET_SCHEDULER_add_now(&call_flush_completion,
133 h); 132 h);
134} 133}
135 134
136 135
@@ -140,7 +139,7 @@ trigger_flush_notification (struct GNUNET_TESTBED_LOGGER_Handle *h)
140 * @param h the logger handle 139 * @param h the logger handle
141 */ 140 */
142static void 141static void
143dispatch_buffer (struct GNUNET_TESTBED_LOGGER_Handle *h); 142dispatch_buffer(struct GNUNET_TESTBED_LOGGER_Handle *h);
144 143
145 144
146/** 145/**
@@ -149,19 +148,19 @@ dispatch_buffer (struct GNUNET_TESTBED_LOGGER_Handle *h);
149 * @param cls our handle 148 * @param cls our handle
150 */ 149 */
151static void 150static void
152notify_sent (void *cls) 151notify_sent(void *cls)
153{ 152{
154 struct GNUNET_TESTBED_LOGGER_Handle *h = cls; 153 struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
155 154
156 h->mq_len--; 155 h->mq_len--;
157 if ( (0 == h->mq_len) && 156 if ((0 == h->mq_len) &&
158 (NULL != h->cb) ) 157 (NULL != h->cb))
159 { 158 {
160 if (0 == h->buse) 159 if (0 == h->buse)
161 trigger_flush_notification (h); 160 trigger_flush_notification(h);
162 else 161 else
163 dispatch_buffer (h); 162 dispatch_buffer(h);
164 } 163 }
165} 164}
166 165
167 166
@@ -171,25 +170,25 @@ notify_sent (void *cls)
171 * @param h the logger handle 170 * @param h the logger handle
172 */ 171 */
173static void 172static void
174dispatch_buffer (struct GNUNET_TESTBED_LOGGER_Handle *h) 173dispatch_buffer(struct GNUNET_TESTBED_LOGGER_Handle *h)
175{ 174{
176 struct GNUNET_MessageHeader *msg; 175 struct GNUNET_MessageHeader *msg;
177 struct GNUNET_MQ_Envelope *env; 176 struct GNUNET_MQ_Envelope *env;
178 177
179 env = GNUNET_MQ_msg_extra (msg, 178 env = GNUNET_MQ_msg_extra(msg,
180 h->buse, 179 h->buse,
181 GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG); 180 GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG);
182 GNUNET_memcpy (&msg[1], 181 GNUNET_memcpy(&msg[1],
183 h->buf, 182 h->buf,
184 h->buse); 183 h->buse);
185 h->bwrote += h->buse; 184 h->bwrote += h->buse;
186 h->buse = 0; 185 h->buse = 0;
187 h->mq_len++; 186 h->mq_len++;
188 GNUNET_MQ_notify_sent (env, 187 GNUNET_MQ_notify_sent(env,
189 &notify_sent, 188 &notify_sent,
190 h); 189 h);
191 GNUNET_MQ_send (h->mq, 190 GNUNET_MQ_send(h->mq,
192 env); 191 env);
193} 192}
194 193
195 194
@@ -200,13 +199,13 @@ dispatch_buffer (struct GNUNET_TESTBED_LOGGER_Handle *h)
200 * @param error error code 199 * @param error error code
201 */ 200 */
202static void 201static void
203mq_error_handler (void *cls, 202mq_error_handler(void *cls,
204 enum GNUNET_MQ_Error error) 203 enum GNUNET_MQ_Error error)
205{ 204{
206 struct GNUNET_TESTBED_LOGGER_Handle *h = cls; 205 struct GNUNET_TESTBED_LOGGER_Handle *h = cls;
207 206
208 GNUNET_break (0); 207 GNUNET_break(0);
209 GNUNET_MQ_destroy (h->mq); 208 GNUNET_MQ_destroy(h->mq);
210 h->mq = NULL; 209 h->mq = NULL;
211} 210}
212 211
@@ -219,21 +218,21 @@ mq_error_handler (void *cls,
219 * upon any error 218 * upon any error
220 */ 219 */
221struct GNUNET_TESTBED_LOGGER_Handle * 220struct GNUNET_TESTBED_LOGGER_Handle *
222GNUNET_TESTBED_LOGGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) 221GNUNET_TESTBED_LOGGER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
223{ 222{
224 struct GNUNET_TESTBED_LOGGER_Handle *h; 223 struct GNUNET_TESTBED_LOGGER_Handle *h;
225 224
226 h = GNUNET_new (struct GNUNET_TESTBED_LOGGER_Handle); 225 h = GNUNET_new(struct GNUNET_TESTBED_LOGGER_Handle);
227 h->mq = GNUNET_CLIENT_connect (cfg, 226 h->mq = GNUNET_CLIENT_connect(cfg,
228 "testbed-logger", 227 "testbed-logger",
229 NULL, 228 NULL,
230 &mq_error_handler, 229 &mq_error_handler,
231 h); 230 h);
232 if (NULL == h->mq) 231 if (NULL == h->mq)
233 { 232 {
234 GNUNET_free (h); 233 GNUNET_free(h);
235 return NULL; 234 return NULL;
236 } 235 }
237 return h; 236 return h;
238} 237}
239 238
@@ -244,23 +243,23 @@ GNUNET_TESTBED_LOGGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
244 * @param h the logger handle 243 * @param h the logger handle
245 */ 244 */
246void 245void
247GNUNET_TESTBED_LOGGER_disconnect (struct GNUNET_TESTBED_LOGGER_Handle *h) 246GNUNET_TESTBED_LOGGER_disconnect(struct GNUNET_TESTBED_LOGGER_Handle *h)
248{ 247{
249 if (NULL != h->flush_completion_task) 248 if (NULL != h->flush_completion_task)
250 { 249 {
251 GNUNET_SCHEDULER_cancel (h->flush_completion_task); 250 GNUNET_SCHEDULER_cancel(h->flush_completion_task);
252 h->flush_completion_task = NULL; 251 h->flush_completion_task = NULL;
253 } 252 }
254 if (0 != h->mq_len) 253 if (0 != h->mq_len)
255 LOG (GNUNET_ERROR_TYPE_WARNING, 254 LOG(GNUNET_ERROR_TYPE_WARNING,
256 "Disconnect lost %u logger message[s]\n", 255 "Disconnect lost %u logger message[s]\n",
257 h->mq_len); 256 h->mq_len);
258 if (NULL != h->mq) 257 if (NULL != h->mq)
259 { 258 {
260 GNUNET_MQ_destroy (h->mq); 259 GNUNET_MQ_destroy(h->mq);
261 h->mq = NULL; 260 h->mq = NULL;
262 } 261 }
263 GNUNET_free (h); 262 GNUNET_free(h);
264} 263}
265 264
266 265
@@ -274,25 +273,25 @@ GNUNET_TESTBED_LOGGER_disconnect (struct GNUNET_TESTBED_LOGGER_Handle *h)
274 * @param size how many bytes of @a data to send 273 * @param size how many bytes of @a data to send
275 */ 274 */
276void 275void
277GNUNET_TESTBED_LOGGER_write (struct GNUNET_TESTBED_LOGGER_Handle *h, 276GNUNET_TESTBED_LOGGER_write(struct GNUNET_TESTBED_LOGGER_Handle *h,
278 const void *data, 277 const void *data,
279 size_t size) 278 size_t size)
280{ 279{
281 if (NULL == h->mq) 280 if (NULL == h->mq)
282 return; 281 return;
283 while (0 != size) 282 while (0 != size)
284 { 283 {
285 size_t fit_size = GNUNET_MIN (size, 284 size_t fit_size = GNUNET_MIN(size,
286 BUFFER_SIZE - h->buse); 285 BUFFER_SIZE - h->buse);
287 GNUNET_memcpy (&h->buf[h->buse], 286 GNUNET_memcpy(&h->buf[h->buse],
288 data, 287 data,
289 fit_size); 288 fit_size);
290 h->buse += fit_size; 289 h->buse += fit_size;
291 data += fit_size; 290 data += fit_size;
292 size -= fit_size; 291 size -= fit_size;
293 if (0 != size) 292 if (0 != size)
294 dispatch_buffer (h); 293 dispatch_buffer(h);
295 } 294 }
296} 295}
297 296
298 297
@@ -304,20 +303,20 @@ GNUNET_TESTBED_LOGGER_write (struct GNUNET_TESTBED_LOGGER_Handle *h,
304 * @param cb_cls the closure for the above callback 303 * @param cb_cls the closure for the above callback
305 */ 304 */
306void 305void
307GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h, 306GNUNET_TESTBED_LOGGER_flush(struct GNUNET_TESTBED_LOGGER_Handle *h,
308 GNUNET_TESTBED_LOGGER_FlushCompletion cb, 307 GNUNET_TESTBED_LOGGER_FlushCompletion cb,
309 void *cb_cls) 308 void *cb_cls)
310{ 309{
311 GNUNET_assert (NULL == h->cb); 310 GNUNET_assert(NULL == h->cb);
312 h->cb = cb; 311 h->cb = cb;
313 h->cb_cls = cb_cls; 312 h->cb_cls = cb_cls;
314 if ( (NULL == h->mq) || 313 if ((NULL == h->mq) ||
315 (0 == h->buse) ) 314 (0 == h->buse))
316 { 315 {
317 trigger_flush_notification (h); 316 trigger_flush_notification(h);
318 return; 317 return;
319 } 318 }
320 dispatch_buffer (h); 319 dispatch_buffer(h);
321} 320}
322 321
323 322
@@ -329,13 +328,13 @@ GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h,
329 * @param h the logger handle 328 * @param h the logger handle
330 */ 329 */
331void 330void
332GNUNET_TESTBED_LOGGER_flush_cancel (struct GNUNET_TESTBED_LOGGER_Handle *h) 331GNUNET_TESTBED_LOGGER_flush_cancel(struct GNUNET_TESTBED_LOGGER_Handle *h)
333{ 332{
334 if (NULL != h->flush_completion_task) 333 if (NULL != h->flush_completion_task)
335 { 334 {
336 GNUNET_SCHEDULER_cancel (h->flush_completion_task); 335 GNUNET_SCHEDULER_cancel(h->flush_completion_task);
337 h->flush_completion_task = NULL; 336 h->flush_completion_task = NULL;
338 } 337 }
339 h->cb = NULL; 338 h->cb = NULL;
340 h->cb_cls = NULL; 339 h->cb_cls = NULL;
341} 340}