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_MessageDelete
 A delete message body This allows deletion of an own previous message with any custom automatic delay. 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_VERSION   0x00000001
 Version number of GNUnet Messenger API. More...
 
#define GNUNET_MESSENGER_SERVICE_NAME   "messenger"
 Identifier of GNUnet MESSENGER Service. More...
 
#define GNUNET_MESSENGER_KIND_MAX   (GNUNET_MESSENGER_KIND_DELETE)
 

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, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_MessageFlags flags)
 Method called whenever a message is sent or received from a room. More...
 
typedef int(* GNUNET_MESSENGER_MemberCallback) (void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)
 Method called for each member in a room during iteration. 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_DELETE = 15, GNUNET_MESSENGER_KIND_UNKNOWN = 0
}
 Enum for the different supported kinds of messages. More...
 
enum  GNUNET_MESSENGER_MessageFlags { GNUNET_MESSENGER_FLAG_NONE = 0, GNUNET_MESSENGER_FLAG_SENT = 1, GNUNET_MESSENGER_FLAG_PRIVATE = 2 }
 Enum for the different supported flags used by message handling Compatible flags can be OR'ed together. 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 or NULL if the anonymous key was used. 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_enter_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...
 
int GNUNET_MESSENGER_find_rooms (const struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_MESSENGER_Contact *contact, GNUNET_MESSENGER_MemberCallback callback, void *cls)
 Searches for a specific contact in a given room and calls a selected callback with a given closure for each of them containing the contact as a member. More...
 
const struct GNUNET_HashCodeGNUNET_MESSENGER_room_get_key (const struct GNUNET_MESSENGER_Room *room)
 Get the key of a given room. More...
 
const struct GNUNET_MESSENGER_ContactGNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
 Get the contact of a member in a room which sent a specific message identified with a given hash. 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 or NULL if the anonymous key was used. More...
 
void GNUNET_MESSENGER_send_message (struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_MESSENGER_Contact *contact)
 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...
 
int GNUNET_MESSENGER_iterate_members (struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback, void *cls)
 Iterates through all members of a given room and calls a selected callback for each of them with a provided closure. More...
 

Detailed Description

Instant messaging based on the CADET subsystem.

Macro Definition Documentation

◆ GNUNET_MESSENGER_VERSION

#define GNUNET_MESSENGER_VERSION   0x00000001

Version number of GNUnet Messenger API.

Current version of the Messenger: 0.1

Definition at line 56 of file gnunet_messenger_service.h.

Referenced by convert_messenger_key_to_port(), create_message_info(), iterate_send_room_message(), and update_tunnel_messenger_version().

◆ GNUNET_MESSENGER_SERVICE_NAME

#define GNUNET_MESSENGER_SERVICE_NAME   "messenger"

Identifier of GNUnet MESSENGER Service.

Definition at line 61 of file gnunet_messenger_service.h.

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

◆ GNUNET_MESSENGER_KIND_MAX

#define GNUNET_MESSENGER_KIND_MAX   (GNUNET_MESSENGER_KIND_DELETE)

Definition at line 164 of file gnunet_messenger_service.h.

Referenced by calc_usual_padding().

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

Definition at line 530 of file gnunet_messenger_service.h.

◆ GNUNET_MESSENGER_MessageCallback

typedef void(* GNUNET_MESSENGER_MessageCallback) (void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, enum GNUNET_MESSENGER_MessageFlags flags)

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

The flag private_message will be GNUNET_YES if a message was received privately, otherwise GNUNET_NO.

Parameters

Definition at line 546 of file gnunet_messenger_service.h.

◆ GNUNET_MESSENGER_MemberCallback

typedef int(* GNUNET_MESSENGER_MemberCallback) (void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)

Method called for each member in a room during iteration.

If the method returns GNUNET_YES the iteration continues, otherwise it will quit the iteration.

Parameters

Definition at line 561 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_DELETE 

The delete kind.

The message contains a GNUNET_MESSENGER_MessageDelete body.

GNUNET_MESSENGER_KIND_UNKNOWN 

The unknown kind.

The message contains an unknown body.

Definition at line 81 of file gnunet_messenger_service.h.

82 {
87 
92 
97 
102 
107 
112 
117 
122 
127 
132 
137 
142 
147 
152 
157 
162 };

◆ GNUNET_MESSENGER_MessageFlags

Enum for the different supported flags used by message handling Compatible flags can be OR'ed together.

Enumerator
GNUNET_MESSENGER_FLAG_NONE 

The none flag.

The flag indicates that the message is not affected by any special context.

GNUNET_MESSENGER_FLAG_SENT 

The sent flag.

The flag indicates that the message was sent by the client.

GNUNET_MESSENGER_FLAG_PRIVATE 

The private flag.

The flag indicates that the message was privately encrypted.

Definition at line 504 of file gnunet_messenger_service.h.

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 35 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_PRIVATE, GNUNET_MESSENGER_KIND_REQUEST, and GNUNET_MESSENGER_KIND_TEXT.

Referenced by callback_verify_room_message(), handle_recv_message(), handle_send_message(), handle_tunnel_message(), and on_message().

36 {
37  switch (kind)
38  {
40  return "INFO";
42  return "JOIN";
44  return "LEAVE";
46  return "NAME";
48  return "KEY";
50  return "PEER";
52  return "ID";
54  return "MISS";
56  return "MERGE";
58  return "REQUEST";
60  return "INVITE";
62  return "TEXT";
64  return "FILE";
66  return "PRIVATE";
67  default:
68  return "UNKNOWN";
69  }
70 }
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
[in]cfgConfiguration to use
[in]nameName to look up an ego or NULL to stay anonymous
[in]identity_callbackFunction called when the EGO of the handle changes

Definition at line 405 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 on_peer(), and run().

408 {
410 
411  reconnect (handle);
412 
413  if (handle->mq)
414  {
415  const uint16_t name_len = name ? strlen (name) : 0;
416 
418  struct GNUNET_MQ_Envelope *env;
419 
421 
422  char *extra = ((char*) msg) + sizeof(*msg);
423 
424  if (name_len)
425  GNUNET_memcpy(extra, name, name_len);
426 
427  extra[name_len] = '\0';
428 
429  GNUNET_MQ_send (handle->mq, env);
430  return handle;
431  }
432  else
433  {
434  destroy_handle (handle);
435  return NULL;
436  }
437 }
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

Definition at line 440 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.

441 {
442  if ((!handle) || (!get_handle_name (handle)))
443  return GNUNET_SYSERR;
444 
446  struct GNUNET_MQ_Envelope *env;
447 
449  GNUNET_MQ_send (handle->mq, env);
450  return GNUNET_OK;
451 }
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

Definition at line 454 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_cb(), and shutdown_hook().

455 {
456  if (!handle)
457  return;
458 
460  struct GNUNET_MQ_Envelope *env;
461 
463  GNUNET_MQ_send (handle->mq, env);
464 
465  destroy_handle (handle);
466 }
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
[in]handleMessenger handle to use
Returns
Name used by the messenger or NULL

Definition at line 469 of file messenger_api.c.

References get_handle_name().

Referenced by on_identity().

470 {
471  if (!handle)
472  return NULL;
473 
474  return get_handle_name (handle);
475 }
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

Definition at line 478 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.

479 {
480  if (!handle)
481  return GNUNET_SYSERR;
482 
483  const uint16_t name_len = name ? strlen (name) : 0;
484 
486  struct GNUNET_MQ_Envelope *env;
487 
489 
490  char *extra = ((char*) msg) + sizeof(*msg);
491 
492  if (name_len)
493  GNUNET_memcpy(extra, name, name_len);
494 
495  extra[name_len] = '\0';
496 
497  GNUNET_MQ_send (handle->mq, env);
498  return GNUNET_YES;
499 }
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 or NULL if the anonymous key was used.

Parameters
[in]handleMessenger handle to use
Returns
Used ego's public key or NULL

Definition at line 511 of file messenger_api.c.

References get_handle_key(), and get_non_anonymous_key().

512 {
513  if (!handle)
514  return NULL;
515 
516  return get_non_anonymous_key (get_handle_key (handle));
517 }
const struct GNUNET_IDENTITY_PublicKey * get_handle_key(const struct GNUNET_MESSENGER_Handle *handle)
Returns the public key of a given handle.
static const struct GNUNET_IDENTITY_PublicKey * get_non_anonymous_key(const struct GNUNET_IDENTITY_PublicKey *public_key)
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_enter_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

Definition at line 520 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(), on_peer(), and second_stage().

521 {
522  if ((!handle) || (!key))
523  return NULL;
524 
525  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
526 
527  if (!room)
528  {
529  room = create_room (handle, key);
530 
531  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room,
533  {
534  destroy_room (room);
535  return NULL;
536  }
537  }
538 
539  send_open_room (handle, room);
540  return room;
541 }
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_enter_room()

struct GNUNET_MESSENGER_Room* GNUNET_MESSENGER_enter_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

Definition at line 544 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_enter_room().

Referenced by barrier_wait_cb(), on_identity(), and second_stage().

546 {
547  if ((!handle) || (!door) || (!key))
548  return NULL;
549 
550  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
551 
552  if (!room)
553  {
554  room = create_room (handle, key);
555 
556  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room,
558  {
559  destroy_room (room);
560  return NULL;
561  }
562  }
563 
564  send_enter_room (handle, room, door);
565  return room;
566 }
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
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.
static void send_enter_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_PeerIdentity *door)
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

Definition at line 569 of file messenger_api.c.

References GNUNET_MESSENGER_Room::handle, and send_close_room().

Referenced by shutdown_cb(), and shutdown_hook().

570 {
571  if (!room)
572  return;
573 
574  send_close_room (room->handle, room);
575 }
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_find_rooms()

int GNUNET_MESSENGER_find_rooms ( const struct GNUNET_MESSENGER_Handle handle,
const struct GNUNET_MESSENGER_Contact contact,
GNUNET_MESSENGER_MemberCallback  callback,
void *  cls 
)

Searches for a specific contact in a given room and calls a selected callback with a given closure for each of them containing the contact as a member.

The callback will receive a room matching the condition and the given contact. The function returns the amount of rooms iterated with the given callback.

Parameters
[in]handleMessenger handle to use
[in]contactContact handle
[in]callbackFunction called for each room
[in]clsClosure for the callback handler
Returns
Amount of rooms iterated

Definition at line 605 of file messenger_api.c.

References GNUNET_MESSENGER_RoomFind::callback, GNUNET_MESSENGER_RoomFind::cls, GNUNET_MESSENGER_RoomFind::contact, GNUNET_MESSENGER_RoomFind::counter, GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_SYSERR, iterate_find_room(), GNUNET_MESSENGER_Contact::rc, GNUNET_MESSENGER_Handle::rooms, and SIZE_MAX.

607 {
608  if (!handle)
609  return GNUNET_SYSERR;
610 
611  struct GNUNET_MESSENGER_RoomFind find;
612 
613  find.contact = contact;
614  find.callback = callback;
615  find.counter = (contact? contact->rc : SIZE_MAX);
616  find.cls = cls;
617 
619 }
GNUNET_MESSENGER_MemberCallback callback
#define SIZE_MAX
Definition: platform.h:213
struct GNUNET_CONTAINER_MultiHashMap * rooms
const struct GNUNET_MESSENGER_Contact * contact
static int iterate_find_room(void *cls, const struct GNUNET_HashCode *key, void *value)
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
Here is the call graph for this function:

◆ GNUNET_MESSENGER_room_get_key()

const struct GNUNET_HashCode* GNUNET_MESSENGER_room_get_key ( const struct GNUNET_MESSENGER_Room room)

Get the key of a given room.

Parameters
[in]roomRoom handle
Returns
Hash identifying the port or NULL on failure

Definition at line 622 of file messenger_api.c.

References GNUNET_MESSENGER_Room::key.

623 {
624  if (!room)
625  return NULL;
626 
627  return &(room->key);
628 }
struct GNUNET_HashCode key

◆ GNUNET_MESSENGER_get_sender()

const struct GNUNET_MESSENGER_Contact* GNUNET_MESSENGER_get_sender ( const struct GNUNET_MESSENGER_Room room,
const struct GNUNET_HashCode hash 
)

Get the contact of a member in a room which sent a specific message identified with a given hash.

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

Parameters
[in]roomRoom handle
[in]hashHash identifying a message
Returns
Contact handle, NULL otherwise

Definition at line 631 of file messenger_api.c.

References get_room_sender().

632 {
633  if ((!room) || (!hash))
634  return NULL;
635 
636  return get_room_sender(room, hash);
637 }
struct GNUNET_MESSENGER_Contact * get_room_sender(const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
Returns a messages sender locally stored from a map for a given hash in a room.
Here is the call 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
[in]contactContact handle
Returns
Name of contact or NULL

Definition at line 640 of file messenger_api.c.

References get_contact_name().

Referenced by on_message().

641 {
642  if (!contact)
643  return NULL;
644 
645  return get_contact_name (contact);
646 }
const char * get_contact_name(const struct GNUNET_MESSENGER_Contact *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 or NULL if the anonymous key was used.

Parameters
[in]contactContact handle
Returns
Public key of the ego used by contact or NULL

Definition at line 649 of file messenger_api.c.

References get_contact_key(), and get_non_anonymous_key().

Referenced by iterate_send_private_message().

650 {
651  if (!contact)
652  return NULL;
653 
654  return get_non_anonymous_key (get_contact_key (contact));
655 }
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.
static const struct GNUNET_IDENTITY_PublicKey * get_non_anonymous_key(const struct GNUNET_IDENTITY_PublicKey *public_key)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_MESSENGER_send_message()

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

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.

If you provide a specific contact as receiver of the given message, the message will automatically be encrypted and sent as a private message (see GNUNET_MESSENGER_MessagePrivate). Therefore the selected contact will be the only member receiving the actual message.

Sending a message to all members in a given room can be done by providing NULL as contact.

Parameters

Definition at line 658 of file messenger_api.c.

References encode_message(), env, filter_message_sending(), GNUNET_MESSENGER_SendMessage::flags, get_contact_key(), get_message_size(), get_non_anonymous_key(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_IDENTITY_key_get_length(), GNUNET_IDENTITY_write_key_to_buffer(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE, GNUNET_MESSENGER_FLAG_NONE, GNUNET_MESSENGER_FLAG_PRIVATE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SYSERR, GNUNET_MESSENGER_Room::handle, GNUNET_MESSENGER_SendMessage::key, GNUNET_MESSENGER_Room::key, key_length, GNUNET_MESSENGER_Handle::mq, and msg.

Referenced by iterate_send_private_message(), on_identity(), and read_stdio().

660 {
661  if ((!room) || (!message))
662  return;
663 
664  switch (filter_message_sending (message))
665  {
666  case GNUNET_SYSERR:
667  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sending message aborted: This kind of message is reserved for the service!\n");
668  return;
669  case GNUNET_NO:
670  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: This kind of message could cause issues!\n");
671  return;
672  default:
673  break;
674  }
675 
676  ssize_t key_length = 0;
677 
678  if (contact)
679  {
680  const struct GNUNET_IDENTITY_PublicKey *public_key = get_non_anonymous_key (
681  get_contact_key(contact)
682  );
683 
684  if (public_key)
685  key_length = GNUNET_IDENTITY_key_get_length(public_key);
686  else
687  key_length = -1;
688  }
689 
690  if (key_length < 0)
691  {
692  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: Invalid key!\n");
693  return;
694  }
695 
696  const uint16_t msg_length = get_message_size (message, GNUNET_NO);
697 
699  struct GNUNET_MQ_Envelope *env;
700 
701  const uint16_t length = (uint16_t) key_length + msg_length;
702 
703  env = GNUNET_MQ_msg_extra(
704  msg, length,
706  );
707 
708  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
709 
710  msg->flags = (uint32_t) (
712  );
713 
714  char *buffer = ((char*) msg) + sizeof(*msg);
715  char *msg_buffer = buffer + key_length;
716 
717  if (key_length > 0)
718  GNUNET_IDENTITY_write_key_to_buffer(get_contact_key(contact), buffer, key_length);
719 
720  encode_message (message, msg_length, msg_buffer, GNUNET_NO);
721 
722  GNUNET_MQ_send (room->handle->mq, env);
723 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_HashCode key
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.
ssize_t GNUNET_IDENTITY_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:976
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, int include_signature)
Encodes a given message into a buffer of a maximal length in bytes.
ssize_t GNUNET_IDENTITY_write_key_to_buffer(const struct GNUNET_IDENTITY_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_IDENTITY_PublicKey to a compact buffer.
static const struct GNUNET_IDENTITY_PublicKey * get_non_anonymous_key(const struct GNUNET_IDENTITY_PublicKey *public_key)
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
int filter_message_sending(const struct GNUNET_MESSENGER_Message *message)
Returns if a specific kind of message should be sent by a client.
static const int key_length
Fixed size of the public/private keys.
Definition: gnunet-abd.c:211
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE
An identity key as per LSD0001.
#define GNUNET_log(kind,...)
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
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, int include_signature)
Returns the exact size in bytes to encode a given message.
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
[in]roomRoom handle
[in]hashHash identifying a message
Returns
Message struct or NULL if no message with that hash is known

Definition at line 726 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_GetMessage::hash, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_GetMessage::key, GNUNET_MESSENGER_Handle::mq, and msg.

727 {
728  if ((!room) || (!hash))
729  return NULL;
730 
731  const struct GNUNET_MESSENGER_Message *message = get_room_message (room, hash);
732 
733  if (!message)
734  {
736  struct GNUNET_MQ_Envelope *env;
737 
739  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
740  GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash));
741  GNUNET_MQ_send (room->handle->mq, env);
742  }
743 
744  return message;
745 }
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
const struct GNUNET_MESSENGER_Message * get_room_message(const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
Returns a message locally stored from a map for a given hash in a room.
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE
Message to request something from a room.
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_iterate_members()

int GNUNET_MESSENGER_iterate_members ( struct GNUNET_MESSENGER_Room room,
GNUNET_MESSENGER_MemberCallback  callback,
void *  cls 
)

Iterates through all members of a given room and calls a selected callback for each of them with a provided closure.

The callback will receive the contact of each member. The function returns the amount of members iterated with the given callback.

Parameters
[in]roomRoom handle
[in]callbackFunction called for each member
[in]clsClosure for the callback handler
Returns
Amount of members iterated

Definition at line 748 of file messenger_api.c.

References GNUNET_SYSERR, and iterate_room_members().

Referenced by end_cb(), and read_stdio().

750 {
751  if (!room)
752  return GNUNET_SYSERR;
753 
754  return iterate_room_members(room, callback, cls);
755 }
int iterate_room_members(struct GNUNET_MESSENGER_Room *room, GNUNET_MESSENGER_MemberCallback callback, void *cls)
Iterates through all members of a given room to forward each of them to a selected callback with a cu...
Here is the call graph for this function:
Here is the caller graph for this function: