gnunet-android

GNUnet for Android
Log | Files | Refs | README

gnunet_transport_communication_service.h (12951B)


      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 (being) 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  * Function to start burst, if request by transport service.
    139  *
    140  * @param address The address to start the burst against.
    141  */
    142 typedef void (*GNUNET_TRANSPORT_StartBurstNotify) (const char *address,
    143                                                    struct GNUNET_TIME_Relative rtt,
    144                                                    struct GNUNET_PeerIdentity *peer);
    145 
    146 /**
    147  * Connect to the transport service.
    148  *
    149  * @param cfg configuration to use
    150  * @param config_section_name section of the configuration to use for
    151  *                            options
    152  * @param addr_prefix address prefix for addresses supported by this
    153  *        communicator, could be NULL for incoming-only communicators
    154  * @param cc what characteristics does the communicator have?
    155  * @param mq_init function to call to initialize a message queue given
    156  *                the address of another peer, can be NULL if the
    157  *                communicator only supports receiving messages
    158  * @param mq_init_cls closure for @a mq_init
    159  * @param notify_cb function to pass backchannel messages to communicator
    160  * @param notify_cb_cls closure for @a notify_cb
    161  * @param sb Function to start burst, if request by transport service.
    162  * @return NULL on error
    163  */
    164 struct GNUNET_TRANSPORT_CommunicatorHandle *
    165 GNUNET_TRANSPORT_communicator_connect (
    166   const struct GNUNET_CONFIGURATION_Handle *cfg,
    167   const char *config_section_name,
    168   const char *addr_prefix,
    169   enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
    170   GNUNET_TRANSPORT_CommunicatorMqInit mq_init,
    171   void *mq_init_cls,
    172   GNUNET_TRANSPORT_CommunicatorNotify notify_cb,
    173   void *notify_cb_cls,
    174   GNUNET_TRANSPORT_StartBurstNotify sb);
    175 
    176 
    177 /**
    178  * Disconnect from the transport service.
    179  *
    180  * @param ch handle returned from connect
    181  */
    182 void
    183 GNUNET_TRANSPORT_communicator_disconnect (
    184   struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
    185 
    186 
    187 /* ************************* Receiving *************************** */
    188 
    189 /**
    190  * Function called to notify communicator that we have received
    191  * and processed the message.  Used for flow control (if supported
    192  * by the communicator).
    193  *
    194  * @param cls closure
    195  * @param success #GNUNET_SYSERR on failure (try to disconnect/reset connection)
    196  *                #GNUNET_OK on success
    197  */
    198 typedef void
    199 (*GNUNET_TRANSPORT_MessageCompletedCallback) (void *cls,
    200                                               int success);
    201 
    202 
    203 /**
    204  * Notify transport service that the communicator has received
    205  * a message.
    206  *
    207  * @param handle connection to transport service
    208  * @param sender presumed sender of the message (details to be checked
    209  *        by higher layers)
    210  * @param msg the message
    211  * @param expected_addr_validity how long does the communicator believe it
    212  *        will continue to be able to receive messages from the same address
    213  *        on which it received this message?
    214  * @param cb function to call once handling the message is done, NULL if
    215  *         flow control is not supported by this communicator
    216  * @param cb_cls closure for @a cb
    217  * @return #GNUNET_OK if all is well, #GNUNET_NO if the message was
    218  *         immediately dropped due to memory limitations (communicator
    219  *         should try to apply back pressure),
    220  *         #GNUNET_SYSERR if the message could not be delivered because
    221  *         the transport service is not yet up
    222  */
    223 int
    224 GNUNET_TRANSPORT_communicator_receive (
    225   struct GNUNET_TRANSPORT_CommunicatorHandle *handle,
    226   const struct GNUNET_PeerIdentity *sender,
    227   const struct GNUNET_MessageHeader *msg,
    228   struct GNUNET_TIME_Relative expected_addr_validity,
    229   GNUNET_TRANSPORT_MessageCompletedCallback cb,
    230   void *cb_cls);
    231 
    232 
    233 /**
    234  * The communicator tells the transport service that it finished the burst.*
    235  * @param handle connection to transport service.
    236  */
    237 void
    238 GNUNET_TRANSPORT_communicator_burst_finished (struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
    239 
    240 /* ************************* Discovery *************************** */
    241 
    242 /**
    243  * Handle returned to identify the internal data structure the transport
    244  * API has created to manage a message queue to a particular peer.
    245  */
    246 struct GNUNET_TRANSPORT_QueueHandle;
    247 
    248 
    249 /**
    250  * Possible states of a connection.
    251  */
    252 enum GNUNET_TRANSPORT_ConnectionStatus
    253 {
    254   /**
    255    * Connection is down.
    256    */
    257   GNUNET_TRANSPORT_CS_DOWN = -1,
    258 
    259   /**
    260    * this is an outbound connection (transport initiated)
    261    */
    262   GNUNET_TRANSPORT_CS_OUTBOUND = 0,
    263 
    264   /**
    265    * this is an inbound connection (communicator initiated)
    266    */
    267   GNUNET_TRANSPORT_CS_INBOUND = 1
    268 };
    269 
    270 
    271 /**
    272  * Notify transport service that a MQ became available due to an
    273  * "inbound" connection or because the communicator discovered the
    274  * presence of another peer.
    275  *
    276  * @param ch connection to transport service
    277  * @param peer peer with which we can now communicate
    278  * @param address address in human-readable format, 0-terminated, UTF-8
    279  * @param mtu maximum message size supported by queue, 0 if
    280  *            sending is not supported, SIZE_MAX for no MTU
    281  * @param q_len number of messages that can be send through this queue
    282  * @param priority queue priority. Queues with highest priority should be
    283  *                 used
    284  * @param nt which network type does the @a address belong to?
    285  * @param cs what is the connection status of the queue?
    286  * @param mq message queue of the @a peer
    287  * @return API handle identifying the new MQ
    288  */
    289 struct GNUNET_TRANSPORT_QueueHandle *
    290 GNUNET_TRANSPORT_communicator_mq_add (
    291   struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
    292   const struct GNUNET_PeerIdentity *peer,
    293   const char *address,
    294   uint32_t mtu,
    295   uint64_t q_len,
    296   uint32_t priority,
    297   enum GNUNET_NetworkType nt,
    298   enum GNUNET_TRANSPORT_ConnectionStatus cs,
    299   struct GNUNET_MQ_Handle *mq);
    300 
    301 /**
    302  * Notify transport service that an MQ was updated
    303  *
    304  * @param ch connection to transport service
    305  * @param u_qh the queue to update
    306  * @param q_len number of messages that can be send through this queue
    307  * @param priority queue priority. Queues with highest priority should be
    308  *                 used
    309  */
    310 void
    311 GNUNET_TRANSPORT_communicator_mq_update (
    312   struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
    313   const struct GNUNET_TRANSPORT_QueueHandle *u_qh,
    314   uint64_t q_len,
    315   uint32_t priority);
    316 
    317 /**
    318  * Notify transport service that an MQ became unavailable due to a
    319  * disconnect or timeout.
    320  *
    321  * @param qh handle for the queue that must be invalidated
    322  */
    323 void
    324 GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh);
    325 
    326 
    327 /**
    328  * Internal representation of an address a communicator is
    329  * currently providing for the transport service.
    330  */
    331 struct GNUNET_TRANSPORT_AddressIdentifier;
    332 
    333 
    334 /**
    335  * Notify transport service about an address that this communicator
    336  * provides for this peer.
    337  *
    338  * @param ch connection to transport service
    339  * @param address our address in human-readable format, 0-terminated, UTF-8
    340  * @param nt which network type does the address belong to?
    341  * @param expiration when does the communicator foresee this address expiring?
    342  */
    343 struct GNUNET_TRANSPORT_AddressIdentifier *
    344 GNUNET_TRANSPORT_communicator_address_add (
    345   struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
    346   const char *address,
    347   enum GNUNET_NetworkType nt,
    348   struct GNUNET_TIME_Relative expiration);
    349 
    350 
    351 /**
    352  * Notify transport service about an address that this communicator
    353  * no longer provides for this peer.
    354  *
    355  * @param ai address that is no longer provided
    356  */
    357 void
    358 GNUNET_TRANSPORT_communicator_address_remove (
    359   struct GNUNET_TRANSPORT_AddressIdentifier *ai);
    360 
    361 /**
    362  * Notify transport service that this communicator no longer provides all its addresses for this peer.
    363  *
    364  * @param ch The communicator handle.
    365  */
    366 void
    367 GNUNET_TRANSPORT_communicator_address_remove_all (
    368                                                   struct GNUNET_TRANSPORT_CommunicatorHandle *ch);
    369 
    370 /**
    371  * The communicator asks the transport service to route a message via
    372  * a different path to another communicator service at another peer.
    373  * This must only be done for special control traffic (as there is no
    374  * flow control for this API), such as acknowledgements, and generally
    375  * only be done if the communicator is uni-directional (i.e. cannot
    376  * send the message back itself).
    377  *
    378  * While backchannel messages are signed and encrypted, communicators
    379  * must protect against replay attacks when using this backchannel
    380  * communication!
    381  *
    382  * @param ch handle of this communicator
    383  * @param pid peer to send the message to
    384  * @param comm name of the communicator to send the message to
    385  * @param header header of the message to transmit and pass via the
    386  *        notify-API to @a pid's communicator @a comm
    387  */
    388 void
    389 GNUNET_TRANSPORT_communicator_notify (
    390   struct GNUNET_TRANSPORT_CommunicatorHandle *ch,
    391   const struct GNUNET_PeerIdentity *pid,
    392   const char *comm,
    393   const struct GNUNET_MessageHeader *header);
    394 
    395 
    396 #if 0 /* keep Emacsens' auto-indent happy */
    397 {
    398 #endif
    399 #ifdef __cplusplus
    400 }
    401 #endif
    402 
    403 /* ifndef GNUNET_TRANSPORT_COMMUNICATOR_SERVICE_H */
    404 #endif
    405 
    406 /** @} */ /* end of group */
    407 
    408 /** @} */ /* end of group addition */
    409 
    410 /* end of gnunet_transport_communicator_service.h */