aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-service-core_sessions.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/gnunet-service-core_sessions.c')
-rw-r--r--src/core/gnunet-service-core_sessions.c814
1 files changed, 409 insertions, 405 deletions
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 */