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) | |
download | gnunet-10eac9bb7230973e2c37be9181c36bd086ca38de.tar.gz gnunet-10eac9bb7230973e2c37be9181c36bd086ca38de.zip |
-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 | |||
11 | endif | 11 | endif |
12 | 12 | ||
13 | plugin_LTLIBRARIES = \ | 13 | plugin_LTLIBRARIES = \ |
14 | libgnunet_plugin_dhtu_gnunet.la \ | ||
14 | libgnunet_plugin_dhtu_ip.la | 15 | libgnunet_plugin_dhtu_ip.la |
15 | 16 | ||
16 | libgnunet_plugin_dhtu_ip_la_SOURCES = \ | 17 | libgnunet_plugin_dhtu_ip_la_SOURCES = \ |
@@ -22,3 +23,13 @@ libgnunet_plugin_dhtu_ip_la_LIBADD = \ | |||
22 | libgnunet_plugin_dhtu_ip_la_LDFLAGS = \ | 23 | libgnunet_plugin_dhtu_ip_la_LDFLAGS = \ |
23 | $(GN_PLUGIN_LDFLAGS) | 24 | $(GN_PLUGIN_LDFLAGS) |
24 | 25 | ||
26 | |||
27 | |||
28 | libgnunet_plugin_dhtu_gnunet_la_SOURCES = \ | ||
29 | plugin_dhtu_gnunet.c | ||
30 | libgnunet_plugin_dhtu_gnunet_la_LIBADD = \ | ||
31 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
32 | $(XLIBS) \ | ||
33 | $(LTLIBINTL) | ||
34 | libgnunet_plugin_dhtu_gnunet_la_LDFLAGS = \ | ||
35 | $(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 @@ | |||
21 | /** | 21 | /** |
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
23 | * | 23 | * |
24 | * @file plugin_dhtu_ip.c | 24 | * @file plugin_dhtu_gnunet.c |
25 | * @brief plain IP based DHT network underlay | 25 | * @brief plain IP based DHT network underlay |
26 | */ | 26 | */ |
27 | #include "platform.h" | 27 | #include "platform.h" |
28 | #incluce "gnunet_dhtu_plugin.h" | 28 | #include "gnunet_dhtu_plugin.h" |
29 | |||
30 | /** | ||
31 | * Handle for a private key used by this underlay. | ||
32 | */ | ||
33 | struct GNUNET_DHTU_PrivateKey | ||
34 | { | ||
35 | /** | ||
36 | * GNUnet uses eddsa for peers. | ||
37 | */ | ||
38 | struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_priv; | ||
39 | |||
40 | }; | ||
41 | |||
42 | |||
43 | /** | ||
44 | * Handle for a public key used by this underlay. | ||
45 | */ | ||
46 | struct PublicKey | ||
47 | { | ||
48 | |||
49 | /** | ||
50 | * Header. | ||
51 | */ | ||
52 | struct GNUNET_DHTU_PublicKey header; | ||
53 | |||
54 | /** | ||
55 | * GNUnet uses eddsa for peers. | ||
56 | */ | ||
57 | struct GNUNET_CRYPTO_EddsaPublicKey eddsa_pub; | ||
58 | |||
59 | }; | ||
60 | |||
29 | 61 | ||
30 | /** | 62 | /** |
31 | * Opaque handle that the underlay offers for our address to be used when | 63 | * Opaque handle that the underlay offers for our address to be used when |
@@ -47,7 +79,7 @@ struct GNUNET_DHTU_Source | |||
47 | */ | 79 | */ |
48 | struct GNUNET_DHTU_Target | 80 | struct GNUNET_DHTU_Target |
49 | { | 81 | { |
50 | 82 | ||
51 | /** | 83 | /** |
52 | * Application context for this target. | 84 | * Application context for this target. |
53 | */ | 85 | */ |
@@ -94,20 +126,11 @@ struct GNUNET_DHTU_PreferenceHandle | |||
94 | 126 | ||
95 | 127 | ||
96 | /** | 128 | /** |
97 | * Opaque handle for a private key used by this underlay. | ||
98 | */ | ||
99 | struct GNUNET_DHTU_PrivateKey | ||
100 | { | ||
101 | /* we are IP, we do not do crypto */ | ||
102 | }; | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Closure for all plugin functions. | 129 | * Closure for all plugin functions. |
107 | */ | 130 | */ |
108 | struct Plugin | 131 | struct Plugin |
109 | { | 132 | { |
110 | /** | 133 | /** |
111 | * Callbacks into the DHT. | 134 | * Callbacks into the DHT. |
112 | */ | 135 | */ |
113 | struct GNUNET_DHTU_PluginEnvironment *env; | 136 | struct GNUNET_DHTU_PluginEnvironment *env; |
@@ -126,10 +149,17 @@ struct Plugin | |||
126 | static ssize_t | 149 | static ssize_t |
127 | ip_sign (void *cls, | 150 | ip_sign (void *cls, |
128 | const struct GNUNET_DHTU_PrivateKey *pk, | 151 | const struct GNUNET_DHTU_PrivateKey *pk, |
129 | const struct GNUNET_DHTU_SignaturePurpose *purpose, | 152 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
130 | void **sig) | 153 | void **sig) |
131 | { | 154 | { |
132 | return 0; | 155 | struct GNUNET_CRYPTO_EddsaSignature *es; |
156 | |||
157 | es = GNUNET_new (struct GNUNET_CRYPTO_EddsaSignature); | ||
158 | GNUNET_CRYPTO_eddsa_sign_ (&pk->eddsa_priv, | ||
159 | purpose, | ||
160 | es); | ||
161 | *sig = es; | ||
162 | return sizeof (*es); | ||
133 | } | 163 | } |
134 | 164 | ||
135 | 165 | ||
@@ -148,11 +178,31 @@ ip_sign (void *cls, | |||
148 | static enum GNUNET_GenericReturnValue | 178 | static enum GNUNET_GenericReturnValue |
149 | ip_verify (void *cls, | 179 | ip_verify (void *cls, |
150 | const struct GNUNET_DHTU_PublicKey *pk, | 180 | const struct GNUNET_DHTU_PublicKey *pk, |
151 | const struct GNUNET_DHTU_SignaturePurpose *purpose, | 181 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
152 | const void *sig, | 182 | const void *sig, |
153 | size_t sig_size) | 183 | size_t sig_size) |
154 | { | 184 | { |
155 | return GNUNET_NO; | 185 | const struct GNUNET_CRYPTO_EddsaSignature *es = sig; |
186 | const struct PublicKey *pub; | ||
187 | |||
188 | GNUNET_assert (sizeof (struct PublicKey) == | ||
189 | ntohs (pk->size)); | ||
190 | pub = (const struct PublicKey *) pk; | ||
191 | if (sizeof (*es) != sig_size) | ||
192 | { | ||
193 | GNUNET_break_op (0); | ||
194 | return GNUNET_SYSERR; | ||
195 | } | ||
196 | if (GNUNET_OK != | ||
197 | GNUNET_CRYPTO_eddsa_verify_ (ntohl (purpose->purpose), | ||
198 | purpose, | ||
199 | es, | ||
200 | &pub->eddsa_pub)) | ||
201 | { | ||
202 | GNUNET_break_op (0); | ||
203 | return GNUNET_SYSERR; | ||
204 | } | ||
205 | return GNUNET_OK; | ||
156 | } | 206 | } |
157 | 207 | ||
158 | 208 | ||
@@ -174,7 +224,7 @@ ip_try_connect (void *cls, | |||
174 | * Request underlay to keep the connection to @a target alive if possible. | 224 | * Request underlay to keep the connection to @a target alive if possible. |
175 | * Hold may be called multiple times to express a strong preference to | 225 | * Hold may be called multiple times to express a strong preference to |
176 | * keep a connection, say because a @a target is in multiple tables. | 226 | * keep a connection, say because a @a target is in multiple tables. |
177 | * | 227 | * |
178 | * @param cls closure | 228 | * @param cls closure |
179 | * @param target connection to keep alive | 229 | * @param target connection to keep alive |
180 | */ | 230 | */ |
@@ -196,7 +246,7 @@ ip_hold (void *cls, | |||
196 | 246 | ||
197 | /** | 247 | /** |
198 | * Do no long request underlay to keep the connection alive. | 248 | * Do no long request underlay to keep the connection alive. |
199 | * | 249 | * |
200 | * @param cls closure | 250 | * @param cls closure |
201 | * @param target connection to keep alive | 251 | * @param target connection to keep alive |
202 | */ | 252 | */ |
@@ -204,7 +254,7 @@ static void | |||
204 | ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) | 254 | ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) |
205 | { | 255 | { |
206 | struct GNUNET_DHTU_Target *target = ph->target; | 256 | struct GNUNET_DHTU_Target *target = ph->target; |
207 | 257 | ||
208 | GNUNET_CONTAINER_DLL_remove (target->ph_head, | 258 | GNUNET_CONTAINER_DLL_remove (target->ph_head, |
209 | target->ph_tail, | 259 | target->ph_tail, |
210 | ph); | 260 | ph); |
@@ -225,7 +275,7 @@ ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) | |||
225 | * @param msg_size number of bytes in @a msg | 275 | * @param msg_size number of bytes in @a msg |
226 | * @param finished_cb function called once transmission is done | 276 | * @param finished_cb function called once transmission is done |
227 | * (not called if @a target disconnects, then only the | 277 | * (not called if @a target disconnects, then only the |
228 | * disconnect_cb is called). | 278 | * disconnect_cb is called). |
229 | * @param finished_cb_cls closure for @a finished_cb | 279 | * @param finished_cb_cls closure for @a finished_cb |
230 | */ | 280 | */ |
231 | static void | 281 | 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 | |||
240 | static ssize_t | 240 | static ssize_t |
241 | ip_sign (void *cls, | 241 | ip_sign (void *cls, |
242 | const struct GNUNET_DHTU_PrivateKey *pk, | 242 | const struct GNUNET_DHTU_PrivateKey *pk, |
243 | const struct GNUNET_DHTU_SignaturePurpose *purpose, | 243 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
244 | void **sig) | 244 | void **sig) |
245 | { | 245 | { |
246 | return 0; | 246 | return 0; |
@@ -262,7 +262,7 @@ ip_sign (void *cls, | |||
262 | static enum GNUNET_GenericReturnValue | 262 | static enum GNUNET_GenericReturnValue |
263 | ip_verify (void *cls, | 263 | ip_verify (void *cls, |
264 | const struct GNUNET_DHTU_PublicKey *pk, | 264 | const struct GNUNET_DHTU_PublicKey *pk, |
265 | const struct GNUNET_DHTU_SignaturePurpose *purpose, | 265 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
266 | const void *sig, | 266 | const void *sig, |
267 | size_t sig_size) | 267 | size_t sig_size) |
268 | { | 268 | { |
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 | |||
75 | 75 | ||
76 | /* followed by size-2 bytes of the actual public key */ | 76 | /* followed by size-2 bytes of the actual public key */ |
77 | }; | 77 | }; |
78 | 78 | ||
79 | 79 | ||
80 | /** | 80 | /** |
81 | * Hash used by the DHT for keys and peers. | 81 | * Hash used by the DHT for keys and peers. |
82 | */ | 82 | */ |
83 | struct GNUNET_DHTU_Hash | 83 | struct GNUNET_DHTU_Hash |
84 | { | 84 | { |
85 | |||
86 | /** | ||
87 | * For now, use a 512 bit hash. (To be discussed). | ||
88 | */ | ||
89 | struct GNUNET_HashCode hc; | ||
90 | }; | ||
91 | |||
92 | 85 | ||
93 | /** | ||
94 | * @brief header of what an DHTU signature signs | ||
95 | * this must be followed by "size - 8" bytes of | ||
96 | * the actual signed data | ||
97 | */ | ||
98 | struct GNUNET_DHTU_SignaturePurpose | ||
99 | { | ||
100 | /** | 86 | /** |
101 | * How many bytes does this signature sign? | 87 | * For now, use a 512 bit hash. (To be discussed). |
102 | * (including this purpose header); in network | ||
103 | * byte order (!). | ||
104 | */ | ||
105 | uint32_t size GNUNET_PACKED; | ||
106 | |||
107 | /** | ||
108 | * What does this signature vouch for? This | ||
109 | * must contain a GNUNET_SIGNATURE_PURPOSE_XXX | ||
110 | * constant (from gnunet_signatures.h). In | ||
111 | * network byte order! | ||
112 | */ | 88 | */ |
113 | uint32_t purpose GNUNET_PACKED; | 89 | struct GNUNET_HashCode hc; |
114 | }; | 90 | }; |
115 | 91 | ||
116 | 92 | ||
@@ -131,7 +107,7 @@ struct GNUNET_DHTU_PluginEnvironment | |||
131 | */ | 107 | */ |
132 | void *cls; | 108 | void *cls; |
133 | 109 | ||
134 | /** | 110 | /** |
135 | * Function to call with new addresses of this peer. | 111 | * Function to call with new addresses of this peer. |
136 | * | 112 | * |
137 | * @param cls the closure | 113 | * @param cls the closure |
@@ -151,7 +127,7 @@ struct GNUNET_DHTU_PluginEnvironment | |||
151 | struct GNUNET_DHTU_Source *source, | 127 | struct GNUNET_DHTU_Source *source, |
152 | void **ctx); | 128 | void **ctx); |
153 | 129 | ||
154 | /** | 130 | /** |
155 | * Function to call with expired addresses of this peer. | 131 | * Function to call with expired addresses of this peer. |
156 | * | 132 | * |
157 | * @param[in] ctx storage space used by the DHT in association with this address | 133 | * @param[in] ctx storage space used by the DHT in association with this address |
@@ -160,7 +136,7 @@ struct GNUNET_DHTU_PluginEnvironment | |||
160 | (*address_del_cb)(void *ctx); | 136 | (*address_del_cb)(void *ctx); |
161 | 137 | ||
162 | /** | 138 | /** |
163 | * We have a new estimate on the size of the underlay. | 139 | * We have a new estimate on the size of the underlay. |
164 | * | 140 | * |
165 | * @param cls closure | 141 | * @param cls closure |
166 | * @param timestamp time when the estimate was received from the server (or created by the server) | 142 | * @param timestamp time when the estimate was received from the server (or created by the server) |
@@ -172,7 +148,7 @@ struct GNUNET_DHTU_PluginEnvironment | |||
172 | struct GNUNET_TIME_Absolute timestamp, | 148 | struct GNUNET_TIME_Absolute timestamp, |
173 | double logestimate, | 149 | double logestimate, |
174 | double std_dev); | 150 | double std_dev); |
175 | 151 | ||
176 | /** | 152 | /** |
177 | * Function to call when we connect to a peer and can henceforth transmit to | 153 | * Function to call when we connect to a peer and can henceforth transmit to |
178 | * that peer. | 154 | * that peer. |
@@ -208,7 +184,7 @@ struct GNUNET_DHTU_PluginEnvironment | |||
208 | * @param cls the closure | 184 | * @param cls the closure |
209 | * @param origin where the message originated from | 185 | * @param origin where the message originated from |
210 | * @param[in,out] tctx ctx of target address where we received the message from | 186 | * @param[in,out] tctx ctx of target address where we received the message from |
211 | * @param[in,out] sctx ctx of our own source address at which we received the message | 187 | * @param[in,out] sctx ctx of our own source address at which we received the message |
212 | * @param message the message we received @param message_size number of | 188 | * @param message the message we received @param message_size number of |
213 | * bytes in @a message | 189 | * bytes in @a message |
214 | */ | 190 | */ |
@@ -244,7 +220,7 @@ struct GNUNET_DHTU_PluginFunctions | |||
244 | ssize_t | 220 | ssize_t |
245 | (*sign)(void *cls, | 221 | (*sign)(void *cls, |
246 | const struct GNUNET_DHTU_PrivateKey *pk, | 222 | const struct GNUNET_DHTU_PrivateKey *pk, |
247 | const struct GNUNET_DHTU_SignaturePurpose *purpose, | 223 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
248 | void **sig); | 224 | void **sig); |
249 | 225 | ||
250 | /** | 226 | /** |
@@ -262,7 +238,7 @@ struct GNUNET_DHTU_PluginFunctions | |||
262 | enum GNUNET_GenericReturnValue | 238 | enum GNUNET_GenericReturnValue |
263 | (*verify)(void *cls, | 239 | (*verify)(void *cls, |
264 | const struct GNUNET_DHTU_PublicKey *pk, | 240 | const struct GNUNET_DHTU_PublicKey *pk, |
265 | const struct GNUNET_DHTU_SignaturePurpose *purpose, | 241 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
266 | const void *sig, | 242 | const void *sig, |
267 | size_t sig_size); | 243 | size_t sig_size); |
268 | 244 | ||
@@ -281,7 +257,7 @@ struct GNUNET_DHTU_PluginFunctions | |||
281 | * Request underlay to keep the connection to @a target alive if possible. | 257 | * Request underlay to keep the connection to @a target alive if possible. |
282 | * Hold may be called multiple times to express a strong preference to | 258 | * Hold may be called multiple times to express a strong preference to |
283 | * keep a connection, say because a @a target is in multiple tables. | 259 | * keep a connection, say because a @a target is in multiple tables. |
284 | * | 260 | * |
285 | * @param cls closure | 261 | * @param cls closure |
286 | * @param target connection to keep alive | 262 | * @param target connection to keep alive |
287 | */ | 263 | */ |
@@ -291,13 +267,13 @@ struct GNUNET_DHTU_PluginFunctions | |||
291 | 267 | ||
292 | /** | 268 | /** |
293 | * Do no long request underlay to keep the connection alive. | 269 | * Do no long request underlay to keep the connection alive. |
294 | * | 270 | * |
295 | * @param cls closure | 271 | * @param cls closure |
296 | * @param target connection to keep alive | 272 | * @param target connection to keep alive |
297 | */ | 273 | */ |
298 | void | 274 | void |
299 | (*drop)(struct GNUNET_DHTU_PreferenceHandle *ph); | 275 | (*drop)(struct GNUNET_DHTU_PreferenceHandle *ph); |
300 | 276 | ||
301 | /** | 277 | /** |
302 | * Send message to some other participant over the network. Note that | 278 | * Send message to some other participant over the network. Note that |
303 | * sending is not guaranteeing that the other peer actually received the | 279 | * sending is not guaranteeing that the other peer actually received the |
@@ -310,7 +286,7 @@ struct GNUNET_DHTU_PluginFunctions | |||
310 | * @param msg_size number of bytes in @a msg | 286 | * @param msg_size number of bytes in @a msg |
311 | * @param finished_cb function called once transmission is done | 287 | * @param finished_cb function called once transmission is done |
312 | * (not called if @a target disconnects, then only the | 288 | * (not called if @a target disconnects, then only the |
313 | * disconnect_cb is called). | 289 | * disconnect_cb is called). |
314 | * @param finished_cb_cls closure for @a finished_cb | 290 | * @param finished_cb_cls closure for @a finished_cb |
315 | */ | 291 | */ |
316 | void | 292 | void |
@@ -320,7 +296,7 @@ struct GNUNET_DHTU_PluginFunctions | |||
320 | size_t msg_size, | 296 | size_t msg_size, |
321 | GNUNET_SCHEDULER_TaskCallback finished_cb, | 297 | GNUNET_SCHEDULER_TaskCallback finished_cb, |
322 | void *finished_cb_cls); | 298 | void *finished_cb_cls); |
323 | 299 | ||
324 | }; | 300 | }; |
325 | 301 | ||
326 | 302 | ||