aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-11 12:15:01 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-11 12:15:01 +0000
commitd76c206d329c61652f4ea88ba7efd480d437876a (patch)
tree86a680bba69ad22c68f05b2f921ba5bec10a3e62 /src/transport
parent1fe306c6b89e25fddf96bb588ce7989bd4c53a59 (diff)
downloadgnunet-d76c206d329c61652f4ea88ba7efd480d437876a.tar.gz
gnunet-d76c206d329c61652f4ea88ba7efd480d437876a.zip
more ats API hacking
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport_ats-new.c83
1 files changed, 72 insertions, 11 deletions
diff --git a/src/transport/gnunet-service-transport_ats-new.c b/src/transport/gnunet-service-transport_ats-new.c
index d6eef7bee..250ebc119 100644
--- a/src/transport/gnunet-service-transport_ats-new.c
+++ b/src/transport/gnunet-service-transport_ats-new.c
@@ -105,6 +105,21 @@ struct GST_AtsHandle
105}; 105};
106 106
107 107
108
109/**
110 * Calculate an updated bandwidth assignment and notify.
111 *
112 * @param ats handle
113 * @param change which allocation record changed?
114 */
115static void
116update_bandwidth_assignment (struct GST_AtsHandle *atc,
117 struct AllocationRecord *change)
118{
119
120}
121
122
108/** 123/**
109 * Initialize the ATS subsystem. 124 * Initialize the ATS subsystem.
110 * 125 *
@@ -168,6 +183,23 @@ GST_ats_shutdown (struct GST_AtsHandle *atc)
168 183
169 184
170/** 185/**
186 * Closure for 'update_session'
187 */
188struct UpdateSessionContext
189{
190 /**
191 * Ats handle.
192 */
193 struct GST_AtsHandle *atc;
194
195 /**
196 * Allocation record with new information.
197 */
198 struct AllocationRecord *arnew;
199};
200
201
202/**
171 * Update an allocation record, merging with the new information 203 * Update an allocation record, merging with the new information
172 * 204 *
173 * @param cls a new 'struct AllocationRecord' 205 * @param cls a new 'struct AllocationRecord'
@@ -181,8 +213,10 @@ update_session (void *cls,
181 const GNUNET_HashCode *key, 213 const GNUNET_HashCode *key,
182 void *value) 214 void *value)
183{ 215{
184 struct AllocationRecord *arnew = cls; 216 struct UpdateSessionContext *usc = cls;
217 struct AllocationRecord *arnew = usc->arnew;
185 struct AllocationRecord *arold = value; 218 struct AllocationRecord *arold = value;
219 int change;
186 220
187 if (0 != strcmp (arnew->plugin_name, arold->plugin_name)) 221 if (0 != strcmp (arnew->plugin_name, arold->plugin_name))
188 return GNUNET_YES; 222 return GNUNET_YES;
@@ -193,12 +227,24 @@ update_session (void *cls,
193 arnew->plugin_addr, 227 arnew->plugin_addr,
194 arnew->plugin_addr_len)) ) ) 228 arnew->plugin_addr_len)) ) )
195 { 229 {
230 change = GNUNET_NO;
196 /* records match */ 231 /* records match */
197 arold->session = arnew->session; 232 if (arnew->session != arold->session)
198 if (arnew->connected == GNUNET_YES) 233 {
199 arold->connected = GNUNET_YES; 234 arold->session = arnew->session;
235 change = GNUNET_YES;
236 }
237 if ( (arnew->connected == GNUNET_YES) &&
238 (arold->connected == GNUNET_NO) )
239 {
240 arold->connected = GNUNET_YES;
241 change = GNUNET_YES;
242 }
200 // FIXME: merge ats arrays of (arold, arnew); 243 // FIXME: merge ats arrays of (arold, arnew);
201 return GNUNET_NO; 244
245 if (GNUNET_YES == change)
246 update_bandwidth_assignment (usc->atc, arold);
247 return GNUNET_NO;
202 } 248 }
203 return GNUNET_YES; 249 return GNUNET_YES;
204} 250}
@@ -265,6 +311,7 @@ GST_ats_peer_connect (struct GST_AtsHandle *atc,
265 uint32_t ats_count) 311 uint32_t ats_count)
266{ 312{
267 struct AllocationRecord *ar; 313 struct AllocationRecord *ar;
314 struct UpdateSessionContext usc;
268 315
269 ar = create_allocation_record (plugin_name, 316 ar = create_allocation_record (plugin_name,
270 session, 317 session,
@@ -273,10 +320,12 @@ GST_ats_peer_connect (struct GST_AtsHandle *atc,
273 ats, 320 ats,
274 ats_count); 321 ats_count);
275 ar->connected = GNUNET_YES; 322 ar->connected = GNUNET_YES;
323 usc.atc = atc;
324 usc.arnew = ar;
276 if (GNUNET_SYSERR == 325 if (GNUNET_SYSERR ==
277 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 326 GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
278 &update_session, 327 &update_session,
279 ar)) 328 &usc))
280 { 329 {
281 destroy_allocation_record (NULL, &peer->hashPubKey, ar); 330 destroy_allocation_record (NULL, &peer->hashPubKey, ar);
282 return; 331 return;
@@ -292,7 +341,7 @@ GST_ats_peer_connect (struct GST_AtsHandle *atc,
292/** 341/**
293 * Mark all matching allocation records as not connected. 342 * Mark all matching allocation records as not connected.
294 * 343 *
295 * @param cls unused 344 * @param cls 'struct GTS_AtsHandle'
296 * @param key identity of the peer associated with the record 345 * @param key identity of the peer associated with the record
297 * @param value the 'struct AllocationRecord' to clear the 'connected' flag 346 * @param value the 'struct AllocationRecord' to clear the 'connected' flag
298 * @return GNUNET_OK (continue to iterate) 347 * @return GNUNET_OK (continue to iterate)
@@ -302,9 +351,14 @@ disconnect_peer (void *cls,
302 const GNUNET_HashCode *key, 351 const GNUNET_HashCode *key,
303 void *value) 352 void *value)
304{ 353{
354 struct GST_AtsHandle *atc = cls;
305 struct AllocationRecord *ar = value; 355 struct AllocationRecord *ar = value;
306 356
307 ar->connected = GNUNET_NO; 357 if (GNUNET_YES == ar->connected)
358 {
359 ar->connected = GNUNET_NO;
360 update_bandwidth_assignment (atc, ar);
361 }
308 return GNUNET_OK; 362 return GNUNET_OK;
309} 363}
310 364
@@ -323,7 +377,7 @@ GST_ats_peer_disconnect (struct GST_AtsHandle *atc,
323{ 377{
324 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 378 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
325 &disconnect_peer, 379 &disconnect_peer,
326 NULL); 380 atc);
327} 381}
328 382
329 383
@@ -369,6 +423,11 @@ destroy_session (void *cls,
369 GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers, 423 GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers,
370 key, 424 key,
371 ar)); 425 ar));
426 if (GNUNET_YES == ar->connected);
427 {
428 /* FIXME: is this supposed to be allowed? What to do then? */
429 GNUNET_break (0);
430 }
372 destroy_allocation_record (NULL, key, ar); 431 destroy_allocation_record (NULL, key, ar);
373 return GNUNET_OK; 432 return GNUNET_OK;
374} 433}
@@ -424,6 +483,7 @@ GST_ats_address_update (struct GST_AtsHandle *atc,
424 uint32_t ats_count) 483 uint32_t ats_count)
425{ 484{
426 struct AllocationRecord *ar; 485 struct AllocationRecord *ar;
486 struct UpdateSessionContext usc;
427 487
428 ar = create_allocation_record (plugin_name, 488 ar = create_allocation_record (plugin_name,
429 session, 489 session,
@@ -431,11 +491,12 @@ GST_ats_address_update (struct GST_AtsHandle *atc,
431 plugin_addr_len, 491 plugin_addr_len,
432 ats, 492 ats,
433 ats_count); 493 ats_count);
434 494 usc.atc = atc;
495 usc.arnew = ar;
435 if (GNUNET_SYSERR == 496 if (GNUNET_SYSERR ==
436 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 497 GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
437 &update_session, 498 &update_session,
438 ar)) 499 &usc))
439 { 500 {
440 destroy_allocation_record (NULL, &peer->hashPubKey, ar); 501 destroy_allocation_record (NULL, &peer->hashPubKey, ar);
441 return; 502 return;