2 * This file is part of GNUnet
3 * Copyright (C) 2013 Christian Grothoff (and other contributing authors)
5 * GNUnet is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published
7 * by the Free Software Foundation; either version 3, or (at your
8 * option) any later version.
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 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNUnet; see the file COPYING. If not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
22 * @file social/social_api.c
23 * @brief Social service; implements social interactions using the PSYC service.
24 * @author Gabor X Toth
31 #include "gnunet_util_lib.h"
32 #include "gnunet_env_lib.h"
33 #include "gnunet_core_service.h"
34 #include "gnunet_identity_service.h"
35 #include "gnunet_namestore_service.h"
36 #include "gnunet_gns_service.h"
37 #include "gnunet_psyc_service.h"
38 #include "gnunet_psyc_util_lib.h"
39 #include "gnunet_social_service.h"
42 #define LOG(kind,...) GNUNET_log_from (kind, "social-api",__VA_ARGS__)
45 static struct GNUNET_CORE_Handle *core;
46 static struct GNUNET_GNS_Handle *gns;
47 static struct GNUNET_NAMESTORE_Handle *namestore;
48 static struct GNUNET_PeerIdentity this_peer;
52 * Handle for a pseudonym of another user in the network.
54 struct GNUNET_SOCIAL_Nym
56 struct GNUNET_CRYPTO_EcdsaPublicKey pub_key;
57 struct GNUNET_HashCode pub_key_hash;
62 * Handle for a place where social interactions happen.
64 struct GNUNET_SOCIAL_Place
67 * Configuration to use.
69 const struct GNUNET_CONFIGURATION_Handle *cfg;
72 * Client connection to the service.
74 struct GNUNET_CLIENT_MANAGER_Connection *client;
77 * Transmission handle.
79 struct GNUNET_PSYC_TransmitHandle *tmit;
84 struct GNUNET_PSYC_ReceiveHandle *recv;
87 * Slicer for processing incoming methods.
89 struct GNUNET_SOCIAL_Slicer *slicer;
92 * Message to send on reconnect.
94 struct GNUNET_MessageHeader *connect_msg;
97 * Function called after disconnected from the service.
99 GNUNET_ContinuationCallback disconnect_cb;
102 * Closure for @a disconnect_cb.
104 void *disconnect_cls;
107 * Public key of the place.
109 struct GNUNET_CRYPTO_EddsaPublicKey pub_key;
112 * Private key of the ego.
114 struct GNUNET_CRYPTO_EcdsaPrivateKey ego_key;
117 * Does this place belong to a host (#GNUNET_YES) or guest (#GNUNET_NO)?
122 * Is this place in the process of disconnecting from the service?
123 * #GNUNET_YES or #GNUNET_NO
125 uint8_t is_disconnecting;
130 * Host handle for a place that we entered.
132 struct GNUNET_SOCIAL_Host
134 struct GNUNET_SOCIAL_Place plc;
136 struct GNUNET_CRYPTO_EddsaPrivateKey place_key;
141 struct GNUNET_PSYC_ReceiveHandle *recv;
144 * Slicer for processing incoming methods.
146 struct GNUNET_SOCIAL_Slicer *slicer;
148 GNUNET_SOCIAL_HostEnterCallback enter_cb;
150 GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb;
152 GNUNET_SOCIAL_FarewellCallback farewell_cb;
155 * Closure for callbacks.
159 struct GNUNET_SOCIAL_Nym *notice_place_leave_nym;
160 struct GNUNET_ENV_Environment *notice_place_leave_env;
165 * Guest handle for place that we entered.
167 struct GNUNET_SOCIAL_Guest
169 struct GNUNET_SOCIAL_Place plc;
174 struct GNUNET_PSYC_ReceiveHandle *recv;
177 * Slicer for processing incoming methods.
179 struct GNUNET_SOCIAL_Slicer *slicer;
181 GNUNET_SOCIAL_GuestEnterCallback enter_cb;
183 GNUNET_SOCIAL_EntryDecisionCallback entry_dcsn_cb;
186 * Closure for callbacks.
193 * Hash map of all nyms.
194 * pub_key_hash -> struct GNUNET_SOCIAL_Nym *
196 struct GNUNET_CONTAINER_MultiHashMap *nyms;
200 * Handle for a try-and-slice instance.
202 struct GNUNET_SOCIAL_Slicer
205 * Method handlers: method_name -> SlicerMethodCallbacks
207 struct GNUNET_CONTAINER_MultiHashMap *method_handlers;
210 * Modifier handlers: modifier name -> SlicerModifierCallbacks
212 struct GNUNET_CONTAINER_MultiHashMap *modifier_handlers;
215 * Currently being processed message part.
217 const struct GNUNET_MessageHeader *msg;
220 * ID of currently being received message.
225 * Method name of currently being received message.
230 * Name of currently processed modifier.
235 * Value of currently processed modifier.
240 * Public key of the nym the current message originates from.
242 struct GNUNET_CRYPTO_EcdsaPublicKey nym_key;
245 * Size of @a method_name (including terminating \0).
247 uint16_t method_name_size;
250 * Size of @a modifier_name (including terminating \0).
252 uint16_t mod_name_size;
255 * Size of modifier value fragment.
257 uint16_t mod_value_size;
260 * Full size of modifier value.
262 uint16_t mod_full_value_size;
265 * Remaining bytes from the value of the current modifier.
267 uint16_t mod_value_remaining;
270 * Operator of currently processed modifier.
277 * Callbacks for a slicer method handler.
279 struct SlicerMethodCallbacks
281 GNUNET_SOCIAL_MethodCallback method_cb;
282 GNUNET_SOCIAL_ModifierCallback modifier_cb;
283 GNUNET_SOCIAL_DataCallback data_cb;
284 GNUNET_SOCIAL_EndOfMessageCallback eom_cb;
289 struct SlicerMethodRemoveClosure
291 struct GNUNET_SOCIAL_Slicer *slicer;
292 struct SlicerMethodCallbacks rm_cbs;
297 * Callbacks for a slicer method handler.
299 struct SlicerModifierCallbacks
301 GNUNET_SOCIAL_ModifierCallback modifier_cb;
306 struct SlicerModifierRemoveClosure
308 struct GNUNET_SOCIAL_Slicer *slicer;
309 struct SlicerModifierCallbacks rm_cbs;
314 * Handle for an announcement request.
316 struct GNUNET_SOCIAL_Announcement
325 struct GNUNET_SOCIAL_TalkRequest
334 struct GNUNET_SOCIAL_HistoryRequest
339 struct GNUNET_SOCIAL_Place *plc;
349 struct GNUNET_PSYC_ReceiveHandle *recv;
352 * Function to call when the operation finished.
354 GNUNET_ResultCallback result_cb;
357 * Closure for @a result_cb.
363 struct GNUNET_SOCIAL_LookHandle
368 struct GNUNET_SOCIAL_Place *plc;
376 * State variable result callback.
378 GNUNET_PSYC_StateVarCallback var_cb;
381 * Function to call when the operation finished.
383 GNUNET_ResultCallback result_cb;
386 * Name of current modifier being received.
391 * Size of current modifier value being received.
393 size_t mod_value_size;
396 * Remaining size of current modifier value still to be received.
398 size_t mod_value_remaining;
401 * Closure for @a result_cb.
409 static struct GNUNET_SOCIAL_Nym *
410 nym_get_or_create (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub_key)
412 struct GNUNET_SOCIAL_Nym *nym = NULL;
413 struct GNUNET_HashCode pub_key_hash;
418 GNUNET_CRYPTO_hash (pub_key, sizeof (*pub_key), &pub_key_hash);
421 nyms = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
423 nym = GNUNET_CONTAINER_multihashmap_get (nyms, &pub_key_hash);
427 nym = GNUNET_new (struct GNUNET_SOCIAL_Nym);
428 nym->pub_key = *pub_key;
429 nym->pub_key_hash = pub_key_hash;
430 GNUNET_CONTAINER_multihashmap_put (nyms, &nym->pub_key_hash, nym,
431 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
438 nym_destroy (struct GNUNET_SOCIAL_Nym *nym)
440 GNUNET_CONTAINER_multihashmap_remove (nyms, &nym->pub_key_hash, nym);
445 /*** MESSAGE HANDLERS ***/
447 /** _notice_place_leave from guests */
450 host_recv_notice_place_leave_method (void *cls,
451 const struct GNUNET_PSYC_MessageMethod *meth,
454 const struct GNUNET_SOCIAL_Nym *nym,
455 const char *method_name)
457 struct GNUNET_SOCIAL_Host *hst = cls;
461 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
462 "Host received method for message ID %" PRIu64 " from nym %s: %s\n",
463 message_id, GNUNET_h2s (&nym->pub_key_hash), method_name);
465 hst->notice_place_leave_nym = (struct GNUNET_SOCIAL_Nym *) nym;
466 hst->notice_place_leave_env = GNUNET_ENV_environment_create ();
471 host_recv_notice_place_leave_modifier (void *cls,
472 const struct GNUNET_MessageHeader *msg,
474 enum GNUNET_ENV_Operator oper,
478 uint16_t full_value_size)
480 struct GNUNET_SOCIAL_Host *hst = cls;
481 if (NULL == hst->notice_place_leave_env)
484 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
485 "Host received modifier for _notice_place_leave message with ID %" PRIu64 ":\n"
487 message_id, oper, name, value_size, value);
489 /* skip _nym, it's added later in eom() */
490 if (0 == memcmp (name, "_nym", sizeof ("_nym"))
491 || 0 == memcmp (name, "_nym_", sizeof ("_nym_") - 1))
494 GNUNET_ENV_environment_add (hst->notice_place_leave_env,
495 GNUNET_ENV_OP_SET, name, value, value_size);
500 host_recv_notice_place_leave_eom (void *cls,
501 const struct GNUNET_MessageHeader *msg,
505 struct GNUNET_SOCIAL_Host *hst = cls;
506 if (NULL == hst->notice_place_leave_env)
509 if (GNUNET_YES != cancelled)
511 if (NULL != hst->farewell_cb)
512 hst->farewell_cb (hst->cb_cls, hst->notice_place_leave_nym,
513 hst->notice_place_leave_env);
514 /* announce leaving guest to place */
515 GNUNET_ENV_environment_add (hst->notice_place_leave_env, GNUNET_ENV_OP_SET,
516 "_nym", hst->notice_place_leave_nym,
517 sizeof (*hst->notice_place_leave_nym));
518 GNUNET_SOCIAL_host_announce (hst, "_notice_place_leave",
519 hst->notice_place_leave_env,
520 NULL, NULL, GNUNET_SOCIAL_ANNOUNCE_NONE);
521 nym_destroy (hst->notice_place_leave_nym);
523 GNUNET_ENV_environment_destroy (hst->notice_place_leave_env);
524 hst->notice_place_leave_env = NULL;
531 * Call a method handler for an incoming message part.
534 slicer_method_handler_notify (void *cls, const struct GNUNET_HashCode *key,
537 struct GNUNET_SOCIAL_Slicer *slicer = cls;
538 const struct GNUNET_MessageHeader *msg = slicer->msg;
539 struct SlicerMethodCallbacks *cbs = value;
540 uint16_t ptype = ntohs (msg->type);
544 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD:
546 if (NULL == cbs->method_cb)
548 struct GNUNET_PSYC_MessageMethod *
549 meth = (struct GNUNET_PSYC_MessageMethod *) msg;
550 cbs->method_cb (cbs->cls, meth, slicer->message_id,
552 nym_get_or_create (&slicer->nym_key),
553 slicer->method_name);
557 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER:
559 if (NULL == cbs->modifier_cb)
561 struct GNUNET_PSYC_MessageModifier *
562 mod = (struct GNUNET_PSYC_MessageModifier *) msg;
563 cbs->modifier_cb (cbs->cls, &mod->header, slicer->message_id,
564 mod->oper, (const char *) &mod[1],
565 (const void *) &mod[1] + ntohs (mod->name_size),
566 ntohs (mod->header.size) - sizeof (*mod) - ntohs (mod->name_size),
567 ntohs (mod->value_size));
571 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT:
573 if (NULL == cbs->modifier_cb)
575 cbs->modifier_cb (cbs->cls, msg, slicer->message_id,
576 slicer->mod_oper, slicer->mod_name, &msg[1],
577 ntohs (msg->size) - sizeof (*msg),
578 slicer->mod_full_value_size);
582 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_DATA:
584 if (NULL == cbs->data_cb)
586 uint64_t data_offset = 0; // FIXME
587 cbs->data_cb (cbs->cls, msg, slicer->message_id,
588 data_offset, &msg[1], ntohs (msg->size) - sizeof (*msg));
592 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END:
593 if (NULL == cbs->eom_cb)
595 cbs->eom_cb (cbs->cls, msg, slicer->message_id, GNUNET_NO);
598 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_CANCEL:
599 if (NULL == cbs->eom_cb)
601 cbs->eom_cb (cbs->cls, msg, slicer->message_id, GNUNET_YES);
609 * Call a method handler for an incoming message part.
612 slicer_modifier_handler_notify (void *cls, const struct GNUNET_HashCode *key,
615 struct GNUNET_SOCIAL_Slicer *slicer = cls;
616 struct SlicerModifierCallbacks *cbs = value;
618 cbs->modifier_cb (cbs->cls, slicer->msg, slicer->message_id, slicer->mod_oper,
619 slicer->mod_name, slicer->mod_value,
620 slicer->mod_value_size, slicer->mod_full_value_size);
626 * Process an incoming message part and call matching handlers.
633 * Flags for the message.
634 * @see enum GNUNET_PSYC_MessageFlags
636 * The message part. as it arrived from the network.
639 slicer_message (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key,
640 uint64_t message_id, uint32_t flags, uint64_t fragment_offset,
641 const struct GNUNET_MessageHeader *msg)
643 struct GNUNET_SOCIAL_Slicer *slicer = cls;
644 slicer->nym_key = *slave_key;
646 uint16_t ptype = ntohs (msg->type);
647 if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_METHOD == ptype)
649 struct GNUNET_PSYC_MessageMethod *
650 meth = (struct GNUNET_PSYC_MessageMethod *) msg;
651 slicer->method_name_size = ntohs (meth->header.size) - sizeof (*meth);
652 slicer->method_name = GNUNET_malloc (slicer->method_name_size);
653 memcpy (slicer->method_name, &meth[1], slicer->method_name_size);
654 slicer->message_id = message_id;
658 GNUNET_assert (message_id == slicer->message_id);
661 LOG (GNUNET_ERROR_TYPE_DEBUG,
662 "Slicer received message of type %u and size %u, "
663 "with ID %" PRIu64 " and method %s\n",
664 ptype, ntohs (msg->size), message_id, slicer->method_name);
668 /* try-and-slice modifier */
672 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER:
674 struct GNUNET_PSYC_MessageModifier *
675 mod = (struct GNUNET_PSYC_MessageModifier *) msg;
676 slicer->mod_oper = mod->oper;
677 slicer->mod_name_size = ntohs (mod->name_size);
678 slicer->mod_name = GNUNET_malloc (slicer->mod_name_size);
679 memcpy (slicer->mod_name, &mod[1], slicer->mod_name_size);
680 slicer->mod_value = (char *) &mod[1] + slicer->mod_name_size;
681 slicer->mod_full_value_size = ntohs (mod->value_size);
682 slicer->mod_value_remaining = slicer->mod_full_value_size;
683 slicer->mod_value_size
684 = ntohs (mod->header.size) - sizeof (*mod) - slicer->mod_name_size;
686 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT:
687 if (ptype == GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT)
689 slicer->mod_value = (char *) &msg[1];
690 slicer->mod_value_size = ntohs (msg->size) - sizeof (*msg);
692 slicer->mod_value_remaining -= slicer->mod_value_size;
693 char *name = GNUNET_malloc (slicer->mod_name_size);
694 memcpy (name, slicer->mod_name, slicer->mod_name_size);
697 struct GNUNET_HashCode key;
698 uint16_t name_len = strlen (name);
699 GNUNET_CRYPTO_hash (name, name_len, &key);
700 GNUNET_CONTAINER_multihashmap_get_multiple (slicer->modifier_handlers, &key,
701 slicer_modifier_handler_notify,
703 char *p = strrchr (name, '_');
711 /* try-and-slice method */
713 char *name = GNUNET_malloc (slicer->method_name_size);
714 memcpy (name, slicer->method_name, slicer->method_name_size);
717 struct GNUNET_HashCode key;
718 uint16_t name_len = strlen (name);
719 GNUNET_CRYPTO_hash (name, name_len, &key);
720 GNUNET_CONTAINER_multihashmap_get_multiple (slicer->method_handlers, &key,
721 slicer_method_handler_notify,
723 char *p = strrchr (name, '_');
730 if (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_END <= ptype)
731 GNUNET_free (slicer->method_name);
733 if (0 == slicer->mod_value_remaining && NULL != slicer->mod_name)
735 GNUNET_free (slicer->mod_name);
736 slicer->mod_name = NULL;
737 slicer->mod_name_size = 0;
738 slicer->mod_value_size = 0;
739 slicer->mod_full_value_size = 0;
740 slicer->mod_oper = 0;
748 * Create a try-and-slice instance.
750 * A slicer processes incoming messages and notifies callbacks about matching
751 * methods or modifiers encountered.
753 * @return A new try-and-slice construct.
755 struct GNUNET_SOCIAL_Slicer *
756 GNUNET_SOCIAL_slicer_create (void)
758 struct GNUNET_SOCIAL_Slicer *slicer = GNUNET_malloc (sizeof (*slicer));
759 slicer->method_handlers = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
760 slicer->modifier_handlers = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_NO);
766 * Add a method to the try-and-slice instance.
768 * The callbacks are called for messages with a matching @a method_name prefix.
771 * The try-and-slice instance to extend.
773 * Name of the given method, use empty string to match all.
775 * Method handler invoked upon a matching message.
777 * Modifier handler, invoked after @a method_cb
778 * for each modifier in the message.
780 * Data handler, invoked after @a modifier_cb for each data fragment.
782 * Invoked upon reaching the end of a matching message.
784 * Closure for the callbacks.
787 GNUNET_SOCIAL_slicer_method_add (struct GNUNET_SOCIAL_Slicer *slicer,
788 const char *method_name,
789 GNUNET_SOCIAL_MethodCallback method_cb,
790 GNUNET_SOCIAL_ModifierCallback modifier_cb,
791 GNUNET_SOCIAL_DataCallback data_cb,
792 GNUNET_SOCIAL_EndOfMessageCallback eom_cb,
795 struct GNUNET_HashCode key;
796 GNUNET_CRYPTO_hash (method_name, strlen (method_name), &key);
798 struct SlicerMethodCallbacks *cbs = GNUNET_malloc (sizeof (*cbs));
799 cbs->method_cb = method_cb;
800 cbs->modifier_cb = modifier_cb;
801 cbs->data_cb = data_cb;
802 cbs->eom_cb = eom_cb;
805 GNUNET_CONTAINER_multihashmap_put (slicer->method_handlers, &key, cbs,
806 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
811 slicer_method_remove (void *cls, const struct GNUNET_HashCode *key, void *value)
813 struct SlicerMethodRemoveClosure *rm_cls = cls;
814 struct GNUNET_SOCIAL_Slicer *slicer = rm_cls->slicer;
815 struct SlicerMethodCallbacks *rm_cbs = &rm_cls->rm_cbs;
816 struct SlicerMethodCallbacks *cbs = value;
818 if (cbs->method_cb == rm_cbs->method_cb
819 && cbs->modifier_cb == rm_cbs->modifier_cb
820 && cbs->data_cb == rm_cbs->data_cb
821 && cbs->eom_cb == rm_cbs->eom_cb)
823 GNUNET_CONTAINER_multihashmap_remove (slicer->method_handlers, key, cbs);
832 * Remove a registered method from the try-and-slice instance.
834 * Removes one matching handler registered with the given
835 * @a method_name and callbacks.
838 * The try-and-slice instance.
840 * Name of the method to remove.
848 * End of message handler.
850 * @return #GNUNET_OK if a method handler was removed,
851 * #GNUNET_NO if no handler matched the given method name and callbacks.
854 GNUNET_SOCIAL_slicer_method_remove (struct GNUNET_SOCIAL_Slicer *slicer,
855 const char *method_name,
856 GNUNET_SOCIAL_MethodCallback method_cb,
857 GNUNET_SOCIAL_ModifierCallback modifier_cb,
858 GNUNET_SOCIAL_DataCallback data_cb,
859 GNUNET_SOCIAL_EndOfMessageCallback eom_cb)
861 struct GNUNET_HashCode key;
862 GNUNET_CRYPTO_hash (method_name, strlen (method_name), &key);
864 struct SlicerMethodRemoveClosure rm_cls;
865 rm_cls.slicer = slicer;
866 struct SlicerMethodCallbacks *rm_cbs = &rm_cls.rm_cbs;
867 rm_cbs->method_cb = method_cb;
868 rm_cbs->modifier_cb = modifier_cb;
869 rm_cbs->data_cb = data_cb;
870 rm_cbs->eom_cb = eom_cb;
874 == GNUNET_CONTAINER_multihashmap_get_multiple (slicer->method_handlers, &key,
875 slicer_method_remove,
883 * Watch a place for changed objects.
886 * The try-and-slice instance.
887 * @param object_filter
888 * Object prefix to match.
890 * Function to call when encountering a state modifier.
892 * Closure for callback.
895 GNUNET_SOCIAL_slicer_modifier_add (struct GNUNET_SOCIAL_Slicer *slicer,
896 const char *object_filter,
897 GNUNET_SOCIAL_ModifierCallback modifier_cb,
900 struct SlicerModifierCallbacks *cbs = GNUNET_malloc (sizeof *cbs);
901 cbs->modifier_cb = modifier_cb;
904 struct GNUNET_HashCode key;
905 GNUNET_CRYPTO_hash (object_filter, strlen (object_filter), &key);
906 GNUNET_CONTAINER_multihashmap_put (slicer->modifier_handlers, &key, cbs,
907 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
912 slicer_modifier_remove (void *cls, const struct GNUNET_HashCode *key, void *value)
914 struct SlicerModifierRemoveClosure *rm_cls = cls;
915 struct GNUNET_SOCIAL_Slicer *slicer = rm_cls->slicer;
916 struct SlicerModifierCallbacks *rm_cbs = &rm_cls->rm_cbs;
917 struct SlicerModifierCallbacks *cbs = value;
919 if (cbs->modifier_cb == rm_cbs->modifier_cb)
921 GNUNET_CONTAINER_multihashmap_remove (slicer->modifier_handlers, key, cbs);
930 * Remove a registered modifier from the try-and-slice instance.
932 * Removes one matching handler registered with the given
933 * @a object_filter and @a modifier_cb.
936 * The try-and-slice instance.
937 * @param object_filter
938 * Object prefix to match.
940 * Function to call when encountering a state modifier changes.
943 GNUNET_SOCIAL_slicer_modifier_remove (struct GNUNET_SOCIAL_Slicer *slicer,
944 const char *object_filter,
945 GNUNET_SOCIAL_ModifierCallback modifier_cb)
947 struct GNUNET_HashCode key;
948 GNUNET_CRYPTO_hash (object_filter, strlen (object_filter), &key);
950 struct SlicerModifierRemoveClosure rm_cls;
951 rm_cls.slicer = slicer;
952 struct SlicerModifierCallbacks *rm_cbs = &rm_cls.rm_cbs;
953 rm_cbs->modifier_cb = modifier_cb;
957 == GNUNET_CONTAINER_multihashmap_get_multiple (slicer->modifier_handlers, &key,
958 slicer_modifier_remove,
966 slicer_method_free (void *cls, const struct GNUNET_HashCode *key, void *value)
968 struct SlicerMethodCallbacks *cbs = value;
975 * Destroy a given try-and-slice instance.
981 GNUNET_SOCIAL_slicer_destroy (struct GNUNET_SOCIAL_Slicer *slicer)
983 GNUNET_CONTAINER_multihashmap_iterate (slicer->method_handlers,
984 slicer_method_free, NULL);
985 GNUNET_CONTAINER_multihashmap_destroy (slicer->method_handlers);
986 GNUNET_free (slicer);
994 place_send_connect_msg (struct GNUNET_SOCIAL_Place *plc)
996 uint16_t cmsg_size = ntohs (plc->connect_msg->size);
997 struct GNUNET_MessageHeader * cmsg = GNUNET_malloc (cmsg_size);
998 memcpy (cmsg, plc->connect_msg, cmsg_size);
999 GNUNET_CLIENT_MANAGER_transmit_now (plc->client, cmsg);
1004 place_recv_disconnect (void *cls,
1005 struct GNUNET_CLIENT_MANAGER_Connection *client,
1006 const struct GNUNET_MessageHeader *msg)
1008 struct GNUNET_SOCIAL_Place *
1009 plc = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*plc));
1011 GNUNET_CLIENT_MANAGER_reconnect (client);
1012 place_send_connect_msg (plc);
1017 place_recv_result (void *cls,
1018 struct GNUNET_CLIENT_MANAGER_Connection *client,
1019 const struct GNUNET_MessageHeader *msg)
1021 struct GNUNET_SOCIAL_Place *
1022 plc = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*plc));
1024 const struct GNUNET_OperationResultMessage *
1025 res = (const struct GNUNET_OperationResultMessage *) msg;
1027 uint16_t size = ntohs (msg->size);
1028 if (size < sizeof (*res))
1029 { /* Error, message too small. */
1034 uint16_t data_size = size - sizeof (*res);
1035 const char *data = (0 < data_size) ? (const char *) &res[1] : NULL;
1036 GNUNET_CLIENT_MANAGER_op_result (plc->client, GNUNET_ntohll (res->op_id),
1037 GNUNET_ntohll (res->result_code),
1043 op_recv_history_result (void *cls, int64_t result,
1044 const void *err_msg, uint16_t err_msg_size)
1046 LOG (GNUNET_ERROR_TYPE_DEBUG,
1047 "Received history replay result: %" PRId64 ".\n", result);
1049 struct GNUNET_SOCIAL_HistoryRequest *hist = cls;
1051 if (NULL != hist->result_cb)
1052 hist->result_cb (hist->cls, result, err_msg, err_msg_size);
1054 GNUNET_PSYC_receive_destroy (hist->recv);
1060 op_recv_state_result (void *cls, int64_t result,
1061 const void *err_msg, uint16_t err_msg_size)
1063 LOG (GNUNET_ERROR_TYPE_DEBUG,
1064 "Received state request result: %" PRId64 ".\n", result);
1066 struct GNUNET_SOCIAL_LookHandle *look = cls;
1068 if (NULL != look->result_cb)
1069 look->result_cb (look->cls, result, err_msg, err_msg_size);
1076 place_recv_history_result (void *cls,
1077 struct GNUNET_CLIENT_MANAGER_Connection *client,
1078 const struct GNUNET_MessageHeader *msg)
1080 struct GNUNET_SOCIAL_Place *
1081 plc = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*plc));
1083 const struct GNUNET_OperationResultMessage *
1084 res = (const struct GNUNET_OperationResultMessage *) msg;
1085 struct GNUNET_PSYC_MessageHeader *
1086 pmsg = (struct GNUNET_PSYC_MessageHeader *) &res[1];
1088 LOG (GNUNET_ERROR_TYPE_DEBUG,
1089 "%p Received historic fragment for message #%" PRIu64 ".\n",
1090 plc, GNUNET_ntohll (pmsg->message_id));
1092 GNUNET_ResultCallback result_cb = NULL;
1093 struct GNUNET_SOCIAL_HistoryRequest *hist = NULL;
1095 if (GNUNET_YES != GNUNET_CLIENT_MANAGER_op_find (plc->client,
1096 GNUNET_ntohll (res->op_id),
1097 &result_cb, (void *) &hist))
1098 { /* Operation not found. */
1099 LOG (GNUNET_ERROR_TYPE_WARNING,
1100 "%p Replay operation not found for historic fragment of message #%"
1102 plc, GNUNET_ntohll (pmsg->message_id));
1106 uint16_t size = ntohs (msg->size);
1107 if (size < sizeof (*res) + sizeof (*pmsg))
1108 { /* Error, message too small. */
1113 GNUNET_PSYC_receive_message (hist->recv,
1114 (const struct GNUNET_PSYC_MessageHeader *) pmsg);
1119 place_recv_state_result (void *cls,
1120 struct GNUNET_CLIENT_MANAGER_Connection *client,
1121 const struct GNUNET_MessageHeader *msg)
1123 struct GNUNET_SOCIAL_Place *
1124 plc = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*plc));
1126 const struct GNUNET_OperationResultMessage *
1127 res = (const struct GNUNET_OperationResultMessage *) msg;
1129 GNUNET_ResultCallback result_cb = NULL;
1130 struct GNUNET_SOCIAL_LookHandle *look = NULL;
1132 if (GNUNET_YES != GNUNET_CLIENT_MANAGER_op_find (plc->client,
1133 GNUNET_ntohll (res->op_id),
1134 &result_cb, (void *) &look))
1135 { /* Operation not found. */
1139 const struct GNUNET_MessageHeader *
1140 mod = (struct GNUNET_MessageHeader *) &res[1];
1141 uint16_t mod_size = ntohs (mod->size);
1142 if (ntohs (msg->size) - sizeof (*res) != mod_size)
1144 GNUNET_break_op (0);
1145 LOG (GNUNET_ERROR_TYPE_WARNING,
1146 "Invalid modifier size in state result: %u - %u != %u\n",
1147 ntohs (msg->size), sizeof (*res), mod_size);
1150 switch (ntohs (mod->type))
1152 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MODIFIER:
1154 const struct GNUNET_PSYC_MessageModifier *
1155 pmod = (const struct GNUNET_PSYC_MessageModifier *) mod;
1157 const char *name = (const char *) &pmod[1];
1158 uint16_t name_size = ntohs (pmod->name_size);
1159 if ('\0' != name[name_size - 1])
1161 GNUNET_break_op (0);
1162 LOG (GNUNET_ERROR_TYPE_WARNING,
1163 "Invalid modifier name in state result\n");
1166 look->mod_value_size = ntohs (pmod->value_size);
1167 look->var_cb (look->cls, mod, name, name + name_size,
1168 mod_size - sizeof (*mod) - name_size,
1169 look->mod_value_size);
1170 if (look->mod_value_size > mod_size - sizeof (*mod) - name_size)
1172 look->mod_value_remaining = look->mod_value_size;
1173 look->mod_name = GNUNET_malloc (name_size);
1174 memcpy (look->mod_name, name, name_size);
1179 case GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_MOD_CONT:
1180 look->var_cb (look->cls, mod, look->mod_name, (const char *) &mod[1],
1181 mod_size - sizeof (*mod), look->mod_value_size);
1182 look->mod_value_remaining -= mod_size - sizeof (*mod);
1183 if (0 == look->mod_value_remaining)
1185 GNUNET_free (look->mod_name);
1193 place_recv_message_ack (void *cls,
1194 struct GNUNET_CLIENT_MANAGER_Connection *client,
1195 const struct GNUNET_MessageHeader *msg)
1197 struct GNUNET_SOCIAL_Place *
1198 plc = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*plc));
1199 GNUNET_PSYC_transmit_got_ack (plc->tmit);
1204 place_recv_message (void *cls,
1205 struct GNUNET_CLIENT_MANAGER_Connection *client,
1206 const struct GNUNET_MessageHeader *msg)
1208 struct GNUNET_SOCIAL_Place *
1209 plc = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*plc));
1210 GNUNET_PSYC_receive_message (plc->recv,
1211 (const struct GNUNET_PSYC_MessageHeader *) msg);
1216 host_recv_message (void *cls,
1217 struct GNUNET_CLIENT_MANAGER_Connection *client,
1218 const struct GNUNET_MessageHeader *msg)
1220 struct GNUNET_SOCIAL_Host *
1221 hst = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (hst->plc));
1222 GNUNET_PSYC_receive_message (hst->recv,
1223 (const struct GNUNET_PSYC_MessageHeader *) msg);
1224 GNUNET_PSYC_receive_message (hst->plc.recv,
1225 (const struct GNUNET_PSYC_MessageHeader *) msg);
1230 host_recv_enter_ack (void *cls,
1231 struct GNUNET_CLIENT_MANAGER_Connection *client,
1232 const struct GNUNET_MessageHeader *msg)
1234 struct GNUNET_SOCIAL_Host *
1235 hst = GNUNET_CLIENT_MANAGER_get_user_context_ (client,
1236 sizeof (struct GNUNET_SOCIAL_Place));
1238 struct GNUNET_PSYC_CountersResultMessage *
1239 cres = (struct GNUNET_PSYC_CountersResultMessage *) msg;
1240 int32_t result = ntohl (cres->result_code) + INT32_MIN;
1241 if (NULL != hst->enter_cb)
1242 hst->enter_cb (hst->cb_cls, result, GNUNET_ntohll (cres->max_message_id));
1247 host_recv_enter_request (void *cls,
1248 struct GNUNET_CLIENT_MANAGER_Connection *client,
1249 const struct GNUNET_MessageHeader *msg)
1251 struct GNUNET_SOCIAL_Host *
1252 hst = GNUNET_CLIENT_MANAGER_get_user_context_ (client,
1253 sizeof (struct GNUNET_SOCIAL_Place));
1254 if (NULL == hst->answer_door_cb)
1257 const char *method_name = NULL;
1258 struct GNUNET_ENV_Environment *env = NULL;
1259 const void *data = NULL;
1260 uint16_t data_size = 0;
1262 const struct GNUNET_PSYC_JoinRequestMessage *
1263 req = (const struct GNUNET_PSYC_JoinRequestMessage *) msg;
1264 const struct GNUNET_PSYC_Message *entry_msg = NULL;
1266 if (sizeof (*req) + sizeof (*entry_msg) <= ntohs (req->header.size))
1268 entry_msg = (struct GNUNET_PSYC_Message *) &req[1];
1269 LOG (GNUNET_ERROR_TYPE_DEBUG,
1270 "Received entry_msg of type %u and size %u.\n",
1271 ntohs (entry_msg->header.type), ntohs (entry_msg->header.size));
1273 env = GNUNET_ENV_environment_create ();
1274 if (GNUNET_OK != GNUNET_PSYC_message_parse (entry_msg, &method_name, env,
1277 GNUNET_break_op (0);
1278 str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&req->slave_key);
1279 LOG (GNUNET_ERROR_TYPE_WARNING,
1280 "Ignoring invalid entry request from nym %s.\n",
1283 GNUNET_ENV_environment_destroy (env);
1288 struct GNUNET_SOCIAL_Nym *nym = nym_get_or_create (&req->slave_key);
1289 hst->answer_door_cb (hst->cb_cls, nym, method_name, env,
1293 GNUNET_ENV_environment_destroy (env);
1298 guest_recv_enter_ack (void *cls,
1299 struct GNUNET_CLIENT_MANAGER_Connection *client,
1300 const struct GNUNET_MessageHeader *msg)
1302 struct GNUNET_SOCIAL_Guest *
1303 gst = GNUNET_CLIENT_MANAGER_get_user_context_ (client,
1304 sizeof (struct GNUNET_SOCIAL_Place));
1306 struct GNUNET_PSYC_CountersResultMessage *
1307 cres = (struct GNUNET_PSYC_CountersResultMessage *) msg;
1308 int32_t result = ntohl (cres->result_code) + INT32_MIN;
1309 if (NULL != gst->enter_cb)
1310 gst->enter_cb (gst->cb_cls, result, GNUNET_ntohll (cres->max_message_id));
1315 guest_recv_join_decision (void *cls,
1316 struct GNUNET_CLIENT_MANAGER_Connection *client,
1317 const struct GNUNET_MessageHeader *msg)
1319 struct GNUNET_SOCIAL_Guest *
1320 gst = GNUNET_CLIENT_MANAGER_get_user_context_ (client,
1321 sizeof (struct GNUNET_SOCIAL_Place));
1322 const struct GNUNET_PSYC_JoinDecisionMessage *
1323 dcsn = (const struct GNUNET_PSYC_JoinDecisionMessage *) msg;
1325 struct GNUNET_PSYC_Message *pmsg = NULL;
1326 if (ntohs (dcsn->header.size) <= sizeof (*dcsn) + sizeof (*pmsg))
1327 pmsg = (struct GNUNET_PSYC_Message *) &dcsn[1];
1329 if (NULL != gst->entry_dcsn_cb)
1330 gst->entry_dcsn_cb (gst->cb_cls, ntohl (dcsn->is_admitted), pmsg);
1334 static struct GNUNET_CLIENT_MANAGER_MessageHandler host_handlers[] =
1336 { host_recv_enter_ack, NULL,
1337 GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER_ACK,
1338 sizeof (struct GNUNET_PSYC_CountersResultMessage), GNUNET_NO },
1340 { host_recv_enter_request, NULL,
1341 GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST,
1342 sizeof (struct GNUNET_PSYC_JoinRequestMessage), GNUNET_YES },
1344 { host_recv_message, NULL,
1345 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
1346 sizeof (struct GNUNET_PSYC_MessageHeader), GNUNET_YES },
1348 { place_recv_message_ack, NULL,
1349 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK,
1350 sizeof (struct GNUNET_MessageHeader), GNUNET_NO },
1352 { place_recv_history_result, NULL,
1353 GNUNET_MESSAGE_TYPE_PSYC_HISTORY_RESULT,
1354 sizeof (struct GNUNET_OperationResultMessage), GNUNET_YES },
1356 { place_recv_state_result, NULL,
1357 GNUNET_MESSAGE_TYPE_PSYC_STATE_RESULT,
1358 sizeof (struct GNUNET_OperationResultMessage), GNUNET_YES },
1360 { place_recv_result, NULL,
1361 GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE,
1362 sizeof (struct GNUNET_OperationResultMessage), GNUNET_YES },
1364 { place_recv_disconnect, NULL, 0, 0, GNUNET_NO },
1366 { NULL, NULL, 0, 0, GNUNET_NO }
1370 static struct GNUNET_CLIENT_MANAGER_MessageHandler guest_handlers[] =
1372 { guest_recv_enter_ack, NULL,
1373 GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK,
1374 sizeof (struct GNUNET_PSYC_CountersResultMessage), GNUNET_NO },
1376 { host_recv_enter_request, NULL,
1377 GNUNET_MESSAGE_TYPE_PSYC_JOIN_REQUEST,
1378 sizeof (struct GNUNET_PSYC_JoinRequestMessage), GNUNET_YES },
1380 { place_recv_message, NULL,
1381 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE,
1382 sizeof (struct GNUNET_PSYC_MessageHeader), GNUNET_YES },
1384 { place_recv_message_ack, NULL,
1385 GNUNET_MESSAGE_TYPE_PSYC_MESSAGE_ACK,
1386 sizeof (struct GNUNET_MessageHeader), GNUNET_NO },
1388 { guest_recv_join_decision, NULL,
1389 GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION,
1390 sizeof (struct GNUNET_PSYC_JoinDecisionMessage), GNUNET_YES },
1392 { place_recv_history_result, NULL,
1393 GNUNET_MESSAGE_TYPE_PSYC_HISTORY_RESULT,
1394 sizeof (struct GNUNET_OperationResultMessage), GNUNET_YES },
1396 { place_recv_state_result, NULL,
1397 GNUNET_MESSAGE_TYPE_PSYC_STATE_RESULT,
1398 sizeof (struct GNUNET_OperationResultMessage), GNUNET_YES },
1400 { place_recv_result, NULL,
1401 GNUNET_MESSAGE_TYPE_PSYC_RESULT_CODE,
1402 sizeof (struct GNUNET_OperationResultMessage), GNUNET_YES },
1404 { place_recv_disconnect, NULL, 0, 0, GNUNET_NO },
1406 { NULL, NULL, 0, 0, GNUNET_NO }
1411 place_cleanup (struct GNUNET_SOCIAL_Place *plc)
1413 GNUNET_PSYC_transmit_destroy (plc->tmit);
1414 GNUNET_PSYC_receive_destroy (plc->recv);
1415 GNUNET_free (plc->connect_msg);
1416 if (NULL != plc->disconnect_cb)
1417 plc->disconnect_cb (plc->disconnect_cls);
1422 host_cleanup (void *cls)
1424 struct GNUNET_SOCIAL_Host *hst = cls;
1425 place_cleanup (&hst->plc);
1426 GNUNET_PSYC_receive_destroy (hst->recv);
1427 GNUNET_SOCIAL_slicer_destroy (hst->slicer);
1433 guest_cleanup (void *cls)
1435 struct GNUNET_SOCIAL_Guest *gst = cls;
1436 place_cleanup (&gst->plc);
1444 * Enter a place as host.
1446 * A place is created upon first entering, and it is active until permanently
1447 * left using GNUNET_SOCIAL_host_leave().
1450 * Configuration to contact the social service.
1452 * Identity of the host.
1454 * Private-public key pair of the place.
1455 * NULL for ephemeral places.
1457 * Policy specifying entry and history restrictions for the place.
1459 * Slicer to handle incoming messages.
1460 * @param answer_door_cb
1461 * Function to handle new nyms that want to enter.
1462 * @param farewell_cb
1463 * Function to handle departing nyms.
1465 * Closure for the callbacks.
1467 * @return Handle for the host.
1469 struct GNUNET_SOCIAL_Host *
1470 GNUNET_SOCIAL_host_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
1471 const struct GNUNET_IDENTITY_Ego *ego,
1472 const struct GNUNET_CRYPTO_EddsaPrivateKey *place_key,
1473 enum GNUNET_PSYC_Policy policy,
1474 struct GNUNET_SOCIAL_Slicer *slicer,
1475 GNUNET_SOCIAL_HostEnterCallback enter_cb,
1476 GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb,
1477 GNUNET_SOCIAL_FarewellCallback farewell_cb,
1480 struct GNUNET_SOCIAL_Host *hst = GNUNET_malloc (sizeof (*hst));
1481 struct GNUNET_SOCIAL_Place *plc = &hst->plc;
1482 struct HostEnterRequest *req = GNUNET_malloc (sizeof (*req));
1484 if (NULL != place_key)
1486 hst->place_key = *place_key;
1490 struct GNUNET_CRYPTO_EddsaPrivateKey *
1491 ephemeral_key = GNUNET_CRYPTO_eddsa_key_create ();
1492 hst->place_key = *ephemeral_key;
1493 GNUNET_CRYPTO_eddsa_key_get_public (&hst->place_key, &plc->pub_key);
1494 GNUNET_CRYPTO_eddsa_key_clear (ephemeral_key);
1495 GNUNET_free (ephemeral_key);
1497 plc->ego_key = *GNUNET_IDENTITY_ego_get_private_key (ego);
1499 req->header.size = htons (sizeof (*req));
1500 req->header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER);
1501 req->policy = policy;
1502 req->place_key = hst->place_key;
1503 req->host_key = plc->ego_key;
1505 plc->connect_msg = (struct GNUNET_MessageHeader *) req;
1507 plc->is_host = GNUNET_YES;
1508 plc->slicer = slicer;
1510 hst->plc.ego_key = *GNUNET_IDENTITY_ego_get_private_key (ego);
1511 hst->enter_cb = enter_cb;
1512 hst->answer_door_cb = answer_door_cb;
1513 hst->farewell_cb = farewell_cb;
1516 plc->client = GNUNET_CLIENT_MANAGER_connect (cfg, "social", host_handlers);
1517 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, hst, sizeof (*plc));
1519 plc->tmit = GNUNET_PSYC_transmit_create (plc->client);
1520 plc->recv = GNUNET_PSYC_receive_create (NULL, slicer_message, plc->slicer);
1522 hst->slicer = GNUNET_SOCIAL_slicer_create ();
1523 GNUNET_SOCIAL_slicer_method_add (hst->slicer, "_notice_place_leave",
1524 host_recv_notice_place_leave_method,
1525 host_recv_notice_place_leave_modifier,
1526 NULL, host_recv_notice_place_leave_eom, hst);
1527 hst->recv = GNUNET_PSYC_receive_create (NULL, slicer_message, hst->slicer);
1529 place_send_connect_msg (plc);
1535 * Enter a place as host.
1537 * A place is created upon first entering, and it is active until permanently
1538 * left using GNUNET_SOCIAL_host_leave().
1541 * Configuration to contact the social service.
1543 * Identity of the host.
1545 * GNS name in the zone of the @a ego that contains the
1546 * public key of the place in a PLACE record.
1548 * Policy specifying entry and history restrictions for the place.
1550 * Slicer to handle incoming messages.
1551 * @param answer_door_cb
1552 * Function to handle new nyms that want to enter.
1553 * @param farewell_cb
1554 * Function to handle departing nyms.
1556 * Closure for the callbacks.
1558 * @return Handle for the host.
1560 struct GNUNET_SOCIAL_Host *
1561 GNUNET_SOCIAL_host_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
1562 struct GNUNET_IDENTITY_Ego *ego,
1563 const char *gns_name,
1564 enum GNUNET_PSYC_Policy policy,
1565 struct GNUNET_SOCIAL_Slicer *slicer,
1566 GNUNET_SOCIAL_HostEnterCallback enter_cb,
1567 GNUNET_SOCIAL_AnswerDoorCallback answer_door_cb,
1568 GNUNET_SOCIAL_FarewellCallback farewell_cb,
1571 struct GNUNET_CRYPTO_EddsaPrivateKey place_key = {};
1574 * 1. get public key by looking up PLACE entry under gns_name
1575 * in the zone of the ego.
1576 * 2. get private key from $GNUNET_DATA_HOME/social/places/PUB_KEY_HASH
1579 return GNUNET_SOCIAL_host_enter (cfg, ego, &place_key, policy, slicer,
1580 enter_cb, answer_door_cb, farewell_cb, cls);
1585 * Decision whether to admit @a nym into the place or refuse entry.
1588 * Host of the place.
1590 * Handle for the entity that wanted to enter.
1591 * @param is_admitted
1592 * #GNUNET_YES if @a nym is admitted,
1593 * #GNUNET_NO if @a nym is refused entry,
1594 * #GNUNET_SYSERR if we cannot answer the request.
1595 * @param method_name
1596 * Method name for the rejection message.
1598 * Environment containing variables for the message, or NULL.
1600 * Data for the rejection message to send back.
1602 * Number of bytes in @a data for method.
1603 * @return #GNUNET_OK on success,
1604 * #GNUNET_SYSERR if the message is too large.
1607 GNUNET_SOCIAL_host_entry_decision (struct GNUNET_SOCIAL_Host *hst,
1608 struct GNUNET_SOCIAL_Nym *nym,
1610 const struct GNUNET_PSYC_Message *entry_resp)
1612 struct GNUNET_PSYC_JoinDecisionMessage *dcsn;
1613 uint16_t entry_resp_size
1614 = (NULL != entry_resp) ? ntohs (entry_resp->header.size) : 0;
1616 if (GNUNET_MULTICAST_FRAGMENT_MAX_PAYLOAD < sizeof (*dcsn) + entry_resp_size)
1617 return GNUNET_SYSERR;
1619 dcsn = GNUNET_malloc (sizeof (*dcsn) + entry_resp_size);
1620 dcsn->header.size = htons (sizeof (*dcsn) + entry_resp_size);
1621 dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION);
1622 dcsn->is_admitted = htonl (is_admitted);
1623 dcsn->slave_key = nym->pub_key;
1625 if (0 < entry_resp_size)
1626 memcpy (&dcsn[1], entry_resp, entry_resp_size);
1628 GNUNET_CLIENT_MANAGER_transmit (hst->plc.client, &dcsn->header);
1634 * Throw @a nym out of the place.
1636 * The @a nym reference will remain valid until the
1637 * #GNUNET_SOCIAL_FarewellCallback is invoked,
1638 * which should be very soon after this call.
1641 * Host of the place.
1643 * Handle for the entity to be ejected.
1646 GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *hst,
1647 const struct GNUNET_SOCIAL_Nym *nym)
1649 struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create ();
1650 GNUNET_ENV_environment_add (env, GNUNET_ENV_OP_SET,
1651 "_nym", &nym->pub_key, sizeof (nym->pub_key));
1652 GNUNET_SOCIAL_host_announce (hst, "_notice_place_leave", env, NULL, NULL,
1653 GNUNET_SOCIAL_ANNOUNCE_NONE);
1658 * Get the public key of a @a nym.
1660 * Suitable, for example, to be used with GNUNET_NAMESTORE_zone_to_name().
1663 * Pseudonym to map to a cryptographic identifier.
1664 * @param[out] nym_key
1665 * Set to the public key of the nym.
1667 const struct GNUNET_CRYPTO_EcdsaPublicKey *
1668 GNUNET_SOCIAL_nym_get_key (const struct GNUNET_SOCIAL_Nym *nym)
1670 return &nym->pub_key;
1675 * Obtain the private-public key pair of the hosted place.
1677 * The public part is suitable for storing in GNS within a PLACE record,
1678 * along with peer IDs to join at.
1681 * Host of the place.
1683 * @return Private-public key pair of the hosted place.
1685 const struct GNUNET_CRYPTO_EddsaPrivateKey *
1686 GNUNET_SOCIAL_host_get_place_key (struct GNUNET_SOCIAL_Host *hst)
1688 return &hst->place_key;
1693 namestore_result_host_advertise (void *cls, int32_t success, const char *emsg)
1700 * Connected to core service.
1703 core_connected_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity)
1705 this_peer = *my_identity;
1711 * Advertise the place in the GNS zone of the @e ego of the @a host.
1713 * @param hst Host of the place.
1714 * @param name The name for the PLACE record to put in the zone.
1715 * @param peer_count Number of elements in the @a peers array.
1716 * @param peers List of peers in the PLACE record that can be used to send join
1718 * @param expiration_time Expiration time of the record, use 0 to remove the record.
1719 * @param password Password used to encrypt the record.
1722 GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *hst,
1725 const struct GNUNET_PeerIdentity *peers,
1726 struct GNUNET_TIME_Relative expiration_time,
1727 const char *password)
1729 struct GNUNET_SOCIAL_Place *plc = &hst->plc;
1730 if (NULL == namestore)
1731 namestore = GNUNET_NAMESTORE_connect (plc->cfg);
1733 core = GNUNET_CORE_connect (plc->cfg, NULL, core_connected_cb, NULL, NULL,
1734 NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
1736 struct GNUNET_GNSRECORD_Data rd = { 0 };
1737 rd.record_type = GNUNET_GNSRECORD_TYPE_PLACE;
1738 rd.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
1740 = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_WEEKS, 1).rel_value_us;
1742 struct GNUNET_GNSRECORD_PlaceData *rec = GNUNET_malloc (sizeof (*rec));
1743 rec->place_key = plc->pub_key;
1744 rec->origin = this_peer;
1745 rec->relay_count = htons (0); // FIXME
1747 rd.data_size = sizeof (*rec);
1750 GNUNET_NAMESTORE_records_store (namestore, &hst->plc.ego_key,
1751 name, 1, &rd, namestore_result_host_advertise,
1757 * Send a message to all nyms that are present in the place.
1759 * This function is restricted to the host. Nyms can only send requests
1760 * to the host who can decide to relay it to everyone in the place.
1762 * @param host Host of the place.
1763 * @param method_name Method to use for the announcement.
1764 * @param env Environment containing variables for the message and operations
1765 * on objects of the place. Can be NULL.
1766 * @param notify Function to call to get the payload of the announcement.
1767 * @param notify_cls Closure for @a notify.
1768 * @param flags Flags for this announcement.
1770 * @return NULL on error (announcement already in progress?).
1772 struct GNUNET_SOCIAL_Announcement *
1773 GNUNET_SOCIAL_host_announce (struct GNUNET_SOCIAL_Host *hst,
1774 const char *method_name,
1775 const struct GNUNET_ENV_Environment *env,
1776 GNUNET_PSYC_TransmitNotifyData notify_data,
1777 void *notify_data_cls,
1778 enum GNUNET_SOCIAL_AnnounceFlags flags)
1781 GNUNET_PSYC_transmit_message (hst->plc.tmit, method_name, env,
1782 NULL, notify_data, notify_data_cls, flags));
1783 return (struct GNUNET_SOCIAL_Announcement *) hst->plc.tmit;
1788 * Resume transmitting announcement.
1791 * The announcement to resume.
1794 GNUNET_SOCIAL_host_announce_resume (struct GNUNET_SOCIAL_Announcement *a)
1796 GNUNET_PSYC_transmit_resume ((struct GNUNET_PSYC_TransmitHandle *) a);
1801 * Cancel announcement.
1804 * The announcement to cancel.
1807 GNUNET_SOCIAL_host_announce_cancel (struct GNUNET_SOCIAL_Announcement *a)
1809 GNUNET_PSYC_transmit_cancel ((struct GNUNET_PSYC_TransmitHandle *) a);
1814 * Obtain handle for a hosted place.
1816 * The returned handle can be used to access the place API.
1818 * @param host Handle for the host.
1820 * @return Handle for the hosted place, valid as long as @a host is valid.
1822 struct GNUNET_SOCIAL_Place *
1823 GNUNET_SOCIAL_host_get_place (struct GNUNET_SOCIAL_Host *hst)
1830 * Stop hosting a place.
1832 * Invalidates host handle.
1834 * @param host Host leaving the place.
1835 * @param keep_active Keep the place active after last host disconnected.
1838 GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *hst,
1840 GNUNET_ContinuationCallback leave_cb,
1843 struct GNUNET_SOCIAL_Place *plc = &hst->plc;
1845 /* FIXME: send msg to service */
1847 plc->is_disconnecting = GNUNET_YES;
1848 plc->disconnect_cb = leave_cb;
1849 plc->disconnect_cls = leave_cls;
1851 GNUNET_CLIENT_MANAGER_disconnect (plc->client, GNUNET_YES,
1852 &host_cleanup, hst);
1858 static struct GuestEnterRequest *
1859 guest_enter_request_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *guest_key,
1860 const struct GNUNET_CRYPTO_EddsaPublicKey *place_key,
1861 const struct GNUNET_PeerIdentity *origin,
1863 const struct GNUNET_PeerIdentity *relays,
1864 const struct GNUNET_PSYC_Message *join_msg)
1866 uint16_t join_msg_size = ntohs (join_msg->header.size);
1867 uint16_t relay_size = relay_count * sizeof (*relays);
1869 struct GuestEnterRequest *
1870 req = GNUNET_malloc (sizeof (*req) + relay_size + join_msg_size);
1872 req->header.size = htons (sizeof (*req) + relay_size + join_msg_size);
1873 req->header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER);
1874 req->place_key = *place_key;
1875 req->guest_key = *guest_key;
1876 req->origin = *origin;
1877 req->relay_count = relay_count;
1879 uint16_t p = sizeof (*req);
1882 memcpy ((char *) req + p, relays, relay_size);
1886 memcpy ((char *) req + p, join_msg, join_msg_size);
1891 * Request entry to a place as a guest.
1893 * @param cfg Configuration to contact the social service.
1894 * @param ego Identity of the guest.
1895 * @param crypto_address Public key of the place to enter.
1896 * @param origin Peer identity of the origin of the underlying multicast group.
1897 * @param relay_count Number of elements in the @a relays array.
1898 * @param relays Relays for the underlying multicast group.
1899 * @param method_name Method name for the message.
1900 * @param env Environment containing variables for the message, or NULL.
1901 * @param data Payload for the message to give to the enter callback.
1902 * @param data_size Number of bytes in @a data.
1903 * @param slicer Slicer to use for processing incoming requests from guests.
1905 * @return NULL on errors, otherwise handle for the guest.
1907 struct GNUNET_SOCIAL_Guest *
1908 GNUNET_SOCIAL_guest_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
1909 const struct GNUNET_IDENTITY_Ego *ego,
1910 const struct GNUNET_CRYPTO_EddsaPublicKey *place_key,
1911 const struct GNUNET_PeerIdentity *origin,
1912 uint32_t relay_count,
1913 const struct GNUNET_PeerIdentity *relays,
1914 const struct GNUNET_PSYC_Message *entry_msg,
1915 struct GNUNET_SOCIAL_Slicer *slicer,
1916 GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
1917 GNUNET_SOCIAL_EntryDecisionCallback entry_dcsn_cb,
1920 struct GNUNET_SOCIAL_Guest *gst = GNUNET_malloc (sizeof (*gst));
1921 struct GNUNET_SOCIAL_Place *plc = &gst->plc;
1923 plc->ego_key = *GNUNET_IDENTITY_ego_get_private_key (ego);
1924 plc->pub_key = *place_key;
1926 plc->is_host = GNUNET_YES;
1927 plc->slicer = slicer;
1929 gst->enter_cb = local_enter_cb;
1930 gst->entry_dcsn_cb = entry_dcsn_cb;
1933 plc->client = GNUNET_CLIENT_MANAGER_connect (cfg, "social", guest_handlers);
1934 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, gst, sizeof (*plc));
1936 plc->tmit = GNUNET_PSYC_transmit_create (plc->client);
1937 plc->recv = GNUNET_PSYC_receive_create (NULL, slicer_message, plc->slicer);
1939 struct GuestEnterRequest *
1940 req = guest_enter_request_create (&plc->ego_key, place_key, origin,
1941 relay_count, relays, entry_msg);
1942 plc->connect_msg = &req->header;
1943 place_send_connect_msg (plc);
1949 * Result of a GNS name lookup for entering a place.
1951 * @see GNUNET_SOCIAL_guest_enter_by_name
1954 gns_result_guest_enter (void *cls, uint32_t rd_count,
1955 const struct GNUNET_GNSRECORD_Data *rd)
1957 struct GNUNET_SOCIAL_Guest *gst = cls;
1958 struct GNUNET_SOCIAL_Place *plc = &gst->plc;
1960 const struct GNUNET_GNSRECORD_PlaceData *
1961 rec = (const struct GNUNET_GNSRECORD_PlaceData *) rd->data;
1965 if (NULL != gst->enter_cb)
1966 gst->enter_cb (gst->cb_cls, GNUNET_SYSERR, 0);
1971 if (rd->data_size < sizeof (*rec))
1973 GNUNET_break_op (0);
1974 if (NULL != gst->enter_cb)
1975 gst->enter_cb (gst->cb_cls, GNUNET_SYSERR, 0);
1979 struct GuestEnterRequest *
1980 req = (struct GuestEnterRequest *) plc->connect_msg;
1981 uint16_t req_size = ntohs (req->header.size);
1982 uint16_t relay_count = ntohs (rec->relay_count);
1984 if (0 < relay_count)
1986 if (rd->data_size == sizeof (*rec) + relay_count * sizeof (struct GNUNET_PeerIdentity))
1988 struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &rec[1];
1989 uint16_t relay_size = relay_count * sizeof (struct GNUNET_PeerIdentity);
1990 struct GuestEnterRequest *
1991 req2 = GNUNET_malloc (req_size + relay_size);
1993 req2->header.size = htons (req_size + relay_size);
1994 req2->header.type = req->header.type;
1995 req2->guest_key = req->guest_key;
1997 uint16_t p = sizeof (*req);
2000 memcpy ((char *) req2 + p, relays, relay_size);
2004 memcpy ((char *) req + p, &req[1], req_size - sizeof (*req));
2006 plc->connect_msg = &req2->header;
2012 GNUNET_break_op (0);
2016 req->place_key = rec->place_key;
2017 req->origin = rec->origin;
2018 req->relay_count = rec->relay_count;
2019 memcpy (&req[1], &rec[1],
2020 ntohl (rec->relay_count) * sizeof (struct GNUNET_PeerIdentity));
2022 plc->connect_msg = &req->header;
2023 plc->pub_key = req->place_key;
2025 plc->tmit = GNUNET_PSYC_transmit_create (plc->client);
2026 plc->recv = GNUNET_PSYC_receive_create (NULL, slicer_message, plc);
2028 place_send_connect_msg (plc);
2032 * Request entry to a place as a guest.
2034 * @param cfg Configuration to contact the social service.
2035 * @param ego Identity of the guest.
2036 * @param address GNS name of the place to enter. Either in the form of
2037 * 'room.friend.gnu', or 'NYMPUBKEY.zkey'. This latter case refers to
2038 * the 'PLACE' record of the empty label ("+") in the GNS zone with the
2039 * nym's public key 'NYMPUBKEY', and can be used to request entry to a
2040 * pseudonym's place directly.
2041 * @param method_name Method name for the message.
2042 * @param env Environment containing variables for the message, or NULL.
2043 * @param data Payload for the message to give to the enter callback.
2044 * @param data_size Number of bytes in @a data.
2045 * @param slicer Slicer to use for processing incoming requests from guests.
2047 * @return NULL on errors, otherwise handle for the guest.
2049 struct GNUNET_SOCIAL_Guest *
2050 GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
2051 struct GNUNET_IDENTITY_Ego *ego,
2053 const struct GNUNET_PSYC_Message *join_msg,
2054 struct GNUNET_SOCIAL_Slicer *slicer,
2055 GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
2056 GNUNET_SOCIAL_EntryDecisionCallback entry_decision_cb,
2059 struct GNUNET_SOCIAL_Guest *gst = GNUNET_malloc (sizeof (*gst));
2060 struct GNUNET_SOCIAL_Place *plc = &gst->plc;
2062 gst->enter_cb = local_enter_cb;
2065 plc->ego_key = *GNUNET_IDENTITY_ego_get_private_key (ego);
2067 plc->is_host = GNUNET_NO;
2068 plc->slicer = slicer;
2070 struct GuestEnterRequest *
2071 req = guest_enter_request_create (&plc->ego_key, NULL, NULL, 0, NULL,
2073 plc->connect_msg = &req->header;
2075 /* FIXME: get the public key of the origin and relays
2076 * by looking up the PLACE record of gns_name.
2079 gns = GNUNET_GNS_connect (cfg);
2081 plc->client = GNUNET_CLIENT_MANAGER_connect (cfg, "social", guest_handlers);
2082 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, gst, sizeof (*plc));
2084 struct GNUNET_CRYPTO_EcdsaPublicKey ego_pub_key;
2085 GNUNET_IDENTITY_ego_get_public_key (ego, &ego_pub_key);
2086 GNUNET_GNS_lookup (gns, gns_name, &ego_pub_key,
2087 GNUNET_GNSRECORD_TYPE_PLACE, GNUNET_GNS_LO_DEFAULT,
2088 NULL, gns_result_guest_enter, gst);
2095 * Talk to the host of the place.
2098 * Place where we want to talk to the host.
2099 * @param method_name
2100 * Method to invoke on the host.
2102 * Environment containing variables for the message, or NULL.
2103 * @param notify_data
2104 * Function to use to get the payload for the method.
2105 * @param notify_data_cls
2106 * Closure for @a notify_data.
2108 * Flags for the message being sent.
2110 * @return NULL if we are already trying to talk to the host,
2111 * otherwise handle to cancel the request.
2113 struct GNUNET_SOCIAL_TalkRequest *
2114 GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *gst,
2115 const char *method_name,
2116 const struct GNUNET_ENV_Environment *env,
2117 GNUNET_PSYC_TransmitNotifyData notify_data,
2118 void *notify_data_cls,
2119 enum GNUNET_SOCIAL_TalkFlags flags)
2122 GNUNET_PSYC_transmit_message (gst->plc.tmit, method_name, env,
2123 NULL, notify_data, notify_data_cls, flags));
2124 return (struct GNUNET_SOCIAL_TalkRequest *) gst->plc.tmit;
2129 * Resume talking to the host of the place.
2132 * Talk request to resume.
2135 GNUNET_SOCIAL_guest_talk_resume (struct GNUNET_SOCIAL_TalkRequest *tr)
2137 GNUNET_PSYC_transmit_resume ((struct GNUNET_PSYC_TransmitHandle *) tr);
2142 * Cancel talking to the host of the place.
2145 * Talk request to cancel.
2148 GNUNET_SOCIAL_guest_talk_cancel (struct GNUNET_SOCIAL_TalkRequest *tr)
2150 GNUNET_PSYC_transmit_cancel ((struct GNUNET_PSYC_TransmitHandle *) tr);
2155 * Leave a place temporarily or permanently.
2157 * Notifies the owner of the place about leaving, and destroys the place handle.
2161 * @param keep_active
2162 * Keep place active after last application disconnected.
2163 * #GNUNET_YES or #GNUNET_NO
2165 * Optional environment for the leave message if @a keep_active
2166 * is #GNUNET_NO. NULL if not needed.
2168 * Called upon disconnecting from the social service.
2171 GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst,
2173 struct GNUNET_ENV_Environment *env,
2174 GNUNET_ContinuationCallback leave_cb,
2177 struct GNUNET_SOCIAL_Place *plc = &gst->plc;
2179 /* FIXME: send msg to service */
2181 plc->is_disconnecting = GNUNET_YES;
2182 plc->disconnect_cb = leave_cb;
2183 plc->disconnect_cls = leave_cls;
2185 if (GNUNET_NO == keep_active)
2187 GNUNET_SOCIAL_guest_talk (gst, "_notice_place_leave", env, NULL, NULL,
2188 GNUNET_SOCIAL_TALK_NONE);
2191 GNUNET_CLIENT_MANAGER_disconnect (plc->client, GNUNET_YES,
2192 &guest_cleanup, gst);
2197 * Obtain handle for a place entered as guest.
2199 * The returned handle can be used to access the place API.
2201 * @param guest Handle for the guest.
2203 * @return Handle for the place, valid as long as @a guest is valid.
2205 struct GNUNET_SOCIAL_Place *
2206 GNUNET_SOCIAL_guest_get_place (struct GNUNET_SOCIAL_Guest *gst)
2212 static struct GNUNET_SOCIAL_HistoryRequest *
2213 place_history_replay (struct GNUNET_SOCIAL_Place *plc,
2214 uint64_t start_message_id,
2215 uint64_t end_message_id,
2216 uint64_t message_limit,
2217 const char *method_prefix,
2219 struct GNUNET_SOCIAL_Slicer *slicer,
2220 GNUNET_ResultCallback result_cb,
2223 struct GNUNET_PSYC_HistoryRequestMessage *req;
2224 struct GNUNET_SOCIAL_HistoryRequest *hist = GNUNET_malloc (sizeof (*hist));
2226 hist->recv = GNUNET_PSYC_receive_create (NULL, slicer_message, slicer);
2227 hist->result_cb = result_cb;
2229 hist->op_id = GNUNET_CLIENT_MANAGER_op_add (plc->client,
2230 &op_recv_history_result, hist);
2232 GNUNET_assert (NULL != method_prefix);
2233 uint16_t method_size = strnlen (method_prefix,
2234 GNUNET_SERVER_MAX_MESSAGE_SIZE
2235 - sizeof (*req)) + 1;
2236 GNUNET_assert ('\0' == method_prefix[method_size - 1]);
2237 req = GNUNET_malloc (sizeof (*req) + method_size);
2238 req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_HISTORY_REPLAY);
2239 req->header.size = htons (sizeof (*req) + method_size);
2240 req->start_message_id = GNUNET_htonll (start_message_id);
2241 req->end_message_id = GNUNET_htonll (end_message_id);
2242 req->message_limit = GNUNET_htonll (message_limit);
2243 req->flags = htonl (flags);
2244 req->op_id = GNUNET_htonll (hist->op_id);
2245 memcpy (&req[1], method_prefix, method_size);
2247 GNUNET_CLIENT_MANAGER_transmit (plc->client, &req->header);
2253 * Learn about the history of a place.
2255 * Messages are returned through the @a slicer function
2256 * and have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
2259 * Place we want to learn more about.
2260 * @param start_message_id
2261 * First historic message we are interested in.
2262 * @param end_message_id
2263 * Last historic message we are interested in (inclusive).
2264 * @param method_prefix
2265 * Only retrieve messages with this method prefix.
2267 * OR'ed GNUNET_PSYC_HistoryReplayFlags
2269 * Slicer to use for retrieved messages.
2270 * Can be the same as the slicer of the place.
2272 * Function called after all messages retrieved.
2273 * NULL if not needed.
2274 * @param cls Closure for @a result_cb.
2276 struct GNUNET_SOCIAL_HistoryRequest *
2277 GNUNET_SOCIAL_place_history_replay (struct GNUNET_SOCIAL_Place *plc,
2278 uint64_t start_message_id,
2279 uint64_t end_message_id,
2280 const char *method_prefix,
2282 struct GNUNET_SOCIAL_Slicer *slicer,
2283 GNUNET_ResultCallback result_cb,
2286 return place_history_replay (plc, start_message_id, end_message_id, 0,
2287 method_prefix, flags, slicer, result_cb, cls);
2292 * Learn about the history of a place.
2294 * Sends messages through the slicer function of the place where
2295 * start_message_id <= message_id <= end_message_id.
2296 * The messages will have the #GNUNET_PSYC_MESSAGE_HISTORIC flag set.
2298 * To get the latest message, use 0 for both the start and end message ID.
2301 * Place we want to learn more about.
2302 * @param message_limit
2303 * Maximum number of historic messages we are interested in.
2304 * @param method_prefix
2305 * Only retrieve messages with this method prefix.
2307 * OR'ed GNUNET_PSYC_HistoryReplayFlags
2309 * Function called after all messages retrieved.
2310 * NULL if not needed.
2311 * @param cls Closure for @a result_cb.
2313 struct GNUNET_SOCIAL_HistoryRequest *
2314 GNUNET_SOCIAL_place_history_replay_latest (struct GNUNET_SOCIAL_Place *plc,
2315 uint64_t message_limit,
2316 const char *method_prefix,
2318 struct GNUNET_SOCIAL_Slicer *slicer,
2319 GNUNET_ResultCallback result_cb,
2322 return place_history_replay (plc, 0, 0, message_limit, method_prefix, flags,
2323 slicer, result_cb, cls);
2328 * Cancel learning about the history of a place.
2331 * History lesson to cancel.
2334 GNUNET_SOCIAL_place_history_replay_cancel (struct GNUNET_SOCIAL_HistoryRequest *hist)
2336 GNUNET_PSYC_receive_destroy (hist->recv);
2337 GNUNET_CLIENT_MANAGER_op_cancel (hist->plc->client, hist->op_id);
2343 * Request matching state variables.
2345 static struct GNUNET_SOCIAL_LookHandle *
2346 place_state_get (struct GNUNET_SOCIAL_Place *plc,
2347 uint16_t type, const char *name,
2348 GNUNET_PSYC_StateVarCallback var_cb,
2349 GNUNET_ResultCallback result_cb, void *cls)
2351 struct GNUNET_PSYC_StateRequestMessage *req;
2352 struct GNUNET_SOCIAL_LookHandle *look = GNUNET_malloc (sizeof (*look));
2354 look->var_cb = var_cb;
2355 look->result_cb = result_cb;
2357 look->op_id = GNUNET_CLIENT_MANAGER_op_add (plc->client,
2358 &op_recv_state_result, look);
2360 GNUNET_assert (NULL != name);
2361 size_t name_size = strnlen (name, GNUNET_SERVER_MAX_MESSAGE_SIZE
2362 - sizeof (*req)) + 1;
2363 req = GNUNET_malloc (sizeof (*req) + name_size);
2364 req->header.type = htons (type);
2365 req->header.size = htons (sizeof (*req) + name_size);
2366 req->op_id = GNUNET_htonll (look->op_id);
2367 memcpy (&req[1], name, name_size);
2369 GNUNET_CLIENT_MANAGER_transmit (plc->client, &req->header);
2375 * Look at a particular object in the place.
2377 * The best matching object is returned (its name might be less specific than
2378 * what was requested).
2381 * The place where to look.
2383 * Full name of the object.
2385 * Set to the size of the returned value.
2387 * @return NULL if there is no such object at this place.
2389 struct GNUNET_SOCIAL_LookHandle *
2390 GNUNET_SOCIAL_place_look_at (struct GNUNET_SOCIAL_Place *plc,
2391 const char *full_name,
2392 GNUNET_PSYC_StateVarCallback var_cb,
2393 GNUNET_ResultCallback result_cb,
2396 return place_state_get (plc, GNUNET_MESSAGE_TYPE_PSYC_STATE_GET,
2397 full_name, var_cb, result_cb, cls);
2402 * Look for objects in the place with a matching name prefix.
2405 * The place where to look.
2406 * @param name_prefix
2407 * Look at objects with names beginning with this value.
2409 * Function to call for each object found.
2411 * Closure for callback function.
2413 * @return Handle that can be used to stop looking at objects.
2415 struct GNUNET_SOCIAL_LookHandle *
2416 GNUNET_SOCIAL_place_look_for (struct GNUNET_SOCIAL_Place *plc,
2417 const char *name_prefix,
2418 GNUNET_PSYC_StateVarCallback var_cb,
2419 GNUNET_ResultCallback result_cb,
2422 return place_state_get (plc, GNUNET_MESSAGE_TYPE_PSYC_STATE_GET_PREFIX,
2423 name_prefix, var_cb, result_cb, cls);
2428 * Cancel a state request operation.
2431 * Handle for the operation to cancel.
2434 GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *look)
2436 GNUNET_CLIENT_MANAGER_op_cancel (look->plc->client, look->op_id);
2441 /* end of social_api.c */