aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/bio.c197
-rw-r--r--src/util/client.c209
-rw-r--r--src/util/common_allocation.c3
-rw-r--r--src/util/common_logging.c35
-rw-r--r--src/util/configuration.c73
-rw-r--r--src/util/connection.c576
-rw-r--r--src/util/container_bloomfilter.c68
-rw-r--r--src/util/container_heap.c11
-rw-r--r--src/util/container_meta_data.c11
-rw-r--r--src/util/container_multihashmap.c18
-rw-r--r--src/util/container_slist.c24
-rw-r--r--src/util/crypto_aes.c14
-rw-r--r--src/util/crypto_hash.c66
-rw-r--r--src/util/crypto_ksk.c58
-rw-r--r--src/util/crypto_random.c15
-rw-r--r--src/util/crypto_rsa.c64
-rw-r--r--src/util/disk.c246
-rw-r--r--src/util/disk.h52
-rw-r--r--src/util/gnunet-service-resolver.c14
-rw-r--r--src/util/network.c1600
-rw-r--r--src/util/os_installation.c5
-rw-r--r--src/util/os_priority.c204
-rw-r--r--src/util/peer.c39
-rw-r--r--src/util/perf_crypto_hash.c3
-rw-r--r--src/util/program.c8
-rw-r--r--src/util/pseudonym.c29
-rw-r--r--src/util/resolver_api.c236
-rw-r--r--src/util/scheduler.c158
-rw-r--r--src/util/server.c136
-rw-r--r--src/util/service.c48
-rw-r--r--src/util/strings.c8
-rw-r--r--src/util/test_bio.c189
-rw-r--r--src/util/test_client.c25
-rw-r--r--src/util/test_configuration.c2
-rw-r--r--src/util/test_connection.c47
-rw-r--r--src/util/test_connection_addressing.c57
-rw-r--r--src/util/test_connection_receive_cancel.c31
-rw-r--r--src/util/test_connection_timeout.c23
-rw-r--r--src/util/test_connection_timeout_no_connect.c9
-rw-r--r--src/util/test_connection_transmit_cancel.c8
-rw-r--r--src/util/test_container_bloomfilter.c3
-rw-r--r--src/util/test_container_slist.c15
-rw-r--r--src/util/test_crypto_aes.c4
-rw-r--r--src/util/test_crypto_ksk.c4
-rw-r--r--src/util/test_crypto_rsa.c11
-rw-r--r--src/util/test_disk.c28
-rw-r--r--src/util/test_getopt.c6
-rw-r--r--src/util/test_os_load.c16
-rw-r--r--src/util/test_resolver_api.c9
-rw-r--r--src/util/test_scheduler.c33
-rw-r--r--src/util/test_server.c3
-rw-r--r--src/util/test_server_disconnect.c3
-rw-r--r--src/util/test_server_with_client.c3
-rw-r--r--src/util/test_service.c19
-rw-r--r--src/util/time.c34
-rw-r--r--src/util/winproc.c4
56 files changed, 2387 insertions, 2427 deletions
diff --git a/src/util/bio.c b/src/util/bio.c
index ea9415d63..860e9e63e 100644
--- a/src/util/bio.c
+++ b/src/util/bio.c
@@ -57,9 +57,9 @@ GNUNET_BIO_read_open (const char *fn)
57 struct GNUNET_BIO_ReadHandle *h; 57 struct GNUNET_BIO_ReadHandle *h;
58 58
59 fd = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, 59 fd = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ,
60 GNUNET_DISK_PERM_NONE); 60 GNUNET_DISK_PERM_NONE);
61 h = GNUNET_malloc (sizeof(struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE); 61 h = GNUNET_malloc (sizeof (struct GNUNET_BIO_ReadHandle) + BIO_BUFFER_SIZE);
62 h->buffer = (char*) &h[1]; 62 h->buffer = (char *) &h[1];
63 h->size = BIO_BUFFER_SIZE; 63 h->size = BIO_BUFFER_SIZE;
64 h->fd = fd; 64 h->fd = fd;
65 return h; 65 return h;
@@ -74,8 +74,8 @@ GNUNET_BIO_read_open (const char *fn)
74 * @param emsg set to the error message 74 * @param emsg set to the error message
75 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 75 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
76 */ 76 */
77int GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, 77int
78 char **emsg) 78GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg)
79{ 79{
80 *emsg = h->emsg; 80 *emsg = h->emsg;
81 GNUNET_DISK_file_close (h->fd); 81 GNUNET_DISK_file_close (h->fd);
@@ -93,10 +93,9 @@ int GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h,
93 * @param len the number of bytes to read 93 * @param len the number of bytes to read
94 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 94 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
95 */ 95 */
96int GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, 96int
97 const char *what, 97GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
98 void *result, 98 const char *what, void *result, size_t len)
99 size_t len)
100{ 99{
101 char *dst = result; 100 char *dst = result;
102 size_t min; 101 size_t min;
@@ -119,32 +118,28 @@ int GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
119 pos += min; 118 pos += min;
120 } 119 }
121 if (pos == len) 120 if (pos == len)
122 return GNUNET_OK; /* done! */ 121 return GNUNET_OK; /* done! */
123 GNUNET_assert (h->have == h->pos); 122 GNUNET_assert (h->have == h->pos);
124 /* fill buffer */ 123 /* fill buffer */
125 ret = GNUNET_DISK_file_read (h->fd, 124 ret = GNUNET_DISK_file_read (h->fd, h->buffer, h->size);
126 h->buffer,
127 h->size);
128 if (ret == -1) 125 if (ret == -1)
129 { 126 {
130 GNUNET_asprintf (&h->emsg, 127 GNUNET_asprintf (&h->emsg,
131 _("Error reading `%s': %s"), 128 _("Error reading `%s': %s"),
132 what, 129 what, STRERROR (errno));
133 STRERROR (errno)); 130 return GNUNET_SYSERR;
134 return GNUNET_SYSERR;
135 } 131 }
136 if (ret == 0) 132 if (ret == 0)
137 { 133 {
138 GNUNET_asprintf (&h->emsg, 134 GNUNET_asprintf (&h->emsg,
139 _("Error reading `%s': %s"), 135 _("Error reading `%s': %s"),
140 what, 136 what, _("End of file"));
141 _("End of file")); 137 return GNUNET_SYSERR;
142 return GNUNET_SYSERR; 138 }
143 }
144 h->pos = 0; 139 h->pos = 0;
145 h->have = ret; 140 h->have = ret;
146 } 141 }
147 while (pos < len); /* should always be true */ 142 while (pos < len); /* should always be true */
148 return GNUNET_OK; 143 return GNUNET_OK;
149} 144}
150 145
@@ -159,10 +154,9 @@ int GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h,
159 * @param maxLen maximum allowed length for the string 154 * @param maxLen maximum allowed length for the string
160 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 155 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
161 */ 156 */
162int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, 157int
163 const char *what, 158GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
164 char **result, 159 const char *what, char **result, size_t maxLen)
165 size_t maxLen)
166{ 160{
167 char *buf; 161 char *buf;
168 uint32_t big; 162 uint32_t big;
@@ -177,14 +171,14 @@ int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
177 if (big > maxLen) 171 if (big > maxLen)
178 { 172 {
179 GNUNET_asprintf (&h->emsg, 173 GNUNET_asprintf (&h->emsg,
180 _("String `%s' longer than allowed (%u > %u)"), 174 _("String `%s' longer than allowed (%u > %u)"),
181 what, 175 what, big, maxLen);
182 big,
183 maxLen);
184 return GNUNET_SYSERR; 176 return GNUNET_SYSERR;
185 } 177 }
186 buf = GNUNET_malloc (big); 178 buf = GNUNET_malloc (big);
187 buf[--big] = '\0'; 179 buf[--big] = '\0';
180 if (big == 0)
181 return GNUNET_OK;
188 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big)) 182 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, big))
189 { 183 {
190 GNUNET_free (buf); 184 GNUNET_free (buf);
@@ -203,30 +197,27 @@ int GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h,
203 * @param result the buffer to store a pointer to the (allocated) metadata 197 * @param result the buffer to store a pointer to the (allocated) metadata
204 * @return GNUNET_OK on success, GNUNET_SYSERR on failure 198 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
205 */ 199 */
206int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h, 200int
207 const char *what, 201GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
208 struct GNUNET_CONTAINER_MetaData **result) 202 const char *what,
203 struct GNUNET_CONTAINER_MetaData **result)
209{ 204{
210 uint32_t size; 205 uint32_t size;
211 char *buf; 206 char *buf;
212 struct GNUNET_CONTAINER_MetaData *meta; 207 struct GNUNET_CONTAINER_MetaData *meta;
213 208
214 if (GNUNET_BIO_read_int32__ (h, 209 if (GNUNET_BIO_read_int32__ (h, what, (int32_t *) & size) != GNUNET_OK)
215 what,
216 (int32_t*) &size) != GNUNET_OK)
217 return GNUNET_SYSERR; 210 return GNUNET_SYSERR;
218 if (size > MAX_META_DATA) 211 if (size > MAX_META_DATA)
219 { 212 {
220 GNUNET_asprintf (&h->emsg, 213 GNUNET_asprintf (&h->emsg,
221 _("Serialized metadata `%s' larger than allowed (%u > %u)"), 214 _
222 what, 215 ("Serialized metadata `%s' larger than allowed (%u > %u)"),
223 size, 216 what, size, MAX_META_DATA);
224 MAX_META_DATA);
225 return GNUNET_SYSERR; 217 return GNUNET_SYSERR;
226 } 218 }
227 buf = GNUNET_malloc (size); 219 buf = GNUNET_malloc (size);
228 if (GNUNET_OK != 220 if (GNUNET_OK != GNUNET_BIO_read (h, what, buf, size))
229 GNUNET_BIO_read (h, what, buf, size))
230 { 221 {
231 GNUNET_free (buf); 222 GNUNET_free (buf);
232 return GNUNET_SYSERR; 223 return GNUNET_SYSERR;
@@ -236,8 +227,7 @@ int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
236 { 227 {
237 GNUNET_free (buf); 228 GNUNET_free (buf);
238 GNUNET_asprintf (&h->emsg, 229 GNUNET_asprintf (&h->emsg,
239 _("Metadata `%s' failed to deserialize"), 230 _("Metadata `%s' failed to deserialize"), what);
240 what);
241 return GNUNET_SYSERR; 231 return GNUNET_SYSERR;
242 } 232 }
243 GNUNET_free (buf); 233 GNUNET_free (buf);
@@ -253,18 +243,14 @@ int GNUNET_BIO_read_meta_data (struct GNUNET_BIO_ReadHandle *h,
253 * @param what describes what is being read (for error message creation) 243 * @param what describes what is being read (for error message creation)
254 * @param i address of 32-bit integer to read 244 * @param i address of 32-bit integer to read
255 * @return GNUNET_OK on success, GNUNET_SYSERR on error 245 * @return GNUNET_OK on success, GNUNET_SYSERR on error
256 */ 246 */
257int GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h, 247int
258 const char *what, 248GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
259 int32_t *i) 249 const char *what, int32_t * i)
260{ 250{
261 int32_t big; 251 int32_t big;
262 252
263 if (GNUNET_OK != 253 if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof (int32_t)))
264 GNUNET_BIO_read (h,
265 what,
266 &big,
267 sizeof (int32_t)))
268 return GNUNET_SYSERR; 254 return GNUNET_SYSERR;
269 *i = ntohl (big); 255 *i = ntohl (big);
270 return GNUNET_OK; 256 return GNUNET_OK;
@@ -278,18 +264,14 @@ int GNUNET_BIO_read_int32__ (struct GNUNET_BIO_ReadHandle *h,
278 * @param what describes what is being read (for error message creation) 264 * @param what describes what is being read (for error message creation)
279 * @param i address of 64-bit integer to read 265 * @param i address of 64-bit integer to read
280 * @return GNUNET_OK on success, GNUNET_SYSERR on error 266 * @return GNUNET_OK on success, GNUNET_SYSERR on error
281 */ 267 */
282int GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h, 268int
283 const char *what, 269GNUNET_BIO_read_int64__ (struct GNUNET_BIO_ReadHandle *h,
284 int64_t *i) 270 const char *what, int64_t * i)
285{ 271{
286 int64_t big; 272 int64_t big;
287 273
288 if (GNUNET_OK != 274 if (GNUNET_OK != GNUNET_BIO_read (h, what, &big, sizeof (int64_t)))
289 GNUNET_BIO_read (h,
290 what,
291 &big,
292 sizeof (int64_t)))
293 return GNUNET_SYSERR; 275 return GNUNET_SYSERR;
294 *i = GNUNET_ntohll (big); 276 *i = GNUNET_ntohll (big);
295 return GNUNET_OK; 277 return GNUNET_OK;
@@ -314,16 +296,21 @@ struct GNUNET_BIO_WriteHandle
314 * @param fn file name to be opened 296 * @param fn file name to be opened
315 * @return IO handle on success, NULL on error 297 * @return IO handle on success, NULL on error
316 */ 298 */
317struct GNUNET_BIO_WriteHandle *GNUNET_BIO_write_open (const char *fn) 299struct GNUNET_BIO_WriteHandle *
300GNUNET_BIO_write_open (const char *fn)
318{ 301{
319 struct GNUNET_DISK_FileHandle *fd; 302 struct GNUNET_DISK_FileHandle *fd;
320 struct GNUNET_BIO_WriteHandle *h; 303 struct GNUNET_BIO_WriteHandle *h;
321 304
322 fd = GNUNET_DISK_file_open (fn, 305 fd = GNUNET_DISK_file_open (fn,
323 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_TRUNCATE | GNUNET_DISK_OPEN_CREATE, 306 GNUNET_DISK_OPEN_WRITE |
324 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); 307 GNUNET_DISK_OPEN_TRUNCATE |
325 h = GNUNET_malloc (sizeof(struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE); 308 GNUNET_DISK_OPEN_CREATE,
326 h->buffer = (char*) &h[1]; 309 GNUNET_DISK_PERM_USER_READ |
310 GNUNET_DISK_PERM_USER_WRITE);
311 h =
312 GNUNET_malloc (sizeof (struct GNUNET_BIO_WriteHandle) + BIO_BUFFER_SIZE);
313 h->buffer = (char *) &h[1];
327 h->size = BIO_BUFFER_SIZE; 314 h->size = BIO_BUFFER_SIZE;
328 h->fd = fd; 315 h->fd = fd;
329 316
@@ -337,7 +324,8 @@ struct GNUNET_BIO_WriteHandle *GNUNET_BIO_write_open (const char *fn)
337 * @param h file handle 324 * @param h file handle
338 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 325 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
339 */ 326 */
340int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h) 327int
328GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
341{ 329{
342 ssize_t wrt; 330 ssize_t wrt;
343 int ret; 331 int ret;
@@ -350,9 +338,9 @@ int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
350 { 338 {
351 wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have); 339 wrt = GNUNET_DISK_file_write (h->fd, h->buffer, h->have);
352 if (wrt == h->have) 340 if (wrt == h->have)
353 ret = GNUNET_OK; 341 ret = GNUNET_OK;
354 else 342 else
355 ret = GNUNET_SYSERR; 343 ret = GNUNET_SYSERR;
356 GNUNET_DISK_file_close (h->fd); 344 GNUNET_DISK_file_close (h->fd);
357 } 345 }
358 GNUNET_free (h); 346 GNUNET_free (h);
@@ -368,9 +356,9 @@ int GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h)
368 * @param n number of bytes to write 356 * @param n number of bytes to write
369 * @return GNUNET_OK on success, GNUNET_SYSERR on error 357 * @return GNUNET_OK on success, GNUNET_SYSERR on error
370 */ 358 */
371int GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, 359int
372 const void *buffer, 360GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
373 size_t n) 361 const void *buffer, size_t n)
374{ 362{
375 const char *src = buffer; 363 const char *src = buffer;
376 size_t min; 364 size_t min;
@@ -390,18 +378,18 @@ int GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
390 pos += min; 378 pos += min;
391 h->have += min; 379 h->have += min;
392 if (pos == n) 380 if (pos == n)
393 return GNUNET_OK; /* done */ 381 return GNUNET_OK; /* done */
394 GNUNET_assert (h->have == h->size); 382 GNUNET_assert (h->have == h->size);
395 ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->size); 383 ret = GNUNET_DISK_file_write (h->fd, h->buffer, h->size);
396 if (ret != h->size) 384 if (ret != h->size)
397 { 385 {
398 GNUNET_DISK_file_close (h->fd); 386 GNUNET_DISK_file_close (h->fd);
399 h->fd = NULL; 387 h->fd = NULL;
400 return GNUNET_SYSERR; /* error */ 388 return GNUNET_SYSERR; /* error */
401 } 389 }
402 h->have = 0; 390 h->have = 0;
403 } 391 }
404 while (pos < n); /* should always be true */ 392 while (pos < n); /* should always be true */
405 return GNUNET_OK; 393 return GNUNET_OK;
406} 394}
407 395
@@ -413,14 +401,13 @@ int GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h,
413 * @param s string to write (can be NULL) 401 * @param s string to write (can be NULL)
414 * @return GNUNET_OK on success, GNUNET_SYSERR on error 402 * @return GNUNET_OK on success, GNUNET_SYSERR on error
415 */ 403 */
416int GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, 404int
417 const char *s) 405GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *s)
418{ 406{
419 uint32_t slen; 407 uint32_t slen;
420 408
421 slen = (uint32_t) ((s == NULL) ? 0 : strlen(s) + 1); 409 slen = (uint32_t) ((s == NULL) ? 0 : strlen (s) + 1);
422 if (GNUNET_OK != 410 if (GNUNET_OK != GNUNET_BIO_write_int32 (h, slen))
423 GNUNET_BIO_write_int32 (h, slen))
424 return GNUNET_SYSERR; 411 return GNUNET_SYSERR;
425 if (0 != slen) 412 if (0 != slen)
426 return GNUNET_BIO_write (h, s, slen - 1); 413 return GNUNET_BIO_write (h, s, slen - 1);
@@ -435,28 +422,28 @@ int GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h,
435 * @param m metadata to write 422 * @param m metadata to write
436 * @return GNUNET_OK on success, GNUNET_SYSERR on error 423 * @return GNUNET_OK on success, GNUNET_SYSERR on error
437 */ 424 */
438int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h, 425int
439 const struct GNUNET_CONTAINER_MetaData *m) 426GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
427 const struct GNUNET_CONTAINER_MetaData *m)
440{ 428{
441 unsigned int size; 429 unsigned int size;
442 char *buf; 430 char *buf;
443 431
444 size = GNUNET_CONTAINER_meta_data_get_serialized_size (m, 432 size = GNUNET_CONTAINER_meta_data_get_serialized_size (m,
445 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL 433 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL
446 | 434 |
447 GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS); 435 GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS);
448 if (size > MAX_META_DATA) 436 if (size > MAX_META_DATA)
449 size = MAX_META_DATA; 437 size = MAX_META_DATA;
450 buf = GNUNET_malloc (size); 438 buf = GNUNET_malloc (size);
451 GNUNET_CONTAINER_meta_data_serialize (m, 439 GNUNET_CONTAINER_meta_data_serialize (m,
452 buf, 440 buf,
453 size, 441 size,
454 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART | 442 GNUNET_CONTAINER_META_DATA_SERIALIZE_PART
455 GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS); 443 |
456 if ( (GNUNET_OK != 444 GNUNET_CONTAINER_META_DATA_SERIALIZE_NO_COMPRESS);
457 GNUNET_BIO_write_int32 (h, size)) || 445 if ((GNUNET_OK != GNUNET_BIO_write_int32 (h, size))
458 (GNUNET_OK != 446 || (GNUNET_OK != GNUNET_BIO_write (h, buf, size)))
459 GNUNET_BIO_write (h, buf, size)) )
460 { 447 {
461 GNUNET_free (buf); 448 GNUNET_free (buf);
462 return GNUNET_SYSERR; 449 return GNUNET_SYSERR;
@@ -472,9 +459,9 @@ int GNUNET_BIO_write_meta_data (struct GNUNET_BIO_WriteHandle *h,
472 * @param h hande to open file 459 * @param h hande to open file
473 * @param i address of 32-bit integer to write 460 * @param i address of 32-bit integer to write
474 * @return GNUNET_OK on success, GNUNET_SYSERR on error 461 * @return GNUNET_OK on success, GNUNET_SYSERR on error
475 */ 462 */
476int GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, 463int
477 int32_t i) 464GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, int32_t i)
478{ 465{
479 int32_t big; 466 int32_t big;
480 big = htonl (i); 467 big = htonl (i);
@@ -488,9 +475,9 @@ int GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h,
488 * @param h hande to open file 475 * @param h hande to open file
489 * @param i address of 64-bit integer to write 476 * @param i address of 64-bit integer to write
490 * @return GNUNET_OK on success, GNUNET_SYSERR on error 477 * @return GNUNET_OK on success, GNUNET_SYSERR on error
491 */ 478 */
492int GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, 479int
493 int64_t i) 480GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, int64_t i)
494{ 481{
495 int64_t big; 482 int64_t big;
496 big = GNUNET_htonll (i); 483 big = GNUNET_htonll (i);
diff --git a/src/util/client.c b/src/util/client.c
index 8915c2f65..60aa6f101 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -48,7 +48,7 @@
48/** 48/**
49 * Handle for a transmission request. 49 * Handle for a transmission request.
50 */ 50 */
51struct GNUNET_CLIENT_TransmitHandle 51struct GNUNET_CLIENT_TransmitHandle
52{ 52{
53 /** 53 /**
54 * Connection state. 54 * Connection state.
@@ -128,7 +128,7 @@ struct GNUNET_CLIENT_Connection
128 * Our configuration. 128 * Our configuration.
129 */ 129 */
130 struct GNUNET_CONFIGURATION_Handle *cfg; 130 struct GNUNET_CONFIGURATION_Handle *cfg;
131 131
132 /** 132 /**
133 * Name of the service we interact with. 133 * Name of the service we interact with.
134 */ 134 */
@@ -198,8 +198,8 @@ struct GNUNET_CLIENT_Connection
198 198
199static struct GNUNET_CONNECTION_Handle * 199static struct GNUNET_CONNECTION_Handle *
200do_connect (struct GNUNET_SCHEDULER_Handle *sched, 200do_connect (struct GNUNET_SCHEDULER_Handle *sched,
201 const char *service_name, 201 const char *service_name,
202 const struct GNUNET_CONFIGURATION_Handle *cfg) 202 const struct GNUNET_CONFIGURATION_Handle *cfg)
203{ 203{
204 struct GNUNET_CONNECTION_Handle *sock; 204 struct GNUNET_CONNECTION_Handle *sock;
205 char *hostname; 205 char *hostname;
@@ -217,7 +217,8 @@ do_connect (struct GNUNET_SCHEDULER_Handle *sched,
217 "HOSTNAME", &hostname))) 217 "HOSTNAME", &hostname)))
218 { 218 {
219 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 219 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
220 _("Could not determine valid hostname and port for service `%s' from configuration.\n"), 220 _
221 ("Could not determine valid hostname and port for service `%s' from configuration.\n"),
221 service_name); 222 service_name);
222 return NULL; 223 return NULL;
223 } 224 }
@@ -226,14 +227,14 @@ do_connect (struct GNUNET_SCHEDULER_Handle *sched,
226 GNUNET_free (hostname); 227 GNUNET_free (hostname);
227 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 228 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
228 _("Need a non-empty hostname for service `%s'.\n"), 229 _("Need a non-empty hostname for service `%s'.\n"),
229 service_name); 230 service_name);
230 return NULL; 231 return NULL;
231 } 232 }
232 sock = GNUNET_CONNECTION_create_from_connect (sched, 233 sock = GNUNET_CONNECTION_create_from_connect (sched,
233 cfg, 234 cfg,
234 hostname, 235 hostname,
235 port, 236 port,
236 GNUNET_SERVER_MAX_MESSAGE_SIZE); 237 GNUNET_SERVER_MAX_MESSAGE_SIZE);
237 GNUNET_free (hostname); 238 GNUNET_free (hostname);
238 return sock; 239 return sock;
239} 240}
@@ -277,7 +278,7 @@ finish_cleanup (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
277 struct GNUNET_CLIENT_Connection *sock = cls; 278 struct GNUNET_CLIENT_Connection *sock = cls;
278 279
279 if (sock->th != NULL) 280 if (sock->th != NULL)
280 GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th); 281 GNUNET_CLIENT_notify_transmit_ready_cancel (sock->th);
281 GNUNET_array_grow (sock->received_buf, sock->received_size, 0); 282 GNUNET_array_grow (sock->received_buf, sock->received_size, 0);
282 GNUNET_free (sock->service_name); 283 GNUNET_free (sock->service_name);
283 GNUNET_CONFIGURATION_destroy (sock->cfg); 284 GNUNET_CONFIGURATION_destroy (sock->cfg);
@@ -307,10 +308,10 @@ GNUNET_CLIENT_disconnect (struct GNUNET_CLIENT_Connection *sock)
307 sock->in_receive = GNUNET_SYSERR; 308 sock->in_receive = GNUNET_SYSERR;
308 else 309 else
309 GNUNET_SCHEDULER_add_after (sock->sched, 310 GNUNET_SCHEDULER_add_after (sock->sched,
310 GNUNET_YES, 311 GNUNET_YES,
311 GNUNET_SCHEDULER_PRIORITY_KEEP, 312 GNUNET_SCHEDULER_PRIORITY_KEEP,
312 GNUNET_SCHEDULER_NO_TASK, 313 GNUNET_SCHEDULER_NO_TASK,
313 &finish_cleanup, sock); 314 &finish_cleanup, sock);
314} 315}
315 316
316 317
@@ -322,8 +323,8 @@ check_complete (struct GNUNET_CLIENT_Connection *conn)
322{ 323{
323 if ((conn->received_pos >= sizeof (struct GNUNET_MessageHeader)) && 324 if ((conn->received_pos >= sizeof (struct GNUNET_MessageHeader)) &&
324 (conn->received_pos >= 325 (conn->received_pos >=
325 ntohs (((const struct GNUNET_MessageHeader *) conn-> 326 ntohs (((const struct GNUNET_MessageHeader *) conn->received_buf)->
326 received_buf)->size))) 327 size)))
327 conn->msg_complete = GNUNET_YES; 328 conn->msg_complete = GNUNET_YES;
328} 329}
329 330
@@ -352,11 +353,10 @@ receive_helper (void *cls,
352 GNUNET_assert (conn->msg_complete == GNUNET_NO); 353 GNUNET_assert (conn->msg_complete == GNUNET_NO);
353 if (GNUNET_SYSERR == conn->in_receive) 354 if (GNUNET_SYSERR == conn->in_receive)
354 GNUNET_SCHEDULER_add_after (conn->sched, 355 GNUNET_SCHEDULER_add_after (conn->sched,
355 GNUNET_YES, 356 GNUNET_YES,
356 GNUNET_SCHEDULER_PRIORITY_KEEP, 357 GNUNET_SCHEDULER_PRIORITY_KEEP,
357 GNUNET_SCHEDULER_NO_TASK, 358 GNUNET_SCHEDULER_NO_TASK,
358 &finish_cleanup, 359 &finish_cleanup, conn);
359 conn);
360 conn->in_receive = GNUNET_NO; 360 conn->in_receive = GNUNET_NO;
361 if ((available == 0) || (conn->sock == NULL) || (errCode != 0)) 361 if ((available == 0) || (conn->sock == NULL) || (errCode != 0))
362 { 362 {
@@ -403,28 +403,28 @@ receive_task (void *scls, const struct GNUNET_SCHEDULER_TaskContext *tc)
403{ 403{
404 struct GNUNET_CLIENT_Connection *sock = scls; 404 struct GNUNET_CLIENT_Connection *sock = scls;
405 GNUNET_CLIENT_MessageHandler handler = sock->receiver_handler; 405 GNUNET_CLIENT_MessageHandler handler = sock->receiver_handler;
406 const struct GNUNET_MessageHeader *cmsg = (const struct GNUNET_MessageHeader *) sock->received_buf; 406 const struct GNUNET_MessageHeader *cmsg =
407 (const struct GNUNET_MessageHeader *) sock->received_buf;
407 void *cls = sock->receiver_handler_cls; 408 void *cls = sock->receiver_handler_cls;
408 uint16_t msize = ntohs (cmsg->size); 409 uint16_t msize = ntohs (cmsg->size);
409 char mbuf[msize]; 410 char mbuf[msize];
410 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader*) mbuf; 411 struct GNUNET_MessageHeader *msg = (struct GNUNET_MessageHeader *) mbuf;
411 412
412 if (GNUNET_SYSERR == sock->in_receive) 413 if (GNUNET_SYSERR == sock->in_receive)
413 GNUNET_SCHEDULER_add_after (sock->sched, 414 GNUNET_SCHEDULER_add_after (sock->sched,
414 GNUNET_YES, 415 GNUNET_YES,
415 GNUNET_SCHEDULER_PRIORITY_KEEP, 416 GNUNET_SCHEDULER_PRIORITY_KEEP,
416 GNUNET_SCHEDULER_NO_TASK, 417 GNUNET_SCHEDULER_NO_TASK,
417 &finish_cleanup, 418 &finish_cleanup, sock);
418 sock);
419 sock->in_receive = GNUNET_NO; 419 sock->in_receive = GNUNET_NO;
420 GNUNET_assert (GNUNET_YES == sock->msg_complete); 420 GNUNET_assert (GNUNET_YES == sock->msg_complete);
421 GNUNET_assert (sock->received_pos >= msize); 421 GNUNET_assert (sock->received_pos >= msize);
422 memcpy (msg, cmsg, msize); 422 memcpy (msg, cmsg, msize);
423 memmove (sock->received_buf, 423 memmove (sock->received_buf,
424 &sock->received_buf[msize], sock->received_pos - msize); 424 &sock->received_buf[msize], sock->received_pos - msize);
425 sock->received_pos -= msize; 425 sock->received_pos -= msize;
426 sock->msg_complete = GNUNET_NO; 426 sock->msg_complete = GNUNET_NO;
427 sock->receiver_handler = NULL; 427 sock->receiver_handler = NULL;
428 check_complete (sock); 428 check_complete (sock);
429 if (handler != NULL) 429 if (handler != NULL)
430 handler (cls, msg); 430 handler (cls, msg);
@@ -457,15 +457,14 @@ GNUNET_CLIENT_receive (struct GNUNET_CLIENT_Connection *sock,
457 sock->in_receive = GNUNET_YES; 457 sock->in_receive = GNUNET_YES;
458 if (GNUNET_YES == sock->msg_complete) 458 if (GNUNET_YES == sock->msg_complete)
459 GNUNET_SCHEDULER_add_after (sock->sched, 459 GNUNET_SCHEDULER_add_after (sock->sched,
460 GNUNET_YES, 460 GNUNET_YES,
461 GNUNET_SCHEDULER_PRIORITY_KEEP, 461 GNUNET_SCHEDULER_PRIORITY_KEEP,
462 GNUNET_SCHEDULER_NO_TASK, 462 GNUNET_SCHEDULER_NO_TASK,
463 &receive_task, sock); 463 &receive_task, sock);
464 else 464 else
465 GNUNET_CONNECTION_receive (sock->sock, 465 GNUNET_CONNECTION_receive (sock->sock,
466 GNUNET_SERVER_MAX_MESSAGE_SIZE, 466 GNUNET_SERVER_MAX_MESSAGE_SIZE,
467 timeout, 467 timeout, &receive_helper, sock);
468 &receive_helper, sock);
469} 468}
470 469
471 470
@@ -488,8 +487,8 @@ write_shutdown (void *cls, size_t size, void *buf)
488 if (size < sizeof (struct GNUNET_MessageHeader)) 487 if (size < sizeof (struct GNUNET_MessageHeader))
489 { 488 {
490 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 489 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
491 _("Failed to transmit shutdown request to client.\n")); 490 _("Failed to transmit shutdown request to client.\n"));
492 return 0; /* client disconnected */ 491 return 0; /* client disconnected */
493 } 492 }
494 msg = (struct GNUNET_MessageHeader *) buf; 493 msg = (struct GNUNET_MessageHeader *) buf;
495 msg->type = htons (GNUNET_MESSAGE_TYPE_SHUTDOWN); 494 msg->type = htons (GNUNET_MESSAGE_TYPE_SHUTDOWN);
@@ -508,9 +507,10 @@ void
508GNUNET_CLIENT_service_shutdown (struct GNUNET_CLIENT_Connection *sock) 507GNUNET_CLIENT_service_shutdown (struct GNUNET_CLIENT_Connection *sock)
509{ 508{
510 GNUNET_CONNECTION_notify_transmit_ready (sock->sock, 509 GNUNET_CONNECTION_notify_transmit_ready (sock->sock,
511 sizeof (struct GNUNET_MessageHeader), 510 sizeof (struct
512 GNUNET_TIME_UNIT_FOREVER_REL, 511 GNUNET_MessageHeader),
513 &write_shutdown, sock); 512 GNUNET_TIME_UNIT_FOREVER_REL,
513 &write_shutdown, sock);
514} 514}
515 515
516 516
@@ -624,9 +624,9 @@ GNUNET_CLIENT_service_test (struct GNUNET_SCHEDULER_Handle *sched,
624 conn->test_cb_cls = task_cls; 624 conn->test_cb_cls = task_cls;
625 if (NULL == 625 if (NULL ==
626 GNUNET_CONNECTION_notify_transmit_ready (conn->sock, 626 GNUNET_CONNECTION_notify_transmit_ready (conn->sock,
627 sizeof (struct 627 sizeof (struct
628 GNUNET_MessageHeader), 628 GNUNET_MessageHeader),
629 timeout, &write_test, NULL)) 629 timeout, &write_test, NULL))
630 { 630 {
631 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 631 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
632 _("Failure to transmit request to service `%s'\n"), 632 _("Failure to transmit request to service `%s'\n"),
@@ -649,10 +649,7 @@ GNUNET_CLIENT_service_test (struct GNUNET_SCHEDULER_Handle *sched,
649 * @param buf where to write them 649 * @param buf where to write them
650 * @return number of bytes written to buf 650 * @return number of bytes written to buf
651 */ 651 */
652static size_t 652static size_t client_notify (void *cls, size_t size, void *buf);
653client_notify (void *cls,
654 size_t size,
655 void *buf);
656 653
657 654
658 655
@@ -665,22 +662,22 @@ client_notify (void *cls,
665 */ 662 */
666static void 663static void
667client_delayed_retry (void *cls, 664client_delayed_retry (void *cls,
668 const struct GNUNET_SCHEDULER_TaskContext *tc) 665 const struct GNUNET_SCHEDULER_TaskContext *tc)
669{ 666{
670 struct GNUNET_CLIENT_TransmitHandle *th = cls; 667 struct GNUNET_CLIENT_TransmitHandle *th = cls;
671 668
672 th->task = GNUNET_SCHEDULER_NO_TASK; 669 th->task = GNUNET_SCHEDULER_NO_TASK;
673 th->th = GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock, 670 th->th = GNUNET_CONNECTION_notify_transmit_ready (th->sock->sock,
674 th->size, 671 th->size,
675 GNUNET_TIME_absolute_get_remaining (th->timeout), 672 GNUNET_TIME_absolute_get_remaining
676 &client_notify, 673 (th->timeout),
677 th); 674 &client_notify, th);
678 if (th->th == NULL) 675 if (th->th == NULL)
679 { 676 {
680 GNUNET_break (0); 677 GNUNET_break (0);
681 th->notify (th->notify_cls, 0, NULL); 678 th->notify (th->notify_cls, 0, NULL);
682 GNUNET_free (th); 679 GNUNET_free (th);
683 return; 680 return;
684 } 681 }
685} 682}
686 683
@@ -696,51 +693,42 @@ client_delayed_retry (void *cls,
696 * @return number of bytes written to buf 693 * @return number of bytes written to buf
697 */ 694 */
698static size_t 695static size_t
699client_notify (void *cls, 696client_notify (void *cls, size_t size, void *buf)
700 size_t size,
701 void *buf)
702{ 697{
703 struct GNUNET_CLIENT_TransmitHandle *th = cls; 698 struct GNUNET_CLIENT_TransmitHandle *th = cls;
704 size_t ret; 699 size_t ret;
705 struct GNUNET_TIME_Relative delay; 700 struct GNUNET_TIME_Relative delay;
706 701
707 th->th = NULL; 702 th->th = NULL;
708 th->sock->th = NULL; 703 th->sock->th = NULL;
709 if (buf == NULL) 704 if (buf == NULL)
710 { 705 {
711 delay = GNUNET_TIME_absolute_get_remaining (th->timeout); 706 delay = GNUNET_TIME_absolute_get_remaining (th->timeout);
712 delay.value /= 2; 707 delay.value /= 2;
713 if ( (GNUNET_YES != th->auto_retry) || 708 if ((GNUNET_YES != th->auto_retry) ||
714 (0 == --th->attempts_left) || 709 (0 == --th->attempts_left) || (delay.value < 1))
715 (delay.value < 1) ) 710 {
716 { 711 GNUNET_break (0 == th->notify (th->notify_cls, 0, NULL));
717 GNUNET_break (0 == th->notify (th->notify_cls, 712 GNUNET_free (th);
718 0, 713 return 0;
719 NULL)); 714 }
720 GNUNET_free (th);
721 return 0;
722 }
723 /* auto-retry */ 715 /* auto-retry */
724 GNUNET_CONNECTION_destroy (th->sock->sock); 716 GNUNET_CONNECTION_destroy (th->sock->sock);
725 th->sock->sock = do_connect (th->sock->sched, 717 th->sock->sock = do_connect (th->sock->sched,
726 th->sock->service_name, 718 th->sock->service_name, th->sock->cfg);
727 th->sock->cfg);
728 GNUNET_assert (NULL != th->sock->sock); 719 GNUNET_assert (NULL != th->sock->sock);
729 delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS); 720 delay = GNUNET_TIME_relative_min (delay, GNUNET_TIME_UNIT_SECONDS);
730 th->task = GNUNET_SCHEDULER_add_delayed (th->sock->sched, 721 th->task = GNUNET_SCHEDULER_add_delayed (th->sock->sched,
731 GNUNET_NO, 722 GNUNET_NO,
732 GNUNET_SCHEDULER_PRIORITY_KEEP, 723 GNUNET_SCHEDULER_PRIORITY_KEEP,
733 GNUNET_SCHEDULER_NO_TASK, 724 GNUNET_SCHEDULER_NO_TASK,
734 delay, 725 delay,
735 &client_delayed_retry, 726 &client_delayed_retry, th);
736 th);
737 th->sock->th = th; 727 th->sock->th = th;
738 return 0; 728 return 0;
739 } 729 }
740 GNUNET_assert (size >= th->size); 730 GNUNET_assert (size >= th->size);
741 ret = th->notify (th->notify_cls, 731 ret = th->notify (th->notify_cls, size, buf);
742 size,
743 buf);
744 GNUNET_free (th); 732 GNUNET_free (th);
745 return ret; 733 return ret;
746} 734}
@@ -769,7 +757,7 @@ struct GNUNET_CLIENT_TransmitHandle *
769GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock, 757GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock,
770 size_t size, 758 size_t size,
771 struct GNUNET_TIME_Relative timeout, 759 struct GNUNET_TIME_Relative timeout,
772 int auto_retry, 760 int auto_retry,
773 GNUNET_CONNECTION_TransmitReadyNotify 761 GNUNET_CONNECTION_TransmitReadyNotify
774 notify, void *notify_cls) 762 notify, void *notify_cls)
775{ 763{
@@ -786,10 +774,9 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock,
786 th->notify_cls = notify_cls; 774 th->notify_cls = notify_cls;
787 th->attempts_left = MAX_ATTEMPTS; 775 th->attempts_left = MAX_ATTEMPTS;
788 th->th = GNUNET_CONNECTION_notify_transmit_ready (sock->sock, 776 th->th = GNUNET_CONNECTION_notify_transmit_ready (sock->sock,
789 size, 777 size,
790 timeout, 778 timeout,
791 &client_notify, 779 &client_notify, th);
792 th);
793 if (NULL == th->th) 780 if (NULL == th->th)
794 { 781 {
795 GNUNET_break (0); 782 GNUNET_break (0);
@@ -807,13 +794,13 @@ GNUNET_CLIENT_notify_transmit_ready (struct GNUNET_CLIENT_Connection *sock,
807 * @param th handle from the original request. 794 * @param th handle from the original request.
808 */ 795 */
809void 796void
810GNUNET_CLIENT_notify_transmit_ready_cancel (struct GNUNET_CLIENT_TransmitHandle *th) 797GNUNET_CLIENT_notify_transmit_ready_cancel (struct
798 GNUNET_CLIENT_TransmitHandle *th)
811{ 799{
812 if (th->task != GNUNET_SCHEDULER_NO_TASK) 800 if (th->task != GNUNET_SCHEDULER_NO_TASK)
813 { 801 {
814 GNUNET_break (NULL == th->th); 802 GNUNET_break (NULL == th->th);
815 GNUNET_SCHEDULER_cancel (th->sock->sched, 803 GNUNET_SCHEDULER_cancel (th->sock->sched, th->task);
816 th->task);
817 } 804 }
818 else 805 else
819 { 806 {
@@ -871,14 +858,12 @@ struct TARCtx
871 * @return number of bytes written to buf 858 * @return number of bytes written to buf
872 */ 859 */
873static size_t 860static size_t
874transmit_for_response (void *cls, 861transmit_for_response (void *cls, size_t size, void *buf)
875 size_t size,
876 void *buf)
877{ 862{
878 struct TARCtx *tc = cls; 863 struct TARCtx *tc = cls;
879 uint16_t msize; 864 uint16_t msize;
880 865
881 msize = ntohs(tc->hdr->size); 866 msize = ntohs (tc->hdr->size);
882 if (NULL == buf) 867 if (NULL == buf)
883 { 868 {
884 tc->rn (tc->rn_cls, NULL); 869 tc->rn (tc->rn_cls, NULL);
@@ -888,9 +873,9 @@ transmit_for_response (void *cls,
888 GNUNET_assert (size >= msize); 873 GNUNET_assert (size >= msize);
889 memcpy (buf, tc->hdr, msize); 874 memcpy (buf, tc->hdr, msize);
890 GNUNET_CLIENT_receive (tc->sock, 875 GNUNET_CLIENT_receive (tc->sock,
891 tc->rn, 876 tc->rn,
892 tc->rn_cls, 877 tc->rn_cls,
893 GNUNET_TIME_absolute_get_remaining (tc->timeout)); 878 GNUNET_TIME_absolute_get_remaining (tc->timeout));
894 GNUNET_free (tc); 879 GNUNET_free (tc);
895 return msize; 880 return msize;
896} 881}
@@ -918,32 +903,34 @@ transmit_for_response (void *cls,
918 * is already pending 903 * is already pending
919 */ 904 */
920int 905int
921GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection *sock, 906GNUNET_CLIENT_transmit_and_get_response (struct GNUNET_CLIENT_Connection
922 const struct GNUNET_MessageHeader *hdr, 907 *sock,
923 struct GNUNET_TIME_Relative timeout, 908 const struct GNUNET_MessageHeader
924 int auto_retry, 909 *hdr,
925 GNUNET_CLIENT_MessageHandler rn, 910 struct GNUNET_TIME_Relative timeout,
926 void *rn_cls) 911 int auto_retry,
912 GNUNET_CLIENT_MessageHandler rn,
913 void *rn_cls)
927{ 914{
928 struct TARCtx *tc; 915 struct TARCtx *tc;
929 uint16_t msize; 916 uint16_t msize;
930 917
931 if (NULL != sock->th) 918 if (NULL != sock->th)
932 return GNUNET_SYSERR; 919 return GNUNET_SYSERR;
933 msize = ntohs(hdr->size); 920 msize = ntohs (hdr->size);
934 tc = GNUNET_malloc(sizeof (struct TARCtx) + msize); 921 tc = GNUNET_malloc (sizeof (struct TARCtx) + msize);
935 tc->sock = sock; 922 tc->sock = sock;
936 tc->hdr = (const struct GNUNET_MessageHeader*) &tc[1]; 923 tc->hdr = (const struct GNUNET_MessageHeader *) &tc[1];
937 memcpy (&tc[1], hdr, msize); 924 memcpy (&tc[1], hdr, msize);
938 tc->timeout = GNUNET_TIME_relative_to_absolute (timeout); 925 tc->timeout = GNUNET_TIME_relative_to_absolute (timeout);
939 tc->rn = rn; 926 tc->rn = rn;
940 tc->rn_cls = rn_cls; 927 tc->rn_cls = rn_cls;
941 if (NULL == GNUNET_CLIENT_notify_transmit_ready (sock, 928 if (NULL == GNUNET_CLIENT_notify_transmit_ready (sock,
942 msize, 929 msize,
943 timeout, 930 timeout,
944 auto_retry, 931 auto_retry,
945 &transmit_for_response, 932 &transmit_for_response,
946 tc)) 933 tc))
947 { 934 {
948 GNUNET_break (0); 935 GNUNET_break (0);
949 GNUNET_free (tc); 936 GNUNET_free (tc);
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 2f78c98f6..748ca620d 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -48,8 +48,7 @@ GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
48{ 48{
49 /* As a security precaution, we generally do not allow very large 49 /* As a security precaution, we generally do not allow very large
50 allocations using the default 'GNUNET_malloc' macro */ 50 allocations using the default 'GNUNET_malloc' macro */
51 GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, 51 GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber);
52 linenumber);
53 return GNUNET_xmalloc_unchecked_ (size, filename, linenumber); 52 return GNUNET_xmalloc_unchecked_ (size, filename, linenumber);
54} 53}
55 54
diff --git a/src/util/common_logging.c b/src/util/common_logging.c
index 96cfcd85c..5af499341 100644
--- a/src/util/common_logging.c
+++ b/src/util/common_logging.c
@@ -442,7 +442,7 @@ GNUNET_error_type_to_string (enum GNUNET_ErrorType kind)
442 * @return string form; will be overwritten by next call to GNUNET_h2s. 442 * @return string form; will be overwritten by next call to GNUNET_h2s.
443 */ 443 */
444const char * 444const char *
445GNUNET_h2s (const GNUNET_HashCode *hc) 445GNUNET_h2s (const GNUNET_HashCode * hc)
446{ 446{
447 static struct GNUNET_CRYPTO_HashAsciiEncoded ret; 447 static struct GNUNET_CRYPTO_HashAsciiEncoded ret;
448 GNUNET_CRYPTO_hash_to_enc (hc, &ret); 448 GNUNET_CRYPTO_hash_to_enc (hc, &ret);
@@ -481,12 +481,12 @@ GNUNET_i2s (const struct GNUNET_PeerIdentity *pid)
481 * @return nicely formatted string for the address 481 * @return nicely formatted string for the address
482 * will be overwritten by next call to GNUNET_a2s. 482 * will be overwritten by next call to GNUNET_a2s.
483 */ 483 */
484const char *GNUNET_a2s (const struct sockaddr *addr, 484const char *
485 socklen_t addrlen) 485GNUNET_a2s (const struct sockaddr *addr, socklen_t addrlen)
486{ 486{
487 static char buf[INET6_ADDRSTRLEN+8]; 487 static char buf[INET6_ADDRSTRLEN + 8];
488 static char b2[6]; 488 static char b2[6];
489 const struct sockaddr_in * v4; 489 const struct sockaddr_in *v4;
490 const struct sockaddr_in6 *v6; 490 const struct sockaddr_in6 *v6;
491 491
492 if (addr == NULL) 492 if (addr == NULL)
@@ -494,24 +494,24 @@ const char *GNUNET_a2s (const struct sockaddr *addr,
494 switch (addr->sa_family) 494 switch (addr->sa_family)
495 { 495 {
496 case AF_INET: 496 case AF_INET:
497 v4 = (const struct sockaddr_in*)addr; 497 v4 = (const struct sockaddr_in *) addr;
498 inet_ntop(AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN); 498 inet_ntop (AF_INET, &v4->sin_addr, buf, INET_ADDRSTRLEN);
499 if (0 == ntohs(v4->sin_port)) 499 if (0 == ntohs (v4->sin_port))
500 return buf; 500 return buf;
501 strcat (buf, ":"); 501 strcat (buf, ":");
502 sprintf (b2, "%u", ntohs(v4->sin_port)); 502 sprintf (b2, "%u", ntohs (v4->sin_port));
503 strcat (buf, b2); 503 strcat (buf, b2);
504 return buf; 504 return buf;
505 case AF_INET6: 505 case AF_INET6:
506 v6 = (const struct sockaddr_in6*)addr; 506 v6 = (const struct sockaddr_in6 *) addr;
507 buf[0] = '['; 507 buf[0] = '[';
508 inet_ntop(AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN); 508 inet_ntop (AF_INET6, &v6->sin6_addr, &buf[1], INET6_ADDRSTRLEN);
509 if (0 == ntohs(v6->sin6_port)) 509 if (0 == ntohs (v6->sin6_port))
510 return &buf[1]; 510 return &buf[1];
511 strcat (buf, "]:"); 511 strcat (buf, "]:");
512 sprintf (b2, "%u", ntohs(v6->sin6_port)); 512 sprintf (b2, "%u", ntohs (v6->sin6_port));
513 strcat (buf, b2); 513 strcat (buf, b2);
514 return buf; 514 return buf;
515 default: 515 default:
516 return _("invalid address"); 516 return _("invalid address");
517 } 517 }
@@ -521,8 +521,7 @@ const char *GNUNET_a2s (const struct sockaddr *addr,
521/** 521/**
522 * Initializer 522 * Initializer
523 */ 523 */
524void __attribute__ ((constructor)) 524void __attribute__ ((constructor)) GNUNET_util_cl_init ()
525GNUNET_util_cl_init()
526{ 525{
527 GNUNET_stderr = stderr; 526 GNUNET_stderr = stderr;
528} 527}
diff --git a/src/util/configuration.c b/src/util/configuration.c
index 2541a79f4..c14645067 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -344,10 +344,10 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
344 GNUNET_assert (0 == fclose (fp)); 344 GNUNET_assert (0 == fclose (fp));
345 if (error != 0) 345 if (error != 0)
346 { 346 {
347 cfg->dirty = GNUNET_SYSERR; /* last write failed */ 347 cfg->dirty = GNUNET_SYSERR; /* last write failed */
348 return GNUNET_SYSERR; 348 return GNUNET_SYSERR;
349 } 349 }
350 cfg->dirty = GNUNET_NO; /* last write succeeded */ 350 cfg->dirty = GNUNET_NO; /* last write succeeded */
351 return GNUNET_OK; 351 return GNUNET_OK;
352} 352}
353 353
@@ -359,9 +359,10 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
359 * @param iter function to call on each option 359 * @param iter function to call on each option
360 * @param iter_cls closure for iter 360 * @param iter_cls closure for iter
361 */ 361 */
362void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg, 362void
363 GNUNET_CONFIGURATION_Iterator iter, 363GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg,
364 void *iter_cls) 364 GNUNET_CONFIGURATION_Iterator iter,
365 void *iter_cls)
365{ 366{
366 struct ConfigSection *spos; 367 struct ConfigSection *spos;
367 struct ConfigEntry *epos; 368 struct ConfigEntry *epos;
@@ -371,10 +372,10 @@ void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg
371 { 372 {
372 epos = spos->entries; 373 epos = spos->entries;
373 while (epos != NULL) 374 while (epos != NULL)
374 { 375 {
375 iter (iter_cls, spos->name, epos->key, epos->val); 376 iter (iter_cls, spos->name, epos->key, epos->val);
376 epos = epos->next; 377 epos = epos->next;
377 } 378 }
378 spos = spos->next; 379 spos = spos->next;
379 } 380 }
380} 381}
@@ -391,9 +392,7 @@ void GNUNET_CONFIGURATION_iterate (const struct GNUNET_CONFIGURATION_Handle *cfg
391 */ 392 */
392static void 393static void
393copy_entry (void *cls, 394copy_entry (void *cls,
394 const char *section, 395 const char *section, const char *option, const char *value)
395 const char *option,
396 const char *value)
397{ 396{
398 struct GNUNET_CONFIGURATION_Handle *dst = cls; 397 struct GNUNET_CONFIGURATION_Handle *dst = cls;
399 GNUNET_CONFIGURATION_set_value_string (dst, section, option, value); 398 GNUNET_CONFIGURATION_set_value_string (dst, section, option, value);
@@ -425,7 +424,8 @@ GNUNET_CONFIGURATION_dup (const struct GNUNET_CONFIGURATION_Handle *cfg)
425 * @return matching entry, NULL if not found 424 * @return matching entry, NULL if not found
426 */ 425 */
427static struct ConfigSection * 426static struct ConfigSection *
428findSection (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section) 427findSection (const struct GNUNET_CONFIGURATION_Handle *cfg,
428 const char *section)
429{ 429{
430 struct ConfigSection *pos; 430 struct ConfigSection *pos;
431 431
@@ -531,8 +531,9 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle
531 * @return GNUNET_OK on success, GNUNET_SYSERR on error 531 * @return GNUNET_OK on success, GNUNET_SYSERR on error
532 */ 532 */
533int 533int
534GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle 534GNUNET_CONFIGURATION_get_value_number (const struct
535 *cfg, const char *section, 535 GNUNET_CONFIGURATION_Handle *cfg,
536 const char *section,
536 const char *option, 537 const char *option,
537 unsigned long long *number) 538 unsigned long long *number)
538{ 539{
@@ -558,17 +559,14 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
558 */ 559 */
559int 560int
560GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle 561GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
561 *cfg, const char *section, 562 *cfg, const char *section,
562 const char *option, 563 const char *option,
563 struct GNUNET_TIME_Relative *time) 564 struct GNUNET_TIME_Relative *time)
564{ 565{
565 unsigned long long num; 566 unsigned long long num;
566 int ret; 567 int ret;
567 568
568 ret = GNUNET_CONFIGURATION_get_value_number (cfg, 569 ret = GNUNET_CONFIGURATION_get_value_number (cfg, section, option, &num);
569 section,
570 option,
571 &num);
572 if (ret == GNUNET_OK) 570 if (ret == GNUNET_OK)
573 time->value = (uint64_t) num; 571 time->value = (uint64_t) num;
574 return ret; 572 return ret;
@@ -586,8 +584,9 @@ GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle
586 * @return GNUNET_OK on success, GNUNET_SYSERR on error 584 * @return GNUNET_OK on success, GNUNET_SYSERR on error
587 */ 585 */
588int 586int
589GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle 587GNUNET_CONFIGURATION_get_value_string (const struct
590 *cfg, const char *section, 588 GNUNET_CONFIGURATION_Handle *cfg,
589 const char *section,
591 const char *option, char **value) 590 const char *option, char **value)
592{ 591{
593 struct ConfigEntry *e; 592 struct ConfigEntry *e;
@@ -616,8 +615,9 @@ GNUNET_CONFIGURATION_get_value_string (const struct GNUNET_CONFIGURATION_Handle
616 * @return GNUNET_OK on success, GNUNET_SYSERR on error 615 * @return GNUNET_OK on success, GNUNET_SYSERR on error
617 */ 616 */
618int 617int
619GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle 618GNUNET_CONFIGURATION_get_value_choice (const struct
620 *cfg, const char *section, 619 GNUNET_CONFIGURATION_Handle *cfg,
620 const char *section,
621 const char *option, 621 const char *option,
622 const char **choices, 622 const char **choices,
623 const char **value) 623 const char **value)
@@ -656,8 +656,9 @@ GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle
656 * @return GNUNET_YES if so, GNUNET_NO if not. 656 * @return GNUNET_YES if so, GNUNET_NO if not.
657 */ 657 */
658int 658int
659GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, 659GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle
660 const char *section, const char *option) 660 *cfg, const char *section,
661 const char *option)
661{ 662{
662 struct ConfigEntry *e; 663 struct ConfigEntry *e;
663 if ((NULL == (e = findEntry (cfg, section, option))) || (e->val == NULL)) 664 if ((NULL == (e = findEntry (cfg, section, option))) || (e->val == NULL))
@@ -676,8 +677,8 @@ GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg,
676 * @return $-expanded string 677 * @return $-expanded string
677 */ 678 */
678char * 679char *
679GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cfg, 680GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle
680 char *orig) 681 *cfg, char *orig)
681{ 682{
682 int i; 683 int i;
683 char *prefix; 684 char *prefix;
@@ -733,8 +734,9 @@ GNUNET_CONFIGURATION_expand_dollar (const struct GNUNET_CONFIGURATION_Handle *cf
733 * @return GNUNET_OK on success, GNUNET_SYSERR on error 734 * @return GNUNET_OK on success, GNUNET_SYSERR on error
734 */ 735 */
735int 736int
736GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handle 737GNUNET_CONFIGURATION_get_value_filename (const struct
737 *cfg, const char *section, 738 GNUNET_CONFIGURATION_Handle *cfg,
739 const char *section,
738 const char *option, char **value) 740 const char *option, char **value)
739{ 741{
740 int ret; 742 int ret;
@@ -770,8 +772,9 @@ GNUNET_CONFIGURATION_get_value_filename (const struct GNUNET_CONFIGURATION_Handl
770 * @return GNUNET_YES, GNUNET_NO or GNUNET_SYSERR 772 * @return GNUNET_YES, GNUNET_NO or GNUNET_SYSERR
771 */ 773 */
772int 774int
773GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle *cfg, 775GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle
774 const char *section, const char *option) 776 *cfg, const char *section,
777 const char *option)
775{ 778{
776 static const char *yesno[] = { "YES", "NO", NULL }; 779 static const char *yesno[] = { "YES", "NO", NULL };
777 const char *val; 780 const char *val;
@@ -801,7 +804,7 @@ int
801GNUNET_CONFIGURATION_iterate_value_filenames (const struct 804GNUNET_CONFIGURATION_iterate_value_filenames (const struct
802 GNUNET_CONFIGURATION_Handle 805 GNUNET_CONFIGURATION_Handle
803 *cfg, const char *section, 806 *cfg, const char *section,
804 const char *option, 807 const char *option,
805 GNUNET_FileNameCallback cb, 808 GNUNET_FileNameCallback cb,
806 void *cb_cls) 809 void *cb_cls)
807{ 810{
diff --git a/src/util/connection.c b/src/util/connection.c
index 6c2aafb0e..daf0cbf03 100644
--- a/src/util/connection.c
+++ b/src/util/connection.c
@@ -45,32 +45,32 @@
45 * Possible functions to call after connect failed or succeeded. 45 * Possible functions to call after connect failed or succeeded.
46 */ 46 */
47enum ConnectContinuations 47enum ConnectContinuations
48 { 48{
49 /** 49 /**
50 * Call nothing. 50 * Call nothing.
51 */ 51 */
52 COCO_NONE = 0, 52 COCO_NONE = 0,
53 53
54 /** 54 /**
55 * Call "receive_again". 55 * Call "receive_again".
56 */ 56 */
57 COCO_RECEIVE_AGAIN = 1, 57 COCO_RECEIVE_AGAIN = 1,
58 58
59 /** 59 /**
60 * Call "transmit_ready". 60 * Call "transmit_ready".
61 */ 61 */
62 COCO_TRANSMIT_READY = 2, 62 COCO_TRANSMIT_READY = 2,
63 63
64 /** 64 /**
65 * Call "destroy_continuation". 65 * Call "destroy_continuation".
66 */ 66 */
67 COCO_DESTROY_CONTINUATION = 4 67 COCO_DESTROY_CONTINUATION = 4
68 }; 68};
69 69
70 70
71/** 71/**
72 * Transmission handle. There can only be one for each connection. 72 * Transmission handle. There can only be one for each connection.
73 */ 73 */
74struct GNUNET_CONNECTION_TransmitHandle 74struct GNUNET_CONNECTION_TransmitHandle
75{ 75{
76 76
@@ -166,7 +166,7 @@ struct GNUNET_CONNECTION_Handle
166 166
167 /** 167 /**
168 * Configuration to use. 168 * Configuration to use.
169 */ 169 */
170 const struct GNUNET_CONFIGURATION_Handle *cfg; 170 const struct GNUNET_CONFIGURATION_Handle *cfg;
171 171
172 /** 172 /**
@@ -253,12 +253,12 @@ struct GNUNET_CONNECTION_Handle
253 * Timeout for receiving (in absolute time). 253 * Timeout for receiving (in absolute time).
254 */ 254 */
255 struct GNUNET_TIME_Absolute receive_timeout; 255 struct GNUNET_TIME_Absolute receive_timeout;
256 256
257 /** 257 /**
258 * Functions to call after connect failed or succeeded. 258 * Functions to call after connect failed or succeeded.
259 */ 259 */
260 enum ConnectContinuations ccs; 260 enum ConnectContinuations ccs;
261 261
262 /** 262 /**
263 * Maximum number of bytes to read (for receiving). 263 * Maximum number of bytes to read (for receiving).
264 */ 264 */
@@ -293,8 +293,9 @@ struct GNUNET_CONNECTION_Handle
293 */ 293 */
294struct GNUNET_CONNECTION_Handle * 294struct GNUNET_CONNECTION_Handle *
295GNUNET_CONNECTION_create_from_existing (struct GNUNET_SCHEDULER_Handle 295GNUNET_CONNECTION_create_from_existing (struct GNUNET_SCHEDULER_Handle
296 *sched, struct GNUNET_NETWORK_Handle *osSocket, 296 *sched,
297 size_t maxbuf) 297 struct GNUNET_NETWORK_Handle
298 *osSocket, size_t maxbuf)
298{ 299{
299 struct GNUNET_CONNECTION_Handle *ret; 300 struct GNUNET_CONNECTION_Handle *ret;
300 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf); 301 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf);
@@ -320,10 +321,11 @@ GNUNET_CONNECTION_create_from_existing (struct GNUNET_SCHEDULER_Handle
320 */ 321 */
321struct GNUNET_CONNECTION_Handle * 322struct GNUNET_CONNECTION_Handle *
322GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle 323GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle
323 *sched, 324 *sched,
324 GNUNET_CONNECTION_AccessCheck access, 325 GNUNET_CONNECTION_AccessCheck access,
325 void *access_cls, struct GNUNET_NETWORK_Handle *lsock, 326 void *access_cls,
326 size_t maxbuf) 327 struct GNUNET_NETWORK_Handle *lsock,
328 size_t maxbuf)
327{ 329{
328 struct GNUNET_CONNECTION_Handle *ret; 330 struct GNUNET_CONNECTION_Handle *ret;
329 char addr[32]; 331 char addr[32];
@@ -336,7 +338,8 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle
336 void *uaddr; 338 void *uaddr;
337 339
338 addrlen = sizeof (addr); 340 addrlen = sizeof (addr);
339 sock = GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen); 341 sock =
342 GNUNET_NETWORK_socket_accept (lsock, (struct sockaddr *) &addr, &addrlen);
340 if (NULL == sock) 343 if (NULL == sock)
341 { 344 {
342 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept"); 345 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept");
@@ -375,10 +378,11 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle
375 (GNUNET_YES != (aret = access (access_cls, uaddr, addrlen)))) 378 (GNUNET_YES != (aret = access (access_cls, uaddr, addrlen))))
376 { 379 {
377 if (aret == GNUNET_NO) 380 if (aret == GNUNET_NO)
378 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 381 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
379 _("Access denied to `%s'\n"), 382 _("Access denied to `%s'\n"),
380 GNUNET_a2s(uaddr, addrlen)); 383 GNUNET_a2s (uaddr, addrlen));
381 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR)); 384 GNUNET_break (GNUNET_OK ==
385 GNUNET_NETWORK_socket_shutdown (sock, SHUT_RDWR));
382 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock)); 386 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock));
383 GNUNET_free (uaddr); 387 GNUNET_free (uaddr);
384 return NULL; 388 return NULL;
@@ -392,9 +396,8 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle
392 ret->sched = sched; 396 ret->sched = sched;
393#if DEBUG_CONNECTION 397#if DEBUG_CONNECTION
394 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 398 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
395 _("Accepting connection from `%s': %p\n"), 399 _("Accepting connection from `%s': %p\n"),
396 GNUNET_a2s(uaddr, addrlen), 400 GNUNET_a2s (uaddr, addrlen), ret);
397 ret);
398#endif 401#endif
399 return ret; 402 return ret;
400} 403}
@@ -409,7 +412,7 @@ GNUNET_CONNECTION_create_from_accept (struct GNUNET_SCHEDULER_Handle
409 */ 412 */
410int 413int
411GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock, 414GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock,
412 void **addr, size_t * addrlen) 415 void **addr, size_t * addrlen)
413{ 416{
414 if ((sock->addr == NULL) || (sock->addrlen == 0)) 417 if ((sock->addr == NULL) || (sock->addrlen == 0))
415 return GNUNET_NO; 418 return GNUNET_NO;
@@ -428,7 +431,7 @@ GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *sock,
428 */ 431 */
429static void 432static void
430retry_connect_continuation (void *cls, 433retry_connect_continuation (void *cls,
431 const struct GNUNET_SCHEDULER_TaskContext *tc); 434 const struct GNUNET_SCHEDULER_TaskContext *tc);
432 435
433 436
434/** 437/**
@@ -467,9 +470,8 @@ destroy_continuation (void *cls,
467 if (0 != (sock->ccs & COCO_TRANSMIT_READY)) 470 if (0 != (sock->ccs & COCO_TRANSMIT_READY))
468 { 471 {
469#if DEBUG_CONNECTION 472#if DEBUG_CONNECTION
470 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 473 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
471 "Destroy waits for CCS-TR to be done (%p)\n", 474 "Destroy waits for CCS-TR to be done (%p)\n", sock);
472 sock);
473#endif 475#endif
474 sock->ccs |= COCO_DESTROY_CONTINUATION; 476 sock->ccs |= COCO_DESTROY_CONTINUATION;
475 return; 477 return;
@@ -477,9 +479,8 @@ destroy_continuation (void *cls,
477 if (sock->write_task != GNUNET_SCHEDULER_NO_TASK) 479 if (sock->write_task != GNUNET_SCHEDULER_NO_TASK)
478 { 480 {
479#if DEBUG_CONNECTION 481#if DEBUG_CONNECTION
480 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
481 "Destroy waits for write_task to be done (%p)\n", 483 "Destroy waits for write_task to be done (%p)\n", sock);
482 sock);
483#endif 484#endif
484 GNUNET_SCHEDULER_add_after (sock->sched, 485 GNUNET_SCHEDULER_add_after (sock->sched,
485 GNUNET_YES, 486 GNUNET_YES,
@@ -496,9 +497,8 @@ destroy_continuation (void *cls,
496 if (sock->sock != NULL) 497 if (sock->sock != NULL)
497 { 498 {
498#if DEBUG_CONNECTION 499#if DEBUG_CONNECTION
499 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 500 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
500 "Shutting down socket (%p)\n", 501 "Shutting down socket (%p)\n", sock);
501 sock);
502#endif 502#endif
503 GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); 503 GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR);
504 } 504 }
@@ -512,9 +512,7 @@ destroy_continuation (void *cls,
512 return; 512 return;
513 } 513 }
514#if DEBUG_CONNECTION 514#if DEBUG_CONNECTION
515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 515 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Destroy actually runs (%p)!\n", sock);
516 "Destroy actually runs (%p)!\n",
517 sock);
518#endif 516#endif
519 GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK); 517 GNUNET_assert (sock->nth.timeout_task == GNUNET_SCHEDULER_NO_TASK);
520 GNUNET_assert (sock->ccs == COCO_NONE); 518 GNUNET_assert (sock->ccs == COCO_NONE);
@@ -529,8 +527,7 @@ destroy_continuation (void *cls,
529 GNUNET_free_non_null (sock->hostname); 527 GNUNET_free_non_null (sock->hostname);
530#if DEBUG_CONNECTION 528#if DEBUG_CONNECTION
531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 529 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
532 "Freeing memory of connection %p.\n", 530 "Freeing memory of connection %p.\n", sock);
533 sock);
534#endif 531#endif
535 GNUNET_free (sock); 532 GNUNET_free (sock);
536} 533}
@@ -559,10 +556,8 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h)
559{ 556{
560#if DEBUG_CONNECTION 557#if DEBUG_CONNECTION
561 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
562 "Failed to establish TCP connection to `%s:%u', no further addresses to try (%p).\n", 559 "Failed to establish TCP connection to `%s:%u', no further addresses to try (%p).\n",
563 h->hostname, 560 h->hostname, h->port, h);
564 h->port,
565 h);
566#endif 561#endif
567 /* connect failed / timed out */ 562 /* connect failed / timed out */
568 GNUNET_break (h->ap_head == NULL); 563 GNUNET_break (h->ap_head == NULL);
@@ -575,49 +570,46 @@ connect_fail_continuation (struct GNUNET_CONNECTION_Handle *h)
575 if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) 570 if (0 != (h->ccs & COCO_RECEIVE_AGAIN))
576 { 571 {
577#if DEBUG_CONNECTION 572#if DEBUG_CONNECTION
578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
579 "connect_timeout_continuation triggers receive_again (%p)\n", 574 "connect_timeout_continuation triggers receive_again (%p)\n",
580 h); 575 h);
581#endif 576#endif
582 h->ccs -= COCO_RECEIVE_AGAIN; 577 h->ccs -= COCO_RECEIVE_AGAIN;
583 h->read_task = GNUNET_SCHEDULER_add_after (h->sched, 578 h->read_task = GNUNET_SCHEDULER_add_after (h->sched,
584 GNUNET_NO, 579 GNUNET_NO,
585 GNUNET_SCHEDULER_PRIORITY_KEEP, 580 GNUNET_SCHEDULER_PRIORITY_KEEP,
586 GNUNET_SCHEDULER_NO_TASK, 581 GNUNET_SCHEDULER_NO_TASK,
587 &receive_again, 582 &receive_again, h);
588 h);
589 } 583 }
590 if (0 != (h->ccs & COCO_TRANSMIT_READY)) 584 if (0 != (h->ccs & COCO_TRANSMIT_READY))
591 { 585 {
592#if DEBUG_CONNECTION 586#if DEBUG_CONNECTION
593 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
594 "connect_timeout_continuation cancels timeout_task, triggers transmit_ready (%p)\n", 588 "connect_timeout_continuation cancels timeout_task, triggers transmit_ready (%p)\n",
595 h); 589 h);
596#endif 590#endif
597 GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); 591 GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK);
598 GNUNET_SCHEDULER_cancel (h->sched, h->nth.timeout_task); 592 GNUNET_SCHEDULER_cancel (h->sched, h->nth.timeout_task);
599 h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; 593 h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
600 h->ccs -= COCO_TRANSMIT_READY; 594 h->ccs -= COCO_TRANSMIT_READY;
601 h->write_task = GNUNET_SCHEDULER_add_after (h->sched, 595 h->write_task = GNUNET_SCHEDULER_add_after (h->sched,
602 GNUNET_NO, 596 GNUNET_NO,
603 GNUNET_SCHEDULER_PRIORITY_KEEP, 597 GNUNET_SCHEDULER_PRIORITY_KEEP,
604 GNUNET_SCHEDULER_NO_TASK, 598 GNUNET_SCHEDULER_NO_TASK,
605 &transmit_ready, 599 &transmit_ready, h);
606 h);
607 } 600 }
608 if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) 601 if (0 != (h->ccs & COCO_DESTROY_CONTINUATION))
609 { 602 {
610#if DEBUG_CONNECTION 603#if DEBUG_CONNECTION
611 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 604 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
612 "connect_timeout_continuation runs destroy_continuation (%p)\n", 605 "connect_timeout_continuation runs destroy_continuation (%p)\n",
613 h); 606 h);
614#endif 607#endif
615 h->ccs -= COCO_DESTROY_CONTINUATION; 608 h->ccs -= COCO_DESTROY_CONTINUATION;
616 GNUNET_SCHEDULER_add_continuation (h->sched, 609 GNUNET_SCHEDULER_add_continuation (h->sched,
617 GNUNET_NO, 610 GNUNET_NO,
618 &destroy_continuation, 611 &destroy_continuation,
619 h, 612 h, GNUNET_SCHEDULER_REASON_TIMEOUT);
620 GNUNET_SCHEDULER_REASON_TIMEOUT);
621 } 613 }
622} 614}
623 615
@@ -632,58 +624,57 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h)
632{ 624{
633#if DEBUG_CONNECTION 625#if DEBUG_CONNECTION
634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 626 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
635 "Connection to `%s' succeeded! (%p)\n", 627 "Connection to `%s' succeeded! (%p)\n",
636 GNUNET_a2s(h->addr, h->addrlen), 628 GNUNET_a2s (h->addr, h->addrlen), h);
637 h);
638#endif 629#endif
639 /* trigger jobs that waited for the connection */ 630 /* trigger jobs that waited for the connection */
640 if (0 != (h->ccs & COCO_RECEIVE_AGAIN)) 631 if (0 != (h->ccs & COCO_RECEIVE_AGAIN))
641 { 632 {
642#if DEBUG_CONNECTION 633#if DEBUG_CONNECTION
643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
644 "connect_success_continuation runs receive_again (%p)\n", 635 "connect_success_continuation runs receive_again (%p)\n",
645 h); 636 h);
646#endif 637#endif
647 h->ccs -= COCO_RECEIVE_AGAIN; 638 h->ccs -= COCO_RECEIVE_AGAIN;
648 h->read_task = GNUNET_SCHEDULER_add_after (h->sched, 639 h->read_task = GNUNET_SCHEDULER_add_after (h->sched,
649 GNUNET_NO, 640 GNUNET_NO,
650 GNUNET_SCHEDULER_PRIORITY_KEEP, 641 GNUNET_SCHEDULER_PRIORITY_KEEP,
651 GNUNET_SCHEDULER_NO_TASK, 642 GNUNET_SCHEDULER_NO_TASK,
652 &receive_again, 643 &receive_again, h);
653 h);
654 } 644 }
655 if (0 != (h->ccs & COCO_TRANSMIT_READY)) 645 if (0 != (h->ccs & COCO_TRANSMIT_READY))
656 { 646 {
657#if DEBUG_CONNECTION 647#if DEBUG_CONNECTION
658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 648 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
659 "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n", 649 "connect_success_continuation runs transmit_ready, cancels timeout_task (%p)\n",
660 h); 650 h);
661#endif 651#endif
662 GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK); 652 GNUNET_assert (h->nth.timeout_task != GNUNET_SCHEDULER_NO_TASK);
663 GNUNET_SCHEDULER_cancel (h->sched, h->nth.timeout_task); 653 GNUNET_SCHEDULER_cancel (h->sched, h->nth.timeout_task);
664 h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; 654 h->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
665 h->ccs -= COCO_TRANSMIT_READY; 655 h->ccs -= COCO_TRANSMIT_READY;
666 h->write_task = 656 h->write_task =
667 GNUNET_SCHEDULER_add_write_net (h->sched, 657 GNUNET_SCHEDULER_add_write_net (h->sched,
668 GNUNET_NO, 658 GNUNET_NO,
669 GNUNET_SCHEDULER_PRIORITY_KEEP, 659 GNUNET_SCHEDULER_PRIORITY_KEEP,
670 GNUNET_SCHEDULER_NO_TASK, 660 GNUNET_SCHEDULER_NO_TASK,
671 GNUNET_TIME_absolute_get_remaining (h->nth.transmit_timeout), 661 GNUNET_TIME_absolute_get_remaining
672 h->sock, &transmit_ready, h); 662 (h->nth.transmit_timeout), h->sock,
663 &transmit_ready, h);
673 } 664 }
674 if (0 != (h->ccs & COCO_DESTROY_CONTINUATION)) 665 if (0 != (h->ccs & COCO_DESTROY_CONTINUATION))
675 { 666 {
676#if DEBUG_CONNECTION 667#if DEBUG_CONNECTION
677 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
678 "connect_success_continuation runs destroy_continuation (%p)\n", 669 "connect_success_continuation runs destroy_continuation (%p)\n",
679 h); 670 h);
680#endif 671#endif
681 h->ccs -= COCO_DESTROY_CONTINUATION; 672 h->ccs -= COCO_DESTROY_CONTINUATION;
682 GNUNET_SCHEDULER_add_continuation (h->sched, 673 GNUNET_SCHEDULER_add_continuation (h->sched,
683 GNUNET_NO, 674 GNUNET_NO,
684 &destroy_continuation, 675 &destroy_continuation,
685 h, 676 h,
686 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 677 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
687 } 678 }
688} 679}
689 680
@@ -697,7 +688,7 @@ connect_success_continuation (struct GNUNET_CONNECTION_Handle *h)
697 */ 688 */
698static void 689static void
699connect_probe_continuation (void *cls, 690connect_probe_continuation (void *cls,
700 const struct GNUNET_SCHEDULER_TaskContext *tc) 691 const struct GNUNET_SCHEDULER_TaskContext *tc)
701{ 692{
702 struct AddressProbe *ap = cls; 693 struct AddressProbe *ap = cls;
703 struct GNUNET_CONNECTION_Handle *h = ap->h; 694 struct GNUNET_CONNECTION_Handle *h = ap->h;
@@ -709,15 +700,16 @@ connect_probe_continuation (void *cls,
709 len = sizeof (error); 700 len = sizeof (error);
710 errno = 0; 701 errno = 0;
711 error = 0; 702 error = 0;
712 if ( (0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) || 703 if ((0 == (tc->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ||
713 (GNUNET_OK != GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR, &error, &len)) || 704 (GNUNET_OK !=
714 (error != 0) || (errno != 0) ) 705 GNUNET_NETWORK_socket_getsockopt (ap->sock, SOL_SOCKET, SO_ERROR,
706 &error, &len)) || (error != 0)
707 || (errno != 0))
715 { 708 {
716 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock)); 709 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ap->sock));
717 GNUNET_free (ap); 710 GNUNET_free (ap);
718 if ( (NULL == h->ap_head) && 711 if ((NULL == h->ap_head) && (h->dns_active == GNUNET_NO))
719 (h->dns_active == GNUNET_NO) ) 712 connect_fail_continuation (h);
720 connect_fail_continuation (h);
721 return; 713 return;
722 } 714 }
723 h->sock = ap->sock; 715 h->sock = ap->sock;
@@ -748,55 +740,48 @@ connect_probe_continuation (void *cls,
748 */ 740 */
749static void 741static void
750try_connect_using_address (void *cls, 742try_connect_using_address (void *cls,
751 const struct sockaddr * addr, 743 const struct sockaddr *addr, socklen_t addrlen)
752 socklen_t addrlen)
753{ 744{
754 struct GNUNET_CONNECTION_Handle *h = cls; 745 struct GNUNET_CONNECTION_Handle *h = cls;
755 struct AddressProbe *ap; 746 struct AddressProbe *ap;
756 struct GNUNET_TIME_Relative delay; 747 struct GNUNET_TIME_Relative delay;
757 748
758 if (addr == NULL) 749 if (addr == NULL)
759 { 750 {
760 if (h->dns_active == GNUNET_SYSERR) 751 if (h->dns_active == GNUNET_SYSERR)
761 { 752 {
762 h->dns_active = GNUNET_NO; 753 h->dns_active = GNUNET_NO;
763 GNUNET_SCHEDULER_add_after (h->sched, 754 GNUNET_SCHEDULER_add_after (h->sched,
764 GNUNET_YES, 755 GNUNET_YES,
765 GNUNET_SCHEDULER_PRIORITY_KEEP, 756 GNUNET_SCHEDULER_PRIORITY_KEEP,
766 h->read_task, 757 h->read_task, &destroy_continuation, h);
767 &destroy_continuation, 758 return;
768 h); 759 }
769 return;
770 }
771 h->dns_active = GNUNET_NO; 760 h->dns_active = GNUNET_NO;
772 if (NULL == h->ap_head) 761 if (NULL == h->ap_head)
773 connect_fail_continuation (h); 762 connect_fail_continuation (h);
774 return; 763 return;
775 } 764 }
776 if (h->sock != NULL) 765 if (h->sock != NULL)
777 return; /* already connected */ 766 return; /* already connected */
778 if (h->dns_active == GNUNET_SYSERR) 767 if (h->dns_active == GNUNET_SYSERR)
779 { 768 {
780#if DEBUG_CONNECTION 769#if DEBUG_CONNECTION
781 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
782 "Connection %p has already been destroyed.\n", 771 "Connection %p has already been destroyed.\n", h);
783 h);
784#endif 772#endif
785 return; /* already destroyed */ 773 return; /* already destroyed */
786 } 774 }
787 /* try to connect */ 775 /* try to connect */
788#if DEBUG_CONNECTION 776#if DEBUG_CONNECTION
789 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 777 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
790 "Trying to connect using address `%s:%u/%s:%u'\n", 778 "Trying to connect using address `%s:%u/%s:%u'\n",
791 h->hostname, 779 h->hostname, h->port, GNUNET_a2s (addr, addrlen), h->port);
792 h->port,
793 GNUNET_a2s (addr, addrlen),
794 h->port);
795#endif 780#endif
796 ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen); 781 ap = GNUNET_malloc (sizeof (struct AddressProbe) + addrlen);
797 ap->addr = (const struct sockaddr*) &ap[1]; 782 ap->addr = (const struct sockaddr *) &ap[1];
798 memcpy (&ap[1], addr, addrlen); 783 memcpy (&ap[1], addr, addrlen);
799 ap->addrlen = addrlen; 784 ap->addrlen = addrlen;
800 ap->h = h; 785 ap->h = h;
801 786
802 switch (ap->addr->sa_family) 787 switch (ap->addr->sa_family)
@@ -810,25 +795,24 @@ try_connect_using_address (void *cls,
810 default: 795 default:
811 GNUNET_break (0); 796 GNUNET_break (0);
812 GNUNET_free (ap); 797 GNUNET_free (ap);
813 return; /* not supported by us */ 798 return; /* not supported by us */
814 } 799 }
815 ap->sock = GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0); 800 ap->sock =
801 GNUNET_NETWORK_socket_create (ap->addr->sa_family, SOCK_STREAM, 0);
816 if (ap->sock == NULL) 802 if (ap->sock == NULL)
817 { 803 {
818 GNUNET_free (ap); 804 GNUNET_free (ap);
819 return; /* not supported by OS */ 805 return; /* not supported by OS */
820 } 806 }
821#if DEBUG_CONNECTION 807#if DEBUG_CONNECTION
822 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 808 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
823 _("Trying to connect to `%s' (%p)\n"), 809 _("Trying to connect to `%s' (%p)\n"),
824 GNUNET_a2s(ap->addr, 810 GNUNET_a2s (ap->addr, ap->addrlen), h);
825 ap->addrlen),
826 h);
827#endif 811#endif
828 if ( (GNUNET_OK != GNUNET_NETWORK_socket_connect (ap->sock, 812 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (ap->sock,
829 ap->addr, 813 ap->addr,
830 ap->addrlen)) && 814 ap->addrlen)) &&
831 (errno != EINPROGRESS)) 815 (errno != EINPROGRESS))
832 { 816 {
833 /* maybe refused / unsupported address, try next */ 817 /* maybe refused / unsupported address, try next */
834 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); 818 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect");
@@ -840,18 +824,18 @@ try_connect_using_address (void *cls,
840 delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT; 824 delay = GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT;
841 if (h->nth.notify_ready != NULL) 825 if (h->nth.notify_ready != NULL)
842 delay = GNUNET_TIME_relative_min (delay, 826 delay = GNUNET_TIME_relative_min (delay,
843 GNUNET_TIME_absolute_get_remaining (h->nth.transmit_timeout)); 827 GNUNET_TIME_absolute_get_remaining (h->
828 nth.
829 transmit_timeout));
844 if (h->receiver != NULL) 830 if (h->receiver != NULL)
845 delay = GNUNET_TIME_relative_min (delay, 831 delay = GNUNET_TIME_relative_min (delay,
846 GNUNET_TIME_absolute_get_remaining (h->receive_timeout)); 832 GNUNET_TIME_absolute_get_remaining (h->
847 ap->task = GNUNET_SCHEDULER_add_write_net (h->sched, 833 receive_timeout));
848 GNUNET_NO, 834 ap->task =
849 GNUNET_SCHEDULER_PRIORITY_KEEP, 835 GNUNET_SCHEDULER_add_write_net (h->sched, GNUNET_NO,
850 GNUNET_SCHEDULER_NO_TASK, 836 GNUNET_SCHEDULER_PRIORITY_KEEP,
851 delay, 837 GNUNET_SCHEDULER_NO_TASK, delay, ap->sock,
852 ap->sock, 838 &connect_probe_continuation, ap);
853 &connect_probe_continuation,
854 ap);
855} 839}
856 840
857 841
@@ -863,18 +847,17 @@ try_connect_using_address (void *cls,
863 */ 847 */
864static void 848static void
865retry_connect_continuation (void *cls, 849retry_connect_continuation (void *cls,
866 const struct GNUNET_SCHEDULER_TaskContext *tc) 850 const struct GNUNET_SCHEDULER_TaskContext *tc)
867{ 851{
868 struct GNUNET_CONNECTION_Handle *sock = cls; 852 struct GNUNET_CONNECTION_Handle *sock = cls;
869 853
870 sock->dns_active = GNUNET_YES; 854 sock->dns_active = GNUNET_YES;
871 GNUNET_RESOLVER_ip_get (sock->sched, 855 GNUNET_RESOLVER_ip_get (sock->sched,
872 sock->cfg, 856 sock->cfg,
873 sock->hostname, 857 sock->hostname,
874 AF_UNSPEC, 858 AF_UNSPEC,
875 GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT, 859 GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT,
876 &try_connect_using_address, 860 &try_connect_using_address, sock);
877 sock);
878} 861}
879 862
880 863
@@ -892,14 +875,15 @@ retry_connect_continuation (void *cls,
892 * @return the socket handle 875 * @return the socket handle
893 */ 876 */
894struct GNUNET_CONNECTION_Handle * 877struct GNUNET_CONNECTION_Handle *
895GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched, 878GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched,
896 const struct GNUNET_CONFIGURATION_Handle *cfg, 879 const struct
897 const char *hostname, 880 GNUNET_CONFIGURATION_Handle *cfg,
898 uint16_t port, size_t maxbuf) 881 const char *hostname, uint16_t port,
882 size_t maxbuf)
899{ 883{
900 struct GNUNET_CONNECTION_Handle *ret; 884 struct GNUNET_CONNECTION_Handle *ret;
901 885
902 GNUNET_assert (0 < strlen (hostname)); /* sanity check */ 886 GNUNET_assert (0 < strlen (hostname)); /* sanity check */
903 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf); 887 ret = GNUNET_malloc (sizeof (struct GNUNET_CONNECTION_Handle) + maxbuf);
904 ret->cfg = cfg; 888 ret->cfg = cfg;
905 ret->sched = sched; 889 ret->sched = sched;
@@ -927,9 +911,9 @@ GNUNET_CONNECTION_create_from_connect (struct GNUNET_SCHEDULER_Handle *sched,
927 */ 911 */
928struct GNUNET_CONNECTION_Handle * 912struct GNUNET_CONNECTION_Handle *
929GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle 913GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle
930 *sched, int af_family, 914 *sched, int af_family,
931 const struct sockaddr *serv_addr, 915 const struct sockaddr *serv_addr,
932 socklen_t addrlen, size_t maxbuf) 916 socklen_t addrlen, size_t maxbuf)
933{ 917{
934 struct GNUNET_NETWORK_Handle *s; 918 struct GNUNET_NETWORK_Handle *s;
935 struct GNUNET_CONNECTION_Handle *ret; 919 struct GNUNET_CONNECTION_Handle *ret;
@@ -941,7 +925,8 @@ GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle
941 GNUNET_ERROR_TYPE_BULK, "socket"); 925 GNUNET_ERROR_TYPE_BULK, "socket");
942 return NULL; 926 return NULL;
943 } 927 }
944 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen)) && (errno != EINPROGRESS)) 928 if ((GNUNET_OK != GNUNET_NETWORK_socket_connect (s, serv_addr, addrlen))
929 && (errno != EINPROGRESS))
945 { 930 {
946 /* maybe refused / unsupported address, try next */ 931 /* maybe refused / unsupported address, try next */
947 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect"); 932 GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "connect");
@@ -954,9 +939,8 @@ GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle
954 ret->addrlen = addrlen; 939 ret->addrlen = addrlen;
955#if DEBUG_CONNECTION 940#if DEBUG_CONNECTION
956 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 941 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
957 _("Trying to connect to `%s' (%p)\n"), 942 _("Trying to connect to `%s' (%p)\n"),
958 GNUNET_a2s(serv_addr, addrlen), 943 GNUNET_a2s (serv_addr, addrlen), ret);
959 ret);
960#endif 944#endif
961 return ret; 945 return ret;
962} 946}
@@ -973,8 +957,7 @@ GNUNET_CONNECTION_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle
973int 957int
974GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock) 958GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock)
975{ 959{
976 if ( (sock->ap_head != NULL) || 960 if ((sock->ap_head != NULL) || (sock->dns_active == GNUNET_YES))
977 (sock->dns_active == GNUNET_YES) )
978 return GNUNET_YES; /* still trying to connect */ 961 return GNUNET_YES; /* still trying to connect */
979 return (sock->sock == NULL) ? GNUNET_NO : GNUNET_YES; 962 return (sock->sock == NULL) ? GNUNET_NO : GNUNET_YES;
980} 963}
@@ -990,11 +973,10 @@ GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *sock)
990void 973void
991GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock) 974GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *sock)
992{ 975{
993 if ( (sock->write_buffer_off == 0) && 976 if ((sock->write_buffer_off == 0) && (sock->dns_active == GNUNET_YES))
994 (sock->dns_active == GNUNET_YES) )
995 { 977 {
996 sock->dns_active = GNUNET_SYSERR; /* if we're still trying to connect and have 978 sock->dns_active = GNUNET_SYSERR; /* if we're still trying to connect and have
997 no message pending, stop trying! */ 979 no message pending, stop trying! */
998 return; 980 return;
999 } 981 }
1000 GNUNET_assert (sock->sched != NULL); 982 GNUNET_assert (sock->sched != NULL);
@@ -1016,8 +998,7 @@ signal_timeout (struct GNUNET_CONNECTION_Handle *sh)
1016 998
1017#if DEBUG_CONNECTION 999#if DEBUG_CONNECTION
1018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1000 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1019 "Network signals time out to receiver (%p)!\n", 1001 "Network signals time out to receiver (%p)!\n", sh);
1020 sh);
1021#endif 1002#endif
1022 GNUNET_assert (NULL != (receiver = sh->receiver)); 1003 GNUNET_assert (NULL != (receiver = sh->receiver));
1023 sh->receiver = NULL; 1004 sh->receiver = NULL;
@@ -1053,17 +1034,17 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1053 1034
1054 sh->read_task = GNUNET_SCHEDULER_NO_TASK; 1035 sh->read_task = GNUNET_SCHEDULER_NO_TASK;
1055 now = GNUNET_TIME_absolute_get (); 1036 now = GNUNET_TIME_absolute_get ();
1056 if ( (now.value > sh->receive_timeout.value) || 1037 if ((now.value > sh->receive_timeout.value) ||
1057 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) || 1038 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) ||
1058 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) ) 1039 (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)))
1059 { 1040 {
1060#if DEBUG_CONNECTION 1041#if DEBUG_CONNECTION
1061 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 1042 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
1062 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1043 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1063 "Receive from `%s' encounters error: time out by %llums... (%p)\n", 1044 "Receive from `%s' encounters error: time out by %llums... (%p)\n",
1064 GNUNET_a2s (sh->addr, sh->addrlen), 1045 GNUNET_a2s (sh->addr, sh->addrlen),
1065 GNUNET_TIME_absolute_get_duration (sh->receive_timeout).value, 1046 GNUNET_TIME_absolute_get_duration (sh->receive_timeout).
1066 sh); 1047 value, sh);
1067#endif 1048#endif
1068 signal_timeout (sh); 1049 signal_timeout (sh);
1069 return; 1050 return;
@@ -1073,8 +1054,7 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1073 /* connect failed for good */ 1054 /* connect failed for good */
1074#if DEBUG_CONNECTION 1055#if DEBUG_CONNECTION
1075 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1056 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1076 "Receive encounters error, socket closed... (%p)\n", 1057 "Receive encounters error, socket closed... (%p)\n", sh);
1077 sh);
1078#endif 1058#endif
1079 signal_error (sh, ECONNREFUSED); 1059 signal_error (sh, ECONNREFUSED);
1080 return; 1060 return;
@@ -1088,8 +1068,7 @@ RETRY:
1088 goto RETRY; 1068 goto RETRY;
1089#if DEBUG_CONNECTION 1069#if DEBUG_CONNECTION
1090 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1091 "Error receiving: %s\n", 1071 "Error receiving: %s\n", STRERROR (errno));
1092 STRERROR (errno));
1093#endif 1072#endif
1094 signal_error (sh, errno); 1073 signal_error (sh, errno);
1095 return; 1074 return;
@@ -1097,10 +1076,8 @@ RETRY:
1097#if DEBUG_CONNECTION 1076#if DEBUG_CONNECTION
1098 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1077 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1099 "receive_ready read %u/%u bytes from `%s' (%p)!\n", 1078 "receive_ready read %u/%u bytes from `%s' (%p)!\n",
1100 (unsigned int) ret, 1079 (unsigned int) ret,
1101 sh->max, 1080 sh->max, GNUNET_a2s (sh->addr, sh->addrlen), sh);
1102 GNUNET_a2s(sh->addr, sh->addrlen),
1103 sh);
1104#endif 1081#endif
1105 GNUNET_assert (NULL != (receiver = sh->receiver)); 1082 GNUNET_assert (NULL != (receiver = sh->receiver));
1106 sh->receiver = NULL; 1083 sh->receiver = NULL;
@@ -1125,13 +1102,12 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1125 struct GNUNET_TIME_Absolute now; 1102 struct GNUNET_TIME_Absolute now;
1126 1103
1127 sh->read_task = GNUNET_SCHEDULER_NO_TASK; 1104 sh->read_task = GNUNET_SCHEDULER_NO_TASK;
1128 if (sh->sock == NULL) 1105 if (sh->sock == NULL)
1129 { 1106 {
1130 /* not connected and no longer trying */ 1107 /* not connected and no longer trying */
1131#if DEBUG_CONNECTION 1108#if DEBUG_CONNECTION
1132 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1109 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1133 "Receive encounters error, socket closed (%p)...\n", 1110 "Receive encounters error, socket closed (%p)...\n", sh);
1134 sh);
1135#endif 1111#endif
1136 signal_error (sh, ECONNREFUSED); 1112 signal_error (sh, ECONNREFUSED);
1137 return; 1113 return;
@@ -1142,8 +1118,7 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1142 { 1118 {
1143#if DEBUG_CONNECTION 1119#if DEBUG_CONNECTION
1144 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1145 "Receive encounters error: time out (%p)...\n", 1121 "Receive encounters error: time out (%p)...\n", sh);
1146 sh);
1147#endif 1122#endif
1148 signal_timeout (sh); 1123 signal_timeout (sh);
1149 return; 1124 return;
@@ -1151,14 +1126,13 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1151 GNUNET_assert (sh->sock != NULL); 1126 GNUNET_assert (sh->sock != NULL);
1152 /* connect succeeded, wait for data! */ 1127 /* connect succeeded, wait for data! */
1153 sh->read_task = GNUNET_SCHEDULER_add_read_net (tc->sched, 1128 sh->read_task = GNUNET_SCHEDULER_add_read_net (tc->sched,
1154 GNUNET_YES, 1129 GNUNET_YES,
1155 GNUNET_SCHEDULER_PRIORITY_KEEP, 1130 GNUNET_SCHEDULER_PRIORITY_KEEP,
1156 GNUNET_SCHEDULER_NO_TASK, 1131 GNUNET_SCHEDULER_NO_TASK,
1157 GNUNET_TIME_absolute_get_remaining 1132 GNUNET_TIME_absolute_get_remaining
1158 (sh->receive_timeout), 1133 (sh->receive_timeout),
1159 sh->sock, 1134 sh->sock,
1160 &receive_ready, 1135 &receive_ready, sh);
1161 sh);
1162} 1136}
1163 1137
1164 1138
@@ -1177,14 +1151,15 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1177 */ 1151 */
1178void 1152void
1179GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock, 1153GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock,
1180 size_t max, 1154 size_t max,
1181 struct GNUNET_TIME_Relative timeout, 1155 struct GNUNET_TIME_Relative timeout,
1182 GNUNET_CONNECTION_Receiver receiver, void *receiver_cls) 1156 GNUNET_CONNECTION_Receiver receiver,
1157 void *receiver_cls)
1183{ 1158{
1184 struct GNUNET_SCHEDULER_TaskContext tc; 1159 struct GNUNET_SCHEDULER_TaskContext tc;
1185 1160
1186 GNUNET_assert ((sock->read_task == GNUNET_SCHEDULER_NO_TASK) && 1161 GNUNET_assert ((sock->read_task == GNUNET_SCHEDULER_NO_TASK) &&
1187 (0 == (sock->ccs & COCO_RECEIVE_AGAIN)) && 1162 (0 == (sock->ccs & COCO_RECEIVE_AGAIN)) &&
1188 (sock->receiver == NULL)); 1163 (sock->receiver == NULL));
1189 sock->receiver = receiver; 1164 sock->receiver = receiver;
1190 sock->receiver_cls = receiver_cls; 1165 sock->receiver_cls = receiver_cls;
@@ -1198,8 +1173,7 @@ GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *sock,
1198 receive_again (sock, &tc); 1173 receive_again (sock, &tc);
1199 return; 1174 return;
1200 } 1175 }
1201 if ( (sock->dns_active != GNUNET_YES) && 1176 if ((sock->dns_active != GNUNET_YES) && (sock->ap_head == NULL))
1202 (sock->ap_head == NULL) )
1203 { 1177 {
1204 receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT); 1178 receiver (receiver_cls, NULL, 0, NULL, 0, ETIMEDOUT);
1205 return; 1179 return;
@@ -1221,12 +1195,12 @@ GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *sock)
1221{ 1195{
1222 if (sock->read_task != GNUNET_SCHEDULER_NO_TASK) 1196 if (sock->read_task != GNUNET_SCHEDULER_NO_TASK)
1223 { 1197 {
1224 GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->sched, 1198 GNUNET_assert (sock == GNUNET_SCHEDULER_cancel (sock->sched,
1225 sock->read_task)); 1199 sock->read_task));
1226 sock->read_task = GNUNET_SCHEDULER_NO_TASK; 1200 sock->read_task = GNUNET_SCHEDULER_NO_TASK;
1227 } 1201 }
1228 else 1202 else
1229 { 1203 {
1230 GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN)); 1204 GNUNET_assert (0 != (sock->ccs & COCO_RECEIVE_AGAIN));
1231 sock->ccs -= COCO_RECEIVE_AGAIN; 1205 sock->ccs -= COCO_RECEIVE_AGAIN;
1232 } 1206 }
@@ -1285,28 +1259,24 @@ process_notify (struct GNUNET_CONNECTION_Handle *sock)
1285 * This task notifies the client about the timeout. 1259 * This task notifies the client about the timeout.
1286 */ 1260 */
1287static void 1261static void
1288transmit_timeout (void *cls, 1262transmit_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1289 const struct GNUNET_SCHEDULER_TaskContext *tc)
1290{ 1263{
1291 struct GNUNET_CONNECTION_Handle *sock = cls; 1264 struct GNUNET_CONNECTION_Handle *sock = cls;
1292 GNUNET_CONNECTION_TransmitReadyNotify notify; 1265 GNUNET_CONNECTION_TransmitReadyNotify notify;
1293 1266
1294#if DEBUG_CONNECTION 1267#if DEBUG_CONNECTION
1295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1268 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1296 "transmit_timeout running (%p)\n", 1269 "transmit_timeout running (%p)\n", sock);
1297 sock);
1298#endif 1270#endif
1299 sock->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK; 1271 sock->nth.timeout_task = GNUNET_SCHEDULER_NO_TASK;
1300#if DEBUG_CONNECTION 1272#if DEBUG_CONNECTION
1301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1273 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1302 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n", 1274 "Transmit to `%s:%u/%s' fails, time out reached (%p).\n",
1303 sock->hostname, 1275 sock->hostname,
1304 sock->port, 1276 sock->port, GNUNET_a2s (sock->addr, sock->addrlen), sock);
1305 GNUNET_a2s (sock->addr, sock->addrlen),
1306 sock);
1307#endif 1277#endif
1308 GNUNET_assert (0 != (sock->ccs & COCO_TRANSMIT_READY)); 1278 GNUNET_assert (0 != (sock->ccs & COCO_TRANSMIT_READY));
1309 sock->ccs -= COCO_TRANSMIT_READY; /* remove request */ 1279 sock->ccs -= COCO_TRANSMIT_READY; /* remove request */
1310 notify = sock->nth.notify_ready; 1280 notify = sock->nth.notify_ready;
1311 sock->nth.notify_ready = NULL; 1281 sock->nth.notify_ready = NULL;
1312 notify (sock->nth.notify_ready_cls, 0, NULL); 1282 notify (sock->nth.notify_ready_cls, 0, NULL);
@@ -1320,17 +1290,15 @@ transmit_timeout (void *cls,
1320 * This task notifies the client about the error. 1290 * This task notifies the client about the error.
1321 */ 1291 */
1322static void 1292static void
1323connect_error (void *cls, 1293connect_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1324 const struct GNUNET_SCHEDULER_TaskContext *tc)
1325{ 1294{
1326 struct GNUNET_CONNECTION_Handle *sock = cls; 1295 struct GNUNET_CONNECTION_Handle *sock = cls;
1327 GNUNET_CONNECTION_TransmitReadyNotify notify; 1296 GNUNET_CONNECTION_TransmitReadyNotify notify;
1328 1297
1329#if DEBUG_CONNECTION 1298#if DEBUG_CONNECTION
1330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1331 "Transmission request of size %u fails, connection failed (%p).\n", 1300 "Transmission request of size %u fails, connection failed (%p).\n",
1332 sock->nth.notify_size, 1301 sock->nth.notify_size, sock);
1333 sock);
1334#endif 1302#endif
1335 sock->write_task = GNUNET_SCHEDULER_NO_TASK; 1303 sock->write_task = GNUNET_SCHEDULER_NO_TASK;
1336 notify = sock->nth.notify_ready; 1304 notify = sock->nth.notify_ready;
@@ -1369,9 +1337,8 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1369 size_t have; 1337 size_t have;
1370 1338
1371#if DEBUG_CONNECTION 1339#if DEBUG_CONNECTION
1372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1373 "transmit_ready running (%p).\n", 1341 "transmit_ready running (%p).\n", sock);
1374 sock);
1375#endif 1342#endif
1376 GNUNET_assert (sock->write_task != GNUNET_SCHEDULER_NO_TASK); 1343 GNUNET_assert (sock->write_task != GNUNET_SCHEDULER_NO_TASK);
1377 sock->write_task = GNUNET_SCHEDULER_NO_TASK; 1344 sock->write_task = GNUNET_SCHEDULER_NO_TASK;
@@ -1379,10 +1346,9 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1379 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT)) 1346 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
1380 { 1347 {
1381#if DEBUG_CONNECTION 1348#if DEBUG_CONNECTION
1382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1383 "Transmit to `%s' fails, time out reached (%p).\n", 1350 "Transmit to `%s' fails, time out reached (%p).\n",
1384 GNUNET_a2s (sock->addr, sock->addrlen), 1351 GNUNET_a2s (sock->addr, sock->addrlen), sock);
1385 sock);
1386#endif 1352#endif
1387 notify = sock->nth.notify_ready; 1353 notify = sock->nth.notify_ready;
1388 sock->nth.notify_ready = NULL; 1354 sock->nth.notify_ready = NULL;
@@ -1393,24 +1359,25 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1393 if (tc->write_ready == NULL) 1359 if (tc->write_ready == NULL)
1394 { 1360 {
1395 /* special circumstances (in particular, 1361 /* special circumstances (in particular,
1396 PREREQ_DONE after connect): not yet ready to write, 1362 PREREQ_DONE after connect): not yet ready to write,
1397 but no "fatal" error either. Hence retry. */ 1363 but no "fatal" error either. Hence retry. */
1398 goto SCHEDULE_WRITE; 1364 goto SCHEDULE_WRITE;
1399 } 1365 }
1400 if (! GNUNET_NETWORK_fdset_isset (tc->write_ready, 1366 if (!GNUNET_NETWORK_fdset_isset (tc->write_ready, sock->sock))
1401 sock->sock))
1402 { 1367 {
1403#if DEBUG_CONNECTION 1368#if DEBUG_CONNECTION
1404 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1369 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1405 _("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"), 1370 _
1406 sock); 1371 ("Could not satisfy pending transmission request, socket closed or connect failed (%p).\n"),
1372 sock);
1407#endif 1373#endif
1408 if (NULL != sock->sock) 1374 if (NULL != sock->sock)
1409 { 1375 {
1410 GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR); 1376 GNUNET_NETWORK_socket_shutdown (sock->sock, SHUT_RDWR);
1411 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (sock->sock)); 1377 GNUNET_break (GNUNET_OK ==
1412 sock->sock = NULL; 1378 GNUNET_NETWORK_socket_close (sock->sock));
1413 } 1379 sock->sock = NULL;
1380 }
1414 transmit_error (sock); 1381 transmit_error (sock);
1415 return; /* connect failed for good, we're finished */ 1382 return; /* connect failed for good, we're finished */
1416 } 1383 }
@@ -1419,13 +1386,14 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1419 have = sock->write_buffer_off - sock->write_buffer_pos; 1386 have = sock->write_buffer_off - sock->write_buffer_pos;
1420 if (have == 0) 1387 if (have == 0)
1421 { 1388 {
1422 /* no data ready for writing, terminate write loop */ 1389 /* no data ready for writing, terminate write loop */
1423 return; 1390 return;
1424 } 1391 }
1425RETRY: 1392RETRY:
1426 ret = GNUNET_NETWORK_socket_send (sock->sock, 1393 ret = GNUNET_NETWORK_socket_send (sock->sock,
1427 &sock->write_buffer[sock->write_buffer_pos], 1394 &sock->write_buffer[sock->
1428 have); 1395 write_buffer_pos],
1396 have);
1429 if (ret == -1) 1397 if (ret == -1)
1430 { 1398 {
1431 if (errno == EINTR) 1399 if (errno == EINTR)
@@ -1442,10 +1410,8 @@ RETRY:
1442#if DEBUG_CONNECTION 1410#if DEBUG_CONNECTION
1443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1411 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1444 "transmit_ready transmitted %u/%u bytes to `%s' (%p)\n", 1412 "transmit_ready transmitted %u/%u bytes to `%s' (%p)\n",
1445 (unsigned int) ret, 1413 (unsigned int) ret,
1446 have, 1414 have, GNUNET_a2s (sock->addr, sock->addrlen), sock);
1447 GNUNET_a2s(sock->addr, sock->addrlen),
1448 sock);
1449#endif 1415#endif
1450 sock->write_buffer_pos += ret; 1416 sock->write_buffer_pos += ret;
1451 if (sock->write_buffer_pos == sock->write_buffer_off) 1417 if (sock->write_buffer_pos == sock->write_buffer_off)
@@ -1454,25 +1420,23 @@ RETRY:
1454 sock->write_buffer_pos = 0; 1420 sock->write_buffer_pos = 0;
1455 sock->write_buffer_off = 0; 1421 sock->write_buffer_off = 0;
1456 } 1422 }
1457 if ( (sock->write_buffer_off == 0) && 1423 if ((sock->write_buffer_off == 0) && (NULL == sock->nth.notify_ready))
1458 (NULL == sock->nth.notify_ready)) 1424 return; /* all data sent! */
1459 return; /* all data sent! */
1460 /* not done writing, schedule more */ 1425 /* not done writing, schedule more */
1461SCHEDULE_WRITE: 1426SCHEDULE_WRITE:
1462#if DEBUG_CONNECTION 1427#if DEBUG_CONNECTION
1463 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1464 "Re-scheduling transmit_ready (more to do) (%p).\n", 1429 "Re-scheduling transmit_ready (more to do) (%p).\n", sock);
1465 sock);
1466#endif 1430#endif
1467 if (sock->write_task == GNUNET_SCHEDULER_NO_TASK) 1431 if (sock->write_task == GNUNET_SCHEDULER_NO_TASK)
1468 sock->write_task = 1432 sock->write_task =
1469 GNUNET_SCHEDULER_add_write_net (tc->sched, 1433 GNUNET_SCHEDULER_add_write_net (tc->sched,
1470 GNUNET_NO, 1434 GNUNET_NO,
1471 GNUNET_SCHEDULER_PRIORITY_KEEP, 1435 GNUNET_SCHEDULER_PRIORITY_KEEP,
1472 GNUNET_SCHEDULER_NO_TASK, 1436 GNUNET_SCHEDULER_NO_TASK,
1473 GNUNET_TIME_absolute_get_remaining (sock->nth.transmit_timeout), 1437 GNUNET_TIME_absolute_get_remaining
1474 sock->sock, 1438 (sock->nth.transmit_timeout),
1475 &transmit_ready, sock); 1439 sock->sock, &transmit_ready, sock);
1476} 1440}
1477 1441
1478 1442
@@ -1492,10 +1456,10 @@ SCHEDULE_WRITE:
1492 */ 1456 */
1493struct GNUNET_CONNECTION_TransmitHandle * 1457struct GNUNET_CONNECTION_TransmitHandle *
1494GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle 1458GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1495 *sock, size_t size, 1459 *sock, size_t size,
1496 struct GNUNET_TIME_Relative timeout, 1460 struct GNUNET_TIME_Relative timeout,
1497 GNUNET_CONNECTION_TransmitReadyNotify 1461 GNUNET_CONNECTION_TransmitReadyNotify
1498 notify, void *notify_cls) 1462 notify, void *notify_cls)
1499{ 1463{
1500 if (sock->nth.notify_ready != NULL) 1464 if (sock->nth.notify_ready != NULL)
1501 return NULL; 1465 return NULL;
@@ -1510,17 +1474,15 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1510 sock->nth.notify_size = size; 1474 sock->nth.notify_size = size;
1511 sock->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout); 1475 sock->nth.transmit_timeout = GNUNET_TIME_relative_to_absolute (timeout);
1512 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task); 1476 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == sock->nth.timeout_task);
1513 if ( (sock->sock == NULL) && 1477 if ((sock->sock == NULL) &&
1514 (sock->ap_head == NULL) && 1478 (sock->ap_head == NULL) && (sock->dns_active != GNUNET_YES))
1515 (sock->dns_active != GNUNET_YES) ) 1479 {
1516 {
1517 sock->write_task = GNUNET_SCHEDULER_add_delayed (sock->sched, 1480 sock->write_task = GNUNET_SCHEDULER_add_delayed (sock->sched,
1518 GNUNET_NO, 1481 GNUNET_NO,
1519 GNUNET_SCHEDULER_PRIORITY_KEEP, 1482 GNUNET_SCHEDULER_PRIORITY_KEEP,
1520 GNUNET_SCHEDULER_NO_TASK, 1483 GNUNET_SCHEDULER_NO_TASK,
1521 GNUNET_TIME_UNIT_ZERO, 1484 GNUNET_TIME_UNIT_ZERO,
1522 &connect_error, 1485 &connect_error, sock);
1523 sock);
1524 return &sock->nth; 1486 return &sock->nth;
1525 } 1487 }
1526 if (GNUNET_SCHEDULER_NO_TASK != sock->write_task) 1488 if (GNUNET_SCHEDULER_NO_TASK != sock->write_task)
@@ -1528,33 +1490,35 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1528 if (sock->sock != NULL) 1490 if (sock->sock != NULL)
1529 { 1491 {
1530#if DEBUG_CONNECTION 1492#if DEBUG_CONNECTION
1531 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1532 "Scheduling transmit_ready (%p).\n", 1494 "Scheduling transmit_ready (%p).\n", sock);
1533 sock);
1534#endif 1495#endif
1535 sock->write_task = GNUNET_SCHEDULER_add_write_net (sock->sched, 1496 sock->write_task = GNUNET_SCHEDULER_add_write_net (sock->sched,
1536 GNUNET_NO, 1497 GNUNET_NO,
1537 GNUNET_SCHEDULER_PRIORITY_KEEP, 1498 GNUNET_SCHEDULER_PRIORITY_KEEP,
1538 GNUNET_SCHEDULER_NO_TASK, 1499 GNUNET_SCHEDULER_NO_TASK,
1539 GNUNET_TIME_absolute_get_remaining (sock->nth.transmit_timeout), 1500 GNUNET_TIME_absolute_get_remaining
1540 sock->sock, 1501 (sock->nth.
1541 &transmit_ready, sock); 1502 transmit_timeout),
1503 sock->sock,
1504 &transmit_ready,
1505 sock);
1542 } 1506 }
1543 else 1507 else
1544 { 1508 {
1545#if DEBUG_CONNECTION 1509#if DEBUG_CONNECTION
1546 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1510 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1547 "CCS-Scheduling transmit_ready, adding timeout task (%p).\n", 1511 "CCS-Scheduling transmit_ready, adding timeout task (%p).\n",
1548 sock); 1512 sock);
1549#endif 1513#endif
1550 sock->ccs |= COCO_TRANSMIT_READY; 1514 sock->ccs |= COCO_TRANSMIT_READY;
1551 sock->nth.timeout_task = GNUNET_SCHEDULER_add_delayed (sock->sched, 1515 sock->nth.timeout_task = GNUNET_SCHEDULER_add_delayed (sock->sched,
1552 GNUNET_NO, 1516 GNUNET_NO,
1553 GNUNET_SCHEDULER_PRIORITY_KEEP, 1517 GNUNET_SCHEDULER_PRIORITY_KEEP,
1554 GNUNET_SCHEDULER_NO_TASK, 1518 GNUNET_SCHEDULER_NO_TASK,
1555 timeout, 1519 timeout,
1556 &transmit_timeout, 1520 &transmit_timeout,
1557 sock); 1521 sock);
1558 } 1522 }
1559 return &sock->nth; 1523 return &sock->nth;
1560} 1524}
@@ -1566,15 +1530,16 @@ GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle
1566 */ 1530 */
1567void 1531void
1568GNUNET_CONNECTION_notify_transmit_ready_cancel (struct 1532GNUNET_CONNECTION_notify_transmit_ready_cancel (struct
1569 GNUNET_CONNECTION_TransmitHandle *h) 1533 GNUNET_CONNECTION_TransmitHandle
1534 *h)
1570{ 1535{
1571 GNUNET_assert (h->notify_ready != NULL); 1536 GNUNET_assert (h->notify_ready != NULL);
1572 if (0 != (h->sh->ccs & COCO_TRANSMIT_READY)) 1537 if (0 != (h->sh->ccs & COCO_TRANSMIT_READY))
1573 { 1538 {
1574#if DEBUG_CONNECTION 1539#if DEBUG_CONNECTION
1575 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1576 "notify_transmit_ready_cancel cancels timeout_task (%p)\n", 1541 "notify_transmit_ready_cancel cancels timeout_task (%p)\n",
1577 h); 1542 h);
1578#endif 1543#endif
1579 GNUNET_SCHEDULER_cancel (h->sh->sched, h->timeout_task); 1544 GNUNET_SCHEDULER_cancel (h->sh->sched, h->timeout_task);
1580 h->timeout_task = GNUNET_SCHEDULER_NO_TASK; 1545 h->timeout_task = GNUNET_SCHEDULER_NO_TASK;
@@ -1582,8 +1547,7 @@ GNUNET_CONNECTION_notify_transmit_ready_cancel (struct
1582 } 1547 }
1583 else 1548 else
1584 { 1549 {
1585 GNUNET_SCHEDULER_cancel (h->sh->sched, 1550 GNUNET_SCHEDULER_cancel (h->sh->sched, h->sh->write_task);
1586 h->sh->write_task);
1587 h->sh->write_task = GNUNET_SCHEDULER_NO_TASK; 1551 h->sh->write_task = GNUNET_SCHEDULER_NO_TASK;
1588 } 1552 }
1589 h->notify_ready = NULL; 1553 h->notify_ready = NULL;
diff --git a/src/util/container_bloomfilter.c b/src/util/container_bloomfilter.c
index 1ed09296d..8e44f4fc6 100644
--- a/src/util/container_bloomfilter.c
+++ b/src/util/container_bloomfilter.c
@@ -142,7 +142,8 @@ testBit (char *bitArray, unsigned int bitIdx)
142 * @param fh A file to keep the 4 bit address usage counters in 142 * @param fh A file to keep the 4 bit address usage counters in
143 */ 143 */
144static void 144static void
145incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh) 145incrementBit (char *bitArray, unsigned int bitIdx,
146 const struct GNUNET_DISK_FileHandle *fh)
146{ 147{
147 off_t fileSlot; 148 off_t fileSlot;
148 unsigned char value; 149 unsigned char value;
@@ -157,8 +158,8 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File
157 fileSlot = bitIdx / 2; 158 fileSlot = bitIdx / 2;
158 targetLoc = bitIdx % 2; 159 targetLoc = bitIdx % 2;
159 160
160 GNUNET_assert (fileSlot == 161 GNUNET_assert (fileSlot ==
161 GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET)); 162 GNUNET_DISK_file_seek (fh, fileSlot, GNUNET_DISK_SEEK_SET));
162 if (1 != GNUNET_DISK_file_read (fh, &value, 1)) 163 if (1 != GNUNET_DISK_file_read (fh, &value, 1))
163 value = 0; 164 value = 0;
164 low = value & 0xF; 165 low = value & 0xF;
@@ -175,9 +176,9 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File
175 high++; 176 high++;
176 } 177 }
177 value = ((high << 4) | low); 178 value = ((high << 4) | low);
178 GNUNET_assert (fileSlot == GNUNET_DISK_file_seek (fh, 179 GNUNET_assert (fileSlot == GNUNET_DISK_file_seek (fh,
179 fileSlot, 180 fileSlot,
180 GNUNET_DISK_SEEK_SET)); 181 GNUNET_DISK_SEEK_SET));
181 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1)); 182 GNUNET_assert (1 == GNUNET_DISK_file_write (fh, &value, 1));
182} 183}
183 184
@@ -190,7 +191,8 @@ incrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File
190 * @param fh A file to keep the 4bit address usage counters in 191 * @param fh A file to keep the 4bit address usage counters in
191 */ 192 */
192static void 193static void
193decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_FileHandle *fh) 194decrementBit (char *bitArray, unsigned int bitIdx,
195 const struct GNUNET_DISK_FileHandle *fh)
194{ 196{
195 off_t fileSlot; 197 off_t fileSlot;
196 unsigned char value; 198 unsigned char value;
@@ -243,8 +245,7 @@ decrementBit (char *bitArray, unsigned int bitIdx, const struct GNUNET_DISK_File
243 * @return GNUNET_OK if created ok, GNUNET_SYSERR otherwise 245 * @return GNUNET_OK if created ok, GNUNET_SYSERR otherwise
244 */ 246 */
245static int 247static int
246makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, 248makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh, size_t size)
247 size_t size)
248{ 249{
249 char *buffer; 250 char *buffer;
250 size_t bytesleft = size; 251 size_t bytesleft = size;
@@ -286,7 +287,7 @@ makeEmptyFile (const struct GNUNET_DISK_FileHandle *fh,
286 * @param bit the current bit 287 * @param bit the current bit
287 */ 288 */
288typedef void (*BitIterator) (void *cls, 289typedef void (*BitIterator) (void *cls,
289 struct GNUNET_CONTAINER_BloomFilter * bf, 290 struct GNUNET_CONTAINER_BloomFilter * bf,
290 unsigned int bit); 291 unsigned int bit);
291 292
292/** 293/**
@@ -314,9 +315,9 @@ iterateBits (struct GNUNET_CONTAINER_BloomFilter *bf,
314 { 315 {
315 while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t))) 316 while (slot < (sizeof (GNUNET_HashCode) / sizeof (uint32_t)))
316 { 317 {
317 callback (arg, 318 callback (arg,
318 bf, 319 bf,
319 (((uint32_t *) &tmp[round & 1])[slot]) & 320 (((uint32_t *) & tmp[round & 1])[slot]) &
320 ((bf->bitArraySize * 8) - 1)); 321 ((bf->bitArraySize * 8) - 1));
321 slot++; 322 slot++;
322 bitCount--; 323 bitCount--;
@@ -342,7 +343,7 @@ iterateBits (struct GNUNET_CONTAINER_BloomFilter *bf,
342 */ 343 */
343static void 344static void
344incrementBitCallback (void *cls, 345incrementBitCallback (void *cls,
345 struct GNUNET_CONTAINER_BloomFilter *bf, 346 struct GNUNET_CONTAINER_BloomFilter *bf,
346 unsigned int bit) 347 unsigned int bit)
347{ 348{
348 incrementBit (bf->bitArray, bit, bf->fh); 349 incrementBit (bf->bitArray, bit, bf->fh);
@@ -357,7 +358,7 @@ incrementBitCallback (void *cls,
357 */ 358 */
358static void 359static void
359decrementBitCallback (void *cls, 360decrementBitCallback (void *cls,
360 struct GNUNET_CONTAINER_BloomFilter *bf, 361 struct GNUNET_CONTAINER_BloomFilter *bf,
361 unsigned int bit) 362 unsigned int bit)
362{ 363{
363 decrementBit (bf->bitArray, bit, bf->fh); 364 decrementBit (bf->bitArray, bit, bf->fh);
@@ -372,7 +373,7 @@ decrementBitCallback (void *cls,
372 */ 373 */
373static void 374static void
374testBitCallback (void *cls, 375testBitCallback (void *cls,
375 struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit) 376 struct GNUNET_CONTAINER_BloomFilter *bf, unsigned int bit)
376{ 377{
377 int *arg = cls; 378 int *arg = cls;
378 if (GNUNET_NO == testBit (bf->bitArray, bit)) 379 if (GNUNET_NO == testBit (bf->bitArray, bit))
@@ -392,9 +393,8 @@ testBitCallback (void *cls,
392 * @return the bloomfilter 393 * @return the bloomfilter
393 */ 394 */
394struct GNUNET_CONTAINER_BloomFilter * 395struct GNUNET_CONTAINER_BloomFilter *
395GNUNET_CONTAINER_bloomfilter_load (const char *filename, 396GNUNET_CONTAINER_bloomfilter_load (const char *filename,
396 size_t size, 397 size_t size, unsigned int k)
397 unsigned int k)
398{ 398{
399 struct GNUNET_CONTAINER_BloomFilter *bf; 399 struct GNUNET_CONTAINER_BloomFilter *bf;
400 char *rbuff; 400 char *rbuff;
@@ -416,8 +416,9 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename,
416 if (filename != NULL) 416 if (filename != NULL)
417 { 417 {
418 bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE 418 bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE
419 | GNUNET_DISK_OPEN_CREATE, 419 | GNUNET_DISK_OPEN_CREATE,
420 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); 420 GNUNET_DISK_PERM_USER_READ |
421 GNUNET_DISK_PERM_USER_WRITE);
421 if (NULL == bf->fh) 422 if (NULL == bf->fh)
422 { 423 {
423 GNUNET_free (bf); 424 GNUNET_free (bf);
@@ -446,12 +447,11 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename,
446 int res; 447 int res;
447 448
448 res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE); 449 res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
449 if (res == -1) 450 if (res == -1)
450 { 451 {
451 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 452 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
452 "read", 453 "read", bf->filename);
453 bf->filename); 454 }
454 }
455 if (res == 0) 455 if (res == 0)
456 break; /* is ok! we just did not use that many bits yet */ 456 break; /* is ok! we just did not use that many bits yet */
457 for (i = 0; i < res; i++) 457 for (i = 0; i < res; i++)
@@ -486,8 +486,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename,
486 */ 486 */
487struct GNUNET_CONTAINER_BloomFilter * 487struct GNUNET_CONTAINER_BloomFilter *
488GNUNET_CONTAINER_bloomfilter_init (const char *data, 488GNUNET_CONTAINER_bloomfilter_init (const char *data,
489 size_t size, 489 size_t size, unsigned int k)
490 unsigned int k)
491{ 490{
492 struct GNUNET_CONTAINER_BloomFilter *bf; 491 struct GNUNET_CONTAINER_BloomFilter *bf;
493 size_t ui; 492 size_t ui;
@@ -527,8 +526,7 @@ GNUNET_CONTAINER_bloomfilter_init (const char *data,
527 */ 526 */
528int 527int
529GNUNET_CONTAINER_bloomfilter_get_raw_data (struct GNUNET_CONTAINER_BloomFilter 528GNUNET_CONTAINER_bloomfilter_get_raw_data (struct GNUNET_CONTAINER_BloomFilter
530 *bf, char *data, 529 *bf, char *data, size_t size)
531 size_t size)
532{ 530{
533 if (NULL == bf) 531 if (NULL == bf)
534 return GNUNET_SYSERR; 532 return GNUNET_SYSERR;
@@ -624,8 +622,7 @@ GNUNET_CONTAINER_bloomfilter_add (struct GNUNET_CONTAINER_BloomFilter *bf,
624 */ 622 */
625int 623int
626GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf, 624GNUNET_CONTAINER_bloomfilter_or (struct GNUNET_CONTAINER_BloomFilter *bf,
627 const char *data, 625 const char *data, size_t size)
628 size_t size)
629{ 626{
630 unsigned int i; 627 unsigned int i;
631 628
@@ -671,9 +668,8 @@ GNUNET_CONTAINER_bloomfilter_remove (struct GNUNET_CONTAINER_BloomFilter *bf,
671void 668void
672GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf, 669GNUNET_CONTAINER_bloomfilter_resize (struct GNUNET_CONTAINER_BloomFilter *bf,
673 GNUNET_HashCodeIterator iterator, 670 GNUNET_HashCodeIterator iterator,
674 void *iterator_cls, 671 void *iterator_cls,
675 size_t size, 672 size_t size, unsigned int k)
676 unsigned int k)
677{ 673{
678 GNUNET_HashCode hc; 674 GNUNET_HashCode hc;
679 unsigned int i; 675 unsigned int i;
diff --git a/src/util/container_heap.c b/src/util/container_heap.c
index 4709d97a6..9d252159f 100644
--- a/src/util/container_heap.c
+++ b/src/util/container_heap.c
@@ -67,7 +67,8 @@ struct GNUNET_CONTAINER_Heap
67 * @param heap the heap 67 * @param heap the heap
68 * @return NULL if the heap is empty 68 * @return NULL if the heap is empty
69 */ 69 */
70void *GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *heap) 70void *
71GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *heap)
71{ 72{
72 if ((heap == NULL) || (heap->root == NULL)) 73 if ((heap == NULL) || (heap->root == NULL))
73 return NULL; 74 return NULL;
@@ -76,7 +77,7 @@ void *GNUNET_CONTAINER_heap_peek (struct GNUNET_CONTAINER_Heap *heap)
76} 77}
77 78
78static int 79static int
79next_power_of_2(int v) 80next_power_of_2 (int v)
80{ 81{
81 v |= v >> 1; 82 v |= v >> 1;
82 v |= v >> 2; 83 v |= v >> 2;
@@ -129,7 +130,7 @@ void
129GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap) 130GNUNET_CONTAINER_heap_destroy (struct GNUNET_CONTAINER_Heap *heap)
130{ 131{
131 while (heap->size > 0) 132 while (heap->size > 0)
132 GNUNET_CONTAINER_heap_remove_root (heap); 133 GNUNET_CONTAINER_heap_remove_root (heap);
133 GNUNET_free (heap); 134 GNUNET_free (heap);
134 return; 135 return;
135} 136}
@@ -175,7 +176,7 @@ getNextPos (struct GNUNET_CONTAINER_Heap *root)
175 else 176 else
176 { 177 {
177 parent = root->root; 178 parent = root->root;
178 for (i = next_power_of_2(pos) >> 2; i > 1; i >>= 1) 179 for (i = next_power_of_2 (pos) >> 2; i > 1; i >>= 1)
179 { 180 {
180 if (((pos / i) % 2) == 0) 181 if (((pos / i) % 2) == 0)
181 parent = parent->left_child; 182 parent = parent->left_child;
@@ -209,7 +210,7 @@ getPos (struct GNUNET_CONTAINER_Heap *root, unsigned int pos)
209 else 210 else
210 { 211 {
211 ret = root->root; 212 ret = root->root;
212 for (i = next_power_of_2(pos) >> 2; i > 0; i >>= 1) 213 for (i = next_power_of_2 (pos) >> 2; i > 0; i >>= 1)
213 { 214 {
214 if (((pos / i) % 2) == 0) 215 if (((pos / i) % 2) == 0)
215 ret = ret->left_child; 216 ret = ret->left_child;
diff --git a/src/util/container_meta_data.c b/src/util/container_meta_data.c
index 5c70f95ff..ebf6ce778 100644
--- a/src/util/container_meta_data.c
+++ b/src/util/container_meta_data.c
@@ -196,8 +196,7 @@ GNUNET_CONTAINER_meta_data_get_contents (const struct
196 { 196 {
197 if ((iter != NULL) && 197 if ((iter != NULL) &&
198 (GNUNET_OK != iter (iter_cls, 198 (GNUNET_OK != iter (iter_cls,
199 md->items[i].type, 199 md->items[i].type, md->items[i].data)))
200 md->items[i].data)))
201 return GNUNET_SYSERR; 200 return GNUNET_SYSERR;
202 } 201 }
203 else 202 else
@@ -487,8 +486,7 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
487 hdr->version = htonl (md == NULL ? 1 : 0); 486 hdr->version = htonl (md == NULL ? 1 : 0);
488 hdr->entries = htonl (ic); 487 hdr->entries = htonl (ic);
489 for (i = 0; i < ic; i++) 488 for (i = 0; i < ic; i++)
490 ((uint32_t *) &hdr[1])[i] = 489 ((uint32_t *) & hdr[1])[i] = htonl ((uint32_t) md->items[i].type);
491 htonl ((uint32_t) md->items[i].type);
492 pos = sizeof (struct MetaDataHeader); 490 pos = sizeof (struct MetaDataHeader);
493 pos += sizeof (unsigned int) * ic; 491 pos += sizeof (unsigned int) * ic;
494 for (i = 0; i < ic; i++) 492 for (i = 0; i < ic; i++)
@@ -556,7 +554,8 @@ GNUNET_CONTAINER_meta_data_serialize (const struct GNUNET_CONTAINER_MetaData
556 */ 554 */
557ssize_t 555ssize_t
558GNUNET_CONTAINER_meta_data_get_serialized_size (const struct 556GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
559 GNUNET_CONTAINER_MetaData *md, 557 GNUNET_CONTAINER_MetaData *
558 md,
560 enum 559 enum
561 GNUNET_CONTAINER_MetaDataSerializationOptions 560 GNUNET_CONTAINER_MetaDataSerializationOptions
562 opt) 561 opt)
@@ -579,7 +578,7 @@ GNUNET_CONTAINER_meta_data_get_serialized_size (const struct
579 hdr->version = htonl (md == NULL ? 1 : 0); 578 hdr->version = htonl (md == NULL ? 1 : 0);
580 hdr->entries = htonl (ic); 579 hdr->entries = htonl (ic);
581 for (i = 0; i < ic; i++) 580 for (i = 0; i < ic; i++)
582 ((uint32_t *) &hdr[1])[i] = htonl ((uint32_t) md->items[i].type); 581 ((uint32_t *) & hdr[1])[i] = htonl ((uint32_t) md->items[i].type);
583 pos = sizeof (struct MetaDataHeader); 582 pos = sizeof (struct MetaDataHeader);
584 pos += sizeof (uint32_t) * ic; 583 pos += sizeof (uint32_t) * ic;
585 for (i = 0; i < ic; i++) 584 for (i = 0; i < ic; i++)
diff --git a/src/util/container_multihashmap.c b/src/util/container_multihashmap.c
index 2c88b1a52..e291b8b50 100644
--- a/src/util/container_multihashmap.c
+++ b/src/util/container_multihashmap.c
@@ -199,8 +199,7 @@ GNUNET_CONTAINER_multihashmap_iterate (const struct
199 e = map->map[i]; 199 e = map->map[i];
200 while (e != NULL) 200 while (e != NULL)
201 { 201 {
202 if ( (NULL != it) && 202 if ((NULL != it) && (GNUNET_OK != it (it_cls, &e->key, e->value)))
203 (GNUNET_OK != it (it_cls, &e->key, e->value)) )
204 return GNUNET_SYSERR; 203 return GNUNET_SYSERR;
205 count++; 204 count++;
206 e = e->next; 205 e = e->next;
@@ -235,8 +234,8 @@ GNUNET_CONTAINER_multihashmap_remove (struct GNUNET_CONTAINER_MultiHashMap
235 e = map->map[i]; 234 e = map->map[i];
236 while (e != NULL) 235 while (e != NULL)
237 { 236 {
238 if ( (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) && 237 if ((0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) &&
239 (value == e->value)) 238 (value == e->value))
240 { 239 {
241 if (p == NULL) 240 if (p == NULL)
242 map->map[i] = e->next; 241 map->map[i] = e->next;
@@ -354,7 +353,7 @@ grow (struct GNUNET_CONTAINER_MultiHashMap *map)
354 while (NULL != (e = old_map[i])) 353 while (NULL != (e = old_map[i]))
355 { 354 {
356 old_map[i] = e->next; 355 old_map[i] = e->next;
357 idx = idx_of (map, &e->key); 356 idx = idx_of (map, &e->key);
358 e->next = new_map[idx]; 357 e->next = new_map[idx];
359 new_map[idx] = e; 358 new_map[idx] = e;
360 } 359 }
@@ -386,8 +385,8 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
386 unsigned int i; 385 unsigned int i;
387 386
388 i = idx_of (map, key); 387 i = idx_of (map, key);
389 if ( (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) && 388 if ((opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE) &&
390 (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST) ) 389 (opt != GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST))
391 { 390 {
392 e = map->map[i]; 391 e = map->map[i];
393 while (e != NULL) 392 while (e != NULL)
@@ -405,7 +404,7 @@ GNUNET_CONTAINER_multihashmap_put (struct GNUNET_CONTAINER_MultiHashMap *map,
405 if (map->size / 3 >= map->map_length / 4) 404 if (map->size / 3 >= map->map_length / 4)
406 { 405 {
407 grow (map); 406 grow (map);
408 i = idx_of (map, key); 407 i = idx_of (map, key);
409 } 408 }
410 e = GNUNET_malloc (sizeof (struct MapEntry)); 409 e = GNUNET_malloc (sizeof (struct MapEntry));
411 e->key = *key; 410 e->key = *key;
@@ -443,8 +442,7 @@ GNUNET_CONTAINER_multihashmap_get_multiple (const struct
443 { 442 {
444 if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode))) 443 if (0 == memcmp (key, &e->key, sizeof (GNUNET_HashCode)))
445 { 444 {
446 if ( (it != NULL) && 445 if ((it != NULL) && (GNUNET_OK != it (it_cls, &e->key, e->value)))
447 (GNUNET_OK != it (it_cls, &e->key, e->value)) )
448 return GNUNET_SYSERR; 446 return GNUNET_SYSERR;
449 count++; 447 count++;
450 } 448 }
diff --git a/src/util/container_slist.c b/src/util/container_slist.c
index 3d96e26e2..4f5607a28 100644
--- a/src/util/container_slist.c
+++ b/src/util/container_slist.c
@@ -34,7 +34,7 @@ struct GNUNET_CONTAINER_SList_Elem
34{ 34{
35 /** 35 /**
36 * This is a linked list. 36 * This is a linked list.
37 */ 37 */
38 struct GNUNET_CONTAINER_SList_Elem *next; 38 struct GNUNET_CONTAINER_SList_Elem *next;
39 39
40 /** 40 /**
@@ -102,9 +102,8 @@ struct GNUNET_CONTAINER_SList_Iterator
102 * @return a new element 102 * @return a new element
103 */ 103 */
104static struct GNUNET_CONTAINER_SList_Elem * 104static struct GNUNET_CONTAINER_SList_Elem *
105create_elem (enum GNUNET_CONTAINER_SListDisposition disp, 105create_elem (enum GNUNET_CONTAINER_SListDisposition disp,
106 const void *buf, 106 const void *buf, size_t len)
107 size_t len)
108{ 107{
109 struct GNUNET_CONTAINER_SList_Elem *e; 108 struct GNUNET_CONTAINER_SList_Elem *e;
110 109
@@ -112,12 +111,12 @@ create_elem (enum GNUNET_CONTAINER_SListDisposition disp,
112 { 111 {
113 e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len); 112 e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem) + len);
114 memcpy (&e[1], buf, len); 113 memcpy (&e[1], buf, len);
115 e->elem = (void*) &e[1]; 114 e->elem = (void *) &e[1];
116 } 115 }
117 else 116 else
118 { 117 {
119 e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem)); 118 e = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_SList_Elem));
120 e->elem = (void*) buf; 119 e->elem = (void *) buf;
121 } 120 }
122 e->disp = disp; 121 e->disp = disp;
123 e->len = len; 122 e->len = len;
@@ -133,8 +132,8 @@ create_elem (enum GNUNET_CONTAINER_SListDisposition disp,
133 * @param len length of the buffer 132 * @param len length of the buffer
134 */ 133 */
135void 134void
136GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l, 135GNUNET_CONTAINER_slist_add (struct GNUNET_CONTAINER_SList *l,
137 enum GNUNET_CONTAINER_SListDisposition disp, 136 enum GNUNET_CONTAINER_SListDisposition disp,
138 const void *buf, size_t len) 137 const void *buf, size_t len)
139{ 138{
140 struct GNUNET_CONTAINER_SList_Elem *e; 139 struct GNUNET_CONTAINER_SList_Elem *e;
@@ -201,7 +200,7 @@ GNUNET_CONTAINER_slist_clear (struct GNUNET_CONTAINER_SList *l)
201 { 200 {
202 n = e->next; 201 n = e->next;
203 if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC) 202 if (e->disp == GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC)
204 GNUNET_free (e->elem); 203 GNUNET_free (e->elem);
205 GNUNET_free (e); 204 GNUNET_free (e);
206 e = n; 205 e = n;
207 } 206 }
@@ -224,8 +223,7 @@ GNUNET_CONTAINER_slist_contains (const struct GNUNET_CONTAINER_SList *l,
224 struct GNUNET_CONTAINER_SList_Elem *e; 223 struct GNUNET_CONTAINER_SList_Elem *e;
225 224
226 for (e = l->head; e != NULL; e = e->next) 225 for (e = l->head; e != NULL; e = e->next)
227 if ( (e->len == len) && 226 if ((e->len == len) && (memcmp (buf, e->elem, len) == 0))
228 (memcmp (buf, e->elem, len) == 0) )
229 return GNUNET_YES; 227 return GNUNET_YES;
230 return GNUNET_NO; 228 return GNUNET_NO;
231} 229}
@@ -275,8 +273,8 @@ GNUNET_CONTAINER_slist_erase (struct GNUNET_CONTAINER_SList_Iterator *i)
275 */ 273 */
276void 274void
277GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before, 275GNUNET_CONTAINER_slist_insert (struct GNUNET_CONTAINER_SList_Iterator *before,
278 enum GNUNET_CONTAINER_SListDisposition disp, 276 enum GNUNET_CONTAINER_SListDisposition disp,
279 const void *buf, size_t len) 277 const void *buf, size_t len)
280{ 278{
281 struct GNUNET_CONTAINER_SList_Elem *e; 279 struct GNUNET_CONTAINER_SList_Elem *e;
282 280
diff --git a/src/util/crypto_aes.c b/src/util/crypto_aes.c
index 6db932b5b..a44c2d133 100644
--- a/src/util/crypto_aes.c
+++ b/src/util/crypto_aes.c
@@ -76,9 +76,9 @@ ssize_t
76GNUNET_CRYPTO_aes_encrypt (const void *block, 76GNUNET_CRYPTO_aes_encrypt (const void *block,
77 size_t len, 77 size_t len,
78 const struct GNUNET_CRYPTO_AesSessionKey 78 const struct GNUNET_CRYPTO_AesSessionKey
79 *sessionkey, 79 * sessionkey,
80 const struct GNUNET_CRYPTO_AesInitializationVector 80 const struct GNUNET_CRYPTO_AesInitializationVector
81 *iv, void *result) 81 * iv, void *result)
82{ 82{
83 gcry_cipher_hd_t handle; 83 gcry_cipher_hd_t handle;
84 int rc; 84 int rc;
@@ -116,12 +116,12 @@ GNUNET_CRYPTO_aes_encrypt (const void *block,
116 * @return -1 on failure, size of decrypted block on success 116 * @return -1 on failure, size of decrypted block on success
117 */ 117 */
118ssize_t 118ssize_t
119GNUNET_CRYPTO_aes_decrypt (const void *block, 119GNUNET_CRYPTO_aes_decrypt (const void *block,
120 size_t size, 120 size_t size,
121 const struct GNUNET_CRYPTO_AesSessionKey 121 const struct GNUNET_CRYPTO_AesSessionKey
122 *sessionkey, 122 * sessionkey,
123 const struct GNUNET_CRYPTO_AesInitializationVector 123 const struct GNUNET_CRYPTO_AesInitializationVector
124 *iv, void *result) 124 * iv, void *result)
125{ 125{
126 gcry_cipher_hd_t handle; 126 gcry_cipher_hd_t handle;
127 int rc; 127 int rc;
diff --git a/src/util/crypto_hash.c b/src/util/crypto_hash.c
index 60e0ec5a2..3f5869489 100644
--- a/src/util/crypto_hash.c
+++ b/src/util/crypto_hash.c
@@ -359,12 +359,10 @@ sha512_final (struct sha512_ctx *sctx, unsigned char *hash)
359 * @param ret pointer to where to write the hashcode 359 * @param ret pointer to where to write the hashcode
360 */ 360 */
361void 361void
362GNUNET_CRYPTO_hash (const void *block, 362GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret)
363 size_t size,
364 GNUNET_HashCode * ret)
365{ 363{
366 struct sha512_ctx ctx; 364 struct sha512_ctx ctx;
367 365
368 sha512_init (&ctx); 366 sha512_init (&ctx);
369 sha512_update (&ctx, block, size); 367 sha512_update (&ctx, block, size);
370 sha512_final (&ctx, (unsigned char *) ret); 368 sha512_final (&ctx, (unsigned char *) ret);
@@ -416,7 +414,7 @@ struct FileHashContext
416 * Current offset. 414 * Current offset.
417 */ 415 */
418 uint64_t offset; 416 uint64_t offset;
419 417
420 /** 418 /**
421 * Run on shutdown? 419 * Run on shutdown?
422 */ 420 */
@@ -480,8 +478,7 @@ file_hash_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
480 GNUNET_SCHEDULER_add_after (tc->sched, 478 GNUNET_SCHEDULER_add_after (tc->sched,
481 fhc->run_on_shutdown, 479 fhc->run_on_shutdown,
482 GNUNET_SCHEDULER_PRIORITY_KEEP, 480 GNUNET_SCHEDULER_PRIORITY_KEEP,
483 GNUNET_SCHEDULER_NO_TASK, 481 GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc);
484 &file_hash_task, fhc);
485} 482}
486 483
487 484
@@ -523,8 +520,8 @@ GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
523 } 520 }
524 fhc->run_on_shutdown = run_on_shutdown; 521 fhc->run_on_shutdown = run_on_shutdown;
525 fhc->fh = GNUNET_DISK_file_open (filename, 522 fhc->fh = GNUNET_DISK_file_open (filename,
526 GNUNET_DISK_OPEN_READ, 523 GNUNET_DISK_OPEN_READ,
527 GNUNET_DISK_PERM_NONE); 524 GNUNET_DISK_PERM_NONE);
528 if (!fhc->fh) 525 if (!fhc->fh)
529 { 526 {
530 file_hash_finish (fhc, NULL); 527 file_hash_finish (fhc, NULL);
@@ -533,8 +530,7 @@ GNUNET_CRYPTO_hash_file (struct GNUNET_SCHEDULER_Handle *sched,
533 GNUNET_SCHEDULER_add_after (sched, 530 GNUNET_SCHEDULER_add_after (sched,
534 run_on_shutdown, 531 run_on_shutdown,
535 priority, 532 priority,
536 GNUNET_SCHEDULER_NO_TASK, 533 GNUNET_SCHEDULER_NO_TASK, &file_hash_task, fhc);
537 &file_hash_task, fhc);
538} 534}
539 535
540 536
@@ -662,18 +658,18 @@ GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
662} 658}
663 659
664void 660void
665GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode, GNUNET_HashCode * result) 661GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
662 GNUNET_HashCode * result)
666{ 663{
667 int i; 664 int i;
668 for (i = (sizeof (GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0; 665 for (i = (sizeof (GNUNET_HashCode) / sizeof (uint32_t)) - 1; i >= 0; i--)
669 i--) 666 result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, (uint32_t) - 1);
670 result->bits[i] = GNUNET_CRYPTO_random_u32 (mode, (uint32_t)-1);
671} 667}
672 668
673void 669void
674GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a, 670GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a,
675 const GNUNET_HashCode * b, 671 const GNUNET_HashCode * b,
676 GNUNET_HashCode * result) 672 GNUNET_HashCode * result)
677{ 673{
678 int i; 674 int i;
679 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; 675 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
@@ -683,8 +679,8 @@ GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a,
683 679
684void 680void
685GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a, 681GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a,
686 const GNUNET_HashCode * delta, 682 const GNUNET_HashCode * delta,
687 GNUNET_HashCode * result) 683 GNUNET_HashCode * result)
688{ 684{
689 int i; 685 int i;
690 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; 686 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
@@ -694,7 +690,7 @@ GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a,
694 690
695void 691void
696GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, 692GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a,
697 const GNUNET_HashCode * b, GNUNET_HashCode * result) 693 const GNUNET_HashCode * b, GNUNET_HashCode * result)
698{ 694{
699 int i; 695 int i;
700 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; 696 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
@@ -707,18 +703,18 @@ GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a,
707 */ 703 */
708void 704void
709GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc, 705GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
710 struct GNUNET_CRYPTO_AesSessionKey *skey, 706 struct GNUNET_CRYPTO_AesSessionKey *skey,
711 struct GNUNET_CRYPTO_AesInitializationVector 707 struct GNUNET_CRYPTO_AesInitializationVector
712 *iv) 708 *iv)
713{ 709{
714 GNUNET_assert (sizeof (GNUNET_HashCode) >= 710 GNUNET_assert (sizeof (GNUNET_HashCode) >=
715 GNUNET_CRYPTO_AES_KEY_LENGTH + 711 GNUNET_CRYPTO_AES_KEY_LENGTH +
716 sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); 712 sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
717 memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH); 713 memcpy (skey, hc, GNUNET_CRYPTO_AES_KEY_LENGTH);
718 skey->crc32 = 714 skey->crc32 =
719 htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH)); 715 htonl (GNUNET_CRYPTO_crc32_n (skey, GNUNET_CRYPTO_AES_KEY_LENGTH));
720 memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH], 716 memcpy (iv, &((char *) hc)[GNUNET_CRYPTO_AES_KEY_LENGTH],
721 sizeof (struct GNUNET_CRYPTO_AesInitializationVector)); 717 sizeof (struct GNUNET_CRYPTO_AesInitializationVector));
722} 718}
723 719
724/** 720/**
@@ -741,21 +737,21 @@ GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit)
741 */ 737 */
742int 738int
743GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, 739GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1,
744 const GNUNET_HashCode * h2) 740 const GNUNET_HashCode * h2)
745{ 741{
746 unsigned int *i1; 742 unsigned int *i1;
747 unsigned int *i2; 743 unsigned int *i2;
748 int i; 744 int i;
749 745
750 i1 = (unsigned int *) h1; 746 i1 = (unsigned int *) h1;
751 i2 = (unsigned int *) h2; 747 i2 = (unsigned int *) h2;
752 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0; 748 for (i = (sizeof (GNUNET_HashCode) / sizeof (unsigned int)) - 1; i >= 0;
753 i--) 749 i--)
754 { 750 {
755 if (i1[i] > i2[i]) 751 if (i1[i] > i2[i])
756 return 1; 752 return 1;
757 if (i1[i] < i2[i]) 753 if (i1[i] < i2[i])
758 return -1; 754 return -1;
759 } 755 }
760 return 0; 756 return 0;
761} 757}
@@ -767,21 +763,21 @@ GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1,
767 */ 763 */
768int 764int
769GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1, 765GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
770 const GNUNET_HashCode * h2, 766 const GNUNET_HashCode * h2,
771 const GNUNET_HashCode * target) 767 const GNUNET_HashCode * target)
772{ 768{
773 int i; 769 int i;
774 unsigned int d1; 770 unsigned int d1;
775 unsigned int d2; 771 unsigned int d2;
776 772
777 for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--) 773 for (i = sizeof (GNUNET_HashCode) / sizeof (unsigned int) - 1; i >= 0; i--)
778 { 774 {
779 d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i]; 775 d1 = ((unsigned int *) h1)[i] ^ ((unsigned int *) target)[i];
780 d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i]; 776 d2 = ((unsigned int *) h2)[i] ^ ((unsigned int *) target)[i];
781 if (d1 > d2) 777 if (d1 > d2)
782 return 1; 778 return 1;
783 else if (d1 < d2) 779 else if (d1 < d2)
784 return -1; 780 return -1;
785 } 781 }
786 return 0; 782 return 0;
787} 783}
diff --git a/src/util/crypto_ksk.c b/src/util/crypto_ksk.c
index 170974b2f..96f8140ad 100644
--- a/src/util/crypto_ksk.c
+++ b/src/util/crypto_ksk.c
@@ -774,11 +774,8 @@ static pid_t genproc;
774 * blocked gathering entropy. 774 * blocked gathering entropy.
775 */ 775 */
776static void 776static void
777entropy_generator (void *cls, 777entropy_generator (void *cls,
778 const char *what, 778 const char *what, int printchar, int current, int total)
779 int printchar,
780 int current,
781 int total)
782{ 779{
783 unsigned long code; 780 unsigned long code;
784 enum GNUNET_OS_ProcessStatusType type; 781 enum GNUNET_OS_ProcessStatusType type;
@@ -789,50 +786,45 @@ entropy_generator (void *cls,
789 if (current == total) 786 if (current == total)
790 { 787 {
791 if (genproc != 0) 788 if (genproc != 0)
792 { 789 {
793 if (0 != PLIBC_KILL(genproc, SIGTERM)) 790 if (0 != PLIBC_KILL (genproc, SIGTERM))
794 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 791 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill");
795 "kill"); 792 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
796 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); 793 genproc = 0;
797 genproc = 0; 794 }
798 }
799 return; 795 return;
800 } 796 }
801 if (genproc != 0) 797 if (genproc != 0)
802 { 798 {
803 ret = GNUNET_OS_process_status (genproc, 799 ret = GNUNET_OS_process_status (genproc, &type, &code);
804 &type,
805 &code);
806 if (ret == GNUNET_NO) 800 if (ret == GNUNET_NO)
807 return; /* still running */ 801 return; /* still running */
808 if (ret == GNUNET_SYSERR) 802 if (ret == GNUNET_SYSERR)
809 { 803 {
810 GNUNET_break (0); 804 GNUNET_break (0);
811 return; 805 return;
812 } 806 }
813 if (0 != PLIBC_KILL(genproc, SIGTERM)) 807 if (0 != PLIBC_KILL (genproc, SIGTERM))
814 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, 808 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "kill");
815 "kill");
816 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc)); 809 GNUNET_break (GNUNET_OK == GNUNET_OS_process_wait (genproc));
817 genproc = 0; 810 genproc = 0;
818 } 811 }
819 GNUNET_log(GNUNET_ERROR_TYPE_INFO, 812 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
820 _("Starting `%s' process to generate entropy\n"), 813 _("Starting `%s' process to generate entropy\n"), "find");
821 "find");
822 genproc = GNUNET_OS_start_process ("sh", 814 genproc = GNUNET_OS_start_process ("sh",
823 "sh", 815 "sh",
824 "-c", 816 "-c",
825 "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null", 817 "exec find / -mount -type f -exec cp {} /dev/null \\; 2>/dev/null",
826 NULL); 818 NULL);
827} 819}
828 820
829 821
830static void 822static void
831killfind () 823killfind ()
832{ 824{
833 if (genproc != 0) 825 if (genproc != 0)
834 { 826 {
835 PLIBC_KILL(genproc, SIGKILL); 827 PLIBC_KILL (genproc, SIGKILL);
836 genproc = 0; 828 genproc = 0;
837 } 829 }
838} 830}
diff --git a/src/util/crypto_random.c b/src/util/crypto_random.c
index 50af9f251..5d85d1daa 100644
--- a/src/util/crypto_random.c
+++ b/src/util/crypto_random.c
@@ -37,8 +37,7 @@
37 * @return a random value in the interval [0,i[. 37 * @return a random value in the interval [0,i[.
38 */ 38 */
39uint32_t 39uint32_t
40GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, 40GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i)
41 uint32_t i)
42{ 41{
43#ifdef gcry_fast_random_poll 42#ifdef gcry_fast_random_poll
44 static unsigned int invokeCount; 43 static unsigned int invokeCount;
@@ -55,8 +54,7 @@ GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
55 gcry_fast_random_poll (); 54 gcry_fast_random_poll ();
56#endif 55#endif
57 gcry_randomize ((unsigned char *) &ret, 56 gcry_randomize ((unsigned char *) &ret,
58 sizeof (uint32_t), 57 sizeof (uint32_t), GCRY_STRONG_RANDOM);
59 GCRY_STRONG_RANDOM);
60 return ret % i; 58 return ret % i;
61 } 59 }
62 else 60 else
@@ -108,8 +106,7 @@ GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n)
108 * @return random 64-bit number 106 * @return random 64-bit number
109 */ 107 */
110uint64_t 108uint64_t
111GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, 109GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max)
112 uint64_t max)
113{ 110{
114 uint64_t ret; 111 uint64_t ret;
115 112
@@ -117,8 +114,7 @@ GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
117 if (mode == GNUNET_CRYPTO_QUALITY_STRONG) 114 if (mode == GNUNET_CRYPTO_QUALITY_STRONG)
118 { 115 {
119 gcry_randomize ((unsigned char *) &ret, 116 gcry_randomize ((unsigned char *) &ret,
120 sizeof (uint64_t), 117 sizeof (uint64_t), GCRY_STRONG_RANDOM);
121 GCRY_STRONG_RANDOM);
122 return ret % max; 118 return ret % max;
123 } 119 }
124 else 120 else
@@ -144,8 +140,7 @@ GNUNET_CRYPTO_random_disable_entropy_gathering ()
144/** 140/**
145 * Initializer 141 * Initializer
146 */ 142 */
147void __attribute__ ((constructor)) 143void __attribute__ ((constructor)) GNUNET_util_random_init ()
148GNUNET_util_random_init()
149{ 144{
150 SRANDOM (time (NULL)); 145 SRANDOM (time (NULL));
151} 146}
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c
index cbd9f8f37..c3e0a7833 100644
--- a/src/util/crypto_rsa.c
+++ b/src/util/crypto_rsa.c
@@ -571,9 +571,13 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
571 return NULL; 571 return NULL;
572 while (GNUNET_YES != GNUNET_DISK_file_test (filename)) 572 while (GNUNET_YES != GNUNET_DISK_file_test (filename))
573 { 573 {
574 fd = GNUNET_DISK_file_open (filename, 574 fd = GNUNET_DISK_file_open (filename,
575 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_FAILIFEXISTS, 575 GNUNET_DISK_OPEN_WRITE |
576 GNUNET_DISK_PERM_USER_READ| GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_GROUP_READ); 576 GNUNET_DISK_OPEN_CREATE |
577 GNUNET_DISK_OPEN_FAILIFEXISTS,
578 GNUNET_DISK_PERM_USER_READ |
579 GNUNET_DISK_PERM_USER_WRITE |
580 GNUNET_DISK_PERM_GROUP_READ);
577 if (NULL == fd) 581 if (NULL == fd)
578 { 582 {
579 if (errno == EEXIST) 583 if (errno == EEXIST)
@@ -584,7 +588,11 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
584 } 588 }
585 cnt = 0; 589 cnt = 0;
586 590
587 while (GNUNET_YES != GNUNET_DISK_file_lock (fd, 0, sizeof (struct RsaPrivateKeyBinaryEncoded), GNUNET_YES)) 591 while (GNUNET_YES !=
592 GNUNET_DISK_file_lock (fd, 0,
593 sizeof (struct
594 RsaPrivateKeyBinaryEncoded),
595 GNUNET_YES))
588 { 596 {
589 sleep (1); 597 sleep (1);
590 if (0 == ++cnt % 10) 598 if (0 == ++cnt % 10)
@@ -602,13 +610,17 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
602 GNUNET_assert (ret != NULL); 610 GNUNET_assert (ret != NULL);
603 enc = rsa_encode_key (ret); 611 enc = rsa_encode_key (ret);
604 GNUNET_assert (enc != NULL); 612 GNUNET_assert (enc != NULL);
605 GNUNET_assert (ntohs (enc->len) == GNUNET_DISK_file_write (fd, enc, ntohs (enc->len))); 613 GNUNET_assert (ntohs (enc->len) ==
614 GNUNET_DISK_file_write (fd, enc, ntohs (enc->len)));
606 GNUNET_free (enc); 615 GNUNET_free (enc);
607 616
608 GNUNET_DISK_file_sync (fd); 617 GNUNET_DISK_file_sync (fd);
609 if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct RsaPrivateKeyBinaryEncoded))) 618 if (GNUNET_YES !=
610 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 619 GNUNET_DISK_file_unlock (fd, 0,
611 "fcntl", filename); 620 sizeof (struct
621 RsaPrivateKeyBinaryEncoded)))
622 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl",
623 filename);
612 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 624 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
613 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 625 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
614 _("Stored new private key in `%s'.\n"), filename); 626 _("Stored new private key in `%s'.\n"), filename);
@@ -616,7 +628,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
616 } 628 }
617 /* hostkey file exists already, read it! */ 629 /* hostkey file exists already, read it! */
618 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ, 630 fd = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READ,
619 GNUNET_DISK_PERM_NONE); 631 GNUNET_DISK_PERM_NONE);
620 if (NULL == fd) 632 if (NULL == fd)
621 { 633 {
622 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename); 634 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", filename);
@@ -625,7 +637,10 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
625 cnt = 0; 637 cnt = 0;
626 while (1) 638 while (1)
627 { 639 {
628 if (GNUNET_YES != GNUNET_DISK_file_lock (fd, 0, sizeof (struct RsaPrivateKeyBinaryEncoded), GNUNET_NO)) 640 if (GNUNET_YES !=
641 GNUNET_DISK_file_lock (fd, 0,
642 sizeof (struct RsaPrivateKeyBinaryEncoded),
643 GNUNET_NO))
629 { 644 {
630 if (0 == ++cnt % 10) 645 if (0 == ++cnt % 10)
631 { 646 {
@@ -645,9 +660,12 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
645 /* eh, what!? File we opened is now gone!? */ 660 /* eh, what!? File we opened is now gone!? */
646 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 661 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
647 "stat", filename); 662 "stat", filename);
648 if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct RsaPrivateKeyBinaryEncoded))) 663 if (GNUNET_YES !=
649 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 664 GNUNET_DISK_file_unlock (fd, 0,
650 "fcntl", filename); 665 sizeof (struct
666 RsaPrivateKeyBinaryEncoded)))
667 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl",
668 filename);
651 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd)); 669 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fd));
652 670
653 return NULL; 671 return NULL;
@@ -658,9 +676,12 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
658 { 676 {
659 /* maybe we got the read lock before the hostkey generating 677 /* maybe we got the read lock before the hostkey generating
660 process had a chance to get the write lock; give it up! */ 678 process had a chance to get the write lock; give it up! */
661 if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct RsaPrivateKeyBinaryEncoded))) 679 if (GNUNET_YES !=
662 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 680 GNUNET_DISK_file_unlock (fd, 0,
663 "fcntl", filename); 681 sizeof (struct
682 RsaPrivateKeyBinaryEncoded)))
683 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl",
684 filename);
664 if (0 == ++cnt % 10) 685 if (0 == ++cnt % 10)
665 { 686 {
666 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 687 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -690,7 +711,9 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename)
690 filename); 711 filename);
691 } 712 }
692 GNUNET_free (enc); 713 GNUNET_free (enc);
693 if (GNUNET_YES != GNUNET_DISK_file_unlock (fd, 0, sizeof (struct RsaPrivateKeyBinaryEncoded))) 714 if (GNUNET_YES !=
715 GNUNET_DISK_file_unlock (fd, 0,
716 sizeof (struct RsaPrivateKeyBinaryEncoded)))
694 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); 717 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename);
695 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd)); 718 GNUNET_assert (GNUNET_YES == GNUNET_DISK_file_close (fd));
696 return ret; 719 return ret;
@@ -758,10 +781,9 @@ GNUNET_CRYPTO_rsa_encrypt (const void *block,
758 * @return the size of the decrypted block, -1 on error 781 * @return the size of the decrypted block, -1 on error
759 */ 782 */
760ssize_t 783ssize_t
761GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key, 784GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey * key,
762 const struct GNUNET_CRYPTO_RsaEncryptedData *block, 785 const struct GNUNET_CRYPTO_RsaEncryptedData *
763 void *result, 786 block, void *result, size_t max)
764 size_t max)
765{ 787{
766 gcry_sexp_t resultsexp; 788 gcry_sexp_t resultsexp;
767 gcry_sexp_t data; 789 gcry_sexp_t data;
diff --git a/src/util/disk.c b/src/util/disk.c
index b1b631a7f..9f93a1ee2 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -79,7 +79,7 @@ struct GNUNET_DISK_PipeHandle
79 /** 79 /**
80 * File descriptors for the pipe. 80 * File descriptors for the pipe.
81 */ 81 */
82 struct GNUNET_DISK_FileHandle * fd[2]; 82 struct GNUNET_DISK_FileHandle *fd[2];
83}; 83};
84 84
85 85
@@ -171,8 +171,8 @@ GNUNET_DISK_handle_invalid (const struct GNUNET_DISK_FileHandle *h)
171 * @return the new position on success, GNUNET_SYSERR otherwise 171 * @return the new position on success, GNUNET_SYSERR otherwise
172 */ 172 */
173off_t 173off_t
174GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset, 174GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle * h, off_t offset,
175 enum GNUNET_DISK_Seek whence) 175 enum GNUNET_DISK_Seek whence)
176{ 176{
177 if (h == NULL) 177 if (h == NULL)
178 { 178 {
@@ -182,8 +182,9 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset,
182 182
183#ifdef MINGW 183#ifdef MINGW
184 DWORD ret; 184 DWORD ret;
185 static DWORD t[] = { [GNUNET_DISK_SEEK_SET] = FILE_BEGIN, 185 static DWORD t[] = {[GNUNET_DISK_SEEK_SET] = FILE_BEGIN,
186 [GNUNET_DISK_SEEK_CUR] = FILE_CURRENT, [GNUNET_DISK_SEEK_END] = FILE_END }; 186 [GNUNET_DISK_SEEK_CUR] = FILE_CURRENT,[GNUNET_DISK_SEEK_END] = FILE_END
187 };
187 188
188 ret = SetFilePointer (h->h, offset, NULL, t[whence]); 189 ret = SetFilePointer (h->h, offset, NULL, t[whence]);
189 if (ret == INVALID_SET_FILE_POINTER) 190 if (ret == INVALID_SET_FILE_POINTER)
@@ -193,8 +194,9 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset,
193 } 194 }
194 return ret; 195 return ret;
195#else 196#else
196 static int t[] = { [GNUNET_DISK_SEEK_SET] = SEEK_SET, 197 static int t[] = {[GNUNET_DISK_SEEK_SET] = SEEK_SET,
197 [GNUNET_DISK_SEEK_CUR] = SEEK_CUR, [GNUNET_DISK_SEEK_END] = SEEK_END }; 198 [GNUNET_DISK_SEEK_CUR] = SEEK_CUR,[GNUNET_DISK_SEEK_END] = SEEK_END
199 };
198 200
199 return lseek (h->fd, offset, t[whence]); 201 return lseek (h->fd, offset, t[whence]);
200#endif 202#endif
@@ -215,8 +217,7 @@ GNUNET_DISK_file_seek (const struct GNUNET_DISK_FileHandle *h, off_t offset,
215 */ 217 */
216int 218int
217GNUNET_DISK_file_size (const char *filename, 219GNUNET_DISK_file_size (const char *filename,
218 uint64_t *size, 220 uint64_t * size, int includeSymLinks)
219 int includeSymLinks)
220{ 221{
221 struct GetFileSizeData gfsd; 222 struct GetFileSizeData gfsd;
222 int ret; 223 int ret;
@@ -245,27 +246,24 @@ GNUNET_DISK_file_size (const char *filename,
245 * @param ino set to the inode ID 246 * @param ino set to the inode ID
246 * @return GNUNET_OK on success 247 * @return GNUNET_OK on success
247 */ 248 */
248int GNUNET_DISK_file_get_identifiers (const char *filename, 249int
249 uint32_t *dev, 250GNUNET_DISK_file_get_identifiers (const char *filename,
250 uint64_t *ino) 251 uint32_t * dev, uint64_t * ino)
251{ 252{
252#if LINUX 253#if LINUX
253 struct stat sbuf; 254 struct stat sbuf;
254 struct statvfs fbuf; 255 struct statvfs fbuf;
255 256
256 if ( (0 == stat(filename, 257 if ((0 == stat (filename, &sbuf)) && (0 == statvfs (filename, &fbuf)))
257 &sbuf)) &&
258 (0 == statvfs (filename,
259 &fbuf) ) )
260 { 258 {
261 *dev = (uint32_t) fbuf.f_fsid; 259 *dev = (uint32_t) fbuf.f_fsid;
262 *ino = (uint64_t) sbuf.st_ino; 260 *ino = (uint64_t) sbuf.st_ino;
263 return GNUNET_OK; 261 return GNUNET_OK;
264 } 262 }
265#endif 263#endif
266 return GNUNET_SYSERR; 264 return GNUNET_SYSERR;
267} 265}
268 266
269 267
270/** 268/**
271 * Create an (empty) temporary file on disk. 269 * Create an (empty) temporary file on disk.
@@ -286,12 +284,7 @@ GNUNET_DISK_mktemp (const char *t)
286 tmpdir = getenv ("TMPDIR"); 284 tmpdir = getenv ("TMPDIR");
287 tmpdir = tmpdir ? tmpdir : "/tmp"; 285 tmpdir = tmpdir ? tmpdir : "/tmp";
288 286
289 GNUNET_asprintf (&tmpl, 287 GNUNET_asprintf (&tmpl, "%s%s%s%s", tmpdir, DIR_SEPARATOR_STR, t, "XXXXXX");
290 "%s%s%s%s",
291 tmpdir,
292 DIR_SEPARATOR_STR,
293 t,
294 "XXXXXX");
295#ifdef MINGW 288#ifdef MINGW
296 fn = (char *) GNUNET_malloc (MAX_PATH + 1); 289 fn = (char *) GNUNET_malloc (MAX_PATH + 1);
297 plibc_conv_to_win_path (tmpl, fn); 290 plibc_conv_to_win_path (tmpl, fn);
@@ -302,16 +295,12 @@ GNUNET_DISK_mktemp (const char *t)
302 fd = mkstemp (fn); 295 fd = mkstemp (fn);
303 if (fd == -1) 296 if (fd == -1)
304 { 297 {
305 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 298 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn);
306 "mkstemp",
307 fn);
308 GNUNET_free (fn); 299 GNUNET_free (fn);
309 return NULL; 300 return NULL;
310 } 301 }
311 if (0 != CLOSE (fd)) 302 if (0 != CLOSE (fd))
312 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, 303 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "close", fn);
313 "close",
314 fn);
315 return fn; 304 return fn;
316} 305}
317 306
@@ -348,8 +337,8 @@ GNUNET_DISK_get_blocks_available (const char *part)
348 if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy)) 337 if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy))
349 { 338 {
350 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 339 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
351 _("`%s' failed for drive `%s': %u\n"), 340 _("`%s' failed for drive `%s': %u\n"),
352 "GetDiskFreeSpace", szDrive, GetLastError ()); 341 "GetDiskFreeSpace", szDrive, GetLastError ());
353 342
354 return -1; 343 return -1;
355 } 344 }
@@ -564,8 +553,8 @@ GNUNET_DISK_directory_create_for_file (const char *filename)
564 * @return the number of bytes read on success, GNUNET_SYSERR on failure 553 * @return the number of bytes read on success, GNUNET_SYSERR on failure
565 */ 554 */
566ssize_t 555ssize_t
567GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result, 556GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle * h, void *result,
568 size_t len) 557 size_t len)
569{ 558{
570 if (h == NULL) 559 if (h == NULL)
571 { 560 {
@@ -597,19 +586,17 @@ GNUNET_DISK_file_read (const struct GNUNET_DISK_FileHandle *h, void *result,
597 * @return number of bytes read, GNUNET_SYSERR on failure 586 * @return number of bytes read, GNUNET_SYSERR on failure
598 */ 587 */
599ssize_t 588ssize_t
600GNUNET_DISK_fn_read (const char * fn, 589GNUNET_DISK_fn_read (const char *fn, void *result, size_t len)
601 void *result,
602 size_t len)
603{ 590{
604 struct GNUNET_DISK_FileHandle *fh; 591 struct GNUNET_DISK_FileHandle *fh;
605 ssize_t ret; 592 ssize_t ret;
606 593
607 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ, 594 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_READ,
608 GNUNET_DISK_PERM_NONE); 595 GNUNET_DISK_PERM_NONE);
609 if (!fh) 596 if (!fh)
610 return GNUNET_SYSERR; 597 return GNUNET_SYSERR;
611 ret = GNUNET_DISK_file_read (fh, result, len); 598 ret = GNUNET_DISK_file_read (fh, result, len);
612 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); 599 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
613 600
614 return ret; 601 return ret;
615} 602}
@@ -623,8 +610,8 @@ GNUNET_DISK_fn_read (const char * fn,
623 * @return number of bytes written on success, GNUNET_SYSERR on error 610 * @return number of bytes written on success, GNUNET_SYSERR on error
624 */ 611 */
625ssize_t 612ssize_t
626GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, const void *buffer, 613GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle * h,
627 size_t n) 614 const void *buffer, size_t n)
628{ 615{
629 if (h == NULL) 616 if (h == NULL)
630 { 617 {
@@ -657,21 +644,20 @@ GNUNET_DISK_file_write (const struct GNUNET_DISK_FileHandle *h, const void *buff
657 * @return number of bytes written on success, GNUNET_SYSERR on error 644 * @return number of bytes written on success, GNUNET_SYSERR on error
658 */ 645 */
659ssize_t 646ssize_t
660GNUNET_DISK_fn_write (const char * fn, const void *buffer, 647GNUNET_DISK_fn_write (const char *fn, const void *buffer,
661 size_t n, 648 size_t n, enum GNUNET_DISK_AccessPermissions mode)
662 enum GNUNET_DISK_AccessPermissions mode)
663{ 649{
664 struct GNUNET_DISK_FileHandle *fh; 650 struct GNUNET_DISK_FileHandle *fh;
665 ssize_t ret; 651 ssize_t ret;
666 652
667 fh = GNUNET_DISK_file_open (fn, 653 fh = GNUNET_DISK_file_open (fn,
668 GNUNET_DISK_OPEN_WRITE 654 GNUNET_DISK_OPEN_WRITE
669 | GNUNET_DISK_OPEN_TRUNCATE 655 | GNUNET_DISK_OPEN_TRUNCATE
670 | GNUNET_DISK_OPEN_CREATE, mode); 656 | GNUNET_DISK_OPEN_CREATE, mode);
671 if (!fh) 657 if (!fh)
672 return GNUNET_SYSERR; 658 return GNUNET_SYSERR;
673 ret = GNUNET_DISK_file_write (fh, buffer, n); 659 ret = GNUNET_DISK_file_write (fh, buffer, n);
674 GNUNET_assert(GNUNET_OK == GNUNET_DISK_file_close(fh)); 660 GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh));
675 return ret; 661 return ret;
676} 662}
677 663
@@ -688,7 +674,7 @@ GNUNET_DISK_fn_write (const char * fn, const void *buffer,
688int 674int
689GNUNET_DISK_directory_scan (const char *dirName, 675GNUNET_DISK_directory_scan (const char *dirName,
690 GNUNET_FileNameCallback callback, 676 GNUNET_FileNameCallback callback,
691 void *callback_cls) 677 void *callback_cls)
692{ 678{
693 DIR *dinfo; 679 DIR *dinfo;
694 struct dirent *finfo; 680 struct dirent *finfo;
@@ -954,9 +940,7 @@ GNUNET_DISK_directory_remove (const char *fileName)
954 return GNUNET_SYSERR; 940 return GNUNET_SYSERR;
955 } 941 }
956 if (GNUNET_SYSERR == 942 if (GNUNET_SYSERR ==
957 GNUNET_DISK_directory_scan (fileName, 943 GNUNET_DISK_directory_scan (fileName, &remove_helper, NULL))
958 &remove_helper,
959 NULL))
960 return GNUNET_SYSERR; 944 return GNUNET_SYSERR;
961 if (0 != RMDIR (fileName)) 945 if (0 != RMDIR (fileName))
962 { 946 {
@@ -988,13 +972,16 @@ GNUNET_DISK_file_copy (const char *src, const char *dst)
988 return GNUNET_SYSERR; 972 return GNUNET_SYSERR;
989 pos = 0; 973 pos = 0;
990 in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ, 974 in = GNUNET_DISK_file_open (src, GNUNET_DISK_OPEN_READ,
991 GNUNET_DISK_PERM_NONE); 975 GNUNET_DISK_PERM_NONE);
992 if (!in) 976 if (!in)
993 return GNUNET_SYSERR; 977 return GNUNET_SYSERR;
994 out = GNUNET_DISK_file_open (dst, GNUNET_DISK_OPEN_WRITE 978 out = GNUNET_DISK_file_open (dst, GNUNET_DISK_OPEN_WRITE
995 | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_FAILIFEXISTS, 979 | GNUNET_DISK_OPEN_CREATE |
996 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE 980 GNUNET_DISK_OPEN_FAILIFEXISTS,
997 | GNUNET_DISK_PERM_GROUP_READ | GNUNET_DISK_PERM_GROUP_WRITE); 981 GNUNET_DISK_PERM_USER_READ |
982 GNUNET_DISK_PERM_USER_WRITE |
983 GNUNET_DISK_PERM_GROUP_READ |
984 GNUNET_DISK_PERM_GROUP_WRITE);
998 if (!out) 985 if (!out)
999 { 986 {
1000 GNUNET_DISK_file_close (in); 987 GNUNET_DISK_file_close (in);
@@ -1089,7 +1076,7 @@ GNUNET_DISK_file_change_owner (const char *filename, const char *user)
1089 */ 1076 */
1090int 1077int
1091GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart, 1078GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
1092 off_t lockEnd, int excl) 1079 off_t lockEnd, int excl)
1093{ 1080{
1094 if (fh == NULL) 1081 if (fh == NULL)
1095 { 1082 {
@@ -1100,7 +1087,7 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
1100#ifndef MINGW 1087#ifndef MINGW
1101 struct flock fl; 1088 struct flock fl;
1102 1089
1103 memset (&fl, 0, sizeof(struct flock)); 1090 memset (&fl, 0, sizeof (struct flock));
1104 fl.l_type = excl ? F_WRLCK : F_RDLCK; 1091 fl.l_type = excl ? F_WRLCK : F_RDLCK;
1105 fl.l_whence = SEEK_SET; 1092 fl.l_whence = SEEK_SET;
1106 fl.l_start = lockStart; 1093 fl.l_start = lockStart;
@@ -1110,11 +1097,12 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
1110#else 1097#else
1111 OVERLAPPED o; 1098 OVERLAPPED o;
1112 1099
1113 memset (&o, 0, sizeof(OVERLAPPED)); 1100 memset (&o, 0, sizeof (OVERLAPPED));
1114 o.Offset = lockStart; 1101 o.Offset = lockStart;
1115 1102
1116 if (!LockFileEx (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0) 1103 if (!LockFileEx (fh->h, (excl ? LOCKFILE_EXCLUSIVE_LOCK : 0)
1117 | LOCKFILE_FAIL_IMMEDIATELY, 0, lockEnd - lockStart, 0, &o)) 1104 | LOCKFILE_FAIL_IMMEDIATELY, 0, lockEnd - lockStart, 0,
1105 &o))
1118 { 1106 {
1119 SetErrnoFromWinError (GetLastError ()); 1107 SetErrnoFromWinError (GetLastError ());
1120 return GNUNET_SYSERR; 1108 return GNUNET_SYSERR;
@@ -1134,7 +1122,7 @@ GNUNET_DISK_file_lock (struct GNUNET_DISK_FileHandle *fh, off_t lockStart,
1134 */ 1122 */
1135int 1123int
1136GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart, 1124GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart,
1137 off_t unlockEnd) 1125 off_t unlockEnd)
1138{ 1126{
1139 if (fh == NULL) 1127 if (fh == NULL)
1140 { 1128 {
@@ -1145,7 +1133,7 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart,
1145#ifndef MINGW 1133#ifndef MINGW
1146 struct flock fl; 1134 struct flock fl;
1147 1135
1148 memset (&fl, 0, sizeof(struct flock)); 1136 memset (&fl, 0, sizeof (struct flock));
1149 fl.l_type = F_UNLCK; 1137 fl.l_type = F_UNLCK;
1150 fl.l_whence = SEEK_SET; 1138 fl.l_whence = SEEK_SET;
1151 fl.l_start = unlockStart; 1139 fl.l_start = unlockStart;
@@ -1155,7 +1143,7 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart,
1155#else 1143#else
1156 OVERLAPPED o; 1144 OVERLAPPED o;
1157 1145
1158 memset (&o, 0, sizeof(OVERLAPPED)); 1146 memset (&o, 0, sizeof (OVERLAPPED));
1159 o.Offset = unlockStart; 1147 o.Offset = unlockStart;
1160 1148
1161 if (!UnlockFileEx (fh->h, 0, unlockEnd - unlockStart, 0, &o)) 1149 if (!UnlockFileEx (fh->h, 0, unlockEnd - unlockStart, 0, &o))
@@ -1183,8 +1171,8 @@ GNUNET_DISK_file_unlock (struct GNUNET_DISK_FileHandle *fh, off_t unlockStart,
1183 */ 1171 */
1184struct GNUNET_DISK_FileHandle * 1172struct GNUNET_DISK_FileHandle *
1185GNUNET_DISK_file_open (const char *fn, 1173GNUNET_DISK_file_open (const char *fn,
1186 enum GNUNET_DISK_OpenFlags flags, 1174 enum GNUNET_DISK_OpenFlags flags,
1187 enum GNUNET_DISK_AccessPermissions perm) 1175 enum GNUNET_DISK_AccessPermissions perm)
1188{ 1176{
1189 char *expfn; 1177 char *expfn;
1190 struct GNUNET_DISK_FileHandle *ret; 1178 struct GNUNET_DISK_FileHandle *ret;
@@ -1203,7 +1191,7 @@ GNUNET_DISK_file_open (const char *fn,
1203#ifndef MINGW 1191#ifndef MINGW
1204 mode = 0; 1192 mode = 0;
1205 if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE)) 1193 if (GNUNET_DISK_OPEN_READWRITE == (flags & GNUNET_DISK_OPEN_READWRITE))
1206 oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */ 1194 oflags = O_RDWR; /* note: O_RDWR is NOT always O_RDONLY | O_WRONLY */
1207 else if (flags & GNUNET_DISK_OPEN_READ) 1195 else if (flags & GNUNET_DISK_OPEN_READ)
1208 oflags = O_RDONLY; 1196 oflags = O_RDONLY;
1209 else if (flags & GNUNET_DISK_OPEN_WRITE) 1197 else if (flags & GNUNET_DISK_OPEN_WRITE)
@@ -1245,11 +1233,11 @@ GNUNET_DISK_file_open (const char *fn,
1245 1233
1246 fd = open (expfn, oflags | O_LARGEFILE, mode); 1234 fd = open (expfn, oflags | O_LARGEFILE, mode);
1247 if (fd == -1) 1235 if (fd == -1)
1248 { 1236 {
1249 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn); 1237 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn);
1250 GNUNET_free (expfn); 1238 GNUNET_free (expfn);
1251 return NULL; 1239 return NULL;
1252 } 1240 }
1253#else 1241#else
1254 access = 0; 1242 access = 0;
1255 disp = OPEN_ALWAYS; 1243 disp = OPEN_ALWAYS;
@@ -1277,33 +1265,35 @@ GNUNET_DISK_file_open (const char *fn,
1277 disp = TRUNCATE_EXISTING; 1265 disp = TRUNCATE_EXISTING;
1278 } 1266 }
1279 else 1267 else
1280 { 1268 {
1281 disp = OPEN_ALWAYS; 1269 disp = OPEN_ALWAYS;
1282 } 1270 }
1283 1271
1284 /* TODO: access priviledges? */ 1272 /* TODO: access priviledges? */
1285 h = CreateFile (expfn, access, FILE_SHARE_DELETE | FILE_SHARE_READ 1273 h = CreateFile (expfn, access, FILE_SHARE_DELETE | FILE_SHARE_READ
1286 | FILE_SHARE_WRITE, NULL, disp, FILE_ATTRIBUTE_NORMAL, NULL); 1274 | FILE_SHARE_WRITE, NULL, disp, FILE_ATTRIBUTE_NORMAL,
1275 NULL);
1287 if (h == INVALID_HANDLE_VALUE) 1276 if (h == INVALID_HANDLE_VALUE)
1288 {
1289 SetErrnoFromWinError (GetLastError ());
1290 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn);
1291 GNUNET_free (expfn);
1292 return NULL;
1293 }
1294
1295 if (flags & GNUNET_DISK_OPEN_APPEND)
1296 if (SetFilePointer (h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER)
1297 { 1277 {
1298 SetErrnoFromWinError (GetLastError ()); 1278 SetErrnoFromWinError (GetLastError ());
1299 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "SetFilePointer", expfn); 1279 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "open", expfn);
1300 CloseHandle (h);
1301 GNUNET_free (expfn); 1280 GNUNET_free (expfn);
1302 return NULL; 1281 return NULL;
1303 } 1282 }
1283
1284 if (flags & GNUNET_DISK_OPEN_APPEND)
1285 if (SetFilePointer (h, 0, 0, FILE_END) == INVALID_SET_FILE_POINTER)
1286 {
1287 SetErrnoFromWinError (GetLastError ());
1288 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "SetFilePointer",
1289 expfn);
1290 CloseHandle (h);
1291 GNUNET_free (expfn);
1292 return NULL;
1293 }
1304#endif 1294#endif
1305 1295
1306 ret = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle)); 1296 ret = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle));
1307#ifdef MINGW 1297#ifdef MINGW
1308 ret->h = h; 1298 ret->h = h;
1309#else 1299#else
@@ -1330,19 +1320,19 @@ GNUNET_DISK_file_close (struct GNUNET_DISK_FileHandle *h)
1330 1320
1331#if MINGW 1321#if MINGW
1332 if (!CloseHandle (h->h)) 1322 if (!CloseHandle (h->h))
1333 { 1323 {
1334 SetErrnoFromWinError (GetLastError ()); 1324 SetErrnoFromWinError (GetLastError ());
1335 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close"); 1325 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close");
1336 GNUNET_free (h); 1326 GNUNET_free (h);
1337 return GNUNET_SYSERR; 1327 return GNUNET_SYSERR;
1338 } 1328 }
1339#else 1329#else
1340 if (close (h->fd) != 0) 1330 if (close (h->fd) != 0)
1341 { 1331 {
1342 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close"); 1332 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "close");
1343 GNUNET_free (h); 1333 GNUNET_free (h);
1344 return GNUNET_SYSERR; 1334 return GNUNET_SYSERR;
1345 } 1335 }
1346#endif 1336#endif
1347 GNUNET_free (h); 1337 GNUNET_free (h);
1348 return GNUNET_OK; 1338 return GNUNET_OK;
@@ -1454,8 +1444,9 @@ struct GNUNET_DISK_MapHandle
1454 * @return pointer to the mapped memory region, NULL on failure 1444 * @return pointer to the mapped memory region, NULL on failure
1455 */ 1445 */
1456void * 1446void *
1457GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK_MapHandle **m, 1447GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h,
1458 enum GNUNET_DISK_MapType access, size_t len) 1448 struct GNUNET_DISK_MapHandle **m,
1449 enum GNUNET_DISK_MapType access, size_t len)
1459{ 1450{
1460 if (h == NULL) 1451 if (h == NULL)
1461 { 1452 {
@@ -1467,7 +1458,7 @@ GNUNET_DISK_file_map (const struct GNUNET_DISK_FileHandle *h, struct GNUNET_DISK
1467 DWORD mapAccess, protect; 1458 DWORD mapAccess, protect;
1468 void *ret; 1459 void *ret;
1469 1460
1470 if ((access & GNUNET_DISK_MAP_TYPE_READ) && 1461 if ((access & GNUNET_DISK_MAP_TYPE_READ) &&
1471 (access & GNUNET_DISK_MAP_TYPE_WRITE)) 1462 (access & GNUNET_DISK_MAP_TYPE_WRITE))
1472 { 1463 {
1473 protect = PAGE_READWRITE; 1464 protect = PAGE_READWRITE;
@@ -1594,7 +1585,9 @@ GNUNET_DISK_pipe (int blocking)
1594 struct GNUNET_DISK_PipeHandle *p; 1585 struct GNUNET_DISK_PipeHandle *p;
1595 struct GNUNET_DISK_FileHandle *fds; 1586 struct GNUNET_DISK_FileHandle *fds;
1596 1587
1597 p = GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) + 2 * sizeof (struct GNUNET_DISK_FileHandle)); 1588 p =
1589 GNUNET_malloc (sizeof (struct GNUNET_DISK_PipeHandle) +
1590 2 * sizeof (struct GNUNET_DISK_FileHandle));
1598 fds = (struct GNUNET_DISK_FileHandle *) &p[1]; 1591 fds = (struct GNUNET_DISK_FileHandle *) &p[1];
1599 p->fd[0] = &fds[0]; 1592 p->fd[0] = &fds[0];
1600 p->fd[1] = &fds[1]; 1593 p->fd[1] = &fds[1];
@@ -1620,27 +1613,27 @@ GNUNET_DISK_pipe (int blocking)
1620 flags |= O_NONBLOCK; 1613 flags |= O_NONBLOCK;
1621 ret = fcntl (fd[0], F_SETFL, flags); 1614 ret = fcntl (fd[0], F_SETFL, flags);
1622 if (ret != -1) 1615 if (ret != -1)
1623 { 1616 {
1624 flags = fcntl (fd[1], F_GETFL); 1617 flags = fcntl (fd[1], F_GETFL);
1625 flags |= O_NONBLOCK; 1618 flags |= O_NONBLOCK;
1626 ret = fcntl (fd[1], F_SETFL, flags); 1619 ret = fcntl (fd[1], F_SETFL, flags);
1627 } 1620 }
1628 if (ret == -1) 1621 if (ret == -1)
1629 { 1622 {
1630 eno = errno; 1623 eno = errno;
1631 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "fcntl"); 1624 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fcntl");
1632 GNUNET_break (0 == close (p->fd[0]->fd)); 1625 GNUNET_break (0 == close (p->fd[0]->fd));
1633 GNUNET_break (0 == close (p->fd[1]->fd)); 1626 GNUNET_break (0 == close (p->fd[1]->fd));
1634 GNUNET_free (p); 1627 GNUNET_free (p);
1635 errno = eno; 1628 errno = eno;
1636 return NULL; 1629 return NULL;
1637 } 1630 }
1638 } 1631 }
1639#else 1632#else
1640 BOOL ret; 1633 BOOL ret;
1641 1634
1642 ret = CreatePipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0); 1635 ret = CreatePipe (&p->fd[0]->h, &p->fd[1]->h, NULL, 0);
1643 if (! ret) 1636 if (!ret)
1644 { 1637 {
1645 GNUNET_free (p); 1638 GNUNET_free (p);
1646 SetErrnoFromWinError (GetLastError ()); 1639 SetErrnoFromWinError (GetLastError ());
@@ -1649,10 +1642,10 @@ GNUNET_DISK_pipe (int blocking)
1649 if (!blocking) 1642 if (!blocking)
1650 { 1643 {
1651 DWORD mode; 1644 DWORD mode;
1652 1645
1653 mode = PIPE_NOWAIT; 1646 mode = PIPE_NOWAIT;
1654 p->fd[0] = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle)); 1647 p->fd[0] = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle));
1655 p->fd[1] = GNUNET_malloc(sizeof(struct GNUNET_DISK_FileHandle)); 1648 p->fd[1] = GNUNET_malloc (sizeof (struct GNUNET_DISK_FileHandle));
1656 SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL); 1649 SetNamedPipeHandleState (p->fd[0]->h, &mode, NULL, NULL);
1657 SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL); 1650 SetNamedPipeHandleState (p->fd[1]->h, &mode, NULL, NULL);
1658 /* this always fails on Windows 95, so we don't care about error handling */ 1651 /* this always fails on Windows 95, so we don't care about error handling */
@@ -1673,7 +1666,7 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
1673{ 1666{
1674 int ret = GNUNET_OK; 1667 int ret = GNUNET_OK;
1675 int save; 1668 int save;
1676 1669
1677#ifdef MINGW 1670#ifdef MINGW
1678 if (!CloseHandle (p->fd[0]->h)) 1671 if (!CloseHandle (p->fd[0]->h))
1679 { 1672 {
@@ -1711,8 +1704,8 @@ GNUNET_DISK_pipe_close (struct GNUNET_DISK_PipeHandle *p)
1711 * @param n end to access 1704 * @param n end to access
1712 */ 1705 */
1713const struct GNUNET_DISK_FileHandle * 1706const struct GNUNET_DISK_FileHandle *
1714GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p, 1707GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p,
1715 enum GNUNET_DISK_PipeEnd n) 1708 enum GNUNET_DISK_PipeEnd n)
1716{ 1709{
1717 switch (n) 1710 switch (n)
1718 { 1711 {
@@ -1736,15 +1729,14 @@ GNUNET_DISK_pipe_handle (const struct GNUNET_DISK_PipeHandle *p,
1736 */ 1729 */
1737int 1730int
1738GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, 1731GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh,
1739 void *dst, 1732 void *dst, size_t dst_len)
1740 size_t dst_len)
1741{ 1733{
1742#ifdef MINGW 1734#ifdef MINGW
1743 if (dst_len < sizeof (HANDLE)) 1735 if (dst_len < sizeof (HANDLE))
1744 return GNUNET_SYSERR; 1736 return GNUNET_SYSERR;
1745 *((HANDLE *) dst) = fh->h; 1737 *((HANDLE *) dst) = fh->h;
1746#else 1738#else
1747 if (dst_len < sizeof(int)) 1739 if (dst_len < sizeof (int))
1748 return GNUNET_SYSERR; 1740 return GNUNET_SYSERR;
1749 *((int *) dst) = fh->fd; 1741 *((int *) dst) = fh->fd;
1750#endif 1742#endif
diff --git a/src/util/disk.h b/src/util/disk.h
index 96324e120..21c1ab9a1 100644
--- a/src/util/disk.h
+++ b/src/util/disk.h
@@ -16,41 +16,40 @@
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/** 21/**
22 * @file util/disk.h 22 * @file util/disk.h
23 * @brief Internal DISK related helper functions 23 * @brief Internal DISK related helper functions
24 * @author Nils Durner 24 * @author Nils Durner
25 */ 25 */
26 26
27
28#ifndef GNUNET_DISK_H_ 27#ifndef GNUNET_DISK_H_
29#define GNUNET_DISK_H_ 28#define GNUNET_DISK_H_
30 29
31#include "gnunet_disk_lib.h" 30#include "gnunet_disk_lib.h"
32 31
33
34/** 32/**
35 * Handle used to access files (and pipes). 33 * Handle used to access files (and pipes).
36 */ 34 */
37struct GNUNET_DISK_FileHandle 35struct GNUNET_DISK_FileHandle
38{ 36{
37
39#ifdef MINGW 38#ifdef MINGW
40 /** 39 /**
41 * File handle under W32. 40 * File handle under W32.
42 */ 41 */
43 HANDLE h; 42 HANDLE h;
44#else 43
44#else /* */
45 /** 45 /**
46 * File handle on other OSes. 46 * File handle on other OSes.
47 */ 47 */
48 int fd; 48 int fd;
49#endif 49
50}; 50#endif /* */
51 51};
52 52
53
54/** 53/**
55 * Retrieve OS file handle 54 * Retrieve OS file handle
56 * 55 *
@@ -59,9 +58,8 @@ struct GNUNET_DISK_FileHandle
59 * @param dst destination buffer 58 * @param dst destination buffer
60 * @param dst_len length of dst 59 * @param dst_len length of dst
61 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 60 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
62 */ 61 */
63int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle *fh, 62int GNUNET_DISK_internal_file_handle_ (const struct GNUNET_DISK_FileHandle
64 void *dst, 63 *fh, void *dst, size_t dst_len);
65 size_t dst_len); 64
66 65#endif /* GNUNET_DISK_H_ */
67#endif /* GNUNET_DISK_H_ */
diff --git a/src/util/gnunet-service-resolver.c b/src/util/gnunet-service-resolver.c
index 1dce5cedc..f8dd2e166 100644
--- a/src/util/gnunet-service-resolver.c
+++ b/src/util/gnunet-service-resolver.c
@@ -44,7 +44,7 @@ struct IPCache
44 * This is a linked list. 44 * This is a linked list.
45 */ 45 */
46 struct IPCache *next; 46 struct IPCache *next;
47 47
48 /** 48 /**
49 * Hostname in human-readable form. 49 * Hostname in human-readable form.
50 */ 50 */
@@ -54,7 +54,7 @@ struct IPCache
54 * Hostname in binary format. 54 * Hostname in binary format.
55 */ 55 */
56 struct sockaddr *sa; 56 struct sockaddr *sa;
57 57
58 /** 58 /**
59 * Last time this entry was updated. 59 * Last time this entry was updated.
60 */ 60 */
@@ -89,11 +89,9 @@ getnameinfo_resolve (struct IPCache *cache)
89{ 89{
90 char hostname[256]; 90 char hostname[256];
91 91
92 if (0 == getnameinfo (cache->sa, 92 if (0 == getnameinfo (cache->sa,
93 cache->salen, 93 cache->salen,
94 hostname, 94 hostname, sizeof (hostname), NULL, 0, 0))
95 sizeof(hostname),
96 NULL, 0, 0))
97 cache->addr = GNUNET_strdup (hostname); 95 cache->addr = GNUNET_strdup (hostname);
98} 96}
99#endif 97#endif
@@ -273,7 +271,7 @@ getaddrinfo_resolve (struct GNUNET_SERVER_TransmitContext *tc,
273 // FIXME NILS 271 // FIXME NILS
274 1 272 1
275#endif 273#endif
276 ) 274 )
277 return GNUNET_NO; /* other function may still succeed */ 275 return GNUNET_NO; /* other function may still succeed */
278 return GNUNET_SYSERR; 276 return GNUNET_SYSERR;
279 } 277 }
diff --git a/src/util/network.c b/src/util/network.c
index 071b18cc6..df3c90c81 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -16,90 +16,94 @@
16 along with GNUnet; see the file COPYING. If not, write to the 16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330, 17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. 18 Boston, MA 02111-1307, USA.
19*/ 19*/
20 20
21/** 21/**
22 * @file util/network.c 22 * @file util/network.c
23 * @brief basic, low-level networking interface 23 * @brief basic, low-level networking interface
24 * @author Nils Durner 24 * @author Nils Durner
25 */ 25 */
26 26
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_disk_lib.h" 28#include "gnunet_disk_lib.h"
29#include "disk.h" 29#include "disk.h"
30#include "gnunet_container_lib.h" 30#include "gnunet_container_lib.h"
31 31
32#define DEBUG_NETWORK GNUNET_NO 32#define DEBUG_NETWORK GNUNET_NO
33 33
34#ifndef INVALID_SOCKET 34#ifndef INVALID_SOCKET
35#define INVALID_SOCKET -1 35#define INVALID_SOCKET -1
36#endif 36#endif /* */
37 37 struct GNUNET_NETWORK_Handle
38struct GNUNET_NETWORK_Handle 38{
39{ 39 int fd;
40 int fd; 40 };
41}; 41 struct GNUNET_NETWORK_FDSet
42 42{
43struct GNUNET_NETWORK_FDSet 43
44{ 44 /* socket descriptors */
45 /* socket descriptors */ 45 int nsds;
46 int nsds; 46 fd_set sds;
47 fd_set sds; 47
48#ifdef WINDOWS 48#ifdef WINDOWS
49 /* handles */ 49 /* handles */
50 struct GNUNET_CONTAINER_SList *handles; 50 struct GNUNET_CONTAINER_SList *handles;
51#endif 51
52}; 52#endif /* */
53 53};
54
54#ifndef FD_COPY 55#ifndef FD_COPY
55#define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set))) 56#define FD_COPY(s, d) (memcpy ((d), (s), sizeof (fd_set)))
56#endif 57#endif /* */
57 58
58
59
60/** 59/**
61 * Set if a socket should use blocking or non-blocking IO. 60 * Set if a socket should use blocking or non-blocking IO.
62 * @param fd socket 61 * @param fd socket
63 * @param doBlock blocking mode 62 * @param doBlock blocking mode
64 * @return GNUNET_OK on success, GNUNET_SYSERR on error 63 * @return GNUNET_OK on success, GNUNET_SYSERR on error
65 */ 64 */
66static int 65static int
67socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, 66socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, int doBlock)
68 int doBlock) 67{
69{ 68
70#if MINGW 69#if MINGW
71 u_long mode; 70 u_long mode;
72 mode = !doBlock; 71 mode = !doBlock;
73 if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR) 72 if (ioctlsocket (fd->fd, FIONBIO, &mode) == SOCKET_ERROR)
74 { 73
75 SetErrnoFromWinsockError (WSAGetLastError ()); 74 {
76 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket"); 75 SetErrnoFromWinsockError (WSAGetLastError ());
77 return GNUNET_SYSERR; 76 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "ioctlsocket");
78 } 77 return GNUNET_SYSERR;
79 return GNUNET_OK; 78 }
80 79 return GNUNET_OK;
81#else 80
82 /* not MINGW */ 81#else /* */
83 int flags = fcntl (fd->fd, F_GETFL); 82 /* not MINGW */
84 if (flags == -1) 83 int flags = fcntl (fd->fd, F_GETFL);
85 { 84 if (flags == -1)
86 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); 85
87 return GNUNET_SYSERR; 86 {
88 } 87 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
89 if (doBlock) 88 return GNUNET_SYSERR;
90 flags &= ~O_NONBLOCK; 89 }
91 else 90 if (doBlock)
92 flags |= O_NONBLOCK; 91 flags &= ~O_NONBLOCK;
93 if (0 != fcntl (fd->fd, F_SETFL, flags)) 92
94 { 93 else
95 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl"); 94 flags |= O_NONBLOCK;
96 return GNUNET_SYSERR; 95 if (0 != fcntl (fd->fd, F_SETFL, flags))
97 } 96
98 return GNUNET_OK; 97 {
99#endif 98 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "fcntl");
100} 99 return GNUNET_SYSERR;
101 100 }
102 101 return GNUNET_OK;
102
103#endif /* */
104}
105
106
103#ifndef MINGW 107#ifndef MINGW
104/** 108/**
105 * Make a socket non-inheritable to child processes 109 * Make a socket non-inheritable to child processes
@@ -107,62 +111,56 @@ socket_set_blocking (struct GNUNET_NETWORK_Handle *fd,
107 * @param h the socket to make non-inheritable 111 * @param h the socket to make non-inheritable
108 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 112 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
109 * @warning Not implemented on Windows 113 * @warning Not implemented on Windows
110 */ 114 */
111static int 115static int
112socket_set_inheritable (const struct GNUNET_NETWORK_Handle 116socket_set_inheritable (const struct GNUNET_NETWORK_Handle *h)
113 *h) 117{
114{ 118 int i;
115 int i; 119 i = fcntl (h->fd, F_GETFD);
116 120 if (i == (i | FD_CLOEXEC))
117 i = fcntl (h->fd, F_GETFD); 121 return GNUNET_OK;
118 if (i == (i | FD_CLOEXEC)) 122 return (fcntl (h->fd, F_SETFD, i | FD_CLOEXEC) == 0)
119 return GNUNET_OK; 123 ? GNUNET_OK : GNUNET_SYSERR;
120 return (fcntl (h->fd, F_SETFD, i | FD_CLOEXEC) == 0) 124 }
121 ? GNUNET_OK : GNUNET_SYSERR; 125
122} 126
123#endif 127#endif /* */
124 128
125
126
127#ifdef DARWIN 129#ifdef DARWIN
128/** 130/**
129 * The MSG_NOSIGNAL equivalent on Mac OS X 131 * The MSG_NOSIGNAL equivalent on Mac OS X
130 * 132 *
131 * @param h the socket to make non-delaying 133 * @param h the socket to make non-delaying
132 */ 134 */
133static void 135static void
134socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle 136socket_set_nosigpipe (const struct GNUNET_NETWORK_Handle *h)
135 *h) 137{
136{ 138 int value = 1;
137 int value = 1; 139 if (0 !=
138 if (0 != setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof(value))) 140 setsockopt (h->fd, SOL_SOCKET, SO_NOSIGPIPE, &value, sizeof (value)))
139 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 141 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
140 "setsockopt"); 142 }
141} 143
142#endif 144
143 145#endif /* */
144 146
145
146/** 147/**
147 * Disable delays when sending data via the socket. 148 * Disable delays when sending data via the socket.
148 * (GNUnet makes sure that messages are as big as 149 * (GNUnet makes sure that messages are as big as
149 * possible already). 150 * possible already).
150 * 151 *
151 * @param h the socket to make non-delaying 152 * @param h the socket to make non-delaying
152 */ 153 */
153static void 154static void
154socket_set_nodelay (const struct GNUNET_NETWORK_Handle 155socket_set_nodelay (const struct GNUNET_NETWORK_Handle *h)
155 *h) 156{
156{ 157 int value = 1;
157 int value = 1; 158 if (0 !=
158 if (0 != setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof(value))) 159 setsockopt (h->fd, IPPROTO_TCP, TCP_NODELAY, &value, sizeof (value)))
159 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 160 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "setsockopt");
160 "setsockopt"); 161 }
161 162
162} 163
163
164
165
166/** 164/**
167 * accept a new connection on a socket 165 * accept a new connection on a socket
168 * 166 *
@@ -170,124 +168,142 @@ socket_set_nodelay (const struct GNUNET_NETWORK_Handle
170 * @param address address of the connecting peer, may be NULL 168 * @param address address of the connecting peer, may be NULL
171 * @param address_len length of address 169 * @param address_len length of address
172 * @return client socket 170 * @return client socket
173 */ 171 */
174struct GNUNET_NETWORK_Handle * 172struct GNUNET_NETWORK_Handle *
175GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, 173GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
176 struct sockaddr *address, 174 struct sockaddr *address,
177 socklen_t * address_len) 175 socklen_t * address_len)
178{ 176{
179 struct GNUNET_NETWORK_Handle *ret; 177 struct GNUNET_NETWORK_Handle *ret;
180 178 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
181 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); 179 ret->fd = accept (desc->fd, address, address_len);
182 ret->fd = accept (desc->fd, address, address_len); 180 if (ret->fd == INVALID_SOCKET)
183 if (ret->fd == INVALID_SOCKET) 181
184 { 182 {
183
185#ifdef MINGW 184#ifdef MINGW
186 SetErrnoFromWinsockError (WSAGetLastError ()); 185 SetErrnoFromWinsockError (WSAGetLastError ());
187#endif 186
188 GNUNET_free (ret); 187#endif /* */
189 return NULL; 188 GNUNET_free (ret);
190 } 189 return NULL;
190 }
191
191#ifndef MINGW 192#ifndef MINGW
192 if (ret->fd >= FD_SETSIZE) 193 if (ret->fd >= FD_SETSIZE)
193 { 194
194 GNUNET_break (0 == close (ret->fd)); 195 {
195 GNUNET_free (ret); 196 GNUNET_break (0 == close (ret->fd));
196 errno = EMFILE; 197 GNUNET_free (ret);
197 return NULL; 198 errno = EMFILE;
198 } 199 return NULL;
199#endif 200 }
200 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) 201
201 { 202#endif /* */
202 /* we might want to treat this one as fatal... */ 203 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
203 GNUNET_break (0); 204
204 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); 205 {
205 return NULL; 206
206 } 207 /* we might want to treat this one as fatal... */
208 GNUNET_break (0);
209 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
210 return NULL;
211 }
212
207#ifndef MINGW 213#ifndef MINGW
208 if (GNUNET_OK != socket_set_inheritable (ret)) 214 if (GNUNET_OK != socket_set_inheritable (ret))
209 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 215 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
210 "socket_set_inheritable"); 216 "socket_set_inheritable");
211#endif 217
218#endif /* */
212#ifdef DARWIN 219#ifdef DARWIN
213 socket_set_nosigpipe (ret); 220 socket_set_nosigpipe (ret);
214#endif 221
215 socket_set_nodelay (ret); 222#endif /* */
216 return ret; 223 socket_set_nodelay (ret);
217} 224 return ret;
218 225 }
226
227
219/** 228/**
220 * Bind to a connected socket 229 * Bind to a connected socket
221 * @param desc socket 230 * @param desc socket
222 * @param address address to be bound 231 * @param address address to be bound
223 * @param address_len length of address 232 * @param address_len length of address
224 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 233 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
225 */ 234 */
226int 235int
227GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, 236GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
228 const struct sockaddr *address, 237 const struct sockaddr *address,
229 socklen_t address_len) 238 socklen_t address_len)
230{ 239{
231 int ret; 240 int ret;
232 241 ret = bind (desc->fd, address, address_len);
233 ret = bind (desc->fd, address, address_len); 242
234#ifdef MINGW 243#ifdef MINGW
235 if (SOCKET_ERROR == ret) 244 if (SOCKET_ERROR == ret)
236 SetErrnoFromWinsockError (WSAGetLastError ()); 245 SetErrnoFromWinsockError (WSAGetLastError ());
237#endif 246
238 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; 247#endif /* */
239} 248 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
240 249 }
241 250
251
242/** 252/**
243 * Close a socket 253 * Close a socket
244 * @param desc socket 254 * @param desc socket
245 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 255 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
246 */ 256 */
247int 257int
248GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) 258GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc)
249{ 259{
250 int ret; 260 int ret;
251 int eno; 261 int eno;
252 262
253#ifdef MINGW 263#ifdef MINGW
254 ret = closesocket (desc->fd); 264 ret = closesocket (desc->fd);
255 SetErrnoFromWinsockError (WSAGetLastError ()); 265 SetErrnoFromWinsockError (WSAGetLastError ());
256#else 266
257 ret = close (desc->fd); 267#else /* */
258#endif 268 ret = close (desc->fd);
259 eno = errno; 269
260 GNUNET_free (desc); 270#endif /* */
261 errno = eno; 271 eno = errno;
262 return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; 272 GNUNET_free (desc);
263} 273 errno = eno;
264 274 return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
275 }
276
277
265/** 278/**
266 * Connect a socket 279 * Connect a socket
267 * @param desc socket 280 * @param desc socket
268 * @param address peer address 281 * @param address peer address
269 * @param address_len length of address 282 * @param address_len length of address
270 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 283 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
271 */ 284 */
272int 285int
273GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, 286GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
274 const struct sockaddr *address, 287 const struct sockaddr *address,
275 socklen_t address_len) 288 socklen_t address_len)
276{ 289{
277 int ret; 290 int ret;
278 291 ret = connect (desc->fd, address, address_len);
279 ret = connect (desc->fd, address, address_len); 292
280#ifdef MINGW 293#ifdef MINGW
281 if (SOCKET_ERROR == ret) 294 if (SOCKET_ERROR == ret)
282 { 295
283 SetErrnoFromWinsockError (WSAGetLastError ()); 296 {
284 if (errno == EWOULDBLOCK) 297 SetErrnoFromWinsockError (WSAGetLastError ());
285 errno = EINPROGRESS; 298 if (errno == EWOULDBLOCK)
286 } 299 errno = EINPROGRESS;
287#endif 300 }
288 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; 301
289} 302#endif /* */
290 303 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
304 }
305
306
291/** 307/**
292 * Get socket options 308 * Get socket options
293 * 309 *
@@ -297,71 +313,78 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc,
297 * @param optval options 313 * @param optval options
298 * @param optlen length of optval 314 * @param optlen length of optval
299 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 315 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
300 */ 316 */
301int 317int
302GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc, 318GNUNET_NETWORK_socket_getsockopt (const struct GNUNET_NETWORK_Handle *desc,
303 int level, int optname, void *optval, 319 int level, int optname, void *optval,
304 socklen_t * optlen) 320 socklen_t * optlen)
305{ 321{
306 int ret; 322 int ret;
307 323 ret = getsockopt (desc->fd, level, optname, optval, optlen);
308 ret = getsockopt (desc->fd, level, optname, optval, optlen); 324
309#ifdef MINGW 325#ifdef MINGW
310 if (ret == 0 && level == SOL_SOCKET && optname == SO_ERROR) 326 if (ret == 0 && level == SOL_SOCKET && optname == SO_ERROR)
311 *((int *) optval) = GetErrnoFromWinsockError (*((int *) optval)); 327 *((int *) optval) = GetErrnoFromWinsockError (*((int *) optval));
312 else if (SOCKET_ERROR == ret) 328
313 SetErrnoFromWinsockError (WSAGetLastError ()); 329 else if (SOCKET_ERROR == ret)
314#endif 330 SetErrnoFromWinsockError (WSAGetLastError ());
315 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; 331
316} 332#endif /* */
317 333 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
334 }
335
336
318/** 337/**
319 * Listen on a socket 338 * Listen on a socket
320 * @param desc socket 339 * @param desc socket
321 * @param backlog length of the listen queue 340 * @param backlog length of the listen queue
322 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 341 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
323 */ 342 */
324int 343int
325GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc, 344GNUNET_NETWORK_socket_listen (const struct GNUNET_NETWORK_Handle *desc,
326 int backlog) 345 int backlog)
327{ 346{
328 int ret; 347 int ret;
329 348 ret = listen (desc->fd, backlog);
330 ret = listen (desc->fd, backlog); 349
331#ifdef MINGW 350#ifdef MINGW
332 if (SOCKET_ERROR == ret) 351 if (SOCKET_ERROR == ret)
333 SetErrnoFromWinsockError (WSAGetLastError ()); 352 SetErrnoFromWinsockError (WSAGetLastError ());
334#endif 353
335 354#endif /* */
336 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; 355 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
337} 356 }
338 357
358
339/** 359/**
340 * Read data from a connected socket (always non-blocking). 360 * Read data from a connected socket (always non-blocking).
341 * @param desc socket 361 * @param desc socket
342 * @param buffer buffer 362 * @param buffer buffer
343 * @param length length of buffer 363 * @param length length of buffer
344 */ 364 */
345ssize_t 365 ssize_t
346GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc, 366GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc,
347 void *buffer, size_t length) 367 void *buffer, size_t length)
348{ 368{
349 int ret; 369 int ret;
350 int flags; 370 int flags;
351 371 flags = 0;
352 flags = 0; 372
353#ifdef MSG_DONTWAIT 373#ifdef MSG_DONTWAIT
354 flags |= MSG_DONTWAIT; 374 flags |= MSG_DONTWAIT;
355#endif 375
356 ret = recv (desc->fd, buffer, length, flags); 376#endif /* */
377 ret = recv (desc->fd, buffer, length, flags);
378
357#ifdef MINGW 379#ifdef MINGW
358 if (SOCKET_ERROR == ret) 380 if (SOCKET_ERROR == ret)
359 SetErrnoFromWinsockError (WSAGetLastError ()); 381 SetErrnoFromWinsockError (WSAGetLastError ());
360#endif 382
361 383#endif /* */
362 return ret; 384 return ret;
363} 385 }
364 386
387
365/** 388/**
366 * Send data (always non-blocking). 389 * Send data (always non-blocking).
367 * 390 *
@@ -369,31 +392,34 @@ GNUNET_NETWORK_socket_recv (const struct GNUNET_NETWORK_Handle * desc,
369 * @param buffer data to send 392 * @param buffer data to send
370 * @param length size of the buffer 393 * @param length size of the buffer
371 * @return number of bytes sent, GNUNET_SYSERR on error 394 * @return number of bytes sent, GNUNET_SYSERR on error
372 */ 395 */
373ssize_t 396 ssize_t
374GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc, 397GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc,
375 const void *buffer, size_t length) 398 const void *buffer, size_t length)
376{ 399{
377 int ret; 400 int ret;
378 int flags; 401 int flags;
379 402 flags = 0;
380 flags = 0; 403
381#ifdef MSG_DONTWAIT 404#ifdef MSG_DONTWAIT
382 flags |= MSG_DONTWAIT; 405 flags |= MSG_DONTWAIT;
383#endif 406
407#endif /* */
384#ifdef MSG_NOSIGNAL 408#ifdef MSG_NOSIGNAL
385 flags |= MSG_NOSIGNAL; 409 flags |= MSG_NOSIGNAL;
386#endif 410
387 ret = send (desc->fd, buffer, length, flags); 411#endif /* */
412 ret = send (desc->fd, buffer, length, flags);
413
388#ifdef MINGW 414#ifdef MINGW
389 if (SOCKET_ERROR == ret) 415 if (SOCKET_ERROR == ret)
390 SetErrnoFromWinsockError (WSAGetLastError ()); 416 SetErrnoFromWinsockError (WSAGetLastError ());
391#endif 417
392 418#endif /* */
393 return ret; 419 return ret;
394} 420 }
395 421
396 422
397/** 423/**
398 * Send data to a particular destination (always non-blocking). 424 * Send data to a particular destination (always non-blocking).
399 * This function only works for UDP sockets. 425 * This function only works for UDP sockets.
@@ -404,32 +430,36 @@ GNUNET_NETWORK_socket_send (const struct GNUNET_NETWORK_Handle * desc,
404 * @param dest_addr destination address 430 * @param dest_addr destination address
405 * @param dest_len length of address 431 * @param dest_len length of address
406 * @return number of bytes sent, GNUNET_SYSERR on error 432 * @return number of bytes sent, GNUNET_SYSERR on error
407 */ 433 */
408ssize_t 434 ssize_t
409GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, 435GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc,
410 const void *message, size_t length, 436 const void *message, size_t length,
411 const struct sockaddr * dest_addr, 437 const struct sockaddr * dest_addr,
412 socklen_t dest_len) 438 socklen_t dest_len)
413{ 439{
414 int ret; 440 int ret;
415 int flags; 441 int flags;
416 442 flags = 0;
417 flags = 0; 443
418#ifdef MSG_DONTWAIT 444#ifdef MSG_DONTWAIT
419 flags |= MSG_DONTWAIT; 445 flags |= MSG_DONTWAIT;
420#endif 446
447#endif /* */
421#ifdef MSG_NOSIGNAL 448#ifdef MSG_NOSIGNAL
422 flags |= MSG_NOSIGNAL; 449 flags |= MSG_NOSIGNAL;
423#endif 450
424 ret = sendto (desc->fd, message, length, flags, dest_addr, dest_len); 451#endif /* */
452 ret = sendto (desc->fd, message, length, flags, dest_addr, dest_len);
453
425#ifdef MINGW 454#ifdef MINGW
426 if (SOCKET_ERROR == ret) 455 if (SOCKET_ERROR == ret)
427 SetErrnoFromWinsockError (WSAGetLastError ()); 456 SetErrnoFromWinsockError (WSAGetLastError ());
428#endif 457
429 458#endif /* */
430 return ret; 459 return ret;
431} 460 }
432 461
462
433/** 463/**
434 * Set socket option 464 * Set socket option
435 * @param fd socket 465 * @param fd socket
@@ -438,26 +468,25 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc,
438 * @param option_value value to set 468 * @param option_value value to set
439 * @param option_len size of option_value 469 * @param option_len size of option_value
440 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 470 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
441 */ 471 */
442int 472int
443GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd, 473GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd,
444 int level, int option_name, 474 int level, int option_name,
445 const void *option_value, 475 const void *option_value,
446 socklen_t option_len) 476 socklen_t option_len)
447{ 477{
448 int ret; 478 int ret;
449 479 ret = setsockopt (fd->fd, level, option_name, option_value, option_len);
450 ret = setsockopt (fd->fd, level, option_name, option_value, option_len); 480
451#ifdef MINGW 481#ifdef MINGW
452 if (SOCKET_ERROR == ret) 482 if (SOCKET_ERROR == ret)
453 SetErrnoFromWinsockError (WSAGetLastError ()); 483 SetErrnoFromWinsockError (WSAGetLastError ());
454#endif 484
455 485#endif /* */
456 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; 486 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
457} 487 }
458 488
459 489
460
461/** 490/**
462 * Create a new socket. Configure it for non-blocking IO and 491 * Create a new socket. Configure it for non-blocking IO and
463 * mark it as non-inheritable to child processes (set the 492 * mark it as non-inheritable to child processes (set the
@@ -467,282 +496,297 @@ GNUNET_NETWORK_socket_setsockopt (struct GNUNET_NETWORK_Handle *fd,
467 * @param type socket type 496 * @param type socket type
468 * @param protocol network protocol 497 * @param protocol network protocol
469 * @return new socket, NULL on error 498 * @return new socket, NULL on error
470 */ 499 */
471struct GNUNET_NETWORK_Handle * 500struct GNUNET_NETWORK_Handle *
472GNUNET_NETWORK_socket_create (int domain, int type, int protocol) 501GNUNET_NETWORK_socket_create (int domain, int type, int protocol)
473{ 502{
474 struct GNUNET_NETWORK_Handle *ret; 503 struct GNUNET_NETWORK_Handle *ret;
475 504 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle));
476 ret = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_Handle)); 505 ret->fd = socket (domain, type, protocol);
477 ret->fd = socket (domain, type, protocol); 506 if (INVALID_SOCKET == ret->fd)
478 if (INVALID_SOCKET == ret->fd) 507
479 { 508 {
509
480#ifdef MINGW 510#ifdef MINGW
481 SetErrnoFromWinsockError (WSAGetLastError ()); 511 SetErrnoFromWinsockError (WSAGetLastError ());
482#endif 512
483 GNUNET_free (ret); 513#endif /* */
484 return NULL; 514 GNUNET_free (ret);
485 } 515 return NULL;
516 }
517
486#ifndef MINGW 518#ifndef MINGW
487 if (ret->fd >= FD_SETSIZE) 519 if (ret->fd >= FD_SETSIZE)
488 { 520
489 GNUNET_break (0 == close (ret->fd)); 521 {
490 GNUNET_free (ret); 522 GNUNET_break (0 == close (ret->fd));
491 errno = EMFILE; 523 GNUNET_free (ret);
492 return NULL; 524 errno = EMFILE;
493 } 525 return NULL;
494#endif 526 }
495 527
496 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO)) 528#endif /* */
497 { 529 if (GNUNET_SYSERR == socket_set_blocking (ret, GNUNET_NO))
498 /* we might want to treat this one as fatal... */ 530
499 GNUNET_break (0); 531 {
500 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret)); 532
501 return NULL; 533 /* we might want to treat this one as fatal... */
502 } 534 GNUNET_break (0);
535 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (ret));
536 return NULL;
537 }
538
503#ifndef MINGW 539#ifndef MINGW
504 if (GNUNET_OK != socket_set_inheritable (ret)) 540 if (GNUNET_OK != socket_set_inheritable (ret))
505 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 541 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
506 "socket_set_inheritable"); 542 "socket_set_inheritable");
507#endif 543
544#endif /* */
508#ifdef DARWIN 545#ifdef DARWIN
509 socket_set_nosigpipe (ret); 546 socket_set_nosigpipe (ret);
510#endif 547
511 if (type == SOCK_STREAM) 548#endif /* */
512 socket_set_nodelay (ret); 549 if (type == SOCK_STREAM)
513 550 socket_set_nodelay (ret);
514 return ret; 551 return ret;
515} 552 }
516 553
554
517/** 555/**
518 * Shut down socket operations 556 * Shut down socket operations
519 * @param desc socket 557 * @param desc socket
520 * @param how type of shutdown 558 * @param how type of shutdown
521 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise 559 * @return GNUNET_OK on success, GNUNET_SYSERR otherwise
522 */ 560 */
523int 561int
524GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc, 562GNUNET_NETWORK_socket_shutdown (struct GNUNET_NETWORK_Handle *desc,
525 int how) 563 int how)
526{ 564{
527 int ret; 565 int ret;
528 566 ret = shutdown (desc->fd, how);
529 ret = shutdown (desc->fd, how); 567
530#ifdef MINGW 568#ifdef MINGW
531 if (ret != 0) 569 if (ret != 0)
532 SetErrnoFromWinsockError (WSAGetLastError ()); 570 SetErrnoFromWinsockError (WSAGetLastError ());
533#endif 571
534 572#endif /* */
535 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR; 573 return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
536} 574 }
537 575
538 576
539/** 577/**
540 * Reset FD set 578 * Reset FD set
541 * @param fds fd set 579 * @param fds fd set
542 */ 580 */
543void 581void
544GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds) 582GNUNET_NETWORK_fdset_zero (struct GNUNET_NETWORK_FDSet *fds)
545{ 583{
546 FD_ZERO (&fds->sds); 584 FD_ZERO (&fds->sds);
547 fds->nsds = 0; 585 fds->nsds = 0;
586
548#ifdef MINGW 587#ifdef MINGW
549 GNUNET_CONTAINER_slist_clear (fds->handles); 588 GNUNET_CONTAINER_slist_clear (fds->handles);
550#endif 589
551} 590#endif /* */
552 591}
553 592
554/** 593/**
555 * Add a socket to the FD set 594 * Add a socket to the FD set
556 * @param fds fd set 595 * @param fds fd set
557 * @param desc socket to add 596 * @param desc socket to add
558 */ 597 */
559void 598void
560GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds, 599GNUNET_NETWORK_fdset_set (struct GNUNET_NETWORK_FDSet *fds,
561 const struct GNUNET_NETWORK_Handle *desc) 600 const struct GNUNET_NETWORK_Handle *desc)
562{ 601{
563 FD_SET (desc->fd, &fds->sds); 602 FD_SET (desc->fd, &fds->sds);
564 603 if (desc->fd + 1 > fds->nsds)
565 if (desc->fd + 1 > fds->nsds) 604 fds->nsds = desc->fd + 1;
566 fds->nsds = desc->fd + 1; 605 }
567} 606
568 607
569
570/** 608/**
571 * Check whether a socket is part of the fd set 609 * Check whether a socket is part of the fd set
572 * @param fds fd set 610 * @param fds fd set
573 * @param desc socket 611 * @param desc socket
574 * @return 0 if the FD is not set 612 * @return 0 if the FD is not set
575 */ 613 */
576int 614int
577GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds, 615GNUNET_NETWORK_fdset_isset (const struct GNUNET_NETWORK_FDSet *fds,
578 const struct GNUNET_NETWORK_Handle *desc) 616 const struct GNUNET_NETWORK_Handle *desc)
579{ 617{
580 return FD_ISSET (desc->fd, &fds->sds); 618 return FD_ISSET (desc->fd, &fds->sds);
581} 619 }
582 620
583 621
584/** 622/**
585 * Add one fd set to another 623 * Add one fd set to another
586 * @param dst the fd set to add to 624 * @param dst the fd set to add to
587 * @param src the fd set to add from 625 * @param src the fd set to add from
588 */ 626 */
589void 627void
590GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst, 628GNUNET_NETWORK_fdset_add (struct GNUNET_NETWORK_FDSet *dst,
591 const struct GNUNET_NETWORK_FDSet *src) 629 const struct GNUNET_NETWORK_FDSet *src)
592{ 630{
593 int nfds; 631 int nfds;
594 632 for (nfds = src->nsds; nfds > 0; nfds--)
595 for (nfds = src->nsds; nfds > 0; nfds--) 633 if (FD_ISSET (nfds, &src->sds))
596 if (FD_ISSET (nfds, &src->sds)) 634
597 { 635 {
598 FD_SET (nfds, &dst->sds); 636 FD_SET (nfds, &dst->sds);
599 if (nfds + 1 > dst->nsds) 637 if (nfds + 1 > dst->nsds)
600 dst->nsds = nfds + 1; 638 dst->nsds = nfds + 1;
601 } 639 }
602} 640 }
603 641
604 642
605/** 643/**
606 * Copy one fd set to another 644 * Copy one fd set to another
607 * @param to destination 645 * @param to destination
608 * @param from source 646 * @param from source
609 */ 647 */
610void 648void
611GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to, 649GNUNET_NETWORK_fdset_copy (struct GNUNET_NETWORK_FDSet *to,
612 const struct GNUNET_NETWORK_FDSet *from) 650 const struct GNUNET_NETWORK_FDSet *from)
613{ 651{
614 FD_COPY (&from->sds, &to->sds); 652 FD_COPY (&from->sds, &to->sds);
615 to->nsds = from->nsds; 653 to->nsds = from->nsds;
654
616#ifdef MINGW 655#ifdef MINGW
617 struct GNUNET_CONTAINER_SList_Iterator *iter; 656 struct GNUNET_CONTAINER_SList_Iterator *iter;
618 657 GNUNET_CONTAINER_slist_clear (to->handles);
619 658 for (iter = GNUNET_CONTAINER_slist_begin (from->handles);
620 GNUNET_CONTAINER_slist_clear (to->handles); 659 GNUNET_CONTAINER_slist_end (iter) != GNUNET_YES;
621 660 GNUNET_CONTAINER_slist_next (iter))
622 for (iter = GNUNET_CONTAINER_slist_begin (from->handles); 661
623 GNUNET_CONTAINER_slist_end (iter) != GNUNET_YES; GNUNET_CONTAINER_slist_next (iter)) 662 {
624 { 663 void *handle;
625 void *handle; 664 size_t len;
626 size_t len; 665 handle = GNUNET_CONTAINER_slist_get (iter, &len);
627 666 GNUNET_CONTAINER_slist_add (to->handles,
628 handle = GNUNET_CONTAINER_slist_get (iter, &len); 667 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
629 GNUNET_CONTAINER_slist_add (to->handles, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, handle, len); 668 handle, len);
630 } 669 }
631#endif 670#endif /* */
632} 671}
633 672
634
635/** 673/**
636 * Copy a native fd set 674 * Copy a native fd set
637 * @param to destination 675 * @param to destination
638 * @param from native source set 676 * @param from native source set
639 * @param nfds the biggest socket number in from + 1 677 * @param nfds the biggest socket number in from + 1
640 */ 678 */
641void 679void
642GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to, 680GNUNET_NETWORK_fdset_copy_native (struct GNUNET_NETWORK_FDSet *to,
643 const fd_set * from, int nfds) 681 const fd_set * from, int nfds)
644{ 682{
645 FD_COPY (from, &to->sds); 683 FD_COPY (from, &to->sds);
646 to->nsds = nfds; 684 to->nsds = nfds;
647} 685 }
648 686
649
650/** 687/**
651 * Add a file handle to the fd set 688 * Add a file handle to the fd set
652 * @param fds fd set 689 * @param fds fd set
653 * @param h the file handle to add 690 * @param h the file handle to add
654 */ 691 */
655void 692void
656GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds, 693GNUNET_NETWORK_fdset_handle_set (struct GNUNET_NETWORK_FDSet *fds,
657 const struct GNUNET_DISK_FileHandle *h) 694 const struct GNUNET_DISK_FileHandle *h)
658{ 695{
696
659#ifdef MINGW 697#ifdef MINGW
660 HANDLE hw; 698 HANDLE hw;
661 699 GNUNET_DISK_internal_file_handle_ (h, &hw, sizeof (HANDLE));
662 GNUNET_DISK_internal_file_handle_ (h, &hw, sizeof (HANDLE)); 700 GNUNET_CONTAINER_slist_add (fds->handles, GNUNET_NO, &hw, sizeof (HANDLE));
663 GNUNET_CONTAINER_slist_add (fds->handles, GNUNET_NO, &hw, sizeof (HANDLE)); 701
664#else 702#else /* */
665 int fd; 703 int fd;
666 704 GNUNET_DISK_internal_file_handle_ (h, &fd, sizeof (int));
667 GNUNET_DISK_internal_file_handle_ (h, &fd, sizeof (int)); 705 FD_SET (fd, &fds->sds);
668 FD_SET (fd, &fds->sds); 706 if (fd + 1 > fds->nsds)
669 if (fd + 1 > fds->nsds) 707 fds->nsds = fd + 1;
670 fds->nsds = fd + 1; 708
671#endif 709#endif /* */
672} 710}
673 711
712
674/** 713/**
675 * Check if a file handle is part of an fd set 714 * Check if a file handle is part of an fd set
676 * @param fds fd set 715 * @param fds fd set
677 * @param h file handle 716 * @param h file handle
678 * @return GNUNET_YES if the file handle is part of the set 717 * @return GNUNET_YES if the file handle is part of the set
679 */ 718 */
680int 719int
681GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds, 720GNUNET_NETWORK_fdset_handle_isset (const struct GNUNET_NETWORK_FDSet *fds,
682 const struct GNUNET_DISK_FileHandle *h) 721 const struct GNUNET_DISK_FileHandle *h)
683{ 722{
723
684#ifdef MINGW 724#ifdef MINGW
685 return GNUNET_CONTAINER_slist_contains (fds->handles, h->h, sizeof (HANDLE)); 725 return GNUNET_CONTAINER_slist_contains (fds->handles, h->h,
686#else 726 sizeof (HANDLE));
687 return FD_ISSET (h->fd, &fds->sds); 727
688#endif 728#else /* */
689} 729 return FD_ISSET (h->fd, &fds->sds);
690 730
731#endif /* */
732}
733
734
691/** 735/**
692 * Checks if two fd sets overlap 736 * Checks if two fd sets overlap
693 * @param fds1 first fd set 737 * @param fds1 first fd set
694 * @param fds2 second fd set 738 * @param fds2 second fd set
695 * @return GNUNET_YES if they do overlap, GNUNET_NO otherwise 739 * @return GNUNET_YES if they do overlap, GNUNET_NO otherwise
696 */ 740 */
697int 741int
698GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1, 742GNUNET_NETWORK_fdset_overlap (const struct GNUNET_NETWORK_FDSet *fds1,
699 const struct GNUNET_NETWORK_FDSet *fds2) 743 const struct GNUNET_NETWORK_FDSet *fds2)
700{ 744{
701 int nfds; 745 int nfds;
702 746 nfds = fds1->nsds;
703 nfds = fds1->nsds; 747 if (nfds < fds2->nsds)
704 if (nfds < fds2->nsds) 748 nfds = fds2->nsds;
705 nfds = fds2->nsds; 749 for (; nfds >= 0; nfds--)
706 750 if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds))
707 for (; nfds >= 0; nfds--) 751 return GNUNET_YES;
708 if (FD_ISSET (nfds, &fds1->sds) && FD_ISSET (nfds, &fds2->sds)) 752 return GNUNET_NO;
709 return GNUNET_YES; 753 }
710 754
711 return GNUNET_NO; 755
712}
713
714/** 756/**
715 * Creates an fd set 757 * Creates an fd set
716 * @return a new fd set 758 * @return a new fd set
717 */ 759 */
718struct GNUNET_NETWORK_FDSet * 760struct GNUNET_NETWORK_FDSet *
719GNUNET_NETWORK_fdset_create () 761GNUNET_NETWORK_fdset_create ()
720{ 762{
721 struct GNUNET_NETWORK_FDSet *fds; 763 struct GNUNET_NETWORK_FDSet *fds;
722 764 fds = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_FDSet));
723 fds = GNUNET_malloc (sizeof (struct GNUNET_NETWORK_FDSet)); 765
724#ifdef MINGW 766#ifdef MINGW
725 fds->handles = GNUNET_CONTAINER_slist_create (); 767 fds->handles = GNUNET_CONTAINER_slist_create ();
726#endif 768
727 GNUNET_NETWORK_fdset_zero (fds); 769#endif /* */
728 return fds; 770 GNUNET_NETWORK_fdset_zero (fds);
729} 771 return fds;
730 772 }
731 773
774
732/** 775/**
733 * Releases the associated memory of an fd set 776 * Releases the associated memory of an fd set
734 * @param fds fd set 777 * @param fds fd set
735 */ 778 */
736void 779void
737GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds) 780GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds)
738{ 781{
782
739#ifdef MINGW 783#ifdef MINGW
740 GNUNET_CONTAINER_slist_destroy (fds->handles); 784 GNUNET_CONTAINER_slist_destroy (fds->handles);
741#endif 785
742 GNUNET_free (fds); 786#endif /* */
743} 787 GNUNET_free (fds);
744 788 }
745 789
746/** 790/**
747 * Check if sockets meet certain conditions 791 * Check if sockets meet certain conditions
748 * @param rfds set of sockets to be checked for readability 792 * @param rfds set of sockets to be checked for readability
@@ -750,249 +794,259 @@ GNUNET_NETWORK_fdset_destroy (struct GNUNET_NETWORK_FDSet *fds)
750 * @param efds set of sockets to be checked for exceptions 794 * @param efds set of sockets to be checked for exceptions
751 * @param timeout relative value when to return 795 * @param timeout relative value when to return
752 * @return number of selected sockets, GNUNET_SYSERR on error 796 * @return number of selected sockets, GNUNET_SYSERR on error
753 */ 797 */
754int 798int
755GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds, 799GNUNET_NETWORK_socket_select (struct GNUNET_NETWORK_FDSet *rfds,
756 struct GNUNET_NETWORK_FDSet *wfds, 800 struct GNUNET_NETWORK_FDSet *wfds,
757 struct GNUNET_NETWORK_FDSet *efds, 801 struct GNUNET_NETWORK_FDSet *efds,
758 const struct GNUNET_TIME_Relative timeout) 802 const struct GNUNET_TIME_Relative timeout)
759{ 803{
760 int nfds; 804 int nfds;
761 805 nfds = 0;
762 nfds = 0; 806 if (NULL != rfds)
763 if (NULL != rfds) 807 nfds = rfds->nsds;
764 nfds = rfds->nsds; 808 if (NULL != wfds)
765 if (NULL != wfds) 809 nfds = GNUNET_MAX (nfds, wfds->nsds);
766 nfds = GNUNET_MAX (nfds, wfds->nsds); 810 if (NULL != efds)
767 if (NULL != efds) 811 nfds = GNUNET_MAX (nfds, efds->nsds);
768 nfds = GNUNET_MAX (nfds, efds->nsds); 812
769
770#ifndef MINGW 813#ifndef MINGW
771 struct timeval tv; 814 struct timeval tv;
772 815 tv.tv_sec = timeout.value / GNUNET_TIME_UNIT_SECONDS.value;
773 tv.tv_sec = timeout.value / GNUNET_TIME_UNIT_SECONDS.value; 816 tv.tv_usec =
774 tv.tv_usec = 1000 * (timeout.value - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.value)); 817 1000 * (timeout.value - (tv.tv_sec * GNUNET_TIME_UNIT_SECONDS.value));
775 if ( (nfds == 0) && 818 if ((nfds == 0) && (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value))
776 (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value) ) 819
777 { 820 {
778 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 821 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
779 _("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"), 822 _
780 "select"); 823 ("Fatal internal logic error, process hangs in `%s' (abort with CTRL-C)!\n"),
781 GNUNET_break (0); 824 "select");
782 } 825 GNUNET_break (0);
783 return select (nfds + 1, 826 }
784 (rfds != NULL) ? &rfds->sds : NULL, 827 return select (nfds + 1,
785 (wfds != NULL) ? &wfds->sds : NULL, 828 (rfds != NULL) ? &rfds->sds : NULL,
786 (efds != NULL) ? &efds->sds : NULL, 829 (wfds != NULL) ? &wfds->sds : NULL,
787 (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value) 830 (efds != NULL) ? &efds->sds : NULL,
788 ? NULL 831 (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
789 : &tv); 832 ? NULL : &tv);
790#else 833
791 DWORD limit; 834#else /* */
792 fd_set sock_read, sock_write, sock_except; 835 DWORD limit;
793 fd_set aread, awrite, aexcept; 836 fd_set sock_read, sock_write, sock_except;
794 int i; 837 fd_set aread, awrite, aexcept;
795 struct timeval tvslice; 838 int i;
796 int retcode; 839 struct timeval tvslice;
797 DWORD ms_total; 840 int retcode;
798 841 DWORD ms_total;
842
799#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set)) 843#define SAFE_FD_ISSET(fd, set) (set != NULL && FD_ISSET(fd, set))
800 844
801 /* calculate how long we need to wait in milliseconds */ 845 /* calculate how long we need to wait in milliseconds */
802 if (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value) 846 if (timeout.value == GNUNET_TIME_UNIT_FOREVER_REL.value)
803 ms_total = INFINITE; 847 ms_total = INFINITE;
804 else 848
805 ms_total = timeout.value / GNUNET_TIME_UNIT_MILLISECONDS.value; 849 else
806 850 ms_total = timeout.value / GNUNET_TIME_UNIT_MILLISECONDS.value;
807 /* select() may be used as a portable way to sleep */ 851
808 if (!(rfds || wfds || efds)) 852 /* select() may be used as a portable way to sleep */
809 { 853 if (!(rfds || wfds || efds))
810 Sleep (ms_total); 854
811 return 0; 855 {
812 } 856 Sleep (ms_total);
813 857 return 0;
814 if (rfds) 858 }
815 sock_read = rfds->sds; 859 if (rfds)
816 else 860 sock_read = rfds->sds;
817 FD_ZERO(&sock_read); 861
818 862 else
819 if (wfds) 863 FD_ZERO (&sock_read);
820 sock_write = wfds->sds; 864 if (wfds)
821 else 865 sock_write = wfds->sds;
822 FD_ZERO(&sock_write); 866
823 867 else
824 if (efds) 868 FD_ZERO (&sock_write);
825 sock_except = efds->sds; 869 if (efds)
826 else 870 sock_except = efds->sds;
827 FD_ZERO(&sock_except); 871
828 872 else
829 /* multiplex between winsock select() and waiting on the handles */ 873 FD_ZERO (&sock_except);
830 874
831 FD_ZERO (&aread); 875 /* multiplex between winsock select() and waiting on the handles */
832 FD_ZERO (&awrite); 876 FD_ZERO (&aread);
833 FD_ZERO (&aexcept); 877 FD_ZERO (&awrite);
834 878 FD_ZERO (&aexcept);
835 limit = GetTickCount () + ms_total; 879 limit = GetTickCount () + ms_total;
836 do 880
837 { 881 do
838 retcode = 0; 882
839 883 {
840 if (nfds > 0) 884 retcode = 0;
841 { 885 if (nfds > 0)
842 /* overwrite the zero'd sets here; the select call 886
843 * will clear those that are not active */ 887 {
844 888
845 FD_COPY (&sock_read, &aread); 889 /* overwrite the zero'd sets here; the select call
846 FD_COPY (&sock_write, &awrite); 890 * will clear those that are not active */
847 FD_COPY (&sock_except, &aexcept); 891 FD_COPY (&sock_read, &aread);
848 892 FD_COPY (&sock_write, &awrite);
849 tvslice.tv_sec = 0; 893 FD_COPY (&sock_except, &aexcept);
850 tvslice.tv_usec = 100000; 894 tvslice.tv_sec = 0;
851 895 tvslice.tv_usec = 100000;
852 if ((retcode = 896 if ((retcode =
853 select (nfds + 1, &aread, &awrite, &aexcept, 897 select (nfds + 1, &aread, &awrite, &aexcept,
854 &tvslice)) == SOCKET_ERROR) 898 &tvslice)) == SOCKET_ERROR)
855 { 899
856 SetErrnoFromWinsockError (WSAGetLastError ()); 900 {
857 if (errno == ENOTSOCK) 901 SetErrnoFromWinsockError (WSAGetLastError ());
858 errno = EBADF; 902 if (errno == ENOTSOCK)
859 903 errno = EBADF;
904
860#if DEBUG_NETWORK 905#if DEBUG_NETWORK
861 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select"); 906 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "select");
862#endif 907
863 908#endif /* */
864 goto select_loop_end; 909 goto select_loop_end;
865 } 910 }
866 } 911 }
867 912
868 /* Poll read pipes */ 913 /* Poll read pipes */
869 if (rfds) 914 if (rfds)
870 { 915
871 struct GNUNET_CONTAINER_SList_Iterator *i; 916 {
872 int on_next; 917 struct GNUNET_CONTAINER_SList_Iterator *i;
873 918 int on_next;
874 on_next = GNUNET_NO; 919 on_next = GNUNET_NO;
875 for (i = GNUNET_CONTAINER_slist_begin (rfds->handles); 920 for (i = GNUNET_CONTAINER_slist_begin (rfds->handles);
876 GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; 921 GNUNET_CONTAINER_slist_end (i) != GNUNET_YES;
877 on_next || GNUNET_CONTAINER_slist_next (i)) 922 on_next || GNUNET_CONTAINER_slist_next (i))
878 { 923
879 HANDLE h; 924 {
880 DWORD dwBytes; 925 HANDLE h;
881 926 DWORD dwBytes;
882 h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL); 927 h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL);
883 on_next = GNUNET_NO; 928 on_next = GNUNET_NO;
884 929 if (!PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL))
885 if (!PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL)) 930
886 { 931 {
887 GNUNET_CONTAINER_slist_erase (i); 932 GNUNET_CONTAINER_slist_erase (i);
888 on_next = GNUNET_YES; 933 on_next = GNUNET_YES;
889 934 retcode = -1;
890 retcode = -1; 935 SetErrnoFromWinError (GetLastError ());
891 SetErrnoFromWinError (GetLastError ()); 936
892#if DEBUG_NETWORK 937#if DEBUG_NETWORK
893 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "PeekNamedPipe"); 938 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
894#endif 939 "PeekNamedPipe");
895 goto select_loop_end; 940
896 } 941#endif /* */
897 else if (dwBytes) 942 goto select_loop_end;
898 { 943 }
899 retcode++; 944
900 } 945 else if (dwBytes)
901 else 946
902 { 947 {
903 GNUNET_CONTAINER_slist_erase (i); 948 retcode++;
904 on_next = GNUNET_YES; 949 }
905 } 950
906 } 951 else
907 } 952
908 953 {
909 /* Poll for faulty pipes */ 954 GNUNET_CONTAINER_slist_erase (i);
910 if (efds) 955 on_next = GNUNET_YES;
911 { 956 }
912 struct GNUNET_CONTAINER_SList_Iterator *i; 957 }
913 int on_next; 958 }
914 959
915 on_next = GNUNET_NO; 960 /* Poll for faulty pipes */
916 for (i = GNUNET_CONTAINER_slist_begin (efds->handles); 961 if (efds)
917 GNUNET_CONTAINER_slist_end (i) != GNUNET_YES; 962
918 on_next || GNUNET_CONTAINER_slist_next (i)) 963 {
919 { 964 struct GNUNET_CONTAINER_SList_Iterator *i;
920 HANDLE h; 965 int on_next;
921 DWORD dwBytes; 966 on_next = GNUNET_NO;
922 967 for (i = GNUNET_CONTAINER_slist_begin (efds->handles);
923 h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL); 968 GNUNET_CONTAINER_slist_end (i) != GNUNET_YES;
924 969 on_next || GNUNET_CONTAINER_slist_next (i))
925 if (PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL)) 970
926 { 971 {
927 GNUNET_CONTAINER_slist_erase (i); 972 HANDLE h;
928 on_next = GNUNET_YES; 973 DWORD dwBytes;
929 974 h = *(HANDLE *) GNUNET_CONTAINER_slist_get (i, NULL);
930 retcode++; 975 if (PeekNamedPipe (h, NULL, 0, NULL, &dwBytes, NULL))
931 } 976
932 else 977 {
933 on_next = GNUNET_NO; 978 GNUNET_CONTAINER_slist_erase (i);
934 } 979 on_next = GNUNET_YES;
935 } 980 retcode++;
936 981 }
937 /* FIXME */ 982
938 if (wfds) 983 else
939 GNUNET_assert (GNUNET_CONTAINER_slist_count (wfds->handles) == 0); 984 on_next = GNUNET_NO;
940 985 }
941 /* Check for closed sockets */ 986 }
942 for (i = 0; i < nfds; i++) 987
943 { 988 /* FIXME */
944 if (SAFE_FD_ISSET (i, &sock_read)) 989 if (wfds)
945 { 990 GNUNET_assert (GNUNET_CONTAINER_slist_count (wfds->handles) == 0);
946 struct sockaddr addr; 991
947 int len; 992 /* Check for closed sockets */
948 993 for (i = 0; i < nfds; i++)
949 if (getpeername (i, &addr, &len) == SOCKET_ERROR) 994
950 { 995 {
951 int err, len; 996 if (SAFE_FD_ISSET (i, &sock_read))
952 997
953 len = sizeof (err); 998 {
954 if (getsockopt 999 struct sockaddr addr;
955 (i, SOL_SOCKET, SO_ERROR, (char *) &err, &len) == 0 1000 int len;
956 && err == WSAENOTCONN) 1001 if (getpeername (i, &addr, &len) == SOCKET_ERROR)
957 { 1002
958 if (!SAFE_FD_ISSET (i, &aread)) 1003 {
959 { 1004 int err, len;
960 FD_SET (i, &aread); 1005 len = sizeof (err);
961 retcode++; 1006 if (getsockopt
962 } 1007 (i, SOL_SOCKET, SO_ERROR, (char *) &err, &len) == 0
963 } 1008 &&err == WSAENOTCONN)
964 } 1009
965 } 1010 {
966 } 1011 if (!SAFE_FD_ISSET (i, &aread))
967 1012
968 select_loop_end:; 1013 {
969 } 1014 FD_SET (i, &aread);
970 while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit)); 1015 retcode++;
971 1016 }
972 if (retcode != -1) 1017 }
973 { 1018 }
974 if (rfds) 1019 }
975 { 1020 }
976 GNUNET_NETWORK_fdset_zero (rfds); 1021 select_loop_end:;
977 GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode); 1022 }
978 } 1023 while (retcode == 0 && (ms_total == INFINITE || GetTickCount () < limit));
979 1024 if (retcode != -1)
980 if (wfds) 1025
981 { 1026 {
982 GNUNET_NETWORK_fdset_zero (wfds); 1027 if (rfds)
983 GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode); 1028
984 } 1029 {
985 1030 GNUNET_NETWORK_fdset_zero (rfds);
986 if (efds) 1031 GNUNET_NETWORK_fdset_copy_native (rfds, &aread, retcode);
987 { 1032 }
988 GNUNET_NETWORK_fdset_zero (efds); 1033 if (wfds)
989 GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode); 1034
990 } 1035 {
991 } 1036 GNUNET_NETWORK_fdset_zero (wfds);
992 1037 GNUNET_NETWORK_fdset_copy_native (wfds, &awrite, retcode);
993 return retcode; 1038 }
994#endif 1039 if (efds)
995} 1040
996 1041 {
997 1042 GNUNET_NETWORK_fdset_zero (efds);
998/* end of network.c */ 1043 GNUNET_NETWORK_fdset_copy_native (efds, &aexcept, retcode);
1044 }
1045 }
1046 return retcode;
1047
1048#endif /* */
1049}
1050
1051
1052/* end of network.c */
diff --git a/src/util/os_installation.c b/src/util/os_installation.c
index afb8c2474..7079e2fef 100644
--- a/src/util/os_installation.c
+++ b/src/util/os_installation.c
@@ -298,8 +298,9 @@ os_get_gnunet_path ()
298 return ret; 298 return ret;
299 /* other attempts here */ 299 /* other attempts here */
300 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 300 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
301 _("Could not determine installation path for GNUnet. Set `%s' environment variable.\n"), 301 _
302 "GNUNET_PREFIX"); 302 ("Could not determine installation path for GNUnet. Set `%s' environment variable.\n"),
303 "GNUNET_PREFIX");
303 return NULL; 304 return NULL;
304} 305}
305 306
diff --git a/src/util/os_priority.c b/src/util/os_priority.c
index 4c77704bf..cb04428d3 100644
--- a/src/util/os_priority.c
+++ b/src/util/os_priority.c
@@ -141,23 +141,23 @@ GNUNET_OS_start_process (const char *filename, ...)
141 if (ret != 0) 141 if (ret != 0)
142 { 142 {
143 if (ret == -1) 143 if (ret == -1)
144 { 144 {
145 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); 145 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
146 } 146 }
147 else 147 else
148 { 148 {
149#if HAVE_WORKING_VFORK 149#if HAVE_WORKING_VFORK
150 /* let's hope vfork actually works; for some extreme cases (including 150 /* let's hope vfork actually works; for some extreme cases (including
151 a testcase) we need 'execvp' to have run before we return, since 151 a testcase) we need 'execvp' to have run before we return, since
152 we may send a signal to the process next and we don't want it 152 we may send a signal to the process next and we don't want it
153 to be caught by OUR signal handler (but either by the default 153 to be caught by OUR signal handler (but either by the default
154 handler or the actual handler as installed by the process itself). */ 154 handler or the actual handler as installed by the process itself). */
155#else 155#else
156 /* let's give the child process a chance to run execvp, 1s should 156 /* let's give the child process a chance to run execvp, 1s should
157 be plenty in practice */ 157 be plenty in practice */
158 sleep (1); 158 sleep (1);
159#endif 159#endif
160 } 160 }
161 return ret; 161 return ret;
162 } 162 }
163 argc = 0; 163 argc = 0;
@@ -184,29 +184,30 @@ GNUNET_OS_start_process (const char *filename, ...)
184 cmdlen = 0; 184 cmdlen = 0;
185 va_start (ap, filename); 185 va_start (ap, filename);
186 while (NULL != (arg = va_arg (ap, char *))) 186 while (NULL != (arg = va_arg (ap, char *)))
187 cmdlen = cmdlen + strlen (arg) + 3; 187 cmdlen = cmdlen + strlen (arg) + 3;
188 va_end (ap); 188 va_end (ap);
189 189
190 cmd = idx = GNUNET_malloc (sizeof(char) * cmdlen); 190 cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen);
191 va_start (ap, filename); 191 va_start (ap, filename);
192 while (NULL != (arg = va_arg (ap, char *))) 192 while (NULL != (arg = va_arg (ap, char *)))
193 idx += sprintf (idx, "\"%s\" ", arg); 193 idx += sprintf (idx, "\"%s\" ", arg);
194 va_end (ap); 194 va_end (ap);
195 195
196 memset (&start, 0, sizeof(start)); 196 memset (&start, 0, sizeof (start));
197 start.cb = sizeof(start); 197 start.cb = sizeof (start);
198 198
199 if (!CreateProcess (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, 199 if (!CreateProcess
200 NULL, &start, &proc)) 200 (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &start,
201 { 201 &proc))
202 SetErrnoFromWinError (GetLastError ()); 202 {
203 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); 203 SetErrnoFromWinError (GetLastError ());
204 return -1; 204 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
205 } 205 return -1;
206 }
206 CloseHandle (proc.hProcess); 207 CloseHandle (proc.hProcess);
207 CloseHandle (proc.hThread); 208 CloseHandle (proc.hThread);
208 209
209 GNUNET_free(cmd); 210 GNUNET_free (cmd);
210 211
211 return proc.dwProcessId; 212 return proc.dwProcessId;
212#endif 213#endif
@@ -236,23 +237,23 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[])
236 if (ret != 0) 237 if (ret != 0)
237 { 238 {
238 if (ret == -1) 239 if (ret == -1)
239 { 240 {
240 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); 241 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
241 } 242 }
242 else 243 else
243 { 244 {
244#if HAVE_WORKING_VFORK 245#if HAVE_WORKING_VFORK
245 /* let's hope vfork actually works; for some extreme cases (including 246 /* let's hope vfork actually works; for some extreme cases (including
246 a testcase) we need 'execvp' to have run before we return, since 247 a testcase) we need 'execvp' to have run before we return, since
247 we may send a signal to the process next and we don't want it 248 we may send a signal to the process next and we don't want it
248 to be caught by OUR signal handler (but either by the default 249 to be caught by OUR signal handler (but either by the default
249 handler or the actual handler as installed by the process itself). */ 250 handler or the actual handler as installed by the process itself). */
250#else 251#else
251 /* let's give the child process a chance to run execvp, 1s should 252 /* let's give the child process a chance to run execvp, 1s should
252 be plenty in practice */ 253 be plenty in practice */
253 sleep (1); 254 sleep (1);
254#endif 255#endif
255 } 256 }
256 return ret; 257 return ret;
257 } 258 }
258 execvp (filename, argv); 259 execvp (filename, argv);
@@ -268,33 +269,34 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[])
268 cmdlen = 0; 269 cmdlen = 0;
269 arg = argv; 270 arg = argv;
270 while (*arg) 271 while (*arg)
271 { 272 {
272 cmdlen = cmdlen + strlen (*arg) + 3; 273 cmdlen = cmdlen + strlen (*arg) + 3;
273 arg++; 274 arg++;
274 } 275 }
275 276
276 cmd = idx = GNUNET_malloc (sizeof(char) * cmdlen); 277 cmd = idx = GNUNET_malloc (sizeof (char) * cmdlen);
277 arg = argv; 278 arg = argv;
278 while (*arg) 279 while (*arg)
279 { 280 {
280 idx += sprintf (idx, "\"%s\" ", *arg); 281 idx += sprintf (idx, "\"%s\" ", *arg);
281 arg++; 282 arg++;
282 } 283 }
283 284
284 memset (&start, 0, sizeof(start)); 285 memset (&start, 0, sizeof (start));
285 start.cb = sizeof(start); 286 start.cb = sizeof (start);
286 287
287 if (!CreateProcess (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, 288 if (!CreateProcess
288 NULL, &start, &proc)) 289 (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, &start,
289 { 290 &proc))
290 SetErrnoFromWinError (GetLastError ()); 291 {
291 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); 292 SetErrnoFromWinError (GetLastError ());
292 return -1; 293 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork");
293 } 294 return -1;
295 }
294 CloseHandle (proc.hProcess); 296 CloseHandle (proc.hProcess);
295 CloseHandle (proc.hThread); 297 CloseHandle (proc.hThread);
296 298
297 GNUNET_free(cmd); 299 GNUNET_free (cmd);
298 300
299 return proc.dwProcessId; 301 return proc.dwProcessId;
300#endif 302#endif
@@ -309,7 +311,7 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[])
309 */ 311 */
310int 312int
311GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type, 313GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
312 unsigned long *code) 314 unsigned long *code)
313{ 315{
314#ifndef MINGW 316#ifndef MINGW
315 int status; 317 int status;
@@ -317,7 +319,7 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
317 319
318 GNUNET_assert (0 != proc); 320 GNUNET_assert (0 != proc);
319 ret = waitpid (proc, &status, WNOHANG); 321 ret = waitpid (proc, &status, WNOHANG);
320 if (0 == ret) 322 if (0 == ret)
321 { 323 {
322 *type = GNUNET_OS_PROCESS_RUNNING; 324 *type = GNUNET_OS_PROCESS_RUNNING;
323 *code = 0; 325 *code = 0;
@@ -329,50 +331,50 @@ GNUNET_OS_process_status (pid_t proc, enum GNUNET_OS_ProcessStatusType *type,
329 return GNUNET_SYSERR; 331 return GNUNET_SYSERR;
330 } 332 }
331 if (WIFEXITED (status)) 333 if (WIFEXITED (status))
332 { 334 {
333 *type = GNUNET_OS_PROCESS_EXITED; 335 *type = GNUNET_OS_PROCESS_EXITED;
334 *code = WEXITSTATUS (status); 336 *code = WEXITSTATUS (status);
335 } 337 }
336 else if (WIFSIGNALED (status)) 338 else if (WIFSIGNALED (status))
337 { 339 {
338 *type = GNUNET_OS_PROCESS_SIGNALED; 340 *type = GNUNET_OS_PROCESS_SIGNALED;
339 *code = WTERMSIG (status); 341 *code = WTERMSIG (status);
340 } 342 }
341 else if (WIFSTOPPED (status)) 343 else if (WIFSTOPPED (status))
342 { 344 {
343 *type = GNUNET_OS_PROCESS_SIGNALED; 345 *type = GNUNET_OS_PROCESS_SIGNALED;
344 *code = WSTOPSIG (status); 346 *code = WSTOPSIG (status);
345 } 347 }
346 else if (WIFCONTINUED (status)) 348 else if (WIFCONTINUED (status))
347 { 349 {
348 *type = GNUNET_OS_PROCESS_RUNNING; 350 *type = GNUNET_OS_PROCESS_RUNNING;
349 *code = 0; 351 *code = 0;
350 } 352 }
351 else 353 else
352 { 354 {
353 *type = GNUNET_OS_PROCESS_UNKNOWN; 355 *type = GNUNET_OS_PROCESS_UNKNOWN;
354 *code = 0; 356 *code = 0;
355 } 357 }
356#else 358#else
357 HANDLE h; 359 HANDLE h;
358 DWORD c; 360 DWORD c;
359 361
360 h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc); 362 h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc);
361 if (INVALID_HANDLE_VALUE == h) 363 if (INVALID_HANDLE_VALUE == h)
362 { 364 {
363 SetErrnoFromWinError (GetLastError ()); 365 SetErrnoFromWinError (GetLastError ());
364 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "OpenProcess"); 366 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "OpenProcess");
365 return GNUNET_SYSERR; 367 return GNUNET_SYSERR;
366 } 368 }
367 369
368 c = GetExitCodeProcess (proc, &c); 370 c = GetExitCodeProcess (proc, &c);
369 if (STILL_ACTIVE == c) 371 if (STILL_ACTIVE == c)
370 { 372 {
371 *type = GNUNET_OS_PROCESS_RUNNING; 373 *type = GNUNET_OS_PROCESS_RUNNING;
372 *code = 0; 374 *code = 0;
373 CloseHandle (h); 375 CloseHandle (h);
374 return GNUNET_NO; 376 return GNUNET_NO;
375 } 377 }
376 *type = GNUNET_OS_PROCESS_EXITED; 378 *type = GNUNET_OS_PROCESS_EXITED;
377 *code = c; 379 *code = c;
378 CloseHandle (h); 380 CloseHandle (h);
@@ -401,16 +403,16 @@ GNUNET_OS_process_wait (pid_t proc)
401 403
402 h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc); 404 h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, proc);
403 if (INVALID_HANDLE_VALUE == h) 405 if (INVALID_HANDLE_VALUE == h)
404 { 406 {
405 SetErrnoFromWinError (GetLastError ()); 407 SetErrnoFromWinError (GetLastError ());
406 return GNUNET_SYSERR; 408 return GNUNET_SYSERR;
407 } 409 }
408 410
409 if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE)) 411 if (WAIT_OBJECT_0 != WaitForSingleObject (h, INFINITE))
410 { 412 {
411 SetErrnoFromWinError (GetLastError ()); 413 SetErrnoFromWinError (GetLastError ());
412 ret = GNUNET_SYSERR; 414 ret = GNUNET_SYSERR;
413 } 415 }
414 else 416 else
415 ret = GNUNET_OK; 417 ret = GNUNET_OK;
416 418
diff --git a/src/util/peer.c b/src/util/peer.c
index acb1b3922..2ad4b3d67 100644
--- a/src/util/peer.c
+++ b/src/util/peer.c
@@ -83,7 +83,7 @@ static unsigned int free_list_start;
83 * @return the interned identity. 83 * @return the interned identity.
84 */ 84 */
85GNUNET_PEER_Id 85GNUNET_PEER_Id
86GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid) 86GNUNET_PEER_intern (const struct GNUNET_PeerIdentity *pid)
87{ 87{
88 GNUNET_PEER_Id ret; 88 GNUNET_PEER_Id ret;
89 struct PeerEntry *e; 89 struct PeerEntry *e;
@@ -93,8 +93,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
93 return 0; 93 return 0;
94 if (NULL == map) 94 if (NULL == map)
95 map = GNUNET_CONTAINER_multihashmap_create (32); 95 map = GNUNET_CONTAINER_multihashmap_create (32);
96 e = GNUNET_CONTAINER_multihashmap_get (map, 96 e = GNUNET_CONTAINER_multihashmap_get (map, &pid->hashPubKey);
97 &pid->hashPubKey);
98 if (e != NULL) 97 if (e != NULL)
99 { 98 {
100 GNUNET_assert (e->rc > 0); 99 GNUNET_assert (e->rc > 0);
@@ -105,8 +104,8 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
105 if (ret == size) 104 if (ret == size)
106 { 105 {
107 GNUNET_array_grow (table, size, size + 16); 106 GNUNET_array_grow (table, size, size + 16);
108 for (i=ret;i<size;i++) 107 for (i = ret; i < size; i++)
109 table[i].pid = i + 1; 108 table[i].pid = i + 1;
110 } 109 }
111 if (ret == 0) 110 if (ret == 0)
112 { 111 {
@@ -121,9 +120,9 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
121 table[ret].rc = 1; 120 table[ret].rc = 1;
122 table[ret].pid = ret; 121 table[ret].pid = ret;
123 GNUNET_CONTAINER_multihashmap_put (map, 122 GNUNET_CONTAINER_multihashmap_put (map,
124 &pid->hashPubKey, 123 &pid->hashPubKey,
125 &table[ret], 124 &table[ret],
126 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); 125 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
127 return ret; 126 return ret;
128} 127}
129 128
@@ -135,8 +134,7 @@ GNUNET_PEER_intern (const struct GNUNET_PeerIdentity * pid)
135 * @param count size of the ids array 134 * @param count size of the ids array
136 */ 135 */
137void 136void
138GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, 137GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids, unsigned int count)
139 unsigned int count)
140{ 138{
141 int i; 139 int i;
142 GNUNET_PEER_Id id; 140 GNUNET_PEER_Id id;
@@ -150,13 +148,13 @@ GNUNET_PEER_decrement_rcs (const GNUNET_PEER_Id * ids,
150 GNUNET_assert (table[id].rc > 0); 148 GNUNET_assert (table[id].rc > 0);
151 table[id].rc--; 149 table[id].rc--;
152 if (table[id].rc == 0) 150 if (table[id].rc == 0)
153 { 151 {
154 GNUNET_CONTAINER_multihashmap_remove (map, 152 GNUNET_CONTAINER_multihashmap_remove (map,
155 &table[id].id.hashPubKey, 153 &table[id].id.hashPubKey,
156 &table[id]); 154 &table[id]);
157 table[id].pid = free_list_start; 155 table[id].pid = free_list_start;
158 free_list_start = id; 156 free_list_start = id;
159 } 157 }
160 } 158 }
161} 159}
162 160
@@ -179,8 +177,8 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta)
179 if (table[id].rc == 0) 177 if (table[id].rc == 0)
180 { 178 {
181 GNUNET_CONTAINER_multihashmap_remove (map, 179 GNUNET_CONTAINER_multihashmap_remove (map,
182 &table[id].id.hashPubKey, 180 &table[id].id.hashPubKey,
183 &table[id]); 181 &table[id]);
184 table[id].pid = free_list_start; 182 table[id].pid = free_list_start;
185 free_list_start = id; 183 free_list_start = id;
186 } 184 }
@@ -194,8 +192,7 @@ GNUNET_PEER_change_rc (GNUNET_PEER_Id id, int delta)
194 * @param pid where to write the normal peer identity 192 * @param pid where to write the normal peer identity
195 */ 193 */
196void 194void
197GNUNET_PEER_resolve (GNUNET_PEER_Id id, 195GNUNET_PEER_resolve (GNUNET_PEER_Id id, struct GNUNET_PeerIdentity *pid)
198 struct GNUNET_PeerIdentity * pid)
199{ 196{
200 if (id == 0) 197 if (id == 0)
201 { 198 {
diff --git a/src/util/perf_crypto_hash.c b/src/util/perf_crypto_hash.c
index 76ba24be0..6e505b807 100644
--- a/src/util/perf_crypto_hash.c
+++ b/src/util/perf_crypto_hash.c
@@ -57,7 +57,8 @@ main (int argc, char *argv[])
57 start = GNUNET_TIME_absolute_get (); 57 start = GNUNET_TIME_absolute_get ();
58 perfHash (); 58 perfHash ();
59 printf ("Hash perf took %llu ms\n", 59 printf ("Hash perf took %llu ms\n",
60 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).value); 60 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
61 value);
61 return 0; 62 return 0;
62} 63}
63 64
diff --git a/src/util/program.c b/src/util/program.c
index aa272ea96..695a6f9bc 100644
--- a/src/util/program.c
+++ b/src/util/program.c
@@ -89,10 +89,10 @@ program_main (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
89 * @param a2 second command line option 89 * @param a2 second command line option
90 */ 90 */
91static int 91static int
92cmd_sorter (const void *a1, const void *a2) 92cmd_sorter (__const void *a1, __const void *a2)
93{ 93{
94 const struct GNUNET_GETOPT_CommandLineOption *c1 = a1; 94 __const struct GNUNET_GETOPT_CommandLineOption *c1 = a1;
95 const struct GNUNET_GETOPT_CommandLineOption *c2 = a2; 95 __const struct GNUNET_GETOPT_CommandLineOption *c2 = a2;
96 if (toupper (c1->shortName) > toupper (c2->shortName)) 96 if (toupper (c1->shortName) > toupper (c2->shortName))
97 return 1; 97 return 1;
98 if (toupper (c1->shortName) < toupper (c2->shortName)) 98 if (toupper (c1->shortName) < toupper (c2->shortName))
@@ -174,7 +174,7 @@ GNUNET_PROGRAM_run (int argc,
174 qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption), 174 qsort (allopts, cnt, sizeof (struct GNUNET_GETOPT_CommandLineOption),
175 &cmd_sorter); 175 &cmd_sorter);
176 loglev = GNUNET_strdup ("WARNING"); 176 loglev = GNUNET_strdup ("WARNING");
177 if ((-1 == (ret = GNUNET_GETOPT_run (binaryName, 177 if ((-1 == (ret = GNUNET_GETOPT_run (binaryName,
178 allopts, 178 allopts,
179 (unsigned int) argc, argv))) || 179 (unsigned int) argc, argv))) ||
180 ((GNUNET_OK != 180 ((GNUNET_OK !=
diff --git a/src/util/pseudonym.c b/src/util/pseudonym.c
index bf746c66b..0465b1b2c 100644
--- a/src/util/pseudonym.c
+++ b/src/util/pseudonym.c
@@ -193,7 +193,7 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
193 tag += off; 193 tag += off;
194 } 194 }
195 buf = GNUNET_malloc (tag); 195 buf = GNUNET_malloc (tag);
196 ((int32_t *) buf)[0] = htonl (ranking); /* ranking */ 196 ((int32_t *) buf)[0] = htonl (ranking); /* ranking */
197 if (ns_name != NULL) 197 if (ns_name != NULL)
198 { 198 {
199 memcpy (&buf[sizeof (int32_t)], ns_name, off + 1); 199 memcpy (&buf[sizeof (int32_t)], ns_name, off + 1);
@@ -211,7 +211,8 @@ write_pseudonym_info (const struct GNUNET_CONFIGURATION_Handle *cfg,
211 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL)); 211 GNUNET_CONTAINER_META_DATA_SERIALIZE_FULL));
212 GNUNET_break 212 GNUNET_break
213 (tag == GNUNET_DISK_fn_write (fn, buf, tag, GNUNET_DISK_PERM_USER_READ 213 (tag == GNUNET_DISK_fn_write (fn, buf, tag, GNUNET_DISK_PERM_USER_READ
214 | GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_GROUP_READ)); 214 | GNUNET_DISK_PERM_USER_WRITE |
215 GNUNET_DISK_PERM_GROUP_READ));
215 GNUNET_free (fn); 216 GNUNET_free (fn);
216 GNUNET_free (buf); 217 GNUNET_free (buf);
217 /* create entry for pseudonym name in names */ 218 /* create entry for pseudonym name in names */
@@ -365,8 +366,9 @@ GNUNET_PSEUDONYM_id_to_name (const struct GNUNET_CONFIGURATION_Handle *cfg,
365 if (0 == STAT (fn, &sbuf)) 366 if (0 == STAT (fn, &sbuf))
366 GNUNET_DISK_file_size (fn, &len, GNUNET_YES); 367 GNUNET_DISK_file_size (fn, &len, GNUNET_YES);
367 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_CREATE 368 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_CREATE
368 | GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_PERM_USER_READ 369 | GNUNET_DISK_OPEN_READWRITE,
369 | GNUNET_DISK_PERM_USER_WRITE); 370 GNUNET_DISK_PERM_USER_READ |
371 GNUNET_DISK_PERM_USER_WRITE);
370 i = 0; 372 i = 0;
371 idx = -1; 373 idx = -1;
372 while ((len >= sizeof (GNUNET_HashCode)) && 374 while ((len >= sizeof (GNUNET_HashCode)) &&
@@ -437,11 +439,14 @@ GNUNET_PSEUDONYM_name_to_id (const struct GNUNET_CONFIGURATION_Handle *cfg,
437 return GNUNET_SYSERR; 439 return GNUNET_SYSERR;
438 } 440 }
439 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_CREATE 441 fh = GNUNET_DISK_file_open (fn, GNUNET_DISK_OPEN_CREATE
440 | GNUNET_DISK_OPEN_READWRITE, GNUNET_DISK_PERM_USER_READ 442 | GNUNET_DISK_OPEN_READWRITE,
441 | GNUNET_DISK_PERM_USER_WRITE); 443 GNUNET_DISK_PERM_USER_READ |
444 GNUNET_DISK_PERM_USER_WRITE);
442 GNUNET_free (fn); 445 GNUNET_free (fn);
443 GNUNET_DISK_file_seek (fh, idx * sizeof (GNUNET_HashCode), GNUNET_DISK_SEEK_SET); 446 GNUNET_DISK_file_seek (fh, idx * sizeof (GNUNET_HashCode),
444 if (sizeof (GNUNET_HashCode) != GNUNET_DISK_file_read (fh, nsid, sizeof (GNUNET_HashCode))) 447 GNUNET_DISK_SEEK_SET);
448 if (sizeof (GNUNET_HashCode) !=
449 GNUNET_DISK_file_read (fh, nsid, sizeof (GNUNET_HashCode)))
445 { 450 {
446 GNUNET_DISK_file_close (fh); 451 GNUNET_DISK_file_close (fh);
447 return GNUNET_SYSERR; 452 return GNUNET_SYSERR;
@@ -462,12 +467,12 @@ struct ListPseudonymClosure
462 * FIXME 467 * FIXME
463 */ 468 */
464 GNUNET_PSEUDONYM_Iterator iterator; 469 GNUNET_PSEUDONYM_Iterator iterator;
465 470
466 /** 471 /**
467 * FIXME 472 * FIXME
468 */ 473 */
469 void *closure; 474 void *closure;
470 475
471 /** 476 /**
472 * FIXME 477 * FIXME
473 */ 478 */
@@ -575,9 +580,7 @@ GNUNET_PSEUDONYM_rank (const struct GNUNET_CONFIGURATION_Handle *cfg,
575 * @param data value of entry to insert 580 * @param data value of entry to insert
576 */ 581 */
577static int 582static int
578merge_meta_helper (void *cls, 583merge_meta_helper (void *cls, EXTRACTOR_KeywordType type, const char *data)
579 EXTRACTOR_KeywordType type,
580 const char *data)
581{ 584{
582 struct GNUNET_CONTAINER_MetaData *meta = cls; 585 struct GNUNET_CONTAINER_MetaData *meta = cls;
583 GNUNET_CONTAINER_meta_data_insert (meta, type, data); 586 GNUNET_CONTAINER_meta_data_insert (meta, type, data);
diff --git a/src/util/resolver_api.c b/src/util/resolver_api.c
index c32fc58fa..69d143bc1 100644
--- a/src/util/resolver_api.c
+++ b/src/util/resolver_api.c
@@ -100,7 +100,7 @@ struct GNUNET_RESOLVER_RequestHandle
100 100
101 /** 101 /**
102 * Desired address family. 102 * Desired address family.
103 */ 103 */
104 int domain; 104 int domain;
105 105
106 /** 106 /**
@@ -123,35 +123,30 @@ check_config (const struct GNUNET_CONFIGURATION_Handle *cfg)
123 struct sockaddr_in v4; 123 struct sockaddr_in v4;
124 struct sockaddr_in6 v6; 124 struct sockaddr_in6 v6;
125 125
126 memset (&v4, 0, sizeof(v4)); 126 memset (&v4, 0, sizeof (v4));
127 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 127 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
128 v4.sin_family = AF_INET; 128 v4.sin_family = AF_INET;
129#if HAVE_SOCKADDR_IN_SIN_LEN 129#if HAVE_SOCKADDR_IN_SIN_LEN
130 v4.sin_len = sizeof(v4); 130 v4.sin_len = sizeof (v4);
131#endif 131#endif
132 memset (&v6, 0, sizeof(v6)); 132 memset (&v6, 0, sizeof (v6));
133 v6.sin6_family = AF_INET6; 133 v6.sin6_family = AF_INET6;
134#if HAVE_SOCKADDR_IN_SIN_LEN 134#if HAVE_SOCKADDR_IN_SIN_LEN
135 v6.sin6_len = sizeof(v6); 135 v6.sin6_len = sizeof (v6);
136#endif 136#endif
137 if (GNUNET_OK != 137 if (GNUNET_OK !=
138 GNUNET_CONFIGURATION_get_value_string (cfg, 138 GNUNET_CONFIGURATION_get_value_string (cfg,
139 "resolver", 139 "resolver",
140 "HOSTNAME", 140 "HOSTNAME", &hostname))
141 &hostname))
142 { 141 {
143 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 142 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
144 _("Must specify `%s' for `%s' in configuration!\n"), 143 _("Must specify `%s' for `%s' in configuration!\n"),
145 "HOSTNAME", 144 "HOSTNAME", "resolver");
146 "resolver");
147 GNUNET_assert (0); 145 GNUNET_assert (0);
148 } 146 }
149 if ( (1 != inet_pton (AF_INET, 147 if ((1 != inet_pton (AF_INET,
150 hostname, 148 hostname,
151 &v4)) || 149 &v4)) || (1 != inet_pton (AF_INET6, hostname, &v6)))
152 (1 != inet_pton (AF_INET6,
153 hostname,
154 &v6)) )
155 { 150 {
156 GNUNET_free (hostname); 151 GNUNET_free (hostname);
157 return; 152 return;
@@ -160,16 +155,15 @@ check_config (const struct GNUNET_CONFIGURATION_Handle *cfg)
160 while (loopback[i] != NULL) 155 while (loopback[i] != NULL)
161 if (0 == strcasecmp (loopback[i++], hostname)) 156 if (0 == strcasecmp (loopback[i++], hostname))
162 { 157 {
163 GNUNET_free (hostname); 158 GNUNET_free (hostname);
164 return; 159 return;
165 } 160 }
166 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
167 _("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"), 162 _
168 "localhost", 163 ("Must specify `%s' or numeric IP address for `%s' of `%s' in configuration!\n"),
169 "HOSTNAME", 164 "localhost", "HOSTNAME", "resolver");
170 "resolver"); 165 GNUNET_free (hostname);
171 GNUNET_free (hostname); 166 GNUNET_assert (0);
172 GNUNET_assert (0);
173} 167}
174 168
175 169
@@ -274,9 +268,7 @@ handle_address_response (void *cls, const struct GNUNET_MessageHeader *msg)
274#if DEBUG_RESOLVER 268#if DEBUG_RESOLVER
275 { 269 {
276 char *ips = no_resolve (sa, salen); 270 char *ips = no_resolve (sa, salen);
277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 271 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Resolver returns `%s'.\n", ips);
278 "Resolver returns `%s'.\n",
279 ips);
280 GNUNET_free (ips); 272 GNUNET_free (ips);
281 } 273 }
282#endif 274#endif
@@ -297,54 +289,42 @@ handle_address_response (void *cls, const struct GNUNET_MessageHeader *msg)
297 * @param tc unused scheduler context 289 * @param tc unused scheduler context
298 */ 290 */
299static void 291static void
300numeric_resolution (void *cls, 292numeric_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
301 const struct GNUNET_SCHEDULER_TaskContext *tc)
302{ 293{
303 struct GNUNET_RESOLVER_RequestHandle *rh = cls; 294 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
304 struct sockaddr_in v4; 295 struct sockaddr_in v4;
305 struct sockaddr_in6 v6; 296 struct sockaddr_in6 v6;
306 297
307 memset (&v4, 0, sizeof(v4)); 298 memset (&v4, 0, sizeof (v4));
308 v4.sin_family = AF_INET; 299 v4.sin_family = AF_INET;
309#if HAVE_SOCKADDR_IN_SIN_LEN 300#if HAVE_SOCKADDR_IN_SIN_LEN
310 v4.sin_len = sizeof(v4); 301 v4.sin_len = sizeof (v4);
311#endif 302#endif
312 memset (&v6, 0, sizeof(v6)); 303 memset (&v6, 0, sizeof (v6));
313 v6.sin6_family = AF_INET6; 304 v6.sin6_family = AF_INET6;
314#if HAVE_SOCKADDR_IN_SIN_LEN 305#if HAVE_SOCKADDR_IN_SIN_LEN
315 v6.sin6_len = sizeof(v6); 306 v6.sin6_len = sizeof (v6);
316#endif 307#endif
317 308
318 if ( ( (rh->domain == AF_UNSPEC) || (rh->domain == AF_INET) ) && 309 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET)) &&
319 (1 == inet_pton (AF_INET, 310 (1 == inet_pton (AF_INET, rh->hostname, &v4.sin_addr)))
320 rh->hostname,
321 &v4.sin_addr)) )
322 { 311 {
323 rh->addr_callback (rh->cls, 312 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
324 (const struct sockaddr*) &v4, 313 if ((rh->domain == AF_UNSPEC) &&
325 sizeof(v4)); 314 (1 == inet_pton (AF_INET6, rh->hostname, &v6.sin6_addr)))
326 if ( (rh->domain == AF_UNSPEC) && 315 {
327 (1 == inet_pton (AF_INET6, 316 /* this can happen on some systems IF "hostname" is "localhost" */
328 rh->hostname, 317 rh->addr_callback (rh->cls,
329 &v6.sin6_addr)) ) 318 (const struct sockaddr *) &v6, sizeof (v6));
330 { 319 }
331 /* this can happen on some systems IF "hostname" is "localhost" */ 320 rh->addr_callback (rh->cls, NULL, 0);
332 rh->addr_callback (rh->cls,
333 (const struct sockaddr*) &v6,
334 sizeof(v6));
335 }
336 rh->addr_callback (rh->cls, NULL, 0);
337 GNUNET_free (rh); 321 GNUNET_free (rh);
338 return; 322 return;
339 } 323 }
340 if ( ( (rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6) ) && 324 if (((rh->domain == AF_UNSPEC) || (rh->domain == AF_INET6)) &&
341 (1 == inet_pton (AF_INET6, 325 (1 == inet_pton (AF_INET6, rh->hostname, &v6.sin6_addr)))
342 rh->hostname,
343 &v6.sin6_addr)) )
344 { 326 {
345 rh->addr_callback (rh->cls, 327 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
346 (const struct sockaddr*) &v6,
347 sizeof(v6));
348 rh->addr_callback (rh->cls, NULL, 0); 328 rh->addr_callback (rh->cls, NULL, 0);
349 GNUNET_free (rh); 329 GNUNET_free (rh);
350 return; 330 return;
@@ -365,44 +345,35 @@ numeric_resolution (void *cls,
365 * @param tc unused scheduler context 345 * @param tc unused scheduler context
366 */ 346 */
367static void 347static void
368loopback_resolution (void *cls, 348loopback_resolution (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
369 const struct GNUNET_SCHEDULER_TaskContext *tc)
370{ 349{
371 struct GNUNET_RESOLVER_RequestHandle *rh = cls; 350 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
372 struct sockaddr_in v4; 351 struct sockaddr_in v4;
373 struct sockaddr_in6 v6; 352 struct sockaddr_in6 v6;
374 353
375 memset (&v4, 0, sizeof(v4)); 354 memset (&v4, 0, sizeof (v4));
376 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 355 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
377 v4.sin_family = AF_INET; 356 v4.sin_family = AF_INET;
378#if HAVE_SOCKADDR_IN_SIN_LEN 357#if HAVE_SOCKADDR_IN_SIN_LEN
379 v4.sin_len = sizeof(v4); 358 v4.sin_len = sizeof (v4);
380#endif 359#endif
381 memset (&v6, 0, sizeof(v6)); 360 memset (&v6, 0, sizeof (v6));
382 v6.sin6_family = AF_INET6; 361 v6.sin6_family = AF_INET6;
383#if HAVE_SOCKADDR_IN_SIN_LEN 362#if HAVE_SOCKADDR_IN_SIN_LEN
384 v6.sin6_len = sizeof(v6); 363 v6.sin6_len = sizeof (v6);
385#endif 364#endif
386 v6.sin6_addr = in6addr_loopback; 365 v6.sin6_addr = in6addr_loopback;
387 switch (rh->domain) 366 switch (rh->domain)
388 { 367 {
389 case AF_INET: 368 case AF_INET:
390 rh->addr_callback (rh->cls, 369 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
391 (const struct sockaddr*) &v4,
392 sizeof(v4));
393 break; 370 break;
394 case AF_INET6: 371 case AF_INET6:
395 rh->addr_callback (rh->cls, 372 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
396 (const struct sockaddr*) &v6,
397 sizeof(v6));
398 break; 373 break;
399 case AF_UNSPEC: 374 case AF_UNSPEC:
400 rh->addr_callback (rh->cls, 375 rh->addr_callback (rh->cls, (const struct sockaddr *) &v6, sizeof (v6));
401 (const struct sockaddr*) &v6, 376 rh->addr_callback (rh->cls, (const struct sockaddr *) &v4, sizeof (v4));
402 sizeof(v6));
403 rh->addr_callback (rh->cls,
404 (const struct sockaddr*) &v4,
405 sizeof(v4));
406 break; 377 break;
407 default: 378 default:
408 GNUNET_break (0); 379 GNUNET_break (0);
@@ -431,8 +402,8 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched,
431 const char *hostname, 402 const char *hostname,
432 int domain, 403 int domain,
433 struct GNUNET_TIME_Relative timeout, 404 struct GNUNET_TIME_Relative timeout,
434 GNUNET_RESOLVER_AddressCallback callback, 405 GNUNET_RESOLVER_AddressCallback callback,
435 void *callback_cls) 406 void *callback_cls)
436{ 407{
437 struct GNUNET_CLIENT_Connection *client; 408 struct GNUNET_CLIENT_Connection *client;
438 struct GNUNET_RESOLVER_GetMessage *msg; 409 struct GNUNET_RESOLVER_GetMessage *msg;
@@ -451,32 +422,31 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched,
451 GNUNET_break (0); 422 GNUNET_break (0);
452 return NULL; 423 return NULL;
453 } 424 }
454 rh = GNUNET_malloc (sizeof(struct GNUNET_RESOLVER_RequestHandle) + slen); 425 rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen);
455 rh->sched = sched; 426 rh->sched = sched;
456 rh->domain = domain; 427 rh->domain = domain;
457 rh->addr_callback = callback; 428 rh->addr_callback = callback;
458 rh->cls = callback_cls; 429 rh->cls = callback_cls;
459 memcpy (&rh[1], hostname, slen); 430 memcpy (&rh[1], hostname, slen);
460 rh->hostname = (const char*) &rh[1]; 431 rh->hostname = (const char *) &rh[1];
461 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout); 432 rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
462 433
463 /* first, check if this is a numeric address */ 434 /* first, check if this is a numeric address */
464 if ( ( (1 == inet_pton (AF_INET, 435 if (((1 == inet_pton (AF_INET,
465 hostname, 436 hostname,
466 &v4)) && 437 &v4)) &&
467 ( (domain == AF_INET) || (domain == AF_UNSPEC)) ) || 438 ((domain == AF_INET) || (domain == AF_UNSPEC))) ||
468 ( (1 == inet_pton (AF_INET6, 439 ((1 == inet_pton (AF_INET6,
469 hostname, 440 hostname,
470 &v6)) && 441 &v6)) &&
471 ( (domain == AF_INET6) || (domain == AF_UNSPEC)) ) ) 442 ((domain == AF_INET6) || (domain == AF_UNSPEC))))
472 { 443 {
473 rh->task = GNUNET_SCHEDULER_add_delayed (sched, 444 rh->task = GNUNET_SCHEDULER_add_delayed (sched,
474 GNUNET_NO, 445 GNUNET_NO,
475 GNUNET_SCHEDULER_PRIORITY_KEEP, 446 GNUNET_SCHEDULER_PRIORITY_KEEP,
476 GNUNET_SCHEDULER_NO_TASK, 447 GNUNET_SCHEDULER_NO_TASK,
477 GNUNET_TIME_UNIT_ZERO, 448 GNUNET_TIME_UNIT_ZERO,
478 &numeric_resolution, 449 &numeric_resolution, rh);
479 rh);
480 return rh; 450 return rh;
481 } 451 }
482 /* then, check if this is a loopback address */ 452 /* then, check if this is a loopback address */
@@ -484,25 +454,24 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched,
484 while (loopback[i] != NULL) 454 while (loopback[i] != NULL)
485 if (0 == strcasecmp (loopback[i++], hostname)) 455 if (0 == strcasecmp (loopback[i++], hostname))
486 { 456 {
487 rh->task = GNUNET_SCHEDULER_add_delayed (sched, 457 rh->task = GNUNET_SCHEDULER_add_delayed (sched,
488 GNUNET_NO, 458 GNUNET_NO,
489 GNUNET_SCHEDULER_PRIORITY_KEEP, 459 GNUNET_SCHEDULER_PRIORITY_KEEP,
490 GNUNET_SCHEDULER_NO_TASK, 460 GNUNET_SCHEDULER_NO_TASK,
491 GNUNET_TIME_UNIT_ZERO, 461 GNUNET_TIME_UNIT_ZERO,
492 &loopback_resolution, 462 &loopback_resolution, rh);
493 rh); 463 return rh;
494 return rh;
495 } 464 }
496 465
497 client = GNUNET_CLIENT_connect (sched, "resolver", cfg); 466 client = GNUNET_CLIENT_connect (sched, "resolver", cfg);
498 if (client == NULL) 467 if (client == NULL)
499 { 468 {
500 GNUNET_free (rh); 469 GNUNET_free (rh);
501 return NULL; 470 return NULL;
502 } 471 }
503 rh->client = client; 472 rh->client = client;
504 473
505 msg = (struct GNUNET_RESOLVER_GetMessage*) buf; 474 msg = (struct GNUNET_RESOLVER_GetMessage *) buf;
506 msg->header.size = 475 msg->header.size =
507 htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + slen); 476 htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + slen);
508 msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); 477 msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
@@ -517,11 +486,10 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched,
517#endif 486#endif
518 if (GNUNET_OK != 487 if (GNUNET_OK !=
519 GNUNET_CLIENT_transmit_and_get_response (client, 488 GNUNET_CLIENT_transmit_and_get_response (client,
520 &msg->header, 489 &msg->header,
521 timeout, 490 timeout,
522 GNUNET_YES, 491 GNUNET_YES,
523 &handle_address_response, 492 &handle_address_response, rh))
524 rh))
525 { 493 {
526 GNUNET_free (rh); 494 GNUNET_free (rh);
527 GNUNET_CLIENT_disconnect (client); 495 GNUNET_CLIENT_disconnect (client);
@@ -538,8 +506,7 @@ GNUNET_RESOLVER_ip_get (struct GNUNET_SCHEDULER_Handle *sched,
538 * @param msg message with the hostname, NULL on error 506 * @param msg message with the hostname, NULL on error
539 */ 507 */
540static void 508static void
541handle_hostname_response (void *cls, 509handle_hostname_response (void *cls, const struct GNUNET_MessageHeader *msg)
542 const struct GNUNET_MessageHeader *msg)
543{ 510{
544 struct GNUNET_RESOLVER_RequestHandle *rh = cls; 511 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
545 uint16_t size; 512 uint16_t size;
@@ -596,17 +563,14 @@ handle_hostname_response (void *cls,
596 * @param tc unused scheduler context 563 * @param tc unused scheduler context
597 */ 564 */
598static void 565static void
599numeric_reverse (void *cls, 566numeric_reverse (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
600 const struct GNUNET_SCHEDULER_TaskContext *tc)
601{ 567{
602 struct GNUNET_RESOLVER_RequestHandle *rh = cls; 568 struct GNUNET_RESOLVER_RequestHandle *rh = cls;
603 char *result; 569 char *result;
604 570
605 result = no_resolve ((const struct sockaddr*) &rh[1], 571 result = no_resolve ((const struct sockaddr *) &rh[1], rh->salen);
606 rh->salen);
607#if DEBUG_RESOLVER 572#if DEBUG_RESOLVER
608 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("Resolver returns `%s'.\n"), result);
609 _("Resolver returns `%s'.\n"), result);
610#endif 574#endif
611 if (result != NULL) 575 if (result != NULL)
612 { 576 {
@@ -659,12 +623,11 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
659 if (GNUNET_NO == do_resolve) 623 if (GNUNET_NO == do_resolve)
660 { 624 {
661 rh->task = GNUNET_SCHEDULER_add_delayed (sched, 625 rh->task = GNUNET_SCHEDULER_add_delayed (sched,
662 GNUNET_NO, 626 GNUNET_NO,
663 GNUNET_SCHEDULER_PRIORITY_KEEP, 627 GNUNET_SCHEDULER_PRIORITY_KEEP,
664 GNUNET_SCHEDULER_NO_TASK, 628 GNUNET_SCHEDULER_NO_TASK,
665 GNUNET_TIME_UNIT_ZERO, 629 GNUNET_TIME_UNIT_ZERO,
666 &numeric_reverse, 630 &numeric_reverse, rh);
667 rh);
668 return rh; 631 return rh;
669 } 632 }
670 if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) > 633 if (salen + sizeof (struct GNUNET_RESOLVER_GetMessage) >
@@ -682,7 +645,7 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
682 } 645 }
683 rh->client = client; 646 rh->client = client;
684 647
685 msg = (struct GNUNET_RESOLVER_GetMessage*) buf; 648 msg = (struct GNUNET_RESOLVER_GetMessage *) buf;
686 msg->header.size = 649 msg->header.size =
687 htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + salen); 650 htons (sizeof (struct GNUNET_RESOLVER_GetMessage) + salen);
688 msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST); 651 msg->header.type = htons (GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST);
@@ -695,11 +658,10 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
695#endif 658#endif
696 if (GNUNET_OK != 659 if (GNUNET_OK !=
697 GNUNET_CLIENT_transmit_and_get_response (client, 660 GNUNET_CLIENT_transmit_and_get_response (client,
698 &msg->header, 661 &msg->header,
699 timeout, 662 timeout,
700 GNUNET_YES, 663 GNUNET_YES,
701 &handle_hostname_response, 664 &handle_hostname_response, rh))
702 rh))
703 { 665 {
704 GNUNET_CLIENT_disconnect (client); 666 GNUNET_CLIENT_disconnect (client);
705 GNUNET_free (rh); 667 GNUNET_free (rh);
@@ -722,8 +684,8 @@ GNUNET_RESOLVER_hostname_get (struct GNUNET_SCHEDULER_Handle *sched,
722 */ 684 */
723struct GNUNET_RESOLVER_RequestHandle * 685struct GNUNET_RESOLVER_RequestHandle *
724GNUNET_RESOLVER_hostname_resolve (struct GNUNET_SCHEDULER_Handle *sched, 686GNUNET_RESOLVER_hostname_resolve (struct GNUNET_SCHEDULER_Handle *sched,
725 const struct GNUNET_CONFIGURATION_Handle *cfg, 687 const struct GNUNET_CONFIGURATION_Handle
726 int domain, 688 *cfg, int domain,
727 struct GNUNET_TIME_Relative timeout, 689 struct GNUNET_TIME_Relative timeout,
728 GNUNET_RESOLVER_AddressCallback callback, 690 GNUNET_RESOLVER_AddressCallback callback,
729 void *cls) 691 void *cls)
@@ -742,7 +704,8 @@ GNUNET_RESOLVER_hostname_resolve (struct GNUNET_SCHEDULER_Handle *sched,
742 _("Resolving our hostname `%s'\n"), hostname); 704 _("Resolving our hostname `%s'\n"), hostname);
743#endif 705#endif
744 return GNUNET_RESOLVER_ip_get (sched, 706 return GNUNET_RESOLVER_ip_get (sched,
745 cfg, hostname, domain, timeout, callback, cls); 707 cfg, hostname, domain, timeout, callback,
708 cls);
746} 709}
747 710
748 711
@@ -760,8 +723,7 @@ GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *h)
760 if (h->client != NULL) 723 if (h->client != NULL)
761 GNUNET_CLIENT_disconnect (h->client); 724 GNUNET_CLIENT_disconnect (h->client);
762 if (h->task != GNUNET_SCHEDULER_NO_TASK) 725 if (h->task != GNUNET_SCHEDULER_NO_TASK)
763 GNUNET_SCHEDULER_cancel (h->sched, 726 GNUNET_SCHEDULER_cancel (h->sched, h->task);
764 h->task);
765 GNUNET_free (h); 727 GNUNET_free (h);
766} 728}
767 729
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 24ea28d2c..2bb356eb6 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -232,9 +232,9 @@ is_pending (struct GNUNET_SCHEDULER_Handle *sched,
232 */ 232 */
233static void 233static void
234update_sets (struct GNUNET_SCHEDULER_Handle *sched, 234update_sets (struct GNUNET_SCHEDULER_Handle *sched,
235 struct GNUNET_NETWORK_FDSet * rs, 235 struct GNUNET_NETWORK_FDSet *rs,
236 struct GNUNET_NETWORK_FDSet * ws, 236 struct GNUNET_NETWORK_FDSet *ws,
237 struct GNUNET_TIME_Relative *timeout) 237 struct GNUNET_TIME_Relative *timeout)
238{ 238{
239 struct Task *pos; 239 struct Task *pos;
240 240
@@ -254,12 +254,12 @@ update_sets (struct GNUNET_SCHEDULER_Handle *sched,
254 254
255 to = GNUNET_TIME_absolute_get_remaining (pos->timeout); 255 to = GNUNET_TIME_absolute_get_remaining (pos->timeout);
256 if (timeout->value > to.value) 256 if (timeout->value > to.value)
257 *timeout = to; 257 *timeout = to;
258 } 258 }
259 if (pos->read_set != NULL) 259 if (pos->read_set != NULL)
260 GNUNET_NETWORK_fdset_add (rs, pos->read_set); 260 GNUNET_NETWORK_fdset_add (rs, pos->read_set);
261 if (pos->write_set != NULL) 261 if (pos->write_set != NULL)
262 GNUNET_NETWORK_fdset_add (ws, pos->write_set); 262 GNUNET_NETWORK_fdset_add (ws, pos->write_set);
263 pos = pos->next; 263 pos = pos->next;
264 } 264 }
265} 265}
@@ -275,8 +275,8 @@ update_sets (struct GNUNET_SCHEDULER_Handle *sched,
275 * @return GNUNET_YES if there was some overlap 275 * @return GNUNET_YES if there was some overlap
276 */ 276 */
277static int 277static int
278set_overlaps (const struct GNUNET_NETWORK_FDSet * ready, 278set_overlaps (const struct GNUNET_NETWORK_FDSet *ready,
279 struct GNUNET_NETWORK_FDSet * want) 279 struct GNUNET_NETWORK_FDSet *want)
280{ 280{
281 if (NULL == want) 281 if (NULL == want)
282 return GNUNET_NO; 282 return GNUNET_NO;
@@ -307,7 +307,7 @@ is_ready (struct GNUNET_SCHEDULER_Handle *sched,
307 struct Task *task, 307 struct Task *task,
308 struct GNUNET_TIME_Absolute now, 308 struct GNUNET_TIME_Absolute now,
309 const struct GNUNET_NETWORK_FDSet *rs, 309 const struct GNUNET_NETWORK_FDSet *rs,
310 const struct GNUNET_NETWORK_FDSet * ws) 310 const struct GNUNET_NETWORK_FDSet *ws)
311{ 311{
312 if ((GNUNET_NO == task->run_on_shutdown) && (GNUNET_YES == sched->shutdown)) 312 if ((GNUNET_NO == task->run_on_shutdown) && (GNUNET_YES == sched->shutdown))
313 return GNUNET_NO; 313 return GNUNET_NO;
@@ -341,8 +341,7 @@ is_ready (struct GNUNET_SCHEDULER_Handle *sched,
341 * @param task task ready for execution 341 * @param task task ready for execution
342 */ 342 */
343static void 343static void
344queue_ready_task (struct GNUNET_SCHEDULER_Handle *handle, 344queue_ready_task (struct GNUNET_SCHEDULER_Handle *handle, struct Task *task)
345 struct Task *task)
346{ 345{
347 task->next = handle->ready[check_priority (task->priority)]; 346 task->next = handle->ready[check_priority (task->priority)];
348 handle->ready[check_priority (task->priority)] = task; 347 handle->ready[check_priority (task->priority)] = task;
@@ -360,8 +359,8 @@ queue_ready_task (struct GNUNET_SCHEDULER_Handle *handle,
360 */ 359 */
361static void 360static void
362check_ready (struct GNUNET_SCHEDULER_Handle *handle, 361check_ready (struct GNUNET_SCHEDULER_Handle *handle,
363 const struct GNUNET_NETWORK_FDSet * rs, 362 const struct GNUNET_NETWORK_FDSet *rs,
364 const struct GNUNET_NETWORK_FDSet * ws) 363 const struct GNUNET_NETWORK_FDSet *ws)
365{ 364{
366 struct Task *pos; 365 struct Task *pos;
367 struct Task *prev; 366 struct Task *prev;
@@ -375,9 +374,8 @@ check_ready (struct GNUNET_SCHEDULER_Handle *handle,
375 { 374 {
376#if DEBUG_TASKS 375#if DEBUG_TASKS
377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
378 "Checking readyness of task: %llu / %p\n", 377 "Checking readyness of task: %llu / %p\n",
379 pos->id, 378 pos->id, pos->callback_cls);
380 pos->callback_cls);
381#endif 379#endif
382 next = pos->next; 380 next = pos->next;
383 if (GNUNET_YES == is_ready (handle, pos, now, rs, ws)) 381 if (GNUNET_YES == is_ready (handle, pos, now, rs, ws))
@@ -401,7 +399,8 @@ check_ready (struct GNUNET_SCHEDULER_Handle *handle,
401 * 399 *
402 * @param t task to destroy 400 * @param t task to destroy
403 */ 401 */
404static void destroy_task (struct Task *t) 402static void
403destroy_task (struct Task *t)
405{ 404{
406 if (NULL != t->read_set) 405 if (NULL != t->read_set)
407 GNUNET_NETWORK_fdset_destroy (t->read_set); 406 GNUNET_NETWORK_fdset_destroy (t->read_set);
@@ -452,9 +451,7 @@ run_ready (struct GNUNET_SCHEDULER_Handle *sched)
452 pos->callback (pos->callback_cls, &tc); 451 pos->callback (pos->callback_cls, &tc);
453#if DEBUG_TASKS 452#if DEBUG_TASKS
454 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
455 "Running task: %llu / %p\n", 454 "Running task: %llu / %p\n", pos->id, pos->callback_cls);
456 pos->id,
457 pos->callback_cls);
458#endif 455#endif
459 destroy_task (pos); 456 destroy_task (pos);
460 sched->tasks_run++; 457 sched->tasks_run++;
@@ -477,9 +474,9 @@ sighandler_shutdown ()
477{ 474{
478 static char c; 475 static char c;
479 476
480 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_WRITE), 477 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
481 &c, 478 (sigpipe, GNUNET_DISK_PIPE_END_WRITE), &c,
482 sizeof(c)); 479 sizeof (c));
483} 480}
484 481
485 482
@@ -537,7 +534,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls)
537 { 534 {
538 GNUNET_NETWORK_fdset_zero (rs); 535 GNUNET_NETWORK_fdset_zero (rs);
539 GNUNET_NETWORK_fdset_zero (ws); 536 GNUNET_NETWORK_fdset_zero (ws);
540 timeout = GNUNET_TIME_relative_get_forever(); 537 timeout = GNUNET_TIME_relative_get_forever ();
541 update_sets (&sched, rs, ws, &timeout); 538 update_sets (&sched, rs, ws, &timeout);
542#ifndef MINGW 539#ifndef MINGW
543 GNUNET_NETWORK_fdset_handle_set (rs, pr); 540 GNUNET_NETWORK_fdset_handle_set (rs, pr);
@@ -545,30 +542,28 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls)
545 if (sched.ready_count > 0) 542 if (sched.ready_count > 0)
546 { 543 {
547 /* no blocking, more work already ready! */ 544 /* no blocking, more work already ready! */
548 timeout = GNUNET_TIME_relative_get_zero(); 545 timeout = GNUNET_TIME_relative_get_zero ();
549 } 546 }
550 ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout); 547 ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout);
551#ifndef MINGW 548#ifndef MINGW
552 if (GNUNET_NETWORK_fdset_handle_isset (rs, pr)) 549 if (GNUNET_NETWORK_fdset_handle_isset (rs, pr))
553 break; 550 break;
554#endif 551#endif
555 if (last_tr == sched.tasks_run) 552 if (last_tr == sched.tasks_run)
556 { 553 {
557 busy_wait_warning++; 554 busy_wait_warning++;
558 } 555 }
559 else 556 else
560 { 557 {
561 last_tr = sched.tasks_run; 558 last_tr = sched.tasks_run;
562 busy_wait_warning = 0; 559 busy_wait_warning = 0;
563 } 560 }
564 if ( (ret == 0) && 561 if ((ret == 0) && (timeout.value == 0) && (busy_wait_warning > 16))
565 (timeout.value == 0) && 562 {
566 (busy_wait_warning > 16) ) 563 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
567 { 564 _("Looks like we're busy waiting...\n"));
568 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 565 sleep (1); /* mitigate */
569 _("Looks like we're busy waiting...\n")); 566 }
570 sleep (1); /* mitigate */
571 }
572 if (ret == GNUNET_SYSERR) 567 if (ret == GNUNET_SYSERR)
573 { 568 {
574 if (errno == EINTR) 569 if (errno == EINTR)
@@ -707,9 +702,7 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Handle *sched,
707 ret = t->callback_cls; 702 ret = t->callback_cls;
708#if DEBUG_TASKS 703#if DEBUG_TASKS
709 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 704 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
710 "Canceling task: %llu / %p\n", 705 "Canceling task: %llu / %p\n", task, t->callback_cls);
711 task,
712 t->callback_cls);
713#endif 706#endif
714 destroy_task (t); 707 destroy_task (t);
715 return ret; 708 return ret;
@@ -745,9 +738,8 @@ GNUNET_SCHEDULER_add_continuation (struct GNUNET_SCHEDULER_Handle *sched,
745 task->run_on_shutdown = run_on_shutdown; 738 task->run_on_shutdown = run_on_shutdown;
746#if DEBUG_TASKS 739#if DEBUG_TASKS
747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
748 "Adding continuation task: %llu / %p\n", 741 "Adding continuation task: %llu / %p\n",
749 task->id, 742 task->id, task->callback_cls);
750 task->callback_cls);
751#endif 743#endif
752 queue_ready_task (sched, task); 744 queue_ready_task (sched, task);
753} 745}
@@ -848,11 +840,13 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_SCHEDULER_Handle * sched,
848 */ 840 */
849GNUNET_SCHEDULER_TaskIdentifier 841GNUNET_SCHEDULER_TaskIdentifier
850GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched, 842GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched,
851 int run_on_shutdown, 843 int run_on_shutdown,
852 enum GNUNET_SCHEDULER_Priority prio, 844 enum GNUNET_SCHEDULER_Priority prio,
853 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 845 GNUNET_SCHEDULER_TaskIdentifier
854 struct GNUNET_TIME_Relative delay, 846 prerequisite_task,
855 struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_Task main, void *cls) 847 struct GNUNET_TIME_Relative delay,
848 struct GNUNET_NETWORK_Handle * rfd,
849 GNUNET_SCHEDULER_Task main, void *cls)
856{ 850{
857 struct GNUNET_NETWORK_FDSet *rs; 851 struct GNUNET_NETWORK_FDSet *rs;
858 GNUNET_SCHEDULER_TaskIdentifier ret; 852 GNUNET_SCHEDULER_TaskIdentifier ret;
@@ -861,8 +855,8 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched,
861 rs = GNUNET_NETWORK_fdset_create (); 855 rs = GNUNET_NETWORK_fdset_create ();
862 GNUNET_NETWORK_fdset_set (rs, rfd); 856 GNUNET_NETWORK_fdset_set (rs, rfd);
863 ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, 857 ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio,
864 prerequisite_task, delay, 858 prerequisite_task, delay,
865 rs, NULL, main, cls); 859 rs, NULL, main, cls);
866 GNUNET_NETWORK_fdset_destroy (rs); 860 GNUNET_NETWORK_fdset_destroy (rs);
867 return ret; 861 return ret;
868} 862}
@@ -894,11 +888,13 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_SCHEDULER_Handle * sched,
894 */ 888 */
895GNUNET_SCHEDULER_TaskIdentifier 889GNUNET_SCHEDULER_TaskIdentifier
896GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle * sched, 890GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle * sched,
897 int run_on_shutdown, 891 int run_on_shutdown,
898 enum GNUNET_SCHEDULER_Priority prio, 892 enum GNUNET_SCHEDULER_Priority prio,
899 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 893 GNUNET_SCHEDULER_TaskIdentifier
900 struct GNUNET_TIME_Relative delay, 894 prerequisite_task,
901 struct GNUNET_NETWORK_Handle *wfd, GNUNET_SCHEDULER_Task main, void *cls) 895 struct GNUNET_TIME_Relative delay,
896 struct GNUNET_NETWORK_Handle * wfd,
897 GNUNET_SCHEDULER_Task main, void *cls)
902{ 898{
903 struct GNUNET_NETWORK_FDSet *ws; 899 struct GNUNET_NETWORK_FDSet *ws;
904 GNUNET_SCHEDULER_TaskIdentifier ret; 900 GNUNET_SCHEDULER_TaskIdentifier ret;
@@ -907,8 +903,8 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_SCHEDULER_Handle * sched,
907 ws = GNUNET_NETWORK_fdset_create (); 903 ws = GNUNET_NETWORK_fdset_create ();
908 GNUNET_NETWORK_fdset_set (ws, wfd); 904 GNUNET_NETWORK_fdset_set (ws, wfd);
909 ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, 905 ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio,
910 prerequisite_task, delay, 906 prerequisite_task, delay,
911 NULL, ws, main, cls); 907 NULL, ws, main, cls);
912 GNUNET_NETWORK_fdset_destroy (ws); 908 GNUNET_NETWORK_fdset_destroy (ws);
913 return ret; 909 return ret;
914} 910}
@@ -957,7 +953,7 @@ GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle * sched,
957 prerequisite_task, 953 prerequisite_task,
958 struct GNUNET_TIME_Relative delay, 954 struct GNUNET_TIME_Relative delay,
959 const struct GNUNET_NETWORK_FDSet * rs, 955 const struct GNUNET_NETWORK_FDSet * rs,
960 const struct GNUNET_NETWORK_FDSet * ws, 956 const struct GNUNET_NETWORK_FDSet * ws,
961 GNUNET_SCHEDULER_Task main, void *cls) 957 GNUNET_SCHEDULER_Task main, void *cls)
962{ 958{
963 struct Task *task; 959 struct Task *task;
@@ -987,9 +983,7 @@ GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle * sched,
987 sched->pending = task; 983 sched->pending = task;
988#if DEBUG_TASKS 984#if DEBUG_TASKS
989 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 985 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
990 "Adding task: %llu / %p\n", 986 "Adding task: %llu / %p\n", task->id, task->callback_cls);
991 task->id,
992 task->callback_cls);
993#endif 987#endif
994 return task->id; 988 return task->id;
995} 989}
@@ -1020,12 +1014,13 @@ GNUNET_SCHEDULER_add_select (struct GNUNET_SCHEDULER_Handle * sched,
1020 */ 1014 */
1021GNUNET_SCHEDULER_TaskIdentifier 1015GNUNET_SCHEDULER_TaskIdentifier
1022GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle * sched, 1016GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle * sched,
1023 int run_on_shutdown, 1017 int run_on_shutdown,
1024 enum GNUNET_SCHEDULER_Priority prio, 1018 enum GNUNET_SCHEDULER_Priority prio,
1025 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 1019 GNUNET_SCHEDULER_TaskIdentifier
1026 struct GNUNET_TIME_Relative delay, 1020 prerequisite_task,
1027 const struct GNUNET_DISK_FileHandle *rfd, 1021 struct GNUNET_TIME_Relative delay,
1028 GNUNET_SCHEDULER_Task main, void *cls) 1022 const struct GNUNET_DISK_FileHandle * rfd,
1023 GNUNET_SCHEDULER_Task main, void *cls)
1029{ 1024{
1030 struct GNUNET_NETWORK_FDSet *rs; 1025 struct GNUNET_NETWORK_FDSet *rs;
1031 GNUNET_SCHEDULER_TaskIdentifier ret; 1026 GNUNET_SCHEDULER_TaskIdentifier ret;
@@ -1034,8 +1029,8 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle * sched,
1034 rs = GNUNET_NETWORK_fdset_create (); 1029 rs = GNUNET_NETWORK_fdset_create ();
1035 GNUNET_NETWORK_fdset_handle_set (rs, rfd); 1030 GNUNET_NETWORK_fdset_handle_set (rs, rfd);
1036 ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, 1031 ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio,
1037 prerequisite_task, delay, 1032 prerequisite_task, delay,
1038 rs, NULL, main, cls); 1033 rs, NULL, main, cls);
1039 GNUNET_NETWORK_fdset_destroy (rs); 1034 GNUNET_NETWORK_fdset_destroy (rs);
1040 return ret; 1035 return ret;
1041} 1036}
@@ -1067,12 +1062,13 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_SCHEDULER_Handle * sched,
1067 */ 1062 */
1068GNUNET_SCHEDULER_TaskIdentifier 1063GNUNET_SCHEDULER_TaskIdentifier
1069GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle * sched, 1064GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle * sched,
1070 int run_on_shutdown, 1065 int run_on_shutdown,
1071 enum GNUNET_SCHEDULER_Priority prio, 1066 enum GNUNET_SCHEDULER_Priority prio,
1072 GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 1067 GNUNET_SCHEDULER_TaskIdentifier
1073 struct GNUNET_TIME_Relative delay, 1068 prerequisite_task,
1074 const struct GNUNET_DISK_FileHandle *wfd, 1069 struct GNUNET_TIME_Relative delay,
1075 GNUNET_SCHEDULER_Task main, void *cls) 1070 const struct GNUNET_DISK_FileHandle * wfd,
1071 GNUNET_SCHEDULER_Task main, void *cls)
1076{ 1072{
1077 struct GNUNET_NETWORK_FDSet *ws; 1073 struct GNUNET_NETWORK_FDSet *ws;
1078 GNUNET_SCHEDULER_TaskIdentifier ret; 1074 GNUNET_SCHEDULER_TaskIdentifier ret;
@@ -1081,8 +1077,8 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_SCHEDULER_Handle * sched,
1081 ws = GNUNET_NETWORK_fdset_create (); 1077 ws = GNUNET_NETWORK_fdset_create ();
1082 GNUNET_NETWORK_fdset_handle_set (ws, wfd); 1078 GNUNET_NETWORK_fdset_handle_set (ws, wfd);
1083 ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio, 1079 ret = GNUNET_SCHEDULER_add_select (sched, run_on_shutdown, prio,
1084 prerequisite_task, delay, 1080 prerequisite_task, delay,
1085 NULL, ws, main, cls); 1081 NULL, ws, main, cls);
1086 GNUNET_NETWORK_fdset_destroy (ws); 1082 GNUNET_NETWORK_fdset_destroy (ws);
1087 return ret; 1083 return ret;
1088} 1084}
diff --git a/src/util/server.c b/src/util/server.c
index 646299718..42fa8c46c 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -272,13 +272,11 @@ destroy_server (struct GNUNET_SERVER_Handle *server)
272 struct NotifyList *npos; 272 struct NotifyList *npos;
273 273
274#if DEBUG_SERVER 274#if DEBUG_SERVER
275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 275 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Server shutting down.\n");
276 "Server shutting down.\n");
277#endif 276#endif
278 GNUNET_assert (server->listen_socket == NULL); 277 GNUNET_assert (server->listen_socket == NULL);
279 if (GNUNET_OK != GNUNET_DISK_pipe_close (server->shutpipe)) 278 if (GNUNET_OK != GNUNET_DISK_pipe_close (server->shutpipe))
280 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 279 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "pipe-close");
281 "pipe-close");
282 while (server->clients != NULL) 280 while (server->clients != NULL)
283 { 281 {
284 pos = server->clients; 282 pos = server->clients;
@@ -318,26 +316,29 @@ process_listen_socket (void *cls,
318 { 316 {
319 /* shutdown was initiated */ 317 /* shutdown was initiated */
320 GNUNET_assert (server->listen_socket != NULL); 318 GNUNET_assert (server->listen_socket != NULL);
321 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (server->listen_socket)); 319 GNUNET_break (GNUNET_OK ==
320 GNUNET_NETWORK_socket_close (server->listen_socket));
322 server->listen_socket = NULL; 321 server->listen_socket = NULL;
323 if (server->do_shutdown) 322 if (server->do_shutdown)
324 destroy_server (server); 323 destroy_server (server);
325 return; 324 return;
326 } 325 }
327 shutpipe = GNUNET_DISK_pipe_handle (server->shutpipe, 326 shutpipe = GNUNET_DISK_pipe_handle (server->shutpipe,
328 GNUNET_DISK_PIPE_END_READ); 327 GNUNET_DISK_PIPE_END_READ);
329 GNUNET_assert (GNUNET_NETWORK_fdset_isset (tc->read_ready, server->listen_socket)); 328 GNUNET_assert (GNUNET_NETWORK_fdset_isset
330 GNUNET_assert (!GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, shutpipe)); 329 (tc->read_ready, server->listen_socket));
331 sock = GNUNET_CONNECTION_create_from_accept (tc->sched, 330 GNUNET_assert (!GNUNET_NETWORK_fdset_handle_isset
332 server->access, 331 (tc->read_ready, shutpipe));
333 server->access_cls, 332 sock =
334 server->listen_socket, 333 GNUNET_CONNECTION_create_from_accept (tc->sched, server->access,
335 server->maxbuf); 334 server->access_cls,
335 server->listen_socket,
336 server->maxbuf);
336 if (sock != NULL) 337 if (sock != NULL)
337 { 338 {
338#if DEBUG_SERVER 339#if DEBUG_SERVER
339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 340 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
340 "Server accepted incoming connection.\n"); 341 "Server accepted incoming connection.\n");
341#endif 342#endif
342 client = GNUNET_SERVER_connect_socket (server, sock); 343 client = GNUNET_SERVER_connect_socket (server, sock);
343 /* decrement reference count, we don't keep "client" alive */ 344 /* decrement reference count, we don't keep "client" alive */
@@ -352,8 +353,7 @@ process_listen_socket (void *cls,
352 GNUNET_SCHEDULER_PRIORITY_HIGH, 353 GNUNET_SCHEDULER_PRIORITY_HIGH,
353 GNUNET_SCHEDULER_NO_TASK, 354 GNUNET_SCHEDULER_NO_TASK,
354 GNUNET_TIME_UNIT_FOREVER_REL, 355 GNUNET_TIME_UNIT_FOREVER_REL,
355 r, NULL, 356 r, NULL, &process_listen_socket, server);
356 &process_listen_socket, server);
357 GNUNET_NETWORK_fdset_destroy (r); 357 GNUNET_NETWORK_fdset_destroy (r);
358} 358}
359 359
@@ -388,7 +388,8 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen)
388 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 388 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
389 return NULL; 389 return NULL;
390 } 390 }
391 if (GNUNET_NETWORK_socket_setsockopt (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) 391 if (GNUNET_NETWORK_socket_setsockopt
392 (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
392 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 393 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
393 "setsockopt"); 394 "setsockopt");
394 /* bind the socket */ 395 /* bind the socket */
@@ -409,9 +410,8 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen)
409 return NULL; 410 return NULL;
410 } 411 }
411#if DEBUG_SERVER 412#if DEBUG_SERVER
412 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
413 "Server starts to listen on port %u.\n", 414 "Server starts to listen on port %u.\n", port);
414 port);
415#endif 415#endif
416 return sock; 416 return sock;
417} 417}
@@ -472,15 +472,14 @@ GNUNET_SERVER_create (struct GNUNET_SCHEDULER_Handle *sched,
472 { 472 {
473 r = GNUNET_NETWORK_fdset_create (); 473 r = GNUNET_NETWORK_fdset_create ();
474 GNUNET_NETWORK_fdset_set (r, ret->listen_socket); 474 GNUNET_NETWORK_fdset_set (r, ret->listen_socket);
475 GNUNET_NETWORK_fdset_handle_set (r, GNUNET_DISK_pipe_handle (ret->shutpipe, 475 GNUNET_NETWORK_fdset_handle_set (r,
476 GNUNET_DISK_PIPE_END_READ)); 476 GNUNET_DISK_pipe_handle (ret->shutpipe,
477 GNUNET_SCHEDULER_add_select (sched, 477 GNUNET_DISK_PIPE_END_READ));
478 GNUNET_YES, 478 GNUNET_SCHEDULER_add_select (sched, GNUNET_YES,
479 GNUNET_SCHEDULER_PRIORITY_HIGH, 479 GNUNET_SCHEDULER_PRIORITY_HIGH,
480 GNUNET_SCHEDULER_NO_TASK, 480 GNUNET_SCHEDULER_NO_TASK,
481 GNUNET_TIME_UNIT_FOREVER_REL, 481 GNUNET_TIME_UNIT_FOREVER_REL, r, NULL,
482 r, 482 &process_listen_socket, ret);
483 NULL, &process_listen_socket, ret);
484 GNUNET_NETWORK_fdset_destroy (r); 483 GNUNET_NETWORK_fdset_destroy (r);
485 } 484 }
486 return ret; 485 return ret;
@@ -500,10 +499,11 @@ GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *s)
500 if (s->listen_socket == NULL) 499 if (s->listen_socket == NULL)
501 destroy_server (s); 500 destroy_server (s);
502 else 501 else
503 GNUNET_break (1 == GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle (s->shutpipe, 502 GNUNET_break (1 ==
504 GNUNET_DISK_PIPE_END_WRITE), 503 GNUNET_DISK_file_write (GNUNET_DISK_pipe_handle
505 &c, 504 (s->shutpipe,
506 sizeof(c))); 505 GNUNET_DISK_PIPE_END_WRITE), &c,
506 sizeof (c)));
507} 507}
508 508
509 509
@@ -565,9 +565,8 @@ GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server,
565 size = ntohs (message->size); 565 size = ntohs (message->size);
566#if DEBUG_SERVER 566#if DEBUG_SERVER
567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 567 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
568 "Server schedules transmission of %u-byte message of type %u to client.\n", 568 "Server schedules transmission of %u-byte message of type %u to client.\n",
569 size, 569 size, type);
570 type);
571#endif 570#endif
572 pos = server->handlers; 571 pos = server->handlers;
573 found = GNUNET_NO; 572 found = GNUNET_NO;
@@ -668,10 +667,10 @@ process_client_buffer (struct GNUNET_SERVER_Client *client)
668 server = client->server; 667 server = client->server;
669#if DEBUG_SERVER 668#if DEBUG_SERVER
670 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
671 "Private buffer contains %u bytes; client is %s and we are %s\n", 670 "Private buffer contains %u bytes; client is %s and we are %s\n",
672 client->receive_pos, 671 client->receive_pos,
673 client->suspended ? "suspended" : "up", 672 client->suspended ? "suspended" : "up",
674 client->shutdown_now ? "in shutdown" : "running"); 673 client->shutdown_now ? "in shutdown" : "running");
675#endif 674#endif
676 while ((client->receive_pos >= sizeof (struct GNUNET_MessageHeader)) && 675 while ((client->receive_pos >= sizeof (struct GNUNET_MessageHeader)) &&
677 (0 == client->suspended) && (GNUNET_YES != client->shutdown_now)) 676 (0 == client->suspended) && (GNUNET_YES != client->shutdown_now))
@@ -679,19 +678,17 @@ process_client_buffer (struct GNUNET_SERVER_Client *client)
679 hdr = (const struct GNUNET_MessageHeader *) &client->incoming_buffer; 678 hdr = (const struct GNUNET_MessageHeader *) &client->incoming_buffer;
680 msize = ntohs (hdr->size); 679 msize = ntohs (hdr->size);
681 if (msize > client->receive_pos) 680 if (msize > client->receive_pos)
682 { 681 {
683#if DEBUG_SERVER 682#if DEBUG_SERVER
684 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
685 "Total message size is %u, we only have %u bytes; need more data\n", 684 "Total message size is %u, we only have %u bytes; need more data\n",
686 msize, 685 msize, client->receive_pos);
687 client->receive_pos);
688#endif 686#endif
689 break; 687 break;
690 } 688 }
691#if DEBUG_SERVER 689#if DEBUG_SERVER
692 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 690 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
693 "Passing %u bytes to callback for processing\n", 691 "Passing %u bytes to callback for processing\n", msize);
694 msize);
695#endif 692#endif
696 if ((msize < sizeof (struct GNUNET_MessageHeader)) || 693 if ((msize < sizeof (struct GNUNET_MessageHeader)) ||
697 (GNUNET_OK != GNUNET_SERVER_inject (server, client, hdr))) 694 (GNUNET_OK != GNUNET_SERVER_inject (server, client, hdr)))
@@ -727,9 +724,7 @@ static void
727process_incoming (void *cls, 724process_incoming (void *cls,
728 const void *buf, 725 const void *buf,
729 size_t available, 726 size_t available,
730 const struct sockaddr *addr, 727 const struct sockaddr *addr, socklen_t addrlen, int errCode)
731 socklen_t addrlen,
732 int errCode)
733{ 728{
734 struct GNUNET_SERVER_Client *client = cls; 729 struct GNUNET_SERVER_Client *client = cls;
735 struct GNUNET_SERVER_Handle *server = client->server; 730 struct GNUNET_SERVER_Handle *server = client->server;
@@ -749,9 +744,8 @@ process_incoming (void *cls,
749 } 744 }
750#if DEBUG_SERVER 745#if DEBUG_SERVER
751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 746 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
752 "Server receives %u bytes from `%s'.\n", 747 "Server receives %u bytes from `%s'.\n",
753 available, 748 available, GNUNET_a2s (addr, addrlen));
754 GNUNET_a2s(addr, addrlen));
755#endif 749#endif
756 GNUNET_SERVER_client_keep (client); 750 GNUNET_SERVER_client_keep (client);
757 client->last_activity = GNUNET_TIME_absolute_get (); 751 client->last_activity = GNUNET_TIME_absolute_get ();
@@ -763,8 +757,7 @@ process_incoming (void *cls,
763 maxcpy = sizeof (client->incoming_buffer) - client->receive_pos; 757 maxcpy = sizeof (client->incoming_buffer) - client->receive_pos;
764#if DEBUG_SERVER 758#if DEBUG_SERVER
765 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 759 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
766 "Can copy %u bytes to private buffer\n", 760 "Can copy %u bytes to private buffer\n", maxcpy);
767 maxcpy);
768#endif 761#endif
769 memcpy (&client->incoming_buffer[client->receive_pos], cbuf, maxcpy); 762 memcpy (&client->incoming_buffer[client->receive_pos], cbuf, maxcpy);
770 client->receive_pos += maxcpy; 763 client->receive_pos += maxcpy;
@@ -775,12 +768,12 @@ process_incoming (void *cls,
775 if (available > 0) 768 if (available > 0)
776 { 769 {
777#if DEBUG_SERVER 770#if DEBUG_SERVER
778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 771 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
779 "Client has suspended processing; copying %u bytes to side buffer to be used later.\n", 772 "Client has suspended processing; copying %u bytes to side buffer to be used later.\n",
780 available); 773 available);
781#endif 774#endif
782 GNUNET_assert (client->side_buf_size == 0); 775 GNUNET_assert (client->side_buf_size == 0);
783 GNUNET_assert (client->side_buf == NULL); 776 GNUNET_assert (client->side_buf == NULL);
784 client->side_buf_size = available; 777 client->side_buf_size = available;
785 client->side_buf = GNUNET_malloc (available); 778 client->side_buf = GNUNET_malloc (available);
786 memcpy (client->side_buf, cbuf, available); 779 memcpy (client->side_buf, cbuf, available);
@@ -790,7 +783,7 @@ process_incoming (void *cls,
790 } 783 }
791#if DEBUG_SERVER 784#if DEBUG_SERVER
792 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
793 "Now processing messages in private buffer\n"); 786 "Now processing messages in private buffer\n");
794#endif 787#endif
795 process_client_buffer (client); 788 process_client_buffer (client);
796 } 789 }
@@ -800,9 +793,8 @@ process_incoming (void *cls,
800 { 793 {
801 /* Finally, keep receiving! */ 794 /* Finally, keep receiving! */
802 client->receive (client->client_closure, 795 client->receive (client->client_closure,
803 GNUNET_SERVER_MAX_MESSAGE_SIZE, 796 GNUNET_SERVER_MAX_MESSAGE_SIZE,
804 server->idle_timeout, 797 server->idle_timeout, &process_incoming, client);
805 &process_incoming, client);
806 } 798 }
807 if (GNUNET_YES == client->shutdown_now) 799 if (GNUNET_YES == client->shutdown_now)
808 shutdown_incoming_processing (client); 800 shutdown_incoming_processing (client);
@@ -821,9 +813,8 @@ restart_processing (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
821 process_client_buffer (client); 813 process_client_buffer (client);
822 if (0 == client->suspended) 814 if (0 == client->suspended)
823 client->receive (client->client_closure, 815 client->receive (client->client_closure,
824 GNUNET_SERVER_MAX_MESSAGE_SIZE, 816 GNUNET_SERVER_MAX_MESSAGE_SIZE,
825 client->server->idle_timeout, 817 client->server->idle_timeout, &process_incoming, client);
826 &process_incoming, client);
827} 818}
828 819
829 820
@@ -840,9 +831,8 @@ add_client (struct GNUNET_SERVER_Handle *server,
840 client->next = server->clients; 831 client->next = server->clients;
841 server->clients = client; 832 server->clients = client;
842 client->receive (client->client_closure, 833 client->receive (client->client_closure,
843 GNUNET_SERVER_MAX_MESSAGE_SIZE, 834 GNUNET_SERVER_MAX_MESSAGE_SIZE,
844 server->idle_timeout, 835 server->idle_timeout, &process_incoming, client);
845 &process_incoming, client);
846} 836}
847 837
848 838
@@ -888,7 +878,7 @@ sock_notify_transmit_ready (void *cls,
888 void *notify_cls) 878 void *notify_cls)
889{ 879{
890 return GNUNET_CONNECTION_notify_transmit_ready (cls, size, timeout, notify, 880 return GNUNET_CONNECTION_notify_transmit_ready (cls, size, timeout, notify,
891 notify_cls); 881 notify_cls);
892} 882}
893 883
894 884
@@ -1058,7 +1048,7 @@ GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client,
1058 if (client->receive != &sock_receive) 1048 if (client->receive != &sock_receive)
1059 return GNUNET_SYSERR; /* not a network client */ 1049 return GNUNET_SYSERR; /* not a network client */
1060 return GNUNET_CONNECTION_get_address (client->client_closure, 1050 return GNUNET_CONNECTION_get_address (client->client_closure,
1061 addr, addrlen); 1051 addr, addrlen);
1062} 1052}
1063 1053
1064 1054
diff --git a/src/util/service.c b/src/util/service.c
index 948730df9..0a33809be 100644
--- a/src/util/service.c
+++ b/src/util/service.c
@@ -650,7 +650,7 @@ check_access (void *cls, const struct sockaddr *addr, socklen_t addrlen)
650 { 650 {
651 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 651 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
652 _("Access from `%s' denied to service `%s'\n"), 652 _("Access from `%s' denied to service `%s'\n"),
653 GNUNET_a2s(addr, addrlen), sctx->serviceName); 653 GNUNET_a2s (addr, addrlen), sctx->serviceName);
654 } 654 }
655 return ret; 655 return ret;
656} 656}
@@ -770,8 +770,8 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
770 { 770 {
771 if (GNUNET_OK != 771 if (GNUNET_OK !=
772 GNUNET_CONFIGURATION_get_value_time (sctx->cfg, 772 GNUNET_CONFIGURATION_get_value_time (sctx->cfg,
773 sctx->serviceName, 773 sctx->serviceName,
774 "TIMEOUT", &idleout)) 774 "TIMEOUT", &idleout))
775 return GNUNET_SYSERR; 775 return GNUNET_SYSERR;
776 776
777 sctx->timeout = idleout; 777 sctx->timeout = idleout;
@@ -794,7 +794,8 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
794 { 794 {
795 if (GNUNET_SYSERR == 795 if (GNUNET_SYSERR ==
796 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg, 796 (disablev6 = GNUNET_CONFIGURATION_get_value_yesno (sctx->cfg,
797 sctx->serviceName, 797 sctx->
798 serviceName,
798 "DISABLEV6"))) 799 "DISABLEV6")))
799 return GNUNET_SYSERR; 800 return GNUNET_SYSERR;
800 } 801 }
@@ -824,16 +825,16 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
824 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 825 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
825 return GNUNET_SYSERR; 826 return GNUNET_SYSERR;
826 } 827 }
827 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 828 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
828 _("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"), 829 _
829 sctx->serviceName, 830 ("Disabling IPv6 support for service `%s', failed to create IPv6 socket: %s\n"),
830 STRERROR (errno)); 831 sctx->serviceName, STRERROR (errno));
831 disablev6 = GNUNET_YES; 832 disablev6 = GNUNET_YES;
832 } 833 }
833 else 834 else
834 { 835 {
835 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc)); 836 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (desc));
836 } 837 }
837 } 838 }
838 839
839 840
@@ -900,7 +901,7 @@ setup_service (struct GNUNET_SERVICE_Context *sctx)
900 { 901 {
901 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 902 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
902 _("Failed to find %saddress for `%s'.\n"), 903 _("Failed to find %saddress for `%s'.\n"),
903 disablev6 ? "IPv4 " : "", hostname); 904 disablev6 ? "IPv4 " : "", hostname);
904 freeaddrinfo (res); 905 freeaddrinfo (res);
905 GNUNET_free (hostname); 906 GNUNET_free (hostname);
906 return GNUNET_SYSERR; 907 return GNUNET_SYSERR;
@@ -1086,10 +1087,8 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1086 if (sctx->server == NULL) 1087 if (sctx->server == NULL)
1087 { 1088 {
1088 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1089 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1089 _("Failed to start `%s' at `%s'\n"), 1090 _("Failed to start `%s' at `%s'\n"),
1090 sctx->serviceName, 1091 sctx->serviceName, GNUNET_a2s (sctx->addr, sctx->addrlen));
1091 GNUNET_a2s (sctx->addr,
1092 sctx->addrlen));
1093 sctx->ret = GNUNET_SYSERR; 1092 sctx->ret = GNUNET_SYSERR;
1094 return; 1093 return;
1095 } 1094 }
@@ -1107,10 +1106,8 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1107 write_pid_file (sctx, getpid ()); 1106 write_pid_file (sctx, getpid ());
1108 } 1107 }
1109 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1108 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1110 _("Service `%s' runs at %s\n"), 1109 _("Service `%s' runs at %s\n"),
1111 sctx->serviceName, 1110 sctx->serviceName, GNUNET_a2s (sctx->addr, sctx->addrlen));
1112 GNUNET_a2s (sctx->addr,
1113 sctx->addrlen));
1114 sctx->task (sctx->task_cls, tc->sched, sctx->server, sctx->cfg); 1111 sctx->task (sctx->task_cls, tc->sched, sctx->server, sctx->cfg);
1115} 1112}
1116 1113
@@ -1121,7 +1118,7 @@ service_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1121static int 1118static int
1122detach_terminal (struct GNUNET_SERVICE_Context *sctx) 1119detach_terminal (struct GNUNET_SERVICE_Context *sctx)
1123{ 1120{
1124#ifndef MINGW 1121#ifndef MINGW
1125 pid_t pid; 1122 pid_t pid;
1126 int nullfd; 1123 int nullfd;
1127 int filedes[2]; 1124 int filedes[2];
@@ -1304,7 +1301,7 @@ GNUNET_SERVICE_run (int argc,
1304 sctx.cfg = cfg = GNUNET_CONFIGURATION_create (); 1301 sctx.cfg = cfg = GNUNET_CONFIGURATION_create ();
1305 /* setup subsystems */ 1302 /* setup subsystems */
1306 if ((GNUNET_SYSERR == 1303 if ((GNUNET_SYSERR ==
1307 GNUNET_GETOPT_run (serviceName, 1304 GNUNET_GETOPT_run (serviceName,
1308 service_options, 1305 service_options,
1309 argc, 1306 argc,
1310 argv)) || 1307 argv)) ||
@@ -1337,9 +1334,8 @@ GNUNET_SERVICE_run (int argc,
1337 } 1334 }
1338#if 0 1335#if 0
1339 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1336 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1340 "Service `%s' runs with configuration from `%s'\n", 1337 "Service `%s' runs with configuration from `%s'\n",
1341 serviceName, 1338 serviceName, cfg_fn);
1342 cfg_fn);
1343#endif 1339#endif
1344 /* actually run service */ 1340 /* actually run service */
1345 GNUNET_SCHEDULER_run (&service_task, &sctx); 1341 GNUNET_SCHEDULER_run (&service_task, &sctx);
diff --git a/src/util/strings.c b/src/util/strings.c
index 133fda857..d53bcd482 100644
--- a/src/util/strings.c
+++ b/src/util/strings.c
@@ -198,13 +198,13 @@ GNUNET_STRINGS_to_utf8 (const char *input, size_t len, const char *charset)
198 tmp = GNUNET_malloc (tmpSize); 198 tmp = GNUNET_malloc (tmpSize);
199 itmp = tmp; 199 itmp = tmp;
200 finSize = tmpSize; 200 finSize = tmpSize;
201 if (iconv (cd, 201 if (iconv (cd,
202#if FREEBSD 202#if FREEBSD
203 (const char **) &input, 203 (const char **) &input,
204#else 204#else
205 (char **) &input, 205 (char **) &input,
206#endif 206#endif
207 &len, &itmp, &finSize) == (size_t) - 1) 207 &len, &itmp, &finSize) == (size_t) - 1)
208 { 208 {
209 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "iconv"); 209 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "iconv");
210 iconv_close (cd); 210 iconv_close (cd);
diff --git a/src/util/test_bio.c b/src/util/test_bio.c
index c673fc11f..7b5be6ccd 100644
--- a/src/util/test_bio.c
+++ b/src/util/test_bio.c
@@ -34,98 +34,121 @@ int
34main (int argc, char *argv[]) 34main (int argc, char *argv[])
35{ 35{
36 36
37 char *readResultString; 37 char *readResultString;
38 int64_t testNumber = (int64_t)TESTNUMBER64; 38 int64_t testNumber = (int64_t) TESTNUMBER64;
39 int64_t testNum; 39 int64_t testNum;
40 char *msg; 40 char *msg;
41 char file[102400]; 41 static char file[102400];
42 char meta[1024*1024*10]; 42 static char meta[1024 * 1024 * 10];
43 int i,j; 43 int i, j;
44 for(i=0;i<102400;i++){ 44 for (i = 0; i < 102400; i++)
45 file[i]='a'; 45 {
46 file[i] = 'a';
46 } 47 }
47 for(j=0;j<1024*1024*10;j++){ 48 for (j = 0; j < 1024 * 1024 * 10; j++)
48 meta[j]='b'; 49 {
50 meta[j] = 'b';
49 } 51 }
50 char* fileName = GNUNET_DISK_mktemp ("gnunet_bio"); 52 char *fileName = GNUNET_DISK_mktemp ("gnunet_bio");
51 char* fileName2 = GNUNET_DISK_mktemp ("gnunet_zwei_bio"); 53 char *fileName2 = GNUNET_DISK_mktemp ("gnunet_zwei_bio");
52 char* fileName3 = GNUNET_DISK_mktemp ("gnunet_drei_bio"); 54 char *fileName3 = GNUNET_DISK_mktemp ("gnunet_drei_bio");
53 char* fileName4 = GNUNET_DISK_mktemp ("gnunet_vier_bio"); 55 char *fileName4 = GNUNET_DISK_mktemp ("gnunet_vier_bio");
54 56
55 struct GNUNET_BIO_ReadHandle *fileR,*fileR2,*fileR3,*fileR4; 57 struct GNUNET_BIO_ReadHandle *fileR, *fileR2, *fileR3, *fileR4;
56 struct GNUNET_BIO_WriteHandle *fileW,*fileW2,*fileW3,*fileW4; 58 struct GNUNET_BIO_WriteHandle *fileW, *fileW2, *fileW3, *fileW4;
57 struct GNUNET_CONTAINER_MetaData *metaDataW; 59 struct GNUNET_CONTAINER_MetaData *metaDataW;
58 struct GNUNET_CONTAINER_MetaData *metaDataR; 60 struct GNUNET_CONTAINER_MetaData *metaDataR;
59 struct GNUNET_BIO_ReadHandle *fileRNO; 61 struct GNUNET_BIO_ReadHandle *fileRNO;
60 struct GNUNET_BIO_WriteHandle *fileWNO; 62 struct GNUNET_BIO_WriteHandle *fileWNO;
61 struct GNUNET_CONTAINER_MetaData *metaData; 63 struct GNUNET_CONTAINER_MetaData *metaData;
62 struct GNUNET_CONTAINER_MetaData *metaDataNO; 64 struct GNUNET_CONTAINER_MetaData *metaDataNO;
63 65
64 metaData = GNUNET_CONTAINER_meta_data_create(); 66 metaData = GNUNET_CONTAINER_meta_data_create ();
65 metaDataNO = GNUNET_CONTAINER_meta_data_create(); 67 metaDataNO = GNUNET_CONTAINER_meta_data_create ();
66 metaDataR = GNUNET_CONTAINER_meta_data_create(); 68 metaDataR = GNUNET_CONTAINER_meta_data_create ();
67 metaDataW = GNUNET_CONTAINER_meta_data_create(); 69 metaDataW = GNUNET_CONTAINER_meta_data_create ();
68 GNUNET_CONTAINER_meta_data_add_publication_date(metaDataW); 70 GNUNET_CONTAINER_meta_data_add_publication_date (metaDataW);
69 GNUNET_CONTAINER_meta_data_add_publication_date(metaData); 71 GNUNET_CONTAINER_meta_data_add_publication_date (metaData);
70 GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_meta_data_insert(metaData,EXTRACTOR_COMMENT,meta)); 72 GNUNET_assert (GNUNET_OK ==
73 GNUNET_CONTAINER_meta_data_insert (metaData,
74 EXTRACTOR_COMMENT, meta));
71 75
72///////////write 76///////////write
73 fileW = GNUNET_BIO_write_open(fileName); 77 fileW = GNUNET_BIO_write_open (fileName);
74 GNUNET_assert(NULL != fileW); 78 GNUNET_assert (NULL != fileW);
75 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_string(fileW, TESTSTRING)); 79 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW, TESTSTRING));
76 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_meta_data(fileW,metaDataW)); 80 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_meta_data (fileW, metaDataW));
77 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_int64(fileW,testNumber)); 81 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_int64 (fileW, testNumber));
78 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_close(fileW)); 82 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW));
79 fileW2 = GNUNET_BIO_write_open(fileName2); 83 fileW2 = GNUNET_BIO_write_open (fileName2);
80 GNUNET_assert(NULL != fileW2); 84 GNUNET_assert (NULL != fileW2);
81 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_string(fileW2,NULL)); 85 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW2, NULL));
82 fileWNO = GNUNET_BIO_write_open(file); 86 fileWNO = GNUNET_BIO_write_open (file);
83 fileW3 = GNUNET_BIO_write_open(fileName3); 87 GNUNET_assert (NULL != fileWNO);
84 GNUNET_assert(NULL != fileW3); 88 GNUNET_assert (GNUNET_SYSERR ==
85 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_meta_data(fileW3,metaData)); 89 GNUNET_BIO_write_string (fileWNO, TESTSTRING));
86 fileW4 = GNUNET_BIO_write_open(fileName4); 90 GNUNET_assert (GNUNET_SYSERR ==
87 GNUNET_assert(NULL != fileW4); 91 GNUNET_BIO_write_meta_data (fileWNO, metaDataW));
88 GNUNET_assert(GNUNET_OK == GNUNET_BIO_write_string(fileW4,"")); 92 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_write_close (fileWNO));
89 GNUNET_assert(NULL != fileWNO); 93 fileW3 = GNUNET_BIO_write_open (fileName3);
90 GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_write_string(fileWNO, TESTSTRING)); 94 GNUNET_assert (NULL != fileW3);
91 GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_write_meta_data(fileWNO,metaDataW)); 95 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_meta_data (fileW3, metaData));
92 GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_write_close(fileWNO)); 96 fileW4 = GNUNET_BIO_write_open (fileName4);
97 GNUNET_assert (NULL != fileW4);
98 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_string (fileW4, ""));
99 GNUNET_assert (GNUNET_OK == GNUNET_BIO_write_close (fileW4));
93 100
94////////////read 101////////////read
95 fileRNO = GNUNET_BIO_read_open(file); 102 fileRNO = GNUNET_BIO_read_open (file);
96 GNUNET_assert(NULL != fileRNO); 103 GNUNET_assert (NULL != fileRNO);
97 GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_read_string(fileRNO, "Read string error", &readResultString, 200)); 104 GNUNET_assert (GNUNET_SYSERR ==
98 GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_read_int64(fileRNO, &testNum)); 105 GNUNET_BIO_read_string (fileRNO, "Read string error",
99 GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_read_meta_data(fileRNO,"Read meta error", &metaDataNO)); 106 &readResultString, 200));
100 fileR = GNUNET_BIO_read_open(fileName); 107 GNUNET_assert (GNUNET_SYSERR == GNUNET_BIO_read_int64 (fileRNO, &testNum));
101 GNUNET_assert(NULL != fileR); 108 GNUNET_assert (GNUNET_SYSERR ==
102 GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_string(fileR, "Read string error", &readResultString, 200)); 109 GNUNET_BIO_read_meta_data (fileRNO, "Read meta error",
103 GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_meta_data(fileR, "Read meta error", &metaDataR)); 110 &metaDataNO));
104 GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_meta_data_test_equal(metaDataR,metaDataW)); 111 fileR = GNUNET_BIO_read_open (fileName);
105 GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_int64(fileR, &testNum)); 112 GNUNET_assert (NULL != fileR);
106 fileR2 = GNUNET_BIO_read_open(fileName2); 113 GNUNET_assert (GNUNET_OK ==
107 GNUNET_assert(NULL != fileR2); 114 GNUNET_BIO_read_string (fileR, "Read string error",
108 GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_read_string(fileR2, "Read string error", &readResultString, 200)); 115 &readResultString, 200));
109 fileR3 = GNUNET_BIO_read_open(fileName3); 116 GNUNET_assert (GNUNET_OK ==
110 GNUNET_assert(NULL != fileR3); 117 GNUNET_BIO_read_meta_data (fileR, "Read meta error",
111 GNUNET_assert(GNUNET_SYSERR == GNUNET_BIO_read_meta_data(fileR3, "Read meta error", &metaDataR)); 118 &metaDataR));
112 fileR4 = GNUNET_BIO_read_open(fileName4); 119 GNUNET_assert (GNUNET_YES ==
113 GNUNET_assert(NULL != fileR4); 120 GNUNET_CONTAINER_meta_data_test_equal (metaDataR,
114 GNUNET_assert(GNUNET_OK == GNUNET_BIO_read_string(fileR4, "Read string error", &readResultString, 200)); 121 metaDataW));
115 GNUNET_BIO_read_close(fileR,&msg); 122 GNUNET_assert (GNUNET_OK == GNUNET_BIO_read_int64 (fileR, &testNum));
116 GNUNET_BIO_read_close(fileR2,&msg); 123 fileR2 = GNUNET_BIO_read_open (fileName2);
117 GNUNET_BIO_read_close(fileR3,&msg); 124 GNUNET_assert (NULL != fileR2);
118 GNUNET_BIO_read_close(fileR4,&msg); 125 GNUNET_assert (GNUNET_SYSERR ==
119 GNUNET_CONTAINER_meta_data_destroy(metaDataW); 126 GNUNET_BIO_read_string (fileR2, "Read string error",
120 GNUNET_CONTAINER_meta_data_destroy(metaDataNO); 127 &readResultString, 200));
121 GNUNET_CONTAINER_meta_data_destroy(metaDataR); 128 fileR3 = GNUNET_BIO_read_open (fileName3);
122 GNUNET_CONTAINER_meta_data_destroy(metaData); 129 GNUNET_assert (NULL != fileR3);
123 GNUNET_free(fileName); 130 GNUNET_assert (GNUNET_SYSERR ==
124 GNUNET_free(fileName2); 131 GNUNET_BIO_read_meta_data (fileR3, "Read meta error",
125 GNUNET_free(fileName3); 132 &metaDataR));
126 GNUNET_free(fileName4); 133 fileR4 = GNUNET_BIO_read_open (fileName4);
134 GNUNET_assert (NULL != fileR4);
135 GNUNET_assert (GNUNET_OK ==
136 GNUNET_BIO_read_string (fileR4, "Read string error",
137 &readResultString, 200));
138 GNUNET_BIO_read_close (fileR, &msg);
139 GNUNET_BIO_read_close (fileR2, &msg);
140 GNUNET_BIO_read_close (fileR3, &msg);
141 GNUNET_BIO_read_close (fileR4, &msg);
142 GNUNET_CONTAINER_meta_data_destroy (metaDataW);
143 GNUNET_CONTAINER_meta_data_destroy (metaDataNO);
144 GNUNET_CONTAINER_meta_data_destroy (metaDataR);
145 GNUNET_CONTAINER_meta_data_destroy (metaData);
146 GNUNET_free (fileName);
147 GNUNET_free (fileName2);
148 GNUNET_free (fileName3);
149 GNUNET_free (fileName4);
127 150
128 151
129 return 0; 152 return 0;
130 153
131} /* end of main */ 154} /* end of main */
diff --git a/src/util/test_client.c b/src/util/test_client.c
index 04efd951b..04f002c43 100644
--- a/src/util/test_client.c
+++ b/src/util/test_client.c
@@ -61,8 +61,7 @@ copy_msg (void *cls, size_t size, void *buf)
61 GNUNET_SERVER_receive_done (ctx->client, GNUNET_OK); 61 GNUNET_SERVER_receive_done (ctx->client, GNUNET_OK);
62 GNUNET_free (cpy); 62 GNUNET_free (cpy);
63 GNUNET_free (ctx); 63 GNUNET_free (ctx);
64 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 64 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Message bounced back to client\n");
65 "Message bounced back to client\n");
66 return sizeof (struct GNUNET_MessageHeader); 65 return sizeof (struct GNUNET_MessageHeader);
67} 66}
68 67
@@ -79,7 +78,7 @@ echo_cb (void *cls,
79 struct GNUNET_MessageHeader *cpy; 78 struct GNUNET_MessageHeader *cpy;
80 79
81 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
82 "Receiving message from client, bouncing back\n"); 81 "Receiving message from client, bouncing back\n");
83 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == 82 GNUNET_assert (sizeof (struct GNUNET_MessageHeader) ==
84 ntohs (message->size)); 83 ntohs (message->size));
85 cc = GNUNET_malloc (sizeof (struct CopyContext)); 84 cc = GNUNET_malloc (sizeof (struct CopyContext));
@@ -109,10 +108,11 @@ recv_bounce (void *cls, const struct GNUNET_MessageHeader *got)
109 108
110 GNUNET_assert (got != NULL); /* timeout */ 109 GNUNET_assert (got != NULL); /* timeout */
111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
112 "Receiving bounce, checking content\n"); 111 "Receiving bounce, checking content\n");
113 msg.type = htons (MY_TYPE); 112 msg.type = htons (MY_TYPE);
114 msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 113 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
115 GNUNET_assert (0 == memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader))); 114 GNUNET_assert (0 ==
115 memcmp (got, &msg, sizeof (struct GNUNET_MessageHeader)));
116 GNUNET_CLIENT_disconnect (client); 116 GNUNET_CLIENT_disconnect (client);
117 client = NULL; 117 client = NULL;
118 GNUNET_SERVER_destroy (server); 118 GNUNET_SERVER_destroy (server);
@@ -128,8 +128,7 @@ make_msg (void *cls, size_t size, void *buf)
128 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); 128 GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader));
129 msg->type = htons (MY_TYPE); 129 msg->type = htons (MY_TYPE);
130 msg->size = htons (sizeof (struct GNUNET_MessageHeader)); 130 msg->size = htons (sizeof (struct GNUNET_MessageHeader));
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Creating message for transmission\n");
132 "Creating message for transmission\n");
133 return sizeof (struct GNUNET_MessageHeader); 132 return sizeof (struct GNUNET_MessageHeader);
134} 133}
135 134
@@ -163,9 +162,9 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
163 GNUNET_assert (NULL != 162 GNUNET_assert (NULL !=
164 GNUNET_CLIENT_notify_transmit_ready (client, 163 GNUNET_CLIENT_notify_transmit_ready (client,
165 sizeof (struct 164 sizeof (struct
166 GNUNET_MessageHeader), 165 GNUNET_MessageHeader),
167 GNUNET_TIME_UNIT_SECONDS, 166 GNUNET_TIME_UNIT_SECONDS,
168 GNUNET_NO, 167 GNUNET_NO,
169 &make_msg, NULL)); 168 &make_msg, NULL));
170 GNUNET_CLIENT_receive (client, &recv_bounce, cls, 169 GNUNET_CLIENT_receive (client, &recv_bounce, cls,
171 GNUNET_TIME_relative_multiply 170 GNUNET_TIME_relative_multiply
@@ -199,13 +198,13 @@ main (int argc, char *argv[])
199{ 198{
200 int ret = 0; 199 int ret = 0;
201 200
202 GNUNET_log_setup ("test_client", 201 GNUNET_log_setup ("test_client",
203#if VERBOSE 202#if VERBOSE
204 "DEBUG", 203 "DEBUG",
205#else 204#else
206 "WARNING", 205 "WARNING",
207#endif 206#endif
208 NULL); 207 NULL);
209 ret += check (); 208 ret += check ();
210 209
211 return ret; 210 return ret;
diff --git a/src/util/test_configuration.c b/src/util/test_configuration.c
index 6a2fda699..4c7f69a14 100644
--- a/src/util/test_configuration.c
+++ b/src/util/test_configuration.c
@@ -70,7 +70,7 @@ testConfig ()
70#ifndef MINGW 70#ifndef MINGW
71 if (0 != strcmp (c, "/hello/world")) 71 if (0 != strcmp (c, "/hello/world"))
72#else 72#else
73 #define HI "\\hello\\world" 73#define HI "\\hello\\world"
74 if (strstr (c, HI) != c + strlen (c) - strlen (HI)) 74 if (strstr (c, HI) != c + strlen (c) - strlen (HI))
75#endif 75#endif
76 { 76 {
diff --git a/src/util/test_connection.c b/src/util/test_connection.c
index e144f66c1..0f4c46b3b 100644
--- a/src/util/test_connection.c
+++ b/src/util/test_connection.c
@@ -64,12 +64,13 @@ open_listen_socket ()
64 sa.sin_family = AF_INET; 64 sa.sin_family = AF_INET;
65 desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); 65 desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0);
66 GNUNET_assert (desc != NULL); 66 GNUNET_assert (desc != NULL);
67 if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) 67 if (GNUNET_NETWORK_socket_setsockopt
68 (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
68 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
69 "setsockopt"); 70 "setsockopt");
70 GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, 71 GNUNET_assert (GNUNET_NETWORK_socket_bind
71 (const struct sockaddr*) &sa, 72 (desc, (const struct sockaddr *) &sa,
72 sizeof (sa)) == GNUNET_OK); 73 sizeof (sa)) == GNUNET_OK);
73 GNUNET_NETWORK_socket_listen (desc, 5); 74 GNUNET_NETWORK_socket_listen (desc, 5);
74 return desc; 75 return desc;
75} 76}
@@ -94,10 +95,10 @@ receive_check (void *cls,
94 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n"); 95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n");
95#endif 96#endif
96 GNUNET_CONNECTION_receive (asock, 97 GNUNET_CONNECTION_receive (asock,
97 1024, 98 1024,
98 GNUNET_TIME_relative_multiply 99 GNUNET_TIME_relative_multiply
99 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, 100 (GNUNET_TIME_UNIT_SECONDS, 5),
100 cls); 101 &receive_check, cls);
101 } 102 }
102 else 103 else
103 { 104 {
@@ -118,7 +119,7 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test accepts connection\n"); 119 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test accepts connection\n");
119#endif 120#endif
120 asock = GNUNET_CONNECTION_create_from_accept (tc->sched, 121 asock = GNUNET_CONNECTION_create_from_accept (tc->sched,
121 NULL, NULL, ls, 1024); 122 NULL, NULL, ls, 1024);
122 GNUNET_assert (asock != NULL); 123 GNUNET_assert (asock != NULL);
123 GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); 124 GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock));
124#if VERBOSE 125#if VERBOSE
@@ -130,9 +131,10 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
130 "Test asks to receive on accepted socket\n"); 131 "Test asks to receive on accepted socket\n");
131#endif 132#endif
132 GNUNET_CONNECTION_receive (asock, 133 GNUNET_CONNECTION_receive (asock,
133 1024, 134 1024,
134 GNUNET_TIME_relative_multiply 135 GNUNET_TIME_relative_multiply
135 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, cls); 136 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
137 cls);
136} 138}
137 139
138static size_t 140static size_t
@@ -158,27 +160,26 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
158 lsock = GNUNET_CONNECTION_create_from_existing (tc->sched, ls, 0); 160 lsock = GNUNET_CONNECTION_create_from_existing (tc->sched, ls, 0);
159 GNUNET_assert (lsock != NULL); 161 GNUNET_assert (lsock != NULL);
160 csock = GNUNET_CONNECTION_create_from_connect (tc->sched, 162 csock = GNUNET_CONNECTION_create_from_connect (tc->sched,
161 cfg, 163 cfg,
162 "localhost", PORT, 1024); 164 "localhost", PORT, 1024);
163 GNUNET_assert (csock != NULL); 165 GNUNET_assert (csock != NULL);
164#if VERBOSE 166#if VERBOSE
165 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test asks for write notification\n"); 167 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test asks for write notification\n");
166#endif 168#endif
167 GNUNET_assert (NULL != 169 GNUNET_assert (NULL !=
168 GNUNET_CONNECTION_notify_transmit_ready (csock, 170 GNUNET_CONNECTION_notify_transmit_ready (csock,
169 12, 171 12,
170 GNUNET_TIME_UNIT_SECONDS, 172 GNUNET_TIME_UNIT_SECONDS,
171 &make_hello, 173 &make_hello, NULL));
172 NULL));
173#if VERBOSE 174#if VERBOSE
174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n"); 175 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n");
175#endif 176#endif
176 GNUNET_SCHEDULER_add_read_net (tc->sched, 177 GNUNET_SCHEDULER_add_read_net (tc->sched,
177 GNUNET_NO, 178 GNUNET_NO,
178 GNUNET_SCHEDULER_PRIORITY_HIGH, 179 GNUNET_SCHEDULER_PRIORITY_HIGH,
179 GNUNET_SCHEDULER_NO_TASK, 180 GNUNET_SCHEDULER_NO_TASK,
180 GNUNET_TIME_UNIT_FOREVER_REL, 181 GNUNET_TIME_UNIT_FOREVER_REL,
181 ls, &run_accept, cls); 182 ls, &run_accept, cls);
182} 183}
183 184
184 185
diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c
index f37352c67..1b85dfac6 100644
--- a/src/util/test_connection_addressing.c
+++ b/src/util/test_connection_addressing.c
@@ -63,12 +63,13 @@ open_listen_socket ()
63 sa.sin_port = htons (PORT); 63 sa.sin_port = htons (PORT);
64 desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); 64 desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0);
65 GNUNET_assert (desc != 0); 65 GNUNET_assert (desc != 0);
66 if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) 66 if (GNUNET_NETWORK_socket_setsockopt
67 (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
67 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 68 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
68 "setsockopt"); 69 "setsockopt");
69 GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, 70 GNUNET_assert (GNUNET_NETWORK_socket_bind
70 (const struct sockaddr*) &sa, 71 (desc, (const struct sockaddr *) &sa,
71 sizeof (sa)) == GNUNET_OK); 72 sizeof (sa)) == GNUNET_OK);
72 GNUNET_NETWORK_socket_listen (desc, 5); 73 GNUNET_NETWORK_socket_listen (desc, 5);
73 return desc; 74 return desc;
74} 75}
@@ -88,10 +89,10 @@ receive_check (void *cls,
88 if (sofar < 12) 89 if (sofar < 12)
89 { 90 {
90 GNUNET_CONNECTION_receive (asock, 91 GNUNET_CONNECTION_receive (asock,
91 1024, 92 1024,
92 GNUNET_TIME_relative_multiply 93 GNUNET_TIME_relative_multiply
93 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, 94 (GNUNET_TIME_UNIT_SECONDS, 5),
94 cls); 95 &receive_check, cls);
95 } 96 }
96 else 97 else
97 { 98 {
@@ -110,7 +111,7 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
110 struct sockaddr_in expect; 111 struct sockaddr_in expect;
111 112
112 asock = GNUNET_CONNECTION_create_from_accept (tc->sched, 113 asock = GNUNET_CONNECTION_create_from_accept (tc->sched,
113 NULL, NULL, ls, 1024); 114 NULL, NULL, ls, 1024);
114 GNUNET_assert (asock != NULL); 115 GNUNET_assert (asock != NULL);
115 GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); 116 GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock));
116 GNUNET_assert (GNUNET_OK == 117 GNUNET_assert (GNUNET_OK ==
@@ -128,9 +129,10 @@ run_accept (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
128 GNUNET_free (addr); 129 GNUNET_free (addr);
129 GNUNET_CONNECTION_destroy (lsock); 130 GNUNET_CONNECTION_destroy (lsock);
130 GNUNET_CONNECTION_receive (asock, 131 GNUNET_CONNECTION_receive (asock,
131 1024, 132 1024,
132 GNUNET_TIME_relative_multiply 133 GNUNET_TIME_relative_multiply
133 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, cls); 134 (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check,
135 cls);
134} 136}
135 137
136static size_t 138static size_t
@@ -156,23 +158,22 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
156 v4.sin_port = htons (PORT); 158 v4.sin_port = htons (PORT);
157 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); 159 v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
158 csock = GNUNET_CONNECTION_create_from_sockaddr (tc->sched, 160 csock = GNUNET_CONNECTION_create_from_sockaddr (tc->sched,
159 AF_INET, 161 AF_INET,
160 (const struct sockaddr 162 (const struct sockaddr
161 *) &v4, sizeof (v4), 163 *) &v4, sizeof (v4), 1024);
162 1024);
163 GNUNET_assert (csock != NULL); 164 GNUNET_assert (csock != NULL);
164 GNUNET_assert (NULL != 165 GNUNET_assert (NULL !=
165 GNUNET_CONNECTION_notify_transmit_ready (csock, 166 GNUNET_CONNECTION_notify_transmit_ready (csock,
166 12, 167 12,
167 GNUNET_TIME_UNIT_SECONDS, 168 GNUNET_TIME_UNIT_SECONDS,
168 &make_hello, NULL)); 169 &make_hello, NULL));
169 GNUNET_CONNECTION_destroy (csock); 170 GNUNET_CONNECTION_destroy (csock);
170 GNUNET_SCHEDULER_add_read_net (tc->sched, 171 GNUNET_SCHEDULER_add_read_net (tc->sched,
171 GNUNET_NO, 172 GNUNET_NO,
172 GNUNET_SCHEDULER_PRIORITY_HIGH, 173 GNUNET_SCHEDULER_PRIORITY_HIGH,
173 GNUNET_SCHEDULER_NO_TASK, 174 GNUNET_SCHEDULER_NO_TASK,
174 GNUNET_TIME_UNIT_FOREVER_REL, 175 GNUNET_TIME_UNIT_FOREVER_REL,
175 ls, &run_accept, cls); 176 ls, &run_accept, cls);
176} 177}
177 178
178 179
@@ -197,13 +198,13 @@ main (int argc, char *argv[])
197{ 198{
198 int ret = 0; 199 int ret = 0;
199 200
200 GNUNET_log_setup ("test_connection_addressing", 201 GNUNET_log_setup ("test_connection_addressing",
201#if VERBOSE 202#if VERBOSE
202 "DEBUG", 203 "DEBUG",
203#else 204#else
204 "WARNING", 205 "WARNING",
205#endif 206#endif
206 NULL); 207 NULL);
207 ret += check (); 208 ret += check ();
208 return ret; 209 return ret;
209} 210}
diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c
index e985bf935..5856e27ed 100644
--- a/src/util/test_connection_receive_cancel.c
+++ b/src/util/test_connection_receive_cancel.c
@@ -62,12 +62,13 @@ open_listen_socket ()
62 sa.sin_port = htons (PORT); 62 sa.sin_port = htons (PORT);
63 desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); 63 desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0);
64 GNUNET_assert (desc != NULL); 64 GNUNET_assert (desc != NULL);
65 if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) 65 if (GNUNET_NETWORK_socket_setsockopt
66 (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
66 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 67 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
67 "setsockopt"); 68 "setsockopt");
68 GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, 69 GNUNET_assert (GNUNET_NETWORK_socket_bind
69 (const struct sockaddr*) &sa, 70 (desc, (const struct sockaddr *) &sa,
70 sizeof (sa)) == GNUNET_OK); 71 sizeof (sa)) == GNUNET_OK);
71 GNUNET_NETWORK_socket_listen (desc, 5); 72 GNUNET_NETWORK_socket_listen (desc, 5);
72 return desc; 73 return desc;
73} 74}
@@ -89,15 +90,15 @@ run_accept_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
89{ 90{
90 91
91 asock = GNUNET_CONNECTION_create_from_accept (tc->sched, 92 asock = GNUNET_CONNECTION_create_from_accept (tc->sched,
92 NULL, NULL, ls, 1024); 93 NULL, NULL, ls, 1024);
93 GNUNET_assert (asock != NULL); 94 GNUNET_assert (asock != NULL);
94 GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); 95 GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock));
95 GNUNET_CONNECTION_destroy (lsock); 96 GNUNET_CONNECTION_destroy (lsock);
96 GNUNET_CONNECTION_receive (asock, 97 GNUNET_CONNECTION_receive (asock,
97 1024, 98 1024,
98 GNUNET_TIME_relative_multiply 99 GNUNET_TIME_relative_multiply
99 (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive, 100 (GNUNET_TIME_UNIT_SECONDS, 5), &dead_receive,
100 cls); 101 cls);
101} 102}
102 103
103 104
@@ -120,14 +121,14 @@ task_receive_cancel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
120 lsock = GNUNET_CONNECTION_create_from_existing (tc->sched, ls, 0); 121 lsock = GNUNET_CONNECTION_create_from_existing (tc->sched, ls, 0);
121 GNUNET_assert (lsock != NULL); 122 GNUNET_assert (lsock != NULL);
122 csock = GNUNET_CONNECTION_create_from_connect (tc->sched, cfg, 123 csock = GNUNET_CONNECTION_create_from_connect (tc->sched, cfg,
123 "localhost", PORT, 1024); 124 "localhost", PORT, 1024);
124 GNUNET_assert (csock != NULL); 125 GNUNET_assert (csock != NULL);
125 GNUNET_SCHEDULER_add_read_net (tc->sched, 126 GNUNET_SCHEDULER_add_read_net (tc->sched,
126 GNUNET_NO, 127 GNUNET_NO,
127 GNUNET_SCHEDULER_PRIORITY_HIGH, 128 GNUNET_SCHEDULER_PRIORITY_HIGH,
128 GNUNET_SCHEDULER_NO_TASK, 129 GNUNET_SCHEDULER_NO_TASK,
129 GNUNET_TIME_UNIT_FOREVER_REL, 130 GNUNET_TIME_UNIT_FOREVER_REL,
130 ls, &run_accept_cancel, cls); 131 ls, &run_accept_cancel, cls);
131 GNUNET_SCHEDULER_add_delayed (tc->sched, 132 GNUNET_SCHEDULER_add_delayed (tc->sched,
132 GNUNET_NO, 133 GNUNET_NO,
133 GNUNET_SCHEDULER_PRIORITY_KEEP, 134 GNUNET_SCHEDULER_PRIORITY_KEEP,
diff --git a/src/util/test_connection_timeout.c b/src/util/test_connection_timeout.c
index 5968f797f..0590d36d5 100644
--- a/src/util/test_connection_timeout.c
+++ b/src/util/test_connection_timeout.c
@@ -59,12 +59,13 @@ open_listen_socket ()
59 sa.sin_port = htons (PORT); 59 sa.sin_port = htons (PORT);
60 desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); 60 desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0);
61 GNUNET_assert (desc != NULL); 61 GNUNET_assert (desc != NULL);
62 if (GNUNET_NETWORK_socket_setsockopt (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) 62 if (GNUNET_NETWORK_socket_setsockopt
63 (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
63 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 64 GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
64 "setsockopt"); 65 "setsockopt");
65 GNUNET_assert (GNUNET_NETWORK_socket_bind (desc, 66 GNUNET_assert (GNUNET_NETWORK_socket_bind
66 (const struct sockaddr*) &sa, 67 (desc, (const struct sockaddr *) &sa,
67 sizeof (sa)) == GNUNET_OK); 68 sizeof (sa)) == GNUNET_OK);
68 GNUNET_NETWORK_socket_listen (desc, 5); 69 GNUNET_NETWORK_socket_listen (desc, 5);
69 return desc; 70 return desc;
70} 71}
@@ -93,9 +94,9 @@ send_kilo (void *cls, size_t size, void *buf)
93 94
94 GNUNET_assert (NULL != 95 GNUNET_assert (NULL !=
95 GNUNET_CONNECTION_notify_transmit_ready (csock, 96 GNUNET_CONNECTION_notify_transmit_ready (csock,
96 1024, 97 1024,
97 GNUNET_TIME_UNIT_SECONDS, 98 GNUNET_TIME_UNIT_SECONDS,
98 &send_kilo, cls)); 99 &send_kilo, cls));
99 return 1024; 100 return 1024;
100} 101}
101 102
@@ -108,13 +109,13 @@ task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
108 lsock = GNUNET_CONNECTION_create_from_existing (tc->sched, ls, 0); 109 lsock = GNUNET_CONNECTION_create_from_existing (tc->sched, ls, 0);
109 GNUNET_assert (lsock != NULL); 110 GNUNET_assert (lsock != NULL);
110 csock = GNUNET_CONNECTION_create_from_connect (tc->sched, cfg, 111 csock = GNUNET_CONNECTION_create_from_connect (tc->sched, cfg,
111 "localhost", PORT, 1024); 112 "localhost", PORT, 1024);
112 GNUNET_assert (csock != NULL); 113 GNUNET_assert (csock != NULL);
113 GNUNET_assert (NULL != 114 GNUNET_assert (NULL !=
114 GNUNET_CONNECTION_notify_transmit_ready (csock, 115 GNUNET_CONNECTION_notify_transmit_ready (csock,
115 1024, 116 1024,
116 GNUNET_TIME_UNIT_SECONDS, 117 GNUNET_TIME_UNIT_SECONDS,
117 &send_kilo, cls)); 118 &send_kilo, cls));
118} 119}
119 120
120 121
diff --git a/src/util/test_connection_timeout_no_connect.c b/src/util/test_connection_timeout_no_connect.c
index 84d50b4fb..6d226999f 100644
--- a/src/util/test_connection_timeout_no_connect.c
+++ b/src/util/test_connection_timeout_no_connect.c
@@ -54,13 +54,14 @@ static void
54task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 54task_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
55{ 55{
56 csock = GNUNET_CONNECTION_create_from_connect (tc->sched, cfg, 56 csock = GNUNET_CONNECTION_create_from_connect (tc->sched, cfg,
57 "localhost", PORT, 1024); 57 "localhost", PORT, 1024);
58 GNUNET_assert (csock != NULL); 58 GNUNET_assert (csock != NULL);
59 GNUNET_assert (NULL != 59 GNUNET_assert (NULL !=
60 GNUNET_CONNECTION_notify_transmit_ready (csock, 60 GNUNET_CONNECTION_notify_transmit_ready (csock,
61 1024, 61 1024,
62 GNUNET_TIME_UNIT_SECONDS, 62 GNUNET_TIME_UNIT_SECONDS,
63 &handle_timeout, cls)); 63 &handle_timeout,
64 cls));
64} 65}
65 66
66 67
diff --git a/src/util/test_connection_transmit_cancel.c b/src/util/test_connection_transmit_cancel.c
index 5ec19bdb1..afdca68b5 100644
--- a/src/util/test_connection_transmit_cancel.c
+++ b/src/util/test_connection_transmit_cancel.c
@@ -51,12 +51,12 @@ task_transmit_cancel (void *cls,
51 struct GNUNET_CONNECTION_Handle *csock; 51 struct GNUNET_CONNECTION_Handle *csock;
52 52
53 csock = GNUNET_CONNECTION_create_from_connect (tc->sched, cfg, 53 csock = GNUNET_CONNECTION_create_from_connect (tc->sched, cfg,
54 "localhost", PORT, 1024); 54 "localhost", PORT, 1024);
55 GNUNET_assert (csock != NULL); 55 GNUNET_assert (csock != NULL);
56 th = GNUNET_CONNECTION_notify_transmit_ready (csock, 56 th = GNUNET_CONNECTION_notify_transmit_ready (csock,
57 12, 57 12,
58 GNUNET_TIME_UNIT_MINUTES, 58 GNUNET_TIME_UNIT_MINUTES,
59 &not_run, cls); 59 &not_run, cls);
60 GNUNET_CONNECTION_notify_transmit_ready_cancel (th); 60 GNUNET_CONNECTION_notify_transmit_ready_cancel (th);
61 GNUNET_CONNECTION_destroy (csock); 61 GNUNET_CONNECTION_destroy (csock);
62 *ok = 0; 62 *ok = 0;
diff --git a/src/util/test_container_bloomfilter.c b/src/util/test_container_bloomfilter.c
index 2e7fb2e28..f54028f54 100644
--- a/src/util/test_container_bloomfilter.c
+++ b/src/util/test_container_bloomfilter.c
@@ -42,8 +42,7 @@ nextHC (GNUNET_HashCode * hc)
42} 42}
43 43
44static int 44static int
45add_iterator (void *cls, 45add_iterator (void *cls, GNUNET_HashCode * next)
46 GNUNET_HashCode * next)
47{ 46{
48 int *ret = cls; 47 int *ret = cls;
49 GNUNET_HashCode pos; 48 GNUNET_HashCode pos;
diff --git a/src/util/test_container_slist.c b/src/util/test_container_slist.c
index 7d31eff2e..bc134d26a 100644
--- a/src/util/test_container_slist.c
+++ b/src/util/test_container_slist.c
@@ -39,7 +39,7 @@ main (int argc, char *argv[])
39 unsigned int i; 39 unsigned int i;
40 unsigned int j; 40 unsigned int j;
41 size_t s; 41 size_t s;
42 const void *p; 42 const void *p;
43 43
44 GNUNET_log_setup ("test-container-slist", "WARNING", NULL); 44 GNUNET_log_setup ("test-container-slist", "WARNING", NULL);
45 45
@@ -48,7 +48,9 @@ main (int argc, char *argv[])
48 CHECK (GNUNET_CONTAINER_slist_count (l) == 0); 48 CHECK (GNUNET_CONTAINER_slist_count (l) == 0);
49 49
50 for (i = 0; i < 100; i++) 50 for (i = 0; i < 100; i++)
51 GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &i, sizeof (i)); 51 GNUNET_CONTAINER_slist_add (l,
52 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
53 &i, sizeof (i));
52 CHECK (GNUNET_CONTAINER_slist_count (l) == 100); 54 CHECK (GNUNET_CONTAINER_slist_count (l) == 100);
53 55
54 for (it = GNUNET_CONTAINER_slist_begin (l), i = 99; 56 for (it = GNUNET_CONTAINER_slist_begin (l), i = 99;
@@ -62,8 +64,9 @@ main (int argc, char *argv[])
62 CHECK (s == sizeof (i)); 64 CHECK (s == sizeof (i));
63 65
64 j *= 2; 66 j *= 2;
65 GNUNET_CONTAINER_slist_insert (it, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &j, 67 GNUNET_CONTAINER_slist_insert (it,
66 sizeof (j)); 68 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
69 &j, sizeof (j));
67 } 70 }
68 GNUNET_free (it); 71 GNUNET_free (it);
69 CHECK (GNUNET_CONTAINER_slist_count (l) == 200); 72 CHECK (GNUNET_CONTAINER_slist_count (l) == 200);
@@ -101,7 +104,9 @@ main (int argc, char *argv[])
101 CHECK (GNUNET_CONTAINER_slist_count (l) == 0); 104 CHECK (GNUNET_CONTAINER_slist_count (l) == 0);
102 105
103 for (i = 0; i < 100; i++) 106 for (i = 0; i < 100; i++)
104 GNUNET_CONTAINER_slist_add (l, GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, &i, sizeof (i)); 107 GNUNET_CONTAINER_slist_add (l,
108 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT,
109 &i, sizeof (i));
105 110
106 GNUNET_CONTAINER_slist_destroy (l); 111 GNUNET_CONTAINER_slist_destroy (l);
107 112
diff --git a/src/util/test_crypto_aes.c b/src/util/test_crypto_aes.c
index f876e4175..fb0d05683 100644
--- a/src/util/test_crypto_aes.c
+++ b/src/util/test_crypto_aes.c
@@ -52,7 +52,7 @@ testSymcipher ()
52 } 52 }
53 size = GNUNET_CRYPTO_aes_decrypt (result, size, 53 size = GNUNET_CRYPTO_aes_decrypt (result, size,
54 &key, 54 &key,
55 (const struct 55 (const struct
56 GNUNET_CRYPTO_AesInitializationVector *) 56 GNUNET_CRYPTO_AesInitializationVector *)
57 INITVALUE, res); 57 INITVALUE, res);
58 if (strlen (TESTSTRING) + 1 != size) 58 if (strlen (TESTSTRING) + 1 != size)
@@ -134,7 +134,7 @@ verifyCrypto ()
134 GNUNET_CRYPTO_aes_decrypt (result, 134 GNUNET_CRYPTO_aes_decrypt (result,
135 GNUNET_CRYPTO_AES_KEY_LENGTH, 135 GNUNET_CRYPTO_AES_KEY_LENGTH,
136 &key, 136 &key,
137 (const struct 137 (const struct
138 GNUNET_CRYPTO_AesInitializationVector *) 138 GNUNET_CRYPTO_AesInitializationVector *)
139 "testtesttesttest", res)) 139 "testtesttesttest", res))
140 { 140 {
diff --git a/src/util/test_crypto_ksk.c b/src/util/test_crypto_ksk.c
index 943e9792b..ad63cb6de 100644
--- a/src/util/test_crypto_ksk.c
+++ b/src/util/test_crypto_ksk.c
@@ -169,8 +169,8 @@ testSignVerify (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey)
169 continue; 169 continue;
170 } 170 }
171 if (GNUNET_SYSERR != 171 if (GNUNET_SYSERR !=
172 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING, 172 GNUNET_CRYPTO_rsa_verify
173 &purp, &sig, &pkey)) 173 (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING, &purp, &sig, &pkey))
174 { 174 {
175 printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n"); 175 printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
176 ok = GNUNET_SYSERR; 176 ok = GNUNET_SYSERR;
diff --git a/src/util/test_crypto_rsa.c b/src/util/test_crypto_rsa.c
index 6b17b4f49..b3663662e 100644
--- a/src/util/test_crypto_rsa.c
+++ b/src/util/test_crypto_rsa.c
@@ -76,9 +76,7 @@ testEncryptDecrypt ()
76 if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0) 76 if (strncmp (TESTSTRING, result, strlen (TESTSTRING)) != 0)
77 { 77 {
78 printf ("%s != %.*s - testEncryptDecrypt failed!\n", 78 printf ("%s != %.*s - testEncryptDecrypt failed!\n",
79 TESTSTRING, 79 TESTSTRING, (int) MAX_TESTVAL, result);
80 (int) MAX_TESTVAL,
81 result);
82 ok++; 80 ok++;
83 continue; 81 continue;
84 } 82 }
@@ -229,8 +227,8 @@ testSignVerify ()
229 continue; 227 continue;
230 } 228 }
231 if (GNUNET_SYSERR != 229 if (GNUNET_SYSERR !=
232 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING, 230 GNUNET_CRYPTO_rsa_verify
233 &purp, &sig, &pkey)) 231 (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_TCP_PING, &purp, &sig, &pkey))
234 { 232 {
235 printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n"); 233 printf ("GNUNET_CRYPTO_rsa_verify failed to fail!\n");
236 ok = GNUNET_SYSERR; 234 ok = GNUNET_SYSERR;
@@ -275,7 +273,8 @@ testSignPerformance ()
275 } 273 }
276 } 274 }
277 printf ("%d RSA sign operations %llu ms\n", ITER, 275 printf ("%d RSA sign operations %llu ms\n", ITER,
278 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).value); 276 (unsigned long long) GNUNET_TIME_absolute_get_duration (start).
277 value);
279 GNUNET_CRYPTO_rsa_key_free (hostkey); 278 GNUNET_CRYPTO_rsa_key_free (hostkey);
280 return ok; 279 return ok;
281} 280}
diff --git a/src/util/test_disk.c b/src/util/test_disk.c
index 8b485edc5..c84ec812a 100644
--- a/src/util/test_disk.c
+++ b/src/util/test_disk.c
@@ -36,10 +36,11 @@ testReadWrite ()
36 char tmp[100 + 1]; 36 char tmp[100 + 1];
37 int ret; 37 int ret;
38 38
39 if (strlen(TESTSTRING) != 39 if (strlen (TESTSTRING) !=
40 GNUNET_DISK_fn_write (".testfile", TESTSTRING, 40 GNUNET_DISK_fn_write (".testfile", TESTSTRING,
41 strlen (TESTSTRING), 41 strlen (TESTSTRING),
42 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE)) 42 GNUNET_DISK_PERM_USER_READ |
43 GNUNET_DISK_PERM_USER_WRITE))
43 return 1; 44 return 1;
44 if (GNUNET_OK != GNUNET_DISK_file_test (".testfile")) 45 if (GNUNET_OK != GNUNET_DISK_file_test (".testfile"))
45 return 1; 46 return 1;
@@ -92,8 +93,9 @@ testOpenClose ()
92 long avail; 93 long avail;
93 94
94 fh = GNUNET_DISK_file_open (".testfile", GNUNET_DISK_OPEN_READWRITE 95 fh = GNUNET_DISK_file_open (".testfile", GNUNET_DISK_OPEN_READWRITE
95 | GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_PERM_USER_READ 96 | GNUNET_DISK_OPEN_CREATE,
96 | GNUNET_DISK_PERM_USER_WRITE); 97 GNUNET_DISK_PERM_USER_READ |
98 GNUNET_DISK_PERM_USER_WRITE);
97 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); 99 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh));
98 GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5)); 100 GNUNET_break (5 == GNUNET_DISK_file_write (fh, "Hello", 5));
99 GNUNET_DISK_file_close (fh); 101 GNUNET_DISK_file_close (fh);
@@ -108,8 +110,9 @@ testOpenClose ()
108 avail = GNUNET_DISK_get_blocks_available (".testfile"); 110 avail = GNUNET_DISK_get_blocks_available (".testfile");
109 GNUNET_log_skip (0, GNUNET_NO); 111 GNUNET_log_skip (0, GNUNET_NO);
110 fh = GNUNET_DISK_file_open (".testfile", GNUNET_DISK_OPEN_READWRITE 112 fh = GNUNET_DISK_file_open (".testfile", GNUNET_DISK_OPEN_READWRITE
111 | GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_PERM_USER_WRITE 113 | GNUNET_DISK_OPEN_CREATE,
112 | GNUNET_DISK_PERM_USER_READ); 114 GNUNET_DISK_PERM_USER_WRITE |
115 GNUNET_DISK_PERM_USER_READ);
113 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh)); 116 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh));
114 while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) && 117 while ((avail == GNUNET_DISK_get_blocks_available (".testfile")) &&
115 (avail != -1)) 118 (avail != -1))
@@ -138,11 +141,14 @@ scan_callback (void *want, const char *filename)
138static int 141static int
139testDirScan () 142testDirScan ()
140{ 143{
141 if (GNUNET_OK != GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry")) 144 if (GNUNET_OK !=
145 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry"))
142 return 1; 146 return 1;
143 if (GNUNET_OK != GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more")) 147 if (GNUNET_OK !=
148 GNUNET_DISK_directory_create ("test" DIR_SEPARATOR_STR "entry_more"))
144 return 1; 149 return 1;
145 GNUNET_DISK_directory_scan ("test", &scan_callback, "test" DIR_SEPARATOR_STR "entry"); 150 GNUNET_DISK_directory_scan ("test", &scan_callback,
151 "test" DIR_SEPARATOR_STR "entry");
146 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test")) 152 if (GNUNET_OK != GNUNET_DISK_directory_remove ("test"))
147 return 1; 153 return 1;
148 if (ok < 2) 154 if (ok < 2)
diff --git a/src/util/test_getopt.c b/src/util/test_getopt.c
index e254ac31f..1472fbb91 100644
--- a/src/util/test_getopt.c
+++ b/src/util/test_getopt.c
@@ -87,8 +87,7 @@ testVersion ()
87 GNUNET_GETOPT_OPTION_END 87 GNUNET_GETOPT_OPTION_END
88 }; 88 };
89 89
90 if (-1 != GNUNET_GETOPT_run ("test_getopt", 90 if (-1 != GNUNET_GETOPT_run ("test_getopt", versionoptionlist, 2, myargv))
91 versionoptionlist, 2, myargv))
92 { 91 {
93 GNUNET_break (0); 92 GNUNET_break (0);
94 return 1; 93 return 1;
@@ -109,8 +108,7 @@ testAbout ()
109 GNUNET_GETOPT_OPTION_END 108 GNUNET_GETOPT_OPTION_END
110 }; 109 };
111 110
112 if (-1 != GNUNET_GETOPT_run ("test_getopt", 111 if (-1 != GNUNET_GETOPT_run ("test_getopt", aboutoptionlist, 2, myargv))
113 aboutoptionlist, 2, myargv))
114 { 112 {
115 GNUNET_break (0); 113 GNUNET_break (0);
116 return 1; 114 return 1;
diff --git a/src/util/test_os_load.c b/src/util/test_os_load.c
index 7cc35e56d..e45c4ac36 100644
--- a/src/util/test_os_load.c
+++ b/src/util/test_os_load.c
@@ -131,14 +131,18 @@ testdisk ()
131 } 131 }
132 memset (buf, 42, sizeof (buf)); 132 memset (buf, 42, sizeof (buf));
133 fh = GNUNET_DISK_file_open (".loadfile", GNUNET_DISK_OPEN_WRITE 133 fh = GNUNET_DISK_file_open (".loadfile", GNUNET_DISK_OPEN_WRITE
134 | GNUNET_DISK_OPEN_CREATE, GNUNET_DISK_PERM_USER_READ 134 | GNUNET_DISK_OPEN_CREATE,
135 | GNUNET_DISK_PERM_USER_WRITE); 135 GNUNET_DISK_PERM_USER_READ |
136 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid(fh)); 136 GNUNET_DISK_PERM_USER_WRITE);
137 GNUNET_assert (GNUNET_NO == GNUNET_DISK_handle_invalid (fh));
137 while (GNUNET_TIME_absolute_get_duration (start).value < 60 * 1000) 138 while (GNUNET_TIME_absolute_get_duration (start).value < 60 * 1000)
138 { 139 {
139 GNUNET_DISK_file_seek (fh, GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 140 GNUNET_DISK_file_seek (fh,
140 1024 * 1024 * 1024), GNUNET_DISK_SEEK_SET); 141 GNUNET_CRYPTO_random_u64
141 GNUNET_assert (sizeof (buf) == GNUNET_DISK_file_write (fh, buf, sizeof (buf))); 142 (GNUNET_CRYPTO_QUALITY_WEAK, 1024 * 1024 * 1024),
143 GNUNET_DISK_SEEK_SET);
144 GNUNET_assert (sizeof (buf) ==
145 GNUNET_DISK_file_write (fh, buf, sizeof (buf)));
142 GNUNET_DISK_file_sync (fh); 146 GNUNET_DISK_file_sync (fh);
143 if (ret < GNUNET_OS_load_disk_get (cfg)) 147 if (ret < GNUNET_OS_load_disk_get (cfg))
144 break; 148 break;
diff --git a/src/util/test_resolver_api.c b/src/util/test_resolver_api.c
index 295217c30..15a7f820b 100644
--- a/src/util/test_resolver_api.c
+++ b/src/util/test_resolver_api.c
@@ -44,8 +44,8 @@ check_hostname (void *cls, const struct sockaddr *sa, socklen_t salen)
44 return; 44 return;
45 } 45 }
46 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 46 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
47 _("Got IP address `%s' for our host.\n"), 47 _("Got IP address `%s' for our host.\n"),
48 GNUNET_a2s (sa, salen)); 48 GNUNET_a2s (sa, salen));
49} 49}
50 50
51 51
@@ -126,8 +126,7 @@ static void
126run (void *cls, 126run (void *cls,
127 struct GNUNET_SCHEDULER_Handle *sched, 127 struct GNUNET_SCHEDULER_Handle *sched,
128 char *const *args, 128 char *const *args,
129 const char *cfgfile, 129 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
130 const struct GNUNET_CONFIGURATION_Handle *cfg)
131{ 130{
132 struct sockaddr_in sa; 131 struct sockaddr_in sa;
133 struct GNUNET_TIME_Relative timeout = 132 struct GNUNET_TIME_Relative timeout =
@@ -186,7 +185,7 @@ check ()
186 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 185 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
187 ok = 1; 186 ok = 1;
188 } 187 }
189 GNUNET_OS_process_wait(pid); 188 GNUNET_OS_process_wait (pid);
190 if (ok != 0) 189 if (ok != 0)
191 fprintf (stderr, "Missed some resolutions: %u\n", ok); 190 fprintf (stderr, "Missed some resolutions: %u\n", ok);
192 return ok; 191 return ok;
diff --git a/src/util/test_scheduler.c b/src/util/test_scheduler.c
index b19ccff2d..98dce6f97 100644
--- a/src/util/test_scheduler.c
+++ b/src/util/test_scheduler.c
@@ -119,17 +119,17 @@ task5 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
119 fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ); 119 fds[0] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_READ);
120 fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE); 120 fds[1] = GNUNET_DISK_pipe_handle (p, GNUNET_DISK_PIPE_END_WRITE);
121 GNUNET_SCHEDULER_add_read_file (tc->sched, 121 GNUNET_SCHEDULER_add_read_file (tc->sched,
122 GNUNET_NO, 122 GNUNET_NO,
123 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 123 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
124 GNUNET_SCHEDULER_NO_TASK, 124 GNUNET_SCHEDULER_NO_TASK,
125 GNUNET_TIME_UNIT_FOREVER_REL, 125 GNUNET_TIME_UNIT_FOREVER_REL,
126 fds[0], &taskRd, cls); 126 fds[0], &taskRd, cls);
127 GNUNET_SCHEDULER_add_write_file (tc->sched, 127 GNUNET_SCHEDULER_add_write_file (tc->sched,
128 GNUNET_NO, 128 GNUNET_NO,
129 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 129 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
130 GNUNET_SCHEDULER_NO_TASK, 130 GNUNET_SCHEDULER_NO_TASK,
131 GNUNET_TIME_UNIT_FOREVER_REL, 131 GNUNET_TIME_UNIT_FOREVER_REL,
132 fds[1], &taskWrt, cls); 132 fds[1], &taskWrt, cls);
133} 133}
134 134
135 135
@@ -146,19 +146,18 @@ task1 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
146 t2 = GNUNET_SCHEDULER_add_after (tc->sched, 146 t2 = GNUNET_SCHEDULER_add_after (tc->sched,
147 GNUNET_NO, 147 GNUNET_NO,
148 GNUNET_SCHEDULER_PRIORITY_IDLE, 148 GNUNET_SCHEDULER_PRIORITY_IDLE,
149 GNUNET_SCHEDULER_NO_TASK, 149 GNUNET_SCHEDULER_NO_TASK, &task2, cls);
150 &task2, cls);
151 /* t3 will go before t4: higher priority */ 150 /* t3 will go before t4: higher priority */
152 t4 = GNUNET_SCHEDULER_add_after (tc->sched, 151 t4 = GNUNET_SCHEDULER_add_after (tc->sched,
153 GNUNET_NO, 152 GNUNET_NO,
154 GNUNET_SCHEDULER_PRIORITY_IDLE, 153 GNUNET_SCHEDULER_PRIORITY_IDLE,
155 t2, &task4, cls); 154 t2, &task4, cls);
156 GNUNET_SCHEDULER_add_delayed (tc->sched, 155 GNUNET_SCHEDULER_add_delayed (tc->sched,
157 GNUNET_NO, 156 GNUNET_NO,
158 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 157 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
159 t2, 158 t2,
160 GNUNET_TIME_relative_get_zero (), 159 GNUNET_TIME_relative_get_zero (),
161 &task3, cls); 160 &task3, cls);
162 /* t4 will go first: lower prio, but prereq! */ 161 /* t4 will go first: lower prio, but prereq! */
163 GNUNET_SCHEDULER_add_after (tc->sched, 162 GNUNET_SCHEDULER_add_after (tc->sched,
164 GNUNET_NO, 163 GNUNET_NO,
diff --git a/src/util/test_server.c b/src/util/test_server.c
index eadc03568..ae5609de0 100644
--- a/src/util/test_server.c
+++ b/src/util/test_server.c
@@ -87,7 +87,8 @@ my_receive (void *cls,
87 *ok = 2; /* report success */ 87 *ok = 2; /* report success */
88 msg.type = htons (MY_TYPE2); 88 msg.type = htons (MY_TYPE2);
89 msg.size = htons (sizeof (struct GNUNET_MessageHeader)); 89 msg.size = htons (sizeof (struct GNUNET_MessageHeader));
90 receiver (receiver_cls, &msg, sizeof (struct GNUNET_MessageHeader), NULL, 0, 0); 90 receiver (receiver_cls, &msg, sizeof (struct GNUNET_MessageHeader),
91 NULL, 0, 0);
91 break; 92 break;
92 case 3: 93 case 3:
93 /* called after first receive instantly 94 /* called after first receive instantly
diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c
index 9aff7fc72..c5ce5e736 100644
--- a/src/util/test_server_disconnect.c
+++ b/src/util/test_server_disconnect.c
@@ -210,8 +210,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
210 256, 210 256,
211 GNUNET_TIME_relative_multiply 211 GNUNET_TIME_relative_multiply
212 (GNUNET_TIME_UNIT_MILLISECONDS, 250), 212 (GNUNET_TIME_UNIT_MILLISECONDS, 250),
213 GNUNET_NO, 213 GNUNET_NO, &notify_ready, NULL);
214 &notify_ready, NULL);
215} 214}
216 215
217 216
diff --git a/src/util/test_server_with_client.c b/src/util/test_server_with_client.c
index 2558fd10c..508c505b1 100644
--- a/src/util/test_server_with_client.c
+++ b/src/util/test_server_with_client.c
@@ -184,8 +184,7 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
184 256, 184 256,
185 GNUNET_TIME_relative_multiply 185 GNUNET_TIME_relative_multiply
186 (GNUNET_TIME_UNIT_MILLISECONDS, 250), 186 (GNUNET_TIME_UNIT_MILLISECONDS, 250),
187 GNUNET_NO, 187 GNUNET_NO, &notify_ready, NULL);
188 &notify_ready, NULL);
189} 188}
190 189
191 190
diff --git a/src/util/test_service.c b/src/util/test_service.c
index 037f6edf7..93cafb4d2 100644
--- a/src/util/test_service.c
+++ b/src/util/test_service.c
@@ -86,8 +86,7 @@ ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
86 GNUNET_CLIENT_notify_transmit_ready (client, 86 GNUNET_CLIENT_notify_transmit_ready (client,
87 sizeof (struct GNUNET_MessageHeader), 87 sizeof (struct GNUNET_MessageHeader),
88 GNUNET_TIME_UNIT_SECONDS, 88 GNUNET_TIME_UNIT_SECONDS,
89 GNUNET_NO, 89 GNUNET_NO, &build_msg, client);
90 &build_msg, client);
91} 90}
92 91
93static void 92static void
@@ -114,12 +113,12 @@ runner (void *cls,
114 GNUNET_SERVER_add_handlers (server, myhandlers); 113 GNUNET_SERVER_add_handlers (server, myhandlers);
115 GNUNET_CLIENT_service_test (sched, 114 GNUNET_CLIENT_service_test (sched,
116 "test_service", 115 "test_service",
117 cfg, GNUNET_TIME_UNIT_SECONDS, &ready, (void*) cfg); 116 cfg, GNUNET_TIME_UNIT_SECONDS, &ready,
117 (void *) cfg);
118} 118}
119 119
120static void 120static void
121term (void *cls, 121term (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
122 const struct GNUNET_CONFIGURATION_Handle *cfg)
123{ 122{
124 int *ok = cls; 123 int *ok = cls;
125 *ok = 0; 124 *ok = 0;
@@ -170,8 +169,7 @@ ready6 (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
170 GNUNET_CLIENT_notify_transmit_ready (client, 169 GNUNET_CLIENT_notify_transmit_ready (client,
171 sizeof (struct GNUNET_MessageHeader), 170 sizeof (struct GNUNET_MessageHeader),
172 GNUNET_TIME_UNIT_SECONDS, 171 GNUNET_TIME_UNIT_SECONDS,
173 GNUNET_NO, 172 GNUNET_NO, &build_msg, client);
174 &build_msg, client);
175} 173}
176 174
177static void 175static void
@@ -184,7 +182,8 @@ runner6 (void *cls,
184 GNUNET_SERVER_add_handlers (server, myhandlers); 182 GNUNET_SERVER_add_handlers (server, myhandlers);
185 GNUNET_CLIENT_service_test (sched, 183 GNUNET_CLIENT_service_test (sched,
186 "test_service6", 184 "test_service6",
187 cfg, GNUNET_TIME_UNIT_SECONDS, &ready6, (void*) cfg); 185 cfg, GNUNET_TIME_UNIT_SECONDS, &ready6,
186 (void *) cfg);
188} 187}
189 188
190/** 189/**
@@ -254,8 +253,8 @@ static void
254start_stop_main (void *cls, 253start_stop_main (void *cls,
255 struct GNUNET_SCHEDULER_Handle *sched, 254 struct GNUNET_SCHEDULER_Handle *sched,
256 char *const *args, 255 char *const *args,
257 const char *cfgfile, 256 const char *cfgfile,
258 const struct GNUNET_CONFIGURATION_Handle *cfg) 257 const struct GNUNET_CONFIGURATION_Handle *cfg)
259{ 258{
260 int *ret = cls; 259 int *ret = cls;
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 260 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/util/time.c b/src/util/time.c
index 90351138a..6411de662 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -40,7 +40,9 @@ GNUNET_TIME_absolute_get ()
40 struct timeval tv; 40 struct timeval tv;
41 41
42 GETTIMEOFDAY (&tv, NULL); 42 GETTIMEOFDAY (&tv, NULL);
43 ret.value = (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) + ((uint64_t) tv.tv_usec / 1000LL)); 43 ret.value =
44 (uint64_t) (((uint64_t) tv.tv_sec * 1000LL) +
45 ((uint64_t) tv.tv_usec / 1000LL));
44 return ret; 46 return ret;
45} 47}
46 48
@@ -106,7 +108,7 @@ struct GNUNET_TIME_Absolute
106GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel) 108GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
107{ 109{
108 struct GNUNET_TIME_Absolute ret; 110 struct GNUNET_TIME_Absolute ret;
109 if (rel.value == (uint64_t) -1LL) 111 if (rel.value == (uint64_t) - 1LL)
110 return GNUNET_TIME_absolute_get_forever (); 112 return GNUNET_TIME_absolute_get_forever ();
111 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 113 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
112 if (rel.value + now.value < rel.value) 114 if (rel.value + now.value < rel.value)
@@ -126,11 +128,10 @@ GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel)
126 * @param t2 other timestamp 128 * @param t2 other timestamp
127 * @return timestamp that is smaller 129 * @return timestamp that is smaller
128 */ 130 */
129struct GNUNET_TIME_Relative GNUNET_TIME_relative_min (struct 131struct GNUNET_TIME_Relative
130 GNUNET_TIME_Relative 132GNUNET_TIME_relative_min (struct
131 t1, 133 GNUNET_TIME_Relative
132 struct 134 t1, struct GNUNET_TIME_Relative t2)
133 GNUNET_TIME_Relative t2)
134{ 135{
135 return (t1.value < t2.value) ? t1 : t2; 136 return (t1.value < t2.value) ? t1 : t2;
136} 137}
@@ -144,11 +145,10 @@ struct GNUNET_TIME_Relative GNUNET_TIME_relative_min (struct
144 * @param t2 other timestamp 145 * @param t2 other timestamp
145 * @return timestamp that is smaller 146 * @return timestamp that is smaller
146 */ 147 */
147struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_min (struct 148struct GNUNET_TIME_Absolute
148 GNUNET_TIME_Absolute 149GNUNET_TIME_absolute_min (struct
149 t1, 150 GNUNET_TIME_Absolute
150 struct 151 t1, struct GNUNET_TIME_Absolute t2)
151 GNUNET_TIME_Absolute t2)
152{ 152{
153 return (t1.value < t2.value) ? t1 : t2; 153 return (t1.value < t2.value) ? t1 : t2;
154} 154}
@@ -254,7 +254,7 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
254 { 254 {
255 GNUNET_break (0); 255 GNUNET_break (0);
256 return GNUNET_TIME_relative_get_forever (); 256 return GNUNET_TIME_relative_get_forever ();
257 } 257 }
258 return ret; 258 return ret;
259} 259}
260 260
@@ -269,9 +269,9 @@ GNUNET_TIME_relative_multiply (struct GNUNET_TIME_Relative rel,
269 * @return remaining duration for the operation, 269 * @return remaining duration for the operation,
270 * assuming it continues at the same speed 270 * assuming it continues at the same speed
271 */ 271 */
272struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start, 272struct GNUNET_TIME_Relative
273 uint64_t finished, 273GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolute start,
274 uint64_t total) 274 uint64_t finished, uint64_t total)
275{ 275{
276 struct GNUNET_TIME_Relative dur; 276 struct GNUNET_TIME_Relative dur;
277 double exp; 277 double exp;
@@ -283,7 +283,7 @@ struct GNUNET_TIME_Relative GNUNET_TIME_calculate_eta (struct GNUNET_TIME_Absolu
283 if (finished == 0) 283 if (finished == 0)
284 return GNUNET_TIME_UNIT_FOREVER_REL; 284 return GNUNET_TIME_UNIT_FOREVER_REL;
285 dur = GNUNET_TIME_absolute_get_duration (start); 285 dur = GNUNET_TIME_absolute_get_duration (start);
286 exp = ((double)dur.value) * ((double) total) / ((double)finished); 286 exp = ((double) dur.value) * ((double) total) / ((double) finished);
287 ret.value = ((uint64_t) exp) - dur.value; 287 ret.value = ((uint64_t) exp) - dur.value;
288 return ret; 288 return ret;
289} 289}
diff --git a/src/util/winproc.c b/src/util/winproc.c
index 862222c05..bd2f2d091 100644
--- a/src/util/winproc.c
+++ b/src/util/winproc.c
@@ -73,8 +73,8 @@ void
73plibc_panic (int err, char *msg) 73plibc_panic (int err, char *msg)
74{ 74{
75 GNUNET_log (((err == 75 GNUNET_log (((err ==
76 INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR), 76 INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR),
77 "%s", msg); 77 "%s", msg);
78} 78}
79 79
80/** 80/**