GNUnet  0.11.x
Functions
messenger_api.c File Reference

messenger api: client implementation of GNUnet MESSENGER service More...

#include "gnunet_messenger_service.h"
#include "gnunet-service-messenger.h"
#include "messenger_api_handle.h"
#include "messenger_api_message.h"
#include "messenger_api_util.h"
Include dependency graph for messenger_api.c:

Go to the source code of this file.

Functions

const char * GNUNET_MESSENGER_name_of_kind (enum GNUNET_MESSENGER_MessageKind kind)
 Get the name of a message kind. More...
 
static int check_get_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg)
 
static void handle_get_name (void *cls, const struct GNUNET_MESSENGER_NameMessage *msg)
 
static int check_get_key (void *cls, const struct GNUNET_MESSENGER_KeyMessage *msg)
 
static void handle_get_key (void *cls, const struct GNUNET_MESSENGER_KeyMessage *msg)
 
static void handle_member_id (void *cls, const struct GNUNET_MESSENGER_MemberMessage *msg)
 
static void handle_room_open (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
 
static void handle_room_entry (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
 
static void handle_room_close (void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
 
static int check_recv_message (void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg)
 
static void handle_recv_message (void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg)
 
static void reconnect (struct GNUNET_MESSENGER_Handle *handle)
 
static void send_open_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
 
static void send_enter_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_PeerIdentity *door)
 
static void send_close_room (struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
 
static int iterate_reset_room (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static void callback_reconnect (void *cls)
 
static int iterate_close_room (void *cls, const struct GNUNET_HashCode *key, void *value)
 
static void callback_mq_error (void *cls, enum GNUNET_MQ_Error error)
 
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...
 
static const struct GNUNET_IDENTITY_PublicKeyget_non_anonymous_key (const struct GNUNET_IDENTITY_PublicKey *public_key)
 
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...
 
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

messenger api: client implementation of GNUnet MESSENGER service

Author
Tobias Frisch

Definition in file messenger_api.c.

Function Documentation

◆ check_get_name()

static int check_get_name ( void *  cls,
const struct GNUNET_MESSENGER_NameMessage msg 
)
static

Definition at line 73 of file messenger_api.c.

References GNUNET_MQ_check_zero_termination, and GNUNET_OK.

74 {
76  return GNUNET_OK;
77 }
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...

◆ handle_get_name()

static void handle_get_name ( void *  cls,
const struct GNUNET_MESSENGER_NameMessage msg 
)
static

Definition at line 80 of file messenger_api.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, handle, name, and set_handle_name().

81 {
82  struct GNUNET_MESSENGER_Handle *handle = cls;
83 
84  const char *name = ((const char*) msg) + sizeof(*msg);
85 
86  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set name of handle: %s\n", name);
87 
88  set_handle_name (handle, strlen (name) > 0 ? name : NULL);
89 }
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
const char * name
void set_handle_name(struct GNUNET_MESSENGER_SrvHandle *handle, const char *name)
Tries to rename the handle which implies renaming the EGO its using and moving all related data into ...
#define GNUNET_log(kind,...)
Here is the call graph for this function:

◆ check_get_key()

static int check_get_key ( void *  cls,
const struct GNUNET_MESSENGER_KeyMessage msg 
)
static

Definition at line 92 of file messenger_api.c.

References GNUNET_IDENTITY_read_key_from_buffer(), GNUNET_NO, GNUNET_OK, GNUNET_MESSENGER_KeyMessage::header, and GNUNET_MessageHeader::size.

93 {
94  const uint16_t full_length = ntohs (msg->header.size);
95 
96  if (full_length < sizeof(*msg))
97  return GNUNET_NO;
98 
99  const uint16_t length = full_length - sizeof(*msg);
100  const char *buffer = ((const char*) msg) + sizeof(*msg);
101 
103  if (GNUNET_IDENTITY_read_key_from_buffer(&pubkey, buffer, length) < 0)
104  return GNUNET_NO;
105 
106  return GNUNET_OK;
107 }
ssize_t GNUNET_IDENTITY_read_key_from_buffer(struct GNUNET_IDENTITY_PublicKey *key, const void *buffer, size_t len)
Reads a GNUNET_IDENTITY_PublicKey from a compact buffer.
Definition: identity_api.c:994
struct GNUNET_MessageHeader header
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
An identity key as per LSD0001.
Here is the call graph for this function:

◆ handle_get_key()

static void handle_get_key ( void *  cls,
const struct GNUNET_MESSENGER_KeyMessage msg 
)
static

Definition at line 110 of file messenger_api.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_IDENTITY_public_key_to_string(), GNUNET_IDENTITY_read_key_from_buffer(), GNUNET_log, handle, GNUNET_MESSENGER_KeyMessage::header, GNUNET_MESSENGER_Handle::identity_callback, GNUNET_MESSENGER_Handle::identity_cls, set_handle_key(), and GNUNET_MessageHeader::size.

111 {
112  struct GNUNET_MESSENGER_Handle *handle = cls;
113 
114  const uint16_t length = ntohs (msg->header.size) - sizeof(*msg);
115  const char *buffer = ((const char*) msg) + sizeof(*msg);
116 
118  if (GNUNET_IDENTITY_read_key_from_buffer(&pubkey, buffer, length) < 0)
119  return;
120 
122  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set key of handle: %s\n", str);
123  GNUNET_free(str);
124 
125  set_handle_key (handle, &pubkey);
126 
127  if (handle->identity_callback)
128  handle->identity_callback (handle->identity_cls, handle);
129 }
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
ssize_t GNUNET_IDENTITY_read_key_from_buffer(struct GNUNET_IDENTITY_PublicKey *key, const void *buffer, size_t len)
Reads a GNUNET_IDENTITY_PublicKey from a compact buffer.
Definition: identity_api.c:994
struct GNUNET_MessageHeader header
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
An identity key as per LSD0001.
#define GNUNET_log(kind,...)
void set_handle_key(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_IDENTITY_PublicKey *pubkey)
Sets the public key of a given handle to a specific public key.
GNUNET_MESSENGER_IdentityCallback identity_callback
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

◆ handle_member_id()

static void handle_member_id ( void *  cls,
const struct GNUNET_MESSENGER_MemberMessage msg 
)
static

Definition at line 132 of file messenger_api.c.

References GNUNET_MESSENGER_Room::contact_id, GNUNET_CONTAINER_multihashmap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, GNUNET_memcpy, GNUNET_new, handle, GNUNET_MESSENGER_MemberMessage::id, key, GNUNET_MESSENGER_MemberMessage::key, and GNUNET_MESSENGER_Handle::rooms.

133 {
134  struct GNUNET_MESSENGER_Handle *handle = cls;
135 
136  const struct GNUNET_HashCode *key = &(msg->key);
137  const struct GNUNET_ShortHashCode *id = &(msg->id);
138 
139  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set id of handle in room: %s\n", GNUNET_h2s (key));
140 
141  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
142 
143  if (room)
144  {
145  if (!room->contact_id)
147 
148  GNUNET_memcpy(room->contact_id, id, sizeof(*id));
149  }
150 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
A 256-bit hashcode.
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.
struct GNUNET_ShortHashCode * contact_id
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_CONTAINER_MultiHashMap * rooms
A 512-bit hashcode.
struct GNUNET_HashCode key
The key used in the DHT.
struct GNUNET_ShortHashCode id
#define GNUNET_log(kind,...)
Here is the call graph for this function:

◆ handle_room_open()

static void handle_room_open ( void *  cls,
const struct GNUNET_MESSENGER_RoomMessage msg 
)
static

Definition at line 153 of file messenger_api.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, handle, key, GNUNET_MESSENGER_RoomMessage::key, and open_handle_room().

154 {
155  struct GNUNET_MESSENGER_Handle *handle = cls;
156 
157  const struct GNUNET_HashCode *key = &(msg->key);
158 
159  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key));
160 
161  open_handle_room (handle, key);
162 }
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
int open_handle_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Makes a given handle a member of the room using a specific key and opens the room from the handles se...
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
A 512-bit hashcode.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_log(kind,...)
Here is the call graph for this function:

◆ handle_room_entry()

static void handle_room_entry ( void *  cls,
const struct GNUNET_MESSENGER_RoomMessage msg 
)
static

Definition at line 165 of file messenger_api.c.

References GNUNET_MESSENGER_RoomMessage::door, entry_handle_room_at(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, handle, key, and GNUNET_MESSENGER_RoomMessage::key.

166 {
167  struct GNUNET_MESSENGER_Handle *handle = cls;
168 
169  const struct GNUNET_PeerIdentity *door = &(msg->door);
170  const struct GNUNET_HashCode *key = &(msg->key);
171 
172  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Entered room: %s\n", GNUNET_h2s (key));
173 
174  entry_handle_room_at (handle, door, key);
175 }
void entry_handle_room_at(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Adds a tunnel for a room known to a handle identified by a given key to a list of opened connections...
struct GNUNET_PeerIdentity door
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
A 512-bit hashcode.
struct GNUNET_HashCode key
The key used in the DHT.
The identity of the host (wraps the signing key of the peer).
#define GNUNET_log(kind,...)
Here is the call graph for this function:

◆ handle_room_close()

static void handle_room_close ( void *  cls,
const struct GNUNET_MESSENGER_RoomMessage msg 
)
static

Definition at line 178 of file messenger_api.c.

References close_handle_room(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_h2s(), GNUNET_log, handle, key, and GNUNET_MESSENGER_RoomMessage::key.

179 {
180  struct GNUNET_MESSENGER_Handle *handle = cls;
181 
182  const struct GNUNET_HashCode *key = &(msg->key);
183 
184  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Closed room: %s\n", GNUNET_h2s (key));
185 
186  close_handle_room (handle, key);
187 }
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
int close_handle_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Removes the membership of the room using a specific key and closes it if no other handle from this se...
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
A 512-bit hashcode.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_log(kind,...)
Here is the call graph for this function:

◆ check_recv_message()

static int check_recv_message ( void *  cls,
const struct GNUNET_MESSENGER_RecvMessage msg 
)
static

Definition at line 190 of file messenger_api.c.

References decode_message(), GNUNET_NO, GNUNET_OK, GNUNET_YES, GNUNET_MESSENGER_RecvMessage::header, GNUNET_MESSENGER_Message::header, and GNUNET_MessageHeader::size.

191 {
192  const uint16_t full_length = ntohs (msg->header.size);
193 
194  if (full_length < sizeof(*msg))
195  return GNUNET_NO;
196 
197  const uint16_t length = full_length - sizeof(*msg);
198  const char *buffer = ((const char*) msg) + sizeof(*msg);
199 
200  struct GNUNET_MESSENGER_Message message;
201 
202  if (length < sizeof(message.header))
203  return GNUNET_NO;
204 
205  if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL))
206  return GNUNET_NO;
207 
208  return GNUNET_OK;
209 }
int decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, int include_signature, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_MessageHeader header
Here is the call graph for this function:

◆ handle_recv_message()

static void handle_recv_message ( void *  cls,
const struct GNUNET_MESSENGER_RecvMessage msg 
)
static

Definition at line 212 of file messenger_api.c.

References context, GNUNET_MESSENGER_RecvMessage::context, decode_message(), GNUNET_MESSENGER_RecvMessage::flags, get_handle_contact_store(), get_store_contact_raw(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_h2s_full(), GNUNET_log, GNUNET_MESSENGER_name_of_kind(), GNUNET_YES, handle, handle_room_message(), GNUNET_MESSENGER_RecvMessage::hash, GNUNET_MESSENGER_RecvMessage::header, GNUNET_MESSENGER_Message::header, key, GNUNET_MESSENGER_RecvMessage::key, GNUNET_MESSENGER_MessageHeader::kind, GNUNET_MESSENGER_Handle::msg_callback, GNUNET_MESSENGER_Handle::msg_cls, reconnect(), GNUNET_MESSENGER_Handle::rooms, GNUNET_MESSENGER_RecvMessage::sender, and GNUNET_MessageHeader::size.

213 {
214  struct GNUNET_MESSENGER_Handle *handle = cls;
215 
216  const struct GNUNET_HashCode *key = &(msg->key);
217  const struct GNUNET_HashCode *sender = &(msg->sender);
218  const struct GNUNET_HashCode *context = &(msg->context);
219  const struct GNUNET_HashCode *hash = &(msg->hash);
220  const enum GNUNET_MESSENGER_MessageFlags flags = (
222  );
223 
224  const uint16_t length = ntohs (msg->header.size) - sizeof(*msg);
225  const char *buffer = ((const char*) msg) + sizeof(*msg);
226 
227  struct GNUNET_MESSENGER_Message message;
228  decode_message (&message, length, buffer, GNUNET_YES, NULL);
229 
230  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n", GNUNET_MESSENGER_name_of_kind (message.header.kind));
231 
232  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
233 
234  if (room)
235  {
237 
238  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Raw contact from sender and context: (%s : %s)\n",
239  GNUNET_h2s(sender), GNUNET_h2s_full(context));
240 
242  store, context, sender
243  );
244 
245  handle_room_message (room, contact, &message, hash);
246 
247  if (handle->msg_callback)
248  handle->msg_callback (handle->msg_cls, room, contact, &message, hash, flags);
249  }
250  else
251  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Room not found\n");
252 }
int decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, int include_signature, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static pa_context * context
Pulseaudio context.
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_MESSENGER_MessageFlags
Enum for the different supported flags used by message handling.
GNUNET_MESSENGER_MessageCallback msg_callback
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
Definition: messenger_api.c:35
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_CONTAINER_MultiHashMap * rooms
A 512-bit hashcode.
void handle_room_message(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Handles a message with a given hash in a room for the client API to update members and its informatio...
struct GNUNET_HashCode key
The key used in the DHT.
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store(struct GNUNET_MESSENGER_Handle *handle)
Returns the used contact store of a given handle.
struct GNUNET_MESSENGER_Contact * get_store_contact_raw(struct GNUNET_MESSENGER_ContactStore *store, const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *key_hash)
Returns a contact using the hash of a specific public key.
#define GNUNET_log(kind,...)
struct GNUNET_MessageHeader header
Here is the call graph for this function:

◆ reconnect()

static void reconnect ( struct GNUNET_MESSENGER_Handle handle)
static

Definition at line 361 of file messenger_api.c.

References callback_mq_error(), GNUNET_MESSENGER_Handle::cfg, GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME, GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE, GNUNET_MESSENGER_SERVICE_NAME, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MESSENGER_Handle::mq, and recv_message().

Referenced by callback_reconnect(), GNUNET_MESSENGER_connect(), and handle_recv_message().

362 {
363  const struct GNUNET_MQ_MessageHandler handlers[] =
364  {
367  struct GNUNET_MESSENGER_NameMessage, handle
368  ),
371  struct GNUNET_MESSENGER_KeyMessage, handle
372  ),
374  member_id,
376  struct GNUNET_MESSENGER_MemberMessage, handle
377  ),
379  room_open,
381  struct GNUNET_MESSENGER_RoomMessage, handle
382  ),
384  room_entry,
386  struct GNUNET_MESSENGER_RoomMessage, handle
387  ),
389  room_close,
391  struct GNUNET_MESSENGER_RoomMessage, handle
392  ),
394  recv_message,
396  struct GNUNET_MESSENGER_RecvMessage, handle
397  ),
399  };
400 
401  handle->mq = GNUNET_CLIENT_connect (handle->cfg, GNUNET_MESSENGER_SERVICE_NAME, handlers, &callback_mq_error, handle);
402 }
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY
Message to receive the current member id of a handle in room.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1063
static void callback_mq_error(void *cls, enum GNUNET_MQ_Error error)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
struct GNUNET_MQ_Handle * mq
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
static int recv_message(void *cls, const struct GNUNET_MessageHeader *msg)
We have received a full message, pass to the MQ dispatcher.
Definition: client.c:332
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME
Message handler for a specific message type.
const struct GNUNET_CONFIGURATION_Handle * cfg
#define GNUNET_MESSENGER_SERVICE_NAME
Identifier of GNUnet MESSENGER Service.
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN
Message to receive the current name of a handle.
Message to receive the current public key of a handle.
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE
Message to receive something from a room.
General message to confirm interaction with a room.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_open_room()

static void send_open_room ( struct GNUNET_MESSENGER_Handle handle,
struct GNUNET_MESSENGER_Room room 
)
static

Definition at line 258 of file messenger_api.c.

References env, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_MESSENGER_RoomMessage::key, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_Handle::mq, and msg.

Referenced by GNUNET_MESSENGER_open_room(), and iterate_reset_room().

259 {
261  struct GNUNET_MQ_Envelope *env;
262 
264  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
265  GNUNET_MQ_send (handle->mq, env);
266 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_HashCode key
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_MQ_Handle * mq
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN
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
General message to confirm interaction with a room.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_enter_room()

static void send_enter_room ( struct GNUNET_MESSENGER_Handle handle,
struct GNUNET_MESSENGER_Room room,
const struct GNUNET_PeerIdentity door 
)
static

Definition at line 269 of file messenger_api.c.

References GNUNET_MESSENGER_RoomMessage::door, env, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_MESSENGER_RoomMessage::key, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_Handle::mq, and msg.

Referenced by GNUNET_MESSENGER_enter_room(), and iterate_reset_room().

271 {
273  struct GNUNET_MQ_Envelope *env;
274 
276  GNUNET_memcpy(&(msg->door), door, sizeof(*door));
277  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
278  GNUNET_MQ_send (handle->mq, env);
279 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_HashCode key
struct GNUNET_PeerIdentity door
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_MQ_Handle * mq
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY
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
General message to confirm interaction with a room.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_close_room()

static void send_close_room ( struct GNUNET_MESSENGER_Handle handle,
struct GNUNET_MESSENGER_Room room 
)
static

Definition at line 282 of file messenger_api.c.

References env, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_MESSENGER_RoomMessage::key, GNUNET_MESSENGER_Room::key, GNUNET_MESSENGER_Handle::mq, and msg.

Referenced by GNUNET_MESSENGER_close_room(), and iterate_close_room().

283 {
285  struct GNUNET_MQ_Envelope *env;
286 
288  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
289  GNUNET_MQ_send (handle->mq, env);
290 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_HashCode key
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_MQ_Handle * mq
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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
General message to confirm interaction with a room.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_reset_room()

static int iterate_reset_room ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 293 of file messenger_api.c.

References GNUNET_MESSENGER_Room::entries, GNUNET_PEER_resolve(), GNUNET_YES, GNUNET_MESSENGER_ListTunnels::head, GNUNET_MESSENGER_ListTunnel::next, GNUNET_MESSENGER_Room::opened, GNUNET_MESSENGER_ListTunnel::peer, send_enter_room(), send_open_room(), and value.

Referenced by callback_reconnect().

294 {
295  struct GNUNET_MESSENGER_Handle *handle = cls;
296  struct GNUNET_MESSENGER_Room *room = value;
297 
298  if (GNUNET_YES == room->opened)
299  send_open_room (handle, room);
300 
301  struct GNUNET_MESSENGER_ListTunnel *entry = room->entries.head;
302 
303  struct GNUNET_PeerIdentity door;
304 
305  while (entry)
306  {
307  GNUNET_PEER_resolve (entry->peer, &door);
308 
309  send_enter_room (handle, room, &door);
310 
311  entry = entry->next;
312  }
313 
314  return GNUNET_YES;
315 }
struct GNUNET_MESSENGER_ListTunnel * head
struct GNUNET_MESSENGER_ListTunnel * next
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:225
struct GNUNET_MESSENGER_ListTunnels entries
static char * value
Value of the record to add/remove.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void send_open_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
The identity of the host (wraps the signing key of the peer).
static void send_enter_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_PeerIdentity *door)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_reconnect()

static void callback_reconnect ( void *  cls)
static

Definition at line 318 of file messenger_api.c.

References GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_TIME_STD_BACKOFF, iterate_reset_room(), reconnect(), GNUNET_MESSENGER_Handle::reconnect_task, GNUNET_MESSENGER_Handle::reconnect_time, and GNUNET_MESSENGER_Handle::rooms.

Referenced by callback_mq_error().

319 {
320  struct GNUNET_MESSENGER_Handle *handle = cls;
321 
322  handle->reconnect_task = NULL;
324  ;
325 
326  reconnect (handle);
327 
329 }
static int iterate_reset_room(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_SCHEDULER_Task * reconnect_task
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_CONTAINER_MultiHashMap * rooms
struct GNUNET_TIME_Relative reconnect_time
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static void reconnect(struct GNUNET_MESSENGER_Handle *handle)
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ iterate_close_room()

static int iterate_close_room ( void *  cls,
const struct GNUNET_HashCode key,
void *  value 
)
static

Definition at line 332 of file messenger_api.c.

References GNUNET_YES, send_close_room(), and value.

Referenced by callback_mq_error().

333 {
334  struct GNUNET_MESSENGER_Handle *handle = cls;
335  struct GNUNET_MESSENGER_Room *room = value;
336 
337  send_close_room (handle, room);
338 
339  return GNUNET_YES;
340 }
static char * value
Value of the record to add/remove.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static void send_close_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ callback_mq_error()

static void callback_mq_error ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Definition at line 343 of file messenger_api.c.

References callback_reconnect(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), iterate_close_room(), GNUNET_MESSENGER_Handle::mq, GNUNET_MESSENGER_Handle::reconnect_task, GNUNET_MESSENGER_Handle::reconnect_time, and GNUNET_MESSENGER_Handle::rooms.

Referenced by reconnect().

344 {
345  struct GNUNET_MESSENGER_Handle *handle = cls;
346 
347  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "MQ_Error: %u\n", error);
348 
350 
351  if (handle->mq)
352  {
353  GNUNET_MQ_destroy (handle->mq);
354  handle->mq = NULL;
355  }
356 
358 }
static void callback_reconnect(void *cls)
static int iterate_close_room(void *cls, const struct GNUNET_HashCode *key, void *value)
struct GNUNET_SCHEDULER_Task * reconnect_task
struct GNUNET_MQ_Handle * mq
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_CONTAINER_MultiHashMap * rooms
struct GNUNET_TIME_Relative reconnect_time
#define GNUNET_log(kind,...)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_non_anonymous_key()

static const struct GNUNET_IDENTITY_PublicKey* get_non_anonymous_key ( const struct GNUNET_IDENTITY_PublicKey public_key)
static

Definition at line 502 of file messenger_api.c.

References get_anonymous_public_key(), and GNUNET_memcmp.

Referenced by GNUNET_MESSENGER_contact_get_key(), GNUNET_MESSENGER_get_key(), and GNUNET_MESSENGER_send_message().

503 {
504  if (0 == GNUNET_memcmp(public_key, get_anonymous_public_key()))
505  return NULL;
506 
507  return public_key;
508 }
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
const struct GNUNET_IDENTITY_PublicKey * get_anonymous_public_key()
Returns the public identity key of GNUNET_IDENTITY_ego_get_anonymous() without recalculating it every...
Here is the call graph for this function:
Here is the caller graph for this function: