-struct GNUNET_ATS_PerformanceMonitorHandle
-{
- struct GNUNET_ATS_PerformanceMonitorHandle *next;
- struct GNUNET_ATS_PerformanceMonitorHandle *prev;
-
- struct GNUNET_ATS_PerformanceHandle * ph;
-
- GNUNET_ATS_PerformanceMonitorCb moncb;
- void *moncb_cls;
-
- uint32_t id;
-};
-
-
/**
* ATS Handle to obtain and/or modify performance information.
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
- * Callback to invoke on performance changes.
+ * Callback to invoke when an address has performance changes.
*/
- GNUNET_ATS_AddressInformationCallback infocb;
+ GNUNET_ATS_AddressInformationCallback addr_info_cb;
/**
- * Closure for 'infocb'.
+ * Closure for 'addr_info_cb'.
*/
- void *infocb_cls;
+ void *addr_info_cb_cls;
/**
* Connection to ATS service.
*/
struct GNUNET_ATS_AddressListHandle *addresslist_tail;
- /**
- * Head of linked list of pending performance monitors.
- */
- struct GNUNET_ATS_PerformanceMonitorHandle *monitor_head;
-
- /**
- * Tail of linked list of pending performance monitors.
- */
- struct GNUNET_ATS_PerformanceMonitorHandle *monitor_tail;
/**
* Current request for transmission to ATS.
uint16_t plugin_address_length;
uint16_t plugin_name_length;
uint32_t ats_count;
+ int addr_active;
if (ntohs (msg->size) < sizeof (struct PeerInformationMessage))
{
ats_count = ntohl (pi->ats_count);
plugin_address_length = ntohs (pi->address_length);
plugin_name_length = ntohs (pi->plugin_name_length);
+ addr_active = ntohl (pi->address_active);
atsi = (const struct GNUNET_ATS_Information *) &pi[1];
plugin_address = (const char *) &atsi[ats_count];
plugin_name = &plugin_address[plugin_address_length];
GNUNET_break (0);
return GNUNET_SYSERR;
}
- if (ph->infocb == NULL)
+
+ if (NULL != ph->addr_info_cb)
{
- return GNUNET_OK;
- }
+ address.peer = pi->peer;
+ address.address = plugin_address;
+ address.address_length = plugin_address_length;
+ address.transport_name = plugin_name;
- address.peer = pi->peer;
- address.address = plugin_address;
- address.address_length = plugin_address_length;
- address.transport_name = plugin_name;
- ph->infocb (ph->infocb_cls, &address, pi->bandwidth_out, pi->bandwidth_in,
+ ph->addr_info_cb (ph->addr_info_cb_cls, &address, addr_active, pi->bandwidth_out, pi->bandwidth_in,
atsi, ats_count);
+ }
return GNUNET_OK;
}
_("Received last message for %s \n"), "ATS_ADDRESSLIST_RESPONSE");
bandwidth_zero.value__ = htonl (0);
if (NULL != alh->cb)
- alh->cb (ph->infocb_cls,
+ alh->cb (ph->addr_info_cb_cls,
NULL,
+ GNUNET_NO,
bandwidth_zero, bandwidth_zero,
NULL, 0);
GNUNET_CONTAINER_DLL_remove (ph->addresslist_head, ph->addresslist_tail, alh);
if ((GNUNET_YES == alh->all_addresses) || (GNUNET_YES == active))
{
if (NULL != alh->cb)
- alh->cb (ph->infocb_cls,
+ alh->cb (ph->addr_info_cb_cls,
&address,
+ active,
pi->bandwidth_out, pi->bandwidth_in,
atsi, ats_count);
}
return GNUNET_OK;
}
-/**
- * We received a monitor response message. Validate and process it.
- *
- * @param ph our context with the callback
- * @param msg the message
- * @return GNUNET_OK if the message was well-formed
- */
-static int
-process_mr_message (struct GNUNET_ATS_PerformanceHandle *ph,
- const struct GNUNET_MessageHeader *msg)
-{
- struct MonitorResponseMessage *mrm = (struct MonitorResponseMessage *) msg;
- struct GNUNET_ATS_PerformanceMonitorHandle *cur;
- struct GNUNET_ATS_Information *ats;
- size_t msg_size;
- uint32_t ats_count;
- uint32_t id;
-
- msg_size = ntohs (msg->size);
- if (msg_size < sizeof (struct MonitorResponseMessage))
- return GNUNET_SYSERR;
-
- ats_count = ntohl (mrm->ats_count);
- if (msg_size != (sizeof (struct MonitorResponseMessage) +
- ats_count * sizeof (struct GNUNET_ATS_Information)))
- return GNUNET_SYSERR;
-
- id = ntohl (mrm->id);
- /* Do work here */
- for (cur = ph->monitor_head; NULL != cur; cur = cur->next)
- {
- if (id == cur->id)
- break;
- }
-
- if (NULL == cur)
- return GNUNET_SYSERR;
-
- ats = (struct GNUNET_ATS_Information *) &mrm[1];
- cur->moncb (cur->moncb_cls, &mrm->peer, ats, ats_count);
-
- return GNUNET_OK;
-}
-
/**
* Type of a function to call when we receive a message
if (GNUNET_OK != process_ar_message (ph, msg))
goto reconnect;
break;
- case GNUNET_MESSAGE_TYPE_ATS_MONITOR_RESPONSE:
- if (GNUNET_OK != process_mr_message (ph, msg))
- goto reconnect;
- break;
default:
GNUNET_break (0);
goto reconnect;
init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
init->header.size = htons (sizeof (struct ClientStartMessage));
init->start_flag =
- htonl ((ph->infocb ==
- NULL) ? START_FLAG_PERFORMANCE_NO_PIC :
- START_FLAG_PERFORMANCE_WITH_PIC);
+ htonl ((NULL ==ph->addr_info_cb) ?
+ START_FLAG_PERFORMANCE_NO_PIC : START_FLAG_PERFORMANCE_WITH_PIC);
GNUNET_CONTAINER_DLL_insert (ph->pending_head, ph->pending_tail, p);
}
do_transmit (ph);
* Get handle to access performance API of the ATS subsystem.
*
* @param cfg configuration to use
- * @param infocb function to call on allocation changes, can be NULL
- * @param infocb_cls closure for infocb
+ * @param addr_info_cb callback called when performance characteristics for
+ * an address change
+ * @param addr_info_cb_cls closure for infocb
* @return ats performance context
*/
struct GNUNET_ATS_PerformanceHandle *
GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
- GNUNET_ATS_AddressInformationCallback infocb,
- void *infocb_cls)
+ GNUNET_ATS_AddressInformationCallback addr_info_cb,
+ void *addr_info_cb_cls)
{
struct GNUNET_ATS_PerformanceHandle *ph;
ph = GNUNET_malloc (sizeof (struct GNUNET_ATS_PerformanceHandle));
ph->cfg = cfg;
- ph->infocb = infocb;
- ph->infocb_cls = infocb_cls;
+ ph->addr_info_cb = addr_info_cb;
+ ph->addr_info_cb_cls = addr_info_cb_cls;
ph->id = 0;
reconnect (ph);
return ph;
}
-
-/**
- * Start monitoring performance information
- *
- * @param ph performance handle to use
- * @param monitor_cb function to call on performance changes
- * @param monitor_cb_cls closure for infocb
- * @return a performance monitor handle
- */
-struct GNUNET_ATS_PerformanceMonitorHandle *
-GNUNET_ATS_performance_monitor_start (struct GNUNET_ATS_PerformanceHandle * ph,
- GNUNET_ATS_PerformanceMonitorCb monitor_cb,
- void * monitor_cb_cls)
-{
- struct MonitorMessage *m;
- struct PendingMessage *p;
- GNUNET_assert (NULL != ph);
-
- if (NULL == monitor_cb)
- return NULL;
-
- struct GNUNET_ATS_PerformanceMonitorHandle *phm =
- GNUNET_malloc (sizeof (struct GNUNET_ATS_PerformanceMonitorHandle));
-
- ph->monitor_id ++;
- phm->id = ph->monitor_id;
- phm->ph = ph;
- phm->moncb = monitor_cb;
- phm->moncb_cls = monitor_cb_cls;
- GNUNET_CONTAINER_DLL_insert (ph->monitor_head, ph->monitor_tail, phm);
-
- p = GNUNET_malloc (sizeof (struct PendingMessage) +
- sizeof (struct MonitorMessage));
- p->size = sizeof (struct MonitorMessage);
- m = (struct MonitorMessage *) &p[1];
- m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR);
- m->header.size = htons (sizeof (struct MonitorMessage));
- m->id = htonl (phm->id);
- m->op = htonl (GNUNET_YES);
- GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
- do_transmit (ph);
-
- return phm;
-}
-
-
-/**
- * Stop monitoring performance information
- *
- * @param ph performance handle to use
- * @param monitor_cb function to call on performance changes
- * @param monitor_cb_cls closure for infocb
- * @return a performance monitor handle
- */
-void
-GNUNET_ATS_performance_monitor_stop (struct GNUNET_ATS_PerformanceMonitorHandle * phm)
-{
- struct MonitorMessage *m;
- struct PendingMessage *p;
-
- GNUNET_assert (NULL != phm);
-
- p = GNUNET_malloc (sizeof (struct PendingMessage) +
- sizeof (struct MonitorMessage));
- p->size = sizeof (struct MonitorMessage);
- m = (struct MonitorMessage *) &p[1];
- m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR);
- m->header.size = htons (sizeof (struct MonitorMessage));
- m->id = htonl (phm->id);
- m->op = htonl (GNUNET_NO);
- GNUNET_CONTAINER_DLL_insert_tail (phm->ph->pending_head, phm->ph->pending_tail, p);
- do_transmit (phm->ph);
-
- GNUNET_CONTAINER_DLL_remove (phm->ph->monitor_head, phm->ph->monitor_tail, phm);
- GNUNET_free (phm);
-}
-
/**
* Client is done using the ATS performance subsystem, release resources.
*
struct PendingMessage *p;
struct GNUNET_ATS_ReservationContext *rc;
struct GNUNET_ATS_AddressListHandle *alh;
- struct GNUNET_ATS_PerformanceMonitorHandle *phm;
while (NULL != (p = ph->pending_head))
{
GNUNET_break (NULL == rc->rcb);
GNUNET_free (rc);
}
- while (NULL != (phm = ph->monitor_head))
- {
- GNUNET_CONTAINER_DLL_remove (ph->monitor_head, ph->monitor_tail, phm);
- GNUNET_free (phm);
- }
+
if (GNUNET_SCHEDULER_NO_TASK != ph->task)
{
GNUNET_SCHEDULER_cancel (ph->task);
* @param ... 0-terminated specification of the desired changes
*/
void
-GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
+GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
const struct GNUNET_PeerIdentity *peer, ...)
{
struct PendingMessage *p;
do_transmit (ph);
}
+/**
+ * Send feedback to ATS on how good a the requirements for a peer and a
+ * preference is satisfied by ATS
+ *
+ * @param ph performance handle
+ * @param scope the time interval this valid for: [now - scope .. now]
+ * @param peer identifies the peer
+ * @param ... 0-terminated specification of the desired changes
+ */
+void
+GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TIME_Relative scope, ...)
+{
+ struct PendingMessage *p;
+ struct FeedbackPreferenceMessage *m;
+ size_t msize;
+ uint32_t count;
+ struct PreferenceInformation *pi;
+ va_list ap;
+ enum GNUNET_ATS_PreferenceKind kind;
+
+ count = 0;
+ va_start (ap, scope);
+ while (GNUNET_ATS_PREFERENCE_END !=
+ (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
+ {
+ switch (kind)
+ {
+ case GNUNET_ATS_PREFERENCE_BANDWIDTH:
+ count++;
+ (void) va_arg (ap, double);
+
+ break;
+ case GNUNET_ATS_PREFERENCE_LATENCY:
+ count++;
+ (void) va_arg (ap, double);
+
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ }
+ va_end (ap);
+ msize =
+ count * sizeof (struct PreferenceInformation) +
+ sizeof (struct FeedbackPreferenceMessage);
+ p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
+ p->size = msize;
+ p->is_init = GNUNET_NO;
+ m = (struct FeedbackPreferenceMessage *) &p[1];
+ m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK);
+ m->header.size = htons (msize);
+ m->scope = GNUNET_TIME_relative_hton (scope);
+ m->num_feedback = htonl (count);
+ m->peer = *peer;
+ pi = (struct PreferenceInformation *) &m[1];
+ count = 0;
+ va_start (ap, scope);
+ while (GNUNET_ATS_PREFERENCE_END !=
+ (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
+ {
+ pi[count].preference_kind = htonl (kind);
+ switch (kind)
+ {
+ case GNUNET_ATS_PREFERENCE_BANDWIDTH:
+ pi[count].preference_value = (float) va_arg (ap, double);
+
+ count++;
+ break;
+ case GNUNET_ATS_PREFERENCE_LATENCY:
+ pi[count].preference_value = (float) va_arg (ap, double);
+
+ count++;
+ break;
+ default:
+ GNUNET_assert (0);
+ }
+ }
+ va_end (ap);
+ GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
+ do_transmit (ph);
+}
+
/* end of ats_api_performance.c */