#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_social_service.h"
+#include "gnunet_core_service.h"
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
+#define DATA2ARG(data) data, sizeof (data)
+
/* operations corresponding to API calls */
/** --host-enter */
/** --ego */
static char *opt_ego;
+/** --peer */
+static char *opt_peer;
+
/** --follow */
static int opt_follow;
struct GNUNET_SOCIAL_Place *plc;
+/* DISCONNECT */
+
+
static void
-cleanup ()
+disconnect ()
{
-
+ GNUNET_SOCIAL_app_disconnect (app);
+ GNUNET_CORE_disconnect (core);
+ GNUNET_SCHEDULER_shutdown ();
}
-
/**
* Terminate the test case (failure).
*
static void
timeout (void *cls)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout\n");
- cleanup ();
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Timeout.\n");
+ disconnect ();
+}
+
+static void
+schedule_end (void *cls)
+{
+ ret = 0;
+ disconnect ();
}
static void
-host_leave (struct GNUNET_SOCIAL_Host *host)
+end ()
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "The end.\n");
+ if (timeout_task != NULL)
+ {
+ GNUNET_SCHEDULER_cancel (timeout_task);
+ timeout_task = NULL;
+ }
+ GNUNET_SCHEDULER_add_now (&schedule_end, NULL);
}
+/* LEAVE */
+
+
static void
-host_announce (struct GNUNET_SOCIAL_Host *host,
- const char *method,
- const char *data)
+host_left ()
{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "The host has left the place.\n");
+ end ();
+}
+
+static void
+host_leave ()
+{
+ GNUNET_SOCIAL_host_leave (hst, NULL, &host_left, NULL);
+ hst = NULL;
+ plc = NULL;
}
static void
-guest_leave (struct GNUNET_SOCIAL_Guest *guest)
+guest_left (void *cls)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "The guest has left the place.\n");
+}
+
+static void
+guest_leave ()
+{
+ struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
+ GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
+ "_notice_place_leave", DATA2ARG ("Leaving."));
+ GNUNET_SOCIAL_guest_leave (gst, env, &guest_left, NULL);
+ GNUNET_PSYC_env_destroy (env);
+ gst = NULL;
+ plc = NULL;
+}
+
+
+/* ANNOUNCE / TALK */
+
+
+struct TransmitClosure
+{
+ const char *data;
+ size_t size;
+} tmit;
+
+
+static int
+notify_data (void *cls, uint16_t *data_size, void *data)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Transmit notify data: %u bytes available\n",
+ *data_size);
+
+ struct TransmitClosure *tmit = cls;
+ uint16_t size = tmit->size < *data_size ? tmit->size : *data_size;
+ *data_size = size;
+ memcpy (data, tmit->data, size);
+
+ tmit->size -= size;
+ tmit->data += size;
+
+ return 0 == tmit->size ? GNUNET_NO : GNUNET_YES;
}
static void
-guest_talk (struct GNUNET_SOCIAL_Guest *guest,
- const char *method,
- const char *data)
+host_announce (const char *method, const char *data, size_t data_size)
{
+ struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
+ GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
+ "_foo", DATA2ARG ("bar baz"));
+
+ tmit = (struct TransmitClosure) {};
+ tmit.data = data;
+ tmit.size = data_size;
+ GNUNET_SOCIAL_host_announce (hst, method, env,
+ ¬ify_data, &tmit,
+ GNUNET_SOCIAL_ANNOUNCE_NONE);
}
static void
-history_replay (struct GNUNET_SOCIAL_Place *place,
- uint64_t start, uint64_t end, const char *prefix)
+guest_talk (const char *method,
+ const char *data, size_t data_size)
{
+ struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
+ GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
+ "_foo", DATA2ARG ("bar baz"));
+
+ tmit = (struct TransmitClosure) {};
+ tmit.data = data;
+ tmit.size = data_size;
+ GNUNET_SOCIAL_guest_talk (gst, method, env,
+ ¬ify_data, &tmit,
+ GNUNET_SOCIAL_TALK_NONE);
}
+/* HISTORY REPLAY */
+
+
static void
-history_replay_latest (struct GNUNET_SOCIAL_Place *place,
- uint64_t limit, const char *prefix)
+recv_history_replay_result (void *cls, int64_t result,
+ const void *data, uint16_t data_size)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Guest received history replay result: %" PRId64 "\n"
+ "%.*s\n",
+ result, data_size, (const char *) data);
+}
+
+static void
+history_replay (uint64_t start, uint64_t end, const char *prefix)
+{
+ GNUNET_SOCIAL_place_history_replay (plc, start, end, prefix,
+ GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
+ slicer,
+ &recv_history_replay_result,
+ NULL);
}
static void
-look_at (struct GNUNET_SOCIAL_Place *place,
- const char *name)
+history_replay_latest (uint64_t limit, const char *prefix)
+{
+ GNUNET_SOCIAL_place_history_replay_latest (plc, limit, prefix,
+ GNUNET_PSYC_HISTORY_REPLAY_LOCAL,
+ slicer,
+ &recv_history_replay_result,
+ NULL);
+}
+
+
+/* LOOK AT/FOR */
+
+
+static void
+look_result (void *cls, int64_t result_code,
+ const void *data, uint16_t data_size)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "look_result: %" PRId64 "\n", result_code);
}
static void
-look_for (struct GNUNET_SOCIAL_Place *place,
- const char *name)
+look_var (void *cls,
+ const struct GNUNET_MessageHeader *mod,
+ const char *name,
+ const void *value,
+ uint32_t value_size,
+ uint32_t full_value_size)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "guest_look_at_var: %s\n%.*s\n",
+ name, value_size, (const char *) value);
+}
+
+static void
+look_at (const char *name)
+{
+ GNUNET_SOCIAL_place_look_at (plc, name, look_var, look_result, NULL);
}
-/* SLICER + CALLBACKS */
+
+static void
+look_for (const char *name)
+{
+ GNUNET_SOCIAL_place_look_for (plc, name, look_var, look_result, NULL);
+}
+
+
+/* SLICER */
static void
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Received modifier for message ID %" PRIu64 ":\n"
"%c%s: %.*s (size: %u)\n",
- message_id, oper, name, value_size, value, value_size);
+ message_id, oper, name, value_size, (const char *) value, value_size);
}
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Received data for message ID %" PRIu64 ":\n"
"%.*s\n",
- message_id, data_size, data);
+ message_id, data_size, (const char *) data);
}
}
-/* GUEST ENTER + CALLBACKS */
+/* GUEST ENTER */
static void
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"%s\n%.*s\n",
- method_name, data_size, data);
+ method_name, data_size, (const char *) data);
}
}
const char *method_name = "_request_enter";
struct GNUNET_PSYC_Environment *env = GNUNET_PSYC_env_create ();
GNUNET_PSYC_env_add (env, GNUNET_PSYC_OP_SET,
- "_foo", "bar", sizeof ("bar"));
+ "_foo", DATA2ARG ("bar"));
void *data = "let me in";
uint16_t data_size = strlen (data) + 1;
static void
-guest_enter (const struct GNUNET_CRYPTO_EddsaPublicKey *place_pub_key,
- struct GNUNET_PeerIdentity *peer)
+guest_enter (struct GNUNET_PeerIdentity *peer)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Entering to place as guest.\n");
}
-
-/* HOST ENTER + CALLBACKS */
+/* HOST ENTER */
static void
}
-/* RECONNECT CALLBACKS */
+/* PLACE RECONNECT */
+
static void
place_reconnected ()
{
if (op_history_replay) {
- history_replay (plc, opt_start, opt_end, opt_method);
+ history_replay (opt_start, opt_end, opt_method);
}
else if (op_history_replay_latest) {
- history_replay_latest (plc, opt_limit, opt_method);
+ history_replay_latest (opt_limit, opt_method);
}
else if (op_look_at) {
- look_at (plc, opt_name);
+ look_at (opt_name);
}
else if (op_look_for) {
- look_for (plc, opt_name);
+ look_for (opt_name);
}
}
"Host reconnected\n");
if (op_host_leave) {
- host_leave (hst);
+ host_leave ();
}
else if (op_host_announce) {
- host_announce (hst, opt_method, opt_data);
+ host_announce (opt_method, opt_data, strlen (opt_data));
}
else {
place_reconnected ();
"Guest reconnected\n");
if (op_guest_leave) {
- guest_leave (gst);
+ guest_leave ();
}
else if (op_guest_talk) {
- guest_talk (gst, opt_method, opt_data);
+ guest_talk (opt_method, opt_data, strlen (opt_data));
}
else {
place_reconnected ();
}
-/* APP CALLBACKS */
+/* APP */
static void
host_enter ();
}
else if (op_guest_enter) {
- guest_enter (&place_pub_key);
+ guest_enter (&peer);
+ // FIXME: guest_enter_by_name
}
}
struct GNUNET_HashCode host_pub_hash;
GNUNET_CRYPTO_hash (host_pub_key, sizeof (*host_pub_key), &host_pub_hash);
char *
- host_pub_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (guest_pub_key);
+ host_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (host_pub_key);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Host: %s (%s)\n",
struct GNUNET_HashCode guest_pub_hash;
GNUNET_CRYPTO_hash (guest_pub_key, sizeof (*guest_pub_key), &guest_pub_hash);
char *
- guest_pub_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (guest_pub_key);
+ guest_pub_str = GNUNET_CRYPTO_eddsa_public_key_to_string (guest_pub_key);
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Guest: %s (%s)\n",
NULL);
}
-/* CORE CALLBACKS */
+
+/* CORE */
static void
}
+/* RUN */
+
+
/**
* Main function run by the scheduler.
*
if (op_host_enter && NULL != opt_place)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("--place must not be specified when using --host-enter\n"));
+ _("--place must not be specified when using --host-enter\n"));
return;
}
&place_pub_key))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _ ("--place missing or invalid.\n"));
+ _("--place missing or invalid.\n"));
return;
}
/* operations */
{ 'E', "host-enter", NULL,
- _ ("create a place for nyms to join"),
+ gettext_noop ("create a place for nyms to join"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_enter },
{ 'L', "host-leave", NULL,
- _ ("destroy a place we were hosting"),
+ gettext_noop ("destroy a place we were hosting"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_leave },
{ 'A', "host-announce", NULL,
- _ ("publish something to a place we are hosting"),
+ gettext_noop ("publish something to a place we are hosting"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &op_host_announce },
{ 'e', "guest-enter", NULL,
- _ ("join somebody else's place"),
+ gettext_noop ("join somebody else's place"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_enter },
{ 'l', "guest-leave", NULL,
- _ ("leave somebody else's place"),
+ gettext_noop ("leave somebody else's place"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_leave },
{ 't', "guest-talk", NULL,
- _ ("submit something to somebody's place"),
+ gettext_noop ("submit something to somebody's place"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &op_guest_talk },
{ 'R', "history-replay", NULL,
- _ ("replay history of messages between message IDs --start and --end"),
+ gettext_noop ("replay history of messages between message IDs --start and --end"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &op_history_replay },
{ 'r', "history-replay-latest", NULL,
- _ ("replay history of latest messages up to the given --limit"),
+ gettext_noop ("replay history of latest messages up to the given --limit"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &op_history_replay_latest },
/* options */
{ 'A', "app", "application ID",
- _ ("application ID to use when connecting"),
+ gettext_noop ("application ID to use when connecting"),
GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_app },
{ 'p', "place", "PUBKEY",
- _ ("public key of place"),
+ gettext_noop ("public key of place"),
GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_place },
+ { 'P', "peer", "PEER_ID",
+ gettext_noop ("peer ID for --guest-enter"),
+ GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_peer },
+
{ 'g', "ego", "PUBKEY",
- _ ("public key of ego"),
+ gettext_noop ("public key of ego"),
GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_place },
{ 'f', "follow", NULL,
- _ ("wait for incoming messages"),
+ gettext_noop ("wait for incoming messages"),
GNUNET_NO, &GNUNET_GETOPT_set_one, &opt_follow },
{ 'm', "method", "METHOD_NAME",
- _ ("method name"),
+ gettext_noop ("method name"),
GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_method },
{ 'd', "data", "DATA",
- _ ("message body to transmit"),
+ gettext_noop ("message body to transmit"),
GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_data },
{ 'n', "name", "VAR_NAME",
- _ ("state var name to query"),
+ gettext_noop ("state var name to query"),
GNUNET_NO, &GNUNET_GETOPT_set_string, &opt_name },
{ 'a', "start", NULL,
- _ ("start message ID for history replay"),
+ gettext_noop ("start message ID for history replay"),
GNUNET_NO, &GNUNET_GETOPT_set_ulong, &opt_start },
{ 'z', "end", NULL,
- _ ("end message ID for history replay"),
+ gettext_noop ("end message ID for history replay"),
GNUNET_NO, &GNUNET_GETOPT_set_ulong, &opt_end },
{ 'n', "limit", NULL,
- _ ("number of messages to replay from history"),
+ gettext_noop ("number of messages to replay from history"),
GNUNET_NO, &GNUNET_GETOPT_set_ulong, &opt_limit },
GNUNET_GETOPT_OPTION_END
return 2;
const char *help =
- _ ("interact with the social service: enter/leave, send/receive messages, access history and state")m;
+ _ ("interact with the social service: enter/leave, send/receive messages, access history and state");
const char *usage =
"gnunet-social --host-enter --ego <name or pubkey> [--listen]\n"
"gnunet-social --host-leave --place <pubkey>\n"