aboutsummaryrefslogtreecommitdiff
path: root/src/dv
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-03-15 09:08:12 +0000
committerChristian Grothoff <christian@grothoff.org>2013-03-15 09:08:12 +0000
commitfef4792abec19870be63c7922ada0ebd4397a7c1 (patch)
tree5fa28540da5def61fbba9fc23113164b1ea1f082 /src/dv
parenteb11823bf308688976715a0cb95e98b34c811c72 (diff)
downloadgnunet-fef4792abec19870be63c7922ada0ebd4397a7c1.tar.gz
gnunet-fef4792abec19870be63c7922ada0ebd4397a7c1.zip
-adding distance change notification from service to plugin
Diffstat (limited to 'src/dv')
-rw-r--r--src/dv/dv_api.c24
-rw-r--r--src/dv/gnunet-service-dv.c40
-rw-r--r--src/dv/gnunet_dv_service.h11
-rw-r--r--src/dv/plugin_transport_dv.c2
4 files changed, 64 insertions, 13 deletions
diff --git a/src/dv/dv_api.c b/src/dv/dv_api.c
index dab7c7ad3..ecc13941b 100644
--- a/src/dv/dv_api.c
+++ b/src/dv/dv_api.c
@@ -114,6 +114,11 @@ struct GNUNET_DV_ServiceHandle
114 GNUNET_DV_ConnectCallback connect_cb; 114 GNUNET_DV_ConnectCallback connect_cb;
115 115
116 /** 116 /**
117 * Function to call on distance change events.
118 */
119 GNUNET_DV_DistanceChangedCallback distance_cb;
120
121 /**
117 * Function to call on disconnect events. 122 * Function to call on disconnect events.
118 */ 123 */
119 GNUNET_DV_DisconnectCallback disconnect_cb; 124 GNUNET_DV_DisconnectCallback disconnect_cb;
@@ -288,6 +293,7 @@ handle_message_receipt (void *cls,
288{ 293{
289 struct GNUNET_DV_ServiceHandle *sh = cls; 294 struct GNUNET_DV_ServiceHandle *sh = cls;
290 const struct GNUNET_DV_ConnectMessage *cm; 295 const struct GNUNET_DV_ConnectMessage *cm;
296 const struct GNUNET_DV_DistanceUpdateMessage *dum;
291 const struct GNUNET_DV_DisconnectMessage *dm; 297 const struct GNUNET_DV_DisconnectMessage *dm;
292 const struct GNUNET_DV_ReceivedMessage *rm; 298 const struct GNUNET_DV_ReceivedMessage *rm;
293 const struct GNUNET_MessageHeader *payload; 299 const struct GNUNET_MessageHeader *payload;
@@ -314,6 +320,18 @@ handle_message_receipt (void *cls,
314 &cm->peer, 320 &cm->peer,
315 ntohl (cm->distance)); 321 ntohl (cm->distance));
316 break; 322 break;
323 case GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED:
324 if (ntohs (msg->size) != sizeof (struct GNUNET_DV_DistanceUpdateMessage))
325 {
326 GNUNET_break (0);
327 reconnect (sh);
328 return;
329 }
330 dum = (const struct GNUNET_DV_DistanceUpdateMessage *) msg;
331 sh->distance_cb (sh->cls,
332 &dum->peer,
333 ntohl (dum->distance));
334 break;
317 case GNUNET_MESSAGE_TYPE_DV_DISCONNECT: 335 case GNUNET_MESSAGE_TYPE_DV_DISCONNECT:
318 if (ntohs (msg->size) != sizeof (struct GNUNET_DV_DisconnectMessage)) 336 if (ntohs (msg->size) != sizeof (struct GNUNET_DV_DisconnectMessage))
319 { 337 {
@@ -361,9 +379,6 @@ handle_message_receipt (void *cls,
361 &process_ack, 379 &process_ack,
362 &ctx); 380 &ctx);
363 break; 381 break;
364 case GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED:
365 GNUNET_break (0);
366 break;
367 default: 382 default:
368 reconnect (sh); 383 reconnect (sh);
369 break; 384 break;
@@ -478,6 +493,7 @@ reconnect (struct GNUNET_DV_ServiceHandle *sh)
478 * @param cfg configuration 493 * @param cfg configuration
479 * @param cls closure for callbacks 494 * @param cls closure for callbacks
480 * @param connect_cb function to call on connects 495 * @param connect_cb function to call on connects
496 * @param distance_cb function to call if distances change
481 * @param disconnect_cb function to call on disconnects 497 * @param disconnect_cb function to call on disconnects
482 * @param message_cb function to call if we receive messages 498 * @param message_cb function to call if we receive messages
483 * @return handle to access the service 499 * @return handle to access the service
@@ -486,6 +502,7 @@ struct GNUNET_DV_ServiceHandle *
486GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 502GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
487 void *cls, 503 void *cls,
488 GNUNET_DV_ConnectCallback connect_cb, 504 GNUNET_DV_ConnectCallback connect_cb,
505 GNUNET_DV_DistanceChangedCallback distance_cb,
489 GNUNET_DV_DisconnectCallback disconnect_cb, 506 GNUNET_DV_DisconnectCallback disconnect_cb,
490 GNUNET_DV_MessageReceivedCallback message_cb) 507 GNUNET_DV_MessageReceivedCallback message_cb)
491{ 508{
@@ -495,6 +512,7 @@ GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
495 sh->cfg = cfg; 512 sh->cfg = cfg;
496 sh->cls = cls; 513 sh->cls = cls;
497 sh->connect_cb = connect_cb; 514 sh->connect_cb = connect_cb;
515 sh->distance_cb = distance_cb;
498 sh->disconnect_cb = disconnect_cb; 516 sh->disconnect_cb = disconnect_cb;
499 sh->message_cb = message_cb; 517 sh->message_cb = message_cb;
500 sh->send_callbacks = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES); 518 sh->send_callbacks = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES);
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index e6c107981..23fff3f3b 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -28,8 +28,7 @@
28 * @author Nathan Evans 28 * @author Nathan Evans
29 * 29 *
30 * TODO: 30 * TODO:
31 * - distance updates are not properly communicate to US by core, 31 * - distance updates are not properly communicate to US by core/transport/ats
32 * and conversely we don't give distance updates properly to the plugin yet
33 */ 32 */
34#include "platform.h" 33#include "platform.h"
35#include "gnunet_util_lib.h" 34#include "gnunet_util_lib.h"
@@ -528,6 +527,29 @@ send_ack_to_plugin (const struct GNUNET_PeerIdentity *target,
528 527
529 528
530/** 529/**
530 * Send a DISTANCE_CHANGED message to the plugin.
531 *
532 * @param peer peer with a changed distance
533 * @param distance new distance to the peer
534 */
535static void
536send_distance_change_to_plugin (const struct GNUNET_PeerIdentity *peer,
537 uint32_t distance)
538{
539 struct GNUNET_DV_DistanceUpdateMessage du_msg;
540
541 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
542 "Delivering DISTANCE_CHANGED for message about peer `%s'\n",
543 GNUNET_i2s (peer));
544 du_msg.header.size = htons (sizeof (du_msg));
545 du_msg.header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED);
546 du_msg.distance = htonl (distance);
547 du_msg.peer = *peer;
548 send_control_to_plugin (&du_msg.header);
549}
550
551
552/**
531 * Give a CONNECT message to the plugin. 553 * Give a CONNECT message to the plugin.
532 * 554 *
533 * @param target peer that connected 555 * @param target peer that connected
@@ -875,7 +897,7 @@ check_possible_route (void *cls, const struct GNUNET_HashCode * key, void *value
875 /* this 'target' is cheaper than the existing route; switch to alternative route! */ 897 /* this 'target' is cheaper than the existing route; switch to alternative route! */
876 move_route (route, ntohl (target->distance) + 1); 898 move_route (route, ntohl (target->distance) + 1);
877 route->next_hop = neighbor; 899 route->next_hop = neighbor;
878 // FIXME: notify plugin about distance update? 900 send_distance_change_to_plugin (&target->peer, ntohl (target->distance) + 1);
879 } 901 }
880 return GNUNET_YES; /* got a route to this target already */ 902 return GNUNET_YES; /* got a route to this target already */
881 } 903 }
@@ -985,14 +1007,14 @@ check_target_added (void *cls,
985 if (current_route->next_hop == neighbor) 1007 if (current_route->next_hop == neighbor)
986 { 1008 {
987 /* we had the same route before, no change */ 1009 /* we had the same route before, no change */
988 if (ntohl (target->distance) != ntohl (current_route->target.distance)) 1010 if (ntohl (target->distance) + 1 != ntohl (current_route->target.distance))
989 { 1011 {
990 current_route->target.distance = target->distance; 1012 current_route->target.distance = htonl (ntohl (target->distance) + 1);
991 // FIXME: notify about distance change... 1013 send_distance_change_to_plugin (&target->peer, ntohl (target->distance) + 1);
992 } 1014 }
993 return GNUNET_OK; 1015 return GNUNET_OK;
994 } 1016 }
995 if (ntohl (current_route->target.distance) >= ntohl (target->distance)) 1017 if (ntohl (current_route->target.distance) >= ntohl (target->distance) + 1)
996 { 1018 {
997 /* alternative, shorter route exists, ignore */ 1019 /* alternative, shorter route exists, ignore */
998 return GNUNET_OK; 1020 return GNUNET_OK;
@@ -1003,8 +1025,8 @@ check_target_added (void *cls,
1003 check that the shorter routes actually work, a malicious 1025 check that the shorter routes actually work, a malicious
1004 direct neighbor can use this to DoS our long routes */ 1026 direct neighbor can use this to DoS our long routes */
1005 current_route->next_hop = neighbor; 1027 current_route->next_hop = neighbor;
1006 current_route->target.distance = target->distance; 1028 current_route->target.distance = htonl (ntohl (target->distance) + 1);
1007 // FIXME: notify about distance change 1029 send_distance_change_to_plugin (&target->peer, ntohl (target->distance) + 1);
1008 return GNUNET_OK; 1030 return GNUNET_OK;
1009 } 1031 }
1010 /* new route */ 1032 /* new route */
diff --git a/src/dv/gnunet_dv_service.h b/src/dv/gnunet_dv_service.h
index 7bdb17858..ebb84c2e2 100644
--- a/src/dv/gnunet_dv_service.h
+++ b/src/dv/gnunet_dv_service.h
@@ -40,6 +40,15 @@ typedef void (*GNUNET_DV_ConnectCallback)(void *cls,
40 40
41/** 41/**
42 * Signature of a function to be called if DV 42 * Signature of a function to be called if DV
43 * distance to a peer is changed.
44 */
45typedef void (*GNUNET_DV_DistanceChangedCallback)(void *cls,
46 const struct GNUNET_PeerIdentity *peer,
47 uint32_t distance);
48
49
50/**
51 * Signature of a function to be called if DV
43 * is no longer able to talk to a peer. 52 * is no longer able to talk to a peer.
44 */ 53 */
45typedef void (*GNUNET_DV_DisconnectCallback)(void *cls, 54typedef void (*GNUNET_DV_DisconnectCallback)(void *cls,
@@ -84,6 +93,7 @@ struct GNUNET_DV_ServiceHandle;
84 * @param cfg configuration 93 * @param cfg configuration
85 * @param cls closure for callbacks 94 * @param cls closure for callbacks
86 * @param connect_cb function to call on connects 95 * @param connect_cb function to call on connects
96 * @param distance_cb function to call if distances change
87 * @param disconnect_cb function to call on disconnects 97 * @param disconnect_cb function to call on disconnects
88 * @param message_cb function to call if we receive messages 98 * @param message_cb function to call if we receive messages
89 * @return handle to access the service 99 * @return handle to access the service
@@ -92,6 +102,7 @@ struct GNUNET_DV_ServiceHandle *
92GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 102GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
93 void *cls, 103 void *cls,
94 GNUNET_DV_ConnectCallback connect_cb, 104 GNUNET_DV_ConnectCallback connect_cb,
105 GNUNET_DV_DistanceChangedCallback distance_cb,
95 GNUNET_DV_DisconnectCallback disconnect_cb, 106 GNUNET_DV_DisconnectCallback disconnect_cb,
96 GNUNET_DV_MessageReceivedCallback message_cb); 107 GNUNET_DV_MessageReceivedCallback message_cb);
97 108
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c
index ef8456b55..c07fc52de 100644
--- a/src/dv/plugin_transport_dv.c
+++ b/src/dv/plugin_transport_dv.c
@@ -309,7 +309,7 @@ libgnunet_plugin_transport_dv_init (void *cls)
309 plugin->env = env; 309 plugin->env = env;
310 plugin->dvh = GNUNET_DV_service_connect (env->cfg, 310 plugin->dvh = GNUNET_DV_service_connect (env->cfg,
311 plugin, 311 plugin,
312 NULL, NULL, /*FIXME! */ 312 NULL, NULL, NULL, /*FIXME! */
313 &handle_dv_message_received); 313 &handle_dv_message_received);
314 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); 314 api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
315 api->cls = plugin; 315 api->cls = plugin;