diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-19 01:08:03 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-19 01:08:03 +0000 |
commit | f735158d94616b75ade351a3cce226483b8af55e (patch) | |
tree | 1cd9732b99cc6437fec7751b8f3c9ef28f0371c9 /src/ats | |
parent | d769049a7db56037ea4aff3d9d8a8d42a373ec9c (diff) | |
download | gnunet-f735158d94616b75ade351a3cce226483b8af55e.tar.gz gnunet-f735158d94616b75ade351a3cce226483b8af55e.zip |
-towards improved ATS API, adding return value with address record when adding address, adding new subsystem with peer-to-address map to transport; causes various new assertions to fail, but no major regression -- not finished
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/ats_api_scheduling.c | 51 |
1 files changed, 22 insertions, 29 deletions
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index c7c79d289..1c30f2e66 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c | |||
@@ -48,6 +48,12 @@ | |||
48 | */ | 48 | */ |
49 | struct GNUNET_ATS_AddressRecord | 49 | struct GNUNET_ATS_AddressRecord |
50 | { | 50 | { |
51 | |||
52 | /** | ||
53 | * Scheduling handle this address record belongs to. | ||
54 | */ | ||
55 | struct GNUNET_ATS_SchedulingHandle *sh; | ||
56 | |||
51 | /** | 57 | /** |
52 | * Address data. | 58 | * Address data. |
53 | */ | 59 | */ |
@@ -331,7 +337,7 @@ find_empty_session_slot (struct GNUNET_ATS_SchedulingHandle *sh) | |||
331 | off++; | 337 | off++; |
332 | i++; | 338 | i++; |
333 | } | 339 | } |
334 | if ( (NOT_FOUND != off) && | 340 | if ( (NOT_FOUND != off % sh->session_array_size) && |
335 | (NULL == sh->session_array[off % sh->session_array_size]) ) | 341 | (NULL == sh->session_array[off % sh->session_array_size]) ) |
336 | return off; | 342 | return off; |
337 | i = sh->session_array_size; | 343 | i = sh->session_array_size; |
@@ -1191,9 +1197,10 @@ GNUNET_ATS_session_known (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1191 | * @param session session handle, can be NULL | 1197 | * @param session session handle, can be NULL |
1192 | * @param ats performance data for the address | 1198 | * @param ats performance data for the address |
1193 | * @param ats_count number of performance records in @a ats | 1199 | * @param ats_count number of performance records in @a ats |
1194 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 1200 | * @return handle to the address representation inside ATS, NULL |
1201 | * on error (i.e. ATS knows this exact address already) | ||
1195 | */ | 1202 | */ |
1196 | int | 1203 | struct GNUNET_ATS_AddressRecord * |
1197 | GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | 1204 | GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, |
1198 | const struct GNUNET_HELLO_Address *address, | 1205 | const struct GNUNET_HELLO_Address *address, |
1199 | struct Session *session, | 1206 | struct Session *session, |
@@ -1209,7 +1216,7 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1209 | { | 1216 | { |
1210 | /* we need a valid address */ | 1217 | /* we need a valid address */ |
1211 | GNUNET_break (0); | 1218 | GNUNET_break (0); |
1212 | return GNUNET_SYSERR; | 1219 | return NULL; |
1213 | } | 1220 | } |
1214 | namelen = (NULL == address->transport_name) | 1221 | namelen = (NULL == address->transport_name) |
1215 | ? 0 | 1222 | ? 0 |
@@ -1224,17 +1231,18 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1224 | { | 1231 | { |
1225 | /* address too large for us, this should not happen */ | 1232 | /* address too large for us, this should not happen */ |
1226 | GNUNET_break (0); | 1233 | GNUNET_break (0); |
1227 | return GNUNET_SYSERR; | 1234 | return NULL; |
1228 | } | 1235 | } |
1229 | 1236 | ||
1230 | if (NOT_FOUND != find_session_id (sh, session, address)) | 1237 | if (NOT_FOUND != find_session_id (sh, session, address)) |
1231 | { | 1238 | { |
1232 | /* Already existing, nothing todo, but this should not happen */ | 1239 | /* Already existing, nothing todo, but this should not happen */ |
1233 | GNUNET_break (0); | 1240 | GNUNET_break (0); |
1234 | return GNUNET_SYSERR; | 1241 | return NULL; |
1235 | } | 1242 | } |
1236 | s = find_empty_session_slot (sh); | 1243 | s = find_empty_session_slot (sh); |
1237 | ar = GNUNET_new (struct GNUNET_ATS_AddressRecord); | 1244 | ar = GNUNET_new (struct GNUNET_ATS_AddressRecord); |
1245 | ar->sh = sh; | ||
1238 | ar->slot = s; | 1246 | ar->slot = s; |
1239 | ar->session = session; | 1247 | ar->session = session; |
1240 | ar->address = GNUNET_HELLO_address_copy (address); | 1248 | ar->address = GNUNET_HELLO_address_copy (address); |
@@ -1244,7 +1252,7 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1244 | memcpy (ar->ats, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); | 1252 | memcpy (ar->ats, ats, ats_count * sizeof (struct GNUNET_ATS_Information)); |
1245 | sh->session_array[s] = ar; | 1253 | sh->session_array[s] = ar; |
1246 | send_add_address_message (sh, ar, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD); | 1254 | send_add_address_message (sh, ar, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD); |
1247 | return GNUNET_OK; | 1255 | return ar; |
1248 | } | 1256 | } |
1249 | 1257 | ||
1250 | 1258 | ||
@@ -1256,33 +1264,17 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1256 | * which case the call may be ignored or the information may be stored | 1264 | * which case the call may be ignored or the information may be stored |
1257 | * for later use). Update bandwidth assignments. | 1265 | * for later use). Update bandwidth assignments. |
1258 | * | 1266 | * |
1259 | * FIXME: change API so we do not have to do the linear search! | 1267 | * @param ar address record to update information for |
1260 | * | ||
1261 | * @param sh handle | ||
1262 | * @param address the address | ||
1263 | * @param session session handle, can be NULL | 1268 | * @param session session handle, can be NULL |
1264 | * @param ats performance data for the address | 1269 | * @param ats performance data for the address |
1265 | * @param ats_count number of performance records in @a ats | 1270 | * @param ats_count number of performance records in @a ats |
1266 | * @return #GNUNET_YES on success, #GNUNET_NO if address or session are unknown, | ||
1267 | * #GNUNET_SYSERR on hard failure | ||
1268 | */ | 1271 | */ |
1269 | int | 1272 | void |
1270 | GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, | 1273 | GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar, |
1271 | const struct GNUNET_HELLO_Address *address, | ||
1272 | struct Session *session, | 1274 | struct Session *session, |
1273 | const struct GNUNET_ATS_Information *ats, | 1275 | const struct GNUNET_ATS_Information *ats, |
1274 | uint32_t ats_count) | 1276 | uint32_t ats_count) |
1275 | { | 1277 | { |
1276 | uint32_t s; | ||
1277 | struct GNUNET_ATS_AddressRecord *ar; | ||
1278 | |||
1279 | s = find_session_id (sh, session, address); | ||
1280 | if (NOT_FOUND == s) | ||
1281 | { | ||
1282 | GNUNET_break (0); | ||
1283 | return GNUNET_NO; | ||
1284 | } | ||
1285 | ar = sh->session_array[s]; | ||
1286 | GNUNET_array_grow (ar->ats, | 1278 | GNUNET_array_grow (ar->ats, |
1287 | ar->ats_count, | 1279 | ar->ats_count, |
1288 | ats_count); | 1280 | ats_count); |
@@ -1290,8 +1282,9 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1290 | ats, | 1282 | ats, |
1291 | ats_count * sizeof (struct GNUNET_ATS_Information)); | 1283 | ats_count * sizeof (struct GNUNET_ATS_Information)); |
1292 | ar->session = session; | 1284 | ar->session = session; |
1293 | send_add_address_message (sh, ar, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); | 1285 | send_add_address_message (ar->sh, |
1294 | return GNUNET_YES; | 1286 | ar, |
1287 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE); | ||
1295 | } | 1288 | } |
1296 | 1289 | ||
1297 | 1290 | ||
@@ -1384,7 +1377,7 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh, | |||
1384 | s = find_session_id (sh, session, address); | 1377 | s = find_session_id (sh, session, address); |
1385 | if (NOT_FOUND == s) | 1378 | if (NOT_FOUND == s) |
1386 | { | 1379 | { |
1387 | GNUNET_break (0); | 1380 | GNUNET_assert (0); |
1388 | return; | 1381 | return; |
1389 | } | 1382 | } |
1390 | ar = sh->session_array[s]; | 1383 | ar = sh->session_array[s]; |