summaryrefslogtreecommitdiff
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.c226
1 files changed, 113 insertions, 113 deletions
diff --git a/src/peerinfo/test_peerinfo_api_notify_friend_only.c b/src/peerinfo/test_peerinfo_api_notify_friend_only.c
index 0a9bfc083..80b5883de 100644
--- a/src/peerinfo/test_peerinfo_api_notify_friend_only.c
+++ b/src/peerinfo/test_peerinfo_api_notify_friend_only.c
@@ -1,19 +1,19 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2004, 2009 GNUnet e.V. 3 Copyright (C) 2004, 2009 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License, 7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version. 8 or (at your 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 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19 */ 19 */
@@ -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,46 +61,46 @@ 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;
@@ -109,7 +109,7 @@ done (void *cls)
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,137 @@ 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(GNUNET_TIME_UNIT_HOURS), buf, max);
126 (*agc)--; 126 (*agc)--;
127 return ret; 127 return ret;
128} 128}
129 129
130 130
131static void 131static void
132process_w_fo (void *cls, 132process_w_fo(void *cls,
133 const struct GNUNET_PeerIdentity *peer, 133 const struct GNUNET_PeerIdentity *peer,
134 const struct GNUNET_HELLO_Message *hello, 134 const struct GNUNET_HELLO_Message *hello,
135 const char *err_msg) 135 const char *err_msg)
136{ 136{
137 if (err_msg != NULL) 137 if (err_msg != NULL)
138 {
139 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
140 _("Error in communication with PEERINFO service\n"));
141 GNUNET_SCHEDULER_add_now (&done, NULL);
142 return;
143 }
144
145 if (NULL != peer)
146 {
147 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
148 "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s (peer),
149 (NULL != hello) ? "with" : "without");
150
151 if (NULL == hello)
152 return;
153
154 if (GNUNET_NO == GNUNET_HELLO_is_friend_only (hello))
155 { 138 {
156 GNUNET_break(0); 139 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
140 _("Error in communication with PEERINFO service\n"));
141 GNUNET_SCHEDULER_add_now(&done, NULL);
157 return; 142 return;
158 } 143 }
159 144
160 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n", 145 if (NULL != peer)
161 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public",
162 GNUNET_i2s (peer));
163 if (0 == GNUNET_memcmp (&pid, peer))
164 { 146 {
165 res_cb_w_fo = GNUNET_YES; 147 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
166 GNUNET_SCHEDULER_add_now (&done, NULL); 148 "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s(peer),
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;
167 } 169 }
168 return;
169 }
170} 170}
171 171
172static void 172static void
173process_wo_fo (void *cls, const struct GNUNET_PeerIdentity *peer, 173process_wo_fo(void *cls, const struct GNUNET_PeerIdentity *peer,
174 const struct GNUNET_HELLO_Message *hello, const char *err_msg) 174 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
175{ 175{
176 if (err_msg != NULL) 176 if (err_msg != NULL)
177 {
178 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
179 _("Error in communication with PEERINFO service\n"));
180 GNUNET_SCHEDULER_add_now (&done, NULL);
181 return;
182 }
183
184 if (NULL != peer)
185 {
186 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
187 "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s (peer),
188 (NULL != hello) ? "with" : "without");
189
190 if (NULL == hello)
191 return;
192
193 if (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello))
194 { 177 {
195 GNUNET_break(0); 178 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
179 _("Error in communication with PEERINFO service\n"));
180 GNUNET_SCHEDULER_add_now(&done, NULL);
196 return; 181 return;
197 } 182 }
198 183
199 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Received %s HELLO for peer `%s'\n", 184 if (NULL != peer)
200 (GNUNET_YES == GNUNET_HELLO_is_friend_only (hello)) ? "friend only" : "public",
201 GNUNET_i2s (peer));
202 if (0 == GNUNET_memcmp (&pid, peer))
203 { 185 {
204 GNUNET_break(0); 186 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
205 res_cb_wo_fo = GNUNET_YES; 187 "Received callback for peer `%s' %s HELLO\n", GNUNET_i2s(peer),
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 }
206 } 207 }
207 }
208} 208}
209 209
210 210
211static void 211static void
212add_peer () 212add_peer()
213{ 213{
214 struct GNUNET_HELLO_Message *h2; 214 struct GNUNET_HELLO_Message *h2;
215 size_t agc; 215 size_t agc;
216 216
217 agc = 2; 217 agc = 2;
218 memset (&pid, 32, sizeof(pid)); 218 memset(&pid, 32, sizeof(pid));
219 h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &agc, 219 h2 = GNUNET_HELLO_create(&pid.public_key, &address_generator, &agc,
220 GNUNET_YES); 220 GNUNET_YES);
221 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); 221 GNUNET_PEERINFO_add_peer(h, h2, NULL, NULL);
222 GNUNET_free(h2); 222 GNUNET_free(h2);
223} 223}
224 224
225 225
226static void 226static void
227run (void *cls, 227run(void *cls,
228 const struct GNUNET_CONFIGURATION_Handle *cfg, 228 const struct GNUNET_CONFIGURATION_Handle *cfg,
229 struct GNUNET_TESTING_Peer *peer) 229 struct GNUNET_TESTING_Peer *peer)
230{ 230{
231 timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 231 timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL);
232 mycfg = cfg; 232 mycfg = cfg;
233 pnc_w_fo = GNUNET_PEERINFO_notify (mycfg, GNUNET_YES, &process_w_fo, NULL); 233 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); 234 pnc_wo_fo = GNUNET_PEERINFO_notify(mycfg, GNUNET_NO, &process_wo_fo, NULL);
235 h = GNUNET_PEERINFO_connect (cfg); 235 h = GNUNET_PEERINFO_connect(cfg);
236 GNUNET_assert(NULL != h); 236 GNUNET_assert(NULL != h);
237 add_peer (); 237 add_peer();
238} 238}
239 239
240 240
241int 241int
242main (int argc, char *argv[]) 242main(int argc, char *argv[])
243{ 243{
244 res_cb_w_fo = GNUNET_NO; 244 res_cb_w_fo = GNUNET_NO;
245 res_cb_wo_fo = GNUNET_NO; 245 res_cb_wo_fo = GNUNET_NO;
246 global_ret = 3; 246 global_ret = 3;
247 if (0 != GNUNET_TESTING_service_run ("test-peerinfo-api-friend-only", 247 if (0 != GNUNET_TESTING_service_run("test-peerinfo-api-friend-only",
248 "peerinfo", 248 "peerinfo",
249 "test_peerinfo_api_data.conf", 249 "test_peerinfo_api_data.conf",
250 &run, NULL)) 250 &run, NULL))
251 return 1; 251 return 1;
252 return global_ret; 252 return global_ret;
253} 253}