GNUnet  0.10.x
Functions
gnunet-service-core_sessions.h File Reference
#include "gnunet-service-core.h"
#include "gnunet-service-core_kx.h"
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)
 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...
 
void GSC_SESSIONS_end (const struct GNUNET_PeerIdentity *pid)
 End the session with the given peer (we are no longer connected). More...
 
void GSC_SESSIONS_solicit (const struct GNUNET_PeerIdentity *pid)
 Traffic is being solicited for the given peer. 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...
 
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_broadcast_typemap (const struct GNUNET_MessageHeader *msg)
 Broadcast an updated typemap message to all neighbours. More...
 
void GSC_SESSIONS_notify_client_about_sessions (struct GSC_Client *client)
 We have a new client, notify it about all current sessions. 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 (void)
 Initialize sessions subsystem. More...
 
void GSC_SESSIONS_done (void)
 Shutdown sessions subsystem. More...
 

Function Documentation

◆ GSC_SESSIONS_create()

void GSC_SESSIONS_create ( const struct GNUNET_PeerIdentity peer,
struct GSC_KeyExchangeInfo kx 
)

Create a session, a key exchange was just completed.

Parameters
peerpeer that is now connected
kxkey exchange that completed

Definition at line 320 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, peer, start_typemap_task(), and Session::tmap.

Referenced by handle_pong().

322 {
323  struct Session *session;
324 
326  "Creating session for peer `%s'\n",
327  GNUNET_i2s (peer));
328  session = GNUNET_new (struct Session);
329  session->tmap = GSC_TYPEMAP_create ();
330  session->peer = peer;
331  session->kx = kx;
334  sessions,
335  session->peer,
336  session,
339  gettext_noop ("# peers connected"),
341  GNUNET_NO);
342  GSC_CLIENTS_notify_clients_about_neighbour (peer, NULL, session->tmap);
343  start_typemap_task (session);
344 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_STATISTICS_Handle * GSC_stats
For creating statistics.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
struct GSC_TypeMap * tmap
Current type map for this peer.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
Data kept per session.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GSC_TypeMap * GSC_TYPEMAP_create()
Create an empty type map.
const struct GNUNET_PeerIdentity * peer
Identity of the other peer.
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.
#define GNUNET_log(kind,...)
struct GSC_KeyExchangeInfo * kx
Key exchange state for this peer.
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
static void start_typemap_task(struct Session *session)
Restart the typemap task for the given session.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_CONTAINER_MultiPeerMap * sessions
Map of peer identities to struct Session.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GSC_CLIENTS_notify_clients_about_neighbour(const struct GNUNET_PeerIdentity *neighbour, const struct GSC_TypeMap *tmap_old, const struct GSC_TypeMap *tmap_new)
Notify all clients about a change to existing session.
#define gettext_noop(String)
Definition: gettext.h:69
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.

Parameters
peerpeer that is now connected

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

References find_session(), and start_typemap_task().

Referenced by handle_ephemeral_key().

356 {
357  struct Session *session;
358 
359  session = find_session (peer);
360  if (NULL == session)
361  {
362  /* KX/session is new for both sides; thus no need to restart what
363  has not yet begun */
364  return;
365  }
366  start_typemap_task (session);
367 }
static struct Session * find_session(const struct GNUNET_PeerIdentity *peer)
Find the session for the given peer.
Data kept per session.
static void start_typemap_task(struct Session *session)
Restart the typemap task for the given session.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_SESSIONS_confirm_typemap()

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.

Parameters
peerpeer that confirmed the type map
msgconfirmation message we received

Definition at line 378 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(), Session::peer, GNUNET_MessageHeader::size, TypeMapConfirmationMessage::tm_hash, and Session::typemap_task.

Referenced by deliver_message().

380 {
381  const struct TypeMapConfirmationMessage *cmsg;
382  struct Session *session;
383 
384  session = find_session (peer);
385  if (NULL == session)
386  {
387  GNUNET_break (0);
388  return;
389  }
390  if (ntohs (msg->size) != sizeof (struct TypeMapConfirmationMessage))
391  {
392  GNUNET_break_op (0);
393  return;
394  }
395  cmsg = (const struct TypeMapConfirmationMessage *) msg;
396  if (GNUNET_YES != GSC_TYPEMAP_check_hash (&cmsg->tm_hash))
397  {
398  /* our typemap has changed in the meantime, do not
399  accept confirmation */
401  gettext_noop (
402  "# outdated typemap confirmations received"),
403  1,
404  GNUNET_NO);
406  "Got outdated typemap confirmated from peer `%s'\n",
407  GNUNET_i2s (session->peer));
408  return;
409  }
411  "Got typemap confirmation from peer `%s'\n",
412  GNUNET_i2s (session->peer));
413  if (NULL != session->typemap_task)
414  {
416  session->typemap_task = NULL;
417  }
419  gettext_noop (
420  "# valid typemap confirmations received"),
421  1,
422  GNUNET_NO);
423 }
#define GNUNET_NO
Definition: gnunet_common.h:81
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_STATISTICS_Handle * GSC_stats
For creating statistics.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
Message sent to confirm that a typemap was received.
static struct Session * find_session(const struct GNUNET_PeerIdentity *peer)
Find the session for the given peer.
Data kept per session.
const struct GNUNET_PeerIdentity * peer
Identity of the other peer.
int GSC_TYPEMAP_check_hash(const struct GNUNET_HashCode *hc)
Check if the given hash matches our current type map.
struct GNUNET_SCHEDULER_Task * typemap_task
Task to transmit our type map.
#define GNUNET_log(kind,...)
struct GNUNET_HashCode tm_hash
Hash of the (decompressed) type map that was received.
#define GNUNET_YES
Definition: gnunet_common.h:80
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define gettext_noop(String)
Definition: gettext.h:69
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller 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 213 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, 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().

214 {
215  struct Session *session;
216  struct GSC_ClientActiveRequest *car;
217  struct SessionMessageEntry *sme;
218 
219  session = find_session (pid);
220  if (NULL == session)
221  return;
223  "Destroying session for peer `%s'\n",
224  GNUNET_i2s (session->peer));
225  if (NULL != session->cork_task)
226  {
228  session->cork_task = NULL;
229  }
230  while (NULL != (car = session->active_client_request_head))
231  {
234  car);
236  }
237  while (NULL != (sme = session->sme_head))
238  {
239  GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme);
240  GNUNET_free (sme);
241  }
242  if (NULL != session->typemap_task)
243  {
245  session->typemap_task = NULL;
246  }
248  session->tmap,
249  NULL);
250  GNUNET_assert (
251  GNUNET_YES ==
252  GNUNET_CONTAINER_multipeermap_remove (sessions, session->peer, session));
254  gettext_noop ("# peers connected"),
256  GNUNET_NO);
257  GSC_TYPEMAP_destroy (session->tmap);
258  session->tmap = NULL;
259  GNUNET_free (session);
260 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
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.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct SessionMessageEntry * sme_tail
Tail of list of messages ready for encryption.
int 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.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_STATISTICS_Handle * GSC_stats
For creating statistics.
Message ready for encryption.
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).
struct SessionMessageEntry * sme_head
Head of list of messages ready for encryption.
Record kept for each request for transmission issued by a client that is still pending.
void GSC_TYPEMAP_destroy(struct GSC_TypeMap *tmap)
Free the given type map.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
struct GSC_TypeMap * tmap
Current type map for this peer.
struct GSC_ClientActiveRequest * active_client_request_head
Head of list of requests from clients for transmission to this peer.
static struct Session * find_session(const struct GNUNET_PeerIdentity *peer)
Find the session for the given peer.
Data kept per session.
const struct GNUNET_PeerIdentity * peer
Identity of the other peer.
struct GNUNET_SCHEDULER_Task * typemap_task
Task to transmit our type map.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_CONTAINER_MultiPeerMap * sessions
Map of peer identities to struct Session.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GSC_CLIENTS_notify_clients_about_neighbour(const struct GNUNET_PeerIdentity *neighbour, const struct GSC_TypeMap *tmap_old, const struct GSC_TypeMap *tmap_new)
Notify all clients about a change to existing session.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 845 of file gnunet-service-core_sessions.c.

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

Referenced by handle_transport_notify_excess_bw().

846 {
847  struct Session *session;
848 
850  "Transport solicits for %s\n",
851  GNUNET_i2s (pid));
852  session = find_session (pid);
853  if (NULL == session)
854  return;
855  try_transmission (session);
856 }
static void try_transmission(struct Session *session)
Try to perform a transmission on the given session.
static struct Session * find_session(const struct GNUNET_PeerIdentity *peer)
Find the session for the given peer.
Data kept per session.
#define GNUNET_log(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller 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 485 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().

486 {
487  struct Session *session;
488 
489  session = find_session (&car->target);
490  if (NULL == session)
491  {
493  "Dropped client request for transmission (am disconnected)\n");
494  GNUNET_break (0); /* should have been rejected earlier */
496  return;
497  }
499  {
500  GNUNET_break (0);
502  return;
503  }
505  "Received client transmission request. queueing\n");
508  car);
509  try_transmission (session);
510 }
struct GSC_ClientActiveRequest * active_client_request_tail
Tail of list of requests from clients for transmission to this peer.
static void try_transmission(struct Session *session)
Try to perform a transmission on the given session.
#define GNUNET_NO
Definition: gnunet_common.h:81
#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_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
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).
struct GSC_ClientActiveRequest * active_client_request_head
Head of list of requests from clients for transmission to this peer.
static struct Session * find_session(const struct GNUNET_PeerIdentity *peer)
Find the session for the given peer.
Data kept per session.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:80
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?
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 520 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().

521 {
522  struct Session *session;
523 
524  if (0 == memcmp (&car->target,
526  sizeof (struct GNUNET_PeerIdentity)))
527  return;
528  session = find_session (&car->target);
529  GNUNET_assert (NULL != session);
532  car);
533  /* dequeueing of 'high' priority messages may unblock
534  transmission for lower-priority messages, so we also
535  need to try in this case. */
536  try_transmission (session);
537 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
struct GSC_ClientActiveRequest * active_client_request_tail
Tail of list of requests from clients for transmission to this peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void try_transmission(struct Session *session)
Try to perform a transmission on the given session.
struct GSC_ClientActiveRequest * active_client_request_head
Head of list of requests from clients for transmission to this peer.
static struct Session * find_session(const struct GNUNET_PeerIdentity *peer)
Find the session for the given peer.
struct GNUNET_PeerIdentity GSC_my_identity
Our identity.
Data kept per session.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_PeerIdentity target
Which peer is the message going to be for?
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
caroriginal request that was queued and then solicited; this handle will now be 'owned' by the SESSIONS subsystem
msgmessage to transmit
priorityhow important is this message

Definition at line 868 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(), SessionMessageEntry::next, SessionMessageEntry::prev, SessionMessageEntry::priority, SessionMessageEntry::size, GNUNET_MessageHeader::size, Session::sme_head, Session::sme_tail, GSC_ClientActiveRequest::target, and try_transmission().

Referenced by tokenized_cb().

871 {
872  struct Session *session;
873  struct SessionMessageEntry *sme;
874  struct SessionMessageEntry *pos;
875  size_t msize;
876 
877  session = find_session (&car->target);
878  if (NULL == session)
879  return;
880  msize = ntohs (msg->size);
881  sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) + msize);
882  GNUNET_memcpy (&sme[1], msg, msize);
883  sme->size = msize;
884  sme->priority = priority;
886  {
887  sme->deadline =
890  "Mesage corked, delaying transmission\n");
891  }
892  pos = session->sme_head;
893  while ((NULL != pos) && (pos->priority >= sme->priority))
894  pos = pos->next;
895  if (NULL == pos)
897  session->sme_tail,
898  sme);
899  else
901  session->sme_tail,
902  pos->prev,
903  sme);
904  try_transmission (session);
905 }
size_t size
How long is the message? (number of bytes following the struct MessageEntry, but not including the si...
enum GNUNET_MQ_PriorityPreferences priority
How important is this message.
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:245
static void try_transmission(struct Session *session)
Try to perform a transmission on the given session.
struct SessionMessageEntry * sme_tail
Tail of list of messages ready for encryption.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_TIME_Absolute deadline
Deadline for transmission, 1s after we received it (if we are not corking), otherwise "now"...
Message ready for encryption.
#define GNUNET_memcpy(dst, src, n)
struct SessionMessageEntry * sme_head
Head of list of messages ready for encryption.
struct SessionMessageEntry * next
We keep messages in a doubly linked list.
#define GNUNET_CONTAINER_DLL_insert_after(head, tail, other, element)
Insert an element into a DLL after the given other element.
struct SessionMessageEntry * prev
We keep messages in a doubly linked list.
static struct Session * find_session(const struct GNUNET_PeerIdentity *peer)
Find the session for the given peer.
Data kept per session.
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
#define GNUNET_log(kind,...)
Flag to indicate that CORKing is acceptable.
#define GNUNET_CONSTANTS_MAX_CORK_DELAY
How long do we delay messages to get larger packet sizes (CORKing)?
struct GNUNET_PeerIdentity target
Which peer is the message going to be for?
#define GNUNET_malloc(size)
Wrapper around malloc.
Here is the call graph for this function:
Here is the caller graph for this function:

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

Parameters
msgmessage to transmit

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

References do_restart_typemap_message(), and GNUNET_CONTAINER_multipeermap_iterate().

Referenced by broadcast_my_type_map().

828 {
829  if (NULL == sessions)
830  return;
833  (void *) msg);
834 }
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.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_CONTAINER_MultiPeerMap * sessions
Map of peer identities to struct Session.
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 456 of file gnunet-service-core_sessions.c.

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

Referenced by handle_client_init().

457 {
458  /* notify new client about existing sessions */
461  client);
462 }
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_CONTAINER_MultiPeerMap * sessions
Map of peer identities to struct Session.
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).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_SESSIONS_set_typemap()

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.

Parameters
peerpeer this is about
msgtypemap update message

We've received a typemap message from a peer, update ours.

Notifies clients about the session.

Parameters
peerpeer this is about
msgtypemap update message

Definition at line 916 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, SessionMessageEntry::next, Session::peer, SessionMessageEntry::priority, TypeMapConfirmationMessage::reserved, SessionMessageEntry::size, GNUNET_MessageHeader::size, Session::sme_head, Session::sme_tail, TypeMapConfirmationMessage::tm_hash, Session::tmap, try_transmission(), and GNUNET_MessageHeader::type.

Referenced by deliver_message().

918 {
919  struct Session *session;
920  struct GSC_TypeMap *nmap;
921  struct SessionMessageEntry *sme;
922  struct TypeMapConfirmationMessage *tmc;
923 
924  nmap = GSC_TYPEMAP_get_from_message (msg);
925  if (NULL == nmap)
926  {
927  GNUNET_break_op (0);
928  return; /* malformed */
929  }
930  session = find_session (peer);
931  if (NULL == session)
932  {
933  GSC_TYPEMAP_destroy (nmap);
934  GNUNET_break (0);
935  return;
936  }
938  "Received TYPEMAP from %s\n",
939  GNUNET_i2s (session->peer));
940  for (sme = session->sme_head; NULL != sme; sme = sme->next)
941  {
942  if (GNUNET_YES == sme->is_typemap_confirm)
943  {
944  GNUNET_CONTAINER_DLL_remove (session->sme_head, session->sme_tail, sme);
945  GNUNET_free (sme);
946  break;
947  }
948  }
949  sme = GNUNET_malloc (sizeof (struct SessionMessageEntry) +
950  sizeof (struct TypeMapConfirmationMessage));
952  sme->size = sizeof (struct TypeMapConfirmationMessage);
955  tmc = (struct TypeMapConfirmationMessage *) &sme[1];
956  tmc->header.size = htons (sizeof (struct TypeMapConfirmationMessage));
958  tmc->reserved = htonl (0);
959  GSC_TYPEMAP_hash (nmap, &tmc->tm_hash);
960  GNUNET_CONTAINER_DLL_insert (session->sme_head, session->sme_tail, sme);
961  try_transmission (session);
962  GSC_CLIENTS_notify_clients_about_neighbour (peer, session->tmap, nmap);
963  GSC_TYPEMAP_destroy (session->tmap);
964  session->tmap = nmap;
965 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
size_t size
How long is the message? (number of bytes following the struct MessageEntry, but not including the si...
enum GNUNET_MQ_PriorityPreferences priority
How important is this message.
static void try_transmission(struct Session *session)
Try to perform a transmission on the given session.
struct SessionMessageEntry * sme_tail
Tail of list of messages ready for encryption.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_TIME_Absolute deadline
Deadline for transmission, 1s after we received it (if we are not corking), otherwise "now"...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Message ready for encryption.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP
Other peer confirms having received the type map.
struct SessionMessageEntry * sme_head
Head of list of messages ready for encryption.
struct SessionMessageEntry * next
We keep messages in a doubly linked list.
Message sent to confirm that a typemap was received.
void GSC_TYPEMAP_destroy(struct GSC_TypeMap *tmap)
Free the given type map.
struct GSC_TypeMap * tmap
Current type map for this peer.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static struct Session * find_session(const struct GNUNET_PeerIdentity *peer)
Find the session for the given peer.
Data kept per session.
const struct GNUNET_PeerIdentity * peer
Identity of the other peer.
int is_typemap_confirm
Flag set to GNUNET_YES if this is a typemap confirmation message.
void GSC_TYPEMAP_hash(const struct GSC_TypeMap *tm, struct GNUNET_HashCode *hc)
Hash the contents of a type map.
#define GNUNET_log(kind,...)
A type map describing which messages a given neighbour is able to process.
struct GNUNET_HashCode tm_hash
Hash of the (decompressed) type map that was received.
#define GNUNET_YES
Definition: gnunet_common.h:80
uint32_t reserved
Reserved, always zero.
Highest priority, control traffic (i.e.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
struct GNUNET_MessageHeader header
Header with type GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP.
#define GNUNET_malloc(size)
Wrapper around malloc.
struct GSC_TypeMap * GSC_TYPEMAP_get_from_message(const struct GNUNET_MessageHeader *msg)
Extract a type map from a TYPE_MAP message.
void GSC_CLIENTS_notify_clients_about_neighbour(const struct GNUNET_PeerIdentity *neighbour, const struct GSC_TypeMap *tmap_old, const struct GSC_TypeMap *tmap_new)
Notify all clients about a change to existing session.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GSC_SESSIONS_add_to_typemap()

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.

Parameters
peerpeer this is about
typetype of the message

Definition at line 977 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(), and Session::tmap.

Referenced by GSC_CLIENTS_deliver_message().

979 {
980  struct Session *session;
981  struct GSC_TypeMap *nmap;
982 
983  if (0 == memcmp (peer, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity)))
984  return;
985  session = find_session (peer);
986  GNUNET_assert (NULL != session);
987  if (GNUNET_YES == GSC_TYPEMAP_test_match (session->tmap, &type, 1))
988  return; /* already in it */
989  nmap = GSC_TYPEMAP_extend (session->tmap, &type, 1);
990  GSC_CLIENTS_notify_clients_about_neighbour (peer, session->tmap, nmap);
991  GSC_TYPEMAP_destroy (session->tmap);
992  session->tmap = nmap;
993 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GSC_TYPEMAP_destroy(struct GSC_TypeMap *tmap)
Free the given type map.
struct GSC_TypeMap * tmap
Current type map for this peer.
static struct Session * find_session(const struct GNUNET_PeerIdentity *peer)
Find the session for the given peer.
struct GNUNET_PeerIdentity GSC_my_identity
Our identity.
Data kept per session.
The identity of the host (wraps the signing key of the peer).
int GSC_TYPEMAP_test_match(const struct GSC_TypeMap *tmap, const uint16_t *types, unsigned int tcnt)
Test if any of the types from the types array is in the given type map.
struct GSC_TypeMap * GSC_TYPEMAP_extend(const struct GSC_TypeMap *tmap, const uint16_t *types, unsigned int tcnt)
Add additional types to a given typemap.
A type map describing which messages a given neighbour is able to process.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_YES
Definition: gnunet_common.h:80
void GSC_CLIENTS_notify_clients_about_neighbour(const struct GNUNET_PeerIdentity *neighbour, const struct GSC_TypeMap *tmap_old, const struct GSC_TypeMap *tmap_new)
Notify all clients about a change to existing session.
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 1000 of file gnunet-service-core_sessions.c.

References GNUNET_CONTAINER_multipeermap_create(), and GNUNET_YES.

Referenced by run().

1001 {
1003 }
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).
#define GNUNET_YES
Definition: gnunet_common.h:80
static GNUNET_NETWORK_STRUCT_END struct GNUNET_CONTAINER_MultiPeerMap * sessions
Map of peer identities to struct Session.
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 1031 of file gnunet-service-core_sessions.c.

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

Referenced by shutdown_task().

1032 {
1033  if (NULL != sessions)
1034  {
1037  NULL);
1039  sessions = NULL;
1040  }
1041 }
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
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.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static GNUNET_NETWORK_STRUCT_END struct GNUNET_CONTAINER_MultiPeerMap * sessions
Map of peer identities to struct Session.
Here is the call graph for this function:
Here is the caller graph for this function: