GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
gnunet-daemon-topology.c File Reference

code for maintaining the overlay topology More...

Include dependency graph for gnunet-daemon-topology.c:

Go to the source code of this file.

Data Structures

struct  Peer
 Record for neighbours and blacklisted peers. More...
 
struct  StoreHelloEntry
 Context for a add hello uri request. More...
 
struct  FindAdvHelloContext
 Closure for find_advertisable_hello(). More...
 

Macros

#define HELLO_ADVERTISEMENT_MIN_FREQUENCY    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
 At what frequency do we sent HELLOs to a peer?
 
#define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
 After what time period do we expire the HELLO Bloom filter?
 

Functions

static int free_peer (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 Free all resources associated with the given peer.
 
static void attempt_connect (struct Peer *pos)
 Recalculate how much we want to be connected to the specified peer and let ATS know about the result.
 
static struct Peermake_peer (const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *hello)
 Create a new entry in the peer list.
 
static void setup_filter (struct Peer *peer)
 Setup bloom filter for the given peer entry.
 
static int find_advertisable_hello (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 Find a peer that would be reasonable for advertising.
 
static void schedule_next_hello (void *cls)
 Calculate when we would like to send the next HELLO to this peer and ask for it.
 
static int reschedule_hellos (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 Cancel existing requests for sending HELLOs to this peer and recalculate when we should send HELLOs to it based on our current state (something changed!).
 
static void * connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq, enum GNUNET_CORE_PeerClass class)
 Method called whenever a peer connects.
 
static int try_add_peers (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 Try to add more peers to our connection set.
 
static void add_peer_task (void *cls)
 Add peers and schedule connection attempt.
 
static void disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
 Method called whenever a peer disconnects.
 
static void address_iterator (void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
 Iterator called on each address.
 
static void consider_for_advertising (const struct GNUNET_MessageHeader *hello)
 We've gotten a HELLO from another peer.
 
static void error_cb (void *cls)
 
static void sync_cb (void *cls)
 
static void process_peer (void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *err_msg)
 PEERSTORE calls this function to let us know about a possible peer that we might want to connect to.
 
static void start_notify (void *cls)
 
static void pid_change_cb (void *cls, const struct GNUNET_HELLO_Parser *parser, const struct GNUNET_HashCode *addr_hash)
 
static void core_init (void *cls, const struct GNUNET_PeerIdentity *my_id)
 Function called after GNUNET_CORE_connect has succeeded (or failed for good).
 
static int check_hello (void *cls, const struct GNUNET_MessageHeader *msg)
 This function is called whenever an encrypted HELLO message is received.
 
static void shc_cont (void *cls, int success)
 
static void handle_hello (void *cls, const struct GNUNET_MessageHeader *msg)
 This function is called whenever an encrypted HELLO message is received.
 
static void cleaning_task (void *cls)
 Last task run during shutdown.
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Main function that will be run.
 
int main (int argc, char *const *argv)
 The main function for the topology daemon.
 

Variables

struct GNUNET_SCHEDULER_Taskpeerstore_notify_task
 The task to delayed start the notification process initially.
 
static struct GNUNET_PEERSTORE_Monitorpeerstore_notify
 Our peerstore notification context.
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Our configuration.
 
static struct GNUNET_PILS_Handlepils
 Handle to the PILS service.
 
static struct GNUNET_CORE_Handlehandle
 Handle to the CORE service.
 
static struct GNUNET_PEERSTORE_Handleps
 Handle to the PEERSTORE service.
 
struct GNUNET_TRANSPORT_ApplicationHandletransport
 Handle to Transport service.
 
static struct GNUNET_PeerIdentity my_identity
 Identity of this peer.
 
static struct GNUNET_CONTAINER_MultiPeerMappeers
 All of our current neighbours and all peers for which we have HELLOs.
 
static struct GNUNET_STATISTICS_Handlestats
 Handle for reporting statistics.
 
static struct GNUNET_SCHEDULER_Taskadd_task
 Task scheduled to asynchronously reconsider adding/removing peer connectivity suggestions.
 
static unsigned int connection_count
 Number of peers that we are currently connected to.
 
static unsigned int target_connection_count
 Target number of connections.
 
static struct StoreHelloEntryshe_head
 Head of the linkd list to store the store context for hellos.
 
static struct StoreHelloEntryshe_tail
 Tail of the linkd list to store the store context for hellos.
 

Detailed Description

code for maintaining the overlay topology

Author
Christian Grothoff

This daemon combines one Function:

  • gossping HELLOs

Definition in file gnunet-daemon-topology.c.

Macro Definition Documentation

◆ HELLO_ADVERTISEMENT_MIN_FREQUENCY

#define HELLO_ADVERTISEMENT_MIN_FREQUENCY    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)

At what frequency do we sent HELLOs to a peer?

Definition at line 46 of file gnunet-daemon-topology.c.

59{
64
69 struct GNUNET_MQ_Handle *mq;
70
74 struct GNUNET_MessageHeader *hello;
75
81
85 struct GNUNET_TIME_Absolute next_hello_allowed;
86
90 struct GNUNET_TIME_Absolute filter_expiration;
91
96 struct GNUNET_SCHEDULER_Task *hello_delay_task;
97
102
106 uint32_t strength;
107
108};
109
113struct StoreHelloEntry
114{
118 struct StoreHelloEntry *prev;
119
123 struct StoreHelloEntry *next;
124
129};
130
136
137
143
147static const struct GNUNET_CONFIGURATION_Handle *cfg;
148
152static struct GNUNET_PILS_Handle *pils;
153
157static struct GNUNET_CORE_Handle *handle;
158
162static struct GNUNET_PEERSTORE_Handle *ps;
163
168
172static struct GNUNET_PeerIdentity my_identity;
173
180
184static struct GNUNET_STATISTICS_Handle *stats;
185
190static struct GNUNET_SCHEDULER_Task *add_task;
191
195static unsigned int connection_count;
196
200static unsigned int target_connection_count;
201
205static struct StoreHelloEntry *she_head;
206
210static struct StoreHelloEntry *she_tail;
211
220static int
221free_peer (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
222{
223 struct Peer *pos = value;
224
225 GNUNET_break (NULL == pos->mq);
228 if (NULL != pos->hello_delay_task)
229 {
231 pos->hello_delay_task = NULL;
232 }
233 if (NULL != pos->ash)
234 {
236 pos->ash = NULL;
237 }
238 if (NULL != pos->hello)
239 {
240 GNUNET_free (pos->hello);
241 pos->hello = NULL;
242 }
243 if (NULL != pos->filter)
244 {
246 pos->filter = NULL;
247 }
248 GNUNET_free (pos);
249 return GNUNET_YES;
250}
251
252
259static void
260attempt_connect (struct Peer *pos)
261{
262 uint32_t strength;
264
266 "Checking if we want to attempt connection to `%s'\n",
267 GNUNET_i2s(&pos->pid));
268 if (0 == GNUNET_memcmp (&my_identity, &pos->pid))
269 return; /* This is myself, nothing to do. */
271 strength = 1;
272 else
273 strength = 0;
274 if (NULL != pos->mq)
275 strength *= 2; /* existing connections preferred */
276 if (NULL != pos->ash)
277 {
279 pos->ash = NULL;
280 }
281 pos->strength = strength;
282 if (0 != strength)
283 {
285 "Asking to connect to `%s' with strength %u\n",
286 GNUNET_i2s (&pos->pid),
287 (unsigned int) strength);
289 gettext_noop ("# connect requests issued to ATS"),
290 1,
291 GNUNET_NO);
292 // TODO Use strength somehow.
293 bw.value__ = 0;
295 &pos->pid,
297 bw);
298 }
299}
300
301
309static struct Peer *
310make_peer (const struct GNUNET_PeerIdentity *peer,
311 const struct GNUNET_MessageHeader *hello)
312{
313 struct Peer *ret;
314
315 ret = GNUNET_new (struct Peer);
316 ret->pid = *peer;
317 if (NULL != hello)
318 {
319 ret->hello = GNUNET_malloc (ntohs (hello->size));
320 GNUNET_memcpy (ret->hello, hello, ntohs (hello->size));
321 }
324 peers,
325 peer,
326 ret,
328 return ret;
329}
330
331
337static void
338setup_filter (struct Peer *peer)
339{
340 struct GNUNET_HashCode hc;
341
342 /* 2^{-5} chance of not sending a HELLO to a peer is
343 * acceptably small (if the filter is 50% full);
344 * 64 bytes of memory are small compared to the rest
345 * of the data structure and would only really become
346 * "useless" once a HELLO has been passed on to ~100
347 * other peers, which is likely more than enough in
348 * any case; hence 64, 5 as bloomfilter parameters. */peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5);
349 peer->filter_expiration =
351 /* never send a peer its own HELLO */
352 GNUNET_CRYPTO_hash (&peer->pid, sizeof(struct GNUNET_PeerIdentity), &hc);
354}
355
356
361{
365 struct Peer *peer;
366
370 struct Peer *result;
371
375 size_t max_size;
376
378};
379
380
389static int
390find_advertisable_hello (void *cls,
391 const struct GNUNET_PeerIdentity *pid,
392 void *value)
393{
394 struct FindAdvHelloContext *fah = cls;
395 struct Peer *pos = value;
396 struct GNUNET_TIME_Relative rst_time;
397 struct GNUNET_HashCode hc;
398 size_t hs;
399
401 "find_advertisable_hello\n");
402 if (pos == fah->peer)
403 return GNUNET_YES;
405 "find_advertisable_hello 2\n");
406 if (pos->hello == NULL)
407 return GNUNET_YES;
409 "find_advertisable_hello 3\n");
411 if (0 == rst_time.rel_value_us)
412 {
413 /* time to discard... */
415 setup_filter (pos);
416 }
417 fah->next_adv = GNUNET_TIME_relative_min (rst_time, fah->next_adv);
418 hs = pos->hello->size;
419 if (hs > fah->max_size)
420 return GNUNET_YES;
422 "find_advertisable_hello 4\n");
424 sizeof(struct GNUNET_PeerIdentity),
425 &hc);
427 fah->result = pos;
428 return GNUNET_YES;
429}
430
431
438static void
439schedule_next_hello (void *cls)
440{
441 struct Peer *pl = cls;
442 struct FindAdvHelloContext fah;
443 struct GNUNET_MQ_Envelope *env;
444 size_t want;
445 struct GNUNET_TIME_Relative delay;
446 struct GNUNET_HashCode hc;
447
449 "schedule_next_hello\n");
450 pl->hello_delay_task = NULL;
451 GNUNET_assert (NULL != pl->mq);
452 /* find applicable HELLOs */
453 fah.peer = pl;
454 fah.result = NULL;
458 if (NULL == fah.result)
459 {
460 pl->hello_delay_task =
462
463 return;
464 }
465 want = ntohs (fah.result->hello->size);
467 "Sending HELLO with %u bytes for peer %s\n",
468 (unsigned int) want,
469 GNUNET_i2s (&pl->pid));
471 GNUNET_MQ_send (pl->mq, env);
472
473 /* avoid sending this one again soon */
474 GNUNET_CRYPTO_hash (&pl->pid, sizeof(struct GNUNET_PeerIdentity), &hc);
476
478 gettext_noop ("# HELLO messages gossipped"),
479 1,
480 GNUNET_NO);
481 /* prepare to send the next one */
487}
488
489
500static int
501reschedule_hellos (void *cls,
502 const struct GNUNET_PeerIdentity *pid,
503 void *value)
504{
505 struct Peer *peer = value;
506 (void) cls;
507
509 "Reschedule for `%s'\n",
510 GNUNET_i2s (&peer->pid));
511 if (NULL == peer->mq)
512 return GNUNET_YES;
513 if (NULL != peer->hello_delay_task)
514 {
516 peer->hello_delay_task = NULL;
517 }
519 "Schedule_next_hello\n");
520 peer->hello_delay_task =
522 return GNUNET_YES;
523}
524
525
535static void *
536connect_notify (void *cls,
537 const struct GNUNET_PeerIdentity *peer,
538 struct GNUNET_MQ_Handle *mq,
539 enum GNUNET_CORE_PeerClass class)
540{
541 struct Peer *pos;
542
544 "Core told us that we are connecting to `%s'\n",
545 GNUNET_i2s (peer));
546 if (0 == GNUNET_memcmp (&my_identity, peer))
547 return NULL;
551 gettext_noop ("# peers connected"),
553 GNUNET_NO);
555 if (NULL == pos)
556 {
557 pos = make_peer (peer, NULL);
558 }
559 else
560 {
561 GNUNET_assert (NULL == pos->mq);
562 }
563 pos->mq = mq;
564 reschedule_hellos (NULL, peer, pos);
565 return pos;
566}
567
568
577static int
578try_add_peers (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
579{
580 struct Peer *pos = value;
581
582 attempt_connect (pos);
583 return GNUNET_YES;
584}
585
586
592static void
593add_peer_task (void *cls)
594{
595 add_task = NULL;
596
598}
599
600
608static void
609disconnect_notify (void *cls,
610 const struct GNUNET_PeerIdentity *peer,
611 void *internal_cls)
612{
613 struct Peer *pos = internal_cls;
614
615 if (NULL == pos)
616 return; /* myself, we're shutting down */
618 "Core told us that we disconnected from `%s'\n",
619 GNUNET_i2s (peer));
620 if (NULL == pos->mq)
621 {
622 GNUNET_break (0);
623 return;
624 }
625 pos->mq = NULL;
627 if (NULL != pos->hello_delay_task)
628 {
630 pos->hello_delay_task = NULL;
631 }
633 gettext_noop ("# peers connected"),
635 GNUNET_NO);
637 (NULL == add_task))
639
640}
641
642
650static void
651address_iterator (void *cls,
652 const struct GNUNET_PeerIdentity *pid,
653 const char *uri)
654{
655 int *flag = cls;
656 (void) pid;
657
658 *flag = *flag + 1;
659 // *flag = GNUNET_YES;
660}
661
662
669static void
671{
672 int num_addresses_old = 0;
673 int num_addresses_new = 0;
675 const struct GNUNET_PeerIdentity *pid;
676 struct Peer *peer;
677 uint16_t size;
678
680 if (NULL == parser)
681 {
682 return;
683 }
686 &num_addresses_new);
688 "consider 0 for %s\n",
689 GNUNET_i2s (pid));
690 if (0 == num_addresses_new)
691 {
693 return; /* no point in advertising this one... */
694 }
696 if (NULL == peer)
697 {
698 peer = make_peer (pid, hello);
699 }
700 else if (NULL != peer->hello)
701 {
703 struct GNUNET_TIME_Absolute new_hello_exp =
705 struct GNUNET_TIME_Absolute old_hello_exp =
707 struct GNUNET_HELLO_Parser *parser_old =
709
710 GNUNET_HELLO_parser_iterate (parser_old,
712 &num_addresses_old);
713 GNUNET_HELLO_parser_free (parser_old);
714 if (GNUNET_TIME_absolute_cmp (new_hello_exp, >, now) &&
715 (GNUNET_TIME_absolute_cmp (new_hello_exp, >, old_hello_exp) ||
716 num_addresses_old < num_addresses_new))
717 {
718 GNUNET_free (peer->hello);
719 size = ntohs (hello->size);
720 peer->hello = GNUNET_malloc (size);
721 GNUNET_memcpy (peer->hello, hello, size);
722 }
723 else
724 {
726 "consider 3\n");
728 return;
729 }
730 }
731 else
732 {
733 size = ntohs (hello->size);
734 peer->hello = GNUNET_malloc (size);
735 GNUNET_memcpy (peer->hello, hello, size);
736 }
738 "Found HELLO from peer `%s' for advertising\n",
739 GNUNET_i2s (pid));
740 if (NULL != peer->filter)
741 {
743 peer->filter = NULL;
744 }
745 setup_filter (peer);
746 /* since we have a new HELLO to pick from, re-schedule all
747 * HELLO requests that are not bound by the HELLO send rate! */
750}
751
752
753static void
754error_cb (void *cls)
755{
757 _ (
758 "Error in communication with PEERSTORE service to monitor.\n"));
759 return;
760}
761
762
763static void
764sync_cb (void *cls)
765{
767 _ ("Finished initial PEERSTORE iteration in monitor.\n"));
768 return;
769}
770
771
781static void
782process_peer (void *cls,
783 const struct GNUNET_PEERSTORE_Record *record,
784 const char *err_msg)
785{
786 struct Peer *pos;
787 struct GNUNET_MessageHeader *hello;
788
789 if (NULL != err_msg)
790 {
792 _ ("Error in communication with PEERSTORE service: %s\n"),
793 err_msg);
798 "peerstore",
799 NULL,
801 error_cb,
802 NULL,
803 sync_cb,
804 NULL,
806 NULL);
807 return;
808 }
809 GNUNET_assert (NULL != record);
811 "Processing HELLO from peerstore from peer `%s'\n",
812 GNUNET_i2s (&record->peer));
813 hello = record->value;
814 if (NULL == hello)
815 {
816 /* free existing HELLO, if any */
818 if (NULL != pos)
819 {
820 GNUNET_free (pos->hello);
821 pos->hello = NULL;
822 if (NULL != pos->filter)
823 {
825 pos->filter = NULL;
826 }
827 if (NULL == pos->mq)
828 free_peer (NULL, &pos->pid, pos);
829 }
831 return;
832 }
835 if (NULL == pos)
836 pos = make_peer (&record->peer, hello);
837 attempt_connect (pos);
839}
840
841
842static void
843start_notify (void *cls)
844{
845 (void) cls;
846
848 "Starting to process new hellos for gossiping.\n");
852 "peerstore",
853 NULL,
855 &error_cb,
856 NULL,
857 &sync_cb,
858 NULL,
860 NULL);
861}
862
863static void
864pid_change_cb (void *cls,
865 const struct GNUNET_HELLO_Parser *parser,
866 const struct GNUNET_HashCode *addr_hash)
867{
869}
870
878static void
879core_init (void *cls, const struct GNUNET_PeerIdentity *my_id)
880{
881 if (NULL == my_id)
882 {
883 GNUNET_log (
885 _ ("Failed to connect to core service, can not manage topology!\n"));
887 return;
888 }
889 my_identity = *my_id;
890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id));
894 NULL);
895}
896
897
907static int
908check_hello (void *cls, const struct GNUNET_MessageHeader *msg)
909{
911 const struct GNUNET_PeerIdentity *pid = GNUNET_HELLO_parser_get_id (parser);
912
913 if (NULL == pid)
914 {
915 GNUNET_break_op (0);
916 return GNUNET_SYSERR;
917 }
918 return GNUNET_OK;
919}
920
921
922static void
923shc_cont (void *cls, int success)
924{
925 struct StoreHelloEntry *she = cls;
926
927 she->sc = NULL;
928 if (GNUNET_YES == success)
930 "Hello stored successfully!\n");
931 else
933 "Error storing hello!\n");
935 GNUNET_free (she);
936}
937
938
946static void
947handle_hello (void *cls, const struct GNUNET_MessageHeader *msg)
948{
949 struct StoreHelloEntry *she;
950 const struct GNUNET_PeerIdentity *other = cls;
952
954 "Received encrypted HELLO from peer `%s'\n",
955 GNUNET_i2s (other));
957 gettext_noop ("# HELLO messages received"),
958 1,
959 GNUNET_NO);
961 she = GNUNET_new (struct StoreHelloEntry);
963 if (NULL != she->sc)
964 {
966 }
967 else
968 GNUNET_free (she);
970}
971
972
979static void
980cleaning_task (void *cls)
981{
982 struct StoreHelloEntry *pos;
983
984 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Topology shutdown\n");
985 while (NULL != (pos = she_head))
986 {
988 if (NULL != pos->sc)
990 GNUNET_free (pos);
991 }
992 if (NULL != peerstore_notify)
993 {
995 peerstore_notify = NULL;
996 }
997 else if (NULL != peerstore_notify_task)
998 {
1000 }
1001 if (NULL != pils)
1002 {
1004 pils = NULL;
1005 }
1006 if (NULL != handle)
1007 {
1009 handle = NULL;
1010 }
1011 if (NULL != add_task)
1012 {
1014 add_task = NULL;
1015 }
1018 peers = NULL;
1019 if (NULL != transport)
1020 {
1022 transport = NULL;
1023 }
1024 if (NULL != ps)
1025 {
1027 ps = NULL;
1028 }
1029 if (NULL != stats)
1030 {
1032 stats = NULL;
1033 }
1034}
1035
1036
1045static void
1046run (void *cls,
1047 char *const *args,
1048 const char *cfgfile,
1049 const struct GNUNET_CONFIGURATION_Handle *c)
1050{
1052 { GNUNET_MQ_hd_var_size (hello,
1054 struct GNUNET_MessageHeader,
1055 NULL),
1057 unsigned long long opt;
1058 const struct GNUNET_CORE_ServiceInfo service_info =
1059 {
1061 .version = { 1, 0 },
1062 .version_max = { 1, 0 },
1063 .version_min = { 1, 0 },
1064 };
1065
1066 cfg = c;
1067 stats = GNUNET_STATISTICS_create ("topology", cfg);
1068
1069 if (GNUNET_OK !=
1071 "TOPOLOGY",
1072 "TARGET-CONNECTION-COUNT",
1073 &opt))
1074 opt = 16;
1075 target_connection_count = (unsigned int) opt;
1077 GNUNET_NO);
1081 NULL,
1082 &core_init,
1085 handlers,
1086 &service_info);
1089 if (NULL == pils)
1090 {
1092 _ ("Failed to connect to `%s' service.\n"),
1093 "pils");
1095 return;
1096 }
1097 if (NULL == handle)
1098 {
1100 _ ("Failed to connect to `%s' service.\n"),
1101 "core");
1103 return;
1104 }
1105}
1106
1107
1115int
1116main (int argc, char *const *argv)
1117{
1118 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1120 };
1121 int ret;
1122
1123 ret = (GNUNET_OK ==
1125 argc,
1126 argv,
1127 "gnunet-daemon-topology",
1128 _ ("GNUnet topology control"),
1129 options,
1130 &run,
1131 NULL))
1132 ? 0
1133 : 1;
1134 return ret;
1135}
1136
1137
1138#if defined(__linux__) && defined(__GLIBC__)
1139#include <malloc.h>
1140
1141void __attribute__ ((constructor))
1142GNUNET_TOPOLOGY_memory_init (void);
1143
1147void __attribute__ ((constructor))
1148GNUNET_TOPOLOGY_memory_init (void)
1149{
1150 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1151 mallopt (M_TOP_PAD, 1 * 1024);
1152 malloc_trim (0);
1153}
1154
1155
1156#endif
1157
1158/* end of gnunet-daemon-topology.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
struct GNUNET_MQ_MessageHandlers handlers[]
Definition 003.c:1
struct GNUNET_MessageHeader * msg
Definition 005.c:2
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
#define gettext_noop(String)
Definition gettext.h:74
static int ret
Final status code.
Definition gnunet-arm.c:93
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static struct GNUNET_CORE_Handle * handle
Handle to the CORE service.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our current neighbours and all peers for which we have HELLOs.
static void handle_hello(void *cls, const struct GNUNET_MessageHeader *msg)
This function is called whenever an encrypted HELLO message is received.
static int check_hello(void *cls, const struct GNUNET_MessageHeader *msg)
This function is called whenever an encrypted HELLO message is received.
static void sync_cb(void *cls)
static void cleaning_task(void *cls)
Last task run during shutdown.
static void add_peer_task(void *cls)
Add peers and schedule connection attempt.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
static void consider_for_advertising(const struct GNUNET_MessageHeader *hello)
We've gotten a HELLO from another peer.
static unsigned int target_connection_count
Target number of connections.
static void schedule_next_hello(void *cls)
Calculate when we would like to send the next HELLO to this peer and ask for it.
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
static struct GNUNET_PEERSTORE_Monitor * peerstore_notify
Our peerstore notification context.
static void disconnect_notify(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a peer disconnects.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static void address_iterator(void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
Iterator called on each address.
static unsigned int connection_count
Number of peers that we are currently connected to.
static struct StoreHelloEntry * she_head
Head of the linkd list to store the store context for hellos.
static void start_notify(void *cls)
static struct StoreHelloEntry * she_tail
Tail of the linkd list to store the store context for hellos.
struct GNUNET_SCHEDULER_Task * peerstore_notify_task
The task to delayed start the notification process initially.
static void process_peer(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *err_msg)
PEERSTORE calls this function to let us know about a possible peer that we might want to connect to.
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
static void core_init(void *cls, const struct GNUNET_PeerIdentity *my_id)
Function called after GNUNET_CORE_connect has succeeded (or failed for good).
static void shc_cont(void *cls, int success)
#define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY
After what time period do we expire the HELLO Bloom filter?
static int reschedule_hellos(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Cancel existing requests for sending HELLOs to this peer and recalculate when we should send HELLOs t...
static void pid_change_cb(void *cls, const struct GNUNET_HELLO_Parser *parser, const struct GNUNET_HashCode *addr_hash)
struct GNUNET_TRANSPORT_ApplicationHandle * transport
Handle to Transport service.
#define HELLO_ADVERTISEMENT_MIN_FREQUENCY
At what frequency do we sent HELLOs to a peer?
static void setup_filter(struct Peer *peer)
Setup bloom filter for the given peer entry.
static int free_peer(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Free all resources associated with the given peer.
static void error_cb(void *cls)
static struct GNUNET_SCHEDULER_Task * add_task
Task scheduled to asynchronously reconsider adding/removing peer connectivity suggestions.
static void attempt_connect(struct Peer *pos)
Recalculate how much we want to be connected to the specified peer and let ATS know about the result.
static int find_advertisable_hello(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Find a peer that would be reasonable for advertising.
static struct Peer * make_peer(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *hello)
Create a new entry in the peer list.
static int try_add_peers(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Try to add more peers to our connection set.
static void * connect_notify(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq, enum GNUNET_CORE_PeerClass class)
Method called whenever a peer connects.
static struct GNUNET_PILS_Handle * pils
Handle to the PILS service.
static char * value
Value of the record to add/remove.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
struct GNUNET_PILS_Handle * GNUNET_PILS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_PILS_PidChangeCallback pid_change_cb, void *cls)
Connect to the PILS service.
Definition pils_api.c:367
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
Definition pils_api.c:390
struct GNUNET_PQ_ResultSpec __attribute__
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
struct GNUNET_TRANSPORT_ApplicationSuggestHandle * GNUNET_TRANSPORT_application_suggest(struct GNUNET_TRANSPORT_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_MQ_PriorityPreferences pk, struct GNUNET_BANDWIDTH_Value32NBO bw)
An application would like TRANSPORT to connect to a peer.
void GNUNET_TRANSPORT_application_done(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Shutdown TRANSPORT application client.
void GNUNET_TRANSPORT_application_suggest_cancel(struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh)
We no longer care about being connected to a peer.
struct GNUNET_TRANSPORT_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application client handle.
struct GNUNET_CONTAINER_BloomFilter * GNUNET_CONTAINER_bloomfilter_init(const char *data, size_t size, unsigned int k)
Create a Bloom filter from raw bits.
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
bool GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associated with a filter in memory, flush to drive if needed (do not free the space on...
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
GNUNET_CORE_PeerClass
The peer class gives a hint about the capabilities of a peer.
struct GNUNET_CORE_Handle * GNUNET_CORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, void *cls, GNUNET_CORE_StartupCallback init, GNUNET_CORE_ConnectEventHandler connects, GNUNET_CORE_DisconnectEventHandler disconnects, const struct GNUNET_MQ_MessageHandler *handlers, struct GNUNET_CORE_ServiceInfo *service_info)
Connect to the core service.
Definition core_api.c:698
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition core_api.c:744
@ GNUNET_CORE_SERVICE_TOPOLOGY
Identifier for topology service.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition crypto_hash.c:41
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
enum GNUNET_GenericReturnValue GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY
There must only be one value per key; storing a value should fail if a value under the same key alrea...
void GNUNET_HELLO_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of a builder.
Definition hello-uri.c:379
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_msg(const struct GNUNET_MessageHeader *msg)
Parse msg.
Definition hello-uri.c:415
const struct GNUNET_PeerIdentity * GNUNET_HELLO_parser_iterate(const struct GNUNET_HELLO_Parser *parser, GNUNET_HELLO_UriCallback uc, void *uc_cls)
Iterate over URIs in a parser.
Definition hello-uri.c:975
struct GNUNET_TIME_Absolute GNUNET_HELLO_get_expiration_time_from_msg(const struct GNUNET_MessageHeader *msg)
Get the expiration time for this HELLO.
Definition hello-uri.c:597
const struct GNUNET_PeerIdentity * GNUNET_HELLO_parser_get_id(const struct GNUNET_HELLO_Parser *parser)
Get the PeerIdentity for this builder.
Definition hello-uri.c:353
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition mq.c:550
void GNUNET_MQ_set_options(struct GNUNET_MQ_Handle *mq, enum GNUNET_MQ_PriorityPreferences pp)
Set application-specific options for this queue.
Definition mq.c:888
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
@ GNUNET_MQ_PRIO_BEST_EFFORT
Best-effort traffic (e.g.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
void GNUNET_PEERSTORE_monitor_stop(struct GNUNET_PEERSTORE_Monitor *zm)
Stop monitoring.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
struct GNUNET_PEERSTORE_Monitor * GNUNET_PEERSTORE_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, int iterate_first, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Request watching a given key The monitoring can be filtered to contain only records matching peer and...
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
void GNUNET_PEERSTORE_monitor_next(struct GNUNET_PEERSTORE_Monitor *zm, uint64_t limit)
Calls the monitor processor specified in GNUNET_PEERSTORE_monitor_start for the next record(s).
void GNUNET_PEERSTORE_hello_add_cancel(struct GNUNET_PEERSTORE_StoreHelloContext *huc)
Cancel the request to add a hello.
#define GNUNET_PEERSTORE_HELLO_KEY
Key used for storing HELLO in the peerstore.
struct GNUNET_PEERSTORE_StoreHelloContext * GNUNET_PEERSTORE_hello_add(struct GNUNET_PEERSTORE_Handle *h, const struct GNUNET_MessageHeader *msg, GNUNET_PEERSTORE_Continuation cont, void *cont_cls)
Add hello to peerstore.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition program.c:407
#define GNUNET_MESSAGE_TYPE_HELLO_URI
Latest HELLO messages used for communicating peer addresses.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:567
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition scheduler.c:1339
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition scheduler.c:980
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition scheduler.c:1304
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition scheduler.c:1277
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
struct GNUNET_TIME_Relative GNUNET_TIME_relative_min(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the minimum of two relative time values.
Definition time.c:344
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition time.c:406
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition time.c:111
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition time.c:316
#define GNUNET_TIME_absolute_cmp(t1, op, t2)
Compare two absolute times.
static unsigned int size
Size of the "table".
Definition peer.c:68
#define _(String)
GNU gettext support macro.
Definition platform.h:179
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
Closure for find_advertisable_hello().
size_t max_size
Maximum HELLO size we can use right now.
struct Peer * peer
Peer we want to advertise to.
struct GNUNET_TIME_Relative next_adv
struct Peer * result
Where to store the result (peer selected for advertising).
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
Internal representation of the hash map.
Context for the core service connection.
Definition core_api.c:78
Gnunet service info - identifying compatibility with a range of version of a service communicating ov...
enum GNUNET_CORE_Service service
Identifier of the service on top of CORE.
Definition of a command line option.
Context for parsing HELLOs.
Definition hello-uri.c:232
A 512-bit hashcode.
Handle to a message queue.
Definition mq.c:87
Message handler for a specific message type.
Header for all communications.
Handle to the PEERSTORE service.
Context for a add hello uri request.
A handle for the PILS service.
Definition pils_api.c:82
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Definition scheduler.c:136
Handle for the service.
Time for absolute times used by GNUnet, in microseconds.
Time for relative time used by GNUnet, in microseconds.
Handle to the TRANSPORT subsystem for application management.
Handle for TRANSPORT address suggestion requests.
Record for neighbours and blacklisted peers.
struct GNUNET_PeerIdentity pid
Which peer is this entry about?
struct GNUNET_MessageHeader * hello
Pointer to the hello uri of this peer; can be NULL.
struct GNUNET_TIME_Absolute next_hello_allowed
Next time we are allowed to transmit a HELLO to this peer?
struct GNUNET_CONTAINER_BloomFilter * filter
Bloom filter used to mark which peers already got the HELLO from this peer.
struct GNUNET_SCHEDULER_Task * hello_delay_task
ID of task we use to wait for the time to send the next HELLO to this peer.
struct GNUNET_TIME_Absolute filter_expiration
When should we reset the bloom filter of this entry?
struct GNUNET_TRANSPORT_ApplicationSuggestHandle * ash
Transport suggest handle.
uint32_t strength
How much would we like to connect to this peer?
struct GNUNET_MQ_Handle * mq
Our handle for transmitting to this peer; NULL if peer is not connected.
Context for a add hello uri request.
struct GNUNET_PEERSTORE_StoreHelloContext * sc
Store hello ctx.
struct StoreHelloEntry * prev
Kept (also) in a DLL.
struct StoreHelloEntry * next
Kept (also) in a DLL.

◆ HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY

#define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY    GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)

After what time period do we expire the HELLO Bloom filter?

Definition at line 52 of file gnunet-daemon-topology.c.

Function Documentation

◆ free_peer()

static int free_peer ( void *  cls,
const struct GNUNET_PeerIdentity pid,
void *  value 
)
static

Free all resources associated with the given peer.

Parameters
clsclosure (not used)
pididentity of the peer
valuepeer to free
Returns
GNUNET_YES (always: continue to iterate)

Definition at line 222 of file gnunet-daemon-topology.c.

223{
224 struct Peer *pos = value;
225
226 GNUNET_break (NULL == pos->mq);
229 if (NULL != pos->hello_delay_task)
230 {
232 pos->hello_delay_task = NULL;
233 }
234 if (NULL != pos->ash)
235 {
237 pos->ash = NULL;
238 }
239 if (NULL != pos->hello)
240 {
241 GNUNET_free (pos->hello);
242 pos->hello = NULL;
243 }
244 if (NULL != pos->filter)
245 {
247 pos->filter = NULL;
248 }
249 GNUNET_free (pos);
250 return GNUNET_YES;
251}

References Peer::ash, Peer::filter, GNUNET_break, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_TRANSPORT_application_suggest_cancel(), GNUNET_YES, Peer::hello, Peer::hello_delay_task, Peer::mq, peers, pid, and value.

Referenced by cleaning_task(), and process_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ attempt_connect()

static void attempt_connect ( struct Peer pos)
static

Recalculate how much we want to be connected to the specified peer and let ATS know about the result.

Parameters
pospeer to consider connecting to

Definition at line 261 of file gnunet-daemon-topology.c.

262{
263 uint32_t strength;
265
267 "Checking if we want to attempt connection to `%s'\n",
268 GNUNET_i2s(&pos->pid));
269 if (0 == GNUNET_memcmp (&my_identity, &pos->pid))
270 return; /* This is myself, nothing to do. */
272 strength = 1;
273 else
274 strength = 0;
275 if (NULL != pos->mq)
276 strength *= 2; /* existing connections preferred */
277 if (NULL != pos->ash)
278 {
280 pos->ash = NULL;
281 }
282 pos->strength = strength;
283 if (0 != strength)
284 {
286 "Asking to connect to `%s' with strength %u\n",
287 GNUNET_i2s (&pos->pid),
288 (unsigned int) strength);
290 gettext_noop ("# connect requests issued to ATS"),
291 1,
292 GNUNET_NO);
293 // TODO Use strength somehow.
294 bw.value__ = 0;
296 &pos->pid,
298 bw);
299 }
300}

References Peer::ash, connection_count, gettext_noop, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, GNUNET_MQ_PRIO_BEST_EFFORT, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TRANSPORT_application_suggest(), GNUNET_TRANSPORT_application_suggest_cancel(), Peer::mq, my_identity, Peer::pid, stats, Peer::strength, target_connection_count, transport, and GNUNET_BANDWIDTH_Value32NBO::value__.

Referenced by process_peer(), and try_add_peers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ make_peer()

static struct Peer * make_peer ( const struct GNUNET_PeerIdentity peer,
const struct GNUNET_MessageHeader hello 
)
static

Create a new entry in the peer list.

Parameters
peeridentity of the new entry
hellohello message, can be NULL
Returns
the new entry

Definition at line 311 of file gnunet-daemon-topology.c.

313{
314 struct Peer *ret;
315
316 ret = GNUNET_new (struct Peer);
317 ret->pid = *peer;
318 if (NULL != hello)
319 {
320 ret->hello = GNUNET_malloc (ntohs (hello->size));
321 GNUNET_memcpy (ret->hello, hello, ntohs (hello->size));
322 }
325 peers,
326 peer,
327 ret,
329 return ret;
330}

References GNUNET_break, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_put(), GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_OK, Peer::hello, peers, ret, and GNUNET_MessageHeader::size.

Referenced by connect_notify(), consider_for_advertising(), and process_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_filter()

static void setup_filter ( struct Peer peer)
static

Setup bloom filter for the given peer entry.

Parameters
peerentry to initialize

Definition at line 339 of file gnunet-daemon-topology.c.

340{
341 struct GNUNET_HashCode hc;
342
343 /* 2^{-5} chance of not sending a HELLO to a peer is
344 * acceptably small (if the filter is 50% full);
345 * 64 bytes of memory are small compared to the rest
346 * of the data structure and would only really become
347 * "useless" once a HELLO has been passed on to ~100
348 * other peers, which is likely more than enough in
349 * any case; hence 64, 5 as bloomfilter parameters. */peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5);
350 peer->filter_expiration =
352 /* never send a peer its own HELLO */
353 GNUNET_CRYPTO_hash (&peer->pid, sizeof(struct GNUNET_PeerIdentity), &hc);
355}

References Peer::filter, Peer::filter_expiration, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_bloomfilter_init(), GNUNET_CRYPTO_hash(), GNUNET_TIME_relative_to_absolute(), HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY, and Peer::pid.

Referenced by consider_for_advertising(), and find_advertisable_hello().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_advertisable_hello()

static int find_advertisable_hello ( void *  cls,
const struct GNUNET_PeerIdentity pid,
void *  value 
)
static

Find a peer that would be reasonable for advertising.

Parameters
clsclosure
pididentity of a peer
value'struct Peer*' for the peer we are considering
Returns
GNUNET_YES (continue iteration)

Definition at line 391 of file gnunet-daemon-topology.c.

394{
395 struct FindAdvHelloContext *fah = cls;
396 struct Peer *pos = value;
397 struct GNUNET_TIME_Relative rst_time;
398 struct GNUNET_HashCode hc;
399 size_t hs;
400
402 "find_advertisable_hello\n");
403 if (pos == fah->peer)
404 return GNUNET_YES;
406 "find_advertisable_hello 2\n");
407 if (pos->hello == NULL)
408 return GNUNET_YES;
410 "find_advertisable_hello 3\n");
412 if (0 == rst_time.rel_value_us)
413 {
414 /* time to discard... */
416 setup_filter (pos);
417 }
418 fah->next_adv = GNUNET_TIME_relative_min (rst_time, fah->next_adv);
419 hs = pos->hello->size;
420 if (hs > fah->max_size)
421 return GNUNET_YES;
423 "find_advertisable_hello 4\n");
425 sizeof(struct GNUNET_PeerIdentity),
426 &hc);
428 fah->result = pos;
429 return GNUNET_YES;
430}

References Peer::filter, Peer::filter_expiration, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NO, GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_min(), GNUNET_YES, Peer::hello, FindAdvHelloContext::max_size, FindAdvHelloContext::next_adv, FindAdvHelloContext::peer, Peer::pid, GNUNET_TIME_Relative::rel_value_us, FindAdvHelloContext::result, setup_filter(), GNUNET_MessageHeader::size, and value.

Referenced by schedule_next_hello().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedule_next_hello()

static void schedule_next_hello ( void *  cls)
static

Calculate when we would like to send the next HELLO to this peer and ask for it.

Parameters
clsfor which peer to schedule the HELLO

Definition at line 440 of file gnunet-daemon-topology.c.

441{
442 struct Peer *pl = cls;
443 struct FindAdvHelloContext fah;
444 struct GNUNET_MQ_Envelope *env;
445 size_t want;
446 struct GNUNET_TIME_Relative delay;
447 struct GNUNET_HashCode hc;
448
450 "schedule_next_hello\n");
451 pl->hello_delay_task = NULL;
452 GNUNET_assert (NULL != pl->mq);
453 /* find applicable HELLOs */
454 fah.peer = pl;
455 fah.result = NULL;
456 fah.max_size = GNUNET_MAX_MESSAGE_SIZE - 1;
457 fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
459 if (NULL == fah.result)
460 {
461 pl->hello_delay_task =
463
464 return;
465 }
466 want = ntohs (fah.result->hello->size);
468 "Sending HELLO with %u bytes for peer %s\n",
469 (unsigned int) want,
470 GNUNET_i2s (&pl->pid));
471 env = GNUNET_MQ_msg_copy (fah.result->hello);
472 GNUNET_MQ_send (pl->mq, env);
473
474 /* avoid sending this one again soon */
475 GNUNET_CRYPTO_hash (&pl->pid, sizeof(struct GNUNET_PeerIdentity), &hc);
476 GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &hc);
477
479 gettext_noop ("# HELLO messages gossipped"),
480 1,
481 GNUNET_NO);
482 /* prepare to send the next one */
488}

References env, Peer::filter, find_advertisable_hello(), gettext_noop, GNUNET_assert, GNUNET_CONTAINER_bloomfilter_add(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_MQ_msg_copy(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_FOREVER_REL, Peer::hello, HELLO_ADVERTISEMENT_MIN_FREQUENCY, Peer::hello_delay_task, FindAdvHelloContext::max_size, Peer::mq, FindAdvHelloContext::next_adv, Peer::next_hello_allowed, FindAdvHelloContext::peer, peers, Peer::pid, FindAdvHelloContext::result, schedule_next_hello(), GNUNET_MessageHeader::size, and stats.

Referenced by reschedule_hellos(), and schedule_next_hello().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reschedule_hellos()

static int reschedule_hellos ( void *  cls,
const struct GNUNET_PeerIdentity pid,
void *  value 
)
static

Cancel existing requests for sending HELLOs to this peer and recalculate when we should send HELLOs to it based on our current state (something changed!).

Parameters
clsclosure struct Peer to skip, or NULL
pididentity of a peer
valuestruct Peer * for the peer
Returns
GNUNET_YES (always)

Definition at line 502 of file gnunet-daemon-topology.c.

505{
506 struct Peer *peer = value;
507 (void) cls;
508
510 "Reschedule for `%s'\n",
511 GNUNET_i2s (&peer->pid));
512 if (NULL == peer->mq)
513 return GNUNET_YES;
514 if (NULL != peer->hello_delay_task)
515 {
517 peer->hello_delay_task = NULL;
518 }
520 "Schedule_next_hello\n");
521 peer->hello_delay_task =
523 return GNUNET_YES;
524}

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, Peer::hello_delay_task, Peer::mq, Peer::pid, schedule_next_hello(), and value.

Referenced by connect_notify(), and consider_for_advertising().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connect_notify()

static void * connect_notify ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_MQ_Handle mq,
enum GNUNET_CORE_PeerClass  class 
)
static

Method called whenever a peer connects.

Parameters
clsclosure
peerpeer identity this notification is about
mqmessage queue for communicating with peer
classclass of the connecting peer
Returns
our struct Peer for peer

Definition at line 537 of file gnunet-daemon-topology.c.

541{
542 struct Peer *pos;
543
545 "Core told us that we are connecting to `%s'\n",
546 GNUNET_i2s (peer));
547 if (0 == GNUNET_memcmp (&my_identity, peer))
548 return NULL;
552 gettext_noop ("# peers connected"),
554 GNUNET_NO);
556 if (NULL == pos)
557 {
558 pos = make_peer (peer, NULL);
559 }
560 else
561 {
562 GNUNET_assert (NULL == pos->mq);
563 }
564 pos->mq = mq;
565 reschedule_hellos (NULL, peer, pos);
566 return pos;
567}

References connection_count, gettext_noop, GNUNET_assert, GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, GNUNET_MQ_PRIO_BEST_EFFORT, GNUNET_MQ_set_options(), GNUNET_NO, GNUNET_STATISTICS_set(), make_peer(), mq, Peer::mq, my_identity, peers, reschedule_hellos(), and stats.

Referenced by reconnect(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ try_add_peers()

static int try_add_peers ( void *  cls,
const struct GNUNET_PeerIdentity pid,
void *  value 
)
static

Try to add more peers to our connection set.

Parameters
clsclosure, not used
pididentity of a peer
valuestruct Peer * for the peer
Returns
GNUNET_YES (continue to iterate)

Definition at line 579 of file gnunet-daemon-topology.c.

580{
581 struct Peer *pos = value;
582
583 attempt_connect (pos);
584 return GNUNET_YES;
585}

References attempt_connect(), GNUNET_YES, and value.

Referenced by add_peer_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ add_peer_task()

static void add_peer_task ( void *  cls)
static

Add peers and schedule connection attempt.

Parameters
clsunused, NULL

Definition at line 594 of file gnunet-daemon-topology.c.

595{
596 add_task = NULL;
597
599}

References add_task, GNUNET_CONTAINER_multipeermap_iterate(), peers, and try_add_peers().

Referenced by disconnect_notify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnect_notify()

static void disconnect_notify ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  internal_cls 
)
static

Method called whenever a peer disconnects.

Parameters
clsclosure
peerpeer identity this notification is about
internal_clsthe struct Peer for this peer

Definition at line 610 of file gnunet-daemon-topology.c.

613{
614 struct Peer *pos = internal_cls;
615
616 if (NULL == pos)
617 return; /* myself, we're shutting down */
619 "Core told us that we disconnected from `%s'\n",
620 GNUNET_i2s (peer));
621 if (NULL == pos->mq)
622 {
623 GNUNET_break (0);
624 return;
625 }
626 pos->mq = NULL;
628 if (NULL != pos->hello_delay_task)
629 {
631 pos->hello_delay_task = NULL;
632 }
634 gettext_noop ("# peers connected"),
636 GNUNET_NO);
638 (NULL == add_task))
640
641}

References add_peer_task(), add_task, connection_count, gettext_noop, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), Peer::hello_delay_task, Peer::mq, stats, and target_connection_count.

Referenced by reconnect(), and run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ address_iterator()

static void address_iterator ( void *  cls,
const struct GNUNET_PeerIdentity pid,
const char *  uri 
)
static

Iterator called on each address.

Parameters
clsflag that we will set if we see any addresses
addressthe address of the peer
Returns
GNUNET_SYSERR always, to terminate iteration

Definition at line 652 of file gnunet-daemon-topology.c.

655{
656 int *flag = cls;
657 (void) pid;
658
659 *flag = *flag + 1;
660 // *flag = GNUNET_YES;
661}

References pid.

Referenced by consider_for_advertising().

Here is the caller graph for this function:

◆ consider_for_advertising()

static void consider_for_advertising ( const struct GNUNET_MessageHeader hello)
static

We've gotten a HELLO from another peer.

Consider it for advertising.

Parameters
hellothe HELLO we got

Definition at line 671 of file gnunet-daemon-topology.c.

672{
673 int num_addresses_old = 0;
674 int num_addresses_new = 0;
676 const struct GNUNET_PeerIdentity *pid;
677 struct Peer *peer;
678 uint16_t size;
679
681 if (NULL == parser)
682 {
683 return;
684 }
687 &num_addresses_new);
689 "consider 0 for %s\n",
690 GNUNET_i2s (pid));
691 if (0 == num_addresses_new)
692 {
694 return; /* no point in advertising this one... */
695 }
697 if (NULL == peer)
698 {
699 peer = make_peer (pid, hello);
700 }
701 else if (NULL != peer->hello)
702 {
704 struct GNUNET_TIME_Absolute new_hello_exp =
706 struct GNUNET_TIME_Absolute old_hello_exp =
708 struct GNUNET_HELLO_Parser *parser_old =
710
711 GNUNET_HELLO_parser_iterate (parser_old,
713 &num_addresses_old);
714 GNUNET_HELLO_parser_free (parser_old);
715 if (GNUNET_TIME_absolute_cmp (new_hello_exp, >, now) &&
716 (GNUNET_TIME_absolute_cmp (new_hello_exp, >, old_hello_exp) ||
717 num_addresses_old < num_addresses_new))
718 {
719 GNUNET_free (peer->hello);
720 size = ntohs (hello->size);
721 peer->hello = GNUNET_malloc (size);
722 GNUNET_memcpy (peer->hello, hello, size);
723 }
724 else
725 {
727 "consider 3\n");
729 return;
730 }
731 }
732 else
733 {
734 size = ntohs (hello->size);
735 peer->hello = GNUNET_malloc (size);
736 GNUNET_memcpy (peer->hello, hello, size);
737 }
739 "Found HELLO from peer `%s' for advertising\n",
740 GNUNET_i2s (pid));
741 if (NULL != peer->filter)
742 {
744 peer->filter = NULL;
745 }
746 setup_filter (peer);
747 /* since we have a new HELLO to pick from, re-schedule all
748 * HELLO requests that are not bound by the HELLO send rate! */
751}

References address_iterator(), Peer::filter, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_get_expiration_time_from_msg(), GNUNET_HELLO_parser_free(), GNUNET_HELLO_parser_from_msg(), GNUNET_HELLO_parser_iterate(), GNUNET_i2s(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_TIME_absolute_cmp, GNUNET_TIME_absolute_get(), Peer::hello, make_peer(), peers, pid, reschedule_hellos(), setup_filter(), GNUNET_MessageHeader::size, and size.

Referenced by process_peer().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ error_cb()

static void error_cb ( void *  cls)
static

Definition at line 755 of file gnunet-daemon-topology.c.

756{
758 _ (
759 "Error in communication with PEERSTORE service to monitor.\n"));
760 return;
761}

References _, GNUNET_ERROR_TYPE_DEBUG, and GNUNET_log.

Referenced by process_peer(), and start_notify().

Here is the caller graph for this function:

◆ sync_cb()

static void sync_cb ( void *  cls)
static

Definition at line 765 of file gnunet-daemon-topology.c.

766{
768 _ ("Finished initial PEERSTORE iteration in monitor.\n"));
769 return;
770}

References _, GNUNET_ERROR_TYPE_DEBUG, and GNUNET_log.

Referenced by process_peer(), and start_notify().

Here is the caller graph for this function:

◆ process_peer()

static void process_peer ( void *  cls,
const struct GNUNET_PEERSTORE_Record record,
const char *  err_msg 
)
static

PEERSTORE calls this function to let us know about a possible peer that we might want to connect to.

Parameters
clsclosure (not used)
peerpotential peer to connect to
helloHELLO for this peer (or NULL)
err_msgNULL if successful, otherwise contains error message

Definition at line 783 of file gnunet-daemon-topology.c.

786{
787 struct Peer *pos;
788 struct GNUNET_MessageHeader *hello;
789
790 if (NULL != err_msg)
791 {
793 _ ("Error in communication with PEERSTORE service: %s\n"),
794 err_msg);
799 "peerstore",
800 NULL,
802 error_cb,
803 NULL,
804 sync_cb,
805 NULL,
807 NULL);
808 return;
809 }
810 GNUNET_assert (NULL != record);
812 "Processing HELLO from peerstore from peer `%s'\n",
813 GNUNET_i2s (&record->peer));
814 hello = record->value;
815 if (NULL == hello)
816 {
817 /* free existing HELLO, if any */
819 if (NULL != pos)
820 {
821 GNUNET_free (pos->hello);
822 pos->hello = NULL;
823 if (NULL != pos->filter)
824 {
826 pos->filter = NULL;
827 }
828 if (NULL == pos->mq)
829 free_peer (NULL, &pos->pid, pos);
830 }
832 return;
833 }
836 if (NULL == pos)
837 pos = make_peer (&record->peer, hello);
838 attempt_connect (pos);
840}

References _, attempt_connect(), cfg, consider_for_advertising(), error_cb(), Peer::filter, free_peer(), GNUNET_assert, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_PEERSTORE_HELLO_KEY, GNUNET_PEERSTORE_monitor_next(), GNUNET_PEERSTORE_monitor_start(), GNUNET_PEERSTORE_monitor_stop(), GNUNET_YES, Peer::hello, make_peer(), Peer::mq, peers, peerstore_notify, Peer::pid, process_peer(), record(), and sync_cb().

Referenced by process_peer(), and start_notify().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_notify()

static void start_notify ( void *  cls)
static

Definition at line 844 of file gnunet-daemon-topology.c.

845{
846 (void) cls;
847
849 "Starting to process new hellos for gossiping.\n");
853 "peerstore",
854 NULL,
856 &error_cb,
857 NULL,
858 &sync_cb,
859 NULL,
861 NULL);
862}

References cfg, error_cb(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_PEERSTORE_HELLO_KEY, GNUNET_PEERSTORE_monitor_start(), GNUNET_YES, peerstore_notify, process_peer(), and sync_cb().

Referenced by core_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pid_change_cb()

static void pid_change_cb ( void *  cls,
const struct GNUNET_HELLO_Parser parser,
const struct GNUNET_HashCode addr_hash 
)
static

Definition at line 865 of file gnunet-daemon-topology.c.

868{
870}

References GNUNET_HELLO_parser_get_id(), and my_identity.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ core_init()

static void core_init ( void *  cls,
const struct GNUNET_PeerIdentity my_id 
)
static

Function called after GNUNET_CORE_connect has succeeded (or failed for good).

Parameters
clsclosure
my_idID of this peer, NULL if we failed

Definition at line 880 of file gnunet-daemon-topology.c.

881{
882 if (NULL == my_id)
883 {
884 GNUNET_log (
886 _ ("Failed to connect to core service, can not manage topology!\n"));
888 return;
889 }
890 my_identity = *my_id;
891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id));
895 NULL);
896}

References _, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_shutdown(), GNUNET_TIME_UNIT_SECONDS, my_identity, peerstore_notify_task, and start_notify().

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_hello()

static int check_hello ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

This function is called whenever an encrypted HELLO message is received.

Parameters
clsclosure with the peer identity of the sender
messagethe actual HELLO message
Returns
GNUNET_OK if message is well-formed GNUNET_SYSERR if message is invalid

Definition at line 909 of file gnunet-daemon-topology.c.

910{
912 const struct GNUNET_PeerIdentity *pid = GNUNET_HELLO_parser_get_id (parser);
913
914 if (NULL == pid)
915 {
916 GNUNET_break_op (0);
917 return GNUNET_SYSERR;
918 }
919 return GNUNET_OK;
920}

References GNUNET_break_op, GNUNET_HELLO_parser_from_msg(), GNUNET_HELLO_parser_get_id(), GNUNET_OK, GNUNET_SYSERR, msg, and pid.

Here is the call graph for this function:

◆ shc_cont()

static void shc_cont ( void *  cls,
int  success 
)
static

Definition at line 924 of file gnunet-daemon-topology.c.

925{
926 struct StoreHelloEntry *she = cls;
927
928 she->sc = NULL;
929 if (GNUNET_YES == success)
931 "Hello stored successfully!\n");
932 else
934 "Error storing hello!\n");
936 GNUNET_free (she);
937}

References GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_YES, StoreHelloEntry::sc, she_head, and she_tail.

Referenced by handle_hello().

Here is the caller graph for this function:

◆ handle_hello()

static void handle_hello ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

This function is called whenever an encrypted HELLO message is received.

Parameters
clsclosure with the peer identity of the sender
messagethe actual HELLO message

Definition at line 948 of file gnunet-daemon-topology.c.

949{
950 struct StoreHelloEntry *she;
951 const struct GNUNET_PeerIdentity *other = cls;
953
955 "Received encrypted HELLO from peer `%s'\n",
956 GNUNET_i2s (other));
958 gettext_noop ("# HELLO messages received"),
959 1,
960 GNUNET_NO);
962 she = GNUNET_new (struct StoreHelloEntry);
964 if (NULL != she->sc)
965 {
967 }
968 else
969 GNUNET_free (she);
971}

References gettext_noop, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_parser_free(), GNUNET_HELLO_parser_from_msg(), GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_PEERSTORE_hello_add(), GNUNET_STATISTICS_update(), msg, ps, StoreHelloEntry::sc, shc_cont(), she_head, she_tail, and stats.

Here is the call graph for this function:

◆ cleaning_task()

static void cleaning_task ( void *  cls)
static

Last task run during shutdown.

Disconnects us from the transport and core.

Parameters
clsunused, NULL

Definition at line 981 of file gnunet-daemon-topology.c.

982{
983 struct StoreHelloEntry *pos;
984
985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Topology shutdown\n");
986 while (NULL != (pos = she_head))
987 {
989 if (NULL != pos->sc)
991 GNUNET_free (pos);
992 }
993 if (NULL != peerstore_notify)
994 {
996 peerstore_notify = NULL;
997 }
998 else if (NULL != peerstore_notify_task)
999 {
1001 }
1002 if (NULL != pils)
1003 {
1005 pils = NULL;
1006 }
1007 if (NULL != handle)
1008 {
1010 handle = NULL;
1011 }
1012 if (NULL != add_task)
1013 {
1015 add_task = NULL;
1016 }
1019 peers = NULL;
1020 if (NULL != transport)
1021 {
1023 transport = NULL;
1024 }
1025 if (NULL != ps)
1026 {
1028 ps = NULL;
1029 }
1030 if (NULL != stats)
1031 {
1033 stats = NULL;
1034 }
1035}

References add_task, free_peer(), GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CORE_disconnect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_PEERSTORE_disconnect(), GNUNET_PEERSTORE_hello_add_cancel(), GNUNET_PEERSTORE_monitor_stop(), GNUNET_PILS_disconnect(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_TRANSPORT_application_done(), handle, peers, peerstore_notify, peerstore_notify_task, pils, ps, StoreHelloEntry::sc, she_head, she_tail, stats, and transport.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle c 
)
static

Main function that will be run.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
cconfiguration

Definition at line 1047 of file gnunet-daemon-topology.c.

1051{
1053 { GNUNET_MQ_hd_var_size (hello,
1055 struct GNUNET_MessageHeader,
1056 NULL),
1058 unsigned long long opt;
1059 const struct GNUNET_CORE_ServiceInfo service_info =
1060 {
1062 .version = { 1, 0 },
1063 .version_max = { 1, 0 },
1064 .version_min = { 1, 0 },
1065 };
1066
1067 cfg = c;
1068 stats = GNUNET_STATISTICS_create ("topology", cfg);
1069
1070 if (GNUNET_OK !=
1072 "TOPOLOGY",
1073 "TARGET-CONNECTION-COUNT",
1074 &opt))
1075 opt = 16;
1076 target_connection_count = (unsigned int) opt;
1078 GNUNET_NO);
1082 NULL,
1083 &core_init,
1086 handlers,
1087 &service_info);
1090 if (NULL == pils)
1091 {
1093 _ ("Failed to connect to `%s' service.\n"),
1094 "pils");
1096 return;
1097 }
1098 if (NULL == handle)
1099 {
1101 _ ("Failed to connect to `%s' service.\n"),
1102 "core");
1104 return;
1105 }
1106}

References _, cfg, cleaning_task(), connect_notify(), core_init(), disconnect_notify(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_CORE_connect(), GNUNET_CORE_SERVICE_TOPOLOGY, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MESSAGE_TYPE_HELLO_URI, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_OK, GNUNET_PEERSTORE_connect(), GNUNET_PILS_connect(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_TRANSPORT_application_init(), handle, handlers, peers, pid_change_cb(), pils, ps, GNUNET_CORE_ServiceInfo::service, stats, target_connection_count, and transport.

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

The main function for the topology daemon.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 1117 of file gnunet-daemon-topology.c.

1118{
1119 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1121 };
1122 int ret;
1123
1124 ret = (GNUNET_OK ==
1126 argc,
1127 argv,
1128 "gnunet-daemon-topology",
1129 _ ("GNUnet topology control"),
1130 options,
1131 &run,
1132 NULL))
1133 ? 0
1134 : 1;
1135 return ret;
1136}

References _, GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_OS_project_data_gnunet(), GNUNET_PROGRAM_run(), options, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ peerstore_notify_task

struct GNUNET_SCHEDULER_Task* peerstore_notify_task

The task to delayed start the notification process initially.

We like to give transport some time to give us our hello to distribute it.

Definition at line 136 of file gnunet-daemon-topology.c.

Referenced by cleaning_task(), and core_init().

◆ peerstore_notify

struct GNUNET_PEERSTORE_Monitor* peerstore_notify
static

Our peerstore notification context.

We use notification to instantly learn about new peers as they are discovered.

Definition at line 143 of file gnunet-daemon-topology.c.

Referenced by cleaning_task(), process_peer(), and start_notify().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

Definition at line 148 of file gnunet-daemon-topology.c.

Referenced by process_peer(), run(), and start_notify().

◆ pils

struct GNUNET_PILS_Handle* pils
static

Handle to the PILS service.

Definition at line 153 of file gnunet-daemon-topology.c.

Referenced by cleaning_task(), and run().

◆ handle

struct GNUNET_CORE_Handle* handle
static

Handle to the CORE service.

Definition at line 158 of file gnunet-daemon-topology.c.

Referenced by cleaning_task(), and run().

◆ ps

◆ transport

Handle to Transport service.

Definition at line 168 of file gnunet-daemon-topology.c.

Referenced by attempt_connect(), cleaning_task(), and run().

◆ my_identity

struct GNUNET_PeerIdentity my_identity
static

Identity of this peer.

Definition at line 173 of file gnunet-daemon-topology.c.

Referenced by attempt_connect(), connect_notify(), core_init(), and pid_change_cb().

◆ peers

struct GNUNET_CONTAINER_MultiPeerMap* peers
static

All of our current neighbours and all peers for which we have HELLOs.

So pretty much everyone. Maps peer identities to struct Peer * values.

Definition at line 180 of file gnunet-daemon-topology.c.

Referenced by add_peer_task(), cleaning_task(), connect_notify(), consider_for_advertising(), free_peer(), make_peer(), process_peer(), run(), and schedule_next_hello().

◆ stats

struct GNUNET_STATISTICS_Handle* stats
static

Handle for reporting statistics.

Definition at line 185 of file gnunet-daemon-topology.c.

Referenced by attempt_connect(), cleaning_task(), connect_notify(), disconnect_notify(), handle_hello(), run(), and schedule_next_hello().

◆ add_task

struct GNUNET_SCHEDULER_Task* add_task
static

Task scheduled to asynchronously reconsider adding/removing peer connectivity suggestions.

Definition at line 191 of file gnunet-daemon-topology.c.

Referenced by add_peer_task(), cleaning_task(), and disconnect_notify().

◆ connection_count

unsigned int connection_count
static

Number of peers that we are currently connected to.

Definition at line 196 of file gnunet-daemon-topology.c.

Referenced by attempt_connect(), connect_notify(), and disconnect_notify().

◆ target_connection_count

unsigned int target_connection_count
static

Target number of connections.

Definition at line 201 of file gnunet-daemon-topology.c.

Referenced by attempt_connect(), disconnect_notify(), and run().

◆ she_head

struct StoreHelloEntry* she_head
static

Head of the linkd list to store the store context for hellos.

Definition at line 206 of file gnunet-daemon-topology.c.

Referenced by cleaning_task(), handle_hello(), and shc_cont().

◆ she_tail

struct StoreHelloEntry* she_tail
static

Tail of the linkd list to store the store context for hellos.

Definition at line 211 of file gnunet-daemon-topology.c.

Referenced by cleaning_task(), handle_hello(), and shc_cont().