/** * Compute the MIN of two bandwidth values. * * @param b1 first value * @param b2 second value * @return the min of b1 and b2 */ struct GNUNET_BANDWIDTH_Value32NBO GNUNET_BANDWIDTH_value_min (struct GNUNET_BANDWIDTH_Value32NBO b1, struct GNUNET_BANDWIDTH_Value32NBO b2) { return GNUNET_BANDWIDTH_value_init (GNUNET_MIN (ntohl (b1.value__), ntohl (b2.value__))); }
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); } }
/** * Compute how many bytes are available for consumption right now. * quota. * * @param av tracker to query * @return number of bytes available for consumption right now */ int64_t GNUNET_BANDWIDTH_tracker_get_available (struct GNUNET_BANDWIDTH_Tracker *av) { struct GNUNET_BANDWIDTH_Value32NBO bps; uint64_t avail; int64_t used; update_tracker (av); bps = GNUNET_BANDWIDTH_value_init (av->available_bytes_per_s__); avail = GNUNET_BANDWIDTH_value_get_available_until (bps, GNUNET_TIME_absolute_get_duration (av->last_update__)); used = av->consumption_since_last_update__; LOG (GNUNET_ERROR_TYPE_DEBUG, "Tracker %p available bandwidth is %lld bytes\n", av, (long long) (int64_t) (avail - used)); return (int64_t) (avail - used); }
/** * Return all peers currently known to ATS * * @param peer the respective peer * @param pi_it the iterator to call for every peer * @param pi_it_cls the closure for the iterator */ void GAS_addresses_get_peer_info (const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_PeerInfo_Iterator pi_it, void *pi_it_cls) { struct PeerInfoIteratorContext pi_ctx; struct GNUNET_BANDWIDTH_Value32NBO zero_bw; GNUNET_assert (NULL != peer); GNUNET_assert (NULL != addresses); if (NULL == pi_it) return; /* does not make sense without callback */ zero_bw = GNUNET_BANDWIDTH_value_init (0); pi_ctx.it = pi_it; pi_ctx.it_cls = pi_it_cls; GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, &peerinfo_it, &pi_ctx); if (NULL != pi_it) pi_it (pi_it_cls, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0, zero_bw, zero_bw); }
/** * 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; }