diff options
Diffstat (limited to 'src/dhtu')
-rw-r--r-- | src/dhtu/Makefile.am | 12 | ||||
-rw-r--r-- | src/dhtu/plugin_dhtu_gnunet.c | 163 | ||||
-rw-r--r-- | src/dhtu/plugin_dhtu_ip.c | 4 |
3 files changed, 156 insertions, 23 deletions
diff --git a/src/dhtu/Makefile.am b/src/dhtu/Makefile.am index 72b422812..f4b968526 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,14 @@ 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/core/libgnunetcore.la \ | ||
32 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
33 | $(XLIBS) \ | ||
34 | $(LTLIBINTL) | ||
35 | libgnunet_plugin_dhtu_gnunet_la_LDFLAGS = \ | ||
36 | $(GN_PLUGIN_LDFLAGS) | ||
diff --git a/src/dhtu/plugin_dhtu_gnunet.c b/src/dhtu/plugin_dhtu_gnunet.c index d6cd75242..ccd329e8e 100644 --- a/src/dhtu/plugin_dhtu_gnunet.c +++ b/src/dhtu/plugin_dhtu_gnunet.c | |||
@@ -21,11 +21,44 @@ | |||
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 | #include "gnunet_core_service.h" | ||
30 | |||
31 | /** | ||
32 | * Handle for a private key used by this underlay. | ||
33 | */ | ||
34 | struct GNUNET_DHTU_PrivateKey | ||
35 | { | ||
36 | /** | ||
37 | * GNUnet uses eddsa for peers. | ||
38 | */ | ||
39 | struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_priv; | ||
40 | |||
41 | }; | ||
42 | |||
43 | |||
44 | /** | ||
45 | * Handle for a public key used by this underlay. | ||
46 | */ | ||
47 | struct PublicKey | ||
48 | { | ||
49 | |||
50 | /** | ||
51 | * Header. | ||
52 | */ | ||
53 | struct GNUNET_DHTU_PublicKey header; | ||
54 | |||
55 | /** | ||
56 | * GNUnet uses eddsa for peers. | ||
57 | */ | ||
58 | struct GNUNET_CRYPTO_EddsaPublicKey eddsa_pub; | ||
59 | |||
60 | }; | ||
61 | |||
29 | 62 | ||
30 | /** | 63 | /** |
31 | * Opaque handle that the underlay offers for our address to be used when | 64 | * Opaque handle that the underlay offers for our address to be used when |
@@ -47,7 +80,7 @@ struct GNUNET_DHTU_Source | |||
47 | */ | 80 | */ |
48 | struct GNUNET_DHTU_Target | 81 | struct GNUNET_DHTU_Target |
49 | { | 82 | { |
50 | 83 | ||
51 | /** | 84 | /** |
52 | * Application context for this target. | 85 | * Application context for this target. |
53 | */ | 86 | */ |
@@ -94,23 +127,20 @@ struct GNUNET_DHTU_PreferenceHandle | |||
94 | 127 | ||
95 | 128 | ||
96 | /** | 129 | /** |
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. | 130 | * Closure for all plugin functions. |
107 | */ | 131 | */ |
108 | struct Plugin | 132 | struct Plugin |
109 | { | 133 | { |
110 | /** | 134 | /** |
111 | * Callbacks into the DHT. | 135 | * Callbacks into the DHT. |
112 | */ | 136 | */ |
113 | struct GNUNET_DHTU_PluginEnvironment *env; | 137 | struct GNUNET_DHTU_PluginEnvironment *env; |
138 | |||
139 | /** | ||
140 | * Handle to the CORE service. | ||
141 | */ | ||
142 | struct GNUNET_CORE_Handle *core; | ||
143 | |||
114 | }; | 144 | }; |
115 | 145 | ||
116 | 146 | ||
@@ -126,10 +156,17 @@ struct Plugin | |||
126 | static ssize_t | 156 | static ssize_t |
127 | ip_sign (void *cls, | 157 | ip_sign (void *cls, |
128 | const struct GNUNET_DHTU_PrivateKey *pk, | 158 | const struct GNUNET_DHTU_PrivateKey *pk, |
129 | const struct GNUNET_DHTU_SignaturePurpose *purpose, | 159 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
130 | void **sig) | 160 | void **sig) |
131 | { | 161 | { |
132 | return 0; | 162 | struct GNUNET_CRYPTO_EddsaSignature *es; |
163 | |||
164 | es = GNUNET_new (struct GNUNET_CRYPTO_EddsaSignature); | ||
165 | GNUNET_CRYPTO_eddsa_sign_ (&pk->eddsa_priv, | ||
166 | purpose, | ||
167 | es); | ||
168 | *sig = es; | ||
169 | return sizeof (*es); | ||
133 | } | 170 | } |
134 | 171 | ||
135 | 172 | ||
@@ -148,11 +185,31 @@ ip_sign (void *cls, | |||
148 | static enum GNUNET_GenericReturnValue | 185 | static enum GNUNET_GenericReturnValue |
149 | ip_verify (void *cls, | 186 | ip_verify (void *cls, |
150 | const struct GNUNET_DHTU_PublicKey *pk, | 187 | const struct GNUNET_DHTU_PublicKey *pk, |
151 | const struct GNUNET_DHTU_SignaturePurpose *purpose, | 188 | const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, |
152 | const void *sig, | 189 | const void *sig, |
153 | size_t sig_size) | 190 | size_t sig_size) |
154 | { | 191 | { |
155 | return GNUNET_NO; | 192 | const struct GNUNET_CRYPTO_EddsaSignature *es = sig; |
193 | const struct PublicKey *pub; | ||
194 | |||
195 | GNUNET_assert (sizeof (struct PublicKey) == | ||
196 | ntohs (pk->size)); | ||
197 | pub = (const struct PublicKey *) pk; | ||
198 | if (sizeof (*es) != sig_size) | ||
199 | { | ||
200 | GNUNET_break_op (0); | ||
201 | return GNUNET_SYSERR; | ||
202 | } | ||
203 | if (GNUNET_OK != | ||
204 | GNUNET_CRYPTO_eddsa_verify_ (ntohl (purpose->purpose), | ||
205 | purpose, | ||
206 | es, | ||
207 | &pub->eddsa_pub)) | ||
208 | { | ||
209 | GNUNET_break_op (0); | ||
210 | return GNUNET_SYSERR; | ||
211 | } | ||
212 | return GNUNET_OK; | ||
156 | } | 213 | } |
157 | 214 | ||
158 | 215 | ||
@@ -174,7 +231,7 @@ ip_try_connect (void *cls, | |||
174 | * Request underlay to keep the connection to @a target alive if possible. | 231 | * 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 | 232 | * 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. | 233 | * keep a connection, say because a @a target is in multiple tables. |
177 | * | 234 | * |
178 | * @param cls closure | 235 | * @param cls closure |
179 | * @param target connection to keep alive | 236 | * @param target connection to keep alive |
180 | */ | 237 | */ |
@@ -196,7 +253,7 @@ ip_hold (void *cls, | |||
196 | 253 | ||
197 | /** | 254 | /** |
198 | * Do no long request underlay to keep the connection alive. | 255 | * Do no long request underlay to keep the connection alive. |
199 | * | 256 | * |
200 | * @param cls closure | 257 | * @param cls closure |
201 | * @param target connection to keep alive | 258 | * @param target connection to keep alive |
202 | */ | 259 | */ |
@@ -204,7 +261,7 @@ static void | |||
204 | ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) | 261 | ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) |
205 | { | 262 | { |
206 | struct GNUNET_DHTU_Target *target = ph->target; | 263 | struct GNUNET_DHTU_Target *target = ph->target; |
207 | 264 | ||
208 | GNUNET_CONTAINER_DLL_remove (target->ph_head, | 265 | GNUNET_CONTAINER_DLL_remove (target->ph_head, |
209 | target->ph_tail, | 266 | target->ph_tail, |
210 | ph); | 267 | ph); |
@@ -225,7 +282,7 @@ ip_drop (struct GNUNET_DHTU_PreferenceHandle *ph) | |||
225 | * @param msg_size number of bytes in @a msg | 282 | * @param msg_size number of bytes in @a msg |
226 | * @param finished_cb function called once transmission is done | 283 | * @param finished_cb function called once transmission is done |
227 | * (not called if @a target disconnects, then only the | 284 | * (not called if @a target disconnects, then only the |
228 | * disconnect_cb is called). | 285 | * disconnect_cb is called). |
229 | * @param finished_cb_cls closure for @a finished_cb | 286 | * @param finished_cb_cls closure for @a finished_cb |
230 | */ | 287 | */ |
231 | static void | 288 | static void |
@@ -240,6 +297,60 @@ ip_send (void *cls, | |||
240 | } | 297 | } |
241 | 298 | ||
242 | 299 | ||
300 | |||
301 | /** | ||
302 | * Method called whenever a given peer connects. | ||
303 | * | ||
304 | * @param cls closure | ||
305 | * @param peer peer identity this notification is about | ||
306 | * @return closure associated with @a peer. given to mq callbacks and | ||
307 | * #GNUNET_CORE_DisconnectEventHandler | ||
308 | */ | ||
309 | static void * | ||
310 | core_connect_cb (void *cls, | ||
311 | const struct GNUNET_PeerIdentity *peer, | ||
312 | struct GNUNET_MQ_Handle *mq) | ||
313 | { | ||
314 | return NULL; | ||
315 | } | ||
316 | |||
317 | |||
318 | /** | ||
319 | * Method called whenever a peer disconnects. | ||
320 | * | ||
321 | * @param cls closure | ||
322 | * @param peer peer identity this notification is about | ||
323 | * @param peer_cls closure associated with peer. given in | ||
324 | * #GNUNET_CORE_ConnectEventHandler | ||
325 | */ | ||
326 | static void | ||
327 | core_disconnect_cb (void *cls, | ||
328 | const struct GNUNET_PeerIdentity *peer, | ||
329 | void *peer_cls) | ||
330 | { | ||
331 | } | ||
332 | |||
333 | |||
334 | /** | ||
335 | * Function called after #GNUNET_CORE_connect has succeeded (or failed | ||
336 | * for good). Note that the private key of the peer is intentionally | ||
337 | * not exposed here; if you need it, your process should try to read | ||
338 | * the private key file directly (which should work if you are | ||
339 | * authorized...). Implementations of this function must not call | ||
340 | * #GNUNET_CORE_disconnect (other than by scheduling a new task to | ||
341 | * do this later). | ||
342 | * | ||
343 | * @param cls closure | ||
344 | * @param my_identity ID of this peer, NULL if we failed | ||
345 | */ | ||
346 | static void | ||
347 | core_init_cb (void *cls, | ||
348 | const struct GNUNET_PeerIdentity *my_identity) | ||
349 | { | ||
350 | struct Plugin *plugin = cls; | ||
351 | } | ||
352 | |||
353 | |||
243 | /** | 354 | /** |
244 | * Entry point for the plugin. | 355 | * Entry point for the plugin. |
245 | * | 356 | * |
@@ -252,6 +363,9 @@ libgnunet_plugin_dhtu_ip_init (void *cls) | |||
252 | struct GNUNET_DHTU_PluginEnvironment *env = cls; | 363 | struct GNUNET_DHTU_PluginEnvironment *env = cls; |
253 | struct GNUNET_DHTU_PluginFunctions *api; | 364 | struct GNUNET_DHTU_PluginFunctions *api; |
254 | struct Plugin *plugin; | 365 | struct Plugin *plugin; |
366 | struct GNUNET_MQ_MessageHandler handlers[] = { | ||
367 | GNUNET_MQ_handler_end () | ||
368 | }; | ||
255 | 369 | ||
256 | plugin = GNUNET_new (struct Plugin); | 370 | plugin = GNUNET_new (struct Plugin); |
257 | plugin->env = env; | 371 | plugin->env = env; |
@@ -263,6 +377,12 @@ libgnunet_plugin_dhtu_ip_init (void *cls) | |||
263 | api->hold = &ip_hold; | 377 | api->hold = &ip_hold; |
264 | api->drop = &ip_drop; | 378 | api->drop = &ip_drop; |
265 | api->send = &ip_send; | 379 | api->send = &ip_send; |
380 | plugin->core = GNUNET_CORE_connect (env->cfg, | ||
381 | plugin, | ||
382 | &core_init_cb, | ||
383 | &core_connect_cb, | ||
384 | &core_disconnect_cb, | ||
385 | handlers); | ||
266 | return api; | 386 | return api; |
267 | } | 387 | } |
268 | 388 | ||
@@ -279,6 +399,7 @@ libgnunet_plugin_dhtu_gnunet_done (void *cls) | |||
279 | struct GNUNET_DHTU_PluginFunctions *api = cls; | 399 | struct GNUNET_DHTU_PluginFunctions *api = cls; |
280 | struct Plugin *plugin = api->cls; | 400 | struct Plugin *plugin = api->cls; |
281 | 401 | ||
402 | GNUNET_CORE_disconnect (plugin->core); | ||
282 | GNUNET_free (plugin); | 403 | GNUNET_free (plugin); |
283 | GNUNET_free (api); | 404 | GNUNET_free (api); |
284 | return NULL; | 405 | return NULL; |
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 | { |