diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-09-16 17:32:45 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-09-16 17:32:45 +0000 |
commit | 8e8c63b8f9cd8ce94d63e4c854f299c66bf32c6f (patch) | |
tree | 84e1982b5a8f162610eb39b63ab8fcf482f22728 /src | |
parent | b153da6c4c2d6d24f41c4e023e5ac384ea9733a8 (diff) | |
download | gnunet-8e8c63b8f9cd8ce94d63e4c854f299c66bf32c6f.tar.gz gnunet-8e8c63b8f9cd8ce94d63e4c854f299c66bf32c6f.zip |
Fixed adding path to tunnel, deleting old path and replugging node under new one
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index f8bf4cfb1..b84f07621 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -1123,7 +1123,7 @@ tunnel_find_peer(struct MeshTunnelPathNode *root, struct MeshPeerInfo *peer) | |||
1123 | return root; | 1123 | return root; |
1124 | for (i = 0; i < root->nchildren; i++) | 1124 | for (i = 0; i < root->nchildren; i++) |
1125 | { | 1125 | { |
1126 | n = tunnel_find_peer(n, peer); | 1126 | n = tunnel_find_peer(&root->children[i], peer); |
1127 | if (NULL != n) | 1127 | if (NULL != n) |
1128 | return n; | 1128 | return n; |
1129 | } | 1129 | } |
@@ -1137,20 +1137,20 @@ tunnel_find_peer(struct MeshTunnelPathNode *root, struct MeshPeerInfo *peer) | |||
1137 | * @param t Tunnel where to add the new path. | 1137 | * @param t Tunnel where to add the new path. |
1138 | * @param p Path to be integrated. | 1138 | * @param p Path to be integrated. |
1139 | * | 1139 | * |
1140 | * @return GNUNET_OK in case of success. | 1140 | * @return pointer to the pathless node, NULL on error |
1141 | * GNUNET_SYSERR in case of error. | ||
1142 | * | 1141 | * |
1143 | * TODO: notify peers of deletion | 1142 | * TODO: notify peers of deletion |
1144 | */ | 1143 | */ |
1145 | static int | 1144 | static struct MeshTunnelPathNode * |
1146 | tunnel_del_path(struct MeshTunnel *t, struct MeshPeerInfo *peer) | 1145 | tunnel_del_path(struct MeshTunnel *t, struct MeshPeerInfo *peer) |
1147 | { | 1146 | { |
1148 | struct MeshTunnelPathNode *parent; | 1147 | struct MeshTunnelPathNode *parent; |
1148 | struct MeshTunnelPathNode *node; | ||
1149 | struct MeshTunnelPathNode *n; | 1149 | struct MeshTunnelPathNode *n; |
1150 | 1150 | ||
1151 | n = tunnel_find_peer(t->paths->me, peer); | 1151 | node = n = tunnel_find_peer(t->paths->me, peer); |
1152 | if (NULL == n) | 1152 | if (NULL == n) |
1153 | return GNUNET_SYSERR; | 1153 | return NULL; |
1154 | parent = n->parent; | 1154 | parent = n->parent; |
1155 | n->parent = NULL; | 1155 | n->parent = NULL; |
1156 | while (NULL != parent && | 1156 | while (NULL != parent && |
@@ -1162,11 +1162,11 @@ tunnel_del_path(struct MeshTunnel *t, struct MeshPeerInfo *peer) | |||
1162 | parent = parent->parent; | 1162 | parent = parent->parent; |
1163 | } | 1163 | } |
1164 | if (NULL == parent) | 1164 | if (NULL == parent) |
1165 | return GNUNET_SYSERR; | 1165 | return node; |
1166 | *n = parent->children[parent->nchildren - 1]; | 1166 | *n = parent->children[parent->nchildren - 1]; |
1167 | parent->nchildren--; | 1167 | parent->nchildren--; |
1168 | parent->children = GNUNET_realloc (parent->children, parent->nchildren); | 1168 | parent->children = GNUNET_realloc (parent->children, parent->nchildren); |
1169 | return GNUNET_OK; | 1169 | return node; |
1170 | } | 1170 | } |
1171 | 1171 | ||
1172 | 1172 | ||
@@ -1186,6 +1186,7 @@ static int | |||
1186 | tunnel_add_path(struct MeshTunnel *t, struct MeshPeerPath *p) | 1186 | tunnel_add_path(struct MeshTunnel *t, struct MeshPeerPath *p) |
1187 | { | 1187 | { |
1188 | struct MeshTunnelPathNode *parent; | 1188 | struct MeshTunnelPathNode *parent; |
1189 | struct MeshTunnelPathNode *oldnode; | ||
1189 | struct MeshTunnelPathNode *n; | 1190 | struct MeshTunnelPathNode *n; |
1190 | struct GNUNET_PeerIdentity id; | 1191 | struct GNUNET_PeerIdentity id; |
1191 | struct GNUNET_PeerIdentity hop; | 1192 | struct GNUNET_PeerIdentity hop; |
@@ -1201,7 +1202,7 @@ tunnel_add_path(struct MeshTunnel *t, struct MeshPeerPath *p) | |||
1201 | } | 1202 | } |
1202 | /* Ignore return value, if not found it's ok. */ | 1203 | /* Ignore return value, if not found it's ok. */ |
1203 | GNUNET_PEER_resolve(p->peers[p->length - 1], &id); | 1204 | GNUNET_PEER_resolve(p->peers[p->length - 1], &id); |
1204 | tunnel_del_path(t, peer_info_get(&id)); | 1205 | oldnode = tunnel_del_path(t, peer_info_get(&id)); |
1205 | /* Look for the first node that is not already present in the tree | 1206 | /* Look for the first node that is not already present in the tree |
1206 | * | 1207 | * |
1207 | * Assuming that the tree is somewhat balanced, O(log n * log N). | 1208 | * Assuming that the tree is somewhat balanced, O(log n * log N). |
@@ -1228,23 +1229,38 @@ tunnel_add_path(struct MeshTunnel *t, struct MeshPeerPath *p) | |||
1228 | } | 1229 | } |
1229 | if (-1 == me) | 1230 | if (-1 == me) |
1230 | { | 1231 | { |
1231 | /* New path deviates from tree before reaching us. What happened ?*/ | 1232 | /* New path deviates from tree before reaching us. What happened? */ |
1232 | GNUNET_break (0); | 1233 | GNUNET_break (0); |
1233 | return GNUNET_SYSERR; | 1234 | return GNUNET_SYSERR; |
1234 | } | 1235 | } |
1235 | /* Add the rest of the path as a branch from parent. */ | 1236 | /* Add the rest of the path as a branch from parent. */ |
1236 | while (i < p->length) | 1237 | while (i < p->length) |
1237 | { | 1238 | { |
1238 | parent->children = GNUNET_realloc(parent->children, parent->nchildren); | ||
1239 | parent->nchildren++; | 1239 | parent->nchildren++; |
1240 | GNUNET_PEER_resolve(p->peers[i], &id); | 1240 | parent->children = GNUNET_realloc(parent->children, parent->nchildren); |
1241 | n->peer = peer_info_get(&id); | 1241 | n = &parent->children[parent->nchildren - 1]; |
1242 | if (i == p->length - 1) | ||
1243 | { | ||
1244 | if (NULL != oldnode) | ||
1245 | { | ||
1246 | /* Assignation and free can be misleading, using explicit mempcy */ | ||
1247 | memcpy (n, oldnode, sizeof(struct MeshTunnelPathNode)); | ||
1248 | GNUNET_free (oldnode); | ||
1249 | } | ||
1250 | n->status = MESH_PEER_WAITING; | ||
1251 | } | ||
1252 | else | ||
1253 | { | ||
1254 | n->t = t; | ||
1255 | n->status = MESH_PEER_RELAY; | ||
1256 | GNUNET_PEER_resolve(p->peers[i], &id); | ||
1257 | n->peer = peer_info_get(&id); | ||
1258 | } | ||
1242 | n->parent = parent; | 1259 | n->parent = parent; |
1243 | n->t = t; | ||
1244 | n->status = MESH_PEER_RELAY; | ||
1245 | i++; | 1260 | i++; |
1261 | parent = n; | ||
1246 | } | 1262 | } |
1247 | n->status = MESH_PEER_SEARCHING; | 1263 | |
1248 | /* Add info about first hop into hashmap. */ | 1264 | /* Add info about first hop into hashmap. */ |
1249 | if (me < p->length - 1) | 1265 | if (me < p->length - 1) |
1250 | { | 1266 | { |