2 This file is part of GNUnet.
3 (C) 2010,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 transport/gnunet-service-transport_neighbours.c
23 * @brief neighbour management
24 * @author Christian Grothoff
27 #include "gnunet-service-transport_neighbours.h"
28 #include "gnunet-service-transport.h"
31 // - have a way to access the currently 'connected' session
32 // (for sending and to notice disconnect of it!)
33 // - have a way to access/update bandwidth/quota information per peer
34 // (for CostReport/TrafficReport callbacks)
39 * Initialize the neighbours subsystem.
41 * @param cls closure for callbacks
42 * @param connect_cb function to call if we connect to a peer
43 * @param disconnect_cb function to call if we disconnect from a peer
46 GST_neighbours_start (void *cls,
47 GNUNET_TRANSPORT_NotifyConnect connect_cb,
48 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb)
54 * Cleanup the neighbours subsystem.
57 GST_neighbours_stop ()
63 * Try to create a connection to the given target (eventually).
65 * @param target peer to try to connect to
68 GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
74 * Test if we're connected to the given peer.
76 * @param target peer to test
77 * @return GNUNET_YES if we are connected, GNUNET_NO if not
80 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target)
87 * Transmit a message to the given target using the active connection.
89 * @param target destination
90 * @param msg message to send
91 * @param cont function to call when done
92 * @param cont_cls closure for 'cont'
95 GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
96 const struct GNUNET_MessageHeader *msg,
97 GST_NeighbourSendContinuation cont,
104 * Change the incoming quota for the given peer.
106 * @param neighbour identity of peer to change qutoa for
107 * @param quota new quota
110 GST_neighbours_set_quota (const struct GNUNET_PeerIdentity *neighbour,
111 struct GNUNET_BANDWIDTH_Value32NBO quota)
115 n = find_neighbour (neighbour);
118 GNUNET_STATISTICS_update (stats,
119 gettext_noop ("# SET QUOTA messages ignored (no such peer)"),
124 GNUNET_BANDWIDTH_tracker_update_quota (&n->in_tracker,
126 if (0 != ntohl (qsm->quota.value__))
129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
130 "Disconnecting peer `%4s' due to `%s'\n",
134 GNUNET_STATISTICS_update (stats,
135 gettext_noop ("# disconnects due to quota of 0"),
138 GST_neighbours_force_disconnect (neighbour);
145 * If we have an active connection to the given target, it must be shutdown.
147 * @param target peer to disconnect from
150 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target)
156 * Iterate over all connected neighbours.
158 * @param cb function to call
159 * @param cb_cls closure for cb
162 GST_neighbours_iterate (GST_NeighbourIterator cb,
169 * We have received a PONG. Update lifeness of the neighbour.
171 * @param sender peer sending the PONG
172 * @param hdr the PONG message (presumably)
173 * @param plugin_name name of transport that delivered the PONG
174 * @param sender_address address of the other peer, NULL if other peer
176 * @param sender_address_len number of bytes in sender_address
177 * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
180 GST_neighbours_handle_pong (const struct GNUNET_PeerIdentity *sender,
181 const struct GNUNET_MessageHeader *hdr,
182 const char *plugin_name,
183 const void *sender_address,
184 size_t sender_address_len)
186 return GNUNET_SYSERR;
191 * We have received a CONNECT. Set the peer to connected.
193 * @param sender peer sending the PONG
194 * @param hdr the PONG message (presumably)
195 * @param plugin_name name of transport that delivered the PONG
196 * @param sender_address address of the other peer, NULL if other peer
198 * @param sender_address_len number of bytes in sender_address
199 * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
202 GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender,
203 const struct GNUNET_MessageHeader *hdr,
204 const char *plugin_name,
205 const void *sender_address,
206 size_t sender_address_len)
208 return GNUNET_SYSERR;
213 * We have received a DISCONNECT. Set the peer to disconnected.
215 * @param sender peer sending the PONG
216 * @param hdr the PONG message (presumably)
217 * @param plugin_name name of transport that delivered the PONG
218 * @param sender_address address of the other peer, NULL if other peer
220 * @param sender_address_len number of bytes in sender_address
221 * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
224 GST_neighbours_handle_disconnect (const struct GNUNET_PeerIdentity *sender,
225 const struct GNUNET_MessageHeader *hdr,
226 const char *plugin_name,
227 const void *sender_address,
228 size_t sender_address_len)
230 return GNUNET_SYSERR;
234 /* end of file gnunet-service-transport_neighbours.c */