aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-12-15 15:01:39 +0000
committerChristian Grothoff <christian@grothoff.org>2014-12-15 15:01:39 +0000
commit8094e23bf7e13b1c203ba8b85e5edcbfdf5ff650 (patch)
tree424d79f91128aa2428c32d8c6efbd9e926bf37b6 /src/ats
parent482d35a0c3148bcc69929c5778038db00d0839b9 (diff)
downloadgnunet-8094e23bf7e13b1c203ba8b85e5edcbfdf5ff650.tar.gz
gnunet-8094e23bf7e13b1c203ba8b85e5edcbfdf5ff650.zip
-doxygen, indentation
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/ats_api_performance.c66
-rw-r--r--src/ats/gnunet-service-ats_performance.c33
-rw-r--r--src/ats/test_ats_api_performance_list_peer_addresses.c16
3 files changed, 67 insertions, 48 deletions
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c
index ab242a0e9..840e302b0 100644
--- a/src/ats/ats_api_performance.c
+++ b/src/ats/ats_api_performance.c
@@ -481,9 +481,9 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph,
481 GNUNET_break(0); 481 GNUNET_break(0);
482 return GNUNET_SYSERR; 482 return GNUNET_SYSERR;
483 } 483 }
484 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
485 _("Received %s message\n"), 485 _("Received %s message\n"),
486 "ATS_ADDRESSLIST_RESPONSE"); 486 "ATS_ADDRESSLIST_RESPONSE");
487 487
488 pi = (const struct PeerInformationMessage *) msg; 488 pi = (const struct PeerInformationMessage *) msg;
489 id = ntohl (pi->id); 489 id = ntohl (pi->id);
@@ -520,20 +520,27 @@ process_ar_message (struct GNUNET_ATS_PerformanceHandle *ph,
520 } 520 }
521 521
522 memset (&allzeros, '\0', sizeof(allzeros)); 522 memset (&allzeros, '\0', sizeof(allzeros));
523 if ((0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros))) 523 if ( (0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros))) &&
524 && (0 == plugin_name_length) && (0 == plugin_address_length) 524 (0 == plugin_name_length) &&
525 && (0 == ats_count)) 525 (0 == plugin_address_length) &&
526 (0 == ats_count) )
526 { 527 {
527 /* Done */ 528 /* Done */
528 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, _("Received last message for %s \n"), 529 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
529 "ATS_ADDRESSLIST_RESPONSE"); 530 _("Received last message for %s \n"),
531 "ATS_ADDRESSLIST_RESPONSE");
530 bandwidth_zero.value__ = htonl (0); 532 bandwidth_zero.value__ = htonl (0);
533 GNUNET_CONTAINER_DLL_remove (ph->addresslist_head,
534 ph->addresslist_tail,
535 alh);
531 if (NULL != alh->cb) 536 if (NULL != alh->cb)
532 alh->cb (ph->addr_info_cb_cls, NULL, GNUNET_NO, bandwidth_zero, 537 alh->cb (ph->addr_info_cb_cls,
533 bandwidth_zero, NULL, 0); 538 NULL,
534 GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, ph->addresslist_tail, 539 GNUNET_NO,
535 alh); 540 bandwidth_zero,
536 GNUNET_free(alh); 541 bandwidth_zero,
542 NULL, 0);
543 GNUNET_free (alh);
537 return GNUNET_OK; 544 return GNUNET_OK;
538 } 545 }
539 546
@@ -797,10 +804,8 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *hand
797 struct PendingMessage *p; 804 struct PendingMessage *p;
798 struct AddressListRequestMessage *m; 805 struct AddressListRequestMessage *m;
799 806
800 GNUNET_assert(NULL != handle);
801 if (NULL == infocb) 807 if (NULL == infocb)
802 return NULL ; 808 return NULL;
803
804 alh = GNUNET_new (struct GNUNET_ATS_AddressListHandle); 809 alh = GNUNET_new (struct GNUNET_ATS_AddressListHandle);
805 alh->id = handle->id; 810 alh->id = handle->id;
806 handle->id++; 811 handle->id++;
@@ -809,19 +814,21 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *hand
809 alh->ph = handle; 814 alh->ph = handle;
810 alh->all_addresses = all; 815 alh->all_addresses = all;
811 if (NULL == peer) 816 if (NULL == peer)
817 {
812 alh->all_peers = GNUNET_YES; 818 alh->all_peers = GNUNET_YES;
819 }
813 else 820 else
814 { 821 {
815 alh->all_peers = GNUNET_NO; 822 alh->all_peers = GNUNET_NO;
816 alh->peer = (*peer); 823 alh->peer = (*peer);
817 } 824 }
818 825 GNUNET_CONTAINER_DLL_insert (handle->addresslist_head,
819 GNUNET_CONTAINER_DLL_insert(handle->addresslist_head, 826 handle->addresslist_tail,
820 handle->addresslist_tail, alh); 827 alh);
821 828
822 p = GNUNET_malloc (sizeof (struct PendingMessage) + 829 p = GNUNET_malloc (sizeof (struct PendingMessage) +
823 sizeof (struct AddressListRequestMessage)); 830 sizeof (struct AddressListRequestMessage));
824 p->size = sizeof(struct AddressListRequestMessage); 831 p->size = sizeof (struct AddressListRequestMessage);
825 m = (struct AddressListRequestMessage *) &p[1]; 832 m = (struct AddressListRequestMessage *) &p[1];
826 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST); 833 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST);
827 m->header.size = htons (sizeof(struct AddressListRequestMessage)); 834 m->header.size = htons (sizeof(struct AddressListRequestMessage));
@@ -829,14 +836,9 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *hand
829 m->id = htonl (alh->id); 836 m->id = htonl (alh->id);
830 if (NULL != peer) 837 if (NULL != peer)
831 m->peer = *peer; 838 m->peer = *peer;
832 else
833 {
834 memset (&m->peer, '\0', sizeof(struct GNUNET_PeerIdentity));
835 }
836 GNUNET_CONTAINER_DLL_insert_tail(handle->pending_head, 839 GNUNET_CONTAINER_DLL_insert_tail(handle->pending_head,
837 handle->pending_tail, 840 handle->pending_tail,
838 p); 841 p);
839
840 do_transmit (handle); 842 do_transmit (handle);
841 843
842 return alh; 844 return alh;
@@ -846,7 +848,7 @@ GNUNET_ATS_performance_list_addresses (struct GNUNET_ATS_PerformanceHandle *hand
846/** 848/**
847 * Cancel a pending address listing operation 849 * Cancel a pending address listing operation
848 * 850 *
849 * @param handle the GNUNET_ATS_AddressListHandle handle to cancel 851 * @param handle the handle of the request to cancel
850 */ 852 */
851void 853void
852GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle) 854GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandle *handle)
@@ -860,7 +862,7 @@ GNUNET_ATS_performance_list_addresses_cancel (struct GNUNET_ATS_AddressListHandl
860 862
861 863
862/** 864/**
863 * Convert a GNUNET_ATS_PreferenceType to a string 865 * Convert a `enum GNUNET_ATS_PreferenceType` to a string
864 * 866 *
865 * @param type the preference type 867 * @param type the preference type
866 * @return a string or NULL if invalid 868 * @return a string or NULL if invalid
@@ -871,7 +873,7 @@ GNUNET_ATS_print_preference_type (uint32_t type)
871 char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString; 873 char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
872 if (type < GNUNET_ATS_PreferenceCount) 874 if (type < GNUNET_ATS_PreferenceCount)
873 return prefs[type]; 875 return prefs[type];
874 return NULL ; 876 return NULL;
875} 877}
876 878
877 879
@@ -988,12 +990,10 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
988 case GNUNET_ATS_PREFERENCE_BANDWIDTH: 990 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
989 count++; 991 count++;
990 (void) va_arg (ap, double); 992 (void) va_arg (ap, double);
991
992 break; 993 break;
993 case GNUNET_ATS_PREFERENCE_LATENCY: 994 case GNUNET_ATS_PREFERENCE_LATENCY:
994 count++; 995 count++;
995 (void) va_arg (ap, double); 996 (void) va_arg (ap, double);
996
997 break; 997 break;
998 default: 998 default:
999 GNUNET_assert(0); 999 GNUNET_assert(0);
@@ -1035,7 +1035,9 @@ GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
1035 } 1035 }
1036 } 1036 }
1037 va_end(ap); 1037 va_end(ap);
1038 GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p); 1038 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head,
1039 ph->pending_tail,
1040 p);
1039 do_transmit (ph); 1041 do_transmit (ph);
1040} 1042}
1041 1043
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c
index ac2509455..71e176a60 100644
--- a/src/ats/gnunet-service-ats_performance.c
+++ b/src/ats/gnunet-service-ats_performance.c
@@ -360,13 +360,26 @@ GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
360 360
361 361
362/** 362/**
363 * FIXME. 363 * Send a #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE with the
364 * given address details to the client identified in @a ai.
365 *
366 * @param ai our address information context (identifies the client)
367 * @param id the peer id this address is for
368 * @param plugin_name name of the plugin that supports this address
369 * @param plugin_addr address
370 * @param plugin_addr_len length of @a plugin_addr
371 * @param active #GNUNET_YES if this address is actively used
372 * @param atsi ats performance information
373 * @param atsi_count number of ats performance elements in @a atsi
374 * @param bandwidth_out current outbound bandwidth assigned to address
375 * @param bandwidth_in current inbound bandwidth assigned to address
364 */ 376 */
365static void 377static void
366transmit_req_addr (struct AddressIteration *ai, 378transmit_req_addr (struct AddressIteration *ai,
367 const struct GNUNET_PeerIdentity *id, 379 const struct GNUNET_PeerIdentity *id,
368 const char *plugin_name, 380 const char *plugin_name,
369 const void *plugin_addr, size_t plugin_addr_len, 381 const void *plugin_addr,
382 size_t plugin_addr_len,
370 int active, 383 int active,
371 const struct GNUNET_ATS_Information *atsi, 384 const struct GNUNET_ATS_Information *atsi,
372 uint32_t atsi_count, 385 uint32_t atsi_count,
@@ -468,14 +481,14 @@ req_addr_peerinfo_it (void *cls,
468 /* Transmit result */ 481 /* Transmit result */
469 if ((GNUNET_YES == ai->all) || (GNUNET_YES == active)) 482 if ((GNUNET_YES == ai->all) || (GNUNET_YES == active))
470 { 483 {
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 484 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
472 "Sending result for %s peer `%s' plugin `%s' BW out %u, BW in %u\n", 485 "Sending result for %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
473 (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE", 486 (active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
474 GNUNET_i2s (id), 487 GNUNET_i2s (id),
475 plugin_name, 488 plugin_name,
476 (unsigned int) ntohl (bandwidth_out.value__), 489 (unsigned int) ntohl (bandwidth_out.value__),
477 (unsigned int) ntohl (bandwidth_in.value__)); 490 (unsigned int) ntohl (bandwidth_in.value__));
478 transmit_req_addr (cls, 491 transmit_req_addr (ai,
479 id, 492 id,
480 plugin_name, 493 plugin_name,
481 plugin_addr, plugin_addr_len, 494 plugin_addr, plugin_addr_len,
diff --git a/src/ats/test_ats_api_performance_list_peer_addresses.c b/src/ats/test_ats_api_performance_list_peer_addresses.c
index bebec4881..ed1b99f44 100644
--- a/src/ats/test_ats_api_performance_list_peer_addresses.c
+++ b/src/ats/test_ats_api_performance_list_peer_addresses.c
@@ -105,9 +105,10 @@ ats_perf_cb (void *cls,
105 uint32_t ats_count) 105 uint32_t ats_count)
106{ 106{
107 static int counter = 0; 107 static int counter = 0;
108
108 if (NULL == address) 109 if (NULL == address)
109 { 110 {
110 phal = 0; 111 phal = NULL;
111 if (2 == counter) 112 if (2 == counter)
112 { 113 {
113 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 114 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -117,6 +118,9 @@ ats_perf_cb (void *cls,
117 } 118 }
118 else 119 else
119 { 120 {
121 fprintf (stderr,
122 "Expected 2 addresses, got %d\n",
123 counter);
120 GNUNET_break (0); 124 GNUNET_break (0);
121 GNUNET_SCHEDULER_shutdown (); 125 GNUNET_SCHEDULER_shutdown ();
122 } 126 }
@@ -136,9 +140,9 @@ ats_perf_cb (void *cls,
136 140
137 141
138static int 142static int
139stat_cb(void *cls, const char *subsystem, 143stat_cb (void *cls, const char *subsystem,
140 const char *name, uint64_t value, 144 const char *name, uint64_t value,
141 int is_persistent) 145 int is_persistent)
142{ 146{
143 147
144 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 148 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@@ -153,7 +157,7 @@ stat_cb(void *cls, const char *subsystem,
153 if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL))) 157 if (NULL == (perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL)))
154 { 158 {
155 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
156 "Failed to connect to performance API\n"); 160 "Failed to connect to performance API\n");
157 GNUNET_SCHEDULER_shutdown (); 161 GNUNET_SCHEDULER_shutdown ();
158 return GNUNET_SYSERR; 162 return GNUNET_SYSERR;
159 } 163 }
@@ -190,7 +194,7 @@ end (void *cls,
190 phal = NULL; 194 phal = NULL;
191 } 195 }
192 196
193 if (perf_ats != NULL) 197 if (NULL != perf_ats)
194 { 198 {
195 GNUNET_ATS_performance_done (perf_ats); 199 GNUNET_ATS_performance_done (perf_ats);
196 perf_ats = NULL; 200 perf_ats = NULL;