aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/Makefile.am6
-rw-r--r--src/mesh/gnunet-service-mesh-new.c4
-rw-r--r--src/mesh/mesh_path.c125
-rw-r--r--src/mesh/mesh_path.h133
4 files changed, 263 insertions, 5 deletions
diff --git a/src/mesh/Makefile.am b/src/mesh/Makefile.am
index 84d4838b3..0fae3b356 100644
--- a/src/mesh/Makefile.am
+++ b/src/mesh/Makefile.am
@@ -1,4 +1,4 @@
1INCLUDES = -I$(top_srcdir)/src/include 1NCLUDES = -I$(top_srcdir)/src/include
2 2
3if MINGW 3if MINGW
4 WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols 4 WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols
@@ -102,7 +102,7 @@ gnunet_mesh_DEPENDENCIES = \
102 102
103gnunet_service_mesh_new_SOURCES = \ 103gnunet_service_mesh_new_SOURCES = \
104 gnunet-service-mesh-new.c \ 104 gnunet-service-mesh-new.c \
105 mesh_tunnel_tree.c \ 105 mesh_path.c \
106 mesh_common.c 106 mesh_common.c
107gnunet_service_mesh_new_CFLAGS = $(AM_CFLAGS) 107gnunet_service_mesh_new_CFLAGS = $(AM_CFLAGS)
108gnunet_service_mesh_new_LDADD = \ 108gnunet_service_mesh_new_LDADD = \
@@ -156,7 +156,7 @@ test_mesh_api_SOURCES = \
156test_mesh_api_LDADD = \ 156test_mesh_api_LDADD = \
157 $(top_builddir)/src/util/libgnunetutil.la \ 157 $(top_builddir)/src/util/libgnunetutil.la \
158 $(top_builddir)/src/testing/libgnunettesting.la \ 158 $(top_builddir)/src/testing/libgnunettesting.la \
159 $(top_builddir)/src/mesh/libgnunetmesh.la 159 $(top_builddir)/src/mesh/libgnunetmesh2.la
160test_mesh_api_DEPENDENCIES = \ 160test_mesh_api_DEPENDENCIES = \
161 libgnunetmesh.la \ 161 libgnunetmesh.la \
162 $(top_builddir)/src/util/libgnunetutil.la 162 $(top_builddir)/src/util/libgnunetutil.la
diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c
index 697d8275e..a0f5f1a24 100644
--- a/src/mesh/gnunet-service-mesh-new.c
+++ b/src/mesh/gnunet-service-mesh-new.c
@@ -48,7 +48,7 @@
48#include "platform.h" 48#include "platform.h"
49#include "mesh2.h" 49#include "mesh2.h"
50#include "mesh2_protocol.h" 50#include "mesh2_protocol.h"
51#include "mesh_tunnel_tree.h" 51#include "mesh_path.h"
52#include "block_mesh.h" 52#include "block_mesh.h"
53#include "gnunet_dht_service.h" 53#include "gnunet_dht_service.h"
54#include "gnunet_statistics_service.h" 54#include "gnunet_statistics_service.h"
@@ -309,7 +309,7 @@ struct MeshTunnel
309 /** 309 /**
310 * State of the tunnel. 310 * State of the tunnel.
311 */ 311 */
312 MeshTunnelState state; 312 enum MeshTunnelState state;
313 313
314 /** 314 /**
315 * Local tunnel number ( >= GNUNET_MESH_LOCAL_TUNNEL_ID_CLI or 0 ) 315 * Local tunnel number ( >= GNUNET_MESH_LOCAL_TUNNEL_ID_CLI or 0 )
diff --git a/src/mesh/mesh_path.c b/src/mesh/mesh_path.c
new file mode 100644
index 000000000..05444655a
--- /dev/null
+++ b/src/mesh/mesh_path.c
@@ -0,0 +1,125 @@
1/*
2 This file is part of GNUnet.
3 (C) 2001 - 2013 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20
21/**
22 * @file mesh/mesh_path.c
23 * @brief Path handling functions
24 * @author Bartlomiej Polot
25 */
26
27#include "mesh2.h"
28#include "mesh_path.h"
29
30
31/**
32 * Create a new path
33 *
34 * @param length How many hops will the path have.
35 *
36 * @return A newly allocated path with a peer array of the specified length.
37 */
38struct MeshPeerPath *
39path_new (unsigned int length)
40{
41 struct MeshPeerPath *p;
42
43 p = GNUNET_malloc (sizeof (struct MeshPeerPath));
44 if (length > 0)
45 {
46 p->length = length;
47 p->peers = GNUNET_malloc (length * sizeof (GNUNET_PEER_Id));
48 }
49 return p;
50}
51
52
53/**
54 * Invert the path
55 *
56 * @param path the path to invert
57 */
58void
59path_invert (struct MeshPeerPath *path)
60{
61 GNUNET_PEER_Id aux;
62 unsigned int i;
63
64 for (i = 0; i < path->length / 2; i++)
65 {
66 aux = path->peers[i];
67 path->peers[i] = path->peers[path->length - i - 1];
68 path->peers[path->length - i - 1] = aux;
69 }
70}
71
72
73/**
74 * Duplicate a path, incrementing short peer's rc.
75 *
76 * @param path The path to duplicate.
77 */
78struct MeshPeerPath *
79path_duplicate (struct MeshPeerPath *path)
80{
81 struct MeshPeerPath *aux;
82 unsigned int i;
83
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);
88 return aux;
89}
90
91
92/**
93 * Get the length of a path.
94 *
95 * @param path The path to measure, with the local peer at any point of it.
96 *
97 * @return Number of hops to reach destination.
98 * UINT_MAX in case the peer is not in the path.
99 */
100unsigned int
101path_get_length (struct MeshPeerPath *path)
102{
103 if (NULL == path)
104 return UINT_MAX;
105 return path->length;
106}
107
108
109/**
110 * Destroy the path and free any allocated resources linked to it
111 *
112 * @param p the path to destroy
113 *
114 * @return GNUNET_OK on success
115 */
116int
117path_destroy (struct MeshPeerPath *p)
118{
119 if (NULL == p)
120 return GNUNET_OK;
121 GNUNET_PEER_decrement_rcs (p->peers, p->length);
122 GNUNET_free_non_null (p->peers);
123 GNUNET_free (p);
124 return GNUNET_OK;
125}
diff --git a/src/mesh/mesh_path.h b/src/mesh/mesh_path.h
new file mode 100644
index 000000000..c3f3264b0
--- /dev/null
+++ b/src/mesh/mesh_path.h
@@ -0,0 +1,133 @@
1/*
2 This file is part of GNUnet.
3 (C) 2001 - 2013 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19*/
20
21/**
22 * @file mesh/mesh_path.h
23 * @brief Path handling functions
24 * @author Bartlomiej Polot
25 */
26
27#ifndef MESH_PATH_H
28#define MESH_PATH_H
29
30#ifdef __cplusplus
31extern "C"
32{
33 #if 0 /* keep Emacsens' auto-indent happy */
34}
35#endif
36#endif
37
38#include "mesh2.h"
39
40/******************************************************************************/
41/************************ DATA STRUCTURES ****************************/
42/******************************************************************************/
43
44/**
45 * Information regarding a possible path to reach a single peer
46 */
47struct MeshPeerPath
48{
49
50 /**
51 * Linked list
52 */
53 struct MeshPeerPath *next;
54 struct MeshPeerPath *prev;
55
56 /**
57 * List of all the peers that form the path from origin to target.
58 */
59 GNUNET_PEER_Id *peers;
60
61 /**
62 * Number of peers (hops) in the path
63 */
64 unsigned int length;
65
66};
67
68/******************************************************************************/
69/************************* FUNCTIONS *****************************/
70/******************************************************************************/
71
72/**
73 * Create a new path.
74 *
75 * @param length How many hops will the path have.
76 *
77 * @return A newly allocated path with a peer array of the specified length.
78 */
79struct MeshPeerPath *
80path_new (unsigned int length);
81
82
83/**
84 * Invert the path.
85 *
86 * @param path The path to invert.
87 */
88void
89path_invert (struct MeshPeerPath *path);
90
91
92/**
93 * Duplicate a path, incrementing short peer's rc.
94 *
95 * @param path The path to duplicate.
96 */
97struct MeshPeerPath *
98path_duplicate (struct MeshPeerPath *path);
99
100
101/**
102 * Get the length of a path.
103 *
104 * @param path The path to measure, with the local peer at any point of it.
105 *
106 * @return Number of hops to reach destination.
107 * UINT_MAX in case the peer is not in the path.
108 */
109unsigned int
110path_get_length (struct MeshPeerPath *path);
111
112
113/**
114 * Destroy the path and free any allocated resources linked to it
115 *
116 * @param p the path to destroy
117 *
118 * @return GNUNET_OK on success
119 */
120int
121path_destroy (struct MeshPeerPath *p);
122
123
124#if 0 /* keep Emacsens' auto-indent happy */
125{
126 #endif
127 #ifdef __cplusplus
128}
129#endif
130
131
132/* ifndef MESH_PATH_H */
133#endif \ No newline at end of file