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.c132
1 files changed, 96 insertions, 36 deletions
diff --git a/src/social/social_api.c b/src/social/social_api.c
index 923ab5e33..fc649fcde 100644
--- a/src/social/social_api.c
+++ b/src/social/social_api.c
@@ -1079,43 +1079,18 @@ place_cleanup (struct GNUNET_SOCIAL_Place *plc)
1079} 1079}
1080 1080
1081 1081
1082void 1082static void
1083place_disconnect (struct GNUNET_SOCIAL_Place *plc) 1083place_disconnect (struct GNUNET_SOCIAL_Place *plc)
1084{ 1084{
1085 struct GNUNET_HashCode place_pub_hash; 1085 struct GNUNET_HashCode place_pub_hash;
1086 GNUNET_CRYPTO_hash (&plc->pub_key, sizeof (plc->pub_key), &place_pub_hash); 1086
1087 GNUNET_CRYPTO_hash (&plc->pub_key,
1088 sizeof (plc->pub_key),
1089 &place_pub_hash);
1087 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1090 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1088 "place_disconnect, plc = %s\n", 1091 "place_disconnect, plc = %s\n",
1089 GNUNET_h2s (&place_pub_hash)); 1092 GNUNET_h2s (&place_pub_hash));
1090 if (NULL != plc->mq) 1093 place_cleanup (plc);
1091 {
1092 struct GNUNET_MQ_Envelope *env = GNUNET_MQ_get_last_envelope (plc->mq);
1093 if (NULL != env)
1094 {
1095 GNUNET_MQ_notify_sent (env, (GNUNET_SCHEDULER_TaskCallback) place_cleanup, plc);
1096 }
1097 else
1098 {
1099 place_cleanup (plc);
1100 }
1101 }
1102 else
1103 {
1104 place_cleanup (plc);
1105 }
1106}
1107
1108
1109void
1110place_leave (struct GNUNET_SOCIAL_Place *plc)
1111{
1112 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1113 "social_api: place_leave\n");
1114 struct GNUNET_MessageHeader *msg;
1115 struct GNUNET_MQ_Envelope *
1116 env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
1117
1118 GNUNET_MQ_send (plc->mq, env);
1119} 1094}
1120 1095
1121 1096
@@ -1589,7 +1564,7 @@ GNUNET_SOCIAL_host_disconnect (struct GNUNET_SOCIAL_Host *hst,
1589 GNUNET_ContinuationCallback disconnect_cb, 1564 GNUNET_ContinuationCallback disconnect_cb,
1590 void *cls) 1565 void *cls)
1591{ 1566{
1592 struct GNUNET_SOCIAL_Place *plc = &hst->plc; 1567 struct GNUNET_SOCIAL_Place *plc = &hst->plc;
1593 1568
1594 plc->disconnect_cb = disconnect_cb; 1569 plc->disconnect_cb = disconnect_cb;
1595 plc->disconnect_cls = cls; 1570 plc->disconnect_cls = cls;
@@ -1598,6 +1573,32 @@ GNUNET_SOCIAL_host_disconnect (struct GNUNET_SOCIAL_Host *hst,
1598 1573
1599 1574
1600/** 1575/**
1576 * Closure for #host_leave_cont.
1577 */
1578struct HostLeaveContext
1579{
1580 struct GNUNET_SOCIAL_Host *hst;
1581 GNUNET_ContinuationCallback disconnect_cb;
1582 void *disconnect_cb_cls;
1583};
1584
1585
1586/**
1587 * FIXME.
1588 */
1589static void
1590host_leave_cont (void *cls)
1591{
1592 struct HostLeaveContext *hlc = cls;
1593
1594 GNUNET_SOCIAL_host_disconnect (hlc->hst,
1595 hlc->disconnect_cb,
1596 hlc->disconnect_cb_cls);
1597 GNUNET_free (hlc);
1598}
1599
1600
1601/**
1601 * Stop hosting the home. 1602 * Stop hosting the home.
1602 * 1603 *
1603 * Sends a _notice_place_closing announcement to the home. 1604 * Sends a _notice_place_closing announcement to the home.
@@ -1620,12 +1621,25 @@ GNUNET_SOCIAL_host_leave (struct GNUNET_SOCIAL_Host *hst,
1620 GNUNET_ContinuationCallback disconnect_cb, 1621 GNUNET_ContinuationCallback disconnect_cb,
1621 void *cls) 1622 void *cls)
1622{ 1623{
1624 struct GNUNET_MessageHeader *msg;
1625 struct GNUNET_MQ_Envelope *envelope;
1626 struct HostLeaveContext *hlc;
1627
1623 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1628 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1624 "GNUNET_SOCIAL_host_leave\n"); 1629 "GNUNET_SOCIAL_host_leave\n");
1625 GNUNET_SOCIAL_host_announce (hst, "_notice_place_closing", env, NULL, NULL, 1630 GNUNET_SOCIAL_host_announce (hst, "_notice_place_closing", env, NULL, NULL,
1626 GNUNET_SOCIAL_ANNOUNCE_NONE); 1631 GNUNET_SOCIAL_ANNOUNCE_NONE);
1627 place_leave (&hst->plc); 1632 envelope = GNUNET_MQ_msg (msg,
1628 GNUNET_SOCIAL_host_disconnect (hst, disconnect_cb, cls); 1633 GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
1634 hlc = GNUNET_new (struct HostLeaveContext);
1635 hlc->hst = hst;
1636 hlc->disconnect_cb = disconnect_cb;
1637 hlc->disconnect_cb_cls = cls;
1638 GNUNET_MQ_notify_sent (envelope,
1639 &host_leave_cont,
1640 hlc);
1641 GNUNET_MQ_send (hst->plc.mq,
1642 envelope);
1629} 1643}
1630 1644
1631 1645
@@ -2057,6 +2071,35 @@ GNUNET_SOCIAL_guest_disconnect (struct GNUNET_SOCIAL_Guest *gst,
2057 2071
2058 2072
2059/** 2073/**
2074 * Closure for #leave_done_cont.
2075 */
2076struct LeaveContext
2077{
2078 struct GNUNET_SOCIAL_Guest *gst;
2079 GNUNET_ContinuationCallback disconnect_cb;
2080 void *disconnect_cb_cls;
2081};
2082
2083
2084/**
2085 * The leave message was transmitted, now complete the
2086 * disconnection process.
2087 *
2088 * @param cls a `struct LeaveContext`
2089 */
2090static void
2091leave_done_cont (void *cls)
2092{
2093 struct LeaveContext *lc = cls;
2094
2095 GNUNET_SOCIAL_guest_disconnect (lc->gst,
2096 lc->disconnect_cb,
2097 lc->disconnect_cb_cls);
2098 GNUNET_free (lc);
2099}
2100
2101
2102/**
2060 * Leave a place temporarily or permanently. 2103 * Leave a place temporarily or permanently.
2061 * 2104 *
2062 * Notifies the owner of the place about leaving, and destroys the place handle. 2105 * Notifies the owner of the place about leaving, and destroys the place handle.
@@ -2078,10 +2121,27 @@ GNUNET_SOCIAL_guest_leave (struct GNUNET_SOCIAL_Guest *gst,
2078 GNUNET_ContinuationCallback disconnect_cb, 2121 GNUNET_ContinuationCallback disconnect_cb,
2079 void *cls) 2122 void *cls)
2080{ 2123{
2124 struct GNUNET_MessageHeader *msg;
2125 struct GNUNET_MQ_Envelope *envelope;
2126 struct LeaveContext *lc;
2127
2081 GNUNET_SOCIAL_guest_talk (gst, "_notice_place_leave", env, NULL, NULL, 2128 GNUNET_SOCIAL_guest_talk (gst, "_notice_place_leave", env, NULL, NULL,
2082 GNUNET_SOCIAL_TALK_NONE); 2129 GNUNET_SOCIAL_TALK_NONE);
2083 place_leave (&gst->plc); 2130
2084 GNUNET_SOCIAL_guest_disconnect (gst, disconnect_cb, cls); 2131
2132 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2133 "social_api: place_leave\n");
2134 envelope = GNUNET_MQ_msg (msg,
2135 GNUNET_MESSAGE_TYPE_SOCIAL_PLACE_LEAVE);
2136 lc = GNUNET_new (struct LeaveContext);
2137 lc->gst = gst;
2138 lc->disconnect_cb = disconnect_cb;
2139 lc->disconnect_cb_cls = cls;
2140 GNUNET_MQ_notify_sent (envelope,
2141 &leave_done_cont,
2142 lc);
2143 GNUNET_MQ_send (gst->plc.mq,
2144 envelope);
2085} 2145}
2086 2146
2087 2147