GNUnet  0.10.x
Data Structures | Macros | Functions | Variables
gnunet-daemon-topology.c File Reference

code for maintaining the overlay topology More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_friends_lib.h"
#include "gnunet_constants.h"
#include "gnunet_core_service.h"
#include "gnunet_protocols.h"
#include "gnunet_peerinfo_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_transport_service.h"
#include "gnunet_ats_service.h"
Include dependency graph for gnunet-daemon-topology.c:

Go to the source code of this file.

Data Structures

struct  Peer
 Information about preferences and sessions we track per peer. 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 blacklist_check (void *cls, const struct GNUNET_PeerIdentity *pid)
 Function that decides if a connection is acceptable or not. More...
 
static void whitelist_peers ()
 Whitelist all peers that we blacklisted; we've passed the minimum number of friends. More...
 
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_HELLO_Message *hello, int is_friend)
 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 int address_iterator (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Iterator called on each address. More...
 
static void consider_for_advertising (const struct GNUNET_HELLO_Message *hello)
 We've gotten a HELLO from another peer. More...
 
static void process_peer (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
 PEERINFO calls this function to let us know about a possible peer that we might want to connect to. More...
 
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 void handle_friend (void *cls, const struct GNUNET_PeerIdentity *pid)
 Process friend found in FRIENDS file. More...
 
static void read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Read the friends file. More...
 
static int check_hello (void *cls, const struct GNUNET_HELLO_Message *message)
 This function is called whenever an encrypted HELLO message is received. More...
 
static void handle_hello (void *cls, const struct GNUNET_HELLO_Message *message)
 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

static struct GNUNET_PEERINFO_NotifyContextpeerinfo_notify
 Our peerinfo 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_PEERINFO_Handlepi
 Handle to the PEERINFO service. More...
 
static struct GNUNET_ATS_ConnectivityHandleats
 Handle to the ATS service. More...
 
static struct GNUNET_PeerIdentity my_identity
 Identity of this peer. More...
 
static struct GNUNET_CONTAINER_MultiPeerMappeers
 All of our friends, 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_TRANSPORT_Blacklistblacklist
 Blacklist (NULL if we have none). More...
 
static struct GNUNET_SCHEDULER_Taskadd_task
 Task scheduled to asynchronously reconsider adding/removing peer connectivity suggestions. More...
 
static struct GNUNET_TRANSPORT_OfferHelloHandleoh
 Active HELLO offering to transport service. More...
 
static int friends_only
 Flag to disallow non-friend connections (pure F2F mode). More...
 
static unsigned int minimum_friend_count
 Minimum number of friends to have in the connection set before we allow non-friends. More...
 
static unsigned int connection_count
 Number of peers (friends and others) that we are currently connected to. More...
 
static unsigned int target_connection_count
 Target number of connections. More...
 
static unsigned int friend_count
 Number of friends that we are currently connected to. More...
 

Detailed Description

code for maintaining the overlay topology

Author
Christian Grothoff

This daemon combines three functions:

All three require similar information (who are our friends impacts connectivity suggestions; connectivity suggestions should consider blacklisting; connectivity suggestions should consider available/known HELLOs; gossip requires connectivity data; connectivity suggestions require connectivity data), which is why they are combined in this program.

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

Referenced by schedule_next_hello().

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

Referenced by setup_filter().

Function Documentation

◆ blacklist_check()

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

Function that decides if a connection is acceptable or not.

If we have a blacklist, only friends are allowed, so the check is rather simple.

Parameters
clsclosure
pidpeer to approve or disapprove
Returns
GNUNET_OK if the connection is allowed

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

References gettext_noop, GNUNET_CONTAINER_multipeermap_get(), GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_YES, and Peer::is_friend.

Referenced by disconnect_notify(), and run().

220 {
221  struct Peer *pos;
222 
224  if ((NULL != pos) && (GNUNET_YES == pos->is_friend))
225  return GNUNET_OK;
227  gettext_noop("# peers blacklisted"),
228  1,
229  GNUNET_NO);
230  return GNUNET_SYSERR;
231 }
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
int is_friend
Is this peer listed here because it is a friend?
Information about preferences and sessions we track per peer.
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.
#define GNUNET_YES
Definition: gnunet_common.h:77
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our friends, all of our current neighbours and all peers for which we have HELLOs...
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ whitelist_peers()

static void whitelist_peers ( )
static

Whitelist all peers that we blacklisted; we've passed the minimum number of friends.

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

References GNUNET_TRANSPORT_blacklist_cancel().

Referenced by cleaning_task(), and connect_notify().

240 {
241  if (NULL != blacklist)
242  {
244  blacklist = NULL;
245  }
246 }
static struct GNUNET_TRANSPORT_Blacklist * blacklist
Blacklist (NULL if we have none).
void GNUNET_TRANSPORT_blacklist_cancel(struct GNUNET_TRANSPORT_Blacklist *br)
Abort the blacklist.
Here is the call graph for this function:
Here is the caller graph for this function:

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

References Peer::filter, GNUNET_ATS_connectivity_suggest_cancel(), GNUNET_break, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_free, GNUNET_free_non_null, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_YES, Peer::hello, Peer::hello_delay_task, Peer::mq, Peer::sh, and value.

Referenced by cleaning_task(), and process_peer().

259 {
260  struct Peer *pos = value;
261 
262  GNUNET_break(NULL == pos->mq);
265  if (NULL != pos->hello_delay_task)
266  {
268  pos->hello_delay_task = NULL;
269  }
270  if (NULL != pos->sh)
271  {
273  pos->sh = NULL;
274  }
275  if (NULL != pos->hello)
276  {
278  pos->hello = NULL;
279  }
280  if (NULL != pos->filter)
281  {
283  pos->filter = NULL;
284  }
285  GNUNET_free(pos);
286  return GNUNET_YES;
287 }
int 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.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
void GNUNET_ATS_connectivity_suggest_cancel(struct GNUNET_ATS_ConnectivitySuggestHandle *sh)
We no longer care about being connected to a peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_ATS_ConnectivitySuggestHandle * sh
Handle for our connectivity suggestion for this peer.
static char * value
Value of the record to add/remove.
struct GNUNET_MQ_Handle * mq
Our handle for transmitting to this peer; NULL if peer is not connected.
Information about preferences and sessions we track per peer.
struct GNUNET_HELLO_Message * hello
Pointer to the HELLO message 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.
#define GNUNET_YES
Definition: gnunet_common.h:77
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.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our friends, all of our current neighbours and all peers for which we have HELLOs...
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associcated with a filter in memory, flush to drive if needed (do not free the space o...
#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:956
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 297 of file gnunet-daemon-topology.c.

References connection_count, friend_count, friends_only, gettext_noop, GNUNET_ATS_connectivity_suggest(), GNUNET_ATS_connectivity_suggest_cancel(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, Peer::is_friend, minimum_friend_count, Peer::mq, my_identity, Peer::pid, Peer::sh, Peer::strength, and target_connection_count.

Referenced by process_peer(), and try_add_peers().

298 {
299  uint32_t strength;
300 
301  if (0 == GNUNET_memcmp(&my_identity, &pos->pid))
302  return; /* This is myself, nothing to do. */
304  strength = 1;
305  else
306  strength = 0;
308  {
309  if (pos->is_friend)
310  strength += 10; /* urgently needed */
311  else
312  strength = 0; /* disallowed */
313  }
314  if (pos->is_friend)
315  strength *= 2; /* friends always count more */
316  if (NULL != pos->mq)
317  strength *= 2; /* existing connections preferred */
318  if (strength == pos->strength)
319  return; /* nothing to do */
320  if (NULL != pos->sh)
321  {
323  pos->sh = NULL;
324  }
325  pos->strength = strength;
326  if (0 != strength)
327  {
329  "Asking to connect to `%s' with strength %u\n",
330  GNUNET_i2s(&pos->pid),
331  (unsigned int)strength);
333  gettext_noop("# connect requests issued to ATS"),
334  1,
335  GNUNET_NO);
336  pos->sh = GNUNET_ATS_connectivity_suggest(ats, &pos->pid, strength);
337  }
338 }
static int friends_only
Flag to disallow non-friend connections (pure F2F mode).
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
uint32_t strength
How much would we like to connect to this peer?
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_ATS_connectivity_suggest_cancel(struct GNUNET_ATS_ConnectivitySuggestHandle *sh)
We no longer care about being connected to a 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.
struct GNUNET_ATS_ConnectivitySuggestHandle * sh
Handle for our connectivity suggestion for this peer.
struct GNUNET_ATS_ConnectivitySuggestHandle * GNUNET_ATS_connectivity_suggest(struct GNUNET_ATS_ConnectivityHandle *ch, const struct GNUNET_PeerIdentity *peer, uint32_t strength)
We would like to receive address suggestions for a peer.
static unsigned int target_connection_count
Target number of connections.
static struct GNUNET_ATS_ConnectivityHandle * ats
Handle to the ATS service.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
int is_friend
Is this peer listed here because it is a friend?
struct GNUNET_PeerIdentity pid
Which peer is this for?
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
static unsigned int connection_count
Number of peers (friends and others) that we are currently connected to.
struct GNUNET_MQ_Handle * mq
Our handle for transmitting to this peer; NULL if peer is not connected.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static unsigned int minimum_friend_count
Minimum number of friends to have in the connection set before we allow non-friends.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define gettext_noop(String)
Definition: gettext.h:69
static unsigned int friend_count
Number of friends that we are currently connected to.
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_HELLO_Message hello,
int  is_friend 
)
static

Create a new entry in the peer list.

Parameters
peeridentity of the new entry
hellohello message, can be NULL
is_friendis the new entry for a friend?
Returns
the new entry

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

References GNUNET_break, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_put(), GNUNET_HELLO_size(), GNUNET_malloc, GNUNET_memcpy, GNUNET_new, GNUNET_OK, Peer::hello, Peer::is_friend, Peer::peer, Peer::pid, and ret.

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

353 {
354  struct Peer *ret;
355 
356  ret = GNUNET_new(struct Peer);
357  ret->pid = *peer;
358  ret->is_friend = is_friend;
359  if (NULL != hello)
360  {
361  ret->hello = GNUNET_malloc(GNUNET_HELLO_size(hello));
362  GNUNET_memcpy(ret->hello, hello, GNUNET_HELLO_size(hello));
363  }
366  peers,
367  peer,
368  ret,
370  return ret;
371 }
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
There must only be one value per key; storing a value should fail if a value under the same key alrea...
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
int is_friend
Is this peer listed here because it is a friend?
struct GNUNET_PeerIdentity pid
Which peer is this for?
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.
Information about preferences and sessions we track per peer.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:643
struct GNUNET_HELLO_Message * hello
Pointer to the HELLO message of this peer; can be NULL.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our friends, all of our current neighbours and all peers for which we have HELLOs...
#define GNUNET_malloc(size)
Wrapper around malloc.
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 380 of file gnunet-daemon-topology.c.

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().

381 {
382  struct GNUNET_HashCode hc;
383 
384  /* 2^{-5} chance of not sending a HELLO to a peer is
385  * acceptably small (if the filter is 50% full);
386  * 64 bytes of memory are small compared to the rest
387  * of the data structure and would only really become
388  * "useless" once a HELLO has been passed on to ~100
389  * other peers, which is likely more than enough in
390  * any case; hence 64, 5 as bloomfilter parameters. */
391  peer->filter = GNUNET_CONTAINER_bloomfilter_init(NULL, 64, 5);
392  peer->filter_expiration =
394  /* never send a peer its own HELLO */
395  GNUNET_CRYPTO_hash(&peer->pid, sizeof(struct GNUNET_PeerIdentity), &hc);
397 }
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.
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:246
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
A 512-bit hashcode.
struct GNUNET_PeerIdentity pid
Which peer is this for?
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CONTAINER_BloomFilter * filter
Bloom filter used to mark which peers already got the HELLO from this peer.
#define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY
After what time period do we expire the HELLO Bloom filter?
struct GNUNET_TIME_Absolute filter_expiration
When should we reset the bloom filter of this entry?
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 432 of file gnunet-daemon-topology.c.

References Peer::filter, Peer::filter_expiration, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_bloomfilter_test(), GNUNET_CRYPTO_hash(), GNUNET_HELLO_size(), 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(), and value.

Referenced by schedule_next_hello().

435 {
436  struct FindAdvHelloContext *fah = cls;
437  struct Peer *pos = value;
438  struct GNUNET_TIME_Relative rst_time;
439  struct GNUNET_HashCode hc;
440  size_t hs;
441 
442  if (pos == fah->peer)
443  return GNUNET_YES;
444  if (pos->hello == NULL)
445  return GNUNET_YES;
447  if (0 == rst_time.rel_value_us)
448  {
449  /* time to discard... */
451  setup_filter(pos);
452  }
453  fah->next_adv = GNUNET_TIME_relative_min(rst_time, fah->next_adv);
454  hs = GNUNET_HELLO_size(pos->hello);
455  if (hs > fah->max_size)
456  return GNUNET_YES;
457  GNUNET_CRYPTO_hash(&fah->peer->pid,
458  sizeof(struct GNUNET_PeerIdentity),
459  &hc);
461  fah->result = pos;
462  return GNUNET_YES;
463 }
#define GNUNET_NO
Definition: gnunet_common.h:78
static void setup_filter(struct Peer *peer)
Setup bloom filter for the given peer entry.
static char * value
Value of the record to add/remove.
int 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_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
struct Peer * peer
Peer we want to advertise to.
A 512-bit hashcode.
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:272
struct GNUNET_TIME_Relative next_adv
struct GNUNET_PeerIdentity pid
Which peer is this for?
The identity of the host (wraps the signing key of the peer).
Information about preferences and sessions we track per peer.
size_t max_size
Maximum HELLO size we can use right now.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:643
struct GNUNET_HELLO_Message * hello
Pointer to the HELLO message of this peer; can be NULL.
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:331
struct GNUNET_CONTAINER_BloomFilter * filter
Bloom filter used to mark which peers already got the HELLO from this peer.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_TIME_Absolute filter_expiration
When should we reset the bloom filter of this entry?
Closure for find_advertisable_hello().
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associcated with a filter in memory, flush to drive if needed (do not free the space o...
struct Peer * result
Where to store the result (peer selected for advertising).
Time for relative time used by GNUnet, in microseconds.
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 473 of file gnunet-daemon-topology.c.

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_HELLO_size(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_MQ_msg_copy(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_HELLO_Message::header, Peer::hello, HELLO_ADVERTISEMENT_MIN_FREQUENCY, Peer::hello_delay_task, FindAdvHelloContext::max_size, Peer::mq, FindAdvHelloContext::next_adv, Peer::next_hello_allowed, FindAdvHelloContext::peer, Peer::pid, GNUNET_TIME_Relative::rel_value_us, and FindAdvHelloContext::result.

Referenced by reschedule_hellos().

474 {
475  struct Peer *pl = cls;
476  struct FindAdvHelloContext fah;
477  struct GNUNET_MQ_Envelope *env;
478  size_t want;
480  struct GNUNET_HashCode hc;
481 
482  pl->hello_delay_task = NULL;
483  GNUNET_assert(NULL != pl->mq);
484  /* find applicable HELLOs */
485  fah.peer = pl;
486  fah.result = NULL;
487  fah.max_size = GNUNET_MAX_MESSAGE_SIZE - 1;
488  fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL;
490  pl->hello_delay_task =
492  if (NULL == fah.result)
493  return;
495  if (0 != delay.rel_value_us)
496  return;
497 
498  want = GNUNET_HELLO_size(fah.result->hello);
500  "Sending HELLO with %u bytes",
501  (unsigned int)want);
502  env = GNUNET_MQ_msg_copy(&fah.result->hello->header);
503  GNUNET_MQ_send(pl->mq, env);
504 
505  /* avoid sending this one again soon */
506  GNUNET_CRYPTO_hash(&pl->pid, sizeof(struct GNUNET_PeerIdentity), &hc);
507  GNUNET_CONTAINER_bloomfilter_add(fah.result->filter, &hc);
508 
510  gettext_noop("# HELLO messages gossipped"),
511  1,
512  GNUNET_NO);
513  /* prepare to send the next one */
514  pl->next_hello_allowed =
516  if (NULL != pl->hello_delay_task)
519 }
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:651
void GNUNET_CONTAINER_bloomfilter_add(struct GNUNET_CONTAINER_BloomFilter *bf, const struct GNUNET_HashCode *e)
Add an element to the filter.
uint64_t rel_value_us
The actual value.
#define HELLO_ADVERTISEMENT_MIN_FREQUENCY
At what frequency do we sent HELLOs to a peer?
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:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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 GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
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:1237
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:44
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:1264
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
A 512-bit hashcode.
struct GNUNET_TIME_Absolute next_hello_allowed
Next time we are allowed to transmit a HELLO to this peer?
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_PeerIdentity pid
Which peer is this for?
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
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.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_MQ_Handle * mq
Our handle for transmitting to this peer; NULL if peer is not connected.
Information about preferences and sessions we track per peer.
#define GNUNET_log(kind,...)
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:643
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:331
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.
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:351
Closure for find_advertisable_hello().
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our friends, all of our current neighbours and all peers for which we have HELLOs...
Time for relative time used by GNUnet, in microseconds.
#define gettext_noop(String)
Definition: gettext.h:69
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 533 of file gnunet-daemon-topology.c.

References GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_YES, Peer::hello_delay_task, Peer::mq, Peer::peer, schedule_next_hello(), and value.

Referenced by connect_notify(), and consider_for_advertising().

536 {
537  struct Peer *peer = value;
538  struct Peer *skip = cls;
539 
540  if (skip == peer)
541  return GNUNET_YES;
542  if (NULL == peer->mq)
543  return GNUNET_YES;
544  if (NULL != peer->hello_delay_task)
545  {
547  peer->hello_delay_task = NULL;
548  }
549  peer->hello_delay_task =
551  return GNUNET_YES;
552 }
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 char * value
Value of the record to add/remove.
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:1264
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_MQ_Handle * mq
Our handle for transmitting to this peer; NULL if peer is not connected.
Information about preferences and sessions we track per peer.
#define GNUNET_YES
Definition: gnunet_common.h:77
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.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 564 of file gnunet-daemon-topology.c.

References connection_count, friend_count, friends_only, 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(), GNUNET_YES, Peer::is_friend, make_peer(), minimum_friend_count, Peer::mq, my_identity, reschedule_hellos(), and whitelist_peers().

Referenced by reconnect(), and run().

567 {
568  struct Peer *pos;
569 
571  "Core told us that we are connecting to `%s'\n",
572  GNUNET_i2s(peer));
573  if (0 == GNUNET_memcmp(&my_identity, peer))
574  return NULL;
578  gettext_noop("# peers connected"),
580  GNUNET_NO);
582  if (NULL == pos)
583  {
584  pos = make_peer(peer, NULL, GNUNET_NO);
585  }
586  else
587  {
588  GNUNET_assert(NULL == pos->mq);
589  }
590  pos->mq = mq;
591  if (pos->is_friend)
592  {
593  friend_count++;
595  whitelist_peers();
597  gettext_noop("# friends connected"),
598  friend_count,
599  GNUNET_NO);
600  }
601  reschedule_hellos(NULL, peer, pos);
602  return pos;
603 }
static int friends_only
Flag to disallow non-friend connections (pure F2F mode).
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
static void whitelist_peers()
Whitelist all peers that we blacklisted; we've passed the minimum number of friends.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
static struct Peer * make_peer(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, int is_friend)
Create a new entry in the peer list.
Best-effort traffic (i.e.
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 GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
int is_friend
Is this peer listed here because it is a friend?
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
static unsigned int connection_count
Number of peers (friends and others) that we are currently connected to.
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:1063
struct GNUNET_MQ_Handle * mq
Our handle for transmitting to this peer; NULL if peer is not connected.
Information about preferences and sessions we track per peer.
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.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our friends, all of our current neighbours and all peers for which we have HELLOs...
static unsigned int minimum_friend_count
Minimum number of friends to have in the connection set before we allow non-friends.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define gettext_noop(String)
Definition: gettext.h:69
static unsigned int friend_count
Number of friends that we are currently connected to.
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 615 of file gnunet-daemon-topology.c.

References attempt_connect(), GNUNET_YES, and value.

Referenced by add_peer_task().

616 {
617  struct Peer *pos = value;
618 
619  attempt_connect(pos);
620  return GNUNET_YES;
621 }
static char * value
Value of the record to add/remove.
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...
Information about preferences and sessions we track per peer.
#define GNUNET_YES
Definition: gnunet_common.h:77
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 630 of file gnunet-daemon-topology.c.

References GNUNET_CONTAINER_multipeermap_iterate(), and try_add_peers().

Referenced by disconnect_notify().

631 {
632  add_task = NULL;
633 
635 }
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.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our friends, all of our current neighbours and all peers for which we have HELLOs...
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 646 of file gnunet-daemon-topology.c.

References add_peer_task(), blacklist_check(), connection_count, friend_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(), GNUNET_TRANSPORT_blacklist(), Peer::hello_delay_task, Peer::is_friend, minimum_friend_count, Peer::mq, and target_connection_count.

Referenced by reconnect(), and run().

649 {
650  struct Peer *pos = internal_cls;
651 
652  if (NULL == pos)
653  return; /* myself, we're shutting down */
655  "Core told us that we disconnected from `%s'\n",
656  GNUNET_i2s(peer));
657  if (NULL == pos->mq)
658  {
659  GNUNET_break(0);
660  return;
661  }
662  pos->mq = NULL;
664  if (NULL != pos->hello_delay_task)
665  {
667  pos->hello_delay_task = NULL;
668  }
670  gettext_noop("# peers connected"),
672  GNUNET_NO);
673  if (pos->is_friend)
674  {
675  friend_count--;
677  gettext_noop("# friends connected"),
678  friend_count,
679  GNUNET_NO);
680  }
683  (NULL == add_task))
685  if ((friend_count < minimum_friend_count) && (NULL == blacklist))
687 }
static struct GNUNET_SCHEDULER_Task * add_task
Task scheduled to asynchronously reconsider adding/removing peer connectivity suggestions.
static int blacklist_check(void *cls, const struct GNUNET_PeerIdentity *pid)
Function that decides if a connection is acceptable or not.
static struct GNUNET_TRANSPORT_Blacklist * blacklist
Blacklist (NULL if we have none).
#define GNUNET_NO
Definition: gnunet_common.h:78
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static unsigned int target_connection_count
Target number of connections.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
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:1264
struct GNUNET_TRANSPORT_Blacklist * GNUNET_TRANSPORT_blacklist(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_TRANSPORT_BlacklistCallback cb, void *cb_cls)
Install a blacklist callback.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
static void add_peer_task(void *cls)
Add peers and schedule connection attempt.
int is_friend
Is this peer listed here because it is a friend?
static unsigned int connection_count
Number of peers (friends and others) that we are currently connected to.
struct GNUNET_MQ_Handle * mq
Our handle for transmitting to this peer; NULL if peer is not connected.
Information about preferences and sessions we track per peer.
#define GNUNET_log(kind,...)
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.
static unsigned int minimum_friend_count
Minimum number of friends to have in the connection set before we allow non-friends.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define gettext_noop(String)
Definition: gettext.h:69
static unsigned int friend_count
Number of friends that we are currently connected to.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
Here is the call graph for this function:
Here is the caller graph for this function:

◆ address_iterator()

static int address_iterator ( void *  cls,
const struct GNUNET_HELLO_Address address,
struct GNUNET_TIME_Absolute  expiration 
)
static

Iterator called on each address.

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

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

References GNUNET_SYSERR, and GNUNET_YES.

Referenced by consider_for_advertising().

702 {
703  int *flag = cls;
704 
705  *flag = GNUNET_YES;
706  return GNUNET_SYSERR;
707 }
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the caller graph for this function:

◆ consider_for_advertising()

static void consider_for_advertising ( const struct GNUNET_HELLO_Message hello)
static

We've gotten a HELLO from another peer.

Consider it for advertising.

Parameters
hellothe HELLO we got

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

References GNUNET_TIME_Absolute::abs_value_us, address_iterator(), Peer::filter, GNUNET_break, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELLO_equals(), GNUNET_HELLO_get_id(), GNUNET_HELLO_iterate_addresses(), GNUNET_HELLO_merge(), GNUNET_HELLO_size(), GNUNET_i2s(), GNUNET_log, GNUNET_malloc, GNUNET_memcmp, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_FOREVER_ABS, Peer::hello, make_peer(), my_identity, nh, Peer::peer, reschedule_hellos(), setup_filter(), and size.

Referenced by process_peer().

718 {
719  int have_address;
720  struct GNUNET_PeerIdentity pid;
721  struct GNUNET_TIME_Absolute dt;
722  struct GNUNET_HELLO_Message *nh;
723  struct Peer *peer;
724  uint16_t size;
725 
726  if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid))
727  {
728  GNUNET_break(0);
729  return;
730  }
731  if (0 == GNUNET_memcmp(&pid, &my_identity))
732  return; /* that's me! */
733  have_address = GNUNET_NO;
735  GNUNET_NO,
737  &have_address);
738  if (GNUNET_NO == have_address)
739  return; /* no point in advertising this one... */
741  if (NULL == peer)
742  {
743  peer = make_peer(&pid, hello, GNUNET_NO);
744  }
745  else if (NULL != peer->hello)
746  {
747  dt = GNUNET_HELLO_equals(peer->hello, hello, GNUNET_TIME_absolute_get());
748  if (dt.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us)
749  return; /* nothing new here */
750  }
752  "Found HELLO from peer `%s' for advertising\n",
753  GNUNET_i2s(&pid));
754  if (NULL != peer->hello)
755  {
756  nh = GNUNET_HELLO_merge(peer->hello, hello);
757  GNUNET_free(peer->hello);
758  peer->hello = nh;
759  }
760  else
761  {
762  size = GNUNET_HELLO_size(hello);
763  peer->hello = GNUNET_malloc(size);
764  GNUNET_memcpy(peer->hello, hello, size);
765  }
766  if (NULL != peer->filter)
767  {
769  peer->filter = NULL;
770  }
771  setup_filter(peer);
772  /* since we have a new HELLO to pick from, re-schedule all
773  * HELLO requests that are not bound by the HELLO send rate! */
775 }
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
Definition: hello.c:662
A HELLO message is used to exchange information about transports with other peers.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
struct GNUNET_HELLO_Message * GNUNET_HELLO_merge(const struct GNUNET_HELLO_Message *h1, const struct GNUNET_HELLO_Message *h2)
Construct a HELLO message by merging the addresses in two existing HELLOs (which must be for the same...
Definition: hello.c:519
struct GNUNET_TIME_Absolute GNUNET_HELLO_equals(const struct GNUNET_HELLO_Message *h1, const struct GNUNET_HELLO_Message *h2, struct GNUNET_TIME_Absolute now)
Test if two HELLO messages contain the same addresses.
Definition: hello.c:824
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static void setup_filter(struct Peer *peer)
Setup bloom filter for the given peer entry.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
static struct Peer * make_peer(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, int is_friend)
Create a new entry in the peer list.
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_HELLO_Message * GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, int return_modified, GNUNET_HELLO_AddressIterator it, void *it_cls)
Iterate over all of the addresses in the HELLO.
Definition: hello.c:252
static struct GNUNET_NAT_Handle * nh
Handle to NAT operation.
Definition: gnunet-nat.c:80
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static int address_iterator(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Iterator called on each address.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static unsigned int size
Size of the "table".
Definition: peer.c:66
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
The identity of the host (wraps the signing key of the peer).
Information about preferences and sessions we track per peer.
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.
#define GNUNET_log(kind,...)
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:643
struct GNUNET_HELLO_Message * hello
Pointer to the HELLO message 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.
Time for absolute times used by GNUnet, in microseconds.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our friends, all of our current neighbours and all peers for which we have HELLOs...
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associcated with a filter in memory, flush to drive if needed (do not free the space o...
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_peer()

static void process_peer ( void *  cls,
const struct GNUNET_PeerIdentity peer,
const struct GNUNET_HELLO_Message hello,
const char *  err_msg 
)
static

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

References _, attempt_connect(), consider_for_advertising(), Peer::filter, free_peer(), GNUNET_assert, GNUNET_CONTAINER_bloomfilter_free(), GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free_non_null, GNUNET_log, GNUNET_memcmp, GNUNET_NO, GNUNET_PEERINFO_notify(), GNUNET_PEERINFO_notify_cancel(), Peer::hello, Peer::is_friend, make_peer(), Peer::mq, my_identity, and Peer::pid.

Referenced by core_init().

792 {
793  struct Peer *pos;
794 
795  if (NULL != err_msg)
796  {
798  _("Error in communication with PEERINFO service: %s\n"),
799  err_msg);
803  return;
804  }
805  GNUNET_assert(NULL != peer);
806  if (0 == GNUNET_memcmp(&my_identity, peer))
807  return; /* that's me! */
808  if (NULL == hello)
809  {
810  /* free existing HELLO, if any */
812  if (NULL != pos)
813  {
815  pos->hello = NULL;
816  if (NULL != pos->filter)
817  {
819  pos->filter = NULL;
820  }
821  if ((NULL == pos->mq) && (GNUNET_NO == pos->is_friend))
822  free_peer(NULL, &pos->pid, pos);
823  }
824  return;
825  }
828  if (NULL == pos)
829  pos = make_peer(peer, hello, GNUNET_NO);
830  attempt_connect(pos);
831 }
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
void GNUNET_PEERINFO_notify_cancel(struct GNUNET_PEERINFO_NotifyContext *nc)
Stop notifying about changes.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_PEERINFO_NotifyContext * GNUNET_PEERINFO_notify(const struct GNUNET_CONFIGURATION_Handle *cfg, int include_friend_only, GNUNET_PEERINFO_Processor callback, void *callback_cls)
Call a method whenever our known information about peers changes.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct Peer * make_peer(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, int is_friend)
Create a new entry in the peer list.
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 void consider_for_advertising(const struct GNUNET_HELLO_Message *hello)
We&#39;ve gotten a HELLO from another peer.
int is_friend
Is this peer listed here because it is a friend?
struct GNUNET_PeerIdentity pid
Which peer is this for?
static void process_peer(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
PEERINFO calls this function to let us know about a possible peer that we might want to connect to...
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
struct GNUNET_MQ_Handle * mq
Our handle for transmitting to this peer; NULL if peer is not connected.
Information about preferences and sessions we track per peer.
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.
#define GNUNET_log(kind,...)
static struct GNUNET_PEERINFO_NotifyContext * peerinfo_notify
Our peerinfo notification context.
struct GNUNET_HELLO_Message * hello
Pointer to the HELLO message 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.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our friends, all of our current neighbours and all peers for which we have HELLOs...
static int free_peer(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Free all resources associated with the given peer.
void GNUNET_CONTAINER_bloomfilter_free(struct GNUNET_CONTAINER_BloomFilter *bf)
Free the space associcated with a filter in memory, flush to drive if needed (do not free the space o...
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 842 of file gnunet-daemon-topology.c.

References _, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_PEERINFO_notify(), GNUNET_SCHEDULER_shutdown(), my_identity, and process_peer().

Referenced by run().

843 {
844  if (NULL == my_id)
845  {
846  GNUNET_log(
848  _("Failed to connect to core service, can not manage topology!\n"));
850  return;
851  }
852  my_identity = *my_id;
853  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s(my_id));
856 }
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
#define GNUNET_NO
Definition: gnunet_common.h:78
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
struct GNUNET_PEERINFO_NotifyContext * GNUNET_PEERINFO_notify(const struct GNUNET_CONFIGURATION_Handle *cfg, int include_friend_only, GNUNET_PEERINFO_Processor callback, void *callback_cls)
Call a method whenever our known information about peers changes.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static void process_peer(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
PEERINFO calls this function to let us know about a possible peer that we might want to connect to...
#define GNUNET_log(kind,...)
static struct GNUNET_PEERINFO_NotifyContext * peerinfo_notify
Our peerinfo notification context.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_friend()

static void handle_friend ( void *  cls,
const struct GNUNET_PeerIdentity pid 
)
static

Process friend found in FRIENDS file.

Parameters
clspointer to an unsigned int to be incremented per friend found
pididentity of the friend

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

References _, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_i2s(), GNUNET_log, GNUNET_memcmp, GNUNET_YES, make_peer(), my_identity, and Peer::pid.

Referenced by read_friends_file().

867 {
868  unsigned int *entries_found = cls;
869  struct Peer *fl;
870 
871  if (0 == GNUNET_memcmp(pid, &my_identity))
872  {
874  _("Found myself `%s' in friend list (useless, ignored)\n"),
875  GNUNET_i2s(pid));
876  return;
877  }
878  (*entries_found)++;
879  fl = make_peer(pid, NULL, GNUNET_YES);
881  _("Found friend `%s' in configuration\n"),
882  GNUNET_i2s(&fl->pid));
883 }
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct Peer * make_peer(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, int is_friend)
Create a new entry in the peer list.
struct GNUNET_PeerIdentity pid
Which peer is this for?
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
Information about preferences and sessions we track per peer.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_friends_file()

static void read_friends_file ( const struct GNUNET_CONFIGURATION_Handle cfg)
static

Read the friends file.

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

References _, friends_only, gettext_noop, GNUNET_ERROR_TYPE_WARNING, GNUNET_FRIENDS_parse(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_YES, handle_friend(), minimum_friend_count, and target_connection_count.

Referenced by run().

891 {
892  unsigned int entries_found;
893 
894  entries_found = 0;
895  if (GNUNET_OK != GNUNET_FRIENDS_parse(cfg, &handle_friend, &entries_found))
896  {
897  if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0))
899  _("Encountered errors parsing friends list!\n"));
900  }
902  gettext_noop("# friends in configuration"),
903  entries_found,
904  GNUNET_NO);
905  if ((minimum_friend_count > entries_found) && (GNUNET_NO == friends_only))
906  {
907  GNUNET_log(
909  _(
910  "Fewer friends specified than required by minimum friend count. Will only connect to friends.\n"));
911  }
913  (GNUNET_NO == friends_only))
914  {
915  GNUNET_log(
917  _(
918  "More friendly connections required than target total number of connections.\n"));
919  }
920 }
static int friends_only
Flag to disallow non-friend connections (pure F2F mode).
int GNUNET_FRIENDS_parse(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_FRIENDS_Callback cb, void *cb_cls)
Parse the FRIENDS file.
Definition: friends.c:39
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static unsigned int target_connection_count
Target number of connections.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static void handle_friend(void *cls, const struct GNUNET_PeerIdentity *pid)
Process friend found in FRIENDS file.
static unsigned int minimum_friend_count
Minimum number of friends to have in the connection set before we allow non-friends.
#define gettext_noop(String)
Definition: gettext.h:69
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_HELLO_Message message 
)
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 933 of file gnunet-daemon-topology.c.

References GNUNET_break_op, GNUNET_HELLO_get_id(), GNUNET_OK, and GNUNET_SYSERR.

934 {
935  struct GNUNET_PeerIdentity pid;
936 
937  if (GNUNET_OK != GNUNET_HELLO_get_id(message, &pid))
938  {
939  GNUNET_break_op(0);
940  return GNUNET_SYSERR;
941  }
942  return GNUNET_OK;
943 }
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
Definition: hello.c:662
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
The identity of the host (wraps the signing key of the peer).
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
Here is the call graph for this function:

◆ handle_hello()

static void handle_hello ( void *  cls,
const struct GNUNET_HELLO_Message message 
)
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 954 of file gnunet-daemon-topology.c.

References friend_count, friends_only, gettext_noop, GNUNET_assert, GNUNET_CONTAINER_multipeermap_get(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_get_id(), GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_PEERINFO_add_peer(), GNUNET_STATISTICS_update(), GNUNET_YES, Peer::is_friend, minimum_friend_count, and Peer::peer.

955 {
956  const struct GNUNET_PeerIdentity *other = cls;
957  struct Peer *peer;
958  struct GNUNET_PeerIdentity pid;
959 
961  "Received encrypted HELLO from peer `%s'",
962  GNUNET_i2s(other));
965  gettext_noop("# HELLO messages received"),
966  1,
967  GNUNET_NO);
969  if (NULL == peer)
970  {
972  return;
973  }
974  else
975  {
976  if ((GNUNET_YES != peer->is_friend) && (GNUNET_YES == friends_only))
977  return;
978  if ((GNUNET_YES != peer->is_friend) &&
980  return;
981  }
982  (void)GNUNET_PEERINFO_add_peer(pi, message, NULL, NULL);
983 }
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
Definition: hello.c:662
static int friends_only
Flag to disallow non-friend connections (pure F2F mode).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
struct GNUNET_MQ_Envelope * GNUNET_PEERINFO_add_peer(struct GNUNET_PEERINFO_Handle *h, const struct GNUNET_HELLO_Message *hello, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Add a host to the persistent list.
Definition: peerinfo_api.c:552
static struct GNUNET_PEERINFO_Handle * pi
Handle to the PEERINFO service.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
int is_friend
Is this peer listed here because it is a friend?
The identity of the host (wraps the signing key of the peer).
Information about preferences and sessions we track per peer.
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.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our friends, all of our current neighbours and all peers for which we have HELLOs...
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static unsigned int minimum_friend_count
Minimum number of friends to have in the connection set before we allow non-friends.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define gettext_noop(String)
Definition: gettext.h:69
static unsigned int friend_count
Number of friends that we are currently connected to.
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 993 of file gnunet-daemon-topology.c.

References free_peer(), GNUNET_ATS_connectivity_done(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_CORE_disconnect(), GNUNET_NO, GNUNET_PEERINFO_disconnect(), GNUNET_PEERINFO_notify_cancel(), GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), GNUNET_TRANSPORT_offer_hello_cancel(), and whitelist_peers().

Referenced by run().

994 {
995  if (NULL != peerinfo_notify)
996  {
998  peerinfo_notify = NULL;
999  }
1000  if (NULL != handle)
1001  {
1003  handle = NULL;
1004  }
1005  whitelist_peers();
1006  if (NULL != add_task)
1007  {
1009  add_task = NULL;
1010  }
1011  if (NULL != oh)
1012  {
1014  oh = NULL;
1015  }
1018  peers = NULL;
1019  if (NULL != ats)
1020  {
1022  ats = NULL;
1023  }
1024  if (NULL != pi)
1025  {
1027  pi = NULL;
1028  }
1029  if (NULL != stats)
1030  {
1032  stats = NULL;
1033  }
1034 }
static struct GNUNET_SCHEDULER_Task * add_task
Task scheduled to asynchronously reconsider adding/removing peer connectivity suggestions.
static void whitelist_peers()
Whitelist all peers that we blacklisted; we&#39;ve passed the minimum number of friends.
void GNUNET_PEERINFO_notify_cancel(struct GNUNET_PEERINFO_NotifyContext *nc)
Stop notifying about changes.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
static struct GNUNET_ATS_ConnectivityHandle * ats
Handle to the ATS service.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
static struct GNUNET_TRANSPORT_OfferHelloHandle * oh
Active HELLO offering to transport service.
void GNUNET_TRANSPORT_offer_hello_cancel(struct GNUNET_TRANSPORT_OfferHelloHandle *ohh)
Cancel the request to transport to offer the HELLO message.
static struct GNUNET_PEERINFO_Handle * pi
Handle to the PEERINFO service.
void GNUNET_CORE_disconnect(struct GNUNET_CORE_Handle *handle)
Disconnect from the core service.
Definition: core_api.c:728
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static struct GNUNET_PEERINFO_NotifyContext * peerinfo_notify
Our peerinfo notification context.
void GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h)
Disconnect from the peerinfo service.
Definition: peerinfo_api.c:154
static struct GNUNET_CORE_Handle * handle
Handle to the CORE service.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our friends, all of our current neighbours and all peers for which we have HELLOs...
void GNUNET_ATS_connectivity_done(struct GNUNET_ATS_ConnectivityHandle *ch)
Client is done with ATS connectivity management, release resources.
static int free_peer(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Free all resources associated with the given peer.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 1046 of file gnunet-daemon-topology.c.

References _, blacklist_check(), cleaning_task(), connect_notify(), core_init(), disconnect_notify(), friends_only, GNUNET_ATS_connectivity_init(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONTAINER_multipeermap_create(), GNUNET_CORE_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MESSAGE_TYPE_HELLO, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NO, GNUNET_OK, GNUNET_PEERINFO_connect(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_TRANSPORT_blacklist(), GNUNET_YES, Peer::hello, minimum_friend_count, read_friends_file(), and target_connection_count.

Referenced by main().

1050 {
1052  { GNUNET_MQ_hd_var_size(hello,
1054  struct GNUNET_HELLO_Message,
1055  NULL),
1057  unsigned long long opt;
1058 
1059  cfg = c;
1060  stats = GNUNET_STATISTICS_create("topology", cfg);
1061  friends_only =
1062  GNUNET_CONFIGURATION_get_value_yesno(cfg, "TOPOLOGY", "FRIENDS-ONLY");
1064  "TOPOLOGY",
1065  "MINIMUM-FRIENDS",
1066  &opt))
1067  opt = 0;
1068  minimum_friend_count = (unsigned int)opt;
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);
1080  "Topology would like %u connections with at least %u friends\n",
1083  if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0))
1088  NULL,
1089  &core_init,
1090  &connect_notify,
1092  handlers);
1094  if (NULL == handle)
1095  {
1097  _("Failed to connect to `%s' service.\n"),
1098  "core");
1100  return;
1101  }
1102 }
static int friends_only
Flag to disallow non-friend connections (pure F2F mode).
A HELLO message is used to exchange information about transports with other peers.
int 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_PEERINFO_Handle * GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the peerinfo service.
Definition: peerinfo_api.c:128
static int blacklist_check(void *cls, const struct GNUNET_PeerIdentity *pid)
Function that decides if a connection is acceptable or not.
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1284
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
static struct GNUNET_TRANSPORT_Blacklist * blacklist
Blacklist (NULL if we have none).
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
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).
static void read_friends_file(const struct GNUNET_CONFIGURATION_Handle *cfg)
Read the friends file.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static unsigned int target_connection_count
Target number of connections.
static struct GNUNET_ATS_ConnectivityHandle * ats
Handle to the ATS service.
static struct GNUNET_STATISTICS_Handle * stats
Handle for reporting statistics.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_TRANSPORT_Blacklist * GNUNET_TRANSPORT_blacklist(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_TRANSPORT_BlacklistCallback cb, void *cb_cls)
Install a blacklist callback.
static void core_init(void *cls, const struct GNUNET_PeerIdentity *my_id)
Function called after GNUNET_CORE_connect has succeeded (or failed for good).
Message handler for a specific message type.
static struct GNUNET_PEERINFO_Handle * pi
Handle to the PEERINFO service.
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:690
struct GNUNET_ATS_ConnectivityHandle * GNUNET_ATS_connectivity_init(const struct GNUNET_CONFIGURATION_Handle *cfg)
Initialize the ATS connectivity suggestion client handle.
#define GNUNET_log(kind,...)
static void * connect_notify(void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq)
Method called whenever a peer connects.
static struct GNUNET_CORE_Handle * handle
Handle to the CORE service.
#define GNUNET_YES
Definition: gnunet_common.h:77
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
static struct GNUNET_CONTAINER_MultiPeerMap * peers
All of our friends, all of our current neighbours and all peers for which we have HELLOs...
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
static unsigned int minimum_friend_count
Minimum number of friends to have in the connection set before we allow non-friends.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
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.
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 1113 of file gnunet-daemon-topology.c.

References _, __attribute__, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), ret, and run().

1114 {
1115  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1117  };
1118  int ret;
1119 
1120  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
1121  return 2;
1122 
1123  ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc,
1124  argv,
1125  "gnunet-daemon-topology",
1126  _("GNUnet topology control"),
1127  options,
1128  &run,
1129  NULL))
1130  ? 0
1131  : 1;
1132  GNUNET_free((void *)argv);
1133  return ret;
1134 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1439
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Definition of a command line option.
static int ret
Final status code.
Definition: gnunet-arm.c:89
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run.
int 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, parse options).
Definition: program.c:367
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:

Variable Documentation

◆ peerinfo_notify

struct GNUNET_PEERINFO_NotifyContext* peerinfo_notify
static

Our peerinfo notification context.

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

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

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Our configuration.

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

◆ handle

struct GNUNET_CORE_Handle* handle
static

Handle to the CORE service.

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

◆ pi

struct GNUNET_PEERINFO_Handle* pi
static

Handle to the PEERINFO service.

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

◆ ats

struct GNUNET_ATS_ConnectivityHandle* ats
static

Handle to the ATS service.

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

◆ my_identity

struct GNUNET_PeerIdentity my_identity
static

Identity of this peer.

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

Referenced by attempt_connect(), connect_notify(), consider_for_advertising(), core_init(), handle_friend(), and process_peer().

◆ peers

struct GNUNET_CONTAINER_MultiPeerMap* peers
static

All of our friends, 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 159 of file gnunet-daemon-topology.c.

◆ stats

struct GNUNET_STATISTICS_Handle* stats
static

Handle for reporting statistics.

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

◆ blacklist

struct GNUNET_TRANSPORT_Blacklist* blacklist
static

Blacklist (NULL if we have none).

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

◆ add_task

struct GNUNET_SCHEDULER_Task* add_task
static

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

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

◆ oh

Active HELLO offering to transport service.

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

Referenced by GNUNET_SET_accept(), GNUNET_SET_prepare(), and handle_result().

◆ friends_only

int friends_only
static

Flag to disallow non-friend connections (pure F2F mode).

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

Referenced by attempt_connect(), connect_notify(), handle_hello(), read_friends_file(), and run().

◆ minimum_friend_count

unsigned int minimum_friend_count
static

Minimum number of friends to have in the connection set before we allow non-friends.

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

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

◆ connection_count

unsigned int connection_count
static

Number of peers (friends and others) 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(), read_friends_file(), and run().

◆ friend_count

unsigned int friend_count
static

Number of friends that we are currently connected to.

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

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