};
+
+/**
+ * Calculate an updated bandwidth assignment and notify.
+ *
+ * @param ats handle
+ * @param change which allocation record changed?
+ */
+static void
+update_bandwidth_assignment (struct GST_AtsHandle *atc,
+ struct AllocationRecord *change)
+{
+
+}
+
+
/**
* Initialize the ATS subsystem.
*
}
+/**
+ * Closure for 'update_session'
+ */
+struct UpdateSessionContext
+{
+ /**
+ * Ats handle.
+ */
+ struct GST_AtsHandle *atc;
+
+ /**
+ * Allocation record with new information.
+ */
+ struct AllocationRecord *arnew;
+};
+
+
/**
* Update an allocation record, merging with the new information
*
const GNUNET_HashCode *key,
void *value)
{
- struct AllocationRecord *arnew = cls;
+ struct UpdateSessionContext *usc = cls;
+ struct AllocationRecord *arnew = usc->arnew;
struct AllocationRecord *arold = value;
+ int change;
if (0 != strcmp (arnew->plugin_name, arold->plugin_name))
return GNUNET_YES;
arnew->plugin_addr,
arnew->plugin_addr_len)) ) )
{
+ change = GNUNET_NO;
/* records match */
- arold->session = arnew->session;
- if (arnew->connected == GNUNET_YES)
- arold->connected = GNUNET_YES;
+ if (arnew->session != arold->session)
+ {
+ arold->session = arnew->session;
+ change = GNUNET_YES;
+ }
+ if ( (arnew->connected == GNUNET_YES) &&
+ (arold->connected == GNUNET_NO) )
+ {
+ arold->connected = GNUNET_YES;
+ change = GNUNET_YES;
+ }
// FIXME: merge ats arrays of (arold, arnew);
- return GNUNET_NO;
+
+ if (GNUNET_YES == change)
+ update_bandwidth_assignment (usc->atc, arold);
+ return GNUNET_NO;
}
return GNUNET_YES;
}
uint32_t ats_count)
{
struct AllocationRecord *ar;
+ struct UpdateSessionContext usc;
ar = create_allocation_record (plugin_name,
session,
ats,
ats_count);
ar->connected = GNUNET_YES;
+ usc.atc = atc;
+ usc.arnew = ar;
if (GNUNET_SYSERR ==
GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
&update_session,
- ar))
+ &usc))
{
destroy_allocation_record (NULL, &peer->hashPubKey, ar);
return;
/**
* Mark all matching allocation records as not connected.
*
- * @param cls unused
+ * @param cls 'struct GTS_AtsHandle'
* @param key identity of the peer associated with the record
* @param value the 'struct AllocationRecord' to clear the 'connected' flag
* @return GNUNET_OK (continue to iterate)
const GNUNET_HashCode *key,
void *value)
{
+ struct GST_AtsHandle *atc = cls;
struct AllocationRecord *ar = value;
- ar->connected = GNUNET_NO;
+ if (GNUNET_YES == ar->connected)
+ {
+ ar->connected = GNUNET_NO;
+ update_bandwidth_assignment (atc, ar);
+ }
return GNUNET_OK;
}
{
(void) GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
&disconnect_peer,
- NULL);
+ atc);
}
GNUNET_CONTAINER_multihashmap_remove (sdc->atc->peers,
key,
ar));
+ if (GNUNET_YES == ar->connected);
+ {
+ /* FIXME: is this supposed to be allowed? What to do then? */
+ GNUNET_break (0);
+ }
destroy_allocation_record (NULL, key, ar);
return GNUNET_OK;
}
uint32_t ats_count)
{
struct AllocationRecord *ar;
+ struct UpdateSessionContext usc;
ar = create_allocation_record (plugin_name,
session,
plugin_addr_len,
ats,
ats_count);
-
+ usc.atc = atc;
+ usc.arnew = ar;
if (GNUNET_SYSERR ==
GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
&update_session,
- ar))
+ &usc))
{
destroy_allocation_record (NULL, &peer->hashPubKey, ar);
return;