revert
[oweals/gnunet.git] / src / include / gnunet_transport_communication_service.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009-2016 GNUnet e.V.
4
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.
9
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.
14     
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/>.
17 */
18
19 /**
20  * @author Christian Grothoff
21  *
22  * @file
23  * API of the transport service towards the communicator processes.
24  *
25  * @defgroup transport TRANSPORT service
26  * Low-level communication with other peers
27  *
28  * @see [Documentation](https://gnunet.org/transport-service)
29  *
30  * @{
31  */
32
33 #ifndef GNUNET_TRANSPORT_COMMUNICATION_SERVICE_H
34 #define GNUNET_TRANSPORT_COMMUNICATION_SERVICE_H
35
36 #ifdef __cplusplus
37 extern "C"
38 {
39 #if 0                           /* keep Emacsens' auto-indent happy */
40 }
41 #endif
42 #endif
43
44 #include "gnunet_util_lib.h"
45
46 /**
47  * Version number of the transport communication API.
48  */
49 #define GNUNET_TRANSPORT_COMMUNICATION_VERSION 0x00000000
50
51
52 /**
53  * Function called by the transport service to initialize a
54  * message queue given address information about another peer.
55  *
56  * @param cls closure
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
62  */
63 typedef struct GNUNET_MQ_Handle *
64 (*GNUNET_TRANSPORT_CommunicatorMqInit) (void *cls,
65                                         const struct GNUNET_PeerIdentity *peer,
66                                         const void *address);
67
68
69 /**
70  * Opaque handle to the transport service for communicators.
71  */
72 struct GNUNET_TRANSPORT_CommunicatorHandle;
73
74
75 /**
76  * Connect to the transport service.
77  *
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
87  */
88 struct GNUNET_TRANSPORT_CommunicatorHandle *
89 GNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
90                                        const char *name,
91                                        size_t mtu,
92                                        GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
93                                        void *mq_init_cls);
94
95
96 /**
97  * Disconnect from the transport service.
98  *
99  * @param ch handle returned from connect
100  */
101 void
102 GNUNET_TRANSPORT_communicator_disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
103
104
105 /* ************************* Receiving *************************** */
106
107 /**
108  * Function called to notify communicator that we have received
109  * and processed the message.
110  *
111  * @param cls closure
112  * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection)
113  *                #GNUNET_OK on success
114  */
115 typedef void
116 (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls,
117                                               int success);
118
119
120 /**
121  * Notify transport service that the communicator has received
122  * a message.
123  *
124  * @param handle connection to transport service
125  * @param sender presumed sender of the message (details to be checked
126  *        by higher layers)
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
136  */
137 int
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,
142                                        void *cb_cls);
143
144
145 /* ************************* Discovery *************************** */
146
147
148 /**
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.
152  *
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
158  */
159 void
160 GNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
161                                       const struct GNUNET_PeerIdentity *peer,
162                                       const char *address,
163                                       enum GNUNET_ATS_Network_Type nt,
164                                       struct GNUNET_MQ_Handle *mq);
165
166
167 /**
168  * Notify transport service that an MQ became unavailable due to a
169  * disconnect or timeout.
170  *
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
176  */
177 void
178 GNUNET_TRANSPORT_communicator_mq_remove (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
179                                          const struct GNUNET_PeerIdentity *peer,
180                                          const char *address,
181                                          enum GNUNET_ATS_Network_Type nt,
182                                          struct GNUNET_MQ_Handle *mq);
183
184
185 /**
186  * Notify transport service about an address that this communicator
187  * provides for this peer.
188  *
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?
193  */
194 void
195 GNUNET_TRANSPORT_communicator_address_add (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
196                                            const char *address,
197                                            enum GNUNET_ATS_Network_Type nt,
198                                            struct GNUNET_TIME_Absolute expiration);
199
200
201 /**
202  * Notify transport service about an address that this communicator
203  * no longer provides for this peer.
204  *
205  * @param handle connection to transport service
206  * @param address our former address in human-readable format,
207  *        0-terminated, in UTF-8
208  */
209 void
210 GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
211                                               const char *address);
212
213
214 #if 0                           /* keep Emacsens' auto-indent happy */
215 {
216 #endif
217 #ifdef __cplusplus
218 }
219 #endif
220
221 /* ifndef GNUNET_TRANSPORT_COMMUNICATOR_SERVICE_H */
222 #endif
223
224 /** @} */  /* end of group */
225
226 /* end of gnunet_transport_communicator_service.h */