aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-09-16 20:44:43 +0000
committerBart Polot <bart@net.in.tum.de>2011-09-16 20:44:43 +0000
commit20e4f54aa38c685e9510e483afbad566ba28a286 (patch)
treeb37280abdf663996b0f076446dc7f66511fe4884 /src
parent2bb81a442abdc6fb699c2379d1437264f3a02d75 (diff)
downloadgnunet-20e4f54aa38c685e9510e483afbad566ba28a286.tar.gz
gnunet-20e4f54aa38c685e9510e483afbad566ba28a286.zip
Added code to create siglne paths from trees
Fixed create path packet creation Fixed memory leakage on tunnel destroy Added more debugging output to help locate problems Tried to change comments so gnu indent doesn't break the code SO badly
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh.c192
1 files changed, 150 insertions, 42 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 4e9b62615..f2e0e33ed 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -493,6 +493,13 @@ struct MeshClient
493 */ 493 */
494 struct GNUNET_DHT_GetHandle *dht_get_type; 494 struct GNUNET_DHT_GetHandle *dht_get_type;
495 495
496#if MESH_DEBUG
497 /**
498 * ID of the client, for debug messages
499 */
500 unsigned int id;
501#endif
502
496}; 503};
497 504
498/******************************************************************************/ 505/******************************************************************************/
@@ -570,6 +577,10 @@ GNUNET_SCHEDULER_TaskIdentifier announce_applications_task;
570 */ 577 */
571GNUNET_SCHEDULER_TaskIdentifier announce_id_task; 578GNUNET_SCHEDULER_TaskIdentifier announce_id_task;
572 579
580#if MESH_DEBUG
581unsigned int next_client_id;
582#endif
583
573 584
574/******************************************************************************/ 585/******************************************************************************/
575/************************ PERIODIC FUNCTIONS ****************************/ 586/************************ PERIODIC FUNCTIONS ****************************/
@@ -776,6 +787,26 @@ path_destroy (struct MeshPeerPath *p)
776 787
777 788
778/** 789/**
790 * Invert the path
791 *
792 * @param p the path to invert
793 */
794static void
795path_invert (struct MeshPeerPath *path)
796{
797 GNUNET_PEER_Id aux;
798 unsigned int i;
799
800 for (i = 0; i < path->length / 2; i++)
801 {
802 aux = path->peers[i];
803 path->peers[i] = path->peers[path->length - i - 1];
804 path->peers[path->length - i - 1] = aux;
805 }
806}
807
808
809/**
779 * Find the first peer whom to send a packet to go down this path 810 * Find the first peer whom to send a packet to go down this path
780 * 811 *
781 * @param t The tunnel to use 812 * @param t The tunnel to use
@@ -948,15 +979,7 @@ path_remove_from_peer (struct MeshPeerInfo *peer, GNUNET_PEER_Id p1,
948static void 979static void
949path_add_to_origin (struct MeshPeerInfo *peer_info, struct MeshPeerPath *path) 980path_add_to_origin (struct MeshPeerInfo *peer_info, struct MeshPeerPath *path)
950{ 981{
951 GNUNET_PEER_Id aux; 982 path_invert(path);
952 unsigned int i;
953
954 for (i = 0; i < path->length / 2; i++)
955 {
956 aux = path->peers[i];
957 path->peers[i] = path->peers[path->length - i - 1];
958 path->peers[path->length - i - 1] = aux;
959 }
960 path_add_to_peer (peer_info, path); 983 path_add_to_peer (peer_info, path);
961} 984}
962 985
@@ -1193,6 +1216,42 @@ tunnel_del_path (struct MeshTunnel *t, struct MeshPeerInfo *peer)
1193 1216
1194 1217
1195/** 1218/**
1219 * Return a newly allocated individual path to reach a peer from the local peer,
1220 * according to the path tree of some tunnel.
1221 *
1222 * @param t Tunnel from which to read the path tree
1223 * @param peer_info Destination peer to whom we want a path
1224 *
1225 * @return A newly allocated individual path to reach the destination peer.
1226 * Path must be destroyed afterwards.
1227 */
1228static struct MeshPeerPath *
1229tunnel_get_path_to_peer(struct MeshTunnel *t, struct MeshPeerInfo *peer_info)
1230{
1231 struct MeshTunnelPathNode *n;
1232 struct MeshPeerPath *p;
1233
1234 n = tunnel_find_peer(t->paths->me, peer_info);
1235 p = GNUNET_malloc(sizeof(struct MeshPeerPath));
1236
1237 /* Building the path (inverted!) */
1238 while (n->peer->id != myid)
1239 {
1240 GNUNET_array_append(p->peers, p->length, n->peer->id);
1241 GNUNET_PEER_change_rc(n->peer->id, 1);
1242 n = n->parent;
1243 GNUNET_assert(NULL != n);
1244 }
1245 GNUNET_array_append(p->peers, p->length, myid);
1246 GNUNET_PEER_change_rc(myid, 1);
1247
1248 path_invert(p);
1249
1250 return p;
1251}
1252
1253
1254/**
1196 * Integrate a stand alone path into the tunnel tree. 1255 * Integrate a stand alone path into the tunnel tree.
1197 * 1256 *
1198 * @param t Tunnel where to add the new path. 1257 * @param t Tunnel where to add the new path.
@@ -1341,6 +1400,8 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer)
1341 * @param peer Peer that (at least) has been affected by the disconnection 1400 * @param peer Peer that (at least) has been affected by the disconnection
1342 * @param p1 Peer that got disconnected from p2 1401 * @param p1 Peer that got disconnected from p2
1343 * @param p2 Peer that got disconnected from p1 1402 * @param p2 Peer that got disconnected from p1
1403 *
1404 * FIXME path
1344 */ 1405 */
1345static void 1406static void
1346tunnel_notify_connection_broken (struct MeshTunnel *t, 1407tunnel_notify_connection_broken (struct MeshTunnel *t,
@@ -1366,10 +1427,14 @@ tunnel_destroy (struct MeshTunnel *t)
1366 GNUNET_HashCode hash; 1427 GNUNET_HashCode hash;
1367 int r; 1428 int r;
1368 1429
1430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: DESTROYING TUNNEL at %p\n", t);
1369 if (NULL == t) 1431 if (NULL == t)
1370 return GNUNET_OK; 1432 return GNUNET_OK;
1371 1433
1372 c = t->client; 1434 c = t->client;
1435#if MESH_DEBUG
1436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: by client %u\n", c->id);
1437#endif
1373 1438
1374 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); 1439 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
1375 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (tunnels, &hash, t)) 1440 if (GNUNET_YES != GNUNET_CONTAINER_multihashmap_remove (tunnels, &hash, t))
@@ -1398,6 +1463,27 @@ tunnel_destroy (struct MeshTunnel *t)
1398} 1463}
1399 1464
1400 1465
1466/**
1467 * tunnel_destroy_iterator: iterator for deleting each tunnel that belongs to a
1468 * client when the client disconnects.
1469 *
1470 * @param cls closure (client that is disconnecting)
1471 * @param key the hash of the local tunnel id (used to access the hashmap)
1472 * @param value the value stored at the key (tunnel to destroy)
1473 *
1474 * @return GNUNET_OK on success
1475 */
1476static int
1477tunnel_destroy_iterator (void *cls, const GNUNET_HashCode * key, void *value)
1478{
1479 int r;
1480
1481 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: D %p\n", value);
1482 r = tunnel_destroy ((struct MeshTunnel *) value);
1483 return r;
1484}
1485
1486
1401/******************************************************************************/ 1487/******************************************************************************/
1402/**************** MESH NETWORK HANDLER HELPERS ***********************/ 1488/**************** MESH NETWORK HANDLER HELPERS ***********************/
1403/******************************************************************************/ 1489/******************************************************************************/
@@ -2236,28 +2322,12 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
2236/******************************************************************************/ 2322/******************************************************************************/
2237 2323
2238/** 2324/**
2239 * delete_tunnel_entry: iterator for deleting each tunnel that belongs to a
2240 * client when the client disconnects.
2241 * @param cls closure (client that is disconnecting)
2242 * @param key the hash of the local tunnel id (used to access the hashmap)
2243 * @param value the value stored at the key (tunnel to destroy)
2244 * @return GNUNET_OK on success
2245 */
2246static int
2247delete_tunnel_entry (void *cls, const GNUNET_HashCode * key, void *value)
2248{
2249 int r;
2250
2251 r = tunnel_destroy ((struct MeshTunnel *) value);
2252 return r;
2253}
2254
2255
2256/**
2257 * deregister_app: iterator for removing each application registered by a client 2325 * deregister_app: iterator for removing each application registered by a client
2326 *
2258 * @param cls closure 2327 * @param cls closure
2259 * @param key the hash of the application id (used to access the hashmap) 2328 * @param key the hash of the application id (used to access the hashmap)
2260 * @param value the value stored at the key (client) 2329 * @param value the value stored at the key (client)
2330 *
2261 * @return GNUNET_OK on success 2331 * @return GNUNET_OK on success
2262 */ 2332 */
2263static int 2333static int
@@ -2399,6 +2469,7 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
2399 struct GNUNET_PeerIdentity id; 2469 struct GNUNET_PeerIdentity id;
2400 struct MeshTunnel *t = cls; 2470 struct MeshTunnel *t = cls;
2401 struct MeshPeerInfo *peer_info; 2471 struct MeshPeerInfo *peer_info;
2472 struct MeshPathInfo *path_info;
2402 struct MeshPeerPath *p; 2473 struct MeshPeerPath *p;
2403 int i; 2474 int i;
2404 2475
@@ -2441,6 +2512,12 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
2441 2512
2442 p = path_build_from_dht (get_path, put_path); 2513 p = path_build_from_dht (get_path, put_path);
2443 path_add_to_peer (peer_info, p); 2514 path_add_to_peer (peer_info, p);
2515 tunnel_add_peer(t, peer_info);
2516 p = tunnel_get_path_to_peer(t, peer_info);
2517 path_info = GNUNET_malloc(sizeof(struct MeshPathInfo));
2518 path_info->t = t;
2519 path_info->peer = peer_info;
2520 path_info->path = p;
2444#if MESH_DEBUG 2521#if MESH_DEBUG
2445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2522 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2446 "MESH: new route for tunnel 0x%x found, has %u hops\n", 2523 "MESH: new route for tunnel 0x%x found, has %u hops\n",
@@ -2454,14 +2531,24 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
2454#endif 2531#endif
2455 2532
2456 GNUNET_PEER_resolve (p->peers[1], &id); 2533 GNUNET_PEER_resolve (p->peers[1], &id);
2457 GNUNET_CORE_notify_transmit_ready (core_handle, /* handle */ 2534 GNUNET_CORE_notify_transmit_ready (core_handle,
2458 0, /* cork */ 2535 /* handle */
2459 0, /* priority */ 2536 0,
2460 GNUNET_TIME_UNIT_FOREVER_REL, /* timeout */ 2537 /* cork */
2461 &id, /* target */ 2538 0,
2462 sizeof (struct GNUNET_MESH_ManipulatePath) + (p->length * sizeof (struct GNUNET_PeerIdentity)), /*size */ 2539 /* priority */
2463 &send_core_create_path, /* callback */ 2540 GNUNET_TIME_UNIT_FOREVER_REL,
2464 peer_info); /* cls */ 2541 /* timeout */
2542 &id,
2543 /* target */
2544 sizeof (struct GNUNET_MESH_ManipulatePath)
2545 +
2546 (p->length *
2547 sizeof (struct GNUNET_PeerIdentity)),
2548 /*size */
2549 &send_core_create_path,
2550 /* callback */
2551 path_info); /* cls */
2465} 2552}
2466 2553
2467/******************************************************************************/ 2554/******************************************************************************/
@@ -2477,16 +2564,18 @@ dht_get_type_handler (void *cls, struct GNUNET_TIME_Absolute exp,
2477 * for the last call when the server is destroyed 2564 * for the last call when the server is destroyed
2478 */ 2565 */
2479static void 2566static void
2480handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) 2567handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
2481{ 2568{
2482 struct MeshClient *c; 2569 struct MeshClient *c;
2483 struct MeshClient *next; 2570 struct MeshClient *next;
2484 2571
2485 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: client disconnected\n"); 2572 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: client disconnected\n");
2573 if (client == NULL)
2574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: (SERVER DOWN)\n");
2486 c = clients; 2575 c = clients;
2487 while (NULL != c) 2576 while (NULL != c)
2488 { 2577 {
2489 if (c->handle != client) 2578 if (c->handle != client && NULL != client)
2490 { 2579 {
2491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... searching\n"); 2580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... searching\n");
2492 c = c->next; 2581 c = c->next;
@@ -2495,7 +2584,8 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
2495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: matching client found\n"); 2584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: matching client found\n");
2496 if (NULL != c->tunnels) 2585 if (NULL != c->tunnels)
2497 { 2586 {
2498 GNUNET_CONTAINER_multihashmap_iterate (c->tunnels, &delete_tunnel_entry, 2587 GNUNET_CONTAINER_multihashmap_iterate (c->tunnels,
2588 &tunnel_destroy_iterator,
2499 c); 2589 c);
2500 GNUNET_CONTAINER_multihashmap_destroy (c->tunnels); 2590 GNUNET_CONTAINER_multihashmap_destroy (c->tunnels);
2501 } 2591 }
@@ -2563,6 +2653,9 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
2563 2653
2564 /* Create new client structure */ 2654 /* Create new client structure */
2565 c = GNUNET_malloc (sizeof (struct MeshClient)); 2655 c = GNUNET_malloc (sizeof (struct MeshClient));
2656#if MESH_DEBUG
2657 c->id = next_client_id++;
2658#endif
2566 c->handle = client; 2659 c->handle = client;
2567 a = (GNUNET_MESH_ApplicationType *) &cc_msg[1]; 2660 a = (GNUNET_MESH_ApplicationType *) &cc_msg[1];
2568 if (napps > 0) 2661 if (napps > 0)
@@ -2574,6 +2667,7 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
2574 for (i = 0; i < napps; i++) 2667 for (i = 0; i < napps; i++)
2575 { 2668 {
2576 at = ntohl (a[i]); 2669 at = ntohl (a[i]);
2670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: app type: %u\n", at);
2577 GNUNET_CRYPTO_hash (&at, sizeof (at), &hc); 2671 GNUNET_CRYPTO_hash (&at, sizeof (at), &hc);
2578 /* store in clients hashmap */ 2672 /* store in clients hashmap */
2579 GNUNET_CONTAINER_multihashmap_put (c->apps, &hc, c, 2673 GNUNET_CONTAINER_multihashmap_put (c->apps, &hc, c,
@@ -2615,7 +2709,9 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
2615 GNUNET_SERVER_notification_context_add (nc, client); 2709 GNUNET_SERVER_notification_context_add (nc, client);
2616 2710
2617 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2711 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2618 2712#if MESH_DEBUG
2713 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: new client processed\n");
2714#endif
2619} 2715}
2620 2716
2621 2717
@@ -2644,6 +2740,9 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
2644 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 2740 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2645 return; 2741 return;
2646 } 2742 }
2743#if MESH_DEBUG
2744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: by client %u\n", c->id);
2745#endif
2647 2746
2648 /* Message sanity check */ 2747 /* Message sanity check */
2649 if (sizeof (struct GNUNET_MESH_TunnelMessage) != ntohs (message->size)) 2748 if (sizeof (struct GNUNET_MESH_TunnelMessage) != ntohs (message->size))
@@ -2670,6 +2769,7 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
2670 } 2769 }
2671 2770
2672 t = GNUNET_malloc (sizeof (struct MeshTunnel)); 2771 t = GNUNET_malloc (sizeof (struct MeshTunnel));
2772 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: CREATED TUNNEL at %p\n", t);
2673 while (NULL != tunnel_get_by_pi (myid, next_tid)) 2773 while (NULL != tunnel_get_by_pi (myid, next_tid))
2674 next_tid = (next_tid + 1) & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; 2774 next_tid = (next_tid + 1) & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
2675 t->id.tid = next_tid++; 2775 t->id.tid = next_tid++;
@@ -2736,7 +2836,9 @@ handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
2736 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 2836 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
2737 return; 2837 return;
2738 } 2838 }
2739 2839#if MESH_DEBUG
2840 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: by client %u\n", c->id);
2841#endif
2740 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message; 2842 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
2741 2843
2742 /* Retrieve tunnel */ 2844 /* Retrieve tunnel */
@@ -2751,7 +2853,8 @@ handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
2751 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash); 2853 GNUNET_CRYPTO_hash (&t->id, sizeof (struct MESH_TunnelID), &hash);
2752 GNUNET_CONTAINER_multihashmap_remove (tunnels, &hash, t); 2854 GNUNET_CONTAINER_multihashmap_remove (tunnels, &hash, t);
2753 2855
2754// notify_tunnel_destroy(t); 2856// notify_tunnel_destroy(t); FIXME
2857 tunnel_destroy(t);
2755 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2858 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2756 return; 2859 return;
2757} 2860}
@@ -3314,7 +3417,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
3314{ 3417{
3315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: starting to run\n"); 3418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: starting to run\n");
3316 GNUNET_SERVER_add_handlers (server, client_handlers); 3419 GNUNET_SERVER_add_handlers (server, client_handlers);
3317 GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL); 3420 GNUNET_SERVER_disconnect_notify (server,
3421 &handle_local_client_disconnect,
3422 NULL);
3318 server_handle = server; 3423 server_handle = server;
3319 core_handle = GNUNET_CORE_connect (c, /* Main configuration */ 3424 core_handle = GNUNET_CORE_connect (c, /* Main configuration */
3320 CORE_QUEUE_SIZE, /* queue size */ 3425 CORE_QUEUE_SIZE, /* queue size */
@@ -3352,6 +3457,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
3352 LOCAL_QUEUE_SIZE); 3457 LOCAL_QUEUE_SIZE);
3353 clients = NULL; 3458 clients = NULL;
3354 clients_tail = NULL; 3459 clients_tail = NULL;
3460#if MESH_DEBUG
3461 next_client_id = 0;
3462#endif
3355 3463
3356 announce_applications_task = GNUNET_SCHEDULER_NO_TASK; 3464 announce_applications_task = GNUNET_SCHEDULER_NO_TASK;
3357 3465