aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-06-03 09:34:15 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-06-03 09:34:15 +0000
commit7d6e6b045a300cf753e685bc18ec0b1e264d1a25 (patch)
tree2e7069a9bfb46aef0ea9a45b944fbc934aaa2ce1 /src/peerinfo
parent84bcdbdd34bfa4d597ae2635146fe15631b46f44 (diff)
downloadgnunet-7d6e6b045a300cf753e685bc18ec0b1e264d1a25.tar.gz
gnunet-7d6e6b045a300cf753e685bc18ec0b1e264d1a25.zip
fix for bug #0003416: do not stop parsing uri when plugin is not found
- changed semantics for address generator cb: GNUNET_SYSERR indicates stop, >= 0 indicates bytes added
Diffstat (limited to 'src/peerinfo')
-rw-r--r--src/peerinfo/perf_peerinfo_api.c6
-rw-r--r--src/peerinfo/test_peerinfo_api.c6
-rw-r--r--src/peerinfo/test_peerinfo_api_friend_only.c6
-rw-r--r--src/peerinfo/test_peerinfo_api_notify_friend_only.c292
4 files changed, 150 insertions, 160 deletions
diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c
index 4eb84e8c2..3a3213350 100644
--- a/src/peerinfo/perf_peerinfo_api.c
+++ b/src/peerinfo/perf_peerinfo_api.c
@@ -53,16 +53,16 @@ check_it (void *cls, const struct GNUNET_HELLO_Address *address,
53} 53}
54 54
55 55
56static size_t 56static ssize_t
57address_generator (void *cls, size_t max, void *buf) 57address_generator (void *cls, size_t max, void *buf)
58{ 58{
59 size_t *agc = cls; 59 size_t *agc = cls;
60 size_t ret; 60 ssize_t ret;
61 char *caddress; 61 char *caddress;
62 struct GNUNET_HELLO_Address address; 62 struct GNUNET_HELLO_Address address;
63 63
64 if (*agc == 0) 64 if (*agc == 0)
65 return 0; 65 return GNUNET_SYSERR; /* Done */
66 66
67 GNUNET_asprintf (&caddress, "Address%d", *agc); 67 GNUNET_asprintf (&caddress, "Address%d", *agc);
68 address.peer = pid; 68 address.peer = pid;
diff --git a/src/peerinfo/test_peerinfo_api.c b/src/peerinfo/test_peerinfo_api.c
index d69456e0c..b0d120869 100644
--- a/src/peerinfo/test_peerinfo_api.c
+++ b/src/peerinfo/test_peerinfo_api.c
@@ -60,15 +60,15 @@ check_it (void *cls, const struct GNUNET_HELLO_Address *address,
60} 60}
61 61
62 62
63static size_t 63static ssize_t
64address_generator (void *cls, size_t max, void *buf) 64address_generator (void *cls, size_t max, void *buf)
65{ 65{
66 size_t *agc = cls; 66 size_t *agc = cls;
67 size_t ret; 67 ssize_t ret;
68 struct GNUNET_HELLO_Address address; 68 struct GNUNET_HELLO_Address address;
69 69
70 if (0 == *agc) 70 if (0 == *agc)
71 return 0; 71 return GNUNET_SYSERR; /* Done */
72 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); 72 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity));
73 address.address = "Address"; 73 address.address = "Address";
74 address.transport_name = "peerinfotest"; 74 address.transport_name = "peerinfotest";
diff --git a/src/peerinfo/test_peerinfo_api_friend_only.c b/src/peerinfo/test_peerinfo_api_friend_only.c
index e2c4ec574..3b4eeb8f5 100644
--- a/src/peerinfo/test_peerinfo_api_friend_only.c
+++ b/src/peerinfo/test_peerinfo_api_friend_only.c
@@ -42,15 +42,15 @@ static unsigned int retries;
42 42
43static int global_ret; 43static int global_ret;
44 44
45static size_t 45static ssize_t
46address_generator (void *cls, size_t max, void *buf) 46address_generator (void *cls, size_t max, void *buf)
47{ 47{
48 size_t *agc = cls; 48 size_t *agc = cls;
49 size_t ret; 49 ssize_t ret;
50 struct GNUNET_HELLO_Address address; 50 struct GNUNET_HELLO_Address address;
51 51
52 if (0 == *agc) 52 if (0 == *agc)
53 return 0; 53 return GNUNET_SYSERR; /* Done */
54 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); 54 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity));
55 address.address = "Address"; 55 address.address = "Address";
56 address.transport_name = "peerinfotest"; 56 address.transport_name = "peerinfotest";
diff --git a/src/peerinfo/test_peerinfo_api_notify_friend_only.c b/src/peerinfo/test_peerinfo_api_notify_friend_only.c
index f37107898..c47fe6387 100644
--- a/src/peerinfo/test_peerinfo_api_notify_friend_only.c
+++ b/src/peerinfo/test_peerinfo_api_notify_friend_only.c
@@ -1,22 +1,22 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2004, 2009 Christian Grothoff (and other contributing authors) 3 (C) 2004, 2009 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 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 7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version. 8 option) any later version.
9 9
10 GNUnet is distributed in the hope that it will be useful, but 10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details. 13 General Public License for more details.
14 14
15 You should have received a copy of the GNU General Public License 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 16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19 */
20 20
21/** 21/**
22 * @file peerinfo/test_peerinfo_api_notify_friend_only.c 22 * @file peerinfo/test_peerinfo_api_notify_friend_only.c
@@ -42,7 +42,6 @@ static struct GNUNET_PEERINFO_NotifyContext *pnc_wo_fo;
42 42
43static const struct GNUNET_CONFIGURATION_Handle *mycfg; 43static const struct GNUNET_CONFIGURATION_Handle *mycfg;
44 44
45
46static int global_ret; 45static int global_ret;
47 46
48/** 47/**
@@ -61,169 +60,164 @@ struct GNUNET_PeerIdentity pid;
61 60
62GNUNET_SCHEDULER_TaskIdentifier timeout_task; 61GNUNET_SCHEDULER_TaskIdentifier timeout_task;
63 62
64
65static void 63static void
66end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 64end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
67{ 65{
68 timeout_task = GNUNET_SCHEDULER_NO_TASK; 66 timeout_task = GNUNET_SCHEDULER_NO_TASK;
69 GNUNET_break (0); 67 GNUNET_break(0);
70 if (NULL != pnc_wo_fo) 68 if (NULL != pnc_wo_fo)
71 { 69 {
72 GNUNET_PEERINFO_notify_cancel (pnc_wo_fo); 70 GNUNET_PEERINFO_notify_cancel (pnc_wo_fo);
73 pnc_wo_fo = NULL; 71 pnc_wo_fo = NULL;
74 } 72 }
75 if (NULL != pnc_w_fo) 73 if (NULL != pnc_w_fo)
76 { 74 {
77 GNUNET_PEERINFO_notify_cancel (pnc_w_fo); 75 GNUNET_PEERINFO_notify_cancel (pnc_w_fo);
78 pnc_w_fo = NULL; 76 pnc_w_fo = NULL;
79 } 77 }
80 if (NULL != h) 78 if (NULL != h)
81 { 79 {
82 GNUNET_PEERINFO_disconnect (h); 80 GNUNET_PEERINFO_disconnect (h);
83 h = NULL; 81 h = NULL;
84 } 82 }
85 global_ret = 255; 83 global_ret = 255;
86} 84}
87 85
88static void 86static void
89done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 87done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
90{ 88{
91 if (NULL != pnc_w_fo) 89 if (NULL != pnc_w_fo)
92 GNUNET_PEERINFO_notify_cancel (pnc_w_fo); 90 GNUNET_PEERINFO_notify_cancel (pnc_w_fo);
93 pnc_w_fo = NULL; 91 pnc_w_fo = NULL;
94 if (NULL != pnc_wo_fo) 92 if (NULL != pnc_wo_fo)
95 GNUNET_PEERINFO_notify_cancel (pnc_wo_fo); 93 GNUNET_PEERINFO_notify_cancel (pnc_wo_fo);
96 pnc_wo_fo = NULL; 94 pnc_wo_fo = NULL;
97 GNUNET_PEERINFO_disconnect (h); 95 GNUNET_PEERINFO_disconnect (h);
98 h = NULL; 96 h = NULL;
99 97
100 if (GNUNET_SCHEDULER_NO_TASK != timeout_task) 98 if (GNUNET_SCHEDULER_NO_TASK != timeout_task)
101 { 99 {
102 GNUNET_SCHEDULER_cancel (timeout_task); 100 GNUNET_SCHEDULER_cancel (timeout_task);
103 timeout_task = GNUNET_SCHEDULER_NO_TASK; 101 timeout_task = GNUNET_SCHEDULER_NO_TASK;
104 } 102 }
105 103
106 if ((GNUNET_YES == res_cb_w_fo) && (GNUNET_NO == res_cb_wo_fo)) 104 if ((GNUNET_YES == res_cb_w_fo) && (GNUNET_NO == res_cb_wo_fo))
107 global_ret = 0; 105 global_ret = 0;
108 else 106 else
109 GNUNET_break (0); 107 GNUNET_break(0);
110} 108}
111 109
112static size_t 110static ssize_t
113address_generator (void *cls, size_t max, void *buf) 111address_generator (void *cls, size_t max, void *buf)
114{ 112{
115 size_t *agc = cls; 113 size_t *agc = cls;
116 size_t ret; 114 ssize_t ret;
117 struct GNUNET_HELLO_Address address; 115 struct GNUNET_HELLO_Address address;
118 116
119 if (0 == *agc) 117 if (0 == *agc)
120 return 0; 118 return GNUNET_SYSERR; /* Done */
121 memset (&address.peer, 0, sizeof (struct GNUNET_PeerIdentity)); 119 memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity));
122 address.address = "Address"; 120 address.address = "Address";
123 address.transport_name = "peerinfotest"; 121 address.transport_name = "peerinfotest";
124 address.address_length = *agc; 122 address.address_length = *agc;
125 ret = 123 ret = GNUNET_HELLO_add_address (&address,
126 GNUNET_HELLO_add_address (&address, 124 GNUNET_TIME_relative_to_absolute (GNUNET_TIME_UNIT_HOURS), buf, max);
127 GNUNET_TIME_relative_to_absolute
128 (GNUNET_TIME_UNIT_HOURS), buf, max);
129 (*agc)--; 125 (*agc)--;
130 return ret; 126 return ret;
131} 127}
132 128
133static void 129static void
134process_w_fo (void *cls, const struct GNUNET_PeerIdentity *peer, 130process_w_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
135 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 131 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
136{ 132{
137 if (err_msg != NULL) 133 if (err_msg != NULL )
138 { 134 {
139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 135 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
140 _("Error in communication with PEERINFO service\n")); 136 _("Error in communication with PEERINFO service\n"));
141 GNUNET_SCHEDULER_add_now(&done, NULL); 137 GNUNET_SCHEDULER_add_now (&done, NULL );
142 return; 138 return;
143 } 139 }
144 140
145 if (NULL != peer) 141 if (NULL != peer)
146 { 142 {
147 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received callback for peer `%s' %s HELLO\n", 143 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
148 GNUNET_i2s (peer), 144 "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s (peer),
149 (NULL != hello) ? "with" : "without"); 145 (NULL != hello) ? "with" : "without");
150 146
151 if (NULL == hello) 147 if (NULL == hello)
152 return; 148 return;
153 149
154 if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello)) 150 if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello))
155 { 151 {
156 GNUNET_break (0); 152 GNUNET_break(0);
157 return; 153 return;
158 } 154 }
159 155
160 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n", 156 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n",
161 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public", 157 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public",
162 GNUNET_i2s (peer)); 158 GNUNET_i2s (peer));
163 if (0 == memcmp (&pid, peer, sizeof (pid))) 159 if (0 == memcmp (&pid, peer, sizeof(pid)))
164 { 160 {
165 res_cb_w_fo = GNUNET_YES; 161 res_cb_w_fo = GNUNET_YES;
166 GNUNET_SCHEDULER_add_now(&done, NULL); 162 GNUNET_SCHEDULER_add_now (&done, NULL );
167 } 163 }
168 return; 164 return;
169 } 165 }
170} 166}
171 167
172static void 168static void
173process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer, 169process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
174 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 170 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
175{ 171{
176 if (err_msg != NULL) 172 if (err_msg != NULL )
177 { 173 {
178 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 174 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
179 _("Error in communication with PEERINFO service\n")); 175 _("Error in communication with PEERINFO service\n"));
180 GNUNET_SCHEDULER_add_now(&done, NULL); 176 GNUNET_SCHEDULER_add_now (&done, NULL );
181 return; 177 return;
182 } 178 }
183 179
184 if (NULL != peer) 180 if (NULL != peer)
185 { 181 {
186 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received callback for peer `%s' %s HELLO\n", 182 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
187 GNUNET_i2s (peer), 183 "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s (peer),
188 (NULL != hello) ? "with" : "without"); 184 (NULL != hello) ? "with" : "without");
189 185
190 if (NULL == hello) 186 if (NULL == hello)
191 return; 187 return;
192 188
193 if (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello)) 189 if (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello))
194 { 190 {
195 GNUNET_break (0); 191 GNUNET_break(0);
196 return; 192 return;
197 } 193 }
198 194
199 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n", 195 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n",
200 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public", 196 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public",
201 GNUNET_i2s (peer)); 197 GNUNET_i2s (peer));
202 if (0 == memcmp (&pid, peer, sizeof (pid))) 198 if (0 == memcmp (&pid, peer, sizeof(pid)))
203 { 199 {
204 GNUNET_break (0); 200 GNUNET_break(0);
205 res_cb_wo_fo = GNUNET_YES; 201 res_cb_wo_fo = GNUNET_YES;
206 } 202 }
207 } 203 }
208} 204}
209 205
210static void 206static void
211add_peer_done (void *cls, const char *emsg) 207add_peer_done (void *cls, const char *emsg)
212{ 208{
213 if (NULL == emsg) 209 if (NULL == emsg)
214 { 210 {
215 return; 211 return;
216 } 212 }
217 else 213 else
218 { 214 {
219 GNUNET_break (0); 215 GNUNET_break(0);
220 GNUNET_SCHEDULER_cancel (timeout_task); 216 GNUNET_SCHEDULER_cancel (timeout_task);
221 timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL); 217 timeout_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL );
222 } 218 }
223} 219}
224 220
225
226
227static void 221static void
228add_peer () 222add_peer ()
229{ 223{
@@ -231,40 +225,36 @@ add_peer ()
231 size_t agc; 225 size_t agc;
232 226
233 agc = 2; 227 agc = 2;
234 memset (&pid, 32, sizeof (pid)); 228 memset (&pid, 32, sizeof(pid));
235 h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, GNUNET_YES); 229 h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc,
236 GNUNET_PEERINFO_add_peer (h, h2, &add_peer_done, NULL); 230 GNUNET_YES);
237 GNUNET_free (h2); 231 GNUNET_PEERINFO_add_peer (h, h2, &add_peer_done, NULL );
232 GNUNET_free(h2);
238 233
239} 234}
240 235
241
242
243static void 236static void
244run (void *cls, 237run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg,
245 const struct GNUNET_CONFIGURATION_Handle *cfg, 238 struct GNUNET_TESTING_Peer *peer)
246 struct GNUNET_TESTING_Peer *peer)
247{ 239{
248 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 240 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL );
249 mycfg = cfg; 241 mycfg = cfg;
250 pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL); 242 pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL );
251 pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL); 243 pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL );
252 h = GNUNET_PEERINFO_connect (cfg); 244 h = GNUNET_PEERINFO_connect (cfg);
253 GNUNET_assert (NULL != h); 245 GNUNET_assert(NULL != h);
254 add_peer (); 246 add_peer ();
255} 247}
256 248
257
258int 249int
259main (int argc, char *argv[]) 250main (int argc, char *argv[])
260{ 251{
261 res_cb_w_fo = GNUNET_NO; 252 res_cb_w_fo = GNUNET_NO;
262 res_cb_wo_fo = GNUNET_NO; 253 res_cb_wo_fo = GNUNET_NO;
263 global_ret = 3; 254 global_ret = 3;
264 if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only", 255 if (0
265 "peerinfo", 256 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only",
266 "test_peerinfo_api_data.conf", 257 "peerinfo", "test_peerinfo_api_data.conf", &run, NULL ))
267 &run, NULL))
268 return 1; 258 return 1;
269 return global_ret; 259 return global_ret;
270} 260}