[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r26506 - gnunet/src/ats
From: |
gnunet |
Subject: |
[GNUnet-SVN] r26506 - gnunet/src/ats |
Date: |
Wed, 20 Mar 2013 10:13:10 +0100 |
Author: wachs
Date: 2013-03-20 10:13:10 +0100 (Wed, 20 Mar 2013)
New Revision: 26506
Modified:
gnunet/src/ats/gnunet-service-ats_performance.c
gnunet/src/ats/test_ats_api_performance_monitor.c
Log:
changes
Modified: gnunet/src/ats/gnunet-service-ats_performance.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_performance.c 2013-03-20 09:01:15 UTC
(rev 26505)
+++ gnunet/src/ats/gnunet-service-ats_performance.c 2013-03-20 09:13:10 UTC
(rev 26506)
@@ -534,7 +534,6 @@
struct MonitorResponseMessage *mrm;
size_t msglen;
-
msglen = sizeof (struct MonitorResponseMessage) +
ats_count * sizeof (struct
GNUNET_ATS_Information);
mrm = GNUNET_malloc (msglen);
@@ -551,21 +550,75 @@
mrm->id = curm->id;
GNUNET_SERVER_notification_context_unicast (nc,
cur->client,
- (struct GNUNET_MessageHeader *) &mrm,
+ (struct GNUNET_MessageHeader *) mrm,
GNUNET_YES);
}
GNUNET_free (mrm);
}
+static void
+mon_peerinfo_it (void *cls,
+ const struct GNUNET_PeerIdentity *id,
+ const char *plugin_name,
+ const void *plugin_addr, size_t plugin_addr_len,
+ const int active,
+ const struct GNUNET_ATS_Information *atsi,
+ uint32_t atsi_count,
+ struct GNUNET_BANDWIDTH_Value32NBO
+ bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
+{
+ struct PerformanceMonitorClient *pmc = cls;
+ struct MonitorResponseMessage *mrm;
+ size_t msglen;
+ if (NULL == id)
+ return; /* last callback */
+
+ msglen = sizeof (struct MonitorResponseMessage) +
+ atsi_count * sizeof (struct GNUNET_ATS_Information);
+ mrm = GNUNET_malloc (msglen);
+
+ mrm->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_MONITOR_RESPONSE);
+ mrm->header.size = htons (msglen);
+ mrm->ats_count = htonl (atsi_count);
+ mrm->peer = *id;
+ mrm->id = pmc->id;
+
+ /* Send initial information about peers to client */
+/*
+ GNUNET_SERVER_notification_context_unicast (nc,
+ pmc->client,
+ (struct GNUNET_MessageHeader *) mrm,
+ GNUNET_YES);
+*/
+ GNUNET_free (mrm);
+}
+
+/**
+ * Iterator for GAS_handle_monitor
+ *
+ * @param cls the performance monitoring client requesting information
+ * @param id result
+ */
+static void
+mon_peer_it (void *cls,
+ const struct GNUNET_PeerIdentity *id)
+{
+ struct PerformanceMonitorClient *pmc = cls;
+ if (NULL != id)
+ GAS_addresses_get_peer_info (GSA_addresses, id, &mon_peerinfo_it, pmc);
+}
+
+
void
GAS_handle_monitor (void *cls,
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
struct PerformanceClient *pc;
- struct PerformanceMonitorClient *res;
+ struct PerformanceMonitorClient *pmc;
struct MonitorMessage *mm = (struct MonitorMessage *) message;
size_t msg_size;
uint32_t id;
@@ -588,38 +641,42 @@
id = ntohl (mm->id);
op = ntohl (mm->op);
- for (res = pc->pm_head; NULL != res; res = res->next)
- if ((res->id == id) && (client == res->client))
+ for (pmc = pc->pm_head; NULL != pmc; pmc = pmc->next)
+ if ((pmc->id == id) && (client == pmc->client))
break;
if (GNUNET_YES == op)
{
/* Start monitoring */
- if (NULL != res)
+ if (NULL != pmc)
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client,
GNUNET_SYSERR);
return; /* Duplicate*/
}
- res = GNUNET_malloc (sizeof (struct
PerformanceMonitorClient));
- res->client = client;
- res->id = id;
- GNUNET_CONTAINER_DLL_insert (pc->pm_head, pc->pm_tail,
res);
+ pmc = GNUNET_malloc (sizeof (struct
PerformanceMonitorClient));
+ pmc->client = client;
+ pmc->id = id;
+ GNUNET_CONTAINER_DLL_insert (pc->pm_head, pc->pm_tail,
pmc);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Added performance monitoring client %p
id %u\n",
client, id);
+
+ /* Return all values here */
+ GAS_addresses_iterate_peers (GSA_addresses, &mon_peer_it, pc);
+
}
else if (GNUNET_NO == op)
{
/* Stop monitoring */
- if (NULL == res)
+ if (NULL == pmc)
{
GNUNET_break (0);
GNUNET_SERVER_receive_done (client,
GNUNET_SYSERR);
return; /* Not existing */
}
- GNUNET_CONTAINER_DLL_remove (pc->pm_head, pc->pm_tail,
res);
- GNUNET_free (res);
+ GNUNET_CONTAINER_DLL_remove (pc->pm_head, pc->pm_tail,
pmc);
+ GNUNET_free (pmc);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Removed performance monitoring client
%p id %u\n",
client, id);
Modified: gnunet/src/ats/test_ats_api_performance_monitor.c
===================================================================
--- gnunet/src/ats/test_ats_api_performance_monitor.c 2013-03-20 09:01:15 UTC
(rev 26505)
+++ gnunet/src/ats/test_ats_api_performance_monitor.c 2013-03-20 09:13:10 UTC
(rev 26506)
@@ -36,13 +36,42 @@
struct GNUNET_CONFIGURATION_Handle *cfg;
+static struct GNUNET_ATS_SchedulingHandle *sh;
+
static struct GNUNET_ATS_PerformanceHandle *ph;
static struct GNUNET_ATS_PerformanceMonitorHandle *phm;
+static struct GNUNET_HELLO_Address addr;
+
+static struct GNUNET_ATS_Information atsi[3];
+
static int ret;
+static void cleanup_addresses ()
+{
+ GNUNET_ATS_address_destroyed (sh, &addr, NULL);
+}
+static void setup_addresses ()
+{
+ memset (&addr.peer,'\0', sizeof (addr.peer));
+ addr.transport_name = "test";
+ addr.address = NULL;
+ addr.address_length = 0;
+ atsi[0].type = htonl(GNUNET_ATS_NETWORK_TYPE);
+ atsi[0].value = htonl(GNUNET_ATS_NET_LAN);
+
+ atsi[1].type = htonl(GNUNET_ATS_QUALITY_NET_DELAY);
+ atsi[1].value = htonl(100);
+
+ atsi[2].type = htonl(GNUNET_ATS_QUALITY_NET_DISTANCE);
+ atsi[2].value = htonl(5);
+
+ GNUNET_ATS_address_add (sh, &addr, NULL, atsi, 3);
+}
+
+
static void
end_now (int res)
{
@@ -56,7 +85,10 @@
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_NO_TASK;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
+ cleanup_addresses ();
+
if (NULL != phm)
{
GNUNET_ATS_performance_monitor_stop (phm);
@@ -68,6 +100,12 @@
GNUNET_ATS_performance_done (ph);
ph = NULL;
}
+
+ if (NULL != sh)
+ {
+ GNUNET_ATS_scheduling_done (sh);
+ sh = NULL;
+ }
ret = res;
}
@@ -124,6 +162,11 @@
cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
+ sh = GNUNET_ATS_scheduling_init (cfg, NULL, NULL);
+ GNUNET_assert (NULL != sh);
+
+ setup_addresses ();
+
ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
GNUNET_assert (NULL != ph);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r26506 - gnunet/src/ats,
gnunet <=