[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r34958 - in gnunet/src: ats include transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r34958 - in gnunet/src: ats include transport |
Date: |
Thu, 22 Jan 2015 21:54:15 +0100 |
Author: grothoff
Date: 2015-01-22 21:54:15 +0100 (Thu, 22 Jan 2015)
New Revision: 34958
Removed:
gnunet/src/ats/test_ats_api_scheduling_destroy_address_twice.c
Modified:
gnunet/src/ats/Makefile.am
gnunet/src/ats/ats_api_scheduling.c
gnunet/src/ats/test_ats_api_scheduling_destroy_address.c
gnunet/src/ats/test_ats_solver_alternative_after_delete_address.c
gnunet/src/ats/test_ats_solver_request_and_delete_address.c
gnunet/src/include/gnunet_ats_service.h
gnunet/src/transport/gnunet-service-transport_ats.c
gnunet/src/transport/gnunet-service-transport_ats.h
gnunet/src/transport/gnunet-service-transport_neighbours.c
Log:
towards a cleaner ATS scheduling API
Modified: gnunet/src/ats/Makefile.am
===================================================================
--- gnunet/src/ats/Makefile.am 2015-01-22 19:58:04 UTC (rev 34957)
+++ gnunet/src/ats/Makefile.am 2015-01-22 20:54:15 UTC (rev 34958)
@@ -116,7 +116,6 @@
test_ats_api_scheduling_add_address_duplicate \
test_ats_api_scheduling_add_address_inbound \
test_ats_api_scheduling_destroy_address \
- test_ats_api_scheduling_destroy_address_twice \
test_ats_api_scheduling_add_session \
test_ats_api_scheduling_destroy_session \
test_ats_api_delayed_service_scheduling_add_address \
@@ -217,15 +216,6 @@
libgnunetats.la \
$(top_builddir)/src/statistics/libgnunetstatistics.la
-test_ats_api_scheduling_destroy_address_twice_SOURCES = \
- test_ats_api_scheduling_destroy_address_twice.c \
- test_ats_api_common.c test_ats_api_common.h
-test_ats_api_scheduling_destroy_address_twice_LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/testing/libgnunettesting.la \
- libgnunetats.la \
- $(top_builddir)/src/statistics/libgnunetstatistics.la
-
test_ats_api_scheduling_add_session_SOURCES = \
test_ats_api_scheduling_add_session.c test_ats_api_common.c
test_ats_api_scheduling_add_session_LDADD = \
Modified: gnunet/src/ats/ats_api_scheduling.c
===================================================================
--- gnunet/src/ats/ats_api_scheduling.c 2015-01-22 19:58:04 UTC (rev 34957)
+++ gnunet/src/ats/ats_api_scheduling.c 2015-01-22 20:54:15 UTC (rev 34958)
@@ -1257,6 +1257,49 @@
/**
+ * An address was used to initiate a session.
+ *
+ * @param ar address record to update information for
+ * @param session session handle
+ */
+void
+GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
+ struct Session *session)
+{
+ GNUNET_break (NULL == ar->session);
+ ar->session = session;
+}
+
+
+/**
+ * A session was destroyed, disassociate it from the
+ * given address record. If this was an incoming
+ * addess, destroy the address as well.
+ *
+ * @param ar address record to update information for
+ * @param session session handle
+ * @return #GNUNET_YES if the @a ar was destroyed because
+ * it was an incoming address,
+ * #GNUNET_NO if the @ar was kept because we can
+ * use it still to establish a new session
+ */
+int
+GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
+ struct Session *session)
+{
+ GNUNET_break (session == ar->session);
+ ar->session = NULL;
+ if (GNUNET_HELLO_address_check_option (ar->address,
+ GNUNET_HELLO_ADDRESS_INFO_INBOUND))
+ {
+ GNUNET_ATS_address_destroy (ar);
+ return GNUNET_YES;
+ }
+ return GNUNET_NO;
+}
+
+
+/**
* We have updated performance statistics for a given address. Note
* that this function can be called for addresses that are currently
* in use as well as addresses that are valid but not actively in use.
@@ -1265,13 +1308,11 @@
* for later use). Update bandwidth assignments.
*
* @param ar address record to update information for
- * @param session session handle, can be NULL
* @param ats performance data for the address
* @param ats_count number of performance records in @a ats
*/
void
GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
- struct Session *session,
const struct GNUNET_ATS_Information *ats,
uint32_t ats_count)
{
@@ -1281,7 +1322,6 @@
memcpy (ar->ats,
ats,
ats_count * sizeof (struct GNUNET_ATS_Information));
- ar->session = session;
send_add_address_message (ar->sh,
ar,
GNUNET_MESSAGE_TYPE_ATS_ADDRESS_UPDATE);
@@ -1291,111 +1331,73 @@
/**
* An address is now in use or not used any more.
*
- * @param sh handle
- * @param address the address
- * @param session session handle, can be NULL
+ * @param ar the address
* @param in_use #GNUNET_YES if this address is now used, #GNUNET_NO
* if address is not used any more
*/
void
-GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session,
- int in_use)
+GNUNET_ATS_address_set_in_use (struct GNUNET_ATS_AddressRecord *ar,
+ int in_use)
{
+ struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
struct GNUNET_MQ_Envelope *ev;
struct AddressUseMessage *m;
- struct GNUNET_ATS_AddressRecord *ar;
char *pm;
size_t namelen;
size_t msize;
- uint32_t s = 0;
- s = find_session_id (sh, session, address);
- if (s == NOT_FOUND)
- {
- /* trying to set unknown address to NO */
- GNUNET_break (0);
- return;
- }
- ar = sh->session_array[s];
ar->in_use = in_use;
- namelen = (NULL == address->transport_name)
+ namelen = (NULL == ar->address->transport_name)
? 0
- : strlen (address->transport_name) + 1;
- msize = address->address_length + namelen;
+ : strlen (ar->address->transport_name) + 1;
+ msize = ar->address->address_length + namelen;
ev = GNUNET_MQ_msg_extra (m, msize, GNUNET_MESSAGE_TYPE_ATS_ADDRESS_IN_USE);
- m->peer = address->peer;
+ m->peer = ar->address->peer;
m->in_use = htons (in_use);
- m->address_length = htons (address->address_length);
- m->address_local_info = htonl ((uint32_t) address->local_info);
+ m->address_length = htons (ar->address->address_length);
+ m->address_local_info = htonl ((uint32_t) ar->address->local_info);
m->plugin_name_length = htons (namelen);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Setting address used to %s for peer `%s', plugin `%s', session
%p\n",
(GNUNET_YES == in_use) ? "YES" : "NO",
- GNUNET_i2s (&address->peer),
- address->transport_name,
- session);
+ GNUNET_i2s (&ar->address->peer),
+ ar->address->transport_name,
+ ar->session);
- m->session_id = htonl (s);
+ m->session_id = htonl (ar->slot);
pm = (char *) &m[1];
/* FIXME: no need to send the address data */
- memcpy (pm, address->address, address->address_length);
- memcpy (&pm[address->address_length], address->transport_name, namelen);
+ memcpy (pm, ar->address->address, ar->address->address_length);
+ memcpy (&pm[ar->address->address_length],
+ ar->address->transport_name, namelen);
GNUNET_MQ_send (sh->mq, ev);
}
/**
- * An address got destroyed, stop including it as a valid address.
+ * An address got destroyed, stop using it as a valid address.
*
- * If a session is given, only the session will be removed, if no session is
- * given the full address will be deleted.
- *
- * FIXME: the above sentence already indicates that this API is a
- * mess and troublesome. FIX IT!
- *
- * @param sh handle
- * @param address the address
- * @param session session handle that is no longer valid, can be NULL
+ * @param ar address to destroy
*/
void
-GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session)
+GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar)
{
- uint32_t s;
+ struct GNUNET_ATS_SchedulingHandle *sh = ar->sh;
struct GNUNET_MQ_Envelope *ev;
struct AddressDestroyedMessage *m;
- struct GNUNET_ATS_AddressRecord *ar;
char *pm;
size_t namelen;
size_t msize;
- s = find_session_id (sh, session, address);
- if (NOT_FOUND == s)
- {
- GNUNET_assert (0);
- return;
- }
- ar = sh->session_array[s];
- if (NULL != session)
- {
- /* FIXME: this is yucky, fix API! */
- GNUNET_break (ar->session == session);
- ar->session = NULL;
- return;
- }
-
-
- GNUNET_assert (NULL != address->transport_name);
- namelen = strlen (address->transport_name) + 1;
+ GNUNET_break (NULL == ar->session);
+ GNUNET_assert (NULL != ar->address->transport_name);
+ namelen = strlen (ar->address->transport_name) + 1;
GNUNET_assert (namelen > 1);
- msize = address->address_length + namelen;
+ msize = ar->address->address_length + namelen;
if ((msize + sizeof (struct AddressDestroyedMessage) >=
GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
- (address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
+ (ar->address->address_length >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
(namelen >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
{
GNUNET_break (0);
@@ -1403,24 +1405,24 @@
}
ev = GNUNET_MQ_msg_extra (m, msize,
GNUNET_MESSAGE_TYPE_ATS_ADDRESS_DESTROYED);
- m->peer = address->peer;
- m->address_length = htons (address->address_length);
- m->address_local_info = htonl ((uint32_t) address->local_info);
+ m->peer = ar->address->peer;
+ m->address_length = htons (ar->address->address_length);
+ m->address_local_info = htonl ((uint32_t) ar->address->local_info);
m->plugin_name_length = htons (namelen);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Deleting address for peer `%s', plugin `%s', session %p\n",
- GNUNET_i2s (&address->peer),
- address->transport_name,
- session);
+ GNUNET_i2s (&ar->address->peer),
+ ar->address->transport_name,
+ ar->session);
- m->session_id = htonl (s);
+ m->session_id = htonl (ar->slot);
pm = (char *) &m[1];
memcpy (pm,
- address->address,
- address->address_length);
- memcpy (&pm[address->address_length],
- address->transport_name,
+ ar->address->address,
+ ar->address->address_length);
+ memcpy (&pm[ar->address->address_length],
+ ar->address->transport_name,
namelen);
GNUNET_MQ_send (sh->mq, ev);
ar->session = NULL;
Modified: gnunet/src/ats/test_ats_api_scheduling_destroy_address.c
===================================================================
--- gnunet/src/ats/test_ats_api_scheduling_destroy_address.c 2015-01-22
19:58:04 UTC (rev 34957)
+++ gnunet/src/ats/test_ats_api_scheduling_destroy_address.c 2015-01-22
20:54:15 UTC (rev 34958)
@@ -46,6 +46,11 @@
static struct GNUNET_ATS_SchedulingHandle *sched_ats;
/**
+ * Our address record.
+ */
+static struct GNUNET_ATS_AddressRecord *ar;
+
+/**
* Return value
*/
static int ret;
@@ -139,9 +144,8 @@
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Statistics observed address added, now destroying address\n");
- GNUNET_ATS_address_destroyed (sched_ats,
- &test_hello_address,
- test_session);
+ GNUNET_ATS_address_destroy (ar);
+ ar = NULL;
}
return GNUNET_OK;
}
@@ -211,11 +215,11 @@
test_hello_address.address_length = test_addr.addr_len;
/* Adding address */
- GNUNET_ATS_address_add (sched_ats,
- &test_hello_address,
- test_session,
- test_ats_info,
- test_ats_count);
+ ar = GNUNET_ATS_address_add (sched_ats,
+ &test_hello_address,
+ test_session,
+ test_ats_info,
+ test_ats_count);
}
Deleted: gnunet/src/ats/test_ats_api_scheduling_destroy_address_twice.c
===================================================================
--- gnunet/src/ats/test_ats_api_scheduling_destroy_address_twice.c
2015-01-22 19:58:04 UTC (rev 34957)
+++ gnunet/src/ats/test_ats_api_scheduling_destroy_address_twice.c
2015-01-22 20:54:15 UTC (rev 34958)
@@ -1,244 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2010,2011 Christian Grothoff (and other contributing authors)
-
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-*/
-/**
- * @file ats/test_ats_api_scheduling_destroy_address.c
- * @brief test destroying addresses in automatic transport selection
scheduling API
- * @author Christian Grothoff
- * @author Matthias Wachs
- *
- */
-#include "platform.h"
-#include "gnunet_ats_service.h"
-#include "gnunet_testing_lib.h"
-#include "ats.h"
-#include "test_ats_api_common.h"
-
-/**
- * Timeout task
- */
-static struct GNUNET_SCHEDULER_Task * die_task;
-
-/**
- * Statistics handle
- */
-static struct GNUNET_STATISTICS_Handle *stats;
-
-/**
- * Scheduling handle
- */
-static struct GNUNET_ATS_SchedulingHandle *sched_ats;
-
-/**
- * Return value
- */
-static int ret;
-
-/**
- * Test address
- */
-static struct Test_Address test_addr;
-
-/**
- * Test peer
- */
-static struct PeerContext p;
-
-/**
- * HELLO address
- */
-struct GNUNET_HELLO_Address test_hello_address;
-
-/**
- * Session
- */
-static void *test_session;
-
-/**
- * Test ats info
- */
-struct GNUNET_ATS_Information test_ats_info[2];
-
-/**
- * Test ats count
- */
-static uint32_t test_ats_count;
-
-
-static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
-
-
-static int
-stat_cb(void *cls, const char *subsystem,
- const char *name, uint64_t value,
- int is_persistent)
-{
- static int initial_ats_stat_cb = GNUNET_YES;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "ATS statistics: `%s' `%s' %llu\n",
- subsystem,name, value);
-
- if ((0 == value) && (initial_ats_stat_cb == GNUNET_NO))
- {
- fprintf (stderr, "We now expect a warning about destroying an unknown
address...\n");
- GNUNET_ATS_address_destroyed (sched_ats, &test_hello_address,
test_session);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, &end, NULL);
- }
- if ((0 == value) && (initial_ats_stat_cb == GNUNET_YES))
- {
- initial_ats_stat_cb = GNUNET_NO;
- }
- if (1 == value)
- {
- GNUNET_ATS_address_destroyed (sched_ats, &test_hello_address,
test_session);
- }
-
- return GNUNET_OK;
-}
-
-
-static void
-end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
-
- if (die_task != NULL)
- {
- GNUNET_SCHEDULER_cancel (die_task);
- die_task = NULL;
- }
-
- if (NULL != sched_ats)
- {
- GNUNET_ATS_scheduling_done (sched_ats);
- sched_ats = NULL;
- }
-
- GNUNET_STATISTICS_watch_cancel (stats, "ats", "# addresses", &stat_cb, NULL);
- if (NULL != stats)
- {
- GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
- stats = NULL;
- }
-
- free_test_address (&test_addr);
-
- ret = 0;
-}
-
-
-static void
-end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- die_task = NULL;
- end ( NULL, NULL);
- ret = GNUNET_SYSERR;
-}
-
-
-static void
-address_suggest_cb (void *cls,
- const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
- struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not expect suggestion
callback!\n");
- GNUNET_SCHEDULER_add_now (&end_badly, NULL);
-}
-
-
-static int
-dummy_stat (void *cls,
- const char *subsystem,
- const char *name,
- uint64_t value,
- int is_persistent)
-{
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Got dummy stat %s%s:%s = %llu\n",
- is_persistent ? "!" : " ", subsystem, name, value);
- return GNUNET_OK;
-}
-
-
-static void
-got_initial_value (void *cls, int success)
-{
- struct GNUNET_CONFIGURATION_Handle *cfg = cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Got initial value\n");
-
- /* Connect to ATS scheduling */
- sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
- if (sched_ats == NULL)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS
scheduling!\n");
- GNUNET_SCHEDULER_add_now (&end_badly, NULL);
- return;
- }
-
- /* Set up peer */
- memset (&p.id, '1', sizeof (p.id));
- /* 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;
-
- /* Adding address without session */
- test_session = NULL;
- create_test_address (&test_addr, "test", test_session, "test", strlen
("test") + 1);
- test_hello_address.peer = p.id;
- test_hello_address.transport_name = test_addr.plugin;
- test_hello_address.address = test_addr.addr;
- test_hello_address.address_length = test_addr.addr_len;
-
- /* Adding address */
- GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session,
test_ats_info, test_ats_count);
-}
-
-static void
-run (void *cls,
- const struct GNUNET_CONFIGURATION_Handle *cfg,
- struct GNUNET_TESTING_Peer *peer)
-{
- die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
- stats = GNUNET_STATISTICS_create ("ats", cfg);
- GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL);
-
- GNUNET_STATISTICS_get (stats, "ats", "# addresses", TIMEOUT,
- &got_initial_value, &dummy_stat,
- GNUNET_CONFIGURATION_dup (cfg));
-}
-
-
-int
-main (int argc, char *argv[])
-{
- ret = 0;
- if (0 != GNUNET_TESTING_peer_run ("test-ats-api",
- "test_ats_api.conf",
- &run, NULL))
- return 1;
- return ret;
-}
-
-/* end of file test_ats_api_scheduling_destroy_address.c */
Modified: gnunet/src/ats/test_ats_solver_alternative_after_delete_address.c
===================================================================
--- gnunet/src/ats/test_ats_solver_alternative_after_delete_address.c
2015-01-22 19:58:04 UTC (rev 34957)
+++ gnunet/src/ats/test_ats_solver_alternative_after_delete_address.c
2015-01-22 20:54:15 UTC (rev 34958)
@@ -106,7 +106,17 @@
static struct GNUNET_HELLO_Address *second_suggestion = NULL;
+/**
+ * 1st Address we will destroy.
+ */
+static struct GNUNET_ATS_AddressRecord *ar;
+/**
+ * 2nd Address we will destroy.
+ */
+static struct GNUNET_ATS_AddressRecord *ar2;
+
+
static int
stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value,
int is_persistent);
@@ -198,7 +208,8 @@
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting 1st address for peer `%s'
: `%s'\n",
GNUNET_i2s (&address->peer), (char *) address->address);
- GNUNET_ATS_address_destroyed (sched_ats, address, session);
+ GNUNET_ATS_address_destroy (ar);
+ ar = NULL;
first_address_deleted = GNUNET_YES;
return;
@@ -225,7 +236,8 @@
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Deleting 2nd address for peer
`%s' : `%s'\n",
GNUNET_i2s (&address->peer), (char *) address->address);
- GNUNET_ATS_address_destroyed (sched_ats, address, session);
+ GNUNET_ATS_address_destroy (ar2);
+ ar2 = NULL;
second_address_deleted = GNUNET_YES;
return;
}
@@ -318,9 +330,11 @@
/* Adding address */
- GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL, test_ats_info,
test_ats_count);
+ ar = GNUNET_ATS_address_add (sched_ats, &test_hello_address, NULL,
+ test_ats_info, test_ats_count);
/* Adding alternative address */
- GNUNET_ATS_address_add (sched_ats, &alt_test_hello_address, NULL,
test_ats_info, test_ats_count);
+ ar2 = GNUNET_ATS_address_add (sched_ats, &alt_test_hello_address, NULL,
+ test_ats_info, test_ats_count);
}
Modified: gnunet/src/ats/test_ats_solver_request_and_delete_address.c
===================================================================
--- gnunet/src/ats/test_ats_solver_request_and_delete_address.c 2015-01-22
19:58:04 UTC (rev 34957)
+++ gnunet/src/ats/test_ats_solver_request_and_delete_address.c 2015-01-22
20:54:15 UTC (rev 34958)
@@ -85,6 +85,10 @@
*/
static uint32_t test_ats_count;
+/**
+ * The address we will delete.
+ */
+static struct GNUNET_ATS_AddressRecord *ar;
static int address_deleted = GNUNET_NO;
@@ -152,7 +156,8 @@
"Received sugggestion for peer `%s', deleting address\n",
GNUNET_i2s (&address->peer));
address_deleted = GNUNET_YES;
- GNUNET_ATS_address_destroyed (sched_ats, &test_hello_address, NULL);
+ GNUNET_ATS_address_destroy (ar);
+ ar = NULL;
}
else
{
@@ -231,9 +236,9 @@
test_hello_address.address_length = test_addr.addr_len;
/* Adding address */
- GNUNET_ATS_address_add (sched_ats, &test_hello_address,
- NULL,
- test_ats_info, test_ats_count);
+ ar = GNUNET_ATS_address_add (sched_ats, &test_hello_address,
+ NULL,
+ test_ats_info, test_ats_count);
}
Modified: gnunet/src/include/gnunet_ats_service.h
===================================================================
--- gnunet/src/include/gnunet_ats_service.h 2015-01-22 19:58:04 UTC (rev
34957)
+++ gnunet/src/include/gnunet_ats_service.h 2015-01-22 20:54:15 UTC (rev
34958)
@@ -460,7 +460,7 @@
*
* @param sh handle
* @param address the address
- * @param session session handle (if available)
+ * @param session session handle (if available, i.e. for incoming connections)
* @param ats performance data for the address
* @param ats_count number of performance records in @a ats
* @return handle to the address representation inside ATS, NULL
@@ -476,6 +476,34 @@
/**
+ * An address was used to initiate a session.
+ *
+ * @param ar address record to update information for
+ * @param session session handle
+ */
+void
+GNUNET_ATS_address_add_session (struct GNUNET_ATS_AddressRecord *ar,
+ struct Session *session);
+
+
+/**
+ * A session was destroyed, disassociate it from the
+ * given address record. If this was an incoming
+ * addess, destroy the address as well.
+ *
+ * @param ar address record to update information for
+ * @param session session handle
+ * @return #GNUNET_YES if the @a ar was destroyed because
+ * it was an incoming address,
+ * #GNUNET_NO if the @ar was kept because we can
+ * use it still to establish a new session
+ */
+int
+GNUNET_ATS_address_del_session (struct GNUNET_ATS_AddressRecord *ar,
+ struct Session *session);
+
+
+/**
* We have updated performance statistics for a given address. Note
* that this function can be called for addresses that are currently
* in use as well as addresses that are valid but not actively in use.
@@ -486,49 +514,38 @@
* suggest to switch addresses.
*
* @param ar address record to update information for
- * @param session session handle (if available)
* @param ats performance data for the address
* @param ats_count number of performance records in @a ats
*/
void
GNUNET_ATS_address_update (struct GNUNET_ATS_AddressRecord *ar,
- struct Session *session,
const struct GNUNET_ATS_Information *ats,
uint32_t ats_count);
/**
- * An address is now in use or not used any more.
+ * An address is now in use, or not used any more.
*
- * @param sh handle
- * @param address the address
- * @param session session handle
+ * @param ar address record for which to toggle the flag
* @param in_use #GNUNET_YES if this address is now used, #GNUNET_NO
- * if address is not used any more
+ * if address is not used any more
*/
void
-GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session,
- int in_use);
+GNUNET_ATS_address_set_in_use (struct GNUNET_ATS_AddressRecord *ar,
+ int in_use);
/**
- * An address got destroyed, stop including it as a valid address.
+ * An address got destroyed, stop using it as a valid address.
*
- * If a session is given, only the session will be removed, if no session is
- * given the full address will be deleted.
- *
- * @param sh handle
- * @param address the address
- * @param session session handle that is no longer valid (if available)
+ * @param ar address record to destroy, it's validation has
+ * expired and ATS may no longer use it
*/
void
-GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
- const struct GNUNET_HELLO_Address *address,
- struct Session *session);
+GNUNET_ATS_address_destroy (struct GNUNET_ATS_AddressRecord *ar);
+
/* ******************************** Performance API
***************************** */
/**
Modified: gnunet/src/transport/gnunet-service-transport_ats.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_ats.c 2015-01-22 19:58:04 UTC
(rev 34957)
+++ gnunet/src/transport/gnunet-service-transport_ats.c 2015-01-22 20:54:15 UTC
(rev 34958)
@@ -254,11 +254,8 @@
"Telling ATS about new session %p for peer %s\n",
session,
GNUNET_i2s (&address->peer));
- // FIXME: tell ATS API, but not using this call:
- GNUNET_ATS_address_update (ai->ar,
- session,
- NULL, 0);
-
+ GNUNET_ATS_address_add_session (ai->ar,
+ session);
}
@@ -300,14 +297,12 @@
"Telling ATS to destroy session %p from peer %s\n",
session,
GNUNET_i2s (&address->peer));
- /* FIXME: if this was an *inbound* address, destroy it
- FULLY here well; but use different API, as looking up
- inbound address without session is not great... */
- GNUNET_ATS_address_destroyed (GST_ats, address, session);
if (GNUNET_YES ==
- GNUNET_HELLO_address_check_option (address,
- GNUNET_HELLO_ADDRESS_INFO_INBOUND))
+ GNUNET_ATS_address_del_session (ai->ar, session))
+ {
+ ai->ar = NULL;
GST_ats_expire_address (address);
+ }
}
@@ -355,13 +350,36 @@
ats,
ats_count);
GNUNET_ATS_address_update (ai->ar,
- session,
ats_new, ats_count);
GNUNET_free_non_null (ats_new);
}
/**
+ * Notify ATS about a new session now being in use (or not).
+ *
+ * @param address the address
+ * @param session the session
+ * @param in_use #GNUNET_YES or #GNUNET_NO
+ */
+void
+GST_ats_set_in_use (const struct GNUNET_HELLO_Address *address,
+ struct Session *session,
+ int in_use)
+{
+ struct AddressInfo *ai;
+
+ ai = find_ai (address, session);
+ if (NULL == ai)
+ {
+ GNUNET_break (0);
+ return;
+ }
+ GNUNET_ATS_address_set_in_use (ai->ar, in_use);
+}
+
+
+/**
* Notify ATS that the address has expired and thus cannot
* be used any longer. This function must only be called
* if the corresponding session is already gone.
@@ -388,7 +406,8 @@
"transport-ats",
"Telling ATS to destroy address from peer %s\n",
GNUNET_i2s (&address->peer));
- GNUNET_ATS_address_destroyed (GST_ats, address, NULL);
+ if (NULL != ai->ar)
+ GNUNET_ATS_address_destroy (ai->ar);
GNUNET_HELLO_address_free (ai->address);
GNUNET_free (ai);
}
Modified: gnunet/src/transport/gnunet-service-transport_ats.h
===================================================================
--- gnunet/src/transport/gnunet-service-transport_ats.h 2015-01-22 19:58:04 UTC
(rev 34957)
+++ gnunet/src/transport/gnunet-service-transport_ats.h 2015-01-22 20:54:15 UTC
(rev 34958)
@@ -79,6 +79,19 @@
/**
+ * Notify ATS about a new session now being in use (or not).
+ *
+ * @param address the address
+ * @param session the session
+ * @param in_use #GNUNET_YES or #GNUNET_NO
+ */
+void
+GST_ats_set_in_use (const struct GNUNET_HELLO_Address *address,
+ struct Session *session,
+ int in_use);
+
+
+/**
* Notify ATS about property changes to an address
*
* @param address the address
Modified: gnunet/src/transport/gnunet-service-transport_neighbours.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_neighbours.c 2015-01-22
19:58:04 UTC (rev 34957)
+++ gnunet/src/transport/gnunet-service-transport_neighbours.c 2015-01-22
20:54:15 UTC (rev 34958)
@@ -631,8 +631,12 @@
{
if (GNUNET_YES == na->ats_active)
{
- GST_validation_set_address_use (na->address, na->session, GNUNET_NO);
- GNUNET_ATS_address_in_use (GST_ats, na->address, na->session, GNUNET_NO);
+ GST_validation_set_address_use (na->address,
+ na->session,
+ GNUNET_NO);
+ GST_ats_set_in_use (na->address,
+ na->session,
+ GNUNET_NO);
}
na->bandwidth_in = GNUNET_BANDWIDTH_value_init (0);
@@ -816,10 +820,9 @@
if (is_active != n->primary_address.ats_active)
{
n->primary_address.ats_active = is_active;
- GNUNET_ATS_address_in_use (GST_ats,
- n->primary_address.address,
- n->primary_address.session,
- is_active);
+ GST_ats_set_in_use (n->primary_address.address,
+ n->primary_address.session,
+ is_active);
GST_validation_set_address_use (n->primary_address.address,
n->primary_address.session,
is_active);
@@ -855,10 +858,9 @@
if (GNUNET_YES == is_active)
{
/* Telling ATS about new session */
- GNUNET_ATS_address_in_use (GST_ats,
- n->primary_address.address,
- n->primary_address.session,
- GNUNET_YES);
+ GST_ats_set_in_use (n->primary_address.address,
+ n->primary_address.session,
+ GNUNET_YES);
GST_validation_set_address_use (n->primary_address.address,
n->primary_address.session,
GNUNET_YES);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r34958 - in gnunet/src: ats include transport,
gnunet <=