GNUnet  0.10.x
gnunet-service-ats-new.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011, 2018 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
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/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
29 #include "gnunet_ats_plugin_new.h"
30 #include "ats2.h"
31 
32 
36 enum ClientType {
40  CT_NONE = 0,
41 
46 
51 };
52 
53 
57 struct Client;
58 
67 
72 
76  struct Client *client;
77 
81  struct GNUNET_ATS_PreferenceHandle *ph;
82 
87 };
88 
89 
98 
102  struct Client *client;
103 
108 
112  uint32_t session_id;
113 };
114 
115 
119 struct Client {
124 
129 
134 
138  union {
139  struct {
144 
149  } application;
150 
151  struct {
156  } transport;
157  } details;
158 };
159 
160 
165 
170 
174 static char *plugin_name;
175 
179 static struct Client *transport_client;
180 
181 
190 static void
191 suggest_cb(void *cls,
192  const struct GNUNET_PeerIdentity *pid,
193  const char *address)
194 {
195  struct GNUNET_MQ_Envelope *env;
196  size_t slen = strlen(address) + 1;
197  struct AddressSuggestionMessage *as;
198 
199  if (NULL == transport_client)
200  {
201  // FIXME: stats!
202  return;
203  }
205  "Suggesting address `%s' of peer `%s'\n",
206  address,
207  GNUNET_i2s(pid));
208  env = GNUNET_MQ_msg_extra(as,
209  slen,
211  as->peer = *pid;
212  memcpy(&as[1],
213  address,
214  slen);
215  GNUNET_MQ_send(transport_client->mq,
216  env);
217 }
218 
219 
230 static void
231 allocate_cb(void *cls,
232  struct GNUNET_ATS_Session *session,
233  const struct GNUNET_PeerIdentity *peer,
234  struct GNUNET_BANDWIDTH_Value32NBO bw_in,
235  struct GNUNET_BANDWIDTH_Value32NBO bw_out)
236 {
237  struct GNUNET_MQ_Envelope *env;
238  struct SessionAllocationMessage *sam;
239 
240  (void)cls;
241  if ((NULL == transport_client) ||
242  (session->client != transport_client))
243  {
244  /* transport must have just died and solver is addressing the
245  losses of sessions (possibly of previous transport), ignore! */
246  return;
247  }
249  "Allocating %u/%u bytes for %p of peer `%s'\n",
250  ntohl(bw_in.value__),
251  ntohl(bw_out.value__),
252  session,
253  GNUNET_i2s(peer));
254  env = GNUNET_MQ_msg(sam,
256  sam->session_id = session->session_id;
257  sam->peer = *peer;
258  sam->bandwidth_in = bw_in;
259  sam->bandwidth_out = bw_out;
260  GNUNET_MQ_send(transport_client->mq,
261  env);
262 }
263 
264 
271 static void
272 prop_ntoh(const struct PropertiesNBO *properties,
273  struct GNUNET_ATS_Properties *prop)
274 {
275  prop->delay = GNUNET_TIME_relative_ntoh(properties->delay);
276  prop->goodput_out = ntohl(properties->goodput_out);
277  prop->goodput_in = ntohl(properties->goodput_in);
278  prop->utilization_out = ntohl(properties->utilization_out);
279  prop->utilization_in = ntohl(properties->utilization_in);
280  prop->distance = ntohl(properties->distance);
281  prop->mtu = ntohl(properties->mtu);
282  prop->nt = (enum GNUNET_NetworkType)ntohl(properties->nt);
283  prop->cc = (enum GNUNET_TRANSPORT_CommunicatorCharacteristics)ntohl(properties->cc);
284 }
285 
286 
293 static void
294 handle_suggest(void *cls,
295  const struct ExpressPreferenceMessage *msg)
296 {
297  struct Client *c = cls;
298  struct ClientPreference *cp;
299 
300  if (CT_NONE == c->type)
301  c->type = CT_APPLICATION;
302  if (CT_APPLICATION != c->type)
303  {
304  GNUNET_break(0);
306  return;
307  }
309  "Client suggested we talk to %s with preference %d at rate %u\n",
310  GNUNET_i2s(&msg->peer),
311  (int)ntohl(msg->pk),
312  (int)ntohl(msg->bw.value__));
313  cp = GNUNET_new(struct ClientPreference);
314  cp->client = c;
315  cp->pref.peer = msg->peer;
316  cp->pref.bw = msg->bw;
317  cp->pref.pk = (enum GNUNET_MQ_PreferenceKind)ntohl(msg->pk);
318  cp->ph = plugin->preference_add(plugin->cls,
319  &cp->pref);
321  c->details.application.cp_tail,
322  cp);
324 }
325 
326 
333 static void
335  const struct ExpressPreferenceMessage *msg)
336 {
337  struct Client *c = cls;
338  struct ClientPreference *cp;
339 
340  if (CT_NONE == c->type)
341  c->type = CT_APPLICATION;
342  if (CT_APPLICATION != c->type)
343  {
344  GNUNET_break(0);
346  return;
347  }
348  for (cp = c->details.application.cp_head;
349  NULL != cp;
350  cp = cp->next)
351  if ((cp->pref.pk == (enum GNUNET_MQ_PreferenceKind)ntohl(msg->pk)) &&
352  (cp->pref.bw.value__ == msg->bw.value__) &&
353  (0 == GNUNET_memcmp(&cp->pref.peer,
354  &msg->peer)))
355  break;
356  if (NULL == cp)
357  {
358  GNUNET_break(0);
360  return;
361  }
362  plugin->preference_del(plugin->cls,
363  cp->ph,
364  &cp->pref);
366  c->details.application.cp_tail,
367  cp);
368  GNUNET_free(cp);
370 }
371 
372 
379 static void
380 handle_start(void *cls,
381  const struct GNUNET_MessageHeader *hdr)
382 {
383  struct Client *c = cls;
384 
385  if (CT_NONE != c->type)
386  {
387  GNUNET_break(0);
389  return;
390  }
391  c->type = CT_TRANSPORT;
392  c->details.transport.sessions
394  if (NULL != transport_client)
395  {
396  GNUNET_SERVICE_client_drop(transport_client->client);
397  transport_client = NULL;
398  }
399  transport_client = c;
401 }
402 
403 
412 static int
414  const struct SessionAddMessage *message)
415 {
416  struct Client *c = cls;
417 
419  if (CT_TRANSPORT != c->type)
420  {
421  GNUNET_break(0);
422  return GNUNET_SYSERR;
423  }
424  return GNUNET_OK;
425 }
426 
427 
434 static void
436  const struct SessionAddMessage *message)
437 {
438  struct Client *c = cls;
439  const char *address = (const char *)&message[1];
440  struct GNUNET_ATS_Session *session;
442  ntohs(message->header.type));
443 
445  message->session_id);
446  if (NULL != session)
447  {
448  GNUNET_break(0);
450  return;
451  }
452  session = GNUNET_new(struct GNUNET_ATS_Session);
453  session->data.session = session;
454  session->client = c;
455  session->session_id = message->session_id;
456  session->data.peer = message->peer;
457  prop_ntoh(&message->properties,
458  &session->data.prop);
459  session->data.inbound_only = inbound_only;
462  message->session_id,
463  session,
465  session->sh = plugin->session_add(plugin->cls,
466  &session->data,
467  address);
468  GNUNET_assert(NULL != session->sh);
470  "Transport has new session %p to %s\n",
471  session,
472  GNUNET_i2s(&message->peer));
474 }
475 
476 
483 static void
485  const struct SessionUpdateMessage *msg)
486 {
487  struct Client *c = cls;
488  struct GNUNET_ATS_Session *session;
489 
490  if (CT_TRANSPORT != c->type)
491  {
492  GNUNET_break(0);
494  return;
495  }
497  msg->session_id);
498  if (NULL == session)
499  {
500  GNUNET_break(0);
502  return;
503  }
504  prop_ntoh(&msg->properties,
505  &session->data.prop);
506  plugin->session_update(plugin->cls,
507  session->sh,
508  &session->data);
510 }
511 
512 
519 static void
521  const struct SessionDelMessage *message)
522 {
523  struct Client *c = cls;
524  struct GNUNET_ATS_Session *session;
525 
526  if (CT_TRANSPORT != c->type)
527  {
528  GNUNET_break(0);
530  return;
531  }
533  message->session_id);
534  if (NULL == session)
535  {
536  GNUNET_break(0);
538  return;
539  }
540  GNUNET_assert(NULL != session->sh);
541  plugin->session_del(plugin->cls,
542  session->sh,
543  &session->data);
544  session->sh = NULL;
547  session->session_id,
548  session));
550  "Transport lost session %p to %s\n",
551  session,
552  GNUNET_i2s(&session->data.peer));
553  GNUNET_free(session);
555 }
556 
557 
567 static void *
570  struct GNUNET_MQ_Handle *mq)
571 {
572  struct Client *c = GNUNET_new(struct Client);
573 
574  c->client = client;
575  c->mq = mq;
576  return c;
577 }
578 
579 
588 static int
589 free_session(void *cls,
590  uint32_t key,
591  void *value)
592 {
593  struct Client *c = cls;
594  struct GNUNET_ATS_Session *session = value;
595 
596  (void)key;
597  GNUNET_assert(c == session->client);
598  GNUNET_assert(NULL != session->sh);
599  plugin->session_del(plugin->cls,
600  session->sh,
601  &session->data);
602  session->sh = NULL;
603  GNUNET_free(session);
604  return GNUNET_OK;
605 }
606 
607 
616 static void
619  void *app_ctx)
620 {
621  struct Client *c = app_ctx;
622 
623  (void)cls;
624  GNUNET_assert(c->client == client);
625  switch (c->type)
626  {
627  case CT_NONE:
628  break;
629 
630  case CT_APPLICATION:
631  for (struct ClientPreference *cp = c->details.application.cp_head;
632  NULL != cp;
633  cp = c->details.application.cp_head)
634  {
635  plugin->preference_del(plugin->cls,
636  cp->ph,
637  &cp->pref);
639  c->details.application.cp_tail,
640  cp);
641  GNUNET_free(cp);
642  }
643  break;
644 
645  case CT_TRANSPORT:
646  if (transport_client == c)
647  transport_client = NULL;
649  &free_session,
650  c);
652  break;
653  }
654  GNUNET_free(c);
655 }
656 
657 
663 static void
664 final_cleanup(void *cls)
665 {
666  (void)cls;
667  if (NULL != stats)
668  {
670  GNUNET_NO);
671  stats = NULL;
672  }
673  if (NULL != plugin)
674  {
676  plugin);
677  plugin = NULL;
678  }
679  if (NULL != plugin_name)
680  {
682  plugin_name = NULL;
683  }
684 }
685 
686 
692 static void
693 cleanup_task(void *cls)
694 {
695  (void)cls;
697  "ATS shutdown initiated\n");
699  NULL);
700 }
701 
702 
710 static void
711 run(void *cls,
712  const struct GNUNET_CONFIGURATION_Handle *cfg,
714 {
715  static struct GNUNET_ATS_PluginEnvironment env;
716  char *solver;
717 
718  stats = GNUNET_STATISTICS_create("ats",
719  cfg);
720  if (GNUNET_SYSERR ==
722  "ats",
723  "SOLVER",
724  &solver))
725  {
727  "No ATS solver configured, using 'simple' approach\n");
728  solver = GNUNET_strdup("simple");
729  }
731  NULL);
732  env.cls = NULL;
733  env.cfg = cfg;
734  env.stats = stats;
735  env.suggest_cb = &suggest_cb;
736  env.allocate_cb = &allocate_cb;
738  "libgnunet_plugin_ats2_%s",
739  solver);
740  GNUNET_free(solver);
741  if (NULL == (plugin = GNUNET_PLUGIN_load(plugin_name,
742  &env)))
743  {
745  _("Failed to initialize solver `%s'!\n"),
746  plugin_name);
748  return;
749  }
750 }
751 
752 
757  ("ats",
759  &run,
762  NULL,
763  GNUNET_MQ_hd_fixed_size(suggest,
766  NULL),
767  GNUNET_MQ_hd_fixed_size(suggest_cancel,
770  NULL),
773  struct GNUNET_MessageHeader,
774  NULL),
775  GNUNET_MQ_hd_var_size(session_add,
777  struct SessionAddMessage,
778  NULL),
779  GNUNET_MQ_hd_var_size(session_add,
781  struct SessionAddMessage,
782  NULL),
783  GNUNET_MQ_hd_fixed_size(session_update,
785  struct SessionUpdateMessage,
786  NULL),
787  GNUNET_MQ_hd_fixed_size(session_del,
789  struct SessionDelMessage,
790  NULL),
792 
793 
794 /* end of gnunet-service-ats.c */
GNUNET_TRANSPORT_CommunicatorCharacteristics
What characteristics does this communicator have?
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
Message sent by ATS client to ATS service when an session was destroyed and must thus henceforth no l...
Definition: ats2.h:201
struct Client::@0::@2 transport
static struct GNUNET_STATISTICS_Handle * stats
Handle for statistics.
static void allocate_cb(void *cls, struct GNUNET_ATS_Session *session, const struct GNUNET_PeerIdentity *peer, struct GNUNET_BANDWIDTH_Value32NBO bw_in, struct GNUNET_BANDWIDTH_Value32NBO bw_out)
Function called by the solver to tell the transpor to allocate bandwidth for the specified session...
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
uint32_t cc
What characteristics does this communicator have? A enum GNUNET_TRANSPORT_CommunicatorCharacteristics...
Definition: ats2.h:101
#define GNUNET_MESSAGE_TYPE_ATS_START
Type of the &#39;struct ClientStartMessage&#39; sent by clients to ATS to identify the type of the client...
Information we track per client.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
uint32_t utilization_in
Actual traffic on this connection from the other peer to this peer.
Definition: ats2.h:76
static void final_cleanup(void *cls)
Task run at the end during shutdown.
struct GNUNET_ATS_Session * session
Handle to the session that has the given properties.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
We don&#39;t know yet.
struct GNUNET_STATISTICS_Handle * stats
Statistics handle to be used by the solver.
struct GNUNET_SERVICE_Client * client
Service handle of the client.
void(* session_update)(void *cls, struct GNUNET_ATS_SessionHandle *sh, const struct GNUNET_ATS_SessionData *data)
data changed for a given sh, solver should consider the updated performance characteristics.
uint32_t goodput_out
Confirmed successful payload on this connection from this peer to the other peer. ...
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg, struct GNUNET_SERVICE_Handle *service)
Process template requests.
Handle to a service.
Definition: service.c:114
uint32_t utilization_in
Actual traffic on this connection from the other peer to this peer.
static void handle_session_update(void *cls, const struct SessionUpdateMessage *msg)
Handle &#39;session update&#39; messages from transport clients.
struct GNUNET_PeerIdentity peer
Which peer is this about? (Technically redundant, as the session_id should be sufficient, but may enable client to find the session faster and/or check consistency).
Definition: ats2.h:243
uint32_t session_id
Internal number this client will henceforth use to refer to this session.
Definition: ats2.h:149
uint32_t session_id
Unique ID for the session when talking with the client.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1284
struct GNUNET_ATS_SessionHandle * sh
Session state in the plugin.
enum GNUNET_MQ_PreferenceKind pk
What type of performance preference does the client have?
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
static int start
Set if we are to start default services (including ARM).
Definition: gnunet-arm.c:39
int GNUNET_CONTAINER_multihashmap32_iterate(struct GNUNET_CONTAINER_MultiHashMap32 *map, GNUNET_CONTAINER_MulitHashMapIterator32Callback it, void *it_cls)
Iterate over all entries in the map.
Internal representation of a session by the plugin.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MQ_Handle * mq
Message queue to talk to the client.
struct ClientPreference * prev
DLL pointer.
#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION
Type of the &#39;struct AddressSuggestionMessage&#39; sent by ATS to clients to suggest switching to a differ...
static struct GNUNET_TRANSPORT_CoreHandle * transport
Transport service.
enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc
What characteristics does this communicator have?
struct Client * client
Which client expressed the preference?
uint32_t goodput_out
Confirmed successful payload on this connection from this peer to the other peer. ...
Definition: ats2.h:52
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_PeerIdentity peer
Peer the session is with.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int free_session(void *cls, uint32_t key, void *value)
Function called on each session to release associated state on transport disconnect.
Preferences expressed by a client are kept in a DLL per client.
Transport service.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
static struct Client * transport_client
The transport client (there can only be one at a time).
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
Handle for the service.
struct Client::@0::@1 application
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
int GNUNET_CONTAINER_multihashmap32_put(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
ATS performance characteristics for an address.
uint32_t session_id
Internal number this client uses to refer to this session.
Definition: ats2.h:180
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY
Type of the &#39;struct SessionAddMessage&#39; send by transport clients to ATS to inform ATS about a session...
Transport client to ATS service: here is another session you can use.
Definition: ats2.h:138
static int inbound_only
Option -i.
#define GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION
Type of the &#39;struct SessionAllocationMessage&#39; send by ATS to the transport to tell it about resources...
uint32_t value__
The actual value (bytes per second).
uint32_t utilization_out
Actual traffic on this connection from this peer to the other peer.
Definition: ats2.h:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
uint32_t pk
What type of performance preference does the client have? A enum GNUNET_MQ_PreferenceKind in NBO...
Definition: ats2.h:121
void * GNUNET_PLUGIN_unload(const char *library_name, void *arg)
Unload plugin (runs the "done" callback and returns whatever "done" returned).
Definition: plugin.c:255
void(* session_del)(void *cls, struct GNUNET_ATS_SessionHandle *sh, const struct GNUNET_ATS_SessionData *data)
A session went away.
static void handle_session_del(void *cls, const struct SessionDelMessage *message)
Handle &#39;session delete&#39; messages from transport clients.
Handle to a client that is connected to a service.
Definition: service.c:246
static void cleanup_task(void *cls)
Task run during shutdown.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
uint32_t mtu
MTU of the network layer, UINT32_MAX for no MTU (stream).
Definition: ats2.h:89
struct GNUNET_CONTAINER_MultiHashMap32 * sessions
Map from session IDs to struct GNUNET_ATS_Session objects.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
struct ClientPreference * cp_tail
Tail of DLL of preferences expressed by this client.
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
GNUNET_MQ_PreferenceKind
Enum defining all known preference categories.
int GNUNET_CONTAINER_multihashmap32_remove(struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key, const void *value)
Remove the given key-value pair from the map.
uint32_t distance
Distance on network layer (required for distance-vector routing) in hops.
Definition: ats2.h:82
static char * value
Value of the record to add/remove.
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD or GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY.
Definition: ats2.h:143
Information about ongoing sessions of the transport client.
void * GNUNET_CONTAINER_multihashmap32_get(const struct GNUNET_CONTAINER_MultiHashMap32 *map, uint32_t key)
Given a key find a value in the map matching the key.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
struct GNUNET_ATS_PreferenceHandle *(* preference_add)(void *cls, const struct GNUNET_ATS_Preference *pref)
The plugin should begin to respect a new preference.
Message used to notify ATS that the performance characteristics for an session have changed...
Definition: ats2.h:171
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1264
static int check_session_add(void *cls, const struct SessionAddMessage *message)
Check &#39;session_add&#39; message is well-formed and comes from a transport client.
struct GNUNET_TIME_Relative delay
Delay.
ATS Service allocates resources to an session identified by the given session_id for the given peer w...
Definition: ats2.h:226
Preference being expressed by an application client.
uint32_t session_id
Internal number this client uses to refer to this session.
Definition: ats2.h:210
static char * plugin_name
Solver plugin name as string.
Internal representation of the hash map.
static void handle_suggest(void *cls, const struct ExpressPreferenceMessage *msg)
We have received a struct ExpressPreferenceMessage from an application client.
automatic transport selection messages
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
How much bandwidth we are allowed for sending.
Definition: ats2.h:248
struct GNUNET_TIME_Relative GNUNET_TIME_relative_ntoh(struct GNUNET_TIME_RelativeNBO a)
Convert relative time from network byte order.
Definition: time.c:639
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2315
uint32_t goodput_in
Confirmed useful payload on this connection to this peer from the other peer.
struct GNUNET_ATS_SessionHandle *(* session_add)(void *cls, const struct GNUNET_ATS_SessionData *data, const char *address)
Transport established a new session with performance characteristics given in data.
uint32_t session_id
Internal number this client uses to refer to the session this suggestion is about.
Definition: ats2.h:236
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
A client disconnected from us.
struct GNUNET_CONTAINER_MultiHashMap32 * GNUNET_CONTAINER_multihashmap32_create(unsigned int len)
Create a 32-bit key multi hash map.
void GNUNET_CONTAINER_multihashmap32_destroy(struct GNUNET_CONTAINER_MultiHashMap32 *map)
Destroy a 32-bit key hash map.
int GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
There must only be one value per key; storing a value should fail if a value under the same key alrea...
uint32_t mtu
MTU of the network layer, UINT32_MAX for no MTU (stream).
static void handle_start(void *cls, const struct GNUNET_MessageHeader *hdr)
Handle &#39;start&#39; messages from transport clients.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
struct GNUNET_HashCode key
The key used in the DHT.
struct PropertiesNBO properties
Performance properties of the session.
Definition: ats2.h:192
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
#define GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE
Type of the &#39;struct SessionUpdateMessage&#39; send by transport clients to ATS to inform ATS about proper...
uint32_t nt
Which network scope does the respective address belong to? A enum GNUNET_NetworkType nt in NBO...
Definition: ats2.h:95
struct GNUNET_BANDWIDTH_Value32NBO bw
How much bandwidth in bytes/second does the application expect?
#define GNUNET_MESSAGE_TYPE_ATS_SUGGEST
Type of the &#39;struct ExpressPreferenceMessage&#39; send by clients to ATS to establish bandwidth preferenc...
int inbound_only
Is the session inbound only?
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void * cls
Closure to pass to all solver functions in this struct.
Plugin-relevant information about a session.
struct GNUNET_PeerIdentity peer
Identity of the peer that this session is for.
Definition: ats2.h:154
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
#define GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL
Type of the &#39;struct ExpressPreferenceMessage&#39; send by clients to ATS to abandon bandwidth preference...
enum GNUNET_NetworkType nt
Which network scope does the respective address belong to?
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
ATS Service suggests to the transport service to use the address identified by the given session_id f...
Definition: ats.h:237
enum ClientType type
Type of the client, initially CT_NONE.
struct GNUNET_ATS_Preference pref
Details about the preference.
static void suggest_cb(void *cls, const struct GNUNET_PeerIdentity *pid, const char *address)
Function called by the solver to prompt the transport to try out a new address.
Handle to a message queue.
Definition: mq.c:84
void(* suggest_cb)(void *cls, const struct GNUNET_PeerIdentity *pid, const char *address)
Suggest to the transport that it should try establishing a connection using the given address...
The identity of the host (wraps the signing key of the peer).
void(* allocate_cb)(void *cls, struct GNUNET_ATS_Session *session, const struct GNUNET_PeerIdentity *peer, struct GNUNET_BANDWIDTH_Value32NBO bw_in, struct GNUNET_BANDWIDTH_Value32NBO bw_out)
Tell the transport that it should allocate the given bandwidth to the specified session.
struct GNUNET_ATS_PreferenceHandle * ph
Plugin&#39;s representation of the preference.
struct GNUNET_ATS_SessionData data
Session data exposed to the plugin.
configuration data
Definition: configuration.c:83
void(* preference_del)(void *cls, struct GNUNET_ATS_PreferenceHandle *ph, const struct GNUNET_ATS_Preference *pref)
The plugin should end respecting a preference.
struct GNUNET_TIME_RelativeNBO delay
Delay.
Definition: ats2.h:44
static void * client_connect_cb(void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
A client connected to us.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle to be used by the solver.
#define GNUNET_log(kind,...)
static void prop_ntoh(const struct PropertiesNBO *properties, struct GNUNET_ATS_Properties *prop)
Convert properties to prop.
static void handle_session_add(void *cls, const struct SessionAddMessage *message)
Handle &#39;session add&#39; messages from transport clients.
uint32_t goodput_in
Confirmed useful payload on this connection to this peer from the other peer.
Definition: ats2.h:60
struct Client * client
The transport client that provided the session.
static void handle_suggest_cancel(void *cls, const struct ExpressPreferenceMessage *msg)
We have received a struct ExpressPreferenceMessage from an application client.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
#define GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL
Type of the &#39;struct SessionDelMessage&#39; send by transport clients to ATS to tell ATS that a session is...
void * cls
Closure to pass to all callbacks in this struct.
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_PeerIdentity peer
Which peer is this about? (Technically redundant, as the session_id should be sufficient, but may enable client to find the session faster and/or check consistency).
Definition: ats.h:254
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:206
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:351
struct ClientPreference * next
DLL pointer.
union Client::@0 details
Details depending on type.
struct GNUNET_PeerIdentity peer
Peer to get address suggestions for.
struct ClientPreference * cp_head
Head of DLL of preferences expressed by this client.
ATS performance characteristics for an address.
Definition: ats2.h:39
The ATS plugin will pass a pointer to a struct of this type as to the initialization function of the ...
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
ClientType
What type of client is this client?
struct GNUNET_BANDWIDTH_Value32NBO bw
How much bandwidth in bytes/second does the application expect?
Definition: ats2.h:131
uint32_t data
The data value.
Application client to ATS service: we would like to have address suggestions for this peer...
Definition: ats2.h:109
unsigned int distance
Distance on network layer (required for distance-vector routing) in hops.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
How much bandwidth we are allowed for receiving.
Definition: ats2.h:253
static char * address
GNS address for this phone.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2234
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
GNUNET_SERVICE_MAIN("ats", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_fixed_size(suggest, GNUNET_MESSAGE_TYPE_ATS_SUGGEST, struct ExpressPreferenceMessage, NULL), GNUNET_MQ_hd_fixed_size(suggest_cancel, GNUNET_MESSAGE_TYPE_ATS_SUGGEST_CANCEL, struct ExpressPreferenceMessage, NULL), GNUNET_MQ_hd_fixed_size(start, GNUNET_MESSAGE_TYPE_ATS_START, struct GNUNET_MessageHeader, NULL), GNUNET_MQ_hd_var_size(session_add, GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD, struct SessionAddMessage, NULL), GNUNET_MQ_hd_var_size(session_add, GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY, struct SessionAddMessage, NULL), GNUNET_MQ_hd_fixed_size(session_update, GNUNET_MESSAGE_TYPE_ATS_SESSION_UPDATE, struct SessionUpdateMessage, NULL), GNUNET_MQ_hd_fixed_size(session_del, GNUNET_MESSAGE_TYPE_ATS_SESSION_DEL, struct SessionDelMessage, NULL), GNUNET_MQ_handler_end())
Define "main" method using service macro.
struct PropertiesNBO properties
Performance properties of the session.
Definition: ats2.h:159
#define GNUNET_free(ptr)
Wrapper around free.
uint32_t utilization_out
Actual traffic on this connection from this peer to the other peer.
struct GNUNET_PeerIdentity peer
Peer to get address suggestions for.
Definition: ats2.h:126
#define GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD
Type of the &#39;struct SessionAddMessage&#39; send by transport clients to ATS to ask ATS to allocate resour...
struct GNUNET_ATS_Properties prop
ATS performance characteristics for a session.