gnunet-android

GNUnet for Android
Log | Files | Refs | README

gnunet_transport_core_service.h (5871B)


      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  * @addtogroup Backbone
     22  * @{
     23  *
     24  * @author Christian Grothoff
     25  *
     26  * @file
     27  * API of the transport service towards the CORE service (TNG version)
     28  *
     29  * @defgroup TNG Transport Next Generation service
     30  * Communication with other peers
     31  *
     32  * @see [Documentation](https://gnunet.org/transport-service)
     33  *
     34  * @{
     35  */
     36 #ifndef GNUNET_TRANSPORT_CORE_SERVICE_H
     37 #define GNUNET_TRANSPORT_CORE_SERVICE_H
     38 
     39 #ifdef __cplusplus
     40 extern "C" {
     41 #if 0 /* keep Emacsens' auto-indent happy */
     42 }
     43 #endif
     44 #endif
     45 
     46 
     47 #include "gnunet_util_lib.h"
     48 
     49 /**
     50  * Version number of the transport API.
     51  */
     52 #define GNUNET_TRANSPORT_CORE_VERSION 0x00000000
     53 
     54 
     55 /**
     56  * Opaque handle to the service.
     57  */
     58 struct GNUNET_TRANSPORT_CoreHandle;
     59 
     60 
     61 /**
     62  * Function called to notify transport users that another
     63  * peer connected to us.
     64  *
     65  * @param cls closure
     66  * @param peer the identity of the peer that connected; this
     67  *        pointer will remain valid until the disconnect, hence
     68  *        applications do not necessarily have to make a copy
     69  *        of the value if they only need it until disconnect
     70  * @param mq message queue to use to transmit to @a peer
     71  * @return closure to use in MQ handlers
     72  */
     73 typedef void *(*GNUNET_TRANSPORT_NotifyConnect) (
     74   void *cls,
     75   const struct GNUNET_PeerIdentity *peer,
     76   struct GNUNET_MQ_Handle *mq);
     77 
     78 
     79 /**
     80  * Function called to notify transport users that another peer
     81  * disconnected from us.  The message queue that was given to the
     82  * connect notification will be destroyed and must not be used
     83  * henceforth.
     84  *
     85  * @param cls closure from #GNUNET_TRANSPORT_core_connect
     86  * @param peer the peer that disconnected
     87  * @param handlers_cls closure of the handlers, was returned from the
     88  *                    connect notification callback
     89  */
     90 typedef void (*GNUNET_TRANSPORT_NotifyDisconnect) (
     91   void *cls,
     92   const struct GNUNET_PeerIdentity *peer,
     93   void *handler_cls);
     94 
     95 
     96 /**
     97  * Connect to the transport service.  Note that the connection may
     98  * complete (or fail) asynchronously.
     99  *
    100  * @param cfg configuration to use
    101  * @param self our own identity (API should check that it matches
    102  *             the identity found by transport), or NULL (no check)
    103  * @param handlers array of message handlers; note that the
    104  *                 closures provided will be ignored and replaced
    105  *                 with the respective return value from @a nc
    106  * @param handlers array with handlers to call when we receive messages, or NULL
    107  * @param cls closure for the @a nc, @a nd and @a neb callbacks
    108  * @param nc function to call on connect events, or NULL
    109  * @param nd function to call on disconnect events, or NULL
    110  * @param neb function to call if we have excess bandwidth to a peer, or NULL
    111  * @return NULL on error
    112  */
    113 struct GNUNET_TRANSPORT_CoreHandle *
    114 GNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
    115                                const struct GNUNET_PeerIdentity *self,
    116                                const struct GNUNET_MQ_MessageHandler *handlers,
    117                                void *cls,
    118                                GNUNET_TRANSPORT_NotifyConnect nc,
    119                                GNUNET_TRANSPORT_NotifyDisconnect nd);
    120 
    121 
    122 /**
    123  * Disconnect from the transport service.
    124  *
    125  * @param handle handle returned from connect
    126  */
    127 void
    128 GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle);
    129 
    130 
    131 /**
    132  * Notification from the CORE service to the TRANSPORT service
    133  * that the CORE service has finished processing a message from
    134  * TRANSPORT (via the @code{handlers} of #GNUNET_TRANSPORT_core_connect())
    135  * and that it is thus now OK for TRANSPORT to send more messages
    136  * for @a pid.
    137  *
    138  * Used to provide flow control, this is our equivalent to
    139  * #GNUNET_SERVICE_client_continue() of an ordinary service.
    140  *
    141  * Note that due to the use of a window, TRANSPORT may send multiple
    142  * messages destined for the same peer even without an intermediate
    143  * call to this function. However, CORE must still call this function
    144  * once per message received, as otherwise eventually the window will
    145  * be full and TRANSPORT will stop providing messages to CORE for @a
    146  * pid.
    147  *
    148  * @param ch core handle
    149  * @param pid which peer was the message from that was fully processed by CORE
    150  */
    151 void
    152 GNUNET_TRANSPORT_core_receive_continue (struct GNUNET_TRANSPORT_CoreHandle *ch,
    153                                         const struct GNUNET_PeerIdentity *pid);
    154 
    155 
    156 /**
    157  * Checks if a given peer is connected to us and get the message queue.
    158  * Convenience function.
    159  *
    160  * @param handle connection to transport service
    161  * @param peer the peer to check
    162  * @return NULL if disconnected, otherwise message queue for @a peer
    163  */
    164 struct GNUNET_MQ_Handle *
    165 GNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle,
    166                               const struct GNUNET_PeerIdentity *peer);
    167 
    168 
    169 #if 0 /* keep Emacsens' auto-indent happy */
    170 {
    171 #endif
    172 #ifdef __cplusplus
    173 }
    174 #endif
    175 
    176 /* ifndef GNUNET_TRANSPORT_CORE_SERVICE_H */
    177 #endif
    178 
    179 /** @} */ /* end of group */
    180 
    181 /** @} */ /* end of group addition */
    182 
    183 /* end of gnunet_transport_core_service.h */