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 include/gnunet_transport_service.h
23 * @brief low-level P2P IO
24 * @author Christian Grothoff
27 #ifndef GNUNET_TRANSPORT_SERVICE_H
28 #define GNUNET_TRANSPORT_SERVICE_H
33 #if 0 /* keep Emacsens' auto-indent happy */
38 #include "gnunet_configuration_lib.h"
39 #include "gnunet_crypto_lib.h"
40 #include "gnunet_network_lib.h"
41 #include "gnunet_scheduler_lib.h"
42 #include "gnunet_time_lib.h"
45 * Version number of the transport API.
47 #define GNUNET_TRANSPORT_VERSION 0x00000000
50 * Function called by the transport for each received message.
53 * @param latency estimated latency for communicating with the
55 * @param peer (claimed) identity of the other peer
56 * @param message the message
58 typedef void (*GNUNET_TRANSPORT_ReceiveCallback) (void *cls,
59 struct GNUNET_TIME_Relative
62 GNUNET_PeerIdentity * peer,
64 GNUNET_MessageHeader *
69 * Opaque handle to the service.
71 struct GNUNET_TRANSPORT_Handle;
75 * Function called to notify transport users that another
76 * peer connected to us.
79 * @param peer the peer that connected
80 * @param latency current latency of the connection
83 (*GNUNET_TRANSPORT_NotifyConnect) (void *cls,
84 const struct GNUNET_PeerIdentity * peer,
85 struct GNUNET_TIME_Relative latency);
88 * Function called to notify transport users that another
89 * peer disconnected from us.
92 * @param peer the peer that disconnected
95 (*GNUNET_TRANSPORT_NotifyDisconnect) (void *cls,
96 const struct GNUNET_PeerIdentity *
101 * Connect to the transport service. Note that the connection may
102 * complete (or fail) asynchronously.
104 * @param sched scheduler to use
105 * @param cfg configuration to use
106 * @param cls closure for the callbacks
107 * @param rec receive function to call
108 * @param nc function to call on connect events
109 * @param dc function to call on disconnect events
111 struct GNUNET_TRANSPORT_Handle *GNUNET_TRANSPORT_connect (struct
112 GNUNET_SCHEDULER_Handle
115 GNUNET_CONFIGURATION_Handle
117 GNUNET_TRANSPORT_ReceiveCallback
119 GNUNET_TRANSPORT_NotifyConnect
121 GNUNET_TRANSPORT_NotifyDisconnect
126 * Disconnect from the transport service.
128 void GNUNET_TRANSPORT_disconnect (struct GNUNET_TRANSPORT_Handle *handle);
132 * Set the share of incoming/outgoing bandwidth for the given
133 * peer to the specified amount.
135 * @param handle connection to transport service
136 * @param target who's bandwidth quota is being changed
137 * @param quota_in incoming bandwidth quota in bytes per ms; 0 can
138 * be used to force all traffic to be discarded
139 * @param quota_out outgoing bandwidth quota in bytes per ms; 0 can
140 * be used to force all traffic to be discarded
141 * @param timeout how long to wait until signaling failure if
142 * we can not communicate the quota change
143 * @param cont continuation to call when done, will be called
144 * either with reason "TIMEOUT" or with reason "PREREQ_DONE"
145 * @param cont_cls closure for continuation
148 GNUNET_TRANSPORT_set_quota (struct GNUNET_TRANSPORT_Handle *handle,
149 const struct GNUNET_PeerIdentity *target,
152 struct GNUNET_TIME_Relative timeout,
153 GNUNET_SCHEDULER_Task cont, void *cont_cls);
157 * Opaque handle for a transmission-ready request.
159 struct GNUNET_TRANSPORT_TransmitHandle;
163 * Check if we could queue a message of the given size for
164 * transmission. The transport service will take both its
165 * internal buffers and bandwidth limits imposed by the
166 * other peer into consideration when answering this query.
168 * @param handle connection to transport service
169 * @param target who should receive the message
170 * @param size how big is the message we want to transmit?
171 * @param priority how important is the message?
172 * @param timeout after how long should we give up (and call
173 * notify with buf NULL and size 0)?
174 * @param notify function to call when we are ready to
175 * send such a message
176 * @param notify_cls closure for notify
177 * @return NULL if someone else is already waiting to be notified
178 * non-NULL if the notify callback was queued (can be used to cancel
179 * using GNUNET_TRANSPORT_notify_transmit_ready_cancel)
181 struct GNUNET_TRANSPORT_TransmitHandle
182 *GNUNET_TRANSPORT_notify_transmit_ready (struct GNUNET_TRANSPORT_Handle
184 const struct GNUNET_PeerIdentity
185 *target, size_t size,
186 unsigned int priority,
187 struct GNUNET_TIME_Relative
189 GNUNET_NETWORK_TransmitReadyNotify
190 notify, void *notify_cls);
194 * Cancel the specified transmission-ready
198 GNUNET_TRANSPORT_notify_transmit_ready_cancel (struct
199 GNUNET_TRANSPORT_TransmitHandle
204 * Obtain the HELLO message for this peer.
206 * @param handle connection to transport service
207 * @param timeout how long to wait for the HELLO
208 * @param rec function to call with the HELLO, sender will be our peer
209 * identity; message and sender will be NULL on timeout
210 * (handshake with transport service pending/failed).
211 * cost estimate will be 0.
212 * @param rec_cls closure for rec
215 GNUNET_TRANSPORT_get_hello (struct GNUNET_TRANSPORT_Handle *handle,
216 struct GNUNET_TIME_Relative timeout,
217 GNUNET_TRANSPORT_ReceiveCallback rec,
222 * Offer the transport service the HELLO of another peer. Note that
223 * the transport service may just ignore this message if the HELLO is
224 * malformed or useless due to our local configuration.
226 * @param handle connection to transport service
227 * @param hello the hello message
230 GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle,
231 const struct GNUNET_MessageHeader *hello);
234 #if 0 /* keep Emacsens' auto-indent happy */
241 /* ifndef GNUNET_TRANSPORT_SERVICE_H */
243 /* end of gnunet_transport_service.h */