GNUnet  0.10.x
Functions | Variables
gnunet-service-dht_hello.c File Reference

GNUnet DHT integration with peerinfo. More...

#include "platform.h"
#include "gnunet-service-dht.h"
#include "gnunet-service-dht_hello.h"
#include "gnunet_peerinfo_service.h"
Include dependency graph for gnunet-service-dht_hello.c:

Go to the source code of this file.

Functions

const struct GNUNET_HELLO_MessageGDS_HELLO_get (const struct GNUNET_PeerIdentity *peer)
 Obtain a peer's HELLO if available. More...
 
static void process_hello (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
 Function called for each HELLO known to PEERINFO. More...
 
void GDS_HELLO_init ()
 Initialize HELLO subsystem. More...
 
static int free_hello (void *cls, const struct GNUNET_PeerIdentity *key, void *hello)
 Free memory occopied by the HELLO. More...
 
void GDS_HELLO_done ()
 Shutdown HELLO subsystem. More...
 

Variables

static struct GNUNET_PEERINFO_NotifyContextpnc
 Handle for peerinfo notifications. More...
 
static struct GNUNET_CONTAINER_MultiPeerMappeer_to_hello
 Hash map of peers to HELLOs. More...
 

Detailed Description

GNUnet DHT integration with peerinfo.

Author
Christian Grothoff

TODO:

Definition in file gnunet-service-dht_hello.c.

Function Documentation

◆ GDS_HELLO_get()

const struct GNUNET_HELLO_Message* GDS_HELLO_get ( const struct GNUNET_PeerIdentity peer)

Obtain a peer's HELLO if available.

Parameters
peerpeer to look for a HELLO from
Returns
HELLO for the given peer

Definition at line 53 of file gnunet-service-dht_hello.c.

References GNUNET_CONTAINER_multipeermap_get().

Referenced by handle_find_peer().

54 {
55  if (NULL == peer_to_hello)
56  return NULL;
58 }
static struct GNUNET_CONTAINER_MultiPeerMap * peer_to_hello
Hash map of peers to HELLOs.
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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_hello()

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

Function called for each HELLO known to PEERINFO.

Parameters
clsclosure
peerid of the peer, NULL for last call
hellohello message for the peer (can be NULL)
err_msgerror message (not used)

FIXME this is called once per address. Merge instead of replacing?

Definition at line 72 of file gnunet-service-dht_hello.c.

References GDS_stats, gettext_noop, GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE, GNUNET_CONTAINER_multipeermap_get(), GNUNET_CONTAINER_multipeermap_put(), GNUNET_free_non_null, GNUNET_HELLO_get_last_expiration(), GNUNET_HELLO_size(), GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_SYSERR, and GNUNET_TIME_absolute_get_remaining().

Referenced by GDS_HELLO_init().

76 {
77  struct GNUNET_TIME_Absolute ex;
78  struct GNUNET_HELLO_Message *hm;
79 
80  if (NULL == hello)
81  return;
83  if (0 == GNUNET_TIME_absolute_get_remaining (ex).rel_value_us)
84  return;
86  gettext_noop ("# HELLOs obtained from peerinfo"), 1,
87  GNUNET_NO);
90  hm = GNUNET_malloc (GNUNET_HELLO_size (hello));
91  GNUNET_memcpy (hm, hello, GNUNET_HELLO_size (hello));
94  peer, hm,
96 }
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
A HELLO message is used to exchange information about transports with other peers.
If a value with the given key exists, replace it.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_free_non_null(ptr)
Free the memory pointed to by ptr if ptr is not NULL.
static struct GNUNET_CONTAINER_MultiPeerMap * peer_to_hello
Hash map of peers to HELLOs.
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 GNUNET_memcpy(dst, src, n)
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
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.
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.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:649
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
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_TIME_Absolute GNUNET_HELLO_get_last_expiration(const struct GNUNET_HELLO_Message *msg)
When does the last address in the given HELLO expire?
Definition: hello.c:890
#define GNUNET_malloc(size)
Wrapper around malloc.
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GDS_HELLO_init()

void GDS_HELLO_init ( void  )

Initialize HELLO subsystem.

Definition at line 103 of file gnunet-service-dht_hello.c.

References GDS_cfg, GNUNET_CONTAINER_multipeermap_create(), GNUNET_NO, GNUNET_PEERINFO_notify(), and process_hello().

Referenced by run().

104 {
106  GNUNET_NO,
107  &process_hello,
108  NULL);
110  GNUNET_NO);
111 }
static struct GNUNET_PEERINFO_NotifyContext * pnc
Handle for peerinfo notifications.
#define GNUNET_NO
Definition: gnunet_common.h:81
static struct GNUNET_CONTAINER_MultiPeerMap * peer_to_hello
Hash map of peers to HELLOs.
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).
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.
static void process_hello(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
Function called for each HELLO known to PEERINFO.
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
Configuration we use.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_hello()

static int free_hello ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  hello 
)
static

Free memory occopied by the HELLO.

Definition at line 118 of file gnunet-service-dht_hello.c.

References GNUNET_free, and GNUNET_OK.

Referenced by GDS_HELLO_done().

121 {
122  GNUNET_free (hello);
123  return GNUNET_OK;
124 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function:

◆ GDS_HELLO_done()

void GDS_HELLO_done ( void  )

Shutdown HELLO subsystem.

Definition at line 131 of file gnunet-service-dht_hello.c.

References free_hello(), GNUNET_CONTAINER_multipeermap_destroy(), GNUNET_CONTAINER_multipeermap_iterate(), and GNUNET_PEERINFO_notify_cancel().

Referenced by shutdown_task().

132 {
133  if (NULL != pnc)
134  {
136  pnc = NULL;
137  }
138  if (NULL != peer_to_hello)
139  {
141  &free_hello,
142  NULL);
144  }
145 }
static struct GNUNET_PEERINFO_NotifyContext * pnc
Handle for peerinfo notifications.
void GNUNET_PEERINFO_notify_cancel(struct GNUNET_PEERINFO_NotifyContext *nc)
Stop notifying about changes.
static struct GNUNET_CONTAINER_MultiPeerMap * peer_to_hello
Hash map of peers to HELLOs.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
static int free_hello(void *cls, const struct GNUNET_PeerIdentity *key, void *hello)
Free memory occopied by the HELLO.
Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ pnc

struct GNUNET_PEERINFO_NotifyContext* pnc
static

Handle for peerinfo notifications.

Definition at line 38 of file gnunet-service-dht_hello.c.

◆ peer_to_hello

struct GNUNET_CONTAINER_MultiPeerMap* peer_to_hello
static

Hash map of peers to HELLOs.

Definition at line 43 of file gnunet-service-dht_hello.c.