* @brief Information we track per path.
* @author Bartlomiej Polot
* @author Christian Grothoff
- *
- * TODO:
- * - path desirability score calculations are not done
*/
#include "platform.h"
#include "gnunet-service-cadet-new_connection.h"
+#include "gnunet-service-cadet-new_tunnels.h"
#include "gnunet-service-cadet-new_peer.h"
#include "gnunet-service-cadet-new_paths.h"
};
+/**
+ * Calculate the path's desirability score.
+ *
+ * @param path path to calculate the score for
+ */
+static void
+recalculate_path_desirability (struct CadetPeerPath *path)
+{
+ double result = 0.0;
+
+ for (unsigned int i=0;i<path->entries_length;i++)
+ {
+ struct CadetPeer *cp = path->entries[i]->peer;
+
+ result += GCP_get_desirability_of_path (cp,
+ i);
+ }
+ path->desirability = (GNUNET_CONTAINER_HeapCostType) result;
+}
+
+
/**
* Return how much we like keeping the path. This is an aggregate
* score based on various factors, including the age of the path
"Destroying path %s\n",
GCPP_2s (path));
for (unsigned int i=0;i<path->entries_length;i++)
- GNUNET_free (path->entries[i]);
+ {
+ struct CadetPeerPathEntry *entry = path->entries[i];
+
+ if (NULL != entry->cc)
+ {
+ struct CadetTConnection *ct;
+
+ ct = GCC_get_ct (entry->cc);
+ if (NULL != ct)
+ GCT_connection_lost (ct);
+ GCC_destroy_without_tunnel (entry->cc);
+ }
+ GNUNET_free (entry);
+ }
GNUNET_free (path->entries);
GNUNET_free (path);
}
entry = path->entries[path->entries_length - 1];
path->hn = GCP_attach_path (entry->peer,
path,
- path->entries_length,
+ path->entries_length - 1,
GNUNET_NO);
if (NULL != path->hn)
return; /* yep, got attached, we are done. */
else
entry->score += delta;
}
-
- /* FIXME: update path desirability! */
+ recalculate_path_desirability (path);
}
struct CadetPeerPathEntry *entry = path->entries[old_len + i];
path->entries_length = old_len + i + 1;
- /* FIXME: note that path->desirability is used, but not yet updated here! */
+ recalculate_path_desirability (path);
hn = GCP_attach_path (peers[i],
path,
old_len + (unsigned int) i,
struct CadetPeerPath *path;
struct GNUNET_CONTAINER_HeapNode *hn;
int i;
+ unsigned int skip;
+ unsigned int total_len;
/* precompute 'cpath' so we can avoid doing the lookups lots of times */
- for (unsigned int off=0;off<get_path_length + put_path_length;off++)
+ skip = 0;
+ total_len = get_path_length + put_path_length;
+ for (unsigned int off=0;off<total_len;off++)
{
const struct GNUNET_PeerIdentity *pid;
pid = (off < get_path_length)
? &get_path[get_path_length - off]
: &put_path[get_path_length + put_path_length - off];
- cpath[off] = GCP_get (pid,
- GNUNET_YES);
+ cpath[off - skip] = GCP_get (pid,
+ GNUNET_YES);
+ /* Check that no peer is twice on the path */
+ for (unsigned int i=0;i<off;i++)
+ {
+ if (cpath[i] == cpath[off])
+ {
+ skip = off - i;
+ break;
+ }
+ }
}
+ total_len -= skip;
/* First figure out if this path is a subset of an existing path, an
extension of an existing path, or a new path. */
- cm_ctx.cpath_length = get_path_length + put_path_length;
+ cm_ctx.cpath_length = total_len;
cm_ctx.cpath = cpath;
cm_ctx.match = NULL;
- for (i=get_path_length + put_path_length-1;i>=0;i--)
+ for (i=total_len-1;i>=0;i--)
{
GCP_iterate_paths_at (cpath[i],
(unsigned int) i,
&cm_ctx);
if (NULL != cm_ctx.match)
{
- if (i == get_path_length + put_path_length - 1)
+ if (i == total_len - 1)
{
/* Existing path includes this one, nothing to do! */
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Trying to extend existing path %s by additional links discovered from DHT\n",
GCPP_2s (cm_ctx.match));
extend_path (cm_ctx.match,
- &cpath[i],
- get_path_length + put_path_length - i,
+ &cpath[i + 1],
+ total_len - i - 1,
GNUNET_NO);
return;
}
/* No match at all, create completely new path */
path = GNUNET_new (struct CadetPeerPath);
- path->entries_length = get_path_length + put_path_length;
+ path->entries_length = total_len;
path->entries = GNUNET_new_array (path->entries_length,
struct CadetPeerPathEntry *);
for (i=path->entries_length-1;i>=0;i--)
/* Finally, try to attach it */
hn = NULL;
- for (i=get_path_length + put_path_length-1;i>=0;i--)
+ for (i=total_len-1;i>=0;i--)
{
struct CadetPeerPathEntry *entry = path->entries[i];
path->entries_length = i + 1;
- /* FIXME: note that path->desirability is used, but not yet initialized here! */
+ recalculate_path_desirability (path);
hn = GCP_attach_path (cpath[i],
path,
(unsigned int) i,
"Extending existing path %s to create inverse for incoming connection\n",
GCPP_2s (cm_ctx.match));
extend_path (cm_ctx.match,
- &cpath[i],
- path_length - i,
+ &cpath[i + 1],
+ path_length - i - 1,
GNUNET_YES);
/* Check that extension was successful */
GNUNET_assert (cm_ctx.match->entries_length == path_length);
entry,
i);
}
+ recalculate_path_desirability (path);
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Created new path %s to create inverse for incoming connection\n",
GCPP_2s (path));