aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-11-27 22:02:05 +0100
committerChristian Grothoff <christian@grothoff.org>2016-11-27 22:02:05 +0100
commitefa2e98f9b1231a76c023c0d67540da066b51742 (patch)
treecf3242463396d0301fadec0cc3aa2c6b044ba856
parentd74b18fc17793292761b02828a066a9f135c8df4 (diff)
downloadgnunet-efa2e98f9b1231a76c023c0d67540da066b51742.tar.gz
gnunet-efa2e98f9b1231a76c023c0d67540da066b51742.zip
towards implementing notification for peer addresses
-rw-r--r--src/nat/gnunet-service-nat.c116
1 files changed, 115 insertions, 1 deletions
diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c
index c3e134b35..e42a94ea4 100644
--- a/src/nat/gnunet-service-nat.c
+++ b/src/nat/gnunet-service-nat.c
@@ -127,6 +127,11 @@ struct LocalAddressList
127 */ 127 */
128 int af; 128 int af;
129 129
130 /**
131 * What type of address is this?
132 */
133 enum GNUNET_NAT_AddressClass ac;
134
130}; 135};
131 136
132 137
@@ -502,6 +507,7 @@ handle_test (void *cls,
502 507
503 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 508 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
504 "Received REQUEST_TEST message from client\n"); 509 "Received REQUEST_TEST message from client\n");
510 /* FIXME: actually process test request */
505 GNUNET_SERVICE_client_continue (ch->client); 511 GNUNET_SERVICE_client_continue (ch->client);
506} 512}
507 513
@@ -657,6 +663,70 @@ ifc_proc (void *cls,
657 663
658 664
659/** 665/**
666 * Notify all clients about a change in the list
667 * of addresses this peer has.
668 *
669 * @param delta the entry in the list that changed
670 * @param add #GNUNET_YES to add, #GNUNET_NO to remove
671 */
672static void
673notify_clients (struct LocalAddressList *delta,
674 int add)
675{
676 for (struct ClientHandle *ch = ch_head;
677 NULL != ch;
678 ch = ch->next)
679 {
680 struct GNUNET_MQ_Envelope *env;
681 struct GNUNET_NAT_AddressChangeNotificationMessage *msg;
682 void *addr;
683 struct sockaddr_in v4;
684 struct sockaddr_in6 v6;
685 size_t alen;
686
687 if (0 == (ch->flags & GNUNET_NAT_RF_ADDRESSES))
688 continue;
689 switch (delta->af)
690 {
691 case AF_INET:
692 alen = sizeof (struct sockaddr_in);
693 addr = &v4;
694 memset (&v4, 0, sizeof (v4));
695 v4.sin_family = AF_INET;
696 GNUNET_memcpy (&v4.sin_addr,
697 delta->addr,
698 sizeof (struct in_addr));
699 /* FIXME: set port */
700 break;
701 case AF_INET6:
702 alen = sizeof (struct sockaddr_in6);
703 addr = &v6;
704 memset (&v6, 0, sizeof (v6));
705 v6.sin6_family = AF_INET6;
706 GNUNET_memcpy (&v6.sin6_addr,
707 delta->addr,
708 sizeof (struct in6_addr));
709 /* FIXME: set port, and link/interface! */
710 break;
711 default:
712 GNUNET_break (0);
713 continue;
714 }
715 env = GNUNET_MQ_msg_extra (msg,
716 alen,
717 GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE);
718 msg->add_remove = htonl (add);
719 msg->addr_class = htonl (delta->ac);
720 GNUNET_memcpy (&msg[1],
721 addr,
722 alen);
723 GNUNET_MQ_send (ch->mq,
724 env);
725 }
726}
727
728
729/**
660 * Task we run periodically to scan for network interfaces. 730 * Task we run periodically to scan for network interfaces.
661 * 731 *
662 * @param cls NULL 732 * @param cls NULL
@@ -665,6 +735,7 @@ static void
665run_scan (void *cls) 735run_scan (void *cls)
666{ 736{
667 struct IfcProcContext ifc_ctx; 737 struct IfcProcContext ifc_ctx;
738 int found;
668 739
669 scan_task = GNUNET_SCHEDULER_add_delayed (SCAN_FREQ, 740 scan_task = GNUNET_SCHEDULER_add_delayed (SCAN_FREQ,
670 &run_scan, 741 &run_scan,
@@ -674,7 +745,50 @@ run_scan (void *cls)
674 sizeof (ifc_ctx)); 745 sizeof (ifc_ctx));
675 GNUNET_OS_network_interfaces_list (&ifc_proc, 746 GNUNET_OS_network_interfaces_list (&ifc_proc,
676 &ifc_ctx); 747 &ifc_ctx);
677 /* FIXME: notify clients of changes in lal-DLL */ 748 for (struct LocalAddressList *lal = lal_head;
749 NULL != lal;
750 lal = lal->next)
751 {
752 found = GNUNET_NO;
753 for (struct LocalAddressList *pos = ifc_ctx.lal_head;
754 NULL != pos;
755 pos = pos->next)
756 {
757 if ( (pos->af == lal->af) &&
758 (0 == memcmp (lal->addr,
759 pos->addr,
760 (AF_INET == lal->af)
761 ? sizeof (struct in_addr)
762 : sizeof (struct in6_addr))) )
763 found = GNUNET_YES;
764 }
765 if (GNUNET_NO == found)
766 notify_clients (lal,
767 GNUNET_NO);
768 }
769
770 for (struct LocalAddressList *pos = ifc_ctx.lal_head;
771 NULL != pos;
772 pos = pos->next)
773 {
774 found = GNUNET_NO;
775 for (struct LocalAddressList *lal = lal_head;
776 NULL != lal;
777 lal = lal->next)
778 {
779 if ( (pos->af == lal->af) &&
780 (0 == memcmp (lal->addr,
781 pos->addr,
782 (AF_INET == lal->af)
783 ? sizeof (struct in_addr)
784 : sizeof (struct in6_addr))) )
785 found = GNUNET_YES;
786 }
787 if (GNUNET_NO == found)
788 notify_clients (pos,
789 GNUNET_YES);
790 }
791
678 destroy_lal (); 792 destroy_lal ();
679 lal_head = ifc_ctx.lal_head; 793 lal_head = ifc_ctx.lal_head;
680 lal_tail = ifc_ctx.lal_tail; 794 lal_tail = ifc_ctx.lal_tail;