diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-03-14 14:15:50 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-03-14 14:15:50 +0000 |
commit | 07cee5298f5fba8009efd9a5b3137730dd01597c (patch) | |
tree | cf43105f7af7998470de62ef368c7a99ea026488 /src/dv | |
parent | c0ee9a86aba8adf73d03a5b7bfa4650a24028855 (diff) | |
download | gnunet-07cee5298f5fba8009efd9a5b3137730dd01597c.tar.gz gnunet-07cee5298f5fba8009efd9a5b3137730dd01597c.zip |
-towards actually using consensus
Diffstat (limited to 'src/dv')
-rw-r--r-- | src/dv/gnunet-service-dv.c | 104 |
1 files changed, 101 insertions, 3 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index 2bf923ccc..63f49f53a 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c | |||
@@ -26,6 +26,15 @@ | |||
26 | * | 26 | * |
27 | * @author Christian Grothoff | 27 | * @author Christian Grothoff |
28 | * @author Nathan Evans | 28 | * @author Nathan Evans |
29 | * | ||
30 | * TODO: | ||
31 | * - routing tables are not exchanged with direct neighbors | ||
32 | * - distance updates are not properly communicate to US by core, | ||
33 | * and conversely we don't give distance updates properly to the plugin yet | ||
34 | * - even local flow control (send ACK only after core took our message) is | ||
35 | * not implemented, but should be (easy fix) | ||
36 | * - we send 'ACK' even if a message was dropped due to no route (may | ||
37 | * be harmless, but should at least be documented) | ||
29 | */ | 38 | */ |
30 | #include "platform.h" | 39 | #include "platform.h" |
31 | #include "gnunet_util_lib.h" | 40 | #include "gnunet_util_lib.h" |
@@ -40,7 +49,7 @@ | |||
40 | /** | 49 | /** |
41 | * How often do we establish the consensu? | 50 | * How often do we establish the consensu? |
42 | */ | 51 | */ |
43 | #define GNUNET_DV_CONSENSUS_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)) | 52 | #define GNUNET_DV_CONSENSUS_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) |
44 | 53 | ||
45 | /** | 54 | /** |
46 | * Maximum number of messages we queue per peer. | 55 | * Maximum number of messages we queue per peer. |
@@ -744,6 +753,18 @@ move_route (struct Route *route, | |||
744 | 753 | ||
745 | 754 | ||
746 | /** | 755 | /** |
756 | * Start creating a new consensus from scratch. | ||
757 | * | ||
758 | * @param cls the 'struct DirectNeighbor' of the peer we're building | ||
759 | * a routing consensus with | ||
760 | * @param tc scheduler context | ||
761 | */ | ||
762 | static void | ||
763 | start_consensus (void *cls, | ||
764 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
765 | |||
766 | |||
767 | /** | ||
747 | * Method called whenever a peer connects. | 768 | * Method called whenever a peer connects. |
748 | * | 769 | * |
749 | * @param cls closure | 770 | * @param cls closure |
@@ -759,7 +780,7 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
759 | struct DirectNeighbor *neighbor; | 780 | struct DirectNeighbor *neighbor; |
760 | struct Route *route; | 781 | struct Route *route; |
761 | uint32_t distance; | 782 | uint32_t distance; |
762 | 783 | ||
763 | /* Check for connect to self message */ | 784 | /* Check for connect to self message */ |
764 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) | 785 | if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) |
765 | return; | 786 | return; |
@@ -789,10 +810,87 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
789 | GNUNET_free (route); | 810 | GNUNET_free (route); |
790 | } | 811 | } |
791 | route->next_hop = neighbor; | 812 | route->next_hop = neighbor; |
792 | // FIXME: begin exchange_routing_information! | 813 | neighbor->consensus_task = GNUNET_SCHEDULER_add_now (&start_consensus, |
814 | neighbor); | ||
815 | } | ||
816 | |||
817 | |||
818 | /** | ||
819 | * We inserted the last element into the consensus, get ready to | ||
820 | * insert the next element into the consensus or conclude if | ||
821 | * we're done. | ||
822 | * | ||
823 | * @param cls the 'struct DirectNeighbor' of the peer we're building | ||
824 | * a routing consensus with | ||
825 | * @param success GNUNET_OK if the last element was added successfully, | ||
826 | * GNUNET_SYSERR if we failed | ||
827 | */ | ||
828 | static void | ||
829 | insert_next_element (void *cls, | ||
830 | int success) | ||
831 | { | ||
832 | struct DirectNeighbor *neighbor = cls; | ||
833 | struct GNUNET_CONSENSUS_Element element; | ||
834 | |||
835 | // FIXME: initialize element... | ||
836 | GNUNET_CONSENSUS_insert (neighbor->consensus, | ||
837 | &element, | ||
838 | &insert_next_element, | ||
839 | neighbor); | ||
793 | } | 840 | } |
794 | 841 | ||
795 | 842 | ||
843 | /** | ||
844 | * We have learned a new route from the other peer. Add it to the | ||
845 | * route set we're building. | ||
846 | * | ||
847 | * @param cls the 'struct DirectNeighbor' we're building the consensus with | ||
848 | * @param element the new element we have learned | ||
849 | * @return GNUNET_OK if the valid is well-formed and should be added to the consensus, | ||
850 | * GNUNET_SYSERR if the element should be ignored and not be propagated | ||
851 | */ | ||
852 | static int | ||
853 | learn_route_cb (void *cls, | ||
854 | const struct GNUNET_CONSENSUS_Element *element) | ||
855 | { | ||
856 | GNUNET_break (0); // FIXME | ||
857 | return GNUNET_SYSERR; | ||
858 | } | ||
859 | |||
860 | |||
861 | /** | ||
862 | * Start creating a new consensus from scratch. | ||
863 | * | ||
864 | * @param cls the 'struct DirectNeighbor' of the peer we're building | ||
865 | * a routing consensus with | ||
866 | * @param tc scheduler context | ||
867 | */ | ||
868 | static void | ||
869 | start_consensus (void *cls, | ||
870 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
871 | { | ||
872 | struct DirectNeighbor *neighbor = cls; | ||
873 | struct GNUNET_HashCode session_id; | ||
874 | |||
875 | neighbor->consensus_task = GNUNET_SCHEDULER_NO_TASK; | ||
876 | GNUNET_assert (NULL == neighbor->consensus); | ||
877 | GNUNET_CRYPTO_hash_xor (&session_id, &my_identity.hashPubKey, &neighbor->peer.hashPubKey); // ARG order? | ||
878 | neighbor->consensus = GNUNET_CONSENSUS_create (cfg, | ||
879 | 1, | ||
880 | &neighbor->peer, | ||
881 | &session_id, | ||
882 | &learn_route_cb, | ||
883 | neighbor); | ||
884 | if (NULL == neighbor->consensus) | ||
885 | { | ||
886 | neighbor->consensus_task = GNUNET_SCHEDULER_add_delayed (GNUNET_DV_CONSENSUS_FREQUENCY, | ||
887 | &start_consensus, | ||
888 | neighbor); | ||
889 | return; | ||
890 | } | ||
891 | insert_next_element (neighbor, GNUNET_OK); | ||
892 | } | ||
893 | |||
796 | 894 | ||
797 | /** | 895 | /** |
798 | * Core handler for DV data messages. Whatever this message | 896 | * Core handler for DV data messages. Whatever this message |