GNUnet  0.18.1
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   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.

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

◆ GNUNET_MESSENGER_KIND_MAX

#define GNUNET_MESSENGER_KIND_MAX   (GNUNET_MESSENGER_KIND_DELETE)

Definition at line 206 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 571 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 588 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 604 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 123 of file gnunet_messenger_service.h.

124 {
129 
134 
139 
144 
149 
154 
159 
164 
169 
174 
179 
184 
189 
194 
199 
204 };
@ 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 546 of file gnunet_messenger_service.h.

547 {
552 
557 
562 };
@ 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 35 of file messenger_api.c.

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";
68  return "DELETE";
69  default:
70  return "UNKNOWN";
71  }
72 }

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

442 {
444 
445  reconnect (handle);
446 
447  if (handle->mq)
448  {
449  const uint16_t name_len = name ? strlen (name) : 0;
450 
452  struct GNUNET_MQ_Envelope *env;
453 
455 
456  char *extra = ((char*) msg) + sizeof(*msg);
457 
458  if (name_len)
459  GNUNET_memcpy(extra, name, name_len);
460 
461  extra[name_len] = '\0';
462 
464  return handle;
465  }
466  else
467  {
469  return NULL;
470  }
471 }
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:303
#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:56
#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 474 of file messenger_api.c.

475 {
476  if ((!handle) || (!get_handle_name (handle)))
477  return GNUNET_SYSERR;
478 
480  struct GNUNET_MQ_Envelope *env;
481 
484  return GNUNET_OK;
485 }
@ GNUNET_OK
Definition: gnunet_common.h:99
@ GNUNET_SYSERR
Definition: gnunet_common.h:97
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:71
#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 488 of file messenger_api.c.

489 {
490  if (!handle)
491  return;
492 
494  struct GNUNET_MQ_Envelope *env;
495 
498 
500 }
#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 503 of file messenger_api.c.

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

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

514 {
515  if (!handle)
516  return GNUNET_SYSERR;
517 
518  const uint16_t name_len = name ? strlen (name) : 0;
519 
521  struct GNUNET_MQ_Envelope *env;
522 
524 
525  char *extra = ((char*) msg) + sizeof(*msg);
526 
527  if (name_len)
528  GNUNET_memcpy(extra, name, name_len);
529 
530  extra[name_len] = '\0';
531 
533  return GNUNET_YES;
534 }
@ 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 546 of file messenger_api.c.

547 {
548  if (!handle)
549  return NULL;
550 
552 }
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 555 of file messenger_api.c.

557 {
558  if ((!handle) || (!key))
559  return NULL;
560 
562 
563  if (!room)
564  {
565  room = create_room (handle, key);
566 
569  {
570  destroy_room (room);
571  return NULL;
572  }
573  }
574 
575  send_open_room (handle, room);
576  return room;
577 }
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 580 of file messenger_api.c.

583 {
584  if ((!handle) || (!door) || (!key))
585  return NULL;
586 
588 
589  if (!room)
590  {
591  room = create_room (handle, key);
592 
595  {
596  destroy_room (room);
597  return NULL;
598  }
599  }
600 
601  send_enter_room (handle, room, door);
602  return room;
603 }
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 606 of file messenger_api.c.

607 {
608  if (!room)
609  return;
610 
611  send_close_room (room->handle, room);
612 }
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 644 of file messenger_api.c.

648 {
649  if (!handle)
650  return GNUNET_SYSERR;
651 
652  struct GNUNET_MESSENGER_RoomFind find;
653 
654  find.contact = contact;
655  find.callback = callback;
656  find.counter = (contact? contact->rc : SIZE_MAX);
657  find.cls = cls;
658 
660 }
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback 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:207
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 663 of file messenger_api.c.

664 {
665  if (!room)
666  return NULL;
667 
668  return &(room->key);
669 }
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 672 of file messenger_api.c.

674 {
675  if ((!room) || (!hash))
676  return NULL;
677 
678  return get_room_sender(room, hash);
679 }
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 682 of file messenger_api.c.

683 {
684  if (!contact)
685  return NULL;
686 
687  return get_contact_name (contact);
688 }
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 691 of file messenger_api.c.

692 {
693  if (!contact)
694  return NULL;
695 
696  return get_non_anonymous_key (get_contact_key (contact));
697 }
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 700 of file messenger_api.c.

703 {
704  if ((!room) || (!message))
705  return;
706 
707  switch (filter_message_sending (message))
708  {
709  case GNUNET_SYSERR:
710  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sending message aborted: This kind of message is reserved for the service!\n");
711  return;
712  case GNUNET_NO:
713  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: This kind of message could cause issues!\n");
714  return;
715  default:
716  break;
717  }
718 
719  ssize_t key_length = 0;
720 
721  if (contact)
722  {
723  const struct GNUNET_IDENTITY_PublicKey *public_key = get_non_anonymous_key (
724  get_contact_key(contact)
725  );
726 
727  if (public_key)
728  key_length = GNUNET_IDENTITY_public_key_get_length(public_key);
729  else
730  key_length = -1;
731  }
732 
733  if (key_length < 0)
734  {
735  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: Invalid key!\n");
736  return;
737  }
738 
739  const uint16_t msg_length = get_message_size (message, GNUNET_NO);
740 
742  struct GNUNET_MQ_Envelope *env;
743 
744  const uint16_t length = (uint16_t) key_length + msg_length;
745 
747  msg, length,
749  );
750 
751  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
752 
753  msg->flags = (uint32_t) (
755  );
756 
757  char *buffer = ((char*) msg) + sizeof(*msg);
758  char *msg_buffer = buffer + key_length;
759 
760  if (key_length > 0)
761  GNUNET_IDENTITY_write_public_key_to_buffer(get_contact_key(contact), buffer, key_length);
762 
763  encode_message (message, msg_length, msg_buffer, GNUNET_NO);
764 
765  GNUNET_MQ_send (room->handle->mq, env);
766 }
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
Definition: gnunet_common.h:98
@ 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 769 of file messenger_api.c.

771 {
772  if ((!room) || (!hash))
773  return NULL;
774 
775  const struct GNUNET_MESSENGER_Message *message = get_room_message (room, hash);
776 
777  if (!message)
778  {
780  struct GNUNET_MQ_Envelope *env;
781 
783  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
784  GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash));
785  GNUNET_MQ_send (room->handle->mq, env);
786  }
787 
788  return message;
789 }
#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 792 of file messenger_api.c.

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