summaryrefslogtreecommitdiff
path: root/src/transport/gnunet-communicator-unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/gnunet-communicator-unix.c')
-rw-r--r--src/transport/gnunet-communicator-unix.c958
1 files changed, 479 insertions, 479 deletions
diff --git a/src/transport/gnunet-communicator-unix.c b/src/transport/gnunet-communicator-unix.c
index cb1fbc230..da610daa1 100644
--- a/src/transport/gnunet-communicator-unix.c
+++ b/src/transport/gnunet-communicator-unix.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/gnunet-communicator-unix.c 22 * @file transport/gnunet-communicator-unix.c
@@ -64,8 +64,7 @@ GNUNET_NETWORK_STRUCT_BEGIN
64/** 64/**
65 * UNIX Message-Packet header. 65 * UNIX Message-Packet header.
66 */ 66 */
67struct UNIXMessage 67struct UNIXMessage {
68{
69 /** 68 /**
70 * Message header. 69 * Message header.
71 */ 70 */
@@ -83,9 +82,7 @@ GNUNET_NETWORK_STRUCT_END
83/** 82/**
84 * Handle for a queue. 83 * Handle for a queue.
85 */ 84 */
86struct Queue 85struct Queue {
87{
88
89 /** 86 /**
90 * Queues with pending messages (!) are kept in a DLL. 87 * Queues with pending messages (!) are kept in a DLL.
91 */ 88 */
@@ -208,37 +205,37 @@ static struct GNUNET_TRANSPORT_AddressIdentifier *ai;
208 * @param queue queue to close down 205 * @param queue queue to close down
209 */ 206 */
210static void 207static void
211queue_destroy (struct Queue *queue) 208queue_destroy(struct Queue *queue)
212{ 209{
213 struct GNUNET_MQ_Handle *mq; 210 struct GNUNET_MQ_Handle *mq;
214 211
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 212 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
216 "Disconnecting queue for peer `%s'\n", 213 "Disconnecting queue for peer `%s'\n",
217 GNUNET_i2s (&queue->target)); 214 GNUNET_i2s(&queue->target));
218 if (0 != queue->bytes_in_queue) 215 if (0 != queue->bytes_in_queue)
219 { 216 {
220 GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue); 217 GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue);
221 queue->bytes_in_queue = 0; 218 queue->bytes_in_queue = 0;
222 } 219 }
223 if (NULL != (mq = queue->mq)) 220 if (NULL != (mq = queue->mq))
224 { 221 {
225 queue->mq = NULL; 222 queue->mq = NULL;
226 GNUNET_MQ_destroy (mq); 223 GNUNET_MQ_destroy(mq);
227 } 224 }
228 GNUNET_assert ( 225 GNUNET_assert(
229 GNUNET_YES == 226 GNUNET_YES ==
230 GNUNET_CONTAINER_multipeermap_remove (queue_map, &queue->target, queue)); 227 GNUNET_CONTAINER_multipeermap_remove(queue_map, &queue->target, queue));
231 GNUNET_STATISTICS_set (stats, 228 GNUNET_STATISTICS_set(stats,
232 "# queues active", 229 "# queues active",
233 GNUNET_CONTAINER_multipeermap_size (queue_map), 230 GNUNET_CONTAINER_multipeermap_size(queue_map),
234 GNUNET_NO); 231 GNUNET_NO);
235 if (NULL != queue->timeout_task) 232 if (NULL != queue->timeout_task)
236 { 233 {
237 GNUNET_SCHEDULER_cancel (queue->timeout_task); 234 GNUNET_SCHEDULER_cancel(queue->timeout_task);
238 queue->timeout_task = NULL; 235 queue->timeout_task = NULL;
239 } 236 }
240 GNUNET_free (queue->address); 237 GNUNET_free(queue->address);
241 GNUNET_free (queue); 238 GNUNET_free(queue);
242} 239}
243 240
244 241
@@ -248,28 +245,28 @@ queue_destroy (struct Queue *queue)
248 * @param cls the `struct Queue *` to disconnect 245 * @param cls the `struct Queue *` to disconnect
249 */ 246 */
250static void 247static void
251queue_timeout (void *cls) 248queue_timeout(void *cls)
252{ 249{
253 struct Queue *queue = cls; 250 struct Queue *queue = cls;
254 struct GNUNET_TIME_Relative left; 251 struct GNUNET_TIME_Relative left;
255 252
256 queue->timeout_task = NULL; 253 queue->timeout_task = NULL;
257 left = GNUNET_TIME_absolute_get_remaining (queue->timeout); 254 left = GNUNET_TIME_absolute_get_remaining(queue->timeout);
258 if (0 != left.rel_value_us) 255 if (0 != left.rel_value_us)
259 { 256 {
260 /* not actually our turn yet, but let's at least update 257 /* not actually our turn yet, but let's at least update
261 the monitor, it may think we're about to die ... */ 258 the monitor, it may think we're about to die ... */
262 queue->timeout_task = 259 queue->timeout_task =
263 GNUNET_SCHEDULER_add_delayed (left, &queue_timeout, queue); 260 GNUNET_SCHEDULER_add_delayed(left, &queue_timeout, queue);
264 return; 261 return;
265 } 262 }
266 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 263 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
267 "Queue %p was idle for %s, disconnecting\n", 264 "Queue %p was idle for %s, disconnecting\n",
268 queue, 265 queue,
269 GNUNET_STRINGS_relative_time_to_string ( 266 GNUNET_STRINGS_relative_time_to_string(
270 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 267 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
271 GNUNET_YES)); 268 GNUNET_YES));
272 queue_destroy (queue); 269 queue_destroy(queue);
273} 270}
274 271
275 272
@@ -281,11 +278,11 @@ queue_timeout (void *cls)
281 * @param queue queue for which the timeout should be rescheduled 278 * @param queue queue for which the timeout should be rescheduled
282 */ 279 */
283static void 280static void
284reschedule_queue_timeout (struct Queue *queue) 281reschedule_queue_timeout(struct Queue *queue)
285{ 282{
286 GNUNET_assert (NULL != queue->timeout_task); 283 GNUNET_assert(NULL != queue->timeout_task);
287 queue->timeout = 284 queue->timeout =
288 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 285 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
289} 286}
290 287
291 288
@@ -298,22 +295,22 @@ reschedule_queue_timeout (struct Queue *queue)
298 * @return converted unix path 295 * @return converted unix path
299 */ 296 */
300static struct sockaddr_un * 297static struct sockaddr_un *
301unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len) 298unix_address_to_sockaddr(const char *unixpath, socklen_t *sock_len)
302{ 299{
303 struct sockaddr_un *un; 300 struct sockaddr_un *un;
304 size_t slen; 301 size_t slen;
305 302
306 GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ 303 GNUNET_assert(0 < strlen(unixpath)); /* sanity check */
307 un = GNUNET_new (struct sockaddr_un); 304 un = GNUNET_new(struct sockaddr_un);
308 un->sun_family = AF_UNIX; 305 un->sun_family = AF_UNIX;
309 slen = strlen (unixpath); 306 slen = strlen(unixpath);
310 if (slen >= sizeof (un->sun_path)) 307 if (slen >= sizeof(un->sun_path))
311 slen = sizeof (un->sun_path) - 1; 308 slen = sizeof(un->sun_path) - 1;
312 GNUNET_memcpy (un->sun_path, unixpath, slen); 309 GNUNET_memcpy(un->sun_path, unixpath, slen);
313 un->sun_path[slen] = '\0'; 310 un->sun_path[slen] = '\0';
314 slen = sizeof (struct sockaddr_un); 311 slen = sizeof(struct sockaddr_un);
315#if HAVE_SOCKADDR_UN_SUN_LEN 312#if HAVE_SOCKADDR_UN_SUN_LEN
316 un->sun_len = (u_char) slen; 313 un->sun_len = (u_char)slen;
317#endif 314#endif
318 (*sock_len) = slen; 315 (*sock_len) = slen;
319 if ('@' == un->sun_path[0]) 316 if ('@' == un->sun_path[0])
@@ -325,8 +322,7 @@ unix_address_to_sockaddr (const char *unixpath, socklen_t *sock_len)
325/** 322/**
326 * Closure to #lookup_queue_it(). 323 * Closure to #lookup_queue_it().
327 */ 324 */
328struct LookupCtx 325struct LookupCtx {
329{
330 /** 326 /**
331 * Location to store the queue, if found. 327 * Location to store the queue, if found.
332 */ 328 */
@@ -353,17 +349,17 @@ struct LookupCtx
353 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success 349 * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
354 */ 350 */
355static int 351static int
356lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 352lookup_queue_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
357{ 353{
358 struct LookupCtx *lctx = cls; 354 struct LookupCtx *lctx = cls;
359 struct Queue *queue = value; 355 struct Queue *queue = value;
360 356
361 if ((queue->address_len = lctx->un_len) && 357 if ((queue->address_len = lctx->un_len) &&
362 (0 == memcmp (lctx->un, queue->address, queue->address_len))) 358 (0 == memcmp(lctx->un, queue->address, queue->address_len)))
363 { 359 {
364 lctx->res = queue; 360 lctx->res = queue;
365 return GNUNET_NO; 361 return GNUNET_NO;
366 } 362 }
367 return GNUNET_YES; 363 return GNUNET_YES;
368} 364}
369 365
@@ -376,18 +372,18 @@ lookup_queue_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
376 * @return NULL if queue was not found 372 * @return NULL if queue was not found
377 */ 373 */
378static struct Queue * 374static struct Queue *
379lookup_queue (const struct GNUNET_PeerIdentity *peer, 375lookup_queue(const struct GNUNET_PeerIdentity *peer,
380 const struct sockaddr_un *un, 376 const struct sockaddr_un *un,
381 socklen_t un_len) 377 socklen_t un_len)
382{ 378{
383 struct LookupCtx lctx; 379 struct LookupCtx lctx;
384 380
385 lctx.un = un; 381 lctx.un = un;
386 lctx.un_len = un_len; 382 lctx.un_len = un_len;
387 GNUNET_CONTAINER_multipeermap_get_multiple (queue_map, 383 GNUNET_CONTAINER_multipeermap_get_multiple(queue_map,
388 peer, 384 peer,
389 &lookup_queue_it, 385 &lookup_queue_it,
390 &lctx); 386 &lctx);
391 return lctx.res; 387 return lctx.res;
392} 388}
393 389
@@ -399,103 +395,105 @@ lookup_queue (const struct GNUNET_PeerIdentity *peer,
399 * @param cls NULL 395 * @param cls NULL
400 */ 396 */
401static void 397static void
402select_write_cb (void *cls) 398select_write_cb(void *cls)
403{ 399{
404 struct Queue *queue = queue_tail; 400 struct Queue *queue = queue_tail;
405 const struct GNUNET_MessageHeader *msg = queue->msg; 401 const struct GNUNET_MessageHeader *msg = queue->msg;
406 size_t msg_size = ntohs (msg->size); 402 size_t msg_size = ntohs(msg->size);
407 ssize_t sent; 403 ssize_t sent;
408 404
409 /* take queue of the ready list */ 405 /* take queue of the ready list */
410 write_task = NULL; 406 write_task = NULL;
411 GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue); 407 GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue);
412 if (NULL != queue_head) 408 if (NULL != queue_head)
413 write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 409 write_task = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
414 unix_sock, 410 unix_sock,
415 &select_write_cb, 411 &select_write_cb,
416 NULL); 412 NULL);
417 413
418 /* send 'msg' */ 414 /* send 'msg' */
419 queue->msg = NULL; 415 queue->msg = NULL;
420 GNUNET_MQ_impl_send_continue (queue->mq); 416 GNUNET_MQ_impl_send_continue(queue->mq);
421resend: 417resend:
422 /* Send the data */ 418 /* Send the data */
423 sent = GNUNET_NETWORK_socket_sendto (unix_sock, 419 sent = GNUNET_NETWORK_socket_sendto(unix_sock,
424 msg, 420 msg,
425 msg_size, 421 msg_size,
426 (const struct sockaddr *) queue->address, 422 (const struct sockaddr *)queue->address,
427 queue->address_len); 423 queue->address_len);
428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 424 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
429 "UNIX transmitted message to %s (%d/%u: %s)\n", 425 "UNIX transmitted message to %s (%d/%u: %s)\n",
430 GNUNET_i2s (&queue->target), 426 GNUNET_i2s(&queue->target),
431 (int) sent, 427 (int)sent,
432 (unsigned int) msg_size, 428 (unsigned int)msg_size,
433 (sent < 0) ? strerror (errno) : "ok"); 429 (sent < 0) ? strerror(errno) : "ok");
434 if (-1 != sent) 430 if (-1 != sent)
435 { 431 {
436 GNUNET_STATISTICS_update (stats, 432 GNUNET_STATISTICS_update(stats,
437 "# bytes sent", 433 "# bytes sent",
438 (long long) sent, 434 (long long)sent,
439 GNUNET_NO); 435 GNUNET_NO);
440 reschedule_queue_timeout (queue); 436 reschedule_queue_timeout(queue);
441 return; /* all good */ 437 return; /* all good */
442 } 438 }
443 GNUNET_STATISTICS_update (stats, 439 GNUNET_STATISTICS_update(stats,
444 "# network transmission failures", 440 "# network transmission failures",
445 1, 441 1,
446 GNUNET_NO); 442 GNUNET_NO);
447 switch (errno) 443 switch (errno)
448 {
449 case EAGAIN:
450 case ENOBUFS:
451 /* We should retry later... */
452 GNUNET_log_strerror (GNUNET_ERROR_TYPE_DEBUG, "send");
453 return;
454 case EMSGSIZE: {
455 socklen_t size = 0;
456 socklen_t len = sizeof (size);
457
458 GNUNET_NETWORK_socket_getsockopt (unix_sock,
459 SOL_SOCKET,
460 SO_SNDBUF,
461 &size,
462 &len);
463 if (size > ntohs (msg->size))
464 { 444 {
465 /* Buffer is bigger than message: error, no retry 445 case EAGAIN:
466 * This should never happen!*/ 446 case ENOBUFS:
467 GNUNET_break (0); 447 /* We should retry later... */
448 GNUNET_log_strerror(GNUNET_ERROR_TYPE_DEBUG, "send");
449 return;
450
451 case EMSGSIZE: {
452 socklen_t size = 0;
453 socklen_t len = sizeof(size);
454
455 GNUNET_NETWORK_socket_getsockopt(unix_sock,
456 SOL_SOCKET,
457 SO_SNDBUF,
458 &size,
459 &len);
460 if (size > ntohs(msg->size))
461 {
462 /* Buffer is bigger than message: error, no retry
463 * This should never happen!*/
464 GNUNET_break(0);
465 return;
466 }
467 GNUNET_log(
468 GNUNET_ERROR_TYPE_DEBUG,
469 "Trying to increase socket buffer size from %u to %u for message size %u\n",
470 (unsigned int)size,
471 (unsigned int)((msg_size / 1000) + 2) * 1000,
472 (unsigned int)msg_size);
473 size = ((msg_size / 1000) + 2) * 1000;
474 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt(unix_sock,
475 SOL_SOCKET,
476 SO_SNDBUF,
477 &size,
478 sizeof(size)))
479 goto resend; /* Increased buffer size, retry sending */
480 /* Ok, then just try very modest increase */
481 size = msg_size;
482 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt(unix_sock,
483 SOL_SOCKET,
484 SO_SNDBUF,
485 &size,
486 sizeof(size)))
487 goto resend; /* Increased buffer size, retry sending */
488 /* Could not increase buffer size: error, no retry */
489 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "setsockopt");
490 return;
491 }
492
493 default:
494 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "send");
468 return; 495 return;
469 } 496 }
470 GNUNET_log (
471 GNUNET_ERROR_TYPE_DEBUG,
472 "Trying to increase socket buffer size from %u to %u for message size %u\n",
473 (unsigned int) size,
474 (unsigned int) ((msg_size / 1000) + 2) * 1000,
475 (unsigned int) msg_size);
476 size = ((msg_size / 1000) + 2) * 1000;
477 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock,
478 SOL_SOCKET,
479 SO_SNDBUF,
480 &size,
481 sizeof (size)))
482 goto resend; /* Increased buffer size, retry sending */
483 /* Ok, then just try very modest increase */
484 size = msg_size;
485 if (GNUNET_OK == GNUNET_NETWORK_socket_setsockopt (unix_sock,
486 SOL_SOCKET,
487 SO_SNDBUF,
488 &size,
489 sizeof (size)))
490 goto resend; /* Increased buffer size, retry sending */
491 /* Could not increase buffer size: error, no retry */
492 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "setsockopt");
493 return;
494 }
495 default:
496 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "send");
497 return;
498 }
499} 497}
500 498
501 499
@@ -508,22 +506,22 @@ resend:
508 * @param impl_state our `struct Queue` 506 * @param impl_state our `struct Queue`
509 */ 507 */
510static void 508static void
511mq_send (struct GNUNET_MQ_Handle *mq, 509mq_send(struct GNUNET_MQ_Handle *mq,
512 const struct GNUNET_MessageHeader *msg, 510 const struct GNUNET_MessageHeader *msg,
513 void *impl_state) 511 void *impl_state)
514{ 512{
515 struct Queue *queue = impl_state; 513 struct Queue *queue = impl_state;
516 514
517 GNUNET_assert (mq == queue->mq); 515 GNUNET_assert(mq == queue->mq);
518 GNUNET_assert (NULL == queue->msg); 516 GNUNET_assert(NULL == queue->msg);
519 queue->msg = msg; 517 queue->msg = msg;
520 GNUNET_CONTAINER_DLL_insert (queue_head, queue_tail, queue); 518 GNUNET_CONTAINER_DLL_insert(queue_head, queue_tail, queue);
521 GNUNET_assert (NULL != unix_sock); 519 GNUNET_assert(NULL != unix_sock);
522 if (NULL == write_task) 520 if (NULL == write_task)
523 write_task = GNUNET_SCHEDULER_add_write_net (GNUNET_TIME_UNIT_FOREVER_REL, 521 write_task = GNUNET_SCHEDULER_add_write_net(GNUNET_TIME_UNIT_FOREVER_REL,
524 unix_sock, 522 unix_sock,
525 &select_write_cb, 523 &select_write_cb,
526 NULL); 524 NULL);
527} 525}
528 526
529 527
@@ -536,15 +534,15 @@ mq_send (struct GNUNET_MQ_Handle *mq,
536 * @param impl_state our `struct Queue` 534 * @param impl_state our `struct Queue`
537 */ 535 */
538static void 536static void
539mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state) 537mq_destroy(struct GNUNET_MQ_Handle *mq, void *impl_state)
540{ 538{
541 struct Queue *queue = impl_state; 539 struct Queue *queue = impl_state;
542 540
543 if (mq == queue->mq) 541 if (mq == queue->mq)
544 { 542 {
545 queue->mq = NULL; 543 queue->mq = NULL;
546 queue_destroy (queue); 544 queue_destroy(queue);
547 } 545 }
548} 546}
549 547
550 548
@@ -555,19 +553,19 @@ mq_destroy (struct GNUNET_MQ_Handle *mq, void *impl_state)
555 * @param impl_state our `struct Queue` 553 * @param impl_state our `struct Queue`
556 */ 554 */
557static void 555static void
558mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state) 556mq_cancel(struct GNUNET_MQ_Handle *mq, void *impl_state)
559{ 557{
560 struct Queue *queue = impl_state; 558 struct Queue *queue = impl_state;
561 559
562 GNUNET_assert (NULL != queue->msg); 560 GNUNET_assert(NULL != queue->msg);
563 queue->msg = NULL; 561 queue->msg = NULL;
564 GNUNET_CONTAINER_DLL_remove (queue_head, queue_tail, queue); 562 GNUNET_CONTAINER_DLL_remove(queue_head, queue_tail, queue);
565 GNUNET_assert (NULL != write_task); 563 GNUNET_assert(NULL != write_task);
566 if (NULL == queue_head) 564 if (NULL == queue_head)
567 { 565 {
568 GNUNET_SCHEDULER_cancel (write_task); 566 GNUNET_SCHEDULER_cancel(write_task);
569 write_task = NULL; 567 write_task = NULL;
570 } 568 }
571} 569}
572 570
573 571
@@ -581,15 +579,15 @@ mq_cancel (struct GNUNET_MQ_Handle *mq, void *impl_state)
581 * @param error error code 579 * @param error error code
582 */ 580 */
583static void 581static void
584mq_error (void *cls, enum GNUNET_MQ_Error error) 582mq_error(void *cls, enum GNUNET_MQ_Error error)
585{ 583{
586 struct Queue *queue = cls; 584 struct Queue *queue = cls;
587 585
588 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 586 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
589 "UNIX MQ error in queue to %s: %d\n", 587 "UNIX MQ error in queue to %s: %d\n",
590 GNUNET_i2s (&queue->target), 588 GNUNET_i2s(&queue->target),
591 (int) error); 589 (int)error);
592 queue_destroy (queue); 590 queue_destroy(queue);
593} 591}
594 592
595 593
@@ -604,60 +602,60 @@ mq_error (void *cls, enum GNUNET_MQ_Error error)
604 * @return the queue or NULL of max connections exceeded 602 * @return the queue or NULL of max connections exceeded
605 */ 603 */
606static struct Queue * 604static struct Queue *
607setup_queue (const struct GNUNET_PeerIdentity *target, 605setup_queue(const struct GNUNET_PeerIdentity *target,
608 enum GNUNET_TRANSPORT_ConnectionStatus cs, 606 enum GNUNET_TRANSPORT_ConnectionStatus cs,
609 const struct sockaddr_un *un, 607 const struct sockaddr_un *un,
610 socklen_t un_len) 608 socklen_t un_len)
611{ 609{
612 struct Queue *queue; 610 struct Queue *queue;
613 611
614 queue = GNUNET_new (struct Queue); 612 queue = GNUNET_new(struct Queue);
615 queue->target = *target; 613 queue->target = *target;
616 queue->address = GNUNET_memdup (un, un_len); 614 queue->address = GNUNET_memdup(un, un_len);
617 queue->address_len = un_len; 615 queue->address_len = un_len;
618 (void) GNUNET_CONTAINER_multipeermap_put ( 616 (void)GNUNET_CONTAINER_multipeermap_put(
619 queue_map, 617 queue_map,
620 &queue->target, 618 &queue->target,
621 queue, 619 queue,
622 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 620 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
623 GNUNET_STATISTICS_set (stats, 621 GNUNET_STATISTICS_set(stats,
624 "# queues active", 622 "# queues active",
625 GNUNET_CONTAINER_multipeermap_size (queue_map), 623 GNUNET_CONTAINER_multipeermap_size(queue_map),
626 GNUNET_NO); 624 GNUNET_NO);
627 queue->timeout = 625 queue->timeout =
628 GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); 626 GNUNET_TIME_relative_to_absolute(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
629 queue->timeout_task = 627 queue->timeout_task =
630 GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 628 GNUNET_SCHEDULER_add_delayed(GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
631 &queue_timeout, 629 &queue_timeout,
632 queue); 630 queue);
633 queue->mq = GNUNET_MQ_queue_for_callbacks (&mq_send, 631 queue->mq = GNUNET_MQ_queue_for_callbacks(&mq_send,
634 &mq_destroy, 632 &mq_destroy,
635 &mq_cancel, 633 &mq_cancel,
636 queue, 634 queue,
637 NULL, 635 NULL,
638 &mq_error, 636 &mq_error,
639 queue); 637 queue);
640 { 638 {
641 char *foreign_addr; 639 char *foreign_addr;
642 640
643 if ('\0' == un->sun_path[0]) 641 if ('\0' == un->sun_path[0])
644 GNUNET_asprintf (&foreign_addr, 642 GNUNET_asprintf(&foreign_addr,
645 "%s-@%s", 643 "%s-@%s",
646 COMMUNICATOR_ADDRESS_PREFIX, 644 COMMUNICATOR_ADDRESS_PREFIX,
647 &un->sun_path[1]); 645 &un->sun_path[1]);
648 else 646 else
649 GNUNET_asprintf (&foreign_addr, 647 GNUNET_asprintf(&foreign_addr,
650 "%s-%s", 648 "%s-%s",
651 COMMUNICATOR_ADDRESS_PREFIX, 649 COMMUNICATOR_ADDRESS_PREFIX,
652 un->sun_path); 650 un->sun_path);
653 queue->qh = GNUNET_TRANSPORT_communicator_mq_add (ch, 651 queue->qh = GNUNET_TRANSPORT_communicator_mq_add(ch,
654 &queue->target, 652 &queue->target,
655 foreign_addr, 653 foreign_addr,
656 UNIX_MTU, 654 UNIX_MTU,
657 GNUNET_NT_LOOPBACK, 655 GNUNET_NT_LOOPBACK,
658 cs, 656 cs,
659 queue->mq); 657 queue->mq);
660 GNUNET_free (foreign_addr); 658 GNUNET_free(foreign_addr);
661 } 659 }
662 return queue; 660 return queue;
663} 661}
@@ -671,7 +669,7 @@ setup_queue (const struct GNUNET_PeerIdentity *target,
671 * @param cls NULL 669 * @param cls NULL
672 */ 670 */
673static void 671static void
674select_read_cb (void *cls); 672select_read_cb(void *cls);
675 673
676 674
677/** 675/**
@@ -682,21 +680,21 @@ select_read_cb (void *cls);
682 * @param success #GNUNET_OK on success 680 * @param success #GNUNET_OK on success
683 */ 681 */
684static void 682static void
685receive_complete_cb (void *cls, int success) 683receive_complete_cb(void *cls, int success)
686{ 684{
687 (void) cls; 685 (void)cls;
688 delivering_messages--; 686 delivering_messages--;
689 if (GNUNET_OK != success) 687 if (GNUNET_OK != success)
690 GNUNET_STATISTICS_update (stats, 688 GNUNET_STATISTICS_update(stats,
691 "# transport transmission failures", 689 "# transport transmission failures",
692 1, 690 1,
693 GNUNET_NO); 691 GNUNET_NO);
694 GNUNET_assert (NULL != unix_sock); 692 GNUNET_assert(NULL != unix_sock);
695 if ((NULL == read_task) && (delivering_messages < max_queue_length)) 693 if ((NULL == read_task) && (delivering_messages < max_queue_length))
696 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 694 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
697 unix_sock, 695 unix_sock,
698 &select_read_cb, 696 &select_read_cb,
699 NULL); 697 NULL);
700} 698}
701 699
702 700
@@ -708,7 +706,7 @@ receive_complete_cb (void *cls, int success)
708 * @param cls NULL 706 * @param cls NULL
709 */ 707 */
710static void 708static void
711select_read_cb (void *cls) 709select_read_cb(void *cls)
712{ 710{
713 char buf[65536] GNUNET_ALIGN; 711 char buf[65536] GNUNET_ALIGN;
714 struct Queue *queue; 712 struct Queue *queue;
@@ -718,93 +716,93 @@ select_read_cb (void *cls)
718 ssize_t ret; 716 ssize_t ret;
719 uint16_t msize; 717 uint16_t msize;
720 718
721 GNUNET_assert (NULL != unix_sock); 719 GNUNET_assert(NULL != unix_sock);
722 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 720 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
723 unix_sock, 721 unix_sock,
724 &select_read_cb, 722 &select_read_cb,
725 NULL); 723 NULL);
726 addrlen = sizeof (un); 724 addrlen = sizeof(un);
727 memset (&un, 0, sizeof (un)); 725 memset(&un, 0, sizeof(un));
728 ret = GNUNET_NETWORK_socket_recvfrom (unix_sock, 726 ret = GNUNET_NETWORK_socket_recvfrom(unix_sock,
729 buf, 727 buf,
730 sizeof (buf), 728 sizeof(buf),
731 (struct sockaddr *) &un, 729 (struct sockaddr *)&un,
732 &addrlen); 730 &addrlen);
733 if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno))) 731 if ((-1 == ret) && ((EAGAIN == errno) || (ENOBUFS == errno)))
734 return; 732 return;
735 if (-1 == ret) 733 if (-1 == ret)
736 { 734 {
737 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "recvfrom"); 735 GNUNET_log_strerror(GNUNET_ERROR_TYPE_WARNING, "recvfrom");
738 return; 736 return;
739 } 737 }
740 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 738 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
741 "Read %d bytes from socket %s\n", 739 "Read %d bytes from socket %s\n",
742 (int) ret, 740 (int)ret,
743 un.sun_path); 741 un.sun_path);
744 GNUNET_assert (AF_UNIX == (un.sun_family)); 742 GNUNET_assert(AF_UNIX == (un.sun_family));
745 msg = (struct UNIXMessage *) buf; 743 msg = (struct UNIXMessage *)buf;
746 msize = ntohs (msg->header.size); 744 msize = ntohs(msg->header.size);
747 if ((msize < sizeof (struct UNIXMessage)) || (msize > ret)) 745 if ((msize < sizeof(struct UNIXMessage)) || (msize > ret))
748 { 746 {
749 GNUNET_break_op (0); 747 GNUNET_break_op(0);
750 return; 748 return;
751 } 749 }
752 queue = lookup_queue (&msg->sender, &un, addrlen); 750 queue = lookup_queue(&msg->sender, &un, addrlen);
753 if (NULL == queue) 751 if (NULL == queue)
754 queue = 752 queue =
755 setup_queue (&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen); 753 setup_queue(&msg->sender, GNUNET_TRANSPORT_CS_INBOUND, &un, addrlen);
756 else 754 else
757 reschedule_queue_timeout (queue); 755 reschedule_queue_timeout(queue);
758 if (NULL == queue) 756 if (NULL == queue)
759 { 757 {
760 GNUNET_log ( 758 GNUNET_log(
761 GNUNET_ERROR_TYPE_ERROR, 759 GNUNET_ERROR_TYPE_ERROR,
762 _ ( 760 _(
763 "Maximum number of UNIX connections exceeded, dropping incoming message\n")); 761 "Maximum number of UNIX connections exceeded, dropping incoming message\n"));
764 return; 762 return;
765 } 763 }
766 764
767 { 765 {
768 uint16_t offset = 0; 766 uint16_t offset = 0;
769 uint16_t tsize = msize - sizeof (struct UNIXMessage); 767 uint16_t tsize = msize - sizeof(struct UNIXMessage);
770 const char *msgbuf = (const char *) &msg[1]; 768 const char *msgbuf = (const char *)&msg[1];
771 769
772 while (offset + sizeof (struct GNUNET_MessageHeader) <= tsize) 770 while (offset + sizeof(struct GNUNET_MessageHeader) <= tsize)
773 {
774 const struct GNUNET_MessageHeader *currhdr;
775 struct GNUNET_MessageHeader al_hdr;
776 uint16_t csize;
777
778 currhdr = (const struct GNUNET_MessageHeader *) &msgbuf[offset];
779 /* ensure aligned access */
780 memcpy (&al_hdr, currhdr, sizeof (al_hdr));
781 csize = ntohs (al_hdr.size);
782 if ((csize < sizeof (struct GNUNET_MessageHeader)) ||
783 (csize > tsize - offset))
784 { 771 {
785 GNUNET_break_op (0); 772 const struct GNUNET_MessageHeader *currhdr;
786 break; 773 struct GNUNET_MessageHeader al_hdr;
774 uint16_t csize;
775
776 currhdr = (const struct GNUNET_MessageHeader *)&msgbuf[offset];
777 /* ensure aligned access */
778 memcpy(&al_hdr, currhdr, sizeof(al_hdr));
779 csize = ntohs(al_hdr.size);
780 if ((csize < sizeof(struct GNUNET_MessageHeader)) ||
781 (csize > tsize - offset))
782 {
783 GNUNET_break_op(0);
784 break;
785 }
786 ret = GNUNET_TRANSPORT_communicator_receive(ch,
787 &msg->sender,
788 currhdr,
789 GNUNET_TIME_UNIT_FOREVER_REL,
790 &receive_complete_cb,
791 NULL);
792 if (GNUNET_SYSERR == ret)
793 return; /* transport not up */
794 if (GNUNET_NO == ret)
795 break;
796 delivering_messages++;
797 offset += csize;
787 } 798 }
788 ret = GNUNET_TRANSPORT_communicator_receive (ch,
789 &msg->sender,
790 currhdr,
791 GNUNET_TIME_UNIT_FOREVER_REL,
792 &receive_complete_cb,
793 NULL);
794 if (GNUNET_SYSERR == ret)
795 return; /* transport not up */
796 if (GNUNET_NO == ret)
797 break;
798 delivering_messages++;
799 offset += csize;
800 }
801 } 799 }
802 if (delivering_messages >= max_queue_length) 800 if (delivering_messages >= max_queue_length)
803 { 801 {
804 /* we should try to apply 'back pressure' */ 802 /* we should try to apply 'back pressure' */
805 GNUNET_SCHEDULER_cancel (read_task); 803 GNUNET_SCHEDULER_cancel(read_task);
806 read_task = NULL; 804 read_task = NULL;
807 } 805 }
808} 806}
809 807
810 808
@@ -826,43 +824,43 @@ select_read_cb (void *cls)
826 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid 824 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the provided address is invalid
827 */ 825 */
828static int 826static int
829mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address) 827mq_init(void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
830{ 828{
831 struct Queue *queue; 829 struct Queue *queue;
832 const char *path; 830 const char *path;
833 struct sockaddr_un *un; 831 struct sockaddr_un *un;
834 socklen_t un_len; 832 socklen_t un_len;
835 833
836 (void) cls; 834 (void)cls;
837 if (0 != strncmp (address, 835 if (0 != strncmp(address,
838 COMMUNICATOR_ADDRESS_PREFIX "-", 836 COMMUNICATOR_ADDRESS_PREFIX "-",
839 strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) 837 strlen(COMMUNICATOR_ADDRESS_PREFIX "-")))
840 { 838 {
841 GNUNET_break_op (0); 839 GNUNET_break_op(0);
842 return GNUNET_SYSERR; 840 return GNUNET_SYSERR;
843 } 841 }
844 path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")]; 842 path = &address[strlen(COMMUNICATOR_ADDRESS_PREFIX "-")];
845 un = unix_address_to_sockaddr (path, &un_len); 843 un = unix_address_to_sockaddr(path, &un_len);
846 queue = lookup_queue (peer, un, un_len); 844 queue = lookup_queue(peer, un, un_len);
847 if (NULL != queue) 845 if (NULL != queue)
848 { 846 {
849 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 847 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
850 "Address `%s' for %s ignored, queue exists\n", 848 "Address `%s' for %s ignored, queue exists\n",
851 path, 849 path,
852 GNUNET_i2s (peer)); 850 GNUNET_i2s(peer));
853 GNUNET_free (un); 851 GNUNET_free(un);
854 return GNUNET_OK; 852 return GNUNET_OK;
855 } 853 }
856 queue = setup_queue (peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len); 854 queue = setup_queue(peer, GNUNET_TRANSPORT_CS_OUTBOUND, un, un_len);
857 GNUNET_free (un); 855 GNUNET_free(un);
858 if (NULL == queue) 856 if (NULL == queue)
859 { 857 {
860 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 858 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
861 "Failed to setup queue to %s at `%s'\n", 859 "Failed to setup queue to %s at `%s'\n",
862 GNUNET_i2s (peer), 860 GNUNET_i2s(peer),
863 path); 861 path);
864 return GNUNET_NO; 862 return GNUNET_NO;
865 } 863 }
866 return GNUNET_OK; 864 return GNUNET_OK;
867} 865}
868 866
@@ -876,15 +874,15 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
876 * @return #GNUNET_OK to continue to iterate 874 * @return #GNUNET_OK to continue to iterate
877 */ 875 */
878static int 876static int
879get_queue_delete_it (void *cls, 877get_queue_delete_it(void *cls,
880 const struct GNUNET_PeerIdentity *target, 878 const struct GNUNET_PeerIdentity *target,
881 void *value) 879 void *value)
882{ 880{
883 struct Queue *queue = value; 881 struct Queue *queue = value;
884 882
885 (void) cls; 883 (void)cls;
886 (void) target; 884 (void)target;
887 queue_destroy (queue); 885 queue_destroy(queue);
888 return GNUNET_OK; 886 return GNUNET_OK;
889} 887}
890 888
@@ -895,40 +893,40 @@ get_queue_delete_it (void *cls,
895 * @param cls NULL (always) 893 * @param cls NULL (always)
896 */ 894 */
897static void 895static void
898do_shutdown (void *cls) 896do_shutdown(void *cls)
899{ 897{
900 if (NULL != read_task) 898 if (NULL != read_task)
901 { 899 {
902 GNUNET_SCHEDULER_cancel (read_task); 900 GNUNET_SCHEDULER_cancel(read_task);
903 read_task = NULL; 901 read_task = NULL;
904 } 902 }
905 if (NULL != write_task) 903 if (NULL != write_task)
906 { 904 {
907 GNUNET_SCHEDULER_cancel (write_task); 905 GNUNET_SCHEDULER_cancel(write_task);
908 write_task = NULL; 906 write_task = NULL;
909 } 907 }
910 if (NULL != unix_sock) 908 if (NULL != unix_sock)
911 { 909 {
912 GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_close (unix_sock)); 910 GNUNET_break(GNUNET_OK == GNUNET_NETWORK_socket_close(unix_sock));
913 unix_sock = NULL; 911 unix_sock = NULL;
914 } 912 }
915 GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); 913 GNUNET_CONTAINER_multipeermap_iterate(queue_map, &get_queue_delete_it, NULL);
916 GNUNET_CONTAINER_multipeermap_destroy (queue_map); 914 GNUNET_CONTAINER_multipeermap_destroy(queue_map);
917 if (NULL != ai) 915 if (NULL != ai)
918 { 916 {
919 GNUNET_TRANSPORT_communicator_address_remove (ai); 917 GNUNET_TRANSPORT_communicator_address_remove(ai);
920 ai = NULL; 918 ai = NULL;
921 } 919 }
922 if (NULL != ch) 920 if (NULL != ch)
923 { 921 {
924 GNUNET_TRANSPORT_communicator_disconnect (ch); 922 GNUNET_TRANSPORT_communicator_disconnect(ch);
925 ch = NULL; 923 ch = NULL;
926 } 924 }
927 if (NULL != stats) 925 if (NULL != stats)
928 { 926 {
929 GNUNET_STATISTICS_destroy (stats, GNUNET_NO); 927 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
930 stats = NULL; 928 stats = NULL;
931 } 929 }
932} 930}
933 931
934 932
@@ -944,14 +942,14 @@ do_shutdown (void *cls)
944 * @param msg payload 942 * @param msg payload
945 */ 943 */
946static void 944static void
947enc_notify_cb (void *cls, 945enc_notify_cb(void *cls,
948 const struct GNUNET_PeerIdentity *sender, 946 const struct GNUNET_PeerIdentity *sender,
949 const struct GNUNET_MessageHeader *msg) 947 const struct GNUNET_MessageHeader *msg)
950{ 948{
951 (void) cls; 949 (void)cls;
952 (void) sender; 950 (void)sender;
953 (void) msg; 951 (void)msg;
954 GNUNET_break_op (0); 952 GNUNET_break_op(0);
955} 953}
956 954
957 955
@@ -964,109 +962,110 @@ enc_notify_cb (void *cls,
964 * @param cfg configuration 962 * @param cfg configuration
965 */ 963 */
966static void 964static void
967run (void *cls, 965run(void *cls,
968 char *const *args, 966 char *const *args,
969 const char *cfgfile, 967 const char *cfgfile,
970 const struct GNUNET_CONFIGURATION_Handle *cfg) 968 const struct GNUNET_CONFIGURATION_Handle *cfg)
971{ 969{
972 char *unix_socket_path; 970 char *unix_socket_path;
973 struct sockaddr_un *un; 971 struct sockaddr_un *un;
974 socklen_t un_len; 972 socklen_t un_len;
975 char *my_addr; 973 char *my_addr;
976 (void) cls; 974
975 (void)cls;
977 976
978 if (GNUNET_OK != 977 if (GNUNET_OK !=
979 GNUNET_CONFIGURATION_get_value_filename (cfg, 978 GNUNET_CONFIGURATION_get_value_filename(cfg,
980 COMMUNICATOR_CONFIG_SECTION, 979 COMMUNICATOR_CONFIG_SECTION,
981 "UNIXPATH", 980 "UNIXPATH",
982 &unix_socket_path)) 981 &unix_socket_path))
983 { 982 {
984 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 983 GNUNET_log_config_missing(GNUNET_ERROR_TYPE_ERROR,
985 COMMUNICATOR_CONFIG_SECTION, 984 COMMUNICATOR_CONFIG_SECTION,
986 "UNIXPATH"); 985 "UNIXPATH");
987 return; 986 return;
988 } 987 }
989 if (GNUNET_OK != 988 if (GNUNET_OK !=
990 GNUNET_CONFIGURATION_get_value_number (cfg, 989 GNUNET_CONFIGURATION_get_value_number(cfg,
991 COMMUNICATOR_CONFIG_SECTION, 990 COMMUNICATOR_CONFIG_SECTION,
992 "MAX_QUEUE_LENGTH", 991 "MAX_QUEUE_LENGTH",
993 &max_queue_length)) 992 &max_queue_length))
994 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH; 993 max_queue_length = DEFAULT_MAX_QUEUE_LENGTH;
995 994
996 un = unix_address_to_sockaddr (unix_socket_path, &un_len); 995 un = unix_address_to_sockaddr(unix_socket_path, &un_len);
997 if (NULL == un) 996 if (NULL == un)
998 { 997 {
999 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 998 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1000 "Failed to setup UNIX domain socket address with path `%s'\n", 999 "Failed to setup UNIX domain socket address with path `%s'\n",
1001 unix_socket_path); 1000 unix_socket_path);
1002 GNUNET_free (unix_socket_path); 1001 GNUNET_free(unix_socket_path);
1003 return; 1002 return;
1004 } 1003 }
1005 unix_sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_DGRAM, 0); 1004 unix_sock = GNUNET_NETWORK_socket_create(AF_UNIX, SOCK_DGRAM, 0);
1006 if (NULL == unix_sock) 1005 if (NULL == unix_sock)
1007 { 1006 {
1008 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); 1007 GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "socket");
1009 GNUNET_free (un); 1008 GNUNET_free(un);
1010 GNUNET_free (unix_socket_path); 1009 GNUNET_free(unix_socket_path);
1011 return; 1010 return;
1012 } 1011 }
1013 if (('\0' != un->sun_path[0]) && 1012 if (('\0' != un->sun_path[0]) &&
1014 (GNUNET_OK != GNUNET_DISK_directory_create_for_file (un->sun_path))) 1013 (GNUNET_OK != GNUNET_DISK_directory_create_for_file(un->sun_path)))
1015 { 1014 {
1016 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1015 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
1017 _ ("Cannot create path to `%s'\n"), 1016 _("Cannot create path to `%s'\n"),
1018 un->sun_path); 1017 un->sun_path);
1019 GNUNET_NETWORK_socket_close (unix_sock); 1018 GNUNET_NETWORK_socket_close(unix_sock);
1020 unix_sock = NULL; 1019 unix_sock = NULL;
1021 GNUNET_free (un); 1020 GNUNET_free(un);
1022 GNUNET_free (unix_socket_path); 1021 GNUNET_free(unix_socket_path);
1023 return; 1022 return;
1024 } 1023 }
1025 if (GNUNET_OK != GNUNET_NETWORK_socket_bind (unix_sock, 1024 if (GNUNET_OK != GNUNET_NETWORK_socket_bind(unix_sock,
1026 (const struct sockaddr *) un, 1025 (const struct sockaddr *)un,
1027 un_len)) 1026 un_len))
1028 { 1027 {
1029 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path); 1028 GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, "bind", un->sun_path);
1030 GNUNET_NETWORK_socket_close (unix_sock); 1029 GNUNET_NETWORK_socket_close(unix_sock);
1031 unix_sock = NULL; 1030 unix_sock = NULL;
1032 GNUNET_free (un); 1031 GNUNET_free(un);
1033 GNUNET_free (unix_socket_path); 1032 GNUNET_free(unix_socket_path);
1034 return; 1033 return;
1035 } 1034 }
1036 GNUNET_free (un); 1035 GNUNET_free(un);
1037 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path); 1036 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Bound to `%s'\n", unix_socket_path);
1038 stats = GNUNET_STATISTICS_create ("C-UNIX", cfg); 1037 stats = GNUNET_STATISTICS_create("C-UNIX", cfg);
1039 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 1038 GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL);
1040 read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 1039 read_task = GNUNET_SCHEDULER_add_read_net(GNUNET_TIME_UNIT_FOREVER_REL,
1041 unix_sock, 1040 unix_sock,
1042 &select_read_cb, 1041 &select_read_cb,
1042 NULL);
1043 queue_map = GNUNET_CONTAINER_multipeermap_create(10, GNUNET_NO);
1044 ch = GNUNET_TRANSPORT_communicator_connect(cfg,
1045 COMMUNICATOR_CONFIG_SECTION,
1046 COMMUNICATOR_ADDRESS_PREFIX,
1047 GNUNET_TRANSPORT_CC_RELIABLE,
1048 &mq_init,
1049 NULL,
1050 &enc_notify_cb,
1043 NULL); 1051 NULL);
1044 queue_map = GNUNET_CONTAINER_multipeermap_create (10, GNUNET_NO);
1045 ch = GNUNET_TRANSPORT_communicator_connect (cfg,
1046 COMMUNICATOR_CONFIG_SECTION,
1047 COMMUNICATOR_ADDRESS_PREFIX,
1048 GNUNET_TRANSPORT_CC_RELIABLE,
1049 &mq_init,
1050 NULL,
1051 &enc_notify_cb,
1052 NULL);
1053 if (NULL == ch) 1052 if (NULL == ch)
1054 { 1053 {
1055 GNUNET_break (0); 1054 GNUNET_break(0);
1056 GNUNET_SCHEDULER_shutdown (); 1055 GNUNET_SCHEDULER_shutdown();
1057 GNUNET_free (unix_socket_path); 1056 GNUNET_free(unix_socket_path);
1058 return; 1057 return;
1059 } 1058 }
1060 GNUNET_asprintf (&my_addr, 1059 GNUNET_asprintf(&my_addr,
1061 "%s-%s", 1060 "%s-%s",
1062 COMMUNICATOR_ADDRESS_PREFIX, 1061 COMMUNICATOR_ADDRESS_PREFIX,
1063 unix_socket_path); 1062 unix_socket_path);
1064 GNUNET_free (unix_socket_path); 1063 GNUNET_free(unix_socket_path);
1065 ai = GNUNET_TRANSPORT_communicator_address_add (ch, 1064 ai = GNUNET_TRANSPORT_communicator_address_add(ch,
1066 my_addr, 1065 my_addr,
1067 GNUNET_NT_LOOPBACK, 1066 GNUNET_NT_LOOPBACK,
1068 GNUNET_TIME_UNIT_FOREVER_REL); 1067 GNUNET_TIME_UNIT_FOREVER_REL);
1069 GNUNET_free (my_addr); 1068 GNUNET_free(my_addr);
1070} 1069}
1071 1070
1072 1071
@@ -1078,26 +1077,27 @@ run (void *cls,
1078 * @return 0 ok, 1 on error 1077 * @return 0 ok, 1 on error
1079 */ 1078 */
1080int 1079int
1081main (int argc, char *const *argv) 1080main(int argc, char *const *argv)
1082{ 1081{
1083 static const struct GNUNET_GETOPT_CommandLineOption options[] = { 1082 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
1084 GNUNET_GETOPT_OPTION_END}; 1083 GNUNET_GETOPT_OPTION_END
1084 };
1085 int ret; 1085 int ret;
1086 1086
1087 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 1087 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv))
1088 return 2; 1088 return 2;
1089 1089
1090 ret = (GNUNET_OK == 1090 ret = (GNUNET_OK ==
1091 GNUNET_PROGRAM_run (argc, 1091 GNUNET_PROGRAM_run(argc,
1092 argv, 1092 argv,
1093 "gnunet-communicator-unix", 1093 "gnunet-communicator-unix",
1094 _ ("GNUnet UNIX domain socket communicator"), 1094 _("GNUnet UNIX domain socket communicator"),
1095 options, 1095 options,
1096 &run, 1096 &run,
1097 NULL)) 1097 NULL))
1098 ? 0 1098 ? 0
1099 : 1; 1099 : 1;
1100 GNUNET_free ((void *) argv); 1100 GNUNET_free((void *)argv);
1101 return ret; 1101 return ret;
1102} 1102}
1103 1103
@@ -1108,11 +1108,11 @@ main (int argc, char *const *argv)
1108/** 1108/**
1109 * MINIMIZE heap size (way below 128k) since this process doesn't need much. 1109 * MINIMIZE heap size (way below 128k) since this process doesn't need much.
1110 */ 1110 */
1111void __attribute__ ((constructor)) GNUNET_ARM_memory_init () 1111void __attribute__ ((constructor)) GNUNET_ARM_memory_init()
1112{ 1112{
1113 mallopt (M_TRIM_THRESHOLD, 4 * 1024); 1113 mallopt(M_TRIM_THRESHOLD, 4 * 1024);
1114 mallopt (M_TOP_PAD, 1 * 1024); 1114 mallopt(M_TOP_PAD, 1 * 1024);
1115 malloc_trim (0); 1115 malloc_trim(0);
1116} 1116}
1117#endif 1117#endif
1118 1118