aboutsummaryrefslogtreecommitdiff
path: root/src/regex/regex_api_announce.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regex/regex_api_announce.c')
-rw-r--r--src/regex/regex_api_announce.c105
1 files changed, 52 insertions, 53 deletions
diff --git a/src/regex/regex_api_announce.c b/src/regex/regex_api_announce.c
index e1af0b7a9..3b5801994 100644
--- a/src/regex/regex_api_announce.c
+++ b/src/regex/regex_api_announce.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file regex/regex_api_announce.c 21 * @file regex/regex_api_announce.c
22 * @brief access regex service to advertise capabilities via regex 22 * @brief access regex service to advertise capabilities via regex
@@ -29,13 +29,12 @@
29#include "gnunet_regex_service.h" 29#include "gnunet_regex_service.h"
30#include "regex_ipc.h" 30#include "regex_ipc.h"
31 31
32#define LOG(kind,...) GNUNET_log_from (kind, "regex-api",__VA_ARGS__) 32#define LOG(kind, ...) GNUNET_log_from(kind, "regex-api", __VA_ARGS__)
33 33
34/** 34/**
35 * Handle to store cached data about a regex announce. 35 * Handle to store cached data about a regex announce.
36 */ 36 */
37struct GNUNET_REGEX_Announcement 37struct GNUNET_REGEX_Announcement {
38{
39 /** 38 /**
40 * Connection to the regex service. 39 * Connection to the regex service.
41 */ 40 */
@@ -70,7 +69,7 @@ struct GNUNET_REGEX_Announcement
70 * @param a REGEX to announce. 69 * @param a REGEX to announce.
71 */ 70 */
72static void 71static void
73announce_reconnect (struct GNUNET_REGEX_Announcement *a); 72announce_reconnect(struct GNUNET_REGEX_Announcement *a);
74 73
75 74
76/** 75/**
@@ -81,14 +80,14 @@ announce_reconnect (struct GNUNET_REGEX_Announcement *a);
81 * @param error error code 80 * @param error error code
82 */ 81 */
83static void 82static void
84announce_mq_error_handler (void *cls, 83announce_mq_error_handler(void *cls,
85 enum GNUNET_MQ_Error error) 84 enum GNUNET_MQ_Error error)
86{ 85{
87 struct GNUNET_REGEX_Announcement *a = cls; 86 struct GNUNET_REGEX_Announcement *a = cls;
88 87
89 GNUNET_MQ_destroy (a->mq); 88 GNUNET_MQ_destroy(a->mq);
90 a->mq = NULL; 89 a->mq = NULL;
91 announce_reconnect (a); 90 announce_reconnect(a);
92} 91}
93 92
94 93
@@ -98,31 +97,31 @@ announce_mq_error_handler (void *cls,
98 * @param a REGEX to announce. 97 * @param a REGEX to announce.
99 */ 98 */
100static void 99static void
101announce_reconnect (struct GNUNET_REGEX_Announcement *a) 100announce_reconnect(struct GNUNET_REGEX_Announcement *a)
102{ 101{
103 struct GNUNET_MQ_Envelope *env; 102 struct GNUNET_MQ_Envelope *env;
104 struct AnnounceMessage *am; 103 struct AnnounceMessage *am;
105 size_t slen; 104 size_t slen;
106 105
107 a->mq = GNUNET_CLIENT_connect (a->cfg, 106 a->mq = GNUNET_CLIENT_connect(a->cfg,
108 "regex", 107 "regex",
109 NULL, 108 NULL,
110 &announce_mq_error_handler, 109 &announce_mq_error_handler,
111 a); 110 a);
112 if (NULL == a->mq) 111 if (NULL == a->mq)
113 return; 112 return;
114 slen = strlen (a->regex) + 1; 113 slen = strlen(a->regex) + 1;
115 env = GNUNET_MQ_msg_extra (am, 114 env = GNUNET_MQ_msg_extra(am,
116 slen, 115 slen,
117 GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE); 116 GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE);
118 am->compression = htons (a->compression); 117 am->compression = htons(a->compression);
119 am->reserved = htons (0); 118 am->reserved = htons(0);
120 am->refresh_delay = GNUNET_TIME_relative_hton (a->refresh_delay); 119 am->refresh_delay = GNUNET_TIME_relative_hton(a->refresh_delay);
121 GNUNET_memcpy (&am[1], 120 GNUNET_memcpy(&am[1],
122 a->regex, 121 a->regex,
123 slen); 122 slen);
124 GNUNET_MQ_send (a->mq, 123 GNUNET_MQ_send(a->mq,
125 env); 124 env);
126} 125}
127 126
128 127
@@ -137,35 +136,35 @@ announce_reconnect (struct GNUNET_REGEX_Announcement *a)
137 * Must be freed by calling #GNUNET_REGEX_announce_cancel(). 136 * Must be freed by calling #GNUNET_REGEX_announce_cancel().
138 */ 137 */
139struct GNUNET_REGEX_Announcement * 138struct GNUNET_REGEX_Announcement *
140GNUNET_REGEX_announce (const struct GNUNET_CONFIGURATION_Handle *cfg, 139GNUNET_REGEX_announce(const struct GNUNET_CONFIGURATION_Handle *cfg,
141 const char *regex, 140 const char *regex,
142 struct GNUNET_TIME_Relative refresh_delay, 141 struct GNUNET_TIME_Relative refresh_delay,
143 uint16_t compression) 142 uint16_t compression)
144{ 143{
145 struct GNUNET_REGEX_Announcement *a; 144 struct GNUNET_REGEX_Announcement *a;
146 size_t slen; 145 size_t slen;
147 146
148 slen = strlen (regex) + 1; 147 slen = strlen(regex) + 1;
149 if (slen + sizeof (struct AnnounceMessage) >= GNUNET_MAX_MESSAGE_SIZE) 148 if (slen + sizeof(struct AnnounceMessage) >= GNUNET_MAX_MESSAGE_SIZE)
150 { 149 {
151 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 150 GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
152 _("Regex `%s' is too long!\n"), 151 _("Regex `%s' is too long!\n"),
153 regex); 152 regex);
154 GNUNET_break (0); 153 GNUNET_break(0);
155 return NULL; 154 return NULL;
156 } 155 }
157 a = GNUNET_new (struct GNUNET_REGEX_Announcement); 156 a = GNUNET_new(struct GNUNET_REGEX_Announcement);
158 a->cfg = cfg; 157 a->cfg = cfg;
159 a->refresh_delay = refresh_delay; 158 a->refresh_delay = refresh_delay;
160 a->compression = compression; 159 a->compression = compression;
161 a->regex = GNUNET_strdup (regex); 160 a->regex = GNUNET_strdup(regex);
162 announce_reconnect (a); 161 announce_reconnect(a);
163 if (NULL == a->mq) 162 if (NULL == a->mq)
164 { 163 {
165 GNUNET_free (a->regex); 164 GNUNET_free(a->regex);
166 GNUNET_free (a); 165 GNUNET_free(a);
167 return NULL; 166 return NULL;
168 } 167 }
169 return a; 168 return a;
170} 169}
171 170
@@ -176,11 +175,11 @@ GNUNET_REGEX_announce (const struct GNUNET_CONFIGURATION_Handle *cfg,
176 * @param a handle returned by a previous #GNUNET_REGEX_announce() call. 175 * @param a handle returned by a previous #GNUNET_REGEX_announce() call.
177 */ 176 */
178void 177void
179GNUNET_REGEX_announce_cancel (struct GNUNET_REGEX_Announcement *a) 178GNUNET_REGEX_announce_cancel(struct GNUNET_REGEX_Announcement *a)
180{ 179{
181 GNUNET_MQ_destroy (a->mq); 180 GNUNET_MQ_destroy(a->mq);
182 GNUNET_free (a->regex); 181 GNUNET_free(a->regex);
183 GNUNET_free (a); 182 GNUNET_free(a);
184} 183}
185 184
186/* end of regex_api_announce.c */ 185/* end of regex_api_announce.c */