aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_manipulation.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-04-03 14:59:01 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-04-03 14:59:01 +0000
commita106ca799b1905f8093f8d8e12d1996b894f8a9f (patch)
tree82666f66147531dfd75734399e3100268c5eb333 /src/transport/gnunet-service-transport_manipulation.c
parent37b6710fcbbc07888b0cbdc2d24f73579cb71ab9 (diff)
downloadgnunet-a106ca799b1905f8093f8d8e12d1996b894f8a9f.tar.gz
gnunet-a106ca799b1905f8093f8d8e12d1996b894f8a9f.zip
generic ats manipulation
Diffstat (limited to 'src/transport/gnunet-service-transport_manipulation.c')
-rw-r--r--src/transport/gnunet-service-transport_manipulation.c151
1 files changed, 122 insertions, 29 deletions
diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c
index 4543add00..720b47179 100644
--- a/src/transport/gnunet-service-transport_manipulation.c
+++ b/src/transport/gnunet-service-transport_manipulation.c
@@ -48,6 +48,57 @@ enum TRAFFIC_METRIC_DIRECTION
48struct GST_ManipulationHandle man_handle; 48struct GST_ManipulationHandle man_handle;
49 49
50 50
51/**
52 * Struct containing information about manipulations to a specific peer
53 */
54struct TM_Peer;
55
56struct PropManipulationEntry
57{
58 struct PropManipulationEntry *next;
59 struct PropManipulationEntry *prev;
60
61 uint32_t type;
62
63 uint32_t metrics[TM_BOTH];
64
65};
66
67/**
68 * Struct containing information about manipulations to a specific peer
69 */
70struct TM_Peer
71{
72 /**
73 * Peer ID
74 */
75 struct GNUNET_PeerIdentity peer;
76
77 struct PropManipulationEntry *head;
78 struct PropManipulationEntry *tail;
79
80 /**
81 * Peer specific manipulation metrics
82 */
83 uint32_t metrics [TM_BOTH][GNUNET_ATS_QualityPropertiesCount];
84
85 /**
86 * Task to schedule delayed sendding
87 */
88 GNUNET_SCHEDULER_TaskIdentifier send_delay_task;
89
90 /**
91 * Send queue DLL head
92 */
93 struct DelayQueueEntry *send_head;
94
95 /**
96 * Send queue DLL tail
97 */
98 struct DelayQueueEntry *send_tail;
99};
100
101
51struct GST_ManipulationHandle 102struct GST_ManipulationHandle
52{ 103{
53 /** 104 /**
@@ -55,6 +106,8 @@ struct GST_ManipulationHandle
55 */ 106 */
56 struct GNUNET_CONTAINER_MultiHashMap *peers; 107 struct GNUNET_CONTAINER_MultiHashMap *peers;
57 108
109 struct TM_Peer general;
110
58 /** 111 /**
59 * General inbound delay 112 * General inbound delay
60 */ 113 */
@@ -75,12 +128,11 @@ struct GST_ManipulationHandle
75 */ 128 */
76 unsigned long long distance_send; 129 unsigned long long distance_send;
77 130
131 struct PropManipulationEntry *head;
132 struct PropManipulationEntry *tail;
78}; 133};
79 134
80/** 135
81 * Struct containing information about manipulations to a specific peer
82 */
83struct TM_Peer;
84 136
85/** 137/**
86 * Entry in the delay queue for an outbound delayed message 138 * Entry in the delay queue for an outbound delayed message
@@ -133,37 +185,70 @@ struct DelayQueueEntry
133 void *cont_cls; 185 void *cont_cls;
134}; 186};
135 187
136/** 188
137 * Struct containing information about manipulations to a specific peer 189static void
138 */ 190set_metric (struct TM_Peer *dest, int direction, uint32_t type, uint32_t value)
139struct TM_Peer
140{ 191{
141 /** 192 struct PropManipulationEntry *cur;
142 * Peer ID 193 for (cur = dest->head; NULL != cur; cur = cur->next)
143 */ 194 {
144 struct GNUNET_PeerIdentity peer; 195 if (cur->type == type)
196 break;
197 }
198 if (NULL == cur)
199 {
200 cur = GNUNET_malloc (sizeof (struct PropManipulationEntry));
201 GNUNET_CONTAINER_DLL_insert (dest->head, dest->tail, cur);
202 cur->type = type;
203 cur->metrics[TM_SEND] = UINT32_MAX;
204 cur->metrics[TM_RECEIVE] = UINT32_MAX;
205 }
145 206
146 /**
147 * Peer specific manipulation metrics
148 */
149 uint32_t metrics [TM_BOTH][GNUNET_ATS_QualityPropertiesCount];
150 207
151 /** 208 switch (direction) {
152 * Task to schedule delayed sendding 209 case TM_BOTH:
153 */ 210 cur->metrics[TM_SEND] = value;
154 GNUNET_SCHEDULER_TaskIdentifier send_delay_task; 211 cur->metrics[TM_RECEIVE] = value;
212 break;
213 case TM_SEND:
214 cur->metrics[TM_SEND] = value;
215 break;
216 case TM_RECEIVE:
217 cur->metrics[TM_RECEIVE] = value;
218 break;
219 default:
220 break;
221 }
155 222
156 /** 223}
157 * Send queue DLL head
158 */
159 struct DelayQueueEntry *send_head;
160 224
161 /** 225static uint32_t
162 * Send queue DLL tail 226find_metric (struct TM_Peer *dest, uint32_t type, int direction)
163 */ 227{
164 struct DelayQueueEntry *send_tail; 228 struct PropManipulationEntry *cur;
165};
166 229
230 for (cur = dest->head; NULL != cur; cur = cur->next)
231 {
232 if (cur->type == type)
233 return cur->metrics[direction];
234
235 }
236 return UINT32_MAX;
237}
238
239static void
240free_metric (struct TM_Peer *dest)
241{
242 struct PropManipulationEntry *cur;
243 struct PropManipulationEntry *next;
244
245 for (cur = dest->head; NULL != cur; cur = next)
246 {
247 next = cur->next;
248 GNUNET_CONTAINER_DLL_remove (dest->head, dest->tail, cur);
249 GNUNET_free (cur);
250 }
251}
167 252
168static void 253static void
169set_delay(struct TM_Peer *tmp, struct GNUNET_PeerIdentity *peer, int direction, uint32_t value) 254set_delay(struct TM_Peer *tmp, struct GNUNET_PeerIdentity *peer, int direction, uint32_t value)
@@ -278,6 +363,8 @@ GST_manipulation_set_metric (void *cls, struct GNUNET_SERVER_Client *client,
278 type = htonl (ats[c].type); 363 type = htonl (ats[c].type);
279 value = htonl (ats[c].value); 364 value = htonl (ats[c].value);
280 365
366 set_metric (&man_handle.general, direction, type, value);
367
281 switch (type) { 368 switch (type) {
282 case GNUNET_ATS_QUALITY_NET_DELAY: 369 case GNUNET_ATS_QUALITY_NET_DELAY:
283 if ((TM_RECEIVE == direction) || (TM_BOTH == direction)) 370 if ((TM_RECEIVE == direction) || (TM_BOTH == direction))
@@ -321,6 +408,10 @@ GST_manipulation_set_metric (void *cls, struct GNUNET_SERVER_Client *client,
321 { 408 {
322 type = htonl (ats[c].type); 409 type = htonl (ats[c].type);
323 value = htonl (ats[c].value); 410 value = htonl (ats[c].value);
411
412 set_metric (tmp, direction, type, value);
413
414
324 switch (type) { 415 switch (type) {
325 case GNUNET_ATS_QUALITY_NET_DELAY: 416 case GNUNET_ATS_QUALITY_NET_DELAY:
326 set_delay (tmp, &tm->peer, direction, value); 417 set_delay (tmp, &tm->peer, direction, value);
@@ -570,6 +661,7 @@ free_tmps (void *cls,
570 { 661 {
571 struct TM_Peer *tmp = (struct TM_Peer *) value; 662 struct TM_Peer *tmp = (struct TM_Peer *) value;
572 GNUNET_CONTAINER_multihashmap_remove (man_handle.peers, key, value); 663 GNUNET_CONTAINER_multihashmap_remove (man_handle.peers, key, value);
664 free_metric (tmp);
573 next = tmp->send_head; 665 next = tmp->send_head;
574 while (NULL != (dqe = next)) 666 while (NULL != (dqe = next))
575 { 667 {
@@ -597,6 +689,7 @@ GST_manipulation_stop ()
597 GNUNET_CONTAINER_multihashmap_iterate (man_handle.peers, &free_tmps,NULL); 689 GNUNET_CONTAINER_multihashmap_iterate (man_handle.peers, &free_tmps,NULL);
598 690
599 GNUNET_CONTAINER_multihashmap_destroy (man_handle.peers); 691 GNUNET_CONTAINER_multihashmap_destroy (man_handle.peers);
692 free_metric (&man_handle.general);
600 man_handle.peers = NULL; 693 man_handle.peers = NULL;
601} 694}
602 695