aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-11 13:05:42 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-11 13:05:42 +0000
commit3dab4cd6a1ff1c4cf885af8f2f032fdc44250c86 (patch)
tree90ed909442731ce5cd8b852a8faa480609ceb8a1 /src/transport
parent297e28384ae74a468895f950552ae4acfb7efb0d (diff)
downloadgnunet-3dab4cd6a1ff1c4cf885af8f2f032fdc44250c86.tar.gz
gnunet-3dab4cd6a1ff1c4cf885af8f2f032fdc44250c86.zip
dummy ATS implementation
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/gnunet-service-transport_ats-new.c98
-rw-r--r--src/transport/gnunet-service-transport_ats-new.h9
2 files changed, 103 insertions, 4 deletions
diff --git a/src/transport/gnunet-service-transport_ats-new.c b/src/transport/gnunet-service-transport_ats-new.c
index 983674c07..d7e91a64e 100644
--- a/src/transport/gnunet-service-transport_ats-new.c
+++ b/src/transport/gnunet-service-transport_ats-new.c
@@ -106,18 +106,108 @@ struct GST_AtsHandle
106 * Task scheduled to update our bandwidth assignment. 106 * Task scheduled to update our bandwidth assignment.
107 */ 107 */
108 GNUNET_SCHEDULER_TaskIdentifier ba_task; 108 GNUNET_SCHEDULER_TaskIdentifier ba_task;
109
110 /**
111 * Total bandwidth per configuration.
112 */
113 unsigned long long total_bps;
114};
115
116
117
118/**
119 * Count number of connected records.
120 *
121 * @param cls pointer to counter
122 * @param key identity of the peer associated with the records
123 * @param value a 'struct AllocationRecord'
124 * @return GNUNET_YES (continue iteration)
125 */
126static int
127count_connections (void *cls,
128 const GNUNET_HashCode *key,
129 void *value)
130{
131 unsigned int *ac = cls;
132 struct AllocationRecord *ar = value;
133
134 if (GNUNET_YES == ar->connected)
135 (*ac)++;
136 return GNUNET_YES;
137}
138
139struct SetBandwidthContext
140{
141 struct GST_AtsHandle *atc;
142 struct GNUNET_BANDWIDTH_Value32NBO bw;
109}; 143};
110 144
145/**
146 * Set bandwidth based on record.
147 *
148 * @param cls 'struct SetBandwidthContext'
149 * @param key identity of the peer associated with the records
150 * @param value a 'struct AllocationRecord'
151 * @return GNUNET_YES (continue iteration)
152 */
153static int
154set_bw_connections (void *cls,
155 const GNUNET_HashCode *key,
156 void *value)
157{
158 struct SetBandwidthContext *sbc = cls;
159 struct AllocationRecord *ar = value;
160
161 if (GNUNET_YES == ar->connected)
162 {
163 ar->bandwidth = sbc->bw;
164 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
165 (const struct GNUNET_PeerIdentity*) key,
166 ar->plugin_name,
167 ar->session,
168 ar->plugin_addr,
169 ar->plugin_addr_len,
170 ar->bandwidth);
171 }
172 else if (ntohl(ar->bandwidth.value__) > 0)
173 {
174 ar->bandwidth = GNUNET_BANDWIDTH_value_init (0);
175 sbc->atc->alloc_cb (sbc->atc->alloc_cb_cls,
176 (const struct GNUNET_PeerIdentity*) key,
177 ar->plugin_name,
178 ar->session,
179 ar->plugin_addr,
180 ar->plugin_addr_len,
181 ar->bandwidth);
182 }
183 return GNUNET_YES;
184}
185
111 186
187/**
188 * Task run to update bandwidth assignments.
189 *
190 * @param cls the 'struct GST_AtsHandle'
191 * @param tc scheduler context
192 */
112static void 193static void
113update_bandwidth_task (void *cls, 194update_bandwidth_task (void *cls,
114 const struct GNUNET_SCHEDULER_TaskContext *tc) 195 const struct GNUNET_SCHEDULER_TaskContext *tc)
115{ 196{
116 struct GST_AtsHandle *atc = cls; 197 struct GST_AtsHandle *atc = cls;
198 unsigned int ac;
199 struct SetBandwidthContext bwc;
117 200
118 atc->ba_task = GNUNET_SCHEDULER_NO_TASK; 201 atc->ba_task = GNUNET_SCHEDULER_NO_TASK;
119 /* FIXME: update calculations! */ 202 /* FIXME: update calculations NICELY; what follows is a naive version */
120 203 GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
204 &count_connections,
205 &ac);
206 bwc.atc = atc;
207 bwc.bw = GNUNET_BANDWIDTH_value_init (atc->total_bps / ac);
208 GNUNET_CONTAINER_multihashmap_iterate (atc->peers,
209 &set_bw_connections,
210 &bwc);
121} 211}
122 212
123 213
@@ -158,6 +248,10 @@ GST_ats_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
158 atc->alloc_cb = alloc_cb; 248 atc->alloc_cb = alloc_cb;
159 atc->alloc_cb_cls = alloc_cb_cls; 249 atc->alloc_cb_cls = alloc_cb_cls;
160 atc->peers = GNUNET_CONTAINER_multihashmap_create (256); 250 atc->peers = GNUNET_CONTAINER_multihashmap_create (256);
251 GNUNET_CONFIGURATION_get_value_number (cfg,
252 "core",
253 "TOTAL_QUOTA_OUT",
254 &atc->total_bps);
161 return atc; 255 return atc;
162} 256}
163 257
diff --git a/src/transport/gnunet-service-transport_ats-new.h b/src/transport/gnunet-service-transport_ats-new.h
index e4e85fee1..b3f004989 100644
--- a/src/transport/gnunet-service-transport_ats-new.h
+++ b/src/transport/gnunet-service-transport_ats-new.h
@@ -19,9 +19,14 @@
19*/ 19*/
20/** 20/**
21 * @file transport/gnunet-service-transport_ats-new.h 21 * @file transport/gnunet-service-transport_ats-new.h
22 * @brief automatic transport selection API 22 * @brief automatic transport selection and outbound bandwidth determination
23 * @author Christian Grothoff 23 * @author Christian Grothoff
24 * @author Matthias Wachs 24 * @author Matthias Wachs
25 *
26 * TODO:
27 * - turn into service
28 * - extend API to express communication preferences to ATS
29 * (to be called DIRECTLY from apps, not from transport/core!)
25 */ 30 */
26#ifndef GNUNET_SERVICE_TRANSPORT_ATS_H 31#ifndef GNUNET_SERVICE_TRANSPORT_ATS_H
27#define GNUNET_SERVICE_TRANSPORT_ATS_H 32#define GNUNET_SERVICE_TRANSPORT_ATS_H
@@ -51,7 +56,7 @@ struct GST_AtsHandle;
51 * @param session session to use (if available) 56 * @param session session to use (if available)
52 * @param plugin_addr address to use (if available) 57 * @param plugin_addr address to use (if available)
53 * @param plugin_addr_len number of bytes in addr 58 * @param plugin_addr_len number of bytes in addr
54 * @param bandwidth assigned bandwidth for the connection 59 * @param bandwidth assigned outbound bandwidth for the connection
55 */ 60 */
56typedef void (*GNUNET_TRANSPORT_ATS_AllocationNotification)(void *cls, 61typedef void (*GNUNET_TRANSPORT_ATS_AllocationNotification)(void *cls,
57 const struct GNUNET_PeerIdentity *peer, 62 const struct GNUNET_PeerIdentity *peer,