aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-06 12:42:48 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-06 12:42:48 +0000
commit34206679446e053b674a4fbdaabdd8c463ad70e2 (patch)
treed283489042217798e92bb0168c4c7399f16a5c71 /src
parent0dcfafed3117b1759f1d4ab3cb5db11952e65061 (diff)
downloadgnunet-34206679446e053b674a4fbdaabdd8c463ad70e2.tar.gz
gnunet-34206679446e053b674a4fbdaabdd8c463ad70e2.zip
-fix ril delete address handling
Diffstat (limited to 'src')
-rw-r--r--src/ats/plugin_ats_ril.c20
-rw-r--r--src/ats/test_ats_solver_preferences.c99
2 files changed, 45 insertions, 74 deletions
diff --git a/src/ats/plugin_ats_ril.c b/src/ats/plugin_ats_ril.c
index 73bb8d27d..6be8ef4f6 100644
--- a/src/ats/plugin_ats_ril.c
+++ b/src/ats/plugin_ats_ril.c
@@ -819,7 +819,9 @@ envi_set_active_suggestion (struct GAS_RIL_Handle *solver,
819{ 819{
820 int notify = GNUNET_NO; 820 int notify = GNUNET_NO;
821 821
822 LOG(GNUNET_ERROR_TYPE_DEBUG, " set_active_suggestion() for peer '%s'\n", GNUNET_i2s (&agent->peer)); 822 LOG(GNUNET_ERROR_TYPE_DEBUG,
823 " set_active_suggestion() for peer '%s'\n",
824 GNUNET_i2s (&agent->peer));
823 825
824 //address change 826 //address change
825 if (agent->address_inuse != new_address) 827 if (agent->address_inuse != new_address)
@@ -2303,21 +2305,17 @@ GAS_ril_address_delete (void *solver,
2303 agent->addresses_tail, 2305 agent->addresses_tail,
2304 address_wrapped); 2306 address_wrapped);
2305 GNUNET_free (address_wrapped); 2307 GNUNET_free (address_wrapped);
2308 address_was_used = GNUNET_NO;
2306 if (agent->suggestion_address == address) 2309 if (agent->suggestion_address == address)
2307 { 2310 {
2308 agent->suggestion_address = NULL;
2309 agent->suggestion_issue = GNUNET_NO; 2311 agent->suggestion_issue = GNUNET_NO;
2310 address_was_used = GNUNET_YES; 2312 agent->suggestion_address = NULL;
2311 } 2313 }
2312 else if (agent->address_inuse == address) 2314 if (agent->address_inuse == address)
2313 { 2315 {
2314 agent->address_inuse = NULL;
2315 address_was_used = GNUNET_YES; 2316 address_was_used = GNUNET_YES;
2316 } 2317 }
2317 else 2318
2318 {
2319 address_was_used = GNUNET_NO;
2320 }
2321 2319
2322 //decrease W 2320 //decrease W
2323 m_new = agent->m - ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1)); 2321 m_new = agent->m - ((s->parameters.rbf_divisor+1) * (s->parameters.rbf_divisor+1));
@@ -2358,6 +2356,8 @@ GAS_ril_address_delete (void *solver,
2358 { 2356 {
2359 if (NULL != agent->addresses_head) //if peer has an address left, use it 2357 if (NULL != agent->addresses_head) //if peer has an address left, use it
2360 { 2358 {
2359 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2360 "Active address died, suggesting alternative!\n");
2361 envi_set_active_suggestion (s, 2361 envi_set_active_suggestion (s,
2362 agent, 2362 agent,
2363 agent->addresses_head->address_naked, 2363 agent->addresses_head->address_naked,
@@ -2367,6 +2367,8 @@ GAS_ril_address_delete (void *solver,
2367 } 2367 }
2368 else 2368 else
2369 { 2369 {
2370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2371 "Active address died, suggesting disconnect!\n");
2370 envi_set_active_suggestion (s, agent, NULL, 0, 0, GNUNET_NO); 2372 envi_set_active_suggestion (s, agent, NULL, 0, 0, GNUNET_NO);
2371 } 2373 }
2372 } 2374 }
diff --git a/src/ats/test_ats_solver_preferences.c b/src/ats/test_ats_solver_preferences.c
index aa2c438a2..0cf5be870 100644
--- a/src/ats/test_ats_solver_preferences.c
+++ b/src/ats/test_ats_solver_preferences.c
@@ -1,10 +1,4 @@
1/* 1/*
2 if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, &ats_perf_cb, NULL)))
3 {
4 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
5 "Failed to connect to performance API\n");
6 GNUNET_SCHEDULER_add_now (end_badly, NULL);
7 }
8 This file is part of GNUnet. 2 This file is part of GNUnet.
9 (C) 2010-2013 Christian Grothoff (and other contributing authors) 3 (C) 2010-2013 Christian Grothoff (and other contributing authors)
10 4
@@ -28,6 +22,10 @@
28 * @brief solver test: preference client handling 22 * @brief solver test: preference client handling
29 * @author Christian Grothoff 23 * @author Christian Grothoff
30 * @author Matthias Wachs 24 * @author Matthias Wachs
25 *
26 * FIXME: This test merely calls some of the API
27 * functions, it fails to check that
28 * preferences actually achieve anything.
31 */ 29 */
32#include "platform.h" 30#include "platform.h"
33#include "gnunet_util_lib.h" 31#include "gnunet_util_lib.h"
@@ -41,9 +39,9 @@
41static struct GNUNET_SCHEDULER_Task * die_task; 39static struct GNUNET_SCHEDULER_Task * die_task;
42 40
43/** 41/**
44 * Statistics handle 42 * Task to terminate the test
45 */ 43 */
46static struct GNUNET_STATISTICS_Handle *stats; 44static struct GNUNET_SCHEDULER_Task *end_task;
47 45
48/** 46/**
49 * Scheduling handle 47 * Scheduling handle
@@ -96,16 +94,17 @@ static struct GNUNET_ATS_Information test_ats_info[3];
96static uint32_t test_ats_count; 94static uint32_t test_ats_count;
97 95
98 96
99static int
100stat_cb (void *cls, const char *subsystem, const char *name, uint64_t value,
101 int is_persistent);
102
103
104static void 97static void
105end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 98end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
106{ 99{
107 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Done!\n"); 100 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Done!\n");
108 101
102 if (perf_ats != NULL)
103 {
104 GNUNET_ATS_performance_done (perf_ats);
105 perf_ats = NULL;
106 }
107
109 if (die_task != NULL ) 108 if (die_task != NULL )
110 { 109 {
111 GNUNET_SCHEDULER_cancel (die_task); 110 GNUNET_SCHEDULER_cancel (die_task);
@@ -127,16 +126,7 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
127 GNUNET_ATS_performance_done (perf_ats); 126 GNUNET_ATS_performance_done (perf_ats);
128 perf_ats = NULL; 127 perf_ats = NULL;
129 } 128 }
130
131 GNUNET_STATISTICS_watch_cancel (stats, "ats", "# active performance clients", &stat_cb, NULL );
132 if (NULL != stats)
133 {
134 GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
135 stats = NULL;
136 }
137
138 free_test_address (&test_addr); 129 free_test_address (&test_addr);
139
140 ret = 0; 130 ret = 0;
141} 131}
142 132
@@ -152,16 +142,16 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
152 142
153static void 143static void
154perf_info_cb (void *cls, 144perf_info_cb (void *cls,
155 const struct GNUNET_HELLO_Address *address, int address_active, 145 const struct GNUNET_HELLO_Address *address, int address_active,
156 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 146 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
157 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 147 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
158 const struct GNUNET_ATS_Information *ats, uint32_t ats_count) 148 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
159{ 149{
160 if (NULL == address) 150 if (NULL == address)
161 return; 151 return;
162 152 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
163 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "ATS performance info: `%s'\n", 153 "ATS performance info: `%s'\n",
164 GNUNET_i2s (&address->peer)); 154 GNUNET_i2s (&address->peer));
165} 155}
166 156
167 157
@@ -175,54 +165,31 @@ address_suggest_cb (void *cls,
175{ 165{
176 int c; 166 int c;
177 double pref_val; 167 double pref_val;
168
178 if (NULL == perf_ats) 169 if (NULL == perf_ats)
179 return; 170 return;
180 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++) 171 for (c = 1; c < GNUNET_ATS_PreferenceCount; c++)
181 { 172 {
182 pref_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10); 173 pref_val = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 10);
183 GNUNET_ATS_performance_change_preference (perf_ats, 174 GNUNET_ATS_performance_change_preference (perf_ats,
184 &test_hello_address.peer, GNUNET_ATS_PREFERENCE_LATENCY, pref_val, 175 &test_hello_address.peer,
185 GNUNET_ATS_PREFERENCE_END); 176 GNUNET_ATS_PREFERENCE_LATENCY, pref_val,
186 } 177 GNUNET_ATS_PREFERENCE_END);
187}
188
189
190static int
191stat_cb (void *cls, const char *subsystem, const char *name, uint64_t value,
192 int is_persistent)
193{
194 static int last_value = 0;
195 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n",
196 subsystem, name, value);
197
198 if ((0 == last_value) && (1 == value))
199 {
200 if (perf_ats != NULL)
201 {
202 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Disconnecting performance client\n");
203 GNUNET_ATS_performance_done(perf_ats);
204 perf_ats = NULL;
205 }
206 }
207 if ((1 == last_value) && (0 == value))
208 {
209 GNUNET_SCHEDULER_add_now (&end, NULL);
210 } 178 }
211 last_value = value; 179 if (NULL == end_task)
180 end_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
181 &end, NULL);
212 182
213 return GNUNET_OK;
214} 183}
215 184
216 185
186
217static void 187static void
218run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, 188run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg,
219 struct GNUNET_TESTING_Peer *peer) 189 struct GNUNET_TESTING_Peer *peer)
220{ 190{
221 191
222 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL ); 192 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL );
223 stats = GNUNET_STATISTICS_create ("ats", mycfg);
224 GNUNET_STATISTICS_watch (stats, "ats", "# active performance clients", &stat_cb, NULL );
225
226 connect_ats = GNUNET_ATS_connectivity_init (mycfg); 193 connect_ats = GNUNET_ATS_connectivity_init (mycfg);
227 194
228 /* Connect to ATS scheduling */ 195 /* Connect to ATS scheduling */
@@ -235,11 +202,11 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg,
235 return; 202 return;
236 } 203 }
237 204
238 perf_ats = GNUNET_ATS_performance_init (mycfg, &perf_info_cb, NULL ); 205 perf_ats = GNUNET_ATS_performance_init (mycfg, &perf_info_cb, NULL);
239 if (perf_ats == NULL ) 206 if (perf_ats == NULL)
240 { 207 {
241 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 208 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
242 "Could not connect to ATS performance!\n"); 209 "Could not connect to ATS performance!\n");
243 GNUNET_SCHEDULER_add_now (&end_badly, NULL ); 210 GNUNET_SCHEDULER_add_now (&end_badly, NULL );
244 return; 211 return;
245 } 212 }
@@ -247,8 +214,9 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg,
247 /* Set up peer */ 214 /* Set up peer */
248 memset (&p.id, '1', sizeof(p.id)); 215 memset (&p.id, '1', sizeof(p.id));
249 216
250 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", 217 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
251 GNUNET_i2s_full (&p.id)); 218 "Created peer `%s'\n",
219 GNUNET_i2s_full (&p.id));
252 220
253 /* Prepare ATS Information */ 221 /* Prepare ATS Information */
254 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); 222 test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
@@ -261,8 +229,9 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg,
261 229
262 /* Adding address without session */ 230 /* Adding address without session */
263 test_session = NULL; 231 test_session = NULL;
264 create_test_address (&test_addr, "test", test_session, "test", 232 create_test_address (&test_addr, "test",
265 strlen ("test") + 1); 233 test_session, "test",
234 strlen ("test") + 1);
266 test_hello_address.peer = p.id; 235 test_hello_address.peer = p.id;
267 test_hello_address.transport_name = test_addr.plugin; 236 test_hello_address.transport_name = test_addr.plugin;
268 test_hello_address.address = test_addr.addr; 237 test_hello_address.address = test_addr.addr;