2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file ats/test_ats_api_scheduling_add_address.c
22 * @brief test adding addresses in automatic transport selection scheduling API
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_ats_service.h"
28 #include "gnunet_testing_lib-new.h"
31 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
33 static GNUNET_SCHEDULER_TaskIdentifier die_task;
35 static struct GNUNET_ATS_SchedulingHandle *ats;
47 struct GNUNET_ATS_Information *ats;
55 struct GNUNET_PeerIdentity id;
61 static struct Address test_addr;
63 static struct PeerContext p;
65 static struct GNUNET_ATS_Information atsi;
69 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
71 die_task = GNUNET_SCHEDULER_NO_TASK;
73 GNUNET_ATS_scheduling_done (ats);
81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
82 if (die_task != GNUNET_SCHEDULER_NO_TASK)
84 GNUNET_SCHEDULER_cancel (die_task);
85 die_task = GNUNET_SCHEDULER_NO_TASK;
87 GNUNET_ATS_scheduling_done (ats);
93 address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
94 struct Session *session,
95 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
96 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
97 const struct GNUNET_ATS_Information *ats,
100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggests address `%s'\n",
101 GNUNET_i2s (&address->peer));
104 memcmp (&address->peer, &p.id,
105 sizeof (struct GNUNET_PeerIdentity)));
106 GNUNET_assert (0 == strcmp (address->transport_name, test_addr.plugin));
107 GNUNET_assert (address->address_length == test_addr.addr_len);
109 memcmp (address->address, test_addr.plugin,
110 address->address_length));
111 GNUNET_assert (test_addr.session == session);
115 GNUNET_SCHEDULER_add_now (&end, NULL);
121 const struct GNUNET_CONFIGURATION_Handle *cfg,
122 struct GNUNET_TESTING_Peer *peer)
124 struct GNUNET_HELLO_Address address0;
127 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
128 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
138 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
140 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
143 test_addr.plugin = "test";
144 test_addr.session = NULL;
145 test_addr.addr = GNUNET_strdup ("test");
146 test_addr.addr_len = 4;
148 /* Adding address without session */
149 address0.peer = p.id;
150 address0.transport_name = test_addr.plugin;
151 address0.address = test_addr.addr;
152 address0.address_length = test_addr.addr_len;
153 GNUNET_ATS_address_add (ats, &address0, test_addr.session, NULL, 0);
155 test_addr.session = &test_addr;
156 /* Update address with session */
157 GNUNET_ATS_address_add (ats, &address0, test_addr.session, NULL, 0);
159 /* Update address with session */
160 test_addr.session = &address0;
161 GNUNET_assert (GNUNET_OK == GNUNET_ATS_address_add (ats, &address0, test_addr.session, NULL, 0));
162 GNUNET_log_skip (2, GNUNET_NO);
163 GNUNET_assert (GNUNET_SYSERR == GNUNET_ATS_address_add (ats, &address0, test_addr.session, NULL, 0));
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Requesting peer `%s'\n",
167 GNUNET_ATS_suggest_address (ats, &p.id);
172 main (int argc, char *argv[])
174 if (0 != GNUNET_TESTING_peer_run ("test_ats_api_scheduling_add_address",
181 /* end of file test_ats_api_scheduling_add_address.c */