diff options
57 files changed, 1375 insertions, 3873 deletions
diff --git a/contrib/.gitignore b/contrib/.gitignore index a6c776023..304706d7e 100644 --- a/contrib/.gitignore +++ b/contrib/.gitignore | |||
@@ -6,3 +6,4 @@ timeout_watchdog | |||
6 | gnunet_pyexpect.py | 6 | gnunet_pyexpect.py |
7 | gnunet_pyexpect.pyc | 7 | gnunet_pyexpect.pyc |
8 | pydiffer.pyc | 8 | pydiffer.pyc |
9 | test_gnunet_prefix | ||
diff --git a/po/POTFILES.in b/po/POTFILES.in index b0fae9dbe..c73881fef 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in | |||
@@ -402,6 +402,10 @@ src/transport/plugin_transport_udp_broadcasting.c | |||
402 | src/transport/plugin_transport_udp.c | 402 | src/transport/plugin_transport_udp.c |
403 | src/transport/plugin_transport_unix.c | 403 | src/transport/plugin_transport_unix.c |
404 | src/transport/plugin_transport_wlan.c | 404 | src/transport/plugin_transport_wlan.c |
405 | src/transport/tcp_connection_legacy.c | ||
406 | src/transport/tcp_server_legacy.c | ||
407 | src/transport/tcp_server_mst_legacy.c | ||
408 | src/transport/tcp_service_legacy.c | ||
405 | src/transport/transport_api_address_to_string.c | 409 | src/transport/transport_api_address_to_string.c |
406 | src/transport/transport_api_blacklist.c | 410 | src/transport/transport_api_blacklist.c |
407 | src/transport/transport_api_core.c | 411 | src/transport/transport_api_core.c |
@@ -425,7 +429,6 @@ src/util/common_endian.c | |||
425 | src/util/common_logging.c | 429 | src/util/common_logging.c |
426 | src/util/configuration.c | 430 | src/util/configuration.c |
427 | src/util/configuration_loader.c | 431 | src/util/configuration_loader.c |
428 | src/util/connection.c | ||
429 | src/util/container_bloomfilter.c | 432 | src/util/container_bloomfilter.c |
430 | src/util/container_heap.c | 433 | src/util/container_heap.c |
431 | src/util/container_meta_data.c | 434 | src/util/container_meta_data.c |
@@ -472,11 +475,9 @@ src/util/plugin.c | |||
472 | src/util/program.c | 475 | src/util/program.c |
473 | src/util/resolver_api.c | 476 | src/util/resolver_api.c |
474 | src/util/scheduler.c | 477 | src/util/scheduler.c |
475 | src/util/server.c | ||
476 | src/util/server_mst.c | 478 | src/util/server_mst.c |
477 | src/util/server_nc.c | 479 | src/util/server_nc.c |
478 | src/util/server_tc.c | 480 | src/util/server_tc.c |
479 | src/util/service.c | ||
480 | src/util/service_new.c | 481 | src/util/service_new.c |
481 | src/util/signal.c | 482 | src/util/signal.c |
482 | src/util/socks.c | 483 | src/util/socks.c |
diff --git a/src/cadet/Makefile.am b/src/cadet/Makefile.am index af1a6720c..ce30ebe46 100644 --- a/src/cadet/Makefile.am +++ b/src/cadet/Makefile.am | |||
@@ -69,7 +69,7 @@ gnunet_service_cadet_LDADD = \ | |||
69 | $(top_builddir)/src/hello/libgnunethello.la \ | 69 | $(top_builddir)/src/hello/libgnunethello.la \ |
70 | $(top_builddir)/src/block/libgnunetblock.la | 70 | $(top_builddir)/src/block/libgnunetblock.la |
71 | if LINUX | 71 | if LINUX |
72 | gnunet_service_cadet_new_LDFLAGS = -lrt | 72 | gnunet_service_cadet_LDFLAGS = -lrt |
73 | endif | 73 | endif |
74 | 74 | ||
75 | 75 | ||
diff --git a/src/consensus/consensus_protocol.h b/src/consensus/consensus_protocol.h index 320d460c7..f2933ed6f 100644 --- a/src/consensus/consensus_protocol.h +++ b/src/consensus/consensus_protocol.h | |||
@@ -109,7 +109,7 @@ struct ConsensusElement | |||
109 | /** | 109 | /** |
110 | * Is this a marker element? | 110 | * Is this a marker element? |
111 | */ | 111 | */ |
112 | uint8_t marker GNUNET_PACKED; | 112 | uint8_t marker; |
113 | 113 | ||
114 | /* rest: element data */ | 114 | /* rest: element data */ |
115 | }; | 115 | }; |
@@ -117,7 +117,7 @@ struct ConsensusElement | |||
117 | 117 | ||
118 | struct ConsensusSizeElement | 118 | struct ConsensusSizeElement |
119 | { | 119 | { |
120 | struct ConsensusElement ce GNUNET_PACKED; | 120 | struct ConsensusElement ce; |
121 | 121 | ||
122 | uint64_t size GNUNET_PACKED; | 122 | uint64_t size GNUNET_PACKED; |
123 | uint8_t sender_index; | 123 | uint8_t sender_index; |
@@ -125,7 +125,7 @@ struct ConsensusSizeElement | |||
125 | 125 | ||
126 | struct ConsensusStuffedElement | 126 | struct ConsensusStuffedElement |
127 | { | 127 | { |
128 | struct ConsensusElement ce GNUNET_PACKED; | 128 | struct ConsensusElement ce; |
129 | struct GNUNET_HashCode rand GNUNET_PACKED; | 129 | struct GNUNET_HashCode rand GNUNET_PACKED; |
130 | }; | 130 | }; |
131 | 131 | ||
diff --git a/src/conversation/gnunet-helper-audio-playback.c b/src/conversation/gnunet-helper-audio-playback.c index e965cb2aa..4344e1d41 100644 --- a/src/conversation/gnunet-helper-audio-playback.c +++ b/src/conversation/gnunet-helper-audio-playback.c | |||
@@ -549,7 +549,6 @@ ogg_demux_and_decode () | |||
549 | */ | 549 | */ |
550 | static int | 550 | static int |
551 | stdin_receiver (void *cls, | 551 | stdin_receiver (void *cls, |
552 | void *client, | ||
553 | const struct GNUNET_MessageHeader *msg) | 552 | const struct GNUNET_MessageHeader *msg) |
554 | { | 553 | { |
555 | struct AudioMessage *audio; | 554 | struct AudioMessage *audio; |
@@ -727,12 +726,14 @@ ogg_init () | |||
727 | ogg_sync_init (&oy); | 726 | ogg_sync_init (&oy); |
728 | } | 727 | } |
729 | 728 | ||
729 | |||
730 | static void | 730 | static void |
731 | drain_callback (pa_stream*s, int success, void *userdata) | 731 | drain_callback (pa_stream*s, int success, void *userdata) |
732 | { | 732 | { |
733 | pa_threaded_mainloop_signal (m, 0); | 733 | pa_threaded_mainloop_signal (m, 0); |
734 | } | 734 | } |
735 | 735 | ||
736 | |||
736 | /** | 737 | /** |
737 | * The main function for the playback helper. | 738 | * The main function for the playback helper. |
738 | * | 739 | * |
@@ -746,7 +747,7 @@ main (int argc, char *argv[]) | |||
746 | static unsigned long long toff; | 747 | static unsigned long long toff; |
747 | 748 | ||
748 | char readbuf[MAXLINE]; | 749 | char readbuf[MAXLINE]; |
749 | struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst; | 750 | struct GNUNET_MessageStreamTokenizer *stdin_mst; |
750 | char c; | 751 | char c; |
751 | ssize_t ret; | 752 | ssize_t ret; |
752 | #ifdef DEBUG_READ_PURE_OGG | 753 | #ifdef DEBUG_READ_PURE_OGG |
@@ -762,7 +763,7 @@ main (int argc, char *argv[]) | |||
762 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe"); | 763 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "pipe"); |
763 | return 1; | 764 | return 1; |
764 | } | 765 | } |
765 | stdin_mst = GNUNET_SERVER_mst_create (&stdin_receiver, NULL); | 766 | stdin_mst = GNUNET_MST_create (&stdin_receiver, NULL); |
766 | ogg_init (); | 767 | ogg_init (); |
767 | pa_init (); | 768 | pa_init (); |
768 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -802,11 +803,11 @@ main (int argc, char *argv[]) | |||
802 | } | 803 | } |
803 | else | 804 | else |
804 | #endif | 805 | #endif |
805 | GNUNET_SERVER_mst_receive (stdin_mst, NULL, | 806 | GNUNET_MST_from_buffer (stdin_mst, |
806 | readbuf, ret, | 807 | readbuf, ret, |
807 | GNUNET_NO, GNUNET_NO); | 808 | GNUNET_NO, GNUNET_NO); |
808 | } | 809 | } |
809 | GNUNET_SERVER_mst_destroy (stdin_mst); | 810 | GNUNET_MST_destroy (stdin_mst); |
810 | if (stream_out) | 811 | if (stream_out) |
811 | { | 812 | { |
812 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 813 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
diff --git a/src/conversation/microphone.c b/src/conversation/microphone.c index 94f52f8dc..7871433a3 100644 --- a/src/conversation/microphone.c +++ b/src/conversation/microphone.c | |||
@@ -64,13 +64,11 @@ struct Microphone | |||
64 | * Function to process the audio from the record helper | 64 | * Function to process the audio from the record helper |
65 | * | 65 | * |
66 | * @param cls clsoure with our `struct Microphone` | 66 | * @param cls clsoure with our `struct Microphone` |
67 | * @param client NULL | ||
68 | * @param msg the message from the helper | 67 | * @param msg the message from the helper |
69 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 68 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
70 | */ | 69 | */ |
71 | static int | 70 | static int |
72 | process_record_messages (void *cls, | 71 | process_record_messages (void *cls, |
73 | void *client, | ||
74 | const struct GNUNET_MessageHeader *msg) | 72 | const struct GNUNET_MessageHeader *msg) |
75 | { | 73 | { |
76 | struct Microphone *mic = cls; | 74 | struct Microphone *mic = cls; |
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c index 906898512..8a7cada5c 100644 --- a/src/core/gnunet-service-core_kx.c +++ b/src/core/gnunet-service-core_kx.c | |||
@@ -263,6 +263,11 @@ struct GSC_KeyExchangeInfo | |||
263 | struct GNUNET_MQ_Handle *mq; | 263 | struct GNUNET_MQ_Handle *mq; |
264 | 264 | ||
265 | /** | 265 | /** |
266 | * Our message stream tokenizer (for encrypted payload). | ||
267 | */ | ||
268 | struct GNUNET_MessageStreamTokenizer *mst; | ||
269 | |||
270 | /** | ||
266 | * PING message we transmit to the other peer. | 271 | * PING message we transmit to the other peer. |
267 | */ | 272 | */ |
268 | struct PingMessage ping; | 273 | struct PingMessage ping; |
@@ -370,11 +375,6 @@ static struct GNUNET_CRYPTO_EcdhePrivateKey *my_ephemeral_key; | |||
370 | static struct EphemeralKeyMessage current_ekm; | 375 | static struct EphemeralKeyMessage current_ekm; |
371 | 376 | ||
372 | /** | 377 | /** |
373 | * Our message stream tokenizer (for encrypted payload). | ||
374 | */ | ||
375 | static struct GNUNET_SERVER_MessageStreamTokenizer *mst; | ||
376 | |||
377 | /** | ||
378 | * DLL head. | 378 | * DLL head. |
379 | */ | 379 | */ |
380 | static struct GSC_KeyExchangeInfo *kx_head; | 380 | static struct GSC_KeyExchangeInfo *kx_head; |
@@ -702,6 +702,55 @@ setup_fresh_ping (struct GSC_KeyExchangeInfo *kx) | |||
702 | 702 | ||
703 | 703 | ||
704 | /** | 704 | /** |
705 | * Deliver P2P message to interested clients. Invokes send twice, | ||
706 | * once for clients that want the full message, and once for clients | ||
707 | * that only want the header | ||
708 | * | ||
709 | * @param cls the `struct GSC_KeyExchangeInfo` | ||
710 | * @param m the message | ||
711 | */ | ||
712 | static int | ||
713 | deliver_message (void *cls, | ||
714 | const struct GNUNET_MessageHeader *m) | ||
715 | { | ||
716 | struct GSC_KeyExchangeInfo *kx = cls; | ||
717 | |||
718 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
719 | "Decrypted message of type %d from %s\n", | ||
720 | ntohs (m->type), | ||
721 | GNUNET_i2s (kx->peer)); | ||
722 | if (GNUNET_CORE_KX_STATE_UP != kx->status) | ||
723 | { | ||
724 | GNUNET_STATISTICS_update (GSC_stats, | ||
725 | gettext_noop ("# PAYLOAD dropped (out of order)"), | ||
726 | 1, | ||
727 | GNUNET_NO); | ||
728 | return GNUNET_OK; | ||
729 | } | ||
730 | switch (ntohs (m->type)) | ||
731 | { | ||
732 | case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: | ||
733 | case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: | ||
734 | GSC_SESSIONS_set_typemap (kx->peer, m); | ||
735 | return GNUNET_OK; | ||
736 | case GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP: | ||
737 | GSC_SESSIONS_confirm_typemap (kx->peer, m); | ||
738 | return GNUNET_OK; | ||
739 | default: | ||
740 | GSC_CLIENTS_deliver_message (kx->peer, | ||
741 | m, | ||
742 | ntohs (m->size), | ||
743 | GNUNET_CORE_OPTION_SEND_FULL_INBOUND); | ||
744 | GSC_CLIENTS_deliver_message (kx->peer, | ||
745 | m, | ||
746 | sizeof (struct GNUNET_MessageHeader), | ||
747 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND); | ||
748 | } | ||
749 | return GNUNET_OK; | ||
750 | } | ||
751 | |||
752 | |||
753 | /** | ||
705 | * Function called by transport to notify us that | 754 | * Function called by transport to notify us that |
706 | * a peer connected to us (on the network level). | 755 | * a peer connected to us (on the network level). |
707 | * Starts the key exchange with the given peer. | 756 | * Starts the key exchange with the given peer. |
@@ -727,6 +776,8 @@ handle_transport_notify_connect (void *cls, | |||
727 | 1, | 776 | 1, |
728 | GNUNET_NO); | 777 | GNUNET_NO); |
729 | kx = GNUNET_new (struct GSC_KeyExchangeInfo); | 778 | kx = GNUNET_new (struct GSC_KeyExchangeInfo); |
779 | kx->mst = GNUNET_MST_create (&deliver_message, | ||
780 | kx); | ||
730 | kx->mq = mq; | 781 | kx->mq = mq; |
731 | kx->peer = pid; | 782 | kx->peer = pid; |
732 | kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; | 783 | kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; |
@@ -801,6 +852,7 @@ handle_transport_notify_disconnect (void *cls, | |||
801 | GNUNET_CONTAINER_DLL_remove (kx_head, | 852 | GNUNET_CONTAINER_DLL_remove (kx_head, |
802 | kx_tail, | 853 | kx_tail, |
803 | kx); | 854 | kx); |
855 | GNUNET_MST_destroy (kx->mst); | ||
804 | GNUNET_free (kx); | 856 | GNUNET_free (kx); |
805 | } | 857 | } |
806 | 858 | ||
@@ -1417,24 +1469,6 @@ GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx, | |||
1417 | 1469 | ||
1418 | 1470 | ||
1419 | /** | 1471 | /** |
1420 | * Closure for #deliver_message() | ||
1421 | */ | ||
1422 | struct DeliverMessageContext | ||
1423 | { | ||
1424 | |||
1425 | /** | ||
1426 | * Key exchange context. | ||
1427 | */ | ||
1428 | struct GSC_KeyExchangeInfo *kx; | ||
1429 | |||
1430 | /** | ||
1431 | * Sender of the message. | ||
1432 | */ | ||
1433 | const struct GNUNET_PeerIdentity *peer; | ||
1434 | }; | ||
1435 | |||
1436 | |||
1437 | /** | ||
1438 | * We received an encrypted message. Check that it is | 1472 | * We received an encrypted message. Check that it is |
1439 | * well-formed (size-wise). | 1473 | * well-formed (size-wise). |
1440 | * | 1474 | * |
@@ -1475,7 +1509,6 @@ handle_encrypted (void *cls, | |||
1475 | struct GNUNET_TIME_Absolute t; | 1509 | struct GNUNET_TIME_Absolute t; |
1476 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; | 1510 | struct GNUNET_CRYPTO_SymmetricInitializationVector iv; |
1477 | struct GNUNET_CRYPTO_AuthKey auth_key; | 1511 | struct GNUNET_CRYPTO_AuthKey auth_key; |
1478 | struct DeliverMessageContext dmc; | ||
1479 | uint16_t size = ntohs (m->header.size); | 1512 | uint16_t size = ntohs (m->header.size); |
1480 | char buf[size] GNUNET_ALIGN; | 1513 | char buf[size] GNUNET_ALIGN; |
1481 | 1514 | ||
@@ -1620,15 +1653,12 @@ handle_encrypted (void *cls, | |||
1620 | gettext_noop ("# bytes of payload decrypted"), | 1653 | gettext_noop ("# bytes of payload decrypted"), |
1621 | size - sizeof (struct EncryptedMessage), | 1654 | size - sizeof (struct EncryptedMessage), |
1622 | GNUNET_NO); | 1655 | GNUNET_NO); |
1623 | dmc.kx = kx; | ||
1624 | dmc.peer = kx->peer; | ||
1625 | if (GNUNET_OK != | 1656 | if (GNUNET_OK != |
1626 | GNUNET_SERVER_mst_receive (mst, | 1657 | GNUNET_MST_from_buffer (kx->mst, |
1627 | &dmc, | 1658 | &buf[sizeof (struct EncryptedMessage)], |
1628 | &buf[sizeof (struct EncryptedMessage)], | 1659 | size - sizeof (struct EncryptedMessage), |
1629 | size - sizeof (struct EncryptedMessage), | 1660 | GNUNET_YES, |
1630 | GNUNET_YES, | 1661 | GNUNET_NO)) |
1631 | GNUNET_NO)) | ||
1632 | GNUNET_break_op (0); | 1662 | GNUNET_break_op (0); |
1633 | } | 1663 | } |
1634 | 1664 | ||
@@ -1656,57 +1686,6 @@ handle_transport_notify_excess_bw (void *cls, | |||
1656 | 1686 | ||
1657 | 1687 | ||
1658 | /** | 1688 | /** |
1659 | * Deliver P2P message to interested clients. Invokes send twice, | ||
1660 | * once for clients that want the full message, and once for clients | ||
1661 | * that only want the header | ||
1662 | * | ||
1663 | * @param cls always NULL | ||
1664 | * @param client who sent us the message (struct GSC_KeyExchangeInfo) | ||
1665 | * @param m the message | ||
1666 | */ | ||
1667 | static int | ||
1668 | deliver_message (void *cls, | ||
1669 | void *client, | ||
1670 | const struct GNUNET_MessageHeader *m) | ||
1671 | { | ||
1672 | struct DeliverMessageContext *dmc = client; | ||
1673 | |||
1674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1675 | "Decrypted message of type %d from %s\n", | ||
1676 | ntohs (m->type), | ||
1677 | GNUNET_i2s (dmc->peer)); | ||
1678 | if (GNUNET_CORE_KX_STATE_UP != dmc->kx->status) | ||
1679 | { | ||
1680 | GNUNET_STATISTICS_update (GSC_stats, | ||
1681 | gettext_noop ("# PAYLOAD dropped (out of order)"), | ||
1682 | 1, | ||
1683 | GNUNET_NO); | ||
1684 | return GNUNET_OK; | ||
1685 | } | ||
1686 | switch (ntohs (m->type)) | ||
1687 | { | ||
1688 | case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP: | ||
1689 | case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP: | ||
1690 | GSC_SESSIONS_set_typemap (dmc->peer, m); | ||
1691 | return GNUNET_OK; | ||
1692 | case GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP: | ||
1693 | GSC_SESSIONS_confirm_typemap (dmc->peer, m); | ||
1694 | return GNUNET_OK; | ||
1695 | default: | ||
1696 | GSC_CLIENTS_deliver_message (dmc->peer, | ||
1697 | m, | ||
1698 | ntohs (m->size), | ||
1699 | GNUNET_CORE_OPTION_SEND_FULL_INBOUND); | ||
1700 | GSC_CLIENTS_deliver_message (dmc->peer, | ||
1701 | m, | ||
1702 | sizeof (struct GNUNET_MessageHeader), | ||
1703 | GNUNET_CORE_OPTION_SEND_HDR_INBOUND); | ||
1704 | } | ||
1705 | return GNUNET_OK; | ||
1706 | } | ||
1707 | |||
1708 | |||
1709 | /** | ||
1710 | * Setup the message that links the ephemeral key to our persistent | 1689 | * Setup the message that links the ephemeral key to our persistent |
1711 | * public key and generate the appropriate signature. | 1690 | * public key and generate the appropriate signature. |
1712 | */ | 1691 | */ |
@@ -1829,8 +1808,6 @@ GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk) | |||
1829 | rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, | 1808 | rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, |
1830 | &do_rekey, | 1809 | &do_rekey, |
1831 | NULL); | 1810 | NULL); |
1832 | mst = GNUNET_SERVER_mst_create (&deliver_message, | ||
1833 | NULL); | ||
1834 | transport | 1811 | transport |
1835 | = GNUNET_TRANSPORT_core_connect (GSC_cfg, | 1812 | = GNUNET_TRANSPORT_core_connect (GSC_cfg, |
1836 | &GSC_my_identity, | 1813 | &GSC_my_identity, |
@@ -1874,11 +1851,6 @@ GSC_KX_done () | |||
1874 | GNUNET_free (my_private_key); | 1851 | GNUNET_free (my_private_key); |
1875 | my_private_key = NULL; | 1852 | my_private_key = NULL; |
1876 | } | 1853 | } |
1877 | if (NULL != mst) | ||
1878 | { | ||
1879 | GNUNET_SERVER_mst_destroy (mst); | ||
1880 | mst = NULL; | ||
1881 | } | ||
1882 | if (NULL != nc) | 1854 | if (NULL != nc) |
1883 | { | 1855 | { |
1884 | GNUNET_notification_context_destroy (nc); | 1856 | GNUNET_notification_context_destroy (nc); |
diff --git a/src/dns/gnunet-service-dns.c b/src/dns/gnunet-service-dns.c index 74f595c5e..079f74ce4 100644 --- a/src/dns/gnunet-service-dns.c +++ b/src/dns/gnunet-service-dns.c | |||
@@ -882,11 +882,10 @@ handle_client_response (void *cls, | |||
882 | * message is received by the tokenizer from the DNS hijack process. | 882 | * message is received by the tokenizer from the DNS hijack process. |
883 | * | 883 | * |
884 | * @param cls closure | 884 | * @param cls closure |
885 | * @param client identification of the client | ||
886 | * @param message the actual message, a DNS request we should handle | 885 | * @param message the actual message, a DNS request we should handle |
887 | */ | 886 | */ |
888 | static int | 887 | static int |
889 | process_helper_messages (void *cls GNUNET_UNUSED, void *client, | 888 | process_helper_messages (void *cls, |
890 | const struct GNUNET_MessageHeader *message) | 889 | const struct GNUNET_MessageHeader *message) |
891 | { | 890 | { |
892 | uint16_t msize; | 891 | uint16_t msize; |
diff --git a/src/exit/gnunet-daemon-exit.c b/src/exit/gnunet-daemon-exit.c index a32cb3086..15a462ada 100644 --- a/src/exit/gnunet-daemon-exit.c +++ b/src/exit/gnunet-daemon-exit.c | |||
@@ -2905,12 +2905,10 @@ tcp_from_helper (const struct GNUNET_TUN_TcpHeader *tcp, | |||
2905 | * Receive packets from the helper-process | 2905 | * Receive packets from the helper-process |
2906 | * | 2906 | * |
2907 | * @param cls unused | 2907 | * @param cls unused |
2908 | * @param client unsued | ||
2909 | * @param message message received from helper | 2908 | * @param message message received from helper |
2910 | */ | 2909 | */ |
2911 | static int | 2910 | static int |
2912 | message_token (void *cls GNUNET_UNUSED, | 2911 | message_token (void *cls GNUNET_UNUSED, |
2913 | void *client GNUNET_UNUSED, | ||
2914 | const struct GNUNET_MessageHeader *message) | 2912 | const struct GNUNET_MessageHeader *message) |
2915 | { | 2913 | { |
2916 | const struct GNUNET_TUN_Layer2PacketHeader *pkt_tun; | 2914 | const struct GNUNET_TUN_Layer2PacketHeader *pkt_tun; |
diff --git a/src/fs/fs_dirmetascan.c b/src/fs/fs_dirmetascan.c index 2f79c7c05..7b9f178fd 100644 --- a/src/fs/fs_dirmetascan.c +++ b/src/fs/fs_dirmetascan.c | |||
@@ -245,12 +245,10 @@ finish_scan (void *cls) | |||
245 | * Calls the scanner progress handler. | 245 | * Calls the scanner progress handler. |
246 | * | 246 | * |
247 | * @param cls the closure (directory scanner object) | 247 | * @param cls the closure (directory scanner object) |
248 | * @param client always NULL | ||
249 | * @param msg message from the helper process | 248 | * @param msg message from the helper process |
250 | */ | 249 | */ |
251 | static int | 250 | static int |
252 | process_helper_msgs (void *cls, | 251 | process_helper_msgs (void *cls, |
253 | void *client, | ||
254 | const struct GNUNET_MessageHeader *msg) | 252 | const struct GNUNET_MessageHeader *msg) |
255 | { | 253 | { |
256 | struct GNUNET_FS_DirScanner *ds = cls; | 254 | struct GNUNET_FS_DirScanner *ds = cls; |
diff --git a/src/include/Makefile.am b/src/include/Makefile.am index 4fb2577fd..b745da125 100644 --- a/src/include/Makefile.am +++ b/src/include/Makefile.am | |||
@@ -38,7 +38,6 @@ gnunetinclude_HEADERS = \ | |||
38 | gnunet_common.h \ | 38 | gnunet_common.h \ |
39 | gnunet_constants.h \ | 39 | gnunet_constants.h \ |
40 | gnunet_configuration_lib.h \ | 40 | gnunet_configuration_lib.h \ |
41 | gnunet_connection_lib.h \ | ||
42 | gnunet_consensus_service.h \ | 41 | gnunet_consensus_service.h \ |
43 | gnunet_container_lib.h \ | 42 | gnunet_container_lib.h \ |
44 | gnunet_conversation_service.h \ | 43 | gnunet_conversation_service.h \ |
@@ -107,7 +106,6 @@ gnunetinclude_HEADERS = \ | |||
107 | gnunet_scalarproduct_service.h \ | 106 | gnunet_scalarproduct_service.h \ |
108 | gnunet_scheduler_lib.h \ | 107 | gnunet_scheduler_lib.h \ |
109 | gnunet_secretsharing_service.h \ | 108 | gnunet_secretsharing_service.h \ |
110 | gnunet_server_lib.h \ | ||
111 | gnunet_service_lib.h \ | 109 | gnunet_service_lib.h \ |
112 | gnunet_set_service.h \ | 110 | gnunet_set_service.h \ |
113 | gnunet_signal_lib.h \ | 111 | gnunet_signal_lib.h \ |
diff --git a/src/include/gnunet_connection_lib.h b/src/include/gnunet_connection_lib.h deleted file mode 100644 index e9dd95d1b..000000000 --- a/src/include/gnunet_connection_lib.h +++ /dev/null | |||
@@ -1,400 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @author Christian Grothoff | ||
23 | * | ||
24 | * @file include/gnunet_connection_lib.h | ||
25 | * Basic, low-level TCP networking interface | ||
26 | * | ||
27 | * @defgroup connection Connection library | ||
28 | * Basic, low-level TCP networking interface | ||
29 | * @{ | ||
30 | */ | ||
31 | #ifndef GNUNET_CONNECTION_LIB_H | ||
32 | #define GNUNET_CONNECTION_LIB_H | ||
33 | |||
34 | #ifdef __cplusplus | ||
35 | extern "C" | ||
36 | { | ||
37 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
38 | } | ||
39 | #endif | ||
40 | #endif | ||
41 | |||
42 | #include "gnunet_network_lib.h" | ||
43 | #include "gnunet_scheduler_lib.h" | ||
44 | #include "gnunet_time_lib.h" | ||
45 | |||
46 | /** | ||
47 | * Timeout we use on TCP connect before trying another | ||
48 | * result from the DNS resolver. Actual value used | ||
49 | * is this value divided by the number of address families. | ||
50 | * Default is 5s. | ||
51 | */ | ||
52 | #define GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
53 | |||
54 | /** | ||
55 | * @brief handle for a network connection | ||
56 | */ | ||
57 | struct GNUNET_CONNECTION_Handle; | ||
58 | |||
59 | |||
60 | /** | ||
61 | * Credentials for UNIX domain sockets. | ||
62 | */ | ||
63 | struct GNUNET_CONNECTION_Credentials | ||
64 | { | ||
65 | /** | ||
66 | * UID of the other end of the connection. | ||
67 | */ | ||
68 | uid_t uid; | ||
69 | |||
70 | /** | ||
71 | * GID of the other end of the connection. | ||
72 | */ | ||
73 | gid_t gid; | ||
74 | }; | ||
75 | |||
76 | |||
77 | /** | ||
78 | * Function to call for access control checks. | ||
79 | * | ||
80 | * @param cls closure | ||
81 | * @param ucred credentials, if available, otherwise NULL | ||
82 | * @param addr address | ||
83 | * @param addrlen length of address | ||
84 | * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR | ||
85 | * for unknown address family (will be denied). | ||
86 | */ | ||
87 | typedef int (*GNUNET_CONNECTION_AccessCheck) (void *cls, | ||
88 | const struct | ||
89 | GNUNET_CONNECTION_Credentials * | ||
90 | ucred, | ||
91 | const struct sockaddr * addr, | ||
92 | socklen_t addrlen); | ||
93 | |||
94 | |||
95 | /** | ||
96 | * Callback function for data received from the network. Note that | ||
97 | * both "available" and "err" would be 0 if the read simply timed out. | ||
98 | * | ||
99 | * @param cls closure | ||
100 | * @param buf pointer to received data | ||
101 | * @param available number of bytes availabe in "buf", | ||
102 | * possibly 0 (on errors) | ||
103 | * @param addr address of the sender | ||
104 | * @param addrlen size of addr | ||
105 | * @param errCode value of errno (on errors receiving) | ||
106 | */ | ||
107 | typedef void (*GNUNET_CONNECTION_Receiver) (void *cls, const void *buf, | ||
108 | size_t available, | ||
109 | const struct sockaddr * addr, | ||
110 | socklen_t addrlen, int errCode); | ||
111 | |||
112 | /** | ||
113 | * Set the persist option on this connection handle. Indicates | ||
114 | * that the underlying socket or fd should never really be closed. | ||
115 | * Used for indicating process death. | ||
116 | * | ||
117 | * @param connection the connection to set persistent | ||
118 | */ | ||
119 | void | ||
120 | GNUNET_CONNECTION_persist_ (struct GNUNET_CONNECTION_Handle *connection); | ||
121 | |||
122 | /** | ||
123 | * Disable the "CORK" feature for communication with the given socket, | ||
124 | * forcing the OS to immediately flush the buffer on transmission | ||
125 | * instead of potentially buffering multiple messages. Essentially | ||
126 | * reduces the OS send buffers to zero. | ||
127 | * Used to make sure that the last messages sent through the connection | ||
128 | * reach the other side before the process is terminated. | ||
129 | * | ||
130 | * @param connection the connection to make flushing and blocking | ||
131 | * @return #GNUNET_OK on success | ||
132 | */ | ||
133 | int | ||
134 | GNUNET_CONNECTION_disable_corking (struct GNUNET_CONNECTION_Handle *connection); | ||
135 | |||
136 | |||
137 | /** | ||
138 | * Create a connection handle by (asynchronously) connecting to a host. | ||
139 | * This function returns immediately, even if the connection has not | ||
140 | * yet been established. This function only creates TCP connections. | ||
141 | * | ||
142 | * @param s socket to connect | ||
143 | * @param serv_addr server address | ||
144 | * @param addrlen length of server address | ||
145 | * @return the connection handle | ||
146 | */ | ||
147 | struct GNUNET_CONNECTION_Handle * | ||
148 | GNUNET_CONNECTION_connect_socket (struct GNUNET_NETWORK_Handle *s, | ||
149 | const struct sockaddr *serv_addr, | ||
150 | socklen_t addrlen); | ||
151 | |||
152 | |||
153 | /** | ||
154 | * Create a connection handle by boxing an existing OS socket. The OS | ||
155 | * socket should henceforth be no longer used directly. | ||
156 | * #GNUNET_CONNECTION_destroy() will close it. | ||
157 | * | ||
158 | * @param osSocket existing socket to box | ||
159 | * @return the boxed socket handle | ||
160 | */ | ||
161 | struct GNUNET_CONNECTION_Handle * | ||
162 | GNUNET_CONNECTION_create_from_existing (struct GNUNET_NETWORK_Handle *osSocket); | ||
163 | |||
164 | |||
165 | /** | ||
166 | * Create a connection handle by accepting on a listen socket. This | ||
167 | * function may block if the listen socket has no connection ready. | ||
168 | * | ||
169 | * @param access_cb function to use to check if access is allowed | ||
170 | * @param access_cb_cls closure for @a access_cb | ||
171 | * @param lsock listen socket | ||
172 | * @return the connection handle, NULL on error (for example, access refused) | ||
173 | */ | ||
174 | struct GNUNET_CONNECTION_Handle * | ||
175 | GNUNET_CONNECTION_create_from_accept (GNUNET_CONNECTION_AccessCheck access_cb, | ||
176 | void *access_cb_cls, | ||
177 | struct GNUNET_NETWORK_Handle *lsock); | ||
178 | |||
179 | |||
180 | /** | ||
181 | * Create a connection handle by (asynchronously) connecting to a host. | ||
182 | * This function returns immediately, even if the connection has not | ||
183 | * yet been established. This function only creates TCP connections. | ||
184 | * | ||
185 | * @param cfg configuration to use | ||
186 | * @param hostname name of the host to connect to | ||
187 | * @param port port to connect to | ||
188 | * @return the connection handle | ||
189 | */ | ||
190 | struct GNUNET_CONNECTION_Handle * | ||
191 | GNUNET_CONNECTION_create_from_connect (const struct GNUNET_CONFIGURATION_Handle | ||
192 | *cfg, const char *hostname, | ||
193 | uint16_t port); | ||
194 | |||
195 | |||
196 | /** | ||
197 | * Create a connection handle by connecting to a UNIX domain service. | ||
198 | * This function returns immediately, even if the connection has not | ||
199 | * yet been established. This function only creates UNIX connections. | ||
200 | * | ||
201 | * @param cfg configuration to use | ||
202 | * @param unixpath path to connect to) | ||
203 | * @return the connection handle, NULL on systems without UNIX support | ||
204 | */ | ||
205 | struct GNUNET_CONNECTION_Handle * | ||
206 | GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct | ||
207 | GNUNET_CONFIGURATION_Handle | ||
208 | *cfg, const char *unixpath); | ||
209 | |||
210 | |||
211 | |||
212 | |||
213 | /** | ||
214 | * Create a connection handle by (asynchronously) connecting to a host. | ||
215 | * This function returns immediately, even if the connection has not | ||
216 | * yet been established. This function only creates TCP connections. | ||
217 | * | ||
218 | * @param af_family address family to use | ||
219 | * @param serv_addr server address | ||
220 | * @param addrlen length of server address | ||
221 | * @return the connection handle | ||
222 | */ | ||
223 | struct GNUNET_CONNECTION_Handle * | ||
224 | GNUNET_CONNECTION_create_from_sockaddr (int af_family, | ||
225 | const struct sockaddr *serv_addr, | ||
226 | socklen_t addrlen); | ||
227 | |||
228 | /** | ||
229 | * Check if connection is valid (no fatal errors have happened so far). | ||
230 | * Note that a connection that is still trying to connect is considered | ||
231 | * valid. | ||
232 | * | ||
233 | * @param connection handle to check | ||
234 | * @return GNUNET_YES if valid, GNUNET_NO otherwise | ||
235 | */ | ||
236 | int | ||
237 | GNUNET_CONNECTION_check (struct GNUNET_CONNECTION_Handle *connection); | ||
238 | |||
239 | |||
240 | /** | ||
241 | * Obtain the network address of the other party. | ||
242 | * | ||
243 | * @param connection the client to get the address for | ||
244 | * @param addr where to store the address | ||
245 | * @param addrlen where to store the length of the address | ||
246 | * @return GNUNET_OK on success | ||
247 | */ | ||
248 | int | ||
249 | GNUNET_CONNECTION_get_address (struct GNUNET_CONNECTION_Handle *connection, | ||
250 | void **addr, size_t * addrlen); | ||
251 | |||
252 | |||
253 | /** | ||
254 | * Close the connection and free associated resources. There must | ||
255 | * not be any pending requests for reading or writing to the | ||
256 | * connection at this time. | ||
257 | * | ||
258 | * @param connection connection to destroy | ||
259 | */ | ||
260 | void | ||
261 | GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection); | ||
262 | |||
263 | |||
264 | /** | ||
265 | * Receive data from the given connection. Note that this function will | ||
266 | * call "receiver" asynchronously using the scheduler. It will | ||
267 | * "immediately" return. Note that there MUST only be one active | ||
268 | * receive call per connection at any given point in time (so do not | ||
269 | * call receive again until the receiver callback has been invoked). | ||
270 | * | ||
271 | * @param connection connection handle | ||
272 | * @param max maximum number of bytes to read | ||
273 | * @param timeout maximum amount of time to wait | ||
274 | * @param receiver function to call with received data | ||
275 | * @param receiver_cls closure for receiver | ||
276 | */ | ||
277 | void | ||
278 | GNUNET_CONNECTION_receive (struct GNUNET_CONNECTION_Handle *connection, size_t max, | ||
279 | struct GNUNET_TIME_Relative timeout, | ||
280 | GNUNET_CONNECTION_Receiver receiver, | ||
281 | void *receiver_cls); | ||
282 | |||
283 | |||
284 | /** | ||
285 | * Cancel receive job on the given connection. Note that the | ||
286 | * receiver callback must not have been called yet in order | ||
287 | * for the cancellation to be valid. | ||
288 | * | ||
289 | * @param connection connection handle | ||
290 | * @return closure of the original receiver callback closure | ||
291 | */ | ||
292 | void * | ||
293 | GNUNET_CONNECTION_receive_cancel (struct GNUNET_CONNECTION_Handle *connection); | ||
294 | |||
295 | |||
296 | /** | ||
297 | * Function called to notify a client about the connection begin ready | ||
298 | * to queue more data. @a buf will be NULL and @a size zero if the | ||
299 | * connection was closed for writing in the meantime. | ||
300 | * | ||
301 | * @param cls closure | ||
302 | * @param size number of bytes available in @a buf | ||
303 | * @param buf where the callee should write the message | ||
304 | * @return number of bytes written to @a buf | ||
305 | */ | ||
306 | typedef size_t | ||
307 | (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, | ||
308 | size_t size, | ||
309 | void *buf); | ||
310 | |||
311 | |||
312 | /** | ||
313 | * Opaque handle that can be used to cancel | ||
314 | * a transmit-ready notification. | ||
315 | */ | ||
316 | struct GNUNET_CONNECTION_TransmitHandle; | ||
317 | |||
318 | /** | ||
319 | * Ask the connection to call us once the specified number of bytes | ||
320 | * are free in the transmission buffer. Will never call the @a notify | ||
321 | * callback in this task, but always first go into the scheduler. Note that | ||
322 | * this function will abort if "size" is greater than | ||
323 | * #GNUNET_SERVER_MAX_MESSAGE_SIZE. | ||
324 | * | ||
325 | * Note that "notify" will be called either when enough | ||
326 | * buffer space is available OR when the connection is destroyed. | ||
327 | * The size parameter given to notify is guaranteed to be | ||
328 | * larger or equal to size if the buffer is ready, or zero | ||
329 | * if the connection was destroyed (or at least closed for | ||
330 | * writing). Finally, any time before 'notify' is called, a | ||
331 | * client may call "notify_transmit_ready_cancel" to cancel | ||
332 | * the transmission request. | ||
333 | * | ||
334 | * Only one transmission request can be scheduled at the same | ||
335 | * time. Notify will be run with the same scheduler priority | ||
336 | * as that of the caller. | ||
337 | * | ||
338 | * @param connection connection | ||
339 | * @param size number of bytes to send | ||
340 | * @param timeout after how long should we give up (and call | ||
341 | * notify with buf NULL and size 0)? | ||
342 | * @param notify function to call when buffer space is available | ||
343 | * @param notify_cls closure for notify | ||
344 | * @return non-NULL if the notify callback was queued, | ||
345 | * NULL if we are already going to notify someone else (busy) | ||
346 | */ | ||
347 | struct GNUNET_CONNECTION_TransmitHandle * | ||
348 | GNUNET_CONNECTION_notify_transmit_ready (struct GNUNET_CONNECTION_Handle *connection, | ||
349 | size_t size, | ||
350 | struct GNUNET_TIME_Relative timeout, | ||
351 | GNUNET_CONNECTION_TransmitReadyNotify | ||
352 | notify, void *notify_cls); | ||
353 | |||
354 | |||
355 | /** | ||
356 | * Cancel the specified transmission-ready | ||
357 | * notification. | ||
358 | * | ||
359 | * @param th handle for notification to cancel | ||
360 | */ | ||
361 | void | ||
362 | GNUNET_CONNECTION_notify_transmit_ready_cancel (struct | ||
363 | GNUNET_CONNECTION_TransmitHandle | ||
364 | *th); | ||
365 | |||
366 | |||
367 | /** | ||
368 | * Create a connection to be proxied using a given connection. | ||
369 | * | ||
370 | * @param cph connection to proxy server | ||
371 | * @return connection to be proxied | ||
372 | */ | ||
373 | struct GNUNET_CONNECTION_Handle * | ||
374 | GNUNET_CONNECTION_create_proxied_from_handshake (struct GNUNET_CONNECTION_Handle *cph); | ||
375 | |||
376 | |||
377 | /** | ||
378 | * Activate proxied connection and destroy initial proxy handshake connection. | ||
379 | * There must not be any pending requests for reading or writing to the | ||
380 | * proxy hadshake connection at this time. | ||
381 | * | ||
382 | * @param proxied connection connection to proxy server | ||
383 | */ | ||
384 | void | ||
385 | GNUNET_CONNECTION_acivate_proxied (struct GNUNET_CONNECTION_Handle *proxied); | ||
386 | |||
387 | |||
388 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
389 | { | ||
390 | #endif | ||
391 | #ifdef __cplusplus | ||
392 | } | ||
393 | #endif | ||
394 | |||
395 | /* ifndef GNUNET_CONNECTION_LIB_H */ | ||
396 | #endif | ||
397 | |||
398 | /** @} */ /* end of group */ | ||
399 | |||
400 | /* end of gnunet_connection_lib.h */ | ||
diff --git a/src/include/gnunet_helper_lib.h b/src/include/gnunet_helper_lib.h index db0ca98aa..60b3ff681 100644 --- a/src/include/gnunet_helper_lib.h +++ b/src/include/gnunet_helper_lib.h | |||
@@ -38,7 +38,8 @@ | |||
38 | #define GNUNET_HELPER_LIB_H | 38 | #define GNUNET_HELPER_LIB_H |
39 | 39 | ||
40 | #include "gnunet_scheduler_lib.h" | 40 | #include "gnunet_scheduler_lib.h" |
41 | #include "gnunet_server_lib.h" | 41 | #include "gnunet_mst_lib.h" |
42 | |||
42 | 43 | ||
43 | /** | 44 | /** |
44 | * The handle to a helper process. | 45 | * The handle to a helper process. |
@@ -52,7 +53,8 @@ struct GNUNET_HELPER_Handle; | |||
52 | * | 53 | * |
53 | * @param cls the closure from GNUNET_HELPER_start() | 54 | * @param cls the closure from GNUNET_HELPER_start() |
54 | */ | 55 | */ |
55 | typedef void (*GNUNET_HELPER_ExceptionCallback) (void *cls); | 56 | typedef void |
57 | (*GNUNET_HELPER_ExceptionCallback) (void *cls); | ||
56 | 58 | ||
57 | 59 | ||
58 | /** | 60 | /** |
@@ -75,7 +77,7 @@ struct GNUNET_HELPER_Handle * | |||
75 | GNUNET_HELPER_start (int with_control_pipe, | 77 | GNUNET_HELPER_start (int with_control_pipe, |
76 | const char *binary_name, | 78 | const char *binary_name, |
77 | char *const binary_argv[], | 79 | char *const binary_argv[], |
78 | GNUNET_SERVER_MessageTokenizerCallback cb, | 80 | GNUNET_MessageTokenizerCallback cb, |
79 | GNUNET_HELPER_ExceptionCallback exp_cb, | 81 | GNUNET_HELPER_ExceptionCallback exp_cb, |
80 | void *cb_cls); | 82 | void *cb_cls); |
81 | 83 | ||
diff --git a/src/include/gnunet_mq_lib.h b/src/include/gnunet_mq_lib.h index b05128ccc..ecee1b223 100644 --- a/src/include/gnunet_mq_lib.h +++ b/src/include/gnunet_mq_lib.h | |||
@@ -35,6 +35,7 @@ | |||
35 | #ifndef GNUNET_MQ_LIB_H | 35 | #ifndef GNUNET_MQ_LIB_H |
36 | #define GNUNET_MQ_LIB_H | 36 | #define GNUNET_MQ_LIB_H |
37 | 37 | ||
38 | #include "gnunet_scheduler_lib.h" | ||
38 | 39 | ||
39 | /** | 40 | /** |
40 | * Allocate an envelope, with extra space allocated after the space needed | 41 | * Allocate an envelope, with extra space allocated after the space needed |
diff --git a/src/include/gnunet_server_lib.h b/src/include/gnunet_server_lib.h deleted file mode 100644 index 5da31bcd7..000000000 --- a/src/include/gnunet_server_lib.h +++ /dev/null | |||
@@ -1,887 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009-2013 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @author Christian Grothoff | ||
23 | * | ||
24 | * @file | ||
25 | * Library for building GNUnet network servers | ||
26 | |||
27 | * @defgroup server Server library | ||
28 | * Library for building GNUnet network servers | ||
29 | * | ||
30 | * Provides functions for a server that communicates with clients. | ||
31 | * | ||
32 | * @see [Documentation](https://gnunet.org/ipc) | ||
33 | * | ||
34 | * @{ | ||
35 | */ | ||
36 | |||
37 | #ifndef GNUNET_SERVER_LIB_H | ||
38 | #define GNUNET_SERVER_LIB_H | ||
39 | |||
40 | #ifdef __cplusplus | ||
41 | extern "C" | ||
42 | { | ||
43 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
44 | } | ||
45 | #endif | ||
46 | #endif | ||
47 | |||
48 | #include "gnunet_common.h" | ||
49 | #include "gnunet_connection_lib.h" | ||
50 | |||
51 | |||
52 | /** | ||
53 | * Largest supported message (to be precise, one byte more | ||
54 | * than the largest possible message, so tests involving | ||
55 | * this value should check for messages being smaller than | ||
56 | * this value). | ||
57 | */ | ||
58 | #define GNUNET_SERVER_MAX_MESSAGE_SIZE 65536 | ||
59 | |||
60 | /** | ||
61 | * Smallest supported message. | ||
62 | */ | ||
63 | #define GNUNET_SERVER_MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader) | ||
64 | |||
65 | /** | ||
66 | * @brief handle for a server | ||
67 | */ | ||
68 | struct GNUNET_SERVER_Handle; | ||
69 | |||
70 | /** | ||
71 | * @brief opaque handle for a client of the server | ||
72 | */ | ||
73 | struct GNUNET_SERVER_Client; | ||
74 | |||
75 | /** | ||
76 | * @brief opaque handle server returns for aborting transmission to a client. | ||
77 | */ | ||
78 | struct GNUNET_SERVER_TransmitHandle; | ||
79 | |||
80 | |||
81 | /** | ||
82 | * Functions with this signature are called whenever a message is | ||
83 | * received. | ||
84 | * | ||
85 | * @param cls closure | ||
86 | * @param client identification of the client | ||
87 | * @param message the actual message | ||
88 | */ | ||
89 | typedef void | ||
90 | (*GNUNET_SERVER_MessageCallback) (void *cls, | ||
91 | struct GNUNET_SERVER_Client *client, | ||
92 | const struct GNUNET_MessageHeader *message); | ||
93 | |||
94 | |||
95 | /** | ||
96 | * Message handler. Each struct specifies how to handle on particular | ||
97 | * type of message received. | ||
98 | */ | ||
99 | struct GNUNET_SERVER_MessageHandler | ||
100 | { | ||
101 | /** | ||
102 | * Function to call for messages of "type". | ||
103 | */ | ||
104 | GNUNET_SERVER_MessageCallback callback; | ||
105 | |||
106 | /** | ||
107 | * Closure argument for @e callback. | ||
108 | */ | ||
109 | void *callback_cls; | ||
110 | |||
111 | /** | ||
112 | * Type of the message this handler covers. | ||
113 | */ | ||
114 | uint16_t type; | ||
115 | |||
116 | /** | ||
117 | * Expected size of messages of this type. Use 0 for | ||
118 | * variable-size. If non-zero, messages of the given | ||
119 | * type will be discarded (and the connection closed) | ||
120 | * if they do not have the right size. | ||
121 | */ | ||
122 | uint16_t expected_size; | ||
123 | |||
124 | }; | ||
125 | |||
126 | |||
127 | /** | ||
128 | * Create a new server. | ||
129 | * | ||
130 | * @param access_cb function for access control | ||
131 | * @param access_cb_cls closure for @a access_cb | ||
132 | * @param lsocks NULL-terminated array of listen sockets | ||
133 | * @param idle_timeout after how long should we timeout idle connections? | ||
134 | * @param require_found if #GNUNET_YES, connections sending messages of unknown type | ||
135 | * will be closed | ||
136 | * @return handle for the new server, NULL on error | ||
137 | * (typically, "port" already in use) | ||
138 | */ | ||
139 | struct GNUNET_SERVER_Handle * | ||
140 | GNUNET_SERVER_create_with_sockets (GNUNET_CONNECTION_AccessCheck access_cb, | ||
141 | void *access_cb_cls, | ||
142 | struct GNUNET_NETWORK_Handle **lsocks, | ||
143 | struct GNUNET_TIME_Relative idle_timeout, | ||
144 | int require_found); | ||
145 | |||
146 | /** | ||
147 | * Create a new server. | ||
148 | * | ||
149 | * @param access_cb function for access control | ||
150 | * @param access_cb_cls closure for @a access_cb | ||
151 | * @param server_addr address toes listen on (including port), NULL terminated array | ||
152 | * @param socklen lengths of respective @a server_addr | ||
153 | * @param idle_timeout after how long should we timeout idle connections? | ||
154 | * @param require_found if #GNUNET_YES, connections sending messages of unknown type | ||
155 | * will be closed | ||
156 | * @return handle for the new server, NULL on error | ||
157 | * (typically, "port" already in use) | ||
158 | */ | ||
159 | struct GNUNET_SERVER_Handle * | ||
160 | GNUNET_SERVER_create (GNUNET_CONNECTION_AccessCheck access_cb, | ||
161 | void *access_cb_cls, | ||
162 | struct sockaddr *const *server_addr, | ||
163 | const socklen_t *socklen, | ||
164 | struct GNUNET_TIME_Relative idle_timeout, | ||
165 | int require_found); | ||
166 | |||
167 | |||
168 | /** | ||
169 | * Suspend accepting connections from the listen socket temporarily. | ||
170 | * Resume activity using #GNUNET_SERVER_resume. | ||
171 | * | ||
172 | * @param server server to stop accepting connections. | ||
173 | */ | ||
174 | void | ||
175 | GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server); | ||
176 | |||
177 | |||
178 | /** | ||
179 | * Resume accepting connections from the listen socket. | ||
180 | * | ||
181 | * @param server server to resume accepting connections. | ||
182 | */ | ||
183 | void | ||
184 | GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server); | ||
185 | |||
186 | |||
187 | /** | ||
188 | * Stop the listen socket and get ready to shutdown the server once | ||
189 | * only clients marked using #GNUNET_SERVER_client_mark_monitor are | ||
190 | * left. | ||
191 | * | ||
192 | * @param server server to stop listening on | ||
193 | */ | ||
194 | void | ||
195 | GNUNET_SERVER_stop_listening (struct GNUNET_SERVER_Handle *server); | ||
196 | |||
197 | |||
198 | /** | ||
199 | * Free resources held by this server. | ||
200 | * | ||
201 | * @param server server to destroy | ||
202 | */ | ||
203 | void | ||
204 | GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server); | ||
205 | |||
206 | |||
207 | /** | ||
208 | * Add additional handlers to an existing server. | ||
209 | * | ||
210 | * @param server the server to add handlers to | ||
211 | * @param handlers array of message handlers for | ||
212 | * incoming messages; the last entry must | ||
213 | * have "NULL" for the "callback"; multiple | ||
214 | * entries for the same type are allowed, | ||
215 | * they will be called in order of occurence. | ||
216 | * These handlers can be removed later; | ||
217 | * the handlers array must exist until removed | ||
218 | * (or server is destroyed). | ||
219 | */ | ||
220 | void | ||
221 | GNUNET_SERVER_add_handlers (struct GNUNET_SERVER_Handle *server, | ||
222 | const struct GNUNET_SERVER_MessageHandler *handlers); | ||
223 | |||
224 | |||
225 | /** | ||
226 | * Notify us when the server has enough space to transmit | ||
227 | * a message of the given size to the given client. | ||
228 | * | ||
229 | * @param client client to transmit message to | ||
230 | * @param size requested amount of buffer space | ||
231 | * @param timeout after how long should we give up (and call | ||
232 | * notify with buf NULL and size 0)? | ||
233 | * @param callback function to call when space is available | ||
234 | * @param callback_cls closure for @a callback | ||
235 | * @return non-NULL if the notify callback was queued; can be used | ||
236 | * to cancel the request using | ||
237 | * #GNUNET_SERVER_notify_transmit_ready_cancel. | ||
238 | * NULL if we are already going to notify someone else (busy) | ||
239 | */ | ||
240 | struct GNUNET_SERVER_TransmitHandle * | ||
241 | GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, | ||
242 | size_t size, | ||
243 | struct GNUNET_TIME_Relative timeout, | ||
244 | GNUNET_CONNECTION_TransmitReadyNotify callback, | ||
245 | void *callback_cls); | ||
246 | |||
247 | |||
248 | /** | ||
249 | * Abort transmission request. | ||
250 | * | ||
251 | * @param th request to abort | ||
252 | */ | ||
253 | void | ||
254 | GNUNET_SERVER_notify_transmit_ready_cancel (struct GNUNET_SERVER_TransmitHandle *th); | ||
255 | |||
256 | |||
257 | /** | ||
258 | * Set the 'monitor' flag on this client. Clients which have been | ||
259 | * marked as 'monitors' won't prevent the server from shutting down | ||
260 | * once #GNUNET_SERVER_stop_listening has been invoked. The idea is | ||
261 | * that for "normal" clients we likely want to allow them to process | ||
262 | * their requests; however, monitor-clients are likely to 'never' | ||
263 | * disconnect during shutdown and thus will not be considered when | ||
264 | * determining if the server should continue to exist after | ||
265 | * #GNUNET_SERVER_destroy has been called. | ||
266 | * | ||
267 | * @param client the client to set the 'monitor' flag on | ||
268 | */ | ||
269 | void | ||
270 | GNUNET_SERVER_client_mark_monitor (struct GNUNET_SERVER_Client *client); | ||
271 | |||
272 | |||
273 | /** | ||
274 | * Set the persistent flag on this client, used to setup client | ||
275 | * connection to only be killed when the process of the service it's | ||
276 | * connected to is actually dead. This API is used during shutdown | ||
277 | * signalling within ARM, and it is not expected that typical users | ||
278 | * of the API would need this function. | ||
279 | * | ||
280 | * @param client the client to set the persistent flag on | ||
281 | */ | ||
282 | void | ||
283 | GNUNET_SERVER_client_persist_ (struct GNUNET_SERVER_Client *client); | ||
284 | |||
285 | |||
286 | /** | ||
287 | * Resume receiving from this client, we are done processing the | ||
288 | * current request. This function must be called from within each | ||
289 | * #GNUNET_SERVER_MessageCallback (or its respective continuations). | ||
290 | * | ||
291 | * @param client client we were processing a message of | ||
292 | * @param success #GNUNET_OK to keep the connection open and | ||
293 | * continue to receive | ||
294 | * #GNUNET_NO to close the connection (normal behavior) | ||
295 | * #GNUNET_SYSERR to close the connection (signal | ||
296 | * serious error) | ||
297 | */ | ||
298 | void | ||
299 | GNUNET_SERVER_receive_done (struct GNUNET_SERVER_Client *client, | ||
300 | int success); | ||
301 | |||
302 | |||
303 | /** | ||
304 | * Change the timeout for a particular client. Decreasing the timeout | ||
305 | * may not go into effect immediately (only after the previous timeout | ||
306 | * times out or activity happens on the socket). | ||
307 | * | ||
308 | * @param client the client to update | ||
309 | * @param timeout new timeout for activities on the socket | ||
310 | */ | ||
311 | void | ||
312 | GNUNET_SERVER_client_set_timeout (struct GNUNET_SERVER_Client *client, | ||
313 | struct GNUNET_TIME_Relative timeout); | ||
314 | |||
315 | |||
316 | /** | ||
317 | * Return user context associated with the given client. | ||
318 | * Note: you should probably use the macro (call without the underscore). | ||
319 | * | ||
320 | * @param client client to query | ||
321 | * @param size number of bytes in user context struct (for verification only) | ||
322 | * @return pointer to user context | ||
323 | */ | ||
324 | void * | ||
325 | GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client, | ||
326 | size_t size); | ||
327 | |||
328 | |||
329 | /** | ||
330 | * Set user context to be associated with the given client. | ||
331 | * Note: you should probably use the macro (call without the underscore). | ||
332 | * | ||
333 | * @param client client to query | ||
334 | * @param ptr pointer to user context | ||
335 | * @param size number of bytes in user context struct (for verification only) | ||
336 | */ | ||
337 | void | ||
338 | GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client, | ||
339 | void *ptr, | ||
340 | size_t size); | ||
341 | |||
342 | |||
343 | /** | ||
344 | * Return user context associated with the given client. | ||
345 | * | ||
346 | * @param client client to query | ||
347 | * @param type expected return type (i.e. 'struct Foo') | ||
348 | * @return pointer to user context of type 'type *'. | ||
349 | */ | ||
350 | #define GNUNET_SERVER_client_get_user_context(client,type) \ | ||
351 | (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type)) | ||
352 | |||
353 | /** | ||
354 | * Set user context to be associated with the given client. | ||
355 | * | ||
356 | * @param client client to query | ||
357 | * @param value pointer to user context | ||
358 | */ | ||
359 | #define GNUNET_SERVER_client_set_user_context(client,value) \ | ||
360 | GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value)) | ||
361 | |||
362 | |||
363 | /** | ||
364 | * Disable the warning the server issues if a message is not acknowledged | ||
365 | * in a timely fashion. Use this call if a client is intentionally delayed | ||
366 | * for a while. Only applies to the current message. | ||
367 | * | ||
368 | * @param client client for which to disable the warning | ||
369 | */ | ||
370 | void | ||
371 | GNUNET_SERVER_disable_receive_done_warning (struct GNUNET_SERVER_Client | ||
372 | *client); | ||
373 | |||
374 | |||
375 | /** | ||
376 | * Inject a message into the server, pretend it came | ||
377 | * from the specified client. Delivery of the message | ||
378 | * will happen instantly (if a handler is installed; | ||
379 | * otherwise the call does nothing). | ||
380 | * | ||
381 | * @param server the server receiving the message | ||
382 | * @param sender the "pretended" sender of the message | ||
383 | * can be NULL! | ||
384 | * @param message message to transmit | ||
385 | * @return #GNUNET_OK if the message was OK and the | ||
386 | * connection can stay open | ||
387 | * #GNUNET_SYSERR if the connection to the | ||
388 | * client should be shut down | ||
389 | */ | ||
390 | int | ||
391 | GNUNET_SERVER_inject (struct GNUNET_SERVER_Handle *server, | ||
392 | struct GNUNET_SERVER_Client *sender, | ||
393 | const struct GNUNET_MessageHeader *message); | ||
394 | |||
395 | |||
396 | /** | ||
397 | * Add a TCP socket-based connection to the set of handles managed by | ||
398 | * this server. Use this function for outgoing (P2P) connections that | ||
399 | * we initiated (and where this server should process incoming | ||
400 | * messages). | ||
401 | * | ||
402 | * @param server the server to use | ||
403 | * @param connection the connection to manage (client must | ||
404 | * stop using this connection from now on) | ||
405 | * @return the client handle | ||
406 | */ | ||
407 | struct GNUNET_SERVER_Client * | ||
408 | GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, | ||
409 | struct GNUNET_CONNECTION_Handle *connection); | ||
410 | |||
411 | |||
412 | /** | ||
413 | * Notify the server that the given client handle should | ||
414 | * be kept (keeps the connection up if possible, increments | ||
415 | * the internal reference counter). | ||
416 | * | ||
417 | * @param client the client to keep | ||
418 | */ | ||
419 | void | ||
420 | GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client); | ||
421 | |||
422 | |||
423 | /** | ||
424 | * Notify the server that the given client handle is no | ||
425 | * longer required. Decrements the reference counter. If | ||
426 | * that counter reaches zero an inactive connection maybe | ||
427 | * closed. | ||
428 | * | ||
429 | * @param client the client to drop | ||
430 | */ | ||
431 | void | ||
432 | GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client); | ||
433 | |||
434 | |||
435 | /** | ||
436 | * Obtain the network address of the other party. | ||
437 | * | ||
438 | * @param client the client to get the address for | ||
439 | * @param addr where to store the address | ||
440 | * @param addrlen where to store the length of @a addr | ||
441 | * @return #GNUNET_OK on success | ||
442 | */ | ||
443 | int | ||
444 | GNUNET_SERVER_client_get_address (struct GNUNET_SERVER_Client *client, | ||
445 | void **addr, size_t *addrlen); | ||
446 | |||
447 | |||
448 | /** | ||
449 | * Functions with this signature are called whenever a client | ||
450 | * is disconnected on the network level. | ||
451 | * | ||
452 | * @param cls closure | ||
453 | * @param client identification of the client; NULL | ||
454 | * for the last call when the server is destroyed | ||
455 | */ | ||
456 | typedef void | ||
457 | (*GNUNET_SERVER_DisconnectCallback) (void *cls, | ||
458 | struct GNUNET_SERVER_Client *client); | ||
459 | |||
460 | |||
461 | /** | ||
462 | * Functions with this signature are called whenever a client | ||
463 | * is connected on the network level. | ||
464 | * | ||
465 | * @param cls closure | ||
466 | * @param client identification of the client | ||
467 | */ | ||
468 | typedef void | ||
469 | (*GNUNET_SERVER_ConnectCallback) (void *cls, | ||
470 | struct GNUNET_SERVER_Client *client); | ||
471 | |||
472 | |||
473 | /** | ||
474 | * Ask the server to notify us whenever a client disconnects. | ||
475 | * This function is called whenever the actual network connection | ||
476 | * is closed; the reference count may be zero or larger than zero | ||
477 | * at this point. If the server is destroyed before this | ||
478 | * notification is explicitly cancelled, the 'callback' will | ||
479 | * once be called with a 'client' argument of NULL to indicate | ||
480 | * that the server itself is now gone (and that the callback | ||
481 | * won't be called anymore and also can no longer be cancelled). | ||
482 | * | ||
483 | * @param server the server manageing the clients | ||
484 | * @param callback function to call on disconnect | ||
485 | * @param callback_cls closure for @a callback | ||
486 | */ | ||
487 | void | ||
488 | GNUNET_SERVER_disconnect_notify (struct GNUNET_SERVER_Handle *server, | ||
489 | GNUNET_SERVER_DisconnectCallback callback, | ||
490 | void *callback_cls); | ||
491 | |||
492 | |||
493 | /** | ||
494 | * Ask the server to notify us whenever a client connects. | ||
495 | * This function is called whenever the actual network connection | ||
496 | * is opened. If the server is destroyed before this | ||
497 | * notification is explicitly cancelled, the @a callback will | ||
498 | * once be called with a 'client' argument of NULL to indicate | ||
499 | * that the server itself is now gone (and that the callback | ||
500 | * won't be called anymore and also can no longer be cancelled). | ||
501 | * | ||
502 | * @param server the server manageing the clients | ||
503 | * @param callback function to call on sconnect | ||
504 | * @param callback_cls closure for @a callback | ||
505 | */ | ||
506 | void | ||
507 | GNUNET_SERVER_connect_notify (struct GNUNET_SERVER_Handle *server, | ||
508 | GNUNET_SERVER_ConnectCallback callback, | ||
509 | void *callback_cls); | ||
510 | |||
511 | |||
512 | /** | ||
513 | * Ask the server to stop notifying us whenever a client disconnects. | ||
514 | * Arguments must match exactly those given to | ||
515 | * #GNUNET_SERVER_disconnect_notify. It is not necessary to call this | ||
516 | * function during shutdown of the server; in fact, most applications | ||
517 | * will never use this function. | ||
518 | * | ||
519 | * @param server the server manageing the clients | ||
520 | * @param callback function to call on disconnect | ||
521 | * @param callback_cls closure for @a callback | ||
522 | */ | ||
523 | void | ||
524 | GNUNET_SERVER_disconnect_notify_cancel (struct GNUNET_SERVER_Handle *server, | ||
525 | GNUNET_SERVER_DisconnectCallback callback, | ||
526 | void *callback_cls); | ||
527 | |||
528 | |||
529 | /** | ||
530 | * Ask the server to stop notifying us whenever a client connects. | ||
531 | * Arguments must match exactly those given to | ||
532 | * #GNUNET_SERVER_connect_notify. It is not necessary to call this | ||
533 | * function during shutdown of the server; in fact, most applications | ||
534 | * will never use this function. | ||
535 | * | ||
536 | * @param server the server manageing the clients | ||
537 | * @param callback function to call on connect | ||
538 | * @param callback_cls closure for @a callback | ||
539 | */ | ||
540 | void | ||
541 | GNUNET_SERVER_connect_notify_cancel (struct GNUNET_SERVER_Handle *server, | ||
542 | GNUNET_SERVER_ConnectCallback callback, | ||
543 | void *callback_cls); | ||
544 | |||
545 | |||
546 | /** | ||
547 | * Ask the server to disconnect from the given client. This is the | ||
548 | * same as passing #GNUNET_SYSERR to #GNUNET_SERVER_receive_done, | ||
549 | * except that it allows dropping of a client even when not handling a | ||
550 | * message from that client. | ||
551 | * | ||
552 | * @param client the client to disconnect from | ||
553 | */ | ||
554 | void | ||
555 | GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client); | ||
556 | |||
557 | |||
558 | /** | ||
559 | * Disable the "CORK" feature for communication with the given client, | ||
560 | * forcing the OS to immediately flush the buffer on transmission | ||
561 | * instead of potentially buffering multiple messages. | ||
562 | * | ||
563 | * @param client handle to the client | ||
564 | * @return #GNUNET_OK on success | ||
565 | */ | ||
566 | int | ||
567 | GNUNET_SERVER_client_disable_corking (struct GNUNET_SERVER_Client *client); | ||
568 | |||
569 | |||
570 | /** | ||
571 | * The tansmit context is the key datastructure for a conveniance API | ||
572 | * used for transmission of complex results to the client followed | ||
573 | * ONLY by signaling receive_done with success or error | ||
574 | */ | ||
575 | struct GNUNET_SERVER_TransmitContext; | ||
576 | |||
577 | |||
578 | /** | ||
579 | * Create a new transmission context for the given client. | ||
580 | * | ||
581 | * @param client client to create the context for. | ||
582 | * @return NULL on error | ||
583 | */ | ||
584 | struct GNUNET_SERVER_TransmitContext * | ||
585 | GNUNET_SERVER_transmit_context_create (struct GNUNET_SERVER_Client *client); | ||
586 | |||
587 | |||
588 | /** | ||
589 | * Append a message to the transmission context. | ||
590 | * All messages in the context will be sent by | ||
591 | * the #GNUNET_SERVER_transmit_context_run method. | ||
592 | * | ||
593 | * @param tc context to use | ||
594 | * @param data what to append to the result message | ||
595 | * @param length length of @a data | ||
596 | * @param type type of the message | ||
597 | */ | ||
598 | void | ||
599 | GNUNET_SERVER_transmit_context_append_data (struct GNUNET_SERVER_TransmitContext *tc, | ||
600 | const void *data, | ||
601 | size_t length, uint16_t type); | ||
602 | |||
603 | |||
604 | /** | ||
605 | * Append a message to the transmission context. | ||
606 | * All messages in the context will be sent by | ||
607 | * the transmit_context_run method. | ||
608 | * | ||
609 | * @param tc context to use | ||
610 | * @param msg message to append | ||
611 | */ | ||
612 | void | ||
613 | GNUNET_SERVER_transmit_context_append_message (struct GNUNET_SERVER_TransmitContext *tc, | ||
614 | const struct GNUNET_MessageHeader *msg); | ||
615 | |||
616 | |||
617 | /** | ||
618 | * Execute a transmission context. If there is an error in the | ||
619 | * transmission, the receive_done method will be called with an error | ||
620 | * code (#GNUNET_SYSERR), otherwise with #GNUNET_OK. | ||
621 | * | ||
622 | * @param tc transmission context to use | ||
623 | * @param timeout when to time out and abort the transmission | ||
624 | */ | ||
625 | void | ||
626 | GNUNET_SERVER_transmit_context_run (struct GNUNET_SERVER_TransmitContext *tc, | ||
627 | struct GNUNET_TIME_Relative timeout); | ||
628 | |||
629 | |||
630 | /** | ||
631 | * Destroy a transmission context. This function must not be called | ||
632 | * after #GNUNET_SERVER_transmit_context_run. | ||
633 | * | ||
634 | * @param tc transmission context to destroy | ||
635 | * @param success code to give to #GNUNET_SERVER_receive_done for | ||
636 | * the client: #GNUNET_OK to keep the connection open and | ||
637 | * continue to receive | ||
638 | * #GNUNET_NO to close the connection (normal behavior) | ||
639 | * #GNUNET_SYSERR to close the connection (signal | ||
640 | * serious error) | ||
641 | */ | ||
642 | void | ||
643 | GNUNET_SERVER_transmit_context_destroy (struct GNUNET_SERVER_TransmitContext *tc, | ||
644 | int success); | ||
645 | |||
646 | |||
647 | /** | ||
648 | * The notification context is the key datastructure for a conveniance | ||
649 | * API used for transmission of notifications to the client until the | ||
650 | * client disconnects or is disconnected (or the notification context | ||
651 | * is destroyed, in which case we disconnect these clients). | ||
652 | * Essentially, all (notification) messages are queued up until the | ||
653 | * client is able to read them. | ||
654 | */ | ||
655 | struct GNUNET_SERVER_NotificationContext; | ||
656 | |||
657 | |||
658 | /** | ||
659 | * Create a new notification context. | ||
660 | * | ||
661 | * @param server server for which this function creates the context | ||
662 | * @param queue_length maximum number of messages to keep in | ||
663 | * the notification queue; optional messages are dropped | ||
664 | * if the queue gets longer than this number of messages | ||
665 | * @return handle to the notification context | ||
666 | */ | ||
667 | struct GNUNET_SERVER_NotificationContext * | ||
668 | GNUNET_SERVER_notification_context_create (struct GNUNET_SERVER_Handle *server, | ||
669 | unsigned int queue_length); | ||
670 | |||
671 | |||
672 | /** | ||
673 | * Destroy the context, force disconnect for all clients. | ||
674 | * | ||
675 | * @param nc context to destroy. | ||
676 | */ | ||
677 | void | ||
678 | GNUNET_SERVER_notification_context_destroy (struct GNUNET_SERVER_NotificationContext *nc); | ||
679 | |||
680 | |||
681 | /** | ||
682 | * Add a client to the notification context. | ||
683 | * | ||
684 | * @param nc context to modify | ||
685 | * @param client client to add | ||
686 | */ | ||
687 | void | ||
688 | GNUNET_SERVER_notification_context_add (struct GNUNET_SERVER_NotificationContext *nc, | ||
689 | struct GNUNET_SERVER_Client *client); | ||
690 | |||
691 | |||
692 | /** | ||
693 | * Send a message to a particular client; must have | ||
694 | * already been added to the notification context. | ||
695 | * | ||
696 | * @param nc context to modify | ||
697 | * @param client client to transmit to | ||
698 | * @param msg message to send | ||
699 | * @param can_drop can this message be dropped due to queue length limitations | ||
700 | */ | ||
701 | void | ||
702 | GNUNET_SERVER_notification_context_unicast (struct GNUNET_SERVER_NotificationContext *nc, | ||
703 | struct GNUNET_SERVER_Client *client, | ||
704 | const struct GNUNET_MessageHeader *msg, | ||
705 | int can_drop); | ||
706 | |||
707 | |||
708 | /** | ||
709 | * Send a message to all clients of this context. | ||
710 | * | ||
711 | * @param nc context to modify | ||
712 | * @param msg message to send | ||
713 | * @param can_drop can this message be dropped due to queue length limitations | ||
714 | */ | ||
715 | void | ||
716 | GNUNET_SERVER_notification_context_broadcast (struct GNUNET_SERVER_NotificationContext *nc, | ||
717 | const struct GNUNET_MessageHeader *msg, | ||
718 | int can_drop); | ||
719 | |||
720 | |||
721 | /** | ||
722 | * Return active number of subscribers in this context. | ||
723 | * | ||
724 | * @param nc context to query | ||
725 | * @return number of current subscribers | ||
726 | */ | ||
727 | unsigned int | ||
728 | GNUNET_SERVER_notification_context_get_size (struct GNUNET_SERVER_NotificationContext *nc); | ||
729 | |||
730 | |||
731 | /** | ||
732 | * Create a message queue for a server's client. | ||
733 | * | ||
734 | * @param client the client | ||
735 | * @return the message queue | ||
736 | */ | ||
737 | struct GNUNET_MQ_Handle * | ||
738 | GNUNET_MQ_queue_for_server_client (struct GNUNET_SERVER_Client *client); | ||
739 | |||
740 | |||
741 | /** | ||
742 | * Handle to a message stream tokenizer. | ||
743 | */ | ||
744 | struct GNUNET_SERVER_MessageStreamTokenizer; | ||
745 | |||
746 | |||
747 | /** | ||
748 | * Functions with this signature are called whenever a | ||
749 | * complete message is received by the tokenizer. | ||
750 | * | ||
751 | * Do not call #GNUNET_SERVER_mst_destroy from within | ||
752 | * the scope of this callback. | ||
753 | * | ||
754 | * @param cls closure | ||
755 | * @param client identification of the client | ||
756 | * @param message the actual message | ||
757 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing | ||
758 | */ | ||
759 | typedef int | ||
760 | (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, | ||
761 | void *client, | ||
762 | const struct GNUNET_MessageHeader *message); | ||
763 | |||
764 | |||
765 | /** | ||
766 | * Create a message stream tokenizer. | ||
767 | * | ||
768 | * @param cb function to call on completed messages | ||
769 | * @param cb_cls closure for @a cb | ||
770 | * @return handle to tokenizer | ||
771 | */ | ||
772 | struct GNUNET_SERVER_MessageStreamTokenizer * | ||
773 | GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, | ||
774 | void *cb_cls); | ||
775 | |||
776 | |||
777 | /** | ||
778 | * Add incoming data to the receive buffer and call the | ||
779 | * callback for all complete messages. | ||
780 | * | ||
781 | * @param mst tokenizer to use | ||
782 | * @param client_identity ID of client for which this is a buffer, | ||
783 | * can be NULL (will be passed back to 'cb') | ||
784 | * @param buf input data to add | ||
785 | * @param size number of bytes in @a buf | ||
786 | * @param purge should any excess bytes in the buffer be discarded | ||
787 | * (i.e. for packet-based services like UDP) | ||
788 | * @param one_shot only call callback once, keep rest of message in buffer | ||
789 | * @return #GNUNET_OK if we are done processing (need more data) | ||
790 | * #GNUNET_NO if one_shot was set and we have another message ready | ||
791 | * #GNUNET_SYSERR if the data stream is corrupt | ||
792 | */ | ||
793 | int | ||
794 | GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, | ||
795 | void *client_identity, | ||
796 | const char *buf, size_t size, | ||
797 | int purge, int one_shot); | ||
798 | |||
799 | |||
800 | /** | ||
801 | * Destroys a tokenizer. | ||
802 | * | ||
803 | * @param mst tokenizer to destroy | ||
804 | */ | ||
805 | void | ||
806 | GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst); | ||
807 | |||
808 | |||
809 | /** | ||
810 | * Signature of a function to create a custom tokenizer. | ||
811 | * | ||
812 | * @param cls closure from #GNUNET_SERVER_set_callbacks | ||
813 | * @param client handle to client the tokenzier will be used for | ||
814 | * @return handle to custom tokenizer ('mst') | ||
815 | */ | ||
816 | typedef void* | ||
817 | (*GNUNET_SERVER_MstCreateCallback) (void *cls, | ||
818 | struct GNUNET_SERVER_Client *client); | ||
819 | |||
820 | |||
821 | /** | ||
822 | * Signature of a function to destroy a custom tokenizer. | ||
823 | * | ||
824 | * @param cls closure from #GNUNET_SERVER_set_callbacks | ||
825 | * @param mst custom tokenizer handle | ||
826 | */ | ||
827 | typedef void | ||
828 | (*GNUNET_SERVER_MstDestroyCallback) (void *cls, | ||
829 | void *mst); | ||
830 | |||
831 | |||
832 | /** | ||
833 | * Signature of a function to receive data for a custom tokenizer. | ||
834 | * | ||
835 | * @param cls closure from #GNUNET_SERVER_set_callbacks | ||
836 | * @param mst custom tokenizer handle | ||
837 | * @param client_identity ID of client for which this is a buffer, | ||
838 | * can be NULL (will be passed back to 'cb') | ||
839 | * @param buf input data to add | ||
840 | * @param size number of bytes in @a buf | ||
841 | * @param purge should any excess bytes in the buffer be discarded | ||
842 | * (i.e. for packet-based services like UDP) | ||
843 | * @param one_shot only call callback once, keep rest of message in buffer | ||
844 | * @return #GNUNET_OK if we are done processing (need more data) | ||
845 | * #GNUNET_NO if one_shot was set and we have another message ready | ||
846 | * #GNUNET_SYSERR if the data stream is corrupt | ||
847 | */ | ||
848 | typedef int | ||
849 | (*GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst, | ||
850 | struct GNUNET_SERVER_Client *client, | ||
851 | const char *buf, | ||
852 | size_t size, | ||
853 | int purge, | ||
854 | int one_shot); | ||
855 | |||
856 | |||
857 | /** | ||
858 | * Change functions used by the server to tokenize the message stream. | ||
859 | * (very rarely used). | ||
860 | * | ||
861 | * @param server server to modify | ||
862 | * @param create new tokenizer initialization function | ||
863 | * @param destroy new tokenizer destruction function | ||
864 | * @param receive new tokenizer receive function | ||
865 | * @param cls closure for @a create, @a receive and @a destroy | ||
866 | */ | ||
867 | void | ||
868 | GNUNET_SERVER_set_callbacks (struct GNUNET_SERVER_Handle *server, | ||
869 | GNUNET_SERVER_MstCreateCallback create, | ||
870 | GNUNET_SERVER_MstDestroyCallback destroy, | ||
871 | GNUNET_SERVER_MstReceiveCallback receive, | ||
872 | void *cls); | ||
873 | |||
874 | |||
875 | #if 0 /* keep Emacsens' auto-indent happy */ | ||
876 | { | ||
877 | #endif | ||
878 | #ifdef __cplusplus | ||
879 | } | ||
880 | #endif | ||
881 | |||
882 | /* ifndef GNUNET_SERVER_LIB_H */ | ||
883 | #endif | ||
884 | |||
885 | /** @} */ /* end of group server */ | ||
886 | |||
887 | /* end of gnunet_server_lib.h */ | ||
diff --git a/src/include/gnunet_service_lib.h b/src/include/gnunet_service_lib.h index 75b880530..c506fc6fa 100644 --- a/src/include/gnunet_service_lib.h +++ b/src/include/gnunet_service_lib.h | |||
@@ -44,22 +44,28 @@ extern "C" | |||
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | #include "gnunet_configuration_lib.h" | 46 | #include "gnunet_configuration_lib.h" |
47 | #include "gnunet_server_lib.h" | ||
48 | #include "gnunet_mq_lib.h" | 47 | #include "gnunet_mq_lib.h" |
49 | 48 | ||
49 | /** | ||
50 | * Largest supported message (to be precise, one byte more | ||
51 | * than the largest possible message, so tests involving | ||
52 | * this value should check for messages being smaller than | ||
53 | * this value). NOTE: legacy name. | ||
54 | */ | ||
55 | #define GNUNET_SERVER_MAX_MESSAGE_SIZE 65536 | ||
50 | 56 | ||
51 | /** | 57 | /** |
52 | * Function called by the service's run | 58 | * Smallest supported message. NOTE: legacy name. |
53 | * method to run service-specific setup code. | ||
54 | * | ||
55 | * @param cls closure | ||
56 | * @param server the initialized server | ||
57 | * @param cfg configuration to use | ||
58 | */ | 59 | */ |
59 | typedef void | 60 | #define GNUNET_SERVER_MIN_BUFFER_SIZE sizeof (struct GNUNET_MessageHeader) |
60 | (*GNUNET_SERVICE_Main) (void *cls, | 61 | |
61 | struct GNUNET_SERVER_Handle *server, | 62 | /** |
62 | const struct GNUNET_CONFIGURATION_Handle *cfg); | 63 | * Timeout we use on TCP connect before trying another |
64 | * result from the DNS resolver. Actual value used | ||
65 | * is this value divided by the number of address families. | ||
66 | * Default is 5s. NOTE: legacy name. | ||
67 | */ | ||
68 | #define GNUNET_CONNECTION_CONNECT_RETRY_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
63 | 69 | ||
64 | 70 | ||
65 | /** | 71 | /** |
@@ -88,27 +94,6 @@ enum GNUNET_SERVICE_Options | |||
88 | }; | 94 | }; |
89 | 95 | ||
90 | 96 | ||
91 | /** | ||
92 | * Run a standard GNUnet service startup sequence (initialize loggers | ||
93 | * and configuration, parse options). | ||
94 | * | ||
95 | * @param argc number of command line arguments in @a argv | ||
96 | * @param argv command line arguments | ||
97 | * @param service_name our service name | ||
98 | * @param options service options | ||
99 | * @param task main task of the service | ||
100 | * @param task_cls closure for @a task | ||
101 | * @return #GNUNET_SYSERR on error, #GNUNET_OK | ||
102 | * if we shutdown nicely | ||
103 | * @deprecated | ||
104 | */ | ||
105 | int | ||
106 | GNUNET_SERVICE_run (int argc, | ||
107 | char *const *argv, | ||
108 | const char *service_name, | ||
109 | enum GNUNET_SERVICE_Options options, | ||
110 | GNUNET_SERVICE_Main task, | ||
111 | void *task_cls); | ||
112 | 97 | ||
113 | 98 | ||
114 | /** | 99 | /** |
@@ -134,18 +119,6 @@ GNUNET_SERVICE_start (const char *service_name, | |||
134 | 119 | ||
135 | 120 | ||
136 | /** | 121 | /** |
137 | * Obtain the server used by a service. Note that the server must NOT | ||
138 | * be destroyed by the caller. | ||
139 | * | ||
140 | * @param ctx the service context returned from the start function | ||
141 | * @return handle to the server for this service, NULL if there is none | ||
142 | * @deprecated | ||
143 | */ | ||
144 | struct GNUNET_SERVER_Handle * | ||
145 | GNUNET_SERVICE_get_server (struct GNUNET_SERVICE_Context *ctx); | ||
146 | |||
147 | |||
148 | /** | ||
149 | * Get the NULL-terminated array of listen sockets for this service. | 122 | * Get the NULL-terminated array of listen sockets for this service. |
150 | * | 123 | * |
151 | * @param ctx service context to query | 124 | * @param ctx service context to query |
diff --git a/src/include/gnunet_util_lib.h b/src/include/gnunet_util_lib.h index 52f5d8ab2..b42751d2a 100644 --- a/src/include/gnunet_util_lib.h +++ b/src/include/gnunet_util_lib.h | |||
@@ -41,7 +41,6 @@ extern "C" | |||
41 | #include "gnunet_crypto_lib.h" | 41 | #include "gnunet_crypto_lib.h" |
42 | #include "gnunet_bandwidth_lib.h" | 42 | #include "gnunet_bandwidth_lib.h" |
43 | #include "gnunet_bio_lib.h" | 43 | #include "gnunet_bio_lib.h" |
44 | #include "gnunet_connection_lib.h" | ||
45 | #include "gnunet_client_lib.h" | 44 | #include "gnunet_client_lib.h" |
46 | #include "gnunet_container_lib.h" | 45 | #include "gnunet_container_lib.h" |
47 | #include "gnunet_getopt_lib.h" | 46 | #include "gnunet_getopt_lib.h" |
@@ -55,7 +54,6 @@ extern "C" | |||
55 | #include "gnunet_plugin_lib.h" | 54 | #include "gnunet_plugin_lib.h" |
56 | #include "gnunet_program_lib.h" | 55 | #include "gnunet_program_lib.h" |
57 | #include "gnunet_protocols.h" | 56 | #include "gnunet_protocols.h" |
58 | #include "gnunet_server_lib.h" | ||
59 | #include "gnunet_service_lib.h" | 57 | #include "gnunet_service_lib.h" |
60 | #include "gnunet_signal_lib.h" | 58 | #include "gnunet_signal_lib.h" |
61 | #include "gnunet_strings_lib.h" | 59 | #include "gnunet_strings_lib.h" |
diff --git a/src/multicast/.gitignore b/src/multicast/.gitignore index d38ca9c02..43752ec4b 100644 --- a/src/multicast/.gitignore +++ b/src/multicast/.gitignore | |||
@@ -2,3 +2,4 @@ gnunet-service-multicast | |||
2 | gnunet-multicast | 2 | gnunet-multicast |
3 | test_multicast | 3 | test_multicast |
4 | test_multicast_multipeer | 4 | test_multicast_multipeer |
5 | test_multicast_2peers | ||
diff --git a/src/nat-auto/Makefile.am b/src/nat-auto/Makefile.am index 19695fabd..14f3f2330 100644 --- a/src/nat-auto/Makefile.am +++ b/src/nat-auto/Makefile.am | |||
@@ -37,11 +37,11 @@ lib_LTLIBRARIES = \ | |||
37 | 37 | ||
38 | libgnunetnatauto_la_SOURCES = \ | 38 | libgnunetnatauto_la_SOURCES = \ |
39 | nat_auto_api.c \ | 39 | nat_auto_api.c \ |
40 | nat_auto_api_test.c | 40 | nat_auto_api_test.c |
41 | libgnunetnatauto_la_LIBADD = \ | 41 | libgnunetnatauto_la_LIBADD = \ |
42 | $(top_builddir)/src/nat/libgnunetnatnew.la \ | 42 | $(top_builddir)/src/nat/libgnunetnatnew.la \ |
43 | $(top_builddir)/src/util/libgnunetutil.la \ | 43 | $(top_builddir)/src/util/libgnunetutil.la \ |
44 | $(GN_LIBINTL) @EXT_LIBS@ | 44 | $(GN_LIBINTL) @EXT_LIBS@ |
45 | libgnunetnatauto_la_LDFLAGS = \ | 45 | libgnunetnatauto_la_LDFLAGS = \ |
46 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ | 46 | $(GN_LIB_LDFLAGS) $(WINFLAGS) \ |
47 | -version-info 0:0:0 | 47 | -version-info 0:0:0 |
@@ -55,4 +55,3 @@ gnunet_service_nat_auto_LDADD = \ | |||
55 | $(LIBGCRYPT_LIBS) \ | 55 | $(LIBGCRYPT_LIBS) \ |
56 | -lgcrypt \ | 56 | -lgcrypt \ |
57 | $(GN_LIBINTL) | 57 | $(GN_LIBINTL) |
58 | |||
diff --git a/src/nat-auto/gnunet-nat-server.c b/src/nat-auto/gnunet-nat-server.c index 371e4b27e..590fad4d6 100644 --- a/src/nat-auto/gnunet-nat-server.c +++ b/src/nat-auto/gnunet-nat-server.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2011 GNUnet e.V. | 3 | Copyright (C) 2011, 2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -31,9 +31,21 @@ | |||
31 | 31 | ||
32 | 32 | ||
33 | /** | 33 | /** |
34 | * Our server. | 34 | * Information we track per client. |
35 | */ | 35 | */ |
36 | static struct GNUNET_SERVER_Handle *server; | 36 | struct ClientData |
37 | { | ||
38 | /** | ||
39 | * Timeout task. | ||
40 | */ | ||
41 | struct GNUNET_SCHEDULER_Task *tt; | ||
42 | |||
43 | /** | ||
44 | * Client handle. | ||
45 | */ | ||
46 | struct GNUNET_SERVICE_Client *client; | ||
47 | }; | ||
48 | |||
37 | 49 | ||
38 | /** | 50 | /** |
39 | * Our configuration. | 51 | * Our configuration. |
@@ -248,21 +260,18 @@ try_send_udp (uint32_t dst_ipv4, | |||
248 | * We've received a request to probe a NAT | 260 | * We've received a request to probe a NAT |
249 | * traversal. Do it. | 261 | * traversal. Do it. |
250 | * | 262 | * |
251 | * @param cls unused | 263 | * @param cls handle to client (we always close) |
252 | * @param client handle to client (we always close) | ||
253 | * @param msg message with details about what to test | 264 | * @param msg message with details about what to test |
254 | */ | 265 | */ |
255 | static void | 266 | static void |
256 | test (void *cls, | 267 | handle_test (void *cls, |
257 | struct GNUNET_SERVER_Client *client, | 268 | const struct GNUNET_NAT_AUTO_TestMessage *tm) |
258 | const struct GNUNET_MessageHeader *msg) | ||
259 | { | 269 | { |
260 | const struct GNUNET_NAT_AUTO_TestMessage *tm; | 270 | struct ClientData *cd = cls; |
261 | uint16_t dport; | 271 | uint16_t dport; |
262 | 272 | ||
263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 273 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
264 | "Received test request\n"); | 274 | "Received test request\n"); |
265 | tm = (const struct GNUNET_NAT_AUTO_TestMessage *) msg; | ||
266 | dport = ntohs (tm->dport); | 275 | dport = ntohs (tm->dport); |
267 | if (0 == dport) | 276 | if (0 == dport) |
268 | try_anat (tm->dst_ipv4, | 277 | try_anat (tm->dst_ipv4, |
@@ -276,126 +285,119 @@ test (void *cls, | |||
276 | try_send_udp (tm->dst_ipv4, | 285 | try_send_udp (tm->dst_ipv4, |
277 | dport, | 286 | dport, |
278 | tm->data); | 287 | tm->data); |
279 | GNUNET_SERVER_receive_done (client, | 288 | GNUNET_SERVICE_client_drop (cd->client); |
280 | GNUNET_NO); | ||
281 | } | 289 | } |
282 | 290 | ||
283 | 291 | ||
284 | /** | 292 | /** |
285 | * Task run during shutdown. | 293 | * Main function that will be run. |
286 | * | 294 | * |
287 | * @param cls unused | 295 | * @param cls closure |
296 | * @param c configuration | ||
297 | * @param srv service handle | ||
288 | */ | 298 | */ |
289 | static void | 299 | static void |
290 | shutdown_task (void *cls) | 300 | run (void *cls, |
301 | const struct GNUNET_CONFIGURATION_Handle *c, | ||
302 | struct GNUNET_SERVICE_Handle *srv) | ||
291 | { | 303 | { |
292 | GNUNET_SERVER_destroy (server); | 304 | cfg = c; |
293 | server = NULL; | ||
294 | } | 305 | } |
295 | 306 | ||
296 | 307 | ||
297 | /** | 308 | /** |
298 | * Main function that will be run. | 309 | * Forcefully drops client after 1s. |
299 | * | 310 | * |
300 | * @param cls closure | 311 | * @param cls our `struct ClientData` of a client to drop |
301 | * @param args remaining command-line arguments | ||
302 | * @param cfgfile name of the configuration file used (for saving, can be NULL!) | ||
303 | * @param c configuration | ||
304 | */ | 312 | */ |
305 | static void | 313 | static void |
306 | run (void *cls, | 314 | force_timeout (void *cls) |
307 | char *const *args, | ||
308 | const char *cfgfile, | ||
309 | const struct GNUNET_CONFIGURATION_Handle *c) | ||
310 | { | 315 | { |
311 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | 316 | struct ClientData *cd = cls; |
312 | {&test, NULL, GNUNET_MESSAGE_TYPE_NAT_TEST, | ||
313 | sizeof (struct GNUNET_NAT_AUTO_TestMessage)}, | ||
314 | {NULL, NULL, 0, 0} | ||
315 | }; | ||
316 | unsigned int port; | ||
317 | struct sockaddr_in in4; | ||
318 | struct sockaddr_in6 in6; | ||
319 | |||
320 | socklen_t slen[] = { | ||
321 | sizeof (in4), | ||
322 | sizeof (in6), | ||
323 | 0 | ||
324 | }; | ||
325 | struct sockaddr *sa[] = { | ||
326 | (struct sockaddr *) &in4, | ||
327 | (struct sockaddr *) &in6, | ||
328 | NULL | ||
329 | }; | ||
330 | 317 | ||
331 | cfg = c; | 318 | cd->tt = NULL; |
332 | if ( (NULL == args[0]) || | 319 | GNUNET_SERVICE_client_drop (cd->client); |
333 | (1 != SSCANF (args[0], "%u", &port)) || | ||
334 | (0 == port) || | ||
335 | (65536 <= port) ) | ||
336 | { | ||
337 | FPRINTF (stderr, | ||
338 | _("Please pass valid port number as the first argument! (got `%s')\n"), | ||
339 | args[0]); | ||
340 | return; | ||
341 | } | ||
342 | memset (&in4, 0, sizeof (in4)); | ||
343 | memset (&in6, 0, sizeof (in6)); | ||
344 | in4.sin_family = AF_INET; | ||
345 | in4.sin_port = htons ((uint16_t) port); | ||
346 | in6.sin6_family = AF_INET6; | ||
347 | in6.sin6_port = htons ((uint16_t) port); | ||
348 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
349 | in4.sin_len = sizeof (in4); | ||
350 | in6.sin6_len = sizeof (in6); | ||
351 | #endif | ||
352 | server = GNUNET_SERVER_create (NULL, | ||
353 | NULL, | ||
354 | (struct sockaddr * const *) sa, | ||
355 | slen, | ||
356 | GNUNET_TIME_UNIT_SECONDS, | ||
357 | GNUNET_YES); | ||
358 | GNUNET_SERVER_add_handlers (server, | ||
359 | handlers); | ||
360 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, | ||
361 | NULL); | ||
362 | } | 320 | } |
363 | 321 | ||
364 | 322 | ||
323 | |||
365 | /** | 324 | /** |
366 | * Main function of gnunet-nat-server. | 325 | * Callback called when a client connects to the service. |
367 | * | 326 | * |
368 | * @param argc number of command-line arguments | 327 | * @param cls closure for the service |
369 | * @param argv command line | 328 | * @param c the new client that connected to the service |
370 | * @return 0 on success, -1 on error | 329 | * @param mq the message queue used to send messages to the client |
330 | * @return our `struct ClientData` | ||
371 | */ | 331 | */ |
372 | int | 332 | static void * |
373 | main (int argc, char *const argv[]) | 333 | client_connect_cb (void *cls, |
334 | struct GNUNET_SERVICE_Client *c, | ||
335 | struct GNUNET_MQ_Handle *mq) | ||
374 | { | 336 | { |
375 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 337 | struct ClientData *cd; |
376 | GNUNET_GETOPT_OPTION_END | 338 | |
377 | }; | 339 | cd = GNUNET_new (struct ClientData); |
378 | 340 | cd->client = c; | |
379 | if (GNUNET_OK != | 341 | cd->tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, |
380 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 342 | &force_timeout, |
381 | &argc, &argv)) | 343 | cd); |
382 | return 2; | 344 | return cd; |
383 | 345 | } | |
384 | if (GNUNET_OK != | 346 | |
385 | GNUNET_PROGRAM_run (argc, | 347 | |
386 | argv, | 348 | /** |
387 | "gnunet-nat-server [options] PORT", | 349 | * Callback called when a client disconnected from the service |
388 | _("GNUnet NAT traversal test helper daemon"), | 350 | * |
389 | options, | 351 | * @param cls closure for the service |
390 | &run, | 352 | * @param c the client that disconnected |
391 | NULL)) | 353 | * @param internal_cls our `struct ClientData` |
392 | { | 354 | */ |
393 | GNUNET_free ((void*) argv); | 355 | static void |
394 | return 1; | 356 | client_disconnect_cb (void *cls, |
395 | } | 357 | struct GNUNET_SERVICE_Client *c, |
396 | GNUNET_free ((void*) argv); | 358 | void *internal_cls) |
397 | return 0; | 359 | { |
360 | struct ClientData *cd = internal_cls; | ||
361 | |||
362 | if (NULL != cd->tt) | ||
363 | GNUNET_SCHEDULER_cancel (cd->tt); | ||
364 | GNUNET_free (cd); | ||
398 | } | 365 | } |
399 | 366 | ||
400 | 367 | ||
368 | /** | ||
369 | * Define "main" method using service macro. | ||
370 | */ | ||
371 | GNUNET_SERVICE_MAIN | ||
372 | ("nat-server", | ||
373 | GNUNET_SERVICE_OPTION_NONE, | ||
374 | &run, | ||
375 | &client_connect_cb, | ||
376 | &client_disconnect_cb, | ||
377 | NULL, | ||
378 | GNUNET_MQ_hd_fixed_size (test, | ||
379 | GNUNET_MESSAGE_TYPE_NAT_TEST, | ||
380 | struct GNUNET_NAT_AUTO_TestMessage, | ||
381 | NULL), | ||
382 | GNUNET_MQ_handler_end ()); | ||
383 | |||
384 | |||
385 | #if defined(LINUX) && defined(__GLIBC__) | ||
386 | #include <malloc.h> | ||
387 | |||
388 | /** | ||
389 | * MINIMIZE heap size (way below 128k) since this process doesn't need much. | ||
390 | */ | ||
391 | void __attribute__ ((constructor)) | ||
392 | GNUNET_ARM_memory_init () | ||
393 | { | ||
394 | mallopt (M_TRIM_THRESHOLD, 4 * 1024); | ||
395 | mallopt (M_TOP_PAD, 1 * 1024); | ||
396 | malloc_trim (0); | ||
397 | } | ||
398 | #endif | ||
399 | |||
400 | |||
401 | |||
402 | |||
401 | /* end of gnunet-nat-server.c */ | 403 | /* end of gnunet-nat-server.c */ |
diff --git a/src/psyc/.gitignore b/src/psyc/.gitignore index e12b3210c..14a175367 100644 --- a/src/psyc/.gitignore +++ b/src/psyc/.gitignore | |||
@@ -1 +1,2 @@ | |||
1 | gnunet-service-psyc | 1 | gnunet-service-psyc |
2 | test_psyc | ||
diff --git a/src/psycstore/.gitignore b/src/psycstore/.gitignore index fc2e4cf8e..5ec783202 100644 --- a/src/psycstore/.gitignore +++ b/src/psycstore/.gitignore | |||
@@ -1 +1,5 @@ | |||
1 | gnunet-service-psycstore | 1 | gnunet-service-psycstore |
2 | test_plugin_psycstore_mysql | ||
3 | test_plugin_psycstore_sqlite | ||
4 | test_plugin_psycstore_postgres | ||
5 | test_psycstore | ||
diff --git a/src/psycutil/.gitignore b/src/psycutil/.gitignore new file mode 100644 index 000000000..03d8197fb --- /dev/null +++ b/src/psycutil/.gitignore | |||
@@ -0,0 +1 @@ | |||
test_psyc_env | |||
diff --git a/src/regex/gnunet-service-regex.c b/src/regex/gnunet-service-regex.c index 294670be6..e763bf08d 100644 --- a/src/regex/gnunet-service-regex.c +++ b/src/regex/gnunet-service-regex.c | |||
@@ -37,19 +37,14 @@ struct ClientEntry | |||
37 | { | 37 | { |
38 | 38 | ||
39 | /** | 39 | /** |
40 | * Kept in DLL. | 40 | * Queue for transmissions to @e client. |
41 | */ | 41 | */ |
42 | struct ClientEntry *next; | 42 | struct GNUNET_MQ_Handle *mq; |
43 | |||
44 | /** | ||
45 | * Kept in DLL. | ||
46 | */ | ||
47 | struct ClientEntry *prev; | ||
48 | 43 | ||
49 | /** | 44 | /** |
50 | * Handle identifying the client. | 45 | * Handle identifying the client. |
51 | */ | 46 | */ |
52 | struct GNUNET_SERVER_Client *client; | 47 | struct GNUNET_SERVICE_Client *client; |
53 | 48 | ||
54 | /** | 49 | /** |
55 | * Search handle (if this client is searching). | 50 | * Search handle (if this client is searching). |
@@ -69,7 +64,7 @@ struct ClientEntry | |||
69 | /** | 64 | /** |
70 | * Task for re-announcing. | 65 | * Task for re-announcing. |
71 | */ | 66 | */ |
72 | struct GNUNET_SCHEDULER_Task * refresh_task; | 67 | struct GNUNET_SCHEDULER_Task *refresh_task; |
73 | 68 | ||
74 | }; | 69 | }; |
75 | 70 | ||
@@ -85,70 +80,12 @@ static struct GNUNET_DHT_Handle *dht; | |||
85 | static struct GNUNET_STATISTICS_Handle *stats; | 80 | static struct GNUNET_STATISTICS_Handle *stats; |
86 | 81 | ||
87 | /** | 82 | /** |
88 | * Head of list of clients. | ||
89 | */ | ||
90 | static struct ClientEntry *client_head; | ||
91 | |||
92 | /** | ||
93 | * End of list of clients. | ||
94 | */ | ||
95 | static struct ClientEntry *client_tail; | ||
96 | |||
97 | /** | ||
98 | * Our notification context, used to send back results to the client. | ||
99 | */ | ||
100 | static struct GNUNET_SERVER_NotificationContext *nc; | ||
101 | |||
102 | /** | ||
103 | * Private key for this peer. | 83 | * Private key for this peer. |
104 | */ | 84 | */ |
105 | static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key; | 85 | static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key; |
106 | 86 | ||
107 | 87 | ||
108 | /** | 88 | /** |
109 | * A client disconnected. Remove all of its data structure entries. | ||
110 | * | ||
111 | * @param cls closure, NULL | ||
112 | * @param client identification of the client | ||
113 | */ | ||
114 | static void | ||
115 | handle_client_disconnect (void *cls, | ||
116 | struct GNUNET_SERVER_Client *client) | ||
117 | { | ||
118 | struct ClientEntry *ce; | ||
119 | struct ClientEntry *nx; | ||
120 | |||
121 | nx = client_head; | ||
122 | for (ce = nx; NULL != ce; ce = nx) | ||
123 | { | ||
124 | nx = ce->next; | ||
125 | if (ce->client == client) | ||
126 | { | ||
127 | if (NULL != ce->refresh_task) | ||
128 | { | ||
129 | GNUNET_SCHEDULER_cancel (ce->refresh_task); | ||
130 | ce->refresh_task = NULL; | ||
131 | } | ||
132 | if (NULL != ce->ah) | ||
133 | { | ||
134 | REGEX_INTERNAL_announce_cancel (ce->ah); | ||
135 | ce->ah = NULL; | ||
136 | } | ||
137 | if (NULL != ce->sh) | ||
138 | { | ||
139 | REGEX_INTERNAL_search_cancel (ce->sh); | ||
140 | ce->sh = NULL; | ||
141 | } | ||
142 | GNUNET_CONTAINER_DLL_remove (client_head, | ||
143 | client_tail, | ||
144 | ce); | ||
145 | GNUNET_free (ce); | ||
146 | } | ||
147 | } | ||
148 | } | ||
149 | |||
150 | |||
151 | /** | ||
152 | * Task run during shutdown. | 89 | * Task run during shutdown. |
153 | * | 90 | * |
154 | * @param cls unused | 91 | * @param cls unused |
@@ -156,17 +93,11 @@ handle_client_disconnect (void *cls, | |||
156 | static void | 93 | static void |
157 | cleanup_task (void *cls) | 94 | cleanup_task (void *cls) |
158 | { | 95 | { |
159 | struct ClientEntry *ce; | ||
160 | |||
161 | while (NULL != (ce = client_head)) | ||
162 | handle_client_disconnect (NULL, | ||
163 | ce->client); | ||
164 | GNUNET_DHT_disconnect (dht); | 96 | GNUNET_DHT_disconnect (dht); |
165 | dht = NULL; | 97 | dht = NULL; |
166 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 98 | GNUNET_STATISTICS_destroy (stats, |
99 | GNUNET_NO); | ||
167 | stats = NULL; | 100 | stats = NULL; |
168 | GNUNET_SERVER_notification_context_destroy (nc); | ||
169 | nc = NULL; | ||
170 | GNUNET_free (my_private_key); | 101 | GNUNET_free (my_private_key); |
171 | my_private_key = NULL; | 102 | my_private_key = NULL; |
172 | } | 103 | } |
@@ -191,35 +122,51 @@ reannounce (void *cls) | |||
191 | 122 | ||
192 | 123 | ||
193 | /** | 124 | /** |
194 | * Handle ANNOUNCE message. | 125 | * Check ANNOUNCE message. |
195 | * | 126 | * |
196 | * @param cls closure | 127 | * @param cls identification of the client |
197 | * @param client identification of the client | 128 | * @param am the actual message |
198 | * @param message the actual message | 129 | * @return #GNUNET_OK if @am is well-formed |
199 | */ | 130 | */ |
200 | static void | 131 | static int |
201 | handle_announce (void *cls, | 132 | check_announce (void *cls, |
202 | struct GNUNET_SERVER_Client *client, | 133 | const struct AnnounceMessage *am) |
203 | const struct GNUNET_MessageHeader *message) | ||
204 | { | 134 | { |
205 | const struct AnnounceMessage *am; | 135 | struct ClientEntry *ce = cls; |
206 | const char *regex; | 136 | const char *regex; |
207 | struct ClientEntry *ce; | ||
208 | uint16_t size; | 137 | uint16_t size; |
209 | 138 | ||
210 | size = ntohs (message->size); | 139 | size = ntohs (am->header.size) - sizeof (*am); |
211 | am = (const struct AnnounceMessage *) message; | ||
212 | regex = (const char *) &am[1]; | 140 | regex = (const char *) &am[1]; |
213 | if ( (size <= sizeof (struct AnnounceMessage)) || | 141 | if ('\0' != regex[size - 1]) |
214 | ('\0' != regex[size - sizeof (struct AnnounceMessage) - 1]) ) | ||
215 | { | 142 | { |
216 | GNUNET_break (0); | 143 | GNUNET_break (0); |
217 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 144 | return GNUNET_SYSERR; |
218 | return; | 145 | } |
146 | if (NULL != ce->ah) | ||
147 | { | ||
148 | /* only one announcement per client allowed */ | ||
149 | GNUNET_break (0); | ||
150 | return GNUNET_SYSERR; | ||
219 | } | 151 | } |
152 | return GNUNET_OK; | ||
153 | } | ||
220 | 154 | ||
221 | ce = GNUNET_new (struct ClientEntry); | 155 | |
222 | ce->client = client; | 156 | /** |
157 | * Handle ANNOUNCE message. | ||
158 | * | ||
159 | * @param cls identification of the client | ||
160 | * @param am the actual message | ||
161 | */ | ||
162 | static void | ||
163 | handle_announce (void *cls, | ||
164 | const struct AnnounceMessage *am) | ||
165 | { | ||
166 | struct ClientEntry *ce = cls; | ||
167 | const char *regex; | ||
168 | |||
169 | regex = (const char *) &am[1]; | ||
223 | ce->frequency = GNUNET_TIME_relative_ntoh (am->refresh_delay); | 170 | ce->frequency = GNUNET_TIME_relative_ntoh (am->refresh_delay); |
224 | ce->refresh_task = GNUNET_SCHEDULER_add_delayed (ce->frequency, | 171 | ce->refresh_task = GNUNET_SCHEDULER_add_delayed (ce->frequency, |
225 | &reannounce, | 172 | &reannounce, |
@@ -238,14 +185,11 @@ handle_announce (void *cls, | |||
238 | { | 185 | { |
239 | GNUNET_break (0); | 186 | GNUNET_break (0); |
240 | GNUNET_SCHEDULER_cancel (ce->refresh_task); | 187 | GNUNET_SCHEDULER_cancel (ce->refresh_task); |
241 | GNUNET_free (ce); | 188 | ce->refresh_task = NULL; |
242 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 189 | GNUNET_SERVICE_client_drop (ce->client); |
243 | return; | 190 | return; |
244 | } | 191 | } |
245 | GNUNET_CONTAINER_DLL_insert (client_head, | 192 | GNUNET_SERVICE_client_continue (ce->client); |
246 | client_tail, | ||
247 | ce); | ||
248 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
249 | } | 193 | } |
250 | 194 | ||
251 | 195 | ||
@@ -268,6 +212,7 @@ handle_search_result (void *cls, | |||
268 | unsigned int put_path_length) | 212 | unsigned int put_path_length) |
269 | { | 213 | { |
270 | struct ClientEntry *ce = cls; | 214 | struct ClientEntry *ce = cls; |
215 | struct GNUNET_MQ_Envelope *env; | ||
271 | struct ResultMessage *result; | 216 | struct ResultMessage *result; |
272 | struct GNUNET_PeerIdentity *gp; | 217 | struct GNUNET_PeerIdentity *gp; |
273 | uint16_t size; | 218 | uint16_t size; |
@@ -280,59 +225,73 @@ handle_search_result (void *cls, | |||
280 | GNUNET_break (0); | 225 | GNUNET_break (0); |
281 | return; | 226 | return; |
282 | } | 227 | } |
283 | size = (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity) + sizeof (struct ResultMessage); | 228 | size = (get_path_length + put_path_length) * sizeof (struct GNUNET_PeerIdentity); |
284 | result = GNUNET_malloc (size); | 229 | env = GNUNET_MQ_msg_extra (result, |
285 | result->header.size = htons (size); | 230 | size, |
286 | result->header.type = htons (GNUNET_MESSAGE_TYPE_REGEX_RESULT); | 231 | GNUNET_MESSAGE_TYPE_REGEX_RESULT); |
287 | result->get_path_length = htons ((uint16_t) get_path_length); | 232 | result->get_path_length = htons ((uint16_t) get_path_length); |
288 | result->put_path_length = htons ((uint16_t) put_path_length); | 233 | result->put_path_length = htons ((uint16_t) put_path_length); |
289 | result->id = *id; | 234 | result->id = *id; |
290 | gp = &result->id; | 235 | gp = &result->id; |
291 | GNUNET_memcpy (&gp[1], | 236 | GNUNET_memcpy (&gp[1], |
292 | get_path, | 237 | get_path, |
293 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 238 | get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
294 | GNUNET_memcpy (&gp[1 + get_path_length], | 239 | GNUNET_memcpy (&gp[1 + get_path_length], |
295 | put_path, | 240 | put_path, |
296 | put_path_length * sizeof (struct GNUNET_PeerIdentity)); | 241 | put_path_length * sizeof (struct GNUNET_PeerIdentity)); |
297 | GNUNET_SERVER_notification_context_unicast (nc, | 242 | GNUNET_MQ_send (ce->mq, |
298 | ce->client, | 243 | env); |
299 | &result->header, GNUNET_NO); | ||
300 | GNUNET_free (result); | ||
301 | } | 244 | } |
302 | 245 | ||
303 | 246 | ||
304 | /** | 247 | /** |
305 | * Handle SEARCH message. | 248 | * Check SEARCH message. |
306 | * | 249 | * |
307 | * @param cls closure | 250 | * @param cls identification of the client |
308 | * @param client identification of the client | ||
309 | * @param message the actual message | 251 | * @param message the actual message |
310 | */ | 252 | */ |
311 | static void | 253 | static int |
312 | handle_search (void *cls, | 254 | check_search (void *cls, |
313 | struct GNUNET_SERVER_Client *client, | 255 | const struct RegexSearchMessage *sm) |
314 | const struct GNUNET_MessageHeader *message) | ||
315 | { | 256 | { |
316 | const struct RegexSearchMessage *sm; | 257 | struct ClientEntry *ce = cls; |
317 | const char *string; | 258 | const char *string; |
318 | struct ClientEntry *ce; | ||
319 | uint16_t size; | 259 | uint16_t size; |
320 | 260 | ||
321 | size = ntohs (message->size); | 261 | size = ntohs (sm->header.size) - sizeof (*sm); |
322 | sm = (const struct RegexSearchMessage *) message; | ||
323 | string = (const char *) &sm[1]; | 262 | string = (const char *) &sm[1]; |
324 | if ( (size <= sizeof (struct RegexSearchMessage)) || | 263 | if ('\0' != string[size - 1]) |
325 | ('\0' != string[size - sizeof (struct RegexSearchMessage) - 1]) ) | ||
326 | { | 264 | { |
327 | GNUNET_break (0); | 265 | GNUNET_break (0); |
328 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 266 | return GNUNET_SYSERR; |
329 | return; | ||
330 | } | 267 | } |
268 | if (NULL != ce->sh) | ||
269 | { | ||
270 | /* only one search allowed per client */ | ||
271 | GNUNET_break (0); | ||
272 | return GNUNET_SYSERR; | ||
273 | } | ||
274 | return GNUNET_OK; | ||
275 | } | ||
276 | |||
277 | |||
278 | /** | ||
279 | * Handle SEARCH message. | ||
280 | * | ||
281 | * @param cls identification of the client | ||
282 | * @param message the actual message | ||
283 | */ | ||
284 | static void | ||
285 | handle_search (void *cls, | ||
286 | const struct RegexSearchMessage *sm) | ||
287 | { | ||
288 | struct ClientEntry *ce = cls; | ||
289 | const char *string; | ||
290 | |||
291 | string = (const char *) &sm[1]; | ||
331 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 292 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
332 | "Starting to search for `%s'\n", | 293 | "Starting to search for `%s'\n", |
333 | string); | 294 | string); |
334 | ce = GNUNET_new (struct ClientEntry); | ||
335 | ce->client = client; | ||
336 | ce->sh = REGEX_INTERNAL_search (dht, | 295 | ce->sh = REGEX_INTERNAL_search (dht, |
337 | string, | 296 | string, |
338 | &handle_search_result, | 297 | &handle_search_result, |
@@ -341,15 +300,10 @@ handle_search (void *cls, | |||
341 | if (NULL == ce->sh) | 300 | if (NULL == ce->sh) |
342 | { | 301 | { |
343 | GNUNET_break (0); | 302 | GNUNET_break (0); |
344 | GNUNET_free (ce); | 303 | GNUNET_SERVICE_client_drop (ce->client); |
345 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
346 | return; | 304 | return; |
347 | } | 305 | } |
348 | GNUNET_CONTAINER_DLL_insert (client_head, | 306 | GNUNET_SERVICE_client_continue (ce->client); |
349 | client_tail, | ||
350 | ce); | ||
351 | GNUNET_SERVER_notification_context_add (nc, client); | ||
352 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
353 | } | 307 | } |
354 | 308 | ||
355 | 309 | ||
@@ -357,19 +311,14 @@ handle_search (void *cls, | |||
357 | * Process regex requests. | 311 | * Process regex requests. |
358 | * | 312 | * |
359 | * @param cls closure | 313 | * @param cls closure |
360 | * @param server the initialized server | ||
361 | * @param cfg configuration to use | 314 | * @param cfg configuration to use |
315 | * @param service the initialized service | ||
362 | */ | 316 | */ |
363 | static void | 317 | static void |
364 | run (void *cls, struct GNUNET_SERVER_Handle *server, | 318 | run (void *cls, |
365 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 319 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
320 | struct GNUNET_SERVICE_Handle *service) | ||
366 | { | 321 | { |
367 | static const struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
368 | {&handle_announce, NULL, GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE, 0}, | ||
369 | {&handle_search, NULL, GNUNET_MESSAGE_TYPE_REGEX_SEARCH, 0}, | ||
370 | {NULL, NULL, 0, 0} | ||
371 | }; | ||
372 | |||
373 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); | 322 | my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (cfg); |
374 | if (NULL == my_private_key) | 323 | if (NULL == my_private_key) |
375 | { | 324 | { |
@@ -386,28 +335,84 @@ run (void *cls, struct GNUNET_SERVER_Handle *server, | |||
386 | } | 335 | } |
387 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, | 336 | GNUNET_SCHEDULER_add_shutdown (&cleanup_task, |
388 | NULL); | 337 | NULL); |
389 | nc = GNUNET_SERVER_notification_context_create (server, 1); | ||
390 | stats = GNUNET_STATISTICS_create ("regex", cfg); | 338 | stats = GNUNET_STATISTICS_create ("regex", cfg); |
391 | GNUNET_SERVER_add_handlers (server, handlers); | ||
392 | GNUNET_SERVER_disconnect_notify (server, | ||
393 | &handle_client_disconnect, | ||
394 | NULL); | ||
395 | } | 339 | } |
396 | 340 | ||
397 | 341 | ||
398 | /** | 342 | /** |
399 | * The main function for the regex service. | 343 | * Callback called when a client connects to the service. |
400 | * | 344 | * |
401 | * @param argc number of arguments from the command line | 345 | * @param cls closure for the service |
402 | * @param argv command line arguments | 346 | * @param c the new client that connected to the service |
403 | * @return 0 ok, 1 on error | 347 | * @param mq the message queue used to send messages to the client |
348 | * @return @a c | ||
404 | */ | 349 | */ |
405 | int | 350 | static void * |
406 | main (int argc, char *const *argv) | 351 | client_connect_cb (void *cls, |
352 | struct GNUNET_SERVICE_Client *c, | ||
353 | struct GNUNET_MQ_Handle *mq) | ||
407 | { | 354 | { |
408 | return (GNUNET_OK == | 355 | struct ClientEntry *ce; |
409 | GNUNET_SERVICE_run (argc, argv, "regex", | 356 | |
410 | GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1; | 357 | ce = GNUNET_new (struct ClientEntry); |
358 | ce->client = c; | ||
359 | ce->mq = mq; | ||
360 | return ce; | ||
411 | } | 361 | } |
412 | 362 | ||
363 | |||
364 | /** | ||
365 | * Callback called when a client disconnected from the service | ||
366 | * | ||
367 | * @param cls closure for the service | ||
368 | * @param c the client that disconnected | ||
369 | * @param internal_cls should be equal to @a c | ||
370 | */ | ||
371 | static void | ||
372 | client_disconnect_cb (void *cls, | ||
373 | struct GNUNET_SERVICE_Client *c, | ||
374 | void *internal_cls) | ||
375 | { | ||
376 | struct ClientEntry *ce = internal_cls; | ||
377 | |||
378 | if (NULL != ce->refresh_task) | ||
379 | { | ||
380 | GNUNET_SCHEDULER_cancel (ce->refresh_task); | ||
381 | ce->refresh_task = NULL; | ||
382 | } | ||
383 | if (NULL != ce->ah) | ||
384 | { | ||
385 | REGEX_INTERNAL_announce_cancel (ce->ah); | ||
386 | ce->ah = NULL; | ||
387 | } | ||
388 | if (NULL != ce->sh) | ||
389 | { | ||
390 | REGEX_INTERNAL_search_cancel (ce->sh); | ||
391 | ce->sh = NULL; | ||
392 | } | ||
393 | GNUNET_free (ce); | ||
394 | } | ||
395 | |||
396 | |||
397 | /** | ||
398 | * Define "main" method using service macro. | ||
399 | */ | ||
400 | GNUNET_SERVICE_MAIN | ||
401 | ("regex", | ||
402 | GNUNET_SERVICE_OPTION_NONE, | ||
403 | &run, | ||
404 | &client_connect_cb, | ||
405 | &client_disconnect_cb, | ||
406 | NULL, | ||
407 | GNUNET_MQ_hd_var_size (announce, | ||
408 | GNUNET_MESSAGE_TYPE_REGEX_ANNOUNCE, | ||
409 | struct AnnounceMessage, | ||
410 | NULL), | ||
411 | GNUNET_MQ_hd_var_size (search, | ||
412 | GNUNET_MESSAGE_TYPE_REGEX_SEARCH, | ||
413 | struct RegexSearchMessage, | ||
414 | NULL), | ||
415 | GNUNET_MQ_handler_end ()); | ||
416 | |||
417 | |||
413 | /* end of gnunet-service-regex.c */ | 418 | /* end of gnunet-service-regex.c */ |
diff --git a/src/social/.gitignore b/src/social/.gitignore index 41954615f..875aa1105 100644 --- a/src/social/.gitignore +++ b/src/social/.gitignore | |||
@@ -1,2 +1,3 @@ | |||
1 | gnunet-social | 1 | gnunet-social |
2 | gnunet-service-social | 2 | gnunet-service-social |
3 | test_social | ||
diff --git a/src/testbed-logger/gnunet-service-testbed-logger.c b/src/testbed-logger/gnunet-service-testbed-logger.c index 1c250b306..f915e70af 100644 --- a/src/testbed-logger/gnunet-service-testbed-logger.c +++ b/src/testbed-logger/gnunet-service-testbed-logger.c | |||
@@ -40,42 +40,6 @@ | |||
40 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 40 | LOG (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
41 | 41 | ||
42 | /** | 42 | /** |
43 | * The message queue for sending messages to clients | ||
44 | */ | ||
45 | struct MessageQueue | ||
46 | { | ||
47 | /** | ||
48 | * The message to be sent | ||
49 | */ | ||
50 | struct GNUNET_MessageHeader *msg; | ||
51 | |||
52 | /** | ||
53 | * The client to send the message to | ||
54 | */ | ||
55 | struct GNUNET_SERVER_Client *client; | ||
56 | |||
57 | /** | ||
58 | * next pointer for DLL | ||
59 | */ | ||
60 | struct MessageQueue *next; | ||
61 | |||
62 | /** | ||
63 | * prev pointer for DLL | ||
64 | */ | ||
65 | struct MessageQueue *prev; | ||
66 | }; | ||
67 | |||
68 | /** | ||
69 | * The message queue head | ||
70 | */ | ||
71 | static struct MessageQueue *mq_head; | ||
72 | |||
73 | /** | ||
74 | * The message queue tail | ||
75 | */ | ||
76 | static struct MessageQueue *mq_tail; | ||
77 | |||
78 | /** | ||
79 | * Handle for buffered writing. | 43 | * Handle for buffered writing. |
80 | */ | 44 | */ |
81 | struct GNUNET_BIO_WriteHandle *bio; | 45 | struct GNUNET_BIO_WriteHandle *bio; |
@@ -92,23 +56,38 @@ static int in_shutdown; | |||
92 | 56 | ||
93 | 57 | ||
94 | /** | 58 | /** |
95 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_ADDHOST messages | 59 | * Check #GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG messages |
96 | * | 60 | * |
97 | * @param cls NULL | 61 | * @param cls client identification of the client |
98 | * @param client identification of the client | 62 | * @param msg the actual message |
63 | * @return #GNUNET_OK (they are all always OK) | ||
64 | */ | ||
65 | static int | ||
66 | check_log_msg (void *cls, | ||
67 | const struct GNUNET_MessageHeader *msg) | ||
68 | { | ||
69 | return GNUNET_OK; | ||
70 | } | ||
71 | |||
72 | |||
73 | /** | ||
74 | * Message handler for #GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG messages | ||
75 | * | ||
76 | * @param cls client identification of the client | ||
99 | * @param msg the actual message | 77 | * @param msg the actual message |
100 | */ | 78 | */ |
101 | static void | 79 | static void |
102 | handle_log_msg (void *cls, | 80 | handle_log_msg (void *cls, |
103 | struct GNUNET_SERVER_Client *client, | ||
104 | const struct GNUNET_MessageHeader *msg) | 81 | const struct GNUNET_MessageHeader *msg) |
105 | { | 82 | { |
83 | struct GNUNET_SERVICE_Client *client = cls; | ||
106 | uint16_t ms; | 84 | uint16_t ms; |
107 | 85 | ||
108 | ms = ntohs (msg->size); | 86 | ms = ntohs (msg->size) - sizeof (struct GNUNET_MessageHeader); |
109 | ms -= sizeof (struct GNUNET_MessageHeader); | 87 | GNUNET_BIO_write (bio, |
110 | GNUNET_BIO_write (bio, &msg[1], ms); | 88 | &msg[1], |
111 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | 89 | ms); |
90 | GNUNET_SERVICE_client_continue (client); | ||
112 | } | 91 | } |
113 | 92 | ||
114 | 93 | ||
@@ -120,69 +99,55 @@ handle_log_msg (void *cls, | |||
120 | static void | 99 | static void |
121 | shutdown_task (void *cls) | 100 | shutdown_task (void *cls) |
122 | { | 101 | { |
123 | struct MessageQueue *mq_entry; | ||
124 | |||
125 | in_shutdown = GNUNET_YES; | 102 | in_shutdown = GNUNET_YES; |
126 | if (0 != nconn) | 103 | if (0 != nconn) |
127 | { | 104 | { |
128 | /* Delay shutdown if there are active connections */ | 105 | /* Delay shutdown if there are active connections */ |
129 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 106 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
107 | NULL); | ||
130 | return; | 108 | return; |
131 | } | 109 | } |
132 | while (NULL != (mq_entry = mq_head)) | 110 | GNUNET_break (GNUNET_OK == |
133 | { | 111 | GNUNET_BIO_write_close (bio)); |
134 | GNUNET_free (mq_entry->msg); | ||
135 | GNUNET_SERVER_client_drop (mq_entry->client); | ||
136 | GNUNET_CONTAINER_DLL_remove (mq_head, | ||
137 | mq_tail, | ||
138 | mq_entry); | ||
139 | GNUNET_free (mq_entry); | ||
140 | } | ||
141 | GNUNET_break (GNUNET_OK == GNUNET_BIO_write_close (bio)); | ||
142 | } | 112 | } |
143 | 113 | ||
144 | 114 | ||
145 | /** | 115 | /** |
146 | x * Functions with this signature are called whenever a client | 116 | * Callback called when a client connects to the service. |
147 | * is disconnected on the network level. | ||
148 | * | 117 | * |
149 | * @param cls closure | 118 | * @param cls closure for the service |
150 | * @param client identification of the client; NULL | 119 | * @param c the new client that connected to the service |
151 | * for the last call when the server is destroyed | 120 | * @param mq the message queue used to send messages to the client |
121 | * @return @a c | ||
152 | */ | 122 | */ |
153 | static void | 123 | static void * |
154 | client_disconnected (void *cls, | 124 | client_connect_cb (void *cls, |
155 | struct GNUNET_SERVER_Client *client) | 125 | struct GNUNET_SERVICE_Client *c, |
126 | struct GNUNET_MQ_Handle *mq) | ||
156 | { | 127 | { |
157 | if (NULL == client) | 128 | /* FIXME: is this really what we want here? */ |
158 | { | 129 | GNUNET_SERVICE_client_persist (c); |
159 | GNUNET_break (0 == nconn); | 130 | nconn++; |
160 | return; | 131 | return c; |
161 | } | ||
162 | nconn--; | ||
163 | if (GNUNET_YES == in_shutdown) | ||
164 | GNUNET_SCHEDULER_shutdown (); | ||
165 | } | 132 | } |
166 | 133 | ||
167 | 134 | ||
168 | /** | 135 | /** |
169 | * Functions with this signature are called whenever a client | 136 | * Callback called when a client disconnected from the service |
170 | * is connected on the network level. | ||
171 | * | 137 | * |
172 | * @param cls closure | 138 | * @param cls closure for the service |
173 | * @param client identification of the client | 139 | * @param c the client that disconnected |
140 | * @param internal_cls should be equal to @a c | ||
174 | */ | 141 | */ |
175 | static void | 142 | static void |
176 | client_connected (void *cls, | 143 | client_disconnect_cb (void *cls, |
177 | struct GNUNET_SERVER_Client *client) | 144 | struct GNUNET_SERVICE_Client *c, |
145 | void *internal_cls) | ||
178 | { | 146 | { |
179 | if (NULL == client) | 147 | nconn--; |
180 | { | 148 | if (GNUNET_YES == in_shutdown) |
181 | GNUNET_break (0 == nconn); | 149 | GNUNET_SCHEDULER_shutdown (); |
182 | return; | 150 | GNUNET_assert (c == internal_cls); |
183 | } | ||
184 | GNUNET_SERVER_client_persist_ (client); | ||
185 | nconn++; | ||
186 | } | 151 | } |
187 | 152 | ||
188 | 153 | ||
@@ -190,18 +155,14 @@ client_connected (void *cls, | |||
190 | * Testbed setup | 155 | * Testbed setup |
191 | * | 156 | * |
192 | * @param cls closure | 157 | * @param cls closure |
193 | * @param server the initialized server | ||
194 | * @param cfg configuration to use | 158 | * @param cfg configuration to use |
159 | * @param service the initialized service | ||
195 | */ | 160 | */ |
196 | static void | 161 | static void |
197 | logger_run (void *cls, | 162 | logger_run (void *cls, |
198 | struct GNUNET_SERVER_Handle *server, | 163 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
199 | const struct GNUNET_CONFIGURATION_Handle *cfg) | 164 | struct GNUNET_SERVICE_Handle *service) |
200 | { | 165 | { |
201 | static const struct GNUNET_SERVER_MessageHandler message_handlers[] = { | ||
202 | {&handle_log_msg, NULL, GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, 0}, | ||
203 | {NULL, NULL, 0, 0} | ||
204 | }; | ||
205 | char *dir; | 166 | char *dir; |
206 | char *fn; | 167 | char *fn; |
207 | char *hname; | 168 | char *hname; |
@@ -223,7 +184,8 @@ logger_run (void *cls, | |||
223 | pid = getpid (); | 184 | pid = getpid (); |
224 | hname_len = GNUNET_OS_get_hostname_max_length (); | 185 | hname_len = GNUNET_OS_get_hostname_max_length (); |
225 | hname = GNUNET_malloc (hname_len); | 186 | hname = GNUNET_malloc (hname_len); |
226 | if (0 != gethostname (hname, hname_len)) | 187 | if (0 != gethostname (hname, |
188 | hname_len)) | ||
227 | { | 189 | { |
228 | LOG (GNUNET_ERROR_TYPE_ERROR, | 190 | LOG (GNUNET_ERROR_TYPE_ERROR, |
229 | "Cannot get hostname. Exiting\n"); | 191 | "Cannot get hostname. Exiting\n"); |
@@ -247,24 +209,27 @@ logger_run (void *cls, | |||
247 | return; | 209 | return; |
248 | } | 210 | } |
249 | GNUNET_free (fn); | 211 | GNUNET_free (fn); |
250 | GNUNET_SERVER_add_handlers (server, message_handlers); | 212 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, |
251 | GNUNET_SERVER_connect_notify (server, &client_connected, NULL); | 213 | NULL); |
252 | GNUNET_SERVER_disconnect_notify (server, &client_disconnected, NULL); | ||
253 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | ||
254 | LOG_DEBUG ("TESTBED-LOGGER startup complete\n"); | 214 | LOG_DEBUG ("TESTBED-LOGGER startup complete\n"); |
255 | } | 215 | } |
256 | 216 | ||
257 | 217 | ||
258 | /** | 218 | /** |
259 | * The starting point of execution | 219 | * Define "main" method using service macro. |
260 | */ | 220 | */ |
261 | int | 221 | GNUNET_SERVICE_MAIN |
262 | main (int argc, char *const *argv) | 222 | ("testbed-logger", |
263 | { | 223 | GNUNET_SERVICE_OPTION_NONE, |
264 | return (GNUNET_OK == | 224 | &logger_run, |
265 | GNUNET_SERVICE_run (argc, argv, "testbed-logger", | 225 | &client_connect_cb, |
266 | GNUNET_SERVICE_OPTION_NONE, | 226 | &client_disconnect_cb, |
267 | &logger_run, NULL)) ? 0 : 1; | 227 | NULL, |
268 | } | 228 | GNUNET_MQ_hd_var_size (log_msg, |
229 | GNUNET_MESSAGE_TYPE_TESTBED_LOGGER_MSG, | ||
230 | struct GNUNET_MessageHeader, | ||
231 | NULL), | ||
232 | GNUNET_MQ_handler_end ()); | ||
233 | |||
269 | 234 | ||
270 | /* end of gnunet-service-testbed-logger.c */ | 235 | /* end of gnunet-service-testbed-logger.c */ |
diff --git a/src/testbed-logger/test_testbed_logger_api.c b/src/testbed-logger/test_testbed_logger_api.c index 0ebe0c3f4..e627feeb4 100644 --- a/src/testbed-logger/test_testbed_logger_api.c +++ b/src/testbed-logger/test_testbed_logger_api.c | |||
@@ -258,11 +258,15 @@ main (int argc, char **argv) | |||
258 | GNUNET_log_setup ("test-testbed-logger-api", | 258 | GNUNET_log_setup ("test-testbed-logger-api", |
259 | "WARNING", | 259 | "WARNING", |
260 | NULL); | 260 | NULL); |
261 | GNUNET_break (GNUNET_OK == | ||
262 | GNUNET_DISK_directory_remove ("/tmp/test-testbed")); | ||
261 | ret = GNUNET_TESTING_service_run ("test-testbed-logger", | 263 | ret = GNUNET_TESTING_service_run ("test-testbed-logger", |
262 | "testbed-logger", | 264 | "testbed-logger", |
263 | "test_testbed_logger_api.conf", | 265 | "test_testbed_logger_api.conf", |
264 | &test_main, | 266 | &test_main, |
265 | NULL); | 267 | NULL); |
268 | GNUNET_break (GNUNET_OK == | ||
269 | GNUNET_DISK_directory_remove ("/tmp/test-testbed")); | ||
266 | if (0 != ret) | 270 | if (0 != ret) |
267 | return 1; | 271 | return 1; |
268 | if (GNUNET_OK != result) | 272 | if (GNUNET_OK != result) |
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c index 731944bc4..5d2c1cc37 100644 --- a/src/testbed/testbed_api_hosts.c +++ b/src/testbed/testbed_api_hosts.c | |||
@@ -952,10 +952,11 @@ gen_rsh_suffix_args (const char * const *append_args) | |||
952 | * @param client identification of the client | 952 | * @param client identification of the client |
953 | * @param message the actual message | 953 | * @param message the actual message |
954 | * | 954 | * |
955 | * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing | 955 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing |
956 | */ | 956 | */ |
957 | static int | 957 | static int |
958 | helper_mst (void *cls, void *client, const struct GNUNET_MessageHeader *message) | 958 | helper_mst (void *cls, |
959 | const struct GNUNET_MessageHeader *message) | ||
959 | { | 960 | { |
960 | struct GNUNET_TESTBED_ControllerProc *cp = cls; | 961 | struct GNUNET_TESTBED_ControllerProc *cp = cls; |
961 | const struct GNUNET_TESTBED_HelperReply *msg; | 962 | const struct GNUNET_TESTBED_HelperReply *msg; |
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am index acc2557c6..7687f2348 100644 --- a/src/transport/Makefile.am +++ b/src/transport/Makefile.am | |||
@@ -191,6 +191,8 @@ libexec_PROGRAMS = \ | |||
191 | $(BT_BIN) \ | 191 | $(BT_BIN) \ |
192 | gnunet-service-transport | 192 | gnunet-service-transport |
193 | 193 | ||
194 | |||
195 | |||
194 | bin_PROGRAMS = \ | 196 | bin_PROGRAMS = \ |
195 | gnunet-transport \ | 197 | gnunet-transport \ |
196 | gnunet-transport-certificate-creation | 198 | gnunet-transport-certificate-creation |
@@ -561,7 +563,7 @@ TESTS = \ | |||
561 | $(HTTP_API_TIMEOUT_TEST) \ | 563 | $(HTTP_API_TIMEOUT_TEST) \ |
562 | $(HTTPS_API_TIMEOUT_TEST) \ | 564 | $(HTTPS_API_TIMEOUT_TEST) \ |
563 | $(WLAN_TIMEOUT_TEST) \ | 565 | $(WLAN_TIMEOUT_TEST) \ |
564 | $(BT_TIMEOUT_TEST) | 566 | $(BT_TIMEOUT_TEST) |
565 | if HAVE_GETOPT_BINARY | 567 | if HAVE_GETOPT_BINARY |
566 | TESTS += \ | 568 | TESTS += \ |
567 | test_transport_api_slow_ats | 569 | test_transport_api_slow_ats |
diff --git a/src/transport/gnunet-helper-transport-wlan-dummy.c b/src/transport/gnunet-helper-transport-wlan-dummy.c index 684546314..63ed9c4b7 100644 --- a/src/transport/gnunet-helper-transport-wlan-dummy.c +++ b/src/transport/gnunet-helper-transport-wlan-dummy.c | |||
@@ -120,11 +120,11 @@ send_mac_to_plugin (char *buffer, struct GNUNET_TRANSPORT_WLAN_MacAddress *mac) | |||
120 | * type to the output forward and copy it to the buffer for stdout. | 120 | * type to the output forward and copy it to the buffer for stdout. |
121 | * | 121 | * |
122 | * @param cls the 'struct SendBuffer' to copy the converted message to | 122 | * @param cls the 'struct SendBuffer' to copy the converted message to |
123 | * @param client unused | ||
124 | * @param hdr inbound message from the FIFO | 123 | * @param hdr inbound message from the FIFO |
125 | */ | 124 | */ |
126 | static int | 125 | static int |
127 | stdin_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | 126 | stdin_send (void *cls, |
127 | const struct GNUNET_MessageHeader *hdr) | ||
128 | { | 128 | { |
129 | struct SendBuffer *write_pout = cls; | 129 | struct SendBuffer *write_pout = cls; |
130 | const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; | 130 | const struct GNUNET_TRANSPORT_WLAN_RadiotapSendMessage *in; |
@@ -166,11 +166,11 @@ stdin_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | |||
166 | * We read a full message from stdin. Copy it to our send buffer. | 166 | * We read a full message from stdin. Copy it to our send buffer. |
167 | * | 167 | * |
168 | * @param cls the 'struct SendBuffer' to copy to | 168 | * @param cls the 'struct SendBuffer' to copy to |
169 | * @param client unused | ||
170 | * @param hdr the message we received to copy to the buffer | 169 | * @param hdr the message we received to copy to the buffer |
171 | */ | 170 | */ |
172 | static int | 171 | static int |
173 | file_in_send (void *cls, void *client, const struct GNUNET_MessageHeader *hdr) | 172 | file_in_send (void *cls, |
173 | const struct GNUNET_MessageHeader *hdr) | ||
174 | { | 174 | { |
175 | struct SendBuffer *write_std = cls; | 175 | struct SendBuffer *write_std = cls; |
176 | uint16_t sendsize; | 176 | uint16_t sendsize; |
@@ -213,8 +213,8 @@ main (int argc, char *argv[]) | |||
213 | fd_set wfds; | 213 | fd_set wfds; |
214 | struct timeval tv; | 214 | struct timeval tv; |
215 | int retval; | 215 | int retval; |
216 | struct GNUNET_SERVER_MessageStreamTokenizer *stdin_mst = NULL; | 216 | struct GNUNET_MessageStreamTokenizer *stdin_mst = NULL; |
217 | struct GNUNET_SERVER_MessageStreamTokenizer *file_in_mst = NULL; | 217 | struct GNUNET_MessageStreamTokenizer *file_in_mst = NULL; |
218 | struct GNUNET_TRANSPORT_WLAN_MacAddress macaddr; | 218 | struct GNUNET_TRANSPORT_WLAN_MacAddress macaddr; |
219 | int first; | 219 | int first; |
220 | 220 | ||
@@ -340,8 +340,8 @@ main (int argc, char *argv[]) | |||
340 | write_std.pos = 0; | 340 | write_std.pos = 0; |
341 | write_pout.size = 0; | 341 | write_pout.size = 0; |
342 | write_pout.pos = 0; | 342 | write_pout.pos = 0; |
343 | stdin_mst = GNUNET_SERVER_mst_create (&stdin_send, &write_pout); | 343 | stdin_mst = GNUNET_MST_create (&stdin_send, &write_pout); |
344 | file_in_mst = GNUNET_SERVER_mst_create (&file_in_send, &write_std); | 344 | file_in_mst = GNUNET_MST_create (&file_in_send, &write_std); |
345 | 345 | ||
346 | /* Send 'random' mac address */ | 346 | /* Send 'random' mac address */ |
347 | macaddr.mac[0] = 0x13; | 347 | macaddr.mac[0] = 0x13; |
@@ -453,8 +453,9 @@ main (int argc, char *argv[]) | |||
453 | } | 453 | } |
454 | else if (0 < readsize) | 454 | else if (0 < readsize) |
455 | { | 455 | { |
456 | GNUNET_SERVER_mst_receive (stdin_mst, NULL, readbuf, readsize, | 456 | GNUNET_MST_from_buffer (stdin_mst, |
457 | GNUNET_NO, GNUNET_NO); | 457 | readbuf, readsize, |
458 | GNUNET_NO, GNUNET_NO); | ||
458 | 459 | ||
459 | } | 460 | } |
460 | else | 461 | else |
@@ -475,8 +476,9 @@ main (int argc, char *argv[]) | |||
475 | } | 476 | } |
476 | else if (0 < readsize) | 477 | else if (0 < readsize) |
477 | { | 478 | { |
478 | GNUNET_SERVER_mst_receive (file_in_mst, NULL, readbuf, readsize, | 479 | GNUNET_MST_from_buffer (file_in_mst, |
479 | GNUNET_NO, GNUNET_NO); | 480 | readbuf, readsize, |
481 | GNUNET_NO, GNUNET_NO); | ||
480 | } | 482 | } |
481 | else | 483 | else |
482 | { | 484 | { |
@@ -489,9 +491,9 @@ main (int argc, char *argv[]) | |||
489 | end: | 491 | end: |
490 | /* clean up */ | 492 | /* clean up */ |
491 | if (NULL != stdin_mst) | 493 | if (NULL != stdin_mst) |
492 | GNUNET_SERVER_mst_destroy (stdin_mst); | 494 | GNUNET_MST_destroy (stdin_mst); |
493 | if (NULL != file_in_mst) | 495 | if (NULL != file_in_mst) |
494 | GNUNET_SERVER_mst_destroy (file_in_mst); | 496 | GNUNET_MST_destroy (file_in_mst); |
495 | 497 | ||
496 | if (NULL != fpout) | 498 | if (NULL != fpout) |
497 | fclose (fpout); | 499 | fclose (fpout); |
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index ceed94af8..e91149289 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -221,7 +221,7 @@ struct GNUNET_ATS_Session | |||
221 | /** | 221 | /** |
222 | * Message stream tokenizer for incoming data | 222 | * Message stream tokenizer for incoming data |
223 | */ | 223 | */ |
224 | struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk; | 224 | struct GNUNET_MessageStreamTokenizer *msg_tk; |
225 | 225 | ||
226 | /** | 226 | /** |
227 | * Session timeout task | 227 | * Session timeout task |
@@ -528,7 +528,7 @@ client_delete_session (struct GNUNET_ATS_Session *s) | |||
528 | GNUNET_TRANSPORT_SS_DONE); | 528 | GNUNET_TRANSPORT_SS_DONE); |
529 | if (NULL != s->msg_tk) | 529 | if (NULL != s->msg_tk) |
530 | { | 530 | { |
531 | GNUNET_SERVER_mst_destroy (s->msg_tk); | 531 | GNUNET_MST_destroy (s->msg_tk); |
532 | s->msg_tk = NULL; | 532 | s->msg_tk = NULL; |
533 | } | 533 | } |
534 | GNUNET_HELLO_address_free (s->address); | 534 | GNUNET_HELLO_address_free (s->address); |
@@ -1158,13 +1158,11 @@ client_wake_up (void *cls) | |||
1158 | * Callback for message stream tokenizer | 1158 | * Callback for message stream tokenizer |
1159 | * | 1159 | * |
1160 | * @param cls the session | 1160 | * @param cls the session |
1161 | * @param client not used | ||
1162 | * @param message the message received | 1161 | * @param message the message received |
1163 | * @return always #GNUNET_OK | 1162 | * @return always #GNUNET_OK |
1164 | */ | 1163 | */ |
1165 | static int | 1164 | static int |
1166 | client_receive_mst_cb (void *cls, | 1165 | client_receive_mst_cb (void *cls, |
1167 | void *client, | ||
1168 | const struct GNUNET_MessageHeader *message) | 1166 | const struct GNUNET_MessageHeader *message) |
1169 | { | 1167 | { |
1170 | struct GNUNET_ATS_Session *s = cls; | 1168 | struct GNUNET_ATS_Session *s = cls; |
@@ -1274,14 +1272,13 @@ client_receive (void *stream, | |||
1274 | return CURL_WRITEFUNC_PAUSE; | 1272 | return CURL_WRITEFUNC_PAUSE; |
1275 | } | 1273 | } |
1276 | if (NULL == s->msg_tk) | 1274 | if (NULL == s->msg_tk) |
1277 | s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, | 1275 | s->msg_tk = GNUNET_MST_create (&client_receive_mst_cb, |
1278 | s); | 1276 | s); |
1279 | GNUNET_SERVER_mst_receive (s->msg_tk, | 1277 | GNUNET_MST_from_buffer (s->msg_tk, |
1280 | s, | 1278 | stream, |
1281 | stream, | 1279 | len, |
1282 | len, | 1280 | GNUNET_NO, |
1283 | GNUNET_NO, | 1281 | GNUNET_NO); |
1284 | GNUNET_NO); | ||
1285 | return len; | 1282 | return len; |
1286 | } | 1283 | } |
1287 | 1284 | ||
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index 63c67b81c..2d6f40d58 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -201,7 +201,7 @@ struct GNUNET_ATS_Session | |||
201 | /** | 201 | /** |
202 | * Message stream tokenizer for incoming data | 202 | * Message stream tokenizer for incoming data |
203 | */ | 203 | */ |
204 | struct GNUNET_SERVER_MessageStreamTokenizer *msg_tk; | 204 | struct GNUNET_MessageStreamTokenizer *msg_tk; |
205 | 205 | ||
206 | /** | 206 | /** |
207 | * Client recv handle | 207 | * Client recv handle |
@@ -608,7 +608,7 @@ server_delete_session (struct GNUNET_ATS_Session *s) | |||
608 | } | 608 | } |
609 | if (NULL != s->msg_tk) | 609 | if (NULL != s->msg_tk) |
610 | { | 610 | { |
611 | GNUNET_SERVER_mst_destroy (s->msg_tk); | 611 | GNUNET_MST_destroy (s->msg_tk); |
612 | s->msg_tk = NULL; | 612 | s->msg_tk = NULL; |
613 | } | 613 | } |
614 | GNUNET_HELLO_address_free (s->address); | 614 | GNUNET_HELLO_address_free (s->address); |
@@ -1621,13 +1621,11 @@ server_send_callback (void *cls, | |||
1621 | * Callback called by MessageStreamTokenizer when a message has arrived | 1621 | * Callback called by MessageStreamTokenizer when a message has arrived |
1622 | * | 1622 | * |
1623 | * @param cls current session as closure | 1623 | * @param cls current session as closure |
1624 | * @param client client | ||
1625 | * @param message the message to be forwarded to transport service | 1624 | * @param message the message to be forwarded to transport service |
1626 | * @return #GNUNET_OK | 1625 | * @return #GNUNET_OK |
1627 | */ | 1626 | */ |
1628 | static int | 1627 | static int |
1629 | server_receive_mst_cb (void *cls, | 1628 | server_receive_mst_cb (void *cls, |
1630 | void *client, | ||
1631 | const struct GNUNET_MessageHeader *message) | 1629 | const struct GNUNET_MessageHeader *message) |
1632 | { | 1630 | { |
1633 | struct GNUNET_ATS_Session *s = cls; | 1631 | struct GNUNET_ATS_Session *s = cls; |
@@ -1847,13 +1845,16 @@ server_access_cb (void *cls, | |||
1847 | *upload_data_size); | 1845 | *upload_data_size); |
1848 | if (s->msg_tk == NULL) | 1846 | if (s->msg_tk == NULL) |
1849 | { | 1847 | { |
1850 | s->msg_tk = GNUNET_SERVER_mst_create (&server_receive_mst_cb, s); | 1848 | s->msg_tk = GNUNET_MST_create (&server_receive_mst_cb, |
1849 | s); | ||
1851 | } | 1850 | } |
1852 | GNUNET_SERVER_mst_receive (s->msg_tk, s, upload_data, *upload_data_size, | 1851 | GNUNET_MST_from_buffer (s->msg_tk, |
1853 | GNUNET_NO, GNUNET_NO); | 1852 | upload_data, |
1853 | *upload_data_size, | ||
1854 | GNUNET_NO, GNUNET_NO); | ||
1854 | server_mhd_connection_timeout (plugin, s, | 1855 | server_mhd_connection_timeout (plugin, s, |
1855 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us / 1000LL | 1856 | GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us / 1000LL |
1856 | / 1000LL); | 1857 | / 1000LL); |
1857 | (*upload_data_size) = 0; | 1858 | (*upload_data_size) = 0; |
1858 | } | 1859 | } |
1859 | else | 1860 | else |
@@ -1935,7 +1936,7 @@ server_disconnect_cb (void *cls, | |||
1935 | sc->session->server_recv = NULL; | 1936 | sc->session->server_recv = NULL; |
1936 | if (NULL != sc->session->msg_tk) | 1937 | if (NULL != sc->session->msg_tk) |
1937 | { | 1938 | { |
1938 | GNUNET_SERVER_mst_destroy (sc->session->msg_tk); | 1939 | GNUNET_MST_destroy (sc->session->msg_tk); |
1939 | sc->session->msg_tk = NULL; | 1940 | sc->session->msg_tk = NULL; |
1940 | } | 1941 | } |
1941 | } | 1942 | } |
@@ -2757,7 +2758,7 @@ server_start_report_addresses (struct HTTP_Server_Plugin *plugin) | |||
2757 | return; | 2758 | return; |
2758 | } | 2759 | } |
2759 | 2760 | ||
2760 | plugin->nat | 2761 | plugin->nat |
2761 | = GNUNET_NAT_register (plugin->env->cfg, | 2762 | = GNUNET_NAT_register (plugin->env->cfg, |
2762 | "transport-http_server", | 2763 | "transport-http_server", |
2763 | IPPROTO_TCP, | 2764 | IPPROTO_TCP, |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 34bbd00e0..10ea01cec 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -45,10 +45,495 @@ | |||
45 | */ | 45 | */ |
46 | #define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) | 46 | #define NAT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) |
47 | 47 | ||
48 | GNUNET_NETWORK_STRUCT_BEGIN | 48 | /** |
49 | * Opaque handle that can be used to cancel | ||
50 | * a transmit-ready notification. | ||
51 | */ | ||
52 | struct GNUNET_CONNECTION_TransmitHandle; | ||
53 | |||
54 | /** | ||
55 | * @brief handle for a server | ||
56 | */ | ||
57 | struct GNUNET_SERVER_Handle; | ||
58 | |||
59 | /** | ||
60 | * @brief opaque handle for a client of the server | ||
61 | */ | ||
62 | struct GNUNET_SERVER_Client; | ||
63 | |||
64 | /** | ||
65 | * @brief opaque handle server returns for aborting transmission to a client. | ||
66 | */ | ||
67 | struct GNUNET_SERVER_TransmitHandle; | ||
68 | |||
69 | /** | ||
70 | * @brief handle for a network connection | ||
71 | */ | ||
72 | struct GNUNET_CONNECTION_Handle; | ||
73 | |||
74 | |||
75 | /** | ||
76 | * Function called to notify a client about the connection begin ready | ||
77 | * to queue more data. @a buf will be NULL and @a size zero if the | ||
78 | * connection was closed for writing in the meantime. | ||
79 | * | ||
80 | * @param cls closure | ||
81 | * @param size number of bytes available in @a buf | ||
82 | * @param buf where the callee should write the message | ||
83 | * @return number of bytes written to @a buf | ||
84 | */ | ||
85 | typedef size_t | ||
86 | (*GNUNET_CONNECTION_TransmitReadyNotify) (void *cls, | ||
87 | size_t size, | ||
88 | void *buf); | ||
89 | |||
90 | /** | ||
91 | * Credentials for UNIX domain sockets. | ||
92 | */ | ||
93 | struct GNUNET_CONNECTION_Credentials | ||
94 | { | ||
95 | /** | ||
96 | * UID of the other end of the connection. | ||
97 | */ | ||
98 | uid_t uid; | ||
99 | |||
100 | /** | ||
101 | * GID of the other end of the connection. | ||
102 | */ | ||
103 | gid_t gid; | ||
104 | }; | ||
105 | |||
106 | |||
107 | /** | ||
108 | * Functions with this signature are called whenever a client | ||
109 | * is disconnected on the network level. | ||
110 | * | ||
111 | * @param cls closure | ||
112 | * @param client identification of the client; NULL | ||
113 | * for the last call when the server is destroyed | ||
114 | */ | ||
115 | typedef void | ||
116 | (*GNUNET_SERVER_DisconnectCallback) (void *cls, | ||
117 | struct GNUNET_SERVER_Client *client); | ||
118 | |||
119 | |||
120 | /** | ||
121 | * Functions with this signature are called whenever a client | ||
122 | * is connected on the network level. | ||
123 | * | ||
124 | * @param cls closure | ||
125 | * @param client identification of the client | ||
126 | */ | ||
127 | typedef void | ||
128 | (*GNUNET_SERVER_ConnectCallback) (void *cls, | ||
129 | struct GNUNET_SERVER_Client *client); | ||
130 | |||
131 | |||
49 | 132 | ||
50 | 133 | ||
51 | /** | 134 | /** |
135 | * Function to call for access control checks. | ||
136 | * | ||
137 | * @param cls closure | ||
138 | * @param ucred credentials, if available, otherwise NULL | ||
139 | * @param addr address | ||
140 | * @param addrlen length of address | ||
141 | * @return GNUNET_YES to allow, GNUNET_NO to deny, GNUNET_SYSERR | ||
142 | * for unknown address family (will be denied). | ||
143 | */ | ||
144 | typedef int | ||
145 | (*GNUNET_CONNECTION_AccessCheck) (void *cls, | ||
146 | const struct | ||
147 | GNUNET_CONNECTION_Credentials * | ||
148 | ucred, | ||
149 | const struct sockaddr * addr, | ||
150 | socklen_t addrlen); | ||
151 | |||
152 | /** | ||
153 | * Callback function for data received from the network. Note that | ||
154 | * both "available" and "err" would be 0 if the read simply timed out. | ||
155 | * | ||
156 | * @param cls closure | ||
157 | * @param buf pointer to received data | ||
158 | * @param available number of bytes availabe in "buf", | ||
159 | * possibly 0 (on errors) | ||
160 | * @param addr address of the sender | ||
161 | * @param addrlen size of addr | ||
162 | * @param errCode value of errno (on errors receiving) | ||
163 | */ | ||
164 | typedef void | ||
165 | (*GNUNET_CONNECTION_Receiver) (void *cls, const void *buf, | ||
166 | size_t available, | ||
167 | const struct sockaddr * addr, | ||
168 | socklen_t addrlen, int errCode); | ||
169 | |||
170 | |||
171 | |||
172 | /** | ||
173 | * Close the connection and free associated resources. There must | ||
174 | * not be any pending requests for reading or writing to the | ||
175 | * connection at this time. | ||
176 | * | ||
177 | * @param connection connection to destroy | ||
178 | */ | ||
179 | void | ||
180 | GNUNET_CONNECTION_destroy (struct GNUNET_CONNECTION_Handle *connection); | ||
181 | |||
182 | |||
183 | /** | ||
184 | * Signature of a function to create a custom tokenizer. | ||
185 | * | ||
186 | * @param cls closure from #GNUNET_SERVER_set_callbacks | ||
187 | * @param client handle to client the tokenzier will be used for | ||
188 | * @return handle to custom tokenizer ('mst') | ||
189 | */ | ||
190 | typedef void* | ||
191 | (*GNUNET_SERVER_MstCreateCallback) (void *cls, | ||
192 | struct GNUNET_SERVER_Client *client); | ||
193 | |||
194 | |||
195 | /** | ||
196 | * Signature of a function to destroy a custom tokenizer. | ||
197 | * | ||
198 | * @param cls closure from #GNUNET_SERVER_set_callbacks | ||
199 | * @param mst custom tokenizer handle | ||
200 | */ | ||
201 | typedef void | ||
202 | (*GNUNET_SERVER_MstDestroyCallback) (void *cls, | ||
203 | void *mst); | ||
204 | |||
205 | /** | ||
206 | * Signature of a function to receive data for a custom tokenizer. | ||
207 | * | ||
208 | * @param cls closure from #GNUNET_SERVER_set_callbacks | ||
209 | * @param mst custom tokenizer handle | ||
210 | * @param client_identity ID of client for which this is a buffer, | ||
211 | * can be NULL (will be passed back to 'cb') | ||
212 | * @param buf input data to add | ||
213 | * @param size number of bytes in @a buf | ||
214 | * @param purge should any excess bytes in the buffer be discarded | ||
215 | * (i.e. for packet-based services like UDP) | ||
216 | * @param one_shot only call callback once, keep rest of message in buffer | ||
217 | * @return #GNUNET_OK if we are done processing (need more data) | ||
218 | * #GNUNET_NO if one_shot was set and we have another message ready | ||
219 | * #GNUNET_SYSERR if the data stream is corrupt | ||
220 | */ | ||
221 | typedef int | ||
222 | (*GNUNET_SERVER_MstReceiveCallback) (void *cls, void *mst, | ||
223 | struct GNUNET_SERVER_Client *client, | ||
224 | const char *buf, | ||
225 | size_t size, | ||
226 | int purge, | ||
227 | int one_shot); | ||
228 | /** | ||
229 | * Functions with this signature are called whenever a message is | ||
230 | * received. | ||
231 | * | ||
232 | * @param cls closure | ||
233 | * @param client identification of the client | ||
234 | * @param message the actual message | ||
235 | */ | ||
236 | typedef void | ||
237 | (*GNUNET_SERVER_MessageCallback) (void *cls, | ||
238 | struct GNUNET_SERVER_Client *client, | ||
239 | const struct GNUNET_MessageHeader *message); | ||
240 | |||
241 | /** | ||
242 | * Message handler. Each struct specifies how to handle on particular | ||
243 | * type of message received. | ||
244 | */ | ||
245 | struct GNUNET_SERVER_MessageHandler | ||
246 | { | ||
247 | /** | ||
248 | * Function to call for messages of "type". | ||
249 | */ | ||
250 | GNUNET_SERVER_MessageCallback callback; | ||
251 | |||
252 | /** | ||
253 | * Closure argument for @e callback. | ||
254 | */ | ||
255 | void *callback_cls; | ||
256 | |||
257 | /** | ||
258 | * Type of the message this handler covers. | ||
259 | */ | ||
260 | uint16_t type; | ||
261 | |||
262 | /** | ||
263 | * Expected size of messages of this type. Use 0 for | ||
264 | * variable-size. If non-zero, messages of the given | ||
265 | * type will be discarded (and the connection closed) | ||
266 | * if they do not have the right size. | ||
267 | */ | ||
268 | uint16_t expected_size; | ||
269 | |||
270 | }; | ||
271 | |||
272 | /** | ||
273 | * Ask the server to disconnect from the given client. This is the | ||
274 | * same as passing #GNUNET_SYSERR to #GNUNET_SERVER_receive_done, | ||
275 | * except that it allows dropping of a client even when not handling a | ||
276 | * message from that client. | ||
277 | * | ||
278 | * @param client the client to disconnect from | ||
279 | */ | ||
280 | void | ||
281 | GNUNET_SERVER_client_disconnect (struct GNUNET_SERVER_Client *client); | ||
282 | |||
283 | /** | ||
284 | * Return user context associated with the given client. | ||
285 | * Note: you should probably use the macro (call without the underscore). | ||
286 | * | ||
287 | * @param client client to query | ||
288 | * @param size number of bytes in user context struct (for verification only) | ||
289 | * @return pointer to user context | ||
290 | */ | ||
291 | void * | ||
292 | GNUNET_SERVER_client_get_user_context_ (struct GNUNET_SERVER_Client *client, | ||
293 | size_t size); | ||
294 | |||
295 | |||
296 | /** | ||
297 | * Functions with this signature are called whenever a | ||
298 | * complete message is received by the tokenizer. | ||
299 | * | ||
300 | * Do not call #GNUNET_SERVER_mst_destroy from within | ||
301 | * the scope of this callback. | ||
302 | * | ||
303 | * @param cls closure | ||
304 | * @param client identification of the client | ||
305 | * @param message the actual message | ||
306 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing | ||
307 | */ | ||
308 | typedef int | ||
309 | (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, | ||
310 | void *client, | ||
311 | const struct GNUNET_MessageHeader *message); | ||
312 | |||
313 | |||
314 | /** | ||
315 | * Create a message stream tokenizer. | ||
316 | * | ||
317 | * @param cb function to call on completed messages | ||
318 | * @param cb_cls closure for @a cb | ||
319 | * @return handle to tokenizer | ||
320 | */ | ||
321 | struct GNUNET_SERVER_MessageStreamTokenizer * | ||
322 | GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, | ||
323 | void *cb_cls); | ||
324 | |||
325 | /** | ||
326 | * Add incoming data to the receive buffer and call the | ||
327 | * callback for all complete messages. | ||
328 | * | ||
329 | * @param mst tokenizer to use | ||
330 | * @param client_identity ID of client for which this is a buffer, | ||
331 | * can be NULL (will be passed back to 'cb') | ||
332 | * @param buf input data to add | ||
333 | * @param size number of bytes in @a buf | ||
334 | * @param purge should any excess bytes in the buffer be discarded | ||
335 | * (i.e. for packet-based services like UDP) | ||
336 | * @param one_shot only call callback once, keep rest of message in buffer | ||
337 | * @return #GNUNET_OK if we are done processing (need more data) | ||
338 | * #GNUNET_NO if one_shot was set and we have another message ready | ||
339 | * #GNUNET_SYSERR if the data stream is corrupt | ||
340 | */ | ||
341 | int | ||
342 | GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, | ||
343 | void *client_identity, | ||
344 | const char *buf, size_t size, | ||
345 | int purge, int one_shot); | ||
346 | |||
347 | |||
348 | |||
349 | /** | ||
350 | * Destroys a tokenizer. | ||
351 | * | ||
352 | * @param mst tokenizer to destroy | ||
353 | */ | ||
354 | void | ||
355 | GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst); | ||
356 | |||
357 | |||
358 | /** | ||
359 | * Set user context to be associated with the given client. | ||
360 | * Note: you should probably use the macro (call without the underscore). | ||
361 | * | ||
362 | * @param client client to query | ||
363 | * @param ptr pointer to user context | ||
364 | * @param size number of bytes in user context struct (for verification only) | ||
365 | */ | ||
366 | void | ||
367 | GNUNET_SERVER_client_set_user_context_ (struct GNUNET_SERVER_Client *client, | ||
368 | void *ptr, | ||
369 | size_t size); | ||
370 | /** | ||
371 | * Return user context associated with the given client. | ||
372 | * | ||
373 | * @param client client to query | ||
374 | * @param type expected return type (i.e. 'struct Foo') | ||
375 | * @return pointer to user context of type 'type *'. | ||
376 | */ | ||
377 | #define GNUNET_SERVER_client_get_user_context(client,type) \ | ||
378 | (type *) GNUNET_SERVER_client_get_user_context_ (client, sizeof (type)) | ||
379 | |||
380 | /** | ||
381 | * Set user context to be associated with the given client. | ||
382 | * | ||
383 | * @param client client to query | ||
384 | * @param value pointer to user context | ||
385 | */ | ||
386 | #define GNUNET_SERVER_client_set_user_context(client,value) \ | ||
387 | GNUNET_SERVER_client_set_user_context_ (client, value, sizeof (*value)) | ||
388 | |||
389 | |||
390 | |||
391 | /** | ||
392 | * Notify us when the server has enough space to transmit | ||
393 | * a message of the given size to the given client. | ||
394 | * | ||
395 | * @param client client to transmit message to | ||
396 | * @param size requested amount of buffer space | ||
397 | * @param timeout after how long should we give up (and call | ||
398 | * notify with buf NULL and size 0)? | ||
399 | * @param callback function to call when space is available | ||
400 | * @param callback_cls closure for @a callback | ||
401 | * @return non-NULL if the notify callback was queued; can be used | ||
402 | * to cancel the request using | ||
403 | * #GNUNET_SERVER_notify_transmit_ready_cancel. | ||
404 | * NULL if we are already going to notify someone else (busy) | ||
405 | */ | ||
406 | struct GNUNET_SERVER_TransmitHandle * | ||
407 | GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, | ||
408 | size_t size, | ||
409 | struct GNUNET_TIME_Relative timeout, | ||
410 | GNUNET_CONNECTION_TransmitReadyNotify callback, | ||
411 | void *callback_cls); | ||
412 | |||
413 | /** | ||
414 | * Abort transmission request. | ||
415 | * | ||
416 | * @param th request to abort | ||
417 | */ | ||
418 | void | ||
419 | GNUNET_SERVER_notify_transmit_ready_cancel (struct GNUNET_SERVER_TransmitHandle *th); | ||
420 | |||
421 | |||
422 | |||
423 | |||
424 | /** | ||
425 | * Notify the server that the given client handle should | ||
426 | * be kept (keeps the connection up if possible, increments | ||
427 | * the internal reference counter). | ||
428 | * | ||
429 | * @param client the client to keep | ||
430 | */ | ||
431 | void | ||
432 | GNUNET_SERVER_client_keep (struct GNUNET_SERVER_Client *client); | ||
433 | |||
434 | |||
435 | /** | ||
436 | * Notify the server that the given client handle is no | ||
437 | * longer required. Decrements the reference counter. If | ||
438 | * that counter reaches zero an inactive connection maybe | ||
439 | * closed. | ||
440 | * | ||
441 | * @param client the client to drop | ||
442 | */ | ||
443 | void | ||
444 | GNUNET_SERVER_client_drop (struct GNUNET_SERVER_Client *client); | ||
445 | |||
446 | |||
447 | /** | ||
448 | * Function called by the service's run | ||
449 | * method to run service-specific setup code. | ||
450 | * | ||
451 | * @param cls closure | ||
452 | * @param server the initialized server | ||
453 | * @param cfg configuration to use | ||
454 | */ | ||
455 | typedef void | ||
456 | (*GNUNET_SERVICE_Main) (void *cls, | ||
457 | struct GNUNET_SERVER_Handle *server, | ||
458 | const struct GNUNET_CONFIGURATION_Handle *cfg); | ||
459 | |||
460 | |||
461 | |||
462 | /** | ||
463 | * Suspend accepting connections from the listen socket temporarily. | ||
464 | * Resume activity using #GNUNET_SERVER_resume. | ||
465 | * | ||
466 | * @param server server to stop accepting connections. | ||
467 | */ | ||
468 | void | ||
469 | GNUNET_SERVER_suspend (struct GNUNET_SERVER_Handle *server); | ||
470 | |||
471 | /** | ||
472 | * Notify us when the server has enough space to transmit | ||
473 | * a message of the given size to the given client. | ||
474 | * | ||
475 | * @param client client to transmit message to | ||
476 | * @param size requested amount of buffer space | ||
477 | * @param timeout after how long should we give up (and call | ||
478 | * notify with buf NULL and size 0)? | ||
479 | * @param callback function to call when space is available | ||
480 | * @param callback_cls closure for @a callback | ||
481 | * @return non-NULL if the notify callback was queued; can be used | ||
482 | * to cancel the request using | ||
483 | * #GNUNET_SERVER_notify_transmit_ready_cancel. | ||
484 | * NULL if we are already going to notify someone else (busy) | ||
485 | */ | ||
486 | struct GNUNET_SERVER_TransmitHandle * | ||
487 | GNUNET_SERVER_notify_transmit_ready (struct GNUNET_SERVER_Client *client, | ||
488 | size_t size, | ||
489 | struct GNUNET_TIME_Relative timeout, | ||
490 | GNUNET_CONNECTION_TransmitReadyNotify callback, | ||
491 | void *callback_cls); | ||
492 | |||
493 | |||
494 | /** | ||
495 | * Add a TCP socket-based connection to the set of handles managed by | ||
496 | * this server. Use this function for outgoing (P2P) connections that | ||
497 | * we initiated (and where this server should process incoming | ||
498 | * messages). | ||
499 | * | ||
500 | * @param server the server to use | ||
501 | * @param connection the connection to manage (client must | ||
502 | * stop using this connection from now on) | ||
503 | * @return the client handle | ||
504 | */ | ||
505 | struct GNUNET_SERVER_Client * | ||
506 | GNUNET_SERVER_connect_socket (struct GNUNET_SERVER_Handle *server, | ||
507 | struct GNUNET_CONNECTION_Handle *connection); | ||
508 | |||
509 | |||
510 | /** | ||
511 | * Resume accepting connections from the listen socket. | ||
512 | * | ||
513 | * @param server server to resume accepting connections. | ||
514 | */ | ||
515 | void | ||
516 | GNUNET_SERVER_resume (struct GNUNET_SERVER_Handle *server); | ||
517 | |||
518 | /** | ||
519 | * Free resources held by this server. | ||
520 | * | ||
521 | * @param server server to destroy | ||
522 | */ | ||
523 | void | ||
524 | GNUNET_SERVER_destroy (struct GNUNET_SERVER_Handle *server); | ||
525 | |||
526 | |||
527 | |||
528 | |||
529 | #include "tcp_connection_legacy.c" | ||
530 | #include "tcp_server_mst_legacy.c" | ||
531 | #include "tcp_server_legacy.c" | ||
532 | #include "tcp_service_legacy.c" | ||
533 | |||
534 | GNUNET_NETWORK_STRUCT_BEGIN | ||
535 | |||
536 | /** | ||
52 | * Initial handshake message for a session. | 537 | * Initial handshake message for a session. |
53 | */ | 538 | */ |
54 | struct WelcomeMessage | 539 | struct WelcomeMessage |
@@ -521,47 +1006,6 @@ struct Plugin | |||
521 | }; | 1006 | }; |
522 | 1007 | ||
523 | 1008 | ||
524 | /* begin of ancient copy-and-pasted code that should be | ||
525 | specialized for TCP ...*/ | ||
526 | /** | ||
527 | * Add the given UNIX domain path as an address to the | ||
528 | * list (as the first entry). | ||
529 | * | ||
530 | * @param saddrs array to update | ||
531 | * @param saddrlens where to store the address length | ||
532 | * @param unixpath path to add | ||
533 | * @param abstract #GNUNET_YES to add an abstract UNIX domain socket. This | ||
534 | * parameter is ignore on systems other than LINUX | ||
535 | */ | ||
536 | static void | ||
537 | add_unixpath (struct sockaddr **saddrs, | ||
538 | socklen_t *saddrlens, | ||
539 | const char *unixpath, | ||
540 | int abstract) | ||
541 | { | ||
542 | #ifdef AF_UNIX | ||
543 | struct sockaddr_un *un; | ||
544 | |||
545 | un = GNUNET_new (struct sockaddr_un); | ||
546 | un->sun_family = AF_UNIX; | ||
547 | strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1); | ||
548 | #ifdef LINUX | ||
549 | if (GNUNET_YES == abstract) | ||
550 | un->sun_path[0] = '\0'; | ||
551 | #endif | ||
552 | #if HAVE_SOCKADDR_UN_SUN_LEN | ||
553 | un->sun_len = (u_char) sizeof (struct sockaddr_un); | ||
554 | #endif | ||
555 | *saddrs = (struct sockaddr *) un; | ||
556 | *saddrlens = sizeof (struct sockaddr_un); | ||
557 | #else | ||
558 | /* this function should never be called | ||
559 | * unless AF_UNIX is defined! */ | ||
560 | GNUNET_assert (0); | ||
561 | #endif | ||
562 | } | ||
563 | |||
564 | |||
565 | /** | 1009 | /** |
566 | * Get the list of addresses that a server for the given service | 1010 | * Get the list of addresses that a server for the given service |
567 | * should bind to. | 1011 | * should bind to. |
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index eb48341b7..3a9013a5a 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -159,6 +159,11 @@ struct GNUNET_ATS_Session | |||
159 | struct GNUNET_PeerIdentity target; | 159 | struct GNUNET_PeerIdentity target; |
160 | 160 | ||
161 | /** | 161 | /** |
162 | * Tokenizer for inbound messages. | ||
163 | */ | ||
164 | struct GNUNET_MessageStreamTokenizer *mst; | ||
165 | |||
166 | /** | ||
162 | * Plugin this session belongs to. | 167 | * Plugin this session belongs to. |
163 | */ | 168 | */ |
164 | struct Plugin *plugin; | 169 | struct Plugin *plugin; |
@@ -626,6 +631,11 @@ free_session (struct GNUNET_ATS_Session *s) | |||
626 | GNUNET_free (s->frag_ctx); | 631 | GNUNET_free (s->frag_ctx); |
627 | s->frag_ctx = NULL; | 632 | s->frag_ctx = NULL; |
628 | } | 633 | } |
634 | if (NULL != s->mst) | ||
635 | { | ||
636 | GNUNET_MST_destroy (s->mst); | ||
637 | s->mst = NULL; | ||
638 | } | ||
629 | GNUNET_free (s); | 639 | GNUNET_free (s); |
630 | } | 640 | } |
631 | 641 | ||
@@ -2499,18 +2509,16 @@ read_process_ack (struct Plugin *plugin, | |||
2499 | * Message tokenizer has broken up an incomming message. Pass it on | 2509 | * Message tokenizer has broken up an incomming message. Pass it on |
2500 | * to the service. | 2510 | * to the service. |
2501 | * | 2511 | * |
2502 | * @param cls the `struct Plugin *` | 2512 | * @param cls the `struct GNUNET_ATS_Session *` |
2503 | * @param client the `struct GNUNET_ATS_Session *` | ||
2504 | * @param hdr the actual message | 2513 | * @param hdr the actual message |
2505 | * @return #GNUNET_OK (always) | 2514 | * @return #GNUNET_OK (always) |
2506 | */ | 2515 | */ |
2507 | static int | 2516 | static int |
2508 | process_inbound_tokenized_messages (void *cls, | 2517 | process_inbound_tokenized_messages (void *cls, |
2509 | void *client, | ||
2510 | const struct GNUNET_MessageHeader *hdr) | 2518 | const struct GNUNET_MessageHeader *hdr) |
2511 | { | 2519 | { |
2512 | struct Plugin *plugin = cls; | 2520 | struct GNUNET_ATS_Session *session = cls; |
2513 | struct GNUNET_ATS_Session *session = client; | 2521 | struct Plugin *plugin = session->plugin; |
2514 | 2522 | ||
2515 | if (GNUNET_YES == session->in_destroy) | 2523 | if (GNUNET_YES == session->in_destroy) |
2516 | return GNUNET_OK; | 2524 | return GNUNET_OK; |
@@ -2626,6 +2634,8 @@ udp_plugin_create_session (void *cls, | |||
2626 | struct GNUNET_ATS_Session *s; | 2634 | struct GNUNET_ATS_Session *s; |
2627 | 2635 | ||
2628 | s = GNUNET_new (struct GNUNET_ATS_Session); | 2636 | s = GNUNET_new (struct GNUNET_ATS_Session); |
2637 | s->mst = GNUNET_MST_create (&process_inbound_tokenized_messages, | ||
2638 | s); | ||
2629 | s->plugin = plugin; | 2639 | s->plugin = plugin; |
2630 | s->address = GNUNET_HELLO_address_copy (address); | 2640 | s->address = GNUNET_HELLO_address_copy (address); |
2631 | s->target = address->peer; | 2641 | s->target = address->peer; |
@@ -2792,12 +2802,11 @@ process_udp_message (struct Plugin *plugin, | |||
2792 | GNUNET_free (address); | 2802 | GNUNET_free (address); |
2793 | 2803 | ||
2794 | s->rc++; | 2804 | s->rc++; |
2795 | GNUNET_SERVER_mst_receive (plugin->mst, | 2805 | GNUNET_MST_from_buffer (s->mst, |
2796 | s, | 2806 | (const char *) &msg[1], |
2797 | (const char *) &msg[1], | 2807 | ntohs (msg->header.size) - sizeof(struct UDPMessage), |
2798 | ntohs (msg->header.size) - sizeof(struct UDPMessage), | 2808 | GNUNET_YES, |
2799 | GNUNET_YES, | 2809 | GNUNET_NO); |
2800 | GNUNET_NO); | ||
2801 | s->rc--; | 2810 | s->rc--; |
2802 | if ( (0 == s->rc) && | 2811 | if ( (0 == s->rc) && |
2803 | (GNUNET_YES == s->in_destroy) ) | 2812 | (GNUNET_YES == s->in_destroy) ) |
@@ -3990,8 +3999,6 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3990 | p->sessions = GNUNET_CONTAINER_multipeermap_create (16, | 3999 | p->sessions = GNUNET_CONTAINER_multipeermap_create (16, |
3991 | GNUNET_NO); | 4000 | GNUNET_NO); |
3992 | p->defrag_ctxs = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 4001 | p->defrag_ctxs = GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
3993 | p->mst = GNUNET_SERVER_mst_create (&process_inbound_tokenized_messages, | ||
3994 | p); | ||
3995 | GNUNET_BANDWIDTH_tracker_init (&p->tracker, | 4002 | GNUNET_BANDWIDTH_tracker_init (&p->tracker, |
3996 | NULL, | 4003 | NULL, |
3997 | NULL, | 4004 | NULL, |
@@ -4008,7 +4015,6 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
4008 | _("Failed to create UDP network sockets\n")); | 4015 | _("Failed to create UDP network sockets\n")); |
4009 | GNUNET_CONTAINER_multipeermap_destroy (p->sessions); | 4016 | GNUNET_CONTAINER_multipeermap_destroy (p->sessions); |
4010 | GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); | 4017 | GNUNET_CONTAINER_heap_destroy (p->defrag_ctxs); |
4011 | GNUNET_SERVER_mst_destroy (p->mst); | ||
4012 | if (NULL != p->nat) | 4018 | if (NULL != p->nat) |
4013 | GNUNET_NAT_unregister (p->nat); | 4019 | GNUNET_NAT_unregister (p->nat); |
4014 | GNUNET_free (p); | 4020 | GNUNET_free (p); |
@@ -4120,11 +4126,6 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
4120 | GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); | 4126 | GNUNET_CONTAINER_heap_destroy (plugin->defrag_ctxs); |
4121 | plugin->defrag_ctxs = NULL; | 4127 | plugin->defrag_ctxs = NULL; |
4122 | } | 4128 | } |
4123 | if (NULL != plugin->mst) | ||
4124 | { | ||
4125 | GNUNET_SERVER_mst_destroy (plugin->mst); | ||
4126 | plugin->mst = NULL; | ||
4127 | } | ||
4128 | while (NULL != (udpw = plugin->ipv4_queue_head)) | 4129 | while (NULL != (udpw = plugin->ipv4_queue_head)) |
4129 | { | 4130 | { |
4130 | dequeue (plugin, | 4131 | dequeue (plugin, |
diff --git a/src/transport/plugin_transport_udp.h b/src/transport/plugin_transport_udp.h index 152b16099..48c7365c7 100644 --- a/src/transport/plugin_transport_udp.h +++ b/src/transport/plugin_transport_udp.h | |||
@@ -164,11 +164,6 @@ struct Plugin | |||
164 | struct GNUNET_SCHEDULER_Task *select_task_v6; | 164 | struct GNUNET_SCHEDULER_Task *select_task_v6; |
165 | 165 | ||
166 | /** | 166 | /** |
167 | * Tokenizer for inbound messages. | ||
168 | */ | ||
169 | struct GNUNET_SERVER_MessageStreamTokenizer *mst; | ||
170 | |||
171 | /** | ||
172 | * Bandwidth tracker to limit global UDP traffic. | 167 | * Bandwidth tracker to limit global UDP traffic. |
173 | */ | 168 | */ |
174 | struct GNUNET_BANDWIDTH_Tracker tracker; | 169 | struct GNUNET_BANDWIDTH_Tracker tracker; |
@@ -192,7 +187,7 @@ struct Plugin | |||
192 | * Handle to NAT traversal support. | 187 | * Handle to NAT traversal support. |
193 | */ | 188 | */ |
194 | struct GNUNET_NAT_STUN_Handle *stun; | 189 | struct GNUNET_NAT_STUN_Handle *stun; |
195 | 190 | ||
196 | /** | 191 | /** |
197 | * The read socket for IPv4 | 192 | * The read socket for IPv4 |
198 | */ | 193 | */ |
@@ -204,11 +199,6 @@ struct Plugin | |||
204 | struct GNUNET_NETWORK_Handle *sockv6; | 199 | struct GNUNET_NETWORK_Handle *sockv6; |
205 | 200 | ||
206 | /** | 201 | /** |
207 | * Tokenizer for inbound messages. | ||
208 | */ | ||
209 | struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_mst; | ||
210 | |||
211 | /** | ||
212 | * Head of DLL of broadcast addresses | 202 | * Head of DLL of broadcast addresses |
213 | */ | 203 | */ |
214 | struct BroadcastAddress *broadcast_tail; | 204 | struct BroadcastAddress *broadcast_tail; |
diff --git a/src/transport/plugin_transport_udp_broadcasting.c b/src/transport/plugin_transport_udp_broadcasting.c index a440830fd..c6ddbce9b 100644 --- a/src/transport/plugin_transport_udp_broadcasting.c +++ b/src/transport/plugin_transport_udp_broadcasting.c | |||
@@ -133,11 +133,10 @@ struct MstContext | |||
133 | */ | 133 | */ |
134 | static int | 134 | static int |
135 | broadcast_mst_cb (void *cls, | 135 | broadcast_mst_cb (void *cls, |
136 | void *client, | ||
137 | const struct GNUNET_MessageHeader *message) | 136 | const struct GNUNET_MessageHeader *message) |
138 | { | 137 | { |
139 | struct Plugin *plugin = cls; | 138 | struct MstContext *mc = cls; |
140 | struct MstContext *mc = client; | 139 | struct Plugin *plugin = mc->plugin; |
141 | struct GNUNET_HELLO_Address *address; | 140 | struct GNUNET_HELLO_Address *address; |
142 | const struct GNUNET_MessageHeader *hello; | 141 | const struct GNUNET_MessageHeader *hello; |
143 | const struct UDP_Beacon_Message *msg; | 142 | const struct UDP_Beacon_Message *msg; |
@@ -191,16 +190,20 @@ udp_broadcast_receive (struct Plugin *plugin, | |||
191 | size_t udp_addr_len, | 190 | size_t udp_addr_len, |
192 | enum GNUNET_ATS_Network_Type network_type) | 191 | enum GNUNET_ATS_Network_Type network_type) |
193 | { | 192 | { |
193 | struct GNUNET_MessageStreamTokenizer *broadcast_mst; | ||
194 | struct MstContext mc; | 194 | struct MstContext mc; |
195 | 195 | ||
196 | broadcast_mst = GNUNET_MST_create (&broadcast_mst_cb, | ||
197 | &mc); | ||
198 | mc.plugin = plugin; | ||
196 | mc.udp_addr = udp_addr; | 199 | mc.udp_addr = udp_addr; |
197 | mc.udp_addr_len = udp_addr_len; | 200 | mc.udp_addr_len = udp_addr_len; |
198 | mc.ats_address_network_type = network_type; | 201 | mc.ats_address_network_type = network_type; |
199 | GNUNET_SERVER_mst_receive (plugin->broadcast_mst, | 202 | GNUNET_MST_from_buffer (broadcast_mst, |
200 | &mc, | 203 | buf, size, |
201 | buf, size, | 204 | GNUNET_NO, |
202 | GNUNET_NO, | 205 | GNUNET_NO); |
203 | GNUNET_NO); | 206 | GNUNET_MST_destroy (broadcast_mst); |
204 | } | 207 | } |
205 | 208 | ||
206 | 209 | ||
@@ -546,10 +549,6 @@ setup_broadcast (struct Plugin *plugin, | |||
546 | return; | 549 | return; |
547 | } | 550 | } |
548 | 551 | ||
549 | /* always create tokenizers */ | ||
550 | plugin->broadcast_mst = | ||
551 | GNUNET_SERVER_mst_create (&broadcast_mst_cb, plugin); | ||
552 | |||
553 | if (GNUNET_YES != plugin->enable_broadcasting) | 552 | if (GNUNET_YES != plugin->enable_broadcasting) |
554 | return; /* We do not send, just receive */ | 553 | return; /* We do not send, just receive */ |
555 | 554 | ||
@@ -636,13 +635,6 @@ stop_broadcast (struct Plugin *plugin) | |||
636 | GNUNET_free (p); | 635 | GNUNET_free (p); |
637 | } | 636 | } |
638 | } | 637 | } |
639 | |||
640 | /* Destroy MSTs */ | ||
641 | if (NULL != plugin->broadcast_mst) | ||
642 | { | ||
643 | GNUNET_SERVER_mst_destroy (plugin->broadcast_mst); | ||
644 | plugin->broadcast_mst = NULL; | ||
645 | } | ||
646 | } | 638 | } |
647 | 639 | ||
648 | /* end of plugin_transport_udp_broadcasting.c */ | 640 | /* end of plugin_transport_udp_broadcasting.c */ |
diff --git a/src/transport/plugin_transport_wlan.c b/src/transport/plugin_transport_wlan.c index 376065d24..3f5ada10b 100644 --- a/src/transport/plugin_transport_wlan.c +++ b/src/transport/plugin_transport_wlan.c | |||
@@ -38,6 +38,7 @@ | |||
38 | #include "gnunet_fragmentation_lib.h" | 38 | #include "gnunet_fragmentation_lib.h" |
39 | #include "gnunet_constants.h" | 39 | #include "gnunet_constants.h" |
40 | 40 | ||
41 | |||
41 | #if BUILD_WLAN | 42 | #if BUILD_WLAN |
42 | /* begin case wlan */ | 43 | /* begin case wlan */ |
43 | #define PLUGIN_NAME "wlan" | 44 | #define PLUGIN_NAME "wlan" |
@@ -48,6 +49,7 @@ | |||
48 | #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_wlan_done | 49 | #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_wlan_done |
49 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-wlan",__VA_ARGS__) | 50 | #define LOG(kind,...) GNUNET_log_from (kind, "transport-wlan",__VA_ARGS__) |
50 | 51 | ||
52 | |||
51 | /** | 53 | /** |
52 | * time out of a mac endpoint | 54 | * time out of a mac endpoint |
53 | */ | 55 | */ |
@@ -92,6 +94,30 @@ | |||
92 | #error need to build wlan or bluetooth | 94 | #error need to build wlan or bluetooth |
93 | #endif | 95 | #endif |
94 | 96 | ||
97 | |||
98 | |||
99 | /** | ||
100 | * Functions with this signature are called whenever a | ||
101 | * complete message is received by the tokenizer. | ||
102 | * | ||
103 | * Do not call #GNUNET_SERVER_mst_destroy from within | ||
104 | * the scope of this callback. | ||
105 | * | ||
106 | * @param cls closure | ||
107 | * @param client identification of the client | ||
108 | * @param message the actual message | ||
109 | * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing | ||
110 | */ | ||
111 | typedef int | ||
112 | (*GNUNET_SERVER_MessageTokenizerCallback) (void *cls, | ||
113 | void *client, | ||
114 | const struct GNUNET_MessageHeader *message); | ||
115 | |||
116 | |||
117 | /* Include legacy message stream tokenizer that was removed from util (for now) */ | ||
118 | #include "tcp_server_mst_legacy.c" | ||
119 | |||
120 | |||
95 | /** | 121 | /** |
96 | * Max size of packet (that we give to the WLAN driver for transmission) | 122 | * Max size of packet (that we give to the WLAN driver for transmission) |
97 | */ | 123 | */ |
@@ -1728,11 +1754,10 @@ send_hello_beacon (void *cls) | |||
1728 | * Function used for to process the data from the suid process | 1754 | * Function used for to process the data from the suid process |
1729 | * | 1755 | * |
1730 | * @param cls the plugin handle | 1756 | * @param cls the plugin handle |
1731 | * @param client client that send the data (not used) | ||
1732 | * @param hdr header of the GNUNET_MessageHeader | 1757 | * @param hdr header of the GNUNET_MessageHeader |
1733 | */ | 1758 | */ |
1734 | static int | 1759 | static int |
1735 | handle_helper_message (void *cls, void *client, | 1760 | handle_helper_message (void *cls, |
1736 | const struct GNUNET_MessageHeader *hdr) | 1761 | const struct GNUNET_MessageHeader *hdr) |
1737 | { | 1762 | { |
1738 | struct Plugin *plugin = cls; | 1763 | struct Plugin *plugin = cls; |
diff --git a/src/util/connection.c b/src/transport/tcp_connection_legacy.c index e822b264f..f5253445d 100644 --- a/src/util/connection.c +++ b/src/transport/tcp_connection_legacy.c | |||
@@ -35,7 +35,6 @@ | |||
35 | #include "gnunet_resolver_service.h" | 35 | #include "gnunet_resolver_service.h" |
36 | 36 | ||
37 | 37 | ||
38 | #define LOG(kind,...) GNUNET_log_from (kind, "util-connection", __VA_ARGS__) | ||
39 | 38 | ||
40 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-connection", syscall) | 39 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-connection", syscall) |
41 | 40 | ||
diff --git a/src/util/server.c b/src/transport/tcp_server_legacy.c index 83c30e328..c055285b1 100644 --- a/src/util/server.c +++ b/src/transport/tcp_server_legacy.c | |||
@@ -28,10 +28,6 @@ | |||
28 | #include "gnunet_util_lib.h" | 28 | #include "gnunet_util_lib.h" |
29 | #include "gnunet_protocols.h" | 29 | #include "gnunet_protocols.h" |
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from (kind, "util-server", __VA_ARGS__) | ||
32 | |||
33 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-server", syscall) | ||
34 | |||
35 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-server", syscall, filename) | 31 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-server", syscall, filename) |
36 | 32 | ||
37 | 33 | ||
diff --git a/src/transport/tcp_server_mst_legacy.c b/src/transport/tcp_server_mst_legacy.c new file mode 100644 index 000000000..ba42b1837 --- /dev/null +++ b/src/transport/tcp_server_mst_legacy.c | |||
@@ -0,0 +1,311 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2010 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file util/server_mst.c | ||
23 | * @brief convenience functions for handling inbound message buffers | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_util_lib.h" | ||
29 | |||
30 | |||
31 | #if HAVE_UNALIGNED_64_ACCESS | ||
32 | #define ALIGN_FACTOR 4 | ||
33 | #else | ||
34 | #define ALIGN_FACTOR 8 | ||
35 | #endif | ||
36 | |||
37 | |||
38 | /** | ||
39 | * Handle to a message stream tokenizer. | ||
40 | */ | ||
41 | struct GNUNET_SERVER_MessageStreamTokenizer | ||
42 | { | ||
43 | |||
44 | /** | ||
45 | * Function to call on completed messages. | ||
46 | */ | ||
47 | GNUNET_SERVER_MessageTokenizerCallback cb; | ||
48 | |||
49 | /** | ||
50 | * Closure for @e cb. | ||
51 | */ | ||
52 | void *cb_cls; | ||
53 | |||
54 | /** | ||
55 | * Size of the buffer (starting at @e hdr). | ||
56 | */ | ||
57 | size_t curr_buf; | ||
58 | |||
59 | /** | ||
60 | * How many bytes in buffer have we already processed? | ||
61 | */ | ||
62 | size_t off; | ||
63 | |||
64 | /** | ||
65 | * How many bytes in buffer are valid right now? | ||
66 | */ | ||
67 | size_t pos; | ||
68 | |||
69 | /** | ||
70 | * Beginning of the buffer. Typed like this to force alignment. | ||
71 | */ | ||
72 | struct GNUNET_MessageHeader *hdr; | ||
73 | |||
74 | }; | ||
75 | |||
76 | |||
77 | |||
78 | /** | ||
79 | * Create a message stream tokenizer. | ||
80 | * | ||
81 | * @param cb function to call on completed messages | ||
82 | * @param cb_cls closure for @a cb | ||
83 | * @return handle to tokenizer | ||
84 | */ | ||
85 | struct GNUNET_SERVER_MessageStreamTokenizer * | ||
86 | GNUNET_SERVER_mst_create (GNUNET_SERVER_MessageTokenizerCallback cb, | ||
87 | void *cb_cls) | ||
88 | { | ||
89 | struct GNUNET_SERVER_MessageStreamTokenizer *ret; | ||
90 | |||
91 | ret = GNUNET_new (struct GNUNET_SERVER_MessageStreamTokenizer); | ||
92 | ret->hdr = GNUNET_malloc (GNUNET_SERVER_MIN_BUFFER_SIZE); | ||
93 | ret->curr_buf = GNUNET_SERVER_MIN_BUFFER_SIZE; | ||
94 | ret->cb = cb; | ||
95 | ret->cb_cls = cb_cls; | ||
96 | return ret; | ||
97 | } | ||
98 | |||
99 | |||
100 | /** | ||
101 | * Add incoming data to the receive buffer and call the | ||
102 | * callback for all complete messages. | ||
103 | * | ||
104 | * @param mst tokenizer to use | ||
105 | * @param client_identity ID of client for which this is a buffer | ||
106 | * @param buf input data to add | ||
107 | * @param size number of bytes in @a buf | ||
108 | * @param purge should any excess bytes in the buffer be discarded | ||
109 | * (i.e. for packet-based services like UDP) | ||
110 | * @param one_shot only call callback once, keep rest of message in buffer | ||
111 | * @return #GNUNET_OK if we are done processing (need more data) | ||
112 | * #GNUNET_NO if @a one_shot was set and we have another message ready | ||
113 | * #GNUNET_SYSERR if the data stream is corrupt | ||
114 | */ | ||
115 | int | ||
116 | GNUNET_SERVER_mst_receive (struct GNUNET_SERVER_MessageStreamTokenizer *mst, | ||
117 | void *client_identity, | ||
118 | const char *buf, size_t size, | ||
119 | int purge, int one_shot) | ||
120 | { | ||
121 | const struct GNUNET_MessageHeader *hdr; | ||
122 | size_t delta; | ||
123 | uint16_t want; | ||
124 | char *ibuf; | ||
125 | int need_align; | ||
126 | unsigned long offset; | ||
127 | int ret; | ||
128 | |||
129 | GNUNET_assert (mst->off <= mst->pos); | ||
130 | GNUNET_assert (mst->pos <= mst->curr_buf); | ||
131 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
132 | "Server-mst receives %u bytes with %u bytes already in private buffer\n", | ||
133 | (unsigned int) size, (unsigned int) (mst->pos - mst->off)); | ||
134 | ret = GNUNET_OK; | ||
135 | ibuf = (char *) mst->hdr; | ||
136 | while (mst->pos > 0) | ||
137 | { | ||
138 | do_align: | ||
139 | GNUNET_assert (mst->pos >= mst->off); | ||
140 | if ((mst->curr_buf - mst->off < sizeof (struct GNUNET_MessageHeader)) || | ||
141 | (0 != (mst->off % ALIGN_FACTOR))) | ||
142 | { | ||
143 | /* need to align or need more space */ | ||
144 | mst->pos -= mst->off; | ||
145 | memmove (ibuf, &ibuf[mst->off], mst->pos); | ||
146 | mst->off = 0; | ||
147 | } | ||
148 | if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) | ||
149 | { | ||
150 | delta = | ||
151 | GNUNET_MIN (sizeof (struct GNUNET_MessageHeader) - | ||
152 | (mst->pos - mst->off), size); | ||
153 | GNUNET_memcpy (&ibuf[mst->pos], buf, delta); | ||
154 | mst->pos += delta; | ||
155 | buf += delta; | ||
156 | size -= delta; | ||
157 | } | ||
158 | if (mst->pos - mst->off < sizeof (struct GNUNET_MessageHeader)) | ||
159 | { | ||
160 | if (purge) | ||
161 | { | ||
162 | mst->off = 0; | ||
163 | mst->pos = 0; | ||
164 | } | ||
165 | return GNUNET_OK; | ||
166 | } | ||
167 | hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; | ||
168 | want = ntohs (hdr->size); | ||
169 | if (want < sizeof (struct GNUNET_MessageHeader)) | ||
170 | { | ||
171 | GNUNET_break_op (0); | ||
172 | return GNUNET_SYSERR; | ||
173 | } | ||
174 | if ( (mst->curr_buf - mst->off < want) && | ||
175 | (mst->off > 0) ) | ||
176 | { | ||
177 | /* can get more space by moving */ | ||
178 | mst->pos -= mst->off; | ||
179 | memmove (ibuf, &ibuf[mst->off], mst->pos); | ||
180 | mst->off = 0; | ||
181 | } | ||
182 | if (mst->curr_buf < want) | ||
183 | { | ||
184 | /* need to get more space by growing buffer */ | ||
185 | GNUNET_assert (0 == mst->off); | ||
186 | mst->hdr = GNUNET_realloc (mst->hdr, want); | ||
187 | ibuf = (char *) mst->hdr; | ||
188 | mst->curr_buf = want; | ||
189 | } | ||
190 | hdr = (const struct GNUNET_MessageHeader *) &ibuf[mst->off]; | ||
191 | if (mst->pos - mst->off < want) | ||
192 | { | ||
193 | delta = GNUNET_MIN (want - (mst->pos - mst->off), size); | ||
194 | GNUNET_assert (mst->pos + delta <= mst->curr_buf); | ||
195 | GNUNET_memcpy (&ibuf[mst->pos], buf, delta); | ||
196 | mst->pos += delta; | ||
197 | buf += delta; | ||
198 | size -= delta; | ||
199 | } | ||
200 | if (mst->pos - mst->off < want) | ||
201 | { | ||
202 | if (purge) | ||
203 | { | ||
204 | mst->off = 0; | ||
205 | mst->pos = 0; | ||
206 | } | ||
207 | return GNUNET_OK; | ||
208 | } | ||
209 | if (one_shot == GNUNET_SYSERR) | ||
210 | { | ||
211 | /* cannot call callback again, but return value saying that | ||
212 | * we have another full message in the buffer */ | ||
213 | ret = GNUNET_NO; | ||
214 | goto copy; | ||
215 | } | ||
216 | if (one_shot == GNUNET_YES) | ||
217 | one_shot = GNUNET_SYSERR; | ||
218 | mst->off += want; | ||
219 | if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr)) | ||
220 | return GNUNET_SYSERR; | ||
221 | if (mst->off == mst->pos) | ||
222 | { | ||
223 | /* reset to beginning of buffer, it's free right now! */ | ||
224 | mst->off = 0; | ||
225 | mst->pos = 0; | ||
226 | } | ||
227 | } | ||
228 | GNUNET_assert (0 == mst->pos); | ||
229 | while (size > 0) | ||
230 | { | ||
231 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
232 | "Server-mst has %u bytes left in inbound buffer\n", | ||
233 | (unsigned int) size); | ||
234 | if (size < sizeof (struct GNUNET_MessageHeader)) | ||
235 | break; | ||
236 | offset = (unsigned long) buf; | ||
237 | need_align = (0 != (offset % ALIGN_FACTOR)) ? GNUNET_YES : GNUNET_NO; | ||
238 | if (GNUNET_NO == need_align) | ||
239 | { | ||
240 | /* can try to do zero-copy and process directly from original buffer */ | ||
241 | hdr = (const struct GNUNET_MessageHeader *) buf; | ||
242 | want = ntohs (hdr->size); | ||
243 | if (want < sizeof (struct GNUNET_MessageHeader)) | ||
244 | { | ||
245 | GNUNET_break_op (0); | ||
246 | mst->off = 0; | ||
247 | return GNUNET_SYSERR; | ||
248 | } | ||
249 | if (size < want) | ||
250 | break; /* or not: buffer incomplete, so copy to private buffer... */ | ||
251 | if (one_shot == GNUNET_SYSERR) | ||
252 | { | ||
253 | /* cannot call callback again, but return value saying that | ||
254 | * we have another full message in the buffer */ | ||
255 | ret = GNUNET_NO; | ||
256 | goto copy; | ||
257 | } | ||
258 | if (one_shot == GNUNET_YES) | ||
259 | one_shot = GNUNET_SYSERR; | ||
260 | if (GNUNET_SYSERR == mst->cb (mst->cb_cls, client_identity, hdr)) | ||
261 | return GNUNET_SYSERR; | ||
262 | buf += want; | ||
263 | size -= want; | ||
264 | } | ||
265 | else | ||
266 | { | ||
267 | /* need to copy to private buffer to align; | ||
268 | * yes, we go a bit more spagetti than usual here */ | ||
269 | goto do_align; | ||
270 | } | ||
271 | } | ||
272 | copy: | ||
273 | if ((size > 0) && (!purge)) | ||
274 | { | ||
275 | if (size + mst->pos > mst->curr_buf) | ||
276 | { | ||
277 | mst->hdr = GNUNET_realloc (mst->hdr, size + mst->pos); | ||
278 | ibuf = (char *) mst->hdr; | ||
279 | mst->curr_buf = size + mst->pos; | ||
280 | } | ||
281 | GNUNET_assert (size + mst->pos <= mst->curr_buf); | ||
282 | GNUNET_memcpy (&ibuf[mst->pos], buf, size); | ||
283 | mst->pos += size; | ||
284 | } | ||
285 | if (purge) | ||
286 | { | ||
287 | mst->off = 0; | ||
288 | mst->pos = 0; | ||
289 | } | ||
290 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
291 | "Server-mst leaves %u bytes in private buffer\n", | ||
292 | (unsigned int) (mst->pos - mst->off)); | ||
293 | return ret; | ||
294 | } | ||
295 | |||
296 | |||
297 | /** | ||
298 | * Destroys a tokenizer. | ||
299 | * | ||
300 | * @param mst tokenizer to destroy | ||
301 | */ | ||
302 | void | ||
303 | GNUNET_SERVER_mst_destroy (struct GNUNET_SERVER_MessageStreamTokenizer *mst) | ||
304 | { | ||
305 | GNUNET_free (mst->hdr); | ||
306 | GNUNET_free (mst); | ||
307 | } | ||
308 | |||
309 | |||
310 | |||
311 | /* end of server_mst.c */ | ||
diff --git a/src/util/service.c b/src/transport/tcp_service_legacy.c index d1dffa139..050a38acc 100644 --- a/src/util/service.c +++ b/src/transport/tcp_service_legacy.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "gnunet_protocols.h" | 28 | #include "gnunet_protocols.h" |
29 | #include "gnunet_constants.h" | 29 | #include "gnunet_constants.h" |
30 | #include "gnunet_resolver_service.h" | 30 | #include "gnunet_resolver_service.h" |
31 | #include "speedup.h" | ||
32 | 31 | ||
33 | #if HAVE_MALLINFO | 32 | #if HAVE_MALLINFO |
34 | #include <malloc.h> | 33 | #include <malloc.h> |
@@ -36,13 +35,6 @@ | |||
36 | #endif | 35 | #endif |
37 | 36 | ||
38 | 37 | ||
39 | #define LOG(kind,...) GNUNET_log_from (kind, "util-service", __VA_ARGS__) | ||
40 | |||
41 | #define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-service", syscall) | ||
42 | |||
43 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-service", syscall, filename) | ||
44 | |||
45 | |||
46 | /* ******************* access control ******************** */ | 38 | /* ******************* access control ******************** */ |
47 | 39 | ||
48 | /** | 40 | /** |
@@ -1152,7 +1144,6 @@ service_task (void *cls) | |||
1152 | struct GNUNET_SERVICE_Context *sctx = cls; | 1144 | struct GNUNET_SERVICE_Context *sctx = cls; |
1153 | unsigned int i; | 1145 | unsigned int i; |
1154 | 1146 | ||
1155 | (void) GNUNET_SPEEDUP_start_ (sctx->cfg); | ||
1156 | GNUNET_RESOLVER_connect (sctx->cfg); | 1147 | GNUNET_RESOLVER_connect (sctx->cfg); |
1157 | if (NULL != sctx->lsocks) | 1148 | if (NULL != sctx->lsocks) |
1158 | sctx->server | 1149 | sctx->server |
@@ -1528,7 +1519,6 @@ shutdown: | |||
1528 | } | 1519 | } |
1529 | } | 1520 | } |
1530 | #endif | 1521 | #endif |
1531 | GNUNET_SPEEDUP_stop_ (); | ||
1532 | GNUNET_CONFIGURATION_destroy (cfg); | 1522 | GNUNET_CONFIGURATION_destroy (cfg); |
1533 | i = 0; | 1523 | i = 0; |
1534 | if (NULL != sctx.addrs) | 1524 | if (NULL != sctx.addrs) |
diff --git a/src/transport/test_plugin_transport.c b/src/transport/test_plugin_transport.c index be79d5499..1d92588ea 100644 --- a/src/transport/test_plugin_transport.c +++ b/src/transport/test_plugin_transport.c | |||
@@ -552,7 +552,7 @@ setup_plugin_environment () | |||
552 | 552 | ||
553 | 553 | ||
554 | static int | 554 | static int |
555 | handle_helper_message (void *cls, void *client, | 555 | handle_helper_message (void *cls, |
556 | const struct GNUNET_MessageHeader *hdr) | 556 | const struct GNUNET_MessageHeader *hdr) |
557 | { | 557 | { |
558 | return GNUNET_OK; | 558 | return GNUNET_OK; |
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index df319fe77..2ca977065 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -30,7 +30,6 @@ W32CONSOLEHELPER = gnunet-helper-w32-console | |||
30 | endif | 30 | endif |
31 | 31 | ||
32 | if !MINGW | 32 | if !MINGW |
33 | SERVER_CLIENT_UNIX = test_server_with_client_unix | ||
34 | TEST_CLIENT_UNIC_NC = test_client_unix.nc | 33 | TEST_CLIENT_UNIC_NC = test_client_unix.nc |
35 | else | 34 | else |
36 | TEST_CLIENT_UNIC_NC = | 35 | TEST_CLIENT_UNIC_NC = |
@@ -68,7 +67,6 @@ libgnunetutil_la_SOURCES = \ | |||
68 | common_logging.c \ | 67 | common_logging.c \ |
69 | configuration.c \ | 68 | configuration.c \ |
70 | configuration_loader.c \ | 69 | configuration_loader.c \ |
71 | connection.c \ | ||
72 | container_bloomfilter.c \ | 70 | container_bloomfilter.c \ |
73 | container_heap.c \ | 71 | container_heap.c \ |
74 | container_meta_data.c \ | 72 | container_meta_data.c \ |
@@ -108,16 +106,10 @@ libgnunetutil_la_SOURCES = \ | |||
108 | program.c \ | 106 | program.c \ |
109 | resolver_api.c resolver.h \ | 107 | resolver_api.c resolver.h \ |
110 | scheduler.c \ | 108 | scheduler.c \ |
111 | server.c \ | ||
112 | server_mst.c \ | ||
113 | server_nc.c \ | ||
114 | server_tc.c \ | ||
115 | service.c \ | ||
116 | service_new.c \ | 109 | service_new.c \ |
117 | signal.c \ | 110 | signal.c \ |
118 | strings.c \ | 111 | strings.c \ |
119 | time.c \ | 112 | time.c \ |
120 | socks.c \ | ||
121 | speedup.c speedup.h | 113 | speedup.c speedup.h |
122 | 114 | ||
123 | libgnunetutil_la_LIBADD = \ | 115 | libgnunetutil_la_LIBADD = \ |
@@ -263,14 +255,13 @@ if HAVE_BENCHMARKS | |||
263 | endif | 255 | endif |
264 | 256 | ||
265 | if HAVE_SSH_KEY | 257 | if HAVE_SSH_KEY |
266 | SSH_USING_TESTS = test_socks.nc | 258 | # SSH_USING_TESTS = test_socks.nc |
267 | endif | 259 | endif |
268 | 260 | ||
269 | check_PROGRAMS = \ | 261 | check_PROGRAMS = \ |
270 | test_bio \ | 262 | test_bio \ |
271 | test_client.nc \ | 263 | test_client.nc \ |
272 | $(TEST_CLIENT_UNIX_NC) \ | 264 | $(TEST_CLIENT_UNIX_NC) \ |
273 | $(SSH_USING_TESTS) \ | ||
274 | test_common_allocation \ | 265 | test_common_allocation \ |
275 | test_common_endian \ | 266 | test_common_endian \ |
276 | test_common_logging \ | 267 | test_common_logging \ |
@@ -298,12 +289,6 @@ check_PROGRAMS = \ | |||
298 | test_crypto_rsa \ | 289 | test_crypto_rsa \ |
299 | test_disk \ | 290 | test_disk \ |
300 | test_getopt \ | 291 | test_getopt \ |
301 | test_connection.nc \ | ||
302 | test_connection_addressing.nc \ | ||
303 | test_connection_receive_cancel.nc \ | ||
304 | test_connection_timeout.nc \ | ||
305 | test_connection_timeout_no_connect.nc \ | ||
306 | test_connection_transmit_cancel.nc \ | ||
307 | test_mq \ | 292 | test_mq \ |
308 | test_os_network \ | 293 | test_os_network \ |
309 | test_peer \ | 294 | test_peer \ |
@@ -312,11 +297,6 @@ check_PROGRAMS = \ | |||
312 | test_resolver_api.nc \ | 297 | test_resolver_api.nc \ |
313 | test_scheduler \ | 298 | test_scheduler \ |
314 | test_scheduler_delay \ | 299 | test_scheduler_delay \ |
315 | test_server.nc \ | ||
316 | test_server_disconnect.nc \ | ||
317 | test_server_with_client.nc \ | ||
318 | test_server_mst_interrupt.nc \ | ||
319 | $(SERVER_CLIENT_UNIX) \ | ||
320 | test_service \ | 300 | test_service \ |
321 | test_strings \ | 301 | test_strings \ |
322 | test_strings_to_data \ | 302 | test_strings_to_data \ |
@@ -330,18 +310,7 @@ check_PROGRAMS = \ | |||
330 | # Declare .nc (NO-CONCURRENCY) as a test extension so that we can impart | 310 | # Declare .nc (NO-CONCURRENCY) as a test extension so that we can impart |
331 | # sequential execution order for them | 311 | # sequential execution order for them |
332 | TEST_EXTENSIONS = .nc | 312 | TEST_EXTENSIONS = .nc |
333 | test_connection.log: test_client.log | 313 | test_test_client_unix.log: test_client.log |
334 | test_connection_addressing.log: test_connection.log | ||
335 | test_connection_timeout_no_connect.log: test_connection_addressing.log | ||
336 | test_connection_transmit_cancel.log: test_connection_timeout_no_connect.log | ||
337 | test_connection_receive_cancel.log: test_connection_transmit_cancel.log | ||
338 | test_connection_timeout.log: test_connection_receive_cancel.log | ||
339 | test_resolver_api.log: test_connection_timeout.log | ||
340 | test_server.log: test_resolver_api.log | ||
341 | test_server_disconnect.log: test_server.log | ||
342 | test_server_with_client.log: test_server_disconnect.log | ||
343 | test_server_mst_interrupt.log: test_server_with_client.log | ||
344 | test_client_unix.log: test_server_mst_interrupt.log | ||
345 | 314 | ||
346 | test_bio_SOURCES = \ | 315 | test_bio_SOURCES = \ |
347 | test_bio.c | 316 | test_bio.c |
@@ -518,36 +487,6 @@ test_getopt_SOURCES = \ | |||
518 | test_getopt_LDADD = \ | 487 | test_getopt_LDADD = \ |
519 | libgnunetutil.la | 488 | libgnunetutil.la |
520 | 489 | ||
521 | test_connection_nc_SOURCES = \ | ||
522 | test_connection.c | ||
523 | test_connection_nc_LDADD = \ | ||
524 | libgnunetutil.la | ||
525 | |||
526 | test_connection_addressing_nc_SOURCES = \ | ||
527 | test_connection_addressing.c | ||
528 | test_connection_addressing_nc_LDADD = \ | ||
529 | libgnunetutil.la | ||
530 | |||
531 | test_connection_receive_cancel_nc_SOURCES = \ | ||
532 | test_connection_receive_cancel.c | ||
533 | test_connection_receive_cancel_nc_LDADD = \ | ||
534 | libgnunetutil.la | ||
535 | |||
536 | test_connection_timeout_nc_SOURCES = \ | ||
537 | test_connection_timeout.c | ||
538 | test_connection_timeout_nc_LDADD = \ | ||
539 | libgnunetutil.la | ||
540 | |||
541 | test_connection_timeout_no_connect_nc_SOURCES = \ | ||
542 | test_connection_timeout_no_connect.c | ||
543 | test_connection_timeout_no_connect_nc_LDADD = \ | ||
544 | libgnunetutil.la | ||
545 | |||
546 | test_connection_transmit_cancel_nc_SOURCES = \ | ||
547 | test_connection_transmit_cancel.c | ||
548 | test_connection_transmit_cancel_nc_LDADD = \ | ||
549 | libgnunetutil.la | ||
550 | |||
551 | test_mq_SOURCES = \ | 490 | test_mq_SOURCES = \ |
552 | test_mq.c | 491 | test_mq.c |
553 | test_mq_LDADD = \ | 492 | test_mq_LDADD = \ |
@@ -588,32 +527,6 @@ test_scheduler_delay_SOURCES = \ | |||
588 | test_scheduler_delay_LDADD = \ | 527 | test_scheduler_delay_LDADD = \ |
589 | libgnunetutil.la | 528 | libgnunetutil.la |
590 | 529 | ||
591 | test_server_mst_interrupt_nc_SOURCES = \ | ||
592 | test_server_mst_interrupt.c | ||
593 | test_server_mst_interrupt_nc_LDADD = \ | ||
594 | libgnunetutil.la | ||
595 | |||
596 | test_server_nc_SOURCES = \ | ||
597 | test_server.c | ||
598 | test_server_nc_LDADD = \ | ||
599 | libgnunetutil.la | ||
600 | |||
601 | test_server_disconnect_nc_SOURCES = \ | ||
602 | test_server_disconnect.c | ||
603 | test_server_disconnect_nc_LDADD = \ | ||
604 | libgnunetutil.la | ||
605 | |||
606 | test_server_with_client_nc_SOURCES = \ | ||
607 | test_server_with_client.c | ||
608 | test_server_with_client_nc_LDADD = \ | ||
609 | libgnunetutil.la | ||
610 | |||
611 | test_server_with_client_unix_SOURCES = \ | ||
612 | test_server_with_client_unix.c | ||
613 | test_server_with_client_unix_LDADD = \ | ||
614 | libgnunetutil.la | ||
615 | |||
616 | |||
617 | test_service_SOURCES = \ | 530 | test_service_SOURCES = \ |
618 | test_service.c | 531 | test_service.c |
619 | test_service_LDADD = \ | 532 | test_service_LDADD = \ |
@@ -624,7 +537,6 @@ test_strings_SOURCES = \ | |||
624 | test_strings_LDADD = \ | 537 | test_strings_LDADD = \ |
625 | libgnunetutil.la | 538 | libgnunetutil.la |
626 | 539 | ||
627 | |||
628 | test_strings_to_data_SOURCES = \ | 540 | test_strings_to_data_SOURCES = \ |
629 | test_strings_to_data.c | 541 | test_strings_to_data.c |
630 | test_strings_to_data_LDADD = \ | 542 | test_strings_to_data_LDADD = \ |
diff --git a/src/util/helper.c b/src/util/helper.c index cdb1b01d4..1a79c477a 100644 --- a/src/util/helper.c +++ b/src/util/helper.c | |||
@@ -27,6 +27,7 @@ | |||
27 | */ | 27 | */ |
28 | #include "platform.h" | 28 | #include "platform.h" |
29 | #include "gnunet_util_lib.h" | 29 | #include "gnunet_util_lib.h" |
30 | #include "gnunet_mst_lib.h" | ||
30 | 31 | ||
31 | 32 | ||
32 | /** | 33 | /** |
@@ -107,7 +108,7 @@ struct GNUNET_HELPER_Handle | |||
107 | /** | 108 | /** |
108 | * The Message-Tokenizer that tokenizes the messages comming from the helper | 109 | * The Message-Tokenizer that tokenizes the messages comming from the helper |
109 | */ | 110 | */ |
110 | struct GNUNET_SERVER_MessageStreamTokenizer *mst; | 111 | struct GNUNET_MessageStreamTokenizer *mst; |
111 | 112 | ||
112 | /** | 113 | /** |
113 | * The exception callback | 114 | * The exception callback |
@@ -272,7 +273,10 @@ GNUNET_HELPER_wait (struct GNUNET_HELPER_Handle *h) | |||
272 | } | 273 | } |
273 | /* purge MST buffer */ | 274 | /* purge MST buffer */ |
274 | if (NULL != h->mst) | 275 | if (NULL != h->mst) |
275 | (void) GNUNET_SERVER_mst_receive (h->mst, NULL, NULL, 0, GNUNET_YES, GNUNET_NO); | 276 | (void) GNUNET_MST_from_buffer (h->mst, |
277 | NULL, 0, | ||
278 | GNUNET_YES, | ||
279 | GNUNET_NO); | ||
276 | return ret; | 280 | return ret; |
277 | } | 281 | } |
278 | 282 | ||
@@ -373,10 +377,10 @@ helper_read (void *cls) | |||
373 | h->fh_from_helper, | 377 | h->fh_from_helper, |
374 | &helper_read, h); | 378 | &helper_read, h); |
375 | if (GNUNET_SYSERR == | 379 | if (GNUNET_SYSERR == |
376 | GNUNET_SERVER_mst_receive (h->mst, | 380 | GNUNET_MST_from_buffer (h->mst, |
377 | NULL, | 381 | buf, t, |
378 | buf, t, | 382 | GNUNET_NO, |
379 | GNUNET_NO, GNUNET_NO)) | 383 | GNUNET_NO)) |
380 | { | 384 | { |
381 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 385 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
382 | _("Failed to parse inbound message from helper `%s'\n"), | 386 | _("Failed to parse inbound message from helper `%s'\n"), |
@@ -487,7 +491,7 @@ struct GNUNET_HELPER_Handle * | |||
487 | GNUNET_HELPER_start (int with_control_pipe, | 491 | GNUNET_HELPER_start (int with_control_pipe, |
488 | const char *binary_name, | 492 | const char *binary_name, |
489 | char *const binary_argv[], | 493 | char *const binary_argv[], |
490 | GNUNET_SERVER_MessageTokenizerCallback cb, | 494 | GNUNET_MessageTokenizerCallback cb, |
491 | GNUNET_HELPER_ExceptionCallback exp_cb, | 495 | GNUNET_HELPER_ExceptionCallback exp_cb, |
492 | void *cb_cls) | 496 | void *cb_cls) |
493 | { | 497 | { |
@@ -508,7 +512,8 @@ GNUNET_HELPER_start (int with_control_pipe, | |||
508 | h->binary_argv[c] = NULL; | 512 | h->binary_argv[c] = NULL; |
509 | h->cb_cls = cb_cls; | 513 | h->cb_cls = cb_cls; |
510 | if (NULL != cb) | 514 | if (NULL != cb) |
511 | h->mst = GNUNET_SERVER_mst_create (cb, h->cb_cls); | 515 | h->mst = GNUNET_MST_create (cb, |
516 | h->cb_cls); | ||
512 | h->exp_cb = exp_cb; | 517 | h->exp_cb = exp_cb; |
513 | h->retry_back_off = 0; | 518 | h->retry_back_off = 0; |
514 | start_helper (h); | 519 | start_helper (h); |
@@ -544,7 +549,7 @@ GNUNET_HELPER_destroy (struct GNUNET_HELPER_Handle *h) | |||
544 | GNUNET_free (sh); | 549 | GNUNET_free (sh); |
545 | } | 550 | } |
546 | if (NULL != h->mst) | 551 | if (NULL != h->mst) |
547 | GNUNET_SERVER_mst_destroy (h->mst); | 552 | GNUNET_MST_destroy (h->mst); |
548 | GNUNET_free (h->binary_name); | 553 | GNUNET_free (h->binary_name); |
549 | for (c = 0; h->binary_argv[c] != NULL; c++) | 554 | for (c = 0; h->binary_argv[c] != NULL; c++) |
550 | GNUNET_free (h->binary_argv[c]); | 555 | GNUNET_free (h->binary_argv[c]); |
diff --git a/src/util/mq.c b/src/util/mq.c index 25cf24e11..90b2aa968 100644 --- a/src/util/mq.c +++ b/src/util/mq.c | |||
@@ -202,24 +202,6 @@ struct GNUNET_MQ_Handle | |||
202 | 202 | ||
203 | 203 | ||
204 | /** | 204 | /** |
205 | * Implementation-specific state for connection to | ||
206 | * client (MQ for server). | ||
207 | */ | ||
208 | struct ServerClientSocketState | ||
209 | { | ||
210 | /** | ||
211 | * Handle of the client that connected to the server. | ||
212 | */ | ||
213 | struct GNUNET_SERVER_Client *client; | ||
214 | |||
215 | /** | ||
216 | * Active transmission request to the client. | ||
217 | */ | ||
218 | struct GNUNET_SERVER_TransmitHandle *th; | ||
219 | }; | ||
220 | |||
221 | |||
222 | /** | ||
223 | * Call the message message handler that was registered | 205 | * Call the message message handler that was registered |
224 | * for the type of the given message in the given message queue. | 206 | * for the type of the given message in the given message queue. |
225 | * | 207 | * |
@@ -708,92 +690,6 @@ GNUNET_MQ_msg_nested_mh_ (struct GNUNET_MessageHeader **mhp, | |||
708 | 690 | ||
709 | 691 | ||
710 | /** | 692 | /** |
711 | * Transmit a queued message to the session's client. | ||
712 | * | ||
713 | * @param cls consensus session | ||
714 | * @param size number of bytes available in @a buf | ||
715 | * @param buf where the callee should write the message | ||
716 | * @return number of bytes written to @a buf | ||
717 | */ | ||
718 | static size_t | ||
719 | transmit_queued (void *cls, | ||
720 | size_t size, | ||
721 | void *buf) | ||
722 | { | ||
723 | struct GNUNET_MQ_Handle *mq = cls; | ||
724 | struct ServerClientSocketState *state = GNUNET_MQ_impl_state (mq); | ||
725 | const struct GNUNET_MessageHeader *msg = GNUNET_MQ_impl_current (mq); | ||
726 | size_t msg_size; | ||
727 | |||
728 | GNUNET_assert (NULL != buf); | ||
729 | msg_size = ntohs (msg->size); | ||
730 | GNUNET_assert (size >= msg_size); | ||
731 | GNUNET_memcpy (buf, msg, msg_size); | ||
732 | state->th = NULL; | ||
733 | |||
734 | GNUNET_MQ_impl_send_continue (mq); | ||
735 | |||
736 | return msg_size; | ||
737 | } | ||
738 | |||
739 | |||
740 | static void | ||
741 | server_client_destroy_impl (struct GNUNET_MQ_Handle *mq, | ||
742 | void *impl_state) | ||
743 | { | ||
744 | struct ServerClientSocketState *state = impl_state; | ||
745 | |||
746 | if (NULL != state->th) | ||
747 | { | ||
748 | GNUNET_SERVER_notify_transmit_ready_cancel (state->th); | ||
749 | state->th = NULL; | ||
750 | } | ||
751 | |||
752 | GNUNET_assert (NULL != mq); | ||
753 | GNUNET_assert (NULL != state); | ||
754 | GNUNET_SERVER_client_drop (state->client); | ||
755 | GNUNET_free (state); | ||
756 | } | ||
757 | |||
758 | |||
759 | static void | ||
760 | server_client_send_impl (struct GNUNET_MQ_Handle *mq, | ||
761 | const struct GNUNET_MessageHeader *msg, | ||
762 | void *impl_state) | ||
763 | { | ||
764 | GNUNET_assert (NULL != mq); | ||
765 | |||
766 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
767 | "Sending message of type %u and size %u\n", | ||
768 | ntohs (msg->type), ntohs (msg->size)); | ||
769 | |||
770 | struct ServerClientSocketState *state = impl_state; | ||
771 | state->th = GNUNET_SERVER_notify_transmit_ready (state->client, | ||
772 | ntohs (msg->size), | ||
773 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
774 | &transmit_queued, | ||
775 | mq); | ||
776 | } | ||
777 | |||
778 | |||
779 | struct GNUNET_MQ_Handle * | ||
780 | GNUNET_MQ_queue_for_server_client (struct GNUNET_SERVER_Client *client) | ||
781 | { | ||
782 | struct GNUNET_MQ_Handle *mq; | ||
783 | struct ServerClientSocketState *scss; | ||
784 | |||
785 | mq = GNUNET_new (struct GNUNET_MQ_Handle); | ||
786 | scss = GNUNET_new (struct ServerClientSocketState); | ||
787 | mq->impl_state = scss; | ||
788 | scss->client = client; | ||
789 | GNUNET_SERVER_client_keep (client); | ||
790 | mq->send_impl = &server_client_send_impl; | ||
791 | mq->destroy_impl = &server_client_destroy_impl; | ||
792 | return mq; | ||
793 | } | ||
794 | |||
795 | |||
796 | /** | ||
797 | * Associate the assoc_data in mq with a unique request id. | 693 | * Associate the assoc_data in mq with a unique request id. |
798 | * | 694 | * |
799 | * @param mq message queue, id will be unique for the queue | 695 | * @param mq message queue, id will be unique for the queue |
diff --git a/src/util/test_connection.c b/src/util/test_connection.c deleted file mode 100644 index eaca75c2e..000000000 --- a/src/util/test_connection.c +++ /dev/null | |||
@@ -1,167 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_connection.c | ||
22 | * @brief tests for connection.c | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | |||
27 | #define PORT 12435 | ||
28 | |||
29 | |||
30 | static struct GNUNET_CONNECTION_Handle *csock; | ||
31 | |||
32 | static struct GNUNET_CONNECTION_Handle *asock; | ||
33 | |||
34 | static struct GNUNET_CONNECTION_Handle *lsock; | ||
35 | |||
36 | static size_t sofar; | ||
37 | |||
38 | static struct GNUNET_NETWORK_Handle *ls; | ||
39 | |||
40 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
41 | |||
42 | /** | ||
43 | * Create and initialize a listen socket for the server. | ||
44 | * | ||
45 | * @return -1 on error, otherwise the listen socket | ||
46 | */ | ||
47 | static struct GNUNET_NETWORK_Handle * | ||
48 | open_listen_socket () | ||
49 | { | ||
50 | const static int on = 1; | ||
51 | struct sockaddr_in sa; | ||
52 | struct GNUNET_NETWORK_Handle *desc; | ||
53 | |||
54 | memset (&sa, 0, sizeof (sa)); | ||
55 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
56 | sa.sin_len = sizeof (sa); | ||
57 | #endif | ||
58 | sa.sin_port = htons (PORT); | ||
59 | sa.sin_family = AF_INET; | ||
60 | desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); | ||
61 | GNUNET_assert (desc != NULL); | ||
62 | if (GNUNET_NETWORK_socket_setsockopt | ||
63 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | ||
64 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); | ||
65 | GNUNET_assert (GNUNET_OK == | ||
66 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, | ||
67 | sizeof (sa))); | ||
68 | GNUNET_NETWORK_socket_listen (desc, 5); | ||
69 | return desc; | ||
70 | } | ||
71 | |||
72 | static void | ||
73 | receive_check (void *cls, const void *buf, size_t available, | ||
74 | const struct sockaddr *addr, socklen_t addrlen, int errCode) | ||
75 | { | ||
76 | int *ok = cls; | ||
77 | |||
78 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive validates incoming data\n"); | ||
79 | GNUNET_assert (buf != NULL); /* no timeout */ | ||
80 | if (0 == memcmp (&"Hello World"[sofar], buf, available)) | ||
81 | sofar += available; | ||
82 | if (sofar < 12) | ||
83 | { | ||
84 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive needs more data\n"); | ||
85 | GNUNET_CONNECTION_receive (asock, 1024, | ||
86 | GNUNET_TIME_relative_multiply | ||
87 | (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, | ||
88 | cls); | ||
89 | } | ||
90 | else | ||
91 | { | ||
92 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Receive closes accepted socket\n"); | ||
93 | *ok = 0; | ||
94 | GNUNET_CONNECTION_destroy (asock); | ||
95 | GNUNET_CONNECTION_destroy (csock); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | |||
100 | static void | ||
101 | run_accept (void *cls) | ||
102 | { | ||
103 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test accepts connection\n"); | ||
104 | asock = GNUNET_CONNECTION_create_from_accept (NULL, NULL, ls); | ||
105 | GNUNET_assert (asock != NULL); | ||
106 | GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); | ||
107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test destroys listen socket\n"); | ||
108 | GNUNET_CONNECTION_destroy (lsock); | ||
109 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
110 | "Test asks to receive on accepted socket\n"); | ||
111 | GNUNET_CONNECTION_receive (asock, 1024, | ||
112 | GNUNET_TIME_relative_multiply | ||
113 | (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, | ||
114 | cls); | ||
115 | } | ||
116 | |||
117 | |||
118 | static size_t | ||
119 | make_hello (void *cls, size_t size, void *buf) | ||
120 | { | ||
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
122 | "Test prepares to transmit on connect socket\n"); | ||
123 | GNUNET_assert (size >= 12); | ||
124 | strcpy ((char *) buf, "Hello World"); | ||
125 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test destroys client socket\n"); | ||
126 | return 12; | ||
127 | } | ||
128 | |||
129 | |||
130 | static void | ||
131 | task (void *cls) | ||
132 | { | ||
133 | ls = open_listen_socket (); | ||
134 | lsock = GNUNET_CONNECTION_create_from_existing (ls); | ||
135 | GNUNET_assert (lsock != NULL); | ||
136 | csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); | ||
137 | GNUNET_assert (csock != NULL); | ||
138 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test asks for write notification\n"); | ||
139 | GNUNET_assert (NULL != | ||
140 | GNUNET_CONNECTION_notify_transmit_ready (csock, 12, | ||
141 | GNUNET_TIME_UNIT_SECONDS, | ||
142 | &make_hello, NULL)); | ||
143 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test prepares to accept\n"); | ||
144 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept, | ||
145 | cls); | ||
146 | } | ||
147 | |||
148 | |||
149 | int | ||
150 | main (int argc, char *argv[]) | ||
151 | { | ||
152 | int ok; | ||
153 | |||
154 | GNUNET_log_setup ("test_connection", | ||
155 | "WARNING", | ||
156 | NULL); | ||
157 | |||
158 | ok = 1; | ||
159 | cfg = GNUNET_CONFIGURATION_create (); | ||
160 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", | ||
161 | "localhost"); | ||
162 | GNUNET_SCHEDULER_run (&task, &ok); | ||
163 | GNUNET_CONFIGURATION_destroy (cfg); | ||
164 | return ok; | ||
165 | } | ||
166 | |||
167 | /* end of test_connection.c */ | ||
diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c deleted file mode 100644 index a6345b10a..000000000 --- a/src/util/test_connection_addressing.c +++ /dev/null | |||
@@ -1,186 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_connection_addressing.c | ||
22 | * @brief tests for connection.c | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | |||
27 | |||
28 | #define PORT 12435 | ||
29 | |||
30 | |||
31 | static struct GNUNET_CONNECTION_Handle *csock; | ||
32 | |||
33 | static struct GNUNET_CONNECTION_Handle *asock; | ||
34 | |||
35 | static struct GNUNET_CONNECTION_Handle *lsock; | ||
36 | |||
37 | static size_t sofar; | ||
38 | |||
39 | static struct GNUNET_NETWORK_Handle *ls; | ||
40 | |||
41 | |||
42 | |||
43 | /** | ||
44 | * Create and initialize a listen socket for the server. | ||
45 | * | ||
46 | * @return NULL on error, otherwise the listen socket | ||
47 | */ | ||
48 | static struct GNUNET_NETWORK_Handle * | ||
49 | open_listen_socket () | ||
50 | { | ||
51 | const static int on = 1; | ||
52 | struct sockaddr_in sa; | ||
53 | struct GNUNET_NETWORK_Handle *desc; | ||
54 | |||
55 | memset (&sa, 0, sizeof (sa)); | ||
56 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
57 | sa.sin_len = sizeof (sa); | ||
58 | #endif | ||
59 | sa.sin_family = AF_INET; | ||
60 | sa.sin_port = htons (PORT); | ||
61 | desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); | ||
62 | GNUNET_assert (desc != 0); | ||
63 | if (GNUNET_NETWORK_socket_setsockopt | ||
64 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | ||
65 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); | ||
66 | if (GNUNET_OK != | ||
67 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, | ||
68 | sizeof (sa))) | ||
69 | { | ||
70 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
71 | "bind"); | ||
72 | GNUNET_assert (0); | ||
73 | } | ||
74 | GNUNET_NETWORK_socket_listen (desc, 5); | ||
75 | return desc; | ||
76 | } | ||
77 | |||
78 | |||
79 | static void | ||
80 | receive_check (void *cls, const void *buf, size_t available, | ||
81 | const struct sockaddr *addr, socklen_t addrlen, int errCode) | ||
82 | { | ||
83 | int *ok = cls; | ||
84 | |||
85 | GNUNET_assert (buf != NULL); /* no timeout */ | ||
86 | if (0 == memcmp (&"Hello World"[sofar], buf, available)) | ||
87 | sofar += available; | ||
88 | if (sofar < 12) | ||
89 | { | ||
90 | GNUNET_CONNECTION_receive (asock, 1024, | ||
91 | GNUNET_TIME_relative_multiply | ||
92 | (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, | ||
93 | cls); | ||
94 | } | ||
95 | else | ||
96 | { | ||
97 | *ok = 0; | ||
98 | GNUNET_CONNECTION_destroy (csock); | ||
99 | GNUNET_CONNECTION_destroy (asock); | ||
100 | } | ||
101 | } | ||
102 | |||
103 | |||
104 | static void | ||
105 | run_accept (void *cls) | ||
106 | { | ||
107 | void *addr; | ||
108 | size_t alen; | ||
109 | struct sockaddr_in *v4; | ||
110 | struct sockaddr_in expect; | ||
111 | |||
112 | asock = GNUNET_CONNECTION_create_from_accept (NULL, NULL, ls); | ||
113 | GNUNET_assert (asock != NULL); | ||
114 | GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); | ||
115 | GNUNET_assert (GNUNET_OK == | ||
116 | GNUNET_CONNECTION_get_address (asock, &addr, &alen)); | ||
117 | GNUNET_assert (alen == sizeof (struct sockaddr_in)); | ||
118 | v4 = addr; | ||
119 | memset (&expect, 0, sizeof (expect)); | ||
120 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
121 | expect.sin_len = sizeof (expect); | ||
122 | #endif | ||
123 | expect.sin_family = AF_INET; | ||
124 | expect.sin_port = v4->sin_port; | ||
125 | expect.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | ||
126 | GNUNET_assert (0 == memcmp (&expect, v4, alen)); | ||
127 | GNUNET_free (addr); | ||
128 | GNUNET_CONNECTION_destroy (lsock); | ||
129 | GNUNET_CONNECTION_receive (asock, 1024, | ||
130 | GNUNET_TIME_relative_multiply | ||
131 | (GNUNET_TIME_UNIT_SECONDS, 5), &receive_check, | ||
132 | cls); | ||
133 | } | ||
134 | |||
135 | static size_t | ||
136 | make_hello (void *cls, size_t size, void *buf) | ||
137 | { | ||
138 | GNUNET_assert (size >= 12); | ||
139 | strcpy ((char *) buf, "Hello World"); | ||
140 | return 12; | ||
141 | } | ||
142 | |||
143 | |||
144 | static void | ||
145 | task (void *cls) | ||
146 | { | ||
147 | struct sockaddr_in v4; | ||
148 | |||
149 | ls = open_listen_socket (); | ||
150 | lsock = GNUNET_CONNECTION_create_from_existing (ls); | ||
151 | GNUNET_assert (lsock != NULL); | ||
152 | |||
153 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
154 | v4.sin_len = sizeof (v4); | ||
155 | #endif | ||
156 | v4.sin_family = AF_INET; | ||
157 | v4.sin_port = htons (PORT); | ||
158 | v4.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | ||
159 | csock = | ||
160 | GNUNET_CONNECTION_create_from_sockaddr (AF_INET, | ||
161 | (const struct sockaddr *) &v4, | ||
162 | sizeof (v4)); | ||
163 | GNUNET_assert (csock != NULL); | ||
164 | GNUNET_assert (NULL != | ||
165 | GNUNET_CONNECTION_notify_transmit_ready (csock, 12, | ||
166 | GNUNET_TIME_UNIT_SECONDS, | ||
167 | &make_hello, NULL)); | ||
168 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, ls, &run_accept, | ||
169 | cls); | ||
170 | } | ||
171 | |||
172 | |||
173 | int | ||
174 | main (int argc, char *argv[]) | ||
175 | { | ||
176 | int ok; | ||
177 | |||
178 | GNUNET_log_setup ("test_connection_addressing", | ||
179 | "WARNING", | ||
180 | NULL); | ||
181 | ok = 1; | ||
182 | GNUNET_SCHEDULER_run (&task, &ok); | ||
183 | return ok; | ||
184 | } | ||
185 | |||
186 | /* end of test_connection_addressing.c */ | ||
diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c deleted file mode 100644 index 9c0ab699e..000000000 --- a/src/util/test_connection_receive_cancel.c +++ /dev/null | |||
@@ -1,160 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_connection_receive_cancel.c | ||
22 | * @brief tests for connection.c | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | |||
27 | #define PORT 12435 | ||
28 | |||
29 | |||
30 | static struct GNUNET_CONNECTION_Handle *csock; | ||
31 | |||
32 | static struct GNUNET_CONNECTION_Handle *asock; | ||
33 | |||
34 | static struct GNUNET_CONNECTION_Handle *lsock; | ||
35 | |||
36 | static struct GNUNET_NETWORK_Handle *ls; | ||
37 | |||
38 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
39 | |||
40 | |||
41 | /** | ||
42 | * Create and initialize a listen socket for the server. | ||
43 | * | ||
44 | * @return NULL on error, otherwise the listen socket | ||
45 | */ | ||
46 | static struct GNUNET_NETWORK_Handle * | ||
47 | open_listen_socket () | ||
48 | { | ||
49 | const static int on = 1; | ||
50 | struct sockaddr_in sa; | ||
51 | struct GNUNET_NETWORK_Handle *desc; | ||
52 | |||
53 | memset (&sa, 0, sizeof (sa)); | ||
54 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
55 | sa.sin_len = sizeof (sa); | ||
56 | #endif | ||
57 | sa.sin_family = AF_INET; | ||
58 | sa.sin_port = htons (PORT); | ||
59 | desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); | ||
60 | GNUNET_assert (desc != NULL); | ||
61 | if (GNUNET_NETWORK_socket_setsockopt | ||
62 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | ||
63 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | ||
64 | "setsockopt"); | ||
65 | GNUNET_assert (GNUNET_OK == | ||
66 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, | ||
67 | sizeof (sa))); | ||
68 | GNUNET_NETWORK_socket_listen (desc, 5); | ||
69 | return desc; | ||
70 | } | ||
71 | |||
72 | |||
73 | static void | ||
74 | dead_receive (void *cls, | ||
75 | const void *buf, | ||
76 | size_t available, | ||
77 | const struct sockaddr *addr, | ||
78 | socklen_t addrlen, | ||
79 | int errCode) | ||
80 | { | ||
81 | GNUNET_assert (0); | ||
82 | } | ||
83 | |||
84 | |||
85 | static void | ||
86 | run_accept_cancel (void *cls) | ||
87 | { | ||
88 | asock = GNUNET_CONNECTION_create_from_accept (NULL, NULL, ls); | ||
89 | GNUNET_assert (asock != NULL); | ||
90 | GNUNET_assert (GNUNET_YES == GNUNET_CONNECTION_check (asock)); | ||
91 | GNUNET_CONNECTION_destroy (lsock); | ||
92 | GNUNET_CONNECTION_receive (asock, 1024, | ||
93 | GNUNET_TIME_relative_multiply | ||
94 | (GNUNET_TIME_UNIT_SECONDS, 5), | ||
95 | &dead_receive, cls); | ||
96 | } | ||
97 | |||
98 | |||
99 | static void | ||
100 | receive_cancel_task (void *cls) | ||
101 | { | ||
102 | int *ok = cls; | ||
103 | |||
104 | GNUNET_CONNECTION_receive_cancel (asock); | ||
105 | GNUNET_CONNECTION_destroy (csock); | ||
106 | GNUNET_CONNECTION_destroy (asock); | ||
107 | *ok = 0; | ||
108 | } | ||
109 | |||
110 | |||
111 | static void | ||
112 | task_receive_cancel (void *cls) | ||
113 | { | ||
114 | ls = open_listen_socket (); | ||
115 | lsock = GNUNET_CONNECTION_create_from_existing (ls); | ||
116 | GNUNET_assert (lsock != NULL); | ||
117 | csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); | ||
118 | GNUNET_assert (csock != NULL); | ||
119 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | ||
120 | ls, | ||
121 | &run_accept_cancel, | ||
122 | cls); | ||
123 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | ||
124 | &receive_cancel_task, | ||
125 | cls); | ||
126 | } | ||
127 | |||
128 | |||
129 | /** | ||
130 | * Main method, starts scheduler with task_timeout. | ||
131 | */ | ||
132 | static int | ||
133 | check_receive_cancel () | ||
134 | { | ||
135 | int ok; | ||
136 | |||
137 | ok = 1; | ||
138 | cfg = GNUNET_CONFIGURATION_create (); | ||
139 | GNUNET_CONFIGURATION_set_value_string (cfg, | ||
140 | "resolver", | ||
141 | "HOSTNAME", | ||
142 | "localhost"); | ||
143 | GNUNET_SCHEDULER_run (&task_receive_cancel, &ok); | ||
144 | GNUNET_CONFIGURATION_destroy (cfg); | ||
145 | return ok; | ||
146 | } | ||
147 | |||
148 | |||
149 | int | ||
150 | main (int argc, char *argv[]) | ||
151 | { | ||
152 | int ret = 0; | ||
153 | |||
154 | GNUNET_log_setup ("test_connection_receive_cancel", "WARNING", NULL); | ||
155 | ret += check_receive_cancel (); | ||
156 | |||
157 | return ret; | ||
158 | } | ||
159 | |||
160 | /* end of test_connection_receive_cancel.c */ | ||
diff --git a/src/util/test_connection_timeout.c b/src/util/test_connection_timeout.c deleted file mode 100644 index e78cec669..000000000 --- a/src/util/test_connection_timeout.c +++ /dev/null | |||
@@ -1,129 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_connection_timeout.c | ||
22 | * @brief tests for connection.c | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | |||
27 | #define PORT 12435 | ||
28 | |||
29 | static struct GNUNET_CONNECTION_Handle *csock; | ||
30 | |||
31 | static struct GNUNET_CONNECTION_Handle *lsock; | ||
32 | |||
33 | static struct GNUNET_NETWORK_Handle *ls; | ||
34 | |||
35 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
36 | |||
37 | |||
38 | /** | ||
39 | * Create and initialize a listen socket for the server. | ||
40 | * | ||
41 | * @return NULL on error, otherwise the listen socket | ||
42 | */ | ||
43 | static struct GNUNET_NETWORK_Handle * | ||
44 | open_listen_socket () | ||
45 | { | ||
46 | const static int on = 1; | ||
47 | struct sockaddr_in sa; | ||
48 | struct GNUNET_NETWORK_Handle *desc; | ||
49 | |||
50 | memset (&sa, 0, sizeof (sa)); | ||
51 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
52 | sa.sin_len = sizeof (sa); | ||
53 | #endif | ||
54 | sa.sin_family = AF_INET; | ||
55 | sa.sin_port = htons (PORT); | ||
56 | desc = GNUNET_NETWORK_socket_create (AF_INET, SOCK_STREAM, 0); | ||
57 | GNUNET_assert (desc != NULL); | ||
58 | if (GNUNET_NETWORK_socket_setsockopt | ||
59 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | ||
60 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); | ||
61 | GNUNET_assert (GNUNET_OK == | ||
62 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, | ||
63 | sizeof (sa))); | ||
64 | GNUNET_NETWORK_socket_listen (desc, 5); | ||
65 | return desc; | ||
66 | } | ||
67 | |||
68 | |||
69 | static size_t | ||
70 | send_kilo (void *cls, size_t size, void *buf) | ||
71 | { | ||
72 | int *ok = cls; | ||
73 | |||
74 | if (size == 0) | ||
75 | { | ||
76 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got the desired timeout!\n"); | ||
77 | GNUNET_assert (buf == NULL); | ||
78 | *ok = 0; | ||
79 | GNUNET_CONNECTION_destroy (lsock); | ||
80 | GNUNET_CONNECTION_destroy (csock); | ||
81 | return 0; | ||
82 | } | ||
83 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending kilo to fill buffer.\n"); | ||
84 | GNUNET_assert (size >= 1024); | ||
85 | memset (buf, 42, 1024); | ||
86 | |||
87 | GNUNET_assert (NULL != | ||
88 | GNUNET_CONNECTION_notify_transmit_ready (csock, 1024, | ||
89 | GNUNET_TIME_UNIT_SECONDS, | ||
90 | &send_kilo, cls)); | ||
91 | return 1024; | ||
92 | } | ||
93 | |||
94 | |||
95 | static void | ||
96 | task_timeout (void *cls) | ||
97 | { | ||
98 | |||
99 | ls = open_listen_socket (); | ||
100 | lsock = GNUNET_CONNECTION_create_from_existing (ls); | ||
101 | GNUNET_assert (lsock != NULL); | ||
102 | csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); | ||
103 | GNUNET_assert (csock != NULL); | ||
104 | GNUNET_assert (NULL != | ||
105 | GNUNET_CONNECTION_notify_transmit_ready (csock, 1024, | ||
106 | GNUNET_TIME_UNIT_SECONDS, | ||
107 | &send_kilo, cls)); | ||
108 | } | ||
109 | |||
110 | |||
111 | int | ||
112 | main (int argc, char *argv[]) | ||
113 | { | ||
114 | int ok; | ||
115 | |||
116 | GNUNET_log_setup ("test_connection_timeout", | ||
117 | "WARNING", | ||
118 | NULL); | ||
119 | |||
120 | ok = 1; | ||
121 | cfg = GNUNET_CONFIGURATION_create (); | ||
122 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", | ||
123 | "localhost"); | ||
124 | GNUNET_SCHEDULER_run (&task_timeout, &ok); | ||
125 | GNUNET_CONFIGURATION_destroy (cfg); | ||
126 | return ok; | ||
127 | } | ||
128 | |||
129 | /* end of test_connection_timeout.c */ | ||
diff --git a/src/util/test_connection_timeout_no_connect.c b/src/util/test_connection_timeout_no_connect.c deleted file mode 100644 index ebcd4b71e..000000000 --- a/src/util/test_connection_timeout_no_connect.c +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_connection_timeout_no_connect.c | ||
22 | * @brief tests for connection.c, doing timeout which connect failure | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | |||
27 | #define PORT 13425 | ||
28 | |||
29 | static struct GNUNET_CONNECTION_Handle *csock; | ||
30 | |||
31 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
32 | |||
33 | static size_t | ||
34 | handle_timeout (void *cls, size_t size, void *buf) | ||
35 | { | ||
36 | int *ok = cls; | ||
37 | |||
38 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received timeout signal.\n"); | ||
39 | GNUNET_assert (size == 0); | ||
40 | GNUNET_assert (buf == NULL); | ||
41 | *ok = 0; | ||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | |||
46 | static void | ||
47 | task_timeout (void *cls) | ||
48 | { | ||
49 | csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); | ||
50 | GNUNET_assert (csock != NULL); | ||
51 | GNUNET_assert (NULL != | ||
52 | GNUNET_CONNECTION_notify_transmit_ready (csock, 1024, | ||
53 | GNUNET_TIME_UNIT_SECONDS, | ||
54 | &handle_timeout, | ||
55 | cls)); | ||
56 | } | ||
57 | |||
58 | |||
59 | int | ||
60 | main (int argc, char *argv[]) | ||
61 | { | ||
62 | int ok; | ||
63 | |||
64 | GNUNET_log_setup ("test_connection_timeout_no_connect", | ||
65 | "WARNING", | ||
66 | NULL); | ||
67 | ok = 1; | ||
68 | cfg = GNUNET_CONFIGURATION_create (); | ||
69 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", | ||
70 | "localhost"); | ||
71 | GNUNET_SCHEDULER_run (&task_timeout, &ok); | ||
72 | GNUNET_CONFIGURATION_destroy (cfg); | ||
73 | return ok; | ||
74 | } | ||
75 | |||
76 | /* end of test_connection_timeout_no_connect.c */ | ||
diff --git a/src/util/test_connection_transmit_cancel.c b/src/util/test_connection_transmit_cancel.c deleted file mode 100644 index 9ef0720ed..000000000 --- a/src/util/test_connection_transmit_cancel.c +++ /dev/null | |||
@@ -1,76 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_connection_transmit_cancel.c | ||
22 | * @brief tests for connection.c | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | |||
27 | #define PORT 12435 | ||
28 | |||
29 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
30 | |||
31 | |||
32 | static size_t | ||
33 | not_run (void *cls, size_t size, void *buf) | ||
34 | { | ||
35 | GNUNET_assert (0); | ||
36 | return 0; | ||
37 | } | ||
38 | |||
39 | |||
40 | static void | ||
41 | task_transmit_cancel (void *cls) | ||
42 | { | ||
43 | int *ok = cls; | ||
44 | struct GNUNET_CONNECTION_TransmitHandle *th; | ||
45 | struct GNUNET_CONNECTION_Handle *csock; | ||
46 | |||
47 | csock = GNUNET_CONNECTION_create_from_connect (cfg, "localhost", PORT); | ||
48 | GNUNET_assert (csock != NULL); | ||
49 | th = GNUNET_CONNECTION_notify_transmit_ready (csock, 12, | ||
50 | GNUNET_TIME_UNIT_MINUTES, | ||
51 | ¬_run, cls); | ||
52 | GNUNET_assert (NULL != th); | ||
53 | GNUNET_CONNECTION_notify_transmit_ready_cancel (th); | ||
54 | GNUNET_CONNECTION_destroy (csock); | ||
55 | *ok = 0; | ||
56 | } | ||
57 | |||
58 | |||
59 | int | ||
60 | main (int argc, char *argv[]) | ||
61 | { | ||
62 | int ok; | ||
63 | |||
64 | GNUNET_log_setup ("test_connection_transmit_cancel", | ||
65 | "WARNING", | ||
66 | NULL); | ||
67 | ok = 1; | ||
68 | cfg = GNUNET_CONFIGURATION_create (); | ||
69 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", | ||
70 | "localhost"); | ||
71 | GNUNET_SCHEDULER_run (&task_transmit_cancel, &ok); | ||
72 | GNUNET_CONFIGURATION_destroy (cfg); | ||
73 | return ok; | ||
74 | } | ||
75 | |||
76 | /* end of test_connection_transmit_cancel.c */ | ||
diff --git a/src/util/test_server.c b/src/util/test_server.c deleted file mode 100644 index 8003adbf4..000000000 --- a/src/util/test_server.c +++ /dev/null | |||
@@ -1,302 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2010, 2014, 2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_server.c | ||
22 | * @brief tests for server.c | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | |||
27 | /** | ||
28 | * TCP port to use for the server. | ||
29 | */ | ||
30 | #define PORT 12435 | ||
31 | |||
32 | /** | ||
33 | * Timeout to use for operations. | ||
34 | */ | ||
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2) | ||
36 | |||
37 | /** | ||
38 | * Test message type. | ||
39 | */ | ||
40 | #define MY_TYPE 128 | ||
41 | |||
42 | /** | ||
43 | * Test message type. | ||
44 | */ | ||
45 | #define MY_TYPE2 129 | ||
46 | |||
47 | /** | ||
48 | * Handle for the server. | ||
49 | */ | ||
50 | static struct GNUNET_SERVER_Handle *server; | ||
51 | |||
52 | /** | ||
53 | * Handle for the client. | ||
54 | */ | ||
55 | static struct GNUNET_MQ_Handle *mq; | ||
56 | |||
57 | /** | ||
58 | * Handle of the server for the client. | ||
59 | */ | ||
60 | static struct GNUNET_SERVER_Client *argclient; | ||
61 | |||
62 | /** | ||
63 | * Our configuration. | ||
64 | */ | ||
65 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
66 | |||
67 | /** | ||
68 | * Number indiciating in which phase of the test we are. | ||
69 | */ | ||
70 | static int ok; | ||
71 | |||
72 | |||
73 | /** | ||
74 | * Final task invoked to clean up. | ||
75 | * | ||
76 | * @param cls NULL | ||
77 | */ | ||
78 | static void | ||
79 | finish_up (void *cls) | ||
80 | { | ||
81 | GNUNET_assert (7 == ok); | ||
82 | ok = 0; | ||
83 | GNUNET_SERVER_destroy (server); | ||
84 | GNUNET_MQ_destroy (mq); | ||
85 | GNUNET_CONFIGURATION_destroy (cfg); | ||
86 | } | ||
87 | |||
88 | |||
89 | /** | ||
90 | * The server has received the second message, initiate clean up. | ||
91 | * | ||
92 | * @param cls NULL | ||
93 | * @param client client we got the message from | ||
94 | * @param message the message | ||
95 | */ | ||
96 | static void | ||
97 | recv_fin_cb (void *cls, | ||
98 | struct GNUNET_SERVER_Client *client, | ||
99 | const struct GNUNET_MessageHeader *message) | ||
100 | { | ||
101 | GNUNET_assert (6 == ok); | ||
102 | ok = 7; | ||
103 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
104 | GNUNET_SCHEDULER_add_now (&finish_up, NULL); | ||
105 | } | ||
106 | |||
107 | |||
108 | /** | ||
109 | * We have received the reply from the server, check that we are at | ||
110 | * the right stage and queue the next message to the server. Cleans | ||
111 | * up #argclient. | ||
112 | * | ||
113 | * @param cls NULL | ||
114 | * @param msg message we got from the server | ||
115 | */ | ||
116 | static void | ||
117 | handle_reply (void *cls, | ||
118 | const struct GNUNET_MessageHeader *msg) | ||
119 | { | ||
120 | struct GNUNET_MQ_Envelope *env; | ||
121 | struct GNUNET_MessageHeader *m; | ||
122 | |||
123 | GNUNET_assert (4 == ok); | ||
124 | ok = 6; | ||
125 | env = GNUNET_MQ_msg (m, | ||
126 | MY_TYPE2); | ||
127 | GNUNET_MQ_send (mq, | ||
128 | env); | ||
129 | } | ||
130 | |||
131 | |||
132 | /** | ||
133 | * Send a reply of type #MY_TYPE from the server to the client. | ||
134 | * Checks that we are in the right phase and transmits the | ||
135 | * reply. Cleans up #argclient state. | ||
136 | * | ||
137 | * @param cls NULL | ||
138 | * @param size number of bytes we are allowed to send | ||
139 | * @param buf where to copy the reply | ||
140 | * @return number of bytes written to @a buf | ||
141 | */ | ||
142 | static size_t | ||
143 | reply_msg (void *cls, | ||
144 | size_t size, | ||
145 | void *buf) | ||
146 | { | ||
147 | struct GNUNET_MessageHeader msg; | ||
148 | |||
149 | GNUNET_assert (3 == ok); | ||
150 | ok = 4; | ||
151 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | ||
152 | msg.type = htons (MY_TYPE); | ||
153 | msg.size = htons (sizeof (struct GNUNET_MessageHeader)); | ||
154 | GNUNET_memcpy (buf, &msg, sizeof (struct GNUNET_MessageHeader)); | ||
155 | GNUNET_assert (NULL != argclient); | ||
156 | GNUNET_SERVER_receive_done (argclient, GNUNET_OK); | ||
157 | GNUNET_SERVER_client_drop (argclient); | ||
158 | argclient = NULL; | ||
159 | return sizeof (struct GNUNET_MessageHeader); | ||
160 | } | ||
161 | |||
162 | |||
163 | /** | ||
164 | * Function called whenever the server receives a message of | ||
165 | * type #MY_TYPE. Checks that we are at the stage where | ||
166 | * we expect the first message, then sends a reply. Stores | ||
167 | * the handle to the client in #argclient. | ||
168 | * | ||
169 | * @param cls NULL | ||
170 | * @param client client that sent the message | ||
171 | * @param message the message we received | ||
172 | */ | ||
173 | static void | ||
174 | recv_cb (void *cls, | ||
175 | struct GNUNET_SERVER_Client *client, | ||
176 | const struct GNUNET_MessageHeader *message) | ||
177 | { | ||
178 | GNUNET_assert (2 == ok); | ||
179 | ok = 3; | ||
180 | argclient = client; | ||
181 | GNUNET_SERVER_client_keep (argclient); | ||
182 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)); | ||
183 | GNUNET_assert (MY_TYPE == ntohs (message->type)); | ||
184 | GNUNET_assert (NULL != | ||
185 | GNUNET_SERVER_notify_transmit_ready (client, | ||
186 | ntohs (message->size), | ||
187 | TIMEOUT, | ||
188 | &reply_msg, | ||
189 | NULL)); | ||
190 | } | ||
191 | |||
192 | |||
193 | /** | ||
194 | * Message handlers for the server. | ||
195 | */ | ||
196 | static struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
197 | {&recv_cb, NULL, MY_TYPE, sizeof (struct GNUNET_MessageHeader)}, | ||
198 | {&recv_fin_cb, NULL, MY_TYPE2, sizeof (struct GNUNET_MessageHeader)}, | ||
199 | {NULL, NULL, 0, 0} | ||
200 | }; | ||
201 | |||
202 | |||
203 | /** | ||
204 | * Generic error handler, called with the appropriate error code and | ||
205 | * the same closure specified at the creation of the message queue. | ||
206 | * Not every message queue implementation supports an error handler. | ||
207 | * | ||
208 | * @param cls closure with the `struct GNUNET_STATISTICS_Handle *` | ||
209 | * @param error error code | ||
210 | */ | ||
211 | static void | ||
212 | mq_error_handler (void *cls, | ||
213 | enum GNUNET_MQ_Error error) | ||
214 | { | ||
215 | GNUNET_assert (0); /* should never happen */ | ||
216 | } | ||
217 | |||
218 | |||
219 | /** | ||
220 | * First task run by the scheduler. Initializes the server and | ||
221 | * a client and asks for a transmission from the client to the | ||
222 | * server. | ||
223 | * | ||
224 | * @param cls NULL | ||
225 | */ | ||
226 | static void | ||
227 | task (void *cls) | ||
228 | { | ||
229 | struct sockaddr_in sa; | ||
230 | struct sockaddr *sap[2]; | ||
231 | socklen_t slens[2]; | ||
232 | struct GNUNET_MQ_Envelope *env; | ||
233 | struct GNUNET_MessageHeader *msg; | ||
234 | struct GNUNET_MQ_MessageHandler chandlers[] = { | ||
235 | GNUNET_MQ_hd_fixed_size (reply, | ||
236 | MY_TYPE, | ||
237 | struct GNUNET_MessageHeader, | ||
238 | cls), | ||
239 | GNUNET_MQ_handler_end () | ||
240 | }; | ||
241 | |||
242 | sap[0] = (struct sockaddr *) &sa; | ||
243 | slens[0] = sizeof (sa); | ||
244 | sap[1] = NULL; | ||
245 | slens[1] = 0; | ||
246 | memset (&sa, 0, sizeof (sa)); | ||
247 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
248 | sa.sin_len = sizeof (sa); | ||
249 | #endif | ||
250 | sa.sin_family = AF_INET; | ||
251 | sa.sin_port = htons (PORT); | ||
252 | server = GNUNET_SERVER_create (NULL, NULL, | ||
253 | sap, slens, | ||
254 | TIMEOUT, GNUNET_NO); | ||
255 | GNUNET_assert (server != NULL); | ||
256 | GNUNET_SERVER_add_handlers (server, handlers); | ||
257 | cfg = GNUNET_CONFIGURATION_create (); | ||
258 | GNUNET_CONFIGURATION_set_value_number (cfg, | ||
259 | "test-server", | ||
260 | "PORT", | ||
261 | PORT); | ||
262 | GNUNET_CONFIGURATION_set_value_string (cfg, | ||
263 | "test-server", | ||
264 | "HOSTNAME", | ||
265 | "localhost"); | ||
266 | GNUNET_CONFIGURATION_set_value_string (cfg, | ||
267 | "resolver", | ||
268 | "HOSTNAME", | ||
269 | "localhost"); | ||
270 | mq = GNUNET_CLIENT_connect (cfg, | ||
271 | "test-server", | ||
272 | chandlers, | ||
273 | &mq_error_handler, | ||
274 | NULL); | ||
275 | GNUNET_assert (NULL != mq); | ||
276 | ok = 2; | ||
277 | env = GNUNET_MQ_msg (msg, | ||
278 | MY_TYPE); | ||
279 | GNUNET_MQ_send (mq, | ||
280 | env); | ||
281 | } | ||
282 | |||
283 | |||
284 | /** | ||
285 | * Runs the test. | ||
286 | * | ||
287 | * @param argc length of @a argv | ||
288 | * @param argv command line arguments (ignored) | ||
289 | * @return 0 on success, otherwise phase of failure | ||
290 | */ | ||
291 | int | ||
292 | main (int argc, char *argv[]) | ||
293 | { | ||
294 | GNUNET_log_setup ("test_server", | ||
295 | "WARNING", | ||
296 | NULL); | ||
297 | ok = 1; | ||
298 | GNUNET_SCHEDULER_run (&task, &ok); | ||
299 | return ok; | ||
300 | } | ||
301 | |||
302 | /* end of test_server.c */ | ||
diff --git a/src/util/test_server_disconnect.c b/src/util/test_server_disconnect.c deleted file mode 100644 index c3d003e90..000000000 --- a/src/util/test_server_disconnect.c +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2010, 2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_server_disconnect.c | ||
22 | * @brief tests for server.c, specifically GNUNET_SERVER_client_disconnect | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_util_lib.h" | ||
26 | |||
27 | |||
28 | #define PORT 12435 | ||
29 | |||
30 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 250) | ||
31 | |||
32 | #define MY_TYPE 128 | ||
33 | |||
34 | static struct GNUNET_SERVER_Handle *server; | ||
35 | |||
36 | static struct GNUNET_MQ_Handle *mq; | ||
37 | |||
38 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
39 | |||
40 | static int ok; | ||
41 | |||
42 | |||
43 | static void | ||
44 | finish_up (void *cls) | ||
45 | { | ||
46 | GNUNET_assert (ok == 5); | ||
47 | ok = 0; | ||
48 | GNUNET_SERVER_destroy (server); | ||
49 | GNUNET_MQ_destroy (mq); | ||
50 | GNUNET_CONFIGURATION_destroy (cfg); | ||
51 | } | ||
52 | |||
53 | |||
54 | static void | ||
55 | notify_disconnect (void *cls, | ||
56 | struct GNUNET_SERVER_Client *clientarg) | ||
57 | { | ||
58 | if (NULL == clientarg) | ||
59 | return; | ||
60 | GNUNET_assert (ok == 4); | ||
61 | ok = 5; | ||
62 | GNUNET_SCHEDULER_add_now (&finish_up, NULL); | ||
63 | } | ||
64 | |||
65 | |||
66 | static void | ||
67 | server_disconnect (void *cls) | ||
68 | { | ||
69 | struct GNUNET_SERVER_Client *argclient = cls; | ||
70 | |||
71 | GNUNET_assert (ok == 3); | ||
72 | ok = 4; | ||
73 | GNUNET_SERVER_client_disconnect (argclient); | ||
74 | GNUNET_SERVER_client_drop (argclient); | ||
75 | } | ||
76 | |||
77 | |||
78 | static void | ||
79 | recv_cb (void *cls, | ||
80 | struct GNUNET_SERVER_Client *client, | ||
81 | const struct GNUNET_MessageHeader *message) | ||
82 | { | ||
83 | GNUNET_assert (ok == 2); | ||
84 | ok = 3; | ||
85 | GNUNET_SERVER_client_keep (client); | ||
86 | GNUNET_SCHEDULER_add_now (&server_disconnect, client); | ||
87 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == ntohs (message->size)); | ||
88 | GNUNET_assert (MY_TYPE == ntohs (message->type)); | ||
89 | GNUNET_SERVER_receive_done (client, GNUNET_OK); | ||
90 | } | ||
91 | |||
92 | |||
93 | static struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
94 | {&recv_cb, NULL, MY_TYPE, sizeof (struct GNUNET_MessageHeader)}, | ||
95 | {NULL, NULL, 0, 0} | ||
96 | }; | ||
97 | |||
98 | |||
99 | static void | ||
100 | task (void *cls) | ||
101 | { | ||
102 | struct sockaddr_in sa; | ||
103 | struct sockaddr *sap[2]; | ||
104 | socklen_t slens[2]; | ||
105 | struct GNUNET_MQ_Envelope *env; | ||
106 | struct GNUNET_MessageHeader *msg; | ||
107 | |||
108 | sap[0] = (struct sockaddr *) &sa; | ||
109 | slens[0] = sizeof (sa); | ||
110 | sap[1] = NULL; | ||
111 | slens[1] = 0; | ||
112 | memset (&sa, 0, sizeof (sa)); | ||
113 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
114 | sa.sin_len = sizeof (sa); | ||
115 | #endif | ||
116 | sa.sin_family = AF_INET; | ||
117 | sa.sin_port = htons (PORT); | ||
118 | server = GNUNET_SERVER_create (NULL, NULL, sap, slens, TIMEOUT, GNUNET_NO); | ||
119 | GNUNET_assert (server != NULL); | ||
120 | GNUNET_SERVER_add_handlers (server, handlers); | ||
121 | GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, NULL); | ||
122 | cfg = GNUNET_CONFIGURATION_create (); | ||
123 | GNUNET_CONFIGURATION_set_value_number (cfg, "test-server", "PORT", PORT); | ||
124 | GNUNET_CONFIGURATION_set_value_string (cfg, "test-server", "HOSTNAME", | ||
125 | "localhost"); | ||
126 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", | ||
127 | "localhost"); | ||
128 | mq = GNUNET_CLIENT_connect (cfg, | ||
129 | "test-server", | ||
130 | NULL, | ||
131 | NULL, | ||
132 | NULL); | ||
133 | GNUNET_assert (NULL != mq); | ||
134 | ok = 2; | ||
135 | env = GNUNET_MQ_msg (msg, | ||
136 | MY_TYPE); | ||
137 | GNUNET_MQ_send (mq, | ||
138 | env); | ||
139 | } | ||
140 | |||
141 | |||
142 | /** | ||
143 | * Main method, starts scheduler with task1, | ||
144 | * checks that "ok" is correct at the end. | ||
145 | */ | ||
146 | static int | ||
147 | check () | ||
148 | { | ||
149 | ok = 1; | ||
150 | GNUNET_SCHEDULER_run (&task, &ok); | ||
151 | return ok; | ||
152 | } | ||
153 | |||
154 | |||
155 | int | ||
156 | main (int argc, char *argv[]) | ||
157 | { | ||
158 | int ret = 0; | ||
159 | |||
160 | GNUNET_log_setup ("test_server_disconnect", "WARNING", NULL); | ||
161 | ret += check (); | ||
162 | |||
163 | return ret; | ||
164 | } | ||
165 | |||
166 | /* end of test_server_disconnect.c */ | ||
diff --git a/src/util/test_server_mst_interrupt.c b/src/util/test_server_mst_interrupt.c deleted file mode 100644 index 3141a75bd..000000000 --- a/src/util/test_server_mst_interrupt.c +++ /dev/null | |||
@@ -1,60 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2010 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_server_mst_interrupt.c | ||
22 | * @brief test for interrupt message processing in server_mst.c | ||
23 | */ | ||
24 | #include "platform.h" | ||
25 | #include "gnunet_protocols.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | |||
28 | static struct GNUNET_SERVER_MessageStreamTokenizer * mst; | ||
29 | |||
30 | |||
31 | /* Callback destroying mst with data in buffer */ | ||
32 | static int | ||
33 | mst_cb (void *cls, void *client, | ||
34 | const struct GNUNET_MessageHeader * message) | ||
35 | { | ||
36 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MST gave me message, destroying\n"); | ||
37 | GNUNET_SERVER_mst_destroy (mst); | ||
38 | return GNUNET_SYSERR; | ||
39 | } | ||
40 | |||
41 | |||
42 | int | ||
43 | main (int argc, char *argv[]) | ||
44 | { | ||
45 | struct GNUNET_PeerIdentity id; | ||
46 | struct GNUNET_MessageHeader msg[2]; | ||
47 | |||
48 | GNUNET_log_setup ("test_server_mst_interrupt", "WARNING", NULL); | ||
49 | memset (&id, 0, sizeof (id)); | ||
50 | msg[0].size = htons (sizeof (msg)); | ||
51 | msg[0].type = htons (sizeof (GNUNET_MESSAGE_TYPE_DUMMY)); | ||
52 | mst = GNUNET_SERVER_mst_create(mst_cb, NULL); | ||
53 | GNUNET_SERVER_mst_receive (mst, &id, | ||
54 | (const char *) &msg, 2 * sizeof (msg), | ||
55 | GNUNET_NO, GNUNET_NO); | ||
56 | /* If we reach this line, it did not crash */ | ||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | /* end of test_server_mst_interrupt.c */ | ||
diff --git a/src/util/test_server_with_client.c b/src/util/test_server_with_client.c deleted file mode 100644 index 63bfda00c..000000000 --- a/src/util/test_server_with_client.c +++ /dev/null | |||
@@ -1,198 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_server_with_client.c | ||
22 | * @brief tests for server.c and client.c, | ||
23 | * specifically disconnect_notify, | ||
24 | * client_get_address and receive_done (resume processing) | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | |||
29 | #define PORT 22335 | ||
30 | |||
31 | #define MY_TYPE 128 | ||
32 | |||
33 | |||
34 | static struct GNUNET_SERVER_Handle *server; | ||
35 | |||
36 | static struct GNUNET_MQ_Handle *mq; | ||
37 | |||
38 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
39 | |||
40 | static int ok; | ||
41 | |||
42 | |||
43 | static void | ||
44 | send_done (void *cls) | ||
45 | { | ||
46 | struct GNUNET_SERVER_Client *argclient = cls; | ||
47 | |||
48 | GNUNET_assert (ok == 3); | ||
49 | ok++; | ||
50 | GNUNET_SERVER_receive_done (argclient, GNUNET_OK); | ||
51 | } | ||
52 | |||
53 | |||
54 | static void | ||
55 | recv_cb (void *cls, | ||
56 | struct GNUNET_SERVER_Client *argclient, | ||
57 | const struct GNUNET_MessageHeader *message) | ||
58 | { | ||
59 | void *addr; | ||
60 | size_t addrlen; | ||
61 | struct sockaddr_in sa; | ||
62 | struct sockaddr_in *have; | ||
63 | |||
64 | GNUNET_assert (GNUNET_OK == | ||
65 | GNUNET_SERVER_client_get_address (argclient, | ||
66 | &addr, | ||
67 | &addrlen)); | ||
68 | |||
69 | GNUNET_assert (addrlen == sizeof (struct sockaddr_in)); | ||
70 | have = addr; | ||
71 | memset (&sa, 0, sizeof (sa)); | ||
72 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
73 | sa.sin_len = sizeof (sa); | ||
74 | #endif | ||
75 | sa.sin_family = AF_INET; | ||
76 | sa.sin_port = have->sin_port; | ||
77 | sa.sin_addr.s_addr = htonl (INADDR_LOOPBACK); | ||
78 | GNUNET_assert (0 == memcmp (&sa, addr, addrlen)); | ||
79 | GNUNET_free (addr); | ||
80 | switch (ok) | ||
81 | { | ||
82 | case 2: | ||
83 | ok++; | ||
84 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
85 | (GNUNET_TIME_UNIT_MILLISECONDS, 50), | ||
86 | &send_done, | ||
87 | argclient); | ||
88 | break; | ||
89 | case 4: | ||
90 | ok++; | ||
91 | GNUNET_MQ_destroy (mq); | ||
92 | GNUNET_SERVER_receive_done (argclient, | ||
93 | GNUNET_OK); | ||
94 | break; | ||
95 | default: | ||
96 | GNUNET_assert (0); | ||
97 | } | ||
98 | |||
99 | } | ||
100 | |||
101 | |||
102 | static void | ||
103 | clean_up (void *cls) | ||
104 | { | ||
105 | GNUNET_SERVER_destroy (server); | ||
106 | server = NULL; | ||
107 | GNUNET_CONFIGURATION_destroy (cfg); | ||
108 | cfg = NULL; | ||
109 | } | ||
110 | |||
111 | |||
112 | /** | ||
113 | * Functions with this signature are called whenever a client | ||
114 | * is disconnected on the network level. | ||
115 | * | ||
116 | * @param cls closure | ||
117 | * @param client identification of the client | ||
118 | */ | ||
119 | static void | ||
120 | notify_disconnect (void *cls, | ||
121 | struct GNUNET_SERVER_Client *client) | ||
122 | { | ||
123 | if (client == NULL) | ||
124 | return; | ||
125 | GNUNET_assert (ok == 5); | ||
126 | ok = 0; | ||
127 | GNUNET_SCHEDULER_add_now (&clean_up, NULL); | ||
128 | } | ||
129 | |||
130 | |||
131 | static struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
132 | {&recv_cb, NULL, MY_TYPE, sizeof (struct GNUNET_MessageHeader)}, | ||
133 | {NULL, NULL, 0, 0} | ||
134 | }; | ||
135 | |||
136 | |||
137 | static void | ||
138 | task (void *cls) | ||
139 | { | ||
140 | struct sockaddr_in sa; | ||
141 | struct sockaddr *sap[2]; | ||
142 | socklen_t slens[2]; | ||
143 | struct GNUNET_MQ_Envelope *env; | ||
144 | struct GNUNET_MessageHeader *msg; | ||
145 | |||
146 | sap[0] = (struct sockaddr *) &sa; | ||
147 | slens[0] = sizeof (sa); | ||
148 | sap[1] = NULL; | ||
149 | slens[1] = 0; | ||
150 | memset (&sa, 0, sizeof (sa)); | ||
151 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
152 | sa.sin_len = sizeof (sa); | ||
153 | #endif | ||
154 | sa.sin_family = AF_INET; | ||
155 | sa.sin_port = htons (PORT); | ||
156 | server = | ||
157 | GNUNET_SERVER_create (NULL, NULL, sap, slens, | ||
158 | GNUNET_TIME_relative_multiply | ||
159 | (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO); | ||
160 | GNUNET_assert (server != NULL); | ||
161 | handlers[0].callback_cls = cls; | ||
162 | GNUNET_SERVER_add_handlers (server, handlers); | ||
163 | GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls); | ||
164 | cfg = GNUNET_CONFIGURATION_create (); | ||
165 | GNUNET_CONFIGURATION_set_value_number (cfg, "test", "PORT", PORT); | ||
166 | GNUNET_CONFIGURATION_set_value_string (cfg, "test", "HOSTNAME", "localhost"); | ||
167 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", | ||
168 | "localhost"); | ||
169 | mq = GNUNET_CLIENT_connect (cfg, | ||
170 | "test", | ||
171 | NULL, | ||
172 | NULL, | ||
173 | NULL); | ||
174 | GNUNET_assert (NULL != mq); | ||
175 | ok = 2; | ||
176 | env = GNUNET_MQ_msg (msg, | ||
177 | MY_TYPE); | ||
178 | GNUNET_MQ_send (mq, | ||
179 | env); | ||
180 | env = GNUNET_MQ_msg (msg, | ||
181 | MY_TYPE); | ||
182 | GNUNET_MQ_send (mq, | ||
183 | env); | ||
184 | } | ||
185 | |||
186 | |||
187 | int | ||
188 | main (int argc, char *argv[]) | ||
189 | { | ||
190 | GNUNET_log_setup ("test_server_with_client", | ||
191 | "WARNING", | ||
192 | NULL); | ||
193 | ok = 1; | ||
194 | GNUNET_SCHEDULER_run (&task, NULL); | ||
195 | return ok; | ||
196 | } | ||
197 | |||
198 | /* end of test_server_with_client.c */ | ||
diff --git a/src/util/test_server_with_client_unix.c b/src/util/test_server_with_client_unix.c deleted file mode 100644 index 8fabbe210..000000000 --- a/src/util/test_server_with_client_unix.c +++ /dev/null | |||
@@ -1,176 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2016 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 3, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | ||
20 | /** | ||
21 | * @file util/test_server_with_client_unix.c | ||
22 | * @brief tests for server.c and client.c, | ||
23 | * specifically disconnect_notify, | ||
24 | * client_get_address and receive_done (resume processing) | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | |||
29 | #define MY_TYPE 128 | ||
30 | |||
31 | |||
32 | static struct GNUNET_SERVER_Handle *server; | ||
33 | |||
34 | static struct GNUNET_MQ_Handle *mq; | ||
35 | |||
36 | static struct GNUNET_CONFIGURATION_Handle *cfg; | ||
37 | |||
38 | static int ok; | ||
39 | |||
40 | |||
41 | static void | ||
42 | send_done (void *cls) | ||
43 | { | ||
44 | struct GNUNET_SERVER_Client *argclient = cls; | ||
45 | |||
46 | GNUNET_assert (ok == 3); | ||
47 | ok++; | ||
48 | GNUNET_SERVER_receive_done (argclient, GNUNET_OK); | ||
49 | } | ||
50 | |||
51 | |||
52 | static void | ||
53 | recv_cb (void *cls, | ||
54 | struct GNUNET_SERVER_Client *argclient, | ||
55 | const struct GNUNET_MessageHeader *message) | ||
56 | { | ||
57 | switch (ok) | ||
58 | { | ||
59 | case 2: | ||
60 | ok++; | ||
61 | (void) GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | ||
62 | (GNUNET_TIME_UNIT_MILLISECONDS, 50), | ||
63 | &send_done, | ||
64 | argclient); | ||
65 | break; | ||
66 | case 4: | ||
67 | ok++; | ||
68 | GNUNET_MQ_destroy (mq); | ||
69 | GNUNET_SERVER_receive_done (argclient, GNUNET_OK); | ||
70 | break; | ||
71 | default: | ||
72 | GNUNET_assert (0); | ||
73 | } | ||
74 | |||
75 | } | ||
76 | |||
77 | |||
78 | static void | ||
79 | clean_up (void *cls) | ||
80 | { | ||
81 | GNUNET_SERVER_destroy (server); | ||
82 | server = NULL; | ||
83 | GNUNET_CONFIGURATION_destroy (cfg); | ||
84 | cfg = NULL; | ||
85 | } | ||
86 | |||
87 | |||
88 | /** | ||
89 | * Functions with this signature are called whenever a client | ||
90 | * is disconnected on the network level. | ||
91 | * | ||
92 | * @param cls closure | ||
93 | * @param client identification of the client | ||
94 | */ | ||
95 | static void | ||
96 | notify_disconnect (void *cls, | ||
97 | struct GNUNET_SERVER_Client *client) | ||
98 | { | ||
99 | if (client == NULL) | ||
100 | return; | ||
101 | GNUNET_assert (ok == 5); | ||
102 | ok = 0; | ||
103 | (void) GNUNET_SCHEDULER_add_now (&clean_up, NULL); | ||
104 | } | ||
105 | |||
106 | |||
107 | static struct GNUNET_SERVER_MessageHandler handlers[] = { | ||
108 | {&recv_cb, NULL, MY_TYPE, sizeof (struct GNUNET_MessageHeader)}, | ||
109 | {NULL, NULL, 0, 0} | ||
110 | }; | ||
111 | |||
112 | |||
113 | static void | ||
114 | task (void *cls) | ||
115 | { | ||
116 | struct sockaddr_un un; | ||
117 | const char *unixpath = "/tmp/testsock"; | ||
118 | struct sockaddr *sap[2]; | ||
119 | socklen_t slens[2]; | ||
120 | struct GNUNET_MQ_Envelope *env; | ||
121 | struct GNUNET_MessageHeader *msg; | ||
122 | |||
123 | memset (&un, 0, sizeof (un)); | ||
124 | un.sun_family = AF_UNIX; | ||
125 | strncpy(un.sun_path, unixpath, sizeof (un.sun_path) - 1); | ||
126 | #if HAVE_SOCKADDR_UN_SUN_LEN | ||
127 | un.sun_len = (u_char) sizeof (un); | ||
128 | #endif | ||
129 | |||
130 | sap[0] = (struct sockaddr *) &un; | ||
131 | slens[0] = sizeof (un); | ||
132 | sap[1] = NULL; | ||
133 | slens[1] = 0; | ||
134 | server = | ||
135 | GNUNET_SERVER_create (NULL, NULL, sap, slens, | ||
136 | GNUNET_TIME_relative_multiply | ||
137 | (GNUNET_TIME_UNIT_MILLISECONDS, 250), GNUNET_NO); | ||
138 | GNUNET_assert (server != NULL); | ||
139 | handlers[0].callback_cls = cls; | ||
140 | GNUNET_SERVER_add_handlers (server, handlers); | ||
141 | GNUNET_SERVER_disconnect_notify (server, ¬ify_disconnect, cls); | ||
142 | cfg = GNUNET_CONFIGURATION_create (); | ||
143 | |||
144 | GNUNET_CONFIGURATION_set_value_string (cfg, "test", "UNIXPATH", unixpath); | ||
145 | GNUNET_CONFIGURATION_set_value_string (cfg, "resolver", "HOSTNAME", | ||
146 | "localhost"); | ||
147 | mq = GNUNET_CLIENT_connect (cfg, | ||
148 | "test", | ||
149 | NULL, | ||
150 | NULL, | ||
151 | NULL); | ||
152 | GNUNET_assert (NULL != mq); | ||
153 | ok = 2; | ||
154 | env = GNUNET_MQ_msg (msg, | ||
155 | MY_TYPE); | ||
156 | GNUNET_MQ_send (mq, | ||
157 | env); | ||
158 | env = GNUNET_MQ_msg (msg, | ||
159 | MY_TYPE); | ||
160 | GNUNET_MQ_send (mq, | ||
161 | env); | ||
162 | } | ||
163 | |||
164 | |||
165 | int | ||
166 | main (int argc, char *argv[]) | ||
167 | { | ||
168 | GNUNET_log_setup ("test_server_with_client_unix", | ||
169 | "WARNING", | ||
170 | NULL); | ||
171 | ok = 1; | ||
172 | GNUNET_SCHEDULER_run (&task, NULL); | ||
173 | return ok; | ||
174 | } | ||
175 | |||
176 | /* end of test_server_with_client_unix.c */ | ||
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c index ab0b00d76..4759f3746 100644 --- a/src/vpn/gnunet-service-vpn.c +++ b/src/vpn/gnunet-service-vpn.c | |||
@@ -2217,12 +2217,10 @@ route_packet (struct DestinationEntry *destination, | |||
2217 | * and forward the packet. | 2217 | * and forward the packet. |
2218 | * | 2218 | * |
2219 | * @param cls closure, NULL | 2219 | * @param cls closure, NULL |
2220 | * @param client NULL | ||
2221 | * @param message message we got from the client (VPN channel interface) | 2220 | * @param message message we got from the client (VPN channel interface) |
2222 | */ | 2221 | */ |
2223 | static int | 2222 | static int |
2224 | message_token (void *cls, | 2223 | message_token (void *cls, |
2225 | void *client, | ||
2226 | const struct GNUNET_MessageHeader *message) | 2224 | const struct GNUNET_MessageHeader *message) |
2227 | { | 2225 | { |
2228 | const struct GNUNET_TUN_Layer2PacketHeader *tun; | 2226 | const struct GNUNET_TUN_Layer2PacketHeader *tun; |