diff options
Diffstat (limited to 'src/dv/plugin_transport_dv.c')
-rw-r--r-- | src/dv/plugin_transport_dv.c | 170 |
1 files changed, 31 insertions, 139 deletions
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c index 3a8bafcef..ef8456b55 100644 --- a/src/dv/plugin_transport_dv.c +++ b/src/dv/plugin_transport_dv.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2002--2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -114,21 +114,11 @@ struct Plugin | |||
114 | struct GNUNET_TRANSPORT_PluginEnvironment *env; | 114 | struct GNUNET_TRANSPORT_PluginEnvironment *env; |
115 | 115 | ||
116 | /** | 116 | /** |
117 | * List of open sessions. | 117 | * List of open sessions. FIXME: use hash map! |
118 | */ | 118 | */ |
119 | struct Session *sessions; | 119 | struct Session *sessions; |
120 | 120 | ||
121 | /** | 121 | /** |
122 | * Our server. | ||
123 | */ | ||
124 | //struct GNUNET_SERVER_Handle *server; | ||
125 | |||
126 | /* | ||
127 | * Handle to the running service. | ||
128 | */ | ||
129 | //struct GNUNET_SERVICE_Context *service; | ||
130 | |||
131 | /** | ||
132 | * Copy of the handler array where the closures are | 122 | * Copy of the handler array where the closures are |
133 | * set to this struct's instance. | 123 | * set to this struct's instance. |
134 | */ | 124 | */ |
@@ -137,53 +127,35 @@ struct Plugin | |||
137 | /** | 127 | /** |
138 | * Handle to the DV service | 128 | * Handle to the DV service |
139 | */ | 129 | */ |
140 | struct GNUNET_DV_Handle *dv_handle; | 130 | struct GNUNET_DV_ServiceHandle *dvh; |
141 | 131 | ||
142 | }; | 132 | }; |
143 | 133 | ||
134 | |||
144 | /** | 135 | /** |
145 | * Handler for messages received from the DV service. | 136 | * Handler for messages received from the DV service. |
137 | * | ||
138 | * @param cls closure with the plugin | ||
139 | * @param sender sender of the message | ||
140 | * @param distance how far did the message travel | ||
141 | * @param msg actual message payload | ||
146 | */ | 142 | */ |
147 | void | 143 | static void |
148 | handle_dv_message_received (void *cls, struct GNUNET_PeerIdentity *sender, | 144 | handle_dv_message_received (void *cls, |
149 | char *msg, size_t msg_len, uint32_t distance, | 145 | const struct GNUNET_PeerIdentity *sender, |
150 | char *sender_address, size_t sender_address_len) | 146 | uint32_t distance, |
147 | const struct GNUNET_MessageHeader *msg) | ||
151 | { | 148 | { |
152 | struct Plugin *plugin = cls; | 149 | struct Plugin *plugin = cls; |
150 | struct GNUNET_ATS_Information ats; | ||
153 | 151 | ||
154 | #if DEBUG_DV_MESSAGES | 152 | ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); |
155 | char *my_id; | 153 | ats.value = htonl (distance); |
156 | |||
157 | my_id = GNUNET_strdup (GNUNET_i2s (plugin->env->my_identity)); | ||
158 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "plugin_transport_dv", | ||
159 | _("%s Received message from %s of type %d, distance %u!\n"), | ||
160 | my_id, GNUNET_i2s (sender), | ||
161 | ntohs (((struct GNUNET_MessageHeader *) msg)->type), | ||
162 | distance); | ||
163 | if (sender_address_len == (2 * sizeof (struct GNUNET_PeerIdentity))) | ||
164 | { | ||
165 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "plugin_transport_dv", | ||
166 | "Parsed sender address: %s:%s\n", | ||
167 | GNUNET_i2s ((struct GNUNET_PeerIdentity *) sender_address), | ||
168 | GNUNET_h2s (& | ||
169 | ((struct GNUNET_PeerIdentity *) | ||
170 | &sender_address[sizeof | ||
171 | (struct | ||
172 | GNUNET_PeerIdentity)])->hashPubKey)); | ||
173 | } | ||
174 | |||
175 | GNUNET_free_non_null (my_id); | ||
176 | #endif | ||
177 | struct GNUNET_ATS_Information ats[1]; | ||
178 | |||
179 | ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); | ||
180 | ats[0].value = htonl (distance); | ||
181 | 154 | ||
182 | plugin->env->receive (plugin->env->cls, sender, | 155 | plugin->env->receive (plugin->env->cls, sender, |
183 | (struct GNUNET_MessageHeader *) msg, | 156 | msg, |
184 | (const struct GNUNET_ATS_Information *) &ats, 1, NULL, | 157 | &ats, 1, |
185 | sender_address, sender_address_len); | 158 | NULL, NULL, 0); |
186 | |||
187 | } | 159 | } |
188 | 160 | ||
189 | 161 | ||
@@ -219,14 +191,7 @@ dv_plugin_send (void *cls, | |||
219 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) | 191 | GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) |
220 | { | 192 | { |
221 | int ret = -1; | 193 | int ret = -1; |
222 | #if 0 | ||
223 | struct Plugin *plugin = cls; | ||
224 | 194 | ||
225 | ret = | ||
226 | GNUNET_DV_send (plugin->dv_handle, &session->sender, | ||
227 | msgbuf, msgbuf_size, priority, | ||
228 | timeout, addr, addrlen, cont, cont_cls); | ||
229 | #endif | ||
230 | return ret; | 195 | return ret; |
231 | } | 196 | } |
232 | 197 | ||
@@ -269,33 +234,10 @@ dv_plugin_address_pretty_printer (void *cls, const char *type, const void *addr, | |||
269 | GNUNET_TRANSPORT_AddressStringCallback asc, | 234 | GNUNET_TRANSPORT_AddressStringCallback asc, |
270 | void *asc_cls) | 235 | void *asc_cls) |
271 | { | 236 | { |
272 | char *dest_peer; | 237 | asc (asc_cls, NULL); |
273 | char *via_peer; | ||
274 | char *print_string; | ||
275 | char *addr_buf = (char *) addr; | ||
276 | |||
277 | if (addrlen != sizeof (struct GNUNET_PeerIdentity) * 2) | ||
278 | { | ||
279 | asc (asc_cls, NULL); | ||
280 | } | ||
281 | else | ||
282 | { | ||
283 | dest_peer = | ||
284 | GNUNET_strdup (GNUNET_i2s ((struct GNUNET_PeerIdentity *) addr)); | ||
285 | via_peer = | ||
286 | GNUNET_strdup (GNUNET_i2s | ||
287 | ((struct GNUNET_PeerIdentity *) | ||
288 | &addr_buf[sizeof (struct GNUNET_PeerIdentity)])); | ||
289 | GNUNET_asprintf (&print_string, "DV Peer `%s' via peer`%s'", dest_peer, | ||
290 | via_peer); | ||
291 | asc (asc_cls, print_string); | ||
292 | asc (asc_cls, NULL); | ||
293 | GNUNET_free (via_peer); | ||
294 | GNUNET_free (dest_peer); | ||
295 | GNUNET_free (print_string); | ||
296 | } | ||
297 | } | 238 | } |
298 | 239 | ||
240 | |||
299 | /** | 241 | /** |
300 | * Convert the DV address to a pretty string. | 242 | * Convert the DV address to a pretty string. |
301 | * | 243 | * |
@@ -308,34 +250,10 @@ dv_plugin_address_pretty_printer (void *cls, const char *type, const void *addr, | |||
308 | static const char * | 250 | static const char * |
309 | address_to_string (void *cls, const void *addr, size_t addrlen) | 251 | address_to_string (void *cls, const void *addr, size_t addrlen) |
310 | { | 252 | { |
311 | static char return_buffer[2 * 4 + 2]; // Two four character peer identity prefixes a ':' and '\0' | 253 | return "<not implemented>"; |
312 | |||
313 | struct GNUNET_CRYPTO_HashAsciiEncoded peer_hash; | ||
314 | struct GNUNET_CRYPTO_HashAsciiEncoded via_hash; | ||
315 | struct GNUNET_PeerIdentity *peer; | ||
316 | struct GNUNET_PeerIdentity *via; | ||
317 | char *addr_buf = (char *) addr; | ||
318 | |||
319 | if (addrlen == (2 * sizeof (struct GNUNET_PeerIdentity))) | ||
320 | { | ||
321 | peer = (struct GNUNET_PeerIdentity *) addr_buf; | ||
322 | via = | ||
323 | (struct GNUNET_PeerIdentity *) | ||
324 | &addr_buf[sizeof (struct GNUNET_PeerIdentity)]; | ||
325 | |||
326 | GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &peer_hash); | ||
327 | peer_hash.encoding[4] = '\0'; | ||
328 | GNUNET_CRYPTO_hash_to_enc (&via->hashPubKey, &via_hash); | ||
329 | via_hash.encoding[4] = '\0'; | ||
330 | GNUNET_snprintf (return_buffer, sizeof (return_buffer), "%s:%s", &peer_hash, | ||
331 | &via_hash); | ||
332 | } | ||
333 | else | ||
334 | return NULL; | ||
335 | |||
336 | return return_buffer; | ||
337 | } | 254 | } |
338 | 255 | ||
256 | |||
339 | /** | 257 | /** |
340 | * Another peer has suggested an address for this peer and transport | 258 | * Another peer has suggested an address for this peer and transport |
341 | * plugin. Check that this could be a valid address. This function | 259 | * plugin. Check that this could be a valid address. This function |
@@ -355,26 +273,7 @@ address_to_string (void *cls, const void *addr, size_t addrlen) | |||
355 | static int | 273 | static int |
356 | dv_plugin_check_address (void *cls, const void *addr, size_t addrlen) | 274 | dv_plugin_check_address (void *cls, const void *addr, size_t addrlen) |
357 | { | 275 | { |
358 | struct Plugin *plugin = cls; | 276 | return GNUNET_SYSERR; |
359 | |||
360 | /* Verify that the first peer of this address matches our peer id! */ | ||
361 | if ((addrlen != (2 * sizeof (struct GNUNET_PeerIdentity))) || | ||
362 | (0 != | ||
363 | memcmp (addr, plugin->env->my_identity, | ||
364 | sizeof (struct GNUNET_PeerIdentity)))) | ||
365 | { | ||
366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
367 | "%s: Address not correct size or identity doesn't match ours!\n", | ||
368 | GNUNET_i2s (plugin->env->my_identity)); | ||
369 | if (addrlen == (2 * sizeof (struct GNUNET_PeerIdentity))) | ||
370 | { | ||
371 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Peer in address is %s\n", | ||
372 | GNUNET_i2s (addr)); | ||
373 | } | ||
374 | return GNUNET_SYSERR; | ||
375 | } | ||
376 | |||
377 | return GNUNET_OK; | ||
378 | } | 277 | } |
379 | 278 | ||
380 | 279 | ||
@@ -408,16 +307,10 @@ libgnunet_plugin_transport_dv_init (void *cls) | |||
408 | 307 | ||
409 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | 308 | plugin = GNUNET_malloc (sizeof (struct Plugin)); |
410 | plugin->env = env; | 309 | plugin->env = env; |
411 | 310 | plugin->dvh = GNUNET_DV_service_connect (env->cfg, | |
412 | plugin->dv_handle = | 311 | plugin, |
413 | GNUNET_DV_connect (env->cfg, &handle_dv_message_received, plugin); | 312 | NULL, NULL, /*FIXME! */ |
414 | 313 | &handle_dv_message_received); | |
415 | if (plugin->dv_handle == NULL) | ||
416 | { | ||
417 | GNUNET_free (plugin); | ||
418 | return NULL; | ||
419 | } | ||
420 | |||
421 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 314 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); |
422 | api->cls = plugin; | 315 | api->cls = plugin; |
423 | api->send = &dv_plugin_send; | 316 | api->send = &dv_plugin_send; |
@@ -425,6 +318,7 @@ libgnunet_plugin_transport_dv_init (void *cls) | |||
425 | api->address_pretty_printer = &dv_plugin_address_pretty_printer; | 318 | api->address_pretty_printer = &dv_plugin_address_pretty_printer; |
426 | api->check_address = &dv_plugin_check_address; | 319 | api->check_address = &dv_plugin_check_address; |
427 | api->address_to_string = &address_to_string; | 320 | api->address_to_string = &address_to_string; |
321 | api->string_to_address = NULL; /* FIXME */ | ||
428 | api->get_session = dv_get_session; | 322 | api->get_session = dv_get_session; |
429 | return api; | 323 | return api; |
430 | } | 324 | } |
@@ -439,9 +333,7 @@ libgnunet_plugin_transport_dv_done (void *cls) | |||
439 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; | 333 | struct GNUNET_TRANSPORT_PluginFunctions *api = cls; |
440 | struct Plugin *plugin = api->cls; | 334 | struct Plugin *plugin = api->cls; |
441 | 335 | ||
442 | if (plugin->dv_handle != NULL) | 336 | GNUNET_DV_service_disconnect (plugin->dvh); |
443 | GNUNET_DV_disconnect (plugin->dv_handle); | ||
444 | |||
445 | GNUNET_free (plugin); | 337 | GNUNET_free (plugin); |
446 | GNUNET_free (api); | 338 | GNUNET_free (api); |
447 | return NULL; | 339 | return NULL; |