GNUnet  0.10.x
Data Structures | Macros | Functions
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.

Referenced by GNUNET_REGEX_search(), and handle_search_response().

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.

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(), GNUNET_REGEX_Search::mq, mq_error_handler(), and GNUNET_REGEX_Search::string.

Referenced by GNUNET_REGEX_search(), and mq_error_handler().

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);
170  s->mq = GNUNET_CLIENT_connect (s->cfg,
171  "regex",
172  handlers,
174  s);
175  if (NULL == s->mq)
176  return;
177  env = GNUNET_MQ_msg_extra (rsm,
178  slen,
180  GNUNET_memcpy (&rsm[1],
181  s->string,
182  slen);
183  GNUNET_MQ_send (s->mq,
184  env);
185 }
char * string
Search string to transmit to the service.
Message to initiate regex search.
Definition: regex_ipc.h:64
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:901
#define GNUNET_MESSAGE_TYPE_REGEX_SEARCH
Search for peer with matching capability.
Result from regex search.
Definition: regex_ipc.h:79
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MESSAGE_TYPE_REGEX_RESULT
Result in response to regex search.
struct GNUNET_MQ_Handle * mq
Connection to the regex service.
#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:52
#define GNUNET_memcpy(dst, src, n)
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Message handler for a specific message type.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
We got a disconnect after asking regex to do the announcement.
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:353
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
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.

References ResultMessage::get_path_length, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, ResultMessage::header, ResultMessage::put_path_length, size, and GNUNET_MessageHeader::size.

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 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
uint16_t put_path_length
Number of entries in the PUT path.
Definition: regex_ipc.h:94
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_REGEX_RESULT.
Definition: regex_ipc.h:84
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static unsigned int size
Size of the "table".
Definition: peer.c:67
The identity of the host (wraps the signing key of the peer).
uint16_t get_path_length
Number of entries in the GET path.
Definition: regex_ipc.h:89

◆ 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.

References GNUNET_REGEX_Search::callback, GNUNET_REGEX_Search::callback_cls, ResultMessage::get_path_length, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), ResultMessage::id, LOG, pid, and ResultMessage::put_path_length.

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 }
#define LOG(kind,...)
uint16_t put_path_length
Number of entries in the PUT path.
Definition: regex_ipc.h:94
GNUNET_REGEX_Found callback
Function to call with results.
void * callback_cls
Closure for callback.
struct GNUNET_PeerIdentity id
Identity of the peer that was found.
Definition: regex_ipc.h:99
The identity of the host (wraps the signing key of the peer).
uint16_t get_path_length
Number of entries in the GET path.
Definition: regex_ipc.h:89
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
Handle to store data about a regex search.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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.

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

Referenced by search_reconnect().

141 {
142  struct GNUNET_REGEX_Search *s = cls;
143 
144  GNUNET_MQ_destroy (s->mq);
145  s->mq = NULL;
146  search_reconnect (s);
147 }
static void search_reconnect(struct GNUNET_REGEX_Search *s)
(Re)connect to the REGEX service for the given search s.
struct GNUNET_MQ_Handle * mq
Connection to the regex service.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
Handle to store data about a regex search.
Here is the call graph for this function:
Here is the caller graph for this function: