diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-03-15 13:42:13 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-03-15 13:42:13 +0000 |
commit | 510fb496d9f55a279e366f6835240c35c2e4e1a6 (patch) | |
tree | 00b93eb57f7725c35fb43e8503a1f5ba6b324e58 /src/transport/gnunet-service-transport_manipulation.c | |
parent | efb9b0d1a203a6381eacf6905a4ae43014d8804b (diff) | |
download | gnunet-510fb496d9f55a279e366f6835240c35c2e4e1a6.tar.gz gnunet-510fb496d9f55a279e366f6835240c35c2e4e1a6.zip |
changes
Diffstat (limited to 'src/transport/gnunet-service-transport_manipulation.c')
-rw-r--r-- | src/transport/gnunet-service-transport_manipulation.c | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c index 5e52799df..c7594e394 100644 --- a/src/transport/gnunet-service-transport_manipulation.c +++ b/src/transport/gnunet-service-transport_manipulation.c | |||
@@ -54,6 +54,16 @@ struct GST_ManipulationHandle | |||
54 | */ | 54 | */ |
55 | struct GNUNET_TIME_Relative delay_out; | 55 | struct GNUNET_TIME_Relative delay_out; |
56 | 56 | ||
57 | /** | ||
58 | * General inbound distance | ||
59 | */ | ||
60 | unsigned long long distance_in; | ||
61 | |||
62 | /** | ||
63 | * General outbound distance | ||
64 | */ | ||
65 | unsigned long long distance_out; | ||
66 | |||
57 | }; | 67 | }; |
58 | 68 | ||
59 | 69 | ||
@@ -153,16 +163,48 @@ GST_manipulation_set_metric (void *cls, struct GNUNET_SERVER_Client *client, | |||
153 | const struct GNUNET_MessageHeader *message) | 163 | const struct GNUNET_MessageHeader *message) |
154 | { | 164 | { |
155 | struct TrafficMetricMessage *tm = (struct TrafficMetricMessage *) message; | 165 | struct TrafficMetricMessage *tm = (struct TrafficMetricMessage *) message; |
166 | struct GNUNET_PeerIdentity dummy; | ||
156 | struct GNUNET_ATS_Information *ats; | 167 | struct GNUNET_ATS_Information *ats; |
157 | struct TM_Peer *tmp; | 168 | struct TM_Peer *tmp; |
158 | uint32_t type; | 169 | uint32_t type; |
159 | uint32_t value; | 170 | uint32_t value; |
171 | uint16_t direction; | ||
160 | int c; | 172 | int c; |
161 | int c2; | 173 | int c2; |
162 | 174 | ||
163 | if (0 == ntohs (tm->ats_count)) | 175 | if (0 == ntohs (tm->ats_count)) |
164 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 176 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
165 | 177 | ||
178 | memset (&dummy, '\0', sizeof (struct GNUNET_PeerIdentity)); | ||
179 | if (0 == memcmp (&tm->peer, &dummy, sizeof (struct GNUNET_PeerIdentity))) | ||
180 | { | ||
181 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received traffic metrics for all peers \n"); | ||
182 | |||
183 | ats = (struct GNUNET_ATS_Information *) &tm[1]; | ||
184 | for (c = 0; c < ntohs (tm->ats_count); c++) | ||
185 | { | ||
186 | type = htonl (ats[c].type); | ||
187 | value = htonl (ats[c].value); | ||
188 | direction = ntohs (tm->direction); | ||
189 | switch (type) { | ||
190 | case GNUNET_ATS_QUALITY_NET_DELAY: | ||
191 | |||
192 | if ((TM_RECEIVE == direction) || (TM_BOTH == direction)) | ||
193 | man_handle.delay_in.rel_value = value; | ||
194 | if ((TM_SEND == direction) || (TM_BOTH == direction)) | ||
195 | man_handle.delay_out.rel_value = value; | ||
196 | break; | ||
197 | case GNUNET_ATS_QUALITY_NET_DISTANCE: | ||
198 | |||
199 | break; | ||
200 | default: | ||
201 | break; | ||
202 | } | ||
203 | |||
204 | } | ||
205 | return; | ||
206 | } | ||
207 | |||
166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received traffic metrics for peer `%s'\n", | 208 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received traffic metrics for peer `%s'\n", |
167 | GNUNET_i2s(&tm->peer)); | 209 | GNUNET_i2s(&tm->peer)); |
168 | 210 | ||
@@ -290,14 +332,25 @@ GST_manipulation_recv (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
290 | struct GNUNET_ATS_Information ats_new[ats_count]; | 332 | struct GNUNET_ATS_Information ats_new[ats_count]; |
291 | struct GNUNET_TIME_Relative quota_delay; | 333 | struct GNUNET_TIME_Relative quota_delay; |
292 | struct GNUNET_TIME_Relative m_delay; | 334 | struct GNUNET_TIME_Relative m_delay; |
335 | uint32_t m_distance; | ||
293 | 336 | ||
294 | if (man_handle.delay_in.rel_value > GNUNET_TIME_UNIT_ZERO.rel_value) | 337 | if (man_handle.delay_in.rel_value > GNUNET_TIME_UNIT_ZERO.rel_value) |
295 | m_delay = man_handle.delay_in; /* Global delay */ | 338 | m_delay = man_handle.delay_in; /* Global delay */ |
296 | else | 339 | else |
297 | m_delay = GNUNET_TIME_UNIT_ZERO; | 340 | m_delay = GNUNET_TIME_UNIT_ZERO; |
298 | 341 | ||
342 | if (man_handle.distance_in > 0) | ||
343 | m_distance = man_handle.distance_in; /* Global distance */ | ||
344 | else | ||
345 | m_distance = 0; | ||
346 | |||
299 | for (d = 0; d < ats_count; d++) | 347 | for (d = 0; d < ats_count; d++) |
348 | { | ||
300 | ats_new[d] = ats[d]; | 349 | ats_new[d] = ats[d]; |
350 | if ((ntohl(ats[d].type) == GNUNET_ATS_QUALITY_NET_DISTANCE) && | ||
351 | (man_handle.distance_in > 0)) | ||
352 | ats_new[d].value = htonl(man_handle.distance_in); /* Global inbound distance */ | ||
353 | } | ||
301 | 354 | ||
302 | if (NULL != (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &peer->hashPubKey))) | 355 | if (NULL != (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &peer->hashPubKey))) |
303 | { | 356 | { |
@@ -327,6 +380,20 @@ void | |||
327 | GST_manipulation_init (const struct GNUNET_CONFIGURATION_Handle *GST_cfg) | 380 | GST_manipulation_init (const struct GNUNET_CONFIGURATION_Handle *GST_cfg) |
328 | { | 381 | { |
329 | 382 | ||
383 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (GST_cfg, | ||
384 | "transport", "MANIPULATE_DISTANCE_IN", &man_handle.distance_in)) | ||
385 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Setting inbound distance_in to %u\n", | ||
386 | (unsigned long long) man_handle.distance_in); | ||
387 | else | ||
388 | man_handle.distance_in = 0; | ||
389 | |||
390 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_number (GST_cfg, | ||
391 | "transport", "MANIPULATE_DISTANCE_OUT", &man_handle.distance_out)) | ||
392 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Setting outbound distance_in to %u\n", | ||
393 | (unsigned long long) man_handle.distance_out); | ||
394 | else | ||
395 | man_handle.distance_out = 0; | ||
396 | |||
330 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (GST_cfg, | 397 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (GST_cfg, |
331 | "transport", "MANIPULATE_DELAY_IN", &man_handle.delay_in)) | 398 | "transport", "MANIPULATE_DELAY_IN", &man_handle.delay_in)) |
332 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Delaying inbound traffic for %llu ms\n", | 399 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Delaying inbound traffic for %llu ms\n", |