aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am8
-rw-r--r--src/transport/gnunet-service-transport.c179
-rw-r--r--src/transport/test_transport_ats.c12
-rw-r--r--src/transport/transport.h5
4 files changed, 195 insertions, 9 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 13db3b5c2..43c4692b5 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -105,6 +105,10 @@ gnunet_transport_LDADD = \
105gnunet_transport_DEPENDENCIES = \ 105gnunet_transport_DEPENDENCIES = \
106 libgnunettransport.la 106 libgnunettransport.la
107 107
108if HAVE_GLPK
109 GN_GLPK = -lglpk
110endif
111
108gnunet_service_transport_SOURCES = \ 112gnunet_service_transport_SOURCES = \
109 gnunet-service-transport.c 113 gnunet-service-transport.c
110gnunet_service_transport_LDADD = \ 114gnunet_service_transport_LDADD = \
@@ -112,10 +116,10 @@ gnunet_service_transport_LDADD = \
112 $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \ 116 $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
113 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 117 $(top_builddir)/src/statistics/libgnunetstatistics.la \
114 $(top_builddir)/src/util/libgnunetutil.la \ 118 $(top_builddir)/src/util/libgnunetutil.la \
119 $(GN_GLPK) \
115 $(GN_LIBINTL) 120 $(GN_LIBINTL)
116gnunet_service_transport_DEPENDENCIES = \ 121gnunet_service_transport_DEPENDENCIES = \
117 libgnunettransport.la 122 libgnunettransport.la
118
119 123
120plugin_LTLIBRARIES = \ 124plugin_LTLIBRARIES = \
121 libgnunet_plugin_transport_tcp.la \ 125 libgnunet_plugin_transport_tcp.la \
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index 1a5d0af4b..ba9cdfbc6 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -38,6 +38,9 @@
38#include "gnunet_signatures.h" 38#include "gnunet_signatures.h"
39#include "gnunet_transport_plugin.h" 39#include "gnunet_transport_plugin.h"
40#include "transport.h" 40#include "transport.h"
41#if HAVE_GLPK
42#include <glpk.h>
43#endif
41 44
42#define DEBUG_BLACKLIST GNUNET_YES 45#define DEBUG_BLACKLIST GNUNET_YES
43 46
@@ -5546,6 +5549,153 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
5546 GNUNET_break (bc_head == NULL); 5549 GNUNET_break (bc_head == NULL);
5547} 5550}
5548 5551
5552
5553
5554#if HAVE_GLPK
5555
5556glp_prob * ats_create_problem(int peers, double b_min, double b_max, double r, const struct ATS_peer * list, int max_it, int max_dur)
5557{
5558 int c1, c2;
5559 glp_prob *lp;
5560 char * transport;
5561
5562 int rows = 1 + peers + peers + peers;
5563 int cols = peers;
5564 int index = 1;
5565 int start = 0;
5566 int cur_row = 0;
5567
5568 int ia[1+(rows*cols)], ja[1+(rows*cols)];
5569 double ar[1+(rows*cols)];
5570 double value;
5571
5572 /* Setting options */
5573/* glp_smcp * options = GNUNET_malloc( sizeof (glp_smcp));
5574 // max iterations
5575 options->it_lim = max_it;
5576 // max durations
5577 options->tm_lim = max_it;
5578 options->msg_lev = GLP_MSG_OFF;
5579 options->meth = GLP_PRIMAL;
5580 options->pricing = GLP_PT_PSE;
5581 options->r_test = GLP_RT_HAR;
5582 options->tol_bnd =
5583*/
5584
5585 lp = glp_create_prob();
5586 glp_set_prob_name(lp, "gnunet ats bandwidth distribution");
5587 glp_set_obj_dir(lp, GLP_MAX);
5588
5589 /* Adding transports */
5590 glp_add_cols(lp, cols);
5591 for (c1=1; c1<=cols; c1++)
5592 {
5593 GNUNET_asprintf(&transport,"Peer %s",GNUNET_i2s(&list[c1-1].peer));
5594 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ats_create_problem Peer[%i] : %s \n",c1-1 , transport);
5595 /* add a single transport */
5596 glp_set_col_name(lp, c1, transport);
5597 /* add a lower bound */
5598 glp_set_col_bnds(lp, c1, GLP_LO, 0.0, 0.0);
5599 /* set coefficient function */
5600 glp_set_obj_coef(lp, c1, 1.0);
5601 GNUNET_free(transport);
5602 }
5603
5604
5605 /* Adding constraints */
5606 glp_add_rows(lp, rows);
5607 cur_row = 1;
5608
5609 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i \n", cur_row);
5610 glp_set_row_bnds(lp, cur_row, GLP_UP, 0.0, b_max);
5611 for (index=1; index<=cols; index++)
5612 {
5613 ia[index] = 1, ja[index] = index, ar[index] = 1.0;
5614 }
5615
5616
5617 cur_row = 2;
5618 start = index+1;
5619 for (c1=0; c1<peers; c1++)
5620 {
5621 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i \n", cur_row);
5622 glp_set_row_bnds(lp, cur_row , GLP_UP, 0.0, b_max);
5623
5624 for (c2 = 1; c2 <= cols; c2++)
5625 {
5626 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "c1: %i c2 %i index: %i \n",c1 , c2, index);
5627 ia[index] = cur_row;
5628 ja[index] = c2;
5629 ar[index] = ((c1+1 == c2) ? 1.0 : 0.0);
5630 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ia: %i ja %i ar: %f \n",cur_row , c2, ((c1+1 == c2) ? 1.0 : 0.0));
5631 index++;
5632 }
5633 cur_row++;
5634 }
5635
5636 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CONST 3 \n");
5637
5638 start = index+1;
5639 for (c1=0; c1<peers; c1++)
5640 {
5641 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i \n", cur_row);
5642 glp_set_row_bnds(lp, cur_row , GLP_LO, b_min, 0.0);
5643
5644 for (c2 = 1; c2 <= cols; c2++)
5645 {
5646 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "c1: %i c2 %i index: %i \n",c1 , c2, index);
5647 ia[index] = cur_row;
5648 ja[index] = c2;
5649 ar[index] = ((c1+1 == c2) ? 1.0 : 0.0);
5650 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ia: %i ja %i ar: %f \n",cur_row , c2, ((c1+1 == c2) ? 1.0 : 0.0));
5651 index++;
5652 }
5653 cur_row++;
5654 }
5655
5656 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CONST 4 \n");
5657
5658 start = index+1;
5659 for (c1=0; c1<peers; c1++)
5660 {
5661
5662 value = list[c1].f * r;
5663 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "row: %i %f\n", cur_row, value);
5664 glp_set_row_bnds(lp, cur_row , GLP_LO, value, 0.0);
5665
5666 for (c2 = 1; c2 <= cols; c2++)
5667 {
5668 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "c1: %i c2 %i index: %i \n",c1 , c2, index);
5669 ia[index] = cur_row;
5670 ja[index] = c2;
5671 ar[index] = ((c1+1 == c2) ? (1.0/b_max) : 0.0);
5672 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ia: %i ja %i ar: %f \n",cur_row , c2, ((c1+1 == c2) ? 1.0 : 0.0));
5673 index++;
5674 }
5675 cur_row++;
5676 }
5677
5678 glp_load_matrix(lp, rows * cols, ia, ja, ar);
5679
5680 glp_simplex(lp, NULL);
5681
5682
5683 printf("z = %g; ", glp_get_obj_val(lp));
5684 for (c1=1; c1<= peers; c1++ )
5685 {
5686 printf("x%i = %g; ", c1, glp_get_col_prim(lp, c1));
5687 }
5688 glp_delete_prob(lp);
5689 //GNUNET_free(options);
5690 return lp;
5691}
5692#else
5693void ats_create_problem(int peers, double b_min, double b_max, double r, const struct ATS_peer * list, int max_it, int max_dur)
5694{
5695
5696}
5697#endif
5698
5549void ats_calculate_bandwidth_distribution (struct ATS_info * ats) 5699void ats_calculate_bandwidth_distribution (struct ATS_info * ats)
5550{ 5700{
5551 struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(ats->last,GNUNET_TIME_absolute_get()); 5701 struct GNUNET_TIME_Relative delta = GNUNET_TIME_absolute_get_difference(ats->last,GNUNET_TIME_absolute_get());
@@ -5559,6 +5709,29 @@ void ats_calculate_bandwidth_distribution (struct ATS_info * ats)
5559#if DEBUG_ATS 5709#if DEBUG_ATS
5560 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CALCULATE DISTRIBUTION\n"); 5710 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "CALCULATE DISTRIBUTION\n");
5561#endif 5711#endif
5712
5713 int transports = 9;
5714 double b_min = 10;
5715 double b_max = 100.0;
5716 double r = 0.8;
5717
5718 int it = 50;
5719 int dur = 500;
5720
5721 struct ATS_peer * list = GNUNET_malloc(transports * sizeof (struct ATS_peer));
5722 int c = 0;
5723 while (c < transports)
5724 {
5725 list[c].peer.hashPubKey.bits[0] = c+1;
5726 list[c].f = 1 / (double) transports;
5727 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "ats_calculate_bandwidth_distribution Peer[%i] : %s %p \n",c , GNUNET_i2s(&list[c].peer), &list[c].peer);
5728 c++;
5729 }
5730
5731 ats_create_problem(transports, b_min, b_max, r, list, it, dur);
5732
5733 GNUNET_free (list);
5734
5562 ats->last = GNUNET_TIME_absolute_get(); 5735 ats->last = GNUNET_TIME_absolute_get();
5563 5736
5564} 5737}
@@ -5780,6 +5953,12 @@ run (void *cls,
5780 validation_map = NULL; 5953 validation_map = NULL;
5781 return; 5954 return;
5782 } 5955 }
5956#if HAVE_GLPK
5957 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("HAVE\n"));
5958#else
5959 //GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("NOT HAVE\n"));
5960#endif
5961
5783 ats = ats_init(); 5962 ats = ats_init();
5784 max_connect_per_transport = (uint32_t) tneigh; 5963 max_connect_per_transport = (uint32_t) tneigh;
5785 peerinfo = GNUNET_PEERINFO_connect (cfg); 5964 peerinfo = GNUNET_PEERINFO_connect (cfg);
diff --git a/src/transport/test_transport_ats.c b/src/transport/test_transport_ats.c
index 2d3321a9e..0f80807f6 100644
--- a/src/transport/test_transport_ats.c
+++ b/src/transport/test_transport_ats.c
@@ -45,7 +45,7 @@
45/** 45/**
46 * How long until we give up on transmitting the message? 46 * How long until we give up on transmitting the message?
47 */ 47 */
48#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90) 48#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
49 49
50/** 50/**
51 * How long until we give up on transmitting the message? 51 * How long until we give up on transmitting the message?
@@ -138,7 +138,7 @@ end_badly ()
138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n"); 138 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Disconnecting from transports!\n");
139 GNUNET_break (0); 139 GNUNET_break (0);
140 GNUNET_TRANSPORT_disconnect (p1.th); 140 GNUNET_TRANSPORT_disconnect (p1.th);
141 GNUNET_TRANSPORT_disconnect (p2.th); 141 //GNUNET_TRANSPORT_disconnect (p2.th);
142 ok = 1; 142 ok = 1;
143} 143}
144 144
@@ -367,11 +367,11 @@ run (void *cls,
367 &end_badly, NULL); 367 &end_badly, NULL);
368 368
369 setup_peer (&p1, "test_transport_ats_peer1.conf"); 369 setup_peer (&p1, "test_transport_ats_peer1.conf");
370 setup_peer (&p2, "test_transport_ats_peer2.conf"); 370 //setup_peer (&p2, "test_transport_ats_peer2.conf");
371 371
372 GNUNET_assert(p1.th != NULL); 372 GNUNET_assert(p1.th != NULL);
373 GNUNET_assert(p2.th != NULL); 373 //GNUNET_assert(p2.th != NULL);
374 374 return;
375 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); 375 GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1);
376} 376}
377 377
@@ -398,7 +398,7 @@ check ()
398 argv, "test-transport-api", "nohelp", 398 argv, "test-transport-api", "nohelp",
399 options, &run, &ok); 399 options, &run, &ok);
400 stop_arm (&p1); 400 stop_arm (&p1);
401 stop_arm (&p2); 401 // stop_arm (&p2);
402 402
403 if (is_https) 403 if (is_https)
404 { 404 {
diff --git a/src/transport/transport.h b/src/transport/transport.h
index dc9e7ce58..7dc96de68 100644
--- a/src/transport/transport.h
+++ b/src/transport/transport.h
@@ -34,7 +34,7 @@
34#define ATS_MIN_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,250) 34#define ATS_MIN_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS,250)
35#define ATS_EXEC_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,1) 35#define ATS_EXEC_INTERVAL GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,1)
36 36
37#define DEBUG_ATS GNUNET_NO 37#define DEBUG_ATS GNUNET_YES
38 38
39struct ATS_info 39struct ATS_info
40{ 40{
@@ -49,6 +49,9 @@ struct ATS_info
49struct ATS_peer 49struct ATS_peer
50{ 50{
51 struct GNUNET_PeerIdentity peer; 51 struct GNUNET_PeerIdentity peer;
52 struct NeighbourList * n;
53 double f;
54 int t;
52}; 55};
53 56
54#define DEBUG_TRANSPORT GNUNET_NO 57#define DEBUG_TRANSPORT GNUNET_NO