[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r25525 - gnunet/src/ats
From: |
gnunet |
Subject: |
[GNUnet-SVN] r25525 - gnunet/src/ats |
Date: |
Tue, 18 Dec 2012 14:13:40 +0100 |
Author: wachs
Date: 2012-12-18 14:13:40 +0100 (Tue, 18 Dec 2012)
New Revision: 25525
Modified:
gnunet/src/ats/ats_api_performance.c
gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c
gnunet/src/ats/test_ats_simplistic_change_preference.c
Log:
- preference mgmt
Modified: gnunet/src/ats/ats_api_performance.c
===================================================================
--- gnunet/src/ats/ats_api_performance.c 2012-12-18 12:22:39 UTC (rev
25524)
+++ gnunet/src/ats/ats_api_performance.c 2012-12-18 13:13:40 UTC (rev
25525)
@@ -830,6 +830,22 @@
/**
+ * Convert a GNUNET_ATS_PreferenceType to a string
+ *
+ * @param type the preference type
+ * @return a string or NULL if invalid
+ */
+const char *
+GNUNET_ATS_print_preference_type (uint32_t type)
+{
+ char *prefs[GNUNET_ATS_PreferenceCount] = GNUNET_ATS_PreferenceTypeString;
+ if (type < GNUNET_ATS_PreferenceCount)
+ return prefs[type];
+ return NULL;
+}
+
+
+/**
* Change preferences for the given peer. Preference changes are forgotten if
peers
* disconnect.
*
Modified: gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c 2012-12-18
12:22:39 UTC (rev 25524)
+++ gnunet/src/ats/gnunet-service-ats_addresses_simplistic.c 2012-12-18
13:13:40 UTC (rev 25525)
@@ -157,11 +157,23 @@
struct ATS_Address *addr;
};
+
+struct PreferencePeer
+{
+ struct GNUNET_PeerIdentity id;
+
+ float prefs[GNUNET_ATS_PreferenceCount];
+};
+
struct PreferenceClient
{
struct PreferenceClient *prev;
struct PreferenceClient *next;
- void *client;
+ void *client;
+
+ float prefs[GNUNET_ATS_PreferenceCount];
+
+ struct GNUNET_CONTAINER_MultiHashMap *peers;
};
/**
@@ -228,6 +240,18 @@
}
+static int
+delete_peers (void *cls,
+ const struct GNUNET_HashCode * key,
+ void *value)
+{
+ struct GNUNET_CONTAINER_MultiHashMap *m = cls;
+ struct PreferencePeer *p = (struct PreferencePeer *) value;
+ GNUNET_CONTAINER_multihashmap_remove (m, &p->id.hashPubKey, p);
+ GNUNET_free (p);
+ return GNUNET_OK;
+}
+
/**
* Shutdown the simplistic problem solving component
*
@@ -297,6 +321,8 @@
{
next_pc = pc->next;
GNUNET_CONTAINER_DLL_remove (s->pc_head, s->pc_tail, pc);
+ GNUNET_CONTAINER_multihashmap_iterate (pc->peers, &delete_peers,
pc->peers);
+ GNUNET_CONTAINER_multihashmap_destroy (pc->peers);
GNUNET_free (pc);
}
GNUNET_free (s);
@@ -858,6 +884,17 @@
}
+static double
+update_pref_value (struct PreferenceClient *cur, int kind, float score)
+{
+ float res = (cur->prefs[kind] + score) / 2; /* change update algorithm here
*/;
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p changes preference for peer type %s
from %f to %f\n",
+ cur->client,
+ GNUNET_ATS_print_preference_type (kind),
+ cur->prefs[kind], res);
+ return res;
+}
+
/**
* Changes the preferences for a peer in the problem
*
@@ -876,30 +913,61 @@
{
struct GAS_SIMPLISTIC_Handle *s = solver;
struct PreferenceClient *cur;
+ struct PreferencePeer *p;
+ int i;
GNUNET_assert (NULL != solver);
GNUNET_assert (NULL != client);
GNUNET_assert (NULL != peer);
- LOG (GNUNET_ERROR_TYPE_ERROR, "Client %p changes preference for peer `%s'
%d\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Client %p changes preference for peer `%s' %s
%f\n",
client,
GNUNET_i2s (peer),
+ GNUNET_ATS_print_preference_type (kind),
score);
+ if (kind >= GNUNET_ATS_PreferenceCount)
+ {
+ GNUNET_break (0);
+ return;
+ }
+
for (cur = s->pc_head; NULL != cur; cur = cur->next)
{
if (client == cur->client)
break;
}
-
if (NULL == cur)
{
cur = GNUNET_malloc (sizeof (struct PreferenceClient));
cur->client = client;
+ cur->peers = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
GNUNET_CONTAINER_DLL_insert (s->pc_head, s->pc_tail, cur);
}
+ p = GNUNET_CONTAINER_multihashmap_get (cur->peers, &peer->hashPubKey);
+ if (NULL == p)
+ {
+ p = GNUNET_malloc (sizeof (struct PreferencePeer));
+ p->id = (*peer);
+ for (i = 0; i < GNUNET_ATS_PreferenceCount; i++)
+ p->prefs[i] = 1;
+ GNUNET_CONTAINER_multihashmap_put (cur->peers,
+ &peer->hashPubKey,
+ p,
+
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
+ }
+ switch (kind) {
+ case GNUNET_ATS_PREFERENCE_BANDWIDTH:
+ case GNUNET_ATS_PREFERENCE_LATENCY:
+ p->prefs[kind] = update_pref_value (cur, kind, score);
+ break;
+ case GNUNET_ATS_PREFERENCE_END:
+ break;
+ default:
+ break;
+ }
}
Modified: gnunet/src/ats/test_ats_simplistic_change_preference.c
===================================================================
--- gnunet/src/ats/test_ats_simplistic_change_preference.c 2012-12-18
12:22:39 UTC (rev 25524)
+++ gnunet/src/ats/test_ats_simplistic_change_preference.c 2012-12-18
13:13:40 UTC (rev 25525)
@@ -46,6 +46,12 @@
static struct GNUNET_ATS_SchedulingHandle *sched_ats;
/**
+ * Scheduling handle
+ */
+static struct GNUNET_ATS_PerformanceHandle *perf_ats;
+
+
+/**
* Return value
*/
static int ret;
@@ -99,6 +105,8 @@
if (sched_ats != NULL)
GNUNET_ATS_scheduling_done (sched_ats);
+ if (perf_ats != NULL)
+ GNUNET_ATS_performance_done (perf_ats);
free_test_address (&test_addr[0]);
ret = GNUNET_SYSERR;
}
@@ -113,6 +121,8 @@
GNUNET_SCHEDULER_cancel (die_task);
die_task = GNUNET_SCHEDULER_NO_TASK;
}
+ GNUNET_ATS_performance_done (perf_ats);
+ perf_ats = NULL;
GNUNET_ATS_scheduling_done (sched_ats);
sched_ats = NULL;
free_test_address (&test_addr[0]);
@@ -177,26 +187,17 @@
GNUNET_SCHEDULER_add_now (&end, NULL);
return;
}
- p[0].bw_out_assigned = bw_out;
- p[0].bw_in_assigned = bw_in;
+
stage ++;
- /* Add a 2nd address */
- /* Prepare ATS Information */
- test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE);
- test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN);
- test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
- test_ats_info[1].value = htonl(1);
- test_ats_count = 2;
+ /* Change preference */
+ GNUNET_ATS_change_preference (perf_ats,
+ &p[0].id,
+ GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000,
GNUNET_ATS_PREFERENCE_END);
- /* Adding address with session */
- test_session[1] = &test_addr[1];
- create_test_address (&test_addr[1], "test1", test_session[1], "test1",
strlen ("test1") + 1);
- test_hello_address[1].peer = p[1].id;
- test_hello_address[1].transport_name = test_addr[1].plugin;
- test_hello_address[1].address = test_addr[1].addr;
- test_hello_address[1].address_length = test_addr[1].addr_len;
- GNUNET_ATS_address_add (sched_ats, &test_hello_address[1],
test_session[1], test_ats_info, test_ats_count);
+ /* Request address */
+ GNUNET_ATS_suggest_address (sched_ats, &p[0].id);
+ return;
}
if (1 == stage)
{
@@ -321,6 +322,15 @@
return;
}
+ perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL);
+ if (perf_ats == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS
performance!\n");
+ ret = 1;
+ end ();
+ return;
+ }
+
/* Set up peer 0 */
if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0,
&p[0].id.hashPubKey))
{
@@ -372,7 +382,7 @@
int
main (int argc, char *argv[])
{
- if (0 != GNUNET_TESTING_peer_run ("test_ats_simplististic",
+ if (0 != GNUNET_TESTING_peer_run ("test_ats_simplistic_change_preference",
"test_ats_api.conf",
&run, NULL))
return 1;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r25525 - gnunet/src/ats,
gnunet <=