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_transport_plugin.h"
32 #include "gnunet_util_lib.h"
35 // - ATS and similar info is a bit lacking in the API right now...
40 * Initialize the neighbours subsystem.
42 * @param cls closure for callbacks
43 * @param connect_cb function to call if we connect to a peer
44 * @param disconnect_cb function to call if we disconnect from a peer
47 GST_neighbours_start (void *cls,
48 GNUNET_TRANSPORT_NotifyConnect connect_cb,
49 GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb);
53 * Cleanup the neighbours subsystem.
56 GST_neighbours_stop (void);
60 * Try to create a connection to the given target (eventually).
62 * @param target peer to try to connect to
65 GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
69 * Test if we're connected to the given peer.
71 * @param target peer to test
72 * @return GNUNET_YES if we are connected, GNUNET_NO if not
75 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
79 * Function called after the transmission is done.
82 * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected
84 typedef void (*GST_NeighbourSendContinuation)(void *cls,
89 * Transmit a message to the given target using the active connection.
91 * @param target destination
92 * @param msg message to send
93 * @param msg_size number of bytes in msg
94 * @param timeout when to fail with timeout
95 * @param cont function to call when done
96 * @param cont_cls closure for 'cont'
99 GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
102 struct GNUNET_TIME_Relative timeout,
103 GST_NeighbourSendContinuation cont,
108 * We have received a message from the given sender.
109 * How long should we delay before receiving more?
110 * (Also used to keep the peer marked as live).
112 * @param sender sender of the message
113 * @param size size of the message
114 * @param do_forward set to GNUNET_YES if the message should be forwarded to clients
115 * GNUNET_NO if the neighbour is not connected or violates the quota
116 * @return how long to wait before reading more from this sender
118 struct GNUNET_TIME_Relative
119 GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender,
125 * Keep the connection to the given neighbour alive longer,
126 * we received a KEEPALIVE (or equivalent).
128 * @param neighbour neighbour to keep alive
131 GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour);
135 * Change the incoming quota for the given peer.
137 * @param neighbour identity of peer to change qutoa for
138 * @param quota new quota
141 GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
142 struct GNUNET_BANDWIDTH_Value32NBO quota);
146 * If we have an active connection to the given target, it must be shutdown.
148 * @param target peer to disconnect from
151 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
155 * Function called for each connected neighbour.
158 * @param neighbour identity of the neighbour
159 * @param ats performance data
160 * @param ats_count number of entries in ats (excluding 0-termination)
162 typedef void (*GST_NeighbourIterator)(void *cls,
163 const struct GNUNET_PeerIdentity *neighbour,
164 const struct GNUNET_TRANSPORT_ATS_Information *ats,
169 * Iterate over all connected neighbours.
171 * @param cb function to call
172 * @param cb_cls closure for cb
175 GST_neighbours_iterate (GST_NeighbourIterator cb,
180 * A session was terminated. Take note.
182 * @param peer identity of the peer where the session died
183 * @param session session that is gone
186 GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer,
187 struct Session *session);
191 * For an existing neighbour record, set the active connection to
192 * use the given address.
194 * @param peer identity of the peer to switch the address for
195 * @param plugin_name name of transport that delivered the PONG
196 * @param address address of the other peer, NULL if other peer
198 * @param address_len number of bytes in address
199 * @param session session to use (or NULL)
200 * @param ats performance data
201 * @param ats_count number of entries in ats (excluding 0-termination)
204 GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
205 const char *plugin_name,
208 struct Session *session,
209 const struct GNUNET_TRANSPORT_ATS_Information *ats,
214 /* end of file gnunet-service-transport_neighbours.h */