GNUnet 0.21.2
messenger_api.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2024 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
26#include "gnunet_common.h"
28
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{
102 struct GNUNET_MESSENGER_Handle *handle = cls;
103
104 const struct GNUNET_HashCode *key = &(msg->key);
105 const struct GNUNET_HashCode *prev = &(msg->previous);
106
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opened room: %s\n", GNUNET_h2s (key));
108
110
112
113 if (! room)
114 return;
115
116 update_room_last_message (room, prev);
117
119}
120
121
122static void
124 const struct GNUNET_MESSENGER_RoomMessage *msg)
125{
126 struct GNUNET_MESSENGER_Handle *handle = cls;
127
128 const struct GNUNET_PeerIdentity *door = &(msg->door);
129 const struct GNUNET_HashCode *key = &(msg->key);
130 const struct GNUNET_HashCode *prev = &(msg->previous);
131
132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entered room: %s\n", GNUNET_h2s (key));
133
135
137
138 if (! room)
139 return;
140
141 update_room_last_message (room, prev);
142
144}
145
146
147static void
149 const struct GNUNET_MESSENGER_RoomMessage *msg)
150{
151 struct GNUNET_MESSENGER_Handle *handle = cls;
152
153 const struct GNUNET_HashCode *key = &(msg->key);
154 const struct GNUNET_HashCode *prev = &(msg->previous);
155
157
158 if (room)
159 update_room_last_message (room, prev);
160
161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Closed room: %s\n", GNUNET_h2s (key));
162
164}
165
166
167static void
169 const struct GNUNET_MESSENGER_RoomMessage *msg)
170{
171 struct GNUNET_MESSENGER_Handle *handle = cls;
172
173 const struct GNUNET_HashCode *key = &(msg->key);
174 const struct GNUNET_HashCode *prev = &(msg->previous);
175
177
178 if (! room)
179 return;
180
181 update_room_last_message (room, prev);
182
183 room->wait_for_sync = GNUNET_NO;
184
186}
187
188
189void
191 struct GNUNET_MESSENGER_Message *message,
192 struct GNUNET_MESSENGER_Message *transcript);
193
194static void
197{
198 struct GNUNET_MESSENGER_Handle *handle = cls;
199
200 const struct GNUNET_HashCode *key = &(msg->key);
201 const struct GNUNET_ShortHashCode *id = &(msg->id);
202 const uint32_t reset = msg->reset;
203
204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Changed member id in room: %s\n",
205 GNUNET_h2s (key));
206
208
209 if (! room)
210 {
211 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Room is unknown to handle: %s\n",
212 GNUNET_h2s (key));
213 return;
214 }
215
216 struct GNUNET_MESSENGER_Message *message;
217 if ((! get_room_sender_id (room)) || (GNUNET_YES == reset))
218 {
219 set_room_sender_id (room, id);
221 }
222 else
223 message = create_message_id (id);
224
225 if (! message)
226 return;
227
228 enqueue_message_to_room (room, message, NULL);
229}
230
231
234 const struct GNUNET_MESSENGER_RecvMessage *msg)
235{
236 const uint16_t full_length = ntohs (msg->header.size);
237
238 if (full_length < sizeof(*msg))
239 {
241 "Receiving failed: Message invalid!\n");
242 return GNUNET_NO;
243 }
244
245 const uint16_t length = full_length - sizeof(*msg);
246 const char *buffer = ((const char*) msg) + sizeof(*msg);
247
248 struct GNUNET_MESSENGER_Message message;
249
251 GNUNET_YES))
252 {
254 "Receiving failed: Message too short!\n");
255 return GNUNET_NO;
256 }
257
258 if (GNUNET_YES != decode_message (&message, length, buffer, GNUNET_YES, NULL))
259 {
261 "Receiving failed: Message decoding failed!\n");
262 return GNUNET_NO;
263 }
264
265 cleanup_message (&message);
266 return GNUNET_OK;
267}
268
269
270static void
272 const struct GNUNET_MESSENGER_RecvMessage *msg)
273{
274 struct GNUNET_MESSENGER_Handle *handle = cls;
275
276 const struct GNUNET_HashCode *key = &(msg->key);
277 const struct GNUNET_HashCode *sender = &(msg->sender);
278 const struct GNUNET_HashCode *context = &(msg->context);
279 const struct GNUNET_HashCode *hash = &(msg->hash);
280
281 enum GNUNET_MESSENGER_MessageFlags flags = (
282 (enum GNUNET_MESSENGER_MessageFlags) (msg->flags));
283
284 const uint16_t length = ntohs (msg->header.size) - sizeof(*msg);
285 const char *buffer = ((const char*) msg) + sizeof(*msg);
286
287 struct GNUNET_MESSENGER_Message message;
288 decode_message (&message, length, buffer, GNUNET_YES, NULL);
289
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receiving message: %s\n",
292
294
295 if (! room)
296 {
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Unknown room for this client: %s\n",
298 GNUNET_h2s (key));
299
300 goto skip_message;
301 }
302
304 "Raw contact from sender and context: (%s : %s)\n",
306
308 sender,
309 context,
310 hash,
311 &message,
312 flags);
313
314skip_message:
315 cleanup_message (&message);
316}
317
318
319static void
321 const struct GNUNET_MESSENGER_GetMessage *msg)
322{
323 struct GNUNET_MESSENGER_Handle *handle = cls;
324
325 const struct GNUNET_HashCode *key = &(msg->key);
326 const struct GNUNET_HashCode *hash = &(msg->hash);
327
328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Missing message in room: %s\n",
329 GNUNET_h2s (hash));
330
332
333 if (! room)
334 {
336 "Miss in unknown room for this client: %s\n", GNUNET_h2s (key));
337 return;
338 }
339
340 if (! get_room_sender_id (room))
341 return;
342
343 struct GNUNET_MESSENGER_Message *message = create_message_request (hash);
344 if (! message)
345 return;
346
347 enqueue_message_to_room (room, message, NULL);
348}
349
350
351static void
353
354static void
356 struct GNUNET_MESSENGER_Room *room)
357{
358 GNUNET_assert ((handle) && (handle->mq) && (room));
359
361
363 struct GNUNET_MQ_Envelope *env;
364
366 "Open room (%s) by member using key: %s\n",
367 GNUNET_h2s (&(room->key)),
369
370 const ssize_t len = GNUNET_CRYPTO_public_key_get_length (key);
371
372 env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0,
374 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
375 GNUNET_memcpy (&(msg->previous), &(room->last_message),
376 sizeof(msg->previous));
377
378 char *msg_buffer = ((char*) msg) + sizeof(*msg);
379
380 if (len > 0)
382
384}
385
386
387static void
389 struct GNUNET_MESSENGER_Room *room,
390 const struct GNUNET_PeerIdentity *door)
391{
392 GNUNET_assert ((handle) && (handle->mq) && (room) && (door));
393
395
397 struct GNUNET_MQ_Envelope *env;
398
399 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Enter room (%s) via door: %s (%s)\n",
400 GNUNET_h2s (&(room->key)),
401 GNUNET_i2s (door),
403
404 const ssize_t len = GNUNET_CRYPTO_public_key_get_length (key);
405
406 env = GNUNET_MQ_msg_extra (msg, len > 0 ? len : 0,
408 GNUNET_memcpy (&(msg->door), door, sizeof(*door));
409 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
410 GNUNET_memcpy (&(msg->previous), &(room->last_message),
411 sizeof(msg->previous));
412
413 char *msg_buffer = ((char*) msg) + sizeof(*msg);
414
415 if (len > 0)
417
419}
420
421
422static void
424 struct GNUNET_MESSENGER_Room *room)
425{
426 GNUNET_assert ((handle) && (handle->mq) && (room));
427
429 struct GNUNET_MQ_Envelope *env;
430
431 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Close room (%s)!\n",
432 GNUNET_h2s (&(room->key)));
433
435
436 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
437 GNUNET_memcpy (&(msg->previous), &(room->last_message),
438 sizeof(msg->previous));
439
441}
442
443
444static void
446 struct GNUNET_MESSENGER_Room *room)
447{
448 GNUNET_assert ((handle) && (handle->mq) && (room));
449
451 struct GNUNET_MQ_Envelope *env;
452
454
455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sync room (%s)!\n",
456 GNUNET_h2s (&(room->key)));
457
459
460 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
461 GNUNET_memcpy (&(msg->previous), &(room->last_message),
462 sizeof(msg->previous));
463
465}
466
467
470 const struct GNUNET_HashCode *key,
471 void *value)
472{
473 struct GNUNET_MESSENGER_Handle *handle = cls;
474 struct GNUNET_MESSENGER_Room *room = value;
475
476 if (GNUNET_YES == room->opened)
477 send_open_room (handle, room);
478
479 struct GNUNET_MESSENGER_ListTunnel *entry = room->entries.head;
480
481 struct GNUNET_PeerIdentity door;
482
483 while (entry)
484 {
485 GNUNET_PEER_resolve (entry->peer, &door);
486
487 send_enter_room (handle, room, &door);
488
489 entry = entry->next;
490 }
491
492 return GNUNET_YES;
493}
494
495
496static void
498{
499 struct GNUNET_MESSENGER_Handle *handle = cls;
500
501 handle->reconnect_task = NULL;
502 handle->reconnect_time = GNUNET_TIME_STD_BACKOFF (handle->reconnect_time);
503
504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Reconnect messenger!\n");
505
507
509 handle);
510}
511
512
515 const struct GNUNET_HashCode *key,
516 void *value)
517{
518 struct GNUNET_MESSENGER_Handle *handle = cls;
519 struct GNUNET_MESSENGER_Room *room = value;
520
521 send_close_room (handle, room);
522
523 return GNUNET_YES;
524}
525
526
527static void
529 enum GNUNET_MQ_Error error)
530{
531 struct GNUNET_MESSENGER_Handle *handle = cls;
532
533 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MQ_Error: %u\n", error);
534
536 handle);
537
538 if (handle->mq)
539 {
541 handle->mq = NULL;
542 }
543
544 handle->reconnect_task = GNUNET_SCHEDULER_add_delayed (handle->reconnect_time,
546 handle);
547}
548
549
550static void
552{
553 const struct GNUNET_MQ_MessageHandler handlers[] = {
555 member_id,
558 ),
560 room_open,
563 ),
565 room_entry,
568 ),
570 room_close,
573 ),
578 ),
580 miss_message,
583 ),
585 room_sync,
588 ),
590 };
591
595}
596
597
600 const char *name,
601 const struct GNUNET_CRYPTO_PrivateKey *key,
603 void *msg_cls)
604{
606 msg_cls);
607
609
610 if (handle->mq)
611 {
613
616
617 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Connect handle!\n");
618
620 struct GNUNET_MQ_Envelope *env;
621
624 return handle;
625 }
626 else
627 {
629 return NULL;
630 }
631}
632
633
634void
636{
637 if (! handle)
638 return;
639
640 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnect handle!\n");
641
643 struct GNUNET_MQ_Envelope *env;
644
647
649}
650
651
652static void
654{
655 GNUNET_assert (cls);
656
657 struct GNUNET_MESSENGER_Room *room = cls;
658
659 room->opened = GNUNET_NO;
660 clear_list_tunnels (&(room->entries));
661
662 send_close_room (room->handle, room);
663}
664
665
666static void
668{
669 GNUNET_assert (cls);
670
671 struct GNUNET_MESSENGER_RoomSubscription *subscription = cls;
672
673 subscription->task = NULL;
674
675 struct GNUNET_MESSENGER_Room *room = subscription->room;
676 struct GNUNET_MESSENGER_Message *message = subscription->message;
677
678 subscription->message = NULL;
679
680 const struct GNUNET_ShortHashCode *discourse =
681 &(message->body.subscribe.discourse);
682
684 discourse,
685 subscription))
686 {
687 destroy_message (message);
688 return;
689 }
690
691 GNUNET_free (subscription);
692
693 enqueue_message_to_room (room, message, NULL);
694}
695
696
697static void
699 struct GNUNET_MESSENGER_Message *message)
700{
701 GNUNET_assert ((room) && (message));
702
703 const uint32_t flags = message->body.subscribe.flags;
704
705 const struct GNUNET_ShortHashCode *discourse =
706 &(message->body.subscribe.discourse);
707
708 struct GNUNET_MESSENGER_RoomSubscription *subscription =
710
712 goto active_subscription;
713
714 if (! subscription)
715 return;
716
717 if (subscription->task)
718 GNUNET_SCHEDULER_cancel (subscription->task);
719
720 if (subscription->message)
721 destroy_message (subscription->message);
722
724 discourse,
725 subscription))
726 {
727 subscription->task = NULL;
728 subscription->message = NULL;
729 return;
730 }
731
732 GNUNET_free (subscription);
733 return;
734
735active_subscription:
737 return;
738
739 struct GNUNET_TIME_Relative time =
741
742 if (! subscription)
743 {
744 subscription = GNUNET_new (struct GNUNET_MESSENGER_RoomSubscription);
745
747 room->subscriptions, discourse, subscription,
749 {
750 GNUNET_free (subscription);
751 return;
752 }
753
754 subscription->room = room;
755 }
756 else
757 {
758 if (subscription->task)
759 GNUNET_SCHEDULER_cancel (subscription->task);
760
761 if (subscription->message)
762 destroy_message (subscription->message);
763 }
764
765 subscription->message = create_message_subscribe (discourse, time,
766 flags);
767
768 if (! subscription->message)
769 {
770 subscription->task = NULL;
771 return;
772 }
773
775 time, 0.9);
776
779 keep_subscription_alive, subscription);
780}
781
782
783static void
785 struct GNUNET_MESSENGER_Message *message,
786 const struct GNUNET_CRYPTO_PrivateKey *key,
787 struct GNUNET_HashCode *hash)
788{
789 GNUNET_assert ((room) && (message) && (key) && (hash));
790
791 const struct GNUNET_ShortHashCode *sender_id = get_room_sender_id (room);
792
795
796 GNUNET_memcpy (&(message->header.sender_id), sender_id,
797 sizeof(message->header.sender_id));
798 GNUNET_memcpy (&(message->header.previous), &(room->last_message),
799 sizeof(message->header.previous));
800
801 message->header.signature.type = key->type;
802
803 const uint16_t msg_length = get_message_size (message, GNUNET_YES);
804
806 struct GNUNET_MQ_Envelope *env;
807
809 msg, msg_length,
811 );
812
813 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
814
815 char *msg_buffer = ((char*) msg) + sizeof(*msg);
816 encode_message (message, msg_length, msg_buffer, GNUNET_YES);
817
818 hash_message (message, msg_length, msg_buffer, hash);
819 sign_message (message, msg_length, msg_buffer, hash, key);
820
821 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Send message (%s)!\n",
822 GNUNET_h2s (hash));
823
824 if (! get_message_discourse (message))
825 update_room_last_message (room, hash);
826
827 switch (message->header.kind)
828 {
831 break;
833 handle_discourse_subscription (room, message);
834 break;
835 default:
836 break;
837 }
838
839 GNUNET_MQ_send (room->handle->mq, env);
840}
841
842
843void
845 struct GNUNET_MESSENGER_Message *message,
846 struct GNUNET_MESSENGER_Message *transcript)
847{
848 GNUNET_assert ((room) && (message));
849
850 const struct GNUNET_CRYPTO_PrivateKey *key = get_handle_key (room->handle);
851
852 enqueue_to_messages (&(room->queue), key, message, transcript);
853
854 if (GNUNET_YES != is_room_available (room))
855 return;
856
857 if (GNUNET_YES == is_message_session_bound (message))
858 send_sync_room (room->handle, room);
859 else if (GNUNET_YES != room->wait_for_sync)
861}
862
863
864static void
866{
867 struct GNUNET_MESSENGER_Room *room = cls;
868
869 GNUNET_assert ((room) && (room->handle));
870
871 room->queue_task = NULL;
872
873 if ((GNUNET_YES != is_room_available (room)) || (!(room->handle->mq)))
874 goto next_message;
875
876 struct GNUNET_MESSENGER_Message *message = NULL;
877 struct GNUNET_MESSENGER_Message *transcript = NULL;
878
880 memset (&key, 0, sizeof(key));
881
882 message = dequeue_from_messages (&(room->queue), &key, &transcript);
883
884 if (! message)
885 {
886 if (transcript)
887 destroy_message (transcript);
888
889 return;
890 }
891
892 struct GNUNET_HashCode hash;
893 send_message_to_room (room, message, &key, &hash);
894
895 if (! transcript)
896 {
898 goto next_message;
899 }
900
901 GNUNET_memcpy (&(transcript->body.transcript.hash), &hash, sizeof(hash));
902
904 memset (&pubkey, 0, sizeof(pubkey));
906
907 if (GNUNET_YES == encrypt_message (transcript, &pubkey))
908 {
909 struct GNUNET_HashCode other;
910 send_message_to_room (room, transcript, &key, &other);
911
913
914 link_room_message (room, &hash, &other);
915 link_room_message (room, &other, &hash);
916 }
917 else
919 "Sending transcript aborted: Encryption failed!\n");
920
921 destroy_message (transcript);
922
924 if (! room->queue.head)
925 return;
926
929}
930
931static void
933{
934 if ((GNUNET_YES != is_room_available (room)) || (!(room->handle)))
935 return;
936
937 if (room->handle->mq)
939 else if (!(room->queue_task))
942}
943
944
945const char*
947{
948 if (! handle)
949 return NULL;
950
951 return get_handle_name (handle);
952}
953
954
957 struct GNUNET_MESSENGER_Room *room,
958 const struct GNUNET_MESSENGER_Contact *contact)
959{
960 const struct GNUNET_MESSENGER_Handle *handle = cls;
961
962 if (GNUNET_YES != room->use_handle_name)
963 return GNUNET_YES;
964
965 const char *name = get_handle_name (handle);
966
967 if (! name)
968 return GNUNET_YES;
969
971
972 if (! message)
973 return GNUNET_NO;
974
975 enqueue_message_to_room (room, message, NULL);
976 return GNUNET_YES;
977}
978
979
982 const char *name)
983{
984 if (! handle)
985 return GNUNET_SYSERR;
986
987 set_handle_name (handle, strlen (name) > 0 ? name : NULL);
989 return GNUNET_YES;
990}
991
992
993static const struct GNUNET_CRYPTO_PublicKey*
995{
996 if (0 == GNUNET_memcmp (public_key, get_anonymous_public_key ()))
997 return NULL;
998
999 return public_key;
1000}
1001
1002
1003const struct GNUNET_CRYPTO_PublicKey*
1005{
1006 if (! handle)
1007 return NULL;
1008
1010}
1011
1012
1013static enum GNUNET_GenericReturnValue
1015 struct GNUNET_MESSENGER_Room *room,
1016 const struct GNUNET_MESSENGER_Contact *contact)
1017{
1018 const struct GNUNET_CRYPTO_PrivateKey *key = cls;
1019
1021
1022 if (! message)
1023 return GNUNET_NO;
1024
1025 enqueue_message_to_room (room, message, NULL);
1026 return GNUNET_YES;
1027}
1028
1029
1032 const struct GNUNET_CRYPTO_PrivateKey *key)
1033{
1034 if (! handle)
1035 return GNUNET_SYSERR;
1036
1037 if (! key)
1038 {
1040 set_handle_key (handle, NULL);
1041 return GNUNET_YES;
1042 }
1043
1045 return GNUNET_SYSERR;
1046
1047 struct GNUNET_CRYPTO_PrivateKey priv;
1048 GNUNET_memcpy (&priv, key, sizeof (priv));
1049
1052
1054 return GNUNET_YES;
1055}
1056
1057
1060 const struct GNUNET_HashCode *key)
1061{
1062 if ((! handle) || (! key))
1063 return NULL;
1064
1066 handle->rooms, key);
1067
1068 if (! room)
1069 {
1070 room = create_room (handle, key);
1071
1073 room,
1075 {
1076 destroy_room (room);
1077 return NULL;
1078 }
1079 }
1080
1081 send_open_room (handle, room);
1082 return room;
1083}
1084
1085
1088 const struct GNUNET_PeerIdentity *door,
1089 const struct GNUNET_HashCode *key)
1090{
1091 if ((! handle) || (! door) || (! key))
1092 return NULL;
1093
1095 handle->rooms, key);
1096
1097 if (! room)
1098 {
1099 room = create_room (handle, key);
1100
1102 room,
1104 {
1105 destroy_room (room);
1106 return NULL;
1107 }
1108 }
1109
1110 send_enter_room (handle, room, door);
1111 return room;
1112}
1113
1114
1115void
1117{
1118 if (! room)
1119 return;
1120
1122
1123 if (! message)
1124 return;
1125
1126 enqueue_message_to_room (room, message, NULL);
1127}
1128
1129
1131{
1134 size_t counter;
1135 void *cls;
1136};
1137
1138static enum GNUNET_GenericReturnValue
1140 const struct GNUNET_HashCode *key,
1141 void *value)
1142{
1143 struct GNUNET_MESSENGER_RoomFind *find = cls;
1144 struct GNUNET_MESSENGER_Room *room = value;
1145
1146 if ((find->counter > 0) && ((! find->contact) || (GNUNET_YES ==
1147 find_room_member (room,
1148 find->
1149 contact)))
1150 )
1151 {
1152 find->counter--;
1153
1154 if (! find->callback)
1155 return GNUNET_YES;
1156
1157 return find->callback (find->cls, room, find->contact);
1158 }
1159 else
1160 return GNUNET_NO;
1161}
1162
1163
1164int
1166 const struct GNUNET_MESSENGER_Contact *contact,
1168 void *cls)
1169{
1170 if (! handle)
1171 return GNUNET_SYSERR;
1172
1173 struct GNUNET_MESSENGER_RoomFind find;
1174
1175 find.contact = contact;
1176 find.callback = callback;
1177 find.counter = (contact? contact->rc : SIZE_MAX);
1178 find.cls = cls;
1179
1181 iterate_find_room, &find);
1182}
1183
1184
1185const struct GNUNET_HashCode*
1187{
1188 if (! room)
1189 return NULL;
1190
1191 return &(room->key);
1192}
1193
1194
1195const struct GNUNET_MESSENGER_Contact*
1197 const struct GNUNET_HashCode *hash)
1198{
1199 if ((! room) || (! hash))
1200 return NULL;
1201
1202 return get_room_sender (room, hash);
1203}
1204
1205
1206const struct GNUNET_MESSENGER_Contact*
1208 const struct GNUNET_HashCode *hash)
1209{
1210 if ((! room) || (! hash))
1211 return NULL;
1212
1213 return get_room_recipient (room, hash);
1214}
1215
1216
1217const char*
1219 GNUNET_MESSENGER_Contact *contact)
1220{
1221 if (! contact)
1222 return NULL;
1223
1224 return get_contact_name (contact);
1225}
1226
1227
1228const struct GNUNET_CRYPTO_PublicKey*
1230 GNUNET_MESSENGER_Contact *contact)
1231{
1232 if (! contact)
1233 return NULL;
1234
1235 return get_non_anonymous_key (get_contact_key (contact));
1236}
1237
1238
1239size_t
1241 GNUNET_MESSENGER_Contact *contact)
1242{
1243 if (! contact)
1244 return 0;
1245
1246 return get_contact_id (contact);
1247}
1248
1249
1250static void
1252 struct GNUNET_MESSENGER_Message *message,
1253 const struct GNUNET_CRYPTO_PublicKey *public_key)
1254{
1255 struct GNUNET_MESSENGER_Message *transcript = NULL;
1256 const struct GNUNET_CRYPTO_PublicKey *pubkey;
1257
1258 char *original_name;
1259
1260 if (GNUNET_MESSENGER_KIND_NAME != message->header.kind)
1261 goto skip_naming;
1262
1263 original_name = message->body.name.name;
1265 "Apply rule for using handle name in room: %s\n", GNUNET_h2s (
1266 &(room->key)));
1267
1268 const char *handle_name = get_handle_name (room->handle);
1269
1270 if ((handle_name) && (GNUNET_YES == room->use_handle_name) &&
1271 ((! original_name) || (0 == strlen (original_name))))
1272 {
1273 if (original_name)
1274 GNUNET_free (original_name);
1275
1276 message->body.name.name = GNUNET_strdup (handle_name);
1277 }
1278
1279skip_naming:
1280 if (! public_key)
1281 goto skip_encryption;
1282
1284
1285 if (0 != GNUNET_memcmp (pubkey, public_key))
1286 transcript = transcribe_message (message, public_key);
1287
1288 if (GNUNET_YES != encrypt_message (message, public_key))
1289 {
1291 "Sending message aborted: Encryption failed!\n");
1292
1293 if (transcript)
1294 destroy_message (transcript);
1295
1296 destroy_message (message);
1297 return;
1298 }
1299
1300skip_encryption:
1301 enqueue_message_to_room (room, message, transcript);
1302}
1303
1304
1305void
1307 const struct GNUNET_MESSENGER_Message *message,
1308 const struct GNUNET_MESSENGER_Contact *contact)
1309{
1310 if ((! room) || (! message))
1311 return;
1312
1313 switch (filter_message_sending (message))
1314 {
1315 case GNUNET_SYSERR:
1317 "Sending message aborted: This kind of message is reserved for the service!\n");
1318 return;
1319 case GNUNET_NO:
1321 "Sending message aborted: This kind of message could cause issues!\n");
1322 return;
1323 default:
1324 break;
1325 }
1326
1327 const struct GNUNET_CRYPTO_PublicKey *public_key;
1328
1329 if (contact)
1330 {
1331 public_key = get_non_anonymous_key (
1332 get_contact_key (contact)
1333 );
1334
1335 if (! public_key)
1336 {
1338 "Sending message aborted: Invalid key!\n");
1339 return;
1340 }
1341 }
1342 else
1343 public_key = NULL;
1344
1345 send_message_to_room_with_key (room, copy_message (message), public_key);
1346}
1347
1348
1349void
1351 const struct GNUNET_HashCode *hash,
1352 const struct GNUNET_TIME_Relative delay)
1353{
1354 struct GNUNET_MESSENGER_Message *message = create_message_delete (hash,
1355 delay);
1356
1357 if (! message)
1358 {
1360 "Sending deletion aborted: Message creation failed!\n");
1361 return;
1362 }
1363
1364 enqueue_message_to_room (room, message, NULL);
1365}
1366
1367
1368void
1370 const struct GNUNET_HashCode *hash,
1371 const struct GNUNET_TIME_Relative delay)
1372{
1373 if ((! room) || (! hash))
1374 return;
1375
1376 delete_message_in_room (room, hash, delay);
1377}
1378
1379
1380const struct GNUNET_MESSENGER_Message*
1382 const struct GNUNET_HashCode *hash)
1383{
1384 if ((! room) || (! hash))
1385 return NULL;
1386
1387 const struct GNUNET_MESSENGER_Message *message = get_room_message (room,
1388 hash);
1389
1390 if (! message)
1391 {
1392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Request message (%s)!\n",
1393 GNUNET_h2s (hash));
1394
1396 struct GNUNET_MQ_Envelope *env;
1397
1399 GNUNET_memcpy (&(msg->key), &(room->key), sizeof(msg->key));
1400 GNUNET_memcpy (&(msg->hash), hash, sizeof(*hash));
1401 GNUNET_MQ_send (room->handle->mq, env);
1402 }
1403
1404 return message;
1405}
1406
1407
1408int
1411 void *cls)
1412{
1413 if (! room)
1414 return GNUNET_SYSERR;
1415
1416 return iterate_room_members (room, callback, cls);
1417}
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_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:1057
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:394
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:145
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:445
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:981
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_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:1208
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:1232
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:628
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:504
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 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