diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-10-21 11:25:33 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-10-21 11:25:33 +0000 |
commit | 29424a239722a6b30533b12553149760a9a761a8 (patch) | |
tree | fce55046c9540ba780a1ae4ef53ab545ee253e3a /src/mesh | |
parent | 10b6ee1de177d1581be900ca0d54b866aa606f32 (diff) | |
download | gnunet-29424a239722a6b30533b12553149760a9a761a8.tar.gz gnunet-29424a239722a6b30533b12553149760a9a761a8.zip |
Solved Mantis #1834
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 88 |
1 files changed, 51 insertions, 37 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 8d37ae7ab..ca1fc0550 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -148,6 +148,11 @@ struct MeshPeerInfo | |||
148 | struct GNUNET_DHT_GetHandle *dhtget; | 148 | struct GNUNET_DHT_GetHandle *dhtget; |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Closure given to the DHT GET | ||
152 | */ | ||
153 | struct MeshPathInfo *dhtgetcls; | ||
154 | |||
155 | /** | ||
151 | * Handles to stop queued transmissions for this peer | 156 | * Handles to stop queued transmissions for this peer |
152 | */ | 157 | */ |
153 | struct GNUNET_CORE_TransmitHandle *core_transmit[CORE_QUEUE_SIZE]; | 158 | struct GNUNET_CORE_TransmitHandle *core_transmit[CORE_QUEUE_SIZE]; |
@@ -1241,6 +1246,7 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t) | |||
1241 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1246 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1242 | "MESH: Starting DHT GET for peer %s\n", | 1247 | "MESH: Starting DHT GET for peer %s\n", |
1243 | GNUNET_i2s (&id)); | 1248 | GNUNET_i2s (&id)); |
1249 | peer->dhtgetcls = path_info; | ||
1244 | peer->dhtget = | 1250 | peer->dhtget = |
1245 | GNUNET_DHT_get_start(dht_handle, /* handle */ | 1251 | GNUNET_DHT_get_start(dht_handle, /* handle */ |
1246 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ | 1252 | GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ |
@@ -1258,29 +1264,47 @@ peer_info_connect (struct MeshPeerInfo *peer, struct MeshTunnel *t) | |||
1258 | } | 1264 | } |
1259 | 1265 | ||
1260 | 1266 | ||
1261 | #if LATER | ||
1262 | /** | 1267 | /** |
1263 | * Destroy the peer_info and free any allocated resources linked to it | 1268 | * Destroy the peer_info and free any allocated resources linked to it |
1264 | * @param t tunnel the path belongs to | 1269 | * |
1265 | * @param pi the peer_info to destroy | 1270 | * @param pi The peer_info to destroy. |
1271 | * | ||
1266 | * @return GNUNET_OK on success | 1272 | * @return GNUNET_OK on success |
1267 | */ | 1273 | */ |
1268 | static int | 1274 | static int |
1269 | peer_info_destroy (struct MeshPeerInfo *pi) | 1275 | peer_info_destroy (struct MeshPeerInfo *pi) |
1270 | { | 1276 | { |
1271 | GNUNET_HashCode hash; | ||
1272 | struct GNUNET_PeerIdentity id; | 1277 | struct GNUNET_PeerIdentity id; |
1278 | GNUNET_HashCode hash; | ||
1279 | struct MeshPeerPath *p; | ||
1280 | struct MeshPeerPath *nextp; | ||
1281 | unsigned int i; | ||
1273 | 1282 | ||
1274 | GNUNET_PEER_resolve (pi->id, &id); | 1283 | GNUNET_PEER_resolve (pi->id, &id); |
1275 | GNUNET_PEER_change_rc (pi->id, -1); | 1284 | GNUNET_PEER_change_rc (pi->id, -1); |
1276 | GNUNET_CRYPTO_hash (&id, sizeof (struct GNUNET_PeerIdentity), &hash); | 1285 | GNUNET_CRYPTO_hash (&id, sizeof (struct GNUNET_PeerIdentity), &hash); |
1277 | 1286 | ||
1278 | GNUNET_CONTAINER_multihashmap_remove (peers, &hash, pi); | 1287 | GNUNET_CONTAINER_multihashmap_remove (peers, &hash, pi); |
1279 | GNUNET_SCHEDULER_cancel (pi->path_refresh_task); | 1288 | if (NULL != pi->dhtget) |
1289 | { | ||
1290 | GNUNET_DHT_get_stop(pi->dhtget); | ||
1291 | GNUNET_free (pi->dhtgetcls); | ||
1292 | } | ||
1293 | for (i = 0; i < CORE_QUEUE_SIZE; i++) | ||
1294 | { | ||
1295 | peer_info_cancel_transmission(pi, i); | ||
1296 | } | ||
1297 | p = pi->path_head; | ||
1298 | while (NULL != p) | ||
1299 | { | ||
1300 | nextp = p->next; | ||
1301 | GNUNET_CONTAINER_DLL_remove (pi->path_head, pi->path_tail, p); | ||
1302 | path_destroy (p); | ||
1303 | p = nextp; | ||
1304 | } | ||
1280 | GNUNET_free (pi); | 1305 | GNUNET_free (pi); |
1281 | return GNUNET_OK; | 1306 | return GNUNET_OK; |
1282 | } | 1307 | } |
1283 | #endif | ||
1284 | 1308 | ||
1285 | 1309 | ||
1286 | /** | 1310 | /** |
@@ -1337,6 +1361,7 @@ path_remove_from_peer (struct MeshPeerInfo *peer, | |||
1337 | if ((p->peers[i] == p1 && p->peers[i + 1] == p2) || | 1361 | if ((p->peers[i] == p1 && p->peers[i + 1] == p2) || |
1338 | (p->peers[i] == p2 && p->peers[i + 1] == p1)) | 1362 | (p->peers[i] == p2 && p->peers[i + 1] == p1)) |
1339 | { | 1363 | { |
1364 | GNUNET_CONTAINER_DLL_remove (peer->path_head, peer->path_tail, p); | ||
1340 | path_destroy (p); | 1365 | path_destroy (p); |
1341 | destroyed++; | 1366 | destroyed++; |
1342 | break; | 1367 | break; |
@@ -2248,34 +2273,6 @@ send_core_path_ack (void *cls, size_t size, void *buf) | |||
2248 | } | 2273 | } |
2249 | 2274 | ||
2250 | 2275 | ||
2251 | #if LATER | ||
2252 | /** | ||
2253 | * Send another peer a notification to destroy a tunnel | ||
2254 | * @param cls The tunnel to destroy | ||
2255 | * @param size Size in the buffer | ||
2256 | * @param buf Memory where to put the data to transmit | ||
2257 | * @return Size of data put in buffer | ||
2258 | */ | ||
2259 | static size_t | ||
2260 | send_core_tunnel_destroy (void *cls, size_t size, void *buf) | ||
2261 | { | ||
2262 | struct MeshTunnel *t = cls; | ||
2263 | struct MeshClient *c; | ||
2264 | struct GNUNET_MESH_TunnelMessage *msg; | ||
2265 | |||
2266 | c = t->client; | ||
2267 | msg = buf; | ||
2268 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY); | ||
2269 | /*FIXME*/ msg->header.size = | ||
2270 | htons (sizeof (struct GNUNET_MESH_TunnelMessage)); | ||
2271 | msg->tunnel_id = htonl (t->id.tid); | ||
2272 | |||
2273 | tunnel_destroy (c, t); | ||
2274 | return sizeof (struct GNUNET_MESH_TunnelMessage); | ||
2275 | } | ||
2276 | #endif | ||
2277 | |||
2278 | |||
2279 | /******************************************************************************/ | 2276 | /******************************************************************************/ |
2280 | /******************** MESH NETWORK HANDLERS **************************/ | 2277 | /******************** MESH NETWORK HANDLERS **************************/ |
2281 | /******************************************************************************/ | 2278 | /******************************************************************************/ |
@@ -4077,13 +4074,12 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
4077 | /******************************************************************************/ | 4074 | /******************************************************************************/ |
4078 | 4075 | ||
4079 | /** | 4076 | /** |
4080 | * Iterator over hash map entries. | 4077 | * Iterator over tunnel hash map entries to destroy the tunnel during shutdown. |
4081 | * | 4078 | * |
4082 | * @param cls closure | 4079 | * @param cls closure |
4083 | * @param key current key code | 4080 | * @param key current key code |
4084 | * @param value value in the hash map | 4081 | * @param value value in the hash map |
4085 | * @return GNUNET_YES if we should continue to | 4082 | * @return GNUNET_YES if we should continue to iterate, |
4086 | * iterate, | ||
4087 | * GNUNET_NO if not. | 4083 | * GNUNET_NO if not. |
4088 | */ | 4084 | */ |
4089 | int | 4085 | int |
@@ -4095,6 +4091,23 @@ shutdown_tunnel (void *cls, const GNUNET_HashCode * key, void *value) | |||
4095 | } | 4091 | } |
4096 | 4092 | ||
4097 | /** | 4093 | /** |
4094 | * Iterator over peer hash map entries to destroy the tunnel during shutdown. | ||
4095 | * | ||
4096 | * @param cls closure | ||
4097 | * @param key current key code | ||
4098 | * @param value value in the hash map | ||
4099 | * @return GNUNET_YES if we should continue to iterate, | ||
4100 | * GNUNET_NO if not. | ||
4101 | */ | ||
4102 | int | ||
4103 | shutdown_peer (void *cls, const GNUNET_HashCode * key, void *value) | ||
4104 | { | ||
4105 | struct MeshPeerInfo *p = value; | ||
4106 | peer_info_destroy(p); | ||
4107 | return GNUNET_YES; | ||
4108 | } | ||
4109 | |||
4110 | /** | ||
4098 | * Task run during shutdown. | 4111 | * Task run during shutdown. |
4099 | * | 4112 | * |
4100 | * @param cls unused | 4113 | * @param cls unused |
@@ -4111,6 +4124,7 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
4111 | core_handle = NULL; | 4124 | core_handle = NULL; |
4112 | } | 4125 | } |
4113 | GNUNET_CONTAINER_multihashmap_iterate(tunnels, &shutdown_tunnel, NULL); | 4126 | GNUNET_CONTAINER_multihashmap_iterate(tunnels, &shutdown_tunnel, NULL); |
4127 | GNUNET_CONTAINER_multihashmap_iterate(peers, &shutdown_peer, NULL); | ||
4114 | if (dht_handle != NULL) | 4128 | if (dht_handle != NULL) |
4115 | { | 4129 | { |
4116 | GNUNET_DHT_disconnect (dht_handle); | 4130 | GNUNET_DHT_disconnect (dht_handle); |