/*
This file is part of GNUnet.
(C) 2011 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3, or (at your
option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/**
* @file ats/gnunet-service-ats_addresses_simplistic.h
* @brief ats simplistic ressource assignment
* @author Matthias Wachs
* @author Christian Grothoff
*/
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet-service-ats_addresses.h"
#include "gnunet_statistics_service.h"
#define LOG(kind,...) GNUNET_log_from (kind, "ats-simplistic",__VA_ARGS__)
/**
* ATS simplistic solver
*
* Assigns in and outbound bandwidth equally for all addresses in specific
* network type (WAN, LAN) based on configured in and outbound quota for this
* network.
*
* For each peer only a single is selected and marked as "active" in the address
* struct.
*
* E.g.:
*
* You have the networks WAN and LAN and quotas
* WAN_TOTAL_IN, WAN_TOTAL_OUT
* LAN_TOTAL_IN, LAN_TOTAL_OUT
*
* If you have x addresses in the network segment LAN, the quotas are
* QUOTA_PER_ADDRESS = LAN_TOTAL_OUT / x
*
* Quotas are automatically recalculated and reported back when addresses are
* - requested
*
*/
#define PREF_AGING_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
#define PREF_AGING_FACTOR 0.95
#define DEFAULT_PREFERENCE 1.0
#define MIN_UPDATE_INTERVAL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
/**
* A handle for the simplistic solver
*/
struct GAS_SIMPLISTIC_Handle
{
/**
* Statistics handle
*/
struct GNUNET_STATISTICS_Handle *stats;
/**
* Total number of addresses for solver
*/
unsigned int total_addresses;
/**
* Number of active addresses for solver
*/
unsigned int active_addresses;
/**
* Networks array
*/
struct Network *network_entries;
/**
* Number of networks
*/
unsigned int networks;
/**
* Callback
*/
GAS_bandwidth_changed_cb bw_changed;
/**
* Callback cls
*/
void *bw_changed_cls;
struct GNUNET_CONTAINER_MultiHashMap *prefs;
struct PreferenceClient *pc_head;
struct PreferenceClient *pc_tail;
};
struct Network
{
/**
* ATS network type
*/
unsigned int type;
/**
* Network description
*/
char *desc;
/**
* Total inbound quota
*
*/
unsigned long long total_quota_in;
/**
* Total outbound quota
*
*/
unsigned long long total_quota_out;
/**
* Number of active addresses for this network
*/
unsigned int active_addresses;
/**
* Number of total addresses for this network
*/
unsigned int total_addresses;
/**
* String for statistics total addresses
*/
char *stat_total;
/**
* String for statistics active addresses
*/
char *stat_active