diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-09-27 17:34:12 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-09-27 17:34:12 +0000 |
commit | 31ee5f418d7ae0d1ede1f24397769868e4341e28 (patch) | |
tree | 0bb901d488c3848e39390a097d99a90dcee402a1 /src | |
parent | 25460d90ddba69630ad9363d5fd43c000069a9dc (diff) | |
download | gnunet-31ee5f418d7ae0d1ede1f24397769868e4341e28.tar.gz gnunet-31ee5f418d7ae0d1ede1f24397769868e4341e28.zip |
WiP
Diffstat (limited to 'src')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 143 |
1 files changed, 49 insertions, 94 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 25ba15a8b..c90cada1b 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -92,7 +92,7 @@ struct MeshDataDescriptor | |||
92 | GNUNET_PEER_Id destination; | 92 | GNUNET_PEER_Id destination; |
93 | 93 | ||
94 | /** Number of identical messages sent to different hops (multicast) */ | 94 | /** Number of identical messages sent to different hops (multicast) */ |
95 | unsigned int copies; | 95 | unsigned int *copies; |
96 | 96 | ||
97 | /** Which handler was used to request the transmission */ | 97 | /** Which handler was used to request the transmission */ |
98 | unsigned int handler_n; | 98 | unsigned int handler_n; |
@@ -1307,51 +1307,6 @@ send_core_data_to_origin (void *cls, size_t size, void *buf) | |||
1307 | } | 1307 | } |
1308 | #endif | 1308 | #endif |
1309 | 1309 | ||
1310 | /** | ||
1311 | * Function called to notify a client about the socket | ||
1312 | * being ready to queue more data. "buf" will be | ||
1313 | * NULL and "size" zero if the socket was closed for | ||
1314 | * writing in the meantime. | ||
1315 | * | ||
1316 | * @param cls closure (data itself) | ||
1317 | * @param size number of bytes available in buf | ||
1318 | * @param buf where the callee should write the message | ||
1319 | * @return number of bytes written to buf | ||
1320 | */ | ||
1321 | static size_t | ||
1322 | send_core_data_unicast (void *cls, size_t size, void *buf) | ||
1323 | { | ||
1324 | struct MeshDataDescriptor *info = cls; | ||
1325 | struct GNUNET_MESH_Unicast *msg = buf; | ||
1326 | size_t total_size; | ||
1327 | |||
1328 | GNUNET_assert (NULL != info); | ||
1329 | total_size = sizeof (struct GNUNET_MESH_Unicast) + info->size; | ||
1330 | GNUNET_assert (total_size < 65536); /* UNIT16_MAX */ | ||
1331 | |||
1332 | if (total_size > size) | ||
1333 | { | ||
1334 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1335 | "not enough buffer to send data to peer\n"); | ||
1336 | return 0; | ||
1337 | } | ||
1338 | msg->header.size = htons (total_size); | ||
1339 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_UNICAST); | ||
1340 | GNUNET_PEER_resolve (info->origin->oid, &msg->oid); | ||
1341 | GNUNET_PEER_resolve (info->destination, &msg->destination); | ||
1342 | msg->tid = htonl (info->origin->tid); | ||
1343 | if (0 != info->size) | ||
1344 | { | ||
1345 | memcpy (&msg[1], &info[1], info->size); | ||
1346 | } | ||
1347 | if (NULL != info->client) | ||
1348 | { | ||
1349 | GNUNET_SERVER_receive_done (info->client, GNUNET_OK); | ||
1350 | } | ||
1351 | GNUNET_free (info); | ||
1352 | return total_size; | ||
1353 | } | ||
1354 | |||
1355 | 1310 | ||
1356 | /** | 1311 | /** |
1357 | * Function called to notify a client about the socket | 1312 | * Function called to notify a client about the socket |
@@ -1381,26 +1336,31 @@ send_core_data_multicast (void *cls, size_t size, void *buf) | |||
1381 | if (info->peer) | 1336 | if (info->peer) |
1382 | { | 1337 | { |
1383 | info->peer->core_transmit[info->handler_n] = NULL; | 1338 | info->peer->core_transmit[info->handler_n] = NULL; |
1339 | info->peer->infos[info->handler_n] = NULL; | ||
1384 | } | 1340 | } |
1385 | if (total_size > size) | 1341 | if (total_size > size) |
1386 | { | 1342 | { |
1387 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1343 | GNUNET_break (0); |
1388 | "not enough buffer to send data futher\n"); | 1344 | total_size = 0; |
1389 | return 0; | ||
1390 | } | 1345 | } |
1391 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); | 1346 | else |
1392 | msg->header.size = htons (total_size); | 1347 | { |
1393 | GNUNET_PEER_resolve (info->origin->oid, &msg->oid); | 1348 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_MULTICAST); |
1394 | msg->tid = htonl (info->origin->tid); | 1349 | msg->header.size = htons (total_size); |
1395 | memcpy (&msg[1], &info[1], total_size); | 1350 | GNUNET_PEER_resolve (info->origin->oid, &msg->oid); |
1396 | if (0 == --info->copies) | 1351 | msg->tid = htonl (info->origin->tid); |
1352 | memcpy (&msg[1], info->data, total_size); | ||
1353 | } | ||
1354 | if (0 == --(*info->copies)) | ||
1397 | { | 1355 | { |
1398 | if (NULL != info->client) | 1356 | if (NULL != info->client) |
1399 | { | 1357 | { |
1400 | GNUNET_SERVER_receive_done (info->client, GNUNET_OK); | 1358 | GNUNET_SERVER_receive_done (info->client, GNUNET_OK); |
1401 | } | 1359 | } |
1402 | GNUNET_free (info); | 1360 | GNUNET_free (info->data); |
1361 | GNUNET_free (info->copies); | ||
1403 | } | 1362 | } |
1363 | GNUNET_free (info); | ||
1404 | return total_size; | 1364 | return total_size; |
1405 | } | 1365 | } |
1406 | 1366 | ||
@@ -1789,13 +1749,14 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1789 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1749 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1790 | { | 1750 | { |
1791 | struct GNUNET_MESH_Multicast *msg; | 1751 | struct GNUNET_MESH_Multicast *msg; |
1792 | struct GNUNET_PeerIdentity id; | 1752 | struct GNUNET_PeerIdentity *id; |
1793 | struct MeshDataDescriptor *info; | 1753 | struct MeshDataDescriptor *info; |
1794 | struct MeshTunnelTreeNode *n; | 1754 | struct MeshTunnelTreeNode *n; |
1795 | struct MeshTunnel *t; | 1755 | struct MeshTunnel *t; |
1796 | unsigned int copies; | 1756 | unsigned int *copies; |
1797 | unsigned int i; | 1757 | unsigned int i; |
1798 | size_t size; | 1758 | size_t size; |
1759 | void *data; | ||
1799 | 1760 | ||
1800 | size = ntohs (message->size) - sizeof (struct GNUNET_MESH_Multicast); | 1761 | size = ntohs (message->size) - sizeof (struct GNUNET_MESH_Multicast); |
1801 | if (size < sizeof (struct GNUNET_MessageHeader)) | 1762 | if (size < sizeof (struct GNUNET_MessageHeader)) |
@@ -1821,20 +1782,23 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1821 | n = t->tree->me->children_head; | 1782 | n = t->tree->me->children_head; |
1822 | if (NULL == n) | 1783 | if (NULL == n) |
1823 | return GNUNET_OK; | 1784 | return GNUNET_OK; |
1824 | for (copies = 0; NULL != n; n = n->next) | 1785 | copies = GNUNET_malloc (sizeof (unsigned int)); |
1825 | copies++; | 1786 | for (*copies = 0; NULL != n; n = n->next) |
1787 | (*copies)++; | ||
1826 | n = t->tree->me->children_head; | 1788 | n = t->tree->me->children_head; |
1827 | info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); | 1789 | data = GNUNET_malloc (size); |
1828 | info->data = GNUNET_malloc (size); | 1790 | memcpy (data, &msg[1], size); |
1829 | memcpy(info->data, &msg[1], size); | ||
1830 | info->origin = &t->id; | ||
1831 | info->copies = copies; | ||
1832 | info->size = size; | ||
1833 | info->client = t->client->handle; | ||
1834 | while (NULL != n) | 1791 | while (NULL != n) |
1835 | { | 1792 | { |
1836 | GNUNET_PEER_resolve (n->peer, &id); | 1793 | info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); |
1837 | info->peer = peer_info_get(&id); | 1794 | info->origin = &t->id; |
1795 | info->data = data; | ||
1796 | info->size = size; | ||
1797 | info->copies = copies; | ||
1798 | info->client = t->client->handle; | ||
1799 | info->destination = n->peer; | ||
1800 | id = path_get_first_hop(t->tree, n->peer); | ||
1801 | info->peer = peer_info_get(id); | ||
1838 | GNUNET_assert (NULL != info->peer); | 1802 | GNUNET_assert (NULL != info->peer); |
1839 | for (i = 0; NULL != info->peer->core_transmit[i]; i++) | 1803 | for (i = 0; NULL != info->peer->core_transmit[i]; i++) |
1840 | { | 1804 | { |
@@ -1848,7 +1812,7 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1848 | info->peer->infos[i] = info; | 1812 | info->peer->infos[i] = info; |
1849 | info->peer->core_transmit[i] = | 1813 | info->peer->core_transmit[i] = |
1850 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, | 1814 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, |
1851 | GNUNET_TIME_UNIT_FOREVER_REL, &id, | 1815 | GNUNET_TIME_UNIT_FOREVER_REL, id, |
1852 | ntohs (msg->header.size), | 1816 | ntohs (msg->header.size), |
1853 | &send_core_data_multicast, info); | 1817 | &send_core_data_multicast, info); |
1854 | } | 1818 | } |
@@ -2820,9 +2784,8 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client, | |||
2820 | struct MeshTunnel *t; | 2784 | struct MeshTunnel *t; |
2821 | struct MeshPeerInfo *pi; | 2785 | struct MeshPeerInfo *pi; |
2822 | struct GNUNET_MESH_Unicast *data_msg; | 2786 | struct GNUNET_MESH_Unicast *data_msg; |
2823 | struct MeshDataDescriptor *info; | ||
2824 | MESH_TunnelNumber tid; | 2787 | MESH_TunnelNumber tid; |
2825 | size_t data_size; | 2788 | size_t size; |
2826 | 2789 | ||
2827 | /* Sanity check for client registration */ | 2790 | /* Sanity check for client registration */ |
2828 | if (NULL == (c = client_get (client))) | 2791 | if (NULL == (c = client_get (client))) |
@@ -2833,8 +2796,9 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client, | |||
2833 | } | 2796 | } |
2834 | data_msg = (struct GNUNET_MESH_Unicast *) message; | 2797 | data_msg = (struct GNUNET_MESH_Unicast *) message; |
2835 | /* Sanity check for message size */ | 2798 | /* Sanity check for message size */ |
2799 | size = ntohs (message->size); | ||
2836 | if (sizeof (struct GNUNET_MESH_Unicast) + | 2800 | if (sizeof (struct GNUNET_MESH_Unicast) + |
2837 | sizeof (struct GNUNET_MessageHeader) > ntohs (data_msg->header.size)) | 2801 | sizeof (struct GNUNET_MessageHeader) > size) |
2838 | { | 2802 | { |
2839 | GNUNET_break (0); | 2803 | GNUNET_break (0); |
2840 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2804 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
@@ -2868,31 +2832,22 @@ handle_local_unicast (void *cls, struct GNUNET_SERVER_Client *client, | |||
2868 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 2832 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
2869 | return; | 2833 | return; |
2870 | } | 2834 | } |
2871 | if (pi->id == myid) | 2835 | |
2836 | /* Ok, everything is correct, send the message | ||
2837 | * (pretend we got it from a mesh peer) | ||
2838 | */ | ||
2872 | { | 2839 | { |
2873 | struct GNUNET_MESH_Unicast copy; | 2840 | char buf[ntohs (message->size)]; |
2841 | struct GNUNET_MESH_Unicast *copy; | ||
2874 | 2842 | ||
2875 | /* Work around const limitation */ | 2843 | /* Work around const limitation */ |
2876 | memcpy (©, data_msg, sizeof (struct GNUNET_MESH_Unicast)); | 2844 | copy = (struct GNUNET_MESH_Unicast *) buf; |
2877 | copy.oid = my_full_id; | 2845 | memcpy (buf, data_msg, size); |
2878 | copy.tid = htonl (t->id.tid); | 2846 | copy->oid = my_full_id; |
2879 | handle_mesh_data_unicast (NULL, &my_full_id, ©.header, NULL); | 2847 | copy->tid = htonl (t->id.tid); |
2880 | return; | 2848 | handle_mesh_data_unicast (NULL, &my_full_id, ©->header, NULL); |
2849 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
2881 | } | 2850 | } |
2882 | data_size = ntohs (message->size) - sizeof (struct GNUNET_MESH_Unicast); | ||
2883 | info = GNUNET_malloc (sizeof (struct MeshDataDescriptor) + data_size); | ||
2884 | memcpy (&info[1], &data_msg[1], data_size); | ||
2885 | info->destination = pi->id; | ||
2886 | info->origin = &t->id; | ||
2887 | info->size = data_size; | ||
2888 | info->client = client; | ||
2889 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, | ||
2890 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
2891 | path_get_first_hop (t->tree, pi->id), | ||
2892 | /* FIXME re-check types */ | ||
2893 | data_size + | ||
2894 | sizeof (struct GNUNET_MESH_Unicast), | ||
2895 | &send_core_data_unicast, info); | ||
2896 | return; | 2851 | return; |
2897 | } | 2852 | } |
2898 | 2853 | ||