diff options
author | t3sserakt <t3ss@posteo.de> | 2022-04-01 15:08:41 +0200 |
---|---|---|
committer | t3sserakt <t3ss@posteo.de> | 2022-04-03 14:29:27 +0200 |
commit | 8f5b71e500a10790bf72d42de03e2db4971bf772 (patch) | |
tree | 10507356b5df0d2d0ce0b3b60a91dc070ce1001d /src/include | |
parent | 027177be3bae0c60d530b0b88ed375b082c94d81 (diff) | |
parent | e6a0ea8cf388a05856aaedbc5444f266ae47a7ef (diff) | |
download | gnunet-8f5b71e500a10790bf72d42de03e2db4971bf772.tar.gz gnunet-8f5b71e500a10790bf72d42de03e2db4971bf772.zip |
Merge branch 'master' of ssh://git.gnunet.org/gnunet
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 281 | ||||
-rw-r--r-- | src/include/gnunet_messenger_service.h | 23 | ||||
-rw-r--r-- | src/include/gnunet_namestore_plugin.h | 65 | ||||
-rw-r--r-- | src/include/gnunet_namestore_service.h | 156 | ||||
-rw-r--r-- | src/include/gnunet_time_lib.h | 29 |
5 files changed, 482 insertions, 72 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 72d783148..582a58861 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -287,6 +287,59 @@ struct GNUNET_CRYPTO_EddsaPrivateScalar | |||
287 | unsigned char s[512 / 8]; | 287 | unsigned char s[512 / 8]; |
288 | }; | 288 | }; |
289 | 289 | ||
290 | /** | ||
291 | * Private ECC key material encoded for transmission. To be used only for | ||
292 | * Edx25519 signatures. An inital key corresponds to data from the key | ||
293 | * expansion and clamping in the EdDSA key generation. | ||
294 | */ | ||
295 | struct GNUNET_CRYPTO_Edx25519PrivateKey | ||
296 | { | ||
297 | /** | ||
298 | * a is a value mod n, where n has at most 256 bits. It is the first half of | ||
299 | * the seed-expansion of EdDSA and will be clamped. | ||
300 | */ | ||
301 | unsigned char a[256 / 8]; | ||
302 | |||
303 | /** | ||
304 | * b consists of 32 bytes which where originally the lower 32bytes of the key | ||
305 | * expansion. Subsequent calls to derive_private will change this value, too. | ||
306 | */ | ||
307 | unsigned char b[256 / 8]; | ||
308 | }; | ||
309 | |||
310 | |||
311 | /** | ||
312 | * Public ECC key (always for curve Ed25519) encoded in a format suitable for | ||
313 | * network transmission and Edx25519 (same as EdDSA) signatures. Refer to | ||
314 | * section 5.1.3 of rfc8032, for a thorough explanation of how this value maps | ||
315 | * to the x- and y-coordinates. | ||
316 | */ | ||
317 | struct GNUNET_CRYPTO_Edx25519PublicKey | ||
318 | { | ||
319 | /** | ||
320 | * Point Q consists of a y-value mod p (256 bits); the x-value is | ||
321 | * always positive. The point is stored in Ed25519 standard | ||
322 | * compact format. | ||
323 | */ | ||
324 | unsigned char q_y[256 / 8]; | ||
325 | }; | ||
326 | |||
327 | /** | ||
328 | * @brief an ECC signature using Edx25519 (same as in EdDSA). | ||
329 | */ | ||
330 | struct GNUNET_CRYPTO_Edx25519Signature | ||
331 | { | ||
332 | /** | ||
333 | * R value. | ||
334 | */ | ||
335 | unsigned char r[256 / 8]; | ||
336 | |||
337 | /** | ||
338 | * S value. | ||
339 | */ | ||
340 | unsigned char s[256 / 8]; | ||
341 | }; | ||
342 | |||
290 | 343 | ||
291 | /** | 344 | /** |
292 | * @brief type for session keys | 345 | * @brief type for session keys |
@@ -1279,6 +1332,17 @@ GNUNET_CRYPTO_eddsa_key_get_public ( | |||
1279 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, | 1332 | const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, |
1280 | struct GNUNET_CRYPTO_EddsaPublicKey *pub); | 1333 | struct GNUNET_CRYPTO_EddsaPublicKey *pub); |
1281 | 1334 | ||
1335 | /** | ||
1336 | * @ingroup crypto | ||
1337 | * Extract the public key for the given private key. | ||
1338 | * | ||
1339 | * @param priv the private key | ||
1340 | * @param pub where to write the public key | ||
1341 | */ | ||
1342 | void | ||
1343 | GNUNET_CRYPTO_edx25519_key_get_public ( | ||
1344 | const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv, | ||
1345 | struct GNUNET_CRYPTO_Edx25519PublicKey *pub); | ||
1282 | 1346 | ||
1283 | /** | 1347 | /** |
1284 | * @ingroup crypto | 1348 | * @ingroup crypto |
@@ -1465,6 +1529,30 @@ GNUNET_CRYPTO_eddsa_key_create (struct GNUNET_CRYPTO_EddsaPrivateKey *pk); | |||
1465 | 1529 | ||
1466 | /** | 1530 | /** |
1467 | * @ingroup crypto | 1531 | * @ingroup crypto |
1532 | * Create a new private key. | ||
1533 | * | ||
1534 | * @param[out] pk private key to initialize | ||
1535 | */ | ||
1536 | void | ||
1537 | GNUNET_CRYPTO_edx25519_key_create (struct GNUNET_CRYPTO_Edx25519PrivateKey *pk); | ||
1538 | |||
1539 | /** | ||
1540 | * @ingroup crypto | ||
1541 | * Create a new private key for Edx25519 from a given seed. After expanding | ||
1542 | * the seed, the first half of the key will be clamped according to EdDSA. | ||
1543 | * | ||
1544 | * @param seed seed input | ||
1545 | * @param seedsize size of the seed in bytes | ||
1546 | * @param[out] pk private key to initialize | ||
1547 | */ | ||
1548 | void | ||
1549 | GNUNET_CRYPTO_edx25519_key_create_from_seed ( | ||
1550 | const void *seed, | ||
1551 | size_t seedsize, | ||
1552 | struct GNUNET_CRYPTO_Edx25519PrivateKey *pk); | ||
1553 | |||
1554 | /** | ||
1555 | * @ingroup crypto | ||
1468 | * Create a new private key. Clear with #GNUNET_CRYPTO_ecdhe_key_clear(). | 1556 | * Create a new private key. Clear with #GNUNET_CRYPTO_ecdhe_key_clear(). |
1469 | * | 1557 | * |
1470 | * @param[out] pk set to fresh private key; | 1558 | * @param[out] pk set to fresh private key; |
@@ -1492,6 +1580,14 @@ GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk); | |||
1492 | void | 1580 | void |
1493 | GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk); | 1581 | GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk); |
1494 | 1582 | ||
1583 | /** | ||
1584 | * @ingroup crypto | ||
1585 | * Clear memory that was used to store a private key. | ||
1586 | * | ||
1587 | * @param pk location of the key | ||
1588 | */ | ||
1589 | void | ||
1590 | GNUNET_CRYPTO_edx25519_key_clear (struct GNUNET_CRYPTO_Edx25519PrivateKey *pk); | ||
1495 | 1591 | ||
1496 | /** | 1592 | /** |
1497 | * @ingroup crypto | 1593 | * @ingroup crypto |
@@ -1874,6 +1970,53 @@ GNUNET_CRYPTO_ecdsa_sign_ ( | |||
1874 | sig)); \ | 1970 | sig)); \ |
1875 | } while (0) | 1971 | } while (0) |
1876 | 1972 | ||
1973 | /** | ||
1974 | * @ingroup crypto | ||
1975 | * @brief Edx25519 sign a given block. | ||
1976 | * | ||
1977 | * The @a purpose data is the beginning of the data of which the signature is | ||
1978 | * to be created. The `size` field in @a purpose must correctly indicate the | ||
1979 | * number of bytes of the data structure, including its header. If possible, | ||
1980 | * use #GNUNET_CRYPTO_edx25519_sign() instead of this function (only if @a | ||
1981 | * validate is not fixed-size, you must use this function directly). | ||
1982 | * | ||
1983 | * @param priv private key to use for the signing | ||
1984 | * @param purpose what to sign (size, purpose) | ||
1985 | * @param[out] sig where to write the signature | ||
1986 | * @return #GNUNET_SYSERR on error, #GNUNET_OK on success | ||
1987 | */ | ||
1988 | enum GNUNET_GenericReturnValue | ||
1989 | GNUNET_CRYPTO_edx25519_sign_ ( | ||
1990 | const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv, | ||
1991 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | ||
1992 | struct GNUNET_CRYPTO_Edx25519Signature *sig); | ||
1993 | |||
1994 | |||
1995 | /** | ||
1996 | * @ingroup crypto | ||
1997 | * @brief Edx25519 sign a given block. The resulting signature is compatible | ||
1998 | * with EdDSA. | ||
1999 | * | ||
2000 | * The @a ps data must be a fixed-size struct for which the signature is to be | ||
2001 | * created. The `size` field in @a ps->purpose must correctly indicate the | ||
2002 | * number of bytes of the data structure, including its header. | ||
2003 | * | ||
2004 | * @param priv private key to use for the signing | ||
2005 | * @param ps packed struct with what to sign, MUST begin with a purpose | ||
2006 | * @param[out] sig where to write the signature | ||
2007 | */ | ||
2008 | #define GNUNET_CRYPTO_edx25519_sign(priv,ps,sig) do { \ | ||
2009 | /* check size is set correctly */ \ | ||
2010 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ | ||
2011 | /* check 'ps' begins with the purpose */ \ | ||
2012 | GNUNET_static_assert (((void*) (ps)) == \ | ||
2013 | ((void*) &(ps)->purpose)); \ | ||
2014 | GNUNET_assert (GNUNET_OK == \ | ||
2015 | GNUNET_CRYPTO_edx25519_sign_ (priv, \ | ||
2016 | &(ps)->purpose, \ | ||
2017 | sig)); \ | ||
2018 | } while (0) | ||
2019 | |||
1877 | 2020 | ||
1878 | /** | 2021 | /** |
1879 | * @ingroup crypto | 2022 | * @ingroup crypto |
@@ -1917,7 +2060,7 @@ GNUNET_CRYPTO_eddsa_verify_ ( | |||
1917 | */ | 2060 | */ |
1918 | #define GNUNET_CRYPTO_eddsa_verify(purp,ps,sig,pub) ({ \ | 2061 | #define GNUNET_CRYPTO_eddsa_verify(purp,ps,sig,pub) ({ \ |
1919 | /* check size is set correctly */ \ | 2062 | /* check size is set correctly */ \ |
1920 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ | 2063 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ |
1921 | /* check 'ps' begins with the purpose */ \ | 2064 | /* check 'ps' begins with the purpose */ \ |
1922 | GNUNET_static_assert (((void*) (ps)) == \ | 2065 | GNUNET_static_assert (((void*) (ps)) == \ |
1923 | ((void*) &(ps)->purpose)); \ | 2066 | ((void*) &(ps)->purpose)); \ |
@@ -1927,7 +2070,6 @@ GNUNET_CRYPTO_eddsa_verify_ ( | |||
1927 | pub); \ | 2070 | pub); \ |
1928 | }) | 2071 | }) |
1929 | 2072 | ||
1930 | |||
1931 | /** | 2073 | /** |
1932 | * @ingroup crypto | 2074 | * @ingroup crypto |
1933 | * @brief Verify ECDSA signature. | 2075 | * @brief Verify ECDSA signature. |
@@ -1982,6 +2124,58 @@ GNUNET_CRYPTO_ecdsa_verify_ ( | |||
1982 | 2124 | ||
1983 | /** | 2125 | /** |
1984 | * @ingroup crypto | 2126 | * @ingroup crypto |
2127 | * @brief Verify Edx25519 signature. | ||
2128 | * | ||
2129 | * The @a validate data is the beginning of the data of which the signature | ||
2130 | * is to be verified. The `size` field in @a validate must correctly indicate | ||
2131 | * the number of bytes of the data structure, including its header. If @a | ||
2132 | * purpose does not match the purpose given in @a validate (the latter must be | ||
2133 | * in big endian), signature verification fails. If possible, use | ||
2134 | * #GNUNET_CRYPTO_edx25519_verify() instead of this function (only if @a | ||
2135 | * validate is not fixed-size, you must use this function directly). | ||
2136 | * | ||
2137 | * @param purpose what is the purpose that the signature should have? | ||
2138 | * @param validate block to validate (size, purpose, data) | ||
2139 | * @param sig signature that is being validated | ||
2140 | * @param pub public key of the signer | ||
2141 | * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid | ||
2142 | */ | ||
2143 | enum GNUNET_GenericReturnValue | ||
2144 | GNUNET_CRYPTO_edx25519_verify_ ( | ||
2145 | uint32_t purpose, | ||
2146 | const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, | ||
2147 | const struct GNUNET_CRYPTO_Edx25519Signature *sig, | ||
2148 | const struct GNUNET_CRYPTO_Edx25519PublicKey *pub); | ||
2149 | |||
2150 | |||
2151 | /** | ||
2152 | * @ingroup crypto | ||
2153 | * @brief Verify Edx25519 signature. | ||
2154 | * | ||
2155 | * The @a ps data must be a fixed-size struct for which the signature is to be | ||
2156 | * created. The `size` field in @a ps->purpose must correctly indicate the | ||
2157 | * number of bytes of the data structure, including its header. | ||
2158 | * | ||
2159 | * @param purp purpose of the signature, must match 'ps->purpose.purpose' | ||
2160 | * (except in host byte order) | ||
2161 | * @param priv private key to use for the signing | ||
2162 | * @param ps packed struct with what to sign, MUST begin with a purpose | ||
2163 | * @param sig where to write the signature | ||
2164 | */ | ||
2165 | #define GNUNET_CRYPTO_edx25519_verify(purp,ps,sig,pub) ({ \ | ||
2166 | /* check size is set correctly */ \ | ||
2167 | GNUNET_assert (ntohl ((ps)->purpose.size) == sizeof (*(ps))); \ | ||
2168 | /* check 'ps' begins with the purpose */ \ | ||
2169 | GNUNET_static_assert (((void*) (ps)) == \ | ||
2170 | ((void*) &(ps)->purpose)); \ | ||
2171 | GNUNET_CRYPTO_edx25519_verify_ (purp, \ | ||
2172 | &(ps)->purpose, \ | ||
2173 | sig, \ | ||
2174 | pub); \ | ||
2175 | }) | ||
2176 | |||
2177 | /** | ||
2178 | * @ingroup crypto | ||
1985 | * Derive a private key from a given private key and a label. | 2179 | * Derive a private key from a given private key and a label. |
1986 | * Essentially calculates a private key 'h = H(l,P) * d mod n' | 2180 | * Essentially calculates a private key 'h = H(l,P) * d mod n' |
1987 | * where n is the size of the ECC group and P is the public | 2181 | * where n is the size of the ECC group and P is the public |
@@ -2018,6 +2212,26 @@ GNUNET_CRYPTO_ecdsa_public_key_derive ( | |||
2018 | const char *context, | 2212 | const char *context, |
2019 | struct GNUNET_CRYPTO_EcdsaPublicKey *result); | 2213 | struct GNUNET_CRYPTO_EcdsaPublicKey *result); |
2020 | 2214 | ||
2215 | /** | ||
2216 | * This is a signature function for ECDSA which takes a | ||
2217 | * private key, derives/blinds it and signs the message. | ||
2218 | * | ||
2219 | * @param pkey original private key | ||
2220 | * @param label label to use for key deriviation | ||
2221 | * @param context additional context to use for HKDF of 'h'; | ||
2222 | * typically the name of the subsystem/application | ||
2223 | * @param purp the signature purpose | ||
2224 | * @param sig the resulting signature | ||
2225 | * @return GNUNET_OK on success | ||
2226 | */ | ||
2227 | enum GNUNET_GenericReturnValue | ||
2228 | GNUNET_CRYPTO_ecdsa_sign_derived ( | ||
2229 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pkey, | ||
2230 | const char *label, | ||
2231 | const char *context, | ||
2232 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | ||
2233 | struct GNUNET_CRYPTO_EcdsaSignature *sig); | ||
2234 | |||
2021 | 2235 | ||
2022 | /** | 2236 | /** |
2023 | * @ingroup crypto | 2237 | * @ingroup crypto |
@@ -2063,23 +2277,23 @@ GNUNET_CRYPTO_eddsa_public_key_derive ( | |||
2063 | 2277 | ||
2064 | 2278 | ||
2065 | /** | 2279 | /** |
2066 | * This is a signature function for EdDSA which takes the | 2280 | * This is a signature function for EdDSA which takes a |
2067 | * secret scalar sk instead of the private seed which is | 2281 | * private key and derives it using the label and context |
2068 | * usually the case for crypto APIs. We require this functionality | 2282 | * before signing. |
2069 | * in order to use derived private keys for signatures we | ||
2070 | * cannot calculate the inverse of a sk to find the seed | ||
2071 | * efficiently. | ||
2072 | * | 2283 | * |
2073 | * The resulting signature is a standard EdDSA signature | 2284 | * @param pkey original private key |
2074 | * which can be verified using the usual APIs. | 2285 | * @param label label to use for key deriviation |
2075 | * | 2286 | * @param context additional context to use for HKDF of 'h'; |
2076 | * @param sk the secret scalar | 2287 | * typically the name of the subsystem/application |
2077 | * @param purp the signature purpose | 2288 | * @param purp the signature purpose |
2078 | * @param sig the resulting signature | 2289 | * @param sig the resulting signature |
2290 | * @return GNUNET_OK on success | ||
2079 | */ | 2291 | */ |
2080 | void | 2292 | enum GNUNET_GenericReturnValue |
2081 | GNUNET_CRYPTO_eddsa_sign_with_scalar ( | 2293 | GNUNET_CRYPTO_eddsa_sign_derived ( |
2082 | const struct GNUNET_CRYPTO_EddsaPrivateScalar *priv, | 2294 | const struct GNUNET_CRYPTO_EddsaPrivateKey *pkey, |
2295 | const char *label, | ||
2296 | const char *context, | ||
2083 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, | 2297 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
2084 | struct GNUNET_CRYPTO_EddsaSignature *sig); | 2298 | struct GNUNET_CRYPTO_EddsaSignature *sig); |
2085 | 2299 | ||
@@ -2095,6 +2309,43 @@ GNUNET_CRYPTO_eddsa_key_get_public_from_scalar ( | |||
2095 | const struct GNUNET_CRYPTO_EddsaPrivateScalar *s, | 2309 | const struct GNUNET_CRYPTO_EddsaPrivateScalar *s, |
2096 | struct GNUNET_CRYPTO_EddsaPublicKey *pkey); | 2310 | struct GNUNET_CRYPTO_EddsaPublicKey *pkey); |
2097 | 2311 | ||
2312 | /** | ||
2313 | * @ingroup crypto | ||
2314 | * Derive a private scalar from a given private key and a label. | ||
2315 | * Essentially calculates a private key 'h = H(l,P) * d mod n' | ||
2316 | * where n is the size of the ECC group and P is the public | ||
2317 | * key associated with the private key 'd'. | ||
2318 | * | ||
2319 | * @param priv original private key | ||
2320 | * @param seed input seed | ||
2321 | * @param seedsize size of the seed | ||
2322 | * @param result derived private key | ||
2323 | */ | ||
2324 | void | ||
2325 | GNUNET_CRYPTO_edx25519_private_key_derive ( | ||
2326 | const struct GNUNET_CRYPTO_Edx25519PrivateKey *priv, | ||
2327 | const void *seed, | ||
2328 | size_t seedsize, | ||
2329 | struct GNUNET_CRYPTO_Edx25519PrivateKey *result); | ||
2330 | |||
2331 | |||
2332 | /** | ||
2333 | * @ingroup crypto | ||
2334 | * Derive a public key from a given public key and a label. | ||
2335 | * Essentially calculates a public key 'V = H(l,P) * P'. | ||
2336 | * | ||
2337 | * @param pub original public key | ||
2338 | * @param seed input seed | ||
2339 | * @param seedsize size of the seed | ||
2340 | * @param result where to write the derived public key | ||
2341 | */ | ||
2342 | void | ||
2343 | GNUNET_CRYPTO_edx25519_public_key_derive ( | ||
2344 | const struct GNUNET_CRYPTO_Edx25519PublicKey *pub, | ||
2345 | const void *seed, | ||
2346 | size_t seedsize, | ||
2347 | struct GNUNET_CRYPTO_Edx25519PublicKey *result); | ||
2348 | |||
2098 | 2349 | ||
2099 | /** | 2350 | /** |
2100 | * Output the given MPI value to the given buffer in network | 2351 | * Output the given MPI value to the given buffer in network |
diff --git a/src/include/gnunet_messenger_service.h b/src/include/gnunet_messenger_service.h index 96d48b411..f8bbc7398 100644 --- a/src/include/gnunet_messenger_service.h +++ b/src/include/gnunet_messenger_service.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2020--2021 GNUnet e.V. | 3 | Copyright (C) 2020--2022 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 |
@@ -96,6 +96,27 @@ struct GNUNET_MESSENGER_RoomEntryRecord | |||
96 | 96 | ||
97 | GNUNET_NETWORK_STRUCT_END | 97 | GNUNET_NETWORK_STRUCT_END |
98 | 98 | ||
99 | GNUNET_NETWORK_STRUCT_BEGIN | ||
100 | |||
101 | /** | ||
102 | * A room details record specifies a custom name for a given room and | ||
103 | * some additional space for flags. | ||
104 | */ | ||
105 | struct GNUNET_MESSENGER_RoomDetailsRecord | ||
106 | { | ||
107 | /** | ||
108 | * The custom name for the room. | ||
109 | */ | ||
110 | char name [256]; | ||
111 | |||
112 | /** | ||
113 | * The flags of the room. | ||
114 | */ | ||
115 | uint32_t flags; | ||
116 | }; | ||
117 | |||
118 | GNUNET_NETWORK_STRUCT_END | ||
119 | |||
99 | /** | 120 | /** |
100 | * Enum for the different supported kinds of messages | 121 | * Enum for the different supported kinds of messages |
101 | */ | 122 | */ |
diff --git a/src/include/gnunet_namestore_plugin.h b/src/include/gnunet_namestore_plugin.h index 9cc8abc6e..3dca5a853 100644 --- a/src/include/gnunet_namestore_plugin.h +++ b/src/include/gnunet_namestore_plugin.h | |||
@@ -150,6 +150,71 @@ struct GNUNET_NAMESTORE_PluginFunctions | |||
150 | const struct GNUNET_IDENTITY_PublicKey *value_zone, | 150 | const struct GNUNET_IDENTITY_PublicKey *value_zone, |
151 | GNUNET_NAMESTORE_RecordIterator iter, | 151 | GNUNET_NAMESTORE_RecordIterator iter, |
152 | void *iter_cls); | 152 | void *iter_cls); |
153 | |||
154 | /** Transaction-based API draft **/ | ||
155 | |||
156 | /** | ||
157 | * Start a transaction in the database | ||
158 | * | ||
159 | * @param cls closure (internal context for the plugin) | ||
160 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | ||
161 | */ | ||
162 | enum GNUNET_GenericReturnValue | ||
163 | (*transaction_begin) (void *cls); | ||
164 | |||
165 | /** | ||
166 | * Abort a transaction in the database | ||
167 | * | ||
168 | * @param cls closure (internal context for the plugin) | ||
169 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | ||
170 | */ | ||
171 | enum GNUNET_GenericReturnValue | ||
172 | (*transaction_abort) (void *cls); | ||
173 | |||
174 | /** | ||
175 | * Commit a transaction in the database | ||
176 | * | ||
177 | * @param cls closure (internal context for the plugin) | ||
178 | * @return #GNUNET_OK on success, #GNUNET_NO if there were no results, #GNUNET_SYSERR on error | ||
179 | */ | ||
180 | enum GNUNET_GenericReturnValue | ||
181 | (*transaction_commit) (void *cls); | ||
182 | |||
183 | /** | ||
184 | * Replace a record in the datastore for which we are the authority. | ||
185 | * Removes any existing record in the same zone with the same name. | ||
186 | * | ||
187 | * @param cls closure (internal context for the plugin) | ||
188 | * @param zone private key of the zone | ||
189 | * @param label name of the record in the zone | ||
190 | * @param rd_count number of entries in @a rd array, 0 to delete all records | ||
191 | * @param rd array of records with data to store | ||
192 | * @return #GNUNET_OK on success, else #GNUNET_SYSERR | ||
193 | */ | ||
194 | int | ||
195 | (*replace_records) (void *cls, | ||
196 | const struct GNUNET_IDENTITY_PrivateKey *zone, | ||
197 | const char *label, | ||
198 | unsigned int rd_count, | ||
199 | const struct GNUNET_GNSRECORD_Data *rd); | ||
200 | |||
201 | /** | ||
202 | * Lookup records in the datastore for which we are the authority. | ||
203 | * | ||
204 | * @param cls closure (internal context for the plugin) | ||
205 | * @param zone private key of the zone | ||
206 | * @param label name of the record in the zone | ||
207 | * @param iter function to call with the result | ||
208 | * @param iter_cls closure for @a iter | ||
209 | * @return #GNUNET_OK on success, #GNUNET_NO for no results, else #GNUNET_SYSERR | ||
210 | */ | ||
211 | int | ||
212 | (*select_records) (void *cls, | ||
213 | const struct GNUNET_IDENTITY_PrivateKey *zone, | ||
214 | const char *label, | ||
215 | GNUNET_NAMESTORE_RecordIterator iter, | ||
216 | void *iter_cls); | ||
217 | |||
153 | }; | 218 | }; |
154 | 219 | ||
155 | 220 | ||
diff --git a/src/include/gnunet_namestore_service.h b/src/include/gnunet_namestore_service.h index 619b81aed..86572803f 100644 --- a/src/include/gnunet_namestore_service.h +++ b/src/include/gnunet_namestore_service.h | |||
@@ -212,61 +212,6 @@ GNUNET_NAMESTORE_records_lookup (struct GNUNET_NAMESTORE_Handle *h, | |||
212 | 212 | ||
213 | 213 | ||
214 | /** | 214 | /** |
215 | * Open a record set for editing. | ||
216 | * Retrieves an exclusive lock on this set. | ||
217 | * Must be commited using @a GNUNET_NAMESTORE_records_commit | ||
218 | * | ||
219 | * @param h handle to the namestore | ||
220 | * @param pkey private key of the zone | ||
221 | * @param label name that is being mapped | ||
222 | * @param error_cb function to call on error (i.e. disconnect or unable to get lock) | ||
223 | * the handle is afterwards invalid | ||
224 | * @param error_cb_cls closure for @a error_cb | ||
225 | * @param rm function to call with the result (with 0 records if we don't have that label) | ||
226 | * @param rm_cls closure for @a rm | ||
227 | * @return handle to abort the request | ||
228 | */ | ||
229 | struct GNUNET_NAMESTORE_QueueEntry * | ||
230 | GNUNET_NAMESTORE_records_open (struct GNUNET_NAMESTORE_Handle *h, | ||
231 | const struct | ||
232 | GNUNET_IDENTITY_PrivateKey *pkey, | ||
233 | const char *label, | ||
234 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
235 | void *error_cb_cls, | ||
236 | GNUNET_NAMESTORE_RecordMonitor rm, | ||
237 | void *rm_cls); | ||
238 | |||
239 | /** | ||
240 | * Commit the record set to the namestore. | ||
241 | * Releases the lock on the record set. | ||
242 | * Use an empty array to | ||
243 | * remove all records under the given name. | ||
244 | * | ||
245 | * The continuation is called after the value has been stored in the | ||
246 | * database. Monitors may be notified asynchronously (basically with | ||
247 | * a buffer). However, if any monitor is consistently too slow to | ||
248 | * keep up with the changes, calling @a cont will be delayed until the | ||
249 | * monitors do keep up. | ||
250 | * | ||
251 | * @param h handle to the namestore | ||
252 | * @param pkey private key of the zone | ||
253 | * @param label name that is being mapped | ||
254 | * @param rd_count number of records in the 'rd' array | ||
255 | * @param rd array of records with data to store | ||
256 | * @param cont continuation to call when done | ||
257 | * @param cont_cls closure for @a cont | ||
258 | * @return handle to abort the request | ||
259 | */ | ||
260 | struct GNUNET_NAMESTORE_QueueEntry * | ||
261 | GNUNET_NAMESTORE_records_commit (struct GNUNET_NAMESTORE_Handle *h, | ||
262 | const struct GNUNET_IDENTITY_PrivateKey *pkey, | ||
263 | const char *label, | ||
264 | unsigned int rd_count, | ||
265 | const struct GNUNET_GNSRECORD_Data *rd, | ||
266 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
267 | void *cont_cls); | ||
268 | |||
269 | /** | ||
270 | * Look for an existing PKEY delegation record for a given public key. | 215 | * Look for an existing PKEY delegation record for a given public key. |
271 | * Returns at most one result to the processor. | 216 | * Returns at most one result to the processor. |
272 | * | 217 | * |
@@ -448,6 +393,107 @@ void | |||
448 | GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm); | 393 | GNUNET_NAMESTORE_zone_monitor_stop (struct GNUNET_NAMESTORE_ZoneMonitor *zm); |
449 | 394 | ||
450 | 395 | ||
396 | /** | ||
397 | * New API draft. Experimental | ||
398 | */ | ||
399 | |||
400 | /** | ||
401 | * Begin a namestore transaction. | ||
402 | * | ||
403 | * @param h handle to the namestore | ||
404 | * @param error_cb function to call on error (i.e. disconnect or unable to get lock) | ||
405 | * the handle is afterwards invalid | ||
406 | * @param error_cb_cls closure for @a error_cb | ||
407 | * @return handle to abort the request | ||
408 | */ | ||
409 | struct GNUNET_NAMESTORE_QueueEntry * | ||
410 | GNUNET_NAMESTORE_transaction_begin (struct GNUNET_NAMESTORE_Handle *h, | ||
411 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
412 | void *error_cb_cls); | ||
413 | |||
414 | /** | ||
415 | * Begin rollback all actions in a transaction. | ||
416 | * Reverts all actions performed since #GNUNET_NAMESTORE_transaction_begin | ||
417 | * | ||
418 | * @param h handle to the namestore | ||
419 | * @param error_cb function to call on error (i.e. disconnect or unable to get lock) | ||
420 | * the handle is afterwards invalid | ||
421 | * @param error_cb_cls closure for @a error_cb | ||
422 | * @return handle to abort the request | ||
423 | */ | ||
424 | struct GNUNET_NAMESTORE_QueueEntry * | ||
425 | GNUNET_NAMESTORE_transaction_abort (struct GNUNET_NAMESTORE_Handle *h, | ||
426 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
427 | void *error_cb_cls); | ||
428 | /** | ||
429 | * Commit a namestore transaction. | ||
430 | * Saves all actions performed since #GNUNET_NAMESTORE_transaction_begin | ||
431 | * | ||
432 | * @param h handle to the namestore | ||
433 | * @param error_cb function to call on error (i.e. disconnect or unable to get lock) | ||
434 | * the handle is afterwards invalid | ||
435 | * @param error_cb_cls closure for @a error_cb | ||
436 | * @return handle to abort the request | ||
437 | */ | ||
438 | struct GNUNET_NAMESTORE_QueueEntry * | ||
439 | GNUNET_NAMESTORE_transaction_commit (struct GNUNET_NAMESTORE_Handle *h, | ||
440 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
441 | void *error_cb_cls); | ||
442 | |||
443 | /** | ||
444 | * Lookup an item in the namestore. | ||
445 | * | ||
446 | * @param h handle to the namestore | ||
447 | * @param pkey private key of the zone | ||
448 | * @param label name that is being mapped | ||
449 | * @param error_cb function to call on error (i.e. disconnect) | ||
450 | * the handle is afterwards invalid | ||
451 | * @param error_cb_cls closure for @a error_cb | ||
452 | * @param rm function to call with the result (with 0 records if we don't have that label); | ||
453 | * the handle is afterwards invalid | ||
454 | * @param rm_cls closure for @a rm | ||
455 | * @return handle to abort the request | ||
456 | */ | ||
457 | struct GNUNET_NAMESTORE_QueueEntry * | ||
458 | GNUNET_NAMESTORE_records_select (struct GNUNET_NAMESTORE_Handle *h, | ||
459 | const struct | ||
460 | GNUNET_IDENTITY_PrivateKey *pkey, | ||
461 | const char *label, | ||
462 | GNUNET_SCHEDULER_TaskCallback error_cb, | ||
463 | void *error_cb_cls, | ||
464 | GNUNET_NAMESTORE_RecordMonitor rm, | ||
465 | void *rm_cls); | ||
466 | |||
467 | |||
468 | /** | ||
469 | * Creates, deletes or updates an item in the namestore. | ||
470 | * If the item is already present, it is replaced with the new record set. | ||
471 | * Use an empty array to remove all records under the given name. | ||
472 | * | ||
473 | * The continuation is called after the value has been stored in the | ||
474 | * database. Monitors may be notified asynchronously (basically with | ||
475 | * a buffer). However, if any monitor is consistently too slow to | ||
476 | * keep up with the changes, calling @a cont will be delayed until the | ||
477 | * monitors do keep up. | ||
478 | * | ||
479 | * @param h handle to the namestore | ||
480 | * @param pkey private key of the zone | ||
481 | * @param label name that is being mapped | ||
482 | * @param rd_count number of records in the 'rd' array | ||
483 | * @param rd array of records with data to store | ||
484 | * @param cont continuation to call when done | ||
485 | * @param cont_cls closure for @a cont | ||
486 | * @return handle to abort the request | ||
487 | */ | ||
488 | struct GNUNET_NAMESTORE_QueueEntry * | ||
489 | GNUNET_NAMESTORE_records_replace (struct GNUNET_NAMESTORE_Handle *h, | ||
490 | const struct GNUNET_IDENTITY_PrivateKey *pkey, | ||
491 | const char *label, | ||
492 | unsigned int rd_count, | ||
493 | const struct GNUNET_GNSRECORD_Data *rd, | ||
494 | GNUNET_NAMESTORE_ContinuationWithStatus cont, | ||
495 | void *cont_cls); | ||
496 | |||
451 | #if 0 /* keep Emacsens' auto-indent happy */ | 497 | #if 0 /* keep Emacsens' auto-indent happy */ |
452 | { | 498 | { |
453 | #endif | 499 | #endif |
diff --git a/src/include/gnunet_time_lib.h b/src/include/gnunet_time_lib.h index 96413c3cc..d59eb984d 100644 --- a/src/include/gnunet_time_lib.h +++ b/src/include/gnunet_time_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) 2001-2013 GNUnet e.V. | 3 | Copyright (C) 2001-2022 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 |
@@ -482,6 +482,18 @@ GNUNET_TIME_absolute_max (struct GNUNET_TIME_Absolute t1, | |||
482 | 482 | ||
483 | 483 | ||
484 | /** | 484 | /** |
485 | * Round down absolute time @a at to multiple of @a rt. | ||
486 | * | ||
487 | * @param at absolute time to round | ||
488 | * @param rt multiple to round to (non-zero) | ||
489 | * @return rounded time | ||
490 | */ | ||
491 | struct GNUNET_TIME_Absolute | ||
492 | GNUNET_TIME_absolute_round_down (struct GNUNET_TIME_Absolute at, | ||
493 | struct GNUNET_TIME_Relative rt); | ||
494 | |||
495 | |||
496 | /** | ||
485 | * Return the maximum of two timestamps. | 497 | * Return the maximum of two timestamps. |
486 | * | 498 | * |
487 | * @param t1 first timestamp | 499 | * @param t1 first timestamp |
@@ -517,6 +529,21 @@ GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future); | |||
517 | 529 | ||
518 | 530 | ||
519 | /** | 531 | /** |
532 | * Test if @a a1 and @a a2 are equal within a margin of | ||
533 | * error of @a t. | ||
534 | * | ||
535 | * @param a1 time to compare | ||
536 | * @param a2 time to compare | ||
537 | * @param t tolerance to apply | ||
538 | * @return true if "|a1-a2|<=t" holds. | ||
539 | */ | ||
540 | bool | ||
541 | GNUNET_TIME_absolute_approx_eq (struct GNUNET_TIME_Absolute a1, | ||
542 | struct GNUNET_TIME_Absolute a2, | ||
543 | struct GNUNET_TIME_Relative t); | ||
544 | |||
545 | |||
546 | /** | ||
520 | * Calculate the estimate time of arrival/completion | 547 | * Calculate the estimate time of arrival/completion |
521 | * for an operation. | 548 | * for an operation. |
522 | * | 549 | * |