aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs_cp.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-01-30 16:02:52 +0000
committerChristian Grothoff <christian@grothoff.org>2011-01-30 16:02:52 +0000
commitbc0e1c956bef848d2569e0c56ccbda13597418f7 (patch)
tree88d82a018890ed112c61f21fe2f38e2fe1edc89f /src/fs/gnunet-service-fs_cp.c
parentdee60c25690117fabb90b497dbe23378b3e00db1 (diff)
downloadgnunet-bc0e1c956bef848d2569e0c56ccbda13597418f7.tar.gz
gnunet-bc0e1c956bef848d2569e0c56ccbda13597418f7.zip
stuff
Diffstat (limited to 'src/fs/gnunet-service-fs_cp.c')
-rw-r--r--src/fs/gnunet-service-fs_cp.c284
1 files changed, 284 insertions, 0 deletions
diff --git a/src/fs/gnunet-service-fs_cp.c b/src/fs/gnunet-service-fs_cp.c
new file mode 100644
index 000000000..6f3f06d3f
--- /dev/null
+++ b/src/fs/gnunet-service-fs_cp.c
@@ -0,0 +1,284 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20
21/**
22 * @file fs/gnunet-service-fs_cp.c
23 * @brief API to handle 'connected peers'
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet-service-fs.h"
28#include "gnunet-service-fs_cp.h"
29
30
31struct GSF_PeerTransmitHandle
32{
33
34 /**
35 * Time when this transmission request was issued.
36 */
37 struct GNUNET_TIME_Absolute transmission_request_start_time;
38
39
40};
41
42
43/**
44 * A connected peer.
45 */
46struct GSF_ConnectedPeer
47{
48
49 /**
50 * Performance data for this peer.
51 */
52 struct GSF_PeerPerformanceData ppd;
53
54 /**
55 * Time until when we blocked this peer from migrating
56 * data to us.
57 */
58 struct GNUNET_TIME_Absolute last_migration_block;
59
60 /**
61 * Handle for an active request for transmission to this
62 * peer, or NULL.
63 */
64 struct GNUNET_CORE_TransmitHandle *cth;
65
66 /**
67 * Messages (replies, queries, content migration) we would like to
68 * send to this peer in the near future. Sorted by priority, head.
69 */
70 struct GSF_PeerTransmitHandle *pth_head;
71
72 /**
73 * Messages (replies, queries, content migration) we would like to
74 * send to this peer in the near future. Sorted by priority, tail.
75 */
76 struct GSF_PeerTransmitHandle *pth_tail;
77
78 /**
79 * Context of our GNUNET_CORE_peer_change_preference call (or NULL).
80 */
81 struct GNUNET_CORE_InformationRequestContext *irc;
82
83 /**
84 * ID of delay task for scheduling transmission.
85 */
86 GNUNET_SCHEDULER_TaskIdentifier delayed_transmission_request_task;
87
88 /**
89 * Increase in traffic preference still to be submitted
90 * to the core service for this peer.
91 */
92 uint64_t inc_preference;
93
94 /**
95 * Trust rating for this peer
96 */
97 uint32_t trust;
98
99 /**
100 * Trust rating for this peer on disk.
101 */
102 uint32_t disk_trust;
103
104 /**
105 * The peer's identity.
106 */
107 GNUNET_PEER_Id pid;
108
109 /**
110 * Which offset in "last_p2p_replies" will be updated next?
111 * (we go round-robin).
112 */
113 unsigned int last_p2p_replies_woff;
114
115 /**
116 * Which offset in "last_client_replies" will be updated next?
117 * (we go round-robin).
118 */
119 unsigned int last_client_replies_woff;
120
121 /**
122 * Current offset into 'last_request_times' ring buffer.
123 */
124 unsigned int last_request_times_off;
125
126};
127
128
129/**
130 * A peer connected to us. Setup the connected peer
131 * records.
132 *
133 * @param peer identity of peer that connected
134 * @param atsi performance data for the connection
135 * @return handle to connected peer entry
136 */
137struct GSF_ConnectedPeer *
138GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
139 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
140{
141 // FIXME
142 return NULL;
143}
144
145
146/**
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.
150 *
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
159 */
160struct GSF_PeerTransmitHandle *
161GSF_peer_transmit_ (struct GSF_ConnectedPeer *peer,
162 int is_query,
163 uint32_t priority,
164 struct GNUNET_TIME_Relative timeout,
165 size_t size,
166 GSF_GetMessageCallback gmc,
167 void *gmc_cls)
168{
169 // FIXME
170 return NULL;
171}
172
173
174/**
175 * Cancel an earlier request for transmission.
176 */
177void
178GSF_peer_transmit_cancel_ (struct GSF_PeerTransmitHandle *pth)
179{
180}
181
182
183/**
184 * Report on receiving a reply; update the performance record of the given peer.
185 *
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)
191 */
192void
193GSF_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)
198{
199}
200
201
202/**
203 * Method called whenever a given peer has a status change.
204 *
205 * @param cls closure
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
212 */
213void
214GSF_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)
220{
221}
222
223
224/**
225 * A peer disconnected from us. Tear down the connected peer
226 * record.
227 *
228 * @param cls unused
229 * @param peer identity of peer that connected
230 */
231void
232GSF_peer_disconnect_handler_ (void *cls,
233 const struct GNUNET_PeerIdentity *peer)
234{
235}
236
237
238/**
239 * Iterate over all connected peers.
240 *
241 * @param it function to call for each peer
242 * @param it_cls closure for it
243 */
244void
245GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it,
246 void *it_cls)
247{
248}
249
250
251/**
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
258 * case).
259 *
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
264 */
265void
266GSF_connected_peer_reserve_ (struct GSF_ConnectedPeer *cp,
267 size_t size,
268 GSF_PeerReserveCallback rc,
269 void *rc_cls)
270{
271 // FIXME: should we allow queueing multiple reservation requests?
272 // FIXME: what about cancellation?
273 // FIXME: change docu on peer disconnect handling?
274 if (NULL != cp->irc)
275 {
276 rc (rc_cls, cp, GNUNET_NO);
277 return;
278 }
279 // FIXME...
280}
281
282
283#endif
284/* end of gnunet-service-fs_cp.h */