diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-18 18:48:38 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-18 18:48:38 +0000 |
commit | 91bbd8cd39ca071c3957f9905b8dd185d48f6b7a (patch) | |
tree | d7a6ee189d54e8495f2397a2bae797d2dca2a572 | |
parent | 99e53626db6c906892e35a0d525938be8cb5a366 (diff) | |
download | gnunet-91bbd8cd39ca071c3957f9905b8dd185d48f6b7a.tar.gz gnunet-91bbd8cd39ca071c3957f9905b8dd185d48f6b7a.zip |
-towards changing use of target distance to be from source (incomplete)
-rw-r--r-- | src/dv/gnunet-service-dv.c | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index 1c185197a..7cfbadbd5 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c | |||
@@ -650,7 +650,7 @@ core_transmit_notify (void *cls, size_t size, void *buf) | |||
650 | * Forward the given payload to the given target. | 650 | * Forward the given payload to the given target. |
651 | * | 651 | * |
652 | * @param target where to send the message | 652 | * @param target where to send the message |
653 | * @param distance expected (remaining) distance to the target | 653 | * @param distance distance to the @a sender |
654 | * @param uid unique ID for the message | 654 | * @param uid unique ID for the message |
655 | * @param sender original sender of the message | 655 | * @param sender original sender of the message |
656 | * @param actual_target ultimate recipient for the message | 656 | * @param actual_target ultimate recipient for the message |
@@ -1788,23 +1788,26 @@ handle_dv_route_message (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1788 | return GNUNET_SYSERR; | 1788 | return GNUNET_SYSERR; |
1789 | } | 1789 | } |
1790 | rm = (const struct RouteMessage *) message; | 1790 | rm = (const struct RouteMessage *) message; |
1791 | distance = ntohl (rm->distance); | ||
1792 | payload = (const struct GNUNET_MessageHeader *) &rm[1]; | ||
1793 | if (ntohs (message->size) != sizeof (struct RouteMessage) + ntohs (payload->size)) | ||
1794 | { | ||
1795 | GNUNET_break_op (0); | ||
1796 | return GNUNET_SYSERR; | ||
1797 | } | ||
1791 | strncpy (prev, GNUNET_i2s (peer), 4); | 1798 | strncpy (prev, GNUNET_i2s (peer), 4); |
1792 | strncpy (me, GNUNET_i2s (&my_identity), 4); | 1799 | strncpy (me, GNUNET_i2s (&my_identity), 4); |
1793 | strncpy (src, GNUNET_i2s (&rm->sender), 4); | 1800 | strncpy (src, GNUNET_i2s (&rm->sender), 4); |
1794 | strncpy (dst, GNUNET_i2s (&rm->target), 4); | 1801 | strncpy (dst, GNUNET_i2s (&rm->target), 4); |
1795 | prev[4] = me[4] = src[4] = dst[4] = '\0'; | 1802 | prev[4] = me[4] = src[4] = dst[4] = '\0'; |
1796 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1803 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1797 | "Handling DV message from %s to %s routed by %s to me (%s @ %u)\n", | 1804 | "Handling DV message with %u bytes payload of type %u from %s to %s routed by %s to me (%s @ hop %u)\n", |
1805 | ntohs (message->size) - sizeof (struct RouteMessage), | ||
1806 | ntohs (payload->type), | ||
1798 | src, dst, | 1807 | src, dst, |
1799 | prev, me, | 1808 | prev, me, |
1800 | (unsigned int) ntohl (rm->distance)); | 1809 | (unsigned int) distance + 1); |
1801 | 1810 | ||
1802 | payload = (const struct GNUNET_MessageHeader *) &rm[1]; | ||
1803 | if (ntohs (message->size) != sizeof (struct RouteMessage) + ntohs (payload->size)) | ||
1804 | { | ||
1805 | GNUNET_break_op (0); | ||
1806 | return GNUNET_SYSERR; | ||
1807 | } | ||
1808 | if (0 == memcmp (&rm->target, | 1811 | if (0 == memcmp (&rm->target, |
1809 | &my_identity, | 1812 | &my_identity, |
1810 | sizeof (struct GNUNET_PeerIdentity))) | 1813 | sizeof (struct GNUNET_PeerIdentity))) |
@@ -1815,7 +1818,7 @@ handle_dv_route_message (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1815 | if ( (NULL == route) && | 1818 | if ( (NULL == route) && |
1816 | (NULL == GNUNET_CONTAINER_multipeermap_get (direct_neighbors, | 1819 | (NULL == GNUNET_CONTAINER_multipeermap_get (direct_neighbors, |
1817 | &rm->sender)) && | 1820 | &rm->sender)) && |
1818 | (ntohl (rm->distance) < DEFAULT_FISHEYE_DEPTH) ) | 1821 | (distance < DEFAULT_FISHEYE_DEPTH) ) |
1819 | { | 1822 | { |
1820 | /* don't have reverse route yet, learn it! */ | 1823 | /* don't have reverse route yet, learn it! */ |
1821 | neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, | 1824 | neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, |
@@ -1827,11 +1830,11 @@ handle_dv_route_message (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1827 | } | 1830 | } |
1828 | target = GNUNET_new (struct Target); | 1831 | target = GNUNET_new (struct Target); |
1829 | target->peer = rm->sender; | 1832 | target->peer = rm->sender; |
1830 | target->distance = htonl (ntohl (rm->distance)); | 1833 | target->distance = htonl (distance); |
1831 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1834 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1832 | "Learning target %s at distance %u from delivery!\n", | 1835 | "Learning sender %s at distance %u from delivery!\n", |
1833 | GNUNET_i2s (&rm->sender), | 1836 | GNUNET_i2s (&rm->sender), |
1834 | 1 + ntohl (rm->distance)); | 1837 | (unsigned int) distance + 1); |
1835 | if (NULL == neighbor->neighbor_table) | 1838 | if (NULL == neighbor->neighbor_table) |
1836 | neighbor->neighbor_table = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 1839 | neighbor->neighbor_table = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); |
1837 | if (GNUNET_YES != | 1840 | if (GNUNET_YES != |
@@ -1846,11 +1849,12 @@ handle_dv_route_message (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1846 | add_new_route (target, neighbor); | 1849 | add_new_route (target, neighbor); |
1847 | } | 1850 | } |
1848 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1849 | "Delivering %u bytes to myself!\n", | 1852 | "Delivering %u bytes from %s to myself!\n", |
1850 | ntohs (payload->size)); | 1853 | ntohs (payload->size), |
1854 | GNUNET_i2s (&rm->sender)); | ||
1851 | send_data_to_plugin (payload, | 1855 | send_data_to_plugin (payload, |
1852 | &rm->sender, | 1856 | &rm->sender, |
1853 | 1 + ntohl (rm->distance)); | 1857 | 1 + distance); |
1854 | return GNUNET_OK; | 1858 | return GNUNET_OK; |
1855 | } | 1859 | } |
1856 | if ( (NULL == GNUNET_CONTAINER_multipeermap_get (direct_neighbors, | 1860 | if ( (NULL == GNUNET_CONTAINER_multipeermap_get (direct_neighbors, |
@@ -1859,9 +1863,9 @@ handle_dv_route_message (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1859 | &rm->sender)) ) | 1863 | &rm->sender)) ) |
1860 | { | 1864 | { |
1861 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1865 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1862 | "Learning target %s at distance %u from forwarding!\n", | 1866 | "Learning sender %s at distance %u from forwarding!\n", |
1863 | GNUNET_i2s (&rm->sender), | 1867 | GNUNET_i2s (&rm->sender), |
1864 | 1 + ntohl (rm->distance)); | 1868 | 1 + distance); |
1865 | neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, | 1869 | neighbor = GNUNET_CONTAINER_multipeermap_get (direct_neighbors, |
1866 | peer); | 1870 | peer); |
1867 | if (NULL == neighbor) | 1871 | if (NULL == neighbor) |
@@ -1871,7 +1875,7 @@ handle_dv_route_message (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1871 | } | 1875 | } |
1872 | target = GNUNET_new (struct Target); | 1876 | target = GNUNET_new (struct Target); |
1873 | target->peer = rm->sender; | 1877 | target->peer = rm->sender; |
1874 | target->distance = htonl (ntohl (rm->distance)); | 1878 | target->distance = htonl (distance); |
1875 | if (NULL == neighbor->neighbor_table) | 1879 | if (NULL == neighbor->neighbor_table) |
1876 | neighbor->neighbor_table = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); | 1880 | neighbor->neighbor_table = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO); |
1877 | if (GNUNET_YES != | 1881 | if (GNUNET_YES != |
@@ -1903,28 +1907,16 @@ handle_dv_route_message (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1903 | 1, GNUNET_NO); | 1907 | 1, GNUNET_NO); |
1904 | return GNUNET_OK; | 1908 | return GNUNET_OK; |
1905 | } | 1909 | } |
1906 | distance = DIRECT_NEIGHBOR_COST; | ||
1907 | } | 1910 | } |
1908 | else | 1911 | else |
1909 | { | 1912 | { |
1910 | if (ntohl (route->target.distance) > ntohl (rm->distance) + 1) | ||
1911 | { | ||
1912 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1913 | "Distance too far, not routing %u bytes!\n", | ||
1914 | ntohs (payload->size)); | ||
1915 | GNUNET_STATISTICS_update (stats, | ||
1916 | "# messages discarded (target too far)", | ||
1917 | 1, GNUNET_NO); | ||
1918 | return GNUNET_OK; | ||
1919 | } | ||
1920 | neighbor = route->next_hop; | 1913 | neighbor = route->next_hop; |
1921 | distance = ntohl (route->target.distance); | ||
1922 | } | 1914 | } |
1923 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1915 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1924 | "Forwarding message to %s\n", | 1916 | "Forwarding message to %s\n", |
1925 | GNUNET_i2s (&neighbor->peer)); | 1917 | GNUNET_i2s (&neighbor->peer)); |
1926 | forward_payload (neighbor, | 1918 | forward_payload (neighbor, |
1927 | distance, | 1919 | distance + 1, |
1928 | 0, | 1920 | 0, |
1929 | &rm->sender, | 1921 | &rm->sender, |
1930 | &rm->target, | 1922 | &rm->target, |