GNUnet 0.22.0
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
30
32#include "gnunet_time_lib.h"
39#include "messenger_api_room.h"
40#include "messenger_api_util.h"
41
42const char*
44{
45 switch (kind)
46 {
48 return "INFO";
50 return "JOIN";
52 return "LEAVE";
54 return "NAME";
56 return "KEY";
58 return "PEER";
60 return "ID";
62 return "MISS";
64 return "MERGE";
66 return "REQUEST";
68 return "INVITE";
70 return "TEXT";
72 return "FILE";
74 return "PRIVATE";
76 return "DELETE";
78 return "CONNECTION";
80 return "TICKET";
82 return "TRANSCRIPT";
84 return "TAG";
86 return "SUBSCRIBE";
88 return "TALK";
89 default:
90 return "UNKNOWN";
91 }
92}
93
94
95static void
97
98static void
100 const struct GNUNET_MESSENGER_RoomMessage *msg)
101{
103 const struct GNUNET_HashCode *key;
104 const struct GNUNET_HashCode *prev;
105 struct GNUNET_MESSENGER_Room *room;
106
107 GNUNET_assert ((cls) && (msg));
108
109 handle = cls;
110
111 key = &(msg->key);
112 prev = &(msg->previous);
113
114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key));
115
117
118 room = get_handle_room (handle, key);
119 if (! room)
120 return;
121
122 update_room_last_message (room, prev);
124}
125
126
127static void
129 const struct GNUNET_MESSENGER_RoomMessage *msg)
130{
132 const struct GNUNET_PeerIdentity *door;
133 const struct GNUNET_HashCode *key;
134 const struct GNUNET_HashCode *prev;
135 struct GNUNET_MESSENGER_Room *room;
136
137 GNUNET_assert ((cls) && (msg));
138
139 handle = cls;
140
141 door = &(msg->door);
142 key = &(msg->key);
143 prev = &(msg->previous);
144
145 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entered room: %s\n", GNUNET_h2s (key));
146
148
149 room = get_handle_room (handle, key);
150 if (! room)
151 return;
152
153 update_room_last_message (room, prev);
155}
156
157
158static void
160 const struct GNUNET_MESSENGER_RoomMessage *msg)
161{
163 const struct GNUNET_HashCode *key;
164 const struct GNUNET_HashCode *prev;
165 struct GNUNET_MESSENGER_Room *room;
166
167 GNUNET_assert ((cls) && (msg));
168
169 handle = cls;
170
171 key = &(msg->key);
172 prev = &(msg->previous);
173
174 room = get_handle_room (handle, key);
175 if (room)
176 update_room_last_message (room, prev);
177
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Closed room: %s\n", GNUNET_h2s (key));
179
181}
182
183
184static void
186 const struct GNUNET_MESSENGER_RoomMessage *msg)
187{
189 const struct GNUNET_HashCode *key;
190 const struct GNUNET_HashCode *prev;
191 struct GNUNET_MESSENGER_Room *room;
192
193 GNUNET_assert ((cls) && (msg));
194
195 handle = cls;
196
197 key = &(msg->key);
198 prev = &(msg->previous);
199
200 room = get_handle_room (handle, key);
201 if (! room)
202 return;
203
204 update_room_last_message (room, prev);
205
206 room->wait_for_sync = GNUNET_NO;
208}
209
210
211void
213 struct GNUNET_MESSENGER_Message *message,
214 struct GNUNET_MESSENGER_Message *transcript);
215
216static void
219{
221 const struct GNUNET_HashCode *key;
222 const struct GNUNET_ShortHashCode *id;
223 struct GNUNET_MESSENGER_Room *room;
224 struct GNUNET_MESSENGER_Message *message;
225 uint32_t reset;
226
227 GNUNET_assert ((cls) && (msg));
228
229 handle = cls;
230
231 key = &(msg->key);
232 id = &(msg->id);
233 reset = msg->reset;
234
235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Changed member id in room: %s\n",
236 GNUNET_h2s (key));
237
238 room = get_handle_room (handle, key);
239 if (! room)
240 {
241 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Room is unknown to handle: %s\n",
242 GNUNET_h2s (key));
243 return;
244 }
245
246 if ((! get_room_sender_id (room)) || (GNUNET_YES == reset))
247 {
248 set_room_sender_id (room, id);
250 }
251 else
252 message = create_message_id (id);
253
254 if (! message)
255 return;
256
257 enqueue_message_to_room (room, message, NULL);
258}
259
260
263 const struct GNUNET_MESSENGER_RecvMessage *msg)
264{
265 struct GNUNET_MESSENGER_Message message;
266 uint16_t full_length, length;
267 const char *buffer;
268
270
271 full_length = ntohs (msg->header.size);
272
273 if (full_length < sizeof(*msg))
274 {
276 "Receiving failed: Message invalid!\n");
277 return GNUNET_NO;
278 }
279
280 length = full_length - sizeof(*msg);
281 buffer = ((const char*) msg) + sizeof(*msg);
282
284 GNUNET_YES))
285 {
287 "Receiving failed: Message too short!\n");
288 return GNUNET_NO;
289 }
290
291 if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL))
292 {
294 "Receiving failed: Message decoding failed!\n");
295 return GNUNET_NO;
296 }
297
298 cleanup_message (&message);
299 return GNUNET_OK;
300}
301
302
303static void
305 const struct GNUNET_MESSENGER_RecvMessage *msg)
306{
308 const struct GNUNET_HashCode *key;
309 const struct GNUNET_HashCode *sender;
310 const struct GNUNET_HashCode *context;
311 const struct GNUNET_HashCode *hash;
313 struct GNUNET_MESSENGER_Message message;
314 struct GNUNET_MESSENGER_Room *room;
315 uint16_t length;
316 const char *buffer;
317
318 GNUNET_assert ((cls) && (msg));
319
320 handle = cls;
321
322 key = &(msg->key);
323 sender = &(msg->sender);
324 context = &(msg->context);
325 hash = &(msg->hash);
326
327 flags = (enum GNUNET_MESSENGER_MessageFlags) (msg->flags);
328
329 length = ntohs (msg->header.size) - sizeof(*msg);
330 buffer = ((const char*) msg) + sizeof(*msg);
331
332 decode_message (&message, length, buffer, GNUNET_YES, NULL);
333
334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n",
336
337 room = get_handle_room (handle, key);
338 if (! room)
339 {
340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n",
341 GNUNET_h2s (key));
342
343 goto skip_message;
344 }
345
347 "Raw contact from sender and context: (%s : %s)\n",
349
351 sender,
352 context,
353 hash,
354 &message,
355 flags);
356
357skip_message:
358 cleanup_message (&message);
359}
360
361
362static void
364 const struct GNUNET_MESSENGER_GetMessage *msg)
365{
367 const struct GNUNET_HashCode *key;
368 const struct GNUNET_HashCode *hash;
369 struct GNUNET_MESSENGER_Room *room;
370
371 GNUNET_assert ((cls) && (msg));
372
373 handle = cls;
374
375 key = &(msg->key);
376 hash = &(msg->hash);
377
378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Missing message in room: %s\n",
379 GNUNET_h2s (hash));
380
381 room = get_handle_room (handle, key);
382 if (! room)
383 {
385 "Miss in unknown room for this client: %s\n", GNUNET_h2s (key));
386 return;
387 }
388
389 if (! get_room_sender_id (room))
390 return;
391
392 {
393 struct GNUNET_MESSENGER_Message *message;
394
395 message = create_message_request (hash);
396 if (! message)
397 return;
398
399 enqueue_message_to_room (room, message, NULL);
400 }
401}
402
403
404static void
406
407static void
409 struct GNUNET_MESSENGER_Room *room)
410{
411 const struct GNUNET_CRYPTO_PublicKey *key;
413 struct GNUNET_MQ_Envelope *env;
414 char *msg_buffer;
415 ssize_t len;
416
417 GNUNET_assert ((handle) && (handle->mq) && (room));
418
420
422 "Open room (%s) by member using key: %s\n",
423 GNUNET_h2s (&(room->key)),
425
427
428 env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0,
430 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
431 GNUNET_memcpy (&(msg->previous), &(room->last_message),
432 sizeof(msg->previous));
433
434 msg_buffer = ((char*) msg) + sizeof(*msg);
435
436 if (len > 0)
438
440}
441
442
443static void
445 struct GNUNET_MESSENGER_Room *room,
446 const struct GNUNET_PeerIdentity *door)
447{
448 const struct GNUNET_CRYPTO_PublicKey *key;
450 struct GNUNET_MQ_Envelope *env;
451 char *msg_buffer;
452 ssize_t len;
453
454 GNUNET_assert ((handle) && (handle->mq) && (room) && (door));
455
457
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Enter room (%s) via door: %s (%s)\n",
459 GNUNET_h2s (&(room->key)),
460 GNUNET_i2s (door),
462
464
465 env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0,
467 GNUNET_memcpy (&(msg->door), door, sizeof(*door));
468 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
469 GNUNET_memcpy (&(msg->previous), &(room->last_message),
470 sizeof(msg->previous));
471
472 msg_buffer = ((char*) msg) + sizeof(*msg);
473
474 if (len > 0)
476
478}
479
480
481static void
483 struct GNUNET_MESSENGER_Room *room)
484{
486 struct GNUNET_MQ_Envelope *env;
487
488 GNUNET_assert ((handle) && (handle->mq) && (room));
489
490 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Close room (%s)!\n",
491 GNUNET_h2s (&(room->key)));
492
494
495 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
496 GNUNET_memcpy (&(msg->previous), &(room->last_message),
497 sizeof(msg->previous));
498
500}
501
502
503static void
505 struct GNUNET_MESSENGER_Room *room)
506{
508 struct GNUNET_MQ_Envelope *env;
509
510 GNUNET_assert ((handle) && (handle->mq) && (room));
511
513
514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sync room (%s)!\n",
515 GNUNET_h2s (&(room->key)));
516
518
519 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
520 GNUNET_memcpy (&(msg->previous), &(room->last_message),
521 sizeof(msg->previous));
522
524}
525
526
529 const struct GNUNET_HashCode *key,
530 void *value)
531{
533 struct GNUNET_MESSENGER_Room *room;
534 struct GNUNET_MESSENGER_ListTunnel *entry;
535
536 GNUNET_assert ((cls) && (value));
537
538 handle = cls;
539 room = value;
540
541 if (GNUNET_YES == room->opened)
542 send_open_room (handle, room);
543
544 entry = room->entries.head;
545 while (entry)
546 {
547 struct GNUNET_PeerIdentity door;
548
549 GNUNET_PEER_resolve (entry->peer, &door);
550 send_enter_room (handle, room, &door);
551
552 entry = entry->next;
553 }
554
555 return GNUNET_YES;
556}
557
558
559static void
561{
563
564 GNUNET_assert (cls);
565
566 handle = cls;
567
568 handle->reconnect_task = NULL;
569 handle->reconnect_time = GNUNET_TIME_STD_BACKOFF (handle->reconnect_time);
570
571 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnect messenger!\n");
572
574
576 handle);
577}
578
579
582 const struct GNUNET_HashCode *key,
583 void *value)
584{
586 struct GNUNET_MESSENGER_Room *room;
587
588 GNUNET_assert ((cls) && (value));
589
590 handle = cls;
591 room = value;
592
593 send_close_room (handle, room);
594
595 return GNUNET_YES;
596}
597
598
599static void
601 enum GNUNET_MQ_Error error)
602{
604
605 GNUNET_assert (cls);
606
607 handle = cls;
608
609 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MQ_Error: %u\n", error);
610
612 handle);
613
614 if (handle->mq)
615 {
617 handle->mq = NULL;
618 }
619
620 handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_time,
622 handle);
623}
624
625
626static void
628{
630
631 {
632 const struct GNUNET_MQ_MessageHandler handlers[] = {
634 member_id,
637 ),
639 room_open,
642 ),
644 room_entry,
647 ),
649 room_close,
652 ),
657 ),
659 miss_message,
662 ),
664 room_sync,
667 ),
669 };
670
674 handle);
675 }
676}
677
678
681 const char *name,
682 const struct GNUNET_CRYPTO_PrivateKey *key,
684 void *msg_cls)
685{
687
689
691
693
694 if (handle->mq)
695 {
697 struct GNUNET_MQ_Envelope *env;
698
700
703
704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connect handle!\n");
705
708 return handle;
709 }
710 else
711 {
713 return NULL;
714 }
715}
716
717
718void
720{
722 struct GNUNET_MQ_Envelope *env;
723
724 if (! handle)
725 return;
726
727 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect handle!\n");
728
731
733}
734
735
736static void
738{
739 struct GNUNET_MESSENGER_Room *room;
740
741 GNUNET_assert (cls);
742
743 room = cls;
744
745 room->opened = GNUNET_NO;
746 clear_list_tunnels (&(room->entries));
747
748 send_close_room (room->handle, room);
749}
750
751
752static void
754{
755 struct GNUNET_MESSENGER_RoomSubscription *subscription;
756 struct GNUNET_MESSENGER_Room *room;
757 struct GNUNET_MESSENGER_Message *message;
758 const struct GNUNET_ShortHashCode *discourse;
759
760 GNUNET_assert (cls);
761
762 subscription = cls;
763 subscription->task = NULL;
764
765 room = subscription->room;
766 message = subscription->message;
767
768 subscription->message = NULL;
769
770 discourse = &(message->body.subscribe.discourse);
771
773 discourse,
774 subscription))
775 {
776 destroy_message (message);
777 return;
778 }
779
780 GNUNET_free (subscription);
781
782 enqueue_message_to_room (room, message, NULL);
783}
784
785
786static void
788 struct GNUNET_MESSENGER_Message *message)
789{
790 const struct GNUNET_ShortHashCode *discourse;
791 struct GNUNET_MESSENGER_RoomSubscription *subscription;
792 struct GNUNET_TIME_Relative time;
793 uint32_t flags;
794
795 GNUNET_assert ((room) && (message));
796
797 flags = message->body.subscribe.flags;
798
799 discourse = &(message->body.subscribe.discourse);
800
802 discourse);
803
805 goto active_subscription;
806
807 if (! subscription)
808 return;
809
810 if (subscription->task)
811 GNUNET_SCHEDULER_cancel (subscription->task);
812
813 if (subscription->message)
814 destroy_message (subscription->message);
815
817 discourse,
818 subscription))
819 {
820 subscription->task = NULL;
821 subscription->message = NULL;
822 return;
823 }
824
825 GNUNET_free (subscription);
826 return;
827
828active_subscription:
830 return;
831
833
834 if (! subscription)
835 {
836 subscription = GNUNET_new (struct GNUNET_MESSENGER_RoomSubscription);
837
839 room->subscriptions, discourse, subscription,
841 {
842 GNUNET_free (subscription);
843 return;
844 }
845
846 subscription->room = room;
847 }
848 else
849 {
850 if (subscription->task)
851 GNUNET_SCHEDULER_cancel (subscription->task);
852
853 if (subscription->message)
854 destroy_message (subscription->message);
855 }
856
857 subscription->message = create_message_subscribe (discourse, time,
858 flags);
859
860 if (! subscription->message)
861 {
862 subscription->task = NULL;
863 return;
864 }
865
866 {
867 struct GNUNET_TIME_Relative delay;
868 delay = GNUNET_TIME_relative_multiply_double (time, 0.9);
869
872 keep_subscription_alive, subscription);
873 }
874}
875
876
877static void
879 struct GNUNET_MESSENGER_Message *message,
880 const struct GNUNET_CRYPTO_PrivateKey *key,
881 struct GNUNET_HashCode *hash)
882{
883 const struct GNUNET_ShortHashCode *sender_id;
885 struct GNUNET_MQ_Envelope *env;
886 uint16_t msg_length;
887 char *msg_buffer;
888
889 GNUNET_assert ((room) && (message) && (key) && (hash));
890
891 sender_id = get_room_sender_id (room);
892
895
896 GNUNET_memcpy (&(message->header.sender_id), sender_id,
897 sizeof(message->header.sender_id));
898 GNUNET_memcpy (&(message->header.previous), &(room->last_message),
899 sizeof(message->header.previous));
900
901 message->header.signature.type = key->type;
902
903 msg_length = get_message_size (message, GNUNET_YES);
904
906 msg, msg_length,
908 );
909
910 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
911
912 msg_buffer = ((char*) msg) + sizeof(*msg);
913 encode_message (message, msg_length, msg_buffer, GNUNET_YES);
914
915 hash_message (message, msg_length, msg_buffer, hash);
916 sign_message (message, msg_length, msg_buffer, hash, key);
917
918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send message (%s)!\n",
919 GNUNET_h2s (hash));
920
921 if (! get_message_discourse (message))
922 update_room_last_message (room, hash);
923
924 switch (message->header.kind)
925 {
928 break;
930 handle_discourse_subscription (room, message);
931 break;
932 default:
933 break;
934 }
935
936 GNUNET_MQ_send (room->handle->mq, env);
937}
938
939
940void
942 struct GNUNET_MESSENGER_Message *message,
943 struct GNUNET_MESSENGER_Message *transcript)
944{
945 const struct GNUNET_CRYPTO_PrivateKey *key;
946
947 GNUNET_assert ((room) && (message));
948
949 key = get_handle_key (room->handle);
950
951 enqueue_to_messages (&(room->queue), key, message, transcript);
952
953 if (GNUNET_YES != is_room_available (room))
954 return;
955
956 if (GNUNET_YES == is_message_session_bound (message))
957 send_sync_room (room->handle, room);
958 else if (GNUNET_YES != room->wait_for_sync)
960}
961
962
963static void
965{
966 struct GNUNET_MESSENGER_Room *room;
967 struct GNUNET_MESSENGER_Message *message;
968 struct GNUNET_MESSENGER_Message *transcript;
970 struct GNUNET_HashCode hash;
972
973 GNUNET_assert (cls);
974
975 room = cls;
976
977 GNUNET_assert (room->handle);
978
979 room->queue_task = NULL;
980
981 if ((GNUNET_YES != is_room_available (room)) || (!(room->handle->mq)))
982 goto next_message;
983
984 message = NULL;
985 transcript = NULL;
986 memset (&key, 0, sizeof(key));
987
988 message = dequeue_from_messages (&(room->queue), &key, &transcript);
989
990 if (! message)
991 {
992 if (transcript)
993 destroy_message (transcript);
994
995 return;
996 }
997
998 send_message_to_room (room, message, &key, &hash);
999
1000 if (! transcript)
1001 {
1003 goto next_message;
1004 }
1005
1006 GNUNET_memcpy (&(transcript->body.transcript.hash), &hash, sizeof(hash));
1007
1008 memset (&pubkey, 0, sizeof(pubkey));
1010
1011 if (GNUNET_YES == encrypt_message (transcript, &pubkey))
1012 {
1013 struct GNUNET_HashCode other;
1014 send_message_to_room (room, transcript, &key, &other);
1015
1017
1018 link_room_message (room, &hash, &other);
1019 link_room_message (room, &other, &hash);
1020 }
1021 else
1023 "Sending transcript aborted: Encryption failed!\n");
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 struct GNUNET_MESSENGER_Message *message;
1478
1479 GNUNET_assert ((room) && (hash));
1480
1481 message = create_message_delete (hash, delay);
1482
1483 if (! message)
1484 {
1486 "Sending deletion aborted: Message creation failed!\n");
1487 return;
1488 }
1489
1490 enqueue_message_to_room (room, message, NULL);
1491}
1492
1493
1494void
1496 const struct GNUNET_HashCode *hash,
1497 const struct GNUNET_TIME_Relative delay)
1498{
1499 if ((! room) || (! hash))
1500 return;
1501
1502 delete_message_in_room (room, hash, delay);
1503}
1504
1505
1506const struct GNUNET_MESSENGER_Message*
1508 const struct GNUNET_HashCode *hash)
1509{
1510 const struct GNUNET_MESSENGER_Message *message;
1511
1512 if ((! room) || (! hash))
1513 return NULL;
1514
1515 message = get_room_message (room, hash);
1516
1517 if (! message)
1518 {
1520 struct GNUNET_MQ_Envelope *env;
1521
1522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request message (%s)!\n",
1523 GNUNET_h2s (hash));
1524
1526 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
1527 GNUNET_memcpy (&(msg->hash), hash, sizeof(*hash));
1528 GNUNET_MQ_send (room->handle->mq, env);
1529 }
1530
1531 return message;
1532}
1533
1534
1535int
1538 void *cls)
1539{
1540 if (! room)
1541 return GNUNET_SYSERR;
1542
1543 return iterate_room_members (room, callback, cls);
1544}
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:43
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:63
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#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:979
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:1276
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:1206
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:1230
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)
Definition: messenger_api.c:99
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)
void delete_message_in_room(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay)
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_delete(const struct GNUNET_HashCode *hash, const struct GNUNET_TIME_Relative delay)
Creates and allocates a new delete message containing the hash of a message to delete after a specifi...
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_leave()
Creates and allocates a new leave 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...
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()
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