/*
This file is part of GNUnet.
- (C) 2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2013 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
* ID of the task we use to (periodically) update our consensus
* with this peer. Used if we are the initiating peer.
*/
- GNUNET_SCHEDULER_TaskIdentifier initiate_task;
+ struct GNUNET_SCHEDULER_Task * initiate_task;
/**
* At what offset are we, with respect to inserting our own routes
/**
* Hashmap with all routes that we currently support; contains
* routing information for all peers from distance 2
- * up to distance DEFAULT_FISHEYE_DEPTH.
+ * up to distance #DEFAULT_FISHEYE_DEPTH.
*/
static struct GNUNET_CONTAINER_MultiPeerMap *all_routes;
/**
* Task scheduled to refresh routes based on direct neighbours.
*/
-static GNUNET_SCHEDULER_TaskIdentifier rr_task;
+static struct GNUNET_SCHEDULER_Task * rr_task;
/**
* #GNUNET_YES if we are shutting down.
*
* @param cls the 'struct DirectNeighbor' of the peer we're building
* a routing consensus with
- * @param tc scheduler context
*/
static void
-initiate_set_union (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+initiate_set_union (void *cls);
/**
size_t size;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delivering message from peer `%s'\n",
- GNUNET_i2s (origin));
+ "Delivering message from peer `%s' at distance %u\n",
+ GNUNET_i2s (origin),
+ (unsigned int) distance);
size = sizeof (struct GNUNET_DV_ReceivedMessage) +
ntohs (message->size);
if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
off,
GNUNET_i2s (&dn->peer));
GNUNET_assert (NULL != core_api);
- if (NULL != dn->pm_head)
+ if (NULL != pending)
dn->cth =
GNUNET_CORE_notify_transmit_ready (core_api,
GNUNET_YES /* cork */,
- 0 /* priority */,
+ GNUNET_CORE_PRIO_BEST_EFFORT,
GNUNET_TIME_UNIT_FOREVER_REL,
&dn->peer,
msize,
* Forward the given payload to the given target.
*
* @param target where to send the message
- * @param distance expected (remaining) distance to the target
+ * @param distance distance to the @a sender
* @param uid unique ID for the message
* @param sender original sender of the message
* @param actual_target ultimate recipient for the message
if (NULL == target->cth)
target->cth = GNUNET_CORE_notify_transmit_ready (core_api,
GNUNET_YES /* cork */,
- 0 /* priority */,
+ GNUNET_CORE_PRIO_BEST_EFFORT,
GNUNET_TIME_UNIT_FOREVER_REL,
&target->peer,
msize,
target = &route->target;
GNUNET_assert (ntohl (target->distance) < DEFAULT_FISHEYE_DEPTH);
element.size = sizeof (struct Target);
- element.type = htons (0); /* do we need this? */
+ element.element_type = htons (0);
element.data = target;
/* Find next non-NULL entry */
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Adding peer `%s' with distance %u to SET\n",
GNUNET_i2s (&target->peer),
- ntohl (target->distance));
+ ntohl (target->distance) + 1);
GNUNET_SET_add_element (neighbor->my_set,
&element,
&build_set, neighbor);
* Task to run #refresh_routes() on all direct neighbours.
*
* @param cls NULL
- * @param tc unused
*/
static void
-refresh_routes_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+refresh_routes_task (void *cls)
{
- rr_task = GNUNET_SCHEDULER_NO_TASK;
+ rr_task = NULL;
GNUNET_CONTAINER_multipeermap_iterate (direct_neighbors,
&refresh_routes,
NULL);
static void
schedule_refresh_routes ()
{
- if (GNUNET_SCHEDULER_NO_TASK == rr_task)
+ if (NULL == rr_task)
rr_task = GNUNET_SCHEDULER_add_now (&refresh_routes_task,
NULL);
}
-/**
- * Get distance information from 'atsi'.
- *
- * @param atsi performance data
- * @param atsi_count number of entries in atsi
- * @return connected transport distance
- */
-static uint32_t
-get_atsi_distance (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_QUALITY_NET_DISTANCE)
- 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 enum GNUNET_ATS_Network_Type
-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 (enum GNUNET_ATS_Network_Type) 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.
GNUNET_SET_listen_cancel (neighbor->listen_handle);
neighbor->listen_handle = NULL;
}
- if (GNUNET_SCHEDULER_NO_TASK != neighbor->initiate_task)
+ if (NULL != neighbor->initiate_task)
{
GNUNET_SCHEDULER_cancel (neighbor->initiate_task);
- neighbor->initiate_task = GNUNET_SCHEDULER_NO_TASK;
+ neighbor->initiate_task = NULL;
}
}
*
* @param cls closure
* @param address the address
- * @param active is this address in active use
+ * @param active #GNUNET_YES if this address is actively used
+ * to maintain a connection to a peer;
+ * #GNUNET_NO if the address is not actively used;
+ * #GNUNET_SYSERR if this address is no longer available for ATS
* @param bandwidth_out assigned outbound bandwidth for the connection
* @param bandwidth_in assigned inbound bandwidth for the connection
- * @param ats performance data for the address (as far as known)
- * @param ats_count number of performance records in @a ats
+ * @param prop performance data for the address (as far as known)
*/
static void
handle_ats_update (void *cls,
int active,
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Properties *prop)
{
struct DirectNeighbor *neighbor;
uint32_t distance;
- enum GNUNET_ATS_Network_Type network = GNUNET_ATS_NET_UNSPECIFIED;
+ enum GNUNET_ATS_Network_Type network;
- if (GNUNET_NO == active)
+ if (NULL == address)
+ {
+ /* ATS service temporarily disconnected */
return;
- distance = get_atsi_distance (ats, ats_count);
- network = get_atsi_network (ats, ats_count);
+ }
+
+ if (GNUNET_YES != active)
+ {
+ // FIXME: handle disconnect/inactive case too!
+ return;
+ }
+ distance = prop->distance;
+ network = prop->scope;
GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != network);
/* check if entry exists */
neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
enum GNUNET_SET_Status status)
{
struct DirectNeighbor *neighbor = cls;
+ struct DirectNeighbor *dn;
struct Target *target;
char *status_str;
case GNUNET_SET_STATUS_OK:
status_str = "GNUNET_SET_STATUS_OK";
break;
- case GNUNET_SET_STATUS_TIMEOUT:
- status_str = "GNUNET_SET_STATUS_TIMEOUT";
- break;
case GNUNET_SET_STATUS_FAILURE:
status_str = "GNUNET_SET_STATUS_FAILURE";
break;
GNUNET_break_op (0);
return;
}
- if (GNUNET_YES ==
- GNUNET_CONTAINER_multipeermap_contains (direct_neighbors,
- &((struct Target *) element->data)->peer))
+ if ( (NULL != (dn = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, &((struct Target *) element->data)->peer))) && (DIRECT_NEIGHBOR_COST == dn->distance) )
{
/* this is a direct neighbor of ours, we do not care about routes
to this peer */
GNUNET_free (target);
}
break;
- case GNUNET_SET_STATUS_TIMEOUT:
case GNUNET_SET_STATUS_FAILURE:
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Failed to establish DV union, will try again later\n");
*
* @param cls the `struct DirectNeighbor *` of the peer we're building
* a routing consensus with
- * @param tc scheduler context
*/
static void
-initiate_set_union (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+initiate_set_union (void *cls)
{
- static uint16_t salt;
struct DirectNeighbor *neighbor = cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Initiating SET union with peer `%s'\n",
GNUNET_i2s (&neighbor->peer));
- neighbor->initiate_task = GNUNET_SCHEDULER_NO_TASK;
+ neighbor->initiate_task = NULL;
neighbor->my_set = GNUNET_SET_create (cfg,
GNUNET_SET_OPERATION_UNION);
neighbor->set_op = GNUNET_SET_prepare (&neighbor->peer,
&neighbor->real_session_id,
NULL,
- salt++,
GNUNET_SET_RESULT_ADDED,
&handle_set_union_result,
neighbor);
* @return #GNUNET_OK on success, #GNUNET_SYSERR if the other peer violated the protocol
*/
static int
-handle_dv_route_message (void *cls, const struct GNUNET_PeerIdentity *peer,
+handle_dv_route_message (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message)
{
const struct RouteMessage *rm;
const struct GNUNET_MessageHeader *payload;
struct Route *route;
struct DirectNeighbor *neighbor;
+ struct DirectNeighbor *dn;
struct Target *target;
uint32_t distance;
char me[5];
return GNUNET_SYSERR;
}
rm = (const struct RouteMessage *) message;
+ distance = ntohl (rm->distance);
+ payload = (const struct GNUNET_MessageHeader *) &rm[1];
+ if (ntohs (message->size) != sizeof (struct RouteMessage) + ntohs (payload->size))
+ {
+ GNUNET_break_op (0);
+ return GNUNET_SYSERR;
+ }
strncpy (prev, GNUNET_i2s (peer), 4);
strncpy (me, GNUNET_i2s (&my_identity), 4);
strncpy (src, GNUNET_i2s (&rm->sender), 4);
strncpy (dst, GNUNET_i2s (&rm->target), 4);
prev[4] = me[4] = src[4] = dst[4] = '\0';
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Handling DV message from %s to %s routed by %s to me (%s @ %u)\n",
+ "Handling DV message with %u bytes payload of type %u from %s to %s routed by %s to me (%s @ hop %u)\n",
+ ntohs (message->size) - sizeof (struct RouteMessage),
+ ntohs (payload->type),
src, dst,
prev, me,
- (unsigned int) ntohl (rm->distance));
+ (unsigned int) distance + 1);
- payload = (const struct GNUNET_MessageHeader *) &rm[1];
- if (ntohs (message->size) != sizeof (struct RouteMessage) + ntohs (payload->size))
- {
- GNUNET_break_op (0);
- return GNUNET_SYSERR;
- }
if (0 == memcmp (&rm->target,
&my_identity,
sizeof (struct GNUNET_PeerIdentity)))
{
+ if ((NULL
+ != (dn = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
+ &rm->sender))) && (DIRECT_NEIGHBOR_COST == dn->distance))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Discarding DV message, as %s is a direct neighbor\n",
+ GNUNET_i2s (&rm->sender));
+ GNUNET_STATISTICS_update (stats,
+ "# messages discarded (direct neighbor)",
+ 1, GNUNET_NO);
+ return GNUNET_OK;
+ }
/* message is for me, check reverse route! */
route = GNUNET_CONTAINER_multipeermap_get (all_routes,
&rm->sender);
if ( (NULL == route) &&
- (NULL == GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
- &rm->sender)) &&
- (ntohs (rm->distance) < DEFAULT_FISHEYE_DEPTH) )
+ (distance < DEFAULT_FISHEYE_DEPTH) )
{
/* don't have reverse route yet, learn it! */
neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
if (NULL == neighbor)
{
GNUNET_break (0);
- return GNUNET_SYSERR;
+ return GNUNET_OK;
}
target = GNUNET_new (struct Target);
target->peer = rm->sender;
- target->distance = htonl (ntohl (rm->distance));
+ target->distance = htonl (distance);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Learning target %s at distance %u from delivery!\n",
+ "Learning sender %s at distance %u from delivery!\n",
GNUNET_i2s (&rm->sender),
- 1 + ntohs (rm->distance));
+ (unsigned int) distance + 1);
if (NULL == neighbor->neighbor_table)
neighbor->neighbor_table = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
if (GNUNET_YES !=
{
GNUNET_break_op (0);
GNUNET_free (target);
+ return GNUNET_OK;
}
add_new_route (target, neighbor);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Delivering %u bytes to myself!\n",
- ntohs (payload->size));
+ "Delivering %u bytes from %s to myself!\n",
+ ntohs (payload->size),
+ GNUNET_i2s (&rm->sender));
send_data_to_plugin (payload,
&rm->sender,
- ntohl (route->target.distance));
+ 1 + distance);
return GNUNET_OK;
}
if ( (NULL == GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
&rm->sender)) )
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Learning target %s at distance %u from forwarding!\n",
+ "Learning sender %s at distance %u from forwarding!\n",
GNUNET_i2s (&rm->sender),
- 1 + ntohs (rm->distance));
+ 1 + distance);
neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors,
peer);
if (NULL == neighbor)
{
GNUNET_break (0);
- return GNUNET_SYSERR;
+ return GNUNET_OK;
}
target = GNUNET_new (struct Target);
target->peer = rm->sender;
- target->distance = htonl (ntohl (rm->distance));
+ target->distance = htonl (distance);
if (NULL == neighbor->neighbor_table)
neighbor->neighbor_table = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
if (GNUNET_YES !=
{
GNUNET_break_op (0);
GNUNET_free (target);
+ return GNUNET_OK;
}
add_new_route (target, neighbor);
}
1, GNUNET_NO);
return GNUNET_OK;
}
- distance = DIRECT_NEIGHBOR_COST;
}
else
{
- if (ntohl (route->target.distance) > ntohl (rm->distance) + 1)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Distance too far, not routing %u bytes!\n",
- ntohs (payload->size));
- GNUNET_STATISTICS_update (stats,
- "# messages discarded (target too far)",
- 1, GNUNET_NO);
- return GNUNET_OK;
- }
neighbor = route->next_hop;
- distance = ntohl (route->target.distance);
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Forwarding message to %s\n",
GNUNET_i2s (&neighbor->peer));
forward_payload (neighbor,
- distance,
+ distance + 1,
0,
&rm->sender,
&rm->target,
if (NULL == route)
{
/* got disconnected */
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "No route to %s, dropping local message of type %u\n",
+ GNUNET_i2s (&msg->target),
+ ntohs (payload->type));
GNUNET_STATISTICS_update (stats,
"# local messages discarded (no route)",
1, GNUNET_NO);
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Forwarding %u bytes to %s\n",
+ "Forwarding %u bytes of type %u to %s\n",
ntohs (payload->size),
+ ntohs (payload->type),
GNUNET_i2s (&msg->target));
forward_payload (route->next_hop,
- ntohl (route->target.distance),
+ 0 /* first hop, distance is zero */,
htonl (msg->uid),
&my_identity,
&msg->target,
* Task run during shutdown.
*
* @param cls unused
- * @param tc unused
*/
static void
-shutdown_task (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+shutdown_task (void *cls)
{
unsigned int i;
consensi[i].array_length,
0);
}
- if (GNUNET_SCHEDULER_NO_TASK != rr_task)
+ if (NULL != rr_task)
{
GNUNET_SCHEDULER_cancel (rr_task);
- rr_task = GNUNET_SCHEDULER_NO_TASK;
+ rr_task = NULL;
}
}
MAX_QUEUE_SIZE_PLUGIN);
stats = GNUNET_STATISTICS_create ("dv", cfg);
GNUNET_SERVER_add_handlers (server, plugin_handlers);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL);
}