static void
send_bw_notification (struct ATS_Address *aa)
{
  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New bandwidth for peer %s is %u/%u\n",
              GNUNET_i2s (&aa->peer), ntohl (aa->assigned_bw_in.value__),
              ntohl (aa->assigned_bw_out.value__));
  GAS_scheduling_transmit_address_suggestion (&aa->peer, aa->plugin, aa->addr,
                                              aa->addr_len, aa->session_id,
                                              aa->ats, aa->ats_count,
                                              aa->assigned_bw_out,
                                              aa->assigned_bw_in);
  GAS_reservations_set_bandwidth (&aa->peer, aa->assigned_bw_in);
  GAS_performance_notify_clients (&aa->peer, aa->plugin, aa->addr, aa->addr_len,
                                  aa->ats, aa->ats_count, aa->assigned_bw_out,
                                  aa->assigned_bw_in);
}
static void 
request_address_mlp (const struct GNUNET_PeerIdentity *peer)
{
  struct ATS_Address *aa;
  aa = NULL;

#if HAVE_GLPK
  /* Get preferred address from MLP */
  struct ATS_PreferedAddress * paddr = NULL;
  paddr = GAS_mlp_get_preferred_address (mlp, addresses, peer);
  aa = paddr->address;
  aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(paddr->bandwidth_out);
  /* FIXME use bw in value */
  paddr->bandwidth_in = paddr->bandwidth_out;
  aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init (paddr->bandwidth_in);
  GNUNET_free (paddr);
#endif

  if (aa == NULL)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
                "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer));
    return;
  }
  if (aa->active == GNUNET_NO)
  {
    aa->active = GNUNET_YES;
    active_addr_count++;

    send_bw_notification (aa);
  }
  else
  {
    /* just to be sure... */
    GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr,
                                                aa->addr_len, aa->session_id,
                                                aa->ats, aa->ats_count,
                                                aa->assigned_bw_out,
                                                aa->assigned_bw_in);
  }

}
static void 
request_address_simple (const struct GNUNET_PeerIdentity *peer)
{
  struct ATS_Address *aa;
  aa = NULL;

  /* Get address with: stick to current address, lower distance, lower latency */
  GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
                                              &find_address_it, &aa);
  if (aa == NULL)
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
                "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer));
    return;
  }

  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
              "Suggesting address %p for peer `%s'\n", aa, GNUNET_i2s (peer));

  if (aa->active == GNUNET_NO)
  {
    aa->active = GNUNET_YES;
    active_addr_count++;
    if (ats_mode == SIMPLE)
    {
      recalculate_assigned_bw ();
    }
  }
  else
  {
    /* just to be sure... */
    GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr,
                                                aa->addr_len, aa->session_id,
                                                aa->ats, aa->ats_count,
                                                aa->assigned_bw_out,
                                                aa->assigned_bw_in);
  }
}
static void
send_bw_notification (struct ATS_Address *aa)
{
  struct GNUNET_ATS_Information *ats;
  uint32_t ats_count;

  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New bandwidth for peer %s is %u/%u\n",
              GNUNET_i2s (&aa->peer), ntohl (aa->assigned_bw_in.value__),
              ntohl (aa->assigned_bw_out.value__));
  ats_count = assemble_ats_information (aa, &ats);

  GAS_scheduling_transmit_address_suggestion (&aa->peer, aa->plugin, aa->addr,
                                              aa->addr_len, aa->session_id,
                                              ats, ats_count,
                                              aa->assigned_bw_out,
                                              aa->assigned_bw_in);
  GAS_reservations_set_bandwidth (&aa->peer, aa->assigned_bw_in);
  GAS_performance_notify_all_clients (&aa->peer, aa->plugin, aa->addr, aa->addr_len,
                                  aa->active,
                                  ats, ats_count, aa->assigned_bw_out,
                                  aa->assigned_bw_in);
  GNUNET_free (ats);
}
/**
 * Callback for solver to notify about assignment changes
 *
 * @param cls NULL
 * @param address the address with changes
 */
static void
bandwidth_changed_cb (void *cls,
		      struct ATS_Address *address)
{
  long long diff_out;
  long long diff_in;

  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Bandwidth assignment changed for peer %s to %u/%u\n",
              GNUNET_i2s (&address->peer),
              (unsigned int) address->assigned_bw_in,
              (unsigned int) address->assigned_bw_out);
  GAS_reservations_set_bandwidth (&address->peer,
                                  GNUNET_BANDWIDTH_value_init (address->assigned_bw_in));
  /* Notify performance clients about changes to address */
  GAS_performance_notify_all_clients (&address->peer,
				      address->plugin,
				      address->addr,
				      address->addr_len,
				      address->active,
				      &address->properties,
                                      address->local_address_info,
				      GNUNET_BANDWIDTH_value_init (address->assigned_bw_out),
				      GNUNET_BANDWIDTH_value_init (address->assigned_bw_in));

  if ( (0 == address->assigned_bw_in) &&
       (0 == address->assigned_bw_out) )
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Telling transport to disconnect peer `%s'\n",
                GNUNET_i2s (&address->peer));

    /* Notify scheduling clients about suggestion */
    GAS_scheduling_transmit_address_suggestion (&address->peer,
                                                address->session_id,
                                                GNUNET_BANDWIDTH_ZERO,
                                                GNUNET_BANDWIDTH_ZERO);
    return;
  }

  /* Do bandwidth stability check */
  diff_out = llabs ((long long) address->assigned_bw_out -
                    (long long) address->last_notified_bw_out);
  diff_in = llabs ((long long) address->assigned_bw_in -
                   (long long) address->last_notified_bw_in);
  if ( (diff_out < htonl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) &&
       (diff_in < htonl (GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT.value__)) )
  {
    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                "Bandwidth change too small, not notifying client\n");
    return;
  }

  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Sending bandwidth update for peer `%s': %u/%u\n",
              GNUNET_i2s (&address->peer),
              address->assigned_bw_out,
              address->assigned_bw_out);

  /* *Notify scheduling clients about suggestion */
  GAS_scheduling_transmit_address_suggestion (&address->peer,
                                              address->session_id,
                                              GNUNET_BANDWIDTH_value_init (address->assigned_bw_out),
                                              GNUNET_BANDWIDTH_value_init (address->assigned_bw_in));

  address->last_notified_bw_out = address->assigned_bw_out;
  address->last_notified_bw_in = address->assigned_bw_in;
}