diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-09-27 11:36:07 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-09-27 11:36:07 +0000 |
commit | 6cbcd301264c12f18b2b837db0297b314ce120e7 (patch) | |
tree | c7b8ac4106e7ac3460deddbdeeb7304d21647c0d /src/mesh | |
parent | c337ebf6be7f4c4cd00ce80aa9e6e968d86be437 (diff) | |
download | gnunet-6cbcd301264c12f18b2b837db0297b314ce120e7.tar.gz gnunet-6cbcd301264c12f18b2b837db0297b314ce120e7.zip |
Fixed compiler warning, otherwise WiP with multicast retransmission
Diffstat (limited to 'src/mesh')
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 149 |
1 files changed, 54 insertions, 95 deletions
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c index 539d5ebdb..25ba15a8b 100644 --- a/src/mesh/gnunet-service-mesh.c +++ b/src/mesh/gnunet-service-mesh.c | |||
@@ -79,25 +79,27 @@ struct MeshDataDescriptor | |||
79 | /** ID of the tunnel this packet travels in */ | 79 | /** ID of the tunnel this packet travels in */ |
80 | struct MESH_TunnelID *origin; | 80 | struct MESH_TunnelID *origin; |
81 | 81 | ||
82 | /** Ultimate destination of the packet */ | 82 | /** Data itself */ |
83 | GNUNET_PEER_Id destination; | 83 | void *data; |
84 | |||
85 | /** Number of identical messages sent to different hops (multicast) */ | ||
86 | unsigned int copies; | ||
87 | |||
88 | /** Size of the data */ | ||
89 | size_t size; | ||
90 | 84 | ||
91 | /** Client that asked for the transmission, if any */ | 85 | /** Client that asked for the transmission, if any */ |
92 | struct GNUNET_SERVER_Client *client; | 86 | struct GNUNET_SERVER_Client *client; |
93 | 87 | ||
94 | /** Who was is message being sent to */ | 88 | /** Who was this message being sent to */ |
95 | struct MeshPeerInfo *peer; | 89 | struct MeshPeerInfo *peer; |
96 | 90 | ||
91 | /** Ultimate destination of the packet */ | ||
92 | GNUNET_PEER_Id destination; | ||
93 | |||
94 | /** Number of identical messages sent to different hops (multicast) */ | ||
95 | unsigned int copies; | ||
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; |
99 | 99 | ||
100 | /* Data at the end */ | 100 | /** Size of the data */ |
101 | size_t size; | ||
102 | |||
101 | }; | 103 | }; |
102 | 104 | ||
103 | 105 | ||
@@ -468,41 +470,7 @@ unsigned int next_client_id; | |||
468 | /************************ ITERATORS ****************************/ | 470 | /************************ ITERATORS ****************************/ |
469 | /******************************************************************************/ | 471 | /******************************************************************************/ |
470 | 472 | ||
471 | 473 | /* FIXME move iterators here */ | |
472 | /** | ||
473 | * Iterator over hash map peer entries collect all neighbors who to resend the | ||
474 | * data to. | ||
475 | * | ||
476 | * @param cls closure (**GNUNET_PEER_Id to store hops to send packet) | ||
477 | * @param key current key code (peer id hash) | ||
478 | * @param value value in the hash map (peer_info) | ||
479 | * @return GNUNET_YES if we should continue to iterate, GNUNET_NO if not. | ||
480 | */ | ||
481 | static int | ||
482 | iterate_collect_neighbors (void *cls, const GNUNET_HashCode * key, void *value) | ||
483 | { | ||
484 | struct MeshPeerInfo *peer_info = value; | ||
485 | struct MeshPathInfo *neighbors = cls; | ||
486 | struct GNUNET_PeerIdentity *id; | ||
487 | GNUNET_PEER_Id peer_id; | ||
488 | unsigned int i; | ||
489 | |||
490 | if (peer_info->id == myid) | ||
491 | { | ||
492 | return GNUNET_YES; | ||
493 | } | ||
494 | id = path_get_first_hop (neighbors->t->tree, peer_info->id); | ||
495 | peer_id = GNUNET_PEER_search(id); | ||
496 | for (i = 0; i < neighbors->path->length; i++) | ||
497 | { | ||
498 | if (neighbors->path->peers[i] == peer_id) | ||
499 | return GNUNET_YES; | ||
500 | } | ||
501 | GNUNET_array_append (neighbors->path->peers, neighbors->path->length, | ||
502 | peer_id); | ||
503 | |||
504 | return GNUNET_YES; | ||
505 | } | ||
506 | 474 | ||
507 | 475 | ||
508 | /******************************************************************************/ | 476 | /******************************************************************************/ |
@@ -941,32 +909,25 @@ path_build_from_dht (const struct GNUNET_PeerIdentity *const *get_path, | |||
941 | /** | 909 | /** |
942 | * Send keepalive packets for a peer | 910 | * Send keepalive packets for a peer |
943 | * | 911 | * |
944 | * @param cls unused | 912 | * @param cls Closure (tunnel for which to send the keepalive). |
945 | * @param tc unused | 913 | * @param tc Notification context. |
946 | * | ||
947 | * FIXME path | ||
948 | */ | 914 | */ |
949 | void | 915 | void |
950 | path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 916 | path_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
951 | { | 917 | { |
952 | struct MeshTunnel *t = cls; | 918 | struct MeshTunnel *t = cls; |
953 | 919 | ||
954 | // struct GNUNET_PeerIdentity id; | ||
955 | |||
956 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) | 920 | if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN) |
957 | { | 921 | { |
958 | return; | 922 | return; |
959 | } | 923 | } |
960 | /* FIXME implement multicast keepalive. Just an empty multicast packet? */ | 924 | /* FIXME path |
961 | // GNUNET_PEER_resolve (path_get_first_hop (path->t, path->peer)->id, &id); | 925 | * TODO: implement explicit multicast keepalive? */ |
962 | // GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, | 926 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, |
963 | // GNUNET_TIME_UNIT_FOREVER_REL, &id, | 927 | GNUNET_TIME_UNIT_FOREVER_REL, NULL, |
964 | // sizeof (struct GNUNET_MESH_ManipulatePath) | 928 | sizeof (struct GNUNET_MESH_ManipulatePath), |
965 | // + | 929 | NULL, //&send_core_data_multicast, |
966 | // (path->path->length * | 930 | t); |
967 | // sizeof (struct GNUNET_PeerIdentity)), | ||
968 | // &send_core_create_path, | ||
969 | // t); | ||
970 | t->path_refresh_task = | 931 | t->path_refresh_task = |
971 | GNUNET_SCHEDULER_add_delayed (t->tree->refresh, &path_refresh, t); | 932 | GNUNET_SCHEDULER_add_delayed (t->tree->refresh, &path_refresh, t); |
972 | return; | 933 | return; |
@@ -1401,7 +1362,10 @@ send_core_data_unicast (void *cls, size_t size, void *buf) | |||
1401 | * @param cls closure (data itself) | 1362 | * @param cls closure (data itself) |
1402 | * @param size number of bytes available in buf | 1363 | * @param size number of bytes available in buf |
1403 | * @param buf where the callee should write the message | 1364 | * @param buf where the callee should write the message |
1365 | * | ||
1404 | * @return number of bytes written to buf | 1366 | * @return number of bytes written to buf |
1367 | * | ||
1368 | * FIXME path | ||
1405 | */ | 1369 | */ |
1406 | static size_t | 1370 | static size_t |
1407 | send_core_data_multicast (void *cls, size_t size, void *buf) | 1371 | send_core_data_multicast (void *cls, size_t size, void *buf) |
@@ -1816,6 +1780,8 @@ handle_mesh_data_unicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1816 | * @param atsi performance data | 1780 | * @param atsi performance data |
1817 | * @return GNUNET_OK to keep the connection open, | 1781 | * @return GNUNET_OK to keep the connection open, |
1818 | * GNUNET_SYSERR to close it (signal serious error) | 1782 | * GNUNET_SYSERR to close it (signal serious error) |
1783 | * | ||
1784 | * TODO: Check who we got this from, to validate route. | ||
1819 | */ | 1785 | */ |
1820 | static int | 1786 | static int |
1821 | handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, | 1787 | handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, |
@@ -1825,17 +1791,14 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1825 | struct GNUNET_MESH_Multicast *msg; | 1791 | struct GNUNET_MESH_Multicast *msg; |
1826 | struct GNUNET_PeerIdentity id; | 1792 | struct GNUNET_PeerIdentity id; |
1827 | struct MeshDataDescriptor *info; | 1793 | struct MeshDataDescriptor *info; |
1828 | struct MeshPathInfo neighbors; | 1794 | struct MeshTunnelTreeNode *n; |
1829 | struct MeshTunnel *t; | 1795 | struct MeshTunnel *t; |
1796 | unsigned int copies; | ||
1797 | unsigned int i; | ||
1830 | size_t size; | 1798 | size_t size; |
1831 | uint16_t i; | ||
1832 | uint16_t j; | ||
1833 | |||
1834 | 1799 | ||
1835 | size = ntohs (message->size); | 1800 | size = ntohs (message->size) - sizeof (struct GNUNET_MESH_Multicast); |
1836 | if (size < | 1801 | if (size < sizeof (struct GNUNET_MessageHeader)) |
1837 | sizeof (struct GNUNET_MESH_Multicast) + | ||
1838 | sizeof (struct GNUNET_MessageHeader)) | ||
1839 | { | 1802 | { |
1840 | GNUNET_break_op (0); | 1803 | GNUNET_break_op (0); |
1841 | return GNUNET_OK; | 1804 | return GNUNET_OK; |
@@ -1846,6 +1809,7 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1846 | if (NULL == t) | 1809 | if (NULL == t) |
1847 | { | 1810 | { |
1848 | /* TODO notify that we dont know that tunnel */ | 1811 | /* TODO notify that we dont know that tunnel */ |
1812 | GNUNET_break_op (0); | ||
1849 | return GNUNET_OK; | 1813 | return GNUNET_OK; |
1850 | } | 1814 | } |
1851 | 1815 | ||
@@ -1854,46 +1818,41 @@ handle_mesh_data_multicast (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1854 | { | 1818 | { |
1855 | send_subscribed_clients ((struct GNUNET_MessageHeader *) &msg[1]); | 1819 | send_subscribed_clients ((struct GNUNET_MessageHeader *) &msg[1]); |
1856 | } | 1820 | } |
1857 | 1821 | n = t->tree->me->children_head; | |
1858 | /* Retransmit to other peers. | 1822 | if (NULL == n) |
1859 | * Using path here as just a collection of peers, not a path per se. | ||
1860 | */ | ||
1861 | neighbors.t = t; | ||
1862 | neighbors.path = path_new (0); | ||
1863 | GNUNET_CONTAINER_multihashmap_iterate (t->peers, &iterate_collect_neighbors, | ||
1864 | &neighbors); | ||
1865 | if (0 == neighbors.path->length) | ||
1866 | { | ||
1867 | GNUNET_free (neighbors.path); | ||
1868 | return GNUNET_OK; | 1823 | return GNUNET_OK; |
1869 | } | 1824 | for (copies = 0; NULL != n; n = n->next) |
1870 | size -= sizeof (struct GNUNET_MESH_Multicast); | 1825 | copies++; |
1871 | info = GNUNET_malloc (sizeof (struct MeshDataDescriptor) + size); | 1826 | n = t->tree->me->children_head; |
1827 | info = GNUNET_malloc (sizeof (struct MeshDataDescriptor)); | ||
1828 | info->data = GNUNET_malloc (size); | ||
1829 | memcpy(info->data, &msg[1], size); | ||
1872 | info->origin = &t->id; | 1830 | info->origin = &t->id; |
1873 | info->copies = neighbors.path->length; | 1831 | info->copies = copies; |
1874 | for (i = 0; i < info->copies; i++) | 1832 | info->size = size; |
1833 | info->client = t->client->handle; | ||
1834 | while (NULL != n) | ||
1875 | { | 1835 | { |
1876 | GNUNET_PEER_resolve (neighbors.path->peers[i], &id); | 1836 | GNUNET_PEER_resolve (n->peer, &id); |
1877 | info->peer = GNUNET_CONTAINER_multihashmap_get (peers, &id.hashPubKey); | 1837 | info->peer = peer_info_get(&id); |
1878 | GNUNET_assert (NULL != info->peer); | 1838 | GNUNET_assert (NULL != info->peer); |
1879 | for (j = 0; 0 != info->peer->core_transmit[j]; j++) | 1839 | for (i = 0; NULL != info->peer->core_transmit[i]; i++) |
1880 | { | 1840 | { |
1881 | if (j == (CORE_QUEUE_SIZE - 1)) | 1841 | if (i == (CORE_QUEUE_SIZE - 1)) |
1882 | { | 1842 | { |
1883 | GNUNET_break (0); | 1843 | GNUNET_break (0); |
1884 | return GNUNET_OK; | 1844 | return GNUNET_OK; |
1885 | } | 1845 | } |
1886 | } | 1846 | } |
1887 | info->handler_n = j; | 1847 | info->handler_n = i; |
1888 | info->peer->infos[j] = info; | 1848 | info->peer->infos[i] = info; |
1889 | info->peer->core_transmit[j] = | 1849 | info->peer->core_transmit[i] = |
1890 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, | 1850 | GNUNET_CORE_notify_transmit_ready (core_handle, 0, 0, |
1891 | GNUNET_TIME_UNIT_FOREVER_REL, &id, | 1851 | GNUNET_TIME_UNIT_FOREVER_REL, &id, |
1892 | ntohs (msg->header.size), | 1852 | ntohs (msg->header.size), |
1893 | &send_core_data_multicast, info); | 1853 | &send_core_data_multicast, info); |
1894 | } | 1854 | } |
1895 | GNUNET_free (neighbors.path->peers); | 1855 | |
1896 | GNUNET_free (neighbors.path); | ||
1897 | return GNUNET_OK; | 1856 | return GNUNET_OK; |
1898 | } | 1857 | } |
1899 | 1858 | ||
@@ -2010,7 +1969,7 @@ handle_mesh_path_ack (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
2010 | GNUNET_break_op (0); | 1969 | GNUNET_break_op (0); |
2011 | return GNUNET_OK; | 1970 | return GNUNET_OK; |
2012 | } | 1971 | } |
2013 | n = tree_find_peer(t->tree, peer_info->id); | 1972 | n = tree_find_peer(t->tree->root, peer_info->id); |
2014 | if (NULL == n) | 1973 | if (NULL == n) |
2015 | { | 1974 | { |
2016 | GNUNET_break_op (0); | 1975 | GNUNET_break_op (0); |