GNUnet  0.11.x
Data Structures | Macros | Typedefs | Enumerations | Functions
MESSENGER service

Instant messaging based on the CADET subsystem. More...

Data Structures

struct  GNUNET_MESSENGER_MessageHeader
 The header of a GNUNET_MESSENGER_Message. More...
 
struct  GNUNET_MESSENGER_MessageInfo
 An info message body. More...
 
struct  GNUNET_MESSENGER_MessageJoin
 A join message body. More...
 
struct  GNUNET_MESSENGER_MessageLeave
 A leave message body. More...
 
struct  GNUNET_MESSENGER_MessageName
 A name message body. More...
 
struct  GNUNET_MESSENGER_MessageKey
 A key message body. More...
 
struct  GNUNET_MESSENGER_MessagePeer
 A peer message body. More...
 
struct  GNUNET_MESSENGER_MessageId
 An id message body. More...
 
struct  GNUNET_MESSENGER_MessageMiss
 A miss message body. More...
 
struct  GNUNET_MESSENGER_MessageMerge
 A merge message body. More...
 
struct  GNUNET_MESSENGER_MessageRequest
 A request message body. More...
 
struct  GNUNET_MESSENGER_MessageInvite
 An invite message body. More...
 
struct  GNUNET_MESSENGER_MessageText
 A text message body. More...
 
struct  GNUNET_MESSENGER_MessageFile
 A file message body. More...
 
struct  GNUNET_MESSENGER_MessagePrivate
 A private message body. More...
 
struct  GNUNET_MESSENGER_MessageBody
 The unified body of a GNUNET_MESSENGER_Message. More...
 
struct  GNUNET_MESSENGER_Message
 Struct to a message. More...
 

Macros

#define GNUNET_MESSENGER_SERVICE_NAME   "messenger"
 

Typedefs

typedef void(* GNUNET_MESSENGER_IdentityCallback) (void *cls, struct GNUNET_MESSENGER_Handle *handle)
 Method called whenever the EGO of a handle changes or if the first connection fails to load a valid EGO and the anonymous key pair will be used instead. More...
 
typedef void(* GNUNET_MESSENGER_MessageCallback) (void *cls, const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
 Method called whenever a message is sent or received from a room. More...
 

Enumerations

enum  GNUNET_MESSENGER_MessageKind {
  GNUNET_MESSENGER_KIND_INFO = 1, GNUNET_MESSENGER_KIND_JOIN = 2, GNUNET_MESSENGER_KIND_LEAVE = 3, GNUNET_MESSENGER_KIND_NAME = 4,
  GNUNET_MESSENGER_KIND_KEY = 5, GNUNET_MESSENGER_KIND_PEER = 6, GNUNET_MESSENGER_KIND_ID = 7, GNUNET_MESSENGER_KIND_MISS = 8,
  GNUNET_MESSENGER_KIND_MERGE = 9, GNUNET_MESSENGER_KIND_REQUEST = 10, GNUNET_MESSENGER_KIND_INVITE = 11, GNUNET_MESSENGER_KIND_TEXT = 12,
  GNUNET_MESSENGER_KIND_FILE = 13, GNUNET_MESSENGER_KIND_PRIVATE = 14, GNUNET_MESSENGER_KIND_UNKNOWN = 0
}
 Enum for the different supported kinds of messages. More...
 

Functions

const char * GNUNET_MESSENGER_name_of_kind (enum GNUNET_MESSENGER_MessageKind kind)
 Get the name of a message kind. More...
 
struct GNUNET_MESSENGER_HandleGNUNET_MESSENGER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, GNUNET_MESSENGER_IdentityCallback identity_callback, void *identity_cls, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls)
 Set up a handle for the messenger related functions and connects to all necessary services. More...
 
int GNUNET_MESSENGER_update (struct GNUNET_MESSENGER_Handle *handle)
 Update a handle of the messenger to use a different ego key and replace the old one with a newly generated one. More...
 
void GNUNET_MESSENGER_disconnect (struct GNUNET_MESSENGER_Handle *handle)
 Disconnect all of the messengers used services and clears up its used memory. More...
 
const char * GNUNET_MESSENGER_get_name (const struct GNUNET_MESSENGER_Handle *handle)
 Get the name (if specified, otherwise NULL) used by the messenger. More...
 
int GNUNET_MESSENGER_set_name (struct GNUNET_MESSENGER_Handle *handle, const char *name)
 Set the name for the messenger. More...
 
const struct GNUNET_IDENTITY_PublicKeyGNUNET_MESSENGER_get_key (const struct GNUNET_MESSENGER_Handle *handle)
 Get the public key used by the messenger. More...
 
struct GNUNET_MESSENGER_RoomGNUNET_MESSENGER_open_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
 Open a room to send and receive messages. More...
 
struct GNUNET_MESSENGER_RoomGNUNET_MESSENGER_entry_room (struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
 Enter a room to send and receive messages through a door opened using GNUNET_MESSENGER_open_room(...). More...
 
void GNUNET_MESSENGER_close_room (struct GNUNET_MESSENGER_Room *room)
 Close a room which was entered, opened or both in various order and variety. More...
 
struct GNUNET_MESSENGER_ContactGNUNET_MESSENGER_get_member (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_ShortHashCode *id)
 Get the contact of a member in a room identified by their id. More...
 
const char * GNUNET_MESSENGER_contact_get_name (const struct GNUNET_MESSENGER_Contact *contact)
 Get the name used by the contact. More...
 
const struct GNUNET_IDENTITY_PublicKeyGNUNET_MESSENGER_contact_get_key (const struct GNUNET_MESSENGER_Contact *contact)
 Get the public key used by the contact. More...
 
void GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message)
 Send a message into a room. More...
 
const struct GNUNET_MESSENGER_MessageGNUNET_MESSENGER_get_message (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
 Get the message in a room identified by its hash. More...
 

Detailed Description

Instant messaging based on the CADET subsystem.

Macro Definition Documentation

◆ GNUNET_MESSENGER_SERVICE_NAME

#define GNUNET_MESSENGER_SERVICE_NAME   "messenger"

Definition at line 51 of file gnunet_messenger_service.h.

Referenced by create_service(), reconnect(), and run().

Typedef Documentation

◆ GNUNET_MESSENGER_IdentityCallback

typedef void(* GNUNET_MESSENGER_IdentityCallback) (void *cls, struct GNUNET_MESSENGER_Handle *handle)

Method called whenever the EGO of a handle changes or if the first connection fails to load a valid EGO and the anonymous key pair will be used instead.

Parameters
clsClosure from GNUNET_MESSENGER_connect
handleMessenger handle

Definition at line 422 of file gnunet_messenger_service.h.

◆ GNUNET_MESSENGER_MessageCallback

typedef void(* GNUNET_MESSENGER_MessageCallback) (void *cls, const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)

Method called whenever a message is sent or received from a room.

Parameters
clsClosure from GNUNET_MESSENGER_connect
roomRoom handle
messageNewly received or sent message
hashHash identifying the message

Definition at line 433 of file gnunet_messenger_service.h.

Enumeration Type Documentation

◆ GNUNET_MESSENGER_MessageKind

Enum for the different supported kinds of messages.

Enumerator
GNUNET_MESSENGER_KIND_INFO 

The info kind.

The message contains a GNUNET_MESSENGER_MessageInfo body.

GNUNET_MESSENGER_KIND_JOIN 

The join kind.

The message contains a GNUNET_MESSENGER_MessageJoin body.

GNUNET_MESSENGER_KIND_LEAVE 

The leave kind.

The message contains a GNUNET_MESSENGER_MessageLeave body.

GNUNET_MESSENGER_KIND_NAME 

The name kind.

The message contains a GNUNET_MESSENGER_MessageName body.

GNUNET_MESSENGER_KIND_KEY 

The key kind.

The message contains a GNUNET_MESSENGER_MessageKey body.

GNUNET_MESSENGER_KIND_PEER 

The peer kind.

The message contains a GNUNET_MESSENGER_MessagePeer body.

GNUNET_MESSENGER_KIND_ID 

The id kind.

The message contains a GNUNET_MESSENGER_MessageId body.

GNUNET_MESSENGER_KIND_MISS 

The miss kind.

The message contains a GNUNET_MESSENGER_MessageMiss body.

GNUNET_MESSENGER_KIND_MERGE 

The merge kind.

The message contains a GNUNET_MESSENGER_MessageMerge body.

GNUNET_MESSENGER_KIND_REQUEST 

The request kind.

The message contains a GNUNET_MESSENGER_MessageRequest body.

GNUNET_MESSENGER_KIND_INVITE 

The invite kind.

The message contains a GNUNET_MESSENGER_MessageInvite body.

GNUNET_MESSENGER_KIND_TEXT 

The text kind.

The message contains a GNUNET_MESSENGER_MessageText body.

GNUNET_MESSENGER_KIND_FILE 

The file kind.

The message contains a GNUNET_MESSENGER_MessageFile body.

GNUNET_MESSENGER_KIND_PRIVATE 

The private kind.

The message contains a GNUNET_MESSENGER_MessagePrivate body.

GNUNET_MESSENGER_KIND_UNKNOWN 

The unknown kind.

The message contains an unknown body.

Definition at line 71 of file gnunet_messenger_service.h.

72 {
77 
82 
87 
92 
97 
102 
107 
112 
117 
122 
127 
132 
137 
142 
147 };

Function Documentation

◆ GNUNET_MESSENGER_name_of_kind()

const char* GNUNET_MESSENGER_name_of_kind ( enum GNUNET_MESSENGER_MessageKind  kind)

Get the name of a message kind.

Parameters
kindKind of a message
Returns
Name of that kind

Definition at line 34 of file messenger_api.c.

References GNUNET_MESSENGER_KIND_FILE, GNUNET_MESSENGER_KIND_ID, GNUNET_MESSENGER_KIND_INFO, GNUNET_MESSENGER_KIND_INVITE, GNUNET_MESSENGER_KIND_JOIN, GNUNET_MESSENGER_KIND_KEY, GNUNET_MESSENGER_KIND_LEAVE, GNUNET_MESSENGER_KIND_MERGE, GNUNET_MESSENGER_KIND_MISS, GNUNET_MESSENGER_KIND_NAME, GNUNET_MESSENGER_KIND_PEER, GNUNET_MESSENGER_KIND_REQUEST, and GNUNET_MESSENGER_KIND_TEXT.

Referenced by handle_recv_message(), and handle_send_message().

35 {
36  switch (kind)
37  {
39  return "INFO";
41  return "JOIN";
43  return "LEAVE";
45  return "NAME";
47  return "KEY";
49  return "PEER";
51  return "ID";
53  return "MISS";
55  return "MERGE";
57  return "REQUEST";
59  return "INVITE";
61  return "TEXT";
63  return "FILE";
64  default:
65  return "UNKNOWN";
66  }
67 }
Here is the caller graph for this function:

◆ GNUNET_MESSENGER_connect()

struct GNUNET_MESSENGER_Handle* GNUNET_MESSENGER_connect ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  name,
GNUNET_MESSENGER_IdentityCallback  identity_callback,
void *  identity_cls,
GNUNET_MESSENGER_MessageCallback  msg_callback,
void *  msg_cls 
)

Set up a handle for the messenger related functions and connects to all necessary services.

It will look up the ego key identified by its name and use it for signing all messages from the handle.

Parameters
cfgConfiguration to use
nameName to look up an ego or NULL to stay anonymous
identity_callbackFunction called when the EGO of the handle changes
identity_clsClosure for the identity_callback handler
msg_callbackFunction called when a new message is sent or received
msg_clsClosure for the msg_callback handler
Returns
Messenger handle to use, NULL on error

Definition at line 355 of file messenger_api.c.

References create_handle(), destroy_handle(), env, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), handle, GNUNET_MESSENGER_Handle::mq, msg, and reconnect().

Referenced by run().

358 {
360 
361  reconnect (handle);
362 
363  if (handle->mq)
364  {
365  const uint16_t name_len = name ? strlen (name) : 0;
366 
368  struct GNUNET_MQ_Envelope *env;
369 
371 
372  char *extra = ((char*) msg) + sizeof(*msg);
373 
374  if (name_len)
375  GNUNET_memcpy(extra, name, name_len);
376 
377  extra[name_len] = '\0';
378 
379  GNUNET_MQ_send (handle->mq, env);
380  return handle;
381  }
382  else
383  {
384  destroy_handle (handle);
385  return NULL;
386  }
387 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE
struct GNUNET_MQ_Handle * mq
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
Message to create a handle for a client.
GNUNET_MESSENGER_MessageCallback msg_callback
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void destroy_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Destroys a handle and frees its memory fully.
struct GNUNET_MESSENGER_SrvHandle * create_handle(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq)
Creates and allocates a new handle related to a service and using a given mq (message queue)...
const char * name
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
static void reconnect(struct GNUNET_MESSENGER_Handle *handle)
GNUNET_MESSENGER_IdentityCallback identity_callback
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MESSENGER_update()

int GNUNET_MESSENGER_update ( struct GNUNET_MESSENGER_Handle handle)

Update a handle of the messenger to use a different ego key and replace the old one with a newly generated one.

All participated rooms get informed about the key renewal. The handle requires a set name for this function to work and it needs to be unused by other egos.

Keep in mind that this will fully delete the old ego key (if any is used) even if any other service wants to use it as default.

Parameters
handleMessenger handle to use
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 390 of file messenger_api.c.

References env, get_handle_name(), GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, GNUNET_SYSERR, GNUNET_MESSENGER_Handle::mq, and msg.

391 {
392  if ((!handle) || (!get_handle_name(handle)))
393  return GNUNET_SYSERR;
394 
396  struct GNUNET_MQ_Envelope *env;
397 
399  GNUNET_MQ_send (handle->mq, env);
400  return GNUNET_OK;
401 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
const char * get_handle_name(const struct GNUNET_MESSENGER_Handle *handle)
Returns the current name of a given handle or NULL if no valid name was assigned yet.
struct GNUNET_MQ_Handle * mq
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Message to update the handle (its EGO key) for a client.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
Here is the call graph for this function:

◆ GNUNET_MESSENGER_disconnect()

void GNUNET_MESSENGER_disconnect ( struct GNUNET_MESSENGER_Handle handle)

Disconnect all of the messengers used services and clears up its used memory.

Parameters
handleMessenger handle to use

Definition at line 404 of file messenger_api.c.

References destroy_handle(), env, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_MESSENGER_Handle::mq, and msg.

Referenced by shutdown_hook().

405 {
406  if (!handle)
407  return;
408 
410  struct GNUNET_MQ_Envelope *env;
411 
413  GNUNET_MQ_send (handle->mq, env);
414 
415  destroy_handle (handle);
416 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_MQ_Handle * mq
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Message to destroy the handle for a client.
void destroy_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Destroys a handle and frees its memory fully.
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MESSENGER_get_name()

const char* GNUNET_MESSENGER_get_name ( const struct GNUNET_MESSENGER_Handle handle)

Get the name (if specified, otherwise NULL) used by the messenger.

Parameters
handleMessenger handle to use
Returns
Name used by the messenger or NULL

Definition at line 419 of file messenger_api.c.

References get_handle_name().

Referenced by on_identity().

420 {
421  if (!handle)
422  return NULL;
423 
424  return get_handle_name (handle);
425 }
const char * get_handle_name(const struct GNUNET_MESSENGER_Handle *handle)
Returns the current name of a given handle or NULL if no valid name was assigned yet.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MESSENGER_set_name()

int GNUNET_MESSENGER_set_name ( struct GNUNET_MESSENGER_Handle handle,
const char *  name 
)

Set the name for the messenger.

This will rename the currently used ego and move all stored files related to the current name to its new directory. If anything fails during this process the function returns GNUNET_NO and the name for the messenger won't change as specified.

Parameters
handleMessenger handle to use
nameName for the messenger to change to
Returns
GNUNET_YES on success, GNUNET_NO on failure and GNUNET_SYSERR if handle is NULL

Definition at line 428 of file messenger_api.c.

References env, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_SYSERR, GNUNET_YES, GNUNET_MESSENGER_Handle::mq, and msg.

429 {
430  if (!handle)
431  return GNUNET_SYSERR;
432 
433  const uint16_t name_len = name ? strlen (name) : 0;
434 
436  struct GNUNET_MQ_Envelope *env;
437 
439 
440  char *extra = ((char*) msg) + sizeof(*msg);
441 
442  if (name_len)
443  GNUNET_memcpy(extra, name, name_len);
444 
445  extra[name_len] = '\0';
446 
447  GNUNET_MQ_send (handle->mq, env);
448  return GNUNET_YES;
449 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_MQ_Handle * mq
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
const char * name
Message to receive the current name of a handle.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
Here is the call graph for this function:

◆ GNUNET_MESSENGER_get_key()

const struct GNUNET_IDENTITY_PublicKey* GNUNET_MESSENGER_get_key ( const struct GNUNET_MESSENGER_Handle handle)

Get the public key used by the messenger.

Parameters
handleMessenger handle to use
Returns
Used ego's public key

Definition at line 452 of file messenger_api.c.

References get_handle_key().

453 {
454  if (!handle)
455  return NULL;
456 
457  return get_handle_key (handle);
458 }
const struct GNUNET_IDENTITY_PublicKey * get_handle_key(const struct GNUNET_MESSENGER_Handle *handle)
Returns the public key of a given handle.
Here is the call graph for this function:

◆ GNUNET_MESSENGER_open_room()

struct GNUNET_MESSENGER_Room* GNUNET_MESSENGER_open_room ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_HashCode key 
)

Open a room to send and receive messages.

The room will use the specified key as port for the underlying cadet service. Opening a room results in opening the port for incoming connections as possible door.

Notice that there can only be one room related to a specific key. So trying to open two rooms with the same key will result in opening the room once but returning the handle both times because the room stays open.

You can also open a room after entering it through a door using GNUNET_MESSENGER_entry_room(...). This will notify all entered doors to list you as new door.

( All doors form a ring structured network to shorten the latency sending and receiving messages. )

Parameters
handleMessenger handle to use
keyHash identifying the port
Returns
Room handle, NULL on error

Definition at line 461 of file messenger_api.c.

References create_room(), destroy_room(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_OK, GNUNET_MESSENGER_Handle::rooms, and send_open_room().

Referenced by on_identity().

462 {
463  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
464 
465  if (!room)
466  {
467  room = create_room (handle, key);
468 
469  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room,
471  {
472  destroy_room (room);
473  return NULL;
474  }
475  }
476 
477  send_open_room (handle, room);
478  return room;
479 }
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_CONTAINER_MultiHashMap * rooms
static void send_open_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_MESSENGER_SrvRoom * create_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Creates and allocates a new room for a handle with a given key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MESSENGER_entry_room()

struct GNUNET_MESSENGER_Room* GNUNET_MESSENGER_entry_room ( struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_PeerIdentity door,
const struct GNUNET_HashCode key 
)

Enter a room to send and receive messages through a door opened using GNUNET_MESSENGER_open_room(...).

Notice that there can only be one room related to a specific key. So trying to enter two rooms with the same key will result in entering the room once but returning the handle both times because the room stays entered. You can however enter a room through multiple doors in parallel which results in connecting both ends. But entering the room through the same door won't have any effect after the first time.

You can also enter a room through a door after opening it using GNUNET_MESSENGER_open_room(...). But the door may not be your own peer identity.

( All doors form a ring structured network to shorten the latency sending and receiving messages. )

Parameters
handleMessenger handle to use
doorPeer identity of an open door
keyHash identifying the port
Returns
Room handle, NULL on error

Definition at line 482 of file messenger_api.c.

References create_room(), destroy_room(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_OK, GNUNET_MESSENGER_Handle::rooms, and send_entry_room().

Referenced by on_identity().

484 {
485  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
486 
487  if (!room)
488  {
489  room = create_room (handle, key);
490 
491  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room,
493  {
494  destroy_room (room);
495  return NULL;
496  }
497  }
498 
499  send_entry_room (handle, room, door);
500  return room;
501 }
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
struct GNUNET_CONTAINER_MultiHashMap * rooms
static void send_entry_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_PeerIdentity *door)
int GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
struct GNUNET_MESSENGER_SrvRoom * create_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Creates and allocates a new room for a handle with a given key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MESSENGER_close_room()

void GNUNET_MESSENGER_close_room ( struct GNUNET_MESSENGER_Room room)

Close a room which was entered, opened or both in various order and variety.

Closing a room will destroy all connections from your peer to another and the other way around.

( After a member closes a door, all members entered through that specific door have to use another one or open the room on their own. )

Parameters
roomRoom handle

Definition at line 504 of file messenger_api.c.

References GNUNET_MESSENGER_Room::handle, and send_close_room().

Referenced by shutdown_hook().

505 {
506  send_close_room (room->handle, room);
507 }
struct GNUNET_MESSENGER_Handle * handle
static void send_close_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MESSENGER_get_member()

struct GNUNET_MESSENGER_Contact* GNUNET_MESSENGER_get_member ( const struct GNUNET_MESSENGER_Room room,
const struct GNUNET_ShortHashCode id 
)

Get the contact of a member in a room identified by their id.

Notice that contacts are independent of rooms but will be removed if all rooms containing these contacts get closed.

Parameters
roomRoom handle
idHash identifying a member
Returns
Contact handle, NULL if id is not in use

Definition at line 510 of file messenger_api.c.

References GNUNET_CONTAINER_multishortmap_get(), and GNUNET_MESSENGER_Room::members.

Referenced by on_message().

511 {
512  return GNUNET_CONTAINER_multishortmap_get (room->members, id);
513 }
struct GNUNET_CONTAINER_MultiShortmap * members
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MESSENGER_contact_get_name()

const char* GNUNET_MESSENGER_contact_get_name ( const struct GNUNET_MESSENGER_Contact contact)

Get the name used by the contact.

Parameters
contactContact handle
Returns
Name of contact or NULL

Definition at line 516 of file messenger_api.c.

References get_contact_name().

Referenced by on_message().

517 {
518  if (!contact)
519  return NULL;
520 
521  return get_contact_name (contact);
522 }
const char * get_contact_name(const struct GNUNET_MESSENGER_SrvContact *contact)
Returns the current name of a given contact or NULL if no valid name was assigned yet...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MESSENGER_contact_get_key()

const struct GNUNET_IDENTITY_PublicKey* GNUNET_MESSENGER_contact_get_key ( const struct GNUNET_MESSENGER_Contact contact)

Get the public key used by the contact.

Parameters
contactContact handle
Returns
Public key of the ego used by contact

Definition at line 525 of file messenger_api.c.

References get_contact_key().

526 {
527  if (!contact)
528  return NULL;
529 
530  return get_contact_key (contact);
531 }
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_SrvContact *contact)
Returns the public key of a given contact.
Here is the call graph for this function:

◆ GNUNET_MESSENGER_send_message()

void GNUNET_MESSENGER_send_message ( struct GNUNET_MESSENGER_Room room,
const struct GNUNET_MESSENGER_Message message 
)

Send a message into a room.

If you opened the room all entered members will receive the message. If you entered the room through a door all so entered doors will receive the message as well. All members receiving the message will also propagate this message recursively as long as the message is unknown to them.

Notice that all messages sent and received are also stored and can be propagated to new members entering the room.

Parameters
roomRoom handle
messageNew message to send

Definition at line 534 of file messenger_api.c.

References encode_message(), env, get_message_size(), GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_MESSENGER_Room::handle, GNUNET_MESSENGER_SendMessage::key, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_Handle::mq, and msg.

Referenced by read_stdio().

535 {
536  const uint16_t length = get_message_size (message);
537 
539  struct GNUNET_MQ_Envelope *env;
540 
542 
543  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key));
544 
545  char *buffer = ((char*) msg) + sizeof(*msg);
546  encode_message (message, length, buffer);
547 
548  GNUNET_MQ_send (room->handle->mq, env);
549 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_HashCode key
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message)
Returns the exact size in bytes to encode a given message.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer)
Encodes a given message into a buffer of a maximal length in bytes.
struct GNUNET_MQ_Handle * mq
Message to send something into a room.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MESSENGER_get_message()

const struct GNUNET_MESSENGER_Message* GNUNET_MESSENGER_get_message ( const struct GNUNET_MESSENGER_Room room,
const struct GNUNET_HashCode hash 
)

Get the message in a room identified by its hash.

Parameters
roomRoom handle
hashHash identifying a message
Returns
Message struct or NULL if no message with that hash is known

Definition at line 552 of file messenger_api.c.

References env, get_room_message(), GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_MESSENGER_Room::handle, GNUNET_MESSENGER_RecvMessage::hash, GNUNET_MESSENGER_RecvMessage::key, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_Handle::mq, and msg.

553 {
554  const struct GNUNET_MESSENGER_Message *message = get_room_message (room, hash);
555 
556  if (!message)
557  {
559  struct GNUNET_MQ_Envelope *env;
560 
562  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key));
563  GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash));
564  GNUNET_MQ_send (room->handle->mq, env);
565  }
566 
567  return message;
568 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_HashCode key
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_MQ_Handle * mq
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
const struct GNUNET_MESSENGER_Message * get_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *hash, int request)
Returns a message from a room identified by a given hash.
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
Message to receive something from a room.
Here is the call graph for this function: