aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-03-15 09:53:24 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-03-15 09:53:24 +0000
commit08cd1ab49a879b8c8357d3bc60fe05deaeb929c9 (patch)
tree79d53b230f3fd0bc3e4a5d74126b7cf177487067 /src/transport
parent08d2455de7350963a135c336c23414c8fcdf7ca6 (diff)
downloadgnunet-08cd1ab49a879b8c8357d3bc60fe05deaeb929c9.tar.gz
gnunet-08cd1ab49a879b8c8357d3bc60fe05deaeb929c9.zip
changes to manipulation
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport.c2
-rw-r--r--src/transport/gnunet-service-transport_manipulation.c78
-rw-r--r--src/transport/gnunet-service-transport_manipulation.h2
3 files changed, 68 insertions, 14 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index bd1576d25..b167a7d93 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -667,7 +667,7 @@ key_generation_cb (void *cls,
667 GST_blacklist_start (GST_server); 667 GST_blacklist_start (GST_server);
668 GST_ats = 668 GST_ats =
669 GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL); 669 GNUNET_ATS_scheduling_init (GST_cfg, &ats_request_address_change, NULL);
670 GST_manipulation_init (); 670 GST_manipulation_init (GST_cfg);
671 GST_plugins_load (&GST_manipulation_recv, 671 GST_plugins_load (&GST_manipulation_recv,
672 &plugin_env_address_change_notification, 672 &plugin_env_address_change_notification,
673 &plugin_env_session_end, 673 &plugin_env_session_end,
diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c
index 34c8ab173..fa8621e3d 100644
--- a/src/transport/gnunet-service-transport_manipulation.c
+++ b/src/transport/gnunet-service-transport_manipulation.c
@@ -34,13 +34,33 @@
34#include "gnunet-service-transport.h" 34#include "gnunet-service-transport.h"
35#include "transport.h" 35#include "transport.h"
36 36
37static struct GNUNET_CONTAINER_MultiHashMap *peers;
38
39#define DELAY 0 37#define DELAY 0
40#define DISTANCE 1 38#define DISTANCE 1
41 39
40struct GST_ManipulationHandle man_handle;
41
42
43struct GST_ManipulationHandle
44{
45 struct GNUNET_CONTAINER_MultiHashMap *peers;
46
47 /**
48 * General inbound delay
49 */
50 struct GNUNET_TIME_Relative delay_in;
51
52 /**
53 * General outbound delay
54 */
55 struct GNUNET_TIME_Relative delay_out;
56
57};
58
59
42struct TM_Peer; 60struct TM_Peer;
43 61
62
63
44struct DelayQueueEntry 64struct DelayQueueEntry
45{ 65{
46 struct DelayQueueEntry *prev; 66 struct DelayQueueEntry *prev;
@@ -146,7 +166,7 @@ GST_manipulation_set_metric (void *cls, struct GNUNET_SERVER_Client *client,
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received traffic metrics for peer `%s'\n", 166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received traffic metrics for peer `%s'\n",
147 GNUNET_i2s(&tm->peer)); 167 GNUNET_i2s(&tm->peer));
148 168
149 if (NULL == (tmp = GNUNET_CONTAINER_multihashmap_get (peers, &tm->peer.hashPubKey))) 169 if (NULL == (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &tm->peer.hashPubKey)))
150 { 170 {
151 tmp = GNUNET_malloc (sizeof (struct TM_Peer)); 171 tmp = GNUNET_malloc (sizeof (struct TM_Peer));
152 tmp->peer = (tm->peer); 172 tmp->peer = (tm->peer);
@@ -157,7 +177,7 @@ GST_manipulation_set_metric (void *cls, struct GNUNET_SERVER_Client *client,
157 tmp->metrics[c][c2] = UINT32_MAX; 177 tmp->metrics[c][c2] = UINT32_MAX;
158 } 178 }
159 } 179 }
160 GNUNET_CONTAINER_multihashmap_put (peers, &tm->peer.hashPubKey, tmp, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); 180 GNUNET_CONTAINER_multihashmap_put (man_handle.peers, &tm->peer.hashPubKey, tmp, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
161 } 181 }
162 182
163 ats = (struct GNUNET_ATS_Information *) &tm[1]; 183 ats = (struct GNUNET_ATS_Information *) &tm[1];
@@ -211,7 +231,7 @@ GST_manipulation_send (const struct GNUNET_PeerIdentity *target, const void *msg
211 struct DelayQueueEntry *dqe; 231 struct DelayQueueEntry *dqe;
212 struct GNUNET_TIME_Relative delay; 232 struct GNUNET_TIME_Relative delay;
213 233
214 if (NULL != (tmp = GNUNET_CONTAINER_multihashmap_get (peers, &target->hashPubKey))) 234 if (NULL != (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &target->hashPubKey)))
215 { 235 {
216 /* Manipulate here */ 236 /* Manipulate here */
217 /* Delay */ 237 /* Delay */
@@ -234,6 +254,25 @@ GST_manipulation_send (const struct GNUNET_PeerIdentity *target, const void *msg
234 return; 254 return;
235 } 255 }
236 } 256 }
257 else if (man_handle.delay_out.rel_value != 0)
258 {
259 /* We have a delay */
260 delay = man_handle.delay_out;
261 dqe = GNUNET_malloc (sizeof (struct DelayQueueEntry) + msg_size);
262 dqe->tmp = tmp;
263 dqe->sent_at = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), delay);
264 dqe->cont = cont;
265 dqe->cont_cls = cont_cls;
266 dqe->msg = &dqe[1];
267 dqe->msg_size = msg_size;
268 dqe->timeout = timeout;
269 memcpy (dqe->msg, msg, msg_size);
270 GNUNET_CONTAINER_DLL_insert_tail (tmp->send_head, tmp->send_tail, dqe);
271 if (GNUNET_SCHEDULER_NO_TASK == tmp->send_delay_task)
272 tmp->send_delay_task =GNUNET_SCHEDULER_add_delayed (delay, &send_delayed, dqe);
273 return;
274 }
275
237 /* Normal sending */ 276 /* Normal sending */
238 GST_neighbours_send (target, msg, msg_size, timeout, cont, cont_cls); 277 GST_neighbours_send (target, msg, msg_size, timeout, cont, cont_cls);
239} 278}
@@ -254,7 +293,7 @@ GST_manipulation_recv (void *cls, const struct GNUNET_PeerIdentity *peer,
254 293
255 for (d = 0; d < ats_count; d++) 294 for (d = 0; d < ats_count; d++)
256 295
257 if (NULL != (tmp = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey))) 296 if (NULL != (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &peer->hashPubKey)))
258 { 297 {
259 /* Manipulate distance */ 298 /* Manipulate distance */
260 for (d = 0; d < ats_count; d++) 299 for (d = 0; d < ats_count; d++)
@@ -291,9 +330,24 @@ GST_manipulation_recv (void *cls, const struct GNUNET_PeerIdentity *peer,
291} 330}
292 331
293void 332void
294GST_manipulation_init () 333GST_manipulation_init (const struct GNUNET_CONFIGURATION_Handle *GST_cfg)
295{ 334{
296 peers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); 335
336 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (GST_cfg,
337 "transport", "MANIPULATE_DELAY_IN", &man_handle.delay_in))
338 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Delaying inbound traffic for %llu ms\n",
339 (unsigned long long) man_handle.delay_in.rel_value);
340 else
341 man_handle.delay_in.rel_value = 0;
342
343 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_time (GST_cfg,
344 "transport", "MANIPULATE_DELAY_OUT", &man_handle.delay_out))
345 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Delaying outbound traffic for %llu ms\n",
346 (unsigned long long) man_handle.delay_out.rel_value);
347 else
348 man_handle.delay_out.rel_value = 0;
349
350 man_handle.peers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
297} 351}
298 352
299int free_tmps (void *cls, 353int free_tmps (void *cls,
@@ -305,7 +359,7 @@ int free_tmps (void *cls,
305 if (NULL != value) 359 if (NULL != value)
306 { 360 {
307 struct TM_Peer *tmp = (struct TM_Peer *) value; 361 struct TM_Peer *tmp = (struct TM_Peer *) value;
308 GNUNET_CONTAINER_multihashmap_remove (peers, key, value); 362 GNUNET_CONTAINER_multihashmap_remove (man_handle.peers, key, value);
309 next = tmp->send_head; 363 next = tmp->send_head;
310 while (NULL != (dqe = next)) 364 while (NULL != (dqe = next))
311 { 365 {
@@ -326,10 +380,10 @@ int free_tmps (void *cls,
326void 380void
327GST_manipulation_stop () 381GST_manipulation_stop ()
328{ 382{
329 GNUNET_CONTAINER_multihashmap_iterate (peers, &free_tmps,NULL); 383 GNUNET_CONTAINER_multihashmap_iterate (man_handle.peers, &free_tmps,NULL);
330 384
331 GNUNET_CONTAINER_multihashmap_destroy (peers); 385 GNUNET_CONTAINER_multihashmap_destroy (man_handle.peers);
332 peers = NULL; 386 man_handle.peers = NULL;
333} 387}
334 388
335 389
diff --git a/src/transport/gnunet-service-transport_manipulation.h b/src/transport/gnunet-service-transport_manipulation.h
index f8faa85dd..1ec75206b 100644
--- a/src/transport/gnunet-service-transport_manipulation.h
+++ b/src/transport/gnunet-service-transport_manipulation.h
@@ -54,7 +54,7 @@ GST_manipulation_recv (void *cls, const struct GNUNET_PeerIdentity *peer,
54 uint16_t sender_address_len); 54 uint16_t sender_address_len);
55 55
56void 56void
57GST_manipulation_init (); 57GST_manipulation_init (const struct GNUNET_CONFIGURATION_Handle *GST_cfg);
58 58
59void 59void
60GST_manipulation_stop (); 60GST_manipulation_stop ();