GNUnet 0.22.2
regex_api_announce.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2012, 2013, 2016 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 */
26#include "platform.h"
27#include "gnunet_protocols.h"
28#include "gnunet_util_lib.h"
30#include "regex_ipc.h"
31
32#define LOG(kind, ...) GNUNET_log_from (kind, "regex-api", __VA_ARGS__)
33
38{
43
48
52 char *regex;
53
58
62 uint16_t compression;
63};
64
65
71static void
73
74
82static void
84 enum GNUNET_MQ_Error error)
85{
86 struct GNUNET_REGEX_Announcement *a = cls;
87
89 a->mq = NULL;
91}
92
93
99static void
101{
102 struct GNUNET_MQ_Envelope *env;
103 struct AnnounceMessage *am;
104 size_t slen;
105
107 "regex",
108 NULL,
110 a);
111 if (NULL == a->mq)
112 return;
113 slen = strlen (a->regex) + 1;
115 slen,
117 am->compression = htons (a->compression);
118 am->reserved = htons (0);
120 GNUNET_memcpy (&am[1],
121 a->regex,
122 slen);
123 GNUNET_MQ_send (a->mq,
124 env);
125}
126
127
140 const char *regex,
142 uint16_t compression)
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}
170
171
172void
174{
176 GNUNET_free (a->regex);
177 GNUNET_free (a);
178}
179
180
181/* end of regex_api_announce.c */
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
Constants for network protocols.
API to access regex service to advertise capabilities via regex and discover respective peers using m...
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
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_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#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.
GNUNET_MQ_Error
Error codes for the queue.
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_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
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:700
#define GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE
Advertise regex capability.
void GNUNET_REGEX_announce_cancel(struct GNUNET_REGEX_Announcement *a)
Stop announcing the regex specified by the given handle.
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 the given peer under the given regular expression.
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:620
#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.
static void announce_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
We got a disconnect after asking regex to do the announcement.
regex IPC messages (not called 'regex.h' due to conflict with system headers)
Request for regex service to announce capability.
Definition: regex_ipc.h:35
struct GNUNET_TIME_RelativeNBO refresh_delay
Delay between repeated announcements.
Definition: regex_ipc.h:54
uint16_t reserved
Always zero.
Definition: regex_ipc.h:49
uint16_t compression
How many characters can we squeeze per edge?
Definition: regex_ipc.h:44
Handle to a message queue.
Definition: mq.c:87
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.
Time for relative time used by GNUnet, in microseconds.