aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-11 12:46:39 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-11 12:46:39 +0000
commit297e28384ae74a468895f950552ae4acfb7efb0d (patch)
tree1ba7eb0371eec16db9ef48ac9538376447e04a33 /src/transport
parentf4d8c1ac6729a93a737a5dc92722ca0d7bd32ce5 (diff)
downloadgnunet-297e28384ae74a468895f950552ae4acfb7efb0d.tar.gz
gnunet-297e28384ae74a468895f950552ae4acfb7efb0d.zip
stuff
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport_ats-new.c85
1 files changed, 56 insertions, 29 deletions
diff --git a/src/transport/gnunet-service-transport_ats-new.c b/src/transport/gnunet-service-transport_ats-new.c
index 250ebc119..983674c07 100644
--- a/src/transport/gnunet-service-transport_ats-new.c
+++ b/src/transport/gnunet-service-transport_ats-new.c
@@ -102,9 +102,24 @@ struct GST_AtsHandle
102 */ 102 */
103 struct GNUNET_CONTAINER_MultiHashMap *peers; 103 struct GNUNET_CONTAINER_MultiHashMap *peers;
104 104
105 /**
106 * Task scheduled to update our bandwidth assignment.
107 */
108 GNUNET_SCHEDULER_TaskIdentifier ba_task;
105}; 109};
106 110
107 111
112static void
113update_bandwidth_task (void *cls,
114 const struct GNUNET_SCHEDULER_TaskContext *tc)
115{
116 struct GST_AtsHandle *atc = cls;
117
118 atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
119 /* FIXME: update calculations! */
120
121}
122
108 123
109/** 124/**
110 * Calculate an updated bandwidth assignment and notify. 125 * Calculate an updated bandwidth assignment and notify.
@@ -116,7 +131,10 @@ static void
116update_bandwidth_assignment (struct GST_AtsHandle *atc, 131update_bandwidth_assignment (struct GST_AtsHandle *atc,
117 struct AllocationRecord *change) 132 struct AllocationRecord *change)
118{ 133{
119 134 /* FIXME: based on the 'change', update the problem... */
135 if (atc->ba_task == GNUNET_SCHEDULER_NO_TASK)
136 atc->ba_task = GNUNET_SCHEDULER_add_now (&update_bandwidth_task,
137 atc);
120} 138}
121 139
122 140
@@ -174,6 +192,11 @@ destroy_allocation_record (void *cls,
174void 192void
175GST_ats_shutdown (struct GST_AtsHandle *atc) 193GST_ats_shutdown (struct GST_AtsHandle *atc)
176{ 194{
195 if (GNUNET_SCHEDULER_NO_TASK != atc->ba_task)
196 {
197 GNUNET_SCHEDULER_cancel (atc->ba_task);
198 atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
199 }
177 GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 200 GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
178 &destroy_allocation_record, 201 &destroy_allocation_record,
179 NULL); 202 NULL);
@@ -287,6 +310,31 @@ create_allocation_record (const char *plugin_name,
287 310
288 311
289/** 312/**
313 * Mark all matching allocation records as not connected.
314 *
315 * @param cls 'struct GTS_AtsHandle'
316 * @param key identity of the peer associated with the record
317 * @param value the 'struct AllocationRecord' to clear the 'connected' flag
318 * @return GNUNET_OK (continue to iterate)
319 */
320static int
321disconnect_peer (void *cls,
322 const GNUNET_HashCode *key,
323 void *value)
324{
325 struct GST_AtsHandle *atc = cls;
326 struct AllocationRecord *ar = value;
327
328 if (GNUNET_YES == ar->connected)
329 {
330 ar->connected = GNUNET_NO;
331 update_bandwidth_assignment (atc, ar);
332 }
333 return GNUNET_OK;
334}
335
336
337/**
290 * We established a new connection with a peer (for example, because 338 * We established a new connection with a peer (for example, because
291 * core asked for it or because the other peer connected to us). 339 * core asked for it or because the other peer connected to us).
292 * Calculate bandwidth assignments including the new peer. 340 * Calculate bandwidth assignments including the new peer.
@@ -313,6 +361,9 @@ GST_ats_peer_connect (struct GST_AtsHandle *atc,
313 struct AllocationRecord *ar; 361 struct AllocationRecord *ar;
314 struct UpdateSessionContext usc; 362 struct UpdateSessionContext usc;
315 363
364 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
365 &disconnect_peer,
366 atc);
316 ar = create_allocation_record (plugin_name, 367 ar = create_allocation_record (plugin_name,
317 session, 368 session,
318 plugin_addr, 369 plugin_addr,
@@ -339,31 +390,6 @@ GST_ats_peer_connect (struct GST_AtsHandle *atc,
339 390
340 391
341/** 392/**
342 * Mark all matching allocation records as not connected.
343 *
344 * @param cls 'struct GTS_AtsHandle'
345 * @param key identity of the peer associated with the record
346 * @param value the 'struct AllocationRecord' to clear the 'connected' flag
347 * @return GNUNET_OK (continue to iterate)
348 */
349static int
350disconnect_peer (void *cls,
351 const GNUNET_HashCode *key,
352 void *value)
353{
354 struct GST_AtsHandle *atc = cls;
355 struct AllocationRecord *ar = value;
356
357 if (GNUNET_YES == ar->connected)
358 {
359 ar->connected = GNUNET_NO;
360 update_bandwidth_assignment (atc, ar);
361 }
362 return GNUNET_OK;
363}
364
365
366/**
367 * We disconnected from the given peer (for example, because ats, core 393 * We disconnected from the given peer (for example, because ats, core
368 * or blacklist asked for it or because the other peer disconnected). 394 * or blacklist asked for it or because the other peer disconnected).
369 * Calculate bandwidth assignments without the peer. 395 * Calculate bandwidth assignments without the peer.
@@ -375,9 +401,10 @@ void
375GST_ats_peer_disconnect (struct GST_AtsHandle *atc, 401GST_ats_peer_disconnect (struct GST_AtsHandle *atc,
376 const struct GNUNET_PeerIdentity *peer) 402 const struct GNUNET_PeerIdentity *peer)
377{ 403{
378 (void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers, 404 (void) GNUNET_CONTAINER_multihashmap_get_multiple (atc->peers,
379 &disconnect_peer, 405 &peer->hashPubKey,
380 atc); 406 &disconnect_peer,
407 atc);
381} 408}
382 409
383 410