GNUnet 0.21.1
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";
85 default:
86 return "UNKNOWN";
87 }
88}
89
90
93
94static void
97{
98 struct GNUNET_MESSENGER_Handle *handle = cls;
99
100 const struct GNUNET_HashCode *key = &(msg->key);
101 const struct GNUNET_HashCode *prev = &(msg->previous);
102
103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key));
104
106
108
109 if (! room)
110 return;
111
112 update_room_last_message (room, prev);
113
115}
116
117
118static void
120 const struct GNUNET_MESSENGER_RoomMessage *msg)
121{
122 struct GNUNET_MESSENGER_Handle *handle = cls;
123
124 const struct GNUNET_PeerIdentity *door = &(msg->door);
125 const struct GNUNET_HashCode *key = &(msg->key);
126 const struct GNUNET_HashCode *prev = &(msg->previous);
127
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entered room: %s\n", GNUNET_h2s (key));
129
131
133
134 if (! room)
135 return;
136
137 update_room_last_message (room, prev);
138
140}
141
142
143static void
145 const struct GNUNET_MESSENGER_RoomMessage *msg)
146{
147 struct GNUNET_MESSENGER_Handle *handle = cls;
148
149 const struct GNUNET_HashCode *key = &(msg->key);
150 const struct GNUNET_HashCode *prev = &(msg->previous);
151
153
154 if (room)
155 update_room_last_message (room, prev);
156
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Closed room: %s\n", GNUNET_h2s (key));
158
160}
161
162
163static void
165 const struct GNUNET_MESSENGER_RoomMessage *msg)
166{
167 struct GNUNET_MESSENGER_Handle *handle = cls;
168
169 const struct GNUNET_HashCode *key = &(msg->key);
170 const struct GNUNET_HashCode *prev = &(msg->previous);
171
173
174 if (! room)
175 return;
176
177 update_room_last_message (room, prev);
178
179 room->wait_for_sync = GNUNET_NO;
180
182}
183
184
185static void
187 struct GNUNET_MESSENGER_Message *message,
188 struct GNUNET_MESSENGER_Message *transcript);
189
190static void
193{
194 struct GNUNET_MESSENGER_Handle *handle = cls;
195
196 const struct GNUNET_HashCode *key = &(msg->key);
197 const struct GNUNET_ShortHashCode *id = &(msg->id);
198 const uint32_t reset = msg->reset;
199
200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Changed member id in room: %s\n",
201 GNUNET_h2s (key));
202
204
205 if (! room)
206 {
207 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Room is unknown to handle: %s\n",
208 GNUNET_h2s (key));
209 return;
210 }
211
212 struct GNUNET_MESSENGER_Message *message;
213 if ((! get_room_sender_id (room)) || (GNUNET_YES == reset))
214 {
215 set_room_sender_id (room, id);
217 }
218 else
219 message = create_message_id (id);
220
221 if (! message)
222 return;
223
224 enqueue_message_to_room (room, message, NULL);
225}
226
227
230 const struct GNUNET_MESSENGER_RecvMessage *msg)
231{
232 const uint16_t full_length = ntohs (msg->header.size);
233
234 if (full_length < sizeof(*msg))
235 {
237 "Receiving failed: Message invalid!\n");
238 return GNUNET_NO;
239 }
240
241 const uint16_t length = full_length - sizeof(*msg);
242 const char *buffer = ((const char*) msg) + sizeof(*msg);
243
244 struct GNUNET_MESSENGER_Message message;
245
247 GNUNET_YES))
248 {
250 "Receiving failed: Message too short!\n");
251 return GNUNET_NO;
252 }
253
254 if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL))
255 {
257 "Receiving failed: Message decoding failed!\n");
258 return GNUNET_NO;
259 }
260
261 cleanup_message (&message);
262 return GNUNET_OK;
263}
264
265
266static void
268 const struct GNUNET_MESSENGER_RecvMessage *msg)
269{
270 struct GNUNET_MESSENGER_Handle *handle = cls;
271
272 const struct GNUNET_HashCode *key = &(msg->key);
273 const struct GNUNET_HashCode *sender = &(msg->sender);
274 const struct GNUNET_HashCode *context = &(msg->context);
275 const struct GNUNET_HashCode *hash = &(msg->hash);
276
277 enum GNUNET_MESSENGER_MessageFlags flags = (
278 (enum GNUNET_MESSENGER_MessageFlags) (msg->flags));
279
280 const uint16_t length = ntohs (msg->header.size) - sizeof(*msg);
281 const char *buffer = ((const char*) msg) + sizeof(*msg);
282
283 struct GNUNET_MESSENGER_Message message;
284 decode_message (&message, length, buffer, GNUNET_YES, NULL);
285
286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n",
288
290
291 if (! room)
292 {
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n",
294 GNUNET_h2s (key));
295
296 goto skip_message;
297 }
298
300 "Raw contact from sender and context: (%s : %s)\n",
302
304 sender,
305 context,
306 hash,
307 &message,
308 flags);
309
310skip_message:
311 cleanup_message (&message);
312}
313
314
315static void
317 const struct GNUNET_MESSENGER_GetMessage *msg)
318{
319 struct GNUNET_MESSENGER_Handle *handle = cls;
320
321 const struct GNUNET_HashCode *key = &(msg->key);
322 const struct GNUNET_HashCode *hash = &(msg->hash);
323
324 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Missing message in room: %s\n",
325 GNUNET_h2s (hash));
326
328
329 if (! room)
330 {
332 "Miss in unknown room for this client: %s\n", GNUNET_h2s (key));
333 return;
334 }
335
336 if (! get_room_sender_id (room))
337 return;
338
339 struct GNUNET_MESSENGER_Message *message = create_message_request (hash);
340 if (! message)
341 return;
342
343 enqueue_message_to_room (room, message, NULL);
344}
345
346
347static void
349
350static void
352 struct GNUNET_MESSENGER_Room *room)
353{
355
357 struct GNUNET_MQ_Envelope *env;
358
360 "Open room (%s) by member using key: %s\n",
361 GNUNET_h2s (&(room->key)),
363
364 const ssize_t len = GNUNET_CRYPTO_public_key_get_length (key);
365
366 env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0,
368 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
369 GNUNET_memcpy (&(msg->previous), &(room->last_message),
370 sizeof(msg->previous));
371
372 char *msg_buffer = ((char*) msg) + sizeof(*msg);
373
374 if (len > 0)
376
378}
379
380
381static void
383 struct GNUNET_MESSENGER_Room *room,
384 const struct GNUNET_PeerIdentity *door)
385{
387
389 struct GNUNET_MQ_Envelope *env;
390
391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Enter room (%s) via door: %s (%s)\n",
392 GNUNET_h2s (&(room->key)),
393 GNUNET_i2s (door),
395
396 const ssize_t len = GNUNET_CRYPTO_public_key_get_length (key);
397
398 env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0,
400 GNUNET_memcpy (&(msg->door), door, sizeof(*door));
401 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
402 GNUNET_memcpy (&(msg->previous), &(room->last_message),
403 sizeof(msg->previous));
404
405 char *msg_buffer = ((char*) msg) + sizeof(*msg);
406
407 if (len > 0)
409
411}
412
413
414static void
416 struct GNUNET_MESSENGER_Room *room)
417{
419 struct GNUNET_MQ_Envelope *env;
420
421 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Close room (%s)!\n",
422 GNUNET_h2s (&(room->key)));
423
425
426 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
427 GNUNET_memcpy (&(msg->previous), &(room->last_message),
428 sizeof(msg->previous));
429
431}
432
433
434static void
436 struct GNUNET_MESSENGER_Room *room)
437{
439 struct GNUNET_MQ_Envelope *env;
440
442
443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sync room (%s)!\n",
444 GNUNET_h2s (&(room->key)));
445
447
448 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
449 GNUNET_memcpy (&(msg->previous), &(room->last_message),
450 sizeof(msg->previous));
451
453}
454
455
458 const struct GNUNET_HashCode *key,
459 void *value)
460{
461 struct GNUNET_MESSENGER_Handle *handle = cls;
462 struct GNUNET_MESSENGER_Room *room = value;
463
464 if (GNUNET_YES == room->opened)
465 send_open_room (handle, room);
466
467 struct GNUNET_MESSENGER_ListTunnel *entry = room->entries.head;
468
469 struct GNUNET_PeerIdentity door;
470
471 while (entry)
472 {
473 GNUNET_PEER_resolve (entry->peer, &door);
474
475 send_enter_room (handle, room, &door);
476
477 entry = entry->next;
478 }
479
480 return GNUNET_YES;
481}
482
483
484static void
486{
487 struct GNUNET_MESSENGER_Handle *handle = cls;
488
489 handle->reconnect_task = NULL;
490 handle->reconnect_time = GNUNET_TIME_STD_BACKOFF (handle->reconnect_time);
491
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnect messenger!\n");
493
495
497 handle);
498}
499
500
503 const struct GNUNET_HashCode *key,
504 void *value)
505{
506 struct GNUNET_MESSENGER_Handle *handle = cls;
507 struct GNUNET_MESSENGER_Room *room = value;
508
509 send_close_room (handle, room);
510
511 return GNUNET_YES;
512}
513
514
515static void
517 enum GNUNET_MQ_Error error)
518{
519 struct GNUNET_MESSENGER_Handle *handle = cls;
520
521 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MQ_Error: %u\n", error);
522
524 handle);
525
526 if (handle->mq)
527 {
529 handle->mq = NULL;
530 }
531
532 handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_time,
534 handle);
535}
536
537
538static void
540{
541 const struct GNUNET_MQ_MessageHandler handlers[] = {
543 member_id,
546 ),
548 room_open,
551 ),
553 room_entry,
556 ),
558 room_close,
561 ),
566 ),
568 miss_message,
571 ),
573 room_sync,
576 ),
578 };
579
583}
584
585
588 const char *name,
589 const struct GNUNET_CRYPTO_PrivateKey *key,
591 void *msg_cls)
592{
594 msg_cls);
595
597
598 if (handle->mq)
599 {
601
604
606 struct GNUNET_MQ_Envelope *env;
607
610 return handle;
611 }
612 else
613 {
615 return NULL;
616 }
617}
618
619
620void
622{
623 if (! handle)
624 return;
625
627 struct GNUNET_MQ_Envelope *env;
628
631
633}
634
635
636static void
638 struct GNUNET_MESSENGER_Message *message,
639 const struct GNUNET_CRYPTO_PrivateKey *key,
640 struct GNUNET_HashCode *hash)
641{
642 const struct GNUNET_ShortHashCode *sender_id = get_room_sender_id (room);
643
646
647 GNUNET_memcpy (&(message->header.sender_id), sender_id,
648 sizeof(message->header.sender_id));
649 GNUNET_memcpy (&(message->header.previous), &(room->last_message),
650 sizeof(message->header.previous));
651
652 message->header.signature.type = key->type;
653
654 const uint16_t msg_length = get_message_size (message, GNUNET_YES);
655
657 struct GNUNET_MQ_Envelope *env;
658
660 msg, msg_length,
662 );
663
664 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
665
666 char *msg_buffer = ((char*) msg) + sizeof(*msg);
667 encode_message (message, msg_length, msg_buffer, GNUNET_YES);
668
669 hash_message (message, msg_length, msg_buffer, hash);
670 sign_message (message, msg_length, msg_buffer, hash, key);
671
672 update_room_last_message (room, hash);
673
674 GNUNET_MQ_send (room->handle->mq, env);
675
677 send_close_room (room->handle, room);
678}
679
680
681static void
683 struct GNUNET_MESSENGER_Message *message,
684 struct GNUNET_MESSENGER_Message *transcript)
685{
686 GNUNET_assert ((room) && (message));
687
688 const struct GNUNET_CRYPTO_PrivateKey *key = get_handle_key (room->handle);
689 enum GNUNET_GenericReturnValue priority;
690
691 switch (message->header.kind)
692 {
694 priority = GNUNET_YES;
695 break;
696 default:
697 priority = GNUNET_NO;
698 break;
699 }
700
701 enqueue_to_messages (&(room->queue), key, message, transcript, priority);
702
703 if (GNUNET_YES != is_room_available (room))
704 return;
705
706 if (GNUNET_YES == is_message_session_bound (message))
707 send_sync_room (room->handle, room);
708 else if (GNUNET_YES != room->wait_for_sync)
710}
711
712
715{
716 if (GNUNET_YES != is_room_available (room))
717 return room->queue.head ? GNUNET_NO : GNUNET_YES;
718
719 struct GNUNET_MESSENGER_Message *message = NULL;
720 struct GNUNET_MESSENGER_Message *transcript = NULL;
723 struct GNUNET_HashCode hash, other;
724
725 do {
726 if (message)
727 destroy_message (message);
728
729 message = dequeue_from_messages (&(room->queue), &key, &transcript);
730
731 if (! message)
732 {
733 message = transcript;
734 continue;
735 }
736
737 send_message_to_room (room, message, &key, &hash);
738
739 if (! transcript)
740 continue;
741
742 GNUNET_memcpy (&(transcript->body.transcript.hash), &hash, sizeof(hash));
744
745 if (GNUNET_YES == encrypt_message (transcript, &pubkey))
746 {
747 send_message_to_room (room, transcript, &key, &other);
748
749 link_room_message (room, &hash, &other);
750 link_room_message (room, &other, &hash);
751 }
752 else
754 "Sending transcript aborted: Encryption failed!\n");
755
756 destroy_message (transcript);
757 } while (message);
758
759 return GNUNET_YES;
760}
761
762
763const char*
765{
766 if (! handle)
767 return NULL;
768
769 return get_handle_name (handle);
770}
771
772
775 struct GNUNET_MESSENGER_Room *room,
776 const struct GNUNET_MESSENGER_Contact *contact)
777{
778 const struct GNUNET_MESSENGER_Handle *handle = cls;
779
780 if (GNUNET_YES != room->use_handle_name)
781 return GNUNET_YES;
782
783 const char *name = get_handle_name (handle);
784
785 if (! name)
786 return GNUNET_YES;
787
789
790 if (! message)
791 return GNUNET_NO;
792
793 enqueue_message_to_room (room, message, NULL);
794 return GNUNET_YES;
795}
796
797
800 const char *name)
801{
802 if (! handle)
803 return GNUNET_SYSERR;
804
805 set_handle_name (handle, strlen (name) > 0 ? name : NULL);
807 return GNUNET_YES;
808}
809
810
811static const struct GNUNET_CRYPTO_PublicKey*
813{
814 if (0 == GNUNET_memcmp (public_key, get_anonymous_public_key ()))
815 return NULL;
816
817 return public_key;
818}
819
820
821const struct GNUNET_CRYPTO_PublicKey*
823{
824 if (! handle)
825 return NULL;
826
828}
829
830
833 struct GNUNET_MESSENGER_Room *room,
834 const struct GNUNET_MESSENGER_Contact *contact)
835{
836 const struct GNUNET_CRYPTO_PrivateKey *key = cls;
837
839
840 if (! message)
841 return GNUNET_NO;
842
843 enqueue_message_to_room (room, message, NULL);
844 return GNUNET_YES;
845}
846
847
850 const struct GNUNET_CRYPTO_PrivateKey *key)
851{
852 if (! handle)
853 return GNUNET_SYSERR;
854
855 if (! key)
856 {
858 set_handle_key (handle, NULL);
859 return GNUNET_YES;
860 }
861
863 return GNUNET_SYSERR;
864
865 struct GNUNET_CRYPTO_PrivateKey priv;
866 GNUNET_memcpy (&priv, key, sizeof (priv));
867
869 set_handle_key (handle, &priv);
870 return GNUNET_YES;
871}
872
873
876 const struct GNUNET_HashCode *key)
877{
878 if ((! handle) || (! key))
879 return NULL;
880
882 handle->rooms, key);
883
884 if (! room)
885 {
886 room = create_room (handle, key);
887
889 room,
891 {
892 destroy_room (room);
893 return NULL;
894 }
895 }
896
897 send_open_room (handle, room);
898 return room;
899}
900
901
904 const struct GNUNET_PeerIdentity *door,
905 const struct GNUNET_HashCode *key)
906{
907 if ((! handle) || (! door) || (! key))
908 return NULL;
909
911 handle->rooms, key);
912
913 if (! room)
914 {
915 room = create_room (handle, key);
916
918 room,
920 {
921 destroy_room (room);
922 return NULL;
923 }
924 }
925
926 send_enter_room (handle, room, door);
927 return room;
928}
929
930
931void
933{
934 if (! room)
935 return;
936
938
939 if (message)
940 enqueue_message_to_room (room, message, NULL);
941}
942
943
945{
948 size_t counter;
949 void *cls;
950};
951
954 const struct GNUNET_HashCode *key,
955 void *value)
956{
957 struct GNUNET_MESSENGER_RoomFind *find = cls;
958 struct GNUNET_MESSENGER_Room *room = value;
959
960 if ((find->counter > 0) && ((! find->contact) || (GNUNET_YES ==
961 find_room_member (room,
962 find->
963 contact))))
964 {
965 find->counter--;
966
967 if (! find->callback)
968 return GNUNET_YES;
969
970 return find->callback (find->cls, room, find->contact);
971 }
972 else
973 return GNUNET_NO;
974}
975
976
977int
979 const struct GNUNET_MESSENGER_Contact *contact,
981 void *cls)
982{
983 if (! handle)
984 return GNUNET_SYSERR;
985
986 struct GNUNET_MESSENGER_RoomFind find;
987
988 find.contact = contact;
989 find.callback = callback;
990 find.counter = (contact? contact->rc : SIZE_MAX);
991 find.cls = cls;
992
994 iterate_find_room, &find);
995}
996
997
998const struct GNUNET_HashCode*
1000{
1001 if (! room)
1002 return NULL;
1003
1004 return &(room->key);
1005}
1006
1007
1008const struct GNUNET_MESSENGER_Contact*
1010 const struct GNUNET_HashCode *hash)
1011{
1012 if ((! room) || (! hash))
1013 return NULL;
1014
1015 return get_room_sender (room, hash);
1016}
1017
1018
1019const struct GNUNET_MESSENGER_Contact*
1021 const struct GNUNET_HashCode *hash)
1022{
1023 if ((! room) || (! hash))
1024 return NULL;
1025
1026 return get_room_recipient (room, hash);
1027}
1028
1029
1030const char*
1032 GNUNET_MESSENGER_Contact *contact)
1033{
1034 if (! contact)
1035 return NULL;
1036
1037 return get_contact_name (contact);
1038}
1039
1040
1041const struct GNUNET_CRYPTO_PublicKey*
1043 GNUNET_MESSENGER_Contact *contact)
1044{
1045 if (! contact)
1046 return NULL;
1047
1048 return get_non_anonymous_key (get_contact_key (contact));
1049}
1050
1051
1052size_t
1054 GNUNET_MESSENGER_Contact *contact)
1055{
1056 if (! contact)
1057 return 0;
1058
1059 return get_contact_id (contact);
1060}
1061
1062
1063static void
1065 struct GNUNET_MESSENGER_Message *message,
1066 const struct GNUNET_CRYPTO_PublicKey *public_key)
1067{
1068 struct GNUNET_MESSENGER_Message *transcript = NULL;
1069 const struct GNUNET_CRYPTO_PublicKey *pubkey;
1070
1071 char *original_name;
1072
1073 if (GNUNET_MESSENGER_KIND_NAME != message->header.kind)
1074 goto skip_naming;
1075
1076 original_name = message->body.name.name;
1078 "Apply rule for using handle name in room: %s\n", GNUNET_h2s (
1079 &(room->key)));
1080
1081 const char *handle_name = get_handle_name (room->handle);
1082
1083 if ((handle_name) && (GNUNET_YES == room->use_handle_name) &&
1084 ((! original_name) || (0 == strlen (original_name))))
1085 {
1086 if (original_name)
1087 GNUNET_free (original_name);
1088
1089 message->body.name.name = GNUNET_strdup (handle_name);
1090 }
1091
1092skip_naming:
1093 if (! public_key)
1094 goto skip_encryption;
1095
1097
1098 if (0 != GNUNET_memcmp (pubkey, public_key))
1099 transcript = transcribe_message (message, public_key);
1100
1101 if (GNUNET_YES != encrypt_message (message, public_key))
1102 {
1104 "Sending message aborted: Encryption failed!\n");
1105
1106 if (transcript)
1107 destroy_message (transcript);
1108
1109 destroy_message (message);
1110 return;
1111 }
1112
1113skip_encryption:
1114 enqueue_message_to_room (room, message, transcript);
1115}
1116
1117
1118void
1120 const struct GNUNET_MESSENGER_Message *message,
1121 const struct GNUNET_MESSENGER_Contact *contact)
1122{
1123 if ((! room) || (! message))
1124 return;
1125
1126 switch (filter_message_sending (message))
1127 {
1128 case GNUNET_SYSERR:
1130 "Sending message aborted: This kind of message is reserved for the service!\n");
1131 return;
1132 case GNUNET_NO:
1134 "Sending message aborted: This kind of message could cause issues!\n");
1135 return;
1136 default:
1137 break;
1138 }
1139
1140 const struct GNUNET_CRYPTO_PublicKey *public_key;
1141
1142 if (contact)
1143 {
1144 public_key = get_non_anonymous_key (
1145 get_contact_key (contact)
1146 );
1147
1148 if (! public_key)
1149 {
1151 "Sending message aborted: Invalid key!\n");
1152 return;
1153 }
1154 }
1155 else
1156 public_key = NULL;
1157
1158 send_message_to_room_with_key (room, copy_message (message), public_key);
1159}
1160
1161
1162void
1164 const struct GNUNET_HashCode *hash,
1165 const struct GNUNET_TIME_Relative delay)
1166{
1167 struct GNUNET_MESSENGER_Message *message = create_message_delete (hash,
1168 delay);
1169
1170 if (! message)
1171 {
1173 "Sending deletion aborted: Message creation failed!\n");
1174 return;
1175 }
1176
1177 send_message_to_room_with_key (room, message, NULL);
1178}
1179
1180
1181void
1183 const struct GNUNET_HashCode *hash,
1184 const struct GNUNET_TIME_Relative delay)
1185{
1186 if ((! room) || (! hash))
1187 return;
1188
1189 delete_message_in_room (room, hash, delay);
1190}
1191
1192
1193const struct GNUNET_MESSENGER_Message*
1195 const struct GNUNET_HashCode *hash)
1196{
1197 if ((! room) || (! hash))
1198 return NULL;
1199
1200 const struct GNUNET_MESSENGER_Message *message = get_room_message (room,
1201 hash);
1202
1203 if (! message)
1204 {
1206 struct GNUNET_MQ_Envelope *env;
1207
1209 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
1210 GNUNET_memcpy (&(msg->hash), hash, sizeof(*hash));
1211 GNUNET_MQ_send (room->handle->mq, env);
1212 }
1213
1214 return message;
1215}
1216
1217
1218int
1221 void *cls)
1222{
1223 if (! room)
1224 return GNUNET_SYSERR;
1225
1226 return iterate_room_members (room, callback, cls);
1227}
1228
1229
1231{
1234};
1235
1236
1237static enum GNUNET_GenericReturnValue
1239 struct GNUNET_MESSENGER_Room *room,
1240 const struct GNUNET_MESSENGER_Contact *contact)
1241{
1242 struct GNUNET_MESSENGER_CheckTicket *check = cls;
1243
1244 const struct GNUNET_CRYPTO_PublicKey *key;
1246
1247 if ((key) && (0 == GNUNET_memcmp (key, check->audience)))
1248 {
1249 check->result = GNUNET_YES;
1250 return GNUNET_NO;
1251 }
1252
1253 return GNUNET_YES;
1254}
1255
1256
1257void
1259 const struct GNUNET_RECLAIM_Ticket *ticket)
1260{
1261 if ((! room) || (! ticket))
1262 return;
1263
1264 const struct GNUNET_CRYPTO_PublicKey *pubkey;
1266
1267 if (0 != GNUNET_memcmp (pubkey, &(ticket->identity)))
1268 {
1270 "Sending ticket aborted: Invalid identity!\n");
1271 return;
1272 }
1273
1274 struct GNUNET_MESSENGER_CheckTicket check;
1275 check.audience = &(ticket->audience);
1276 check.result = GNUNET_NO;
1277
1278 const int members = iterate_room_members (
1279 room,
1281 &check);
1282
1283 if ((! members) || (GNUNET_YES != check.result))
1284 {
1286 "Sending ticket aborted: Audience not found!\n");
1287 return;
1288 }
1289
1291 &(ticket->rnd)
1292 );
1293
1294 if (! message)
1295 {
1297 "Sending ticket aborted: Message creation failed!\n");
1298 return;
1299 }
1300
1301 send_message_to_room_with_key (room, message, &(ticket->audience));
1302}
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:109
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 char * value
Value of the record to add/remove.
static struct GNUNET_RECLAIM_Ticket ticket
Ticket to consume.
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:1057
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_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.
@ 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:68
#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:551
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:602
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:47
#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.
@ 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_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.
void GNUNET_MESSENGER_send_ticket(struct GNUNET_MESSENGER_Room *room, const struct GNUNET_RECLAIM_Ticket *ticket)
Send a ticket into a 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_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_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:304
#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)
#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:683
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
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:1278
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:638
#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 enum GNUNET_GenericReturnValue iterate_send_key_to_room(void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)
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 check_ticket_audience(void *cls, struct GNUNET_MESSENGER_Room *room, const struct GNUNET_MESSENGER_Contact *contact)
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 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:95
static enum GNUNET_GenericReturnValue dequeue_messages_from_room(struct GNUNET_MESSENGER_Room *room)
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 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)
static void reconnect(struct GNUNET_MESSENGER_Handle *handle)
static void enqueue_message_to_room(struct GNUNET_MESSENGER_Room *room, struct GNUNET_MESSENGER_Message *message, struct GNUNET_MESSENGER_Message *transcript)
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 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.
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_ticket(const struct GNUNET_RECLAIM_Identifier *identifier)
Creates and allocates a new ticket message containing the identifier of a ticket to exchange it with ...
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, enum GNUNET_GenericReturnValue priority)
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.
const struct GNUNET_CRYPTO_PublicKey * audience
enum GNUNET_GenericReturnValue result
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_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.
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_MESSENGER_Handle * handle
enum GNUNET_GenericReturnValue opened
enum GNUNET_GenericReturnValue wait_for_sync
struct GNUNET_MESSENGER_MessageControl * control
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.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
The identity of the host (wraps the signing key of the peer).
The authorization ticket.
struct GNUNET_CRYPTO_PublicKey audience
The ticket audience (= relying party)
struct GNUNET_RECLAIM_Identifier rnd
The ticket random identifier.
struct GNUNET_CRYPTO_PublicKey identity
The ticket issuer (= the user)
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