aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_hello.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/transport/gnunet-service-transport_hello.c
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/transport/gnunet-service-transport_hello.c')
-rw-r--r--src/transport/gnunet-service-transport_hello.c209
1 files changed, 103 insertions, 106 deletions
diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c
index 2d7440650..24a8321a2 100644
--- a/src/transport/gnunet-service-transport_hello.c
+++ b/src/transport/gnunet-service-transport_hello.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/** 21/**
22 * @file transport/gnunet-service-transport_hello.c 22 * @file transport/gnunet-service-transport_hello.c
@@ -36,7 +36,7 @@
36/** 36/**
37 * How often do we refresh our HELLO (due to expiration concerns)? 37 * How often do we refresh our HELLO (due to expiration concerns)?
38 */ 38 */
39#define HELLO_REFRESH_PERIOD GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 6) 39#define HELLO_REFRESH_PERIOD GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 6)
40 40
41/** 41/**
42 * Hello address expiration 42 * Hello address expiration
@@ -48,8 +48,7 @@ extern struct GNUNET_TIME_Relative hello_expiration;
48 * Entry in linked list of network addresses for ourselves. Also 48 * Entry in linked list of network addresses for ourselves. Also
49 * includes a cached signature for 'struct TransportPongMessage's. 49 * includes a cached signature for 'struct TransportPongMessage's.
50 */ 50 */
51struct OwnAddressList 51struct OwnAddressList {
52{
53 /** 52 /**
54 * This is a doubly-linked list. 53 * This is a doubly-linked list.
55 */ 54 */
@@ -82,7 +81,6 @@ struct OwnAddressList
82 * multiple origins. 81 * multiple origins.
83 */ 82 */
84 unsigned int rc; 83 unsigned int rc;
85
86}; 84};
87 85
88 86
@@ -125,8 +123,7 @@ static struct GNUNET_SCHEDULER_Task *hello_task;
125/** 123/**
126 * Closure for #address_generator(). 124 * Closure for #address_generator().
127 */ 125 */
128struct GeneratorContext 126struct GeneratorContext {
129{
130 /** 127 /**
131 * Where are we in the DLL? 128 * Where are we in the DLL?
132 */ 129 */
@@ -149,19 +146,19 @@ struct GeneratorContext
149 * end of the iteration. 146 * end of the iteration.
150 */ 147 */
151static ssize_t 148static ssize_t
152address_generator (void *cls, 149address_generator(void *cls,
153 size_t max, 150 size_t max,
154 void *buf) 151 void *buf)
155{ 152{
156 struct GeneratorContext *gc = cls; 153 struct GeneratorContext *gc = cls;
157 ssize_t ret; 154 ssize_t ret;
158 155
159 if (NULL == gc->addr_pos) 156 if (NULL == gc->addr_pos)
160 return GNUNET_SYSERR; /* Done */ 157 return GNUNET_SYSERR; /* Done */
161 ret = GNUNET_HELLO_add_address (gc->addr_pos->address, 158 ret = GNUNET_HELLO_add_address(gc->addr_pos->address,
162 gc->expiration, 159 gc->expiration,
163 buf, 160 buf,
164 max); 161 max);
165 gc->addr_pos = gc->addr_pos->next; 162 gc->addr_pos = gc->addr_pos->next;
166 return ret; 163 return ret;
167} 164}
@@ -174,38 +171,38 @@ address_generator (void *cls,
174 * @param cls unused 171 * @param cls unused
175 */ 172 */
176static void 173static void
177refresh_hello_task (void *cls) 174refresh_hello_task(void *cls)
178{ 175{
179 struct GeneratorContext gc; 176 struct GeneratorContext gc;
180 177
181 hello_task = NULL; 178 hello_task = NULL;
182 gc.addr_pos = oal_head; 179 gc.addr_pos = oal_head;
183 gc.expiration = GNUNET_TIME_relative_to_absolute (hello_expiration); 180 gc.expiration = GNUNET_TIME_relative_to_absolute(hello_expiration);
184 181
185 GNUNET_free_non_null (our_hello); 182 GNUNET_free_non_null(our_hello);
186 our_hello = GNUNET_HELLO_create (&GST_my_identity.public_key, 183 our_hello = GNUNET_HELLO_create(&GST_my_identity.public_key,
187 &address_generator, 184 &address_generator,
188 &gc, 185 &gc,
189 friend_option); 186 friend_option);
190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 187 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
191 "Refreshed my %s HELLO, new size is %d\n", 188 "Refreshed my %s HELLO, new size is %d\n",
192 (GNUNET_YES == friend_option) ? "friend-only" : "public", 189 (GNUNET_YES == friend_option) ? "friend-only" : "public",
193 GNUNET_HELLO_size (our_hello)); 190 GNUNET_HELLO_size(our_hello));
194 GNUNET_STATISTICS_update (GST_stats, 191 GNUNET_STATISTICS_update(GST_stats,
195 gettext_noop ("# refreshed my HELLO"), 192 gettext_noop("# refreshed my HELLO"),
196 1, 193 1,
197 GNUNET_NO); 194 GNUNET_NO);
198 if (NULL != hello_cb) 195 if (NULL != hello_cb)
199 hello_cb (hello_cb_cls, 196 hello_cb(hello_cb_cls,
200 GST_hello_get ()); 197 GST_hello_get());
201 GNUNET_PEERINFO_add_peer (GST_peerinfo, 198 GNUNET_PEERINFO_add_peer(GST_peerinfo,
202 our_hello, 199 our_hello,
203 NULL, 200 NULL,
204 NULL); 201 NULL);
205 hello_task = 202 hello_task =
206 GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD, 203 GNUNET_SCHEDULER_add_delayed(HELLO_REFRESH_PERIOD,
207 &refresh_hello_task, 204 &refresh_hello_task,
208 NULL); 205 NULL);
209} 206}
210 207
211 208
@@ -215,14 +212,14 @@ refresh_hello_task (void *cls)
215 * have been shutdown). 212 * have been shutdown).
216 */ 213 */
217static void 214static void
218refresh_hello () 215refresh_hello()
219{ 216{
220 if (NULL != hello_task) 217 if (NULL != hello_task)
221 { 218 {
222 GNUNET_SCHEDULER_cancel (hello_task); 219 GNUNET_SCHEDULER_cancel(hello_task);
223 hello_task = GNUNET_SCHEDULER_add_now (&refresh_hello_task, 220 hello_task = GNUNET_SCHEDULER_add_now(&refresh_hello_task,
224 NULL); 221 NULL);
225 } 222 }
226} 223}
227 224
228 225
@@ -234,14 +231,14 @@ refresh_hello ()
234 * @param cb_cls closure for @a cb 231 * @param cb_cls closure for @a cb
235 */ 232 */
236void 233void
237GST_hello_start (int friend_only, 234GST_hello_start(int friend_only,
238 GST_HelloCallback cb, 235 GST_HelloCallback cb,
239 void *cb_cls) 236 void *cb_cls)
240{ 237{
241 hello_cb = cb; 238 hello_cb = cb;
242 hello_cb_cls = cb_cls; 239 hello_cb_cls = cb_cls;
243 friend_option = friend_only; 240 friend_option = friend_only;
244 refresh_hello_task (NULL); 241 refresh_hello_task(NULL);
245} 242}
246 243
247 244
@@ -249,20 +246,20 @@ GST_hello_start (int friend_only,
249 * Shutdown the HELLO module. 246 * Shutdown the HELLO module.
250 */ 247 */
251void 248void
252GST_hello_stop () 249GST_hello_stop()
253{ 250{
254 hello_cb = NULL; 251 hello_cb = NULL;
255 hello_cb_cls = NULL; 252 hello_cb_cls = NULL;
256 if (NULL != hello_task) 253 if (NULL != hello_task)
257 { 254 {
258 GNUNET_SCHEDULER_cancel (hello_task); 255 GNUNET_SCHEDULER_cancel(hello_task);
259 hello_task = NULL; 256 hello_task = NULL;
260 } 257 }
261 if (NULL != our_hello) 258 if (NULL != our_hello)
262 { 259 {
263 GNUNET_free (our_hello); 260 GNUNET_free(our_hello);
264 our_hello = NULL; 261 our_hello = NULL;
265 } 262 }
266} 263}
267 264
268 265
@@ -272,9 +269,9 @@ GST_hello_stop ()
272 * @return our HELLO message 269 * @return our HELLO message
273 */ 270 */
274const struct GNUNET_MessageHeader * 271const struct GNUNET_MessageHeader *
275GST_hello_get () 272GST_hello_get()
276{ 273{
277 return (const struct GNUNET_MessageHeader *) our_hello; 274 return (const struct GNUNET_MessageHeader *)our_hello;
278} 275}
279 276
280 277
@@ -285,52 +282,52 @@ GST_hello_get ()
285 * @param address address to add or remove 282 * @param address address to add or remove
286 */ 283 */
287void 284void
288GST_hello_modify_addresses (int addremove, 285GST_hello_modify_addresses(int addremove,
289 const struct GNUNET_HELLO_Address *address) 286 const struct GNUNET_HELLO_Address *address)
290{ 287{
291 struct OwnAddressList *al; 288 struct OwnAddressList *al;
292 289
293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 290 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
294 (GNUNET_YES == addremove) 291 (GNUNET_YES == addremove)
295 ? "Adding `%s' to the set of our addresses\n" 292 ? "Adding `%s' to the set of our addresses\n"
296 : "Removing `%s' from the set of our addresses\n", 293 : "Removing `%s' from the set of our addresses\n",
297 GST_plugins_a2s (address)); 294 GST_plugins_a2s(address));
298 GNUNET_assert (NULL != address); 295 GNUNET_assert(NULL != address);
299 for (al = oal_head; al != NULL; al = al->next) 296 for (al = oal_head; al != NULL; al = al->next)
300 if (0 == GNUNET_HELLO_address_cmp (address, al->address)) 297 if (0 == GNUNET_HELLO_address_cmp(address, al->address))
301 break; 298 break;
302 if (GNUNET_NO == addremove) 299 if (GNUNET_NO == addremove)
303 {
304 if (NULL == al)
305 { 300 {
306 /* address to be removed not found!? */ 301 if (NULL == al)
307 GNUNET_break (0); 302 {
303 /* address to be removed not found!? */
304 GNUNET_break(0);
305 return;
306 }
307 al->rc--;
308 if (0 != al->rc)
309 return; /* RC not yet zero */
310 GNUNET_CONTAINER_DLL_remove(oal_head,
311 oal_tail,
312 al);
313 GNUNET_HELLO_address_free(al->address);
314 GNUNET_free(al);
315 refresh_hello();
308 return; 316 return;
309 } 317 }
310 al->rc--;
311 if (0 != al->rc)
312 return; /* RC not yet zero */
313 GNUNET_CONTAINER_DLL_remove (oal_head,
314 oal_tail,
315 al);
316 GNUNET_HELLO_address_free (al->address);
317 GNUNET_free (al);
318 refresh_hello ();
319 return;
320 }
321 if (NULL != al) 318 if (NULL != al)
322 { 319 {
323 /* address added twice or more */ 320 /* address added twice or more */
324 al->rc++; 321 al->rc++;
325 return; 322 return;
326 } 323 }
327 al = GNUNET_new (struct OwnAddressList); 324 al = GNUNET_new(struct OwnAddressList);
328 al->rc = 1; 325 al->rc = 1;
329 GNUNET_CONTAINER_DLL_insert (oal_head, 326 GNUNET_CONTAINER_DLL_insert(oal_head,
330 oal_tail, 327 oal_tail,
331 al); 328 al);
332 al->address = GNUNET_HELLO_address_copy (address); 329 al->address = GNUNET_HELLO_address_copy(address);
333 refresh_hello (); 330 refresh_hello();
334} 331}
335 332
336 333
@@ -345,20 +342,20 @@ GST_hello_modify_addresses (int addremove,
345 * #GNUNET_NO if not 342 * #GNUNET_NO if not
346 */ 343 */
347int 344int
348GST_hello_test_address (const struct GNUNET_HELLO_Address *address, 345GST_hello_test_address(const struct GNUNET_HELLO_Address *address,
349 struct GNUNET_CRYPTO_EddsaSignature **sig, 346 struct GNUNET_CRYPTO_EddsaSignature **sig,
350 struct GNUNET_TIME_Absolute **sig_expiration) 347 struct GNUNET_TIME_Absolute **sig_expiration)
351{ 348{
352 struct OwnAddressList *al; 349 struct OwnAddressList *al;
353 350
354 for (al = oal_head; al != NULL; al = al->next) 351 for (al = oal_head; al != NULL; al = al->next)
355 if (0 == GNUNET_HELLO_address_cmp (address, 352 if (0 == GNUNET_HELLO_address_cmp(address,
356 al->address)) 353 al->address))
357 { 354 {
358 *sig = &al->pong_signature; 355 *sig = &al->pong_signature;
359 *sig_expiration = &al->pong_sig_expires; 356 *sig_expiration = &al->pong_sig_expires;
360 return GNUNET_YES; 357 return GNUNET_YES;
361 } 358 }
362 *sig = NULL; 359 *sig = NULL;
363 *sig_expiration = NULL; 360 *sig_expiration = NULL;
364 return GNUNET_NO; 361 return GNUNET_NO;