2 This file is part of GNUnet
3 (C) 2009 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 2, 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/plugin_transport.h
23 * @brief API for the transport services. This header
24 * specifies the struct that is given to the plugin's entry
25 * method and the other struct that must be returned.
26 * Note that the destructors of transport plugins will
27 * be given the value returned by the constructor
28 * and is expected to return a NULL pointer.
31 * - consider moving DATA message (latency measurement)
32 * to service; avoids encapsulation overheads and
33 * would enable latency measurements for non-bidi
37 * @author Christian Grothoff
39 #ifndef PLUGIN_TRANSPORT_H
40 #define PLUGIN_TRANSPORT_H
42 #include "gnunet_configuration_lib.h"
43 #include "gnunet_scheduler_lib.h"
44 #include "gnunet_transport_service.h"
47 * Function called by the transport for each received message.
48 * This function should also be called with "NULL" for the
49 * message to signal that the other peer disconnected.
52 * @param latency estimated latency for communicating with the
53 * given peer; should be set to GNUNET_TIME_UNIT_FOREVER_REL
54 * until the transport has seen messages transmitted in
55 * BOTH directions (and hence been able to do an actual
56 * round-trip observation); a non-FOREVER latency is also used
57 * by the transport to know that communication in both directions
58 * using this one plugin actually works
59 * @param peer (claimed) identity of the other peer
60 * @param message the message, NULL if peer was disconnected
62 typedef void (*GNUNET_TRANSPORT_PluginReceiveCallback) (void *cls,
70 GNUNET_MessageHeader *
75 * Function that will be called if we receive a validation
76 * of an address challenge that we transmitted to another
77 * peer. Note that the validation should only be considered
78 * acceptable if the challenge matches AND if the sender
79 * address is at least a plausible address for this peer
80 * (otherwise we may be seeing a MiM attack).
83 * @param name name of the transport that generated the address
84 * @param peer who responded to our challenge
85 * @param challenge the challenge number we presumably used
86 * @param sender_addr string describing our sender address (as observed
87 * by the other peer in human-readable format)
89 typedef void (*GNUNET_TRANSPORT_ValidationNotification) (void *cls,
101 * Function that will be called for each address the transport
102 * is aware that it might be reachable under.
105 * @param name name of the transport that generated the address
106 * @param addr one of the addresses of the host, NULL for the last address
107 * the specific address format depends on the transport
108 * @param addrlen length of the address
109 * @param expires when should this address automatically expire?
111 typedef void (*GNUNET_TRANSPORT_AddressNotification) (void *cls,
121 * Function that will be called for each address obtained from the HELLO.
124 * @param name name of the transport that generated the address
125 * @param addr one of the addresses of the host, NULL for the last address
126 * the specific address format depends on the transport
127 * @param addrlen length of the address
129 typedef void (*GNUNET_TRANSPORT_AddressCallback) (void *cls,
136 * The transport service will pass a pointer to a struct
137 * of this type as the first and only argument to the
138 * entry point of each transport plugin.
140 struct GNUNET_TRANSPORT_PluginEnvironment
143 * Configuration to use.
145 const struct GNUNET_CONFIGURATION_Handle *cfg;
150 struct GNUNET_SCHEDULER_Handle *sched;
155 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *my_public_key;
160 struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
163 * Identity of this peer.
165 const struct GNUNET_PeerIdentity *my_identity;
168 * Closure for the various callbacks.
173 * Function that should be called by the transport plugin
174 * whenever a message is received.
176 GNUNET_TRANSPORT_PluginReceiveCallback receive;
179 * Function that must be called by each plugin to notify the
180 * transport service about the addresses under which the transport
181 * provided by the plugin can be reached.
183 GNUNET_TRANSPORT_AddressNotification notify_address;
186 * Function that must be called by each plugin to notify the
187 * transport service about a successful validation of an
188 * address of another peer (or at least likely successful
191 GNUNET_TRANSPORT_ValidationNotification notify_validation;
194 * What is the default quota (in terms of incoming bytes per
195 * ms) for new connections?
197 uint32_t default_quota_in;
200 * What is the maximum number of connections that this transport
201 * should allow? Transports that do not have sessions (such as
202 * UDP) can ignore this value.
204 uint32_t max_connections;
210 * Function that can be used by the transport service to validate
211 * the address of another peer. Even if
212 * we already have a connection to this peer, this function is
213 * required to establish a new one.
216 * @param target who should receive this message
217 * @param challenge challenge code to use
218 * @param timeout how long should we try to transmit these?
219 * @param addrlen length of the address
220 * @param addr the address
221 * @return GNUNET_OK on success, GNUNET_SYSERR if the address
225 (*GNUNET_TRANSPORT_ValidationFunction) (void *cls,
227 GNUNET_PeerIdentity * target,
229 struct GNUNET_TIME_Relative
230 timeout, const void *addr,
234 * Function called by the GNUNET_TRANSPORT_TransmitFunction
238 * @param target who was the recipient of the message?
239 * @param result GNUNET_OK on success
240 * GNUNET_SYSERR if the target disconnected;
241 * disconnect will ALSO be signalled using
242 * the ReceiveCallback.
245 (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls,
246 const struct GNUNET_PeerIdentity *
251 * Function that can be used by the transport service to transmit
252 * a message using the plugin. Note that in the case of a
253 * peer disconnecting, the continuation MUST be called
254 * prior to the disconnect notification itself. This function
255 * will be called with this peer's HELLO message to initiate
256 * a fresh connection to another peer.
259 * @param target who should receive this message
260 * @param priority how important is the message?
261 * @param msg the message to transmit
262 * @param timeout how long to wait at most for the transmission
263 * @param cont continuation to call once the message has
264 * been transmitted (or if the transport is ready
265 * for the next transmission call; or if the
266 * peer disconnected...); can be NULL
267 * @param cont_cls closure for cont
270 (*GNUNET_TRANSPORT_TransmitFunction) (void *cls,
271 const struct GNUNET_PeerIdentity *
273 unsigned int priority,
274 const struct GNUNET_MessageHeader *
276 struct GNUNET_TIME_Relative timeout,
277 GNUNET_TRANSPORT_TransmitContinuation
278 cont, void *cont_cls);
282 * Function that can be called to force a disconnect from the
283 * specified neighbour. This should also cancel all previously
284 * scheduled transmissions. Obviously the transmission may have been
285 * partially completed already, which is OK. The plugin is supposed
286 * to close the connection (if applicable) and no longer call the
287 * transmit continuation(s).
289 * Finally, plugin MUST NOT call the services's receive function to
290 * notify the service that the connection to the specified target was
291 * closed after a getting this call.
294 * @param target peer for which the last transmission is
298 (*GNUNET_TRANSPORT_DisconnectFunction) (void *cls,
299 const struct GNUNET_PeerIdentity *
304 * Function called by the pretty printer for the resolved address for
305 * each human-readable address obtained.
308 * @param hostname one of the names for the host, NULL
309 * on the last call to the callback
311 typedef void (*GNUNET_TRANSPORT_AddressStringCallback) (void *cls,
312 const char *address);
316 * Convert the transports address to a nice, human-readable
320 * @param name name of the transport that generated the address
321 * @param addr one of the addresses of the host, NULL for the last address
322 * the specific address format depends on the transport
323 * @param addrlen length of the address
324 * @param numeric should (IP) addresses be displayed in numeric form?
325 * @param timeout after how long should we give up?
326 * @param asc function to call on each string
327 * @param asc_cls closure for asc
330 (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls,
335 struct GNUNET_TIME_Relative
337 GNUNET_TRANSPORT_AddressStringCallback
342 * Set a quota for receiving data from the given peer; this is a
343 * per-transport limit. The transport should limit its read/select
344 * calls to stay below the quota (in terms of incoming data).
347 * @param peer the peer for whom the quota is given
348 * @param quota_in quota for receiving/sending data in bytes per ms
351 (*GNUNET_TRANSPORT_SetQuota) (void *cls,
352 const struct GNUNET_PeerIdentity * target,
357 * Another peer has suggested an address for this
358 * peer and transport plugin. Check that this could be a valid
359 * address. If so, consider adding it to the list
362 * @param addr pointer to the address
363 * @param addrlen length of addr
364 * @return GNUNET_OK if this is a plausible address for this peer
368 (*GNUNET_TRANSPORT_SuggestAddress) (void *cls,
369 const void *addr, size_t addrlen);
372 * Each plugin is required to return a pointer to a struct of this
373 * type as the return value from its entry point.
375 struct GNUNET_TRANSPORT_PluginFunctions
379 * Closure for all of the callbacks.
384 * Function used to send a single message to a particular
385 * peer using the specified address. Used to validate
388 GNUNET_TRANSPORT_ValidationFunction validate;
391 * Function that the transport service will use to transmit data to
392 * another peer. May be null for plugins that only support
393 * receiving data. After this call, the plugin call the specified
394 * continuation with success or error before notifying us about the
395 * target having disconnected.
397 GNUNET_TRANSPORT_TransmitFunction send;
400 * Function that can be used to force the plugin to disconnect from
401 * the given peer and cancel all previous transmissions (and their
402 * continuations). Note that if the transport does not have
403 * sessions / persistent connections (for example, UDP), this
404 * function may very well do nothing.
406 GNUNET_TRANSPORT_DisconnectFunction disconnect;
409 * Function to pretty-print addresses. NOTE: this function is not
410 * yet used by transport-service, but will be used in the future
411 * once the transport-API has been completed.
413 GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer;
416 * Function that the transport service can use to try to enforce a
417 * quota for the number of bytes received via this transport.
418 * Transports that can not refuse incoming data (such as UDP)
419 * are free to ignore these calls.
421 GNUNET_TRANSPORT_SetQuota set_receive_quota;
424 * Function that will be called if another peer suggested that
425 * we should use a particular address (since he is reaching
426 * us at that address) for this transport.
428 GNUNET_TRANSPORT_SuggestAddress address_suggested;
431 * Relative cost of this transport compared to others. This
432 * is supposed to be a static cost estimate which determines
433 * which plugins should not even be attempted if other,
434 * cheaper transports are already working. The idea is that
435 * the costs have roughly this relationship:
437 * TCP < UDP < HTTP == HTTPS < SMTP
440 unsigned int cost_estimate;