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 3, 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_change_preference 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;
64 static struct GNUNET_BANDWIDTH_Value32NBO zbw; /* zero bandwidth */
68 if (irc->info != NULL)
69 irc->info (irc->info_cls,
70 NULL, zbw, zbw, 0, 0);
71 GNUNET_CLIENT_disconnect (irc->client, GNUNET_NO);
75 if ( (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_CORE_CONFIGURATION_INFO) ||
76 (ntohs (msg->size) != sizeof (struct ConfigurationInfoMessage)) )
79 if (irc->info != NULL)
80 irc->info (irc->info_cls,
81 NULL, zbw, zbw, 0, 0);
82 GNUNET_CLIENT_disconnect (irc->client, GNUNET_NO);
86 cim = (const struct ConfigurationInfoMessage*) msg;
87 if (irc->info != NULL)
88 irc->info (irc->info_cls,
92 ntohl (cim->reserved_amount),
93 GNUNET_ntohll (cim->preference));
94 GNUNET_CLIENT_disconnect (irc->client, GNUNET_NO);
100 * Obtain statistics and/or change preferences for the given peer.
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 bw_out set to the current bandwidth limit (sending) for this peer,
107 * caller should set "bw_out" to "-1" to avoid changing
108 * the current value; otherwise "bw_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; "bw_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 (const struct GNUNET_CONFIGURATION_Handle *cfg,
125 const struct GNUNET_PeerIdentity *peer,
126 struct GNUNET_TIME_Relative timeout,
127 struct GNUNET_BANDWIDTH_Value32NBO bw_out,
130 GNUNET_CORE_PeerConfigurationInfoCallback info,
133 struct GNUNET_CORE_InformationRequestContext *irc;
134 struct RequestInfoMessage rim;
135 struct GNUNET_CLIENT_Connection *client;
138 client = GNUNET_CLIENT_connect ("core", cfg);
141 irc = GNUNET_malloc (sizeof (struct GNUNET_CORE_InformationRequestContext));
142 irc->client = client;
144 irc->info_cls = info_cls;
145 rim.header.size = htons (sizeof (struct RequestInfoMessage));
146 rim.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_REQUEST_INFO);
147 rim.reserved = htonl (0);
148 rim.limit_outbound = bw_out;
149 rim.reserve_inbound = htonl (amount);
150 rim.preference_change = GNUNET_htonll(preference);
152 retry = ( (amount == 0) && (preference == 0) ) ? GNUNET_YES : GNUNET_NO;
153 GNUNET_assert (GNUNET_OK == GNUNET_CLIENT_transmit_and_get_response (client,
164 * Cancel request for getting information about a peer.
166 * @param irc context returned by the original GNUNET_CORE_peer_get_info call
169 GNUNET_CORE_peer_change_preference_cancel (struct GNUNET_CORE_InformationRequestContext *irc)
171 GNUNET_CLIENT_disconnect (irc->client, GNUNET_NO);
175 /* end of core_api_peer_get_info.c */