2 This file is part of GNUnet.
3 Copyright (C) 2009-2016 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @author Christian Grothoff
23 * API of the transport service towards the communicator processes.
25 * @defgroup transport TRANSPORT service
26 * Low-level communication with other peers
28 * @see [Documentation](https://gnunet.org/transport-service)
33 #ifndef GNUNET_TRANSPORT_COMMUNICATION_SERVICE_H
34 #define GNUNET_TRANSPORT_COMMUNICATION_SERVICE_H
39 #if 0 /* keep Emacsens' auto-indent happy */
44 #include "gnunet_util_lib.h"
47 * Version number of the transport communication API.
49 #define GNUNET_TRANSPORT_COMMUNICATION_VERSION 0x00000000
53 * Function called by the transport service to initialize a
54 * message queue given address information about another peer.
57 * @param peer identity of the other peer
58 * @param address where to send the message, human-readable
59 * communicator-specific format, 0-terminated, UTF-8
60 * @return NULL if the provided address is invalid, otherwise an MQ to
61 * send messages to that peer
63 typedef struct GNUNET_MQ_Handle *
64 (*GNUNET_TRANSPORT_CommunicatorMqInit) (void *cls,
65 const struct GNUNET_PeerIdentity *peer,
70 * Opaque handle to the transport service for communicators.
72 struct GNUNET_TRANSPORT_CommunicatorHandle;
76 * Connect to the transport service.
78 * @param cfg configuration to use
79 * @param name name of the communicator that is connecting
80 * @param mtu maximum message size supported by communicator, 0 if
81 * sending is not supported
82 * @param mq_init function to call to initialize a message queue given
83 * the address of another peer, can be NULL if the
84 * communicator only supports receiving messages
85 * @param mq_init_cls closure for @a mq_init
86 * @return NULL on error
88 struct GNUNET_TRANSPORT_CommunicatorHandle *
89 GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
92 GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
97 * Disconnect from the transport service.
99 * @param ch handle returned from connect
102 GNUNET_TRANSPORT_communicator_disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
105 /* ************************* Receiving *************************** */
108 * Function called to notify communicator that we have received
109 * and processed the message.
112 * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection)
113 * #GNUNET_OK on success
116 (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls,
121 * Notify transport service that the communicator has received
124 * @param handle connection to transport service
125 * @param sender presumed sender of the message (details to be checked
127 * @param msg the message
128 * @param cb function to call once handling the message is done, NULL if
129 * flow control is not supported by this communicator
130 * @param cb_cls closure for @a cb
131 * @return #GNUNET_OK if all is well, #GNUNET_NO if the message was
132 * immediately dropped due to memory limitations (communicator
133 * should try to apply back pressure),
134 * #GNUNET_SYSERR if the message is ill formed and communicator
135 * should try to reset stream
138 GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
139 const struct GNUNET_PeerIdentity *sender,
140 const struct GNUNET_MessageHeader *msg,
141 GNUNET_TRANSPORT_MessageCompletedCallback cb,
145 /* ************************* Discovery *************************** */
149 * Notify transport service that an MQ became available due to an
150 * "inbound" connection or because the communicator discovered the
151 * presence of another peer.
153 * @param handle connection to transport service
154 * @param peer peer with which we can now communicate
155 * @param address address in human-readable format, 0-terminated, UTF-8
156 * @param nt which network type does the @a address belong to?
157 * @param mq message queue of the @a peer
160 GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
161 const struct GNUNET_PeerIdentity *peer,
163 enum GNUNET_ATS_Network_Type nt,
164 struct GNUNET_MQ_Handle *mq);
168 * Notify transport service that an MQ became unavailable due to a
169 * disconnect or timeout.
171 * @param handle connection to transport service
172 * @param peer peer with which we can no longer communicate via the given mq
173 * @param address address in human-readable format, 0-terminated, UTF-8
174 * @param nt which network type does the @a address belong to?
175 * @param mq message queue of the @a peer
178 GNUNET_TRANSPORT_communicator_mq_remove (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
179 const struct GNUNET_PeerIdentity *peer,
181 enum GNUNET_ATS_Network_Type nt,
182 struct GNUNET_MQ_Handle *mq);
186 * Notify transport service about an address that this communicator
187 * provides for this peer.
189 * @param handle connection to transport service
190 * @param address our address in human-readable format, 0-terminated, UTF-8
191 * @param nt which network type does the address belong to?
192 * @param expiration when does the communicator forsee this address expiring?
195 GNUNET_TRANSPORT_communicator_address_add (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
197 enum GNUNET_ATS_Network_Type nt,
198 struct GNUNET_TIME_Absolute expiration);
202 * Notify transport service about an address that this communicator
203 * no longer provides for this peer.
205 * @param handle connection to transport service
206 * @param address our former address in human-readable format,
207 * 0-terminated, in UTF-8
210 GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
211 const char *address);
214 #if 0 /* keep Emacsens' auto-indent happy */
221 /* ifndef GNUNET_TRANSPORT_COMMUNICATOR_SERVICE_H */
224 /** @} */ /* end of group */
226 /* end of gnunet_transport_communicator_service.h */