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
73 check_get_name (void *cls,
74  const struct GNUNET_MESSENGER_NameMessage *msg)
75 {
77  return GNUNET_OK;
78 }
79 
80 static void
81 handle_get_name (void *cls,
82  const struct GNUNET_MESSENGER_NameMessage *msg)
83 {
84  struct GNUNET_MESSENGER_Handle *handle = cls;
85 
86  const char *name = ((const char*) msg) + sizeof(*msg);
87 
88  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set name of handle: %s\n", name);
89 
90  set_handle_name (handle, strlen (name) > 0 ? name : NULL);
91 }
92 
93 static int
94 check_get_key (void *cls,
95  const struct GNUNET_MESSENGER_KeyMessage *msg)
96 {
97  const uint16_t full_length = ntohs (msg->header.size);
98 
99  if (full_length < sizeof(*msg))
100  return GNUNET_NO;
101 
102  const uint16_t length = full_length - sizeof(*msg);
103  const char *buffer = ((const char*) msg) + sizeof(*msg);
104 
106  if (GNUNET_IDENTITY_read_key_from_buffer(&pubkey, buffer, length) < 0)
107  return GNUNET_NO;
108 
109  return GNUNET_OK;
110 }
111 
112 static void
113 handle_get_key (void *cls,
114  const struct GNUNET_MESSENGER_KeyMessage *msg)
115 {
116  struct GNUNET_MESSENGER_Handle *handle = cls;
117 
118  const uint16_t length = ntohs (msg->header.size) - sizeof(*msg);
119  const char *buffer = ((const char*) msg) + sizeof(*msg);
120 
122  if (GNUNET_IDENTITY_read_key_from_buffer(&pubkey, buffer, length) < 0)
123  return;
124 
126  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set key of handle: %s\n", str);
127  GNUNET_free(str);
128 
130 
131  if (handle->identity_callback)
132  handle->identity_callback (handle->identity_cls, handle);
133 }
134 
135 static void
136 handle_member_id (void *cls,
137  const struct GNUNET_MESSENGER_MemberMessage *msg)
138 {
139  struct GNUNET_MESSENGER_Handle *handle = cls;
140 
141  const struct GNUNET_HashCode *key = &(msg->key);
142  const struct GNUNET_ShortHashCode *id = &(msg->id);
143 
144  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Set id of handle in room: %s\n", GNUNET_h2s (key));
145 
147 
148  if (room)
149  {
150  if (!room->contact_id)
152 
153  GNUNET_memcpy(room->contact_id, id, sizeof(*id));
154  }
155 }
156 
157 static void
158 handle_room_open (void *cls,
159  const struct GNUNET_MESSENGER_RoomMessage *msg)
160 {
161  struct GNUNET_MESSENGER_Handle *handle = cls;
162 
163  const struct GNUNET_HashCode *key = &(msg->key);
164 
165  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key));
166 
168 }
169 
170 static void
171 handle_room_entry (void *cls,
172  const struct GNUNET_MESSENGER_RoomMessage *msg)
173 {
174  struct GNUNET_MESSENGER_Handle *handle = cls;
175 
176  const struct GNUNET_PeerIdentity *door = &(msg->door);
177  const struct GNUNET_HashCode *key = &(msg->key);
178 
179  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Entered room: %s\n", GNUNET_h2s (key));
180 
182 }
183 
184 static void
185 handle_room_close (void *cls,
186  const struct GNUNET_MESSENGER_RoomMessage *msg)
187 {
188  struct GNUNET_MESSENGER_Handle *handle = cls;
189 
190  const struct GNUNET_HashCode *key = &(msg->key);
191 
192  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Closed room: %s\n", GNUNET_h2s (key));
193 
195 }
196 
197 static int
199  const struct GNUNET_MESSENGER_RecvMessage *msg)
200 {
201  const uint16_t full_length = ntohs (msg->header.size);
202 
203  if (full_length < sizeof(*msg))
204  return GNUNET_NO;
205 
206  const uint16_t length = full_length - sizeof(*msg);
207  const char *buffer = ((const char*) msg) + sizeof(*msg);
208 
209  struct GNUNET_MESSENGER_Message message;
210 
212  return GNUNET_NO;
213 
214  if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL))
215  return GNUNET_NO;
216 
217  cleanup_message(&message);
218  return GNUNET_OK;
219 }
220 
221 static void
223  const struct GNUNET_MESSENGER_RecvMessage *msg)
224 {
225  struct GNUNET_MESSENGER_Handle *handle = cls;
226 
227  const struct GNUNET_HashCode *key = &(msg->key);
228  const struct GNUNET_HashCode *sender = &(msg->sender);
229  const struct GNUNET_HashCode *context = &(msg->context);
230  const struct GNUNET_HashCode *hash = &(msg->hash);
231  const enum GNUNET_MESSENGER_MessageFlags flags = (
232  (enum GNUNET_MESSENGER_MessageFlags) (msg->flags)
233  );
234 
235  const uint16_t length = ntohs (msg->header.size) - sizeof(*msg);
236  const char *buffer = ((const char*) msg) + sizeof(*msg);
237 
238  struct GNUNET_MESSENGER_Message message;
239  decode_message (&message, length, buffer, GNUNET_YES, NULL);
240 
241  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n", GNUNET_MESSENGER_name_of_kind (message.header.kind));
242 
244 
245  if (room)
246  {
248 
249  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Raw contact from sender and context: (%s : %s)\n",
251 
253  store, context, sender
254  );
255 
256  contact = handle_room_message (room, contact, &message, hash);
257 
258  const struct GNUNET_MESSENGER_Message *stored_message = get_room_message(room, hash);
259 
260  if (handle->msg_callback)
261  handle->msg_callback (handle->msg_cls, room, contact, stored_message, hash, flags);
262  }
263  else
264  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n", GNUNET_h2s (key));
265 
266  cleanup_message(&message);
267 }
268 
269 static void
271 
272 static void
274  struct GNUNET_MESSENGER_Room *room)
275 {
277  struct GNUNET_MQ_Envelope *env;
278 
280  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
282 }
283 
284 static void
286  struct GNUNET_MESSENGER_Room *room,
287  const struct GNUNET_PeerIdentity *door)
288 {
290  struct GNUNET_MQ_Envelope *env;
291 
293  GNUNET_memcpy(&(msg->door), door, sizeof(*door));
294  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
296 }
297 
298 static void
300  struct GNUNET_MESSENGER_Room *room)
301 {
303  struct GNUNET_MQ_Envelope *env;
304 
306  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
308 }
309 
310 static int
312  const struct GNUNET_HashCode *key,
313  void *value)
314 {
315  struct GNUNET_MESSENGER_Handle *handle = cls;
316  struct GNUNET_MESSENGER_Room *room = value;
317 
318  if (GNUNET_YES == room->opened)
319  send_open_room (handle, room);
320 
321  struct GNUNET_MESSENGER_ListTunnel *entry = room->entries.head;
322 
323  struct GNUNET_PeerIdentity door;
324 
325  while (entry)
326  {
327  GNUNET_PEER_resolve (entry->peer, &door);
328 
329  send_enter_room (handle, room, &door);
330 
331  entry = entry->next;
332  }
333 
334  return GNUNET_YES;
335 }
336 
337 static void
339 {
340  struct GNUNET_MESSENGER_Handle *handle = cls;
341 
342  handle->reconnect_task = NULL;
343  handle->reconnect_time = GNUNET_TIME_STD_BACKOFF(handle->reconnect_time)
344  ;
345 
346  reconnect (handle);
347 
349 }
350 
351 static int
353  const struct GNUNET_HashCode *key,
354  void *value)
355 {
356  struct GNUNET_MESSENGER_Handle *handle = cls;
357  struct GNUNET_MESSENGER_Room *room = value;
358 
359  send_close_room (handle, room);
360 
361  return GNUNET_YES;
362 }
363 
364 static void
365 callback_mq_error (void *cls,
366  enum GNUNET_MQ_Error error)
367 {
368  struct GNUNET_MESSENGER_Handle *handle = cls;
369 
370  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "MQ_Error: %u\n", error);
371 
373 
374  if (handle->mq)
375  {
377  handle->mq = NULL;
378  }
379 
381 }
382 
383 static void
385 {
386  const struct GNUNET_MQ_MessageHandler handlers[] =
387  {
391  ),
395  ),
397  member_id,
400  ),
402  room_open,
405  ),
407  room_entry,
410  ),
412  room_close,
415  ),
417  recv_message,
420  ),
422  };
423 
425 }
426 
429  const char *name,
431  void *identity_cls,
433  void *msg_cls)
434 {
436 
437  reconnect (handle);
438 
439  if (handle->mq)
440  {
441  const uint16_t name_len = name ? strlen (name) : 0;
442 
444  struct GNUNET_MQ_Envelope *env;
445 
447 
448  char *extra = ((char*) msg) + sizeof(*msg);
449 
450  if (name_len)
451  GNUNET_memcpy(extra, name, name_len);
452 
453  extra[name_len] = '\0';
454 
456  return handle;
457  }
458  else
459  {
461  return NULL;
462  }
463 }
464 
465 int
467 {
468  if ((!handle) || (!get_handle_name (handle)))
469  return GNUNET_SYSERR;
470 
472  struct GNUNET_MQ_Envelope *env;
473 
476  return GNUNET_OK;
477 }
478 
479 void
481 {
482  if (!handle)
483  return;
484 
486  struct GNUNET_MQ_Envelope *env;
487 
490 
492 }
493 
494 const char*
496 {
497  if (!handle)
498  return NULL;
499 
500  return get_handle_name (handle);
501 }
502 
503 int
505  const char *name)
506 {
507  if (!handle)
508  return GNUNET_SYSERR;
509 
510  const uint16_t name_len = name ? strlen (name) : 0;
511 
513  struct GNUNET_MQ_Envelope *env;
514 
516 
517  char *extra = ((char*) msg) + sizeof(*msg);
518 
519  if (name_len)
520  GNUNET_memcpy(extra, name, name_len);
521 
522  extra[name_len] = '\0';
523 
525  return GNUNET_YES;
526 }
527 
528 static const struct GNUNET_IDENTITY_PublicKey*
530 {
531  if (0 == GNUNET_memcmp(public_key, get_anonymous_public_key()))
532  return NULL;
533 
534  return public_key;
535 }
536 
537 const struct GNUNET_IDENTITY_PublicKey*
539 {
540  if (!handle)
541  return NULL;
542 
544 }
545 
546 struct GNUNET_MESSENGER_Room*
548  const struct GNUNET_HashCode *key)
549 {
550  if ((!handle) || (!key))
551  return NULL;
552 
554 
555  if (!room)
556  {
557  room = create_room (handle, key);
558 
561  {
562  destroy_room (room);
563  return NULL;
564  }
565  }
566 
567  send_open_room (handle, room);
568  return room;
569 }
570 
571 struct GNUNET_MESSENGER_Room*
573  const struct GNUNET_PeerIdentity *door,
574  const struct GNUNET_HashCode *key)
575 {
576  if ((!handle) || (!door) || (!key))
577  return NULL;
578 
580 
581  if (!room)
582  {
583  room = create_room (handle, key);
584 
587  {
588  destroy_room (room);
589  return NULL;
590  }
591  }
592 
593  send_enter_room (handle, room, door);
594  return room;
595 }
596 
597 void
599 {
600  if (!room)
601  return;
602 
603  send_close_room (room->handle, room);
604 }
605 
607 {
610  size_t counter;
611  void *cls;
612 };
613 
614 static int
615 iterate_find_room (void* cls,
616  const struct GNUNET_HashCode *key,
617  void *value)
618 {
619  struct GNUNET_MESSENGER_RoomFind *find = cls;
620  struct GNUNET_MESSENGER_Room *room = value;
621 
622  if ((find->counter > 0) && ((!find->contact) || (GNUNET_YES == find_room_member(room, find->contact))))
623  {
624  find->counter--;
625 
626  if (!find->callback)
627  return GNUNET_YES;
628 
629  return find->callback(find->cls, room, find->contact);
630  }
631  else
632  return GNUNET_NO;
633 }
634 
635 int
637  const struct GNUNET_MESSENGER_Contact *contact,
639  void *cls)
640 {
641  if (!handle)
642  return GNUNET_SYSERR;
643 
644  struct GNUNET_MESSENGER_RoomFind find;
645 
646  find.contact = contact;
647  find.callback = callback;
648  find.counter = (contact? contact->rc : SIZE_MAX);
649  find.cls = cls;
650 
652 }
653 
654 const struct GNUNET_HashCode*
656 {
657  if (!room)
658  return NULL;
659 
660  return &(room->key);
661 }
662 
663 const struct GNUNET_MESSENGER_Contact*
665  const struct GNUNET_HashCode *hash)
666 {
667  if ((!room) || (!hash))
668  return NULL;
669 
670  return get_room_sender(room, hash);
671 }
672 
673 const char*
675 {
676  if (!contact)
677  return NULL;
678 
679  return get_contact_name (contact);
680 }
681 
682 const struct GNUNET_IDENTITY_PublicKey*
684 {
685  if (!contact)
686  return NULL;
687 
688  return get_non_anonymous_key (get_contact_key (contact));
689 }
690 
691 void
693  const struct GNUNET_MESSENGER_Message *message,
694  const struct GNUNET_MESSENGER_Contact *contact)
695 {
696  if ((!room) || (!message))
697  return;
698 
699  switch (filter_message_sending (message))
700  {
701  case GNUNET_SYSERR:
702  GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Sending message aborted: This kind of message is reserved for the service!\n");
703  return;
704  case GNUNET_NO:
705  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: This kind of message could cause issues!\n");
706  return;
707  default:
708  break;
709  }
710 
711  ssize_t key_length = 0;
712 
713  if (contact)
714  {
715  const struct GNUNET_IDENTITY_PublicKey *public_key = get_non_anonymous_key (
716  get_contact_key(contact)
717  );
718 
719  if (public_key)
720  key_length = GNUNET_IDENTITY_key_get_length(public_key);
721  else
722  key_length = -1;
723  }
724 
725  if (key_length < 0)
726  {
727  GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Sending message aborted: Invalid key!\n");
728  return;
729  }
730 
731  const uint16_t msg_length = get_message_size (message, GNUNET_NO);
732 
734  struct GNUNET_MQ_Envelope *env;
735 
736  const uint16_t length = (uint16_t) key_length + msg_length;
737 
739  msg, length,
741  );
742 
743  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
744 
745  msg->flags = (uint32_t) (
747  );
748 
749  char *buffer = ((char*) msg) + sizeof(*msg);
750  char *msg_buffer = buffer + key_length;
751 
752  if (key_length > 0)
753  GNUNET_IDENTITY_write_key_to_buffer(get_contact_key(contact), buffer, key_length);
754 
755  encode_message (message, msg_length, msg_buffer, GNUNET_NO);
756 
757  GNUNET_MQ_send (room->handle->mq, env);
758 }
759 
760 const struct GNUNET_MESSENGER_Message*
762  const struct GNUNET_HashCode *hash)
763 {
764  if ((!room) || (!hash))
765  return NULL;
766 
767  const struct GNUNET_MESSENGER_Message *message = get_room_message (room, hash);
768 
769  if (!message)
770  {
772  struct GNUNET_MQ_Envelope *env;
773 
775  GNUNET_memcpy(&(msg->key), &(room->key), sizeof(msg->key));
776  GNUNET_memcpy(&(msg->hash), hash, sizeof(*hash));
777  GNUNET_MQ_send (room->handle->mq, env);
778  }
779 
780  return message;
781 }
782 
783 int
786  void *cls)
787 {
788  if (!room)
789  return GNUNET_SYSERR;
790 
791  return iterate_room_members(room, callback, cls);
792 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
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
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
struct GNUNET_HashCode key
The key used in the DHT.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
static pa_context * context
Pulseaudio context.
static struct GNUNET_IDENTITY_PublicKey pubkey
Public key of the zone to look in.
static char * value
Value of the record to add/remove.
GNUnet MESSENGER service.
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 ...
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...
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).
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...
void destroy_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Destroys a handle and frees its memory fully.
struct GNUNET_MESSENGER_SrvRoom * create_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Creates and allocates a new room for a handle with a given key.
void destroy_room(struct GNUNET_MESSENGER_SrvRoom *room)
Destroys a room and frees its memory fully.
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_YES
Definition: gnunet_common.h:97
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
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:1064
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.
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MulitHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map.
void * GNUNET_CONTAINER_multihashmap_get(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Given a key find a value in the map matching the key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
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_write_key_to_buffer(const struct GNUNET_IDENTITY_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_IDENTITY_PublicKey to a compact buffer.
ssize_t GNUNET_IDENTITY_read_key_from_buffer(struct GNUNET_IDENTITY_PublicKey *key, const void *buffer, size_t len)
Reads a GNUNET_IDENTITY_PublicKey from a compact buffer.
ssize_t GNUNET_IDENTITY_key_get_length(const struct GNUNET_IDENTITY_PublicKey *key)
Get the compacted length of a GNUNET_IDENTITY_PublicKey.
Definition: identity_api.c:991
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
const char * GNUNET_MESSENGER_get_name(const struct GNUNET_MESSENGER_Handle *handle)
Get the name (if specified, otherwise NULL) used by the messenger.
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.
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...
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...
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.
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...
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
GNUNET_MESSENGER_MessageFlags
Enum for the different supported flags used by message handling Compatible flags can be OR'ed togethe...
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.
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_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.
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 char * GNUNET_MESSENGER_contact_get_name(const struct GNUNET_MESSENGER_Contact *contact)
Get the name used by the contact.
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.
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
Definition: messenger_api.c:35
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.
void GNUNET_MESSENGER_disconnect(struct GNUNET_MESSENGER_Handle *handle)
Disconnect all of the messengers used services and clears up its used memory.
const struct GNUNET_HashCode * GNUNET_MESSENGER_room_get_key(const struct GNUNET_MESSENGER_Room *room)
Get the key of a given room.
#define GNUNET_MESSENGER_SERVICE_NAME
Identifier of GNUnet MESSENGER Service.
void GNUNET_MESSENGER_close_room(struct GNUNET_MESSENGER_Room *room)
Close a room which was entered, opened or both in various order and variety.
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 GNUNET_MESSENGER_set_name(struct GNUNET_MESSENGER_Handle *handle, const char *name)
Set the name for the messenger.
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.
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.
@ GNUNET_MESSENGER_KIND_INFO
The info kind.
@ GNUNET_MESSENGER_KIND_MISS
The miss kind.
@ GNUNET_MESSENGER_KIND_INVITE
The invite kind.
@ GNUNET_MESSENGER_KIND_PRIVATE
The private kind.
@ GNUNET_MESSENGER_KIND_FILE
The file kind.
@ GNUNET_MESSENGER_KIND_REQUEST
The request kind.
@ GNUNET_MESSENGER_KIND_NAME
The name kind.
@ GNUNET_MESSENGER_KIND_LEAVE
The leave kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_TEXT
The text kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
@ GNUNET_MESSENGER_FLAG_PRIVATE
The private flag.
@ GNUNET_MESSENGER_FLAG_NONE
The none flag.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:355
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:52
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:839
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 GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SEND_MESSAGE
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_CREATE
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_UPDATE
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_NAME
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_SET_NAME
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_GET_KEY
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY
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
#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 int iterate_reset_room(void *cls, const struct GNUNET_HashCode *key, void *value)
static void handle_recv_message(void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg)
static void callback_reconnect(void *cls)
static void handle_room_close(void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
static const struct GNUNET_IDENTITY_PublicKey * get_non_anonymous_key(const struct GNUNET_IDENTITY_PublicKey *public_key)
static int iterate_find_room(void *cls, const struct GNUNET_HashCode *key, void *value)
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 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 void callback_mq_error(void *cls, enum GNUNET_MQ_Error error)
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 int iterate_close_room(void *cls, const struct GNUNET_HashCode *key, void *value)
static int check_get_key(void *cls, const struct GNUNET_MESSENGER_KeyMessage *msg)
Definition: messenger_api.c:94
static void handle_get_name(void *cls, const struct GNUNET_MESSENGER_NameMessage *msg)
Definition: messenger_api.c:81
static int check_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 int check_get_name(void *cls, const struct GNUNET_MESSENGER_NameMessage *msg)
Definition: messenger_api.c:73
const struct GNUNET_IDENTITY_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.
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_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 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 * 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.
struct GNUNET_MESSENGER_ContactStore * get_handle_contact_store(struct GNUNET_MESSENGER_Handle *handle)
Returns the used contact store of a given handle.
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.
const struct GNUNET_IDENTITY_PublicKey * get_handle_key(const struct GNUNET_MESSENGER_Handle *handle)
Returns the public key of a given handle.
messenger api: client implementation of GNUnet MESSENGER service
int filter_message_sending(const struct GNUNET_MESSENGER_Message *message)
Returns if a specific kind of message should be sent by a client.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, int include_header)
Encodes a given message into a buffer of a maximal length in bytes.
int decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, int include_header, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind, int include_header)
Returns the minimal size in bytes to encode a message of a specific kind.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, int include_header)
Returns the exact size in bytes to encode a given message.
void cleanup_message(struct GNUNET_MESSENGER_Message *message)
Frees the messages body memory.
messenger api: client and service implementation of GNUnet MESSENGER service
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_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.
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.
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...
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...
const struct GNUNET_IDENTITY_PublicKey * get_anonymous_public_key()
Returns the public identity key of GNUNET_IDENTITY_ego_get_anonymous() without recalculating it every...
messenger api: client implementation of GNUnet MESSENGER service
#define SIZE_MAX
Definition: platform.h:207
const char * name
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect to the service.
Definition: dns_api.c:81
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration to use.
Definition: dns_api.c:66
struct GNUNET_MQ_Handle * mq
Connection to DNS service, or NULL.
Definition: dns_api.c:61
A 512-bit hashcode.
An identity key as per LSD0001.
Message to create a handle for a client.
Message to destroy the handle for a client.
Message to request something from a room.
struct GNUNET_MQ_Handle * mq
GNUNET_MESSENGER_MessageCallback msg_callback
GNUNET_MESSENGER_IdentityCallback identity_callback
Message to receive the current public key of a handle.
struct GNUNET_MESSENGER_ListTunnel * next
struct GNUNET_MESSENGER_ListTunnel * head
Message to receive the current member id of a handle in room.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
Message to receive the current name of a handle.
Message to receive something from a room.
GNUNET_MESSENGER_MemberCallback callback
const struct GNUNET_MESSENGER_Contact * contact
General message to confirm interaction with a room.
struct GNUNET_MESSENGER_Handle * handle
struct GNUNET_MESSENGER_ListTunnels entries
struct GNUNET_ShortHashCode * contact_id
struct GNUNET_HashCode key
Message to send something into a room.
Message to update the handle (its EGO key) for a client.
Message handler for a specific message type.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
static char * get_key(char *line)
Definition: testing.c:1808