2 This file is part of GNUnet.
3 (C) 2001 - 2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file mesh/mesh_path.c
23 * @brief Path handling functions
24 * @author Bartlomiej Polot
28 #include "mesh_path.h"
34 * @param length How many hops will the path have.
36 * @return A newly allocated path with a peer array of the specified length.
39 path_new (unsigned int length)
41 struct MeshPeerPath *p;
43 p = GNUNET_malloc (sizeof (struct MeshPeerPath));
47 p->peers = GNUNET_malloc (length * sizeof (GNUNET_PEER_Id));
56 * @param path the path to invert
59 path_invert (struct MeshPeerPath *path)
64 for (i = 0; i < path->length / 2; i++)
67 path->peers[i] = path->peers[path->length - i - 1];
68 path->peers[path->length - i - 1] = aux;
74 * Duplicate a path, incrementing short peer's rc.
76 * @param path The path to duplicate.
79 path_duplicate (struct MeshPeerPath *path)
81 struct MeshPeerPath *aux;
84 aux = path_new (path->length);
85 memcpy (aux->peers, path->peers, path->length * sizeof (GNUNET_PEER_Id));
86 for (i = 0; i < path->length; i++)
87 GNUNET_PEER_change_rc (path->peers[i], 1);
93 * Get the length of a path.
95 * @param path The path to measure, with the local peer at any point of it.
97 * @return Number of hops to reach destination.
98 * UINT_MAX in case the peer is not in the path.
101 path_get_length (struct MeshPeerPath *path)
110 * Destroy the path and free any allocated resources linked to it
112 * @param p the path to destroy
114 * @return GNUNET_OK on success
117 path_destroy (struct MeshPeerPath *p)
121 GNUNET_PEER_decrement_rcs (p->peers, p->length);
122 GNUNET_free_non_null (p->peers);