diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/ats/.gitignore | 1 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats-new.c | 140 | ||||
-rw-r--r-- | src/include/gnunet_ats_plugin_new.h | 85 | ||||
-rw-r--r-- | src/transport/.gitignore | 1 |
4 files changed, 207 insertions, 20 deletions
diff --git a/src/ats/.gitignore b/src/ats/.gitignore index 97f1088b9..fa72eb136 100644 --- a/src/ats/.gitignore +++ b/src/ats/.gitignore | |||
@@ -3,3 +3,4 @@ test_ats_api_proportional | |||
3 | test_ats_reservation_api_proportional | 3 | test_ats_reservation_api_proportional |
4 | test_ats_api_mlp | 4 | test_ats_api_mlp |
5 | test_ats_api_ril | 5 | test_ats_api_ril |
6 | gnunet-service-ats-new | ||
diff --git a/src/ats/gnunet-service-ats-new.c b/src/ats/gnunet-service-ats-new.c index 57398e641..c4ce4e0bb 100644 --- a/src/ats/gnunet-service-ats-new.c +++ b/src/ats/gnunet-service-ats-new.c | |||
@@ -22,9 +22,7 @@ | |||
22 | * @author Christian Grothoff | 22 | * @author Christian Grothoff |
23 | * | 23 | * |
24 | * TODO: | 24 | * TODO: |
25 | * - implement messages ATS -> transport | 25 | * - implement unloading of ATS plugins |
26 | * - implement loading / unloading of ATS plugins | ||
27 | * - expose plugin the API to send messages ATS -> transport | ||
28 | */ | 26 | */ |
29 | #include "platform.h" | 27 | #include "platform.h" |
30 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
@@ -176,7 +174,7 @@ struct Client | |||
176 | /** | 174 | /** |
177 | * Handle for statistics. | 175 | * Handle for statistics. |
178 | */ | 176 | */ |
179 | static struct GNUNET_STATISTICS_Handle *GSA_stats; | 177 | static struct GNUNET_STATISTICS_Handle *stats; |
180 | 178 | ||
181 | /** | 179 | /** |
182 | * Our solver. | 180 | * Our solver. |
@@ -184,12 +182,90 @@ static struct GNUNET_STATISTICS_Handle *GSA_stats; | |||
184 | static struct GNUNET_ATS_SolverFunctions *plugin; | 182 | static struct GNUNET_ATS_SolverFunctions *plugin; |
185 | 183 | ||
186 | /** | 184 | /** |
185 | * Solver plugin name as string | ||
186 | */ | ||
187 | static char *plugin_name; | ||
188 | |||
189 | /** | ||
187 | * The transport client (there can only be one at a time). | 190 | * The transport client (there can only be one at a time). |
188 | */ | 191 | */ |
189 | static struct Client *transport_client; | 192 | static struct Client *transport_client; |
190 | 193 | ||
191 | 194 | ||
192 | /** | 195 | /** |
196 | * Function called by the solver to prompt the transport to | ||
197 | * try out a new address. | ||
198 | * | ||
199 | * @param cls closure, NULL | ||
200 | * @param pid peer this is about | ||
201 | * @param address address the transport should try | ||
202 | */ | ||
203 | static void | ||
204 | suggest_cb (void *cls, | ||
205 | const struct GNUNET_PeerIdentity *pid, | ||
206 | const char *address) | ||
207 | { | ||
208 | struct GNUNET_MQ_Envelope *env; | ||
209 | size_t slen = strlen (address) + 1; | ||
210 | struct AddressSuggestionMessage *as; | ||
211 | |||
212 | if (NULL == transport_client) | ||
213 | { | ||
214 | // FIXME: stats! | ||
215 | return; | ||
216 | } | ||
217 | env = GNUNET_MQ_msg_extra (as, | ||
218 | slen, | ||
219 | GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); | ||
220 | as->peer = *pid; | ||
221 | memcpy (&as[1], | ||
222 | address, | ||
223 | slen); | ||
224 | GNUNET_MQ_send (transport_client->mq, | ||
225 | env); | ||
226 | } | ||
227 | |||
228 | |||
229 | /** | ||
230 | * Function called by the solver to tell the transpor to | ||
231 | * allocate bandwidth for the specified session. | ||
232 | * | ||
233 | * @param cls closure, NULL | ||
234 | * @param session session this is about | ||
235 | * @param peer peer this is about | ||
236 | * @param bw_in suggested bandwidth for receiving | ||
237 | * @param bw_out suggested bandwidth for transmission | ||
238 | */ | ||
239 | static void | ||
240 | allocate_cb (void *cls, | ||
241 | struct GNUNET_ATS_Session *session, | ||
242 | const struct GNUNET_PeerIdentity *peer, | ||
243 | struct GNUNET_BANDWIDTH_Value32NBO bw_in, | ||
244 | struct GNUNET_BANDWIDTH_Value32NBO bw_out) | ||
245 | { | ||
246 | struct GNUNET_MQ_Envelope *env; | ||
247 | struct SessionAllocationMessage *sam; | ||
248 | |||
249 | (void) cls; | ||
250 | if ( (NULL == transport_client) || | ||
251 | (session->client != transport_client) ) | ||
252 | { | ||
253 | /* transport must have just died and solver is addressing the | ||
254 | losses of sessions (possibly of previous transport), ignore! */ | ||
255 | return; | ||
256 | } | ||
257 | env = GNUNET_MQ_msg (sam, | ||
258 | GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION); | ||
259 | sam->session_id = session->session_id; | ||
260 | sam->peer = *peer; | ||
261 | sam->bandwidth_in = bw_in; | ||
262 | sam->bandwidth_out = bw_out; | ||
263 | GNUNET_MQ_send (transport_client->mq, | ||
264 | env); | ||
265 | } | ||
266 | |||
267 | |||
268 | /** | ||
193 | * Convert @a properties to @a prop | 269 | * Convert @a properties to @a prop |
194 | * | 270 | * |
195 | * @param properties in NBO | 271 | * @param properties in NBO |
@@ -359,7 +435,8 @@ handle_session_add (void *cls, | |||
359 | const struct SessionAddMessage *message) | 435 | const struct SessionAddMessage *message) |
360 | { | 436 | { |
361 | struct Client *c = cls; | 437 | struct Client *c = cls; |
362 | struct GNUNET_ATS_Session *session; | 438 | const char *address = (const char *) &message[1]; |
439 | struct GNUNET_ATS_Session *session; | ||
363 | int inbound_only = (GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY == | 440 | int inbound_only = (GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY == |
364 | ntohs (message->header.type)); | 441 | ntohs (message->header.type)); |
365 | 442 | ||
@@ -385,12 +462,12 @@ handle_session_add (void *cls, | |||
385 | session, | 462 | session, |
386 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 463 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
387 | session->sh = plugin->session_add (plugin->cls, | 464 | session->sh = plugin->session_add (plugin->cls, |
388 | &session->data); | 465 | &session->data, |
466 | address); | ||
389 | GNUNET_SERVICE_client_continue (c->client); | 467 | GNUNET_SERVICE_client_continue (c->client); |
390 | } | 468 | } |
391 | 469 | ||
392 | 470 | ||
393 | |||
394 | /** | 471 | /** |
395 | * Handle 'session update' messages from transport clients. | 472 | * Handle 'session update' messages from transport clients. |
396 | * | 473 | * |
@@ -572,11 +649,16 @@ cleanup_task (void *cls) | |||
572 | { | 649 | { |
573 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 650 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
574 | "ATS shutdown initiated\n"); | 651 | "ATS shutdown initiated\n"); |
575 | if (NULL != GSA_stats) | 652 | if (NULL != stats) |
576 | { | 653 | { |
577 | GNUNET_STATISTICS_destroy (GSA_stats, | 654 | GNUNET_STATISTICS_destroy (stats, |
578 | GNUNET_NO); | 655 | GNUNET_NO); |
579 | GSA_stats = NULL; | 656 | stats = NULL; |
657 | } | ||
658 | if (NULL != plugin_name) | ||
659 | { | ||
660 | GNUNET_free (plugin_name); | ||
661 | plugin_name = NULL; | ||
580 | } | 662 | } |
581 | } | 663 | } |
582 | 664 | ||
@@ -593,19 +675,41 @@ run (void *cls, | |||
593 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 675 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
594 | struct GNUNET_SERVICE_Handle *service) | 676 | struct GNUNET_SERVICE_Handle *service) |
595 | { | 677 | { |
596 | GSA_stats = GNUNET_STATISTICS_create ("ats", | 678 | static struct GNUNET_ATS_PluginEnvironment env; |
597 | cfg); | 679 | char *solver; |
680 | |||
681 | stats = GNUNET_STATISTICS_create ("ats", | ||
682 | cfg); | ||
683 | if (GNUNET_SYSERR == | ||
684 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
685 | "ats", | ||
686 | "SOLVER", | ||
687 | &solver)) | ||
688 | { | ||
689 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
690 | "No ATS solver configured, using 'simple' approach\n"); | ||
691 | solver = GNUNET_strdup ("simple"); | ||
692 | } | ||
598 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, | 693 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, |
599 | NULL); | 694 | NULL); |
600 | #if 0 | 695 | env.cls = NULL; |
601 | if (GNUNET_OK != | 696 | env.cfg = cfg; |
602 | GAS_plugin_init (cfg)) | 697 | env.stats = stats; |
698 | env.suggest_cb = &suggest_cb; | ||
699 | env.allocate_cb = &allocate_cb; | ||
700 | GNUNET_asprintf (&plugin_name, | ||
701 | "libgnunet_plugin_ats2_%s", | ||
702 | solver); | ||
703 | GNUNET_free (solver); | ||
704 | if (NULL == (plugin = GNUNET_PLUGIN_load (plugin_name, | ||
705 | &env))) | ||
603 | { | 706 | { |
604 | GNUNET_break (0); | 707 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
708 | _("Failed to initialize solver `%s'!\n"), | ||
709 | plugin_name); | ||
605 | GNUNET_SCHEDULER_shutdown (); | 710 | GNUNET_SCHEDULER_shutdown (); |
606 | return; | 711 | return; |
607 | } | 712 | } |
608 | #endif | ||
609 | } | 713 | } |
610 | 714 | ||
611 | 715 | ||
diff --git a/src/include/gnunet_ats_plugin_new.h b/src/include/gnunet_ats_plugin_new.h index 267477871..d2960c9cf 100644 --- a/src/include/gnunet_ats_plugin_new.h +++ b/src/include/gnunet_ats_plugin_new.h | |||
@@ -147,16 +147,40 @@ struct GNUNET_ATS_SolverFunctions | |||
147 | struct GNUNET_ATS_PreferenceHandle *ph, | 147 | struct GNUNET_ATS_PreferenceHandle *ph, |
148 | const struct GNUNET_ATS_Preference *pref); | 148 | const struct GNUNET_ATS_Preference *pref); |
149 | 149 | ||
150 | 150 | /** | |
151 | * Transport established a new session with performance | ||
152 | * characteristics given in @a data. | ||
153 | * | ||
154 | * @param cls closure | ||
155 | * @param data performance characteristics of @a sh | ||
156 | * @param address address information (for debugging) | ||
157 | * @return handle by which the plugin will identify this session | ||
158 | */ | ||
151 | struct GNUNET_ATS_SessionHandle * | 159 | struct GNUNET_ATS_SessionHandle * |
152 | (*session_add)(void *cls, | 160 | (*session_add)(void *cls, |
153 | const struct GNUNET_ATS_SessionData *data); | 161 | const struct GNUNET_ATS_SessionData *data, |
162 | const char *address); | ||
154 | 163 | ||
164 | /** | ||
165 | * @a data changed for a given @a sh, solver should consider | ||
166 | * the updated performance characteristics. | ||
167 | * | ||
168 | * @param cls closure | ||
169 | * @param sh session this is about | ||
170 | * @param data performance characteristics of @a sh | ||
171 | */ | ||
155 | void | 172 | void |
156 | (*session_update)(void *cls, | 173 | (*session_update)(void *cls, |
157 | struct GNUNET_ATS_SessionHandle *sh, | 174 | struct GNUNET_ATS_SessionHandle *sh, |
158 | const struct GNUNET_ATS_SessionData *data); | 175 | const struct GNUNET_ATS_SessionData *data); |
159 | 176 | ||
177 | /** | ||
178 | * A session went away. Solver should update accordingly. | ||
179 | * | ||
180 | * @param cls closure | ||
181 | * @param sh session this is about | ||
182 | * @param data (last) performance characteristics of @a sh | ||
183 | */ | ||
160 | void | 184 | void |
161 | (*session_del)(void *cls, | 185 | (*session_del)(void *cls, |
162 | struct GNUNET_ATS_SessionHandle *sh, | 186 | struct GNUNET_ATS_SessionHandle *sh, |
@@ -164,6 +188,63 @@ struct GNUNET_ATS_SolverFunctions | |||
164 | 188 | ||
165 | }; | 189 | }; |
166 | 190 | ||
191 | |||
192 | /** | ||
193 | * The ATS plugin will pass a pointer to a struct | ||
194 | * of this type as to the initialization function | ||
195 | * of the ATS plugins. | ||
196 | */ | ||
197 | struct GNUNET_ATS_PluginEnvironment | ||
198 | { | ||
199 | /** | ||
200 | * Configuration handle to be used by the solver | ||
201 | */ | ||
202 | const struct GNUNET_CONFIGURATION_Handle *cfg; | ||
203 | |||
204 | /** | ||
205 | * Statistics handle to be used by the solver | ||
206 | */ | ||
207 | struct GNUNET_STATISTICS_Handle *stats; | ||
208 | |||
209 | /** | ||
210 | * Closure to pass to all callbacks in this struct. | ||
211 | */ | ||
212 | void *cls; | ||
213 | |||
214 | /** | ||
215 | * Suggest to the transport that it should try establishing | ||
216 | * a connection using the given address. | ||
217 | * | ||
218 | * @param cls closure, NULL | ||
219 | * @param pid peer this is about | ||
220 | * @param address address the transport should try | ||
221 | */ | ||
222 | void | ||
223 | (*suggest_cb) (void *cls, | ||
224 | const struct GNUNET_PeerIdentity *pid, | ||
225 | const char *address); | ||
226 | |||
227 | /** | ||
228 | * Tell the transport that it should allocate the given | ||
229 | * bandwidth to the specified session. | ||
230 | * | ||
231 | * @param cls closure, NULL | ||
232 | * @param session session this is about | ||
233 | * @param peer peer this is about | ||
234 | * @param bw_in suggested bandwidth for receiving | ||
235 | * @param bw_out suggested bandwidth for transmission | ||
236 | */ | ||
237 | void | ||
238 | (*allocate_cb) (void *cls, | ||
239 | struct GNUNET_ATS_Session *session, | ||
240 | const struct GNUNET_PeerIdentity *peer, | ||
241 | struct GNUNET_BANDWIDTH_Value32NBO bw_in, | ||
242 | struct GNUNET_BANDWIDTH_Value32NBO bw_out); | ||
243 | |||
244 | }; | ||
245 | |||
246 | |||
247 | |||
167 | #endif | 248 | #endif |
168 | 249 | ||
169 | /** @} */ /* end of group */ | 250 | /** @} */ /* end of group */ |
diff --git a/src/transport/.gitignore b/src/transport/.gitignore index 90f908a47..e2f12c230 100644 --- a/src/transport/.gitignore +++ b/src/transport/.gitignore | |||
@@ -84,3 +84,4 @@ test_transport_blacklisting_outbound_bl_plugin | |||
84 | test_transport_testing_restart | 84 | test_transport_testing_restart |
85 | test_transport_testing_startstop | 85 | test_transport_testing_startstop |
86 | gnunet-communicator-unix | 86 | gnunet-communicator-unix |
87 | gnunet-service-tng | ||