diff options
-rw-r--r-- | src/include/Makefile.am | 1 | ||||
-rw-r--r-- | src/include/gnunet_protocols.h | 5 | ||||
-rw-r--r-- | src/include/gnunet_testbed_logger_service.h | 131 | ||||
-rw-r--r-- | src/testbed/Makefile.am | 12 | ||||
-rw-r--r-- | src/testbed/testbed.conf.in | 12 | ||||
-rw-r--r-- | src/testbed/testbed_logger_api.c | 402 |
6 files changed, 561 insertions, 2 deletions
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index e27fc7027..a82eab961 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am | |||
@@ -78,6 +78,7 @@ gnunetinclude_HEADERS = \ | |||
78 | gnunet_stream_lib.h \ | 78 | gnunet_stream_lib.h \ |
79 | gnunet_strings_lib.h \ | 79 | gnunet_strings_lib.h \ |
80 | gnunet_testbed_service.h \ | 80 | gnunet_testbed_service.h \ |
81 | gnunet_testbed_logger_service.h \ | ||
81 | gnunet_testing_lib.h \ | 82 | gnunet_testing_lib.h \ |
82 | gnunet_time_lib.h \ | 83 | gnunet_time_lib.h \ |
83 | gnunet_transport_service.h \ | 84 | gnunet_transport_service.h \ |
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index f65d76775..b49590390 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h | |||
@@ -1827,6 +1827,11 @@ extern "C" | |||
1827 | #define GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG 600 | 1827 | #define GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG 600 |
1828 | 1828 | ||
1829 | /** | 1829 | /** |
1830 | * Message for TESTBED LOGGER acknowledgement | ||
1831 | */ | ||
1832 | #define GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_ACK 601 | ||
1833 | |||
1834 | /** | ||
1830 | * Next available: 605 | 1835 | * Next available: 605 |
1831 | */ | 1836 | */ |
1832 | 1837 | ||
diff --git a/src/include/gnunet_testbed_logger_service.h b/src/include/gnunet_testbed_logger_service.h new file mode 100644 index 000000000..c8b4b7762 --- /dev/null +++ b/src/include/gnunet_testbed_logger_service.h | |||
@@ -0,0 +1,131 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008--2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
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 | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file include/gnunet_testbed_logger_service.h | ||
23 | * @brief API for submitting data to the testbed logger service | ||
24 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_TESTBED_LOGGER_SERVICE_H | ||
28 | #define GNUNET_TESTBED_LOGGER_SERVICE_H | ||
29 | |||
30 | #ifdef __cplusplus | ||
31 | extern "C" | ||
32 | { | ||
33 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
34 | } | ||
35 | #endif | ||
36 | #endif | ||
37 | |||
38 | #include "gnunet_configuration_lib.h" | ||
39 | |||
40 | /** | ||
41 | * Opaque handle for the logging service | ||
42 | */ | ||
43 | struct GNUNET_TESTBED_LOGGER_Handle; | ||
44 | |||
45 | |||
46 | /** | ||
47 | * Connect to the testbed logger service | ||
48 | * | ||
49 | * @param cfg configuration to use | ||
50 | * @return the handle which can be used for sending data to the service; NULL | ||
51 | * upon any error | ||
52 | */ | ||
53 | struct GNUNET_TESTBED_LOGGER_Handle * | ||
54 | GNUNET_TESTBED_LOGGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
55 | |||
56 | |||
57 | /** | ||
58 | * Disconnect from the logger service. Also cancels any pending send handles. | ||
59 | * | ||
60 | * @param h the logger handle | ||
61 | */ | ||
62 | void | ||
63 | GNUNET_TESTBED_LOGGER_disconnect (struct GNUNET_TESTBED_LOGGER_Handle *h); | ||
64 | |||
65 | |||
66 | /** | ||
67 | * Opaque handle representing a send request | ||
68 | */ | ||
69 | struct GNUNET_TESTBED_LOGGER_SendHandle; | ||
70 | |||
71 | |||
72 | /** | ||
73 | * Functions of this type are called to notify a successful transmission of the | ||
74 | * message to the logger service | ||
75 | * | ||
76 | * @param cls the closure given to GNUNET_TESTBED_LOGGER_send() | ||
77 | * @param size the amount of data sent | ||
78 | */ | ||
79 | typedef void (*GNUNET_TESTBED_LOGGER_FlushCompletion) (void *cls, size_t size); | ||
80 | |||
81 | |||
82 | /** | ||
83 | * Send data to be logged to the logger service. The data will be buffered and | ||
84 | * will be sent upon an explicit call to GNUNET_TESTBED_LOGGER_flush() or upon | ||
85 | * exceeding a threshold size. | ||
86 | * | ||
87 | * @param h the logger handle | ||
88 | * @param data the data to send; | ||
89 | * @param size how many bytes of data to send | ||
90 | * @param cb the callback to be called upon completion of the send request | ||
91 | * @param cb_cls the closure for the above callback | ||
92 | * @return the send handle which can used for cancelling the send operation. | ||
93 | * Will be invalid if upon call to completion callback | ||
94 | */ | ||
95 | void | ||
96 | GNUNET_TESTBED_LOGGER_write (struct GNUNET_TESTBED_LOGGER_Handle *h, | ||
97 | const void *data, size_t size); | ||
98 | |||
99 | |||
100 | /** | ||
101 | * Flush the buffered data to the logger service | ||
102 | * | ||
103 | * @param h the logger handle | ||
104 | * @param cb the callback to call after the data is flushed | ||
105 | * @param cb_cls the closure for the above callback | ||
106 | */ | ||
107 | void | ||
108 | GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h, | ||
109 | GNUNET_TESTBED_LOGGER_FlushCompletion cb, | ||
110 | void *cb_cls); | ||
111 | |||
112 | |||
113 | /** | ||
114 | * Cancel notification upon flush. | ||
115 | * | ||
116 | * @param h the logger handle | ||
117 | */ | ||
118 | void | ||
119 | GNUNET_TESTBED_LOGGER_flush_cancel (struct GNUNET_TESTBED_LOGGER_Handle *h); | ||
120 | |||
121 | |||
122 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
123 | { | ||
124 | #endif | ||
125 | #ifdef __cplusplus | ||
126 | } | ||
127 | #endif | ||
128 | |||
129 | #endif /* GNUNET_TESTBED_LOGGER_SERVICE_H */ | ||
130 | |||
131 | /* End of gnunet_testbed_logger_service.h */ | ||
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am index 871b64867..7d65e9fc2 100644 --- a/src/testbed/Makefile.am +++ b/src/testbed/Makefile.am | |||
@@ -83,7 +83,8 @@ gnunet_testbed_mpi_spawn_DEPENDENCIES = \ | |||
83 | libgnunettestbed.la | 83 | libgnunettestbed.la |
84 | 84 | ||
85 | lib_LTLIBRARIES = \ | 85 | lib_LTLIBRARIES = \ |
86 | libgnunettestbed.la | 86 | libgnunettestbed.la \ |
87 | libgnunettestbedlogger.la | ||
87 | 88 | ||
88 | libgnunettestbed_la_SOURCES = \ | 89 | libgnunettestbed_la_SOURCES = \ |
89 | testbed_api.c testbed_api.h testbed.h \ | 90 | testbed_api.c testbed_api.h testbed.h \ |
@@ -109,6 +110,15 @@ libgnunettestbed_la_LDFLAGS = \ | |||
109 | $(GN_LIB_LDFLAGS) \ | 110 | $(GN_LIB_LDFLAGS) \ |
110 | -version-info 0:0:0 | 111 | -version-info 0:0:0 |
111 | 112 | ||
113 | libgnunettestbedlogger_la_SOURCES = \ | ||
114 | testbed_logger_api.c | ||
115 | libgnunettestbedlogger_la_LIBADD = $(XLIB) \ | ||
116 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
117 | $(LTLIBINTL) | ||
118 | libgnunettestbedlogger_la_LDFLAGS = \ | ||
119 | $(GN_LIB_LDFLAGS) \ | ||
120 | -version-info 0:0:0 | ||
121 | |||
112 | check_PROGRAMS = \ | 122 | check_PROGRAMS = \ |
113 | test_testbed_api_hosts \ | 123 | test_testbed_api_hosts \ |
114 | test_gnunet_helper_testbed \ | 124 | test_gnunet_helper_testbed \ |
diff --git a/src/testbed/testbed.conf.in b/src/testbed/testbed.conf.in index 9dc269e5c..cf724409a 100644 --- a/src/testbed/testbed.conf.in +++ b/src/testbed/testbed.conf.in | |||
@@ -47,4 +47,14 @@ MAX_OPEN_FDS = 512 | |||
47 | SETUP_TIMEOUT = 5 m | 47 | SETUP_TIMEOUT = 5 m |
48 | 48 | ||
49 | # Where should testbed write load statistics data | 49 | # Where should testbed write load statistics data |
50 | # STATS_DIR = /tmp/load \ No newline at end of file | 50 | # STATS_DIR = /tmp/load |
51 | |||
52 | [testbed-logger] | ||
53 | AUTOSTART = NO | ||
54 | @UNIXONLY@ PORT = 2102 | ||
55 | HOSTNAME = localhost | ||
56 | BINARY = gnunet-service-testbed-logger | ||
57 | UNIXPaTH = /tmp/gnunet-gnunet-testbed-logger.sock | ||
58 | DIR = /tmp | ||
59 | UNIX_MATCH_UID = YES | ||
60 | UNIX_MATCH_GID = YES | ||
diff --git a/src/testbed/testbed_logger_api.c b/src/testbed/testbed_logger_api.c new file mode 100644 index 000000000..81e20dd2a --- /dev/null +++ b/src/testbed/testbed_logger_api.c | |||
@@ -0,0 +1,402 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | (C) 2008--2013 Christian Grothoff (and other contributing authors) | ||
4 | |||
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 | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed/testbed_logger_api.c | ||
23 | * @brief Client-side routines for communicating with the tesbted logger service | ||
24 | * @author Sree Harsha Totakura <sreeharsha@totakura.in> | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | #include "gnunet_testbed_logger_service.h" | ||
30 | |||
31 | /** | ||
32 | * Generic logging shorthand | ||
33 | */ | ||
34 | #define LOG(kind, ...) \ | ||
35 | GNUNET_log_from (kind, "testbed-logger-api", __VA_ARGS__) | ||
36 | |||
37 | /** | ||
38 | * Debug logging | ||
39 | */ | ||
40 | #define LOG_DEBUG(...) \ | ||
41 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | ||
42 | |||
43 | #ifdef GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD | ||
44 | #undef GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD | ||
45 | #endif | ||
46 | |||
47 | /** | ||
48 | * Threshold after which exponential backoff should not increase (15 s). | ||
49 | */ | ||
50 | #define GNUNET_TIME_STD_EXPONENTIAL_BACKOFF_THRESHOLD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3) | ||
51 | |||
52 | |||
53 | /** | ||
54 | * The message queue for sending messages to the controller service | ||
55 | */ | ||
56 | struct MessageQueue | ||
57 | { | ||
58 | /** | ||
59 | * next pointer for DLL | ||
60 | */ | ||
61 | struct MessageQueue *next; | ||
62 | |||
63 | /** | ||
64 | * prev pointer for DLL | ||
65 | */ | ||
66 | struct MessageQueue *prev; | ||
67 | |||
68 | /** | ||
69 | * The message to be sent | ||
70 | */ | ||
71 | struct GNUNET_MessageHeader *msg; | ||
72 | |||
73 | /** | ||
74 | * Completion callback | ||
75 | */ | ||
76 | GNUNET_TESTBED_LOGGER_FlushCompletion cb; | ||
77 | |||
78 | /** | ||
79 | * callback closure | ||
80 | */ | ||
81 | void *cb_cls; | ||
82 | }; | ||
83 | |||
84 | |||
85 | /** | ||
86 | * Connection handle for the logger service | ||
87 | */ | ||
88 | struct GNUNET_TESTBED_LOGGER_Handle | ||
89 | { | ||
90 | /** | ||
91 | * Client connection | ||
92 | */ | ||
93 | struct GNUNET_CLIENT_Connection *client; | ||
94 | |||
95 | struct GNUNET_CLIENT_TransmitHandle *th; | ||
96 | |||
97 | /** | ||
98 | * DLL head for the message queue | ||
99 | */ | ||
100 | struct MessageQueue *mq_head; | ||
101 | |||
102 | /** | ||
103 | * DLL tail for the message queue | ||
104 | */ | ||
105 | struct MessageQueue *mq_tail; | ||
106 | |||
107 | GNUNET_SCHEDULER_TaskIdentifier flush_completion_task; | ||
108 | |||
109 | GNUNET_TESTBED_LOGGER_FlushCompletion cb; | ||
110 | |||
111 | void *cb_cls; | ||
112 | |||
113 | void *buf; | ||
114 | |||
115 | size_t bs; | ||
116 | |||
117 | size_t bwrote; | ||
118 | |||
119 | struct GNUNET_TIME_Relative retry_backoff; | ||
120 | }; | ||
121 | |||
122 | |||
123 | /** | ||
124 | * Task to call the flush completion notification | ||
125 | * | ||
126 | * @param cls the logger handle | ||
127 | * @param tc the scheduler task context | ||
128 | */ | ||
129 | static void | ||
130 | call_flush_completion (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
131 | { | ||
132 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; | ||
133 | GNUNET_TESTBED_LOGGER_FlushCompletion cb; | ||
134 | void *cb_cls; | ||
135 | size_t bw; | ||
136 | |||
137 | h->flush_completion_task = GNUNET_SCHEDULER_NO_TASK; | ||
138 | bw = h->bwrote; | ||
139 | h->bwrote = 0; | ||
140 | cb = h->cb; | ||
141 | h->cb = NULL; | ||
142 | cb_cls = h->cb_cls; | ||
143 | h->cb_cls = NULL; | ||
144 | if (NULL != cb) | ||
145 | cb (cb_cls, bw); | ||
146 | } | ||
147 | |||
148 | |||
149 | /** | ||
150 | * Schedule the flush completion notification task | ||
151 | * | ||
152 | * @param | ||
153 | * @return | ||
154 | */ | ||
155 | static void | ||
156 | trigger_flush_notification (struct GNUNET_TESTBED_LOGGER_Handle *h) | ||
157 | { | ||
158 | if (GNUNET_SCHEDULER_NO_TASK != h->flush_completion_task) | ||
159 | GNUNET_SCHEDULER_cancel (h->flush_completion_task); | ||
160 | h->flush_completion_task = GNUNET_SCHEDULER_add_now (&call_flush_completion, h); | ||
161 | } | ||
162 | |||
163 | |||
164 | /** | ||
165 | * Function called to notify a client about the connection begin ready to queue | ||
166 | * more data. "buf" will be NULL and "size" zero if the connection was closed | ||
167 | * for writing in the meantime. | ||
168 | * | ||
169 | * @param cls closure | ||
170 | * @param size number of bytes available in buf | ||
171 | * @param buf where the callee should write the message | ||
172 | * @return number of bytes written to buf | ||
173 | */ | ||
174 | static size_t | ||
175 | transmit_ready_notify (void *cls, size_t size, void *buf) | ||
176 | { | ||
177 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; | ||
178 | struct MessageQueue *mq; | ||
179 | |||
180 | h->th = NULL; | ||
181 | mq = h->mq_head; | ||
182 | GNUNET_assert (NULL != mq); | ||
183 | if ((0 == size) && (NULL == buf)) /* Timeout */ | ||
184 | { | ||
185 | LOG_DEBUG ("Message sending timed out -- retrying\n"); | ||
186 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); | ||
187 | h->th = | ||
188 | GNUNET_CLIENT_notify_transmit_ready (h->client, | ||
189 | ntohs (mq->msg->size), | ||
190 | h->retry_backoff, GNUNET_YES, | ||
191 | &transmit_ready_notify, h); | ||
192 | return 0; | ||
193 | } | ||
194 | h->retry_backoff = GNUNET_TIME_UNIT_ZERO; | ||
195 | GNUNET_assert (ntohs (mq->msg->size) <= size); | ||
196 | size = ntohs (mq->msg->size); | ||
197 | memcpy (buf, mq->msg, size); | ||
198 | LOG_DEBUG ("Message of type: %u and size: %u sent\n", | ||
199 | ntohs (mq->msg->type), size); | ||
200 | GNUNET_free (mq->msg); | ||
201 | GNUNET_CONTAINER_DLL_remove (h->mq_head, h->mq_tail, mq); | ||
202 | GNUNET_free (mq); | ||
203 | h->bwrote += size; | ||
204 | mq = h->mq_head; | ||
205 | if (NULL != mq) | ||
206 | { | ||
207 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); | ||
208 | h->th = | ||
209 | GNUNET_CLIENT_notify_transmit_ready (h->client, | ||
210 | ntohs (mq->msg->size), | ||
211 | h->retry_backoff, GNUNET_YES, | ||
212 | &transmit_ready_notify, h); | ||
213 | return size; | ||
214 | } | ||
215 | if (NULL != h->cb) | ||
216 | trigger_flush_notification (h); /* Call the flush completion callback */ | ||
217 | return size; | ||
218 | } | ||
219 | |||
220 | |||
221 | /** | ||
222 | * Queues a message in send queue of the logger handle | ||
223 | * | ||
224 | * @param h the logger handle | ||
225 | * @param msg the message to queue | ||
226 | */ | ||
227 | static void | ||
228 | queue_message (struct GNUNET_TESTBED_LOGGER_Handle *h, | ||
229 | struct GNUNET_MessageHeader *msg) | ||
230 | { | ||
231 | struct MessageQueue *mq; | ||
232 | uint16_t type; | ||
233 | uint16_t size; | ||
234 | |||
235 | type = ntohs (msg->type); | ||
236 | size = ntohs (msg->size); | ||
237 | mq = GNUNET_malloc (sizeof (struct MessageQueue)); | ||
238 | mq->msg = msg; | ||
239 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
240 | "Queueing message of type %u, size %u for sending\n", type, | ||
241 | ntohs (msg->size)); | ||
242 | GNUNET_CONTAINER_DLL_insert_tail (h->mq_head, h->mq_tail, mq); | ||
243 | if (NULL == h->th) | ||
244 | { | ||
245 | h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); | ||
246 | h->th = | ||
247 | GNUNET_CLIENT_notify_transmit_ready (h->client, size, | ||
248 | h->retry_backoff, GNUNET_YES, | ||
249 | &transmit_ready_notify, | ||
250 | h); | ||
251 | } | ||
252 | } | ||
253 | |||
254 | |||
255 | /** | ||
256 | * Send the buffered data to the service | ||
257 | * | ||
258 | * @param h the logger handle | ||
259 | */ | ||
260 | static void | ||
261 | dispatch_buffer (struct GNUNET_TESTBED_LOGGER_Handle *h) | ||
262 | { | ||
263 | struct GNUNET_MessageHeader *msg; | ||
264 | size_t msize; | ||
265 | |||
266 | msize = sizeof (struct GNUNET_MessageHeader) + h->bs; | ||
267 | msg = GNUNET_realloc (h->buf, msize); | ||
268 | h->buf = NULL; | ||
269 | memmove (&msg[1], msg, h->bs); | ||
270 | h->bs = 0; | ||
271 | msg->type = htons (GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG); | ||
272 | msg->size = htons (msize); | ||
273 | queue_message (h, msg); | ||
274 | } | ||
275 | |||
276 | |||
277 | /** | ||
278 | * Connect to the testbed logger service | ||
279 | * | ||
280 | * @param cfg configuration to use | ||
281 | * @return the handle which can be used for sending data to the service; NULL | ||
282 | * upon any error | ||
283 | */ | ||
284 | struct GNUNET_TESTBED_LOGGER_Handle * | ||
285 | GNUNET_TESTBED_LOGGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
286 | { | ||
287 | struct GNUNET_TESTBED_LOGGER_Handle *h; | ||
288 | struct GNUNET_CLIENT_Connection *client; | ||
289 | |||
290 | client = GNUNET_CLIENT_connect ("testbed-logger", cfg); | ||
291 | if (NULL == client) | ||
292 | return NULL; | ||
293 | h = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_LOGGER_Handle)); | ||
294 | h->client = client; | ||
295 | return h; | ||
296 | } | ||
297 | |||
298 | |||
299 | /** | ||
300 | * Disconnect from the logger service. | ||
301 | * | ||
302 | * @param h the logger handle | ||
303 | */ | ||
304 | void | ||
305 | GNUNET_TESTBED_LOGGER_disconnect (struct GNUNET_TESTBED_LOGGER_Handle *h) | ||
306 | { | ||
307 | struct MessageQueue *mq; | ||
308 | |||
309 | if (GNUNET_SCHEDULER_NO_TASK != h->flush_completion_task) | ||
310 | GNUNET_SCHEDULER_cancel (h->flush_completion_task); | ||
311 | while (NULL != (mq = h->mq_head)) | ||
312 | { | ||
313 | GNUNET_CONTAINER_DLL_remove (h->mq_head, h->mq_tail, mq); | ||
314 | GNUNET_free (mq->msg); | ||
315 | GNUNET_free (mq); | ||
316 | } | ||
317 | GNUNET_CLIENT_disconnect (h->client); | ||
318 | GNUNET_free (h); | ||
319 | } | ||
320 | |||
321 | |||
322 | /** | ||
323 | * Send data to be logged to the logger service. The data will be buffered and | ||
324 | * will be sent upon an explicit call to GNUNET_TESTBED_LOGGER_flush() or upon | ||
325 | * exceeding a threshold size. | ||
326 | * | ||
327 | * @param h the logger handle | ||
328 | * @param data the data to send; | ||
329 | * @param size how many bytes of data to send | ||
330 | * @param cb the callback to be called upon completion of the send request | ||
331 | * @param cb_cls the closure for the above callback | ||
332 | * @return the send handle which can used for cancelling the send operation. | ||
333 | * Will be invalid if upon call to completion callback | ||
334 | */ | ||
335 | void | ||
336 | GNUNET_TESTBED_LOGGER_write (struct GNUNET_TESTBED_LOGGER_Handle *h, | ||
337 | const void *data, size_t size) | ||
338 | { | ||
339 | size_t fit_size; | ||
340 | |||
341 | GNUNET_assert (0 != size); | ||
342 | GNUNET_assert (NULL != data); | ||
343 | GNUNET_assert (size < (GNUNET_SERVER_MAX_MESSAGE_SIZE | ||
344 | - sizeof (struct GNUNET_MessageHeader))); | ||
345 | fit_size = sizeof (struct GNUNET_MessageHeader) + h->bs + size; | ||
346 | if ( GNUNET_SERVER_MAX_MESSAGE_SIZE < fit_size ) | ||
347 | dispatch_buffer (h); | ||
348 | if (NULL == h->buf) | ||
349 | { | ||
350 | h->buf = GNUNET_malloc (size); | ||
351 | h->bs = size; | ||
352 | memcpy (h->buf, data, size); | ||
353 | return; | ||
354 | } | ||
355 | h->buf = GNUNET_realloc (h->buf, h->bs + size); | ||
356 | memcpy (h->buf + h->bs, data, size); | ||
357 | h->bs += size; | ||
358 | return; | ||
359 | } | ||
360 | |||
361 | |||
362 | /** | ||
363 | * Flush the buffered data to the logger service | ||
364 | * | ||
365 | * @param h the logger handle | ||
366 | * @param cb the callback to call after the data is flushed | ||
367 | * @param cb_cls the closure for the above callback | ||
368 | */ | ||
369 | void | ||
370 | GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h, | ||
371 | GNUNET_TESTBED_LOGGER_FlushCompletion cb, | ||
372 | void *cb_cls) | ||
373 | { | ||
374 | h->cb = cb; | ||
375 | h->cb_cls = cb_cls; | ||
376 | if (NULL == h->buf) | ||
377 | { | ||
378 | trigger_flush_notification (h); | ||
379 | return; | ||
380 | } | ||
381 | dispatch_buffer (h); | ||
382 | } | ||
383 | |||
384 | |||
385 | /** | ||
386 | * Cancel notification upon flush. | ||
387 | * | ||
388 | * @param h the logger handle | ||
389 | */ | ||
390 | void | ||
391 | GNUNET_TESTBED_LOGGER_flush_cancel (struct GNUNET_TESTBED_LOGGER_Handle *h) | ||
392 | { | ||
393 | if (GNUNET_SCHEDULER_NO_TASK != h->flush_completion_task) | ||
394 | { | ||
395 | GNUNET_SCHEDULER_cancel (h->flush_completion_task); | ||
396 | h->flush_completion_task = GNUNET_SCHEDULER_NO_TASK; | ||
397 | } | ||
398 | h->cb = NULL; | ||
399 | h->cb_cls = NULL; | ||
400 | } | ||
401 | |||
402 | /* End of testbed_logger_api.c */ | ||