aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/core
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core.h31
-rw-r--r--src/core/core_api.c562
-rw-r--r--src/core/core_api_monitor_peers.c84
-rw-r--r--src/core/gnunet-core.c196
-rw-r--r--src/core/gnunet-service-core.c897
-rw-r--r--src/core/gnunet-service-core.h24
-rw-r--r--src/core/gnunet-service-core_kx.c2027
-rw-r--r--src/core/gnunet-service-core_kx.h20
-rw-r--r--src/core/gnunet-service-core_sessions.c819
-rw-r--r--src/core/gnunet-service-core_sessions.h42
-rw-r--r--src/core/gnunet-service-core_typemap.c231
-rw-r--r--src/core/gnunet-service-core_typemap.h42
-rw-r--r--src/core/test_core_api.c344
-rw-r--r--src/core/test_core_api_reliability.c584
-rw-r--r--src/core/test_core_api_send_to_self.c150
-rw-r--r--src/core/test_core_api_start_only.c228
-rw-r--r--src/core/test_core_quota_compliance.c901
17 files changed, 3593 insertions, 3589 deletions
diff --git a/src/core/core.h b/src/core/core.h
index 95d506fbd..44933b4a0 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -16,7 +16,7 @@
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 core/core.h 22 * @file core/core.h
@@ -80,9 +80,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
80 * uint16_t type values specifying which messages this 80 * uint16_t type values specifying which messages this
81 * client is interested in. 81 * client is interested in.
82 */ 82 */
83struct InitMessage 83struct InitMessage {
84{
85
86 /** 84 /**
87 * Header with type #GNUNET_MESSAGE_TYPE_CORE_INIT. 85 * Header with type #GNUNET_MESSAGE_TYPE_CORE_INIT.
88 */ 86 */
@@ -99,9 +97,7 @@ struct InitMessage
99 * Message transmitted by the gnunet-service-core process 97 * Message transmitted by the gnunet-service-core process
100 * to its clients in response to an INIT message. 98 * to its clients in response to an INIT message.
101 */ 99 */
102struct InitReplyMessage 100struct InitReplyMessage {
103{
104
105 /** 101 /**
106 * Header with type #GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY 102 * Header with type #GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY
107 */ 103 */
@@ -123,8 +119,7 @@ struct InitReplyMessage
123 * Message sent by the service to clients to notify them 119 * Message sent by the service to clients to notify them
124 * about a peer connecting. 120 * about a peer connecting.
125 */ 121 */
126struct ConnectNotifyMessage 122struct ConnectNotifyMessage {
127{
128 /** 123 /**
129 * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT 124 * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT
130 */ 125 */
@@ -146,8 +141,7 @@ struct ConnectNotifyMessage
146 * Message sent by the service to clients to notify them 141 * Message sent by the service to clients to notify them
147 * about a peer disconnecting. 142 * about a peer disconnecting.
148 */ 143 */
149struct DisconnectNotifyMessage 144struct DisconnectNotifyMessage {
150{
151 /** 145 /**
152 * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT. 146 * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT.
153 */ 147 */
@@ -174,8 +168,7 @@ struct DisconnectNotifyMessage
174 * looking at the size field in the header of NotifyTrafficMessage and 168 * looking at the size field in the header of NotifyTrafficMessage and
175 * checking it with the size field in the message that follows. 169 * checking it with the size field in the message that follows.
176 */ 170 */
177struct NotifyTrafficMessage 171struct NotifyTrafficMessage {
178{
179 /** 172 /**
180 * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND 173 * Header with type #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND
181 * or #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND. 174 * or #GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND.
@@ -195,8 +188,7 @@ struct NotifyTrafficMessage
195 * Client notifying core about the maximum-priority 188 * Client notifying core about the maximum-priority
196 * message it has in the queue for a particular target. 189 * message it has in the queue for a particular target.
197 */ 190 */
198struct SendMessageRequest 191struct SendMessageRequest {
199{
200 /** 192 /**
201 * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST 193 * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST
202 */ 194 */
@@ -240,8 +232,7 @@ struct SendMessageRequest
240 * transmit a message to the given target 232 * transmit a message to the given target
241 * (response to #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST). 233 * (response to #GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST).
242 */ 234 */
243struct SendMessageReady 235struct SendMessageReady {
244{
245 /** 236 /**
246 * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND_READY 237 * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND_READY
247 */ 238 */
@@ -271,8 +262,7 @@ struct SendMessageReady
271 * Client asking core to transmit a particular message to a particular 262 * Client asking core to transmit a particular message to a particular
272 * target (response to #GNUNET_MESSAGE_TYPE_CORE_SEND_READY). 263 * target (response to #GNUNET_MESSAGE_TYPE_CORE_SEND_READY).
273 */ 264 */
274struct SendMessage 265struct SendMessage {
275{
276 /** 266 /**
277 * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND 267 * Header with type #GNUNET_MESSAGE_TYPE_CORE_SEND
278 */ 268 */
@@ -301,8 +291,7 @@ struct SendMessage
301 * Message sent by the service to monitor clients to notify them 291 * Message sent by the service to monitor clients to notify them
302 * about a peer changing status. 292 * about a peer changing status.
303 */ 293 */
304struct MonitorNotifyMessage 294struct MonitorNotifyMessage {
305{
306 /** 295 /**
307 * Header with type #GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY 296 * Header with type #GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY
308 */ 297 */
diff --git a/src/core/core_api.c b/src/core/core_api.c
index 223677a5b..010d0eb69 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -16,7 +16,7 @@
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 * @file core/core_api.c 21 * @file core/core_api.c
22 * @brief core service; this is the main API for encrypted P2P 22 * @brief core service; this is the main API for encrypted P2P
@@ -29,15 +29,13 @@
29#include "gnunet_core_service.h" 29#include "gnunet_core_service.h"
30#include "core.h" 30#include "core.h"
31 31
32#define LOG(kind, ...) GNUNET_log_from (kind, "core-api", __VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from(kind, "core-api", __VA_ARGS__)
33 33
34 34
35/** 35/**
36 * Information we track for each peer. 36 * Information we track for each peer.
37 */ 37 */
38struct PeerRecord 38struct PeerRecord {
39{
40
41 /** 39 /**
42 * Corresponding CORE handle. 40 * Corresponding CORE handle.
43 */ 41 */
@@ -75,9 +73,7 @@ struct PeerRecord
75/** 73/**
76 * Context for the core service connection. 74 * Context for the core service connection.
77 */ 75 */
78struct GNUNET_CORE_Handle 76struct GNUNET_CORE_Handle {
79{
80
81 /** 77 /**
82 * Configuration we're using. 78 * Configuration we're using.
83 */ 79 */
@@ -153,7 +149,7 @@ struct GNUNET_CORE_Handle
153 * @param h our handle to the core service 149 * @param h our handle to the core service
154 */ 150 */
155static void 151static void
156reconnect (struct GNUNET_CORE_Handle *h); 152reconnect(struct GNUNET_CORE_Handle *h);
157 153
158 154
159/** 155/**
@@ -163,13 +159,13 @@ reconnect (struct GNUNET_CORE_Handle *h);
163 * @param tc task context 159 * @param tc task context
164 */ 160 */
165static void 161static void
166reconnect_task (void *cls) 162reconnect_task(void *cls)
167{ 163{
168 struct GNUNET_CORE_Handle *h = cls; 164 struct GNUNET_CORE_Handle *h = cls;
169 165
170 h->reconnect_task = NULL; 166 h->reconnect_task = NULL;
171 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service after delay\n"); 167 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service after delay\n");
172 reconnect (h); 168 reconnect(h);
173} 169}
174 170
175 171
@@ -183,26 +179,26 @@ reconnect_task (void *cls)
183 * @return #GNUNET_YES (continue) 179 * @return #GNUNET_YES (continue)
184 */ 180 */
185static int 181static int
186disconnect_and_free_peer_entry (void *cls, 182disconnect_and_free_peer_entry(void *cls,
187 const struct GNUNET_PeerIdentity *key, 183 const struct GNUNET_PeerIdentity *key,
188 void *value) 184 void *value)
189{ 185{
190 struct GNUNET_CORE_Handle *h = cls; 186 struct GNUNET_CORE_Handle *h = cls;
191 struct PeerRecord *pr = value; 187 struct PeerRecord *pr = value;
192 188
193 GNUNET_assert (pr->h == h); 189 GNUNET_assert(pr->h == h);
194 if (NULL != h->disconnects) 190 if (NULL != h->disconnects)
195 h->disconnects (h->cls, &pr->peer, pr->client_cls); 191 h->disconnects(h->cls, &pr->peer, pr->client_cls);
196 GNUNET_assert (GNUNET_YES == 192 GNUNET_assert(GNUNET_YES ==
197 GNUNET_CONTAINER_multipeermap_remove (h->peers, key, pr)); 193 GNUNET_CONTAINER_multipeermap_remove(h->peers, key, pr));
198 GNUNET_MQ_destroy (pr->mq); 194 GNUNET_MQ_destroy(pr->mq);
199 GNUNET_assert (NULL == pr->mq); 195 GNUNET_assert(NULL == pr->mq);
200 if (NULL != pr->env) 196 if (NULL != pr->env)
201 { 197 {
202 GNUNET_MQ_discard (pr->env); 198 GNUNET_MQ_discard(pr->env);
203 pr->env = NULL; 199 pr->env = NULL;
204 } 200 }
205 GNUNET_free (pr); 201 GNUNET_free(pr);
206 return GNUNET_YES; 202 return GNUNET_YES;
207} 203}
208 204
@@ -214,21 +210,21 @@ disconnect_and_free_peer_entry (void *cls,
214 * @param h our handle 210 * @param h our handle
215 */ 211 */
216static void 212static void
217reconnect_later (struct GNUNET_CORE_Handle *h) 213reconnect_later(struct GNUNET_CORE_Handle *h)
218{ 214{
219 GNUNET_assert (NULL == h->reconnect_task); 215 GNUNET_assert(NULL == h->reconnect_task);
220 if (NULL != h->mq) 216 if (NULL != h->mq)
221 { 217 {
222 GNUNET_MQ_destroy (h->mq); 218 GNUNET_MQ_destroy(h->mq);
223 h->mq = NULL; 219 h->mq = NULL;
224 } 220 }
225 GNUNET_assert (NULL == h->reconnect_task); 221 GNUNET_assert(NULL == h->reconnect_task);
226 h->reconnect_task = 222 h->reconnect_task =
227 GNUNET_SCHEDULER_add_delayed (h->retry_backoff, &reconnect_task, h); 223 GNUNET_SCHEDULER_add_delayed(h->retry_backoff, &reconnect_task, h);
228 GNUNET_CONTAINER_multipeermap_iterate (h->peers, 224 GNUNET_CONTAINER_multipeermap_iterate(h->peers,
229 &disconnect_and_free_peer_entry, 225 &disconnect_and_free_peer_entry,
230 h); 226 h);
231 h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); 227 h->retry_backoff = GNUNET_TIME_STD_BACKOFF(h->retry_backoff);
232} 228}
233 229
234 230
@@ -240,12 +236,12 @@ reconnect_later (struct GNUNET_CORE_Handle *h)
240 * @param error error code 236 * @param error error code
241 */ 237 */
242static void 238static void
243handle_mq_error (void *cls, enum GNUNET_MQ_Error error) 239handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
244{ 240{
245 struct GNUNET_CORE_Handle *h = cls; 241 struct GNUNET_CORE_Handle *h = cls;
246 242
247 LOG (GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %d\n", error); 243 LOG(GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %d\n", error);
248 reconnect_later (h); 244 reconnect_later(h);
249} 245}
250 246
251 247
@@ -258,9 +254,9 @@ handle_mq_error (void *cls, enum GNUNET_MQ_Error error)
258 * @param impl_state state of the implementation 254 * @param impl_state state of the implementation
259 */ 255 */
260static void 256static void
261core_mq_send_impl (struct GNUNET_MQ_Handle *mq, 257core_mq_send_impl(struct GNUNET_MQ_Handle *mq,
262 const struct GNUNET_MessageHeader *msg, 258 const struct GNUNET_MessageHeader *msg,
263 void *impl_state) 259 void *impl_state)
264{ 260{
265 struct PeerRecord *pr = impl_state; 261 struct PeerRecord *pr = impl_state;
266 struct GNUNET_CORE_Handle *h = pr->h; 262 struct GNUNET_CORE_Handle *h = pr->h;
@@ -271,44 +267,44 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
271 enum GNUNET_MQ_PriorityPreferences flags; 267 enum GNUNET_MQ_PriorityPreferences flags;
272 268
273 if (NULL == h->mq) 269 if (NULL == h->mq)
274 { 270 {
275 /* We're currently reconnecting, pretend this worked */ 271 /* We're currently reconnecting, pretend this worked */
276 GNUNET_MQ_impl_send_continue (mq); 272 GNUNET_MQ_impl_send_continue(mq);
277 return; 273 return;
278 } 274 }
279 GNUNET_assert (NULL == pr->env); 275 GNUNET_assert(NULL == pr->env);
280 /* extract options from envelope */ 276 /* extract options from envelope */
281 env = GNUNET_MQ_get_current_envelope (mq); 277 env = GNUNET_MQ_get_current_envelope(mq);
282 flags = GNUNET_MQ_env_get_options (env); 278 flags = GNUNET_MQ_env_get_options(env);
283 279
284 /* check message size for sanity */ 280 /* check message size for sanity */
285 msize = ntohs (msg->size); 281 msize = ntohs(msg->size);
286 if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof (struct SendMessage)) 282 if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(struct SendMessage))
287 { 283 {
288 GNUNET_break (0); 284 GNUNET_break(0);
289 GNUNET_MQ_impl_send_continue (mq); 285 GNUNET_MQ_impl_send_continue(mq);
290 return; 286 return;
291 } 287 }
292 288
293 /* ask core for transmission */ 289 /* ask core for transmission */
294 LOG (GNUNET_ERROR_TYPE_DEBUG, 290 LOG(GNUNET_ERROR_TYPE_DEBUG,
295 "Asking core for transmission of %u bytes to `%s'\n", 291 "Asking core for transmission of %u bytes to `%s'\n",
296 (unsigned int) msize, 292 (unsigned int)msize,
297 GNUNET_i2s (&pr->peer)); 293 GNUNET_i2s(&pr->peer));
298 env = GNUNET_MQ_msg (smr, GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST); 294 env = GNUNET_MQ_msg(smr, GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST);
299 smr->priority = htonl ((uint32_t) flags); 295 smr->priority = htonl((uint32_t)flags);
300 smr->peer = pr->peer; 296 smr->peer = pr->peer;
301 smr->size = htons (msize); 297 smr->size = htons(msize);
302 smr->smr_id = htons (++pr->smr_id_gen); 298 smr->smr_id = htons(++pr->smr_id_gen);
303 GNUNET_MQ_send (h->mq, env); 299 GNUNET_MQ_send(h->mq, env);
304 300
305 /* prepare message with actual transmission data */ 301 /* prepare message with actual transmission data */
306 pr->env = GNUNET_MQ_msg_nested_mh (sm, GNUNET_MESSAGE_TYPE_CORE_SEND, msg); 302 pr->env = GNUNET_MQ_msg_nested_mh(sm, GNUNET_MESSAGE_TYPE_CORE_SEND, msg);
307 sm->priority = htonl ((uint32_t) flags); 303 sm->priority = htonl((uint32_t)flags);
308 sm->peer = pr->peer; 304 sm->peer = pr->peer;
309 LOG (GNUNET_ERROR_TYPE_DEBUG, 305 LOG(GNUNET_ERROR_TYPE_DEBUG,
310 "Calling get_message with buffer of %u bytes\n", 306 "Calling get_message with buffer of %u bytes\n",
311 (unsigned int) msize); 307 (unsigned int)msize);
312} 308}
313 309
314 310
@@ -320,11 +316,11 @@ core_mq_send_impl (struct GNUNET_MQ_Handle *mq,
320 * @param impl_state state of the implementation 316 * @param impl_state state of the implementation
321 */ 317 */
322static void 318static void
323core_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) 319core_mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
324{ 320{
325 struct PeerRecord *pr = impl_state; 321 struct PeerRecord *pr = impl_state;
326 322
327 GNUNET_assert (mq == pr->mq); 323 GNUNET_assert(mq == pr->mq);
328 pr->mq = NULL; 324 pr->mq = NULL;
329} 325}
330 326
@@ -337,13 +333,13 @@ core_mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
337 * @param impl_state state specific to the implementation 333 * @param impl_state state specific to the implementation
338 */ 334 */
339static void 335static void
340core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state) 336core_mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
341{ 337{
342 struct PeerRecord *pr = impl_state; 338 struct PeerRecord *pr = impl_state;
343 339
344 (void) mq; 340 (void)mq;
345 GNUNET_assert (NULL != pr->env); 341 GNUNET_assert(NULL != pr->env);
346 GNUNET_MQ_discard (pr->env); 342 GNUNET_MQ_discard(pr->env);
347 pr->env = NULL; 343 pr->env = NULL;
348} 344}
349 345
@@ -357,12 +353,12 @@ core_mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
357 * @param error error code 353 * @param error error code
358 */ 354 */
359static void 355static void
360core_mq_error_handler (void *cls, enum GNUNET_MQ_Error error) 356core_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
361{ 357{
362 /* struct PeerRecord *pr = cls; */ 358 /* struct PeerRecord *pr = cls; */
363 (void) cls; 359 (void)cls;
364 (void) error; 360 (void)error;
365 GNUNET_break_op (0); 361 GNUNET_break_op(0);
366} 362}
367 363
368 364
@@ -375,32 +371,32 @@ core_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
375 * @param peer the peer that is connecting to us 371 * @param peer the peer that is connecting to us
376 */ 372 */
377static void 373static void
378connect_peer (struct GNUNET_CORE_Handle *h, 374connect_peer(struct GNUNET_CORE_Handle *h,
379 const struct GNUNET_PeerIdentity *peer) 375 const struct GNUNET_PeerIdentity *peer)
380{ 376{
381 struct PeerRecord *pr; 377 struct PeerRecord *pr;
382 378
383 pr = GNUNET_new (struct PeerRecord); 379 pr = GNUNET_new(struct PeerRecord);
384 pr->peer = *peer; 380 pr->peer = *peer;
385 pr->h = h; 381 pr->h = h;
386 GNUNET_assert (GNUNET_YES == 382 GNUNET_assert(GNUNET_YES ==
387 GNUNET_CONTAINER_multipeermap_put ( 383 GNUNET_CONTAINER_multipeermap_put(
388 h->peers, 384 h->peers,
389 &pr->peer, 385 &pr->peer,
390 pr, 386 pr,
391 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 387 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
392 pr->mq = GNUNET_MQ_queue_for_callbacks (&core_mq_send_impl, 388 pr->mq = GNUNET_MQ_queue_for_callbacks(&core_mq_send_impl,
393 &core_mq_destroy_impl, 389 &core_mq_destroy_impl,
394 &core_mq_cancel_impl, 390 &core_mq_cancel_impl,
395 pr, 391 pr,
396 h->handlers, 392 h->handlers,
397 &core_mq_error_handler, 393 &core_mq_error_handler,
398 pr); 394 pr);
399 if (NULL != h->connects) 395 if (NULL != h->connects)
400 { 396 {
401 pr->client_cls = h->connects (h->cls, &pr->peer, pr->mq); 397 pr->client_cls = h->connects(h->cls, &pr->peer, pr->mq);
402 GNUNET_MQ_set_handlers_closure (pr->mq, pr->client_cls); 398 GNUNET_MQ_set_handlers_closure(pr->mq, pr->client_cls);
403 } 399 }
404} 400}
405 401
406 402
@@ -413,42 +409,42 @@ connect_peer (struct GNUNET_CORE_Handle *h,
413 * @param m the init reply 409 * @param m the init reply
414 */ 410 */
415static void 411static void
416handle_init_reply (void *cls, const struct InitReplyMessage *m) 412handle_init_reply(void *cls, const struct InitReplyMessage *m)
417{ 413{
418 struct GNUNET_CORE_Handle *h = cls; 414 struct GNUNET_CORE_Handle *h = cls;
419 GNUNET_CORE_StartupCallback init; 415 GNUNET_CORE_StartupCallback init;
420 416
421 GNUNET_break (0 == ntohl (m->reserved)); 417 GNUNET_break(0 == ntohl(m->reserved));
422 h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS; 418 h->retry_backoff = GNUNET_TIME_UNIT_MILLISECONDS;
423 if (NULL != (init = h->init)) 419 if (NULL != (init = h->init))
424 {
425 /* mark so we don't call init on reconnect */
426 h->init = NULL;
427 h->me = m->my_identity;
428 LOG (GNUNET_ERROR_TYPE_DEBUG,
429 "Connected to core service of peer `%s'.\n",
430 GNUNET_i2s (&h->me));
431 h->have_init = GNUNET_YES;
432 init (h->cls, &h->me);
433 }
434 else
435 {
436 LOG (GNUNET_ERROR_TYPE_DEBUG,
437 "Successfully reconnected to core service.\n");
438 if (GNUNET_NO == h->have_init)
439 { 420 {
421 /* mark so we don't call init on reconnect */
422 h->init = NULL;
440 h->me = m->my_identity; 423 h->me = m->my_identity;
424 LOG(GNUNET_ERROR_TYPE_DEBUG,
425 "Connected to core service of peer `%s'.\n",
426 GNUNET_i2s(&h->me));
441 h->have_init = GNUNET_YES; 427 h->have_init = GNUNET_YES;
428 init(h->cls, &h->me);
442 } 429 }
443 else 430 else
444 { 431 {
445 GNUNET_break (0 == memcmp (&h->me, 432 LOG(GNUNET_ERROR_TYPE_DEBUG,
446 &m->my_identity, 433 "Successfully reconnected to core service.\n");
447 sizeof (struct GNUNET_PeerIdentity))); 434 if (GNUNET_NO == h->have_init)
435 {
436 h->me = m->my_identity;
437 h->have_init = GNUNET_YES;
438 }
439 else
440 {
441 GNUNET_break(0 == memcmp(&h->me,
442 &m->my_identity,
443 sizeof(struct GNUNET_PeerIdentity)));
444 }
448 } 445 }
449 }
450 /* fake 'connect to self' */ 446 /* fake 'connect to self' */
451 connect_peer (h, &h->me); 447 connect_peer(h, &h->me);
452} 448}
453 449
454 450
@@ -460,28 +456,28 @@ handle_init_reply (void *cls, const struct InitReplyMessage *m)
460 * @param cnm the connect message 456 * @param cnm the connect message
461 */ 457 */
462static void 458static void
463handle_connect_notify (void *cls, const struct ConnectNotifyMessage *cnm) 459handle_connect_notify(void *cls, const struct ConnectNotifyMessage *cnm)
464{ 460{
465 struct GNUNET_CORE_Handle *h = cls; 461 struct GNUNET_CORE_Handle *h = cls;
466 struct PeerRecord *pr; 462 struct PeerRecord *pr;
467 463
468 LOG (GNUNET_ERROR_TYPE_DEBUG, 464 LOG(GNUNET_ERROR_TYPE_DEBUG,
469 "Received notification about connection from `%s'.\n", 465 "Received notification about connection from `%s'.\n",
470 GNUNET_i2s (&cnm->peer)); 466 GNUNET_i2s(&cnm->peer));
471 if (0 == memcmp (&h->me, &cnm->peer, sizeof (struct GNUNET_PeerIdentity))) 467 if (0 == memcmp(&h->me, &cnm->peer, sizeof(struct GNUNET_PeerIdentity)))
472 { 468 {
473 /* connect to self!? */ 469 /* connect to self!? */
474 GNUNET_break (0); 470 GNUNET_break(0);
475 return; 471 return;
476 } 472 }
477 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &cnm->peer); 473 pr = GNUNET_CONTAINER_multipeermap_get(h->peers, &cnm->peer);
478 if (NULL != pr) 474 if (NULL != pr)
479 { 475 {
480 GNUNET_break (0); 476 GNUNET_break(0);
481 reconnect_later (h); 477 reconnect_later(h);
482 return; 478 return;
483 } 479 }
484 connect_peer (h, &cnm->peer); 480 connect_peer(h, &cnm->peer);
485} 481}
486 482
487 483
@@ -493,29 +489,29 @@ handle_connect_notify (void *cls, const struct ConnectNotifyMessage *cnm)
493 * @param dnm message about the disconnect event 489 * @param dnm message about the disconnect event
494 */ 490 */
495static void 491static void
496handle_disconnect_notify (void *cls, const struct DisconnectNotifyMessage *dnm) 492handle_disconnect_notify(void *cls, const struct DisconnectNotifyMessage *dnm)
497{ 493{
498 struct GNUNET_CORE_Handle *h = cls; 494 struct GNUNET_CORE_Handle *h = cls;
499 struct PeerRecord *pr; 495 struct PeerRecord *pr;
500 496
501 if (0 == memcmp (&h->me, &dnm->peer, sizeof (struct GNUNET_PeerIdentity))) 497 if (0 == memcmp(&h->me, &dnm->peer, sizeof(struct GNUNET_PeerIdentity)))
502 { 498 {
503 /* disconnect from self!? */ 499 /* disconnect from self!? */
504 GNUNET_break (0); 500 GNUNET_break(0);
505 return; 501 return;
506 } 502 }
507 GNUNET_break (0 == ntohl (dnm->reserved)); 503 GNUNET_break(0 == ntohl(dnm->reserved));
508 LOG (GNUNET_ERROR_TYPE_DEBUG, 504 LOG(GNUNET_ERROR_TYPE_DEBUG,
509 "Received notification about disconnect from `%s'.\n", 505 "Received notification about disconnect from `%s'.\n",
510 GNUNET_i2s (&dnm->peer)); 506 GNUNET_i2s(&dnm->peer));
511 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &dnm->peer); 507 pr = GNUNET_CONTAINER_multipeermap_get(h->peers, &dnm->peer);
512 if (NULL == pr) 508 if (NULL == pr)
513 { 509 {
514 GNUNET_break (0); 510 GNUNET_break(0);
515 reconnect_later (h); 511 reconnect_later(h);
516 return; 512 return;
517 } 513 }
518 disconnect_and_free_peer_entry (h, &pr->peer, pr); 514 disconnect_and_free_peer_entry(h, &pr->peer, pr);
519} 515}
520 516
521 517
@@ -527,24 +523,24 @@ handle_disconnect_notify (void *cls, const struct DisconnectNotifyMessage *dnm)
527 * @return #GNUNET_OK if the message is well-formed 523 * @return #GNUNET_OK if the message is well-formed
528 */ 524 */
529static int 525static int
530check_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm) 526check_notify_inbound(void *cls, const struct NotifyTrafficMessage *ntm)
531{ 527{
532 uint16_t msize; 528 uint16_t msize;
533 const struct GNUNET_MessageHeader *em; 529 const struct GNUNET_MessageHeader *em;
534 530
535 (void) cls; 531 (void)cls;
536 msize = ntohs (ntm->header.size) - sizeof (struct NotifyTrafficMessage); 532 msize = ntohs(ntm->header.size) - sizeof(struct NotifyTrafficMessage);
537 if (msize < sizeof (struct GNUNET_MessageHeader)) 533 if (msize < sizeof(struct GNUNET_MessageHeader))
538 { 534 {
539 GNUNET_break (0); 535 GNUNET_break(0);
540 return GNUNET_SYSERR; 536 return GNUNET_SYSERR;
541 } 537 }
542 em = (const struct GNUNET_MessageHeader *) &ntm[1]; 538 em = (const struct GNUNET_MessageHeader *)&ntm[1];
543 if (msize != ntohs (em->size)) 539 if (msize != ntohs(em->size))
544 { 540 {
545 GNUNET_break (0); 541 GNUNET_break(0);
546 return GNUNET_SYSERR; 542 return GNUNET_SYSERR;
547 } 543 }
548 return GNUNET_OK; 544 return GNUNET_OK;
549} 545}
550 546
@@ -557,24 +553,24 @@ check_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm)
557 * @param ntm the message we got from CORE. 553 * @param ntm the message we got from CORE.
558 */ 554 */
559static void 555static void
560handle_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm) 556handle_notify_inbound(void *cls, const struct NotifyTrafficMessage *ntm)
561{ 557{
562 struct GNUNET_CORE_Handle *h = cls; 558 struct GNUNET_CORE_Handle *h = cls;
563 const struct GNUNET_MessageHeader *em; 559 const struct GNUNET_MessageHeader *em;
564 struct PeerRecord *pr; 560 struct PeerRecord *pr;
565 561
566 LOG (GNUNET_ERROR_TYPE_DEBUG, 562 LOG(GNUNET_ERROR_TYPE_DEBUG,
567 "Received inbound message from `%s'.\n", 563 "Received inbound message from `%s'.\n",
568 GNUNET_i2s (&ntm->peer)); 564 GNUNET_i2s(&ntm->peer));
569 em = (const struct GNUNET_MessageHeader *) &ntm[1]; 565 em = (const struct GNUNET_MessageHeader *)&ntm[1];
570 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &ntm->peer); 566 pr = GNUNET_CONTAINER_multipeermap_get(h->peers, &ntm->peer);
571 if (NULL == pr) 567 if (NULL == pr)
572 { 568 {
573 GNUNET_break (0); 569 GNUNET_break(0);
574 reconnect_later (h); 570 reconnect_later(h);
575 return; 571 return;
576 } 572 }
577 GNUNET_MQ_inject_message (pr->mq, em); 573 GNUNET_MQ_inject_message(pr->mq, em);
578} 574}
579 575
580 576
@@ -587,38 +583,38 @@ handle_notify_inbound (void *cls, const struct NotifyTrafficMessage *ntm)
587 * @param smr the message we got 583 * @param smr the message we got
588 */ 584 */
589static void 585static void
590handle_send_ready (void *cls, const struct SendMessageReady *smr) 586handle_send_ready(void *cls, const struct SendMessageReady *smr)
591{ 587{
592 struct GNUNET_CORE_Handle *h = cls; 588 struct GNUNET_CORE_Handle *h = cls;
593 struct PeerRecord *pr; 589 struct PeerRecord *pr;
594 590
595 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, &smr->peer); 591 pr = GNUNET_CONTAINER_multipeermap_get(h->peers, &smr->peer);
596 if (NULL == pr) 592 if (NULL == pr)
597 { 593 {
598 GNUNET_break (0); 594 GNUNET_break(0);
599 reconnect_later (h); 595 reconnect_later(h);
600 return; 596 return;
601 } 597 }
602 LOG (GNUNET_ERROR_TYPE_DEBUG, 598 LOG(GNUNET_ERROR_TYPE_DEBUG,
603 "Received notification about transmission readiness to `%s'.\n", 599 "Received notification about transmission readiness to `%s'.\n",
604 GNUNET_i2s (&smr->peer)); 600 GNUNET_i2s(&smr->peer));
605 if (NULL == pr->env) 601 if (NULL == pr->env)
606 { 602 {
607 /* request must have been cancelled between the original request 603 /* request must have been cancelled between the original request
608 * and the response from CORE, ignore CORE's readiness */ 604 * and the response from CORE, ignore CORE's readiness */
609 return; 605 return;
610 } 606 }
611 if (ntohs (smr->smr_id) != pr->smr_id_gen) 607 if (ntohs(smr->smr_id) != pr->smr_id_gen)
612 { 608 {
613 /* READY message is for expired or cancelled message, 609 /* READY message is for expired or cancelled message,
614 * ignore! (we should have already sent another request) */ 610 * ignore! (we should have already sent another request) */
615 return; 611 return;
616 } 612 }
617 613
618 /* ok, all good, send message out! */ 614 /* ok, all good, send message out! */
619 GNUNET_MQ_send (h->mq, pr->env); 615 GNUNET_MQ_send(h->mq, pr->env);
620 pr->env = NULL; 616 pr->env = NULL;
621 GNUNET_MQ_impl_send_continue (pr->mq); 617 GNUNET_MQ_impl_send_continue(pr->mq);
622} 618}
623 619
624 620
@@ -629,50 +625,50 @@ handle_send_ready (void *cls, const struct SendMessageReady *smr)
629 * @param h our handle to the core service 625 * @param h our handle to the core service
630 */ 626 */
631static void 627static void
632reconnect (struct GNUNET_CORE_Handle *h) 628reconnect(struct GNUNET_CORE_Handle *h)
633{ 629{
634 struct GNUNET_MQ_MessageHandler handlers[] = 630 struct GNUNET_MQ_MessageHandler handlers[] =
635 {GNUNET_MQ_hd_fixed_size (init_reply, 631 { GNUNET_MQ_hd_fixed_size(init_reply,
636 GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY, 632 GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY,
637 struct InitReplyMessage, 633 struct InitReplyMessage,
638 h),
639 GNUNET_MQ_hd_fixed_size (connect_notify,
640 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT,
641 struct ConnectNotifyMessage,
642 h),
643 GNUNET_MQ_hd_fixed_size (disconnect_notify,
644 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT,
645 struct DisconnectNotifyMessage,
646 h),
647 GNUNET_MQ_hd_var_size (notify_inbound,
648 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND,
649 struct NotifyTrafficMessage,
650 h), 634 h),
651 GNUNET_MQ_hd_fixed_size (send_ready, 635 GNUNET_MQ_hd_fixed_size(connect_notify,
652 GNUNET_MESSAGE_TYPE_CORE_SEND_READY, 636 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT,
653 struct SendMessageReady, 637 struct ConnectNotifyMessage,
654 h), 638 h),
655 GNUNET_MQ_handler_end ()}; 639 GNUNET_MQ_hd_fixed_size(disconnect_notify,
640 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT,
641 struct DisconnectNotifyMessage,
642 h),
643 GNUNET_MQ_hd_var_size(notify_inbound,
644 GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND,
645 struct NotifyTrafficMessage,
646 h),
647 GNUNET_MQ_hd_fixed_size(send_ready,
648 GNUNET_MESSAGE_TYPE_CORE_SEND_READY,
649 struct SendMessageReady,
650 h),
651 GNUNET_MQ_handler_end() };
656 struct InitMessage *init; 652 struct InitMessage *init;
657 struct GNUNET_MQ_Envelope *env; 653 struct GNUNET_MQ_Envelope *env;
658 uint16_t *ts; 654 uint16_t *ts;
659 655
660 GNUNET_assert (NULL == h->mq); 656 GNUNET_assert(NULL == h->mq);
661 h->mq = GNUNET_CLIENT_connect (h->cfg, "core", handlers, &handle_mq_error, h); 657 h->mq = GNUNET_CLIENT_connect(h->cfg, "core", handlers, &handle_mq_error, h);
662 if (NULL == h->mq) 658 if (NULL == h->mq)
663 { 659 {
664 reconnect_later (h); 660 reconnect_later(h);
665 return; 661 return;
666 } 662 }
667 env = GNUNET_MQ_msg_extra (init, 663 env = GNUNET_MQ_msg_extra(init,
668 sizeof (uint16_t) * h->hcnt, 664 sizeof(uint16_t) * h->hcnt,
669 GNUNET_MESSAGE_TYPE_CORE_INIT); 665 GNUNET_MESSAGE_TYPE_CORE_INIT);
670 LOG (GNUNET_ERROR_TYPE_INFO, "(Re)connecting to CORE service\n"); 666 LOG(GNUNET_ERROR_TYPE_INFO, "(Re)connecting to CORE service\n");
671 init->options = htonl (0); 667 init->options = htonl(0);
672 ts = (uint16_t *) &init[1]; 668 ts = (uint16_t *)&init[1];
673 for (unsigned int hpos = 0; hpos < h->hcnt; hpos++) 669 for (unsigned int hpos = 0; hpos < h->hcnt; hpos++)
674 ts[hpos] = htons (h->handlers[hpos].type); 670 ts[hpos] = htons(h->handlers[hpos].type);
675 GNUNET_MQ_send (h->mq, env); 671 GNUNET_MQ_send(h->mq, env);
676} 672}
677 673
678 674
@@ -691,34 +687,34 @@ reconnect (struct GNUNET_CORE_Handle *h)
691 * NULL on error (in this case, init is never called) 687 * NULL on error (in this case, init is never called)
692 */ 688 */
693struct GNUNET_CORE_Handle * 689struct GNUNET_CORE_Handle *
694GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 690GNUNET_CORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg,
695 void *cls, 691 void *cls,
696 GNUNET_CORE_StartupCallback init, 692 GNUNET_CORE_StartupCallback init,
697 GNUNET_CORE_ConnectEventHandler connects, 693 GNUNET_CORE_ConnectEventHandler connects,
698 GNUNET_CORE_DisconnectEventHandler disconnects, 694 GNUNET_CORE_DisconnectEventHandler disconnects,
699 const struct GNUNET_MQ_MessageHandler *handlers) 695 const struct GNUNET_MQ_MessageHandler *handlers)
700{ 696{
701 struct GNUNET_CORE_Handle *h; 697 struct GNUNET_CORE_Handle *h;
702 698
703 h = GNUNET_new (struct GNUNET_CORE_Handle); 699 h = GNUNET_new(struct GNUNET_CORE_Handle);
704 h->cfg = cfg; 700 h->cfg = cfg;
705 h->cls = cls; 701 h->cls = cls;
706 h->init = init; 702 h->init = init;
707 h->connects = connects; 703 h->connects = connects;
708 h->disconnects = disconnects; 704 h->disconnects = disconnects;
709 h->peers = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); 705 h->peers = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_NO);
710 h->handlers = GNUNET_MQ_copy_handlers (handlers); 706 h->handlers = GNUNET_MQ_copy_handlers(handlers);
711 h->hcnt = GNUNET_MQ_count_handlers (handlers); 707 h->hcnt = GNUNET_MQ_count_handlers(handlers);
712 GNUNET_assert (h->hcnt < 708 GNUNET_assert(h->hcnt <
713 (GNUNET_MAX_MESSAGE_SIZE - sizeof (struct InitMessage)) / 709 (GNUNET_MAX_MESSAGE_SIZE - sizeof(struct InitMessage)) /
714 sizeof (uint16_t)); 710 sizeof(uint16_t));
715 LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service\n"); 711 LOG(GNUNET_ERROR_TYPE_DEBUG, "Connecting to CORE service\n");
716 reconnect (h); 712 reconnect(h);
717 if (NULL == h->mq) 713 if (NULL == h->mq)
718 { 714 {
719 GNUNET_CORE_disconnect (h); 715 GNUNET_CORE_disconnect(h);
720 return NULL; 716 return NULL;
721 } 717 }
722 return h; 718 return h;
723} 719}
724 720
@@ -729,26 +725,26 @@ GNUNET_CORE_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
729 * @param handle connection to core to disconnect 725 * @param handle connection to core to disconnect
730 */ 726 */
731void 727void
732GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle) 728GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
733{ 729{
734 LOG (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n"); 730 LOG(GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from CORE service\n");
735 GNUNET_CONTAINER_multipeermap_iterate (handle->peers, 731 GNUNET_CONTAINER_multipeermap_iterate(handle->peers,
736 &disconnect_and_free_peer_entry, 732 &disconnect_and_free_peer_entry,
737 handle); 733 handle);
738 GNUNET_CONTAINER_multipeermap_destroy (handle->peers); 734 GNUNET_CONTAINER_multipeermap_destroy(handle->peers);
739 handle->peers = NULL; 735 handle->peers = NULL;
740 if (NULL != handle->reconnect_task) 736 if (NULL != handle->reconnect_task)
741 { 737 {
742 GNUNET_SCHEDULER_cancel (handle->reconnect_task); 738 GNUNET_SCHEDULER_cancel(handle->reconnect_task);
743 handle->reconnect_task = NULL; 739 handle->reconnect_task = NULL;
744 } 740 }
745 if (NULL != handle->mq) 741 if (NULL != handle->mq)
746 { 742 {
747 GNUNET_MQ_destroy (handle->mq); 743 GNUNET_MQ_destroy(handle->mq);
748 handle->mq = NULL; 744 handle->mq = NULL;
749 } 745 }
750 GNUNET_free_non_null (handle->handlers); 746 GNUNET_free_non_null(handle->handlers);
751 GNUNET_free (handle); 747 GNUNET_free(handle);
752} 748}
753 749
754 750
@@ -760,12 +756,12 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
760 * @return NULL if peer is not connected 756 * @return NULL if peer is not connected
761 */ 757 */
762struct GNUNET_MQ_Handle * 758struct GNUNET_MQ_Handle *
763GNUNET_CORE_get_mq (const struct GNUNET_CORE_Handle *h, 759GNUNET_CORE_get_mq(const struct GNUNET_CORE_Handle *h,
764 const struct GNUNET_PeerIdentity *pid) 760 const struct GNUNET_PeerIdentity *pid)
765{ 761{
766 struct PeerRecord *pr; 762 struct PeerRecord *pr;
767 763
768 pr = GNUNET_CONTAINER_multipeermap_get (h->peers, pid); 764 pr = GNUNET_CONTAINER_multipeermap_get(h->peers, pid);
769 if (NULL == pr) 765 if (NULL == pr)
770 return NULL; 766 return NULL;
771 return pr->mq; 767 return pr->mq;
diff --git a/src/core/core_api_monitor_peers.c b/src/core/core_api_monitor_peers.c
index 165f741d2..90f4a3d15 100644
--- a/src/core/core_api_monitor_peers.c
+++ b/src/core/core_api_monitor_peers.c
@@ -16,7 +16,7 @@
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 core/core_api_monitor_peers.c 22 * @file core/core_api_monitor_peers.c
@@ -32,9 +32,7 @@
32/** 32/**
33 * Handle to a CORE monitoring operation. 33 * Handle to a CORE monitoring operation.
34 */ 34 */
35struct GNUNET_CORE_MonitorHandle 35struct GNUNET_CORE_MonitorHandle {
36{
37
38 /** 36 /**
39 * Our configuration. 37 * Our configuration.
40 */ 38 */
@@ -64,7 +62,7 @@ struct GNUNET_CORE_MonitorHandle
64 * @param mh monitoring session to reconnect to CORE 62 * @param mh monitoring session to reconnect to CORE
65 */ 63 */
66static void 64static void
67reconnect (struct GNUNET_CORE_MonitorHandle *mh); 65reconnect(struct GNUNET_CORE_MonitorHandle *mh);
68 66
69 67
70/** 68/**
@@ -76,12 +74,12 @@ reconnect (struct GNUNET_CORE_MonitorHandle *mh);
76 * @param error error code 74 * @param error error code
77 */ 75 */
78static void 76static void
79handle_mq_error (void *cls, enum GNUNET_MQ_Error error) 77handle_mq_error(void *cls, enum GNUNET_MQ_Error error)
80{ 78{
81 struct GNUNET_CORE_MonitorHandle *mh = cls; 79 struct GNUNET_CORE_MonitorHandle *mh = cls;
82 80
83 (void) error; 81 (void)error;
84 reconnect (mh); 82 reconnect(mh);
85} 83}
86 84
87 85
@@ -92,14 +90,14 @@ handle_mq_error (void *cls, enum GNUNET_MQ_Error error)
92 * @param mon_message monitor message 90 * @param mon_message monitor message
93 */ 91 */
94static void 92static void
95handle_receive_info (void *cls, const struct MonitorNotifyMessage *mon_message) 93handle_receive_info(void *cls, const struct MonitorNotifyMessage *mon_message)
96{ 94{
97 struct GNUNET_CORE_MonitorHandle *mh = cls; 95 struct GNUNET_CORE_MonitorHandle *mh = cls;
98 96
99 mh->peer_cb (mh->peer_cb_cls, 97 mh->peer_cb(mh->peer_cb_cls,
100 &mon_message->peer, 98 &mon_message->peer,
101 (enum GNUNET_CORE_KxState) ntohl (mon_message->state), 99 (enum GNUNET_CORE_KxState)ntohl(mon_message->state),
102 GNUNET_TIME_absolute_ntoh (mon_message->timeout)); 100 GNUNET_TIME_absolute_ntoh(mon_message->timeout));
103} 101}
104 102
105 103
@@ -110,32 +108,32 @@ handle_receive_info (void *cls, const struct MonitorNotifyMessage *mon_message)
110 * @param mh monitoring session to reconnect to CORE 108 * @param mh monitoring session to reconnect to CORE
111 */ 109 */
112static void 110static void
113reconnect (struct GNUNET_CORE_MonitorHandle *mh) 111reconnect(struct GNUNET_CORE_MonitorHandle *mh)
114{ 112{
115 struct GNUNET_MQ_MessageHandler handlers[] = 113 struct GNUNET_MQ_MessageHandler handlers[] =
116 {GNUNET_MQ_hd_fixed_size (receive_info, 114 { GNUNET_MQ_hd_fixed_size(receive_info,
117 GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY, 115 GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY,
118 struct MonitorNotifyMessage, 116 struct MonitorNotifyMessage,
119 mh), 117 mh),
120 GNUNET_MQ_handler_end ()}; 118 GNUNET_MQ_handler_end() };
121 struct GNUNET_MQ_Envelope *env; 119 struct GNUNET_MQ_Envelope *env;
122 struct GNUNET_MessageHeader *msg; 120 struct GNUNET_MessageHeader *msg;
123 121
124 if (NULL != mh->mq) 122 if (NULL != mh->mq)
125 GNUNET_MQ_destroy (mh->mq); 123 GNUNET_MQ_destroy(mh->mq);
126 /* FIXME: use backoff? */ 124 /* FIXME: use backoff? */
127 mh->mq = 125 mh->mq =
128 GNUNET_CLIENT_connect (mh->cfg, "core", handlers, &handle_mq_error, mh); 126 GNUNET_CLIENT_connect(mh->cfg, "core", handlers, &handle_mq_error, mh);
129 if (NULL == mh->mq) 127 if (NULL == mh->mq)
130 return; 128 return;
131 /* notify callback about reconnect */ 129 /* notify callback about reconnect */
132 if (NULL != mh->peer_cb) 130 if (NULL != mh->peer_cb)
133 mh->peer_cb (mh->peer_cb_cls, 131 mh->peer_cb(mh->peer_cb_cls,
134 NULL, 132 NULL,
135 GNUNET_CORE_KX_CORE_DISCONNECT, 133 GNUNET_CORE_KX_CORE_DISCONNECT,
136 GNUNET_TIME_UNIT_FOREVER_ABS); 134 GNUNET_TIME_UNIT_FOREVER_ABS);
137 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS); 135 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS);
138 GNUNET_MQ_send (mh->mq, env); 136 GNUNET_MQ_send(mh->mq, env);
139} 137}
140 138
141 139
@@ -156,23 +154,23 @@ reconnect (struct GNUNET_CORE_MonitorHandle *mh)
156 * @return NULL on error 154 * @return NULL on error
157 */ 155 */
158struct GNUNET_CORE_MonitorHandle * 156struct GNUNET_CORE_MonitorHandle *
159GNUNET_CORE_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 157GNUNET_CORE_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg,
160 GNUNET_CORE_MonitorCallback peer_cb, 158 GNUNET_CORE_MonitorCallback peer_cb,
161 void *peer_cb_cls) 159 void *peer_cb_cls)
162{ 160{
163 struct GNUNET_CORE_MonitorHandle *mh; 161 struct GNUNET_CORE_MonitorHandle *mh;
164 162
165 GNUNET_assert (NULL != peer_cb); 163 GNUNET_assert(NULL != peer_cb);
166 mh = GNUNET_new (struct GNUNET_CORE_MonitorHandle); 164 mh = GNUNET_new(struct GNUNET_CORE_MonitorHandle);
167 mh->cfg = cfg; 165 mh->cfg = cfg;
168 reconnect (mh); 166 reconnect(mh);
169 mh->peer_cb = peer_cb; 167 mh->peer_cb = peer_cb;
170 mh->peer_cb_cls = peer_cb_cls; 168 mh->peer_cb_cls = peer_cb_cls;
171 if (NULL == mh->mq) 169 if (NULL == mh->mq)
172 { 170 {
173 GNUNET_free (mh); 171 GNUNET_free(mh);
174 return NULL; 172 return NULL;
175 } 173 }
176 return mh; 174 return mh;
177} 175}
178 176
@@ -183,14 +181,14 @@ GNUNET_CORE_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
183 * @param mh monitor to stop 181 * @param mh monitor to stop
184 */ 182 */
185void 183void
186GNUNET_CORE_monitor_stop (struct GNUNET_CORE_MonitorHandle *mh) 184GNUNET_CORE_monitor_stop(struct GNUNET_CORE_MonitorHandle *mh)
187{ 185{
188 if (NULL != mh->mq) 186 if (NULL != mh->mq)
189 { 187 {
190 GNUNET_MQ_destroy (mh->mq); 188 GNUNET_MQ_destroy(mh->mq);
191 mh->mq = NULL; 189 mh->mq = NULL;
192 } 190 }
193 GNUNET_free (mh); 191 GNUNET_free(mh);
194} 192}
195 193
196 194
diff --git a/src/core/gnunet-core.c b/src/core/gnunet-core.c
index aeb3ba61f..2ffafc075 100644
--- a/src/core/gnunet-core.c
+++ b/src/core/gnunet-core.c
@@ -11,12 +11,12 @@
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 core/gnunet-core.c 22 * @file core/gnunet-core.c
@@ -46,14 +46,14 @@ static struct GNUNET_CORE_MonitorHandle *mh;
46 * @param cls NULL 46 * @param cls NULL
47 */ 47 */
48static void 48static void
49shutdown_task (void *cls) 49shutdown_task(void *cls)
50{ 50{
51 (void) cls; 51 (void)cls;
52 if (NULL != mh) 52 if (NULL != mh)
53 { 53 {
54 GNUNET_CORE_monitor_stop (mh); 54 GNUNET_CORE_monitor_stop(mh);
55 mh = NULL; 55 mh = NULL;
56 } 56 }
57} 57}
58 58
59 59
@@ -67,64 +67,72 @@ shutdown_task (void *cls)
67 * @param timeout timeout for the new state 67 * @param timeout timeout for the new state
68 */ 68 */
69static void 69static void
70monitor_cb (void *cls, 70monitor_cb(void *cls,
71 const struct GNUNET_PeerIdentity *peer, 71 const struct GNUNET_PeerIdentity *peer,
72 enum GNUNET_CORE_KxState state, 72 enum GNUNET_CORE_KxState state,
73 struct GNUNET_TIME_Absolute timeout) 73 struct GNUNET_TIME_Absolute timeout)
74{ 74{
75 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 75 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get();
76 const char *now_str; 76 const char *now_str;
77 const char *state_str; 77 const char *state_str;
78 78
79 (void) cls; 79 (void)cls;
80 if (((NULL == peer) || (GNUNET_CORE_KX_ITERATION_FINISHED == state)) && 80 if (((NULL == peer) || (GNUNET_CORE_KX_ITERATION_FINISHED == state)) &&
81 (GNUNET_NO == monitor_connections)) 81 (GNUNET_NO == monitor_connections))
82 { 82 {
83 GNUNET_SCHEDULER_shutdown (); 83 GNUNET_SCHEDULER_shutdown();
84 return; 84 return;
85 } 85 }
86 86
87 switch (state) 87 switch (state)
88 { 88 {
89 case GNUNET_CORE_KX_STATE_DOWN: 89 case GNUNET_CORE_KX_STATE_DOWN:
90 /* should never happen, as we immediately send the key */ 90 /* should never happen, as we immediately send the key */
91 state_str = _ ("fresh connection"); 91 state_str = _("fresh connection");
92 break; 92 break;
93 case GNUNET_CORE_KX_STATE_KEY_SENT: 93
94 state_str = _ ("key sent"); 94 case GNUNET_CORE_KX_STATE_KEY_SENT:
95 break; 95 state_str = _("key sent");
96 case GNUNET_CORE_KX_STATE_KEY_RECEIVED: 96 break;
97 state_str = _ ("key received"); 97
98 break; 98 case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
99 case GNUNET_CORE_KX_STATE_UP: 99 state_str = _("key received");
100 state_str = _ ("connection established"); 100 break;
101 break; 101
102 case GNUNET_CORE_KX_STATE_REKEY_SENT: 102 case GNUNET_CORE_KX_STATE_UP:
103 state_str = _ ("rekeying"); 103 state_str = _("connection established");
104 break; 104 break;
105 case GNUNET_CORE_KX_PEER_DISCONNECT: 105
106 state_str = _ ("disconnected"); 106 case GNUNET_CORE_KX_STATE_REKEY_SENT:
107 break; 107 state_str = _("rekeying");
108 case GNUNET_CORE_KX_ITERATION_FINISHED: 108 break;
109 return; 109
110 case GNUNET_CORE_KX_CORE_DISCONNECT: 110 case GNUNET_CORE_KX_PEER_DISCONNECT:
111 fprintf (stderr, 111 state_str = _("disconnected");
112 "%s\n", 112 break;
113 _ ("Connection to CORE service lost (reconnecting)")); 113
114 return; 114 case GNUNET_CORE_KX_ITERATION_FINISHED:
115 default: 115 return;
116 state_str = _ ("unknown state"); 116
117 break; 117 case GNUNET_CORE_KX_CORE_DISCONNECT:
118 } 118 fprintf(stderr,
119 now_str = GNUNET_STRINGS_absolute_time_to_string (now); 119 "%s\n",
120 fprintf (stdout, 120 _("Connection to CORE service lost (reconnecting)"));
121 _ ("%24s: %-30s %4s (timeout in %6s)\n"), 121 return;
122 now_str, 122
123 state_str, 123 default:
124 GNUNET_i2s (peer), 124 state_str = _("unknown state");
125 GNUNET_STRINGS_relative_time_to_string ( 125 break;
126 GNUNET_TIME_absolute_get_remaining (timeout), 126 }
127 GNUNET_YES)); 127 now_str = GNUNET_STRINGS_absolute_time_to_string(now);
128 fprintf(stdout,
129 _("%24s: %-30s %4s (timeout in %6s)\n"),
130 now_str,
131 state_str,
132 GNUNET_i2s(peer),
133 GNUNET_STRINGS_relative_time_to_string(
134 GNUNET_TIME_absolute_get_remaining(timeout),
135 GNUNET_YES));
128} 136}
129 137
130 138
@@ -137,25 +145,25 @@ monitor_cb (void *cls,
137 * @param cfg configuration 145 * @param cfg configuration
138 */ 146 */
139static void 147static void
140run (void *cls, 148run(void *cls,
141 char *const *args, 149 char *const *args,
142 const char *cfgfile, 150 const char *cfgfile,
143 const struct GNUNET_CONFIGURATION_Handle *cfg) 151 const struct GNUNET_CONFIGURATION_Handle *cfg)
144{ 152{
145 (void) cls; 153 (void)cls;
146 (void) cfgfile; 154 (void)cfgfile;
147 if (NULL != args[0]) 155 if (NULL != args[0])
148 { 156 {
149 fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]); 157 fprintf(stderr, _("Invalid command line argument `%s'\n"), args[0]);
150 return; 158 return;
151 } 159 }
152 mh = GNUNET_CORE_monitor_start (cfg, &monitor_cb, NULL); 160 mh = GNUNET_CORE_monitor_start(cfg, &monitor_cb, NULL);
153 if (NULL == mh) 161 if (NULL == mh)
154 { 162 {
155 fprintf (stderr, "%s", _ ("Failed to connect to CORE service!\n")); 163 fprintf(stderr, "%s", _("Failed to connect to CORE service!\n"));
156 return; 164 return;
157 } 165 }
158 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 166 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
159} 167}
160 168
161 169
@@ -167,30 +175,30 @@ run (void *cls,
167 * @return 0 ok, 1 on error 175 * @return 0 ok, 1 on error
168 */ 176 */
169int 177int
170main (int argc, char *const *argv) 178main(int argc, char *const *argv)
171{ 179{
172 int res; 180 int res;
173 struct GNUNET_GETOPT_CommandLineOption options[] = 181 struct GNUNET_GETOPT_CommandLineOption options[] =
174 {GNUNET_GETOPT_option_flag ( 182 { GNUNET_GETOPT_option_flag(
175 'm', 183 'm',
176 "monitor", 184 "monitor",
177 gettext_noop ( 185 gettext_noop(
178 "provide information about all current connections (continuously)"), 186 "provide information about all current connections (continuously)"),
179 &monitor_connections), 187 &monitor_connections),
180 GNUNET_GETOPT_OPTION_END}; 188 GNUNET_GETOPT_OPTION_END };
181 189
182 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 190 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
183 return 2; 191 return 2;
184 res = GNUNET_PROGRAM_run (argc, 192 res = GNUNET_PROGRAM_run(argc,
185 argv, 193 argv,
186 "gnunet-core", 194 "gnunet-core",
187 gettext_noop ( 195 gettext_noop(
188 "Print information about connected peers."), 196 "Print information about connected peers."),
189 options, 197 options,
190 &run, 198 &run,
191 NULL); 199 NULL);
192 200
193 GNUNET_free ((void *) argv); 201 GNUNET_free((void *)argv);
194 if (GNUNET_OK == res) 202 if (GNUNET_OK == res)
195 return 0; 203 return 0;
196 return 1; 204 return 1;
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c
index 740707ce1..505798683 100644
--- a/src/core/gnunet-service-core.c
+++ b/src/core/gnunet-service-core.c
@@ -16,7 +16,7 @@
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 core/gnunet-service-core.c 22 * @file core/gnunet-service-core.c
@@ -50,8 +50,7 @@
50/** 50/**
51 * Data structure for each client connected to the CORE service. 51 * Data structure for each client connected to the CORE service.
52 */ 52 */
53struct GSC_Client 53struct GSC_Client {
54{
55 /** 54 /**
56 * Clients are kept in a linked list. 55 * Clients are kept in a linked list.
57 */ 56 */
@@ -149,11 +148,11 @@ static struct GSC_Client *client_tail;
149 * @return #GNUNET_YES if @a c is interested, #GNUNET_NO if not. 148 * @return #GNUNET_YES if @a c is interested, #GNUNET_NO if not.
150 */ 149 */
151static int 150static int
152type_match (uint16_t type, struct GSC_Client *c) 151type_match(uint16_t type, struct GSC_Client *c)
153{ 152{
154 if ((0 == c->tcnt) && (0 != c->options)) 153 if ((0 == c->tcnt) && (0 != c->options))
155 return GNUNET_YES; /* peer without handlers and inbound/outbond 154 return GNUNET_YES; /* peer without handlers and inbound/outbond
156 callbacks matches ALL */ 155 callbacks matches ALL */
157 if (NULL == c->types) 156 if (NULL == c->types)
158 return GNUNET_NO; 157 return GNUNET_NO;
159 for (unsigned int i = 0; i < c->tcnt; i++) 158 for (unsigned int i = 0; i < c->tcnt; i++)
@@ -171,7 +170,7 @@ type_match (uint16_t type, struct GSC_Client *c)
171 * @return #GNUNET_OK if @a im is well-formed 170 * @return #GNUNET_OK if @a im is well-formed
172 */ 171 */
173static int 172static int
174check_client_init (void *cls, const struct InitMessage *im) 173check_client_init(void *cls, const struct InitMessage *im)
175{ 174{
176 return GNUNET_OK; 175 return GNUNET_OK;
177} 176}
@@ -184,7 +183,7 @@ check_client_init (void *cls, const struct InitMessage *im)
184 * @param im the `struct InitMessage` 183 * @param im the `struct InitMessage`
185 */ 184 */
186static void 185static void
187handle_client_init (void *cls, const struct InitMessage *im) 186handle_client_init(void *cls, const struct InitMessage *im)
188{ 187{
189 struct GSC_Client *c = cls; 188 struct GSC_Client *c = cls;
190 struct GNUNET_MQ_Envelope *env; 189 struct GNUNET_MQ_Envelope *env;
@@ -193,33 +192,33 @@ handle_client_init (void *cls, const struct InitMessage *im)
193 const uint16_t *types; 192 const uint16_t *types;
194 193
195 /* check that we don't have an entry already */ 194 /* check that we don't have an entry already */
196 msize = ntohs (im->header.size) - sizeof (struct InitMessage); 195 msize = ntohs(im->header.size) - sizeof(struct InitMessage);
197 types = (const uint16_t *) &im[1]; 196 types = (const uint16_t *)&im[1];
198 c->tcnt = msize / sizeof (uint16_t); 197 c->tcnt = msize / sizeof(uint16_t);
199 c->options = ntohl (im->options); 198 c->options = ntohl(im->options);
200 c->got_init = GNUNET_YES; 199 c->got_init = GNUNET_YES;
201 all_client_options |= c->options; 200 all_client_options |= c->options;
202 c->types = GNUNET_malloc (msize); 201 c->types = GNUNET_malloc(msize);
203 GNUNET_assert (GNUNET_YES == 202 GNUNET_assert(GNUNET_YES ==
204 GNUNET_CONTAINER_multipeermap_put ( 203 GNUNET_CONTAINER_multipeermap_put(
205 c->connectmap, 204 c->connectmap,
206 &GSC_my_identity, 205 &GSC_my_identity,
207 NULL, 206 NULL,
208 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 207 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
209 for (unsigned int i = 0; i < c->tcnt; i++) 208 for (unsigned int i = 0; i < c->tcnt; i++)
210 c->types[i] = ntohs (types[i]); 209 c->types[i] = ntohs(types[i]);
211 GSC_TYPEMAP_add (c->types, c->tcnt); 210 GSC_TYPEMAP_add(c->types, c->tcnt);
212 GNUNET_log ( 211 GNUNET_log(
213 GNUNET_ERROR_TYPE_DEBUG, 212 GNUNET_ERROR_TYPE_DEBUG,
214 "Client connecting to core service is interested in %u message types\n", 213 "Client connecting to core service is interested in %u message types\n",
215 (unsigned int) c->tcnt); 214 (unsigned int)c->tcnt);
216 /* send init reply message */ 215 /* send init reply message */
217 env = GNUNET_MQ_msg (irm, GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY); 216 env = GNUNET_MQ_msg(irm, GNUNET_MESSAGE_TYPE_CORE_INIT_REPLY);
218 irm->reserved = htonl (0); 217 irm->reserved = htonl(0);
219 irm->my_identity = GSC_my_identity; 218 irm->my_identity = GSC_my_identity;
220 GNUNET_MQ_send (c->mq, env); 219 GNUNET_MQ_send(c->mq, env);
221 GSC_SESSIONS_notify_client_about_sessions (c); 220 GSC_SESSIONS_notify_client_about_sessions(c);
222 GNUNET_SERVICE_client_continue (c->client); 221 GNUNET_SERVICE_client_continue(c->client);
223} 222}
224 223
225 224
@@ -236,17 +235,17 @@ handle_client_init (void *cls, const struct InitMessage *im)
236 * and we should thus drop the connection 235 * and we should thus drop the connection
237 */ 236 */
238void 237void
239GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car, 238GSC_CLIENTS_reject_request(struct GSC_ClientActiveRequest *car,
240 int drop_client) 239 int drop_client)
241{ 240{
242 GNUNET_assert ( 241 GNUNET_assert(
243 GNUNET_YES == 242 GNUNET_YES ==
244 GNUNET_CONTAINER_multipeermap_remove (car->client_handle->requests, 243 GNUNET_CONTAINER_multipeermap_remove(car->client_handle->requests,
245 &car->target, 244 &car->target,
246 car)); 245 car));
247 if (GNUNET_YES == drop_client) 246 if (GNUNET_YES == drop_client)
248 GNUNET_SERVICE_client_drop (car->client_handle->client); 247 GNUNET_SERVICE_client_drop(car->client_handle->client);
249 GNUNET_free (car); 248 GNUNET_free(car);
250} 249}
251 250
252 251
@@ -258,7 +257,7 @@ GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car,
258 * and SESSIONS after this call. 257 * and SESSIONS after this call.
259 */ 258 */
260void 259void
261GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car) 260GSC_CLIENTS_solicit_request(struct GSC_ClientActiveRequest *car)
262{ 261{
263 struct GSC_Client *c; 262 struct GSC_Client *c;
264 struct GNUNET_MQ_Envelope *env; 263 struct GNUNET_MQ_Envelope *env;
@@ -268,31 +267,31 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
268 267
269 c = car->client_handle; 268 c = car->client_handle;
270 if (GNUNET_YES != 269 if (GNUNET_YES !=
271 GNUNET_CONTAINER_multipeermap_contains (c->connectmap, &car->target)) 270 GNUNET_CONTAINER_multipeermap_contains(c->connectmap, &car->target))
272 { 271 {
273 /* connection has gone down since, drop request */ 272 /* connection has gone down since, drop request */
274 GNUNET_assert (0 != memcmp (&car->target, 273 GNUNET_assert(0 != memcmp(&car->target,
275 &GSC_my_identity, 274 &GSC_my_identity,
276 sizeof (struct GNUNET_PeerIdentity))); 275 sizeof(struct GNUNET_PeerIdentity)));
277 GSC_SESSIONS_dequeue_request (car); 276 GSC_SESSIONS_dequeue_request(car);
278 GSC_CLIENTS_reject_request (car, GNUNET_NO); 277 GSC_CLIENTS_reject_request(car, GNUNET_NO);
279 return; 278 return;
280 } 279 }
281 delay = GNUNET_TIME_absolute_get_duration (car->received_time); 280 delay = GNUNET_TIME_absolute_get_duration(car->received_time);
282 left = GNUNET_TIME_absolute_get_duration (car->deadline); 281 left = GNUNET_TIME_absolute_get_duration(car->deadline);
283 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 282 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
284 GNUNET_log ( 283 GNUNET_log(
285 GNUNET_ERROR_TYPE_WARNING, 284 GNUNET_ERROR_TYPE_WARNING,
286 "Client waited %s for permission to transmit to `%s'%s (priority %u)\n", 285 "Client waited %s for permission to transmit to `%s'%s (priority %u)\n",
287 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), 286 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES),
288 GNUNET_i2s (&car->target), 287 GNUNET_i2s(&car->target),
289 (0 == left.rel_value_us) ? " (past deadline)" : "", 288 (0 == left.rel_value_us) ? " (past deadline)" : "",
290 car->priority); 289 car->priority);
291 env = GNUNET_MQ_msg (smr, GNUNET_MESSAGE_TYPE_CORE_SEND_READY); 290 env = GNUNET_MQ_msg(smr, GNUNET_MESSAGE_TYPE_CORE_SEND_READY);
292 smr->size = htons (car->msize); 291 smr->size = htons(car->msize);
293 smr->smr_id = car->smr_id; 292 smr->smr_id = car->smr_id;
294 smr->peer = car->target; 293 smr->peer = car->target;
295 GNUNET_MQ_send (c->mq, env); 294 GNUNET_MQ_send(c->mq, env);
296} 295}
297 296
298 297
@@ -303,87 +302,85 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car)
303 * @param req the `struct SendMessageRequest` 302 * @param req the `struct SendMessageRequest`
304 */ 303 */
305static void 304static void
306handle_client_send_request (void *cls, const struct SendMessageRequest *req) 305handle_client_send_request(void *cls, const struct SendMessageRequest *req)
307{ 306{
308 struct GSC_Client *c = cls; 307 struct GSC_Client *c = cls;
309 struct GSC_ClientActiveRequest *car; 308 struct GSC_ClientActiveRequest *car;
310 int is_loopback; 309 int is_loopback;
311 310
312 if (NULL == c->requests) 311 if (NULL == c->requests)
313 c->requests = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO); 312 c->requests = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_NO);
314 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 313 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
315 "Client asked for transmission to `%s'\n", 314 "Client asked for transmission to `%s'\n",
316 GNUNET_i2s (&req->peer)); 315 GNUNET_i2s(&req->peer));
317 is_loopback = (0 == memcmp (&req->peer, 316 is_loopback = (0 == memcmp(&req->peer,
318 &GSC_my_identity, 317 &GSC_my_identity,
319 sizeof (struct GNUNET_PeerIdentity))); 318 sizeof(struct GNUNET_PeerIdentity)));
320 if ((! is_loopback) && 319 if ((!is_loopback) &&
321 (GNUNET_YES != 320 (GNUNET_YES !=
322 GNUNET_CONTAINER_multipeermap_contains (c->connectmap, &req->peer))) 321 GNUNET_CONTAINER_multipeermap_contains(c->connectmap, &req->peer)))
323 { 322 {
324 /* neighbour must have disconnected since request was issued, 323 /* neighbour must have disconnected since request was issued,
325 * ignore (client will realize it once it processes the 324 * ignore (client will realize it once it processes the
326 * disconnect notification) */ 325 * disconnect notification) */
327 GNUNET_STATISTICS_update (GSC_stats, 326 GNUNET_STATISTICS_update(GSC_stats,
328 gettext_noop ( 327 gettext_noop(
329 "# send requests dropped (disconnected)"), 328 "# send requests dropped (disconnected)"),
330 1, 329 1,
331 GNUNET_NO); 330 GNUNET_NO);
332 GNUNET_SERVICE_client_continue (c->client); 331 GNUNET_SERVICE_client_continue(c->client);
333 return; 332 return;
334 } 333 }
335 334
336 car = GNUNET_CONTAINER_multipeermap_get (c->requests, &req->peer); 335 car = GNUNET_CONTAINER_multipeermap_get(c->requests, &req->peer);
337 if (NULL == car) 336 if (NULL == car)
338 { 337 {
339 /* create new entry */ 338 /* create new entry */
340 car = GNUNET_new (struct GSC_ClientActiveRequest); 339 car = GNUNET_new(struct GSC_ClientActiveRequest);
341 GNUNET_assert (GNUNET_OK == 340 GNUNET_assert(GNUNET_OK ==
342 GNUNET_CONTAINER_multipeermap_put ( 341 GNUNET_CONTAINER_multipeermap_put(
343 c->requests, 342 c->requests,
344 &req->peer, 343 &req->peer,
345 car, 344 car,
346 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)); 345 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
347 car->client_handle = c; 346 car->client_handle = c;
348 } 347 }
349 else 348 else
350 { 349 {
351 /* dequeue and recycle memory from pending request, there can only 350 /* dequeue and recycle memory from pending request, there can only
352 be at most one per client and peer */ 351 be at most one per client and peer */
353 GNUNET_STATISTICS_update (GSC_stats, 352 GNUNET_STATISTICS_update(GSC_stats,
354 gettext_noop ( 353 gettext_noop(
355 "# dequeuing CAR (duplicate request)"), 354 "# dequeuing CAR (duplicate request)"),
356 1, 355 1,
357 GNUNET_NO); 356 GNUNET_NO);
358 GSC_SESSIONS_dequeue_request (car); 357 GSC_SESSIONS_dequeue_request(car);
359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 358 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
360 "Transmission request to `%s' was a duplicate!\n", 359 "Transmission request to `%s' was a duplicate!\n",
361 GNUNET_i2s (&req->peer)); 360 GNUNET_i2s(&req->peer));
362 } 361 }
363 car->target = req->peer; 362 car->target = req->peer;
364 car->received_time = GNUNET_TIME_absolute_get (); 363 car->received_time = GNUNET_TIME_absolute_get();
365 car->deadline = GNUNET_TIME_absolute_ntoh (req->deadline); 364 car->deadline = GNUNET_TIME_absolute_ntoh(req->deadline);
366 car->priority = (enum GNUNET_MQ_PriorityPreferences) ntohl (req->priority); 365 car->priority = (enum GNUNET_MQ_PriorityPreferences)ntohl(req->priority);
367 car->msize = ntohs (req->size); 366 car->msize = ntohs(req->size);
368 car->smr_id = req->smr_id; 367 car->smr_id = req->smr_id;
369 car->was_solicited = GNUNET_NO; 368 car->was_solicited = GNUNET_NO;
370 GNUNET_SERVICE_client_continue (c->client); 369 GNUNET_SERVICE_client_continue(c->client);
371 if (is_loopback) 370 if (is_loopback)
372 { 371 {
373 /* loopback, satisfy immediately */ 372 /* loopback, satisfy immediately */
374 GSC_CLIENTS_solicit_request (car); 373 GSC_CLIENTS_solicit_request(car);
375 return; 374 return;
376 } 375 }
377 GSC_SESSIONS_queue_request (car); 376 GSC_SESSIONS_queue_request(car);
378} 377}
379 378
380 379
381/** 380/**
382 * Closure for the #client_tokenizer_callback(). 381 * Closure for the #client_tokenizer_callback().
383 */ 382 */
384struct TokenizerContext 383struct TokenizerContext {
385{
386
387 /** 384 /**
388 * Active request handle for the message. 385 * Active request handle for the message.
389 */ 386 */
@@ -409,58 +406,58 @@ struct TokenizerContext
409 * #GNUNET_SYSERR to stop further processing with error 406 * #GNUNET_SYSERR to stop further processing with error
410 */ 407 */
411static int 408static int
412tokenized_cb (void *cls, const struct GNUNET_MessageHeader *message) 409tokenized_cb(void *cls, const struct GNUNET_MessageHeader *message)
413{ 410{
414 struct TokenizerContext *tc = cls; 411 struct TokenizerContext *tc = cls;
415 struct GSC_ClientActiveRequest *car = tc->car; 412 struct GSC_ClientActiveRequest *car = tc->car;
416 char buf[92]; 413 char buf[92];
417 414
418 GNUNET_snprintf (buf, 415 GNUNET_snprintf(buf,
419 sizeof (buf), 416 sizeof(buf),
420 gettext_noop ("# bytes of messages of type %u received"), 417 gettext_noop("# bytes of messages of type %u received"),
421 (unsigned int) ntohs (message->type)); 418 (unsigned int)ntohs(message->type));
422 GNUNET_STATISTICS_update (GSC_stats, buf, ntohs (message->size), GNUNET_NO); 419 GNUNET_STATISTICS_update(GSC_stats, buf, ntohs(message->size), GNUNET_NO);
423 if (0 == memcmp (&car->target, 420 if (0 == memcmp(&car->target,
424 &GSC_my_identity, 421 &GSC_my_identity,
425 sizeof (struct GNUNET_PeerIdentity))) 422 sizeof(struct GNUNET_PeerIdentity)))
426 { 423 {
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 424 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
428 "Delivering message of type %u to myself\n", 425 "Delivering message of type %u to myself\n",
429 ntohs (message->type)); 426 ntohs(message->type));
430 GSC_CLIENTS_deliver_message (&GSC_my_identity, 427 GSC_CLIENTS_deliver_message(&GSC_my_identity,
431 message, 428 message,
432 ntohs (message->size), 429 ntohs(message->size),
433 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); 430 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
434 GSC_CLIENTS_deliver_message (&GSC_my_identity, 431 GSC_CLIENTS_deliver_message(&GSC_my_identity,
435 message, 432 message,
436 sizeof (struct GNUNET_MessageHeader), 433 sizeof(struct GNUNET_MessageHeader),
437 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); 434 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
438 GSC_CLIENTS_deliver_message (&GSC_my_identity, 435 GSC_CLIENTS_deliver_message(&GSC_my_identity,
439 message, 436 message,
440 ntohs (message->size), 437 ntohs(message->size),
441 GNUNET_CORE_OPTION_SEND_FULL_INBOUND); 438 GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
442 GSC_CLIENTS_deliver_message (&GSC_my_identity, 439 GSC_CLIENTS_deliver_message(&GSC_my_identity,
443 message, 440 message,
444 sizeof (struct GNUNET_MessageHeader), 441 sizeof(struct GNUNET_MessageHeader),
445 GNUNET_CORE_OPTION_SEND_HDR_INBOUND); 442 GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
446 } 443 }
447 else 444 else
448 { 445 {
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 446 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
450 "Delivering message of type %u and size %u to %s\n", 447 "Delivering message of type %u and size %u to %s\n",
451 ntohs (message->type), 448 ntohs(message->type),
452 ntohs (message->size), 449 ntohs(message->size),
453 GNUNET_i2s (&car->target)); 450 GNUNET_i2s(&car->target));
454 GSC_CLIENTS_deliver_message (&car->target, 451 GSC_CLIENTS_deliver_message(&car->target,
455 message, 452 message,
456 ntohs (message->size), 453 ntohs(message->size),
457 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND); 454 GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND);
458 GSC_CLIENTS_deliver_message (&car->target, 455 GSC_CLIENTS_deliver_message(&car->target,
459 message, 456 message,
460 sizeof (struct GNUNET_MessageHeader), 457 sizeof(struct GNUNET_MessageHeader),
461 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND); 458 GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND);
462 GSC_SESSIONS_transmit (car, message, tc->priority); 459 GSC_SESSIONS_transmit(car, message, tc->priority);
463 } 460 }
464 return GNUNET_OK; 461 return GNUNET_OK;
465} 462}
466 463
@@ -473,7 +470,7 @@ tokenized_cb (void *cls, const struct GNUNET_MessageHeader *message)
473 * @return #GNUNET_OK if @a sm is well-formed 470 * @return #GNUNET_OK if @a sm is well-formed
474 */ 471 */
475static int 472static int
476check_client_send (void *cls, const struct SendMessage *sm) 473check_client_send(void *cls, const struct SendMessage *sm)
477{ 474{
478 return GNUNET_OK; 475 return GNUNET_OK;
479} 476}
@@ -486,7 +483,7 @@ check_client_send (void *cls, const struct SendMessage *sm)
486 * @param sm the `struct SendMessage` 483 * @param sm the `struct SendMessage`
487 */ 484 */
488static void 485static void
489handle_client_send (void *cls, const struct SendMessage *sm) 486handle_client_send(void *cls, const struct SendMessage *sm)
490{ 487{
491 struct GSC_Client *c = cls; 488 struct GSC_Client *c = cls;
492 struct TokenizerContext tc; 489 struct TokenizerContext tc;
@@ -494,51 +491,51 @@ handle_client_send (void *cls, const struct SendMessage *sm)
494 struct GNUNET_TIME_Relative delay; 491 struct GNUNET_TIME_Relative delay;
495 struct GNUNET_MessageStreamTokenizer *mst; 492 struct GNUNET_MessageStreamTokenizer *mst;
496 493
497 msize = ntohs (sm->header.size) - sizeof (struct SendMessage); 494 msize = ntohs(sm->header.size) - sizeof(struct SendMessage);
498 tc.car = GNUNET_CONTAINER_multipeermap_get (c->requests, &sm->peer); 495 tc.car = GNUNET_CONTAINER_multipeermap_get(c->requests, &sm->peer);
499 if (NULL == tc.car) 496 if (NULL == tc.car)
500 { 497 {
501 /* Must have been that we first approved the request, then got disconnected 498 /* Must have been that we first approved the request, then got disconnected
502 * (which triggered removal of the 'car') and now the client gives us a message 499 * (which triggered removal of the 'car') and now the client gives us a message
503 * just *before* the client learns about the disconnect. Theoretically, we 500 * just *before* the client learns about the disconnect. Theoretically, we
504 * might also now be *again* connected. So this can happen (but should be 501 * might also now be *again* connected. So this can happen (but should be
505 * rare). If it does happen, the message is discarded. */ 502 * rare). If it does happen, the message is discarded. */
506 GNUNET_STATISTICS_update (GSC_stats, 503 GNUNET_STATISTICS_update(GSC_stats,
507 gettext_noop ( 504 gettext_noop(
508 "# messages discarded (session disconnected)"), 505 "# messages discarded (session disconnected)"),
509 1, 506 1,
510 GNUNET_NO); 507 GNUNET_NO);
511 GNUNET_SERVICE_client_continue (c->client); 508 GNUNET_SERVICE_client_continue(c->client);
512 return; 509 return;
513 } 510 }
514 delay = GNUNET_TIME_absolute_get_duration (tc.car->received_time); 511 delay = GNUNET_TIME_absolute_get_duration(tc.car->received_time);
515 tc.priority = (enum GNUNET_MQ_PriorityPreferences) ntohl (sm->priority); 512 tc.priority = (enum GNUNET_MQ_PriorityPreferences)ntohl(sm->priority);
516 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us) 513 if (delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
517 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 514 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
518 "Client waited %s for transmission of %u bytes to `%s'\n", 515 "Client waited %s for transmission of %u bytes to `%s'\n",
519 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), 516 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES),
520 msize, 517 msize,
521 GNUNET_i2s (&sm->peer)); 518 GNUNET_i2s(&sm->peer));
522 else 519 else
523 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 520 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
524 "Client waited %s for transmission of %u bytes to `%s'\n", 521 "Client waited %s for transmission of %u bytes to `%s'\n",
525 GNUNET_STRINGS_relative_time_to_string (delay, GNUNET_YES), 522 GNUNET_STRINGS_relative_time_to_string(delay, GNUNET_YES),
526 msize, 523 msize,
527 GNUNET_i2s (&sm->peer)); 524 GNUNET_i2s(&sm->peer));
528 525
529 GNUNET_assert ( 526 GNUNET_assert(
530 GNUNET_YES == 527 GNUNET_YES ==
531 GNUNET_CONTAINER_multipeermap_remove (c->requests, &sm->peer, tc.car)); 528 GNUNET_CONTAINER_multipeermap_remove(c->requests, &sm->peer, tc.car));
532 mst = GNUNET_MST_create (&tokenized_cb, &tc); 529 mst = GNUNET_MST_create(&tokenized_cb, &tc);
533 GNUNET_MST_from_buffer (mst, 530 GNUNET_MST_from_buffer(mst,
534 (const char *) &sm[1], 531 (const char *)&sm[1],
535 msize, 532 msize,
536 GNUNET_YES, 533 GNUNET_YES,
537 GNUNET_NO); 534 GNUNET_NO);
538 GNUNET_MST_destroy (mst); 535 GNUNET_MST_destroy(mst);
539 GSC_SESSIONS_dequeue_request (tc.car); 536 GSC_SESSIONS_dequeue_request(tc.car);
540 GNUNET_free (tc.car); 537 GNUNET_free(tc.car);
541 GNUNET_SERVICE_client_continue (c->client); 538 GNUNET_SERVICE_client_continue(c->client);
542} 539}
543 540
544 541
@@ -551,19 +548,19 @@ handle_client_send (void *cls, const struct SendMessage *sm)
551 * @return #GNUNET_YES (continue iteration) 548 * @return #GNUNET_YES (continue iteration)
552 */ 549 */
553static int 550static int
554destroy_active_client_request (void *cls, 551destroy_active_client_request(void *cls,
555 const struct GNUNET_PeerIdentity *key, 552 const struct GNUNET_PeerIdentity *key,
556 void *value) 553 void *value)
557{ 554{
558 struct GSC_ClientActiveRequest *car = value; 555 struct GSC_ClientActiveRequest *car = value;
559 556
560 GNUNET_assert ( 557 GNUNET_assert(
561 GNUNET_YES == 558 GNUNET_YES ==
562 GNUNET_CONTAINER_multipeermap_remove (car->client_handle->requests, 559 GNUNET_CONTAINER_multipeermap_remove(car->client_handle->requests,
563 &car->target, 560 &car->target,
564 car)); 561 car));
565 GSC_SESSIONS_dequeue_request (car); 562 GSC_SESSIONS_dequeue_request(car);
566 GNUNET_free (car); 563 GNUNET_free(car);
567 return GNUNET_YES; 564 return GNUNET_YES;
568} 565}
569 566
@@ -577,17 +574,17 @@ destroy_active_client_request (void *cls,
577 * @return our client handle 574 * @return our client handle
578 */ 575 */
579static void * 576static void *
580client_connect_cb (void *cls, 577client_connect_cb(void *cls,
581 struct GNUNET_SERVICE_Client *client, 578 struct GNUNET_SERVICE_Client *client,
582 struct GNUNET_MQ_Handle *mq) 579 struct GNUNET_MQ_Handle *mq)
583{ 580{
584 struct GSC_Client *c; 581 struct GSC_Client *c;
585 582
586 c = GNUNET_new (struct GSC_Client); 583 c = GNUNET_new(struct GSC_Client);
587 c->client = client; 584 c->client = client;
588 c->mq = mq; 585 c->mq = mq;
589 c->connectmap = GNUNET_CONTAINER_multipeermap_create (16, GNUNET_NO); 586 c->connectmap = GNUNET_CONTAINER_multipeermap_create(16, GNUNET_NO);
590 GNUNET_CONTAINER_DLL_insert (client_head, client_tail, c); 587 GNUNET_CONTAINER_DLL_insert(client_head, client_tail, c);
591 return c; 588 return c;
592} 589}
593 590
@@ -600,31 +597,31 @@ client_connect_cb (void *cls,
600 * @param app_ctx our `struct GST_Client` for @a client 597 * @param app_ctx our `struct GST_Client` for @a client
601 */ 598 */
602static void 599static void
603client_disconnect_cb (void *cls, 600client_disconnect_cb(void *cls,
604 struct GNUNET_SERVICE_Client *client, 601 struct GNUNET_SERVICE_Client *client,
605 void *app_ctx) 602 void *app_ctx)
606{ 603{
607 struct GSC_Client *c = app_ctx; 604 struct GSC_Client *c = app_ctx;
608 605
609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 606 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
610 "Client %p has disconnected from core service.\n", 607 "Client %p has disconnected from core service.\n",
611 client); 608 client);
612 GNUNET_CONTAINER_DLL_remove (client_head, client_tail, c); 609 GNUNET_CONTAINER_DLL_remove(client_head, client_tail, c);
613 if (NULL != c->requests) 610 if (NULL != c->requests)
614 { 611 {
615 GNUNET_CONTAINER_multipeermap_iterate (c->requests, 612 GNUNET_CONTAINER_multipeermap_iterate(c->requests,
616 &destroy_active_client_request, 613 &destroy_active_client_request,
617 NULL); 614 NULL);
618 GNUNET_CONTAINER_multipeermap_destroy (c->requests); 615 GNUNET_CONTAINER_multipeermap_destroy(c->requests);
619 } 616 }
620 GNUNET_CONTAINER_multipeermap_destroy (c->connectmap); 617 GNUNET_CONTAINER_multipeermap_destroy(c->connectmap);
621 c->connectmap = NULL; 618 c->connectmap = NULL;
622 if (NULL != c->types) 619 if (NULL != c->types)
623 { 620 {
624 GSC_TYPEMAP_remove (c->types, c->tcnt); 621 GSC_TYPEMAP_remove(c->types, c->tcnt);
625 GNUNET_free (c->types); 622 GNUNET_free(c->types);
626 } 623 }
627 GNUNET_free (c); 624 GNUNET_free(c);
628 625
629 /* recalculate 'all_client_options' */ 626 /* recalculate 'all_client_options' */
630 all_client_options = 0; 627 all_client_options = 0;
@@ -644,7 +641,7 @@ client_disconnect_cb (void *cls,
644 * @param tmap_new updated type map for the neighbour, NULL for disconnect 641 * @param tmap_new updated type map for the neighbour, NULL for disconnect
645 */ 642 */
646void 643void
647GSC_CLIENTS_notify_client_about_neighbour ( 644GSC_CLIENTS_notify_client_about_neighbour(
648 struct GSC_Client *client, 645 struct GSC_Client *client,
649 const struct GNUNET_PeerIdentity *neighbour, 646 const struct GNUNET_PeerIdentity *neighbour,
650 const struct GSC_TypeMap *tmap_old, 647 const struct GSC_TypeMap *tmap_old,
@@ -656,62 +653,62 @@ GSC_CLIENTS_notify_client_about_neighbour (
656 653
657 if (GNUNET_YES != client->got_init) 654 if (GNUNET_YES != client->got_init)
658 return; 655 return;
659 old_match = GSC_TYPEMAP_test_match (tmap_old, client->types, client->tcnt); 656 old_match = GSC_TYPEMAP_test_match(tmap_old, client->types, client->tcnt);
660 new_match = GSC_TYPEMAP_test_match (tmap_new, client->types, client->tcnt); 657 new_match = GSC_TYPEMAP_test_match(tmap_new, client->types, client->tcnt);
661 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 658 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
662 "Notifying client about neighbour %s (%d/%d)\n", 659 "Notifying client about neighbour %s (%d/%d)\n",
663 GNUNET_i2s (neighbour), 660 GNUNET_i2s(neighbour),
664 old_match, 661 old_match,
665 new_match); 662 new_match);
666 if (old_match == new_match) 663 if (old_match == new_match)
667 { 664 {
668 GNUNET_assert ( 665 GNUNET_assert(
669 old_match == 666 old_match ==
670 GNUNET_CONTAINER_multipeermap_contains (client->connectmap, neighbour)); 667 GNUNET_CONTAINER_multipeermap_contains(client->connectmap, neighbour));
671 return; /* no change */ 668 return; /* no change */
672 } 669 }
673 if (GNUNET_NO == old_match) 670 if (GNUNET_NO == old_match)
674 { 671 {
675 struct ConnectNotifyMessage *cnm; 672 struct ConnectNotifyMessage *cnm;
676 673
677 /* send connect */ 674 /* send connect */
678 GNUNET_assert ( 675 GNUNET_assert(
679 GNUNET_NO == 676 GNUNET_NO ==
680 GNUNET_CONTAINER_multipeermap_contains (client->connectmap, neighbour)); 677 GNUNET_CONTAINER_multipeermap_contains(client->connectmap, neighbour));
681 GNUNET_assert (GNUNET_YES == 678 GNUNET_assert(GNUNET_YES ==
682 GNUNET_CONTAINER_multipeermap_put ( 679 GNUNET_CONTAINER_multipeermap_put(
683 client->connectmap, 680 client->connectmap,
684 neighbour, 681 neighbour,
685 NULL, 682 NULL,
686 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 683 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
687 env = GNUNET_MQ_msg (cnm, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT); 684 env = GNUNET_MQ_msg(cnm, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
688 cnm->reserved = htonl (0); 685 cnm->reserved = htonl(0);
689 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 686 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
690 "Sending NOTIFY_CONNECT message about peer %s to client.\n", 687 "Sending NOTIFY_CONNECT message about peer %s to client.\n",
691 GNUNET_i2s (neighbour)); 688 GNUNET_i2s(neighbour));
692 cnm->peer = *neighbour; 689 cnm->peer = *neighbour;
693 GNUNET_MQ_send (client->mq, env); 690 GNUNET_MQ_send(client->mq, env);
694 } 691 }
695 else 692 else
696 { 693 {
697 struct DisconnectNotifyMessage *dcm; 694 struct DisconnectNotifyMessage *dcm;
698 695
699 /* send disconnect */ 696 /* send disconnect */
700 GNUNET_assert ( 697 GNUNET_assert(
701 GNUNET_YES == 698 GNUNET_YES ==
702 GNUNET_CONTAINER_multipeermap_contains (client->connectmap, neighbour)); 699 GNUNET_CONTAINER_multipeermap_contains(client->connectmap, neighbour));
703 GNUNET_assert (GNUNET_YES == 700 GNUNET_assert(GNUNET_YES ==
704 GNUNET_CONTAINER_multipeermap_remove (client->connectmap, 701 GNUNET_CONTAINER_multipeermap_remove(client->connectmap,
705 neighbour, 702 neighbour,
706 NULL)); 703 NULL));
707 env = GNUNET_MQ_msg (dcm, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT); 704 env = GNUNET_MQ_msg(dcm, GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT);
708 dcm->reserved = htonl (0); 705 dcm->reserved = htonl(0);
709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 706 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
710 "Sending NOTIFY_DISCONNECT message about peer %s to client.\n", 707 "Sending NOTIFY_DISCONNECT message about peer %s to client.\n",
711 GNUNET_i2s (neighbour)); 708 GNUNET_i2s(neighbour));
712 dcm->peer = *neighbour; 709 dcm->peer = *neighbour;
713 GNUNET_MQ_send (client->mq, env); 710 GNUNET_MQ_send(client->mq, env);
714 } 711 }
715} 712}
716 713
717 714
@@ -725,7 +722,7 @@ GSC_CLIENTS_notify_client_about_neighbour (
725 * @param tmap_new updated type map for the neighbour, NULL for disconnect 722 * @param tmap_new updated type map for the neighbour, NULL for disconnect
726 */ 723 */
727void 724void
728GSC_CLIENTS_notify_clients_about_neighbour ( 725GSC_CLIENTS_notify_clients_about_neighbour(
729 const struct GNUNET_PeerIdentity *neighbour, 726 const struct GNUNET_PeerIdentity *neighbour,
730 const struct GSC_TypeMap *tmap_old, 727 const struct GSC_TypeMap *tmap_old,
731 const struct GSC_TypeMap *tmap_new) 728 const struct GSC_TypeMap *tmap_new)
@@ -733,10 +730,10 @@ GSC_CLIENTS_notify_clients_about_neighbour (
733 struct GSC_Client *c; 730 struct GSC_Client *c;
734 731
735 for (c = client_head; NULL != c; c = c->next) 732 for (c = client_head; NULL != c; c = c->next)
736 GSC_CLIENTS_notify_client_about_neighbour (c, 733 GSC_CLIENTS_notify_client_about_neighbour(c,
737 neighbour, 734 neighbour,
738 tmap_old, 735 tmap_old,
739 tmap_new); 736 tmap_new);
740} 737}
741 738
742 739
@@ -752,108 +749,108 @@ GSC_CLIENTS_notify_clients_about_neighbour (
752 * receive the message 749 * receive the message
753 */ 750 */
754void 751void
755GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, 752GSC_CLIENTS_deliver_message(const struct GNUNET_PeerIdentity *sender,
756 const struct GNUNET_MessageHeader *msg, 753 const struct GNUNET_MessageHeader *msg,
757 uint16_t msize, 754 uint16_t msize,
758 uint32_t options) 755 uint32_t options)
759{ 756{
760 size_t size = msize + sizeof (struct NotifyTrafficMessage); 757 size_t size = msize + sizeof(struct NotifyTrafficMessage);
761 758
762 if (size >= GNUNET_MAX_MESSAGE_SIZE) 759 if (size >= GNUNET_MAX_MESSAGE_SIZE)
763 { 760 {
764 GNUNET_break (0); 761 GNUNET_break(0);
765 return; 762 return;
766 } 763 }
767 if (! ((0 != (all_client_options & options)) || 764 if (!((0 != (all_client_options & options)) ||
768 (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)))) 765 (0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND))))
769 return; /* no client cares about this message notification */ 766 return; /* no client cares about this message notification */
770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 767 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
771 "Core service passes message from `%s' of type %u to client.\n", 768 "Core service passes message from `%s' of type %u to client.\n",
772 GNUNET_i2s (sender), 769 GNUNET_i2s(sender),
773 (unsigned int) ntohs (msg->type)); 770 (unsigned int)ntohs(msg->type));
774 GSC_SESSIONS_add_to_typemap (sender, ntohs (msg->type)); 771 GSC_SESSIONS_add_to_typemap(sender, ntohs(msg->type));
775 772
776 for (struct GSC_Client *c = client_head; NULL != c; c = c->next) 773 for (struct GSC_Client *c = client_head; NULL != c; c = c->next)
777 {
778 struct GNUNET_MQ_Envelope *env;
779 struct NotifyTrafficMessage *ntm;
780 uint16_t mtype;
781 unsigned int qlen;
782 int tm;
783
784 tm = type_match (ntohs (msg->type), c);
785 if (! ((0 != (c->options & options)) ||
786 ((0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
787 (GNUNET_YES == tm))))
788 continue; /* neither options nor type match permit the message */
789 if ((0 != (options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)) &&
790 ((0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
791 (GNUNET_YES == tm)))
792 continue;
793 if ((0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) &&
794 (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND)))
795 continue;
796
797 /* Drop messages if:
798 1) We are above the hard limit, or
799 2) We are above the soft limit, and a coin toss limited
800 to the message size (giving larger messages a
801 proportionally higher chance of being queued) falls
802 below the threshold. The threshold is based on where
803 we are between the soft and the hard limit, scaled
804 to match the range of message sizes we usually encounter
805 (i.e. up to 32k); so a 64k message has a 50% chance of
806 being kept if we are just barely below the hard max,
807 and a 99% chance of being kept if we are at the soft max.
808 The reason is to make it more likely to drop control traffic
809 (ACK, queries) which may be cummulative or highly redundant,
810 and cheap to drop than data traffic. */
811 qlen = GNUNET_MQ_get_length (c->mq);
812 if ((qlen >= HARD_MAX_QUEUE) ||
813 ((qlen > SOFT_MAX_QUEUE) &&
814 ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
815 ntohs (msg->size))) <
816 (qlen - SOFT_MAX_QUEUE) * 0x8000 /
817 (HARD_MAX_QUEUE - SOFT_MAX_QUEUE))))
818 { 774 {
819 char buf[1024]; 775 struct GNUNET_MQ_Envelope *env;
820 776 struct NotifyTrafficMessage *ntm;
821 GNUNET_log ( 777 uint16_t mtype;
822 GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK, 778 unsigned int qlen;
823 "Dropping decrypted message of type %u as client is too busy (queue full)\n", 779 int tm;
824 (unsigned int) ntohs (msg->type)); 780
825 GNUNET_snprintf (buf, 781 tm = type_match(ntohs(msg->type), c);
826 sizeof (buf), 782 if (!((0 != (c->options & options)) ||
827 gettext_noop ( 783 ((0 != (options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) &&
828 "# messages of type %u discarded (client busy)"), 784 (GNUNET_YES == tm))))
829 (unsigned int) ntohs (msg->type)); 785 continue; /* neither options nor type match permit the message */
830 GNUNET_STATISTICS_update (GSC_stats, buf, 1, GNUNET_NO); 786 if ((0 != (options & GNUNET_CORE_OPTION_SEND_HDR_INBOUND)) &&
831 continue; 787 ((0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
788 (GNUNET_YES == tm)))
789 continue;
790 if ((0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) &&
791 (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND)))
792 continue;
793
794 /* Drop messages if:
795 1) We are above the hard limit, or
796 2) We are above the soft limit, and a coin toss limited
797 to the message size (giving larger messages a
798 proportionally higher chance of being queued) falls
799 below the threshold. The threshold is based on where
800 we are between the soft and the hard limit, scaled
801 to match the range of message sizes we usually encounter
802 (i.e. up to 32k); so a 64k message has a 50% chance of
803 being kept if we are just barely below the hard max,
804 and a 99% chance of being kept if we are at the soft max.
805 The reason is to make it more likely to drop control traffic
806 (ACK, queries) which may be cummulative or highly redundant,
807 and cheap to drop than data traffic. */
808 qlen = GNUNET_MQ_get_length(c->mq);
809 if ((qlen >= HARD_MAX_QUEUE) ||
810 ((qlen > SOFT_MAX_QUEUE) &&
811 ((GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK,
812 ntohs(msg->size))) <
813 (qlen - SOFT_MAX_QUEUE) * 0x8000 /
814 (HARD_MAX_QUEUE - SOFT_MAX_QUEUE))))
815 {
816 char buf[1024];
817
818 GNUNET_log(
819 GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
820 "Dropping decrypted message of type %u as client is too busy (queue full)\n",
821 (unsigned int)ntohs(msg->type));
822 GNUNET_snprintf(buf,
823 sizeof(buf),
824 gettext_noop(
825 "# messages of type %u discarded (client busy)"),
826 (unsigned int)ntohs(msg->type));
827 GNUNET_STATISTICS_update(GSC_stats, buf, 1, GNUNET_NO);
828 continue;
829 }
830
831 GNUNET_log(
832 GNUNET_ERROR_TYPE_DEBUG,
833 "Sending %u message with %u bytes to client interested in messages of type %u.\n",
834 options,
835 ntohs(msg->size),
836 (unsigned int)ntohs(msg->type));
837
838 if (0 != (options & (GNUNET_CORE_OPTION_SEND_FULL_INBOUND |
839 GNUNET_CORE_OPTION_SEND_HDR_INBOUND)))
840 mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND;
841 else
842 mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND;
843 env = GNUNET_MQ_msg_extra(ntm, msize, mtype);
844 ntm->peer = *sender;
845 GNUNET_memcpy(&ntm[1], msg, msize);
846
847 GNUNET_assert(
848 (0 == (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
849 (GNUNET_YES != tm) ||
850 (GNUNET_YES ==
851 GNUNET_CONTAINER_multipeermap_contains(c->connectmap, sender)));
852 GNUNET_MQ_send(c->mq, env);
832 } 853 }
833
834 GNUNET_log (
835 GNUNET_ERROR_TYPE_DEBUG,
836 "Sending %u message with %u bytes to client interested in messages of type %u.\n",
837 options,
838 ntohs (msg->size),
839 (unsigned int) ntohs (msg->type));
840
841 if (0 != (options & (GNUNET_CORE_OPTION_SEND_FULL_INBOUND |
842 GNUNET_CORE_OPTION_SEND_HDR_INBOUND)))
843 mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_INBOUND;
844 else
845 mtype = GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND;
846 env = GNUNET_MQ_msg_extra (ntm, msize, mtype);
847 ntm->peer = *sender;
848 GNUNET_memcpy (&ntm[1], msg, msize);
849
850 GNUNET_assert (
851 (0 == (c->options & GNUNET_CORE_OPTION_SEND_FULL_INBOUND)) ||
852 (GNUNET_YES != tm) ||
853 (GNUNET_YES ==
854 GNUNET_CONTAINER_multipeermap_contains (c->connectmap, sender)));
855 GNUNET_MQ_send (c->mq, env);
856 }
857} 854}
858 855
859 856
@@ -864,21 +861,21 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
864 * @param cls NULL, unused 861 * @param cls NULL, unused
865 */ 862 */
866static void 863static void
867shutdown_task (void *cls) 864shutdown_task(void *cls)
868{ 865{
869 struct GSC_Client *c; 866 struct GSC_Client *c;
870 867
871 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n"); 868 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Core service shutting down.\n");
872 while (NULL != (c = client_head)) 869 while (NULL != (c = client_head))
873 GNUNET_SERVICE_client_drop (c->client); 870 GNUNET_SERVICE_client_drop(c->client);
874 GSC_SESSIONS_done (); 871 GSC_SESSIONS_done();
875 GSC_KX_done (); 872 GSC_KX_done();
876 GSC_TYPEMAP_done (); 873 GSC_TYPEMAP_done();
877 if (NULL != GSC_stats) 874 if (NULL != GSC_stats)
878 { 875 {
879 GNUNET_STATISTICS_destroy (GSC_stats, GNUNET_NO); 876 GNUNET_STATISTICS_destroy(GSC_stats, GNUNET_NO);
880 GSC_stats = NULL; 877 GSC_stats = NULL;
881 } 878 }
882 GSC_cfg = NULL; 879 GSC_cfg = NULL;
883} 880}
884 881
@@ -893,13 +890,13 @@ shutdown_task (void *cls)
893 * @param message iteration request message 890 * @param message iteration request message
894 */ 891 */
895static void 892static void
896handle_client_monitor_peers (void *cls, 893handle_client_monitor_peers(void *cls,
897 const struct GNUNET_MessageHeader *message) 894 const struct GNUNET_MessageHeader *message)
898{ 895{
899 struct GSC_Client *c = cls; 896 struct GSC_Client *c = cls;
900 897
901 GNUNET_SERVICE_client_continue (c->client); 898 GNUNET_SERVICE_client_continue(c->client);
902 GSC_KX_handle_client_monitor_peers (c->mq); 899 GSC_KX_handle_client_monitor_peers(c->mq);
903} 900}
904 901
905 902
@@ -911,72 +908,72 @@ handle_client_monitor_peers (void *cls,
911 * @param service the initialized service 908 * @param service the initialized service
912 */ 909 */
913static void 910static void
914run (void *cls, 911run(void *cls,
915 const struct GNUNET_CONFIGURATION_Handle *c, 912 const struct GNUNET_CONFIGURATION_Handle *c,
916 struct GNUNET_SERVICE_Handle *service) 913 struct GNUNET_SERVICE_Handle *service)
917{ 914{
918 struct GNUNET_CRYPTO_EddsaPrivateKey *pk; 915 struct GNUNET_CRYPTO_EddsaPrivateKey *pk;
919 char *keyfile; 916 char *keyfile;
920 917
921 GSC_cfg = c; 918 GSC_cfg = c;
922 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (GSC_cfg, 919 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename(GSC_cfg,
923 "PEER", 920 "PEER",
924 "PRIVATE_KEY", 921 "PRIVATE_KEY",
925 &keyfile)) 922 &keyfile))
926 { 923 {
927 GNUNET_log ( 924 GNUNET_log(
928 GNUNET_ERROR_TYPE_ERROR, 925 GNUNET_ERROR_TYPE_ERROR,
929 _ ("Core service is lacking HOSTKEY configuration setting. Exiting.\n")); 926 _("Core service is lacking HOSTKEY configuration setting. Exiting.\n"));
930 GNUNET_SCHEDULER_shutdown (); 927 GNUNET_SCHEDULER_shutdown();
931 return; 928 return;
932 } 929 }
933 GSC_stats = GNUNET_STATISTICS_create ("core", GSC_cfg); 930 GSC_stats = GNUNET_STATISTICS_create("core", GSC_cfg);
934 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); 931 GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL);
935 GNUNET_SERVICE_suspend (service); 932 GNUNET_SERVICE_suspend(service);
936 GSC_TYPEMAP_init (); 933 GSC_TYPEMAP_init();
937 pk = GNUNET_CRYPTO_eddsa_key_create_from_file (keyfile); 934 pk = GNUNET_CRYPTO_eddsa_key_create_from_file(keyfile);
938 GNUNET_free (keyfile); 935 GNUNET_free(keyfile);
939 GNUNET_assert (NULL != pk); 936 GNUNET_assert(NULL != pk);
940 if (GNUNET_OK != GSC_KX_init (pk)) 937 if (GNUNET_OK != GSC_KX_init(pk))
941 { 938 {
942 GNUNET_SCHEDULER_shutdown (); 939 GNUNET_SCHEDULER_shutdown();
943 return; 940 return;
944 } 941 }
945 GSC_SESSIONS_init (); 942 GSC_SESSIONS_init();
946 GNUNET_SERVICE_resume (service); 943 GNUNET_SERVICE_resume(service);
947 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 944 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
948 _ ("Core service of `%s' ready.\n"), 945 _("Core service of `%s' ready.\n"),
949 GNUNET_i2s (&GSC_my_identity)); 946 GNUNET_i2s(&GSC_my_identity));
950} 947}
951 948
952 949
953/** 950/**
954 * Define "main" method using service macro. 951 * Define "main" method using service macro.
955 */ 952 */
956GNUNET_SERVICE_MAIN ( 953GNUNET_SERVICE_MAIN(
957 "core", 954 "core",
958 GNUNET_SERVICE_OPTION_NONE, 955 GNUNET_SERVICE_OPTION_NONE,
959 &run, 956 &run,
960 &client_connect_cb, 957 &client_connect_cb,
961 &client_disconnect_cb, 958 &client_disconnect_cb,
962 NULL, 959 NULL,
963 GNUNET_MQ_hd_var_size (client_init, 960 GNUNET_MQ_hd_var_size(client_init,
964 GNUNET_MESSAGE_TYPE_CORE_INIT, 961 GNUNET_MESSAGE_TYPE_CORE_INIT,
965 struct InitMessage, 962 struct InitMessage,
966 NULL), 963 NULL),
967 GNUNET_MQ_hd_fixed_size (client_monitor_peers, 964 GNUNET_MQ_hd_fixed_size(client_monitor_peers,
968 GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS, 965 GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS,
969 struct GNUNET_MessageHeader, 966 struct GNUNET_MessageHeader,
970 NULL), 967 NULL),
971 GNUNET_MQ_hd_fixed_size (client_send_request, 968 GNUNET_MQ_hd_fixed_size(client_send_request,
972 GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST, 969 GNUNET_MESSAGE_TYPE_CORE_SEND_REQUEST,
973 struct SendMessageRequest, 970 struct SendMessageRequest,
974 NULL), 971 NULL),
975 GNUNET_MQ_hd_var_size (client_send, 972 GNUNET_MQ_hd_var_size(client_send,
976 GNUNET_MESSAGE_TYPE_CORE_SEND, 973 GNUNET_MESSAGE_TYPE_CORE_SEND,
977 struct SendMessage, 974 struct SendMessage,
978 NULL), 975 NULL),
979 GNUNET_MQ_handler_end ()); 976 GNUNET_MQ_handler_end());
980 977
981 978
982/* end of gnunet-service-core.c */ 979/* end of gnunet-service-core.c */
diff --git a/src/core/gnunet-service-core.h b/src/core/gnunet-service-core.h
index 154596933..7cb4dffa9 100644
--- a/src/core/gnunet-service-core.h
+++ b/src/core/gnunet-service-core.h
@@ -16,7 +16,7 @@
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 core/gnunet-service-core.h 22 * @file core/gnunet-service-core.h
@@ -43,9 +43,7 @@ struct GSC_Client;
43 * client that is still pending. (This struct is used by 43 * client that is still pending. (This struct is used by
44 * both the 'CLIENTS' and 'SESSIONS' subsystems.) 44 * both the 'CLIENTS' and 'SESSIONS' subsystems.)
45 */ 45 */
46struct GSC_ClientActiveRequest 46struct GSC_ClientActiveRequest {
47{
48
49 /** 47 /**
50 * Active requests are kept in a doubly-linked list of 48 * Active requests are kept in a doubly-linked list of
51 * the respective target peer. 49 * the respective target peer.
@@ -108,7 +106,7 @@ struct GSC_ClientActiveRequest
108 * and SESSIONS after this call. 106 * and SESSIONS after this call.
109 */ 107 */
110void 108void
111GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car); 109GSC_CLIENTS_solicit_request(struct GSC_ClientActiveRequest *car);
112 110
113 111
114/** 112/**
@@ -124,8 +122,8 @@ GSC_CLIENTS_solicit_request (struct GSC_ClientActiveRequest *car);
124 * and we should thus drop the connection 122 * and we should thus drop the connection
125 */ 123 */
126void 124void
127GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car, 125GSC_CLIENTS_reject_request(struct GSC_ClientActiveRequest *car,
128 int drop_client); 126 int drop_client);
129 127
130 128
131/** 129/**
@@ -139,7 +137,7 @@ GSC_CLIENTS_reject_request (struct GSC_ClientActiveRequest *car,
139 * @param tmap_new updated type map for the neighbour, NULL for disconnect 137 * @param tmap_new updated type map for the neighbour, NULL for disconnect
140 */ 138 */
141void 139void
142GSC_CLIENTS_notify_client_about_neighbour ( 140GSC_CLIENTS_notify_client_about_neighbour(
143 struct GSC_Client *client, 141 struct GSC_Client *client,
144 const struct GNUNET_PeerIdentity *neighbour, 142 const struct GNUNET_PeerIdentity *neighbour,
145 const struct GSC_TypeMap *tmap_old, 143 const struct GSC_TypeMap *tmap_old,
@@ -158,10 +156,10 @@ GSC_CLIENTS_notify_client_about_neighbour (
158 * receive the message 156 * receive the message
159 */ 157 */
160void 158void
161GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, 159GSC_CLIENTS_deliver_message(const struct GNUNET_PeerIdentity *sender,
162 const struct GNUNET_MessageHeader *msg, 160 const struct GNUNET_MessageHeader *msg,
163 uint16_t msize, 161 uint16_t msize,
164 uint32_t options); 162 uint32_t options);
165 163
166 164
167/** 165/**
@@ -174,7 +172,7 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender,
174 * @param tmap_new updated type map for the neighbour, NULL for disconnect 172 * @param tmap_new updated type map for the neighbour, NULL for disconnect
175 */ 173 */
176void 174void
177GSC_CLIENTS_notify_clients_about_neighbour ( 175GSC_CLIENTS_notify_clients_about_neighbour(
178 const struct GNUNET_PeerIdentity *neighbour, 176 const struct GNUNET_PeerIdentity *neighbour,
179 const struct GSC_TypeMap *tmap_old, 177 const struct GSC_TypeMap *tmap_old,
180 const struct GSC_TypeMap *tmap_new); 178 const struct GSC_TypeMap *tmap_new);
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c
index d226b65e2..e73dc2430 100644
--- a/src/core/gnunet-service-core_kx.c
+++ b/src/core/gnunet-service-core_kx.c
@@ -16,7 +16,7 @@
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 core/gnunet-service-core_kx.c 22 * @file core/gnunet-service-core_kx.c
@@ -44,25 +44,25 @@
44 * How long do we wait for SET_KEY confirmation initially? 44 * How long do we wait for SET_KEY confirmation initially?
45 */ 45 */
46#define INITIAL_SET_KEY_RETRY_FREQUENCY \ 46#define INITIAL_SET_KEY_RETRY_FREQUENCY \
47 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) 47 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
48 48
49/** 49/**
50 * What is the minimum frequency for a PING message? 50 * What is the minimum frequency for a PING message?
51 */ 51 */
52#define MIN_PING_FREQUENCY \ 52#define MIN_PING_FREQUENCY \
53 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) 53 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5)
54 54
55/** 55/**
56 * How often do we rekey? 56 * How often do we rekey?
57 */ 57 */
58#define REKEY_FREQUENCY \ 58#define REKEY_FREQUENCY \
59 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12) 59 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 12)
60 60
61/** 61/**
62 * What time difference do we tolerate? 62 * What time difference do we tolerate?
63 */ 63 */
64#define REKEY_TOLERANCE \ 64#define REKEY_TOLERANCE \
65 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) 65 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
66 66
67/** 67/**
68 * What is the maximum age of a message for us to consider processing 68 * What is the maximum age of a message for us to consider processing
@@ -80,9 +80,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
80 * Message transmitted with the signed ephemeral key of a peer. The 80 * Message transmitted with the signed ephemeral key of a peer. The
81 * session key is then derived from the two ephemeral keys (ECDHE). 81 * session key is then derived from the two ephemeral keys (ECDHE).
82 */ 82 */
83struct EphemeralKeyMessage 83struct EphemeralKeyMessage {
84{
85
86 /** 84 /**
87 * Message type is #GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY. 85 * Message type is #GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY.
88 */ 86 */
@@ -132,8 +130,7 @@ struct EphemeralKeyMessage
132 * can decrypt. The other peer should respond with a PONG with the 130 * can decrypt. The other peer should respond with a PONG with the
133 * same content, except this time encrypted with the receiver's key. 131 * same content, except this time encrypted with the receiver's key.
134 */ 132 */
135struct PingMessage 133struct PingMessage {
136{
137 /** 134 /**
138 * Message type is #GNUNET_MESSAGE_TYPE_CORE_PING. 135 * Message type is #GNUNET_MESSAGE_TYPE_CORE_PING.
139 */ 136 */
@@ -160,8 +157,7 @@ struct PingMessage
160/** 157/**
161 * Response to a PING. Includes data from the original PING. 158 * Response to a PING. Includes data from the original PING.
162 */ 159 */
163struct PongMessage 160struct PongMessage {
164{
165 /** 161 /**
166 * Message type is #GNUNET_MESSAGE_TYPE_CORE_PONG. 162 * Message type is #GNUNET_MESSAGE_TYPE_CORE_PONG.
167 */ 163 */
@@ -194,8 +190,7 @@ struct PongMessage
194 * Encapsulation for encrypted messages exchanged between 190 * Encapsulation for encrypted messages exchanged between
195 * peers. Followed by the actual encrypted data. 191 * peers. Followed by the actual encrypted data.
196 */ 192 */
197struct EncryptedMessage 193struct EncryptedMessage {
198{
199 /** 194 /**
200 * Message type is #GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE. 195 * Message type is #GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE.
201 */ 196 */
@@ -240,15 +235,13 @@ GNUNET_NETWORK_STRUCT_END
240 * that are NOT encrypted. 235 * that are NOT encrypted.
241 */ 236 */
242#define ENCRYPTED_HEADER_SIZE \ 237#define ENCRYPTED_HEADER_SIZE \
243 (offsetof (struct EncryptedMessage, sequence_number)) 238 (offsetof(struct EncryptedMessage, sequence_number))
244 239
245 240
246/** 241/**
247 * Information about the status of a key exchange with another peer. 242 * Information about the status of a key exchange with another peer.
248 */ 243 */
249struct GSC_KeyExchangeInfo 244struct GSC_KeyExchangeInfo {
250{
251
252 /** 245 /**
253 * DLL. 246 * DLL.
254 */ 247 */
@@ -408,13 +401,13 @@ static struct GNUNET_NotificationContext *nc;
408 * @param kx key exchange context 401 * @param kx key exchange context
409 */ 402 */
410static uint32_t 403static uint32_t
411calculate_seed (struct GSC_KeyExchangeInfo *kx) 404calculate_seed(struct GSC_KeyExchangeInfo *kx)
412{ 405{
413 /* Note: may want to make this non-random and instead 406 /* Note: may want to make this non-random and instead
414 derive from key material to avoid having an undetectable 407 derive from key material to avoid having an undetectable
415 side-channel */ 408 side-channel */
416 return htonl ( 409 return htonl(
417 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX)); 410 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
418} 411}
419 412
420 413
@@ -424,16 +417,16 @@ calculate_seed (struct GSC_KeyExchangeInfo *kx)
424 * @param kx key exchange state to inform about 417 * @param kx key exchange state to inform about
425 */ 418 */
426static void 419static void
427monitor_notify_all (struct GSC_KeyExchangeInfo *kx) 420monitor_notify_all(struct GSC_KeyExchangeInfo *kx)
428{ 421{
429 struct MonitorNotifyMessage msg; 422 struct MonitorNotifyMessage msg;
430 423
431 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY); 424 msg.header.type = htons(GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY);
432 msg.header.size = htons (sizeof (msg)); 425 msg.header.size = htons(sizeof(msg));
433 msg.state = htonl ((uint32_t) kx->status); 426 msg.state = htonl((uint32_t)kx->status);
434 msg.peer = *kx->peer; 427 msg.peer = *kx->peer;
435 msg.timeout = GNUNET_TIME_absolute_hton (kx->timeout); 428 msg.timeout = GNUNET_TIME_absolute_hton(kx->timeout);
436 GNUNET_notification_context_broadcast (nc, &msg.header, GNUNET_NO); 429 GNUNET_notification_context_broadcast(nc, &msg.header, GNUNET_NO);
437 kx->last_notify_timeout = kx->timeout; 430 kx->last_notify_timeout = kx->timeout;
438} 431}
439 432
@@ -446,30 +439,31 @@ monitor_notify_all (struct GSC_KeyExchangeInfo *kx)
446 * @param seed seed to use 439 * @param seed seed to use
447 */ 440 */
448static void 441static void
449derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey, 442derive_auth_key(struct GNUNET_CRYPTO_AuthKey *akey,
450 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, 443 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
451 uint32_t seed) 444 uint32_t seed)
452{ 445{
453 static const char ctx[] = "authentication key"; 446 static const char ctx[] = "authentication key";
447
454#if DEBUG_KX 448#if DEBUG_KX
455 struct GNUNET_HashCode sh; 449 struct GNUNET_HashCode sh;
456 450
457 GNUNET_CRYPTO_hash (skey, sizeof (*skey), &sh); 451 GNUNET_CRYPTO_hash(skey, sizeof(*skey), &sh);
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 452 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
459 "Deriving Auth key from SKEY %s and seed %u\n", 453 "Deriving Auth key from SKEY %s and seed %u\n",
460 GNUNET_h2s (&sh), 454 GNUNET_h2s(&sh),
461 (unsigned int) seed); 455 (unsigned int)seed);
462#endif 456#endif
463 GNUNET_CRYPTO_hmac_derive_key (akey, 457 GNUNET_CRYPTO_hmac_derive_key(akey,
464 skey, 458 skey,
465 &seed, 459 &seed,
466 sizeof (seed), 460 sizeof(seed),
467 skey, 461 skey,
468 sizeof ( 462 sizeof(
469 struct GNUNET_CRYPTO_SymmetricSessionKey), 463 struct GNUNET_CRYPTO_SymmetricSessionKey),
470 ctx, 464 ctx,
471 sizeof (ctx), 465 sizeof(ctx),
472 NULL); 466 NULL);
473} 467}
474 468
475 469
@@ -482,31 +476,32 @@ derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey,
482 * @param identity identity of the other peer to use 476 * @param identity identity of the other peer to use
483 */ 477 */
484static void 478static void
485derive_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, 479derive_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
486 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, 480 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
487 uint32_t seed, 481 uint32_t seed,
488 const struct GNUNET_PeerIdentity *identity) 482 const struct GNUNET_PeerIdentity *identity)
489{ 483{
490 static const char ctx[] = "initialization vector"; 484 static const char ctx[] = "initialization vector";
485
491#if DEBUG_KX 486#if DEBUG_KX
492 struct GNUNET_HashCode sh; 487 struct GNUNET_HashCode sh;
493 488
494 GNUNET_CRYPTO_hash (skey, sizeof (*skey), &sh); 489 GNUNET_CRYPTO_hash(skey, sizeof(*skey), &sh);
495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 490 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
496 "Deriving IV from SKEY %s and seed %u for peer %s\n", 491 "Deriving IV from SKEY %s and seed %u for peer %s\n",
497 GNUNET_h2s (&sh), 492 GNUNET_h2s(&sh),
498 (unsigned int) seed, 493 (unsigned int)seed,
499 GNUNET_i2s (identity)); 494 GNUNET_i2s(identity));
500#endif 495#endif
501 GNUNET_CRYPTO_symmetric_derive_iv (iv, 496 GNUNET_CRYPTO_symmetric_derive_iv(iv,
502 skey, 497 skey,
503 &seed, 498 &seed,
504 sizeof (seed), 499 sizeof(seed),
505 identity, 500 identity,
506 sizeof (struct GNUNET_PeerIdentity), 501 sizeof(struct GNUNET_PeerIdentity),
507 ctx, 502 ctx,
508 sizeof (ctx), 503 sizeof(ctx),
509 NULL); 504 NULL);
510} 505}
511 506
512 507
@@ -520,35 +515,36 @@ derive_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
520 * @param identity identity of the other peer to use 515 * @param identity identity of the other peer to use
521 */ 516 */
522static void 517static void
523derive_pong_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, 518derive_pong_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
524 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, 519 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
525 uint32_t seed, 520 uint32_t seed,
526 uint32_t challenge, 521 uint32_t challenge,
527 const struct GNUNET_PeerIdentity *identity) 522 const struct GNUNET_PeerIdentity *identity)
528{ 523{
529 static const char ctx[] = "pong initialization vector"; 524 static const char ctx[] = "pong initialization vector";
525
530#if DEBUG_KX 526#if DEBUG_KX
531 struct GNUNET_HashCode sh; 527 struct GNUNET_HashCode sh;
532 528
533 GNUNET_CRYPTO_hash (skey, sizeof (*skey), &sh); 529 GNUNET_CRYPTO_hash(skey, sizeof(*skey), &sh);
534 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 530 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
535 "Deriving PONG IV from SKEY %s and seed %u/%u for %s\n", 531 "Deriving PONG IV from SKEY %s and seed %u/%u for %s\n",
536 GNUNET_h2s (&sh), 532 GNUNET_h2s(&sh),
537 (unsigned int) seed, 533 (unsigned int)seed,
538 (unsigned int) challenge, 534 (unsigned int)challenge,
539 GNUNET_i2s (identity)); 535 GNUNET_i2s(identity));
540#endif 536#endif
541 GNUNET_CRYPTO_symmetric_derive_iv (iv, 537 GNUNET_CRYPTO_symmetric_derive_iv(iv,
542 skey, 538 skey,
543 &seed, 539 &seed,
544 sizeof (seed), 540 sizeof(seed),
545 identity, 541 identity,
546 sizeof (struct GNUNET_PeerIdentity), 542 sizeof(struct GNUNET_PeerIdentity),
547 &challenge, 543 &challenge,
548 sizeof (challenge), 544 sizeof(challenge),
549 ctx, 545 ctx,
550 sizeof (ctx), 546 sizeof(ctx),
551 NULL); 547 NULL);
552} 548}
553 549
554 550
@@ -561,33 +557,34 @@ derive_pong_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
561 * @param skey set to derived session key 557 * @param skey set to derived session key
562 */ 558 */
563static void 559static void
564derive_aes_key (const struct GNUNET_PeerIdentity *sender, 560derive_aes_key(const struct GNUNET_PeerIdentity *sender,
565 const struct GNUNET_PeerIdentity *receiver, 561 const struct GNUNET_PeerIdentity *receiver,
566 const struct GNUNET_HashCode *key_material, 562 const struct GNUNET_HashCode *key_material,
567 struct GNUNET_CRYPTO_SymmetricSessionKey *skey) 563 struct GNUNET_CRYPTO_SymmetricSessionKey *skey)
568{ 564{
569 static const char ctx[] = "aes key generation vector"; 565 static const char ctx[] = "aes key generation vector";
566
570#if DEBUG_KX 567#if DEBUG_KX
571 struct GNUNET_HashCode sh; 568 struct GNUNET_HashCode sh;
572 569
573 GNUNET_CRYPTO_hash (skey, sizeof (*skey), &sh); 570 GNUNET_CRYPTO_hash(skey, sizeof(*skey), &sh);
574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 571 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
575 "Deriving AES Keys for %s to %s from %s\n", 572 "Deriving AES Keys for %s to %s from %s\n",
576 GNUNET_i2s (sender), 573 GNUNET_i2s(sender),
577 GNUNET_i2s2 (receiver), 574 GNUNET_i2s2(receiver),
578 GNUNET_h2s (key_material)); 575 GNUNET_h2s(key_material));
579#endif 576#endif
580 GNUNET_CRYPTO_kdf (skey, 577 GNUNET_CRYPTO_kdf(skey,
581 sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey), 578 sizeof(struct GNUNET_CRYPTO_SymmetricSessionKey),
582 ctx, 579 ctx,
583 sizeof (ctx), 580 sizeof(ctx),
584 key_material, 581 key_material,
585 sizeof (struct GNUNET_HashCode), 582 sizeof(struct GNUNET_HashCode),
586 sender, 583 sender,
587 sizeof (struct GNUNET_PeerIdentity), 584 sizeof(struct GNUNET_PeerIdentity),
588 receiver, 585 receiver,
589 sizeof (struct GNUNET_PeerIdentity), 586 sizeof(struct GNUNET_PeerIdentity),
590 NULL); 587 NULL);
591} 588}
592 589
593 590
@@ -603,35 +600,35 @@ derive_aes_key (const struct GNUNET_PeerIdentity *sender,
603 * @return #GNUNET_OK on success 600 * @return #GNUNET_OK on success
604 */ 601 */
605static int 602static int
606do_encrypt (struct GSC_KeyExchangeInfo *kx, 603do_encrypt(struct GSC_KeyExchangeInfo *kx,
607 const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, 604 const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
608 const void *in, 605 const void *in,
609 void *out, 606 void *out,
610 size_t size) 607 size_t size)
611{ 608{
612 if (size != (uint16_t) size) 609 if (size != (uint16_t)size)
613 { 610 {
614 GNUNET_break (0); 611 GNUNET_break(0);
615 return GNUNET_NO; 612 return GNUNET_NO;
616 } 613 }
617 GNUNET_assert (size == GNUNET_CRYPTO_symmetric_encrypt (in, 614 GNUNET_assert(size == GNUNET_CRYPTO_symmetric_encrypt(in,
618 (uint16_t) size, 615 (uint16_t)size,
619 &kx->encrypt_key, 616 &kx->encrypt_key,
620 iv, 617 iv,
621 out)); 618 out));
622 GNUNET_STATISTICS_update (GSC_stats, 619 GNUNET_STATISTICS_update(GSC_stats,
623 gettext_noop ("# bytes encrypted"), 620 gettext_noop("# bytes encrypted"),
624 size, 621 size,
625 GNUNET_NO); 622 GNUNET_NO);
626 /* the following is too sensitive to write to log files by accident, 623 /* the following is too sensitive to write to log files by accident,
627 so we require manual intervention to get this one... */ 624 so we require manual intervention to get this one... */
628#if DEBUG_KX 625#if DEBUG_KX
629 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 626 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
630 "Encrypted %u bytes for `%s' using key %u, IV %u\n", 627 "Encrypted %u bytes for `%s' using key %u, IV %u\n",
631 (unsigned int) size, 628 (unsigned int)size,
632 GNUNET_i2s (kx->peer), 629 GNUNET_i2s(kx->peer),
633 (unsigned int) kx->encrypt_key.crc32, 630 (unsigned int)kx->encrypt_key.crc32,
634 GNUNET_CRYPTO_crc32_n (iv, sizeof (iv))); 631 GNUNET_CRYPTO_crc32_n(iv, sizeof(iv)));
635#endif 632#endif
636 return GNUNET_OK; 633 return GNUNET_OK;
637} 634}
@@ -650,46 +647,46 @@ do_encrypt (struct GSC_KeyExchangeInfo *kx,
650 * @return #GNUNET_OK on success 647 * @return #GNUNET_OK on success
651 */ 648 */
652static int 649static int
653do_decrypt (struct GSC_KeyExchangeInfo *kx, 650do_decrypt(struct GSC_KeyExchangeInfo *kx,
654 const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, 651 const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
655 const void *in, 652 const void *in,
656 void *out, 653 void *out,
657 size_t size) 654 size_t size)
658{ 655{
659 if (size != (uint16_t) size) 656 if (size != (uint16_t)size)
660 { 657 {
661 GNUNET_break (0); 658 GNUNET_break(0);
662 return GNUNET_NO; 659 return GNUNET_NO;
663 } 660 }
664 if ((kx->status != GNUNET_CORE_KX_STATE_KEY_RECEIVED) && 661 if ((kx->status != GNUNET_CORE_KX_STATE_KEY_RECEIVED) &&
665 (kx->status != GNUNET_CORE_KX_STATE_UP) && 662 (kx->status != GNUNET_CORE_KX_STATE_UP) &&
666 (kx->status != GNUNET_CORE_KX_STATE_REKEY_SENT)) 663 (kx->status != GNUNET_CORE_KX_STATE_REKEY_SENT))
667 { 664 {
668 GNUNET_break_op (0); 665 GNUNET_break_op(0);
669 return GNUNET_SYSERR; 666 return GNUNET_SYSERR;
670 } 667 }
671 if (size != GNUNET_CRYPTO_symmetric_decrypt (in, 668 if (size != GNUNET_CRYPTO_symmetric_decrypt(in,
672 (uint16_t) size, 669 (uint16_t)size,
673 &kx->decrypt_key, 670 &kx->decrypt_key,
674 iv, 671 iv,
675 out)) 672 out))
676 { 673 {
677 GNUNET_break (0); 674 GNUNET_break(0);
678 return GNUNET_SYSERR; 675 return GNUNET_SYSERR;
679 } 676 }
680 GNUNET_STATISTICS_update (GSC_stats, 677 GNUNET_STATISTICS_update(GSC_stats,
681 gettext_noop ("# bytes decrypted"), 678 gettext_noop("# bytes decrypted"),
682 size, 679 size,
683 GNUNET_NO); 680 GNUNET_NO);
684 /* the following is too sensitive to write to log files by accident, 681 /* the following is too sensitive to write to log files by accident,
685 so we require manual intervention to get this one... */ 682 so we require manual intervention to get this one... */
686#if DEBUG_KX 683#if DEBUG_KX
687 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 684 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
688 "Decrypted %u bytes from `%s' using key %u, IV %u\n", 685 "Decrypted %u bytes from `%s' using key %u, IV %u\n",
689 (unsigned int) size, 686 (unsigned int)size,
690 GNUNET_i2s (kx->peer), 687 GNUNET_i2s(kx->peer),
691 (unsigned int) kx->decrypt_key.crc32, 688 (unsigned int)kx->decrypt_key.crc32,
692 GNUNET_CRYPTO_crc32_n (iv, sizeof (*iv))); 689 GNUNET_CRYPTO_crc32_n(iv, sizeof(*iv)));
693#endif 690#endif
694 return GNUNET_OK; 691 return GNUNET_OK;
695} 692}
@@ -701,7 +698,7 @@ do_decrypt (struct GSC_KeyExchangeInfo *kx,
701 * @param kx key exchange context 698 * @param kx key exchange context
702 */ 699 */
703static void 700static void
704send_key (struct GSC_KeyExchangeInfo *kx); 701send_key(struct GSC_KeyExchangeInfo *kx);
705 702
706 703
707/** 704/**
@@ -710,15 +707,15 @@ send_key (struct GSC_KeyExchangeInfo *kx);
710 * @param cls our `struct GSC_KeyExchangeInfo` 707 * @param cls our `struct GSC_KeyExchangeInfo`
711 */ 708 */
712static void 709static void
713set_key_retry_task (void *cls) 710set_key_retry_task(void *cls)
714{ 711{
715 struct GSC_KeyExchangeInfo *kx = cls; 712 struct GSC_KeyExchangeInfo *kx = cls;
716 713
717 kx->retry_set_key_task = NULL; 714 kx->retry_set_key_task = NULL;
718 kx->set_key_retry_frequency = 715 kx->set_key_retry_frequency =
719 GNUNET_TIME_STD_BACKOFF (kx->set_key_retry_frequency); 716 GNUNET_TIME_STD_BACKOFF(kx->set_key_retry_frequency);
720 GNUNET_assert (GNUNET_CORE_KX_STATE_DOWN != kx->status); 717 GNUNET_assert(GNUNET_CORE_KX_STATE_DOWN != kx->status);
721 send_key (kx); 718 send_key(kx);
722} 719}
723 720
724 721
@@ -728,7 +725,7 @@ set_key_retry_task (void *cls)
728 * @param kx key exchange context to create PING for 725 * @param kx key exchange context to create PING for
729 */ 726 */
730static void 727static void
731setup_fresh_ping (struct GSC_KeyExchangeInfo *kx) 728setup_fresh_ping(struct GSC_KeyExchangeInfo *kx)
732{ 729{
733 struct PingMessage pp; 730 struct PingMessage pp;
734 struct PingMessage *pm; 731 struct PingMessage *pm;
@@ -736,19 +733,19 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx)
736 733
737 pm = &kx->ping; 734 pm = &kx->ping;
738 kx->ping_challenge = 735 kx->ping_challenge =
739 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX); 736 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX);
740 pm->header.size = htons (sizeof (struct PingMessage)); 737 pm->header.size = htons(sizeof(struct PingMessage));
741 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); 738 pm->header.type = htons(GNUNET_MESSAGE_TYPE_CORE_PING);
742 pm->iv_seed = calculate_seed (kx); 739 pm->iv_seed = calculate_seed(kx);
743 derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, kx->peer); 740 derive_iv(&iv, &kx->encrypt_key, pm->iv_seed, kx->peer);
744 pp.challenge = kx->ping_challenge; 741 pp.challenge = kx->ping_challenge;
745 pp.target = *kx->peer; 742 pp.target = *kx->peer;
746 do_encrypt (kx, 743 do_encrypt(kx,
747 &iv, 744 &iv,
748 &pp.target, 745 &pp.target,
749 &pm->target, 746 &pm->target,
750 sizeof (struct PingMessage) - 747 sizeof(struct PingMessage) -
751 ((void *) &pm->target - (void *) pm)); 748 ((void *)&pm->target - (void *)pm));
752} 749}
753 750
754 751
@@ -764,41 +761,43 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx)
764 * #GNUNET_SYSERR to stop further processing with error 761 * #GNUNET_SYSERR to stop further processing with error
765 */ 762 */
766static int 763static int
767deliver_message (void *cls, const struct GNUNET_MessageHeader *m) 764deliver_message(void *cls, const struct GNUNET_MessageHeader *m)
768{ 765{
769 struct GSC_KeyExchangeInfo *kx = cls; 766 struct GSC_KeyExchangeInfo *kx = cls;
770 767
771 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 768 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
772 "Decrypted message of type %d from %s\n", 769 "Decrypted message of type %d from %s\n",
773 ntohs (m->type), 770 ntohs(m->type),
774 GNUNET_i2s (kx->peer)); 771 GNUNET_i2s(kx->peer));
775 if (GNUNET_CORE_KX_STATE_UP != kx->status) 772 if (GNUNET_CORE_KX_STATE_UP != kx->status)
776 { 773 {
777 GNUNET_STATISTICS_update (GSC_stats, 774 GNUNET_STATISTICS_update(GSC_stats,
778 gettext_noop ("# PAYLOAD dropped (out of order)"), 775 gettext_noop("# PAYLOAD dropped (out of order)"),
779 1, 776 1,
780 GNUNET_NO); 777 GNUNET_NO);
781 return GNUNET_OK; 778 return GNUNET_OK;
782 } 779 }
783 switch (ntohs (m->type)) 780 switch (ntohs(m->type))
784 { 781 {
785 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: 782 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
786 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: 783 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
787 GSC_SESSIONS_set_typemap (kx->peer, m); 784 GSC_SESSIONS_set_typemap(kx->peer, m);
788 return GNUNET_OK; 785 return GNUNET_OK;
789 case GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP: 786
790 GSC_SESSIONS_confirm_typemap (kx->peer, m); 787 case GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP:
791 return GNUNET_OK; 788 GSC_SESSIONS_confirm_typemap(kx->peer, m);
792 default: 789 return GNUNET_OK;
793 GSC_CLIENTS_deliver_message (kx->peer, 790
794 m, 791 default:
795 ntohs (m->size), 792 GSC_CLIENTS_deliver_message(kx->peer,
796 GNUNET_CORE_OPTION_SEND_FULL_INBOUND); 793 m,
797 GSC_CLIENTS_deliver_message (kx->peer, 794 ntohs(m->size),
798 m, 795 GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
799 sizeof (struct GNUNET_MessageHeader), 796 GSC_CLIENTS_deliver_message(kx->peer,
800 GNUNET_CORE_OPTION_SEND_HDR_INBOUND); 797 m,
801 } 798 sizeof(struct GNUNET_MessageHeader),
799 GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
800 }
802 return GNUNET_OK; 801 return GNUNET_OK;
803} 802}
804 803
@@ -813,49 +812,49 @@ deliver_message (void *cls, const struct GNUNET_MessageHeader *m)
813 * @return key exchange information context 812 * @return key exchange information context
814 */ 813 */
815static void * 814static void *
816handle_transport_notify_connect (void *cls, 815handle_transport_notify_connect(void *cls,
817 const struct GNUNET_PeerIdentity *pid, 816 const struct GNUNET_PeerIdentity *pid,
818 struct GNUNET_MQ_Handle *mq) 817 struct GNUNET_MQ_Handle *mq)
819{ 818{
820 struct GSC_KeyExchangeInfo *kx; 819 struct GSC_KeyExchangeInfo *kx;
821 struct GNUNET_HashCode h1; 820 struct GNUNET_HashCode h1;
822 struct GNUNET_HashCode h2; 821 struct GNUNET_HashCode h2;
823 822
824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 823 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
825 "Initiating key exchange with `%s'\n", 824 "Initiating key exchange with `%s'\n",
826 GNUNET_i2s (pid)); 825 GNUNET_i2s(pid));
827 GNUNET_STATISTICS_update (GSC_stats, 826 GNUNET_STATISTICS_update(GSC_stats,
828 gettext_noop ("# key exchanges initiated"), 827 gettext_noop("# key exchanges initiated"),
829 1, 828 1,
830 GNUNET_NO); 829 GNUNET_NO);
831 kx = GNUNET_new (struct GSC_KeyExchangeInfo); 830 kx = GNUNET_new(struct GSC_KeyExchangeInfo);
832 kx->mst = GNUNET_MST_create (&deliver_message, kx); 831 kx->mst = GNUNET_MST_create(&deliver_message, kx);
833 kx->mq = mq; 832 kx->mq = mq;
834 kx->peer = pid; 833 kx->peer = pid;
835 kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; 834 kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY;
836 GNUNET_CONTAINER_DLL_insert (kx_head, kx_tail, kx); 835 GNUNET_CONTAINER_DLL_insert(kx_head, kx_tail, kx);
837 kx->status = GNUNET_CORE_KX_STATE_KEY_SENT; 836 kx->status = GNUNET_CORE_KX_STATE_KEY_SENT;
838 monitor_notify_all (kx); 837 monitor_notify_all(kx);
839 GNUNET_CRYPTO_hash (pid, sizeof (struct GNUNET_PeerIdentity), &h1); 838 GNUNET_CRYPTO_hash(pid, sizeof(struct GNUNET_PeerIdentity), &h1);
840 GNUNET_CRYPTO_hash (&GSC_my_identity, 839 GNUNET_CRYPTO_hash(&GSC_my_identity,
841 sizeof (struct GNUNET_PeerIdentity), 840 sizeof(struct GNUNET_PeerIdentity),
842 &h2); 841 &h2);
843 if (0 < GNUNET_CRYPTO_hash_cmp (&h1, &h2)) 842 if (0 < GNUNET_CRYPTO_hash_cmp(&h1, &h2))
844 { 843 {
845 /* peer with "lower" identity starts KX, otherwise we typically end up 844 /* peer with "lower" identity starts KX, otherwise we typically end up
846 with both peers starting the exchange and transmit the 'set key' 845 with both peers starting the exchange and transmit the 'set key'
847 message twice */ 846 message twice */
848 send_key (kx); 847 send_key(kx);
849 } 848 }
850 else 849 else
851 { 850 {
852 /* peer with "higher" identity starts a delayed KX, if the "lower" peer 851 /* peer with "higher" identity starts a delayed KX, if the "lower" peer
853 * does not start a KX since it sees no reasons to do so */ 852 * does not start a KX since it sees no reasons to do so */
854 kx->retry_set_key_task = 853 kx->retry_set_key_task =
855 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, 854 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS,
856 &set_key_retry_task, 855 &set_key_retry_task,
857 kx); 856 kx);
858 } 857 }
859 return kx; 858 return kx;
860} 859}
861 860
@@ -870,35 +869,35 @@ handle_transport_notify_connect (void *cls,
870 * @param handler_cls the `struct GSC_KeyExchangeInfo` of the peer 869 * @param handler_cls the `struct GSC_KeyExchangeInfo` of the peer
871 */ 870 */
872static void 871static void
873handle_transport_notify_disconnect (void *cls, 872handle_transport_notify_disconnect(void *cls,
874 const struct GNUNET_PeerIdentity *peer, 873 const struct GNUNET_PeerIdentity *peer,
875 void *handler_cls) 874 void *handler_cls)
876{ 875{
877 struct GSC_KeyExchangeInfo *kx = handler_cls; 876 struct GSC_KeyExchangeInfo *kx = handler_cls;
878 877
879 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 878 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
880 "Peer `%s' disconnected from us.\n", 879 "Peer `%s' disconnected from us.\n",
881 GNUNET_i2s (peer)); 880 GNUNET_i2s(peer));
882 GSC_SESSIONS_end (kx->peer); 881 GSC_SESSIONS_end(kx->peer);
883 GNUNET_STATISTICS_update (GSC_stats, 882 GNUNET_STATISTICS_update(GSC_stats,
884 gettext_noop ("# key exchanges stopped"), 883 gettext_noop("# key exchanges stopped"),
885 1, 884 1,
886 GNUNET_NO); 885 GNUNET_NO);
887 if (NULL != kx->retry_set_key_task) 886 if (NULL != kx->retry_set_key_task)
888 { 887 {
889 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); 888 GNUNET_SCHEDULER_cancel(kx->retry_set_key_task);
890 kx->retry_set_key_task = NULL; 889 kx->retry_set_key_task = NULL;
891 } 890 }
892 if (NULL != kx->keep_alive_task) 891 if (NULL != kx->keep_alive_task)
893 { 892 {
894 GNUNET_SCHEDULER_cancel (kx->keep_alive_task); 893 GNUNET_SCHEDULER_cancel(kx->keep_alive_task);
895 kx->keep_alive_task = NULL; 894 kx->keep_alive_task = NULL;
896 } 895 }
897 kx->status = GNUNET_CORE_KX_PEER_DISCONNECT; 896 kx->status = GNUNET_CORE_KX_PEER_DISCONNECT;
898 monitor_notify_all (kx); 897 monitor_notify_all(kx);
899 GNUNET_CONTAINER_DLL_remove (kx_head, kx_tail, kx); 898 GNUNET_CONTAINER_DLL_remove(kx_head, kx_tail, kx);
900 GNUNET_MST_destroy (kx->mst); 899 GNUNET_MST_destroy(kx->mst);
901 GNUNET_free (kx); 900 GNUNET_free(kx);
902} 901}
903 902
904 903
@@ -908,16 +907,16 @@ handle_transport_notify_disconnect (void *cls,
908 * @param kx key exchange context 907 * @param kx key exchange context
909 */ 908 */
910static void 909static void
911send_ping (struct GSC_KeyExchangeInfo *kx) 910send_ping(struct GSC_KeyExchangeInfo *kx)
912{ 911{
913 struct GNUNET_MQ_Envelope *env; 912 struct GNUNET_MQ_Envelope *env;
914 913
915 GNUNET_STATISTICS_update (GSC_stats, 914 GNUNET_STATISTICS_update(GSC_stats,
916 gettext_noop ("# PING messages transmitted"), 915 gettext_noop("# PING messages transmitted"),
917 1, 916 1,
918 GNUNET_NO); 917 GNUNET_NO);
919 env = GNUNET_MQ_msg_copy (&kx->ping.header); 918 env = GNUNET_MQ_msg_copy(&kx->ping.header);
920 GNUNET_MQ_send (kx->mq, env); 919 GNUNET_MQ_send(kx->mq, env);
921} 920}
922 921
923 922
@@ -927,24 +926,24 @@ send_ping (struct GSC_KeyExchangeInfo *kx)
927 * @param kx session to derive keys for 926 * @param kx session to derive keys for
928 */ 927 */
929static void 928static void
930derive_session_keys (struct GSC_KeyExchangeInfo *kx) 929derive_session_keys(struct GSC_KeyExchangeInfo *kx)
931{ 930{
932 struct GNUNET_HashCode key_material; 931 struct GNUNET_HashCode key_material;
933 932
934 if (GNUNET_OK != GNUNET_CRYPTO_ecc_ecdh (my_ephemeral_key, 933 if (GNUNET_OK != GNUNET_CRYPTO_ecc_ecdh(my_ephemeral_key,
935 &kx->other_ephemeral_key, 934 &kx->other_ephemeral_key,
936 &key_material)) 935 &key_material))
937 { 936 {
938 GNUNET_break (0); 937 GNUNET_break(0);
939 return; 938 return;
940 } 939 }
941 derive_aes_key (&GSC_my_identity, kx->peer, &key_material, &kx->encrypt_key); 940 derive_aes_key(&GSC_my_identity, kx->peer, &key_material, &kx->encrypt_key);
942 derive_aes_key (kx->peer, &GSC_my_identity, &key_material, &kx->decrypt_key); 941 derive_aes_key(kx->peer, &GSC_my_identity, &key_material, &kx->decrypt_key);
943 memset (&key_material, 0, sizeof (key_material)); 942 memset(&key_material, 0, sizeof(key_material));
944 /* fresh key, reset sequence numbers */ 943 /* fresh key, reset sequence numbers */
945 kx->last_sequence_number_received = 0; 944 kx->last_sequence_number_received = 0;
946 kx->last_packets_bitmap = 0; 945 kx->last_packets_bitmap = 0;
947 setup_fresh_ping (kx); 946 setup_fresh_ping(kx);
948} 947}
949 948
950 949
@@ -956,7 +955,7 @@ derive_session_keys (struct GSC_KeyExchangeInfo *kx)
956 * @param m the set key message we received 955 * @param m the set key message we received
957 */ 956 */
958static void 957static void
959handle_ephemeral_key (void *cls, const struct EphemeralKeyMessage *m) 958handle_ephemeral_key(void *cls, const struct EphemeralKeyMessage *m)
960{ 959{
961 struct GSC_KeyExchangeInfo *kx = cls; 960 struct GSC_KeyExchangeInfo *kx = cls;
962 struct GNUNET_TIME_Absolute start_t; 961 struct GNUNET_TIME_Absolute start_t;
@@ -964,183 +963,193 @@ handle_ephemeral_key (void *cls, const struct EphemeralKeyMessage *m)
964 struct GNUNET_TIME_Absolute now; 963 struct GNUNET_TIME_Absolute now;
965 enum GNUNET_CORE_KxState sender_status; 964 enum GNUNET_CORE_KxState sender_status;
966 965
967 end_t = GNUNET_TIME_absolute_ntoh (m->expiration_time); 966 end_t = GNUNET_TIME_absolute_ntoh(m->expiration_time);
968 if (((GNUNET_CORE_KX_STATE_KEY_RECEIVED == kx->status) || 967 if (((GNUNET_CORE_KX_STATE_KEY_RECEIVED == kx->status) ||
969 (GNUNET_CORE_KX_STATE_UP == kx->status) || 968 (GNUNET_CORE_KX_STATE_UP == kx->status) ||
970 (GNUNET_CORE_KX_STATE_REKEY_SENT == kx->status)) && 969 (GNUNET_CORE_KX_STATE_REKEY_SENT == kx->status)) &&
971 (end_t.abs_value_us < kx->foreign_key_expires.abs_value_us)) 970 (end_t.abs_value_us < kx->foreign_key_expires.abs_value_us))
972 { 971 {
973 GNUNET_STATISTICS_update (GSC_stats, 972 GNUNET_STATISTICS_update(GSC_stats,
974 gettext_noop ("# old ephemeral keys ignored"), 973 gettext_noop("# old ephemeral keys ignored"),
975 1, 974 1,
976 GNUNET_NO); 975 GNUNET_NO);
977 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 976 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
978 "Received expired EPHEMERAL_KEY from %s\n", 977 "Received expired EPHEMERAL_KEY from %s\n",
979 GNUNET_i2s (&m->origin_identity)); 978 GNUNET_i2s(&m->origin_identity));
980 return; 979 return;
981 } 980 }
982 if (0 == memcmp (&m->ephemeral_key, 981 if (0 == memcmp(&m->ephemeral_key,
983 &kx->other_ephemeral_key, 982 &kx->other_ephemeral_key,
984 sizeof (m->ephemeral_key))) 983 sizeof(m->ephemeral_key)))
985 { 984 {
986 GNUNET_STATISTICS_update (GSC_stats, 985 GNUNET_STATISTICS_update(GSC_stats,
987 gettext_noop ( 986 gettext_noop(
988 "# duplicate ephemeral keys ignored"), 987 "# duplicate ephemeral keys ignored"),
989 1, 988 1,
990 GNUNET_NO); 989 GNUNET_NO);
991 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 990 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
992 "Ignoring duplicate EPHEMERAL_KEY from %s\n", 991 "Ignoring duplicate EPHEMERAL_KEY from %s\n",
993 GNUNET_i2s (&m->origin_identity)); 992 GNUNET_i2s(&m->origin_identity));
994 return; 993 return;
995 } 994 }
996 if (0 != memcmp (&m->origin_identity, 995 if (0 != memcmp(&m->origin_identity,
997 kx->peer, 996 kx->peer,
998 sizeof (struct GNUNET_PeerIdentity))) 997 sizeof(struct GNUNET_PeerIdentity)))
999 { 998 {
1000 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 999 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1001 "Received EPHEMERAL_KEY from %s, but expected %s\n", 1000 "Received EPHEMERAL_KEY from %s, but expected %s\n",
1002 GNUNET_i2s (&m->origin_identity), 1001 GNUNET_i2s(&m->origin_identity),
1003 GNUNET_i2s_full (kx->peer)); 1002 GNUNET_i2s_full(kx->peer));
1004 GNUNET_break_op (0); 1003 GNUNET_break_op(0);
1005 return; 1004 return;
1006 } 1005 }
1007 if ((ntohl (m->purpose.size) != 1006 if ((ntohl(m->purpose.size) !=
1008 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + 1007 sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) +
1009 sizeof (struct GNUNET_TIME_AbsoluteNBO) + 1008 sizeof(struct GNUNET_TIME_AbsoluteNBO) +
1010 sizeof (struct GNUNET_TIME_AbsoluteNBO) + 1009 sizeof(struct GNUNET_TIME_AbsoluteNBO) +
1011 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) + 1010 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey) +
1012 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)) || 1011 sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) ||
1013 (GNUNET_OK != 1012 (GNUNET_OK !=
1014 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY, 1013 GNUNET_CRYPTO_eddsa_verify(GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY,
1015 &m->purpose, 1014 &m->purpose,
1016 &m->signature, 1015 &m->signature,
1017 &m->origin_identity.public_key))) 1016 &m->origin_identity.public_key)))
1018 { 1017 {
1019 /* invalid signature */ 1018 /* invalid signature */
1020 GNUNET_break_op (0); 1019 GNUNET_break_op(0);
1021 GNUNET_STATISTICS_update (GSC_stats, 1020 GNUNET_STATISTICS_update(GSC_stats,
1022 gettext_noop ( 1021 gettext_noop(
1023 "# EPHEMERAL_KEYs rejected (bad signature)"), 1022 "# EPHEMERAL_KEYs rejected (bad signature)"),
1024 1, 1023 1,
1025 GNUNET_NO); 1024 GNUNET_NO);
1026 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1025 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1027 "Received EPHEMERAL_KEY from %s with bad signature\n", 1026 "Received EPHEMERAL_KEY from %s with bad signature\n",
1028 GNUNET_i2s (&m->origin_identity)); 1027 GNUNET_i2s(&m->origin_identity));
1029 return; 1028 return;
1030 } 1029 }
1031 now = GNUNET_TIME_absolute_get (); 1030 now = GNUNET_TIME_absolute_get();
1032 start_t = GNUNET_TIME_absolute_ntoh (m->creation_time); 1031 start_t = GNUNET_TIME_absolute_ntoh(m->creation_time);
1033 if ((end_t.abs_value_us < 1032 if ((end_t.abs_value_us <
1034 GNUNET_TIME_absolute_subtract (now, REKEY_TOLERANCE).abs_value_us) || 1033 GNUNET_TIME_absolute_subtract(now, REKEY_TOLERANCE).abs_value_us) ||
1035 (start_t.abs_value_us > 1034 (start_t.abs_value_us >
1036 GNUNET_TIME_absolute_add (now, REKEY_TOLERANCE).abs_value_us)) 1035 GNUNET_TIME_absolute_add(now, REKEY_TOLERANCE).abs_value_us))
1037 { 1036 {
1038 GNUNET_log ( 1037 GNUNET_log(
1039 GNUNET_ERROR_TYPE_WARNING, 1038 GNUNET_ERROR_TYPE_WARNING,
1040 _ ( 1039 _(
1041 "EPHEMERAL_KEY from peer `%s' rejected as its validity range does not match our system time (%llu not in [%llu,%llu]).\n"), 1040 "EPHEMERAL_KEY from peer `%s' rejected as its validity range does not match our system time (%llu not in [%llu,%llu]).\n"),
1042 GNUNET_i2s (kx->peer), 1041 GNUNET_i2s(kx->peer),
1043 (unsigned long long) now.abs_value_us, 1042 (unsigned long long)now.abs_value_us,
1044 (unsigned long long) start_t.abs_value_us, 1043 (unsigned long long)start_t.abs_value_us,
1045 (unsigned long long) end_t.abs_value_us); 1044 (unsigned long long)end_t.abs_value_us);
1046 GNUNET_STATISTICS_update (GSC_stats, 1045 GNUNET_STATISTICS_update(GSC_stats,
1047 gettext_noop ( 1046 gettext_noop(
1048 "# EPHEMERAL_KEY messages rejected due to time"), 1047 "# EPHEMERAL_KEY messages rejected due to time"),
1049 1, 1048 1,
1050 GNUNET_NO); 1049 GNUNET_NO);
1051 return; 1050 return;
1052 } 1051 }
1053#if DEBUG_KX 1052#if DEBUG_KX
1054 { 1053 {
1055 struct GNUNET_HashCode eh; 1054 struct GNUNET_HashCode eh;
1056 1055
1057 GNUNET_CRYPTO_hash (&m->ephemeral_key, sizeof (m->ephemeral_key), &eh); 1056 GNUNET_CRYPTO_hash(&m->ephemeral_key, sizeof(m->ephemeral_key), &eh);
1058 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1057 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1059 "Received valid EPHEMERAL_KEY `%s' from `%s' in state %d.\n", 1058 "Received valid EPHEMERAL_KEY `%s' from `%s' in state %d.\n",
1060 GNUNET_h2s (&eh), 1059 GNUNET_h2s(&eh),
1061 GNUNET_i2s (kx->peer), 1060 GNUNET_i2s(kx->peer),
1062 kx->status); 1061 kx->status);
1063 } 1062 }
1064#endif 1063#endif
1065 GNUNET_STATISTICS_update (GSC_stats, 1064 GNUNET_STATISTICS_update(GSC_stats,
1066 gettext_noop ("# valid ephemeral keys received"), 1065 gettext_noop("# valid ephemeral keys received"),
1067 1, 1066 1,
1068 GNUNET_NO); 1067 GNUNET_NO);
1069 kx->other_ephemeral_key = m->ephemeral_key; 1068 kx->other_ephemeral_key = m->ephemeral_key;
1070 kx->foreign_key_expires = end_t; 1069 kx->foreign_key_expires = end_t;
1071 derive_session_keys (kx); 1070 derive_session_keys(kx);
1072 1071
1073 /* check if we still need to send the sender our key */ 1072 /* check if we still need to send the sender our key */
1074 sender_status = (enum GNUNET_CORE_KxState) ntohl (m->sender_status); 1073 sender_status = (enum GNUNET_CORE_KxState)ntohl(m->sender_status);
1075 switch (sender_status) 1074 switch (sender_status)
1076 { 1075 {
1077 case GNUNET_CORE_KX_STATE_DOWN: 1076 case GNUNET_CORE_KX_STATE_DOWN:
1078 GNUNET_break_op (0); 1077 GNUNET_break_op(0);
1079 break; 1078 break;
1080 case GNUNET_CORE_KX_STATE_KEY_SENT: 1079
1081 /* fine, need to send our key after updating our status, see below */ 1080 case GNUNET_CORE_KX_STATE_KEY_SENT:
1082 GSC_SESSIONS_reinit (kx->peer); 1081 /* fine, need to send our key after updating our status, see below */
1083 break; 1082 GSC_SESSIONS_reinit(kx->peer);
1084 case GNUNET_CORE_KX_STATE_KEY_RECEIVED: 1083 break;
1085 /* other peer already got our key, but typemap did go down */ 1084
1086 GSC_SESSIONS_reinit (kx->peer); 1085 case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
1087 break; 1086 /* other peer already got our key, but typemap did go down */
1088 case GNUNET_CORE_KX_STATE_UP: 1087 GSC_SESSIONS_reinit(kx->peer);
1089 /* other peer already got our key, typemap NOT down */ 1088 break;
1090 break; 1089
1091 case GNUNET_CORE_KX_STATE_REKEY_SENT: 1090 case GNUNET_CORE_KX_STATE_UP:
1092 /* other peer already got our key, typemap NOT down */ 1091 /* other peer already got our key, typemap NOT down */
1093 break; 1092 break;
1094 default: 1093
1095 GNUNET_break (0); 1094 case GNUNET_CORE_KX_STATE_REKEY_SENT:
1096 break; 1095 /* other peer already got our key, typemap NOT down */
1097 } 1096 break;
1097
1098 default:
1099 GNUNET_break(0);
1100 break;
1101 }
1098 /* check if we need to confirm everything is fine via PING + PONG */ 1102 /* check if we need to confirm everything is fine via PING + PONG */
1099 switch (kx->status) 1103 switch (kx->status)
1100 { 1104 {
1101 case GNUNET_CORE_KX_STATE_DOWN: 1105 case GNUNET_CORE_KX_STATE_DOWN:
1102 GNUNET_assert (NULL == kx->keep_alive_task); 1106 GNUNET_assert(NULL == kx->keep_alive_task);
1103 kx->status = GNUNET_CORE_KX_STATE_KEY_RECEIVED; 1107 kx->status = GNUNET_CORE_KX_STATE_KEY_RECEIVED;
1104 monitor_notify_all (kx); 1108 monitor_notify_all(kx);
1105 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status) 1109 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1106 send_key (kx); 1110 send_key(kx);
1107 else 1111 else
1108 send_ping (kx); 1112 send_ping(kx);
1109 break; 1113 break;
1110 case GNUNET_CORE_KX_STATE_KEY_SENT: 1114
1111 GNUNET_assert (NULL == kx->keep_alive_task); 1115 case GNUNET_CORE_KX_STATE_KEY_SENT:
1112 kx->status = GNUNET_CORE_KX_STATE_KEY_RECEIVED; 1116 GNUNET_assert(NULL == kx->keep_alive_task);
1113 monitor_notify_all (kx); 1117 kx->status = GNUNET_CORE_KX_STATE_KEY_RECEIVED;
1114 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status) 1118 monitor_notify_all(kx);
1115 send_key (kx); 1119 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1116 else 1120 send_key(kx);
1117 send_ping (kx); 1121 else
1118 break; 1122 send_ping(kx);
1119 case GNUNET_CORE_KX_STATE_KEY_RECEIVED: 1123 break;
1120 GNUNET_assert (NULL == kx->keep_alive_task); 1124
1121 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status) 1125 case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
1122 send_key (kx); 1126 GNUNET_assert(NULL == kx->keep_alive_task);
1123 else 1127 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1124 send_ping (kx); 1128 send_key(kx);
1125 break; 1129 else
1126 case GNUNET_CORE_KX_STATE_UP: 1130 send_ping(kx);
1127 kx->status = GNUNET_CORE_KX_STATE_REKEY_SENT; 1131 break;
1128 monitor_notify_all (kx); 1132
1129 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status) 1133 case GNUNET_CORE_KX_STATE_UP:
1130 send_key (kx); 1134 kx->status = GNUNET_CORE_KX_STATE_REKEY_SENT;
1131 else 1135 monitor_notify_all(kx);
1132 send_ping (kx); 1136 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1133 break; 1137 send_key(kx);
1134 case GNUNET_CORE_KX_STATE_REKEY_SENT: 1138 else
1135 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status) 1139 send_ping(kx);
1136 send_key (kx); 1140 break;
1137 else 1141
1138 send_ping (kx); 1142 case GNUNET_CORE_KX_STATE_REKEY_SENT:
1139 break; 1143 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1140 default: 1144 send_key(kx);
1141 GNUNET_break (0); 1145 else
1142 break; 1146 send_ping(kx);
1143 } 1147 break;
1148
1149 default:
1150 GNUNET_break(0);
1151 break;
1152 }
1144} 1153}
1145 1154
1146 1155
@@ -1152,7 +1161,7 @@ handle_ephemeral_key (void *cls, const struct EphemeralKeyMessage *m)
1152 * @param m the encrypted PING message itself 1161 * @param m the encrypted PING message itself
1153 */ 1162 */
1154static void 1163static void
1155handle_ping (void *cls, const struct PingMessage *m) 1164handle_ping(void *cls, const struct PingMessage *m)
1156{ 1165{
1157 struct GSC_KeyExchangeInfo *kx = cls; 1166 struct GSC_KeyExchangeInfo *kx = cls;
1158 struct PingMessage t; 1167 struct PingMessage t;
@@ -1161,70 +1170,70 @@ handle_ping (void *cls, const struct PingMessage *m)
1161 struct GNUNET_MQ_Envelope *env; 1170 struct GNUNET_MQ_Envelope *env;
1162 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 1171 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
1163 1172
1164 GNUNET_STATISTICS_update (GSC_stats, 1173 GNUNET_STATISTICS_update(GSC_stats,
1165 gettext_noop ("# PING messages received"), 1174 gettext_noop("# PING messages received"),
1166 1, 1175 1,
1167 GNUNET_NO); 1176 GNUNET_NO);
1168 if ((kx->status != GNUNET_CORE_KX_STATE_KEY_RECEIVED) && 1177 if ((kx->status != GNUNET_CORE_KX_STATE_KEY_RECEIVED) &&
1169 (kx->status != GNUNET_CORE_KX_STATE_UP) && 1178 (kx->status != GNUNET_CORE_KX_STATE_UP) &&
1170 (kx->status != GNUNET_CORE_KX_STATE_REKEY_SENT)) 1179 (kx->status != GNUNET_CORE_KX_STATE_REKEY_SENT))
1171 { 1180 {
1172 /* ignore */ 1181 /* ignore */
1173 GNUNET_STATISTICS_update (GSC_stats, 1182 GNUNET_STATISTICS_update(GSC_stats,
1174 gettext_noop ( 1183 gettext_noop(
1175 "# PING messages dropped (out of order)"), 1184 "# PING messages dropped (out of order)"),
1176 1, 1185 1,
1177 GNUNET_NO); 1186 GNUNET_NO);
1178 return; 1187 return;
1179 } 1188 }
1180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1189 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1181 "Core service receives PING request from `%s'.\n", 1190 "Core service receives PING request from `%s'.\n",
1182 GNUNET_i2s (kx->peer)); 1191 GNUNET_i2s(kx->peer));
1183 derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity); 1192 derive_iv(&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity);
1184 if (GNUNET_OK != do_decrypt (kx, 1193 if (GNUNET_OK != do_decrypt(kx,
1185 &iv, 1194 &iv,
1186 &m->target, 1195 &m->target,
1187 &t.target, 1196 &t.target,
1188 sizeof (struct PingMessage) - 1197 sizeof(struct PingMessage) -
1189 ((void *) &m->target - (void *) m))) 1198 ((void *)&m->target - (void *)m)))
1190 { 1199 {
1191 GNUNET_break_op (0); 1200 GNUNET_break_op(0);
1192 return; 1201 return;
1193 } 1202 }
1194 if (0 != 1203 if (0 !=
1195 memcmp (&t.target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 1204 memcmp(&t.target, &GSC_my_identity, sizeof(struct GNUNET_PeerIdentity)))
1196 { 1205 {
1197 if (GNUNET_CORE_KX_STATE_REKEY_SENT != kx->status) 1206 if (GNUNET_CORE_KX_STATE_REKEY_SENT != kx->status)
1198 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1207 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1199 "Decryption of PING from peer `%s' failed, PING for `%s'?\n", 1208 "Decryption of PING from peer `%s' failed, PING for `%s'?\n",
1200 GNUNET_i2s (kx->peer), 1209 GNUNET_i2s(kx->peer),
1201 GNUNET_i2s2 (&t.target)); 1210 GNUNET_i2s2(&t.target));
1202 else 1211 else
1203 GNUNET_log ( 1212 GNUNET_log(
1204 GNUNET_ERROR_TYPE_DEBUG, 1213 GNUNET_ERROR_TYPE_DEBUG,
1205 "Decryption of PING from peer `%s' failed after rekey (harmless)\n", 1214 "Decryption of PING from peer `%s' failed after rekey (harmless)\n",
1206 GNUNET_i2s (kx->peer)); 1215 GNUNET_i2s(kx->peer));
1207 GNUNET_break_op (0); 1216 GNUNET_break_op(0);
1208 return; 1217 return;
1209 } 1218 }
1210 /* construct PONG */ 1219 /* construct PONG */
1211 tx.reserved = 0; 1220 tx.reserved = 0;
1212 tx.challenge = t.challenge; 1221 tx.challenge = t.challenge;
1213 tx.target = t.target; 1222 tx.target = t.target;
1214 env = GNUNET_MQ_msg (tp, GNUNET_MESSAGE_TYPE_CORE_PONG); 1223 env = GNUNET_MQ_msg(tp, GNUNET_MESSAGE_TYPE_CORE_PONG);
1215 tp->iv_seed = calculate_seed (kx); 1224 tp->iv_seed = calculate_seed(kx);
1216 derive_pong_iv (&iv, &kx->encrypt_key, tp->iv_seed, t.challenge, kx->peer); 1225 derive_pong_iv(&iv, &kx->encrypt_key, tp->iv_seed, t.challenge, kx->peer);
1217 do_encrypt (kx, 1226 do_encrypt(kx,
1218 &iv, 1227 &iv,
1219 &tx.challenge, 1228 &tx.challenge,
1220 &tp->challenge, 1229 &tp->challenge,
1221 sizeof (struct PongMessage) - 1230 sizeof(struct PongMessage) -
1222 ((void *) &tp->challenge - (void *) tp)); 1231 ((void *)&tp->challenge - (void *)tp));
1223 GNUNET_STATISTICS_update (GSC_stats, 1232 GNUNET_STATISTICS_update(GSC_stats,
1224 gettext_noop ("# PONG messages created"), 1233 gettext_noop("# PONG messages created"),
1225 1, 1234 1,
1226 GNUNET_NO); 1235 GNUNET_NO);
1227 GNUNET_MQ_send (kx->mq, env); 1236 GNUNET_MQ_send(kx->mq, env);
1228} 1237}
1229 1238
1230 1239
@@ -1235,39 +1244,39 @@ handle_ping (void *cls, const struct PingMessage *m)
1235 * @param cls the `struct GSC_KeyExchangeInfo` 1244 * @param cls the `struct GSC_KeyExchangeInfo`
1236 */ 1245 */
1237static void 1246static void
1238send_keep_alive (void *cls) 1247send_keep_alive(void *cls)
1239{ 1248{
1240 struct GSC_KeyExchangeInfo *kx = cls; 1249 struct GSC_KeyExchangeInfo *kx = cls;
1241 struct GNUNET_TIME_Relative retry; 1250 struct GNUNET_TIME_Relative retry;
1242 struct GNUNET_TIME_Relative left; 1251 struct GNUNET_TIME_Relative left;
1243 1252
1244 kx->keep_alive_task = NULL; 1253 kx->keep_alive_task = NULL;
1245 left = GNUNET_TIME_absolute_get_remaining (kx->timeout); 1254 left = GNUNET_TIME_absolute_get_remaining(kx->timeout);
1246 if (0 == left.rel_value_us) 1255 if (0 == left.rel_value_us)
1247 { 1256 {
1248 GNUNET_STATISTICS_update (GSC_stats, 1257 GNUNET_STATISTICS_update(GSC_stats,
1249 gettext_noop ("# sessions terminated by timeout"), 1258 gettext_noop("# sessions terminated by timeout"),
1250 1, 1259 1,
1251 GNUNET_NO); 1260 GNUNET_NO);
1252 GSC_SESSIONS_end (kx->peer); 1261 GSC_SESSIONS_end(kx->peer);
1253 kx->status = GNUNET_CORE_KX_STATE_KEY_SENT; 1262 kx->status = GNUNET_CORE_KX_STATE_KEY_SENT;
1254 monitor_notify_all (kx); 1263 monitor_notify_all(kx);
1255 send_key (kx); 1264 send_key(kx);
1256 return; 1265 return;
1257 } 1266 }
1258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1267 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1259 "Sending KEEPALIVE to `%s'\n", 1268 "Sending KEEPALIVE to `%s'\n",
1260 GNUNET_i2s (kx->peer)); 1269 GNUNET_i2s(kx->peer));
1261 GNUNET_STATISTICS_update (GSC_stats, 1270 GNUNET_STATISTICS_update(GSC_stats,
1262 gettext_noop ("# keepalive messages sent"), 1271 gettext_noop("# keepalive messages sent"),
1263 1, 1272 1,
1264 GNUNET_NO); 1273 GNUNET_NO);
1265 setup_fresh_ping (kx); 1274 setup_fresh_ping(kx);
1266 send_ping (kx); 1275 send_ping(kx);
1267 retry = GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), 1276 retry = GNUNET_TIME_relative_max(GNUNET_TIME_relative_divide(left, 2),
1268 MIN_PING_FREQUENCY); 1277 MIN_PING_FREQUENCY);
1269 kx->keep_alive_task = 1278 kx->keep_alive_task =
1270 GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx); 1279 GNUNET_SCHEDULER_add_delayed(retry, &send_keep_alive, kx);
1271} 1280}
1272 1281
1273 1282
@@ -1279,24 +1288,24 @@ send_keep_alive (void *cls)
1279 * @param kx key exchange where we saw activity 1288 * @param kx key exchange where we saw activity
1280 */ 1289 */
1281static void 1290static void
1282update_timeout (struct GSC_KeyExchangeInfo *kx) 1291update_timeout(struct GSC_KeyExchangeInfo *kx)
1283{ 1292{
1284 struct GNUNET_TIME_Relative delta; 1293 struct GNUNET_TIME_Relative delta;
1285 1294
1286 kx->timeout = 1295 kx->timeout =
1287 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 1296 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1288 delta = 1297 delta =
1289 GNUNET_TIME_absolute_get_difference (kx->last_notify_timeout, kx->timeout); 1298 GNUNET_TIME_absolute_get_difference(kx->last_notify_timeout, kx->timeout);
1290 if (delta.rel_value_us > 5LL * 1000LL * 1000LL) 1299 if (delta.rel_value_us > 5LL * 1000LL * 1000LL)
1291 { 1300 {
1292 /* we only notify monitors about timeout changes if those 1301 /* we only notify monitors about timeout changes if those
1293 are bigger than the threshold (5s) */ 1302 are bigger than the threshold (5s) */
1294 monitor_notify_all (kx); 1303 monitor_notify_all(kx);
1295 } 1304 }
1296 if (NULL != kx->keep_alive_task) 1305 if (NULL != kx->keep_alive_task)
1297 GNUNET_SCHEDULER_cancel (kx->keep_alive_task); 1306 GNUNET_SCHEDULER_cancel(kx->keep_alive_task);
1298 kx->keep_alive_task = GNUNET_SCHEDULER_add_delayed ( 1307 kx->keep_alive_task = GNUNET_SCHEDULER_add_delayed(
1299 GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2), 1308 GNUNET_TIME_relative_divide(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 2),
1300 &send_keep_alive, 1309 &send_keep_alive,
1301 kx); 1310 kx);
1302} 1311}
@@ -1309,131 +1318,141 @@ update_timeout (struct GSC_KeyExchangeInfo *kx)
1309 * @param m the encrypted PONG message itself 1318 * @param m the encrypted PONG message itself
1310 */ 1319 */
1311static void 1320static void
1312handle_pong (void *cls, const struct PongMessage *m) 1321handle_pong(void *cls, const struct PongMessage *m)
1313{ 1322{
1314 struct GSC_KeyExchangeInfo *kx = cls; 1323 struct GSC_KeyExchangeInfo *kx = cls;
1315 struct PongMessage t; 1324 struct PongMessage t;
1316 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 1325 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
1317 1326
1318 GNUNET_STATISTICS_update (GSC_stats, 1327 GNUNET_STATISTICS_update(GSC_stats,
1319 gettext_noop ("# PONG messages received"), 1328 gettext_noop("# PONG messages received"),
1320 1, 1329 1,
1321 GNUNET_NO); 1330 GNUNET_NO);
1322 switch (kx->status) 1331 switch (kx->status)
1323 { 1332 {
1324 case GNUNET_CORE_KX_STATE_DOWN: 1333 case GNUNET_CORE_KX_STATE_DOWN:
1325 GNUNET_STATISTICS_update (GSC_stats, 1334 GNUNET_STATISTICS_update(GSC_stats,
1326 gettext_noop ( 1335 gettext_noop(
1327 "# PONG messages dropped (connection down)"), 1336 "# PONG messages dropped (connection down)"),
1328 1, 1337 1,
1329 GNUNET_NO); 1338 GNUNET_NO);
1330 return; 1339 return;
1331 case GNUNET_CORE_KX_STATE_KEY_SENT: 1340
1332 GNUNET_STATISTICS_update (GSC_stats, 1341 case GNUNET_CORE_KX_STATE_KEY_SENT:
1333 gettext_noop ( 1342 GNUNET_STATISTICS_update(GSC_stats,
1334 "# PONG messages dropped (out of order)"), 1343 gettext_noop(
1335 1, 1344 "# PONG messages dropped (out of order)"),
1336 GNUNET_NO); 1345 1,
1337 return; 1346 GNUNET_NO);
1338 case GNUNET_CORE_KX_STATE_KEY_RECEIVED: 1347 return;
1339 break; 1348
1340 case GNUNET_CORE_KX_STATE_UP: 1349 case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
1341 break; 1350 break;
1342 case GNUNET_CORE_KX_STATE_REKEY_SENT: 1351
1343 break; 1352 case GNUNET_CORE_KX_STATE_UP:
1344 default: 1353 break;
1345 GNUNET_break (0); 1354
1346 return; 1355 case GNUNET_CORE_KX_STATE_REKEY_SENT:
1347 } 1356 break;
1348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1357
1349 "Core service receives PONG response from `%s'.\n", 1358 default:
1350 GNUNET_i2s (kx->peer)); 1359 GNUNET_break(0);
1360 return;
1361 }
1362 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1363 "Core service receives PONG response from `%s'.\n",
1364 GNUNET_i2s(kx->peer));
1351 /* mark as garbage, just to be sure */ 1365 /* mark as garbage, just to be sure */
1352 memset (&t, 255, sizeof (t)); 1366 memset(&t, 255, sizeof(t));
1353 derive_pong_iv (&iv, 1367 derive_pong_iv(&iv,
1354 &kx->decrypt_key, 1368 &kx->decrypt_key,
1355 m->iv_seed, 1369 m->iv_seed,
1356 kx->ping_challenge, 1370 kx->ping_challenge,
1357 &GSC_my_identity); 1371 &GSC_my_identity);
1358 if (GNUNET_OK != do_decrypt (kx, 1372 if (GNUNET_OK != do_decrypt(kx,
1359 &iv, 1373 &iv,
1360 &m->challenge, 1374 &m->challenge,
1361 &t.challenge, 1375 &t.challenge,
1362 sizeof (struct PongMessage) - 1376 sizeof(struct PongMessage) -
1363 ((void *) &m->challenge - (void *) m))) 1377 ((void *)&m->challenge - (void *)m)))
1364 { 1378 {
1365 GNUNET_break_op (0); 1379 GNUNET_break_op(0);
1366 return; 1380 return;
1367 } 1381 }
1368 GNUNET_STATISTICS_update (GSC_stats, 1382 GNUNET_STATISTICS_update(GSC_stats,
1369 gettext_noop ("# PONG messages decrypted"), 1383 gettext_noop("# PONG messages decrypted"),
1370 1, 1384 1,
1371 GNUNET_NO); 1385 GNUNET_NO);
1372 if ((0 != 1386 if ((0 !=
1373 memcmp (&t.target, kx->peer, sizeof (struct GNUNET_PeerIdentity))) || 1387 memcmp(&t.target, kx->peer, sizeof(struct GNUNET_PeerIdentity))) ||
1374 (kx->ping_challenge != t.challenge)) 1388 (kx->ping_challenge != t.challenge))
1375 { 1389 {
1376 /* PONG malformed */ 1390 /* PONG malformed */
1377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1391 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1378 "Received malformed PONG wanted sender `%s' with challenge %u\n", 1392 "Received malformed PONG wanted sender `%s' with challenge %u\n",
1379 GNUNET_i2s (kx->peer), 1393 GNUNET_i2s(kx->peer),
1380 (unsigned int) kx->ping_challenge); 1394 (unsigned int)kx->ping_challenge);
1381 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1395 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1382 "Received malformed PONG received from `%s' with challenge %u\n", 1396 "Received malformed PONG received from `%s' with challenge %u\n",
1383 GNUNET_i2s (&t.target), 1397 GNUNET_i2s(&t.target),
1384 (unsigned int) t.challenge); 1398 (unsigned int)t.challenge);
1385 return; 1399 return;
1386 } 1400 }
1387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1401 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1388 "Received valid PONG from `%s'\n", 1402 "Received valid PONG from `%s'\n",
1389 GNUNET_i2s (kx->peer)); 1403 GNUNET_i2s(kx->peer));
1390 /* no need to resend key any longer */ 1404 /* no need to resend key any longer */
1391 if (NULL != kx->retry_set_key_task) 1405 if (NULL != kx->retry_set_key_task)
1392 { 1406 {
1393 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); 1407 GNUNET_SCHEDULER_cancel(kx->retry_set_key_task);
1394 kx->retry_set_key_task = NULL; 1408 kx->retry_set_key_task = NULL;
1395 } 1409 }
1396 switch (kx->status) 1410 switch (kx->status)
1397 { 1411 {
1398 case GNUNET_CORE_KX_STATE_DOWN: 1412 case GNUNET_CORE_KX_STATE_DOWN:
1399 GNUNET_assert (0); /* should be impossible */ 1413 GNUNET_assert(0); /* should be impossible */
1400 return; 1414 return;
1401 case GNUNET_CORE_KX_STATE_KEY_SENT: 1415
1402 GNUNET_assert (0); /* should be impossible */ 1416 case GNUNET_CORE_KX_STATE_KEY_SENT:
1403 return; 1417 GNUNET_assert(0); /* should be impossible */
1404 case GNUNET_CORE_KX_STATE_KEY_RECEIVED: 1418 return;
1405 GNUNET_STATISTICS_update (GSC_stats, 1419
1406 gettext_noop ( 1420 case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
1407 "# session keys confirmed via PONG"), 1421 GNUNET_STATISTICS_update(GSC_stats,
1408 1, 1422 gettext_noop(
1409 GNUNET_NO); 1423 "# session keys confirmed via PONG"),
1410 kx->status = GNUNET_CORE_KX_STATE_UP; 1424 1,
1411 monitor_notify_all (kx); 1425 GNUNET_NO);
1412 GSC_SESSIONS_create (kx->peer, kx); 1426 kx->status = GNUNET_CORE_KX_STATE_UP;
1413 GNUNET_assert (NULL == kx->keep_alive_task); 1427 monitor_notify_all(kx);
1414 update_timeout (kx); 1428 GSC_SESSIONS_create(kx->peer, kx);
1415 break; 1429 GNUNET_assert(NULL == kx->keep_alive_task);
1416 case GNUNET_CORE_KX_STATE_UP: 1430 update_timeout(kx);
1417 GNUNET_STATISTICS_update (GSC_stats, 1431 break;
1418 gettext_noop ("# timeouts prevented via PONG"), 1432
1419 1, 1433 case GNUNET_CORE_KX_STATE_UP:
1420 GNUNET_NO); 1434 GNUNET_STATISTICS_update(GSC_stats,
1421 update_timeout (kx); 1435 gettext_noop("# timeouts prevented via PONG"),
1422 break; 1436 1,
1423 case GNUNET_CORE_KX_STATE_REKEY_SENT: 1437 GNUNET_NO);
1424 GNUNET_STATISTICS_update (GSC_stats, 1438 update_timeout(kx);
1425 gettext_noop ( 1439 break;
1426 "# rekey operations confirmed via PONG"), 1440
1427 1, 1441 case GNUNET_CORE_KX_STATE_REKEY_SENT:
1428 GNUNET_NO); 1442 GNUNET_STATISTICS_update(GSC_stats,
1429 kx->status = GNUNET_CORE_KX_STATE_UP; 1443 gettext_noop(
1430 monitor_notify_all (kx); 1444 "# rekey operations confirmed via PONG"),
1431 update_timeout (kx); 1445 1,
1432 break; 1446 GNUNET_NO);
1433 default: 1447 kx->status = GNUNET_CORE_KX_STATE_UP;
1434 GNUNET_break (0); 1448 monitor_notify_all(kx);
1435 break; 1449 update_timeout(kx);
1436 } 1450 break;
1451
1452 default:
1453 GNUNET_break(0);
1454 break;
1455 }
1437} 1456}
1438 1457
1439 1458
@@ -1443,40 +1462,40 @@ handle_pong (void *cls, const struct PongMessage *m)
1443 * @param kx key exchange context 1462 * @param kx key exchange context
1444 */ 1463 */
1445static void 1464static void
1446send_key (struct GSC_KeyExchangeInfo *kx) 1465send_key(struct GSC_KeyExchangeInfo *kx)
1447{ 1466{
1448 struct GNUNET_MQ_Envelope *env; 1467 struct GNUNET_MQ_Envelope *env;
1449 1468
1450 GNUNET_assert (GNUNET_CORE_KX_STATE_DOWN != kx->status); 1469 GNUNET_assert(GNUNET_CORE_KX_STATE_DOWN != kx->status);
1451 if (NULL != kx->retry_set_key_task) 1470 if (NULL != kx->retry_set_key_task)
1452 { 1471 {
1453 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); 1472 GNUNET_SCHEDULER_cancel(kx->retry_set_key_task);
1454 kx->retry_set_key_task = NULL; 1473 kx->retry_set_key_task = NULL;
1455 } 1474 }
1456 /* always update sender status in SET KEY message */ 1475 /* always update sender status in SET KEY message */
1457#if DEBUG_KX 1476#if DEBUG_KX
1458 { 1477 {
1459 struct GNUNET_HashCode hc; 1478 struct GNUNET_HashCode hc;
1460 1479
1461 GNUNET_CRYPTO_hash (&current_ekm.ephemeral_key, 1480 GNUNET_CRYPTO_hash(&current_ekm.ephemeral_key,
1462 sizeof (current_ekm.ephemeral_key), 1481 sizeof(current_ekm.ephemeral_key),
1463 &hc); 1482 &hc);
1464 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1483 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1465 "Sending EPHEMERAL_KEY %s to `%s' (my status: %d)\n", 1484 "Sending EPHEMERAL_KEY %s to `%s' (my status: %d)\n",
1466 GNUNET_h2s (&hc), 1485 GNUNET_h2s(&hc),
1467 GNUNET_i2s (kx->peer), 1486 GNUNET_i2s(kx->peer),
1468 kx->status); 1487 kx->status);
1469 } 1488 }
1470#endif 1489#endif
1471 current_ekm.sender_status = htonl ((int32_t) (kx->status)); 1490 current_ekm.sender_status = htonl((int32_t)(kx->status));
1472 env = GNUNET_MQ_msg_copy (&current_ekm.header); 1491 env = GNUNET_MQ_msg_copy(&current_ekm.header);
1473 GNUNET_MQ_send (kx->mq, env); 1492 GNUNET_MQ_send(kx->mq, env);
1474 if (GNUNET_CORE_KX_STATE_KEY_SENT != kx->status) 1493 if (GNUNET_CORE_KX_STATE_KEY_SENT != kx->status)
1475 send_ping (kx); 1494 send_ping(kx);
1476 kx->retry_set_key_task = 1495 kx->retry_set_key_task =
1477 GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency, 1496 GNUNET_SCHEDULER_add_delayed(kx->set_key_retry_frequency,
1478 &set_key_retry_task, 1497 &set_key_retry_task,
1479 kx); 1498 kx);
1480} 1499}
1481 1500
1482 1501
@@ -1488,11 +1507,11 @@ send_key (struct GSC_KeyExchangeInfo *kx)
1488 * @param payload_size number of bytes in @a payload 1507 * @param payload_size number of bytes in @a payload
1489 */ 1508 */
1490void 1509void
1491GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, 1510GSC_KX_encrypt_and_transmit(struct GSC_KeyExchangeInfo *kx,
1492 const void *payload, 1511 const void *payload,
1493 size_t payload_size) 1512 size_t payload_size)
1494{ 1513{
1495 size_t used = payload_size + sizeof (struct EncryptedMessage); 1514 size_t used = payload_size + sizeof(struct EncryptedMessage);
1496 char pbuf[used]; /* plaintext */ 1515 char pbuf[used]; /* plaintext */
1497 struct EncryptedMessage *em; /* encrypted message */ 1516 struct EncryptedMessage *em; /* encrypted message */
1498 struct EncryptedMessage *ph; /* plaintext header */ 1517 struct EncryptedMessage *ph; /* plaintext header */
@@ -1500,55 +1519,55 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
1500 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 1519 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
1501 struct GNUNET_CRYPTO_AuthKey auth_key; 1520 struct GNUNET_CRYPTO_AuthKey auth_key;
1502 1521
1503 ph = (struct EncryptedMessage *) pbuf; 1522 ph = (struct EncryptedMessage *)pbuf;
1504 ph->sequence_number = htonl (++kx->last_sequence_number_sent); 1523 ph->sequence_number = htonl(++kx->last_sequence_number_sent);
1505 ph->iv_seed = calculate_seed (kx); 1524 ph->iv_seed = calculate_seed(kx);
1506 ph->reserved = 0; 1525 ph->reserved = 0;
1507 ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 1526 ph->timestamp = GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get());
1508 GNUNET_memcpy (&ph[1], payload, payload_size); 1527 GNUNET_memcpy(&ph[1], payload, payload_size);
1509 env = GNUNET_MQ_msg_extra (em, 1528 env = GNUNET_MQ_msg_extra(em,
1510 payload_size, 1529 payload_size,
1511 GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE); 1530 GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE);
1512 em->iv_seed = ph->iv_seed; 1531 em->iv_seed = ph->iv_seed;
1513 derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, kx->peer); 1532 derive_iv(&iv, &kx->encrypt_key, ph->iv_seed, kx->peer);
1514 GNUNET_assert (GNUNET_OK == do_encrypt (kx, 1533 GNUNET_assert(GNUNET_OK == do_encrypt(kx,
1515 &iv, 1534 &iv,
1516 &ph->sequence_number, 1535 &ph->sequence_number,
1517 &em->sequence_number, 1536 &em->sequence_number,
1518 used - ENCRYPTED_HEADER_SIZE)); 1537 used - ENCRYPTED_HEADER_SIZE));
1519#if DEBUG_KX 1538#if DEBUG_KX
1520 { 1539 {
1521 struct GNUNET_HashCode hc; 1540 struct GNUNET_HashCode hc;
1522 1541
1523 GNUNET_CRYPTO_hash (&ph->sequence_number, 1542 GNUNET_CRYPTO_hash(&ph->sequence_number,
1524 used - ENCRYPTED_HEADER_SIZE, 1543 used - ENCRYPTED_HEADER_SIZE,
1525 &hc); 1544 &hc);
1526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1545 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1527 "Encrypted payload `%s' of %u bytes for %s\n", 1546 "Encrypted payload `%s' of %u bytes for %s\n",
1528 GNUNET_h2s (&hc), 1547 GNUNET_h2s(&hc),
1529 (unsigned int) (used - ENCRYPTED_HEADER_SIZE), 1548 (unsigned int)(used - ENCRYPTED_HEADER_SIZE),
1530 GNUNET_i2s (kx->peer)); 1549 GNUNET_i2s(kx->peer));
1531 } 1550 }
1532#endif 1551#endif
1533 derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed); 1552 derive_auth_key(&auth_key, &kx->encrypt_key, ph->iv_seed);
1534 GNUNET_CRYPTO_hmac (&auth_key, 1553 GNUNET_CRYPTO_hmac(&auth_key,
1535 &em->sequence_number, 1554 &em->sequence_number,
1536 used - ENCRYPTED_HEADER_SIZE, 1555 used - ENCRYPTED_HEADER_SIZE,
1537 &em->hmac); 1556 &em->hmac);
1538#if DEBUG_KX 1557#if DEBUG_KX
1539 { 1558 {
1540 struct GNUNET_HashCode hc; 1559 struct GNUNET_HashCode hc;
1541 1560
1542 GNUNET_CRYPTO_hash (&auth_key, sizeof (auth_key), &hc); 1561 GNUNET_CRYPTO_hash(&auth_key, sizeof(auth_key), &hc);
1543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1562 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1544 "For peer %s, used AC %s to create hmac %s\n", 1563 "For peer %s, used AC %s to create hmac %s\n",
1545 GNUNET_i2s (kx->peer), 1564 GNUNET_i2s(kx->peer),
1546 GNUNET_h2s (&hc), 1565 GNUNET_h2s(&hc),
1547 GNUNET_h2s2 (&em->hmac)); 1566 GNUNET_h2s2(&em->hmac));
1548 } 1567 }
1549#endif 1568#endif
1550 kx->has_excess_bandwidth = GNUNET_NO; 1569 kx->has_excess_bandwidth = GNUNET_NO;
1551 GNUNET_MQ_send (kx->mq, env); 1570 GNUNET_MQ_send(kx->mq, env);
1552} 1571}
1553 1572
1554 1573
@@ -1561,15 +1580,15 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
1561 * @return #GNUNET_OK if @a msg is well-formed (size-wise) 1580 * @return #GNUNET_OK if @a msg is well-formed (size-wise)
1562 */ 1581 */
1563static int 1582static int
1564check_encrypted (void *cls, const struct EncryptedMessage *m) 1583check_encrypted(void *cls, const struct EncryptedMessage *m)
1565{ 1584{
1566 uint16_t size = ntohs (m->header.size) - sizeof (*m); 1585 uint16_t size = ntohs(m->header.size) - sizeof(*m);
1567 1586
1568 if (size < sizeof (struct GNUNET_MessageHeader)) 1587 if (size < sizeof(struct GNUNET_MessageHeader))
1569 { 1588 {
1570 GNUNET_break_op (0); 1589 GNUNET_break_op(0);
1571 return GNUNET_SYSERR; 1590 return GNUNET_SYSERR;
1572 } 1591 }
1573 return GNUNET_OK; 1592 return GNUNET_OK;
1574} 1593}
1575 1594
@@ -1582,7 +1601,7 @@ check_encrypted (void *cls, const struct EncryptedMessage *m)
1582 * @param m encrypted message 1601 * @param m encrypted message
1583 */ 1602 */
1584static void 1603static void
1585handle_encrypted (void *cls, const struct EncryptedMessage *m) 1604handle_encrypted(void *cls, const struct EncryptedMessage *m)
1586{ 1605{
1587 struct GSC_KeyExchangeInfo *kx = cls; 1606 struct GSC_KeyExchangeInfo *kx = cls;
1588 struct EncryptedMessage *pt; /* plaintext */ 1607 struct EncryptedMessage *pt; /* plaintext */
@@ -1591,183 +1610,183 @@ handle_encrypted (void *cls, const struct EncryptedMessage *m)
1591 struct GNUNET_TIME_Absolute t; 1610 struct GNUNET_TIME_Absolute t;
1592 struct GNUNET_CRYPTO_SymmetricInitializationVector iv; 1611 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
1593 struct GNUNET_CRYPTO_AuthKey auth_key; 1612 struct GNUNET_CRYPTO_AuthKey auth_key;
1594 uint16_t size = ntohs (m->header.size); 1613 uint16_t size = ntohs(m->header.size);
1595 char buf[size] GNUNET_ALIGN; 1614 char buf[size] GNUNET_ALIGN;
1596 1615
1597 if (GNUNET_CORE_KX_STATE_UP != kx->status) 1616 if (GNUNET_CORE_KX_STATE_UP != kx->status)
1598 { 1617 {
1599 GNUNET_STATISTICS_update (GSC_stats, 1618 GNUNET_STATISTICS_update(GSC_stats,
1600 gettext_noop ( 1619 gettext_noop(
1601 "# DATA message dropped (out of order)"), 1620 "# DATA message dropped (out of order)"),
1602 1, 1621 1,
1603 GNUNET_NO); 1622 GNUNET_NO);
1604 return; 1623 return;
1605 } 1624 }
1606 if (0 == 1625 if (0 ==
1607 GNUNET_TIME_absolute_get_remaining (kx->foreign_key_expires).rel_value_us) 1626 GNUNET_TIME_absolute_get_remaining(kx->foreign_key_expires).rel_value_us)
1608 {
1609 GNUNET_log (
1610 GNUNET_ERROR_TYPE_WARNING,
1611 _ (
1612 "Session to peer `%s' went down due to key expiration (should not happen)\n"),
1613 GNUNET_i2s (kx->peer));
1614 GNUNET_STATISTICS_update (GSC_stats,
1615 gettext_noop (
1616 "# sessions terminated by key expiration"),
1617 1,
1618 GNUNET_NO);
1619 GSC_SESSIONS_end (kx->peer);
1620 if (NULL != kx->keep_alive_task)
1621 { 1627 {
1622 GNUNET_SCHEDULER_cancel (kx->keep_alive_task); 1628 GNUNET_log(
1623 kx->keep_alive_task = NULL; 1629 GNUNET_ERROR_TYPE_WARNING,
1630 _(
1631 "Session to peer `%s' went down due to key expiration (should not happen)\n"),
1632 GNUNET_i2s(kx->peer));
1633 GNUNET_STATISTICS_update(GSC_stats,
1634 gettext_noop(
1635 "# sessions terminated by key expiration"),
1636 1,
1637 GNUNET_NO);
1638 GSC_SESSIONS_end(kx->peer);
1639 if (NULL != kx->keep_alive_task)
1640 {
1641 GNUNET_SCHEDULER_cancel(kx->keep_alive_task);
1642 kx->keep_alive_task = NULL;
1643 }
1644 kx->status = GNUNET_CORE_KX_STATE_KEY_SENT;
1645 monitor_notify_all(kx);
1646 send_key(kx);
1647 return;
1624 } 1648 }
1625 kx->status = GNUNET_CORE_KX_STATE_KEY_SENT;
1626 monitor_notify_all (kx);
1627 send_key (kx);
1628 return;
1629 }
1630 1649
1631 /* validate hash */ 1650 /* validate hash */
1632#if DEBUG_KX 1651#if DEBUG_KX
1633 { 1652 {
1634 struct GNUNET_HashCode hc; 1653 struct GNUNET_HashCode hc;
1635 1654
1636 GNUNET_CRYPTO_hash (&m->sequence_number, size - ENCRYPTED_HEADER_SIZE, &hc); 1655 GNUNET_CRYPTO_hash(&m->sequence_number, size - ENCRYPTED_HEADER_SIZE, &hc);
1637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1656 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1638 "Received encrypted payload `%s' of %u bytes from %s\n", 1657 "Received encrypted payload `%s' of %u bytes from %s\n",
1639 GNUNET_h2s (&hc), 1658 GNUNET_h2s(&hc),
1640 (unsigned int) (size - ENCRYPTED_HEADER_SIZE), 1659 (unsigned int)(size - ENCRYPTED_HEADER_SIZE),
1641 GNUNET_i2s (kx->peer)); 1660 GNUNET_i2s(kx->peer));
1642 } 1661 }
1643#endif 1662#endif
1644 derive_auth_key (&auth_key, &kx->decrypt_key, m->iv_seed); 1663 derive_auth_key(&auth_key, &kx->decrypt_key, m->iv_seed);
1645 GNUNET_CRYPTO_hmac (&auth_key, 1664 GNUNET_CRYPTO_hmac(&auth_key,
1646 &m->sequence_number, 1665 &m->sequence_number,
1647 size - ENCRYPTED_HEADER_SIZE, 1666 size - ENCRYPTED_HEADER_SIZE,
1648 &ph); 1667 &ph);
1649#if DEBUG_KX 1668#if DEBUG_KX
1650 { 1669 {
1651 struct GNUNET_HashCode hc; 1670 struct GNUNET_HashCode hc;
1652 1671
1653 GNUNET_CRYPTO_hash (&auth_key, sizeof (auth_key), &hc); 1672 GNUNET_CRYPTO_hash(&auth_key, sizeof(auth_key), &hc);
1654 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1673 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1655 "For peer %s, used AC %s to verify hmac %s\n", 1674 "For peer %s, used AC %s to verify hmac %s\n",
1656 GNUNET_i2s (kx->peer), 1675 GNUNET_i2s(kx->peer),
1657 GNUNET_h2s (&hc), 1676 GNUNET_h2s(&hc),
1658 GNUNET_h2s2 (&m->hmac)); 1677 GNUNET_h2s2(&m->hmac));
1659 } 1678 }
1660#endif 1679#endif
1661 if (0 != memcmp (&ph, &m->hmac, sizeof (struct GNUNET_HashCode))) 1680 if (0 != memcmp(&ph, &m->hmac, sizeof(struct GNUNET_HashCode)))
1662 { 1681 {
1663 /* checksum failed */ 1682 /* checksum failed */
1664 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1683 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
1665 "Failed checksum validation for a message from `%s'\n", 1684 "Failed checksum validation for a message from `%s'\n",
1666 GNUNET_i2s (kx->peer)); 1685 GNUNET_i2s(kx->peer));
1667 return; 1686 return;
1668 } 1687 }
1669 derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity); 1688 derive_iv(&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity);
1670 /* decrypt */ 1689 /* decrypt */
1671 if (GNUNET_OK != do_decrypt (kx, 1690 if (GNUNET_OK != do_decrypt(kx,
1672 &iv, 1691 &iv,
1673 &m->sequence_number, 1692 &m->sequence_number,
1674 &buf[ENCRYPTED_HEADER_SIZE], 1693 &buf[ENCRYPTED_HEADER_SIZE],
1675 size - ENCRYPTED_HEADER_SIZE)) 1694 size - ENCRYPTED_HEADER_SIZE))
1676 { 1695 {
1677 GNUNET_break_op (0); 1696 GNUNET_break_op(0);
1678 return; 1697 return;
1679 } 1698 }
1680 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1699 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1681 "Decrypted %u bytes from %s\n", 1700 "Decrypted %u bytes from %s\n",
1682 (unsigned int) (size - ENCRYPTED_HEADER_SIZE), 1701 (unsigned int)(size - ENCRYPTED_HEADER_SIZE),
1683 GNUNET_i2s (kx->peer)); 1702 GNUNET_i2s(kx->peer));
1684 pt = (struct EncryptedMessage *) buf; 1703 pt = (struct EncryptedMessage *)buf;
1685 1704
1686 /* validate sequence number */ 1705 /* validate sequence number */
1687 snum = ntohl (pt->sequence_number); 1706 snum = ntohl(pt->sequence_number);
1688 if (kx->last_sequence_number_received == snum) 1707 if (kx->last_sequence_number_received == snum)
1689 { 1708 {
1690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1709 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1691 "Received duplicate message, ignoring.\n"); 1710 "Received duplicate message, ignoring.\n");
1692 /* duplicate, ignore */ 1711 /* duplicate, ignore */
1693 GNUNET_STATISTICS_update (GSC_stats, 1712 GNUNET_STATISTICS_update(GSC_stats,
1694 gettext_noop ("# bytes dropped (duplicates)"), 1713 gettext_noop("# bytes dropped (duplicates)"),
1695 size, 1714 size,
1696 GNUNET_NO); 1715 GNUNET_NO);
1697 return; 1716 return;
1698 } 1717 }
1699 if ((kx->last_sequence_number_received > snum) && 1718 if ((kx->last_sequence_number_received > snum) &&
1700 (kx->last_sequence_number_received - snum > 32)) 1719 (kx->last_sequence_number_received - snum > 32))
1701 {
1702 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1703 "Received ancient out of sequence message, ignoring.\n");
1704 /* ancient out of sequence, ignore */
1705 GNUNET_STATISTICS_update (GSC_stats,
1706 gettext_noop (
1707 "# bytes dropped (out of sequence)"),
1708 size,
1709 GNUNET_NO);
1710 return;
1711 }
1712 if (kx->last_sequence_number_received > snum)
1713 {
1714 uint32_t rotbit = 1U << (kx->last_sequence_number_received - snum - 1);
1715
1716 if ((kx->last_packets_bitmap & rotbit) != 0)
1717 { 1720 {
1718 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1721 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1719 "Received duplicate message, ignoring.\n"); 1722 "Received ancient out of sequence message, ignoring.\n");
1720 GNUNET_STATISTICS_update (GSC_stats, 1723 /* ancient out of sequence, ignore */
1721 gettext_noop ("# bytes dropped (duplicates)"), 1724 GNUNET_STATISTICS_update(GSC_stats,
1722 size, 1725 gettext_noop(
1723 GNUNET_NO); 1726 "# bytes dropped (out of sequence)"),
1724 /* duplicate, ignore */ 1727 size,
1728 GNUNET_NO);
1725 return; 1729 return;
1726 } 1730 }
1727 kx->last_packets_bitmap |= rotbit; 1731 if (kx->last_sequence_number_received > snum)
1728 } 1732 {
1733 uint32_t rotbit = 1U << (kx->last_sequence_number_received - snum - 1);
1734
1735 if ((kx->last_packets_bitmap & rotbit) != 0)
1736 {
1737 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1738 "Received duplicate message, ignoring.\n");
1739 GNUNET_STATISTICS_update(GSC_stats,
1740 gettext_noop("# bytes dropped (duplicates)"),
1741 size,
1742 GNUNET_NO);
1743 /* duplicate, ignore */
1744 return;
1745 }
1746 kx->last_packets_bitmap |= rotbit;
1747 }
1729 if (kx->last_sequence_number_received < snum) 1748 if (kx->last_sequence_number_received < snum)
1730 { 1749 {
1731 unsigned int shift = (snum - kx->last_sequence_number_received); 1750 unsigned int shift = (snum - kx->last_sequence_number_received);
1732 1751
1733 if (shift >= 8 * sizeof (kx->last_packets_bitmap)) 1752 if (shift >= 8 * sizeof(kx->last_packets_bitmap))
1734 kx->last_packets_bitmap = 0; 1753 kx->last_packets_bitmap = 0;
1735 else 1754 else
1736 kx->last_packets_bitmap <<= shift; 1755 kx->last_packets_bitmap <<= shift;
1737 kx->last_sequence_number_received = snum; 1756 kx->last_sequence_number_received = snum;
1738 } 1757 }
1739 1758
1740 /* check timestamp */ 1759 /* check timestamp */
1741 t = GNUNET_TIME_absolute_ntoh (pt->timestamp); 1760 t = GNUNET_TIME_absolute_ntoh(pt->timestamp);
1742 if (GNUNET_TIME_absolute_get_duration (t).rel_value_us > 1761 if (GNUNET_TIME_absolute_get_duration(t).rel_value_us >
1743 MAX_MESSAGE_AGE.rel_value_us) 1762 MAX_MESSAGE_AGE.rel_value_us)
1744 { 1763 {
1745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1764 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1746 "Message received far too old (%s). Content ignored.\n", 1765 "Message received far too old (%s). Content ignored.\n",
1747 GNUNET_STRINGS_relative_time_to_string ( 1766 GNUNET_STRINGS_relative_time_to_string(
1748 GNUNET_TIME_absolute_get_duration (t), 1767 GNUNET_TIME_absolute_get_duration(t),
1749 GNUNET_YES)); 1768 GNUNET_YES));
1750 GNUNET_STATISTICS_update (GSC_stats, 1769 GNUNET_STATISTICS_update(GSC_stats,
1751 gettext_noop ( 1770 gettext_noop(
1752 "# bytes dropped (ancient message)"), 1771 "# bytes dropped (ancient message)"),
1753 size, 1772 size,
1754 GNUNET_NO); 1773 GNUNET_NO);
1755 return; 1774 return;
1756 } 1775 }
1757 1776
1758 /* process decrypted message(s) */ 1777 /* process decrypted message(s) */
1759 update_timeout (kx); 1778 update_timeout(kx);
1760 GNUNET_STATISTICS_update (GSC_stats, 1779 GNUNET_STATISTICS_update(GSC_stats,
1761 gettext_noop ("# bytes of payload decrypted"), 1780 gettext_noop("# bytes of payload decrypted"),
1762 size - sizeof (struct EncryptedMessage), 1781 size - sizeof(struct EncryptedMessage),
1763 GNUNET_NO); 1782 GNUNET_NO);
1764 if (GNUNET_OK != 1783 if (GNUNET_OK !=
1765 GNUNET_MST_from_buffer (kx->mst, 1784 GNUNET_MST_from_buffer(kx->mst,
1766 &buf[sizeof (struct EncryptedMessage)], 1785 &buf[sizeof(struct EncryptedMessage)],
1767 size - sizeof (struct EncryptedMessage), 1786 size - sizeof(struct EncryptedMessage),
1768 GNUNET_YES, 1787 GNUNET_YES,
1769 GNUNET_NO)) 1788 GNUNET_NO))
1770 GNUNET_break_op (0); 1789 GNUNET_break_op(0);
1771} 1790}
1772 1791
1773 1792
@@ -1779,17 +1798,17 @@ handle_encrypted (void *cls, const struct EncryptedMessage *m)
1779 * @param connect_cls the `struct Neighbour` 1798 * @param connect_cls the `struct Neighbour`
1780 */ 1799 */
1781static void 1800static void
1782handle_transport_notify_excess_bw (void *cls, 1801handle_transport_notify_excess_bw(void *cls,
1783 const struct GNUNET_PeerIdentity *pid, 1802 const struct GNUNET_PeerIdentity *pid,
1784 void *connect_cls) 1803 void *connect_cls)
1785{ 1804{
1786 struct GSC_KeyExchangeInfo *kx = connect_cls; 1805 struct GSC_KeyExchangeInfo *kx = connect_cls;
1787 1806
1788 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1807 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
1789 "Peer %s has excess bandwidth available\n", 1808 "Peer %s has excess bandwidth available\n",
1790 GNUNET_i2s (pid)); 1809 GNUNET_i2s(pid));
1791 kx->has_excess_bandwidth = GNUNET_YES; 1810 kx->has_excess_bandwidth = GNUNET_YES;
1792 GSC_SESSIONS_solicit (pid); 1811 GSC_SESSIONS_solicit(pid);
1793} 1812}
1794 1813
1795 1814
@@ -1798,40 +1817,40 @@ handle_transport_notify_excess_bw (void *cls,
1798 * public key and generate the appropriate signature. 1817 * public key and generate the appropriate signature.
1799 */ 1818 */
1800static void 1819static void
1801sign_ephemeral_key () 1820sign_ephemeral_key()
1802{ 1821{
1803 current_ekm.header.size = htons (sizeof (struct EphemeralKeyMessage)); 1822 current_ekm.header.size = htons(sizeof(struct EphemeralKeyMessage));
1804 current_ekm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY); 1823 current_ekm.header.type = htons(GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY);
1805 current_ekm.sender_status = 0; /* to be set later */ 1824 current_ekm.sender_status = 0; /* to be set later */
1806 current_ekm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY); 1825 current_ekm.purpose.purpose = htonl(GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY);
1807 current_ekm.purpose.size = 1826 current_ekm.purpose.size =
1808 htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) + 1827 htonl(sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) +
1809 sizeof (struct GNUNET_TIME_AbsoluteNBO) + 1828 sizeof(struct GNUNET_TIME_AbsoluteNBO) +
1810 sizeof (struct GNUNET_TIME_AbsoluteNBO) + 1829 sizeof(struct GNUNET_TIME_AbsoluteNBO) +
1811 sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) + 1830 sizeof(struct GNUNET_CRYPTO_EcdhePublicKey) +
1812 sizeof (struct GNUNET_PeerIdentity)); 1831 sizeof(struct GNUNET_PeerIdentity));
1813 current_ekm.creation_time = 1832 current_ekm.creation_time =
1814 GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); 1833 GNUNET_TIME_absolute_hton(GNUNET_TIME_absolute_get());
1815 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (GSC_cfg, 1834 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(GSC_cfg,
1816 "core", 1835 "core",
1817 "USE_EPHEMERAL_KEYS")) 1836 "USE_EPHEMERAL_KEYS"))
1818 { 1837 {
1819 current_ekm.expiration_time = 1838 current_ekm.expiration_time =
1820 GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute ( 1839 GNUNET_TIME_absolute_hton(GNUNET_TIME_relative_to_absolute(
1821 GNUNET_TIME_relative_add (REKEY_FREQUENCY, REKEY_TOLERANCE))); 1840 GNUNET_TIME_relative_add(REKEY_FREQUENCY, REKEY_TOLERANCE)));
1822 } 1841 }
1823 else 1842 else
1824 { 1843 {
1825 current_ekm.expiration_time = 1844 current_ekm.expiration_time =
1826 GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); 1845 GNUNET_TIME_absolute_hton(GNUNET_TIME_UNIT_FOREVER_ABS);
1827 } 1846 }
1828 GNUNET_CRYPTO_ecdhe_key_get_public (my_ephemeral_key, 1847 GNUNET_CRYPTO_ecdhe_key_get_public(my_ephemeral_key,
1829 &current_ekm.ephemeral_key); 1848 &current_ekm.ephemeral_key);
1830 current_ekm.origin_identity = GSC_my_identity; 1849 current_ekm.origin_identity = GSC_my_identity;
1831 GNUNET_assert (GNUNET_OK == 1850 GNUNET_assert(GNUNET_OK ==
1832 GNUNET_CRYPTO_eddsa_sign (my_private_key, 1851 GNUNET_CRYPTO_eddsa_sign(my_private_key,
1833 &current_ekm.purpose, 1852 &current_ekm.purpose,
1834 &current_ekm.signature)); 1853 &current_ekm.signature));
1835} 1854}
1836 1855
1837 1856
@@ -1841,40 +1860,40 @@ sign_ephemeral_key ()
1841 * @param cls closure, NULL 1860 * @param cls closure, NULL
1842 */ 1861 */
1843static void 1862static void
1844do_rekey (void *cls) 1863do_rekey(void *cls)
1845{ 1864{
1846 struct GSC_KeyExchangeInfo *pos; 1865 struct GSC_KeyExchangeInfo *pos;
1847 1866
1848 rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, &do_rekey, NULL); 1867 rekey_task = GNUNET_SCHEDULER_add_delayed(REKEY_FREQUENCY, &do_rekey, NULL);
1849 if (NULL != my_ephemeral_key) 1868 if (NULL != my_ephemeral_key)
1850 GNUNET_free (my_ephemeral_key); 1869 GNUNET_free(my_ephemeral_key);
1851 my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create (); 1870 my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create();
1852 GNUNET_assert (NULL != my_ephemeral_key); 1871 GNUNET_assert(NULL != my_ephemeral_key);
1853 sign_ephemeral_key (); 1872 sign_ephemeral_key();
1854 { 1873 {
1855 struct GNUNET_HashCode eh; 1874 struct GNUNET_HashCode eh;
1856 1875
1857 GNUNET_CRYPTO_hash (&current_ekm.ephemeral_key, 1876 GNUNET_CRYPTO_hash(&current_ekm.ephemeral_key,
1858 sizeof (current_ekm.ephemeral_key), 1877 sizeof(current_ekm.ephemeral_key),
1859 &eh); 1878 &eh);
1860 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Rekeying to %s\n", GNUNET_h2s (&eh)); 1879 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Rekeying to %s\n", GNUNET_h2s(&eh));
1861 } 1880 }
1862 for (pos = kx_head; NULL != pos; pos = pos->next) 1881 for (pos = kx_head; NULL != pos; pos = pos->next)
1863 {
1864 if (GNUNET_CORE_KX_STATE_UP == pos->status)
1865 {
1866 pos->status = GNUNET_CORE_KX_STATE_REKEY_SENT;
1867 monitor_notify_all (pos);
1868 derive_session_keys (pos);
1869 }
1870 if (GNUNET_CORE_KX_STATE_DOWN == pos->status)
1871 { 1882 {
1872 pos->status = GNUNET_CORE_KX_STATE_KEY_SENT; 1883 if (GNUNET_CORE_KX_STATE_UP == pos->status)
1873 monitor_notify_all (pos); 1884 {
1885 pos->status = GNUNET_CORE_KX_STATE_REKEY_SENT;
1886 monitor_notify_all(pos);
1887 derive_session_keys(pos);
1888 }
1889 if (GNUNET_CORE_KX_STATE_DOWN == pos->status)
1890 {
1891 pos->status = GNUNET_CORE_KX_STATE_KEY_SENT;
1892 monitor_notify_all(pos);
1893 }
1894 monitor_notify_all(pos);
1895 send_key(pos);
1874 } 1896 }
1875 monitor_notify_all (pos);
1876 send_key (pos);
1877 }
1878} 1897}
1879 1898
1880 1899
@@ -1885,65 +1904,65 @@ do_rekey (void *cls)
1885 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 1904 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1886 */ 1905 */
1887int 1906int
1888GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) 1907GSC_KX_init(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
1889{ 1908{
1890 struct GNUNET_MQ_MessageHandler handlers[] = 1909 struct GNUNET_MQ_MessageHandler handlers[] =
1891 {GNUNET_MQ_hd_fixed_size (ephemeral_key, 1910 { GNUNET_MQ_hd_fixed_size(ephemeral_key,
1892 GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY, 1911 GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY,
1893 struct EphemeralKeyMessage, 1912 struct EphemeralKeyMessage,
1894 NULL),
1895 GNUNET_MQ_hd_fixed_size (ping,
1896 GNUNET_MESSAGE_TYPE_CORE_PING,
1897 struct PingMessage,
1898 NULL),
1899 GNUNET_MQ_hd_fixed_size (pong,
1900 GNUNET_MESSAGE_TYPE_CORE_PONG,
1901 struct PongMessage,
1902 NULL),
1903 GNUNET_MQ_hd_var_size (encrypted,
1904 GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE,
1905 struct EncryptedMessage,
1906 NULL), 1913 NULL),
1907 GNUNET_MQ_handler_end ()}; 1914 GNUNET_MQ_hd_fixed_size(ping,
1915 GNUNET_MESSAGE_TYPE_CORE_PING,
1916 struct PingMessage,
1917 NULL),
1918 GNUNET_MQ_hd_fixed_size(pong,
1919 GNUNET_MESSAGE_TYPE_CORE_PONG,
1920 struct PongMessage,
1921 NULL),
1922 GNUNET_MQ_hd_var_size(encrypted,
1923 GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE,
1924 struct EncryptedMessage,
1925 NULL),
1926 GNUNET_MQ_handler_end() };
1908 1927
1909 my_private_key = pk; 1928 my_private_key = pk;
1910 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, 1929 GNUNET_CRYPTO_eddsa_key_get_public(my_private_key,
1911 &GSC_my_identity.public_key); 1930 &GSC_my_identity.public_key);
1912 my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create (); 1931 my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create();
1913 if (NULL == my_ephemeral_key) 1932 if (NULL == my_ephemeral_key)
1914 { 1933 {
1915 GNUNET_break (0); 1934 GNUNET_break(0);
1916 GNUNET_free (my_private_key); 1935 GNUNET_free(my_private_key);
1917 my_private_key = NULL; 1936 my_private_key = NULL;
1918 return GNUNET_SYSERR; 1937 return GNUNET_SYSERR;
1919 } 1938 }
1920 sign_ephemeral_key (); 1939 sign_ephemeral_key();
1921 { 1940 {
1922 struct GNUNET_HashCode eh; 1941 struct GNUNET_HashCode eh;
1923 1942
1924 GNUNET_CRYPTO_hash (&current_ekm.ephemeral_key, 1943 GNUNET_CRYPTO_hash(&current_ekm.ephemeral_key,
1925 sizeof (current_ekm.ephemeral_key), 1944 sizeof(current_ekm.ephemeral_key),
1926 &eh); 1945 &eh);
1927 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1946 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
1928 "Starting with ephemeral key %s\n", 1947 "Starting with ephemeral key %s\n",
1929 GNUNET_h2s (&eh)); 1948 GNUNET_h2s(&eh));
1930 } 1949 }
1931 1950
1932 nc = GNUNET_notification_context_create (1); 1951 nc = GNUNET_notification_context_create(1);
1933 rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, &do_rekey, NULL); 1952 rekey_task = GNUNET_SCHEDULER_add_delayed(REKEY_FREQUENCY, &do_rekey, NULL);
1934 transport = 1953 transport =
1935 GNUNET_TRANSPORT_core_connect (GSC_cfg, 1954 GNUNET_TRANSPORT_core_connect(GSC_cfg,
1936 &GSC_my_identity, 1955 &GSC_my_identity,
1937 handlers, 1956 handlers,
1938 NULL, 1957 NULL,
1939 &handle_transport_notify_connect, 1958 &handle_transport_notify_connect,
1940 &handle_transport_notify_disconnect, 1959 &handle_transport_notify_disconnect,
1941 &handle_transport_notify_excess_bw); 1960 &handle_transport_notify_excess_bw);
1942 if (NULL == transport) 1961 if (NULL == transport)
1943 { 1962 {
1944 GSC_KX_done (); 1963 GSC_KX_done();
1945 return GNUNET_SYSERR; 1964 return GNUNET_SYSERR;
1946 } 1965 }
1947 return GNUNET_OK; 1966 return GNUNET_OK;
1948} 1967}
1949 1968
@@ -1952,33 +1971,33 @@ GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
1952 * Shutdown KX subsystem. 1971 * Shutdown KX subsystem.
1953 */ 1972 */
1954void 1973void
1955GSC_KX_done () 1974GSC_KX_done()
1956{ 1975{
1957 if (NULL != transport) 1976 if (NULL != transport)
1958 { 1977 {
1959 GNUNET_TRANSPORT_core_disconnect (transport); 1978 GNUNET_TRANSPORT_core_disconnect(transport);
1960 transport = NULL; 1979 transport = NULL;
1961 } 1980 }
1962 if (NULL != rekey_task) 1981 if (NULL != rekey_task)
1963 { 1982 {
1964 GNUNET_SCHEDULER_cancel (rekey_task); 1983 GNUNET_SCHEDULER_cancel(rekey_task);
1965 rekey_task = NULL; 1984 rekey_task = NULL;
1966 } 1985 }
1967 if (NULL != my_ephemeral_key) 1986 if (NULL != my_ephemeral_key)
1968 { 1987 {
1969 GNUNET_free (my_ephemeral_key); 1988 GNUNET_free(my_ephemeral_key);
1970 my_ephemeral_key = NULL; 1989 my_ephemeral_key = NULL;
1971 } 1990 }
1972 if (NULL != my_private_key) 1991 if (NULL != my_private_key)
1973 { 1992 {
1974 GNUNET_free (my_private_key); 1993 GNUNET_free(my_private_key);
1975 my_private_key = NULL; 1994 my_private_key = NULL;
1976 } 1995 }
1977 if (NULL != nc) 1996 if (NULL != nc)
1978 { 1997 {
1979 GNUNET_notification_context_destroy (nc); 1998 GNUNET_notification_context_destroy(nc);
1980 nc = NULL; 1999 nc = NULL;
1981 } 2000 }
1982} 2001}
1983 2002
1984 2003
@@ -1989,9 +2008,9 @@ GSC_KX_done ()
1989 * @return number of items in the message queue 2008 * @return number of items in the message queue
1990 */ 2009 */
1991unsigned int 2010unsigned int
1992GSC_NEIGHBOURS_get_queue_length (const struct GSC_KeyExchangeInfo *kxinfo) 2011GSC_NEIGHBOURS_get_queue_length(const struct GSC_KeyExchangeInfo *kxinfo)
1993{ 2012{
1994 return GNUNET_MQ_get_length (kxinfo->mq); 2013 return GNUNET_MQ_get_length(kxinfo->mq);
1995} 2014}
1996 2015
1997 2016
@@ -2002,7 +2021,7 @@ GSC_NEIGHBOURS_get_queue_length (const struct GSC_KeyExchangeInfo *kxinfo)
2002 * @return #GNUNET_YES if excess bandwidth is available, #GNUNET_NO if not 2021 * @return #GNUNET_YES if excess bandwidth is available, #GNUNET_NO if not
2003 */ 2022 */
2004int 2023int
2005GSC_NEIGHBOURS_check_excess_bandwidth (const struct GSC_KeyExchangeInfo *kxinfo) 2024GSC_NEIGHBOURS_check_excess_bandwidth(const struct GSC_KeyExchangeInfo *kxinfo)
2006{ 2025{
2007 return kxinfo->has_excess_bandwidth; 2026 return kxinfo->has_excess_bandwidth;
2008} 2027}
@@ -2017,28 +2036,28 @@ GSC_NEIGHBOURS_check_excess_bandwidth (const struct GSC_KeyExchangeInfo *kxinfo)
2017 * @param mq message queue to add for monitoring 2036 * @param mq message queue to add for monitoring
2018 */ 2037 */
2019void 2038void
2020GSC_KX_handle_client_monitor_peers (struct GNUNET_MQ_Handle *mq) 2039GSC_KX_handle_client_monitor_peers(struct GNUNET_MQ_Handle *mq)
2021{ 2040{
2022 struct GNUNET_MQ_Envelope *env; 2041 struct GNUNET_MQ_Envelope *env;
2023 struct MonitorNotifyMessage *done_msg; 2042 struct MonitorNotifyMessage *done_msg;
2024 struct GSC_KeyExchangeInfo *kx; 2043 struct GSC_KeyExchangeInfo *kx;
2025 2044
2026 GNUNET_notification_context_add (nc, mq); 2045 GNUNET_notification_context_add(nc, mq);
2027 for (kx = kx_head; NULL != kx; kx = kx->next) 2046 for (kx = kx_head; NULL != kx; kx = kx->next)
2028 { 2047 {
2029 struct GNUNET_MQ_Envelope *env; 2048 struct GNUNET_MQ_Envelope *env;
2030 struct MonitorNotifyMessage *msg; 2049 struct MonitorNotifyMessage *msg;
2031 2050
2032 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY); 2051 env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY);
2033 msg->state = htonl ((uint32_t) kx->status); 2052 msg->state = htonl((uint32_t)kx->status);
2034 msg->peer = *kx->peer; 2053 msg->peer = *kx->peer;
2035 msg->timeout = GNUNET_TIME_absolute_hton (kx->timeout); 2054 msg->timeout = GNUNET_TIME_absolute_hton(kx->timeout);
2036 GNUNET_MQ_send (mq, env); 2055 GNUNET_MQ_send(mq, env);
2037 } 2056 }
2038 env = GNUNET_MQ_msg (done_msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY); 2057 env = GNUNET_MQ_msg(done_msg, GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY);
2039 done_msg->state = htonl ((uint32_t) GNUNET_CORE_KX_ITERATION_FINISHED); 2058 done_msg->state = htonl((uint32_t)GNUNET_CORE_KX_ITERATION_FINISHED);
2040 done_msg->timeout = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS); 2059 done_msg->timeout = GNUNET_TIME_absolute_hton(GNUNET_TIME_UNIT_FOREVER_ABS);
2041 GNUNET_MQ_send (mq, env); 2060 GNUNET_MQ_send(mq, env);
2042} 2061}
2043 2062
2044 2063
diff --git a/src/core/gnunet-service-core_kx.h b/src/core/gnunet-service-core_kx.h
index d27c3687a..d8928f7d3 100644
--- a/src/core/gnunet-service-core_kx.h
+++ b/src/core/gnunet-service-core_kx.h
@@ -11,12 +11,12 @@
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 core/gnunet-service-core_kx.h 22 * @file core/gnunet-service-core_kx.h
@@ -44,9 +44,9 @@ struct GSC_KeyExchangeInfo;
44 * @param payload_size number of bytes in 'payload' 44 * @param payload_size number of bytes in 'payload'
45 */ 45 */
46void 46void
47GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, 47GSC_KX_encrypt_and_transmit(struct GSC_KeyExchangeInfo *kx,
48 const void *payload, 48 const void *payload,
49 size_t payload_size); 49 size_t payload_size);
50 50
51 51
52/** 52/**
@@ -56,14 +56,14 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
56 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 56 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
57 */ 57 */
58int 58int
59GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk); 59GSC_KX_init(struct GNUNET_CRYPTO_EddsaPrivateKey *pk);
60 60
61 61
62/** 62/**
63 * Shutdown KX subsystem. 63 * Shutdown KX subsystem.
64 */ 64 */
65void 65void
66GSC_KX_done (void); 66GSC_KX_done(void);
67 67
68 68
69/** 69/**
@@ -73,7 +73,7 @@ GSC_KX_done (void);
73 * @return #GNUNET_YES if excess bandwidth is available, #GNUNET_NO if not 73 * @return #GNUNET_YES if excess bandwidth is available, #GNUNET_NO if not
74 */ 74 */
75int 75int
76GSC_NEIGHBOURS_check_excess_bandwidth (const struct GSC_KeyExchangeInfo *target); 76GSC_NEIGHBOURS_check_excess_bandwidth(const struct GSC_KeyExchangeInfo *target);
77 77
78 78
79/** 79/**
@@ -83,7 +83,7 @@ GSC_NEIGHBOURS_check_excess_bandwidth (const struct GSC_KeyExchangeInfo *target)
83 * @return number of items in the message queue 83 * @return number of items in the message queue
84 */ 84 */
85unsigned int 85unsigned int
86GSC_NEIGHBOURS_get_queue_length (const struct GSC_KeyExchangeInfo *target); 86GSC_NEIGHBOURS_get_queue_length(const struct GSC_KeyExchangeInfo *target);
87 87
88 88
89/** 89/**
@@ -95,7 +95,7 @@ GSC_NEIGHBOURS_get_queue_length (const struct GSC_KeyExchangeInfo *target);
95 * @param mq message queue to add for monitoring 95 * @param mq message queue to add for monitoring
96 */ 96 */
97void 97void
98GSC_KX_handle_client_monitor_peers (struct GNUNET_MQ_Handle *mq); 98GSC_KX_handle_client_monitor_peers(struct GNUNET_MQ_Handle *mq);
99 99
100 100
101#endif 101#endif
diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c
index 8ff61ec20..daca22aef 100644
--- a/src/core/gnunet-service-core_sessions.c
+++ b/src/core/gnunet-service-core_sessions.c
@@ -16,7 +16,7 @@
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 core/gnunet-service-core_sessions.c 22 * @file core/gnunet-service-core_sessions.c
@@ -43,9 +43,7 @@
43 * Message ready for encryption. This struct is followed by the 43 * Message ready for encryption. This struct is followed by the
44 * actual content of the message. 44 * actual content of the message.
45 */ 45 */
46struct SessionMessageEntry 46struct SessionMessageEntry {
47{
48
49 /** 47 /**
50 * We keep messages in a doubly linked list. 48 * We keep messages in a doubly linked list.
51 */ 49 */
@@ -90,8 +88,7 @@ struct SessionMessageEntry
90/** 88/**
91 * Data kept per session. 89 * Data kept per session.
92 */ 90 */
93struct Session 91struct Session {
94{
95 /** 92 /**
96 * Identity of the other peer. 93 * Identity of the other peer.
97 */ 94 */
@@ -159,9 +156,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
159/** 156/**
160 * Message sent to confirm that a typemap was received. 157 * Message sent to confirm that a typemap was received.
161 */ 158 */
162struct TypeMapConfirmationMessage 159struct TypeMapConfirmationMessage {
163{
164
165 /** 160 /**
166 * Header with type #GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP. 161 * Header with type #GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP.
167 */ 162 */
@@ -195,11 +190,11 @@ static struct GNUNET_CONTAINER_MultiPeerMap *sessions;
195 * session handle 190 * session handle
196 */ 191 */
197static struct Session * 192static struct Session *
198find_session (const struct GNUNET_PeerIdentity *peer) 193find_session(const struct GNUNET_PeerIdentity *peer)
199{ 194{
200 if (NULL == sessions) 195 if (NULL == sessions)
201 return NULL; 196 return NULL;
202 return GNUNET_CONTAINER_multipeermap_get (sessions, peer); 197 return GNUNET_CONTAINER_multipeermap_get(sessions, peer);
203} 198}
204 199
205 200
@@ -210,53 +205,53 @@ find_session (const struct GNUNET_PeerIdentity *peer)
210 * @param pid identity of peer to kill session with 205 * @param pid identity of peer to kill session with
211 */ 206 */
212void 207void
213GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid) 208GSC_SESSIONS_end(const struct GNUNET_PeerIdentity *pid)
214{ 209{
215 struct Session *session; 210 struct Session *session;
216 struct GSC_ClientActiveRequest *car; 211 struct GSC_ClientActiveRequest *car;
217 struct SessionMessageEntry *sme; 212 struct SessionMessageEntry *sme;
218 213
219 session = find_session (pid); 214 session = find_session(pid);
220 if (NULL == session) 215 if (NULL == session)
221 return; 216 return;
222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 217 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
223 "Destroying session for peer `%s'\n", 218 "Destroying session for peer `%s'\n",
224 GNUNET_i2s (session->peer)); 219 GNUNET_i2s(session->peer));
225 if (NULL != session->cork_task) 220 if (NULL != session->cork_task)
226 { 221 {
227 GNUNET_SCHEDULER_cancel (session->cork_task); 222 GNUNET_SCHEDULER_cancel(session->cork_task);
228 session->cork_task = NULL; 223 session->cork_task = NULL;
229 } 224 }
230 while (NULL != (car = session->active_client_request_head)) 225 while (NULL != (car = session->active_client_request_head))
231 { 226 {
232 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, 227 GNUNET_CONTAINER_DLL_remove(session->active_client_request_head,
233 session->active_client_request_tail, 228 session->active_client_request_tail,
234 car); 229 car);
235 GSC_CLIENTS_reject_request (car, GNUNET_NO); 230 GSC_CLIENTS_reject_request(car, GNUNET_NO);
236 } 231 }
237 while (NULL != (sme = session->sme_head)) 232 while (NULL != (sme = session->sme_head))
238 { 233 {
239 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme); 234 GNUNET_CONTAINER_DLL_remove(session->sme_head, session->sme_tail, sme);
240 GNUNET_free (sme); 235 GNUNET_free(sme);
241 } 236 }
242 if (NULL != session->typemap_task) 237 if (NULL != session->typemap_task)
243 { 238 {
244 GNUNET_SCHEDULER_cancel (session->typemap_task); 239 GNUNET_SCHEDULER_cancel(session->typemap_task);
245 session->typemap_task = NULL; 240 session->typemap_task = NULL;
246 } 241 }
247 GSC_CLIENTS_notify_clients_about_neighbour (session->peer, 242 GSC_CLIENTS_notify_clients_about_neighbour(session->peer,
248 session->tmap, 243 session->tmap,
249 NULL); 244 NULL);
250 GNUNET_assert ( 245 GNUNET_assert(
251 GNUNET_YES == 246 GNUNET_YES ==
252 GNUNET_CONTAINER_multipeermap_remove (sessions, session->peer, session)); 247 GNUNET_CONTAINER_multipeermap_remove(sessions, session->peer, session));
253 GNUNET_STATISTICS_set (GSC_stats, 248 GNUNET_STATISTICS_set(GSC_stats,
254 gettext_noop ("# peers connected"), 249 gettext_noop("# peers connected"),
255 GNUNET_CONTAINER_multipeermap_size (sessions), 250 GNUNET_CONTAINER_multipeermap_size(sessions),
256 GNUNET_NO); 251 GNUNET_NO);
257 GSC_TYPEMAP_destroy (session->tmap); 252 GSC_TYPEMAP_destroy(session->tmap);
258 session->tmap = NULL; 253 session->tmap = NULL;
259 GNUNET_free (session); 254 GNUNET_free(session);
260} 255}
261 256
262 257
@@ -267,29 +262,29 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
267 * @param cls the `struct Session *` 262 * @param cls the `struct Session *`
268 */ 263 */
269static void 264static void
270transmit_typemap_task (void *cls) 265transmit_typemap_task(void *cls)
271{ 266{
272 struct Session *session = cls; 267 struct Session *session = cls;
273 struct GNUNET_MessageHeader *hdr; 268 struct GNUNET_MessageHeader *hdr;
274 struct GNUNET_TIME_Relative delay; 269 struct GNUNET_TIME_Relative delay;
275 270
276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 271 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
277 "Sending TYPEMAP to %s\n", 272 "Sending TYPEMAP to %s\n",
278 GNUNET_i2s (session->peer)); 273 GNUNET_i2s(session->peer));
279 session->typemap_delay = GNUNET_TIME_STD_BACKOFF (session->typemap_delay); 274 session->typemap_delay = GNUNET_TIME_STD_BACKOFF(session->typemap_delay);
280 delay = session->typemap_delay; 275 delay = session->typemap_delay;
281 /* randomize a bit to avoid spont. sync */ 276 /* randomize a bit to avoid spont. sync */
282 delay.rel_value_us += 277 delay.rel_value_us +=
283 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000 * 1000); 278 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 1000 * 1000);
284 session->typemap_task = 279 session->typemap_task =
285 GNUNET_SCHEDULER_add_delayed (delay, &transmit_typemap_task, session); 280 GNUNET_SCHEDULER_add_delayed(delay, &transmit_typemap_task, session);
286 GNUNET_STATISTICS_update (GSC_stats, 281 GNUNET_STATISTICS_update(GSC_stats,
287 gettext_noop ("# type map refreshes sent"), 282 gettext_noop("# type map refreshes sent"),
288 1, 283 1,
289 GNUNET_NO); 284 GNUNET_NO);
290 hdr = GSC_TYPEMAP_compute_type_map_message (); 285 hdr = GSC_TYPEMAP_compute_type_map_message();
291 GSC_KX_encrypt_and_transmit (session->kx, hdr, ntohs (hdr->size)); 286 GSC_KX_encrypt_and_transmit(session->kx, hdr, ntohs(hdr->size));
292 GNUNET_free (hdr); 287 GNUNET_free(hdr);
293} 288}
294 289
295 290
@@ -299,14 +294,14 @@ transmit_typemap_task (void *cls)
299 * @param session session to restart typemap transmission for 294 * @param session session to restart typemap transmission for
300 */ 295 */
301static void 296static void
302start_typemap_task (struct Session *session) 297start_typemap_task(struct Session *session)
303{ 298{
304 if (NULL != session->typemap_task) 299 if (NULL != session->typemap_task)
305 GNUNET_SCHEDULER_cancel (session->typemap_task); 300 GNUNET_SCHEDULER_cancel(session->typemap_task);
306 session->typemap_delay = GNUNET_TIME_UNIT_SECONDS; 301 session->typemap_delay = GNUNET_TIME_UNIT_SECONDS;
307 session->typemap_task = GNUNET_SCHEDULER_add_delayed (session->typemap_delay, 302 session->typemap_task = GNUNET_SCHEDULER_add_delayed(session->typemap_delay,
308 &transmit_typemap_task, 303 &transmit_typemap_task,
309 session); 304 session);
310} 305}
311 306
312 307
@@ -317,30 +312,30 @@ start_typemap_task (struct Session *session)
317 * @param kx key exchange that completed 312 * @param kx key exchange that completed
318 */ 313 */
319void 314void
320GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, 315GSC_SESSIONS_create(const struct GNUNET_PeerIdentity *peer,
321 struct GSC_KeyExchangeInfo *kx) 316 struct GSC_KeyExchangeInfo *kx)
322{ 317{
323 struct Session *session; 318 struct Session *session;
324 319
325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 320 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
326 "Creating session for peer `%s'\n", 321 "Creating session for peer `%s'\n",
327 GNUNET_i2s (peer)); 322 GNUNET_i2s(peer));
328 session = GNUNET_new (struct Session); 323 session = GNUNET_new(struct Session);
329 session->tmap = GSC_TYPEMAP_create (); 324 session->tmap = GSC_TYPEMAP_create();
330 session->peer = peer; 325 session->peer = peer;
331 session->kx = kx; 326 session->kx = kx;
332 GNUNET_assert (GNUNET_OK == 327 GNUNET_assert(GNUNET_OK ==
333 GNUNET_CONTAINER_multipeermap_put ( 328 GNUNET_CONTAINER_multipeermap_put(
334 sessions, 329 sessions,
335 session->peer, 330 session->peer,
336 session, 331 session,
337 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 332 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
338 GNUNET_STATISTICS_set (GSC_stats, 333 GNUNET_STATISTICS_set(GSC_stats,
339 gettext_noop ("# peers connected"), 334 gettext_noop("# peers connected"),
340 GNUNET_CONTAINER_multipeermap_size (sessions), 335 GNUNET_CONTAINER_multipeermap_size(sessions),
341 GNUNET_NO); 336 GNUNET_NO);
342 GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, session->tmap); 337 GSC_CLIENTS_notify_clients_about_neighbour(peer, NULL, session->tmap);
343 start_typemap_task (session); 338 start_typemap_task(session);
344} 339}
345 340
346 341
@@ -352,18 +347,18 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
352 * @param peer peer that is now connected 347 * @param peer peer that is now connected
353 */ 348 */
354void 349void
355GSC_SESSIONS_reinit (const struct GNUNET_PeerIdentity *peer) 350GSC_SESSIONS_reinit(const struct GNUNET_PeerIdentity *peer)
356{ 351{
357 struct Session *session; 352 struct Session *session;
358 353
359 session = find_session (peer); 354 session = find_session(peer);
360 if (NULL == session) 355 if (NULL == session)
361 { 356 {
362 /* KX/session is new for both sides; thus no need to restart what 357 /* KX/session is new for both sides; thus no need to restart what
363 has not yet begun */ 358 has not yet begun */
364 return; 359 return;
365 } 360 }
366 start_typemap_task (session); 361 start_typemap_task(session);
367} 362}
368 363
369 364
@@ -375,51 +370,51 @@ GSC_SESSIONS_reinit (const struct GNUNET_PeerIdentity *peer)
375 * @param msg confirmation message we received 370 * @param msg confirmation message we received
376 */ 371 */
377void 372void
378GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer, 373GSC_SESSIONS_confirm_typemap(const struct GNUNET_PeerIdentity *peer,
379 const struct GNUNET_MessageHeader *msg) 374 const struct GNUNET_MessageHeader *msg)
380{ 375{
381 const struct TypeMapConfirmationMessage *cmsg; 376 const struct TypeMapConfirmationMessage *cmsg;
382 struct Session *session; 377 struct Session *session;
383 378
384 session = find_session (peer); 379 session = find_session(peer);
385 if (NULL == session) 380 if (NULL == session)
386 { 381 {
387 GNUNET_break (0); 382 GNUNET_break(0);
388 return; 383 return;
389 } 384 }
390 if (ntohs (msg->size) != sizeof (struct TypeMapConfirmationMessage)) 385 if (ntohs(msg->size) != sizeof(struct TypeMapConfirmationMessage))
391 { 386 {
392 GNUNET_break_op (0); 387 GNUNET_break_op(0);
393 return; 388 return;
394 } 389 }
395 cmsg = (const struct TypeMapConfirmationMessage *) msg; 390 cmsg = (const struct TypeMapConfirmationMessage *)msg;
396 if (GNUNET_YES != GSC_TYPEMAP_check_hash (&cmsg->tm_hash)) 391 if (GNUNET_YES != GSC_TYPEMAP_check_hash(&cmsg->tm_hash))
397 { 392 {
398 /* our typemap has changed in the meantime, do not 393 /* our typemap has changed in the meantime, do not
399 accept confirmation */ 394 accept confirmation */
400 GNUNET_STATISTICS_update (GSC_stats, 395 GNUNET_STATISTICS_update(GSC_stats,
401 gettext_noop ( 396 gettext_noop(
402 "# outdated typemap confirmations received"), 397 "# outdated typemap confirmations received"),
403 1, 398 1,
404 GNUNET_NO); 399 GNUNET_NO);
405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 400 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
406 "Got outdated typemap confirmated from peer `%s'\n", 401 "Got outdated typemap confirmated from peer `%s'\n",
407 GNUNET_i2s (session->peer)); 402 GNUNET_i2s(session->peer));
408 return; 403 return;
409 } 404 }
410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 405 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
411 "Got typemap confirmation from peer `%s'\n", 406 "Got typemap confirmation from peer `%s'\n",
412 GNUNET_i2s (session->peer)); 407 GNUNET_i2s(session->peer));
413 if (NULL != session->typemap_task) 408 if (NULL != session->typemap_task)
414 { 409 {
415 GNUNET_SCHEDULER_cancel (session->typemap_task); 410 GNUNET_SCHEDULER_cancel(session->typemap_task);
416 session->typemap_task = NULL; 411 session->typemap_task = NULL;
417 } 412 }
418 GNUNET_STATISTICS_update (GSC_stats, 413 GNUNET_STATISTICS_update(GSC_stats,
419 gettext_noop ( 414 gettext_noop(
420 "# valid typemap confirmations received"), 415 "# valid typemap confirmations received"),
421 1, 416 1,
422 GNUNET_NO); 417 GNUNET_NO);
423} 418}
424 419
425 420
@@ -432,17 +427,17 @@ GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer,
432 * @return #GNUNET_OK (continue to iterate) 427 * @return #GNUNET_OK (continue to iterate)
433 */ 428 */
434static int 429static int
435notify_client_about_session (void *cls, 430notify_client_about_session(void *cls,
436 const struct GNUNET_PeerIdentity *key, 431 const struct GNUNET_PeerIdentity *key,
437 void *value) 432 void *value)
438{ 433{
439 struct GSC_Client *client = cls; 434 struct GSC_Client *client = cls;
440 struct Session *session = value; 435 struct Session *session = value;
441 436
442 GSC_CLIENTS_notify_client_about_neighbour (client, 437 GSC_CLIENTS_notify_client_about_neighbour(client,
443 session->peer, 438 session->peer,
444 NULL, /* old TMAP: none */ 439 NULL, /* old TMAP: none */
445 session->tmap); 440 session->tmap);
446 return GNUNET_OK; 441 return GNUNET_OK;
447} 442}
448 443
@@ -453,12 +448,12 @@ notify_client_about_session (void *cls,
453 * @param client the new client 448 * @param client the new client
454 */ 449 */
455void 450void
456GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client) 451GSC_SESSIONS_notify_client_about_sessions(struct GSC_Client *client)
457{ 452{
458 /* notify new client about existing sessions */ 453 /* notify new client about existing sessions */
459 GNUNET_CONTAINER_multipeermap_iterate (sessions, 454 GNUNET_CONTAINER_multipeermap_iterate(sessions,
460 &notify_client_about_session, 455 &notify_client_about_session,
461 client); 456 client);
462} 457}
463 458
464 459
@@ -469,7 +464,7 @@ GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client)
469 * @param session session to transmit messages from 464 * @param session session to transmit messages from
470 */ 465 */
471static void 466static void
472try_transmission (struct Session *session); 467try_transmission(struct Session *session);
473 468
474 469
475/** 470/**
@@ -482,31 +477,31 @@ try_transmission (struct Session *session);
482 * have been invoked on it 477 * have been invoked on it
483 */ 478 */
484void 479void
485GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car) 480GSC_SESSIONS_queue_request(struct GSC_ClientActiveRequest *car)
486{ 481{
487 struct Session *session; 482 struct Session *session;
488 483
489 session = find_session (&car->target); 484 session = find_session(&car->target);
490 if (NULL == session) 485 if (NULL == session)
491 { 486 {
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 487 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
493 "Dropped client request for transmission (am disconnected)\n"); 488 "Dropped client request for transmission (am disconnected)\n");
494 GNUNET_break (0); /* should have been rejected earlier */ 489 GNUNET_break(0); /* should have been rejected earlier */
495 GSC_CLIENTS_reject_request (car, GNUNET_NO); 490 GSC_CLIENTS_reject_request(car, GNUNET_NO);
496 return; 491 return;
497 } 492 }
498 if (car->msize > GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 493 if (car->msize > GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
499 { 494 {
500 GNUNET_break (0); 495 GNUNET_break(0);
501 GSC_CLIENTS_reject_request (car, GNUNET_YES); 496 GSC_CLIENTS_reject_request(car, GNUNET_YES);
502 return; 497 return;
503 } 498 }
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 499 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
505 "Received client transmission request. queueing\n"); 500 "Received client transmission request. queueing\n");
506 GNUNET_CONTAINER_DLL_insert_tail (session->active_client_request_head, 501 GNUNET_CONTAINER_DLL_insert_tail(session->active_client_request_head,
507 session->active_client_request_tail, 502 session->active_client_request_tail,
508 car); 503 car);
509 try_transmission (session); 504 try_transmission(session);
510} 505}
511 506
512 507
@@ -517,23 +512,23 @@ GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car)
517 * the caller (CLIENTS sysbsystem) 512 * the caller (CLIENTS sysbsystem)
518 */ 513 */
519void 514void
520GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car) 515GSC_SESSIONS_dequeue_request(struct GSC_ClientActiveRequest *car)
521{ 516{
522 struct Session *session; 517 struct Session *session;
523 518
524 if (0 == memcmp (&car->target, 519 if (0 == memcmp(&car->target,
525 &GSC_my_identity, 520 &GSC_my_identity,
526 sizeof (struct GNUNET_PeerIdentity))) 521 sizeof(struct GNUNET_PeerIdentity)))
527 return; 522 return;
528 session = find_session (&car->target); 523 session = find_session(&car->target);
529 GNUNET_assert (NULL != session); 524 GNUNET_assert(NULL != session);
530 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, 525 GNUNET_CONTAINER_DLL_remove(session->active_client_request_head,
531 session->active_client_request_tail, 526 session->active_client_request_tail,
532 car); 527 car);
533 /* dequeueing of 'high' priority messages may unblock 528 /* dequeueing of 'high' priority messages may unblock
534 transmission for lower-priority messages, so we also 529 transmission for lower-priority messages, so we also
535 need to try in this case. */ 530 need to try in this case. */
536 try_transmission (session); 531 try_transmission(session);
537} 532}
538 533
539 534
@@ -545,7 +540,7 @@ GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car)
545 * @param msize how many bytes do we have already 540 * @param msize how many bytes do we have already
546 */ 541 */
547static void 542static void
548solicit_messages (struct Session *session, size_t msize) 543solicit_messages(struct Session *session, size_t msize)
549{ 544{
550 struct GSC_ClientActiveRequest *car; 545 struct GSC_ClientActiveRequest *car;
551 struct GSC_ClientActiveRequest *nxt; 546 struct GSC_ClientActiveRequest *nxt;
@@ -555,33 +550,33 @@ solicit_messages (struct Session *session, size_t msize)
555 so_size = msize; 550 so_size = msize;
556 pmax = GNUNET_MQ_PRIO_BACKGROUND; 551 pmax = GNUNET_MQ_PRIO_BACKGROUND;
557 for (car = session->active_client_request_head; NULL != car; car = car->next) 552 for (car = session->active_client_request_head; NULL != car; car = car->next)
558 { 553 {
559 if (GNUNET_YES == car->was_solicited) 554 if (GNUNET_YES == car->was_solicited)
560 continue; 555 continue;
561 pmax = GNUNET_MAX (pmax, car->priority & GNUNET_MQ_PRIORITY_MASK); 556 pmax = GNUNET_MAX(pmax, car->priority & GNUNET_MQ_PRIORITY_MASK);
562 } 557 }
563 nxt = session->active_client_request_head; 558 nxt = session->active_client_request_head;
564 while (NULL != (car = nxt)) 559 while (NULL != (car = nxt))
565 { 560 {
566 nxt = car->next; 561 nxt = car->next;
567 if (car->priority < pmax) 562 if (car->priority < pmax)
568 continue; 563 continue;
569 if (so_size + car->msize > GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 564 if (so_size + car->msize > GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
570 break; 565 break;
571 so_size += car->msize; 566 so_size += car->msize;
572 if (GNUNET_YES == car->was_solicited) 567 if (GNUNET_YES == car->was_solicited)
573 continue; 568 continue;
574 car->was_solicited = GNUNET_YES; 569 car->was_solicited = GNUNET_YES;
575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 570 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
576 "Soliciting message with priority %u\n", 571 "Soliciting message with priority %u\n",
577 car->priority); 572 car->priority);
578 GSC_CLIENTS_solicit_request (car); 573 GSC_CLIENTS_solicit_request(car);
579 /* The above call may *dequeue* requests and thereby 574 /* The above call may *dequeue* requests and thereby
580 clobber 'nxt'. Hence we need to restart from the 575 clobber 'nxt'. Hence we need to restart from the
581 head of the list. */ 576 head of the list. */
582 nxt = session->active_client_request_head; 577 nxt = session->active_client_request_head;
583 so_size = msize; 578 so_size = msize;
584 } 579 }
585} 580}
586 581
587 582
@@ -592,12 +587,12 @@ solicit_messages (struct Session *session, size_t msize)
592 * @param cls `struct Session` with the messages to transmit now 587 * @param cls `struct Session` with the messages to transmit now
593 */ 588 */
594static void 589static void
595pop_cork_task (void *cls) 590pop_cork_task(void *cls)
596{ 591{
597 struct Session *session = cls; 592 struct Session *session = cls;
598 593
599 session->cork_task = NULL; 594 session->cork_task = NULL;
600 try_transmission (session); 595 try_transmission(session);
601} 596}
602 597
603 598
@@ -609,7 +604,7 @@ pop_cork_task (void *cls)
609 * @param session session to transmit messages from 604 * @param session session to transmit messages from
610 */ 605 */
611static void 606static void
612try_transmission (struct Session *session) 607try_transmission(struct Session *session)
613{ 608{
614 struct SessionMessageEntry *pos; 609 struct SessionMessageEntry *pos;
615 size_t msize; 610 size_t msize;
@@ -625,13 +620,13 @@ try_transmission (struct Session *session)
625 /* if the peer has excess bandwidth, background traffic is allowed, 620 /* if the peer has excess bandwidth, background traffic is allowed,
626 otherwise not */ 621 otherwise not */
627 if (MAX_ENCRYPTED_MESSAGE_QUEUE_SIZE <= 622 if (MAX_ENCRYPTED_MESSAGE_QUEUE_SIZE <=
628 GSC_NEIGHBOURS_get_queue_length (session->kx)) 623 GSC_NEIGHBOURS_get_queue_length(session->kx))
629 { 624 {
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 625 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
631 "Transmission queue already very long, waiting...\n"); 626 "Transmission queue already very long, waiting...\n");
632 return; /* queue already too long */ 627 return; /* queue already too long */
633 } 628 }
634 excess = GSC_NEIGHBOURS_check_excess_bandwidth (session->kx); 629 excess = GSC_NEIGHBOURS_check_excess_bandwidth(session->kx);
635 if (GNUNET_YES == excess) 630 if (GNUNET_YES == excess)
636 maxp = GNUNET_MQ_PRIO_BACKGROUND; 631 maxp = GNUNET_MQ_PRIO_BACKGROUND;
637 else 632 else
@@ -640,98 +635,98 @@ try_transmission (struct Session *session)
640 pos = session->sme_head; 635 pos = session->sme_head;
641 while ((NULL != pos) && 636 while ((NULL != pos) &&
642 (msize + pos->size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)) 637 (msize + pos->size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE))
643 { 638 {
644 GNUNET_assert (pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); 639 GNUNET_assert(pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
645 msize += pos->size; 640 msize += pos->size;
646 maxp = GNUNET_MAX (maxp, pos->priority & GNUNET_MQ_PRIORITY_MASK); 641 maxp = GNUNET_MAX(maxp, pos->priority & GNUNET_MQ_PRIORITY_MASK);
647 min_deadline = GNUNET_TIME_absolute_min (min_deadline, pos->deadline); 642 min_deadline = GNUNET_TIME_absolute_min(min_deadline, pos->deadline);
648 pos = pos->next; 643 pos = pos->next;
649 } 644 }
650 GNUNET_log ( 645 GNUNET_log(
651 GNUNET_ERROR_TYPE_DEBUG, 646 GNUNET_ERROR_TYPE_DEBUG,
652 "Calculating transmission set with %u priority (%s) and %s earliest deadline\n", 647 "Calculating transmission set with %u priority (%s) and %s earliest deadline\n",
653 maxp, 648 maxp,
654 (GNUNET_YES == excess) ? "excess bandwidth" : "limited bandwidth", 649 (GNUNET_YES == excess) ? "excess bandwidth" : "limited bandwidth",
655 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( 650 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining(
656 min_deadline), 651 min_deadline),
657 GNUNET_YES)); 652 GNUNET_YES));
658 653
659 if (maxp < GNUNET_MQ_PRIO_CRITICAL_CONTROL) 654 if (maxp < GNUNET_MQ_PRIO_CRITICAL_CONTROL)
660 {
661 /* if highest already solicited priority from clients is not critical,
662 check if there are higher-priority messages to be solicited from clients */
663 if (GNUNET_YES == excess)
664 maxpc = GNUNET_MQ_PRIO_BACKGROUND;
665 else
666 maxpc = GNUNET_MQ_PRIO_BEST_EFFORT;
667 for (car = session->active_client_request_head; NULL != car;
668 car = car->next)
669 { 655 {
670 if (GNUNET_YES == car->was_solicited) 656 /* if highest already solicited priority from clients is not critical,
671 continue; 657 check if there are higher-priority messages to be solicited from clients */
672 maxpc = GNUNET_MAX (maxpc, car->priority & GNUNET_MQ_PRIORITY_MASK); 658 if (GNUNET_YES == excess)
659 maxpc = GNUNET_MQ_PRIO_BACKGROUND;
660 else
661 maxpc = GNUNET_MQ_PRIO_BEST_EFFORT;
662 for (car = session->active_client_request_head; NULL != car;
663 car = car->next)
664 {
665 if (GNUNET_YES == car->was_solicited)
666 continue;
667 maxpc = GNUNET_MAX(maxpc, car->priority & GNUNET_MQ_PRIORITY_MASK);
668 }
669 if (maxpc > maxp)
670 {
671 /* we have messages waiting for solicitation that have a higher
672 priority than those that we already accepted; solicit the
673 high-priority messages first */
674 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
675 "Soliciting messages based on priority (%u > %u)\n",
676 maxpc,
677 maxp);
678 solicit_messages(session, 0);
679 return;
680 }
673 } 681 }
674 if (maxpc > maxp) 682 else
675 { 683 {
676 /* we have messages waiting for solicitation that have a higher 684 /* never solicit more, we have critical messages to process */
677 priority than those that we already accepted; solicit the 685 excess = GNUNET_NO;
678 high-priority messages first */ 686 maxpc = GNUNET_MQ_PRIO_BACKGROUND;
679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
680 "Soliciting messages based on priority (%u > %u)\n",
681 maxpc,
682 maxp);
683 solicit_messages (session, 0);
684 return;
685 } 687 }
686 } 688 now = GNUNET_TIME_absolute_get();
687 else
688 {
689 /* never solicit more, we have critical messages to process */
690 excess = GNUNET_NO;
691 maxpc = GNUNET_MQ_PRIO_BACKGROUND;
692 }
693 now = GNUNET_TIME_absolute_get ();
694 if (((GNUNET_YES == excess) || (maxpc >= GNUNET_MQ_PRIO_BEST_EFFORT)) && 689 if (((GNUNET_YES == excess) || (maxpc >= GNUNET_MQ_PRIO_BEST_EFFORT)) &&
695 ((0 == msize) || 690 ((0 == msize) ||
696 ((msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) && 691 ((msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) &&
697 (min_deadline.abs_value_us > now.abs_value_us)))) 692 (min_deadline.abs_value_us > now.abs_value_us))))
698 {
699 /* not enough ready yet (tiny message & cork possible), or no messages at all,
700 and either excess bandwidth or best-effort or higher message waiting at
701 client; in this case, we try to solicit more */
702 GNUNET_log (
703 GNUNET_ERROR_TYPE_DEBUG,
704 "Soliciting messages (excess %d, maxpc %d, message size %u, deadline %s)\n",
705 excess,
706 maxpc,
707 (unsigned int) msize,
708 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
709 min_deadline),
710 GNUNET_YES));
711 solicit_messages (session, msize);
712 if (msize > 0)
713 {
714 /* if there is data to send, just not yet, make sure we do transmit
715 * it once the deadline is reached */
716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
717 "Corking until %s\n",
718 GNUNET_STRINGS_relative_time_to_string (
719 GNUNET_TIME_absolute_get_remaining (min_deadline),
720 GNUNET_YES));
721 if (NULL != session->cork_task)
722 GNUNET_SCHEDULER_cancel (session->cork_task);
723 session->cork_task =
724 GNUNET_SCHEDULER_add_at (min_deadline, &pop_cork_task, session);
725 }
726 else
727 { 693 {
728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 694 /* not enough ready yet (tiny message & cork possible), or no messages at all,
729 "Queue empty, waiting for solicitations\n"); 695 and either excess bandwidth or best-effort or higher message waiting at
696 client; in this case, we try to solicit more */
697 GNUNET_log(
698 GNUNET_ERROR_TYPE_DEBUG,
699 "Soliciting messages (excess %d, maxpc %d, message size %u, deadline %s)\n",
700 excess,
701 maxpc,
702 (unsigned int)msize,
703 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining(
704 min_deadline),
705 GNUNET_YES));
706 solicit_messages(session, msize);
707 if (msize > 0)
708 {
709 /* if there is data to send, just not yet, make sure we do transmit
710 * it once the deadline is reached */
711 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
712 "Corking until %s\n",
713 GNUNET_STRINGS_relative_time_to_string(
714 GNUNET_TIME_absolute_get_remaining(min_deadline),
715 GNUNET_YES));
716 if (NULL != session->cork_task)
717 GNUNET_SCHEDULER_cancel(session->cork_task);
718 session->cork_task =
719 GNUNET_SCHEDULER_add_at(min_deadline, &pop_cork_task, session);
720 }
721 else
722 {
723 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
724 "Queue empty, waiting for solicitations\n");
725 }
726 return;
730 } 727 }
731 return; 728 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
732 } 729 "Building combined plaintext buffer to transmit message!\n");
733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
734 "Building combined plaintext buffer to transmit message!\n");
735 /* create plaintext buffer of all messages (that fit), encrypt and 730 /* create plaintext buffer of all messages (that fit), encrypt and
736 transmit */ 731 transmit */
737 { 732 {
@@ -742,33 +737,33 @@ try_transmission (struct Session *session)
742 737
743 used = 0; 738 used = 0;
744 while ((NULL != (pos = session->sme_head)) && (used + pos->size <= msize)) 739 while ((NULL != (pos = session->sme_head)) && (used + pos->size <= msize))
745 { 740 {
746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 741 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
747 "Adding message of type %d (%d/%d) to payload for %s\n", 742 "Adding message of type %d (%d/%d) to payload for %s\n",
748 ntohs (((const struct GNUNET_MessageHeader *) &pos[1])->type), 743 ntohs(((const struct GNUNET_MessageHeader *)&pos[1])->type),
749 pos->is_typemap, 744 pos->is_typemap,
750 pos->is_typemap_confirm, 745 pos->is_typemap_confirm,
751 GNUNET_i2s (session->peer)); 746 GNUNET_i2s(session->peer));
752 GNUNET_memcpy (&pbuf[used], &pos[1], pos->size); 747 GNUNET_memcpy(&pbuf[used], &pos[1], pos->size);
753 used += pos->size; 748 used += pos->size;
754 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, pos); 749 GNUNET_CONTAINER_DLL_remove(session->sme_head, session->sme_tail, pos);
755 GNUNET_free (pos); 750 GNUNET_free(pos);
756 } 751 }
757 /* compute average payload size */ 752 /* compute average payload size */
758 total_bytes += used; 753 total_bytes += used;
759 total_msgs++; 754 total_msgs++;
760 if (0 == total_msgs) 755 if (0 == total_msgs)
761 { 756 {
762 /* 2^32 messages, wrap around... */ 757 /* 2^32 messages, wrap around... */
763 total_msgs = 1; 758 total_msgs = 1;
764 total_bytes = used; 759 total_bytes = used;
765 } 760 }
766 GNUNET_STATISTICS_set (GSC_stats, 761 GNUNET_STATISTICS_set(GSC_stats,
767 "# avg payload per encrypted message", 762 "# avg payload per encrypted message",
768 total_bytes / total_msgs, 763 total_bytes / total_msgs,
769 GNUNET_NO); 764 GNUNET_NO);
770 /* now actually transmit... */ 765 /* now actually transmit... */
771 GSC_KX_encrypt_and_transmit (session->kx, pbuf, used); 766 GSC_KX_encrypt_and_transmit(session->kx, pbuf, used);
772 } 767 }
773} 768}
774 769
@@ -783,36 +778,36 @@ try_transmission (struct Session *session)
783 * @return always #GNUNET_OK 778 * @return always #GNUNET_OK
784 */ 779 */
785static int 780static int
786do_restart_typemap_message (void *cls, 781do_restart_typemap_message(void *cls,
787 const struct GNUNET_PeerIdentity *key, 782 const struct GNUNET_PeerIdentity *key,
788 void *value) 783 void *value)
789{ 784{
790 const struct GNUNET_MessageHeader *hdr = cls; 785 const struct GNUNET_MessageHeader *hdr = cls;
791 struct Session *session = value; 786 struct Session *session = value;
792 struct SessionMessageEntry *sme; 787 struct SessionMessageEntry *sme;
793 uint16_t size; 788 uint16_t size;
794 789
795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 790 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
796 "Restarting sending TYPEMAP to %s\n", 791 "Restarting sending TYPEMAP to %s\n",
797 GNUNET_i2s (session->peer)); 792 GNUNET_i2s(session->peer));
798 size = ntohs (hdr->size); 793 size = ntohs(hdr->size);
799 for (sme = session->sme_head; NULL != sme; sme = sme->next) 794 for (sme = session->sme_head; NULL != sme; sme = sme->next)
800 {
801 if (GNUNET_YES == sme->is_typemap)
802 { 795 {
803 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme); 796 if (GNUNET_YES == sme->is_typemap)
804 GNUNET_free (sme); 797 {
805 break; 798 GNUNET_CONTAINER_DLL_remove(session->sme_head, session->sme_tail, sme);
799 GNUNET_free(sme);
800 break;
801 }
806 } 802 }
807 } 803 sme = GNUNET_malloc(sizeof(struct SessionMessageEntry) + size);
808 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size);
809 sme->is_typemap = GNUNET_YES; 804 sme->is_typemap = GNUNET_YES;
810 GNUNET_memcpy (&sme[1], hdr, size); 805 GNUNET_memcpy(&sme[1], hdr, size);
811 sme->size = size; 806 sme->size = size;
812 sme->priority = GNUNET_MQ_PRIO_CRITICAL_CONTROL; 807 sme->priority = GNUNET_MQ_PRIO_CRITICAL_CONTROL;
813 GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, sme); 808 GNUNET_CONTAINER_DLL_insert(session->sme_head, session->sme_tail, sme);
814 try_transmission (session); 809 try_transmission(session);
815 start_typemap_task (session); 810 start_typemap_task(session);
816 return GNUNET_OK; 811 return GNUNET_OK;
817} 812}
818 813
@@ -824,13 +819,13 @@ do_restart_typemap_message (void *cls,
824 * @param msg message to transmit 819 * @param msg message to transmit
825 */ 820 */
826void 821void
827GSC_SESSIONS_broadcast_typemap (const struct GNUNET_MessageHeader *msg) 822GSC_SESSIONS_broadcast_typemap(const struct GNUNET_MessageHeader *msg)
828{ 823{
829 if (NULL == sessions) 824 if (NULL == sessions)
830 return; 825 return;
831 GNUNET_CONTAINER_multipeermap_iterate (sessions, 826 GNUNET_CONTAINER_multipeermap_iterate(sessions,
832 &do_restart_typemap_message, 827 &do_restart_typemap_message,
833 (void *) msg); 828 (void *)msg);
834} 829}
835 830
836 831
@@ -842,17 +837,17 @@ GSC_SESSIONS_broadcast_typemap (const struct GNUNET_MessageHeader *msg)
842 * @param pid identity of peer ready to receive data 837 * @param pid identity of peer ready to receive data
843 */ 838 */
844void 839void
845GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid) 840GSC_SESSIONS_solicit(const struct GNUNET_PeerIdentity *pid)
846{ 841{
847 struct Session *session; 842 struct Session *session;
848 843
849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 844 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
850 "Transport solicits for %s\n", 845 "Transport solicits for %s\n",
851 GNUNET_i2s (pid)); 846 GNUNET_i2s(pid));
852 session = find_session (pid); 847 session = find_session(pid);
853 if (NULL == session) 848 if (NULL == session)
854 return; 849 return;
855 try_transmission (session); 850 try_transmission(session);
856} 851}
857 852
858 853
@@ -865,43 +860,43 @@ GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid)
865 * @param priority how important is this message 860 * @param priority how important is this message
866 */ 861 */
867void 862void
868GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, 863GSC_SESSIONS_transmit(struct GSC_ClientActiveRequest *car,
869 const struct GNUNET_MessageHeader *msg, 864 const struct GNUNET_MessageHeader *msg,
870 enum GNUNET_MQ_PriorityPreferences priority) 865 enum GNUNET_MQ_PriorityPreferences priority)
871{ 866{
872 struct Session *session; 867 struct Session *session;
873 struct SessionMessageEntry *sme; 868 struct SessionMessageEntry *sme;
874 struct SessionMessageEntry *pos; 869 struct SessionMessageEntry *pos;
875 size_t msize; 870 size_t msize;
876 871
877 session = find_session (&car->target); 872 session = find_session(&car->target);
878 if (NULL == session) 873 if (NULL == session)
879 return; 874 return;
880 msize = ntohs (msg->size); 875 msize = ntohs(msg->size);
881 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + msize); 876 sme = GNUNET_malloc(sizeof(struct SessionMessageEntry) + msize);
882 GNUNET_memcpy (&sme[1], msg, msize); 877 GNUNET_memcpy(&sme[1], msg, msize);
883 sme->size = msize; 878 sme->size = msize;
884 sme->priority = priority; 879 sme->priority = priority;
885 if (0 != (GNUNET_MQ_PREF_CORK_ALLOWED & priority)) 880 if (0 != (GNUNET_MQ_PREF_CORK_ALLOWED & priority))
886 { 881 {
887 sme->deadline = 882 sme->deadline =
888 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY); 883 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_MAX_CORK_DELAY);
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 884 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
890 "Mesage corked, delaying transmission\n"); 885 "Mesage corked, delaying transmission\n");
891 } 886 }
892 pos = session->sme_head; 887 pos = session->sme_head;
893 while ((NULL != pos) && (pos->priority >= sme->priority)) 888 while ((NULL != pos) && (pos->priority >= sme->priority))
894 pos = pos->next; 889 pos = pos->next;
895 if (NULL == pos) 890 if (NULL == pos)
896 GNUNET_CONTAINER_DLL_insert_tail (session->sme_head, 891 GNUNET_CONTAINER_DLL_insert_tail(session->sme_head,
892 session->sme_tail,
893 sme);
894 else
895 GNUNET_CONTAINER_DLL_insert_after(session->sme_head,
897 session->sme_tail, 896 session->sme_tail,
897 pos->prev,
898 sme); 898 sme);
899 else 899 try_transmission(session);
900 GNUNET_CONTAINER_DLL_insert_after (session->sme_head,
901 session->sme_tail,
902 pos->prev,
903 sme);
904 try_transmission (session);
905} 900}
906 901
907 902
@@ -913,54 +908,54 @@ GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
913 * @param msg typemap update message 908 * @param msg typemap update message
914 */ 909 */
915void 910void
916GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, 911GSC_SESSIONS_set_typemap(const struct GNUNET_PeerIdentity *peer,
917 const struct GNUNET_MessageHeader *msg) 912 const struct GNUNET_MessageHeader *msg)
918{ 913{
919 struct Session *session; 914 struct Session *session;
920 struct GSC_TypeMap *nmap; 915 struct GSC_TypeMap *nmap;
921 struct SessionMessageEntry *sme; 916 struct SessionMessageEntry *sme;
922 struct TypeMapConfirmationMessage *tmc; 917 struct TypeMapConfirmationMessage *tmc;
923 918
924 nmap = GSC_TYPEMAP_get_from_message (msg); 919 nmap = GSC_TYPEMAP_get_from_message(msg);
925 if (NULL == nmap) 920 if (NULL == nmap)
926 { 921 {
927 GNUNET_break_op (0); 922 GNUNET_break_op(0);
928 return; /* malformed */ 923 return; /* malformed */
929 } 924 }
930 session = find_session (peer); 925 session = find_session(peer);
931 if (NULL == session) 926 if (NULL == session)
932 { 927 {
933 GSC_TYPEMAP_destroy (nmap); 928 GSC_TYPEMAP_destroy(nmap);
934 GNUNET_break (0); 929 GNUNET_break(0);
935 return; 930 return;
936 } 931 }
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 932 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
938 "Received TYPEMAP from %s\n", 933 "Received TYPEMAP from %s\n",
939 GNUNET_i2s (session->peer)); 934 GNUNET_i2s(session->peer));
940 for (sme = session->sme_head; NULL != sme; sme = sme->next) 935 for (sme = session->sme_head; NULL != sme; sme = sme->next)
941 {
942 if (GNUNET_YES == sme->is_typemap_confirm)
943 { 936 {
944 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme); 937 if (GNUNET_YES == sme->is_typemap_confirm)
945 GNUNET_free (sme); 938 {
946 break; 939 GNUNET_CONTAINER_DLL_remove(session->sme_head, session->sme_tail, sme);
940 GNUNET_free(sme);
941 break;
942 }
947 } 943 }
948 } 944 sme = GNUNET_malloc(sizeof(struct SessionMessageEntry) +
949 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + 945 sizeof(struct TypeMapConfirmationMessage));
950 sizeof (struct TypeMapConfirmationMessage)); 946 sme->deadline = GNUNET_TIME_absolute_get();
951 sme->deadline = GNUNET_TIME_absolute_get (); 947 sme->size = sizeof(struct TypeMapConfirmationMessage);
952 sme->size = sizeof (struct TypeMapConfirmationMessage);
953 sme->priority = GNUNET_MQ_PRIO_CRITICAL_CONTROL; 948 sme->priority = GNUNET_MQ_PRIO_CRITICAL_CONTROL;
954 sme->is_typemap_confirm = GNUNET_YES; 949 sme->is_typemap_confirm = GNUNET_YES;
955 tmc = (struct TypeMapConfirmationMessage *) &sme[1]; 950 tmc = (struct TypeMapConfirmationMessage *)&sme[1];
956 tmc->header.size = htons (sizeof (struct TypeMapConfirmationMessage)); 951 tmc->header.size = htons(sizeof(struct TypeMapConfirmationMessage));
957 tmc->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP); 952 tmc->header.type = htons(GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP);
958 tmc->reserved = htonl (0); 953 tmc->reserved = htonl(0);
959 GSC_TYPEMAP_hash (nmap, &tmc->tm_hash); 954 GSC_TYPEMAP_hash(nmap, &tmc->tm_hash);
960 GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, sme); 955 GNUNET_CONTAINER_DLL_insert(session->sme_head, session->sme_tail, sme);
961 try_transmission (session); 956 try_transmission(session);
962 GSC_CLIENTS_notify_clients_about_neighbour (peer, session->tmap, nmap); 957 GSC_CLIENTS_notify_clients_about_neighbour(peer, session->tmap, nmap);
963 GSC_TYPEMAP_destroy (session->tmap); 958 GSC_TYPEMAP_destroy(session->tmap);
964 session->tmap = nmap; 959 session->tmap = nmap;
965} 960}
966 961
@@ -974,21 +969,21 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
974 * @param type type of the message 969 * @param type type of the message
975 */ 970 */
976void 971void
977GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, 972GSC_SESSIONS_add_to_typemap(const struct GNUNET_PeerIdentity *peer,
978 uint16_t type) 973 uint16_t type)
979{ 974{
980 struct Session *session; 975 struct Session *session;
981 struct GSC_TypeMap *nmap; 976 struct GSC_TypeMap *nmap;
982 977
983 if (0 == memcmp (peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 978 if (0 == memcmp(peer, &GSC_my_identity, sizeof(struct GNUNET_PeerIdentity)))
984 return; 979 return;
985 session = find_session (peer); 980 session = find_session(peer);
986 GNUNET_assert (NULL != session); 981 GNUNET_assert(NULL != session);
987 if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, &type, 1)) 982 if (GNUNET_YES == GSC_TYPEMAP_test_match(session->tmap, &type, 1))
988 return; /* already in it */ 983 return; /* already in it */
989 nmap = GSC_TYPEMAP_extend (session->tmap, &type, 1); 984 nmap = GSC_TYPEMAP_extend(session->tmap, &type, 1);
990 GSC_CLIENTS_notify_clients_about_neighbour (peer, session->tmap, nmap); 985 GSC_CLIENTS_notify_clients_about_neighbour(peer, session->tmap, nmap);
991 GSC_TYPEMAP_destroy (session->tmap); 986 GSC_TYPEMAP_destroy(session->tmap);
992 session->tmap = nmap; 987 session->tmap = nmap;
993} 988}
994 989
@@ -997,9 +992,9 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
997 * Initialize sessions subsystem. 992 * Initialize sessions subsystem.
998 */ 993 */
999void 994void
1000GSC_SESSIONS_init () 995GSC_SESSIONS_init()
1001{ 996{
1002 sessions = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); 997 sessions = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES);
1003} 998}
1004 999
1005 1000
@@ -1013,13 +1008,13 @@ GSC_SESSIONS_init ()
1013 * @return #GNUNET_OK (continue to iterate) 1008 * @return #GNUNET_OK (continue to iterate)
1014 */ 1009 */
1015static int 1010static int
1016free_session_helper (void *cls, 1011free_session_helper(void *cls,
1017 const struct GNUNET_PeerIdentity *key, 1012 const struct GNUNET_PeerIdentity *key,
1018 void *value) 1013 void *value)
1019{ 1014{
1020 /* struct Session *session = value; */ 1015 /* struct Session *session = value; */
1021 1016
1022 GSC_SESSIONS_end (key); 1017 GSC_SESSIONS_end(key);
1023 return GNUNET_OK; 1018 return GNUNET_OK;
1024} 1019}
1025 1020
@@ -1028,16 +1023,16 @@ free_session_helper (void *cls,
1028 * Shutdown sessions subsystem. 1023 * Shutdown sessions subsystem.
1029 */ 1024 */
1030void 1025void
1031GSC_SESSIONS_done () 1026GSC_SESSIONS_done()
1032{ 1027{
1033 if (NULL != sessions) 1028 if (NULL != sessions)
1034 { 1029 {
1035 GNUNET_CONTAINER_multipeermap_iterate (sessions, 1030 GNUNET_CONTAINER_multipeermap_iterate(sessions,
1036 &free_session_helper, 1031 &free_session_helper,
1037 NULL); 1032 NULL);
1038 GNUNET_CONTAINER_multipeermap_destroy (sessions); 1033 GNUNET_CONTAINER_multipeermap_destroy(sessions);
1039 sessions = NULL; 1034 sessions = NULL;
1040 } 1035 }
1041} 1036}
1042 1037
1043/* end of gnunet-service-core_sessions.c */ 1038/* end of gnunet-service-core_sessions.c */
diff --git a/src/core/gnunet-service-core_sessions.h b/src/core/gnunet-service-core_sessions.h
index e92ce0962..ba0f0a0db 100644
--- a/src/core/gnunet-service-core_sessions.h
+++ b/src/core/gnunet-service-core_sessions.h
@@ -16,7 +16,7 @@
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 core/gnunet-service-core_neighbours.h 22 * @file core/gnunet-service-core_neighbours.h
@@ -37,8 +37,8 @@
37 * @param kx key exchange that completed 37 * @param kx key exchange that completed
38 */ 38 */
39void 39void
40GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, 40GSC_SESSIONS_create(const struct GNUNET_PeerIdentity *peer,
41 struct GSC_KeyExchangeInfo *kx); 41 struct GSC_KeyExchangeInfo *kx);
42 42
43 43
44/** 44/**
@@ -49,7 +49,7 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
49 * @param peer peer that is now connected 49 * @param peer peer that is now connected
50 */ 50 */
51void 51void
52GSC_SESSIONS_reinit (const struct GNUNET_PeerIdentity *peer); 52GSC_SESSIONS_reinit(const struct GNUNET_PeerIdentity *peer);
53 53
54 54
55/** 55/**
@@ -60,8 +60,8 @@ GSC_SESSIONS_reinit (const struct GNUNET_PeerIdentity *peer);
60 * @param msg confirmation message we received 60 * @param msg confirmation message we received
61 */ 61 */
62void 62void
63GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer, 63GSC_SESSIONS_confirm_typemap(const struct GNUNET_PeerIdentity *peer,
64 const struct GNUNET_MessageHeader *msg); 64 const struct GNUNET_MessageHeader *msg);
65 65
66 66
67/** 67/**
@@ -71,7 +71,7 @@ GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer,
71 * @param pid identity of peer to kill session with 71 * @param pid identity of peer to kill session with
72 */ 72 */
73void 73void
74GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid); 74GSC_SESSIONS_end(const struct GNUNET_PeerIdentity *pid);
75 75
76 76
77/** 77/**
@@ -82,7 +82,7 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid);
82 * @param pid identity of peer ready to receive data 82 * @param pid identity of peer ready to receive data
83 */ 83 */
84void 84void
85GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid); 85GSC_SESSIONS_solicit(const struct GNUNET_PeerIdentity *pid);
86 86
87 87
88/** 88/**
@@ -95,7 +95,7 @@ GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid);
95 * have been invoked on it 95 * have been invoked on it
96 */ 96 */
97void 97void
98GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car); 98GSC_SESSIONS_queue_request(struct GSC_ClientActiveRequest *car);
99 99
100 100
101/** 101/**
@@ -105,7 +105,7 @@ GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car);
105 * the caller (CLIENTS sysbsystem) 105 * the caller (CLIENTS sysbsystem)
106 */ 106 */
107void 107void
108GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car); 108GSC_SESSIONS_dequeue_request(struct GSC_ClientActiveRequest *car);
109 109
110 110
111/** 111/**
@@ -117,9 +117,9 @@ GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car);
117 * @param priority how important is this message 117 * @param priority how important is this message
118 */ 118 */
119void 119void
120GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, 120GSC_SESSIONS_transmit(struct GSC_ClientActiveRequest *car,
121 const struct GNUNET_MessageHeader *msg, 121 const struct GNUNET_MessageHeader *msg,
122 enum GNUNET_MQ_PriorityPreferences priority); 122 enum GNUNET_MQ_PriorityPreferences priority);
123 123
124 124
125/** 125/**
@@ -129,7 +129,7 @@ GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
129 * @param msg message to transmit 129 * @param msg message to transmit
130 */ 130 */
131void 131void
132GSC_SESSIONS_broadcast_typemap (const struct GNUNET_MessageHeader *msg); 132GSC_SESSIONS_broadcast_typemap(const struct GNUNET_MessageHeader *msg);
133 133
134 134
135/** 135/**
@@ -138,7 +138,7 @@ GSC_SESSIONS_broadcast_typemap (const struct GNUNET_MessageHeader *msg);
138 * @param client the new client 138 * @param client the new client
139 */ 139 */
140void 140void
141GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client); 141GSC_SESSIONS_notify_client_about_sessions(struct GSC_Client *client);
142 142
143 143
144/** 144/**
@@ -149,8 +149,8 @@ GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client);
149 * @param msg typemap update message 149 * @param msg typemap update message
150 */ 150 */
151void 151void
152GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, 152GSC_SESSIONS_set_typemap(const struct GNUNET_PeerIdentity *peer,
153 const struct GNUNET_MessageHeader *msg); 153 const struct GNUNET_MessageHeader *msg);
154 154
155 155
156/** 156/**
@@ -162,22 +162,22 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
162 * @param type type of the message 162 * @param type type of the message
163 */ 163 */
164void 164void
165GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, 165GSC_SESSIONS_add_to_typemap(const struct GNUNET_PeerIdentity *peer,
166 uint16_t type); 166 uint16_t type);
167 167
168 168
169/** 169/**
170 * Initialize sessions subsystem. 170 * Initialize sessions subsystem.
171 */ 171 */
172void 172void
173GSC_SESSIONS_init (void); 173GSC_SESSIONS_init(void);
174 174
175 175
176/** 176/**
177 * Shutdown sessions subsystem. 177 * Shutdown sessions subsystem.
178 */ 178 */
179void 179void
180GSC_SESSIONS_done (void); 180GSC_SESSIONS_done(void);
181 181
182 182
183#endif 183#endif
diff --git a/src/core/gnunet-service-core_typemap.c b/src/core/gnunet-service-core_typemap.c
index 9dd3c71c8..55cd9fb14 100644
--- a/src/core/gnunet-service-core_typemap.c
+++ b/src/core/gnunet-service-core_typemap.c
@@ -16,7 +16,7 @@
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 core/gnunet-service-core_typemap.c 22 * @file core/gnunet-service-core_typemap.c
@@ -36,8 +36,7 @@
36 * A type map describing which messages a given neighbour is able 36 * A type map describing which messages a given neighbour is able
37 * to process. 37 * to process.
38 */ 38 */
39struct GSC_TypeMap 39struct GSC_TypeMap {
40{
41 uint32_t bits[(UINT16_MAX + 1) / 32]; 40 uint32_t bits[(UINT16_MAX + 1) / 32];
42}; 41};
43 42
@@ -67,7 +66,7 @@ static int hash_current;
67 * Our type map changed, recompute its hash. 66 * Our type map changed, recompute its hash.
68 */ 67 */
69static void 68static void
70rehash_typemap () 69rehash_typemap()
71{ 70{
72 hash_current = GNUNET_NO; 71 hash_current = GNUNET_NO;
73} 72}
@@ -80,9 +79,9 @@ rehash_typemap ()
80 * @param hc where to store the hash code 79 * @param hc where to store the hash code
81 */ 80 */
82void 81void
83GSC_TYPEMAP_hash (const struct GSC_TypeMap *tm, struct GNUNET_HashCode *hc) 82GSC_TYPEMAP_hash(const struct GSC_TypeMap *tm, struct GNUNET_HashCode *hc)
84{ 83{
85 GNUNET_CRYPTO_hash (tm, sizeof (struct GSC_TypeMap), hc); 84 GNUNET_CRYPTO_hash(tm, sizeof(struct GSC_TypeMap), hc);
86} 85}
87 86
88 87
@@ -93,16 +92,16 @@ GSC_TYPEMAP_hash (const struct GSC_TypeMap *tm, struct GNUNET_HashCode *hc)
93 * @return #GNUNET_YES if the hash matches, #GNUNET_NO if not 92 * @return #GNUNET_YES if the hash matches, #GNUNET_NO if not
94 */ 93 */
95int 94int
96GSC_TYPEMAP_check_hash (const struct GNUNET_HashCode *hc) 95GSC_TYPEMAP_check_hash(const struct GNUNET_HashCode *hc)
97{ 96{
98 if (GNUNET_NO == hash_current) 97 if (GNUNET_NO == hash_current)
99 { 98 {
100 GSC_TYPEMAP_hash (&my_type_map, &my_tm_hash); 99 GSC_TYPEMAP_hash(&my_type_map, &my_tm_hash);
101 hash_current = GNUNET_YES; 100 hash_current = GNUNET_YES;
102 } 101 }
103 return (0 == memcmp (hc, &my_tm_hash, sizeof (struct GNUNET_HashCode))) 102 return (0 == memcmp(hc, &my_tm_hash, sizeof(struct GNUNET_HashCode)))
104 ? GNUNET_YES 103 ? GNUNET_YES
105 : GNUNET_NO; 104 : GNUNET_NO;
106} 105}
107 106
108 107
@@ -112,39 +111,39 @@ GSC_TYPEMAP_check_hash (const struct GNUNET_HashCode *hc)
112 * @return this peers current type map message. 111 * @return this peers current type map message.
113 */ 112 */
114struct GNUNET_MessageHeader * 113struct GNUNET_MessageHeader *
115GSC_TYPEMAP_compute_type_map_message () 114GSC_TYPEMAP_compute_type_map_message()
116{ 115{
117 char *tmp; 116 char *tmp;
118 uLongf dlen; 117 uLongf dlen;
119 struct GNUNET_MessageHeader *hdr; 118 struct GNUNET_MessageHeader *hdr;
120 119
121#ifdef compressBound 120#ifdef compressBound
122 dlen = compressBound (sizeof (my_type_map)); 121 dlen = compressBound(sizeof(my_type_map));
123#else 122#else
124 dlen = sizeof (my_type_map) + (sizeof (my_type_map) / 100) + 20; 123 dlen = sizeof(my_type_map) + (sizeof(my_type_map) / 100) + 20;
125 /* documentation says 100.1% oldSize + 12 bytes, but we 124 /* documentation says 100.1% oldSize + 12 bytes, but we
126 * should be able to overshoot by more to be safe */ 125 * should be able to overshoot by more to be safe */
127#endif 126#endif
128 hdr = GNUNET_malloc (dlen + sizeof (struct GNUNET_MessageHeader)); 127 hdr = GNUNET_malloc(dlen + sizeof(struct GNUNET_MessageHeader));
129 tmp = (char *) &hdr[1]; 128 tmp = (char *)&hdr[1];
130 if ((Z_OK != compress2 ((Bytef *) tmp, 129 if ((Z_OK != compress2((Bytef *)tmp,
131 &dlen, 130 &dlen,
132 (const Bytef *) &my_type_map, 131 (const Bytef *)&my_type_map,
133 sizeof (my_type_map), 132 sizeof(my_type_map),
134 9)) || 133 9)) ||
135 (dlen >= sizeof (my_type_map))) 134 (dlen >= sizeof(my_type_map)))
136 { 135 {
137 /* compression failed, use uncompressed map */ 136 /* compression failed, use uncompressed map */
138 dlen = sizeof (my_type_map); 137 dlen = sizeof(my_type_map);
139 GNUNET_memcpy (tmp, &my_type_map, sizeof (my_type_map)); 138 GNUNET_memcpy(tmp, &my_type_map, sizeof(my_type_map));
140 hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP); 139 hdr->type = htons(GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP);
141 } 140 }
142 else 141 else
143 { 142 {
144 /* compression worked, use compressed map */ 143 /* compression worked, use compressed map */
145 hdr->type = htons (GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP); 144 hdr->type = htons(GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP);
146 } 145 }
147 hdr->size = htons ((uint16_t) dlen + sizeof (struct GNUNET_MessageHeader)); 146 hdr->size = htons((uint16_t)dlen + sizeof(struct GNUNET_MessageHeader));
148 return hdr; 147 return hdr;
149} 148}
150 149
@@ -156,50 +155,52 @@ GSC_TYPEMAP_compute_type_map_message ()
156 * @return NULL on error 155 * @return NULL on error
157 */ 156 */
158struct GSC_TypeMap * 157struct GSC_TypeMap *
159GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg) 158GSC_TYPEMAP_get_from_message(const struct GNUNET_MessageHeader *msg)
160{ 159{
161 struct GSC_TypeMap *ret; 160 struct GSC_TypeMap *ret;
162 uint16_t size; 161 uint16_t size;
163 uLongf dlen; 162 uLongf dlen;
164 163
165 size = ntohs (msg->size); 164 size = ntohs(msg->size);
166 switch (ntohs (msg->type)) 165 switch (ntohs(msg->type))
167 {
168 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
169 GNUNET_STATISTICS_update (GSC_stats,
170 gettext_noop ("# type maps received"),
171 1,
172 GNUNET_NO);
173 if (size != sizeof (struct GSC_TypeMap))
174 { 166 {
175 GNUNET_break_op (0); 167 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
168 GNUNET_STATISTICS_update(GSC_stats,
169 gettext_noop("# type maps received"),
170 1,
171 GNUNET_NO);
172 if (size != sizeof(struct GSC_TypeMap))
173 {
174 GNUNET_break_op(0);
175 return NULL;
176 }
177 ret = GNUNET_new(struct GSC_TypeMap);
178 GNUNET_memcpy(ret, &msg[1], sizeof(struct GSC_TypeMap));
179 return ret;
180
181 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
182 GNUNET_STATISTICS_update(GSC_stats,
183 gettext_noop("# type maps received"),
184 1,
185 GNUNET_NO);
186 ret = GNUNET_new(struct GSC_TypeMap);
187 dlen = sizeof(struct GSC_TypeMap);
188 if ((Z_OK != uncompress((Bytef *)ret,
189 &dlen,
190 (const Bytef *)&msg[1],
191 (uLong)size)) ||
192 (dlen != sizeof(struct GSC_TypeMap)))
193 {
194 GNUNET_break_op(0);
195 GNUNET_free(ret);
196 return NULL;
197 }
198 return ret;
199
200 default:
201 GNUNET_break(0);
176 return NULL; 202 return NULL;
177 } 203 }
178 ret = GNUNET_new (struct GSC_TypeMap);
179 GNUNET_memcpy (ret, &msg[1], sizeof (struct GSC_TypeMap));
180 return ret;
181 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
182 GNUNET_STATISTICS_update (GSC_stats,
183 gettext_noop ("# type maps received"),
184 1,
185 GNUNET_NO);
186 ret = GNUNET_new (struct GSC_TypeMap);
187 dlen = sizeof (struct GSC_TypeMap);
188 if ((Z_OK != uncompress ((Bytef *) ret,
189 &dlen,
190 (const Bytef *) &msg[1],
191 (uLong) size)) ||
192 (dlen != sizeof (struct GSC_TypeMap)))
193 {
194 GNUNET_break_op (0);
195 GNUNET_free (ret);
196 return NULL;
197 }
198 return ret;
199 default:
200 GNUNET_break (0);
201 return NULL;
202 }
203} 204}
204 205
205 206
@@ -207,17 +208,17 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg)
207 * Send my type map to all connected peers (it got changed). 208 * Send my type map to all connected peers (it got changed).
208 */ 209 */
209static void 210static void
210broadcast_my_type_map () 211broadcast_my_type_map()
211{ 212{
212 struct GNUNET_MessageHeader *hdr; 213 struct GNUNET_MessageHeader *hdr;
213 214
214 hdr = GSC_TYPEMAP_compute_type_map_message (); 215 hdr = GSC_TYPEMAP_compute_type_map_message();
215 GNUNET_STATISTICS_update (GSC_stats, 216 GNUNET_STATISTICS_update(GSC_stats,
216 gettext_noop ("# updates to my type map"), 217 gettext_noop("# updates to my type map"),
217 1, 218 1,
218 GNUNET_NO); 219 GNUNET_NO);
219 GSC_SESSIONS_broadcast_typemap (hdr); 220 GSC_SESSIONS_broadcast_typemap(hdr);
220 GNUNET_free (hdr); 221 GNUNET_free(hdr);
221} 222}
222 223
223 224
@@ -228,26 +229,26 @@ broadcast_my_type_map ()
228 * @param tlen number of entries in @a types 229 * @param tlen number of entries in @a types
229 */ 230 */
230void 231void
231GSC_TYPEMAP_add (const uint16_t *types, unsigned int tlen) 232GSC_TYPEMAP_add(const uint16_t *types, unsigned int tlen)
232{ 233{
233 unsigned int i; 234 unsigned int i;
234 int changed; 235 int changed;
235 236
236 changed = GNUNET_NO; 237 changed = GNUNET_NO;
237 for (i = 0; i < tlen; i++) 238 for (i = 0; i < tlen; i++)
238 {
239 if (0 == map_counters[types[i]]++)
240 { 239 {
241 my_type_map.bits[types[i] / 32] |= (1 << (types[i] % 32)); 240 if (0 == map_counters[types[i]]++)
242 changed = GNUNET_YES; 241 {
242 my_type_map.bits[types[i] / 32] |= (1 << (types[i] % 32));
243 changed = GNUNET_YES;
244 }
243 } 245 }
244 }
245 if (GNUNET_YES == changed) 246 if (GNUNET_YES == changed)
246 { 247 {
247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Typemap changed, broadcasting!\n"); 248 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Typemap changed, broadcasting!\n");
248 rehash_typemap (); 249 rehash_typemap();
249 broadcast_my_type_map (); 250 broadcast_my_type_map();
250 } 251 }
251} 252}
252 253
253 254
@@ -258,24 +259,24 @@ GSC_TYPEMAP_add (const uint16_t *types, unsigned int tlen)
258 * @param tlen length of the @a types array 259 * @param tlen length of the @a types array
259 */ 260 */
260void 261void
261GSC_TYPEMAP_remove (const uint16_t *types, unsigned int tlen) 262GSC_TYPEMAP_remove(const uint16_t *types, unsigned int tlen)
262{ 263{
263 int changed; 264 int changed;
264 265
265 changed = GNUNET_NO; 266 changed = GNUNET_NO;
266 for (unsigned int i = 0; i < tlen; i++) 267 for (unsigned int i = 0; i < tlen; i++)
267 {
268 if (0 == --map_counters[types[i]])
269 { 268 {
270 my_type_map.bits[types[i] / 32] &= ~(1 << (types[i] % 32)); 269 if (0 == --map_counters[types[i]])
271 changed = GNUNET_YES; 270 {
271 my_type_map.bits[types[i] / 32] &= ~(1 << (types[i] % 32));
272 changed = GNUNET_YES;
273 }
272 } 274 }
273 }
274 if (GNUNET_YES == changed) 275 if (GNUNET_YES == changed)
275 { 276 {
276 rehash_typemap (); 277 rehash_typemap();
277 broadcast_my_type_map (); 278 broadcast_my_type_map();
278 } 279 }
279} 280}
280 281
281 282
@@ -289,9 +290,9 @@ GSC_TYPEMAP_remove (const uint16_t *types, unsigned int tlen)
289 * @return #GNUNET_YES if a type is in the map, #GNUNET_NO if not 290 * @return #GNUNET_YES if a type is in the map, #GNUNET_NO if not
290 */ 291 */
291int 292int
292GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, 293GSC_TYPEMAP_test_match(const struct GSC_TypeMap *tmap,
293 const uint16_t *types, 294 const uint16_t *types,
294 unsigned int tcnt) 295 unsigned int tcnt)
295{ 296{
296 if (NULL == tmap) 297 if (NULL == tmap)
297 return GNUNET_NO; 298 return GNUNET_NO;
@@ -313,15 +314,15 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
313 * @return updated type map (fresh copy) 314 * @return updated type map (fresh copy)
314 */ 315 */
315struct GSC_TypeMap * 316struct GSC_TypeMap *
316GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, 317GSC_TYPEMAP_extend(const struct GSC_TypeMap *tmap,
317 const uint16_t *types, 318 const uint16_t *types,
318 unsigned int tcnt) 319 unsigned int tcnt)
319{ 320{
320 struct GSC_TypeMap *ret; 321 struct GSC_TypeMap *ret;
321 322
322 ret = GNUNET_new (struct GSC_TypeMap); 323 ret = GNUNET_new(struct GSC_TypeMap);
323 if (NULL != tmap) 324 if (NULL != tmap)
324 GNUNET_memcpy (ret, tmap, sizeof (struct GSC_TypeMap)); 325 GNUNET_memcpy(ret, tmap, sizeof(struct GSC_TypeMap));
325 for (unsigned int i = 0; i < tcnt; i++) 326 for (unsigned int i = 0; i < tcnt; i++)
326 ret->bits[types[i] / 32] |= (1 << (types[i] % 32)); 327 ret->bits[types[i] / 32] |= (1 << (types[i] % 32));
327 return ret; 328 return ret;
@@ -334,9 +335,9 @@ GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap,
334 * @return an empty type map 335 * @return an empty type map
335 */ 336 */
336struct GSC_TypeMap * 337struct GSC_TypeMap *
337GSC_TYPEMAP_create () 338GSC_TYPEMAP_create()
338{ 339{
339 return GNUNET_new (struct GSC_TypeMap); 340 return GNUNET_new(struct GSC_TypeMap);
340} 341}
341 342
342 343
@@ -346,9 +347,9 @@ GSC_TYPEMAP_create ()
346 * @param tmap a type map 347 * @param tmap a type map
347 */ 348 */
348void 349void
349GSC_TYPEMAP_destroy (struct GSC_TypeMap *tmap) 350GSC_TYPEMAP_destroy(struct GSC_TypeMap *tmap)
350{ 351{
351 GNUNET_free (tmap); 352 GNUNET_free(tmap);
352} 353}
353 354
354 355
@@ -356,7 +357,7 @@ GSC_TYPEMAP_destroy (struct GSC_TypeMap *tmap)
356 * Initialize typemap subsystem. 357 * Initialize typemap subsystem.
357 */ 358 */
358void 359void
359GSC_TYPEMAP_init () 360GSC_TYPEMAP_init()
360{ 361{
361 /* nothing to do */ 362 /* nothing to do */
362} 363}
@@ -366,7 +367,7 @@ GSC_TYPEMAP_init ()
366 * Shutdown typemap subsystem. 367 * Shutdown typemap subsystem.
367 */ 368 */
368void 369void
369GSC_TYPEMAP_done () 370GSC_TYPEMAP_done()
370{ 371{
371 /* nothing to do */ 372 /* nothing to do */
372} 373}
diff --git a/src/core/gnunet-service-core_typemap.h b/src/core/gnunet-service-core_typemap.h
index 7b4f8d0f1..0fdb918f3 100644
--- a/src/core/gnunet-service-core_typemap.h
+++ b/src/core/gnunet-service-core_typemap.h
@@ -11,12 +11,12 @@
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 core/gnunet-service-core_typemap.h 22 * @file core/gnunet-service-core_typemap.h
@@ -42,8 +42,8 @@ struct GSC_TypeMap;
42 * @param tlen number of entries in @a types 42 * @param tlen number of entries in @a types
43 */ 43 */
44void 44void
45GSC_TYPEMAP_add (const uint16_t *types, 45GSC_TYPEMAP_add(const uint16_t *types,
46 unsigned int tlen); 46 unsigned int tlen);
47 47
48 48
49/** 49/**
@@ -53,8 +53,8 @@ GSC_TYPEMAP_add (const uint16_t *types,
53 * @param tlen number of entries in @a types 53 * @param tlen number of entries in @a types
54 */ 54 */
55void 55void
56GSC_TYPEMAP_remove (const uint16_t *types, 56GSC_TYPEMAP_remove(const uint16_t *types,
57 unsigned int tlen); 57 unsigned int tlen);
58 58
59 59
60/** 60/**
@@ -63,7 +63,7 @@ GSC_TYPEMAP_remove (const uint16_t *types,
63 * @return this peers current type map message. 63 * @return this peers current type map message.
64 */ 64 */
65struct GNUNET_MessageHeader * 65struct GNUNET_MessageHeader *
66GSC_TYPEMAP_compute_type_map_message (void); 66GSC_TYPEMAP_compute_type_map_message(void);
67 67
68 68
69/** 69/**
@@ -73,7 +73,7 @@ GSC_TYPEMAP_compute_type_map_message (void);
73 * @return #GNUNET_YES if the hash matches, #GNUNET_NO if not 73 * @return #GNUNET_YES if the hash matches, #GNUNET_NO if not
74 */ 74 */
75int 75int
76GSC_TYPEMAP_check_hash (const struct GNUNET_HashCode *hc); 76GSC_TYPEMAP_check_hash(const struct GNUNET_HashCode *hc);
77 77
78 78
79/** 79/**
@@ -83,8 +83,8 @@ GSC_TYPEMAP_check_hash (const struct GNUNET_HashCode *hc);
83 * @param hc where to store the hash code 83 * @param hc where to store the hash code
84 */ 84 */
85void 85void
86GSC_TYPEMAP_hash (const struct GSC_TypeMap *tm, 86GSC_TYPEMAP_hash(const struct GSC_TypeMap *tm,
87 struct GNUNET_HashCode *hc); 87 struct GNUNET_HashCode *hc);
88 88
89 89
90/** 90/**
@@ -96,7 +96,7 @@ GSC_TYPEMAP_hash (const struct GSC_TypeMap *tm,
96 * @return NULL on error 96 * @return NULL on error
97 */ 97 */
98struct GSC_TypeMap * 98struct GSC_TypeMap *
99GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg); 99GSC_TYPEMAP_get_from_message(const struct GNUNET_MessageHeader *msg);
100 100
101 101
102/** 102/**
@@ -109,9 +109,9 @@ GSC_TYPEMAP_get_from_message (const struct GNUNET_MessageHeader *msg);
109 * @return #GNUNET_YES if a type is in the map, #GNUNET_NO if not 109 * @return #GNUNET_YES if a type is in the map, #GNUNET_NO if not
110 */ 110 */
111int 111int
112GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap, 112GSC_TYPEMAP_test_match(const struct GSC_TypeMap *tmap,
113 const uint16_t *types, 113 const uint16_t *types,
114 unsigned int tcnt); 114 unsigned int tcnt);
115 115
116 116
117/** 117/**
@@ -123,9 +123,9 @@ GSC_TYPEMAP_test_match (const struct GSC_TypeMap *tmap,
123 * @return updated type map (fresh copy) 123 * @return updated type map (fresh copy)
124 */ 124 */
125struct GSC_TypeMap * 125struct GSC_TypeMap *
126GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap, 126GSC_TYPEMAP_extend(const struct GSC_TypeMap *tmap,
127 const uint16_t *types, 127 const uint16_t *types,
128 unsigned int tcnt); 128 unsigned int tcnt);
129 129
130 130
131/** 131/**
@@ -134,7 +134,7 @@ GSC_TYPEMAP_extend (const struct GSC_TypeMap *tmap,
134 * @return an empty type map 134 * @return an empty type map
135 */ 135 */
136struct GSC_TypeMap * 136struct GSC_TypeMap *
137GSC_TYPEMAP_create (void); 137GSC_TYPEMAP_create(void);
138 138
139 139
140/** 140/**
@@ -143,21 +143,21 @@ GSC_TYPEMAP_create (void);
143 * @param tmap a type map 143 * @param tmap a type map
144 */ 144 */
145void 145void
146GSC_TYPEMAP_destroy (struct GSC_TypeMap *tmap); 146GSC_TYPEMAP_destroy(struct GSC_TypeMap *tmap);
147 147
148 148
149/** 149/**
150 * Initialize typemap subsystem. 150 * Initialize typemap subsystem.
151 */ 151 */
152void 152void
153GSC_TYPEMAP_init (void); 153GSC_TYPEMAP_init(void);
154 154
155 155
156/** 156/**
157 * Shutdown typemap subsystem. 157 * Shutdown typemap subsystem.
158 */ 158 */
159void 159void
160GSC_TYPEMAP_done (void); 160GSC_TYPEMAP_done(void);
161 161
162#endif 162#endif
163/* end of gnunet-service-core_typemap.h */ 163/* end of gnunet-service-core_typemap.h */
diff --git a/src/core/test_core_api.c b/src/core/test_core_api.c
index 1e268c3a6..d29a5f04d 100644
--- a/src/core/test_core_api.c
+++ b/src/core/test_core_api.c
@@ -16,7 +16,7 @@
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 * @file core/test_core_api.c 21 * @file core/test_core_api.c
22 * @brief testcase for core_api.c 22 * @brief testcase for core_api.c
@@ -32,8 +32,7 @@
32 32
33#define MTYPE 12345 33#define MTYPE 12345
34 34
35struct PeerContext 35struct PeerContext {
36{
37 struct GNUNET_CONFIGURATION_Handle *cfg; 36 struct GNUNET_CONFIGURATION_Handle *cfg;
38 struct GNUNET_CORE_Handle *ch; 37 struct GNUNET_CORE_Handle *ch;
39 struct GNUNET_PeerIdentity id; 38 struct GNUNET_PeerIdentity id;
@@ -56,18 +55,18 @@ static int ok;
56 55
57#define OKPP \ 56#define OKPP \
58 do \ 57 do \
59 { \ 58 { \
60 ok++; \ 59 ok++; \
61 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, \ 60 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, \
62 "Now at stage %u at %s:%u\n", \ 61 "Now at stage %u at %s:%u\n", \
63 ok, \ 62 ok, \
64 __FILE__, \ 63 __FILE__, \
65 __LINE__); \ 64 __LINE__); \
66 } while (0) 65 } while (0)
67 66
68 67
69static void 68static void
70offer_hello_done (void *cls) 69offer_hello_done(void *cls)
71{ 70{
72 struct PeerContext *p = cls; 71 struct PeerContext *p = cls;
73 72
@@ -76,263 +75,264 @@ offer_hello_done (void *cls)
76 75
77 76
78static void 77static void
79process_hello (void *cls, const struct GNUNET_MessageHeader *message) 78process_hello(void *cls, const struct GNUNET_MessageHeader *message)
80{ 79{
81 struct PeerContext *p = cls; 80 struct PeerContext *p = cls;
82 81
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 82 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
84 "Received (my) HELLO from transport service\n"); 83 "Received (my) HELLO from transport service\n");
85 GNUNET_assert (message != NULL); 84 GNUNET_assert(message != NULL);
86 if ((p == &p1) && (NULL == p2.oh)) 85 if ((p == &p1) && (NULL == p2.oh))
87 p2.oh = 86 p2.oh =
88 GNUNET_TRANSPORT_offer_hello (p2.cfg, message, &offer_hello_done, &p2); 87 GNUNET_TRANSPORT_offer_hello(p2.cfg, message, &offer_hello_done, &p2);
89 if ((p == &p2) && (NULL == p1.oh)) 88 if ((p == &p2) && (NULL == p1.oh))
90 p1.oh = 89 p1.oh =
91 GNUNET_TRANSPORT_offer_hello (p1.cfg, message, &offer_hello_done, &p1); 90 GNUNET_TRANSPORT_offer_hello(p1.cfg, message, &offer_hello_done, &p1);
92} 91}
93 92
94 93
95static void 94static void
96terminate_peer (struct PeerContext *p) 95terminate_peer(struct PeerContext *p)
97{ 96{
98 if (NULL != p->ch) 97 if (NULL != p->ch)
99 { 98 {
100 GNUNET_CORE_disconnect (p->ch); 99 GNUNET_CORE_disconnect(p->ch);
101 p->ch = NULL; 100 p->ch = NULL;
102 } 101 }
103 if (NULL != p->ghh) 102 if (NULL != p->ghh)
104 { 103 {
105 GNUNET_TRANSPORT_hello_get_cancel (p->ghh); 104 GNUNET_TRANSPORT_hello_get_cancel(p->ghh);
106 p->ghh = NULL; 105 p->ghh = NULL;
107 } 106 }
108 if (NULL != p->oh) 107 if (NULL != p->oh)
109 { 108 {
110 GNUNET_TRANSPORT_offer_hello_cancel (p->oh); 109 GNUNET_TRANSPORT_offer_hello_cancel(p->oh);
111 p->oh = NULL; 110 p->oh = NULL;
112 } 111 }
113 if (NULL != p->ats_sh) 112 if (NULL != p->ats_sh)
114 { 113 {
115 GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh); 114 GNUNET_ATS_connectivity_suggest_cancel(p->ats_sh);
116 p->ats_sh = NULL; 115 p->ats_sh = NULL;
117 } 116 }
118 if (NULL != p->ats) 117 if (NULL != p->ats)
119 { 118 {
120 GNUNET_ATS_connectivity_done (p->ats); 119 GNUNET_ATS_connectivity_done(p->ats);
121 p->ats = NULL; 120 p->ats = NULL;
122 } 121 }
123} 122}
124 123
125 124
126static void 125static void
127terminate_task (void *cls) 126terminate_task(void *cls)
128{ 127{
129 GNUNET_assert (ok == 6); 128 GNUNET_assert(ok == 6);
130 terminate_peer (&p1); 129 terminate_peer(&p1);
131 terminate_peer (&p2); 130 terminate_peer(&p2);
132 ok = 0; 131 ok = 0;
133} 132}
134 133
135 134
136static void 135static void
137terminate_task_error (void *cls) 136terminate_task_error(void *cls)
138{ 137{
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ENDING ANGRILY %u\n", ok); 138 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "ENDING ANGRILY %u\n", ok);
140 GNUNET_break (0); 139 GNUNET_break(0);
141 terminate_peer (&p1); 140 terminate_peer(&p1);
142 terminate_peer (&p2); 141 terminate_peer(&p2);
143 ok = 42; 142 ok = 42;
144} 143}
145 144
146 145
147static void * 146static void *
148connect_notify (void *cls, 147connect_notify(void *cls,
149 const struct GNUNET_PeerIdentity *peer, 148 const struct GNUNET_PeerIdentity *peer,
150 struct GNUNET_MQ_Handle *mq) 149 struct GNUNET_MQ_Handle *mq)
151{ 150{
152 struct PeerContext *pc = cls; 151 struct PeerContext *pc = cls;
153 struct GNUNET_MQ_Envelope *env; 152 struct GNUNET_MQ_Envelope *env;
154 struct GNUNET_MessageHeader *msg; 153 struct GNUNET_MessageHeader *msg;
155 154
156 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) 155 if (0 == memcmp(&pc->id, peer, sizeof(struct GNUNET_PeerIdentity)))
157 return (void *) peer; 156 return (void *)peer;
158 GNUNET_assert (pc->connect_status == 0); 157 GNUNET_assert(pc->connect_status == 0);
159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 158 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
160 "Encrypted connection established to peer `%s'\n", 159 "Encrypted connection established to peer `%s'\n",
161 GNUNET_i2s (peer)); 160 GNUNET_i2s(peer));
162 pc->connect_status = 1; 161 pc->connect_status = 1;
163 if (pc == &p1) 162 if (pc == &p1)
164 { 163 {
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 164 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
166 "Asking core (1) for transmission to peer `%s'\n", 165 "Asking core (1) for transmission to peer `%s'\n",
167 GNUNET_i2s (&p2.id)); 166 GNUNET_i2s(&p2.id));
168 env = GNUNET_MQ_msg (msg, MTYPE); 167 env = GNUNET_MQ_msg(msg, MTYPE);
169 /* enable corking for this test */ 168 /* enable corking for this test */
170 GNUNET_MQ_env_set_options (env, 169 GNUNET_MQ_env_set_options(env,
171 GNUNET_MQ_PRIO_BEST_EFFORT | 170 GNUNET_MQ_PRIO_BEST_EFFORT |
172 GNUNET_MQ_PREF_CORK_ALLOWED); 171 GNUNET_MQ_PREF_CORK_ALLOWED);
173 /* now actually transmit message */ 172 /* now actually transmit message */
174 GNUNET_assert (ok == 4); 173 GNUNET_assert(ok == 4);
175 OKPP; 174 OKPP;
176 GNUNET_MQ_send (mq, env); 175 GNUNET_MQ_send(mq, env);
177 } 176 }
178 return (void *) peer; 177 return (void *)peer;
179} 178}
180 179
181 180
182static void 181static void
183disconnect_notify (void *cls, 182disconnect_notify(void *cls,
184 const struct GNUNET_PeerIdentity *peer, 183 const struct GNUNET_PeerIdentity *peer,
185 void *internal_cls) 184 void *internal_cls)
186{ 185{
187 struct PeerContext *pc = cls; 186 struct PeerContext *pc = cls;
188 187
189 if (0 == memcmp (&pc->id, peer, sizeof (struct GNUNET_PeerIdentity))) 188 if (0 == memcmp(&pc->id, peer, sizeof(struct GNUNET_PeerIdentity)))
190 return; 189 return;
191 pc->connect_status = 0; 190 pc->connect_status = 0;
192 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 191 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
193 "Encrypted connection to `%s' cut\n", 192 "Encrypted connection to `%s' cut\n",
194 GNUNET_i2s (peer)); 193 GNUNET_i2s(peer));
195} 194}
196 195
197 196
198static void 197static void
199handle_test (void *cls, const struct GNUNET_MessageHeader *message) 198handle_test(void *cls, const struct GNUNET_MessageHeader *message)
200{ 199{
201 const struct GNUNET_PeerIdentity *peer = cls; 200 const struct GNUNET_PeerIdentity *peer = cls;
202 201
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 202 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
204 "Receiving message from `%s'.\n", 203 "Receiving message from `%s'.\n",
205 GNUNET_i2s (peer)); 204 GNUNET_i2s(peer));
206 GNUNET_assert (ok == 5); 205 GNUNET_assert(ok == 5);
207 OKPP; 206 OKPP;
208 GNUNET_SCHEDULER_cancel (err_task); 207 GNUNET_SCHEDULER_cancel(err_task);
209 err_task = GNUNET_SCHEDULER_add_now (&terminate_task, NULL); 208 err_task = GNUNET_SCHEDULER_add_now(&terminate_task, NULL);
210} 209}
211 210
212 211
213static void 212static void
214init_notify (void *cls, const struct GNUNET_PeerIdentity *my_identity) 213init_notify(void *cls, const struct GNUNET_PeerIdentity *my_identity)
215{ 214{
216 struct PeerContext *p = cls; 215 struct PeerContext *p = cls;
217 struct GNUNET_MQ_MessageHandler handlers[] = 216 struct GNUNET_MQ_MessageHandler handlers[] =
218 {GNUNET_MQ_hd_fixed_size (test, MTYPE, struct GNUNET_MessageHeader, NULL), 217 { GNUNET_MQ_hd_fixed_size(test, MTYPE, struct GNUNET_MessageHeader, NULL),
219 GNUNET_MQ_handler_end ()}; 218 GNUNET_MQ_handler_end() };
220 219
221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 220 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
222 "Core connection to `%s' established\n", 221 "Core connection to `%s' established\n",
223 GNUNET_i2s (my_identity)); 222 GNUNET_i2s(my_identity));
224 p->id = *my_identity; 223 p->id = *my_identity;
225 if (cls == &p1) 224 if (cls == &p1)
226 { 225 {
227 GNUNET_assert (ok == 2); 226 GNUNET_assert(ok == 2);
228 OKPP; 227 OKPP;
229 /* connect p2 */ 228 /* connect p2 */
230 p2.ch = GNUNET_CORE_connect (p2.cfg, 229 p2.ch = GNUNET_CORE_connect(p2.cfg,
231 &p2, 230 &p2,
232 &init_notify, 231 &init_notify,
233 &connect_notify, 232 &connect_notify,
234 &disconnect_notify, 233 &disconnect_notify,
235 handlers); 234 handlers);
236 } 235 }
237 else 236 else
238 { 237 {
239 GNUNET_assert (ok == 3); 238 GNUNET_assert(ok == 3);
240 OKPP; 239 OKPP;
241 GNUNET_assert (cls == &p2); 240 GNUNET_assert(cls == &p2);
242 p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, &p2.id, 1); 241 p1.ats_sh = GNUNET_ATS_connectivity_suggest(p1.ats, &p2.id, 1);
243 } 242 }
244} 243}
245 244
246 245
247static void 246static void
248setup_peer (struct PeerContext *p, const char *cfgname) 247setup_peer(struct PeerContext *p, const char *cfgname)
249{ 248{
250 char *binary; 249 char *binary;
251 250
252 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 251 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm");
253 p->cfg = GNUNET_CONFIGURATION_create (); 252 p->cfg = GNUNET_CONFIGURATION_create();
254 p->arm_proc = GNUNET_OS_start_process (GNUNET_YES, 253 p->arm_proc = GNUNET_OS_start_process(GNUNET_YES,
255 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 254 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
256 NULL, 255 NULL,
257 NULL, 256 NULL,
258 NULL, 257 NULL,
259 binary, 258 binary,
260 "gnunet-service-arm", 259 "gnunet-service-arm",
261 "-c", 260 "-c",
262 cfgname, 261 cfgname,
263 NULL); 262 NULL);
264 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 263 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_load(p->cfg, cfgname));
265 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 264 p->ats = GNUNET_ATS_connectivity_init(p->cfg);
266 GNUNET_assert (NULL != p->ats); 265 GNUNET_assert(NULL != p->ats);
267 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, 266 p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg,
268 GNUNET_TRANSPORT_AC_ANY, 267 GNUNET_TRANSPORT_AC_ANY,
269 &process_hello, 268 &process_hello,
270 p); 269 p);
271 GNUNET_free (binary); 270 GNUNET_free(binary);
272} 271}
273 272
274 273
275static void 274static void
276run (void *cls, 275run(void *cls,
277 char *const *args, 276 char *const *args,
278 const char *cfgfile, 277 const char *cfgfile,
279 const struct GNUNET_CONFIGURATION_Handle *cfg) 278 const struct GNUNET_CONFIGURATION_Handle *cfg)
280{ 279{
281 struct GNUNET_MQ_MessageHandler handlers[] = 280 struct GNUNET_MQ_MessageHandler handlers[] =
282 {GNUNET_MQ_hd_fixed_size (test, MTYPE, struct GNUNET_MessageHeader, NULL), 281 { GNUNET_MQ_hd_fixed_size(test, MTYPE, struct GNUNET_MessageHeader, NULL),
283 GNUNET_MQ_handler_end ()}; 282 GNUNET_MQ_handler_end() };
284 283
285 GNUNET_assert (ok == 1); 284 GNUNET_assert(ok == 1);
286 OKPP; 285 OKPP;
287 setup_peer (&p1, "test_core_api_peer1.conf"); 286 setup_peer(&p1, "test_core_api_peer1.conf");
288 setup_peer (&p2, "test_core_api_peer2.conf"); 287 setup_peer(&p2, "test_core_api_peer2.conf");
289 err_task = GNUNET_SCHEDULER_add_delayed ( 288 err_task = GNUNET_SCHEDULER_add_delayed(
290 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300), 289 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300),
291 &terminate_task_error, 290 &terminate_task_error,
292 NULL); 291 NULL);
293 p1.ch = GNUNET_CORE_connect (p1.cfg, 292 p1.ch = GNUNET_CORE_connect(p1.cfg,
294 &p1, 293 &p1,
295 &init_notify, 294 &init_notify,
296 &connect_notify, 295 &connect_notify,
297 &disconnect_notify, 296 &disconnect_notify,
298 handlers); 297 handlers);
299} 298}
300 299
301 300
302static void 301static void
303stop_arm (struct PeerContext *p) 302stop_arm(struct PeerContext *p)
304{ 303{
305 if (0 != GNUNET_OS_process_kill (p->arm_proc, GNUNET_TERM_SIG)) 304 if (0 != GNUNET_OS_process_kill(p->arm_proc, GNUNET_TERM_SIG))
306 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 305 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "kill");
307 if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) 306 if (GNUNET_OK != GNUNET_OS_process_wait(p->arm_proc))
308 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 307 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "waitpid");
309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 308 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
310 "ARM process %u stopped\n", 309 "ARM process %u stopped\n",
311 GNUNET_OS_process_get_pid (p->arm_proc)); 310 GNUNET_OS_process_get_pid(p->arm_proc));
312 GNUNET_OS_process_destroy (p->arm_proc); 311 GNUNET_OS_process_destroy(p->arm_proc);
313 p->arm_proc = NULL; 312 p->arm_proc = NULL;
314 GNUNET_CONFIGURATION_destroy (p->cfg); 313 GNUNET_CONFIGURATION_destroy(p->cfg);
315} 314}
316 315
317 316
318int 317int
319main (int argc, char *argv1[]) 318main(int argc, char *argv1[])
320{ 319{
321 char *const argv[] = {"test-core-api", "-c", "test_core_api_data.conf", NULL}; 320 char *const argv[] = { "test-core-api", "-c", "test_core_api_data.conf", NULL };
322 struct GNUNET_GETOPT_CommandLineOption options[] = {GNUNET_GETOPT_OPTION_END}; 321 struct GNUNET_GETOPT_CommandLineOption options[] = { GNUNET_GETOPT_OPTION_END };
322
323 ok = 1; 323 ok = 1;
324 GNUNET_log_setup ("test-core-api", "WARNING", NULL); 324 GNUNET_log_setup("test-core-api", "WARNING", NULL);
325 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 325 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
326 argv, 326 argv,
327 "test-core-api", 327 "test-core-api",
328 "nohelp", 328 "nohelp",
329 options, 329 options,
330 &run, 330 &run,
331 &ok); 331 &ok);
332 stop_arm (&p1); 332 stop_arm(&p1);
333 stop_arm (&p2); 333 stop_arm(&p2);
334 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); 334 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-1");
335 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); 335 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-2");
336 336
337 return ok; 337 return ok;
338} 338}
diff --git a/src/core/test_core_api_reliability.c b/src/core/test_core_api_reliability.c
index 7bd4bfea0..745b0b7d9 100644
--- a/src/core/test_core_api_reliability.c
+++ b/src/core/test_core_api_reliability.c
@@ -16,7 +16,7 @@
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 * @file core/test_core_api_reliability.c 21 * @file core/test_core_api_reliability.c
22 * @brief testcase for core_api.c focusing on reliable transmission (with TCP) 22 * @brief testcase for core_api.c focusing on reliable transmission (with TCP)
@@ -41,7 +41,7 @@
41/** 41/**
42 * How long until we give up on transmitting the message? 42 * How long until we give up on transmitting the message?
43 */ 43 */
44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600) 44#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 600)
45 45
46#define MTYPE 12345 46#define MTYPE 12345
47 47
@@ -53,8 +53,7 @@ static struct GNUNET_TIME_Absolute start_time;
53static struct GNUNET_SCHEDULER_Task *err_task; 53static struct GNUNET_SCHEDULER_Task *err_task;
54 54
55 55
56struct PeerContext 56struct PeerContext {
57{
58 struct GNUNET_CONFIGURATION_Handle *cfg; 57 struct GNUNET_CONFIGURATION_Handle *cfg;
59 struct GNUNET_CORE_Handle *ch; 58 struct GNUNET_CORE_Handle *ch;
60 struct GNUNET_MQ_Handle *mq; 59 struct GNUNET_MQ_Handle *mq;
@@ -77,296 +76,294 @@ static int ok;
77static int32_t tr_n; 76static int32_t tr_n;
78 77
79 78
80#define OKPP do { ok++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 79#define OKPP do { ok++; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
81 80
82struct TestMessage 81struct TestMessage {
83{
84 struct GNUNET_MessageHeader header; 82 struct GNUNET_MessageHeader header;
85 uint32_t num GNUNET_PACKED; 83 uint32_t num GNUNET_PACKED;
86}; 84};
87 85
88 86
89static unsigned int 87static unsigned int
90get_size (unsigned int iter) 88get_size(unsigned int iter)
91{ 89{
92 unsigned int ret; 90 unsigned int ret;
93 91
94 if (iter < 60000) 92 if (iter < 60000)
95 return iter + sizeof (struct TestMessage); 93 return iter + sizeof(struct TestMessage);
96 ret = (iter * iter * iter); 94 ret = (iter * iter * iter);
97 return sizeof (struct TestMessage) + (ret % 60000); 95 return sizeof(struct TestMessage) + (ret % 60000);
98} 96}
99 97
100 98
101static void 99static void
102terminate_peer (struct PeerContext *p) 100terminate_peer(struct PeerContext *p)
103{ 101{
104 if (NULL != p->ch) 102 if (NULL != p->ch)
105 { 103 {
106 GNUNET_CORE_disconnect (p->ch); 104 GNUNET_CORE_disconnect(p->ch);
107 p->ch = NULL; 105 p->ch = NULL;
108 } 106 }
109 if (NULL != p->ghh) 107 if (NULL != p->ghh)
110 { 108 {
111 GNUNET_TRANSPORT_hello_get_cancel (p->ghh); 109 GNUNET_TRANSPORT_hello_get_cancel(p->ghh);
112 p->ghh = NULL; 110 p->ghh = NULL;
113 } 111 }
114 if (NULL != p->oh) 112 if (NULL != p->oh)
115 { 113 {
116 GNUNET_TRANSPORT_offer_hello_cancel (p->oh); 114 GNUNET_TRANSPORT_offer_hello_cancel(p->oh);
117 p->oh = NULL; 115 p->oh = NULL;
118 } 116 }
119 if (NULL != p->ats_sh) 117 if (NULL != p->ats_sh)
120 { 118 {
121 GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh); 119 GNUNET_ATS_connectivity_suggest_cancel(p->ats_sh);
122 p->ats_sh = NULL; 120 p->ats_sh = NULL;
123 } 121 }
124 if (NULL != p->ats) 122 if (NULL != p->ats)
125 { 123 {
126 GNUNET_ATS_connectivity_done (p->ats); 124 GNUNET_ATS_connectivity_done(p->ats);
127 p->ats = NULL; 125 p->ats = NULL;
128 } 126 }
129} 127}
130 128
131 129
132static void 130static void
133terminate_task_error (void *cls) 131terminate_task_error(void *cls)
134{ 132{
135 err_task = NULL; 133 err_task = NULL;
136 GNUNET_break (0); 134 GNUNET_break(0);
137 GNUNET_SCHEDULER_shutdown (); 135 GNUNET_SCHEDULER_shutdown();
138 ok = 42; 136 ok = 42;
139} 137}
140 138
141 139
142static void 140static void
143do_shutdown (void *cls) 141do_shutdown(void *cls)
144{ 142{
145 unsigned long long delta; 143 unsigned long long delta;
146 144
147 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; 145 delta = GNUNET_TIME_absolute_get_duration(start_time).rel_value_us;
148 if (0 == delta) 146 if (0 == delta)
149 delta = 1; 147 delta = 1;
150 fprintf (stderr, 148 fprintf(stderr,
151 "\nThroughput was %llu kb/s\n", 149 "\nThroughput was %llu kb/s\n",
152 total_bytes * 1000000LL / 1024 / delta); 150 total_bytes * 1000000LL / 1024 / delta);
153 GAUGER ("CORE", 151 GAUGER("CORE",
154 "Core throughput/s", 152 "Core throughput/s",
155 total_bytes * 1000000LL / 1024 / delta, 153 total_bytes * 1000000LL / 1024 / delta,
156 "kb/s"); 154 "kb/s");
157 if (NULL != err_task) 155 if (NULL != err_task)
158 { 156 {
159 GNUNET_SCHEDULER_cancel (err_task); 157 GNUNET_SCHEDULER_cancel(err_task);
160 err_task = NULL; 158 err_task = NULL;
161 } 159 }
162 terminate_peer (&p1); 160 terminate_peer(&p1);
163 terminate_peer (&p2); 161 terminate_peer(&p2);
164
165} 162}
166 163
167 164
168static void 165static void
169send_message (struct GNUNET_MQ_Handle *mq, 166send_message(struct GNUNET_MQ_Handle *mq,
170 int32_t num) 167 int32_t num)
171{ 168{
172 struct GNUNET_MQ_Envelope *env; 169 struct GNUNET_MQ_Envelope *env;
173 struct TestMessage *hdr; 170 struct TestMessage *hdr;
174 unsigned int s; 171 unsigned int s;
175 172
176 GNUNET_assert (NULL != mq); 173 GNUNET_assert(NULL != mq);
177 GNUNET_assert (tr_n < TOTAL_MSGS); 174 GNUNET_assert(tr_n < TOTAL_MSGS);
178 s = get_size (tr_n); 175 s = get_size(tr_n);
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 176 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
180 "Sending message %u of size %u\n", 177 "Sending message %u of size %u\n",
181 tr_n, 178 tr_n,
182 s); 179 s);
183 env = GNUNET_MQ_msg_extra (hdr, 180 env = GNUNET_MQ_msg_extra(hdr,
184 s - sizeof (struct TestMessage), 181 s - sizeof(struct TestMessage),
185 MTYPE); 182 MTYPE);
186 hdr->num = htonl (tr_n); 183 hdr->num = htonl(tr_n);
187 memset (&hdr[1], 184 memset(&hdr[1],
188 tr_n, 185 tr_n,
189 s - sizeof (struct TestMessage)); 186 s - sizeof(struct TestMessage));
190 tr_n++; 187 tr_n++;
191 GNUNET_SCHEDULER_cancel (err_task); 188 GNUNET_SCHEDULER_cancel(err_task);
192 err_task = 189 err_task =
193 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 190 GNUNET_SCHEDULER_add_delayed(TIMEOUT,
194 &terminate_task_error, 191 &terminate_task_error,
195 NULL); 192 NULL);
196 total_bytes += s; 193 total_bytes += s;
197 GNUNET_MQ_send (mq, 194 GNUNET_MQ_send(mq,
198 env); 195 env);
199} 196}
200 197
201 198
202static void * 199static void *
203connect_notify (void *cls, 200connect_notify(void *cls,
204 const struct GNUNET_PeerIdentity *peer, 201 const struct GNUNET_PeerIdentity *peer,
205 struct GNUNET_MQ_Handle *mq) 202 struct GNUNET_MQ_Handle *mq)
206{ 203{
207 struct PeerContext *pc = cls; 204 struct PeerContext *pc = cls;
208 205
209 if (0 == memcmp (&pc->id, 206 if (0 == memcmp(&pc->id,
210 peer, 207 peer,
211 sizeof (struct GNUNET_PeerIdentity))) 208 sizeof(struct GNUNET_PeerIdentity)))
212 return (void *) peer; 209 return (void *)peer;
213 pc->mq = mq; 210 pc->mq = mq;
214 GNUNET_assert (0 == pc->connect_status); 211 GNUNET_assert(0 == pc->connect_status);
215 pc->connect_status = 1; 212 pc->connect_status = 1;
216 if (pc == &p1) 213 if (pc == &p1)
217 { 214 {
218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 215 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
219 "Encrypted connection established to peer `%s'\n", 216 "Encrypted connection established to peer `%s'\n",
220 GNUNET_i2s (peer)); 217 GNUNET_i2s(peer));
221 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 218 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
222 "Asking core (1) for transmission to peer `%s'\n", 219 "Asking core (1) for transmission to peer `%s'\n",
223 GNUNET_i2s (&p2.id)); 220 GNUNET_i2s(&p2.id));
224 GNUNET_SCHEDULER_cancel (err_task); 221 GNUNET_SCHEDULER_cancel(err_task);
225 err_task = 222 err_task =
226 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 223 GNUNET_SCHEDULER_add_delayed(TIMEOUT,
227 &terminate_task_error, 224 &terminate_task_error,
228 NULL); 225 NULL);
229 start_time = GNUNET_TIME_absolute_get (); 226 start_time = GNUNET_TIME_absolute_get();
230 send_message (mq, 227 send_message(mq,
231 0); 228 0);
232 } 229 }
233 return (void *) peer; 230 return (void *)peer;
234} 231}
235 232
236 233
237static void 234static void
238disconnect_notify (void *cls, 235disconnect_notify(void *cls,
239 const struct GNUNET_PeerIdentity *peer, 236 const struct GNUNET_PeerIdentity *peer,
240 void *internal_cls) 237 void *internal_cls)
241{ 238{
242 struct PeerContext *pc = cls; 239 struct PeerContext *pc = cls;
243 240
244 if (0 == memcmp (&pc->id, 241 if (0 == memcmp(&pc->id,
245 peer, 242 peer,
246 sizeof (struct GNUNET_PeerIdentity))) 243 sizeof(struct GNUNET_PeerIdentity)))
247 return; 244 return;
248 pc->mq = NULL; 245 pc->mq = NULL;
249 pc->connect_status = 0; 246 pc->connect_status = 0;
250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 247 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
251 "Encrypted connection to `%s' cut\n", 248 "Encrypted connection to `%s' cut\n",
252 GNUNET_i2s (peer)); 249 GNUNET_i2s(peer));
253} 250}
254 251
255 252
256static int 253static int
257check_test (void *cls, 254check_test(void *cls,
258 const struct TestMessage *hdr) 255 const struct TestMessage *hdr)
259{ 256{
260 return GNUNET_OK; /* accept all */ 257 return GNUNET_OK; /* accept all */
261} 258}
262 259
263 260
264static void 261static void
265handle_test (void *cls, 262handle_test(void *cls,
266 const struct TestMessage *hdr) 263 const struct TestMessage *hdr)
267{ 264{
268 static int n; 265 static int n;
269 unsigned int s; 266 unsigned int s;
270 267
271 s = get_size (n); 268 s = get_size(n);
272 if (ntohs (hdr->header.size) != s) 269 if (ntohs(hdr->header.size) != s)
273 { 270 {
274 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 271 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
275 "Expected message %u of size %u, got %u bytes of message %u\n", 272 "Expected message %u of size %u, got %u bytes of message %u\n",
276 n, 273 n,
277 s, 274 s,
278 ntohs (hdr->header.size), 275 ntohs(hdr->header.size),
279 ntohl (hdr->num)); 276 ntohl(hdr->num));
280 GNUNET_SCHEDULER_cancel (err_task); 277 GNUNET_SCHEDULER_cancel(err_task);
281 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, 278 err_task = GNUNET_SCHEDULER_add_now(&terminate_task_error,
282 NULL); 279 NULL);
283 return; 280 return;
284 } 281 }
285 if (ntohl (hdr->num) != n) 282 if (ntohl(hdr->num) != n)
286 { 283 {
287 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 284 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
288 "Expected message %u of size %u, got %u bytes of message %u\n", 285 "Expected message %u of size %u, got %u bytes of message %u\n",
289 n, 286 n,
290 s, 287 s,
291 (unsigned int) ntohs (hdr->header.size), 288 (unsigned int)ntohs(hdr->header.size),
292 (unsigned int) ntohl (hdr->num)); 289 (unsigned int)ntohl(hdr->num));
293 GNUNET_SCHEDULER_cancel (err_task); 290 GNUNET_SCHEDULER_cancel(err_task);
294 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, 291 err_task = GNUNET_SCHEDULER_add_now(&terminate_task_error,
295 NULL); 292 NULL);
296 return; 293 return;
297 } 294 }
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 295 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
299 "Got message %u of size %u\n", 296 "Got message %u of size %u\n",
300 (unsigned int) ntohl (hdr->num), 297 (unsigned int)ntohl(hdr->num),
301 (unsigned int) ntohs (hdr->header.size)); 298 (unsigned int)ntohs(hdr->header.size));
302 n++; 299 n++;
303 if (0 == (n % (TOTAL_MSGS / 100))) 300 if (0 == (n % (TOTAL_MSGS / 100)))
304 fprintf (stderr, 301 fprintf(stderr,
305 "%s", 302 "%s",
306 "."); 303 ".");
307 if (n == TOTAL_MSGS) 304 if (n == TOTAL_MSGS)
308 { 305 {
309 ok = 0; 306 ok = 0;
310 GNUNET_SCHEDULER_shutdown (); 307 GNUNET_SCHEDULER_shutdown();
311 } 308 }
312 else 309 else
313 {
314 if (n == tr_n)
315 { 310 {
316 send_message (p1.mq, 311 if (n == tr_n)
317 tr_n); 312 {
313 send_message(p1.mq,
314 tr_n);
315 }
318 } 316 }
319 }
320} 317}
321 318
322 319
323static void 320static void
324init_notify (void *cls, 321init_notify(void *cls,
325 const struct GNUNET_PeerIdentity *my_identity) 322 const struct GNUNET_PeerIdentity *my_identity)
326{ 323{
327 struct PeerContext *p = cls; 324 struct PeerContext *p = cls;
328 struct GNUNET_MQ_MessageHandler handlers[] = { 325 struct GNUNET_MQ_MessageHandler handlers[] = {
329 GNUNET_MQ_hd_var_size (test, 326 GNUNET_MQ_hd_var_size(test,
330 MTYPE, 327 MTYPE,
331 struct TestMessage, 328 struct TestMessage,
332 NULL), 329 NULL),
333 GNUNET_MQ_handler_end () 330 GNUNET_MQ_handler_end()
334 }; 331 };
335 332
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 333 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
337 "Connection to CORE service of `%s' established\n", 334 "Connection to CORE service of `%s' established\n",
338 GNUNET_i2s (my_identity)); 335 GNUNET_i2s(my_identity));
339 p->id = *my_identity; 336 p->id = *my_identity;
340 if (cls == &p1) 337 if (cls == &p1)
341 { 338 {
342 GNUNET_assert (ok == 2); 339 GNUNET_assert(ok == 2);
343 OKPP; 340 OKPP;
344 /* connect p2 */ 341 /* connect p2 */
345 GNUNET_assert (NULL != 342 GNUNET_assert(NULL !=
346 (p2.ch = GNUNET_CORE_connect (p2.cfg, 343 (p2.ch = GNUNET_CORE_connect(p2.cfg,
347 &p2, 344 &p2,
348 &init_notify, 345 &init_notify,
349 &connect_notify, 346 &connect_notify,
350 &disconnect_notify, 347 &disconnect_notify,
351 handlers))); 348 handlers)));
352 } 349 }
353 else 350 else
354 { 351 {
355 GNUNET_assert (ok == 3); 352 GNUNET_assert(ok == 3);
356 OKPP; 353 OKPP;
357 GNUNET_assert (cls == &p2); 354 GNUNET_assert(cls == &p2);
358 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 355 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
359 "Asking transport (1) to connect to peer `%s'\n", 356 "Asking transport (1) to connect to peer `%s'\n",
360 GNUNET_i2s (&p2.id)); 357 GNUNET_i2s(&p2.id));
361 p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, 358 p1.ats_sh = GNUNET_ATS_connectivity_suggest(p1.ats,
362 &p2.id, 359 &p2.id,
363 1); 360 1);
364 } 361 }
365} 362}
366 363
367 364
368static void 365static void
369offer_hello_done (void *cls) 366offer_hello_done(void *cls)
370{ 367{
371 struct PeerContext *p = cls; 368 struct PeerContext *p = cls;
372 369
@@ -375,129 +372,129 @@ offer_hello_done (void *cls)
375 372
376 373
377static void 374static void
378process_hello (void *cls, 375process_hello(void *cls,
379 const struct GNUNET_MessageHeader *message) 376 const struct GNUNET_MessageHeader *message)
380{ 377{
381 struct PeerContext *p = cls; 378 struct PeerContext *p = cls;
382 379
383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 380 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
384 "Received (my) `%s' from transport service\n", "HELLO"); 381 "Received (my) `%s' from transport service\n", "HELLO");
385 GNUNET_assert (message != NULL); 382 GNUNET_assert(message != NULL);
386 GNUNET_free_non_null (p->hello); 383 GNUNET_free_non_null(p->hello);
387 p->hello = GNUNET_copy_message (message); 384 p->hello = GNUNET_copy_message(message);
388 if ((p == &p1) && (NULL == p2.oh)) 385 if ((p == &p1) && (NULL == p2.oh))
389 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, 386 p2.oh = GNUNET_TRANSPORT_offer_hello(p2.cfg,
390 message, 387 message,
391 &offer_hello_done, 388 &offer_hello_done,
392 &p2); 389 &p2);
393 if ((p == &p2) && (NULL == p1.oh)) 390 if ((p == &p2) && (NULL == p1.oh))
394 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, 391 p1.oh = GNUNET_TRANSPORT_offer_hello(p1.cfg,
395 message, 392 message,
396 &offer_hello_done, 393 &offer_hello_done,
397 &p1); 394 &p1);
398 395
399 if ((p == &p1) && (p2.hello != NULL) && (NULL == p1.oh) ) 396 if ((p == &p1) && (p2.hello != NULL) && (NULL == p1.oh))
400 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, 397 p1.oh = GNUNET_TRANSPORT_offer_hello(p1.cfg,
401 p2.hello, 398 p2.hello,
402 &offer_hello_done, 399 &offer_hello_done,
403 &p1); 400 &p1);
404 if ((p == &p2) && (p1.hello != NULL) && (NULL == p2.oh) ) 401 if ((p == &p2) && (p1.hello != NULL) && (NULL == p2.oh))
405 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, 402 p2.oh = GNUNET_TRANSPORT_offer_hello(p2.cfg,
406 p1.hello, 403 p1.hello,
407 &offer_hello_done, 404 &offer_hello_done,
408 &p2); 405 &p2);
409} 406}
410 407
411 408
412static void 409static void
413setup_peer (struct PeerContext *p, 410setup_peer(struct PeerContext *p,
414 const char *cfgname) 411 const char *cfgname)
415{ 412{
416 char *binary; 413 char *binary;
417 414
418 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 415 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm");
419 p->cfg = GNUNET_CONFIGURATION_create (); 416 p->cfg = GNUNET_CONFIGURATION_create();
420 p->arm_proc 417 p->arm_proc
421 = GNUNET_OS_start_process (GNUNET_YES, 418 = GNUNET_OS_start_process(GNUNET_YES,
422 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 419 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
423 NULL, NULL, NULL, 420 NULL, NULL, NULL,
424 binary, 421 binary,
425 "gnunet-service-arm", 422 "gnunet-service-arm",
426 "-c", 423 "-c",
427 cfgname, 424 cfgname,
428 NULL); 425 NULL);
429 GNUNET_assert (GNUNET_OK == 426 GNUNET_assert(GNUNET_OK ==
430 GNUNET_CONFIGURATION_load (p->cfg, 427 GNUNET_CONFIGURATION_load(p->cfg,
431 cfgname)); 428 cfgname));
432 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 429 p->ats = GNUNET_ATS_connectivity_init(p->cfg);
433 GNUNET_assert (NULL != p->ats); 430 GNUNET_assert(NULL != p->ats);
434 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, 431 p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg,
435 GNUNET_TRANSPORT_AC_ANY, 432 GNUNET_TRANSPORT_AC_ANY,
436 &process_hello, 433 &process_hello,
437 p); 434 p);
438 GNUNET_free (binary); 435 GNUNET_free(binary);
439} 436}
440 437
441 438
442static void 439static void
443run (void *cls, 440run(void *cls,
444 char *const *args, 441 char *const *args,
445 const char *cfgfile, 442 const char *cfgfile,
446 const struct GNUNET_CONFIGURATION_Handle *cfg) 443 const struct GNUNET_CONFIGURATION_Handle *cfg)
447{ 444{
448 struct GNUNET_MQ_MessageHandler handlers[] = { 445 struct GNUNET_MQ_MessageHandler handlers[] = {
449 GNUNET_MQ_hd_fixed_size (test, 446 GNUNET_MQ_hd_fixed_size(test,
450 MTYPE, 447 MTYPE,
451 struct TestMessage, 448 struct TestMessage,
452 NULL), 449 NULL),
453 GNUNET_MQ_handler_end () 450 GNUNET_MQ_handler_end()
454 }; 451 };
455 452
456 GNUNET_assert (ok == 1); 453 GNUNET_assert(ok == 1);
457 OKPP; 454 OKPP;
458 setup_peer (&p1, 455 setup_peer(&p1,
459 "test_core_api_peer1.conf"); 456 "test_core_api_peer1.conf");
460 setup_peer (&p2, 457 setup_peer(&p2,
461 "test_core_api_peer2.conf"); 458 "test_core_api_peer2.conf");
462 err_task = 459 err_task =
463 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 460 GNUNET_SCHEDULER_add_delayed(TIMEOUT,
464 &terminate_task_error, 461 &terminate_task_error,
465 NULL); 462 NULL);
466 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 463 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
467 NULL); 464 NULL);
468 465
469 GNUNET_assert (NULL != 466 GNUNET_assert(NULL !=
470 (p1.ch = GNUNET_CORE_connect (p1.cfg, 467 (p1.ch = GNUNET_CORE_connect(p1.cfg,
471 &p1, 468 &p1,
472 &init_notify, 469 &init_notify,
473 &connect_notify, 470 &connect_notify,
474 &disconnect_notify, 471 &disconnect_notify,
475 handlers))); 472 handlers)));
476} 473}
477 474
478 475
479static void 476static void
480stop_arm (struct PeerContext *p) 477stop_arm(struct PeerContext *p)
481{ 478{
482 if (0 != GNUNET_OS_process_kill (p->arm_proc, 479 if (0 != GNUNET_OS_process_kill(p->arm_proc,
483 GNUNET_TERM_SIG)) 480 GNUNET_TERM_SIG))
484 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 481 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING,
485 "kill"); 482 "kill");
486 if (GNUNET_OK != GNUNET_OS_process_wait (p->arm_proc)) 483 if (GNUNET_OK != GNUNET_OS_process_wait(p->arm_proc))
487 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 484 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING,
488 "waitpid"); 485 "waitpid");
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 486 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
490 "ARM process %u stopped\n", 487 "ARM process %u stopped\n",
491 GNUNET_OS_process_get_pid (p->arm_proc)); 488 GNUNET_OS_process_get_pid(p->arm_proc));
492 GNUNET_OS_process_destroy (p->arm_proc); 489 GNUNET_OS_process_destroy(p->arm_proc);
493 p->arm_proc = NULL; 490 p->arm_proc = NULL;
494 GNUNET_CONFIGURATION_destroy (p->cfg); 491 GNUNET_CONFIGURATION_destroy(p->cfg);
495} 492}
496 493
497 494
498int 495int
499main (int argc, 496main(int argc,
500 char *argv1[]) 497 char *argv1[])
501{ 498{
502 char *const argv[] = { 499 char *const argv[] = {
503 "test-core-api-reliability", 500 "test-core-api-reliability",
@@ -508,23 +505,24 @@ main (int argc,
508 struct GNUNET_GETOPT_CommandLineOption options[] = { 505 struct GNUNET_GETOPT_CommandLineOption options[] = {
509 GNUNET_GETOPT_OPTION_END 506 GNUNET_GETOPT_OPTION_END
510 }; 507 };
508
511 ok = 1; 509 ok = 1;
512 GNUNET_log_setup ("test-core-api-reliability", 510 GNUNET_log_setup("test-core-api-reliability",
513 "WARNING", 511 "WARNING",
514 NULL); 512 NULL);
515 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 513 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
516 argv, 514 argv,
517 "test-core-api-reliability", 515 "test-core-api-reliability",
518 "nohelp", 516 "nohelp",
519 options, 517 options,
520 &run, 518 &run,
521 &ok); 519 &ok);
522 stop_arm (&p1); 520 stop_arm(&p1);
523 stop_arm (&p2); 521 stop_arm(&p2);
524 GNUNET_free_non_null (p1.hello); 522 GNUNET_free_non_null(p1.hello);
525 GNUNET_free_non_null (p2.hello); 523 GNUNET_free_non_null(p2.hello);
526 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); 524 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-1");
527 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); 525 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-2");
528 526
529 return ok; 527 return ok;
530} 528}
diff --git a/src/core/test_core_api_send_to_self.c b/src/core/test_core_api_send_to_self.c
index 703a635e3..dc132380f 100644
--- a/src/core/test_core_api_send_to_self.c
+++ b/src/core/test_core_api_send_to_self.c
@@ -11,12 +11,12 @@
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 core/test_core_api_send_to_self.c 22 * @file core/test_core_api_send_to_self.c
@@ -56,20 +56,20 @@ static struct GNUNET_CORE_Handle *core;
56 * Function scheduled as very last function, cleans up after us 56 * Function scheduled as very last function, cleans up after us
57 */ 57 */
58static void 58static void
59cleanup (void *cls) 59cleanup(void *cls)
60{ 60{
61 if (NULL != die_task) 61 if (NULL != die_task)
62 { 62 {
63 GNUNET_SCHEDULER_cancel (die_task); 63 GNUNET_SCHEDULER_cancel(die_task);
64 die_task = NULL; 64 die_task = NULL;
65 } 65 }
66 if (NULL != core) 66 if (NULL != core)
67 { 67 {
68 GNUNET_CORE_disconnect (core); 68 GNUNET_CORE_disconnect(core);
69 core = NULL; 69 core = NULL;
70 } 70 }
71 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 71 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
72 "Ending test.\n"); 72 "Ending test.\n");
73} 73}
74 74
75 75
@@ -77,64 +77,64 @@ cleanup (void *cls)
77 * Function scheduled as very last function, cleans up after us 77 * Function scheduled as very last function, cleans up after us
78 */ 78 */
79static void 79static void
80do_timeout (void *cls) 80do_timeout(void *cls)
81{ 81{
82 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 82 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
83 "Test timeout.\n"); 83 "Test timeout.\n");
84 die_task = NULL; 84 die_task = NULL;
85 GNUNET_SCHEDULER_shutdown (); 85 GNUNET_SCHEDULER_shutdown();
86} 86}
87 87
88 88
89static void 89static void
90handle_test (void *cls, 90handle_test(void *cls,
91 const struct GNUNET_MessageHeader *message) 91 const struct GNUNET_MessageHeader *message)
92{ 92{
93 GNUNET_SCHEDULER_shutdown (); 93 GNUNET_SCHEDULER_shutdown();
94 ret = 0; 94 ret = 0;
95} 95}
96 96
97 97
98static void 98static void
99init (void *cls, 99init(void *cls,
100 const struct GNUNET_PeerIdentity *my_identity) 100 const struct GNUNET_PeerIdentity *my_identity)
101{ 101{
102 if (NULL == my_identity) 102 if (NULL == my_identity)
103 { 103 {
104 GNUNET_break (0); 104 GNUNET_break(0);
105 return; 105 return;
106 } 106 }
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 107 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
108 "Correctly connected to CORE; we are the peer %s.\n", 108 "Correctly connected to CORE; we are the peer %s.\n",
109 GNUNET_i2s (my_identity)); 109 GNUNET_i2s(my_identity));
110 GNUNET_memcpy (&myself, 110 GNUNET_memcpy(&myself,
111 my_identity, 111 my_identity,
112 sizeof (struct GNUNET_PeerIdentity)); 112 sizeof(struct GNUNET_PeerIdentity));
113} 113}
114 114
115 115
116static void * 116static void *
117connect_cb (void *cls, 117connect_cb(void *cls,
118 const struct GNUNET_PeerIdentity *peer, 118 const struct GNUNET_PeerIdentity *peer,
119 struct GNUNET_MQ_Handle *mq) 119 struct GNUNET_MQ_Handle *mq)
120{ 120{
121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 121 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
122 "Connected to peer %s.\n", 122 "Connected to peer %s.\n",
123 GNUNET_i2s (peer)); 123 GNUNET_i2s(peer));
124 if (0 == memcmp (peer, 124 if (0 == memcmp(peer,
125 &myself, 125 &myself,
126 sizeof (struct GNUNET_PeerIdentity))) 126 sizeof(struct GNUNET_PeerIdentity)))
127 { 127 {
128 struct GNUNET_MQ_Envelope *env; 128 struct GNUNET_MQ_Envelope *env;
129 struct GNUNET_MessageHeader *msg; 129 struct GNUNET_MessageHeader *msg;
130 130
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 131 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
132 "Connected to myself; sending message!\n"); 132 "Connected to myself; sending message!\n");
133 env = GNUNET_MQ_msg (msg, 133 env = GNUNET_MQ_msg(msg,
134 GNUNET_MESSAGE_TYPE_DUMMY); 134 GNUNET_MESSAGE_TYPE_DUMMY);
135 GNUNET_MQ_send (mq, 135 GNUNET_MQ_send(mq,
136 env); 136 env);
137 } 137 }
138 return NULL; 138 return NULL;
139} 139}
140 140
@@ -146,30 +146,30 @@ connect_cb (void *cls,
146 * @param cfg configuration 146 * @param cfg configuration
147 */ 147 */
148static void 148static void
149run (void *cls, 149run(void *cls,
150 const struct GNUNET_CONFIGURATION_Handle *cfg, 150 const struct GNUNET_CONFIGURATION_Handle *cfg,
151 struct GNUNET_TESTING_Peer *peer) 151 struct GNUNET_TESTING_Peer *peer)
152{ 152{
153 struct GNUNET_MQ_MessageHandler handlers[] = { 153 struct GNUNET_MQ_MessageHandler handlers[] = {
154 GNUNET_MQ_hd_fixed_size (test, 154 GNUNET_MQ_hd_fixed_size(test,
155 GNUNET_MESSAGE_TYPE_DUMMY, 155 GNUNET_MESSAGE_TYPE_DUMMY,
156 struct GNUNET_MessageHeader, 156 struct GNUNET_MessageHeader,
157 NULL), 157 NULL),
158 GNUNET_MQ_handler_end () 158 GNUNET_MQ_handler_end()
159 }; 159 };
160 160
161 core = 161 core =
162 GNUNET_CORE_connect (cfg, 162 GNUNET_CORE_connect(cfg,
163 NULL, 163 NULL,
164 &init, 164 &init,
165 &connect_cb, 165 &connect_cb,
166 NULL, 166 NULL,
167 handlers); 167 handlers);
168 GNUNET_SCHEDULER_add_shutdown (&cleanup, 168 GNUNET_SCHEDULER_add_shutdown(&cleanup,
169 NULL); 169 NULL);
170 die_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, 170 die_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES,
171 &do_timeout, 171 &do_timeout,
172 NULL); 172 NULL);
173} 173}
174 174
175 175
@@ -181,12 +181,12 @@ run (void *cls,
181 * @return 0 ok, 1 on error 181 * @return 0 ok, 1 on error
182 */ 182 */
183int 183int
184main (int argc, char *argv[]) 184main(int argc, char *argv[])
185{ 185{
186 ret = 1; 186 ret = 1;
187 if (0 != GNUNET_TESTING_peer_run ("test-core-api-send-to-self", 187 if (0 != GNUNET_TESTING_peer_run("test-core-api-send-to-self",
188 "test_core_api_peer1.conf", 188 "test_core_api_peer1.conf",
189 &run, NULL)) 189 &run, NULL))
190 return 1; 190 return 1;
191 return ret; 191 return ret;
192} 192}
diff --git a/src/core/test_core_api_start_only.c b/src/core/test_core_api_start_only.c
index 92574e3d4..c8a848359 100644
--- a/src/core/test_core_api_start_only.c
+++ b/src/core/test_core_api_start_only.c
@@ -11,12 +11,12 @@
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 * @file transport/test_core_api_start_only.c 21 * @file transport/test_core_api_start_only.c
22 * @brief testcase for core_api.c that only starts two peers, 22 * @brief testcase for core_api.c that only starts two peers,
@@ -32,8 +32,7 @@
32 32
33#define MTYPE 12345 33#define MTYPE 12345
34 34
35struct PeerContext 35struct PeerContext {
36{
37 struct GNUNET_CONFIGURATION_Handle *cfg; 36 struct GNUNET_CONFIGURATION_Handle *cfg;
38 struct GNUNET_CORE_Handle *ch; 37 struct GNUNET_CORE_Handle *ch;
39 struct GNUNET_PeerIdentity id; 38 struct GNUNET_PeerIdentity id;
@@ -50,157 +49,157 @@ static int ok;
50 49
51 50
52static void * 51static void *
53connect_notify (void *cls, 52connect_notify(void *cls,
54 const struct GNUNET_PeerIdentity *peer, 53 const struct GNUNET_PeerIdentity *peer,
55 struct GNUNET_MQ_Handle *mq) 54 struct GNUNET_MQ_Handle *mq)
56{ 55{
57 return NULL; 56 return NULL;
58} 57}
59 58
60 59
61static void 60static void
62disconnect_notify (void *cls, 61disconnect_notify(void *cls,
63 const struct GNUNET_PeerIdentity *peer, 62 const struct GNUNET_PeerIdentity *peer,
64 void *internal_cls) 63 void *internal_cls)
65{ 64{
66} 65}
67 66
68 67
69static struct GNUNET_MQ_MessageHandler handlers[] = { 68static struct GNUNET_MQ_MessageHandler handlers[] = {
70 GNUNET_MQ_handler_end () 69 GNUNET_MQ_handler_end()
71}; 70};
72 71
73 72
74static void 73static void
75shutdown_task (void *cls) 74shutdown_task(void *cls)
76{ 75{
77 GNUNET_CORE_disconnect (p1.ch); 76 GNUNET_CORE_disconnect(p1.ch);
78 p1.ch = NULL; 77 p1.ch = NULL;
79 GNUNET_CORE_disconnect (p2.ch); 78 GNUNET_CORE_disconnect(p2.ch);
80 p2.ch = NULL; 79 p2.ch = NULL;
81 ok = 0; 80 ok = 0;
82} 81}
83 82
84 83
85static void 84static void
86init_notify (void *cls, 85init_notify(void *cls,
87 const struct GNUNET_PeerIdentity *my_identity) 86 const struct GNUNET_PeerIdentity *my_identity)
88{ 87{
89 struct PeerContext *p = cls; 88 struct PeerContext *p = cls;
90 89
91 if (p == &p1) 90 if (p == &p1)
92 { 91 {
93 /* connect p2 */ 92 /* connect p2 */
94 p2.ch = GNUNET_CORE_connect (p2.cfg, 93 p2.ch = GNUNET_CORE_connect(p2.cfg,
95 &p2, 94 &p2,
96 &init_notify, 95 &init_notify,
97 &connect_notify, 96 &connect_notify,
98 &disconnect_notify, 97 &disconnect_notify,
99 handlers); 98 handlers);
100 } 99 }
101 else 100 else
102 { 101 {
103 GNUNET_assert (p == &p2); 102 GNUNET_assert(p == &p2);
104 GNUNET_SCHEDULER_cancel (timeout_task_id); 103 GNUNET_SCHEDULER_cancel(timeout_task_id);
105 timeout_task_id = NULL; 104 timeout_task_id = NULL;
106 GNUNET_SCHEDULER_add_now (&shutdown_task, 105 GNUNET_SCHEDULER_add_now(&shutdown_task,
107 NULL); 106 NULL);
108 } 107 }
109} 108}
110 109
111 110
112static void 111static void
113setup_peer (struct PeerContext *p, 112setup_peer(struct PeerContext *p,
114 const char *cfgname) 113 const char *cfgname)
115{ 114{
116 char *binary; 115 char *binary;
117 116
118 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 117 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm");
119 p->cfg = GNUNET_CONFIGURATION_create (); 118 p->cfg = GNUNET_CONFIGURATION_create();
120 p->arm_proc = 119 p->arm_proc =
121 GNUNET_OS_start_process (GNUNET_YES, 120 GNUNET_OS_start_process(GNUNET_YES,
122 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 121 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
123 NULL, NULL, NULL, 122 NULL, NULL, NULL,
124 binary, 123 binary,
125 "gnunet-service-arm", 124 "gnunet-service-arm",
126 "-c", cfgname, 125 "-c", cfgname,
127 NULL); 126 NULL);
128 GNUNET_assert (GNUNET_OK == 127 GNUNET_assert(GNUNET_OK ==
129 GNUNET_CONFIGURATION_load (p->cfg, 128 GNUNET_CONFIGURATION_load(p->cfg,
130 cfgname)); 129 cfgname));
131 GNUNET_free (binary); 130 GNUNET_free(binary);
132} 131}
133 132
134 133
135static void 134static void
136timeout_task (void *cls) 135timeout_task(void *cls)
137{ 136{
138 fprintf (stderr, 137 fprintf(stderr,
139 "%s", 138 "%s",
140 "Timeout.\n"); 139 "Timeout.\n");
141 if (NULL != p1.ch) 140 if (NULL != p1.ch)
142 { 141 {
143 GNUNET_CORE_disconnect (p1.ch); 142 GNUNET_CORE_disconnect(p1.ch);
144 p1.ch = NULL; 143 p1.ch = NULL;
145 } 144 }
146 if (NULL != p2.ch) 145 if (NULL != p2.ch)
147 { 146 {
148 GNUNET_CORE_disconnect (p2.ch); 147 GNUNET_CORE_disconnect(p2.ch);
149 p2.ch = NULL; 148 p2.ch = NULL;
150 } 149 }
151 ok = 42; 150 ok = 42;
152} 151}
153 152
154 153
155static void 154static void
156run (void *cls, 155run(void *cls,
157 char *const *args, 156 char *const *args,
158 const char *cfgfile, 157 const char *cfgfile,
159 const struct GNUNET_CONFIGURATION_Handle *cfg) 158 const struct GNUNET_CONFIGURATION_Handle *cfg)
160{ 159{
161 GNUNET_assert (ok == 1); 160 GNUNET_assert(ok == 1);
162 ok++; 161 ok++;
163 setup_peer (&p1, "test_core_api_peer1.conf"); 162 setup_peer(&p1, "test_core_api_peer1.conf");
164 setup_peer (&p2, "test_core_api_peer2.conf"); 163 setup_peer(&p2, "test_core_api_peer2.conf");
165 timeout_task_id = 164 timeout_task_id =
166 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 165 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply
167 (GNUNET_TIME_UNIT_MINUTES, 166 (GNUNET_TIME_UNIT_MINUTES,
168 TIMEOUT), 167 TIMEOUT),
169 &timeout_task, 168 &timeout_task,
170 NULL); 169 NULL);
171 p1.ch = GNUNET_CORE_connect (p1.cfg, 170 p1.ch = GNUNET_CORE_connect(p1.cfg,
172 &p1, 171 &p1,
173 &init_notify, 172 &init_notify,
174 &connect_notify, 173 &connect_notify,
175 &disconnect_notify, 174 &disconnect_notify,
176 handlers); 175 handlers);
177} 176}
178 177
179 178
180static void 179static void
181stop_arm (struct PeerContext *p) 180stop_arm(struct PeerContext *p)
182{ 181{
183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 182 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
184 "Stopping peer\n"); 183 "Stopping peer\n");
185 if (0 != GNUNET_OS_process_kill (p->arm_proc, 184 if (0 != GNUNET_OS_process_kill(p->arm_proc,
186 GNUNET_TERM_SIG)) 185 GNUNET_TERM_SIG))
187 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 186 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING,
188 "kill"); 187 "kill");
189 if (GNUNET_OK != 188 if (GNUNET_OK !=
190 GNUNET_OS_process_wait (p->arm_proc)) 189 GNUNET_OS_process_wait(p->arm_proc))
191 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 190 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING,
192 "waitpid"); 191 "waitpid");
193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 192 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
194 "ARM process %u stopped\n", 193 "ARM process %u stopped\n",
195 (unsigned int) GNUNET_OS_process_get_pid (p->arm_proc)); 194 (unsigned int)GNUNET_OS_process_get_pid(p->arm_proc));
196 GNUNET_OS_process_destroy (p->arm_proc); 195 GNUNET_OS_process_destroy(p->arm_proc);
197 p->arm_proc = NULL; 196 p->arm_proc = NULL;
198 GNUNET_CONFIGURATION_destroy (p->cfg); 197 GNUNET_CONFIGURATION_destroy(p->cfg);
199} 198}
200 199
201 200
202static int 201static int
203check () 202check()
204{ 203{
205 char *const argv[] = { 204 char *const argv[] = {
206 "test-core-api-start-only", 205 "test-core-api-start-only",
@@ -211,37 +210,38 @@ check ()
211 struct GNUNET_GETOPT_CommandLineOption options[] = { 210 struct GNUNET_GETOPT_CommandLineOption options[] = {
212 GNUNET_GETOPT_OPTION_END 211 GNUNET_GETOPT_OPTION_END
213 }; 212 };
214 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); 213
215 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); 214 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-1");
215 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-2");
216 216
217 ok = 1; 217 ok = 1;
218 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 218 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
219 argv, 219 argv,
220 "test-core-api-start-only", 220 "test-core-api-start-only",
221 "nohelp", 221 "nohelp",
222 options, 222 options,
223 &run, 223 &run,
224 &ok); 224 &ok);
225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 225 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
226 "Test finished\n"); 226 "Test finished\n");
227 stop_arm (&p1); 227 stop_arm(&p1);
228 stop_arm (&p2); 228 stop_arm(&p2);
229 return ok; 229 return ok;
230} 230}
231 231
232 232
233int 233int
234main (int argc, 234main(int argc,
235 char *argv[]) 235 char *argv[])
236{ 236{
237 int ret; 237 int ret;
238 238
239 GNUNET_log_setup ("test-core-api-start-only", 239 GNUNET_log_setup("test-core-api-start-only",
240 "WARNING", 240 "WARNING",
241 NULL); 241 NULL);
242 ret = check (); 242 ret = check();
243 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1"); 243 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-1");
244 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2"); 244 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-peer-2");
245 return ret; 245 return ret;
246} 246}
247 247
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index 908d90ac3..9db9ab750 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -16,7 +16,7 @@
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 * @file core/test_core_quota_compliance.c 21 * @file core/test_core_quota_compliance.c
22 * @brief testcase for core_api.c focusing quota compliance on core level 22 * @brief testcase for core_api.c focusing quota compliance on core level
@@ -46,16 +46,16 @@
46/** 46/**
47 * How long until we give up on transmitting the message? 47 * How long until we give up on transmitting the message?
48 */ 48 */
49#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) 49#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300)
50 50
51/** 51/**
52 * What delay do we request from the core service for transmission? 52 * What delay do we request from the core service for transmission?
53 */ 53 */
54#define FAST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 150) 54#define FAST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 150)
55 55
56#define MTYPE 12345 56#define MTYPE 12345
57#define MESSAGESIZE (1024 - 8) 57#define MESSAGESIZE (1024 - 8)
58#define MEASUREMENT_LENGTH GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 58#define MEASUREMENT_LENGTH GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30)
59 59
60static unsigned long long total_bytes_sent; 60static unsigned long long total_bytes_sent;
61static unsigned long long total_bytes_recv; 61static unsigned long long total_bytes_recv;
@@ -67,8 +67,7 @@ static struct GNUNET_SCHEDULER_Task *err_task;
67static struct GNUNET_SCHEDULER_Task *measure_task; 67static struct GNUNET_SCHEDULER_Task *measure_task;
68 68
69 69
70struct PeerContext 70struct PeerContext {
71{
72 struct GNUNET_CONFIGURATION_Handle *cfg; 71 struct GNUNET_CONFIGURATION_Handle *cfg;
73 struct GNUNET_CORE_Handle *ch; 72 struct GNUNET_CORE_Handle *ch;
74 struct GNUNET_MQ_Handle *mq; 73 struct GNUNET_MQ_Handle *mq;
@@ -99,13 +98,12 @@ static int running;
99 98
100 99
101#if VERBOSE 100#if VERBOSE
102#define OKPP do { ok++; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 101#define OKPP do { ok++; GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
103#else 102#else
104#define OKPP do { ok++; } while (0) 103#define OKPP do { ok++; } while (0)
105#endif 104#endif
106 105
107struct TestMessage 106struct TestMessage {
108{
109 struct GNUNET_MessageHeader header; 107 struct GNUNET_MessageHeader header;
110 uint32_t num GNUNET_PACKED; 108 uint32_t num GNUNET_PACKED;
111 uint8_t pad[MESSAGESIZE]; 109 uint8_t pad[MESSAGESIZE];
@@ -113,71 +111,71 @@ struct TestMessage
113 111
114 112
115static void 113static void
116terminate_peer (struct PeerContext *p) 114terminate_peer(struct PeerContext *p)
117{ 115{
118 if (NULL != p->ch) 116 if (NULL != p->ch)
119 { 117 {
120 GNUNET_CORE_disconnect (p->ch); 118 GNUNET_CORE_disconnect(p->ch);
121 p->ch = NULL; 119 p->ch = NULL;
122 } 120 }
123 if (NULL != p->ghh) 121 if (NULL != p->ghh)
124 { 122 {
125 GNUNET_TRANSPORT_hello_get_cancel (p->ghh); 123 GNUNET_TRANSPORT_hello_get_cancel(p->ghh);
126 p->ghh = NULL; 124 p->ghh = NULL;
127 } 125 }
128 if (NULL != p->oh) 126 if (NULL != p->oh)
129 { 127 {
130 GNUNET_TRANSPORT_offer_hello_cancel (p->oh); 128 GNUNET_TRANSPORT_offer_hello_cancel(p->oh);
131 p->oh = NULL; 129 p->oh = NULL;
132 } 130 }
133 if (NULL != p->ats_sh) 131 if (NULL != p->ats_sh)
134 { 132 {
135 GNUNET_ATS_connectivity_suggest_cancel (p->ats_sh); 133 GNUNET_ATS_connectivity_suggest_cancel(p->ats_sh);
136 p->ats_sh = NULL; 134 p->ats_sh = NULL;
137 } 135 }
138 if (NULL != p->ats) 136 if (NULL != p->ats)
139 { 137 {
140 GNUNET_ATS_connectivity_done (p->ats); 138 GNUNET_ATS_connectivity_done(p->ats);
141 p->ats = NULL; 139 p->ats = NULL;
142 } 140 }
143 if (NULL != p->stats) 141 if (NULL != p->stats)
144 { 142 {
145 GNUNET_STATISTICS_destroy (p->stats, GNUNET_NO); 143 GNUNET_STATISTICS_destroy(p->stats, GNUNET_NO);
146 p->stats = NULL; 144 p->stats = NULL;
147 } 145 }
148 if (NULL != p->hello) 146 if (NULL != p->hello)
149 { 147 {
150 GNUNET_free (p->hello); 148 GNUNET_free(p->hello);
151 p->hello = NULL; 149 p->hello = NULL;
152 } 150 }
153} 151}
154 152
155 153
156static void 154static void
157shutdown_task (void *cls) 155shutdown_task(void *cls)
158{ 156{
159 if (NULL != err_task) 157 if (NULL != err_task)
160 { 158 {
161 GNUNET_SCHEDULER_cancel (err_task); 159 GNUNET_SCHEDULER_cancel(err_task);
162 err_task = NULL; 160 err_task = NULL;
163 } 161 }
164 if (NULL != measure_task) 162 if (NULL != measure_task)
165 { 163 {
166 GNUNET_SCHEDULER_cancel (measure_task); 164 GNUNET_SCHEDULER_cancel(measure_task);
167 measure_task = NULL; 165 measure_task = NULL;
168 } 166 }
169 terminate_peer (&p1); 167 terminate_peer(&p1);
170 terminate_peer (&p2); 168 terminate_peer(&p2);
171} 169}
172 170
173 171
174static void 172static void
175terminate_task_error (void *cls) 173terminate_task_error(void *cls)
176{ 174{
177 err_task = NULL; 175 err_task = NULL;
178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 176 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
179 "Testcase failed (timeout)!\n"); 177 "Testcase failed (timeout)!\n");
180 GNUNET_SCHEDULER_shutdown (); 178 GNUNET_SCHEDULER_shutdown();
181 ok = 42; 179 ok = 42;
182} 180}
183 181
@@ -193,28 +191,28 @@ terminate_task_error (void *cls)
193 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration 191 * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
194 */ 192 */
195static int 193static int
196print_stat (void *cls, 194print_stat(void *cls,
197 const char *subsystem, 195 const char *subsystem,
198 const char *name, 196 const char *name,
199 uint64_t value, 197 uint64_t value,
200 int is_persistent) 198 int is_persistent)
201{ 199{
202 if (cls == &p1) 200 if (cls == &p1)
203 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 201 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
204 "Peer1 %50s = %12llu\n", 202 "Peer1 %50s = %12llu\n",
205 name, 203 name,
206 (unsigned long long) value); 204 (unsigned long long)value);
207 if (cls == &p2) 205 if (cls == &p2)
208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 206 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
209 "Peer2 %50s = %12llu\n", 207 "Peer2 %50s = %12llu\n",
210 name, 208 name,
211 (unsigned long long) value); 209 (unsigned long long)value);
212 return GNUNET_OK; 210 return GNUNET_OK;
213} 211}
214 212
215 213
216static void 214static void
217measurement_stop (void *cls) 215measurement_stop(void *cls)
218{ 216{
219 unsigned long long delta; 217 unsigned long long delta;
220 unsigned long long throughput_out; 218 unsigned long long throughput_out;
@@ -225,17 +223,17 @@ measurement_stop (void *cls)
225 enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG; 223 enum GNUNET_ErrorType kind = GNUNET_ERROR_TYPE_DEBUG;
226 224
227 measure_task = NULL; 225 measure_task = NULL;
228 fprintf (stdout, "%s", "\n"); 226 fprintf(stdout, "%s", "\n");
229 running = GNUNET_NO; 227 running = GNUNET_NO;
230 228
231 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value_us; 229 delta = GNUNET_TIME_absolute_get_duration(start_time).rel_value_us;
232 if (0 == delta) 230 if (0 == delta)
233 delta = 1; 231 delta = 1;
234 throughput_out = total_bytes_sent * 1000000LL / delta; /* convert to bytes/s */ 232 throughput_out = total_bytes_sent * 1000000LL / delta; /* convert to bytes/s */
235 throughput_in = total_bytes_recv * 1000000LL / delta; /* convert to bytes/s */ 233 throughput_in = total_bytes_recv * 1000000LL / delta; /* convert to bytes/s */
236 234
237 max_quota_in = GNUNET_MIN (current_quota_p1_in, current_quota_p2_in); 235 max_quota_in = GNUNET_MIN(current_quota_p1_in, current_quota_p2_in);
238 max_quota_out = GNUNET_MIN (current_quota_p1_out, current_quota_p2_out); 236 max_quota_out = GNUNET_MIN(current_quota_p1_out, current_quota_p2_out);
239 if (max_quota_out < max_quota_in) 237 if (max_quota_out < max_quota_in)
240 quota_delta = max_quota_in / 3; 238 quota_delta = max_quota_in / 3;
241 else 239 else
@@ -246,167 +244,170 @@ measurement_stop (void *cls)
246 ok = 1; /* fail */ 244 ok = 1; /* fail */
247 else 245 else
248 ok = 0; /* pass */ 246 ok = 0; /* pass */
249 GNUNET_STATISTICS_get (p1.stats, 247 GNUNET_STATISTICS_get(p1.stats,
250 "core", 248 "core",
251 "# discarded CORE_SEND requests", 249 "# discarded CORE_SEND requests",
252 NULL, 250 NULL,
253 &print_stat, 251 &print_stat,
254 &p1); 252 &p1);
255 GNUNET_STATISTICS_get (p1.stats, 253 GNUNET_STATISTICS_get(p1.stats,
256 "core", 254 "core",
257 "# discarded CORE_SEND request bytes", 255 "# discarded CORE_SEND request bytes",
258 NULL, 256 NULL,
259 &print_stat, 257 &print_stat,
260 &p1); 258 &p1);
261 GNUNET_STATISTICS_get (p1.stats, 259 GNUNET_STATISTICS_get(p1.stats,
262 "core", 260 "core",
263 "# discarded lower priority CORE_SEND requests", 261 "# discarded lower priority CORE_SEND requests",
264 NULL, 262 NULL,
265 &print_stat, 263 &print_stat,
266 NULL); 264 NULL);
267 GNUNET_STATISTICS_get (p1.stats, 265 GNUNET_STATISTICS_get(p1.stats,
268 "core", 266 "core",
269 "# discarded lower priority CORE_SEND request bytes", 267 "# discarded lower priority CORE_SEND request bytes",
270 NULL, 268 NULL,
271 &print_stat, 269 &print_stat,
272 &p1); 270 &p1);
273 GNUNET_STATISTICS_get (p2.stats, 271 GNUNET_STATISTICS_get(p2.stats,
274 "core", 272 "core",
275 "# discarded CORE_SEND requests", 273 "# discarded CORE_SEND requests",
276 NULL, 274 NULL,
277 &print_stat, 275 &print_stat,
278 &p2); 276 &p2);
279 277
280 GNUNET_STATISTICS_get (p2.stats, 278 GNUNET_STATISTICS_get(p2.stats,
281 "core", 279 "core",
282 "# discarded CORE_SEND request bytes", 280 "# discarded CORE_SEND request bytes",
283 NULL, 281 NULL,
284 &print_stat, 282 &print_stat,
285 &p2); 283 &p2);
286 GNUNET_STATISTICS_get (p2.stats, 284 GNUNET_STATISTICS_get(p2.stats,
287 "core", 285 "core",
288 "# discarded lower priority CORE_SEND requests", 286 "# discarded lower priority CORE_SEND requests",
289 NULL, 287 NULL,
290 &print_stat, 288 &print_stat,
291 &p2); 289 &p2);
292 GNUNET_STATISTICS_get (p2.stats, 290 GNUNET_STATISTICS_get(p2.stats,
293 "core", 291 "core",
294 "# discarded lower priority CORE_SEND request bytes", 292 "# discarded lower priority CORE_SEND request bytes",
295 NULL, 293 NULL,
296 &print_stat, 294 &print_stat,
297 &p2); 295 &p2);
298 296
299 if (ok != 0) 297 if (ok != 0)
300 kind = GNUNET_ERROR_TYPE_ERROR; 298 kind = GNUNET_ERROR_TYPE_ERROR;
301 switch (test) 299 switch (test)
302 { 300 {
303 case SYMMETRIC: 301 case SYMMETRIC:
304 GNUNET_log (kind, 302 GNUNET_log(kind,
305 "Core quota compliance test with symmetric quotas: %s\n", 303 "Core quota compliance test with symmetric quotas: %s\n",
306 (0 == ok) ? "PASSED" : "FAILED"); 304 (0 == ok) ? "PASSED" : "FAILED");
307 break; 305 break;
308 case ASYMMETRIC_SEND_LIMITED: 306
309 GNUNET_log (kind, 307 case ASYMMETRIC_SEND_LIMITED:
310 "Core quota compliance test with limited sender quota: %s\n", 308 GNUNET_log(kind,
311 (0 == ok) ? "PASSED" : "FAILED"); 309 "Core quota compliance test with limited sender quota: %s\n",
312 break; 310 (0 == ok) ? "PASSED" : "FAILED");
313 case ASYMMETRIC_RECV_LIMITED: 311 break;
314 GNUNET_log (kind, 312
315 "Core quota compliance test with limited receiver quota: %s\n", 313 case ASYMMETRIC_RECV_LIMITED:
316 (0 == ok) ? "PASSED" : "FAILED"); 314 GNUNET_log(kind,
317 break; 315 "Core quota compliance test with limited receiver quota: %s\n",
318 }; 316 (0 == ok) ? "PASSED" : "FAILED");
319 GNUNET_log (kind, 317 break;
320 "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n", 318 }
321 throughput_out, 319 ;
322 total_bytes_sent, 320 GNUNET_log(kind,
323 delta); 321 "Peer 1 send rate: %llu b/s (%llu bytes in %llu ms)\n",
324 GNUNET_log (kind, 322 throughput_out,
325 "Peer 1 send quota: %llu b/s\n", 323 total_bytes_sent,
326 current_quota_p1_out); 324 delta);
327 GNUNET_log (kind, 325 GNUNET_log(kind,
328 "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n", 326 "Peer 1 send quota: %llu b/s\n",
329 throughput_in, 327 current_quota_p1_out);
330 total_bytes_recv, 328 GNUNET_log(kind,
331 delta); 329 "Peer 2 receive rate: %llu b/s (%llu bytes in %llu ms)\n",
332 GNUNET_log (kind, 330 throughput_in,
333 "Peer 2 receive quota: %llu b/s\n", 331 total_bytes_recv,
334 current_quota_p2_in); 332 delta);
333 GNUNET_log(kind,
334 "Peer 2 receive quota: %llu b/s\n",
335 current_quota_p2_in);
335/* 336/*
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in ); 337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. inbound quota allowed: %llu b/s\n",max_quota_in );
337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out); 338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Max. outbound quota allowed: %llu b/s\n",max_quota_out);
338*/ 339 */
339 GNUNET_SCHEDULER_shutdown (); 340 GNUNET_SCHEDULER_shutdown();
340} 341}
341 342
342 343
343static void 344static void
344do_transmit (void *cls) 345do_transmit(void *cls)
345{ 346{
346 struct TestMessage *hdr; 347 struct TestMessage *hdr;
347 struct GNUNET_MQ_Envelope *env; 348 struct GNUNET_MQ_Envelope *env;
348 349
349 env = GNUNET_MQ_msg (hdr, 350 env = GNUNET_MQ_msg(hdr,
350 MTYPE); 351 MTYPE);
351 hdr->num = htonl (tr_n); 352 hdr->num = htonl(tr_n);
352 memset (&hdr->pad, 353 memset(&hdr->pad,
353 tr_n, 354 tr_n,
354 MESSAGESIZE); 355 MESSAGESIZE);
355 tr_n++; 356 tr_n++;
356 GNUNET_SCHEDULER_cancel (err_task); 357 GNUNET_SCHEDULER_cancel(err_task);
357 err_task = 358 err_task =
358 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 359 GNUNET_SCHEDULER_add_delayed(TIMEOUT,
359 &terminate_task_error, 360 &terminate_task_error,
360 NULL); 361 NULL);
361 total_bytes_sent += sizeof (struct TestMessage); 362 total_bytes_sent += sizeof(struct TestMessage);
362 GNUNET_MQ_send (p1.mq, 363 GNUNET_MQ_send(p1.mq,
363 env); 364 env);
364} 365}
365 366
366 367
367static void * 368static void *
368connect_notify (void *cls, 369connect_notify(void *cls,
369 const struct GNUNET_PeerIdentity *peer, 370 const struct GNUNET_PeerIdentity *peer,
370 struct GNUNET_MQ_Handle *mq) 371 struct GNUNET_MQ_Handle *mq)
371{ 372{
372 struct PeerContext *pc = cls; 373 struct PeerContext *pc = cls;
373 374
374 if (0 == memcmp (&pc->id, 375 if (0 == memcmp(&pc->id,
375 peer, 376 peer,
376 sizeof (struct GNUNET_PeerIdentity))) 377 sizeof(struct GNUNET_PeerIdentity)))
377 return NULL; /* loopback */ 378 return NULL; /* loopback */
378 GNUNET_assert (0 == pc->connect_status); 379 GNUNET_assert(0 == pc->connect_status);
379 pc->connect_status = 1; 380 pc->connect_status = 1;
380 pc->mq = mq; 381 pc->mq = mq;
381 if (pc == &p1) 382 if (pc == &p1)
382 { 383 {
383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 384 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
384 "Encrypted connection established to peer `%s'\n", 385 "Encrypted connection established to peer `%s'\n",
385 GNUNET_i2s (peer)); 386 GNUNET_i2s(peer));
386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 387 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
387 "Asking core (1) for transmission to peer `%s'\n", 388 "Asking core (1) for transmission to peer `%s'\n",
388 GNUNET_i2s (&p2.id)); 389 GNUNET_i2s(&p2.id));
389 GNUNET_SCHEDULER_cancel (err_task); 390 GNUNET_SCHEDULER_cancel(err_task);
390 err_task = 391 err_task =
391 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 392 GNUNET_SCHEDULER_add_delayed(TIMEOUT,
392 &terminate_task_error, 393 &terminate_task_error,
393 NULL); 394 NULL);
394 start_time = GNUNET_TIME_absolute_get (); 395 start_time = GNUNET_TIME_absolute_get();
395 running = GNUNET_YES; 396 running = GNUNET_YES;
396 measure_task = 397 measure_task =
397 GNUNET_SCHEDULER_add_delayed (MEASUREMENT_LENGTH, 398 GNUNET_SCHEDULER_add_delayed(MEASUREMENT_LENGTH,
398 &measurement_stop, 399 &measurement_stop,
399 NULL); 400 NULL);
400 do_transmit (NULL); 401 do_transmit(NULL);
401 } 402 }
402 return pc; 403 return pc;
403} 404}
404 405
405 406
406static void 407static void
407disconnect_notify (void *cls, 408disconnect_notify(void *cls,
408 const struct GNUNET_PeerIdentity *peer, 409 const struct GNUNET_PeerIdentity *peer,
409 void *internal_cls) 410 void *internal_cls)
410{ 411{
411 struct PeerContext *pc = cls; 412 struct PeerContext *pc = cls;
412 413
@@ -415,99 +416,99 @@ disconnect_notify (void *cls,
415 pc->connect_status = 0; 416 pc->connect_status = 0;
416 pc->mq = NULL; 417 pc->mq = NULL;
417 if (NULL != measure_task) 418 if (NULL != measure_task)
418 { 419 {
419 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 420 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
420 "Measurement aborted due to disconnect!\n"); 421 "Measurement aborted due to disconnect!\n");
421 GNUNET_SCHEDULER_cancel (measure_task); 422 GNUNET_SCHEDULER_cancel(measure_task);
422 measure_task = NULL; 423 measure_task = NULL;
423 } 424 }
424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 425 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
425 "Encrypted connection to `%s' cut\n", 426 "Encrypted connection to `%s' cut\n",
426 GNUNET_i2s (peer)); 427 GNUNET_i2s(peer));
427} 428}
428 429
429 430
430 431
431static void 432static void
432handle_test (void *cls, 433handle_test(void *cls,
433 const struct TestMessage *hdr) 434 const struct TestMessage *hdr)
434{ 435{
435 static int n; 436 static int n;
436 437
437 total_bytes_recv += sizeof (struct TestMessage); 438 total_bytes_recv += sizeof(struct TestMessage);
438 if (ntohl (hdr->num) != n) 439 if (ntohl(hdr->num) != n)
439 { 440 {
440 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 441 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
441 "Expected message %u, got message %u\n", 442 "Expected message %u, got message %u\n",
442 n, 443 n,
443 ntohl (hdr->num)); 444 ntohl(hdr->num));
444 GNUNET_SCHEDULER_cancel (err_task); 445 GNUNET_SCHEDULER_cancel(err_task);
445 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, 446 err_task = GNUNET_SCHEDULER_add_now(&terminate_task_error,
446 NULL); 447 NULL);
447 return; 448 return;
448 } 449 }
449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 450 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
450 "Got message %u\n", 451 "Got message %u\n",
451 ntohl (hdr->num)); 452 ntohl(hdr->num));
452 n++; 453 n++;
453 if (0 == (n % 10)) 454 if (0 == (n % 10))
454 fprintf (stderr, "%s", "."); 455 fprintf(stderr, "%s", ".");
455 456
456 if (GNUNET_YES == running) 457 if (GNUNET_YES == running)
457 do_transmit (NULL); 458 do_transmit(NULL);
458} 459}
459 460
460 461
461static void 462static void
462init_notify (void *cls, 463init_notify(void *cls,
463 const struct GNUNET_PeerIdentity *my_identity) 464 const struct GNUNET_PeerIdentity *my_identity)
464{ 465{
465 struct PeerContext *p = cls; 466 struct PeerContext *p = cls;
466 struct GNUNET_MQ_MessageHandler handlers[] = { 467 struct GNUNET_MQ_MessageHandler handlers[] = {
467 GNUNET_MQ_hd_fixed_size (test, 468 GNUNET_MQ_hd_fixed_size(test,
468 MTYPE, 469 MTYPE,
469 struct TestMessage, 470 struct TestMessage,
470 NULL), 471 NULL),
471 GNUNET_MQ_handler_end () 472 GNUNET_MQ_handler_end()
472 }; 473 };
473 474
474 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 475 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
475 "Connection to CORE service of `%s' established\n", 476 "Connection to CORE service of `%s' established\n",
476 GNUNET_i2s (my_identity)); 477 GNUNET_i2s(my_identity));
477 GNUNET_assert (NULL != my_identity); 478 GNUNET_assert(NULL != my_identity);
478 p->id = *my_identity; 479 p->id = *my_identity;
479 if (cls == &p1) 480 if (cls == &p1)
480 { 481 {
481 GNUNET_assert (ok == 2); 482 GNUNET_assert(ok == 2);
482 OKPP; 483 OKPP;
483 /* connect p2 */ 484 /* connect p2 */
484 p2.ch = GNUNET_CORE_connect (p2.cfg, 485 p2.ch = GNUNET_CORE_connect(p2.cfg,
485 &p2, 486 &p2,
486 &init_notify, 487 &init_notify,
487 &connect_notify, 488 &connect_notify,
488 &disconnect_notify, 489 &disconnect_notify,
489 handlers); 490 handlers);
490 } 491 }
491 else 492 else
492 { 493 {
493 GNUNET_assert (ok == 3); 494 GNUNET_assert(ok == 3);
494 OKPP; 495 OKPP;
495 GNUNET_assert (cls == &p2); 496 GNUNET_assert(cls == &p2);
496 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 497 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
497 "Asking core (1) to connect to peer `%s' and vice-versa\n", 498 "Asking core (1) to connect to peer `%s' and vice-versa\n",
498 GNUNET_i2s (&p2.id)); 499 GNUNET_i2s(&p2.id));
499 p1.ats_sh = GNUNET_ATS_connectivity_suggest (p1.ats, 500 p1.ats_sh = GNUNET_ATS_connectivity_suggest(p1.ats,
500 &p2.id, 501 &p2.id,
501 1); 502 1);
502 p2.ats_sh = GNUNET_ATS_connectivity_suggest (p2.ats, 503 p2.ats_sh = GNUNET_ATS_connectivity_suggest(p2.ats,
503 &p1.id, 504 &p1.id,
504 1); 505 1);
505 } 506 }
506} 507}
507 508
508 509
509static void 510static void
510offer_hello_done (void *cls) 511offer_hello_done(void *cls)
511{ 512{
512 struct PeerContext *p = cls; 513 struct PeerContext *p = cls;
513 514
@@ -516,175 +517,175 @@ offer_hello_done (void *cls)
516 517
517 518
518static void 519static void
519process_hello (void *cls, 520process_hello(void *cls,
520 const struct GNUNET_MessageHeader *message) 521 const struct GNUNET_MessageHeader *message)
521{ 522{
522 struct PeerContext *p = cls; 523 struct PeerContext *p = cls;
523 524
524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 525 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
525 "Received (my) HELLO from transport service\n"); 526 "Received (my) HELLO from transport service\n");
526 GNUNET_assert (message != NULL); 527 GNUNET_assert(message != NULL);
527 p->hello = GNUNET_malloc (ntohs (message->size)); 528 p->hello = GNUNET_malloc(ntohs(message->size));
528 GNUNET_memcpy (p->hello, message, ntohs (message->size)); 529 GNUNET_memcpy(p->hello, message, ntohs(message->size));
529 if ( (p == &p1) && 530 if ((p == &p1) &&
530 (NULL == p2.oh) ) 531 (NULL == p2.oh))
531 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, 532 p2.oh = GNUNET_TRANSPORT_offer_hello(p2.cfg,
532 message, 533 message,
533 &offer_hello_done, 534 &offer_hello_done,
534 &p2); 535 &p2);
535 if ( (p == &p2) && 536 if ((p == &p2) &&
536 (NULL == p1.oh) ) 537 (NULL == p1.oh))
537 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, message, 538 p1.oh = GNUNET_TRANSPORT_offer_hello(p1.cfg, message,
538 &offer_hello_done, 539 &offer_hello_done,
539 &p1); 540 &p1);
540 541
541 if ( (p == &p1) && 542 if ((p == &p1) &&
542 (NULL != p2.hello) && 543 (NULL != p2.hello) &&
543 (NULL == p1.oh) ) 544 (NULL == p1.oh))
544 p1.oh = GNUNET_TRANSPORT_offer_hello (p1.cfg, 545 p1.oh = GNUNET_TRANSPORT_offer_hello(p1.cfg,
545 p2.hello, 546 p2.hello,
546 &offer_hello_done, 547 &offer_hello_done,
547 &p1); 548 &p1);
548 if ( (p == &p2) && 549 if ((p == &p2) &&
549 (NULL != p1.hello) && 550 (NULL != p1.hello) &&
550 (NULL == p2.oh) ) 551 (NULL == p2.oh))
551 p2.oh = GNUNET_TRANSPORT_offer_hello (p2.cfg, 552 p2.oh = GNUNET_TRANSPORT_offer_hello(p2.cfg,
552 p1.hello, 553 p1.hello,
553 &offer_hello_done, 554 &offer_hello_done,
554 &p2); 555 &p2);
555} 556}
556 557
557 558
558static void 559static void
559setup_peer (struct PeerContext *p, 560setup_peer(struct PeerContext *p,
560 const char *cfgname) 561 const char *cfgname)
561{ 562{
562 char *binary; 563 char *binary;
563 564
564 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-service-arm"); 565 binary = GNUNET_OS_get_libexec_binary_path("gnunet-service-arm");
565 p->cfg = GNUNET_CONFIGURATION_create (); 566 p->cfg = GNUNET_CONFIGURATION_create();
566 p->arm_proc = 567 p->arm_proc =
567 GNUNET_OS_start_process (GNUNET_YES, 568 GNUNET_OS_start_process(GNUNET_YES,
568 GNUNET_OS_INHERIT_STD_OUT_AND_ERR, 569 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
569 NULL, NULL, NULL, 570 NULL, NULL, NULL,
570 binary, 571 binary,
571 "gnunet-service-arm", 572 "gnunet-service-arm",
572 "-c", 573 "-c",
573 cfgname, 574 cfgname,
574 NULL); 575 NULL);
575 GNUNET_assert (GNUNET_OK == 576 GNUNET_assert(GNUNET_OK ==
576 GNUNET_CONFIGURATION_load (p->cfg, 577 GNUNET_CONFIGURATION_load(p->cfg,
577 cfgname)); 578 cfgname));
578 p->stats = GNUNET_STATISTICS_create ("core", 579 p->stats = GNUNET_STATISTICS_create("core",
579 p->cfg); 580 p->cfg);
580 GNUNET_assert (NULL != p->stats); 581 GNUNET_assert(NULL != p->stats);
581 p->ats = GNUNET_ATS_connectivity_init (p->cfg); 582 p->ats = GNUNET_ATS_connectivity_init(p->cfg);
582 GNUNET_assert (NULL != p->ats); 583 GNUNET_assert(NULL != p->ats);
583 p->ghh = GNUNET_TRANSPORT_hello_get (p->cfg, 584 p->ghh = GNUNET_TRANSPORT_hello_get(p->cfg,
584 GNUNET_TRANSPORT_AC_ANY, 585 GNUNET_TRANSPORT_AC_ANY,
585 &process_hello, 586 &process_hello,
586 p); 587 p);
587 GNUNET_free (binary); 588 GNUNET_free(binary);
588} 589}
589 590
590 591
591static void 592static void
592run (void *cls, 593run(void *cls,
593 char *const *args, 594 char *const *args,
594 const char *cfgfile, 595 const char *cfgfile,
595 const struct GNUNET_CONFIGURATION_Handle *cfg) 596 const struct GNUNET_CONFIGURATION_Handle *cfg)
596{ 597{
597 struct GNUNET_MQ_MessageHandler handlers[] = { 598 struct GNUNET_MQ_MessageHandler handlers[] = {
598 GNUNET_MQ_hd_fixed_size (test, 599 GNUNET_MQ_hd_fixed_size(test,
599 MTYPE, 600 MTYPE,
600 struct TestMessage, 601 struct TestMessage,
601 NULL), 602 NULL),
602 GNUNET_MQ_handler_end () 603 GNUNET_MQ_handler_end()
603 }; 604 };
604 605
605 GNUNET_assert (ok == 1); 606 GNUNET_assert(ok == 1);
606 OKPP; 607 OKPP;
607 err_task = 608 err_task =
608 GNUNET_SCHEDULER_add_delayed (TIMEOUT, 609 GNUNET_SCHEDULER_add_delayed(TIMEOUT,
609 &terminate_task_error, 610 &terminate_task_error,
610 NULL); 611 NULL);
611 GNUNET_SCHEDULER_add_shutdown (&shutdown_task, 612 GNUNET_SCHEDULER_add_shutdown(&shutdown_task,
612 NULL); 613 NULL);
613 if (test == SYMMETRIC) 614 if (test == SYMMETRIC)
614 { 615 {
615 setup_peer (&p1, 616 setup_peer(&p1,
616 "test_core_quota_peer1.conf"); 617 "test_core_quota_peer1.conf");
617 setup_peer (&p2, 618 setup_peer(&p2,
618 "test_core_quota_peer2.conf"); 619 "test_core_quota_peer2.conf");
619 } 620 }
620 else if (test == ASYMMETRIC_SEND_LIMITED) 621 else if (test == ASYMMETRIC_SEND_LIMITED)
621 { 622 {
622 setup_peer (&p1, 623 setup_peer(&p1,
623 "test_core_quota_asymmetric_send_limit_peer1.conf"); 624 "test_core_quota_asymmetric_send_limit_peer1.conf");
624 setup_peer (&p2, 625 setup_peer(&p2,
625 "test_core_quota_asymmetric_send_limit_peer2.conf"); 626 "test_core_quota_asymmetric_send_limit_peer2.conf");
626 } 627 }
627 else if (test == ASYMMETRIC_RECV_LIMITED) 628 else if (test == ASYMMETRIC_RECV_LIMITED)
628 { 629 {
629 setup_peer (&p1, 630 setup_peer(&p1,
630 "test_core_quota_asymmetric_recv_limited_peer1.conf"); 631 "test_core_quota_asymmetric_recv_limited_peer1.conf");
631 setup_peer (&p2, 632 setup_peer(&p2,
632 "test_core_quota_asymmetric_recv_limited_peer2.conf"); 633 "test_core_quota_asymmetric_recv_limited_peer2.conf");
633 } 634 }
634 635
635 GNUNET_assert (test != -1); 636 GNUNET_assert(test != -1);
636 GNUNET_assert (GNUNET_SYSERR != 637 GNUNET_assert(GNUNET_SYSERR !=
637 GNUNET_CONFIGURATION_get_value_size (p1.cfg, 638 GNUNET_CONFIGURATION_get_value_size(p1.cfg,
638 "ATS", 639 "ATS",
639 "WAN_QUOTA_IN", 640 "WAN_QUOTA_IN",
640 &current_quota_p1_in)); 641 &current_quota_p1_in));
641 GNUNET_assert (GNUNET_SYSERR != 642 GNUNET_assert(GNUNET_SYSERR !=
642 GNUNET_CONFIGURATION_get_value_size (p2.cfg, 643 GNUNET_CONFIGURATION_get_value_size(p2.cfg,
643 "ATS", 644 "ATS",
644 "WAN_QUOTA_IN", 645 "WAN_QUOTA_IN",
645 &current_quota_p2_in)); 646 &current_quota_p2_in));
646 GNUNET_assert (GNUNET_SYSERR != 647 GNUNET_assert(GNUNET_SYSERR !=
647 GNUNET_CONFIGURATION_get_value_size (p1.cfg, 648 GNUNET_CONFIGURATION_get_value_size(p1.cfg,
648 "ATS", 649 "ATS",
649 "WAN_QUOTA_OUT", 650 "WAN_QUOTA_OUT",
650 &current_quota_p1_out)); 651 &current_quota_p1_out));
651 GNUNET_assert (GNUNET_SYSERR != 652 GNUNET_assert(GNUNET_SYSERR !=
652 GNUNET_CONFIGURATION_get_value_size (p2.cfg, 653 GNUNET_CONFIGURATION_get_value_size(p2.cfg,
653 "ATS", 654 "ATS",
654 "WAN_QUOTA_OUT", 655 "WAN_QUOTA_OUT",
655 &current_quota_p2_out)); 656 &current_quota_p2_out));
656 657
657 p1.ch = GNUNET_CORE_connect (p1.cfg, 658 p1.ch = GNUNET_CORE_connect(p1.cfg,
658 &p1, 659 &p1,
659 &init_notify, 660 &init_notify,
660 &connect_notify, 661 &connect_notify,
661 &disconnect_notify, 662 &disconnect_notify,
662 handlers); 663 handlers);
663} 664}
664 665
665 666
666static void 667static void
667stop_arm (struct PeerContext *p) 668stop_arm(struct PeerContext *p)
668{ 669{
669 if (0 != GNUNET_OS_process_kill (p->arm_proc, 670 if (0 != GNUNET_OS_process_kill(p->arm_proc,
670 GNUNET_TERM_SIG)) 671 GNUNET_TERM_SIG))
671 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 672 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING,
672 "kill"); 673 "kill");
673 if (GNUNET_OK != 674 if (GNUNET_OK !=
674 GNUNET_OS_process_wait (p->arm_proc)) 675 GNUNET_OS_process_wait(p->arm_proc))
675 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 676 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING,
676 "waitpid"); 677 "waitpid");
677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 678 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
678 "ARM process %u stopped\n", 679 "ARM process %u stopped\n",
679 GNUNET_OS_process_get_pid (p->arm_proc)); 680 GNUNET_OS_process_get_pid(p->arm_proc));
680 GNUNET_OS_process_destroy (p->arm_proc); 681 GNUNET_OS_process_destroy(p->arm_proc);
681 p->arm_proc = NULL; 682 p->arm_proc = NULL;
682 GNUNET_CONFIGURATION_destroy (p->cfg); 683 GNUNET_CONFIGURATION_destroy(p->cfg);
683} 684}
684 685
685 686
686static int 687static int
687check () 688check()
688{ 689{
689 char *const argv[] = { 690 char *const argv[] = {
690 "test-core-quota-compliance", 691 "test-core-quota-compliance",
@@ -695,73 +696,77 @@ check ()
695 struct GNUNET_GETOPT_CommandLineOption options[] = { 696 struct GNUNET_GETOPT_CommandLineOption options[] = {
696 GNUNET_GETOPT_OPTION_END 697 GNUNET_GETOPT_OPTION_END
697 }; 698 };
699
698 ok = 1; 700 ok = 1;
699 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 701 GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1,
700 argv, 702 argv,
701 "test-core-quota-compliance", 703 "test-core-quota-compliance",
702 "nohelp", 704 "nohelp",
703 options, 705 options,
704 &run, 706 &run,
705 &ok); 707 &ok);
706 stop_arm (&p1); 708 stop_arm(&p1);
707 stop_arm (&p2); 709 stop_arm(&p2);
708 return ok; 710 return ok;
709} 711}
710 712
711 713
712static void 714static void
713cleanup_directory (int test) 715cleanup_directory(int test)
714{ 716{
715 switch (test) { 717 switch (test)
716 case SYMMETRIC: 718 {
717 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-1/"); 719 case SYMMETRIC:
718 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-sym-peer-2/"); 720 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-quota-sym-peer-1/");
719 break; 721 GNUNET_DISK_directory_remove("/tmp/test-gnunet-core-quota-sym-peer-2/");
720 case ASYMMETRIC_SEND_LIMITED: 722 break;
721 GNUNET_DISK_directory_remove 723
724 case ASYMMETRIC_SEND_LIMITED:
725 GNUNET_DISK_directory_remove
722 ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/"); 726 ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-1/");
723 GNUNET_DISK_directory_remove 727 GNUNET_DISK_directory_remove
724 ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/"); 728 ("/tmp/test-gnunet-core-quota-asym-send-lim-peer-2/");
725 break; 729 break;
726 case ASYMMETRIC_RECV_LIMITED: 730
727 GNUNET_DISK_directory_remove 731 case ASYMMETRIC_RECV_LIMITED:
732 GNUNET_DISK_directory_remove
728 ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/"); 733 ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-1/");
729 GNUNET_DISK_directory_remove 734 GNUNET_DISK_directory_remove
730 ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/"); 735 ("/tmp/test-gnunet-core-quota-asym-recv-lim-peer-2/");
731 break; 736 break;
732 } 737 }
733} 738}
734 739
735 740
736int 741int
737main (int argc, 742main(int argc,
738 char *argv[]) 743 char *argv[])
739{ 744{
740 int ret; 745 int ret;
741 746
742 test = -1; 747 test = -1;
743 if (NULL != strstr (argv[0], 748 if (NULL != strstr(argv[0],
744 "_symmetric")) 749 "_symmetric"))
745 { 750 {
746 test = SYMMETRIC; 751 test = SYMMETRIC;
747 } 752 }
748 else if (NULL != strstr (argv[0], 753 else if (NULL != strstr(argv[0],
749 "_asymmetric_send")) 754 "_asymmetric_send"))
750 { 755 {
751 test = ASYMMETRIC_SEND_LIMITED; 756 test = ASYMMETRIC_SEND_LIMITED;
752 } 757 }
753 else if (NULL != strstr (argv[0], 758 else if (NULL != strstr(argv[0],
754 "_asymmetric_recv")) 759 "_asymmetric_recv"))
755 { 760 {
756 test = ASYMMETRIC_RECV_LIMITED; 761 test = ASYMMETRIC_RECV_LIMITED;
757 } 762 }
758 GNUNET_assert (test != -1); 763 GNUNET_assert(test != -1);
759 cleanup_directory (test); 764 cleanup_directory(test);
760 GNUNET_log_setup ("test-core-quota-compliance", 765 GNUNET_log_setup("test-core-quota-compliance",
761 "WARNING", 766 "WARNING",
762 NULL); 767 NULL);
763 ret = check (); 768 ret = check();
764 cleanup_directory (test); 769 cleanup_directory(test);
765 return ret; 770 return ret;
766} 771}
767 772