aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-03-15 14:27:16 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-03-15 14:27:16 +0000
commit7df1fa12d8761e9a08a2aecc1611c398a1663b6f (patch)
tree3c5b4014ea5e80c7a9b9f8a77e8c27631b5006d3 /src/transport
parentbfe1307e037a7811c2d9f86393554aa6ac09a957 (diff)
downloadgnunet-7df1fa12d8761e9a08a2aecc1611c398a1663b6f.tar.gz
gnunet-7df1fa12d8761e9a08a2aecc1611c398a1663b6f.zip
clean up
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport_manipulation.c28
-rw-r--r--src/transport/gnunet-service-transport_manipulation.h1
-rw-r--r--src/transport/test_transport_api_manipulation_recv_tcp.c2
-rw-r--r--src/transport/test_transport_api_manipulation_send_tcp.c4
-rw-r--r--src/transport/transport_api.c14
5 files changed, 38 insertions, 11 deletions
diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c
index c79176af0..3d9272c53 100644
--- a/src/transport/gnunet-service-transport_manipulation.c
+++ b/src/transport/gnunet-service-transport_manipulation.c
@@ -37,6 +37,14 @@
37#define DELAY 0 37#define DELAY 0
38#define DISTANCE 1 38#define DISTANCE 1
39 39
40
41enum TRAFFIC_METRIC_DIRECTION
42{
43 TM_SEND = 0,
44 TM_RECEIVE = 1,
45 TM_BOTH = 2
46};
47
40struct GST_ManipulationHandle man_handle; 48struct GST_ManipulationHandle man_handle;
41 49
42 50
@@ -175,6 +183,20 @@ GST_manipulation_set_metric (void *cls, struct GNUNET_SERVER_Client *client,
175 if (0 == ntohs (tm->ats_count)) 183 if (0 == ntohs (tm->ats_count))
176 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 184 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
177 185
186 switch (ntohs(tm->direction)) {
187 case 1:
188 direction = TM_SEND;
189 break;
190 case 2:
191 direction = TM_RECEIVE;
192 break;
193 case 3:
194 direction = TM_BOTH;
195 break;
196 default:
197 break;
198 }
199
178 memset (&dummy, '\0', sizeof (struct GNUNET_PeerIdentity)); 200 memset (&dummy, '\0', sizeof (struct GNUNET_PeerIdentity));
179 if (0 == memcmp (&tm->peer, &dummy, sizeof (struct GNUNET_PeerIdentity))) 201 if (0 == memcmp (&tm->peer, &dummy, sizeof (struct GNUNET_PeerIdentity)))
180 { 202 {
@@ -185,7 +207,7 @@ GST_manipulation_set_metric (void *cls, struct GNUNET_SERVER_Client *client,
185 { 207 {
186 type = htonl (ats[c].type); 208 type = htonl (ats[c].type);
187 value = htonl (ats[c].value); 209 value = htonl (ats[c].value);
188 direction = ntohs (tm->direction); 210
189 switch (type) { 211 switch (type) {
190 case GNUNET_ATS_QUALITY_NET_DELAY: 212 case GNUNET_ATS_QUALITY_NET_DELAY:
191 213
@@ -229,10 +251,10 @@ GST_manipulation_set_metric (void *cls, struct GNUNET_SERVER_Client *client,
229 value = htonl (ats[c].value); 251 value = htonl (ats[c].value);
230 switch (type) { 252 switch (type) {
231 case GNUNET_ATS_QUALITY_NET_DELAY: 253 case GNUNET_ATS_QUALITY_NET_DELAY:
232 set_delay (tmp, &tm->peer, ntohs (tm->direction), value); 254 set_delay (tmp, &tm->peer, direction, value);
233 break; 255 break;
234 case GNUNET_ATS_QUALITY_NET_DISTANCE: 256 case GNUNET_ATS_QUALITY_NET_DISTANCE:
235 set_distance (tmp, &tm->peer, ntohs (tm->direction), value); 257 set_distance (tmp, &tm->peer, direction, value);
236 break; 258 break;
237 default: 259 default:
238 break; 260 break;
diff --git a/src/transport/gnunet-service-transport_manipulation.h b/src/transport/gnunet-service-transport_manipulation.h
index 1ec75206b..e1ae2921e 100644
--- a/src/transport/gnunet-service-transport_manipulation.h
+++ b/src/transport/gnunet-service-transport_manipulation.h
@@ -36,6 +36,7 @@
36#include "gnunet-service-transport.h" 36#include "gnunet-service-transport.h"
37#include "transport.h" 37#include "transport.h"
38 38
39
39void 40void
40GST_manipulation_set_metric (void *cls, struct GNUNET_SERVER_Client *client, 41GST_manipulation_set_metric (void *cls, struct GNUNET_SERVER_Client *client,
41 const struct GNUNET_MessageHeader *message); 42 const struct GNUNET_MessageHeader *message);
diff --git a/src/transport/test_transport_api_manipulation_recv_tcp.c b/src/transport/test_transport_api_manipulation_recv_tcp.c
index 46215076f..efd4a481f 100644
--- a/src/transport/test_transport_api_manipulation_recv_tcp.c
+++ b/src/transport/test_transport_api_manipulation_recv_tcp.c
@@ -212,7 +212,7 @@ notify_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
212 ats[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); 212 ats[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
213 ats[1].value = htonl (10); 213 ats[1].value = htonl (10);
214 214
215 GNUNET_TRANSPORT_set_traffic_metric (p1->th, &p2->id, TM_RECEIVE, ats, 2); 215 GNUNET_TRANSPORT_set_traffic_metric (p1->th, &p2->id, GNUNET_YES, GNUNET_NO, ats, 2);
216 send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL); 216 send_task = GNUNET_SCHEDULER_add_now (&sendtask, NULL);
217 } 217 }
218 if (2 == messages_recv) 218 if (2 == messages_recv)
diff --git a/src/transport/test_transport_api_manipulation_send_tcp.c b/src/transport/test_transport_api_manipulation_send_tcp.c
index 2e40e9fcc..3ec7f7bf3 100644
--- a/src/transport/test_transport_api_manipulation_send_tcp.c
+++ b/src/transport/test_transport_api_manipulation_send_tcp.c
@@ -306,10 +306,10 @@ sendtask (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
306 { 306 {
307 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); 307 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY);
308 ats[0].value = htonl (1000); 308 ats[0].value = htonl (1000);
309 GNUNET_TRANSPORT_set_traffic_metric (p2->th, &p1->id, TM_SEND, ats, 1); 309 GNUNET_TRANSPORT_set_traffic_metric (p2->th, &p1->id, GNUNET_NO, GNUNET_YES, ats, 1);
310 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); 310 ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
311 ats[0].value = htonl (10); 311 ats[0].value = htonl (10);
312 GNUNET_TRANSPORT_set_traffic_metric (p1->th, &p2->id, TM_BOTH, ats, 1); 312 GNUNET_TRANSPORT_set_traffic_metric (p1->th, &p2->id, GNUNET_YES, GNUNET_YES, ats, 1);
313 313
314 start_delayed = GNUNET_TIME_absolute_get(); 314 start_delayed = GNUNET_TIME_absolute_get();
315 } 315 }
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c
index 16f821ab2..3b72ead5f 100644
--- a/src/transport/transport_api.c
+++ b/src/transport/transport_api.c
@@ -1213,7 +1213,8 @@ send_metric (void *cls, size_t size, void *buf)
1213 * 1213 *
1214 * @param handle transport handle 1214 * @param handle transport handle
1215 * @param peer the peer to set the metric for 1215 * @param peer the peer to set the metric for
1216 * @param direction can be: TM_SEND, TM_RECV, TM_BOTH 1216 * @param inbound set inbound direction (GNUNET_YES or GNUNET_NO)
1217 * @param outbound set outbound direction (GNUNET_YES or GNUNET_NO)
1217 * @param ats the metric as ATS information 1218 * @param ats the metric as ATS information
1218 * @param ats_count the number of metrics 1219 * @param ats_count the number of metrics
1219 * 1220 *
@@ -1236,7 +1237,8 @@ send_metric (void *cls, size_t size, void *buf)
1236void 1237void
1237GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle, 1238GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
1238 const struct GNUNET_PeerIdentity *peer, 1239 const struct GNUNET_PeerIdentity *peer,
1239 int direction, 1240 int inbound,
1241 int outbound,
1240 const struct GNUNET_ATS_Information *ats, 1242 const struct GNUNET_ATS_Information *ats,
1241 size_t ats_count) 1243 size_t ats_count)
1242{ 1244{
@@ -1244,9 +1246,11 @@ GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
1244 1246
1245 GNUNET_assert (NULL != handle); 1247 GNUNET_assert (NULL != handle);
1246 GNUNET_assert (NULL != peer); 1248 GNUNET_assert (NULL != peer);
1247 GNUNET_assert (direction >= TM_SEND); 1249 GNUNET_assert ((outbound == GNUNET_YES) || (outbound == GNUNET_NO));
1248 GNUNET_assert (direction <= TM_BOTH); 1250 GNUNET_assert ((inbound == GNUNET_YES) || (inbound == GNUNET_NO));
1249 1251
1252 if ((GNUNET_NO == inbound) && (GNUNET_NO == outbound))
1253 return;
1250 if (0 == ats_count) 1254 if (0 == ats_count)
1251 return; 1255 return;
1252 1256
@@ -1256,7 +1260,7 @@ GNUNET_TRANSPORT_set_traffic_metric (struct GNUNET_TRANSPORT_Handle *handle,
1256 msg = GNUNET_malloc (len); 1260 msg = GNUNET_malloc (len);
1257 msg->header.size = htons (len); 1261 msg->header.size = htons (len);
1258 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC); 1262 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_TRAFFIC_METRIC);
1259 msg->direction = htons (direction); 1263 msg->direction = htons (0 + outbound + 2 * inbound);
1260 msg->ats_count = htons (ats_count); 1264 msg->ats_count = htons (ats_count);
1261 msg->peer = (*peer); 1265 msg->peer = (*peer);
1262 memcpy (&msg[1], ats, ats_count * sizeof (struct GNUNET_ATS_Information)); 1266 memcpy (&msg[1], ats, ats_count * sizeof (struct GNUNET_ATS_Information));