aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-07 12:33:51 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-07 12:33:51 +0000
commit577ad3b798f0cd62c2e9ab92fdc58cfe75a3fcdc (patch)
treec0b50fb6b802221d17ea691f4e6a16ce30f8e6de /src
parentc20f6b6366bcfd93ca613b5771dd0dae4b5ccca3 (diff)
downloadgnunet-577ad3b798f0cd62c2e9ab92fdc58cfe75a3fcdc.tar.gz
gnunet-577ad3b798f0cd62c2e9ab92fdc58cfe75a3fcdc.zip
simplify logic
Diffstat (limited to 'src')
-rw-r--r--src/ats/gnunet-service-ats_plugins.c114
-rw-r--r--src/ats/gnunet-service-ats_plugins.h69
-rw-r--r--src/ats/gnunet-service-ats_preferences.c15
3 files changed, 142 insertions, 56 deletions
diff --git a/src/ats/gnunet-service-ats_plugins.c b/src/ats/gnunet-service-ats_plugins.c
index 5e3f9c8d4..c388e7f67 100644
--- a/src/ats/gnunet-service-ats_plugins.c
+++ b/src/ats/gnunet-service-ats_plugins.c
@@ -277,10 +277,10 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
277 unsigned long long *in_dest, 277 unsigned long long *in_dest,
278 int dest_length) 278 int dest_length)
279{ 279{
280 char * entry_in = NULL; 280 char *entry_in = NULL;
281 char * entry_out = NULL; 281 char *entry_out = NULL;
282 char * quota_out_str; 282 char *quota_out_str;
283 char * quota_in_str; 283 char *quota_in_str;
284 int c; 284 int c;
285 int res; 285 int res;
286 286
@@ -367,11 +367,11 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
367 367
368 if (GNUNET_NO == res) 368 if (GNUNET_NO == res)
369 { 369 {
370 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 370 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
371 _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"), 371 _("Could not load quota for network `%s': `%s', assigning default bandwidth %llu\n"),
372 GNUNET_ATS_print_network_type (c), 372 GNUNET_ATS_print_network_type (c),
373 quota_in_str, 373 quota_in_str,
374 GNUNET_ATS_DefaultBandwidth); 374 GNUNET_ATS_DefaultBandwidth);
375 in_dest[c] = GNUNET_ATS_DefaultBandwidth; 375 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
376 } 376 }
377 else 377 else
@@ -385,17 +385,17 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
385 } 385 }
386 else 386 else
387 { 387 {
388 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 388 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
389 _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"), 389 _("No outbound quota configure for network `%s', assigning default bandwidth %llu\n"),
390 GNUNET_ATS_print_network_type (c), 390 GNUNET_ATS_print_network_type (c),
391 GNUNET_ATS_DefaultBandwidth); 391 GNUNET_ATS_DefaultBandwidth);
392 in_dest[c] = GNUNET_ATS_DefaultBandwidth; 392 in_dest[c] = GNUNET_ATS_DefaultBandwidth;
393 } 393 }
394 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, 394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
395 "Loaded quota for network `%s' (in/out): %llu %llu\n", 395 "Loaded quota for network `%s' (in/out): %llu %llu\n",
396 GNUNET_ATS_print_network_type (c), 396 GNUNET_ATS_print_network_type (c),
397 in_dest[c], 397 in_dest[c],
398 out_dest[c]); 398 out_dest[c]);
399 GNUNET_free(entry_out); 399 GNUNET_free(entry_out);
400 GNUNET_free(entry_in); 400 GNUNET_free(entry_in);
401 } 401 }
@@ -520,6 +520,15 @@ GAS_plugins_done ()
520} 520}
521 521
522 522
523/**
524 * Tell the solver that the given address can now be used
525 * for talking to the respective peer.
526 *
527 * @param new_address the new address
528 * @param addr_net network scope the address is in
529 * @param atsi performance data for the address
530 * @param atsi_count size of the @a atsi array
531 */
523void 532void
524GAS_plugin_new_address (struct ATS_Address *new_address, 533GAS_plugin_new_address (struct ATS_Address *new_address,
525 enum GNUNET_ATS_Network_Type addr_net, 534 enum GNUNET_ATS_Network_Type addr_net,
@@ -532,10 +541,17 @@ GAS_plugin_new_address (struct ATS_Address *new_address,
532 atsi, 541 atsi,
533 atsi_count); 542 atsi_count);
534 sf->s_bulk_stop (sf->cls); 543 sf->s_bulk_stop (sf->cls);
535 // if (GAS_connectivity_has_peer (&new_address->peer)) GAS_plugin_request_connect_start (&new_address->peer);
536} 544}
537 545
538 546
547/**
548 * Tell the solver that updated performance data was
549 * observed for the given address.
550 *
551 * @param new_address the new address
552 * @param atsi updated performance data for the address
553 * @param atsi_count size of the @a atsi array
554 */
539void 555void
540GAS_plugin_update_address (struct ATS_Address *address, 556GAS_plugin_update_address (struct ATS_Address *address,
541 const struct GNUNET_ATS_Information *atsi, 557 const struct GNUNET_ATS_Information *atsi,
@@ -549,6 +565,12 @@ GAS_plugin_update_address (struct ATS_Address *address,
549} 565}
550 566
551 567
568/**
569 * Tell the solver that the given address is no longer valid
570 * can cannot be used any longer.
571 *
572 * @param address address that was deleted
573 */
552void 574void
553GAS_plugin_delete_address (struct ATS_Address *address) 575GAS_plugin_delete_address (struct ATS_Address *address)
554{ 576{
@@ -556,35 +578,36 @@ GAS_plugin_delete_address (struct ATS_Address *address)
556} 578}
557 579
558 580
581/**
582 * Tell the solver that the given client has expressed its
583 * appreciation for the past performance of a given connection.
584 *
585 * @param application client providing the feedback
586 * @param peer peer the feedback is about
587 * @param scope timeframe the feedback applies to
588 * @param kind performance property the feedback relates to
589 * @param score_abs degree of the appreciation
590 */
559void 591void
560GAS_plugin_update_preferences (void *client, 592GAS_plugin_preference_feedback (struct GNUNET_SERVER_Client *application,
561 const struct GNUNET_PeerIdentity *peer,
562 enum GNUNET_ATS_PreferenceKind kind,
563 float score_abs)
564{
565 sf->s_bulk_start (sf->cls);
566 /* Tell normalization about change, normalization will call callback if preference changed */
567 GAS_normalization_normalize_preference (client, peer, kind, score_abs);
568 sf->s_bulk_stop (sf->cls);
569}
570
571
572void
573GAS_plugin_preference_feedback (void *application,
574 const struct GNUNET_PeerIdentity *peer, 593 const struct GNUNET_PeerIdentity *peer,
575 const struct GNUNET_TIME_Relative scope, 594 const struct GNUNET_TIME_Relative scope,
576 enum GNUNET_ATS_PreferenceKind kind, 595 enum GNUNET_ATS_PreferenceKind kind,
577 float score_abs) 596 float score_abs)
578{ 597{
579 sf->s_feedback (sf->cls, 598 sf->s_feedback (sf->cls,
580 application, 599 application,
581 peer, 600 peer,
582 scope, 601 scope,
583 kind, 602 kind,
584 score_abs); 603 score_abs);
585} 604}
586 605
587 606
607/**
608 * Stop instant solving, there are many state updates
609 * happening in bulk right now.
610 */
588void 611void
589GAS_plugin_solver_lock () 612GAS_plugin_solver_lock ()
590{ 613{
@@ -592,6 +615,9 @@ GAS_plugin_solver_lock ()
592} 615}
593 616
594 617
618/**
619 * Resume instant solving, we are done with the bulk state updates.
620 */
595void 621void
596GAS_plugin_solver_unlock () 622GAS_plugin_solver_unlock ()
597{ 623{
@@ -599,6 +625,12 @@ GAS_plugin_solver_unlock ()
599} 625}
600 626
601 627
628/**
629 * Notify the plugin that a request to connect to
630 * a particular peer was given to us.
631 *
632 * @param pid identity of peer we now care about
633 */
602void 634void
603GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid) 635GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid)
604{ 636{
@@ -623,6 +655,12 @@ GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid)
623} 655}
624 656
625 657
658/**
659 * Notify the plugin that a request to connect to
660 * a particular peer was dropped.
661 *
662 * @param pid identity of peer we care now less about
663 */
626void 664void
627GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid) 665GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid)
628{ 666{
diff --git a/src/ats/gnunet-service-ats_plugins.h b/src/ats/gnunet-service-ats_plugins.h
index dd85bd361..7e093d940 100644
--- a/src/ats/gnunet-service-ats_plugins.h
+++ b/src/ats/gnunet-service-ats_plugins.h
@@ -108,6 +108,15 @@ GAS_normalized_property_changed (struct ATS_Address *address,
108 double prop_rel); 108 double prop_rel);
109 109
110 110
111/**
112 * Tell the solver that the given address can now be used
113 * for talking to the respective peer.
114 *
115 * @param new_address the new address
116 * @param addr_net network scope the address is in
117 * @param atsi performance data for the address
118 * @param atsi_count size of the @a atsi array
119 */
111void 120void
112GAS_plugin_new_address (struct ATS_Address *new_address, 121GAS_plugin_new_address (struct ATS_Address *new_address,
113 enum GNUNET_ATS_Network_Type addr_net, 122 enum GNUNET_ATS_Network_Type addr_net,
@@ -115,45 +124,83 @@ GAS_plugin_new_address (struct ATS_Address *new_address,
115 uint32_t atsi_count); 124 uint32_t atsi_count);
116 125
117 126
127/**
128 * Tell the solver that updated performance data was
129 * observed for the given address.
130 *
131 * @param new_address the new address
132 * @param atsi updated performance data for the address
133 * @param atsi_count size of the @a atsi array
134 */
118void 135void
119GAS_plugin_update_address (struct ATS_Address *address, 136GAS_plugin_update_address (struct ATS_Address *address,
120 const struct GNUNET_ATS_Information *atsi, 137 const struct GNUNET_ATS_Information *atsi,
121 uint32_t atsi_count); 138 uint32_t atsi_count);
122 139
123 140
141/**
142 * Tell the solver that the given address is no longer valid
143 * can cannot be used any longer.
144 *
145 * @param address address that was deleted
146 */
124void 147void
125GAS_plugin_update_preferences (void *client, 148GAS_plugin_delete_address (struct ATS_Address *address);
126 const struct GNUNET_PeerIdentity *peer,
127 enum GNUNET_ATS_PreferenceKind kind,
128 float score_abs);
129 149
130 150
151/**
152 * Tell the solver that the given client has expressed its
153 * appreciation for the past performance of a given connection.
154 *
155 * @param application client providing the feedback
156 * @param peer peer the feedback is about
157 * @param scope timeframe the feedback applies to
158 * @param kind performance property the feedback relates to
159 * @param score_abs degree of the appreciation
160 */
131void 161void
132GAS_plugin_preference_feedback (void *application, 162GAS_plugin_preference_feedback (struct GNUNET_SERVER_Client *application,
133 const struct GNUNET_PeerIdentity *peer, 163 const struct GNUNET_PeerIdentity *peer,
134 const struct GNUNET_TIME_Relative scope, 164 const struct GNUNET_TIME_Relative scope,
135 enum GNUNET_ATS_PreferenceKind kind, 165 enum GNUNET_ATS_PreferenceKind kind,
136 float score_abs); 166 float score_abs);
137 167
138 168
139void
140GAS_plugin_delete_address (struct ATS_Address *address);
141 169
142 170
171/**
172 * Stop instant solving, there are many state updates
173 * happening in bulk right now.
174 */
143void 175void
144GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid); 176GAS_plugin_solver_lock (void);
145 177
146 178
179/**
180 * Resume instant solving, we are done with the bulk state updates.
181 */
147void 182void
148GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid); 183GAS_plugin_solver_unlock (void);
149 184
150 185
186/**
187 * Notify the plugin that a request to connect to
188 * a particular peer was given to us.
189 *
190 * @param pid identity of peer we now care about
191 */
151void 192void
152GAS_plugin_solver_lock (void); 193GAS_plugin_request_connect_start (const struct GNUNET_PeerIdentity *pid);
153 194
154 195
196/**
197 * Notify the plugin that a request to connect to
198 * a particular peer was dropped.
199 *
200 * @param pid identity of peer we care now less about
201 */
155void 202void
156GAS_plugin_solver_unlock (void); 203GAS_plugin_request_connect_stop (const struct GNUNET_PeerIdentity *pid);
157 204
158 205
159#endif 206#endif
diff --git a/src/ats/gnunet-service-ats_preferences.c b/src/ats/gnunet-service-ats_preferences.c
index cbb1eba08..c9559ba89 100644
--- a/src/ats/gnunet-service-ats_preferences.c
+++ b/src/ats/gnunet-service-ats_preferences.c
@@ -435,7 +435,7 @@ update_abs_preference (struct PreferenceClient *c,
435 p->f_abs[kind] = score; 435 p->f_abs[kind] = score;
436 /* p->f_abs[kind] = (p->f_abs[kind] + score) / 2; */ 436 /* p->f_abs[kind] = (p->f_abs[kind] + score) / 2; */
437 p->next_aging[kind] = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), 437 p->next_aging[kind] = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (),
438 PREF_AGING_INTERVAL); 438 PREF_AGING_INTERVAL);
439 break; 439 break;
440 case GNUNET_ATS_PREFERENCE_END: 440 case GNUNET_ATS_PREFERENCE_END:
441 break; 441 break;
@@ -471,10 +471,10 @@ preference_change (struct GNUNET_SERVER_Client *client,
471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 471 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
472 "Received CHANGE_PREFERENCE for peer `%s'\n", 472 "Received CHANGE_PREFERENCE for peer `%s'\n",
473 GNUNET_i2s (peer)); 473 GNUNET_i2s (peer));
474 GAS_plugin_update_preferences (client, 474 GAS_normalization_normalize_preference (client,
475 peer, 475 peer,
476 kind, 476 kind,
477 score_abs); 477 score_abs);
478} 478}
479 479
480 480
@@ -664,7 +664,6 @@ GAS_normalization_normalize_preference (struct GNUNET_SERVER_Client *client,
664 c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE; 664 c_cur->f_abs_sum[i] = DEFAULT_ABS_PREFERENCE;
665 c_cur->f_rel_sum[i] = DEFAULT_REL_PREFERENCE; 665 c_cur->f_rel_sum[i] = DEFAULT_REL_PREFERENCE;
666 } 666 }
667
668 GNUNET_CONTAINER_DLL_insert (pc_head, 667 GNUNET_CONTAINER_DLL_insert (pc_head,
669 pc_tail, 668 pc_tail,
670 c_cur); 669 c_cur);
@@ -685,7 +684,7 @@ GAS_normalization_normalize_preference (struct GNUNET_SERVER_Client *client,
685 { 684 {
686 p_cur = GNUNET_new (struct PreferencePeer); 685 p_cur = GNUNET_new (struct PreferencePeer);
687 p_cur->client = c_cur; 686 p_cur->client = c_cur;
688 p_cur->id = (*peer); 687 p_cur->id = *peer;
689 for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) 688 for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
690 { 689 {
691 /* Default value per peer absolute preference for a preference: 0 */ 690 /* Default value per peer absolute preference for a preference: 0 */
@@ -725,10 +724,12 @@ GAS_normalization_normalize_preference (struct GNUNET_SERVER_Client *client,
725 if (p_cur->f_abs[kind] == old_value) 724 if (p_cur->f_abs[kind] == old_value)
726 return; 725 return;
727 726
727 GAS_plugin_solver_lock ();
728 run_preference_update (c_cur, 728 run_preference_update (c_cur,
729 p_cur, 729 p_cur,
730 kind, 730 kind,
731 score_abs); 731 score_abs);
732 GAS_plugin_solver_unlock ();
732 733
733 if (NULL == aging_task) 734 if (NULL == aging_task)
734 aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL, 735 aging_task = GNUNET_SCHEDULER_add_delayed (PREF_AGING_INTERVAL,