aboutsummaryrefslogtreecommitdiff
path: root/src/hello
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-04-10 21:05:27 +0000
committerChristian Grothoff <christian@grothoff.org>2010-04-10 21:05:27 +0000
commit8a9ac8c92b1fb30c91c700d42e84749cc8aabb68 (patch)
tree9736e38967822068abd3b8bc01b2d35931e881ff /src/hello
parent85a049155d73ab1001f417b0786b8aefbdd01fd2 (diff)
downloadgnunet-8a9ac8c92b1fb30c91c700d42e84749cc8aabb68.tar.gz
gnunet-8a9ac8c92b1fb30c91c700d42e84749cc8aabb68.zip
work on HELLO
Diffstat (limited to 'src/hello')
-rw-r--r--src/hello/hello.c122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/hello/hello.c b/src/hello/hello.c
index 4ddeebd03..51575ebaf 100644
--- a/src/hello/hello.c
+++ b/src/hello/hello.c
@@ -510,6 +510,7 @@ GNUNET_HELLO_get_id (const struct GNUNET_HELLO_Message *hello,
510 return GNUNET_OK; 510 return GNUNET_OK;
511} 511}
512 512
513
513/** 514/**
514 * Get the header from a HELLO message, used so other code 515 * Get the header from a HELLO message, used so other code
515 * can correctly send HELLO messages. 516 * can correctly send HELLO messages.
@@ -529,4 +530,125 @@ GNUNET_HELLO_get_header (struct GNUNET_HELLO_Message *hello)
529 return &hello->header; 530 return &hello->header;
530} 531}
531 532
533
534struct EqualsContext
535{
536 struct GNUNET_TIME_Absolute expiration_limit;
537
538 struct GNUNET_TIME_Absolute result;
539
540 const struct GNUNET_HELLO_Message *h2;
541
542 const char *tname;
543
544 const void *addr;
545
546 struct GNUNET_TIME_Absolute expiration;
547
548 size_t addrlen;
549
550 int found;
551};
552
553
554static int
555find_other_matching (void *cls,
556 const char *tname,
557 struct GNUNET_TIME_Absolute expiration,
558 const void *addr, size_t addrlen)
559{
560 struct EqualsContext *ec = cls;
561
562 if (expiration.value < ec->expiration_limit.value)
563 return GNUNET_YES;
564 if ( (addrlen == ec->addrlen) &&
565 (0 == strcmp (tname,
566 ec->tname)) &&
567 (0 == memcmp (addr,
568 ec->addr,
569 addrlen)) )
570 {
571 ec->found = GNUNET_YES;
572 if (expiration.value < ec->expiration.value)
573 {
574 ec->result = GNUNET_TIME_absolute_min (expiration,
575 ec->result);
576 }
577 return GNUNET_SYSERR;
578 }
579 return GNUNET_YES;
580}
581
582
583static int
584find_matching (void *cls,
585 const char *tname,
586 struct GNUNET_TIME_Absolute expiration,
587 const void *addr, size_t addrlen)
588{
589 struct EqualsContext *ec = cls;
590
591 if (expiration.value < ec->expiration_limit.value)
592 return GNUNET_YES;
593 ec->tname = tname;
594 ec->expiration = expiration;
595 ec->addr = addr;
596 ec->addrlen = addrlen;
597 ec->found = GNUNET_NO;
598 GNUNET_HELLO_iterate_addresses (ec->h2,
599 GNUNET_NO,
600 &find_other_matching,
601 ec);
602 if (ec->found == GNUNET_NO)
603 {
604 ec->result = GNUNET_TIME_UNIT_ZERO_ABS;
605 return GNUNET_SYSERR;
606 }
607 return GNUNET_OK;
608}
609
610/**
611 * Test if two HELLO messages contain the same addresses.
612 * If they only differ in expiration time, the lowest
613 * expiration time larger than 'now' where they differ
614 * is returned.
615 *
616 * @param h1 first HELLO message
617 * @param h2 the second HELLO message
618 * @param now time to use for deciding which addresses have
619 * expired and should not be considered at all
620 * @return absolute time zero if the two HELLOs are
621 * totally identical; smallest timestamp >= now if
622 * they only differ in timestamps;
623 * forever if the some addresses with expirations >= now
624 * do not match at all
625 */
626struct GNUNET_TIME_Absolute
627GNUNET_HELLO_equals (const struct
628 GNUNET_HELLO_Message *h1,
629 const struct
630 GNUNET_HELLO_Message *h2,
631 struct GNUNET_TIME_Absolute now)
632{
633 struct EqualsContext ec;
634
635 ec.expiration_limit = now;
636 ec.result = GNUNET_TIME_UNIT_FOREVER_ABS;
637 ec.h2 = h2;
638 GNUNET_HELLO_iterate_addresses (h1,
639 GNUNET_NO,
640 &find_matching,
641 &ec);
642 if (ec.result.value ==
643 GNUNET_TIME_UNIT_ZERO.value)
644 return ec.result;
645 ec.h2 = h1;
646 GNUNET_HELLO_iterate_addresses (h2,
647 GNUNET_NO,
648 &find_matching,
649 &ec);
650 return ec.result;
651}
652
653
532/* end of hello.c */ 654/* end of hello.c */