diff options
Diffstat (limited to 'src/transport/test_transport_ats.c')
-rw-r--r-- | src/transport/test_transport_ats.c | 137 |
1 files changed, 68 insertions, 69 deletions
diff --git a/src/transport/test_transport_ats.c b/src/transport/test_transport_ats.c index bf7bc0fe5..d9e4b23d5 100644 --- a/src/transport/test_transport_ats.c +++ b/src/transport/test_transport_ats.c | |||
@@ -28,18 +28,17 @@ | |||
28 | 28 | ||
29 | #define VERBOSE GNUNET_YES | 29 | #define VERBOSE GNUNET_YES |
30 | 30 | ||
31 | static struct ATS_Handle * ats; | 31 | static struct ATS_Handle *ats; |
32 | 32 | ||
33 | static struct GNUNET_CONFIGURATION_Handle * cfg; | 33 | static struct GNUNET_CONFIGURATION_Handle *cfg; |
34 | 34 | ||
35 | static struct TransportConfiguration *tc; | 35 | static struct TransportConfiguration *tc; |
36 | 36 | ||
37 | 37 | ||
38 | static void | 38 | static void |
39 | ats_result_cb () | 39 | ats_result_cb () |
40 | { | 40 | { |
41 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 41 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS Result callback\n"); |
42 | "ATS Result callback\n"); | ||
43 | } | 42 | } |
44 | 43 | ||
45 | struct TransportConfiguration | 44 | struct TransportConfiguration |
@@ -47,35 +46,35 @@ struct TransportConfiguration | |||
47 | int peers; | 46 | int peers; |
48 | int mechanisms; | 47 | int mechanisms; |
49 | 48 | ||
50 | struct ATS_peer * p_head; | 49 | struct ATS_peer *p_head; |
51 | struct ATS_peer * p_tail; | 50 | struct ATS_peer *p_tail; |
52 | 51 | ||
53 | struct ATS_mechanism * m_head; | 52 | struct ATS_mechanism *m_head; |
54 | struct ATS_mechanism * m_tail; | 53 | struct ATS_mechanism *m_tail; |
55 | }; | 54 | }; |
56 | 55 | ||
57 | 56 | ||
58 | static void | 57 | static void |
59 | create_ats_information (struct ATS_peer **p, int * c_p, | 58 | create_ats_information (struct ATS_peer **p, int *c_p, |
60 | struct ATS_mechanism ** m, int * c_m) | 59 | struct ATS_mechanism **m, int *c_m) |
61 | { | 60 | { |
62 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 61 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS needs addresses\n"); |
63 | "ATS needs addresses\n"); | ||
64 | 62 | ||
65 | (*p) = tc->p_head; | 63 | (*p) = tc->p_head; |
66 | (*c_p) = tc->mechanisms; | 64 | (*c_p) = tc->mechanisms; |
67 | (*m) = tc->m_head; | 65 | (*m) = tc->m_head; |
68 | (*c_m) = tc->mechanisms; | 66 | (*c_m) = tc->mechanisms; |
69 | } | 67 | } |
70 | 68 | ||
71 | 69 | ||
72 | static | 70 | static int |
73 | int run_ats () | 71 | run_ats () |
74 | { | 72 | { |
75 | int ret = 0; | 73 | int ret = 0; |
74 | |||
76 | ats_calculate_bandwidth_distribution (ats); | 75 | ats_calculate_bandwidth_distribution (ats); |
77 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 76 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
78 | "Running ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED"); | 77 | "Running ATS: %s \n", (ret == 0) ? "SUCCESSFUL" : "FAILED"); |
79 | return ret; | 78 | return ret; |
80 | } | 79 | } |
81 | 80 | ||
@@ -84,96 +83,96 @@ static int | |||
84 | init_ats () | 83 | init_ats () |
85 | { | 84 | { |
86 | int ret = 0; | 85 | int ret = 0; |
87 | ats = ats_init(1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION, | 86 | |
88 | create_ats_information, | 87 | ats = ats_init (1.0, 1.0, 1.0, 50000, 5, 10, ATS_MAX_EXEC_DURATION, |
89 | ats_result_cb); | 88 | create_ats_information, ats_result_cb); |
90 | //GNUNET_assert (ats != NULL); | 89 | //GNUNET_assert (ats != NULL); |
91 | 90 | ||
92 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 91 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
93 | "Initializing ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED"); | 92 | "Initializing ATS: %s \n", (ret == 0) ? "SUCCESSFUL" : "FAILED"); |
94 | return ret; | 93 | return ret; |
95 | } | 94 | } |
96 | 95 | ||
97 | 96 | ||
98 | static int | 97 | static int |
99 | shutdown_ats () | 98 | shutdown_ats () |
100 | { | 99 | { |
101 | int ret = 0; | 100 | int ret = 0; |
101 | |||
102 | ats_delete_problem (ats); | 102 | ats_delete_problem (ats); |
103 | ats_shutdown (ats); | 103 | ats_shutdown (ats); |
104 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 104 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
105 | "Shutdown ATS: %s \n", (ret==0)? "SUCCESSFUL": "FAILED"); | 105 | "Shutdown ATS: %s \n", (ret == 0) ? "SUCCESSFUL" : "FAILED"); |
106 | return ret; | 106 | return ret; |
107 | } | 107 | } |
108 | 108 | ||
109 | 109 | ||
110 | /* To make compiler happy */ | 110 | /* To make compiler happy */ |
111 | void | 111 | void |
112 | dummy() | 112 | dummy () |
113 | { | 113 | { |
114 | struct ATS_quality_metric * q = qm; | 114 | struct ATS_quality_metric *q = qm; |
115 | |||
115 | q = NULL; | 116 | q = NULL; |
116 | struct ATS_ressource * r = ressources; | 117 | struct ATS_ressource *r = ressources; |
118 | |||
117 | r = NULL; | 119 | r = NULL; |
118 | q++; | 120 | q++; |
119 | r++; | 121 | r++; |
120 | } | 122 | } |
121 | 123 | ||
122 | 124 | ||
123 | static void | 125 | static void |
124 | iterate_peer_values (void *cls, | 126 | iterate_peer_values (void *cls, |
125 | const char *section, | 127 | const char *section, const char *option, const char *value) |
126 | const char *option, | ||
127 | const char *value) | ||
128 | { | 128 | { |
129 | if (strcmp (option, "f") == 0) | 129 | if (strcmp (option, "f") == 0) |
130 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 130 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value); |
131 | "\t %s %s\n", option, value); | ||
132 | } | 131 | } |
133 | 132 | ||
134 | static void | 133 | static void |
135 | iterate_mech_values (void *cls, | 134 | iterate_mech_values (void *cls, |
136 | const char *section, | 135 | const char *section, const char *option, const char *value) |
137 | const char *option, | ||
138 | const char *value) | ||
139 | { | 136 | { |
140 | if (strcmp (option, "f") == 0) | 137 | if (strcmp (option, "f") == 0) |
141 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "\t %s %s\n", option, value); |
142 | "\t %s %s\n", option, value); | ||
143 | } | 139 | } |
144 | 140 | ||
145 | static void | 141 | static void |
146 | iterate_sections (void *cls, | 142 | iterate_sections (void *cls, const char *section) |
147 | const char *section) | ||
148 | { | 143 | { |
149 | struct TransportConfiguration * tc = cls; | 144 | struct TransportConfiguration *tc = cls; |
145 | |||
150 | /* Peer definition */ | 146 | /* Peer definition */ |
151 | if (99 == strlen(section)) | 147 | if (99 == strlen (section)) |
152 | { | 148 | { |
153 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section); | 149 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Peer '%s`\n", section); |
154 | GNUNET_HashCode h; | 150 | GNUNET_HashCode h; |
155 | int res =GNUNET_CRYPTO_hash_from_string(section, &h); | 151 | int res = GNUNET_CRYPTO_hash_from_string (section, &h); |
156 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HASH '%s` %i\n", GNUNET_h2s (&h), res); | 152 | |
157 | GNUNET_CONFIGURATION_iterate_section_values(cfg, section, iterate_peer_values, NULL); | 153 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "HASH '%s` %i\n", GNUNET_h2s (&h), res); |
158 | tc->peers++; | 154 | GNUNET_CONFIGURATION_iterate_section_values (cfg, section, |
159 | } | 155 | iterate_peer_values, NULL); |
160 | if (10 == strlen(section)) | 156 | tc->peers++; |
161 | { | 157 | } |
162 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n",section); | 158 | if (10 == strlen (section)) |
163 | GNUNET_CONFIGURATION_iterate_section_values(cfg, section, iterate_mech_values, NULL); | 159 | { |
164 | tc->peers++; | 160 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Mechanism '%s`\n", section); |
165 | } | 161 | GNUNET_CONFIGURATION_iterate_section_values (cfg, section, |
162 | iterate_mech_values, NULL); | ||
163 | tc->peers++; | ||
164 | } | ||
166 | } | 165 | } |
167 | 166 | ||
168 | 167 | ||
169 | static struct TransportConfiguration * | 168 | static struct TransportConfiguration * |
170 | load_transport_configuration (char * filename) | 169 | load_transport_configuration (char *filename) |
171 | { | 170 | { |
172 | struct TransportConfiguration * ret = GNUNET_malloc(sizeof (struct TransportConfiguration)); | 171 | struct TransportConfiguration *ret = |
172 | GNUNET_malloc (sizeof (struct TransportConfiguration)); | ||
173 | 173 | ||
174 | cfg = GNUNET_CONFIGURATION_create(); | 174 | cfg = GNUNET_CONFIGURATION_create (); |
175 | GNUNET_assert (GNUNET_OK == | 175 | GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (cfg, filename)); |
176 | GNUNET_CONFIGURATION_load(cfg, filename)); | ||
177 | GNUNET_CONFIGURATION_iterate_sections (cfg, iterate_sections, ret); | 176 | GNUNET_CONFIGURATION_iterate_sections (cfg, iterate_sections, ret); |
178 | GNUNET_CONFIGURATION_destroy (cfg); | 177 | GNUNET_CONFIGURATION_destroy (cfg); |
179 | cfg = NULL; | 178 | cfg = NULL; |