41 #define INTERFACE_PROCESSING_INTERVAL GNUNET_TIME_relative_multiply ( \
42 GNUNET_TIME_UNIT_MINUTES, 2)
44 #define LOG(kind, ...) GNUNET_log_from (kind, "ats-scheduling-api", __VA_ARGS__)
186 sh->suggest_cb (
sh->suggest_cb_cls,
256 (NULL !=
sh->session_array[off %
sh->session_array_size])) &&
257 (i < sh->session_array_size))
263 (NULL ==
sh->session_array[off %
sh->session_array_size]))
265 i =
sh->session_array_size;
267 sh->session_array_size,
268 sh->session_array_size * 2);
293 for (i = 1; i <
sh->session_array_size; i++)
294 if ((NULL !=
sh->session_array[i]) &&
296 ((
session ==
sh->session_array[i]->session) ||
297 (NULL ==
sh->session_array[i]->session)) &&
299 &
sh->session_array[i]->address->peer)) &&
301 sh->session_array[i]->address)))
393 if (NULL ==
sh->suggest_cb)
399 if ((0 == ntohl (
m->bandwidth_out.value__)) &&
400 (0 == ntohl (
m->bandwidth_in.value__)))
403 "ATS suggests disconnect from peer `%s' with BW %u/%u\n",
405 (
unsigned int) ntohl (
m->bandwidth_out.value__),
406 (
unsigned int) ntohl (
m->bandwidth_in.value__));
407 sh->suggest_cb (
sh->suggest_cb_cls,
425 "ATS suggests address slot %u for peer `%s' using plugin %s\n",
429 sh->suggest_cb (
sh->suggest_cb_cls,
452 "ATS connection died (code %d), reconnecting\n",
484 m->plugin_name_length = htons (namelen);
485 m->session_id = htonl (ar->
slot);
489 "Adding address for peer `%s', plugin `%s', session %p slot %u\n",
548 for (i = 0; i <
sh->session_array_size; i++)
550 ar =
sh->session_array[i];
572 sh->session_array_size,
595 if (NULL !=
sh->task)
600 for (i = 0; i <
sh->session_array_size; i++)
602 if (NULL != (ar =
sh->session_array[i]))
606 sh->session_array[i] = NULL;
610 sh->session_array_size,
646 namelen = strlen (
address->transport_name) + 1;
647 msize =
address->address_length + namelen;
675 sh->session_array[s] = ar;
732 "Updating address for peer `%s', plugin `%s', session %p slot %u\n",
743 m->session_id = htonl (ar->
slot);
764 "Deleting address for peer `%s', plugin `%s', slot %u session %p\n",
775 m->session_id = htonl (ar->
slot);
automatic transport selection messages
@ START_FLAG_SCHEDULING
This is a scheduling client (aka transport service)
static void force_reconnect(struct GNUNET_ATS_SchedulingHandle *sh)
Disconnect from ATS and then reconnect.
#define NOT_FOUND
Session ID we use if there is no session / slot.
static void release_session(struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id)
Release the session slot from the session table (ATS service is also done using it).
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
We encountered an error handling the MQ to the ATS service.
static struct GNUNET_ATS_AddressRecord * find_session(struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id, const struct GNUNET_PeerIdentity *peer)
Find the session object corresponding to the given session ID.
static void handle_ats_session_release(void *cls, const struct GNUNET_ATS_SessionReleaseMessage *srm)
Type of a function to call when we receive a session release message from the service.
static uint32_t find_session_id(struct GNUNET_ATS_SchedulingHandle *sh, struct GNUNET_ATS_Session *session, const struct GNUNET_HELLO_Address *address)
Get the ID for the given session object.
static void send_add_address_message(struct GNUNET_ATS_SchedulingHandle *sh, const struct GNUNET_ATS_AddressRecord *ar)
Generate and transmit the struct AddressAddMessage for the given address record.
static void reconnect(struct GNUNET_ATS_SchedulingHandle *sh)
Re-establish the connection to the ATS service.
static uint32_t find_empty_session_slot(struct GNUNET_ATS_SchedulingHandle *sh)
Get an available session ID.
static void reconnect_task(void *cls)
Re-establish the connection to the ATS service.
static void handle_ats_address_suggestion(void *cls, const struct AddressSuggestionMessage *m)
Type of a function to call when we receive a address suggestion message from the service.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
static char * init
Set to the name of a service to start.
static struct SolverHandle * sh
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_HashCode session_id
static char * address
GNS address for this phone.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
Automatic transport selection and outbound bandwidth determination.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
void GNUNET_ATS_address_add_session(struct GNUNET_ATS_AddressRecord *ar, struct GNUNET_ATS_Session *session)
An address was used to initiate a session.
struct GNUNET_ATS_SchedulingHandle * GNUNET_ATS_scheduling_init(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_ATS_AddressSuggestionCallback suggest_cb, void *suggest_cb_cls)
Initialize the ATS scheduling subsystem.
void GNUNET_ATS_address_update(struct GNUNET_ATS_AddressRecord *ar, const struct GNUNET_ATS_Properties *prop)
We have updated performance statistics for a given address.
void GNUNET_ATS_properties_hton(struct GNUNET_ATS_PropertiesNBO *nbo, const struct GNUNET_ATS_Properties *hbo)
Convert ATS properties from host to network byte order.
int GNUNET_ATS_address_del_session(struct GNUNET_ATS_AddressRecord *ar, struct GNUNET_ATS_Session *session)
A session was destroyed, disassociate it from the given address record.
void(* GNUNET_ATS_AddressSuggestionCallback)(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
Signature of a function called by ATS with the current bandwidth and address preferences as determine...
void GNUNET_ATS_address_destroy(struct GNUNET_ATS_AddressRecord *ar)
An address got destroyed, stop using it as a valid address.
void GNUNET_ATS_scheduling_done(struct GNUNET_ATS_SchedulingHandle *sh)
Client is done with ATS scheduling, release resources.
struct GNUNET_ATS_AddressRecord * GNUNET_ATS_address_add(struct GNUNET_ATS_SchedulingHandle *sh, const struct GNUNET_HELLO_Address *address, struct GNUNET_ATS_Session *session, const struct GNUNET_ATS_Properties *prop)
We have a new address ATS should know.
#define GNUNET_BANDWIDTH_ZERO
Convenience definition to use for 0-bandwidth.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
#define GNUNET_HELLO_address_free(addr)
Free an address.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
int GNUNET_HELLO_address_check_option(const struct GNUNET_HELLO_Address *address, enum GNUNET_HELLO_AddressInfo option)
Check if an address has a local option set.
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
@ GNUNET_HELLO_ADDRESS_INFO_INBOUND
This is an inbound address and cannot be used to initiate an outbound connection to another peer.
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_array_grow(arr, size, tsize)
Grow a well-typed (!) array.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
@ GNUNET_NT_UNSPECIFIED
Category of last resort.
#define GNUNET_MESSAGE_TYPE_ATS_START
Type of the 'struct ClientStartMessage' sent by clients to ATS to identify the type of the client.
#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE
Type of the 'struct AddressUpdateMessage' sent by clients to ATS to inform ATS about performance chan...
#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION
Type of the 'struct AddressSuggestionMessage' sent by ATS to clients to suggest switching to a differ...
#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_ADD
Type of the 'struct AddressUpdateMessage' sent by client to ATS to add a new address.
#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED
Type of the 'struct AddressDestroyedMessage' sent by clients to ATS to inform ATS about an address be...
#define GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE
Type of the 'struct SessionReleaseMessage' sent by ATS to client to confirm that a session ID was des...
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
Scheduling client to ATS service: here is another address you can use.
Message sent by ATS client to ATS service when an address was destroyed and must thus henceforth no l...
ATS Service suggests to the transport service to use the address identified by the given session_id f...
Message used to notify ATS that the performance characteristics for an address have changed.
First message any client sends to ATS, used to self-identify (what type of client this is).
Information we track per address, incoming or outgoing.
struct GNUNET_HELLO_Address * address
Address data.
struct GNUNET_ATS_Session * session
Session handle.
int in_destroy
We're about to destroy this address record, just ATS does not know this yet.
uint32_t slot
Which slot (index) in the session array does this record correspond to? FIXME: a linear search on thi...
struct GNUNET_ATS_SchedulingHandle * sh
Scheduling handle this address record belongs to.
struct GNUNET_ATS_PropertiesNBO properties
Performance data about the address.
ATS performance characteristics for an address in network byte order (for IPC).
uint32_t scope
Which network scope does the respective address belong to? This property does not change.
ATS performance characteristics for an address.
enum GNUNET_NetworkType scope
Which network scope does the respective address belong to? This property does not change.
Handle to the ATS subsystem for bandwidth/transport scheduling information.
struct GNUNET_SCHEDULER_Task * task
Task to trigger reconnect.
unsigned int session_array_size
Size of the session_array.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_ATS_AddressRecord ** session_array
Array of session objects (we need to translate them to numbers and back for the protocol; the offset ...
void * suggest_cb_cls
Closure for suggest_cb.
GNUNET_ATS_AddressSuggestionCallback suggest_cb
Callback to invoke on suggestions.
struct GNUNET_TIME_Relative backoff
Reconnect backoff delay.
struct GNUNET_MQ_Handle * mq
Message queue for sending requests to the ATS service.
Message sent by ATS service to client to confirm that it is done using the given session ID.
uint32_t session_id
Number the client used to identify the session.
Session handle for connections.
An address for communicating with a peer.
const char * transport_name
Name of the transport plugin enabling the communication using this address.
size_t address_length
Number of bytes in address.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
enum GNUNET_HELLO_AddressInfo local_info
Extended information about address.
const void * address
Binary representation of the address (plugin-specific).
Handle to a message queue.
Message handler for a specific message type.
The identity of the host (wraps the signing key of the peer).
Entry in list of pending tasks.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.