aboutsummaryrefslogtreecommitdiff
path: root/src/hello
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/hello
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/hello')
-rw-r--r--src/hello/hello.c78
-rw-r--r--src/hello/test_hello.c44
2 files changed, 55 insertions, 67 deletions
diff --git a/src/hello/hello.c b/src/hello/hello.c
index 0df888c21..5d64d8f5a 100644
--- a/src/hello/hello.c
+++ b/src/hello/hello.c
@@ -77,8 +77,8 @@ struct GNUNET_HELLO_Message
77size_t 77size_t
78GNUNET_HELLO_add_address (const char *tname, 78GNUNET_HELLO_add_address (const char *tname,
79 struct GNUNET_TIME_Absolute expiration, 79 struct GNUNET_TIME_Absolute expiration,
80 const void *addr, 80 const void *addr, uint16_t addr_len, char *target,
81 uint16_t addr_len, char *target, size_t max) 81 size_t max)
82{ 82{
83 uint16_t alen; 83 uint16_t alen;
84 size_t slen; 84 size_t slen;
@@ -245,9 +245,9 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
245 memcpy (&expire, 245 memcpy (&expire,
246 &inptr[esize - alen - sizeof (struct GNUNET_TIME_AbsoluteNBO)], 246 &inptr[esize - alen - sizeof (struct GNUNET_TIME_AbsoluteNBO)],
247 sizeof (struct GNUNET_TIME_AbsoluteNBO)); 247 sizeof (struct GNUNET_TIME_AbsoluteNBO));
248 iret = it (it_cls, 248 iret =
249 inptr, 249 it (it_cls, inptr, GNUNET_TIME_absolute_ntoh (expire),
250 GNUNET_TIME_absolute_ntoh (expire), &inptr[esize - alen], alen); 250 &inptr[esize - alen], alen);
251 if (iret == GNUNET_SYSERR) 251 if (iret == GNUNET_SYSERR)
252 { 252 {
253 if (ret != NULL) 253 if (ret != NULL)
@@ -280,15 +280,13 @@ struct ExpireContext
280 280
281 281
282static int 282static int
283get_match_exp (void *cls, 283get_match_exp (void *cls, const char *tname,
284 const char *tname, 284 struct GNUNET_TIME_Absolute expiration, const void *addr,
285 struct GNUNET_TIME_Absolute expiration, 285 uint16_t addrlen)
286 const void *addr, uint16_t addrlen)
287{ 286{
288 struct ExpireContext *ec = cls; 287 struct ExpireContext *ec = cls;
289 288
290 if ((addrlen == ec->addrlen) && 289 if ((addrlen == ec->addrlen) && (0 == memcmp (addr, ec->addr, addrlen)) &&
291 (0 == memcmp (addr, ec->addr, addrlen)) &&
292 (0 == strcmp (tname, ec->tname))) 290 (0 == strcmp (tname, ec->tname)))
293 { 291 {
294 ec->found = GNUNET_YES; 292 ec->found = GNUNET_YES;
@@ -313,10 +311,9 @@ struct MergeContext
313 311
314 312
315static int 313static int
316copy_latest (void *cls, 314copy_latest (void *cls, const char *tname,
317 const char *tname, 315 struct GNUNET_TIME_Absolute expiration, const void *addr,
318 struct GNUNET_TIME_Absolute expiration, 316 uint16_t addrlen)
319 const void *addr, uint16_t addrlen)
320{ 317{
321 struct MergeContext *mc = cls; 318 struct MergeContext *mc = cls;
322 struct ExpireContext ec; 319 struct ExpireContext ec;
@@ -331,11 +328,9 @@ copy_latest (void *cls,
331 ((ec.expiration.abs_value == expiration.abs_value) && 328 ((ec.expiration.abs_value == expiration.abs_value) &&
332 (mc->take_equal == GNUNET_YES))) 329 (mc->take_equal == GNUNET_YES)))
333 { 330 {
334 mc->ret += GNUNET_HELLO_add_address (tname, 331 mc->ret +=
335 expiration, 332 GNUNET_HELLO_add_address (tname, expiration, addr, addrlen,
336 addr, 333 &mc->buf[mc->ret], mc->max - mc->ret);
337 addrlen,
338 &mc->buf[mc->ret], mc->max - mc->ret);
339 } 334 }
340 return GNUNET_OK; 335 return GNUNET_OK;
341} 336}
@@ -394,10 +389,9 @@ struct DeltaContext
394 389
395 390
396static int 391static int
397delta_match (void *cls, 392delta_match (void *cls, const char *tname,
398 const char *tname, 393 struct GNUNET_TIME_Absolute expiration, const void *addr,
399 struct GNUNET_TIME_Absolute expiration, 394 uint16_t addrlen)
400 const void *addr, uint16_t addrlen)
401{ 395{
402 struct DeltaContext *dc = cls; 396 struct DeltaContext *dc = cls;
403 int ret; 397 int ret;
@@ -407,8 +401,8 @@ delta_match (void *cls,
407 ec.addrlen = addrlen; 401 ec.addrlen = addrlen;
408 ec.found = GNUNET_NO; 402 ec.found = GNUNET_NO;
409 ec.tname = tname; 403 ec.tname = tname;
410 GNUNET_HELLO_iterate_addresses (dc->old_hello, 404 GNUNET_HELLO_iterate_addresses (dc->old_hello, GNUNET_NO, &get_match_exp,
411 GNUNET_NO, &get_match_exp, &ec); 405 &ec);
412 if ((ec.found == GNUNET_YES) && 406 if ((ec.found == GNUNET_YES) &&
413 ((ec.expiration.abs_value > expiration.abs_value) || 407 ((ec.expiration.abs_value > expiration.abs_value) ||
414 (ec.expiration.abs_value >= dc->expiration_limit.abs_value))) 408 (ec.expiration.abs_value >= dc->expiration_limit.abs_value)))
@@ -553,18 +547,16 @@ struct EqualsContext
553 547
554 548
555static int 549static int
556find_other_matching (void *cls, 550find_other_matching (void *cls, const char *tname,
557 const char *tname, 551 struct GNUNET_TIME_Absolute expiration, const void *addr,
558 struct GNUNET_TIME_Absolute expiration, 552 uint16_t addrlen)
559 const void *addr, uint16_t addrlen)
560{ 553{
561 struct EqualsContext *ec = cls; 554 struct EqualsContext *ec = cls;
562 555
563 if (expiration.abs_value < ec->expiration_limit.abs_value) 556 if (expiration.abs_value < ec->expiration_limit.abs_value)
564 return GNUNET_YES; 557 return GNUNET_YES;
565 if ((addrlen == ec->addrlen) && 558 if ((addrlen == ec->addrlen) && (0 == strcmp (tname, ec->tname)) &&
566 (0 == strcmp (tname, 559 (0 == memcmp (addr, ec->addr, addrlen)))
567 ec->tname)) && (0 == memcmp (addr, ec->addr, addrlen)))
568 { 560 {
569 ec->found = GNUNET_YES; 561 ec->found = GNUNET_YES;
570 if (expiration.abs_value < ec->expiration.abs_value) 562 if (expiration.abs_value < ec->expiration.abs_value)
@@ -576,10 +568,9 @@ find_other_matching (void *cls,
576 568
577 569
578static int 570static int
579find_matching (void *cls, 571find_matching (void *cls, const char *tname,
580 const char *tname, 572 struct GNUNET_TIME_Absolute expiration, const void *addr,
581 struct GNUNET_TIME_Absolute expiration, 573 uint16_t addrlen)
582 const void *addr, uint16_t addrlen)
583{ 574{
584 struct EqualsContext *ec = cls; 575 struct EqualsContext *ec = cls;
585 576
@@ -616,16 +607,15 @@ find_matching (void *cls,
616 * do not match at all 607 * do not match at all
617 */ 608 */
618struct GNUNET_TIME_Absolute 609struct GNUNET_TIME_Absolute
619GNUNET_HELLO_equals (const struct 610GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
620 GNUNET_HELLO_Message *h1, 611 const struct GNUNET_HELLO_Message *h2,
621 const struct 612 struct GNUNET_TIME_Absolute now)
622 GNUNET_HELLO_Message *h2, struct GNUNET_TIME_Absolute now)
623{ 613{
624 struct EqualsContext ec; 614 struct EqualsContext ec;
625 615
626 if (0 != memcmp (&h1->publicKey, 616 if (0 !=
627 &h2->publicKey, 617 memcmp (&h1->publicKey, &h2->publicKey,
628 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded))) 618 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)))
629 return GNUNET_TIME_UNIT_ZERO_ABS; 619 return GNUNET_TIME_UNIT_ZERO_ABS;
630 ec.expiration_limit = now; 620 ec.expiration_limit = now;
631 ec.result = GNUNET_TIME_UNIT_FOREVER_ABS; 621 ec.result = GNUNET_TIME_UNIT_FOREVER_ABS;
diff --git a/src/hello/test_hello.c b/src/hello/test_hello.c
index b6a9dc681..c9bf96791 100644
--- a/src/hello/test_hello.c
+++ b/src/hello/test_hello.c
@@ -41,19 +41,18 @@ my_addr_gen (void *cls, size_t max, void *buf)
41#endif 41#endif
42 if (0 == *i) 42 if (0 == *i)
43 return 0; 43 return 0;
44 ret = GNUNET_HELLO_add_address ("test", 44 ret =
45 GNUNET_TIME_absolute_get (), 45 GNUNET_HELLO_add_address ("test", GNUNET_TIME_absolute_get (),
46 "address_information", *i, buf, max); 46 "address_information", *i, buf, max);
47 (*i)--; 47 (*i)--;
48 return ret; 48 return ret;
49} 49}
50 50
51 51
52static int 52static int
53check_addr (void *cls, 53check_addr (void *cls, const char *tname,
54 const char *tname, 54 struct GNUNET_TIME_Absolute expiration, const void *addr,
55 struct GNUNET_TIME_Absolute expiration, 55 uint16_t addrlen)
56 const void *addr, uint16_t addrlen)
57{ 56{
58 unsigned int *i = cls; 57 unsigned int *i = cls;
59 58
@@ -71,10 +70,9 @@ check_addr (void *cls,
71 70
72 71
73static int 72static int
74remove_some (void *cls, 73remove_some (void *cls, const char *tname,
75 const char *tname, 74 struct GNUNET_TIME_Absolute expiration, const void *addr,
76 struct GNUNET_TIME_Absolute expiration, 75 uint16_t addrlen)
77 const void *addr, uint16_t addrlen)
78{ 76{
79 unsigned int *i = cls; 77 unsigned int *i = cls;
80 78
@@ -118,8 +116,8 @@ main (int argc, char *argv[])
118 fprintf (stderr, "Testing address iteration (empty set)...\n"); 116 fprintf (stderr, "Testing address iteration (empty set)...\n");
119#endif 117#endif
120 GNUNET_assert (NULL == 118 GNUNET_assert (NULL ==
121 GNUNET_HELLO_iterate_addresses (msg1, 119 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
122 GNUNET_NO, &check_addr, &i)); 120 &i));
123 121
124#if VERBOSE 122#if VERBOSE
125 fprintf (stderr, "Testing HELLO creation (with one address)...\n"); 123 fprintf (stderr, "Testing HELLO creation (with one address)...\n");
@@ -134,8 +132,8 @@ main (int argc, char *argv[])
134#endif 132#endif
135 i = 1; 133 i = 1;
136 GNUNET_assert (NULL == 134 GNUNET_assert (NULL ==
137 GNUNET_HELLO_iterate_addresses (msg2, 135 GNUNET_HELLO_iterate_addresses (msg2, GNUNET_NO, &check_addr,
138 GNUNET_NO, &check_addr, &i)); 136 &i));
139 GNUNET_assert (i == 0); 137 GNUNET_assert (i == 0);
140 138
141#if VERBOSE 139#if VERBOSE
@@ -158,8 +156,8 @@ main (int argc, char *argv[])
158#endif 156#endif
159 i = 3; 157 i = 3;
160 GNUNET_assert (NULL == 158 GNUNET_assert (NULL ==
161 GNUNET_HELLO_iterate_addresses (msg3, 159 GNUNET_HELLO_iterate_addresses (msg3, GNUNET_NO, &check_addr,
162 GNUNET_NO, &check_addr, &i)); 160 &i));
163 GNUNET_assert (i == 0); 161 GNUNET_assert (i == 0);
164 162
165#if VERBOSE 163#if VERBOSE
@@ -170,8 +168,8 @@ main (int argc, char *argv[])
170 168
171 i = 3; 169 i = 3;
172 GNUNET_assert (NULL == 170 GNUNET_assert (NULL ==
173 GNUNET_HELLO_iterate_addresses (msg1, 171 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
174 GNUNET_NO, &check_addr, &i)); 172 &i));
175 GNUNET_assert (i == 0); 173 GNUNET_assert (i == 0);
176 GNUNET_free (msg1); 174 GNUNET_free (msg1);
177 175
@@ -184,8 +182,8 @@ main (int argc, char *argv[])
184 GNUNET_assert (i == 0); 182 GNUNET_assert (i == 0);
185 i = 1; 183 i = 1;
186 GNUNET_assert (NULL == 184 GNUNET_assert (NULL ==
187 GNUNET_HELLO_iterate_addresses (msg1, 185 GNUNET_HELLO_iterate_addresses (msg1, GNUNET_NO, &check_addr,
188 GNUNET_NO, &check_addr, &i)); 186 &i));
189 GNUNET_assert (i == 0); 187 GNUNET_assert (i == 0);
190 GNUNET_free (msg1); 188 GNUNET_free (msg1);
191 189
@@ -193,8 +191,8 @@ main (int argc, char *argv[])
193 fprintf (stderr, "Testing delta address iteration...\n"); 191 fprintf (stderr, "Testing delta address iteration...\n");
194#endif 192#endif
195 i = 2; 193 i = 2;
196 GNUNET_HELLO_iterate_new_addresses (msg3, 194 GNUNET_HELLO_iterate_new_addresses (msg3, msg2, startup_time, &check_addr,
197 msg2, startup_time, &check_addr, &i); 195 &i);
198 GNUNET_assert (i == 0); 196 GNUNET_assert (i == 0);
199 GNUNET_free (msg2); 197 GNUNET_free (msg2);
200 GNUNET_free (msg3); 198 GNUNET_free (msg3);