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--2021 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 #include "messenger_api_util.h"
33 
34 const char*
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 }
71 
72 static int
74 {
76  return GNUNET_OK;
77 }
78 
79 static void
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 }
90 
91 static int
92 check_get_key (void *cls, const struct GNUNET_MESSENGER_KeyMessage *msg)
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 
102  struct GNUNET_IDENTITY_PublicKey pubkey;
103  if (GNUNET_IDENTITY_read_key_from_buffer(&pubkey, buffer, length) < 0)
104  return GNUNET_NO;
105 
106  return GNUNET_OK;
107 }
108 
109 static void
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 
117  struct GNUNET_IDENTITY_PublicKey pubkey;
118  if (GNUNET_IDENTITY_read_key_from_buffer(&pubkey, buffer, length) < 0)
119  return;
120 
121  char* str = GNUNET_IDENTITY_public_key_to_string (&pubkey);
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 }
130 
131 static void
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 }
151 
152 static void
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 }
163 
164 static void
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 }
176 
177 static void
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 }
188 
189 static int
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 
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 }
210 
211 static void
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 }
253 
254 static void
256 
257 static void
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 }
267 
268 static void
270  const struct GNUNET_PeerIdentity *door)
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 }
280 
281 static void
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 }
291 
292 static int
293 iterate_reset_room (void *cls, const struct GNUNET_HashCode *key, void *value)
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 }
316 
317 static void
319 {
320  struct GNUNET_MESSENGER_Handle *handle = cls;
321 
322  handle->reconnect_task = NULL;
324  ;
325 
326  reconnect (handle);
327 
329 }
330 
331 static int
332 iterate_close_room (void *cls, const struct GNUNET_HashCode *key, void *value)
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 }
341 
342 static void
343 callback_mq_error (void *cls, enum GNUNET_MQ_Error error)
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 }
359 
360 static void
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 }
403 
408 {
409  struct GNUNET_MESSENGER_Handle *handle = create_handle (cfg, identity_callback, identity_cls, msg_callback, msg_cls);
410 
411  reconnect (handle);
412 
413  if (handle->mq)
414  {
415  const uint16_t name_len = name ? strlen (name) : 0;
416 
418  struct GNUNET_MQ_Envelope *env;
419 
421 
422  char *extra = ((char*) msg) + sizeof(*msg);
423 
424  if (name_len)
425  GNUNET_memcpy(extra, name, name_len);
426 
427  extra[name_len] = '\0';
428 
429  GNUNET_MQ_send (handle->mq, env);
430  return handle;
431  }
432  else
433  {
434  destroy_handle (handle);
435  return NULL;
436  }
437 }
438 
439 int
441 {
442  if ((!handle) || (!get_handle_name (handle)))
443  return GNUNET_SYSERR;
444 
446  struct GNUNET_MQ_Envelope *env;
447 
449  GNUNET_MQ_send (handle->mq, env);
450  return GNUNET_OK;
451 }
452 
453 void
455 {
456  if (!handle)
457  return;
458 
460  struct GNUNET_MQ_Envelope *env;
461 
463  GNUNET_MQ_send (handle->mq, env);
464 
465  destroy_handle (handle);
466 }
467 
468 const char*
470 {
471  if (!handle)
472  return NULL;
473 
474  return get_handle_name (handle);
475 }
476 
477 int
479 {
480  if (!handle)
481  return GNUNET_SYSERR;
482 
483  const uint16_t name_len = name ? strlen (name) : 0;
484 
486  struct GNUNET_MQ_Envelope *env;
487 
489 
490  char *extra = ((char*) msg) + sizeof(*msg);
491 
492  if (name_len)
493  GNUNET_memcpy(extra, name, name_len);
494 
495  extra[name_len] = '\0';
496 
497  GNUNET_MQ_send (handle->mq, env);
498  return GNUNET_YES;
499 }
500 
501 static const struct GNUNET_IDENTITY_PublicKey*
503 {
504  if (0 == GNUNET_memcmp(public_key, get_anonymous_public_key()))
505  return NULL;
506 
507  return public_key;
508 }
509 
510 const struct GNUNET_IDENTITY_PublicKey*
512 {
513  if (!handle)
514  return NULL;
515 
516  return get_non_anonymous_key (get_handle_key (handle));
517 }
518 
519 struct GNUNET_MESSENGER_Room*
521 {
522  if ((!handle) || (!key))
523  return NULL;
524 
525  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
526 
527  if (!room)
528  {
529  room = create_room (handle, key);
530 
531  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room,
533  {
534  destroy_room (room);
535  return NULL;
536  }
537  }
538 
539  send_open_room (handle, room);
540  return room;
541 }
542 
543 struct GNUNET_MESSENGER_Room*
545  const struct GNUNET_HashCode *key)
546 {
547  if ((!handle) || (!door) || (!key))
548  return NULL;
549 
550  struct GNUNET_MESSENGER_Room *room = GNUNET_CONTAINER_multihashmap_get (handle->rooms, key);
551 
552  if (!room)
553  {
554  room = create_room (handle, key);
555 
556  if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put (handle->rooms, key, room,
558  {
559  destroy_room (room);
560  return NULL;
561  }
562  }
563 
564  send_enter_room (handle, room, door);
565  return room;
566 }
567 
568 void
570 {
571  if (!room)
572  return;
573 
574  send_close_room (room->handle, room);
575 }
576 
578 {
581  size_t counter;
582  void *cls;
583 };
584 
585 static int
586 iterate_find_room (void* cls, const struct GNUNET_HashCode *key, void *value)
587 {
588  struct GNUNET_MESSENGER_RoomFind *find = cls;
589  struct GNUNET_MESSENGER_Room *room = value;
590 
591  if ((find->counter > 0) && ((!find->contact) || (GNUNET_YES == find_room_member(room, find->contact))))
592  {
593  find->counter--;
594 
595  if (!find->callback)
596  return GNUNET_YES;
597 
598  return find->callback(find->cls, room, find->contact);
599  }
600  else
601  return GNUNET_NO;
602 }
603 
604 int
607 {
608  if (!handle)
609  return GNUNET_SYSERR;
610 
611  struct GNUNET_MESSENGER_RoomFind find;
612 
613  find.contact = contact;
614  find.callback = callback;
615  find.counter = (contact? contact->rc : SIZE_MAX);
616  find.cls = cls;
617 
619 }
620 
621 const struct GNUNET_HashCode*
623 {
624  if (!room)
625  return NULL;
626 
627  return &(room->key);
628 }
629 
630 const struct GNUNET_MESSENGER_Contact*
631 GNUNET_MESSENGER_get_sender (const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
632 {
633  if ((!room) || (!hash))
634  return NULL;
635 
636  return get_room_sender(room, hash);
637 }
638 
639 const char*
641 {
642  if (!contact)
643  return NULL;
644 
645  return get_contact_name (contact);
646 }
647 
648 const struct GNUNET_IDENTITY_PublicKey*
650 {
651  if (!contact)
652  return NULL;
653 
654  return get_non_anonymous_key (get_contact_key (contact));
655 }
656 
657 void
659  const struct GNUNET_MESSENGER_Contact *contact)
660 {
661  if ((!room) || (!message))
662  return;
663 
664  switch (filter_message_sending (message))
665  {
666  case GNUNET_SYSERR:
667  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sending message aborted: This kind of message is reserved for the service!\n");
668  return;
669  case GNUNET_NO:
670  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: This kind of message could cause issues!\n");
671  return;
672  default:
673  break;
674  }
675 
676  ssize_t key_length = 0;
677 
678  if (contact)
679  {
680  const struct GNUNET_IDENTITY_PublicKey *public_key = get_non_anonymous_key (
681  get_contact_key(contact)
682  );
683 
684  if (public_key)
685  key_length = GNUNET_IDENTITY_key_get_length(public_key);
686  else
687  key_length = -1;
688  }
689 
690  if (key_length < 0)
691  {
692  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: Invalid key!\n");
693  return;
694  }
695 
696  const uint16_t msg_length = get_message_size (message, GNUNET_NO);
697 
699  struct GNUNET_MQ_Envelope *env;
700 
701  const uint16_t length = (uint16_t) key_length + msg_length;
702 
703  env = GNUNET_MQ_msg_extra(
704  msg, length,
706  );
707 
708  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
709 
710  msg->flags = (uint32_t) (
712  );
713 
714  char *buffer = ((char*) msg) + sizeof(*msg);
715  char *msg_buffer = buffer + key_length;
716 
717  if (key_length > 0)
718  GNUNET_IDENTITY_write_key_to_buffer(get_contact_key(contact), buffer, key_length);
719 
720  encode_message (message, msg_length, msg_buffer, GNUNET_NO);
721 
722  GNUNET_MQ_send (room->handle->mq, env);
723 }
724 
725 const struct GNUNET_MESSENGER_Message*
727 {
728  if ((!room) || (!hash))
729  return NULL;
730 
731  const struct GNUNET_MESSENGER_Message *message = get_room_message (room, hash);
732 
733  if (!message)
734  {
736  struct GNUNET_MQ_Envelope *env;
737 
739  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
740  GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash));
741  GNUNET_MQ_send (room->handle->mq, env);
742  }
743 
744  return message;
745 }
746 
747 int
749  void *cls)
750 {
751  if (!room)
752  return GNUNET_SYSERR;
753 
754  return iterate_room_members(room, callback, cls);
755 }
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.
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.
GNUNET_MESSENGER_MemberCallback callback
struct GNUNET_MESSENGER_MessageHeader header
Header.
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.
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY
const struct GNUNET_HashCode * GNUNET_MESSENGER_room_get_key(const struct GNUNET_MESSENGER_Room *room)
Get the key of a given room.
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:80
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.
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.
#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
struct GNUNET_MESSENGER_Contact * 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_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.
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 struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.
const char * GNUNET_MESSENGER_contact_get_name(const struct GNUNET_MESSENGER_Contact *contact)
Get the name used by the contact.
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...
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.
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_PeerIdentity door
struct GNUNET_MESSENGER_ListTunnel * head
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 fo...
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.
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
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.
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)
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.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE
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.
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.
struct GNUNET_MessageHeader header
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
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)
static const struct GNUNET_IDENTITY_PublicKey * get_non_anonymous_key(const struct GNUNET_IDENTITY_PublicKey *public_key)
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)
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
#define SIZE_MAX
Definition: platform.h:213
static int check_get_key(void *cls, const struct GNUNET_MESSENGER_KeyMessage *msg)
Definition: messenger_api.c:92
struct GNUNET_MQ_Handle * mq
static pa_context * context
Pulseaudio context.
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.
GNUNET_MESSENGER_MessageFlags
Enum for the different supported flags used by message handling Compatible flags can be OR&#39;ed togethe...
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.
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind)
Returns the minimal size in bytes to encode a message of a specific kind.
static int check_get_name(void *cls, const struct GNUNET_MESSENGER_NameMessage *msg)
Definition: messenger_api.c:73
#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
int filter_message_sending(const struct GNUNET_MESSENGER_Message *message)
Returns if a specific kind of message should be sent by a client.
Message to create a handle for a client.
GNUNET_MESSENGER_MessageCallback msg_callback
static void handle_room_close(void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
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...
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...
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME
static const int key_length
Fixed size of the public/private keys.
Definition: gnunet-abd.c:211
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.
#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...
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.
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.
messenger api: client implementation of GNUnet MESSENGER service
struct GNUNET_MESSENGER_Handle * handle
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.
struct GNUNET_TIME_Relative reconnect_time
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...
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)
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
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...
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
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.
#define GNUNET_MESSENGER_SERVICE_NAME
Identifier of GNUnet MESSENGER Service.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store(struct GNUNET_MESSENGER_Handle *handle)
Returns the used contact store of a given handle.
#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).
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
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 pr...
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE
configuration data
const char * name
Message to receive the current name of a handle.
int find_room_member(const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)
Checks through all members of a given room if a specific contact is found and returns a result depend...
Message to receive the current public key of a 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.
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 ...
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.
Message to request something from a room.
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.
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)
const struct GNUNET_MESSENGER_Contact * contact
static int iterate_find_room(void *cls, const struct GNUNET_HashCode *key, void *value)
#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.
const struct GNUNET_IDENTITY_PublicKey * get_anonymous_public_key()
Returns the public identity key of GNUNET_IDENTITY_ego_get_anonymous() without recalculating it every...
General message to confirm interaction with a room.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
static void send_enter_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_PeerIdentity *door)
static void handle_room_entry(void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID
#define GNUNET_free(ptr)
Wrapper around free.
messenger api: client and service implementation of GNUnet MESSENGER service
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_MessageHeader header
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.