aboutsummaryrefslogtreecommitdiff
path: root/src/peerinfo/test_peerinfo_api_notify_friend_only.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/peerinfo/test_peerinfo_api_notify_friend_only.c')
-rw-r--r--src/peerinfo/test_peerinfo_api_notify_friend_only.c213
1 files changed, 108 insertions, 105 deletions
diff --git a/src/peerinfo/test_peerinfo_api_notify_friend_only.c b/src/peerinfo/test_peerinfo_api_notify_friend_only.c
index 80b5883de..7c5162102 100644
--- a/src/peerinfo/test_peerinfo_api_notify_friend_only.c
+++ b/src/peerinfo/test_peerinfo_api_notify_friend_only.c
@@ -34,7 +34,7 @@
34#include "gnunet_testing_lib.h" 34#include "gnunet_testing_lib.h"
35#include "peerinfo.h" 35#include "peerinfo.h"
36 36
37#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) 37#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
38 38
39static struct GNUNET_PEERINFO_Handle *h; 39static struct GNUNET_PEERINFO_Handle *h;
40static struct GNUNET_PEERINFO_NotifyContext *pnc_w_fo; 40static struct GNUNET_PEERINFO_NotifyContext *pnc_w_fo;
@@ -61,55 +61,55 @@ struct GNUNET_PeerIdentity pid;
61struct GNUNET_SCHEDULER_Task *timeout_task; 61struct GNUNET_SCHEDULER_Task *timeout_task;
62 62
63static void 63static void
64end_badly(void *cls) 64end_badly (void *cls)
65{ 65{
66 timeout_task = NULL; 66 timeout_task = NULL;
67 GNUNET_break(0); 67 GNUNET_break (0);
68 if (NULL != pnc_wo_fo) 68 if (NULL != pnc_wo_fo)
69 { 69 {
70 GNUNET_PEERINFO_notify_cancel(pnc_wo_fo); 70 GNUNET_PEERINFO_notify_cancel (pnc_wo_fo);
71 pnc_wo_fo = NULL; 71 pnc_wo_fo = NULL;
72 } 72 }
73 if (NULL != pnc_w_fo) 73 if (NULL != pnc_w_fo)
74 { 74 {
75 GNUNET_PEERINFO_notify_cancel(pnc_w_fo); 75 GNUNET_PEERINFO_notify_cancel (pnc_w_fo);
76 pnc_w_fo = NULL; 76 pnc_w_fo = NULL;
77 } 77 }
78 if (NULL != h) 78 if (NULL != h)
79 { 79 {
80 GNUNET_PEERINFO_disconnect(h); 80 GNUNET_PEERINFO_disconnect (h);
81 h = NULL; 81 h = NULL;
82 } 82 }
83 global_ret = 255; 83 global_ret = 255;
84} 84}
85 85
86 86
87static void 87static void
88done(void *cls) 88done (void *cls)
89{ 89{
90 if (NULL != pnc_w_fo) 90 if (NULL != pnc_w_fo)
91 GNUNET_PEERINFO_notify_cancel(pnc_w_fo); 91 GNUNET_PEERINFO_notify_cancel (pnc_w_fo);
92 pnc_w_fo = NULL; 92 pnc_w_fo = NULL;
93 if (NULL != pnc_wo_fo) 93 if (NULL != pnc_wo_fo)
94 GNUNET_PEERINFO_notify_cancel(pnc_wo_fo); 94 GNUNET_PEERINFO_notify_cancel (pnc_wo_fo);
95 pnc_wo_fo = NULL; 95 pnc_wo_fo = NULL;
96 GNUNET_PEERINFO_disconnect(h); 96 GNUNET_PEERINFO_disconnect (h);
97 h = NULL; 97 h = NULL;
98 98
99 if (NULL != timeout_task) 99 if (NULL != timeout_task)
100 { 100 {
101 GNUNET_SCHEDULER_cancel(timeout_task); 101 GNUNET_SCHEDULER_cancel (timeout_task);
102 timeout_task = NULL; 102 timeout_task = NULL;
103 } 103 }
104 104
105 if ((GNUNET_YES == res_cb_w_fo) && (GNUNET_NO == res_cb_wo_fo)) 105 if ((GNUNET_YES == res_cb_w_fo) && (GNUNET_NO == res_cb_wo_fo))
106 global_ret = 0; 106 global_ret = 0;
107 else 107 else
108 GNUNET_break(0); 108 GNUNET_break (0);
109} 109}
110 110
111static ssize_t 111static ssize_t
112address_generator(void *cls, size_t max, void *buf) 112address_generator (void *cls, size_t max, void *buf)
113{ 113{
114 size_t *agc = cls; 114 size_t *agc = cls;
115 ssize_t ret; 115 ssize_t ret;
@@ -117,137 +117,140 @@ address_generator(void *cls, size_t max, void *buf)
117 117
118 if (0 == *agc) 118 if (0 == *agc)
119 return GNUNET_SYSERR; /* Done */ 119 return GNUNET_SYSERR; /* Done */
120 memset(&address.peer, 0, sizeof(struct GNUNET_PeerIdentity)); 120 memset (&address.peer, 0, sizeof(struct GNUNET_PeerIdentity));
121 address.address = "Address"; 121 address.address = "Address";
122 address.transport_name = "peerinfotest"; 122 address.transport_name = "peerinfotest";
123 address.address_length = *agc; 123 address.address_length = *agc;
124 ret = GNUNET_HELLO_add_address(&address, 124 ret = GNUNET_HELLO_add_address (&address,
125 GNUNET_TIME_relative_to_absolute(GNUNET_TIME_UNIT_HOURS), buf, max); 125 GNUNET_TIME_relative_to_absolute (
126 GNUNET_TIME_UNIT_HOURS), buf, max);
126 (*agc)--; 127 (*agc)--;
127 return ret; 128 return ret;
128} 129}
129 130
130 131
131static void 132static void
132process_w_fo(void *cls, 133process_w_fo (void *cls,
133 const struct GNUNET_PeerIdentity *peer, 134 const struct GNUNET_PeerIdentity *peer,
134 const struct GNUNET_HELLO_Message *hello, 135 const struct GNUNET_HELLO_Message *hello,
135 const char *err_msg) 136 const char *err_msg)
136{ 137{
137 if (err_msg != NULL) 138 if (err_msg != NULL)
139 {
140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
141 _ ("Error in communication with PEERINFO service\n"));
142 GNUNET_SCHEDULER_add_now (&done, NULL);
143 return;
144 }
145
146 if (NULL != peer)
147 {
148 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
149 "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s (peer),
150 (NULL != hello) ? "with" : "without");
151
152 if (NULL == hello)
153 return;
154
155 if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello))
138 { 156 {
139 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 157 GNUNET_break (0);
140 _("Error in communication with PEERINFO service\n"));
141 GNUNET_SCHEDULER_add_now(&done, NULL);
142 return; 158 return;
143 } 159 }
144 160
145 if (NULL != peer) 161 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n",
162 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ?
163 "friend only" : "public",
164 GNUNET_i2s (peer));
165 if (0 == GNUNET_memcmp (&pid, peer))
146 { 166 {
147 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 167 res_cb_w_fo = GNUNET_YES;
148 "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s(peer), 168 GNUNET_SCHEDULER_add_now (&done, NULL);
149 (NULL != hello) ? "with" : "without");
150
151 if (NULL == hello)
152 return;
153
154 if (GNUNET_NO == GNUNET_HELLO_is_friend_only(hello))
155 {
156 GNUNET_break(0);
157 return;
158 }
159
160 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",
162 GNUNET_i2s(peer));
163 if (0 == GNUNET_memcmp(&pid, peer))
164 {
165 res_cb_w_fo = GNUNET_YES;
166 GNUNET_SCHEDULER_add_now(&done, NULL);
167 }
168 return;
169 } 169 }
170 return;
171 }
170} 172}
171 173
172static void 174static void
173process_wo_fo(void *cls, const struct GNUNET_PeerIdentity *peer, 175process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer,
174 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 176 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
175{ 177{
176 if (err_msg != NULL) 178 if (err_msg != NULL)
179 {
180 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
181 _ ("Error in communication with PEERINFO service\n"));
182 GNUNET_SCHEDULER_add_now (&done, NULL);
183 return;
184 }
185
186 if (NULL != peer)
187 {
188 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
189 "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s (peer),
190 (NULL != hello) ? "with" : "without");
191
192 if (NULL == hello)
193 return;
194
195 if (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello))
177 { 196 {
178 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, 197 GNUNET_break (0);
179 _("Error in communication with PEERINFO service\n"));
180 GNUNET_SCHEDULER_add_now(&done, NULL);
181 return; 198 return;
182 } 199 }
183 200
184 if (NULL != peer) 201 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n",
202 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ?
203 "friend only" : "public",
204 GNUNET_i2s (peer));
205 if (0 == GNUNET_memcmp (&pid, peer))
185 { 206 {
186 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 207 GNUNET_break (0);
187 "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s(peer), 208 res_cb_wo_fo = GNUNET_YES;
188 (NULL != hello) ? "with" : "without");
189
190 if (NULL == hello)
191 return;
192
193 if (GNUNET_YES == GNUNET_HELLO_is_friend_only(hello))
194 {
195 GNUNET_break(0);
196 return;
197 }
198
199 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",
201 GNUNET_i2s(peer));
202 if (0 == GNUNET_memcmp(&pid, peer))
203 {
204 GNUNET_break(0);
205 res_cb_wo_fo = GNUNET_YES;
206 }
207 } 209 }
210 }
208} 211}
209 212
210 213
211static void 214static void
212add_peer() 215add_peer ()
213{ 216{
214 struct GNUNET_HELLO_Message *h2; 217 struct GNUNET_HELLO_Message *h2;
215 size_t agc; 218 size_t agc;
216 219
217 agc = 2; 220 agc = 2;
218 memset(&pid, 32, sizeof(pid)); 221 memset (&pid, 32, sizeof(pid));
219 h2 = GNUNET_HELLO_create(&pid.public_key, &address_generator, &agc, 222 h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc,
220 GNUNET_YES); 223 GNUNET_YES);
221 GNUNET_PEERINFO_add_peer(h, h2, NULL, NULL); 224 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL);
222 GNUNET_free(h2); 225 GNUNET_free (h2);
223} 226}
224 227
225 228
226static void 229static void
227run(void *cls, 230run (void *cls,
228 const struct GNUNET_CONFIGURATION_Handle *cfg, 231 const struct GNUNET_CONFIGURATION_Handle *cfg,
229 struct GNUNET_TESTING_Peer *peer) 232 struct GNUNET_TESTING_Peer *peer)
230{ 233{
231 timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); 234 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
232 mycfg = cfg; 235 mycfg = cfg;
233 pnc_w_fo = GNUNET_PEERINFO_notify(mycfg, GNUNET_YES, &process_w_fo, NULL); 236 pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL);
234 pnc_wo_fo = GNUNET_PEERINFO_notify(mycfg, GNUNET_NO, &process_wo_fo, NULL); 237 pnc_wo_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_NO, &process_wo_fo, NULL);
235 h = GNUNET_PEERINFO_connect(cfg); 238 h = GNUNET_PEERINFO_connect (cfg);
236 GNUNET_assert(NULL != h); 239 GNUNET_assert (NULL != h);
237 add_peer(); 240 add_peer ();
238} 241}
239 242
240 243
241int 244int
242main(int argc, char *argv[]) 245main (int argc, char *argv[])
243{ 246{
244 res_cb_w_fo = GNUNET_NO; 247 res_cb_w_fo = GNUNET_NO;
245 res_cb_wo_fo = GNUNET_NO; 248 res_cb_wo_fo = GNUNET_NO;
246 global_ret = 3; 249 global_ret = 3;
247 if (0 != GNUNET_TESTING_service_run("test-peerinfo-api-friend-only", 250 if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only",
248 "peerinfo", 251 "peerinfo",
249 "test_peerinfo_api_data.conf", 252 "test_peerinfo_api_data.conf",
250 &run, NULL)) 253 &run, NULL))
251 return 1; 254 return 1;
252 return global_ret; 255 return global_ret;
253} 256}