GNUnet 0.25.2-12-g8d1cef5f6
 
Loading...
Searching...
No Matches
namestore_api_monitor.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2013, 2016, 2018 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 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_constants.h"
29#include "gnunet_arm_service.h"
30#include "gnunet_signatures.h"
32#include "namestore.h"
33
34
105
106
112static void
114
115
122static void
123handle_sync (void *cls, const struct GNUNET_MessageHeader *msg)
124{
125 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
126
127 (void) cls;
128 (void) msg;
129 if (NULL != zm->sync_cb)
131}
132
133
141static int
142check_result (void *cls, const struct RecordResultMessage *lrm)
143{
144 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
145 size_t lrm_len;
146 size_t exp_lrm_len;
147 size_t name_len;
148 size_t rd_len;
149 unsigned rd_count;
150 const char *name_tmp;
151 const char *rd_ser_tmp;
152 size_t key_len;
153
154 (void) zm;
155 key_len = ntohs (lrm->key_len);
156 (void) cls;
157 if (0 == key_len)
158 {
159 GNUNET_break (0);
160 return GNUNET_SYSERR;
161 }
162 lrm_len = ntohs (lrm->gns_header.header.size);
163 rd_len = ntohs (lrm->rd_len);
164 rd_count = ntohs (lrm->rd_count);
165 name_len = ntohs (lrm->name_len);
166 if (name_len > MAX_NAME_LEN)
167 {
168 GNUNET_break (0);
169 return GNUNET_SYSERR;
170 }
171 exp_lrm_len = sizeof(struct RecordResultMessage) + name_len + rd_len + key_len
172 ;
173 if (lrm_len != exp_lrm_len)
174 {
175 GNUNET_break (0);
176 return GNUNET_SYSERR;
177 }
178 if (0 == name_len)
179 {
180 GNUNET_break (0);
181 return GNUNET_SYSERR;
182 }
183 name_tmp = (const char *) &lrm[1] + key_len;
184 if (name_tmp[name_len - 1] != '\0')
185 {
186 GNUNET_break (0);
187 return GNUNET_SYSERR;
188 }
189 rd_ser_tmp = (const char *) &name_tmp[name_len];
190 {
192
193 if (GNUNET_OK !=
194 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd))
195 {
196 GNUNET_break (0);
197 return GNUNET_SYSERR;
198 }
199 }
200 return GNUNET_OK;
201}
202
203
211static void
212handle_result (void *cls, const struct RecordResultMessage *lrm)
213{
214 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
215 struct GNUNET_CRYPTO_BlindablePrivateKey private_key;
216 size_t name_len;
217 size_t rd_len;
218 size_t key_len;
219 size_t kbytes_read;
220 unsigned rd_count;
221 const char *name_tmp;
222 const char *rd_ser_tmp;
223
224 key_len = ntohs (lrm->key_len);
225 rd_len = ntohs (lrm->rd_len);
226 rd_count = ntohs (lrm->rd_count);
227 name_len = ntohs (lrm->name_len);
228 name_tmp = (const char *) &lrm[1] + key_len;
231 key_len,
232 &private_key,
233 &kbytes_read));
234 GNUNET_assert (kbytes_read == key_len);
235 rd_ser_tmp = (const char *) &name_tmp[name_len];
236 {
238
240 GNUNET_OK ==
241 GNUNET_GNSRECORD_records_deserialize (rd_len, rd_ser_tmp, rd_count, rd));
242 if (NULL != zm->monitor2)
243 zm->monitor2 (zm->monitor_cls, &private_key, name_tmp,
245 else
246 zm->monitor (zm->monitor_cls, &private_key, name_tmp, rd_count, rd);
247 }
248}
249
250
259static void
260mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
261{
262 struct GNUNET_NAMESTORE_ZoneMonitor *zm = cls;
263
264 (void) error;
265 reconnect (zm);
266}
267
268
274static void
276{
281 zm),
284 struct RecordResultMessage,
285 zm),
287 struct GNUNET_MQ_Envelope *env;
288 struct ZoneMonitorStartMessage *sm;
289
290 if (NULL != zm->mq)
291 {
294 }
296 "namestore",
297 handlers,
299 zm);
300 if (NULL == zm->mq)
301 return;
303 zm->key_len,
305 sm->iterate_first = htonl (zm->iterate_first);
306 if (0 < zm->key_len)
308 &sm[1],
309 zm->key_len);
310 sm->key_len = htons (zm->key_len);
311 sm->filter = htons (zm->filter);
313}
314
315
352
353
392
393
415void
426
427
433void
435{
436 if (NULL != zm->mq)
437 {
439 zm->mq = NULL;
440 }
441 GNUNET_free (zm);
442}
443
444
445/* end of namestore_api_monitor.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition 003.c:1
struct GNUNET_MessageHeader * msg
Definition 005.c:2
struct GNUNET_MQ_Envelope * env
Definition 005.c:1
static void error_cb(void *cls)
Function called if lookup fails.
Definition gnunet-abd.c:484
static int monitor
Monitor ARM activity.
Definition gnunet-arm.c:63
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
static void sync_cb(void *cls)
Function called once we are in sync in monitor mode.
static struct GNUNET_NAMESTORE_ZoneMonitor * zm
Monitor handle.
static int result
Global testing status.
static struct GNUNET_CONTAINER_BloomFilter * filter
Bloomfilter to quickly tell if we don't have the content.
API that can be used to store naming information on a GNUnet node;.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition client.c:1060
int GNUNET_GNSRECORD_records_deserialize(size_t len, const char *src, unsigned int rd_count, struct GNUNET_GNSRECORD_Data *dest)
Deserialize the given records to the given destination.
GNUNET_GNSRECORD_Filter
Filter for GNUNET_GNSRECORD_normalize_record_set().
ssize_t GNUNET_CRYPTO_write_blindable_sk_to_buffer(const struct GNUNET_CRYPTO_BlindablePrivateKey *key, void *buffer, size_t len)
Writes a GNUNET_CRYPTO_BlindablePrivateKey to a compact buffer.
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_read_private_key_from_buffer(const void *buffer, size_t len, struct GNUNET_CRYPTO_BlindablePrivateKey *key, size_t *read)
Reads a GNUNET_CRYPTO_BlindablePrivateKey from a compact buffer.
ssize_t GNUNET_CRYPTO_blindable_sk_get_length(const struct GNUNET_CRYPTO_BlindablePrivateKey *key)
Get the compacted length of a GNUNET_CRYPTO_BlindablePrivateKey.
Definition crypto_pkey.c:64
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition mq.c:700
void(* GNUNET_NAMESTORE_RecordMonitor)(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namestore.
struct GNUNET_NAMESTORE_ZoneMonitor * GNUNET_NAMESTORE_zone_monitor_start2(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, int iterate_first, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordSetMonitor monitor, void *monitor_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls, enum GNUNET_GNSRECORD_Filter filter)
Begin monitoring a zone for changes.
void(* GNUNET_NAMESTORE_RecordSetMonitor)(void *cls, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, struct GNUNET_TIME_Absolute expiry)
Process a record set that was stored in the namestore.
void GNUNET_NAMESTORE_zone_monitor_stop(struct GNUNET_NAMESTORE_ZoneMonitor *zm)
Stop monitoring a zone for changes.
struct GNUNET_NAMESTORE_ZoneMonitor * GNUNET_NAMESTORE_zone_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_CRYPTO_BlindablePrivateKey *zone, int iterate_first, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor monitor, void *monitor_cls, GNUNET_SCHEDULER_TaskCallback sync_cb, void *sync_cb_cls)
void GNUNET_NAMESTORE_zone_monitor_next(struct GNUNET_NAMESTORE_ZoneMonitor *zm, uint64_t limit)
Calls the monitor processor specified in GNUNET_NAMESTORE_zone_monitor_start for the next record(s).
#define GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT
Service to client: here is a (plaintext) record you requested.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_NEXT
Client to service: I am now ready for the next (set of) monitor events.
#define GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_START
Client to service: start monitoring (yields sequence of "ZONE_ITERATION_RESPONSES" — forever).
#define GNUNET_MESSAGE_TYPE_NAMESTORE_MONITOR_SYNC
Service to client: you're now in sync.
void(* GNUNET_SCHEDULER_TaskCallback)(void *cls)
Signature of the main function of a task.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition time.c:737
#define MAX_NAME_LEN
Maximum length of any name, including 0-termination.
Definition namecache.h:33
common internal definitions for namestore service
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
static void handle_sync(void *cls, const struct GNUNET_MessageHeader *msg)
Handle SYNC message from the namestore service.
static void handle_result(void *cls, const struct RecordResultMessage *lrm)
We've received a notification about a change to our zone.
static int check_result(void *cls, const struct RecordResultMessage *lrm)
We've received a notification about a change to our zone.
static void reconnect(void)
Adjust exponential back-off and reconnect to the service.
A private key for an identity as per LSD0001.
Handle to a message queue.
Definition mq.c:87
Message handler for a specific message type.
Header for all communications.
struct GNUNET_MessageHeader header
header.type will be GNUNET_MESSAGE_TYPE_NAMESTORE_* header.size will be message size
Definition namestore.h:46
Handle for a monitoring activity.
GNUNET_SCHEDULER_TaskCallback sync_cb
Function called when we've synchronized.
void * monitor_cls
Closure for monitor.
struct GNUNET_CRYPTO_BlindablePrivateKey zone
Monitored zone.
void * sync_cb_cls
Closure for sync_cb.
struct GNUNET_MQ_Handle * mq
Handle to namestore service.
GNUNET_NAMESTORE_RecordMonitor monitor
Function to call on events.
void * error_cb_cls
Closure for error_cb.
enum GNUNET_GNSRECORD_Filter filter
Record set filter for this monitor.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration (to reconnect).
uint32_t key_len
Zone key length.
int iterate_first
Do we first iterate over all existing records?
GNUNET_SCHEDULER_TaskCallback error_cb
Function to call on errors.
GNUNET_NAMESTORE_RecordSetMonitor monitor2
Function to call on events.
Record is returned from the namestore (as authority).
Definition namestore.h:415
uint16_t rd_len
Length of serialized record data.
Definition namestore.h:435
uint16_t name_len
Name length.
Definition namestore.h:430
uint16_t rd_count
Number of records contained.
Definition namestore.h:440
struct GNUNET_TIME_AbsoluteNBO expire
Expiration time if the record result (if any).
Definition namestore.h:425
struct GNUNET_NAMESTORE_Header gns_header
Type will be GNUNET_MESSAGE_TYPE_NAMESTORE_RECORD_RESULT.
Definition namestore.h:419
uint16_t key_len
Length of the zone key.
Definition namestore.h:445
Ask for next result of zone iteration for the given operation.
Definition namestore.h:532
uint64_t limit
Number of records to return to the iterator in one shot (before #GNUNET_MESSAGE_TYPE_NAMESTORE_ZONE_M...
Definition namestore.h:548
Start monitoring a zone.
Definition namestore.h:499
uint32_t iterate_first
GNUNET_YES to first iterate over all records, GNUNET_NO to only monitor changes.o
Definition namestore.h:509
uint16_t filter
Record set filter control flags.
Definition namestore.h:515
uint16_t key_len
Length of the zone key.
Definition namestore.h:520