diff options
author | Nathan S. Evans <evans@in.tum.de> | 2011-02-23 11:01:23 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2011-02-23 11:01:23 +0000 |
commit | e94568c6b82c1c89dfe46c75ff174a5254ba24ee (patch) | |
tree | 04c58f2be4c5558276b193e3fc2e21e0c3321b5b /src/testing | |
parent | fe27f72b593c3d82752935bf92df10d9ed9c1e2a (diff) | |
download | gnunet-e94568c6b82c1c89dfe46c75ff174a5254ba24ee.tar.gz gnunet-e94568c6b82c1c89dfe46c75ff174a5254ba24ee.zip |
hack to make NAT topologies work
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/testing_group.c | 100 |
1 files changed, 95 insertions, 5 deletions
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 90aad3ca2..70fe3d4c8 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -40,6 +40,8 @@ | |||
40 | 40 | ||
41 | #define USE_SEND_HELLOS GNUNET_NO | 41 | #define USE_SEND_HELLOS GNUNET_NO |
42 | 42 | ||
43 | #define TOPOLOGY_HACK GNUNET_YES | ||
44 | |||
43 | /** | 45 | /** |
44 | * Lowest port used for GNUnet testing. Should be high enough to not | 46 | * Lowest port used for GNUnet testing. Should be high enough to not |
45 | * conflict with other applications running on the hosts but be low | 47 | * conflict with other applications running on the hosts but be low |
@@ -1840,12 +1842,67 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, | |||
1840 | GNUNET_free (p_string); | 1842 | GNUNET_free (p_string); |
1841 | } | 1843 | } |
1842 | 1844 | ||
1845 | cutoff = (unsigned int) (nat_percentage * pg->total); | ||
1846 | connect_attempts = 0; | ||
1847 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | ||
1848 | { | ||
1849 | for (inner_count = outer_count + 1; inner_count < pg->total; | ||
1850 | inner_count++) | ||
1851 | { | ||
1852 | if ((outer_count > cutoff) || (inner_count > cutoff)) | ||
1853 | { | ||
1854 | #if VERBOSE_TESTING | ||
1855 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1856 | "Connecting peer %d to peer %d\n", | ||
1857 | outer_count, inner_count); | ||
1858 | #endif | ||
1859 | connect_attempts += proc (pg, outer_count, inner_count, list); | ||
1860 | } | ||
1861 | } | ||
1862 | } | ||
1863 | return connect_attempts; | ||
1864 | } | ||
1865 | |||
1866 | #if TOPOLOGY_HACK | ||
1867 | /** | ||
1868 | * Create a topology given a peer group (set of running peers) | ||
1869 | * and a connection processor. | ||
1870 | * | ||
1871 | * @param pg the peergroup to create the topology on | ||
1872 | * @param proc the connection processor to call to actually set | ||
1873 | * up connections between two peers | ||
1874 | * @param list the peer list to use | ||
1875 | * | ||
1876 | * @return the number of connections that were set up | ||
1877 | * | ||
1878 | */ | ||
1879 | static unsigned int | ||
1880 | create_nated_internet_copy (struct GNUNET_TESTING_PeerGroup *pg, | ||
1881 | GNUNET_TESTING_ConnectionProcessor proc, | ||
1882 | enum PeerLists list) | ||
1883 | { | ||
1884 | unsigned int outer_count, inner_count; | ||
1885 | unsigned int cutoff; | ||
1886 | int connect_attempts; | ||
1887 | double nat_percentage; | ||
1888 | char *p_string; | ||
1843 | 1889 | ||
1890 | nat_percentage = 0.6; /* FIXME: default percentage? */ | ||
1891 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (pg->cfg, | ||
1892 | "TESTING", | ||
1893 | "PERCENTAGE", | ||
1894 | &p_string)) | ||
1895 | { | ||
1896 | if (sscanf (p_string, "%lf", &nat_percentage) != 1) | ||
1897 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1898 | _ | ||
1899 | ("Invalid value `%s' for option `%s' in section `%s': expected float\n"), | ||
1900 | p_string, "PERCENTAGE", "TESTING"); | ||
1901 | GNUNET_free (p_string); | ||
1902 | } | ||
1844 | 1903 | ||
1845 | cutoff = (unsigned int) (nat_percentage * pg->total); | 1904 | cutoff = (unsigned int) (nat_percentage * pg->total); |
1846 | |||
1847 | connect_attempts = 0; | 1905 | connect_attempts = 0; |
1848 | |||
1849 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) | 1906 | for (outer_count = 0; outer_count < pg->total - 1; outer_count++) |
1850 | { | 1907 | { |
1851 | for (inner_count = outer_count + 1; inner_count < pg->total; | 1908 | for (inner_count = outer_count + 1; inner_count < pg->total; |
@@ -1859,13 +1916,14 @@ create_nated_internet (struct GNUNET_TESTING_PeerGroup *pg, | |||
1859 | outer_count, inner_count); | 1916 | outer_count, inner_count); |
1860 | #endif | 1917 | #endif |
1861 | connect_attempts += proc (pg, outer_count, inner_count, list); | 1918 | connect_attempts += proc (pg, outer_count, inner_count, list); |
1919 | add_connections(pg, outer_count, inner_count, ALLOWED); | ||
1862 | } | 1920 | } |
1863 | } | 1921 | } |
1864 | } | 1922 | } |
1865 | 1923 | ||
1866 | return connect_attempts; | 1924 | return connect_attempts; |
1867 | |||
1868 | } | 1925 | } |
1926 | #endif | ||
1869 | 1927 | ||
1870 | /** | 1928 | /** |
1871 | * Create a topology given a peer group (set of running peers) | 1929 | * Create a topology given a peer group (set of running peers) |
@@ -2307,6 +2365,7 @@ copy_allowed (struct GNUNET_TESTING_PeerGroup *pg, | |||
2307 | return total; | 2365 | return total; |
2308 | } | 2366 | } |
2309 | 2367 | ||
2368 | |||
2310 | /** | 2369 | /** |
2311 | * Create a topology given a peer group (set of running peers) | 2370 | * Create a topology given a peer group (set of running peers) |
2312 | * and a connection processor. | 2371 | * and a connection processor. |
@@ -3681,6 +3740,9 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3681 | unsigned int num_connections; | 3740 | unsigned int num_connections; |
3682 | int unblacklisted_connections; | 3741 | int unblacklisted_connections; |
3683 | char *filename; | 3742 | char *filename; |
3743 | struct PeerConnection *conn_iter; | ||
3744 | struct PeerConnection *temp_conn; | ||
3745 | unsigned int off; | ||
3684 | 3746 | ||
3685 | #if !OLD | 3747 | #if !OLD |
3686 | unsigned int i; | 3748 | unsigned int i; |
@@ -3868,8 +3930,36 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3868 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 3930 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
3869 | _("Blacklisting all but InterNAT topology\n")); | 3931 | _("Blacklisting all but InterNAT topology\n")); |
3870 | #endif | 3932 | #endif |
3871 | unblacklisted_connections = | 3933 | |
3872 | create_nated_internet (pg, &remove_connections, BLACKLIST); | 3934 | #if TOPOLOGY_HACK |
3935 | for (off = 0; off < pg->total; off++) | ||
3936 | { | ||
3937 | conn_iter = pg->peers[off].allowed_peers_head; | ||
3938 | while (conn_iter != NULL) | ||
3939 | { | ||
3940 | temp_conn = conn_iter->next; | ||
3941 | GNUNET_free(conn_iter); | ||
3942 | conn_iter = temp_conn; | ||
3943 | } | ||
3944 | pg->peers[off].allowed_peers_head = NULL; | ||
3945 | pg->peers[off].allowed_peers_tail = NULL; | ||
3946 | |||
3947 | conn_iter = pg->peers[off].connect_peers_head; | ||
3948 | while (conn_iter != NULL) | ||
3949 | { | ||
3950 | temp_conn = conn_iter->next; | ||
3951 | GNUNET_free(conn_iter); | ||
3952 | conn_iter = temp_conn; | ||
3953 | } | ||
3954 | pg->peers[off].connect_peers_head = NULL; | ||
3955 | pg->peers[off].connect_peers_tail = NULL; | ||
3956 | } | ||
3957 | unblacklisted_connections = create_nated_internet_copy(pg, &remove_connections, BLACKLIST); | ||
3958 | #else | ||
3959 | unblacklisted_connections = | ||
3960 | create_nated_internet (pg, &remove_connections, BLACKLIST); | ||
3961 | #endif | ||
3962 | |||
3873 | break; | 3963 | break; |
3874 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: | 3964 | case GNUNET_TESTING_TOPOLOGY_SCALE_FREE: |
3875 | #if VERBOSE_TESTING | 3965 | #if VERBOSE_TESTING |