aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_peerstore_service.h
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2024-02-23 15:38:49 +0100
committerMartin Schanzenbach <schanzen@gnunet.org>2024-02-23 15:42:31 +0100
commitd8a247e343a85d0e184aeebdab9c26f85afb320c (patch)
treec66830184d8e1fab85189392b5549faa77a5d064 /src/include/gnunet_peerstore_service.h
parent72bc94764fb7b3dafef719f748841d5f7947c2d3 (diff)
downloadgnunet-d8a247e343a85d0e184aeebdab9c26f85afb320c.tar.gz
gnunet-d8a247e343a85d0e184aeebdab9c26f85afb320c.zip
PEERSTORE: Align API with NAMESTORE iterator and monitor.
This includes renaming of PEERSTORE API calls and changing the indended usage/contract. It also deprecates some rather wonky API calls (e.g. *hello_notify and hello_add and friends) NEWS: Reworked PEERSTORE API
Diffstat (limited to 'src/include/gnunet_peerstore_service.h')
-rw-r--r--src/include/gnunet_peerstore_service.h185
1 files changed, 105 insertions, 80 deletions
diff --git a/src/include/gnunet_peerstore_service.h b/src/include/gnunet_peerstore_service.h
index 966abb7a6..0284d46dd 100644
--- a/src/include/gnunet_peerstore_service.h
+++ b/src/include/gnunet_peerstore_service.h
@@ -66,32 +66,32 @@ extern "C" {
66 * messages. 66 * messages.
67 */ 67 */
68#define GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME \ 68#define GNUNET_PEERSTORE_TRANSPORT_BACKCHANNEL_MONOTIME \
69 "transport-backchannel-monotonic-time" 69 "transport-backchannel-monotonic-time"
70 70
71/** 71/**
72 * Key used to store sender's monotonic time from DV learn 72 * Key used to store sender's monotonic time from DV learn
73 * messages. 73 * messages.
74 */ 74 */
75#define GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME \ 75#define GNUNET_PEERSTORE_TRANSPORT_DVLEARN_MONOTIME \
76 "transport-dv-learn-monotonic-time" 76 "transport-dv-learn-monotonic-time"
77 77
78/** 78/**
79 * Key used to store sender's monotonic time from handshake message. 79 * Key used to store sender's monotonic time from handshake message.
80 */ 80 */
81#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE \ 81#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE \
82 "transport-tcp-communicator-handshake" 82 "transport-tcp-communicator-handshake"
83 83
84/** 84/**
85 * Key used to store sender's monotonic time from handshake ack message. 85 * Key used to store sender's monotonic time from handshake ack message.
86 */ 86 */
87#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK \ 87#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_HANDSHAKE_ACK \
88 "transport-tcp-communicator-handshake-ack" 88 "transport-tcp-communicator-handshake-ack"
89 89
90/** 90/**
91 * Key used to store sender's monotonic time from rekey message. 91 * Key used to store sender's monotonic time from rekey message.
92 */ 92 */
93#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY \ 93#define GNUNET_PEERSTORE_TRANSPORT_TCP_COMMUNICATOR_REKEY \
94 "transport-tcp-communicator-rekey" 94 "transport-tcp-communicator-rekey"
95 95
96 96
97/** 97/**
@@ -108,7 +108,12 @@ enum GNUNET_PEERSTORE_StoreOption
108 * Delete any previous values for the given key before 108 * Delete any previous values for the given key before
109 * storing the given value. 109 * storing the given value.
110 */ 110 */
111 GNUNET_PEERSTORE_STOREOPTION_REPLACE = 1 111 GNUNET_PEERSTORE_STOREOPTION_REPLACE = 1,
112
113 /**
114 * Upserts values. Replaces if expiry is later than existing.
115 */
116 GNUNET_PEERSTORE_STOREOPTION_UPSERT_LATER_EXPIRY = 2
112}; 117};
113 118
114/** 119/**
@@ -161,11 +166,6 @@ struct GNUNET_PEERSTORE_Record
161 */ 166 */
162 struct GNUNET_TIME_Absolute expiry; 167 struct GNUNET_TIME_Absolute expiry;
163 168
164 /**
165 * Client from which this record originated.
166 * NOTE: This is internal to the service.
167 */
168 struct GNUNET_SERVICE_Client *client;
169}; 169};
170 170
171 171
@@ -209,16 +209,6 @@ struct GNUNET_PEERSTORE_StoreHelloContext
209 void *cont_cls; 209 void *cont_cls;
210 210
211 /** 211 /**
212 * Map with all store contexts started during adding hello.
213 */
214 struct GNUNET_CONTAINER_MultiPeerMap *store_context_map;
215
216 /**
217 * Active watch to be notified about conflicting hello uri add requests.
218 */
219 struct GNUNET_PEERSTORE_WatchContext *wc;
220
221 /**
222 * Hello uri which was request for storing. 212 * Hello uri which was request for storing.
223 */ 213 */
224 struct GNUNET_MessageHeader *hello; 214 struct GNUNET_MessageHeader *hello;
@@ -229,9 +219,10 @@ struct GNUNET_PEERSTORE_StoreHelloContext
229 struct GNUNET_PeerIdentity *pid; 219 struct GNUNET_PeerIdentity *pid;
230 220
231 /** 221 /**
232 * Was this request successful. 222 * The iteration for the merge
233 */ 223 */
234 int success; 224 struct GNUNET_PEERSTORE_StoreContext *sc;
225
235}; 226};
236 227
237/** 228/**
@@ -249,6 +240,7 @@ struct GNUNET_PEERSTORE_StoreHelloContextClosure
249 * Function called by PEERSTORE for each matching record. 240 * Function called by PEERSTORE for each matching record.
250 * 241 *
251 * @param cls closure 242 * @param cls closure
243 * @param seq sequence in interation
252 * @param record peerstore record information 244 * @param record peerstore record information
253 * @param emsg error message, or NULL if no errors 245 * @param emsg error message, or NULL if no errors
254 */ 246 */
@@ -270,38 +262,6 @@ typedef void (*GNUNET_PEERSTORE_hello_notify_cb) (
270 const char *err_msg); 262 const char *err_msg);
271 263
272/** 264/**
273 * Call a method whenever our known information about peers
274 * changes. Initially calls the given function for all known
275 * peers and then only signals changes.
276 *
277 * If @a include_friend_only is set to #GNUNET_YES peerinfo will include HELLO
278 * messages which are intended for friend to friend mode and which do not
279 * have to be gossiped. Otherwise these messages are skipped. //FIXME Not implemented atm!
280 *
281 * @param h Handle to the PEERSTORE service
282 * @param include_friend_only include HELLO messages for friends only (not used at the moment)
283 * @param callback the method to call for getting the hello.
284 * @param callback_cls closure for @a callback
285 * @return NULL on error
286 */
287struct GNUNET_PEERSTORE_NotifyContext *
288GNUNET_PEERSTORE_hello_changed_notify (struct GNUNET_PEERSTORE_Handle *h,
289 int include_friend_only,
290 GNUNET_PEERSTORE_hello_notify_cb callback,
291 void *callback_cls);
292
293
294/**
295 * Stop notifying about changes.
296 *
297 * @param nc context to stop notifying
298 */
299void
300GNUNET_PEERSTORE_hello_changed_notify_cancel (struct
301 GNUNET_PEERSTORE_NotifyContext *nc);
302
303
304/**
305 * Add hello to peerstore. 265 * Add hello to peerstore.
306 * 266 *
307 * @param h handle for peerstore. 267 * @param h handle for peerstore.
@@ -385,65 +345,130 @@ GNUNET_PEERSTORE_store_cancel (struct GNUNET_PEERSTORE_StoreContext *sc);
385 345
386 346
387/** 347/**
388 * Iterate over records matching supplied key information 348 * Iterate over peerstore entries.
349 * The iteration can be filtered to contain only records
350 * matching @a peer and/or @a key.
351 * The @a sub_system to match must be provided.
352 * @a callback will be called with (each) matching record.
353 * #GNUNET_PEERSTORE_iteration_next() must be invoked
354 * to continue processing until the end of the iteration is
355 * reached.
389 * 356 *
390 * @param h handle to the PEERSTORE service 357 * @param h handle to the PEERSTORE service
391 * @param sub_system name of sub system 358 * @param sub_system name of sub system
392 * @param peer Peer identity (can be NULL) 359 * @param peer Peer identity (can be NULL)
393 * @param key entry key string (can be NULL) 360 * @param key entry key string (can be NULL)
394 * @param callback function called with each matching record, all NULL's on end 361 * @param callback function called with each matching record. The record will be NULL to indicate end.
395 * @param callback_cls closure for @a callback 362 * @param callback_cls closure for @a callback
396 * @return Handle to iteration request 363 * @return Handle to iteration request
397 */ 364 */
398struct GNUNET_PEERSTORE_IterateContext * 365struct GNUNET_PEERSTORE_IterateContext *
399GNUNET_PEERSTORE_iterate (struct GNUNET_PEERSTORE_Handle *h, 366GNUNET_PEERSTORE_iteration_start (struct GNUNET_PEERSTORE_Handle *h,
400 const char *sub_system, 367 const char *sub_system,
401 const struct GNUNET_PeerIdentity *peer, 368 const struct GNUNET_PeerIdentity *peer,
402 const char *key, 369 const char *key,
403 GNUNET_PEERSTORE_Processor callback, 370 GNUNET_PEERSTORE_Processor callback,
404 void *callback_cls); 371 void *callback_cls);
405 372
406 373
407/** 374/**
408 * Cancel an iterate request 375 * Continue an iteration.
409 * Please do not call after the iterate request is done 376 * Do NOT call after the iterate request is done.
410 * 377 *
411 * @param ic Iterate request context as returned by GNUNET_PEERSTORE_iterate() 378 * @param ic Iterate request context as returned by #GNUNET_PEERSTORE_iteration_start()
379 * @param limit how many records to return max until #GNUNET_PEERSTORE_iterate_next() needs to be called again.
412 */ 380 */
413void 381void
414GNUNET_PEERSTORE_iterate_cancel (struct GNUNET_PEERSTORE_IterateContext *ic); 382GNUNET_PEERSTORE_iteration_next (struct GNUNET_PEERSTORE_IterateContext *ic,
383 uint64_t limit);
384
415 385
386/**
387 * Cancel an iteration.
388 * Do NOT call after the iterate request is done
389 *
390 * @param ic Iterate request context as returned by #GNUNET_PEERSTORE_iteration_start()
391 */
392void
393GNUNET_PEERSTORE_iteration_stop (struct GNUNET_PEERSTORE_IterateContext *ic);
416 394
417/** 395/**
418 * Request watching a given key 396 * Request watching a given key
419 * User will be notified with any new values added to key, 397 * The monitoring can be filtered to contain only records
420 * all existing entries are supplied beforehand. 398 * matching @a peer and/or @a key.
399 * The @a sub_system to match must be provided.
400 * @a callback will be called with (each) matching new record.
401 * #GNUNET_PEERSTORE_monitor_next() must be invoked
402 * to continue processing until @a sync_cb is
403 * called, indicating that the caller should be up-to-date.
404 * The caller will be notified with any new values added to key
405 * through @a callback.
406 * If @a iterate_first is set to GNUNET_YES, the monitor will first
407 * iterate over all existing, matching records. In any case,
408 * after @a sync_cb is called the first time monitoring starts.
421 * 409 *
422 * @param h handle to the PEERSTORE service 410 * @param h handle to the PEERSTORE service
411 * @param iterate_first first iterated of all results if GNUNET_YES
423 * @param sub_system name of sub system 412 * @param sub_system name of sub system
424 * @param peer Peer identity 413 * @param peer Peer identity
425 * @param key entry key string 414 * @param key entry key string
415 * @param error_cb function to call on error (i.e. disconnect); note that
416 * unlike the other error callbacks in this API, a call to this
417 * function does NOT destroy the monitor handle, it merely signals
418 * that monitoring is down. You need to still explicitly call
419 * #GNUNET_PEERSTORE_monitor_stop().
420 * @param error_cb_cls closure for @a error_cb
421 * @param sync_cb function called when we're in sync with the peerstore
422 * @param sync_cb_cls closure for @a sync_cb
426 * @param callback function called with each new value 423 * @param callback function called with each new value
427 * @param callback_cls closure for @a callback 424 * @param callback_cls closure for @a callback
428 * @return Handle to watch request 425 * @return Handle to watch request
429 */ 426 */
430struct GNUNET_PEERSTORE_WatchContext * 427struct GNUNET_PEERSTORE_Monitor *
431GNUNET_PEERSTORE_watch (struct GNUNET_PEERSTORE_Handle *h, 428GNUNET_PEERSTORE_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
432 const char *sub_system, 429 int iterate_first,
433 const struct GNUNET_PeerIdentity *peer, 430 const char *sub_system,
434 const char *key, 431 const struct GNUNET_PeerIdentity *peer,
435 GNUNET_PEERSTORE_Processor callback, 432 const char *key,
436 void *callback_cls); 433 GNUNET_SCHEDULER_TaskCallback error_cb,
437 434 void *error_cb_cls,
435 GNUNET_SCHEDULER_TaskCallback sync_cb,
436 void *sync_cb_cls,
437 GNUNET_PEERSTORE_Processor callback,
438 void *callback_cls);
438 439
439/** 440/**
440 * Cancel a watch request 441 * Calls the monitor processor specified in #GNUNET_PEERSTORE_monitor_start
442 * for the next record(s). This function is used to allow clients that merely
443 * monitor the NAMESTORE to still throttle namestore operations, so we can be
444 * sure that the monitors can keep up.
441 * 445 *
442 * @param wc handle to the watch request 446 * Note that #GNUNET_PEERSTORE_store() only waits for this
447 * call if the previous limit set by the client was already reached.
448 * Thus, by using a @a limit greater than 1, monitors basically enable
449 * a queue of notifications to be processed asynchronously with some
450 * delay. Note that even with a limit of 1 the
451 * #GNUNET_PEERSTORE_store() function will run asynchronously
452 * and the continuation may be invoked before the monitors completed
453 * (or even started) processing the notification. Thus, monitors will
454 * only closely track the current state of the peerstore, but not
455 * be involved in the transactions.
456 *
457 * @param zm the monitor
458 * @param limit number of records to return to the iterator in one shot
459 * (before #GNUNET_PEERSTORE_monitor_next is to be called again)
443 */ 460 */
444void 461void
445GNUNET_PEERSTORE_watch_cancel (struct GNUNET_PEERSTORE_WatchContext *wc); 462GNUNET_PEERSTORE_monitor_next (struct GNUNET_PEERSTORE_Monitor *zm,
463 uint64_t limit);
446 464
465/**
466 * Stop monitoring.
467 *
468 * @param zm handle to the monitor activity to stop
469 */
470void
471GNUNET_PEERSTORE_monitor_stop (struct GNUNET_PEERSTORE_Monitor *zm);
447 472
448#if 0 /* keep Emacsens' auto-indent happy */ 473#if 0 /* keep Emacsens' auto-indent happy */
449{ 474{