aboutsummaryrefslogtreecommitdiff
path: root/src/hello/hello.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-05-20 17:04:56 +0000
committerChristian Grothoff <christian@grothoff.org>2015-05-20 17:04:56 +0000
commitdfc14c78063c52aaee7301b04fd7c691d8a2df09 (patch)
tree5e09ffd1815f5f2751cd9d5712c726fff8734dbf /src/hello/hello.c
parentc8be0a0d42d7bf5ca96cc050fc12d71a43d8dca3 (diff)
downloadgnunet-dfc14c78063c52aaee7301b04fd7c691d8a2df09.tar.gz
gnunet-dfc14c78063c52aaee7301b04fd7c691d8a2df09.zip
-indentation, doxygen
Diffstat (limited to 'src/hello/hello.c')
-rw-r--r--src/hello/hello.c232
1 files changed, 164 insertions, 68 deletions
diff --git a/src/hello/hello.c b/src/hello/hello.c
index d552e4454..e6e2787dd 100644
--- a/src/hello/hello.c
+++ b/src/hello/hello.c
@@ -84,7 +84,7 @@ struct GNUNET_HELLO_ComposeUriContext
84 84
85 85
86/** 86/**
87 * Context for 'add_address_to_hello'. 87 * Context for #add_address_to_hello().
88 */ 88 */
89struct GNUNET_HELLO_ParseUriContext 89struct GNUNET_HELLO_ParseUriContext
90{ 90{
@@ -116,7 +116,8 @@ struct GNUNET_HELLO_ParseUriContext
116}; 116};
117 117
118 118
119/** Return HELLO type 119/**
120 * Return HELLO type
120 * 121 *
121 * @param h HELLO Message to test 122 * @param h HELLO Message to test
122 * @return #GNUNET_YES or #GNUNET_NO 123 * @return #GNUNET_YES or #GNUNET_NO
@@ -130,7 +131,6 @@ GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h)
130} 131}
131 132
132 133
133
134/** 134/**
135 * Copy the given address information into 135 * Copy the given address information into
136 * the given buffer using the format of HELLOs. 136 * the given buffer using the format of HELLOs.
@@ -144,7 +144,8 @@ GNUNET_HELLO_is_friend_only (const struct GNUNET_HELLO_Message *h)
144 */ 144 */
145size_t 145size_t
146GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address, 146GNUNET_HELLO_add_address (const struct GNUNET_HELLO_Address *address,
147 struct GNUNET_TIME_Absolute expiration, char *target, 147 struct GNUNET_TIME_Absolute expiration,
148 char *target,
148 size_t max) 149 size_t max)
149{ 150{
150 uint16_t alen; 151 uint16_t alen;
@@ -280,7 +281,8 @@ GNUNET_HELLO_create (const struct GNUNET_CRYPTO_EddsaPublicKey *publicKey,
280struct GNUNET_HELLO_Message * 281struct GNUNET_HELLO_Message *
281GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg, 282GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
282 int return_modified, 283 int return_modified,
283 GNUNET_HELLO_AddressIterator it, void *it_cls) 284 GNUNET_HELLO_AddressIterator it,
285 void *it_cls)
284{ 286{
285 struct GNUNET_HELLO_Address address; 287 struct GNUNET_HELLO_Address address;
286 uint16_t msize; 288 uint16_t msize;
@@ -347,16 +349,39 @@ GNUNET_HELLO_iterate_addresses (const struct GNUNET_HELLO_Message *msg,
347} 349}
348 350
349 351
352/**
353 * Closure for #get_match_exp().
354 */
350struct ExpireContext 355struct ExpireContext
351{ 356{
357 /**
358 * Address we are looking for.
359 */
352 const struct GNUNET_HELLO_Address *address; 360 const struct GNUNET_HELLO_Address *address;
361
362 /**
363 * Set to #GNUNET_YES if we found the @e address.
364 */
353 int found; 365 int found;
366
367 /**
368 * Set to the expiration of the match if @e found is #GNUNET_YES.
369 */
354 struct GNUNET_TIME_Absolute expiration; 370 struct GNUNET_TIME_Absolute expiration;
355}; 371};
356 372
357 373
374/**
375 * Store the expiration time of an address that matches the template.
376 *
377 * @param cls the `struct ExpireContext`
378 * @param address address to match against the template
379 * @param expiration expiration time of @a address, to store in @a cls
380 * @return #GNUNET_SYSERR if we found a matching address, #GNUNET_OK otherwise
381 */
358static int 382static int
359get_match_exp (void *cls, const struct GNUNET_HELLO_Address *address, 383get_match_exp (void *cls,
384 const struct GNUNET_HELLO_Address *address,
360 struct GNUNET_TIME_Absolute expiration) 385 struct GNUNET_TIME_Absolute expiration)
361{ 386{
362 struct ExpireContext *ec = cls; 387 struct ExpireContext *ec = cls;
@@ -371,21 +396,60 @@ get_match_exp (void *cls, const struct GNUNET_HELLO_Address *address,
371} 396}
372 397
373 398
399/**
400 *
401 */
374struct MergeContext 402struct MergeContext
375{ 403{
404 /**
405 *
406 */
376 const struct GNUNET_HELLO_Message *h1; 407 const struct GNUNET_HELLO_Message *h1;
408
409 /**
410 *
411 */
377 const struct GNUNET_HELLO_Message *h2; 412 const struct GNUNET_HELLO_Message *h2;
413
414 /**
415 *
416 */
378 const struct GNUNET_HELLO_Message *other; 417 const struct GNUNET_HELLO_Message *other;
418
419 /**
420 *
421 */
379 char *buf; 422 char *buf;
423
424 /**
425 *
426 */
380 size_t max; 427 size_t max;
428
429 /**
430 *
431 */
381 size_t ret; 432 size_t ret;
433
434 /**
435 *
436 */
382 int take_equal; 437 int take_equal;
383 438
384}; 439};
385 440
386 441
442/**
443 *
444 *
445 * @param cls
446 * @param address
447 * @param expiration
448 * @return
449 */
387static int 450static int
388copy_latest (void *cls, const struct GNUNET_HELLO_Address *address, 451copy_latest (void *cls,
452 const struct GNUNET_HELLO_Address *address,
389 struct GNUNET_TIME_Absolute expiration) 453 struct GNUNET_TIME_Absolute expiration)
390{ 454{
391 struct MergeContext *mc = cls; 455 struct MergeContext *mc = cls;
@@ -407,8 +471,13 @@ copy_latest (void *cls, const struct GNUNET_HELLO_Address *address,
407} 471}
408 472
409 473
474/**
475 *
476 */
410static ssize_t 477static ssize_t
411merge_addr (void *cls, size_t max, void *buf) 478merge_addr (void *cls,
479 size_t max,
480 void *buf)
412{ 481{
413 struct MergeContext *mc = cls; 482 struct MergeContext *mc = cls;
414 483
@@ -449,24 +518,46 @@ GNUNET_HELLO_merge (const struct GNUNET_HELLO_Message *h1,
449 else 518 else
450 friend_only = ntohl (h1->friend_only); /* Both HELLO's have the same type */ 519 friend_only = ntohl (h1->friend_only); /* Both HELLO's have the same type */
451 520
452 return GNUNET_HELLO_create (&h1->publicKey, &merge_addr, &mc, friend_only); 521 return GNUNET_HELLO_create (&h1->publicKey,
522 &merge_addr,
523 &mc,
524 friend_only);
453} 525}
454 526
455 527
528/**
529 *
530 */
456struct DeltaContext 531struct DeltaContext
457{ 532{
533 /**
534 *
535 */
458 struct GNUNET_TIME_Absolute expiration_limit; 536 struct GNUNET_TIME_Absolute expiration_limit;
459 537
538 /**
539 *
540 */
460 GNUNET_HELLO_AddressIterator it; 541 GNUNET_HELLO_AddressIterator it;
461 542
543 /**
544 * Closure for @e it.
545 */
462 void *it_cls; 546 void *it_cls;
463 547
548 /**
549 *
550 */
464 const struct GNUNET_HELLO_Message *old_hello; 551 const struct GNUNET_HELLO_Message *old_hello;
465}; 552};
466 553
467 554
555/**
556 *
557 */
468static int 558static int
469delta_match (void *cls, const struct GNUNET_HELLO_Address *address, 559delta_match (void *cls,
560 const struct GNUNET_HELLO_Address *address,
470 struct GNUNET_TIME_Absolute expiration) 561 struct GNUNET_TIME_Absolute expiration)
471{ 562{
472 struct DeltaContext *dc = cls; 563 struct DeltaContext *dc = cls;
@@ -475,7 +566,9 @@ delta_match (void *cls, const struct GNUNET_HELLO_Address *address,
475 566
476 ec.address = address; 567 ec.address = address;
477 ec.found = GNUNET_NO; 568 ec.found = GNUNET_NO;
478 GNUNET_HELLO_iterate_addresses (dc->old_hello, GNUNET_NO, &get_match_exp, 569 GNUNET_HELLO_iterate_addresses (dc->old_hello,
570 GNUNET_NO,
571 &get_match_exp,
479 &ec); 572 &ec);
480 if ((ec.found == GNUNET_YES) && 573 if ((ec.found == GNUNET_YES) &&
481 ((ec.expiration.abs_value_us > expiration.abs_value_us) || 574 ((ec.expiration.abs_value_us > expiration.abs_value_us) ||
@@ -495,15 +588,12 @@ delta_match (void *cls, const struct GNUNET_HELLO_Address *address,
495 * @param expiration_limit ignore addresses in old_hello 588 * @param expiration_limit ignore addresses in old_hello
496 * that expired before the given time stamp 589 * that expired before the given time stamp
497 * @param it iterator to call on each address 590 * @param it iterator to call on each address
498 * @param it_cls closure for it 591 * @param it_cls closure for @a it
499 */ 592 */
500void 593void
501GNUNET_HELLO_iterate_new_addresses (const struct GNUNET_HELLO_Message 594GNUNET_HELLO_iterate_new_addresses (const struct GNUNET_HELLO_Message *new_hello,
502 *new_hello, 595 const struct GNUNET_HELLO_Message *old_hello,
503 const struct GNUNET_HELLO_Message 596 struct GNUNET_TIME_Absolute expiration_limit,
504 *old_hello,
505 struct GNUNET_TIME_Absolute
506 expiration_limit,
507 GNUNET_HELLO_AddressIterator it, 597 GNUNET_HELLO_AddressIterator it,
508 void *it_cls) 598 void *it_cls)
509{ 599{
@@ -597,25 +687,50 @@ GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello)
597} 687}
598 688
599 689
690/**
691 *
692 */
600struct EqualsContext 693struct EqualsContext
601{ 694{
695 /**
696 *
697 */
602 struct GNUNET_TIME_Absolute expiration_limit; 698 struct GNUNET_TIME_Absolute expiration_limit;
603 699
700 /**
701 *
702 */
604 struct GNUNET_TIME_Absolute result; 703 struct GNUNET_TIME_Absolute result;
605 704
705 /**
706 *
707 */
606 const struct GNUNET_HELLO_Message *h2; 708 const struct GNUNET_HELLO_Message *h2;
607 709
710 /**
711 *
712 */
608 const struct GNUNET_HELLO_Address *address; 713 const struct GNUNET_HELLO_Address *address;
609 714
715 /**
716 *
717 */
610 struct GNUNET_TIME_Absolute expiration; 718 struct GNUNET_TIME_Absolute expiration;
611 719
720 /**
721 *
722 */
612 int found; 723 int found;
613 724
614}; 725};
615 726
616 727
728/**
729 *
730 */
617static int 731static int
618find_other_matching (void *cls, const struct GNUNET_HELLO_Address *address, 732find_other_matching (void *cls,
733 const struct GNUNET_HELLO_Address *address,
619 struct GNUNET_TIME_Absolute expiration) 734 struct GNUNET_TIME_Absolute expiration)
620{ 735{
621 struct EqualsContext *ec = cls; 736 struct EqualsContext *ec = cls;
@@ -633,8 +748,12 @@ find_other_matching (void *cls, const struct GNUNET_HELLO_Address *address,
633} 748}
634 749
635 750
751/**
752 *
753 */
636static int 754static int
637find_matching (void *cls, const struct GNUNET_HELLO_Address *address, 755find_matching (void *cls,
756 const struct GNUNET_HELLO_Address *address,
638 struct GNUNET_TIME_Absolute expiration) 757 struct GNUNET_TIME_Absolute expiration)
639{ 758{
640 struct EqualsContext *ec = cls; 759 struct EqualsContext *ec = cls;
@@ -687,17 +806,27 @@ GNUNET_HELLO_equals (const struct GNUNET_HELLO_Message *h1,
687 ec.expiration_limit = now; 806 ec.expiration_limit = now;
688 ec.result = GNUNET_TIME_UNIT_FOREVER_ABS; 807 ec.result = GNUNET_TIME_UNIT_FOREVER_ABS;
689 ec.h2 = h2; 808 ec.h2 = h2;
690 GNUNET_HELLO_iterate_addresses (h1, GNUNET_NO, &find_matching, &ec); 809 GNUNET_HELLO_iterate_addresses (h1,
810 GNUNET_NO,
811 &find_matching,
812 &ec);
691 if (ec.result.abs_value_us == GNUNET_TIME_UNIT_ZERO.rel_value_us) 813 if (ec.result.abs_value_us == GNUNET_TIME_UNIT_ZERO.rel_value_us)
692 return ec.result; 814 return ec.result;
693 ec.h2 = h1; 815 ec.h2 = h1;
694 GNUNET_HELLO_iterate_addresses (h2, GNUNET_NO, &find_matching, &ec); 816 GNUNET_HELLO_iterate_addresses (h2,
817 GNUNET_NO,
818 &find_matching,
819 &ec);
695 return ec.result; 820 return ec.result;
696} 821}
697 822
698 823
824/**
825 *
826 */
699static int 827static int
700find_max_expire (void *cls, const struct GNUNET_HELLO_Address *address, 828find_max_expire (void *cls,
829 const struct GNUNET_HELLO_Address *address,
701 struct GNUNET_TIME_Absolute expiration) 830 struct GNUNET_TIME_Absolute expiration)
702{ 831{
703 struct GNUNET_TIME_Absolute *max = cls; 832 struct GNUNET_TIME_Absolute *max = cls;
@@ -719,10 +848,14 @@ GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg)
719 struct GNUNET_TIME_Absolute ret; 848 struct GNUNET_TIME_Absolute ret;
720 849
721 ret.abs_value_us = 0; 850 ret.abs_value_us = 0;
722 GNUNET_HELLO_iterate_addresses (msg, GNUNET_NO, &find_max_expire, &ret); 851 GNUNET_HELLO_iterate_addresses (msg,
852 GNUNET_NO,
853 &find_max_expire,
854 &ret);
723 return ret; 855 return ret;
724} 856}
725 857
858
726/** 859/**
727 * GNUnet URIs are of the general form "gnunet://MODULE/IDENTIFIER". 860 * GNUnet URIs are of the general form "gnunet://MODULE/IDENTIFIER".
728 * The specific structure of "IDENTIFIER" depends on the module and 861 * The specific structure of "IDENTIFIER" depends on the module and
@@ -766,55 +899,19 @@ GNUNET_HELLO_get_last_expiration (const struct GNUNET_HELLO_Message *msg)
766 */ 899 */
767 900
768 901
769/* ************************* Compose HELLO URI ************************** */
770
771#if 0
772/**
773 * Replace all characters in the input 'in' according
774 * to the mapping. The mapping says to map each character
775 * in 'oldchars' to the corresponding character (by offset)
776 * in 'newchars'.
777 *
778 * @param in input string to remap
779 * @param oldchars characters to replace
780 * @param newchars replacement characters, must have same length as 'oldchars'
781 * @return copy of string with replacement applied.
782 */
783static char *
784map_characters (const char *in,
785 const char *oldchars,
786 const char *newchars)
787{
788 char *ret;
789 const char *off;
790 size_t i;
791
792 GNUNET_assert (strlen (oldchars) == strlen (newchars));
793 ret = GNUNET_strdup (in);
794 i = 0;
795 while (ret[i] != '\0')
796 {
797 off = strchr (oldchars, ret[i]);
798 if (NULL != off)
799 ret[i] = newchars[off - oldchars];
800 i++;
801 }
802 return ret;
803}
804#endif
805
806 902
807/** 903/**
808 * Function that is called on each address of this peer. 904 * Function that is called on each address of this peer.
809 * Expands the corresponding URI string. 905 * Expands the corresponding URI string.
810 * 906 *
811 * @param cls the 'GNUNET_HELLO_GetUriContext' 907 * @param cls the `struct GNUNET_HELLO_ComposeUriContext`
812 * @param address address to add 908 * @param address address to add
813 * @param expiration expiration time for the address 909 * @param expiration expiration time for the address
814 * @return GNUNET_OK (continue iteration). 910 * @return #GNUNET_OK (continue iteration).
815 */ 911 */
816static int 912static int
817add_address_to_uri (void *cls, const struct GNUNET_HELLO_Address *address, 913add_address_to_uri (void *cls,
914 const struct GNUNET_HELLO_Address *address,
818 struct GNUNET_TIME_Absolute expiration) 915 struct GNUNET_TIME_Absolute expiration)
819{ 916{
820 struct GNUNET_HELLO_ComposeUriContext *ctx = cls; 917 struct GNUNET_HELLO_ComposeUriContext *ctx = cls;
@@ -903,10 +1000,10 @@ GNUNET_HELLO_compose_uri (const struct GNUNET_HELLO_Message *hello,
903 * We're building a HELLO. Parse the next address from the 1000 * We're building a HELLO. Parse the next address from the
904 * parsing context and append it. 1001 * parsing context and append it.
905 * 1002 *
906 * @param cls the 'struct GNUNET_HELLO_AddressParsingContext' 1003 * @param cls the `struct GNUNET_HELLO_ParseUriContext`
907 * @param max number of bytes available for HELLO construction 1004 * @param max number of bytes available for HELLO construction
908 * @param buffer where to copy the next address (in binary format) 1005 * @param buffer where to copy the next address (in binary format)
909 * @return number of bytes added to buffer, GNUNET_SYSERR on error 1006 * @return number of bytes added to buffer, #GNUNET_SYSERR on error
910 */ 1007 */
911static ssize_t 1008static ssize_t
912add_address_to_hello (void *cls, size_t max, void *buffer) 1009add_address_to_hello (void *cls, size_t max, void *buffer)
@@ -926,7 +1023,6 @@ add_address_to_hello (void *cls, size_t max, void *buffer)
926 struct GNUNET_HELLO_Address haddr; 1023 struct GNUNET_HELLO_Address haddr;
927 ssize_t ret; 1024 ssize_t ret;
928 1025
929
930 if (NULL == ctx->pos) 1026 if (NULL == ctx->pos)
931 return GNUNET_SYSERR; 1027 return GNUNET_SYSERR;
932 if (GNUNET_HELLO_URI_SEP != ctx->pos[0]) 1028 if (GNUNET_HELLO_URI_SEP != ctx->pos[0])
@@ -1049,7 +1145,7 @@ add_address_to_hello (void *cls, size_t max, void *buffer)
1049 * @param pubkey Pointer to struct where public key is parsed 1145 * @param pubkey Pointer to struct where public key is parsed
1050 * @param hello Pointer to struct where hello message is parsed 1146 * @param hello Pointer to struct where hello message is parsed
1051 * @param plugins_find Function to find transport plugins by name 1147 * @param plugins_find Function to find transport plugins by name
1052 * @return GNUNET_OK on success, GNUNET_SYSERR if the URI was invalid, GNUNET_NO on other errors 1148 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the URI was invalid, #GNUNET_NO on other errors
1053 */ 1149 */
1054int 1150int
1055GNUNET_HELLO_parse_uri (const char *uri, 1151GNUNET_HELLO_parse_uri (const char *uri,