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"
33 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
35 #define DATA2ARG(data) data, sizeof (data)
37 /* operations corresponding to API calls */
43 static int op_host_enter;
45 /** --host-reconnect */
46 static int op_host_reconnect;
49 static int op_host_leave;
51 /** --host-announce */
52 static int op_host_announce;
55 static int op_host_assign;
58 static int op_guest_enter;
60 /** --guest-reconnect */
61 static int op_guest_reconnect;
64 static int op_guest_leave;
67 static int op_guest_talk;
70 static char *op_replay;
72 /** --replay-latest */
73 static char *op_replay_latest;
76 static int op_look_at;
79 static int op_look_for;
85 static char *opt_app = "cli";
88 static char *opt_place;
97 static char *opt_peer;
100 static int opt_follow;
103 static int opt_welcome;
109 static char *opt_method;
112 // FIXME: should come from STDIN
113 static char *opt_data;
116 static char *opt_name;
119 static uint64_t opt_start;
122 static uint64_t opt_until;
125 static int opt_limit;
133 /** are we waiting for service to close our connection */
134 static char is_disconnecting = 0;
136 /** Task handle for timeout termination. */
137 struct GNUNET_SCHEDULER_Task *timeout_task;
139 const struct GNUNET_CONFIGURATION_Handle *cfg;
141 struct GNUNET_PeerIdentity peer, this_peer;
143 struct GNUNET_SOCIAL_App *app;
145 /** public key of connected place */
146 struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key;
148 struct GNUNET_PSYC_Slicer *slicer;
150 struct GNUNET_SOCIAL_Ego *ego;
151 struct GNUNET_CRYPTO_EcdsaPublicKey ego_pub_key;
153 struct GNUNET_SOCIAL_Host *hst;
154 struct GNUNET_SOCIAL_Guest *gst;
155 struct GNUNET_SOCIAL_Place *plc;
162 * Callback called after the host or guest place disconnected.
165 disconnected (void *cls)
167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnected()\n");
168 GNUNET_SCHEDULER_shutdown ();
173 * Callback called after the application disconnected.
176 app_disconnected (void *cls)
178 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "app_disconnected()\n");
183 GNUNET_SOCIAL_host_disconnect (hst, disconnected, NULL);
187 GNUNET_SOCIAL_guest_disconnect (gst, disconnected, NULL);
192 GNUNET_SCHEDULER_shutdown ();
198 * Disconnect from connected GNUnet services.
203 // handle that we get called several times from several places, but should we?
204 if (!is_disconnecting++) {
205 GNUNET_SOCIAL_app_disconnect (app, app_disconnected, NULL);
207 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "disconnect() called for the #%d time\n", is_disconnecting);
212 scheduler_shutdown (void *cls)
219 * Callback called when the program failed to finish the requested operation in time.
224 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "timeout()\n");
229 schedule_success (void *cls)
237 schedule_fail (void *cls)
244 * Schedule exit with success result.
249 if (timeout_task != NULL)
251 GNUNET_SCHEDULER_cancel (timeout_task);
254 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, schedule_success, NULL);
259 * Schedule exit with failure result.
264 if (timeout_task != NULL)
266 GNUNET_SCHEDULER_cancel (timeout_task);
269 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, schedule_fail, NULL);
277 * Callback notifying about the host has left and stopped hosting the place.
279 * This also indicates the end of the connection to the service.
284 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
285 "The host has left the place.\n");
291 * Leave a place permanently and stop hosting a place.
296 GNUNET_SOCIAL_host_leave (hst, NULL, host_left, NULL);
303 * Callback notifying about the guest has left the place.
305 * This also indicates the end of the connection to the service.
308 guest_left (void *cls)
310 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
311 "The guest has left the place.\n");
316 * Leave a place permanently as guest.
321 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
322 // FIXME: wrong use of vars
323 GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
324 "_message", DATA2ARG ("Leaving."));
325 GNUNET_SOCIAL_guest_leave (gst, env, guest_left, NULL);
326 GNUNET_PSYC_env_destroy (env);
332 /* ANNOUNCE / ASSIGN / TALK */
335 struct TransmitClosure
343 * Callback notifying about available buffer space to write message data
344 * when transmitting messages using host_announce() or guest_talk()
347 notify_data (void *cls, uint16_t *data_size, void *data)
349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
350 "Transmit notify data: %u bytes available\n",
353 struct TransmitClosure *tmit = cls;
354 uint16_t size = tmit->size < *data_size ? tmit->size : *data_size;
356 GNUNET_memcpy (data, tmit->data, size);
363 if ((op_host_announce || op_host_assign || op_guest_talk) && !opt_follow)
377 * Host announcement - send a message to the place.
380 host_announce (const char *method, const char *data, size_t data_size)
382 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
383 GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
384 "_foo", DATA2ARG ("bar baz"));
386 tmit = (struct TransmitClosure) {};
388 tmit.size = data_size;
390 GNUNET_SOCIAL_host_announce (hst, method, env,
392 GNUNET_SOCIAL_ANNOUNCE_NONE);
393 GNUNET_PSYC_env_destroy (env);
398 * Assign a state var of @a name to the value of @a data.
401 host_assign (const char *name, const char *data, size_t data_size)
403 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
404 GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_ASSIGN,
405 name, data, data_size);
407 tmit = (struct TransmitClosure) {};
408 GNUNET_SOCIAL_host_announce (hst, "_assign", env,
410 GNUNET_SOCIAL_ANNOUNCE_NONE);
411 GNUNET_PSYC_env_destroy (env);
416 * Guest talk request to host.
419 guest_talk (const char *method,
420 const char *data, size_t data_size)
422 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
423 GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
424 "_foo", DATA2ARG ("bar baz"));
426 tmit = (struct TransmitClosure) {};
428 tmit.size = data_size;
430 GNUNET_SOCIAL_guest_talk (gst, method, env,
432 GNUNET_SOCIAL_TALK_NONE);
433 GNUNET_PSYC_env_destroy (env);
441 * Callback notifying about the end of history replay results.
444 recv_history_replay_result (void *cls, int64_t result,
445 const void *data, uint16_t data_size)
447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
448 "Received history replay result: %" PRId64 "\n"
450 result, data_size, (const char *) data);
452 if (op_replay || op_replay_latest)
460 * Replay history between a given @a start and @a end message IDs,
461 * optionally filtered by a method @a prefix.
464 history_replay (uint64_t start, uint64_t end, const char *prefix)
466 GNUNET_SOCIAL_place_history_replay (plc, start, end, prefix,
467 GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
469 recv_history_replay_result,
475 * Replay latest @a limit messages.
478 history_replay_latest (uint64_t limit, const char *prefix)
480 GNUNET_SOCIAL_place_history_replay_latest (plc, limit, prefix,
481 GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
483 recv_history_replay_result,
492 * Callback notifying about the end of state var results.
495 look_result (void *cls, int64_t result_code,
496 const void *data, uint16_t data_size)
498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
499 "Received look result: %" PRId64 "\n", result_code);
501 if (op_look_at || op_look_for)
509 * Callback notifying about a state var result.
513 const struct GNUNET_MessageHeader *mod,
517 uint32_t full_value_size)
519 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
520 "Received var: %s\n%.*s\n",
521 name, value_size, (const char *) value);
526 * Look for a state var using exact match of the name.
529 look_at (const char *full_name)
531 GNUNET_SOCIAL_place_look_at (plc, full_name, look_var, look_result, NULL);
536 * Look for state vars by name prefix.
539 look_for (const char *name_prefix)
541 GNUNET_SOCIAL_place_look_for (plc, name_prefix, look_var, look_result, NULL);
549 * Callback notifying about the start of a new incoming message.
552 slicer_recv_method (void *cls,
553 const struct GNUNET_PSYC_MessageHeader *msg,
554 const struct GNUNET_PSYC_MessageMethod *meth,
556 const char *method_name)
558 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
559 "Received method for message ID %" PRIu64 ":\n"
561 message_id, method_name, ntohl (meth->flags));
566 * Callback notifying about an incoming modifier.
569 slicer_recv_modifier (void *cls,
570 const struct GNUNET_PSYC_MessageHeader *msg,
571 const struct GNUNET_MessageHeader *pmsg,
573 enum GNUNET_PSYC_Operator oper,
577 uint16_t full_value_size)
579 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
580 "Received modifier for message ID %" PRIu64 ":\n"
581 "%c%s: %.*s (size: %u)\n",
582 message_id, oper, name, value_size, (const char *) value, value_size);
587 * Callback notifying about an incoming data fragment.
590 slicer_recv_data (void *cls,
591 const struct GNUNET_PSYC_MessageHeader *msg,
592 const struct GNUNET_MessageHeader *pmsg,
597 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
598 "Received data for message ID %" PRIu64 ":\n"
600 message_id, data_size, (const char *) data);
605 * Callback notifying about the end of a message.
608 slicer_recv_eom (void *cls,
609 const struct GNUNET_PSYC_MessageHeader *msg,
610 const struct GNUNET_MessageHeader *pmsg,
612 uint8_t is_cancelled)
614 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
615 "Received end of message ID %" PRIu64
617 message_id, is_cancelled);
622 * Create a slicer for receiving message parts.
624 static struct GNUNET_PSYC_Slicer *
627 slicer = GNUNET_PSYC_slicer_create ();
629 /* register slicer to receive incoming messages with any method name */
630 GNUNET_PSYC_slicer_method_add (slicer, "", NULL,
631 slicer_recv_method, slicer_recv_modifier,
632 slicer_recv_data, slicer_recv_eom, NULL);
641 * Callback called when the guest receives an entry decision from the host.
643 * It is called once after using guest_enter() or guest_enter_by_name(),
644 * in case of a reconnection only the local enter callback is called.
647 guest_recv_entry_decision (void *cls,
649 const struct GNUNET_PSYC_Message *entry_msg)
651 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
652 "Guest received entry decision %d\n",
655 if (NULL != entry_msg)
657 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
658 const char *method_name = NULL;
659 const void *data = NULL;
660 uint16_t data_size = 0;
661 struct GNUNET_PSYC_MessageHeader *
662 pmsg = GNUNET_PSYC_message_header_create_from_psyc (entry_msg);
663 GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size);
666 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
668 method_name, data_size, (const char *) data);
671 if (op_guest_enter && !opt_follow)
679 * Callback called after a guest connection is established to the local service.
682 guest_recv_local_enter (void *cls, int result,
683 const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key,
684 uint64_t max_message_id)
686 char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key);
687 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
688 "Guest entered to local place: %s, max_message_id: %" PRIu64 "\n",
689 pub_str, max_message_id);
690 GNUNET_free (pub_str);
691 GNUNET_assert (0 <= result);
693 if (op_guest_enter && !opt_follow)
701 * Create entry requset message.
703 static struct GNUNET_PSYC_Message *
704 guest_enter_msg_create ()
706 const char *method_name = "_request_enter";
707 struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
708 GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
709 "_foo", DATA2ARG ("bar"));
710 void *data = "let me in";
711 uint16_t data_size = strlen (data) + 1;
713 return GNUNET_PSYC_message_create (method_name, env, data, data_size);
718 * Enter a place as guest, using its public key and peer ID.
721 guest_enter (const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key,
722 const struct GNUNET_PeerIdentity *peer)
724 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
725 "Entering to place as guest.\n");
729 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "--ego missing or invalid\n");
734 struct GNUNET_PSYC_Message *join_msg = guest_enter_msg_create ();
735 gst = GNUNET_SOCIAL_guest_enter (app, ego, pub_key,
736 GNUNET_PSYC_SLAVE_JOIN_NONE,
737 peer, 0, NULL, join_msg, slicer_create (),
738 guest_recv_local_enter,
739 guest_recv_entry_decision, NULL);
740 GNUNET_free (join_msg);
741 plc = GNUNET_SOCIAL_guest_get_place (gst);
746 * Enter a place as guest using its GNS address.
749 guest_enter_by_name (const char *gns_name)
751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752 "Entering to place by name as guest.\n");
754 struct GNUNET_PSYC_Message *join_msg = guest_enter_msg_create ();
755 gst = GNUNET_SOCIAL_guest_enter_by_name (app, ego, gns_name, NULL,
757 guest_recv_local_enter,
758 guest_recv_entry_decision, NULL);
759 GNUNET_free (join_msg);
760 plc = GNUNET_SOCIAL_guest_get_place (gst);
768 * Callback called when a @a nym wants to enter the place.
770 * The request needs to be replied with an entry decision.
773 host_answer_door (void *cls,
774 struct GNUNET_SOCIAL_Nym *nym,
775 const char *method_name,
776 struct GNUNET_PSYC_Environment *env,
780 const struct GNUNET_CRYPTO_EcdsaPublicKey *
781 nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym);
783 nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
785 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
786 "Entry request: %s\n", nym_str);
787 GNUNET_free (nym_str);
791 struct GNUNET_PSYC_Message *
792 resp = GNUNET_PSYC_message_create ("_notice_place_admit", env,
793 DATA2ARG ("Welcome, nym!"));
794 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, resp);
799 struct GNUNET_PSYC_Message *
800 resp = GNUNET_PSYC_message_create ("_notice_place_refuse", NULL,
801 DATA2ARG ("Go away!"));
802 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_NO, resp);
811 * Callback called when a @a nym has left the place.
814 host_farewell (void *cls,
815 const struct GNUNET_SOCIAL_Nym *nym,
816 struct GNUNET_PSYC_Environment *env)
818 const struct GNUNET_CRYPTO_EcdsaPublicKey *
819 nym_key = GNUNET_SOCIAL_nym_get_pub_key (nym);
821 nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key);
823 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
824 "Farewell: %s\n", nym_str);
825 GNUNET_free (nym_str);
830 * Callback called after the host entered the place.
833 host_entered (void *cls, int result,
834 const struct GNUNET_CRYPTO_EddsaPublicKey *pub_key,
835 uint64_t max_message_id)
837 place_pub_key = *pub_key;
838 char *pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key);
839 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
840 "Host entered: %s, max_message_id: %" PRIu64 "\n",
841 pub_str, max_message_id);
842 GNUNET_free (pub_str);
844 if (op_host_enter && !opt_follow)
852 * Enter and start hosting a place.
857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "host_enter()\n");
861 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "--ego missing or invalid\n");
866 hst = GNUNET_SOCIAL_host_enter (app, ego,
867 GNUNET_PSYC_CHANNEL_PRIVATE,
868 slicer_create (), host_entered,
869 host_answer_door, host_farewell, NULL);
870 plc = GNUNET_SOCIAL_host_get_place (hst);
874 /* PLACE RECONNECT */
878 * Perform operations common to both host & guest places.
883 static int first_run = GNUNET_YES;
884 if (GNUNET_NO == first_run)
886 first_run = GNUNET_NO;
889 history_replay (opt_start, opt_until, opt_method);
891 else if (op_replay_latest) {
892 history_replay_latest (opt_limit, opt_method);
894 else if (op_look_at) {
897 else if (op_look_for) {
904 * Callback called after reconnecting to a host place.
907 host_reconnected (void *cls, int result,
908 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
909 uint64_t max_message_id)
911 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
912 "Host reconnected.\n");
917 else if (op_host_announce) {
918 host_announce (opt_method, opt_data, strlen (opt_data));
920 else if (op_host_assign) {
921 host_assign (opt_name, opt_data, strlen (opt_data) + 1);
924 place_reconnected ();
930 * Callback called after reconnecting to a guest place.
933 guest_reconnected (void *cls, int result,
934 const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
935 uint64_t max_message_id)
937 char *place_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (place_pub_key);
938 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
939 "Guest reconnected to place %s.\n", place_pub_str);
940 GNUNET_free (place_pub_str);
942 if (op_guest_leave) {
945 else if (op_guest_talk) {
946 guest_talk (opt_method, opt_data, strlen (opt_data));
949 place_reconnected ();
958 * Callback called after the ego and place callbacks.
961 app_connected (void *cls)
963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
964 "App connected: %p\n", cls);
970 else if (op_host_enter)
974 else if (op_guest_enter)
978 guest_enter_by_name (opt_gns);
984 if (GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (opt_peer,
988 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
998 guest_enter (&place_pub_key, &peer);
1005 * Callback notifying about a host place available for reconnection.
1008 app_recv_host (void *cls,
1009 struct GNUNET_SOCIAL_HostConnection *hconn,
1010 struct GNUNET_SOCIAL_Ego *ego,
1011 const struct GNUNET_CRYPTO_EddsaPublicKey *host_pub_key,
1012 enum GNUNET_SOCIAL_AppPlaceState place_state)
1014 char *host_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (host_pub_key);
1015 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1016 "Host: %s\n", host_pub_str);
1017 GNUNET_free (host_pub_str);
1019 if ((op_host_reconnect || op_host_leave || op_host_announce || op_host_assign
1020 || op_replay || op_replay_latest
1021 || op_look_at || op_look_for)
1022 && 0 == memcmp (&place_pub_key, host_pub_key, sizeof (*host_pub_key)))
1024 hst = GNUNET_SOCIAL_host_enter_reconnect (hconn, slicer_create (), host_reconnected,
1025 host_answer_door, host_farewell, NULL);
1026 plc = GNUNET_SOCIAL_host_get_place (hst);
1032 * Callback notifying about a guest place available for reconnection.
1035 app_recv_guest (void *cls,
1036 struct GNUNET_SOCIAL_GuestConnection *gconn,
1037 struct GNUNET_SOCIAL_Ego *ego,
1038 const struct GNUNET_CRYPTO_EddsaPublicKey *guest_pub_key,
1039 enum GNUNET_SOCIAL_AppPlaceState place_state)
1041 char *guest_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (guest_pub_key);
1042 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1043 "Guest: %s\n", guest_pub_str);
1044 GNUNET_free (guest_pub_str);
1046 if ((op_guest_reconnect || op_guest_leave || op_guest_talk
1047 || op_replay || op_replay_latest
1048 || op_look_at || op_look_for)
1049 && 0 == memcmp (&place_pub_key, guest_pub_key, sizeof (*guest_pub_key)))
1051 gst = GNUNET_SOCIAL_guest_enter_reconnect (gconn, GNUNET_PSYC_SLAVE_JOIN_NONE,
1052 slicer_create (), guest_reconnected, NULL);
1053 plc = GNUNET_SOCIAL_guest_get_place (gst);
1059 * Callback notifying about an available ego.
1062 app_recv_ego (void *cls,
1063 struct GNUNET_SOCIAL_Ego *e,
1064 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub_key,
1067 char *s = GNUNET_CRYPTO_ecdsa_public_key_to_string (pub_key);
1068 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ego: %s\t%s\n", s, name);
1071 if (0 == memcmp (&ego_pub_key, pub_key, sizeof (*pub_key))
1072 || (NULL != opt_ego && 0 == strcmp (opt_ego, name)))
1082 * Establish application connection to receive available egos and places.
1085 app_connect (void *cls)
1087 app = GNUNET_SOCIAL_app_connect (cfg, opt_app,
1097 * Main function run by the scheduler.
1099 * @param cls closure
1100 * @param args remaining command-line arguments
1101 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
1102 * @param c configuration
1105 run (void *cls, char *const *args, const char *cfgfile,
1106 const struct GNUNET_CONFIGURATION_Handle *c)
1109 GNUNET_CRYPTO_get_peer_identity (cfg, &this_peer);
1112 opt_method = "message";
1119 || op_host_enter || op_host_reconnect || op_host_leave
1120 || op_host_announce || op_host_assign
1121 || op_guest_enter || op_guest_reconnect
1122 || op_guest_leave || op_guest_talk
1123 || op_replay || op_replay_latest
1124 || op_look_at || op_look_for))
1129 GNUNET_SCHEDULER_add_shutdown (scheduler_shutdown, NULL);
1132 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, timeout, NULL);
1135 if ((op_host_reconnect || op_host_leave || op_host_announce || op_host_assign
1136 || op_guest_reconnect || (op_guest_enter && !opt_gns)
1137 || op_guest_leave || op_guest_talk
1138 || op_replay || op_replay_latest
1139 || op_look_at || op_look_for)
1141 || GNUNET_OK != GNUNET_CRYPTO_eddsa_public_key_from_string (opt_place,
1145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1146 _("--place missing or invalid.\n"));
1154 GNUNET_CRYPTO_ecdsa_public_key_from_string (opt_ego,
1159 _("Public key `%s' malformed\n"),
1166 GNUNET_SCHEDULER_add_now (app_connect, NULL);
1171 * The main function to obtain peer information.
1173 * @param argc number of arguments from the command line
1174 * @param argv command line arguments
1175 * @return 0 ok, 1 on error
1178 main (int argc, char *const *argv)
1181 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1183 * gnunet program options in addition to the ones below:
1185 * -c, --config=FILENAME
1186 * -l, --logfile=LOGFILE
1187 * -L, --log=LOGLEVEL
1194 { 'A', "host-assign", NULL,
1195 gettext_noop ("assign --name in state to --data"),
1196 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_assign },
1198 { 'B', "guest-leave", NULL,
1199 gettext_noop ("say good-bye and leave somebody else's place"),
1200 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_leave },
1202 { 'C', "host-enter", NULL,
1203 gettext_noop ("create a place"),
1204 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_enter },
1206 { 'D', "host-leave", NULL,
1207 gettext_noop ("destroy a place we were hosting"),
1208 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_leave },
1210 { 'E', "guest-enter", NULL,
1211 gettext_noop ("enter somebody else's place"),
1212 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_enter },
1214 { 'F', "look-for", NULL,
1215 gettext_noop ("find state matching name prefix"),
1216 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_look_for },
1218 { 'H', "replay-latest", NULL,
1219 gettext_noop ("replay history of messages up to the given --limit"),
1220 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_replay_latest },
1222 { 'N', "host-reconnect", NULL,
1223 gettext_noop ("reconnect to a previously created place"),
1224 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_reconnect },
1226 { 'P', "host-announce", NULL,
1227 gettext_noop ("publish something to a place we are hosting"),
1228 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_announce },
1230 { 'R', "guest-reconnect", NULL,
1231 gettext_noop ("reconnect to a previously entered place"),
1232 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_reconnect },
1234 { 'S', "look-at", NULL,
1235 gettext_noop ("search for state matching exact name"),
1236 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_look_at },
1238 { 'T', "guest-talk", NULL,
1239 gettext_noop ("submit something to somebody's place"),
1240 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_talk },
1242 { 'U', "status", NULL,
1243 gettext_noop ("list of egos and subscribed places"),
1244 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_status },
1246 { 'X', "replay", NULL,
1247 gettext_noop ("extract and replay history between message IDs --start and --until"),
1248 GNUNET_NO, &GNUNET_GETOPT_set_one, &op_replay },
1253 { 'a', "app", "APPLICATION_ID",
1254 gettext_noop ("application ID to use when connecting"),
1255 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_app },
1257 { 'd', "data", "DATA",
1258 gettext_noop ("message body or state value"),
1259 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_data },
1261 { 'e', "ego", "NAME|PUBKEY",
1262 gettext_noop ("name or public key of ego"),
1263 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_ego },
1265 { 'f', "follow", NULL,
1266 gettext_noop ("wait for incoming messages"),
1267 GNUNET_NO, &GNUNET_GETOPT_set_one, &opt_follow },
1269 { 'g', "gns", "GNS_NAME",
1270 gettext_noop ("GNS name"),
1271 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_gns },
1273 { 'i', "peer", "PEER_ID",
1274 gettext_noop ("peer ID for --guest-enter"),
1275 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_peer },
1277 { 'k', "name", "VAR_NAME",
1278 gettext_noop ("name (key) to query from state"),
1279 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_name },
1281 { 'm', "method", "METHOD_NAME",
1282 gettext_noop ("method name"),
1283 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_method },
1285 { 'n', "limit", NULL,
1286 gettext_noop ("number of messages to replay from history"),
1287 GNUNET_YES, &GNUNET_GETOPT_set_ulong, &opt_limit },
1289 { 'p', "place", "PUBKEY",
1290 gettext_noop ("key address of place"),
1291 GNUNET_YES, &GNUNET_GETOPT_set_string, &opt_place },
1293 { 's', "start", NULL,
1294 gettext_noop ("start message ID for history replay"),
1295 GNUNET_YES, &GNUNET_GETOPT_set_ulong, &opt_start },
1297 { 'w', "welcome", NULL,
1298 gettext_noop ("respond to entry requests by admitting all guests"),
1299 GNUNET_NO, &GNUNET_GETOPT_set_one, &opt_welcome },
1301 { 'u', "until", NULL,
1302 gettext_noop ("end message ID for history replay"),
1303 GNUNET_YES, &GNUNET_GETOPT_set_ulong, &opt_until },
1305 { 'y', "deny", NULL,
1306 gettext_noop ("respond to entry requests by refusing all guests"),
1307 GNUNET_NO, &GNUNET_GETOPT_set_one, &opt_deny },
1309 GNUNET_GETOPT_OPTION_END
1312 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1316 _ ("gnunet-social - Interact with the social service: enter/leave, send/receive messages, access history and state.\n");
1318 "gnunet-social [--status]\n"
1320 "gnunet-social --host-enter --ego <NAME or PUBKEY> [--follow] [--welcome | --deny]\n"
1321 "gnunet-social --host-reconnect --place <PUBKEY> [--follow] [--welcome | --deny]\n"
1322 "gnunet-social --host-leave --place <PUBKEY>\n"
1323 "gnunet-social --host-assign --place <PUBKEY> --name <NAME> --data <VALUE>\n"
1324 // FIXME: some state ops not implemented yet (no hurry)
1325 // "gnunet-social --host-augment --place <PUBKEY> --name <NAME> --data <VALUE>\n"
1326 // "gnunet-social --host-diminish --place <PUBKEY> --name <NAME> --data <VALUE>\n"
1327 // "gnunet-social --host-set --place <PUBKEY> --name <NAME> --data <VALUE>\n"
1328 "gnunet-social --host-announce --place <PUBKEY> --method <METHOD_NAME> --data <MESSAGE_BODY>\n"
1330 "gnunet-social --guest-enter --place <PUBKEY> --peer <PEERID> --ego <NAME or PUBKEY> [--follow]\n"
1331 "gnunet-social --guest-enter --gns <GNS_NAME> --ego <NAME or PUBKEY> [--follow]\n"
1332 "gnunet-social --guest-reconnect --place <PUBKEY> [--follow]\n"
1333 "gnunet-social --guest-leave --place <PUBKEY>\n"
1334 "gnunet-social --guest-talk --place <PUBKEY> --method <METHOD_NAME> --data <MESSAGE_BODY>\n"
1336 "gnunet-social --history-replay --place <PUBKEY> --start <MSGID> --until <MSGID> [--method <METHOD_PREFIX>]\n"
1337 "gnunet-social --history-replay-latest --place <PUBKEY> --limit <MSG_LIMIT> [--method <METHOD_PREFIX>]\n"
1339 "gnunet-social --look-at --place <PUBKEY> --name <FULL_NAME>\n"
1340 "gnunet-social --look-for --place <PUBKEY> --name <NAME_PREFIX>\n";
1342 res = GNUNET_PROGRAM_run (argc, argv, help, usage, options, &run, NULL);
1344 GNUNET_free ((void *) argv);
1346 if (GNUNET_OK == res)