aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/gnunet-daemon-testbed-blacklist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/gnunet-daemon-testbed-blacklist.c')
-rw-r--r--src/testbed/gnunet-daemon-testbed-blacklist.c170
1 files changed, 85 insertions, 85 deletions
diff --git a/src/testbed/gnunet-daemon-testbed-blacklist.c b/src/testbed/gnunet-daemon-testbed-blacklist.c
index a91c6a161..e894fb79d 100644
--- a/src/testbed/gnunet-daemon-testbed-blacklist.c
+++ b/src/testbed/gnunet-daemon-testbed-blacklist.c
@@ -11,12 +11,12 @@
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 */
20 20
21 21
22/** 22/**
@@ -34,14 +34,14 @@
34/** 34/**
35 * Logging shorthand 35 * Logging shorthand
36 */ 36 */
37#define LOG(type,...) \ 37#define LOG(type, ...) \
38 GNUNET_log (type, __VA_ARGS__) 38 GNUNET_log(type, __VA_ARGS__)
39 39
40/** 40/**
41 * Debug logging shorthand 41 * Debug logging shorthand
42 */ 42 */
43#define DEBUG(...) \ 43#define DEBUG(...) \
44 LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) 44 LOG(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
45 45
46/** 46/**
47 * Allow access from the peers read from the whitelist 47 * Allow access from the peers read from the whitelist
@@ -79,13 +79,13 @@ static int mode;
79 * Cleaup and destroy the map 79 * Cleaup and destroy the map
80 */ 80 */
81static void 81static void
82cleanup_map () 82cleanup_map()
83{ 83{
84 if (NULL != map) 84 if (NULL != map)
85 { 85 {
86 GNUNET_CONTAINER_multipeermap_destroy (map); 86 GNUNET_CONTAINER_multipeermap_destroy(map);
87 map = NULL; 87 map = NULL;
88 } 88 }
89} 89}
90 90
91 91
@@ -95,11 +95,11 @@ cleanup_map ()
95 * @param cls NULL 95 * @param cls NULL
96 */ 96 */
97static void 97static void
98do_shutdown (void *cls) 98do_shutdown(void *cls)
99{ 99{
100 cleanup_map (); 100 cleanup_map();
101 if (NULL != bh) 101 if (NULL != bh)
102 GNUNET_TRANSPORT_blacklist_cancel (bh); 102 GNUNET_TRANSPORT_blacklist_cancel(bh);
103} 103}
104 104
105 105
@@ -111,12 +111,12 @@ do_shutdown (void *cls)
111 * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not 111 * @return GNUNET_OK if the connection is allowed, GNUNET_SYSERR if not
112 */ 112 */
113static int 113static int
114check_access (void *cls, const struct GNUNET_PeerIdentity * pid) 114check_access(void *cls, const struct GNUNET_PeerIdentity * pid)
115{ 115{
116 int contains; 116 int contains;
117 117
118 if (NULL != map) 118 if (NULL != map)
119 contains = GNUNET_CONTAINER_multipeermap_contains (map, pid); 119 contains = GNUNET_CONTAINER_multipeermap_contains(map, pid);
120 else 120 else
121 contains = GNUNET_NO; 121 contains = GNUNET_NO;
122 if (ACCESS_DENY == mode) 122 if (ACCESS_DENY == mode)
@@ -133,42 +133,42 @@ check_access (void *cls, const struct GNUNET_PeerIdentity * pid)
133 * @param cfg the configuration for connecting to the peer's transport service 133 * @param cfg the configuration for connecting to the peer's transport service
134 */ 134 */
135static void 135static void
136setup_ac (const char *fname, 136setup_ac(const char *fname,
137 const struct GNUNET_CONFIGURATION_Handle *cfg) 137 const struct GNUNET_CONFIGURATION_Handle *cfg)
138{ 138{
139 uint64_t fsize; 139 uint64_t fsize;
140 unsigned int npeers; 140 unsigned int npeers;
141 unsigned int cnt; 141 unsigned int cnt;
142 142
143 GNUNET_assert (GNUNET_OK != 143 GNUNET_assert(GNUNET_OK !=
144 GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO, 144 GNUNET_DISK_file_size(fname, &fsize, GNUNET_NO,
145 GNUNET_YES)); 145 GNUNET_YES));
146 if (0 != (fsize % sizeof (struct GNUNET_PeerIdentity))) 146 if (0 != (fsize % sizeof(struct GNUNET_PeerIdentity)))
147 { 147 {
148 GNUNET_break (0); 148 GNUNET_break(0);
149 return; 149 return;
150 } 150 }
151 npeers = fsize / sizeof (struct GNUNET_PeerIdentity); 151 npeers = fsize / sizeof(struct GNUNET_PeerIdentity);
152 if (0 != npeers) 152 if (0 != npeers)
153 { 153 {
154 map = GNUNET_CONTAINER_multipeermap_create (npeers, GNUNET_YES); 154 map = GNUNET_CONTAINER_multipeermap_create(npeers, GNUNET_YES);
155 ilist = GNUNET_malloc_large (fsize); 155 ilist = GNUNET_malloc_large(fsize);
156 GNUNET_assert (fsize == GNUNET_DISK_fn_read (fname, ilist, fsize)); 156 GNUNET_assert(fsize == GNUNET_DISK_fn_read(fname, ilist, fsize));
157 } 157 }
158 for (cnt = 0; cnt < npeers; cnt++) 158 for (cnt = 0; cnt < npeers; cnt++)
159 {
160 if (GNUNET_SYSERR ==
161 GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt],
162 &ilist[cnt],
163 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
164 { 159 {
165 cleanup_map (); 160 if (GNUNET_SYSERR ==
166 GNUNET_free (ilist); 161 GNUNET_CONTAINER_multipeermap_put(map, &ilist[cnt],
167 return; 162 &ilist[cnt],
163 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
164 {
165 cleanup_map();
166 GNUNET_free(ilist);
167 return;
168 }
168 } 169 }
169 } 170 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
170 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 171 bh = GNUNET_TRANSPORT_blacklist(cfg, &check_access, NULL);
171 bh = GNUNET_TRANSPORT_blacklist (cfg, &check_access, NULL);
172} 172}
173 173
174 174
@@ -181,45 +181,45 @@ setup_ac (const char *fname,
181 * @param c configuration 181 * @param c configuration
182 */ 182 */
183static void 183static void
184run (void *cls, 184run(void *cls,
185 char *const *args, 185 char *const *args,
186 const char *cfgfile, 186 const char *cfgfile,
187 const struct GNUNET_CONFIGURATION_Handle *c) 187 const struct GNUNET_CONFIGURATION_Handle *c)
188{ 188{
189 char *shome; 189 char *shome;
190 char *fname; 190 char *fname;
191 191
192 if (GNUNET_OK != 192 if (GNUNET_OK !=
193 GNUNET_CONFIGURATION_get_value_filename (c, 193 GNUNET_CONFIGURATION_get_value_filename(c,
194 "PATHS", 194 "PATHS",
195 "GNUNET_HOME", 195 "GNUNET_HOME",
196 &shome)) 196 &shome))
197 { 197 {
198 GNUNET_break (0); 198 GNUNET_break(0);
199 return; 199 return;
200 } 200 }
201 GNUNET_asprintf (&fname, 201 GNUNET_asprintf(&fname,
202 "%s/whitelist", 202 "%s/whitelist",
203 shome); 203 shome);
204 if (GNUNET_YES == GNUNET_DISK_file_test (fname)) 204 if (GNUNET_YES == GNUNET_DISK_file_test(fname))
205 { 205 {
206 mode = ACCESS_ALLOW; 206 mode = ACCESS_ALLOW;
207 setup_ac (fname, c); 207 setup_ac(fname, c);
208 GNUNET_free (shome); 208 GNUNET_free(shome);
209 GNUNET_free (fname); 209 GNUNET_free(fname);
210 return; 210 return;
211 } 211 }
212 GNUNET_free (fname); 212 GNUNET_free(fname);
213 GNUNET_asprintf (&fname, 213 GNUNET_asprintf(&fname,
214 "%s/blacklist", 214 "%s/blacklist",
215 shome); 215 shome);
216 if (GNUNET_YES == GNUNET_DISK_file_test (fname)) 216 if (GNUNET_YES == GNUNET_DISK_file_test(fname))
217 { 217 {
218 mode = ACCESS_DENY; 218 mode = ACCESS_DENY;
219 setup_ac (shome, c); 219 setup_ac(shome, c);
220 } 220 }
221 GNUNET_free (shome); 221 GNUNET_free(shome);
222 GNUNET_free (fname); 222 GNUNET_free(fname);
223} 223}
224 224
225 225
@@ -231,7 +231,7 @@ run (void *cls,
231 * @return 0 ok, 1 on error 231 * @return 0 ok, 1 on error
232 */ 232 */
233int 233int
234main (int argc, char *const *argv) 234main(int argc, char *const *argv)
235{ 235{
236 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 236 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
237 GNUNET_GETOPT_OPTION_END 237 GNUNET_GETOPT_OPTION_END
@@ -239,15 +239,15 @@ main (int argc, char *const *argv)
239 int ret; 239 int ret;
240 240
241 if (GNUNET_OK != 241 if (GNUNET_OK !=
242 GNUNET_STRINGS_get_utf8_args (argc, argv, 242 GNUNET_STRINGS_get_utf8_args(argc, argv,
243 &argc, &argv)) 243 &argc, &argv))
244 return 2; 244 return 2;
245 ret = 245 ret =
246 (GNUNET_OK == 246 (GNUNET_OK ==
247 GNUNET_PROGRAM_run (argc, argv, 247 GNUNET_PROGRAM_run(argc, argv,
248 "gnunet-daemon-testbed-blacklist", 248 "gnunet-daemon-testbed-blacklist",
249 _("Daemon to restrict incoming transport layer connections during testbed deployments"), 249 _("Daemon to restrict incoming transport layer connections during testbed deployments"),
250 options, &run, NULL)) ? 0 : 1; 250 options, &run, NULL)) ? 0 : 1;
251 GNUNET_free ((void*) argv); 251 GNUNET_free((void*)argv);
252 return ret; 252 return ret;
253} 253}