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.h
23 * @brief neighbour management API
24 * @author Christian Grothoff
26 #ifndef GNUNET_SERVICE_TRANSPORT_NEIGHBOURS_H
27 #define GNUNET_SERVICE_TRANSPORT_NEIGHBOURS_H
29 #include "gnunet_statistics_service.h"
30 #include "gnunet_transport_service.h"
31 #include "gnunet_util_lib.h"
34 // - ATS and similar info is a bit lacking in the API right now...
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);
52 * Cleanup the neighbours subsystem.
55 GST_neighbours_stop (void);
59 * Try to create a connection to the given target (eventually).
61 * @param target peer to try to connect to
64 GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
68 * Test if we're connected to the given peer.
70 * @param target peer to test
71 * @return GNUNET_YES if we are connected, GNUNET_NO if not
74 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
78 * Function called after the transmission is done.
81 * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected
83 typedef void (*GST_NeighbourSendContinuation)(void *cls,
88 * Transmit a message to the given target using the active connection.
90 * @param target destination
91 * @param msg message to send
92 * @param timeout when to fail with timeout
93 * @param cont function to call when done
94 * @param cont_cls closure for 'cont'
97 GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
98 const struct GNUNET_MessageHeader *msg,
99 struct GNUNET_TIME_Relative timeout,
100 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_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
111 struct GNUNET_BANDWIDTH_Value32NBO quota);
115 * If we have an active connection to the given target, it must be shutdown.
117 * @param target peer to disconnect from
120 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
124 * Function called for each connected neighbour.
127 * @param neighbour identity of the neighbour
128 * @param ats performance data
129 * @param ats_count number of entries in ats (excluding 0-termination)
131 typedef void (*GST_NeighbourIterator)(void *cls,
132 const struct GNUNET_PeerIdentity *neighbour,
133 const struct GNUNET_TRANSPORT_ATS_Information *ats,
138 * Iterate over all connected neighbours.
140 * @param cb function to call
141 * @param cb_cls closure for cb
144 GST_neighbours_iterate (GST_NeighbourIterator cb,
149 * We have received a PONG. Update lifeness of the neighbour.
151 * @param sender peer sending the PONG
152 * @param hdr the PONG message (presumably)
153 * @param plugin_name name of transport that delivered the PONG
154 * @param sender_address address of the other peer, NULL if other peer
156 * @param sender_address_len number of bytes in sender_address
157 * @param ats performance data
158 * @param ats_count number of entries in ats (excluding 0-termination)
159 * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
162 GST_neighbours_handle_pong (const struct GNUNET_PeerIdentity *sender,
163 const struct GNUNET_MessageHeader *hdr,
164 const char *plugin_name,
165 const void *sender_address,
166 size_t sender_address_len,
167 const struct GNUNET_TRANSPORT_ATS_Information *ats,
172 * We have received a CONNECT. Set the peer to connected.
174 * @param sender peer sending the PONG
175 * @param hdr the PONG message (presumably)
176 * @param plugin_name name of transport that delivered the PONG
177 * @param sender_address address of the other peer, NULL if other peer
179 * @param sender_address_len number of bytes in sender_address
180 * @param ats performance data
181 * @param ats_count number of entries in ats (excluding 0-termination)
182 * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
185 GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender,
186 const struct GNUNET_MessageHeader *hdr,
187 const char *plugin_name,
188 const void *sender_address,
189 size_t sender_address_len,
190 const struct GNUNET_TRANSPORT_ATS_Information *ats,
195 * We have received a DISCONNECT. Set the peer to disconnected.
197 * @param sender peer sending the PONG
198 * @param hdr the PONG message (presumably)
199 * @param plugin_name name of transport that delivered the PONG
200 * @param sender_address address of the other peer, NULL if other peer
202 * @param sender_address_len number of bytes in sender_address
203 * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
206 GST_neighbours_handle_disconnect (const struct GNUNET_PeerIdentity *sender,
207 const struct GNUNET_MessageHeader *hdr,
208 const char *plugin_name,
209 const void *sender_address,
210 size_t sender_address_len);
214 /* end of file gnunet-service-transport_neighbours.h */