aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/transport_api_blacklist.c49
1 files changed, 27 insertions, 22 deletions
diff --git a/src/transport/transport_api_blacklist.c b/src/transport/transport_api_blacklist.c
index 1c17bd498..2d6dc5f06 100644
--- a/src/transport/transport_api_blacklist.c
+++ b/src/transport/transport_api_blacklist.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010 Christian Grothoff (and other contributing authors) 3 (C) 2010-2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -59,7 +59,7 @@ struct GNUNET_TRANSPORT_Blacklist
59 GNUNET_TRANSPORT_BlacklistCallback cb; 59 GNUNET_TRANSPORT_BlacklistCallback cb;
60 60
61 /** 61 /**
62 * Closure for 'cb'. 62 * Closure for @e cb.
63 */ 63 */
64 void *cb_cls; 64 void *cb_cls;
65 65
@@ -96,12 +96,13 @@ reply (struct GNUNET_TRANSPORT_Blacklist *br);
96 * @param msg query 96 * @param msg query
97 */ 97 */
98static void 98static void
99query_handler (void *cls, const struct GNUNET_MessageHeader *msg) 99query_handler (void *cls,
100 const struct GNUNET_MessageHeader *msg)
100{ 101{
101 struct GNUNET_TRANSPORT_Blacklist *br = cls; 102 struct GNUNET_TRANSPORT_Blacklist *br = cls;
102 const struct BlacklistMessage *bm; 103 const struct BlacklistMessage *bm;
103 104
104 GNUNET_assert (br != NULL); 105 GNUNET_assert (NULL != br);
105 if ((NULL == msg) || 106 if ((NULL == msg) ||
106 (ntohs (msg->size) != sizeof (struct BlacklistMessage)) || 107 (ntohs (msg->size) != sizeof (struct BlacklistMessage)) ||
107 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY)) 108 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_BLACKLIST_QUERY))
@@ -132,19 +133,21 @@ receive (struct GNUNET_TRANSPORT_Blacklist *br)
132/** 133/**
133 * Transmit the blacklist initialization request to the service. 134 * Transmit the blacklist initialization request to the service.
134 * 135 *
135 * @param cls closure (struct GNUNET_TRANSPORT_Blacklist*) 136 * @param cls closure with `struct GNUNET_TRANSPORT_Blacklist *`
136 * @param size number of bytes available in buf 137 * @param size number of bytes available in @a buf
137 * @param buf where the callee should write the message 138 * @param buf where the callee should write the message
138 * @return number of bytes written to buf 139 * @return number of bytes written to @a buf
139 */ 140 */
140static size_t 141static size_t
141transmit_blacklist_init (void *cls, size_t size, void *buf) 142transmit_blacklist_init (void *cls,
143 size_t size,
144 void *buf)
142{ 145{
143 struct GNUNET_TRANSPORT_Blacklist *br = cls; 146 struct GNUNET_TRANSPORT_Blacklist *br = cls;
144 struct GNUNET_MessageHeader req; 147 struct GNUNET_MessageHeader req;
145 148
146 br->th = NULL; 149 br->th = NULL;
147 if (buf == NULL) 150 if (NULL == buf)
148 { 151 {
149 reconnect (br); 152 reconnect (br);
150 return 0; 153 return 0;
@@ -165,10 +168,10 @@ transmit_blacklist_init (void *cls, size_t size, void *buf)
165static void 168static void
166reconnect (struct GNUNET_TRANSPORT_Blacklist *br) 169reconnect (struct GNUNET_TRANSPORT_Blacklist *br)
167{ 170{
168 if (br->client != NULL) 171 if (NULL != br->client)
169 GNUNET_CLIENT_disconnect (br->client); 172 GNUNET_CLIENT_disconnect (br->client);
170 br->client = GNUNET_CLIENT_connect ("transport", br->cfg); 173 br->client = GNUNET_CLIENT_connect ("transport", br->cfg);
171 GNUNET_assert (br->client != NULL); 174 GNUNET_assert (NULL != br->client);
172 br->th = 175 br->th =
173 GNUNET_CLIENT_notify_transmit_ready (br->client, 176 GNUNET_CLIENT_notify_transmit_ready (br->client,
174 sizeof (struct GNUNET_MessageHeader), 177 sizeof (struct GNUNET_MessageHeader),
@@ -181,19 +184,21 @@ reconnect (struct GNUNET_TRANSPORT_Blacklist *br)
181/** 184/**
182 * Transmit the blacklist response to the service. 185 * Transmit the blacklist response to the service.
183 * 186 *
184 * @param cls closure (struct GNUNET_TRANSPORT_Blacklist*) 187 * @param cls closure with `struct GNUNET_TRANSPORT_Blacklist *`
185 * @param size number of bytes available in buf 188 * @param size number of bytes available in @a buf
186 * @param buf where the callee should write the message 189 * @param buf where the callee should write the message
187 * @return number of bytes written to buf 190 * @return number of bytes written to @a buf
188 */ 191 */
189static size_t 192static size_t
190transmit_blacklist_reply (void *cls, size_t size, void *buf) 193transmit_blacklist_reply (void *cls,
194 size_t size,
195 void *buf)
191{ 196{
192 struct GNUNET_TRANSPORT_Blacklist *br = cls; 197 struct GNUNET_TRANSPORT_Blacklist *br = cls;
193 struct BlacklistMessage req; 198 struct BlacklistMessage req;
194 199
195 br->th = NULL; 200 br->th = NULL;
196 if (buf == NULL) 201 if (NULL == buf)
197 { 202 {
198 reconnect (br); 203 reconnect (br);
199 return 0; 204 return 0;
@@ -217,14 +222,14 @@ transmit_blacklist_reply (void *cls, size_t size, void *buf)
217static void 222static void
218reply (struct GNUNET_TRANSPORT_Blacklist *br) 223reply (struct GNUNET_TRANSPORT_Blacklist *br)
219{ 224{
220 GNUNET_assert (br->th == NULL); 225 GNUNET_assert (NULL == br->th);
221 br->th = 226 br->th =
222 GNUNET_CLIENT_notify_transmit_ready (br->client, 227 GNUNET_CLIENT_notify_transmit_ready (br->client,
223 sizeof (struct BlacklistMessage), 228 sizeof (struct BlacklistMessage),
224 GNUNET_TIME_UNIT_FOREVER_REL, 229 GNUNET_TIME_UNIT_FOREVER_REL,
225 GNUNET_NO, &transmit_blacklist_reply, 230 GNUNET_NO, &transmit_blacklist_reply,
226 br); 231 br);
227 if (br->th == NULL) 232 if (NULL == br->th)
228 { 233 {
229 reconnect (br); 234 reconnect (br);
230 return; 235 return;
@@ -243,12 +248,13 @@ reply (struct GNUNET_TRANSPORT_Blacklist *br)
243 * 248 *
244 * @param cfg configuration to use 249 * @param cfg configuration to use
245 * @param cb callback to invoke to check if connections are allowed 250 * @param cb callback to invoke to check if connections are allowed
246 * @param cb_cls closure for cb 251 * @param cb_cls closure for @a cb
247 * @return NULL on error, otherwise handle for cancellation 252 * @return NULL on error, otherwise handle for cancellation
248 */ 253 */
249struct GNUNET_TRANSPORT_Blacklist * 254struct GNUNET_TRANSPORT_Blacklist *
250GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg, 255GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
251 GNUNET_TRANSPORT_BlacklistCallback cb, void *cb_cls) 256 GNUNET_TRANSPORT_BlacklistCallback cb,
257 void *cb_cls)
252{ 258{
253 struct GNUNET_CLIENT_Connection *client; 259 struct GNUNET_CLIENT_Connection *client;
254 struct GNUNET_TRANSPORT_Blacklist *ret; 260 struct GNUNET_TRANSPORT_Blacklist *ret;
@@ -261,7 +267,6 @@ GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
261 ret->cfg = cfg; 267 ret->cfg = cfg;
262 ret->cb = cb; 268 ret->cb = cb;
263 ret->cb_cls = cb_cls; 269 ret->cb_cls = cb_cls;
264 GNUNET_assert (ret->th == NULL);
265 ret->th = 270 ret->th =
266 GNUNET_CLIENT_notify_transmit_ready (client, 271 GNUNET_CLIENT_notify_transmit_ready (client,
267 sizeof (struct GNUNET_MessageHeader), 272 sizeof (struct GNUNET_MessageHeader),
@@ -281,7 +286,7 @@ GNUNET_TRANSPORT_blacklist (const struct GNUNET_CONFIGURATION_Handle *cfg,
281void 286void
282GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br) 287GNUNET_TRANSPORT_blacklist_cancel (struct GNUNET_TRANSPORT_Blacklist *br)
283{ 288{
284 if (br->th != NULL) 289 if (NULL != br->th)
285 { 290 {
286 GNUNET_CLIENT_notify_transmit_ready_cancel (br->th); 291 GNUNET_CLIENT_notify_transmit_ready_cancel (br->th);
287 br->th = NULL; 292 br->th = NULL;