code for managing of 'encrypted' sessions (key exchange done) More...
#include "platform.h"
#include "gnunet-service-core.h"
#include "gnunet-service-core_kx.h"
#include "gnunet-service-core_sessions.h"
#include "gnunet_constants.h"
#include "core.h"
Go to the source code of this file.
Data Structures | |
struct | SessionMessageEntry |
Message ready for encryption. More... | |
struct | Session |
Data kept per session. More... | |
Macros | |
#define | MAX_ENCRYPTED_MESSAGE_QUEUE_SIZE 4 |
How many encrypted messages do we queue at most? Needed to bound memory consumption. | |
Functions | |
static struct Session * | find_session (const struct GNUNET_PeerIdentity *peer) |
Find the session for the given peer. | |
void | GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid) |
End the session with the given peer (we are no longer connected). | |
void | GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, struct GSC_KeyExchangeInfo *kx, enum GNUNET_CORE_PeerClass class) |
Create a session, a key exchange was just completed. | |
void | GSC_SESSIONS_reinit (const struct GNUNET_PeerIdentity *peer) |
The other peer has indicated that it 'lost' the session (KX down), reinitialize the session on our end, in particular this means to restart the typemap transmission. | |
static int | notify_client_about_session (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
Notify the given client about the session (client is new). | |
void | GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client) |
We have a new client, notify it about all current sessions. | |
static void | try_transmission (struct Session *session) |
Try to perform a transmission on the given session. | |
void | GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car) |
Queue a request from a client for transmission to a particular peer. | |
void | GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car) |
Dequeue a request from a client from transmission to a particular peer. | |
static void | solicit_messages (struct Session *session, size_t msize) |
Solicit messages for transmission, starting with those of the highest priority. | |
static void | pop_cork_task (void *cls) |
Some messages were delayed (corked), but the timeout has now expired. | |
void | GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid) |
Traffic is being solicited for the given peer. | |
void | GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car, const struct GNUNET_MessageHeader *msg, enum GNUNET_MQ_PriorityPreferences priority) |
Transmit a message to a particular peer. | |
void | GSC_SESSIONS_init () |
Initialize sessions subsystem. | |
static int | free_session_helper (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
Helper function for GSC_SESSIONS_done() to free all active sessions. | |
void | GSC_SESSIONS_done () |
Shutdown sessions subsystem. | |
Variables | |
static struct GNUNET_CONTAINER_MultiPeerMap * | sessions |
Map of peer identities to struct Session . | |
code for managing of 'encrypted' sessions (key exchange done)
Definition in file gnunet-service-core_sessions.c.
#define MAX_ENCRYPTED_MESSAGE_QUEUE_SIZE 4 |
How many encrypted messages do we queue at most? Needed to bound memory consumption.
Definition at line 38 of file gnunet-service-core_sessions.c.
|
static |
Find the session for the given peer.
peer | identity of the peer |
Definition at line 144 of file gnunet-service-core_sessions.c.
References GNUNET_CONTAINER_multipeermap_get(), Session::peer, and sessions.
Referenced by GSC_SESSIONS_dequeue_request(), GSC_SESSIONS_end(), GSC_SESSIONS_queue_request(), GSC_SESSIONS_reinit(), GSC_SESSIONS_solicit(), and GSC_SESSIONS_transmit().
void GSC_SESSIONS_end | ( | const struct GNUNET_PeerIdentity * | pid | ) |
End the session with the given peer (we are no longer connected).
pid | identity of peer to kill session with |
Definition at line 159 of file gnunet-service-core_sessions.c.
References Session::active_client_request_head, Session::active_client_request_tail, Session::class, Session::cork_task, find_session(), gettext_noop, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_YES, GSC_CLIENTS_notify_clients_about_neighbour(), GSC_CLIENTS_reject_request(), GSC_stats, Session::peer, pid, sessions, Session::sme_head, and Session::sme_tail.
Referenced by free_session_helper(), handle_encrypted_message(), handle_transport_notify_disconnect(), and send_heartbeat().
void GSC_SESSIONS_create | ( | const struct GNUNET_PeerIdentity * | peer, |
struct GSC_KeyExchangeInfo * | kx, | ||
enum GNUNET_CORE_PeerClass | class | ||
) |
Create a session, a key exchange was just completed.
peer | peer that is now connected |
kx | key exchange that completed |
class | the class of the now connected peer |
Definition at line 219 of file gnunet-service-core_sessions.c.
References Session::class, gettext_noop, GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_set(), GSC_CLIENTS_notify_clients_about_neighbour(), GSC_stats, Session::kx, Session::peer, and sessions.
Referenced by check_if_ack_or_heartbeat(), and handle_initiator_done().
void GSC_SESSIONS_reinit | ( | const struct GNUNET_PeerIdentity * | peer | ) |
The other peer has indicated that it 'lost' the session (KX down), reinitialize the session on our end, in particular this means to restart the typemap transmission.
XXX typemap does not exist anymore
peer | peer that is now connected |
Definition at line 259 of file gnunet-service-core_sessions.c.
References find_session(), and Session::peer.
|
static |
Notify the given client about the session (client is new).
cls | the struct GSC_Client |
key | peer identity |
value | the struct Session |
Definition at line 284 of file gnunet-service-core_sessions.c.
References Session::class, GSC_Client::client, GNUNET_OK, GSC_CLIENTS_notify_client_about_neighbour(), Session::peer, and value.
Referenced by GSC_SESSIONS_notify_client_about_sessions().
void GSC_SESSIONS_notify_client_about_sessions | ( | struct GSC_Client * | client | ) |
We have a new client, notify it about all current sessions.
client | the new client |
Definition at line 305 of file gnunet-service-core_sessions.c.
References GNUNET_CONTAINER_multipeermap_iterate(), notify_client_about_session(), and sessions.
Referenced by handle_client_init().
|
static |
Try to perform a transmission on the given session.
Will solicit additional messages if the 'sme' queue is not full enough.
session | session to transmit messages from |
Will solicit additional messages if the 'sme' queue is not full enough or has only low-priority messages.
session | session to transmit messages from |
Definition at line 461 of file gnunet-service-core_sessions.c.
References GNUNET_TIME_Absolute::abs_value_us, Session::active_client_request_head, Session::cork_task, SessionMessageEntry::deadline, GNUNET_assert, GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_MAX, GNUNET_memcpy, GNUNET_MQ_PRIO_BACKGROUND, GNUNET_MQ_PRIO_BEST_EFFORT, GNUNET_MQ_PRIO_CRITICAL_CONTROL, GNUNET_MQ_PRIORITY_MASK, GNUNET_NO, GNUNET_SCHEDULER_add_at(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_absolute_min(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_YES, GSC_KX_encrypt_and_transmit(), GSC_NEIGHBOURS_check_excess_bandwidth(), GSC_NEIGHBOURS_get_queue_length(), GSC_stats, Session::kx, MAX_ENCRYPTED_MESSAGE_QUEUE_SIZE, GSC_ClientActiveRequest::msize, GSC_ClientActiveRequest::next, SessionMessageEntry::next, Session::peer, pop_cork_task(), GSC_ClientActiveRequest::priority, SessionMessageEntry::priority, GNUNET_MessageHeader::size, SessionMessageEntry::size, Session::sme_head, Session::sme_tail, solicit_messages(), type, and GSC_ClientActiveRequest::was_solicited.
Referenced by GSC_SESSIONS_dequeue_request(), GSC_SESSIONS_queue_request(), GSC_SESSIONS_solicit(), GSC_SESSIONS_transmit(), and pop_cork_task().
void GSC_SESSIONS_queue_request | ( | struct GSC_ClientActiveRequest * | car | ) |
Queue a request from a client for transmission to a particular peer.
car | request to queue; this handle is then shared between the caller (CLIENTS subsystem) and SESSIONS and must not be released by either until either #GSC_SESSIONS_dequeue(), GSC_SESSIONS_transmit() or #GSC_CLIENTS_failed() have been invoked on it |
Definition at line 334 of file gnunet-service-core_sessions.c.
References Session::active_client_request_head, Session::active_client_request_tail, find_session(), GNUNET_break, GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_YES, GSC_CLIENTS_reject_request(), GSC_ClientActiveRequest::msize, GSC_ClientActiveRequest::target, and try_transmission().
Referenced by handle_client_send_request().
void GSC_SESSIONS_dequeue_request | ( | struct GSC_ClientActiveRequest * | car | ) |
Dequeue a request from a client from transmission to a particular peer.
car | request to dequeue; this handle will then be 'owned' by the caller (CLIENTS sysbsystem) |
Definition at line 369 of file gnunet-service-core_sessions.c.
References Session::active_client_request_head, Session::active_client_request_tail, find_session(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GSC_my_identity, GSC_ClientActiveRequest::target, and try_transmission().
Referenced by destroy_active_client_request(), GSC_CLIENTS_solicit_request(), handle_client_send(), and handle_client_send_request().
|
static |
Solicit messages for transmission, starting with those of the highest priority.
session | session to solict messages for |
msize | how many bytes do we have already |
Definition at line 397 of file gnunet-service-core_sessions.c.
References Session::active_client_request_head, GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_MAX, GNUNET_MQ_PRIO_BACKGROUND, GNUNET_MQ_PRIORITY_MASK, GNUNET_YES, GSC_CLIENTS_solicit_request(), GSC_ClientActiveRequest::msize, GSC_ClientActiveRequest::next, GSC_ClientActiveRequest::priority, and GSC_ClientActiveRequest::was_solicited.
Referenced by try_transmission().
|
static |
Some messages were delayed (corked), but the timeout has now expired.
Send them now.
cls | struct Session with the messages to transmit now |
Definition at line 444 of file gnunet-service-core_sessions.c.
References Session::cork_task, and try_transmission().
Referenced by try_transmission().
void GSC_SESSIONS_solicit | ( | const struct GNUNET_PeerIdentity * | pid | ) |
Traffic is being solicited for the given peer.
This means that the message queue on the transport-level (NEIGHBOURS subsystem) is now empty and it is now OK to transmit another (non-control) message.
pid | identity of peer ready to receive data |
Definition at line 632 of file gnunet-service-core_sessions.c.
References find_session(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, pid, and try_transmission().
void GSC_SESSIONS_transmit | ( | struct GSC_ClientActiveRequest * | car, |
const struct GNUNET_MessageHeader * | msg, | ||
enum GNUNET_MQ_PriorityPreferences | priority | ||
) |
Transmit a message to a particular peer.
car | original request that was queued and then solicited, ownership does not change (dequeue will be called soon). |
msg | message to transmit |
priority | how important is this message |
Definition at line 647 of file gnunet-service-core_sessions.c.
References SessionMessageEntry::deadline, find_session(), GNUNET_CONSTANTS_MAX_CORK_DELAY, GNUNET_CONTAINER_DLL_insert_after, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_MQ_PREF_CORK_ALLOWED, GNUNET_TIME_relative_to_absolute(), msg, SessionMessageEntry::next, SessionMessageEntry::prev, SessionMessageEntry::priority, GNUNET_MessageHeader::size, SessionMessageEntry::size, Session::sme_head, Session::sme_tail, GSC_ClientActiveRequest::target, and try_transmission().
Referenced by tokenized_cb().
void GSC_SESSIONS_init | ( | void | ) |
Initialize sessions subsystem.
Definition at line 691 of file gnunet-service-core_sessions.c.
References GNUNET_CONTAINER_multipeermap_create(), GNUNET_YES, and sessions.
Referenced by GSC_complete_initialization_cb().
|
static |
Helper function for GSC_SESSIONS_done() to free all active sessions.
cls | NULL |
key | identity of the connected peer |
value | the struct Session for the peer |
Definition at line 707 of file gnunet-service-core_sessions.c.
References GNUNET_OK, GSC_SESSIONS_end(), and key.
Referenced by GSC_SESSIONS_done().
void GSC_SESSIONS_done | ( | void | ) |
Shutdown sessions subsystem.
Definition at line 722 of file gnunet-service-core_sessions.c.
References free_session_helper(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), and sessions.
Referenced by shutdown_task().
|
static |
Map of peer identities to struct Session
.
Definition at line 133 of file gnunet-service-core_sessions.c.
Referenced by find_session(), GSC_SESSIONS_create(), GSC_SESSIONS_done(), GSC_SESSIONS_end(), GSC_SESSIONS_init(), and GSC_SESSIONS_notify_client_about_sessions().