GNUnet 0.22.2
messenger_api.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2024 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 */
26#include "gnunet_common.h"
28
31#include "gnunet_time_lib.h"
32
33#include "messenger_api.h"
40#include "messenger_api_room.h"
41#include "messenger_api_util.h"
42
43const char*
45{
46 switch (kind)
47 {
49 return "INFO";
51 return "JOIN";
53 return "LEAVE";
55 return "NAME";
57 return "KEY";
59 return "PEER";
61 return "ID";
63 return "MISS";
65 return "MERGE";
67 return "REQUEST";
69 return "INVITE";
71 return "TEXT";
73 return "FILE";
75 return "PRIVATE";
77 return "DELETE";
79 return "CONNECTION";
81 return "TICKET";
83 return "TRANSCRIPT";
85 return "TAG";
87 return "SUBSCRIBE";
89 return "TALK";
90 default:
91 return "UNKNOWN";
92 }
93}
94
95
96static void
98
99static void
101 const struct GNUNET_MESSENGER_RoomMessage *msg)
102{
104 const struct GNUNET_HashCode *key;
105 const struct GNUNET_HashCode *prev;
106 struct GNUNET_MESSENGER_Room *room;
107
108 GNUNET_assert ((cls) && (msg));
109
110 handle = cls;
111
112 key = &(msg->key);
113 prev = &(msg->previous);
114
115 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key));
116
118
119 room = get_handle_room (handle, key);
120 if (! room)
121 return;
122
123 update_room_last_message (room, prev);
125}
126
127
128static void
130 const struct GNUNET_MESSENGER_RoomMessage *msg)
131{
133 const struct GNUNET_PeerIdentity *door;
134 const struct GNUNET_HashCode *key;
135 const struct GNUNET_HashCode *prev;
136 struct GNUNET_MESSENGER_Room *room;
137
138 GNUNET_assert ((cls) && (msg));
139
140 handle = cls;
141
142 door = &(msg->door);
143 key = &(msg->key);
144 prev = &(msg->previous);
145
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entered room: %s\n", GNUNET_h2s (key));
147
149
150 room = get_handle_room (handle, key);
151 if (! room)
152 return;
153
154 update_room_last_message (room, prev);
156}
157
158
159static void
161 const struct GNUNET_MESSENGER_RoomMessage *msg)
162{
164 const struct GNUNET_HashCode *key;
165 const struct GNUNET_HashCode *prev;
166 struct GNUNET_MESSENGER_Room *room;
167
168 GNUNET_assert ((cls) && (msg));
169
170 handle = cls;
171
172 key = &(msg->key);
173 prev = &(msg->previous);
174
175 room = get_handle_room (handle, key);
176 if (room)
177 update_room_last_message (room, prev);
178
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Closed room: %s\n", GNUNET_h2s (key));
180
182}
183
184
185static void
187 const struct GNUNET_MESSENGER_RoomMessage *msg)
188{
190 const struct GNUNET_HashCode *key;
191 const struct GNUNET_HashCode *prev;
192 struct GNUNET_MESSENGER_Room *room;
193
194 GNUNET_assert ((cls) && (msg));
195
196 handle = cls;
197
198 key = &(msg->key);
199 prev = &(msg->previous);
200
201 room = get_handle_room (handle, key);
202 if (! room)
203 return;
204
205 update_room_last_message (room, prev);
206
207 room->wait_for_sync = GNUNET_NO;
209}
210
211
212static void
215{
217 const struct GNUNET_HashCode *key;
218 const struct GNUNET_ShortHashCode *id;
219 struct GNUNET_MESSENGER_Room *room;
220 struct GNUNET_MESSENGER_Message *message;
221 uint32_t reset;
222
223 GNUNET_assert ((cls) && (msg));
224
225 handle = cls;
226
227 key = &(msg->key);
228 id = &(msg->id);
229 reset = msg->reset;
230
231 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Changed member id in room: %s\n",
232 GNUNET_h2s (key));
233
234 room = get_handle_room (handle, key);
235 if (! room)
236 {
237 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Room is unknown to handle: %s\n",
238 GNUNET_h2s (key));
239 return;
240 }
241
242 if ((! get_room_sender_id (room)) || (GNUNET_YES == reset))
243 {
244 set_room_sender_id (room, id);
246 }
247 else
248 message = create_message_id (id);
249
250 if (! message)
251 return;
252
253 enqueue_message_to_room (room, message, NULL);
254}
255
256
259 const struct GNUNET_MESSENGER_RecvMessage *msg)
260{
261 struct GNUNET_MESSENGER_Message message;
262 uint16_t full_length, length;
263 const char *buffer;
264
266
267 full_length = ntohs (msg->header.size);
268
269 if (full_length < sizeof(*msg))
270 {
272 "Receiving failed: Message invalid!\n");
273 return GNUNET_NO;
274 }
275
276 length = full_length - sizeof(*msg);
277 buffer = ((const char*) msg) + sizeof(*msg);
278
280 GNUNET_YES))
281 {
283 "Receiving failed: Message too short!\n");
284 return GNUNET_NO;
285 }
286
287 if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL))
288 {
290 "Receiving failed: Message decoding failed!\n");
291 return GNUNET_NO;
292 }
293
294 cleanup_message (&message);
295 return GNUNET_OK;
296}
297
298
299static void
301 const struct GNUNET_MESSENGER_RecvMessage *msg)
302{
304 const struct GNUNET_HashCode *key;
305 const struct GNUNET_HashCode *sender;
306 const struct GNUNET_HashCode *context;
307 const struct GNUNET_HashCode *hash;
309 struct GNUNET_MESSENGER_Message message;
310 struct GNUNET_MESSENGER_Room *room;
311 uint16_t length;
312 const char *buffer;
313
314 GNUNET_assert ((cls) && (msg));
315
316 handle = cls;
317
318 key = &(msg->key);
319 sender = &(msg->sender);
320 context = &(msg->context);
321 hash = &(msg->hash);
322
323 flags = (enum GNUNET_MESSENGER_MessageFlags) (msg->flags);
324
325 length = ntohs (msg->header.size) - sizeof(*msg);
326 buffer = ((const char*) msg) + sizeof(*msg);
327
328 decode_message (&message, length, buffer, GNUNET_YES, NULL);
329
330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n",
332
333 room = get_handle_room (handle, key);
334 if (! room)
335 {
336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n",
337 GNUNET_h2s (key));
338
339 goto skip_message;
340 }
341
343 "Raw contact from sender and context: (%s : %s)\n",
345
347 sender,
348 context,
349 hash,
350 &message,
351 flags);
352
353skip_message:
354 cleanup_message (&message);
355}
356
357
358static void
360 const struct GNUNET_MESSENGER_GetMessage *msg)
361{
363 const struct GNUNET_HashCode *key;
364 const struct GNUNET_HashCode *hash;
365 struct GNUNET_MESSENGER_Room *room;
366
367 GNUNET_assert ((cls) && (msg));
368
369 handle = cls;
370
371 key = &(msg->key);
372 hash = &(msg->hash);
373
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Missing message in room: %s\n",
375 GNUNET_h2s (hash));
376
377 room = get_handle_room (handle, key);
378 if (! room)
379 {
381 "Miss in unknown room for this client: %s\n", GNUNET_h2s (key));
382 return;
383 }
384
385 if (! get_room_sender_id (room))
386 return;
387
388 {
389 struct GNUNET_MESSENGER_Message *message;
390
391 message = create_message_request (hash);
392 if (! message)
393 return;
394
395 enqueue_message_to_room (room, message, NULL);
396 }
397}
398
399
400static void
402
403static void
405 struct GNUNET_MESSENGER_Room *room)
406{
407 const struct GNUNET_CRYPTO_PublicKey *key;
409 struct GNUNET_MQ_Envelope *env;
410 char *msg_buffer;
411 ssize_t len;
412
413 GNUNET_assert ((handle) && (handle->mq) && (room));
414
416
418 "Open room (%s) by member using key: %s\n",
419 GNUNET_h2s (&(room->key)),
421
423
424 env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0,
426 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
427 GNUNET_memcpy (&(msg->previous), &(room->last_message),
428 sizeof(msg->previous));
429
430 msg_buffer = ((char*) msg) + sizeof(*msg);
431
432 if (len > 0)
434
436}
437
438
439static void
441 struct GNUNET_MESSENGER_Room *room,
442 const struct GNUNET_PeerIdentity *door)
443{
444 const struct GNUNET_CRYPTO_PublicKey *key;
446 struct GNUNET_MQ_Envelope *env;
447 char *msg_buffer;
448 ssize_t len;
449
450 GNUNET_assert ((handle) && (handle->mq) && (room) && (door));
451
453
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Enter room (%s) via door: %s (%s)\n",
455 GNUNET_h2s (&(room->key)),
456 GNUNET_i2s (door),
458
460
461 env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0,
463 GNUNET_memcpy (&(msg->door), door, sizeof(*door));
464 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
465 GNUNET_memcpy (&(msg->previous), &(room->last_message),
466 sizeof(msg->previous));
467
468 msg_buffer = ((char*) msg) + sizeof(*msg);
469
470 if (len > 0)
472
474}
475
476
477static void
479 struct GNUNET_MESSENGER_Room *room)
480{
482 struct GNUNET_MQ_Envelope *env;
483
484 GNUNET_assert ((handle) && (handle->mq) && (room));
485
486 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Close room (%s)!\n",
487 GNUNET_h2s (&(room->key)));
488
490
491 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
492 GNUNET_memcpy (&(msg->previous), &(room->last_message),
493 sizeof(msg->previous));
494
496}
497
498
499static void
501 struct GNUNET_MESSENGER_Room *room)
502{
504 struct GNUNET_MQ_Envelope *env;
505
506 GNUNET_assert ((handle) && (handle->mq) && (room));
507
509
510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sync room (%s)!\n",
511 GNUNET_h2s (&(room->key)));
512
514
515 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
516 GNUNET_memcpy (&(msg->previous), &(room->last_message),
517 sizeof(msg->previous));
518
520}
521
522
525 const struct GNUNET_HashCode *key,
526 void *value)
527{
529 struct GNUNET_MESSENGER_Room *room;
530 struct GNUNET_MESSENGER_ListTunnel *entry;
531
532 GNUNET_assert ((cls) && (value));
533
534 handle = cls;
535 room = value;
536
537 if (GNUNET_YES == room->opened)
538 send_open_room (handle, room);
539
540 entry = room->entries.head;
541 while (entry)
542 {
543 struct GNUNET_PeerIdentity door;
544
545 GNUNET_PEER_resolve (entry->peer, &door);
546 send_enter_room (handle, room, &door);
547
548 entry = entry->next;
549 }
550
551 return GNUNET_YES;
552}
553
554
555static void
557{
559
560 GNUNET_assert (cls);
561
562 handle = cls;
563
564 handle->reconnect_task = NULL;
565 handle->reconnect_time = GNUNET_TIME_STD_BACKOFF (handle->reconnect_time);
566
567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnect messenger!\n");
568
570
572 handle);
573}
574
575
578 const struct GNUNET_HashCode *key,
579 void *value)
580{
582 struct GNUNET_MESSENGER_Room *room;
583
584 GNUNET_assert ((cls) && (value));
585
586 handle = cls;
587 room = value;
588
589 send_close_room (handle, room);
590
591 return GNUNET_YES;
592}
593
594
595static void
597 enum GNUNET_MQ_Error error)
598{
600
601 GNUNET_assert (cls);
602
603 handle = cls;
604
605 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MQ_Error: %u\n", error);
606
608 handle);
609
610 if (handle->mq)
611 {
613 handle->mq = NULL;
614 }
615
616 handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_time,
618 handle);
619}
620
621
622static void
624{
626
627 {
628 const struct GNUNET_MQ_MessageHandler handlers[] = {
630 member_id,
633 ),
635 room_open,
638 ),
640 room_entry,
643 ),
645 room_close,
648 ),
653 ),
655 miss_message,
658 ),
660 room_sync,
663 ),
665 };
666
670 handle);
671 }
672}
673
674
677 const char *name,
678 const struct GNUNET_CRYPTO_PrivateKey *key,
680 void *msg_cls)
681{
683
685
687
689
690 if (handle->mq)
691 {
693 struct GNUNET_MQ_Envelope *env;
694
696
699
700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connect handle!\n");
701
704 return handle;
705 }
706 else
707 {
709 return NULL;
710 }
711}
712
713
714void
716{
718 struct GNUNET_MQ_Envelope *env;
719
720 if (! handle)
721 return;
722
723 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect handle!\n");
724
727
729}
730
731
732static void
734{
735 struct GNUNET_MESSENGER_Room *room;
736
737 GNUNET_assert (cls);
738
739 room = cls;
740
741 room->opened = GNUNET_NO;
742 clear_list_tunnels (&(room->entries));
743
744 send_close_room (room->handle, room);
745}
746
747
748static void
750{
751 struct GNUNET_MESSENGER_RoomSubscription *subscription;
752 struct GNUNET_MESSENGER_Room *room;
753 struct GNUNET_MESSENGER_Message *message;
754 const struct GNUNET_ShortHashCode *discourse;
755
756 GNUNET_assert (cls);
757
758 subscription = cls;
759 subscription->task = NULL;
760
761 room = subscription->room;
762 message = subscription->message;
763
764 subscription->message = NULL;
765
766 discourse = &(message->body.subscribe.discourse);
767
769 discourse,
770 subscription))
771 {
772 destroy_message (message);
773 return;
774 }
775
776 GNUNET_free (subscription);
777
778 enqueue_message_to_room (room, message, NULL);
779}
780
781
782static void
784 struct GNUNET_MESSENGER_Message *message)
785{
786 const struct GNUNET_ShortHashCode *discourse;
787 struct GNUNET_MESSENGER_RoomSubscription *subscription;
788 struct GNUNET_TIME_Relative time;
789 uint32_t flags;
790
791 GNUNET_assert ((room) && (message));
792
793 flags = message->body.subscribe.flags;
794
795 discourse = &(message->body.subscribe.discourse);
796
798 discourse);
799
801 goto active_subscription;
802
803 if (! subscription)
804 return;
805
806 if (subscription->task)
807 GNUNET_SCHEDULER_cancel (subscription->task);
808
809 if (subscription->message)
810 destroy_message (subscription->message);
811
813 discourse,
814 subscription))
815 {
816 subscription->task = NULL;
817 subscription->message = NULL;
818 return;
819 }
820
821 GNUNET_free (subscription);
822 return;
823
824active_subscription:
826 return;
827
829
830 if (! subscription)
831 {
832 subscription = GNUNET_new (struct GNUNET_MESSENGER_RoomSubscription);
833
835 room->subscriptions, discourse, subscription,
837 {
838 GNUNET_free (subscription);
839 return;
840 }
841
842 subscription->room = room;
843 }
844 else
845 {
846 if (subscription->task)
847 GNUNET_SCHEDULER_cancel (subscription->task);
848
849 if (subscription->message)
850 destroy_message (subscription->message);
851 }
852
853 subscription->message = create_message_subscribe (discourse, time,
854 flags);
855
856 if (! subscription->message)
857 {
858 subscription->task = NULL;
859 return;
860 }
861
862 {
863 struct GNUNET_TIME_Relative delay;
864 delay = GNUNET_TIME_relative_multiply_double (time, 0.9);
865
868 keep_subscription_alive, subscription);
869 }
870}
871
872
873static void
875 struct GNUNET_MESSENGER_Message *message,
876 const struct GNUNET_CRYPTO_PrivateKey *key,
877 struct GNUNET_HashCode *hash)
878{
879 const struct GNUNET_ShortHashCode *sender_id;
881 struct GNUNET_MQ_Envelope *env;
882 uint16_t msg_length;
883 char *msg_buffer;
884
885 GNUNET_assert ((room) && (message) && (key) && (hash));
886
887 sender_id = get_room_sender_id (room);
888
891
892 GNUNET_memcpy (&(message->header.sender_id), sender_id,
893 sizeof(message->header.sender_id));
894 GNUNET_memcpy (&(message->header.previous), &(room->last_message),
895 sizeof(message->header.previous));
896
897 message->header.signature.type = key->type;
898
899 msg_length = get_message_size (message, GNUNET_YES);
900
902 msg, msg_length,
904 );
905
906 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
907
908 msg_buffer = ((char*) msg) + sizeof(*msg);
909 encode_message (message, msg_length, msg_buffer, GNUNET_YES);
910
911 hash_message (message, msg_length, msg_buffer, hash);
912 sign_message (message, msg_length, msg_buffer, hash, key);
913
914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send message (%s)!\n",
915 GNUNET_h2s (hash));
916
917 if (! get_message_discourse (message))
918 update_room_last_message (room, hash);
919
920 switch (message->header.kind)
921 {
924 break;
926 handle_discourse_subscription (room, message);
927 break;
928 default:
929 break;
930 }
931
932 GNUNET_MQ_send (room->handle->mq, env);
933}
934
935
936void
938 struct GNUNET_MESSENGER_Message *message,
939 struct GNUNET_MESSENGER_Message *transcript)
940{
941 const struct GNUNET_CRYPTO_PrivateKey *key;
942
943 GNUNET_assert ((room) && (message));
944
945 key = get_handle_key (room->handle);
946
947 enqueue_to_messages (&(room->queue), key, message, transcript);
948
949 if (GNUNET_YES != is_room_available (room))
950 return;
951
952 if (GNUNET_YES == is_message_session_bound (message))
953 send_sync_room (room->handle, room);
954 else if (GNUNET_YES != room->wait_for_sync)
956}
957
958
959static void
961{
962 struct GNUNET_MESSENGER_Room *room;
963 struct GNUNET_MESSENGER_Message *message;
964 struct GNUNET_MESSENGER_Message *transcript;
966 struct GNUNET_HashCode hash;
968
969 GNUNET_assert (cls);
970
971 room = cls;
972
973 GNUNET_assert (room->handle);
974
975 room->queue_task = NULL;
976
977 if ((GNUNET_YES != is_room_available (room)) || (!(room->handle->mq)))
978 goto next_message;
979
980 message = NULL;
981 transcript = NULL;
982 memset (&key, 0, sizeof(key));
983
984 message = dequeue_from_messages (&(room->queue), &key, &transcript);
985
986 if (! message)
987 {
988 if (transcript)
989 destroy_message (transcript);
990
991 return;
992 }
993
994 send_message_to_room (room, message, &key, &hash);
995
996 if (! transcript)
997 {
999 goto next_message;
1000 }
1001
1002 GNUNET_memcpy (&(transcript->body.transcript.hash), &hash, sizeof(hash));
1003
1004 memset (&pubkey, 0, sizeof(pubkey));
1006
1007 if (GNUNET_YES == encrypt_message (transcript, &pubkey))
1008 {
1009 struct GNUNET_HashCode other;
1010 send_message_to_room (room, transcript, &key, &other);
1011
1013
1014 link_room_message (room, &hash, &other);
1015 link_room_message (room, &other, &hash);
1016 }
1017 else
1018 {
1020
1022 "Sending transcript aborted: Encryption failed!\n");
1023 }
1024
1025 destroy_message (transcript);
1026
1028 if (! room->queue.head)
1029 return;
1030
1033}
1034
1035static void
1037{
1038 if ((GNUNET_YES != is_room_available (room)) || (!(room->handle)))
1039 return;
1040
1041 if (room->handle->mq)
1043 else if (!(room->queue_task))
1046}
1047
1048
1049const char*
1051{
1052 if (! handle)
1053 return NULL;
1054
1055 return get_handle_name (handle);
1056}
1057
1058
1059static enum GNUNET_GenericReturnValue
1061 struct GNUNET_MESSENGER_Room *room,
1062 const struct GNUNET_MESSENGER_Contact *contact)
1063{
1064 const struct GNUNET_MESSENGER_Handle *handle;
1065 struct GNUNET_MESSENGER_Message *message;
1066 const char *name;
1067
1068 GNUNET_assert ((cls) && (room));
1069
1070 handle = cls;
1071
1072 if (GNUNET_YES != room->use_handle_name)
1073 return GNUNET_YES;
1074
1076 if (! name)
1077 return GNUNET_YES;
1078
1079 message = create_message_name (name);
1080 if (! message)
1081 return GNUNET_NO;
1082
1083 enqueue_message_to_room (room, message, NULL);
1084 return GNUNET_YES;
1085}
1086
1087
1090 const char *name)
1091{
1092 if (! handle)
1093 return GNUNET_SYSERR;
1094
1095 set_handle_name (handle, strlen (name) > 0 ? name : NULL);
1097 return GNUNET_YES;
1098}
1099
1100
1101static const struct GNUNET_CRYPTO_PublicKey*
1103{
1104 if (0 == GNUNET_memcmp (public_key, get_anonymous_public_key ()))
1105 return NULL;
1106
1107 return public_key;
1108}
1109
1110
1111const struct GNUNET_CRYPTO_PublicKey*
1113{
1114 if (! handle)
1115 return NULL;
1116
1118}
1119
1120
1121static enum GNUNET_GenericReturnValue
1123 struct GNUNET_MESSENGER_Room *room,
1124 const struct GNUNET_MESSENGER_Contact *contact)
1125{
1126 const struct GNUNET_CRYPTO_PrivateKey *key;
1127 struct GNUNET_MESSENGER_Message *message;
1128
1129 GNUNET_assert ((cls) && (room));
1130
1131 key = cls;
1132
1133 message = create_message_key (key);
1134 if (! message)
1135 return GNUNET_NO;
1136
1137 enqueue_message_to_room (room, message, NULL);
1138 return GNUNET_YES;
1139}
1140
1141
1144 const struct GNUNET_CRYPTO_PrivateKey *key)
1145{
1146 if (! handle)
1147 return GNUNET_SYSERR;
1148
1149 if (! key)
1150 {
1152 set_handle_key (handle, NULL);
1153 return GNUNET_YES;
1154 }
1155
1157 return GNUNET_SYSERR;
1158
1159 {
1160 struct GNUNET_CRYPTO_PrivateKey priv;
1161 GNUNET_memcpy (&priv, key, sizeof (priv));
1162
1165 }
1166
1168 return GNUNET_YES;
1169}
1170
1171
1174 const struct GNUNET_HashCode *key)
1175{
1176 struct GNUNET_MESSENGER_Room *room;
1177
1178 if ((! handle) || (! key))
1179 return NULL;
1180
1182 if (! room)
1183 {
1184 room = create_room (handle, key);
1185
1187 room,
1189 {
1190 destroy_room (room);
1191 return NULL;
1192 }
1193 }
1194
1195 send_open_room (handle, room);
1196 return room;
1197}
1198
1199
1202 const struct GNUNET_PeerIdentity *door,
1203 const struct GNUNET_HashCode *key)
1204{
1205 struct GNUNET_MESSENGER_Room *room;
1206
1207 if ((! handle) || (! door) || (! key))
1208 return NULL;
1209
1211 if (! room)
1212 {
1213 room = create_room (handle, key);
1214
1216 room,
1218 {
1219 destroy_room (room);
1220 return NULL;
1221 }
1222 }
1223
1224 send_enter_room (handle, room, door);
1225 return room;
1226}
1227
1228
1229void
1231{
1232 struct GNUNET_MESSENGER_Message *message;
1233
1234 if (! room)
1235 return;
1236
1237 message = create_message_leave ();
1238
1239 if (! message)
1240 return;
1241
1242 enqueue_message_to_room (room, message, NULL);
1243}
1244
1245
1247{
1250 size_t counter;
1251 void *cls;
1252};
1253
1254static enum GNUNET_GenericReturnValue
1256 const struct GNUNET_HashCode *key,
1257 void *value)
1258{
1259 struct GNUNET_MESSENGER_RoomFind *find;
1260 struct GNUNET_MESSENGER_Room *room;
1261
1262 GNUNET_assert ((cls) && (value));
1263
1264 find = cls;
1265 room = value;
1266
1267 if ((find->counter > 0) && ((! find->contact) || (GNUNET_YES ==
1268 find_room_member (room,
1269 find->
1270 contact)))
1271 )
1272 {
1273 find->counter--;
1274
1275 if (! find->callback)
1276 return GNUNET_YES;
1277
1278 return find->callback (find->cls, room, find->contact);
1279 }
1280 else
1281 return GNUNET_NO;
1282}
1283
1284
1285int
1287 const struct GNUNET_MESSENGER_Contact *contact,
1289 void *cls)
1290{
1291 struct GNUNET_MESSENGER_RoomFind find;
1292
1293 if (! handle)
1294 return GNUNET_SYSERR;
1295
1296 find.contact = contact;
1297 find.callback = callback;
1298 find.counter = (contact? contact->rc : SIZE_MAX);
1299 find.cls = cls;
1300
1302 iterate_find_room, &find);
1303}
1304
1305
1306const struct GNUNET_HashCode*
1308{
1309 if (! room)
1310 return NULL;
1311
1312 return &(room->key);
1313}
1314
1315
1316const struct GNUNET_MESSENGER_Contact*
1318 const struct GNUNET_HashCode *hash)
1319{
1320 if ((! room) || (! hash))
1321 return NULL;
1322
1323 return get_room_sender (room, hash);
1324}
1325
1326
1327const struct GNUNET_MESSENGER_Contact*
1329 const struct GNUNET_HashCode *hash)
1330{
1331 if ((! room) || (! hash))
1332 return NULL;
1333
1334 return get_room_recipient (room, hash);
1335}
1336
1337
1338const char*
1340 GNUNET_MESSENGER_Contact *contact)
1341{
1342 if (! contact)
1343 return NULL;
1344
1345 return get_contact_name (contact);
1346}
1347
1348
1349const struct GNUNET_CRYPTO_PublicKey*
1351 GNUNET_MESSENGER_Contact *contact)
1352{
1353 if (! contact)
1354 return NULL;
1355
1356 return get_non_anonymous_key (get_contact_key (contact));
1357}
1358
1359
1360size_t
1362 GNUNET_MESSENGER_Contact *contact)
1363{
1364 if (! contact)
1365 return 0;
1366
1367 return get_contact_id (contact);
1368}
1369
1370
1371static void
1373 struct GNUNET_MESSENGER_Message *message,
1374 const struct GNUNET_CRYPTO_PublicKey *public_key)
1375{
1376 struct GNUNET_MESSENGER_Message *transcript;
1377 const struct GNUNET_CRYPTO_PublicKey *pubkey;
1378 const char *handle_name;
1379 char *original_name;
1380
1381 transcript = NULL;
1382
1383 if (GNUNET_MESSENGER_KIND_NAME != message->header.kind)
1384 goto skip_naming;
1385
1386 original_name = message->body.name.name;
1388 "Apply rule for using handle name in room: %s\n", GNUNET_h2s (
1389 &(room->key)));
1390
1391 handle_name = get_handle_name (room->handle);
1392
1393 if ((handle_name) && (GNUNET_YES == room->use_handle_name) &&
1394 ((! original_name) || (0 == strlen (original_name))))
1395 {
1396 if (original_name)
1397 GNUNET_free (original_name);
1398
1399 message->body.name.name = GNUNET_strdup (handle_name);
1400 }
1401
1402skip_naming:
1403 if (! public_key)
1404 goto skip_encryption;
1405
1407
1408 if (0 != GNUNET_memcmp (pubkey, public_key))
1409 transcript = transcribe_message (message, public_key);
1410
1411 if (GNUNET_YES != encrypt_message (message, public_key))
1412 {
1414 "Sending message aborted: Encryption failed!\n");
1415
1416 if (transcript)
1417 destroy_message (transcript);
1418
1419 destroy_message (message);
1420 return;
1421 }
1422
1423skip_encryption:
1424 enqueue_message_to_room (room, message, transcript);
1425}
1426
1427
1428void
1430 const struct GNUNET_MESSENGER_Message *message,
1431 const struct GNUNET_MESSENGER_Contact *contact)
1432{
1433 const struct GNUNET_CRYPTO_PublicKey *public_key;
1434
1435 if ((! room) || (! message))
1436 return;
1437
1438 switch (filter_message_sending (message))
1439 {
1440 case GNUNET_SYSERR:
1442 "Sending message aborted: This kind of message is reserved for the service!\n");
1443 return;
1444 case GNUNET_NO:
1446 "Sending message aborted: This kind of message could cause issues!\n");
1447 return;
1448 default:
1449 break;
1450 }
1451
1452 if (contact)
1453 {
1454 public_key = get_non_anonymous_key (
1455 get_contact_key (contact)
1456 );
1457
1458 if (! public_key)
1459 {
1461 "Sending message aborted: Invalid key!\n");
1462 return;
1463 }
1464 }
1465 else
1466 public_key = NULL;
1467
1468 send_message_to_room_with_key (room, copy_message (message), public_key);
1469}
1470
1471
1472void
1474 const struct GNUNET_HashCode *hash,
1475 const struct GNUNET_TIME_Relative delay)
1476{
1477 if ((! room) || (! hash))
1478 return;
1479
1480 delete_room_message (room, hash, delay);
1481}
1482
1483
1484const struct GNUNET_MESSENGER_Message*
1486 const struct GNUNET_HashCode *hash)
1487{
1488 const struct GNUNET_MESSENGER_Message *message;
1489
1490 if ((! room) || (! hash))
1491 return NULL;
1492
1493 message = get_room_message (room, hash);
1494
1495 if (! message)
1496 {
1498 struct GNUNET_MQ_Envelope *env;
1499
1500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request message (%s)!\n",
1501 GNUNET_h2s (hash));
1502
1504 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
1505 GNUNET_memcpy (&(msg->hash), hash, sizeof(*hash));
1506 GNUNET_MQ_send (room->handle->mq, env);
1507 }
1508
1509 return message;
1510}
1511
1512
1513int
1516 void *cls)
1517{
1518 if (! room)
1519 return GNUNET_SYSERR;
1520
1521 return iterate_room_members (room, callback, cls);
1522}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static enum GNUNET_GenericReturnValue recv_message(void *cls, const struct GNUNET_MessageHeader *msg)
We have received a full message, pass to the MQ dispatcher.
Definition: client.c:335
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
struct GNUNET_HashCode key
The key used in the DHT.
static pa_context * context
Pulseaudio context.
static char * name
Name (label) of the records to list.
static struct GNUNET_CRYPTO_PublicKey pubkey
Public key of the zone to look in.
static int reset
Reset argument.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
static char * value
Value of the record to add/remove.
static struct GNUNET_NSE_FloodMessage next_message
Message for the next round, if we got any.
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition: gnunet-vpn.c:35
commonly used definitions; globals in this file are exempt from the rule that the module name ("commo...
reclaim service; implements identity and personal data sharing for GNUnet
Functions related to time.
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:1060
void GNUNET_CRYPTO_private_key_clear(struct GNUNET_CRYPTO_PrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_pkey.c:47
int GNUNET_CONTAINER_multihashmap_iterate(struct GNUNET_CONTAINER_MultiHashMap *map, GNUNET_CONTAINER_MultiHashMapIteratorCallback 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.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multishortmap_put(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_put(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
void * GNUNET_CONTAINER_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.
int GNUNET_CONTAINER_multishortmap_remove(struct GNUNET_CONTAINER_MultiShortmap *map, const struct GNUNET_ShortHashCode *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
ssize_t GNUNET_CRYPTO_public_key_get_length(const struct GNUNET_CRYPTO_PublicKey *key)
Get the compacted length of a GNUNET_CRYPTO_PublicKey.
Definition: crypto_pkey.c:85
#define GNUNET_log(kind,...)
char * GNUNET_CRYPTO_public_key_to_string(const struct GNUNET_CRYPTO_PublicKey *key)
Creates a (Base32) string representation of the public key.
Definition: crypto_pkey.c:379
ssize_t GNUNET_CRYPTO_write_public_key_to_buffer(const struct GNUNET_CRYPTO_PublicKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_PublicKey to a compact buffer.
Definition: crypto_pkey.c:128
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public(const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: crypto_pkey.c:430
ssize_t GNUNET_CRYPTO_private_key_get_length(const struct GNUNET_CRYPTO_PrivateKey *key)
Get the compacted length of a GNUNET_CRYPTO_PrivateKey.
Definition: crypto_pkey.c:64
#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_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_SCHEDULER_PRIORITY_HIGH
Run with high priority (important requests).
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
const char * GNUNET_h2s_full(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MESSENGER_delete_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay)
Delete a message identified by its hash from a room.
struct GNUNET_MESSENGER_Room * GNUNET_MESSENGER_open_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Open a room to send and receive messages.
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...
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...
const struct GNUNET_HashCode * GNUNET_MESSENGER_room_get_key(const struct GNUNET_MESSENGER_Room *room)
Get the key of a given room.
GNUNET_MESSENGER_MessageKind
Enum for the different supported kinds of messages.
const struct GNUNET_MESSENGER_Contact * GNUNET_MESSENGER_get_recipient(const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
Get the contact of a member in a room which has been targeted as recipient of a specific message iden...
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
Definition: messenger_api.c:44
GNUNET_MESSENGER_MessageFlags
Enum for the different supported flags used by message handling.
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.
void(* GNUNET_MESSENGER_MessageCallback)(void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *sender, const struct GNUNET_MESSENGER_Contact *recipient, 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.
const char * GNUNET_MESSENGER_contact_get_name(const struct GNUNET_MESSENGER_Contact *contact)
Get the name used by the contact.
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.
struct GNUNET_MESSENGER_Handle * GNUNET_MESSENGER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *name, const struct GNUNET_CRYPTO_PrivateKey *key, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls)
Set up a handle for the messenger related functions and connects to all necessary services.
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.
const struct GNUNET_CRYPTO_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.
void GNUNET_MESSENGER_disconnect(struct GNUNET_MESSENGER_Handle *handle)
Disconnect all of the messengers used services and clears up its used memory.
enum GNUNET_GenericReturnValue GNUNET_MESSENGER_set_key(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_CRYPTO_PrivateKey *key)
Set the private key used by the messenger or NULL if the anonymous key should be used instead.
size_t GNUNET_MESSENGER_contact_get_id(const struct GNUNET_MESSENGER_Contact *contact)
Get the locally unique id of the contact.
#define GNUNET_MESSENGER_SERVICE_NAME
Identifier of GNUnet MESSENGER Service.
enum GNUNET_GenericReturnValue(* 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.
const char * GNUNET_MESSENGER_get_name(const struct GNUNET_MESSENGER_Handle *handle)
Get the name (if specified, otherwise NULL) used by the messenger.
enum GNUNET_GenericReturnValue GNUNET_MESSENGER_set_name(struct GNUNET_MESSENGER_Handle *handle, const char *name)
Set the name for the messenger handle and sends messages renaming your contact in currently open room...
void GNUNET_MESSENGER_close_room(struct GNUNET_MESSENGER_Room *room)
Close a room which was entered, opened or both in various order and variety.
const struct GNUNET_CRYPTO_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.
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.
@ 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_TAG
The tag 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_SUBSCRIBE
The subscribe kind.
@ GNUNET_MESSENGER_KIND_TALK
The talk kind.
@ GNUNET_MESSENGER_KIND_PEER
The peer kind.
@ GNUNET_MESSENGER_KIND_UNKNOWN
The unknown kind.
@ GNUNET_MESSENGER_KIND_TRANSCRIPT
The transcript kind.
@ GNUNET_MESSENGER_KIND_KEY
The key kind.
@ GNUNET_MESSENGER_KIND_TEXT
The text kind.
@ GNUNET_MESSENGER_KIND_JOIN
The join kind.
@ GNUNET_MESSENGER_KIND_DELETE
The delete kind.
@ GNUNET_MESSENGER_KIND_CONNECTION
The connection kind.
@ GNUNET_MESSENGER_KIND_TICKET
The ticket kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
@ GNUNET_MESSENGER_KIND_ID
The id kind.
@ GNUNET_MESSENGER_FLAG_SUBSCRIPTION_KEEP_ALIVE
The keep alive flag.
@ GNUNET_MESSENGER_FLAG_SUBSCRIPTION_UNSUBSCRIBE
The unsubscribe 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:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#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:61
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:655
#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:700
void GNUNET_PEER_resolve(GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
Convert an interned PID to a normal peer identity.
Definition: peer.c:220
#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_ROOM_SYNC
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_GET_MESSAGE
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_DESTROY
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_CLOSE
#define GNUNET_MESSAGE_TYPE_MESSENGER_CONNECTION_MEMBER_ID
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_ENTRY
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
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:1277
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed_with_priority(struct GNUNET_TIME_Relative delay, enum GNUNET_SCHEDULER_Priority priority, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1207
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_with_priority(enum GNUNET_SCHEDULER_Priority prio, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified priority.
Definition: scheduler.c:1231
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:630
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply_double(struct GNUNET_TIME_Relative rel, double factor)
Multiply relative time by a given factor.
Definition: time.c:506
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:640
#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 callback_leave_message_sent(void *cls)
static void keep_subscription_alive(void *cls)
static enum GNUNET_GenericReturnValue iterate_send_key_to_room(void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)
static void dequeue_message_from_room(void *cls)
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 enum GNUNET_GenericReturnValue iterate_close_room(void *cls, const struct GNUNET_HashCode *key, void *value)
static enum GNUNET_GenericReturnValue iterate_find_room(void *cls, const struct GNUNET_HashCode *key, void *value)
static void send_message_to_room(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PrivateKey *key, struct GNUNET_HashCode *hash)
static void dequeue_messages_from_room(struct GNUNET_MESSENGER_Room *room)
static enum GNUNET_GenericReturnValue check_recv_message(void *cls, const struct GNUNET_MESSENGER_RecvMessage *msg)
static void handle_room_open(void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
static void send_sync_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
static void send_message_to_room_with_key(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *public_key)
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 handle_room_sync(void *cls, const struct GNUNET_MESSENGER_RoomMessage *msg)
static const struct GNUNET_CRYPTO_PublicKey * get_non_anonymous_key(const struct GNUNET_CRYPTO_PublicKey *public_key)
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_discourse_subscription(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Message *message)
static enum GNUNET_GenericReturnValue iterate_send_name_to_room(void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)
static void handle_member_id(void *cls, const struct GNUNET_MESSENGER_MemberMessage *msg)
void enqueue_message_to_room(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_Message *transcript)
static void reconnect(struct GNUNET_MESSENGER_Handle *handle)
static enum GNUNET_GenericReturnValue iterate_reset_room(void *cls, const struct GNUNET_HashCode *key, void *value)
static void send_open_room(struct GNUNET_MESSENGER_Handle *handle, struct GNUNET_MESSENGER_Room *room)
static void handle_miss_message(void *cls, const struct GNUNET_MESSENGER_GetMessage *msg)
const struct GNUNET_CRYPTO_PublicKey * get_contact_key(const struct GNUNET_MESSENGER_Contact *contact)
Returns the public key of a given contact.
size_t get_contact_id(const struct GNUNET_MESSENGER_Contact *contact)
Returns the locally unique identifier 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.
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.
void open_handle_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Marks a room known to a handle identified by a given key as open.
struct GNUNET_MESSENGER_Handle * create_handle(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_MESSENGER_MessageCallback msg_callback, void *msg_cls)
Creates and allocates a new handle using a given configuration and a custom message callback with a g...
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.
void destroy_handle(struct GNUNET_MESSENGER_Handle *handle)
Destroys a handle and frees its memory fully from the client API.
struct GNUNET_MESSENGER_Room * get_handle_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Returns the room known to a handle identified by a given key.
void set_handle_key(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_CRYPTO_PrivateKey *key)
Sets the keypair of a given handle to the keypair of a specific private key.
void close_handle_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Destroys and so implicitly closes a room known to a handle identified by a given key.
void set_handle_name(struct GNUNET_MESSENGER_Handle *handle, const char *name)
Sets the name of a handle to a specific name.
const struct GNUNET_CRYPTO_PrivateKey * get_handle_key(const struct GNUNET_MESSENGER_Handle *handle)
Returns the private key of a given handle.
const struct GNUNET_CRYPTO_PublicKey * get_handle_pubkey(const struct GNUNET_MESSENGER_Handle *handle)
Returns the public key of a given handle.
void clear_list_tunnels(struct GNUNET_MESSENGER_ListTunnels *tunnels)
Clears the list of tunnels peer identities.
void encode_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, enum GNUNET_GenericReturnValue include_header)
Encodes a given message into a buffer of a maximal length in bytes.
void sign_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, char *buffer, const struct GNUNET_HashCode *hash, const struct GNUNET_CRYPTO_PrivateKey *key)
Signs the hash of a message with a given private key and writes the signature into the buffer as well...
enum GNUNET_GenericReturnValue encrypt_message(struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
Encrypts a message using a given public key and replaces its body and kind with the now private encry...
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
enum GNUNET_GenericReturnValue filter_message_sending(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message should be sent by a client.
const struct GNUNET_ShortHashCode * get_message_discourse(const struct GNUNET_MESSENGER_Message *message)
Returns the discourse hash of a message depending on its kind.
void hash_message(const struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, struct GNUNET_HashCode *hash)
Calculates a hash of a given buffer with a length in bytes from a message.
void destroy_message(struct GNUNET_MESSENGER_Message *message)
Destroys a message and frees its memory fully.
uint16_t get_message_kind_size(enum GNUNET_MESSENGER_MessageKind kind, enum GNUNET_GenericReturnValue include_header)
Returns the minimal size in bytes to encode a message of a specific kind.
struct GNUNET_MESSENGER_Message * transcribe_message(const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_CRYPTO_PublicKey *key)
Transcribes a message as a new transcript message using a given public key from the recipient of the ...
enum GNUNET_GenericReturnValue is_message_session_bound(const struct GNUNET_MESSENGER_Message *message)
Returns if the message should be bound to a member session.
uint16_t get_message_size(const struct GNUNET_MESSENGER_Message *message, enum GNUNET_GenericReturnValue include_header)
Returns the exact size in bytes to encode a given message.
enum GNUNET_GenericReturnValue decode_message(struct GNUNET_MESSENGER_Message *message, uint16_t length, const char *buffer, enum GNUNET_GenericReturnValue include_header, uint16_t *padding)
Decodes a message from a given buffer of a maximal length in bytes.
void cleanup_message(struct GNUNET_MESSENGER_Message *message)
Frees the messages body memory.
void process_message_control(struct GNUNET_MESSENGER_MessageControl *control, const struct GNUNET_HashCode *sender, const struct GNUNET_HashCode *context, const struct GNUNET_HashCode *hash, const struct GNUNET_MESSENGER_Message *message, enum GNUNET_MESSENGER_MessageFlags flags)
Processes a new message with its hash and regarding information about sender, context and message fla...
struct GNUNET_MESSENGER_Message * create_message_name(const char *name)
Creates and allocates a new name message containing the name to change to.
struct GNUNET_MESSENGER_Message * create_message_leave(void)
Creates and allocates a new leave message.
struct GNUNET_MESSENGER_Message * create_message_subscribe(const struct GNUNET_ShortHashCode *discourse, const struct GNUNET_TIME_Relative time, uint32_t flags)
Creates and allocates a new subscribe message for a subscription of a given discourse with a specific...
struct GNUNET_MESSENGER_Message * create_message_join(const struct GNUNET_CRYPTO_PrivateKey *key)
Creates and allocates a new join message containing the clients public key.
struct GNUNET_MESSENGER_Message * create_message_request(const struct GNUNET_HashCode *hash)
Creates and allocates a new request message containing the hash of a missing message.
struct GNUNET_MESSENGER_Message * create_message_key(const struct GNUNET_CRYPTO_PrivateKey *key)
Creates and allocates a new key message containing the public key to change to derived from its priva...
struct GNUNET_MESSENGER_Message * create_message_id(const struct GNUNET_ShortHashCode *unique_id)
Creates and allocates a new id message containing the unique member id to change to.
struct GNUNET_MESSENGER_Message * dequeue_from_messages(struct GNUNET_MESSENGER_QueueMessages *messages, struct GNUNET_CRYPTO_PrivateKey *sender, struct GNUNET_MESSENGER_Message **transcript)
Remove the message from the front of the queue and returns it.
void enqueue_to_messages(struct GNUNET_MESSENGER_QueueMessages *messages, const struct GNUNET_CRYPTO_PrivateKey *sender, struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_Message *transcript)
Adds a specific message to the end or the beginning of the queue depending on its priority.
enum GNUNET_GenericReturnValue 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...
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.
void set_room_sender_id(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_ShortHashCode *id)
Sets the member id of the room's sender to a specific id or NULL.
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.
void update_room_last_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
Updates the last message hash of a room for the client API so that new messages can point to the late...
void delete_room_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay)
Deletes a message with a given hash inside a room under a specific delay.
enum GNUNET_GenericReturnValue is_room_available(const struct GNUNET_MESSENGER_Room *room)
Checks whether a room is available to send messages.
const struct GNUNET_ShortHashCode * get_room_sender_id(const struct GNUNET_MESSENGER_Room *room)
Returns the member id of the room's sender.
void link_room_message(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash, const struct GNUNET_HashCode *other)
Links a message identified by its hash inside a given room with another message identified by its oth...
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...
void destroy_room(struct GNUNET_MESSENGER_Room *room)
Destroys a room and frees its memory fully from the client API.
struct GNUNET_MESSENGER_Contact * get_room_recipient(const struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash)
Returns a messages recipient locally stored from a map for a given hash in a room.
struct GNUNET_MESSENGER_Room * create_room(struct GNUNET_MESSENGER_Handle *handle, const struct GNUNET_HashCode *key)
Creates and allocates a new room for a handle with a given key for the client API.
const struct GNUNET_CRYPTO_PublicKey * get_anonymous_public_key(void)
Returns the public identity key of GNUNET_IDENTITY_ego_get_anonymous() without recalculating it every...
#define SIZE_MAX
Definition: platform.h:208
A private key for an identity as per LSD0001.
An identity key as per LSD0001.
uint32_t type
Type of signature.
A 512-bit hashcode.
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
struct GNUNET_MESSENGER_ListTunnel * next
struct GNUNET_MESSENGER_ListTunnel * head
Message to receive the current member id of a handle in room.
struct GNUNET_MESSENGER_MessageSubscribe subscribe
struct GNUNET_MESSENGER_MessageName name
struct GNUNET_MESSENGER_MessageTranscript transcript
struct GNUNET_HashCode previous
The hash of the previous message from the senders perspective.
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
struct GNUNET_CRYPTO_Signature signature
The signature of the senders private key.
struct GNUNET_TIME_AbsoluteNBO timestamp
The timestamp of the message.
struct GNUNET_ShortHashCode sender_id
The senders id inside of the room the message was sent in.
char * name
The new name which replaces the current senders name.
uint32_t flags
The flags about the subscription to a discourse.
struct GNUNET_TIME_RelativeNBO time
The time window of the subscription.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to subscribe.
struct GNUNET_HashCode hash
The hash of the original message.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
struct GNUNET_MESSENGER_QueueMessage * head
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_SCHEDULER_Task * task
struct GNUNET_MESSENGER_Message * message
struct GNUNET_MESSENGER_Room * room
struct GNUNET_CONTAINER_MultiShortmap * subscriptions
struct GNUNET_MESSENGER_Handle * handle
enum GNUNET_GenericReturnValue opened
enum GNUNET_GenericReturnValue wait_for_sync
struct GNUNET_MESSENGER_MessageControl * control
struct GNUNET_SCHEDULER_Task * queue_task
enum GNUNET_GenericReturnValue use_handle_name
struct GNUNET_MESSENGER_QueueMessages queue
struct GNUNET_MESSENGER_ListTunnels entries
struct GNUNET_HashCode key
struct GNUNET_HashCode last_message
Message to send something into a room.
Message handler for a specific message type.
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
Time for relative time used by GNUnet, in microseconds.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Definition: vpn_api.c:39
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Definition: vpn_api.c:44