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