diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/testbed-logger | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/testbed-logger')
-rw-r--r-- | src/testbed-logger/gnunet-service-testbed-logger.c | 158 | ||||
-rw-r--r-- | src/testbed-logger/test_testbed_logger_api.c | 228 | ||||
-rw-r--r-- | src/testbed-logger/testbed_logger_api.c | 174 |
3 files changed, 281 insertions, 279 deletions
diff --git a/src/testbed-logger/gnunet-service-testbed-logger.c b/src/testbed-logger/gnunet-service-testbed-logger.c index e2f71070b..4e0a3cd34 100644 --- a/src/testbed-logger/gnunet-service-testbed-logger.c +++ b/src/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 | */ |
65 | static int | 65 | static int |
66 | check_log_msg(void *cls, | 66 | check_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 | */ |
79 | static void | 79 | static void |
80 | handle_log_msg(void *cls, | 80 | handle_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 | */ |
99 | static void | 99 | static void |
100 | shutdown_task(void *cls) | 100 | shutdown_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 | */ |
123 | static void * | 123 | static void * |
124 | client_connect_cb(void *cls, | 124 | client_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 | */ |
142 | static void | 142 | static void |
143 | client_disconnect_cb(void *cls, | 143 | client_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 | */ |
161 | static void | 161 | static void |
162 | logger_run(void *cls, | 162 | logger_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 | ||
@@ -225,11 +225,11 @@ GNUNET_SERVICE_MAIN | |||
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 3d228cdb1..7496184c0 100644 --- a/src/testbed-logger/test_testbed_logger_api.c +++ b/src/testbed-logger/test_testbed_logger_api.c | |||
@@ -31,13 +31,13 @@ | |||
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,24 +57,24 @@ static struct GNUNET_SCHEDULER_Task *write_task; | |||
57 | static int result; | 57 | static 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 | ||
80 | /** | 80 | /** |
@@ -84,24 +84,24 @@ static int result; | |||
84 | * @param tc the task context | 84 | * @param tc the task context |
85 | */ | 85 | */ |
86 | static void | 86 | static void |
87 | shutdown_now() | 87 | shutdown_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 | ||
98 | static void | 98 | static void |
99 | do_abort(void *cls) | 99 | do_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 | */ |
120 | static int | 120 | static int |
121 | iterator_cb(void *cls, | 121 | iterator_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 | */ |
167 | static void | 167 | static void |
168 | flush_comp(void *cls, | 168 | flush_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 | ||
192 | static void | 192 | static void |
193 | do_write(void *cls) | 193 | do_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 | */ |
225 | static void | 225 | static void |
226 | test_main(void *cls, | 226 | test_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 | */ |
252 | int | 252 | int |
253 | main(int argc, char **argv) | 253 | main (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 6e383e3c7..58f3d36ce 100644 --- a/src/testbed-logger/testbed_logger_api.c +++ b/src/testbed-logger/testbed_logger_api.c | |||
@@ -33,18 +33,20 @@ | |||
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 \ |
43 | GNUNET_MessageHeader)) | ||
43 | 44 | ||
44 | /** | 45 | /** |
45 | * Connection handle for the logger service | 46 | * Connection handle for the logger service |
46 | */ | 47 | */ |
47 | struct GNUNET_TESTBED_LOGGER_Handle { | 48 | struct GNUNET_TESTBED_LOGGER_Handle |
49 | { | ||
48 | /** | 50 | /** |
49 | * Client connection | 51 | * Client connection |
50 | */ | 52 | */ |
@@ -98,7 +100,7 @@ struct GNUNET_TESTBED_LOGGER_Handle { | |||
98 | * @param cls the logger handle | 100 | * @param cls the logger handle |
99 | */ | 101 | */ |
100 | static void | 102 | static void |
101 | call_flush_completion(void *cls) | 103 | call_flush_completion (void *cls) |
102 | { | 104 | { |
103 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; | 105 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; |
104 | GNUNET_TESTBED_LOGGER_FlushCompletion cb; | 106 | GNUNET_TESTBED_LOGGER_FlushCompletion cb; |
@@ -113,7 +115,7 @@ call_flush_completion(void *cls) | |||
113 | cb_cls = h->cb_cls; | 115 | cb_cls = h->cb_cls; |
114 | h->cb_cls = NULL; | 116 | h->cb_cls = NULL; |
115 | if (NULL != cb) | 117 | if (NULL != cb) |
116 | cb(cb_cls, bw); | 118 | cb (cb_cls, bw); |
117 | } | 119 | } |
118 | 120 | ||
119 | 121 | ||
@@ -123,13 +125,13 @@ call_flush_completion(void *cls) | |||
123 | * @param h logger handle | 125 | * @param h logger handle |
124 | */ | 126 | */ |
125 | static void | 127 | static void |
126 | trigger_flush_notification(struct GNUNET_TESTBED_LOGGER_Handle *h) | 128 | trigger_flush_notification (struct GNUNET_TESTBED_LOGGER_Handle *h) |
127 | { | 129 | { |
128 | if (NULL != h->flush_completion_task) | 130 | if (NULL != h->flush_completion_task) |
129 | GNUNET_SCHEDULER_cancel(h->flush_completion_task); | 131 | GNUNET_SCHEDULER_cancel (h->flush_completion_task); |
130 | h->flush_completion_task | 132 | h->flush_completion_task |
131 | = GNUNET_SCHEDULER_add_now(&call_flush_completion, | 133 | = GNUNET_SCHEDULER_add_now (&call_flush_completion, |
132 | h); | 134 | h); |
133 | } | 135 | } |
134 | 136 | ||
135 | 137 | ||
@@ -139,7 +141,7 @@ trigger_flush_notification(struct GNUNET_TESTBED_LOGGER_Handle *h) | |||
139 | * @param h the logger handle | 141 | * @param h the logger handle |
140 | */ | 142 | */ |
141 | static void | 143 | static void |
142 | dispatch_buffer(struct GNUNET_TESTBED_LOGGER_Handle *h); | 144 | dispatch_buffer (struct GNUNET_TESTBED_LOGGER_Handle *h); |
143 | 145 | ||
144 | 146 | ||
145 | /** | 147 | /** |
@@ -148,19 +150,19 @@ dispatch_buffer(struct GNUNET_TESTBED_LOGGER_Handle *h); | |||
148 | * @param cls our handle | 150 | * @param cls our handle |
149 | */ | 151 | */ |
150 | static void | 152 | static void |
151 | notify_sent(void *cls) | 153 | notify_sent (void *cls) |
152 | { | 154 | { |
153 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; | 155 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; |
154 | 156 | ||
155 | h->mq_len--; | 157 | h->mq_len--; |
156 | if ((0 == h->mq_len) && | 158 | if ((0 == h->mq_len) && |
157 | (NULL != h->cb)) | 159 | (NULL != h->cb)) |
158 | { | 160 | { |
159 | if (0 == h->buse) | 161 | if (0 == h->buse) |
160 | trigger_flush_notification(h); | 162 | trigger_flush_notification (h); |
161 | else | 163 | else |
162 | dispatch_buffer(h); | 164 | dispatch_buffer (h); |
163 | } | 165 | } |
164 | } | 166 | } |
165 | 167 | ||
166 | 168 | ||
@@ -170,25 +172,25 @@ notify_sent(void *cls) | |||
170 | * @param h the logger handle | 172 | * @param h the logger handle |
171 | */ | 173 | */ |
172 | static void | 174 | static void |
173 | dispatch_buffer(struct GNUNET_TESTBED_LOGGER_Handle *h) | 175 | dispatch_buffer (struct GNUNET_TESTBED_LOGGER_Handle *h) |
174 | { | 176 | { |
175 | struct GNUNET_MessageHeader *msg; | 177 | struct GNUNET_MessageHeader *msg; |
176 | struct GNUNET_MQ_Envelope *env; | 178 | struct GNUNET_MQ_Envelope *env; |
177 | 179 | ||
178 | env = GNUNET_MQ_msg_extra(msg, | 180 | env = GNUNET_MQ_msg_extra (msg, |
179 | h->buse, | 181 | h->buse, |
180 | GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG); | 182 | GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG); |
181 | GNUNET_memcpy(&msg[1], | 183 | GNUNET_memcpy (&msg[1], |
182 | h->buf, | 184 | h->buf, |
183 | h->buse); | 185 | h->buse); |
184 | h->bwrote += h->buse; | 186 | h->bwrote += h->buse; |
185 | h->buse = 0; | 187 | h->buse = 0; |
186 | h->mq_len++; | 188 | h->mq_len++; |
187 | GNUNET_MQ_notify_sent(env, | 189 | GNUNET_MQ_notify_sent (env, |
188 | ¬ify_sent, | 190 | ¬ify_sent, |
189 | h); | 191 | h); |
190 | GNUNET_MQ_send(h->mq, | 192 | GNUNET_MQ_send (h->mq, |
191 | env); | 193 | env); |
192 | } | 194 | } |
193 | 195 | ||
194 | 196 | ||
@@ -199,13 +201,13 @@ dispatch_buffer(struct GNUNET_TESTBED_LOGGER_Handle *h) | |||
199 | * @param error error code | 201 | * @param error error code |
200 | */ | 202 | */ |
201 | static void | 203 | static void |
202 | mq_error_handler(void *cls, | 204 | mq_error_handler (void *cls, |
203 | enum GNUNET_MQ_Error error) | 205 | enum GNUNET_MQ_Error error) |
204 | { | 206 | { |
205 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; | 207 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; |
206 | 208 | ||
207 | GNUNET_break(0); | 209 | GNUNET_break (0); |
208 | GNUNET_MQ_destroy(h->mq); | 210 | GNUNET_MQ_destroy (h->mq); |
209 | h->mq = NULL; | 211 | h->mq = NULL; |
210 | } | 212 | } |
211 | 213 | ||
@@ -218,21 +220,21 @@ mq_error_handler(void *cls, | |||
218 | * upon any error | 220 | * upon any error |
219 | */ | 221 | */ |
220 | struct GNUNET_TESTBED_LOGGER_Handle * | 222 | struct GNUNET_TESTBED_LOGGER_Handle * |
221 | GNUNET_TESTBED_LOGGER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) | 223 | GNUNET_TESTBED_LOGGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |
222 | { | 224 | { |
223 | struct GNUNET_TESTBED_LOGGER_Handle *h; | 225 | struct GNUNET_TESTBED_LOGGER_Handle *h; |
224 | 226 | ||
225 | h = GNUNET_new(struct GNUNET_TESTBED_LOGGER_Handle); | 227 | h = GNUNET_new (struct GNUNET_TESTBED_LOGGER_Handle); |
226 | h->mq = GNUNET_CLIENT_connect(cfg, | 228 | h->mq = GNUNET_CLIENT_connect (cfg, |
227 | "testbed-logger", | 229 | "testbed-logger", |
228 | NULL, | 230 | NULL, |
229 | &mq_error_handler, | 231 | &mq_error_handler, |
230 | h); | 232 | h); |
231 | if (NULL == h->mq) | 233 | if (NULL == h->mq) |
232 | { | 234 | { |
233 | GNUNET_free(h); | 235 | GNUNET_free (h); |
234 | return NULL; | 236 | return NULL; |
235 | } | 237 | } |
236 | return h; | 238 | return h; |
237 | } | 239 | } |
238 | 240 | ||
@@ -243,23 +245,23 @@ GNUNET_TESTBED_LOGGER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
243 | * @param h the logger handle | 245 | * @param h the logger handle |
244 | */ | 246 | */ |
245 | void | 247 | void |
246 | GNUNET_TESTBED_LOGGER_disconnect(struct GNUNET_TESTBED_LOGGER_Handle *h) | 248 | GNUNET_TESTBED_LOGGER_disconnect (struct GNUNET_TESTBED_LOGGER_Handle *h) |
247 | { | 249 | { |
248 | if (NULL != h->flush_completion_task) | 250 | if (NULL != h->flush_completion_task) |
249 | { | 251 | { |
250 | GNUNET_SCHEDULER_cancel(h->flush_completion_task); | 252 | GNUNET_SCHEDULER_cancel (h->flush_completion_task); |
251 | h->flush_completion_task = NULL; | 253 | h->flush_completion_task = NULL; |
252 | } | 254 | } |
253 | if (0 != h->mq_len) | 255 | if (0 != h->mq_len) |
254 | LOG(GNUNET_ERROR_TYPE_WARNING, | 256 | LOG (GNUNET_ERROR_TYPE_WARNING, |
255 | "Disconnect lost %u logger message[s]\n", | 257 | "Disconnect lost %u logger message[s]\n", |
256 | h->mq_len); | 258 | h->mq_len); |
257 | if (NULL != h->mq) | 259 | if (NULL != h->mq) |
258 | { | 260 | { |
259 | GNUNET_MQ_destroy(h->mq); | 261 | GNUNET_MQ_destroy (h->mq); |
260 | h->mq = NULL; | 262 | h->mq = NULL; |
261 | } | 263 | } |
262 | GNUNET_free(h); | 264 | GNUNET_free (h); |
263 | } | 265 | } |
264 | 266 | ||
265 | 267 | ||
@@ -273,25 +275,25 @@ GNUNET_TESTBED_LOGGER_disconnect(struct GNUNET_TESTBED_LOGGER_Handle *h) | |||
273 | * @param size how many bytes of @a data to send | 275 | * @param size how many bytes of @a data to send |
274 | */ | 276 | */ |
275 | void | 277 | void |
276 | GNUNET_TESTBED_LOGGER_write(struct GNUNET_TESTBED_LOGGER_Handle *h, | 278 | GNUNET_TESTBED_LOGGER_write (struct GNUNET_TESTBED_LOGGER_Handle *h, |
277 | const void *data, | 279 | const void *data, |
278 | size_t size) | 280 | size_t size) |
279 | { | 281 | { |
280 | if (NULL == h->mq) | 282 | if (NULL == h->mq) |
281 | return; | 283 | return; |
282 | while (0 != size) | 284 | while (0 != size) |
283 | { | 285 | { |
284 | size_t fit_size = GNUNET_MIN(size, | 286 | size_t fit_size = GNUNET_MIN (size, |
285 | BUFFER_SIZE - h->buse); | 287 | BUFFER_SIZE - h->buse); |
286 | GNUNET_memcpy(&h->buf[h->buse], | 288 | GNUNET_memcpy (&h->buf[h->buse], |
287 | data, | 289 | data, |
288 | fit_size); | 290 | fit_size); |
289 | h->buse += fit_size; | 291 | h->buse += fit_size; |
290 | data += fit_size; | 292 | data += fit_size; |
291 | size -= fit_size; | 293 | size -= fit_size; |
292 | if (0 != size) | 294 | if (0 != size) |
293 | dispatch_buffer(h); | 295 | dispatch_buffer (h); |
294 | } | 296 | } |
295 | } | 297 | } |
296 | 298 | ||
297 | 299 | ||
@@ -303,20 +305,20 @@ GNUNET_TESTBED_LOGGER_write(struct GNUNET_TESTBED_LOGGER_Handle *h, | |||
303 | * @param cb_cls the closure for the above callback | 305 | * @param cb_cls the closure for the above callback |
304 | */ | 306 | */ |
305 | void | 307 | void |
306 | GNUNET_TESTBED_LOGGER_flush(struct GNUNET_TESTBED_LOGGER_Handle *h, | 308 | GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h, |
307 | GNUNET_TESTBED_LOGGER_FlushCompletion cb, | 309 | GNUNET_TESTBED_LOGGER_FlushCompletion cb, |
308 | void *cb_cls) | 310 | void *cb_cls) |
309 | { | 311 | { |
310 | GNUNET_assert(NULL == h->cb); | 312 | GNUNET_assert (NULL == h->cb); |
311 | h->cb = cb; | 313 | h->cb = cb; |
312 | h->cb_cls = cb_cls; | 314 | h->cb_cls = cb_cls; |
313 | if ((NULL == h->mq) || | 315 | if ((NULL == h->mq) || |
314 | (0 == h->buse)) | 316 | (0 == h->buse)) |
315 | { | 317 | { |
316 | trigger_flush_notification(h); | 318 | trigger_flush_notification (h); |
317 | return; | 319 | return; |
318 | } | 320 | } |
319 | dispatch_buffer(h); | 321 | dispatch_buffer (h); |
320 | } | 322 | } |
321 | 323 | ||
322 | 324 | ||
@@ -328,13 +330,13 @@ GNUNET_TESTBED_LOGGER_flush(struct GNUNET_TESTBED_LOGGER_Handle *h, | |||
328 | * @param h the logger handle | 330 | * @param h the logger handle |
329 | */ | 331 | */ |
330 | void | 332 | void |
331 | GNUNET_TESTBED_LOGGER_flush_cancel(struct GNUNET_TESTBED_LOGGER_Handle *h) | 333 | GNUNET_TESTBED_LOGGER_flush_cancel (struct GNUNET_TESTBED_LOGGER_Handle *h) |
332 | { | 334 | { |
333 | if (NULL != h->flush_completion_task) | 335 | if (NULL != h->flush_completion_task) |
334 | { | 336 | { |
335 | GNUNET_SCHEDULER_cancel(h->flush_completion_task); | 337 | GNUNET_SCHEDULER_cancel (h->flush_completion_task); |
336 | h->flush_completion_task = NULL; | 338 | h->flush_completion_task = NULL; |
337 | } | 339 | } |
338 | h->cb = NULL; | 340 | h->cb = NULL; |
339 | h->cb_cls = NULL; | 341 | h->cb_cls = NULL; |
340 | } | 342 | } |