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.c69
1 files changed, 24 insertions, 45 deletions
diff --git a/src/testbed/gnunet-daemon-testbed-blacklist.c b/src/testbed/gnunet-daemon-testbed-blacklist.c
index 0e0c7ebd5..0cb83aacf 100644
--- a/src/testbed/gnunet-daemon-testbed-blacklist.c
+++ b/src/testbed/gnunet-daemon-testbed-blacklist.c
@@ -67,12 +67,7 @@ static struct GNUNET_PeerIdentity *ilist;
67 * The blacklist handle we obtain from transport when we register ourselves for 67 * The blacklist handle we obtain from transport when we register ourselves for
68 * access control 68 * access control
69 */ 69 */
70struct GNUNET_TRANSPORT_Blacklist *bh; 70static struct GNUNET_TRANSPORT_Blacklist *bh;
71
72/**
73 * Task for shutdown
74 */
75static struct GNUNET_SCHEDULER_Task * shutdown_task;
76 71
77/** 72/**
78 * Are we allowing or denying access from peers 73 * Are we allowing or denying access from peers
@@ -81,26 +76,6 @@ static int mode;
81 76
82 77
83/** 78/**
84 * @ingroup hashmap
85 * Iterator over hash map entries.
86 *
87 * @param cls closure
88 * @param key current key code
89 * @param value value in the hash map
90 * @return #GNUNET_YES if we should continue to
91 * iterate,
92 * #GNUNET_NO if not.
93 */
94static int
95iterator (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
96{
97 GNUNET_assert (GNUNET_YES == GNUNET_CONTAINER_multipeermap_remove (map, key,
98 value));
99 return GNUNET_YES;
100}
101
102
103/**
104 * Cleaup and destroy the map 79 * Cleaup and destroy the map
105 */ 80 */
106static void 81static void
@@ -108,9 +83,6 @@ cleanup_map ()
108{ 83{
109 if (NULL != map) 84 if (NULL != map)
110 { 85 {
111 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONTAINER_multipeermap_iterate (map,
112 &iterator,
113 NULL));
114 GNUNET_CONTAINER_multipeermap_destroy (map); 86 GNUNET_CONTAINER_multipeermap_destroy (map);
115 map = NULL; 87 map = NULL;
116 } 88 }
@@ -161,14 +133,16 @@ check_access (void *cls, const struct GNUNET_PeerIdentity * pid)
161 * @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
162 */ 134 */
163static void 135static void
164setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg) 136setup_ac (const char *fname,
137 const struct GNUNET_CONFIGURATION_Handle *cfg)
165{ 138{
166 uint64_t fsize; 139 uint64_t fsize;
167 unsigned int npeers; 140 unsigned int npeers;
168 unsigned int cnt; 141 unsigned int cnt;
169 142
170 GNUNET_assert (GNUNET_OK != GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO, 143 GNUNET_assert (GNUNET_OK !=
171 GNUNET_YES)); 144 GNUNET_DISK_file_size (fname, &fsize, GNUNET_NO,
145 GNUNET_YES));
172 if (0 != (fsize % sizeof (struct GNUNET_PeerIdentity))) 146 if (0 != (fsize % sizeof (struct GNUNET_PeerIdentity)))
173 { 147 {
174 GNUNET_break (0); 148 GNUNET_break (0);
@@ -183,17 +157,17 @@ setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg)
183 } 157 }
184 for (cnt = 0; cnt < npeers; cnt++) 158 for (cnt = 0; cnt < npeers; cnt++)
185 { 159 {
186 if (GNUNET_SYSERR == GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt], 160 if (GNUNET_SYSERR ==
187 &ilist[cnt], 161 GNUNET_CONTAINER_multipeermap_put (map, &ilist[cnt],
188 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)) 162 &ilist[cnt],
163 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
189 { 164 {
190 cleanup_map (); 165 cleanup_map ();
191 GNUNET_free (ilist); 166 GNUNET_free (ilist);
192 return; 167 return;
193 } 168 }
194 } 169 }
195 shutdown_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 170 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
196 &do_shutdown, NULL);
197 bh = GNUNET_TRANSPORT_blacklist (cfg, &check_access, NULL); 171 bh = GNUNET_TRANSPORT_blacklist (cfg, &check_access, NULL);
198} 172}
199 173
@@ -207,15 +181,18 @@ setup_ac (const char *fname, const struct GNUNET_CONFIGURATION_Handle *cfg)
207 * @param c configuration 181 * @param c configuration
208 */ 182 */
209static void 183static void
210run (void *cls, char *const *args, const char *cfgfile, 184run (void *cls,
185 char *const *args,
186 const char *cfgfile,
211 const struct GNUNET_CONFIGURATION_Handle *c) 187 const struct GNUNET_CONFIGURATION_Handle *c)
212{ 188{
213 char *shome; 189 char *shome;
214 char *fname; 190 char *fname;
215 191
216 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (c, "PATHS", 192 if (GNUNET_OK !=
217 "GNUNET_HOME", 193 GNUNET_CONFIGURATION_get_value_filename (c, "PATHS",
218 &shome)) 194 "GNUNET_HOME",
195 &shome))
219 { 196 {
220 GNUNET_break (0); 197 GNUNET_break (0);
221 return; 198 return;
@@ -260,13 +237,15 @@ main (int argc, char *const *argv)
260 }; 237 };
261 int ret; 238 int ret;
262 239
263 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 240 if (GNUNET_OK !=
241 GNUNET_STRINGS_get_utf8_args (argc, argv,
242 &argc, &argv))
264 return 2; 243 return 2;
265 ret = 244 ret =
266 (GNUNET_OK == 245 (GNUNET_OK ==
267 GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-testbed-blacklist", 246 GNUNET_PROGRAM_run (argc, argv,
268 _ 247 "gnunet-daemon-testbed-blacklist",
269 ("Daemon to restrict incoming transport layer connections during testbed deployments"), 248 _("Daemon to restrict incoming transport layer connections during testbed deployments"),
270 options, &run, NULL)) ? 0 : 1; 249 options, &run, NULL)) ? 0 : 1;
271 GNUNET_free ((void*) argv); 250 GNUNET_free ((void*) argv);
272 return ret; 251 return ret;