diff options
Diffstat (limited to 'src/ats/gnunet-service-ats-new.c')
-rw-r--r-- | src/ats/gnunet-service-ats-new.c | 69 |
1 files changed, 42 insertions, 27 deletions
diff --git a/src/ats/gnunet-service-ats-new.c b/src/ats/gnunet-service-ats-new.c index d3b2f1ead..fa8c07a1a 100644 --- a/src/ats/gnunet-service-ats-new.c +++ b/src/ats/gnunet-service-ats-new.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | */ | 17 | */ |
@@ -78,7 +78,7 @@ struct ClientPreference | |||
78 | * Plugin's representation of the preference. | 78 | * Plugin's representation of the preference. |
79 | */ | 79 | */ |
80 | struct GNUNET_ATS_PreferenceHandle *ph; | 80 | struct GNUNET_ATS_PreferenceHandle *ph; |
81 | 81 | ||
82 | /** | 82 | /** |
83 | * Details about the preference. | 83 | * Details about the preference. |
84 | */ | 84 | */ |
@@ -93,7 +93,7 @@ struct GNUNET_ATS_Session | |||
93 | { | 93 | { |
94 | 94 | ||
95 | /** | 95 | /** |
96 | * Session data exposed to the plugin. | 96 | * Session data exposed to the plugin. |
97 | */ | 97 | */ |
98 | struct GNUNET_ATS_SessionData data; | 98 | struct GNUNET_ATS_SessionData data; |
99 | 99 | ||
@@ -106,12 +106,12 @@ struct GNUNET_ATS_Session | |||
106 | * Session state in the plugin. | 106 | * Session state in the plugin. |
107 | */ | 107 | */ |
108 | struct GNUNET_ATS_SessionHandle *sh; | 108 | struct GNUNET_ATS_SessionHandle *sh; |
109 | 109 | ||
110 | /** | 110 | /** |
111 | * Unique ID for the session when talking with the client. | 111 | * Unique ID for the session when talking with the client. |
112 | */ | 112 | */ |
113 | uint32_t session_id; | 113 | uint32_t session_id; |
114 | 114 | ||
115 | }; | 115 | }; |
116 | 116 | ||
117 | 117 | ||
@@ -146,12 +146,12 @@ struct Client | |||
146 | * Head of DLL of preferences expressed by this client. | 146 | * Head of DLL of preferences expressed by this client. |
147 | */ | 147 | */ |
148 | struct ClientPreference *cp_head; | 148 | struct ClientPreference *cp_head; |
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Tail of DLL of preferences expressed by this client. | 151 | * Tail of DLL of preferences expressed by this client. |
152 | */ | 152 | */ |
153 | struct ClientPreference *cp_tail; | 153 | struct ClientPreference *cp_tail; |
154 | 154 | ||
155 | } application; | 155 | } application; |
156 | 156 | ||
157 | struct { | 157 | struct { |
@@ -160,9 +160,9 @@ struct Client | |||
160 | * Map from session IDs to `struct GNUNET_ATS_Session` objects. | 160 | * Map from session IDs to `struct GNUNET_ATS_Session` objects. |
161 | */ | 161 | */ |
162 | struct GNUNET_CONTAINER_MultiHashMap32 *sessions; | 162 | struct GNUNET_CONTAINER_MultiHashMap32 *sessions; |
163 | 163 | ||
164 | } transport; | 164 | } transport; |
165 | 165 | ||
166 | } details; | 166 | } details; |
167 | 167 | ||
168 | }; | 168 | }; |
@@ -196,7 +196,7 @@ static struct Client *transport_client; | |||
196 | * @param cls closure, NULL | 196 | * @param cls closure, NULL |
197 | * @param pid peer this is about | 197 | * @param pid peer this is about |
198 | * @param address address the transport should try | 198 | * @param address address the transport should try |
199 | */ | 199 | */ |
200 | static void | 200 | static void |
201 | suggest_cb (void *cls, | 201 | suggest_cb (void *cls, |
202 | const struct GNUNET_PeerIdentity *pid, | 202 | const struct GNUNET_PeerIdentity *pid, |
@@ -205,7 +205,7 @@ suggest_cb (void *cls, | |||
205 | struct GNUNET_MQ_Envelope *env; | 205 | struct GNUNET_MQ_Envelope *env; |
206 | size_t slen = strlen (address) + 1; | 206 | size_t slen = strlen (address) + 1; |
207 | struct AddressSuggestionMessage *as; | 207 | struct AddressSuggestionMessage *as; |
208 | 208 | ||
209 | if (NULL == transport_client) | 209 | if (NULL == transport_client) |
210 | { | 210 | { |
211 | // FIXME: stats! | 211 | // FIXME: stats! |
@@ -285,7 +285,7 @@ prop_ntoh (const struct PropertiesNBO *properties, | |||
285 | 285 | ||
286 | 286 | ||
287 | /** | 287 | /** |
288 | * We have received a `struct ExpressPreferenceMessage` from an application client. | 288 | * We have received a `struct ExpressPreferenceMessage` from an application client. |
289 | * | 289 | * |
290 | * @param cls handle to the client | 290 | * @param cls handle to the client |
291 | * @param msg the start message | 291 | * @param msg the start message |
@@ -320,7 +320,7 @@ handle_suggest (void *cls, | |||
320 | 320 | ||
321 | 321 | ||
322 | /** | 322 | /** |
323 | * We have received a `struct ExpressPreferenceMessage` from an application client. | 323 | * We have received a `struct ExpressPreferenceMessage` from an application client. |
324 | * | 324 | * |
325 | * @param cls handle to the client | 325 | * @param cls handle to the client |
326 | * @param msg the start message | 326 | * @param msg the start message |
@@ -331,7 +331,7 @@ handle_suggest_cancel (void *cls, | |||
331 | { | 331 | { |
332 | struct Client *c = cls; | 332 | struct Client *c = cls; |
333 | struct ClientPreference *cp; | 333 | struct ClientPreference *cp; |
334 | 334 | ||
335 | if (CT_NONE == c->type) | 335 | if (CT_NONE == c->type) |
336 | c->type = CT_APPLICATION; | 336 | c->type = CT_APPLICATION; |
337 | if (CT_APPLICATION != c->type) | 337 | if (CT_APPLICATION != c->type) |
@@ -398,7 +398,7 @@ handle_start (void *cls, | |||
398 | 398 | ||
399 | 399 | ||
400 | /** | 400 | /** |
401 | * Check 'session_add' message is well-formed and comes from a | 401 | * Check 'session_add' message is well-formed and comes from a |
402 | * transport client. | 402 | * transport client. |
403 | * | 403 | * |
404 | * @param cls client that sent the request | 404 | * @param cls client that sent the request |
@@ -433,7 +433,7 @@ handle_session_add (void *cls, | |||
433 | { | 433 | { |
434 | struct Client *c = cls; | 434 | struct Client *c = cls; |
435 | const char *address = (const char *) &message[1]; | 435 | const char *address = (const char *) &message[1]; |
436 | struct GNUNET_ATS_Session *session; | 436 | struct GNUNET_ATS_Session *session; |
437 | int inbound_only = (GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY == | 437 | int inbound_only = (GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY == |
438 | ntohs (message->header.type)); | 438 | ntohs (message->header.type)); |
439 | 439 | ||
@@ -477,7 +477,7 @@ handle_session_update (void *cls, | |||
477 | { | 477 | { |
478 | struct Client *c = cls; | 478 | struct Client *c = cls; |
479 | struct GNUNET_ATS_Session *session; | 479 | struct GNUNET_ATS_Session *session; |
480 | 480 | ||
481 | if (CT_TRANSPORT != c->type) | 481 | if (CT_TRANSPORT != c->type) |
482 | { | 482 | { |
483 | GNUNET_break (0); | 483 | GNUNET_break (0); |
@@ -527,7 +527,7 @@ handle_session_del (void *cls, | |||
527 | GNUNET_break (0); | 527 | GNUNET_break (0); |
528 | GNUNET_SERVICE_client_drop (c->client); | 528 | GNUNET_SERVICE_client_drop (c->client); |
529 | return; | 529 | return; |
530 | } | 530 | } |
531 | plugin->session_del (plugin->cls, | 531 | plugin->session_del (plugin->cls, |
532 | session->sh, | 532 | session->sh, |
533 | &session->data); | 533 | &session->data); |
@@ -637,15 +637,14 @@ client_disconnect_cb (void *cls, | |||
637 | 637 | ||
638 | 638 | ||
639 | /** | 639 | /** |
640 | * Task run during shutdown. | 640 | * Task run at the end during shutdown. |
641 | * | 641 | * |
642 | * @param cls unused | 642 | * @param cls unused |
643 | */ | 643 | */ |
644 | static void | 644 | static void |
645 | cleanup_task (void *cls) | 645 | final_cleanup (void *cls) |
646 | { | 646 | { |
647 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 647 | (void) cls; |
648 | "ATS shutdown initiated\n"); | ||
649 | if (NULL != stats) | 648 | if (NULL != stats) |
650 | { | 649 | { |
651 | GNUNET_STATISTICS_destroy (stats, | 650 | GNUNET_STATISTICS_destroy (stats, |
@@ -667,6 +666,22 @@ cleanup_task (void *cls) | |||
667 | 666 | ||
668 | 667 | ||
669 | /** | 668 | /** |
669 | * Task run during shutdown. | ||
670 | * | ||
671 | * @param cls unused | ||
672 | */ | ||
673 | static void | ||
674 | cleanup_task (void *cls) | ||
675 | { | ||
676 | (void) cls; | ||
677 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
678 | "ATS shutdown initiated\n"); | ||
679 | GNUNET_SCHEDULER_add_now (&final_cleanup, | ||
680 | NULL); | ||
681 | } | ||
682 | |||
683 | |||
684 | /** | ||
670 | * Process template requests. | 685 | * Process template requests. |
671 | * | 686 | * |
672 | * @param cls closure | 687 | * @param cls closure |
@@ -680,7 +695,7 @@ run (void *cls, | |||
680 | { | 695 | { |
681 | static struct GNUNET_ATS_PluginEnvironment env; | 696 | static struct GNUNET_ATS_PluginEnvironment env; |
682 | char *solver; | 697 | char *solver; |
683 | 698 | ||
684 | stats = GNUNET_STATISTICS_create ("ats", | 699 | stats = GNUNET_STATISTICS_create ("ats", |
685 | cfg); | 700 | cfg); |
686 | if (GNUNET_SYSERR == | 701 | if (GNUNET_SYSERR == |
@@ -711,7 +726,7 @@ run (void *cls, | |||
711 | _("Failed to initialize solver `%s'!\n"), | 726 | _("Failed to initialize solver `%s'!\n"), |
712 | plugin_name); | 727 | plugin_name); |
713 | GNUNET_SCHEDULER_shutdown (); | 728 | GNUNET_SCHEDULER_shutdown (); |
714 | return; | 729 | return; |
715 | } | 730 | } |
716 | } | 731 | } |
717 | 732 | ||
@@ -746,11 +761,11 @@ GNUNET_SERVICE_MAIN | |||
746 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY, | 761 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY, |
747 | struct SessionAddMessage, | 762 | struct SessionAddMessage, |
748 | NULL), | 763 | NULL), |
749 | GNUNET_MQ_hd_fixed_size (session_update, | 764 | GNUNET_MQ_hd_fixed_size (session_update, |
750 | GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE, | 765 | GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE, |
751 | struct SessionUpdateMessage, | 766 | struct SessionUpdateMessage, |
752 | NULL), | 767 | NULL), |
753 | GNUNET_MQ_hd_fixed_size (session_del, | 768 | GNUNET_MQ_hd_fixed_size (session_del, |
754 | GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL, | 769 | GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL, |
755 | struct SessionDelMessage, | 770 | struct SessionDelMessage, |
756 | NULL), | 771 | NULL), |