aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_scheduling.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-01-22 21:25:54 +0000
committerChristian Grothoff <christian@grothoff.org>2015-01-22 21:25:54 +0000
commit750da2796162b92c533f9666104c47407ed09e46 (patch)
treeb1fe3ec2ca36854a15fd8e97760d05e9a54836b9 /src/ats/gnunet-service-ats_scheduling.c
parent9c95f4ea09fa61fc193fc45873f76bf6fe6d93f3 (diff)
downloadgnunet-750da2796162b92c533f9666104c47407ed09e46.tar.gz
gnunet-750da2796162b92c533f9666104c47407ed09e46.zip
simplifying IPC for address in use and address update
Diffstat (limited to 'src/ats/gnunet-service-ats_scheduling.c')
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c65
1 files changed, 5 insertions, 60 deletions
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index b0a52f39c..685c6535d 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -311,10 +311,6 @@ GAS_handle_address_update (void *cls,
311{ 311{
312 const struct AddressUpdateMessage *m; 312 const struct AddressUpdateMessage *m;
313 const struct GNUNET_ATS_Information *atsi; 313 const struct GNUNET_ATS_Information *atsi;
314 const char *address;
315 const char *plugin_name;
316 uint16_t address_length;
317 uint16_t plugin_name_length;
318 uint32_t ats_count; 314 uint32_t ats_count;
319 uint16_t size; 315 uint16_t size;
320 316
@@ -330,21 +326,12 @@ GAS_handle_address_update (void *cls,
330 } 326 }
331 m = (const struct AddressUpdateMessage *) message; 327 m = (const struct AddressUpdateMessage *) message;
332 ats_count = ntohl (m->ats_count); 328 ats_count = ntohl (m->ats_count);
333 address_length = ntohs (m->address_length);
334 plugin_name_length = ntohs (m->plugin_name_length);
335 atsi = (const struct GNUNET_ATS_Information *) &m[1]; 329 atsi = (const struct GNUNET_ATS_Information *) &m[1];
336 address = (const char *) &atsi[ats_count];
337 if (plugin_name_length != 0)
338 plugin_name = &address[address_length];
339 else
340 plugin_name = "";
341 330
342 if ((address_length + plugin_name_length + 331 if ((ats_count * sizeof (struct GNUNET_ATS_Information) +
343 ats_count * sizeof (struct GNUNET_ATS_Information) +
344 sizeof (struct AddressUpdateMessage) != ntohs (message->size)) || 332 sizeof (struct AddressUpdateMessage) != ntohs (message->size)) ||
345 (ats_count > 333 (ats_count >
346 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || 334 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)))
347 ((plugin_name_length > 0) && (plugin_name[plugin_name_length - 1] != '\0')))
348 { 335 {
349 GNUNET_break (0); 336 GNUNET_break (0);
350 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 337 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -356,11 +343,8 @@ GAS_handle_address_update (void *cls,
356 GNUNET_NO); 343 GNUNET_NO);
357 GAS_addresses_update (address_handle, 344 GAS_addresses_update (address_handle,
358 &m->peer, 345 &m->peer,
359 plugin_name, 346 ntohl (m->session_id),
360 address, 347 atsi, ats_count);
361 address_length,
362 ntohl (m->address_local_info),
363 ntohl (m->session_id), atsi, ats_count);
364 GNUNET_SERVER_receive_done (client, GNUNET_OK); 348 GNUNET_SERVER_receive_done (client, GNUNET_OK);
365} 349}
366 350
@@ -378,52 +362,13 @@ GAS_handle_address_in_use (void *cls,
378 const struct GNUNET_MessageHeader *message) 362 const struct GNUNET_MessageHeader *message)
379{ 363{
380 const struct AddressUseMessage *m; 364 const struct AddressUseMessage *m;
381 const char *address;
382 const char *plugin_name;
383 int res; 365 int res;
384 uint16_t address_length;
385 uint16_t plugin_name_length;
386 uint16_t size;
387 uint16_t in_use;
388 366
389 size = ntohs (message->size);
390 if (size < sizeof (struct AddressUseMessage))
391 {
392 GNUNET_break (0);
393 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
394 return;
395 }
396 m = (const struct AddressUseMessage *) message; 367 m = (const struct AddressUseMessage *) message;
397
398 address_length = ntohs (m->address_length);
399 plugin_name_length = ntohs (m->plugin_name_length);
400
401 address = (const char *) &m[1];
402 if (plugin_name_length != 0)
403 plugin_name = &address[address_length];
404 else
405 plugin_name = "";
406
407 if ((address_length + plugin_name_length +
408 sizeof (struct AddressUseMessage) != ntohs (message->size)) ||
409 ((plugin_name_length > 0) &&
410 (plugin_name[plugin_name_length - 1] != '\0')))
411 {
412 GNUNET_break (0);
413 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
414 return;
415 }
416
417 in_use = ntohs (m->in_use);
418 res = GAS_addresses_in_use (address_handle, 368 res = GAS_addresses_in_use (address_handle,
419 &m->peer, 369 &m->peer,
420 plugin_name,
421 address,
422 address_length,
423 ntohl (m->address_local_info),
424 ntohl (m->session_id), 370 ntohl (m->session_id),
425 in_use); 371 ntohl (m->in_use));
426
427 if (GNUNET_OK != res) 372 if (GNUNET_OK != res)
428 { 373 {
429 GNUNET_break (0); 374 GNUNET_break (0);