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