aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-09-30 12:51:57 +0000
committerBart Polot <bart@net.in.tum.de>2011-09-30 12:51:57 +0000
commit2627caf2e563599f3cbc980eafe1e4d68fb32c2f (patch)
tree9498feda3e4a39e4c937bf6147209fcf8730b28b /src/mesh
parent4c3512dc834a6be9da4a8a656f596da536ca67f4 (diff)
downloadgnunet-2627caf2e563599f3cbc980eafe1e4d68fb32c2f.tar.gz
gnunet-2627caf2e563599f3cbc980eafe1e4d68fb32c2f.zip
Added send path create on new peer with direct connection, added resource liberation on neighbor disconnection which queued messages
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c62
1 files changed, 57 insertions, 5 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 86030c05b..19affd5a6 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -146,7 +146,12 @@ struct MeshPeerInfo
146 /** 146 /**
147 * Pointer to info stuctures used as cls for queued transmissions 147 * Pointer to info stuctures used as cls for queued transmissions
148 */ 148 */
149 struct MeshDataDescriptor *infos[CORE_QUEUE_SIZE]; 149 void *infos[CORE_QUEUE_SIZE];
150
151 /**
152 * Type of message being in each transmission
153 */
154 uint16_t types[CORE_QUEUE_SIZE];
150 155
151 /** 156 /**
152 * Array of tunnels this peer participates in 157 * Array of tunnels this peer participates in
@@ -1318,6 +1323,7 @@ send_core_data_multicast (void *cls, size_t size, void *buf)
1318 1323
1319 GNUNET_PEER_resolve(info->peer->id, &id); 1324 GNUNET_PEER_resolve(info->peer->id, &id);
1320 info->peer->infos[info->handler_n] = info; 1325 info->peer->infos[info->handler_n] = info;
1326 info->peer->types[info->handler_n] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST;
1321 info->peer->core_transmit[info->handler_n] = 1327 info->peer->core_transmit[info->handler_n] =
1322 GNUNET_CORE_notify_transmit_ready (core_handle, 1328 GNUNET_CORE_notify_transmit_ready (core_handle,
1323 0, 1329 0,
@@ -1802,6 +1808,7 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
1802 } 1808 }
1803 info->handler_n = i; 1809 info->handler_n = i;
1804 info->peer->infos[i] = info; 1810 info->peer->infos[i] = info;
1811 info->peer->types[i] = GNUNET_MESSAGE_TYPE_MESH_MULTICAST;
1805 info->peer->core_transmit[i] = 1812 info->peer->core_transmit[i] =
1806 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, 1813 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
1807 GNUNET_TIME_UNIT_FOREVER_REL, id, 1814 GNUNET_TIME_UNIT_FOREVER_REL, id,
@@ -2612,10 +2619,11 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client,
2612 const struct GNUNET_MessageHeader *message) 2619 const struct GNUNET_MessageHeader *message)
2613{ 2620{
2614 struct GNUNET_MESH_PeerControl *peer_msg; 2621 struct GNUNET_MESH_PeerControl *peer_msg;
2622 struct MeshPathInfo *path_info;
2623 struct MeshPeerInfo *peer_info;
2615 struct MeshClient *c; 2624 struct MeshClient *c;
2616 struct MeshTunnel *t; 2625 struct MeshTunnel *t;
2617 MESH_TunnelNumber tid; 2626 MESH_TunnelNumber tid;
2618 struct MeshPeerInfo *peer_info;
2619 2627
2620 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n"); 2628 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: Got connection request\n");
2621 /* Sanity check for client registration */ 2629 /* Sanity check for client registration */
@@ -2659,8 +2667,6 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client,
2659 /* Start DHT search if needed, otherwise just add peer to tunnel. */ 2667 /* Start DHT search if needed, otherwise just add peer to tunnel. */
2660 if (NULL == peer_info->dhtget && NULL == peer_info->path_head) 2668 if (NULL == peer_info->dhtget && NULL == peer_info->path_head)
2661 { 2669 {
2662 struct MeshPathInfo *path_info;
2663
2664 path_info = GNUNET_malloc(sizeof(struct MeshPathInfo)); 2670 path_info = GNUNET_malloc(sizeof(struct MeshPathInfo));
2665 path_info->peer = peer_info; 2671 path_info->peer = peer_info;
2666 path_info->t = t; 2672 path_info->t = t;
@@ -2675,10 +2681,37 @@ handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client,
2675 &dht_get_id_handler, 2681 &dht_get_id_handler,
2676 (void *) path_info); 2682 (void *) path_info);
2677 } 2683 }
2678 if (NULL != peer_info->path_head) 2684 else if (NULL != peer_info->path_head)
2679 { 2685 {
2686 unsigned int i;
2687 for (i = 0; i < CORE_QUEUE_SIZE; i++)
2688 {
2689 if (NULL == peer_info->core_transmit[i])
2690 break;
2691 }
2692 if (CORE_QUEUE_SIZE == i)
2693 {
2694 GNUNET_break (0);
2695 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2696 return;
2697 }
2698 path_info = GNUNET_malloc(sizeof(struct MeshPathInfo));
2699 path_info->peer = peer_info;
2700 path_info->t = t;
2680 tunnel_add_peer(t, peer_info); 2701 tunnel_add_peer(t, peer_info);
2702 path_info->path = tree_get_path_to_peer(t->tree, peer_info->id);
2703 peer_info = peer_info_get(path_get_first_hop(t->tree, path_info->peer->id));
2704 peer_info->infos[i] = path_info;
2705 peer_info->types[i] = GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE;
2706 peer_info->core_transmit[i] =
2707 GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0,
2708 GNUNET_TIME_UNIT_FOREVER_REL,
2709 path_get_first_hop(t->tree,
2710 path_info->peer->id),
2711 sizeof (struct GNUNET_MessageHeader),
2712 &send_core_create_path, path_info);
2681 } 2713 }
2714 /* Otherwise: there is no path yet, but there is a DHT_get active already. */
2682 GNUNET_SERVER_receive_done (client, GNUNET_OK); 2715 GNUNET_SERVER_receive_done (client, GNUNET_OK);
2683 return; 2716 return;
2684} 2717}
@@ -3095,8 +3128,27 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
3095 { 3128 {
3096 if (pi->core_transmit[i]) 3129 if (pi->core_transmit[i])
3097 { 3130 {
3131 struct MeshDataDescriptor *dd;
3132 struct MeshPathInfo *path_info;
3098 GNUNET_CORE_notify_transmit_ready_cancel (pi->core_transmit[i]); 3133 GNUNET_CORE_notify_transmit_ready_cancel (pi->core_transmit[i]);
3099 /* TODO: notify that tranmission has failed */ 3134 /* TODO: notify that tranmission has failed */
3135 switch (pi->types[i])
3136 {
3137 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
3138 case GNUNET_MESSAGE_TYPE_MESH_UNICAST:
3139 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
3140 dd = pi->infos[i];
3141 if (0 == --(*dd->copies))
3142 {
3143 GNUNET_free (dd->copies);
3144 GNUNET_free (dd->data);
3145 }
3146 break;
3147 case GNUNET_MESSAGE_TYPE_MESH_PATH_CREATE:
3148 path_info = pi->infos[i];
3149 path_destroy(path_info->path);
3150 break;
3151 }
3100 GNUNET_free (pi->infos[i]); 3152 GNUNET_free (pi->infos[i]);
3101 } 3153 }
3102 } 3154 }