aboutsummaryrefslogtreecommitdiff
path: root/src/social/social_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/social/social_api.c')
-rw-r--r--src/social/social_api.c118
1 files changed, 67 insertions, 51 deletions
diff --git a/src/social/social_api.c b/src/social/social_api.c
index 3404160a9..a8433ee24 100644
--- a/src/social/social_api.c
+++ b/src/social/social_api.c
@@ -149,12 +149,7 @@ struct GNUNET_SOCIAL_Place
149 struct GNUNET_PSYC_TransmitHandle *tmit; 149 struct GNUNET_PSYC_TransmitHandle *tmit;
150 150
151 /** 151 /**
152 * Receipt handle. 152 * Slicer for processing incoming messages.
153 */
154 struct GNUNET_PSYC_ReceiveHandle *recv;
155
156 /**
157 * Slicer for processing incoming methods.
158 */ 153 */
159 struct GNUNET_PSYC_Slicer *slicer; 154 struct GNUNET_PSYC_Slicer *slicer;
160 155
@@ -204,12 +199,7 @@ struct GNUNET_SOCIAL_Host
204 struct GNUNET_SOCIAL_Place plc; 199 struct GNUNET_SOCIAL_Place plc;
205 200
206 /** 201 /**
207 * Receipt handle. 202 * Slicer for processing incoming messages from guests.
208 */
209 struct GNUNET_PSYC_ReceiveHandle *recv;
210
211 /**
212 * Slicer for processing incoming methods.
213 */ 203 */
214 struct GNUNET_PSYC_Slicer *slicer; 204 struct GNUNET_PSYC_Slicer *slicer;
215 205
@@ -236,16 +226,6 @@ struct GNUNET_SOCIAL_Guest
236{ 226{
237 struct GNUNET_SOCIAL_Place plc; 227 struct GNUNET_SOCIAL_Place plc;
238 228
239 /**
240 * Receipt handle.
241 */
242 struct GNUNET_PSYC_ReceiveHandle *recv;
243
244 /**
245 * Slicer for processing incoming methods.
246 */
247 struct GNUNET_PSYC_Slicer *slicer;
248
249 GNUNET_SOCIAL_GuestEnterCallback enter_cb; 229 GNUNET_SOCIAL_GuestEnterCallback enter_cb;
250 230
251 GNUNET_SOCIAL_EntryDecisionCallback entry_dcsn_cb; 231 GNUNET_SOCIAL_EntryDecisionCallback entry_dcsn_cb;
@@ -298,9 +278,9 @@ struct GNUNET_SOCIAL_HistoryRequest
298 uint64_t op_id; 278 uint64_t op_id;
299 279
300 /** 280 /**
301 * Message handler. 281 * Slicer for processing incoming messages.
302 */ 282 */
303 struct GNUNET_PSYC_ReceiveHandle *recv; 283 struct GNUNET_PSYC_Slicer *slicer;
304 284
305 /** 285 /**
306 * Function to call when the operation finished. 286 * Function to call when the operation finished.
@@ -519,6 +499,7 @@ app_send_connect_msg (struct GNUNET_SOCIAL_App *app)
519 struct GNUNET_MessageHeader * cmsg = GNUNET_malloc (cmsg_size); 499 struct GNUNET_MessageHeader * cmsg = GNUNET_malloc (cmsg_size);
520 memcpy (cmsg, app->connect_msg, cmsg_size); 500 memcpy (cmsg, app->connect_msg, cmsg_size);
521 GNUNET_CLIENT_MANAGER_transmit_now (app->client, cmsg); 501 GNUNET_CLIENT_MANAGER_transmit_now (app->client, cmsg);
502 GNUNET_free (cmsg);
522} 503}
523 504
524 505
@@ -545,6 +526,7 @@ place_send_connect_msg (struct GNUNET_SOCIAL_Place *plc)
545 struct GNUNET_MessageHeader * cmsg = GNUNET_malloc (cmsg_size); 526 struct GNUNET_MessageHeader * cmsg = GNUNET_malloc (cmsg_size);
546 memcpy (cmsg, plc->connect_msg, cmsg_size); 527 memcpy (cmsg, plc->connect_msg, cmsg_size);
547 GNUNET_CLIENT_MANAGER_transmit_now (plc->client, cmsg); 528 GNUNET_CLIENT_MANAGER_transmit_now (plc->client, cmsg);
529 GNUNET_free (cmsg);
548} 530}
549 531
550 532
@@ -625,7 +607,6 @@ op_recv_history_result (void *cls, int64_t result,
625 if (NULL != hist->result_cb) 607 if (NULL != hist->result_cb)
626 hist->result_cb (hist->cls, result, err_msg, err_msg_size); 608 hist->result_cb (hist->cls, result, err_msg, err_msg_size);
627 609
628 GNUNET_PSYC_receive_destroy (hist->recv);
629 GNUNET_free (hist); 610 GNUNET_free (hist);
630} 611}
631 612
@@ -684,8 +665,8 @@ place_recv_history_result (void *cls,
684 return; 665 return;
685 } 666 }
686 667
687 GNUNET_PSYC_receive_message (hist->recv, 668 GNUNET_PSYC_slicer_message (hist->slicer,
688 (const struct GNUNET_PSYC_MessageHeader *) pmsg); 669 (const struct GNUNET_PSYC_MessageHeader *) pmsg);
689} 670}
690 671
691 672
@@ -781,7 +762,7 @@ place_recv_message (void *cls,
781{ 762{
782 struct GNUNET_SOCIAL_Place * 763 struct GNUNET_SOCIAL_Place *
783 plc = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*plc)); 764 plc = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (*plc));
784 GNUNET_PSYC_receive_message (plc->recv, 765 GNUNET_PSYC_slicer_message (plc->slicer,
785 (const struct GNUNET_PSYC_MessageHeader *) msg); 766 (const struct GNUNET_PSYC_MessageHeader *) msg);
786} 767}
787 768
@@ -793,10 +774,10 @@ host_recv_message (void *cls,
793{ 774{
794 struct GNUNET_SOCIAL_Host * 775 struct GNUNET_SOCIAL_Host *
795 hst = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (hst->plc)); 776 hst = GNUNET_CLIENT_MANAGER_get_user_context_ (client, sizeof (hst->plc));
796 GNUNET_PSYC_receive_message (hst->recv, 777 GNUNET_PSYC_slicer_message (hst->slicer,
797 (const struct GNUNET_PSYC_MessageHeader *) msg); 778 (const struct GNUNET_PSYC_MessageHeader *) msg);
798 GNUNET_PSYC_receive_message (hst->plc.recv, 779 GNUNET_PSYC_slicer_message (hst->plc.slicer,
799 (const struct GNUNET_PSYC_MessageHeader *) msg); 780 (const struct GNUNET_PSYC_MessageHeader *) msg);
800} 781}
801 782
802 783
@@ -855,7 +836,7 @@ host_recv_enter_request (void *cls,
855 &data, &data_size)) 836 &data, &data_size))
856 { 837 {
857 GNUNET_break_op (0); 838 GNUNET_break_op (0);
858 str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&req->slave_key); 839 str = GNUNET_CRYPTO_ecdsa_public_key_to_string (&req->slave_pub_key);
859 LOG (GNUNET_ERROR_TYPE_WARNING, 840 LOG (GNUNET_ERROR_TYPE_WARNING,
860 "Ignoring invalid entry request from nym %s.\n", 841 "Ignoring invalid entry request from nym %s.\n",
861 str); 842 str);
@@ -864,7 +845,7 @@ host_recv_enter_request (void *cls,
864 } 845 }
865 } 846 }
866 847
867 struct GNUNET_SOCIAL_Nym *nym = nym_get_or_create (&req->slave_key); 848 struct GNUNET_SOCIAL_Nym *nym = nym_get_or_create (&req->slave_pub_key);
868 hst->answer_door_cb (hst->cb_cls, nym, method_name, env, 849 hst->answer_door_cb (hst->cb_cls, nym, method_name, env,
869 data_size, data); 850 data_size, data);
870 } while (0); 851 } while (0);
@@ -1098,8 +1079,6 @@ place_cleanup (struct GNUNET_SOCIAL_Place *plc)
1098{ 1079{
1099 if (NULL != plc->tmit) 1080 if (NULL != plc->tmit)
1100 GNUNET_PSYC_transmit_destroy (plc->tmit); 1081 GNUNET_PSYC_transmit_destroy (plc->tmit);
1101 if (NULL != plc->recv)
1102 GNUNET_PSYC_receive_destroy (plc->recv);
1103 if (NULL != plc->connect_msg) 1082 if (NULL != plc->connect_msg)
1104 GNUNET_free (plc->connect_msg); 1083 GNUNET_free (plc->connect_msg);
1105 if (NULL != plc->disconnect_cb) 1084 if (NULL != plc->disconnect_cb)
@@ -1112,11 +1091,6 @@ host_cleanup (void *cls)
1112{ 1091{
1113 struct GNUNET_SOCIAL_Host *hst = cls; 1092 struct GNUNET_SOCIAL_Host *hst = cls;
1114 place_cleanup (&hst->plc); 1093 place_cleanup (&hst->plc);
1115 if (NULL != hst->recv)
1116 {
1117 GNUNET_PSYC_receive_destroy (hst->recv);
1118 hst->recv = NULL;
1119 }
1120 if (NULL != hst->slicer) 1094 if (NULL != hst->slicer)
1121 { 1095 {
1122 GNUNET_PSYC_slicer_destroy (hst->slicer); 1096 GNUNET_PSYC_slicer_destroy (hst->slicer);
@@ -1191,14 +1165,12 @@ GNUNET_SOCIAL_host_enter (const struct GNUNET_SOCIAL_App *app,
1191 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, hst, sizeof (*plc)); 1165 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, hst, sizeof (*plc));
1192 1166
1193 plc->tmit = GNUNET_PSYC_transmit_create (plc->client); 1167 plc->tmit = GNUNET_PSYC_transmit_create (plc->client);
1194 plc->recv = GNUNET_PSYC_receive_create (NULL, GNUNET_PSYC_slicer_message, plc->slicer);
1195 1168
1196 hst->slicer = GNUNET_PSYC_slicer_create (); 1169 hst->slicer = GNUNET_PSYC_slicer_create ();
1197 GNUNET_PSYC_slicer_method_add (hst->slicer, "_notice_place_leave", 1170 GNUNET_PSYC_slicer_method_add (hst->slicer, "_notice_place_leave",
1198 host_recv_notice_place_leave_method, 1171 host_recv_notice_place_leave_method,
1199 host_recv_notice_place_leave_modifier, 1172 host_recv_notice_place_leave_modifier,
1200 NULL, host_recv_notice_place_leave_eom, hst); 1173 NULL, host_recv_notice_place_leave_eom, hst);
1201 hst->recv = GNUNET_PSYC_receive_create (NULL, GNUNET_PSYC_slicer_message, hst->slicer);
1202 1174
1203 uint16_t app_id_size = strlen (app->id) + 1; 1175 uint16_t app_id_size = strlen (app->id) + 1;
1204 struct HostEnterRequest *hreq = GNUNET_malloc (sizeof (*hreq) + app_id_size); 1176 struct HostEnterRequest *hreq = GNUNET_malloc (sizeof (*hreq) + app_id_size);
@@ -1263,14 +1235,12 @@ GNUNET_SOCIAL_host_enter_reconnect (struct GNUNET_SOCIAL_HostConnection *hconn,
1263 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, hst, sizeof (*plc)); 1235 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, hst, sizeof (*plc));
1264 1236
1265 plc->tmit = GNUNET_PSYC_transmit_create (plc->client); 1237 plc->tmit = GNUNET_PSYC_transmit_create (plc->client);
1266 plc->recv = GNUNET_PSYC_receive_create (NULL, GNUNET_PSYC_slicer_message, plc->slicer);
1267 1238
1268 hst->slicer = GNUNET_PSYC_slicer_create (); 1239 hst->slicer = GNUNET_PSYC_slicer_create ();
1269 GNUNET_PSYC_slicer_method_add (hst->slicer, "_notice_place_leave", 1240 GNUNET_PSYC_slicer_method_add (hst->slicer, "_notice_place_leave",
1270 host_recv_notice_place_leave_method, 1241 host_recv_notice_place_leave_method,
1271 host_recv_notice_place_leave_modifier, 1242 host_recv_notice_place_leave_modifier,
1272 NULL, host_recv_notice_place_leave_eom, hst); 1243 NULL, host_recv_notice_place_leave_eom, hst);
1273 hst->recv = GNUNET_PSYC_receive_create (NULL, GNUNET_PSYC_slicer_message, hst->slicer);
1274 1244
1275 hreq->header.size = htons (sizeof (*hreq) + app_id_size); 1245 hreq->header.size = htons (sizeof (*hreq) + app_id_size);
1276 hreq->header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER); 1246 hreq->header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_HOST_ENTER);
@@ -1325,12 +1295,13 @@ GNUNET_SOCIAL_host_entry_decision (struct GNUNET_SOCIAL_Host *hst,
1325 dcsn->header.size = htons (sizeof (*dcsn) + entry_resp_size); 1295 dcsn->header.size = htons (sizeof (*dcsn) + entry_resp_size);
1326 dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION); 1296 dcsn->header.type = htons (GNUNET_MESSAGE_TYPE_PSYC_JOIN_DECISION);
1327 dcsn->is_admitted = htonl (is_admitted); 1297 dcsn->is_admitted = htonl (is_admitted);
1328 dcsn->slave_key = nym->pub_key; 1298 dcsn->slave_pub_key = nym->pub_key;
1329 1299
1330 if (0 < entry_resp_size) 1300 if (0 < entry_resp_size)
1331 memcpy (&dcsn[1], entry_resp, entry_resp_size); 1301 memcpy (&dcsn[1], entry_resp, entry_resp_size);
1332 1302
1333 GNUNET_CLIENT_MANAGER_transmit (hst->plc.client, &dcsn->header); 1303 GNUNET_CLIENT_MANAGER_transmit (hst->plc.client, &dcsn->header);
1304 GNUNET_free (dcsn);
1334 return GNUNET_OK; 1305 return GNUNET_OK;
1335} 1306}
1336 1307
@@ -1690,7 +1661,6 @@ GNUNET_SOCIAL_guest_enter (const struct GNUNET_SOCIAL_App *app,
1690 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, gst, sizeof (*plc)); 1661 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, gst, sizeof (*plc));
1691 1662
1692 plc->tmit = GNUNET_PSYC_transmit_create (plc->client); 1663 plc->tmit = GNUNET_PSYC_transmit_create (plc->client);
1693 plc->recv = GNUNET_PSYC_receive_create (NULL, GNUNET_PSYC_slicer_message, plc->slicer);
1694 1664
1695 struct GuestEnterRequest * 1665 struct GuestEnterRequest *
1696 greq = guest_enter_request_create (app->id, &ego->pub_key, &plc->pub_key, 1666 greq = guest_enter_request_create (app->id, &ego->pub_key, &plc->pub_key,
@@ -1782,7 +1752,6 @@ GNUNET_SOCIAL_guest_enter_by_name (const struct GNUNET_SOCIAL_App *app,
1782 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, gst, sizeof (*plc)); 1752 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, gst, sizeof (*plc));
1783 1753
1784 plc->tmit = GNUNET_PSYC_transmit_create (plc->client); 1754 plc->tmit = GNUNET_PSYC_transmit_create (plc->client);
1785 plc->recv = GNUNET_PSYC_receive_create (NULL, GNUNET_PSYC_slicer_message, plc->slicer);
1786 1755
1787 plc->connect_msg = &greq->header; 1756 plc->connect_msg = &greq->header;
1788 place_send_connect_msg (plc); 1757 place_send_connect_msg (plc);
@@ -1842,7 +1811,6 @@ GNUNET_SOCIAL_guest_enter_reconnect (struct GNUNET_SOCIAL_GuestConnection *gconn
1842 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, gst, sizeof (*plc)); 1811 GNUNET_CLIENT_MANAGER_set_user_context_ (plc->client, gst, sizeof (*plc));
1843 1812
1844 plc->tmit = GNUNET_PSYC_transmit_create (plc->client); 1813 plc->tmit = GNUNET_PSYC_transmit_create (plc->client);
1845 plc->recv = GNUNET_PSYC_receive_create (NULL, GNUNET_PSYC_slicer_message, plc->slicer);
1846 1814
1847 plc->connect_msg = &greq->header; 1815 plc->connect_msg = &greq->header;
1848 place_send_connect_msg (plc); 1816 place_send_connect_msg (plc);
@@ -1994,6 +1962,52 @@ GNUNET_SOCIAL_place_get_key (struct GNUNET_SOCIAL_Place *plc)
1994} 1962}
1995 1963
1996 1964
1965/**
1966 * Set message processing @a flags for a @a method_prefix.
1967 *
1968 * @param plc
1969 * Place.
1970 * @param method_prefix
1971 * Method prefix @a flags apply to.
1972 * @param flags
1973 * The flags that apply to a matching @a method_prefix.
1974 */
1975void
1976GNUNET_SOCIAL_place_msg_proc_set (struct GNUNET_SOCIAL_Place *plc,
1977 const char *method_prefix,
1978 enum GNUNET_SOCIAL_MsgProcFlags flags)
1979{
1980 GNUNET_assert (NULL != method_prefix);
1981 struct MsgProcRequest *mpreq;
1982 uint16_t method_size = strnlen (method_prefix,
1983 GNUNET_SERVER_MAX_MESSAGE_SIZE
1984 - sizeof (*mpreq)) + 1;
1985 GNUNET_assert ('\0' == method_prefix[method_size - 1]);
1986 mpreq = GNUNET_malloc (sizeof (*mpreq) + method_size);
1987
1988 mpreq->header.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_SET);
1989 mpreq->header.size = htons (sizeof (*mpreq) + method_size);
1990 mpreq->flags = htonl (flags);
1991 memcpy (&mpreq[1], method_prefix, method_size);
1992
1993 GNUNET_CLIENT_MANAGER_transmit (plc->client, &mpreq->header);
1994 GNUNET_free (mpreq);
1995}
1996
1997
1998/**
1999 * Clear all message processing flags previously set for this place.
2000 */
2001void
2002GNUNET_SOCIAL_place_msg_proc_clear (struct GNUNET_SOCIAL_Place *plc)
2003{
2004 struct GNUNET_MessageHeader req;
2005 req.type = htons (GNUNET_MESSAGE_TYPE_SOCIAL_MSG_PROC_CLEAR);
2006 req.size = htons (sizeof (req));
2007 GNUNET_CLIENT_MANAGER_transmit (plc->client, &req);
2008}
2009
2010
1997static struct GNUNET_SOCIAL_HistoryRequest * 2011static struct GNUNET_SOCIAL_HistoryRequest *
1998place_history_replay (struct GNUNET_SOCIAL_Place *plc, 2012place_history_replay (struct GNUNET_SOCIAL_Place *plc,
1999 uint64_t start_message_id, 2013 uint64_t start_message_id,
@@ -2008,7 +2022,7 @@ place_history_replay (struct GNUNET_SOCIAL_Place *plc,
2008 struct GNUNET_PSYC_HistoryRequestMessage *req; 2022 struct GNUNET_PSYC_HistoryRequestMessage *req;
2009 struct GNUNET_SOCIAL_HistoryRequest *hist = GNUNET_malloc (sizeof (*hist)); 2023 struct GNUNET_SOCIAL_HistoryRequest *hist = GNUNET_malloc (sizeof (*hist));
2010 hist->plc = plc; 2024 hist->plc = plc;
2011 hist->recv = GNUNET_PSYC_receive_create (NULL, GNUNET_PSYC_slicer_message, slicer); 2025 hist->slicer = slicer;
2012 hist->result_cb = result_cb; 2026 hist->result_cb = result_cb;
2013 hist->cls = cls; 2027 hist->cls = cls;
2014 hist->op_id = GNUNET_CLIENT_MANAGER_op_add (plc->client, 2028 hist->op_id = GNUNET_CLIENT_MANAGER_op_add (plc->client,
@@ -2030,6 +2044,7 @@ place_history_replay (struct GNUNET_SOCIAL_Place *plc,
2030 memcpy (&req[1], method_prefix, method_size); 2044 memcpy (&req[1], method_prefix, method_size);
2031 2045
2032 GNUNET_CLIENT_MANAGER_transmit (plc->client, &req->header); 2046 GNUNET_CLIENT_MANAGER_transmit (plc->client, &req->header);
2047 GNUNET_free (req);
2033 return hist; 2048 return hist;
2034} 2049}
2035 2050
@@ -2118,7 +2133,6 @@ GNUNET_SOCIAL_place_history_replay_latest (struct GNUNET_SOCIAL_Place *plc,
2118void 2133void
2119GNUNET_SOCIAL_place_history_replay_cancel (struct GNUNET_SOCIAL_HistoryRequest *hist) 2134GNUNET_SOCIAL_place_history_replay_cancel (struct GNUNET_SOCIAL_HistoryRequest *hist)
2120{ 2135{
2121 GNUNET_PSYC_receive_destroy (hist->recv);
2122 GNUNET_CLIENT_MANAGER_op_cancel (hist->plc->client, hist->op_id); 2136 GNUNET_CLIENT_MANAGER_op_cancel (hist->plc->client, hist->op_id);
2123 GNUNET_free (hist); 2137 GNUNET_free (hist);
2124} 2138}
@@ -2152,6 +2166,7 @@ place_state_get (struct GNUNET_SOCIAL_Place *plc,
2152 memcpy (&req[1], name, name_size); 2166 memcpy (&req[1], name, name_size);
2153 2167
2154 GNUNET_CLIENT_MANAGER_transmit (plc->client, &req->header); 2168 GNUNET_CLIENT_MANAGER_transmit (plc->client, &req->header);
2169 GNUNET_free (req);
2155 return look; 2170 return look;
2156} 2171}
2157 2172
@@ -2314,6 +2329,7 @@ GNUNET_SOCIAL_zone_add_place (const struct GNUNET_SOCIAL_App *app,
2314 op_recv_zone_add_place_result, 2329 op_recv_zone_add_place_result,
2315 add_plc)); 2330 add_plc));
2316 GNUNET_CLIENT_MANAGER_transmit_now (app->client, &preq->header); 2331 GNUNET_CLIENT_MANAGER_transmit_now (app->client, &preq->header);
2332 GNUNET_free (preq);
2317 return GNUNET_OK; 2333 return GNUNET_OK;
2318} 2334}
2319 2335