GNUnet  0.11.x
messenger_api.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2020 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
27 
29 
30 #include "messenger_api_handle.h"
31 #include "messenger_api_message.h"
32 
33 const char*
35 {
36  switch (kind)
37  {
39  return "INFO";
41  return "JOIN";
43  return "LEAVE";
45  return "NAME";
47  return "KEY";
49  return "PEER";
51  return "ID";
53  return "MISS";
55  return "MERGE";
57  return "REQUEST";
59  return "INVITE";
61  return "TEXT";
63  return "FILE";
64  default:
65  return "UNKNOWN";
66  }
67 }
68 
69 static int
71 {
73  return GNUNET_OK;
74 }
75 
76 static void
78 {
79  struct GNUNET_MESSENGER_Handle *handle = cls;
80 
81  const char *name = ((const char*) msg) + sizeof(*msg);
82 
83  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set name of handle: %s\n", name);
84 
85  set_handle_name (handle, strlen(name) > 0? name : NULL);
86 }
87 
88 static void
90 {
91  struct GNUNET_MESSENGER_Handle *handle = cls;
92 
93  const struct GNUNET_IDENTITY_PublicKey *pubkey = &(msg->pubkey);
94 
95  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set key of handle: %s\n", GNUNET_IDENTITY_public_key_to_string (pubkey));
96 
97  set_handle_key (handle, pubkey);
98 
99  if (handle->identity_callback)
100  handle->identity_callback (handle->identity_cls, handle);
101 }
102 
103 static void
105 {
106  struct GNUNET_MESSENGER_Handle *handle = cls;
107 
108  const struct GNUNET_HashCode *key = &(msg->key);
109  const struct GNUNET_ShortHashCode *id = &(msg->id);
110 
111  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set id of handle in room: %s\n", GNUNET_h2s (key));
112 
113  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
114 
115  if (room)
116  {
117  if (!room->contact_id)
119 
120  GNUNET_memcpy(room->contact_id, id, sizeof(*id));
121  }
122 }
123 
124 static void
126 {
127  struct GNUNET_MESSENGER_Handle *handle = cls;
128 
129  const struct GNUNET_HashCode *key = &(msg->key);
130 
131  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key));
132 
133  open_handle_room (handle, key);
134 }
135 
136 static void
138 {
139  struct GNUNET_MESSENGER_Handle *handle = cls;
140 
141  const struct GNUNET_PeerIdentity *door = &(msg->door);
142  const struct GNUNET_HashCode *key = &(msg->key);
143 
144  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Entered room: %s\n", GNUNET_h2s (key));
145 
146  entry_handle_room_at (handle, door, key);
147 }
148 
149 static void
151 {
152  struct GNUNET_MESSENGER_Handle *handle = cls;
153 
154  const struct GNUNET_HashCode *key = &(msg->key);
155 
156  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Closed room: %s\n", GNUNET_h2s (key));
157 
158  close_handle_room (handle, key);
159 }
160 
161 static int
163 {
164  const uint16_t full_length = ntohs (msg->header.size) - sizeof(msg->header);
165 
166  if (full_length < sizeof(msg->hash))
167  return GNUNET_NO;
168 
169  const uint16_t length = full_length - sizeof(msg->hash);
170  const char *buffer = ((const char*) msg) + sizeof(*msg);
171 
172  struct GNUNET_MESSENGER_Message message;
173 
174  if (length < sizeof(message.header))
175  return GNUNET_NO;
176 
177  if (GNUNET_YES != decode_message (&message, length, buffer))
178  return GNUNET_NO;
179 
180  return GNUNET_OK;
181 }
182 
183 static void
185 {
186  struct GNUNET_MESSENGER_Handle *handle = cls;
187 
188  const struct GNUNET_HashCode *key = &(msg->key);
189  const struct GNUNET_HashCode *hash = &(msg->hash);
190 
191  const char *buffer = ((const char*) msg) + sizeof(*msg);
192 
193  const uint16_t length = ntohs (msg->header.size) - sizeof(*msg);
194 
195  struct GNUNET_MESSENGER_Message message;
196  decode_message (&message, length, buffer);
197 
198  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n", GNUNET_MESSENGER_name_of_kind (message.header.kind));
199 
200  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
201 
202  if (room)
203  {
204  handle_room_message (room, &message, hash);
205 
206  if (handle->msg_callback)
207  handle->msg_callback (handle->msg_cls, room, &message, hash);
208  }
209  else
210  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESSENGER ERROR: Room not found\n");
211 }
212 
213 static void
215 
216 static void
218 {
220  struct GNUNET_MQ_Envelope *env;
221 
223  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key));
224  GNUNET_MQ_send (handle->mq, env);
225 }
226 
227 static void
229  const struct GNUNET_PeerIdentity *door)
230 {
232  struct GNUNET_MQ_Envelope *env;
233 
235  GNUNET_memcpy(&(msg->door), door, sizeof(*door));
236  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key));
237  GNUNET_MQ_send (handle->mq, env);
238 }
239 
240 static void
242 {
244  struct GNUNET_MQ_Envelope *env;
245 
247  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key));
248  GNUNET_MQ_send (handle->mq, env);
249 }
250 
251 static int
252 iterate_reset_room (void *cls, const struct GNUNET_HashCode *key, void *value)
253 {
254  struct GNUNET_MESSENGER_Handle *handle = cls;
255  struct GNUNET_MESSENGER_Room *room = value;
256 
257  if (GNUNET_YES == room->opened)
258  send_open_room (handle, room);
259 
260  struct GNUNET_MESSENGER_ListTunnel *entry = room->entries.head;
261 
262  struct GNUNET_PeerIdentity door;
263 
264  while (entry)
265  {
266  GNUNET_PEER_resolve (entry->peer, &door);
267 
268  send_entry_room (handle, room, &door);
269 
270  entry = entry->next;
271  }
272 
273  return GNUNET_YES;
274 }
275 
276 static void
278 {
279  struct GNUNET_MESSENGER_Handle *handle = cls;
280 
281  handle->reconnect_task = NULL;
283  ;
284 
285  reconnect (handle);
286 
288 }
289 
290 static int
291 iterate_close_room (void *cls, const struct GNUNET_HashCode *key, void *value)
292 {
293  struct GNUNET_MESSENGER_Handle *handle = cls;
294  struct GNUNET_MESSENGER_Room *room = value;
295 
296  send_close_room (handle, room);
297 
298  return GNUNET_YES;
299 }
300 
301 static void
302 callback_mq_error (void *cls, enum GNUNET_MQ_Error error)
303 {
304  struct GNUNET_MESSENGER_Handle *handle = cls;
305 
306  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MQ ERROR: %u\n", error);
307 
309 
310  if (handle->mq)
311  {
312  GNUNET_MQ_destroy (handle->mq);
313  handle->mq = NULL;
314  }
315 
317 }
318 
319 static void
321 {
322  const struct GNUNET_MQ_MessageHandler handlers[] = { GNUNET_MQ_hd_var_size(
326  struct GNUNET_MESSENGER_KeyMessage, handle),
328  member_id,
330  struct GNUNET_MESSENGER_MemberMessage, handle),
331  GNUNET_MQ_hd_fixed_size(room_open,
334  handle),
335  GNUNET_MQ_hd_fixed_size(room_entry,
338  handle),
339  GNUNET_MQ_hd_fixed_size(room_close,
342  handle),
344  recv_message,
346  struct GNUNET_MESSENGER_RecvMessage, handle),
348 
349  handle->mq = GNUNET_CLIENT_connect (handle->cfg,
351  handlers, &callback_mq_error, handle);
352 }
353 
358 {
359  struct GNUNET_MESSENGER_Handle *handle = create_handle (cfg, identity_callback, identity_cls, msg_callback, msg_cls);
360 
361  reconnect (handle);
362 
363  if (handle->mq)
364  {
365  const uint16_t name_len = name ? strlen (name) : 0;
366 
368  struct GNUNET_MQ_Envelope *env;
369 
371 
372  char *extra = ((char*) msg) + sizeof(*msg);
373 
374  if (name_len)
375  GNUNET_memcpy(extra, name, name_len);
376 
377  extra[name_len] = '\0';
378 
379  GNUNET_MQ_send (handle->mq, env);
380  return handle;
381  }
382  else
383  {
384  destroy_handle (handle);
385  return NULL;
386  }
387 }
388 
389 int
391 {
392  if ((!handle) || (!get_handle_name(handle)))
393  return GNUNET_SYSERR;
394 
396  struct GNUNET_MQ_Envelope *env;
397 
399  GNUNET_MQ_send (handle->mq, env);
400  return GNUNET_OK;
401 }
402 
403 void
405 {
406  if (!handle)
407  return;
408 
410  struct GNUNET_MQ_Envelope *env;
411 
413  GNUNET_MQ_send (handle->mq, env);
414 
415  destroy_handle (handle);
416 }
417 
418 const char*
420 {
421  if (!handle)
422  return NULL;
423 
424  return get_handle_name (handle);
425 }
426 
427 int
429 {
430  if (!handle)
431  return GNUNET_SYSERR;
432 
433  const uint16_t name_len = name ? strlen (name) : 0;
434 
436  struct GNUNET_MQ_Envelope *env;
437 
439 
440  char *extra = ((char*) msg) + sizeof(*msg);
441 
442  if (name_len)
443  GNUNET_memcpy(extra, name, name_len);
444 
445  extra[name_len] = '\0';
446 
447  GNUNET_MQ_send (handle->mq, env);
448  return GNUNET_YES;
449 }
450 
451 const struct GNUNET_IDENTITY_PublicKey*
453 {
454  if (!handle)
455  return NULL;
456 
457  return get_handle_key (handle);
458 }
459 
460 struct GNUNET_MESSENGER_Room*
462 {
463  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
464 
465  if (!room)
466  {
467  room = create_room (handle, key);
468 
469  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room,
471  {
472  destroy_room (room);
473  return NULL;
474  }
475  }
476 
477  send_open_room (handle, room);
478  return room;
479 }
480 
481 struct GNUNET_MESSENGER_Room*
483  const struct GNUNET_HashCode *key)
484 {
485  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
486 
487  if (!room)
488  {
489  room = create_room (handle, key);
490 
491  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room,
493  {
494  destroy_room (room);
495  return NULL;
496  }
497  }
498 
499  send_entry_room (handle, room, door);
500  return room;
501 }
502 
503 void
505 {
506  send_close_room (room->handle, room);
507 }
508 
511 {
512  return GNUNET_CONTAINER_multishortmap_get (room->members, id);
513 }
514 
515 const char*
517 {
518  if (!contact)
519  return NULL;
520 
521  return get_contact_name (contact);
522 }
523 
524 const struct GNUNET_IDENTITY_PublicKey*
526 {
527  if (!contact)
528  return NULL;
529 
530  return get_contact_key (contact);
531 }
532 
533 void
535 {
536  const uint16_t length = get_message_size (message);
537 
539  struct GNUNET_MQ_Envelope *env;
540 
542 
543  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key));
544 
545  char *buffer = ((char*) msg) + sizeof(*msg);
546  encode_message (message, length, buffer);
547 
548  GNUNET_MQ_send (room->handle->mq, env);
549 }
550 
551 const struct GNUNET_MESSENGER_Message*
553 {
554  const struct GNUNET_MESSENGER_Message *message = get_room_message (room, hash);
555 
556  if (!message)
557  {
559  struct GNUNET_MQ_Envelope *env;
560 
562  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(room->key));
563  GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash));
564  GNUNET_MQ_send (room->handle->mq, env);
565  }
566 
567  return message;
568 }
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.
int decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer)
Decodes a message from a given buffer of a maximal length in bytes.
const struct GNUNET_IDENTITY_PublicKey * GNUNET_MESSENGER_get_key(const struct GNUNET_MESSENGER_Handle *handle)
Get the public key used by the messenger.
void GNUNET_MESSENGER_send_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message)
Send a message into a room.
struct GNUNET_MESSENGER_MessageHeader header
Header.
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
void GNUNET_MESSENGER_close_room(struct GNUNET_MESSENGER_Room *room)
Close a room which was entered, opened or both in various order and variety.
static void handle_get_name(void *cls, const struct GNUNET_MESSENGER_NameMessage *msg)
Definition: messenger_api.c:77
struct GNUNET_IDENTITY_PublicKey pubkey
const struct GNUNET_IDENTITY_PublicKey * get_handle_key(const struct GNUNET_MESSENGER_Handle *handle)
Returns the public key of a given handle.
Message to receive the current member id of a handle in room.
GNUnet MESSENGER service.
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE
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
struct GNUNET_HashCode key
static void callback_reconnect(void *cls)
GNUNET_MQ_Error
Error codes for the queue.
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...
const char * GNUNET_MESSENGER_contact_get_name(const struct GNUNET_MESSENGER_Contact *contact)
Get the name used by the contact.
char * GNUNET_IDENTITY_public_key_to_string(const struct GNUNET_IDENTITY_PublicKey *key)
Creates a (Base32) string representation of the public key.
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
struct GNUNET_CONTAINER_MultiShortmap * members
struct GNUNET_PeerIdentity door
struct GNUNET_MESSENGER_ListTunnel * head
static void callback_mq_error(void *cls, enum GNUNET_MQ_Error error)
static void handle_recv_message(void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg)
int GNUNET_MESSENGER_set_name(struct GNUNET_MESSENGER_Handle *handle, const char *name)
Set the name for the messenger.
const char * get_contact_name(const struct GNUNET_MESSENGER_SrvContact *contact)
Returns the current name of a given contact or NULL if no valid name was assigned yet...
static int iterate_close_room(void *cls, const struct GNUNET_HashCode *key, void *value)
static int iterate_reset_room(void *cls, const struct GNUNET_HashCode *key, void *value)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message)
Returns the exact size in bytes to encode a given message.
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.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer)
Encodes a given message into a buffer of a maximal length in bytes.
struct GNUNET_SCHEDULER_Task * reconnect_task
struct GNUNET_MESSENGER_ListTunnel * next
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void handle_room_open(void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
static void handle_member_id(void *cls, const struct GNUNET_MESSENGER_MemberMessage *msg)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
static void handle_get_key(void *cls, const struct GNUNET_MESSENGER_KeyMessage *msg)
Definition: messenger_api.c:89
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_MQ_Handle * mq
struct GNUNET_MESSENGER_ListTunnels entries
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.
Message to send something into a room.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
static int check_recv_message(void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg)
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
struct GNUNET_ShortHashCode * contact_id
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
, &#39; bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_...
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 char * value
Value of the record to add/remove.
void(* GNUNET_MESSENGER_MessageCallback)(void *cls, const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash)
Method called whenever a message is sent or received from a room.
static int check_get_name(void *cls, const struct GNUNET_MESSENGER_NameMessage *msg)
Definition: messenger_api.c:70
#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
Message to create a handle for a client.
GNUNET_MESSENGER_MessageCallback msg_callback
struct GNUNET_MESSENGER_Room * GNUNET_MESSENGER_entry_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(...).
static void handle_room_close(void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
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_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
Definition: messenger_api.c:34
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE
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 gene...
struct GNUNET_CONTAINER_MultiHashMap * rooms
A 512-bit hashcode.
messenger api: client implementation of GNUnet MESSENGER service
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME
Message handler for a specific message type.
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_SrvContact *contact)
Returns the public key of a given contact.
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_TIME_Relative reconnect_time
struct GNUNET_HashCode key
The key used in the DHT.
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 E...
static void send_open_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Message to update the handle (its EGO key) for a client.
Message to destroy the handle for a client.
void destroy_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Destroys a handle and frees its memory fully.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static void send_entry_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_PeerIdentity *door)
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.
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY
const struct GNUNET_CONFIGURATION_Handle * cfg
#define GNUNET_MESSENGER_SERVICE_NAME
const struct GNUNET_MESSENGER_Message * get_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *hash, int request)
Returns a message from a room identified by a given hash.
void handle_room_message(struct GNUNET_MESSENGER_Room *room, 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...
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE
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.
The identity of the host (wraps the signing key of the peer).
int 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 ...
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...
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN
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)...
An identity key as per LSD0001.
struct GNUNET_ShortHashCode id
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE
configuration data
Definition: configuration.c:84
void * GNUNET_CONTAINER_multishortmap_get(const struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key)
Given a key find a value in the map matching the key.
const char * name
Message to receive the current name of a handle.
Message to receive the current public key of a handle.
void GNUNET_MESSENGER_disconnect(struct GNUNET_MESSENGER_Handle *handle)
Disconnect all of the messengers used services and clears up its used memory.
#define GNUNET_log(kind,...)
const char * GNUNET_MESSENGER_get_name(const struct GNUNET_MESSENGER_Handle *handle)
Get the name (if specified, otherwise NULL) used by the messenger.
const struct GNUNET_IDENTITY_PublicKey * GNUNET_MESSENGER_contact_get_key(const struct GNUNET_MESSENGER_Contact *contact)
Get the public key used by the contact.
static void send_close_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
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.
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:837
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
static void reconnect(struct GNUNET_MESSENGER_Handle *handle)
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE
GNUNET_MESSENGER_IdentityCallback identity_callback
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
Message to receive something from a room.
struct GNUNET_MESSENGER_Contact * GNUNET_MESSENGER_get_member(const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_ShortHashCode *id)
Get the contact of a member in a room identified by their id.
General message to confirm interaction with a room.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
static void handle_room_entry(void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID
messenger api: client and service implementation of GNUnet MESSENGER service
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_MessageHeader header