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_typemap.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... | |
struct | TypeMapConfirmationMessage |
Message sent to confirm that a typemap was received. More... | |
Macros | |
#define | MAX_ENCRYPTED_MESSAGE_QUEUE_SIZE 4 |
How many encrypted messages do we queue at most? Needed to bound memory consumption. More... | |
Functions | |
static struct Session * | find_session (const struct GNUNET_PeerIdentity *peer) |
Find the session for the given peer. More... | |
void | GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid) |
End the session with the given peer (we are no longer connected). More... | |
static void | transmit_typemap_task (void *cls) |
Transmit our current typemap message to the other peer. More... | |
static void | start_typemap_task (struct Session *session) |
Restart the typemap task for the given session. More... | |
void | GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer, struct GSC_KeyExchangeInfo *kx) |
Create a session, a key exchange was just completed. More... | |
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. More... | |
void | GSC_SESSIONS_confirm_typemap (const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *msg) |
The other peer has confirmed receiving our type map, check if it is current and if so, stop retransmitting it. More... | |
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). More... | |
void | GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client) |
We have a new client, notify it about all current sessions. More... | |
static void | try_transmission (struct Session *session) |
Try to perform a transmission on the given session. More... | |
void | GSC_SESSIONS_queue_request (struct GSC_ClientActiveRequest *car) |
Queue a request from a client for transmission to a particular peer. More... | |
void | GSC_SESSIONS_dequeue_request (struct GSC_ClientActiveRequest *car) |
Dequeue a request from a client from transmission to a particular peer. More... | |
static void | solicit_messages (struct Session *session, size_t msize) |
Solicit messages for transmission, starting with those of the highest priority. More... | |
static void | pop_cork_task (void *cls) |
Some messages were delayed (corked), but the timeout has now expired. More... | |
static int | do_restart_typemap_message (void *cls, const struct GNUNET_PeerIdentity *key, void *value) |
Send an updated typemap message to the neighbour now, and restart typemap transmissions. More... | |
void | GSC_SESSIONS_broadcast_typemap (const struct GNUNET_MessageHeader *msg) |
Broadcast an updated typemap message to all neighbours. More... | |
void | GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid) |
Traffic is being solicited for the given peer. More... | |
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. More... | |
void | GSC_SESSIONS_set_typemap (const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *msg) |
We've received a typemap message from a peer, update ours. More... | |
void | GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer, uint16_t type) |
The given peer send a message of the specified type. More... | |
void | GSC_SESSIONS_init () |
Initialize sessions subsystem. More... | |
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. More... | |
void | GSC_SESSIONS_done () |
Shutdown sessions subsystem. More... | |
Variables | |
static GNUNET_NETWORK_STRUCT_END struct GNUNET_CONTAINER_MultiPeerMap * | sessions |
Map of peer identities to struct Session . More... | |
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 39 of file gnunet-service-core_sessions.c.
|
static |
Find the session for the given peer.
peer | identity of the peer |
Definition at line 196 of file gnunet-service-core_sessions.c.
References GNUNET_CONTAINER_multipeermap_get(), Session::peer, and sessions.
Referenced by GSC_SESSIONS_add_to_typemap(), GSC_SESSIONS_confirm_typemap(), GSC_SESSIONS_dequeue_request(), GSC_SESSIONS_end(), GSC_SESSIONS_queue_request(), GSC_SESSIONS_reinit(), GSC_SESSIONS_set_typemap(), 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 211 of file gnunet-service-core_sessions.c.
References Session::active_client_request_head, Session::active_client_request_tail, 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, GSC_TYPEMAP_destroy(), Session::peer, pid, sessions, Session::sme_head, Session::sme_tail, Session::tmap, and Session::typemap_task.
Referenced by free_session_helper(), handle_encrypted(), handle_transport_notify_disconnect(), and send_keep_alive().
|
static |
Transmit our current typemap message to the other peer.
(Done periodically until the typemap is confirmed).
cls | the struct Session * |
Definition at line 268 of file gnunet-service-core_sessions.c.
References gettext_noop, GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_TIME_STD_BACKOFF, GSC_KX_encrypt_and_transmit(), GSC_stats, GSC_TYPEMAP_compute_type_map_message(), Session::kx, Session::peer, GNUNET_TIME_Relative::rel_value_us, GNUNET_MessageHeader::size, transmit_typemap_task(), Session::typemap_delay, and Session::typemap_task.
Referenced by start_typemap_task(), and transmit_typemap_task().
|
static |
Restart the typemap task for the given session.
session | session to restart typemap transmission for |
Definition at line 300 of file gnunet-service-core_sessions.c.
References GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_UNIT_SECONDS, transmit_typemap_task(), Session::typemap_delay, and Session::typemap_task.
Referenced by do_restart_typemap_message(), GSC_SESSIONS_create(), and GSC_SESSIONS_reinit().
void GSC_SESSIONS_create | ( | const struct GNUNET_PeerIdentity * | peer, |
struct GSC_KeyExchangeInfo * | kx | ||
) |
Create a session, a key exchange was just completed.
peer | peer that is now connected |
kx | key exchange that completed |
Definition at line 318 of file gnunet-service-core_sessions.c.
References 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, GSC_TYPEMAP_create(), Session::kx, Session::peer, sessions, start_typemap_task(), and Session::tmap.
Referenced by handle_pong().
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.
peer | peer that is now connected |
Definition at line 353 of file gnunet-service-core_sessions.c.
References find_session(), Session::peer, and start_typemap_task().
Referenced by handle_ephemeral_key().
void GSC_SESSIONS_confirm_typemap | ( | const struct GNUNET_PeerIdentity * | peer, |
const struct GNUNET_MessageHeader * | msg | ||
) |
The other peer has confirmed receiving our type map, check if it is current and if so, stop retransmitting it.
peer | peer that confirmed the type map |
msg | confirmation message we received |
Definition at line 376 of file gnunet-service-core_sessions.c.
References find_session(), gettext_noop, GNUNET_break, GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_YES, GSC_stats, GSC_TYPEMAP_check_hash(), msg, Session::peer, GNUNET_MessageHeader::size, TypeMapConfirmationMessage::tm_hash, and Session::typemap_task.
Referenced by deliver_message().
|
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 433 of file gnunet-service-core_sessions.c.
References GSC_Client::client, GNUNET_OK, GSC_CLIENTS_notify_client_about_neighbour(), Session::peer, Session::tmap, 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 454 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 610 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 do_restart_typemap_message(), GSC_SESSIONS_dequeue_request(), GSC_SESSIONS_queue_request(), GSC_SESSIONS_set_typemap(), 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 483 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 518 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 546 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 593 of file gnunet-service-core_sessions.c.
References Session::cork_task, and try_transmission().
Referenced by try_transmission().
|
static |
Send an updated typemap message to the neighbour now, and restart typemap transmissions.
cls | the message |
key | neighbour's identity |
value | struct Neighbour of the target |
Definition at line 785 of file gnunet-service-core_sessions.c.
References GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_MQ_PRIO_CRITICAL_CONTROL, GNUNET_OK, GNUNET_YES, SessionMessageEntry::is_typemap, SessionMessageEntry::next, Session::peer, SessionMessageEntry::priority, GNUNET_MessageHeader::size, size, SessionMessageEntry::size, Session::sme_head, Session::sme_tail, start_typemap_task(), try_transmission(), and value.
Referenced by GSC_SESSIONS_broadcast_typemap().
void GSC_SESSIONS_broadcast_typemap | ( | const struct GNUNET_MessageHeader * | msg | ) |
Broadcast an updated typemap message to all neighbours.
Restarts the retransmissions until the typemaps are confirmed.
msg | message to transmit |
Definition at line 826 of file gnunet-service-core_sessions.c.
References do_restart_typemap_message(), GNUNET_CONTAINER_multipeermap_iterate(), msg, and sessions.
Referenced by broadcast_my_type_map().
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 844 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 859 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_set_typemap | ( | const struct GNUNET_PeerIdentity * | peer, |
const struct GNUNET_MessageHeader * | msg | ||
) |
We've received a typemap message from a peer, update ours.
Notifies clients about the session.
peer | peer this is about |
msg | typemap update message |
Definition at line 900 of file gnunet-service-core_sessions.c.
References SessionMessageEntry::deadline, find_session(), GNUNET_break, GNUNET_break_op, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_malloc, GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP, GNUNET_MQ_PRIO_CRITICAL_CONTROL, GNUNET_TIME_absolute_get(), GNUNET_YES, GSC_CLIENTS_notify_clients_about_neighbour(), GSC_TYPEMAP_destroy(), GSC_TYPEMAP_get_from_message(), GSC_TYPEMAP_hash(), TypeMapConfirmationMessage::header, SessionMessageEntry::is_typemap_confirm, msg, SessionMessageEntry::next, Session::peer, SessionMessageEntry::priority, TypeMapConfirmationMessage::reserved, GNUNET_MessageHeader::size, SessionMessageEntry::size, Session::sme_head, Session::sme_tail, TypeMapConfirmationMessage::tm_hash, Session::tmap, try_transmission(), and GNUNET_MessageHeader::type.
Referenced by deliver_message().
void GSC_SESSIONS_add_to_typemap | ( | const struct GNUNET_PeerIdentity * | peer, |
uint16_t | type | ||
) |
The given peer send a message of the specified type.
Make sure the respective bit is set in its type-map and that clients are notified about the session.
peer | peer this is about |
type | type of the message |
Definition at line 961 of file gnunet-service-core_sessions.c.
References find_session(), GNUNET_assert, GNUNET_YES, GSC_CLIENTS_notify_clients_about_neighbour(), GSC_my_identity, GSC_TYPEMAP_destroy(), GSC_TYPEMAP_extend(), GSC_TYPEMAP_test_match(), Session::tmap, and type.
Referenced by GSC_CLIENTS_deliver_message().
void GSC_SESSIONS_init | ( | void | ) |
Initialize sessions subsystem.
Definition at line 984 of file gnunet-service-core_sessions.c.
References GNUNET_CONTAINER_multipeermap_create(), GNUNET_YES, and sessions.
Referenced by run().
|
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 1000 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 1015 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 185 of file gnunet-service-core_sessions.c.
Referenced by find_session(), GSC_SESSIONS_broadcast_typemap(), GSC_SESSIONS_create(), GSC_SESSIONS_done(), GSC_SESSIONS_end(), GSC_SESSIONS_init(), and GSC_SESSIONS_notify_client_about_sessions().