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.c
23 * @brief API to handle 'connected peers'
24 * @author Christian Grothoff
27 #include "gnunet-service-fs.h"
28 #include "gnunet-service-fs_cp.h"
31 struct GSF_PeerTransmitHandle
35 * Time when this transmission request was issued.
37 struct GNUNET_TIME_Absolute transmission_request_start_time;
46 struct GSF_ConnectedPeer
50 * Performance data for this peer.
52 struct GSF_PeerPerformanceData ppd;
55 * Time until when we blocked this peer from migrating
58 struct GNUNET_TIME_Absolute last_migration_block;
61 * Handle for an active request for transmission to this
64 struct GNUNET_CORE_TransmitHandle *cth;
67 * Messages (replies, queries, content migration) we would like to
68 * send to this peer in the near future. Sorted by priority, head.
70 struct GSF_PeerTransmitHandle *pth_head;
73 * Messages (replies, queries, content migration) we would like to
74 * send to this peer in the near future. Sorted by priority, tail.
76 struct GSF_PeerTransmitHandle *pth_tail;
79 * Context of our GNUNET_CORE_peer_change_preference call (or NULL).
81 struct GNUNET_CORE_InformationRequestContext *irc;
84 * ID of delay task for scheduling transmission.
86 GNUNET_SCHEDULER_TaskIdentifier delayed_transmission_request_task;
89 * Increase in traffic preference still to be submitted
90 * to the core service for this peer.
92 uint64_t inc_preference;
95 * Trust rating for this peer
100 * Trust rating for this peer on disk.
105 * The peer's identity.
110 * Which offset in "last_p2p_replies" will be updated next?
111 * (we go round-robin).
113 unsigned int last_p2p_replies_woff;
116 * Which offset in "last_client_replies" will be updated next?
117 * (we go round-robin).
119 unsigned int last_client_replies_woff;
122 * Current offset into 'last_request_times' ring buffer.
124 unsigned int last_request_times_off;
130 * A peer connected to us. Setup the connected peer
133 * @param peer identity of peer that connected
134 * @param atsi performance data for the connection
135 * @return handle to connected peer entry
137 struct GSF_ConnectedPeer *
138 GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
139 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
147 * Transmit a message to the given peer as soon as possible.
148 * If the peer disconnects before the transmission can happen,
149 * the callback is invoked with a 'NULL' buffer.
151 * @param peer target peer
152 * @param is_query is this a query (GNUNET_YES) or content (GNUNET_NO)
153 * @param priority how important is this request?
154 * @param timeout when does this request timeout (call gmc with error)
155 * @param size number of bytes we would like to send to the peer
156 * @param gmc function to call to get the message
157 * @param gmc_cls closure for gmc
158 * @return handle to cancel request
160 struct GSF_PeerTransmitHandle *
161 GSF_peer_transmit_ (struct GSF_ConnectedPeer *peer,
164 struct GNUNET_TIME_Relative timeout,
166 GSF_GetMessageCallback gmc,
175 * Cancel an earlier request for transmission.
178 GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth)
184 * Report on receiving a reply; update the performance record of the given peer.
186 * @param peer responding peer (will be updated)
187 * @param request_time time at which the original query was transmitted
188 * @param request_priority priority of the original request
189 * @param initiator_client local client on responsible for query (or NULL)
190 * @param initiator_peer other peer responsible for query (or NULL)
193 GSF_peer_update_performance_ (struct GSF_ConnectedPeer *peer,
194 GNUNET_TIME_Absolute request_time,
195 uint32_t request_priority,
196 const struct GSF_LocalClient *initiator_client,
197 const struct GSF_ConnectedPeer *initiator_peer)
203 * Method called whenever a given peer has a status change.
206 * @param peer peer identity this notification is about
207 * @param bandwidth_in available amount of inbound bandwidth
208 * @param bandwidth_out available amount of outbound bandwidth
209 * @param timeout absolute time when this peer will time out
210 * unless we see some further activity from it
211 * @param atsi status information
214 GSF_peer_status_handler_ (void *cls,
215 const struct GNUNET_PeerIdentity *peer,
216 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
217 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
218 struct GNUNET_TIME_Absolute timeout,
219 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
225 * A peer disconnected from us. Tear down the connected peer
229 * @param peer identity of peer that connected
232 GSF_peer_disconnect_handler_ (void *cls,
233 const struct GNUNET_PeerIdentity *peer)
239 * Iterate over all connected peers.
241 * @param it function to call for each peer
242 * @param it_cls closure for it
245 GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it,
252 * Try to reserve bandwidth (to receive data FROM the given peer).
253 * This function must only be called ONCE per connected peer at a
254 * time; it can be called again after the 'rc' callback was invoked.
255 * If the peer disconnects, the request is (silently!) ignored (and
256 * the requester is responsible to register for notification about the
257 * peer disconnect if any special action needs to be taken in this
260 * @param cp peer to reserve bandwidth from
261 * @param size number of bytes to reserve
262 * @param rc function to call upon reservation success or failure
263 * @param rc_cls closure for rc
266 GSF_connected_peer_reserve_ (struct GSF_ConnectedPeer *cp,
268 GSF_PeerReserveCallback rc,
271 // FIXME: should we allow queueing multiple reservation requests?
272 // FIXME: what about cancellation?
273 // FIXME: change docu on peer disconnect handling?
276 rc (rc_cls, cp, GNUNET_NO);
284 /* end of gnunet-service-fs_cp.h */