2 This file is part of GNUnet.
3 (C) 2011 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 fs/gnunet-service-fs_cp.h
23 * @brief API to handle 'connected peers'
24 * @author Christian Grothoff
26 #ifndef GNUNET_SERVICE_FS_CP_H
27 #define GNUNET_SERVICE_FS_CP_H
29 #include "gnunet-service-fs.h"
33 * Performance data kept for a peer.
35 struct GSF_PeerPerformanceData
39 * Transport performance data.
41 struct GNUNET_TRANSPORT_ATS_Information *atsi;
44 * List of the last clients for which this peer successfully
47 struct GSF_LocalClient *last_client_replies[CS2P_SUCCESS_LIST_SIZE];
50 * List of the last PIDs for which
51 * this peer successfully answered a query;
52 * We use 0 to indicate no successful reply.
54 GNUNET_PEER_Id last_p2p_replies[P2P_SUCCESS_LIST_SIZE];
57 * Average delay between sending the peer a request and
58 * getting a reply (only calculated over the requests for
59 * which we actually got a reply). Calculated
60 * as a moving average: new_delay = ((n-1)*last_delay+curr_delay) / n
62 struct GNUNET_TIME_Relative avg_reply_delay;
65 * Point in time until which this peer does not want us to migrate content
68 struct GNUNET_TIME_Absolute migration_blocked_until;
71 * Transmission times for the last MAX_QUEUE_PER_PEER
72 * requests for this peer. Used as a ring buffer, current
73 * offset is stored in 'last_request_times_off'. If the
74 * oldest entry is more recent than the 'avg_delay', we should
75 * not send any more requests right now.
77 struct GNUNET_TIME_Absolute last_request_times[MAX_QUEUE_PER_PEER];
80 * How long does it typically take for us to transmit a message
81 * to this peer? (delay between the request being issued and
82 * the callback being invoked).
84 struct GNUNET_LOAD_Value *transmission_delay;
87 * Average priority of successful replies. Calculated
88 * as a moving average: new_avg = ((n-1)*last_avg+curr_prio) / n
93 * Number of pending queries (replies are not counted)
95 unsigned int pending_queries;
98 * Number of pending replies (queries are not counted)
100 unsigned int pending_replies;
106 * Signature of function called on a connected peer.
109 * @param peer identity of the peer
110 * @param cp handle to the connected peer record
111 * @param perf peer performance data
113 typedef void (*GSF_ConnectedPeerIterator)(void *cls,
114 const struct GNUNET_PeerIdentity *peer,
115 struct GSF_ConnectedPeer *cp,
116 const struct GSF_PeerPerformanceData *ppd);
120 * Function called to get a message for transmission.
123 * @param buf_size number of bytes available in buf
124 * @param buf where to copy the message, NULL on error (peer disconnect)
125 * @return number of bytes copied to 'buf', can be 0 (without indicating an error)
127 typedef size_t (*GSF_GetMessageCallback)(void *cls,
133 * Signature of function called on a reservation success or failure.
136 * @param cp handle to the connected peer record
137 * @param success GNUNET_YES on success, GNUNET_NO on failure
139 typedef void (*GSF_PeerReserveCallback)(void *cls,
140 struct GSF_ConnectedPeer *cp,
145 * Handle to cancel a transmission request.
147 struct GSF_PeerTransmitHandle;
151 * A peer connected to us. Setup the connected peer
154 * @param peer identity of peer that connected
155 * @param atsi performance data for the connection
156 * @return handle to connected peer entry
158 struct GSF_ConnectedPeer *
159 GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
160 const struct GNUNET_TRANSPORT_ATS_Information *atsi);
164 * Transmit a message to the given peer as soon as possible.
165 * If the peer disconnects before the transmission can happen,
166 * the callback is invoked with a 'NULL' buffer.
168 * @param peer target peer
169 * @param is_query is this a query (GNUNET_YES) or content (GNUNET_NO)
170 * @param priority how important is this request?
171 * @param timeout when does this request timeout (call gmc with error)
172 * @param size number of bytes we would like to send to the peer
173 * @param gmc function to call to get the message
174 * @param gmc_cls closure for gmc
175 * @return handle to cancel request
177 struct GSF_PeerTransmitHandle *
178 GSF_peer_transmit_ (struct GSF_ConnectedPeer *peer,
181 struct GNUNET_TIME_Relative timeout,
183 GSF_GetMessageCallback gmc,
188 * Cancel an earlier request for transmission.
190 * @param pth request to cancel
193 GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth);
197 * Report on receiving a reply; update the performance record of the given peer.
199 * @param cp responding peer (will be updated)
200 * @param request_time time at which the original query was transmitted
201 * @param request_priority priority of the original request
202 * @param initiator_client local client on responsible for query (or NULL)
203 * @param initiator_peer other peer responsible for query (or NULL)
206 GSF_peer_update_performance_ (struct GSF_ConnectedPeer *cp,
207 struct GNUNET_TIME_Absolute request_time,
208 uint32_t request_priority,
209 const struct GSF_LocalClient *initiator_client,
210 const struct GSF_ConnectedPeer *initiator_peer);
214 * Method called whenever a given peer has a status change.
217 * @param peer peer identity this notification is about
218 * @param bandwidth_in available amount of inbound bandwidth
219 * @param bandwidth_out available amount of outbound bandwidth
220 * @param timeout absolute time when this peer will time out
221 * unless we see some further activity from it
222 * @param atsi status information
225 GSF_peer_status_handler_ (void *cls,
226 const struct GNUNET_PeerIdentity *peer,
227 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
228 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
229 struct GNUNET_TIME_Absolute timeout,
230 const struct GNUNET_TRANSPORT_ATS_Information *atsi);
234 * Handle P2P "MIGRATION_STOP" message.
236 * @param cls closure, always NULL
237 * @param other the other peer involved (sender or receiver, NULL
238 * for loopback messages where we are both sender and receiver)
239 * @param message the actual message
240 * @param atsi performance information
241 * @return GNUNET_OK to keep the connection open,
242 * GNUNET_SYSERR to close it (signal serious error)
245 GSF_handle_p2p_migration_stop_ (void *cls,
246 const struct GNUNET_PeerIdentity *other,
247 const struct GNUNET_MessageHeader *message,
248 const struct GNUNET_TRANSPORT_ATS_Information *atsi);
252 * A peer disconnected from us. Tear down the connected peer
256 * @param peer identity of peer that connected
259 GSF_peer_disconnect_handler_ (void *cls,
260 const struct GNUNET_PeerIdentity *peer);
264 * Notification that a local client disconnected. Clean up all of our
265 * references to the given handle.
267 * @param lc handle to the local client (henceforth invalid)
270 GSF_handle_local_client_disconnect_ (const struct GSF_LocalClient *lc);
274 * Notify core about a preference we have for the given peer
275 * (to allocate more resources towards it). The change will
276 * be communicated the next time we reserve bandwidth with
277 * core (not instantly).
279 * @param cp peer to reserve bandwidth from
280 * @param pref preference change
283 GSF_connected_peer_change_preference_ (struct GSF_ConnectedPeer *cp,
288 * Iterate over all connected peers.
290 * @param it function to call for each peer
291 * @param it_cls closure for it
294 GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it,
299 * Initialize peer management subsystem.
301 * @param cfg configuration to use
304 GSF_connected_peer_init_ (struct GNUNET_CONFIGURATION_Handle *cfg);
308 * Shutdown peer management subsystem.
311 GSF_connected_peer_done_ (void);
315 /* end of gnunet-service-fs_cp.h */