GNUnet  0.20.0
MESSENGER service

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

Data Structures

struct  GNUNET_MESSENGER_RoomEntryRecord
 A room entry record specifies which peer is hosting a given room and may also specify the key to enter it. More...
 
struct  GNUNET_MESSENGER_RoomDetailsRecord
 A room details record specifies a custom name for a given room and some additional space for flags. More...
 
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   0x00000002
 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   0x00000002

Version number of GNUnet Messenger API.

Current version of the Messenger: 0.2

Definition at line 55 of file gnunet_messenger_service.h.

◆ GNUNET_MESSENGER_SERVICE_NAME

#define GNUNET_MESSENGER_SERVICE_NAME   "messenger"

Identifier of GNUnet MESSENGER Service.

Definition at line 60 of file gnunet_messenger_service.h.

◆ GNUNET_MESSENGER_KIND_MAX

#define GNUNET_MESSENGER_KIND_MAX   (GNUNET_MESSENGER_KIND_DELETE)

Definition at line 205 of file gnunet_messenger_service.h.

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
[in/out]cls Closure from GNUNET_MESSENGER_connect
[in/out]handle Messenger handle

Definition at line 566 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 flags will indicate with a bitmask if a message was received privately or if the message was sent by the client.

Parameters
[in/out]cls Closure from GNUNET_MESSENGER_connect
[in]roomRoom handle
[in]senderSender of message
[in]messageNewly received or sent message
[in]hashHash identifying the message
[in]flagsFlags of the message

Definition at line 583 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
[in/out]cls Closure from GNUNET_MESSENGER_iterate_members
[in]roomRoom handle
[in]contactContact handle

Definition at line 599 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 122 of file gnunet_messenger_service.h.

123 {
128 
133 
138 
143 
148 
153 
158 
163 
168 
173 
178 
183 
188 
193 
198 
203 };
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_INVITE
The invite kind.
@ GNUNET_MESSENGER_KIND_PRIVATE
The private kind.
@ GNUNET_MESSENGER_KIND_FILE
The file kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_TEXT
The text kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_DELETE
The delete kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.

◆ 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 541 of file gnunet_messenger_service.h.

542 {
547 
552 
557 };
@ GNUNET_MESSENGER_FLAG_PRIVATE
The private flag.
@ GNUNET_MESSENGER_FLAG_SENT
The sent flag.
@ GNUNET_MESSENGER_FLAG_NONE
The none flag.

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 36 of file messenger_api.c.

37 {
38  switch (kind)
39  {
41  return "INFO";
43  return "JOIN";
45  return "LEAVE";
47  return "NAME";
49  return "KEY";
51  return "PEER";
53  return "ID";
55  return "MISS";
57  return "MERGE";
59  return "REQUEST";
61  return "INVITE";
63  return "TEXT";
65  return "FILE";
67  return "PRIVATE";
69  return "DELETE";
70  default:
71  return "UNKNOWN";
72  }
73 }

References GNUNET_MESSENGER_KIND_DELETE, 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().

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
[in,out]identity_clsClosure for the identity_callback handler
[in]msg_callbackFunction called when a new message is sent or received
[in,out]msg_clsClosure for the msg_callback handler
Returns
Messenger handle to use, NULL on error

Definition at line 437 of file messenger_api.c.

443 {
445 
446  reconnect (handle);
447 
448  if (handle->mq)
449  {
450  const uint16_t name_len = name ? strlen (name) : 0;
451 
453  struct GNUNET_MQ_Envelope *env;
454 
456 
457  char *extra = ((char*) msg) + sizeof(*msg);
458 
459  if (name_len)
460  GNUNET_memcpy(extra, name, name_len);
461 
462  extra[name_len] = '\0';
463 
465  return handle;
466  }
467  else
468  {
470  return NULL;
471  }
472 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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:304
#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:63
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE
static void reconnect(struct GNUNET_MESSENGER_Handle *handle)
struct GNUNET_MESSENGER_Handle * create_handle(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_IdentityCallback identity_callback, void *identity_cls, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls)
Creates and allocates a new handle using a given configuration and a custom message callback with a g...
void destroy_handle(struct GNUNET_MESSENGER_Handle *handle)
Destroys a handle and frees its memory fully from the client API.
const char * name
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:61
Message to create a handle for a client.
GNUNET_MESSENGER_MessageCallback msg_callback
GNUNET_MESSENGER_IdentityCallback identity_callback

References cfg, create_handle(), destroy_handle(), env, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), handle, GNUNET_MESSENGER_Handle::identity_callback, GNUNET_MESSENGER_Handle::identity_cls, GNUNET_DNS_Handle::mq, msg, GNUNET_MESSENGER_Handle::msg_callback, GNUNET_MESSENGER_Handle::msg_cls, name, and reconnect().

Referenced by on_peer(), and run().

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
[in,out]handleMessenger handle to use
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 475 of file messenger_api.c.

476 {
477  if ((!handle) || (!get_handle_name (handle)))
478  return GNUNET_SYSERR;
479 
481  struct GNUNET_MQ_Envelope *env;
482 
485  return GNUNET_OK;
486 }
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE
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.
Message to update the handle (its EGO key) for a client.

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

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
[in,out]handleMessenger handle to use

Definition at line 489 of file messenger_api.c.

490 {
491  if (!handle)
492  return;
493 
495  struct GNUNET_MQ_Envelope *env;
496 
499 
501 }
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY
Message to destroy the handle for a client.

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

Referenced by shutdown_cb(), and shutdown_hook().

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 504 of file messenger_api.c.

505 {
506  if (!handle)
507  return NULL;
508 
509  return get_handle_name (handle);
510 }

References get_handle_name(), and handle.

Referenced by on_identity().

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
[in,out]handleMessenger handle to use
[in]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 513 of file messenger_api.c.

515 {
516  if (!handle)
517  return GNUNET_SYSERR;
518 
519  const uint16_t name_len = name ? strlen (name) : 0;
520 
522  struct GNUNET_MQ_Envelope *env;
523 
525 
526  char *extra = ((char*) msg) + sizeof(*msg);
527 
528  if (name_len)
529  GNUNET_memcpy(extra, name, name_len);
530 
531  extra[name_len] = '\0';
532 
534  return GNUNET_YES;
535 }
@ GNUNET_YES
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME
Message to receive the current name of a handle.

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

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 547 of file messenger_api.c.

548 {
549  if (!handle)
550  return NULL;
551 
553 }
static const struct GNUNET_IDENTITY_PublicKey * get_non_anonymous_key(const struct GNUNET_IDENTITY_PublicKey *public_key)
const struct GNUNET_IDENTITY_PublicKey * get_handle_key(const struct GNUNET_MESSENGER_Handle *handle)
Returns the public key of a given handle.

References get_handle_key(), get_non_anonymous_key(), and 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_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
[in,out]handleMessenger handle to use
[in]keyHash identifying the port
Returns
Room handle, NULL on error

Definition at line 556 of file messenger_api.c.

558 {
559  if ((!handle) || (!key))
560  return NULL;
561 
563 
564  if (!room)
565  {
566  room = create_room (handle, key);
567 
570  {
571  destroy_room (room);
572  return NULL;
573  }
574  }
575 
576  send_open_room (handle, room);
577  return room;
578 }
struct GNUNET_HashCode key
The key used in the DHT.
enum GNUNET_GenericReturnValue 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.
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.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
static void send_open_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
struct GNUNET_MESSENGER_Room * create_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Creates and allocates a new room for a handle with a given key for the client API.
void destroy_room(struct GNUNET_MESSENGER_Room *room)
Destroys a room and frees its memory fully from the client API.

References create_room(), destroy_room(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_OK, handle, key, and send_open_room().

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

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
[in,out]handleMessenger handle to use
[in]doorPeer identity of an open door
[in]keyHash identifying the port
Returns
Room handle, NULL on error

Definition at line 581 of file messenger_api.c.

584 {
585  if ((!handle) || (!door) || (!key))
586  return NULL;
587 
589 
590  if (!room)
591  {
592  room = create_room (handle, key);
593 
596  {
597  destroy_room (room);
598  return NULL;
599  }
600  }
601 
602  send_enter_room (handle, room, door);
603  return room;
604 }
static void send_enter_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_PeerIdentity *door)

References create_room(), destroy_room(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST, GNUNET_OK, handle, key, and send_enter_room().

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

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
[in,out]roomRoom handle

Definition at line 607 of file messenger_api.c.

608 {
609  if (!room)
610  return;
611 
612  send_close_room (room->handle, room);
613 }
static void send_close_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
struct GNUNET_MESSENGER_Handle * handle

References GNUNET_MESSENGER_Room::handle, and send_close_room().

Referenced by shutdown_cb(), and shutdown_hook().

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 645 of file messenger_api.c.

649 {
650  if (!handle)
651  return GNUNET_SYSERR;
652 
653  struct GNUNET_MESSENGER_RoomFind find;
654 
655  find.contact = contact;
656  find.callback = callback;
657  find.counter = (contact? contact->rc : SIZE_MAX);
658  find.cls = cls;
659 
661 }
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
static int iterate_find_room(void *cls, const struct GNUNET_HashCode *key, void *value)
#define SIZE_MAX
Definition: platform.h:208
GNUNET_MESSENGER_MemberCallback callback
const struct GNUNET_MESSENGER_Contact * contact

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

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 664 of file messenger_api.c.

665 {
666  if (!room)
667  return NULL;
668 
669  return &(room->key);
670 }
struct GNUNET_HashCode key

References GNUNET_MESSENGER_Room::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 673 of file messenger_api.c.

675 {
676  if ((!room) || (!hash))
677  return NULL;
678 
679  return get_room_sender(room, hash);
680 }
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.

References get_room_sender().

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 683 of file messenger_api.c.

684 {
685  if (!contact)
686  return NULL;
687 
688  return get_contact_name (contact);
689 }
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.

References get_contact_name().

Referenced by on_message().

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 692 of file messenger_api.c.

693 {
694  if (!contact)
695  return NULL;
696 
697  return get_non_anonymous_key (get_contact_key (contact));
698 }
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.

References get_contact_key(), and get_non_anonymous_key().

Referenced by iterate_send_private_message().

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
[in,out]roomRoom handle
[in]messageNew message to send
[in]contactContact or NULL

Definition at line 701 of file messenger_api.c.

704 {
705  if ((!room) || (!message))
706  return;
707 
708  switch (filter_message_sending (message))
709  {
710  case GNUNET_SYSERR:
711  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sending message aborted: This kind of message is reserved for the service!\n");
712  return;
713  case GNUNET_NO:
714  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: This kind of message could cause issues!\n");
715  return;
716  default:
717  break;
718  }
719 
720  ssize_t key_length = 0;
721 
722  if (contact)
723  {
724  const struct GNUNET_IDENTITY_PublicKey *public_key = get_non_anonymous_key (
725  get_contact_key(contact)
726  );
727 
728  if (public_key)
729  key_length = GNUNET_IDENTITY_public_key_get_length(public_key);
730  else
731  key_length = -1;
732  }
733 
734  if (key_length < 0)
735  {
736  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: Invalid key!\n");
737  return;
738  }
739 
740  const uint16_t msg_length = get_message_size (message, GNUNET_NO);
741 
743  struct GNUNET_MQ_Envelope *env;
744 
745  const uint16_t length = (uint16_t) key_length + msg_length;
746 
748  msg, length,
750  );
751 
752  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
753 
754  msg->flags = (uint32_t) (
756  );
757 
758  char *buffer = ((char*) msg) + sizeof(*msg);
759  char *msg_buffer = buffer + key_length;
760 
761  if (key_length > 0)
762  GNUNET_IDENTITY_write_public_key_to_buffer(get_contact_key(contact), buffer, key_length);
763 
764  encode_message (message, msg_length, msg_buffer, GNUNET_NO);
765 
766  GNUNET_MQ_send (room->handle->mq, env);
767 }
ssize_t GNUNET_IDENTITY_write_public_key_to_buffer(const struct GNUNET_IDENTITY_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_IDENTITY_PublicKey to a compact buffer.
Definition: identity_api.c:890
ssize_t GNUNET_IDENTITY_public_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:830
#define GNUNET_log(kind,...)
@ GNUNET_NO
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE
int filter_message_sending(const struct GNUNET_MESSENGER_Message *message)
Returns if a specific kind of message should be sent by a client.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, int include_header)
Encodes a given message into a buffer of a maximal length in bytes.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, int include_header)
Returns the exact size in bytes to encode a given message.
An identity key as per LSD0001.
struct GNUNET_MQ_Handle * mq
Message to send something into a room.

References encode_message(), env, filter_message_sending(), get_contact_key(), get_message_size(), get_non_anonymous_key(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_WARNING, GNUNET_IDENTITY_public_key_get_length(), GNUNET_IDENTITY_write_public_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_Room::key, GNUNET_MESSENGER_Handle::mq, and msg.

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

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 770 of file messenger_api.c.

772 {
773  if ((!room) || (!hash))
774  return NULL;
775 
776  const struct GNUNET_MESSENGER_Message *message = get_room_message (room, hash);
777 
778  if (!message)
779  {
781  struct GNUNET_MQ_Envelope *env;
782 
784  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
785  GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash));
786  GNUNET_MQ_send (room->handle->mq, env);
787  }
788 
789  return message;
790 }
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE
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.
Message to request something from a room.

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_Room::key, GNUNET_MESSENGER_Handle::mq, and msg.

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 793 of file messenger_api.c.

796 {
797  if (!room)
798  return GNUNET_SYSERR;
799 
800  return iterate_room_members(room, callback, cls);
801 }
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...

References GNUNET_SYSERR, and iterate_room_members().

Referenced by end_cb(), and read_stdio().

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