GNUnet 0.26.2-114-g7c6b613e3
 
Loading...
Searching...
No Matches
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 "gnunet_pils_service.h"
28#include "platform.h"
29#include "gnunet_util_lib.h"
32#include "cadet_protocol.h"
37
38#define LOG(level, ...) GNUNET_log_from (level, "cadet-hll", __VA_ARGS__)
39
65
70
75
76
81
86
92
93
94static void
95sign_hello_cb (void *cls,
96 const struct GNUNET_HELLO_Parser *parser,
97 const struct GNUNET_HashCode *hash)
98{
99
103 "Received new PID information with address hash `%s'\n",
104 GNUNET_h2s (hash));
106}
107
108
117static void
118got_hello (void *cls,
119 const struct GNUNET_PEERSTORE_Record *record,
120 const char *err_msg)
121{
122 const struct GNUNET_PeerIdentity *my_identity;
123 struct CadetPeer *peer;
124 struct GNUNET_MessageHeader *hello;
125
127 if (! my_identity)
128 return;
129
130 if (NULL == record->value)
131 {
133 return;
134 }
135 hello = record->value;
136 if (0 == GNUNET_memcmp (&record->peer, my_identity))
137 {
139 "Ignoring own HELLOs\n");
141 return;
142 }
143
145 "Hello for %s (%d bytes), expires on %s\n",
146 GNUNET_i2s (&record->peer),
147 ntohs (hello->size),
150 peer = GCP_get (&record->peer,
151 GNUNET_YES);
152 GCP_set_hello (peer,
153 hello);
155}
156
157
158static void
159error_cb (void *cls)
160{
162 "Error in PEERSTORE monitoring\n");
163}
164
165
166static void
167sync_cb (void *cls)
168{
170 "Done with initial PEERSTORE iteration during monitoring\n");
171}
172
173
179void
181{
187 "peerstore",
188 NULL,
190 &error_cb,
191 NULL,
192 &sync_cb,
193 NULL,
194 &got_hello,
195 NULL);
198 NULL);
199}
200
201
205void
207{
208 struct PilsRequest *pr;
209
210 if (NULL != peerstore_notify)
211 {
213 peerstore_notify = NULL;
214 }
215 if (NULL != peerstore)
216 {
218 peerstore = NULL;
219 }
220 while (NULL != (pr = pils_requests_head))
221 {
224 pr);
225 if (NULL != pr->op)
227 if (NULL != pr->builder)
229 GNUNET_free (pr);
230 }
231 if (NULL != pils)
232 {
234 pils = NULL;
235 }
236 if (NULL != mine)
237 {
239 mine = NULL;
240 }
241}
242
243
251{
252 return mine;
253}
254
255
256/* 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 GNUNET_PILS_Handle * pils
Handle to PILS.
Definition gnunet-pils.c:44
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.
static struct PilsRequest * pils_requests_head
PILS Operation DLL.
static void sign_hello_cb(void *cls, const struct GNUNET_HELLO_Parser *parser, const struct GNUNET_HashCode *hash)
static struct PilsRequest * pils_requests_tail
PILS Operation DLL.
static struct GNUNET_MessageHeader * mine
Hello message of local peer.
static void error_cb(void *cls)
#define LOG(level,...)
struct GNUNET_MessageHeader * GCH_get_mine()
Get own hello message.
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.
static struct GNUNET_PeerIdentity my_identity
Identity of this peer.
API to the peerstore service.
struct GNUNET_PILS_Handle * GNUNET_PILS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_PILS_PidChangeCallback pid_change_cb, void *cls)
Connect to the PILS service.
Definition pils_api.c:465
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
Definition pils_api.c:488
void GNUNET_PILS_cancel(struct GNUNET_PILS_Operation *op)
Cancel request.
Definition pils_api.c:623
const struct GNUNET_PeerIdentity * GNUNET_PILS_get_identity(const struct GNUNET_PILS_Handle *handle)
Return the current peer identity of a given handle.
Definition pils_api.c:727
API to create, modify and access statistics.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition hello-uri.c:398
struct GNUNET_MessageHeader * GNUNET_HELLO_parser_to_dht_hello_msg(const struct GNUNET_HELLO_Parser *parser)
Generate DHT HELLO message from a parser.
Definition hello-uri.c:1208
struct GNUNET_TIME_Absolute GNUNET_HELLO_get_expiration_time_from_msg(const struct GNUNET_MessageHeader *msg)
Get the expiration time for this HELLO.
Definition hello-uri.c:633
#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.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#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.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition strings.c:665
Struct containing all information regarding a given peer.
Context for building (or parsing) HELLO URIs.
Definition hello-uri.c:185
Context for parsing HELLOs.
Definition hello-uri.c:233
A 512-bit hashcode.
Header for all communications.
Handle to the PEERSTORE service.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_PILS_Operation * op
The pils operation.
struct PilsRequest * next
DLL.
struct PilsRequest * prev
DLL.
struct GNUNET_HELLO_Builder * builder
Address builder.