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.
17 * @author Christian Grothoff
20 * API of the transport service towards the communicator processes.
22 * @defgroup transport TRANSPORT service
23 * Low-level communication with other peers
25 * @see [Documentation](https://gnunet.org/transport-service)
30 #ifndef GNUNET_TRANSPORT_COMMUNICATION_SERVICE_H
31 #define GNUNET_TRANSPORT_COMMUNICATION_SERVICE_H
36 #if 0 /* keep Emacsens' auto-indent happy */
41 #include "gnunet_util_lib.h"
44 * Version number of the transport communication API.
46 #define GNUNET_TRANSPORT_COMMUNICATION_VERSION 0x00000000
50 * Function called by the transport service to initialize a
51 * message queue given address information about another peer.
54 * @param peer identity of the other peer
55 * @param address where to send the message, human-readable
56 * communicator-specific format, 0-terminated, UTF-8
57 * @return NULL if the provided address is invalid, otherwise an MQ to
58 * send messages to that peer
60 typedef struct GNUNET_MQ_Handle *
61 (*GNUNET_TRANSPORT_CommunicatorMqInit) (void *cls,
62 const struct GNUNET_PeerIdentity *peer,
67 * Opaque handle to the transport service for communicators.
69 struct GNUNET_TRANSPORT_CommunicatorHandle;
73 * Connect to the transport service.
75 * @param cfg configuration to use
76 * @param name name of the communicator that is connecting
77 * @param mtu maximum message size supported by communicator, 0 if
78 * sending is not supported
79 * @param mq_init function to call to initialize a message queue given
80 * the address of another peer, can be NULL if the
81 * communicator only supports receiving messages
82 * @param mq_init_cls closure for @a mq_init
83 * @return NULL on error
85 struct GNUNET_TRANSPORT_CommunicatorHandle *
86 GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
89 GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
94 * Disconnect from the transport service.
96 * @param ch handle returned from connect
99 GNUNET_TRANSPORT_communicator_disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
102 /* ************************* Receiving *************************** */
105 * Function called to notify communicator that we have received
106 * and processed the message.
109 * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection)
110 * #GNUNET_OK on success
113 (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls,
118 * Notify transport service that the communicator has received
121 * @param handle connection to transport service
122 * @param sender presumed sender of the message (details to be checked
124 * @param msg the message
125 * @param cb function to call once handling the message is done, NULL if
126 * flow control is not supported by this communicator
127 * @param cb_cls closure for @a cb
128 * @return #GNUNET_OK if all is well, #GNUNET_NO if the message was
129 * immediately dropped due to memory limitations (communicator
130 * should try to apply back pressure),
131 * #GNUNET_SYSERR if the message is ill formed and communicator
132 * should try to reset stream
135 GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
136 const struct GNUNET_PeerIdentity *sender,
137 const struct GNUNET_MessageHeader *msg,
138 GNUNET_TRANSPORT_MessageCompletedCallback cb,
142 /* ************************* Discovery *************************** */
146 * Notify transport service that an MQ became available due to an
147 * "inbound" connection or because the communicator discovered the
148 * presence of another peer.
150 * @param handle connection to transport service
151 * @param peer peer with which we can now communicate
152 * @param address address in human-readable format, 0-terminated, UTF-8
153 * @param nt which network type does the @a address belong to?
154 * @param mq message queue of the @a peer
157 GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
158 const struct GNUNET_PeerIdentity *peer,
160 enum GNUNET_ATS_Network_Type nt,
161 struct GNUNET_MQ_Handle *mq);
165 * Notify transport service that an MQ became unavailable due to a
166 * disconnect or timeout.
168 * @param handle connection to transport service
169 * @param peer peer with which we can no longer communicate via the given mq
170 * @param address address in human-readable format, 0-terminated, UTF-8
171 * @param nt which network type does the @a address belong to?
172 * @param mq message queue of the @a peer
175 GNUNET_TRANSPORT_communicator_mq_remove (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
176 const struct GNUNET_PeerIdentity *peer,
178 enum GNUNET_ATS_Network_Type nt,
179 struct GNUNET_MQ_Handle *mq);
183 * Notify transport service about an address that this communicator
184 * provides for this peer.
186 * @param handle connection to transport service
187 * @param address our address in human-readable format, 0-terminated, UTF-8
188 * @param nt which network type does the address belong to?
189 * @param expiration when does the communicator forsee this address expiring?
192 GNUNET_TRANSPORT_communicator_address_add (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
194 enum GNUNET_ATS_Network_Type nt,
195 struct GNUNET_TIME_Absolute expiration);
199 * Notify transport service about an address that this communicator
200 * no longer provides for this peer.
202 * @param handle connection to transport service
203 * @param address our former address in human-readable format,
204 * 0-terminated, in UTF-8
207 GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
208 const char *address);
211 #if 0 /* keep Emacsens' auto-indent happy */
218 /* ifndef GNUNET_TRANSPORT_COMMUNICATOR_SERVICE_H */
221 /** @} */ /* end of group */
223 /* end of gnunet_transport_communicator_service.h */