diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-12-17 12:34:35 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-12-17 12:34:35 +0000 |
commit | 98850ede1551a3ee4490c15363455d9105e63ce0 (patch) | |
tree | 115ace3d427c537e2f50626bf0f94d0e5550b319 /src/mesh/mesh_path.c | |
parent | eb620579de05105499d35f21db8759682698df9d (diff) | |
download | gnunet-98850ede1551a3ee4490c15363455d9105e63ce0.tar.gz gnunet-98850ede1551a3ee4490c15363455d9105e63ce0.zip |
- dont destroy a path right away, broken paths can cause long loops with outdated DHT data
Diffstat (limited to 'src/mesh/mesh_path.c')
-rw-r--r-- | src/mesh/mesh_path.c | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/src/mesh/mesh_path.c b/src/mesh/mesh_path.c index 52f0c948a..b5c6ce82f 100644 --- a/src/mesh/mesh_path.c +++ b/src/mesh/mesh_path.c | |||
@@ -26,6 +26,26 @@ | |||
26 | 26 | ||
27 | #include "mesh.h" | 27 | #include "mesh.h" |
28 | #include "mesh_path.h" | 28 | #include "mesh_path.h" |
29 | #include "gnunet-service-mesh_peer.h" | ||
30 | |||
31 | /** | ||
32 | * @brief Destroy a path after some time has past. | ||
33 | * | ||
34 | * If the path is returned from DHT again after a while, try again. | ||
35 | * | ||
36 | * @param cls Closure (path to destroy). | ||
37 | * @param tc Task context. | ||
38 | */ | ||
39 | static void | ||
40 | path_destroy_delayed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
41 | { | ||
42 | struct MeshPeerPath *path = cls; | ||
43 | struct MeshPeer *peer; | ||
44 | |||
45 | path->path_delete = GNUNET_SCHEDULER_NO_TASK; | ||
46 | peer = GMP_get_short (path->peers[path->length - 1]); | ||
47 | GMP_remove_path (peer, path); | ||
48 | } | ||
29 | 49 | ||
30 | 50 | ||
31 | /** | 51 | /** |
@@ -106,6 +126,41 @@ path_get_length (struct MeshPeerPath *path) | |||
106 | } | 126 | } |
107 | 127 | ||
108 | 128 | ||
129 | |||
130 | /** | ||
131 | * Mark path as invalid: keep it aroud for a while to avoid trying it in a loop. | ||
132 | * | ||
133 | * DHT_get sometimes returns bad cached results, for instance, on a locally | ||
134 | * cached result where the PUT followed a path that is no longer current. | ||
135 | * | ||
136 | * @param p Path to invalidate. | ||
137 | */ | ||
138 | void | ||
139 | path_invalidate (struct MeshPeerPath *p) | ||
140 | { | ||
141 | if (GNUNET_SCHEDULER_NO_TASK != p->path_delete) | ||
142 | return; | ||
143 | |||
144 | p->path_delete = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, | ||
145 | &path_destroy_delayed, p); | ||
146 | } | ||
147 | |||
148 | |||
149 | /** | ||
150 | * Test if a path is valid (or at least not known to be invalid). | ||
151 | * | ||
152 | * @param path Path to test. | ||
153 | * | ||
154 | * @return #GNUNET_YES If the path is valid or unknown, | ||
155 | * #GNUNET_NO If the path is known to be invalid. | ||
156 | */ | ||
157 | int | ||
158 | path_is_valid (const struct MeshPeerPath *path) | ||
159 | { | ||
160 | return (GNUNET_SCHEDULER_NO_TASK == path->path_delete); | ||
161 | } | ||
162 | |||
163 | |||
109 | /** | 164 | /** |
110 | * Destroy the path and free any allocated resources linked to it | 165 | * Destroy the path and free any allocated resources linked to it |
111 | * | 166 | * |
@@ -118,8 +173,11 @@ path_destroy (struct MeshPeerPath *p) | |||
118 | { | 173 | { |
119 | if (NULL == p) | 174 | if (NULL == p) |
120 | return GNUNET_OK; | 175 | return GNUNET_OK; |
176 | |||
121 | GNUNET_PEER_decrement_rcs (p->peers, p->length); | 177 | GNUNET_PEER_decrement_rcs (p->peers, p->length); |
122 | GNUNET_free_non_null (p->peers); | 178 | GNUNET_free_non_null (p->peers); |
179 | if (GNUNET_SCHEDULER_NO_TASK != p->path_delete) | ||
180 | GNUNET_SCHEDULER_cancel (p->path_delete); | ||
123 | GNUNET_free (p); | 181 | GNUNET_free (p); |
124 | return GNUNET_OK; | 182 | return GNUNET_OK; |
125 | } | 183 | } |
@@ -129,8 +187,8 @@ path_debug (struct MeshPeerPath *p) | |||
129 | { | 187 | { |
130 | unsigned int i; | 188 | unsigned int i; |
131 | 189 | ||
132 | fprintf (stderr, "PATH:"); | 190 | fprintf (stderr, "PATH:"); |
133 | for (i = 0; i < p->length; i++) | 191 | for (i = 0; i < p->length; i++) |
134 | fprintf (stderr, " %s", GNUNET_i2s (GNUNET_PEER_resolve2 (p->peers[i]))); | 192 | fprintf (stderr, " %s", GNUNET_i2s (GNUNET_PEER_resolve2 (p->peers[i]))); |
135 | fprintf (stderr, " END\n"); | 193 | fprintf (stderr, " END\n"); |
136 | } \ No newline at end of file | 194 | } |