diff options
Diffstat (limited to 'src/testbed-logger')
-rw-r--r-- | src/testbed-logger/.gitignore | 2 | ||||
-rw-r--r-- | src/testbed-logger/Makefile.am | 55 | ||||
-rw-r--r-- | src/testbed-logger/gnunet-service-testbed-logger.c | 236 | ||||
-rw-r--r-- | src/testbed-logger/test_testbed_logger_api.c | 277 | ||||
-rw-r--r-- | src/testbed-logger/test_testbed_logger_api.conf | 6 | ||||
-rw-r--r-- | src/testbed-logger/testbed-logger.conf.in | 127 | ||||
-rw-r--r-- | src/testbed-logger/testbed_logger_api.c | 338 |
7 files changed, 0 insertions, 1041 deletions
diff --git a/src/testbed-logger/.gitignore b/src/testbed-logger/.gitignore deleted file mode 100644 index de0c2dcfe..000000000 --- a/src/testbed-logger/.gitignore +++ /dev/null | |||
@@ -1,2 +0,0 @@ | |||
1 | gnunet-service-testbed-logger | ||
2 | test_testbed_logger_api | ||
diff --git a/src/testbed-logger/Makefile.am b/src/testbed-logger/Makefile.am deleted file mode 100644 index 741e4adfc..000000000 --- a/src/testbed-logger/Makefile.am +++ /dev/null | |||
@@ -1,55 +0,0 @@ | |||
1 | # This Makefile.am is in the public domain | ||
2 | AM_CPPFLAGS = -I$(top_srcdir)/src/include | ||
3 | |||
4 | if USE_COVERAGE | ||
5 | AM_CFLAGS = --coverage -O0 | ||
6 | XLIB = -lgcov | ||
7 | endif | ||
8 | |||
9 | libexecdir= $(pkglibdir)/libexec/ | ||
10 | |||
11 | pkgcfgdir= $(pkgdatadir)/config.d/ | ||
12 | |||
13 | pkgcfg_DATA = \ | ||
14 | testbed-logger.conf | ||
15 | |||
16 | libexec_PROGRAMS = \ | ||
17 | gnunet-service-testbed-logger | ||
18 | |||
19 | gnunet_service_testbed_logger_SOURCES = \ | ||
20 | gnunet-service-testbed-logger.c | ||
21 | gnunet_service_testbed_logger_LDADD = \ | ||
22 | $(top_builddir)/src/util/libgnunetutil.la | ||
23 | gnunet_service_testbed_logger_LDFLAGS = \ | ||
24 | $(GN_LIBINTL) | ||
25 | |||
26 | lib_LTLIBRARIES = \ | ||
27 | libgnunettestbedlogger.la | ||
28 | |||
29 | libgnunettestbedlogger_la_SOURCES = \ | ||
30 | testbed_logger_api.c | ||
31 | libgnunettestbedlogger_la_LIBADD = $(XLIB) \ | ||
32 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
33 | $(LTLIBINTL) | ||
34 | libgnunettestbedlogger_la_LDFLAGS = \ | ||
35 | $(GN_LIB_LDFLAGS) \ | ||
36 | -version-info 0:0:0 | ||
37 | |||
38 | check_PROGRAMS = \ | ||
39 | test_testbed_logger_api | ||
40 | |||
41 | if ENABLE_TEST_RUN | ||
42 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | ||
43 | TESTS = \ | ||
44 | test_testbed_logger_api | ||
45 | endif | ||
46 | |||
47 | test_testbed_logger_api_SOURCES = \ | ||
48 | test_testbed_logger_api.c | ||
49 | test_testbed_logger_api_LDADD = \ | ||
50 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
51 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
52 | libgnunettestbedlogger.la | ||
53 | |||
54 | EXTRA_DIST = \ | ||
55 | test_testbed_logger_api.conf | ||
diff --git a/src/testbed-logger/gnunet-service-testbed-logger.c b/src/testbed-logger/gnunet-service-testbed-logger.c deleted file mode 100644 index bc2f0abe0..000000000 --- a/src/testbed-logger/gnunet-service-testbed-logger.c +++ /dev/null | |||
@@ -1,236 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2008--2013 GNUnet e.V. | ||
4 | |||
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 | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed-logger/gnunet-service-testbed-logger.c | ||
23 | * @brief service for collecting messages and writing to a file | ||
24 | * @author Sree Harsha Totakura | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | |||
30 | /** | ||
31 | * Generic logging shorthand | ||
32 | */ | ||
33 | #define LOG(type, ...) \ | ||
34 | GNUNET_log (type, __VA_ARGS__) | ||
35 | |||
36 | /** | ||
37 | * Debug logging shorthand | ||
38 | */ | ||
39 | #define LOG_DEBUG(...) \ | ||
40 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | ||
41 | |||
42 | /** | ||
43 | * Handle for buffered writing. | ||
44 | */ | ||
45 | struct GNUNET_BIO_WriteHandle *bio; | ||
46 | |||
47 | /** | ||
48 | * The number of connections we have | ||
49 | */ | ||
50 | static unsigned int nconn; | ||
51 | |||
52 | /** | ||
53 | * Are we shutting down? | ||
54 | */ | ||
55 | static int in_shutdown; | ||
56 | |||
57 | |||
58 | /** | ||
59 | * Check #GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG messages | ||
60 | * | ||
61 | * @param cls client identification of the client | ||
62 | * @param msg the actual message | ||
63 | * @return #GNUNET_OK (they are all always OK) | ||
64 | */ | ||
65 | static int | ||
66 | check_log_msg (void *cls, | ||
67 | const struct GNUNET_MessageHeader *msg) | ||
68 | { | ||
69 | return GNUNET_OK; | ||
70 | } | ||
71 | |||
72 | |||
73 | /** | ||
74 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG messages | ||
75 | * | ||
76 | * @param cls client identification of the client | ||
77 | * @param msg the actual message | ||
78 | */ | ||
79 | static void | ||
80 | handle_log_msg (void *cls, | ||
81 | const struct GNUNET_MessageHeader *msg) | ||
82 | { | ||
83 | struct GNUNET_SERVICE_Client *client = cls; | ||
84 | uint16_t ms; | ||
85 | |||
86 | ms = ntohs (msg->size) - sizeof(struct GNUNET_MessageHeader); | ||
87 | GNUNET_BIO_write (bio, | ||
88 | "testbed-logger-handle-log-msg", | ||
89 | &msg[1], | ||
90 | ms); | ||
91 | GNUNET_SERVICE_client_continue (client); | ||
92 | } | ||
93 | |||
94 | |||
95 | /** | ||
96 | * Task to clean up and shutdown nicely | ||
97 | * | ||
98 | * @param cls NULL | ||
99 | */ | ||
100 | static void | ||
101 | shutdown_task (void *cls) | ||
102 | { | ||
103 | in_shutdown = GNUNET_YES; | ||
104 | if (0 != nconn) | ||
105 | { | ||
106 | /* Delay shutdown if there are active connections */ | ||
107 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
108 | NULL); | ||
109 | return; | ||
110 | } | ||
111 | GNUNET_break (GNUNET_OK == | ||
112 | GNUNET_BIO_write_close (bio, NULL)); | ||
113 | } | ||
114 | |||
115 | |||
116 | /** | ||
117 | * Callback called when a client connects to the service. | ||
118 | * | ||
119 | * @param cls closure for the service | ||
120 | * @param c the new client that connected to the service | ||
121 | * @param mq the message queue used to send messages to the client | ||
122 | * @return @a c | ||
123 | */ | ||
124 | static void * | ||
125 | client_connect_cb (void *cls, | ||
126 | struct GNUNET_SERVICE_Client *c, | ||
127 | struct GNUNET_MQ_Handle *mq) | ||
128 | { | ||
129 | /* FIXME: is this really what we want here? */ | ||
130 | GNUNET_SERVICE_client_persist (c); | ||
131 | nconn++; | ||
132 | return c; | ||
133 | } | ||
134 | |||
135 | |||
136 | /** | ||
137 | * Callback called when a client disconnected from the service | ||
138 | * | ||
139 | * @param cls closure for the service | ||
140 | * @param c the client that disconnected | ||
141 | * @param internal_cls should be equal to @a c | ||
142 | */ | ||
143 | static void | ||
144 | client_disconnect_cb (void *cls, | ||
145 | struct GNUNET_SERVICE_Client *c, | ||
146 | void *internal_cls) | ||
147 | { | ||
148 | nconn--; | ||
149 | if (GNUNET_YES == in_shutdown) | ||
150 | GNUNET_SCHEDULER_shutdown (); | ||
151 | GNUNET_assert (c == internal_cls); | ||
152 | } | ||
153 | |||
154 | |||
155 | /** | ||
156 | * Testbed setup | ||
157 | * | ||
158 | * @param cls closure | ||
159 | * @param cfg configuration to use | ||
160 | * @param service the initialized service | ||
161 | */ | ||
162 | static void | ||
163 | logger_run (void *cls, | ||
164 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
165 | struct GNUNET_SERVICE_Handle *service) | ||
166 | { | ||
167 | char *dir; | ||
168 | char *fn; | ||
169 | char *hname; | ||
170 | size_t hname_len; | ||
171 | pid_t pid; | ||
172 | |||
173 | if (GNUNET_OK != | ||
174 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
175 | "TESTBED-LOGGER", | ||
176 | "DIR", | ||
177 | &dir)) | ||
178 | { | ||
179 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
180 | "TESTBED-LOGGER", | ||
181 | "DIR"); | ||
182 | GNUNET_SCHEDULER_shutdown (); | ||
183 | return; | ||
184 | } | ||
185 | pid = getpid (); | ||
186 | hname_len = GNUNET_OS_get_hostname_max_length (); | ||
187 | hname = GNUNET_malloc (hname_len); | ||
188 | if (0 != gethostname (hname, | ||
189 | hname_len)) | ||
190 | { | ||
191 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
192 | "Cannot get hostname. Exiting\n"); | ||
193 | GNUNET_free (hname); | ||
194 | GNUNET_free (dir); | ||
195 | GNUNET_SCHEDULER_shutdown (); | ||
196 | return; | ||
197 | } | ||
198 | GNUNET_asprintf (&fn, | ||
199 | "%s/%.*s_%jd.dat", | ||
200 | dir, | ||
201 | (int) hname_len, | ||
202 | hname, | ||
203 | (intmax_t) pid); | ||
204 | GNUNET_free (hname); | ||
205 | GNUNET_free (dir); | ||
206 | if (NULL == (bio = GNUNET_BIO_write_open_file (fn))) | ||
207 | { | ||
208 | GNUNET_free (fn); | ||
209 | GNUNET_SCHEDULER_shutdown (); | ||
210 | return; | ||
211 | } | ||
212 | GNUNET_free (fn); | ||
213 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
214 | NULL); | ||
215 | LOG_DEBUG ("TESTBED-LOGGER startup complete\n"); | ||
216 | } | ||
217 | |||
218 | |||
219 | /** | ||
220 | * Define "main" method using service macro. | ||
221 | */ | ||
222 | GNUNET_SERVICE_MAIN | ||
223 | ("testbed-logger", | ||
224 | GNUNET_SERVICE_OPTION_NONE, | ||
225 | &logger_run, | ||
226 | &client_connect_cb, | ||
227 | &client_disconnect_cb, | ||
228 | NULL, | ||
229 | GNUNET_MQ_hd_var_size (log_msg, | ||
230 | GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, | ||
231 | struct GNUNET_MessageHeader, | ||
232 | NULL), | ||
233 | GNUNET_MQ_handler_end ()); | ||
234 | |||
235 | |||
236 | /* 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 deleted file mode 100644 index 284fb5609..000000000 --- a/src/testbed-logger/test_testbed_logger_api.c +++ /dev/null | |||
@@ -1,277 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2008--2013 GNUnet e.V. | ||
4 | |||
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 | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file testbed-logger/test_testbed_logger_api.c | ||
22 | * @brief testcases for the testbed logger api | ||
23 | * @author Sree Harsha Totakura | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | #include "gnunet_testing_lib.h" | ||
28 | #include "gnunet_testbed_logger_service.h" | ||
29 | |||
30 | /** | ||
31 | * Generic logging shortcut | ||
32 | */ | ||
33 | #define LOG(kind, ...) \ | ||
34 | GNUNET_log (kind, __VA_ARGS__) | ||
35 | |||
36 | /** | ||
37 | * Relative time seconds shorthand | ||
38 | */ | ||
39 | #define TIME_REL_SECS(sec) \ | ||
40 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, sec) | ||
41 | |||
42 | /** | ||
43 | * Opaque handle for the logging service | ||
44 | */ | ||
45 | static struct GNUNET_TESTBED_LOGGER_Handle *h; | ||
46 | |||
47 | static struct GNUNET_TESTING_Peer *peer; | ||
48 | |||
49 | static char *search_dir; | ||
50 | |||
51 | /** | ||
52 | * Abort task identifier | ||
53 | */ | ||
54 | static struct GNUNET_SCHEDULER_Task *abort_task; | ||
55 | static struct GNUNET_SCHEDULER_Task *write_task; | ||
56 | |||
57 | static int result; | ||
58 | |||
59 | #define CANCEL_TASK(task) do { \ | ||
60 | if (NULL != task) \ | ||
61 | { \ | ||
62 | GNUNET_SCHEDULER_cancel (task); \ | ||
63 | task = NULL; \ | ||
64 | } \ | ||
65 | } while (0) | ||
66 | |||
67 | /** | ||
68 | * shortcut to exit during failure | ||
69 | */ | ||
70 | #define FAIL_TEST(cond, ret) do { \ | ||
71 | if (! (cond)) { \ | ||
72 | GNUNET_break (0); \ | ||
73 | CANCEL_TASK (abort_task); \ | ||
74 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); \ | ||
75 | ret; \ | ||
76 | } \ | ||
77 | } while (0) | ||
78 | |||
79 | |||
80 | /** | ||
81 | * Shutdown nicely | ||
82 | * | ||
83 | * @param cls NULL | ||
84 | * @param tc the task context | ||
85 | */ | ||
86 | static void | ||
87 | shutdown_now () | ||
88 | { | ||
89 | CANCEL_TASK (abort_task); | ||
90 | CANCEL_TASK (write_task); | ||
91 | GNUNET_free (search_dir); | ||
92 | if (NULL != h) | ||
93 | GNUNET_TESTBED_LOGGER_disconnect (h); | ||
94 | GNUNET_SCHEDULER_shutdown (); | ||
95 | } | ||
96 | |||
97 | |||
98 | static void | ||
99 | do_abort (void *cls) | ||
100 | { | ||
101 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
102 | "Aborting\n"); | ||
103 | abort_task = NULL; | ||
104 | shutdown_now (); | ||
105 | } | ||
106 | |||
107 | |||
108 | #define BSIZE 1024 | ||
109 | |||
110 | |||
111 | /** | ||
112 | * Function called to iterate over a directory. | ||
113 | * | ||
114 | * @param cls closure | ||
115 | * @param filename complete filename (absolute path) | ||
116 | * @return #GNUNET_OK to continue to iterate, | ||
117 | * #GNUNET_NO to stop iteration with no error, | ||
118 | * #GNUNET_SYSERR to abort iteration with error! | ||
119 | */ | ||
120 | static int | ||
121 | iterator_cb (void *cls, | ||
122 | const char *filename) | ||
123 | { | ||
124 | const char *fn; | ||
125 | size_t len; | ||
126 | uint64_t fs; | ||
127 | |||
128 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
129 | "Iterator sees file %s\n", | ||
130 | filename); | ||
131 | len = strlen (filename); | ||
132 | fn = filename + len; | ||
133 | if (0 != strcasecmp (".dat", fn - 4)) | ||
134 | return GNUNET_OK; | ||
135 | if (GNUNET_OK != | ||
136 | GNUNET_DISK_file_size (filename, | ||
137 | &fs, | ||
138 | GNUNET_NO, | ||
139 | GNUNET_YES)) | ||
140 | { | ||
141 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
142 | "Failed to obtain file size for file %s\n", | ||
143 | filename); | ||
144 | return GNUNET_SYSERR; | ||
145 | } | ||
146 | if ((BSIZE * 2) != fs) | ||
147 | { | ||
148 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
149 | "Unexpected file size for file %s\n", | ||
150 | filename); | ||
151 | /* The file size should be equal to what we | ||
152 | have written */ | ||
153 | return GNUNET_SYSERR; | ||
154 | } | ||
155 | result = GNUNET_OK; | ||
156 | return GNUNET_OK; | ||
157 | } | ||
158 | |||
159 | |||
160 | /** | ||
161 | * Functions of this type are called to notify a successful | ||
162 | * transmission of the message to the logger service | ||
163 | * | ||
164 | * @param cls the closure given to GNUNET_TESTBED_LOGGER_send() | ||
165 | * @param size the amount of data sent | ||
166 | */ | ||
167 | static void | ||
168 | flush_comp (void *cls, | ||
169 | size_t size) | ||
170 | { | ||
171 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
172 | "Flush running\n"); | ||
173 | FAIL_TEST (&write_task == cls, | ||
174 | return ); | ||
175 | FAIL_TEST ((BSIZE * 2) == size, | ||
176 | return ); | ||
177 | FAIL_TEST (GNUNET_OK == | ||
178 | GNUNET_TESTING_peer_stop (peer), | ||
179 | return ); | ||
180 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
181 | "Peer stopped, scanning %s\n", | ||
182 | search_dir); | ||
183 | FAIL_TEST (GNUNET_SYSERR != | ||
184 | GNUNET_DISK_directory_scan (search_dir, | ||
185 | &iterator_cb, | ||
186 | NULL), | ||
187 | return ); | ||
188 | shutdown_now (); | ||
189 | } | ||
190 | |||
191 | |||
192 | static void | ||
193 | do_write (void *cls) | ||
194 | { | ||
195 | static int i; | ||
196 | char buf[BSIZE]; | ||
197 | |||
198 | write_task = NULL; | ||
199 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
200 | "Write task running\n"); | ||
201 | if (0 == i) | ||
202 | write_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (1), | ||
203 | &do_write, | ||
204 | NULL); | ||
205 | (void) memset (buf, i, BSIZE); | ||
206 | GNUNET_TESTBED_LOGGER_write (h, | ||
207 | buf, | ||
208 | BSIZE); | ||
209 | if (0 == i++) | ||
210 | return; | ||
211 | GNUNET_TESTBED_LOGGER_flush (h, | ||
212 | &flush_comp, | ||
213 | &write_task); | ||
214 | } | ||
215 | |||
216 | |||
217 | /** | ||
218 | * Signature of the 'main' function for a (single-peer) testcase that | ||
219 | * is run using #GNUNET_TESTING_peer_run(). | ||
220 | * | ||
221 | * @param cls closure | ||
222 | * @param cfg configuration of the peer that was started | ||
223 | * @param peer identity of the peer that was created | ||
224 | */ | ||
225 | static void | ||
226 | test_main (void *cls, | ||
227 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
228 | struct GNUNET_TESTING_Peer *p) | ||
229 | { | ||
230 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
231 | "Connecting to logger\n"); | ||
232 | FAIL_TEST (NULL != (h = GNUNET_TESTBED_LOGGER_connect (cfg)), | ||
233 | return ); | ||
234 | FAIL_TEST (GNUNET_OK == | ||
235 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
236 | "testbed-logger", | ||
237 | "dir", | ||
238 | &search_dir), | ||
239 | return ); | ||
240 | peer = p; | ||
241 | write_task = GNUNET_SCHEDULER_add_now (&do_write, | ||
242 | NULL); | ||
243 | abort_task = GNUNET_SCHEDULER_add_delayed (TIME_REL_SECS (10), | ||
244 | &do_abort, | ||
245 | NULL); | ||
246 | } | ||
247 | |||
248 | |||
249 | /** | ||
250 | * Main function | ||
251 | */ | ||
252 | int | ||
253 | main (int argc, char **argv) | ||
254 | { | ||
255 | int ret; | ||
256 | |||
257 | result = GNUNET_SYSERR; | ||
258 | GNUNET_log_setup ("test-testbed-logger-api", | ||
259 | "WARNING", | ||
260 | NULL); | ||
261 | GNUNET_DISK_purge_cfg_dir | ||
262 | ("test_testbed_logger_api.conf", | ||
263 | "GNUNET_TEST_HOME"); | ||
264 | ret = GNUNET_TESTING_service_run ("test-testbed-logger", | ||
265 | "testbed-logger", | ||
266 | "test_testbed_logger_api.conf", | ||
267 | &test_main, | ||
268 | NULL); | ||
269 | GNUNET_DISK_purge_cfg_dir | ||
270 | ("test_testbed_logger_api.conf", | ||
271 | "GNUNET_TEST_HOME"); | ||
272 | if (0 != ret) | ||
273 | return 1; | ||
274 | if (GNUNET_OK != result) | ||
275 | return 2; | ||
276 | return 0; | ||
277 | } | ||
diff --git a/src/testbed-logger/test_testbed_logger_api.conf b/src/testbed-logger/test_testbed_logger_api.conf deleted file mode 100644 index 5dc3df7f0..000000000 --- a/src/testbed-logger/test_testbed_logger_api.conf +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | [testbed-logger] | ||
2 | UNIXPATH=$GNUNET_TMP/testbed-logger.sock | ||
3 | DIR=$GNUNET_TEST_HOME/data | ||
4 | |||
5 | [PATHS] | ||
6 | GNUNET_TEST_HOME = $GNUNET_TMP/test-testbed/ \ No newline at end of file | ||
diff --git a/src/testbed-logger/testbed-logger.conf.in b/src/testbed-logger/testbed-logger.conf.in deleted file mode 100644 index 288bbed72..000000000 --- a/src/testbed-logger/testbed-logger.conf.in +++ /dev/null | |||
@@ -1,127 +0,0 @@ | |||
1 | [testbed] | ||
2 | START_ON_DEMAND = NO | ||
3 | @JAVAPORT@ PORT = 2101 | ||
4 | HOSTNAME = localhost | ||
5 | BINARY = gnunet-service-testbed | ||
6 | |||
7 | # How long should operations wait? | ||
8 | OPERATION_TIMEOUT = 30 s | ||
9 | |||
10 | # Set this to the path where the testbed helper is installed. By default the | ||
11 | # helper binary is searched in @prefix@/lib/gnunet/libexec/ | ||
12 | # HELPER_BINARY_PATH = @prefix@/lib/gnunet/libexec/gnunet-helper-testbed | ||
13 | |||
14 | # Add your local network address here. For example, if you want to run | ||
15 | # testbed on a group of hosts connected to network 192.168.1.0/24, then set | ||
16 | # ACCEPT_FROM = 127.0.0.1; 192.168.1.0/24; | ||
17 | # Multiple network addresses can be given. They should be separated by `;' | ||
18 | ACCEPT_FROM = 127.0.0.1; | ||
19 | ACCEPT_FROM6 = ::1; | ||
20 | |||
21 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-testbed.sock | ||
22 | UNIX_MATCH_UID = YES | ||
23 | UNIX_MATCH_GID = YES | ||
24 | |||
25 | # How many maximum number of operations can be run in parallel. This number | ||
26 | # should be decreased if the system is getting overloaded and to reduce the load | ||
27 | # exerted by the emulation. | ||
28 | MAX_PARALLEL_OPERATIONS = 1000 | ||
29 | MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS = 1 | ||
30 | |||
31 | # What topology should be generated by the helper functions GNUNET_TESTBED_run() | ||
32 | # and GNUNET_TESTBED_test_run(). This option has no effect if testbed is | ||
33 | # initialized with other functions. Valid values can be found at: | ||
34 | # https://gnunet.org/supported-topologies | ||
35 | OVERLAY_TOPOLOGY = NONE | ||
36 | |||
37 | # Number of random links to be included to the generate the above topology. | ||
38 | # Note that not all topologies require this option and ignore it. Topologies | ||
39 | # requiring this option are RANDOM, SMALL_WORLD and SMALL_WORLD ring. | ||
40 | # OVERLAY_RANDOM_LINKS = | ||
41 | |||
42 | # This option is required if the OVERLAY_TOPOLOGY is set to FROM_FILE. It is | ||
43 | # ignored for all other topologies. This option should contain the path to | ||
44 | # the file containing the topology information. The format of the file is | ||
45 | # presented at: https://gnunet.org/topology-file-format | ||
46 | # OVERLAY_TOPOLOGY_FILE = /path/to/topology-file | ||
47 | |||
48 | # The following options are required if the OVERLAY_TOPOLOGY is set to | ||
49 | # SCALE_FREE. They are ignored in all other cases. | ||
50 | # The number of maximum peers which can connect to a peer | ||
51 | SCALE_FREE_TOPOLOGY_CAP = 70 | ||
52 | # The minimum number of peers which a peer has to connect | ||
53 | SCALE_FREE_TOPOLOGY_M = 5 | ||
54 | |||
55 | # How many maximum number of handles to peers' services should be kept open at | ||
56 | # any time. This number also keeps a check on the number of open descriptors as | ||
57 | # opening a service connection results in opening a file descriptor. | ||
58 | MAX_PARALLEL_SERVICE_CONNECTIONS = 256 | ||
59 | |||
60 | # Size of the internal testbed cache. It is used to cache handles to peers | ||
61 | # while trying to connect them. | ||
62 | CACHE_SIZE = 30 | ||
63 | |||
64 | # Maximum number of file descriptors a testbed controller is permitted to keep | ||
65 | # open. | ||
66 | MAX_OPEN_FDS = 512 | ||
67 | |||
68 | # How long should we wait for testbed to setup while using helper functions | ||
69 | # GNUNET_TESTBED_test_run() and GNUNET_TESTBED_run() | ||
70 | SETUP_TIMEOUT = 5 m | ||
71 | |||
72 | # Where should testbed write load statistics data | ||
73 | # STATS_DIR = /tmp/load | ||
74 | |||
75 | # What services should be shared among peers. | ||
76 | # Format is "[<service:share>] [<service:share>] ...". The shared services are | ||
77 | # started standalone without any other peer services or a hostkey. For this | ||
78 | # reason, only services which doesn't depend on other services can only be | ||
79 | # shared. Example: To share peerinfo among every 10 peers. The following spec | ||
80 | # will start 5 peerinfo services when 50 peers are started: | ||
81 | # | ||
82 | # SHARED_SERVICES = peerinfo:10 | ||
83 | # | ||
84 | # To share multiple services | ||
85 | # | ||
86 | # SHARED_SERVICES = service1:n_share1 service2:n_share2 ... | ||
87 | # | ||
88 | # Default is to share no services | ||
89 | SHARED_SERVICES = | ||
90 | |||
91 | |||
92 | [testbed-logger] | ||
93 | START_ON_DEMAND = NO | ||
94 | @UNIXONLY@ PORT = 2102 | ||
95 | HOSTNAME = localhost | ||
96 | BINARY = gnunet-service-testbed-logger | ||
97 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-gnunet-testbed-logger.sock | ||
98 | DIR = $GNUNET_TMP | ||
99 | UNIX_MATCH_UID = YES | ||
100 | UNIX_MATCH_GID = YES | ||
101 | |||
102 | |||
103 | [testbed-barrier] | ||
104 | START_ON_DEMAND = NO | ||
105 | @UNIXONLY@ PORT = 2103 | ||
106 | HOSTNAME = localhost | ||
107 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-testbed-barrier.sock | ||
108 | UNIX_MATCH_UID = YES | ||
109 | UNIX_MATCH_GID = YES | ||
110 | |||
111 | |||
112 | # This section is related to configuring underlay restrictions to simulate | ||
113 | # connectivity restrictions of NAT boxes | ||
114 | [testbed-underlay] | ||
115 | START_ON_DEMAND = NO | ||
116 | NOARMBIND = YES | ||
117 | BINARY = gnunet-daemon-testbed-underlay | ||
118 | # The sqlite3 database file containing information about what underlay | ||
119 | # restrictions to apply | ||
120 | # DBFILE = | ||
121 | |||
122 | [latency-logger] | ||
123 | START_ON_DEMAND = NO | ||
124 | NOARMBIND = YES | ||
125 | BINARY = gnunet-daemon-latency-logger | ||
126 | # The sqlite3 database file where the latency values are to be stored | ||
127 | # DBFILE = | ||
diff --git a/src/testbed-logger/testbed_logger_api.c b/src/testbed-logger/testbed_logger_api.c deleted file mode 100644 index d67bdba8b..000000000 --- a/src/testbed-logger/testbed_logger_api.c +++ /dev/null | |||
@@ -1,338 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2008--2013, 2016 GNUnet e.V. | ||
4 | |||
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 | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your 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 | Affero General Public License for more details. | ||
14 | |||
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/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file testbed-logger/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 | * @author Christian Grothoff | ||
26 | */ | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "gnunet_util_lib.h" | ||
30 | #include "gnunet_testbed_logger_service.h" | ||
31 | |||
32 | /** | ||
33 | * Generic logging shorthand | ||
34 | */ | ||
35 | #define LOG(kind, ...) \ | ||
36 | GNUNET_log_from (kind, "testbed-logger-api", __VA_ARGS__) | ||
37 | |||
38 | |||
39 | /** | ||
40 | * The size of the buffer we fill before sending out the message | ||
41 | */ | ||
42 | #define BUFFER_SIZE (GNUNET_MAX_MESSAGE_SIZE - sizeof(struct \ | ||
43 | GNUNET_MessageHeader)) | ||
44 | |||
45 | /** | ||
46 | * Connection handle for the logger service | ||
47 | */ | ||
48 | struct GNUNET_TESTBED_LOGGER_Handle | ||
49 | { | ||
50 | /** | ||
51 | * Client connection | ||
52 | */ | ||
53 | struct GNUNET_MQ_Handle *mq; | ||
54 | |||
55 | /** | ||
56 | * Flush completion callback | ||
57 | */ | ||
58 | GNUNET_TESTBED_LOGGER_FlushCompletion cb; | ||
59 | |||
60 | /** | ||
61 | * Closure for @e cb | ||
62 | */ | ||
63 | void *cb_cls; | ||
64 | |||
65 | /** | ||
66 | * Local buffer for data to be transmitted | ||
67 | */ | ||
68 | char buf[BUFFER_SIZE]; | ||
69 | |||
70 | /** | ||
71 | * How many bytes in @a buf are in use? | ||
72 | */ | ||
73 | size_t buse; | ||
74 | |||
75 | /** | ||
76 | * Number of bytes wrote since last flush | ||
77 | */ | ||
78 | size_t bwrote; | ||
79 | |||
80 | /** | ||
81 | * How long after should we retry sending a message to the service? | ||
82 | */ | ||
83 | struct GNUNET_TIME_Relative retry_backoff; | ||
84 | |||
85 | /** | ||
86 | * Task to call the flush completion callback | ||
87 | */ | ||
88 | struct GNUNET_SCHEDULER_Task *flush_completion_task; | ||
89 | |||
90 | /** | ||
91 | * Number of entries in the MQ. | ||
92 | */ | ||
93 | unsigned int mq_len; | ||
94 | }; | ||
95 | |||
96 | |||
97 | /** | ||
98 | * Task to call the flush completion notification | ||
99 | * | ||
100 | * @param cls the logger handle | ||
101 | */ | ||
102 | static void | ||
103 | call_flush_completion (void *cls) | ||
104 | { | ||
105 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; | ||
106 | GNUNET_TESTBED_LOGGER_FlushCompletion cb; | ||
107 | void *cb_cls; | ||
108 | size_t bw; | ||
109 | |||
110 | h->flush_completion_task = NULL; | ||
111 | bw = h->bwrote; | ||
112 | h->bwrote = 0; | ||
113 | cb = h->cb; | ||
114 | h->cb = NULL; | ||
115 | cb_cls = h->cb_cls; | ||
116 | h->cb_cls = NULL; | ||
117 | if (NULL != cb) | ||
118 | cb (cb_cls, bw); | ||
119 | } | ||
120 | |||
121 | |||
122 | /** | ||
123 | * Schedule the flush completion notification task | ||
124 | * | ||
125 | * @param h logger handle | ||
126 | */ | ||
127 | static void | ||
128 | trigger_flush_notification (struct GNUNET_TESTBED_LOGGER_Handle *h) | ||
129 | { | ||
130 | if (NULL != h->flush_completion_task) | ||
131 | GNUNET_SCHEDULER_cancel (h->flush_completion_task); | ||
132 | h->flush_completion_task | ||
133 | = GNUNET_SCHEDULER_add_now (&call_flush_completion, | ||
134 | h); | ||
135 | } | ||
136 | |||
137 | |||
138 | /** | ||
139 | * Send the buffered data to the service | ||
140 | * | ||
141 | * @param h the logger handle | ||
142 | */ | ||
143 | static void | ||
144 | dispatch_buffer (struct GNUNET_TESTBED_LOGGER_Handle *h); | ||
145 | |||
146 | |||
147 | /** | ||
148 | * MQ successfully sent a message. | ||
149 | * | ||
150 | * @param cls our handle | ||
151 | */ | ||
152 | static void | ||
153 | notify_sent (void *cls) | ||
154 | { | ||
155 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; | ||
156 | |||
157 | h->mq_len--; | ||
158 | if ((0 == h->mq_len) && | ||
159 | (NULL != h->cb)) | ||
160 | { | ||
161 | if (0 == h->buse) | ||
162 | trigger_flush_notification (h); | ||
163 | else | ||
164 | dispatch_buffer (h); | ||
165 | } | ||
166 | } | ||
167 | |||
168 | |||
169 | /** | ||
170 | * Send the buffered data to the service | ||
171 | * | ||
172 | * @param h the logger handle | ||
173 | */ | ||
174 | static void | ||
175 | dispatch_buffer (struct GNUNET_TESTBED_LOGGER_Handle *h) | ||
176 | { | ||
177 | struct GNUNET_MessageHeader *msg; | ||
178 | struct GNUNET_MQ_Envelope *env; | ||
179 | |||
180 | env = GNUNET_MQ_msg_extra (msg, | ||
181 | h->buse, | ||
182 | GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG); | ||
183 | GNUNET_memcpy (&msg[1], | ||
184 | h->buf, | ||
185 | h->buse); | ||
186 | h->bwrote += h->buse; | ||
187 | h->buse = 0; | ||
188 | h->mq_len++; | ||
189 | GNUNET_MQ_notify_sent (env, | ||
190 | ¬ify_sent, | ||
191 | h); | ||
192 | GNUNET_MQ_send (h->mq, | ||
193 | env); | ||
194 | } | ||
195 | |||
196 | |||
197 | /** | ||
198 | * We got disconnected from the logger. Stop logging. | ||
199 | * | ||
200 | * @param cls the `struct GNUNET_TESTBED_LOGGER_Handle` | ||
201 | * @param error error code | ||
202 | */ | ||
203 | static void | ||
204 | mq_error_handler (void *cls, | ||
205 | enum GNUNET_MQ_Error error) | ||
206 | { | ||
207 | struct GNUNET_TESTBED_LOGGER_Handle *h = cls; | ||
208 | |||
209 | GNUNET_break (0); | ||
210 | GNUNET_MQ_destroy (h->mq); | ||
211 | h->mq = NULL; | ||
212 | } | ||
213 | |||
214 | |||
215 | /** | ||
216 | * Connect to the testbed logger service | ||
217 | * | ||
218 | * @param cfg configuration to use | ||
219 | * @return the handle which can be used for sending data to the service; NULL | ||
220 | * upon any error | ||
221 | */ | ||
222 | struct GNUNET_TESTBED_LOGGER_Handle * | ||
223 | GNUNET_TESTBED_LOGGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
224 | { | ||
225 | struct GNUNET_TESTBED_LOGGER_Handle *h; | ||
226 | |||
227 | h = GNUNET_new (struct GNUNET_TESTBED_LOGGER_Handle); | ||
228 | h->mq = GNUNET_CLIENT_connect (cfg, | ||
229 | "testbed-logger", | ||
230 | NULL, | ||
231 | &mq_error_handler, | ||
232 | h); | ||
233 | if (NULL == h->mq) | ||
234 | { | ||
235 | GNUNET_free (h); | ||
236 | return NULL; | ||
237 | } | ||
238 | return h; | ||
239 | } | ||
240 | |||
241 | |||
242 | /** | ||
243 | * Disconnect from the logger service. | ||
244 | * | ||
245 | * @param h the logger handle | ||
246 | */ | ||
247 | void | ||
248 | GNUNET_TESTBED_LOGGER_disconnect (struct GNUNET_TESTBED_LOGGER_Handle *h) | ||
249 | { | ||
250 | if (NULL != h->flush_completion_task) | ||
251 | { | ||
252 | GNUNET_SCHEDULER_cancel (h->flush_completion_task); | ||
253 | h->flush_completion_task = NULL; | ||
254 | } | ||
255 | if (0 != h->mq_len) | ||
256 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
257 | "Disconnect lost %u logger message[s]\n", | ||
258 | h->mq_len); | ||
259 | if (NULL != h->mq) | ||
260 | { | ||
261 | GNUNET_MQ_destroy (h->mq); | ||
262 | h->mq = NULL; | ||
263 | } | ||
264 | GNUNET_free (h); | ||
265 | } | ||
266 | |||
267 | |||
268 | /** | ||
269 | * Send data to be logged to the logger service. The data will be buffered and | ||
270 | * will be sent upon an explicit call to GNUNET_TESTBED_LOGGER_flush() or upon | ||
271 | * exceeding a threshold size. | ||
272 | * | ||
273 | * @param h the logger handle | ||
274 | * @param data the data to send; | ||
275 | * @param size how many bytes of @a data to send | ||
276 | */ | ||
277 | void | ||
278 | GNUNET_TESTBED_LOGGER_write (struct GNUNET_TESTBED_LOGGER_Handle *h, | ||
279 | const void *data, | ||
280 | size_t size) | ||
281 | { | ||
282 | if (NULL == h->mq) | ||
283 | return; | ||
284 | while (0 != size) | ||
285 | { | ||
286 | size_t fit_size = GNUNET_MIN (size, | ||
287 | BUFFER_SIZE - h->buse); | ||
288 | GNUNET_memcpy (&h->buf[h->buse], | ||
289 | data, | ||
290 | fit_size); | ||
291 | h->buse += fit_size; | ||
292 | data += fit_size; | ||
293 | size -= fit_size; | ||
294 | if (0 != size) | ||
295 | dispatch_buffer (h); | ||
296 | } | ||
297 | } | ||
298 | |||
299 | |||
300 | void | ||
301 | GNUNET_TESTBED_LOGGER_flush (struct GNUNET_TESTBED_LOGGER_Handle *h, | ||
302 | GNUNET_TESTBED_LOGGER_FlushCompletion cb, | ||
303 | void *cb_cls) | ||
304 | { | ||
305 | GNUNET_assert (NULL == h->cb); | ||
306 | h->cb = cb; | ||
307 | h->cb_cls = cb_cls; | ||
308 | if ((NULL == h->mq) || | ||
309 | (0 == h->buse)) | ||
310 | { | ||
311 | trigger_flush_notification (h); | ||
312 | return; | ||
313 | } | ||
314 | dispatch_buffer (h); | ||
315 | } | ||
316 | |||
317 | |||
318 | /** | ||
319 | * Cancel notification upon flush. Should only be used when the flush | ||
320 | * completion callback given to GNUNET_TESTBED_LOGGER_flush() is not already | ||
321 | * called. | ||
322 | * | ||
323 | * @param h the logger handle | ||
324 | */ | ||
325 | void | ||
326 | GNUNET_TESTBED_LOGGER_flush_cancel (struct GNUNET_TESTBED_LOGGER_Handle *h) | ||
327 | { | ||
328 | if (NULL != h->flush_completion_task) | ||
329 | { | ||
330 | GNUNET_SCHEDULER_cancel (h->flush_completion_task); | ||
331 | h->flush_completion_task = NULL; | ||
332 | } | ||
333 | h->cb = NULL; | ||
334 | h->cb_cls = NULL; | ||
335 | } | ||
336 | |||
337 | |||
338 | /* End of testbed_logger_api.c */ | ||