aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2012-01-18 15:10:50 +0000
committerBart Polot <bart@net.in.tum.de>2012-01-18 15:10:50 +0000
commitbf2b879fe037bb349433db85a4a0cb4b42bfaf6e (patch)
tree70a4e3d135aec5cbbc5c6c76e174ee74554b387f /src/mesh
parent76393615c3bd7443bb41a1f1054b798b8c4a1117 (diff)
downloadgnunet-bf2b879fe037bb349433db85a4a0cb4b42bfaf6e.tar.gz
gnunet-bf2b879fe037bb349433db85a4a0cb4b42bfaf6e.zip
Fixed client shutdown case, various minor fixes
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/gnunet-service-mesh.c61
1 files changed, 59 insertions, 2 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 637005048..08f722611 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -313,6 +313,11 @@ struct MeshTunnel
313 struct MeshClient *client; 313 struct MeshClient *client;
314 314
315 /** 315 /**
316 * Client destination of the tunnel, if any
317 */
318 struct MeshClient *client_dest;
319
320 /**
316 * Messages ready to transmit 321 * Messages ready to transmit
317 */ 322 */
318 struct MeshQueue *queue_head; 323 struct MeshQueue *queue_head;
@@ -902,6 +907,41 @@ send_clients_tunnel_destroy (struct MeshTunnel *t)
902 907
903 908
904/** 909/**
910 * Notify a client that the other local client disconnected, if needed.
911 * In case the origin disconnects, the destination get a tunnel destroy
912 * notification. Otherwise, the origin gets a (local ID) peer disconnected.
913 *
914 * @param t Tunnel that was destroyed.
915 * @param c Client that disconnected
916 */
917static void
918send_client_tunnel_disconnect (struct MeshTunnel *t, struct MeshClient *c)
919{
920 if (c == t->client_dest)
921 {
922 struct GNUNET_MESH_PeerControl msg;
923
924 msg.header.size = htons (sizeof (msg));
925 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL);
926 msg.tunnel_id = htonl (t->local_tid);
927 msg.peer = my_full_id;
928 GNUNET_SERVER_notification_context_unicast (nc, t->client->handle,
929 &msg.header, GNUNET_NO);
930 }
931 else if (NULL != t->client_dest && c == t->client)
932 {
933 struct GNUNET_MESH_TunnelMessage msg;
934
935 msg.header.size = htons (sizeof (msg));
936 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
937 msg.tunnel_id = htonl (t->local_tid_dest);
938 GNUNET_SERVER_notification_context_unicast (nc, t->client_dest->handle,
939 &msg.header, GNUNET_NO);
940 }
941}
942
943
944/**
905 * Function called to notify a client about the socket 945 * Function called to notify a client about the socket
906 * being ready to queue more data. "buf" will be 946 * being ready to queue more data. "buf" will be
907 * NULL and "size" zero if the socket was closed for 947 * NULL and "size" zero if the socket was closed for
@@ -2244,8 +2284,17 @@ static int
2244tunnel_destroy_iterator (void *cls, const GNUNET_HashCode * key, void *value) 2284tunnel_destroy_iterator (void *cls, const GNUNET_HashCode * key, void *value)
2245{ 2285{
2246 struct MeshTunnel *t = value; 2286 struct MeshTunnel *t = value;
2287 struct MeshClient *c = cls;
2247 int r; 2288 int r;
2248 2289
2290 send_client_tunnel_disconnect(t, c);
2291 if (c == t->client_dest)
2292 {
2293 t->client_dest = NULL;
2294 t->local_tid_dest = 0;
2295 return GNUNET_OK;
2296 }
2297 tunnel_send_destroy(t);
2249 r = tunnel_destroy (t); 2298 r = tunnel_destroy (t);
2250 return r; 2299 return r;
2251} 2300}
@@ -3407,13 +3456,16 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
3407 c = clients; 3456 c = clients;
3408 while (NULL != c) 3457 while (NULL != c)
3409 { 3458 {
3410 if (c->handle != client && NULL != client) 3459 if (c->handle != client)
3411 { 3460 {
3412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... searching\n"); 3461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: ... searching\n");
3413 c = c->next; 3462 c = c->next;
3414 continue; 3463 continue;
3415 } 3464 }
3416 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: matching client found\n"); 3465#if MESH_DEBUG
3466 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MESH: matching client found (%u)\n",
3467 c->id);
3468#endif
3417 GNUNET_SERVER_client_drop (c->handle); 3469 GNUNET_SERVER_client_drop (c->handle);
3418 if (NULL != c->tunnels) 3470 if (NULL != c->tunnels)
3419 { 3471 {
@@ -3687,6 +3739,7 @@ handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
3687 /* Remove from local id hashmap */ 3739 /* Remove from local id hashmap */
3688 GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash); 3740 GNUNET_CRYPTO_hash (&tid, sizeof (MESH_TunnelNumber), &hash);
3689 t = GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash); 3741 t = GNUNET_CONTAINER_multihashmap_get (c->tunnels, &hash);
3742 send_client_tunnel_disconnect(t, c);
3690 GNUNET_assert (GNUNET_YES == 3743 GNUNET_assert (GNUNET_YES ==
3691 GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t)); 3744 GNUNET_CONTAINER_multihashmap_remove (c->tunnels, &hash, t));
3692 3745
@@ -3925,6 +3978,10 @@ handle_local_connect_by_type (void *cls, struct GNUNET_SERVER_Client *client,
3925 cmsg.tunnel_id = htonl (t->local_tid_dest); 3978 cmsg.tunnel_id = htonl (t->local_tid_dest);
3926 c = (struct MeshClient *) GNUNET_CONTAINER_multihashmap_get(applications, 3979 c = (struct MeshClient *) GNUNET_CONTAINER_multihashmap_get(applications,
3927 &hash); 3980 &hash);
3981 t->client_dest = c;
3982 GNUNET_CRYPTO_hash (&t->local_tid_dest, sizeof (MESH_TunnelNumber), &hash);
3983 GNUNET_CONTAINER_multihashmap_put (c->tunnels, &hash, t,
3984 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
3928 GNUNET_SERVER_notification_context_unicast (nc, c->handle, &cmsg.header, 3985 GNUNET_SERVER_notification_context_unicast (nc, c->handle, &cmsg.header,
3929 GNUNET_NO); 3986 GNUNET_NO);
3930 3987