aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_performance.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/gnunet-service-ats_performance.c')
-rw-r--r--src/ats/gnunet-service-ats_performance.c109
1 files changed, 54 insertions, 55 deletions
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c
index 0fa08ac4b..4b8d23720 100644
--- a/src/ats/gnunet-service-ats_performance.c
+++ b/src/ats/gnunet-service-ats_performance.c
@@ -40,13 +40,13 @@ struct PerformanceClient
40 /** 40 /**
41 * Next in doubly-linked list. 41 * Next in doubly-linked list.
42 */ 42 */
43 struct PerformanceClient * next; 43 struct PerformanceClient *next;
44 44
45 /** 45 /**
46 * Previous in doubly-linked list. 46 * Previous in doubly-linked list.
47 */ 47 */
48 struct PerformanceClient * prev; 48 struct PerformanceClient *prev;
49 49
50 /** 50 /**
51 * Actual handle to the client. 51 * Actual handle to the client.
52 */ 52 */
@@ -69,7 +69,7 @@ static struct PerformanceClient *pc_head;
69 * Tail of linked list of all clients to this service. 69 * Tail of linked list of all clients to this service.
70 */ 70 */
71static struct PerformanceClient *pc_tail; 71static struct PerformanceClient *pc_tail;
72 72
73/** 73/**
74 * Context for sending messages to performance clients. 74 * Context for sending messages to performance clients.
75 */ 75 */
@@ -82,10 +82,10 @@ static struct GNUNET_SERVER_NotificationContext *nc;
82 * @param client server handle 82 * @param client server handle
83 * @return internal handle 83 * @return internal handle
84 */ 84 */
85static struct PerformanceClient * 85static struct PerformanceClient *
86find_client (struct GNUNET_SERVER_Client *client) 86find_client (struct GNUNET_SERVER_Client *client)
87{ 87{
88 struct PerformanceClient * pc; 88 struct PerformanceClient *pc;
89 89
90 for (pc = pc_head; pc != NULL; pc = pc->next) 90 for (pc = pc_head; pc != NULL; pc = pc->next)
91 if (pc->client == client) 91 if (pc->client == client)
@@ -101,9 +101,9 @@ find_client (struct GNUNET_SERVER_Client *client)
101 */ 101 */
102void 102void
103GAS_performance_add_client (struct GNUNET_SERVER_Client *client, 103GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
104 enum StartFlag flag) 104 enum StartFlag flag)
105{ 105{
106 struct PerformanceClient * pc; 106 struct PerformanceClient *pc;
107 107
108 GNUNET_break (NULL == find_client (client)); 108 GNUNET_break (NULL == find_client (client));
109 pc = GNUNET_malloc (sizeof (struct PerformanceClient)); 109 pc = GNUNET_malloc (sizeof (struct PerformanceClient));
@@ -111,7 +111,7 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
111 pc->flag = flag; 111 pc->flag = flag;
112 GNUNET_SERVER_notification_context_add (nc, client); 112 GNUNET_SERVER_notification_context_add (nc, client);
113 GNUNET_SERVER_client_keep (client); 113 GNUNET_SERVER_client_keep (client);
114 GNUNET_CONTAINER_DLL_insert(pc_head, pc_tail, pc); 114 GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc);
115} 115}
116 116
117 117
@@ -124,7 +124,7 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
124void 124void
125GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) 125GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
126{ 126{
127 struct PerformanceClient * pc; 127 struct PerformanceClient *pc;
128 128
129 pc = find_client (client); 129 pc = find_client (client);
130 if (NULL == pc) 130 if (NULL == pc)
@@ -150,25 +150,30 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client)
150 */ 150 */
151void 151void
152GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, 152GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
153 const char *plugin_name, 153 const char *plugin_name,
154 const void *plugin_addr, size_t plugin_addr_len, 154 const void *plugin_addr, size_t plugin_addr_len,
155 const struct GNUNET_ATS_Information *atsi, 155 const struct GNUNET_ATS_Information *atsi,
156 uint32_t atsi_count, 156 uint32_t atsi_count,
157 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 157 struct GNUNET_BANDWIDTH_Value32NBO
158 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 158 bandwidth_out,
159 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
159{ 160{
160 struct PerformanceClient *pc; 161 struct PerformanceClient *pc;
161 struct PeerInformationMessage *msg; 162 struct PeerInformationMessage *msg;
162 size_t plugin_name_length = strlen (plugin_name) + 1; 163 size_t plugin_name_length = strlen (plugin_name) + 1;
163 size_t msize = sizeof (struct PeerInformationMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information) 164 size_t msize =
164 + plugin_addr_len + plugin_name_length; 165 sizeof (struct PeerInformationMessage) +
166 atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len +
167 plugin_name_length;
165 char buf[msize]; 168 char buf[msize];
166 struct GNUNET_ATS_Information *atsp; 169 struct GNUNET_ATS_Information *atsp;
167 char *addrp; 170 char *addrp;
168 171
169 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); 172 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
170 GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)); 173 GNUNET_assert (atsi_count <
171 msg = (struct PeerInformationMessage*) buf; 174 GNUNET_SERVER_MAX_MESSAGE_SIZE /
175 sizeof (struct GNUNET_ATS_Information));
176 msg = (struct PeerInformationMessage *) buf;
172 msg->header.size = htons (msize); 177 msg->header.size = htons (msize);
173 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION); 178 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION);
174 msg->ats_count = htonl (atsi_count); 179 msg->ats_count = htonl (atsi_count);
@@ -177,22 +182,19 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
177 msg->plugin_name_length = htons (plugin_name_length); 182 msg->plugin_name_length = htons (plugin_name_length);
178 msg->bandwidth_out = bandwidth_out; 183 msg->bandwidth_out = bandwidth_out;
179 msg->bandwidth_in = bandwidth_in; 184 msg->bandwidth_in = bandwidth_in;
180 atsp = (struct GNUNET_ATS_Information* ) &msg[1]; 185 atsp = (struct GNUNET_ATS_Information *) &msg[1];
181 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); 186 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
182 addrp = (char*) &atsp[atsi_count]; 187 addrp = (char *) &atsp[atsi_count];
183 memcpy (addrp, plugin_addr, plugin_addr_len); 188 memcpy (addrp, plugin_addr, plugin_addr_len);
184 strcpy (&addrp[plugin_addr_len], plugin_name); 189 strcpy (&addrp[plugin_addr_len], plugin_name);
185 for (pc = pc_head; pc != NULL; pc = pc->next) 190 for (pc = pc_head; pc != NULL; pc = pc->next)
186 if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC) 191 if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC)
187 { 192 {
188 GNUNET_SERVER_notification_context_unicast (nc, 193 GNUNET_SERVER_notification_context_unicast (nc, pc->client, &msg->header,
189 pc->client, 194 GNUNET_YES);
190 &msg->header,
191 GNUNET_YES);
192 GNUNET_STATISTICS_update (GSA_stats, 195 GNUNET_STATISTICS_update (GSA_stats,
193 "# performance updates given to clients", 196 "# performance updates given to clients", 1,
194 1, 197 GNUNET_NO);
195 GNUNET_NO);
196 } 198 }
197} 199}
198 200
@@ -206,9 +208,10 @@ GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer,
206 */ 208 */
207void 209void
208GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client, 210GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
209 const struct GNUNET_MessageHeader *message) 211 const struct GNUNET_MessageHeader *message)
210{ 212{
211 const struct ReservationRequestMessage * msg = (const struct ReservationRequestMessage *) message; 213 const struct ReservationRequestMessage *msg =
214 (const struct ReservationRequestMessage *) message;
212 struct ReservationResultMessage result; 215 struct ReservationResultMessage result;
213 int32_t amount; 216 int32_t amount;
214 struct GNUNET_TIME_Relative res_delay; 217 struct GNUNET_TIME_Relative res_delay;
@@ -220,12 +223,10 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
220 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 223 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
221 return; 224 return;
222 } 225 }
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 226 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
224 "Received `%s' message\n", 227 "RESERVATION_REQUEST");
225 "RESERVATION_REQUEST");
226 amount = (int32_t) ntohl (msg->amount); 228 amount = (int32_t) ntohl (msg->amount);
227 res_delay = GAS_reservations_reserve (&msg->peer, 229 res_delay = GAS_reservations_reserve (&msg->peer, amount);
228 amount);
229 if (res_delay.rel_value > 0) 230 if (res_delay.rel_value > 0)
230 amount = 0; 231 amount = 0;
231 result.header.size = htons (sizeof (struct ReservationResultMessage)); 232 result.header.size = htons (sizeof (struct ReservationResultMessage));
@@ -233,14 +234,10 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
233 result.amount = htonl (amount); 234 result.amount = htonl (amount);
234 result.peer = msg->peer; 235 result.peer = msg->peer;
235 result.res_delay = GNUNET_TIME_relative_hton (res_delay); 236 result.res_delay = GNUNET_TIME_relative_hton (res_delay);
236 GNUNET_STATISTICS_update (GSA_stats, 237 GNUNET_STATISTICS_update (GSA_stats, "# reservation requests processed", 1,
237 "# reservation requests processed", 238 GNUNET_NO);
238 1, 239 GNUNET_SERVER_notification_context_unicast (nc, client, &result.header,
239 GNUNET_NO); 240 GNUNET_NO);
240 GNUNET_SERVER_notification_context_unicast (nc,
241 client,
242 &result.header,
243 GNUNET_NO);
244 GNUNET_SERVER_receive_done (client, GNUNET_OK); 241 GNUNET_SERVER_receive_done (client, GNUNET_OK);
245} 242}
246 243
@@ -254,15 +251,16 @@ GAS_handle_reservation_request (void *cls, struct GNUNET_SERVER_Client *client,
254 */ 251 */
255void 252void
256GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client, 253GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
257 const struct GNUNET_MessageHeader *message) 254 const struct GNUNET_MessageHeader *message)
258{ 255{
259 const struct ChangePreferenceMessage * msg; 256 const struct ChangePreferenceMessage *msg;
260 const struct PreferenceInformation *pi; 257 const struct PreferenceInformation *pi;
261 uint16_t msize; 258 uint16_t msize;
262 uint32_t nump; 259 uint32_t nump;
263 uint32_t i; 260 uint32_t i;
264 261
265 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "PREFERENCE_CHANGE"); 262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
263 "PREFERENCE_CHANGE");
266 msize = ntohs (message->size); 264 msize = ntohs (message->size);
267 if (msize < sizeof (struct ChangePreferenceMessage)) 265 if (msize < sizeof (struct ChangePreferenceMessage))
268 { 266 {
@@ -272,21 +270,22 @@ GAS_handle_preference_change (void *cls, struct GNUNET_SERVER_Client *client,
272 } 270 }
273 msg = (const struct ChangePreferenceMessage *) message; 271 msg = (const struct ChangePreferenceMessage *) message;
274 nump = ntohl (msg->num_preferences); 272 nump = ntohl (msg->num_preferences);
275 if (msize != sizeof (struct ChangePreferenceMessage) + nump * sizeof (struct PreferenceInformation)) 273 if (msize !=
274 sizeof (struct ChangePreferenceMessage) +
275 nump * sizeof (struct PreferenceInformation))
276 { 276 {
277 GNUNET_break (0); 277 GNUNET_break (0);
278 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 278 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
279 return; 279 return;
280 } 280 }
281 GNUNET_STATISTICS_update (GSA_stats, 281 GNUNET_STATISTICS_update (GSA_stats, "# preference change requests processed",
282 "# preference change requests processed", 282 1, GNUNET_NO);
283 1,
284 GNUNET_NO);
285 pi = (const struct PreferenceInformation *) &msg[1]; 283 pi = (const struct PreferenceInformation *) &msg[1];
286 for (i=0;i<nump;i++) 284 for (i = 0; i < nump; i++)
287 GAS_addresses_change_preference (&msg->peer, 285 GAS_addresses_change_preference (&msg->peer,
288 (enum GNUNET_ATS_PreferenceKind) ntohl (pi[i].preference_kind), 286 (enum GNUNET_ATS_PreferenceKind)
289 pi[i].preference_value); 287 ntohl (pi[i].preference_kind),
288 pi[i].preference_value);
290 GNUNET_SERVER_receive_done (client, GNUNET_OK); 289 GNUNET_SERVER_receive_done (client, GNUNET_OK);
291} 290}
292 291