GNUnet 0.28.0-dev.3-7-g31e20e2e6
 
Loading...
Searching...
No Matches
gnunet-service-messenger_handle.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2020--2026 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 "platform.h"
28#include "gnunet_protocols.h"
29#include "gnunet_util_lib.h"
30
35
36#include "messenger_api_util.h"
37
43
46 struct GNUNET_MQ_Handle *mq)
47{
49
50 GNUNET_assert ((service) && (mq));
51
53
54 handle->service = service;
55 handle->mq = mq;
56
57 handle->key = NULL;
58
63
64 handle->notify = NULL;
65
66 return handle;
67}
68
69
72 const struct GNUNET_HashCode *key,
73 void *value)
74{
76
77 GNUNET_assert ((cls) && (key));
78
79 handle = cls;
80
82 return GNUNET_YES;
83}
84
85
88 const struct GNUNET_HashCode *key,
89 void *value)
90{
92
94 return GNUNET_YES;
95}
96
97
98void
126
127
128void
131{
133
134 if ((handle->key) && (! key))
135 {
136 GNUNET_free (handle->key);
137 handle->key = NULL;
138 }
139 else if (! handle->key)
141
142 if (key)
143 memcpy (handle->key, key, sizeof(struct GNUNET_CRYPTO_BlindablePublicKey));
144}
145
146
149{
151
152 return handle->key;
153}
154
155
156void
158 const char *name,
159 char **dir)
160{
161 GNUNET_assert ((handle) && (dir));
162
163 if (name)
164 GNUNET_asprintf (dir, "%s%s%c%s%c", handle->service->dir, "identities",
166 else
167 GNUNET_asprintf (dir, "%s%s%c", handle->service->dir, "anonymous",
169}
170
171
174 const struct GNUNET_HashCode *key)
175{
176 struct GNUNET_ShortHashCode *random_id;
177
178 GNUNET_assert ((handle) && (key));
179
180 random_id = GNUNET_new (struct GNUNET_ShortHashCode);
181
182 if (! random_id)
183 return GNUNET_NO;
184
185 generate_free_member_id (random_id, NULL);
186
188 random_id,
190 {
191 GNUNET_free (random_id);
192 return GNUNET_NO;
193 }
194
196 "Created a new member id (%s) for room: %s\n", GNUNET_sh2s (
197 random_id),
198 GNUNET_h2s (key));
199
200 return GNUNET_YES;
201}
202
203
204const struct GNUNET_ShortHashCode*
206 const struct GNUNET_HashCode *key)
207{
208 GNUNET_assert ((handle) && (key));
209
210 return GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key);
211}
212
213
216 const struct GNUNET_HashCode *key,
217 const struct GNUNET_ShortHashCode *unique_id)
218{
219 struct GNUNET_ShortHashCode *member_id;
220
221 GNUNET_assert ((handle) && (key) && (unique_id));
222
223 member_id = GNUNET_CONTAINER_multihashmap_get (handle->member_ids, key);
224
225 if (! member_id)
226 {
227 member_id = GNUNET_new (struct GNUNET_ShortHashCode);
228 GNUNET_memcpy (member_id, unique_id, sizeof(*member_id));
229
231 member_id,
233 {
234 GNUNET_free (member_id);
235 return GNUNET_SYSERR;
236 }
237 }
238
239 if (0 == GNUNET_memcmp (unique_id, member_id))
240 return GNUNET_OK;
241
243 "Change a member id (%s) for room (%s).\n", GNUNET_sh2s (
244 member_id),
245 GNUNET_h2s (key));
246
247 GNUNET_memcpy (member_id, unique_id, sizeof(*unique_id));
248
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Member id changed to (%s).\n",
250 GNUNET_sh2s (unique_id));
251 return GNUNET_OK;
252}
253
254
257 const struct GNUNET_HashCode *key)
258{
259 GNUNET_assert ((handle) && (key));
260
262 handle->routing, key, NULL,
264 return GNUNET_NO;
265
268 key)))
269 return GNUNET_NO;
270
271 return open_service_room (handle->service, handle, key);
272}
273
274
277 const struct GNUNET_PeerIdentity *door,
278 const struct GNUNET_HashCode *key)
279{
280 GNUNET_assert ((handle) && (door) && (key));
281
284 return GNUNET_NO;
285
286 return entry_service_room (handle->service, handle, door, key);
287}
288
289
292 const struct GNUNET_HashCode *key)
293{
294 GNUNET_assert ((handle) && (key));
295
297 iterate_free_values, NULL);
299
300 if ((handle->notify) && (0 == GNUNET_CONTAINER_multihashmap_size (
301 handle->next_ids)))
302 {
304 handle->notify = NULL;
305 }
306
308 return GNUNET_NO;
309
310 {
313
314 if (GNUNET_YES != result)
315 return result;
316
318 return result;
319 }
320}
321
322
325 const struct GNUNET_HashCode *key)
326{
327 GNUNET_assert ((handle) && (key));
328
330}
331
332
335 const struct GNUNET_HashCode *key,
336 void *value)
337{
340 struct GNUNET_MESSENGER_SrvRoom *room;
341 const struct GNUNET_ShortHashCode *member_id;
342 struct GNUNET_MESSENGER_MessageStore *store;
343
344 GNUNET_assert ((cls) && (key) && (value));
345
346 handle = cls;
347 sync = value;
348
349 room = get_service_room (handle->service, key);
350 member_id = get_srv_handle_member_id (handle, key);
351
352 if ((! room) || (! member_id))
353 goto sync_epoch;
354
355 get_message_state_chain_hash (&(room->state), &(sync->hash));
356
357sync_epoch:
358 if (! room)
359 {
360 GNUNET_memcpy (&(sync->epoch), &(sync->hash),
361 sizeof(sync->epoch));
362 goto send_response;
363 }
364
365 store = get_srv_room_message_store (room);
366
367 if (! store)
368 goto send_response;
369
370 GNUNET_memcpy (&(sync->epoch),
371 get_store_message_epoch (store, &(sync->hash)),
372 sizeof(sync->epoch));
373
375 {
377 struct GNUNET_MQ_Envelope *envelope;
378
379 switch (sync->response_type)
380 {
382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Opening room with member id: %s\n",
383 GNUNET_sh2s (member_id));
384 break;
386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Entering room with member id: %s\n",
387 GNUNET_sh2s (member_id));
388 break;
390 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Closing room succeeded: %s\n",
391 GNUNET_h2s (key));
392 break;
394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Synced room: %s\n",
395 GNUNET_h2s (key));
396 break;
397 default:
398 break;
399 }
400
401 envelope = GNUNET_MQ_msg (response, sync->response_type);
402
403 GNUNET_memcpy (&(response->door), &(sync->door), sizeof(response->door));
404 GNUNET_memcpy (&(response->key), key, sizeof(response->key));
405 GNUNET_memcpy (&(response->previous), &(sync->hash), sizeof(response->
406 previous));
407 GNUNET_memcpy (&(response->epoch), &(sync->epoch), sizeof(response->epoch));
408
409 GNUNET_MQ_send (handle->mq, envelope);
410 }
411
412 GNUNET_free (sync);
413 return GNUNET_YES;
414}
415
416
417void
419 struct GNUNET_MESSENGER_SrvRoom *room)
420{
422
423 GNUNET_assert ((handle) && (room));
424
426 syncing,
427 &(room->
428 key)));
429
431
432 if (GNUNET_NO == result)
433 {
435 "Finish syncing room: %s\n",
436 GNUNET_h2s (&(room->key)));
437
439 &(room->key),
440 &
442 handle);
444 room->sync = NULL;
445 }
446 else if (GNUNET_YES != result)
447 {
449 "Merging messages failed while syncing: %s\n",
450 GNUNET_h2s (&(room->key)));
451 room->sync = NULL;
452 }
453 else if (NULL == room->sync)
454 room->sync = handle;
455}
456
457
458void
460 uint16_t response_type,
461 const struct GNUNET_HashCode *key,
462 const struct GNUNET_HashCode *previous,
463 const struct GNUNET_HashCode *epoch,
464 const struct GNUNET_PeerIdentity *door)
465{
466 struct GNUNET_MESSENGER_SrvRoom *room;
468
469 GNUNET_assert ((handle) && (key) && (previous));
470
471 room = get_service_room (handle->service, key);
472
474 "%s syncing room: %s\n",
475 (room) && (room->sync)? "Continue" : "Start",
476 GNUNET_h2s (key));
477
479
480 GNUNET_assert (sync);
482
483 if (door)
484 GNUNET_memcpy (&(sync->door), door, sizeof(sync->door));
485 else if (GNUNET_OK != get_service_peer_identity (handle->service, &(sync->door
486 )))
487 memset (&(sync->door), 0, sizeof(sync->door));
488
489 GNUNET_memcpy (&(sync->hash), previous, sizeof(sync->hash));
490 GNUNET_memcpy (&(sync->epoch), epoch, sizeof(sync->epoch));
491
492 if ((! room) || (! get_srv_handle_member_id (handle, key)) ||
493 (NULL == get_message_state_merge_hash (&(room->state))))
494 {
496 "Finish syncing room quickly: %s\n",
497 GNUNET_h2s (key));
498
500 return;
501 }
502
504 key, sync,
506 {
508 "Could not wait for syncing room: %s\n",
509 GNUNET_h2s (key));
510 GNUNET_free (sync);
511 }
512
513 if (NULL != room->sync)
515 "Wait for syncing: %s\n",
516 GNUNET_h2s (&(room->key)));
517 else
519}
520
521
524 const struct GNUNET_HashCode *key,
525 const struct GNUNET_MESSENGER_Message *message)
526{
527 const struct GNUNET_ShortHashCode *id;
528 struct GNUNET_MESSENGER_SrvRoom *room;
529
530 GNUNET_assert ((handle) && (key) && (message));
531
533
534 if (! id)
535 {
537 "It is required to be a member of a room to send messages!\n");
538 return GNUNET_NO;
539 }
540
541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending message with member id: %s\n",
542 GNUNET_sh2s (id));
543
544 if (0 != GNUNET_memcmp (id, &(message->header.sender_id)))
545 {
547 "Member id does not match with handle!\n");
548 return GNUNET_NO;
549 }
550
551 room = get_service_room (handle->service, key);
552
553 if (! room)
554 {
555 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "The room (%s) is unknown!\n",
556 GNUNET_h2s (key));
557 return GNUNET_NO;
558 }
559
560 {
562 msg = copy_message (message);
563
564 if (! msg)
565 {
566 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Copying message failed!\n");
567 return GNUNET_NO;
568 }
569
570 return send_srv_room_message (room, handle, msg);
571 }
572}
573
574
575static const struct GNUNET_HashCode*
578{
579 GNUNET_assert (session);
580
581 if (session->next)
582 return get_next_member_session_context (session->next);
583 else
584 return get_member_session_context (session);
585}
586
587
588static const struct GNUNET_MESSENGER_SrvMemberSession*
590 struct GNUNET_MESSENGER_SrvRoom *room,
591 const struct GNUNET_HashCode *key)
592{
593 const struct GNUNET_ShortHashCode *id;
595
596 GNUNET_assert ((handle) && (room) && (key) && (handle->service));
597
599
600 if (! id)
601 {
603 "Handle is missing a member id for its member session! (%s)\n",
604 GNUNET_h2s (key));
605 return NULL;
606 }
607
609
610 if (! pubkey)
611 {
613 "Handle is missing a public key for its member session! (%s)\n",
614 GNUNET_h2s (key));
615 return NULL;
616 }
617
618 {
619 struct GNUNET_MESSENGER_MemberStore *store;
620 struct GNUNET_MESSENGER_Member *member;
621
623 member = get_store_member (store, id);
624
625 return get_member_session (member, pubkey);
626 }
627}
628
629
630void
632 struct GNUNET_MESSENGER_SrvRoom *room,
633 const struct GNUNET_MESSENGER_SenderSession *session,
634 const struct GNUNET_MESSENGER_Message *message,
635 const struct GNUNET_HashCode *hash,
636 const struct GNUNET_HashCode *epoch,
637 enum GNUNET_GenericReturnValue recent)
638{
639 const struct GNUNET_HashCode *key;
640 const struct GNUNET_ShortHashCode *id;
641 const struct GNUNET_HashCode *context;
643 const struct GNUNET_ShortHashCode *discourse;
644 struct GNUNET_MESSENGER_Subscription *subscription;
645 struct GNUNET_HashCode sender;
646
647 GNUNET_assert ((handle) && (room) && (session) && (message) && (hash) && (
648 epoch));
649
650 key = get_srv_room_key (room);
652
653 if (! handle->mq)
654 {
656 "Notifying client is missing a message queue!\n");
657 return;
658 }
659
660 if ((GNUNET_MESSENGER_KIND_MERGE == message->header.kind) &&
662 key)) &&
663 (NULL == get_message_state_merge_hash (&(room->state))))
665
666 if (! id)
667 {
669 "Notifying client about message requires membership!\n");
670 return;
671 }
672
673 context = NULL;
674
675 if (GNUNET_MESSENGER_KIND_TALK != message->header.kind)
676 goto skip_message_filter;
677
679 discourse = &(message->body.talk.discourse);
680
681 {
682 struct GNUNET_MESSENGER_MemberStore *member_store;
683 struct GNUNET_MESSENGER_Member *member;
684
685 member_store = get_srv_room_member_store (room);
686
687 if (! member_store)
688 {
690 "Room does not offer a member store: %s\n",
691 GNUNET_h2s (key));
692 return;
693 }
694
695 member = get_store_member (member_store, id);
696
697 if (! member)
698 {
700 "Could not find member in store with given id: %s (%s)\n",
701 GNUNET_sh2s (id),
702 GNUNET_h2s (key));
703 return;
704 }
705
706 subscription = get_member_subscription (member, discourse);
707 }
708
709 if ((! subscription) ||
711 {
713 "Dropping message for client outside of subscription: %s\n",
714 GNUNET_h2s (hash));
715 return;
716 }
717
718skip_message_filter:
719 if (GNUNET_YES == is_peer_message (message))
720 {
721 const struct GNUNET_PeerIdentity *identity = session->peer;
722 GNUNET_CRYPTO_hash (identity, sizeof(*identity), &sender);
723
724 context = &sender;
725 }
726 else
727 {
730 GNUNET_CRYPTO_hash (pubkey, sizeof(*pubkey), &sender);
731
733 }
734
736 "Notifying client about message: %s (%s)\n",
738 message->header.kind));
739
740 {
742 struct GNUNET_MQ_Envelope *env;
743 uint16_t length;
744 char *buffer;
745
746 length = get_message_size (message, GNUNET_YES);
747
748 env = GNUNET_MQ_msg_extra (msg, length,
750
751 GNUNET_memcpy (&(msg->key), key, sizeof(msg->key));
752 GNUNET_memcpy (&(msg->sender), &sender, sizeof(msg->sender));
753 GNUNET_memcpy (&(msg->context), context, sizeof(msg->context));
754 GNUNET_memcpy (&(msg->hash), hash, sizeof(msg->hash));
755 GNUNET_memcpy (&(msg->epoch), epoch, sizeof(msg->epoch));
756
757 msg->flags = (uint32_t) GNUNET_MESSENGER_FLAG_NONE;
758
759 if (GNUNET_YES == is_peer_message (message))
760 msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_PEER;
761 else if (get_handle_member_session (handle, room, key) == session->member)
762 msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_SENT;
763
764 if (GNUNET_YES == recent)
765 msg->flags |= (uint32_t) GNUNET_MESSENGER_FLAG_RECENT;
766
767 buffer = ((char*) msg) + sizeof(*msg);
768 encode_message (message, length, buffer, GNUNET_YES);
769
771 }
772}
773
774
777 const struct GNUNET_HashCode *key,
778 void *value)
779{
782
783 GNUNET_assert ((cls) && (value));
784
785 handle = cls;
786 next = value;
787
789 "Notifying client about next member id: %s (%s)\n",
790 GNUNET_sh2s (&(next->id)), GNUNET_h2s (key));
791
792 {
794 struct GNUNET_MQ_Envelope *env;
795
798
799 GNUNET_memcpy (&(msg->key), key, sizeof(*key));
800 GNUNET_memcpy (&(msg->id), &(next->id), sizeof(next->id));
801 msg->reset = (uint32_t) next->reset;
802
804 }
805
807 return GNUNET_YES;
808}
809
810
811static void
813{
815
816 GNUNET_assert (cls);
817
818 handle = cls;
819 handle->notify = NULL;
820
824}
825
826
827void
829 struct GNUNET_MESSENGER_SrvRoom *room,
830 const struct GNUNET_ShortHashCode *member_id,
832{
835 const struct GNUNET_HashCode *key;
836
837 GNUNET_assert ((handle) && (room) && (member_id));
838
840 key = get_srv_room_key (room);
841
842 if (! next)
843 {
845 "Allocation of next member id failed: %s (%s)\n",
846 GNUNET_sh2s (member_id), GNUNET_h2s (key));
847 return;
848 }
849
850 GNUNET_memcpy (&(next->id), member_id, sizeof(next->id));
851 next->reset = reset;
852
853 prev = GNUNET_CONTAINER_multihashmap_get (handle->next_ids, key);
854
856 next,
858 {
860 "Update of next member id failed: %s (%s)\n",
861 GNUNET_sh2s (member_id), GNUNET_h2s (key));
862 return;
863 }
864
865 if (prev)
866 GNUNET_free (prev);
867
868 if (! handle->notify)
870 handle);
871}
struct GNUNET_MessageHeader * msg
Definition 005.c:2
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static char * dir
Set to the directory where runtime files are stored.
Definition gnunet-arm.c:88
static uint64_t timestamp(void)
Get current timestamp.
static struct MHD_Response * response
Our canonical response.
struct GNUNET_HashCode key
The key used in the DHT.
static void send_response(struct Request *request)
Send the response for the given request and clean up.
static pa_context * context
Pulseaudio context.
static struct GNUNET_CRYPTO_BlindablePublicKey pubkey
Public key of the zone to look in.
static char * name
Name (label) of the records to list.
static int reset
Reset argument.
static struct GNUNET_IDENTITY_Handle * id
Handle to IDENTITY.
static char * value
Value of the record to add/remove.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
static int result
Global testing status.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
void notify_srv_handle_message(struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_MESSENGER_SenderSession *session, const struct GNUNET_MESSENGER_Message *message, const struct GNUNET_HashCode *hash, const struct GNUNET_HashCode *epoch, enum GNUNET_GenericReturnValue recent)
Notifies the handle that a new message was received or sent.
struct GNUNET_MESSENGER_SrvHandle * create_srv_handle(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MQ_Handle *mq)
Creates and allocates a new handle related to a service and using a given mq (message queue).
static enum GNUNET_GenericReturnValue iterate_free_values(void *cls, const struct GNUNET_HashCode *key, void *value)
enum GNUNET_GenericReturnValue change_srv_handle_member_id(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, const struct GNUNET_ShortHashCode *unique_id)
Changes the member id of a given handle in a specific room to match a unique_id and returns GNUNET_OK...
static enum GNUNET_GenericReturnValue iterate_srv_handle_sync_finished(void *cls, const struct GNUNET_HashCode *key, void *value)
enum GNUNET_GenericReturnValue close_srv_handle_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Removes the membership of the room using a specific key and closes it if no other handle from this se...
void sync_srv_handle_room(struct GNUNET_MESSENGER_SrvHandle *handle, uint16_t response_type, const struct GNUNET_HashCode *key, const struct GNUNET_HashCode *previous, const struct GNUNET_HashCode *epoch, const struct GNUNET_PeerIdentity *door)
Starts merging message hashes until the state from a room of a given handle using a specific key is f...
enum GNUNET_GenericReturnValue send_srv_handle_message(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, const struct GNUNET_MESSENGER_Message *message)
Sends a message from a given handle to the room using a specific key.
void notify_srv_handle_member_id(struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_ShortHashCode *member_id, enum GNUNET_GenericReturnValue reset)
Notifies the handle that a new member id needs to be used.
static void task_notify_srv_handle_member_id(void *cls)
static enum GNUNET_GenericReturnValue iterate_close_rooms(void *cls, const struct GNUNET_HashCode *key, void *value)
static const struct GNUNET_MESSENGER_SrvMemberSession * get_handle_member_session(struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvRoom *room, const struct GNUNET_HashCode *key)
void set_srv_handle_key(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_CRYPTO_BlindablePublicKey *key)
Sets the public key of a given handle.
enum GNUNET_GenericReturnValue entry_srv_handle_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Makes a given handle a member of the room using a specific key and enters the room through a tunnel t...
const struct GNUNET_CRYPTO_BlindablePublicKey * get_srv_handle_key(const struct GNUNET_MESSENGER_SrvHandle *handle)
Returns the public key of a given handle.
void merge_srv_handle_room_to_sync(struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_SrvRoom *room)
Merges the latest hash from a specific room by a given handle until the message graph of the room is ...
static enum GNUNET_GenericReturnValue iterate_next_member_ids(void *cls, const struct GNUNET_HashCode *key, void *value)
static const struct GNUNET_HashCode * get_next_member_session_context(const struct GNUNET_MESSENGER_SrvMemberSession *session)
const struct GNUNET_ShortHashCode * get_srv_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns the member id of a given handle in a specific room.
static enum GNUNET_GenericReturnValue create_handle_member_id(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
enum GNUNET_GenericReturnValue is_srv_handle_routing(const struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Returns whether a given handle has enabled routing for a room using a specific key by opening that ro...
void get_srv_handle_data_subdir(const struct GNUNET_MESSENGER_SrvHandle *handle, const char *name, char **dir)
Writes the path of the directory for a given handle using a specific name to the parameter dir.
void destroy_srv_handle(struct GNUNET_MESSENGER_SrvHandle *handle)
Destroys a handle and frees its memory fully.
enum GNUNET_GenericReturnValue open_srv_handle_room(struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Makes a given handle a member of the room using a specific key and opens the room from the handles se...
struct GNUNET_MESSENGER_SrvMemberSession * get_member_session(const struct GNUNET_MESSENGER_Member *member, const struct GNUNET_CRYPTO_BlindablePublicKey *public_key)
Returns the member session of a member identified by a given public key.
struct GNUNET_MESSENGER_Subscription * get_member_subscription(struct GNUNET_MESSENGER_Member *member, const struct GNUNET_ShortHashCode *discourse)
Returns the active subscription of a given member to a selected discourse.
const struct GNUNET_CRYPTO_BlindablePublicKey * get_member_session_public_key(const struct GNUNET_MESSENGER_SrvMemberSession *session)
Returns the public key of a given member session.
const struct GNUNET_HashCode * get_member_session_context(const struct GNUNET_MESSENGER_SrvMemberSession *session)
Returns the member context of a given member session.
struct GNUNET_MESSENGER_Member * get_store_member(const struct GNUNET_MESSENGER_MemberStore *store, const struct GNUNET_ShortHashCode *id)
Returns the member in a store identified by a given id.
const struct GNUNET_HashCode * get_message_state_merge_hash(const struct GNUNET_MESSENGER_MessageState *state)
void get_message_state_chain_hash(const struct GNUNET_MESSENGER_MessageState *state, struct GNUNET_HashCode *hash)
const struct GNUNET_HashCode * get_store_message_epoch(const struct GNUNET_MESSENGER_MessageStore *store, const struct GNUNET_HashCode *hash)
Returns the epoch hash of a message from a message store matching a given hash.
struct GNUNET_MESSENGER_MessageStore * get_srv_room_message_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used message store of a given room.
enum GNUNET_GenericReturnValue merge_srv_room_last_messages(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle)
Reduces all current forks inside of the message history of a room to one remaining last message by me...
enum GNUNET_GenericReturnValue send_srv_room_message(struct GNUNET_MESSENGER_SrvRoom *room, struct GNUNET_MESSENGER_SrvHandle *handle, struct GNUNET_MESSENGER_Message *message)
Sends a message from a given handle into a room.
const struct GNUNET_HashCode * get_srv_room_key(const struct GNUNET_MESSENGER_SrvRoom *room)
Returns the shared secret you need to access a room.
struct GNUNET_MESSENGER_MemberStore * get_srv_room_member_store(struct GNUNET_MESSENGER_SrvRoom *room)
Returns the used member store of a given room.
enum GNUNET_GenericReturnValue get_service_peer_identity(struct GNUNET_MESSENGER_Service *service, struct GNUNET_PeerIdentity *peer)
Tries to write the peer identity of the peer running a service on to the peer parameter.
enum GNUNET_GenericReturnValue entry_service_room(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_PeerIdentity *door, const struct GNUNET_HashCode *key)
Tries to enter a room using a given key for a service by a specific handle.
enum GNUNET_GenericReturnValue close_service_room(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key, enum GNUNET_GenericReturnValue deletion)
Tries to close a room using a given key for a service by a specific handle.
struct GNUNET_MESSENGER_SrvRoom * get_service_room(const struct GNUNET_MESSENGER_Service *service, const struct GNUNET_HashCode *key)
Returns the room identified by a given key for a service.
enum GNUNET_GenericReturnValue open_service_room(struct GNUNET_MESSENGER_Service *service, struct GNUNET_MESSENGER_SrvHandle *handle, const struct GNUNET_HashCode *key)
Tries to open a room using a given key for a service by a specific handle.
enum GNUNET_GenericReturnValue has_subscription_of_timestamp(const struct GNUNET_MESSENGER_Subscription *subscription, struct GNUNET_TIME_Absolute timestamp)
static struct GNUNET_VPN_Handle * handle
Handle to vpn service.
Definition gnunet-vpn.c:35
Constants for network protocols.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:40
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_contains(const struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Check if the map contains any value under the given key (including values that are NULL).
int GNUNET_CONTAINER_multihashmap_remove_all(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key)
Remove all entries for the given key from the map.
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.
unsigned int GNUNET_CONTAINER_multihashmap_size(const struct GNUNET_CONTAINER_MultiHashMap *map)
Get the number of key-value pairs in the map.
void GNUNET_CONTAINER_multihashmap_destroy(struct GNUNET_CONTAINER_MultiHashMap *map)
Destroy a hash map.
struct GNUNET_CONTAINER_MultiHashMap * GNUNET_CONTAINER_multihashmap_create(unsigned int len, int do_not_copy_keys)
Create a multi hash map.
unsigned int GNUNET_CONTAINER_multihashmap_clear(struct GNUNET_CONTAINER_MultiHashMap *map)
Remove all entries from the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multihashmap_get_multiple(struct GNUNET_CONTAINER_MultiHashMap *map, const struct GNUNET_HashCode *key, GNUNET_CONTAINER_MultiHashMapIteratorCallback it, void *it_cls)
Iterate over all entries in the map that match a particular key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST
, ' bother checking if a value already exists (faster than GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE...
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE
Allow multiple values with the same key.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE
If a value with the given key exists, replace it.
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_sh2s(const struct GNUNET_ShortHashCode *shc)
Convert a short hash value to a string (for printing debug messages).
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
const char * GNUNET_MESSENGER_name_of_kind(enum GNUNET_MESSENGER_MessageKind kind)
Get the name of a message kind.
@ GNUNET_MESSENGER_KIND_TALK
The talk kind.
@ GNUNET_MESSENGER_KIND_MERGE
The merge kind.
@ GNUNET_MESSENGER_FLAG_SENT
The sent flag.
@ GNUNET_MESSENGER_FLAG_NONE
The none flag.
@ GNUNET_MESSENGER_FLAG_PEER
The peer flag.
@ GNUNET_MESSENGER_FLAG_RECENT
The recent flag.
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_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_OPEN
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_RECV_MESSAGE
#define GNUNET_MESSAGE_TYPE_MESSENGER_ROOM_SYNC
#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:986
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1310
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
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 maximum length in bytes.
struct GNUNET_MESSENGER_Message * copy_message(const struct GNUNET_MESSENGER_Message *message)
Creates and allocates a copy of a given message.
enum GNUNET_GenericReturnValue is_peer_message(const struct GNUNET_MESSENGER_Message *message)
Returns whether a specific kind of message can be sent by the service without usage of a clients priv...
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 generate_free_member_id(struct GNUNET_ShortHashCode *id, const struct GNUNET_CONTAINER_MultiShortmap *members)
Tries to generate an unused member id and store it into the id parameter.
#define DIR_SEPARATOR
Definition platform.h:166
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
An identity key as per LSD0001.
A 512-bit hashcode.
Message to receive the current member id of a handle in room.
struct GNUNET_MESSENGER_MemberStore * store
struct GNUNET_MESSENGER_MessageTalk talk
enum GNUNET_MESSENGER_MessageKind kind
The kind of the message.
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.
struct GNUNET_ShortHashCode discourse
The hash of the discourse to talk.
struct GNUNET_MESSENGER_MessageHeader header
Header.
struct GNUNET_MESSENGER_MessageBody body
Body.
Message to receive something from a room.
General message to confirm interaction with a room.
struct GNUNET_MESSENGER_SrvMemberSession * member
struct GNUNET_MESSENGER_SrvMemberSession * next
struct GNUNET_MESSENGER_SrvHandle * sync
struct GNUNET_MESSENGER_MessageState state
struct GNUNET_MQ_Envelope * next
Messages are stored in a linked list.
Definition mq.c:39
Handle to a message queue.
Definition mq.c:87
The identity of the host (wraps the signing key of the peer).
A 256-bit hashcode.
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_MQ_Handle * mq
Connection to VPN service.
Definition vpn_api.c:44