summaryrefslogtreecommitdiff
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.c819
1 files changed, 407 insertions, 412 deletions
diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c
index 8ff61ec20..daca22aef 100644
--- a/src/core/gnunet-service-core_sessions.c
+++ b/src/core/gnunet-service-core_sessions.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file core/gnunet-service-core_sessions.c 22 * @file core/gnunet-service-core_sessions.c
@@ -43,9 +43,7 @@
43 * Message ready for encryption. This struct is followed by the 43 * Message ready for encryption. This struct is followed by the
44 * actual content of the message. 44 * actual content of the message.
45 */ 45 */
46struct SessionMessageEntry 46struct SessionMessageEntry {
47{
48
49 /** 47 /**
50 * We keep messages in a doubly linked list. 48 * We keep messages in a doubly linked list.
51 */ 49 */
@@ -90,8 +88,7 @@ struct SessionMessageEntry
90/** 88/**
91 * Data kept per session. 89 * Data kept per session.
92 */ 90 */
93struct Session 91struct Session {
94{
95 /** 92 /**
96 * Identity of the other peer. 93 * Identity of the other peer.
97 */ 94 */
@@ -159,9 +156,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
159/** 156/**
160 * Message sent to confirm that a typemap was received. 157 * Message sent to confirm that a typemap was received.
161 */ 158 */
162struct TypeMapConfirmationMessage 159struct TypeMapConfirmationMessage {
163{
164
165 /** 160 /**
166 * Header with type #GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP. 161 * Header with type #GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP.
167 */ 162 */
@@ -195,11 +190,11 @@ static struct GNUNET_CONTAINER_MultiPeerMap *sessions;
195 * session handle 190 * session handle
196 */ 191 */
197static struct Session * 192static struct Session *
198find_session (const struct GNUNET_PeerIdentity *peer) 193find_session(const struct GNUNET_PeerIdentity *peer)
199{ 194{
200 if (NULL == sessions) 195 if (NULL == sessions)
201 return NULL; 196 return NULL;
202 return GNUNET_CONTAINER_multipeermap_get (sessions, peer); 197 return GNUNET_CONTAINER_multipeermap_get(sessions, peer);
203} 198}
204 199
205 200
@@ -210,53 +205,53 @@ find_session (const struct GNUNET_PeerIdentity *peer)
210 * @param pid identity of peer to kill session with 205 * @param pid identity of peer to kill session with
211 */ 206 */
212void 207void
213GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid) 208GSC_SESSIONS_end(const struct GNUNET_PeerIdentity *pid)
214{ 209{
215 struct Session *session; 210 struct Session *session;
216 struct GSC_ClientActiveRequest *car; 211 struct GSC_ClientActiveRequest *car;
217 struct SessionMessageEntry *sme; 212 struct SessionMessageEntry *sme;
218 213
219 session = find_session (pid); 214 session = find_session(pid);
220 if (NULL == session) 215 if (NULL == session)
221 return; 216 return;
222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 217 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
223 "Destroying session for peer `%s'\n", 218 "Destroying session for peer `%s'\n",
224 GNUNET_i2s (session->peer)); 219 GNUNET_i2s(session->peer));
225 if (NULL != session->cork_task) 220 if (NULL != session->cork_task)
226 { 221 {
227 GNUNET_SCHEDULER_cancel (session->cork_task); 222 GNUNET_SCHEDULER_cancel(session->cork_task);
228 session->cork_task = NULL; 223 session->cork_task = NULL;
229 } 224 }
230 while (NULL != (car = session->active_client_request_head)) 225 while (NULL != (car = session->active_client_request_head))
231 { 226 {
232 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, 227 GNUNET_CONTAINER_DLL_remove(session->active_client_request_head,
233 session->active_client_request_tail, 228 session->active_client_request_tail,
234 car); 229 car);
235 GSC_CLIENTS_reject_request (car, GNUNET_NO); 230 GSC_CLIENTS_reject_request(car, GNUNET_NO);
236 } 231 }
237 while (NULL != (sme = session->sme_head)) 232 while (NULL != (sme = session->sme_head))
238 { 233 {
239 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme); 234 GNUNET_CONTAINER_DLL_remove(session->sme_head, session->sme_tail, sme);
240 GNUNET_free (sme); 235 GNUNET_free(sme);
241 } 236 }
242 if (NULL != session->typemap_task) 237 if (NULL != session->typemap_task)
243 { 238 {
244 GNUNET_SCHEDULER_cancel (session->typemap_task); 239 GNUNET_SCHEDULER_cancel(session->typemap_task);
245 session->typemap_task = NULL; 240 session->typemap_task = NULL;
246 } 241 }
247 GSC_CLIENTS_notify_clients_about_neighbour (session->peer, 242 GSC_CLIENTS_notify_clients_about_neighbour(session->peer,
248 session->tmap, 243 session->tmap,
249 NULL); 244 NULL);
250 GNUNET_assert ( 245 GNUNET_assert(
251 GNUNET_YES == 246 GNUNET_YES ==
252 GNUNET_CONTAINER_multipeermap_remove (sessions, session->peer, session)); 247 GNUNET_CONTAINER_multipeermap_remove(sessions, session->peer, session));
253 GNUNET_STATISTICS_set (GSC_stats, 248 GNUNET_STATISTICS_set(GSC_stats,
254 gettext_noop ("# peers connected"), 249 gettext_noop("# peers connected"),
255 GNUNET_CONTAINER_multipeermap_size (sessions), 250 GNUNET_CONTAINER_multipeermap_size(sessions),
256 GNUNET_NO); 251 GNUNET_NO);
257 GSC_TYPEMAP_destroy (session->tmap); 252 GSC_TYPEMAP_destroy(session->tmap);
258 session->tmap = NULL; 253 session->tmap = NULL;
259 GNUNET_free (session); 254 GNUNET_free(session);
260} 255}
261 256
262 257
@@ -267,29 +262,29 @@ GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
267 * @param cls the `struct Session *` 262 * @param cls the `struct Session *`
268 */ 263 */
269static void 264static void
270transmit_typemap_task (void *cls) 265transmit_typemap_task(void *cls)
271{ 266{
272 struct Session *session = cls; 267 struct Session *session = cls;
273 struct GNUNET_MessageHeader *hdr; 268 struct GNUNET_MessageHeader *hdr;
274 struct GNUNET_TIME_Relative delay; 269 struct GNUNET_TIME_Relative delay;
275 270
276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 271 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
277 "Sending TYPEMAP to %s\n", 272 "Sending TYPEMAP to %s\n",
278 GNUNET_i2s (session->peer)); 273 GNUNET_i2s(session->peer));
279 session->typemap_delay = GNUNET_TIME_STD_BACKOFF (session->typemap_delay); 274 session->typemap_delay = GNUNET_TIME_STD_BACKOFF(session->typemap_delay);
280 delay = session->typemap_delay; 275 delay = session->typemap_delay;
281 /* randomize a bit to avoid spont. sync */ 276 /* randomize a bit to avoid spont. sync */
282 delay.rel_value_us += 277 delay.rel_value_us +=
283 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000 * 1000); 278 GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 1000 * 1000);
284 session->typemap_task = 279 session->typemap_task =
285 GNUNET_SCHEDULER_add_delayed (delay, &transmit_typemap_task, session); 280 GNUNET_SCHEDULER_add_delayed(delay, &transmit_typemap_task, session);
286 GNUNET_STATISTICS_update (GSC_stats, 281 GNUNET_STATISTICS_update(GSC_stats,
287 gettext_noop ("# type map refreshes sent"), 282 gettext_noop("# type map refreshes sent"),
288 1, 283 1,
289 GNUNET_NO); 284 GNUNET_NO);
290 hdr = GSC_TYPEMAP_compute_type_map_message (); 285 hdr = GSC_TYPEMAP_compute_type_map_message();
291 GSC_KX_encrypt_and_transmit (session->kx, hdr, ntohs (hdr->size)); 286 GSC_KX_encrypt_and_transmit(session->kx, hdr, ntohs(hdr->size));
292 GNUNET_free (hdr); 287 GNUNET_free(hdr);
293} 288}
294 289
295 290
@@ -299,14 +294,14 @@ transmit_typemap_task (void *cls)
299 * @param session session to restart typemap transmission for 294 * @param session session to restart typemap transmission for
300 */ 295 */
301static void 296static void
302start_typemap_task (struct Session *session) 297start_typemap_task(struct Session *session)
303{ 298{
304 if (NULL != session->typemap_task) 299 if (NULL != session->typemap_task)
305 GNUNET_SCHEDULER_cancel (session->typemap_task); 300 GNUNET_SCHEDULER_cancel(session->typemap_task);
306 session->typemap_delay = GNUNET_TIME_UNIT_SECONDS; 301 session->typemap_delay = GNUNET_TIME_UNIT_SECONDS;
307 session->typemap_task = GNUNET_SCHEDULER_add_delayed (session->typemap_delay, 302 session->typemap_task = GNUNET_SCHEDULER_add_delayed(session->typemap_delay,
308 &transmit_typemap_task, 303 &transmit_typemap_task,
309 session); 304 session);
310} 305}
311 306
312 307
@@ -317,30 +312,30 @@ start_typemap_task (struct Session *session)
317 * @param kx key exchange that completed 312 * @param kx key exchange that completed
318 */ 313 */
319void 314void
320GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, 315GSC_SESSIONS_create(const struct GNUNET_PeerIdentity *peer,
321 struct GSC_KeyExchangeInfo *kx) 316 struct GSC_KeyExchangeInfo *kx)
322{ 317{
323 struct Session *session; 318 struct Session *session;
324 319
325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 320 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
326 "Creating session for peer `%s'\n", 321 "Creating session for peer `%s'\n",
327 GNUNET_i2s (peer)); 322 GNUNET_i2s(peer));
328 session = GNUNET_new (struct Session); 323 session = GNUNET_new(struct Session);
329 session->tmap = GSC_TYPEMAP_create (); 324 session->tmap = GSC_TYPEMAP_create();
330 session->peer = peer; 325 session->peer = peer;
331 session->kx = kx; 326 session->kx = kx;
332 GNUNET_assert (GNUNET_OK == 327 GNUNET_assert(GNUNET_OK ==
333 GNUNET_CONTAINER_multipeermap_put ( 328 GNUNET_CONTAINER_multipeermap_put(
334 sessions, 329 sessions,
335 session->peer, 330 session->peer,
336 session, 331 session,
337 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 332 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
338 GNUNET_STATISTICS_set (GSC_stats, 333 GNUNET_STATISTICS_set(GSC_stats,
339 gettext_noop ("# peers connected"), 334 gettext_noop("# peers connected"),
340 GNUNET_CONTAINER_multipeermap_size (sessions), 335 GNUNET_CONTAINER_multipeermap_size(sessions),
341 GNUNET_NO); 336 GNUNET_NO);
342 GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, session->tmap); 337 GSC_CLIENTS_notify_clients_about_neighbour(peer, NULL, session->tmap);
343 start_typemap_task (session); 338 start_typemap_task(session);
344} 339}
345 340
346 341
@@ -352,18 +347,18 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
352 * @param peer peer that is now connected 347 * @param peer peer that is now connected
353 */ 348 */
354void 349void
355GSC_SESSIONS_reinit (const struct GNUNET_PeerIdentity *peer) 350GSC_SESSIONS_reinit(const struct GNUNET_PeerIdentity *peer)
356{ 351{
357 struct Session *session; 352 struct Session *session;
358 353
359 session = find_session (peer); 354 session = find_session(peer);
360 if (NULL == session) 355 if (NULL == session)
361 { 356 {
362 /* KX/session is new for both sides; thus no need to restart what 357 /* KX/session is new for both sides; thus no need to restart what
363 has not yet begun */ 358 has not yet begun */
364 return; 359 return;
365 } 360 }
366 start_typemap_task (session); 361 start_typemap_task(session);
367} 362}
368 363
369 364
@@ -375,51 +370,51 @@ GSC_SESSIONS_reinit (const struct GNUNET_PeerIdentity *peer)
375 * @param msg confirmation message we received 370 * @param msg confirmation message we received
376 */ 371 */
377void 372void
378GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer, 373GSC_SESSIONS_confirm_typemap(const struct GNUNET_PeerIdentity *peer,
379 const struct GNUNET_MessageHeader *msg) 374 const struct GNUNET_MessageHeader *msg)
380{ 375{
381 const struct TypeMapConfirmationMessage *cmsg; 376 const struct TypeMapConfirmationMessage *cmsg;
382 struct Session *session; 377 struct Session *session;
383 378
384 session = find_session (peer); 379 session = find_session(peer);
385 if (NULL == session) 380 if (NULL == session)
386 { 381 {
387 GNUNET_break (0); 382 GNUNET_break(0);
388 return; 383 return;
389 } 384 }
390 if (ntohs (msg->size) != sizeof (struct TypeMapConfirmationMessage)) 385 if (ntohs(msg->size) != sizeof(struct TypeMapConfirmationMessage))
391 { 386 {
392 GNUNET_break_op (0); 387 GNUNET_break_op(0);
393 return; 388 return;
394 } 389 }
395 cmsg = (const struct TypeMapConfirmationMessage *) msg; 390 cmsg = (const struct TypeMapConfirmationMessage *)msg;
396 if (GNUNET_YES != GSC_TYPEMAP_check_hash (&cmsg->tm_hash)) 391 if (GNUNET_YES != GSC_TYPEMAP_check_hash(&cmsg->tm_hash))
397 { 392 {
398 /* our typemap has changed in the meantime, do not 393 /* our typemap has changed in the meantime, do not
399 accept confirmation */ 394 accept confirmation */
400 GNUNET_STATISTICS_update (GSC_stats, 395 GNUNET_STATISTICS_update(GSC_stats,
401 gettext_noop ( 396 gettext_noop(
402 "# outdated typemap confirmations received"), 397 "# outdated typemap confirmations received"),
403 1, 398 1,
404 GNUNET_NO); 399 GNUNET_NO);
405 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 400 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
406 "Got outdated typemap confirmated from peer `%s'\n", 401 "Got outdated typemap confirmated from peer `%s'\n",
407 GNUNET_i2s (session->peer)); 402 GNUNET_i2s(session->peer));
408 return; 403 return;
409 } 404 }
410 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 405 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
411 "Got typemap confirmation from peer `%s'\n", 406 "Got typemap confirmation from peer `%s'\n",
412 GNUNET_i2s (session->peer)); 407 GNUNET_i2s(session->peer));
413 if (NULL != session->typemap_task) 408 if (NULL != session->typemap_task)
414 { 409 {
415 GNUNET_SCHEDULER_cancel (session->typemap_task); 410 GNUNET_SCHEDULER_cancel(session->typemap_task);
416 session->typemap_task = NULL; 411 session->typemap_task = NULL;
417 } 412 }
418 GNUNET_STATISTICS_update (GSC_stats, 413 GNUNET_STATISTICS_update(GSC_stats,
419 gettext_noop ( 414 gettext_noop(
420 "# valid typemap confirmations received"), 415 "# valid typemap confirmations received"),
421 1, 416 1,
422 GNUNET_NO); 417 GNUNET_NO);
423} 418}
424 419
425 420
@@ -432,17 +427,17 @@ GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer,
432 * @return #GNUNET_OK (continue to iterate) 427 * @return #GNUNET_OK (continue to iterate)
433 */ 428 */
434static int 429static int
435notify_client_about_session (void *cls, 430notify_client_about_session(void *cls,
436 const struct GNUNET_PeerIdentity *key, 431 const struct GNUNET_PeerIdentity *key,
437 void *value) 432 void *value)
438{ 433{
439 struct GSC_Client *client = cls; 434 struct GSC_Client *client = cls;
440 struct Session *session = value; 435 struct Session *session = value;
441 436
442 GSC_CLIENTS_notify_client_about_neighbour (client, 437 GSC_CLIENTS_notify_client_about_neighbour(client,
443 session->peer, 438 session->peer,
444 NULL, /* old TMAP: none */ 439 NULL, /* old TMAP: none */
445 session->tmap); 440 session->tmap);
446 return GNUNET_OK; 441 return GNUNET_OK;
447} 442}
448 443
@@ -453,12 +448,12 @@ notify_client_about_session (void *cls,
453 * @param client the new client 448 * @param client the new client
454 */ 449 */
455void 450void
456GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client) 451GSC_SESSIONS_notify_client_about_sessions(struct GSC_Client *client)
457{ 452{
458 /* notify new client about existing sessions */ 453 /* notify new client about existing sessions */
459 GNUNET_CONTAINER_multipeermap_iterate (sessions, 454 GNUNET_CONTAINER_multipeermap_iterate(sessions,
460 &notify_client_about_session, 455 &notify_client_about_session,
461 client); 456 client);
462} 457}
463 458
464 459
@@ -469,7 +464,7 @@ GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client)
469 * @param session session to transmit messages from 464 * @param session session to transmit messages from
470 */ 465 */
471static void 466static void
472try_transmission (struct Session *session); 467try_transmission(struct Session *session);
473 468
474 469
475/** 470/**
@@ -482,31 +477,31 @@ try_transmission (struct Session *session);
482 * have been invoked on it 477 * have been invoked on it
483 */ 478 */
484void 479void
485GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car) 480GSC_SESSIONS_queue_request(struct GSC_ClientActiveRequest *car)
486{ 481{
487 struct Session *session; 482 struct Session *session;
488 483
489 session = find_session (&car->target); 484 session = find_session(&car->target);
490 if (NULL == session) 485 if (NULL == session)
491 { 486 {
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 487 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
493 "Dropped client request for transmission (am disconnected)\n"); 488 "Dropped client request for transmission (am disconnected)\n");
494 GNUNET_break (0); /* should have been rejected earlier */ 489 GNUNET_break(0); /* should have been rejected earlier */
495 GSC_CLIENTS_reject_request (car, GNUNET_NO); 490 GSC_CLIENTS_reject_request(car, GNUNET_NO);
496 return; 491 return;
497 } 492 }
498 if (car->msize > GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 493 if (car->msize > GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
499 { 494 {
500 GNUNET_break (0); 495 GNUNET_break(0);
501 GSC_CLIENTS_reject_request (car, GNUNET_YES); 496 GSC_CLIENTS_reject_request(car, GNUNET_YES);
502 return; 497 return;
503 } 498 }
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 499 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
505 "Received client transmission request. queueing\n"); 500 "Received client transmission request. queueing\n");
506 GNUNET_CONTAINER_DLL_insert_tail (session->active_client_request_head, 501 GNUNET_CONTAINER_DLL_insert_tail(session->active_client_request_head,
507 session->active_client_request_tail, 502 session->active_client_request_tail,
508 car); 503 car);
509 try_transmission (session); 504 try_transmission(session);
510} 505}
511 506
512 507
@@ -517,23 +512,23 @@ GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car)
517 * the caller (CLIENTS sysbsystem) 512 * the caller (CLIENTS sysbsystem)
518 */ 513 */
519void 514void
520GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car) 515GSC_SESSIONS_dequeue_request(struct GSC_ClientActiveRequest *car)
521{ 516{
522 struct Session *session; 517 struct Session *session;
523 518
524 if (0 == memcmp (&car->target, 519 if (0 == memcmp(&car->target,
525 &GSC_my_identity, 520 &GSC_my_identity,
526 sizeof (struct GNUNET_PeerIdentity))) 521 sizeof(struct GNUNET_PeerIdentity)))
527 return; 522 return;
528 session = find_session (&car->target); 523 session = find_session(&car->target);
529 GNUNET_assert (NULL != session); 524 GNUNET_assert(NULL != session);
530 GNUNET_CONTAINER_DLL_remove (session->active_client_request_head, 525 GNUNET_CONTAINER_DLL_remove(session->active_client_request_head,
531 session->active_client_request_tail, 526 session->active_client_request_tail,
532 car); 527 car);
533 /* dequeueing of 'high' priority messages may unblock 528 /* dequeueing of 'high' priority messages may unblock
534 transmission for lower-priority messages, so we also 529 transmission for lower-priority messages, so we also
535 need to try in this case. */ 530 need to try in this case. */
536 try_transmission (session); 531 try_transmission(session);
537} 532}
538 533
539 534
@@ -545,7 +540,7 @@ GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car)
545 * @param msize how many bytes do we have already 540 * @param msize how many bytes do we have already
546 */ 541 */
547static void 542static void
548solicit_messages (struct Session *session, size_t msize) 543solicit_messages(struct Session *session, size_t msize)
549{ 544{
550 struct GSC_ClientActiveRequest *car; 545 struct GSC_ClientActiveRequest *car;
551 struct GSC_ClientActiveRequest *nxt; 546 struct GSC_ClientActiveRequest *nxt;
@@ -555,33 +550,33 @@ solicit_messages (struct Session *session, size_t msize)
555 so_size = msize; 550 so_size = msize;
556 pmax = GNUNET_MQ_PRIO_BACKGROUND; 551 pmax = GNUNET_MQ_PRIO_BACKGROUND;
557 for (car = session->active_client_request_head; NULL != car; car = car->next) 552 for (car = session->active_client_request_head; NULL != car; car = car->next)
558 { 553 {
559 if (GNUNET_YES == car->was_solicited) 554 if (GNUNET_YES == car->was_solicited)
560 continue; 555 continue;
561 pmax = GNUNET_MAX (pmax, car->priority & GNUNET_MQ_PRIORITY_MASK); 556 pmax = GNUNET_MAX(pmax, car->priority & GNUNET_MQ_PRIORITY_MASK);
562 } 557 }
563 nxt = session->active_client_request_head; 558 nxt = session->active_client_request_head;
564 while (NULL != (car = nxt)) 559 while (NULL != (car = nxt))
565 { 560 {
566 nxt = car->next; 561 nxt = car->next;
567 if (car->priority < pmax) 562 if (car->priority < pmax)
568 continue; 563 continue;
569 if (so_size + car->msize > GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 564 if (so_size + car->msize > GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
570 break; 565 break;
571 so_size += car->msize; 566 so_size += car->msize;
572 if (GNUNET_YES == car->was_solicited) 567 if (GNUNET_YES == car->was_solicited)
573 continue; 568 continue;
574 car->was_solicited = GNUNET_YES; 569 car->was_solicited = GNUNET_YES;
575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 570 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
576 "Soliciting message with priority %u\n", 571 "Soliciting message with priority %u\n",
577 car->priority); 572 car->priority);
578 GSC_CLIENTS_solicit_request (car); 573 GSC_CLIENTS_solicit_request(car);
579 /* The above call may *dequeue* requests and thereby 574 /* The above call may *dequeue* requests and thereby
580 clobber 'nxt'. Hence we need to restart from the 575 clobber 'nxt'. Hence we need to restart from the
581 head of the list. */ 576 head of the list. */
582 nxt = session->active_client_request_head; 577 nxt = session->active_client_request_head;
583 so_size = msize; 578 so_size = msize;
584 } 579 }
585} 580}
586 581
587 582
@@ -592,12 +587,12 @@ solicit_messages (struct Session *session, size_t msize)
592 * @param cls `struct Session` with the messages to transmit now 587 * @param cls `struct Session` with the messages to transmit now
593 */ 588 */
594static void 589static void
595pop_cork_task (void *cls) 590pop_cork_task(void *cls)
596{ 591{
597 struct Session *session = cls; 592 struct Session *session = cls;
598 593
599 session->cork_task = NULL; 594 session->cork_task = NULL;
600 try_transmission (session); 595 try_transmission(session);
601} 596}
602 597
603 598
@@ -609,7 +604,7 @@ pop_cork_task (void *cls)
609 * @param session session to transmit messages from 604 * @param session session to transmit messages from
610 */ 605 */
611static void 606static void
612try_transmission (struct Session *session) 607try_transmission(struct Session *session)
613{ 608{
614 struct SessionMessageEntry *pos; 609 struct SessionMessageEntry *pos;
615 size_t msize; 610 size_t msize;
@@ -625,13 +620,13 @@ try_transmission (struct Session *session)
625 /* if the peer has excess bandwidth, background traffic is allowed, 620 /* if the peer has excess bandwidth, background traffic is allowed,
626 otherwise not */ 621 otherwise not */
627 if (MAX_ENCRYPTED_MESSAGE_QUEUE_SIZE <= 622 if (MAX_ENCRYPTED_MESSAGE_QUEUE_SIZE <=
628 GSC_NEIGHBOURS_get_queue_length (session->kx)) 623 GSC_NEIGHBOURS_get_queue_length(session->kx))
629 { 624 {
630 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 625 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
631 "Transmission queue already very long, waiting...\n"); 626 "Transmission queue already very long, waiting...\n");
632 return; /* queue already too long */ 627 return; /* queue already too long */
633 } 628 }
634 excess = GSC_NEIGHBOURS_check_excess_bandwidth (session->kx); 629 excess = GSC_NEIGHBOURS_check_excess_bandwidth(session->kx);
635 if (GNUNET_YES == excess) 630 if (GNUNET_YES == excess)
636 maxp = GNUNET_MQ_PRIO_BACKGROUND; 631 maxp = GNUNET_MQ_PRIO_BACKGROUND;
637 else 632 else
@@ -640,98 +635,98 @@ try_transmission (struct Session *session)
640 pos = session->sme_head; 635 pos = session->sme_head;
641 while ((NULL != pos) && 636 while ((NULL != pos) &&
642 (msize + pos->size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)) 637 (msize + pos->size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE))
643 { 638 {
644 GNUNET_assert (pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE); 639 GNUNET_assert(pos->size < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
645 msize += pos->size; 640 msize += pos->size;
646 maxp = GNUNET_MAX (maxp, pos->priority & GNUNET_MQ_PRIORITY_MASK); 641 maxp = GNUNET_MAX(maxp, pos->priority & GNUNET_MQ_PRIORITY_MASK);
647 min_deadline = GNUNET_TIME_absolute_min (min_deadline, pos->deadline); 642 min_deadline = GNUNET_TIME_absolute_min(min_deadline, pos->deadline);
648 pos = pos->next; 643 pos = pos->next;
649 } 644 }
650 GNUNET_log ( 645 GNUNET_log(
651 GNUNET_ERROR_TYPE_DEBUG, 646 GNUNET_ERROR_TYPE_DEBUG,
652 "Calculating transmission set with %u priority (%s) and %s earliest deadline\n", 647 "Calculating transmission set with %u priority (%s) and %s earliest deadline\n",
653 maxp, 648 maxp,
654 (GNUNET_YES == excess) ? "excess bandwidth" : "limited bandwidth", 649 (GNUNET_YES == excess) ? "excess bandwidth" : "limited bandwidth",
655 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining ( 650 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining(
656 min_deadline), 651 min_deadline),
657 GNUNET_YES)); 652 GNUNET_YES));
658 653
659 if (maxp < GNUNET_MQ_PRIO_CRITICAL_CONTROL) 654 if (maxp < GNUNET_MQ_PRIO_CRITICAL_CONTROL)
660 {
661 /* if highest already solicited priority from clients is not critical,
662 check if there are higher-priority messages to be solicited from clients */
663 if (GNUNET_YES == excess)
664 maxpc = GNUNET_MQ_PRIO_BACKGROUND;
665 else
666 maxpc = GNUNET_MQ_PRIO_BEST_EFFORT;
667 for (car = session->active_client_request_head; NULL != car;
668 car = car->next)
669 { 655 {
670 if (GNUNET_YES == car->was_solicited) 656 /* if highest already solicited priority from clients is not critical,
671 continue; 657 check if there are higher-priority messages to be solicited from clients */
672 maxpc = GNUNET_MAX (maxpc, car->priority & GNUNET_MQ_PRIORITY_MASK); 658 if (GNUNET_YES == excess)
659 maxpc = GNUNET_MQ_PRIO_BACKGROUND;
660 else
661 maxpc = GNUNET_MQ_PRIO_BEST_EFFORT;
662 for (car = session->active_client_request_head; NULL != car;
663 car = car->next)
664 {
665 if (GNUNET_YES == car->was_solicited)
666 continue;
667 maxpc = GNUNET_MAX(maxpc, car->priority & GNUNET_MQ_PRIORITY_MASK);
668 }
669 if (maxpc > maxp)
670 {
671 /* we have messages waiting for solicitation that have a higher
672 priority than those that we already accepted; solicit the
673 high-priority messages first */
674 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
675 "Soliciting messages based on priority (%u > %u)\n",
676 maxpc,
677 maxp);
678 solicit_messages(session, 0);
679 return;
680 }
673 } 681 }
674 if (maxpc > maxp) 682 else
675 { 683 {
676 /* we have messages waiting for solicitation that have a higher 684 /* never solicit more, we have critical messages to process */
677 priority than those that we already accepted; solicit the 685 excess = GNUNET_NO;
678 high-priority messages first */ 686 maxpc = GNUNET_MQ_PRIO_BACKGROUND;
679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
680 "Soliciting messages based on priority (%u > %u)\n",
681 maxpc,
682 maxp);
683 solicit_messages (session, 0);
684 return;
685 } 687 }
686 } 688 now = GNUNET_TIME_absolute_get();
687 else
688 {
689 /* never solicit more, we have critical messages to process */
690 excess = GNUNET_NO;
691 maxpc = GNUNET_MQ_PRIO_BACKGROUND;
692 }
693 now = GNUNET_TIME_absolute_get ();
694 if (((GNUNET_YES == excess) || (maxpc >= GNUNET_MQ_PRIO_BEST_EFFORT)) && 689 if (((GNUNET_YES == excess) || (maxpc >= GNUNET_MQ_PRIO_BEST_EFFORT)) &&
695 ((0 == msize) || 690 ((0 == msize) ||
696 ((msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) && 691 ((msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) &&
697 (min_deadline.abs_value_us > now.abs_value_us)))) 692 (min_deadline.abs_value_us > now.abs_value_us))))
698 {
699 /* not enough ready yet (tiny message & cork possible), or no messages at all,
700 and either excess bandwidth or best-effort or higher message waiting at
701 client; in this case, we try to solicit more */
702 GNUNET_log (
703 GNUNET_ERROR_TYPE_DEBUG,
704 "Soliciting messages (excess %d, maxpc %d, message size %u, deadline %s)\n",
705 excess,
706 maxpc,
707 (unsigned int) msize,
708 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_remaining (
709 min_deadline),
710 GNUNET_YES));
711 solicit_messages (session, msize);
712 if (msize > 0)
713 {
714 /* if there is data to send, just not yet, make sure we do transmit
715 * it once the deadline is reached */
716 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
717 "Corking until %s\n",
718 GNUNET_STRINGS_relative_time_to_string (
719 GNUNET_TIME_absolute_get_remaining (min_deadline),
720 GNUNET_YES));
721 if (NULL != session->cork_task)
722 GNUNET_SCHEDULER_cancel (session->cork_task);
723 session->cork_task =
724 GNUNET_SCHEDULER_add_at (min_deadline, &pop_cork_task, session);
725 }
726 else
727 { 693 {
728 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 694 /* not enough ready yet (tiny message & cork possible), or no messages at all,
729 "Queue empty, waiting for solicitations\n"); 695 and either excess bandwidth or best-effort or higher message waiting at
696 client; in this case, we try to solicit more */
697 GNUNET_log(
698 GNUNET_ERROR_TYPE_DEBUG,
699 "Soliciting messages (excess %d, maxpc %d, message size %u, deadline %s)\n",
700 excess,
701 maxpc,
702 (unsigned int)msize,
703 GNUNET_STRINGS_relative_time_to_string(GNUNET_TIME_absolute_get_remaining(
704 min_deadline),
705 GNUNET_YES));
706 solicit_messages(session, msize);
707 if (msize > 0)
708 {
709 /* if there is data to send, just not yet, make sure we do transmit
710 * it once the deadline is reached */
711 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
712 "Corking until %s\n",
713 GNUNET_STRINGS_relative_time_to_string(
714 GNUNET_TIME_absolute_get_remaining(min_deadline),
715 GNUNET_YES));
716 if (NULL != session->cork_task)
717 GNUNET_SCHEDULER_cancel(session->cork_task);
718 session->cork_task =
719 GNUNET_SCHEDULER_add_at(min_deadline, &pop_cork_task, session);
720 }
721 else
722 {
723 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
724 "Queue empty, waiting for solicitations\n");
725 }
726 return;
730 } 727 }
731 return; 728 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
732 } 729 "Building combined plaintext buffer to transmit message!\n");
733 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
734 "Building combined plaintext buffer to transmit message!\n");
735 /* create plaintext buffer of all messages (that fit), encrypt and 730 /* create plaintext buffer of all messages (that fit), encrypt and
736 transmit */ 731 transmit */
737 { 732 {
@@ -742,33 +737,33 @@ try_transmission (struct Session *session)
742 737
743 used = 0; 738 used = 0;
744 while ((NULL != (pos = session->sme_head)) && (used + pos->size <= msize)) 739 while ((NULL != (pos = session->sme_head)) && (used + pos->size <= msize))
745 { 740 {
746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 741 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
747 "Adding message of type %d (%d/%d) to payload for %s\n", 742 "Adding message of type %d (%d/%d) to payload for %s\n",
748 ntohs (((const struct GNUNET_MessageHeader *) &pos[1])->type), 743 ntohs(((const struct GNUNET_MessageHeader *)&pos[1])->type),
749 pos->is_typemap, 744 pos->is_typemap,
750 pos->is_typemap_confirm, 745 pos->is_typemap_confirm,
751 GNUNET_i2s (session->peer)); 746 GNUNET_i2s(session->peer));
752 GNUNET_memcpy (&pbuf[used], &pos[1], pos->size); 747 GNUNET_memcpy(&pbuf[used], &pos[1], pos->size);
753 used += pos->size; 748 used += pos->size;
754 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, pos); 749 GNUNET_CONTAINER_DLL_remove(session->sme_head, session->sme_tail, pos);
755 GNUNET_free (pos); 750 GNUNET_free(pos);
756 } 751 }
757 /* compute average payload size */ 752 /* compute average payload size */
758 total_bytes += used; 753 total_bytes += used;
759 total_msgs++; 754 total_msgs++;
760 if (0 == total_msgs) 755 if (0 == total_msgs)
761 { 756 {
762 /* 2^32 messages, wrap around... */ 757 /* 2^32 messages, wrap around... */
763 total_msgs = 1; 758 total_msgs = 1;
764 total_bytes = used; 759 total_bytes = used;
765 } 760 }
766 GNUNET_STATISTICS_set (GSC_stats, 761 GNUNET_STATISTICS_set(GSC_stats,
767 "# avg payload per encrypted message", 762 "# avg payload per encrypted message",
768 total_bytes / total_msgs, 763 total_bytes / total_msgs,
769 GNUNET_NO); 764 GNUNET_NO);
770 /* now actually transmit... */ 765 /* now actually transmit... */
771 GSC_KX_encrypt_and_transmit (session->kx, pbuf, used); 766 GSC_KX_encrypt_and_transmit(session->kx, pbuf, used);
772 } 767 }
773} 768}
774 769
@@ -783,36 +778,36 @@ try_transmission (struct Session *session)
783 * @return always #GNUNET_OK 778 * @return always #GNUNET_OK
784 */ 779 */
785static int 780static int
786do_restart_typemap_message (void *cls, 781do_restart_typemap_message(void *cls,
787 const struct GNUNET_PeerIdentity *key, 782 const struct GNUNET_PeerIdentity *key,
788 void *value) 783 void *value)
789{ 784{
790 const struct GNUNET_MessageHeader *hdr = cls; 785 const struct GNUNET_MessageHeader *hdr = cls;
791 struct Session *session = value; 786 struct Session *session = value;
792 struct SessionMessageEntry *sme; 787 struct SessionMessageEntry *sme;
793 uint16_t size; 788 uint16_t size;
794 789
795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 790 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
796 "Restarting sending TYPEMAP to %s\n", 791 "Restarting sending TYPEMAP to %s\n",
797 GNUNET_i2s (session->peer)); 792 GNUNET_i2s(session->peer));
798 size = ntohs (hdr->size); 793 size = ntohs(hdr->size);
799 for (sme = session->sme_head; NULL != sme; sme = sme->next) 794 for (sme = session->sme_head; NULL != sme; sme = sme->next)
800 {
801 if (GNUNET_YES == sme->is_typemap)
802 { 795 {
803 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme); 796 if (GNUNET_YES == sme->is_typemap)
804 GNUNET_free (sme); 797 {
805 break; 798 GNUNET_CONTAINER_DLL_remove(session->sme_head, session->sme_tail, sme);
799 GNUNET_free(sme);
800 break;
801 }
806 } 802 }
807 } 803 sme = GNUNET_malloc(sizeof(struct SessionMessageEntry) + size);
808 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + size);
809 sme->is_typemap = GNUNET_YES; 804 sme->is_typemap = GNUNET_YES;
810 GNUNET_memcpy (&sme[1], hdr, size); 805 GNUNET_memcpy(&sme[1], hdr, size);
811 sme->size = size; 806 sme->size = size;
812 sme->priority = GNUNET_MQ_PRIO_CRITICAL_CONTROL; 807 sme->priority = GNUNET_MQ_PRIO_CRITICAL_CONTROL;
813 GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, sme); 808 GNUNET_CONTAINER_DLL_insert(session->sme_head, session->sme_tail, sme);
814 try_transmission (session); 809 try_transmission(session);
815 start_typemap_task (session); 810 start_typemap_task(session);
816 return GNUNET_OK; 811 return GNUNET_OK;
817} 812}
818 813
@@ -824,13 +819,13 @@ do_restart_typemap_message (void *cls,
824 * @param msg message to transmit 819 * @param msg message to transmit
825 */ 820 */
826void 821void
827GSC_SESSIONS_broadcast_typemap (const struct GNUNET_MessageHeader *msg) 822GSC_SESSIONS_broadcast_typemap(const struct GNUNET_MessageHeader *msg)
828{ 823{
829 if (NULL == sessions) 824 if (NULL == sessions)
830 return; 825 return;
831 GNUNET_CONTAINER_multipeermap_iterate (sessions, 826 GNUNET_CONTAINER_multipeermap_iterate(sessions,
832 &do_restart_typemap_message, 827 &do_restart_typemap_message,
833 (void *) msg); 828 (void *)msg);
834} 829}
835 830
836 831
@@ -842,17 +837,17 @@ GSC_SESSIONS_broadcast_typemap (const struct GNUNET_MessageHeader *msg)
842 * @param pid identity of peer ready to receive data 837 * @param pid identity of peer ready to receive data
843 */ 838 */
844void 839void
845GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid) 840GSC_SESSIONS_solicit(const struct GNUNET_PeerIdentity *pid)
846{ 841{
847 struct Session *session; 842 struct Session *session;
848 843
849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 844 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
850 "Transport solicits for %s\n", 845 "Transport solicits for %s\n",
851 GNUNET_i2s (pid)); 846 GNUNET_i2s(pid));
852 session = find_session (pid); 847 session = find_session(pid);
853 if (NULL == session) 848 if (NULL == session)
854 return; 849 return;
855 try_transmission (session); 850 try_transmission(session);
856} 851}
857 852
858 853
@@ -865,43 +860,43 @@ GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid)
865 * @param priority how important is this message 860 * @param priority how important is this message
866 */ 861 */
867void 862void
868GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, 863GSC_SESSIONS_transmit(struct GSC_ClientActiveRequest *car,
869 const struct GNUNET_MessageHeader *msg, 864 const struct GNUNET_MessageHeader *msg,
870 enum GNUNET_MQ_PriorityPreferences priority) 865 enum GNUNET_MQ_PriorityPreferences priority)
871{ 866{
872 struct Session *session; 867 struct Session *session;
873 struct SessionMessageEntry *sme; 868 struct SessionMessageEntry *sme;
874 struct SessionMessageEntry *pos; 869 struct SessionMessageEntry *pos;
875 size_t msize; 870 size_t msize;
876 871
877 session = find_session (&car->target); 872 session = find_session(&car->target);
878 if (NULL == session) 873 if (NULL == session)
879 return; 874 return;
880 msize = ntohs (msg->size); 875 msize = ntohs(msg->size);
881 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + msize); 876 sme = GNUNET_malloc(sizeof(struct SessionMessageEntry) + msize);
882 GNUNET_memcpy (&sme[1], msg, msize); 877 GNUNET_memcpy(&sme[1], msg, msize);
883 sme->size = msize; 878 sme->size = msize;
884 sme->priority = priority; 879 sme->priority = priority;
885 if (0 != (GNUNET_MQ_PREF_CORK_ALLOWED & priority)) 880 if (0 != (GNUNET_MQ_PREF_CORK_ALLOWED & priority))
886 { 881 {
887 sme->deadline = 882 sme->deadline =
888 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_MAX_CORK_DELAY); 883 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_MAX_CORK_DELAY);
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 884 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
890 "Mesage corked, delaying transmission\n"); 885 "Mesage corked, delaying transmission\n");
891 } 886 }
892 pos = session->sme_head; 887 pos = session->sme_head;
893 while ((NULL != pos) && (pos->priority >= sme->priority)) 888 while ((NULL != pos) && (pos->priority >= sme->priority))
894 pos = pos->next; 889 pos = pos->next;
895 if (NULL == pos) 890 if (NULL == pos)
896 GNUNET_CONTAINER_DLL_insert_tail (session->sme_head, 891 GNUNET_CONTAINER_DLL_insert_tail(session->sme_head,
892 session->sme_tail,
893 sme);
894 else
895 GNUNET_CONTAINER_DLL_insert_after(session->sme_head,
897 session->sme_tail, 896 session->sme_tail,
897 pos->prev,
898 sme); 898 sme);
899 else 899 try_transmission(session);
900 GNUNET_CONTAINER_DLL_insert_after (session->sme_head,
901 session->sme_tail,
902 pos->prev,
903 sme);
904 try_transmission (session);
905} 900}
906 901
907 902
@@ -913,54 +908,54 @@ GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
913 * @param msg typemap update message 908 * @param msg typemap update message
914 */ 909 */
915void 910void
916GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, 911GSC_SESSIONS_set_typemap(const struct GNUNET_PeerIdentity *peer,
917 const struct GNUNET_MessageHeader *msg) 912 const struct GNUNET_MessageHeader *msg)
918{ 913{
919 struct Session *session; 914 struct Session *session;
920 struct GSC_TypeMap *nmap; 915 struct GSC_TypeMap *nmap;
921 struct SessionMessageEntry *sme; 916 struct SessionMessageEntry *sme;
922 struct TypeMapConfirmationMessage *tmc; 917 struct TypeMapConfirmationMessage *tmc;
923 918
924 nmap = GSC_TYPEMAP_get_from_message (msg); 919 nmap = GSC_TYPEMAP_get_from_message(msg);
925 if (NULL == nmap) 920 if (NULL == nmap)
926 { 921 {
927 GNUNET_break_op (0); 922 GNUNET_break_op(0);
928 return; /* malformed */ 923 return; /* malformed */
929 } 924 }
930 session = find_session (peer); 925 session = find_session(peer);
931 if (NULL == session) 926 if (NULL == session)
932 { 927 {
933 GSC_TYPEMAP_destroy (nmap); 928 GSC_TYPEMAP_destroy(nmap);
934 GNUNET_break (0); 929 GNUNET_break(0);
935 return; 930 return;
936 } 931 }
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 932 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
938 "Received TYPEMAP from %s\n", 933 "Received TYPEMAP from %s\n",
939 GNUNET_i2s (session->peer)); 934 GNUNET_i2s(session->peer));
940 for (sme = session->sme_head; NULL != sme; sme = sme->next) 935 for (sme = session->sme_head; NULL != sme; sme = sme->next)
941 {
942 if (GNUNET_YES == sme->is_typemap_confirm)
943 { 936 {
944 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme); 937 if (GNUNET_YES == sme->is_typemap_confirm)
945 GNUNET_free (sme); 938 {
946 break; 939 GNUNET_CONTAINER_DLL_remove(session->sme_head, session->sme_tail, sme);
940 GNUNET_free(sme);
941 break;
942 }
947 } 943 }
948 } 944 sme = GNUNET_malloc(sizeof(struct SessionMessageEntry) +
949 sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + 945 sizeof(struct TypeMapConfirmationMessage));
950 sizeof (struct TypeMapConfirmationMessage)); 946 sme->deadline = GNUNET_TIME_absolute_get();
951 sme->deadline = GNUNET_TIME_absolute_get (); 947 sme->size = sizeof(struct TypeMapConfirmationMessage);
952 sme->size = sizeof (struct TypeMapConfirmationMessage);
953 sme->priority = GNUNET_MQ_PRIO_CRITICAL_CONTROL; 948 sme->priority = GNUNET_MQ_PRIO_CRITICAL_CONTROL;
954 sme->is_typemap_confirm = GNUNET_YES; 949 sme->is_typemap_confirm = GNUNET_YES;
955 tmc = (struct TypeMapConfirmationMessage *) &sme[1]; 950 tmc = (struct TypeMapConfirmationMessage *)&sme[1];
956 tmc->header.size = htons (sizeof (struct TypeMapConfirmationMessage)); 951 tmc->header.size = htons(sizeof(struct TypeMapConfirmationMessage));
957 tmc->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP); 952 tmc->header.type = htons(GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP);
958 tmc->reserved = htonl (0); 953 tmc->reserved = htonl(0);
959 GSC_TYPEMAP_hash (nmap, &tmc->tm_hash); 954 GSC_TYPEMAP_hash(nmap, &tmc->tm_hash);
960 GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, sme); 955 GNUNET_CONTAINER_DLL_insert(session->sme_head, session->sme_tail, sme);
961 try_transmission (session); 956 try_transmission(session);
962 GSC_CLIENTS_notify_clients_about_neighbour (peer, session->tmap, nmap); 957 GSC_CLIENTS_notify_clients_about_neighbour(peer, session->tmap, nmap);
963 GSC_TYPEMAP_destroy (session->tmap); 958 GSC_TYPEMAP_destroy(session->tmap);
964 session->tmap = nmap; 959 session->tmap = nmap;
965} 960}
966 961
@@ -974,21 +969,21 @@ GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer,
974 * @param type type of the message 969 * @param type type of the message
975 */ 970 */
976void 971void
977GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, 972GSC_SESSIONS_add_to_typemap(const struct GNUNET_PeerIdentity *peer,
978 uint16_t type) 973 uint16_t type)
979{ 974{
980 struct Session *session; 975 struct Session *session;
981 struct GSC_TypeMap *nmap; 976 struct GSC_TypeMap *nmap;
982 977
983 if (0 == memcmp (peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity))) 978 if (0 == memcmp(peer, &GSC_my_identity, sizeof(struct GNUNET_PeerIdentity)))
984 return; 979 return;
985 session = find_session (peer); 980 session = find_session(peer);
986 GNUNET_assert (NULL != session); 981 GNUNET_assert(NULL != session);
987 if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, &type, 1)) 982 if (GNUNET_YES == GSC_TYPEMAP_test_match(session->tmap, &type, 1))
988 return; /* already in it */ 983 return; /* already in it */
989 nmap = GSC_TYPEMAP_extend (session->tmap, &type, 1); 984 nmap = GSC_TYPEMAP_extend(session->tmap, &type, 1);
990 GSC_CLIENTS_notify_clients_about_neighbour (peer, session->tmap, nmap); 985 GSC_CLIENTS_notify_clients_about_neighbour(peer, session->tmap, nmap);
991 GSC_TYPEMAP_destroy (session->tmap); 986 GSC_TYPEMAP_destroy(session->tmap);
992 session->tmap = nmap; 987 session->tmap = nmap;
993} 988}
994 989
@@ -997,9 +992,9 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
997 * Initialize sessions subsystem. 992 * Initialize sessions subsystem.
998 */ 993 */
999void 994void
1000GSC_SESSIONS_init () 995GSC_SESSIONS_init()
1001{ 996{
1002 sessions = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES); 997 sessions = GNUNET_CONTAINER_multipeermap_create(128, GNUNET_YES);
1003} 998}
1004 999
1005 1000
@@ -1013,13 +1008,13 @@ GSC_SESSIONS_init ()
1013 * @return #GNUNET_OK (continue to iterate) 1008 * @return #GNUNET_OK (continue to iterate)
1014 */ 1009 */
1015static int 1010static int
1016free_session_helper (void *cls, 1011free_session_helper(void *cls,
1017 const struct GNUNET_PeerIdentity *key, 1012 const struct GNUNET_PeerIdentity *key,
1018 void *value) 1013 void *value)
1019{ 1014{
1020 /* struct Session *session = value; */ 1015 /* struct Session *session = value; */
1021 1016
1022 GSC_SESSIONS_end (key); 1017 GSC_SESSIONS_end(key);
1023 return GNUNET_OK; 1018 return GNUNET_OK;
1024} 1019}
1025 1020
@@ -1028,16 +1023,16 @@ free_session_helper (void *cls,
1028 * Shutdown sessions subsystem. 1023 * Shutdown sessions subsystem.
1029 */ 1024 */
1030void 1025void
1031GSC_SESSIONS_done () 1026GSC_SESSIONS_done()
1032{ 1027{
1033 if (NULL != sessions) 1028 if (NULL != sessions)
1034 { 1029 {
1035 GNUNET_CONTAINER_multipeermap_iterate (sessions, 1030 GNUNET_CONTAINER_multipeermap_iterate(sessions,
1036 &free_session_helper, 1031 &free_session_helper,
1037 NULL); 1032 NULL);
1038 GNUNET_CONTAINER_multipeermap_destroy (sessions); 1033 GNUNET_CONTAINER_multipeermap_destroy(sessions);
1039 sessions = NULL; 1034 sessions = NULL;
1040 } 1035 }
1041} 1036}
1042 1037
1043/* end of gnunet-service-core_sessions.c */ 1038/* end of gnunet-service-core_sessions.c */