switch api
[oweals/gnunet.git] / src / transport / gnunet-service-transport_neighbours.h
1 /*
2      This file is part of GNUnet.
3      (C) 2010,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 transport/gnunet-service-transport_neighbours.h
23  * @brief neighbour management API
24  * @author Christian Grothoff
25  */
26 #ifndef GNUNET_SERVICE_TRANSPORT_NEIGHBOURS_H
27 #define GNUNET_SERVICE_TRANSPORT_NEIGHBOURS_H
28
29 #include "gnunet_statistics_service.h"
30 #include "gnunet_transport_service.h"
31 #include "gnunet_transport_plugin.h"
32 #include "gnunet_util_lib.h"
33
34 // TODO:
35 // - ATS and similar info is a bit lacking in the API right now...
36
37
38
39 /**
40  * Initialize the neighbours subsystem.
41  *
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
45  */
46 void 
47 GST_neighbours_start (void *cls,
48                       GNUNET_TRANSPORT_NotifyConnect connect_cb,
49                       GNUNET_TRANSPORT_NotifyDisconnect disconnect_cb);
50
51
52 /**
53  * Cleanup the neighbours subsystem.
54  */
55 void
56 GST_neighbours_stop (void);
57
58
59 /**
60  * Try to create a connection to the given target (eventually).
61  *
62  * @param target peer to try to connect to
63  */
64 void
65 GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
66
67
68 /**
69  * Test if we're connected to the given peer.
70  * 
71  * @param target peer to test
72  * @return GNUNET_YES if we are connected, GNUNET_NO if not
73  */
74 int
75 GST_neighbours_test_connected (const struct GNUNET_PeerIdentity *target);
76
77
78 /**
79  * Function called after the transmission is done.
80  *
81  * @param cls closure
82  * @param success GNUNET_OK on success, GNUNET_NO on failure, GNUNET_SYSERR if we're not connected
83  */
84 typedef void (*GST_NeighbourSendContinuation)(void *cls,
85                                               int success);
86
87
88 /**
89  * Transmit a message to the given target using the active connection.
90  *
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'
97  */
98 void
99 GST_neighbours_send (const struct GNUNET_PeerIdentity *target,
100                      const void *msg,
101                      size_t msg_size,
102                      struct GNUNET_TIME_Relative timeout,
103                      GST_NeighbourSendContinuation cont,
104                      void *cont_cls);
105
106 /**
107  * Change the incoming quota for the given peer.
108  *
109  * @param neighbour identity of peer to change qutoa for
110  * @param quota new quota 
111  */
112 void
113 GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour,
114                                    struct GNUNET_BANDWIDTH_Value32NBO quota);
115
116
117 /**
118  * If we have an active connection to the given target, it must be shutdown.
119  *
120  * @param target peer to disconnect from
121  */
122 void
123 GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target);
124
125
126 /**
127  * Function called for each connected neighbour.
128  *
129  * @param cls closure
130  * @param neighbour identity of the neighbour
131  * @param ats performance data
132  * @param ats_count number of entries in ats (excluding 0-termination)
133  */
134 typedef void (*GST_NeighbourIterator)(void *cls,
135                                       const struct GNUNET_PeerIdentity *neighbour,
136                                       const struct GNUNET_TRANSPORT_ATS_Information *ats,
137                                       uint32_t ats_count);
138
139
140 /**
141  * Iterate over all connected neighbours.
142  *
143  * @param cb function to call 
144  * @param cb_cls closure for cb
145  */
146 void
147 GST_neighbours_iterate (GST_NeighbourIterator cb,
148                         void *cb_cls);
149
150
151 /**
152  * We have received a CONNECT.  Set the peer to connected.
153  *
154  * @param sender peer sending the PONG
155  * @param hdr the PONG message (presumably)
156  * @param plugin_name name of transport that delivered the PONG
157  * @param sender_address address of the other peer, NULL if other peer
158  *                       connected to us
159  * @param sender_address_len number of bytes in sender_address
160  * @param ats performance data
161  * @param ats_count number of entries in ats (excluding 0-termination)
162  * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
163  */
164 int
165 GST_neighbours_handle_connect (const struct GNUNET_PeerIdentity *sender,
166                                const struct GNUNET_MessageHeader *hdr,
167                                const char *plugin_name,
168                                const void *sender_address,
169                                size_t sender_address_len,
170                                struct Session *session,
171                                const struct GNUNET_TRANSPORT_ATS_Information *ats,
172                                uint32_t ats_count);
173
174
175 /**
176  * For an existing neighbour record, set the active connection to
177  * the given address.
178  *
179  * @param plugin_name name of transport that delivered the PONG
180  * @param address address of the other peer, NULL if other peer
181  *                       connected to us
182  * @param address_len number of bytes in address
183  * @param ats performance data
184  * @param ats_count number of entries in ats (excluding 0-termination)
185  */
186 void
187 GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
188                                   const char *plugin_name,
189                                   const void *address,
190                                   size_t address_len,
191                                   struct Session *session,
192                                   const struct GNUNET_TRANSPORT_ATS_Information *ats,
193                                   uint32_t ats_count);
194
195
196 /**
197  * We have received a DISCONNECT.  Set the peer to disconnected.
198  *
199  * @param sender peer sending the PONG
200  * @param hdr the PONG message (presumably)
201  * @param plugin_name name of transport that delivered the PONG
202  * @param sender_address address of the other peer, NULL if other peer
203  *                       connected to us
204  * @param sender_address_len number of bytes in sender_address
205  * @return GNUNET_OK if the message was well-formed, GNUNET_SYSERR if not
206  */
207 int
208 GST_neighbours_handle_disconnect (const struct GNUNET_PeerIdentity *sender,
209                                   const struct GNUNET_MessageHeader *hdr,
210                                   const char *plugin_name,
211                                   const void *sender_address,
212                                   size_t sender_address_len);
213
214
215 #endif
216 /* end of file gnunet-service-transport_neighbours.h */