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;
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);
89  GNUNET_free (hm);
90  hm = GNUNET_malloc (GNUNET_HELLO_size (hello));
91  GNUNET_memcpy (hm, hello, GNUNET_HELLO_size (hello));
94  peer, hm,
96 }
97 
98 
102 void
104 {
106  GNUNET_NO,
107  &process_hello,
108  NULL);
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 */
#define gettext_noop(String)
Definition: gettext.h:69
struct GNUNET_HashCode key
The key used in the DHT.
GNUnet DHT globals.
struct GNUNET_STATISTICS_Handle * GDS_stats
Handle for the statistics service.
const struct GNUNET_CONFIGURATION_Handle * GDS_cfg
Configuration we use.
static struct GNUNET_PEERINFO_NotifyContext * pnc
Handle for peerinfo notifications.
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_HELLO_Message * GDS_HELLO_get(const struct GNUNET_PeerIdentity *peer)
Obtain a peer's HELLO if available.
void GDS_HELLO_init()
Initialize HELLO subsystem.
void GDS_HELLO_done()
Shutdown HELLO subsystem.
static struct GNUNET_CONTAINER_MultiPeerMap * peer_to_hello
Hash map of peers to HELLOs.
static int free_hello(void *cls, const struct GNUNET_PeerIdentity *key, void *hello)
Free memory occopied by the HELLO.
GNUnet DHT integration with peerinfo.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
void GNUNET_CONTAINER_multipeermap_destroy(struct GNUNET_CONTAINER_MultiPeerMap *map)
Destroy a hash map.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CONTAINER_MultiPeerMap * GNUNET_CONTAINER_multipeermap_create(unsigned int len, int do_not_copy_keys)
Create a multi peer map (hash map for public keys of peers).
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.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
@ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE
If a value with the given key exists, replace it.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:652
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_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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.
void GNUNET_PEERINFO_notify_cancel(struct GNUNET_PEERINFO_NotifyContext *nc)
Stop notifying about changes.
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_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:232
Internal representation of the hash map.
A HELLO message is used to exchange information about transports with other peers.
Context for the info handler.
The identity of the host (wraps the signing key of the peer).
Time for absolute times used by GNUnet, in microseconds.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.