aboutsummaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorChristian Grothoff <grothoff@gnunet.org>2021-07-24 22:05:46 +0200
committerChristian Grothoff <grothoff@gnunet.org>2021-07-24 22:06:04 +0200
commit31eae6bbe16302d2593b806ef3d2ac2ca9c2d8de (patch)
treeeba886ebfd704f83f13ce1b50976e3bdca6b2449 /src/include
parentebd034f8139ee90336fd8e7e2f24f9c9d39c5e25 (diff)
downloadgnunet-31eae6bbe16302d2593b806ef3d2ac2ca9c2d8de.tar.gz
gnunet-31eae6bbe16302d2593b806ef3d2ac2ca9c2d8de.zip
early draft for libgnunetpq event notification support
Diffstat (limited to 'src/include')
-rw-r--r--src/include/gnunet_common.h11
-rw-r--r--src/include/gnunet_pq_lib.h168
-rw-r--r--src/include/gnunet_strings_lib.h55
3 files changed, 214 insertions, 20 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index 1126deaf4..df1ccff26 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -435,11 +435,12 @@ enum GNUNET_ErrorType
435 * @param date when was the message logged? 435 * @param date when was the message logged?
436 * @param message what is the message 436 * @param message what is the message
437 */ 437 */
438typedef void (*GNUNET_Logger) (void *cls, 438typedef void
439 enum GNUNET_ErrorType kind, 439(*GNUNET_Logger) (void *cls,
440 const char *component, 440 enum GNUNET_ErrorType kind,
441 const char *date, 441 const char *component,
442 const char *message); 442 const char *date,
443 const char *message);
443 444
444 445
445/** 446/**
diff --git a/src/include/gnunet_pq_lib.h b/src/include/gnunet_pq_lib.h
index 2cecb9885..1f2915165 100644
--- a/src/include/gnunet_pq_lib.h
+++ b/src/include/gnunet_pq_lib.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet 2 This file is part of GNUnet
3 Copyright (C) 2016, 2017, 2020 GNUnet e.V. 3 Copyright (C) 2016, 2017, 2020, 2021 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 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 6 under the terms of the GNU Affero General Public License as published
@@ -853,6 +853,170 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db);
853 853
854 854
855/** 855/**
856 * Function called whenever the socket needed for
857 * notifications from postgres changes.
858 *
859 * @param cls closure
860 * @param fd socket to listen on, -1 for none
861 */
862typedef void
863(*GNUNET_PQ_SocketCallback)(void *cls,
864 int fd);
865
866
867/**
868 * Obtain the file descriptor to poll on for notifications.
869 * Useful if the GNUnet scheduler is NOT to be used for
870 * such notifications.
871 *
872 * @param db database handle
873 * @param sc function to call with the socket
874 * @param sc_cls closure for @a sc
875 */
876void
877GNUNET_PQ_event_set_socket_callback (struct GNUNET_PQ_Context *db,
878 GNUNET_PQ_SocketCallback sc,
879 void *sc_cls);
880
881
882/**
883 * Poll for database events now. Used if the event FD
884 * is ready and the application wants to trigger applicable
885 * events.
886 * Useful if the GNUnet scheduler is NOT to be used for
887 * such notifications.
888 *
889 * @param db database handle
890 */
891void
892GNUNET_PQ_event_do_poll (struct GNUNET_PQ_Context *db);
893
894
895/**
896 * Run poll event loop using the GNUnet scheduler.
897 *
898 * @param db database handle
899 */
900void
901GNUNET_PQ_event_scheduler_start (struct GNUNET_PQ_Context *db);
902
903
904/**
905 * Stop running poll event loop using the GNUnet scheduler.
906 *
907 * @param db database handle
908 */
909void
910GNUNET_PQ_event_scheduler_stop (struct GNUNET_PQ_Context *db);
911
912
913/**
914 * Handle for an active LISTENer to the database.
915 */
916struct GNUNET_PQ_EventHandler;
917
918/**
919 * Function called on events received from Postgres.
920 *
921 * @param cls closure
922 * @param extra additional event data provided
923 * @param extra_size number of bytes in @a extra
924 */
925typedef void
926(*GNUNET_PQ_EventCallback)(void *cls,
927 const void *extra,
928 size_t extra_size);
929
930GNUNET_NETWORK_STRUCT_BEGIN
931
932
933/**
934 * Header of a structure that describes an
935 * event channel we may subscribe to or notify on.
936 */
937struct GNUNET_PQ_EventHeaderP
938{
939 /**
940 * The length of the struct (in bytes, including the length field itself),
941 * in big-endian format.
942 */
943 uint16_t size GNUNET_PACKED;
944
945 /**
946 * The type of the message (GNUNET_PQ_EVENT_TYPE_XXXX), in big-endian format.
947 */
948 uint16_t type GNUNET_PACKED;
949
950};
951
952GNUNET_NETWORK_STRUCT_END
953
954
955/**
956 * Handle for an active LISTENer to the database.
957 */
958struct GNUNET_PQ_EventHandler;
959
960/**
961 * Register callback to be invoked on events of type @a es.
962 *
963 * Unlike many other calls, this function is thread-safe
964 * and may be called from threads that are different
965 * from the one that setup @a db. However, the @a cb
966 * will always be called from the thread that runs
967 * #GNUNET_PQ_event_do_poll() or the GNUnet scheduler.
968 *
969 * @param db database context to use
970 * @param es specification of the event to listen for
971 * @param cb function to call when the event happens, possibly
972 * multiple times (until #GNUNET_PQ_event_listen_cancel() is invoked)
973 * @param cb_cls closure for @a cb
974 * @return handle useful to cancel the listener
975 */
976struct GNUNET_PQ_EventHandler *
977GNUNET_PQ_event_listen (struct GNUNET_PQ_Context *db,
978 const struct GNUNET_PQ_EventHeaderP *es,
979 GNUNET_PQ_EventCallback cb,
980 void *cb_cls);
981
982
983/**
984 * Stop notifications.
985 *
986 * Unlike many other calls, this function is thread-safe
987 * and may be called from threads that are different
988 * from the one that setup @a db. However, the @a cb
989 * will always be called from the thread that runs
990 * #GNUNET_PQ_event_do_poll() or the GNUnet scheduler.
991 *
992 * @param eh handle to unregister.
993 */
994void
995GNUNET_PQ_event_listen_cancel (struct GNUNET_PQ_EventHandler *eh);
996
997
998/**
999 * Notify all that listen on @a es of an event.
1000 *
1001 * Unlike many other calls, this function is thread-safe
1002 * and may be called from threads that are different
1003 * from the one that setup @a db. However, the @a cb
1004 * will always be called from the thread that runs
1005 * #GNUNET_PQ_event_do_poll() or the GNUnet scheduler.
1006 *
1007 * @param db database context to use
1008 * @param es specification of the event to generate
1009 * @param extra additional event data provided
1010 * @param extra_size number of bytes in @a extra
1011 */
1012void
1013GNUNET_PQ_event_notify (struct GNUNET_PQ_Context *db,
1014 const struct GNUNET_PQ_EventHeaderP *es,
1015 const void *extra,
1016 size_t extra_size);
1017
1018
1019/**
856 * Within the @a db context, run all the SQL files 1020 * Within the @a db context, run all the SQL files
857 * from the @a load_path from 0000-9999.sql (as long 1021 * from the @a load_path from 0000-9999.sql (as long
858 * as the files exist contiguously). 1022 * as the files exist contiguously).
@@ -861,7 +1025,7 @@ GNUNET_PQ_reconnect (struct GNUNET_PQ_Context *db);
861 * @param load_path where to find the XXXX.sql files 1025 * @param load_path where to find the XXXX.sql files
862 * @return #GNUNET_OK on success 1026 * @return #GNUNET_OK on success
863 */ 1027 */
864int 1028enum GNUNET_GenericReturnValue
865GNUNET_PQ_run_sql (struct GNUNET_PQ_Context *db, 1029GNUNET_PQ_run_sql (struct GNUNET_PQ_Context *db,
866 const char *load_path); 1030 const char *load_path);
867 1031
diff --git a/src/include/gnunet_strings_lib.h b/src/include/gnunet_strings_lib.h
index 955a3afca..977c2ead7 100644
--- a/src/include/gnunet_strings_lib.h
+++ b/src/include/gnunet_strings_lib.h
@@ -327,7 +327,7 @@ GNUNET_STRINGS_data_to_string_alloc (const void *buf,
327 * @param out_size size of the output buffer @a out 327 * @param out_size size of the output buffer @a out
328 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding 328 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
329 */ 329 */
330int 330enum GNUNET_GenericReturnValue
331GNUNET_STRINGS_string_to_data (const char *enc, 331GNUNET_STRINGS_string_to_data (const char *enc,
332 size_t enclen, 332 size_t enclen,
333 void *out, 333 void *out,
@@ -335,6 +335,24 @@ GNUNET_STRINGS_string_to_data (const char *enc,
335 335
336 336
337/** 337/**
338 * Convert CrockfordBase32 encoding back to data.
339 * @a out_size will be determined from @a enc and
340 * @a out will be allocated to be large enough.
341 *
342 * @param enc the encoding
343 * @param enclen number of characters in @a enc (without 0-terminator, which can be missing)
344 * @param[out] out location where to allocate and store the decoded data
345 * @param[out] out_size set to the size of the output buffer @a out
346 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
347 */
348enum GNUNET_GenericReturnValue
349GNUNET_STRINGS_string_to_data_alloc (const char *enc,
350 size_t enclen,
351 void **out,
352 size_t *out_size);
353
354
355/**
338 * Encode into Base64. 356 * Encode into Base64.
339 * 357 *
340 * @param data the data to encode 358 * @param data the data to encode
@@ -359,7 +377,10 @@ GNUNET_STRINGS_base64_encode (const void *in,
359 * @return the size of the output 377 * @return the size of the output
360 */ 378 */
361size_t 379size_t
362GNUNET_STRINGS_urlencode (const char *data, size_t len, char **out); 380GNUNET_STRINGS_urlencode (const char *data,
381 size_t len,
382 char **out);
383
363 384
364/** 385/**
365 * Encode into Base64url. RFC7515 386 * Encode into Base64url. RFC7515
@@ -371,7 +392,9 @@ GNUNET_STRINGS_urlencode (const char *data, size_t len, char **out);
371 * @return the size of the output 392 * @return the size of the output
372 */ 393 */
373size_t 394size_t
374GNUNET_STRINGS_base64url_encode (const void *in, size_t len, char **output); 395GNUNET_STRINGS_base64url_encode (const void *in,
396 size_t len,
397 char **output);
375 398
376 399
377/** 400/**
@@ -399,7 +422,9 @@ GNUNET_STRINGS_base64_decode (const char *data,
399 * @return the size of the output 422 * @return the size of the output
400 */ 423 */
401size_t 424size_t
402GNUNET_STRINGS_base64url_decode (const char *data, size_t len, void **out); 425GNUNET_STRINGS_base64url_decode (const char *data,
426 size_t len,
427 void **out);
403 428
404/** 429/**
405 * url/percent encode (RFC3986). 430 * url/percent encode (RFC3986).
@@ -411,7 +436,9 @@ GNUNET_STRINGS_base64url_decode (const char *data, size_t len, void **out);
411 * @return the size of the output 436 * @return the size of the output
412 */ 437 */
413size_t 438size_t
414GNUNET_STRINGS_urldecode (const char *data, size_t len, char **out); 439GNUNET_STRINGS_urldecode (const char *data,
440 size_t len,
441 char **out);
415 442
416 443
417/** 444/**
@@ -442,7 +469,7 @@ GNUNET_STRINGS_pp2s (const struct GNUNET_PeerIdentity *pids,
442 * an URI, '* scheme_part' and '*path_part' will remain unchanged 469 * an URI, '* scheme_part' and '*path_part' will remain unchanged
443 * (if they weren't NULL). 470 * (if they weren't NULL).
444 */ 471 */
445int 472enum GNUNET_GenericReturnValue
446GNUNET_STRINGS_parse_uri (const char *path, 473GNUNET_STRINGS_parse_uri (const char *path,
447 char **scheme_part, 474 char **scheme_part,
448 const char **path_part); 475 const char **path_part);
@@ -462,7 +489,7 @@ GNUNET_STRINGS_parse_uri (const char *path,
462 * GNUNET_free (). Can be NULL. 489 * GNUNET_free (). Can be NULL.
463 * @return #GNUNET_YES if 'filename' is absolute, #GNUNET_NO otherwise. 490 * @return #GNUNET_YES if 'filename' is absolute, #GNUNET_NO otherwise.
464 */ 491 */
465int 492enum GNUNET_GenericReturnValue
466GNUNET_STRINGS_path_is_absolute (const char *filename, 493GNUNET_STRINGS_path_is_absolute (const char *filename,
467 int can_be_uri, 494 int can_be_uri,
468 int *r_is_uri, 495 int *r_is_uri,
@@ -505,7 +532,7 @@ enum GNUNET_STRINGS_FilenameCheck
505 * @return #GNUNET_YES if all checks pass, #GNUNET_NO if at least one of them 532 * @return #GNUNET_YES if all checks pass, #GNUNET_NO if at least one of them
506 * fails, #GNUNET_SYSERR when a check can't be performed 533 * fails, #GNUNET_SYSERR when a check can't be performed
507 */ 534 */
508int 535enum GNUNET_GenericReturnValue
509GNUNET_STRINGS_check_filename (const char *filename, 536GNUNET_STRINGS_check_filename (const char *filename,
510 enum GNUNET_STRINGS_FilenameCheck checks); 537 enum GNUNET_STRINGS_FilenameCheck checks);
511 538
@@ -521,7 +548,7 @@ GNUNET_STRINGS_check_filename (const char *filename,
521 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which 548 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which
522 * case the contents of r_buf are undefined. 549 * case the contents of r_buf are undefined.
523 */ 550 */
524int 551enum GNUNET_GenericReturnValue
525GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr, 552GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
526 uint16_t addrlen, 553 uint16_t addrlen,
527 struct sockaddr_in6 *r_buf); 554 struct sockaddr_in6 *r_buf);
@@ -537,7 +564,7 @@ GNUNET_STRINGS_to_address_ipv6 (const char *zt_addr,
537 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which case 564 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which case
538 * the contents of r_buf are undefined. 565 * the contents of r_buf are undefined.
539 */ 566 */
540int 567enum GNUNET_GenericReturnValue
541GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr, 568GNUNET_STRINGS_to_address_ipv4 (const char *zt_addr,
542 uint16_t addrlen, 569 uint16_t addrlen,
543 struct sockaddr_in *r_buf); 570 struct sockaddr_in *r_buf);
@@ -569,7 +596,7 @@ GNUNET_STRINGS_parse_socket_addr (const char *addr,
569 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which 596 * @return #GNUNET_OK if conversion succeeded. #GNUNET_SYSERR otherwise, in which
570 * case the contents of r_buf are undefined. 597 * case the contents of r_buf are undefined.
571 */ 598 */
572int 599enum GNUNET_GenericReturnValue
573GNUNET_STRINGS_to_address_ip (const char *addr, 600GNUNET_STRINGS_to_address_ip (const char *addr,
574 uint16_t addrlen, 601 uint16_t addrlen,
575 struct sockaddr_storage *r_buf); 602 struct sockaddr_storage *r_buf);
@@ -587,7 +614,7 @@ GNUNET_STRINGS_to_address_ip (const char *addr,
587 * @param u8argv a location to store new argv in 614 * @param u8argv a location to store new argv in
588 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 615 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
589 */ 616 */
590int 617enum GNUNET_GenericReturnValue
591GNUNET_STRINGS_get_utf8_args (int argc, 618GNUNET_STRINGS_get_utf8_args (int argc,
592 char *const *argv, 619 char *const *argv,
593 int *u8argc, 620 int *u8argc,
@@ -610,7 +637,9 @@ GNUNET_STRINGS_get_utf8_args (int argc,
610 * null byte 637 * null byte
611 */ 638 */
612size_t 639size_t
613GNUNET_strlcpy (char *dst, const char *src, size_t n); 640GNUNET_strlcpy (char *dst,
641 const char *src,
642 size_t n);
614 643
615 644
616/* ***************** IPv4/IPv6 parsing ****************** */ 645/* ***************** IPv4/IPv6 parsing ****************** */