gnunet_transport_communication_service.h (12231B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2009-2019 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 SPDX-License-Identifier: AGPL3.0-or-later 19 */ 20 21 /** 22 * @addtogroup Backbone 23 * @{ 24 * 25 * @author Christian Grothoff 26 * 27 * @file 28 * API of the transport service towards the communicator processes. 29 * 30 * @defgroup TNG Transport Next Generation service 31 * Low-level communication with other peers 32 * 33 * @see [Documentation](https://gnunet.org/transport-service) 34 * 35 * @{ 36 */ 37 38 #ifndef GNUNET_TRANSPORT_COMMUNICATION_SERVICE_H 39 #define GNUNET_TRANSPORT_COMMUNICATION_SERVICE_H 40 41 #ifdef __cplusplus 42 extern "C" { 43 #if 0 /* keep Emacsens' auto-indent happy */ 44 } 45 #endif 46 #endif 47 48 49 #include "gnunet_util_lib.h" 50 51 /** 52 * Version number of the transport communication API. 53 */ 54 #define GNUNET_TRANSPORT_COMMUNICATION_VERSION 0x00000000 55 56 /** 57 * Queue length 58 */ 59 #define GNUNET_TRANSPORT_QUEUE_LENGTH_UNLIMITED UINT64_MAX 60 61 /** 62 * Function called by the transport service to initialize a 63 * message queue given address information about another peer. 64 * If and when the communication channel is established, the 65 * communicator must call #GNUNET_TRANSPORT_communicator_mq_add() 66 * to notify the service that the channel is now up. It is 67 * the responsibility of the communicator to manage sane 68 * retries and timeouts for any @a peer/@a address combination 69 * provided by the transport service. Timeouts and retries 70 * do not need to be signalled to the transport service. 71 * 72 * @param cls closure 73 * @param peer identity of the other peer 74 * @param address where to send the message, human-readable 75 * communicator-specific format, 0-terminated, UTF-8 76 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is 77 * invalid, #GNUNET_NO if this address is already (beging) connected to. 78 */ 79 typedef int (*GNUNET_TRANSPORT_CommunicatorMqInit) ( 80 void *cls, 81 const struct GNUNET_PeerIdentity *peer, 82 const char *address); 83 84 85 /** 86 * Opaque handle to the transport service for communicators. 87 */ 88 struct GNUNET_TRANSPORT_CommunicatorHandle; 89 90 91 /** 92 * What characteristics does this communicator have? 93 * 94 * FIXME: may want to distinguish bi-directional as well, 95 * should we define a bit for that? Needed in DV logic (handle_dv_learn)! 96 */ 97 enum GNUNET_TRANSPORT_CommunicatorCharacteristics 98 { 99 /** 100 * Characteristics are unknown (e.g. DV). 101 */ 102 GNUNET_TRANSPORT_CC_UNKNOWN = 0, 103 104 /** 105 * Transmission is reliabile (with ACKs), e.g. TCP/HTTP/HTTPS. 106 */ 107 GNUNET_TRANSPORT_CC_RELIABLE = 1, 108 109 /** 110 * Transmission is unreliable (e.g. UDP) 111 */ 112 GNUNET_TRANSPORT_CC_UNRELIABLE = 2 113 }; 114 115 116 /** 117 * Function called when the transport service has received a 118 * backchannel message for this communicator (!) via a different 119 * return path. 120 * 121 * Typically used to receive messages of type 122 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_FC_LIMITS or 123 * #GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_KX_CONFIRMATION 124 * as well as communicator-specific messages to assist with 125 * NAT traversal. 126 * 127 * @param cls closure 128 * @param sender which peer sent the notification 129 * @param msg payload 130 */ 131 typedef void (*GNUNET_TRANSPORT_CommunicatorNotify) ( 132 void *cls, 133 const struct GNUNET_PeerIdentity *sender, 134 const struct GNUNET_MessageHeader *msg); 135 136 137 /** 138 * Connect to the transport service. 139 * 140 * @param cfg configuration to use 141 * @param config_section_name section of the configuration to use for 142 * options 143 * @param addr_prefix address prefix for addresses supported by this 144 * communicator, could be NULL for incoming-only communicators 145 * @param cc what characteristics does the communicator have? 146 * @param mq_init function to call to initialize a message queue given 147 * the address of another peer, can be NULL if the 148 * communicator only supports receiving messages 149 * @param mq_init_cls closure for @a mq_init 150 * @param notify_cb function to pass backchannel messages to communicator 151 * @param notify_cb_cls closure for @a notify_cb 152 * @return NULL on error 153 */ 154 struct GNUNET_TRANSPORT_CommunicatorHandle * 155 GNUNET_TRANSPORT_communicator_connect ( 156 const struct GNUNET_CONFIGURATION_Handle *cfg, 157 const char *config_section_name, 158 const char *addr_prefix, 159 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, 160 GNUNET_TRANSPORT_CommunicatorMqInit mq_init, 161 void *mq_init_cls, 162 GNUNET_TRANSPORT_CommunicatorNotify notify_cb, 163 void *notify_cb_cls); 164 165 166 /** 167 * Disconnect from the transport service. 168 * 169 * @param ch handle returned from connect 170 */ 171 void 172 GNUNET_TRANSPORT_communicator_disconnect ( 173 struct GNUNET_TRANSPORT_CommunicatorHandle *ch); 174 175 176 /* ************************* Receiving *************************** */ 177 178 /** 179 * Function called to notify communicator that we have received 180 * and processed the message. Used for flow control (if supported 181 * by the communicator). 182 * 183 * @param cls closure 184 * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection) 185 * #GNUNET_OK on success 186 */ 187 typedef void 188 (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls, 189 int success); 190 191 192 /** 193 * Notify transport service that the communicator has received 194 * a message. 195 * 196 * @param handle connection to transport service 197 * @param sender presumed sender of the message (details to be checked 198 * by higher layers) 199 * @param msg the message 200 * @param expected_addr_validity how long does the communicator believe it 201 * will continue to be able to receive messages from the same address 202 * on which it received this message? 203 * @param cb function to call once handling the message is done, NULL if 204 * flow control is not supported by this communicator 205 * @param cb_cls closure for @a cb 206 * @return #GNUNET_OK if all is well, #GNUNET_NO if the message was 207 * immediately dropped due to memory limitations (communicator 208 * should try to apply back pressure), 209 * #GNUNET_SYSERR if the message could not be delivered because 210 * the transport service is not yet up 211 */ 212 int 213 GNUNET_TRANSPORT_communicator_receive ( 214 struct GNUNET_TRANSPORT_CommunicatorHandle *handle, 215 const struct GNUNET_PeerIdentity *sender, 216 const struct GNUNET_MessageHeader *msg, 217 struct GNUNET_TIME_Relative expected_addr_validity, 218 GNUNET_TRANSPORT_MessageCompletedCallback cb, 219 void *cb_cls); 220 221 222 /* ************************* Discovery *************************** */ 223 224 /** 225 * Handle returned to identify the internal data structure the transport 226 * API has created to manage a message queue to a particular peer. 227 */ 228 struct GNUNET_TRANSPORT_QueueHandle; 229 230 231 /** 232 * Possible states of a connection. 233 */ 234 enum GNUNET_TRANSPORT_ConnectionStatus 235 { 236 /** 237 * Connection is down. 238 */ 239 GNUNET_TRANSPORT_CS_DOWN = -1, 240 241 /** 242 * this is an outbound connection (transport initiated) 243 */ 244 GNUNET_TRANSPORT_CS_OUTBOUND = 0, 245 246 /** 247 * this is an inbound connection (communicator initiated) 248 */ 249 GNUNET_TRANSPORT_CS_INBOUND = 1 250 }; 251 252 253 /** 254 * Notify transport service that a MQ became available due to an 255 * "inbound" connection or because the communicator discovered the 256 * presence of another peer. 257 * 258 * @param ch connection to transport service 259 * @param peer peer with which we can now communicate 260 * @param address address in human-readable format, 0-terminated, UTF-8 261 * @param mtu maximum message size supported by queue, 0 if 262 * sending is not supported, SIZE_MAX for no MTU 263 * @param q_len number of messages that can be send through this queue 264 * @param priority queue priority. Queues with highest priority should be 265 * used 266 * @param nt which network type does the @a address belong to? 267 * @param cs what is the connection status of the queue? 268 * @param mq message queue of the @a peer 269 * @return API handle identifying the new MQ 270 */ 271 struct GNUNET_TRANSPORT_QueueHandle * 272 GNUNET_TRANSPORT_communicator_mq_add ( 273 struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 274 const struct GNUNET_PeerIdentity *peer, 275 const char *address, 276 uint32_t mtu, 277 uint64_t q_len, 278 uint32_t priority, 279 enum GNUNET_NetworkType nt, 280 enum GNUNET_TRANSPORT_ConnectionStatus cs, 281 struct GNUNET_MQ_Handle *mq); 282 283 /** 284 * Notify transport service that an MQ was updated 285 * 286 * @param ch connection to transport service 287 * @param u_qh the queue to update 288 * @param q_len number of messages that can be send through this queue 289 * @param priority queue priority. Queues with highest priority should be 290 * used 291 */ 292 void 293 GNUNET_TRANSPORT_communicator_mq_update ( 294 struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 295 const struct GNUNET_TRANSPORT_QueueHandle *u_qh, 296 uint64_t q_len, 297 uint32_t priority); 298 299 /** 300 * Notify transport service that an MQ became unavailable due to a 301 * disconnect or timeout. 302 * 303 * @param qh handle for the queue that must be invalidated 304 */ 305 void 306 GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh); 307 308 309 /** 310 * Internal representation of an address a communicator is 311 * currently providing for the transport service. 312 */ 313 struct GNUNET_TRANSPORT_AddressIdentifier; 314 315 316 /** 317 * Notify transport service about an address that this communicator 318 * provides for this peer. 319 * 320 * @param ch connection to transport service 321 * @param address our address in human-readable format, 0-terminated, UTF-8 322 * @param nt which network type does the address belong to? 323 * @param expiration when does the communicator forsee this address expiring? 324 */ 325 struct GNUNET_TRANSPORT_AddressIdentifier * 326 GNUNET_TRANSPORT_communicator_address_add ( 327 struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 328 const char *address, 329 enum GNUNET_NetworkType nt, 330 struct GNUNET_TIME_Relative expiration); 331 332 333 /** 334 * Notify transport service about an address that this communicator 335 * no longer provides for this peer. 336 * 337 * @param ai address that is no longer provided 338 */ 339 void 340 GNUNET_TRANSPORT_communicator_address_remove ( 341 struct GNUNET_TRANSPORT_AddressIdentifier *ai); 342 343 /** 344 * Notify transport service that this communicator no longer provides all its addresses for this peer. 345 * 346 * @param ch The communicator handle. 347 */ 348 void 349 GNUNET_TRANSPORT_communicator_address_remove_all ( 350 struct GNUNET_TRANSPORT_CommunicatorHandle *ch); 351 352 /** 353 * The communicator asks the transport service to route a message via 354 * a different path to another communicator service at another peer. 355 * This must only be done for special control traffic (as there is no 356 * flow control for this API), such as acknowledgements, and generally 357 * only be done if the communicator is uni-directional (i.e. cannot 358 * send the message back itself). 359 * 360 * While backchannel messages are signed and encrypted, communicators 361 * must protect against replay attacks when using this backchannel 362 * communication! 363 * 364 * @param ch handle of this communicator 365 * @param pid peer to send the message to 366 * @param comm name of the communicator to send the message to 367 * @param header header of the message to transmit and pass via the 368 * notify-API to @a pid's communicator @a comm 369 */ 370 void 371 GNUNET_TRANSPORT_communicator_notify ( 372 struct GNUNET_TRANSPORT_CommunicatorHandle *ch, 373 const struct GNUNET_PeerIdentity *pid, 374 const char *comm, 375 const struct GNUNET_MessageHeader *header); 376 377 378 #if 0 /* keep Emacsens' auto-indent happy */ 379 { 380 #endif 381 #ifdef __cplusplus 382 } 383 #endif 384 385 /* ifndef GNUNET_TRANSPORT_COMMUNICATOR_SERVICE_H */ 386 #endif 387 388 /** @} */ /* end of group */ 389 390 /** @} */ /* end of group addition */ 391 392 /* end of gnunet_transport_communicator_service.h */