[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r31010 - in gnunet/src: dv include
From: |
gnunet |
Subject: |
[GNUnet-SVN] r31010 - in gnunet/src: dv include |
Date: |
Tue, 3 Dec 2013 15:23:55 +0100 |
Author: wachs
Date: 2013-12-03 15:23:55 +0100 (Tue, 03 Dec 2013)
New Revision: 31010
Modified:
gnunet/src/dv/dv_api.c
gnunet/src/dv/gnunet-dv.c
gnunet/src/dv/gnunet-service-dv.c
gnunet/src/dv/plugin_transport_dv.c
gnunet/src/include/gnunet_dv_service.h
Log:
- fixing crash during shutdown
- adding network functionality
Modified: gnunet/src/dv/dv_api.c
===================================================================
--- gnunet/src/dv/dv_api.c 2013-12-03 12:31:38 UTC (rev 31009)
+++ gnunet/src/dv/dv_api.c 2013-12-03 14:23:55 UTC (rev 31010)
@@ -324,7 +324,7 @@
cm = (const struct GNUNET_DV_ConnectMessage *) msg;
sh->connect_cb (sh->cls,
&cm->peer,
- ntohl (cm->distance));
+ ntohl (cm->distance), ntohl (cm->network));
break;
case GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED:
if (ntohs (msg->size) != sizeof (struct GNUNET_DV_DistanceUpdateMessage))
Modified: gnunet/src/dv/gnunet-dv.c
===================================================================
--- gnunet/src/dv/gnunet-dv.c 2013-12-03 12:31:38 UTC (rev 31009)
+++ gnunet/src/dv/gnunet-dv.c 2013-12-03 14:23:55 UTC (rev 31010)
@@ -47,7 +47,7 @@
static void
connect_cb (void *cls,
const struct GNUNET_PeerIdentity *peer,
- uint32_t distance)
+ uint32_t distance, uint32_t network)
{
fprintf (stderr, "Connect: %s at %u\n",
GNUNET_i2s (peer),
Modified: gnunet/src/dv/gnunet-service-dv.c
===================================================================
--- gnunet/src/dv/gnunet-service-dv.c 2013-12-03 12:31:38 UTC (rev 31009)
+++ gnunet/src/dv/gnunet-service-dv.c 2013-12-03 14:23:55 UTC (rev 31010)
@@ -270,6 +270,11 @@
uint32_t distance;
/**
+ * The network this peer is in
+ */
+ uint32_t network;
+
+ /**
* Is this neighbor connected at the core level?
*/
int connected;
@@ -378,6 +383,7 @@
*/
static struct GNUNET_ATS_PerformanceHandle *ats;
+static int in_shutdown;
/**
* Start creating a new DV set union by initiating the connection.
@@ -521,21 +527,23 @@
*
* @param target peer that connected
* @param distance distance to the target
+ * @param the network the peer is in
*/
static void
send_connect_to_plugin (const struct GNUNET_PeerIdentity *target,
- uint32_t distance)
+ uint32_t distance, uint32_t network)
{
struct GNUNET_DV_ConnectMessage cm;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delivering CONNECT about peer `%s'\n",
- GNUNET_i2s (target));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Delivering CONNECT about peer `%s' with distance %u\n",
+ GNUNET_i2s (target), distance);
cm.header.size = htons (sizeof (cm));
cm.header.type = htons (GNUNET_MESSAGE_TYPE_DV_CONNECT);
cm.distance = htonl (distance);
+ cm.network = htonl (network);
cm.peer = *target;
- send_control_to_plugin (&cm.header);
+ //send_control_to_plugin (&cm.header);
}
@@ -602,6 +610,7 @@
GNUNET_free (pending);
off += msize;
}
+ GNUNET_assert (NULL != core_api);
if (NULL != dn->pm_head)
dn->cth =
GNUNET_CORE_notify_transmit_ready (core_api,
@@ -666,6 +675,7 @@
target->pm_tail,
pm);
target->pm_queue_size++;
+ GNUNET_assert (NULL != core_api);
if (NULL == target->cth)
target->cth = GNUNET_CORE_notify_transmit_ready (core_api,
GNUNET_YES /* cork */,
@@ -959,6 +969,7 @@
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
neighbor->connected = GNUNET_YES;
neighbor->distance = 0; /* unknown */
+ neighbor->network = GNUNET_ATS_NET_UNSPECIFIED;
}
@@ -1022,7 +1033,8 @@
&route->target.peer,
route,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
- send_connect_to_plugin (&route->target.peer, ntohl (target->distance));
+ send_connect_to_plugin (&route->target.peer, ntohl (target->distance),
+ neighbor->network);
return GNUNET_YES;
}
@@ -1069,13 +1081,32 @@
for (i = 0; i < atsi_count; i++)
if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DISTANCE)
- return (0 == ntohl (atsi->value)) ? DIRECT_NEIGHBOR_COST : ntohl
(atsi->value); // FIXME: 0 check should not be required once ATS is fixed!
+ return (0 == ntohl (atsi[i].value)) ? DIRECT_NEIGHBOR_COST : ntohl
(atsi[i].value); // FIXME: 0 check should not be required once ATS is fixed!
/* If we do not have explicit distance data, assume direct neighbor. */
return DIRECT_NEIGHBOR_COST;
}
/**
+ * Get network information from 'atsi'.
+ *
+ * @param atsi performance data
+ * @param atsi_count number of entries in atsi
+ * @return connected transport network
+ */
+static uint32_t
+get_atsi_network (const struct GNUNET_ATS_Information *atsi,
+ uint32_t atsi_count)
+{
+ uint32_t i;
+
+ for (i = 0; i < atsi_count; i++)
+ if (ntohl (atsi[i].type) == GNUNET_ATS_NETWORK_TYPE)
+ return ntohl (atsi[i].value);
+ return GNUNET_ATS_NET_UNSPECIFIED;
+}
+
+/**
* Multipeermap iterator for freeing routes that go via a particular
* neighbor that disconnected and is thus no longer available.
*
@@ -1193,10 +1224,13 @@
{
struct DirectNeighbor *neighbor;
uint32_t distance;
+ uint32_t network = GNUNET_ATS_NET_UNSPECIFIED;
if (GNUNET_NO == active)
return;
distance = get_atsi_distance (ats, ats_count);
+ network = get_atsi_network (ats, ats_count);
+
/*
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"ATS says distance to %s is %u\n",
@@ -1207,6 +1241,9 @@
&address->peer);
if (NULL != neighbor)
{
+ if (GNUNET_ATS_NET_UNSPECIFIED != network)
+ neighbor->network = network;
+
if ( (DIRECT_NEIGHBOR_COST == neighbor->distance) &&
(DIRECT_NEIGHBOR_COST == distance) )
return; /* no change */
@@ -1239,6 +1276,7 @@
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
neighbor->connected = GNUNET_NO; /* not yet */
neighbor->distance = distance;
+ neighbor->network = network;
}
@@ -1350,8 +1388,10 @@
¤t_route->target.peer,
current_route,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+
send_connect_to_plugin (¤t_route->target.peer,
- ntohl (current_route->target.distance));
+ ntohl (current_route->target.distance),
+ neighbor->network);
return GNUNET_OK;
}
@@ -1782,6 +1822,10 @@
-1, GNUNET_NO);
}
cleanup_neighbor (neighbor);
+
+ if (GNUNET_YES == in_shutdown)
+ return;
+
GNUNET_CONTAINER_multipeermap_iterate (direct_neighbors,
&refresh_routes,
NULL);
@@ -1842,7 +1886,9 @@
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
unsigned int i;
+ in_shutdown = GNUNET_YES;
+ GNUNET_assert (NULL != core_api);
GNUNET_CORE_disconnect (core_api);
core_api = NULL;
GNUNET_ATS_performance_done (ats);
@@ -1858,9 +1904,11 @@
GNUNET_SERVER_notification_context_destroy (nc);
nc = NULL;
for (i=0;i<DEFAULT_FISHEYE_DEPTH - 1;i++)
+ {
GNUNET_array_grow (consensi[i].targets,
consensi[i].array_length,
0);
+ }
}
@@ -1955,7 +2003,7 @@
0},
{NULL, NULL, 0, 0}
};
-
+ in_shutdown = GNUNET_NO;
cfg = c;
direct_neighbors = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO);
all_routes = GNUNET_CONTAINER_multipeermap_create (65536, GNUNET_NO);
@@ -1973,6 +2021,7 @@
if (NULL == ats)
{
GNUNET_CORE_disconnect (core_api);
+ core_api = NULL;
return;
}
nc = GNUNET_SERVER_notification_context_create (server,
Modified: gnunet/src/dv/plugin_transport_dv.c
===================================================================
--- gnunet/src/dv/plugin_transport_dv.c 2013-12-03 12:31:38 UTC (rev 31009)
+++ gnunet/src/dv/plugin_transport_dv.c 2013-12-03 14:23:55 UTC (rev 31010)
@@ -38,6 +38,7 @@
#define LOG(kind,...) GNUNET_log_from (kind, "transport-dv",__VA_ARGS__)
+#define PLUGIN_NAME "dv"
/**
* Encapsulation of all of the state of the plugin.
@@ -123,6 +124,11 @@
uint32_t distance;
/**
+ * Current network the next hop peer is located in
+ */
+ uint32_t network;
+
+ /**
* Does the transport service know about this session (and we thus
* need to call 'session_end' when it is released?)
*/
@@ -180,7 +186,7 @@
ats.value = htonl (session->distance);
plugin->env->update_address_metrics (plugin->env->cls,
&session->sender,
- "", 0,
+ NULL, 0,
session,
&ats, 1);
}
@@ -211,7 +217,7 @@
message,
session, "", 0);
plugin->env->update_address_metrics (plugin->env->cls,
- &session->sender, "", 0, session, &ats, 1);
+ &session->sender, NULL, 0, session, &ats, 1);
return GNUNET_OK;
}
@@ -278,14 +284,17 @@
static void
handle_dv_connect (void *cls,
const struct GNUNET_PeerIdentity *peer,
- uint32_t distance)
+ uint32_t distance, uint32_t network)
{
struct Plugin *plugin = cls;
struct Session *session;
+ struct GNUNET_ATS_Information ats[2];
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message for peer `%s'\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received `%s' message for peer `%s' with next hop in network %s \n",
"DV_CONNECT",
- GNUNET_i2s (peer));
+ GNUNET_i2s (peer),
+ GNUNET_ATS_print_network_type (network));
session = GNUNET_CONTAINER_multipeermap_get (plugin->sessions,
peer);
@@ -300,11 +309,20 @@
session = GNUNET_new (struct Session);
session->sender = *peer;
session->distance = distance;
+ session->network = network;
GNUNET_assert (GNUNET_YES ==
GNUNET_CONTAINER_multipeermap_put (plugin->sessions,
&session->sender,
session,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+
+ /* Notify transport and ats about new connection */
+ ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
+ ats[0].value = htonl (distance);
+ ats[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
+ ats[0].value = htonl (network);
+ plugin->env->session_start (plugin->env->cls, peer, PLUGIN_NAME, NULL, 0,
+ session, ats, 2);
}
@@ -332,7 +350,8 @@
if (NULL == session)
{
GNUNET_break (0);
- handle_dv_connect (plugin, peer, distance);
+ /* FIXME */
+ handle_dv_connect (plugin, peer, distance, 0);
return;
}
session->distance = distance;
@@ -398,6 +417,7 @@
peer);
if (NULL == session)
return; /* nothing to do */
+
free_session (session);
}
@@ -668,7 +688,7 @@
struct Session *session)
{
GNUNET_assert (NULL != session);
- return GNUNET_ATS_NET_UNSPECIFIED;
+ return session->network;
}
Modified: gnunet/src/include/gnunet_dv_service.h
===================================================================
--- gnunet/src/include/gnunet_dv_service.h 2013-12-03 12:31:38 UTC (rev
31009)
+++ gnunet/src/include/gnunet_dv_service.h 2013-12-03 14:23:55 UTC (rev
31010)
@@ -36,10 +36,11 @@
* @param cls closure
* @param peer newly connected peer
* @param distance distance to the peer
+ * @param network the peer is located in
*/
typedef void (*GNUNET_DV_ConnectCallback)(void *cls,
const struct GNUNET_PeerIdentity
*peer,
- uint32_t distance);
+ uint32_t distance, uint32_t network);
/**
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r31010 - in gnunet/src: dv include,
gnunet <=