diff options
Diffstat (limited to 'src/social/social_api.c')
-rw-r--r-- | src/social/social_api.c | 251 |
1 files changed, 155 insertions, 96 deletions
diff --git a/src/social/social_api.c b/src/social/social_api.c index a49f1160d..17e5a3bfc 100644 --- a/src/social/social_api.c +++ b/src/social/social_api.c | |||
@@ -470,7 +470,6 @@ host_recv_notice_place_leave_method (void *cls, | |||
470 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 470 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
471 | "_notice_place_leave: got method from nym %s (%s).\n", | 471 | "_notice_place_leave: got method from nym %s (%s).\n", |
472 | GNUNET_h2s (&hst->notice_place_leave_nym->pub_key_hash), str); | 472 | GNUNET_h2s (&hst->notice_place_leave_nym->pub_key_hash), str); |
473 | GNUNET_break (0); | ||
474 | } | 473 | } |
475 | 474 | ||
476 | 475 | ||
@@ -1251,7 +1250,7 @@ host_recv_enter_ack (void *cls, | |||
1251 | 1250 | ||
1252 | struct GNUNET_PSYC_CountersResultMessage * | 1251 | struct GNUNET_PSYC_CountersResultMessage * |
1253 | cres = (struct GNUNET_PSYC_CountersResultMessage *) msg; | 1252 | cres = (struct GNUNET_PSYC_CountersResultMessage *) msg; |
1254 | int32_t result = ntohl (cres->result_code) + INT32_MIN; | 1253 | int32_t result = ntohl (cres->result_code); |
1255 | if (NULL != hst->enter_cb) | 1254 | if (NULL != hst->enter_cb) |
1256 | hst->enter_cb (hst->cb_cls, result, GNUNET_ntohll (cres->max_message_id)); | 1255 | hst->enter_cb (hst->cb_cls, result, GNUNET_ntohll (cres->max_message_id)); |
1257 | } | 1256 | } |
@@ -1270,6 +1269,7 @@ host_recv_enter_request (void *cls, | |||
1270 | 1269 | ||
1271 | const char *method_name = NULL; | 1270 | const char *method_name = NULL; |
1272 | struct GNUNET_ENV_Environment *env = NULL; | 1271 | struct GNUNET_ENV_Environment *env = NULL; |
1272 | struct GNUNET_PSYC_MessageHeader *entry_pmsg; | ||
1273 | const void *data = NULL; | 1273 | const void *data = NULL; |
1274 | uint16_t data_size = 0; | 1274 | uint16_t data_size = 0; |
1275 | char *str; | 1275 | char *str; |
@@ -1277,34 +1277,38 @@ host_recv_enter_request (void *cls, | |||
1277 | req = (const struct GNUNET_PSYC_JoinRequestMessage *) msg; | 1277 | req = (const struct GNUNET_PSYC_JoinRequestMessage *) msg; |
1278 | const struct GNUNET_PSYC_Message *entry_msg = NULL; | 1278 | const struct GNUNET_PSYC_Message *entry_msg = NULL; |
1279 | 1279 | ||
1280 | if (sizeof (*req) + sizeof (*entry_msg) <= ntohs (req->header.size)) | 1280 | do |
1281 | { | 1281 | { |
1282 | entry_msg = (struct GNUNET_PSYC_Message *) &req[1]; | 1282 | if (sizeof (*req) + sizeof (*entry_msg) <= ntohs (req->header.size)) |
1283 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1284 | "Received entry_msg of type %u and size %u.\n", | ||
1285 | ntohs (entry_msg->header.type), ntohs (entry_msg->header.size)); | ||
1286 | |||
1287 | env = GNUNET_ENV_environment_create (); | ||
1288 | if (GNUNET_OK != GNUNET_PSYC_message_parse (entry_msg, &method_name, env, | ||
1289 | &data, &data_size)) | ||
1290 | { | 1283 | { |
1291 | GNUNET_break_op (0); | 1284 | entry_msg = (struct GNUNET_PSYC_Message *) &req[1]; |
1292 | str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&req->slave_key); | 1285 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1293 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1286 | "Received entry_msg of type %u and size %u.\n", |
1294 | "Ignoring invalid entry request from nym %s.\n", | 1287 | ntohs (entry_msg->header.type), ntohs (entry_msg->header.size)); |
1295 | str); | 1288 | |
1296 | GNUNET_free (str); | 1289 | env = GNUNET_ENV_environment_create (); |
1297 | GNUNET_ENV_environment_destroy (env); | 1290 | entry_pmsg = GNUNET_PSYC_message_header_create_from_psyc (entry_msg); |
1298 | return; | 1291 | if (GNUNET_OK != GNUNET_PSYC_message_parse (entry_pmsg, &method_name, env, |
1292 | &data, &data_size)) | ||
1293 | { | ||
1294 | GNUNET_break_op (0); | ||
1295 | str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&req->slave_key); | ||
1296 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1297 | "Ignoring invalid entry request from nym %s.\n", | ||
1298 | str); | ||
1299 | GNUNET_free (str); | ||
1300 | break; | ||
1301 | } | ||
1299 | } | 1302 | } |
1300 | } | ||
1301 | 1303 | ||
1302 | struct GNUNET_SOCIAL_Nym *nym = nym_get_or_create (&req->slave_key); | 1304 | struct GNUNET_SOCIAL_Nym *nym = nym_get_or_create (&req->slave_key); |
1303 | hst->answer_door_cb (hst->cb_cls, nym, method_name, env, | 1305 | hst->answer_door_cb (hst->cb_cls, nym, method_name, env, |
1304 | data_size, data); | 1306 | data_size, data); |
1307 | } while (0); | ||
1305 | 1308 | ||
1306 | if (NULL != env) | 1309 | if (NULL != env) |
1307 | GNUNET_ENV_environment_destroy (env); | 1310 | GNUNET_ENV_environment_destroy (env); |
1311 | GNUNET_free (entry_pmsg); | ||
1308 | } | 1312 | } |
1309 | 1313 | ||
1310 | 1314 | ||
@@ -1319,7 +1323,7 @@ guest_recv_enter_ack (void *cls, | |||
1319 | 1323 | ||
1320 | struct GNUNET_PSYC_CountersResultMessage * | 1324 | struct GNUNET_PSYC_CountersResultMessage * |
1321 | cres = (struct GNUNET_PSYC_CountersResultMessage *) msg; | 1325 | cres = (struct GNUNET_PSYC_CountersResultMessage *) msg; |
1322 | int32_t result = ntohl (cres->result_code) + INT32_MIN; | 1326 | int32_t result = ntohl (cres->result_code); |
1323 | if (NULL != gst->enter_cb) | 1327 | if (NULL != gst->enter_cb) |
1324 | gst->enter_cb (gst->cb_cls, result, GNUNET_ntohll (cres->max_message_id)); | 1328 | gst->enter_cb (gst->cb_cls, result, GNUNET_ntohll (cres->max_message_id)); |
1325 | } | 1329 | } |
@@ -1424,11 +1428,30 @@ static struct GNUNET_CLIENT_MANAGER_MessageHandler guest_handlers[] = | |||
1424 | static void | 1428 | static void |
1425 | place_cleanup (struct GNUNET_SOCIAL_Place *plc) | 1429 | place_cleanup (struct GNUNET_SOCIAL_Place *plc) |
1426 | { | 1430 | { |
1427 | GNUNET_PSYC_transmit_destroy (plc->tmit); | 1431 | if (NULL != plc->tmit) |
1428 | GNUNET_PSYC_receive_destroy (plc->recv); | 1432 | GNUNET_PSYC_transmit_destroy (plc->tmit); |
1429 | GNUNET_free (plc->connect_msg); | 1433 | if (NULL != plc->recv) |
1434 | GNUNET_PSYC_receive_destroy (plc->recv); | ||
1435 | if (NULL != plc->connect_msg) | ||
1436 | GNUNET_free (plc->connect_msg); | ||
1430 | if (NULL != plc->disconnect_cb) | 1437 | if (NULL != plc->disconnect_cb) |
1431 | plc->disconnect_cb (plc->disconnect_cls); | 1438 | plc->disconnect_cb (plc->disconnect_cls); |
1439 | |||
1440 | if (NULL != core) | ||
1441 | { | ||
1442 | GNUNET_CORE_disconnect (core); | ||
1443 | core = NULL; | ||
1444 | } | ||
1445 | if (NULL != namestore) | ||
1446 | { | ||
1447 | GNUNET_NAMESTORE_disconnect (namestore); | ||
1448 | namestore = NULL; | ||
1449 | } | ||
1450 | if (NULL != gns) | ||
1451 | { | ||
1452 | GNUNET_GNS_disconnect (gns); | ||
1453 | gns = NULL; | ||
1454 | } | ||
1432 | } | 1455 | } |
1433 | 1456 | ||
1434 | 1457 | ||
@@ -1508,7 +1531,6 @@ GNUNET_SOCIAL_host_enter (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1508 | GNUNET_CRYPTO_eddsa_key_clear (ephemeral_key); | 1531 | GNUNET_CRYPTO_eddsa_key_clear (ephemeral_key); |
1509 | GNUNET_free (ephemeral_key); | 1532 | GNUNET_free (ephemeral_key); |
1510 | } | 1533 | } |
1511 | plc->ego_key = *GNUNET_IDENTITY_ego_get_private_key (ego); | ||
1512 | 1534 | ||
1513 | req->header.size = htons (sizeof (*req)); | 1535 | req->header.size = htons (sizeof (*req)); |
1514 | req->header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER); | 1536 | req->header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER); |
@@ -1521,7 +1543,9 @@ GNUNET_SOCIAL_host_enter (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1521 | plc->is_host = GNUNET_YES; | 1543 | plc->is_host = GNUNET_YES; |
1522 | plc->slicer = slicer; | 1544 | plc->slicer = slicer; |
1523 | 1545 | ||
1524 | hst->plc.ego_key = *GNUNET_IDENTITY_ego_get_private_key (ego); | 1546 | plc->ego_key = *GNUNET_IDENTITY_ego_get_private_key (ego); |
1547 | GNUNET_CRYPTO_eddsa_key_get_public (place_key, &plc->pub_key); | ||
1548 | |||
1525 | hst->enter_cb = enter_cb; | 1549 | hst->enter_cb = enter_cb; |
1526 | hst->answer_door_cb = answer_door_cb; | 1550 | hst->answer_door_cb = answer_door_cb; |
1527 | hst->farewell_cb = farewell_cb; | 1551 | hst->farewell_cb = farewell_cb; |
@@ -1744,7 +1768,7 @@ core_connected_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) | |||
1744 | * @param expiration_time | 1768 | * @param expiration_time |
1745 | * Expiration time of the record, use 0 to remove the record. | 1769 | * Expiration time of the record, use 0 to remove the record. |
1746 | * @param password | 1770 | * @param password |
1747 | * Password used to encrypt the record. | 1771 | * Password used to encrypt the record or NULL to keep it cleartext. |
1748 | * @param result_cb | 1772 | * @param result_cb |
1749 | * Function called with the result of the operation. | 1773 | * Function called with the result of the operation. |
1750 | * @param result_cls | 1774 | * @param result_cls |
@@ -1753,9 +1777,9 @@ core_connected_cb (void *cls, const struct GNUNET_PeerIdentity *my_identity) | |||
1753 | void | 1777 | void |
1754 | GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *hst, | 1778 | GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *hst, |
1755 | const char *name, | 1779 | const char *name, |
1756 | size_t peer_count, | 1780 | uint32_t peer_count, |
1757 | const struct GNUNET_PeerIdentity *peers, | 1781 | const struct GNUNET_PeerIdentity *peers, |
1758 | struct GNUNET_TIME_Relative expiration_time, | 1782 | struct GNUNET_TIME_Absolute expiration_time, |
1759 | const char *password, | 1783 | const char *password, |
1760 | GNUNET_NAMESTORE_ContinuationWithStatus result_cb, | 1784 | GNUNET_NAMESTORE_ContinuationWithStatus result_cb, |
1761 | void *result_cls) | 1785 | void *result_cls) |
@@ -1767,19 +1791,20 @@ GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *hst, | |||
1767 | core = GNUNET_CORE_connect (plc->cfg, NULL, core_connected_cb, NULL, NULL, | 1791 | core = GNUNET_CORE_connect (plc->cfg, NULL, core_connected_cb, NULL, NULL, |
1768 | NULL, GNUNET_NO, NULL, GNUNET_NO, NULL); | 1792 | NULL, GNUNET_NO, NULL, GNUNET_NO, NULL); |
1769 | 1793 | ||
1770 | struct GNUNET_GNSRECORD_Data rd = { 0 }; | 1794 | struct GNUNET_GNSRECORD_Data rd = { }; |
1771 | rd.record_type = GNUNET_GNSRECORD_TYPE_PLACE; | 1795 | rd.record_type = GNUNET_GNSRECORD_TYPE_PLACE; |
1772 | rd.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | 1796 | rd.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; |
1773 | rd.expiration_time | 1797 | rd.expiration_time = expiration_time.abs_value_us; |
1774 | = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_WEEKS, 1).rel_value_us; | ||
1775 | 1798 | ||
1776 | struct GNUNET_GNSRECORD_PlaceData *rec = GNUNET_malloc (sizeof (*rec)); | 1799 | struct GNUNET_GNSRECORD_PlaceData * |
1800 | rec = GNUNET_malloc (sizeof (*rec) + peer_count * sizeof (*peers)); | ||
1777 | rec->place_key = plc->pub_key; | 1801 | rec->place_key = plc->pub_key; |
1778 | rec->origin = this_peer; | 1802 | rec->origin = this_peer; |
1779 | rec->relay_count = htons (0); // FIXME | 1803 | rec->relay_count = htonl (peer_count); |
1804 | memcpy (&rec[1], peers, peer_count * sizeof (*peers)); | ||
1780 | 1805 | ||
1781 | rd.data_size = sizeof (*rec); | ||
1782 | rd.data = rec; | 1806 | rd.data = rec; |
1807 | rd.data_size = sizeof (*rec) + peer_count * sizeof (*peers); | ||
1783 | 1808 | ||
1784 | GNUNET_NAMESTORE_records_store (namestore, &hst->plc.ego_key, | 1809 | GNUNET_NAMESTORE_records_store (namestore, &hst->plc.ego_key, |
1785 | name, 1, &rd, result_cb, result_cls); | 1810 | name, 1, &rd, result_cb, result_cls); |
@@ -1907,7 +1932,7 @@ guest_enter_request_create (const struct GNUNET_CRYPTO_EcdsaPrivateKey *guest_ke | |||
1907 | req->place_key = *place_key; | 1932 | req->place_key = *place_key; |
1908 | req->guest_key = *guest_key; | 1933 | req->guest_key = *guest_key; |
1909 | req->origin = *origin; | 1934 | req->origin = *origin; |
1910 | req->relay_count = relay_count; | 1935 | req->relay_count = htonl (relay_count); |
1911 | 1936 | ||
1912 | uint16_t p = sizeof (*req); | 1937 | uint16_t p = sizeof (*req); |
1913 | if (0 < relay_size) | 1938 | if (0 < relay_size) |
@@ -1990,6 +2015,9 @@ gns_result_guest_enter (void *cls, uint32_t rd_count, | |||
1990 | struct GNUNET_SOCIAL_Guest *gst = cls; | 2015 | struct GNUNET_SOCIAL_Guest *gst = cls; |
1991 | struct GNUNET_SOCIAL_Place *plc = &gst->plc; | 2016 | struct GNUNET_SOCIAL_Place *plc = &gst->plc; |
1992 | 2017 | ||
2018 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2019 | "%p GNS result: %u records.\n", gst, rd_count); | ||
2020 | |||
1993 | const struct GNUNET_GNSRECORD_PlaceData * | 2021 | const struct GNUNET_GNSRECORD_PlaceData * |
1994 | rec = (const struct GNUNET_GNSRECORD_PlaceData *) rd->data; | 2022 | rec = (const struct GNUNET_GNSRECORD_PlaceData *) rd->data; |
1995 | 2023 | ||
@@ -2000,7 +2028,6 @@ gns_result_guest_enter (void *cls, uint32_t rd_count, | |||
2000 | return; | 2028 | return; |
2001 | } | 2029 | } |
2002 | 2030 | ||
2003 | |||
2004 | if (rd->data_size < sizeof (*rec)) | 2031 | if (rd->data_size < sizeof (*rec)) |
2005 | { | 2032 | { |
2006 | GNUNET_break_op (0); | 2033 | GNUNET_break_op (0); |
@@ -2009,80 +2036,67 @@ gns_result_guest_enter (void *cls, uint32_t rd_count, | |||
2009 | return; | 2036 | return; |
2010 | } | 2037 | } |
2011 | 2038 | ||
2012 | struct GuestEnterRequest * | 2039 | uint16_t relay_count = ntohl (rec->relay_count); |
2013 | req = (struct GuestEnterRequest *) plc->connect_msg; | 2040 | struct GNUNET_PeerIdentity *relays = NULL; |
2014 | uint16_t req_size = ntohs (req->header.size); | ||
2015 | uint16_t relay_count = ntohs (rec->relay_count); | ||
2016 | 2041 | ||
2017 | if (0 < relay_count) | 2042 | if (0 < relay_count) |
2018 | { | 2043 | { |
2019 | if (rd->data_size == sizeof (*rec) + relay_count * sizeof (struct GNUNET_PeerIdentity)) | 2044 | if (rd->data_size == sizeof (*rec) + relay_count * sizeof (struct GNUNET_PeerIdentity)) |
2020 | { | 2045 | { |
2021 | struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &rec[1]; | 2046 | relays = (struct GNUNET_PeerIdentity *) &rec[1]; |
2022 | uint16_t relay_size = relay_count * sizeof (struct GNUNET_PeerIdentity); | ||
2023 | struct GuestEnterRequest * | ||
2024 | req2 = GNUNET_malloc (req_size + relay_size); | ||
2025 | |||
2026 | req2->header.size = htons (req_size + relay_size); | ||
2027 | req2->header.type = req->header.type; | ||
2028 | req2->guest_key = req->guest_key; | ||
2029 | |||
2030 | uint16_t p = sizeof (*req); | ||
2031 | if (0 < relay_size) | ||
2032 | { | ||
2033 | memcpy ((char *) req2 + p, relays, relay_size); | ||
2034 | p += relay_size; | ||
2035 | } | ||
2036 | |||
2037 | memcpy ((char *) req + p, &req[1], req_size - sizeof (*req)); | ||
2038 | |||
2039 | plc->connect_msg = &req2->header; | ||
2040 | GNUNET_free (req); | ||
2041 | req = req2; | ||
2042 | } | 2047 | } |
2043 | else | 2048 | else |
2044 | { | 2049 | { |
2050 | relay_count = 0; | ||
2045 | GNUNET_break_op (0); | 2051 | GNUNET_break_op (0); |
2046 | } | 2052 | } |
2047 | } | 2053 | } |
2048 | 2054 | ||
2049 | req->place_key = rec->place_key; | 2055 | struct GuestEnterRequest * |
2050 | req->origin = rec->origin; | 2056 | req = guest_enter_request_create (&plc->ego_key, &rec->place_key, |
2051 | req->relay_count = rec->relay_count; | 2057 | &rec->origin, relay_count, relays, |
2052 | memcpy (&req[1], &rec[1], | 2058 | (struct GNUNET_PSYC_Message *) plc->connect_msg); |
2053 | ntohl (rec->relay_count) * sizeof (struct GNUNET_PeerIdentity)); | 2059 | GNUNET_free (plc->connect_msg); |
2054 | |||
2055 | plc->connect_msg = &req->header; | 2060 | plc->connect_msg = &req->header; |
2056 | plc->pub_key = req->place_key; | 2061 | plc->pub_key = req->place_key; |
2057 | 2062 | ||
2058 | plc->tmit = GNUNET_PSYC_transmit_create (plc->client); | 2063 | plc->tmit = GNUNET_PSYC_transmit_create (plc->client); |
2059 | plc->recv = GNUNET_PSYC_receive_create (NULL, slicer_message, plc); | 2064 | plc->recv = GNUNET_PSYC_receive_create (NULL, slicer_message, plc->slicer); |
2060 | 2065 | ||
2061 | place_send_connect_msg (plc); | 2066 | place_send_connect_msg (plc); |
2062 | } | 2067 | } |
2063 | 2068 | ||
2069 | |||
2064 | /** | 2070 | /** |
2065 | * Request entry to a place as a guest. | 2071 | * Request entry to a place by name as a guest. |
2066 | * | 2072 | * |
2067 | * @param cfg Configuration to contact the social service. | 2073 | * @param cfg |
2068 | * @param ego Identity of the guest. | 2074 | * Configuration to contact the social service. |
2069 | * @param address GNS name of the place to enter. Either in the form of | 2075 | * @param ego |
2076 | * Identity of the guest. | ||
2077 | * @param gns_name | ||
2078 | * GNS name of the place to enter. Either in the form of | ||
2070 | * 'room.friend.gnu', or 'NYMPUBKEY.zkey'. This latter case refers to | 2079 | * 'room.friend.gnu', or 'NYMPUBKEY.zkey'. This latter case refers to |
2071 | * the 'PLACE' record of the empty label ("+") in the GNS zone with the | 2080 | * the 'PLACE' record of the empty label ("+") in the GNS zone with the |
2072 | * nym's public key 'NYMPUBKEY', and can be used to request entry to a | 2081 | * nym's public key 'NYMPUBKEY', and can be used to request entry to a |
2073 | * pseudonym's place directly. | 2082 | * pseudonym's place directly. |
2074 | * @param method_name Method name for the message. | 2083 | * @param password |
2075 | * @param env Environment containing variables for the message, or NULL. | 2084 | * Password to decrypt the record, or NULL for cleartext records. |
2076 | * @param data Payload for the message to give to the enter callback. | 2085 | * @param join_msg |
2077 | * @param data_size Number of bytes in @a data. | 2086 | * Entry request message. |
2078 | * @param slicer Slicer to use for processing incoming requests from guests. | 2087 | * @param slicer |
2088 | * Slicer to use for processing incoming requests from guests. | ||
2089 | * @param local_enter_cb | ||
2090 | * Called upon connection established to the social service. | ||
2091 | * @param entry_decision_cb | ||
2092 | * Called upon receiving entry decision. | ||
2079 | * | 2093 | * |
2080 | * @return NULL on errors, otherwise handle for the guest. | 2094 | * @return NULL on errors, otherwise handle for the guest. |
2081 | */ | 2095 | */ |
2082 | struct GNUNET_SOCIAL_Guest * | 2096 | struct GNUNET_SOCIAL_Guest * |
2083 | GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg, | 2097 | GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg, |
2084 | struct GNUNET_IDENTITY_Ego *ego, | 2098 | const struct GNUNET_IDENTITY_Ego *ego, |
2085 | char *gns_name, | 2099 | const char *gns_name, const char *password, |
2086 | const struct GNUNET_PSYC_Message *join_msg, | 2100 | const struct GNUNET_PSYC_Message *join_msg, |
2087 | struct GNUNET_SOCIAL_Slicer *slicer, | 2101 | struct GNUNET_SOCIAL_Slicer *slicer, |
2088 | GNUNET_SOCIAL_GuestEnterCallback local_enter_cb, | 2102 | GNUNET_SOCIAL_GuestEnterCallback local_enter_cb, |
@@ -2092,7 +2106,10 @@ GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg | |||
2092 | struct GNUNET_SOCIAL_Guest *gst = GNUNET_malloc (sizeof (*gst)); | 2106 | struct GNUNET_SOCIAL_Guest *gst = GNUNET_malloc (sizeof (*gst)); |
2093 | struct GNUNET_SOCIAL_Place *plc = &gst->plc; | 2107 | struct GNUNET_SOCIAL_Place *plc = &gst->plc; |
2094 | 2108 | ||
2109 | GNUNET_assert (NULL != join_msg); | ||
2110 | |||
2095 | gst->enter_cb = local_enter_cb; | 2111 | gst->enter_cb = local_enter_cb; |
2112 | gst->entry_dcsn_cb = entry_decision_cb; | ||
2096 | gst->cb_cls = cls; | 2113 | gst->cb_cls = cls; |
2097 | 2114 | ||
2098 | plc->ego_key = *GNUNET_IDENTITY_ego_get_private_key (ego); | 2115 | plc->ego_key = *GNUNET_IDENTITY_ego_get_private_key (ego); |
@@ -2100,14 +2117,10 @@ GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg | |||
2100 | plc->is_host = GNUNET_NO; | 2117 | plc->is_host = GNUNET_NO; |
2101 | plc->slicer = slicer; | 2118 | plc->slicer = slicer; |
2102 | 2119 | ||
2103 | struct GuestEnterRequest * | 2120 | uint16_t join_msg_size = ntohs (join_msg->header.size); |
2104 | req = guest_enter_request_create (&plc->ego_key, NULL, NULL, 0, NULL, | 2121 | plc->connect_msg = GNUNET_malloc (join_msg_size); |
2105 | join_msg); | 2122 | memcpy (plc->connect_msg, join_msg, join_msg_size); |
2106 | plc->connect_msg = &req->header; | ||
2107 | 2123 | ||
2108 | /* FIXME: get the public key of the origin and relays | ||
2109 | * by looking up the PLACE record of gns_name. | ||
2110 | */ | ||
2111 | if (NULL == gns) | 2124 | if (NULL == gns) |
2112 | gns = GNUNET_GNS_connect (cfg); | 2125 | gns = GNUNET_GNS_connect (cfg); |
2113 | 2126 | ||
@@ -2119,7 +2132,6 @@ GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg | |||
2119 | GNUNET_GNS_lookup (gns, gns_name, &ego_pub_key, | 2132 | GNUNET_GNS_lookup (gns, gns_name, &ego_pub_key, |
2120 | GNUNET_GNSRECORD_TYPE_PLACE, GNUNET_GNS_LO_DEFAULT, | 2133 | GNUNET_GNSRECORD_TYPE_PLACE, GNUNET_GNS_LO_DEFAULT, |
2121 | NULL, gns_result_guest_enter, gst); | 2134 | NULL, gns_result_guest_enter, gst); |
2122 | |||
2123 | return gst; | 2135 | return gst; |
2124 | } | 2136 | } |
2125 | 2137 | ||
@@ -2151,10 +2163,13 @@ GNUNET_SOCIAL_guest_talk (struct GNUNET_SOCIAL_Guest *gst, | |||
2151 | void *notify_data_cls, | 2163 | void *notify_data_cls, |
2152 | enum GNUNET_SOCIAL_TalkFlags flags) | 2164 | enum GNUNET_SOCIAL_TalkFlags flags) |
2153 | { | 2165 | { |
2166 | struct GNUNET_SOCIAL_Place *plc = &gst->plc; | ||
2167 | GNUNET_assert (NULL != plc->tmit); | ||
2168 | |||
2154 | if (GNUNET_OK == | 2169 | if (GNUNET_OK == |
2155 | GNUNET_PSYC_transmit_message (gst->plc.tmit, method_name, env, | 2170 | GNUNET_PSYC_transmit_message (plc->tmit, method_name, env, |
2156 | NULL, notify_data, notify_data_cls, flags)); | 2171 | NULL, notify_data, notify_data_cls, flags)); |
2157 | return (struct GNUNET_SOCIAL_TalkRequest *) gst->plc.tmit; | 2172 | return (struct GNUNET_SOCIAL_TalkRequest *) plc->tmit; |
2158 | } | 2173 | } |
2159 | 2174 | ||
2160 | 2175 | ||
@@ -2209,13 +2224,14 @@ GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst, | |||
2209 | { | 2224 | { |
2210 | struct GNUNET_SOCIAL_Place *plc = &gst->plc; | 2225 | struct GNUNET_SOCIAL_Place *plc = &gst->plc; |
2211 | 2226 | ||
2212 | /* FIXME: send msg to service */ | ||
2213 | |||
2214 | plc->is_disconnecting = GNUNET_YES; | 2227 | plc->is_disconnecting = GNUNET_YES; |
2215 | plc->disconnect_cb = leave_cb; | 2228 | plc->disconnect_cb = leave_cb; |
2216 | plc->disconnect_cls = leave_cls; | 2229 | plc->disconnect_cls = leave_cls; |
2217 | 2230 | ||
2218 | if (GNUNET_NO == keep_active) | 2231 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
2232 | "Guest: leaving place.\n"); | ||
2233 | |||
2234 | if (GNUNET_NO == keep_active && NULL != plc->tmit) | ||
2219 | { | 2235 | { |
2220 | GNUNET_SOCIAL_guest_talk (gst, "_notice_place_leave", env, NULL, NULL, | 2236 | GNUNET_SOCIAL_guest_talk (gst, "_notice_place_leave", env, NULL, NULL, |
2221 | GNUNET_SOCIAL_TALK_NONE); | 2237 | GNUNET_SOCIAL_TALK_NONE); |
@@ -2471,4 +2487,47 @@ GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *look) | |||
2471 | } | 2487 | } |
2472 | 2488 | ||
2473 | 2489 | ||
2490 | /** | ||
2491 | * Add public key to the GNS zone of the @e ego. | ||
2492 | * | ||
2493 | * @param cfg | ||
2494 | * Configuration. | ||
2495 | * @param ego | ||
2496 | * Ego. | ||
2497 | * @param name | ||
2498 | * The name for the PKEY record to put in the zone. | ||
2499 | * @param pub_key | ||
2500 | * Public key to add. | ||
2501 | * @param expiration_time | ||
2502 | * Expiration time of the record, use 0 to remove the record. | ||
2503 | * @param result_cb | ||
2504 | * Function called with the result of the operation. | ||
2505 | * @param result_cls | ||
2506 | * Closure for @a result_cb | ||
2507 | */ | ||
2508 | void | ||
2509 | GNUNET_SOCIAL_zone_add_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
2510 | const struct GNUNET_IDENTITY_Ego *ego, | ||
2511 | const char *name, | ||
2512 | const struct GNUNET_CRYPTO_EcdsaPublicKey *pub_key, | ||
2513 | struct GNUNET_TIME_Absolute expiration_time, | ||
2514 | GNUNET_NAMESTORE_ContinuationWithStatus result_cb, | ||
2515 | void *result_cls) | ||
2516 | { | ||
2517 | if (NULL == namestore) | ||
2518 | namestore = GNUNET_NAMESTORE_connect (cfg); | ||
2519 | |||
2520 | struct GNUNET_GNSRECORD_Data rd = { }; | ||
2521 | rd.record_type = GNUNET_GNSRECORD_TYPE_PKEY; | ||
2522 | rd.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION; | ||
2523 | rd.expiration_time = expiration_time.abs_value_us; | ||
2524 | rd.data = pub_key; | ||
2525 | rd.data_size = sizeof (*pub_key); | ||
2526 | |||
2527 | GNUNET_NAMESTORE_records_store (namestore, | ||
2528 | GNUNET_IDENTITY_ego_get_private_key (ego), | ||
2529 | name, 1, &rd, result_cb, result_cls); | ||
2530 | } | ||
2531 | |||
2532 | |||
2474 | /* end of social_api.c */ | 2533 | /* end of social_api.c */ |