[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r26440 - gnunet/src/dv
From: |
gnunet |
Subject: |
[GNUnet-SVN] r26440 - gnunet/src/dv |
Date: |
Fri, 15 Mar 2013 10:08:13 +0100 |
Author: grothoff
Date: 2013-03-15 10:08:12 +0100 (Fri, 15 Mar 2013)
New Revision: 26440
Modified:
gnunet/src/dv/dv_api.c
gnunet/src/dv/gnunet-service-dv.c
gnunet/src/dv/gnunet_dv_service.h
gnunet/src/dv/plugin_transport_dv.c
Log:
-adding distance change notification from service to plugin
Modified: gnunet/src/dv/dv_api.c
===================================================================
--- gnunet/src/dv/dv_api.c 2013-03-15 09:07:30 UTC (rev 26439)
+++ gnunet/src/dv/dv_api.c 2013-03-15 09:08:12 UTC (rev 26440)
@@ -114,6 +114,11 @@
GNUNET_DV_ConnectCallback connect_cb;
/**
+ * Function to call on distance change events.
+ */
+ GNUNET_DV_DistanceChangedCallback distance_cb;
+
+ /**
* Function to call on disconnect events.
*/
GNUNET_DV_DisconnectCallback disconnect_cb;
@@ -288,6 +293,7 @@
{
struct GNUNET_DV_ServiceHandle *sh = cls;
const struct GNUNET_DV_ConnectMessage *cm;
+ const struct GNUNET_DV_DistanceUpdateMessage *dum;
const struct GNUNET_DV_DisconnectMessage *dm;
const struct GNUNET_DV_ReceivedMessage *rm;
const struct GNUNET_MessageHeader *payload;
@@ -314,6 +320,18 @@
&cm->peer,
ntohl (cm->distance));
break;
+ case GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED:
+ if (ntohs (msg->size) != sizeof (struct GNUNET_DV_DistanceUpdateMessage))
+ {
+ GNUNET_break (0);
+ reconnect (sh);
+ return;
+ }
+ dum = (const struct GNUNET_DV_DistanceUpdateMessage *) msg;
+ sh->distance_cb (sh->cls,
+ &dum->peer,
+ ntohl (dum->distance));
+ break;
case GNUNET_MESSAGE_TYPE_DV_DISCONNECT:
if (ntohs (msg->size) != sizeof (struct GNUNET_DV_DisconnectMessage))
{
@@ -361,9 +379,6 @@
&process_ack,
&ctx);
break;
- case GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED:
- GNUNET_break (0);
- break;
default:
reconnect (sh);
break;
@@ -478,6 +493,7 @@
* @param cfg configuration
* @param cls closure for callbacks
* @param connect_cb function to call on connects
+ * @param distance_cb function to call if distances change
* @param disconnect_cb function to call on disconnects
* @param message_cb function to call if we receive messages
* @return handle to access the service
@@ -486,6 +502,7 @@
GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
void *cls,
GNUNET_DV_ConnectCallback connect_cb,
+ GNUNET_DV_DistanceChangedCallback distance_cb,
GNUNET_DV_DisconnectCallback disconnect_cb,
GNUNET_DV_MessageReceivedCallback message_cb)
{
@@ -495,6 +512,7 @@
sh->cfg = cfg;
sh->cls = cls;
sh->connect_cb = connect_cb;
+ sh->distance_cb = distance_cb;
sh->disconnect_cb = disconnect_cb;
sh->message_cb = message_cb;
sh->send_callbacks = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES);
Modified: gnunet/src/dv/gnunet-service-dv.c
===================================================================
--- gnunet/src/dv/gnunet-service-dv.c 2013-03-15 09:07:30 UTC (rev 26439)
+++ gnunet/src/dv/gnunet-service-dv.c 2013-03-15 09:08:12 UTC (rev 26440)
@@ -28,8 +28,7 @@
* @author Nathan Evans
*
* TODO:
- * - distance updates are not properly communicate to US by core,
- * and conversely we don't give distance updates properly to the plugin yet
+ * - distance updates are not properly communicate to US by core/transport/ats
*/
#include "platform.h"
#include "gnunet_util_lib.h"
@@ -528,6 +527,29 @@
/**
+ * Send a DISTANCE_CHANGED message to the plugin.
+ *
+ * @param peer peer with a changed distance
+ * @param distance new distance to the peer
+ */
+static void
+send_distance_change_to_plugin (const struct GNUNET_PeerIdentity *peer,
+ uint32_t distance)
+{
+ struct GNUNET_DV_DistanceUpdateMessage du_msg;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Delivering DISTANCE_CHANGED for message about peer `%s'\n",
+ GNUNET_i2s (peer));
+ du_msg.header.size = htons (sizeof (du_msg));
+ du_msg.header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED);
+ du_msg.distance = htonl (distance);
+ du_msg.peer = *peer;
+ send_control_to_plugin (&du_msg.header);
+}
+
+
+/**
* Give a CONNECT message to the plugin.
*
* @param target peer that connected
@@ -875,7 +897,7 @@
/* this 'target' is cheaper than the existing route; switch to
alternative route! */
move_route (route, ntohl (target->distance) + 1);
route->next_hop = neighbor;
- // FIXME: notify plugin about distance update?
+ send_distance_change_to_plugin (&target->peer, ntohl (target->distance)
+ 1);
}
return GNUNET_YES; /* got a route to this target already */
}
@@ -985,14 +1007,14 @@
if (current_route->next_hop == neighbor)
{
/* we had the same route before, no change */
- if (ntohl (target->distance) != ntohl (current_route->target.distance))
+ if (ntohl (target->distance) + 1 != ntohl
(current_route->target.distance))
{
- current_route->target.distance = target->distance;
- // FIXME: notify about distance change...
+ current_route->target.distance = htonl (ntohl (target->distance) + 1);
+ send_distance_change_to_plugin (&target->peer, ntohl (target->distance)
+ 1);
}
return GNUNET_OK;
}
- if (ntohl (current_route->target.distance) >= ntohl (target->distance))
+ if (ntohl (current_route->target.distance) >= ntohl (target->distance) + 1)
{
/* alternative, shorter route exists, ignore */
return GNUNET_OK;
@@ -1003,8 +1025,8 @@
check that the shorter routes actually work, a malicious
direct neighbor can use this to DoS our long routes */
current_route->next_hop = neighbor;
- current_route->target.distance = target->distance;
- // FIXME: notify about distance change
+ current_route->target.distance = htonl (ntohl (target->distance) + 1);
+ send_distance_change_to_plugin (&target->peer, ntohl (target->distance) +
1);
return GNUNET_OK;
}
/* new route */
Modified: gnunet/src/dv/gnunet_dv_service.h
===================================================================
--- gnunet/src/dv/gnunet_dv_service.h 2013-03-15 09:07:30 UTC (rev 26439)
+++ gnunet/src/dv/gnunet_dv_service.h 2013-03-15 09:08:12 UTC (rev 26440)
@@ -40,6 +40,15 @@
/**
* Signature of a function to be called if DV
+ * distance to a peer is changed.
+ */
+typedef void (*GNUNET_DV_DistanceChangedCallback)(void *cls,
+ const struct
GNUNET_PeerIdentity *peer,
+ uint32_t distance);
+
+
+/**
+ * Signature of a function to be called if DV
* is no longer able to talk to a peer.
*/
typedef void (*GNUNET_DV_DisconnectCallback)(void *cls,
@@ -84,6 +93,7 @@
* @param cfg configuration
* @param cls closure for callbacks
* @param connect_cb function to call on connects
+ * @param distance_cb function to call if distances change
* @param disconnect_cb function to call on disconnects
* @param message_cb function to call if we receive messages
* @return handle to access the service
@@ -92,6 +102,7 @@
GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
void *cls,
GNUNET_DV_ConnectCallback connect_cb,
+ GNUNET_DV_DistanceChangedCallback distance_cb,
GNUNET_DV_DisconnectCallback disconnect_cb,
GNUNET_DV_MessageReceivedCallback message_cb);
Modified: gnunet/src/dv/plugin_transport_dv.c
===================================================================
--- gnunet/src/dv/plugin_transport_dv.c 2013-03-15 09:07:30 UTC (rev 26439)
+++ gnunet/src/dv/plugin_transport_dv.c 2013-03-15 09:08:12 UTC (rev 26440)
@@ -309,7 +309,7 @@
plugin->env = env;
plugin->dvh = GNUNET_DV_service_connect (env->cfg,
plugin,
- NULL, NULL, /*FIXME! */
+ NULL, NULL, NULL, /*FIXME! */
&handle_dv_message_received);
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
api->cls = plugin;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r26440 - gnunet/src/dv,
gnunet <=