GNUnet 0.22.2
RegEx service

Advertise capabilities via RegEx and discover respective peers using matching strings. More...

Collaboration diagram for RegEx service:

Macros

#define GNUNET_REGEX_INITIAL_BYTES   24
 Constant for how many bytes the initial string regex should have. More...
 

Typedefs

typedef void(* GNUNET_REGEX_Found) (void *cls, const struct GNUNET_PeerIdentity *id, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length)
 Search callback function, invoked for every result that was found. More...
 

Functions

struct GNUNET_REGEX_AnnouncementGNUNET_REGEX_announce (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *regex, struct GNUNET_TIME_Relative refresh_delay, uint16_t compression)
 Announce this peer under the given regular expression. More...
 
void GNUNET_REGEX_announce_cancel (struct GNUNET_REGEX_Announcement *a)
 Stop announcing the regex specified by the given handle. More...
 
struct GNUNET_REGEX_SearchGNUNET_REGEX_search (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *string, GNUNET_REGEX_Found callback, void *callback_cls)
 Search for a peer offering a regex matching certain string in the DHT. More...
 
void GNUNET_REGEX_search_cancel (struct GNUNET_REGEX_Search *s)
 Stop search and free all data used by a GNUNET_REGEX_search call. More...
 
void GNUNET_REGEX_ipv4toregexsearch (const struct in_addr *ip, uint16_t port, char *rxstr)
 Create a regex in rxstr from the given ip and port. More...
 
void GNUNET_REGEX_ipv6toregexsearch (const struct in6_addr *ipv6, uint16_t port, char *rxstr)
 Create a regex in rxstr from the given ipv6 and port. More...
 
char * GNUNET_REGEX_ipv6policy2regex (const char *policy)
 Convert an exit policy to a regular expression. More...
 
char * GNUNET_REGEX_ipv4policy2regex (const char *policy)
 Convert an exit policy to a regular expression. More...
 

Detailed Description

Advertise capabilities via RegEx and discover respective peers using matching strings.

See also
Documentation

Macro Definition Documentation

◆ GNUNET_REGEX_INITIAL_BYTES

#define GNUNET_REGEX_INITIAL_BYTES   24

Constant for how many bytes the initial string regex should have.

Definition at line 57 of file gnunet_regex_service.h.

Typedef Documentation

◆ GNUNET_REGEX_Found

typedef void(* GNUNET_REGEX_Found) (void *cls, const struct GNUNET_PeerIdentity *id, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length)

Search callback function, invoked for every result that was found.

Parameters
clsClosure provided in GNUNET_REGEX_search.
idPeer providing a regex that matches the string.
get_pathPath of the get request.
get_path_lengthLength of get_path.
put_pathPath of the put request.
put_path_lengthLength of the put_path.

Definition at line 109 of file gnunet_regex_service.h.

Function Documentation

◆ GNUNET_REGEX_announce()

struct GNUNET_REGEX_Announcement * GNUNET_REGEX_announce ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  regex,
struct GNUNET_TIME_Relative  refresh_delay,
uint16_t  compression 
)

Announce this peer under the given regular expression.

Does not free resources, must call GNUNET_REGEX_announce_cancel for that.

Parameters
cfgconfiguration to use
regexRegular expression to announce.
refresh_delayafter what delay should the announcement be repeated?
compressionHow many characters per edge can we squeeze?
Returns
Handle to reuse o free cached resources. Must be freed by calling GNUNET_REGEX_announce_cancel.

Announce this peer under the given regular expression.

Parameters
cfgconfiguration to use
regexRegular expression to announce.
refresh_delayafter what delay should the announcement be repeated?
compressionHow many characters per edge can we squeeze?
Returns
Handle to reuse o free cached resources. Must be freed by calling GNUNET_REGEX_announce_cancel().

Definition at line 139 of file regex_api_announce.c.

143{
145 size_t slen;
146
147 slen = strlen (regex) + 1;
148 if (slen + sizeof(struct AnnounceMessage) >= GNUNET_MAX_MESSAGE_SIZE)
149 {
151 _ ("Regex `%s' is too long!\n"),
152 regex);
153 GNUNET_break (0);
154 return NULL;
155 }
157 a->cfg = cfg;
162 if (NULL == a->mq)
163 {
164 GNUNET_free (a->regex);
165 GNUNET_free (a);
166 return NULL;
167 }
168 return a;
169}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
#define GNUNET_log(kind,...)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static void announce_reconnect(struct GNUNET_REGEX_Announcement *a)
(Re)connect to the REGEX service with the given announcement a.
Request for regex service to announce capability.
Definition: regex_ipc.h:35
Handle to store cached data about a regex announce.
char * regex
Message we're sending to the service.
uint16_t compression
Number of characters per edge.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_MQ_Handle * mq
Connection to the regex service.
struct GNUNET_TIME_Relative refresh_delay
Frequency of announcements.

References _, announce_reconnect(), cfg, GNUNET_REGEX_Announcement::cfg, GNUNET_REGEX_Announcement::compression, GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_new, GNUNET_strdup, GNUNET_REGEX_Announcement::mq, GNUNET_REGEX_Announcement::refresh_delay, and GNUNET_REGEX_Announcement::regex.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REGEX_announce_cancel()

void GNUNET_REGEX_announce_cancel ( struct GNUNET_REGEX_Announcement a)

Stop announcing the regex specified by the given handle.

Parameters
ahandle returned by a previous GNUNET_REGEX_announce call.

Definition at line 173 of file regex_api_announce.c.

174{
176 GNUNET_free (a->regex);
177 GNUNET_free (a);
178}
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700

References GNUNET_free, GNUNET_MQ_destroy(), GNUNET_REGEX_Announcement::mq, and GNUNET_REGEX_Announcement::regex.

Referenced by cleanup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REGEX_search()

struct GNUNET_REGEX_Search * GNUNET_REGEX_search ( const struct GNUNET_CONFIGURATION_Handle cfg,
const char *  string,
GNUNET_REGEX_Found  callback,
void *  callback_cls 
)

Search for a peer offering a regex matching certain string in the DHT.

The search runs until GNUNET_REGEX_search_cancel is called, even if results are returned.

Parameters
cfgconfiguration to use
stringString to match against the regexes in the DHT.
callbackCallback for found peers.
callback_clsClosure for callback.
Returns
Handle to stop search and free resources. Must be freed by calling GNUNET_REGEX_search_cancel.

Definition at line 189 of file regex_api_search.c.

193{
194 struct GNUNET_REGEX_Search *s;
195 size_t slen = strlen (string) + 1;
196
197 if (slen + sizeof(struct RegexSearchMessage) >= GNUNET_MAX_MESSAGE_SIZE)
198 {
200 _ ("Search string `%s' is too long!\n"),
201 string);
202 GNUNET_break (0);
203 return NULL;
204 }
206 "Starting regex search for %s\n",
207 string);
208 s = GNUNET_new (struct GNUNET_REGEX_Search);
209 s->cfg = cfg;
210 s->string = GNUNET_strdup (string);
211 s->callback = callback;
214 if (NULL == s->mq)
215 {
216 GNUNET_free (s->string);
217 GNUNET_free (s);
218 return NULL;
219 }
220 return s;
221}
@ GNUNET_ERROR_TYPE_DEBUG
static void search_reconnect(struct GNUNET_REGEX_Search *s)
(Re)connect to the REGEX service for the given search s.
#define LOG(kind,...)
Handle to store data about a regex search.
GNUNET_REGEX_Found callback
Function to call with results.
void * callback_cls
Closure for callback.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
char * string
Search string to transmit to the service.
struct GNUNET_MQ_Handle * mq
Connection to the regex service.
Message to initiate regex search.
Definition: regex_ipc.h:64

References _, GNUNET_REGEX_Search::callback, GNUNET_REGEX_Search::callback_cls, cfg, GNUNET_REGEX_Search::cfg, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_new, GNUNET_strdup, LOG, GNUNET_REGEX_Search::mq, search_reconnect(), and GNUNET_REGEX_Search::string.

Referenced by create_channel_to_destination().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REGEX_search_cancel()

void GNUNET_REGEX_search_cancel ( struct GNUNET_REGEX_Search s)

Stop search and free all data used by a GNUNET_REGEX_search call.

Parameters
sHandle returned by a previous GNUNET_REGEX_search call.

Definition at line 225 of file regex_api_search.c.

226{
228 GNUNET_free (s->string);
229 GNUNET_free (s);
230}

References GNUNET_free, GNUNET_MQ_destroy(), GNUNET_REGEX_Search::mq, and GNUNET_REGEX_Search::string.

Referenced by free_channel_state(), and handle_regex_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REGEX_ipv4toregexsearch()

void GNUNET_REGEX_ipv4toregexsearch ( const struct in_addr *  ip,
uint16_t  port,
char *  rxstr 
)

Create a regex in rxstr from the given ip and port.

Parameters
ipIPv4 representation.
portdestination port
rxstrgenerated regex, must be at least GNUNET_TUN_IPV4_REGEXLEN bytes long.

Definition at line 37 of file regex.c.

40{
41 GNUNET_snprintf (rxstr,
43 "4-%04X-%08X",
44 (unsigned int) port,
45 ntohl (ip->s_addr));
46}
static uint16_t port
Port number.
Definition: gnunet-bcd.c:146
int GNUNET_snprintf(char *buf, size_t size, const char *format,...) __attribute__((format(printf
Like snprintf, just aborts if the buffer is of insufficient size.
#define GNUNET_TUN_IPV4_REGEXLEN
Maximum regex string length for use with GNUNET_REGEX_ipv4toregexsearch.

References GNUNET_snprintf(), GNUNET_TUN_IPV4_REGEXLEN, and port.

Referenced by create_channel_to_destination().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REGEX_ipv6toregexsearch()

void GNUNET_REGEX_ipv6toregexsearch ( const struct in6_addr *  ipv6,
uint16_t  port,
char *  rxstr 
)

Create a regex in rxstr from the given ipv6 and port.

Parameters
ipv6IPv6 representation.
portdestination port
rxstrgenerated regex, must be at least GNUNET_TUN_IPV6_REGEXLEN bytes long.

Definition at line 50 of file regex.c.

53{
54 const uint32_t *addr;
55
56 addr = (const uint32_t *) ipv6;
57 GNUNET_snprintf (rxstr,
59 "6-%04X-%08X%08X%08X%08X",
60 (unsigned int) port,
61 ntohl (addr[0]),
62 ntohl (addr[1]),
63 ntohl (addr[2]),
64 ntohl (addr[3]));
65}
static int ipv6
Option -6: IPv6 requested.
Definition: gnunet-vpn.c:65
#define GNUNET_TUN_IPV6_REGEXLEN
Maximum regex string length for use with GNUNET_REGEX_ipv6toregexsearch.

References GNUNET_snprintf(), GNUNET_TUN_IPV6_REGEXLEN, ipv6, and port.

Referenced by create_channel_to_destination().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REGEX_ipv6policy2regex()

char * GNUNET_REGEX_ipv6policy2regex ( const char *  policy)

Convert an exit policy to a regular expression.

The exit policy specifies a set of subnets this peer is willing to serve as an exit for; the resulting regular expression will match the IPv6 address strings as returned by GNUNET_REGEX_ipv6toregexsearch.

Parameters
policyexit policy specification
Returns
regular expression, NULL on error

Definition at line 725 of file regex.c.

726{
727 struct in6_addr zero;
729 char *reg;
730 char *tmp;
731 char *line;
732 unsigned int i;
733
735 if (NULL == np)
736 return NULL;
737 reg = NULL;
738 memset (&zero, 0, sizeof(struct in6_addr));
739 for (i = 0; (0 == i) || (0 != memcmp (&zero, &np[i].network, sizeof(struct
740 in6_addr))
741 );
742 i++)
743 {
744 line = ipv6_to_regex (&np[i]);
745 if (NULL == line)
746 {
747 GNUNET_free (reg);
748 GNUNET_free (np);
749 return NULL;
750 }
751 if (NULL == reg)
752 {
753 reg = line;
754 }
755 else
756 {
757 GNUNET_asprintf (&tmp,
758 "%s|(%s)",
759 reg, line);
760 GNUNET_free (reg);
762 reg = tmp;
763 }
764 if (0 == memcmp (&zero, &np[i].network, sizeof(struct in6_addr)))
765 break;
766 }
767 GNUNET_free (np);
768 return reg;
769}
static char * line
Desired phone line (string to be converted to a hash).
static const struct GNUNET_CRYPTO_PrivateKey zero
Public key of all zeros.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
struct GNUNET_STRINGS_IPv6NetworkPolicy * GNUNET_STRINGS_parse_ipv6_policy(const char *routeListX)
Parse an IPv6 network policy.
Definition: strings.c:1450
static char * ipv6_to_regex(const struct GNUNET_STRINGS_IPv6NetworkPolicy *v6)
Convert a single line of an IPv4 policy to a regular expression.
Definition: regex.c:655
network in CIDR notation for IPV6.
struct in6_addr network
IPv6 address.

References GNUNET_asprintf(), GNUNET_free, GNUNET_STRINGS_parse_ipv6_policy(), ipv6_to_regex(), line, GNUNET_STRINGS_IPv6NetworkPolicy::network, and zero.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_REGEX_ipv4policy2regex()

char * GNUNET_REGEX_ipv4policy2regex ( const char *  policy)

Convert an exit policy to a regular expression.

The exit policy specifies a set of subnets this peer is willing to serve as an exit for; the resulting regular expression will match the IPv4 address strings as returned by GNUNET_REGEX_ipv4toregexsearch.

Parameters
policyexit policy specification
Returns
regular expression, NULL on error

Definition at line 682 of file regex.c.

683{
685 char *reg;
686 char *tmp;
687 char *line;
688 unsigned int i;
689
691 if (NULL == np)
692 return NULL;
693 reg = NULL;
694 for (i = 0; (0 == i) || (0 != np[i].network.s_addr); i++)
695 {
696 line = ipv4_to_regex (&np[i]);
697 if (NULL == line)
698 {
699 GNUNET_free (reg);
700 GNUNET_free (np);
701 return NULL;
702 }
703 if (NULL == reg)
704 {
705 reg = line;
706 }
707 else
708 {
709 GNUNET_asprintf (&tmp,
710 "%s|(%s)",
711 reg, line);
712 GNUNET_free (reg);
714 reg = tmp;
715 }
716 if (0 == np[i].network.s_addr)
717 break;
718 }
719 GNUNET_free (np);
720 return reg;
721}
struct GNUNET_STRINGS_IPv4NetworkPolicy * GNUNET_STRINGS_parse_ipv4_policy(const char *routeListX)
Parse an IPv4 network policy.
Definition: strings.c:1275
static char * ipv4_to_regex(const struct GNUNET_STRINGS_IPv4NetworkPolicy *v4)
Convert a single line of an IPv4 policy to a regular expression.
Definition: regex.c:622
IPV4 network in CIDR notation.
struct in_addr network
IPv4 address.

References GNUNET_asprintf(), GNUNET_free, GNUNET_STRINGS_parse_ipv4_policy(), ipv4_to_regex(), line, and GNUNET_STRINGS_IPv4NetworkPolicy::network.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function: