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_destroy_session.c
22 * @brief test destroying sessions with unknown address (address NULL, length 0)
23 * in automatic transport selection scheduling API
24 * @author Christian Grothoff
25 * @author Matthias Wachs
29 #include "gnunet_ats_service.h"
30 #include "gnunet_testing_lib-new.h"
33 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
35 static GNUNET_SCHEDULER_TaskIdentifier die_task;
37 static struct GNUNET_ATS_SchedulingHandle *ats;
51 struct GNUNET_ATS_Information *ats;
59 struct GNUNET_PeerIdentity id;
65 static struct Address test_addr;
67 static struct PeerContext p;
69 static struct GNUNET_HELLO_Address hello_address;
73 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
75 die_task = GNUNET_SCHEDULER_NO_TASK;
77 GNUNET_ATS_scheduling_done (ats);
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n");
86 if (die_task != GNUNET_SCHEDULER_NO_TASK)
88 GNUNET_SCHEDULER_cancel (die_task);
89 die_task = GNUNET_SCHEDULER_NO_TASK;
91 GNUNET_ATS_scheduling_done (ats);
103 address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
104 struct Session *session,
105 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
106 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
107 const struct GNUNET_ATS_Information *atsi,
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Stage %u: ATS suggests address `%s' session %p\n",
111 stage, GNUNET_i2s (&address->peer), session);
112 GNUNET_ATS_reset_backoff(ats, &address->peer);
115 memcmp (&address->peer, &p.id,
116 sizeof (struct GNUNET_PeerIdentity)));
117 GNUNET_assert (0 == strcmp (address->transport_name, test_addr.plugin));
118 GNUNET_assert (address->address_length == test_addr.addr_len);
120 memcmp (address->address, test_addr.plugin,
121 address->address_length));
122 GNUNET_assert (test_addr.session == session);
126 /* Delete session without the address */
127 struct GNUNET_HELLO_Address hello_address_2;
128 hello_address_2.peer = p.id;
129 hello_address_2.transport_name = test_addr.plugin;
130 hello_address_2.address = NULL;
131 hello_address_2.address_length = 0;
133 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
134 "Stage %u: Destroying address for peer `%s' address %p length %u session %p\n",
136 GNUNET_i2s (&hello_address_2.peer),
137 hello_address_2.address,
138 hello_address_2.address_length,
141 GNUNET_ATS_address_destroyed (ats, &hello_address_2, test_addr.session);
142 test_addr.session = NULL;
143 GNUNET_ATS_suggest_address (ats, &p.id);
148 GNUNET_SCHEDULER_add_now (&end, NULL);
156 const struct GNUNET_CONFIGURATION_Handle *cfg,
157 struct GNUNET_TESTING_Peer *peer)
161 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
162 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
171 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
176 test_addr.plugin = "test";
177 test_addr.session = &test_addr;
178 test_addr.addr = GNUNET_strdup ("test");
179 test_addr.addr_len = 4;
181 /* Adding address with session */
182 hello_address.peer = p.id;
183 hello_address.transport_name = test_addr.plugin;
184 hello_address.address = test_addr.addr;
185 hello_address.address_length = test_addr.addr_len;
186 GNUNET_ATS_address_add (ats, &hello_address, test_addr.session, NULL, 0);
187 GNUNET_ATS_suggest_address (ats, &p.id);
192 main (int argc, char *argv[])
194 if (0 != GNUNET_TESTING_peer_run ("test_ats_api_scheduling_destroy_session",
201 /* end of file test_ats_api_scheduling_destroy_session.c */