2 This file is part of GNUnet.
3 (C) 2009, 2010 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file core/core_api_peer_get_info.c
23 * @brief implementation of the peer_get_info functions
24 * @author Christian Grothoff
27 #include "gnunet_core_service.h"
31 struct GNUNET_CORE_InformationRequestContext
35 * Our connection to the service.
37 struct GNUNET_CLIENT_Connection *client;
40 * Function to call with the information.
42 GNUNET_CORE_PeerConfigurationInfoCallback info;
53 * Receive reply from core service with information about a peer.
55 * @param cls our 'struct GNUNET_CORE_InformationRequestContext *'
56 * @param msg NULL on error (i.e. timeout)
59 receive_info (void *cls,
60 const struct GNUNET_MessageHeader *msg)
62 struct GNUNET_CORE_InformationRequestContext *irc = cls;
63 const struct ConfigurationInfoMessage *cim;
67 if (irc->info != NULL)
68 irc->info (irc->info_cls,
70 GNUNET_CLIENT_disconnect (irc->client);
74 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO) ||
75 (ntohs (msg->size) != sizeof (struct ConfigurationInfoMessage)) )
78 if (irc->info != NULL)
79 irc->info (irc->info_cls,
80 NULL, 0, 0, GNUNET_TIME_UNIT_FOREVER_REL, 0, 0);
81 GNUNET_CLIENT_disconnect (irc->client);
85 cim = (const struct ConfigurationInfoMessage*) msg;
86 if (irc->info != NULL)
87 irc->info (irc->info_cls,
91 ntohl (cim->reserved_amount),
92 GNUNET_ntohll (cim->preference));
93 GNUNET_CLIENT_disconnect (irc->client);
99 * Obtain statistics and/or change preferences for the given peer.
101 * @param sched scheduler to use
102 * @param cfg configuration to use
103 * @param peer identifies the peer
104 * @param timeout after how long should we give up (and call "info" with NULL
105 * for "peer" to signal an error)?
106 * @param bpm_out set to the current bandwidth limit (sending) for this peer,
107 * caller should set "bpm_out" to "-1" to avoid changing
108 * the current value; otherwise "bpm_out" will be lowered to
109 * the specified value; passing a pointer to "0" can be used to force
110 * us to disconnect from the peer; "bpm_out" might not increase
111 * as specified since the upper bound is generally
112 * determined by the other peer!
113 * @param amount reserve N bytes for receiving, negative
114 * amounts can be used to undo a (recent) reservation;
115 * @param preference increase incoming traffic share preference by this amount;
116 * in the absence of "amount" reservations, we use this
117 * preference value to assign proportional bandwidth shares
118 * to all connected peers
119 * @param info function to call with the resulting configuration information
120 * @param info_cls closure for info
121 * @return NULL on error
123 struct GNUNET_CORE_InformationRequestContext *
124 GNUNET_CORE_peer_change_preference (struct GNUNET_SCHEDULER_Handle *sched,
125 const struct GNUNET_CONFIGURATION_Handle *cfg,
126 const struct GNUNET_PeerIdentity *peer,
127 struct GNUNET_TIME_Relative timeout,
131 GNUNET_CORE_PeerConfigurationInfoCallback info,
134 struct GNUNET_CORE_InformationRequestContext *irc;
135 struct RequestInfoMessage rim;
136 struct GNUNET_CLIENT_Connection *client;
139 client = GNUNET_CLIENT_connect (sched, "core", cfg);
142 irc = GNUNET_malloc (sizeof (struct GNUNET_CORE_InformationRequestContext));
143 irc->client = client;
145 irc->info_cls = info_cls;
146 rim.header.size = htons (sizeof (struct RequestInfoMessage));
147 rim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO);
148 rim.reserved = htonl (0);
149 rim.limit_outbound_bpm = htonl (bpm_out);
150 rim.reserve_inbound = htonl (amount);
151 rim.preference_change = GNUNET_htonll(preference);
153 retry = ( (amount == 0) && (preference == 0) ) ? GNUNET_YES : GNUNET_NO;
154 GNUNET_assert (GNUNET_OK == GNUNET_CLIENT_transmit_and_get_response (client,
165 * Cancel request for getting information about a peer.
167 * @param irc context returned by the original GNUNET_CORE_peer_get_info call
170 GNUNET_CORE_peer_get_info_cancel (struct GNUNET_CORE_InformationRequestContext *irc)
172 GNUNET_CLIENT_disconnect (irc->client);
176 /* end of core_api_peer_get_info.c */