From a27249cf6b80518b9b6f8edfb322a0820bead1b8 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Thu, 24 Mar 2011 11:05:01 +0000 Subject: [PATCH] clean up and changes --- src/transport/gnunet-service-transport.c | 154 ++++++++++++++++------- src/transport/transport.h | 12 +- 2 files changed, 118 insertions(+), 48 deletions(-) diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 919192e46..bb20fb612 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -55,6 +55,8 @@ #define DEBUG_ATS GNUNET_YES #endif +#define VERBOSE_ATS GNUNET_NO + /** * Should we do some additional checks (to validate behavior * of clients)? @@ -944,20 +946,20 @@ static void try_transmission_to_peer (struct NeighbourList *n); struct ATS_info * ats_init (); -void ats_shutdown (struct ATS_info * ats); +void ats_shutdown ( ); -void ats_notify_peer_connect (struct ATS_info * ats, +void ats_notify_peer_connect ( const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TRANSPORT_ATS_Information *ats_data); -void ats_notify_peer_disconnect (struct ATS_info * ats, +void ats_notify_peer_disconnect ( const struct GNUNET_PeerIdentity *peer); -void ats_notify_ats_data (struct ATS_info * ats, +void ats_notify_ats_data ( const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TRANSPORT_ATS_Information *ats_data); -struct ForeignAddressList * ats_get_preferred_address (struct ATS_info * ats, +struct ForeignAddressList * ats_get_preferred_address ( struct NeighbourList *n); /** @@ -1682,7 +1684,7 @@ try_transmission_to_peer (struct NeighbourList *n) if (mq->specific_address == NULL) { /* TODO: ADD ATS */ - mq->specific_address = ats_get_preferred_address(ats, n); + mq->specific_address = ats_get_preferred_address(n); GNUNET_STATISTICS_update (stats, gettext_noop ("# transport selected peer address freely"), 1, @@ -2317,7 +2319,7 @@ notify_clients_connect (const struct GNUNET_PeerIdentity *peer, memcpy (&cim->id, peer, sizeof (struct GNUNET_PeerIdentity)); /* notify ats about connecting peer */ - ats_notify_peer_connect(ats, peer, &(cim->ats)); + ats_notify_peer_connect (peer, &(cim->ats)); cpos = clients; while (cpos != NULL) @@ -2354,7 +2356,7 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer) memcpy (&dim.peer, peer, sizeof (struct GNUNET_PeerIdentity)); /* notify ats about connecting peer */ - ats_notify_peer_disconnect(ats, peer); + ats_notify_peer_disconnect (peer); cpos = clients; while (cpos != NULL) @@ -4829,8 +4831,7 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer, } } /* notify ATS about incoming data */ - ats_notify_ats_data(ats, peer, ats_data); - + ats_notify_ats_data(peer, ats_data); if (message != NULL) { @@ -5565,7 +5566,7 @@ struct ATS_transports #define FUNCTION ats_create_problem (int peers, int transports, double b_min, double b_max, double r, double R, const struct ATS_peer * pl, const struct ATS_transports * tl, int max_it, int max_dur) -#if HAVE_LIBGLPK + glp_prob * FUNCTION { int result = GLP_UNDEF; @@ -5583,28 +5584,32 @@ glp_prob * FUNCTION double ar[1+(rows*cols)]; double value; - /* Setting options */ + /* Setting GLPK options */ glp_smcp * options = GNUNET_malloc( sizeof (glp_smcp)); glp_init_smcp(options); - // max iterations + /* maximum iterations */ options->it_lim = max_it; - // max durations + /* maximum durations */ options->tm_lim = max_dur; - options->msg_lev = GLP_MSG_ALL; + /* output level */ + if (VERBOSE_ATS) + options->msg_lev = GLP_MSG_ALL; + else + options->msg_lev = GLP_MSG_OFF; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating LP problem: %i peers, relativity r %3.2f, b_max %5.2f, b_min %5.2f, \n",peers, r, b_max, b_min); + if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Creating LP problem: %i peers, relativity r %3.2f, b_max %5.2f, b_min %5.2f, \n",peers, r, b_max, b_min); lp = glp_create_prob(); glp_set_prob_name(lp, "gnunet ats bandwidth distribution"); glp_set_obj_dir(lp, GLP_MAX); - /* Adding transports */ + /* Adding transports and objective function coefficients*/ glp_add_cols(lp, cols); for (c1=1; c1<=cols; c1++) { GNUNET_asprintf(&peer_n,"%s",GNUNET_i2s(&pl[c1-1].peer)); - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer[%i] , transport %i, %s: f: %f\n",c1-1 , pl[c1-1].t, peer_n, pl[c1-1].f); - /* add a single transport */ + if (DEBUG_ATS) GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer[%i] , transport %i, %s: f: %f\n",c1-1 , pl[c1-1].t, peer_n, pl[c1-1].f); + /* add a single transport*/ glp_set_col_name(lp, c1, peer_n); /* add a lower bound */ glp_set_col_bnds(lp, c1, GLP_LO, 0.0, 0.0); @@ -5615,19 +5620,22 @@ glp_prob * FUNCTION GNUNET_free(peer_n); } - /* Adding constraints */ glp_add_rows(lp, rows); cur_row = 1; - // GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i \n", cur_row); + /* constraint 1: Maximum bandwidth for all peers + * sum(b_i) <= b_max + */ glp_set_row_bnds(lp, cur_row, GLP_UP, 0.0, b_max); for (index=1; index<=cols; index++) { ia[index] = 1, ja[index] = index, ar[index] = 1.0; } - + /* constraint 2: Maximum bandwidth per peer + * V b_i in B: b_i <= b_max + */ cur_row = 2; start = index+1; for (c1=0; c1= b_min + */ start = index+1; for (c1=0; c1= b_min + */ start = index+1; for (c1=0; c1last,GNUNET_TIME_absolute_get()); if (delta.rel_value < ats->min_delta.rel_value) @@ -5737,9 +5800,6 @@ void ats_calculate_bandwidth_distribution (struct ATS_info * ats) #endif return; } -#if DEBUG_ATS - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CALCULATE DISTRIBUTION\n"); -#endif int peers = 3; int transports = 3; @@ -5808,7 +5868,7 @@ ats_schedule_calculation (void *cls, #endif ats_calculate_bandwidth_distribution (ats); - ats->ats_task = GNUNET_SCHEDULER_add_delayed (ats->reg_delta, + ats->ats_task = GNUNET_SCHEDULER_add_delayed (ats->exec_intervall, &ats_schedule_calculation, ats); } @@ -5840,7 +5900,7 @@ struct ATS_info * ats_init () GNUNET_assert(ats->peers!=NULL); ats->min_delta = ATS_MIN_INTERVAL; - ats->reg_delta = ATS_EXEC_INTERVAL; + ats->exec_intervall = ATS_EXEC_INTERVAL; ats->ats_task = GNUNET_SCHEDULER_NO_TASK; /* @@ -5856,7 +5916,7 @@ struct ATS_info * ats_init () } -void ats_shutdown (struct ATS_info * ats) +void ats_shutdown () { #if DEBUG_ATS GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ats_destroy\n"); @@ -5871,7 +5931,7 @@ void ats_shutdown (struct ATS_info * ats) } -void ats_notify_peer_connect (struct ATS_info * ats, +void ats_notify_peer_connect ( const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TRANSPORT_ATS_Information *ats_data) { @@ -5898,7 +5958,7 @@ void ats_notify_peer_connect (struct ATS_info * ats, ats_calculate_bandwidth_distribution(ats); } -void ats_notify_peer_disconnect (struct ATS_info * ats, +void ats_notify_peer_disconnect ( const struct GNUNET_PeerIdentity *peer) { #if DEBUG_ATS @@ -5915,7 +5975,7 @@ void ats_notify_peer_disconnect (struct ATS_info * ats, } -void ats_notify_ats_data (struct ATS_info * ats, +void ats_notify_ats_data ( const struct GNUNET_PeerIdentity *peer, const struct GNUNET_TRANSPORT_ATS_Information *ats_data) { @@ -5925,7 +5985,7 @@ void ats_notify_ats_data (struct ATS_info * ats, ats_calculate_bandwidth_distribution(ats); } -struct ForeignAddressList * ats_get_preferred_address (struct ATS_info * ats, +struct ForeignAddressList * ats_get_preferred_address ( struct NeighbourList *n) { #if DEBUG_ATS diff --git a/src/transport/transport.h b/src/transport/transport.h index bfe9bc094..314a5c2bf 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h @@ -40,8 +40,18 @@ struct ATS_info { struct GNUNET_CONTAINER_MultiHashMap * peers; struct GNUNET_TIME_Absolute last; + /** + * Minimum intervall between two executions + */ struct GNUNET_TIME_Relative min_delta; - struct GNUNET_TIME_Relative reg_delta; + /** + * Regular intervall when execution is triggered + */ + struct GNUNET_TIME_Relative exec_intervall; + /** + * Maximum execution time per calculation + */ + struct GNUNET_TIME_Relative max_exec_duration; GNUNET_SCHEDULER_TaskIdentifier ats_task; }; -- 2.25.1