aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-12-20 17:03:22 +0000
committerBart Polot <bart@net.in.tum.de>2012-12-20 17:03:22 +0000
commit70d43fa030afdbc411bd293434711f3d45fa026b (patch)
tree0d875973ea039b6f225011ec1874b5b067e251b4 /src/mesh
parent0b691ca20af8d64a330fe7ae73eaaf071d8100fb (diff)
downloadgnunet-70d43fa030afdbc411bd293434711f3d45fa026b.tar.gz
gnunet-70d43fa030afdbc411bd293434711f3d45fa026b.zip
- notify owner of disconnecting peers
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c64
1 files changed, 50 insertions, 14 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 7fae00227..7ecff0a83 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -2157,6 +2157,32 @@ client_delete_tunnel (struct MeshClient *c, struct MeshTunnel *t)
2157 2157
2158 2158
2159/** 2159/**
2160 * Notify the owner of a tunnel that a peer has disconnected.
2161 *
2162 * @param c Client (owner of tunnel).
2163 * @param t Tunnel this message is about.
2164 * @param peer_id Short ID of the disconnected peer.
2165 */
2166void
2167client_notify_peer_disconnected (struct MeshClient *c,
2168 struct MeshTunnel *t,
2169 GNUNET_PEER_Id peer_id)
2170{
2171 struct GNUNET_MESH_PeerControl msg;
2172
2173 if (NULL == t->owner || NULL == nc)
2174 return;
2175
2176 msg.header.size = htons (sizeof (msg));
2177 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
2178 msg.tunnel_id = htonl (t->local_tid);
2179 GNUNET_PEER_resolve (peer_id, &msg.peer);
2180 GNUNET_SERVER_notification_context_unicast (nc, t->owner->handle,
2181 &msg.header, GNUNET_NO);
2182}
2183
2184
2185/**
2160 * Send the message to all clients that have subscribed to its type 2186 * Send the message to all clients that have subscribed to its type
2161 * 2187 *
2162 * @param msg Pointer to the message itself 2188 * @param msg Pointer to the message itself
@@ -3408,17 +3434,8 @@ tunnel_notify_client_peer_disconnected (void *cls, GNUNET_PEER_Id peer_id)
3408 struct MeshPeerInfo *peer; 3434 struct MeshPeerInfo *peer;
3409 struct MeshPathInfo *path_info; 3435 struct MeshPathInfo *path_info;
3410 3436
3411 if (NULL != t->owner && NULL != nc) 3437 client_notify_peer_disconnected (t->owner, t, peer_id);
3412 {
3413 struct GNUNET_MESH_PeerControl msg;
3414 3438
3415 msg.header.size = htons (sizeof (msg));
3416 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
3417 msg.tunnel_id = htonl (t->local_tid);
3418 GNUNET_PEER_resolve (peer_id, &msg.peer);
3419 GNUNET_SERVER_notification_context_unicast (nc, t->owner->handle,
3420 &msg.header, GNUNET_NO);
3421 }
3422 peer = peer_info_get_short (peer_id); 3439 peer = peer_info_get_short (peer_id);
3423 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo)); 3440 path_info = GNUNET_malloc (sizeof (struct MeshPathInfo));
3424 path_info->peer = peer; 3441 path_info->peer = peer;
@@ -4695,6 +4712,19 @@ tunnel_new (GNUNET_PEER_Id owner,
4695 return t; 4712 return t;
4696} 4713}
4697 4714
4715/**
4716 * Callback when removing children from a tunnel tree. Notify owner.
4717 *
4718 * @param cls Closure (tunnel).
4719 * @param peer_id Short ID of the peer deleted.
4720 */
4721void
4722tunnel_child_removed (void *cls, GNUNET_PEER_Id peer_id)
4723{
4724 struct MeshTunnel *t = cls;
4725
4726 client_notify_peer_disconnected (t->owner, t, peer_id);
4727}
4698 4728
4699/** 4729/**
4700 * Removes an explicit path from a tunnel, freeing all intermediate nodes 4730 * Removes an explicit path from a tunnel, freeing all intermediate nodes
@@ -4709,7 +4739,7 @@ tunnel_delete_peer (struct MeshTunnel *t, GNUNET_PEER_Id peer)
4709{ 4739{
4710 int r; 4740 int r;
4711 4741
4712 r = tree_del_peer (t->tree, peer, NULL, NULL); 4742 r = tree_del_peer (t->tree, peer, &tunnel_child_removed, t);
4713 if (GNUNET_NO == r) 4743 if (GNUNET_NO == r)
4714 { 4744 {
4715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -5789,6 +5819,8 @@ handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
5789{ 5819{
5790 struct GNUNET_MESH_TunnelDestroy *msg; 5820 struct GNUNET_MESH_TunnelDestroy *msg;
5791 struct MeshTunnel *t; 5821 struct MeshTunnel *t;
5822 GNUNET_PEER_Id parent;
5823 GNUNET_PEER_Id pid;
5792 5824
5793 msg = (struct GNUNET_MESH_TunnelDestroy *) message; 5825 msg = (struct GNUNET_MESH_TunnelDestroy *) message;
5794 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5826 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -5798,6 +5830,7 @@ handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
5798 " for tunnel %s [%u]\n", 5830 " for tunnel %s [%u]\n",
5799 GNUNET_i2s (&msg->oid), ntohl (msg->tid)); 5831 GNUNET_i2s (&msg->oid), ntohl (msg->tid));
5800 t = tunnel_get (&msg->oid, ntohl (msg->tid)); 5832 t = tunnel_get (&msg->oid, ntohl (msg->tid));
5833 /* Check signature */
5801 if (NULL == t) 5834 if (NULL == t)
5802 { 5835 {
5803 /* Probably already got the message from another path, 5836 /* Probably already got the message from another path,
@@ -5808,10 +5841,13 @@ handle_mesh_tunnel_destroy (void *cls, const struct GNUNET_PeerIdentity *peer,
5808 1, GNUNET_NO); 5841 1, GNUNET_NO);
5809 return GNUNET_OK; 5842 return GNUNET_OK;
5810 } 5843 }
5811 if (t->id.oid == myid) 5844 parent = tree_get_predecessor(t->tree);
5845 pid = GNUNET_PEER_search (peer);
5846 if (pid != parent)
5812 { 5847 {
5813 GNUNET_break_op (0); 5848 tree_del_peer (t->tree, pid, &tunnel_child_removed, t);
5814 return GNUNET_OK; 5849 if (tree_count_children(t->tree) > 0 || NULL != t->owner)
5850 return GNUNET_OK;
5815 } 5851 }
5816 if (t->local_tid_dest >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV) 5852 if (t->local_tid_dest >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
5817 { 5853 {