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.

◆ 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 164 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 529 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 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
[in/out]cls Closure from GNUNET_MESSENGER_iterate_members
[in]roomRoom handle
[in]contactContact handle

Definition at line 562 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_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 504 of file gnunet_messenger_service.h.

505 {
510 
515 
520 };
@ 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";
67  default:
68  return "UNKNOWN";
69  }
70 }

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().

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

Definition at line 423 of file messenger_api.c.

429 {
431 
432  reconnect (handle);
433 
434  if (handle->mq)
435  {
436  const uint16_t name_len = name ? strlen (name) : 0;
437 
439  struct GNUNET_MQ_Envelope *env;
440 
442 
443  char *extra = ((char*) msg) + sizeof(*msg);
444 
445  if (name_len)
446  GNUNET_memcpy(extra, name, name_len);
447 
448  extra[name_len] = '\0';
449 
451  return handle;
452  }
453  else
454  {
456  return NULL;
457  }
458 }
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.
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).
void destroy_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Destroys a handle and frees its memory fully.
#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:355
#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_CREATE
static void reconnect(struct GNUNET_MESSENGER_Handle *handle)
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]handle Messenger handle to use
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 461 of file messenger_api.c.

462 {
463  if ((!handle) || (!get_handle_name (handle)))
464  return GNUNET_SYSERR;
465 
467  struct GNUNET_MQ_Envelope *env;
468 
471  return GNUNET_OK;
472 }
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#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]handle Messenger handle to use

Definition at line 475 of file messenger_api.c.

476 {
477  if (!handle)
478  return;
479 
481  struct GNUNET_MQ_Envelope *env;
482 
485 
487 }
#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 490 of file messenger_api.c.

491 {
492  if (!handle)
493  return NULL;
494 
495  return get_handle_name (handle);
496 }

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]handle Messenger 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 499 of file messenger_api.c.

501 {
502  if (!handle)
503  return GNUNET_SYSERR;
504 
505  const uint16_t name_len = name ? strlen (name) : 0;
506 
508  struct GNUNET_MQ_Envelope *env;
509 
511 
512  char *extra = ((char*) msg) + sizeof(*msg);
513 
514  if (name_len)
515  GNUNET_memcpy(extra, name, name_len);
516 
517  extra[name_len] = '\0';
518 
520  return GNUNET_YES;
521 }
@ GNUNET_YES
Definition: gnunet_common.h:97
#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 533 of file messenger_api.c.

534 {
535  if (!handle)
536  return NULL;
537 
539 }
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]handle Messenger handle to use
[in]keyHash identifying the port
Returns
Room handle, NULL on error

Definition at line 542 of file messenger_api.c.

544 {
545  if ((!handle) || (!key))
546  return NULL;
547 
549 
550  if (!room)
551  {
552  room = create_room (handle, key);
553 
556  {
557  destroy_room (room);
558  return NULL;
559  }
560  }
561 
562  send_open_room (handle, room);
563  return room;
564 }
struct GNUNET_HashCode key
The key used in the DHT.
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.
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
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.
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)

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

Definition at line 567 of file messenger_api.c.

570 {
571  if ((!handle) || (!door) || (!key))
572  return NULL;
573 
575 
576  if (!room)
577  {
578  room = create_room (handle, key);
579 
582  {
583  destroy_room (room);
584  return NULL;
585  }
586  }
587 
588  send_enter_room (handle, room, door);
589  return room;
590 }
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]room Room handle

Definition at line 593 of file messenger_api.c.

594 {
595  if (!room)
596  return;
597 
598  send_close_room (room->handle, room);
599 }
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 631 of file messenger_api.c.

635 {
636  if (!handle)
637  return GNUNET_SYSERR;
638 
639  struct GNUNET_MESSENGER_RoomFind find;
640 
641  find.contact = contact;
642  find.callback = callback;
643  find.counter = (contact? contact->rc : SIZE_MAX);
644  find.cls = cls;
645 
647 }
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 650 of file messenger_api.c.

651 {
652  if (!room)
653  return NULL;
654 
655  return &(room->key);
656 }
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 659 of file messenger_api.c.

661 {
662  if ((!room) || (!hash))
663  return NULL;
664 
665  return get_room_sender(room, hash);
666 }
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 669 of file messenger_api.c.

670 {
671  if (!contact)
672  return NULL;
673 
674  return get_contact_name (contact);
675 }
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 678 of file messenger_api.c.

679 {
680  if (!contact)
681  return NULL;
682 
683  return get_non_anonymous_key (get_contact_key (contact));
684 }
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]room Room handle
[in]messageNew message to send
[in]contactContact or NULL

Definition at line 687 of file messenger_api.c.

690 {
691  if ((!room) || (!message))
692  return;
693 
694  switch (filter_message_sending (message))
695  {
696  case GNUNET_SYSERR:
697  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sending message aborted: This kind of message is reserved for the service!\n");
698  return;
699  case GNUNET_NO:
700  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: This kind of message could cause issues!\n");
701  return;
702  default:
703  break;
704  }
705 
706  ssize_t key_length = 0;
707 
708  if (contact)
709  {
710  const struct GNUNET_IDENTITY_PublicKey *public_key = get_non_anonymous_key (
711  get_contact_key(contact)
712  );
713 
714  if (public_key)
716  else
717  key_length = -1;
718  }
719 
720  if (key_length < 0)
721  {
722  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: Invalid key!\n");
723  return;
724  }
725 
726  const uint16_t msg_length = get_message_size (message, GNUNET_NO);
727 
729  struct GNUNET_MQ_Envelope *env;
730 
731  const uint16_t length = (uint16_t) key_length + msg_length;
732 
734  msg, length,
736  );
737 
738  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
739 
740  msg->flags = (uint32_t) (
742  );
743 
744  char *buffer = ((char*) msg) + sizeof(*msg);
745  char *msg_buffer = buffer + key_length;
746 
747  if (key_length > 0)
749 
750  encode_message (message, msg_length, msg_buffer, GNUNET_NO);
751 
752  GNUNET_MQ_send (room->handle->mq, env);
753 }
static const int key_length
Fixed size of the public/private keys.
Definition: gnunet-abd.c:211
#define GNUNET_log(kind,...)
@ GNUNET_NO
Definition: gnunet_common.h:94
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.
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
@ 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.
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.
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.
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_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_Room::key, key_length, 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 756 of file messenger_api.c.

758 {
759  if ((!room) || (!hash))
760  return NULL;
761 
762  const struct GNUNET_MESSENGER_Message *message = get_room_message (room, hash);
763 
764  if (!message)
765  {
767  struct GNUNET_MQ_Envelope *env;
768 
770  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
771  GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash));
772  GNUNET_MQ_send (room->handle->mq, env);
773  }
774 
775  return message;
776 }
#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 779 of file messenger_api.c.

782 {
783  if (!room)
784  return GNUNET_SYSERR;
785 
786  return iterate_room_members(room, callback, cls);
787 }
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: