aboutsummaryrefslogtreecommitdiff
path: root/src/topology
diff options
context:
space:
mode:
authorNils Durner <durner@gnunet.org>2009-06-15 20:11:51 +0000
committerNils Durner <durner@gnunet.org>2009-06-15 20:11:51 +0000
commit1088905b5a89a24706d2c1877d289589e3f3c222 (patch)
tree38ec7cdc1b80502aa950c68ebefe1e3f42efa14b /src/topology
parent7e3df72d6b8a32b15b02110b54c77f77e28928a2 (diff)
downloadgnunet-1088905b5a89a24706d2c1877d289589e3f3c222.tar.gz
gnunet-1088905b5a89a24706d2c1877d289589e3f3c222.zip
more complete DISK API
Diffstat (limited to 'src/topology')
-rw-r--r--src/topology/gnunet-daemon-topology.c80
1 files changed, 40 insertions, 40 deletions
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c
index 0ef896714..f4884e00d 100644
--- a/src/topology/gnunet-daemon-topology.c
+++ b/src/topology/gnunet-daemon-topology.c
@@ -38,26 +38,26 @@
38/** 38/**
39 * For how long do we blacklist a peer after a failed 39 * For how long do we blacklist a peer after a failed
40 * connection attempt? 40 * connection attempt?
41 */ 41 */
42#define BLACKLIST_AFTER_ATTEMPT GNUNET_TIME_UNIT_HOURS 42#define BLACKLIST_AFTER_ATTEMPT GNUNET_TIME_UNIT_HOURS
43 43
44/** 44/**
45 * For how long do we blacklist a friend after a failed 45 * For how long do we blacklist a friend after a failed
46 * connection attempt? 46 * connection attempt?
47 */ 47 */
48#define BLACKLIST_AFTER_ATTEMPT_FRIEND GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 48#define BLACKLIST_AFTER_ATTEMPT_FRIEND GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15)
49 49
50/** 50/**
51 * How frequently are we allowed to ask PEERINFO for more 51 * How frequently are we allowed to ask PEERINFO for more
52 * HELLO's to advertise (at most)? 52 * HELLO's to advertise (at most)?
53 */ 53 */
54#define MIN_HELLO_GATHER_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 27) 54#define MIN_HELLO_GATHER_DELAY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 27)
55 55
56/** 56/**
57 * How often do we at most advertise the same HELLO to the same peer? 57 * How often do we at most advertise the same HELLO to the same peer?
58 * Also used to remove HELLOs of peers that PEERINFO no longer lists 58 * Also used to remove HELLOs of peers that PEERINFO no longer lists
59 * from our cache. 59 * from our cache.
60 */ 60 */
61#define HELLO_ADVERTISEMENT_MIN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12) 61#define HELLO_ADVERTISEMENT_MIN_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12)
62 62
63 63
@@ -97,7 +97,7 @@ struct PeerList
97 * ID of the peer. 97 * ID of the peer.
98 */ 98 */
99 struct GNUNET_PeerIdentity id; 99 struct GNUNET_PeerIdentity id;
100 100
101}; 101};
102 102
103 103
@@ -122,12 +122,12 @@ struct HelloList
122 * this HELLO. 122 * this HELLO.
123 */ 123 */
124 struct GNUNET_CONTAINER_BloomFilter *filter; 124 struct GNUNET_CONTAINER_BloomFilter *filter;
125 125
126 /** 126 /**
127 * What peer is this HELLO for? 127 * What peer is this HELLO for?
128 */ 128 */
129 struct GNUNET_PeerIdentity id; 129 struct GNUNET_PeerIdentity id;
130 130
131 /** 131 /**
132 * When should we remove this entry from the linked list (either 132 * When should we remove this entry from the linked list (either
133 * resetting the filter or possibly eliminating it for good because 133 * resetting the filter or possibly eliminating it for good because
@@ -152,12 +152,12 @@ static struct GNUNET_SCHEDULER_Handle * sched;
152 * Our configuration. 152 * Our configuration.
153 */ 153 */
154static struct GNUNET_CONFIGURATION_Handle * cfg; 154static struct GNUNET_CONFIGURATION_Handle * cfg;
155 155
156/** 156/**
157 * Handle to the core API. 157 * Handle to the core API.
158 */ 158 */
159static struct GNUNET_CORE_Handle *handle; 159static struct GNUNET_CORE_Handle *handle;
160 160
161/** 161/**
162 * Handle to the transport API. 162 * Handle to the transport API.
163 */ 163 */
@@ -167,7 +167,7 @@ static struct GNUNET_TRANSPORT_Handle *transport;
167 * Identity of this peer. 167 * Identity of this peer.
168 */ 168 */
169static struct GNUNET_PeerIdentity my_identity; 169static struct GNUNET_PeerIdentity my_identity;
170 170
171/** 171/**
172 * Linked list of all of our friends and all of our current 172 * Linked list of all of our friends and all of our current
173 * neighbours. 173 * neighbours.
@@ -194,17 +194,17 @@ static unsigned int minimum_friend_count;
194 * Number of peers (friends and others) that we are currently connected to. 194 * Number of peers (friends and others) that we are currently connected to.
195 */ 195 */
196static unsigned int connection_count; 196static unsigned int connection_count;
197 197
198/** 198/**
199 * Target number of connections. 199 * Target number of connections.
200 */ 200 */
201static unsigned int target_connection_count; 201static unsigned int target_connection_count;
202 202
203/** 203/**
204 * Number of friends that we are currently connected to. 204 * Number of friends that we are currently connected to.
205 */ 205 */
206static unsigned int friend_count; 206static unsigned int friend_count;
207 207
208/** 208/**
209 * Should the topology daemon try to establish connections? 209 * Should the topology daemon try to establish connections?
210 */ 210 */
@@ -239,7 +239,7 @@ force_disconnect (const struct GNUNET_PeerIdentity *peer)
239 * Function called by core when our attempt to connect 239 * Function called by core when our attempt to connect
240 * succeeded. Does nothing. 240 * succeeded. Does nothing.
241 */ 241 */
242static size_t 242static size_t
243ready_callback (void *cls, 243ready_callback (void *cls,
244 size_t size, void *buf) 244 size_t size, void *buf)
245{ 245{
@@ -346,7 +346,7 @@ static void connect_notify (void *cls,
346 GNUNET_assert (GNUNET_NO == pos->is_connected); 346 GNUNET_assert (GNUNET_NO == pos->is_connected);
347 pos->is_connected = GNUNET_YES; 347 pos->is_connected = GNUNET_YES;
348 pos->blacklisted_until.value = 0; /* remove blacklisting */ 348 pos->blacklisted_until.value = 0; /* remove blacklisting */
349 friend_count++; 349 friend_count++;
350 return; 350 return;
351 } 351 }
352 pos = pos->next; 352 pos = pos->next;
@@ -364,8 +364,8 @@ static void connect_notify (void *cls,
364/** 364/**
365 * Disconnect from all non-friends (we're below quota). 365 * Disconnect from all non-friends (we're below quota).
366 */ 366 */
367static void 367static void
368drop_non_friends () 368drop_non_friends ()
369{ 369{
370 struct PeerList *pos; 370 struct PeerList *pos;
371 371
@@ -427,7 +427,7 @@ static void disconnect_notify (void *cls,
427 } 427 }
428 prev = pos; 428 prev = pos;
429 pos = pos->next; 429 pos = pos->next;
430 } 430 }
431 GNUNET_break (0); 431 GNUNET_break (0);
432} 432}
433 433
@@ -444,12 +444,12 @@ find_more_peers (void *cls,
444/** 444/**
445 * Determine when we should try again to find more peers and 445 * Determine when we should try again to find more peers and
446 * schedule the task. 446 * schedule the task.
447 */ 447 */
448static void 448static void
449schedule_peer_search () 449schedule_peer_search ()
450{ 450{
451 struct GNUNET_TIME_Relative delay; 451 struct GNUNET_TIME_Relative delay;
452 452
453 /* Typically, we try again every 15 minutes; the minimum period is 453 /* Typically, we try again every 15 minutes; the minimum period is
454 15s; if we are above the connection target, we reduce re-trying 454 15s; if we are above the connection target, we reduce re-trying
455 by the square of how much we are above; so for example, with 200% 455 by the square of how much we are above; so for example, with 200%
@@ -473,8 +473,8 @@ schedule_peer_search ()
473 473
474 474
475/** 475/**
476 * Iterator called on each address. 476 * Iterator called on each address.
477 * 477 *
478 * @param cls flag that we will set if we see any addresses. 478 * @param cls flag that we will set if we see any addresses.
479 */ 479 */
480static int 480static int
@@ -526,18 +526,18 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello)
526 memcpy (&pos->msg, hello, size); 526 memcpy (&pos->msg, hello, size);
527 pos->id = pid; 527 pos->id = pid;
528 pos->expiration = GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY); 528 pos->expiration = GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY);
529 /* 2^{-5} chance of not sending a HELLO to a peer is 529 /* 2^{-5} chance of not sending a HELLO to a peer is
530 acceptably small (if the filter is 50% full); 530 acceptably small (if the filter is 50% full);
531 64 bytes of memory are small compared to the rest 531 64 bytes of memory are small compared to the rest
532 of the data structure and would only really become 532 of the data structure and would only really become
533 "useless" once a HELLO has been passed on to ~100 533 "useless" once a HELLO has been passed on to ~100
534 other peers, which is likely more than enough in 534 other peers, which is likely more than enough in
535 any case; hence 64, 5 as bloomfilter parameters. */ 535 any case; hence 64, 5 as bloomfilter parameters. */
536 pos->filter = GNUNET_CONTAINER_bloomfilter_load (NULL, 64, 5); 536 pos->filter = GNUNET_CONTAINER_bloomfilter_load (NULL, 64, 5);
537 /* never send a peer its own HELLO */ 537 /* never send a peer its own HELLO */
538 GNUNET_CONTAINER_bloomfilter_add (pos->filter, &pos->id.hashPubKey); 538 GNUNET_CONTAINER_bloomfilter_add (pos->filter, &pos->id.hashPubKey);
539 pos->next = hellos; 539 pos->next = hellos;
540 hellos = pos; 540 hellos = pos;
541} 541}
542 542
543 543
@@ -585,7 +585,7 @@ process_peer (void *cls,
585 } 585 }
586 } 586 }
587 pos = pos->next; 587 pos = pos->next;
588 } 588 }
589 if (GNUNET_YES == friends_only) 589 if (GNUNET_YES == friends_only)
590 return; 590 return;
591 if (friend_count < minimum_friend_count) 591 if (friend_count < minimum_friend_count)
@@ -700,7 +700,7 @@ core_init (void *cls,
700 { 700 {
701 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 701 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
702 _("Failed to connect to core service, can not manage topology!\n")); 702 _("Failed to connect to core service, can not manage topology!\n"));
703 return; 703 return;
704 } 704 }
705 handle = server; 705 handle = server;
706 my_identity = *my_id; 706 my_identity = *my_id;
@@ -744,7 +744,7 @@ read_friends_file (struct GNUNET_CONFIGURATION_Handle *cfg)
744 "FRIENDS", 744 "FRIENDS",
745 &fn); 745 &fn);
746 if (GNUNET_OK != GNUNET_DISK_file_test (fn)) 746 if (GNUNET_OK != GNUNET_DISK_file_test (fn))
747 GNUNET_DISK_file_write (fn, NULL, 0, "600"); 747 GNUNET_DISK_fn_write (fn, NULL, 0, "600");
748 if (0 != STAT (fn, &frstat)) 748 if (0 != STAT (fn, &frstat))
749 { 749 {
750 if ((friends_only) || (minimum_friend_count > 0)) 750 if ((friends_only) || (minimum_friend_count > 0))
@@ -761,11 +761,11 @@ read_friends_file (struct GNUNET_CONFIGURATION_Handle *cfg)
761 _("Friends file `%s' is empty.\n"), 761 _("Friends file `%s' is empty.\n"),
762 fn); 762 fn);
763 GNUNET_free (fn); 763 GNUNET_free (fn);
764 return; 764 return;
765 } 765 }
766 data = GNUNET_malloc_large (frstat.st_size); 766 data = GNUNET_malloc_large (frstat.st_size);
767 if (frstat.st_size != 767 if (frstat.st_size !=
768 GNUNET_DISK_file_read (fn, frstat.st_size, data)) 768 GNUNET_DISK_fn_read (fn, data, frstat.st_size))
769 { 769 {
770 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 770 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
771 _("Failed to read friends list from `%s'\n"), fn); 771 _("Failed to read friends list from `%s'\n"), fn);
@@ -914,10 +914,10 @@ hello_advertising (void *cls,
914 while (NULL != (pos = next)) 914 while (NULL != (pos = next))
915 { 915 {
916 next = pos->next; 916 next = pos->next;
917 if (GNUNET_NO == 917 if (GNUNET_NO ==
918 GNUNET_CONTAINER_bloomfilter_test (pos->filter, 918 GNUNET_CONTAINER_bloomfilter_test (pos->filter,
919 &receiver->hashPubKey)) 919 &receiver->hashPubKey))
920 break; 920 break;
921 if (0 == GNUNET_TIME_absolute_get_remaining (pos->expiration).value) 921 if (0 == GNUNET_TIME_absolute_get_remaining (pos->expiration).value)
922 { 922 {
923 /* time to discard... */ 923 /* time to discard... */
@@ -947,11 +947,11 @@ hello_advertising (void *cls,
947 size = 0; 947 size = 0;
948 } 948 }
949 return size; 949 return size;
950 } 950 }
951 if ( (GNUNET_NO == hello_gathering_active) && 951 if ( (GNUNET_NO == hello_gathering_active) &&
952 (GNUNET_TIME_absolute_get_duration (last_hello_gather_time).value > 952 (GNUNET_TIME_absolute_get_duration (last_hello_gather_time).value >
953 MIN_HELLO_GATHER_DELAY.value) ) 953 MIN_HELLO_GATHER_DELAY.value) )
954 { 954 {
955 hello_gathering_active = GNUNET_YES; 955 hello_gathering_active = GNUNET_YES;
956 last_hello_gather_time = GNUNET_TIME_absolute_get(); 956 last_hello_gather_time = GNUNET_TIME_absolute_get();
957 GNUNET_PEERINFO_for_all (cfg, 957 GNUNET_PEERINFO_for_all (cfg,
@@ -994,14 +994,14 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
994 * @param cfgfile name of the configuration file used (for saving, can be NULL!) 994 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
995 * @param c configuration 995 * @param c configuration
996 */ 996 */
997static void 997static void
998run (void *cls, 998run (void *cls,
999 struct GNUNET_SCHEDULER_Handle * s, 999 struct GNUNET_SCHEDULER_Handle * s,
1000 char *const *args, 1000 char *const *args,
1001 const char *cfgfile, 1001 const char *cfgfile,
1002 struct GNUNET_CONFIGURATION_Handle * c) 1002 struct GNUNET_CONFIGURATION_Handle * c)
1003{ 1003{
1004 struct GNUNET_CORE_MessageHandler handlers[] = 1004 struct GNUNET_CORE_MessageHandler handlers[] =
1005 { 1005 {
1006 { &handle_encrypted_hello, GNUNET_MESSAGE_TYPE_HELLO, 0}, 1006 { &handle_encrypted_hello, GNUNET_MESSAGE_TYPE_HELLO, 0},
1007 { NULL, 0, 0 } 1007 { NULL, 0, 0 }
@@ -1012,7 +1012,7 @@ run (void *cls,
1012 cfg = c; 1012 cfg = c;
1013 autoconnect = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1013 autoconnect = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1014 "TOPOLOGY", 1014 "TOPOLOGY",
1015 "AUTOCONNECT"); 1015 "AUTOCONNECT");
1016 friends_only = GNUNET_CONFIGURATION_get_value_yesno (cfg, 1016 friends_only = GNUNET_CONFIGURATION_get_value_yesno (cfg,
1017 "TOPOLOGY", 1017 "TOPOLOGY",
1018 "FRIENDS-ONLY"); 1018 "FRIENDS-ONLY");
@@ -1050,7 +1050,7 @@ run (void *cls,
1050 NULL, GNUNET_NO, 1050 NULL, GNUNET_NO,
1051 NULL, GNUNET_NO, 1051 NULL, GNUNET_NO,
1052 handlers); 1052 handlers);
1053 1053
1054 GNUNET_SCHEDULER_add_delayed (sched, 1054 GNUNET_SCHEDULER_add_delayed (sched,
1055 GNUNET_YES, 1055 GNUNET_YES,
1056 GNUNET_SCHEDULER_PRIORITY_IDLE, 1056 GNUNET_SCHEDULER_PRIORITY_IDLE,
@@ -1075,7 +1075,7 @@ main (int argc, char *const *argv)
1075 ret = (GNUNET_OK == 1075 ret = (GNUNET_OK ==
1076 GNUNET_PROGRAM_run (argc, 1076 GNUNET_PROGRAM_run (argc,
1077 argv, 1077 argv,
1078 "topology", 1078 "topology",
1079 _("GNUnet topology control (maintaining P2P mesh and F2F constraints)"), 1079 _("GNUnet topology control (maintaining P2P mesh and F2F constraints)"),
1080 options, 1080 options,
1081 &run, NULL)) ? 0 : 1; 1081 &run, NULL)) ? 0 : 1;