diff options
Diffstat (limited to 'src/transport/gnunet-service-transport_neighbours_3way.h')
-rw-r--r-- | src/transport/gnunet-service-transport_neighbours_3way.h | 272 |
1 files changed, 272 insertions, 0 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours_3way.h b/src/transport/gnunet-service-transport_neighbours_3way.h new file mode 100644 index 000000000..88790449e --- /dev/null +++ b/src/transport/gnunet-service-transport_neighbours_3way.h | |||
@@ -0,0 +1,272 @@ | |||
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, 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, GNUNET_SYSERR if we're not connected | ||
82 | */ | ||
83 | typedef void (*GST_NeighbourSendContinuation) (void *cls, int success); | ||
84 | |||
85 | |||
86 | /** | ||
87 | * Transmit a message to the given target using the active connection. | ||
88 | * | ||
89 | * @param target destination | ||
90 | * @param msg message to send | ||
91 | * @param msg_size number of bytes in msg | ||
92 | * @param timeout when to fail with timeout | ||
93 | * @param cont function to call when done | ||
94 | * @param cont_cls closure for 'cont' | ||
95 | */ | ||
96 | void | ||
97 | GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg, | ||
98 | size_t msg_size, struct GNUNET_TIME_Relative timeout, | ||
99 | GST_NeighbourSendContinuation cont, void *cont_cls); | ||
100 | |||
101 | |||
102 | /** | ||
103 | * We have received a message from the given sender. | ||
104 | * How long should we delay before receiving more? | ||
105 | * (Also used to keep the peer marked as live). | ||
106 | * | ||
107 | * @param sender sender of the message | ||
108 | * @param size size of the message | ||
109 | * @param do_forward set to GNUNET_YES if the message should be forwarded to clients | ||
110 | * GNUNET_NO if the neighbour is not connected or violates the quota | ||
111 | * @return how long to wait before reading more from this sender | ||
112 | */ | ||
113 | struct GNUNET_TIME_Relative | ||
114 | GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity | ||
115 | *sender, ssize_t size, int *do_forward); | ||
116 | |||
117 | |||
118 | /** | ||
119 | * Keep the connection to the given neighbour alive longer, | ||
120 | * we received a KEEPALIVE (or equivalent). | ||
121 | * | ||
122 | * @param neighbour neighbour to keep alive | ||
123 | */ | ||
124 | void | ||
125 | GST_neighbours_keepalive (const struct GNUNET_PeerIdentity *neighbour); | ||
126 | |||
127 | |||
128 | /** | ||
129 | * Change the incoming quota for the given peer. | ||
130 | * | ||
131 | * @param neighbour identity of peer to change qutoa for | ||
132 | * @param quota new quota | ||
133 | */ | ||
134 | void | ||
135 | GST_neighbours_set_incoming_quota (const struct GNUNET_PeerIdentity *neighbour, | ||
136 | struct GNUNET_BANDWIDTH_Value32NBO quota); | ||
137 | |||
138 | |||
139 | /** | ||
140 | * If we have an active connection to the given target, it must be shutdown. | ||
141 | * | ||
142 | * @param target peer to disconnect from | ||
143 | */ | ||
144 | void | ||
145 | GST_neighbours_force_disconnect (const struct GNUNET_PeerIdentity *target); | ||
146 | |||
147 | |||
148 | /** | ||
149 | * Function called for each connected neighbour. | ||
150 | * | ||
151 | * @param cls closure | ||
152 | * @param neighbour identity of the neighbour | ||
153 | * @param ats performance data | ||
154 | * @param ats_count number of entries in ats (including 0-termination) | ||
155 | * @param transport plugin | ||
156 | * @param addr address | ||
157 | * @param addrlen address length | ||
158 | */ | ||
159 | typedef void (*GST_NeighbourIterator) (void *cls, | ||
160 | const struct GNUNET_PeerIdentity * | ||
161 | neighbour, | ||
162 | const struct | ||
163 | GNUNET_ATS_Information * ats, | ||
164 | uint32_t ats_count, | ||
165 | const char * transport, | ||
166 | const void * addr, | ||
167 | size_t addrlen); | ||
168 | |||
169 | |||
170 | /** | ||
171 | * Iterate over all connected neighbours. | ||
172 | * | ||
173 | * @param cb function to call | ||
174 | * @param cb_cls closure for cb | ||
175 | */ | ||
176 | void | ||
177 | GST_neighbours_iterate (GST_NeighbourIterator cb, void *cb_cls); | ||
178 | |||
179 | |||
180 | /** | ||
181 | * A session was terminated. Take note. | ||
182 | * | ||
183 | * @param peer identity of the peer where the session died | ||
184 | * @param session session that is gone | ||
185 | */ | ||
186 | void | ||
187 | GST_neighbours_session_terminated (const struct GNUNET_PeerIdentity *peer, | ||
188 | struct Session *session); | ||
189 | |||
190 | |||
191 | /** | ||
192 | * For an existing neighbour record, set the active connection to | ||
193 | * use the given address. | ||
194 | * | ||
195 | * @param peer identity of the peer to switch the address for | ||
196 | * @param plugin_name name of transport that delivered the PONG | ||
197 | * @param address address of the other peer, NULL if other peer | ||
198 | * connected to us | ||
199 | * @param address_len number of bytes in address | ||
200 | * @param session session to use (or NULL) | ||
201 | * @param ats performance data | ||
202 | * @param ats_count number of entries in ats | ||
203 | * @param bandwidth_in inbound quota to be used when connection is up | ||
204 | * @param bandwidth_out outbound quota to be used when connection is up | ||
205 | * @return GNUNET_YES if we are currently connected, GNUNET_NO if the | ||
206 | * connection is not up (yet) | ||
207 | */ | ||
208 | int | ||
209 | GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer, | ||
210 | const char *plugin_name, const void *address, | ||
211 | size_t address_len, struct Session *session, | ||
212 | const struct GNUNET_ATS_Information | ||
213 | *ats, uint32_t ats_count, | ||
214 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
215 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out); | ||
216 | |||
217 | |||
218 | /** | ||
219 | * We received a 'SESSION_CONNECT' message from the other peer. | ||
220 | * Consider switching to it. | ||
221 | * | ||
222 | * @param message possibly a 'struct SessionConnectMessage' (check format) | ||
223 | * @param peer identity of the peer to switch the address for | ||
224 | * @param plugin_name name of transport that delivered the PONG | ||
225 | * @param address address of the other peer, NULL if other peer | ||
226 | * connected to us | ||
227 | * @param address_len number of bytes in address | ||
228 | * @param session session to use (or NULL) | ||
229 | * @param ats performance data | ||
230 | * @param ats_count number of entries in ats (excluding 0-termination) | ||
231 | */ | ||
232 | void | ||
233 | GST_neighbours_handle_connect (const struct GNUNET_MessageHeader *message, | ||
234 | const struct GNUNET_PeerIdentity *peer, | ||
235 | const char *plugin_name, | ||
236 | const char *sender_address, uint16_t sender_address_len, | ||
237 | struct Session *session, | ||
238 | const struct GNUNET_ATS_Information *ats, | ||
239 | uint32_t ats_count); | ||
240 | |||
241 | void | ||
242 | GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message, | ||
243 | const struct GNUNET_PeerIdentity *peer, | ||
244 | const char *plugin_name, | ||
245 | const char *sender_address, uint16_t sender_address_len, | ||
246 | struct Session *session, | ||
247 | const struct GNUNET_ATS_Information *ats, | ||
248 | uint32_t ats_count); | ||
249 | |||
250 | void | ||
251 | GST_neighbours_handle_ack (const struct GNUNET_MessageHeader *message, | ||
252 | const struct GNUNET_PeerIdentity *peer, | ||
253 | const char *plugin_name, | ||
254 | const char *sender_address, uint16_t sender_address_len, | ||
255 | struct Session *session, | ||
256 | const struct GNUNET_ATS_Information *ats, | ||
257 | uint32_t ats_count); | ||
258 | |||
259 | /** | ||
260 | * We received a disconnect message from the given peer, | ||
261 | * validate and process. | ||
262 | * | ||
263 | * @param peer sender of the message | ||
264 | * @param msg the disconnect message | ||
265 | */ | ||
266 | void | ||
267 | GST_neighbours_handle_disconnect_message (const struct GNUNET_PeerIdentity *peer, | ||
268 | const struct GNUNET_MessageHeader *msg); | ||
269 | |||
270 | |||
271 | #endif | ||
272 | /* end of file gnunet-service-transport_neighbours.h */ | ||