aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats-new.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/gnunet-service-ats-new.c')
-rw-r--r--src/ats/gnunet-service-ats-new.c140
1 files changed, 122 insertions, 18 deletions
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 */
179static struct GNUNET_STATISTICS_Handle *GSA_stats; 177static 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;
184static struct GNUNET_ATS_SolverFunctions *plugin; 182static struct GNUNET_ATS_SolverFunctions *plugin;
185 183
186/** 184/**
185 * Solver plugin name as string
186 */
187static 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 */
189static struct Client *transport_client; 192static 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 */
203static void
204suggest_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 */
239static void
240allocate_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