GNUnet 0.22.2
regex_api_search.c File Reference

access regex service to discover peers using matching strings More...

#include "platform.h"
#include "gnunet_protocols.h"
#include "gnunet_util_lib.h"
#include "gnunet_regex_service.h"
#include "regex_ipc.h"
Include dependency graph for regex_api_search.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_REGEX_Search
 Handle to store data about a regex search. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "regex-api", __VA_ARGS__)
 

Functions

static void search_reconnect (struct GNUNET_REGEX_Search *s)
 (Re)connect to the REGEX service for the given search s. More...
 
static int check_search_response (void *cls, const struct ResultMessage *result)
 We got a response or disconnect after asking regex to do the search. More...
 
static void handle_search_response (void *cls, const struct ResultMessage *result)
 We got a response or disconnect after asking regex to do the search. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 We got a disconnect after asking regex to do the announcement. 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...
 

Detailed Description

access regex service to discover peers using matching strings

Author
Maximilian Szengel
Christian Grothoff

Definition in file regex_api_search.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "regex-api", __VA_ARGS__)

Definition at line 33 of file regex_api_search.c.

Function Documentation

◆ search_reconnect()

static void search_reconnect ( struct GNUNET_REGEX_Search s)
static

(Re)connect to the REGEX service for the given search s.

Parameters
scontext for the search search for

Definition at line 156 of file regex_api_search.c.

157{
159 GNUNET_MQ_hd_var_size (search_response,
161 struct ResultMessage,
162 s),
164 };
165 size_t slen = strlen (s->string) + 1;
166 struct GNUNET_MQ_Envelope *env;
167 struct RegexSearchMessage *rsm;
168
169 GNUNET_assert (NULL == s->mq);
171 "regex",
172 handlers,
174 s);
175 if (NULL == s->mq)
176 return;
178 slen,
180 GNUNET_memcpy (&rsm[1],
181 s->string,
182 slen);
183 GNUNET_MQ_send (s->mq,
184 env);
185}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1060
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:61
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_REGEX_SEARCH
Search for peer with matching capability.
#define GNUNET_MESSAGE_TYPE_REGEX_RESULT
Result in response to regex search.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
We got a disconnect after asking regex to do the announcement.
Message handler for a specific message type.
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
Result from regex search.
Definition: regex_ipc.h:78

References GNUNET_REGEX_Search::cfg, env, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_memcpy, GNUNET_MESSAGE_TYPE_REGEX_RESULT, GNUNET_MESSAGE_TYPE_REGEX_SEARCH, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), handlers, GNUNET_REGEX_Search::mq, mq_error_handler(), and GNUNET_REGEX_Search::string.

Referenced by GNUNET_REGEX_search(), and mq_error_handler().

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

◆ check_search_response()

static int check_search_response ( void *  cls,
const struct ResultMessage result 
)
static

We got a response or disconnect after asking regex to do the search.

Check it is well-formed.

Parameters
clsthe struct GNUNET_REGEX_Search to handle reply for
resultthe message
Returns
GNUNET_SYSERR if rm is not well-formed.

Definition at line 86 of file regex_api_search.c.

88{
89 uint16_t size = ntohs (result->header.size) - sizeof(*result);
90 uint16_t gpl = ntohs (result->get_path_length);
91 uint16_t ppl = ntohs (result->put_path_length);
92
93 if (size != (gpl + ppl) * sizeof(struct GNUNET_PeerIdentity))
94 {
95 GNUNET_break (0);
96 return GNUNET_SYSERR;
97 }
98 return GNUNET_OK;
99}
static int result
Global testing status.
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
static unsigned int size
Size of the "table".
Definition: peer.c:68
The identity of the host (wraps the signing key of the peer).

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, result, and size.

◆ handle_search_response()

static void handle_search_response ( void *  cls,
const struct ResultMessage result 
)
static

We got a response or disconnect after asking regex to do the search.

Handle it.

Parameters
clsthe struct GNUNET_REGEX_Search to handle reply for
resultthe message

Definition at line 110 of file regex_api_search.c.

112{
113 struct GNUNET_REGEX_Search *s = cls;
114 uint16_t gpl = ntohs (result->get_path_length);
115 uint16_t ppl = ntohs (result->put_path_length);
116 const struct GNUNET_PeerIdentity *pid;
117
118 pid = &result->id;
120 "Got regex result %s\n",
121 GNUNET_i2s (pid));
122 s->callback (s->callback_cls,
123 pid,
124 &pid[1],
125 gpl,
126 &pid[1 + gpl],
127 ppl);
128}
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
#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.

References GNUNET_REGEX_Search::callback, GNUNET_REGEX_Search::callback_cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), LOG, pid, and result.

Here is the call graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

We got a disconnect after asking regex to do the announcement.

Retry.

Parameters
clsthe struct GNUNET_REGEX_Search to retry
errorerror code

Definition at line 139 of file regex_api_search.c.

141{
142 struct GNUNET_REGEX_Search *s = cls;
143
145 s->mq = NULL;
147}
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
static void search_reconnect(struct GNUNET_REGEX_Search *s)
(Re)connect to the REGEX service for the given search s.

References GNUNET_MQ_destroy(), GNUNET_REGEX_Search::mq, and search_reconnect().

Referenced by search_reconnect().

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