diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/topology | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/topology')
-rw-r--r-- | src/topology/friends.c | 252 | ||||
-rw-r--r-- | src/topology/gnunet-daemon-topology.c | 844 | ||||
-rw-r--r-- | src/topology/test_gnunet_daemon_topology.c | 237 |
3 files changed, 669 insertions, 664 deletions
diff --git a/src/topology/friends.c b/src/topology/friends.c index 81c7d45e9..a3b15d8f7 100644 --- a/src/topology/friends.c +++ b/src/topology/friends.c | |||
@@ -36,9 +36,9 @@ | |||
36 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on parsing errors | 36 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on parsing errors |
37 | */ | 37 | */ |
38 | int | 38 | int |
39 | GNUNET_FRIENDS_parse(const struct GNUNET_CONFIGURATION_Handle *cfg, | 39 | GNUNET_FRIENDS_parse (const struct GNUNET_CONFIGURATION_Handle *cfg, |
40 | GNUNET_FRIENDS_Callback cb, | 40 | GNUNET_FRIENDS_Callback cb, |
41 | void *cb_cls) | 41 | void *cb_cls) |
42 | { | 42 | { |
43 | char *fn; | 43 | char *fn; |
44 | char *data; | 44 | char *data; |
@@ -49,94 +49,95 @@ GNUNET_FRIENDS_parse(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
49 | ssize_t ssize; | 49 | ssize_t ssize; |
50 | 50 | ||
51 | if (GNUNET_OK != | 51 | if (GNUNET_OK != |
52 | GNUNET_CONFIGURATION_get_value_filename(cfg, | 52 | GNUNET_CONFIGURATION_get_value_filename (cfg, |
53 | "TOPOLOGY", | 53 | "TOPOLOGY", |
54 | "FRIENDS", | 54 | "FRIENDS", |
55 | &fn)) | 55 | &fn)) |
56 | { | 56 | { |
57 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 57 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
58 | "topology", | 58 | "topology", |
59 | "FRIENDS"); | 59 | "FRIENDS"); |
60 | return GNUNET_SYSERR; | 60 | return GNUNET_SYSERR; |
61 | } | 61 | } |
62 | if (GNUNET_SYSERR == | 62 | if (GNUNET_SYSERR == |
63 | GNUNET_DISK_directory_create_for_file(fn)) | 63 | GNUNET_DISK_directory_create_for_file (fn)) |
64 | { | 64 | { |
65 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, | 65 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
66 | "mkdir", | 66 | "mkdir", |
67 | fn); | 67 | fn); |
68 | GNUNET_free(fn); | 68 | GNUNET_free (fn); |
69 | return GNUNET_SYSERR; | 69 | return GNUNET_SYSERR; |
70 | } | 70 | } |
71 | if ((GNUNET_OK != | 71 | if ((GNUNET_OK != |
72 | GNUNET_DISK_file_test(fn)) && | 72 | GNUNET_DISK_file_test (fn)) && |
73 | (GNUNET_OK != | 73 | (GNUNET_OK != |
74 | GNUNET_DISK_fn_write(fn, | 74 | GNUNET_DISK_fn_write (fn, |
75 | NULL, | 75 | NULL, |
76 | 0, | 76 | 0, |
77 | GNUNET_DISK_PERM_USER_READ | | 77 | GNUNET_DISK_PERM_USER_READ |
78 | GNUNET_DISK_PERM_USER_WRITE | | 78 | | GNUNET_DISK_PERM_USER_WRITE |
79 | GNUNET_DISK_OPEN_CREATE))) | 79 | | GNUNET_DISK_OPEN_CREATE))) |
80 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, | 80 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
81 | "write", | 81 | "write", |
82 | fn); | 82 | fn); |
83 | if ((GNUNET_OK != | 83 | if ((GNUNET_OK != |
84 | GNUNET_DISK_file_size(fn, | 84 | GNUNET_DISK_file_size (fn, |
85 | &fsize, | 85 | &fsize, |
86 | GNUNET_NO, | 86 | GNUNET_NO, |
87 | GNUNET_YES)) || | 87 | GNUNET_YES)) || |
88 | (0 == fsize)) | 88 | (0 == fsize)) |
89 | { | 89 | { |
90 | GNUNET_free(fn); | 90 | GNUNET_free (fn); |
91 | return GNUNET_OK; | 91 | return GNUNET_OK; |
92 | } | 92 | } |
93 | data = GNUNET_malloc_large(fsize); | 93 | data = GNUNET_malloc_large (fsize); |
94 | if (NULL == data) | 94 | if (NULL == data) |
95 | { | 95 | { |
96 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "malloc"); | 96 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc"); |
97 | GNUNET_free(fn); | 97 | GNUNET_free (fn); |
98 | return GNUNET_SYSERR; | 98 | return GNUNET_SYSERR; |
99 | } | 99 | } |
100 | ssize = GNUNET_DISK_fn_read(fn, | 100 | ssize = GNUNET_DISK_fn_read (fn, |
101 | data, | 101 | data, |
102 | fsize); | 102 | fsize); |
103 | if ((ssize < 0) || | 103 | if ((ssize < 0) || |
104 | (fsize != (uint64_t)ssize)) | 104 | (fsize != (uint64_t) ssize)) |
105 | { | 105 | { |
106 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, | 106 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
107 | "read", | 107 | "read", |
108 | "fn"); | 108 | "fn"); |
109 | GNUNET_free(fn); | 109 | GNUNET_free (fn); |
110 | GNUNET_free(data); | 110 | GNUNET_free (data); |
111 | return GNUNET_SYSERR; | 111 | return GNUNET_SYSERR; |
112 | } | 112 | } |
113 | start = 0; | 113 | start = 0; |
114 | pos = 0; | 114 | pos = 0; |
115 | while (pos < fsize) | 115 | while (pos < fsize) |
116 | { | ||
117 | while ((pos < fsize) && | ||
118 | (! isspace ((unsigned char) data[pos]))) | ||
119 | pos++; | ||
120 | if (GNUNET_OK != | ||
121 | GNUNET_CRYPTO_eddsa_public_key_from_string (&data[start], | ||
122 | pos - start, | ||
123 | &pid.public_key)) | ||
116 | { | 124 | { |
117 | while ((pos < fsize) && | 125 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
118 | (!isspace((unsigned char)data[pos]))) | 126 | _ ( |
119 | pos++; | 127 | "Syntax error in FRIENDS file at offset %llu, skipping bytes `%.*s'.\n"), |
120 | if (GNUNET_OK != | 128 | (unsigned long long) pos, |
121 | GNUNET_CRYPTO_eddsa_public_key_from_string(&data[start], | 129 | (int) (pos - start), |
122 | pos - start, | 130 | &data[start]); |
123 | &pid.public_key)) | ||
124 | { | ||
125 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
126 | _("Syntax error in FRIENDS file at offset %llu, skipping bytes `%.*s'.\n"), | ||
127 | (unsigned long long)pos, | ||
128 | (int)(pos - start), | ||
129 | &data[start]); | ||
130 | pos++; | ||
131 | start = pos; | ||
132 | continue; | ||
133 | } | ||
134 | pos++; | 131 | pos++; |
135 | start = pos; | 132 | start = pos; |
136 | cb(cb_cls, &pid); | 133 | continue; |
137 | } | 134 | } |
138 | GNUNET_free(data); | 135 | pos++; |
139 | GNUNET_free(fn); | 136 | start = pos; |
137 | cb (cb_cls, &pid); | ||
138 | } | ||
139 | GNUNET_free (data); | ||
140 | GNUNET_free (fn); | ||
140 | return GNUNET_OK; | 141 | return GNUNET_OK; |
141 | } | 142 | } |
142 | 143 | ||
@@ -144,7 +145,8 @@ GNUNET_FRIENDS_parse(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
144 | /** | 145 | /** |
145 | * Handle for writing a friends file. | 146 | * Handle for writing a friends file. |
146 | */ | 147 | */ |
147 | struct GNUNET_FRIENDS_Writer { | 148 | struct GNUNET_FRIENDS_Writer |
149 | { | ||
148 | /** | 150 | /** |
149 | * Handle to the file. | 151 | * Handle to the file. |
150 | */ | 152 | */ |
@@ -160,41 +162,41 @@ struct GNUNET_FRIENDS_Writer { | |||
160 | * @return NULL on error | 162 | * @return NULL on error |
161 | */ | 163 | */ |
162 | struct GNUNET_FRIENDS_Writer * | 164 | struct GNUNET_FRIENDS_Writer * |
163 | GNUNET_FRIENDS_write_start(const struct GNUNET_CONFIGURATION_Handle *cfg) | 165 | GNUNET_FRIENDS_write_start (const struct GNUNET_CONFIGURATION_Handle *cfg) |
164 | { | 166 | { |
165 | struct GNUNET_FRIENDS_Writer *w; | 167 | struct GNUNET_FRIENDS_Writer *w; |
166 | char *fn; | 168 | char *fn; |
167 | 169 | ||
168 | if (GNUNET_OK != | 170 | if (GNUNET_OK != |
169 | GNUNET_CONFIGURATION_get_value_filename(cfg, "TOPOLOGY", "FRIENDS", &fn)) | 171 | GNUNET_CONFIGURATION_get_value_filename (cfg, "TOPOLOGY", "FRIENDS", &fn)) |
170 | { | 172 | { |
171 | GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR, | 173 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
172 | "topology", "FRIENDS"); | 174 | "topology", "FRIENDS"); |
173 | return NULL; | 175 | return NULL; |
174 | } | 176 | } |
175 | if (GNUNET_OK != | 177 | if (GNUNET_OK != |
176 | GNUNET_DISK_directory_create_for_file(fn)) | 178 | GNUNET_DISK_directory_create_for_file (fn)) |
177 | { | 179 | { |
178 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 180 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
179 | _("Directory for file `%s' does not seem to be writable.\n"), | 181 | _ ("Directory for file `%s' does not seem to be writable.\n"), |
180 | fn); | 182 | fn); |
181 | GNUNET_free(fn); | 183 | GNUNET_free (fn); |
182 | return NULL; | 184 | return NULL; |
183 | } | 185 | } |
184 | if (GNUNET_OK == GNUNET_DISK_file_test(fn)) | 186 | if (GNUNET_OK == GNUNET_DISK_file_test (fn)) |
185 | GNUNET_DISK_file_backup(fn); | 187 | GNUNET_DISK_file_backup (fn); |
186 | w = GNUNET_new(struct GNUNET_FRIENDS_Writer); | 188 | w = GNUNET_new (struct GNUNET_FRIENDS_Writer); |
187 | w->fh = GNUNET_DISK_file_open(fn, | 189 | w->fh = GNUNET_DISK_file_open (fn, |
188 | GNUNET_DISK_OPEN_CREATE | | 190 | GNUNET_DISK_OPEN_CREATE |
189 | GNUNET_DISK_OPEN_WRITE | | 191 | | GNUNET_DISK_OPEN_WRITE |
190 | GNUNET_DISK_OPEN_FAILIFEXISTS, | 192 | | GNUNET_DISK_OPEN_FAILIFEXISTS, |
191 | GNUNET_DISK_PERM_USER_READ); | 193 | GNUNET_DISK_PERM_USER_READ); |
192 | GNUNET_free(fn); | 194 | GNUNET_free (fn); |
193 | if (NULL == w->fh) | 195 | if (NULL == w->fh) |
194 | { | 196 | { |
195 | GNUNET_free(w); | 197 | GNUNET_free (w); |
196 | return NULL; | 198 | return NULL; |
197 | } | 199 | } |
198 | return w; | 200 | return w; |
199 | } | 201 | } |
200 | 202 | ||
@@ -206,12 +208,12 @@ GNUNET_FRIENDS_write_start(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
206 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 208 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
207 | */ | 209 | */ |
208 | int | 210 | int |
209 | GNUNET_FRIENDS_write_stop(struct GNUNET_FRIENDS_Writer *w) | 211 | GNUNET_FRIENDS_write_stop (struct GNUNET_FRIENDS_Writer *w) |
210 | { | 212 | { |
211 | int ret; | 213 | int ret; |
212 | 214 | ||
213 | ret = GNUNET_DISK_file_close(w->fh); | 215 | ret = GNUNET_DISK_file_close (w->fh); |
214 | GNUNET_free(w); | 216 | GNUNET_free (w); |
215 | return ret; | 217 | return ret; |
216 | } | 218 | } |
217 | 219 | ||
@@ -224,28 +226,28 @@ GNUNET_FRIENDS_write_stop(struct GNUNET_FRIENDS_Writer *w) | |||
224 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 226 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
225 | */ | 227 | */ |
226 | int | 228 | int |
227 | GNUNET_FRIENDS_write(struct GNUNET_FRIENDS_Writer *w, | 229 | GNUNET_FRIENDS_write (struct GNUNET_FRIENDS_Writer *w, |
228 | const struct GNUNET_PeerIdentity *friend_id) | 230 | const struct GNUNET_PeerIdentity *friend_id) |
229 | { | 231 | { |
230 | char *buf; | 232 | char *buf; |
231 | char *ret; | 233 | char *ret; |
232 | size_t slen; | 234 | size_t slen; |
233 | 235 | ||
234 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string(&friend_id->public_key); | 236 | ret = GNUNET_CRYPTO_eddsa_public_key_to_string (&friend_id->public_key); |
235 | GNUNET_asprintf(&buf, | 237 | GNUNET_asprintf (&buf, |
236 | "%s\n", | 238 | "%s\n", |
237 | ret); | 239 | ret); |
238 | GNUNET_free(ret); | 240 | GNUNET_free (ret); |
239 | slen = strlen(buf); | 241 | slen = strlen (buf); |
240 | if (slen != | 242 | if (slen != |
241 | GNUNET_DISK_file_write(w->fh, | 243 | GNUNET_DISK_file_write (w->fh, |
242 | buf, | 244 | buf, |
243 | slen)) | 245 | slen)) |
244 | { | 246 | { |
245 | GNUNET_free(buf); | 247 | GNUNET_free (buf); |
246 | return GNUNET_SYSERR; | 248 | return GNUNET_SYSERR; |
247 | } | 249 | } |
248 | GNUNET_free(buf); | 250 | GNUNET_free (buf); |
249 | return GNUNET_OK; | 251 | return GNUNET_OK; |
250 | } | 252 | } |
251 | 253 | ||
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index a550286e7..9e662ca0b 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c | |||
@@ -52,19 +52,20 @@ | |||
52 | * At what frequency do we sent HELLOs to a peer? | 52 | * At what frequency do we sent HELLOs to a peer? |
53 | */ | 53 | */ |
54 | #define HELLO_ADVERTISEMENT_MIN_FREQUENCY \ | 54 | #define HELLO_ADVERTISEMENT_MIN_FREQUENCY \ |
55 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5) | 55 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5) |
56 | 56 | ||
57 | /** | 57 | /** |
58 | * After what time period do we expire the HELLO Bloom filter? | 58 | * After what time period do we expire the HELLO Bloom filter? |
59 | */ | 59 | */ |
60 | #define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY \ | 60 | #define HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY \ |
61 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_HOURS, 4) | 61 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 4) |
62 | 62 | ||
63 | 63 | ||
64 | /** | 64 | /** |
65 | * Record for neighbours, friends and blacklisted peers. | 65 | * Record for neighbours, friends and blacklisted peers. |
66 | */ | 66 | */ |
67 | struct Peer { | 67 | struct Peer |
68 | { | ||
68 | /** | 69 | /** |
69 | * Which peer is this entry about? | 70 | * Which peer is this entry about? |
70 | */ | 71 | */ |
@@ -216,17 +217,17 @@ static unsigned int friend_count; | |||
216 | * @return #GNUNET_OK if the connection is allowed | 217 | * @return #GNUNET_OK if the connection is allowed |
217 | */ | 218 | */ |
218 | static int | 219 | static int |
219 | blacklist_check(void *cls, const struct GNUNET_PeerIdentity *pid) | 220 | blacklist_check (void *cls, const struct GNUNET_PeerIdentity *pid) |
220 | { | 221 | { |
221 | struct Peer *pos; | 222 | struct Peer *pos; |
222 | 223 | ||
223 | pos = GNUNET_CONTAINER_multipeermap_get(peers, pid); | 224 | pos = GNUNET_CONTAINER_multipeermap_get (peers, pid); |
224 | if ((NULL != pos) && (GNUNET_YES == pos->is_friend)) | 225 | if ((NULL != pos) && (GNUNET_YES == pos->is_friend)) |
225 | return GNUNET_OK; | 226 | return GNUNET_OK; |
226 | GNUNET_STATISTICS_update(stats, | 227 | GNUNET_STATISTICS_update (stats, |
227 | gettext_noop("# peers blacklisted"), | 228 | gettext_noop ("# peers blacklisted"), |
228 | 1, | 229 | 1, |
229 | GNUNET_NO); | 230 | GNUNET_NO); |
230 | return GNUNET_SYSERR; | 231 | return GNUNET_SYSERR; |
231 | } | 232 | } |
232 | 233 | ||
@@ -236,13 +237,13 @@ blacklist_check(void *cls, const struct GNUNET_PeerIdentity *pid) | |||
236 | * the minimum number of friends. | 237 | * the minimum number of friends. |
237 | */ | 238 | */ |
238 | static void | 239 | static void |
239 | whitelist_peers() | 240 | whitelist_peers () |
240 | { | 241 | { |
241 | if (NULL != blacklist) | 242 | if (NULL != blacklist) |
242 | { | 243 | { |
243 | GNUNET_TRANSPORT_blacklist_cancel(blacklist); | 244 | GNUNET_TRANSPORT_blacklist_cancel (blacklist); |
244 | blacklist = NULL; | 245 | blacklist = NULL; |
245 | } | 246 | } |
246 | } | 247 | } |
247 | 248 | ||
248 | 249 | ||
@@ -255,34 +256,34 @@ whitelist_peers() | |||
255 | * @return #GNUNET_YES (always: continue to iterate) | 256 | * @return #GNUNET_YES (always: continue to iterate) |
256 | */ | 257 | */ |
257 | static int | 258 | static int |
258 | free_peer(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | 259 | free_peer (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) |
259 | { | 260 | { |
260 | struct Peer *pos = value; | 261 | struct Peer *pos = value; |
261 | 262 | ||
262 | GNUNET_break(NULL == pos->mq); | 263 | GNUNET_break (NULL == pos->mq); |
263 | GNUNET_break(GNUNET_OK == | 264 | GNUNET_break (GNUNET_OK == |
264 | GNUNET_CONTAINER_multipeermap_remove(peers, pid, pos)); | 265 | GNUNET_CONTAINER_multipeermap_remove (peers, pid, pos)); |
265 | if (NULL != pos->hello_delay_task) | 266 | if (NULL != pos->hello_delay_task) |
266 | { | 267 | { |
267 | GNUNET_SCHEDULER_cancel(pos->hello_delay_task); | 268 | GNUNET_SCHEDULER_cancel (pos->hello_delay_task); |
268 | pos->hello_delay_task = NULL; | 269 | pos->hello_delay_task = NULL; |
269 | } | 270 | } |
270 | if (NULL != pos->sh) | 271 | if (NULL != pos->sh) |
271 | { | 272 | { |
272 | GNUNET_ATS_connectivity_suggest_cancel(pos->sh); | 273 | GNUNET_ATS_connectivity_suggest_cancel (pos->sh); |
273 | pos->sh = NULL; | 274 | pos->sh = NULL; |
274 | } | 275 | } |
275 | if (NULL != pos->hello) | 276 | if (NULL != pos->hello) |
276 | { | 277 | { |
277 | GNUNET_free_non_null(pos->hello); | 278 | GNUNET_free_non_null (pos->hello); |
278 | pos->hello = NULL; | 279 | pos->hello = NULL; |
279 | } | 280 | } |
280 | if (NULL != pos->filter) | 281 | if (NULL != pos->filter) |
281 | { | 282 | { |
282 | GNUNET_CONTAINER_bloomfilter_free(pos->filter); | 283 | GNUNET_CONTAINER_bloomfilter_free (pos->filter); |
283 | pos->filter = NULL; | 284 | pos->filter = NULL; |
284 | } | 285 | } |
285 | GNUNET_free(pos); | 286 | GNUNET_free (pos); |
286 | return GNUNET_YES; | 287 | return GNUNET_YES; |
287 | } | 288 | } |
288 | 289 | ||
@@ -294,23 +295,23 @@ free_peer(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | |||
294 | * @param pos peer to consider connecting to | 295 | * @param pos peer to consider connecting to |
295 | */ | 296 | */ |
296 | static void | 297 | static void |
297 | attempt_connect(struct Peer *pos) | 298 | attempt_connect (struct Peer *pos) |
298 | { | 299 | { |
299 | uint32_t strength; | 300 | uint32_t strength; |
300 | 301 | ||
301 | if (0 == GNUNET_memcmp(&my_identity, &pos->pid)) | 302 | if (0 == GNUNET_memcmp (&my_identity, &pos->pid)) |
302 | return; /* This is myself, nothing to do. */ | 303 | return; /* This is myself, nothing to do. */ |
303 | if (connection_count < target_connection_count) | 304 | if (connection_count < target_connection_count) |
304 | strength = 1; | 305 | strength = 1; |
305 | else | 306 | else |
306 | strength = 0; | 307 | strength = 0; |
307 | if ((friend_count < minimum_friend_count) || (GNUNET_YES == friends_only)) | 308 | if ((friend_count < minimum_friend_count) || (GNUNET_YES == friends_only)) |
308 | { | 309 | { |
309 | if (pos->is_friend) | 310 | if (pos->is_friend) |
310 | strength += 10; /* urgently needed */ | 311 | strength += 10; /* urgently needed */ |
311 | else | 312 | else |
312 | strength = 0; /* disallowed */ | 313 | strength = 0; /* disallowed */ |
313 | } | 314 | } |
314 | if (pos->is_friend) | 315 | if (pos->is_friend) |
315 | strength *= 2; /* friends always count more */ | 316 | strength *= 2; /* friends always count more */ |
316 | if (NULL != pos->mq) | 317 | if (NULL != pos->mq) |
@@ -318,23 +319,23 @@ attempt_connect(struct Peer *pos) | |||
318 | if (strength == pos->strength) | 319 | if (strength == pos->strength) |
319 | return; /* nothing to do */ | 320 | return; /* nothing to do */ |
320 | if (NULL != pos->sh) | 321 | if (NULL != pos->sh) |
321 | { | 322 | { |
322 | GNUNET_ATS_connectivity_suggest_cancel(pos->sh); | 323 | GNUNET_ATS_connectivity_suggest_cancel (pos->sh); |
323 | pos->sh = NULL; | 324 | pos->sh = NULL; |
324 | } | 325 | } |
325 | pos->strength = strength; | 326 | pos->strength = strength; |
326 | if (0 != strength) | 327 | if (0 != strength) |
327 | { | 328 | { |
328 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 329 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
329 | "Asking to connect to `%s' with strength %u\n", | 330 | "Asking to connect to `%s' with strength %u\n", |
330 | GNUNET_i2s(&pos->pid), | 331 | GNUNET_i2s (&pos->pid), |
331 | (unsigned int)strength); | 332 | (unsigned int) strength); |
332 | GNUNET_STATISTICS_update(stats, | 333 | GNUNET_STATISTICS_update (stats, |
333 | gettext_noop("# connect requests issued to ATS"), | 334 | gettext_noop ("# connect requests issued to ATS"), |
334 | 1, | 335 | 1, |
335 | GNUNET_NO); | 336 | GNUNET_NO); |
336 | pos->sh = GNUNET_ATS_connectivity_suggest(ats, &pos->pid, strength); | 337 | pos->sh = GNUNET_ATS_connectivity_suggest (ats, &pos->pid, strength); |
337 | } | 338 | } |
338 | } | 339 | } |
339 | 340 | ||
340 | 341 | ||
@@ -347,26 +348,26 @@ attempt_connect(struct Peer *pos) | |||
347 | * @return the new entry | 348 | * @return the new entry |
348 | */ | 349 | */ |
349 | static struct Peer * | 350 | static struct Peer * |
350 | make_peer(const struct GNUNET_PeerIdentity *peer, | 351 | make_peer (const struct GNUNET_PeerIdentity *peer, |
351 | const struct GNUNET_HELLO_Message *hello, | 352 | const struct GNUNET_HELLO_Message *hello, |
352 | int is_friend) | 353 | int is_friend) |
353 | { | 354 | { |
354 | struct Peer *ret; | 355 | struct Peer *ret; |
355 | 356 | ||
356 | ret = GNUNET_new(struct Peer); | 357 | ret = GNUNET_new (struct Peer); |
357 | ret->pid = *peer; | 358 | ret->pid = *peer; |
358 | ret->is_friend = is_friend; | 359 | ret->is_friend = is_friend; |
359 | if (NULL != hello) | 360 | if (NULL != hello) |
360 | { | 361 | { |
361 | ret->hello = GNUNET_malloc(GNUNET_HELLO_size(hello)); | 362 | ret->hello = GNUNET_malloc (GNUNET_HELLO_size (hello)); |
362 | GNUNET_memcpy(ret->hello, hello, GNUNET_HELLO_size(hello)); | 363 | GNUNET_memcpy (ret->hello, hello, GNUNET_HELLO_size (hello)); |
363 | } | 364 | } |
364 | GNUNET_break(GNUNET_OK == | 365 | GNUNET_break (GNUNET_OK == |
365 | GNUNET_CONTAINER_multipeermap_put( | 366 | GNUNET_CONTAINER_multipeermap_put ( |
366 | peers, | 367 | peers, |
367 | peer, | 368 | peer, |
368 | ret, | 369 | ret, |
369 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 370 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
370 | return ret; | 371 | return ret; |
371 | } | 372 | } |
372 | 373 | ||
@@ -377,7 +378,7 @@ make_peer(const struct GNUNET_PeerIdentity *peer, | |||
377 | * @param peer entry to initialize | 378 | * @param peer entry to initialize |
378 | */ | 379 | */ |
379 | static void | 380 | static void |
380 | setup_filter(struct Peer *peer) | 381 | setup_filter (struct Peer *peer) |
381 | { | 382 | { |
382 | struct GNUNET_HashCode hc; | 383 | struct GNUNET_HashCode hc; |
383 | 384 | ||
@@ -388,19 +389,20 @@ setup_filter(struct Peer *peer) | |||
388 | * "useless" once a HELLO has been passed on to ~100 | 389 | * "useless" once a HELLO has been passed on to ~100 |
389 | * other peers, which is likely more than enough in | 390 | * other peers, which is likely more than enough in |
390 | * any case; hence 64, 5 as bloomfilter parameters. */ | 391 | * any case; hence 64, 5 as bloomfilter parameters. */ |
391 | peer->filter = GNUNET_CONTAINER_bloomfilter_init(NULL, 64, 5); | 392 | peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5); |
392 | peer->filter_expiration = | 393 | peer->filter_expiration = |
393 | GNUNET_TIME_relative_to_absolute(HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY); | 394 | GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY); |
394 | /* never send a peer its own HELLO */ | 395 | /* never send a peer its own HELLO */ |
395 | GNUNET_CRYPTO_hash(&peer->pid, sizeof(struct GNUNET_PeerIdentity), &hc); | 396 | GNUNET_CRYPTO_hash (&peer->pid, sizeof(struct GNUNET_PeerIdentity), &hc); |
396 | GNUNET_CONTAINER_bloomfilter_add(peer->filter, &hc); | 397 | GNUNET_CONTAINER_bloomfilter_add (peer->filter, &hc); |
397 | } | 398 | } |
398 | 399 | ||
399 | 400 | ||
400 | /** | 401 | /** |
401 | * Closure for #find_advertisable_hello(). | 402 | * Closure for #find_advertisable_hello(). |
402 | */ | 403 | */ |
403 | struct FindAdvHelloContext { | 404 | struct FindAdvHelloContext |
405 | { | ||
404 | /** | 406 | /** |
405 | * Peer we want to advertise to. | 407 | * Peer we want to advertise to. |
406 | */ | 408 | */ |
@@ -429,9 +431,9 @@ struct FindAdvHelloContext { | |||
429 | * @return #GNUNET_YES (continue iteration) | 431 | * @return #GNUNET_YES (continue iteration) |
430 | */ | 432 | */ |
431 | static int | 433 | static int |
432 | find_advertisable_hello(void *cls, | 434 | find_advertisable_hello (void *cls, |
433 | const struct GNUNET_PeerIdentity *pid, | 435 | const struct GNUNET_PeerIdentity *pid, |
434 | void *value) | 436 | void *value) |
435 | { | 437 | { |
436 | struct FindAdvHelloContext *fah = cls; | 438 | struct FindAdvHelloContext *fah = cls; |
437 | struct Peer *pos = value; | 439 | struct Peer *pos = value; |
@@ -443,21 +445,21 @@ find_advertisable_hello(void *cls, | |||
443 | return GNUNET_YES; | 445 | return GNUNET_YES; |
444 | if (pos->hello == NULL) | 446 | if (pos->hello == NULL) |
445 | return GNUNET_YES; | 447 | return GNUNET_YES; |
446 | rst_time = GNUNET_TIME_absolute_get_remaining(pos->filter_expiration); | 448 | rst_time = GNUNET_TIME_absolute_get_remaining (pos->filter_expiration); |
447 | if (0 == rst_time.rel_value_us) | 449 | if (0 == rst_time.rel_value_us) |
448 | { | 450 | { |
449 | /* time to discard... */ | 451 | /* time to discard... */ |
450 | GNUNET_CONTAINER_bloomfilter_free(pos->filter); | 452 | GNUNET_CONTAINER_bloomfilter_free (pos->filter); |
451 | setup_filter(pos); | 453 | setup_filter (pos); |
452 | } | 454 | } |
453 | fah->next_adv = GNUNET_TIME_relative_min(rst_time, fah->next_adv); | 455 | fah->next_adv = GNUNET_TIME_relative_min (rst_time, fah->next_adv); |
454 | hs = GNUNET_HELLO_size(pos->hello); | 456 | hs = GNUNET_HELLO_size (pos->hello); |
455 | if (hs > fah->max_size) | 457 | if (hs > fah->max_size) |
456 | return GNUNET_YES; | 458 | return GNUNET_YES; |
457 | GNUNET_CRYPTO_hash(&fah->peer->pid, | 459 | GNUNET_CRYPTO_hash (&fah->peer->pid, |
458 | sizeof(struct GNUNET_PeerIdentity), | 460 | sizeof(struct GNUNET_PeerIdentity), |
459 | &hc); | 461 | &hc); |
460 | if (GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test(pos->filter, &hc)) | 462 | if (GNUNET_NO == GNUNET_CONTAINER_bloomfilter_test (pos->filter, &hc)) |
461 | fah->result = pos; | 463 | fah->result = pos; |
462 | return GNUNET_YES; | 464 | return GNUNET_YES; |
463 | } | 465 | } |
@@ -470,7 +472,7 @@ find_advertisable_hello(void *cls, | |||
470 | * @param cls for which peer to schedule the HELLO | 472 | * @param cls for which peer to schedule the HELLO |
471 | */ | 473 | */ |
472 | static void | 474 | static void |
473 | schedule_next_hello(void *cls) | 475 | schedule_next_hello (void *cls) |
474 | { | 476 | { |
475 | struct Peer *pl = cls; | 477 | struct Peer *pl = cls; |
476 | struct FindAdvHelloContext fah; | 478 | struct FindAdvHelloContext fah; |
@@ -480,42 +482,42 @@ schedule_next_hello(void *cls) | |||
480 | struct GNUNET_HashCode hc; | 482 | struct GNUNET_HashCode hc; |
481 | 483 | ||
482 | pl->hello_delay_task = NULL; | 484 | pl->hello_delay_task = NULL; |
483 | GNUNET_assert(NULL != pl->mq); | 485 | GNUNET_assert (NULL != pl->mq); |
484 | /* find applicable HELLOs */ | 486 | /* find applicable HELLOs */ |
485 | fah.peer = pl; | 487 | fah.peer = pl; |
486 | fah.result = NULL; | 488 | fah.result = NULL; |
487 | fah.max_size = GNUNET_MAX_MESSAGE_SIZE - 1; | 489 | fah.max_size = GNUNET_MAX_MESSAGE_SIZE - 1; |
488 | fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; | 490 | fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; |
489 | GNUNET_CONTAINER_multipeermap_iterate(peers, &find_advertisable_hello, &fah); | 491 | GNUNET_CONTAINER_multipeermap_iterate (peers, &find_advertisable_hello, &fah); |
490 | pl->hello_delay_task = | 492 | pl->hello_delay_task = |
491 | GNUNET_SCHEDULER_add_delayed(fah.next_adv, &schedule_next_hello, pl); | 493 | GNUNET_SCHEDULER_add_delayed (fah.next_adv, &schedule_next_hello, pl); |
492 | if (NULL == fah.result) | 494 | if (NULL == fah.result) |
493 | return; | 495 | return; |
494 | delay = GNUNET_TIME_absolute_get_remaining(pl->next_hello_allowed); | 496 | delay = GNUNET_TIME_absolute_get_remaining (pl->next_hello_allowed); |
495 | if (0 != delay.rel_value_us) | 497 | if (0 != delay.rel_value_us) |
496 | return; | 498 | return; |
497 | 499 | ||
498 | want = GNUNET_HELLO_size(fah.result->hello); | 500 | want = GNUNET_HELLO_size (fah.result->hello); |
499 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 501 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
500 | "Sending HELLO with %u bytes", | 502 | "Sending HELLO with %u bytes", |
501 | (unsigned int)want); | 503 | (unsigned int) want); |
502 | env = GNUNET_MQ_msg_copy(&fah.result->hello->header); | 504 | env = GNUNET_MQ_msg_copy (&fah.result->hello->header); |
503 | GNUNET_MQ_send(pl->mq, env); | 505 | GNUNET_MQ_send (pl->mq, env); |
504 | 506 | ||
505 | /* avoid sending this one again soon */ | 507 | /* avoid sending this one again soon */ |
506 | GNUNET_CRYPTO_hash(&pl->pid, sizeof(struct GNUNET_PeerIdentity), &hc); | 508 | GNUNET_CRYPTO_hash (&pl->pid, sizeof(struct GNUNET_PeerIdentity), &hc); |
507 | GNUNET_CONTAINER_bloomfilter_add(fah.result->filter, &hc); | 509 | GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &hc); |
508 | 510 | ||
509 | GNUNET_STATISTICS_update(stats, | 511 | GNUNET_STATISTICS_update (stats, |
510 | gettext_noop("# HELLO messages gossipped"), | 512 | gettext_noop ("# HELLO messages gossipped"), |
511 | 1, | 513 | 1, |
512 | GNUNET_NO); | 514 | GNUNET_NO); |
513 | /* prepare to send the next one */ | 515 | /* prepare to send the next one */ |
514 | pl->next_hello_allowed = | 516 | pl->next_hello_allowed = |
515 | GNUNET_TIME_relative_to_absolute(HELLO_ADVERTISEMENT_MIN_FREQUENCY); | 517 | GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_FREQUENCY); |
516 | if (NULL != pl->hello_delay_task) | 518 | if (NULL != pl->hello_delay_task) |
517 | GNUNET_SCHEDULER_cancel(pl->hello_delay_task); | 519 | GNUNET_SCHEDULER_cancel (pl->hello_delay_task); |
518 | pl->hello_delay_task = GNUNET_SCHEDULER_add_now(&schedule_next_hello, pl); | 520 | pl->hello_delay_task = GNUNET_SCHEDULER_add_now (&schedule_next_hello, pl); |
519 | } | 521 | } |
520 | 522 | ||
521 | 523 | ||
@@ -530,9 +532,9 @@ schedule_next_hello(void *cls) | |||
530 | * @return #GNUNET_YES (always) | 532 | * @return #GNUNET_YES (always) |
531 | */ | 533 | */ |
532 | static int | 534 | static int |
533 | reschedule_hellos(void *cls, | 535 | reschedule_hellos (void *cls, |
534 | const struct GNUNET_PeerIdentity *pid, | 536 | const struct GNUNET_PeerIdentity *pid, |
535 | void *value) | 537 | void *value) |
536 | { | 538 | { |
537 | struct Peer *peer = value; | 539 | struct Peer *peer = value; |
538 | struct Peer *skip = cls; | 540 | struct Peer *skip = cls; |
@@ -542,12 +544,12 @@ reschedule_hellos(void *cls, | |||
542 | if (NULL == peer->mq) | 544 | if (NULL == peer->mq) |
543 | return GNUNET_YES; | 545 | return GNUNET_YES; |
544 | if (NULL != peer->hello_delay_task) | 546 | if (NULL != peer->hello_delay_task) |
545 | { | 547 | { |
546 | GNUNET_SCHEDULER_cancel(peer->hello_delay_task); | 548 | GNUNET_SCHEDULER_cancel (peer->hello_delay_task); |
547 | peer->hello_delay_task = NULL; | 549 | peer->hello_delay_task = NULL; |
548 | } | 550 | } |
549 | peer->hello_delay_task = | 551 | peer->hello_delay_task = |
550 | GNUNET_SCHEDULER_add_now(&schedule_next_hello, peer); | 552 | GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer); |
551 | return GNUNET_YES; | 553 | return GNUNET_YES; |
552 | } | 554 | } |
553 | 555 | ||
@@ -561,44 +563,44 @@ reschedule_hellos(void *cls, | |||
561 | * @return our `struct Peer` for @a peer | 563 | * @return our `struct Peer` for @a peer |
562 | */ | 564 | */ |
563 | static void * | 565 | static void * |
564 | connect_notify(void *cls, | 566 | connect_notify (void *cls, |
565 | const struct GNUNET_PeerIdentity *peer, | 567 | const struct GNUNET_PeerIdentity *peer, |
566 | struct GNUNET_MQ_Handle *mq) | 568 | struct GNUNET_MQ_Handle *mq) |
567 | { | 569 | { |
568 | struct Peer *pos; | 570 | struct Peer *pos; |
569 | 571 | ||
570 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 572 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
571 | "Core told us that we are connecting to `%s'\n", | 573 | "Core told us that we are connecting to `%s'\n", |
572 | GNUNET_i2s(peer)); | 574 | GNUNET_i2s (peer)); |
573 | if (0 == GNUNET_memcmp(&my_identity, peer)) | 575 | if (0 == GNUNET_memcmp (&my_identity, peer)) |
574 | return NULL; | 576 | return NULL; |
575 | GNUNET_MQ_set_options(mq, GNUNET_MQ_PRIO_BEST_EFFORT); | 577 | GNUNET_MQ_set_options (mq, GNUNET_MQ_PRIO_BEST_EFFORT); |
576 | connection_count++; | 578 | connection_count++; |
577 | GNUNET_STATISTICS_set(stats, | 579 | GNUNET_STATISTICS_set (stats, |
578 | gettext_noop("# peers connected"), | 580 | gettext_noop ("# peers connected"), |
579 | connection_count, | 581 | connection_count, |
580 | GNUNET_NO); | 582 | GNUNET_NO); |
581 | pos = GNUNET_CONTAINER_multipeermap_get(peers, peer); | 583 | pos = GNUNET_CONTAINER_multipeermap_get (peers, peer); |
582 | if (NULL == pos) | 584 | if (NULL == pos) |
583 | { | 585 | { |
584 | pos = make_peer(peer, NULL, GNUNET_NO); | 586 | pos = make_peer (peer, NULL, GNUNET_NO); |
585 | } | 587 | } |
586 | else | 588 | else |
587 | { | 589 | { |
588 | GNUNET_assert(NULL == pos->mq); | 590 | GNUNET_assert (NULL == pos->mq); |
589 | } | 591 | } |
590 | pos->mq = mq; | 592 | pos->mq = mq; |
591 | if (pos->is_friend) | 593 | if (pos->is_friend) |
592 | { | 594 | { |
593 | friend_count++; | 595 | friend_count++; |
594 | if ((friend_count == minimum_friend_count) && (GNUNET_YES != friends_only)) | 596 | if ((friend_count == minimum_friend_count) && (GNUNET_YES != friends_only)) |
595 | whitelist_peers(); | 597 | whitelist_peers (); |
596 | GNUNET_STATISTICS_set(stats, | 598 | GNUNET_STATISTICS_set (stats, |
597 | gettext_noop("# friends connected"), | 599 | gettext_noop ("# friends connected"), |
598 | friend_count, | 600 | friend_count, |
599 | GNUNET_NO); | 601 | GNUNET_NO); |
600 | } | 602 | } |
601 | reschedule_hellos(NULL, peer, pos); | 603 | reschedule_hellos (NULL, peer, pos); |
602 | return pos; | 604 | return pos; |
603 | } | 605 | } |
604 | 606 | ||
@@ -612,11 +614,11 @@ connect_notify(void *cls, | |||
612 | * @return #GNUNET_YES (continue to iterate) | 614 | * @return #GNUNET_YES (continue to iterate) |
613 | */ | 615 | */ |
614 | static int | 616 | static int |
615 | try_add_peers(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | 617 | try_add_peers (void *cls, const struct GNUNET_PeerIdentity *pid, void *value) |
616 | { | 618 | { |
617 | struct Peer *pos = value; | 619 | struct Peer *pos = value; |
618 | 620 | ||
619 | attempt_connect(pos); | 621 | attempt_connect (pos); |
620 | return GNUNET_YES; | 622 | return GNUNET_YES; |
621 | } | 623 | } |
622 | 624 | ||
@@ -627,11 +629,11 @@ try_add_peers(void *cls, const struct GNUNET_PeerIdentity *pid, void *value) | |||
627 | * @param cls unused, NULL | 629 | * @param cls unused, NULL |
628 | */ | 630 | */ |
629 | static void | 631 | static void |
630 | add_peer_task(void *cls) | 632 | add_peer_task (void *cls) |
631 | { | 633 | { |
632 | add_task = NULL; | 634 | add_task = NULL; |
633 | 635 | ||
634 | GNUNET_CONTAINER_multipeermap_iterate(peers, &try_add_peers, NULL); | 636 | GNUNET_CONTAINER_multipeermap_iterate (peers, &try_add_peers, NULL); |
635 | } | 637 | } |
636 | 638 | ||
637 | 639 | ||
@@ -643,47 +645,47 @@ add_peer_task(void *cls) | |||
643 | * @param internal_cls the `struct Peer` for this peer | 645 | * @param internal_cls the `struct Peer` for this peer |
644 | */ | 646 | */ |
645 | static void | 647 | static void |
646 | disconnect_notify(void *cls, | 648 | disconnect_notify (void *cls, |
647 | const struct GNUNET_PeerIdentity *peer, | 649 | const struct GNUNET_PeerIdentity *peer, |
648 | void *internal_cls) | 650 | void *internal_cls) |
649 | { | 651 | { |
650 | struct Peer *pos = internal_cls; | 652 | struct Peer *pos = internal_cls; |
651 | 653 | ||
652 | if (NULL == pos) | 654 | if (NULL == pos) |
653 | return; /* myself, we're shutting down */ | 655 | return; /* myself, we're shutting down */ |
654 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 656 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
655 | "Core told us that we disconnected from `%s'\n", | 657 | "Core told us that we disconnected from `%s'\n", |
656 | GNUNET_i2s(peer)); | 658 | GNUNET_i2s (peer)); |
657 | if (NULL == pos->mq) | 659 | if (NULL == pos->mq) |
658 | { | 660 | { |
659 | GNUNET_break(0); | 661 | GNUNET_break (0); |
660 | return; | 662 | return; |
661 | } | 663 | } |
662 | pos->mq = NULL; | 664 | pos->mq = NULL; |
663 | connection_count--; | 665 | connection_count--; |
664 | if (NULL != pos->hello_delay_task) | 666 | if (NULL != pos->hello_delay_task) |
665 | { | 667 | { |
666 | GNUNET_SCHEDULER_cancel(pos->hello_delay_task); | 668 | GNUNET_SCHEDULER_cancel (pos->hello_delay_task); |
667 | pos->hello_delay_task = NULL; | 669 | pos->hello_delay_task = NULL; |
668 | } | 670 | } |
669 | GNUNET_STATISTICS_set(stats, | 671 | GNUNET_STATISTICS_set (stats, |
670 | gettext_noop("# peers connected"), | 672 | gettext_noop ("# peers connected"), |
671 | connection_count, | 673 | connection_count, |
672 | GNUNET_NO); | 674 | GNUNET_NO); |
673 | if (pos->is_friend) | 675 | if (pos->is_friend) |
674 | { | 676 | { |
675 | friend_count--; | 677 | friend_count--; |
676 | GNUNET_STATISTICS_set(stats, | 678 | GNUNET_STATISTICS_set (stats, |
677 | gettext_noop("# friends connected"), | 679 | gettext_noop ("# friends connected"), |
678 | friend_count, | 680 | friend_count, |
679 | GNUNET_NO); | 681 | GNUNET_NO); |
680 | } | 682 | } |
681 | if (((connection_count < target_connection_count) || | 683 | if (((connection_count < target_connection_count) || |
682 | (friend_count < minimum_friend_count)) && | 684 | (friend_count < minimum_friend_count)) && |
683 | (NULL == add_task)) | 685 | (NULL == add_task)) |
684 | add_task = GNUNET_SCHEDULER_add_now(&add_peer_task, NULL); | 686 | add_task = GNUNET_SCHEDULER_add_now (&add_peer_task, NULL); |
685 | if ((friend_count < minimum_friend_count) && (NULL == blacklist)) | 687 | if ((friend_count < minimum_friend_count) && (NULL == blacklist)) |
686 | blacklist = GNUNET_TRANSPORT_blacklist(cfg, &blacklist_check, NULL); | 688 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL); |
687 | } | 689 | } |
688 | 690 | ||
689 | 691 | ||
@@ -696,9 +698,9 @@ disconnect_notify(void *cls, | |||
696 | * @return #GNUNET_SYSERR always, to terminate iteration | 698 | * @return #GNUNET_SYSERR always, to terminate iteration |
697 | */ | 699 | */ |
698 | static int | 700 | static int |
699 | address_iterator(void *cls, | 701 | address_iterator (void *cls, |
700 | const struct GNUNET_HELLO_Address *address, | 702 | const struct GNUNET_HELLO_Address *address, |
701 | struct GNUNET_TIME_Absolute expiration) | 703 | struct GNUNET_TIME_Absolute expiration) |
702 | { | 704 | { |
703 | int *flag = cls; | 705 | int *flag = cls; |
704 | 706 | ||
@@ -714,7 +716,7 @@ address_iterator(void *cls, | |||
714 | * @param hello the HELLO we got | 716 | * @param hello the HELLO we got |
715 | */ | 717 | */ |
716 | static void | 718 | static void |
717 | consider_for_advertising(const struct GNUNET_HELLO_Message *hello) | 719 | consider_for_advertising (const struct GNUNET_HELLO_Message *hello) |
718 | { | 720 | { |
719 | int have_address; | 721 | int have_address; |
720 | struct GNUNET_PeerIdentity pid; | 722 | struct GNUNET_PeerIdentity pid; |
@@ -723,55 +725,55 @@ consider_for_advertising(const struct GNUNET_HELLO_Message *hello) | |||
723 | struct Peer *peer; | 725 | struct Peer *peer; |
724 | uint16_t size; | 726 | uint16_t size; |
725 | 727 | ||
726 | if (GNUNET_OK != GNUNET_HELLO_get_id(hello, &pid)) | 728 | if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) |
727 | { | 729 | { |
728 | GNUNET_break(0); | 730 | GNUNET_break (0); |
729 | return; | 731 | return; |
730 | } | 732 | } |
731 | if (0 == GNUNET_memcmp(&pid, &my_identity)) | 733 | if (0 == GNUNET_memcmp (&pid, &my_identity)) |
732 | return; /* that's me! */ | 734 | return; /* that's me! */ |
733 | have_address = GNUNET_NO; | 735 | have_address = GNUNET_NO; |
734 | GNUNET_HELLO_iterate_addresses(hello, | 736 | GNUNET_HELLO_iterate_addresses (hello, |
735 | GNUNET_NO, | 737 | GNUNET_NO, |
736 | &address_iterator, | 738 | &address_iterator, |
737 | &have_address); | 739 | &have_address); |
738 | if (GNUNET_NO == have_address) | 740 | if (GNUNET_NO == have_address) |
739 | return; /* no point in advertising this one... */ | 741 | return; /* no point in advertising this one... */ |
740 | peer = GNUNET_CONTAINER_multipeermap_get(peers, &pid); | 742 | peer = GNUNET_CONTAINER_multipeermap_get (peers, &pid); |
741 | if (NULL == peer) | 743 | if (NULL == peer) |
742 | { | 744 | { |
743 | peer = make_peer(&pid, hello, GNUNET_NO); | 745 | peer = make_peer (&pid, hello, GNUNET_NO); |
744 | } | 746 | } |
745 | else if (NULL != peer->hello) | 747 | else if (NULL != peer->hello) |
746 | { | 748 | { |
747 | dt = GNUNET_HELLO_equals(peer->hello, hello, GNUNET_TIME_absolute_get()); | 749 | dt = GNUNET_HELLO_equals (peer->hello, hello, GNUNET_TIME_absolute_get ()); |
748 | if (dt.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) | 750 | if (dt.abs_value_us == GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us) |
749 | return; /* nothing new here */ | 751 | return; /* nothing new here */ |
750 | } | 752 | } |
751 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 753 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
752 | "Found HELLO from peer `%s' for advertising\n", | 754 | "Found HELLO from peer `%s' for advertising\n", |
753 | GNUNET_i2s(&pid)); | 755 | GNUNET_i2s (&pid)); |
754 | if (NULL != peer->hello) | 756 | if (NULL != peer->hello) |
755 | { | 757 | { |
756 | nh = GNUNET_HELLO_merge(peer->hello, hello); | 758 | nh = GNUNET_HELLO_merge (peer->hello, hello); |
757 | GNUNET_free(peer->hello); | 759 | GNUNET_free (peer->hello); |
758 | peer->hello = nh; | 760 | peer->hello = nh; |
759 | } | 761 | } |
760 | else | 762 | else |
761 | { | 763 | { |
762 | size = GNUNET_HELLO_size(hello); | 764 | size = GNUNET_HELLO_size (hello); |
763 | peer->hello = GNUNET_malloc(size); | 765 | peer->hello = GNUNET_malloc (size); |
764 | GNUNET_memcpy(peer->hello, hello, size); | 766 | GNUNET_memcpy (peer->hello, hello, size); |
765 | } | 767 | } |
766 | if (NULL != peer->filter) | 768 | if (NULL != peer->filter) |
767 | { | 769 | { |
768 | GNUNET_CONTAINER_bloomfilter_free(peer->filter); | 770 | GNUNET_CONTAINER_bloomfilter_free (peer->filter); |
769 | peer->filter = NULL; | 771 | peer->filter = NULL; |
770 | } | 772 | } |
771 | setup_filter(peer); | 773 | setup_filter (peer); |
772 | /* since we have a new HELLO to pick from, re-schedule all | 774 | /* since we have a new HELLO to pick from, re-schedule all |
773 | * HELLO requests that are not bound by the HELLO send rate! */ | 775 | * HELLO requests that are not bound by the HELLO send rate! */ |
774 | GNUNET_CONTAINER_multipeermap_iterate(peers, &reschedule_hellos, peer); | 776 | GNUNET_CONTAINER_multipeermap_iterate (peers, &reschedule_hellos, peer); |
775 | } | 777 | } |
776 | 778 | ||
777 | 779 | ||
@@ -785,49 +787,49 @@ consider_for_advertising(const struct GNUNET_HELLO_Message *hello) | |||
785 | * @param err_msg NULL if successful, otherwise contains error message | 787 | * @param err_msg NULL if successful, otherwise contains error message |
786 | */ | 788 | */ |
787 | static void | 789 | static void |
788 | process_peer(void *cls, | 790 | process_peer (void *cls, |
789 | const struct GNUNET_PeerIdentity *peer, | 791 | const struct GNUNET_PeerIdentity *peer, |
790 | const struct GNUNET_HELLO_Message *hello, | 792 | const struct GNUNET_HELLO_Message *hello, |
791 | const char *err_msg) | 793 | const char *err_msg) |
792 | { | 794 | { |
793 | struct Peer *pos; | 795 | struct Peer *pos; |
794 | 796 | ||
795 | if (NULL != err_msg) | 797 | if (NULL != err_msg) |
796 | { | 798 | { |
797 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 799 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
798 | _("Error in communication with PEERINFO service: %s\n"), | 800 | _ ("Error in communication with PEERINFO service: %s\n"), |
799 | err_msg); | 801 | err_msg); |
800 | GNUNET_PEERINFO_notify_cancel(peerinfo_notify); | 802 | GNUNET_PEERINFO_notify_cancel (peerinfo_notify); |
801 | peerinfo_notify = | 803 | peerinfo_notify = |
802 | GNUNET_PEERINFO_notify(cfg, GNUNET_NO, &process_peer, NULL); | 804 | GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL); |
803 | return; | 805 | return; |
804 | } | 806 | } |
805 | GNUNET_assert(NULL != peer); | 807 | GNUNET_assert (NULL != peer); |
806 | if (0 == GNUNET_memcmp(&my_identity, peer)) | 808 | if (0 == GNUNET_memcmp (&my_identity, peer)) |
807 | return; /* that's me! */ | 809 | return; /* that's me! */ |
808 | if (NULL == hello) | 810 | if (NULL == hello) |
811 | { | ||
812 | /* free existing HELLO, if any */ | ||
813 | pos = GNUNET_CONTAINER_multipeermap_get (peers, peer); | ||
814 | if (NULL != pos) | ||
809 | { | 815 | { |
810 | /* free existing HELLO, if any */ | 816 | GNUNET_free_non_null (pos->hello); |
811 | pos = GNUNET_CONTAINER_multipeermap_get(peers, peer); | 817 | pos->hello = NULL; |
812 | if (NULL != pos) | 818 | if (NULL != pos->filter) |
813 | { | 819 | { |
814 | GNUNET_free_non_null(pos->hello); | 820 | GNUNET_CONTAINER_bloomfilter_free (pos->filter); |
815 | pos->hello = NULL; | 821 | pos->filter = NULL; |
816 | if (NULL != pos->filter) | 822 | } |
817 | { | 823 | if ((NULL == pos->mq) && (GNUNET_NO == pos->is_friend)) |
818 | GNUNET_CONTAINER_bloomfilter_free(pos->filter); | 824 | free_peer (NULL, &pos->pid, pos); |
819 | pos->filter = NULL; | ||
820 | } | ||
821 | if ((NULL == pos->mq) && (GNUNET_NO == pos->is_friend)) | ||
822 | free_peer(NULL, &pos->pid, pos); | ||
823 | } | ||
824 | return; | ||
825 | } | 825 | } |
826 | consider_for_advertising(hello); | 826 | return; |
827 | pos = GNUNET_CONTAINER_multipeermap_get(peers, peer); | 827 | } |
828 | consider_for_advertising (hello); | ||
829 | pos = GNUNET_CONTAINER_multipeermap_get (peers, peer); | ||
828 | if (NULL == pos) | 830 | if (NULL == pos) |
829 | pos = make_peer(peer, hello, GNUNET_NO); | 831 | pos = make_peer (peer, hello, GNUNET_NO); |
830 | attempt_connect(pos); | 832 | attempt_connect (pos); |
831 | } | 833 | } |
832 | 834 | ||
833 | 835 | ||
@@ -839,20 +841,20 @@ process_peer(void *cls, | |||
839 | * @param my_id ID of this peer, NULL if we failed | 841 | * @param my_id ID of this peer, NULL if we failed |
840 | */ | 842 | */ |
841 | static void | 843 | static void |
842 | core_init(void *cls, const struct GNUNET_PeerIdentity *my_id) | 844 | core_init (void *cls, const struct GNUNET_PeerIdentity *my_id) |
843 | { | 845 | { |
844 | if (NULL == my_id) | 846 | if (NULL == my_id) |
845 | { | 847 | { |
846 | GNUNET_log( | 848 | GNUNET_log ( |
847 | GNUNET_ERROR_TYPE_ERROR, | 849 | GNUNET_ERROR_TYPE_ERROR, |
848 | _("Failed to connect to core service, can not manage topology!\n")); | 850 | _ ("Failed to connect to core service, can not manage topology!\n")); |
849 | GNUNET_SCHEDULER_shutdown(); | 851 | GNUNET_SCHEDULER_shutdown (); |
850 | return; | 852 | return; |
851 | } | 853 | } |
852 | my_identity = *my_id; | 854 | my_identity = *my_id; |
853 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s(my_id)); | 855 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id)); |
854 | peerinfo_notify = | 856 | peerinfo_notify = |
855 | GNUNET_PEERINFO_notify(cfg, GNUNET_NO, &process_peer, NULL); | 857 | GNUNET_PEERINFO_notify (cfg, GNUNET_NO, &process_peer, NULL); |
856 | } | 858 | } |
857 | 859 | ||
858 | 860 | ||
@@ -863,23 +865,23 @@ core_init(void *cls, const struct GNUNET_PeerIdentity *my_id) | |||
863 | * @param pid identity of the friend | 865 | * @param pid identity of the friend |
864 | */ | 866 | */ |
865 | static void | 867 | static void |
866 | handle_friend(void *cls, const struct GNUNET_PeerIdentity *pid) | 868 | handle_friend (void *cls, const struct GNUNET_PeerIdentity *pid) |
867 | { | 869 | { |
868 | unsigned int *entries_found = cls; | 870 | unsigned int *entries_found = cls; |
869 | struct Peer *fl; | 871 | struct Peer *fl; |
870 | 872 | ||
871 | if (0 == GNUNET_memcmp(pid, &my_identity)) | 873 | if (0 == GNUNET_memcmp (pid, &my_identity)) |
872 | { | 874 | { |
873 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 875 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
874 | _("Found myself `%s' in friend list (useless, ignored)\n"), | 876 | _ ("Found myself `%s' in friend list (useless, ignored)\n"), |
875 | GNUNET_i2s(pid)); | 877 | GNUNET_i2s (pid)); |
876 | return; | 878 | return; |
877 | } | 879 | } |
878 | (*entries_found)++; | 880 | (*entries_found)++; |
879 | fl = make_peer(pid, NULL, GNUNET_YES); | 881 | fl = make_peer (pid, NULL, GNUNET_YES); |
880 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 882 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
881 | _("Found friend `%s' in configuration\n"), | 883 | _ ("Found friend `%s' in configuration\n"), |
882 | GNUNET_i2s(&fl->pid)); | 884 | GNUNET_i2s (&fl->pid)); |
883 | } | 885 | } |
884 | 886 | ||
885 | 887 | ||
@@ -887,36 +889,36 @@ handle_friend(void *cls, const struct GNUNET_PeerIdentity *pid) | |||
887 | * Read the friends file. | 889 | * Read the friends file. |
888 | */ | 890 | */ |
889 | static void | 891 | static void |
890 | read_friends_file(const struct GNUNET_CONFIGURATION_Handle *cfg) | 892 | read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) |
891 | { | 893 | { |
892 | unsigned int entries_found; | 894 | unsigned int entries_found; |
893 | 895 | ||
894 | entries_found = 0; | 896 | entries_found = 0; |
895 | if (GNUNET_OK != GNUNET_FRIENDS_parse(cfg, &handle_friend, &entries_found)) | 897 | if (GNUNET_OK != GNUNET_FRIENDS_parse (cfg, &handle_friend, &entries_found)) |
896 | { | 898 | { |
897 | if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0)) | 899 | if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0)) |
898 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | 900 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
899 | _("Encountered errors parsing friends list!\n")); | 901 | _ ("Encountered errors parsing friends list!\n")); |
900 | } | 902 | } |
901 | GNUNET_STATISTICS_update(stats, | 903 | GNUNET_STATISTICS_update (stats, |
902 | gettext_noop("# friends in configuration"), | 904 | gettext_noop ("# friends in configuration"), |
903 | entries_found, | 905 | entries_found, |
904 | GNUNET_NO); | 906 | GNUNET_NO); |
905 | if ((minimum_friend_count > entries_found) && (GNUNET_NO == friends_only)) | 907 | if ((minimum_friend_count > entries_found) && (GNUNET_NO == friends_only)) |
906 | { | 908 | { |
907 | GNUNET_log( | 909 | GNUNET_log ( |
908 | GNUNET_ERROR_TYPE_WARNING, | 910 | GNUNET_ERROR_TYPE_WARNING, |
909 | _( | 911 | _ ( |
910 | "Fewer friends specified than required by minimum friend count. Will only connect to friends.\n")); | 912 | "Fewer friends specified than required by minimum friend count. Will only connect to friends.\n")); |
911 | } | 913 | } |
912 | if ((minimum_friend_count > target_connection_count) && | 914 | if ((minimum_friend_count > target_connection_count) && |
913 | (GNUNET_NO == friends_only)) | 915 | (GNUNET_NO == friends_only)) |
914 | { | 916 | { |
915 | GNUNET_log( | 917 | GNUNET_log ( |
916 | GNUNET_ERROR_TYPE_WARNING, | 918 | GNUNET_ERROR_TYPE_WARNING, |
917 | _( | 919 | _ ( |
918 | "More friendly connections required than target total number of connections.\n")); | 920 | "More friendly connections required than target total number of connections.\n")); |
919 | } | 921 | } |
920 | } | 922 | } |
921 | 923 | ||
922 | 924 | ||
@@ -930,15 +932,15 @@ read_friends_file(const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
930 | * #GNUNET_SYSERR if @a message is invalid | 932 | * #GNUNET_SYSERR if @a message is invalid |
931 | */ | 933 | */ |
932 | static int | 934 | static int |
933 | check_hello(void *cls, const struct GNUNET_HELLO_Message *message) | 935 | check_hello (void *cls, const struct GNUNET_HELLO_Message *message) |
934 | { | 936 | { |
935 | struct GNUNET_PeerIdentity pid; | 937 | struct GNUNET_PeerIdentity pid; |
936 | 938 | ||
937 | if (GNUNET_OK != GNUNET_HELLO_get_id(message, &pid)) | 939 | if (GNUNET_OK != GNUNET_HELLO_get_id (message, &pid)) |
938 | { | 940 | { |
939 | GNUNET_break_op(0); | 941 | GNUNET_break_op (0); |
940 | return GNUNET_SYSERR; | 942 | return GNUNET_SYSERR; |
941 | } | 943 | } |
942 | return GNUNET_OK; | 944 | return GNUNET_OK; |
943 | } | 945 | } |
944 | 946 | ||
@@ -951,35 +953,35 @@ check_hello(void *cls, const struct GNUNET_HELLO_Message *message) | |||
951 | * @param message the actual HELLO message | 953 | * @param message the actual HELLO message |
952 | */ | 954 | */ |
953 | static void | 955 | static void |
954 | handle_hello(void *cls, const struct GNUNET_HELLO_Message *message) | 956 | handle_hello (void *cls, const struct GNUNET_HELLO_Message *message) |
955 | { | 957 | { |
956 | const struct GNUNET_PeerIdentity *other = cls; | 958 | const struct GNUNET_PeerIdentity *other = cls; |
957 | struct Peer *peer; | 959 | struct Peer *peer; |
958 | struct GNUNET_PeerIdentity pid; | 960 | struct GNUNET_PeerIdentity pid; |
959 | 961 | ||
960 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 962 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
961 | "Received encrypted HELLO from peer `%s'", | 963 | "Received encrypted HELLO from peer `%s'", |
962 | GNUNET_i2s(other)); | 964 | GNUNET_i2s (other)); |
963 | GNUNET_assert(GNUNET_OK == GNUNET_HELLO_get_id(message, &pid)); | 965 | GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (message, &pid)); |
964 | GNUNET_STATISTICS_update(stats, | 966 | GNUNET_STATISTICS_update (stats, |
965 | gettext_noop("# HELLO messages received"), | 967 | gettext_noop ("# HELLO messages received"), |
966 | 1, | 968 | 1, |
967 | GNUNET_NO); | 969 | GNUNET_NO); |
968 | peer = GNUNET_CONTAINER_multipeermap_get(peers, &pid); | 970 | peer = GNUNET_CONTAINER_multipeermap_get (peers, &pid); |
969 | if (NULL == peer) | 971 | if (NULL == peer) |
970 | { | 972 | { |
971 | if ((GNUNET_YES == friends_only) || (friend_count < minimum_friend_count)) | 973 | if ((GNUNET_YES == friends_only) || (friend_count < minimum_friend_count)) |
972 | return; | 974 | return; |
973 | } | 975 | } |
974 | else | 976 | else |
975 | { | 977 | { |
976 | if ((GNUNET_YES != peer->is_friend) && (GNUNET_YES == friends_only)) | 978 | if ((GNUNET_YES != peer->is_friend) && (GNUNET_YES == friends_only)) |
977 | return; | 979 | return; |
978 | if ((GNUNET_YES != peer->is_friend) && | 980 | if ((GNUNET_YES != peer->is_friend) && |
979 | (friend_count < minimum_friend_count)) | 981 | (friend_count < minimum_friend_count)) |
980 | return; | 982 | return; |
981 | } | 983 | } |
982 | (void)GNUNET_PEERINFO_add_peer(pi, message, NULL, NULL); | 984 | (void) GNUNET_PEERINFO_add_peer (pi, message, NULL, NULL); |
983 | } | 985 | } |
984 | 986 | ||
985 | 987 | ||
@@ -990,47 +992,47 @@ handle_hello(void *cls, const struct GNUNET_HELLO_Message *message) | |||
990 | * @param cls unused, NULL | 992 | * @param cls unused, NULL |
991 | */ | 993 | */ |
992 | static void | 994 | static void |
993 | cleaning_task(void *cls) | 995 | cleaning_task (void *cls) |
994 | { | 996 | { |
995 | if (NULL != peerinfo_notify) | 997 | if (NULL != peerinfo_notify) |
996 | { | 998 | { |
997 | GNUNET_PEERINFO_notify_cancel(peerinfo_notify); | 999 | GNUNET_PEERINFO_notify_cancel (peerinfo_notify); |
998 | peerinfo_notify = NULL; | 1000 | peerinfo_notify = NULL; |
999 | } | 1001 | } |
1000 | if (NULL != handle) | 1002 | if (NULL != handle) |
1001 | { | 1003 | { |
1002 | GNUNET_CORE_disconnect(handle); | 1004 | GNUNET_CORE_disconnect (handle); |
1003 | handle = NULL; | 1005 | handle = NULL; |
1004 | } | 1006 | } |
1005 | whitelist_peers(); | 1007 | whitelist_peers (); |
1006 | if (NULL != add_task) | 1008 | if (NULL != add_task) |
1007 | { | 1009 | { |
1008 | GNUNET_SCHEDULER_cancel(add_task); | 1010 | GNUNET_SCHEDULER_cancel (add_task); |
1009 | add_task = NULL; | 1011 | add_task = NULL; |
1010 | } | 1012 | } |
1011 | if (NULL != oh) | 1013 | if (NULL != oh) |
1012 | { | 1014 | { |
1013 | GNUNET_TRANSPORT_offer_hello_cancel(oh); | 1015 | GNUNET_TRANSPORT_offer_hello_cancel (oh); |
1014 | oh = NULL; | 1016 | oh = NULL; |
1015 | } | 1017 | } |
1016 | GNUNET_CONTAINER_multipeermap_iterate(peers, &free_peer, NULL); | 1018 | GNUNET_CONTAINER_multipeermap_iterate (peers, &free_peer, NULL); |
1017 | GNUNET_CONTAINER_multipeermap_destroy(peers); | 1019 | GNUNET_CONTAINER_multipeermap_destroy (peers); |
1018 | peers = NULL; | 1020 | peers = NULL; |
1019 | if (NULL != ats) | 1021 | if (NULL != ats) |
1020 | { | 1022 | { |
1021 | GNUNET_ATS_connectivity_done(ats); | 1023 | GNUNET_ATS_connectivity_done (ats); |
1022 | ats = NULL; | 1024 | ats = NULL; |
1023 | } | 1025 | } |
1024 | if (NULL != pi) | 1026 | if (NULL != pi) |
1025 | { | 1027 | { |
1026 | GNUNET_PEERINFO_disconnect(pi); | 1028 | GNUNET_PEERINFO_disconnect (pi); |
1027 | pi = NULL; | 1029 | pi = NULL; |
1028 | } | 1030 | } |
1029 | if (NULL != stats) | 1031 | if (NULL != stats) |
1030 | { | 1032 | { |
1031 | GNUNET_STATISTICS_destroy(stats, GNUNET_NO); | 1033 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); |
1032 | stats = NULL; | 1034 | stats = NULL; |
1033 | } | 1035 | } |
1034 | } | 1036 | } |
1035 | 1037 | ||
1036 | 1038 | ||
@@ -1043,62 +1045,62 @@ cleaning_task(void *cls) | |||
1043 | * @param c configuration | 1045 | * @param c configuration |
1044 | */ | 1046 | */ |
1045 | static void | 1047 | static void |
1046 | run(void *cls, | 1048 | run (void *cls, |
1047 | char *const *args, | 1049 | char *const *args, |
1048 | const char *cfgfile, | 1050 | const char *cfgfile, |
1049 | const struct GNUNET_CONFIGURATION_Handle *c) | 1051 | const struct GNUNET_CONFIGURATION_Handle *c) |
1050 | { | 1052 | { |
1051 | struct GNUNET_MQ_MessageHandler handlers[] = | 1053 | struct GNUNET_MQ_MessageHandler handlers[] = |
1052 | { GNUNET_MQ_hd_var_size(hello, | 1054 | { GNUNET_MQ_hd_var_size (hello, |
1053 | GNUNET_MESSAGE_TYPE_HELLO, | 1055 | GNUNET_MESSAGE_TYPE_HELLO, |
1054 | struct GNUNET_HELLO_Message, | 1056 | struct GNUNET_HELLO_Message, |
1055 | NULL), | 1057 | NULL), |
1056 | GNUNET_MQ_handler_end() }; | 1058 | GNUNET_MQ_handler_end () }; |
1057 | unsigned long long opt; | 1059 | unsigned long long opt; |
1058 | 1060 | ||
1059 | cfg = c; | 1061 | cfg = c; |
1060 | stats = GNUNET_STATISTICS_create("topology", cfg); | 1062 | stats = GNUNET_STATISTICS_create ("topology", cfg); |
1061 | friends_only = | 1063 | friends_only = |
1062 | GNUNET_CONFIGURATION_get_value_yesno(cfg, "TOPOLOGY", "FRIENDS-ONLY"); | 1064 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "TOPOLOGY", "FRIENDS-ONLY"); |
1063 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number(cfg, | 1065 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, |
1064 | "TOPOLOGY", | 1066 | "TOPOLOGY", |
1065 | "MINIMUM-FRIENDS", | 1067 | "MINIMUM-FRIENDS", |
1066 | &opt)) | 1068 | &opt)) |
1067 | opt = 0; | 1069 | opt = 0; |
1068 | minimum_friend_count = (unsigned int)opt; | 1070 | minimum_friend_count = (unsigned int) opt; |
1069 | if (GNUNET_OK != | 1071 | if (GNUNET_OK != |
1070 | GNUNET_CONFIGURATION_get_value_number(cfg, | 1072 | GNUNET_CONFIGURATION_get_value_number (cfg, |
1071 | "TOPOLOGY", | 1073 | "TOPOLOGY", |
1072 | "TARGET-CONNECTION-COUNT", | 1074 | "TARGET-CONNECTION-COUNT", |
1073 | &opt)) | 1075 | &opt)) |
1074 | opt = 16; | 1076 | opt = 16; |
1075 | target_connection_count = (unsigned int)opt; | 1077 | target_connection_count = (unsigned int) opt; |
1076 | peers = GNUNET_CONTAINER_multipeermap_create(target_connection_count * 2, | 1078 | peers = GNUNET_CONTAINER_multipeermap_create (target_connection_count * 2, |
1077 | GNUNET_NO); | 1079 | GNUNET_NO); |
1078 | read_friends_file(cfg); | 1080 | read_friends_file (cfg); |
1079 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | 1081 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1080 | "Topology would like %u connections with at least %u friends\n", | 1082 | "Topology would like %u connections with at least %u friends\n", |
1081 | target_connection_count, | 1083 | target_connection_count, |
1082 | minimum_friend_count); | 1084 | minimum_friend_count); |
1083 | if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0)) | 1085 | if ((GNUNET_YES == friends_only) || (minimum_friend_count > 0)) |
1084 | blacklist = GNUNET_TRANSPORT_blacklist(cfg, &blacklist_check, NULL); | 1086 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL); |
1085 | ats = GNUNET_ATS_connectivity_init(cfg); | 1087 | ats = GNUNET_ATS_connectivity_init (cfg); |
1086 | pi = GNUNET_PEERINFO_connect(cfg); | 1088 | pi = GNUNET_PEERINFO_connect (cfg); |
1087 | handle = GNUNET_CORE_connect(cfg, | 1089 | handle = GNUNET_CORE_connect (cfg, |
1088 | NULL, | 1090 | NULL, |
1089 | &core_init, | 1091 | &core_init, |
1090 | &connect_notify, | 1092 | &connect_notify, |
1091 | &disconnect_notify, | 1093 | &disconnect_notify, |
1092 | handlers); | 1094 | handlers); |
1093 | GNUNET_SCHEDULER_add_shutdown(&cleaning_task, NULL); | 1095 | GNUNET_SCHEDULER_add_shutdown (&cleaning_task, NULL); |
1094 | if (NULL == handle) | 1096 | if (NULL == handle) |
1095 | { | 1097 | { |
1096 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 1098 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1097 | _("Failed to connect to `%s' service.\n"), | 1099 | _ ("Failed to connect to `%s' service.\n"), |
1098 | "core"); | 1100 | "core"); |
1099 | GNUNET_SCHEDULER_shutdown(); | 1101 | GNUNET_SCHEDULER_shutdown (); |
1100 | return; | 1102 | return; |
1101 | } | 1103 | } |
1102 | } | 1104 | } |
1103 | 1105 | ||
1104 | 1106 | ||
@@ -1110,26 +1112,26 @@ run(void *cls, | |||
1110 | * @return 0 ok, 1 on error | 1112 | * @return 0 ok, 1 on error |
1111 | */ | 1113 | */ |
1112 | int | 1114 | int |
1113 | main(int argc, char *const *argv) | 1115 | main (int argc, char *const *argv) |
1114 | { | 1116 | { |
1115 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 1117 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
1116 | GNUNET_GETOPT_OPTION_END | 1118 | GNUNET_GETOPT_OPTION_END |
1117 | }; | 1119 | }; |
1118 | int ret; | 1120 | int ret; |
1119 | 1121 | ||
1120 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) | 1122 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
1121 | return 2; | 1123 | return 2; |
1122 | 1124 | ||
1123 | ret = (GNUNET_OK == GNUNET_PROGRAM_run(argc, | 1125 | ret = (GNUNET_OK == GNUNET_PROGRAM_run (argc, |
1124 | argv, | 1126 | argv, |
1125 | "gnunet-daemon-topology", | 1127 | "gnunet-daemon-topology", |
1126 | _("GNUnet topology control"), | 1128 | _ ("GNUnet topology control"), |
1127 | options, | 1129 | options, |
1128 | &run, | 1130 | &run, |
1129 | NULL)) | 1131 | NULL)) |
1130 | ? 0 | 1132 | ? 0 |
1131 | : 1; | 1133 | : 1; |
1132 | GNUNET_free((void *)argv); | 1134 | GNUNET_free ((void *) argv); |
1133 | return ret; | 1135 | return ret; |
1134 | } | 1136 | } |
1135 | 1137 | ||
@@ -1140,11 +1142,11 @@ main(int argc, char *const *argv) | |||
1140 | /** | 1142 | /** |
1141 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | 1143 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. |
1142 | */ | 1144 | */ |
1143 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init() | 1145 | void __attribute__ ((constructor)) GNUNET_ARM_memory_init () |
1144 | { | 1146 | { |
1145 | mallopt(M_TRIM_THRESHOLD, 4 * 1024); | 1147 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); |
1146 | mallopt(M_TOP_PAD, 1 * 1024); | 1148 | mallopt (M_TOP_PAD, 1 * 1024); |
1147 | malloc_trim(0); | 1149 | malloc_trim (0); |
1148 | } | 1150 | } |
1149 | #endif | 1151 | #endif |
1150 | 1152 | ||
diff --git a/src/topology/test_gnunet_daemon_topology.c b/src/topology/test_gnunet_daemon_topology.c index 9e2db4f66..f6d0e2c2b 100644 --- a/src/topology/test_gnunet_daemon_topology.c +++ b/src/topology/test_gnunet_daemon_topology.c | |||
@@ -41,7 +41,7 @@ | |||
41 | /** | 41 | /** |
42 | * How long until we give up on connecting the peers? | 42 | * How long until we give up on connecting the peers? |
43 | */ | 43 | */ |
44 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60) | 44 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) |
45 | 45 | ||
46 | /* | 46 | /* |
47 | * Store manual connections. | 47 | * Store manual connections. |
@@ -71,7 +71,8 @@ static struct GNUNET_SCHEDULER_Task *timeout_tid; | |||
71 | /* | 71 | /* |
72 | * Peer context for every testbed peer. | 72 | * Peer context for every testbed peer. |
73 | */ | 73 | */ |
74 | struct peerctx { | 74 | struct peerctx |
75 | { | ||
75 | int index; | 76 | int index; |
76 | struct GNUNET_STATISTICS_Handle *statistics; | 77 | struct GNUNET_STATISTICS_Handle *statistics; |
77 | int connections; | 78 | int connections; |
@@ -80,32 +81,32 @@ struct peerctx { | |||
80 | 81 | ||
81 | 82 | ||
82 | static void | 83 | static void |
83 | shutdown_task(void *cls) | 84 | shutdown_task (void *cls) |
84 | { | 85 | { |
85 | unsigned int i; | 86 | unsigned int i; |
86 | 87 | ||
87 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 88 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
88 | "Shutting down testcase\n"); | 89 | "Shutting down testcase\n"); |
89 | 90 | ||
90 | for (i = 0; i < NUM_PEERS; i++) | 91 | for (i = 0; i < NUM_PEERS; i++) |
91 | { | 92 | { |
92 | if (NULL != op[i]) | 93 | if (NULL != op[i]) |
93 | GNUNET_TESTBED_operation_done(op[i]); | 94 | GNUNET_TESTBED_operation_done (op[i]); |
94 | } | 95 | } |
95 | 96 | ||
96 | if (NULL != timeout_tid) | 97 | if (NULL != timeout_tid) |
97 | GNUNET_SCHEDULER_cancel(timeout_tid); | 98 | GNUNET_SCHEDULER_cancel (timeout_tid); |
98 | } | 99 | } |
99 | 100 | ||
100 | static void | 101 | static void |
101 | timeout_task(void *cls) | 102 | timeout_task (void *cls) |
102 | { | 103 | { |
103 | timeout_tid = NULL; | 104 | timeout_tid = NULL; |
104 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | 105 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
105 | "Testcase timeout\n"); | 106 | "Testcase timeout\n"); |
106 | 107 | ||
107 | result = GNUNET_SYSERR; | 108 | result = GNUNET_SYSERR; |
108 | GNUNET_SCHEDULER_shutdown(); | 109 | GNUNET_SCHEDULER_shutdown (); |
109 | } | 110 | } |
110 | 111 | ||
111 | /* | 112 | /* |
@@ -113,174 +114,174 @@ timeout_task(void *cls) | |||
113 | * peers to a peer changes. | 114 | * peers to a peer changes. |
114 | */ | 115 | */ |
115 | int | 116 | int |
116 | statistics_iterator(void *cls, | 117 | statistics_iterator (void *cls, |
117 | const char *subsystem, | 118 | const char *subsystem, |
118 | const char *name, | 119 | const char *name, |
119 | uint64_t value, | 120 | uint64_t value, |
120 | int is_persistent) | 121 | int is_persistent) |
121 | { | 122 | { |
122 | struct peerctx *p_ctx = (struct peerctx*)cls; | 123 | struct peerctx *p_ctx = (struct peerctx*) cls; |
123 | 124 | ||
124 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 125 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
125 | "Peer %d: %s = %llu\n", | 126 | "Peer %d: %s = %llu\n", |
126 | p_ctx->index, | 127 | p_ctx->index, |
127 | name, | 128 | name, |
128 | (unsigned long long)value); | 129 | (unsigned long long) value); |
129 | 130 | ||
130 | if (p_ctx->connections < value) | 131 | if (p_ctx->connections < value) |
131 | p_ctx->connections = value; | 132 | p_ctx->connections = value; |
132 | 133 | ||
133 | if (THRESHOLD <= value && GNUNET_NO == p_ctx->reported) | 134 | if ((THRESHOLD <= value)&&(GNUNET_NO == p_ctx->reported)) |
135 | { | ||
136 | p_ctx->reported = GNUNET_YES; | ||
137 | checked_peers++; | ||
138 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
139 | "Peer %d successfully connected to at least %d peers once.\n", | ||
140 | p_ctx->index, | ||
141 | THRESHOLD); | ||
142 | |||
143 | if (checked_peers == NUM_PEERS) | ||
134 | { | 144 | { |
135 | p_ctx->reported = GNUNET_YES; | 145 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
136 | checked_peers++; | 146 | "Test OK: All peers have connected to %d peers once.\n", |
137 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 147 | THRESHOLD); |
138 | "Peer %d successfully connected to at least %d peers once.\n", | 148 | result = GNUNET_YES; |
139 | p_ctx->index, | 149 | GNUNET_SCHEDULER_shutdown (); |
140 | THRESHOLD); | ||
141 | |||
142 | if (checked_peers == NUM_PEERS) | ||
143 | { | ||
144 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
145 | "Test OK: All peers have connected to %d peers once.\n", | ||
146 | THRESHOLD); | ||
147 | result = GNUNET_YES; | ||
148 | GNUNET_SCHEDULER_shutdown(); | ||
149 | } | ||
150 | } | 150 | } |
151 | } | ||
151 | 152 | ||
152 | return GNUNET_YES; | 153 | return GNUNET_YES; |
153 | } | 154 | } |
154 | 155 | ||
155 | static void * | 156 | static void * |
156 | ca_statistics(void *cls, | 157 | ca_statistics (void *cls, |
157 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 158 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
158 | { | 159 | { |
159 | return GNUNET_STATISTICS_create("topology", cfg); | 160 | return GNUNET_STATISTICS_create ("topology", cfg); |
160 | } | 161 | } |
161 | 162 | ||
162 | 163 | ||
163 | void | 164 | void |
164 | da_statistics(void *cls, | 165 | da_statistics (void *cls, |
165 | void *op_result) | 166 | void *op_result) |
166 | { | 167 | { |
167 | struct peerctx *p_ctx = (struct peerctx *)cls; | 168 | struct peerctx *p_ctx = (struct peerctx *) cls; |
168 | 169 | ||
169 | GNUNET_break(GNUNET_OK == GNUNET_STATISTICS_watch_cancel | 170 | GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel |
170 | (p_ctx->statistics, "topology", "# peers connected", | 171 | (p_ctx->statistics, "topology", "# peers connected", |
171 | statistics_iterator, p_ctx)); | 172 | statistics_iterator, p_ctx)); |
172 | 173 | ||
173 | GNUNET_STATISTICS_destroy(p_ctx->statistics, GNUNET_NO); | 174 | GNUNET_STATISTICS_destroy (p_ctx->statistics, GNUNET_NO); |
174 | p_ctx->statistics = NULL; | 175 | p_ctx->statistics = NULL; |
175 | 176 | ||
176 | GNUNET_free(p_ctx); | 177 | GNUNET_free (p_ctx); |
177 | } | 178 | } |
178 | 179 | ||
179 | 180 | ||
180 | static void | 181 | static void |
181 | service_connect_complete(void *cls, | 182 | service_connect_complete (void *cls, |
182 | struct GNUNET_TESTBED_Operation *op, | 183 | struct GNUNET_TESTBED_Operation *op, |
183 | void *ca_result, | 184 | void *ca_result, |
184 | const char *emsg) | 185 | const char *emsg) |
185 | { | 186 | { |
186 | int ret; | 187 | int ret; |
187 | struct peerctx *p_ctx = (struct peerctx*)cls; | 188 | struct peerctx *p_ctx = (struct peerctx*) cls; |
188 | 189 | ||
189 | if (NULL == ca_result) | 190 | if (NULL == ca_result) |
190 | GNUNET_SCHEDULER_shutdown(); | 191 | GNUNET_SCHEDULER_shutdown (); |
191 | 192 | ||
192 | p_ctx->statistics = ca_result; | 193 | p_ctx->statistics = ca_result; |
193 | 194 | ||
194 | ret = GNUNET_STATISTICS_watch(ca_result, | 195 | ret = GNUNET_STATISTICS_watch (ca_result, |
195 | "topology", | 196 | "topology", |
196 | "# peers connected", | 197 | "# peers connected", |
197 | statistics_iterator, | 198 | statistics_iterator, |
198 | p_ctx); | 199 | p_ctx); |
199 | 200 | ||
200 | if (GNUNET_NO == ret) | 201 | if (GNUNET_NO == ret) |
201 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 202 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
202 | "call to GNUNET_STATISTICS_watch() failed\n"); | 203 | "call to GNUNET_STATISTICS_watch() failed\n"); |
203 | } | 204 | } |
204 | 205 | ||
205 | static void | 206 | static void |
206 | notify_connect_complete(void *cls, | 207 | notify_connect_complete (void *cls, |
207 | struct GNUNET_TESTBED_Operation *op, | 208 | struct GNUNET_TESTBED_Operation *op, |
208 | const char *emsg) | 209 | const char *emsg) |
209 | { | 210 | { |
210 | GNUNET_TESTBED_operation_done(op); | 211 | GNUNET_TESTBED_operation_done (op); |
211 | if (NULL != emsg) | 212 | if (NULL != emsg) |
212 | { | 213 | { |
213 | fprintf(stderr, "Failed to connect two peers: %s\n", emsg); | 214 | fprintf (stderr, "Failed to connect two peers: %s\n", emsg); |
214 | result = GNUNET_SYSERR; | 215 | result = GNUNET_SYSERR; |
215 | GNUNET_SCHEDULER_shutdown(); | 216 | GNUNET_SCHEDULER_shutdown (); |
216 | return; | 217 | return; |
217 | } | 218 | } |
218 | connect_left--; | 219 | connect_left--; |
219 | } | 220 | } |
220 | 221 | ||
221 | static void | 222 | static void |
222 | do_connect(void *cls, | 223 | do_connect (void *cls, |
223 | struct GNUNET_TESTBED_RunHandle *h, | 224 | struct GNUNET_TESTBED_RunHandle *h, |
224 | unsigned int num_peers, | 225 | unsigned int num_peers, |
225 | struct GNUNET_TESTBED_Peer **peers, | 226 | struct GNUNET_TESTBED_Peer **peers, |
226 | unsigned int links_succeeded, | 227 | unsigned int links_succeeded, |
227 | unsigned int links_failed) | 228 | unsigned int links_failed) |
228 | { | 229 | { |
229 | unsigned int i; | 230 | unsigned int i; |
230 | struct peerctx *p_ctx; | 231 | struct peerctx *p_ctx; |
231 | 232 | ||
232 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | 233 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
233 | "Threshold is set to %d.\n", | 234 | "Threshold is set to %d.\n", |
234 | THRESHOLD); | 235 | THRESHOLD); |
235 | 236 | ||
236 | GNUNET_assert(NUM_PEERS == num_peers); | 237 | GNUNET_assert (NUM_PEERS == num_peers); |
237 | 238 | ||
238 | for (i = 0; i < NUM_PEERS; i++) | 239 | for (i = 0; i < NUM_PEERS; i++) |
240 | { | ||
241 | p_ctx = GNUNET_new (struct peerctx); | ||
242 | p_ctx->index = i; | ||
243 | p_ctx->connections = 0; | ||
244 | p_ctx->reported = GNUNET_NO; | ||
245 | |||
246 | if (i < NUM_PEERS - 1) | ||
239 | { | 247 | { |
240 | p_ctx = GNUNET_new(struct peerctx); | 248 | connect_left++; |
241 | p_ctx->index = i; | 249 | GNUNET_TESTBED_overlay_connect (NULL, |
242 | p_ctx->connections = 0; | 250 | ¬ify_connect_complete, NULL, |
243 | p_ctx->reported = GNUNET_NO; | 251 | peers[i], peers[i + 1]); |
244 | |||
245 | if (i < NUM_PEERS - 1) | ||
246 | { | ||
247 | connect_left++; | ||
248 | GNUNET_TESTBED_overlay_connect(NULL, | ||
249 | ¬ify_connect_complete, NULL, | ||
250 | peers[i], peers[i + 1]); | ||
251 | } | ||
252 | |||
253 | op[i] = | ||
254 | GNUNET_TESTBED_service_connect(cls, | ||
255 | peers[i], | ||
256 | "statistics", | ||
257 | service_connect_complete, | ||
258 | p_ctx, /* cls of completion cb */ | ||
259 | ca_statistics, /* connect adapter */ | ||
260 | da_statistics, /* disconnect adapter */ | ||
261 | p_ctx); | ||
262 | } | 252 | } |
263 | 253 | ||
264 | GNUNET_SCHEDULER_add_shutdown(&shutdown_task, NULL); | 254 | op[i] = |
255 | GNUNET_TESTBED_service_connect (cls, | ||
256 | peers[i], | ||
257 | "statistics", | ||
258 | service_connect_complete, | ||
259 | p_ctx, /* cls of completion cb */ | ||
260 | ca_statistics, /* connect adapter */ | ||
261 | da_statistics, /* disconnect adapter */ | ||
262 | p_ctx); | ||
263 | } | ||
264 | |||
265 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | ||
265 | timeout_tid = | 266 | timeout_tid = |
266 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, | 267 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, |
267 | &timeout_task, | 268 | &timeout_task, |
268 | NULL); | 269 | NULL); |
269 | } | 270 | } |
270 | 271 | ||
271 | 272 | ||
272 | int | 273 | int |
273 | main(int argc, char *argv[]) | 274 | main (int argc, char *argv[]) |
274 | { | 275 | { |
275 | result = GNUNET_SYSERR; | 276 | result = GNUNET_SYSERR; |
276 | checked_peers = 0; | 277 | checked_peers = 0; |
277 | 278 | ||
278 | (void)GNUNET_TESTBED_test_run("test-gnunet-daemon-topology", | 279 | (void) GNUNET_TESTBED_test_run ("test-gnunet-daemon-topology", |
279 | "test_gnunet_daemon_topology_data.conf", | 280 | "test_gnunet_daemon_topology_data.conf", |
280 | NUM_PEERS, | 281 | NUM_PEERS, |
281 | 0, NULL, NULL, | 282 | 0, NULL, NULL, |
282 | &do_connect, NULL); | 283 | &do_connect, NULL); |
283 | GNUNET_DISK_directory_remove("/tmp/test-gnunet-topology"); | 284 | GNUNET_DISK_directory_remove ("/tmp/test-gnunet-topology"); |
284 | 285 | ||
285 | return (GNUNET_OK != result) ? 1 : 0; | 286 | return (GNUNET_OK != result) ? 1 : 0; |
286 | } | 287 | } |