aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-service-core_sessions.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-06 11:07:54 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-06 11:07:54 +0000
commit49cacc9a9eb5c4ac424a41533e9dcebbdf3f8af6 (patch)
tree5f46828b1d887b6b9d9131a01a6a622dff430121 /src/core/gnunet-service-core_sessions.c
parent9dac44e13d6b9093615ed2a0dd30c9f6d37d29ab (diff)
downloadgnunet-49cacc9a9eb5c4ac424a41533e9dcebbdf3f8af6.tar.gz
gnunet-49cacc9a9eb5c4ac424a41533e9dcebbdf3f8af6.zip
hdr
Diffstat (limited to 'src/core/gnunet-service-core_sessions.c')
-rw-r--r--src/core/gnunet-service-core_sessions.c94
1 files changed, 29 insertions, 65 deletions
diff --git a/src/core/gnunet-service-core_sessions.c b/src/core/gnunet-service-core_sessions.c
index 1c1332bd4..23d53022e 100644
--- a/src/core/gnunet-service-core_sessions.c
+++ b/src/core/gnunet-service-core_sessions.c
@@ -1,5 +1,33 @@
1/* code for managing of 'encrypted' sessions (key exchange done) */ 1/*
2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
2 20
21/**
22 * @file core/gnunet-service-core_neighbours.c
23 * @brief code for managing of 'encrypted' sessions (key exchange done)
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_service_core.h"
28#include "gnunet_service_core_neighbours.h"
29#include "gnunet_service_core_kx.h"
30#include "gnunet_service_core_sessions.h"
3 31
4/** 32/**
5 * Record kept for each request for transmission issued by a 33 * Record kept for each request for transmission issued by a
@@ -39,10 +67,6 @@ struct Session
39 */ 67 */
40 struct GSC_KeyExchangeInfo *kxinfo; 68 struct GSC_KeyExchangeInfo *kxinfo;
41 69
42 /**
43 * ID of task used for sending keep-alive pings.
44 */
45 GNUNET_SCHEDULER_TaskIdentifier keep_alive_task;
46 70
47 /** 71 /**
48 * ID of task used for cleaning up dead neighbour entries. 72 * ID of task used for cleaning up dead neighbour entries.
@@ -386,8 +410,6 @@ free_neighbour (struct Neighbour *n)
386 if (n->quota_update_task != GNUNET_SCHEDULER_NO_TASK) 410 if (n->quota_update_task != GNUNET_SCHEDULER_NO_TASK)
387 GNUNET_SCHEDULER_cancel (n->quota_update_task); 411 GNUNET_SCHEDULER_cancel (n->quota_update_task);
388 if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) 412 if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK)
389 GNUNET_SCHEDULER_cancel (n->dead_clean_task);
390 if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
391 GNUNET_SCHEDULER_cancel (n->keep_alive_task); 413 GNUNET_SCHEDULER_cancel (n->keep_alive_task);
392 if (n->status == PEER_STATE_KEY_CONFIRMED) 414 if (n->status == PEER_STATE_KEY_CONFIRMED)
393 GNUNET_STATISTICS_update (stats, gettext_noop ("# established sessions"), 415 GNUNET_STATISTICS_update (stats, gettext_noop ("# established sessions"),
@@ -401,64 +423,6 @@ free_neighbour (struct Neighbour *n)
401 423
402 424
403/** 425/**
404 * Task triggered when a neighbour entry is about to time out
405 * (and we should prevent this by sending a PING).
406 *
407 * @param cls the 'struct Neighbour'
408 * @param tc scheduler context (not used)
409 */
410static void
411send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
412{
413 struct Neighbour *n = cls;
414 struct GNUNET_TIME_Relative retry;
415 struct GNUNET_TIME_Relative left;
416 struct MessageEntry *me;
417 struct PingMessage pp;
418 struct PingMessage *pm;
419 struct GNUNET_CRYPTO_AesInitializationVector iv;
420
421 n->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
422 /* send PING */
423 me = GNUNET_malloc (sizeof (struct MessageEntry) +
424 sizeof (struct PingMessage));
425 me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PING_DELAY);
426 me->priority = PING_PRIORITY;
427 me->size = sizeof (struct PingMessage);
428 GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, n->encrypted_tail,
429 n->encrypted_tail, me);
430 pm = (struct PingMessage *) &me[1];
431 pm->header.size = htons (sizeof (struct PingMessage));
432 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
433 pm->iv_seed =
434 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
435 derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer);
436 pp.challenge = n->ping_challenge;
437 pp.target = n->peer;
438#if DEBUG_HANDSHAKE
439 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
440 "Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n",
441 "PING", (unsigned int) n->ping_challenge, GNUNET_i2s (&n->peer),
442 (unsigned int) n->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (&iv,
443 sizeof
444 (iv)),
445 pm->iv_seed);
446#endif
447 do_encrypt (n, &iv, &pp.target, &pm->target,
448 sizeof (struct PingMessage) - ((void *) &pm->target -
449 (void *) pm));
450 process_encrypted_neighbour_queue (n);
451 /* reschedule PING job */
452 left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n));
453 retry =
454 GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2),
455 MIN_PING_FREQUENCY);
456 n->keep_alive_task =
457 GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, n);
458
459}
460
461/**
462 * Consider freeing the given neighbour since we may not need 426 * Consider freeing the given neighbour since we may not need
463 * to keep it around anymore. 427 * to keep it around anymore.
464 * 428 *