diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-09-19 21:05:00 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-09-19 21:05:37 +0200 |
commit | 10eac9bb7230973e2c37be9181c36bd086ca38de (patch) | |
tree | 32344ca7ca145640947d03dddc963ba8b4457bfa | |
parent | 83c0efff026598098addfabdf72698d5d13b7b48 (diff) |
-work on dhtu
-rw-r--r-- | src/dhtu/Makefile.am | 11 | ||||
-rw-r--r-- | src/dhtu/plugin_dhtu_gnunet.c | 92 | ||||
-rw-r--r-- | src/dhtu/plugin_dhtu_ip.c | 4 | ||||
-rw-r--r-- | src/include/gnunet_dhtu_plugin.h | 54 |
4 files changed, 99 insertions, 62 deletions
diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am index 72b422812..4bc96f236 100644 --- a/src/dhtu/Makefile.am +++ b/src/dhtu/Makefile.am @@ -11,6 +11,7 @@ if USE_COVERAGE endif plugin_LTLIBRARIES = \ + libgnunet_plugin_dhtu_gnunet.la \ libgnunet_plugin_dhtu_ip.la libgnunet_plugin_dhtu_ip_la_SOURCES = \ @@ -22,3 +23,13 @@ libgnunet_plugin_dhtu_ip_la_LIBADD = \ libgnunet_plugin_dhtu_ip_la_LDFLAGS = \ $(GN_PLUGIN_LDFLAGS) + + +libgnunet_plugin_dhtu_gnunet_la_SOURCES = \ + plugin_dhtu_gnunet.c +libgnunet_plugin_dhtu_gnunet_la_LIBADD = \ + $(top_builddir)/src/util/libgnunetutil.la \ + $(XLIBS) \ + $(LTLIBINTL) +libgnunet_plugin_dhtu_gnunet_la_LDFLAGS = \ + $(GN_PLUGIN_LDFLAGS) diff --git a/src/dhtu/plugin_dhtu_gnunet.c b/src/dhtu/plugin_dhtu_gnunet.c index d6cd75242..9597ebdc0 100644 --- a/src/dhtu/plugin_dhtu_gnunet.c +++ b/src/dhtu/plugin_dhtu_gnunet.c @@ -21,11 +21,43 @@ /** * @author Christian Grothoff * - * @file plugin_dhtu_ip.c + * @file plugin_dhtu_gnunet.c * @brief plain IP based DHT network underlay */ #include "platform.h" -#incluce "gnunet_dhtu_plugin.h" +#include "gnunet_dhtu_plugin.h" + +/** + * Handle for a private key used by this underlay. + */ +struct GNUNET_DHTU_PrivateKey +{ + /** + * GNUnet uses eddsa for peers. + */ + struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_priv; + +}; + + +/** + * Handle for a public key used by this underlay. + */ +struct PublicKey +{ + + /** + * Header. + */ + struct GNUNET_DHTU_PublicKey header; + + /** + * GNUnet uses eddsa for peers. + */ + struct GNUNET_CRYPTO_EddsaPublicKey eddsa_pub; + +}; + /** * Opaque handle that the underlay offers for our address to be used when @@ -47,7 +79,7 @@ struct GNUNET_DHTU_Source */ struct GNUNET_DHTU_Target { - + /** * Application context for this target. */ @@ -94,20 +126,11 @@ struct GNUNET_DHTU_PreferenceHandle /** - * Opaque handle for a private key used by this underlay. - */ -struct GNUNET_DHTU_PrivateKey -{ - /* we are IP, we do not do crypto */ -}; - - -/** * Closure for all plugin functions. */ struct Plugin { - /** + /** * Callbacks into the DHT. */ struct GNUNET_DHTU_PluginEnvironment *env; @@ -126,10 +149,17 @@ struct Plugin static ssize_t ip_sign (void *cls, const struct GNUNET_DHTU_PrivateKey *pk, - const struct GNUNET_DHTU_SignaturePurpose *purpose, + const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, void **sig) { - return 0; + struct GNUNET_CRYPTO_EddsaSignature *es; + + es = GNUNET_new (struct GNUNET_CRYPTO_EddsaSignature); + GNUNET_CRYPTO_eddsa_sign_ (&pk->eddsa_priv, + purpose, + es); + *sig = es; + return sizeof (*es); } @@ -148,11 +178,31 @@ ip_sign (void *cls, static enum GNUNET_GenericReturnValue ip_verify (void *cls, const struct GNUNET_DHTU_PublicKey *pk, - const struct GNUNET_DHTU_SignaturePurpose *purpose, + const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, const void *sig, size_t sig_size) { - return GNUNET_NO; + const struct GNUNET_CRYPTO_EddsaSignature *es = sig; + const struct PublicKey *pub; + + GNUNET_assert (sizeof (struct PublicKey) == + ntohs (pk->size)); + pub = (const struct PublicKey *) pk; + if (sizeof (*es) != sig_size) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + if (GNUNET_OK != + GNUNET_CRYPTO_eddsa_verify_ (ntohl (purpose->purpose), + purpose, + es, + &pub->eddsa_pub)) + { + GNUNET_break_op (0); + return GNUNET_SYSERR; + } + return GNUNET_OK; } @@ -174,7 +224,7 @@ ip_try_connect (void *cls, * Request underlay to keep the connection to @a target alive if possible. * Hold may be called multiple times to express a strong preference to * keep a connection, say because a @a target is in multiple tables. - * + * * @param cls closure * @param target connection to keep alive */ @@ -196,7 +246,7 @@ ip_hold (void *cls, /** * Do no long request underlay to keep the connection alive. - * + * * @param cls closure * @param target connection to keep alive */ @@ -204,7 +254,7 @@ static void ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) { struct GNUNET_DHTU_Target *target = ph->target; - + GNUNET_CONTAINER_DLL_remove (target->ph_head, target->ph_tail, ph); @@ -225,7 +275,7 @@ ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) * @param msg_size number of bytes in @a msg * @param finished_cb function called once transmission is done * (not called if @a target disconnects, then only the - * disconnect_cb is called). + * disconnect_cb is called). * @param finished_cb_cls closure for @a finished_cb */ static void diff --git a/src/dhtu/plugin_dhtu_ip.c b/src/dhtu/plugin_dhtu_ip.c index 8593a69ef..ae35adb37 100644 --- a/src/dhtu/plugin_dhtu_ip.c +++ b/src/dhtu/plugin_dhtu_ip.c @@ -240,7 +240,7 @@ struct Plugin static ssize_t ip_sign (void *cls, const struct GNUNET_DHTU_PrivateKey *pk, - const struct GNUNET_DHTU_SignaturePurpose *purpose, + const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, void **sig) { return 0; @@ -262,7 +262,7 @@ ip_sign (void *cls, static enum GNUNET_GenericReturnValue ip_verify (void *cls, const struct GNUNET_DHTU_PublicKey *pk, - const struct GNUNET_DHTU_SignaturePurpose *purpose, + const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, const void *sig, size_t sig_size) { diff --git a/src/include/gnunet_dhtu_plugin.h b/src/include/gnunet_dhtu_plugin.h index df9729a23..e65318fb5 100644 --- a/src/include/gnunet_dhtu_plugin.h +++ b/src/include/gnunet_dhtu_plugin.h @@ -75,42 +75,18 @@ struct GNUNET_DHTU_PublicKey /* followed by size-2 bytes of the actual public key */ }; - + /** * Hash used by the DHT for keys and peers. */ struct GNUNET_DHTU_Hash { - - /** - * For now, use a 512 bit hash. (To be discussed). - */ - struct GNUNET_HashCode hc; -}; - -/** - * @brief header of what an DHTU signature signs - * this must be followed by "size - 8" bytes of - * the actual signed data - */ -struct GNUNET_DHTU_SignaturePurpose -{ /** - * How many bytes does this signature sign? - * (including this purpose header); in network - * byte order (!). - */ - uint32_t size GNUNET_PACKED; - - /** - * What does this signature vouch for? This - * must contain a GNUNET_SIGNATURE_PURPOSE_XXX - * constant (from gnunet_signatures.h). In - * network byte order! + * For now, use a 512 bit hash. (To be discussed). */ - uint32_t purpose GNUNET_PACKED; + struct GNUNET_HashCode hc; }; @@ -131,7 +107,7 @@ struct GNUNET_DHTU_PluginEnvironment */ void *cls; - /** + /** * Function to call with new addresses of this peer. * * @param cls the closure @@ -151,7 +127,7 @@ struct GNUNET_DHTU_PluginEnvironment struct GNUNET_DHTU_Source *source, void **ctx); - /** + /** * Function to call with expired addresses of this peer. * * @param[in] ctx storage space used by the DHT in association with this address @@ -160,7 +136,7 @@ struct GNUNET_DHTU_PluginEnvironment (*address_del_cb)(void *ctx); /** - * We have a new estimate on the size of the underlay. + * We have a new estimate on the size of the underlay. * * @param cls closure * @param timestamp time when the estimate was received from the server (or created by the server) @@ -172,7 +148,7 @@ struct GNUNET_DHTU_PluginEnvironment struct GNUNET_TIME_Absolute timestamp, double logestimate, double std_dev); - + /** * Function to call when we connect to a peer and can henceforth transmit to * that peer. @@ -208,7 +184,7 @@ struct GNUNET_DHTU_PluginEnvironment * @param cls the closure * @param origin where the message originated from * @param[in,out] tctx ctx of target address where we received the message from - * @param[in,out] sctx ctx of our own source address at which we received the message + * @param[in,out] sctx ctx of our own source address at which we received the message * @param message the message we received @param message_size number of * bytes in @a message */ @@ -244,7 +220,7 @@ struct GNUNET_DHTU_PluginFunctions ssize_t (*sign)(void *cls, const struct GNUNET_DHTU_PrivateKey *pk, - const struct GNUNET_DHTU_SignaturePurpose *purpose, + const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, void **sig); /** @@ -262,7 +238,7 @@ struct GNUNET_DHTU_PluginFunctions enum GNUNET_GenericReturnValue (*verify)(void *cls, const struct GNUNET_DHTU_PublicKey *pk, - const struct GNUNET_DHTU_SignaturePurpose *purpose, + const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, const void *sig, size_t sig_size); @@ -281,7 +257,7 @@ struct GNUNET_DHTU_PluginFunctions * Request underlay to keep the connection to @a target alive if possible. * Hold may be called multiple times to express a strong preference to * keep a connection, say because a @a target is in multiple tables. - * + * * @param cls closure * @param target connection to keep alive */ @@ -291,13 +267,13 @@ struct GNUNET_DHTU_PluginFunctions /** * Do no long request underlay to keep the connection alive. - * + * * @param cls closure * @param target connection to keep alive */ void (*drop)(struct GNUNET_DHTU_PreferenceHandle *ph); - + /** * Send message to some other participant over the network. Note that * sending is not guaranteeing that the other peer actually received the @@ -310,7 +286,7 @@ struct GNUNET_DHTU_PluginFunctions * @param msg_size number of bytes in @a msg * @param finished_cb function called once transmission is done * (not called if @a target disconnects, then only the - * disconnect_cb is called). + * disconnect_cb is called). * @param finished_cb_cls closure for @a finished_cb */ void @@ -320,7 +296,7 @@ struct GNUNET_DHTU_PluginFunctions size_t msg_size, GNUNET_SCHEDULER_TaskCallback finished_cb, void *finished_cb_cls); - + }; |