[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25062 - gnunet/src/ats
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25062 - gnunet/src/ats |
Date: |
Tue, 20 Nov 2012 10:12:46 +0100 |
Author: wachs
Date: 2012-11-20 10:12:46 +0100 (Tue, 20 Nov 2012)
New Revision: 25062
Modified:
gnunet/src/ats/ats.h
gnunet/src/ats/ats_api_performance.c
gnunet/src/ats/gnunet-service-ats_addresses.c
gnunet/src/ats/gnunet-service-ats_performance.c
gnunet/src/ats/gnunet-service-ats_performance.h
Log:
- changes
Modified: gnunet/src/ats/ats.h
===================================================================
--- gnunet/src/ats/ats.h 2012-11-20 08:18:18 UTC (rev 25061)
+++ gnunet/src/ats/ats.h 2012-11-20 09:12:46 UTC (rev 25062)
@@ -170,6 +170,8 @@
uint32_t ats_count GNUNET_PACKED;
+ uint32_t address_active GNUNET_PACKED;
+
struct GNUNET_PeerIdentity peer;
uint16_t address_length GNUNET_PACKED;
Modified: gnunet/src/ats/ats_api_performance.c
===================================================================
--- gnunet/src/ats/ats_api_performance.c 2012-11-20 08:18:18 UTC (rev
25061)
+++ gnunet/src/ats/ats_api_performance.c 2012-11-20 09:12:46 UTC (rev
25062)
@@ -420,6 +420,60 @@
/**
+ * We received a reservation result 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_ar_message (struct GNUNET_ATS_PerformanceHandle *ph,
+ const struct GNUNET_MessageHeader *msg)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "TO BE IMPLEMENTED\n");
+# if 0
+ TBD!
+ const struct ReservationResultMessage *rr;
+ struct GNUNET_ATS_ReservationContext *rc;
+ int32_t amount;
+
+ if (ntohs (msg->size) < sizeof (struct ReservationResultMessage))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ rr = (const struct ReservationResultMessage *) msg;
+ amount = ntohl (rr->amount);
+ rc = ph->reservation_head;
+ if (0 != memcmp (&rr->peer, &rc->peer, sizeof (struct GNUNET_PeerIdentity)))
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ GNUNET_CONTAINER_DLL_remove (ph->reservation_head, ph->reservation_tail, rc);
+ if ((amount == 0) || (rc->rcb != NULL))
+ {
+ /* tell client if not cancelled */
+ if (rc->rcb != NULL)
+ rc->rcb (rc->rcb_cls, &rr->peer, amount,
+ GNUNET_TIME_relative_ntoh (rr->res_delay));
+ GNUNET_free (rc);
+ return GNUNET_OK;
+ }
+ /* amount non-zero, but client cancelled, consider undo! */
+ if (GNUNET_YES != rc->undo)
+ {
+ GNUNET_free (rc);
+ return GNUNET_OK; /* do not try to undo failed undos or negative
amounts */
+ }
+ GNUNET_free (rc);
+ (void) GNUNET_ATS_reserve_bandwidth (ph, &rr->peer, -amount, NULL, NULL);
+#endif
+ return GNUNET_OK;
+}
+
+
+/**
* Type of a function to call when we receive a message
* from the service.
*
@@ -443,6 +497,10 @@
if (GNUNET_OK != process_rr_message (ph, msg))
goto reconnect;
break;
+ case GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE:
+ if (GNUNET_OK != process_ar_message (ph, msg))
+ goto reconnect;
+ break;
default:
GNUNET_break (0);
goto reconnect;
Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c 2012-11-20 08:18:18 UTC
(rev 25061)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c 2012-11-20 09:12:46 UTC
(rev 25062)
@@ -113,6 +113,7 @@
aa->assigned_bw_in);
GAS_reservations_set_bandwidth (&aa->peer, aa->assigned_bw_in);
GAS_performance_notify_all_clients (&aa->peer, aa->plugin, aa->addr,
aa->addr_len,
+ aa->active,
ats, ats_count, aa->assigned_bw_out,
aa->assigned_bw_in);
GNUNET_free (ats);
@@ -1114,7 +1115,8 @@
/**
* Return all peers currently known to ATS
*
- * @param p_it the iterator to call for every peer
+ * @param p_it the iterator to call for every peer, callbach with id == NULL
+ * when done
* @param p_it_cls the closure for the iterator
*/
void
Modified: gnunet/src/ats/gnunet-service-ats_performance.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_performance.c 2012-11-20 08:18:18 UTC
(rev 25061)
+++ gnunet/src/ats/gnunet-service-ats_performance.c 2012-11-20 09:12:46 UTC
(rev 25062)
@@ -61,6 +61,22 @@
/**
+ * We keep clients that are interested in performance in a linked list.
+ */
+struct AddressIteration
+{
+ /**
+ * Actual handle to the client.
+ */
+ struct PerformanceClient *pc;
+
+ int all;
+
+ unsigned int msg_type;
+};
+
+
+/**
* Head of linked list of all clients to this service.
*/
static struct PerformanceClient *pc_head;
@@ -130,6 +146,7 @@
const struct GNUNET_PeerIdentity *peer,
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
@@ -161,6 +178,7 @@
msg->ats_count = htonl (atsi_count);
msg->peer = *peer;
msg->address_length = htons (plugin_addr_len);
+ msg->address_active = ntohl (active);
msg->plugin_name_length = htons (plugin_name_length);
msg->bandwidth_out = bandwidth_out;
msg->bandwidth_in = bandwidth_in;
@@ -191,6 +209,7 @@
GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
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
@@ -205,10 +224,10 @@
GAS_performance_notify_client (pc,
peer,
plugin_name, plugin_addr,
plugin_addr_len,
+ active,
atsi, atsi_count,
bandwidth_out, bandwidth_in);
}
-
GNUNET_STATISTICS_update (GSA_stats,
"# performance updates given to clients", 1,
GNUNET_NO);
@@ -231,6 +250,10 @@
GNUNET_assert (NULL != pc);
if (NULL == id)
return;
+
+ if (GNUNET_NO == active)
+ return;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Callback for peer `%s' plugin `%s' BW out %llu, BW in %llu \n",
GNUNET_i2s (id),
@@ -240,6 +263,7 @@
GAS_performance_notify_client(pc,
id,
plugin_name, plugin_addr, plugin_addr_len,
+ active,
atsi, atsi_count,
bandwidth_out, bandwidth_in);
}
@@ -274,8 +298,8 @@
enum StartFlag flag)
{
struct PerformanceClient *pc;
+ GNUNET_break (NULL == find_client (client));
- GNUNET_break (NULL == find_client (client));
pc = GNUNET_malloc (sizeof (struct PerformanceClient));
pc->client = client;
pc->flag = flag;
@@ -287,7 +311,101 @@
GAS_addresses_iterate_peers (&peer_it, pc);
}
+
+
+static void
+req_addr_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 AddressIteration *ai = cls;
+ struct PeerInformationMessage *msg;
+ size_t plugin_name_length;
+ size_t msize;
+ struct GNUNET_ATS_Information *atsp;
+ char *addrp;
+
+
+ GNUNET_assert (NULL != ai);
+ GNUNET_assert (NULL != ai->pc);
+ if (NULL == find_client (ai->pc->client))
+ return; /* Client disconnected */
+
+ if ((NULL == id) && (NULL == id) && (NULL == id))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Address iteration done\n");
+ return;
+ }
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Callback for peer `%s' plugin `%s' BW out %llu, BW in %llu \n",
+ GNUNET_i2s (id),
+ plugin_name,
+ ntohl (bandwidth_out.value__),
+ ntohl (bandwidth_in.value__));
+
+ /* Transmit result */
+
+ plugin_name_length = strlen (plugin_name) + 1;
+ msize = sizeof (struct PeerInformationMessage) +
+ atsi_count * sizeof (struct GNUNET_ATS_Information) +
+ plugin_addr_len + plugin_name_length;
+ char buf[msize] GNUNET_ALIGN;
+
+ GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
+ GNUNET_assert (atsi_count <
+ GNUNET_SERVER_MAX_MESSAGE_SIZE /
+ sizeof (struct GNUNET_ATS_Information));
+ msg = (struct PeerInformationMessage *) buf;
+ msg->header.size = htons (msize);
+ msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE);
+ msg->ats_count = htonl (atsi_count);
+ msg->peer = *id;
+ msg->address_length = htons (plugin_addr_len);
+ msg->address_active = ntohl (active);
+ msg->plugin_name_length = htons (plugin_name_length);
+ msg->bandwidth_out = bandwidth_out;
+ msg->bandwidth_in = bandwidth_in;
+ atsp = (struct GNUNET_ATS_Information *) &msg[1];
+ memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
+ addrp = (char *) &atsp[atsi_count];
+ memcpy (addrp, plugin_addr, plugin_addr_len);
+ strcpy (&addrp[plugin_addr_len], plugin_name);
+ GNUNET_SERVER_notification_context_unicast (nc, ai->pc->client, &msg->header,
+ GNUNET_YES);
+}
+
+
/**
+ * Iterator for GAS_handle_request_address_list
+ *
+ * @param cls the client requesting information
+ * @param id result
+ */
+static void
+req_addr_peer_it (void *cls,
+ const struct GNUNET_PeerIdentity *id)
+{
+ struct AddressIteration *ai = cls;
+ if (NULL != id)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Callback for peer `%s'\n",
GNUNET_i2s (id));
+ GAS_addresses_get_peer_info (id, &req_addr_peerinfo_it, ai);
+ }
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Peer iteration done\n");
+ }
+}
+
+/**
* Handle 'address list request' messages from clients.
*
* @param cls unused, NULL
@@ -299,6 +417,7 @@
const struct GNUNET_MessageHeader *message)
{
struct PerformanceClient *pc;
+ struct AddressIteration ai;
struct AddressListRequestMessage * alrm = (struct AddressListRequestMessage
*) message;
struct GNUNET_PeerIdentity allzeros;
@@ -311,19 +430,20 @@
return;
}
+ ai.all = ntohl (alrm->all);
+ ai.pc = pc;
+
memset (&allzeros, '\0', sizeof (struct GNUNET_PeerIdentity));
if (0 == memcmp (&alrm->peer, &allzeros, sizeof (struct
GNUNET_PeerIdentity)))
{
/* Return addresses for all peers */
- GAS_addresses_iterate_peers (&peer_it, pc);
+ GAS_addresses_iterate_peers (&req_addr_peer_it, &ai);
}
else
{
/* Return addresses for a specific peer */
- GAS_addresses_get_peer_info (&alrm->peer, &peerinfo_it, pc);
+ GAS_addresses_get_peer_info (&alrm->peer, &req_addr_peerinfo_it, &ai);
}
-
-
}
Modified: gnunet/src/ats/gnunet-service-ats_performance.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_performance.h 2012-11-20 08:18:18 UTC
(rev 25061)
+++ gnunet/src/ats/gnunet-service-ats_performance.h 2012-11-20 09:12:46 UTC
(rev 25062)
@@ -69,6 +69,7 @@
GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25062 - gnunet/src/ats,
gnunet <=