-static uint32_t allocate_fps(identity_t *ident, double total_weight) {
- common_accounting_t *ftable = &ident->common; /* Common flow table info */
- uint32_t local_rate = ftable->rate;
- uint32_t ideallocal = 0;
- double peer_weights; /* sum of weights of all other limiters */
- double idealweight = 0;
- double last_portion = 0;
- double this_portion = 0;
-
- static int dampen = 0;
- int dampen_increase = 0;
-
- double ideal_under = 0;
- double ideal_over = 0;
-
- int regime = 0;
-
- /* two cases:
- 1. the aggregate is < limit
- 2. the aggregate is >= limit
- */
- peer_weights = total_weight - ident->last_localweight;
- if (peer_weights < 0) {
- peer_weights = 0;
+static inline uint32_t close_enough(uint32_t limit) {
+ uint32_t difference = limit - (limit * CLOSE_ENOUGH);
+
+ if (difference < 10240) {
+ return (limit - 10240);
+ } else {
+ return (limit * CLOSE_ENOUGH);
+ }
+}
+
+static void print_statistics(identity_t *ident, const double ideal_weight,
+ const double total_weight, const double localweight,
+ const char *identifier, common_accounting_t *table,
+ const uint32_t resulting_limit) {
+ struct timeval tv;
+ double time_now;
+
+ gettimeofday(&tv, NULL);
+ time_now = (double) tv.tv_sec + (double) ((double) tv.tv_usec / (double) 1000000);
+
+ printlog(LOG_WARN, "%.2f %d %.2f %.2f %.2f %d %d %d %d %d %d %d %d %d %s:%d ",
+ time_now, table->inst_rate, ideal_weight, localweight, total_weight,
+ table->num_flows, table->num_flows_5k, table->num_flows_10k,
+ table->num_flows_20k, table->num_flows_50k, table->avg_rate,
+ table->max_flow_rate, table->max_flow_rate_flow_hash, resulting_limit,
+ identifier, ident->id);
+
+ if (table->max_flow_rate > 0) {
+ printlog(LOG_WARN, "%.3f\n", (double) table->rate / (double) table->max_flow_rate);
+ } else {
+ printlog(LOG_WARN, "0\n");
+ }
+
+ /* Print to the screen in debug mode. */
+ if (system_loglevel == LOG_DEBUG) {
+ printf("Local Rate: %d, Ideal Weight: %.3f, Local Weight: %.3f, Total Weight: %.3f\n",
+ table->rate, ideal_weight, ident->localweight, total_weight);
+ }
+}
+
+static uint32_t allocate_fps(identity_t *ident, double total_weight,
+ common_accounting_t *table, const char *identifier) {
+
+ uint32_t resulting_limit = 0;
+ double ideal_weight = 0.0;
+ double peer_weights = total_weight - ident->last_localweight;
+
+ /* Keep track of these for measurements & comparisons only. */
+ double ideal_under = 0.0;
+ double ideal_over = 0.0;
+
+ /* Weight sanity. */
+ if (peer_weights < 0.0) {
+ peer_weights = 0.0;