aboutsummaryrefslogtreecommitdiff
path: root/src/core/core_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-05 13:33:59 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-05 13:33:59 +0000
commit1e620c9a829531da18fa309af050c26fddd34f1f (patch)
treec6c97df2551062ee236bfd5ec35df74f1106b0dd /src/core/core_api.c
parent0f29195adbd56ae10dea70c2951333c13e765f88 (diff)
downloadgnunet-1e620c9a829531da18fa309af050c26fddd34f1f.tar.gz
gnunet-1e620c9a829531da18fa309af050c26fddd34f1f.zip
eliminate last calls to GNUNET_CORE_peer_request_connect
Diffstat (limited to 'src/core/core_api.c')
-rw-r--r--src/core/core_api.c150
1 files changed, 13 insertions, 137 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c
index cdb050e8e..3624a6e7f 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -121,6 +121,19 @@ struct PeerRecord
121 121
122 122
123/** 123/**
124 * Type of function called upon completion.
125 *
126 * @param cls closure
127 * @param success GNUNET_OK on success (which for request_connect
128 * ONLY means that we transmitted the connect request to CORE,
129 * it does not mean that we are actually now connected!);
130 * GNUNET_NO on timeout,
131 * GNUNET_SYSERR if core was shut down
132 */
133typedef void (*GNUNET_CORE_ControlContinuation) (void *cls, int success);
134
135
136/**
124 * Entry in a doubly-linked list of control messages to be transmitted 137 * Entry in a doubly-linked list of control messages to be transmitted
125 * to the core service. Control messages include traffic allocation, 138 * to the core service. Control messages include traffic allocation,
126 * connection requests and of course our initial 'init' request. 139 * connection requests and of course our initial 'init' request.
@@ -1623,143 +1636,6 @@ GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle *th)
1623} 1636}
1624 1637
1625 1638
1626/* ****************** GNUNET_CORE_peer_request_connect ******************** */
1627
1628/**
1629 * Handle for a request to the core to connect to
1630 * a particular peer. Can be used to cancel the request
1631 * (before the 'cont'inuation is called).
1632 */
1633struct GNUNET_CORE_PeerRequestHandle
1634{
1635
1636 /**
1637 * Link to control message.
1638 */
1639 struct ControlMessage *cm;
1640
1641 /**
1642 * Core handle used.
1643 */
1644 struct GNUNET_CORE_Handle *h;
1645
1646 /**
1647 * Continuation to run when done.
1648 */
1649 GNUNET_CORE_ControlContinuation cont;
1650
1651 /**
1652 * Closure for 'cont'.
1653 */
1654 void *cont_cls;
1655
1656};
1657
1658
1659/**
1660 * Continuation called when the control message was transmitted.
1661 * Calls the original continuation and frees the remaining
1662 * resources.
1663 *
1664 * @param cls the 'struct GNUNET_CORE_PeerRequestHandle'
1665 * @param success was the request transmitted?
1666 */
1667static void
1668peer_request_connect_cont (void *cls, int success)
1669{
1670 struct GNUNET_CORE_PeerRequestHandle *ret = cls;
1671
1672 if (ret->cont != NULL)
1673 ret->cont (ret->cont_cls, success);
1674 GNUNET_free (ret);
1675}
1676
1677
1678/**
1679 * Request that the core should try to connect to a particular peer.
1680 * Once the request has been transmitted to the core, the continuation
1681 * function will be called. Note that this does NOT mean that a
1682 * connection was successfully established -- it only means that the
1683 * core will now try. Successful establishment of the connection
1684 * will be signalled to the 'connects' callback argument of
1685 * 'GNUNET_CORE_connect' only. If the core service does not respond
1686 * to our connection attempt within the given time frame, 'cont' will
1687 * be called with the TIMEOUT reason code.
1688 *
1689 * @param h core handle
1690 * @param peer who should we connect to
1691 * @param cont function to call once the request has been completed (or timed out)
1692 * @param cont_cls closure for cont
1693 *
1694 * @return NULL on error or already connected,
1695 * otherwise handle for cancellation
1696 */
1697struct GNUNET_CORE_PeerRequestHandle *
1698GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h,
1699 const struct GNUNET_PeerIdentity *peer,
1700 GNUNET_CORE_ControlContinuation cont,
1701 void *cont_cls)
1702{
1703 struct GNUNET_CORE_PeerRequestHandle *ret;
1704 struct ControlMessage *cm;
1705 struct ConnectMessage *msg;
1706
1707 if (NULL != GNUNET_CONTAINER_multihashmap_get (h->peers, &peer->hashPubKey))
1708 {
1709#if DEBUG_CORE
1710 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peers are already connected!\n");
1711#endif
1712 return NULL;
1713 }
1714
1715 cm = GNUNET_malloc (sizeof (struct ControlMessage) +
1716 sizeof (struct ConnectMessage));
1717 msg = (struct ConnectMessage *) &cm[1];
1718 msg->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_CONNECT);
1719 msg->header.size = htons (sizeof (struct ConnectMessage));
1720 msg->reserved = htonl (0);
1721 msg->peer = *peer;
1722 GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
1723 h->control_pending_tail, cm);
1724 ret = GNUNET_malloc (sizeof (struct GNUNET_CORE_PeerRequestHandle));
1725 ret->h = h;
1726 ret->cm = cm;
1727 ret->cont = cont;
1728 ret->cont_cls = cont_cls;
1729 cm->cont = &peer_request_connect_cont;
1730 cm->cont_cls = ret;
1731#if DEBUG_CORE
1732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Queueing REQUEST_CONNECT request\n");
1733#endif
1734 trigger_next_request (h, GNUNET_NO);
1735 return ret;
1736}
1737
1738
1739/**
1740 * Cancel a pending request to connect to a particular peer. Must not
1741 * be called after the 'cont' function was invoked.
1742 *
1743 * @param req request handle that was returned for the original request
1744 */
1745void
1746GNUNET_CORE_peer_request_connect_cancel (struct GNUNET_CORE_PeerRequestHandle
1747 *req)
1748{
1749 struct GNUNET_CORE_Handle *h = req->h;
1750 struct ControlMessage *cm = req->cm;
1751
1752#if DEBUG_CORE
1753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1754 "A CHANGE PREFERENCE request was cancelled!\n");
1755#endif
1756 GNUNET_CONTAINER_DLL_remove (h->control_pending_head, h->control_pending_tail,
1757 cm);
1758 GNUNET_free (cm);
1759 GNUNET_free (req);
1760}
1761
1762
1763/* ****************** GNUNET_CORE_peer_change_preference ******************** */ 1639/* ****************** GNUNET_CORE_peer_change_preference ******************** */
1764 1640
1765 1641