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,
63 struct GNUNET_TIME_Relative
65 const struct GNUNET_PeerIdentity
67 const struct GNUNET_MessageHeader
72 * Function that will be called if we receive a validation
73 * of an address challenge that we transmitted to another
74 * peer. Note that the validation should only be considered
75 * acceptable if the challenge matches AND if the sender
76 * address is at least a plausible address for this peer
77 * (otherwise we may be seeing a MiM attack).
80 * @param name name of the transport that generated the address
81 * @param peer who responded to our challenge
82 * @param challenge the challenge number we presumably used
83 * @param sender_addr string describing our sender address (as observed
84 * by the other peer in human-readable format)
86 typedef void (*GNUNET_TRANSPORT_ValidationNotification) (void *cls,
88 const struct GNUNET_PeerIdentity *peer,
90 const char *sender_addr);
95 * Function that will be called for each address the transport
96 * is aware that it might be reachable under.
99 * @param name name of the transport that generated the address
100 * @param addr one of the addresses of the host, NULL for the last address
101 * the specific address format depends on the transport
102 * @param addrlen length of the address
103 * @param expires when should this address automatically expire?
105 typedef void (*GNUNET_TRANSPORT_AddressNotification) (void *cls,
115 * Function that will be called for each address obtained from the HELLO.
118 * @param name name of the transport that generated the address
119 * @param addr one of the addresses of the host, NULL for the last address
120 * the specific address format depends on the transport
121 * @param addrlen length of the address
123 typedef void (*GNUNET_TRANSPORT_AddressCallback) (void *cls,
130 * The transport service will pass a pointer to a struct
131 * of this type as the first and only argument to the
132 * entry point of each transport plugin.
134 struct GNUNET_TRANSPORT_PluginEnvironment
137 * Configuration to use.
139 const struct GNUNET_CONFIGURATION_Handle *cfg;
144 struct GNUNET_SCHEDULER_Handle *sched;
149 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *my_public_key;
154 struct GNUNET_CRYPTO_RsaPrivateKey *my_private_key;
157 * Identity of this peer.
159 const struct GNUNET_PeerIdentity *my_identity;
162 * Closure for the various callbacks.
167 * Function that should be called by the transport plugin
168 * whenever a message is received.
170 GNUNET_TRANSPORT_PluginReceiveCallback receive;
173 * Function that must be called by each plugin to notify the
174 * transport service about the addresses under which the transport
175 * provided by the plugin can be reached.
177 GNUNET_TRANSPORT_AddressNotification notify_address;
180 * Function that must be called by each plugin to notify the
181 * transport service about a successful validation of an
182 * address of another peer (or at least likely successful
185 GNUNET_TRANSPORT_ValidationNotification notify_validation;
188 * What is the default quota (in terms of incoming bytes per
189 * ms) for new connections?
191 uint32_t default_quota_in;
194 * What is the maximum number of connections that this transport
195 * should allow? Transports that do not have sessions (such as
196 * UDP) can ignore this value.
198 uint32_t max_connections;
204 * Function that can be used by the transport service to validate
205 * the address of another peer. Even if
206 * we already have a connection to this peer, this function is
207 * required to establish a new one.
210 * @param target who should receive this message
211 * @param challenge challenge code to use
212 * @param timeout how long should we try to transmit these?
213 * @param addrlen length of the address
214 * @param addr the address
215 * @return GNUNET_OK on success, GNUNET_SYSERR if the address
219 (*GNUNET_TRANSPORT_ValidationFunction) (void *cls,
221 GNUNET_PeerIdentity * target,
223 struct GNUNET_TIME_Relative
224 timeout, const void *addr,
228 * Function called by the GNUNET_TRANSPORT_TransmitFunction
232 * @param target who was the recipient of the message?
233 * @param result GNUNET_OK on success
234 * GNUNET_SYSERR if the target disconnected;
235 * disconnect will ALSO be signalled using
236 * the ReceiveCallback.
239 (*GNUNET_TRANSPORT_TransmitContinuation) (void *cls,
240 const struct GNUNET_PeerIdentity *
245 * Function that can be used by the transport service to transmit
246 * a message using the plugin. Note that in the case of a
247 * peer disconnecting, the continuation MUST be called
248 * prior to the disconnect notification itself. This function
249 * will be called with this peer's HELLO message to initiate
250 * a fresh connection to another peer.
253 * @param target who should receive this message
254 * @param priority how important is the message?
255 * @param msg the message to transmit
256 * @param timeout how long to wait at most for the transmission
257 * @param cont continuation to call once the message has
258 * been transmitted (or if the transport is ready
259 * for the next transmission call; or if the
260 * peer disconnected...); can be NULL
261 * @param cont_cls closure for cont
264 (*GNUNET_TRANSPORT_TransmitFunction) (void *cls,
265 const struct GNUNET_PeerIdentity *
267 unsigned int priority,
268 const struct GNUNET_MessageHeader *
270 struct GNUNET_TIME_Relative timeout,
271 GNUNET_TRANSPORT_TransmitContinuation
272 cont, void *cont_cls);
276 * Function that can be called to force a disconnect from the
277 * specified neighbour. This should also cancel all previously
278 * scheduled transmissions. Obviously the transmission may have been
279 * partially completed already, which is OK. The plugin is supposed
280 * to close the connection (if applicable) and no longer call the
281 * transmit continuation(s).
283 * Finally, plugin MUST NOT call the services's receive function to
284 * notify the service that the connection to the specified target was
285 * closed after a getting this call.
288 * @param target peer for which the last transmission is
292 (*GNUNET_TRANSPORT_DisconnectFunction) (void *cls,
293 const struct GNUNET_PeerIdentity *
298 * Function called by the pretty printer for the resolved address for
299 * each human-readable address obtained.
302 * @param hostname one of the names for the host, NULL
303 * on the last call to the callback
305 typedef void (*GNUNET_TRANSPORT_AddressStringCallback) (void *cls,
306 const char *address);
310 * Convert the transports address to a nice, human-readable
314 * @param name name of the transport that generated the address
315 * @param addr one of the addresses of the host, NULL for the last address
316 * the specific address format depends on the transport
317 * @param addrlen length of the address
318 * @param numeric should (IP) addresses be displayed in numeric form?
319 * @param timeout after how long should we give up?
320 * @param asc function to call on each string
321 * @param asc_cls closure for asc
324 (*GNUNET_TRANSPORT_AddressPrettyPrinter) (void *cls,
329 struct GNUNET_TIME_Relative
331 GNUNET_TRANSPORT_AddressStringCallback
336 * Set a quota for receiving data from the given peer; this is a
337 * per-transport limit. The transport should limit its read/select
338 * calls to stay below the quota (in terms of incoming data).
341 * @param peer the peer for whom the quota is given
342 * @param quota_in quota for receiving/sending data in bytes per ms
345 (*GNUNET_TRANSPORT_SetQuota) (void *cls,
346 const struct GNUNET_PeerIdentity * target,
351 * Another peer has suggested an address for this
352 * peer and transport plugin. Check that this could be a valid
353 * address. If so, consider adding it to the list
356 * @param addr pointer to the address
357 * @param addrlen length of addr
358 * @return GNUNET_OK if this is a plausible address for this peer
362 (*GNUNET_TRANSPORT_SuggestAddress) (void *cls,
363 const void *addr, size_t addrlen);
366 * Each plugin is required to return a pointer to a struct of this
367 * type as the return value from its entry point.
369 struct GNUNET_TRANSPORT_PluginFunctions
373 * Closure for all of the callbacks.
378 * Function used to send a single message to a particular
379 * peer using the specified address. Used to validate
382 GNUNET_TRANSPORT_ValidationFunction validate;
385 * Function that the transport service will use to transmit data to
386 * another peer. May be null for plugins that only support
387 * receiving data. After this call, the plugin call the specified
388 * continuation with success or error before notifying us about the
389 * target having disconnected.
391 GNUNET_TRANSPORT_TransmitFunction send;
394 * Function that can be used to force the plugin to disconnect from
395 * the given peer and cancel all previous transmissions (and their
396 * continuations). Note that if the transport does not have
397 * sessions / persistent connections (for example, UDP), this
398 * function may very well do nothing.
400 GNUNET_TRANSPORT_DisconnectFunction disconnect;
403 * Function to pretty-print addresses. NOTE: this function is not
404 * yet used by transport-service, but will be used in the future
405 * once the transport-API has been completed.
407 GNUNET_TRANSPORT_AddressPrettyPrinter address_pretty_printer;
410 * Function that the transport service can use to try to enforce a
411 * quota for the number of bytes received via this transport.
412 * Transports that can not refuse incoming data (such as UDP)
413 * are free to ignore these calls.
415 GNUNET_TRANSPORT_SetQuota set_receive_quota;
418 * Function that will be called if another peer suggested that
419 * we should use a particular address (since he is reaching
420 * us at that address) for this transport.
422 GNUNET_TRANSPORT_SuggestAddress address_suggested;
425 * Relative cost of this transport compared to others. This
426 * is supposed to be a static cost estimate which determines
427 * which plugins should not even be attempted if other,
428 * cheaper transports are already working. The idea is that
429 * the costs have roughly this relationship:
431 * TCP < UDP < HTTP == HTTPS < SMTP
434 unsigned int cost_estimate;