aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGabor X Toth <*@tg-x.net>2015-09-08 01:36:44 +0000
committerGabor X Toth <*@tg-x.net>2015-09-08 01:36:44 +0000
commitb5e08fdd9c1663e81afef784a6e3bd6b4552e23e (patch)
treecae60510ffa95f024e63327734f809dd3d929b02 /src
parenta86a539258282bedabd24919e8af9bd113a6538a (diff)
downloadgnunet-b5e08fdd9c1663e81afef784a6e3bd6b4552e23e.tar.gz
gnunet-b5e08fdd9c1663e81afef784a6e3bd6b4552e23e.zip
social: guest_enter_by_name(); zone_add_pkey(); join_msg fixes
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_psyc_util_lib.h9
-rw-r--r--src/include/gnunet_social_service.h63
-rw-r--r--src/multicast/gnunet-service-multicast.c2
-rw-r--r--src/multicast/multicast_api.c1
-rw-r--r--src/psyc/gnunet-service-psyc.c6
-rw-r--r--src/psyc/psyc_api.c11
-rw-r--r--src/psycstore/gnunet-service-psycstore.c2
-rw-r--r--src/psycstore/psyc_util_lib.c46
-rw-r--r--src/psycstore/psycstore_api.c2
-rw-r--r--src/social/gnunet-service-social.c4
-rw-r--r--src/social/social_api.c251
-rw-r--r--src/social/test_social.c103
12 files changed, 344 insertions, 156 deletions
diff --git a/src/include/gnunet_psyc_util_lib.h b/src/include/gnunet_psyc_util_lib.h
index 504476573..10cfc68d9 100644
--- a/src/include/gnunet_psyc_util_lib.h
+++ b/src/include/gnunet_psyc_util_lib.h
@@ -79,7 +79,7 @@ GNUNET_PSYC_message_create (const char *method_name,
79 * #GNUNET_SYSERR on parse error. 79 * #GNUNET_SYSERR on parse error.
80 */ 80 */
81int 81int
82GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_Message *msg, 82GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_MessageHeader *msg,
83 const char **method_name, 83 const char **method_name,
84 struct GNUNET_ENV_Environment *env, 84 struct GNUNET_ENV_Environment *env,
85 const void **data, 85 const void **data,
@@ -247,6 +247,13 @@ GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *
247 uint32_t flags); 247 uint32_t flags);
248 248
249 249
250/**
251 * Create a new PSYC message header from a PSYC message.
252 */
253struct GNUNET_PSYC_MessageHeader *
254GNUNET_PSYC_message_header_create_from_psyc (const struct GNUNET_PSYC_Message *msg);
255
256
250#if 0 /* keep Emacsens' auto-indent happy */ 257#if 0 /* keep Emacsens' auto-indent happy */
251{ 258{
252#endif 259#endif
diff --git a/src/include/gnunet_social_service.h b/src/include/gnunet_social_service.h
index 0af48d168..edb762a1e 100644
--- a/src/include/gnunet_social_service.h
+++ b/src/include/gnunet_social_service.h
@@ -494,6 +494,7 @@ GNUNET_SOCIAL_nym_get_key_hash (const struct GNUNET_SOCIAL_Nym *nym);
494 * Expiration time of the record, use 0 to remove the record. 494 * Expiration time of the record, use 0 to remove the record.
495 * @param password 495 * @param password
496 * Password used to encrypt the record. 496 * Password used to encrypt the record.
497 * FIXME: not implemented yet.
497 * @param result_cb 498 * @param result_cb
498 * Function called with the result of the operation. 499 * Function called with the result of the operation.
499 * @param result_cls 500 * @param result_cls
@@ -502,9 +503,9 @@ GNUNET_SOCIAL_nym_get_key_hash (const struct GNUNET_SOCIAL_Nym *nym);
502void 503void
503GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *host, 504GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *host,
504 const char *name, 505 const char *name,
505 size_t peer_count, 506 uint32_t peer_count,
506 const struct GNUNET_PeerIdentity *peers, 507 const struct GNUNET_PeerIdentity *peers,
507 struct GNUNET_TIME_Relative expiration_time, 508 struct GNUNET_TIME_Absolute expiration_time,
508 const char *password, 509 const char *password,
509 GNUNET_NAMESTORE_ContinuationWithStatus result_cb, 510 GNUNET_NAMESTORE_ContinuationWithStatus result_cb,
510 void *result_cls); 511 void *result_cls);
@@ -702,27 +703,35 @@ GNUNET_SOCIAL_guest_enter (const struct GNUNET_CONFIGURATION_Handle *cfg,
702 703
703 704
704/** 705/**
705 * Request entry to a place as a guest using a GNS name. 706 * Request entry to a place by name as a guest.
706 * 707 *
707 * @param cfg Configuration to contact the social service. 708 * @param cfg
708 * @param ego Identity of the guest. 709 * Configuration to contact the social service.
709 * @param address GNS name of the place to enter. Either in the form of 710 * @param ego
711 * Identity of the guest.
712 * @param gns_name
713 * GNS name of the place to enter. Either in the form of
710 * 'room.friend.gnu', or 'NYMPUBKEY.zkey'. This latter case refers to 714 * 'room.friend.gnu', or 'NYMPUBKEY.zkey'. This latter case refers to
711 * the 'PLACE' record of the empty label ("+") in the GNS zone with the 715 * the 'PLACE' record of the empty label ("+") in the GNS zone with the
712 * nym's public key 'NYMPUBKEY', and can be used to request entry to a 716 * nym's public key 'NYMPUBKEY', and can be used to request entry to a
713 * pseudonym's place directly. 717 * pseudonym's place directly.
714 * @param method_name Method name for the message. 718 * @param password
715 * @param env Environment containing variables for the message, or NULL. 719 * Password to decrypt the record, or NULL for cleartext records.
716 * @param data Payload for the message to give to the enter callback. 720 * @param join_msg
717 * @param data_size Number of bytes in @a data. 721 * Entry request message.
718 * @param slicer Slicer to use for processing incoming requests from guests. 722 * @param slicer
723 * Slicer to use for processing incoming requests from guests.
724 * @param local_enter_cb
725 * Called upon connection established to the social service.
726 * @param entry_decision_cb
727 * Called upon receiving entry decision.
719 * 728 *
720 * @return NULL on errors, otherwise handle for the guest. 729 * @return NULL on errors, otherwise handle for the guest.
721 */ 730 */
722struct GNUNET_SOCIAL_Guest * 731struct GNUNET_SOCIAL_Guest *
723GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg, 732GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
724 struct GNUNET_IDENTITY_Ego *ego, 733 const struct GNUNET_IDENTITY_Ego *ego,
725 char *gns_name, 734 const char *gns_name, const char *password,
726 const struct GNUNET_PSYC_Message *join_msg, 735 const struct GNUNET_PSYC_Message *join_msg,
727 struct GNUNET_SOCIAL_Slicer *slicer, 736 struct GNUNET_SOCIAL_Slicer *slicer,
728 GNUNET_SOCIAL_GuestEnterCallback local_enter_cb, 737 GNUNET_SOCIAL_GuestEnterCallback local_enter_cb,
@@ -964,6 +973,34 @@ void
964GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh); 973GNUNET_SOCIAL_place_look_cancel (struct GNUNET_SOCIAL_LookHandle *lh);
965 974
966 975
976/**
977 * Add public key to the GNS zone of the @e ego.
978 *
979 * @param cfg
980 * Configuration.
981 * @param ego
982 * Ego.
983 * @param name
984 * The name for the PKEY record to put in the zone.
985 * @param pub_key
986 * Public key to add.
987 * @param expiration_time
988 * Expiration time of the record, use 0 to remove the record.
989 * @param result_cb
990 * Function called with the result of the operation.
991 * @param result_cls
992 * Closure for @a result_cb
993 */
994void
995GNUNET_SOCIAL_zone_add_pkey (const struct GNUNET_CONFIGURATION_Handle *cfg,
996 const struct GNUNET_IDENTITY_Ego *ego,
997 const char *name,
998 const struct GNUNET_CRYPTO_EcdsaPublicKey *pub_key,
999 struct GNUNET_TIME_Absolute expiration_time,
1000 GNUNET_NAMESTORE_ContinuationWithStatus result_cb,
1001 void *result_cls);
1002
1003
967#if 0 /* keep Emacsens' auto-indent happy */ 1004#if 0 /* keep Emacsens' auto-indent happy */
968{ 1005{
969#endif 1006#endif
diff --git a/src/multicast/gnunet-service-multicast.c b/src/multicast/gnunet-service-multicast.c
index a9b15cef1..fbf3c159c 100644
--- a/src/multicast/gnunet-service-multicast.c
+++ b/src/multicast/gnunet-service-multicast.c
@@ -807,7 +807,7 @@ client_recv_member_join (void *cls, struct GNUNET_SERVER_Client *client,
807 else if (grp->clients_head == grp->clients_tail) 807 else if (grp->clients_head == grp->clients_tail)
808 { /* First client of the group, send join request. */ 808 { /* First client of the group, send join request. */
809 struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &msg[1]; 809 struct GNUNET_PeerIdentity *relays = (struct GNUNET_PeerIdentity *) &msg[1];
810 uint32_t relay_count = ntohs (msg->relay_count); 810 uint32_t relay_count = ntohl (msg->relay_count);
811 uint16_t relay_size = relay_count * sizeof (*relays); 811 uint16_t relay_size = relay_count * sizeof (*relays);
812 struct GNUNET_MessageHeader *join_msg = NULL; 812 struct GNUNET_MessageHeader *join_msg = NULL;
813 uint16_t join_msg_size = 0; 813 uint16_t join_msg_size = 0;
diff --git a/src/multicast/multicast_api.c b/src/multicast/multicast_api.c
index 5cd729203..c8d82e892 100644
--- a/src/multicast/multicast_api.c
+++ b/src/multicast/multicast_api.c
@@ -802,6 +802,7 @@ GNUNET_MULTICAST_member_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
802 join->group_key = *group_key; 802 join->group_key = *group_key;
803 join->member_key = *member_key; 803 join->member_key = *member_key;
804 join->origin = *origin; 804 join->origin = *origin;
805 join->relay_count = ntohl (relay_count);
805 if (0 < relay_size) 806 if (0 < relay_size)
806 memcpy (&join[1], relays, relay_size); 807 memcpy (&join[1], relays, relay_size);
807 if (0 < join_msg_size) 808 if (0 < join_msg_size)
diff --git a/src/psyc/gnunet-service-psyc.c b/src/psyc/gnunet-service-psyc.c
index 070fd8e47..1f7e7c23c 100644
--- a/src/psyc/gnunet-service-psyc.c
+++ b/src/psyc/gnunet-service-psyc.c
@@ -1792,9 +1792,11 @@ client_recv_slave_join (void *cls, struct GNUNET_SERVER_Client *client,
1792 if (sizeof (*req) + relay_size + sizeof (struct GNUNET_MessageHeader) 1792 if (sizeof (*req) + relay_size + sizeof (struct GNUNET_MessageHeader)
1793 <= req_size) 1793 <= req_size)
1794 { 1794 {
1795 join_msg_size = ntohs (slv->join_msg->header.size); 1795 struct GNUNET_PSYC_Message *
1796 join_msg = (struct GNUNET_PSYC_Message *) (((char *) &req[1]) + relay_size);
1797 join_msg_size = ntohs (join_msg->header.size);
1796 slv->join_msg = GNUNET_malloc (join_msg_size); 1798 slv->join_msg = GNUNET_malloc (join_msg_size);
1797 memcpy (slv->join_msg, ((char *) &req[1]) + relay_size, join_msg_size); 1799 memcpy (slv->join_msg, join_msg, join_msg_size);
1798 } 1800 }
1799 if (sizeof (*req) + relay_size + join_msg_size != req_size) 1801 if (sizeof (*req) + relay_size + join_msg_size != req_size)
1800 { 1802 {
diff --git a/src/psyc/psyc_api.c b/src/psyc/psyc_api.c
index b862eee9c..6128e4d82 100644
--- a/src/psyc/psyc_api.c
+++ b/src/psyc/psyc_api.c
@@ -669,7 +669,7 @@ GNUNET_PSYC_master_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
669 req->channel_key = *channel_key; 669 req->channel_key = *channel_key;
670 req->policy = policy; 670 req->policy = policy;
671 671
672 chn->connect_msg = (struct GNUNET_MessageHeader *) req; 672 chn->connect_msg = &req->header;
673 chn->cfg = cfg; 673 chn->cfg = cfg;
674 chn->is_master = GNUNET_YES; 674 chn->is_master = GNUNET_YES;
675 675
@@ -896,8 +896,7 @@ GNUNET_PSYC_slave_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
896 else 896 else
897 join_msg_size = ntohs (join_msg->header.size); 897 join_msg_size = ntohs (join_msg->header.size);
898 req = GNUNET_malloc (sizeof (*req) + relay_size + join_msg_size); 898 req = GNUNET_malloc (sizeof (*req) + relay_size + join_msg_size);
899 req->header.size = htons (sizeof (*req) 899 req->header.size = htons (sizeof (*req) + relay_size + join_msg_size);
900 + relay_count * sizeof (*relays));
901 req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN); 900 req->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_SLAVE_JOIN);
902 req->channel_key = *channel_key; 901 req->channel_key = *channel_key;
903 req->slave_key = *slave_key; 902 req->slave_key = *slave_key;
@@ -908,11 +907,9 @@ GNUNET_PSYC_slave_join (const struct GNUNET_CONFIGURATION_Handle *cfg,
908 memcpy (&req[1], relays, relay_size); 907 memcpy (&req[1], relays, relay_size);
909 908
910 if (NULL != join_msg) 909 if (NULL != join_msg)
911 memcpy ((char *) &req[1] + relay_size, 910 memcpy ((char *) &req[1] + relay_size, join_msg, join_msg_size);
912 join_msg,
913 join_msg_size);
914 911
915 chn->connect_msg = (struct GNUNET_MessageHeader *) req; 912 chn->connect_msg = &req->header;
916 chn->cfg = cfg; 913 chn->cfg = cfg;
917 chn->is_master = GNUNET_NO; 914 chn->is_master = GNUNET_NO;
918 915
diff --git a/src/psycstore/gnunet-service-psycstore.c b/src/psycstore/gnunet-service-psycstore.c
index 01eb5d707..44103c6a0 100644
--- a/src/psycstore/gnunet-service-psycstore.c
+++ b/src/psycstore/gnunet-service-psycstore.c
@@ -479,7 +479,7 @@ handle_counters_get (void *cls,
479 479
480 res.header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS); 480 res.header.type = htons (GNUNET_MESSAGE_TYPE_PSYCSTORE_RESULT_COUNTERS);
481 res.header.size = htons (sizeof (res)); 481 res.header.size = htons (sizeof (res));
482 res.result_code = htonl (ret - INT32_MIN); 482 res.result_code = htonl (ret);
483 res.op_id = req->op_id; 483 res.op_id = req->op_id;
484 res.max_fragment_id = GNUNET_htonll (res.max_fragment_id); 484 res.max_fragment_id = GNUNET_htonll (res.max_fragment_id);
485 res.max_message_id = GNUNET_htonll (res.max_message_id); 485 res.max_message_id = GNUNET_htonll (res.max_message_id);
diff --git a/src/psycstore/psyc_util_lib.c b/src/psycstore/psyc_util_lib.c
index e45bcafb3..80e84f29c 100644
--- a/src/psycstore/psyc_util_lib.c
+++ b/src/psycstore/psyc_util_lib.c
@@ -198,11 +198,11 @@ GNUNET_PSYC_message_create (const char *method_name,
198 if (method_name_size == 1) 198 if (method_name_size == 1)
199 return NULL; 199 return NULL;
200 200
201 uint16_t msg_size = sizeof (*msg) /* header */ 201 uint16_t msg_size = sizeof (*msg) /* header */
202 + sizeof (*pmeth) + method_name_size /* method */ 202 + sizeof (*pmeth) + method_name_size /* method */
203 + env_size /* modifiers */ 203 + env_size /* modifiers */
204 + ((0 < data_size) ? sizeof (*pmsg) + data_size : 0)/* data */ 204 + ((0 < data_size) ? sizeof (*pmsg) + data_size : 0) /* data */
205 + sizeof (*pmsg); /* end of message */ 205 + sizeof (*pmsg); /* end of message */
206 msg = GNUNET_malloc (msg_size); 206 msg = GNUNET_malloc (msg_size);
207 msg->header.size = htons (msg_size); 207 msg->header.size = htons (msg_size);
208 msg->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE); /* FIXME */ 208 msg->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE); /* FIXME */
@@ -225,6 +225,10 @@ GNUNET_PSYC_message_create (const char *method_name,
225 p += pmod->header.size; 225 p += pmod->header.size;
226 pmod->header.size = htons (pmod->header.size); 226 pmod->header.size = htons (pmod->header.size);
227 227
228 pmod->oper = mod->oper;
229 pmod->name_size = htons (mod_name_size);
230 pmod->value_size = htonl (mod->value_size);
231
228 memcpy (&pmod[1], mod->name, mod_name_size); 232 memcpy (&pmod[1], mod->name, mod_name_size);
229 if (0 < mod->value_size) 233 if (0 < mod->value_size)
230 memcpy ((char *) &pmod[1] + mod_name_size, mod->value, mod->value_size); 234 memcpy ((char *) &pmod[1] + mod_name_size, mod->value, mod->value_size);
@@ -1192,9 +1196,9 @@ parse_message_part_cb (void *cls,
1192 pmod = (struct GNUNET_PSYC_MessageModifier *) msg; 1196 pmod = (struct GNUNET_PSYC_MessageModifier *) msg;
1193 1197
1194 const char *name = (const char *) &pmod[1]; 1198 const char *name = (const char *) &pmod[1];
1195 const void *value = name + pmod->name_size; 1199 const void *value = name + ntohs (pmod->name_size);
1196 GNUNET_ENV_environment_add (pmc->env, pmod->oper, name, value, 1200 GNUNET_ENV_environment_add (pmc->env, pmod->oper, name, value,
1197 pmod->value_size); 1201 ntohl (pmod->value_size));
1198 pmc->msg_state = GNUNET_PSYC_MESSAGE_STATE_MODIFIER; 1202 pmc->msg_state = GNUNET_PSYC_MESSAGE_STATE_MODIFIER;
1199 break; 1203 break;
1200 } 1204 }
@@ -1233,7 +1237,7 @@ parse_message_part_cb (void *cls,
1233 * #GNUNET_SYSERR on parse error. 1237 * #GNUNET_SYSERR on parse error.
1234 */ 1238 */
1235int 1239int
1236GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_Message *msg, 1240GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_MessageHeader *msg,
1237 const char **method_name, 1241 const char **method_name,
1238 struct GNUNET_ENV_Environment *env, 1242 struct GNUNET_ENV_Environment *env,
1239 const void **data, 1243 const void **data,
@@ -1245,16 +1249,10 @@ GNUNET_PSYC_message_parse (const struct GNUNET_PSYC_Message *msg,
1245 cls.data = data; 1249 cls.data = data;
1246 cls.data_size = data_size; 1250 cls.data_size = data_size;
1247 1251
1248 uint16_t msg_size = ntohs (msg->header.size);
1249 struct GNUNET_PSYC_MessageHeader *
1250 pmsg = GNUNET_malloc (sizeof (*pmsg) + msg_size - sizeof (*msg));
1251 memcpy (&pmsg[1], &msg[1], msg_size - sizeof (*msg));
1252
1253 struct GNUNET_PSYC_ReceiveHandle * 1252 struct GNUNET_PSYC_ReceiveHandle *
1254 recv = GNUNET_PSYC_receive_create (NULL, parse_message_part_cb, &cls); 1253 recv = GNUNET_PSYC_receive_create (NULL, parse_message_part_cb, &cls);
1255 GNUNET_PSYC_receive_message (recv, pmsg); 1254 GNUNET_PSYC_receive_message (recv, msg);
1256 GNUNET_PSYC_receive_destroy (recv); 1255 GNUNET_PSYC_receive_destroy (recv);
1257 GNUNET_free (pmsg);
1258 1256
1259 return (GNUNET_PSYC_MESSAGE_STATE_END == cls.msg_state) 1257 return (GNUNET_PSYC_MESSAGE_STATE_END == cls.msg_state)
1260 ? GNUNET_OK 1258 ? GNUNET_OK
@@ -1284,7 +1282,7 @@ GNUNET_PSYC_message_header_init (struct GNUNET_PSYC_MessageHeader *pmsg,
1284 1282
1285 1283
1286/** 1284/**
1287 * Create a new PSYC message header from a multicast message for sending it to clients. 1285 * Create a new PSYC message header from a multicast message.
1288 */ 1286 */
1289struct GNUNET_PSYC_MessageHeader * 1287struct GNUNET_PSYC_MessageHeader *
1290GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg, 1288GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *mmsg,
@@ -1298,3 +1296,19 @@ GNUNET_PSYC_message_header_create (const struct GNUNET_MULTICAST_MessageHeader *
1298 GNUNET_PSYC_message_header_init (pmsg, mmsg, flags); 1296 GNUNET_PSYC_message_header_init (pmsg, mmsg, flags);
1299 return pmsg; 1297 return pmsg;
1300} 1298}
1299
1300
1301/**
1302 * Create a new PSYC message header from a PSYC message.
1303 */
1304struct GNUNET_PSYC_MessageHeader *
1305GNUNET_PSYC_message_header_create_from_psyc (const struct GNUNET_PSYC_Message *msg)
1306{
1307 uint16_t msg_size = ntohs (msg->header.size);
1308 struct GNUNET_PSYC_MessageHeader *
1309 pmsg = GNUNET_malloc (sizeof (*pmsg) + msg_size - sizeof (*msg));
1310 pmsg->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_MESSAGE);
1311 pmsg->header.size = htons (sizeof (*pmsg) + msg_size - sizeof (*msg));
1312 memcpy (&pmsg[1], &msg[1], msg_size - sizeof (*msg));
1313 return pmsg;
1314}
diff --git a/src/psycstore/psycstore_api.c b/src/psycstore/psycstore_api.c
index 214d8ba5d..f378be210 100644
--- a/src/psycstore/psycstore_api.c
+++ b/src/psycstore/psycstore_api.c
@@ -346,7 +346,7 @@ message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
346 if (NULL != op->data_cb) 346 if (NULL != op->data_cb)
347 ((GNUNET_PSYCSTORE_CountersCallback) 347 ((GNUNET_PSYCSTORE_CountersCallback)
348 op->data_cb) (op->cls, 348 op->data_cb) (op->cls,
349 ntohl (cres->result_code) + INT32_MIN, 349 ntohl (cres->result_code),
350 GNUNET_ntohll (cres->max_fragment_id), 350 GNUNET_ntohll (cres->max_fragment_id),
351 GNUNET_ntohll (cres->max_message_id), 351 GNUNET_ntohll (cres->max_message_id),
352 GNUNET_ntohll (cres->max_group_generation), 352 GNUNET_ntohll (cres->max_group_generation),
diff --git a/src/social/gnunet-service-social.c b/src/social/gnunet-service-social.c
index 3f558730e..bf147d3ba 100644
--- a/src/social/gnunet-service-social.c
+++ b/src/social/gnunet-service-social.c
@@ -528,7 +528,7 @@ psyc_master_started (void *cls, int result, uint64_t max_message_id)
528 struct GNUNET_PSYC_CountersResultMessage res; 528 struct GNUNET_PSYC_CountersResultMessage res;
529 res.header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER_ACK); 529 res.header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER_ACK);
530 res.header.size = htons (sizeof (res)); 530 res.header.size = htons (sizeof (res));
531 res.result_code = htonl (result - INT32_MIN); 531 res.result_code = htonl (result);
532 res.max_message_id = GNUNET_htonll (plc->max_message_id); 532 res.max_message_id = GNUNET_htonll (plc->max_message_id);
533 533
534 client_send_msg (plc, &res.header); 534 client_send_msg (plc, &res.header);
@@ -568,7 +568,7 @@ psyc_slave_connected (void *cls, int result, uint64_t max_message_id)
568 struct GNUNET_PSYC_CountersResultMessage res; 568 struct GNUNET_PSYC_CountersResultMessage res;
569 res.header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK); 569 res.header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_GUEST_ENTER_ACK);
570 res.header.size = htons (sizeof (res)); 570 res.header.size = htons (sizeof (res));
571 res.result_code = htonl (result - INT32_MIN); 571 res.result_code = htonl (result);
572 res.max_message_id = GNUNET_htonll (plc->max_message_id); 572 res.max_message_id = GNUNET_htonll (plc->max_message_id);
573 573
574 client_send_msg (plc, &res.header); 574 client_send_msg (plc, &res.header);
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[] =
1424static void 1428static void
1425place_cleanup (struct GNUNET_SOCIAL_Place *plc) 1429place_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)
1753void 1777void
1754GNUNET_SOCIAL_host_advertise (struct GNUNET_SOCIAL_Host *hst, 1778GNUNET_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 */
2082struct GNUNET_SOCIAL_Guest * 2096struct GNUNET_SOCIAL_Guest *
2083GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_CONFIGURATION_Handle *cfg, 2097GNUNET_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 */
2508void
2509GNUNET_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 */
diff --git a/src/social/test_social.c b/src/social/test_social.c
index 50150449c..5a224c4ae 100644
--- a/src/social/test_social.c
+++ b/src/social/test_social.c
@@ -68,6 +68,7 @@ struct GNUNET_CRYPTO_EcdsaPrivateKey *guest_key;
68 68
69struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key; 69struct GNUNET_CRYPTO_EddsaPublicKey place_pub_key;
70struct GNUNET_CRYPTO_EcdsaPublicKey guest_pub_key; 70struct GNUNET_CRYPTO_EcdsaPublicKey guest_pub_key;
71struct GNUNET_CRYPTO_EcdsaPublicKey host_pub_key;
71 72
72struct GNUNET_SOCIAL_Slicer *host_slicer; 73struct GNUNET_SOCIAL_Slicer *host_slicer;
73struct GNUNET_SOCIAL_Slicer *guest_slicer; 74struct GNUNET_SOCIAL_Slicer *guest_slicer;
@@ -110,6 +111,8 @@ struct GNUNET_PSYC_Message *join_resp;
110 111
111uint32_t counter; 112uint32_t counter;
112 113
114uint8_t guest_pkey_added = GNUNET_NO;
115
113enum 116enum
114{ 117{
115 TEST_NONE = 0, 118 TEST_NONE = 0,
@@ -136,11 +139,12 @@ enum
136static void 139static void
137guest_enter (); 140guest_enter ();
138 141
142static void
143guest_enter_by_name ();
139 144
140static void 145static void
141guest_talk (); 146guest_talk ();
142 147
143
144static void 148static void
145host_announce2 (); 149host_announce2 ();
146 150
@@ -309,10 +313,25 @@ schedule_host_leave (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
309 313
310 314
311static void 315static void
316id_guest_ego_cb2 (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
317{
318 GNUNET_assert (NULL != ego);
319 guest_ego = ego;
320
321 guest_enter_by_name ();
322}
323
324
325static void
312host_recv_advertise_result (void *cls, int32_t success, const char *emsg) 326host_recv_advertise_result (void *cls, int32_t success, const char *emsg)
313{ 327{
328 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
329 "Test #%u: Advertise result: %d (%s).\n",
330 test, success, emsg);
314 GNUNET_assert (GNUNET_YES == success); 331 GNUNET_assert (GNUNET_YES == success);
315 GNUNET_SCHEDULER_add_now (&schedule_host_leave, NULL); 332
333 GNUNET_assert (GNUNET_YES == guest_pkey_added);
334 GNUNET_IDENTITY_ego_lookup (cfg, guest_name, id_guest_ego_cb2, NULL);
316} 335}
317 336
318 337
@@ -320,10 +339,12 @@ static void
320host_advertise () 339host_advertise ()
321{ 340{
322 test = TEST_HOST_ADVERTISE; 341 test = TEST_HOST_ADVERTISE;
323 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Test #%u: Advertising place.\n", test); 342 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
343 "Test #%u: Advertising place.\n", test);
344
324 GNUNET_SOCIAL_host_advertise (hst, "home", 1, &this_peer, 345 GNUNET_SOCIAL_host_advertise (hst, "home", 1, &this_peer,
325 GNUNET_TIME_UNIT_MINUTES, "let.me*in!", 346 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
326 host_recv_advertise_result, hst); 347 "let.me*in!", host_recv_advertise_result, hst);
327} 348}
328 349
329 350
@@ -714,10 +735,9 @@ host_recv_eom (void *cls,
714 guest_history_replay (); 735 guest_history_replay ();
715 break; 736 break;
716 737
717 case TEST_GUEST_LEAVE:
718 break;
719
720 default: 738 default:
739 if (TEST_GUEST_LEAVE <= test)
740 break;
721 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); 741 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
722 GNUNET_assert (0); 742 GNUNET_assert (0);
723 } 743 }
@@ -811,19 +831,22 @@ host_announce2 ()
811static void 831static void
812guest_recv_entry_decision (void *cls, 832guest_recv_entry_decision (void *cls,
813 int is_admitted, 833 int is_admitted,
814 const struct GNUNET_PSYC_Message *entry_resp) 834 const struct GNUNET_PSYC_Message *entry_msg)
815{ 835{
816 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 836 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
817 "Test #%u: Guest received entry decision (try %u): %d.\n", 837 "Test #%u: Guest received entry decision (try %u): %d.\n",
818 test, join_req_count, is_admitted); 838 test, join_req_count, is_admitted);
819 839
820 if (NULL != entry_resp) 840 if (NULL != entry_msg)
821 { 841 {
822 struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create (); 842 struct GNUNET_ENV_Environment *env = GNUNET_ENV_environment_create ();
823 const char *method_name = NULL; 843 const char *method_name = NULL;
824 const void *data = NULL; 844 const void *data = NULL;
825 uint16_t data_size = 0; 845 uint16_t data_size = 0;
826 GNUNET_PSYC_message_parse (entry_resp, &method_name, env, &data, &data_size); 846 struct GNUNET_PSYC_MessageHeader *
847 pmsg = GNUNET_PSYC_message_header_create_from_psyc (entry_msg);
848 GNUNET_PSYC_message_parse (pmsg, &method_name, env, &data, &data_size);
849 GNUNET_free (pmsg);
827 850
828 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 851 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
829 "%s\n%.*s\n", 852 "%s\n%.*s\n",
@@ -843,6 +866,10 @@ guest_recv_entry_decision (void *cls,
843 host_announce (); 866 host_announce ();
844 break; 867 break;
845 868
869 case TEST_GUEST_ENTER_BY_NAME:
870 GNUNET_SCHEDULER_add_now (schedule_host_leave, NULL);
871 break;
872
846 default: 873 default:
847 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test); 874 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "invalid test: %d\n", test);
848 GNUNET_assert (0); 875 GNUNET_assert (0);
@@ -878,6 +905,7 @@ host_answer_door (void *cls,
878 905
879 case TEST_HOST_ANSWER_DOOR_ADMIT: 906 case TEST_HOST_ANSWER_DOOR_ADMIT:
880 test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT; 907 test = TEST_GUEST_RECV_ENTRY_DCSN_ADMIT;
908 case TEST_GUEST_ENTER_BY_NAME:
881 join_resp = GNUNET_PSYC_message_create ("_admit_nym", env, 909 join_resp = GNUNET_PSYC_message_create ("_admit_nym", env,
882 DATA2ARG ("Welcome, nym!")); 910 DATA2ARG ("Welcome, nym!"));
883 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp); 911 GNUNET_SOCIAL_host_entry_decision (hst, nym, GNUNET_YES, join_resp);
@@ -894,8 +922,9 @@ static void
894guest_recv_local_enter (void *cls, int result, uint64_t max_message_id) 922guest_recv_local_enter (void *cls, int result, uint64_t max_message_id)
895{ 923{
896 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 924 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
897 "Test #%u: Guest entered to local place.\n", test); 925 "Test #%u: Guest entered to local place: %d\n",
898 926 test, result);
927 GNUNET_assert (0 <= result);
899} 928}
900 929
901 930
@@ -919,14 +948,51 @@ guest_enter ()
919 emsg->data, emsg->data_size); 948 emsg->data, emsg->data_size);
920 949
921 gst = GNUNET_SOCIAL_guest_enter (cfg, guest_ego, &place_pub_key, 950 gst = GNUNET_SOCIAL_guest_enter (cfg, guest_ego, &place_pub_key,
922 &this_peer, 0, NULL, emsg->msg, 951 &this_peer, 0, NULL, emsg->msg, guest_slicer,
923 guest_slicer, &guest_recv_local_enter, 952 guest_recv_local_enter,
924 &guest_recv_entry_decision, NULL); 953 guest_recv_entry_decision, NULL);
954 gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
955}
956
957
958static void
959guest_enter_by_name ()
960{
961 test = TEST_GUEST_ENTER_BY_NAME;
962 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
963 "Test #%u: Entering to place by name as guest.\n", test);
964
965 struct GuestEnterMessage *emsg = &guest_enter_msg;
966
967 emsg->method_name = "_request_enter";
968 emsg->env = GNUNET_ENV_environment_create ();
969 GNUNET_ENV_environment_add (emsg->env, GNUNET_ENV_OP_ASSIGN,
970 "_abc", "abc def", 7);
971 GNUNET_ENV_environment_add (emsg->env, GNUNET_ENV_OP_ASSIGN,
972 "_abc_def", "abc def ghi", 11);
973 emsg->data = "let me in";
974 emsg->data_size = strlen (emsg->data) + 1;
975 emsg->msg = GNUNET_PSYC_message_create (emsg->method_name, emsg->env,
976 emsg->data, emsg->data_size);
977
978 gst = GNUNET_SOCIAL_guest_enter_by_name (cfg, guest_ego,
979 "home.host.gnu", "let.me*in!",
980 emsg->msg, guest_slicer,
981 guest_recv_local_enter,
982 guest_recv_entry_decision, NULL);
925 gst_plc = GNUNET_SOCIAL_guest_get_place (gst); 983 gst_plc = GNUNET_SOCIAL_guest_get_place (gst);
926} 984}
927 985
928 986
929static void 987static void
988guest_recv_add_pkey_result (void *cls, int32_t success, const char *emsg)
989{
990 GNUNET_assert (GNUNET_YES == success);
991 guest_pkey_added = GNUNET_YES;
992}
993
994
995static void
930id_guest_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego) 996id_guest_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
931{ 997{
932 GNUNET_assert (NULL != ego); 998 GNUNET_assert (NULL != ego);
@@ -941,6 +1007,10 @@ id_guest_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
941 guest_recv_mod_foo_bar, &mod_foo_bar_rcls); 1007 guest_recv_mod_foo_bar, &mod_foo_bar_rcls);
942 test = TEST_HOST_ANSWER_DOOR_ADMIT; 1008 test = TEST_HOST_ANSWER_DOOR_ADMIT;
943 1009
1010 GNUNET_SOCIAL_zone_add_pkey (cfg, guest_ego, "host", &host_pub_key,
1011 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_MINUTES),
1012 guest_recv_add_pkey_result, NULL);
1013
944 guest_enter (); 1014 guest_enter ();
945} 1015}
946 1016
@@ -975,6 +1045,7 @@ id_host_ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
975{ 1045{
976 GNUNET_assert (NULL != ego); 1046 GNUNET_assert (NULL != ego);
977 host_ego = ego; 1047 host_ego = ego;
1048 GNUNET_IDENTITY_ego_get_public_key (ego, &host_pub_key);
978 1049
979 host_slicer = GNUNET_SOCIAL_slicer_create (); 1050 host_slicer = GNUNET_SOCIAL_slicer_create ();
980 GNUNET_SOCIAL_slicer_method_add (host_slicer, "", 1051 GNUNET_SOCIAL_slicer_method_add (host_slicer, "",