diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-12-06 20:07:08 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-12-06 20:07:08 +0000 |
commit | 5629c08d1de8cbab4ed1b96c090edde48649f2ef (patch) | |
tree | 73d0bfaf3fc9571fbb1848052b2c92f079c2f45a | |
parent | adf79de3a5f8f88651d4564c7565187c45c50891 (diff) | |
download | gnunet-5629c08d1de8cbab4ed1b96c090edde48649f2ef.tar.gz gnunet-5629c08d1de8cbab4ed1b96c090edde48649f2ef.zip |
eliminating last dependency on util code from wlan helper by inlining
-rw-r--r-- | src/include/gnunet_common.h | 6 | ||||
-rw-r--r-- | src/include/gnunet_network_lib.h | 2 | ||||
-rw-r--r-- | src/include/gnunet_server_lib.h | 2 | ||||
-rw-r--r-- | src/transport/Makefile.am | 2 | ||||
-rw-r--r-- | src/transport/gnunet-transport-wlan-helper.c | 302 | ||||
-rw-r--r-- | src/util/pseudonym.c | 7 |
6 files changed, 308 insertions, 13 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 167187c23..f57c18cb7 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h | |||
@@ -52,12 +52,6 @@ | |||
52 | #define GNUNET_UTIL_VERSION 0x00090000 | 52 | #define GNUNET_UTIL_VERSION 0x00090000 |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Name used for "services" that are actually command-line | ||
56 | * programs invoked by the end user. | ||
57 | */ | ||
58 | #define GNUNET_CLIENT_SERVICE_NAME "client" | ||
59 | |||
60 | /** | ||
61 | * Named constants for return values. The following | 55 | * Named constants for return values. The following |
62 | * invariants hold: "GNUNET_NO == 0" (to allow "if (GNUNET_NO)") | 56 | * invariants hold: "GNUNET_NO == 0" (to allow "if (GNUNET_NO)") |
63 | * "GNUNET_OK != GNUNET_SYSERR", "GNUNET_OK != GNUNET_NO", "GNUNET_NO != GNUNET_SYSERR" | 57 | * "GNUNET_OK != GNUNET_SYSERR", "GNUNET_OK != GNUNET_NO", "GNUNET_NO != GNUNET_SYSERR" |
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h index 67ff11781..a14d5f0bb 100644 --- a/src/include/gnunet_network_lib.h +++ b/src/include/gnunet_network_lib.h | |||
@@ -89,7 +89,6 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
89 | socklen_t * address_len); | 89 | socklen_t * address_len); |
90 | 90 | ||
91 | 91 | ||
92 | #ifdef MINGW | ||
93 | /** | 92 | /** |
94 | * Box a native socket (and check that it is a socket). | 93 | * Box a native socket (and check that it is a socket). |
95 | * | 94 | * |
@@ -98,7 +97,6 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
98 | */ | 97 | */ |
99 | struct GNUNET_NETWORK_Handle * | 98 | struct GNUNET_NETWORK_Handle * |
100 | GNUNET_NETWORK_socket_box_native (SOCKTYPE fd); | 99 | GNUNET_NETWORK_socket_box_native (SOCKTYPE fd); |
101 | #endif | ||
102 | 100 | ||
103 | 101 | ||
104 | /** | 102 | /** |
diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h index c39349c92..2856fd838 100644 --- a/src/include/gnunet_server_lib.h +++ b/src/include/gnunet_server_lib.h | |||
@@ -46,7 +46,7 @@ extern "C" | |||
46 | #define GNUNET_SERVER_MAX_MESSAGE_SIZE 65536 | 46 | #define GNUNET_SERVER_MAX_MESSAGE_SIZE 65536 |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * Largest supported message. | 49 | * Smallest supported message. |
50 | */ | 50 | */ |
51 | #define GNUNET_SERVER_MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader) | 51 | #define GNUNET_SERVER_MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader) |
52 | 52 | ||
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index 92f3ac8c8..6901f6b4d 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -109,8 +109,6 @@ gnunet_transport_certificate_creation_LDADD = \ | |||
109 | 109 | ||
110 | gnunet_transport_wlan_helper_SOURCES = \ | 110 | gnunet_transport_wlan_helper_SOURCES = \ |
111 | gnunet-transport-wlan-helper.c | 111 | gnunet-transport-wlan-helper.c |
112 | gnunet_transport_wlan_helper_LDADD = \ | ||
113 | $(top_builddir)/src/util/libgnunetutil.la | ||
114 | 112 | ||
115 | gnunet_transport_wlan_helper_dummy_SOURCES = \ | 113 | gnunet_transport_wlan_helper_dummy_SOURCES = \ |
116 | gnunet-transport-wlan-helper-dummy.c | 114 | gnunet-transport-wlan-helper-dummy.c |
diff --git a/src/transport/gnunet-transport-wlan-helper.c b/src/transport/gnunet-transport-wlan-helper.c index f4798c2d9..28e6b402f 100644 --- a/src/transport/gnunet-transport-wlan-helper.c +++ b/src/transport/gnunet-transport-wlan-helper.c | |||
@@ -100,7 +100,6 @@ | |||
100 | #include <stdint.h> | 100 | #include <stdint.h> |
101 | 101 | ||
102 | #include "gnunet_protocols.h" | 102 | #include "gnunet_protocols.h" |
103 | #include "gnunet_server_lib.h" | ||
104 | #include "plugin_transport_wlan.h" | 103 | #include "plugin_transport_wlan.h" |
105 | 104 | ||
106 | #define ARPHRD_IEEE80211 801 | 105 | #define ARPHRD_IEEE80211 801 |
@@ -446,6 +445,305 @@ struct ieee80211_radiotap_iterator | |||
446 | }; | 445 | }; |
447 | 446 | ||
448 | 447 | ||
448 | |||
449 | /* specialized version of server_mst.c begins here */ | ||
450 | |||
451 | #define ALIGN_FACTOR 8 | ||
452 | |||
453 | /** | ||
454 | * Smallest supported message. | ||
455 | */ | ||
456 | #define GNUNET_SERVER_MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader) | ||
457 | |||
458 | |||
459 | /** | ||
460 | * Functions with this signature are called whenever a | ||
461 | * complete message is received by the tokenizer. | ||
462 | * | ||
463 | * @param cls closure | ||
464 | * @param client identification of the client | ||
465 | * @param message the actual message | ||
466 | */ | ||
467 | typedef void (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, void *client, | ||
468 | const struct | ||
469 | GNUNET_MessageHeader * | ||
470 | message); | ||
471 | |||
472 | /** | ||
473 | * Handle to a message stream tokenizer. | ||
474 | */ | ||
475 | struct GNUNET_SERVER_MessageStreamTokenizer | ||
476 | { | ||
477 | |||
478 | /** | ||
479 | * Function to call on completed messages. | ||
480 | */ | ||
481 | GNUNET_SERVER_MessageTokenizerCallback cb; | ||
482 | |||
483 | /** | ||
484 | * Closure for cb. | ||
485 | */ | ||
486 | void *cb_cls; | ||
487 | |||
488 | /** | ||
489 | * Size of the buffer (starting at 'hdr'). | ||
490 | */ | ||
491 | size_t curr_buf; | ||
492 | |||
493 | /** | ||
494 | * How many bytes in buffer have we already processed? | ||
495 | */ | ||
496 | size_t off; | ||
497 | |||
498 | /** | ||
499 | * How many bytes in buffer are valid right now? | ||
500 | */ | ||
501 | size_t pos; | ||
502 | |||
503 | /** | ||
504 | * Beginning of the buffer. Typed like this to force alignment. | ||
505 | */ | ||
506 | struct GNUNET_MessageHeader *hdr; | ||
507 | |||
508 | }; | ||
509 | |||
510 | |||
511 | |||
512 | /** | ||
513 | * Create a message stream tokenizer. | ||
514 | * | ||
515 | * @param cb function to call on completed messages | ||
516 | * @param cb_cls closure for cb | ||
517 | * @return handle to tokenizer | ||
518 | */ | ||
519 | struct GNUNET_SERVER_MessageStreamTokenizer * | ||
520 | GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, | ||
521 | void *cb_cls) | ||
522 | { | ||
523 | struct GNUNET_SERVER_MessageStreamTokenizer *ret; | ||
524 | |||
525 | ret = malloc (sizeof (struct GNUNET_SERVER_MessageStreamTokenizer)); | ||
526 | if (NULL == ret) | ||
527 | exit (1); | ||
528 | ret->hdr = malloc (GNUNET_SERVER_MIN_BUFFER_SIZE); | ||
529 | if (NULL == ret->hdr) | ||
530 | exit (2); | ||
531 | ret->curr_buf = GNUNET_SERVER_MIN_BUFFER_SIZE; | ||
532 | ret->cb = cb; | ||
533 | ret->cb_cls = cb_cls; | ||
534 | return ret; | ||
535 | } | ||
536 | |||
537 | |||
538 | #define GNUNET_MIN(a,b) (((a) < (b)) ? (a) : (b)) | ||
539 | |||
540 | /** | ||
541 | * Named constants for return values. The following | ||
542 | * invariants hold: "GNUNET_NO == 0" (to allow "if (GNUNET_NO)") | ||
543 | * "GNUNET_OK != GNUNET_SYSERR", "GNUNET_OK != GNUNET_NO", "GNUNET_NO != GNUNET_SYSERR" | ||
544 | * and finally "GNUNET_YES != GNUNET_NO". | ||
545 | */ | ||
546 | #define GNUNET_OK 1 | ||
547 | #define GNUNET_SYSERR -1 | ||
548 | #define GNUNET_YES 1 | ||
549 | #define GNUNET_NO 0 | ||
550 | |||
551 | |||
552 | /** | ||
553 | * Add incoming data to the receive buffer and call the | ||
554 | * callback for all complete messages. | ||
555 | * | ||
556 | * @param mst tokenizer to use | ||
557 | * @param client_identity ID of client for which this is a buffer | ||
558 | * @param buf input data to add | ||
559 | * @param size number of bytes in buf | ||
560 | * @param purge should any excess bytes in the buffer be discarded | ||
561 | * (i.e. for packet-based services like UDP) | ||
562 | * @param one_shot only call callback once, keep rest of message in buffer | ||
563 | * @return GNUNET_OK if we are done processing (need more data) | ||
564 | * GNUNET_NO if one_shot was set and we have another message ready | ||
565 | * GNUNET_SYSERR if the data stream is corrupt | ||
566 | */ | ||
567 | int | ||
568 | GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, | ||
569 | void *client_identity, const char *buf, size_t size, | ||
570 | int purge, int one_shot) | ||
571 | { | ||
572 | const struct GNUNET_MessageHeader *hdr; | ||
573 | size_t delta; | ||
574 | uint16_t want; | ||
575 | char *ibuf; | ||
576 | int need_align; | ||
577 | unsigned long offset; | ||
578 | int ret; | ||
579 | |||
580 | ret = GNUNET_OK; | ||
581 | ibuf = (char *) mst->hdr; | ||
582 | while (mst->pos > 0) | ||
583 | { | ||
584 | do_align: | ||
585 | if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) || | ||
586 | (0 != (mst->off % ALIGN_FACTOR))) | ||
587 | { | ||
588 | /* need to align or need more space */ | ||
589 | mst->pos -= mst->off; | ||
590 | memmove (ibuf, &ibuf[mst->off], mst->pos); | ||
591 | mst->off = 0; | ||
592 | } | ||
593 | if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) | ||
594 | { | ||
595 | delta = | ||
596 | GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) - | ||
597 | (mst->pos - mst->off), size); | ||
598 | memcpy (&ibuf[mst->pos], buf, delta); | ||
599 | mst->pos += delta; | ||
600 | buf += delta; | ||
601 | size -= delta; | ||
602 | } | ||
603 | if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) | ||
604 | { | ||
605 | if (purge) | ||
606 | { | ||
607 | mst->off = 0; | ||
608 | mst->pos = 0; | ||
609 | } | ||
610 | return GNUNET_OK; | ||
611 | } | ||
612 | hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; | ||
613 | want = ntohs (hdr->size); | ||
614 | if (want < sizeof (struct GNUNET_MessageHeader)) | ||
615 | { | ||
616 | // GNUNET_break_op (0); | ||
617 | return GNUNET_SYSERR; | ||
618 | } | ||
619 | if (mst->curr_buf - mst->off < want) | ||
620 | { | ||
621 | /* need more space */ | ||
622 | mst->pos -= mst->off; | ||
623 | memmove (ibuf, &ibuf[mst->off], mst->pos); | ||
624 | mst->off = 0; | ||
625 | } | ||
626 | if (want > mst->curr_buf) | ||
627 | { | ||
628 | mst->hdr = realloc (mst->hdr, want); | ||
629 | if (NULL == mst->hdr) | ||
630 | exit (3); | ||
631 | ibuf = (char *) mst->hdr; | ||
632 | mst->curr_buf = want; | ||
633 | } | ||
634 | hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; | ||
635 | if (mst->pos - mst->off < want) | ||
636 | { | ||
637 | delta = GNUNET_MIN (want - (mst->pos - mst->off), size); | ||
638 | memcpy (&ibuf[mst->pos], buf, delta); | ||
639 | mst->pos += delta; | ||
640 | buf += delta; | ||
641 | size -= delta; | ||
642 | } | ||
643 | if (mst->pos - mst->off < want) | ||
644 | { | ||
645 | if (purge) | ||
646 | { | ||
647 | mst->off = 0; | ||
648 | mst->pos = 0; | ||
649 | } | ||
650 | return GNUNET_OK; | ||
651 | } | ||
652 | if (one_shot == GNUNET_SYSERR) | ||
653 | { | ||
654 | /* cannot call callback again, but return value saying that | ||
655 | * we have another full message in the buffer */ | ||
656 | ret = GNUNET_NO; | ||
657 | goto copy; | ||
658 | } | ||
659 | if (one_shot == GNUNET_YES) | ||
660 | one_shot = GNUNET_SYSERR; | ||
661 | mst->cb (mst->cb_cls, client_identity, hdr); | ||
662 | mst->off += want; | ||
663 | if (mst->off == mst->pos) | ||
664 | { | ||
665 | /* reset to beginning of buffer, it's free right now! */ | ||
666 | mst->off = 0; | ||
667 | mst->pos = 0; | ||
668 | } | ||
669 | } | ||
670 | while (size > 0) | ||
671 | { | ||
672 | if (size < sizeof (struct GNUNET_MessageHeader)) | ||
673 | break; | ||
674 | offset = (unsigned long) buf; | ||
675 | need_align = (0 != offset % ALIGN_FACTOR) ? GNUNET_YES : GNUNET_NO; | ||
676 | if (GNUNET_NO == need_align) | ||
677 | { | ||
678 | /* can try to do zero-copy and process directly from original buffer */ | ||
679 | hdr = (const struct GNUNET_MessageHeader *) buf; | ||
680 | want = ntohs (hdr->size); | ||
681 | if (want < sizeof (struct GNUNET_MessageHeader)) | ||
682 | { | ||
683 | // GNUNET_break_op (0); | ||
684 | mst->off = 0; | ||
685 | return GNUNET_SYSERR; | ||
686 | } | ||
687 | if (size < want) | ||
688 | break; /* or not, buffer incomplete, so copy to private buffer... */ | ||
689 | if (one_shot == GNUNET_SYSERR) | ||
690 | { | ||
691 | /* cannot call callback again, but return value saying that | ||
692 | * we have another full message in the buffer */ | ||
693 | ret = GNUNET_NO; | ||
694 | goto copy; | ||
695 | } | ||
696 | if (one_shot == GNUNET_YES) | ||
697 | one_shot = GNUNET_SYSERR; | ||
698 | mst->cb (mst->cb_cls, client_identity, hdr); | ||
699 | buf += want; | ||
700 | size -= want; | ||
701 | } | ||
702 | else | ||
703 | { | ||
704 | /* need to copy to private buffer to align; | ||
705 | * yes, we go a bit more spagetti than usual here */ | ||
706 | goto do_align; | ||
707 | } | ||
708 | } | ||
709 | copy: | ||
710 | if ((size > 0) && (!purge)) | ||
711 | { | ||
712 | if (size + mst->pos > mst->curr_buf) | ||
713 | { | ||
714 | mst->hdr = realloc (mst->hdr, size + mst->pos); | ||
715 | if (NULL == mst->hdr) | ||
716 | exit (4); | ||
717 | ibuf = (char *) mst->hdr; | ||
718 | mst->curr_buf = size + mst->pos; | ||
719 | } | ||
720 | // GNUNET_assert (mst->pos + size <= mst->curr_buf); | ||
721 | memcpy (&ibuf[mst->pos], buf, size); | ||
722 | mst->pos += size; | ||
723 | } | ||
724 | if (purge) | ||
725 | mst->off = 0; | ||
726 | return ret; | ||
727 | } | ||
728 | |||
729 | |||
730 | /** | ||
731 | * Destroys a tokenizer. | ||
732 | * | ||
733 | * @param mst tokenizer to destroy | ||
734 | */ | ||
735 | void | ||
736 | GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst) | ||
737 | { | ||
738 | free (mst->hdr); | ||
739 | free (mst); | ||
740 | } | ||
741 | |||
742 | /* end of server_mst.c copy */ | ||
743 | |||
744 | |||
745 | |||
746 | |||
449 | /** | 747 | /** |
450 | * Radiotap header iteration | 748 | * Radiotap header iteration |
451 | * | 749 | * |
@@ -1352,7 +1650,7 @@ main (int argc, char *argv[]) | |||
1352 | 1650 | ||
1353 | dev.write_pout.size = 0; | 1651 | dev.write_pout.size = 0; |
1354 | dev.write_pout.pos = 0; | 1652 | dev.write_pout.pos = 0; |
1355 | stdin_mst = GNUNET_SERVER_mst_create (&stdin_send_hw, &dev); | 1653 | stdin_mst = GNUNET_SERVER_mst_create (&stdin_send_hw, &dev); |
1356 | 1654 | ||
1357 | /* send mac to STDOUT first */ | 1655 | /* send mac to STDOUT first */ |
1358 | write_std.pos = 0; | 1656 | write_std.pos = 0; |
diff --git a/src/util/pseudonym.c b/src/util/pseudonym.c index 2a736bc46..356a83b6b 100644 --- a/src/util/pseudonym.c +++ b/src/util/pseudonym.c | |||
@@ -47,6 +47,13 @@ | |||
47 | 47 | ||
48 | 48 | ||
49 | /** | 49 | /** |
50 | * Configuration section we use. | ||
51 | */ | ||
52 | #define GNUNET_CLIENT_SERVICE_NAME "client" | ||
53 | |||
54 | |||
55 | |||
56 | /** | ||
50 | * Registered callbacks for discovery of pseudonyms. | 57 | * Registered callbacks for discovery of pseudonyms. |
51 | */ | 58 | */ |
52 | struct DiscoveryCallback | 59 | struct DiscoveryCallback |