aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_group.c
diff options
context:
space:
mode:
authorNathan S. Evans <evans@in.tum.de>2010-06-28 16:41:11 +0000
committerNathan S. Evans <evans@in.tum.de>2010-06-28 16:41:11 +0000
commit9748ddd31e98f2775851c8b24a735ba67d31e87a (patch)
treefdff70d7a8c35f227b403e80aeee5290054b1591 /src/testing/testing_group.c
parentceae03698d503c88e96d18984e11079cb95a2184 (diff)
downloadgnunet-9748ddd31e98f2775851c8b24a735ba67d31e87a.tar.gz
gnunet-9748ddd31e98f2775851c8b24a735ba67d31e87a.zip
add test case for NO topology restrictions, connect in ring. good for maximum number of peers testing
Diffstat (limited to 'src/testing/testing_group.c')
-rw-r--r--src/testing/testing_group.c150
1 files changed, 120 insertions, 30 deletions
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c
index 831657305..6770cf446 100644
--- a/src/testing/testing_group.c
+++ b/src/testing/testing_group.c
@@ -31,8 +31,6 @@
31 31
32#define VERBOSE_TESTING GNUNET_NO 32#define VERBOSE_TESTING GNUNET_NO
33 33
34#define VERBOSE_TOPOLOGY GNUNET_NO
35
36#define DEBUG_CHURN GNUNET_NO 34#define DEBUG_CHURN GNUNET_NO
37 35
38/** 36/**
@@ -52,6 +50,8 @@
52 50
53#define MAX_OUTSTANDING_CONNECTIONS 50 51#define MAX_OUTSTANDING_CONNECTIONS 50
54 52
53#define MAX_CONCURRENT_HOSTKEYS 16
54
55#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) 55#define CONNECT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
56 56
57#define CONNECT_ATTEMPTS 8 57#define CONNECT_ATTEMPTS 8
@@ -318,6 +318,11 @@ struct GNUNET_TESTING_PeerGroup
318 * At what time should we fail the peer startup process? 318 * At what time should we fail the peer startup process?
319 */ 319 */
320 struct GNUNET_TIME_Absolute max_timeout; 320 struct GNUNET_TIME_Absolute max_timeout;
321
322 /**
323 * How many peers are being started right now?
324 */
325 unsigned int starting;
321}; 326};
322 327
323/** 328/**
@@ -640,10 +645,8 @@ make_config (const struct GNUNET_CONFIGURATION_Handle *cfg,
640 * @param first index of the first peer 645 * @param first index of the first peer
641 * @param second index of the second peer 646 * @param second index of the second peer
642 * 647 *
643 * @return the number of connections added (can be 0, 1 or 2) 648 * @return the number of connections added
644 * technically should only be 0 or 2, but the small price 649 * technically should only be 0 or 2
645 * of iterating over the lists (hashmaps in the future)
646 * for being sure doesn't bother me!
647 * 650 *
648 */ 651 */
649static int 652static int
@@ -2057,8 +2060,8 @@ connect_topology (struct GNUNET_TESTING_PeerGroup *pg)
2057 * by the topology. This will only have an effect once peers 2060 * by the topology. This will only have an effect once peers
2058 * are started if the FRIENDS_ONLY option is set in the base 2061 * are started if the FRIENDS_ONLY option is set in the base
2059 * config. Also takes an optional restrict topology which 2062 * config. Also takes an optional restrict topology which
2060 * disallows direct TCP connections UNLESS they are specified in 2063 * disallows connections based on a particular transport
2061 * the restricted topology. 2064 * UNLESS they are specified in the restricted topology.
2062 * 2065 *
2063 * @param pg the peer group struct representing the running peers 2066 * @param pg the peer group struct representing the running peers
2064 * @param topology which topology to connect the peers in 2067 * @param topology which topology to connect the peers in
@@ -2086,49 +2089,49 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
2086 switch (topology) 2089 switch (topology)
2087 { 2090 {
2088 case GNUNET_TESTING_TOPOLOGY_CLIQUE: 2091 case GNUNET_TESTING_TOPOLOGY_CLIQUE:
2089#if VERBOSE_TOPOLOGY 2092#if VERBOSE_TESTING
2090 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2093 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2091 _("Creating clique topology\n")); 2094 _("Creating clique topology\n"));
2092#endif 2095#endif
2093 num_connections = create_clique (pg, &add_allowed_connections); 2096 num_connections = create_clique (pg, &add_allowed_connections);
2094 break; 2097 break;
2095 case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING: 2098 case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD_RING:
2096#if VERBOSE_TOPOLOGY 2099#if VERBOSE_TESTING
2097 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2098 _("Creating small world (ring) topology\n")); 2101 _("Creating small world (ring) topology\n"));
2099#endif 2102#endif
2100 num_connections = create_small_world_ring (pg, &add_allowed_connections); 2103 num_connections = create_small_world_ring (pg, &add_allowed_connections);
2101 break; 2104 break;
2102 case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD: 2105 case GNUNET_TESTING_TOPOLOGY_SMALL_WORLD:
2103#if VERBOSE_TOPOLOGY 2106#if VERBOSE_TESTING
2104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2105 _("Creating small world (2d-torus) topology\n")); 2108 _("Creating small world (2d-torus) topology\n"));
2106#endif 2109#endif
2107 num_connections = create_small_world (pg, &add_allowed_connections); 2110 num_connections = create_small_world (pg, &add_allowed_connections);
2108 break; 2111 break;
2109 case GNUNET_TESTING_TOPOLOGY_RING: 2112 case GNUNET_TESTING_TOPOLOGY_RING:
2110#if VERBOSE_TOPOLOGY 2113#if VERBOSE_TESTING
2111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2114 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2112 _("Creating ring topology\n")); 2115 _("Creating ring topology\n"));
2113#endif 2116#endif
2114 num_connections = create_ring (pg, &add_allowed_connections); 2117 num_connections = create_ring (pg, &add_allowed_connections);
2115 break; 2118 break;
2116 case GNUNET_TESTING_TOPOLOGY_2D_TORUS: 2119 case GNUNET_TESTING_TOPOLOGY_2D_TORUS:
2117#if VERBOSE_TOPOLOGY 2120#if VERBOSE_TESTING
2118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2121 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2119 _("Creating 2d torus topology\n")); 2122 _("Creating 2d torus topology\n"));
2120#endif 2123#endif
2121 num_connections = create_2d_torus (pg, &add_allowed_connections); 2124 num_connections = create_2d_torus (pg, &add_allowed_connections);
2122 break; 2125 break;
2123 case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI: 2126 case GNUNET_TESTING_TOPOLOGY_ERDOS_RENYI:
2124#if VERBOSE_TOPOLOGY 2127#if VERBOSE_TESTING
2125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2126 _("Creating Erdos-Renyi topology\n")); 2129 _("Creating Erdos-Renyi topology\n"));
2127#endif 2130#endif
2128 num_connections = create_erdos_renyi (pg, &add_allowed_connections); 2131 num_connections = create_erdos_renyi (pg, &add_allowed_connections);
2129 break; 2132 break;
2130 case GNUNET_TESTING_TOPOLOGY_INTERNAT: 2133 case GNUNET_TESTING_TOPOLOGY_INTERNAT:
2131#if VERBOSE_TOPOLOGY 2134#if VERBOSE_TESTING
2132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2135 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2133 _("Creating InterNAT topology\n")); 2136 _("Creating InterNAT topology\n"));
2134#endif 2137#endif
@@ -2149,38 +2152,43 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
2149 num_connections = create_line (pg, &add_allowed_connections); 2152 num_connections = create_line (pg, &add_allowed_connections);
2150 break; 2153 break;
2151 case GNUNET_TESTING_TOPOLOGY_NONE: 2154 case GNUNET_TESTING_TOPOLOGY_NONE:
2155#if VERBOSE_TESTING
2156 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2157 _("Creating no allowed topology (all peers can connect at core level)\n"));
2158#endif
2152 num_connections = 0; 2159 num_connections = 0;
2153 break; 2160 break;
2154 default: 2161 default:
2155 num_connections = 0; 2162 num_connections = 0;
2156 break; 2163 break;
2157 } 2164 }
2158 if (num_connections < 1) 2165
2166 if (num_connections < 0)
2159 return GNUNET_SYSERR; 2167 return GNUNET_SYSERR;
2160 2168
2161 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "F2F")) 2169 if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno (pg->cfg, "TESTING", "F2F"))
2162 { 2170 {
2163 ret = create_and_copy_friend_files(pg); 2171 ret = create_and_copy_friend_files(pg);
2164 } 2172 if (ret != GNUNET_OK)
2165 2173 {
2166 if (ret != GNUNET_OK)
2167 {
2168#if VERBOSE_TESTING 2174#if VERBOSE_TESTING
2169 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2170 _("Failed during friend file copying!\n")); 2176 _("Failed during friend file copying!\n"));
2171#endif 2177#endif
2172 return GNUNET_SYSERR; 2178 return GNUNET_SYSERR;
2173 } 2179 }
2174 else 2180 else
2175 { 2181 {
2176#if VERBOSE_TESTING 2182#if VERBOSE_TESTING
2177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2178 _("Friend files created/copied successfully!\n")); 2184 _("Friend files created/copied successfully!\n"));
2179#endif 2185#endif
2186 }
2180 } 2187 }
2181 2188
2182 /* Use the create clique method to initially set all connections as blacklisted. */ 2189 /* Use the create clique method to initially set all connections as blacklisted. */
2183 create_clique (pg, &blacklist_connections); 2190 if (restrict_topology != GNUNET_TESTING_TOPOLOGY_NONE)
2191 create_clique (pg, &blacklist_connections);
2184 unblacklisted_connections = 0; 2192 unblacklisted_connections = 0;
2185 /* Un-blacklist connections as per the topology specified */ 2193 /* Un-blacklist connections as per the topology specified */
2186 switch (restrict_topology) 2194 switch (restrict_topology)
@@ -2249,7 +2257,10 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg,
2249 unblacklisted_connections = create_line (pg, &unblacklist_connections); 2257 unblacklisted_connections = create_line (pg, &unblacklist_connections);
2250 break; 2258 break;
2251 case GNUNET_TESTING_TOPOLOGY_NONE: 2259 case GNUNET_TESTING_TOPOLOGY_NONE:
2252 /* Fall through */ 2260#if VERBOSE_TESTING
2261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2262 _("Creating no blacklist topology (all peers can connect at transport level)\n"));
2263#endif
2253 default: 2264 default:
2254 break; 2265 break;
2255 } 2266 }
@@ -2798,6 +2809,69 @@ GNUNET_TESTING_daemons_continue_startup(struct GNUNET_TESTING_PeerGroup *pg)
2798 } 2809 }
2799} 2810}
2800 2811
2812struct InternalStartContext
2813{
2814 struct PeerData *peer;
2815 struct GNUNET_SCHEDULER_Handle *sched;
2816 const struct GNUNET_CONFIGURATION_Handle *pcfg;
2817 struct GNUNET_TIME_Relative timeout;
2818 GNUNET_TESTING_NotifyHostkeyCreated hostkey_callback;
2819 void *hostkey_cls;
2820 GNUNET_TESTING_NotifyDaemonRunning cb;
2821 void *cb_cls;
2822 const char *hostname;
2823};
2824
2825
2826/**
2827 * Prototype of a function that will be called whenever
2828 * a daemon was started by the testing library.
2829 *
2830 * @param cls closure
2831 * @param id identifier for the daemon, NULL on error
2832 * @param d handle for the daemon
2833 * @param emsg error message (NULL on success)
2834 */
2835static void internal_hostkey_callback (void *cls,
2836 const struct GNUNET_PeerIdentity *id,
2837 struct GNUNET_TESTING_Daemon *d,
2838 const char *emsg)
2839{
2840 struct InternalStartContext *internal_context = cls;
2841 internal_context->peer->pg->starting--;
2842 internal_context->hostkey_callback(internal_context->hostkey_cls, id, d, emsg);
2843 GNUNET_free(internal_context);
2844}
2845
2846static void
2847internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
2848{
2849 struct InternalStartContext *internal_context = cls;
2850
2851 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
2852 {
2853 GNUNET_free(internal_context);
2854 return;
2855 }
2856
2857 if (internal_context->peer->pg->starting < MAX_CONCURRENT_HOSTKEYS)
2858 {
2859 internal_context->peer->pg->starting++;
2860 internal_context->peer->daemon = GNUNET_TESTING_daemon_start (internal_context->sched,
2861 internal_context->pcfg,
2862 internal_context->timeout,
2863 internal_context->hostname,
2864 &internal_hostkey_callback,
2865 internal_context,
2866 internal_context->cb,
2867 internal_context->cb_cls);
2868 }
2869 else
2870 {
2871 GNUNET_SCHEDULER_add_delayed(internal_context->sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 100), &internal_start, internal_context);
2872 }
2873}
2874
2801/** 2875/**
2802 * Start count gnunetd processes with the same set of transports and 2876 * Start count gnunetd processes with the same set of transports and
2803 * applications. The port numbers (any option called "PORT") will be 2877 * applications. The port numbers (any option called "PORT") will be
@@ -2842,6 +2916,7 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
2842 char *baseservicehome; 2916 char *baseservicehome;
2843 char *newservicehome; 2917 char *newservicehome;
2844 char *tmpdir; 2918 char *tmpdir;
2919 struct InternalStartContext *internal_context;
2845 struct GNUNET_CONFIGURATION_Handle *pcfg; 2920 struct GNUNET_CONFIGURATION_Handle *pcfg;
2846 unsigned int off; 2921 unsigned int off;
2847 unsigned int hostcnt; 2922 unsigned int hostcnt;
@@ -2968,6 +3043,20 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
2968 pg->peers[off].connect_peers = GNUNET_CONTAINER_multihashmap_create(total); 3043 pg->peers[off].connect_peers = GNUNET_CONTAINER_multihashmap_create(total);
2969 pg->peers[off].blacklisted_peers = GNUNET_CONTAINER_multihashmap_create(total); 3044 pg->peers[off].blacklisted_peers = GNUNET_CONTAINER_multihashmap_create(total);
2970 pg->peers[off].pg = pg; 3045 pg->peers[off].pg = pg;
3046 internal_context = GNUNET_malloc(sizeof(struct InternalStartContext));
3047 internal_context->sched = sched;
3048 internal_context->peer = &pg->peers[off];
3049 internal_context->pcfg = pcfg;
3050 internal_context->timeout = timeout;
3051 internal_context->hostname = hostname;
3052 internal_context->hostkey_callback = hostkey_callback;
3053 internal_context->hostkey_cls = hostkey_cls;
3054 internal_context->cb = cb;
3055 internal_context->cb_cls = cb_cls;
3056
3057 GNUNET_SCHEDULER_add_now (sched, &internal_start, internal_context);
3058
3059 /*
2971 pg->peers[off].daemon = GNUNET_TESTING_daemon_start (sched, 3060 pg->peers[off].daemon = GNUNET_TESTING_daemon_start (sched,
2972 pcfg, 3061 pcfg,
2973 timeout, 3062 timeout,
@@ -2978,6 +3067,7 @@ GNUNET_TESTING_daemons_start (struct GNUNET_SCHEDULER_Handle *sched,
2978 if (NULL == pg->peers[off].daemon) 3067 if (NULL == pg->peers[off].daemon)
2979 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 3068 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2980 _("Could not start peer number %u!\n"), off); 3069 _("Could not start peer number %u!\n"), off);
3070 */
2981 3071
2982 } 3072 }
2983 return pg; 3073 return pg;