gnunet-android

GNUnet for Android
Log | Files | Refs | README

gnunet_regex_service.h (6240B)


      1 /*
      2      This file is part of GNUnet
      3      Copyright (C) 2012, 2013 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 Maximilian Szengel
     25  * @author Christian Grothoff
     26  *
     27  * @file
     28  * API to access regex service to advertise capabilities via regex and discover
     29  * respective peers using matching strings
     30  *
     31  * @defgroup regex  RegEx service
     32  * Advertise capabilities via RegEx and discover
     33  * respective peers using matching strings.
     34  *
     35  * @see [Documentation](https://gnunet.org/regex)
     36  *
     37  * @{
     38  */
     39 #ifndef GNUNET_REGEX_SERVICE_H
     40 #define GNUNET_REGEX_SERVICE_H
     41 
     42 
     43 #include "gnunet_util_lib.h"
     44 
     45 #ifdef __cplusplus
     46 extern "C"
     47 {
     48 #if 0                           /* keep Emacsens' auto-indent happy */
     49 }
     50 #endif
     51 #endif
     52 
     53 
     54 /**
     55  * Constant for how many bytes the initial string regex should have.
     56  */
     57 #define GNUNET_REGEX_INITIAL_BYTES 24
     58 
     59 
     60 /**
     61  * Handle to store cached data about a regex announce.
     62  */
     63 struct GNUNET_REGEX_Announcement;
     64 
     65 /**
     66  * Handle to store data about a regex search.
     67  */
     68 struct GNUNET_REGEX_Search;
     69 
     70 
     71 /**
     72  * Announce this peer under the given regular expression.  Does
     73  * not free resources, must call #GNUNET_REGEX_announce_cancel for
     74  * that.
     75  *
     76  * @param cfg configuration to use
     77  * @param regex Regular expression to announce.
     78  * @param refresh_delay after what delay should the announcement be repeated?
     79  * @param compression How many characters per edge can we squeeze?
     80  * @return Handle to reuse o free cached resources.
     81  *         Must be freed by calling #GNUNET_REGEX_announce_cancel.
     82  */
     83 struct GNUNET_REGEX_Announcement *
     84 GNUNET_REGEX_announce (const struct GNUNET_CONFIGURATION_Handle *cfg,
     85                        const char *regex,
     86                        struct GNUNET_TIME_Relative refresh_delay,
     87                        uint16_t compression);
     88 
     89 
     90 /**
     91  * Stop announcing the regex specified by the given handle.
     92  *
     93  * @param a handle returned by a previous #GNUNET_REGEX_announce call.
     94  */
     95 void
     96 GNUNET_REGEX_announce_cancel (struct GNUNET_REGEX_Announcement *a);
     97 
     98 
     99 /**
    100  * Search callback function, invoked for every result that was found.
    101  *
    102  * @param cls Closure provided in #GNUNET_REGEX_search.
    103  * @param id Peer providing a regex that matches the string.
    104  * @param get_path Path of the get request.
    105  * @param get_path_length Length of @a get_path.
    106  * @param put_path Path of the put request.
    107  * @param put_path_length Length of the @a put_path.
    108  */
    109 typedef void
    110 (*GNUNET_REGEX_Found)(void *cls,
    111                       const struct GNUNET_PeerIdentity *id,
    112                       const struct GNUNET_PeerIdentity *get_path,
    113                       unsigned int get_path_length,
    114                       const struct GNUNET_PeerIdentity *put_path,
    115                       unsigned int put_path_length);
    116 
    117 
    118 /**
    119  * Search for a peer offering a regex matching certain string in the DHT.
    120  * The search runs until #GNUNET_REGEX_search_cancel is called, even if results
    121  * are returned.
    122  *
    123  * @param cfg configuration to use
    124  * @param string String to match against the regexes in the DHT.
    125  * @param callback Callback for found peers.
    126  * @param callback_cls Closure for @c callback.
    127  * @return Handle to stop search and free resources.
    128  *         Must be freed by calling #GNUNET_REGEX_search_cancel.
    129  */
    130 struct GNUNET_REGEX_Search *
    131 GNUNET_REGEX_search (const struct GNUNET_CONFIGURATION_Handle *cfg,
    132                      const char *string,
    133                      GNUNET_REGEX_Found callback,
    134                      void *callback_cls);
    135 
    136 
    137 /**
    138  * Stop search and free all data used by a #GNUNET_REGEX_search call.
    139  *
    140  * @param s Handle returned by a previous #GNUNET_REGEX_search call.
    141  */
    142 void
    143 GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_Search *s);
    144 
    145 
    146 /**
    147  * Create a regex in @a rxstr from the given @a ip and @a port.
    148  *
    149  * @param ip IPv4 representation.
    150  * @param port destination port
    151  * @param rxstr generated regex, must be at least #GNUNET_TUN_IPV4_REGEXLEN
    152  *              bytes long.
    153  */
    154 void
    155 GNUNET_REGEX_ipv4toregexsearch (const struct in_addr *ip,
    156                               uint16_t port,
    157                               char *rxstr);
    158 
    159 
    160 /**
    161  * Create a regex in @a rxstr from the given @a ipv6 and @a port.
    162  *
    163  * @param ipv6 IPv6 representation.
    164  * @param port destination port
    165  * @param rxstr generated regex, must be at least #GNUNET_TUN_IPV6_REGEXLEN
    166  *              bytes long.
    167  */
    168 void
    169 GNUNET_REGEX_ipv6toregexsearch (const struct in6_addr *ipv6,
    170                               uint16_t port,
    171                               char *rxstr);
    172 
    173 
    174 /**
    175  * Convert an exit policy to a regular expression.  The exit policy
    176  * specifies a set of subnets this peer is willing to serve as an
    177  * exit for; the resulting regular expression will match the
    178  * IPv6 address strings as returned by #GNUNET_REGEX_ipv6toregexsearch.
    179  *
    180  * @param policy exit policy specification
    181  * @return regular expression, NULL on error
    182  */
    183 char *
    184 GNUNET_REGEX_ipv6policy2regex (const char *policy);
    185 
    186 
    187 /**
    188  * Convert an exit policy to a regular expression.  The exit policy
    189  * specifies a set of subnets this peer is willing to serve as an
    190  * exit for; the resulting regular expression will match the
    191  * IPv4 address strings as returned by #GNUNET_REGEX_ipv4toregexsearch.
    192  *
    193  * @param policy exit policy specification
    194  * @return regular expression, NULL on error
    195  */
    196 char *
    197 GNUNET_REGEX_ipv4policy2regex (const char *policy);
    198 
    199 
    200 #if 0                           /* keep Emacsens' auto-indent happy */
    201 {
    202 #endif
    203 #ifdef __cplusplus
    204 }
    205 #endif
    206 
    207 #endif
    208 
    209 /** @} */  /* end of group */
    210 
    211 /** @} */ /* end of group addition */