GNUnet  0.11.x
gnunet-service-dht_hello.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
20 
29 #include "platform.h"
30 #include "gnunet-service-dht.h"
33 
34 
39 
44 
45 
52 const struct GNUNET_HELLO_Message *
54 {
55  if (NULL == peer_to_hello)
56  return NULL;
57  return GNUNET_CONTAINER_multipeermap_get (peer_to_hello, peer);
58 }
59 
60 
71 static void
72 process_hello (void *cls,
73  const struct GNUNET_PeerIdentity *peer,
74  const struct GNUNET_HELLO_Message *hello,
75  const char *err_msg)
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);
88  hm = GNUNET_CONTAINER_multipeermap_get (peer_to_hello, peer);
90  hm = GNUNET_malloc (GNUNET_HELLO_size (hello));
91  GNUNET_memcpy (hm, hello, GNUNET_HELLO_size (hello));
93  GNUNET_CONTAINER_multipeermap_put (peer_to_hello,
94  peer, hm,
96 }
97 
98 
102 void
104 {
106  GNUNET_NO,
107  &process_hello,
108  NULL);
109  peer_to_hello = GNUNET_CONTAINER_multipeermap_create (256,
110  GNUNET_NO);
111 }
112 
113 
117 static int
118 free_hello (void *cls,
119  const struct GNUNET_PeerIdentity *key,
120  void *hello)
121 {
122  GNUNET_free (hello);
123  return GNUNET_OK;
124 }
125 
126 
130 void
132 {
133  if (NULL != pnc)
134  {
136  pnc = NULL;
137  }
138  if (NULL != peer_to_hello)
139  {
141  &free_hello,
142  NULL);
144  }
145 }
146 
147 
148 /* end of gnunet-service-dht_hello.c */
static struct GNUNET_PEERINFO_NotifyContext * pnc
Handle for peerinfo notifications.
GNUnet DHT globals.
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.
Context for the info handler.
#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_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
#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.
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).
GNUnet DHT integration with peerinfo.
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
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.
Internal representation of the hash map.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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.
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).
void GDS_HELLO_done()
Shutdown HELLO subsystem.
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.
const struct GNUNET_HELLO_Message * GDS_HELLO_get(const struct GNUNET_PeerIdentity *peer)
Obtain a peer&#39;s HELLO if available.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:652
static int free_hello(void *cls, const struct GNUNET_PeerIdentity *key, void *hello)
Free memory occopied by the HELLO.
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.
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
Configuration we use.
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:892
#define GNUNET_malloc(size)
Wrapper around malloc.
void GDS_HELLO_init()
Initialize HELLO subsystem.
#define GNUNET_free(ptr)
Wrapper around free.
#define gettext_noop(String)
Definition: gettext.h:69