From: Christian Grothoff Date: Thu, 6 Oct 2011 11:07:54 +0000 (+0000) Subject: hdr X-Git-Tag: initial-import-from-subversion-38251~16749 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=49cacc9a9eb5c4ac424a41533e9dcebbdf3f8af6;p=oweals%2Fgnunet.git hdr --- diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c index b10e0bc58..1ab31cb2b 100644 --- a/src/core/gnunet-service-core_kx.c +++ b/src/core/gnunet-service-core_kx.c @@ -371,6 +371,9 @@ GSC_KX_stop (struct GSC_KeyExchangeInfo *kx) GNUNET_PEERINFO_iterate_cancel (kx->pitr); kx->pitr = NULL; } + + GNUNET_SCHEDULER_cancel (n->dead_clean_task); + if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) if (kx->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (kx->retry_set_key_task); GNUNET_free_non_null (kx->public_key); @@ -1513,6 +1516,66 @@ GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *n, } +/** + * Task triggered when a neighbour entry is about to time out + * (and we should prevent this by sending a PING). + * + * @param cls the 'struct Neighbour' + * @param tc scheduler context (not used) + */ +static void +send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) +{ + struct Neighbour *n = cls; + struct GNUNET_TIME_Relative retry; + struct GNUNET_TIME_Relative left; + struct MessageEntry *me; + struct PingMessage pp; + struct PingMessage *pm; + struct GNUNET_CRYPTO_AesInitializationVector iv; + + n->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; + /* send PING */ + me = GNUNET_malloc (sizeof (struct MessageEntry) + + sizeof (struct PingMessage)); + me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PING_DELAY); + me->priority = PING_PRIORITY; + me->size = sizeof (struct PingMessage); + GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, n->encrypted_tail, + n->encrypted_tail, me); + pm = (struct PingMessage *) &me[1]; + pm->header.size = htons (sizeof (struct PingMessage)); + pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); + pm->iv_seed = + GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); + derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); + pp.challenge = n->ping_challenge; + pp.target = n->peer; +#if DEBUG_HANDSHAKE + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", + "PING", (unsigned int) n->ping_challenge, GNUNET_i2s (&n->peer), + (unsigned int) n->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (&iv, + sizeof + (iv)), + pm->iv_seed); +#endif + do_encrypt (n, &iv, &pp.target, &pm->target, + sizeof (struct PingMessage) - ((void *) &pm->target - + (void *) pm)); + process_encrypted_neighbour_queue (n); + /* reschedule PING job */ + left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n)); + retry = + GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), + MIN_PING_FREQUENCY); + n->keep_alive_task = + GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, n); + +} + + + /** diff --git a/src/core/gnunet-service-core_kx.h b/src/core/gnunet-service-core_kx.h index b5b9b712e..104aed5e4 100644 --- a/src/core/gnunet-service-core_kx.h +++ b/src/core/gnunet-service-core_kx.h @@ -98,6 +98,11 @@ struct GSC_KeyExchangeInfo */ GNUNET_SCHEDULER_TaskIdentifier retry_set_key_task; + /** + * ID of task used for sending keep-alive pings. + */ + GNUNET_SCHEDULER_TaskIdentifier keep_alive_task; + /** * What was our PING challenge number (for this peer)? */ diff --git a/src/core/gnunet-service-core_neighbours.c b/src/core/gnunet-service-core_neighbours.c index 0e50454d1..8a0677c88 100644 --- a/src/core/gnunet-service-core_neighbours.c +++ b/src/core/gnunet-service-core_neighbours.c @@ -166,7 +166,7 @@ free_neighbour (struct Neighbour *n) GNUNET_TRANSPORT_notify_transmit_ready_cancel (n->th); n->th = NULL; } - GSC_SESSION_end (&n->peer); + GSC_SESSIONS_end (&n->peer); if (NULL != n->kx) { GSC_KX_stop (n->kx); 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 @@ -/* code for managing of 'encrypted' sessions (key exchange done) */ +/* + This file is part of GNUnet. + (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +/** + * @file core/gnunet-service-core_neighbours.c + * @brief code for managing of 'encrypted' sessions (key exchange done) + * @author Christian Grothoff + */ +#include "platform.h" +#include "gnunet_service_core.h" +#include "gnunet_service_core_neighbours.h" +#include "gnunet_service_core_kx.h" +#include "gnunet_service_core_sessions.h" /** * Record kept for each request for transmission issued by a @@ -39,10 +67,6 @@ struct Session */ struct GSC_KeyExchangeInfo *kxinfo; - /** - * ID of task used for sending keep-alive pings. - */ - GNUNET_SCHEDULER_TaskIdentifier keep_alive_task; /** * ID of task used for cleaning up dead neighbour entries. @@ -386,8 +410,6 @@ free_neighbour (struct Neighbour *n) if (n->quota_update_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (n->quota_update_task); if (n->dead_clean_task != GNUNET_SCHEDULER_NO_TASK) - GNUNET_SCHEDULER_cancel (n->dead_clean_task); - if (n->keep_alive_task != GNUNET_SCHEDULER_NO_TASK) GNUNET_SCHEDULER_cancel (n->keep_alive_task); if (n->status == PEER_STATE_KEY_CONFIRMED) GNUNET_STATISTICS_update (stats, gettext_noop ("# established sessions"), @@ -400,64 +422,6 @@ free_neighbour (struct Neighbour *n) -/** - * Task triggered when a neighbour entry is about to time out - * (and we should prevent this by sending a PING). - * - * @param cls the 'struct Neighbour' - * @param tc scheduler context (not used) - */ -static void -send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) -{ - struct Neighbour *n = cls; - struct GNUNET_TIME_Relative retry; - struct GNUNET_TIME_Relative left; - struct MessageEntry *me; - struct PingMessage pp; - struct PingMessage *pm; - struct GNUNET_CRYPTO_AesInitializationVector iv; - - n->keep_alive_task = GNUNET_SCHEDULER_NO_TASK; - /* send PING */ - me = GNUNET_malloc (sizeof (struct MessageEntry) + - sizeof (struct PingMessage)); - me->deadline = GNUNET_TIME_relative_to_absolute (MAX_PING_DELAY); - me->priority = PING_PRIORITY; - me->size = sizeof (struct PingMessage); - GNUNET_CONTAINER_DLL_insert_after (n->encrypted_head, n->encrypted_tail, - n->encrypted_tail, me); - pm = (struct PingMessage *) &me[1]; - pm->header.size = htons (sizeof (struct PingMessage)); - pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING); - pm->iv_seed = - GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX); - derive_iv (&iv, &n->encrypt_key, pm->iv_seed, &n->peer); - pp.challenge = n->ping_challenge; - pp.target = n->peer; -#if DEBUG_HANDSHAKE - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Encrypting `%s' message with challenge %u for `%4s' using key %u, IV %u (salt %u).\n", - "PING", (unsigned int) n->ping_challenge, GNUNET_i2s (&n->peer), - (unsigned int) n->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (&iv, - sizeof - (iv)), - pm->iv_seed); -#endif - do_encrypt (n, &iv, &pp.target, &pm->target, - sizeof (struct PingMessage) - ((void *) &pm->target - - (void *) pm)); - process_encrypted_neighbour_queue (n); - /* reschedule PING job */ - left = GNUNET_TIME_absolute_get_remaining (get_neighbour_timeout (n)); - retry = - GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2), - MIN_PING_FREQUENCY); - n->keep_alive_task = - GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, n); - -} - /** * Consider freeing the given neighbour since we may not need * to keep it around anymore. diff --git a/src/core/gnunet-service-core_sessions.h b/src/core/gnunet-service-core_sessions.h new file mode 100644 index 000000000..2f8c01840 --- /dev/null +++ b/src/core/gnunet-service-core_sessions.h @@ -0,0 +1,69 @@ +/* + This file is part of GNUnet. + (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors) + + GNUnet is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNUnet; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +/** + * @file core/gnunet-service-core_neighbours.h + * @brief code for managing of 'encrypted' sessions (key exchange done) + * @author Christian Grothoff + */ +#ifndef GNUNET_SERVICE_CORE_SESSIONS_H +#define GNUNET_SERVICE_CORE_SESSIONS_H + +#include "gnunet_service_core_kx.h" +#include "gnunet_service_core_sessions.h" + + +/** + * End the session with the given peer (we are no longer + * connected). + * + * @param pid identity of peer to kill session with + */ +void +GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid); + + +/** + * Traffic is being solicited for the given peer. This means that + * the message queue on the transport-level is now empty and it + * is now OK to transmit another (non-control) message. + * + * @param pid identity of peer ready to receive data + */ +void +GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid); + + +/** + * Initialize sessions subsystem. + */ +void +GSC_SESSIONS_init (void); + + +/** + * Shutdown sessions subsystem. + */ +void +GSC_SESSIONS_done (void); + + + +#endif