2 This file is part of GNUnet.
3 Copyright (C) 2016 GNUnet e.V.
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 * CLI tool to interact with the social service.
24 * @author Gabor X Toth
30 #include "gnunet_util_lib.h"
31 #include "gnunet_social_service.h"
32 #include "gnunet_core_service.h"
34 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
36 #define DATA2ARG(data) data, sizeof (data)
38 /* operations corresponding to API calls */
44 static int op_host_enter;
46 /** --host-reconnect */
47 static int op_host_reconnect;
50 static int op_host_leave;
52 /** --host-announce */
53 static int op_host_announce;
56 static int op_host_assign;
59 static int op_guest_enter;
61 /** --guest-reconnect */
62 static int op_guest_reconnect;
65 static int op_guest_leave;
68 static int op_guest_talk;
71 static char *op_replay;
73 /** --replay-latest */
74 static char *op_replay_latest;
77 static int op_look_at;
80 static int op_look_for;
86 static char *opt_app = "cli";
89 static char *opt_place;
98 static char *opt_peer;
101 static int opt_follow;
104 static int opt_welcome;
110 static char *opt_method;
113 // FIXME: should come from STDIN
114 static char *opt_data;
117 static char *opt_name;
120 static uint64_t opt_start;
123 static uint64_t opt_until;
126 static int opt_limit;
134 /** Task handle for timeout termination. */
135 struct GNUNET_SCHEDULER_Task *timeout_task;
137 const struct GNUNET_CONFIGURATION_Handle *cfg;
139 struct GNUNET_CORE_Handle *core;
140 struct GNUNET_PeerIdentity peer, this_peer;
142 struct GNUNET_SOCIAL_App *app;
144 /** public key of connected place */
145 struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key;
147 struct GNUNET_PSYC_Slicer *slicer;
149 struct GNUNET_SOCIAL_Ego *ego;
150 struct GNUNET_CRYPTO_EcdsaPublicKey ego_pub_key;
152 struct GNUNET_SOCIAL_Host *hst;
153 struct GNUNET_SOCIAL_Guest *gst;
154 struct GNUNET_SOCIAL_Place *plc;
161 * Callback called after the host or guest place disconnected.
164 disconnected (void *cls)
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnected()\n");
167 GNUNET_SCHEDULER_shutdown ();
172 * Callback called after the application disconnected.
175 app_disconnected (void *cls)
177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "app_disconnected()\n");
182 GNUNET_SOCIAL_host_disconnect (hst, disconnected, NULL);
186 GNUNET_SOCIAL_guest_disconnect (gst, disconnected, NULL);
191 GNUNET_SCHEDULER_shutdown ();
197 * Disconnect from connected GNUnet services.
202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnect()\n");
203 GNUNET_SOCIAL_app_disconnect (app, app_disconnected, NULL);
208 * Callback called when the program failed to finish the requested operation in time.
213 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "timeout()\n");
218 schedule_success (void *cls)
226 schedule_fail (void *cls)
233 * Schedule exit with success result.
238 if (timeout_task != NULL)
240 GNUNET_SCHEDULER_cancel (timeout_task);
243 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, schedule_success, NULL);
248 * Schedule exit with failure result.
253 if (timeout_task != NULL)
255 GNUNET_SCHEDULER_cancel (timeout_task);
258 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, schedule_fail, NULL);
266 * Callback notifying about the host has left and stopped hosting the place.
268 * This also indicates the end of the connection to the service.
273 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
274 "The host has left the place.\n");
280 * Leave a place permanently and stop hosting a place.
285 GNUNET_SOCIAL_host_leave (hst, NULL, host_left, NULL);
292 * Callback notifying about the guest has left the place.
294 * This also indicates the end of the connection to the service.
297 guest_left (void *cls)
299 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
300 "The guest has left the place.\n");
305 * Leave a place permanently as guest.
310 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
311 // FIXME: wrong use of vars
312 GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
313 "_message", DATA2ARG ("Leaving."));
314 GNUNET_SOCIAL_guest_leave (gst, env, guest_left, NULL);
315 GNUNET_PSYC_env_destroy (env);
321 /* ANNOUNCE / ASSIGN / TALK */
324 struct TransmitClosure
332 * Callback notifying about available buffer space to write message data
333 * when transmitting messages using host_announce() or guest_talk()
336 notify_data (void *cls, uint16_t *data_size, void *data)
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
339 "Transmit notify data: %u bytes available\n",
342 struct TransmitClosure *tmit = cls;
343 uint16_t size = tmit->size < *data_size ? tmit->size : *data_size;
345 memcpy (data, tmit->data, size);
352 if (op_host_announce || op_host_assign || op_guest_talk)
366 * Host announcement - send a message to the place.
369 host_announce (const char *method, const char *data, size_t data_size)
371 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
372 GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
373 "_foo", DATA2ARG ("bar baz"));
375 tmit = (struct TransmitClosure) {};
377 tmit.size = data_size;
379 GNUNET_SOCIAL_host_announce (hst, method, env,
381 GNUNET_SOCIAL_ANNOUNCE_NONE);
386 * Assign a state var of @a name to the value of @a data.
389 host_assign (const char *name, const char *data, size_t data_size)
391 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
392 GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_ASSIGN,
393 name, data, data_size);
395 tmit = (struct TransmitClosure) {};
396 GNUNET_SOCIAL_host_announce (hst, "_assign", env,
398 GNUNET_SOCIAL_ANNOUNCE_NONE);
403 * Guest talk request to host.
406 guest_talk (const char *method,
407 const char *data, size_t data_size)
409 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
410 GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
411 "_foo", DATA2ARG ("bar baz"));
413 tmit = (struct TransmitClosure) {};
415 tmit.size = data_size;
417 GNUNET_SOCIAL_guest_talk (gst, method, env,
419 GNUNET_SOCIAL_TALK_NONE);
427 * Callback notifying about the end of history replay results.
430 recv_history_replay_result (void *cls, int64_t result,
431 const void *data, uint16_t data_size)
433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
434 "Received history replay result: %" PRId64 "\n"
436 result, data_size, (const char *) data);
438 if (op_replay || op_replay_latest)
446 * Replay history between a given @a start and @a end message IDs,
447 * optionally filtered by a method @a prefix.
450 history_replay (uint64_t start, uint64_t end, const char *prefix)
452 GNUNET_SOCIAL_place_history_replay (plc, start, end, prefix,
453 GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
455 recv_history_replay_result,
461 * Replay latest @a limit messages.
464 history_replay_latest (uint64_t limit, const char *prefix)
466 GNUNET_SOCIAL_place_history_replay_latest (plc, limit, prefix,
467 GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
469 recv_history_replay_result,
478 * Callback notifying about the end of state var results.
481 look_result (void *cls, int64_t result_code,
482 const void *data, uint16_t data_size)
484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 "Received look result: %" PRId64 "\n", result_code);
487 if (op_look_at || op_look_for)
495 * Callback notifying about a state var result.
499 const struct GNUNET_MessageHeader *mod,
503 uint32_t full_value_size)
505 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
506 "Received var: %s\n%.*s\n",
507 name, value_size, (const char *) value);
512 * Look for a state var using exact match of the name.
515 look_at (const char *full_name)
517 GNUNET_SOCIAL_place_look_at (plc, full_name, look_var, look_result, NULL);
522 * Look for state vars by name prefix.
525 look_for (const char *name_prefix)
527 GNUNET_SOCIAL_place_look_for (plc, name_prefix, look_var, look_result, NULL);
535 * Callback notifying about the start of a new incoming message.
538 slicer_recv_method (void *cls,
539 const struct GNUNET_PSYC_MessageHeader *msg,
540 const struct GNUNET_PSYC_MessageMethod *meth,
542 const char *method_name)
544 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
545 "Received method for message ID %" PRIu64 ":\n"
547 message_id, method_name, ntohl (meth->flags));
552 * Callback notifying about an incoming modifier.
555 slicer_recv_modifier (void *cls,
556 const struct GNUNET_PSYC_MessageHeader *msg,
557 const struct GNUNET_MessageHeader *pmsg,
559 enum GNUNET_PSYC_Operator oper,
563 uint16_t full_value_size)
565 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
566 "Received modifier for message ID %" PRIu64 ":\n"
567 "%c%s: %.*s (size: %u)\n",
568 message_id, oper, name, value_size, (const char *) value, value_size);
573 * Callback notifying about an incoming data fragment.
576 slicer_recv_data (void *cls,
577 const struct GNUNET_PSYC_MessageHeader *msg,
578 const struct GNUNET_MessageHeader *pmsg,
583 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
584 "Received data for message ID %" PRIu64 ":\n"
586 message_id, data_size, (const char *) data);
591 * Callback notifying about the end of a message.
594 slicer_recv_eom (void *cls,
595 const struct GNUNET_PSYC_MessageHeader *msg,
596 const struct GNUNET_MessageHeader *pmsg,
598 uint8_t is_cancelled)
600 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
601 "Received end of message ID %" PRIu64
603 message_id, is_cancelled);
608 * Create a slicer for receiving message parts.
610 static struct GNUNET_PSYC_Slicer *
613 slicer = GNUNET_PSYC_slicer_create ();
615 /* register slicer to receive incoming messages with any method name */
616 GNUNET_PSYC_slicer_method_add (slicer, "", NULL,
617 slicer_recv_method, slicer_recv_modifier,
618 slicer_recv_data, slicer_recv_eom, NULL);
627 * Callback called when the guest receives an entry decision from the host.
629 * It is called once after using guest_enter() or guest_enter_by_name(),
630 * in case of a reconnection only the local enter callback is called.
633 guest_recv_entry_decision (void *cls,
635 const struct GNUNET_PSYC_Message *entry_msg)
637 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
638 "Guest received entry decision %d\n",
641 if (NULL != entry_msg)
643 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
644 const char *method_name = NULL;
645 const void *data = NULL;
646 uint16_t data_size = 0;
647 struct GNUNET_PSYC_MessageHeader *
648 pmsg = GNUNET_PSYC_message_header_create_from_psyc (entry_msg);
649 GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size);
652 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
654 method_name, data_size, (const char *) data);
657 if (op_guest_enter && !opt_follow)
665 * Callback called after a guest connection is established to the local service.
668 guest_recv_local_enter (void *cls, int result,
669 const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key,
670 uint64_t max_message_id)
672 char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key);
673 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
674 "Guest entered to local place: %s, max_message_id: %" PRIu64 "\n",
675 pub_str, max_message_id);
676 GNUNET_assert (0 <= result);
678 if (op_guest_enter && !opt_follow)
686 * Create entry requset message.
688 static struct GNUNET_PSYC_Message *
689 guest_enter_msg_create ()
691 const char *method_name = "_request_enter";
692 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
693 GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
694 "_foo", DATA2ARG ("bar"));
695 void *data = "let me in";
696 uint16_t data_size = strlen (data) + 1;
698 return GNUNET_PSYC_message_create (method_name, env, data, data_size);
703 * Enter a place as guest, using its public key and peer ID.
706 guest_enter (const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key,
707 const struct GNUNET_PeerIdentity *peer)
709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
710 "Entering to place as guest.\n");
714 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "--ego missing or invalid\n");
719 gst = GNUNET_SOCIAL_guest_enter (app, ego, pub_key,
720 GNUNET_PSYC_SLAVE_JOIN_NONE,
721 peer, 0, NULL, guest_enter_msg_create (),
723 guest_recv_local_enter,
724 guest_recv_entry_decision, NULL);
725 plc = GNUNET_SOCIAL_guest_get_place (gst);
730 * Enter a place as guest using its GNS address.
733 guest_enter_by_name (const char *gns_name)
735 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
736 "Entering to place by name as guest.\n");
738 gst = GNUNET_SOCIAL_guest_enter_by_name (app, ego, gns_name, NULL,
739 guest_enter_msg_create (), slicer,
740 guest_recv_local_enter,
741 guest_recv_entry_decision, NULL);
742 plc = GNUNET_SOCIAL_guest_get_place (gst);
750 * Callback called when a @a nym wants to enter the place.
752 * The request needs to be replied with an entry decision.
755 host_answer_door (void *cls,
756 struct GNUNET_SOCIAL_Nym *nym,
757 const char *method_name,
758 struct GNUNET_PSYC_Environment *env,
762 const struct GNUNET_CRYPTO_EcdsaPublicKey *
763 nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym);
765 nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
767 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
768 "Entry request: %s\n", nym_str);
769 GNUNET_free (nym_str);
773 struct GNUNET_PSYC_Message *
774 resp = GNUNET_PSYC_message_create ("_notice_place_admit", env,
775 DATA2ARG ("Welcome, nym!"));
776 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, resp);
781 struct GNUNET_PSYC_Message *
782 resp = GNUNET_PSYC_message_create ("_notice_place_refuse", NULL,
783 DATA2ARG ("Go away!"));
784 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_NO, resp);
793 * Callback called when a @a nym has left the place.
796 host_farewell (void *cls,
797 const struct GNUNET_SOCIAL_Nym *nym,
798 struct GNUNET_PSYC_Environment *env)
800 const struct GNUNET_CRYPTO_EcdsaPublicKey *
801 nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym);
803 nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
805 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
806 "Farewell: %s\n", nym_str);
807 GNUNET_free (nym_str);
812 * Callback called after the host entered the place.
815 host_entered (void *cls, int result,
816 const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key,
817 uint64_t max_message_id)
819 place_pub_key = *pub_key;
820 char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key);
821 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
822 "Host entered: %s, max_message_id: %" PRIu64 "\n",
823 pub_str, max_message_id);
825 if (op_host_enter && !opt_follow)
833 * Enter and start hosting a place.
838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "host_enter()\n");
842 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "--ego missing or invalid\n");
847 hst = GNUNET_SOCIAL_host_enter (app, ego,
848 GNUNET_PSYC_CHANNEL_PRIVATE,
849 slicer_create (), host_entered,
850 host_answer_door, host_farewell, NULL);
851 plc = GNUNET_SOCIAL_host_get_place (hst);
855 /* PLACE RECONNECT */
859 * Perform operations common to both host & guest places.
864 static int first_run = GNUNET_YES;
865 if (GNUNET_NO == first_run)
867 first_run = GNUNET_NO;
870 history_replay (opt_start, opt_until, opt_method);
872 else if (op_replay_latest) {
873 history_replay_latest (opt_limit, opt_method);
875 else if (op_look_at) {
878 else if (op_look_for) {
885 * Callback called after reconnecting to a host place.
888 host_reconnected (void *cls, int result,
889 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
890 uint64_t max_message_id)
892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
893 "Host reconnected.\n");
898 else if (op_host_announce) {
899 host_announce (opt_method, opt_data, strlen (opt_data));
901 else if (op_host_assign) {
902 host_assign (opt_name, opt_data, strlen (opt_data) + 1);
905 place_reconnected ();
911 * Callback called after reconnecting to a guest place.
914 guest_reconnected (void *cls, int result,
915 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
916 uint64_t max_message_id)
918 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
919 "Guest reconnected.\n");
921 if (op_guest_leave) {
924 else if (op_guest_talk) {
925 guest_talk (opt_method, opt_data, strlen (opt_data));
928 place_reconnected ();
937 * Callback called after the ego and place callbacks.
940 app_connected (void *cls)
942 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
943 "App connected: %p\n", cls);
949 else if (op_host_enter)
953 else if (op_guest_enter)
957 guest_enter_by_name (opt_gns);
963 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (opt_peer,
967 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
977 guest_enter (&place_pub_key, &peer);
984 * Callback notifying about a host place available for reconnection.
987 app_recv_host (void *cls,
988 struct GNUNET_SOCIAL_HostConnection *hconn,
989 struct GNUNET_SOCIAL_Ego *ego,
990 const struct GNUNET_CRYPTO_EddsaPublicKey *host_pub_key,
991 enum GNUNET_SOCIAL_AppPlaceState place_state)
993 char *host_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (host_pub_key);
994 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
995 "Host: %s\n", host_pub_str);
996 GNUNET_free (host_pub_str);
998 if ((op_host_reconnect || op_host_leave || op_host_announce || op_host_assign
999 || op_replay || op_replay_latest
1000 || op_look_at || op_look_for)
1001 && 0 == memcmp (&place_pub_key, host_pub_key, sizeof (*host_pub_key)))
1003 hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, slicer_create (), host_reconnected,
1004 host_answer_door, host_farewell, NULL);
1005 plc = GNUNET_SOCIAL_host_get_place (hst);
1011 * Callback notifying about a guest place available for reconnection.
1014 app_recv_guest (void *cls,
1015 struct GNUNET_SOCIAL_GuestConnection *gconn,
1016 struct GNUNET_SOCIAL_Ego *ego,
1017 const struct GNUNET_CRYPTO_EddsaPublicKey *guest_pub_key,
1018 enum GNUNET_SOCIAL_AppPlaceState place_state)
1020 char *guest_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (guest_pub_key);
1021 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1022 "Guest: %s\n", guest_pub_str);
1023 GNUNET_free (guest_pub_str);
1025 if ((op_guest_reconnect || op_guest_leave || op_guest_talk
1026 || op_replay || op_replay_latest
1027 || op_look_at || op_look_for)
1028 && 0 == memcmp (&place_pub_key, guest_pub_key, sizeof (*guest_pub_key)))
1030 gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn, GNUNET_PSYC_SLAVE_JOIN_NONE,
1031 slicer_create (), guest_reconnected, NULL);
1032 plc = GNUNET_SOCIAL_guest_get_place (gst);
1038 * Callback notifying about an available ego.
1041 app_recv_ego (void *cls,
1042 struct GNUNET_SOCIAL_Ego *e,
1043 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub_key,
1046 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1048 GNUNET_CRYPTO_ecdsa_public_key_to_string (pub_key), name);
1050 if (0 == memcmp (&ego_pub_key, pub_key, sizeof (*pub_key))
1051 || (NULL != opt_ego && 0 == strcmp (opt_ego, name)))
1061 * Establish application connection to receive available egos and places.
1064 app_connect (void *cls)
1066 GNUNET_CORE_disconnect (core);
1069 app = GNUNET_SOCIAL_app_connect (cfg, opt_app,
1082 core_connected (void *cls, const struct GNUNET_PeerIdentity *my_identity)
1084 this_peer = *my_identity;
1085 GNUNET_SCHEDULER_add_now (app_connect, NULL);
1093 * Main function run by the scheduler.
1095 * @param cls closure
1096 * @param args remaining command-line arguments
1097 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1098 * @param cfg configuration
1101 run (void *cls, char *const *args, const char *cfgfile,
1102 const struct GNUNET_CONFIGURATION_Handle *c)
1104 // GNUNET_SIGNAL_handler_install (SIGINT, disconnect);
1105 // GNUNET_SIGNAL_handler_install (SIGTERM, disconnect);
1106 // GNUNET_SIGNAL_handler_install (SIGKILL, disconnect);
1111 opt_method = "message";
1118 || op_host_enter || op_host_reconnect || op_host_leave
1119 || op_host_announce || op_host_assign
1120 || op_guest_enter || op_guest_reconnect
1121 || op_guest_leave || op_guest_talk
1122 || op_replay || op_replay_latest
1123 || op_look_at || op_look_for))
1130 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, timeout, NULL);
1133 if ((op_host_reconnect || op_host_leave || op_host_announce || op_host_assign
1134 || op_guest_reconnect || (op_guest_enter && !opt_gns)
1135 || op_guest_leave || op_guest_talk
1136 || op_replay || op_replay_latest
1137 || op_look_at || op_look_for)
1139 || GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (opt_place,
1143 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1144 _("--place missing or invalid.\n"));
1151 GNUNET_CRYPTO_ecdsa_public_key_from_string (opt_ego,
1156 core = GNUNET_CORE_connect (cfg, NULL, &core_connected, NULL, NULL,
1157 NULL, GNUNET_NO, NULL, GNUNET_NO, NULL);
1162 * The main function to obtain peer information.
1164 * @param argc number of arguments from the command line
1165 * @param argv command line arguments
1166 * @return 0 ok, 1 on error
1169 main (int argc, char *const *argv)
1172 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1174 * gnunet program options in addition to the ones below:
1176 * -c, --config=FILENAME
1177 * -l, --logfile=LOGFILE
1178 * -L, --log=LOGLEVEL
1185 { 'A', "host-assign", NULL,
1186 gettext_noop ("assign --name in state to --data"),
1187 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_assign },
1189 { 'B', "guest-leave", NULL,
1190 gettext_noop ("say good-bye and leave somebody else's place"),
1191 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_leave },
1193 { 'C', "host-enter", NULL,
1194 gettext_noop ("create a place"),
1195 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_enter },
1197 { 'D', "host-leave", NULL,
1198 gettext_noop ("destroy a place we were hosting"),
1199 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_leave },
1201 { 'E', "guest-enter", NULL,
1202 gettext_noop ("enter somebody else's place"),
1203 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_enter },
1205 { 'F', "look-for", NULL,
1206 gettext_noop ("find state matching name prefix"),
1207 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_look_for },
1209 { 'H', "replay-latest", NULL,
1210 gettext_noop ("replay history of messages up to the given --limit"),
1211 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_replay_latest },
1213 { 'N', "host-reconnect", NULL,
1214 gettext_noop ("reconnect to a previously created place"),
1215 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_reconnect },
1217 { 'P', "host-announce", NULL,
1218 gettext_noop ("publish something to a place we are hosting"),
1219 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_announce },
1221 { 'R', "guest-reconnect", NULL,
1222 gettext_noop ("reconnect to a previously entered place"),
1223 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_reconnect },
1225 { 'S', "look-at", NULL,
1226 gettext_noop ("search for state matching exact name"),
1227 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_look_at },
1229 { 'T', "guest-talk", NULL,
1230 gettext_noop ("submit something to somebody's place"),
1231 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_talk },
1233 { 'U', "status", NULL,
1234 gettext_noop ("list of egos and subscribed places"),
1235 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_status },
1237 { 'X', "replay", NULL,
1238 gettext_noop ("extract and replay history between message IDs --start and --until"),
1239 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_replay },
1244 { 'a', "app", "APPLICATION_ID",
1245 gettext_noop ("application ID to use when connecting"),
1246 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_app },
1248 { 'd', "data", "DATA",
1249 gettext_noop ("message body or state value"),
1250 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_data },
1252 { 'e', "ego", "NAME|PUBKEY",
1253 gettext_noop ("name or public key of ego"),
1254 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_ego },
1256 { 'f', "follow", NULL,
1257 gettext_noop ("wait for incoming messages"),
1258 GNUNET_NO, &GNUNET_GETOPT_set_one, &opt_follow },
1260 { 'g', "gns", "GNS_NAME",
1261 gettext_noop ("GNS name"),
1262 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_gns },
1264 { 'i', "peer", "PEER_ID",
1265 gettext_noop ("peer ID for --guest-enter"),
1266 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_peer },
1268 { 'k', "name", "VAR_NAME",
1269 gettext_noop ("name (key) to query from state"),
1270 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_name },
1272 { 'm', "method", "METHOD_NAME",
1273 gettext_noop ("method name"),
1274 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_method },
1276 { 'n', "limit", NULL,
1277 gettext_noop ("number of messages to replay from history"),
1278 GNUNET_YES, &GNUNET_GETOPT_set_ulong, &opt_limit },
1280 { 'p', "place", "PUBKEY",
1281 gettext_noop ("key address of place"),
1282 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_place },
1284 { 's', "start", NULL,
1285 gettext_noop ("start message ID for history replay"),
1286 GNUNET_YES, &GNUNET_GETOPT_set_ulong, &opt_start },
1288 { 'w', "welcome", NULL,
1289 gettext_noop ("respond to entry requests by admitting all guests"),
1290 GNUNET_NO, &GNUNET_GETOPT_set_one, &opt_welcome },
1292 { 'u', "until", NULL,
1293 gettext_noop ("end message ID for history replay"),
1294 GNUNET_YES, &GNUNET_GETOPT_set_ulong, &opt_until },
1296 { 'y', "deny", NULL,
1297 gettext_noop ("respond to entry requests by refusing all guests"),
1298 GNUNET_NO, &GNUNET_GETOPT_set_one, &opt_deny },
1300 GNUNET_GETOPT_OPTION_END
1303 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1307 _ ("gnunet-social - Interact with the social service: enter/leave, send/receive messages, access history and state.\n");
1309 "gnunet-social [--status]\n"
1311 "gnunet-social --host-enter --ego <NAME or PUBKEY> [--follow] [--welcome | --deny]\n"
1312 "gnunet-social --host-reconnect --place <PUBKEY> [--follow] [--welcome | --deny]\n"
1313 "gnunet-social --host-leave --place <PUBKEY>\n"
1314 "gnunet-social --host-assign --place <PUBKEY> --name <NAME> --data <VALUE>\n"
1315 // FIXME: some state ops not implemented yet (no hurry)
1316 // "gnunet-social --host-augment --place <PUBKEY> --name <NAME> --data <VALUE>\n"
1317 // "gnunet-social --host-diminish --place <PUBKEY> --name <NAME> --data <VALUE>\n"
1318 // "gnunet-social --host-set --place <PUBKEY> --name <NAME> --data <VALUE>\n"
1319 "gnunet-social --host-announce --place <PUBKEY> --method <METHOD_NAME> --data <MESSAGE_BODY>\n"
1321 "gnunet-social --guest-enter --place <PUBKEY> --peer <PEERID> --ego <NAME or PUBKEY> [--follow]\n"
1322 "gnunet-social --guest-enter --gns <GNS_NAME> --ego <NAME or PUBKEY> [--follow]\n"
1323 "gnunet-social --guest-reconnect --place <PUBKEY> [--follow]\n"
1324 "gnunet-social --guest-leave --place <PUBKEY>\n"
1325 "gnunet-social --guest-talk --place <PUBKEY> --method <METHOD_NAME> --data <MESSAGE_BODY>\n"
1327 "gnunet-social --history-replay --place <PUBKEY> --start <MSGID> --until <MSGID> [--method <METHOD_PREFIX>]\n"
1328 "gnunet-social --history-replay-latest --place <PUBKEY> --limit <MSG_LIMIT> [--method <METHOD_PREFIX>]\n"
1330 "gnunet-social --look-at --place <PUBKEY> --name <FULL_NAME>\n"
1331 "gnunet-social --look-for --place <PUBKEY> --name <NAME_PREFIX>\n";
1333 res = GNUNET_PROGRAM_run (argc, argv, help, usage, options, &run, NULL);
1335 GNUNET_free ((void *) argv);
1337 if (GNUNET_OK == res)