From a86a539258282bedabd24919e8af9bd113a6538a Mon Sep 17 00:00:00 2001 From: Gabor X Toth <*@tg-x.net> Date: Tue, 8 Sep 2015 01:36:33 +0000 Subject: social: advertise; farewell fix --- src/include/gnunet_social_service.h | 43 ++++++++++++++++----- src/psyc/gnunet-service-psyc.c | 12 +++--- src/social/gnunet-service-social.c | 7 ++++ src/social/social_api.c | 77 ++++++++++++++++++++++++++----------- src/social/test_social.c | 36 +++++++++++++---- 5 files changed, 131 insertions(+), 44 deletions(-) diff --git a/src/include/gnunet_social_service.h b/src/include/gnunet_social_service.h index 62f6ab7c7..0af48d168 100644 --- a/src/include/gnunet_social_service.h +++ b/src/include/gnunet_social_service.h @@ -38,6 +38,7 @@ extern "C" #include "gnunet_util_lib.h" #include "gnunet_env_lib.h" #include "gnunet_identity_service.h" +#include "gnunet_namestore_service.h" #include "gnunet_psyc_service.h" @@ -459,22 +460,44 @@ GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *host, * @param nym * Pseudonym to map to a cryptographic identifier. * - * @return Public key of nym; + * @return Public key of nym. */ const struct GNUNET_CRYPTO_EcdsaPublicKey * GNUNET_SOCIAL_nym_get_key (const struct GNUNET_SOCIAL_Nym *nym); +/** + * Get the hash of the public key of a @a nym. + * + * @param nym + * Pseudonym to map to a cryptographic identifier. + * + * @return Hash of the public key of nym. + */ +const struct GNUNET_HashCode * +GNUNET_SOCIAL_nym_get_key_hash (const struct GNUNET_SOCIAL_Nym *nym); + + /** * Advertise the place in the GNS zone of the @e ego of the @a host. * - * @param host Host of the place. - * @param name The name for the PLACE record to put in the zone. - * @param peer_count Number of elements in the @a peers array. - * @param peers List of peers in the PLACE record that can be used to send join - * requests to. - * @param expiration_time Expiration time of the record, use 0 to remove the record. - * @param password Password used to encrypt the record. + * @param hst + * Host of the place. + * @param name + * The name for the PLACE record to put in the zone. + * @param peer_count + * Number of elements in the @a peers array. + * @param peers + * List of peers to put in the PLACE record to advertise + * as entry points to the place in addition to the origin. + * @param expiration_time + * Expiration time of the record, use 0 to remove the record. + * @param password + * Password used to encrypt the record. + * @param result_cb + * Function called with the result of the operation. + * @param result_cls + * Closure for @a result_cb */ void GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *host, @@ -482,7 +505,9 @@ GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *host, size_t peer_count, const struct GNUNET_PeerIdentity *peers, struct GNUNET_TIME_Relative expiration_time, - const char *password); + const char *password, + GNUNET_NAMESTORE_ContinuationWithStatus result_cb, + void *result_cls); /** diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c index e20b2280e..070fd8e47 100644 --- a/src/psyc/gnunet-service-psyc.c +++ b/src/psyc/gnunet-service-psyc.c @@ -1,4 +1,3 @@ - /* * This file is part of GNUnet * Copyright (C) 2013 Christian Grothoff (and other contributing authors) @@ -534,7 +533,7 @@ cleanup_slave (struct Slave *slv) static void cleanup_channel (struct Channel *chn) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%p Cleaning up channel %s. master? %u\n", chn, GNUNET_h2s (&chn->pub_key_hash), chn->is_master); message_queue_drop (chn); @@ -569,7 +568,6 @@ client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) struct Channel * chn = GNUNET_SERVER_client_get_user_context (client, struct Channel); - chn->is_disconnected = GNUNET_YES; if (NULL == chn) { @@ -584,6 +582,8 @@ client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) chn, (GNUNET_YES == chn->is_master) ? "master" : "slave", GNUNET_h2s (&chn->pub_key_hash)); + chn->is_disconnected = GNUNET_YES; + struct Client *cli = chn->clients_head; while (NULL != cli) { @@ -1548,9 +1548,11 @@ mcast_recv_request (void *cls, struct Master *mst = cls; uint16_t size = ntohs (req->header.size); + char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&req->member_key); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "%p Received multicast request of size %u.\n", - mst, size); + "%p Received multicast request of size %u from %s.\n", + mst, size, str); + GNUNET_free (str); uint16_t first_ptype = 0, last_ptype = 0; if (GNUNET_SYSERR diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c index 56612b488..3f558730e 100644 --- a/src/social/gnunet-service-social.c +++ b/src/social/gnunet-service-social.c @@ -599,6 +599,13 @@ psyc_recv_message (void *cls, const struct GNUNET_PSYC_MessageHeader *msg) { struct Place *plc = cls; + + char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&msg->slave_key); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%p Received PSYC message of size %u from %s.\n", + plc, ntohs (msg->header.size), str); + GNUNET_free (str); + client_send_msg (plc, &msg->header); /* FIXME: further processing */ diff --git a/src/social/social_api.c b/src/social/social_api.c index 23a977beb..a49f1160d 100644 --- a/src/social/social_api.c +++ b/src/social/social_api.c @@ -455,7 +455,8 @@ host_recv_notice_place_leave_method (void *cls, const char *method_name) { struct GNUNET_SOCIAL_Host *hst = cls; - if (NULL == nym) + if (0 == memcmp (&(struct GNUNET_CRYPTO_EcdsaPublicKey) {}, + &nym->pub_key, sizeof (nym->pub_key))) return; GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -464,6 +465,12 @@ host_recv_notice_place_leave_method (void *cls, hst->notice_place_leave_nym = (struct GNUNET_SOCIAL_Nym *) nym; hst->notice_place_leave_env = GNUNET_ENV_environment_create (); + + char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&hst->notice_place_leave_nym->pub_key); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "_notice_place_leave: got method from nym %s (%s).\n", + GNUNET_h2s (&hst->notice_place_leave_nym->pub_key_hash), str); + GNUNET_break (0); } @@ -506,6 +513,11 @@ host_recv_notice_place_leave_eom (void *cls, if (NULL == hst->notice_place_leave_env) return; + char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&hst->notice_place_leave_nym->pub_key); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "_notice_place_leave: got EOM from nym %s (%s).\n", + GNUNET_h2s (&hst->notice_place_leave_nym->pub_key_hash), str); + if (GNUNET_YES != cancelled) { if (NULL != hst->farewell_cb) @@ -658,10 +670,12 @@ slicer_message (void *cls, const struct GNUNET_CRYPTO_EcdsaPublicKey *slave_key, GNUNET_assert (message_id == slicer->message_id); } + char *nym_str = GNUNET_CRYPTO_ecdsa_public_key_to_string (slave_key); LOG (GNUNET_ERROR_TYPE_DEBUG, "Slicer received message of type %u and size %u, " - "with ID %" PRIu64 " and method %s\n", - ptype, ntohs (msg->size), message_id, slicer->method_name); + "with ID %" PRIu64 " and method %s from %s\n", + ptype, ntohs (msg->size), message_id, slicer->method_name, nym_str); + GNUNET_free (nym_str); slicer->msg = msg; @@ -1661,8 +1675,8 @@ GNUNET_SOCIAL_host_eject (struct GNUNET_SOCIAL_Host *hst, * * @param nym * Pseudonym to map to a cryptographic identifier. - * @param[out] nym_key - * Set to the public key of the nym. + * + * @return Public key of nym. */ const struct GNUNET_CRYPTO_EcdsaPublicKey * GNUNET_SOCIAL_nym_get_key (const struct GNUNET_SOCIAL_Nym *nym) @@ -1671,6 +1685,21 @@ GNUNET_SOCIAL_nym_get_key (const struct GNUNET_SOCIAL_Nym *nym) } +/** + * Get the hash of the public key of a @a nym. + * + * @param nym + * Pseudonym to map to a cryptographic identifier. + * + * @return Hash of the public key of nym. + */ +const struct GNUNET_HashCode * +GNUNET_SOCIAL_nym_get_key_hash (const struct GNUNET_SOCIAL_Nym *nym) +{ + return &nym->pub_key_hash; +} + + /** * Obtain the private-public key pair of the hosted place. * @@ -1689,13 +1718,6 @@ GNUNET_SOCIAL_host_get_place_key (struct GNUNET_SOCIAL_Host *hst) } -static void -namestore_result_host_advertise (void *cls, int32_t success, const char *emsg) -{ - -} - - /** * Connected to core service. */ @@ -1710,13 +1732,23 @@ core_connected_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) /** * Advertise the place in the GNS zone of the @e ego of the @a host. * - * @param hst Host of the place. - * @param name The name for the PLACE record to put in the zone. - * @param peer_count Number of elements in the @a peers array. - * @param peers List of peers in the PLACE record that can be used to send join - * requests to. - * @param expiration_time Expiration time of the record, use 0 to remove the record. - * @param password Password used to encrypt the record. + * @param hst + * Host of the place. + * @param name + * The name for the PLACE record to put in the zone. + * @param peer_count + * Number of elements in the @a peers array. + * @param peers + * List of peers to put in the PLACE record to advertise + * as entry points to the place in addition to the origin. + * @param expiration_time + * Expiration time of the record, use 0 to remove the record. + * @param password + * Password used to encrypt the record. + * @param result_cb + * Function called with the result of the operation. + * @param result_cls + * Closure for @a result_cb */ void GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *hst, @@ -1724,7 +1756,9 @@ GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *hst, size_t peer_count, const struct GNUNET_PeerIdentity *peers, struct GNUNET_TIME_Relative expiration_time, - const char *password) + const char *password, + GNUNET_NAMESTORE_ContinuationWithStatus result_cb, + void *result_cls) { struct GNUNET_SOCIAL_Place *plc = &hst->plc; if (NULL == namestore) @@ -1748,8 +1782,7 @@ GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *hst, rd.data = rec; GNUNET_NAMESTORE_records_store (namestore, &hst->plc.ego_key, - name, 1, &rd, namestore_result_host_advertise, - hst); + name, 1, &rd, result_cb, result_cls); } diff --git a/src/social/test_social.c b/src/social/test_social.c index ad4101bd6..50150449c 100644 --- a/src/social/test_social.c +++ b/src/social/test_social.c @@ -127,7 +127,9 @@ enum TEST_GUEST_LOOK_AT = 12, TEST_GUEST_LOOK_FOR = 13, TEST_GUEST_LEAVE = 14, - TEST_HOST_LEAVE = 15, + TEST_HOST_ADVERTISE = 15, + TEST_GUEST_ENTER_BY_NAME = 16, + TEST_HOST_LEAVE = 17, } test; @@ -306,18 +308,37 @@ schedule_host_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) } +static void +host_recv_advertise_result (void *cls, int32_t success, const char *emsg) +{ + GNUNET_assert (GNUNET_YES == success); + GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL); +} + + +static void +host_advertise () +{ + test = TEST_HOST_ADVERTISE; + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test #%u: Advertising place.\n", test); + GNUNET_SOCIAL_host_advertise (hst, "home", 1, &this_peer, + GNUNET_TIME_UNIT_MINUTES, "let.me*in!", + host_recv_advertise_result, hst); +} + + static void host_farewell (void *cls, const struct GNUNET_SOCIAL_Nym *nym, struct GNUNET_ENV_Environment *env) { - const struct GNUNET_CRYPTO_EcdsaPublicKey *nym_key = GNUNET_SOCIAL_nym_get_key (nym); - char *str; + const struct GNUNET_CRYPTO_EcdsaPublicKey * + nym_key = GNUNET_SOCIAL_nym_get_key (nym); - str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key); + char *str = GNUNET_CRYPTO_ecdsa_public_key_to_string (nym_key); GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Farewell: nym %s has left the place.\n", - str); + "Farewell: nym %s (%s) has left the place.\n", + GNUNET_h2s (GNUNET_SOCIAL_nym_get_key_hash (nym)), str); GNUNET_free (str); GNUNET_assert (1 == GNUNET_ENV_environment_get_count (env)); if (0 != memcmp (&guest_pub_key, nym_key, sizeof (*nym_key))) @@ -328,8 +349,7 @@ host_farewell (void *cls, GNUNET_free (str); GNUNET_assert (0); } - - GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL); + host_advertise (); } -- cgit v1.2.3