aboutsummaryrefslogtreecommitdiff
path: root/src/topology/gnunet-daemon-topology.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/topology/gnunet-daemon-topology.c')
-rw-r--r--src/topology/gnunet-daemon-topology.c169
1 files changed, 10 insertions, 159 deletions
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index 61bcce502..efabac0fc 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -23,23 +23,13 @@
23 * @brief code for maintaining the overlay topology 23 * @brief code for maintaining the overlay topology
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * 25 *
26 * This daemon combines three functions: 26 * This daemon combines one Function:
27 * - suggesting to ATS which peers we might want to connect to
28 * - enforcing the F2F restrictions (by blacklisting)
29 * - gossping HELLOs 27 * - gossping HELLOs
30 * 28 *
31 * All three require similar information (who are our friends
32 * impacts connectivity suggestions; connectivity suggestions
33 * should consider blacklisting; connectivity suggestions
34 * should consider available/known HELLOs; gossip requires
35 * connectivity data; connectivity suggestions require
36 * connectivity data), which is why they are combined in this
37 * program.
38 */ 29 */
39#include "platform.h" 30#include "platform.h"
40#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
41#include "gnunet_hello_uri_lib.h" 32#include "gnunet_hello_uri_lib.h"
42#include "gnunet_friends_lib.h"
43#include "gnunet_constants.h" 33#include "gnunet_constants.h"
44#include "gnunet_core_service.h" 34#include "gnunet_core_service.h"
45#include "gnunet_protocols.h" 35#include "gnunet_protocols.h"
@@ -48,9 +38,6 @@
48#include "gnunet_transport_application_service.h" 38#include "gnunet_transport_application_service.h"
49 39
50 40
51// TODO Remove all occurrencies of friends_only and minimum_friend_count.
52
53
54/** 41/**
55 * At what frequency do we sent HELLOs to a peer? 42 * At what frequency do we sent HELLOs to a peer?
56 */ 43 */
@@ -65,7 +52,7 @@
65 52
66 53
67/** 54/**
68 * Record for neighbours, friends and blacklisted peers. 55 * Record for neighbours and blacklisted peers.
69 */ 56 */
70struct Peer 57struct Peer
71{ 58{
@@ -117,10 +104,6 @@ struct Peer
117 */ 104 */
118 uint32_t strength; 105 uint32_t strength;
119 106
120 /**
121 * Is this peer listed here because it is a friend?
122 */
123 int is_friend;
124}; 107};
125 108
126 109
@@ -168,7 +151,7 @@ static struct GNUNET_PeerIdentity my_identity;
168static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key; 151static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
169 152
170/** 153/**
171 * All of our friends, all of our current neighbours and all peers for 154 * All of our current neighbours and all peers for
172 * which we have HELLOs. So pretty much everyone. Maps peer identities 155 * which we have HELLOs. So pretty much everyone. Maps peer identities
173 * to `struct Peer *` values. 156 * to `struct Peer *` values.
174 */ 157 */
@@ -186,18 +169,7 @@ static struct GNUNET_STATISTICS_Handle *stats;
186static struct GNUNET_SCHEDULER_Task *add_task; 169static struct GNUNET_SCHEDULER_Task *add_task;
187 170
188/** 171/**
189 * Flag to disallow non-friend connections (pure F2F mode). 172 * Number of peers that we are currently connected to.
190 */
191static int friends_only;
192
193/**
194 * Minimum number of friends to have in the
195 * connection set before we allow non-friends.
196 */
197static unsigned int minimum_friend_count;
198
199/**
200 * Number of peers (friends and others) that we are currently connected to.
201 */ 173 */
202static unsigned int connection_count; 174static unsigned int connection_count;
203 175
@@ -207,12 +179,6 @@ static unsigned int connection_count;
207static unsigned int target_connection_count; 179static unsigned int target_connection_count;
208 180
209/** 181/**
210 * Number of friends that we are currently connected to.
211 */
212static unsigned int friend_count;
213
214
215/**
216 * Free all resources associated with the given peer. 182 * Free all resources associated with the given peer.
217 * 183 *
218 * @param cls closure (not used) 184 * @param cls closure (not used)
@@ -271,15 +237,6 @@ attempt_connect (struct Peer *pos)
271 strength = 1; 237 strength = 1;
272 else 238 else
273 strength = 0; 239 strength = 0;
274 if ((friend_count < minimum_friend_count) || (GNUNET_YES == friends_only))
275 {
276 if (pos->is_friend)
277 strength += 10; /* urgently needed */
278 else
279 strength = 0; /* disallowed */
280 }
281 if (pos->is_friend)
282 strength *= 2; /* friends always count more */
283 if (NULL != pos->mq) 240 if (NULL != pos->mq)
284 strength *= 2; /* existing connections preferred */ 241 strength *= 2; /* existing connections preferred */
285 if (strength == pos->strength) 242 if (strength == pos->strength)
@@ -315,19 +272,16 @@ attempt_connect (struct Peer *pos)
315 * 272 *
316 * @param peer identity of the new entry 273 * @param peer identity of the new entry
317 * @param hello hello message, can be NULL 274 * @param hello hello message, can be NULL
318 * @param is_friend is the new entry for a friend?
319 * @return the new entry 275 * @return the new entry
320 */ 276 */
321static struct Peer * 277static struct Peer *
322make_peer (const struct GNUNET_PeerIdentity *peer, 278make_peer (const struct GNUNET_PeerIdentity *peer,
323 const struct GNUNET_MessageHeader *hello, 279 const struct GNUNET_MessageHeader *hello)
324 int is_friend)
325{ 280{
326 struct Peer *ret; 281 struct Peer *ret;
327 282
328 ret = GNUNET_new (struct Peer); 283 ret = GNUNET_new (struct Peer);
329 ret->pid = *peer; 284 ret->pid = *peer;
330 ret->is_friend = is_friend;
331 if (NULL != hello) 285 if (NULL != hello)
332 { 286 {
333 ret->hello = GNUNET_malloc (ntohs (hello->size)); 287 ret->hello = GNUNET_malloc (ntohs (hello->size));
@@ -571,22 +525,13 @@ connect_notify (void *cls,
571 pos = GNUNET_CONTAINER_multipeermap_get (peers, peer); 525 pos = GNUNET_CONTAINER_multipeermap_get (peers, peer);
572 if (NULL == pos) 526 if (NULL == pos)
573 { 527 {
574 pos = make_peer (peer, NULL, GNUNET_NO); 528 pos = make_peer (peer, NULL);
575 } 529 }
576 else 530 else
577 { 531 {
578 GNUNET_assert (NULL == pos->mq); 532 GNUNET_assert (NULL == pos->mq);
579 } 533 }
580 pos->mq = mq; 534 pos->mq = mq;
581 if (pos->is_friend)
582 {
583 friend_count++;
584
585 GNUNET_STATISTICS_set (stats,
586 gettext_noop ("# friends connected"),
587 friend_count,
588 GNUNET_NO);
589 }
590 reschedule_hellos (NULL, peer, pos); 535 reschedule_hellos (NULL, peer, pos);
591 return pos; 536 return pos;
592} 537}
@@ -659,16 +604,7 @@ disconnect_notify (void *cls,
659 gettext_noop ("# peers connected"), 604 gettext_noop ("# peers connected"),
660 connection_count, 605 connection_count,
661 GNUNET_NO); 606 GNUNET_NO);
662 if (pos->is_friend) 607 if ((connection_count < target_connection_count) &&
663 {
664 friend_count--;
665 GNUNET_STATISTICS_set (stats,
666 gettext_noop ("# friends connected"),
667 friend_count,
668 GNUNET_NO);
669 }
670 if (((connection_count < target_connection_count) ||
671 (friend_count < minimum_friend_count)) &&
672 (NULL == add_task)) 608 (NULL == add_task))
673 add_task = GNUNET_SCHEDULER_add_now (&add_peer_task, NULL); 609 add_task = GNUNET_SCHEDULER_add_now (&add_peer_task, NULL);
674 610
@@ -733,7 +669,7 @@ consider_for_advertising (const struct GNUNET_MessageHeader *hello)
733 peer = GNUNET_CONTAINER_multipeermap_get (peers, pid); 669 peer = GNUNET_CONTAINER_multipeermap_get (peers, pid);
734 if (NULL == peer) 670 if (NULL == peer)
735 { 671 {
736 peer = make_peer (pid, hello, GNUNET_NO); 672 peer = make_peer (pid, hello);
737 } 673 }
738 else if (NULL != peer->hello) 674 else if (NULL != peer->hello)
739 { 675 {
@@ -830,7 +766,7 @@ process_peer (void *cls,
830 GNUNET_CONTAINER_bloomfilter_free (pos->filter); 766 GNUNET_CONTAINER_bloomfilter_free (pos->filter);
831 pos->filter = NULL; 767 pos->filter = NULL;
832 } 768 }
833 if ((NULL == pos->mq) && (GNUNET_NO == pos->is_friend)) 769 if (NULL == pos->mq)
834 free_peer (NULL, &pos->pid, pos); 770 free_peer (NULL, &pos->pid, pos);
835 } 771 }
836 return; 772 return;
@@ -838,7 +774,7 @@ process_peer (void *cls,
838 consider_for_advertising (hello); 774 consider_for_advertising (hello);
839 pos = GNUNET_CONTAINER_multipeermap_get (peers, peer); 775 pos = GNUNET_CONTAINER_multipeermap_get (peers, peer);
840 if (NULL == pos) 776 if (NULL == pos)
841 pos = make_peer (peer, hello, GNUNET_NO); 777 pos = make_peer (peer, hello);
842 attempt_connect (pos); 778 attempt_connect (pos);
843} 779}
844 780
@@ -879,70 +815,6 @@ core_init (void *cls, const struct GNUNET_PeerIdentity *my_id)
879 815
880 816
881/** 817/**
882 * Process friend found in FRIENDS file.
883 *
884 * @param cls pointer to an `unsigned int` to be incremented per friend found
885 * @param pid identity of the friend
886 */
887static void
888handle_friend (void *cls, const struct GNUNET_PeerIdentity *pid)
889{
890 unsigned int *entries_found = cls;
891 struct Peer *fl;
892
893 if (0 == GNUNET_memcmp (pid, &my_identity))
894 {
895 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
896 _ ("Found myself `%s' in friend list (useless, ignored)\n"),
897 GNUNET_i2s (pid));
898 return;
899 }
900 (*entries_found)++;
901 fl = make_peer (pid, NULL, GNUNET_YES);
902 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
903 _ ("Found friend `%s' in configuration\n"),
904 GNUNET_i2s (&fl->pid));
905}
906
907
908/**
909 * Read the friends file.
910 */
911static void
912read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
913{
914 unsigned int entries_found;
915
916 entries_found = 0;
917 if (GNUNET_OK != GNUNET_FRIENDS_parse (cfg, &handle_friend, &entries_found))
918 {
919 if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0))
920 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
921 _ ("Encountered errors parsing friends list!\n"));
922 }
923 GNUNET_STATISTICS_update (stats,
924 gettext_noop ("# friends in configuration"),
925 entries_found,
926 GNUNET_NO);
927 if ((minimum_friend_count > entries_found) && (GNUNET_NO == friends_only))
928 {
929 GNUNET_log (
930 GNUNET_ERROR_TYPE_WARNING,
931 _ (
932 "Fewer friends specified than required by minimum friend count. Will only connect to friends.\n"));
933 }
934 if ((minimum_friend_count > target_connection_count) &&
935 (GNUNET_NO == friends_only))
936 {
937 GNUNET_log (
938 GNUNET_ERROR_TYPE_WARNING,
939 _ (
940 "More friendly connections required than target total number of connections.\n"));
941 }
942}
943
944
945/**
946 * This function is called whenever an encrypted HELLO message is 818 * This function is called whenever an encrypted HELLO message is
947 * received. 819 * received.
948 * 820 *
@@ -998,20 +870,6 @@ handle_hello (void *cls, const struct GNUNET_MessageHeader *message)
998 gettext_noop ("# HELLO messages received"), 870 gettext_noop ("# HELLO messages received"),
999 1, 871 1,
1000 GNUNET_NO); 872 GNUNET_NO);
1001 peer = GNUNET_CONTAINER_multipeermap_get (peers, pid);
1002 if (NULL == peer)
1003 {
1004 if ((GNUNET_YES == friends_only) || (friend_count < minimum_friend_count))
1005 return;
1006 }
1007 else
1008 {
1009 if ((GNUNET_YES != peer->is_friend) && (GNUNET_YES == friends_only))
1010 return;
1011 if ((GNUNET_YES != peer->is_friend) &&
1012 (friend_count < minimum_friend_count))
1013 return;
1014 }
1015 GNUNET_HELLO_builder_from_msg (message); 873 GNUNET_HELLO_builder_from_msg (message);
1016 shc = GNUNET_PEERSTORE_hello_add (ps, message, &shc_cont, shc); 874 shc = GNUNET_PEERSTORE_hello_add (ps, message, &shc_cont, shc);
1017 GNUNET_HELLO_builder_free (builder); 875 GNUNET_HELLO_builder_free (builder);
@@ -1094,7 +952,6 @@ run (void *cls,
1094 GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); 952 GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg);
1095 stats = GNUNET_STATISTICS_create ("topology", cfg); 953 stats = GNUNET_STATISTICS_create ("topology", cfg);
1096 954
1097 minimum_friend_count = 0;
1098 if (GNUNET_OK != 955 if (GNUNET_OK !=
1099 GNUNET_CONFIGURATION_get_value_number (cfg, 956 GNUNET_CONFIGURATION_get_value_number (cfg,
1100 "TOPOLOGY", 957 "TOPOLOGY",
@@ -1104,12 +961,6 @@ run (void *cls,
1104 target_connection_count = (unsigned int) opt; 961 target_connection_count = (unsigned int) opt;
1105 peers = GNUNET_CONTAINER_multipeermap_create (target_connection_count * 2, 962 peers = GNUNET_CONTAINER_multipeermap_create (target_connection_count * 2,
1106 GNUNET_NO); 963 GNUNET_NO);
1107 read_friends_file (cfg);
1108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1109 "Topology would like %u connections with at least %u friends\n",
1110 target_connection_count,
1111 minimum_friend_count);
1112
1113 transport = GNUNET_TRANSPORT_application_init (cfg); 964 transport = GNUNET_TRANSPORT_application_init (cfg);
1114 ps = GNUNET_PEERSTORE_connect (cfg); 965 ps = GNUNET_PEERSTORE_connect (cfg);
1115 handle = GNUNET_CORE_connect (cfg, 966 handle = GNUNET_CORE_connect (cfg,