GNUnet 0.21.2
gnunet-daemon-topology.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2007-2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
30#include "platform.h"
31#include "gnunet_util_lib.h"
33#include "gnunet_constants.h"
34#include "gnunet_core_service.h"
35#include "gnunet_protocols.h"
39#include <assert.h>
40
41
45#define HELLO_ADVERTISEMENT_MIN_FREQUENCY \
46 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
47
51#define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY \
52 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4)
53
54
58struct Peer
59{
64
70
75
81
86
91
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
153
158
163
168
173
180
185
191
195static unsigned int connection_count;
196
200static unsigned int target_connection_count;
201
206
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
261{
262 uint32_t strength;
264
265 if (0 == GNUNET_memcmp (&my_identity, &pos->pid))
266 return; /* This is myself, nothing to do. */
268 strength = 1;
269 else
270 strength = 0;
271 if (NULL != pos->mq)
272 strength *= 2; /* existing connections preferred */
273 if (NULL != pos->ash)
274 {
276 pos->ash = NULL;
277 }
278 pos->strength = strength;
279 if (0 != strength)
280 {
282 "Asking to connect to `%s' with strength %u\n",
283 GNUNET_i2s (&pos->pid),
284 (unsigned int) strength);
286 gettext_noop ("# connect requests issued to ATS"),
287 1,
288 GNUNET_NO);
289 // TODO Use strength somehow.
290 bw.value__ = 0;
292 &pos->pid,
294 bw);
295 }
296}
297
298
306static struct Peer *
307make_peer (const struct GNUNET_PeerIdentity *peer,
308 const struct GNUNET_MessageHeader *hello)
309{
310 struct Peer *ret;
311
312 ret = GNUNET_new (struct Peer);
313 ret->pid = *peer;
314 if (NULL != hello)
315 {
316 ret->hello = GNUNET_malloc (ntohs (hello->size));
317 GNUNET_memcpy (ret->hello, hello, ntohs (hello->size));
318 }
321 peers,
322 peer,
323 ret,
325 return ret;
326}
327
328
334static void
335setup_filter (struct Peer *peer)
336{
337 struct GNUNET_HashCode hc;
338
339 /* 2^{-5} chance of not sending a HELLO to a peer is
340 * acceptably small (if the filter is 50% full);
341 * 64 bytes of memory are small compared to the rest
342 * of the data structure and would only really become
343 * "useless" once a HELLO has been passed on to ~100
344 * other peers, which is likely more than enough in
345 * any case; hence 64, 5 as bloomfilter parameters. */peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5);
346 peer->filter_expiration =
348 /* never send a peer its own HELLO */
349 GNUNET_CRYPTO_hash (&peer->pid, sizeof(struct GNUNET_PeerIdentity), &hc);
351}
352
353
358{
362 struct Peer *peer;
363
367 struct Peer *result;
368
372 size_t max_size;
373
375};
376
377
386static int
388 const struct GNUNET_PeerIdentity *pid,
389 void *value)
390{
391 struct FindAdvHelloContext *fah = cls;
392 struct Peer *pos = value;
393 struct GNUNET_TIME_Relative rst_time;
394 struct GNUNET_HashCode hc;
395 size_t hs;
396
398 "find_advertisable_hello\n");
399 if (pos == fah->peer)
400 return GNUNET_YES;
402 "find_advertisable_hello 2\n");
403 if (pos->hello == NULL)
404 return GNUNET_YES;
406 "find_advertisable_hello 3\n");
408 if (0 == rst_time.rel_value_us)
409 {
410 /* time to discard... */
412 setup_filter (pos);
413 }
414 fah->next_adv = GNUNET_TIME_relative_min (rst_time, fah->next_adv);
415 hs = pos->hello->size;
416 if (hs > fah->max_size)
417 return GNUNET_YES;
419 "find_advertisable_hello 4\n");
421 sizeof(struct GNUNET_PeerIdentity),
422 &hc);
424 fah->result = pos;
425 return GNUNET_YES;
426}
427
428
435static void
437{
438 struct Peer *pl = cls;
439 struct FindAdvHelloContext fah;
440 struct GNUNET_MQ_Envelope *env;
441 size_t want;
442 struct GNUNET_TIME_Relative delay;
443 struct GNUNET_HashCode hc;
444
446 "schedule_next_hello\n");
447 pl->hello_delay_task = NULL;
448 GNUNET_assert (NULL != pl->mq);
449 /* find applicable HELLOs */
450 fah.peer = pl;
451 fah.result = NULL;
455 if (NULL == fah.result)
456 {
457 pl->hello_delay_task =
459
460 return;
461 }
462 want = ntohs (fah.result->hello->size);
464 "Sending HELLO with %u bytes for peer %s\n",
465 (unsigned int) want,
466 GNUNET_i2s (&pl->pid));
468 GNUNET_MQ_send (pl->mq, env);
469
470 /* avoid sending this one again soon */
471 GNUNET_CRYPTO_hash (&pl->pid, sizeof(struct GNUNET_PeerIdentity), &hc);
473
475 gettext_noop ("# HELLO messages gossipped"),
476 1,
477 GNUNET_NO);
478 /* prepare to send the next one */
483}
484
485
496static int
498 const struct GNUNET_PeerIdentity *pid,
499 void *value)
500{
501 (void) cls;
502 struct Peer *peer = value;
503
505 "Reschedule for `%s'\n",
506 GNUNET_i2s (&peer->pid));
507 if (NULL == peer->mq)
508 return GNUNET_YES;
509 if (NULL != peer->hello_delay_task)
510 {
512 peer->hello_delay_task = NULL;
513 }
515 "Schedule_next_hello\n");
516 peer->hello_delay_task =
518 return GNUNET_YES;
519}
520
521
530static void *
531connect_notify (void *cls,
532 const struct GNUNET_PeerIdentity *peer,
533 struct GNUNET_MQ_Handle *mq)
534{
535 struct Peer *pos;
536
538 "Core told us that we are connecting to `%s'\n",
539 GNUNET_i2s (peer));
540 if (0 == GNUNET_memcmp (&my_identity, peer))
541 return NULL;
545 gettext_noop ("# peers connected"),
547 GNUNET_NO);
549 if (NULL == pos)
550 {
551 pos = make_peer (peer, NULL);
552 }
553 else
554 {
555 GNUNET_assert (NULL == pos->mq);
556 }
557 pos->mq = mq;
558 reschedule_hellos (NULL, peer, pos);
559 return pos;
560}
561
562
571static int
572try_add_peers (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
573{
574 struct Peer *pos = value;
575
576 attempt_connect (pos);
577 return GNUNET_YES;
578}
579
580
586static void
587add_peer_task (void *cls)
588{
589 add_task = NULL;
590
592}
593
594
602static void
604 const struct GNUNET_PeerIdentity *peer,
605 void *internal_cls)
606{
607 struct Peer *pos = internal_cls;
608
609 if (NULL == pos)
610 return; /* myself, we're shutting down */
612 "Core told us that we disconnected from `%s'\n",
613 GNUNET_i2s (peer));
614 if (NULL == pos->mq)
615 {
616 GNUNET_break (0);
617 return;
618 }
619 pos->mq = NULL;
621 if (NULL != pos->hello_delay_task)
622 {
624 pos->hello_delay_task = NULL;
625 }
627 gettext_noop ("# peers connected"),
629 GNUNET_NO);
631 (NULL == add_task))
633
634}
635
636
644static void
646 const struct GNUNET_PeerIdentity *pid,
647 const char *uri)
648{
649 (void) pid;
650 int *flag = cls;
651
652 *flag = *flag + 1;
653 // *flag = GNUNET_YES;
654}
655
656
663static void
665{
666 int num_addresses_old = 0;
667 int num_addresses_new = 0;
669 const struct GNUNET_PeerIdentity *pid;
670 struct Peer *peer;
671 uint16_t size;
672
675 &num_addresses_new);
677 "consider 0 for %s\n",
678 GNUNET_i2s (pid));
679 if (0 == num_addresses_new)
680 {
682 return; /* no point in advertising this one... */
683 }
685 if (NULL == peer)
686 {
687 peer = make_peer (pid, hello);
688 }
689 else if (NULL != peer->hello)
690 {
692 struct GNUNET_TIME_Absolute new_hello_exp =
694 struct GNUNET_TIME_Absolute old_hello_exp =
697 peer->hello);
698
699 GNUNET_HELLO_builder_iterate (builder_old,
701 &num_addresses_old);
702 GNUNET_HELLO_builder_free (builder_old);
703 if (GNUNET_TIME_absolute_cmp (new_hello_exp, >, now) &&
704 (GNUNET_TIME_absolute_cmp (new_hello_exp, >, old_hello_exp) ||
705 num_addresses_old < num_addresses_new))
706 {
707 GNUNET_free (peer->hello);
708 size = ntohs (hello->size);
709 peer->hello = GNUNET_malloc (size);
710 GNUNET_memcpy (peer->hello, hello, size);
711 }
712 else
713 {
715 "consider 3\n");
717 return;
718 }
719 }
720 else
721 {
722 size = ntohs (hello->size);
723 peer->hello = GNUNET_malloc (size);
724 GNUNET_memcpy (peer->hello, hello, size);
725 }
727 "Found HELLO from peer `%s' for advertising\n",
728 GNUNET_i2s (pid));
729 if (NULL != peer->filter)
730 {
732 peer->filter = NULL;
733 }
734 setup_filter (peer);
735 /* since we have a new HELLO to pick from, re-schedule all
736 * HELLO requests that are not bound by the HELLO send rate! */
739}
740
741
742static void
743error_cb (void *cls)
744{
746 _ (
747 "Error in communication with PEERSTORE service to monitor.\n"));
748 return;
749}
750
751
752static void
753sync_cb (void *cls)
754{
756 _ ("Finished initial PEERSTORE iteration in monitor.\n"));
757 return;
758}
759
760
770static void
771process_peer (void *cls,
772 const struct GNUNET_PEERSTORE_Record *record,
773 const char *err_msg)
774{
775 struct Peer *pos;
776 struct GNUNET_MessageHeader *hello;
777
778 if (NULL != err_msg)
779 {
781 _ ("Error in communication with PEERSTORE service: %s\n"),
782 err_msg);
787 "peerstore",
788 NULL,
790 error_cb,
791 NULL,
792 sync_cb,
793 NULL,
795 NULL);
796 return;
797 }
798 GNUNET_assert (NULL != record);
799 hello = record->value;
800 if (NULL == hello)
801 {
802 /* free existing HELLO, if any */
804 if (NULL != pos)
805 {
806 GNUNET_free (pos->hello);
807 pos->hello = NULL;
808 if (NULL != pos->filter)
809 {
811 pos->filter = NULL;
812 }
813 if (NULL == pos->mq)
814 free_peer (NULL, &pos->pid, pos);
815 }
817 return;
818 }
821 if (NULL == pos)
822 pos = make_peer (&record->peer, hello);
823 attempt_connect (pos);
825}
826
827
828static void
829start_notify (void *cls)
830{
831 (void) cls;
832
834 "Starting to process new hellos for gossiping.\n");
838 "peerstore",
839 NULL,
841 &error_cb,
842 NULL,
843 &sync_cb,
844 NULL,
846 NULL);
847}
848
849
857static void
858core_init (void *cls, const struct GNUNET_PeerIdentity *my_id)
859{
860 if (NULL == my_id)
861 {
862 GNUNET_log (
864 _ ("Failed to connect to core service, can not manage topology!\n"));
866 return;
867 }
868 my_identity = *my_id;
869 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id));
873 NULL);
874}
875
876
886static int
887check_hello (void *cls, const struct GNUNET_MessageHeader *message)
888{
890 message);
892
893 if (NULL == pid)
894 {
895 GNUNET_break_op (0);
896 return GNUNET_SYSERR;
897 }
898 return GNUNET_OK;
899}
900
901
902static void
903shc_cont (void *cls, int success)
904{
905 struct StoreHelloEntry *she = cls;
906
907 she->sc = NULL;
908 if (GNUNET_YES == success)
910 "Hello stored successfully!\n");
911 else
913 "Error storing hello!\n");
915 GNUNET_free (she);
916}
917
918
926static void
927handle_hello (void *cls, const struct GNUNET_MessageHeader *message)
928{
929 struct StoreHelloEntry *she;
930 const struct GNUNET_PeerIdentity *other = cls;
932 message);
933
935 "Received encrypted HELLO from peer `%s'\n",
936 GNUNET_i2s (other));
938 gettext_noop ("# HELLO messages received"),
939 1,
940 GNUNET_NO);
942 she = GNUNET_new (struct StoreHelloEntry);
943 she->sc = GNUNET_PEERSTORE_hello_add (ps, message, &shc_cont, she);
944 if (NULL != she->sc)
945 {
947 }
948 else
949 GNUNET_free (she);
951}
952
953
960static void
961cleaning_task (void *cls)
962{
963 struct StoreHelloEntry *pos;
964
965 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Topology shutdown\n");
966 while (NULL != (pos = she_head))
967 {
969 if (NULL != pos->sc)
971 GNUNET_free (pos);
972 }
973 if (NULL != peerstore_notify)
974 {
976 peerstore_notify = NULL;
977 }
978 else if (NULL != peerstore_notify_task)
979 {
981 }
982 if (NULL != handle)
983 {
985 handle = NULL;
986 }
987 if (NULL != add_task)
988 {
990 add_task = NULL;
991 }
994 peers = NULL;
995 if (NULL != transport)
996 {
998 transport = NULL;
999 }
1000 if (NULL != ps)
1001 {
1003 ps = NULL;
1004 }
1005 if (NULL != stats)
1006 {
1008 stats = NULL;
1009 }
1011}
1012
1013
1022static void
1023run (void *cls,
1024 char *const *args,
1025 const char *cfgfile,
1026 const struct GNUNET_CONFIGURATION_Handle *c)
1027{
1029 { GNUNET_MQ_hd_var_size (hello,
1031 struct GNUNET_MessageHeader,
1032 NULL),
1034 unsigned long long opt;
1035
1036 cfg = c;
1039 stats = GNUNET_STATISTICS_create ("topology", cfg);
1040
1041 if (GNUNET_OK !=
1043 "TOPOLOGY",
1044 "TARGET-CONNECTION-COUNT",
1045 &opt))
1046 opt = 16;
1047 target_connection_count = (unsigned int) opt;
1049 GNUNET_NO);
1053 NULL,
1054 &core_init,
1057 handlers);
1059 if (NULL == handle)
1060 {
1062 _ ("Failed to connect to `%s' service.\n"),
1063 "core");
1065 return;
1066 }
1067}
1068
1069
1077int
1078main (int argc, char *const *argv)
1079{
1080 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1082 };
1083 int ret;
1084
1085 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
1086 return 2;
1087
1088 ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc,
1089 argv,
1090 "gnunet-daemon-topology",
1091 _ ("GNUnet topology control"),
1092 options,
1093 &run,
1094 NULL))
1095 ? 0
1096 : 1;
1097 GNUNET_free_nz ((void *) argv);
1098 return ret;
1099}
1100
1101
1102#if defined(__linux__) && defined(__GLIBC__)
1103#include <malloc.h>
1104
1108void __attribute__ ((constructor))
1109GNUNET_TOPOLOGY_memory_init ()
1110{
1111 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
1112 mallopt (M_TOP_PAD, 1 * 1024);
1113 malloc_trim (0);
1114}
1115
1116
1117#endif
1118
1119/* end of gnunet-daemon-topology.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define gettext_noop(String)
Definition: gettext.h:74
static int ret
Final status code.
Definition: gnunet-arm.c:94
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
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 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 int check_hello(void *cls, const struct GNUNET_MessageHeader *message)
This function is called whenever an encrypted HELLO message is received.
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 handle_hello(void *cls, const struct GNUNET_MessageHeader *message)
This function is called whenever an encrypted HELLO message is received.
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 * connect_notify(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a peer connects.
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...
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)
int main(int argc, char *const *argv)
The main function for the topology daemon.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
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 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_PeerIdentity pid
Identity of the peer we transmit to / connect to.
Core service; the main API for encrypted P2P communications.
Helper library for handling HELLO URIs.
API to the peerstore service.
struct GNUNET_PQ_ResultSpec __attribute__
Constants for network protocols.
API to create, modify and access statistics.
Bandwidth allocation API for applications to interact with.
#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.
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)
Connect to the core service.
Definition: core_api.c:691
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:729
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer's key from the file specified in the configuration.
#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.
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_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition: hello-uri.c:373
const struct GNUNET_PeerIdentity * GNUNET_HELLO_builder_iterate(const struct GNUNET_HELLO_Builder *builder, GNUNET_HELLO_UriCallback uc, void *uc_cls)
Iterate over URIs in a builder.
Definition: hello-uri.c:909
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_msg(const struct GNUNET_MessageHeader *msg)
Parse msg into builder.
Definition: hello-uri.c:391
const struct GNUNET_PeerIdentity * GNUNET_HELLO_builder_get_id(const struct GNUNET_HELLO_Builder *builder)
Get the PeerIdentity for this builder.
Definition: hello-uri.c:366
struct GNUNET_TIME_Absolute GNUNET_HELLO_builder_get_expiration_time(const struct GNUNET_MessageHeader *msg)
Get the expiration time for this HELLO.
Definition: hello-uri.c:470
#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.
#define GNUNET_free_nz(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.
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(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:400
#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:1340
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
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:1305
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:1278
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).
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1230
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:343
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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:405
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
#define GNUNET_TIME_UNIT_MINUTES
One minute.
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:178
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.
uint32_t value__
The actual value (bytes per second).
Internal representation of the hash map.
Context for the core service connection.
Definition: core_api.c:78
Private ECC key encoded for transmission.
Definition of a command line option.
Context for building (or parsing) HELLO URIs.
Definition: hello-uri.c:205
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.
Definition: peerstore_api.c:44
Context for a monitor.
Single PEERSTORE record.
Context for a add hello uri request.
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.
uint64_t rel_value_us
The actual value.
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.