diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-05-10 06:59:02 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-05-10 06:59:02 +0000 |
commit | 428d535013f44be1d1389b333b4f95560414b27b (patch) | |
tree | 989826628e6c1cc61c6a6402192e7e16c0f42422 /src | |
parent | efad1d6733cd7e75a4e6c846ad7c031a0167b8be (diff) | |
download | gnunet-428d535013f44be1d1389b333b4f95560414b27b.tar.gz gnunet-428d535013f44be1d1389b333b4f95560414b27b.zip |
- Fixes
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh-new.c | 86 |
1 files changed, 39 insertions, 47 deletions
diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c index 04af3288f..97b9a9f25 100644 --- a/src/mesh/gnunet-service-mesh-new.c +++ b/src/mesh/gnunet-service-mesh-new.c | |||
@@ -383,6 +383,16 @@ struct MeshTunnel | |||
383 | */ | 383 | */ |
384 | GNUNET_PEER_Id peer; | 384 | GNUNET_PEER_Id peer; |
385 | 385 | ||
386 | /** | ||
387 | * Next hop in the tunnel. | ||
388 | */ | ||
389 | GNUNET_PEER_Id next_hop; | ||
390 | |||
391 | /** | ||
392 | * Previous hop in the tunnel. | ||
393 | */ | ||
394 | GNUNET_PEER_Id prev_hop; | ||
395 | |||
386 | /** | 396 | /** |
387 | * Client owner of the tunnel, if any | 397 | * Client owner of the tunnel, if any |
388 | */ | 398 | */ |
@@ -647,7 +657,7 @@ static struct GNUNET_CRYPTO_EccKeyGenerationContext *keygen; | |||
647 | /** | 657 | /** |
648 | * DLL with all the clients, head. | 658 | * DLL with all the clients, head. |
649 | */ | 659 | */ |
650 | static struct MeshClient *clients; | 660 | static struct MeshClient *clients_head; |
651 | 661 | ||
652 | /** | 662 | /** |
653 | * DLL with all the clients, tail. | 663 | * DLL with all the clients, tail. |
@@ -1036,7 +1046,7 @@ client_get (struct GNUNET_SERVER_Client *client) | |||
1036 | { | 1046 | { |
1037 | struct MeshClient *c; | 1047 | struct MeshClient *c; |
1038 | 1048 | ||
1039 | c = clients; | 1049 | c = clients_head; |
1040 | while (NULL != c) | 1050 | while (NULL != c) |
1041 | { | 1051 | { |
1042 | if (c->handle == client) | 1052 | if (c->handle == client) |
@@ -1223,7 +1233,7 @@ send_subscribed_clients (const struct GNUNET_MessageHeader *msg, | |||
1223 | return 0; | 1233 | return 0; |
1224 | } | 1234 | } |
1225 | 1235 | ||
1226 | for (count = 0, c = clients; c != NULL; c = c->next) | 1236 | for (count = 0, c = clients_head; c != NULL; c = c->next) |
1227 | { | 1237 | { |
1228 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client %u\n", c->id); | 1238 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client %u\n", c->id); |
1229 | if (client_is_subscribed (type, c)) | 1239 | if (client_is_subscribed (type, c)) |
@@ -2348,13 +2358,14 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) | |||
2348 | unsigned int cost; | 2358 | unsigned int cost; |
2349 | 2359 | ||
2350 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tunnel_add_peer\n"); | 2360 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tunnel_add_peer\n"); |
2351 | /* FIXME */ | 2361 | |
2352 | if (t->peer != peer->id) | 2362 | if (t->peer != peer->id) |
2353 | { | 2363 | { |
2354 | GNUNET_array_append (peer->tunnels, peer->ntunnels, t); | 2364 | GNUNET_array_append (peer->tunnels, peer->ntunnels, t); |
2355 | t->peer = peer->id; | 2365 | t->peer = peer->id; |
2356 | } | 2366 | } |
2357 | 2367 | ||
2368 | /* FIXME */ | ||
2358 | if (NULL != (p = peer->path_head)) | 2369 | if (NULL != (p = peer->path_head)) |
2359 | { | 2370 | { |
2360 | best_p = p; | 2371 | best_p = p; |
@@ -2381,32 +2392,6 @@ tunnel_add_peer (struct MeshTunnel *t, struct MeshPeerInfo *peer) | |||
2381 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tunnel_add_peer END\n"); | 2392 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tunnel_add_peer END\n"); |
2382 | } | 2393 | } |
2383 | 2394 | ||
2384 | /** | ||
2385 | * Add a path to a tunnel which we don't own, just to remember the next hop. | ||
2386 | * If destination node was already in the tunnel, the first hop information | ||
2387 | * will be replaced with the new path. | ||
2388 | * | ||
2389 | * @param t Tunnel we want to add a new peer to | ||
2390 | * @param p Path to add | ||
2391 | * @param own_pos Position of local node in path. | ||
2392 | * | ||
2393 | */ | ||
2394 | static void | ||
2395 | tunnel_add_path (struct MeshTunnel *t, struct MeshPeerPath *p, | ||
2396 | unsigned int own_pos) | ||
2397 | { | ||
2398 | struct GNUNET_PeerIdentity id; | ||
2399 | |||
2400 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tunnel_add_path\n"); | ||
2401 | GNUNET_assert (0 != own_pos); | ||
2402 | tree_add_path (t->tree, p, NULL, NULL); | ||
2403 | if (own_pos < p->length - 1) | ||
2404 | { | ||
2405 | GNUNET_PEER_resolve (p->peers[own_pos + 1], &id); | ||
2406 | tree_update_first_hops (t->tree, myid, &id); | ||
2407 | } | ||
2408 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "tunnel_add_path END\n"); | ||
2409 | } | ||
2410 | 2395 | ||
2411 | /** | 2396 | /** |
2412 | * Add a client to a tunnel, initializing all needed data structures. | 2397 | * Add a client to a tunnel, initializing all needed data structures. |
@@ -4097,19 +4082,23 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
4097 | return GNUNET_OK; | 4082 | return GNUNET_OK; |
4098 | } | 4083 | } |
4099 | path_add_to_peers (path, GNUNET_NO); | 4084 | path_add_to_peers (path, GNUNET_NO); |
4100 | tunnel_add_path (t, path, own_pos); | 4085 | t->prev_hop = path->peers[own_pos - 1]; |
4086 | GNUNET_PEER_change_rc (t->prev_hop, 1); | ||
4101 | if (own_pos == size - 1) | 4087 | if (own_pos == size - 1) |
4102 | { | 4088 | { |
4103 | /* It is for us! Send ack. */ | 4089 | /* It is for us! Send ack. */ |
4104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n"); | 4090 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n"); |
4105 | peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO); | 4091 | peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO); |
4106 | t->peer = myid; | 4092 | t->peer = path->peers[0]; |
4107 | send_path_ack (t); | 4093 | send_path_ack (t); |
4108 | } | 4094 | } |
4109 | else | 4095 | else |
4110 | { | 4096 | { |
4111 | struct MeshPeerPath *path2; | 4097 | struct MeshPeerPath *path2; |
4112 | 4098 | ||
4099 | t->next_hop = path->peers[own_pos + 1]; | ||
4100 | GNUNET_PEER_change_rc(t->next_hop, 1); | ||
4101 | |||
4113 | /* It's for somebody else! Retransmit. */ | 4102 | /* It's for somebody else! Retransmit. */ |
4114 | path2 = path_duplicate (path); | 4103 | path2 = path_duplicate (path); |
4115 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Retransmitting.\n"); | 4104 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " Retransmitting.\n"); |
@@ -4947,7 +4936,6 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
4947 | { | 4936 | { |
4948 | struct MeshClient *c; | 4937 | struct MeshClient *c; |
4949 | struct MeshClient *next; | 4938 | struct MeshClient *next; |
4950 | unsigned int i; | ||
4951 | 4939 | ||
4952 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disconnected\n"); | 4940 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "client disconnected\n"); |
4953 | if (client == NULL) | 4941 | if (client == NULL) |
@@ -4956,7 +4944,7 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
4956 | return; | 4944 | return; |
4957 | } | 4945 | } |
4958 | 4946 | ||
4959 | c = clients; | 4947 | c = clients_head; |
4960 | while (NULL != c) | 4948 | while (NULL != c) |
4961 | { | 4949 | { |
4962 | if (c->handle != client) | 4950 | if (c->handle != client) |
@@ -4969,8 +4957,6 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
4969 | c->id); | 4957 | c->id); |
4970 | GNUNET_SERVER_client_drop (c->handle); | 4958 | GNUNET_SERVER_client_drop (c->handle); |
4971 | c->shutting_down = GNUNET_YES; | 4959 | c->shutting_down = GNUNET_YES; |
4972 | GNUNET_assert (NULL != c->own_tunnels); | ||
4973 | GNUNET_assert (NULL != c->incoming_tunnels); | ||
4974 | GNUNET_CONTAINER_multihashmap_iterate (c->own_tunnels, | 4960 | GNUNET_CONTAINER_multihashmap_iterate (c->own_tunnels, |
4975 | &tunnel_destroy_iterator, c); | 4961 | &tunnel_destroy_iterator, c); |
4976 | GNUNET_CONTAINER_multihashmap_iterate (c->incoming_tunnels, | 4962 | GNUNET_CONTAINER_multihashmap_iterate (c->incoming_tunnels, |
@@ -4984,13 +4970,13 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
4984 | if (NULL != c->types) | 4970 | if (NULL != c->types) |
4985 | GNUNET_CONTAINER_multihashmap_destroy (c->types); | 4971 | GNUNET_CONTAINER_multihashmap_destroy (c->types); |
4986 | next = c->next; | 4972 | next = c->next; |
4987 | GNUNET_CONTAINER_DLL_remove (clients, clients_tail, c); | 4973 | GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c); |
4988 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " CLIENT FREE at %p\n", c); | 4974 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " CLIENT FREE at %p\n", c); |
4989 | GNUNET_free (c); | 4975 | GNUNET_free (c); |
4990 | GNUNET_STATISTICS_update (stats, "# clients", -1, GNUNET_NO); | 4976 | GNUNET_STATISTICS_update (stats, "# clients", -1, GNUNET_NO); |
4991 | c = next; | 4977 | c = next; |
4992 | } | 4978 | } |
4993 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " done!\n"); | 4979 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "done!\n"); |
4994 | return; | 4980 | return; |
4995 | } | 4981 | } |
4996 | 4982 | ||
@@ -5014,6 +5000,7 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, | |||
5014 | uint16_t i; | 5000 | uint16_t i; |
5015 | 5001 | ||
5016 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new client connected\n"); | 5002 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new client connected\n"); |
5003 | |||
5017 | /* Check data sanity */ | 5004 | /* Check data sanity */ |
5018 | size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect); | 5005 | size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect); |
5019 | cc_msg = (struct GNUNET_MESH_ClientConnect *) message; | 5006 | cc_msg = (struct GNUNET_MESH_ClientConnect *) message; |
@@ -5027,8 +5014,9 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, | |||
5027 | 5014 | ||
5028 | /* Create new client structure */ | 5015 | /* Create new client structure */ |
5029 | c = GNUNET_malloc (sizeof (struct MeshClient)); | 5016 | c = GNUNET_malloc (sizeof (struct MeshClient)); |
5030 | c->id = next_client_id++; | 5017 | c->id = next_client_id++; // overflow not important: just for debug |
5031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " CLIENT NEW %u\n", c->id); | 5018 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " CLIENT NEW %u\n", c->id); |
5019 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u types\n", ntypes); | ||
5032 | c->handle = client; | 5020 | c->handle = client; |
5033 | GNUNET_SERVER_client_keep (client); | 5021 | GNUNET_SERVER_client_keep (client); |
5034 | if (ntypes > 0) | 5022 | if (ntypes > 0) |
@@ -5041,20 +5029,19 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client, | |||
5041 | for (i = 0; i < ntypes; i++) | 5029 | for (i = 0; i < ntypes; i++) |
5042 | { | 5030 | { |
5043 | u16 = ntohs (t[i]); | 5031 | u16 = ntohs (t[i]); |
5044 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " msg type: %u\n", u16); | 5032 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " msg type: %u\n", u16); |
5045 | GNUNET_CRYPTO_hash (&u16, sizeof (u16), &hc); | 5033 | GNUNET_CRYPTO_hash (&u16, sizeof (u16), &hc); // FIXME pseudo hash |
5046 | 5034 | ||
5047 | /* store in clients hashmap */ | 5035 | /* store in clients hashmap */ |
5048 | GNUNET_CONTAINER_multihashmap_put (c->types, &hc, c, | 5036 | GNUNET_CONTAINER_multihashmap_put (c->types, &hc, c, |
5049 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 5037 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); |
5050 | /* store in global hashmap */ | 5038 | /* store in global hashmap */ |
5051 | GNUNET_CONTAINER_multihashmap_put (types, &hc, c, | 5039 | GNUNET_CONTAINER_multihashmap_put (types, &hc, c, |
5052 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 5040 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
5053 | } | 5041 | } |
5054 | } | 5042 | } |
5055 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u types\n", ntypes); | ||
5056 | 5043 | ||
5057 | GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c); | 5044 | GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c); |
5058 | c->own_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); | 5045 | c->own_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); |
5059 | c->incoming_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); | 5046 | c->incoming_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); |
5060 | c->ignore_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); | 5047 | c->ignore_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); |
@@ -5078,6 +5065,7 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
5078 | const struct GNUNET_MessageHeader *message) | 5065 | const struct GNUNET_MessageHeader *message) |
5079 | { | 5066 | { |
5080 | struct GNUNET_MESH_TunnelMessage *t_msg; | 5067 | struct GNUNET_MESH_TunnelMessage *t_msg; |
5068 | struct MeshPeerInfo *peer_info; | ||
5081 | struct MeshTunnel *t; | 5069 | struct MeshTunnel *t; |
5082 | struct MeshClient *c; | 5070 | struct MeshClient *c; |
5083 | MESH_TunnelNumber tid; | 5071 | MESH_TunnelNumber tid; |
@@ -5102,6 +5090,8 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
5102 | } | 5090 | } |
5103 | 5091 | ||
5104 | t_msg = (struct GNUNET_MESH_TunnelMessage *) message; | 5092 | t_msg = (struct GNUNET_MESH_TunnelMessage *) message; |
5093 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " towards %s\n", | ||
5094 | GNUNET_i2s (&t_msg->peer)); | ||
5105 | /* Sanity check for tunnel numbering */ | 5095 | /* Sanity check for tunnel numbering */ |
5106 | tid = ntohl (t_msg->tunnel_id); | 5096 | tid = ntohl (t_msg->tunnel_id); |
5107 | if (0 == (tid & GNUNET_MESH_LOCAL_TUNNEL_ID_CLI)) | 5097 | if (0 == (tid & GNUNET_MESH_LOCAL_TUNNEL_ID_CLI)) |
@@ -5123,7 +5113,6 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
5123 | t = tunnel_new (myid, next_tid++, c, tid); | 5113 | t = tunnel_new (myid, next_tid++, c, tid); |
5124 | if (NULL == t) | 5114 | if (NULL == t) |
5125 | { | 5115 | { |
5126 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Tunnel creation failed.\n"); | ||
5127 | GNUNET_break (0); | 5116 | GNUNET_break (0); |
5128 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 5117 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
5129 | return; | 5118 | return; |
@@ -5131,8 +5120,11 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client, | |||
5131 | next_tid = next_tid & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; | 5120 | next_tid = next_tid & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; |
5132 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s [%x] (%x)\n", | 5121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s [%x] (%x)\n", |
5133 | GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid); | 5122 | GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid); |
5134 | |||
5135 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new tunnel created\n"); | 5123 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new tunnel created\n"); |
5124 | |||
5125 | peer_info = peer_info_get (&t_msg->peer); | ||
5126 | tunnel_add_peer (t, peer_info); | ||
5127 | peer_info_connect (peer_info, t); | ||
5136 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 5128 | GNUNET_SERVER_receive_done (client, GNUNET_OK); |
5137 | return; | 5129 | return; |
5138 | } | 5130 | } |
@@ -5961,7 +5953,7 @@ key_generation_cb (void *cls, | |||
5961 | &handle_local_client_disconnect, NULL); | 5953 | &handle_local_client_disconnect, NULL); |
5962 | 5954 | ||
5963 | 5955 | ||
5964 | clients = NULL; | 5956 | clients_head = NULL; |
5965 | clients_tail = NULL; | 5957 | clients_tail = NULL; |
5966 | next_client_id = 0; | 5958 | next_client_id = 0; |
5967 | 5959 | ||