aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-05-07 12:54:38 +0000
committerBart Polot <bart@net.in.tum.de>2013-05-07 12:54:38 +0000
commitbd4e10f6c1162adf47bbe60ef005cc42a635d5ad (patch)
treeb25b39e4102ba74e5336aeb5211460f2d240af35 /src
parentb3e54688ae46b901bdbf6aa3020d93a04deda9e8 (diff)
downloadgnunet-bd4e10f6c1162adf47bbe60ef005cc42a635d5ad.tar.gz
gnunet-bd4e10f6c1162adf47bbe60ef005cc42a635d5ad.zip
- wip
Diffstat (limited to 'src')
-rw-r--r--src/mesh/gnunet-service-mesh-new.c1038
-rw-r--r--src/mesh/gnunet-service-mesh.c2
-rw-r--r--src/mesh/mesh2.h10
-rw-r--r--src/mesh/mesh2_api.c65
-rw-r--r--src/mesh/mesh2_protocol.h45
5 files changed, 38 insertions, 1122 deletions
diff --git a/src/mesh/gnunet-service-mesh-new.c b/src/mesh/gnunet-service-mesh-new.c
index e42be9142..1691894e5 100644
--- a/src/mesh/gnunet-service-mesh-new.c
+++ b/src/mesh/gnunet-service-mesh-new.c
@@ -399,11 +399,6 @@ struct MeshTunnel
399 MESH_TunnelNumber local_tid_dest; 399 MESH_TunnelNumber local_tid_dest;
400 400
401 /** 401 /**
402 * Is the speed on the tunnel limited to the slowest peer?
403 */
404 int speed_min;
405
406 /**
407 * Is the tunnel bufferless (minimum latency)? 402 * Is the tunnel bufferless (minimum latency)?
408 */ 403 */
409 int nobuffer; 404 int nobuffer;
@@ -419,11 +414,6 @@ struct MeshTunnel
419 uint32_t bck_pid; 414 uint32_t bck_pid;
420 415
421 /** 416 /**
422 * SKIP value for this tunnel.
423 */
424 uint32_t skip;
425
426 /**
427 * Force sending ACK? Flag to allow duplicate ACK on POLL. 417 * Force sending ACK? Flag to allow duplicate ACK on POLL.
428 */ 418 */
429 int force_ack; 419 int force_ack;
@@ -480,12 +470,7 @@ struct MeshTunnel
480 * Peers in the tunnel, indexed by PeerIdentity -> (MeshPeerInfo) 470 * Peers in the tunnel, indexed by PeerIdentity -> (MeshPeerInfo)
481 * containing peers added by id or by type, not intermediate peers. 471 * containing peers added by id or by type, not intermediate peers.
482 */ 472 */
483 struct GNUNET_CONTAINER_MultiHashMap *peers; 473 struct GNUNET_PEER_Id peer;
484
485 /**
486 * Number of peers that are connected and potentially ready to receive data
487 */
488 unsigned int peers_ready;
489 474
490 /** 475 /**
491 * Client owner of the tunnel, if any 476 * Client owner of the tunnel, if any
@@ -517,16 +502,6 @@ struct MeshTunnel
517 */ 502 */
518 unsigned int nignore; 503 unsigned int nignore;
519 504
520 /**
521 * Blacklisted peers
522 */
523 GNUNET_PEER_Id *blacklisted;
524
525 /**
526 * Number of elements in blacklisted
527 */
528 unsigned int nblacklisted;
529
530 /** 505 /**
531 * Bloomfilter (for peer identities) to stop circular routes 506 * Bloomfilter (for peer identities) to stop circular routes
532 */ 507 */
@@ -534,24 +509,10 @@ struct MeshTunnel
534 509
535 /** 510 /**
536 * Tunnel paths 511 * Tunnel paths
512 * FIXME just a path
537 */ 513 */
538 struct MeshTunnelTree *tree; 514 struct MeshTunnelTree *tree;
539 515
540 /**
541 * Application type we are looking for in this tunnel
542 */
543 GNUNET_MESH_ApplicationType type;
544
545 /**
546 * Used to search peers offering a service
547 */
548 struct GNUNET_DHT_GetHandle *dht_get_type;
549
550 /**
551 * Handle for the regex search for a connect_by_string
552 */
553 struct MeshRegexSearchInfo *regex_search;
554
555 /** 516 /**
556 * Task to keep the used paths alive 517 * Task to keep the used paths alive
557 */ 518 */
@@ -766,11 +727,6 @@ struct MeshClient
766 struct GNUNET_SERVER_Client *handle; 727 struct GNUNET_SERVER_Client *handle;
767 728
768 /** 729 /**
769 * Applications that this client has claimed to provide: H(app) = app.
770 */
771 struct GNUNET_CONTAINER_MultiHashMap *apps;
772
773 /**
774 * Messages that this client has declared interest in 730 * Messages that this client has declared interest in
775 */ 731 */
776 struct GNUNET_CONTAINER_MultiHashMap *types; 732 struct GNUNET_CONTAINER_MultiHashMap *types;
@@ -992,21 +948,11 @@ static MESH_TunnelNumber next_tid;
992static MESH_TunnelNumber next_local_tid; 948static MESH_TunnelNumber next_local_tid;
993 949
994/** 950/**
995 * All application types provided by this peer: H(app) = *Client.
996 */
997static struct GNUNET_CONTAINER_MultiHashMap *applications;
998
999/**
1000 * All message types clients of this peer are interested in. 951 * All message types clients of this peer are interested in.
1001 */ 952 */
1002static struct GNUNET_CONTAINER_MultiHashMap *types; 953static struct GNUNET_CONTAINER_MultiHashMap *types;
1003 954
1004/** 955/**
1005 * Task to periodically announce provided applications.
1006 */
1007GNUNET_SCHEDULER_TaskIdentifier announce_applications_task;
1008
1009/**
1010 * Task to periodically announce itself in the network. 956 * Task to periodically announce itself in the network.
1011 */ 957 */
1012GNUNET_SCHEDULER_TaskIdentifier announce_id_task; 958GNUNET_SCHEDULER_TaskIdentifier announce_id_task;
@@ -1253,74 +1199,6 @@ queue_send (void *cls, size_t size, void *buf);
1253/******************************************************************************/ 1199/******************************************************************************/
1254 1200
1255/** 1201/**
1256 * Announce iterator over for each application provided by the peer
1257 *
1258 * @param cls closure
1259 * @param key current key code
1260 * @param value value in the hash map
1261 * @return GNUNET_YES if we should continue to
1262 * iterate,
1263 * GNUNET_NO if not.
1264 */
1265static int
1266announce_application (void *cls, const struct GNUNET_HashCode * key, void *value)
1267{
1268 struct PBlock block;
1269 struct MeshClient *c;
1270
1271 block.id = my_full_id;
1272 c = GNUNET_CONTAINER_multihashmap_get (applications, key);
1273 GNUNET_assert(NULL != c);
1274 block.type = (long) GNUNET_CONTAINER_multihashmap_get (c->apps, key);
1275 if (0 == block.type)
1276 {
1277 GNUNET_break(0);
1278 return GNUNET_YES;
1279 }
1280 block.type = htonl (block.type);
1281 DEBUG_DHT ("Putting APP key: %s\n", GNUNET_h2s (key));
1282 GNUNET_break (NULL !=
1283 GNUNET_DHT_put (dht_handle, key,
1284 dht_replication_level,
1285 GNUNET_DHT_RO_RECORD_ROUTE |
1286 GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE,
1287 GNUNET_BLOCK_TYPE_MESH_PEER_BY_TYPE,
1288 sizeof (block),
1289 (const char *) &block,
1290 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), /* FIXME: this should be an option */
1291 app_announce_time, NULL, NULL));
1292 return GNUNET_OK;
1293}
1294
1295
1296/**
1297 * Periodically announce what applications are provided by local clients
1298 * (by type)
1299 *
1300 * @param cls closure
1301 * @param tc task context
1302 */
1303static void
1304announce_applications (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1305{
1306 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1307 {
1308 announce_applications_task = GNUNET_SCHEDULER_NO_TASK;
1309 return;
1310 }
1311
1312 DEBUG_DHT ("Starting PUT for apps\n");
1313
1314 GNUNET_CONTAINER_multihashmap_iterate (applications, &announce_application,
1315 NULL);
1316 announce_applications_task =
1317 GNUNET_SCHEDULER_add_delayed (app_announce_time, &announce_applications,
1318 cls);
1319 DEBUG_DHT ("Finished PUT for apps\n");
1320}
1321
1322
1323/**
1324 * Periodically announce self id in the DHT 1202 * Periodically announce self id in the DHT
1325 * 1203 *
1326 * @param cls closure 1204 * @param cls closure
@@ -4483,7 +4361,6 @@ queue_get_next (const struct MeshPeerInfo *peer)
4483 struct MeshTunnelChildInfo *cinfo; 4361 struct MeshTunnelChildInfo *cinfo;
4484 struct GNUNET_MESH_Unicast *ucast; 4362 struct GNUNET_MESH_Unicast *ucast;
4485 struct GNUNET_MESH_ToOrigin *to_orig; 4363 struct GNUNET_MESH_ToOrigin *to_orig;
4486 struct GNUNET_MESH_Multicast *mcast;
4487 struct GNUNET_PeerIdentity id; 4364 struct GNUNET_PeerIdentity id;
4488 uint32_t pid; 4365 uint32_t pid;
4489 uint32_t ack; 4366 uint32_t ack;
@@ -4510,18 +4387,6 @@ queue_get_next (const struct MeshPeerInfo *peer)
4510 pid = ntohl (to_orig->pid); 4387 pid = ntohl (to_orig->pid);
4511 ack = t->bck_ack; 4388 ack = t->bck_ack;
4512 break; 4389 break;
4513 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
4514 mcast = (struct GNUNET_MESH_Multicast *) info->mesh_data->data;
4515 if (GNUNET_MESSAGE_TYPE_MESH_MULTICAST != ntohs(mcast->header.type))
4516 {
4517 // Not a multicast payload: multicast control traffic (destroy, etc)
4518 return q;
4519 }
4520 pid = ntohl (mcast->pid);
4521 GNUNET_PEER_resolve (info->peer->id, &id);
4522 cinfo = tunnel_get_neighbor_fc(t, &id);
4523 ack = cinfo->fwd_ack;
4524 break;
4525 default: 4390 default:
4526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4527 "********* OK!\n"); 4392 "********* OK!\n");
@@ -5032,11 +4897,6 @@ handle_mesh_path_create (void *cls, const struct GNUNET_PeerIdentity *peer,
5032 /* It is for us! Send ack. */ 4897 /* It is for us! Send ack. */
5033 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n"); 4898 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " It's for us!\n");
5034 peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO); 4899 peer_info_add_path_to_origin (orig_peer_info, path, GNUNET_NO);
5035 if (NULL == t->peers)
5036 {
5037 /* New tunnel! Notify clients on first payload message. */
5038 t->peers = GNUNET_CONTAINER_multihashmap_create (4, GNUNET_NO);
5039 }
5040 GNUNET_break (GNUNET_SYSERR != 4900 GNUNET_break (GNUNET_SYSERR !=
5041 GNUNET_CONTAINER_multihashmap_put (t->peers, 4901 GNUNET_CONTAINER_multihashmap_put (t->peers,
5042 &my_full_id.hashPubKey, 4902 &my_full_id.hashPubKey,
@@ -5305,7 +5165,6 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
5305 " pid %u not seen yet, forwarding\n", pid); 5165 " pid %u not seen yet, forwarding\n", pid);
5306 } 5166 }
5307 5167
5308 t->skip += (pid - t->fwd_pid) - 1;
5309 t->fwd_pid = pid; 5168 t->fwd_pid = pid;
5310 5169
5311 if (GMC_is_pid_bigger (pid, t->last_fwd_ack)) 5170 if (GMC_is_pid_bigger (pid, t->last_fwd_ack))
@@ -5319,7 +5178,7 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
5319 } 5178 }
5320 5179
5321 tunnel_reset_timeout (t); 5180 tunnel_reset_timeout (t);
5322 dest_id = GNUNET_PEER_search (&msg->destination); 5181 dest_id = t->peer;
5323 if (dest_id == myid) 5182 if (dest_id == myid)
5324 { 5183 {
5325 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5184 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -5362,86 +5221,6 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer,
5362 5221
5363 5222
5364/** 5223/**
5365 * Core handler for mesh network traffic going from the origin to all peers
5366 *
5367 * @param cls closure
5368 * @param message message
5369 * @param peer peer identity this notification is about
5370 * @return GNUNET_OK to keep the connection open,
5371 * GNUNET_SYSERR to close it (signal serious error)
5372 *
5373 * TODO: Check who we got this from, to validate route.
5374 */
5375static int
5376handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer,
5377 const struct GNUNET_MessageHeader *message)
5378{
5379 struct GNUNET_MESH_Multicast *msg;
5380 struct MeshTunnel *t;
5381 size_t size;
5382 uint32_t pid;
5383
5384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "got a multicast packet from %s\n",
5385 GNUNET_i2s (peer));
5386 size = ntohs (message->size);
5387 if (sizeof (struct GNUNET_MESH_Multicast) +
5388 sizeof (struct GNUNET_MessageHeader) > size)
5389 {
5390 GNUNET_break_op (0);
5391 return GNUNET_OK;
5392 }
5393 msg = (struct GNUNET_MESH_Multicast *) message;
5394 t = tunnel_get (&msg->oid, ntohl (msg->tid));
5395
5396 if (NULL == t)
5397 {
5398 /* TODO notify that we dont know that tunnel */
5399 GNUNET_STATISTICS_update (stats, "# data on unknown tunnel", 1, GNUNET_NO);
5400 GNUNET_break_op (0);
5401 return GNUNET_OK;
5402 }
5403 pid = ntohl (msg->pid);
5404 if (t->fwd_pid == pid)
5405 {
5406 /* already seen this packet, drop */
5407 GNUNET_STATISTICS_update (stats, "# duplicate PID drops", 1, GNUNET_NO);
5408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5409 " Already seen pid %u, DROPPING!\n", pid);
5410 tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK);
5411 return GNUNET_OK;
5412 }
5413 else
5414 {
5415 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5416 " pid %u not seen yet, forwarding\n", pid);
5417 }
5418 t->skip += (pid - t->fwd_pid) - 1;
5419 t->fwd_pid = pid;
5420 tunnel_reset_timeout (t);
5421
5422 /* Transmit to locally interested clients */
5423 if (NULL != t->peers &&
5424 GNUNET_CONTAINER_multihashmap_contains (t->peers, &my_full_id.hashPubKey))
5425 {
5426 GNUNET_STATISTICS_update (stats, "# multicast received", 1, GNUNET_NO);
5427 send_subscribed_clients (message, &msg[1].header, t);
5428 tunnel_send_fwd_ack(t, GNUNET_MESSAGE_TYPE_MESH_MULTICAST);
5429 }
5430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ttl: %u\n", ntohl (msg->ttl));
5431 if (ntohl (msg->ttl) == 0)
5432 {
5433 GNUNET_STATISTICS_update (stats, "# TTL drops", 1, GNUNET_NO);
5434 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " TTL is 0, DROPPING!\n");
5435 tunnel_send_fwd_ack (t, GNUNET_MESSAGE_TYPE_MESH_ACK);
5436 return GNUNET_OK;
5437 }
5438 GNUNET_STATISTICS_update (stats, "# multicast forwarded", 1, GNUNET_NO);
5439 tunnel_send_multicast (t, message);
5440 return GNUNET_OK;
5441}
5442
5443
5444/**
5445 * Core handler for mesh network traffic toward the owner of a tunnel 5224 * Core handler for mesh network traffic toward the owner of a tunnel
5446 * 5225 *
5447 * @param cls closure 5226 * @param cls closure
@@ -5725,14 +5504,6 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
5725 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " via peer %s\n", 5504 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " via peer %s\n",
5726 GNUNET_i2s (peer)); 5505 GNUNET_i2s (peer));
5727 5506
5728 if (NULL != t->regex_search && t->regex_search->peer == peer_info->id)
5729 {
5730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
5731 "connect_by_string completed, stopping search\n");
5732 regex_cancel_search (t->regex_search);
5733 t->regex_search = NULL;
5734 }
5735
5736 /* Add paths to peers? */ 5507 /* Add paths to peers? */
5737 p = tree_get_path_to_peer (t->tree, peer_info->id); 5508 p = tree_get_path_to_peer (t->tree, peer_info->id);
5738 if (NULL != p) 5509 if (NULL != p)
@@ -5754,11 +5525,6 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer,
5754 GNUNET_break_op (0); 5525 GNUNET_break_op (0);
5755 return GNUNET_OK; 5526 return GNUNET_OK;
5756 } 5527 }
5757 if (NULL != t->dht_get_type)
5758 {
5759 GNUNET_DHT_get_stop (t->dht_get_type);
5760 t->dht_get_type = NULL;
5761 }
5762 if (tree_get_status (t->tree, peer_info->id) != MESH_PEER_READY) 5528 if (tree_get_status (t->tree, peer_info->id) != MESH_PEER_READY)
5763 { 5529 {
5764 tree_set_status (t->tree, peer_info->id, MESH_PEER_READY); 5530 tree_set_status (t->tree, peer_info->id, MESH_PEER_READY);
@@ -5833,7 +5599,6 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
5833 {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY, 5599 {&handle_mesh_tunnel_destroy, GNUNET_MESSAGE_TYPE_MESH_TUNNEL_DESTROY,
5834 sizeof (struct GNUNET_MESH_TunnelDestroy)}, 5600 sizeof (struct GNUNET_MESH_TunnelDestroy)},
5835 {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, 5601 {&handle_mesh_data_unicast, GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
5836 {&handle_mesh_data_multicast, GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0},
5837 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE, 5602 {&handle_mesh_keepalive, GNUNET_MESSAGE_TYPE_MESH_PATH_KEEPALIVE,
5838 sizeof (struct GNUNET_MESH_TunnelKeepAlive)}, 5603 sizeof (struct GNUNET_MESH_TunnelKeepAlive)},
5839 {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, 5604 {&handle_mesh_data_to_orig, GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0},
@@ -5852,24 +5617,6 @@ static struct GNUNET_CORE_MessageHandler core_handlers[] = {
5852/**************** MESH LOCAL HANDLER HELPERS ***********************/ 5617/**************** MESH LOCAL HANDLER HELPERS ***********************/
5853/******************************************************************************/ 5618/******************************************************************************/
5854 5619
5855/**
5856 * deregister_app: iterator for removing each application registered by a client
5857 *
5858 * @param cls closure
5859 * @param key the hash of the application id (used to access the hashmap)
5860 * @param value the value stored at the key (client)
5861 *
5862 * @return GNUNET_OK on success
5863 */
5864static int
5865deregister_app (void *cls, const struct GNUNET_HashCode * key, void *value)
5866{
5867 struct MeshClient *c = cls;
5868
5869 GNUNET_break (GNUNET_YES ==
5870 GNUNET_CONTAINER_multihashmap_remove (applications, key, c));
5871 return GNUNET_OK;
5872}
5873 5620
5874#if LATER 5621#if LATER
5875/** 5622/**
@@ -6048,18 +5795,6 @@ handle_local_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
6048 GNUNET_CONTAINER_multihashmap_destroy (c->incoming_tunnels); 5795 GNUNET_CONTAINER_multihashmap_destroy (c->incoming_tunnels);
6049 GNUNET_CONTAINER_multihashmap_destroy (c->ignore_tunnels); 5796 GNUNET_CONTAINER_multihashmap_destroy (c->ignore_tunnels);
6050 5797
6051 /* deregister clients applications */
6052 if (NULL != c->apps)
6053 {
6054 GNUNET_CONTAINER_multihashmap_iterate (c->apps, &deregister_app, c);
6055 GNUNET_CONTAINER_multihashmap_destroy (c->apps);
6056 }
6057 if (0 == GNUNET_CONTAINER_multihashmap_size (applications) &&
6058 GNUNET_SCHEDULER_NO_TASK != announce_applications_task)
6059 {
6060 GNUNET_SCHEDULER_cancel (announce_applications_task);
6061 announce_applications_task = GNUNET_SCHEDULER_NO_TASK;
6062 }
6063 if (NULL != c->types) 5798 if (NULL != c->types)
6064 GNUNET_CONTAINER_multihashmap_destroy (c->types); 5799 GNUNET_CONTAINER_multihashmap_destroy (c->types);
6065 for (i = 0; i < c->n_regex; i++) 5800 for (i = 0; i < c->n_regex; i++)
@@ -6096,11 +5831,9 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
6096{ 5831{
6097 struct GNUNET_MESH_ClientConnect *cc_msg; 5832 struct GNUNET_MESH_ClientConnect *cc_msg;
6098 struct MeshClient *c; 5833 struct MeshClient *c;
6099 GNUNET_MESH_ApplicationType *a;
6100 unsigned int size; 5834 unsigned int size;
6101 uint16_t ntypes; 5835 uint16_t ntypes;
6102 uint16_t *t; 5836 uint16_t *t;
6103 uint16_t napps;
6104 uint16_t i; 5837 uint16_t i;
6105 5838
6106 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new client connected\n"); 5839 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new client connected\n");
@@ -6108,9 +5841,7 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
6108 size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect); 5841 size = ntohs (message->size) - sizeof (struct GNUNET_MESH_ClientConnect);
6109 cc_msg = (struct GNUNET_MESH_ClientConnect *) message; 5842 cc_msg = (struct GNUNET_MESH_ClientConnect *) message;
6110 ntypes = ntohs (cc_msg->types); 5843 ntypes = ntohs (cc_msg->types);
6111 napps = ntohs (cc_msg->applications); 5844 if (size != ntypes * sizeof (uint16_t))
6112 if (size !=
6113 ntypes * sizeof (uint16_t) + napps * sizeof (GNUNET_MESH_ApplicationType))
6114 { 5845 {
6115 GNUNET_break (0); 5846 GNUNET_break (0);
6116 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 5847 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -6123,36 +5854,12 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
6123 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " CLIENT NEW %u\n", c->id); 5854 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " CLIENT NEW %u\n", c->id);
6124 c->handle = client; 5855 c->handle = client;
6125 GNUNET_SERVER_client_keep (client); 5856 GNUNET_SERVER_client_keep (client);
6126 a = (GNUNET_MESH_ApplicationType *) &cc_msg[1];
6127 if (napps > 0)
6128 {
6129 GNUNET_MESH_ApplicationType at;
6130 struct GNUNET_HashCode hc;
6131
6132 c->apps = GNUNET_CONTAINER_multihashmap_create (napps, GNUNET_NO);
6133 for (i = 0; i < napps; i++)
6134 {
6135 at = ntohl (a[i]);
6136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " app type: %u\n", at);
6137 GNUNET_CRYPTO_hash (&at, sizeof (at), &hc);
6138 /* store in clients hashmap */
6139 GNUNET_CONTAINER_multihashmap_put (c->apps, &hc, (void *) (long) at,
6140 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
6141 /* store in global hashmap, for announcements */
6142 GNUNET_CONTAINER_multihashmap_put (applications, &hc, c,
6143 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
6144 }
6145 if (GNUNET_SCHEDULER_NO_TASK == announce_applications_task)
6146 announce_applications_task =
6147 GNUNET_SCHEDULER_add_now (&announce_applications, NULL);
6148
6149 }
6150 if (ntypes > 0) 5857 if (ntypes > 0)
6151 { 5858 {
6152 uint16_t u16; 5859 uint16_t u16;
6153 struct GNUNET_HashCode hc; 5860 struct GNUNET_HashCode hc;
6154 5861
6155 t = (uint16_t *) & a[napps]; 5862 t = (uint16_t *) &cc_msg[1];
6156 c->types = GNUNET_CONTAINER_multihashmap_create (ntypes, GNUNET_NO); 5863 c->types = GNUNET_CONTAINER_multihashmap_create (ntypes, GNUNET_NO);
6157 for (i = 0; i < ntypes; i++) 5864 for (i = 0; i < ntypes; i++)
6158 { 5865 {
@@ -6168,8 +5875,7 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
6168 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 5875 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
6169 } 5876 }
6170 } 5877 }
6171 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 5878 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " client has %u types\n", ntypes);
6172 " client has %u+%u subscriptions\n", napps, ntypes);
6173 5879
6174 GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c); 5880 GNUNET_CONTAINER_DLL_insert (clients, clients_tail, c);
6175 c->own_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); 5881 c->own_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
@@ -6184,85 +5890,6 @@ handle_local_new_client (void *cls, struct GNUNET_SERVER_Client *client,
6184 5890
6185 5891
6186/** 5892/**
6187 * Handler for clients announcing available services by a regular expression.
6188 *
6189 * @param cls closure
6190 * @param client identification of the client
6191 * @param message the actual message, which includes messages the client wants
6192 */
6193static void
6194handle_local_announce_regex (void *cls, struct GNUNET_SERVER_Client *client,
6195 const struct GNUNET_MessageHeader *message)
6196{
6197 const struct GNUNET_MESH_RegexAnnounce *msg;
6198 struct MeshRegexDescriptor rd;
6199 struct MeshClient *c;
6200 char *regex;
6201 size_t len;
6202 size_t offset;
6203
6204 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "announce regex started\n");
6205
6206 /* Sanity check for client registration */
6207 if (NULL == (c = client_get (client)))
6208 {
6209 GNUNET_break (0);
6210 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6211 return;
6212 }
6213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
6214
6215 msg = (const struct GNUNET_MESH_RegexAnnounce *) message;
6216
6217 len = ntohs (message->size) - sizeof(struct GNUNET_MESH_RegexAnnounce);
6218 if (NULL != c->partial_regex)
6219 {
6220 regex = c->partial_regex;
6221 offset = strlen (c->partial_regex);
6222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6223 " continuation, already have %u bytes\n",
6224 offset);
6225 }
6226 else
6227 {
6228 regex = NULL;
6229 offset = 0;
6230 }
6231
6232 regex = GNUNET_realloc (regex, offset + len + 1);
6233 memcpy (&regex[offset], &msg[1], len);
6234 regex[offset + len] = '\0';
6235 if (0 == ntohs (msg->last))
6236 {
6237 c->partial_regex = regex;
6238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6239 " not ended, stored %u bytes for later\n",
6240 len);
6241 GNUNET_SERVER_receive_done (client, GNUNET_OK);
6242 return;
6243 }
6244 rd.regex = regex;
6245 rd.compression = ntohs (msg->compression_characters);
6246 rd.h = NULL;
6247 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " length %u\n", len);
6248 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " regex %s\n", regex);
6249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " compr %u\n", ntohs (rd.compression));
6250 GNUNET_array_append (c->regexes, c->n_regex, rd);
6251 c->partial_regex = NULL;
6252 if (GNUNET_SCHEDULER_NO_TASK == c->regex_announce_task)
6253 {
6254 c->regex_announce_task = GNUNET_SCHEDULER_add_now (&regex_announce, c);
6255 }
6256 else
6257 {
6258 regex_put (&rd);
6259 }
6260 GNUNET_SERVER_receive_done (client, GNUNET_OK);
6261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "announce regex processed\n");
6262}
6263
6264
6265/**
6266 * Handler for requests of new tunnels 5893 * Handler for requests of new tunnels
6267 * 5894 *
6268 * @param cls closure 5895 * @param cls closure
@@ -6327,7 +5954,6 @@ handle_local_tunnel_create (void *cls, struct GNUNET_SERVER_Client *client,
6327 next_tid = next_tid & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI; 5954 next_tid = next_tid & ~GNUNET_MESH_LOCAL_TUNNEL_ID_CLI;
6328 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s [%x] (%x)\n", 5955 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CREATED TUNNEL %s [%x] (%x)\n",
6329 GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid); 5956 GNUNET_i2s (&my_full_id), t->id.tid, t->local_tid);
6330 t->peers = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
6331 5957
6332 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new tunnel created\n"); 5958 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "new tunnel created\n");
6333 GNUNET_SERVER_receive_done (client, GNUNET_OK); 5959 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -6404,63 +6030,6 @@ handle_local_tunnel_destroy (void *cls, struct GNUNET_SERVER_Client *client,
6404 6030
6405 6031
6406/** 6032/**
6407 * Handler for requests of seeting tunnel's speed.
6408 *
6409 * @param cls Closure (unused).
6410 * @param client Identification of the client.
6411 * @param message The actual message.
6412 */
6413static void
6414handle_local_tunnel_speed (void *cls, struct GNUNET_SERVER_Client *client,
6415 const struct GNUNET_MessageHeader *message)
6416{
6417 struct GNUNET_MESH_TunnelMessage *tunnel_msg;
6418 struct MeshClient *c;
6419 struct MeshTunnel *t;
6420 MESH_TunnelNumber tid;
6421
6422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6423 "Got a SPEED request from client!\n");
6424
6425 /* Sanity check for client registration */
6426 if (NULL == (c = client_get (client)))
6427 {
6428 GNUNET_break (0);
6429 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6430 return;
6431 }
6432
6433 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
6434
6435 tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
6436
6437 /* Retrieve tunnel */
6438 tid = ntohl (tunnel_msg->tunnel_id);
6439 t = tunnel_get_by_local_id(c, tid);
6440 if (NULL == t)
6441 {
6442 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " tunnel %X not found\n", tid);
6443 GNUNET_break (0);
6444 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6445 return;
6446 }
6447
6448 switch (ntohs(message->type))
6449 {
6450 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MIN:
6451 t->speed_min = GNUNET_YES;
6452 break;
6453 case GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MAX:
6454 t->speed_min = GNUNET_NO;
6455 break;
6456 default:
6457 GNUNET_break (0);
6458 }
6459 GNUNET_SERVER_receive_done (client, GNUNET_OK);
6460}
6461
6462
6463/**
6464 * Handler for requests of seeting tunnel's buffering policy. 6033 * Handler for requests of seeting tunnel's buffering policy.
6465 * 6034 *
6466 * @param cls Closure (unused). 6035 * @param cls Closure (unused).
@@ -6518,277 +6087,6 @@ handle_local_tunnel_buffer (void *cls, struct GNUNET_SERVER_Client *client,
6518 6087
6519 6088
6520/** 6089/**
6521 * Handler for connection requests to new peers
6522 *
6523 * @param cls closure
6524 * @param client identification of the client
6525 * @param message the actual message (PeerControl)
6526 */
6527static void
6528handle_local_connect_add (void *cls, struct GNUNET_SERVER_Client *client,
6529 const struct GNUNET_MessageHeader *message)
6530{
6531 struct GNUNET_MESH_PeerControl *peer_msg;
6532 struct MeshPeerInfo *peer_info;
6533 struct MeshClient *c;
6534 struct MeshTunnel *t;
6535 MESH_TunnelNumber tid;
6536
6537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got connection request\n");
6538 /* Sanity check for client registration */
6539 if (NULL == (c = client_get (client)))
6540 {
6541 GNUNET_break (0);
6542 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6543 return;
6544 }
6545 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
6546
6547 peer_msg = (struct GNUNET_MESH_PeerControl *) message;
6548
6549 /* Sanity check for message size */
6550 if (sizeof (struct GNUNET_MESH_PeerControl) != ntohs (peer_msg->header.size))
6551 {
6552 GNUNET_break (0);
6553 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6554 return;
6555 }
6556
6557 /* Tunnel exists? */
6558 tid = ntohl (peer_msg->tunnel_id);
6559 t = tunnel_get_by_local_id (c, tid);
6560 if (NULL == t)
6561 {
6562 GNUNET_break (0);
6563 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6564 return;
6565 }
6566
6567 /* Does client own tunnel? */
6568 if (t->owner->handle != client)
6569 {
6570 GNUNET_break (0);
6571 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6572 return;
6573 }
6574 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " for %s\n",
6575 GNUNET_i2s (&peer_msg->peer));
6576 peer_info = peer_info_get (&peer_msg->peer);
6577
6578 tunnel_add_peer (t, peer_info);
6579 peer_info_connect (peer_info, t);
6580
6581 GNUNET_SERVER_receive_done (client, GNUNET_OK);
6582 return;
6583}
6584
6585
6586/**
6587 * Handler for disconnection requests of peers in a tunnel
6588 *
6589 * @param cls closure
6590 * @param client identification of the client
6591 * @param message the actual message (PeerControl)
6592 */
6593static void
6594handle_local_connect_del (void *cls, struct GNUNET_SERVER_Client *client,
6595 const struct GNUNET_MessageHeader *message)
6596{
6597 struct GNUNET_MESH_PeerControl *peer_msg;
6598 struct MeshPeerInfo *peer_info;
6599 struct MeshClient *c;
6600 struct MeshTunnel *t;
6601 MESH_TunnelNumber tid;
6602
6603 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a PEER DEL request\n");
6604 /* Sanity check for client registration */
6605 if (NULL == (c = client_get (client)))
6606 {
6607 GNUNET_break (0);
6608 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6609 return;
6610 }
6611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
6612
6613 peer_msg = (struct GNUNET_MESH_PeerControl *) message;
6614
6615 /* Sanity check for message size */
6616 if (sizeof (struct GNUNET_MESH_PeerControl) != ntohs (peer_msg->header.size))
6617 {
6618 GNUNET_break (0);
6619 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6620 return;
6621 }
6622
6623 /* Tunnel exists? */
6624 tid = ntohl (peer_msg->tunnel_id);
6625 t = tunnel_get_by_local_id (c, tid);
6626 if (NULL == t)
6627 {
6628 GNUNET_break (0);
6629 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6630 return;
6631 }
6632 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " on tunnel %X\n", t->id.tid);
6633
6634 /* Does client own tunnel? */
6635 if (t->owner->handle != client)
6636 {
6637 GNUNET_break (0);
6638 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6639 return;
6640 }
6641
6642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " for peer %s\n",
6643 GNUNET_i2s (&peer_msg->peer));
6644 /* Is the peer in the tunnel? */
6645 peer_info =
6646 GNUNET_CONTAINER_multihashmap_get (t->peers, &peer_msg->peer.hashPubKey);
6647 if (NULL == peer_info)
6648 {
6649 GNUNET_break (0);
6650 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6651 return;
6652 }
6653
6654 /* Ok, delete peer from tunnel */
6655 GNUNET_CONTAINER_multihashmap_remove_all (t->peers,
6656 &peer_msg->peer.hashPubKey);
6657
6658 send_destroy_path (t, peer_info->id);
6659 tunnel_delete_peer (t, peer_info->id);
6660 GNUNET_SERVER_receive_done (client, GNUNET_OK);
6661 return;
6662}
6663
6664/**
6665 * Handler for blacklist requests of peers in a tunnel
6666 *
6667 * @param cls closure
6668 * @param client identification of the client
6669 * @param message the actual message (PeerControl)
6670 *
6671 * FIXME implement DHT block bloomfilter
6672 */
6673static void
6674handle_local_blacklist (void *cls, struct GNUNET_SERVER_Client *client,
6675 const struct GNUNET_MessageHeader *message)
6676{
6677 struct GNUNET_MESH_PeerControl *peer_msg;
6678 struct MeshClient *c;
6679 struct MeshTunnel *t;
6680 MESH_TunnelNumber tid;
6681
6682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a PEER BLACKLIST request\n");
6683 /* Sanity check for client registration */
6684 if (NULL == (c = client_get (client)))
6685 {
6686 GNUNET_break (0);
6687 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6688 return;
6689 }
6690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
6691
6692 peer_msg = (struct GNUNET_MESH_PeerControl *) message;
6693
6694 /* Sanity check for message size */
6695 if (sizeof (struct GNUNET_MESH_PeerControl) != ntohs (peer_msg->header.size))
6696 {
6697 GNUNET_break (0);
6698 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6699 return;
6700 }
6701
6702 /* Tunnel exists? */
6703 tid = ntohl (peer_msg->tunnel_id);
6704 t = tunnel_get_by_local_id (c, tid);
6705 if (NULL == t)
6706 {
6707 GNUNET_break (0);
6708 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6709 return;
6710 }
6711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " on tunnel %X\n", t->id.tid);
6712
6713 GNUNET_array_append(t->blacklisted, t->nblacklisted,
6714 GNUNET_PEER_intern(&peer_msg->peer));
6715}
6716
6717
6718/**
6719 * Handler for unblacklist requests of peers in a tunnel
6720 *
6721 * @param cls closure
6722 * @param client identification of the client
6723 * @param message the actual message (PeerControl)
6724 */
6725static void
6726handle_local_unblacklist (void *cls, struct GNUNET_SERVER_Client *client,
6727 const struct GNUNET_MessageHeader *message)
6728{
6729 struct GNUNET_MESH_PeerControl *peer_msg;
6730 struct MeshClient *c;
6731 struct MeshTunnel *t;
6732 MESH_TunnelNumber tid;
6733 GNUNET_PEER_Id pid;
6734 unsigned int i;
6735
6736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got a PEER UNBLACKLIST request\n");
6737 /* Sanity check for client registration */
6738 if (NULL == (c = client_get (client)))
6739 {
6740 GNUNET_break (0);
6741 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6742 return;
6743 }
6744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
6745
6746 peer_msg = (struct GNUNET_MESH_PeerControl *) message;
6747
6748 /* Sanity check for message size */
6749 if (sizeof (struct GNUNET_MESH_PeerControl) != ntohs (peer_msg->header.size))
6750 {
6751 GNUNET_break (0);
6752 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6753 return;
6754 }
6755
6756 /* Tunnel exists? */
6757 tid = ntohl (peer_msg->tunnel_id);
6758 t = tunnel_get_by_local_id (c, tid);
6759 if (NULL == t)
6760 {
6761 GNUNET_break (0);
6762 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6763 return;
6764 }
6765 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " on tunnel %X\n", t->id.tid);
6766
6767 /* if peer is not known, complain */
6768 pid = GNUNET_PEER_search (&peer_msg->peer);
6769 if (0 == pid)
6770 {
6771 GNUNET_break (0);
6772 return;
6773 }
6774
6775 /* search and remove from list */
6776 for (i = 0; i < t->nblacklisted; i++)
6777 {
6778 if (t->blacklisted[i] == pid)
6779 {
6780 t->blacklisted[i] = t->blacklisted[t->nblacklisted - 1];
6781 GNUNET_array_grow (t->blacklisted, t->nblacklisted, t->nblacklisted - 1);
6782 return;
6783 }
6784 }
6785
6786 /* if peer hasn't been blacklisted, complain */
6787 GNUNET_break (0);
6788}
6789
6790
6791/**
6792 * Handler for client traffic directed to one peer 6090 * Handler for client traffic directed to one peer
6793 * 6091 *
6794 * @param cls closure 6092 * @param cls closure
@@ -6801,7 +6099,6 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client,
6801{ 6099{
6802 struct MeshClient *c; 6100 struct MeshClient *c;
6803 struct MeshTunnel *t; 6101 struct MeshTunnel *t;
6804 struct MeshPeerInfo *pi;
6805 struct GNUNET_MESH_Unicast *data_msg; 6102 struct GNUNET_MESH_Unicast *data_msg;
6806 MESH_TunnelNumber tid; 6103 MESH_TunnelNumber tid;
6807 size_t size; 6104 size_t size;
@@ -6848,16 +6145,6 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client,
6848 return; 6145 return;
6849 } 6146 }
6850 6147
6851 pi = GNUNET_CONTAINER_multihashmap_get (t->peers,
6852 &data_msg->destination.hashPubKey);
6853 /* Is the selected peer in the tunnel? */
6854 if (NULL == pi)
6855 {
6856 GNUNET_break (0);
6857 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
6858 return;
6859 }
6860
6861 /* PID should be as expected */ 6148 /* PID should be as expected */
6862 if (ntohl (data_msg->pid) != t->fwd_pid + 1) 6149 if (ntohl (data_msg->pid) != t->fwd_pid + 1)
6863 { 6150 {
@@ -6990,7 +6277,6 @@ handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client,
6990 copy->ttl = htonl (default_ttl); 6277 copy->ttl = htonl (default_ttl);
6991 copy->pid = htonl (t->bck_pid + 1); 6278 copy->pid = htonl (t->bck_pid + 1);
6992 6279
6993 copy->sender = my_full_id;
6994 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 6280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
6995 " calling generic handler...\n"); 6281 " calling generic handler...\n");
6996 handle_mesh_data_to_orig (NULL, &my_full_id, &copy->header); 6282 handle_mesh_data_to_orig (NULL, &my_full_id, &copy->header);
@@ -7002,97 +6288,6 @@ handle_local_to_origin (void *cls, struct GNUNET_SERVER_Client *client,
7002 6288
7003 6289
7004/** 6290/**
7005 * Handler for client traffic directed to all peers in a tunnel
7006 *
7007 * @param cls closure
7008 * @param client identification of the client
7009 * @param message the actual message
7010 */
7011static void
7012handle_local_multicast (void *cls, struct GNUNET_SERVER_Client *client,
7013 const struct GNUNET_MessageHeader *message)
7014{
7015 struct MeshClient *c;
7016 struct MeshTunnel *t;
7017 struct GNUNET_MESH_Multicast *data_msg;
7018 MESH_TunnelNumber tid;
7019
7020 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7021 "Got a multicast request from a client!\n");
7022
7023 /* Sanity check for client registration */
7024 if (NULL == (c = client_get (client)))
7025 {
7026 GNUNET_break (0);
7027 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7028 return;
7029 }
7030 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " by client %u\n", c->id);
7031
7032 data_msg = (struct GNUNET_MESH_Multicast *) message;
7033
7034 /* Sanity check for message size */
7035 if (sizeof (struct GNUNET_MESH_Multicast) +
7036 sizeof (struct GNUNET_MessageHeader) > ntohs (data_msg->header.size))
7037 {
7038 GNUNET_break (0);
7039 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7040 return;
7041 }
7042
7043 /* Tunnel exists? */
7044 tid = ntohl (data_msg->tid);
7045 t = tunnel_get_by_local_id (c, tid);
7046 if (NULL == t)
7047 {
7048 GNUNET_break (0);
7049 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Tunnel %X unknown.\n", tid);
7050 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, " for client %u.\n", c->id);
7051 GNUNET_break (0);
7052 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7053 return;
7054 }
7055
7056 /* Does client own tunnel? */
7057 if (t->owner->handle != client)
7058 {
7059 GNUNET_break (0);
7060 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7061 return;
7062 }
7063
7064 /* PID should be as expected */
7065 if (ntohl (data_msg->pid) != t->fwd_pid + 1)
7066 {
7067 GNUNET_break (0);
7068 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
7069 "Multicast PID, expected %u, got %u\n",
7070 t->fwd_pid + 1, ntohl (data_msg->pid));
7071 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
7072 return;
7073 }
7074
7075 {
7076 char buf[ntohs (message->size)] GNUNET_ALIGN;
7077 struct GNUNET_MESH_Multicast *copy;
7078
7079 copy = (struct GNUNET_MESH_Multicast *) buf;
7080 memcpy (buf, message, ntohs (message->size));
7081 copy->oid = my_full_id;
7082 copy->tid = htonl (t->id.tid);
7083 copy->ttl = htonl (default_ttl);
7084 GNUNET_assert (ntohl (copy->pid) == (t->fwd_pid + 1));
7085 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
7086 " calling generic handler...\n");
7087 handle_mesh_data_multicast (client, &my_full_id, &copy->header);
7088 }
7089
7090 GNUNET_SERVER_receive_done (t->owner->handle, GNUNET_OK);
7091 return;
7092}
7093
7094
7095/**
7096 * Handler for client's ACKs for payload traffic. 6291 * Handler for client's ACKs for payload traffic.
7097 * 6292 *
7098 * @param cls Closure (unused). 6293 * @param cls Closure (unused).
@@ -7157,36 +6352,6 @@ handle_local_ack (void *cls, struct GNUNET_SERVER_Client *client,
7157} 6352}
7158 6353
7159 6354
7160/**
7161 * Iterator over all peers to send a monitoring client info about a tunnel.
7162 *
7163 * @param cls Closure (message being built).
7164 * @param key Key (hashed tunnel ID, unused).
7165 * @param value Peer info.
7166 *
7167 * @return GNUNET_YES, to keep iterating.
7168 */
7169static int
7170monitor_peers_iterator (void *cls,
7171 const struct GNUNET_HashCode * key,
7172 void *value)
7173{
7174 struct GNUNET_MESH_LocalMonitor *msg = cls;
7175 struct GNUNET_PeerIdentity *id;
7176 struct MeshPeerInfo *info = value;
7177
7178 id = (struct GNUNET_PeerIdentity *) &msg[1];
7179 GNUNET_PEER_resolve (info->id, &id[msg->npeers]);
7180 msg->npeers++;
7181
7182 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
7183 "* sending info about peer %s [%u]\n",
7184 GNUNET_i2s (&id[msg->npeers - 1]), msg->npeers);
7185
7186 return GNUNET_YES;
7187}
7188
7189
7190 6355
7191/** 6356/**
7192 * Iterator over all tunnels to send a monitoring client info about each tunnel. 6357 * Iterator over all tunnels to send a monitoring client info about each tunnel.
@@ -7205,37 +6370,21 @@ monitor_all_tunnels_iterator (void *cls,
7205 struct GNUNET_SERVER_Client *client = cls; 6370 struct GNUNET_SERVER_Client *client = cls;
7206 struct MeshTunnel *t = value; 6371 struct MeshTunnel *t = value;
7207 struct GNUNET_MESH_LocalMonitor *msg; 6372 struct GNUNET_MESH_LocalMonitor *msg;
7208 uint32_t npeers; 6373
7209 6374 msg = GNUNET_malloc (sizeof(struct GNUNET_MESH_LocalMonitor));
7210 npeers = GNUNET_CONTAINER_multihashmap_size (t->peers);
7211 msg = GNUNET_malloc (sizeof(struct GNUNET_MESH_LocalMonitor) +
7212 npeers * sizeof (struct GNUNET_PeerIdentity));
7213 GNUNET_PEER_resolve(t->id.oid, &msg->owner); 6375 GNUNET_PEER_resolve(t->id.oid, &msg->owner);
7214 msg->tunnel_id = htonl (t->id.tid); 6376 msg->tunnel_id = htonl (t->id.tid);
7215 msg->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor) + 6377 msg->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor));
7216 npeers * sizeof (struct GNUNET_PeerIdentity));
7217 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS); 6378 msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
7218 msg->npeers = 0; 6379 GNUNET_PEER_resolve (t->peer, &msg->destination);
7219 (void) GNUNET_CONTAINER_multihashmap_iterate (t->peers, 6380
7220 monitor_peers_iterator,
7221 msg);
7222
7223 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 6381 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
7224 "* sending info about tunnel %s [%u] (%u peers)\n", 6382 "* sending info about tunnel %s [%u]\n",
7225 GNUNET_i2s (&msg->owner), t->id.tid, npeers); 6383 GNUNET_i2s (&msg->owner), t->id.tid);
7226 6384
7227 if (msg->npeers != npeers) 6385 GNUNET_SERVER_notification_context_unicast (nc, client,
7228 { 6386 &msg->header, GNUNET_NO);
7229 GNUNET_break (0); 6387 return GNUNET_YES;
7230 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
7231 "Get tunnels fail: size %u - iter %u\n",
7232 npeers, msg->npeers);
7233 }
7234
7235 msg->npeers = htonl (npeers);
7236 GNUNET_SERVER_notification_context_unicast (nc, client,
7237 &msg->header, GNUNET_NO);
7238 return GNUNET_YES;
7239} 6388}
7240 6389
7241 6390
@@ -7274,107 +6423,6 @@ handle_local_get_tunnels (void *cls, struct GNUNET_SERVER_Client *client,
7274 6423
7275 6424
7276/** 6425/**
7277 * Data needed to build a Monitor_Tunnel message.
7278 */
7279struct MeshMonitorTunnelContext
7280{
7281 /**
7282 * Partial message, including peer count.
7283 */
7284 struct GNUNET_MESH_LocalMonitor *msg;
7285
7286 /**
7287 * Hashmap with positions: peer->position.
7288 */
7289 struct GNUNET_CONTAINER_MultiHashMap *lookup;
7290
7291 /**
7292 * Index of the parent of each peer in the message, realtive to the absolute
7293 * order in the array (can be in a previous message).
7294 */
7295 uint32_t parents[1024];
7296
7297 /**
7298 * Peers visited so far in the tree, aka position of the current peer.
7299 */
7300 unsigned int npeers;
7301
7302 /**
7303 * Client requesting the info.
7304 */
7305 struct MeshClient *c;
7306};
7307
7308
7309/**
7310 * Send a client a message about the structure of a tunnel.
7311 *
7312 * @param ctx Context of the tunnel iteration, with info regarding the state
7313 * of the execution and the number of peers visited for this message.
7314 */
7315static void
7316send_client_tunnel_info (struct MeshMonitorTunnelContext *ctx)
7317{
7318 struct GNUNET_MESH_LocalMonitor *resp = ctx->msg;
7319 struct GNUNET_PeerIdentity *pid;
7320 unsigned int *parent;
7321 size_t size;
7322
7323 size = sizeof (struct GNUNET_MESH_LocalMonitor);
7324 size += (sizeof (struct GNUNET_PeerIdentity) + sizeof (int)) * resp->npeers;
7325 resp->header.size = htons (size);
7326 pid = (struct GNUNET_PeerIdentity *) &resp[1];
7327 parent = (unsigned int *) &pid[resp->npeers];
7328 memcpy (parent, ctx->parents, sizeof(uint32_t) * resp->npeers);
7329 GNUNET_SERVER_notification_context_unicast (nc, ctx->c->handle,
7330 &resp->header, GNUNET_NO);
7331}
7332
7333/**
7334 * Iterator over a tunnel tree to build a message containing all peers
7335 * the in the tunnel, including relay nodes.
7336 *
7337 * @param cls Closure (pointer to pointer of message being built).
7338 * @param peer Short ID of a peer.
7339 * @param parent Short ID of the @c peer 's parent.
7340 */
7341static void
7342tunnel_tree_iterator (void *cls,
7343 GNUNET_PEER_Id peer,
7344 GNUNET_PEER_Id parent)
7345{
7346 struct MeshMonitorTunnelContext *ctx = cls;
7347 struct GNUNET_MESH_LocalMonitor *msg;
7348 struct GNUNET_PeerIdentity *pid;
7349 struct GNUNET_PeerIdentity ppid;
7350
7351 msg = ctx->msg;
7352 pid = (struct GNUNET_PeerIdentity *) &msg[1];
7353 GNUNET_PEER_resolve (peer, &pid[msg->npeers]);
7354 GNUNET_CONTAINER_multihashmap_put (ctx->lookup,
7355 &pid[msg->npeers].hashPubKey,
7356 (void *) (long) ctx->npeers,
7357 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
7358 GNUNET_PEER_resolve (parent, &ppid);
7359 ctx->parents[msg->npeers] =
7360 htonl ((long) GNUNET_CONTAINER_multihashmap_get (ctx->lookup,
7361 &ppid.hashPubKey));
7362
7363 ctx->npeers++;
7364 msg->npeers++;
7365
7366 if (sizeof (struct GNUNET_MESH_LocalMonitor) +
7367 (msg->npeers + 1) *
7368 (sizeof (struct GNUNET_PeerIdentity) + sizeof (uint32_t))
7369 > USHRT_MAX)
7370 {
7371 send_client_tunnel_info (ctx);
7372 msg->npeers = 0;
7373 }
7374}
7375
7376
7377/**
7378 * Handler for client's MONITOR_TUNNEL request. 6426 * Handler for client's MONITOR_TUNNEL request.
7379 * 6427 *
7380 * @param cls Closure (unused). 6428 * @param cls Closure (unused).
@@ -7387,7 +6435,6 @@ handle_local_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
7387{ 6435{
7388 const struct GNUNET_MESH_LocalMonitor *msg; 6436 const struct GNUNET_MESH_LocalMonitor *msg;
7389 struct GNUNET_MESH_LocalMonitor *resp; 6437 struct GNUNET_MESH_LocalMonitor *resp;
7390 struct MeshMonitorTunnelContext ctx;
7391 struct MeshClient *c; 6438 struct MeshClient *c;
7392 struct MeshTunnel *t; 6439 struct MeshTunnel *t;
7393 6440
@@ -7408,11 +6455,10 @@ handle_local_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
7408 t = tunnel_get (&msg->owner, ntohl (msg->tunnel_id)); 6455 t = tunnel_get (&msg->owner, ntohl (msg->tunnel_id));
7409 if (NULL == t) 6456 if (NULL == t)
7410 { 6457 {
7411 /* We don't know the tunnel */ 6458 /* We don't know the tunnel FIXME */
7412 struct GNUNET_MESH_LocalMonitor warn; 6459 struct GNUNET_MESH_LocalMonitor warn;
7413 6460
7414 warn = *msg; 6461 warn = *msg;
7415 warn.npeers = htonl (UINT_MAX);
7416 GNUNET_SERVER_notification_context_unicast (nc, client, 6462 GNUNET_SERVER_notification_context_unicast (nc, client,
7417 &warn.header, 6463 &warn.header,
7418 GNUNET_NO); 6464 GNUNET_NO);
@@ -7421,19 +6467,12 @@ handle_local_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
7421 } 6467 }
7422 6468
7423 /* Initialize context */ 6469 /* Initialize context */
7424 resp = GNUNET_malloc (USHRT_MAX); /* avoid realloc'ing on each step */ 6470 resp = GNUNET_malloc (sizeof (struct GNUNET_MESH_LocalMonitor));
7425 *resp = *msg; 6471 *resp = *msg;
7426 resp->npeers = 0; 6472 GNUNET_PEER_resolve (t->peer, &resp->destination);
7427 ctx.msg = resp; 6473 resp->header.size = htons (sizeof (struct GNUNET_MESH_LocalMonitor));
7428 ctx.lookup = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES); 6474 GNUNET_SERVER_notification_context_unicast (nc, c->handle,
7429 ctx.c = c; 6475 &resp->header, GNUNET_NO);
7430
7431 /* Collect and send information */
7432 tree_iterate_all (t->tree, &tunnel_tree_iterator, &ctx);
7433 send_client_tunnel_info (&ctx);
7434
7435 /* Free context */
7436 GNUNET_CONTAINER_multihashmap_destroy (ctx.lookup);
7437 GNUNET_free (resp); 6476 GNUNET_free (resp);
7438 6477
7439 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 6478 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -7449,46 +6488,22 @@ handle_local_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
7449static struct GNUNET_SERVER_MessageHandler client_handlers[] = { 6488static struct GNUNET_SERVER_MessageHandler client_handlers[] = {
7450 {&handle_local_new_client, NULL, 6489 {&handle_local_new_client, NULL,
7451 GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0}, 6490 GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0},
7452 {&handle_local_announce_regex, NULL,
7453 GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX, 0},
7454 {&handle_local_tunnel_create, NULL, 6491 {&handle_local_tunnel_create, NULL,
7455 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE, 6492 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE,
7456 sizeof (struct GNUNET_MESH_TunnelMessage)}, 6493 sizeof (struct GNUNET_MESH_TunnelMessage)},
7457 {&handle_local_tunnel_destroy, NULL, 6494 {&handle_local_tunnel_destroy, NULL,
7458 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY, 6495 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY,
7459 sizeof (struct GNUNET_MESH_TunnelMessage)}, 6496 sizeof (struct GNUNET_MESH_TunnelMessage)},
7460 {&handle_local_tunnel_speed, NULL,
7461 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MIN,
7462 sizeof (struct GNUNET_MESH_TunnelMessage)},
7463 {&handle_local_tunnel_speed, NULL,
7464 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_MAX,
7465 sizeof (struct GNUNET_MESH_TunnelMessage)},
7466 {&handle_local_tunnel_buffer, NULL, 6497 {&handle_local_tunnel_buffer, NULL,
7467 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_BUFFER, 6498 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_BUFFER,
7468 sizeof (struct GNUNET_MESH_TunnelMessage)}, 6499 sizeof (struct GNUNET_MESH_TunnelMessage)},
7469 {&handle_local_tunnel_buffer, NULL, 6500 {&handle_local_tunnel_buffer, NULL,
7470 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOBUFFER, 6501 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_NOBUFFER,
7471 sizeof (struct GNUNET_MESH_TunnelMessage)}, 6502 sizeof (struct GNUNET_MESH_TunnelMessage)},
7472 {&handle_local_connect_add, NULL,
7473 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD,
7474 sizeof (struct GNUNET_MESH_PeerControl)},
7475 {&handle_local_connect_del, NULL,
7476 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DEL,
7477 sizeof (struct GNUNET_MESH_PeerControl)},
7478 {&handle_local_blacklist, NULL,
7479 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_BLACKLIST,
7480 sizeof (struct GNUNET_MESH_PeerControl)},
7481 {&handle_local_unblacklist, NULL,
7482 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_UNBLACKLIST,
7483 sizeof (struct GNUNET_MESH_PeerControl)},
7484 {&handle_local_connect_by_string, NULL,
7485 GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD_BY_STRING, 0},
7486 {&handle_local_unicast, NULL, 6503 {&handle_local_unicast, NULL,
7487 GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0}, 6504 GNUNET_MESSAGE_TYPE_MESH_UNICAST, 0},
7488 {&handle_local_to_origin, NULL, 6505 {&handle_local_to_origin, NULL,
7489 GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0}, 6506 GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN, 0},
7490 {&handle_local_multicast, NULL,
7491 GNUNET_MESSAGE_TYPE_MESH_MULTICAST, 0},
7492 {&handle_local_ack, NULL, 6507 {&handle_local_ack, NULL,
7493 GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK, 6508 GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK,
7494 sizeof (struct GNUNET_MESH_LocalAck)}, 6509 sizeof (struct GNUNET_MESH_LocalAck)},
@@ -7703,11 +6718,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
7703 GNUNET_SCHEDULER_cancel (announce_id_task); 6718 GNUNET_SCHEDULER_cancel (announce_id_task);
7704 announce_id_task = GNUNET_SCHEDULER_NO_TASK; 6719 announce_id_task = GNUNET_SCHEDULER_NO_TASK;
7705 } 6720 }
7706 if (GNUNET_SCHEDULER_NO_TASK != announce_applications_task)
7707 {
7708 GNUNET_SCHEDULER_cancel (announce_applications_task);
7709 announce_applications_task = GNUNET_SCHEDULER_NO_TASK;
7710 }
7711 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n"); 6721 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n");
7712} 6722}
7713 6723
@@ -7778,7 +6788,6 @@ key_generation_cb (void *cls,
7778 clients_tail = NULL; 6788 clients_tail = NULL;
7779 next_client_id = 0; 6789 next_client_id = 0;
7780 6790
7781 announce_applications_task = GNUNET_SCHEDULER_NO_TASK;
7782 announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls); 6791 announce_id_task = GNUNET_SCHEDULER_add_now (&announce_id, cls);
7783 6792
7784 /* Create a peer_info for the local peer */ 6793 /* Create a peer_info for the local peer */
@@ -7929,7 +6938,6 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
7929 tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); 6938 tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
7930 incoming_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); 6939 incoming_tunnels = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
7931 peers = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); 6940 peers = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
7932 applications = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
7933 types = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO); 6941 types = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_NO);
7934 6942
7935 dht_handle = GNUNET_DHT_connect (c, 64); 6943 dht_handle = GNUNET_DHT_connect (c, 64);
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index 5b7e9991f..168c614dc 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -7890,8 +7890,6 @@ handle_local_show_tunnel (void *cls, struct GNUNET_SERVER_Client *client,
7890static struct GNUNET_SERVER_MessageHandler client_handlers[] = { 7890static struct GNUNET_SERVER_MessageHandler client_handlers[] = {
7891 {&handle_local_new_client, NULL, 7891 {&handle_local_new_client, NULL,
7892 GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0}, 7892 GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT, 0},
7893 {&handle_local_announce_regex, NULL,
7894 GNUNET_MESSAGE_TYPE_MESH_LOCAL_ANNOUNCE_REGEX, 0},
7895 {&handle_local_tunnel_create, NULL, 7893 {&handle_local_tunnel_create, NULL,
7896 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE, 7894 GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE,
7897 sizeof (struct GNUNET_MESH_TunnelMessage)}, 7895 sizeof (struct GNUNET_MESH_TunnelMessage)},
diff --git a/src/mesh/mesh2.h b/src/mesh/mesh2.h
index 39533e654..eaf386fd8 100644
--- a/src/mesh/mesh2.h
+++ b/src/mesh/mesh2.h
@@ -218,11 +218,6 @@ struct GNUNET_MESH_LocalMonitor
218 MESH_TunnelNumber tunnel_id GNUNET_PACKED; 218 MESH_TunnelNumber tunnel_id GNUNET_PACKED;
219 219
220 /** 220 /**
221 * Number of peers in the tunnel.
222 */
223 uint32_t npeers GNUNET_PACKED;
224
225 /**
226 * Alignment. 221 * Alignment.
227 */ 222 */
228 uint32_t reserved GNUNET_PACKED; 223 uint32_t reserved GNUNET_PACKED;
@@ -232,7 +227,10 @@ struct GNUNET_MESH_LocalMonitor
232 */ 227 */
233 struct GNUNET_PeerIdentity owner; 228 struct GNUNET_PeerIdentity owner;
234 229
235 /* struct GNUNET_PeerIdentity peers[npeers] */ 230 /**
231 * ID of the destination of the tunnel (can be local peer).
232 */
233 struct GNUNET_PeerIdentity destination;
236}; 234};
237 235
238 236
diff --git a/src/mesh/mesh2_api.c b/src/mesh/mesh2_api.c
index 98359dff6..b0d5f6909 100644
--- a/src/mesh/mesh2_api.c
+++ b/src/mesh/mesh2_api.c
@@ -208,16 +208,6 @@ struct GNUNET_MESH_Handle
208 */ 208 */
209 void *tunnel_cls; 209 void *tunnel_cls;
210 210
211 /**
212 * All the peer in the tunnel so far.
213 */
214 struct GNUNET_PeerIdentity *peers;
215
216 /**
217 * How many peers we have in this tunnel so far.
218 */
219 unsigned int tunnel_npeers;
220
221#if DEBUG_ACK 211#if DEBUG_ACK
222 unsigned int acks_sent; 212 unsigned int acks_sent;
223 unsigned int acks_recv; 213 unsigned int acks_recv;
@@ -901,20 +891,11 @@ process_incoming_data (struct GNUNET_MESH_Handle *h,
901 LOG (GNUNET_ERROR_TYPE_DEBUG, " ucast on tunnel %s [%X]\n", 891 LOG (GNUNET_ERROR_TYPE_DEBUG, " ucast on tunnel %s [%X]\n",
902 GNUNET_i2s (peer), ntohl (ucast->tid)); 892 GNUNET_i2s (peer), ntohl (ucast->tid));
903 break; 893 break;
904 case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
905 mcast = (struct GNUNET_MESH_Multicast *) message;
906 t = retrieve_tunnel (h, ntohl (mcast->tid));
907 payload = (struct GNUNET_MessageHeader *) &mcast[1];
908 peer = &mcast->oid;
909 pid = ntohl (mcast->pid);
910 LOG (GNUNET_ERROR_TYPE_DEBUG, " mcast on tunnel %s [%X]\n",
911 GNUNET_i2s (peer), ntohl (mcast->tid));
912 break;
913 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN: 894 case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
914 to_orig = (struct GNUNET_MESH_ToOrigin *) message; 895 to_orig = (struct GNUNET_MESH_ToOrigin *) message;
915 t = retrieve_tunnel (h, ntohl (to_orig->tid)); 896 t = retrieve_tunnel (h, ntohl (to_orig->tid));
916 payload = (struct GNUNET_MessageHeader *) &to_orig[1]; 897 payload = (struct GNUNET_MessageHeader *) &to_orig[1];
917 peer = &to_orig->sender; 898 GNUNET_PEER_resolve (t->peer, &peer);
918 pid = ntohl (to_orig->pid); 899 pid = ntohl (to_orig->pid);
919 LOG (GNUNET_ERROR_TYPE_DEBUG, " torig on tunnel %s [%X]\n", 900 LOG (GNUNET_ERROR_TYPE_DEBUG, " torig on tunnel %s [%X]\n",
920 GNUNET_i2s (peer), ntohl (to_orig->tid)); 901 GNUNET_i2s (peer), ntohl (to_orig->tid));
@@ -1022,7 +1003,6 @@ process_get_tunnels (struct GNUNET_MESH_Handle *h,
1022 const struct GNUNET_MessageHeader *message) 1003 const struct GNUNET_MessageHeader *message)
1023{ 1004{
1024 struct GNUNET_MESH_LocalMonitor *msg; 1005 struct GNUNET_MESH_LocalMonitor *msg;
1025 uint32_t npeers;
1026 1006
1027 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Tunnels messasge received\n"); 1007 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Tunnels messasge received\n");
1028 1008
@@ -1033,24 +1013,21 @@ process_get_tunnels (struct GNUNET_MESH_Handle *h,
1033 } 1013 }
1034 1014
1035 msg = (struct GNUNET_MESH_LocalMonitor *) message; 1015 msg = (struct GNUNET_MESH_LocalMonitor *) message;
1036 npeers = ntohl (msg->npeers);
1037 if (ntohs (message->size) != 1016 if (ntohs (message->size) !=
1038 (sizeof (struct GNUNET_MESH_LocalMonitor) + 1017 (sizeof (struct GNUNET_MESH_LocalMonitor) +
1039 npeers * sizeof (struct GNUNET_PeerIdentity))) 1018 sizeof (struct GNUNET_PeerIdentity)))
1040 { 1019 {
1041 GNUNET_break_op (0); 1020 GNUNET_break_op (0);
1042 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1021 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1043 "Get tunnels message: size %hu - expected %u (%u peers)\n", 1022 "Get tunnels message: size %hu - expected %u\n",
1044 ntohs (message->size), 1023 ntohs (message->size),
1045 sizeof (struct GNUNET_MESH_LocalMonitor) + 1024 sizeof (struct GNUNET_MESH_LocalMonitor));
1046 npeers * sizeof (struct GNUNET_PeerIdentity),
1047 npeers);
1048 return; 1025 return;
1049 } 1026 }
1050 h->tunnels_cb (h->tunnels_cls, 1027 h->tunnels_cb (h->tunnels_cls,
1051 ntohl (msg->tunnel_id), 1028 ntohl (msg->tunnel_id),
1052 &msg->owner, 1029 &msg->owner,
1053 (struct GNUNET_PeerIdentity *) &msg[1]); 1030 &msg->destination);
1054} 1031}
1055 1032
1056 1033
@@ -1066,11 +1043,7 @@ process_show_tunnel (struct GNUNET_MESH_Handle *h,
1066 const struct GNUNET_MessageHeader *message) 1043 const struct GNUNET_MessageHeader *message)
1067{ 1044{
1068 struct GNUNET_MESH_LocalMonitor *msg; 1045 struct GNUNET_MESH_LocalMonitor *msg;
1069 struct GNUNET_PeerIdentity *new_peers;
1070 uint32_t *new_parents;
1071 size_t esize; 1046 size_t esize;
1072 uint32_t npeers;
1073 unsigned int i;
1074 1047
1075 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Tunnel messasge received\n"); 1048 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Tunnel messasge received\n");
1076 1049
@@ -1082,40 +1055,25 @@ process_show_tunnel (struct GNUNET_MESH_Handle *h,
1082 1055
1083 /* Verify message sanity */ 1056 /* Verify message sanity */
1084 msg = (struct GNUNET_MESH_LocalMonitor *) message; 1057 msg = (struct GNUNET_MESH_LocalMonitor *) message;
1085 npeers = ntohl (msg->npeers);
1086 esize = sizeof (struct GNUNET_MESH_LocalMonitor); 1058 esize = sizeof (struct GNUNET_MESH_LocalMonitor);
1087 esize += npeers * (sizeof (struct GNUNET_PeerIdentity) + sizeof (uint32_t));
1088 if (ntohs (message->size) != esize) 1059 if (ntohs (message->size) != esize)
1089 { 1060 {
1090 GNUNET_break_op (0); 1061 GNUNET_break_op (0);
1091 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1062 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1092 "Show tunnel message: size %hu - expected %u (%u peers)\n", 1063 "Show tunnel message: size %hu - expected %u\n",
1093 ntohs (message->size), 1064 ntohs (message->size),
1094 esize, 1065 esize);
1095 npeers);
1096 1066
1097 h->tunnel_cb (h->tunnel_cls, NULL, NULL); 1067 h->tunnel_cb (h->tunnel_cls, NULL, NULL);
1098 h->tunnel_cb = NULL; 1068 h->tunnel_cb = NULL;
1099 h->tunnel_cls = NULL; 1069 h->tunnel_cls = NULL;
1100 h->tunnel_npeers = 0;
1101 GNUNET_free_non_null (h->peers);
1102 h->peers = NULL;
1103 1070
1104 return; 1071 return;
1105 } 1072 }
1106 1073
1107 new_peers = (struct GNUNET_PeerIdentity *) &msg[1]; 1074 h->tunnel_cb (h->tunnel_cls,
1108 new_parents = (uint32_t *) &new_peers[npeers]; 1075 &msg->destination,
1109 1076 &msg->owner);
1110 h->peers = GNUNET_realloc (h->peers, h->tunnel_npeers + npeers);
1111 memcpy (&h->peers[h->tunnel_npeers],
1112 new_peers,
1113 npeers * sizeof (struct GNUNET_PeerIdentity));
1114 h->tunnel_npeers += npeers;
1115 for (i = 0; i < npeers; i++)
1116 h->tunnel_cb (h->tunnel_cls,
1117 &new_peers[i],
1118 &h->peers[new_parents[i]]);
1119} 1077}
1120 1078
1121 1079
@@ -1259,7 +1217,6 @@ send_callback (void *cls, size_t size, void *buf)
1259 to.pid = htonl (t->next_send_pid); 1217 to.pid = htonl (t->next_send_pid);
1260 to.ttl = 0; 1218 to.ttl = 0;
1261 memset (&to.oid, 0, sizeof (struct GNUNET_PeerIdentity)); 1219 memset (&to.oid, 0, sizeof (struct GNUNET_PeerIdentity));
1262 memset (&to.sender, 0, sizeof (struct GNUNET_PeerIdentity));
1263 memcpy (cbuf, &to, sizeof (to)); 1220 memcpy (cbuf, &to, sizeof (to));
1264 } 1221 }
1265 } 1222 }
@@ -1712,6 +1669,7 @@ GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h)
1712 * Request information about a specific tunnel of the running mesh peer. 1669 * Request information about a specific tunnel of the running mesh peer.
1713 * 1670 *
1714 * WARNING: unstable API, likely to change in the future! 1671 * WARNING: unstable API, likely to change in the future!
1672 * FIXME Add destination option.
1715 * 1673 *
1716 * @param h Handle to the mesh peer. 1674 * @param h Handle to the mesh peer.
1717 * @param initiator ID of the owner of the tunnel. 1675 * @param initiator ID of the owner of the tunnel.
@@ -1730,7 +1688,6 @@ GNUNET_MESH_show_tunnel (struct GNUNET_MESH_Handle *h,
1730 1688
1731 msg.header.size = htons (sizeof (msg)); 1689 msg.header.size = htons (sizeof (msg));
1732 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL); 1690 msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL);
1733 msg.npeers = htonl (0);
1734 msg.owner = *initiator; 1691 msg.owner = *initiator;
1735 msg.tunnel_id = htonl (tunnel_number); 1692 msg.tunnel_id = htonl (tunnel_number);
1736 msg.reserved = 0; 1693 msg.reserved = 0;
diff --git a/src/mesh/mesh2_protocol.h b/src/mesh/mesh2_protocol.h
index 01f7f3487..9de407625 100644
--- a/src/mesh/mesh2_protocol.h
+++ b/src/mesh/mesh2_protocol.h
@@ -81,41 +81,6 @@ struct GNUNET_MESH_ManipulatePath
81 /* struct GNUNET_PeerIdentity peers[path_length]; */ 81 /* struct GNUNET_PeerIdentity peers[path_length]; */
82}; 82};
83 83
84/**
85 * Message for mesh data traffic to all tunnel targets.
86 */
87struct GNUNET_MESH_Multicast
88{
89 /**
90 * Type: GNUNET_MESSAGE_TYPE_MESH_MULTICAST
91 */
92 struct GNUNET_MessageHeader header;
93
94 /**
95 * TID of the tunnel
96 */
97 uint32_t tid GNUNET_PACKED;
98
99 /**
100 * Number of hops to live
101 */
102 uint32_t ttl GNUNET_PACKED;
103
104 /**
105 * Unique ID of the packet
106 */
107 uint32_t pid GNUNET_PACKED;
108
109 /**
110 * OID of the tunnel
111 */
112 struct GNUNET_PeerIdentity oid;
113
114 /**
115 * Payload follows
116 */
117};
118
119 84
120/** 85/**
121 * Message for mesh data traffic to a particular destination from origin. 86 * Message for mesh data traffic to a particular destination from origin.
@@ -148,11 +113,6 @@ struct GNUNET_MESH_Unicast
148 struct GNUNET_PeerIdentity oid; 113 struct GNUNET_PeerIdentity oid;
149 114
150 /** 115 /**
151 * Destination.
152 */
153 struct GNUNET_PeerIdentity destination;
154
155 /**
156 * Payload follows 116 * Payload follows
157 */ 117 */
158}; 118};
@@ -189,11 +149,6 @@ struct GNUNET_MESH_ToOrigin
189 struct GNUNET_PeerIdentity oid; 149 struct GNUNET_PeerIdentity oid;
190 150
191 /** 151 /**
192 * Sender of the message.
193 */
194 struct GNUNET_PeerIdentity sender;
195
196 /**
197 * Payload follows 152 * Payload follows
198 */ 153 */
199}; 154};