GNUnet 0.26.2-98-gb402d9955
 
Loading...
Searching...
No Matches
gnunet-service-core_sessions.h File Reference
Include dependency graph for gnunet-service-core_sessions.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

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.
 
void GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
 End the session with the given peer (we are no longer connected).
 
void GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid)
 Traffic is being solicited for the given peer.
 
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.
 
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_notify_client_about_sessions (struct GSC_Client *client)
 We have a new client, notify it about all current sessions.
 
void GSC_SESSIONS_init (void)
 Initialize sessions subsystem.
 
void GSC_SESSIONS_done (void)
 Shutdown sessions subsystem.
 

Function Documentation

◆ GSC_SESSIONS_create()

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.

Parameters
peerpeer that is now connected
kxkey exchange that completed
peerpeer that is now connected
kxkey exchange that completed
classthe class of the now connected peer

Definition at line 218 of file gnunet-service-core_sessions.c.

221{
222 struct Session *session;
223
225 "Creating session for peer `%s'\n",
226 GNUNET_i2s (peer));
227 session = GNUNET_new (struct Session);
228 // TODO
229 // session->services = GSC_SVCI_init ();
230 session->peer = peer;
231 session->kx = kx;
232 session->class = class;
235 sessions,
236 session->peer,
237 session,
240 gettext_noop ("# peers connected"),
242 GNUNET_NO);
243 // TODO
245 session->class);
246}
#define gettext_noop(String)
Definition gettext.h:74
void GSC_CLIENTS_notify_clients_about_neighbour(const struct GNUNET_PeerIdentity *neighbour, enum GNUNET_CORE_PeerClass class)
Notify all clients about a change to existing session.
struct GNUNET_STATISTICS_Handle * GSC_stats
For creating statistics.
static struct GNUNET_CONTAINER_MultiPeerMap * sessions
Map of peer identities to struct Session.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_NO
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
Data kept per session.
const struct GNUNET_PeerIdentity * peer
Identity of the other peer.
enum GNUNET_CORE_PeerClass class
Class of the peer.
struct GSC_KeyExchangeInfo * kx
Key exchange state for this peer.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_SESSIONS_reinit()

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 the typemap does not exist anymore

Parameters
peerpeer that is now connected

XXX typemap does not exist anymore

Parameters
peerpeer that is now connected

Definition at line 258 of file gnunet-service-core_sessions.c.

259{
260 struct Session *session;
261
262 session = find_session (peer);
263 if (NULL == session)
264 {
265 /* KX/session is new for both sides; thus no need to restart what
266 has not yet begun */
267 return;
268 }
269}
static struct Session * find_session(const struct GNUNET_PeerIdentity *peer)
Find the session for the given peer.

References find_session(), and Session::peer.

Here is the call graph for this function:

◆ GSC_SESSIONS_end()

void GSC_SESSIONS_end ( const struct GNUNET_PeerIdentity pid)

End the session with the given peer (we are no longer connected).

Parameters
pididentity of peer to kill session with

Definition at line 160 of file gnunet-service-core_sessions.c.

161{
162 struct Session *session;
163 struct GSC_ClientActiveRequest *car;
164 struct SessionMessageEntry *sme;
165
166 if (NULL == pid)
167 {
168 /* We might not know the peer_id yet. */
169 return;
170 }
171 session = find_session (pid);
172 if (NULL == session)
173 return;
175 "Destroying session for peer `%s'\n",
176 GNUNET_i2s (session->peer));
177 if (NULL != session->cork_task)
178 {
180 session->cork_task = NULL;
181 }
182 while (NULL != (car = session->active_client_request_head))
183 {
186 car);
188 }
189 while (NULL != (sme = session->sme_head))
190 {
191 GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme);
192 GNUNET_free (sme);
193 }
194 // TODO
196 session->class);
198 GNUNET_YES ==
201 gettext_noop ("# peers connected"),
203 GNUNET_NO);
204 // TODO
205 // GSC_SVCI_destroy (session->services);
206 GNUNET_free (session);
207}
void GSC_CLIENTS_reject_request(struct GSC_ClientActiveRequest *car, int drop_client)
We will never be ready to transmit the given message in (disconnect or invalid request).
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_YES
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:986
Record kept for each request for transmission issued by a client that is still pending.
Message ready for encryption.
struct SessionMessageEntry * sme_head
Head of list of messages ready for encryption.
struct SessionMessageEntry * sme_tail
Tail of list of messages ready for encryption.
struct GSC_ClientActiveRequest * active_client_request_head
Head of list of requests from clients for transmission to this peer.
struct GNUNET_SCHEDULER_Task * cork_task
Task to transmit corked messages with a delay.
struct GSC_ClientActiveRequest * active_client_request_tail
Tail of list of requests from clients for transmission to this peer.

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_SESSIONS_solicit()

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.

Parameters
pididentity of peer ready to receive data

Definition at line 633 of file gnunet-service-core_sessions.c.

634{
635 struct Session *session;
636
638 "Transport solicits for %s\n",
639 GNUNET_i2s (pid));
640 session = find_session (pid);
641 if (NULL == session)
642 return;
643 try_transmission (session);
644}
static void try_transmission(struct Session *session)
Try to perform a transmission on the given session.

References find_session(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, pid, and try_transmission().

Here is the call graph for this function:

◆ GSC_SESSIONS_queue_request()

void GSC_SESSIONS_queue_request ( struct GSC_ClientActiveRequest car)

Queue a request from a client for transmission to a particular peer.

Parameters
carrequest to queue; this handle is then shared between the caller (CLIENTS subsystem) and SESSIONS and must not be released by either until either 'GNUNET_SESSIONS_dequeue', or 'GNUNET_CLIENTS_failed' have been invoked on it
carrequest 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 331 of file gnunet-service-core_sessions.c.

332{
333 struct Session *session;
334
335 session = find_session (&car->target);
336 if (NULL == session)
337 {
339 "Dropped client request for transmission (am disconnected)\n");
340 GNUNET_break (0); /* should have been rejected earlier */
342 return;
343 }
345 {
346 GNUNET_break (0);
348 return;
349 }
351 "Received client transmission request. queueing\n");
354 car);
355 try_transmission (session);
356}
#define GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE
What is the maximum size for encrypted messages? Note that this number imposes a clear limit on the m...
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
struct GNUNET_PeerIdentity target
Which peer is the message going to be for?
uint16_t msize
How many bytes does the client intend to send?

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_SESSIONS_dequeue_request()

void GSC_SESSIONS_dequeue_request ( struct GSC_ClientActiveRequest car)

Dequeue a request from a client from transmission to a particular peer.

Parameters
carrequest to dequeue; this handle will then be 'owned' by the caller (CLIENTS sysbsystem)

Definition at line 366 of file gnunet-service-core_sessions.c.

367{
368 const struct GNUNET_PeerIdentity *my_identity;
369 struct Session *session;
371 if (NULL == my_identity)
372 return;
373
374 if (0 == memcmp (&car->target,
376 sizeof(struct GNUNET_PeerIdentity)))
377 return;
378 session = find_session (&car->target);
379 GNUNET_assert (NULL != session);
382 car);
383 /* dequeueing of 'high' priority messages may unblock
384 transmission for lower-priority messages, so we also
385 need to try in this case. */
386 try_transmission (session);
387}
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
struct GNUNET_PILS_Handle * GSC_pils
For peer identity access.
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:727
The identity of the host (wraps the signing key of the peer).

References Session::active_client_request_head, Session::active_client_request_tail, find_session(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_PILS_get_identity(), GSC_pils, 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_SESSIONS_transmit()

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.

Parameters
caroriginal request that was queued and then solicited, ownership does not change (dequeue will be called soon).
msgmessage to transmit
priorityhow important is this message

Definition at line 648 of file gnunet-service-core_sessions.c.

651{
652 struct Session *session;
653 struct SessionMessageEntry *sme;
654 struct SessionMessageEntry *pos;
655 size_t msize;
656
657 session = find_session (&car->target);
658 if (NULL == session)
659 {
661 return;
662 }
663 msize = ntohs (msg->size);
664 sme = GNUNET_malloc (sizeof(struct SessionMessageEntry) + msize);
665 GNUNET_memcpy (&sme[1], msg, msize);
666 sme->size = msize;
667 sme->priority = priority;
669 {
670 sme->deadline =
673 "Message corked, delaying transmission\n");
674 }
675 pos = session->sme_head;
676 while ((NULL != pos) && (pos->priority >= sme->priority))
677 pos = pos->next;
678 if (NULL == pos)
680 session->sme_tail,
681 sme);
682 else
684 session->sme_tail,
685 pos->prev,
686 sme);
687 try_transmission (session);
688}
struct GNUNET_MessageHeader * msg
Definition 005.c:2
#define GNUNET_CONSTANTS_MAX_CORK_DELAY
How long do we delay messages to get larger packet sizes (CORKing)?
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_malloc(size)
Wrapper around malloc.
@ GNUNET_MQ_PREF_CORK_ALLOWED
Flag to indicate that CORKing is acceptable.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
struct GNUNET_TIME_Absolute deadline
Deadline for transmission, 1s after we received it (if we are not corking), otherwise "now".
size_t size
How long is the message? (number of bytes following the struct MessageEntry, but not including the si...
struct SessionMessageEntry * next
We keep messages in a doubly linked list.
struct SessionMessageEntry * prev
We keep messages in a doubly linked list.
enum GNUNET_MQ_PriorityPreferences priority
How important is this message.

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(), GNUNET_YES, GSC_CLIENTS_reject_request(), 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Parameters
clientthe new client

Definition at line 302 of file gnunet-service-core_sessions.c.

303{
304 /* notify new client about existing sessions */
307 client);
308}
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).
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.

References GNUNET_CONTAINER_multipeermap_iterate(), notify_client_about_session(), and sessions.

Referenced by handle_client_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_SESSIONS_init()

void GSC_SESSIONS_init ( void  )

Initialize sessions subsystem.

Definition at line 695 of file gnunet-service-core_sessions.c.

696{
698}
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).

References GNUNET_CONTAINER_multipeermap_create(), GNUNET_YES, and sessions.

Referenced by GSC_complete_initialization_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_SESSIONS_done()

void GSC_SESSIONS_done ( void  )

Shutdown sessions subsystem.

Definition at line 726 of file gnunet-service-core_sessions.c.

727{
728 if (NULL != sessions)
729 {
732 NULL);
734 sessions = NULL;
735 }
736}
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 GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.

References free_session_helper(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), and sessions.

Referenced by shutdown_task().

Here is the call graph for this function:
Here is the caller graph for this function: