GNUnet 0.21.2
gnunet-service-cadet_hello.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2014, 2017 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 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
31#include "cadet_protocol.h"
36
37#define LOG(level, ...) GNUNET_log_from (level, "cadet-hll", __VA_ARGS__)
38
43
48
54
55
64static void
65got_hello (void *cls,
66 const struct GNUNET_PEERSTORE_Record *record,
67 const char *err_msg)
68{
69 struct CadetPeer *peer;
71 struct GNUNET_MessageHeader *hello;
72
73 if (NULL == record->value)
74 {
76 return;
77 }
78 hello = record->value;
79 if (0 == GNUNET_memcmp (&record->peer,
80 &my_full_id))
81 {
90 return;
91 }
92
94 "Hello for %s (%d bytes), expires on %s\n",
95 GNUNET_i2s (&record->peer),
96 ntohs (hello->size),
99 peer = GCP_get (&record->peer,
100 GNUNET_YES);
101 GCP_set_hello (peer,
102 hello);
104}
105
106
107static void
108error_cb (void *cls)
109{
111 "Error in PEERSTORE monitoring\n");
112}
113
114
115static void
116sync_cb (void *cls)
117{
119 "Done with initial PEERSTORE iteration during monitoring\n");
120}
121
122
128void
130{
136 "peerstore",
137 NULL,
139 &error_cb,
140 NULL,
141 &sync_cb,
142 NULL,
143 &got_hello,
144 NULL);
145}
146
147
151void
153{
154 if (NULL != peerstore_notify)
155 {
157 peerstore_notify = NULL;
158 }
159 if (NULL != peerstore)
160 {
162 peerstore = NULL;
163 }
164 if (NULL != mine)
165 {
167 mine = NULL;
168 }
169}
170
171
177const struct GNUNET_MessageHeader *
179{
181
182 if (NULL == mine)
183 {
189 }
190 return mine;
191}
192
193
194/* end of gnunet-service-cadet-new_hello.c */
P2P messages used by CADET.
static void record(void *cls, size_t data_size, const void *data)
Process recorded audio data.
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
struct GNUNET_PeerIdentity my_full_id
Local peer own ID.
Definition: gnunet-hello.c:101
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
Definition: gnunet-hello.c:96
Information we track per peer.
void GCD_hello_update()
Function called by the HELLO subsystem whenever OUR hello changes.
cadet service; dealing with DHT requests and results
static void sync_cb(void *cls)
void GCH_shutdown()
Shut down the hello subsystem.
void GCH_init(const struct GNUNET_CONFIGURATION_Handle *c)
Initialize the hello subsystem.
static void got_hello(void *cls, const struct GNUNET_PEERSTORE_Record *record, const char *err_msg)
Process each hello message received from peerinfo.
static struct GNUNET_PEERSTORE_Monitor * peerstore_notify
Our peerstore notification context.
static struct GNUNET_PEERSTORE_Handle * peerstore
Handle to the PEERSTORE service.
const struct GNUNET_MessageHeader * GCH_get_mine(void)
Get own hello message.
static struct GNUNET_MessageHeader * mine
Hello message of local peer.
static void error_cb(void *cls)
#define LOG(level,...)
cadet service; dealing with hello messages
struct CadetPeer * GCP_get(const struct GNUNET_PeerIdentity *peer_id, int create)
Retrieve the CadetPeer structure associated with the peer.
void GCP_set_hello(struct CadetPeer *cp, const struct GNUNET_MessageHeader *hello)
We got a HELLO for a cp, remember it, and possibly trigger adequate actions (like trying to connect).
Information we track per peer.
API to the peerstore service.
API to create, modify and access statistics.
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition: hello-uri.c:373
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_new(const struct GNUNET_PeerIdentity *pid)
Allocate builder.
Definition: hello-uri.c:355
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_from_msg(const struct GNUNET_MessageHeader *msg)
Parse msg into builder.
Definition: hello-uri.c:391
struct GNUNET_TIME_Absolute GNUNET_HELLO_builder_get_expiration_time(const struct GNUNET_MessageHeader *msg)
Get the expiration time for this HELLO.
Definition: hello-uri.c:470
struct GNUNET_MessageHeader * GNUNET_HELLO_builder_to_dht_hello_msg(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_TIME_Relative expiration_time)
Generate DHT HELLO message (without peer ID) from a builder.
Definition: hello-uri.c:666
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_YES
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_PEERSTORE_monitor_stop(struct GNUNET_PEERSTORE_Monitor *zm)
Stop monitoring.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the PEERSTORE service.
struct GNUNET_PEERSTORE_Monitor * GNUNET_PEERSTORE_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, int iterate_first, const char *sub_system, const struct GNUNET_PeerIdentity *peer, const char *key, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls, GNUNET_PEERSTORE_Processor callback, void *callback_cls)
Request watching a given key The monitoring can be filtered to contain only records matching peer and...
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
void GNUNET_PEERSTORE_monitor_next(struct GNUNET_PEERSTORE_Monitor *zm, uint64_t limit)
Calls the monitor processor specified in GNUNET_PEERSTORE_monitor_start for the next record(s).
#define GNUNET_PEERSTORE_HELLO_KEY
Key used for storing HELLO in the peerstore.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:617
Struct containing all information regarding a given peer.
Context for building (or parsing) HELLO URIs.
Definition: hello-uri.c:205
Header for all communications.
Handle to the PEERSTORE service.
Definition: peerstore_api.c:44
Context for a monitor.
Single PEERSTORE record.