aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2011-07-18 08:19:35 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2011-07-18 08:19:35 +0000
commit537451fc9e5411e1ccfc0a9673624b623c6231ed (patch)
tree6caeb1fe4129370394575634ed8293d82654a49d /src
parentb245a60021ef93b0157f6445aa152e808763a145 (diff)
downloadgnunet-537451fc9e5411e1ccfc0a9673624b623c6231ed.tar.gz
gnunet-537451fc9e5411e1ccfc0a9673624b623c6231ed.zip
preliminary commit to prevent more conflicts
Diffstat (limited to 'src')
-rw-r--r--src/transport/test_transport_ats.c160
1 files changed, 128 insertions, 32 deletions
diff --git a/src/transport/test_transport_ats.c b/src/transport/test_transport_ats.c
index 3da824c47..b7e8153d9 100644
--- a/src/transport/test_transport_ats.c
+++ b/src/transport/test_transport_ats.c
@@ -22,49 +22,89 @@
22 * @brief testcase for ats functionality without starting peers 22 * @brief testcase for ats functionality without starting peers
23 */ 23 */
24#include "platform.h" 24#include "platform.h"
25#include "transport_ats.h" 25#include "gnunet_transport_ats.h"
26#include "gnunet_configuration_lib.h" 26#include "gnunet_configuration_lib.h"
27#include "gnunet_crypto_lib.h"
27 28
28#define VERBOSE GNUNET_YES 29#define VERBOSE GNUNET_YES
29 30
30#if HAVE_LIBGLPK
31
32struct GNUNET_CONFIGURATION_Handle *cfg;
33
34static struct ATS_Handle * ats; 31static struct ATS_Handle * ats;
32static struct GNUNET_CONFIGURATION_Handle * cfg;
35 33
36static void 34void ats_result_cb ()
37ats_result_cb ()
38{ 35{
39 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 36 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
40 "ATS Result callback\n"); 37 "ATS Result callback\n");
41} 38}
42 39
40struct TransportConfiguration
41{
42 int peers;
43 int mechanisms;
44
45 struct ATS_peer * p_head;
46 struct ATS_peer * p_tail;
47
48 struct ATS_mechanism * m_head;
49 struct ATS_mechanism * m_tail;
50};
51
52struct TransportConfiguration *tc;
53
54/*
55void create_topology (int c_peers, int c_mechanisms)
56{
57 int c;
58 peers = GNUNET_malloc ( c_peers * sizeof (struct ATS_peer));
59 for (c=0 ; c<c_peers; c++)
60 {
61 peers[c].f = 1.0 / c_peers;
62 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK, &peers[c].peer.hashPubKey);
63 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer %s \n", GNUNET_i2s (&peers[c].peer));
64 peers[c].m_head = NULL;
65 peers[c].m_tail = NULL;
66 }
67 mechanisms = GNUNET_malloc ( c_mechanisms * sizeof (struct ATS_mechanism));
68 for (c=0 ; c<c_mechanisms; c++)
69 {
70 mechanisms[c].peer = &peers[c];
71 }
72}
73
43 74
44static void 75void delete_topology (void)
45create_ats_information (struct ATS_peer **p, int * c_p,
46 struct ATS_mechanism ** m, int * c_m)
47{ 76{
77 GNUNET_free (peers);
78 GNUNET_free (mechanisms);
79}*/
80
81
82void create_ats_information (struct ATS_peer **p, int * c_p,
83 struct ATS_mechanism ** m, int * c_m)
84{
85
48 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 86 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
49 "ATS needs addresses\n"); 87 "ATS needs addresses\n");
50 (*c_m) = 100; 88
51 (*c_p) = 10; 89 (*p) = tc->p_head;
90 (*c_p) = tc->mechanisms;
91 (*m) = tc->m_head;
92 (*c_m) = tc->mechanisms;
93
52} 94}
53 95
54static int 96int run_ats (void)
55run_ats ()
56{ 97{
57 int ret = 0; 98 int ret = 0;
58 99
59 ats_calculate_bandwidth_distribution(ats, NULL); 100 ats_calculate_bandwidth_distribution(ats, NULL);
60 101
61 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 102 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
62 "Running ATS: %s \n", (ret==0)? "SUCCESFULL": "FAILED"); 103 "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
63 return ret; 104 return ret;
64} 105}
65 106
66static int 107int init_ats (void)
67init_ats ()
68{ 108{
69 int ret = 0; 109 int ret = 0;
70 110
@@ -74,26 +114,24 @@ init_ats ()
74 //GNUNET_assert (ats != NULL); 114 //GNUNET_assert (ats != NULL);
75 115
76 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
77 "Initializing ATS: %s \n", (ret==0)? "SUCCESFULL": "FAILED"); 117 "Initializing ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
78 return ret; 118 return ret;
79} 119}
80 120
81 121
82static int 122int shutdown_ats (void)
83shutdown_ats ()
84{ 123{
85 int ret = 0; 124 int ret = 0;
86 125
87 //ats_delete_problem (ats); 126 ats_delete_problem (ats);
88 //ats_shutdown (ats); 127 ats_shutdown (ats);
89 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 128 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
90 "Shutdown ATS: %s \n", (ret==0)? "SUCCESFULL": "FAILED"); 129 "Shutdown ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED");
91 return ret; 130 return ret;
92} 131}
93 132
94/* To make compiler happy */ 133/* To make compiler happy */
95static void 134void dummy(void)
96dummy()
97{ 135{
98 struct ATS_quality_metric * q = qm; 136 struct ATS_quality_metric * q = qm;
99 q = NULL; 137 q = NULL;
@@ -101,7 +139,63 @@ dummy()
101 r = NULL; 139 r = NULL;
102} 140}
103 141
104#endif 142void iterate_peer_values (void *cls,
143 const char *section,
144 const char *option,
145 const char *value)
146{
147 if (strcmp (option, "f") == 0)
148 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
149 "\t %s %s\n", option, value);
150}
151
152void iterate_mech_values (void *cls,
153 const char *section,
154 const char *option,
155 const char *value)
156{
157 if (strcmp (option, "f") == 0)
158 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
159 "\t %s %s\n", option, value);
160}
161
162void iterate_sections (void *cls,
163 const char *section)
164{
165 struct TransportConfiguration * tc = cls;
166 /* Peer definition */
167 if (99 == strlen(section))
168 {
169 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section);
170 GNUNET_HashCode h;
171 int res =GNUNET_CRYPTO_hash_from_string(section, &h);
172 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HASH '%s` %i\n", GNUNET_h2s (&h), res);
173 GNUNET_CONFIGURATION_iterate_section_values(cfg, section, iterate_peer_values, NULL);
174 tc->peers++;
175 }
176 if (10 == strlen(section))
177 {
178 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n",section);
179 GNUNET_CONFIGURATION_iterate_section_values(cfg, section, iterate_mech_values, NULL);
180 tc->peers++;
181 }
182}
183
184void destroy_transport_configuration (char * filename)
185{
186 GNUNET_CONFIGURATION_destroy (cfg);
187
188}
189
190struct TransportConfiguration * load_transport_configuration (char * filename)
191{
192 struct TransportConfiguration * ret = GNUNET_malloc(sizeof (struct TransportConfiguration));
193 cfg = GNUNET_CONFIGURATION_create();
194 GNUNET_CONFIGURATION_load(cfg, filename);
195 GNUNET_CONFIGURATION_iterate_sections(cfg, iterate_sections, ret);
196
197 return ret;
198}
105 199
106int 200int
107main (int argc, char *argv[]) 201main (int argc, char *argv[])
@@ -116,28 +210,30 @@ main (int argc, char *argv[])
116#endif 210#endif
117 NULL); 211 NULL);
118#if !HAVE_LIBGLPK 212#if !HAVE_LIBGLPK
119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 213 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
120 "HAVE_LIBGLPK not set, exiting testcase\n"); 214 "HAVE_LIBGLPK not set, exiting testcase\n");
121#endif 215#endif
122 216
123#if !HAVE_LIBGLPK 217#if !HAVE_LIBGLPK
124 return ret; 218 return ret;
125#else 219#endif
126 220
221 return 0;
127 222
128 cfg = GNUNET_CONFIGURATION_create(); 223 tc = load_transport_configuration ("test.ats");
129 GNUNET_CONFIGURATION_load(cfg, "test_transport_ats_1addr.conf"); 224
225 return ret;
130 226
131 /* Testing */ 227 /* Testing */
132 ats = NULL; 228 ats = NULL;
229
133 ret += init_ats (); 230 ret += init_ats ();
134 ret += run_ats (); 231 ret += run_ats ();
135 ret += shutdown_ats (); 232 ret += shutdown_ats ();
136 233
137 /* Shutdown */ 234 /* Shutdown */
138 GNUNET_CONFIGURATION_destroy(cfg);
139 return ret; 235 return ret;
140#endif 236
141} 237}
142 238
143/* end of test_transport_ats.c*/ 239/* end of test_transport_ats.c*/