aboutsummaryrefslogtreecommitdiff
path: root/src/core/core_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-10-10 11:09:42 +0000
committerChristian Grothoff <christian@grothoff.org>2011-10-10 11:09:42 +0000
commit376b5f749c03e1ff149c2e8248eed9bec928872a (patch)
tree7c44864219de6d7d77bdaec34c9e4b7aaf199647 /src/core/core_api.c
parent9767d2478ccb8dcc3152cb617d84cd4cec2097c3 (diff)
downloadgnunet-376b5f749c03e1ff149c2e8248eed9bec928872a.tar.gz
gnunet-376b5f749c03e1ff149c2e8248eed9bec928872a.zip
dead code elimination
Diffstat (limited to 'src/core/core_api.c')
-rw-r--r--src/core/core_api.c225
1 files changed, 0 insertions, 225 deletions
diff --git a/src/core/core_api.c b/src/core/core_api.c
index c740f593c..16668e9fc 100644
--- a/src/core/core_api.c
+++ b/src/core/core_api.c
@@ -73,30 +73,6 @@ struct PeerRecord
73 struct GNUNET_CORE_TransmitHandle *pending_tail; 73 struct GNUNET_CORE_TransmitHandle *pending_tail;
74 74
75 /** 75 /**
76 * Pending callback waiting for peer information, or NULL for none.
77 */
78 GNUNET_CORE_PeerConfigurationInfoCallback pcic;
79
80 /**
81 * Closure for pcic.
82 */
83 void *pcic_cls;
84
85 /**
86 * Pointer to free when we call pcic and to use to cancel
87 * preference change on disconnect.
88 */
89 struct GNUNET_CORE_InformationRequestContext *pcic_ptr;
90
91 /**
92 * Request information ID for the given pcic (needed in case a
93 * request is cancelled after being submitted to core and a new
94 * one is generated; in this case, we need to avoid matching the
95 * reply to the first (cancelled) request to the second request).
96 */
97 uint32_t rim_id;
98
99 /**
100 * ID of timeout task for the 'pending_head' handle 76 * ID of timeout task for the 'pending_head' handle
101 * which is the one with the smallest timeout. 77 * which is the one with the smallest timeout.
102 */ 78 */
@@ -275,11 +251,6 @@ struct GNUNET_CORE_Handle
275 struct GNUNET_TIME_Relative retry_backoff; 251 struct GNUNET_TIME_Relative retry_backoff;
276 252
277 /** 253 /**
278 * Request information ID generator.
279 */
280 uint32_t rim_id_gen;
281
282 /**
283 * Number of messages we are allowed to queue per target. 254 * Number of messages we are allowed to queue per target.
284 */ 255 */
285 unsigned int queue_size; 256 unsigned int queue_size;
@@ -424,8 +395,6 @@ disconnect_and_free_peer_entry (void *cls, const GNUNET_HashCode * key,
424 struct GNUNET_CORE_Handle *h = cls; 395 struct GNUNET_CORE_Handle *h = cls;
425 struct GNUNET_CORE_TransmitHandle *th; 396 struct GNUNET_CORE_TransmitHandle *th;
426 struct PeerRecord *pr = value; 397 struct PeerRecord *pr = value;
427 GNUNET_CORE_PeerConfigurationInfoCallback pcic;
428 void *pcic_cls;
429 398
430 if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK) 399 if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
431 { 400 {
@@ -443,13 +412,6 @@ disconnect_and_free_peer_entry (void *cls, const GNUNET_HashCode * key,
443 h->disconnects (h->cls, &pr->peer); 412 h->disconnects (h->cls, &pr->peer);
444 /* all requests should have been cancelled, clean up anyway, just in case */ 413 /* all requests should have been cancelled, clean up anyway, just in case */
445 GNUNET_break (pr->queue_size == 0); 414 GNUNET_break (pr->queue_size == 0);
446 if (NULL != (pcic = pr->pcic))
447 {
448 GNUNET_break (0);
449 pcic_cls = pr->pcic_cls;
450 GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr);
451 pcic (pcic_cls, &pr->peer, 0, GNUNET_TIME_UNIT_FOREVER_REL);
452 }
453 while (NULL != (th = pr->pending_head)) 415 while (NULL != (th = pr->pending_head))
454 { 416 {
455 GNUNET_break (0); 417 GNUNET_break (0);
@@ -823,12 +785,10 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
823 const struct DisconnectNotifyMessage *dnm; 785 const struct DisconnectNotifyMessage *dnm;
824 const struct NotifyTrafficMessage *ntm; 786 const struct NotifyTrafficMessage *ntm;
825 const struct GNUNET_MessageHeader *em; 787 const struct GNUNET_MessageHeader *em;
826 const struct ConfigurationInfoMessage *cim;
827 const struct PeerStatusNotifyMessage *psnm; 788 const struct PeerStatusNotifyMessage *psnm;
828 const struct SendMessageReady *smr; 789 const struct SendMessageReady *smr;
829 const struct GNUNET_CORE_MessageHandler *mh; 790 const struct GNUNET_CORE_MessageHandler *mh;
830 GNUNET_CORE_StartupCallback init; 791 GNUNET_CORE_StartupCallback init;
831 GNUNET_CORE_PeerConfigurationInfoCallback pcic;
832 struct PeerRecord *pr; 792 struct PeerRecord *pr;
833 struct GNUNET_CORE_TransmitHandle *th; 793 struct GNUNET_CORE_TransmitHandle *th;
834 unsigned int hpos; 794 unsigned int hpos;
@@ -1190,48 +1150,6 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
1190 GNUNET_CONTAINER_DLL_insert (h->ready_peer_head, h->ready_peer_tail, pr); 1150 GNUNET_CONTAINER_DLL_insert (h->ready_peer_head, h->ready_peer_tail, pr);
1191 trigger_next_request (h, GNUNET_NO); 1151 trigger_next_request (h, GNUNET_NO);
1192 break; 1152 break;
1193 case GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO:
1194 if (ntohs (msg->size) != sizeof (struct ConfigurationInfoMessage))
1195 {
1196 GNUNET_break (0);
1197 reconnect_later (h);
1198 return;
1199 }
1200 cim = (const struct ConfigurationInfoMessage *) msg;
1201 if (0 == memcmp (&h->me, &cim->peer, sizeof (struct GNUNET_PeerIdentity)))
1202 {
1203 /* self-change!? */
1204 GNUNET_break (0);
1205 return;
1206 }
1207#if DEBUG_CORE
1208 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1209 "Received notification about configuration update for `%s' with RIM %u.\n",
1210 GNUNET_i2s (&cim->peer), (unsigned int) ntohl (cim->rim_id));
1211#endif
1212 pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &cim->peer.hashPubKey);
1213 if (pr == NULL)
1214 {
1215 GNUNET_break (0);
1216 reconnect_later (h);
1217 return;
1218 }
1219 if (pr->rim_id != ntohl (cim->rim_id))
1220 {
1221#if DEBUG_CORE
1222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1223 "Reservation ID mismatch in notification...\n");
1224#endif
1225 break;
1226 }
1227 pcic = pr->pcic;
1228 pr->pcic = NULL;
1229 GNUNET_free_non_null (pr->pcic_ptr);
1230 pr->pcic_ptr = NULL;
1231 if (pcic != NULL)
1232 pcic (pr->pcic_cls, &pr->peer, ntohl (cim->reserved_amount),
1233 GNUNET_TIME_relative_ntoh (cim->reserve_delay));
1234 break;
1235 default: 1153 default:
1236 reconnect_later (h); 1154 reconnect_later (h);
1237 return; 1155 return;
@@ -1632,147 +1550,4 @@ GNUNET_CORE_notify_transmit_ready_cancel (struct GNUNET_CORE_TransmitHandle *th)
1632} 1550}
1633 1551
1634 1552
1635/* ****************** GNUNET_CORE_peer_change_preference ******************** */
1636
1637
1638struct GNUNET_CORE_InformationRequestContext
1639{
1640
1641 /**
1642 * Our connection to the service.
1643 */
1644 struct GNUNET_CORE_Handle *h;
1645
1646 /**
1647 * Link to control message, NULL if CM was sent.
1648 */
1649 struct ControlMessage *cm;
1650
1651 /**
1652 * Link to peer record.
1653 */
1654 struct PeerRecord *pr;
1655};
1656
1657
1658/**
1659 * CM was sent, remove link so we don't double-free.
1660 *
1661 * @param cls the 'struct GNUNET_CORE_InformationRequestContext'
1662 * @param success were we successful?
1663 */
1664static void
1665change_preference_send_continuation (void *cls, int success)
1666{
1667 struct GNUNET_CORE_InformationRequestContext *irc = cls;
1668
1669 irc->cm = NULL;
1670}
1671
1672
1673/**
1674 * Obtain statistics and/or change preferences for the given peer.
1675 *
1676 * @param h core handle
1677 * @param peer identifies the peer
1678 * @param amount reserve N bytes for receiving, negative
1679 * amounts can be used to undo a (recent) reservation;
1680 * @param preference increase incoming traffic share preference by this amount;
1681 * in the absence of "amount" reservations, we use this
1682 * preference value to assign proportional bandwidth shares
1683 * to all connected peers
1684 * @param info function to call with the resulting configuration information
1685 * @param info_cls closure for info
1686 * @return NULL on error
1687 */
1688struct GNUNET_CORE_InformationRequestContext *
1689GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
1690 const struct GNUNET_PeerIdentity *peer,
1691 int32_t amount, uint64_t preference,
1692 GNUNET_CORE_PeerConfigurationInfoCallback
1693 info, void *info_cls)
1694{
1695 struct GNUNET_CORE_InformationRequestContext *irc;
1696 struct PeerRecord *pr;
1697 struct RequestInfoMessage *rim;
1698 struct ControlMessage *cm;
1699
1700 pr = GNUNET_CONTAINER_multihashmap_get (h->peers, &peer->hashPubKey);
1701 if (NULL == pr)
1702 {
1703 /* attempt to change preference on peer that is not connected */
1704 GNUNET_assert (0);
1705 return NULL;
1706 }
1707 if (pr->pcic != NULL)
1708 {
1709 /* second change before first one is done */
1710 GNUNET_break (0);
1711 return NULL;
1712 }
1713 irc = GNUNET_malloc (sizeof (struct GNUNET_CORE_InformationRequestContext));
1714 irc->h = h;
1715 irc->pr = pr;
1716 cm = GNUNET_malloc (sizeof (struct ControlMessage) +
1717 sizeof (struct RequestInfoMessage));
1718 cm->cont = &change_preference_send_continuation;
1719 cm->cont_cls = irc;
1720 irc->cm = cm;
1721 rim = (struct RequestInfoMessage *) &cm[1];
1722 rim->header.size = htons (sizeof (struct RequestInfoMessage));
1723 rim->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO);
1724 rim->rim_id = htonl (pr->rim_id = h->rim_id_gen++);
1725 rim->reserved = htonl (0);
1726 rim->reserve_inbound = htonl (amount);
1727 rim->preference_change = GNUNET_htonll (preference);
1728 rim->peer = *peer;
1729#if DEBUG_CORE
1730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1731 "Queueing CHANGE PREFERENCE request for peer `%s' with RIM %u\n",
1732 GNUNET_i2s (peer), (unsigned int) pr->rim_id);
1733#endif
1734 GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
1735 h->control_pending_tail, cm);
1736 pr->pcic = info;
1737 pr->pcic_cls = info_cls;
1738 pr->pcic_ptr = irc; /* for free'ing irc */
1739 if (NULL != h->client)
1740 trigger_next_request (h, GNUNET_NO);
1741 return irc;
1742}
1743
1744
1745/**
1746 * Cancel request for getting information about a peer.
1747 * Note that an eventual change in preference, trust or bandwidth
1748 * assignment MAY have already been committed at the time,
1749 * so cancelling a request is NOT sure to undo the original
1750 * request. The original request may or may not still commit.
1751 * The only thing cancellation ensures is that the callback
1752 * from the original request will no longer be called.
1753 *
1754 * @param irc context returned by the original GNUNET_CORE_peer_get_info call
1755 */
1756void
1757GNUNET_CORE_peer_change_preference_cancel (struct
1758 GNUNET_CORE_InformationRequestContext
1759 *irc)
1760{
1761 struct GNUNET_CORE_Handle *h = irc->h;
1762 struct PeerRecord *pr = irc->pr;
1763
1764 GNUNET_assert (pr->pcic_ptr == irc);
1765 if (irc->cm != NULL)
1766 {
1767 GNUNET_CONTAINER_DLL_remove (h->control_pending_head,
1768 h->control_pending_tail, irc->cm);
1769 GNUNET_free (irc->cm);
1770 }
1771 pr->pcic = NULL;
1772 pr->pcic_cls = NULL;
1773 pr->pcic_ptr = NULL;
1774 GNUNET_free (irc);
1775}
1776
1777
1778/* end of core_api.c */ 1553/* end of core_api.c */