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 * A peer connected to us. Setup the connected peer
36 * @param peer identity of peer that connected
37 * @param atsi performance data for the connection
38 * @return handle to connected peer entry
40 struct GSF_ConnectedPeer *
41 GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
42 const struct GNUNET_TRANSPORT_ATS_Information *atsi);
46 * Function called to get a message for transmission.
49 * @param buf_size number of bytes available in buf
50 * @param buf where to copy the message, NULL on error (peer disconnect)
51 * @return number of bytes copied to 'buf', can be 0 (without indicating an error)
53 typedef size_t (*GSF_GetMessageCallback)(void *cls,
59 * Transmit a message to the given peer as soon as possible.
60 * If the peer disconnects before the transmission can happen,
61 * the callback is invoked with a 'NULL' buffer.
63 * @param peer target peer
64 * @param size number of bytes we would like to send to the peer
65 * @param gmc function to call to get the message
66 * @param gmc_cls closure for gmc
69 GSF_peer_transmit_ (struct GSF_ConnectedPeer *peer,
71 GSF_GetMessageCallback gmc,
76 * Method called whenever a given peer has a status change.
79 * @param peer peer identity this notification is about
80 * @param bandwidth_in available amount of inbound bandwidth
81 * @param bandwidth_out available amount of outbound bandwidth
82 * @param timeout absolute time when this peer will time out
83 * unless we see some further activity from it
84 * @param atsi status information
87 GSF_peer_status_handler_ (void *cls,
88 const struct GNUNET_PeerIdentity *peer,
89 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
90 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
91 struct GNUNET_TIME_Absolute timeout,
92 const struct GNUNET_TRANSPORT_ATS_Information *atsi);
96 * A peer disconnected from us. Tear down the connected peer
100 * @param peer identity of peer that connected
103 GSF_peer_disconnect_handler_ (void *cls,
104 const struct GNUNET_PeerIdentity *peer);
108 * Signature of function called on a connected peer.
111 * @param peer identity of the peer
112 * @param cp handle to the connected peer record
114 typedef void (*GSF_ConnectedPeerIterator)(void *cls,
115 const struct GNUNET_PeerIdentity *peer,
116 struct GSF_ConnectedPeer *cp);
120 * Iterate over all connected peers.
122 * @param it function to call for each peer
123 * @param it_cls closure for it
126 GSF_iterate_connected_peers_ (GSF_ConnectedPeerIterator it,
131 * Register callback to invoke on peer disconnect.
133 * @param cp peer to monitor
134 * @param it function to call on disconnect
135 * @param it_cls closure for it
138 GSF_connected_peer_register_disconnect_callback_ (struct GSF_ConnectedPeer *cp,
139 GSF_ConnectedPeerIterator it,
144 * Unregister callback to invoke on peer disconnect.
146 * @param cp peer to stop monitoring
147 * @param it function to no longer call on disconnect
148 * @param it_cls closure for it
151 GSF_connected_peer_unregister_disconnect_callback_ (struct GSF_ConnectedPeer *cp,
152 GSF_ConnectedPeerIterator it,
157 * Signature of function called on a reservation success.
160 * @param cp handle to the connected peer record
162 typedef void (*GSF_PeerReserveCallback)(void *cls,
163 struct GSF_ConnectedPeer *cp);
167 * Try to reserve bandwidth (to receive data FROM the given peer).
168 * This function must only be called ONCE per connected peer at a
169 * time; it can be called again after the 'rc' callback was invoked.
170 * If the peer disconnects, the request is (silently!) ignored (and
171 * the requester is responsible to register for notification about the
172 * peer disconnect if any special action needs to be taken in this
175 * @param cp peer to reserve bandwidth from
176 * @param size number of bytes to reserve
177 * @param rc function to call upon reservation success
178 * @param rc_cls closure for rc
181 GSF_connected_peer_reserve_ (struct GSF_ConnectedPeer *cp,
183 GSF_PeerReserveCallback rc,
188 /* end of gnunet-service-fs_cp.h */