aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_addresses.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-09-21 10:56:28 +0000
committerChristian Grothoff <christian@grothoff.org>2016-09-21 10:56:28 +0000
commitd4afc6e37a14fe3257263c377a243c1a22ed9ee5 (patch)
treeccfce6d4f92808372d3e7ebfe9f5372e9f21f50c /src/ats/gnunet-service-ats_addresses.c
parent60d02b5b0899f454cb65408bd2ed4c453fa75a3d (diff)
downloadgnunet-d4afc6e37a14fe3257263c377a243c1a22ed9ee5.tar.gz
gnunet-d4afc6e37a14fe3257263c377a243c1a22ed9ee5.zip
migrating more services to new service API
Diffstat (limited to 'src/ats/gnunet-service-ats_addresses.c')
-rw-r--r--src/ats/gnunet-service-ats_addresses.c70
1 files changed, 24 insertions, 46 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 44a4782d5..1a4a33206 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -347,13 +347,13 @@ GAS_addresses_destroy (const struct GNUNET_PeerIdentity *peer,
347 * known and current performance information. It has a solver component 347 * known and current performance information. It has a solver component
348 * responsible for the resource allocation. It tells the solver about changes 348 * responsible for the resource allocation. It tells the solver about changes
349 * and receives updates when the solver changes the resource allocation. 349 * and receives updates when the solver changes the resource allocation.
350 *
351 * @param server handle to our server
352 */ 350 */
353void 351void
354GAS_addresses_init (struct GNUNET_SERVER_Handle *server) 352GAS_addresses_init ()
355{ 353{
356 GSA_addresses = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_NO); 354 GSA_addresses
355 = GNUNET_CONTAINER_multipeermap_create (128,
356 GNUNET_NO);
357 update_addresses_stat (); 357 update_addresses_stat ();
358} 358}
359 359
@@ -515,7 +515,7 @@ struct AddressIteration
515 /** 515 /**
516 * Actual handle to the client. 516 * Actual handle to the client.
517 */ 517 */
518 struct GNUNET_SERVER_Client *client; 518 struct GNUNET_SERVICE_Client *client;
519 519
520 /** 520 /**
521 * Are we sending all addresses, or only those that are active? 521 * Are we sending all addresses, or only those that are active?
@@ -558,30 +558,26 @@ transmit_req_addr (struct AddressIteration *ai,
558 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 558 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
559 559
560{ 560{
561 struct GNUNET_MQ_Envelope *env;
561 struct PeerInformationMessage *msg; 562 struct PeerInformationMessage *msg;
562 char *addrp; 563 char *addrp;
563 size_t plugin_name_length; 564 size_t plugin_name_length;
564 size_t msize; 565 size_t msize;
565 struct GNUNET_SERVER_NotificationContext **uc;
566 struct GNUNET_SERVER_NotificationContext *nc;
567 566
568 if (NULL != plugin_name) 567 if (NULL != plugin_name)
569 plugin_name_length = strlen (plugin_name) + 1; 568 plugin_name_length = strlen (plugin_name) + 1;
570 else 569 else
571 plugin_name_length = 0; 570 plugin_name_length = 0;
572 msize = sizeof (struct PeerInformationMessage) + 571 msize = plugin_addr_len + plugin_name_length;
573 plugin_addr_len + plugin_name_length; 572
574 char buf[msize] GNUNET_ALIGN; 573 GNUNET_assert (sizeof (struct PeerInformationMessage) + msize
575 574 < GNUNET_SERVER_MAX_MESSAGE_SIZE);
576 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); 575 env = GNUNET_MQ_msg_extra (msg,
577 msg = (struct PeerInformationMessage *) buf; 576 msize,
578 msg->header.size = htons (msize); 577 GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
579 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
580 msg->id = htonl (ai->id); 578 msg->id = htonl (ai->id);
581 if (NULL != id) 579 if (NULL != id)
582 msg->peer = *id; 580 msg->peer = *id;
583 else
584 memset (&msg->peer, '\0', sizeof (struct GNUNET_PeerIdentity));
585 msg->address_length = htons (plugin_addr_len); 581 msg->address_length = htons (plugin_addr_len);
586 msg->address_active = ntohl (active); 582 msg->address_active = ntohl (active);
587 msg->plugin_name_length = htons (plugin_name_length); 583 msg->plugin_name_length = htons (plugin_name_length);
@@ -590,28 +586,16 @@ transmit_req_addr (struct AddressIteration *ai,
590 if (NULL != prop) 586 if (NULL != prop)
591 GNUNET_ATS_properties_hton (&msg->properties, 587 GNUNET_ATS_properties_hton (&msg->properties,
592 prop); 588 prop);
593 else
594 memset (&msg->properties,
595 0,
596 sizeof (struct GNUNET_ATS_Properties));
597 msg->address_local_info = htonl ((uint32_t) local_address_info); 589 msg->address_local_info = htonl ((uint32_t) local_address_info);
598 addrp = (char *) &msg[1]; 590 addrp = (char *) &msg[1];
599 if (NULL != plugin_addr) 591 GNUNET_memcpy (addrp,
600 GNUNET_memcpy (addrp, plugin_addr, plugin_addr_len); 592 plugin_addr,
593 plugin_addr_len);
601 if (NULL != plugin_name) 594 if (NULL != plugin_name)
602 strcpy (&addrp[plugin_addr_len], plugin_name); 595 strcpy (&addrp[plugin_addr_len],
603 uc = GNUNET_SERVER_client_get_user_context (ai->client, 596 plugin_name);
604 struct GNUNET_SERVER_NotificationContext *); 597 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (ai->client),
605 if (NULL == uc) 598 env);
606 {
607 GNUNET_break (0);
608 return;
609 }
610 nc = *uc;
611 GNUNET_SERVER_notification_context_unicast (nc,
612 ai->client,
613 &msg->header,
614 GNUNET_NO);
615} 599}
616 600
617 601
@@ -679,22 +663,18 @@ req_addr_peerinfo_it (void *cls,
679/** 663/**
680 * Handle 'address list request' messages from clients. 664 * Handle 'address list request' messages from clients.
681 * 665 *
682 * @param cls unused, NULL 666 * @param cls client that sent the request
683 * @param client client that sent the request 667 * @param alrm the request message
684 * @param message the request message
685 */ 668 */
686void 669void
687GAS_handle_request_address_list (void *cls, 670GAS_handle_request_address_list (struct GNUNET_SERVICE_Client *client,
688 struct GNUNET_SERVER_Client *client, 671 const struct AddressListRequestMessage *alrm)
689 const struct GNUNET_MessageHeader *message)
690{ 672{
691 struct AddressIteration ai; 673 struct AddressIteration ai;
692 const struct AddressListRequestMessage *alrm;
693 struct GNUNET_PeerIdentity allzeros; 674 struct GNUNET_PeerIdentity allzeros;
694 675
695 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
696 "Received ADDRESSLIST_REQUEST message\n"); 677 "Received ADDRESSLIST_REQUEST message\n");
697 alrm = (const struct AddressListRequestMessage *) message;
698 ai.all = ntohl (alrm->all); 678 ai.all = ntohl (alrm->all);
699 ai.id = ntohl (alrm->id); 679 ai.id = ntohl (alrm->id);
700 ai.client = client; 680 ai.client = client;
@@ -728,8 +708,6 @@ GAS_handle_request_address_list (void *cls,
728 GNUNET_HELLO_ADDRESS_INFO_NONE, 708 GNUNET_HELLO_ADDRESS_INFO_NONE,
729 GNUNET_BANDWIDTH_ZERO, 709 GNUNET_BANDWIDTH_ZERO,
730 GNUNET_BANDWIDTH_ZERO); 710 GNUNET_BANDWIDTH_ZERO);
731 GNUNET_SERVER_receive_done (client,
732 GNUNET_OK);
733} 711}
734 712
735 713