[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r34626 - gnunet/src/ats
From: |
gnunet |
Subject: |
[GNUnet-SVN] r34626 - gnunet/src/ats |
Date: |
Mon, 15 Dec 2014 19:09:17 +0100 |
Author: grothoff
Date: 2014-12-15 19:09:16 +0100 (Mon, 15 Dec 2014)
New Revision: 34626
Modified:
gnunet/src/ats/ats.h
gnunet/src/ats/ats_api_performance.c
gnunet/src/ats/gnunet-service-ats.c
gnunet/src/ats/gnunet-service-ats_addresses.c
gnunet/src/ats/gnunet-service-ats_addresses.h
gnunet/src/ats/gnunet-service-ats_performance.c
gnunet/src/ats/gnunet-service-ats_performance.h
Log:
removing dead code, improving comments, simplifying iteration logic, making
iteration over all addresses also faster
Modified: gnunet/src/ats/ats.h
===================================================================
--- gnunet/src/ats/ats.h 2014-12-15 15:16:17 UTC (rev 34625)
+++ gnunet/src/ats/ats.h 2014-12-15 18:09:16 UTC (rev 34626)
@@ -202,15 +202,32 @@
};
+/**
+ * Client to service: please give us an overview of the addresses.
+ */
struct AddressListRequestMessage
{
+ /**
+ * Type is #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_REQUEST
+ */
struct GNUNET_MessageHeader header;
+ /**
+ * ID used to match replies to this request.
+ */
uint32_t id GNUNET_PACKED;
+ /**
+ * Which peer do we care about? All zeros for all.
+ */
+ struct GNUNET_PeerIdentity peer;
+
+ /**
+ * #GNUNET_YES to get information about all addresses,
+ * #GNUNET_NO to only return addresses that are in use.
+ */
int32_t all GNUNET_PACKED;
- struct GNUNET_PeerIdentity peer;
};
Modified: gnunet/src/ats/ats_api_performance.c
===================================================================
--- gnunet/src/ats/ats_api_performance.c 2014-12-15 15:16:17 UTC (rev
34625)
+++ gnunet/src/ats/ats_api_performance.c 2014-12-15 18:09:16 UTC (rev
34626)
@@ -131,7 +131,7 @@
GNUNET_ATS_AddressInformationCallback cb;
/**
- * Callback closure
+ * Callback closure for @e cb
*/
void *cb_cls;
@@ -285,13 +285,15 @@
/**
* We can now transmit a message to ATS. Do it.
*
- * @param cls the 'struct GNUNET_ATS_SchedulingHandle'
+ * @param cls the `struct GNUNET_ATS_PerformanceHandle`
* @param size number of bytes we can transmit to ATS
* @param buf where to copy the messages
- * @return number of bytes copied into buf
+ * @return number of bytes copied into @a buf
*/
static size_t
-transmit_message_to_ats (void *cls, size_t size, void *buf)
+transmit_message_to_ats (void *cls,
+ size_t size,
+ void *buf)
{
struct GNUNET_ATS_PerformanceHandle *ph = cls;
struct PendingMessage *p;
@@ -306,7 +308,9 @@
memcpy (&cbuf[ret], &p[1], p->size);
ret += p->size;
size -= p->size;
- GNUNET_CONTAINER_DLL_remove(ph->pending_head, ph->pending_tail, p);
+ GNUNET_CONTAINER_DLL_remove (ph->pending_head,
+ ph->pending_tail,
+ p);
GNUNET_free(p);
}
do_transmit (ph);
@@ -331,8 +335,11 @@
return;
if (NULL == ph->client)
return; /* currently reconnecting */
- ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client, p->size,
- GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, &transmit_message_to_ats, ph);
+ ph->th = GNUNET_CLIENT_notify_transmit_ready (ph->client,
+ p->size,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES,
+ &transmit_message_to_ats, ph);
}
@@ -428,13 +435,18 @@
GNUNET_break(0);
return GNUNET_SYSERR;
}
- GNUNET_CONTAINER_DLL_remove(ph->reservation_head, ph->reservation_tail, rc);
- if ((amount == 0) || (rc->rcb != NULL ))
+ GNUNET_CONTAINER_DLL_remove (ph->reservation_head,
+ ph->reservation_tail,
+ rc);
+ if ( (0 == amount) ||
+ (NULL != rc->rcb) )
{
/* tell client if not cancelled */
if (rc->rcb != NULL )
- rc->rcb (rc->rcb_cls, &rr->peer, amount,
- GNUNET_TIME_relative_ntoh (rr->res_delay));
+ rc->rcb (rc->rcb_cls,
+ &rr->peer,
+ amount,
+ GNUNET_TIME_relative_ntoh (rr->res_delay));
GNUNET_free(rc);
return GNUNET_OK;
}
@@ -445,7 +457,10 @@
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 );
+ (void) GNUNET_ATS_reserve_bandwidth (ph,
+ &rr->peer,
+ -amount,
+ NULL, NULL);
return GNUNET_OK;
}
@@ -481,10 +496,6 @@
GNUNET_break(0);
return GNUNET_SYSERR;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- _("Received %s message\n"),
- "ATS_ADDRESSLIST_RESPONSE");
-
pi = (const struct PeerInformationMessage *) msg;
id = ntohl (pi->id);
ats_count = ntohl (pi->ats_count);
@@ -494,17 +505,21 @@
atsi = (const struct GNUNET_ATS_Information *) &pi[1];
plugin_address = (const char *) &atsi[ats_count];
plugin_name = &plugin_address[plugin_address_length];
- if ((plugin_address_length + plugin_name_length
- + ats_count * sizeof(struct GNUNET_ATS_Information)
- + sizeof(struct PeerInformationMessage) != ntohs (msg->size))
- || (ats_count
- > GNUNET_SERVER_MAX_MESSAGE_SIZE
- / sizeof(struct GNUNET_ATS_Information))
- || (plugin_name[plugin_name_length - 1] != '\0'))
+ if ( (plugin_address_length + plugin_name_length
+ + ats_count * sizeof(struct GNUNET_ATS_Information)
+ + sizeof (struct PeerInformationMessage) != ntohs (msg->size)) ||
+ (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE
+ / sizeof(struct GNUNET_ATS_Information)) ||
+ (plugin_name[plugin_name_length - 1] != '\0') )
{
GNUNET_break(0);
return GNUNET_SYSERR;
}
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received %s message for peer %s and plugin %s\n",
+ "ATS_ADDRESSLIST_RESPONSE",
+ GNUNET_i2s (&pi->peer),
+ plugin_name);
next = ph->addresslist_head;
while (NULL != (alh = next))
@@ -519,16 +534,16 @@
return GNUNET_SYSERR;
}
- memset (&allzeros, '\0', sizeof(allzeros));
+ memset (&allzeros, '\0', sizeof (allzeros));
if ( (0 == memcmp (&allzeros, &pi->peer, sizeof(allzeros))) &&
(0 == plugin_name_length) &&
(0 == plugin_address_length) &&
(0 == ats_count) )
{
/* Done */
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- _("Received last message for %s \n"),
- "ATS_ADDRESSLIST_RESPONSE");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received last message for %s\n",
+ "ATS_ADDRESSLIST_RESPONSE");
bandwidth_zero.value__ = htonl (0);
GNUNET_CONTAINER_DLL_remove (ph->addresslist_head,
ph->addresslist_tail,
@@ -548,13 +563,15 @@
address.address = plugin_address;
address.address_length = plugin_address_length;
address.transport_name = plugin_name;
-
- if ((GNUNET_YES == alh->all_addresses) || (GNUNET_YES == active))
- {
- if (NULL != alh->cb)
- alh->cb (ph->addr_info_cb_cls, &address, active, pi->bandwidth_out,
- pi->bandwidth_in, atsi, ats_count);
- }
+ if ( ( (GNUNET_YES == alh->all_addresses) ||
+ (GNUNET_YES == active) ) &&
+ (NULL != alh->cb) )
+ alh->cb (ph->addr_info_cb_cls,
+ &address,
+ active,
+ pi->bandwidth_out,
+ pi->bandwidth_in,
+ atsi, ats_count);
return GNUNET_OK;
}
@@ -592,11 +609,15 @@
GNUNET_break(0);
goto reconnect;
}
- GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_CLIENT_receive (ph->client,
+ &process_ats_message,
+ ph,
+ GNUNET_TIME_UNIT_FOREVER_REL);
return;
reconnect:
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Reconnecting!\n");
if (NULL != ph->th)
{
GNUNET_CLIENT_notify_transmit_ready_cancel (ph->th);
@@ -607,10 +628,12 @@
if (NULL != ph->addr_info_cb)
{
/* Indicate reconnect */
- ph->addr_info_cb (ph->addr_info_cb_cls, NULL, GNUNET_NO,
- GNUNET_BANDWIDTH_value_init (0),
- GNUNET_BANDWIDTH_value_init(0),
- NULL, 0);
+ ph->addr_info_cb (ph->addr_info_cb_cls,
+ NULL,
+ GNUNET_NO,
+ GNUNET_BANDWIDTH_value_init (0),
+ GNUNET_BANDWIDTH_value_init (0),
+ NULL, 0);
}
ph->task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
&reconnect_task, ph);
@@ -628,11 +651,14 @@
struct PendingMessage *p;
struct ClientStartMessage *init;
- GNUNET_assert(NULL == ph->client);
- ph->client = GNUNET_CLIENT_connect ("ats", ph->cfg);
- GNUNET_assert(NULL != ph->client);
- GNUNET_CLIENT_receive (ph->client, &process_ats_message, ph,
- GNUNET_TIME_UNIT_FOREVER_REL);
+ GNUNET_assert (NULL == ph->client);
+ ph->client = GNUNET_CLIENT_connect ("ats",
+ ph->cfg);
+ GNUNET_assert (NULL != ph->client);
+ GNUNET_CLIENT_receive (ph->client,
+ &process_ats_message,
+ ph,
+ GNUNET_TIME_UNIT_FOREVER_REL);
if ((NULL == (p = ph->pending_head)) || (GNUNET_YES != p->is_init))
{
p = GNUNET_malloc (sizeof (struct PendingMessage) +
@@ -642,10 +668,12 @@
init = (struct ClientStartMessage *) &p[1];
init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
init->header.size = htons (sizeof(struct ClientStartMessage));
- init->start_flag = 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);
+ init->start_flag = 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);
}
@@ -691,20 +719,25 @@
while (NULL != (p = ph->pending_head))
{
- GNUNET_CONTAINER_DLL_remove(ph->pending_head, ph->pending_tail, p);
- GNUNET_free(p);
+ GNUNET_CONTAINER_DLL_remove (ph->pending_head,
+ ph->pending_tail,
+ p);
+ GNUNET_free (p);
}
while (NULL != (alh = ph->addresslist_head))
{
- GNUNET_CONTAINER_DLL_remove(ph->addresslist_head, ph->addresslist_tail,
- alh);
- GNUNET_free(alh);
+ GNUNET_CONTAINER_DLL_remove (ph->addresslist_head,
+ ph->addresslist_tail,
+ alh);
+ GNUNET_free (alh);
}
while (NULL != (rc = ph->reservation_head))
{
- GNUNET_CONTAINER_DLL_remove(ph->reservation_head, ph->reservation_tail,
rc);
- GNUNET_break(NULL == rc->rcb);
- GNUNET_free(rc);
+ GNUNET_CONTAINER_DLL_remove (ph->reservation_head,
+ ph->reservation_tail,
+ rc);
+ GNUNET_break (NULL == rc->rcb);
+ GNUNET_free (rc);
}
if (GNUNET_SCHEDULER_NO_TASK != ph->task)
@@ -717,7 +750,7 @@
GNUNET_CLIENT_disconnect (ph->client);
ph->client = NULL;
}
- GNUNET_free(ph);
+ GNUNET_free (ph);
}
@@ -731,7 +764,7 @@
* @param amount reserve N bytes for receiving, negative
* amounts can be used to undo a (recent) reservation;
* @param rcb function to call with the resulting reservation information
- * @param rcb_cls closure for info
+ * @param rcb_cls closure for @a rcb
* @return NULL on error
* @deprecated will be replaced soon
*/
@@ -750,9 +783,12 @@
rc->peer = *peer;
rc->rcb = rcb;
rc->rcb_cls = rcb_cls;
- if ((rcb != NULL )&& (amount > 0))rc->undo = GNUNET_YES;
- GNUNET_CONTAINER_DLL_insert_tail(ph->reservation_head, ph->reservation_tail,
- rc);
+ if ( (NULL != rcb) &&
+ (amount > 0) )
+ rc->undo = GNUNET_YES;
+ GNUNET_CONTAINER_DLL_insert_tail (ph->reservation_head,
+ ph->reservation_tail,
+ rc);
p = GNUNET_malloc (sizeof (struct PendingMessage) +
sizeof (struct ReservationRequestMessage));
@@ -763,7 +799,9 @@
m->header.size = htons (sizeof(struct ReservationRequestMessage));
m->amount = htonl (amount);
m->peer = *peer;
- GNUNET_CONTAINER_DLL_insert_tail(ph->pending_head, ph->pending_tail, p);
+ GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head,
+ ph->pending_tail,
+ p);
do_transmit (ph);
return rc;
}
@@ -790,7 +828,7 @@
* get only address currently used
* @param infocb callback to call with the addresses,
* will callback with address == NULL when done
- * @param infocb_cls closure for infocb
+ * @param infocb_cls closure for @a infocb
* @return ats performance context
*/
struct GNUNET_ATS_AddressListHandle*
@@ -820,7 +858,7 @@
else
{
alh->all_peers = GNUNET_NO;
- alh->peer = (*peer);
+ alh->peer = *peer;
}
GNUNET_CONTAINER_DLL_insert (handle->addresslist_head,
handle->addresslist_tail,
@@ -836,9 +874,9 @@
m->id = htonl (alh->id);
if (NULL != peer)
m->peer = *peer;
- GNUNET_CONTAINER_DLL_insert_tail(handle->pending_head,
- handle->pending_tail,
- p);
+ GNUNET_CONTAINER_DLL_insert_tail (handle->pending_head,
+ handle->pending_tail,
+ p);
do_transmit (handle);
return alh;
@@ -853,7 +891,6 @@
void
GNUNET_ATS_performance_list_addresses_cancel (struct
GNUNET_ATS_AddressListHandle *handle)
{
- GNUNET_assert (NULL != handle);
GNUNET_CONTAINER_DLL_remove (handle->ph->addresslist_head,
handle->ph->addresslist_tail,
handle);
Modified: gnunet/src/ats/gnunet-service-ats.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats.c 2014-12-15 15:16:17 UTC (rev 34625)
+++ gnunet/src/ats/gnunet-service-ats.c 2014-12-15 18:09:16 UTC (rev 34626)
@@ -144,7 +144,8 @@
* @param cfg configuration to use
*/
static void
-run (void *cls, struct GNUNET_SERVER_Handle *server,
+run (void *cls,
+ struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *cfg)
{
static const struct GNUNET_SERVER_MessageHandler handlers[] = {
Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c 2014-12-15 15:16:17 UTC
(rev 34625)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c 2014-12-15 18:09:16 UTC
(rev 34626)
@@ -1616,16 +1616,16 @@
return NULL;
}
+
/**
* A performance client disconnected
*
* @param handle address handle
* @param client the client
*/
-
void
GAS_addresses_preference_client_disconnect (struct GAS_Addresses_Handle
*handle,
- void *client)
+ void *client)
{
struct GAS_Addresses_Preference_Clients * pc;
if (NULL != (pc = find_preference_client (handle, client)))
@@ -1640,6 +1640,7 @@
GAS_normalization_preference_client_disconnect (client);
}
+
/**
* Change the preference for a peer
*
@@ -1679,7 +1680,10 @@
GNUNET_CONTAINER_DLL_insert (handle->preference_clients_head,
handle->preference_clients_tail, pc);
handle->pref_clients ++;
- GNUNET_STATISTICS_set (handle->stat, "# active performance clients",
handle->pref_clients, GNUNET_NO);
+ GNUNET_STATISTICS_set (handle->stat,
+ "# active performance clients",
+ handle->pref_clients,
+ GNUNET_NO);
}
handle->env.sf.s_bulk_start (handle->solver);
@@ -1688,6 +1692,7 @@
handle->env.sf.s_bulk_stop (handle->solver);
}
+
/**
* Change the preference for a peer
*
@@ -1700,9 +1705,11 @@
*/
void
GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle,
- void *application, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TIME_Relative scope,
- enum GNUNET_ATS_PreferenceKind kind, float score_abs)
+ void *application,
+ const struct GNUNET_PeerIdentity *peer,
+ const struct GNUNET_TIME_Relative scope,
+ enum GNUNET_ATS_PreferenceKind kind,
+ float score_abs)
{
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"Received `%s' for peer `%s' for client %p\n", "PREFERENCE FEEDBACK",
@@ -1725,6 +1732,7 @@
score_abs);
}
+
/**
* Load quotas for networks from configuration
*
@@ -1850,6 +1858,7 @@
return GNUNET_ATS_NetworkTypeCount;
}
+
/**
* Callback for solver to notify about assignment changes
*
@@ -1945,7 +1954,7 @@
*/
struct GAS_Addresses_Handle *
GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
- const struct GNUNET_STATISTICS_Handle *stats)
+ const struct GNUNET_STATISTICS_Handle *stats)
{
struct GAS_Addresses_Handle *ah;
unsigned long long quotas_in[GNUNET_ATS_NetworkTypeCount];
@@ -1964,11 +1973,11 @@
GNUNET_assert(NULL != ah->addresses);
/* Figure out configured solution method */
- if (GNUNET_SYSERR
- == GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str))
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_get_value_string (cfg, "ats", "MODE", &mode_str))
{
GNUNET_log(GNUNET_ERROR_TYPE_WARNING,
- "No resource assignment method configured, using proportional
approach\n");
+ "No resource assignment method configured, using proportional
approach\n");
ah->ats_mode = MODE_PROPORTIONAL;
}
else
@@ -1982,8 +1991,8 @@
ah->ats_mode = MODE_MLP;
#if !HAVE_LIBGLPK
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Assignment method `%s' configured, but GLPK is not available,
please install \n",
- mode_str);
+ "Assignment method `%s' configured, but GLPK is not
available, please install \n",
+ mode_str);
ah->ats_mode = MODE_PROPORTIONAL;
#endif
}
@@ -1992,8 +2001,8 @@
else
{
GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
- "Invalid resource assignment method `%s' configured, using
proportional approach\n",
- mode_str);
+ "Invalid resource assignment method `%s' configured, using
proportional approach\n",
+ mode_str);
ah->ats_mode = MODE_PROPORTIONAL;
}
GNUNET_free(mode_str);
@@ -2035,11 +2044,18 @@
plugin_short = NULL;
break;
}
- GNUNET_asprintf (&ah->plugin, "libgnunet_plugin_ats_%s", plugin_short);
- GNUNET_log(GNUNET_ERROR_TYPE_INFO, _("Initializing solver `%s '`%s'\n"),
plugin_short, ah->plugin);
- if (NULL == (ah->solver = GNUNET_PLUGIN_load (ah->plugin, &ah->env)))
+ GNUNET_asprintf (&ah->plugin,
+ "libgnunet_plugin_ats_%s",
+ plugin_short);
+ GNUNET_log(GNUNET_ERROR_TYPE_INFO,
+ _("Initializing solver `%s '`%s'\n"),
+ plugin_short,
+ ah->plugin);
+ if (NULL == (ah->solver = GNUNET_PLUGIN_load (ah->plugin, &ah->env)))
{
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver
`%s'!\n"), ah->plugin);
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to initialize solver `%s'!\n"),
+ ah->plugin);
return NULL;
}
@@ -2058,11 +2074,12 @@
GAS_normalization_start (&normalized_preference_changed_cb, ah,
- &normalized_property_changed_cb, ah);
+ &normalized_property_changed_cb, ah);
if (NULL == ah->solver)
{
- GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Failed to initialize solver!\n"));
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ _("Failed to initialize solver!\n"));
GNUNET_free(ah);
return NULL ;
}
@@ -2075,6 +2092,7 @@
return ah;
}
+
/**
* Destroy all addresses iterator
*
@@ -2151,21 +2169,27 @@
handle->addresses = NULL;
while (NULL != (cur = handle->pending_requests_head))
{
- GNUNET_CONTAINER_DLL_remove(handle->pending_requests_head,
handle->pending_requests_tail, cur);
+ GNUNET_CONTAINER_DLL_remove (handle->pending_requests_head,
+ handle->pending_requests_tail,
+ cur);
GNUNET_free(cur);
}
while (NULL != (pcur = handle->preference_clients_head))
{
GNUNET_CONTAINER_DLL_remove (handle->preference_clients_head,
- handle->preference_clients_tail, pcur);
+ handle->preference_clients_tail,
+ pcur);
GNUNET_assert (handle->pref_clients > 0);
handle->pref_clients --;
- GNUNET_STATISTICS_set (handle->stat, "# active performance clients",
handle->pref_clients, GNUNET_NO);
+ GNUNET_STATISTICS_set (handle->stat,
+ "# active performance clients",
+ handle->pref_clients,
+ GNUNET_NO);
GNUNET_free (pcur);
}
-
- GNUNET_PLUGIN_unload (handle->plugin, handle->solver);
+ GNUNET_PLUGIN_unload (handle->plugin,
+ handle->solver);
GNUNET_free (handle->plugin);
GNUNET_free(handle);
/* Stop configured solution method */
@@ -2173,76 +2197,19 @@
}
-struct PeerIteratorContext
-{
- GNUNET_ATS_Peer_Iterator it;
- void *it_cls;
- struct GNUNET_CONTAINER_MultiPeerMap *peers_returned;
-};
-
-
/**
- * Iterator to iterate over all peers
- *
- * @param cls a PeerIteratorContext
- * @param key the peer id
- * @param value the ATS_address
- * @return #GNUNET_OK to continue
+ * Closure for #peerinfo_it().
*/
-static int
-peer_it (void *cls,
- const struct GNUNET_PeerIdentity *key,
- void *value)
-{
- struct PeerIteratorContext *ip_ctx = cls;
-
- if (GNUNET_NO ==
- GNUNET_CONTAINER_multipeermap_contains (ip_ctx->peers_returned, key))
- {
- GNUNET_CONTAINER_multipeermap_put (ip_ctx->peers_returned, key, NULL,
-
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
- ip_ctx->it (ip_ctx->it_cls, key);
- }
-
- return GNUNET_OK;
-}
-
-/**
- * Return information all peers currently known to ATS
- *
- * @param handle the address handle to use
- * @param p_it the iterator to call for every peer
- * @param p_it_cls the closure for the iterator
- */
-void
-GAS_addresses_iterate_peers (struct GAS_Addresses_Handle *handle,
- GNUNET_ATS_Peer_Iterator p_it, void *p_it_cls)
-{
- struct PeerIteratorContext ip_ctx;
- unsigned int size;
-
- if (NULL == p_it)
- return;
- GNUNET_assert(NULL != handle->addresses);
-
- size = GNUNET_CONTAINER_multipeermap_size (handle->addresses);
- if (0 != size)
- {
- ip_ctx.it = p_it;
- ip_ctx.it_cls = p_it_cls;
- ip_ctx.peers_returned = GNUNET_CONTAINER_multipeermap_create (size,
- GNUNET_NO);
- GNUNET_CONTAINER_multipeermap_iterate (handle->addresses,
- &peer_it,
- &ip_ctx);
- GNUNET_CONTAINER_multipeermap_destroy (ip_ctx.peers_returned);
- }
- p_it (p_it_cls, NULL );
-}
-
struct PeerInfoIteratorContext
{
+ /**
+ * Function to call for each address.
+ */
GNUNET_ATS_PeerInfo_Iterator it;
+
+ /**
+ * Closure for @e it.
+ */
void *it_cls;
};
@@ -2263,13 +2230,15 @@
struct PeerInfoIteratorContext *pi_ctx = cls;
struct ATS_Address *addr = value;
- if (NULL != pi_ctx->it)
- {
- pi_ctx->it (pi_ctx->it_cls, &addr->peer, addr->plugin, addr->addr,
- addr->addr_len, addr->active, addr->atsi, addr->atsi_count,
- GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out),
- GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in));
- }
+ pi_ctx->it (pi_ctx->it_cls,
+ &addr->peer,
+ addr->plugin,
+ addr->addr,
+ addr->addr_len,
+ addr->active,
+ addr->atsi, addr->atsi_count,
+ GNUNET_BANDWIDTH_value_init (addr->assigned_bw_out),
+ GNUNET_BANDWIDTH_value_init (addr->assigned_bw_in));
return GNUNET_YES;
}
@@ -2278,36 +2247,40 @@
* Return information all peers currently known to ATS
*
* @param handle the address handle to use
- * @param peer the respective peer
+ * @param peer the respective peer, NULL for 'all' peers
* @param pi_it the iterator to call for every peer
- * @param pi_it_cls the closure for the iterator
+ * @param pi_it_cls the closure for @a pi_it
*/
void
GAS_addresses_get_peer_info (struct GAS_Addresses_Handle *handle,
- const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_PeerInfo_Iterator pi_it,
- void *pi_it_cls)
+ const struct GNUNET_PeerIdentity *peer,
+ GNUNET_ATS_PeerInfo_Iterator pi_it,
+ void *pi_it_cls)
{
struct PeerInfoIteratorContext pi_ctx;
- GNUNET_assert(NULL != peer);
- GNUNET_assert(NULL != handle->addresses);
if (NULL == pi_it)
- return; /* does not make sense without callback */
-
+ {
+ /* does not make sense without callback */
+ GNUNET_break (0);
+ return;
+ }
pi_ctx.it = pi_it;
pi_ctx.it_cls = pi_it_cls;
- GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses,
- peer,
- &peerinfo_it, &pi_ctx);
-
- if (NULL != pi_it)
- pi_it (pi_it_cls,
- NULL, NULL, NULL, 0,
- GNUNET_NO,
- NULL, 0,
- zero_bw,
- zero_bw);
-
+ if (NULL == peer)
+ GNUNET_CONTAINER_multipeermap_iterate (handle->addresses,
+ &peerinfo_it,
+ &pi_ctx);
+ else
+ GNUNET_CONTAINER_multipeermap_get_multiple (handle->addresses,
+ peer,
+ &peerinfo_it, &pi_ctx);
+ pi_it (pi_it_cls,
+ NULL, NULL, NULL, 0,
+ GNUNET_NO,
+ NULL, 0,
+ zero_bw,
+ zero_bw);
}
/* end of gnunet-service-ats_addresses.c */
Modified: gnunet/src/ats/gnunet-service-ats_addresses.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.h 2014-12-15 15:16:17 UTC
(rev 34625)
+++ gnunet/src/ats/gnunet-service-ats_addresses.h 2014-12-15 18:09:16 UTC
(rev 34626)
@@ -642,30 +642,6 @@
/**
- * Iterator for #GAS_addresses_iterate_peers()
- *
- * @param p_it_cls closure
- * @param id the peer id
- */
-typedef void
-(*GNUNET_ATS_Peer_Iterator) (void *p_it_cls,
- const struct GNUNET_PeerIdentity *id);
-
-
-/**
- * Return all peers currently known to ATS
- *
- * @param handle the address handle to use
- * @param p_it the iterator to call for every peer
- * @param p_it_cls the closure for @a p_it
- */
-void
-GAS_addresses_iterate_peers (struct GAS_Addresses_Handle *handle,
- GNUNET_ATS_Peer_Iterator p_it,
- void *p_it_cls);
-
-
-/**
* Iterator for #GAS_addresses_get_peer_info()
*
* @param p_it_cls closure closure
Modified: gnunet/src/ats/gnunet-service-ats_performance.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_performance.c 2014-12-15 15:16:17 UTC
(rev 34625)
+++ gnunet/src/ats/gnunet-service-ats_performance.c 2014-12-15 18:09:16 UTC
(rev 34626)
@@ -60,23 +60,6 @@
/**
- * We keep clients that are interested in performance in a linked list.
- */
-struct AddressIteration
-{
- /**
- * Actual handle to the client.
- */
- struct PerformanceClient *pc;
-
- int all;
-
- uint32_t id;
-
- unsigned int msg_type;
-};
-
-/**
* Address handle
*/
static struct GAS_Addresses_Handle *GSA_addresses;
@@ -294,41 +277,19 @@
plugin_name,
(unsigned int) ntohl (bandwidth_out.value__),
(unsigned int) ntohl (bandwidth_in.value__));
- GAS_performance_notify_client(pc,
- id,
- plugin_name,
- plugin_addr,
- plugin_addr_len,
- active,
- atsi, atsi_count,
- bandwidth_out, bandwidth_in);
+ GAS_performance_notify_client (pc,
+ id,
+ plugin_name,
+ plugin_addr,
+ plugin_addr_len,
+ active,
+ atsi, atsi_count,
+ bandwidth_out,
+ bandwidth_in);
}
/**
- * Iterator for #GAS_performance_add_client()
- *
- * @param cls the client requesting information
- * @param id result
- */
-static void
-peer_it (void *cls,
- const struct GNUNET_PeerIdentity *id)
-{
- struct PerformanceClient *pc = cls;
-
- if (NULL != id)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Callback for peer `%s'\n",
- GNUNET_i2s (id));
- GAS_addresses_get_peer_info (GSA_addresses, id,
- &peerinfo_it, pc);
- }
-}
-
-
-/**
* Register a new performance client.
*
* @param client handle of the new client
@@ -339,8 +300,8 @@
enum StartFlag flag)
{
struct PerformanceClient *pc;
+
GNUNET_break (NULL == find_client (client));
-
pc = GNUNET_new (struct PerformanceClient);
pc->client = client;
pc->flag = flag;
@@ -349,17 +310,43 @@
"Adding performance client %s PIC\n",
(flag == START_FLAG_PERFORMANCE_WITH_PIC) ? "with" : "without");
- GNUNET_SERVER_notification_context_add (nc, client);
- GNUNET_CONTAINER_DLL_insert (pc_head, pc_tail, pc);
-
- /* Send information about clients */
- GAS_addresses_iterate_peers (GSA_addresses,
- &peer_it,
+ GNUNET_SERVER_notification_context_add (nc,
+ client);
+ GNUNET_CONTAINER_DLL_insert (pc_head,
+ pc_tail,
pc);
+ GAS_addresses_get_peer_info (GSA_addresses,
+ NULL,
+ &peerinfo_it,
+ pc);
}
/**
+ * Information we need for the callbacks to return a list of addresses
+ * back to the client.
+ */
+struct AddressIteration
+{
+ /**
+ * Actual handle to the client.
+ */
+ struct PerformanceClient *pc;
+
+ /**
+ * Are we sending all addresses, or only those that are active?
+ */
+ int all;
+
+ /**
+ * Which ID should be included in the response?
+ */
+ uint32_t id;
+
+};
+
+
+/**
* Send a #GNUNET_MESSAGE_TYPE_ATS_ADDRESSLIST_RESPONSE with the
* given address details to the client identified in @a ai.
*
@@ -427,13 +414,16 @@
memcpy (addrp, plugin_addr, plugin_addr_len);
if (NULL != plugin_name)
strcpy (&addrp[plugin_addr_len], plugin_name);
- GNUNET_SERVER_notification_context_unicast (nc, ai->pc->client, &msg->header,
+ GNUNET_SERVER_notification_context_unicast (nc,
+ ai->pc->client,
+ &msg->header,
GNUNET_NO);
}
/**
- * Iterator for #GAS_addresses_get_peer_info()
+ * Iterator for #GAS_addresses_get_peer_info(), called with peer-specific
+ * information to be passed back to the client.
*
* @param cls closure with our `struct AddressIteration *`
* @param id the peer id
@@ -450,7 +440,8 @@
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 void *plugin_addr,
+ size_t plugin_addr_len,
int active,
const struct GNUNET_ATS_Information *atsi,
uint32_t atsi_count,
@@ -459,30 +450,29 @@
{
struct AddressIteration *ai = cls;
- GNUNET_assert (NULL != ai);
- GNUNET_assert (NULL != ai->pc);
- if (NULL == find_client (ai->pc->client))
- return; /* Client disconnected */
-
- if ((NULL == id) && (NULL == plugin_name) && (NULL == plugin_addr))
+ if ( (NULL == id) &&
+ (NULL == plugin_name) &&
+ (NULL == plugin_addr) )
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Address iteration done\n");
+ "Address iteration done for one peer\n");
return;
}
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
+ "Callback for %s peer `%s' plugin `%s' BW out %u, BW in %u\n",
(active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
GNUNET_i2s (id),
plugin_name,
(unsigned int) ntohl (bandwidth_out.value__),
(unsigned int) ntohl (bandwidth_in.value__));
- /* Transmit result */
- if ((GNUNET_YES == ai->all) || (GNUNET_YES == active))
+ /* Transmit result (either if address is active, or if
+ client wanted all addresses) */
+ if ( (GNUNET_YES == ai->all) ||
+ (GNUNET_YES == active))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Sending result for %s peer `%s' plugin `%s' BW out %u, BW in
%u\n",
+ "Sending result for %s peer `%s' plugin `%s' BW out %u, BW in
%u\n",
(active == GNUNET_YES) ? "ACTIVE" : "INACTIVE",
GNUNET_i2s (id),
plugin_name,
@@ -495,38 +485,13 @@
active,
atsi,
atsi_count,
- bandwidth_out, bandwidth_in);
+ bandwidth_out,
+ bandwidth_in);
}
}
/**
- * Iterator for GAS_handle_request_address_list
- *
- * @param cls the client requesting information, a `struct AddressIteration *`
- * @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_DEBUG,
- "Peer iteration done\n");
- return;
- }
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Callback for peer `%s'\n",
- GNUNET_i2s (id));
- GAS_addresses_get_peer_info (GSA_addresses, id,
- &req_addr_peerinfo_it, ai);
-}
-
-
-/**
* Handle 'address list request' messages from clients.
*
* @param cls unused, NULL
@@ -540,7 +505,7 @@
{
struct PerformanceClient *pc;
struct AddressIteration ai;
- struct AddressListRequestMessage * alrm = (struct AddressListRequestMessage
*) message;
+ const struct AddressListRequestMessage *alrm;
struct GNUNET_PeerIdentity allzeros;
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_zero;
@@ -552,7 +517,7 @@
GNUNET_break (0);
return;
}
-
+ alrm = (const struct AddressListRequestMessage *) message;
ai.all = ntohl (alrm->all);
ai.id = ntohl (alrm->id);
ai.pc = pc;
@@ -564,78 +529,31 @@
sizeof (struct GNUNET_PeerIdentity)))
{
/* Return addresses for all peers */
- GAS_addresses_iterate_peers (GSA_addresses, &req_addr_peer_it, &ai);
- transmit_req_addr (&ai, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0,
- bandwidth_zero, bandwidth_zero);
+ GAS_addresses_get_peer_info (GSA_addresses,
+ NULL,
+ &req_addr_peerinfo_it,
+ &ai);
}
else
{
/* Return addresses for a specific peer */
GAS_addresses_get_peer_info (GSA_addresses,
&alrm->peer,
- &req_addr_peerinfo_it, &ai);
- transmit_req_addr (&ai, NULL, NULL, NULL, 0, GNUNET_NO, NULL, 0,
- bandwidth_zero, bandwidth_zero);
+ &req_addr_peerinfo_it,
+ &ai);
}
- GNUNET_SERVER_receive_done (client, GNUNET_OK);
+ transmit_req_addr (&ai,
+ NULL, NULL, NULL,
+ 0, GNUNET_NO,
+ NULL, 0,
+ bandwidth_zero,
+ bandwidth_zero);
+ GNUNET_SERVER_receive_done (client,
+ GNUNET_OK);
}
/**
- * FIXME.
- */
-void
-GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr, size_t plugin_addr_len,
- int active,
- struct GNUNET_ATS_Information *ats,
- uint32_t ats_count,
- struct GNUNET_BANDWIDTH_Value32NBO
bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
-{
- /* Notify here */
- GAS_performance_notify_all_clients (peer,
- plugin_name,
- plugin_addr,
- plugin_addr_len,
- active,
- ats, ats_count,
- bandwidth_out,
- bandwidth_in);
-
-#if 0
- struct PerformanceClient *cur;
- struct PerformanceMonitorClient *curm;
- struct MonitorResponseMessage *mrm;
- size_t msglen;
-
- msglen = sizeof (struct MonitorResponseMessage) +
- ats_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 (ats_count);
- mrm->peer = *peer;
- memcpy (&mrm[1], ats, ats_count * sizeof (struct GNUNET_ATS_Information));
-
- for (cur = pc_head; NULL != cur; cur = cur->next)
- for (curm = cur->pm_head; NULL != curm; curm = curm->next)
- {
- /* Notify client about update */
- mrm->id = htonl (curm->id);
- GNUNET_SERVER_notification_context_unicast (nc,
- cur->client,
- (struct GNUNET_MessageHeader *) mrm,
- GNUNET_YES);
- }
- GNUNET_free (mrm);
-#endif
-}
-
-
-/**
* Handle 'reservation request' messages from clients.
*
* @param cls unused, NULL
Modified: gnunet/src/ats/gnunet-service-ats_performance.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_performance.h 2014-12-15 15:16:17 UTC
(rev 34625)
+++ gnunet/src/ats/gnunet-service-ats_performance.h 2014-12-15 18:09:16 UTC
(rev 34626)
@@ -53,22 +53,6 @@
/**
- * FIXME.
- */
-void
-GAS_handle_performance_update (struct GNUNET_PeerIdentity *peer,
- const char *plugin_name,
- const void *plugin_addr,
- size_t plugin_addr_len,
- int active,
- struct GNUNET_ATS_Information *ats,
- uint32_t ats_count,
- struct GNUNET_BANDWIDTH_Value32NBO
bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO
bandwidth_in);
-
-
-
-/**
* Transmit the given performance information to all performance
* clients.
*
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r34626 - gnunet/src/ats,
gnunet <=