aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-12-06 12:17:31 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-12-06 12:17:31 +0000
commit1f64f8561f93fb9537e828404595e76476527fee (patch)
tree26ebf9ed0f3f684d1305a9f35e60815d3a2aa1b1 /src
parent3002ec476deac2cc52b5ca05368c8c90ae8cb74f (diff)
downloadgnunet-1f64f8561f93fb9537e828404595e76476527fee.tar.gz
gnunet-1f64f8561f93fb9537e828404595e76476527fee.zip
changes
Diffstat (limited to 'src')
-rw-r--r--src/ats/test_ats_api_scheduling_add_address.c78
1 files changed, 68 insertions, 10 deletions
diff --git a/src/ats/test_ats_api_scheduling_add_address.c b/src/ats/test_ats_api_scheduling_add_address.c
index 87929d80f..a52bda3e7 100644
--- a/src/ats/test_ats_api_scheduling_add_address.c
+++ b/src/ats/test_ats_api_scheduling_add_address.c
@@ -51,6 +51,16 @@ static struct Test_Address test_addr;
51 */ 51 */
52static struct PeerContext p; 52static struct PeerContext p;
53 53
54/**
55 * HELLO address
56 */
57struct GNUNET_HELLO_Address test_hello_address;
58
59/**
60 * Session
61 */
62static void *test_session;
63
54 64
55static void 65static void
56create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen) 66create_test_address (struct Test_Address *dest, char * plugin, void *session, void *addr, size_t addrlen)
@@ -96,6 +106,41 @@ end ()
96 free_test_address (&test_addr); 106 free_test_address (&test_addr);
97} 107}
98 108
109static int
110compare_addresses (const struct GNUNET_HELLO_Address *address1, void *session1,
111 const struct GNUNET_HELLO_Address *address2, void *session2)
112{
113 if (0 != memcmp (&address1->peer, &address2->peer, sizeof (struct GNUNET_PeerIdentity)))
114 {
115 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid peer id'\n");
116 return GNUNET_SYSERR;
117 }
118 if (0 != strcmp (address1->transport_name, address2->transport_name))
119 {
120 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid plugin'\n");
121 return GNUNET_SYSERR;
122 }
123 if (address1->address_length != address2->address_length)
124 {
125 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address length'\n");
126 return GNUNET_SYSERR;
127
128 }
129 else if (0 != memcmp (address1->address, address2->address, address2->address_length))
130 {
131 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address'\n");
132 return GNUNET_SYSERR;
133 }
134 if (session1 != session2)
135 {
136 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid session1 %p vs session2 %p'\n",
137 session1, session2);
138 return GNUNET_SYSERR;
139
140 }
141 return GNUNET_OK;
142}
143
99static void 144static void
100address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, 145address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
101 struct Session *session, 146 struct Session *session,
@@ -126,9 +171,20 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
126 } 171 }
127 else 172 else
128 { 173 {
129 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback for correct address `%s'\n", 174
130 GNUNET_i2s (&address->peer)); 175 }
131 ret = 0; 176
177 if (GNUNET_OK == compare_addresses (address, session, &test_hello_address, test_session))
178 {
179 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback with correct address `%s'\n",
180 GNUNET_i2s (&address->peer));
181 ret = 0;
182 }
183 else
184 {
185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Callback with invalid address `%s'\n",
186 GNUNET_i2s (&address->peer));
187 ret = 0;
132 } 188 }
133 GNUNET_ATS_suggest_address_cancel (sched_ats, &p.id); 189 GNUNET_ATS_suggest_address_cancel (sched_ats, &p.id);
134 GNUNET_SCHEDULER_add_now (&end, NULL); 190 GNUNET_SCHEDULER_add_now (&end, NULL);
@@ -139,7 +195,7 @@ run (void *cls,
139 const struct GNUNET_CONFIGURATION_Handle *cfg, 195 const struct GNUNET_CONFIGURATION_Handle *cfg,
140 struct GNUNET_TESTING_Peer *peer) 196 struct GNUNET_TESTING_Peer *peer)
141{ 197{
142 struct GNUNET_HELLO_Address hello_address; 198
143 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 199 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
144 200
145 /* Connect to ATS scheduling */ 201 /* Connect to ATS scheduling */
@@ -166,13 +222,15 @@ run (void *cls,
166 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", 222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
167 GNUNET_i2s_full(&p.id)); 223 GNUNET_i2s_full(&p.id));
168 224
169 create_test_address (&test_addr, "test", &test_addr, "test", strlen ("test") + 1); 225
170 /* Adding address without session */ 226 /* Adding address without session */
171 hello_address.peer = p.id; 227 test_session = &test_addr;
172 hello_address.transport_name = test_addr.plugin; 228 create_test_address (&test_addr, "test", test_session, "test", strlen ("test") + 1);
173 hello_address.address = test_addr.addr; 229 test_hello_address.peer = p.id;
174 hello_address.address_length = test_addr.addr_len; 230 test_hello_address.transport_name = test_addr.plugin;
175 GNUNET_ATS_address_add (sched_ats, &hello_address, test_addr.session, NULL, 0); 231 test_hello_address.address = test_addr.addr;
232 test_hello_address.address_length = test_addr.addr_len;
233 GNUNET_ATS_address_add (sched_ats, &test_hello_address, test_session, NULL, 0);
176 234
177 GNUNET_ATS_suggest_address (sched_ats, &p.id); 235 GNUNET_ATS_suggest_address (sched_ats, &p.id);
178} 236}