GNUnet 0.22.2
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? More...
 
#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? More...
 

Functions

static int free_peer (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 Free all resources associated with the given peer. More...
 
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. More...
 
static struct Peermake_peer (const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *hello)
 Create a new entry in the peer list. More...
 
static void setup_filter (struct Peer *peer)
 Setup bloom filter for the given peer entry. More...
 
static int find_advertisable_hello (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 Find a peer that would be reasonable for advertising. More...
 
static void schedule_next_hello (void *cls)
 Calculate when we would like to send the next HELLO to this peer and ask for it. More...
 
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!). More...
 
static void * connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
 Method called whenever a peer connects. More...
 
static int try_add_peers (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 Try to add more peers to our connection set. More...
 
static void add_peer_task (void *cls)
 Add peers and schedule connection attempt. More...
 
static void disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
 Method called whenever a peer disconnects. More...
 
static void address_iterator (void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
 Iterator called on each address. More...
 
static void consider_for_advertising (const struct GNUNET_MessageHeader *hello)
 We've gotten a HELLO from another peer. More...
 
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. More...
 
static void start_notify (void *cls)
 
static void core_init (void *cls, const struct GNUNET_PeerIdentity *my_id)
 Function called after GNUNET_CORE_connect has succeeded (or failed for good). More...
 
static int check_hello (void *cls, const struct GNUNET_MessageHeader *msg)
 This function is called whenever an encrypted HELLO message is received. More...
 
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. More...
 
static void cleaning_task (void *cls)
 Last task run during shutdown. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Main function that will be run. More...
 
int main (int argc, char *const *argv)
 The main function for the topology daemon. More...
 

Variables

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

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 45 of file gnunet-daemon-topology.c.

◆ 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 51 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 221 of file gnunet-daemon-topology.c.

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}
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our current neighbours and all peers for which we have HELLOs.
static char * value
Value of the record to add/remove.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
void GNUNET_TRANSPORT_application_suggest_cancel(struct GNUNET_TRANSPORT_ApplicationSuggestHandle *sh)
We no longer care about being connected to a peer.
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_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_OK
@ GNUNET_YES
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
Record for neighbours and blacklisted peers.
struct GNUNET_MessageHeader * hello
Pointer to the hello uri of this peer; can be NULL.
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_TRANSPORT_ApplicationSuggestHandle * ash
Transport suggest handle.
struct GNUNET_MQ_Handle * mq
Our handle for transmitting to this peer; NULL if peer is not connected.

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 260 of file gnunet-daemon-topology.c.

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}
#define gettext_noop(String)
Definition: gettext.h:74
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
static unsigned int target_connection_count
Target number of connections.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
static unsigned int connection_count
Number of peers that we are currently connected to.
struct GNUNET_TRANSPORT_ApplicationHandle * transport
Handle to Transport service.
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.
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
@ GNUNET_NO
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_MQ_PRIO_BEST_EFFORT
Best-effort traffic (e.g.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
struct GNUNET_PeerIdentity pid
Which peer is this entry about?
uint32_t strength
How much would we like to connect to this peer?

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 307 of file gnunet-daemon-topology.c.

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}
static int ret
Final status code.
Definition: gnunet-arm.c:93
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.
@ 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...
#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.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.

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 335 of file gnunet-daemon-topology.c.

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}
#define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY
After what time period do we expire the HELLO Bloom filter?
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.
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
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
A 512-bit hashcode.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_TIME_Absolute filter_expiration
When should we reset the bloom filter of this entry?

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 387 of file gnunet-daemon-topology.c.

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}
static void setup_filter(struct Peer *peer)
Setup bloom filter for the given peer entry.
bool GNUNET_CONTAINER_bloomfilter_test(const struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Test if an element is in the filter.
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
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
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).
Time for relative time used by GNUnet, in microseconds.

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 436 of file gnunet-daemon-topology.c.

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;
452 fah.max_size = GNUNET_MAX_MESSAGE_SIZE - 1;
453 fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
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));
467 env = GNUNET_MQ_msg_copy (fah.result->hello);
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);
472 GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &hc);
473
475 gettext_noop ("# HELLO messages gossipped"),
476 1,
477 GNUNET_NO);
478 /* prepare to send the next one */
484}
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void schedule_next_hello(void *cls)
Calculate when we would like to send the next HELLO to this peer and ask for it.
#define HELLO_ADVERTISEMENT_MIN_FREQUENCY
At what frequency do we sent HELLOs to a peer?
static int find_advertisable_hello(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Find a peer that would be reasonable for advertising.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:305
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
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
struct GNUNET_TIME_Absolute next_hello_allowed
Next time we are allowed to transmit a HELLO to this peer?

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 498 of file gnunet-daemon-topology.c.

501{
502 struct Peer *peer = value;
503 (void) cls;
504
506 "Reschedule for `%s'\n",
507 GNUNET_i2s (&peer->pid));
508 if (NULL == peer->mq)
509 return GNUNET_YES;
510 if (NULL != peer->hello_delay_task)
511 {
513 peer->hello_delay_task = NULL;
514 }
516 "Schedule_next_hello\n");
517 peer->hello_delay_task =
519 return GNUNET_YES;
520}
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

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 
)
static

Method called whenever a peer connects.

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

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

535{
536 struct Peer *pos;
537
539 "Core told us that we are connecting to `%s'\n",
540 GNUNET_i2s (peer));
541 if (0 == GNUNET_memcmp (&my_identity, peer))
542 return NULL;
546 gettext_noop ("# peers connected"),
548 GNUNET_NO);
550 if (NULL == pos)
551 {
552 pos = make_peer (peer, NULL);
553 }
554 else
555 {
556 GNUNET_assert (NULL == pos->mq);
557 }
558 pos->mq = mq;
559 reschedule_hellos (NULL, peer, pos);
560 return pos;
561}
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
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 struct Peer * make_peer(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *hello)
Create a new entry in the peer list.
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_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_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.

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 573 of file gnunet-daemon-topology.c.

574{
575 struct Peer *pos = value;
576
577 attempt_connect (pos);
578 return GNUNET_YES;
579}
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.

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 588 of file gnunet-daemon-topology.c.

589{
590 add_task = NULL;
591
593}
static struct GNUNET_SCHEDULER_Task * add_task
Task scheduled to asynchronously reconsider adding/removing peer connectivity suggestions.
static int try_add_peers(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Try to add more peers to our connection set.

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 604 of file gnunet-daemon-topology.c.

607{
608 struct Peer *pos = internal_cls;
609
610 if (NULL == pos)
611 return; /* myself, we're shutting down */
613 "Core told us that we disconnected from `%s'\n",
614 GNUNET_i2s (peer));
615 if (NULL == pos->mq)
616 {
617 GNUNET_break (0);
618 return;
619 }
620 pos->mq = NULL;
622 if (NULL != pos->hello_delay_task)
623 {
625 pos->hello_delay_task = NULL;
626 }
628 gettext_noop ("# peers connected"),
630 GNUNET_NO);
632 (NULL == add_task))
634
635}
static void add_peer_task(void *cls)
Add peers and schedule connection attempt.

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 646 of file gnunet-daemon-topology.c.

649{
650 int *flag = cls;
651 (void) pid;
652
653 *flag = *flag + 1;
654 // *flag = GNUNET_YES;
655}

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 665 of file gnunet-daemon-topology.c.

666{
667 int num_addresses_old = 0;
668 int num_addresses_new = 0;
670 const struct GNUNET_PeerIdentity *pid;
671 struct Peer *peer;
672 uint16_t size;
673
677 &num_addresses_new);
679 "consider 0 for %s\n",
680 GNUNET_i2s (pid));
681 if (0 == num_addresses_new)
682 {
684 return; /* no point in advertising this one... */
685 }
687 if (NULL == peer)
688 {
689 peer = make_peer (pid, hello);
690 }
691 else if (NULL != peer->hello)
692 {
694 struct GNUNET_TIME_Absolute new_hello_exp =
696 struct GNUNET_TIME_Absolute old_hello_exp =
698 struct GNUNET_HELLO_Parser *parser_old =
700
701 GNUNET_HELLO_parser_iterate (parser_old,
703 &num_addresses_old);
704 GNUNET_HELLO_parser_free (parser_old);
705 if (GNUNET_TIME_absolute_cmp (new_hello_exp, >, now) &&
706 (GNUNET_TIME_absolute_cmp (new_hello_exp, >, old_hello_exp) ||
707 num_addresses_old < num_addresses_new))
708 {
709 GNUNET_free (peer->hello);
710 size = ntohs (hello->size);
711 peer->hello = GNUNET_malloc (size);
712 GNUNET_memcpy (peer->hello, hello, size);
713 }
714 else
715 {
717 "consider 3\n");
719 return;
720 }
721 }
722 else
723 {
724 size = ntohs (hello->size);
725 peer->hello = GNUNET_malloc (size);
726 GNUNET_memcpy (peer->hello, hello, size);
727 }
729 "Found HELLO from peer `%s' for advertising\n",
730 GNUNET_i2s (pid));
731 if (NULL != peer->filter)
732 {
734 peer->filter = NULL;
735 }
736 setup_filter (peer);
737 /* since we have a new HELLO to pick from, re-schedule all
738 * HELLO requests that are not bound by the HELLO send rate! */
741}
static void address_iterator(void *cls, const struct GNUNET_PeerIdentity *pid, const char *uri)
Iterator called on each address.
void GNUNET_HELLO_parser_free(struct GNUNET_HELLO_Parser *parser)
Release resources of a builder.
Definition: hello-uri.c:435
struct GNUNET_HELLO_Parser * GNUNET_HELLO_parser_from_msg(const struct GNUNET_MessageHeader *msg)
Parse msg.
Definition: hello-uri.c:471
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:1201
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:619
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
#define GNUNET_TIME_absolute_cmp(t1, op, t2)
Compare two absolute times.
static unsigned int size
Size of the "table".
Definition: peer.c:68
Context for parsing HELLOs.
Definition: hello-uri.c:258
Time for absolute times used by GNUnet, in microseconds.

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(), consensus-simulation::parser, 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 745 of file gnunet-daemon-topology.c.

746{
748 _ (
749 "Error in communication with PEERSTORE service to monitor.\n"));
750 return;
751}
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

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 755 of file gnunet-daemon-topology.c.

756{
758 _ ("Finished initial PEERSTORE iteration in monitor.\n"));
759 return;
760}

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 773 of file gnunet-daemon-topology.c.

776{
777 struct Peer *pos;
778 struct GNUNET_MessageHeader *hello;
779
780 if (NULL != err_msg)
781 {
783 _ ("Error in communication with PEERSTORE service: %s\n"),
784 err_msg);
789 "peerstore",
790 NULL,
792 error_cb,
793 NULL,
794 sync_cb,
795 NULL,
797 NULL);
798 return;
799 }
800 GNUNET_assert (NULL != record);
801 hello = record->value;
802 if (NULL == hello)
803 {
804 /* free existing HELLO, if any */
806 if (NULL != pos)
807 {
808 GNUNET_free (pos->hello);
809 pos->hello = NULL;
810 if (NULL != pos->filter)
811 {
813 pos->filter = NULL;
814 }
815 if (NULL == pos->mq)
816 free_peer (NULL, &pos->pid, pos);
817 }
819 return;
820 }
823 if (NULL == pos)
824 pos = make_peer (&record->peer, hello);
825 attempt_connect (pos);
827}
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static void sync_cb(void *cls)
static void consider_for_advertising(const struct GNUNET_MessageHeader *hello)
We've gotten a HELLO from another peer.
static struct GNUNET_PEERSTORE_Monitor * peerstore_notify
Our peerstore notification context.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
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 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)
void GNUNET_PEERSTORE_monitor_stop(struct GNUNET_PEERSTORE_Monitor *zm)
Stop monitoring.
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...
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).
#define GNUNET_PEERSTORE_HELLO_KEY
Key used for storing HELLO in the peerstore.
Header for all communications.

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_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 831 of file gnunet-daemon-topology.c.

832{
833 (void) cls;
834
836 "Starting to process new hellos for gossiping.\n");
840 "peerstore",
841 NULL,
843 &error_cb,
844 NULL,
845 &sync_cb,
846 NULL,
848 NULL);
849}

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:

◆ 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 860 of file gnunet-daemon-topology.c.

861{
862 if (NULL == my_id)
863 {
864 GNUNET_log (
866 _ ("Failed to connect to core service, can not manage topology!\n"));
868 return;
869 }
870 my_identity = *my_id;
871 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id));
875 NULL);
876}
static void start_notify(void *cls)
struct GNUNET_SCHEDULER_Task * peerstore_notify_task
The task to delayed start the notification process initially.
@ GNUNET_ERROR_TYPE_ERROR
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
#define GNUNET_TIME_UNIT_MINUTES
One minute.

References _, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_shutdown(), GNUNET_TIME_UNIT_MINUTES, 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 889 of file gnunet-daemon-topology.c.

890{
893
894 if (NULL == pid)
895 {
896 GNUNET_break_op (0);
897 return GNUNET_SYSERR;
898 }
899 return GNUNET_OK;
900}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
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:412
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.

References GNUNET_break_op, GNUNET_HELLO_parser_from_msg(), GNUNET_HELLO_parser_get_id(), GNUNET_OK, GNUNET_SYSERR, msg, consensus-simulation::parser, and pid.

Here is the call graph for this function:

◆ shc_cont()

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

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

905{
906 struct StoreHelloEntry *she = cls;
907
908 she->sc = NULL;
909 if (GNUNET_YES == success)
911 "Hello stored successfully!\n");
912 else
914 "Error storing hello!\n");
916 GNUNET_free (she);
917}
static struct StoreHelloEntry * she_head
Head of the linkd list to store the store context for hellos.
static struct StoreHelloEntry * she_tail
Tail of the linkd list to store the store context for hellos.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
Context for a add hello uri request.
struct GNUNET_PEERSTORE_StoreHelloContext * sc
Store hello ctx.

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 928 of file gnunet-daemon-topology.c.

929{
930 struct StoreHelloEntry *she;
931 const struct GNUNET_PeerIdentity *other = cls;
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);
944 if (NULL != she->sc)
945 {
947 }
948 else
949 GNUNET_free (she);
951}
static struct GNUNET_PEERSTORE_Handle * ps
Handle to the PEERSTORE service.
static void shc_cont(void *cls, int success)
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
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.

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, consensus-simulation::parser, 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 961 of file gnunet-daemon-topology.c.

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}
static struct GNUNET_CORE_Handle * handle
Handle to the CORE service.
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
void GNUNET_TRANSPORT_application_done(struct GNUNET_TRANSPORT_ApplicationHandle *ch)
Shutdown TRANSPORT application client.
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:729
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
void GNUNET_PEERSTORE_hello_add_cancel(struct GNUNET_PEERSTORE_StoreHelloContext *huc)
Cancel the request to add a hello.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).

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_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_TRANSPORT_application_done(), handle, my_private_key, peers, peerstore_notify, peerstore_notify_task, 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 1023 of file gnunet-daemon-topology.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}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static void cleaning_task(void *cls)
Last task run during shutdown.
static void disconnect_notify(void *cls, const struct GNUNET_PeerIdentity *peer, void *internal_cls)
Method called whenever a peer disconnects.
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.
struct GNUNET_TRANSPORT_ApplicationHandle * GNUNET_TRANSPORT_application_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the TRANSPORT application client handle.
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
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.
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).
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
#define GNUNET_MESSAGE_TYPE_HELLO_URI
Latest HELLO messages used for communicating peer addresses.
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
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
Message handler for a specific message type.

References _, cfg, cleaning_task(), connect_notify(), core_init(), disconnect_notify(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_CORE_connect(), GNUNET_CRYPTO_eddsa_key_create_from_configuration(), 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_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_TRANSPORT_application_init(), handle, handlers, consensus-simulation::int, my_private_key, peers, ps, 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 1078 of file gnunet-daemon-topology.c.

1079{
1080 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1082 };
1083 int ret;
1084
1085 ret = (GNUNET_OK ==
1087 argc,
1088 argv,
1089 "gnunet-daemon-topology",
1090 _ ("GNUnet topology control"),
1091 options,
1092 &run,
1093 NULL))
1094 ? 0
1095 : 1;
1096 return ret;
1097}
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
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
Definition of a command line option.

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 135 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 142 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 147 of file gnunet-daemon-topology.c.

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

◆ handle

struct GNUNET_CORE_Handle* handle
static

Handle to the CORE service.

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

Referenced by cleaning_task(), and run().

◆ ps

◆ transport

Handle to Transport service.

Definition at line 162 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 167 of file gnunet-daemon-topology.c.

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

◆ my_private_key

struct GNUNET_CRYPTO_EddsaPrivateKey* my_private_key
static

Our private key.

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

Referenced by cleaning_task(), and run().

◆ 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 179 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 184 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 190 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 195 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 200 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 205 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 210 of file gnunet-daemon-topology.c.

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