+ struct CheckMatchContext cm_ctx;
+ struct CadetPeer *cpath[path_length];
+ struct CadetPeerPath *path;
+
+ /* precompute inverted 'cpath' so we can avoid doing the lookups and
+ have the correct order */
+ for (unsigned int off=0;off<path_length;off++)
+ cpath[off] = GCP_get (&pids[path_length - 1 - off],
+ GNUNET_YES);
+
+ /* 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 = cpath;
+ cm_ctx.match = NULL;
+ for (int i=path_length-1;i>=0;i--)
+ {
+ GCP_iterate_paths_at (cpath[i],
+ (unsigned int) i,
+ &check_match,
+ &cm_ctx);
+ if (NULL != cm_ctx.match)
+ {
+ if (i == path_length - 1)
+ {
+ /* Existing path includes this one, return the match! */
+ return cm_ctx.match;
+ }
+ if (cm_ctx.match->entries_length == i + 1)
+ {
+ /* Existing path ends in the middle of new path, extend it! */
+ extend_path (cm_ctx.match,
+ &cpath[i],
+ path_length - i,
+ GNUNET_YES);
+ /* Check that extension was successful */
+ GNUNET_assert (cm_ctx.match->entries_length == path_length);
+ return cm_ctx.match;
+ }
+ }
+ }
+
+ /* No match at all, create completely new path */
+ path = GNUNET_new (struct CadetPeerPath);
+ path->entries_length = path_length;
+ path->entries = GNUNET_new_array (path->entries_length,
+ struct CadetPeerPathEntry);
+ for (int i=path_length-1;i>=0;i--)
+ {
+ struct CadetPeerPathEntry *entry = &path->entries[i];
+
+ entry->peer = cpath[i];
+ entry->path = path;
+ GCP_path_entry_add (entry->peer,
+ entry,
+ i);
+ }
+ path->hn = GCP_attach_path (cpath[path_length - 1],
+ path,
+ path_length - 1,
+ GNUNET_YES);
+ return path;