aboutsummaryrefslogtreecommitdiff
path: root/src/testbed-logger/gnunet-service-testbed-logger.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed-logger/gnunet-service-testbed-logger.c')
-rw-r--r--src/testbed-logger/gnunet-service-testbed-logger.c196
1 files changed, 98 insertions, 98 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 */