summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichele Papalini <micpapal@cisco.com>2020-02-26 16:59:39 +0000
committerGerrit Code Review <gerrit@fd.io>2020-02-26 16:59:39 +0000
commitda2366b91ec8d10e4fd15903b689a7abaf5a2769 (patch)
tree14111810d54ac497893a11c69e52bf4f7f2a59b0
parenta2c5df5ce653ba6362931cb7eda0fb53b002f8ac (diff)
parentf4433f28b509a9f67ca85d79000ccf9c2f4b7a24 (diff)
Merge "[HICN-534] Major rework on libtransport organization"
-rw-r--r--apps/higet/higet.cc5
-rw-r--r--apps/http-proxy/src/IcnReceiver.cc2
-rw-r--r--libtransport/CMakeLists.txt3
-rw-r--r--libtransport/includes/hicn/transport/CMakeLists.txt38
-rw-r--r--libtransport/includes/hicn/transport/core/CMakeLists.txt25
-rw-r--r--libtransport/includes/hicn/transport/core/content_object.h (renamed from libtransport/src/hicn/transport/core/content_object.h)0
-rw-r--r--libtransport/includes/hicn/transport/core/interest.h (renamed from libtransport/src/hicn/transport/core/interest.h)1
-rw-r--r--libtransport/includes/hicn/transport/core/name.h (renamed from libtransport/src/hicn/transport/core/name.h)0
-rw-r--r--libtransport/includes/hicn/transport/core/packet.h (renamed from libtransport/src/hicn/transport/core/packet.h)6
-rw-r--r--libtransport/includes/hicn/transport/core/payload_type.h (renamed from libtransport/src/hicn/transport/core/payload_type.h)0
-rw-r--r--libtransport/includes/hicn/transport/core/prefix.h (renamed from libtransport/src/hicn/transport/core/prefix.h)1
-rw-r--r--libtransport/includes/hicn/transport/errors/CMakeLists.txt (renamed from libtransport/src/hicn/transport/errors/CMakeLists.txt)1
-rw-r--r--libtransport/includes/hicn/transport/errors/errors.h (renamed from libtransport/src/hicn/transport/errors/errors.h)0
-rw-r--r--libtransport/includes/hicn/transport/errors/indexing_exception.h (renamed from libtransport/src/hicn/transport/errors/indexing_exception.h)0
-rw-r--r--libtransport/includes/hicn/transport/errors/invalid_ip_address_exception.h (renamed from libtransport/src/hicn/transport/errors/invalid_ip_address_exception.h)0
-rw-r--r--libtransport/includes/hicn/transport/errors/malformed_ahpacket_exception.h (renamed from libtransport/src/hicn/transport/errors/malformed_ahpacket_exception.h)0
-rw-r--r--libtransport/includes/hicn/transport/errors/malformed_name_exception.h (renamed from libtransport/src/hicn/transport/errors/malformed_name_exception.h)0
-rw-r--r--libtransport/includes/hicn/transport/errors/malformed_packet_exception.h (renamed from libtransport/src/hicn/transport/errors/malformed_packet_exception.h)0
-rw-r--r--libtransport/includes/hicn/transport/errors/not_implemented_exception.h (renamed from libtransport/src/hicn/transport/errors/not_implemented_exception.h)0
-rw-r--r--libtransport/includes/hicn/transport/errors/null_pointer_exception.h (renamed from libtransport/src/hicn/transport/errors/null_pointer_exception.h)0
-rw-r--r--libtransport/includes/hicn/transport/errors/runtime_exception.h (renamed from libtransport/src/hicn/transport/errors/runtime_exception.h)0
-rw-r--r--libtransport/includes/hicn/transport/errors/tokenizer_exception.h (renamed from libtransport/src/hicn/transport/errors/tokenizer_exception.h)0
-rw-r--r--libtransport/includes/hicn/transport/errors/unexpected_manifest_exception.h (renamed from libtransport/src/hicn/transport/errors/unexpected_manifest_exception.h)0
-rw-r--r--libtransport/includes/hicn/transport/http/CMakeLists.txt (renamed from libtransport/src/hicn/transport/http/CMakeLists.txt)12
-rw-r--r--libtransport/includes/hicn/transport/http/client_connection.h (renamed from libtransport/src/hicn/transport/http/client_connection.h)51
-rw-r--r--libtransport/includes/hicn/transport/http/default_values.h (renamed from libtransport/src/hicn/transport/http/default_values.h)0
-rw-r--r--libtransport/includes/hicn/transport/http/facade.h (renamed from libtransport/src/hicn/transport/http/facade.h)2
-rw-r--r--libtransport/includes/hicn/transport/http/message.h (renamed from libtransport/src/hicn/transport/http/message.h)0
-rw-r--r--libtransport/includes/hicn/transport/http/request.h (renamed from libtransport/src/hicn/transport/http/request.h)0
-rw-r--r--libtransport/includes/hicn/transport/http/response.h (renamed from libtransport/src/hicn/transport/http/response.h)0
-rw-r--r--libtransport/includes/hicn/transport/interfaces/CMakeLists.txt35
-rw-r--r--libtransport/includes/hicn/transport/interfaces/callbacks.h (renamed from libtransport/src/hicn/transport/interfaces/callbacks.h)15
-rw-r--r--libtransport/includes/hicn/transport/interfaces/p2psecure_socket_consumer.h32
-rw-r--r--libtransport/includes/hicn/transport/interfaces/p2psecure_socket_producer.h36
-rw-r--r--libtransport/includes/hicn/transport/interfaces/publication_options.h (renamed from libtransport/src/hicn/transport/interfaces/publication_options.h)0
-rw-r--r--libtransport/includes/hicn/transport/interfaces/rtc_socket_producer.h (renamed from libtransport/src/hicn/transport/protocols/download_observer.h)16
-rw-r--r--libtransport/includes/hicn/transport/interfaces/socket_consumer.h (renamed from libtransport/src/hicn/transport/interfaces/socket_consumer.h)232
-rw-r--r--libtransport/includes/hicn/transport/interfaces/socket_options_default_values.h (renamed from libtransport/src/hicn/transport/interfaces/socket_options_default_values.h)0
-rw-r--r--libtransport/includes/hicn/transport/interfaces/socket_options_keys.h (renamed from libtransport/src/hicn/transport/interfaces/socket_options_keys.h)7
-rw-r--r--libtransport/includes/hicn/transport/interfaces/socket_producer.h149
-rw-r--r--libtransport/includes/hicn/transport/interfaces/statistics.h (renamed from libtransport/src/hicn/transport/protocols/statistics.h)12
-rw-r--r--libtransport/includes/hicn/transport/interfaces/verification_policy.h (renamed from libtransport/src/hicn/transport/interfaces/verification_policy.h)0
-rw-r--r--libtransport/includes/hicn/transport/portability/CMakeLists.txt (renamed from libtransport/src/hicn/transport/portability/CMakeLists.txt)1
-rw-r--r--libtransport/includes/hicn/transport/portability/c_portability.h (renamed from libtransport/src/hicn/transport/portability/c_portability.h)0
-rw-r--r--libtransport/includes/hicn/transport/portability/portability.h (renamed from libtransport/src/hicn/transport/portability/portability.h)0
-rw-r--r--libtransport/includes/hicn/transport/portability/win_portability.h (renamed from libtransport/src/hicn/transport/portability/win_portability.h)0
-rw-r--r--libtransport/includes/hicn/transport/security/CMakeLists.txt27
-rw-r--r--libtransport/includes/hicn/transport/security/crypto_hash.h (renamed from libtransport/src/hicn/transport/utils/crypto_hash.h)2
-rw-r--r--libtransport/includes/hicn/transport/security/crypto_hash_type.h (renamed from libtransport/src/hicn/transport/utils/crypto_hash_type.h)0
-rw-r--r--libtransport/includes/hicn/transport/security/crypto_hasher.h (renamed from libtransport/src/hicn/transport/utils/crypto_hasher.h)2
-rw-r--r--libtransport/includes/hicn/transport/security/crypto_suite.h (renamed from libtransport/src/hicn/transport/utils/crypto_suite.h)3
-rw-r--r--libtransport/includes/hicn/transport/security/identity.h (renamed from libtransport/src/hicn/transport/utils/identity.h)7
-rw-r--r--libtransport/includes/hicn/transport/security/key_id.h (renamed from libtransport/src/hicn/transport/utils/key_id.h)0
-rw-r--r--libtransport/includes/hicn/transport/security/signer.h (renamed from libtransport/src/hicn/transport/utils/signer.h)0
-rw-r--r--libtransport/includes/hicn/transport/security/verifier.h (renamed from libtransport/src/hicn/transport/utils/verifier.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/CMakeLists.txt39
-rw-r--r--libtransport/includes/hicn/transport/utils/array.h (renamed from libtransport/src/hicn/transport/utils/array.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/branch_prediction.h (renamed from libtransport/src/hicn/transport/utils/branch_prediction.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/chrono_typedefs.h (renamed from libtransport/src/hicn/transport/utils/chrono_typedefs.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/conversions.h (renamed from libtransport/src/hicn/transport/utils/conversions.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/daemonizator.h (renamed from libtransport/src/hicn/transport/utils/daemonizator.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/hash.h (renamed from libtransport/src/hicn/transport/utils/hash.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/linux.h (renamed from libtransport/src/hicn/transport/utils/linux.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/literals.h (renamed from libtransport/src/hicn/transport/utils/literals.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/log.h (renamed from libtransport/src/hicn/transport/utils/log.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/membuf.h (renamed from libtransport/src/hicn/transport/utils/membuf.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/object_pool.h (renamed from libtransport/src/hicn/transport/utils/object_pool.h)1
-rw-r--r--libtransport/includes/hicn/transport/utils/ring_buffer.h (renamed from libtransport/src/hicn/transport/utils/ring_buffer.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/spinlock.h (renamed from libtransport/src/hicn/transport/utils/spinlock.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/string_tokenizer.h (renamed from libtransport/src/hicn/transport/utils/string_tokenizer.h)0
-rw-r--r--libtransport/includes/hicn/transport/utils/uri.h (renamed from libtransport/src/hicn/transport/utils/uri.h)0
-rw-r--r--libtransport/src/CMakeLists.txt (renamed from libtransport/src/hicn/transport/CMakeLists.txt)26
-rw-r--r--libtransport/src/config.h.in (renamed from libtransport/src/hicn/transport/config.h.in)0
-rw-r--r--libtransport/src/core/CMakeLists.txt (renamed from libtransport/src/hicn/transport/core/CMakeLists.txt)6
-rw-r--r--libtransport/src/core/connector.cc (renamed from libtransport/src/hicn/transport/core/connector.cc)2
-rw-r--r--libtransport/src/core/connector.h (renamed from libtransport/src/hicn/transport/core/connector.h)0
-rw-r--r--libtransport/src/core/content_object.cc (renamed from libtransport/src/hicn/transport/core/content_object.cc)0
-rw-r--r--libtransport/src/core/facade.h (renamed from libtransport/src/hicn/transport/core/facade.h)14
-rw-r--r--libtransport/src/core/forwarder_interface.h (renamed from libtransport/src/hicn/transport/core/forwarder_interface.h)6
-rw-r--r--libtransport/src/core/hicn_forwarder_interface.cc (renamed from libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc)2
-rw-r--r--libtransport/src/core/hicn_forwarder_interface.h (renamed from libtransport/src/hicn/transport/core/hicn_forwarder_interface.h)5
-rw-r--r--libtransport/src/core/hicn_vapi.c (renamed from libtransport/src/hicn/transport/core/hicn_vapi.c)150
-rw-r--r--libtransport/src/core/hicn_vapi.h (renamed from libtransport/src/hicn/transport/core/hicn_vapi.h)0
-rw-r--r--libtransport/src/core/interest.cc (renamed from libtransport/src/hicn/transport/core/interest.cc)0
-rw-r--r--libtransport/src/core/manifest.cc (renamed from libtransport/src/hicn/transport/core/manifest.cc)0
-rw-r--r--libtransport/src/core/manifest.h (renamed from libtransport/src/hicn/transport/core/manifest.h)3
-rw-r--r--libtransport/src/core/manifest_format.h (renamed from libtransport/src/hicn/transport/core/manifest_format.h)2
-rw-r--r--libtransport/src/core/manifest_format_fixed.cc (renamed from libtransport/src/hicn/transport/core/manifest_format_fixed.cc)3
-rw-r--r--libtransport/src/core/manifest_format_fixed.h (renamed from libtransport/src/hicn/transport/core/manifest_format_fixed.h)3
-rw-r--r--libtransport/src/core/manifest_inline.h (renamed from libtransport/src/hicn/transport/core/manifest_inline.h)5
-rw-r--r--libtransport/src/core/memif_connector.cc (renamed from libtransport/src/hicn/transport/core/memif_connector.cc)3
-rw-r--r--libtransport/src/core/memif_connector.h (renamed from libtransport/src/hicn/transport/core/memif_connector.h)9
-rw-r--r--libtransport/src/core/memif_vapi.c (renamed from libtransport/src/hicn/transport/core/memif_vapi.c)57
-rw-r--r--libtransport/src/core/memif_vapi.h (renamed from libtransport/src/hicn/transport/core/memif_vapi.h)0
-rw-r--r--libtransport/src/core/name.cc (renamed from libtransport/src/hicn/transport/core/name.cc)3
-rw-r--r--libtransport/src/core/packet.cc (renamed from libtransport/src/hicn/transport/core/packet.cc)0
-rw-r--r--libtransport/src/core/pending_interest.cc (renamed from libtransport/src/hicn/transport/core/pending_interest.cc)2
-rw-r--r--libtransport/src/core/pending_interest.h (renamed from libtransport/src/hicn/transport/core/pending_interest.h)3
-rw-r--r--libtransport/src/core/portal.h (renamed from libtransport/src/hicn/transport/core/portal.h)9
-rw-r--r--libtransport/src/core/prefix.cc (renamed from libtransport/src/hicn/transport/core/prefix.cc)0
-rw-r--r--libtransport/src/core/raw_socket_connector.cc (renamed from libtransport/src/hicn/transport/core/raw_socket_connector.cc)3
-rw-r--r--libtransport/src/core/raw_socket_connector.h (renamed from libtransport/src/hicn/transport/core/raw_socket_connector.h)3
-rw-r--r--libtransport/src/core/raw_socket_interface.cc (renamed from libtransport/src/hicn/transport/core/raw_socket_interface.cc)3
-rw-r--r--libtransport/src/core/raw_socket_interface.h (renamed from libtransport/src/hicn/transport/core/raw_socket_interface.h)5
-rw-r--r--libtransport/src/core/tcp_socket_connector.cc (renamed from libtransport/src/hicn/transport/core/tcp_socket_connector.cc)5
-rw-r--r--libtransport/src/core/tcp_socket_connector.h (renamed from libtransport/src/hicn/transport/core/tcp_socket_connector.h)3
-rw-r--r--libtransport/src/core/test/CMakeLists.txt (renamed from libtransport/src/hicn/transport/core/test/CMakeLists.txt)0
-rw-r--r--libtransport/src/core/test/test_core_manifest.cc (renamed from libtransport/src/hicn/transport/core/test/test_core_manifest.cc)0
-rw-r--r--libtransport/src/core/udp_socket_connector.cc (renamed from libtransport/src/hicn/transport/core/udp_socket_connector.cc)6
-rw-r--r--libtransport/src/core/udp_socket_connector.h (renamed from libtransport/src/hicn/transport/core/udp_socket_connector.h)3
-rw-r--r--libtransport/src/core/vpp_forwarder_interface.cc (renamed from libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc)39
-rw-r--r--libtransport/src/core/vpp_forwarder_interface.h (renamed from libtransport/src/hicn/transport/core/vpp_forwarder_interface.h)9
-rw-r--r--libtransport/src/hicn/transport/http/client_connection.cc220
-rw-r--r--libtransport/src/hicn/transport/http/server_acceptor.cc110
-rw-r--r--libtransport/src/hicn/transport/http/server_acceptor.h63
-rw-r--r--libtransport/src/hicn/transport/http/server_publisher.cc173
-rw-r--r--libtransport/src/hicn/transport/http/server_publisher.h69
-rw-r--r--libtransport/src/hicn/transport/interfaces/socket_consumer.cc862
-rw-r--r--libtransport/src/hicn/transport/interfaces/socket_producer.cc909
-rw-r--r--libtransport/src/hicn/transport/interfaces/socket_producer.h295
-rw-r--r--libtransport/src/hicn/transport/protocols/manifest_indexing_manager.cc297
-rw-r--r--libtransport/src/http/CMakeLists.txt21
-rw-r--r--libtransport/src/http/client_connection.cc317
-rw-r--r--libtransport/src/http/request.cc (renamed from libtransport/src/hicn/transport/http/request.cc)0
-rw-r--r--libtransport/src/http/response.cc (renamed from libtransport/src/hicn/transport/http/response.cc)0
-rw-r--r--libtransport/src/implementation/CMakeLists.txt (renamed from libtransport/src/hicn/transport/interfaces/CMakeLists.txt)27
-rw-r--r--libtransport/src/implementation/p2psecure_socket_consumer.cc (renamed from libtransport/src/hicn/transport/interfaces/p2psecure_socket_consumer.cc)55
-rw-r--r--libtransport/src/implementation/p2psecure_socket_consumer.h (renamed from libtransport/src/hicn/transport/interfaces/p2psecure_socket_consumer.h)25
-rw-r--r--libtransport/src/implementation/p2psecure_socket_producer.cc (renamed from libtransport/src/hicn/transport/interfaces/p2psecure_socket_producer.cc)52
-rw-r--r--libtransport/src/implementation/p2psecure_socket_producer.h (renamed from libtransport/src/hicn/transport/interfaces/p2psecure_socket_producer.h)33
-rw-r--r--libtransport/src/implementation/rtc_socket_producer.cc (renamed from libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc)50
-rw-r--r--libtransport/src/implementation/rtc_socket_producer.h (renamed from libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h)23
-rw-r--r--libtransport/src/implementation/socket.h (renamed from libtransport/src/hicn/transport/interfaces/socket.h)11
-rw-r--r--libtransport/src/implementation/socket_consumer.h950
-rw-r--r--libtransport/src/implementation/socket_producer.h1061
-rw-r--r--libtransport/src/implementation/tls_rtc_socket_producer.cc (renamed from libtransport/src/hicn/transport/interfaces/tls_rtc_socket_producer.cc)39
-rw-r--r--libtransport/src/implementation/tls_rtc_socket_producer.h (renamed from libtransport/src/hicn/transport/interfaces/tls_rtc_socket_producer.h)14
-rw-r--r--libtransport/src/implementation/tls_socket_consumer.cc (renamed from libtransport/src/hicn/transport/interfaces/tls_socket_consumer.cc)54
-rw-r--r--libtransport/src/implementation/tls_socket_consumer.h (renamed from libtransport/src/hicn/transport/interfaces/tls_socket_consumer.h)29
-rw-r--r--libtransport/src/implementation/tls_socket_producer.cc (renamed from libtransport/src/hicn/transport/interfaces/tls_socket_producer.cc)52
-rw-r--r--libtransport/src/implementation/tls_socket_producer.h (renamed from libtransport/src/hicn/transport/interfaces/tls_socket_producer.h)20
-rw-r--r--libtransport/src/interfaces/CMakeLists.txt39
-rw-r--r--libtransport/src/interfaces/callbacks.cc (renamed from libtransport/src/hicn/transport/interfaces/callbacks.cc)2
-rw-r--r--libtransport/src/interfaces/p2psecure_socket_consumer.cc32
-rw-r--r--libtransport/src/interfaces/p2psecure_socket_producer.cc34
-rw-r--r--libtransport/src/interfaces/rtc_socket_producer.cc29
-rw-r--r--libtransport/src/interfaces/socket_consumer.cc196
-rw-r--r--libtransport/src/interfaces/socket_producer.cc198
-rw-r--r--libtransport/src/interfaces/tls_rtc_socket_producer.cc32
-rw-r--r--libtransport/src/interfaces/tls_rtc_socket_producer.h36
-rw-r--r--libtransport/src/interfaces/tls_socket_consumer.cc31
-rw-r--r--libtransport/src/interfaces/tls_socket_consumer.h36
-rw-r--r--libtransport/src/interfaces/tls_socket_producer.cc31
-rw-r--r--libtransport/src/interfaces/tls_socket_producer.h36
-rw-r--r--libtransport/src/protocols/CMakeLists.txt (renamed from libtransport/src/hicn/transport/protocols/CMakeLists.txt)2
-rw-r--r--libtransport/src/protocols/byte_stream_reassembly.cc (renamed from libtransport/src/hicn/transport/protocols/byte_stream_reassembly.cc)17
-rw-r--r--libtransport/src/protocols/byte_stream_reassembly.h (renamed from libtransport/src/hicn/transport/protocols/byte_stream_reassembly.h)4
-rw-r--r--libtransport/src/protocols/cbr.cc (renamed from libtransport/src/hicn/transport/protocols/cbr.cc)7
-rw-r--r--libtransport/src/protocols/cbr.h (renamed from libtransport/src/hicn/transport/protocols/cbr.h)4
-rw-r--r--libtransport/src/protocols/congestion_window_protocol.h (renamed from libtransport/src/hicn/transport/protocols/congestion_window_protocol.h)0
-rw-r--r--libtransport/src/protocols/consumer.conf (renamed from libtransport/src/hicn/transport/protocols/consumer.conf)0
-rw-r--r--libtransport/src/protocols/data_processing_events.h (renamed from libtransport/src/hicn/transport/protocols/data_processing_events.h)0
-rw-r--r--libtransport/src/protocols/datagram_reassembly.cc (renamed from libtransport/src/hicn/transport/protocols/datagram_reassembly.cc)7
-rw-r--r--libtransport/src/protocols/datagram_reassembly.h (renamed from libtransport/src/hicn/transport/protocols/datagram_reassembly.h)4
-rw-r--r--libtransport/src/protocols/errors.cc (renamed from libtransport/src/hicn/transport/protocols/errors.cc)2
-rw-r--r--libtransport/src/protocols/errors.h (renamed from libtransport/src/hicn/transport/protocols/errors.h)0
-rw-r--r--libtransport/src/protocols/incremental_indexer.cc (renamed from libtransport/src/hicn/transport/protocols/incremental_indexer.cc)3
-rw-r--r--libtransport/src/protocols/incremental_indexer.h (renamed from libtransport/src/hicn/transport/protocols/incremental_indexer.h)12
-rw-r--r--libtransport/src/protocols/indexer.cc (renamed from libtransport/src/hicn/transport/protocols/indexer.cc)25
-rw-r--r--libtransport/src/protocols/indexer.h (renamed from libtransport/src/hicn/transport/protocols/indexer.h)6
-rw-r--r--libtransport/src/protocols/manifest_incremental_indexer.cc (renamed from libtransport/src/hicn/transport/protocols/manifest_incremental_indexer.cc)14
-rw-r--r--libtransport/src/protocols/manifest_incremental_indexer.h (renamed from libtransport/src/hicn/transport/protocols/manifest_incremental_indexer.h)11
-rw-r--r--libtransport/src/protocols/packet_manager.h (renamed from libtransport/src/hicn/transport/protocols/packet_manager.h)4
-rw-r--r--libtransport/src/protocols/protocol.cc (renamed from libtransport/src/hicn/transport/protocols/protocol.cc)8
-rw-r--r--libtransport/src/protocols/protocol.h (renamed from libtransport/src/hicn/transport/protocols/protocol.h)23
-rw-r--r--libtransport/src/protocols/raaqm.cc (renamed from libtransport/src/hicn/transport/protocols/raaqm.cc)30
-rw-r--r--libtransport/src/protocols/raaqm.h (renamed from libtransport/src/hicn/transport/protocols/raaqm.h)13
-rw-r--r--libtransport/src/protocols/raaqm_data_path.cc (renamed from libtransport/src/hicn/transport/protocols/raaqm_data_path.cc)3
-rw-r--r--libtransport/src/protocols/raaqm_data_path.h (renamed from libtransport/src/hicn/transport/protocols/raaqm_data_path.h)3
-rw-r--r--libtransport/src/protocols/rate_estimation.cc (renamed from libtransport/src/hicn/transport/protocols/rate_estimation.cc)3
-rw-r--r--libtransport/src/protocols/rate_estimation.h (renamed from libtransport/src/hicn/transport/protocols/rate_estimation.h)9
-rw-r--r--libtransport/src/protocols/reassembly.cc (renamed from libtransport/src/hicn/transport/protocols/reassembly.cc)8
-rw-r--r--libtransport/src/protocols/reassembly.h (renamed from libtransport/src/hicn/transport/protocols/reassembly.h)10
-rw-r--r--libtransport/src/protocols/rtc.cc (renamed from libtransport/src/hicn/transport/protocols/rtc.cc)11
-rw-r--r--libtransport/src/protocols/rtc.h (renamed from libtransport/src/hicn/transport/protocols/rtc.h)14
-rw-r--r--libtransport/src/protocols/rtc_data_path.cc (renamed from libtransport/src/hicn/transport/protocols/rtc_data_path.cc)58
-rw-r--r--libtransport/src/protocols/rtc_data_path.h (renamed from libtransport/src/hicn/transport/protocols/rtc_data_path.h)17
-rw-r--r--libtransport/src/protocols/test/CMakeLists.txt (renamed from libtransport/src/hicn/transport/protocols/test/CMakeLists.txt)0
-rw-r--r--libtransport/src/protocols/test/test_transport_producer.cc (renamed from libtransport/src/hicn/transport/protocols/test/test_transport_producer.cc)0
-rw-r--r--libtransport/src/protocols/verification_manager.cc (renamed from libtransport/src/hicn/transport/protocols/verification_manager.cc)11
-rw-r--r--libtransport/src/protocols/verification_manager.h (renamed from libtransport/src/hicn/transport/protocols/verification_manager.h)12
-rw-r--r--libtransport/src/security/CMakeLists.txt22
-rw-r--r--libtransport/src/security/identity.cc (renamed from libtransport/src/hicn/transport/utils/identity.cc)2
-rw-r--r--libtransport/src/security/signer.cc (renamed from libtransport/src/hicn/transport/utils/signer.cc)4
-rw-r--r--libtransport/src/security/verifier.cc (renamed from libtransport/src/hicn/transport/utils/verifier.cc)11
-rw-r--r--libtransport/src/utils/CMakeLists.txt (renamed from libtransport/src/hicn/transport/utils/CMakeLists.txt)31
-rw-r--r--libtransport/src/utils/content_store.cc (renamed from libtransport/src/hicn/transport/utils/content_store.cc)8
-rw-r--r--libtransport/src/utils/content_store.h (renamed from libtransport/src/hicn/transport/utils/content_store.h)1
-rw-r--r--libtransport/src/utils/daemonizator.cc (renamed from libtransport/src/hicn/transport/utils/daemonizator.cc)0
-rw-r--r--libtransport/src/utils/deadline_timer.h (renamed from libtransport/src/hicn/transport/utils/deadline_timer.h)2
-rw-r--r--libtransport/src/utils/epoll_event_reactor.cc (renamed from libtransport/src/hicn/transport/utils/epoll_event_reactor.cc)5
-rw-r--r--libtransport/src/utils/epoll_event_reactor.h (renamed from libtransport/src/hicn/transport/utils/epoll_event_reactor.h)2
-rw-r--r--libtransport/src/utils/event_reactor.h (renamed from libtransport/src/hicn/transport/utils/event_reactor.h)0
-rw-r--r--libtransport/src/utils/event_thread.h (renamed from libtransport/src/hicn/transport/utils/event_thread.h)0
-rw-r--r--libtransport/src/utils/fd_deadline_timer.h (renamed from libtransport/src/hicn/transport/utils/fd_deadline_timer.h)5
-rw-r--r--libtransport/src/utils/log.cc (renamed from libtransport/src/hicn/transport/utils/log.cc)0
-rw-r--r--libtransport/src/utils/membuf.cc (renamed from libtransport/src/hicn/transport/utils/membuf.cc)0
-rw-r--r--libtransport/src/utils/memory_pool_allocator.h152
-rw-r--r--libtransport/src/utils/min_filter.h (renamed from libtransport/src/hicn/transport/utils/min_filter.h)0
-rw-r--r--libtransport/src/utils/stream_buffer.h (renamed from libtransport/src/hicn/transport/utils/stream_buffer.h)0
-rw-r--r--libtransport/src/utils/string_tokenizer.cc (renamed from libtransport/src/hicn/transport/utils/string_tokenizer.cc)0
-rw-r--r--libtransport/src/utils/suffix_strategy.h (renamed from libtransport/src/hicn/transport/utils/suffix_strategy.h)3
-rw-r--r--libtransport/src/utils/test.h (renamed from libtransport/src/hicn/transport/utils/test.h)0
-rw-r--r--libtransport/src/utils/uri.cc (renamed from libtransport/src/hicn/transport/utils/uri.cc)0
-rw-r--r--utils/CMakeLists.txt3
-rw-r--r--utils/src/hiperf.cc18
-rw-r--r--utils/src/ping_client.cc10
-rw-r--r--utils/src/ping_server.cc26
218 files changed, 4469 insertions, 3909 deletions
diff --git a/apps/higet/higet.cc b/apps/higet/higet.cc
index fcb0cc540..2aa42e460 100644
--- a/apps/higet/higet.cc
+++ b/apps/higet/higet.cc
@@ -20,10 +20,11 @@
#include <experimental/algorithm>
#include <experimental/functional>
-#ifndef ASIO_STANDALONE
#define ASIO_STANDALONE
#include <asio.hpp>
-#endif
+#undef ASIO_STANDALONE
+
+#include <thread>
typedef std::chrono::time_point<std::chrono::system_clock> Time;
typedef std::chrono::milliseconds TimeDuration;
diff --git a/apps/http-proxy/src/IcnReceiver.cc b/apps/http-proxy/src/IcnReceiver.cc
index cc47e2ed4..24b0eb5dc 100644
--- a/apps/http-proxy/src/IcnReceiver.cc
+++ b/apps/http-proxy/src/IcnReceiver.cc
@@ -16,8 +16,10 @@
#include "IcnReceiver.h"
#include "HTTP1.xMessageFastParser.h"
+#include <hicn/transport/core/interest.h>
#include <hicn/transport/http/default_values.h>
#include <hicn/transport/utils/hash.h>
+#include <hicn/transport/utils/log.h>
#include <functional>
#include <memory>
diff --git a/libtransport/CMakeLists.txt b/libtransport/CMakeLists.txt
index 881e9810a..973dbaf35 100644
--- a/libtransport/CMakeLists.txt
+++ b/libtransport/CMakeLists.txt
@@ -42,7 +42,7 @@ endif ()
# Default: INFO
set(TRANSPORT_LOG_LEVEL "INFO" CACHE STRING "Set log level")
-set(TRANSPORT_ROOT_PATH "src/hicn/transport")
+set(TRANSPORT_ROOT_PATH "src")
set(TRANSPORT_CORE ${TRANSPORT_ROOT_PATH}/core)
set(TRANSPORT_TRANSPORT ${TRANSPORT_ROOT_PATH}/transport)
@@ -168,4 +168,5 @@ list(APPEND LIBTRANSPORT_INTERNAL_INCLUDE_DIRS
${OPENSSL_INCLUDE_DIR}
)
+add_subdirectory(includes/hicn/transport)
add_subdirectory(${TRANSPORT_ROOT_PATH})
diff --git a/libtransport/includes/hicn/transport/CMakeLists.txt b/libtransport/includes/hicn/transport/CMakeLists.txt
new file mode 100644
index 000000000..1099e701d
--- /dev/null
+++ b/libtransport/includes/hicn/transport/CMakeLists.txt
@@ -0,0 +1,38 @@
+# Copyright (c) 2017-2020 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+
+include(GNUInstallDirs)
+
+set(ASIO_STANDALONE 1)
+
+add_subdirectory(core)
+add_subdirectory(errors)
+add_subdirectory(http)
+add_subdirectory(interfaces)
+add_subdirectory(portability)
+add_subdirectory(security)
+add_subdirectory(utils)
+
+set(LIBTRANSPORT_INCLUDE_DIRS
+ ${CMAKE_CURRENT_SOURCE_DIR}/../.. ""
+ CACHE INTERNAL
+ "" FORCE
+)
+
+set(LIBHICNTRANSPORT_TO_INSTALL_HEADER_FILES
+ ${HEADER_FILES} ""
+ CACHE INTERNAL
+ "" FORCE
+) \ No newline at end of file
diff --git a/libtransport/includes/hicn/transport/core/CMakeLists.txt b/libtransport/includes/hicn/transport/core/CMakeLists.txt
new file mode 100644
index 000000000..cb10745ff
--- /dev/null
+++ b/libtransport/includes/hicn/transport/core/CMakeLists.txt
@@ -0,0 +1,25 @@
+# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+
+list(APPEND HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/content_object.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/interest.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/name.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/packet.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/payload_type.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/prefix.h
+)
+
+set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE) \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/core/content_object.h b/libtransport/includes/hicn/transport/core/content_object.h
index 5af548fe4..5af548fe4 100644
--- a/libtransport/src/hicn/transport/core/content_object.h
+++ b/libtransport/includes/hicn/transport/core/content_object.h
diff --git a/libtransport/src/hicn/transport/core/interest.h b/libtransport/includes/hicn/transport/core/interest.h
index 48c833a73..f0c546a8e 100644
--- a/libtransport/src/hicn/transport/core/interest.h
+++ b/libtransport/includes/hicn/transport/core/interest.h
@@ -17,7 +17,6 @@
#include <hicn/transport/core/name.h>
#include <hicn/transport/core/packet.h>
-#include <hicn/transport/utils/object_pool.h>
namespace transport {
diff --git a/libtransport/src/hicn/transport/core/name.h b/libtransport/includes/hicn/transport/core/name.h
index ea72797ad..ea72797ad 100644
--- a/libtransport/src/hicn/transport/core/name.h
+++ b/libtransport/includes/hicn/transport/core/name.h
diff --git a/libtransport/src/hicn/transport/core/packet.h b/libtransport/includes/hicn/transport/core/packet.h
index 35c8606c9..e80912cbe 100644
--- a/libtransport/src/hicn/transport/core/packet.h
+++ b/libtransport/includes/hicn/transport/core/packet.h
@@ -18,10 +18,10 @@
#include <hicn/transport/core/name.h>
#include <hicn/transport/core/payload_type.h>
#include <hicn/transport/portability/portability.h>
+#include <hicn/transport/security/crypto_hasher.h>
+#include <hicn/transport/security/crypto_suite.h>
+#include <hicn/transport/security/key_id.h>
#include <hicn/transport/utils/branch_prediction.h>
-#include <hicn/transport/utils/crypto_hasher.h>
-#include <hicn/transport/utils/crypto_suite.h>
-#include <hicn/transport/utils/key_id.h>
#include <hicn/transport/utils/membuf.h>
#include <hicn/transport/utils/object_pool.h>
diff --git a/libtransport/src/hicn/transport/core/payload_type.h b/libtransport/includes/hicn/transport/core/payload_type.h
index fa79db35a..fa79db35a 100644
--- a/libtransport/src/hicn/transport/core/payload_type.h
+++ b/libtransport/includes/hicn/transport/core/payload_type.h
diff --git a/libtransport/src/hicn/transport/core/prefix.h b/libtransport/includes/hicn/transport/core/prefix.h
index 47971acaf..c3805f13f 100644
--- a/libtransport/src/hicn/transport/core/prefix.h
+++ b/libtransport/includes/hicn/transport/core/prefix.h
@@ -16,6 +16,7 @@
#pragma once
#include <hicn/transport/core/name.h>
+
namespace transport {
namespace core {
diff --git a/libtransport/src/hicn/transport/errors/CMakeLists.txt b/libtransport/includes/hicn/transport/errors/CMakeLists.txt
index 7b0d1332d..5b04ace10 100644
--- a/libtransport/src/hicn/transport/errors/CMakeLists.txt
+++ b/libtransport/includes/hicn/transport/errors/CMakeLists.txt
@@ -27,5 +27,4 @@ list(APPEND HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/indexing_exception.h
)
-set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE) \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/errors/errors.h b/libtransport/includes/hicn/transport/errors/errors.h
index 512e35736..512e35736 100644
--- a/libtransport/src/hicn/transport/errors/errors.h
+++ b/libtransport/includes/hicn/transport/errors/errors.h
diff --git a/libtransport/src/hicn/transport/errors/indexing_exception.h b/libtransport/includes/hicn/transport/errors/indexing_exception.h
index 731314f0e..731314f0e 100644
--- a/libtransport/src/hicn/transport/errors/indexing_exception.h
+++ b/libtransport/includes/hicn/transport/errors/indexing_exception.h
diff --git a/libtransport/src/hicn/transport/errors/invalid_ip_address_exception.h b/libtransport/includes/hicn/transport/errors/invalid_ip_address_exception.h
index 60226f576..60226f576 100644
--- a/libtransport/src/hicn/transport/errors/invalid_ip_address_exception.h
+++ b/libtransport/includes/hicn/transport/errors/invalid_ip_address_exception.h
diff --git a/libtransport/src/hicn/transport/errors/malformed_ahpacket_exception.h b/libtransport/includes/hicn/transport/errors/malformed_ahpacket_exception.h
index f0cfe0b82..f0cfe0b82 100644
--- a/libtransport/src/hicn/transport/errors/malformed_ahpacket_exception.h
+++ b/libtransport/includes/hicn/transport/errors/malformed_ahpacket_exception.h
diff --git a/libtransport/src/hicn/transport/errors/malformed_name_exception.h b/libtransport/includes/hicn/transport/errors/malformed_name_exception.h
index 4ef45d2e8..4ef45d2e8 100644
--- a/libtransport/src/hicn/transport/errors/malformed_name_exception.h
+++ b/libtransport/includes/hicn/transport/errors/malformed_name_exception.h
diff --git a/libtransport/src/hicn/transport/errors/malformed_packet_exception.h b/libtransport/includes/hicn/transport/errors/malformed_packet_exception.h
index ec5c97e6e..ec5c97e6e 100644
--- a/libtransport/src/hicn/transport/errors/malformed_packet_exception.h
+++ b/libtransport/includes/hicn/transport/errors/malformed_packet_exception.h
diff --git a/libtransport/src/hicn/transport/errors/not_implemented_exception.h b/libtransport/includes/hicn/transport/errors/not_implemented_exception.h
index e9869163d..e9869163d 100644
--- a/libtransport/src/hicn/transport/errors/not_implemented_exception.h
+++ b/libtransport/includes/hicn/transport/errors/not_implemented_exception.h
diff --git a/libtransport/src/hicn/transport/errors/null_pointer_exception.h b/libtransport/includes/hicn/transport/errors/null_pointer_exception.h
index bd06485ed..bd06485ed 100644
--- a/libtransport/src/hicn/transport/errors/null_pointer_exception.h
+++ b/libtransport/includes/hicn/transport/errors/null_pointer_exception.h
diff --git a/libtransport/src/hicn/transport/errors/runtime_exception.h b/libtransport/includes/hicn/transport/errors/runtime_exception.h
index ba5128a7e..ba5128a7e 100644
--- a/libtransport/src/hicn/transport/errors/runtime_exception.h
+++ b/libtransport/includes/hicn/transport/errors/runtime_exception.h
diff --git a/libtransport/src/hicn/transport/errors/tokenizer_exception.h b/libtransport/includes/hicn/transport/errors/tokenizer_exception.h
index 76eda838e..76eda838e 100644
--- a/libtransport/src/hicn/transport/errors/tokenizer_exception.h
+++ b/libtransport/includes/hicn/transport/errors/tokenizer_exception.h
diff --git a/libtransport/src/hicn/transport/errors/unexpected_manifest_exception.h b/libtransport/includes/hicn/transport/errors/unexpected_manifest_exception.h
index 6f71471e4..6f71471e4 100644
--- a/libtransport/src/hicn/transport/errors/unexpected_manifest_exception.h
+++ b/libtransport/includes/hicn/transport/errors/unexpected_manifest_exception.h
diff --git a/libtransport/src/hicn/transport/http/CMakeLists.txt b/libtransport/includes/hicn/transport/http/CMakeLists.txt
index b24c80195..9cf618c21 100644
--- a/libtransport/src/hicn/transport/http/CMakeLists.txt
+++ b/libtransport/includes/hicn/transport/http/CMakeLists.txt
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Copyright (c) 2017-2020 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
@@ -13,23 +13,13 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
-list(APPEND SOURCE_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/client_connection.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/request.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/server_publisher.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/server_acceptor.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/response.cc)
-
list(APPEND HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/client_connection.h
${CMAKE_CURRENT_SOURCE_DIR}/request.h
- ${CMAKE_CURRENT_SOURCE_DIR}/server_publisher.h
- ${CMAKE_CURRENT_SOURCE_DIR}/server_acceptor.h
${CMAKE_CURRENT_SOURCE_DIR}/default_values.h
${CMAKE_CURRENT_SOURCE_DIR}/facade.h
${CMAKE_CURRENT_SOURCE_DIR}/response.h
${CMAKE_CURRENT_SOURCE_DIR}/message.h
)
-set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE) \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/http/client_connection.h b/libtransport/includes/hicn/transport/http/client_connection.h
index e93a37111..262756a09 100644
--- a/libtransport/src/hicn/transport/http/client_connection.h
+++ b/libtransport/includes/hicn/transport/http/client_connection.h
@@ -31,7 +31,7 @@ namespace http {
using namespace interface;
using namespace core;
-class HTTPClientConnection : public ConsumerSocket::ReadCallback {
+class HTTPClientConnection {
static constexpr uint32_t max_buffer_capacity = 64 * 1024;
public:
@@ -46,6 +46,8 @@ class HTTPClientConnection : public ConsumerSocket::ReadCallback {
HTTPClientConnection();
+ ~HTTPClientConnection();
+
RC get(const std::string &url, HTTPHeaders headers = {},
HTTPPayload &&payload = nullptr,
std::shared_ptr<HTTPResponse> response = nullptr,
@@ -69,51 +71,8 @@ class HTTPClientConnection : public ConsumerSocket::ReadCallback {
HTTPClientConnection &setCertificate(const std::string &cert_path);
private:
- void sendRequestGetReply(std::string &ipv6_first_word);
-
- bool verifyData(interface::ConsumerSocket &c,
- const core::ContentObject &contentObject);
-
- void processLeavingInterest(interface::ConsumerSocket &c,
- const core::Interest &interest);
-
- // Read callback
- bool isBufferMovable() noexcept override { return true; }
- void getReadBuffer(uint8_t **application_buffer,
- size_t *max_length) override {}
- void readDataAvailable(size_t length) noexcept override {}
- size_t maxBufferSize() const override { return max_buffer_capacity; }
- void readBufferAvailable(
- std::unique_ptr<utils::MemBuf> &&buffer) noexcept override;
- void readError(const std::error_code ec) noexcept override;
- void readSuccess(std::size_t total_size) noexcept override;
-
- // The consumer socket
- ConsumerSocket consumer_;
-
- // The current url provided by the application
- std::string current_url_;
- // The current hICN name used for downloading
- std::stringstream name_;
- // Function to be called when the read is successful
- std::function<void(std::size_t)> success_callback_;
- // Return code for current download
- RC return_code_;
-
- // Application provided callback for saving the received content during
- // the download. If this callback is used, the HTTPClient will NOT save
- // any byte internally.
- ReadBytesCallback *read_bytes_callback_;
-
- HTTPRequest request_;
-
- // Internal read buffer and HTTP response, to be used if the application does
- // not provide any read_bytes_callback
- std::unique_ptr<utils::MemBuf> read_buffer_;
- std::shared_ptr<HTTPResponse> response_;
-
- // Timer
- std::unique_ptr<asio::steady_timer> timer_;
+ class Implementation;
+ Implementation *implementation_;
};
} // end namespace http
diff --git a/libtransport/src/hicn/transport/http/default_values.h b/libtransport/includes/hicn/transport/http/default_values.h
index 2d5a6b821..2d5a6b821 100644
--- a/libtransport/src/hicn/transport/http/default_values.h
+++ b/libtransport/includes/hicn/transport/http/default_values.h
diff --git a/libtransport/src/hicn/transport/http/facade.h b/libtransport/includes/hicn/transport/http/facade.h
index 1551ede3a..8a465ce94 100644
--- a/libtransport/src/hicn/transport/http/facade.h
+++ b/libtransport/includes/hicn/transport/http/facade.h
@@ -16,7 +16,5 @@
#pragma once
#include <hicn/transport/http/client_connection.h>
-#include <hicn/transport/http/server_acceptor.h>
-#include <hicn/transport/http/server_publisher.h>
namespace libl4 = transport; \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/http/message.h b/libtransport/includes/hicn/transport/http/message.h
index b8756224f..b8756224f 100644
--- a/libtransport/src/hicn/transport/http/message.h
+++ b/libtransport/includes/hicn/transport/http/message.h
diff --git a/libtransport/src/hicn/transport/http/request.h b/libtransport/includes/hicn/transport/http/request.h
index 54904d696..54904d696 100644
--- a/libtransport/src/hicn/transport/http/request.h
+++ b/libtransport/includes/hicn/transport/http/request.h
diff --git a/libtransport/src/hicn/transport/http/response.h b/libtransport/includes/hicn/transport/http/response.h
index bab41acb8..bab41acb8 100644
--- a/libtransport/src/hicn/transport/http/response.h
+++ b/libtransport/includes/hicn/transport/http/response.h
diff --git a/libtransport/includes/hicn/transport/interfaces/CMakeLists.txt b/libtransport/includes/hicn/transport/interfaces/CMakeLists.txt
new file mode 100644
index 000000000..38e6143f0
--- /dev/null
+++ b/libtransport/includes/hicn/transport/interfaces/CMakeLists.txt
@@ -0,0 +1,35 @@
+# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+
+list(APPEND HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/socket_consumer.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/socket_producer.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/rtc_socket_producer.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/publication_options.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/socket_options_default_values.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/socket_options_keys.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/callbacks.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/verification_policy.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/statistics.h
+)
+
+if (${OPENSSL_VERSION} VERSION_EQUAL "1.1.1a" OR ${OPENSSL_VERSION} VERSION_GREATER "1.1.1a")
+ list(APPEND HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/p2psecure_socket_producer.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/p2psecure_socket_consumer.h
+ )
+endif()
+
+set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE)
diff --git a/libtransport/src/hicn/transport/interfaces/callbacks.h b/libtransport/includes/hicn/transport/interfaces/callbacks.h
index 9d3d57992..6ae07797e 100644
--- a/libtransport/src/hicn/transport/interfaces/callbacks.h
+++ b/libtransport/includes/hicn/transport/interfaces/callbacks.h
@@ -15,7 +15,7 @@
#pragma once
-#include <hicn/transport/core/facade.h>
+#include <hicn/transport/interfaces/statistics.h>
#include <hicn/transport/interfaces/verification_policy.h>
#include <functional>
@@ -30,12 +30,10 @@ namespace transport {
namespace protocol {
class IcnObserver;
-class TransportStatistics;
} // namespace protocol
namespace core {
-
class ContentObject;
class Interest;
} // namespace core
@@ -58,8 +56,8 @@ using ConsumerInterestCallback =
* The ConsumerTimerCallback is called periodically for exposing to applications
* a summary of the statistics of the transport protocol in use.
*/
-using ConsumerTimerCallback = std::function<void(
- ConsumerSocket &, const protocol::TransportStatistics &stats)>;
+using ConsumerTimerCallback =
+ std::function<void(ConsumerSocket &, const TransportStatistics &stats)>;
/**
* The ProducerContentCallback will be called by the producer socket right after
@@ -96,13 +94,6 @@ using ConsumerContentObjectVerificationFailedCallback =
ConsumerSocket &, const core::ContentObject &, std::error_code ec)>;
/**
- * The ConsumerManifestCallback will be called by the consumer socket when a
- * manifest is received.
- */
-using ConsumerManifestCallback =
- std::function<void(ConsumerSocket &, const core::ContentObjectManifest &)>;
-
-/**
* The ProducerContentObjectCallback will be called in different parts of the
* consumer socket processing pipeline, with a ProducerSocket and an
* ContentObject as parameters.
diff --git a/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_consumer.h b/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_consumer.h
new file mode 100644
index 000000000..097b0a8c0
--- /dev/null
+++ b/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_consumer.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <hicn/transport/interfaces/socket_consumer.h>
+
+namespace transport {
+
+namespace interface {
+
+class P2PSecureConsumerSocket : public ConsumerSocket {
+ public:
+ P2PSecureConsumerSocket(int handshake_protocol, int protocol);
+ ~P2PSecureConsumerSocket() = default;
+};
+
+} // namespace interface
+
+} // end namespace transport
diff --git a/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_producer.h b/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_producer.h
new file mode 100644
index 000000000..6f0d48bb9
--- /dev/null
+++ b/libtransport/includes/hicn/transport/interfaces/p2psecure_socket_producer.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <hicn/transport/interfaces/socket_producer.h>
+
+#include <hicn/transport/security/identity.h>
+
+namespace transport {
+
+namespace interface {
+
+class P2PSecureProducerSocket : public ProducerSocket {
+ public:
+ P2PSecureProducerSocket();
+ P2PSecureProducerSocket(bool rtc,
+ const std::shared_ptr<utils::Identity> &identity);
+ ~P2PSecureProducerSocket() = default;
+};
+
+} // namespace interface
+
+} // end namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/publication_options.h b/libtransport/includes/hicn/transport/interfaces/publication_options.h
index 6910e5371..6910e5371 100644
--- a/libtransport/src/hicn/transport/interfaces/publication_options.h
+++ b/libtransport/includes/hicn/transport/interfaces/publication_options.h
diff --git a/libtransport/src/hicn/transport/protocols/download_observer.h b/libtransport/includes/hicn/transport/interfaces/rtc_socket_producer.h
index 6d24fe6fd..218240f83 100644
--- a/libtransport/src/hicn/transport/protocols/download_observer.h
+++ b/libtransport/includes/hicn/transport/interfaces/rtc_socket_producer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2020 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -15,18 +15,18 @@
#pragma once
+#include <hicn/transport/interfaces/socket_producer.h>
+
namespace transport {
-namespace protocol {
+namespace interface {
-class IcnObserver {
+class RTCProducerSocket : public ProducerSocket {
public:
- virtual ~IcnObserver(){};
-
- virtual void notifyStats(double throughput) = 0;
- virtual void notifyDownloadTime(double downloadTime) = 0;
+ RTCProducerSocket();
+ ~RTCProducerSocket() = default;
};
-} // end namespace protocol
+} // namespace interface
} // end namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/socket_consumer.h b/libtransport/includes/hicn/transport/interfaces/socket_consumer.h
index 48a594adf..e9e671edd 100644
--- a/libtransport/src/hicn/transport/interfaces/socket_consumer.h
+++ b/libtransport/includes/hicn/transport/interfaces/socket_consumer.h
@@ -15,16 +15,15 @@
#pragma once
-#include <hicn/transport/interfaces/socket.h>
+#include <hicn/transport/config.h>
+#include <hicn/transport/core/name.h>
+#include <hicn/transport/core/prefix.h>
+#include <hicn/transport/interfaces/callbacks.h>
#include <hicn/transport/interfaces/socket_options_default_values.h>
-#include <hicn/transport/protocols/protocol.h>
-#include <hicn/transport/protocols/statistics.h>
-#include <hicn/transport/utils/event_thread.h>
-#include <hicn/transport/utils/verifier.h>
+#include <hicn/transport/interfaces/socket_options_keys.h>
+#include <hicn/transport/security/verifier.h>
-extern "C" {
-#include <parc/security/parc_KeyId.h>
-}
+#include <asio/io_service.hpp>
#define CONSUMER_FINISHED 0
#define CONSUMER_BUSY 1
@@ -32,10 +31,13 @@ extern "C" {
namespace transport {
+namespace implementation {
+class ConsumerSocket;
+}
+
namespace interface {
using namespace core;
-using namespace protocol;
/**
* @brief Main interface for consumer applications.
@@ -44,7 +46,7 @@ using namespace protocol;
* It allows to retrieve an application data from one/many producers, by
* hiding all the complexity of the transport protocol used underneath.
*/
-class ConsumerSocket : public BaseSocket {
+class ConsumerSocket {
public:
/**
* The ReadCallback is a class which can be used by the transport for both
@@ -132,8 +134,6 @@ class ConsumerSocket : public BaseSocket {
* the application when the transfer is done.
*/
virtual void readSuccess(std::size_t total_size) noexcept = 0;
-
- virtual void afterRead() {}
};
/**
@@ -149,7 +149,6 @@ class ConsumerSocket : public BaseSocket {
* - RTC: Real time communication
*/
explicit ConsumerSocket(int protocol);
- explicit ConsumerSocket(int protocol, asio::io_service &io_service);
/**
* @brief Destroy the consumer socket.
@@ -159,12 +158,12 @@ class ConsumerSocket : public BaseSocket {
/**
* @brief Connect the consumer socket to the underlying hICN forwarder.
*/
- void connect() override;
+ void connect();
/**
* @brief Check whether consumer socket is active or not.
*/
- bool isRunning() override { return transport_protocol_->isRunning(); }
+ bool isRunning();
/**
* Retrieve a content using the protocol specified in the constructor.
@@ -183,8 +182,8 @@ class ConsumerSocket : public BaseSocket {
* content retrieval succeeded. This information can be obtained from the
* error code in CONTENT_RETRIEVED callback.
*/
- virtual int consume(const Name &name);
- virtual int asyncConsume(const Name &name);
+ int consume(const Name &name);
+ int asyncConsume(const Name &name);
/**
* Verify the packets containing a key after the origin of the key has been
@@ -192,7 +191,7 @@ class ConsumerSocket : public BaseSocket {
*
* @return true if all packets are valid, false otherwise
*/
- virtual bool verifyKeyPackets();
+ bool verifyKeyPackets();
/**
* Stops the consumer socket. If several downloads are queued (using
@@ -211,200 +210,87 @@ class ConsumerSocket : public BaseSocket {
* @return A reference to the internal io_service where the transport protocol
* is running.
*/
- asio::io_service &getIoService() override;
+ asio::io_service &getIoService();
- virtual int setSocketOption(int socket_option_key,
- ReadCallback *socket_option_value);
+ int setSocketOption(int socket_option_key, ReadCallback *socket_option_value);
- virtual int getSocketOption(int socket_option_key,
- ReadCallback **socket_option_value);
+ int getSocketOption(int socket_option_key,
+ ReadCallback **socket_option_value);
- virtual int setSocketOption(int socket_option_key,
- double socket_option_value);
+ int setSocketOption(int socket_option_key, double socket_option_value);
- virtual int setSocketOption(int socket_option_key,
- uint32_t socket_option_value);
+ int setSocketOption(int socket_option_key, uint32_t socket_option_value);
- virtual int setSocketOption(int socket_option_key,
- std::nullptr_t socket_option_value);
+ int setSocketOption(int socket_option_key,
+ std::nullptr_t socket_option_value);
- virtual int setSocketOption(int socket_option_key, bool socket_option_value);
+ int setSocketOption(int socket_option_key, bool socket_option_value);
- virtual int setSocketOption(
- int socket_option_key, ConsumerContentObjectCallback socket_option_value);
+ int setSocketOption(int socket_option_key,
+ ConsumerContentObjectCallback socket_option_value);
- virtual int setSocketOption(
+ int setSocketOption(
int socket_option_key,
ConsumerContentObjectVerificationFailedCallback socket_option_value);
- virtual int setSocketOption(
+ int setSocketOption(
int socket_option_key,
ConsumerContentObjectVerificationCallback socket_option_value);
- virtual int setSocketOption(int socket_option_key,
- ConsumerInterestCallback socket_option_value);
-
- virtual int setSocketOption(int socket_option_key,
- ConsumerManifestCallback socket_option_value);
+ int setSocketOption(int socket_option_key,
+ ConsumerInterestCallback socket_option_value);
- virtual int setSocketOption(int socket_option_key,
- IcnObserver *socket_option_value);
+ int setSocketOption(int socket_option_key,
+ interface::IcnObserver *socket_option_value);
- virtual int setSocketOption(
+ int setSocketOption(
int socket_option_key,
const std::shared_ptr<utils::Verifier> &socket_option_value);
- virtual int setSocketOption(int socket_option_key,
- const std::string &socket_option_value);
+ int setSocketOption(int socket_option_key,
+ const std::string &socket_option_value);
- virtual int setSocketOption(int socket_option_key,
- ConsumerTimerCallback socket_option_value);
+ int setSocketOption(int socket_option_key,
+ ConsumerTimerCallback socket_option_value);
- virtual int getSocketOption(int socket_option_key,
- double &socket_option_value);
+ int getSocketOption(int socket_option_key, double &socket_option_value);
- virtual int getSocketOption(int socket_option_key,
- uint32_t &socket_option_value);
+ int getSocketOption(int socket_option_key, uint32_t &socket_option_value);
- virtual int getSocketOption(int socket_option_key, bool &socket_option_value);
+ int getSocketOption(int socket_option_key, bool &socket_option_value);
- virtual int getSocketOption(int socket_option_key,
- Name **socket_option_value);
+ int getSocketOption(int socket_option_key, Name **socket_option_value);
- virtual int getSocketOption(
- int socket_option_key,
- ConsumerContentObjectCallback **socket_option_value);
+ int getSocketOption(int socket_option_key,
+ ConsumerContentObjectCallback **socket_option_value);
- virtual int getSocketOption(
+ int getSocketOption(
int socket_option_key,
ConsumerContentObjectVerificationFailedCallback **socket_option_value);
- virtual int getSocketOption(
+ int getSocketOption(
int socket_option_key,
ConsumerContentObjectVerificationCallback **socket_option_value);
- virtual int getSocketOption(int socket_option_key,
- ConsumerInterestCallback **socket_option_value);
-
- virtual int getSocketOption(int socket_option_key,
- ConsumerManifestCallback **socket_option_value);
+ int getSocketOption(int socket_option_key,
+ ConsumerInterestCallback **socket_option_value);
- virtual int getSocketOption(int socket_option_key,
- std::shared_ptr<Portal> &socket_option_value);
+ int getSocketOption(int socket_option_key, IcnObserver **socket_option_value);
- virtual int getSocketOption(int socket_option_key,
- IcnObserver **socket_option_value);
-
- virtual int getSocketOption(
- int socket_option_key,
- std::shared_ptr<utils::Verifier> &socket_option_value);
+ int getSocketOption(int socket_option_key,
+ std::shared_ptr<utils::Verifier> &socket_option_value);
- virtual int getSocketOption(int socket_option_key,
- std::string &socket_option_value);
+ int getSocketOption(int socket_option_key, std::string &socket_option_value);
- virtual int getSocketOption(int socket_option_key,
- ConsumerTimerCallback **socket_option_value);
+ int getSocketOption(int socket_option_key,
+ ConsumerTimerCallback **socket_option_value);
- virtual int getSocketOption(int socket_option_key,
- TransportStatistics **socket_option_value);
+ int getSocketOption(int socket_option_key,
+ interface::TransportStatistics **socket_option_value);
protected:
- // If the thread calling lambda_func is not the same of io_service, this
- // function reschedule the function on it
- template <typename Lambda, typename arg2>
- int rescheduleOnIOService(int socket_option_key, arg2 socket_option_value,
- Lambda lambda_func) {
- // To enforce type check
- std::function<int(int, arg2)> func = lambda_func;
- int result = SOCKET_OPTION_SET;
- if (transport_protocol_->isRunning()) {
- std::mutex mtx;
- /* Condition variable for the wait */
- std::condition_variable cv;
- bool done = false;
- io_service_.dispatch([&socket_option_key, &socket_option_value, &mtx, &cv,
- &result, &done, &func]() {
- std::unique_lock<std::mutex> lck(mtx);
- done = true;
- result = func(socket_option_key, socket_option_value);
- cv.notify_all();
- });
- std::unique_lock<std::mutex> lck(mtx);
- if (!done) {
- cv.wait(lck);
- }
- } else {
- result = func(socket_option_key, socket_option_value);
- }
-
- return result;
- }
-
- // context inner state variables
- asio::io_service internal_io_service_;
- asio::io_service &io_service_;
-
- std::shared_ptr<Portal> portal_;
-
- utils::EventThread async_downloader_;
-
- Name network_name_;
-
- int interest_lifetime_;
-
- double min_window_size_;
- double max_window_size_;
- double current_window_size_;
- uint32_t max_retransmissions_;
-
- // RAAQM Parameters
- double minimum_drop_probability_;
- unsigned int sample_number_;
- double gamma_;
- double beta_;
- double drop_factor_;
-
- // Rate estimation parameters
- double rate_estimation_alpha_;
- IcnObserver *rate_estimation_observer_;
- int rate_estimation_batching_parameter_;
- int rate_estimation_choice_;
-
- bool is_async_;
-
- // Verification parameters
- std::shared_ptr<utils::Verifier> verifier_;
- PARCKeyId *key_id_;
- std::atomic_bool verify_signature_;
- std::atomic_bool key_content_;
-
- ConsumerInterestCallback on_interest_retransmission_;
- ConsumerInterestCallback on_interest_output_;
- ConsumerInterestCallback on_interest_timeout_;
- ConsumerInterestCallback on_interest_satisfied_;
-
- ConsumerContentObjectCallback on_content_object_input_;
- ConsumerContentObjectVerificationCallback on_content_object_verification_;
-
- ConsumerContentObjectCallback on_content_object_;
- ConsumerManifestCallback on_manifest_;
- ConsumerTimerCallback stats_summary_;
- ConsumerContentObjectVerificationFailedCallback verification_failed_callback_;
-
- ReadCallback *read_callback_;
-
- // Virtual download for traffic generator
- bool virtual_download_;
-
- uint32_t timer_interval_milliseconds_;
-
- // Transport protocol
- std::unique_ptr<TransportProtocol> transport_protocol_;
-
- // Statistic
- TransportStatistics stats_;
-
- utils::SpinLock guard_raaqm_params_;
+ ConsumerSocket();
+ std::unique_ptr<implementation::ConsumerSocket> socket_;
};
} // namespace interface
diff --git a/libtransport/src/hicn/transport/interfaces/socket_options_default_values.h b/libtransport/includes/hicn/transport/interfaces/socket_options_default_values.h
index bcf103b8c..bcf103b8c 100644
--- a/libtransport/src/hicn/transport/interfaces/socket_options_default_values.h
+++ b/libtransport/includes/hicn/transport/interfaces/socket_options_default_values.h
diff --git a/libtransport/src/hicn/transport/interfaces/socket_options_keys.h b/libtransport/includes/hicn/transport/interfaces/socket_options_keys.h
index a38131271..7910a4422 100644
--- a/libtransport/src/hicn/transport/interfaces/socket_options_keys.h
+++ b/libtransport/includes/hicn/transport/interfaces/socket_options_keys.h
@@ -15,6 +15,12 @@
#pragma once
+#define SOCKET_OPTION_GET 0
+#define SOCKET_OPTION_NOT_GET 1
+#define SOCKET_OPTION_SET 2
+#define SOCKET_OPTION_NOT_SET 3
+#define SOCKET_OPTION_DEFAULT 12345
+
namespace transport {
namespace interface {
@@ -75,7 +81,6 @@ typedef enum {
INTEREST_EXPIRED = 403,
INTEREST_SATISFIED = 404,
CONTENT_OBJECT_INPUT = 411,
- MANIFEST_INPUT = 412,
CONTENT_OBJECT_TO_VERIFY = 413,
VERIFICATION_FAILED = 414,
READ_CALLBACK = 415,
diff --git a/libtransport/includes/hicn/transport/interfaces/socket_producer.h b/libtransport/includes/hicn/transport/interfaces/socket_producer.h
new file mode 100644
index 000000000..3fe99fbd4
--- /dev/null
+++ b/libtransport/includes/hicn/transport/interfaces/socket_producer.h
@@ -0,0 +1,149 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <hicn/transport/config.h>
+#include <hicn/transport/core/name.h>
+#include <hicn/transport/core/prefix.h>
+#include <hicn/transport/interfaces/callbacks.h>
+#include <hicn/transport/interfaces/socket_options_default_values.h>
+#include <hicn/transport/interfaces/socket_options_keys.h>
+#include <hicn/transport/security/signer.h>
+
+#include <asio/io_service.hpp>
+
+namespace transport {
+
+namespace implementation {
+class ProducerSocket;
+}
+
+namespace interface {
+
+using namespace core;
+
+class ProducerSocket {
+ public:
+ explicit ProducerSocket(int protocol = 0);
+
+ virtual ~ProducerSocket();
+
+ void connect();
+
+ bool isRunning();
+
+ uint32_t produce(Name content_name, const uint8_t *buffer, size_t buffer_size,
+ bool is_last = true, uint32_t start_offset = 0) {
+ return produce(content_name, utils::MemBuf::copyBuffer(buffer, buffer_size),
+ is_last, start_offset);
+ }
+
+ uint32_t produce(Name content_name, std::unique_ptr<utils::MemBuf> &&buffer,
+ bool is_last = true, uint32_t start_offset = 0);
+
+ void produce(ContentObject &content_object);
+
+ void produce(const uint8_t *buffer, size_t buffer_size) {
+ produce(utils::MemBuf::copyBuffer(buffer, buffer_size));
+ }
+
+ void produce(std::unique_ptr<utils::MemBuf> &&buffer);
+
+ void asyncProduce(const Name &suffix, const uint8_t *buf, size_t buffer_size,
+ bool is_last = true, uint32_t *start_offset = nullptr);
+
+ void asyncProduce(Name content_name, std::unique_ptr<utils::MemBuf> &&buffer,
+ bool is_last, uint32_t offset,
+ uint32_t **last_segment = nullptr);
+
+ void asyncProduce(ContentObject &content_object);
+
+ void registerPrefix(const Prefix &producer_namespace);
+
+ void serveForever();
+
+ void stop();
+
+ asio::io_service &getIoService();
+
+ int setSocketOption(int socket_option_key, uint32_t socket_option_value);
+
+ int setSocketOption(int socket_option_key,
+ std::nullptr_t socket_option_value);
+
+ int setSocketOption(int socket_option_key, bool socket_option_value);
+
+ int setSocketOption(int socket_option_key, Name *socket_option_value);
+
+ int setSocketOption(int socket_option_key,
+ std::list<Prefix> socket_option_value);
+
+ int setSocketOption(int socket_option_key,
+ ProducerContentObjectCallback socket_option_value);
+
+ int setSocketOption(int socket_option_key,
+ ProducerInterestCallback socket_option_value);
+
+ int setSocketOption(int socket_option_key,
+ ProducerContentCallback socket_option_value);
+
+ int setSocketOption(int socket_option_key, HashAlgorithm socket_option_value);
+
+ int setSocketOption(int socket_option_key,
+ utils::CryptoSuite socket_option_value);
+
+ int setSocketOption(
+ int socket_option_key,
+ const std::shared_ptr<utils::Signer> &socket_option_value);
+
+ int setSocketOption(int socket_option_key,
+ const std::string &socket_option_value);
+
+ int getSocketOption(int socket_option_key, uint32_t &socket_option_value);
+
+ int getSocketOption(int socket_option_key, bool &socket_option_value);
+
+ int getSocketOption(int socket_option_key,
+ std::list<Prefix> &socket_option_value);
+
+ int getSocketOption(int socket_option_key,
+ ProducerContentObjectCallback **socket_option_value);
+
+ int getSocketOption(int socket_option_key,
+ ProducerContentCallback **socket_option_value);
+
+ int getSocketOption(int socket_option_key,
+ ProducerInterestCallback **socket_option_value);
+
+ int getSocketOption(int socket_option_key,
+ HashAlgorithm &socket_option_value);
+
+ int getSocketOption(int socket_option_key,
+ utils::CryptoSuite &socket_option_value);
+
+ int getSocketOption(int socket_option_key,
+ std::shared_ptr<utils::Signer> &socket_option_value);
+
+ int getSocketOption(int socket_option_key, std::string &socket_option_value);
+
+ protected:
+ ProducerSocket(bool);
+ std::unique_ptr<implementation::ProducerSocket> socket_;
+};
+
+} // namespace interface
+
+} // namespace transport
diff --git a/libtransport/src/hicn/transport/protocols/statistics.h b/libtransport/includes/hicn/transport/interfaces/statistics.h
index c92940ab4..26831fbf1 100644
--- a/libtransport/src/hicn/transport/protocols/statistics.h
+++ b/libtransport/includes/hicn/transport/interfaces/statistics.h
@@ -21,7 +21,15 @@
namespace transport {
-namespace protocol {
+namespace interface {
+
+class IcnObserver {
+ public:
+ virtual ~IcnObserver(){};
+
+ virtual void notifyStats(double throughput) = 0;
+ virtual void notifyDownloadTime(double downloadTime) = 0;
+};
class TransportStatistics {
static constexpr double default_alpha = 0.7;
@@ -108,6 +116,6 @@ class TransportStatistics {
double queuing_delay_;
};
-} // end namespace protocol
+} // namespace interface
} // end namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/verification_policy.h b/libtransport/includes/hicn/transport/interfaces/verification_policy.h
index cb5140ac1..cb5140ac1 100644
--- a/libtransport/src/hicn/transport/interfaces/verification_policy.h
+++ b/libtransport/includes/hicn/transport/interfaces/verification_policy.h
diff --git a/libtransport/src/hicn/transport/portability/CMakeLists.txt b/libtransport/includes/hicn/transport/portability/CMakeLists.txt
index 5ad3c8207..469b11192 100644
--- a/libtransport/src/hicn/transport/portability/CMakeLists.txt
+++ b/libtransport/includes/hicn/transport/portability/CMakeLists.txt
@@ -28,5 +28,4 @@ if(WIN32)
)
endif()
-set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE) \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/portability/c_portability.h b/libtransport/includes/hicn/transport/portability/c_portability.h
index 71e976a81..71e976a81 100644
--- a/libtransport/src/hicn/transport/portability/c_portability.h
+++ b/libtransport/includes/hicn/transport/portability/c_portability.h
diff --git a/libtransport/src/hicn/transport/portability/portability.h b/libtransport/includes/hicn/transport/portability/portability.h
index 1d97a346e..1d97a346e 100644
--- a/libtransport/src/hicn/transport/portability/portability.h
+++ b/libtransport/includes/hicn/transport/portability/portability.h
diff --git a/libtransport/src/hicn/transport/portability/win_portability.h b/libtransport/includes/hicn/transport/portability/win_portability.h
index 65d949291..65d949291 100644
--- a/libtransport/src/hicn/transport/portability/win_portability.h
+++ b/libtransport/includes/hicn/transport/portability/win_portability.h
diff --git a/libtransport/includes/hicn/transport/security/CMakeLists.txt b/libtransport/includes/hicn/transport/security/CMakeLists.txt
new file mode 100644
index 000000000..58a96780b
--- /dev/null
+++ b/libtransport/includes/hicn/transport/security/CMakeLists.txt
@@ -0,0 +1,27 @@
+# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+
+list(APPEND HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/signer.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/verifier.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/crypto_hasher.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/crypto_suite.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/crypto_hash.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/crypto_hash_type.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/identity.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/key_id.h
+)
+
+set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE) \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/utils/crypto_hash.h b/libtransport/includes/hicn/transport/security/crypto_hash.h
index 945909d14..5a58f258b 100644
--- a/libtransport/src/hicn/transport/utils/crypto_hash.h
+++ b/libtransport/includes/hicn/transport/security/crypto_hash.h
@@ -17,8 +17,8 @@
#include <hicn/transport/errors/runtime_exception.h>
#include <hicn/transport/portability/portability.h>
+#include <hicn/transport/security/crypto_hash_type.h>
#include <hicn/transport/utils/array.h>
-#include <hicn/transport/utils/crypto_hash_type.h>
extern "C" {
#include <parc/security/parc_CryptoHash.h>
diff --git a/libtransport/src/hicn/transport/utils/crypto_hash_type.h b/libtransport/includes/hicn/transport/security/crypto_hash_type.h
index b7597e208..b7597e208 100644
--- a/libtransport/src/hicn/transport/utils/crypto_hash_type.h
+++ b/libtransport/includes/hicn/transport/security/crypto_hash_type.h
diff --git a/libtransport/src/hicn/transport/utils/crypto_hasher.h b/libtransport/includes/hicn/transport/security/crypto_hasher.h
index c34a26fac..9367c3bc8 100644
--- a/libtransport/src/hicn/transport/utils/crypto_hasher.h
+++ b/libtransport/includes/hicn/transport/security/crypto_hasher.h
@@ -15,7 +15,7 @@
#pragma once
-#include <hicn/transport/utils/crypto_hash.h>
+#include <hicn/transport/security/crypto_hash.h>
extern "C" {
#include <parc/security/parc_CryptoHasher.h>
diff --git a/libtransport/src/hicn/transport/utils/crypto_suite.h b/libtransport/includes/hicn/transport/security/crypto_suite.h
index 8ae32b846..017938f8f 100644
--- a/libtransport/src/hicn/transport/utils/crypto_suite.h
+++ b/libtransport/includes/hicn/transport/security/crypto_suite.h
@@ -19,6 +19,8 @@ extern "C" {
#include <parc/security/parc_CryptoSuite.h>
};
+#include <cstdint>
+
namespace utils {
enum class CryptoSuite : uint8_t {
@@ -31,5 +33,4 @@ enum class CryptoSuite : uint8_t {
ECDSA_256K1 = PARCCryptoSuite_ECDSA_SHA256,
UNKNOWN = PARCCryptoSuite_UNKNOWN
};
-
}
diff --git a/libtransport/src/hicn/transport/utils/identity.h b/libtransport/includes/hicn/transport/security/identity.h
index e9801a005..c5d4b975d 100644
--- a/libtransport/src/hicn/transport/utils/identity.h
+++ b/libtransport/includes/hicn/transport/security/identity.h
@@ -15,9 +15,10 @@
#pragma once
-#include <hicn/transport/core/manifest_format.h>
-#include <hicn/transport/utils/crypto_suite.h>
-#include <hicn/transport/utils/signer.h>
+#include <hicn/transport/security/crypto_suite.h>
+#include <hicn/transport/security/signer.h>
+
+#include <core/manifest_format.h>
extern "C" {
#include <parc/security/parc_Identity.h>
diff --git a/libtransport/src/hicn/transport/utils/key_id.h b/libtransport/includes/hicn/transport/security/key_id.h
index d67b73d7a..d67b73d7a 100644
--- a/libtransport/src/hicn/transport/utils/key_id.h
+++ b/libtransport/includes/hicn/transport/security/key_id.h
diff --git a/libtransport/src/hicn/transport/utils/signer.h b/libtransport/includes/hicn/transport/security/signer.h
index 31b21462b..31b21462b 100644
--- a/libtransport/src/hicn/transport/utils/signer.h
+++ b/libtransport/includes/hicn/transport/security/signer.h
diff --git a/libtransport/src/hicn/transport/utils/verifier.h b/libtransport/includes/hicn/transport/security/verifier.h
index 7ec6e7eda..7ec6e7eda 100644
--- a/libtransport/src/hicn/transport/utils/verifier.h
+++ b/libtransport/includes/hicn/transport/security/verifier.h
diff --git a/libtransport/includes/hicn/transport/utils/CMakeLists.txt b/libtransport/includes/hicn/transport/utils/CMakeLists.txt
new file mode 100644
index 000000000..396bd06d6
--- /dev/null
+++ b/libtransport/includes/hicn/transport/utils/CMakeLists.txt
@@ -0,0 +1,39 @@
+# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+
+list(APPEND HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/array.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/string_tokenizer.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/hash.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/uri.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/chrono_typedefs.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/branch_prediction.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/ring_buffer.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/literals.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/conversions.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/linux.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/log.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/object_pool.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/membuf.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/spinlock.h
+)
+
+if(NOT WIN32)
+ list(APPEND HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/daemonizator.h
+ )
+endif()
+
+set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE) \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/utils/array.h b/libtransport/includes/hicn/transport/utils/array.h
index 7c0ed65d8..7c0ed65d8 100644
--- a/libtransport/src/hicn/transport/utils/array.h
+++ b/libtransport/includes/hicn/transport/utils/array.h
diff --git a/libtransport/src/hicn/transport/utils/branch_prediction.h b/libtransport/includes/hicn/transport/utils/branch_prediction.h
index 8cbfaca76..8cbfaca76 100644
--- a/libtransport/src/hicn/transport/utils/branch_prediction.h
+++ b/libtransport/includes/hicn/transport/utils/branch_prediction.h
diff --git a/libtransport/src/hicn/transport/utils/chrono_typedefs.h b/libtransport/includes/hicn/transport/utils/chrono_typedefs.h
index 8f28e763c..8f28e763c 100644
--- a/libtransport/src/hicn/transport/utils/chrono_typedefs.h
+++ b/libtransport/includes/hicn/transport/utils/chrono_typedefs.h
diff --git a/libtransport/src/hicn/transport/utils/conversions.h b/libtransport/includes/hicn/transport/utils/conversions.h
index 24b529206..24b529206 100644
--- a/libtransport/src/hicn/transport/utils/conversions.h
+++ b/libtransport/includes/hicn/transport/utils/conversions.h
diff --git a/libtransport/src/hicn/transport/utils/daemonizator.h b/libtransport/includes/hicn/transport/utils/daemonizator.h
index 028d74865..028d74865 100644
--- a/libtransport/src/hicn/transport/utils/daemonizator.h
+++ b/libtransport/includes/hicn/transport/utils/daemonizator.h
diff --git a/libtransport/src/hicn/transport/utils/hash.h b/libtransport/includes/hicn/transport/utils/hash.h
index 6815ca4bf..6815ca4bf 100644
--- a/libtransport/src/hicn/transport/utils/hash.h
+++ b/libtransport/includes/hicn/transport/utils/hash.h
diff --git a/libtransport/src/hicn/transport/utils/linux.h b/libtransport/includes/hicn/transport/utils/linux.h
index 5820528e1..5820528e1 100644
--- a/libtransport/src/hicn/transport/utils/linux.h
+++ b/libtransport/includes/hicn/transport/utils/linux.h
diff --git a/libtransport/src/hicn/transport/utils/literals.h b/libtransport/includes/hicn/transport/utils/literals.h
index bd00e0a58..bd00e0a58 100644
--- a/libtransport/src/hicn/transport/utils/literals.h
+++ b/libtransport/includes/hicn/transport/utils/literals.h
diff --git a/libtransport/src/hicn/transport/utils/log.h b/libtransport/includes/hicn/transport/utils/log.h
index 3c4f1277a..3c4f1277a 100644
--- a/libtransport/src/hicn/transport/utils/log.h
+++ b/libtransport/includes/hicn/transport/utils/log.h
diff --git a/libtransport/src/hicn/transport/utils/membuf.h b/libtransport/includes/hicn/transport/utils/membuf.h
index 9fc37dd25..9fc37dd25 100644
--- a/libtransport/src/hicn/transport/utils/membuf.h
+++ b/libtransport/includes/hicn/transport/utils/membuf.h
diff --git a/libtransport/src/hicn/transport/utils/object_pool.h b/libtransport/includes/hicn/transport/utils/object_pool.h
index e8f837753..f78bd2aa2 100644
--- a/libtransport/src/hicn/transport/utils/object_pool.h
+++ b/libtransport/includes/hicn/transport/utils/object_pool.h
@@ -16,6 +16,7 @@
#pragma once
// TODO
+#include <hicn/transport/utils/branch_prediction.h>
#include <hicn/transport/utils/spinlock.h>
#include <deque>
diff --git a/libtransport/src/hicn/transport/utils/ring_buffer.h b/libtransport/includes/hicn/transport/utils/ring_buffer.h
index 9babe56bd..9babe56bd 100644
--- a/libtransport/src/hicn/transport/utils/ring_buffer.h
+++ b/libtransport/includes/hicn/transport/utils/ring_buffer.h
diff --git a/libtransport/src/hicn/transport/utils/spinlock.h b/libtransport/includes/hicn/transport/utils/spinlock.h
index 009a94454..009a94454 100644
--- a/libtransport/src/hicn/transport/utils/spinlock.h
+++ b/libtransport/includes/hicn/transport/utils/spinlock.h
diff --git a/libtransport/src/hicn/transport/utils/string_tokenizer.h b/libtransport/includes/hicn/transport/utils/string_tokenizer.h
index 36630eb58..36630eb58 100644
--- a/libtransport/src/hicn/transport/utils/string_tokenizer.h
+++ b/libtransport/includes/hicn/transport/utils/string_tokenizer.h
diff --git a/libtransport/src/hicn/transport/utils/uri.h b/libtransport/includes/hicn/transport/utils/uri.h
index 7c28e8552..7c28e8552 100644
--- a/libtransport/src/hicn/transport/utils/uri.h
+++ b/libtransport/includes/hicn/transport/utils/uri.h
diff --git a/libtransport/src/hicn/transport/CMakeLists.txt b/libtransport/src/CMakeLists.txt
index 4bdb3c1e7..a182998e3 100644
--- a/libtransport/src/hicn/transport/CMakeLists.txt
+++ b/libtransport/src/CMakeLists.txt
@@ -18,18 +18,18 @@ include(GNUInstallDirs)
set(ASIO_STANDALONE 1)
add_subdirectory(core)
-add_subdirectory(errors)
-add_subdirectory(http)
add_subdirectory(interfaces)
-add_subdirectory(portability)
add_subdirectory(protocols)
+add_subdirectory(security)
+add_subdirectory(implementation)
add_subdirectory(utils)
+add_subdirectory(http)
include(Packager)
extract_version()
-configure_file("config.h.in" "config.h" @ONLY)
+configure_file("config.h.in" "hicn/transport/config.h" @ONLY)
install(
- FILES ${CMAKE_CURRENT_BINARY_DIR}/config.h
+ FILES ${CMAKE_CURRENT_BINARY_DIR}/hicn/transport/config.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hicn/transport
COMPONENT lib${LIBTRANSPORT}-dev
)
@@ -37,13 +37,13 @@ install(
set (COMPILER_DEFINITIONS "-DTRANSPORT_LOG_DEF_LEVEL=TRANSPORT_LOG_${TRANSPORT_LOG_LEVEL}")
list(INSERT LIBTRANSPORT_INTERNAL_INCLUDE_DIRS 0
- ${CMAKE_CURRENT_SOURCE_DIR}/../..
- ${CMAKE_CURRENT_BINARY_DIR}/../..
+ ${CMAKE_CURRENT_SOURCE_DIR}/
+ ${CMAKE_CURRENT_BINARY_DIR}/
)
set(LIBTRANSPORT_INCLUDE_DIRS
- ${CMAKE_CURRENT_SOURCE_DIR}/../../
- ${CMAKE_CURRENT_BINARY_DIR}/../../
+ ${CMAKE_CURRENT_BINARY_DIR}
+ ${LIBTRANSPORT_INCLUDE_DIRS}
"" CACHE INTERNAL
"" FORCE
)
@@ -64,11 +64,11 @@ if (DISABLE_SHARED_LIBRARIES)
build_library(${LIBTRANSPORT}
STATIC
SOURCES ${SOURCE_FILES} ${HEADER_FILES}
- INSTALL_HEADERS ${HEADER_FILES}
+ INSTALL_HEADERS ${LIBHICNTRANSPORT_TO_INSTALL_HEADER_FILES}
LINK_LIBRARIES ${LIBRARIES}
DEPENDS ${DEPENDENCIES}
COMPONENT lib${LIBTRANSPORT}
- INCLUDE_DIRS ${LIBTRANSPORT_INTERNAL_INCLUDE_DIRS}
+ INCLUDE_DIRS ${LIBTRANSPORT_INTERNAL_INCLUDE_DIRS} ${LIBTRANSPORT_INCLUDE_DIRS}
INSTALL_ROOT_DIR hicn/transport
DEFINITIONS ${COMPILER_DEFINITIONS}
)
@@ -76,11 +76,11 @@ else ()
build_library(${LIBTRANSPORT}
STATIC SHARED
SOURCES ${SOURCE_FILES} ${HEADER_FILES}
- INSTALL_HEADERS ${HEADER_FILES}
+ INSTALL_HEADERS ${LIBHICNTRANSPORT_TO_INSTALL_HEADER_FILES}
LINK_LIBRARIES ${LIBRARIES}
DEPENDS ${DEPENDENCIES}
COMPONENT lib${LIBTRANSPORT}
- INCLUDE_DIRS ${LIBTRANSPORT_INTERNAL_INCLUDE_DIRS}
+ INCLUDE_DIRS ${LIBTRANSPORT_INTERNAL_INCLUDE_DIRS} ${LIBTRANSPORT_INCLUDE_DIRS}
INSTALL_ROOT_DIR hicn/transport
DEFINITIONS ${COMPILER_DEFINITIONS}
)
diff --git a/libtransport/src/hicn/transport/config.h.in b/libtransport/src/config.h.in
index 4e9a0f262..4e9a0f262 100644
--- a/libtransport/src/hicn/transport/config.h.in
+++ b/libtransport/src/config.h.in
diff --git a/libtransport/src/hicn/transport/core/CMakeLists.txt b/libtransport/src/core/CMakeLists.txt
index 8439fdf45..12ef9cfe4 100644
--- a/libtransport/src/hicn/transport/core/CMakeLists.txt
+++ b/libtransport/src/core/CMakeLists.txt
@@ -14,19 +14,13 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
list(APPEND HEADER_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/content_object.h
${CMAKE_CURRENT_SOURCE_DIR}/facade.h
- ${CMAKE_CURRENT_SOURCE_DIR}/interest.h
${CMAKE_CURRENT_SOURCE_DIR}/manifest.h
${CMAKE_CURRENT_SOURCE_DIR}/manifest_inline.h
${CMAKE_CURRENT_SOURCE_DIR}/manifest_format_fixed.h
${CMAKE_CURRENT_SOURCE_DIR}/manifest_format.h
- ${CMAKE_CURRENT_SOURCE_DIR}/name.h
- ${CMAKE_CURRENT_SOURCE_DIR}/packet.h
- ${CMAKE_CURRENT_SOURCE_DIR}/payload_type.h
${CMAKE_CURRENT_SOURCE_DIR}/pending_interest.h
${CMAKE_CURRENT_SOURCE_DIR}/portal.h
- ${CMAKE_CURRENT_SOURCE_DIR}/prefix.h
${CMAKE_CURRENT_SOURCE_DIR}/connector.h
${CMAKE_CURRENT_SOURCE_DIR}/tcp_socket_connector.h
${CMAKE_CURRENT_SOURCE_DIR}/udp_socket_connector.h
diff --git a/libtransport/src/hicn/transport/core/connector.cc b/libtransport/src/core/connector.cc
index fc271574c..63919537d 100644
--- a/libtransport/src/hicn/transport/core/connector.cc
+++ b/libtransport/src/core/connector.cc
@@ -13,7 +13,7 @@
* limitations under the License.
*/
-#include <hicn/transport/core/connector.h>
+#include <core/connector.h>
namespace transport {
diff --git a/libtransport/src/hicn/transport/core/connector.h b/libtransport/src/core/connector.h
index f2bbe5dcd..f2bbe5dcd 100644
--- a/libtransport/src/hicn/transport/core/connector.h
+++ b/libtransport/src/core/connector.h
diff --git a/libtransport/src/hicn/transport/core/content_object.cc b/libtransport/src/core/content_object.cc
index 6cbcdb29e..6cbcdb29e 100644
--- a/libtransport/src/hicn/transport/core/content_object.cc
+++ b/libtransport/src/core/content_object.cc
diff --git a/libtransport/src/hicn/transport/core/facade.h b/libtransport/src/core/facade.h
index 27e738e62..04f643f63 100644
--- a/libtransport/src/hicn/transport/core/facade.h
+++ b/libtransport/src/core/facade.h
@@ -15,17 +15,17 @@
#pragma once
-#include <hicn/transport/core/forwarder_interface.h>
-#include <hicn/transport/core/hicn_forwarder_interface.h>
-#include <hicn/transport/core/manifest_format_fixed.h>
-#include <hicn/transport/core/manifest_inline.h>
-#include <hicn/transport/core/portal.h>
+#include <core/forwarder_interface.h>
+#include <core/hicn_forwarder_interface.h>
+#include <core/manifest_format_fixed.h>
+#include <core/manifest_inline.h>
+#include <core/portal.h>
#ifdef __linux__
#ifndef __ANDROID__
-#include <hicn/transport/core/raw_socket_interface.h>
+#include <core/raw_socket_interface.h>
#ifdef __vpp__
-#include <hicn/transport/core/vpp_forwarder_interface.h>
+#include <core/vpp_forwarder_interface.h>
#endif
#endif
#endif
diff --git a/libtransport/src/hicn/transport/core/forwarder_interface.h b/libtransport/src/core/forwarder_interface.h
index 63b4a2eda..3e70e221d 100644
--- a/libtransport/src/hicn/transport/core/forwarder_interface.h
+++ b/libtransport/src/core/forwarder_interface.h
@@ -15,11 +15,10 @@
#pragma once
+#include <core/udp_socket_connector.h>
#include <hicn/transport/core/prefix.h>
-#include <hicn/transport/core/udp_socket_connector.h>
#include <hicn/transport/portability/portability.h>
#include <hicn/transport/utils/chrono_typedefs.h>
-#include <hicn/transport/utils/log.h>
#include <deque>
@@ -50,8 +49,7 @@ class ForwarderInterface {
inet6_address_({}),
mtu_(1500),
output_interface_(""),
- content_store_reserved_(standard_cs_reserved) {
- }
+ content_store_reserved_(standard_cs_reserved) {}
public:
virtual ~ForwarderInterface() {}
diff --git a/libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc b/libtransport/src/core/hicn_forwarder_interface.cc
index 2a02a2ba8..810daba3a 100644
--- a/libtransport/src/hicn/transport/core/hicn_forwarder_interface.cc
+++ b/libtransport/src/core/hicn_forwarder_interface.cc
@@ -13,7 +13,7 @@
* limitations under the License.
*/
-#include <hicn/transport/core/hicn_forwarder_interface.h>
+#include <core/hicn_forwarder_interface.h>
union AddressLight {
uint32_t ipv4;
diff --git a/libtransport/src/hicn/transport/core/hicn_forwarder_interface.h b/libtransport/src/core/hicn_forwarder_interface.h
index b11841b69..6969f4a6b 100644
--- a/libtransport/src/hicn/transport/core/hicn_forwarder_interface.h
+++ b/libtransport/src/core/hicn_forwarder_interface.h
@@ -15,9 +15,10 @@
#pragma once
-#include <hicn/transport/core/forwarder_interface.h>
#include <hicn/transport/core/prefix.h>
-#include <hicn/transport/core/udp_socket_connector.h>
+
+#include <core/forwarder_interface.h>
+#include <core/udp_socket_connector.h>
#include <deque>
diff --git a/libtransport/src/hicn/transport/core/hicn_vapi.c b/libtransport/src/core/hicn_vapi.c
index aea08f31c..d19e36346 100644
--- a/libtransport/src/hicn/transport/core/hicn_vapi.c
+++ b/libtransport/src/core/hicn_vapi.c
@@ -17,9 +17,10 @@
#ifdef __vpp__
-#include <hicn/transport/core/hicn_vapi.h>
#include <hicn/transport/utils/log.h>
+#include <core/hicn_vapi.h>
+
#define HICN_VPP_PLUGIN
#include <hicn/name.h>
#undef HICN_VPP_PLUGIN
@@ -30,13 +31,13 @@
#include <vlibmemory/api.h>
#include <vppinfra/error.h>
+#include <vnet/fib/fib_types.h>
#include <vnet/ip/format.h>
#include <vnet/ip/ip4_packet.h>
#include <vnet/ip/ip6_packet.h>
-#include <vnet/fib/fib_types.h>
-#include <vpp_plugins/hicn/error.h>
#include <vapi/hicn.api.vapi.h>
+#include <vpp_plugins/hicn/error.h>
/////////////////////////////////////////////////////
const char *HICN_ERROR_STRING[] = {
@@ -46,51 +47,50 @@ const char *HICN_ERROR_STRING[] = {
};
/////////////////////////////////////////////////////
-/*********************** Missing Symbol in vpp libraries *************************/
-u8 *
-format_vl_api_address_union (u8 * s, va_list * args)
-{
- return NULL;
-}
+/*********************** Missing Symbol in vpp libraries
+ * *************************/
+u8 *format_vl_api_address_union(u8 *s, va_list *args) { return NULL; }
/*********************************************************************************/
DEFINE_VAPI_MSG_IDS_HICN_API_JSON
-static vapi_error_e register_prod_app_cb(vapi_ctx_t ctx,
- void *callback_ctx,
- vapi_error_e rv,
- bool is_last,
- vapi_payload_hicn_api_register_prod_app_reply *reply) {
- hicn_producer_output_params * output_params = (hicn_producer_output_params *)callback_ctx;
+static vapi_error_e register_prod_app_cb(
+ vapi_ctx_t ctx, void *callback_ctx, vapi_error_e rv, bool is_last,
+ vapi_payload_hicn_api_register_prod_app_reply *reply) {
+ hicn_producer_output_params *output_params =
+ (hicn_producer_output_params *)callback_ctx;
- if(reply == NULL)
- return rv;
+ if (reply == NULL) return rv;
output_params->cs_reserved = reply->cs_reserved;
output_params->prod_addr = (ip_address_t *)malloc(sizeof(ip_address_t));
memset(output_params->prod_addr, 0, sizeof(ip_address_t));
- if(reply->prod_addr.af == ADDRESS_IP6)
- memcpy(&output_params->prod_addr->v6, reply->prod_addr.un.ip6, sizeof(ip6_address_t));
+ if (reply->prod_addr.af == ADDRESS_IP6)
+ memcpy(&output_params->prod_addr->v6, reply->prod_addr.un.ip6,
+ sizeof(ip6_address_t));
else
- memcpy(&output_params->prod_addr->v4, reply->prod_addr.un.ip4, sizeof(ip4_address_t));
+ memcpy(&output_params->prod_addr->v4, reply->prod_addr.un.ip4,
+ sizeof(ip4_address_t));
output_params->face_id = reply->faceid;
return reply->retval;
}
-int hicn_vapi_register_prod_app(
- vapi_ctx_t ctx, hicn_producer_input_params *input_params,
- hicn_producer_output_params *output_params) {
-
+int hicn_vapi_register_prod_app(vapi_ctx_t ctx,
+ hicn_producer_input_params *input_params,
+ hicn_producer_output_params *output_params) {
vapi_lock();
- vapi_msg_hicn_api_register_prod_app * msg = vapi_alloc_hicn_api_register_prod_app(ctx);
+ vapi_msg_hicn_api_register_prod_app *msg =
+ vapi_alloc_hicn_api_register_prod_app(ctx);
- if(ip46_address_is_ip4((ip46_address_t *)&input_params->prefix->address)) {
- memcpy(&msg->payload.prefix.address.un.ip4, &input_params->prefix->address, sizeof(ip4_address_t));
+ if (ip46_address_is_ip4((ip46_address_t *)&input_params->prefix->address)) {
+ memcpy(&msg->payload.prefix.address.un.ip4, &input_params->prefix->address,
+ sizeof(ip4_address_t));
msg->payload.prefix.address.af = ADDRESS_IP4;
} else {
- memcpy(&msg->payload.prefix.address.un.ip6, &input_params->prefix->address, sizeof(ip6_address_t));
+ memcpy(&msg->payload.prefix.address.un.ip6, &input_params->prefix->address,
+ sizeof(ip6_address_t));
msg->payload.prefix.address.af = ADDRESS_IP6;
}
msg->payload.prefix.len = input_params->prefix->len;
@@ -98,26 +98,24 @@ int hicn_vapi_register_prod_app(
msg->payload.swif = input_params->swif;
msg->payload.cs_reserved = input_params->cs_reserved;
- int ret = vapi_hicn_api_register_prod_app(ctx, msg, register_prod_app_cb, output_params);
+ int ret = vapi_hicn_api_register_prod_app(ctx, msg, register_prod_app_cb,
+ output_params);
vapi_unlock();
return ret;
}
-static vapi_error_e face_prod_del_cb(vapi_ctx_t ctx,
- void *callback_ctx,
- vapi_error_e rv,
- bool is_last,
- vapi_payload_hicn_api_face_prod_del_reply *reply) {
- if(reply == NULL)
- return rv;
+static vapi_error_e face_prod_del_cb(
+ vapi_ctx_t ctx, void *callback_ctx, vapi_error_e rv, bool is_last,
+ vapi_payload_hicn_api_face_prod_del_reply *reply) {
+ if (reply == NULL) return rv;
return reply->retval;
}
-int hicn_vapi_face_prod_del(
- vapi_ctx_t ctx, hicn_del_face_app_input_params *input_params) {
+int hicn_vapi_face_prod_del(vapi_ctx_t ctx,
+ hicn_del_face_app_input_params *input_params) {
vapi_lock();
- vapi_msg_hicn_api_face_prod_del * msg = vapi_alloc_hicn_api_face_prod_del(ctx);
+ vapi_msg_hicn_api_face_prod_del *msg = vapi_alloc_hicn_api_face_prod_del(ctx);
msg->payload.faceid = input_params->face_id;
@@ -126,22 +124,22 @@ int hicn_vapi_face_prod_del(
return ret;
}
-static vapi_error_e register_cons_app_cb(vapi_ctx_t ctx,
- void *callback_ctx,
- vapi_error_e rv,
- bool is_last,
- vapi_payload_hicn_api_register_cons_app_reply *reply) {
- hicn_consumer_output_params * output_params = (hicn_consumer_output_params *)callback_ctx;
+static vapi_error_e register_cons_app_cb(
+ vapi_ctx_t ctx, void *callback_ctx, vapi_error_e rv, bool is_last,
+ vapi_payload_hicn_api_register_cons_app_reply *reply) {
+ hicn_consumer_output_params *output_params =
+ (hicn_consumer_output_params *)callback_ctx;
- if(reply == NULL)
- return rv;
+ if (reply == NULL) return rv;
output_params->src6 = (ip_address_t *)malloc(sizeof(ip_address_t));
output_params->src4 = (ip_address_t *)malloc(sizeof(ip_address_t));
memset(output_params->src6, 0, sizeof(ip_address_t));
memset(output_params->src4, 0, sizeof(ip_address_t));
- memcpy(&output_params->src6->v6, &reply->src_addr6.un.ip6, sizeof(ip6_address_t));
- memcpy(&output_params->src4->v4, &reply->src_addr4.un.ip4, sizeof(ip4_address_t));
+ memcpy(&output_params->src6->v6, &reply->src_addr6.un.ip6,
+ sizeof(ip6_address_t));
+ memcpy(&output_params->src4->v4, &reply->src_addr4.un.ip4,
+ sizeof(ip4_address_t));
output_params->face_id1 = reply->faceid1;
output_params->face_id2 = reply->faceid2;
@@ -149,36 +147,33 @@ static vapi_error_e register_cons_app_cb(vapi_ctx_t ctx,
return reply->retval;
}
-int hicn_vapi_register_cons_app(
- vapi_ctx_t ctx, hicn_consumer_input_params *input_params,
- hicn_consumer_output_params *output_params) {
-
+int hicn_vapi_register_cons_app(vapi_ctx_t ctx,
+ hicn_consumer_input_params *input_params,
+ hicn_consumer_output_params *output_params) {
vapi_lock();
- vapi_msg_hicn_api_register_cons_app * msg = vapi_alloc_hicn_api_register_cons_app(ctx);
+ vapi_msg_hicn_api_register_cons_app *msg =
+ vapi_alloc_hicn_api_register_cons_app(ctx);
msg->payload.swif = input_params->swif;
- int ret = vapi_hicn_api_register_cons_app(ctx, msg, register_cons_app_cb, output_params);
+ int ret = vapi_hicn_api_register_cons_app(ctx, msg, register_cons_app_cb,
+ output_params);
vapi_unlock();
return ret;
}
-static vapi_error_e face_cons_del_cb(vapi_ctx_t ctx,
- void *callback_ctx,
- vapi_error_e rv,
- bool is_last,
- vapi_payload_hicn_api_face_cons_del_reply *reply) {
- if(reply == NULL)
- return rv;
+static vapi_error_e face_cons_del_cb(
+ vapi_ctx_t ctx, void *callback_ctx, vapi_error_e rv, bool is_last,
+ vapi_payload_hicn_api_face_cons_del_reply *reply) {
+ if (reply == NULL) return rv;
return reply->retval;
}
-int hicn_vapi_face_cons_del(
- vapi_ctx_t ctx, hicn_del_face_app_input_params *input_params) {
-
+int hicn_vapi_face_cons_del(vapi_ctx_t ctx,
+ hicn_del_face_app_input_params *input_params) {
vapi_lock();
- vapi_msg_hicn_api_face_cons_del * msg = vapi_alloc_hicn_api_face_cons_del(ctx);
+ vapi_msg_hicn_api_face_cons_del *msg = vapi_alloc_hicn_api_face_cons_del(ctx);
msg->payload.faceid = input_params->face_id;
@@ -187,26 +182,23 @@ int hicn_vapi_face_cons_del(
return ret;
}
-static vapi_error_e reigster_route_cb(vapi_ctx_t ctx,
- void *callback_ctx,
- vapi_error_e rv,
- bool is_last,
- vapi_payload_hicn_api_route_nhops_add_reply *reply) {
- if(reply == NULL)
- return rv;
+static vapi_error_e reigster_route_cb(
+ vapi_ctx_t ctx, void *callback_ctx, vapi_error_e rv, bool is_last,
+ vapi_payload_hicn_api_route_nhops_add_reply *reply) {
+ if (reply == NULL) return rv;
return reply->retval;
}
-int hicn_vapi_register_route(
- vapi_ctx_t ctx,
- hicn_producer_set_route_params *input_params) {
-
+int hicn_vapi_register_route(vapi_ctx_t ctx,
+ hicn_producer_set_route_params *input_params) {
vapi_lock();
- vapi_msg_hicn_api_route_nhops_add * msg = vapi_alloc_hicn_api_route_nhops_add(ctx);
+ vapi_msg_hicn_api_route_nhops_add *msg =
+ vapi_alloc_hicn_api_route_nhops_add(ctx);
fib_prefix_t prefix;
- memcpy(&prefix.fp_addr, &input_params->prefix->address, sizeof(ip46_address_t));
+ memcpy(&prefix.fp_addr, &input_params->prefix->address,
+ sizeof(ip46_address_t));
prefix.fp_len = input_params->prefix->len;
msg->payload.face_ids[0] = input_params->face_id;
msg->payload.n_faces = 1;
diff --git a/libtransport/src/hicn/transport/core/hicn_vapi.h b/libtransport/src/core/hicn_vapi.h
index f2718e6f5..f2718e6f5 100644
--- a/libtransport/src/hicn/transport/core/hicn_vapi.h
+++ b/libtransport/src/core/hicn_vapi.h
diff --git a/libtransport/src/hicn/transport/core/interest.cc b/libtransport/src/core/interest.cc
index 166632f0a..166632f0a 100644
--- a/libtransport/src/hicn/transport/core/interest.cc
+++ b/libtransport/src/core/interest.cc
diff --git a/libtransport/src/hicn/transport/core/manifest.cc b/libtransport/src/core/manifest.cc
index 3f890f3d0..3f890f3d0 100644
--- a/libtransport/src/hicn/transport/core/manifest.cc
+++ b/libtransport/src/core/manifest.cc
diff --git a/libtransport/src/hicn/transport/core/manifest.h b/libtransport/src/core/manifest.h
index 9650de94d..b4875bf22 100644
--- a/libtransport/src/hicn/transport/core/manifest.h
+++ b/libtransport/src/core/manifest.h
@@ -16,9 +16,10 @@
#pragma once
#include <hicn/transport/core/content_object.h>
-#include <hicn/transport/core/manifest_format.h>
#include <hicn/transport/core/name.h>
+#include <core/manifest_format.h>
+
#include <set>
namespace transport {
diff --git a/libtransport/src/hicn/transport/core/manifest_format.h b/libtransport/src/core/manifest_format.h
index 9b6777270..f95d19aa8 100644
--- a/libtransport/src/hicn/transport/core/manifest_format.h
+++ b/libtransport/src/core/manifest_format.h
@@ -16,7 +16,7 @@
#pragma once
#include <hicn/transport/core/name.h>
-#include <hicn/transport/utils/crypto_hasher.h>
+#include <hicn/transport/security/crypto_hasher.h>
#include <cinttypes>
#include <type_traits>
diff --git a/libtransport/src/hicn/transport/core/manifest_format_fixed.cc b/libtransport/src/core/manifest_format_fixed.cc
index f5e31d784..4073a5d26 100644
--- a/libtransport/src/hicn/transport/core/manifest_format_fixed.cc
+++ b/libtransport/src/core/manifest_format_fixed.cc
@@ -13,10 +13,11 @@
* limitations under the License.
*/
-#include <hicn/transport/core/manifest_format_fixed.h>
#include <hicn/transport/core/packet.h>
#include <hicn/transport/utils/literals.h>
+#include <core/manifest_format_fixed.h>
+
namespace transport {
namespace core {
diff --git a/libtransport/src/hicn/transport/core/manifest_format_fixed.h b/libtransport/src/core/manifest_format_fixed.h
index 2c6e2bced..9cacb3bc2 100644
--- a/libtransport/src/hicn/transport/core/manifest_format_fixed.h
+++ b/libtransport/src/core/manifest_format_fixed.h
@@ -15,9 +15,10 @@
#pragma once
-#include <hicn/transport/core/manifest_format.h>
#include <hicn/transport/core/packet.h>
+#include <core/manifest_format.h>
+
#include <string>
namespace transport {
diff --git a/libtransport/src/hicn/transport/core/manifest_inline.h b/libtransport/src/core/manifest_inline.h
index 385e43af3..235c6f3a0 100644
--- a/libtransport/src/hicn/transport/core/manifest_inline.h
+++ b/libtransport/src/core/manifest_inline.h
@@ -15,9 +15,10 @@
#pragma once
-#include <hicn/transport/core/manifest.h>
-#include <hicn/transport/core/manifest_format.h>
#include <hicn/transport/portability/portability.h>
+
+#include <core/manifest.h>
+#include <core/manifest_format.h>
#include <set>
namespace transport {
diff --git a/libtransport/src/hicn/transport/core/memif_connector.cc b/libtransport/src/core/memif_connector.cc
index 5e37c882a..2292e9b41 100644
--- a/libtransport/src/hicn/transport/core/memif_connector.cc
+++ b/libtransport/src/core/memif_connector.cc
@@ -13,9 +13,10 @@
* limitations under the License.
*/
-#include <hicn/transport/core/memif_connector.h>
#include <hicn/transport/errors/not_implemented_exception.h>
+#include <core/memif_connector.h>
+
#ifdef __vpp__
#include <sys/epoll.h>
diff --git a/libtransport/src/hicn/transport/core/memif_connector.h b/libtransport/src/core/memif_connector.h
index bf4e2d56c..aafef1e56 100644
--- a/libtransport/src/hicn/transport/core/memif_connector.h
+++ b/libtransport/src/core/memif_connector.h
@@ -16,13 +16,14 @@
#pragma once
#include <hicn/transport/config.h>
-#include <hicn/transport/core/connector.h>
-//#include <hicn/transport/core/hicn_vapi.h>
#include <hicn/transport/portability/portability.h>
-#include <hicn/transport/utils/epoll_event_reactor.h>
-#include <hicn/transport/utils/fd_deadline_timer.h>
#include <hicn/transport/utils/ring_buffer.h>
+#include <core/connector.h>
+//#include <hicn/transport/core/hicn_vapi.h>
+#include <utils/epoll_event_reactor.h>
+#include <utils/fd_deadline_timer.h>
+
#include <asio.hpp>
#include <deque>
#include <mutex>
diff --git a/libtransport/src/hicn/transport/core/memif_vapi.c b/libtransport/src/core/memif_vapi.c
index 11cf42441..ea3513306 100644
--- a/libtransport/src/hicn/transport/core/memif_vapi.c
+++ b/libtransport/src/core/memif_vapi.c
@@ -16,28 +16,26 @@
#ifdef __vpp__
-#include <vapi/vapi_safe.h>
-#include <vppinfra/clib.h>
-#include <hicn/transport/core/memif_vapi.h>
+#include <core/memif_vapi.h>
+
#include <fcntl.h>
#include <inttypes.h>
#include <semaphore.h>
#include <string.h>
#include <sys/stat.h>
+#include <vapi/vapi_safe.h>
+#include <vppinfra/clib.h>
DEFINE_VAPI_MSG_IDS_MEMIF_API_JSON
-static vapi_error_e memif_details_cb(vapi_ctx_t ctx,
- void *callback_ctx,
- vapi_error_e rv,
- bool is_last,
+static vapi_error_e memif_details_cb(vapi_ctx_t ctx, void *callback_ctx,
+ vapi_error_e rv, bool is_last,
vapi_payload_memif_details *reply) {
uint32_t *last_memif_id = (uint32_t *)callback_ctx;
uint32_t current_memif_id = 0;
if (reply != NULL) {
current_memif_id = reply->id;
- }
- else {
+ } else {
return rv;
}
@@ -48,35 +46,30 @@ static vapi_error_e memif_details_cb(vapi_ctx_t ctx,
return rv;
}
-int memif_vapi_get_next_memif_id(vapi_ctx_t ctx,
- uint32_t *memif_id) {
+int memif_vapi_get_next_memif_id(vapi_ctx_t ctx, uint32_t *memif_id) {
vapi_lock();
- vapi_msg_memif_dump * msg = vapi_alloc_memif_dump(ctx);
+ vapi_msg_memif_dump *msg = vapi_alloc_memif_dump(ctx);
int ret = vapi_memif_dump(ctx, msg, memif_details_cb, memif_id);
vapi_unlock();
return ret;
}
-static vapi_error_e memif_create_cb(vapi_ctx_t ctx,
- void *callback_ctx,
- vapi_error_e rv,
- bool is_last,
- vapi_payload_memif_create_reply *reply) {
+static vapi_error_e memif_create_cb(vapi_ctx_t ctx, void *callback_ctx,
+ vapi_error_e rv, bool is_last,
+ vapi_payload_memif_create_reply *reply) {
memif_output_params_t *output_params = (memif_output_params_t *)callback_ctx;
- if (reply == NULL)
- return rv;
+ if (reply == NULL) return rv;
output_params->sw_if_index = reply->sw_if_index;
return rv;
}
-int memif_vapi_create_memif(vapi_ctx_t ctx,
- memif_create_params_t *input_params,
+int memif_vapi_create_memif(vapi_ctx_t ctx, memif_create_params_t *input_params,
memif_output_params_t *output_params) {
vapi_lock();
- vapi_msg_memif_create * msg = vapi_alloc_memif_create(ctx);
+ vapi_msg_memif_create *msg = vapi_alloc_memif_create(ctx);
int ret = 0;
if (input_params->socket_id == ~0) {
@@ -113,26 +106,22 @@ int memif_vapi_create_memif(vapi_ctx_t ctx,
msg->payload.buffer_size = input_params->buffer_size;
ret = vapi_memif_create(ctx, msg, memif_create_cb, output_params);
- END:
+END:
vapi_unlock();
return ret;
}
-static vapi_error_e memif_delete_cb(vapi_ctx_t ctx,
- void *callback_ctx,
- vapi_error_e rv,
- bool is_last,
- vapi_payload_memif_delete_reply *reply) {
- if(reply == NULL)
- return rv;
-
+static vapi_error_e memif_delete_cb(vapi_ctx_t ctx, void *callback_ctx,
+ vapi_error_e rv, bool is_last,
+ vapi_payload_memif_delete_reply *reply) {
+ if (reply == NULL) return rv;
+
return reply->retval;
}
-int memif_vapi_delete_memif(vapi_ctx_t ctx,
- uint32_t sw_if_index) {
+int memif_vapi_delete_memif(vapi_ctx_t ctx, uint32_t sw_if_index) {
vapi_lock();
- vapi_msg_memif_delete * msg = vapi_alloc_memif_delete(ctx);
+ vapi_msg_memif_delete *msg = vapi_alloc_memif_delete(ctx);
msg->payload.sw_if_index = sw_if_index;
diff --git a/libtransport/src/hicn/transport/core/memif_vapi.h b/libtransport/src/core/memif_vapi.h
index c045cf093..c045cf093 100644
--- a/libtransport/src/hicn/transport/core/memif_vapi.h
+++ b/libtransport/src/core/memif_vapi.h
diff --git a/libtransport/src/hicn/transport/core/name.cc b/libtransport/src/core/name.cc
index 85e2b8565..811e93b87 100644
--- a/libtransport/src/hicn/transport/core/name.cc
+++ b/libtransport/src/core/name.cc
@@ -13,13 +13,14 @@
* limitations under the License.
*/
-#include <hicn/transport/core/manifest_format.h>
#include <hicn/transport/core/name.h>
#include <hicn/transport/errors/errors.h>
#include <hicn/transport/errors/tokenizer_exception.h>
#include <hicn/transport/utils/hash.h>
#include <hicn/transport/utils/string_tokenizer.h>
+#include <core/manifest_format.h>
+
namespace transport {
namespace core {
diff --git a/libtransport/src/hicn/transport/core/packet.cc b/libtransport/src/core/packet.cc
index 817f8de66..817f8de66 100644
--- a/libtransport/src/hicn/transport/core/packet.cc
+++ b/libtransport/src/core/packet.cc
diff --git a/libtransport/src/hicn/transport/core/pending_interest.cc b/libtransport/src/core/pending_interest.cc
index dbbd2c83e..fbe98cab5 100644
--- a/libtransport/src/hicn/transport/core/pending_interest.cc
+++ b/libtransport/src/core/pending_interest.cc
@@ -13,7 +13,7 @@
* limitations under the License.
*/
-#include <hicn/transport/core/pending_interest.h>
+#include <core/pending_interest.h>
namespace transport {
diff --git a/libtransport/src/hicn/transport/core/pending_interest.h b/libtransport/src/core/pending_interest.h
index c481cc200..87fed5073 100644
--- a/libtransport/src/hicn/transport/core/pending_interest.h
+++ b/libtransport/src/core/pending_interest.h
@@ -20,7 +20,8 @@
#include <hicn/transport/core/interest.h>
#include <hicn/transport/core/name.h>
#include <hicn/transport/portability/portability.h>
-#include <hicn/transport/utils/deadline_timer.h>
+
+#include <utils/deadline_timer.h>
#include <asio/steady_timer.hpp>
diff --git a/libtransport/src/hicn/transport/core/portal.h b/libtransport/src/core/portal.h
index c6e11ada6..d7c463dfd 100644
--- a/libtransport/src/hicn/transport/core/portal.h
+++ b/libtransport/src/core/portal.h
@@ -17,18 +17,19 @@
#include <hicn/transport/config.h>
#include <hicn/transport/core/content_object.h>
-#include <hicn/transport/core/forwarder_interface.h>
#include <hicn/transport/core/interest.h>
#include <hicn/transport/core/name.h>
-#include <hicn/transport/core/pending_interest.h>
#include <hicn/transport/core/prefix.h>
-#include <hicn/transport/core/udp_socket_connector.h>
#include <hicn/transport/errors/errors.h>
#include <hicn/transport/portability/portability.h>
#include <hicn/transport/utils/log.h>
+#include <core/forwarder_interface.h>
+#include <core/pending_interest.h>
+#include <core/udp_socket_connector.h>
+
#ifdef __vpp__
-#include <hicn/transport/core/memif_connector.h>
+#include <core/memif_connector.h>
#endif
#include <asio.hpp>
diff --git a/libtransport/src/hicn/transport/core/prefix.cc b/libtransport/src/core/prefix.cc
index 59898ab70..59898ab70 100644
--- a/libtransport/src/hicn/transport/core/prefix.cc
+++ b/libtransport/src/core/prefix.cc
diff --git a/libtransport/src/hicn/transport/core/raw_socket_connector.cc b/libtransport/src/core/raw_socket_connector.cc
index 0e1743671..4d780959b 100644
--- a/libtransport/src/hicn/transport/core/raw_socket_connector.cc
+++ b/libtransport/src/core/raw_socket_connector.cc
@@ -13,10 +13,11 @@
* limitations under the License.
*/
-#include <hicn/transport/core/raw_socket_connector.h>
#include <hicn/transport/utils/conversions.h>
#include <hicn/transport/utils/log.h>
+#include <core/raw_socket_connector.h>
+
#include <net/if.h>
#include <netdb.h>
#include <stdio.h>
diff --git a/libtransport/src/hicn/transport/core/raw_socket_connector.h b/libtransport/src/core/raw_socket_connector.h
index fe9ceb227..1d4e9cb39 100644
--- a/libtransport/src/hicn/transport/core/raw_socket_connector.h
+++ b/libtransport/src/core/raw_socket_connector.h
@@ -16,9 +16,10 @@
#pragma once
#include <hicn/transport/config.h>
-#include <hicn/transport/core/connector.h>
#include <hicn/transport/core/name.h>
+#include <core/connector.h>
+
#include <linux/if_packet.h>
#include <net/ethernet.h>
#include <sys/socket.h>
diff --git a/libtransport/src/hicn/transport/core/raw_socket_interface.cc b/libtransport/src/core/raw_socket_interface.cc
index bb4e083e1..7ee2a844d 100644
--- a/libtransport/src/hicn/transport/core/raw_socket_interface.cc
+++ b/libtransport/src/core/raw_socket_interface.cc
@@ -13,9 +13,10 @@
* limitations under the License.
*/
-#include <hicn/transport/core/raw_socket_interface.h>
#include <hicn/transport/utils/linux.h>
+#include <core/raw_socket_interface.h>
+
#include <fstream>
namespace transport {
diff --git a/libtransport/src/hicn/transport/core/raw_socket_interface.h b/libtransport/src/core/raw_socket_interface.h
index ac48e5874..c06d14637 100644
--- a/libtransport/src/hicn/transport/core/raw_socket_interface.h
+++ b/libtransport/src/core/raw_socket_interface.h
@@ -15,9 +15,10 @@
#pragma once
-#include <hicn/transport/core/forwarder_interface.h>
#include <hicn/transport/core/prefix.h>
-#include <hicn/transport/core/raw_socket_connector.h>
+
+#include <core/forwarder_interface.h>
+#include <core/raw_socket_connector.h>
#include <atomic>
#include <deque>
diff --git a/libtransport/src/hicn/transport/core/tcp_socket_connector.cc b/libtransport/src/core/tcp_socket_connector.cc
index c82373ae1..58df8fb08 100644
--- a/libtransport/src/hicn/transport/core/tcp_socket_connector.cc
+++ b/libtransport/src/core/tcp_socket_connector.cc
@@ -13,10 +13,11 @@
* limitations under the License.
*/
+#include <core/tcp_socket_connector.h>
#ifdef _WIN32
-#include <hicn/transport/portability/win_portability.h>
+#include <portability/win_portability.h>
#endif
-#include <hicn/transport/core/tcp_socket_connector.h>
+
#include <hicn/transport/errors/errors.h>
#include <hicn/transport/utils/log.h>
#include <hicn/transport/utils/object_pool.h>
diff --git a/libtransport/src/hicn/transport/core/tcp_socket_connector.h b/libtransport/src/core/tcp_socket_connector.h
index d755b5e86..c57123e9f 100644
--- a/libtransport/src/hicn/transport/core/tcp_socket_connector.h
+++ b/libtransport/src/core/tcp_socket_connector.h
@@ -16,10 +16,11 @@
#pragma once
#include <hicn/transport/config.h>
-#include <hicn/transport/core/connector.h>
#include <hicn/transport/core/name.h>
#include <hicn/transport/utils/branch_prediction.h>
+#include <core/connector.h>
+
#include <asio.hpp>
#include <asio/steady_timer.hpp>
#include <deque>
diff --git a/libtransport/src/hicn/transport/core/test/CMakeLists.txt b/libtransport/src/core/test/CMakeLists.txt
index 48c50e9b0..48c50e9b0 100644
--- a/libtransport/src/hicn/transport/core/test/CMakeLists.txt
+++ b/libtransport/src/core/test/CMakeLists.txt
diff --git a/libtransport/src/hicn/transport/core/test/test_core_manifest.cc b/libtransport/src/core/test/test_core_manifest.cc
index 58563d8f9..58563d8f9 100644
--- a/libtransport/src/hicn/transport/core/test/test_core_manifest.cc
+++ b/libtransport/src/core/test/test_core_manifest.cc
diff --git a/libtransport/src/hicn/transport/core/udp_socket_connector.cc b/libtransport/src/core/udp_socket_connector.cc
index 99f47fedf..ec59c2e64 100644
--- a/libtransport/src/hicn/transport/core/udp_socket_connector.cc
+++ b/libtransport/src/core/udp_socket_connector.cc
@@ -14,13 +14,15 @@
*/
#ifdef _WIN32
-#include <hicn/transport/portability/win_portability.h>
+#include <portability/win_portability.h>
#endif
-#include <hicn/transport/core/udp_socket_connector.h>
+
#include <hicn/transport/errors/errors.h>
#include <hicn/transport/utils/log.h>
#include <hicn/transport/utils/object_pool.h>
+#include <core/udp_socket_connector.h>
+
#include <thread>
#include <vector>
diff --git a/libtransport/src/hicn/transport/core/udp_socket_connector.h b/libtransport/src/core/udp_socket_connector.h
index 7c5dbaf10..5fdb6aeec 100644
--- a/libtransport/src/hicn/transport/core/udp_socket_connector.h
+++ b/libtransport/src/core/udp_socket_connector.h
@@ -16,10 +16,11 @@
#pragma once
#include <hicn/transport/config.h>
-#include <hicn/transport/core/connector.h>
#include <hicn/transport/core/name.h>
#include <hicn/transport/utils/branch_prediction.h>
+#include <core/connector.h>
+
#include <asio.hpp>
#include <asio/steady_timer.hpp>
#include <deque>
diff --git a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc b/libtransport/src/core/vpp_forwarder_interface.cc
index 9e701bf80..7b4298592 100644
--- a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.cc
+++ b/libtransport/src/core/vpp_forwarder_interface.cc
@@ -17,10 +17,9 @@
#ifdef __vpp__
-#include <hicn/transport/core/hicn_vapi.h>
-#include <hicn/transport/core/memif_vapi.h>
-#include <hicn/transport/core/prefix.h>
-#include <hicn/transport/core/vpp_forwarder_interface.h>
+#include <core/hicn_vapi.h>
+#include <core/memif_vapi.h>
+#include <core/vpp_forwarder_interface.h>
extern "C" {
#include <memif/libmemif.h>
@@ -44,8 +43,7 @@ VPPForwarderInterface::VPPForwarderInterface(MemifConnector &connector)
sw_if_index_(~0),
face_id1_(~0),
face_id2_(~0),
- is_consumer_(false){
- }
+ is_consumer_(false) {}
VPPForwarderInterface::~VPPForwarderInterface() {}
@@ -55,8 +53,8 @@ VPPForwarderInterface::~VPPForwarderInterface() {}
uint32_t VPPForwarderInterface::getMemifConfiguration() {
memif_create_params_t input_params = {0};
- int ret = memif_vapi_get_next_memif_id(
- VPPForwarderInterface::sock_, &memif_id_);
+ int ret =
+ memif_vapi_get_next_memif_id(VPPForwarderInterface::sock_, &memif_id_);
if (ret < 0) {
throw errors::RuntimeException(
@@ -73,8 +71,8 @@ uint32_t VPPForwarderInterface::getMemifConfiguration() {
memif_output_params_t output_params = {0};
- ret = memif_vapi_create_memif(VPPForwarderInterface::sock_,
- &input_params, &output_params);
+ ret = memif_vapi_create_memif(VPPForwarderInterface::sock_, &input_params,
+ &output_params);
if (ret < 0) {
throw errors::RuntimeException(
@@ -94,10 +92,8 @@ void VPPForwarderInterface::consumerConnection() {
output.src6 = &ip6_address;
input.swif = sw_if_index_;
-
-
- int ret = hicn_vapi_register_cons_app(VPPForwarderInterface::sock_,
- &input, &output);
+ int ret = hicn_vapi_register_cons_app(VPPForwarderInterface::sock_, &input,
+ &output);
if (ret < 0) {
throw errors::RuntimeException(hicn_vapi_get_error_string(ret));
@@ -106,7 +102,6 @@ void VPPForwarderInterface::consumerConnection() {
face_id1_ = output.face_id1;
face_id2_ = output.face_id2;
-
std::memcpy(inet_address_.v4.as_u8, output.src4->v4.as_u8, IPV4_ADDR_LEN);
std::memcpy(inet6_address_.v6.as_u8, output.src6->v6.as_u8, IPV6_ADDR_LEN);
@@ -156,8 +151,8 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) {
input.prefix->len = addr.len;
input.cs_reserved = content_store_reserved_;
- int ret = hicn_vapi_register_prod_app(
- VPPForwarderInterface::sock_, &input, &output);
+ int ret = hicn_vapi_register_prod_app(VPPForwarderInterface::sock_, &input,
+ &output);
if (ret < 0) {
throw errors::RuntimeException(hicn_vapi_get_error_string(ret));
@@ -174,8 +169,7 @@ void VPPForwarderInterface::registerRoute(Prefix &prefix) {
params.prefix->len = addr.len;
params.face_id = face_id1_;
- int ret = hicn_vapi_register_route(VPPForwarderInterface::sock_,
- &params);
+ int ret = hicn_vapi_register_route(VPPForwarderInterface::sock_, &params);
if (ret < 0) {
throw errors::RuntimeException(hicn_vapi_get_error_string(ret));
@@ -193,16 +187,15 @@ void VPPForwarderInterface::closeConnection() {
hicn_vapi_face_cons_del(VPPForwarderInterface::sock_, &params);
params.face_id = face_id2_;
hicn_vapi_face_cons_del(VPPForwarderInterface::sock_, &params);
- }
- else {
+ } else {
hicn_del_face_app_input_params params;
params.face_id = face_id1_;
hicn_vapi_face_prod_del(VPPForwarderInterface::sock_, &params);
}
if (sw_if_index_ != uint32_t(~0)) {
- int ret = memif_vapi_delete_memif(VPPForwarderInterface::sock_,
- sw_if_index_);
+ int ret =
+ memif_vapi_delete_memif(VPPForwarderInterface::sock_, sw_if_index_);
if (ret < 0) {
TRANSPORT_LOGE("Error deleting memif with sw idx %u.", sw_if_index_);
}
diff --git a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.h b/libtransport/src/core/vpp_forwarder_interface.h
index 9f8000828..eb759f8bc 100644
--- a/libtransport/src/hicn/transport/core/vpp_forwarder_interface.h
+++ b/libtransport/src/core/vpp_forwarder_interface.h
@@ -19,6 +19,8 @@
#ifdef __vpp__
+#include <hicn/transport/core/prefix.h>
+
#ifdef always_inline
#undef always_inline
#endif
@@ -26,9 +28,8 @@ extern "C" {
#include <vapi/vapi_safe.h>
};
-#include <hicn/transport/core/forwarder_interface.h>
-#include <hicn/transport/core/memif_connector.h>
-#include <hicn/transport/core/prefix.h>
+#include <core/forwarder_interface.h>
+#include <core/memif_connector.h>
#include <deque>
@@ -72,7 +73,7 @@ class VPPForwarderInterface
uint32_t memif_id_;
uint32_t sw_if_index_;
- //A consumer socket in vpp has two faces (ipv4 and ipv6)
+ // A consumer socket in vpp has two faces (ipv4 and ipv6)
uint32_t face_id1_;
uint32_t face_id2_;
bool is_consumer_;
diff --git a/libtransport/src/hicn/transport/http/client_connection.cc b/libtransport/src/hicn/transport/http/client_connection.cc
deleted file mode 100644
index bd21bc448..000000000
--- a/libtransport/src/hicn/transport/http/client_connection.cc
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Copyright (c) 2017-2020 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hicn/transport/http/client_connection.h>
-#include <hicn/transport/utils/hash.h>
-
-#define DEFAULT_BETA 0.99
-#define DEFAULT_GAMMA 0.07
-
-namespace transport {
-
-namespace http {
-
-using namespace transport;
-
-HTTPClientConnection::HTTPClientConnection()
- : consumer_(TransportProtocolAlgorithms::RAAQM),
- read_bytes_callback_(nullptr),
- read_buffer_(nullptr),
- response_(std::make_shared<HTTPResponse>()),
- timer_(nullptr) {
- consumer_.setSocketOption(
- ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY,
- (ConsumerContentObjectVerificationCallback)std::bind(
- &HTTPClientConnection::verifyData, this, std::placeholders::_1,
- std::placeholders::_2));
-
- consumer_.setSocketOption(ConsumerCallbacksOptions::READ_CALLBACK, this);
-
- consumer_.connect();
- std::shared_ptr<typename ConsumerSocket::Portal> portal;
- consumer_.getSocketOption(GeneralTransportOptions::PORTAL, portal);
- timer_ = std::make_unique<asio::steady_timer>(portal->getIoService());
-}
-
-HTTPClientConnection::RC HTTPClientConnection::get(
- const std::string &url, HTTPHeaders headers, HTTPPayload &&payload,
- std::shared_ptr<HTTPResponse> response, ReadBytesCallback *callback,
- std::string ipv6_first_word) {
- return sendRequest(url, HTTPMethod::GET, headers, std::move(payload),
- response, callback, ipv6_first_word);
-}
-
-HTTPClientConnection::RC HTTPClientConnection::sendRequest(
- const std::string &url, HTTPMethod method, HTTPHeaders headers,
- HTTPPayload &&payload, std::shared_ptr<HTTPResponse> response,
- ReadBytesCallback *callback, std::string ipv6_first_word) {
- current_url_ = url;
- read_bytes_callback_ = callback;
- if (!response) {
- response_ = std::make_shared<HTTPResponse>();
- } else {
- response_ = response;
- }
-
- auto start = std::chrono::steady_clock::now();
- request_.init(method, url, headers, std::move(payload));
-
- success_callback_ = [this, method = std::move(method), url = std::move(url),
- start = std::move(start)](std::size_t size) -> void {
- auto end = std::chrono::steady_clock::now();
- TRANSPORT_LOGI(
- "%s %s [%s] duration: %llu [usec] %zu [bytes]\n",
- method_map[method].c_str(), url.c_str(), name_.str().c_str(),
- (unsigned long long)
- std::chrono::duration_cast<std::chrono::microseconds>(end - start)
- .count(),
- size);
- };
-
- sendRequestGetReply(ipv6_first_word);
- return return_code_;
-}
-
-void HTTPClientConnection::sendRequestGetReply(std::string &ipv6_first_word) {
- const std::string &request_string = request_.getRequestString();
- const std::string &locator = request_.getLocator();
-
- // Hash it
-
- uint32_t locator_hash =
- utils::hash::fnv32_buf(locator.c_str(), locator.size());
- uint64_t request_hash =
- utils::hash::fnv64_buf(request_string.c_str(), request_string.size());
-
- consumer_.setSocketOption(
- ConsumerCallbacksOptions::INTEREST_OUTPUT,
- (ConsumerInterestCallback)std::bind(
- &HTTPClientConnection::processLeavingInterest, this,
- std::placeholders::_1, std::placeholders::_2));
-
- // Factor hicn name using hash
- name_.str("");
-
- name_ << ipv6_first_word << ":";
-
- for (uint16_t *word = (uint16_t *)&locator_hash;
- std::size_t(word) < (std::size_t(&locator_hash) + sizeof(locator_hash));
- word++) {
- name_ << ":" << std::hex << *word;
- }
-
- for (uint16_t *word = (uint16_t *)&request_hash;
- std::size_t(word) < (std::size_t(&request_hash) + sizeof(request_hash));
- word++) {
- name_ << ":" << std::hex << *word;
- }
-
- name_ << "|0";
-
- consumer_.consume(Name(name_.str()));
-
- consumer_.stop();
-}
-
-std::shared_ptr<HTTPResponse> HTTPClientConnection::response() {
- response_->coalescePayloadBuffer();
- return response_;
-}
-
-bool HTTPClientConnection::verifyData(
- ConsumerSocket &c, const core::ContentObject &contentObject) {
- if (contentObject.getPayloadType() == PayloadType::CONTENT_OBJECT) {
- TRANSPORT_LOGI("VERIFY CONTENT\n");
- } else if (contentObject.getPayloadType() == PayloadType::MANIFEST) {
- TRANSPORT_LOGI("VERIFY MANIFEST\n");
- }
-
- return true;
-}
-
-void HTTPClientConnection::processLeavingInterest(
- ConsumerSocket &c, const core::Interest &interest) {
- if (interest.payloadSize() == 0) {
- Interest &int2 = const_cast<Interest &>(interest);
- auto payload = request_.getRequestString();
- auto payload2 = request_.getPayload();
- int2.appendPayload((uint8_t *)payload.data(), payload.size());
- if (payload2)
- int2.appendPayload((uint8_t *)payload2->data(), payload2->length());
- }
-}
-
-ConsumerSocket &HTTPClientConnection::getConsumer() { return consumer_; }
-
-HTTPClientConnection &HTTPClientConnection::stop() {
- // This is thread safe and can be called from another thread
- consumer_.stop();
-
- return *this;
-}
-
-HTTPClientConnection &HTTPClientConnection::setTimeout(
- const std::chrono::seconds &timeout) {
- timer_->cancel();
- timer_->expires_from_now(timeout);
- timer_->async_wait([this](std::error_code ec) {
- if (!ec) {
- consumer_.stop();
- }
- });
-
- return *this;
-}
-
-HTTPClientConnection &HTTPClientConnection::setCertificate(
- const std::string &cert_path) {
- if (consumer_.setSocketOption(GeneralTransportOptions::CERTIFICATE,
- cert_path) == SOCKET_OPTION_NOT_SET) {
- throw errors::RuntimeException("Error setting the certificate.");
- }
-
- return *this;
-}
-
-// Read buffer management
-void HTTPClientConnection::readBufferAvailable(
- std::unique_ptr<utils::MemBuf> &&buffer) noexcept {
- if (!read_bytes_callback_) {
- response_->appendResponseChunk(std::move(buffer));
- } else {
- read_bytes_callback_->onBytesReceived(std::move(buffer));
- }
-}
-
-// Read buffer management
-void HTTPClientConnection::readError(const std::error_code ec) noexcept {
- TRANSPORT_LOGE("Error %s during download of %s", ec.message().c_str(),
- current_url_.c_str());
- if (read_bytes_callback_) {
- read_bytes_callback_->onError(ec);
- }
-
- return_code_ = HTTPClientConnection::RC::DOWNLOAD_FAILED;
-}
-
-void HTTPClientConnection::readSuccess(std::size_t total_size) noexcept {
- success_callback_(total_size);
- if (read_bytes_callback_) {
- read_bytes_callback_->onSuccess(total_size);
- }
-
- return_code_ = HTTPClientConnection::RC::DOWNLOAD_SUCCESS;
-}
-
-} // namespace http
-
-} // namespace transport
diff --git a/libtransport/src/hicn/transport/http/server_acceptor.cc b/libtransport/src/hicn/transport/http/server_acceptor.cc
deleted file mode 100644
index e478dfcd4..000000000
--- a/libtransport/src/hicn/transport/http/server_acceptor.cc
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hicn/transport/http/server_acceptor.h>
-#include <hicn/transport/utils/hash.h>
-#include <hicn/transport/utils/uri.h>
-
-namespace transport {
-
-namespace http {
-
-HTTPServerAcceptor::HTTPServerAcceptor(std::string &&server_locator,
- OnHttpRequest callback)
- : HTTPServerAcceptor(server_locator, callback) {}
-
-HTTPServerAcceptor::HTTPServerAcceptor(std::string &server_locator,
- OnHttpRequest callback)
- : callback_(callback) {
- utils::Uri uri;
-
- uri.parseProtocolAndLocator(server_locator);
- std::string protocol = uri.getProtocol();
- std::string locator = uri.getLocator();
-
- std::transform(locator.begin(), locator.end(), locator.begin(), ::tolower);
-
- std::transform(protocol.begin(), protocol.end(), protocol.begin(), ::tolower);
-
- if (protocol != "http") {
- throw errors::RuntimeException(
- "Malformed server_locator. The locator format should be in the form "
- "http://locator");
- }
-
- uint32_t locator_hash =
- utils::hash::fnv32_buf(locator.c_str(), locator.size());
-
- std::stringstream stream;
- stream << std::hex << http::default_values::ipv6_first_word << ":0000";
-
- for (uint16_t *word = (uint16_t *)&locator_hash;
- std::size_t(word) < (std::size_t(&locator_hash) + sizeof(locator_hash));
- word++) {
- stream << ":" << std::hex << *word;
- }
-
- stream << "::0";
-
- std::string network = stream.str();
-
- core::Prefix acceptor_namespace(network, 64);
-
- std::string producer_identity = "acceptor_producer";
- acceptor_producer_ = std::make_shared<ProducerSocket>();
- acceptor_producer_->registerPrefix(acceptor_namespace);
-}
-
-void HTTPServerAcceptor::listen(bool async) {
- acceptor_producer_->setSocketOption(
- ProducerCallbacksOptions::INTEREST_INPUT,
- (ProducerInterestCallback)bind(
- &HTTPServerAcceptor::processIncomingInterest, this,
- std::placeholders::_1, std::placeholders::_2));
- acceptor_producer_->connect();
-
- if (!async) {
- acceptor_producer_->serveForever();
- }
-}
-
-void HTTPServerAcceptor::processIncomingInterest(ProducerSocket &p,
- Interest &interest) {
- // Temporary solution. With
- auto payload = interest.getPayload();
-
- int request_id = utils::hash::fnv32_buf(payload->data(), payload->length());
-
- if (publishers_.find(request_id) != publishers_.end()) {
- if (publishers_[request_id]) {
- publishers_[request_id]->getProducer().onInterest(interest);
- return;
- }
- }
-
- publishers_[request_id] =
- std::make_shared<HTTPServerPublisher>(interest.getName());
- callback_(publishers_[request_id], (uint8_t *)payload->data(),
- payload->length(), request_id);
-}
-
-std::map<int, std::shared_ptr<HTTPServerPublisher>>
- &HTTPServerAcceptor::getPublishers() {
- return publishers_;
-}
-
-} // namespace http
-
-} // namespace transport
diff --git a/libtransport/src/hicn/transport/http/server_acceptor.h b/libtransport/src/hicn/transport/http/server_acceptor.h
deleted file mode 100644
index 6ed58f70e..000000000
--- a/libtransport/src/hicn/transport/http/server_acceptor.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <hicn/transport/http/default_values.h>
-#include <hicn/transport/http/request.h>
-#include <hicn/transport/http/server_publisher.h>
-#include <hicn/transport/interfaces/socket_consumer.h>
-#include <hicn/transport/interfaces/socket_producer.h>
-
-#include <functional>
-#include <vector>
-
-namespace transport {
-
-namespace http {
-
-class HTTPServerAcceptor {
- friend class HTTPServerPublisher;
- using OnHttpRequest =
- std::function<void(std::shared_ptr<HTTPServerPublisher> &,
- const uint8_t *, std::size_t, int request_id)>;
-
- public:
- HTTPServerAcceptor(std::string &&server_locator, OnHttpRequest callback);
- HTTPServerAcceptor(std::string &server_locator, OnHttpRequest callback);
-
- void listen(bool async);
-
- std::map<int, std::shared_ptr<HTTPServerPublisher>> &getPublishers();
-
- // void asyncSendResponse();
-
- // HTTPClientConnection& get(std::string &url, HTTPHeaders headers = {},
- // HTTPPayload payload = {});
- //
- // HTTPResponse&& response();
-
- private:
- void processIncomingInterest(ProducerSocket &p, Interest &interest);
-
- OnHttpRequest callback_;
- std::shared_ptr<ProducerSocket> acceptor_producer_;
-
- std::map<int, std::shared_ptr<HTTPServerPublisher>> publishers_;
-};
-
-} // end namespace http
-
-} // end namespace transport
diff --git a/libtransport/src/hicn/transport/http/server_publisher.cc b/libtransport/src/hicn/transport/http/server_publisher.cc
deleted file mode 100644
index b4deb5333..000000000
--- a/libtransport/src/hicn/transport/http/server_publisher.cc
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hicn/transport/http/server_publisher.h>
-#include <hicn/transport/utils/literals.h>
-
-namespace transport {
-
-namespace http {
-
-HTTPServerPublisher::HTTPServerPublisher(const core::Name &content_name)
- : content_name_(content_name) {
- std::string identity = "acceptor_producer";
- producer_ = std::make_unique<ProducerSocket>();
- // utils::Identity::generateIdentity(identity));
- core::Prefix publisher_prefix(content_name_, 128);
- producer_->registerPrefix(publisher_prefix);
-}
-
-HTTPServerPublisher::~HTTPServerPublisher() {
- if (timer_) {
- this->timer_->cancel();
- }
-}
-
-HTTPServerPublisher &HTTPServerPublisher::attachPublisher() {
- // Create a new publisher
- producer_->setSocketOption(GeneralTransportOptions::DATA_PACKET_SIZE,
- 1410_U32);
- producer_->connect();
- return *this;
-}
-
-HTTPServerPublisher &HTTPServerPublisher::setTimeout(
- const std::chrono::milliseconds &timeout, bool timeout_renewal) {
- std::shared_ptr<typename ProducerSocket::Portal> portal;
- producer_->getSocketOption(GeneralTransportOptions::PORTAL, portal);
- timer_ =
- std::make_unique<asio::steady_timer>(portal->getIoService(), timeout);
-
- wait_callback_ = [this](const std::error_code &e) {
- if (!e) {
- producer_->stop();
- }
- };
-
- if (timeout_renewal) {
- interest_enter_callback_ = [this, timeout](ProducerSocket &p,
- const Interest &interest) {
- this->timer_->cancel();
- this->timer_->expires_from_now(timeout);
- this->timer_->async_wait(wait_callback_);
- };
-
- producer_->setSocketOption(
- ProducerCallbacksOptions::CACHE_HIT,
- (ProducerInterestCallback)interest_enter_callback_);
- }
-
- timer_->async_wait(wait_callback_);
-
- return *this;
-}
-
-void HTTPServerPublisher::publishContent(
- const uint8_t *buf, size_t buffer_size,
- std::chrono::milliseconds content_lifetime, bool is_last) {
- if (producer_) {
- producer_->setSocketOption(
- GeneralTransportOptions::CONTENT_OBJECT_EXPIRY_TIME,
- static_cast<uint32_t>(content_lifetime.count()));
- producer_->produce(content_name_, buf, buffer_size, is_last);
- // producer_->setSocketOption(ProducerCallbacksOptions::CACHE_MISS,
- // [this](ProducerSocket &p, const
- // core::Interest &interest){
- // producer_->stop();
- // });
- }
-}
-
-template <typename Handler>
-void HTTPServerPublisher::asyncPublishContent(
- const uint8_t *buf, size_t buffer_size,
- std::chrono::milliseconds content_lifetime, Handler &&handler,
- bool is_last) {
- if (producer_) {
- producer_->setSocketOption(
- GeneralTransportOptions::CONTENT_OBJECT_EXPIRY_TIME,
- static_cast<uint32_t>(content_lifetime.count()));
- producer_->asyncProduce(content_name_, buf, buffer_size,
- std::forward<Handler>(handler), is_last);
- }
-}
-
-void HTTPServerPublisher::serveClients() { producer_->serveForever(); }
-
-void HTTPServerPublisher::stop() {
- std::shared_ptr<typename ProducerSocket::Portal> portal_ptr;
- producer_->getSocketOption(GeneralTransportOptions::PORTAL, portal_ptr);
- portal_ptr->getIoService().stop();
-}
-
-ProducerSocket &HTTPServerPublisher::getProducer() { return *producer_; }
-
-void HTTPServerPublisher::setPublisherName(std::string &name,
- std::string &mask) {
- // Name represents the last 64 bits of the ipv6 address.
- // It is an ipv6 address with the first 64 bits set to 0
- uint16_t i;
- std::string s = content_name_.toString();
- std::shared_ptr<core::Sockaddr> sockaddr = content_name_.getAddress();
- in6_addr name_ipv6 = ((core::Sockaddr6 *)sockaddr.get())->sin6_addr;
-
- in6_addr bitmask, new_address, _name;
-
- if (inet_pton(AF_INET6, mask.c_str(), &bitmask) != 1) {
- throw errors::RuntimeException("Error during conversion to ipv6 address.");
- }
-
- if (inet_pton(AF_INET6, name.c_str(), &_name) != 1) {
- throw errors::RuntimeException("Error during conversion to ipv6 address.");
- }
-
- for (i = 0; i < sizeof(new_address.s6_addr); i++) {
- new_address.s6_addr[i] = name_ipv6.s6_addr[i] & bitmask.s6_addr[i];
- }
-
- for (i = 0; i < sizeof(new_address.s6_addr); i++) {
- new_address.s6_addr[i] |= _name.s6_addr[i] & ~bitmask.s6_addr[i];
- }
-
- // Effectively change the name
- char str[INET6_ADDRSTRLEN];
- inet_ntop(AF_INET6, &new_address, str, INET6_ADDRSTRLEN);
- std::string str2(str);
-
- core::Name new_name(str2, 0);
-
- // If the new name differs from the one required by the consumer part, send a
- // manifest
- if (!new_name.equals(content_name_, false)) {
- // Publish manifest pointing to the new name
-
- auto manifest =
- std::make_shared<ContentObjectManifest>(content_name_.setSuffix(0));
-
- content_name_ = core::Name(str2, 0);
-
- // manifest->setNameList(content_name_);
- manifest->setLifetime(4000 * 1000);
- manifest->encode();
- producer_->produce(*manifest);
-
- core::Prefix ns(content_name_, 128);
- producer_->registerPrefix(ns);
- }
-}
-
-} // namespace http
-
-} // namespace transport
diff --git a/libtransport/src/hicn/transport/http/server_publisher.h b/libtransport/src/hicn/transport/http/server_publisher.h
deleted file mode 100644
index 33d596f63..000000000
--- a/libtransport/src/hicn/transport/http/server_publisher.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <hicn/transport/http/default_values.h>
-#include <hicn/transport/interfaces/socket_consumer.h>
-#include <hicn/transport/interfaces/socket_producer.h>
-
-#include <functional>
-#include <vector>
-
-namespace transport {
-
-namespace http {
-
-using namespace interface;
-using namespace core;
-
-class HTTPServerPublisher {
- public:
- HTTPServerPublisher(const core::Name &content_name);
-
- ~HTTPServerPublisher();
-
- void publishContent(const uint8_t *buf, size_t buffer_size,
- std::chrono::milliseconds content_lifetime, bool is_last);
-
- template <typename Handler>
- void asyncPublishContent(const uint8_t *buf, size_t buffer_size,
- std::chrono::milliseconds content_lifetime,
- Handler &&handler, bool is_last);
-
- void serveClients();
-
- void stop();
-
- ProducerSocket &getProducer();
-
- HTTPServerPublisher &setTimeout(const std::chrono::milliseconds &timeout,
- bool timeout_renewal);
-
- HTTPServerPublisher &attachPublisher();
-
- void setPublisherName(std::string &name, std::string &mask);
-
- private:
- Name content_name_;
- std::unique_ptr<asio::steady_timer> timer_;
- std::unique_ptr<ProducerSocket> producer_;
- ProducerInterestCallback interest_enter_callback_;
- utils::UserCallback wait_callback_;
-};
-
-} // end namespace http
-
-} // end namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/socket_consumer.cc b/libtransport/src/hicn/transport/interfaces/socket_consumer.cc
deleted file mode 100644
index b2c054947..000000000
--- a/libtransport/src/hicn/transport/interfaces/socket_consumer.cc
+++ /dev/null
@@ -1,862 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hicn/transport/interfaces/socket_consumer.h>
-#include <hicn/transport/protocols/cbr.h>
-#include <hicn/transport/protocols/raaqm.h>
-#include <hicn/transport/protocols/rtc.h>
-
-namespace transport {
-
-namespace interface {
-
-ConsumerSocket::ConsumerSocket(int protocol)
- : ConsumerSocket(protocol, internal_io_service_) {}
-
-ConsumerSocket::ConsumerSocket(int protocol, asio::io_service &io_service)
- : io_service_(io_service),
- portal_(std::make_shared<Portal>(io_service_)),
- async_downloader_(),
- interest_lifetime_(default_values::interest_lifetime),
- min_window_size_(default_values::min_window_size),
- max_window_size_(default_values::max_window_size),
- current_window_size_(-1),
- max_retransmissions_(
- default_values::transport_protocol_max_retransmissions),
- /****** RAAQM Parameters ******/
- minimum_drop_probability_(default_values::minimum_drop_probability),
- sample_number_(default_values::sample_number),
- gamma_(default_values::gamma_value),
- beta_(default_values::beta_value),
- drop_factor_(default_values::drop_factor),
- /****** END RAAQM Parameters ******/
- rate_estimation_alpha_(default_values::rate_alpha),
- rate_estimation_observer_(nullptr),
- rate_estimation_batching_parameter_(default_values::batch),
- rate_estimation_choice_(0),
- verifier_(std::make_shared<utils::Verifier>()),
- verify_signature_(false),
- key_content_(false),
- on_interest_output_(VOID_HANDLER),
- on_interest_timeout_(VOID_HANDLER),
- on_interest_satisfied_(VOID_HANDLER),
- on_content_object_input_(VOID_HANDLER),
- on_content_object_verification_(VOID_HANDLER),
- on_content_object_(VOID_HANDLER),
- on_manifest_(VOID_HANDLER),
- stats_summary_(VOID_HANDLER),
- read_callback_(nullptr),
- virtual_download_(false),
- timer_interval_milliseconds_(0),
- guard_raaqm_params_() {
- switch (protocol) {
- case TransportProtocolAlgorithms::CBR:
- transport_protocol_ = std::make_unique<CbrTransportProtocol>(this);
- break;
- case TransportProtocolAlgorithms::RTC:
- transport_protocol_ = std::make_unique<RTCTransportProtocol>(this);
- break;
- case TransportProtocolAlgorithms::RAAQM:
- default:
- transport_protocol_ = std::make_unique<RaaqmTransportProtocol>(this);
- break;
- }
-}
-
-ConsumerSocket::~ConsumerSocket() {
- stop();
- async_downloader_.stop();
-}
-
-void ConsumerSocket::connect() { portal_->connect(); }
-
-int ConsumerSocket::consume(const Name &name) {
- if (transport_protocol_->isRunning()) {
- return CONSUMER_BUSY;
- }
-
- network_name_ = name;
- network_name_.setSuffix(0);
-
- transport_protocol_->start();
-
- return CONSUMER_FINISHED;
-}
-
-int ConsumerSocket::asyncConsume(const Name &name) {
- if (!async_downloader_.stopped()) {
- async_downloader_.add([this, name]() {
- network_name_ = std::move(name);
- network_name_.setSuffix(0);
- transport_protocol_->start();
- });
- }
-
- return CONSUMER_RUNNING;
-}
-
-bool ConsumerSocket::verifyKeyPackets() {
- return transport_protocol_->verifyKeyPackets();
-}
-
-void ConsumerSocket::stop() {
- if (transport_protocol_) {
- if (transport_protocol_->isRunning()) transport_protocol_->stop();
- }
-}
-
-void ConsumerSocket::resume() {
- if (!transport_protocol_->isRunning()) {
- transport_protocol_->resume();
- }
-}
-
-asio::io_service &ConsumerSocket::getIoService() {
- return portal_->getIoService();
-}
-
-int ConsumerSocket::setSocketOption(int socket_option_key,
- ReadCallback *socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key, ReadCallback *socket_option_value) -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::READ_CALLBACK:
- read_callback_ = socket_option_value;
- break;
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
- });
-}
-
-int ConsumerSocket::getSocketOption(int socket_option_key,
- ReadCallback **socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key, ReadCallback **socket_option_value) -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::READ_CALLBACK:
- *socket_option_value = read_callback_;
- break;
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
- });
-}
-
-int ConsumerSocket::setSocketOption(int socket_option_key,
- double socket_option_value) {
- utils::SpinLock::Acquire locked(guard_raaqm_params_);
- switch (socket_option_key) {
- case MIN_WINDOW_SIZE:
- min_window_size_ = socket_option_value;
- break;
-
- case MAX_WINDOW_SIZE:
- max_window_size_ = socket_option_value;
- break;
-
- case CURRENT_WINDOW_SIZE:
- current_window_size_ = socket_option_value;
- break;
-
- case GAMMA_VALUE:
- gamma_ = socket_option_value;
- break;
-
- case BETA_VALUE:
- beta_ = socket_option_value;
- break;
-
- case DROP_FACTOR:
- drop_factor_ = socket_option_value;
- break;
-
- case MINIMUM_DROP_PROBABILITY:
- minimum_drop_probability_ = socket_option_value;
- break;
-
- case RATE_ESTIMATION_ALPHA:
- if (socket_option_value >= 0 && socket_option_value < 1) {
- rate_estimation_alpha_ = socket_option_value;
- } else {
- rate_estimation_alpha_ = default_values::alpha;
- }
- break;
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
-}
-
-int ConsumerSocket::setSocketOption(int socket_option_key,
- uint32_t socket_option_value) {
- utils::SpinLock::Acquire locked(guard_raaqm_params_);
- switch (socket_option_key) {
- case GeneralTransportOptions::MAX_INTEREST_RETX:
- max_retransmissions_ = socket_option_value;
- break;
-
- case GeneralTransportOptions::INTEREST_LIFETIME:
- interest_lifetime_ = socket_option_value;
- break;
-
- case RateEstimationOptions::RATE_ESTIMATION_BATCH_PARAMETER:
- if (socket_option_value > 0) {
- rate_estimation_batching_parameter_ = socket_option_value;
- } else {
- rate_estimation_batching_parameter_ = default_values::batch;
- }
- break;
-
- case RateEstimationOptions::RATE_ESTIMATION_CHOICE:
- if (socket_option_value > 0) {
- rate_estimation_choice_ = socket_option_value;
- } else {
- rate_estimation_choice_ = default_values::rate_choice;
- }
- break;
-
- case GeneralTransportOptions::STATS_INTERVAL:
- timer_interval_milliseconds_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
-}
-
-int ConsumerSocket::setSocketOption(int socket_option_key,
- std::nullptr_t socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key, std::nullptr_t socket_option_value) -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::INTEREST_RETRANSMISSION:
- if (socket_option_value == VOID_HANDLER) {
- on_interest_retransmission_ = VOID_HANDLER;
- break;
- }
-
- case ConsumerCallbacksOptions::INTEREST_EXPIRED:
- if (socket_option_value == VOID_HANDLER) {
- on_interest_timeout_ = VOID_HANDLER;
- break;
- }
-
- case ConsumerCallbacksOptions::INTEREST_SATISFIED:
- if (socket_option_value == VOID_HANDLER) {
- on_interest_satisfied_ = VOID_HANDLER;
- break;
- }
-
- case ConsumerCallbacksOptions::INTEREST_OUTPUT:
- if (socket_option_value == VOID_HANDLER) {
- on_interest_output_ = VOID_HANDLER;
- break;
- }
-
- case ConsumerCallbacksOptions::CONTENT_OBJECT_INPUT:
- if (socket_option_value == VOID_HANDLER) {
- on_content_object_input_ = VOID_HANDLER;
- break;
- }
-
- case ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY:
- if (socket_option_value == VOID_HANDLER) {
- on_content_object_verification_ = VOID_HANDLER;
- break;
- }
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
- });
-}
-
-int ConsumerSocket::setSocketOption(int socket_option_key,
- bool socket_option_value) {
- int result = SOCKET_OPTION_NOT_SET;
- if (!transport_protocol_->isRunning()) {
- switch (socket_option_key) {
- case OtherOptions::VIRTUAL_DOWNLOAD:
- virtual_download_ = socket_option_value;
- result = SOCKET_OPTION_SET;
- break;
-
- case GeneralTransportOptions::VERIFY_SIGNATURE:
- verify_signature_ = socket_option_value;
- result = SOCKET_OPTION_SET;
- break;
-
- case GeneralTransportOptions::KEY_CONTENT:
- key_content_ = socket_option_value;
- result = SOCKET_OPTION_SET;
- break;
-
- default:
- return result;
- }
- }
- return result;
-}
-
-int ConsumerSocket::setSocketOption(
- int socket_option_key, ConsumerContentObjectCallback socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ConsumerContentObjectCallback socket_option_value) -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::CONTENT_OBJECT_INPUT:
- on_content_object_input_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
- });
-}
-
-int ConsumerSocket::setSocketOption(
- int socket_option_key,
- ConsumerContentObjectVerificationCallback socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ConsumerContentObjectVerificationCallback socket_option_value)
- -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY:
- on_content_object_verification_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
- });
-}
-
-int ConsumerSocket::setSocketOption(
- int socket_option_key, ConsumerInterestCallback socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ConsumerInterestCallback socket_option_value) -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::INTEREST_RETRANSMISSION:
- on_interest_retransmission_ = socket_option_value;
- break;
-
- case ConsumerCallbacksOptions::INTEREST_OUTPUT:
- on_interest_output_ = socket_option_value;
- break;
-
- case ConsumerCallbacksOptions::INTEREST_EXPIRED:
- on_interest_timeout_ = socket_option_value;
- break;
-
- case ConsumerCallbacksOptions::INTEREST_SATISFIED:
- on_interest_satisfied_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
- });
-}
-
-int ConsumerSocket::setSocketOption(
- int socket_option_key, ConsumerManifestCallback socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ConsumerManifestCallback socket_option_value) -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::MANIFEST_INPUT:
- on_manifest_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
- });
-}
-
-int ConsumerSocket::setSocketOption(
- int socket_option_key,
- ConsumerContentObjectVerificationFailedCallback socket_option_value) {
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](
- int socket_option_key,
- ConsumerContentObjectVerificationFailedCallback socket_option_value)
- -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::VERIFICATION_FAILED:
- verification_failed_callback_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
- });
-}
-
-int ConsumerSocket::setSocketOption(int socket_option_key,
- IcnObserver *socket_option_value) {
- utils::SpinLock::Acquire locked(guard_raaqm_params_);
- switch (socket_option_key) {
- case RateEstimationOptions::RATE_ESTIMATION_OBSERVER:
- rate_estimation_observer_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
-}
-
-int ConsumerSocket::setSocketOption(
- int socket_option_key,
- const std::shared_ptr<utils::Verifier> &socket_option_value) {
- int result = SOCKET_OPTION_NOT_SET;
- if (!transport_protocol_->isRunning()) {
- switch (socket_option_key) {
- case GeneralTransportOptions::VERIFIER:
- verifier_.reset();
- verifier_ = socket_option_value;
- result = SOCKET_OPTION_SET;
- break;
- default:
- return result;
- }
- }
-
- return result;
-}
-
-int ConsumerSocket::setSocketOption(int socket_option_key,
- const std::string &socket_option_value) {
- int result = SOCKET_OPTION_NOT_SET;
- if (!transport_protocol_->isRunning()) {
- switch (socket_option_key) {
- case GeneralTransportOptions::CERTIFICATE:
- key_id_ = verifier_->addKeyFromCertificate(socket_option_value);
- if (key_id_ != nullptr) result = SOCKET_OPTION_SET;
- break;
-
- case DataLinkOptions::OUTPUT_INTERFACE:
- output_interface_ = socket_option_value;
- portal_->setOutputInterface(output_interface_);
- result = SOCKET_OPTION_SET;
- break;
-
- default:
- return result;
- }
- }
- return result;
-}
-
-int ConsumerSocket::setSocketOption(int socket_option_key,
- ConsumerTimerCallback socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ConsumerTimerCallback socket_option_value) -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::STATS_SUMMARY:
- stats_summary_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
- });
-}
-
-int ConsumerSocket::getSocketOption(int socket_option_key,
- double &socket_option_value) {
- utils::SpinLock::Acquire locked(guard_raaqm_params_);
- switch (socket_option_key) {
- case GeneralTransportOptions::MIN_WINDOW_SIZE:
- socket_option_value = min_window_size_;
- break;
-
- case GeneralTransportOptions::MAX_WINDOW_SIZE:
- socket_option_value = max_window_size_;
- break;
-
- case GeneralTransportOptions::CURRENT_WINDOW_SIZE:
- socket_option_value = current_window_size_;
- break;
-
- // RAAQM parameters
-
- case RaaqmTransportOptions::GAMMA_VALUE:
- socket_option_value = gamma_;
- break;
-
- case RaaqmTransportOptions::BETA_VALUE:
- socket_option_value = beta_;
- break;
-
- case RaaqmTransportOptions::DROP_FACTOR:
- socket_option_value = drop_factor_;
- break;
-
- case RaaqmTransportOptions::MINIMUM_DROP_PROBABILITY:
- socket_option_value = minimum_drop_probability_;
- break;
-
- case RateEstimationOptions::RATE_ESTIMATION_ALPHA:
- socket_option_value = rate_estimation_alpha_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ConsumerSocket::getSocketOption(int socket_option_key,
- uint32_t &socket_option_value) {
- utils::SpinLock::Acquire locked(guard_raaqm_params_);
- switch (socket_option_key) {
- case GeneralTransportOptions::MAX_INTEREST_RETX:
- socket_option_value = max_retransmissions_;
- break;
-
- case GeneralTransportOptions::INTEREST_LIFETIME:
- socket_option_value = interest_lifetime_;
- break;
-
- case RaaqmTransportOptions::SAMPLE_NUMBER:
- socket_option_value = sample_number_;
- break;
-
- case RateEstimationOptions::RATE_ESTIMATION_BATCH_PARAMETER:
- socket_option_value = rate_estimation_batching_parameter_;
- break;
-
- case RateEstimationOptions::RATE_ESTIMATION_CHOICE:
- socket_option_value = rate_estimation_choice_;
- break;
-
- case GeneralTransportOptions::STATS_INTERVAL:
- socket_option_value = timer_interval_milliseconds_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ConsumerSocket::getSocketOption(int socket_option_key,
- bool &socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::RUNNING:
- socket_option_value = transport_protocol_->isRunning();
- break;
-
- case OtherOptions::VIRTUAL_DOWNLOAD:
- socket_option_value = virtual_download_;
- break;
-
- case GeneralTransportOptions::VERIFY_SIGNATURE:
- socket_option_value = verify_signature_;
- break;
-
- case GeneralTransportOptions::KEY_CONTENT:
- socket_option_value = key_content_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ConsumerSocket::getSocketOption(int socket_option_key,
- Name **socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::NETWORK_NAME:
- *socket_option_value = &network_name_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ConsumerSocket::getSocketOption(
- int socket_option_key,
- ConsumerContentObjectCallback **socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ConsumerContentObjectCallback **socket_option_value) -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::CONTENT_OBJECT_INPUT:
- *socket_option_value = &on_content_object_input_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
- });
-}
-
-int ConsumerSocket::getSocketOption(
- int socket_option_key,
- ConsumerContentObjectVerificationCallback **socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ConsumerContentObjectVerificationCallback **socket_option_value)
- -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY:
- *socket_option_value = &on_content_object_verification_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
- });
-}
-
-int ConsumerSocket::getSocketOption(
- int socket_option_key, ConsumerInterestCallback **socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ConsumerInterestCallback **socket_option_value) -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::INTEREST_RETRANSMISSION:
- *socket_option_value = &on_interest_retransmission_;
- break;
-
- case ConsumerCallbacksOptions::INTEREST_OUTPUT:
- *socket_option_value = &on_interest_output_;
- break;
-
- case ConsumerCallbacksOptions::INTEREST_EXPIRED:
- *socket_option_value = &on_interest_timeout_;
- break;
-
- case ConsumerCallbacksOptions::INTEREST_SATISFIED:
- *socket_option_value = &on_interest_satisfied_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
- });
-}
-
-int ConsumerSocket::getSocketOption(
- int socket_option_key, ConsumerManifestCallback **socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ConsumerManifestCallback **socket_option_value) -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::MANIFEST_INPUT:
- *socket_option_value = &on_manifest_;
- break;
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
- });
-}
-
-int ConsumerSocket::getSocketOption(
- int socket_option_key,
- ConsumerContentObjectVerificationFailedCallback **socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](
- int socket_option_key,
- ConsumerContentObjectVerificationFailedCallback **socket_option_value)
- -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::VERIFICATION_FAILED:
- *socket_option_value = &verification_failed_callback_;
- break;
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
- });
-}
-
-int ConsumerSocket::getSocketOption(
- int socket_option_key, std::shared_ptr<Portal> &socket_option_value) {
- switch (socket_option_key) {
- case PORTAL:
- socket_option_value = portal_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ConsumerSocket::getSocketOption(int socket_option_key,
- IcnObserver **socket_option_value) {
- utils::SpinLock::Acquire locked(guard_raaqm_params_);
- switch (socket_option_key) {
- case RateEstimationOptions::RATE_ESTIMATION_OBSERVER:
- *socket_option_value = (rate_estimation_observer_);
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ConsumerSocket::getSocketOption(
- int socket_option_key,
- std::shared_ptr<utils::Verifier> &socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::VERIFIER:
- socket_option_value = verifier_;
- break;
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ConsumerSocket::getSocketOption(int socket_option_key,
- std::string &socket_option_value) {
- switch (socket_option_key) {
- case DataLinkOptions::OUTPUT_INTERFACE:
- socket_option_value = output_interface_;
- break;
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ConsumerSocket::getSocketOption(int socket_option_key,
- TransportStatistics **socket_option_value) {
- switch (socket_option_key) {
- case OtherOptions::STATISTICS:
- *socket_option_value = &stats_;
- break;
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ConsumerSocket::getSocketOption(
- int socket_option_key, ConsumerTimerCallback **socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ConsumerTimerCallback **socket_option_value) -> int {
- switch (socket_option_key) {
- case ConsumerCallbacksOptions::STATS_SUMMARY:
- *socket_option_value = &stats_summary_;
- break;
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
- });
-}
-
-} // namespace interface
-
-} // namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/socket_producer.cc b/libtransport/src/hicn/transport/interfaces/socket_producer.cc
deleted file mode 100644
index 26a7208b6..000000000
--- a/libtransport/src/hicn/transport/interfaces/socket_producer.cc
+++ /dev/null
@@ -1,909 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hicn/transport/interfaces/socket_producer.h>
-#include <hicn/transport/utils/signer.h>
-
-#include <functional>
-
-namespace transport {
-
-namespace interface {
-
-namespace details {}
-
-typedef std::chrono::time_point<std::chrono::steady_clock> Time;
-typedef std::chrono::microseconds TimeDuration;
-
-ProducerSocket::ProducerSocket() : ProducerSocket(internal_io_service_) {}
-
-ProducerSocket::ProducerSocket(asio::io_service &io_service)
- : io_service_(io_service),
- portal_(std::make_shared<Portal>(io_service_)),
- data_packet_size_(default_values::content_object_packet_size),
- content_object_expiry_time_(default_values::content_object_expiry_time),
- output_buffer_(default_values::producer_socket_output_buffer_size),
- async_thread_(),
- registration_status_(REGISTRATION_NOT_ATTEMPTED),
- making_manifest_(false),
- hash_algorithm_(HashAlgorithm::SHA_256),
- suffix_strategy_(core::NextSegmentCalculationStrategy::INCREMENTAL),
- on_interest_input_(VOID_HANDLER),
- on_interest_dropped_input_buffer_(VOID_HANDLER),
- on_interest_inserted_input_buffer_(VOID_HANDLER),
- on_interest_satisfied_output_buffer_(VOID_HANDLER),
- on_interest_process_(VOID_HANDLER),
- on_new_segment_(VOID_HANDLER),
- on_content_object_to_sign_(VOID_HANDLER),
- on_content_object_in_output_buffer_(VOID_HANDLER),
- on_content_object_output_(VOID_HANDLER),
- on_content_object_evicted_from_output_buffer_(VOID_HANDLER),
- on_content_produced_(VOID_HANDLER) {}
-
-ProducerSocket::~ProducerSocket() {
- stop();
- if (listening_thread_.joinable()) {
- listening_thread_.join();
- }
-}
-
-void ProducerSocket::connect() {
- portal_->connect(false);
- listening_thread_ = std::thread(std::bind(&ProducerSocket::listen, this));
-}
-
-void ProducerSocket::serveForever() {
- if (listening_thread_.joinable()) {
- listening_thread_.join();
- }
-}
-
-void ProducerSocket::stop() { portal_->stopEventsLoop(); }
-
-void ProducerSocket::registerPrefix(const Prefix &producer_namespace) {
- served_namespaces_.push_back(producer_namespace);
-}
-
-void ProducerSocket::listen() {
- registration_status_ = REGISTRATION_IN_PROGRESS;
- bool first = true;
-
- for (core::Prefix &producer_namespace : served_namespaces_) {
- if (first) {
- core::BindConfig bind_config(producer_namespace, 1000);
- portal_->bind(bind_config);
- portal_->setProducerCallback(this);
- first = !first;
- } else {
- portal_->registerRoute(producer_namespace);
- }
- }
-
- portal_->runEventsLoop();
-}
-
-void ProducerSocket::passContentObjectToCallbacks(
- const std::shared_ptr<ContentObject> &content_object) {
- if (content_object) {
- io_service_.dispatch([this, content_object]() {
- if (on_new_segment_) {
- on_new_segment_(*this, *content_object);
- }
-
- if (on_content_object_to_sign_) {
- on_content_object_to_sign_(*this, *content_object);
- }
-
- if (on_content_object_in_output_buffer_) {
- on_content_object_in_output_buffer_(*this, *content_object);
- }
- });
-
- output_buffer_.insert(content_object);
-
- io_service_.dispatch([this, content_object]() {
- if (on_content_object_output_) {
- on_content_object_output_(*this, *content_object);
- }
- });
-
- portal_->sendContentObject(*content_object);
- }
-}
-
-void ProducerSocket::produce(ContentObject &content_object) {
- io_service_.dispatch([this, &content_object]() {
- if (on_content_object_in_output_buffer_) {
- on_content_object_in_output_buffer_(*this, content_object);
- }
- });
-
- output_buffer_.insert(std::static_pointer_cast<ContentObject>(
- content_object.shared_from_this()));
-
- io_service_.dispatch([this, &content_object]() {
- if (on_content_object_output_) {
- on_content_object_output_(*this, content_object);
- }
- });
-
- portal_->sendContentObject(content_object);
-}
-
-uint32_t ProducerSocket::produce(Name content_name,
- std::unique_ptr<utils::MemBuf> &&buffer,
- bool is_last, uint32_t start_offset) {
- if (TRANSPORT_EXPECT_FALSE(buffer->length() == 0)) {
- return 0;
- }
-
- // Copy the atomic variables to ensure they keep the same value
- // during the production
- std::size_t data_packet_size = data_packet_size_;
- uint32_t content_object_expiry_time = content_object_expiry_time_;
- HashAlgorithm hash_algo = hash_algorithm_;
- bool making_manifest = making_manifest_;
- auto suffix_strategy = utils::SuffixStrategyFactory::getSuffixStrategy(
- suffix_strategy_, start_offset);
- std::shared_ptr<utils::Signer> signer;
- getSocketOption(GeneralTransportOptions::SIGNER, signer);
-
- auto buffer_size = buffer->length();
- int bytes_segmented = 0;
- std::size_t header_size;
- std::size_t manifest_header_size = 0;
- std::size_t signature_length = 0;
- std::uint32_t final_block_number = start_offset;
- uint64_t free_space_for_content = 0;
-
- core::Packet::Format format;
- std::shared_ptr<ContentObjectManifest> manifest;
- bool is_last_manifest = false;
-
- // TODO Manifest may still be used for indexing
- if (making_manifest && !signer) {
- TRANSPORT_LOGD("Making manifests without setting producer identity.");
- }
-
- core::Packet::Format hf_format = core::Packet::Format::HF_UNSPEC;
- core::Packet::Format hf_format_ah = core::Packet::Format::HF_UNSPEC;
- if (content_name.getType() == HNT_CONTIGUOUS_V4 ||
- content_name.getType() == HNT_IOV_V4) {
- hf_format = core::Packet::Format::HF_INET_TCP;
- hf_format_ah = core::Packet::Format::HF_INET_TCP_AH;
- } else if (content_name.getType() == HNT_CONTIGUOUS_V6 ||
- content_name.getType() == HNT_IOV_V6) {
- hf_format = core::Packet::Format::HF_INET6_TCP;
- hf_format_ah = core::Packet::Format::HF_INET6_TCP_AH;
- } else {
- throw errors::RuntimeException("Unknown name format.");
- }
-
- format = hf_format;
- if (making_manifest) {
- manifest_header_size = core::Packet::getHeaderSizeFromFormat(
- signer ? hf_format_ah : hf_format,
- signer ? signer->getSignatureLength() : 0);
- } else if (signer) {
- format = hf_format_ah;
- signature_length = signer->getSignatureLength();
- }
-
- header_size = core::Packet::getHeaderSizeFromFormat(format, signature_length);
- free_space_for_content = data_packet_size - header_size;
- uint32_t number_of_segments =
- uint32_t(std::ceil(double(buffer_size) / double(free_space_for_content)));
- if (free_space_for_content * number_of_segments < buffer_size) {
- number_of_segments++;
- }
-
- // TODO allocate space for all the headers
- if (making_manifest) {
- uint32_t segment_in_manifest = static_cast<uint32_t>(
- std::floor(double(data_packet_size - manifest_header_size -
- ContentObjectManifest::getManifestHeaderSize()) /
- ContentObjectManifest::getManifestEntrySize()) -
- 1.0);
- uint32_t number_of_manifests = static_cast<uint32_t>(
- std::ceil(float(number_of_segments) / segment_in_manifest));
- final_block_number += number_of_segments + number_of_manifests - 1;
-
- manifest.reset(ContentObjectManifest::createManifest(
- content_name.setSuffix(suffix_strategy->getNextManifestSuffix()),
- core::ManifestVersion::VERSION_1, core::ManifestType::INLINE_MANIFEST,
- hash_algo, is_last_manifest, content_name, suffix_strategy_,
- signer ? signer->getSignatureLength() : 0));
- manifest->setLifetime(content_object_expiry_time);
-
- if (is_last) {
- manifest->setFinalBlockNumber(final_block_number);
- } else {
- manifest->setFinalBlockNumber(utils::SuffixStrategy::INVALID_SUFFIX);
- }
- }
-
- TRANSPORT_LOGD("--------- START PRODUCE ----------");
- for (unsigned int packaged_segments = 0;
- packaged_segments < number_of_segments; packaged_segments++) {
- if (making_manifest) {
- if (manifest->estimateManifestSize(2) >
- data_packet_size - manifest_header_size) {
- // Send the current manifest
- manifest->encode();
-
- // If identity set, sign manifest
- if (signer) {
- signer->sign(*manifest);
- }
-
- passContentObjectToCallbacks(manifest);
- TRANSPORT_LOGD("Send manifest %u", manifest->getName().getSuffix());
-
- // Send content objects stored in the queue
- while (!content_queue_.empty()) {
- passContentObjectToCallbacks(content_queue_.front());
- TRANSPORT_LOGD("Send content %u",
- content_queue_.front()->getName().getSuffix());
- content_queue_.pop();
- }
-
- // Create new manifest. The reference to the last manifest has been
- // acquired in the passContentObjectToCallbacks function, so we can
- // safely release this reference
- manifest.reset(ContentObjectManifest::createManifest(
- content_name.setSuffix(suffix_strategy->getNextManifestSuffix()),
- core::ManifestVersion::VERSION_1,
- core::ManifestType::INLINE_MANIFEST, hash_algo, is_last_manifest,
- content_name, suffix_strategy_,
- signer ? signer->getSignatureLength() : 0));
-
- manifest->setLifetime(content_object_expiry_time);
- manifest->setFinalBlockNumber(
- is_last ? final_block_number
- : utils::SuffixStrategy::INVALID_SUFFIX);
- }
- }
-
- auto content_suffix = suffix_strategy->getNextContentSuffix();
- auto content_object = std::make_shared<ContentObject>(
- content_name.setSuffix(content_suffix), format);
- content_object->setLifetime(content_object_expiry_time);
-
- auto b = buffer->cloneOne();
- b->trimStart(free_space_for_content * packaged_segments);
- b->trimEnd(b->length());
-
- if (TRANSPORT_EXPECT_FALSE(packaged_segments == number_of_segments - 1)) {
- b->append(buffer_size - bytes_segmented);
- bytes_segmented += (int)(buffer_size - bytes_segmented);
-
- if (is_last && making_manifest) {
- is_last_manifest = true;
- } else if (is_last) {
- content_object->setRst();
- }
-
- } else {
- b->append(free_space_for_content);
- bytes_segmented += (int)(free_space_for_content);
- }
-
- content_object->appendPayload(std::move(b));
-
- if (making_manifest) {
- using namespace std::chrono_literals;
- utils::CryptoHash hash = content_object->computeDigest(hash_algo);
- manifest->addSuffixHash(content_suffix, hash);
- content_queue_.push(content_object);
- } else {
- if (signer) {
- signer->sign(*content_object);
- }
- passContentObjectToCallbacks(content_object);
- TRANSPORT_LOGD("Send content %u", content_object->getName().getSuffix());
- }
- }
-
- if (making_manifest) {
- if (is_last_manifest) {
- manifest->setFinalManifest(is_last_manifest);
- }
-
- manifest->encode();
- if (signer) {
- signer->sign(*manifest);
- }
-
- passContentObjectToCallbacks(manifest);
- TRANSPORT_LOGD("Send manifest %u", manifest->getName().getSuffix());
- while (!content_queue_.empty()) {
- passContentObjectToCallbacks(content_queue_.front());
- TRANSPORT_LOGD("Send content %u",
- content_queue_.front()->getName().getSuffix());
- content_queue_.pop();
- }
- }
-
- io_service_.dispatch([this, buffer_size]() {
- if (on_content_produced_) {
- on_content_produced_(*this, std::make_error_code(std::errc(0)),
- buffer_size);
- }
- });
-
- TRANSPORT_LOGD("--------- END PRODUCE ------------");
- return suffix_strategy->getTotalCount();
-}
-
-void ProducerSocket::asyncProduce(ContentObject &content_object) {
- if (!async_thread_.stopped()) {
- auto co_ptr = std::static_pointer_cast<ContentObject>(
- content_object.shared_from_this());
- async_thread_.add([this, content_object = std::move(co_ptr)]() {
- ProducerSocket::produce(*content_object);
- });
- }
-}
-
-void ProducerSocket::asyncProduce(const Name &suffix, const uint8_t *buf,
- size_t buffer_size, bool is_last,
- uint32_t *start_offset) {
- if (!async_thread_.stopped()) {
- async_thread_.add([this, suffix, buffer = buf, size = buffer_size, is_last,
- start_offset]() {
- if (start_offset != NULL) {
- *start_offset = ProducerSocket::produce(suffix, buffer, size, is_last,
- *start_offset);
- } else {
- ProducerSocket::produce(suffix, buffer, size, is_last, 0);
- }
- });
- }
-}
-
-void ProducerSocket::asyncProduce(Name content_name,
- std::unique_ptr<utils::MemBuf> &&buffer,
- bool is_last, uint32_t offset,
- uint32_t **last_segment) {
- if (!async_thread_.stopped()) {
- auto a = buffer.release();
- async_thread_.add([this, content_name, a, is_last, offset, last_segment]() {
- auto buf = std::unique_ptr<utils::MemBuf>(a);
- if (last_segment != NULL) {
- **last_segment =
- offset + ProducerSocket::produce(content_name, std::move(buf),
- is_last, offset);
- } else {
- ProducerSocket::produce(content_name, std::move(buf), is_last, offset);
- }
- });
- }
-}
-
-void ProducerSocket::onInterest(Interest &interest) {
- if (on_interest_input_) {
- on_interest_input_(*this, interest);
- }
-
- const std::shared_ptr<ContentObject> content_object =
- output_buffer_.find(interest);
-
- if (content_object) {
- if (on_interest_satisfied_output_buffer_) {
- on_interest_satisfied_output_buffer_(*this, interest);
- }
-
- if (on_content_object_output_) {
- on_content_object_output_(*this, *content_object);
- }
-
- portal_->sendContentObject(*content_object);
- } else {
- if (on_interest_process_) {
- on_interest_process_(*this, interest);
- }
- }
-}
-
-int ProducerSocket::setSocketOption(int socket_option_key,
- uint32_t socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::DATA_PACKET_SIZE:
- if (socket_option_value < default_values::max_content_object_size &&
- socket_option_value > 0) {
- data_packet_size_ = socket_option_value;
- }
- break;
-
- case GeneralTransportOptions::OUTPUT_BUFFER_SIZE:
- output_buffer_.setLimit(socket_option_value);
- break;
-
- case GeneralTransportOptions::CONTENT_OBJECT_EXPIRY_TIME:
- content_object_expiry_time_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
-}
-
-int ProducerSocket::setSocketOption(int socket_option_key,
- std::nullptr_t socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ProducerContentObjectCallback socket_option_value) -> int {
- switch (socket_option_key) {
- case ProducerCallbacksOptions::INTEREST_INPUT:
- if (socket_option_value == VOID_HANDLER) {
- on_interest_input_ = VOID_HANDLER;
- break;
- }
-
- case ProducerCallbacksOptions::INTEREST_DROP:
- if (socket_option_value == VOID_HANDLER) {
- on_interest_dropped_input_buffer_ = VOID_HANDLER;
- break;
- }
-
- case ProducerCallbacksOptions::INTEREST_PASS:
- if (socket_option_value == VOID_HANDLER) {
- on_interest_inserted_input_buffer_ = VOID_HANDLER;
- break;
- }
-
- case ProducerCallbacksOptions::CACHE_HIT:
- if (socket_option_value == VOID_HANDLER) {
- on_interest_satisfied_output_buffer_ = VOID_HANDLER;
- break;
- }
-
- case ProducerCallbacksOptions::CACHE_MISS:
- if (socket_option_value == VOID_HANDLER) {
- on_interest_process_ = VOID_HANDLER;
- break;
- }
-
- case ProducerCallbacksOptions::NEW_CONTENT_OBJECT:
- if (socket_option_value == VOID_HANDLER) {
- on_new_segment_ = VOID_HANDLER;
- break;
- }
-
- case ProducerCallbacksOptions::CONTENT_OBJECT_SIGN:
- if (socket_option_value == VOID_HANDLER) {
- on_content_object_to_sign_ = VOID_HANDLER;
- break;
- }
-
- case ProducerCallbacksOptions::CONTENT_OBJECT_READY:
- if (socket_option_value == VOID_HANDLER) {
- on_content_object_in_output_buffer_ = VOID_HANDLER;
- break;
- }
-
- case ProducerCallbacksOptions::CONTENT_OBJECT_OUTPUT:
- if (socket_option_value == VOID_HANDLER) {
- on_content_object_output_ = VOID_HANDLER;
- break;
- }
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
- });
-}
-
-int ProducerSocket::setSocketOption(int socket_option_key,
- bool socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::MAKE_MANIFEST:
- making_manifest_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
-}
-
-int ProducerSocket::setSocketOption(int socket_option_key,
- Name *socket_option_value) {
- return SOCKET_OPTION_NOT_SET;
-}
-
-int ProducerSocket::setSocketOption(int socket_option_key,
- std::list<Prefix> socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::NETWORK_NAME:
- served_namespaces_ = socket_option_value;
- break;
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
-}
-
-int ProducerSocket::setSocketOption(
- int socket_option_key, ProducerContentObjectCallback socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ProducerContentObjectCallback socket_option_value) -> int {
- switch (socket_option_key) {
- case ProducerCallbacksOptions::NEW_CONTENT_OBJECT:
- on_new_segment_ = socket_option_value;
- break;
-
- case ProducerCallbacksOptions::CONTENT_OBJECT_SIGN:
- on_content_object_to_sign_ = socket_option_value;
- break;
-
- case ProducerCallbacksOptions::CONTENT_OBJECT_READY:
- on_content_object_in_output_buffer_ = socket_option_value;
- break;
-
- case ProducerCallbacksOptions::CONTENT_OBJECT_OUTPUT:
- on_content_object_output_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
- });
-}
-
-int ProducerSocket::setSocketOption(
- int socket_option_key, ProducerInterestCallback socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ProducerInterestCallback socket_option_value) -> int {
- switch (socket_option_key) {
- case ProducerCallbacksOptions::INTEREST_INPUT:
- on_interest_input_ = socket_option_value;
- break;
-
- case ProducerCallbacksOptions::INTEREST_DROP:
- on_interest_dropped_input_buffer_ = socket_option_value;
- break;
-
- case ProducerCallbacksOptions::INTEREST_PASS:
- on_interest_inserted_input_buffer_ = socket_option_value;
- break;
-
- case ProducerCallbacksOptions::CACHE_HIT:
- on_interest_satisfied_output_buffer_ = socket_option_value;
- break;
-
- case ProducerCallbacksOptions::CACHE_MISS:
- on_interest_process_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
- });
-}
-
-int ProducerSocket::setSocketOption(
- int socket_option_key, ProducerContentCallback socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ProducerContentCallback socket_option_value) -> int {
- switch (socket_option_key) {
- case ProducerCallbacksOptions::CONTENT_PRODUCED:
- on_content_produced_ = socket_option_value;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
- });
-}
-
-int ProducerSocket::setSocketOption(int socket_option_key,
- HashAlgorithm socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::HASH_ALGORITHM:
- hash_algorithm_ = socket_option_value;
- break;
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
-}
-
-int ProducerSocket::setSocketOption(int socket_option_key,
- utils::CryptoSuite socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::CRYPTO_SUITE:
- crypto_suite_ = socket_option_value;
- break;
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
-}
-
-int ProducerSocket::setSocketOption(
- int socket_option_key,
- const std::shared_ptr<utils::Signer> &socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::SIGNER: {
- utils::SpinLock::Acquire locked(signer_lock_);
- signer_.reset();
- signer_ = socket_option_value;
- } break;
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
-}
-
-int ProducerSocket::setSocketOption(int socket_option_key,
- const std::string &socket_option_value) {
- switch (socket_option_key) {
- case DataLinkOptions::OUTPUT_INTERFACE:
- output_interface_ = socket_option_value;
- portal_->setOutputInterface(output_interface_);
- break;
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_SET;
-}
-
-int ProducerSocket::getSocketOption(int socket_option_key,
- uint32_t &socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::OUTPUT_BUFFER_SIZE:
- socket_option_value = (uint32_t)output_buffer_.getLimit();
- break;
-
- case GeneralTransportOptions::DATA_PACKET_SIZE:
- socket_option_value = (uint32_t)data_packet_size_;
- break;
-
- case GeneralTransportOptions::CONTENT_OBJECT_EXPIRY_TIME:
- socket_option_value = content_object_expiry_time_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_SET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ProducerSocket::getSocketOption(int socket_option_key,
- bool &socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::MAKE_MANIFEST:
- socket_option_value = making_manifest_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ProducerSocket::getSocketOption(int socket_option_key,
- std::list<Prefix> &socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::NETWORK_NAME:
- socket_option_value = served_namespaces_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ProducerSocket::getSocketOption(
- int socket_option_key,
- ProducerContentObjectCallback **socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ProducerContentObjectCallback **socket_option_value) -> int {
- switch (socket_option_key) {
- case ProducerCallbacksOptions::NEW_CONTENT_OBJECT:
- *socket_option_value = &on_new_segment_;
- break;
-
- case ProducerCallbacksOptions::CONTENT_OBJECT_SIGN:
- *socket_option_value = &on_content_object_to_sign_;
- break;
-
- case ProducerCallbacksOptions::CONTENT_OBJECT_READY:
- *socket_option_value = &on_content_object_in_output_buffer_;
- break;
-
- case ProducerCallbacksOptions::CONTENT_OBJECT_OUTPUT:
- *socket_option_value = &on_content_object_output_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
- });
-}
-
-int ProducerSocket::getSocketOption(
- int socket_option_key, ProducerContentCallback **socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ProducerContentCallback **socket_option_value) -> int {
- switch (socket_option_key) {
- case ProducerCallbacksOptions::CONTENT_PRODUCED:
- *socket_option_value = &on_content_produced_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
- });
-}
-
-int ProducerSocket::getSocketOption(
- int socket_option_key, ProducerInterestCallback **socket_option_value) {
- // Reschedule the function on the io_service to avoid race condition in case
- // setSocketOption is called while the io_service is running.
- return rescheduleOnIOService(
- socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ProducerInterestCallback **socket_option_value) -> int {
- switch (socket_option_key) {
- case ProducerCallbacksOptions::INTEREST_INPUT:
- *socket_option_value = &on_interest_input_;
- break;
-
- case ProducerCallbacksOptions::INTEREST_DROP:
- *socket_option_value = &on_interest_dropped_input_buffer_;
- break;
-
- case ProducerCallbacksOptions::INTEREST_PASS:
- *socket_option_value = &on_interest_inserted_input_buffer_;
- break;
-
- case CACHE_HIT:
- *socket_option_value = &on_interest_satisfied_output_buffer_;
- break;
-
- case CACHE_MISS:
- *socket_option_value = &on_interest_process_;
- break;
-
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
- });
-}
-
-int ProducerSocket::getSocketOption(
- int socket_option_key, std::shared_ptr<Portal> &socket_option_value) {
- switch (socket_option_key) {
- case PORTAL:
- socket_option_value = portal_;
- break;
- default:
- return SOCKET_OPTION_NOT_GET;
- ;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ProducerSocket::getSocketOption(int socket_option_key,
- HashAlgorithm &socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::HASH_ALGORITHM:
- socket_option_value = hash_algorithm_;
- break;
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ProducerSocket::getSocketOption(int socket_option_key,
- utils::CryptoSuite &socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::HASH_ALGORITHM:
- socket_option_value = crypto_suite_;
- break;
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ProducerSocket::getSocketOption(
- int socket_option_key,
- std::shared_ptr<utils::Signer> &socket_option_value) {
- switch (socket_option_key) {
- case GeneralTransportOptions::SIGNER: {
- utils::SpinLock::Acquire locked(signer_lock_);
- socket_option_value = signer_;
- } break;
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-int ProducerSocket::getSocketOption(int socket_option_key,
- std::string &socket_option_value) {
- switch (socket_option_key) {
- case DataLinkOptions::OUTPUT_INTERFACE:
- socket_option_value = output_interface_;
- break;
- default:
- return SOCKET_OPTION_NOT_GET;
- }
-
- return SOCKET_OPTION_GET;
-}
-
-asio::io_service &ProducerSocket::getIoService() { return io_service_; }
-
-} // namespace interface
-
-} // end namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/socket_producer.h b/libtransport/src/hicn/transport/interfaces/socket_producer.h
deleted file mode 100644
index 5f360f2ce..000000000
--- a/libtransport/src/hicn/transport/interfaces/socket_producer.h
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <hicn/transport/interfaces/socket.h>
-#include <hicn/transport/utils/content_store.h>
-#include <hicn/transport/utils/event_thread.h>
-#include <hicn/transport/utils/signer.h>
-#include <hicn/transport/utils/suffix_strategy.h>
-
-#include <atomic>
-#include <cmath>
-#include <condition_variable>
-#include <mutex>
-#include <queue>
-#include <thread>
-
-#define REGISTRATION_NOT_ATTEMPTED 0
-#define REGISTRATION_SUCCESS 1
-#define REGISTRATION_FAILURE 2
-#define REGISTRATION_IN_PROGRESS 3
-
-namespace transport {
-
-namespace interface {
-
-using namespace core;
-
-class ProducerSocket : public Socket<BasePortal>,
- public BasePortal::ProducerCallback {
- public:
- explicit ProducerSocket();
- explicit ProducerSocket(asio::io_service &io_service);
-
- ~ProducerSocket();
-
- void connect() override;
-
- bool isRunning() override { return !io_service_.stopped(); };
-
- virtual uint32_t produce(Name content_name, const uint8_t *buffer,
- size_t buffer_size, bool is_last = true,
- uint32_t start_offset = 0) {
- return ProducerSocket::produce(
- content_name, utils::MemBuf::copyBuffer(buffer, buffer_size), is_last,
- start_offset);
- }
-
- virtual uint32_t produce(Name content_name,
- std::unique_ptr<utils::MemBuf> &&buffer,
- bool is_last = true, uint32_t start_offset = 0);
-
- virtual void produce(ContentObject &content_object);
-
- virtual void produce(const uint8_t *buffer, size_t buffer_size) {
- produce(utils::MemBuf::copyBuffer(buffer, buffer_size));
- }
-
- virtual void produce(std::unique_ptr<utils::MemBuf> &&buffer) {
- // This API is meant to be used just with the RTC producer.
- // Here it cannot be used since no name for the content is specified.
- throw errors::NotImplementedException();
- }
-
- virtual void asyncProduce(const Name &suffix, const uint8_t *buf,
- size_t buffer_size, bool is_last = true,
- uint32_t *start_offset = nullptr);
-
- void asyncProduce(const Name &suffix);
-
- virtual void asyncProduce(Name content_name,
- std::unique_ptr<utils::MemBuf> &&buffer,
- bool is_last, uint32_t offset,
- uint32_t **last_segment = nullptr);
-
- virtual void asyncProduce(ContentObject &content_object);
-
- virtual void registerPrefix(const Prefix &producer_namespace);
-
- void serveForever();
-
- void stop();
-
- asio::io_service &getIoService() override;
-
- virtual void onInterest(Interest &interest);
-
- virtual void onInterest(Interest::Ptr &&interest) override {
- onInterest(*interest);
- };
-
- virtual int setSocketOption(int socket_option_key,
- uint32_t socket_option_value);
-
- virtual int setSocketOption(int socket_option_key,
- std::nullptr_t socket_option_value);
-
- virtual int setSocketOption(int socket_option_key, bool socket_option_value);
-
- virtual int setSocketOption(int socket_option_key, Name *socket_option_value);
-
- virtual int setSocketOption(int socket_option_key,
- std::list<Prefix> socket_option_value);
-
- virtual int setSocketOption(
- int socket_option_key, ProducerContentObjectCallback socket_option_value);
-
- virtual int setSocketOption(int socket_option_key,
- ProducerInterestCallback socket_option_value);
-
- virtual int setSocketOption(int socket_option_key,
- ProducerContentCallback socket_option_value);
-
- virtual int setSocketOption(int socket_option_key,
- HashAlgorithm socket_option_value);
-
- virtual int setSocketOption(int socket_option_key,
- utils::CryptoSuite socket_option_value);
-
- virtual int setSocketOption(
- int socket_option_key,
- const std::shared_ptr<utils::Signer> &socket_option_value);
-
- virtual int setSocketOption(int socket_option_key,
- const std::string &socket_option_value);
-
- virtual int getSocketOption(int socket_option_key,
- uint32_t &socket_option_value);
-
- virtual int getSocketOption(int socket_option_key, bool &socket_option_value);
-
- virtual int getSocketOption(int socket_option_key,
- std::list<Prefix> &socket_option_value);
-
- virtual int getSocketOption(
- int socket_option_key,
- ProducerContentObjectCallback **socket_option_value);
-
- virtual int getSocketOption(int socket_option_key,
- ProducerContentCallback **socket_option_value);
-
- virtual int getSocketOption(int socket_option_key,
- ProducerInterestCallback **socket_option_value);
-
- virtual int getSocketOption(int socket_option_key,
- std::shared_ptr<Portal> &socket_option_value);
-
- virtual int getSocketOption(int socket_option_key,
- HashAlgorithm &socket_option_value);
-
- virtual int getSocketOption(int socket_option_key,
- utils::CryptoSuite &socket_option_value);
-
- virtual int getSocketOption(
- int socket_option_key,
- std::shared_ptr<utils::Signer> &socket_option_value);
-
- virtual int getSocketOption(int socket_option_key,
- std::string &socket_option_value);
-
- // If the thread calling lambda_func is not the same of io_service, this
- // function reschedule the function on it
- template <typename Lambda, typename arg2>
- int rescheduleOnIOService(int socket_option_key, arg2 socket_option_value,
- Lambda lambda_func) {
- // To enforce type check
- std::function<int(int, arg2)> func = lambda_func;
- int result = SOCKET_OPTION_SET;
- if (listening_thread_.joinable() &&
- std::this_thread::get_id() != listening_thread_.get_id()) {
- std::mutex mtx;
- /* Condition variable for the wait */
- std::condition_variable cv;
- bool done = false;
- io_service_.dispatch([&socket_option_key, &socket_option_value, &mtx, &cv,
- &result, &done, &func]() {
- std::unique_lock<std::mutex> lck(mtx);
- done = true;
- result = func(socket_option_key, socket_option_value);
- cv.notify_all();
- });
- std::unique_lock<std::mutex> lck(mtx);
- if (!done) {
- cv.wait(lck);
- }
- } else {
- result = func(socket_option_key, socket_option_value);
- }
-
- return result;
- }
-
- template <typename Lambda, typename arg2>
- int rescheduleOnIOServiceWithReference(int socket_option_key,
- arg2 &socket_option_value,
- Lambda lambda_func) {
- // To enforce type check
- std::function<int(int, arg2 &)> func = lambda_func;
- int result = SOCKET_OPTION_SET;
- if (listening_thread_.joinable() &&
- std::this_thread::get_id() != this->listening_thread_.get_id()) {
- std::mutex mtx;
- /* Condition variable for the wait */
- std::condition_variable cv;
-
- bool done = false;
- io_service_.dispatch([&socket_option_key, &socket_option_value, &mtx, &cv,
- &result, &done, &func]() {
- std::unique_lock<std::mutex> lck(mtx);
- done = true;
- result = func(socket_option_key, socket_option_value);
- cv.notify_all();
- });
- std::unique_lock<std::mutex> lck(mtx);
- if (!done) {
- cv.wait(lck);
- }
- } else {
- result = func(socket_option_key, socket_option_value);
- }
-
- return result;
- }
- // Threads
- protected:
- std::thread listening_thread_;
- asio::io_service internal_io_service_;
- asio::io_service &io_service_;
- std::shared_ptr<Portal> portal_;
- std::atomic<size_t> data_packet_size_;
- std::list<Prefix>
- served_namespaces_; // No need to be threadsafe, this is always modified
- // by the application thread
- std::atomic<uint32_t> content_object_expiry_time_;
-
- // buffers
- // ContentStore is thread-safe
- utils::ContentStore output_buffer_;
-
- utils::EventThread async_thread_;
- int registration_status_;
-
- std::atomic<bool> making_manifest_;
-
- // map for storing sequence numbers for several calls of the publish
- // function
- std::unordered_map<Name, std::unordered_map<int, uint32_t>> seq_number_map_;
-
- std::atomic<HashAlgorithm> hash_algorithm_;
- std::atomic<utils::CryptoSuite> crypto_suite_;
- utils::SpinLock signer_lock_;
- std::shared_ptr<utils::Signer> signer_;
- core::NextSegmentCalculationStrategy suffix_strategy_;
-
- // While manifests are being built, contents are stored in a queue
- std::queue<std::shared_ptr<ContentObject>> content_queue_;
-
- // callbacks
- ProducerInterestCallback on_interest_input_;
- ProducerInterestCallback on_interest_dropped_input_buffer_;
- ProducerInterestCallback on_interest_inserted_input_buffer_;
- ProducerInterestCallback on_interest_satisfied_output_buffer_;
- ProducerInterestCallback on_interest_process_;
-
- ProducerContentObjectCallback on_new_segment_;
- ProducerContentObjectCallback on_content_object_to_sign_;
- ProducerContentObjectCallback on_content_object_in_output_buffer_;
- ProducerContentObjectCallback on_content_object_output_;
- ProducerContentObjectCallback on_content_object_evicted_from_output_buffer_;
-
- ProducerContentCallback on_content_produced_;
-
- private:
- void listen();
-
- void passContentObjectToCallbacks(
- const std::shared_ptr<ContentObject> &content_object);
-};
-
-} // namespace interface
-
-} // namespace transport
diff --git a/libtransport/src/hicn/transport/protocols/manifest_indexing_manager.cc b/libtransport/src/hicn/transport/protocols/manifest_indexing_manager.cc
deleted file mode 100644
index 5bf9c89f7..000000000
--- a/libtransport/src/hicn/transport/protocols/manifest_indexing_manager.cc
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <hicn/transport/interfaces/socket_consumer.h>
-#include <hicn/transport/protocols/manifest_indexing_manager.h>
-
-#include <cmath>
-#include <deque>
-
-namespace transport {
-
-namespace protocol {
-
-using namespace interface;
-
-ManifestIndexManager::ManifestIndexManager(
- interface::ConsumerSocket *icn_socket, TransportProtocol *next_interest)
- : IncrementalIndexManager(icn_socket),
- PacketManager<Interest>(1024),
- next_to_retrieve_segment_(suffix_queue_.end()),
- suffix_manifest_(core::NextSegmentCalculationStrategy::INCREMENTAL, 0),
- next_reassembly_segment_(
- core::NextSegmentCalculationStrategy::INCREMENTAL, 1, true),
- ignored_segments_(),
- next_interest_(next_interest) {}
-
-bool ManifestIndexManager::onManifest(
- core::ContentObject::Ptr &&content_object) {
- auto manifest =
- std::make_unique<ContentObjectManifest>(std::move(*content_object));
- bool manifest_verified = verification_manager_->onPacketToVerify(*manifest);
-
- if (manifest_verified) {
- manifest->decode();
-
- if (TRANSPORT_EXPECT_FALSE(manifest->getVersion() !=
- core::ManifestVersion::VERSION_1)) {
- throw errors::RuntimeException("Received manifest with unknown version.");
- }
-
- switch (manifest->getManifestType()) {
- case core::ManifestType::INLINE_MANIFEST: {
- auto _it = manifest->getSuffixList().begin();
- auto _end = manifest->getSuffixList().end();
- size_t nb_segments = std::distance(_it, _end);
- final_suffix_ = manifest->getFinalBlockNumber(); // final block number
-
- TRANSPORT_LOGD("Received manifest %u",
- manifest->getWritableName().getSuffix());
- suffix_hash_map_[_it->first] =
- std::make_pair(std::vector<uint8_t>(_it->second, _it->second + 32),
- manifest->getHashAlgorithm());
- suffix_queue_.push_back(_it->first);
-
- // If the transport protocol finished the list of segments to retrieve,
- // reset the next_to_retrieve_segment_ iterator to the next segment
- // provided by this manifest.
- if (TRANSPORT_EXPECT_FALSE(next_to_retrieve_segment_ ==
- suffix_queue_.end())) {
- next_to_retrieve_segment_ = --suffix_queue_.end();
- }
-
- std::advance(_it, 1);
- for (; _it != _end; _it++) {
- suffix_hash_map_[_it->first] = std::make_pair(
- std::vector<uint8_t>(_it->second, _it->second + 32),
- manifest->getHashAlgorithm());
- suffix_queue_.push_back(_it->first);
- }
-
- if (TRANSPORT_EXPECT_FALSE(manifest->getName().getSuffix()) == 0) {
- core::NextSegmentCalculationStrategy strategy =
- manifest->getNextSegmentCalculationStrategy();
-
- suffix_manifest_.reset(0);
- suffix_manifest_.setNbSegments(nb_segments);
- suffix_manifest_.setSuffixStrategy(strategy);
- TRANSPORT_LOGD("Capacity of 1st manifest %zu",
- suffix_manifest_.getNbSegments());
-
- next_reassembly_segment_.reset(*suffix_queue_.begin());
- next_reassembly_segment_.setNbSegments(nb_segments);
- suffix_manifest_.setSuffixStrategy(strategy);
- }
-
- // If the manifest is not full, we add the suffixes of missing segments
- // to the list of segments to ignore when computing the next reassembly
- // index.
- if (TRANSPORT_EXPECT_FALSE(
- suffix_manifest_.getNbSegments() - nb_segments > 0)) {
- auto start = manifest->getSuffixList().begin();
- auto last = --_end;
- for (uint32_t i = last->first + 1;
- i < start->first + suffix_manifest_.getNbSegments(); i++) {
- ignored_segments_.push_back(i);
- }
- }
-
- if (TRANSPORT_EXPECT_FALSE(manifest->isFinalManifest()) == 0) {
- fillWindow(manifest->getWritableName(),
- manifest->getName().getSuffix());
- }
-
- break;
- }
- case core::ManifestType::FLIC_MANIFEST: {
- throw errors::NotImplementedException();
- }
- case core::ManifestType::FINAL_CHUNK_NUMBER: {
- throw errors::NotImplementedException();
- }
- }
- }
-
- return manifest_verified;
-}
-
-void ManifestIndexManager::onManifestReceived(Interest::Ptr &&i,
- ContentObject::Ptr &&c) {
- onManifest(std::move(c));
- if (next_interest_) {
- next_interest_->scheduleNextInterests();
- }
-}
-
-void ManifestIndexManager::onManifestTimeout(Interest::Ptr &&i) {
- const Name &n = i->getName();
- uint32_t segment = n.getSuffix();
-
- if (segment > final_suffix_) {
- return;
- }
-
- TRANSPORT_LOGD("Timeout on manifest %u", segment);
- // Get portal
- std::shared_ptr<interface::BasePortal> portal;
- socket_->getSocketOption(GeneralTransportOptions::PORTAL, portal);
-
- // Send requests for manifest out of the congestion window (no
- // in_flight_interests++)
- portal->sendInterest(
- std::move(i),
- std::bind(&ManifestIndexManager::onManifestReceived, this,
- std::placeholders::_1, std::placeholders::_2),
- std::bind(&ManifestIndexManager::onManifestTimeout, this,
- std::placeholders::_1));
-}
-
-void ManifestIndexManager::fillWindow(Name &name, uint32_t current_manifest) {
- /* Send as many manifest as required for filling window. */
- uint32_t interest_lifetime;
- double window_size;
- std::shared_ptr<interface::BasePortal> portal;
- Interest::Ptr interest;
- uint32_t current_segment = *next_to_retrieve_segment_;
- // suffix_manifest_ now points to the next manifest to request
- uint32_t last_requested_manifest = (suffix_manifest_++).getSuffix();
-
- socket_->getSocketOption(GeneralTransportOptions::PORTAL, portal);
- socket_->getSocketOption(GeneralTransportOptions::INTEREST_LIFETIME,
- interest_lifetime);
- socket_->getSocketOption(GeneralTransportOptions::CURRENT_WINDOW_SIZE,
- window_size);
-
- if (TRANSPORT_EXPECT_FALSE(suffix_manifest_.getSuffix() >= final_suffix_)) {
- suffix_manifest_.updateSuffix(last_requested_manifest);
- return;
- }
-
- if (current_segment + window_size < suffix_manifest_.getSuffix() &&
- current_manifest != last_requested_manifest) {
- suffix_manifest_.updateSuffix(last_requested_manifest);
- return;
- }
-
- do {
- interest = getPacket();
- name.setSuffix(suffix_manifest_.getSuffix());
- interest->setName(name);
- interest->setLifetime(interest_lifetime);
-
- // Send interests for manifest out of the congestion window (no
- // in_flight_interests++)
- portal->sendInterest(
- std::move(interest),
- std::bind(&ManifestIndexManager::onManifestReceived, this,
- std::placeholders::_1, std::placeholders::_2),
- std::bind(&ManifestIndexManager::onManifestTimeout, this,
- std::placeholders::_1));
- TRANSPORT_LOGD("Send manifest interest %u", name.getSuffix());
-
- last_requested_manifest = (suffix_manifest_++).getSuffix();
- } while (current_segment + window_size >= suffix_manifest_.getSuffix() &&
- suffix_manifest_.getSuffix() < final_suffix_);
-
- // suffix_manifest_ now points to the last requested manifest
- suffix_manifest_.updateSuffix(last_requested_manifest);
-}
-
-bool ManifestIndexManager::onContentObject(
- const core::ContentObject &content_object) {
- bool verify_signature;
- socket_->getSocketOption(GeneralTransportOptions::VERIFY_SIGNATURE,
- verify_signature);
-
- if (!verify_signature) {
- return true;
- }
-
- uint64_t segment = content_object.getName().getSuffix();
-
- bool ret = false;
-
- auto it = suffix_hash_map_.find((const unsigned int)segment);
- if (it != suffix_hash_map_.end()) {
- auto hash_type = static_cast<utils::CryptoHashType>(it->second.second);
- auto data_packet_digest = content_object.computeDigest(it->second.second);
- auto data_packet_digest_bytes =
- data_packet_digest.getDigest<uint8_t>().data();
- std::vector<uint8_t> &manifest_digest_bytes = it->second.first;
-
- if (utils::CryptoHash::compareBinaryDigest(data_packet_digest_bytes,
- manifest_digest_bytes.data(),
- hash_type)) {
- suffix_hash_map_.erase(it);
- ret = true;
- } else {
- throw errors::RuntimeException(
- "Verification failure policy has to be implemented.");
- }
- }
-
- return ret;
-}
-
-uint32_t ManifestIndexManager::getNextSuffix() {
- if (TRANSPORT_EXPECT_FALSE(next_to_retrieve_segment_ ==
- suffix_queue_.end())) {
- return invalid_index;
- }
-
- return *next_to_retrieve_segment_++;
-}
-
-uint32_t ManifestIndexManager::getFinalSuffix() { return final_suffix_; }
-
-bool ManifestIndexManager::isFinalSuffixDiscovered() {
- return IncrementalIndexManager::isFinalSuffixDiscovered();
-}
-
-uint32_t ManifestIndexManager::getNextReassemblySegment() {
- uint32_t current_reassembly_segment;
-
- while (true) {
- current_reassembly_segment = next_reassembly_segment_.getSuffix();
- next_reassembly_segment_++;
-
- if (TRANSPORT_EXPECT_FALSE(current_reassembly_segment > final_suffix_)) {
- return invalid_index;
- }
-
- if (ignored_segments_.empty()) break;
-
- auto is_ignored =
- std::find(ignored_segments_.begin(), ignored_segments_.end(),
- current_reassembly_segment);
-
- if (is_ignored == ignored_segments_.end()) break;
-
- ignored_segments_.erase(is_ignored);
- }
-
- return current_reassembly_segment;
-}
-
-void ManifestIndexManager::reset() {
- IncrementalIndexManager::reset();
- suffix_manifest_.reset(0);
- suffix_queue_.clear();
- suffix_hash_map_.clear();
-}
-
-} // end namespace protocol
-
-} // end namespace transport
diff --git a/libtransport/src/http/CMakeLists.txt b/libtransport/src/http/CMakeLists.txt
new file mode 100644
index 000000000..00708822d
--- /dev/null
+++ b/libtransport/src/http/CMakeLists.txt
@@ -0,0 +1,21 @@
+# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+
+list(APPEND SOURCE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/client_connection.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/request.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/response.cc)
+
+set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE) \ No newline at end of file
diff --git a/libtransport/src/http/client_connection.cc b/libtransport/src/http/client_connection.cc
new file mode 100644
index 000000000..7a3a636fe
--- /dev/null
+++ b/libtransport/src/http/client_connection.cc
@@ -0,0 +1,317 @@
+/*
+ * Copyright (c) 2017-2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hicn/transport/core/content_object.h>
+#include <hicn/transport/core/interest.h>
+#include <hicn/transport/http/client_connection.h>
+#include <hicn/transport/utils/hash.h>
+#include <hicn/transport/utils/log.h>
+
+#include <asio.hpp>
+#include <asio/steady_timer.hpp>
+
+#define DEFAULT_BETA 0.99
+#define DEFAULT_GAMMA 0.07
+
+namespace transport {
+
+namespace http {
+
+using namespace transport;
+
+class HTTPClientConnection::Implementation
+ : public ConsumerSocket::ReadCallback {
+ static constexpr uint32_t max_buffer_capacity = 64 * 1024;
+
+ public:
+ Implementation(HTTPClientConnection *http_client)
+ : http_client_(http_client),
+ consumer_(TransportProtocolAlgorithms::RAAQM),
+ read_bytes_callback_(nullptr),
+ read_buffer_(nullptr),
+ response_(std::make_shared<HTTPResponse>()),
+ timer_(nullptr) {
+ consumer_.setSocketOption(
+ ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY,
+ (ConsumerContentObjectVerificationCallback)std::bind(
+ &Implementation::verifyData, this, std::placeholders::_1,
+ std::placeholders::_2));
+
+ consumer_.setSocketOption(ConsumerCallbacksOptions::READ_CALLBACK, this);
+
+ consumer_.connect();
+ timer_ = std::make_unique<asio::steady_timer>(consumer_.getIoService());
+ }
+
+ RC get(const std::string &url, HTTPHeaders headers = {},
+ HTTPPayload &&payload = nullptr,
+ std::shared_ptr<HTTPResponse> response = nullptr,
+ ReadBytesCallback *callback = nullptr,
+ std::string ipv6_first_word = "b001") {
+ return sendRequest(url, HTTPMethod::GET, headers, std::move(payload),
+ response, callback, ipv6_first_word);
+ }
+
+ RC sendRequest(const std::string &url, HTTPMethod method,
+ HTTPHeaders headers = {}, HTTPPayload &&payload = nullptr,
+ std::shared_ptr<HTTPResponse> response = nullptr,
+ ReadBytesCallback *callback = nullptr,
+ std::string ipv6_first_word = "b001") {
+ current_url_ = url;
+ read_bytes_callback_ = callback;
+ if (!response) {
+ response_ = std::make_shared<HTTPResponse>();
+ } else {
+ response_ = response;
+ }
+
+ auto start = std::chrono::steady_clock::now();
+ request_.init(method, url, headers, std::move(payload));
+
+ success_callback_ = [this, method = std::move(method), url = std::move(url),
+ start = std::move(start)](std::size_t size) -> void {
+ auto end = std::chrono::steady_clock::now();
+ TRANSPORT_LOGI(
+ "%s %s [%s] duration: %llu [usec] %zu [bytes]\n",
+ method_map[method].c_str(), url.c_str(), name_.str().c_str(),
+ (unsigned long long)
+ std::chrono::duration_cast<std::chrono::microseconds>(end - start)
+ .count(),
+ size);
+ };
+
+ sendRequestGetReply(ipv6_first_word);
+ return return_code_;
+ }
+
+ std::shared_ptr<HTTPResponse> response() {
+ response_->coalescePayloadBuffer();
+ return response_;
+ }
+
+ HTTPClientConnection &stop() {
+ // This is thread safe and can be called from another thread
+ consumer_.stop();
+
+ return *http_client_;
+ }
+
+ interface::ConsumerSocket &getConsumer() {
+ return consumer_;
+ }
+
+ HTTPClientConnection &setTimeout(const std::chrono::seconds &timeout) {
+ timer_->cancel();
+ timer_->expires_from_now(timeout);
+ timer_->async_wait([this](std::error_code ec) {
+ if (!ec) {
+ consumer_.stop();
+ }
+ });
+
+ return *http_client_;
+ }
+
+ HTTPClientConnection &setCertificate(const std::string &cert_path) {
+ if (consumer_.setSocketOption(GeneralTransportOptions::CERTIFICATE,
+ cert_path) == SOCKET_OPTION_NOT_SET) {
+ throw errors::RuntimeException("Error setting the certificate.");
+ }
+
+ return *http_client_;
+ }
+
+ private:
+ void sendRequestGetReply(std::string &ipv6_first_word) {
+ const std::string &request_string = request_.getRequestString();
+ const std::string &locator = request_.getLocator();
+
+ // Hash it
+
+ uint32_t locator_hash =
+ utils::hash::fnv32_buf(locator.c_str(), locator.size());
+ uint64_t request_hash =
+ utils::hash::fnv64_buf(request_string.c_str(), request_string.size());
+
+ consumer_.setSocketOption(
+ ConsumerCallbacksOptions::INTEREST_OUTPUT,
+ (ConsumerInterestCallback)std::bind(
+ &Implementation::processLeavingInterest, this,
+ std::placeholders::_1, std::placeholders::_2));
+
+ // Factor hicn name using hash
+ name_.str("");
+
+ name_ << ipv6_first_word << ":";
+
+ for (uint16_t *word = (uint16_t *)&locator_hash;
+ std::size_t(word) <
+ (std::size_t(&locator_hash) + sizeof(locator_hash));
+ word++) {
+ name_ << ":" << std::hex << *word;
+ }
+
+ for (uint16_t *word = (uint16_t *)&request_hash;
+ std::size_t(word) <
+ (std::size_t(&request_hash) + sizeof(request_hash));
+ word++) {
+ name_ << ":" << std::hex << *word;
+ }
+
+ name_ << "|0";
+
+ consumer_.consume(Name(name_.str()));
+
+ consumer_.stop();
+ }
+
+ bool verifyData(interface::ConsumerSocket &c,
+ const core::ContentObject &contentObject) {
+ if (contentObject.getPayloadType() == PayloadType::CONTENT_OBJECT) {
+ TRANSPORT_LOGI("VERIFY CONTENT\n");
+ } else if (contentObject.getPayloadType() == PayloadType::MANIFEST) {
+ TRANSPORT_LOGI("VERIFY MANIFEST\n");
+ }
+
+ return true;
+ }
+
+ void processLeavingInterest(interface::ConsumerSocket &c,
+ const core::Interest &interest) {
+ if (interest.payloadSize() == 0) {
+ Interest &int2 = const_cast<Interest &>(interest);
+ auto payload = request_.getRequestString();
+ auto payload2 = request_.getPayload();
+ int2.appendPayload((uint8_t *)payload.data(), payload.size());
+ if (payload2)
+ int2.appendPayload((uint8_t *)payload2->data(), payload2->length());
+ }
+ }
+
+ // Read callback
+ bool isBufferMovable() noexcept override { return true; }
+
+ void getReadBuffer(uint8_t **application_buffer,
+ size_t *max_length) override {}
+
+ void readDataAvailable(size_t length) noexcept override {}
+
+ size_t maxBufferSize() const override { return max_buffer_capacity; }
+
+ void readBufferAvailable(
+ std::unique_ptr<utils::MemBuf> &&buffer) noexcept override {
+ if (!read_bytes_callback_) {
+ response_->appendResponseChunk(std::move(buffer));
+ } else {
+ read_bytes_callback_->onBytesReceived(std::move(buffer));
+ }
+ }
+
+ void readError(const std::error_code ec) noexcept override {
+ TRANSPORT_LOGE("Error %s during download of %s", ec.message().c_str(),
+ current_url_.c_str());
+ if (read_bytes_callback_) {
+ read_bytes_callback_->onError(ec);
+ }
+
+ return_code_ = HTTPClientConnection::RC::DOWNLOAD_FAILED;
+ }
+
+ void readSuccess(std::size_t total_size) noexcept override {
+ success_callback_(total_size);
+ if (read_bytes_callback_) {
+ read_bytes_callback_->onSuccess(total_size);
+ }
+
+ return_code_ = HTTPClientConnection::RC::DOWNLOAD_SUCCESS;
+ }
+
+ HTTPClientConnection *http_client_;
+
+ // The consumer socket
+ ConsumerSocket consumer_;
+
+ // The current url provided by the application
+ std::string current_url_;
+ // The current hICN name used for downloading
+ std::stringstream name_;
+ // Function to be called when the read is successful
+ std::function<void(std::size_t)> success_callback_;
+ // Return code for current download
+ RC return_code_;
+
+ // Application provided callback for saving the received content during
+ // the download. If this callback is used, the HTTPClient will NOT save
+ // any byte internally.
+ ReadBytesCallback *read_bytes_callback_;
+
+ HTTPRequest request_;
+
+ // Internal read buffer and HTTP response, to be used if the application does
+ // not provide any read_bytes_callback
+ std::unique_ptr<utils::MemBuf> read_buffer_;
+ std::shared_ptr<HTTPResponse> response_;
+
+ // Timer
+ std::unique_ptr<asio::steady_timer> timer_;
+};
+
+HTTPClientConnection::HTTPClientConnection() {
+ implementation_ = new Implementation(this);
+}
+
+HTTPClientConnection::~HTTPClientConnection() { delete implementation_; }
+
+HTTPClientConnection::RC HTTPClientConnection::get(
+ const std::string &url, HTTPHeaders headers, HTTPPayload &&payload,
+ std::shared_ptr<HTTPResponse> response, ReadBytesCallback *callback,
+ std::string ipv6_first_word) {
+ return implementation_->get(url, headers, std::move(payload), response,
+ callback, ipv6_first_word);
+}
+
+HTTPClientConnection::RC HTTPClientConnection::sendRequest(
+ const std::string &url, HTTPMethod method, HTTPHeaders headers,
+ HTTPPayload &&payload, std::shared_ptr<HTTPResponse> response,
+ ReadBytesCallback *callback, std::string ipv6_first_word) {
+ return implementation_->sendRequest(url, method, headers, std::move(payload),
+ response, callback, ipv6_first_word);
+}
+
+std::shared_ptr<HTTPResponse> HTTPClientConnection::response() {
+ return implementation_->response();
+}
+
+ConsumerSocket &HTTPClientConnection::getConsumer() {
+ return implementation_->getConsumer();
+}
+
+HTTPClientConnection &HTTPClientConnection::stop() {
+ return implementation_->stop();
+}
+
+HTTPClientConnection &HTTPClientConnection::setTimeout(
+ const std::chrono::seconds &timeout) {
+ return implementation_->setTimeout(timeout);
+}
+
+HTTPClientConnection &HTTPClientConnection::setCertificate(
+ const std::string &cert_path) {
+ return implementation_->setCertificate(cert_path);
+}
+
+} // namespace http
+
+} // namespace transport
diff --git a/libtransport/src/hicn/transport/http/request.cc b/libtransport/src/http/request.cc
index 09f709642..09f709642 100644
--- a/libtransport/src/hicn/transport/http/request.cc
+++ b/libtransport/src/http/request.cc
diff --git a/libtransport/src/hicn/transport/http/response.cc b/libtransport/src/http/response.cc
index ba0acd1ac..ba0acd1ac 100644
--- a/libtransport/src/hicn/transport/http/response.cc
+++ b/libtransport/src/http/response.cc
diff --git a/libtransport/src/hicn/transport/interfaces/CMakeLists.txt b/libtransport/src/implementation/CMakeLists.txt
index 88b83e9d4..5423a7697 100644
--- a/libtransport/src/hicn/transport/interfaces/CMakeLists.txt
+++ b/libtransport/src/implementation/CMakeLists.txt
@@ -13,28 +13,15 @@
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+list(APPEND SOURCE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/rtc_socket_producer.cc
+)
+
list(APPEND HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/socket.h
- ${CMAKE_CURRENT_SOURCE_DIR}/socket_consumer.h
- ${CMAKE_CURRENT_SOURCE_DIR}/socket_producer.h
- ${CMAKE_CURRENT_SOURCE_DIR}/tls_socket_producer.h
- ${CMAKE_CURRENT_SOURCE_DIR}/tls_rtc_socket_producer.h
- ${CMAKE_CURRENT_SOURCE_DIR}/p2psecure_socket_producer.h
- ${CMAKE_CURRENT_SOURCE_DIR}/tls_socket_consumer.h
- ${CMAKE_CURRENT_SOURCE_DIR}/p2psecure_socket_consumer.h
${CMAKE_CURRENT_SOURCE_DIR}/rtc_socket_producer.h
- ${CMAKE_CURRENT_SOURCE_DIR}/publication_options.h
- ${CMAKE_CURRENT_SOURCE_DIR}/socket_options_default_values.h
- ${CMAKE_CURRENT_SOURCE_DIR}/socket_options_keys.h
- ${CMAKE_CURRENT_SOURCE_DIR}/callbacks.h
- ${CMAKE_CURRENT_SOURCE_DIR}/verification_policy.h
-)
-
-list(APPEND SOURCE_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/socket_producer.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/rtc_socket_producer.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/socket_consumer.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/callbacks.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/socket_producer.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/socket_consumer.h
)
if (${OPENSSL_VERSION} VERSION_EQUAL "1.1.1a" OR ${OPENSSL_VERSION} VERSION_GREATER "1.1.1a")
@@ -55,5 +42,5 @@ if (${OPENSSL_VERSION} VERSION_EQUAL "1.1.1a" OR ${OPENSSL_VERSION} VERSION_GREA
)
endif()
-set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
set(HEADER_FILES ${HEADER_FILES} PARENT_SCOPE)
+set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
diff --git a/libtransport/src/hicn/transport/interfaces/p2psecure_socket_consumer.cc b/libtransport/src/implementation/p2psecure_socket_consumer.cc
index ec966e509..40ab58161 100644
--- a/libtransport/src/hicn/transport/interfaces/p2psecure_socket_consumer.cc
+++ b/libtransport/src/implementation/p2psecure_socket_consumer.cc
@@ -1,4 +1,21 @@
-#include <hicn/transport/interfaces/p2psecure_socket_consumer.h>
+/*
+ * Copyright (c) 2017-2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <implementation/p2psecure_socket_consumer.h>
+#include <interfaces/tls_socket_consumer.h>
+
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/tls1.h>
@@ -6,11 +23,10 @@
#include <random>
namespace transport {
-
-namespace interface {
+namespace implementation {
void P2PSecureConsumerSocket::setInterestPayload(
- ConsumerSocket &c, const core::Interest &interest) {
+ interface::ConsumerSocket &c, const core::Interest &interest) {
Interest &int2 = const_cast<Interest &>(interest);
random_suffix_ = int2.getName().getSuffix();
@@ -72,7 +88,7 @@ int read(BIO *b, char *buf, size_t size, size_t *readbytes) {
if (size > INT_MAX) size = INT_MAX;
- ret = transport::interface::readOld(b, buf, (int)size);
+ ret = readOld(b, buf, (int)size);
if (ret <= 0) {
*readbytes = 0;
@@ -105,7 +121,7 @@ int write(BIO *b, const char *buf, size_t size, size_t *written) {
if (size > INT_MAX) size = INT_MAX;
- ret = transport::interface::writeOld(b, buf, (int)size);
+ ret = writeOld(b, buf, (int)size);
if (ret <= 0) {
*written = 0;
@@ -154,8 +170,10 @@ int P2PSecureConsumerSocket::parseHicnKeyIdCb(SSL *s, unsigned int ext_type,
return 1;
}
-P2PSecureConsumerSocket::P2PSecureConsumerSocket(int handshake_protocol, int transport_protocol)
- : ConsumerSocket(handshake_protocol),
+P2PSecureConsumerSocket::P2PSecureConsumerSocket(
+ interface::ConsumerSocket *consumer, int handshake_protocol,
+ int transport_protocol)
+ : ConsumerSocket(consumer, transport_protocol),
name_(),
tls_consumer_(),
buf_pool_(),
@@ -198,9 +216,9 @@ P2PSecureConsumerSocket::P2PSecureConsumerSocket(int handshake_protocol, int tra
ssl_ = SSL_new(ctx_);
bio_meth_ = BIO_meth_new(BIO_TYPE_CONNECT, "secure consumer socket");
- BIO_meth_set_read(bio_meth_, transport::interface::readOld);
- BIO_meth_set_write(bio_meth_, transport::interface::writeOld);
- BIO_meth_set_ctrl(bio_meth_, transport::interface::ctrl);
+ BIO_meth_set_read(bio_meth_, readOld);
+ BIO_meth_set_write(bio_meth_, writeOld);
+ BIO_meth_set_ctrl(bio_meth_, ctrl);
BIO *bio = BIO_new(bio_meth_);
BIO_set_init(bio, 1);
BIO_set_data(bio, this);
@@ -246,7 +264,8 @@ int P2PSecureConsumerSocket::consume(const Name &name) {
ip_address_get_buffer(&(secure_prefix_.address), secure_prefix_.family));
std::shared_ptr<Prefix> prefix =
std::make_shared<Prefix>(*prefix_name, secure_prefix_.len);
- TLSConsumerSocket tls_consumer(this->protocol_, this->ssl_);
+ TLSConsumerSocket tls_consumer(nullptr, this->protocol_, this->ssl_);
+ tls_consumer.setInterface(new interface::TLSConsumerSocket(&tls_consumer));
ConsumerTimerCallback *stats_summary_callback = nullptr;
this->getSocketOption(ConsumerCallbacksOptions::STATS_SUMMARY,
@@ -294,8 +313,11 @@ int P2PSecureConsumerSocket::asyncConsume(const Name &name) {
ip_address_get_buffer(&(secure_prefix_.address), secure_prefix_.family));
std::shared_ptr<Prefix> prefix =
std::make_shared<Prefix>(*prefix_name, secure_prefix_.len);
+
tls_consumer_ =
- std::make_shared<TLSConsumerSocket>(this->protocol_, this->ssl_);
+ std::make_shared<TLSConsumerSocket>(nullptr, this->protocol_, this->ssl_);
+ tls_consumer_->setInterface(
+ new interface::TLSConsumerSocket(tls_consumer_.get()));
ConsumerTimerCallback *stats_summary_callback = nullptr;
this->getSocketOption(ConsumerCallbacksOptions::STATS_SUMMARY,
@@ -327,11 +349,10 @@ void P2PSecureConsumerSocket::registerPrefix(const Prefix &producer_namespace) {
}
int P2PSecureConsumerSocket::setSocketOption(
- int socket_option_key, ConsumerSocket::ReadCallback *socket_option_value) {
+ int socket_option_key, ReadCallback *socket_option_value) {
return rescheduleOnIOService(
socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ConsumerSocket::ReadCallback *socket_option_value) -> int {
+ [this](int socket_option_key, ReadCallback *socket_option_value) -> int {
switch (socket_option_key) {
case ConsumerCallbacksOptions::READ_CALLBACK:
read_callback_decrypted_ = socket_option_value;
@@ -377,6 +398,6 @@ void P2PSecureConsumerSocket::readSuccess(std::size_t total_size) noexcept {
bool P2PSecureConsumerSocket::isBufferMovable() noexcept { return true; }
-} // namespace interface
+} // namespace implementation
} // namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/p2psecure_socket_consumer.h b/libtransport/src/implementation/p2psecure_socket_consumer.h
index ff867f07b..e2ebaf94e 100644
--- a/libtransport/src/hicn/transport/interfaces/p2psecure_socket_consumer.h
+++ b/libtransport/src/implementation/p2psecure_socket_consumer.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Copyright (c) 2017-2020 Cisco and/or its affiliates.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
@@ -16,16 +16,16 @@
#pragma once
#include <hicn/transport/interfaces/socket_consumer.h>
-#include <hicn/transport/interfaces/tls_socket_consumer.h>
+
+#include <implementation/tls_socket_consumer.h>
#include <openssl/bio.h>
#include <openssl/ssl.h>
namespace transport {
-
-namespace interface {
+namespace implementation {
class P2PSecureConsumerSocket : public ConsumerSocket,
- public ConsumerSocket::ReadCallback {
+ public interface::ConsumerSocket::ReadCallback {
/* Return the number of read bytes in readbytes */
friend int read(BIO *b, char *buf, size_t size, size_t *readbytes);
@@ -41,7 +41,9 @@ class P2PSecureConsumerSocket : public ConsumerSocket,
friend long ctrl(BIO *b, int cmd, long num, void *ptr);
public:
- explicit P2PSecureConsumerSocket(int handshake_protocol, int transport_protocol);
+ explicit P2PSecureConsumerSocket(interface::ConsumerSocket *consumer,
+ int handshake_protocol,
+ int transport_protocol);
~P2PSecureConsumerSocket();
@@ -53,7 +55,7 @@ class P2PSecureConsumerSocket : public ConsumerSocket,
int setSocketOption(
int socket_option_key,
- ConsumerSocket::ReadCallback *socket_option_value) override;
+ interface::ConsumerSocket::ReadCallback *socket_option_value) override;
using ConsumerSocket::getSocketOption;
using ConsumerSocket::setSocketOption;
@@ -98,7 +100,7 @@ class P2PSecureConsumerSocket : public ConsumerSocket,
Prefix producer_namespace_;
- ConsumerSocket::ReadCallback *read_callback_decrypted_;
+ interface::ConsumerSocket::ReadCallback *read_callback_decrypted_;
std::mutex mtx_;
@@ -107,9 +109,8 @@ class P2PSecureConsumerSocket : public ConsumerSocket,
int protocol_;
- void setInterestPayload(ConsumerSocket &c, const core::Interest &interest);
- void processPayload(ConsumerSocket &c, std::size_t bytes_transferred,
- const std::error_code &ec);
+ void setInterestPayload(interface::ConsumerSocket &c,
+ const core::Interest &interest);
static int addHicnKeyIdCb(SSL *s, unsigned int ext_type, unsigned int context,
const unsigned char **out, size_t *outlen, X509 *x,
@@ -142,6 +143,6 @@ class P2PSecureConsumerSocket : public ConsumerSocket,
int download_content(const Name &name);
};
-} // namespace interface
+} // namespace implementation
} // end namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/p2psecure_socket_producer.cc b/libtransport/src/implementation/p2psecure_socket_producer.cc
index 8850bde8a..d7161986b 100644
--- a/libtransport/src/hicn/transport/interfaces/p2psecure_socket_producer.cc
+++ b/libtransport/src/implementation/p2psecure_socket_producer.cc
@@ -1,22 +1,40 @@
+/*
+ * Copyright (c) 2017-2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#include <hicn/transport/core/interest.h>
-#include <hicn/transport/interfaces/p2psecure_socket_producer.h>
-#include <hicn/transport/interfaces/tls_rtc_socket_producer.h>
-#include <hicn/transport/interfaces/tls_socket_producer.h>
+
+#include <implementation/p2psecure_socket_producer.h>
+#include <implementation/tls_rtc_socket_producer.h>
+#include <implementation/tls_socket_producer.h>
+#include <interfaces/tls_rtc_socket_producer.h>
+#include <interfaces/tls_socket_producer.h>
#include <openssl/bio.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
namespace transport {
-
-namespace interface {
+namespace implementation {
/* Workaround to prevent content with expiry time equal to 0 to be lost when
* pushed in the forwarder */
#define HICN_HANDSHAKE_CONTENT_EXPIRY_TIME 100;
-P2PSecureProducerSocket::P2PSecureProducerSocket()
- : ProducerSocket(),
+P2PSecureProducerSocket::P2PSecureProducerSocket(
+ interface::ProducerSocket *producer_socket)
+ : ProducerSocket(producer_socket),
mtx_(),
cv_(),
map_secure_producers(),
@@ -24,8 +42,9 @@ P2PSecureProducerSocket::P2PSecureProducerSocket()
list_secure_producers() {}
P2PSecureProducerSocket::P2PSecureProducerSocket(
- bool rtc, const std::shared_ptr<utils::Identity> &identity)
- : ProducerSocket(),
+ interface::ProducerSocket *producer_socket, bool rtc,
+ const std::shared_ptr<utils::Identity> &identity)
+ : ProducerSocket(producer_socket),
rtc_(rtc),
mtx_(),
cv_(),
@@ -65,16 +84,19 @@ P2PSecureProducerSocket::~P2PSecureProducerSocket() {
if (der_prk_) parcBuffer_Release(&der_prk_);
}
-void P2PSecureProducerSocket::onInterestCallback(ProducerSocket &p,
+void P2PSecureProducerSocket::onInterestCallback(interface::ProducerSocket &p,
Interest &interest) {
std::unique_lock<std::mutex> lck(mtx_);
- TRANSPORT_LOGD("Start handshake at %s", interest.getName().toString().c_str());
+ TRANSPORT_LOGD("Start handshake at %s",
+ interest.getName().toString().c_str());
if (!rtc_) {
auto it = map_secure_producers.find(interest.getName());
if (it != map_secure_producers.end()) return;
TLSProducerSocket *tls_producer =
- new TLSProducerSocket(this, interest.getName());
+ new TLSProducerSocket(nullptr, this, interest.getName());
+ tls_producer->setInterface(new interface::TLSProducerSocket(tls_producer));
+
tls_producer->on_content_produced_application_ =
this->on_content_produced_application_;
tls_producer->setSocketOption(CONTENT_OBJECT_EXPIRY_TIME,
@@ -92,7 +114,9 @@ void P2PSecureProducerSocket::onInterestCallback(ProducerSocket &p,
auto it = map_secure_rtc_producers.find(interest.getName());
if (it != map_secure_rtc_producers.end()) return;
TLSRTCProducerSocket *tls_producer =
- new TLSRTCProducerSocket(this, interest.getName());
+ new TLSRTCProducerSocket(nullptr, this, interest.getName());
+ tls_producer->setInterface(
+ new interface::TLSRTCProducerSocket(tls_producer));
tls_producer->on_content_produced_application_ =
this->on_content_produced_application_;
tls_producer->setSocketOption(CONTENT_OBJECT_EXPIRY_TIME,
@@ -375,6 +399,6 @@ int P2PSecureProducerSocket::setSocketOption(
socket_option_value);
}
-} // namespace interface
+} // namespace implementation
} // namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/p2psecure_socket_producer.h b/libtransport/src/implementation/p2psecure_socket_producer.h
index ba3fa0189..c2cbf31ac 100644
--- a/libtransport/src/hicn/transport/interfaces/p2psecure_socket_producer.h
+++ b/libtransport/src/implementation/p2psecure_socket_producer.h
@@ -15,12 +15,13 @@
#pragma once
-#include <hicn/transport/interfaces/socket_producer.h>
-#include <hicn/transport/interfaces/tls_socket_producer.h>
-#include <hicn/transport/interfaces/tls_rtc_socket_producer.h>
-#include <hicn/transport/utils/content_store.h>
-#include <hicn/transport/utils/identity.h>
-#include <hicn/transport/utils/signer.h>
+#include <hicn/transport/security/identity.h>
+#include <hicn/transport/security/signer.h>
+
+#include <implementation/socket_producer.h>
+#include <implementation/tls_rtc_socket_producer.h>
+#include <implementation/tls_socket_producer.h>
+#include <utils/content_store.h>
#include <openssl/ssl.h>
#include <condition_variable>
@@ -28,17 +29,17 @@
#include <mutex>
namespace transport {
-
-namespace interface {
+namespace implementation {
class P2PSecureProducerSocket : public ProducerSocket {
friend class TLSProducerSocket;
friend class TLSRTCProducerSocket;
public:
- explicit P2PSecureProducerSocket();
+ explicit P2PSecureProducerSocket(interface::ProducerSocket *producer_socket);
explicit P2PSecureProducerSocket(
- bool rtc, const std::shared_ptr<utils::Identity> &identity);
+ interface::ProducerSocket *producer_socket, bool rtc,
+ const std::shared_ptr<utils::Identity> &identity);
~P2PSecureProducerSocket();
void produce(const uint8_t *buffer, size_t buffer_size) override;
@@ -49,14 +50,14 @@ class P2PSecureProducerSocket : public ProducerSocket {
uint32_t produce(Name content_name, std::unique_ptr<utils::MemBuf> &&buffer,
bool is_last = true, uint32_t start_offset = 0) override;
- void asyncProduce(const Name &suffix, const uint8_t *buf, size_t buffer_size,
- bool is_last = true,
- uint32_t *start_offset = nullptr) override;
-
void asyncProduce(Name content_name, std::unique_ptr<utils::MemBuf> &&buffer,
bool is_last, uint32_t offset,
uint32_t **last_segment = nullptr) override;
+ void asyncProduce(const Name &suffix, const uint8_t *buf, size_t buffer_size,
+ bool is_last = true,
+ uint32_t *start_offset = nullptr) override;
+
int setSocketOption(int socket_option_key,
ProducerInterestCallback socket_option_value) override;
@@ -121,9 +122,9 @@ class P2PSecureProducerSocket : public ProducerSocket {
std::list<std::unique_ptr<TLSProducerSocket>> list_secure_producers;
std::list<std::unique_ptr<TLSRTCProducerSocket>> list_secure_rtc_producers;
- void onInterestCallback(ProducerSocket &p, Interest &interest);
+ void onInterestCallback(interface::ProducerSocket &p, Interest &interest);
};
-} // namespace interface
+} // namespace implementation
} // namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc b/libtransport/src/implementation/rtc_socket_producer.cc
index fefa419a9..a5b2b4a0e 100644
--- a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.cc
+++ b/libtransport/src/implementation/rtc_socket_producer.cc
@@ -14,7 +14,8 @@
*/
#include <hicn/transport/interfaces/callbacks.h>
-#include <hicn/transport/interfaces/rtc_socket_producer.h>
+
+#include <implementation/rtc_socket_producer.h>
#include <stdlib.h>
#include <time.h>
@@ -54,29 +55,10 @@
// +-----------------------------------------+
namespace transport {
+namespace implementation {
-namespace interface {
-
-RTCProducerSocket::RTCProducerSocket(asio::io_service &io_service)
- : ProducerSocket(io_service),
- currentSeg_(1),
- producedBytes_(0),
- producedPackets_(0),
- bytesProductionRate_(INIT_PACKET_PRODUCTION_RATE * 1400),
- packetsProductionRate_(INIT_PACKET_PRODUCTION_RATE),
- perSecondFactor_(MILLI_IN_A_SEC / STATS_INTERVAL_DURATION),
- timer_on_(false) {
- srand((unsigned int)time(NULL));
- prodLabel_ = ((rand() % 255) << 24UL);
- interests_cache_timer_ =
- std::make_unique<asio::steady_timer>(this->getIoService());
- round_timer_ = std::make_unique<asio::steady_timer>(this->getIoService());
- setSocketOption(GeneralTransportOptions::OUTPUT_BUFFER_SIZE, 10000U);
- scheduleRoundTimer();
-}
-
-RTCProducerSocket::RTCProducerSocket()
- : ProducerSocket(),
+RTCProducerSocket::RTCProducerSocket(interface::ProducerSocket *producer_socket)
+ : ProducerSocket(producer_socket),
currentSeg_(1),
producedBytes_(0),
producedPackets_(0),
@@ -168,14 +150,15 @@ void RTCProducerSocket::produce(std::unique_ptr<utils::MemBuf> &&buffer) {
content_object->shared_from_this()));
if (on_content_object_in_output_buffer_) {
- on_content_object_in_output_buffer_(*this, *content_object);
+ on_content_object_in_output_buffer_(*getInterface(), *content_object);
}
- TRANSPORT_LOGD("Send content %u (produce)", content_object->getName().getSuffix());
+ TRANSPORT_LOGD("Send content %u (produce)",
+ content_object->getName().getSuffix());
portal_->sendContentObject(*content_object);
if (on_content_object_output_) {
- on_content_object_output_(*this, *content_object);
+ on_content_object_output_(*getInterface(), *content_object);
}
uint32_t old_curr = currentSeg_.load();
@@ -199,7 +182,7 @@ void RTCProducerSocket::onInterest(Interest::Ptr &&interest) {
uint32_t lifetime = interest->getLifetime();
if (on_interest_input_) {
- on_interest_input_(*this, *interest);
+ on_interest_input_(*getInterface(), *interest);
}
uint64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(
@@ -216,19 +199,20 @@ void RTCProducerSocket::onInterest(Interest::Ptr &&interest) {
if (content_object) {
if (on_interest_satisfied_output_buffer_) {
- on_interest_satisfied_output_buffer_(*this, *interest);
+ on_interest_satisfied_output_buffer_(*getInterface(), *interest);
}
if (on_content_object_output_) {
- on_content_object_output_(*this, *content_object);
+ on_content_object_output_(*getInterface(), *content_object);
}
- TRANSPORT_LOGD("Send content %u (onInterest)", content_object->getName().getSuffix());
+ TRANSPORT_LOGD("Send content %u (onInterest)",
+ content_object->getName().getSuffix());
portal_->sendContentObject(*content_object);
return;
} else {
if (on_interest_process_) {
- on_interest_process_(*this, *interest);
+ on_interest_process_(*getInterface(), *interest);
}
}
@@ -356,13 +340,13 @@ void RTCProducerSocket::sendNack(uint32_t sequence) {
nack.setPathLabel(prodLabel_);
if (on_content_object_output_) {
- on_content_object_output_(*this, nack);
+ on_content_object_output_(*getInterface(), nack);
}
TRANSPORT_LOGD("Send nack %u", sequence);
portal_->sendContentObject(nack);
}
-} // namespace interface
+} // namespace implementation
} // end namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h b/libtransport/src/implementation/rtc_socket_producer.h
index d7917a8c0..87db2121d 100644
--- a/libtransport/src/hicn/transport/interfaces/rtc_socket_producer.h
+++ b/libtransport/src/implementation/rtc_socket_producer.h
@@ -15,32 +15,27 @@
#pragma once
-#include <hicn/transport/interfaces/socket_producer.h>
-#include <hicn/transport/utils/content_store.h>
+#include <implementation/socket_producer.h>
+#include <utils/content_store.h>
#include <atomic>
#include <map>
#include <mutex>
namespace transport {
-
-namespace interface {
+namespace implementation {
class RTCProducerSocket : virtual public ProducerSocket {
public:
- RTCProducerSocket(asio::io_service &io_service);
-
- RTCProducerSocket();
+ RTCProducerSocket(interface::ProducerSocket *producer_socket);
~RTCProducerSocket();
void registerPrefix(const Prefix &producer_namespace) override;
-
- virtual void produce(std::unique_ptr<utils::MemBuf> &&buffer) override;
-
- void onInterest(Interest::Ptr &&interest) override;
+ void produce(std::unique_ptr<utils::MemBuf> &&buffer) override;
private:
+ void onInterest(Interest::Ptr &&interest) override;
void sendNack(uint32_t sequence);
void updateStats();
void scheduleCacheTimer(uint64_t wait);
@@ -66,14 +61,14 @@ class RTCProducerSocket : virtual public ProducerSocket {
// but for each sequence number we store only the smallest
// expiry time. In this way the mapping from seqs_map_ to
// timers_map_ is unique
- std::multimap<uint64_t,uint32_t> timers_map_;
+ std::multimap<uint64_t, uint32_t> timers_map_;
// this map does the opposite, this map is not ordered
- std::unordered_map<uint32_t,uint64_t> seqs_map_;
+ std::unordered_map<uint32_t, uint64_t> seqs_map_;
bool timer_on_;
std::unique_ptr<asio::steady_timer> interests_cache_timer_;
utils::SpinLock interests_cache_lock_;
};
-} // namespace interface
+} // namespace implementation
} // end namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/socket.h b/libtransport/src/implementation/socket.h
index 4c9bda7df..2e51f3027 100644
--- a/libtransport/src/hicn/transport/interfaces/socket.h
+++ b/libtransport/src/implementation/socket.h
@@ -16,11 +16,12 @@
#pragma once
#include <hicn/transport/config.h>
-#include <hicn/transport/core/facade.h>
#include <hicn/transport/interfaces/callbacks.h>
#include <hicn/transport/interfaces/socket_options_default_values.h>
#include <hicn/transport/interfaces/socket_options_keys.h>
+#include <core/facade.h>
+
#define SOCKET_OPTION_GET 0
#define SOCKET_OPTION_NOT_GET 1
#define SOCKET_OPTION_SET 2
@@ -28,8 +29,7 @@
#define SOCKET_OPTION_DEFAULT 12345
namespace transport {
-
-namespace interface {
+namespace implementation {
// Forward Declarations
template <typename PortalType>
@@ -82,11 +82,8 @@ class Socket {
protected:
virtual ~Socket(){};
-
- protected:
- std::string output_interface_;
};
-} // namespace interface
+} // namespace implementation
} // namespace transport
diff --git a/libtransport/src/implementation/socket_consumer.h b/libtransport/src/implementation/socket_consumer.h
new file mode 100644
index 000000000..2fc8d2b48
--- /dev/null
+++ b/libtransport/src/implementation/socket_consumer.h
@@ -0,0 +1,950 @@
+/*
+ * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hicn/transport/interfaces/socket_consumer.h>
+#include <hicn/transport/interfaces/socket_options_default_values.h>
+#include <hicn/transport/interfaces/statistics.h>
+#include <hicn/transport/security/verifier.h>
+
+#include <protocols/cbr.h>
+#include <protocols/protocol.h>
+#include <protocols/raaqm.h>
+#include <protocols/rtc.h>
+#include <utils/event_thread.h>
+
+namespace transport {
+namespace implementation {
+
+using namespace core;
+using namespace interface;
+using ReadCallback = interface::ConsumerSocket::ReadCallback;
+
+class ConsumerSocket : public Socket<BasePortal> {
+ public:
+ ConsumerSocket(interface::ConsumerSocket *consumer, int protocol)
+ : consumer_interface_(consumer),
+ portal_(std::make_shared<Portal>(io_service_)),
+ async_downloader_(),
+ interest_lifetime_(default_values::interest_lifetime),
+ min_window_size_(default_values::min_window_size),
+ max_window_size_(default_values::max_window_size),
+ current_window_size_(-1),
+ max_retransmissions_(
+ default_values::transport_protocol_max_retransmissions),
+ /****** RAAQM Parameters ******/
+ minimum_drop_probability_(default_values::minimum_drop_probability),
+ sample_number_(default_values::sample_number),
+ gamma_(default_values::gamma_value),
+ beta_(default_values::beta_value),
+ drop_factor_(default_values::drop_factor),
+ /****** END RAAQM Parameters ******/
+ rate_estimation_alpha_(default_values::rate_alpha),
+ rate_estimation_observer_(nullptr),
+ rate_estimation_batching_parameter_(default_values::batch),
+ rate_estimation_choice_(0),
+ verifier_(std::make_shared<utils::Verifier>()),
+ verify_signature_(false),
+ key_content_(false),
+ on_interest_output_(VOID_HANDLER),
+ on_interest_timeout_(VOID_HANDLER),
+ on_interest_satisfied_(VOID_HANDLER),
+ on_content_object_input_(VOID_HANDLER),
+ on_content_object_verification_(VOID_HANDLER),
+ on_content_object_(VOID_HANDLER),
+ stats_summary_(VOID_HANDLER),
+ read_callback_(nullptr),
+ virtual_download_(false),
+ timer_interval_milliseconds_(0),
+ guard_raaqm_params_() {
+ switch (protocol) {
+ case TransportProtocolAlgorithms::CBR:
+ transport_protocol_ =
+ std::make_unique<protocol::CbrTransportProtocol>(this);
+ break;
+ case TransportProtocolAlgorithms::RTC:
+ transport_protocol_ =
+ std::make_unique<protocol::RTCTransportProtocol>(this);
+ break;
+ case TransportProtocolAlgorithms::RAAQM:
+ default:
+ transport_protocol_ =
+ std::make_unique<protocol::RaaqmTransportProtocol>(this);
+ break;
+ }
+ }
+
+ ~ConsumerSocket() {
+ stop();
+ async_downloader_.stop();
+ }
+
+ interface::ConsumerSocket *getInterface() {
+ return consumer_interface_;
+ }
+
+ void setInterface(interface::ConsumerSocket *consumer_socket) {
+ consumer_interface_ = consumer_socket;
+ }
+
+ void connect() { portal_->connect(); }
+
+ bool isRunning() { return transport_protocol_->isRunning(); }
+
+ virtual int consume(const Name &name) {
+ if (transport_protocol_->isRunning()) {
+ return CONSUMER_BUSY;
+ }
+
+ network_name_ = name;
+ network_name_.setSuffix(0);
+
+ transport_protocol_->start();
+
+ return CONSUMER_FINISHED;
+ }
+
+ virtual int asyncConsume(const Name &name) {
+ if (!async_downloader_.stopped()) {
+ async_downloader_.add([this, name]() {
+ network_name_ = std::move(name);
+ network_name_.setSuffix(0);
+ transport_protocol_->start();
+ });
+ }
+
+ return CONSUMER_RUNNING;
+ }
+
+ bool verifyKeyPackets() { return transport_protocol_->verifyKeyPackets(); }
+
+ void stop() {
+ if (transport_protocol_->isRunning()) {
+ transport_protocol_->stop();
+ }
+ }
+
+ void resume() {
+ if (!transport_protocol_->isRunning()) {
+ transport_protocol_->resume();
+ }
+ }
+
+ asio::io_service &getIoService() { return portal_->getIoService(); }
+
+ virtual int setSocketOption(int socket_option_key,
+ ReadCallback *socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in
+ // case setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ReadCallback *socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::READ_CALLBACK:
+ read_callback_ = socket_option_value;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ });
+ }
+
+ int getSocketOption(int socket_option_key,
+ ReadCallback **socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in
+ // case setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ReadCallback **socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::READ_CALLBACK:
+ *socket_option_value = read_callback_;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ });
+ }
+
+ int setSocketOption(int socket_option_key, double socket_option_value) {
+ utils::SpinLock::Acquire locked(guard_raaqm_params_);
+ switch (socket_option_key) {
+ case MIN_WINDOW_SIZE:
+ min_window_size_ = socket_option_value;
+ break;
+
+ case MAX_WINDOW_SIZE:
+ max_window_size_ = socket_option_value;
+ break;
+
+ case CURRENT_WINDOW_SIZE:
+ current_window_size_ = socket_option_value;
+ break;
+
+ case GAMMA_VALUE:
+ gamma_ = socket_option_value;
+ break;
+
+ case BETA_VALUE:
+ beta_ = socket_option_value;
+ break;
+
+ case DROP_FACTOR:
+ drop_factor_ = socket_option_value;
+ break;
+
+ case MINIMUM_DROP_PROBABILITY:
+ minimum_drop_probability_ = socket_option_value;
+ break;
+
+ case RATE_ESTIMATION_ALPHA:
+ if (socket_option_value >= 0 && socket_option_value < 1) {
+ rate_estimation_alpha_ = socket_option_value;
+ } else {
+ rate_estimation_alpha_ = default_values::alpha;
+ }
+ break;
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ }
+
+ int setSocketOption(int socket_option_key, uint32_t socket_option_value) {
+ utils::SpinLock::Acquire locked(guard_raaqm_params_);
+ switch (socket_option_key) {
+ case GeneralTransportOptions::MAX_INTEREST_RETX:
+ max_retransmissions_ = socket_option_value;
+ break;
+
+ case GeneralTransportOptions::INTEREST_LIFETIME:
+ interest_lifetime_ = socket_option_value;
+ break;
+
+ case RateEstimationOptions::RATE_ESTIMATION_BATCH_PARAMETER:
+ if (socket_option_value > 0) {
+ rate_estimation_batching_parameter_ = socket_option_value;
+ } else {
+ rate_estimation_batching_parameter_ = default_values::batch;
+ }
+ break;
+
+ case RateEstimationOptions::RATE_ESTIMATION_CHOICE:
+ if (socket_option_value > 0) {
+ rate_estimation_choice_ = socket_option_value;
+ } else {
+ rate_estimation_choice_ = default_values::rate_choice;
+ }
+ break;
+
+ case GeneralTransportOptions::STATS_INTERVAL:
+ timer_interval_milliseconds_ = socket_option_value;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ }
+
+ int setSocketOption(int socket_option_key,
+ std::nullptr_t socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in
+ // case setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ std::nullptr_t socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::INTEREST_RETRANSMISSION:
+ if (socket_option_value == VOID_HANDLER) {
+ on_interest_retransmission_ = VOID_HANDLER;
+ break;
+ }
+
+ case ConsumerCallbacksOptions::INTEREST_EXPIRED:
+ if (socket_option_value == VOID_HANDLER) {
+ on_interest_timeout_ = VOID_HANDLER;
+ break;
+ }
+
+ case ConsumerCallbacksOptions::INTEREST_SATISFIED:
+ if (socket_option_value == VOID_HANDLER) {
+ on_interest_satisfied_ = VOID_HANDLER;
+ break;
+ }
+
+ case ConsumerCallbacksOptions::INTEREST_OUTPUT:
+ if (socket_option_value == VOID_HANDLER) {
+ on_interest_output_ = VOID_HANDLER;
+ break;
+ }
+
+ case ConsumerCallbacksOptions::CONTENT_OBJECT_INPUT:
+ if (socket_option_value == VOID_HANDLER) {
+ on_content_object_input_ = VOID_HANDLER;
+ break;
+ }
+
+ case ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY:
+ if (socket_option_value == VOID_HANDLER) {
+ on_content_object_verification_ = VOID_HANDLER;
+ break;
+ }
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ });
+ }
+
+ int setSocketOption(int socket_option_key, bool socket_option_value) {
+ int result = SOCKET_OPTION_NOT_SET;
+ if (!transport_protocol_->isRunning()) {
+ switch (socket_option_key) {
+ case OtherOptions::VIRTUAL_DOWNLOAD:
+ virtual_download_ = socket_option_value;
+ result = SOCKET_OPTION_SET;
+ break;
+
+ case GeneralTransportOptions::VERIFY_SIGNATURE:
+ verify_signature_ = socket_option_value;
+ result = SOCKET_OPTION_SET;
+ break;
+
+ case GeneralTransportOptions::KEY_CONTENT:
+ key_content_ = socket_option_value;
+ result = SOCKET_OPTION_SET;
+ break;
+
+ default:
+ return result;
+ }
+ }
+ return result;
+ }
+
+ int setSocketOption(int socket_option_key,
+ ConsumerContentObjectCallback socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in
+ // case setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ConsumerContentObjectCallback socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::CONTENT_OBJECT_INPUT:
+ on_content_object_input_ = socket_option_value;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ });
+ }
+
+ int setSocketOption(
+ int socket_option_key,
+ ConsumerContentObjectVerificationCallback socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in
+ // case setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ConsumerContentObjectVerificationCallback socket_option_value)
+ -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY:
+ on_content_object_verification_ = socket_option_value;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ });
+ }
+
+ int setSocketOption(int socket_option_key,
+ ConsumerInterestCallback socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in
+ // case setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ConsumerInterestCallback socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::INTEREST_RETRANSMISSION:
+ on_interest_retransmission_ = socket_option_value;
+ break;
+
+ case ConsumerCallbacksOptions::INTEREST_OUTPUT:
+ on_interest_output_ = socket_option_value;
+ break;
+
+ case ConsumerCallbacksOptions::INTEREST_EXPIRED:
+ on_interest_timeout_ = socket_option_value;
+ break;
+
+ case ConsumerCallbacksOptions::INTEREST_SATISFIED:
+ on_interest_satisfied_ = socket_option_value;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ });
+ }
+
+ int setSocketOption(
+ int socket_option_key,
+ ConsumerContentObjectVerificationFailedCallback socket_option_value) {
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](
+ int socket_option_key,
+ ConsumerContentObjectVerificationFailedCallback socket_option_value)
+ -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::VERIFICATION_FAILED:
+ verification_failed_callback_ = socket_option_value;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ });
+ }
+
+ // int setSocketOption(
+ // int socket_option_key,
+ // ConsumerContentObjectVerificationFailedCallback socket_option_value) {
+ // return rescheduleOnIOService(
+ // socket_option_key, socket_option_value,
+ // [this](
+ // int socket_option_key,
+ // ConsumerContentObjectVerificationFailedCallback
+ // socket_option_value)
+ // -> int {
+ // switch (socket_option_key) {
+ // case ConsumerCallbacksOptions::VERIFICATION_FAILED:
+ // verification_failed_callback_ = socket_option_value;
+ // break;
+
+ // default:
+ // return SOCKET_OPTION_NOT_SET;
+ // }
+
+ // return SOCKET_OPTION_SET;
+ // });
+ // }
+
+ int setSocketOption(int socket_option_key, IcnObserver *socket_option_value) {
+ utils::SpinLock::Acquire locked(guard_raaqm_params_);
+ switch (socket_option_key) {
+ case RateEstimationOptions::RATE_ESTIMATION_OBSERVER:
+ rate_estimation_observer_ = socket_option_value;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ }
+
+ int setSocketOption(
+ int socket_option_key,
+ const std::shared_ptr<utils::Verifier> &socket_option_value) {
+ int result = SOCKET_OPTION_NOT_SET;
+ if (!transport_protocol_->isRunning()) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::VERIFIER:
+ verifier_.reset();
+ verifier_ = socket_option_value;
+ result = SOCKET_OPTION_SET;
+ break;
+ default:
+ return result;
+ }
+ }
+
+ return result;
+ }
+
+ int setSocketOption(int socket_option_key,
+ const std::string &socket_option_value) {
+ int result = SOCKET_OPTION_NOT_SET;
+ if (!transport_protocol_->isRunning()) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::CERTIFICATE:
+ key_id_ = verifier_->addKeyFromCertificate(socket_option_value);
+
+ if (key_id_ != nullptr) {
+ result = SOCKET_OPTION_SET;
+ }
+ break;
+
+ case DataLinkOptions::OUTPUT_INTERFACE:
+ output_interface_ = socket_option_value;
+ portal_->setOutputInterface(output_interface_);
+ result = SOCKET_OPTION_SET;
+ break;
+
+ default:
+ return result;
+ }
+ }
+ return result;
+ }
+
+ int setSocketOption(int socket_option_key,
+ ConsumerTimerCallback socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in
+ // case setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ConsumerTimerCallback socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::STATS_SUMMARY:
+ stats_summary_ = socket_option_value;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ });
+ }
+
+ int getSocketOption(int socket_option_key, double &socket_option_value) {
+ utils::SpinLock::Acquire locked(guard_raaqm_params_);
+ switch (socket_option_key) {
+ case GeneralTransportOptions::MIN_WINDOW_SIZE:
+ socket_option_value = min_window_size_;
+ break;
+
+ case GeneralTransportOptions::MAX_WINDOW_SIZE:
+ socket_option_value = max_window_size_;
+ break;
+
+ case GeneralTransportOptions::CURRENT_WINDOW_SIZE:
+ socket_option_value = current_window_size_;
+ break;
+
+ // RAAQM parameters
+
+ case RaaqmTransportOptions::GAMMA_VALUE:
+ socket_option_value = gamma_;
+ break;
+
+ case RaaqmTransportOptions::BETA_VALUE:
+ socket_option_value = beta_;
+ break;
+
+ case RaaqmTransportOptions::DROP_FACTOR:
+ socket_option_value = drop_factor_;
+ break;
+
+ case RaaqmTransportOptions::MINIMUM_DROP_PROBABILITY:
+ socket_option_value = minimum_drop_probability_;
+ break;
+
+ case RateEstimationOptions::RATE_ESTIMATION_ALPHA:
+ socket_option_value = rate_estimation_alpha_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ int getSocketOption(int socket_option_key, uint32_t &socket_option_value) {
+ utils::SpinLock::Acquire locked(guard_raaqm_params_);
+ switch (socket_option_key) {
+ case GeneralTransportOptions::MAX_INTEREST_RETX:
+ socket_option_value = max_retransmissions_;
+ break;
+
+ case GeneralTransportOptions::INTEREST_LIFETIME:
+ socket_option_value = interest_lifetime_;
+ break;
+
+ case RaaqmTransportOptions::SAMPLE_NUMBER:
+ socket_option_value = sample_number_;
+ break;
+
+ case RateEstimationOptions::RATE_ESTIMATION_BATCH_PARAMETER:
+ socket_option_value = rate_estimation_batching_parameter_;
+ break;
+
+ case RateEstimationOptions::RATE_ESTIMATION_CHOICE:
+ socket_option_value = rate_estimation_choice_;
+ break;
+
+ case GeneralTransportOptions::STATS_INTERVAL:
+ socket_option_value = timer_interval_milliseconds_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ int getSocketOption(int socket_option_key, bool &socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::RUNNING:
+ socket_option_value = transport_protocol_->isRunning();
+ break;
+
+ case OtherOptions::VIRTUAL_DOWNLOAD:
+ socket_option_value = virtual_download_;
+ break;
+
+ case GeneralTransportOptions::VERIFY_SIGNATURE:
+ socket_option_value = verify_signature_;
+ break;
+
+ case GeneralTransportOptions::KEY_CONTENT:
+ socket_option_value = key_content_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ int getSocketOption(int socket_option_key, Name **socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::NETWORK_NAME:
+ *socket_option_value = &network_name_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ int getSocketOption(int socket_option_key,
+ ConsumerContentObjectCallback **socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in
+ // case setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ConsumerContentObjectCallback **socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::CONTENT_OBJECT_INPUT:
+ *socket_option_value = &on_content_object_input_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ });
+ }
+
+ int getSocketOption(
+ int socket_option_key,
+ ConsumerContentObjectVerificationCallback **socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in
+ // case setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ConsumerContentObjectVerificationCallback **socket_option_value)
+ -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::CONTENT_OBJECT_TO_VERIFY:
+ *socket_option_value = &on_content_object_verification_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ });
+ }
+
+ int getSocketOption(int socket_option_key,
+ ConsumerInterestCallback **socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in
+ // case setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ConsumerInterestCallback **socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::INTEREST_RETRANSMISSION:
+ *socket_option_value = &on_interest_retransmission_;
+ break;
+
+ case ConsumerCallbacksOptions::INTEREST_OUTPUT:
+ *socket_option_value = &on_interest_output_;
+ break;
+
+ case ConsumerCallbacksOptions::INTEREST_EXPIRED:
+ *socket_option_value = &on_interest_timeout_;
+ break;
+
+ case ConsumerCallbacksOptions::INTEREST_SATISFIED:
+ *socket_option_value = &on_interest_satisfied_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ });
+ }
+
+ int getSocketOption(
+ int socket_option_key,
+ ConsumerContentObjectVerificationFailedCallback **socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in
+ // case setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ConsumerContentObjectVerificationFailedCallback *
+ *socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::VERIFICATION_FAILED:
+ *socket_option_value = &verification_failed_callback_;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ });
+ }
+
+ int getSocketOption(int socket_option_key,
+ std::shared_ptr<Portal> &socket_option_value) {
+ switch (socket_option_key) {
+ case PORTAL:
+ socket_option_value = portal_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ int getSocketOption(int socket_option_key,
+ IcnObserver **socket_option_value) {
+ utils::SpinLock::Acquire locked(guard_raaqm_params_);
+ switch (socket_option_key) {
+ case RateEstimationOptions::RATE_ESTIMATION_OBSERVER:
+ *socket_option_value = (rate_estimation_observer_);
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ int getSocketOption(int socket_option_key,
+ std::shared_ptr<utils::Verifier> &socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::VERIFIER:
+ socket_option_value = verifier_;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ int getSocketOption(int socket_option_key, std::string &socket_option_value) {
+ switch (socket_option_key) {
+ case DataLinkOptions::OUTPUT_INTERFACE:
+ socket_option_value = output_interface_;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ int getSocketOption(int socket_option_key,
+ interface::TransportStatistics **socket_option_value) {
+ switch (socket_option_key) {
+ case OtherOptions::STATISTICS:
+ *socket_option_value = &stats_;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ int getSocketOption(int socket_option_key,
+ ConsumerTimerCallback **socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in
+ // case setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ConsumerTimerCallback **socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ConsumerCallbacksOptions::STATS_SUMMARY:
+ *socket_option_value = &stats_summary_;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ });
+ }
+
+ protected:
+ template <typename Lambda, typename arg2>
+ int rescheduleOnIOService(int socket_option_key, arg2 socket_option_value,
+ Lambda lambda_func) {
+ // To enforce type check
+ std::function<int(int, arg2)> func = lambda_func;
+ int result = SOCKET_OPTION_SET;
+ if (transport_protocol_->isRunning()) {
+ std::mutex mtx;
+ /* Condition variable for the wait */
+ std::condition_variable cv;
+ bool done = false;
+ io_service_.dispatch([&socket_option_key, &socket_option_value, &mtx, &cv,
+ &result, &done, &func]() {
+ std::unique_lock<std::mutex> lck(mtx);
+ done = true;
+ result = func(socket_option_key, socket_option_value);
+ cv.notify_all();
+ });
+ std::unique_lock<std::mutex> lck(mtx);
+ if (!done) {
+ cv.wait(lck);
+ }
+ } else {
+ result = func(socket_option_key, socket_option_value);
+ }
+
+ return result;
+ }
+
+ protected:
+ interface::ConsumerSocket *consumer_interface_;
+ asio::io_service io_service_;
+
+ std::shared_ptr<Portal> portal_;
+ utils::EventThread async_downloader_;
+
+ // No need to protect from multiple accesses in the async consumer
+ // The parameter is accessible only with a getSocketOption and
+ // set from the consume
+ Name network_name_;
+
+ int interest_lifetime_;
+
+ double min_window_size_;
+ double max_window_size_;
+ double current_window_size_;
+ uint32_t max_retransmissions_;
+
+ // RAAQM Parameters
+ double minimum_drop_probability_;
+ unsigned int sample_number_;
+ double gamma_;
+ double beta_;
+ double drop_factor_;
+
+ // Rate estimation parameters
+ double rate_estimation_alpha_;
+ IcnObserver *rate_estimation_observer_;
+ int rate_estimation_batching_parameter_;
+ int rate_estimation_choice_;
+
+ bool is_async_;
+
+ // Verification parameters
+ std::shared_ptr<utils::Verifier> verifier_;
+ PARCKeyId *key_id_;
+ std::atomic_bool verify_signature_;
+ bool key_content_;
+
+ ConsumerInterestCallback on_interest_retransmission_;
+ ConsumerInterestCallback on_interest_output_;
+ ConsumerInterestCallback on_interest_timeout_;
+ ConsumerInterestCallback on_interest_satisfied_;
+ ConsumerContentObjectCallback on_content_object_input_;
+ ConsumerContentObjectVerificationCallback on_content_object_verification_;
+ ConsumerContentObjectCallback on_content_object_;
+ ConsumerTimerCallback stats_summary_;
+ ConsumerContentObjectVerificationFailedCallback verification_failed_callback_;
+
+ ReadCallback *read_callback_;
+
+ // Virtual download for traffic generator
+ bool virtual_download_;
+
+ uint32_t timer_interval_milliseconds_;
+
+ // Transport protocol
+ std::unique_ptr<protocol::TransportProtocol> transport_protocol_;
+
+ // Statistic
+ TransportStatistics stats_;
+
+ utils::SpinLock guard_raaqm_params_;
+ std::string output_interface_;
+};
+
+} // namespace implementation
+} // namespace transport \ No newline at end of file
diff --git a/libtransport/src/implementation/socket_producer.h b/libtransport/src/implementation/socket_producer.h
new file mode 100644
index 000000000..1f03fe53d
--- /dev/null
+++ b/libtransport/src/implementation/socket_producer.h
@@ -0,0 +1,1061 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <hicn/transport/security/signer.h>
+
+#include <implementation/socket.h>
+
+#include <utils/content_store.h>
+#include <utils/event_thread.h>
+#include <utils/suffix_strategy.h>
+
+#include <atomic>
+#include <cmath>
+#include <condition_variable>
+#include <mutex>
+#include <queue>
+#include <thread>
+
+#define REGISTRATION_NOT_ATTEMPTED 0
+#define REGISTRATION_SUCCESS 1
+#define REGISTRATION_FAILURE 2
+#define REGISTRATION_IN_PROGRESS 3
+
+namespace transport {
+namespace implementation {
+
+using namespace core;
+using namespace interface;
+
+class ProducerSocket : public Socket<BasePortal>,
+ public BasePortal::ProducerCallback {
+ public:
+ explicit ProducerSocket(interface::ProducerSocket *producer_socket)
+ : producer_interface_(producer_socket),
+ portal_(std::make_shared<Portal>(io_service_)),
+ data_packet_size_(default_values::content_object_packet_size),
+ content_object_expiry_time_(default_values::content_object_expiry_time),
+ output_buffer_(default_values::producer_socket_output_buffer_size),
+ async_thread_(),
+ registration_status_(REGISTRATION_NOT_ATTEMPTED),
+ making_manifest_(false),
+ hash_algorithm_(HashAlgorithm::SHA_256),
+ suffix_strategy_(core::NextSegmentCalculationStrategy::INCREMENTAL),
+ on_interest_input_(VOID_HANDLER),
+ on_interest_dropped_input_buffer_(VOID_HANDLER),
+ on_interest_inserted_input_buffer_(VOID_HANDLER),
+ on_interest_satisfied_output_buffer_(VOID_HANDLER),
+ on_interest_process_(VOID_HANDLER),
+ on_new_segment_(VOID_HANDLER),
+ on_content_object_to_sign_(VOID_HANDLER),
+ on_content_object_in_output_buffer_(VOID_HANDLER),
+ on_content_object_output_(VOID_HANDLER),
+ on_content_object_evicted_from_output_buffer_(VOID_HANDLER),
+ on_content_produced_(VOID_HANDLER) {}
+
+ virtual ~ProducerSocket() {
+ stop();
+ if (listening_thread_.joinable()) {
+ listening_thread_.join();
+ }
+ }
+
+ interface::ProducerSocket *getInterface() {
+ return producer_interface_;
+ }
+
+ void setInterface(interface::ProducerSocket *producer_socket) {
+ producer_interface_ = producer_socket;
+ }
+
+ void connect() override {
+ portal_->connect(false);
+ listening_thread_ = std::thread(std::bind(&ProducerSocket::listen, this));
+ }
+
+ bool isRunning() override { return !io_service_.stopped(); };
+
+ virtual uint32_t produce(Name content_name, const uint8_t *buffer,
+ size_t buffer_size, bool is_last = true,
+ uint32_t start_offset = 0) {
+ return ProducerSocket::produce(
+ content_name, utils::MemBuf::copyBuffer(buffer, buffer_size), is_last,
+ start_offset);
+ }
+
+ virtual uint32_t produce(Name content_name,
+ std::unique_ptr<utils::MemBuf> &&buffer,
+ bool is_last = true, uint32_t start_offset = 0) {
+ if (TRANSPORT_EXPECT_FALSE(buffer->length() == 0)) {
+ return 0;
+ }
+
+ // Copy the atomic variables to ensure they keep the same value
+ // during the production
+ std::size_t data_packet_size = data_packet_size_;
+ uint32_t content_object_expiry_time = content_object_expiry_time_;
+ HashAlgorithm hash_algo = hash_algorithm_;
+ bool making_manifest = making_manifest_;
+ auto suffix_strategy = utils::SuffixStrategyFactory::getSuffixStrategy(
+ suffix_strategy_, start_offset);
+ std::shared_ptr<utils::Signer> signer;
+ getSocketOption(GeneralTransportOptions::SIGNER, signer);
+
+ auto buffer_size = buffer->length();
+ int bytes_segmented = 0;
+ std::size_t header_size;
+ std::size_t manifest_header_size = 0;
+ std::size_t signature_length = 0;
+ std::uint32_t final_block_number = start_offset;
+ uint64_t free_space_for_content = 0;
+
+ core::Packet::Format format;
+ std::shared_ptr<ContentObjectManifest> manifest;
+ bool is_last_manifest = false;
+
+ // TODO Manifest may still be used for indexing
+ if (making_manifest && !signer) {
+ TRANSPORT_LOGD("Making manifests without setting producer identity.");
+ }
+
+ core::Packet::Format hf_format = core::Packet::Format::HF_UNSPEC;
+ core::Packet::Format hf_format_ah = core::Packet::Format::HF_UNSPEC;
+ if (content_name.getType() == HNT_CONTIGUOUS_V4 ||
+ content_name.getType() == HNT_IOV_V4) {
+ hf_format = core::Packet::Format::HF_INET_TCP;
+ hf_format_ah = core::Packet::Format::HF_INET_TCP_AH;
+ } else if (content_name.getType() == HNT_CONTIGUOUS_V6 ||
+ content_name.getType() == HNT_IOV_V6) {
+ hf_format = core::Packet::Format::HF_INET6_TCP;
+ hf_format_ah = core::Packet::Format::HF_INET6_TCP_AH;
+ } else {
+ throw errors::RuntimeException("Unknown name format.");
+ }
+
+ format = hf_format;
+ if (making_manifest) {
+ manifest_header_size = core::Packet::getHeaderSizeFromFormat(
+ signer ? hf_format_ah : hf_format,
+ signer ? signer->getSignatureLength() : 0);
+ } else if (signer) {
+ format = hf_format_ah;
+ signature_length = signer->getSignatureLength();
+ }
+
+ header_size =
+ core::Packet::getHeaderSizeFromFormat(format, signature_length);
+ free_space_for_content = data_packet_size - header_size;
+ uint32_t number_of_segments = uint32_t(
+ std::ceil(double(buffer_size) / double(free_space_for_content)));
+ if (free_space_for_content * number_of_segments < buffer_size) {
+ number_of_segments++;
+ }
+
+ // TODO allocate space for all the headers
+ if (making_manifest) {
+ uint32_t segment_in_manifest = static_cast<uint32_t>(
+ std::floor(double(data_packet_size - manifest_header_size -
+ ContentObjectManifest::getManifestHeaderSize()) /
+ ContentObjectManifest::getManifestEntrySize()) -
+ 1.0);
+ uint32_t number_of_manifests = static_cast<uint32_t>(
+ std::ceil(float(number_of_segments) / segment_in_manifest));
+ final_block_number += number_of_segments + number_of_manifests - 1;
+
+ manifest.reset(ContentObjectManifest::createManifest(
+ content_name.setSuffix(suffix_strategy->getNextManifestSuffix()),
+ core::ManifestVersion::VERSION_1, core::ManifestType::INLINE_MANIFEST,
+ hash_algo, is_last_manifest, content_name, suffix_strategy_,
+ signer ? signer->getSignatureLength() : 0));
+ manifest->setLifetime(content_object_expiry_time);
+
+ if (is_last) {
+ manifest->setFinalBlockNumber(final_block_number);
+ } else {
+ manifest->setFinalBlockNumber(utils::SuffixStrategy::INVALID_SUFFIX);
+ }
+ }
+
+ TRANSPORT_LOGD("--------- START PRODUCE ----------");
+ for (unsigned int packaged_segments = 0;
+ packaged_segments < number_of_segments; packaged_segments++) {
+ if (making_manifest) {
+ if (manifest->estimateManifestSize(2) >
+ data_packet_size - manifest_header_size) {
+ // Send the current manifest
+ manifest->encode();
+
+ // If identity set, sign manifest
+ if (signer) {
+ signer->sign(*manifest);
+ }
+
+ passContentObjectToCallbacks(manifest);
+ TRANSPORT_LOGD("Send manifest %u", manifest->getName().getSuffix());
+
+ // Send content objects stored in the queue
+ while (!content_queue_.empty()) {
+ passContentObjectToCallbacks(content_queue_.front());
+ TRANSPORT_LOGD("Send content %u",
+ content_queue_.front()->getName().getSuffix());
+ content_queue_.pop();
+ }
+
+ // Create new manifest. The reference to the last manifest has been
+ // acquired in the passContentObjectToCallbacks function, so we can
+ // safely release this reference
+ manifest.reset(ContentObjectManifest::createManifest(
+ content_name.setSuffix(suffix_strategy->getNextManifestSuffix()),
+ core::ManifestVersion::VERSION_1,
+ core::ManifestType::INLINE_MANIFEST, hash_algo, is_last_manifest,
+ content_name, suffix_strategy_,
+ signer ? signer->getSignatureLength() : 0));
+
+ manifest->setLifetime(content_object_expiry_time);
+ manifest->setFinalBlockNumber(
+ is_last ? final_block_number
+ : utils::SuffixStrategy::INVALID_SUFFIX);
+ }
+ }
+
+ auto content_suffix = suffix_strategy->getNextContentSuffix();
+ auto content_object = std::make_shared<ContentObject>(
+ content_name.setSuffix(content_suffix), format);
+ content_object->setLifetime(content_object_expiry_time);
+
+ auto b = buffer->cloneOne();
+ b->trimStart(free_space_for_content * packaged_segments);
+ b->trimEnd(b->length());
+
+ if (TRANSPORT_EXPECT_FALSE(packaged_segments == number_of_segments - 1)) {
+ b->append(buffer_size - bytes_segmented);
+ bytes_segmented += (int)(buffer_size - bytes_segmented);
+
+ if (is_last && making_manifest) {
+ is_last_manifest = true;
+ } else if (is_last) {
+ content_object->setRst();
+ }
+
+ } else {
+ b->append(free_space_for_content);
+ bytes_segmented += (int)(free_space_for_content);
+ }
+
+ content_object->appendPayload(std::move(b));
+
+ if (making_manifest) {
+ using namespace std::chrono_literals;
+ utils::CryptoHash hash = content_object->computeDigest(hash_algo);
+ manifest->addSuffixHash(content_suffix, hash);
+ content_queue_.push(content_object);
+ } else {
+ if (signer) {
+ signer->sign(*content_object);
+ }
+ passContentObjectToCallbacks(content_object);
+ TRANSPORT_LOGD("Send content %u",
+ content_object->getName().getSuffix());
+ }
+ }
+
+ if (making_manifest) {
+ if (is_last_manifest) {
+ manifest->setFinalManifest(is_last_manifest);
+ }
+
+ manifest->encode();
+ if (signer) {
+ signer->sign(*manifest);
+ }
+
+ passContentObjectToCallbacks(manifest);
+ TRANSPORT_LOGD("Send manifest %u", manifest->getName().getSuffix());
+ while (!content_queue_.empty()) {
+ passContentObjectToCallbacks(content_queue_.front());
+ TRANSPORT_LOGD("Send content %u",
+ content_queue_.front()->getName().getSuffix());
+ content_queue_.pop();
+ }
+ }
+
+ io_service_.dispatch([this, buffer_size]() {
+ if (on_content_produced_) {
+ on_content_produced_(*producer_interface_,
+ std::make_error_code(std::errc(0)), buffer_size);
+ }
+ });
+
+ TRANSPORT_LOGD("--------- END PRODUCE ------------");
+ return suffix_strategy->getTotalCount();
+ }
+
+ virtual void produce(ContentObject &content_object) {
+ io_service_.dispatch([this, &content_object]() {
+ if (on_content_object_in_output_buffer_) {
+ on_content_object_in_output_buffer_(*producer_interface_,
+ content_object);
+ }
+ });
+
+ output_buffer_.insert(std::static_pointer_cast<ContentObject>(
+ content_object.shared_from_this()));
+
+ io_service_.dispatch([this, &content_object]() {
+ if (on_content_object_output_) {
+ on_content_object_output_(*producer_interface_, content_object);
+ }
+ });
+
+ portal_->sendContentObject(content_object);
+ }
+
+ virtual void produce(const uint8_t *buffer, size_t buffer_size) {
+ produce(utils::MemBuf::copyBuffer(buffer, buffer_size));
+ }
+
+ virtual void produce(std::unique_ptr<utils::MemBuf> &&buffer) {
+ // This API is meant to be used just with the RTC producer.
+ // Here it cannot be used since no name for the content is specified.
+ throw errors::NotImplementedException();
+ }
+
+ virtual void asyncProduce(const Name &suffix, const uint8_t *buf,
+ size_t buffer_size, bool is_last = true,
+ uint32_t *start_offset = nullptr) {
+ if (!async_thread_.stopped()) {
+ async_thread_.add([this, suffix, buffer = buf, size = buffer_size,
+ is_last, start_offset]() {
+ if (start_offset != nullptr) {
+ *start_offset = ProducerSocket::produce(suffix, buffer, size, is_last,
+ *start_offset);
+ } else {
+ ProducerSocket::produce(suffix, buffer, size, is_last, 0);
+ }
+ });
+ }
+ }
+
+ void asyncProduce(const Name &suffix);
+
+ virtual void asyncProduce(Name content_name,
+ std::unique_ptr<utils::MemBuf> &&buffer,
+ bool is_last, uint32_t offset,
+ uint32_t **last_segment = nullptr) {
+ if (!async_thread_.stopped()) {
+ auto a = buffer.release();
+ async_thread_.add(
+ [this, content_name, a, is_last, offset, last_segment]() {
+ auto buf = std::unique_ptr<utils::MemBuf>(a);
+ if (last_segment != NULL) {
+ **last_segment =
+ offset + ProducerSocket::produce(content_name, std::move(buf),
+ is_last, offset);
+ } else {
+ ProducerSocket::produce(content_name, std::move(buf), is_last,
+ offset);
+ }
+ });
+ }
+ }
+
+ virtual void asyncProduce(ContentObject &content_object) {
+ if (!async_thread_.stopped()) {
+ auto co_ptr = std::static_pointer_cast<ContentObject>(
+ content_object.shared_from_this());
+ async_thread_.add([this, content_object = std::move(co_ptr)]() {
+ ProducerSocket::produce(*content_object);
+ });
+ }
+ }
+
+ virtual void registerPrefix(const Prefix &producer_namespace) {
+ served_namespaces_.push_back(producer_namespace);
+ }
+
+ void serveForever() {
+ if (listening_thread_.joinable()) {
+ listening_thread_.join();
+ }
+ }
+
+ void stop() { portal_->stopEventsLoop(); }
+
+ asio::io_service &getIoService() override { return portal_->getIoService(); };
+
+ virtual void onInterest(Interest &interest) {
+ if (on_interest_input_) {
+ on_interest_input_(*producer_interface_, interest);
+ }
+
+ const std::shared_ptr<ContentObject> content_object =
+ output_buffer_.find(interest);
+
+ if (content_object) {
+ if (on_interest_satisfied_output_buffer_) {
+ on_interest_satisfied_output_buffer_(*producer_interface_, interest);
+ }
+
+ if (on_content_object_output_) {
+ on_content_object_output_(*producer_interface_, *content_object);
+ }
+
+ portal_->sendContentObject(*content_object);
+ } else {
+ if (on_interest_process_) {
+ on_interest_process_(*producer_interface_, interest);
+ }
+ }
+ }
+
+ virtual void onInterest(Interest::Ptr &&interest) override {
+ onInterest(*interest);
+ };
+
+ virtual int setSocketOption(int socket_option_key,
+ uint32_t socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::DATA_PACKET_SIZE:
+ if (socket_option_value < default_values::max_content_object_size &&
+ socket_option_value > 0) {
+ data_packet_size_ = socket_option_value;
+ }
+ break;
+
+ case GeneralTransportOptions::OUTPUT_BUFFER_SIZE:
+ output_buffer_.setLimit(socket_option_value);
+ break;
+
+ case GeneralTransportOptions::CONTENT_OBJECT_EXPIRY_TIME:
+ content_object_expiry_time_ = socket_option_value;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ }
+
+ virtual int setSocketOption(int socket_option_key,
+ std::nullptr_t socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in case
+ // setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ProducerContentObjectCallback socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ProducerCallbacksOptions::INTEREST_INPUT:
+ if (socket_option_value == VOID_HANDLER) {
+ on_interest_input_ = VOID_HANDLER;
+ break;
+ }
+
+ case ProducerCallbacksOptions::INTEREST_DROP:
+ if (socket_option_value == VOID_HANDLER) {
+ on_interest_dropped_input_buffer_ = VOID_HANDLER;
+ break;
+ }
+
+ case ProducerCallbacksOptions::INTEREST_PASS:
+ if (socket_option_value == VOID_HANDLER) {
+ on_interest_inserted_input_buffer_ = VOID_HANDLER;
+ break;
+ }
+
+ case ProducerCallbacksOptions::CACHE_HIT:
+ if (socket_option_value == VOID_HANDLER) {
+ on_interest_satisfied_output_buffer_ = VOID_HANDLER;
+ break;
+ }
+
+ case ProducerCallbacksOptions::CACHE_MISS:
+ if (socket_option_value == VOID_HANDLER) {
+ on_interest_process_ = VOID_HANDLER;
+ break;
+ }
+
+ case ProducerCallbacksOptions::NEW_CONTENT_OBJECT:
+ if (socket_option_value == VOID_HANDLER) {
+ on_new_segment_ = VOID_HANDLER;
+ break;
+ }
+
+ case ProducerCallbacksOptions::CONTENT_OBJECT_SIGN:
+ if (socket_option_value == VOID_HANDLER) {
+ on_content_object_to_sign_ = VOID_HANDLER;
+ break;
+ }
+
+ case ProducerCallbacksOptions::CONTENT_OBJECT_READY:
+ if (socket_option_value == VOID_HANDLER) {
+ on_content_object_in_output_buffer_ = VOID_HANDLER;
+ break;
+ }
+
+ case ProducerCallbacksOptions::CONTENT_OBJECT_OUTPUT:
+ if (socket_option_value == VOID_HANDLER) {
+ on_content_object_output_ = VOID_HANDLER;
+ break;
+ }
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ });
+ }
+
+ virtual int setSocketOption(int socket_option_key, bool socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::MAKE_MANIFEST:
+ making_manifest_ = socket_option_value;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ }
+
+ virtual int setSocketOption(int socket_option_key,
+ Name *socket_option_value) {
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ virtual int setSocketOption(int socket_option_key,
+ std::list<Prefix> socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::NETWORK_NAME:
+ served_namespaces_ = socket_option_value;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ }
+
+ virtual int setSocketOption(
+ int socket_option_key,
+ interface::ProducerContentObjectCallback socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in case
+ // setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ProducerContentObjectCallback socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ProducerCallbacksOptions::NEW_CONTENT_OBJECT:
+ on_new_segment_ = socket_option_value;
+ break;
+
+ case ProducerCallbacksOptions::CONTENT_OBJECT_SIGN:
+ on_content_object_to_sign_ = socket_option_value;
+ break;
+
+ case ProducerCallbacksOptions::CONTENT_OBJECT_READY:
+ on_content_object_in_output_buffer_ = socket_option_value;
+ break;
+
+ case ProducerCallbacksOptions::CONTENT_OBJECT_OUTPUT:
+ on_content_object_output_ = socket_option_value;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ });
+ }
+
+ virtual int setSocketOption(
+ int socket_option_key,
+ interface::ProducerInterestCallback socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in case
+ // setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ProducerInterestCallback socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ProducerCallbacksOptions::INTEREST_INPUT:
+ on_interest_input_ = socket_option_value;
+ break;
+
+ case ProducerCallbacksOptions::INTEREST_DROP:
+ on_interest_dropped_input_buffer_ = socket_option_value;
+ break;
+
+ case ProducerCallbacksOptions::INTEREST_PASS:
+ on_interest_inserted_input_buffer_ = socket_option_value;
+ break;
+
+ case ProducerCallbacksOptions::CACHE_HIT:
+ on_interest_satisfied_output_buffer_ = socket_option_value;
+ break;
+
+ case ProducerCallbacksOptions::CACHE_MISS:
+ on_interest_process_ = socket_option_value;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ });
+ }
+
+ virtual int setSocketOption(
+ int socket_option_key,
+ interface::ProducerContentCallback socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in case
+ // setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ProducerContentCallback socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ProducerCallbacksOptions::CONTENT_PRODUCED:
+ on_content_produced_ = socket_option_value;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ });
+ }
+
+ virtual int setSocketOption(int socket_option_key,
+ HashAlgorithm socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::HASH_ALGORITHM:
+ hash_algorithm_ = socket_option_value;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ }
+
+ virtual int setSocketOption(int socket_option_key,
+ utils::CryptoSuite socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::CRYPTO_SUITE:
+ crypto_suite_ = socket_option_value;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ }
+
+ virtual int setSocketOption(
+ int socket_option_key,
+ const std::shared_ptr<utils::Signer> &socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::SIGNER: {
+ utils::SpinLock::Acquire locked(signer_lock_);
+ signer_.reset();
+ signer_ = socket_option_value;
+ } break;
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_SET;
+ }
+
+ virtual int getSocketOption(int socket_option_key,
+ uint32_t &socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::OUTPUT_BUFFER_SIZE:
+ socket_option_value = (uint32_t)output_buffer_.getLimit();
+ break;
+
+ case GeneralTransportOptions::DATA_PACKET_SIZE:
+ socket_option_value = (uint32_t)data_packet_size_;
+ break;
+
+ case GeneralTransportOptions::CONTENT_OBJECT_EXPIRY_TIME:
+ socket_option_value = content_object_expiry_time_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ virtual int getSocketOption(int socket_option_key,
+ bool &socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::MAKE_MANIFEST:
+ socket_option_value = making_manifest_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ virtual int getSocketOption(int socket_option_key,
+ std::list<Prefix> &socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::NETWORK_NAME:
+ socket_option_value = served_namespaces_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ virtual int getSocketOption(
+ int socket_option_key,
+ interface::ProducerContentObjectCallback **socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in case
+ // setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ProducerContentObjectCallback **socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ProducerCallbacksOptions::NEW_CONTENT_OBJECT:
+ *socket_option_value = &on_new_segment_;
+ break;
+
+ case ProducerCallbacksOptions::CONTENT_OBJECT_SIGN:
+ *socket_option_value = &on_content_object_to_sign_;
+ break;
+
+ case ProducerCallbacksOptions::CONTENT_OBJECT_READY:
+ *socket_option_value = &on_content_object_in_output_buffer_;
+ break;
+
+ case ProducerCallbacksOptions::CONTENT_OBJECT_OUTPUT:
+ *socket_option_value = &on_content_object_output_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ });
+ }
+
+ virtual int getSocketOption(
+ int socket_option_key,
+ interface::ProducerContentCallback **socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in case
+ // setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ProducerContentCallback **socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ProducerCallbacksOptions::CONTENT_PRODUCED:
+ *socket_option_value = &on_content_produced_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ });
+ }
+
+ virtual int getSocketOption(
+ int socket_option_key,
+ interface::ProducerInterestCallback **socket_option_value) {
+ // Reschedule the function on the io_service to avoid race condition in case
+ // setSocketOption is called while the io_service is running.
+ return rescheduleOnIOService(
+ socket_option_key, socket_option_value,
+ [this](int socket_option_key,
+ ProducerInterestCallback **socket_option_value) -> int {
+ switch (socket_option_key) {
+ case ProducerCallbacksOptions::INTEREST_INPUT:
+ *socket_option_value = &on_interest_input_;
+ break;
+
+ case ProducerCallbacksOptions::INTEREST_DROP:
+ *socket_option_value = &on_interest_dropped_input_buffer_;
+ break;
+
+ case ProducerCallbacksOptions::INTEREST_PASS:
+ *socket_option_value = &on_interest_inserted_input_buffer_;
+ break;
+
+ case CACHE_HIT:
+ *socket_option_value = &on_interest_satisfied_output_buffer_;
+ break;
+
+ case CACHE_MISS:
+ *socket_option_value = &on_interest_process_;
+ break;
+
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ });
+ }
+
+ virtual int getSocketOption(int socket_option_key,
+ std::shared_ptr<Portal> &socket_option_value) {
+ switch (socket_option_key) {
+ case PORTAL:
+ socket_option_value = portal_;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ ;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ virtual int getSocketOption(int socket_option_key,
+ HashAlgorithm &socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::HASH_ALGORITHM:
+ socket_option_value = hash_algorithm_;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ virtual int getSocketOption(int socket_option_key,
+ utils::CryptoSuite &socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::HASH_ALGORITHM:
+ socket_option_value = crypto_suite_;
+ break;
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ virtual int getSocketOption(
+ int socket_option_key,
+ std::shared_ptr<utils::Signer> &socket_option_value) {
+ switch (socket_option_key) {
+ case GeneralTransportOptions::SIGNER: {
+ utils::SpinLock::Acquire locked(signer_lock_);
+ socket_option_value = signer_;
+ } break;
+ default:
+ return SOCKET_OPTION_NOT_GET;
+ }
+
+ return SOCKET_OPTION_GET;
+ }
+
+ virtual int setSocketOption(int socket_option_key,
+ const std::string &socket_option_value) {
+ return SOCKET_OPTION_NOT_SET;
+ }
+
+ // If the thread calling lambda_func is not the same of io_service, this
+ // function reschedule the function on it
+ template <typename Lambda, typename arg2>
+ int rescheduleOnIOService(int socket_option_key, arg2 socket_option_value,
+ Lambda lambda_func) {
+ // To enforce type check
+ std::function<int(int, arg2)> func = lambda_func;
+ int result = SOCKET_OPTION_SET;
+ if (listening_thread_.joinable() &&
+ std::this_thread::get_id() != listening_thread_.get_id()) {
+ std::mutex mtx;
+ /* Condition variable for the wait */
+ std::condition_variable cv;
+ bool done = false;
+ io_service_.dispatch([&socket_option_key, &socket_option_value, &mtx, &cv,
+ &result, &done, &func]() {
+ std::unique_lock<std::mutex> lck(mtx);
+ done = true;
+ result = func(socket_option_key, socket_option_value);
+ cv.notify_all();
+ });
+ std::unique_lock<std::mutex> lck(mtx);
+ if (!done) {
+ cv.wait(lck);
+ }
+ } else {
+ result = func(socket_option_key, socket_option_value);
+ }
+
+ return result;
+ }
+
+ // If the thread calling lambda_func is not the same of io_service, this
+ // function reschedule the function on it
+ template <typename Lambda, typename arg2>
+ int rescheduleOnIOServiceWithReference(int socket_option_key,
+ arg2 &socket_option_value,
+ Lambda lambda_func) {
+ // To enforce type check
+ std::function<int(int, arg2 &)> func = lambda_func;
+ int result = SOCKET_OPTION_SET;
+ if (listening_thread_.joinable() &&
+ std::this_thread::get_id() != this->listening_thread_.get_id()) {
+ std::mutex mtx;
+ /* Condition variable for the wait */
+ std::condition_variable cv;
+ std::unique_lock<std::mutex> lck(mtx);
+ bool done = false;
+ io_service_.dispatch([&socket_option_key, &socket_option_value, &mtx, &cv,
+ &result, &done, &func]() {
+ std::unique_lock<std::mutex> lck(mtx);
+ done = true;
+ result = func(socket_option_key, socket_option_value);
+
+ if (!done) {
+ cv.wait(lck);
+ }
+ });
+ } else {
+ result = func(socket_option_key, socket_option_value);
+ }
+
+ return result;
+ }
+
+ // Threads
+ protected:
+ interface::ProducerSocket *producer_interface_;
+ std::thread listening_thread_;
+ asio::io_service io_service_;
+ std::shared_ptr<Portal> portal_;
+ std::atomic<size_t> data_packet_size_;
+ std::list<Prefix>
+ served_namespaces_; // No need to be threadsafe, this is always modified
+ // by the application thread
+ std::atomic<uint32_t> content_object_expiry_time_;
+
+ // buffers
+ // ContentStore is thread-safe
+ utils::ContentStore output_buffer_;
+
+ utils::EventThread async_thread_;
+ int registration_status_;
+
+ std::atomic<bool> making_manifest_;
+
+ // map for storing sequence numbers for several calls of the publish
+ // function
+ std::unordered_map<Name, std::unordered_map<int, uint32_t>> seq_number_map_;
+
+ std::atomic<HashAlgorithm> hash_algorithm_;
+ std::atomic<utils::CryptoSuite> crypto_suite_;
+ utils::SpinLock signer_lock_;
+ std::shared_ptr<utils::Signer> signer_;
+ core::NextSegmentCalculationStrategy suffix_strategy_;
+
+ // While manifests are being built, contents are stored in a queue
+ std::queue<std::shared_ptr<ContentObject>> content_queue_;
+
+ // callbacks
+ ProducerInterestCallback on_interest_input_;
+ ProducerInterestCallback on_interest_dropped_input_buffer_;
+ ProducerInterestCallback on_interest_inserted_input_buffer_;
+ ProducerInterestCallback on_interest_satisfied_output_buffer_;
+ ProducerInterestCallback on_interest_process_;
+
+ ProducerContentObjectCallback on_new_segment_;
+ ProducerContentObjectCallback on_content_object_to_sign_;
+ ProducerContentObjectCallback on_content_object_in_output_buffer_;
+ ProducerContentObjectCallback on_content_object_output_;
+ ProducerContentObjectCallback on_content_object_evicted_from_output_buffer_;
+
+ ProducerContentCallback on_content_produced_;
+
+ private:
+ void listen() {
+ bool first = true;
+
+ for (core::Prefix &producer_namespace : served_namespaces_) {
+ if (first) {
+ core::BindConfig bind_config(producer_namespace, 1000);
+ portal_->bind(bind_config);
+ portal_->setProducerCallback(this);
+ first = !first;
+ } else {
+ portal_->registerRoute(producer_namespace);
+ }
+ }
+
+ portal_->runEventsLoop();
+ }
+
+ void passContentObjectToCallbacks(
+ const std::shared_ptr<ContentObject> &content_object) {
+ if (content_object) {
+ io_service_.dispatch([this, content_object]() {
+ if (on_new_segment_) {
+ on_new_segment_(*producer_interface_, *content_object);
+ }
+
+ if (on_content_object_to_sign_) {
+ on_content_object_to_sign_(*producer_interface_, *content_object);
+ }
+
+ if (on_content_object_in_output_buffer_) {
+ on_content_object_in_output_buffer_(*producer_interface_,
+ *content_object);
+ }
+ });
+
+ output_buffer_.insert(content_object);
+
+ io_service_.dispatch([this, content_object]() {
+ if (on_content_object_output_) {
+ on_content_object_output_(*producer_interface_, *content_object);
+ }
+ });
+
+ portal_->sendContentObject(*content_object);
+ }
+ }
+}; // namespace implementation
+
+} // namespace implementation
+
+} // namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/tls_rtc_socket_producer.cc b/libtransport/src/implementation/tls_rtc_socket_producer.cc
index 27c1e54bd..3b3152993 100644
--- a/libtransport/src/hicn/transport/interfaces/tls_rtc_socket_producer.cc
+++ b/libtransport/src/implementation/tls_rtc_socket_producer.cc
@@ -1,14 +1,31 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
#include <hicn/transport/core/interest.h>
#include <hicn/transport/interfaces/p2psecure_socket_producer.h>
-#include <hicn/transport/interfaces/tls_rtc_socket_producer.h>
+
+#include <implementation/p2psecure_socket_producer.h>
+#include <implementation/tls_rtc_socket_producer.h>
#include <openssl/bio.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
namespace transport {
+namespace implementation {
-namespace interface {
int TLSRTCProducerSocket::read(BIO *b, char *buf, size_t size,
size_t *readbytes) {
int ret;
@@ -99,7 +116,9 @@ int TLSRTCProducerSocket::writeOld(BIO *b, const char *buf, int num) {
on_content_produced_application);
if (socket->to_call_oncontentproduced_ == 0 &&
on_content_produced_application) {
- on_content_produced_application(*socket, std::error_code(), 0);
+ on_content_produced_application(
+ (transport::interface::ProducerSocket &)(*socket->getInterface()),
+ std::error_code(), 0);
}
});
}
@@ -107,9 +126,12 @@ int TLSRTCProducerSocket::writeOld(BIO *b, const char *buf, int num) {
return num;
}
-TLSRTCProducerSocket::TLSRTCProducerSocket(P2PSecureProducerSocket *parent,
- const Name &handshake_name)
- : RTCProducerSocket(), TLSProducerSocket(parent, handshake_name) {
+TLSRTCProducerSocket::TLSRTCProducerSocket(
+ interface::ProducerSocket *producer_socket, P2PSecureProducerSocket *parent,
+ const Name &handshake_name)
+ : ProducerSocket(producer_socket),
+ RTCProducerSocket(producer_socket),
+ TLSProducerSocket(producer_socket, parent, handshake_name) {
BIO_METHOD *bio_meth =
BIO_meth_new(BIO_TYPE_ACCEPT, "secure rtc producer socket");
BIO_meth_set_read(bio_meth, TLSRTCProducerSocket::readOld);
@@ -140,7 +162,8 @@ void TLSRTCProducerSocket::accept() {
if (on_interest_process_decrypted) {
Interest inter(std::move(packet_));
- on_interest_process_decrypted(*this, inter);
+ on_interest_process_decrypted(
+ (transport::interface::ProducerSocket &)(*getInterface()), inter);
}
parent_->cv_.notify_one();
@@ -173,6 +196,6 @@ void TLSRTCProducerSocket::produce(std::unique_ptr<utils::MemBuf> &&buffer) {
(void)i; // To shut up gcc 5
}
-} // namespace interface
+} // namespace implementation
} // namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/tls_rtc_socket_producer.h b/libtransport/src/implementation/tls_rtc_socket_producer.h
index 16125f889..685c91244 100644
--- a/libtransport/src/hicn/transport/interfaces/tls_rtc_socket_producer.h
+++ b/libtransport/src/implementation/tls_rtc_socket_producer.h
@@ -15,12 +15,11 @@
#pragma once
-#include <hicn/transport/interfaces/rtc_socket_producer.h>
-#include <hicn/transport/interfaces/tls_socket_producer.h>
+#include <implementation/rtc_socket_producer.h>
+#include <implementation/tls_socket_producer.h>
namespace transport {
-
-namespace interface {
+namespace implementation {
class P2PSecureProducerSocket;
@@ -29,7 +28,8 @@ class TLSRTCProducerSocket : public RTCProducerSocket,
friend class P2PSecureProducerSocket;
public:
- explicit TLSRTCProducerSocket(P2PSecureProducerSocket *parent,
+ explicit TLSRTCProducerSocket(interface::ProducerSocket *producer_socket,
+ P2PSecureProducerSocket *parent,
const Name &handshake_name);
~TLSRTCProducerSocket() = default;
@@ -40,8 +40,8 @@ class TLSRTCProducerSocket : public RTCProducerSocket,
int async_accept() override;
- using TLSProducerSocket::produce;
using TLSProducerSocket::onInterest;
+ using TLSProducerSocket::produce;
protected:
static int read(BIO *b, char *buf, size_t size, size_t *readbytes);
@@ -53,6 +53,6 @@ class TLSRTCProducerSocket : public RTCProducerSocket,
static int writeOld(BIO *h, const char *buf, int num);
};
-} // namespace interface
+} // namespace implementation
} // end namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/tls_socket_consumer.cc b/libtransport/src/implementation/tls_socket_consumer.cc
index 58b3c1d7d..95b287aa6 100644
--- a/libtransport/src/hicn/transport/interfaces/tls_socket_consumer.cc
+++ b/libtransport/src/implementation/tls_socket_consumer.cc
@@ -1,4 +1,20 @@
-#include <hicn/transport/interfaces/tls_socket_consumer.h>
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <implementation/tls_socket_consumer.h>
+
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/tls1.h>
@@ -6,10 +22,9 @@
#include <random>
namespace transport {
+namespace implementation {
-namespace interface {
-
-void TLSConsumerSocket::setInterestPayload(ConsumerSocket &c,
+void TLSConsumerSocket::setInterestPayload(interface::ConsumerSocket &c,
const core::Interest &interest) {
Interest &int2 = const_cast<Interest &>(interest);
random_suffix_ = int2.getName().getSuffix();
@@ -68,7 +83,7 @@ int readTLS(BIO *b, char *buf, size_t size, size_t *readbytes) {
if (size > INT_MAX) size = INT_MAX;
- ret = transport::interface::readOldTLS(b, buf, (int)size);
+ ret = readOldTLS(b, buf, (int)size);
if (ret <= 0) {
*readbytes = 0;
@@ -101,7 +116,7 @@ int writeTLS(BIO *b, const char *buf, size_t size, size_t *written) {
if (size > INT_MAX) size = INT_MAX;
- ret = transport::interface::writeOldTLS(b, buf, (int)size);
+ ret = writeOldTLS(b, buf, (int)size);
if (ret <= 0) {
*written = 0;
@@ -115,8 +130,9 @@ int writeTLS(BIO *b, const char *buf, size_t size, size_t *written) {
long ctrlTLS(BIO *b, int cmd, long num, void *ptr) { return 1; }
-TLSConsumerSocket::TLSConsumerSocket(int protocol, SSL *ssl)
- : ConsumerSocket(protocol),
+TLSConsumerSocket::TLSConsumerSocket(interface::ConsumerSocket *consumer_socket,
+ int protocol, SSL *ssl)
+ : ConsumerSocket(consumer_socket, protocol),
name_(),
buf_pool_(),
decrypted_content_(),
@@ -125,7 +141,6 @@ TLSConsumerSocket::TLSConsumerSocket(int protocol, SSL *ssl)
something_to_read_(false),
content_downloaded_(false),
random_suffix_(),
- secure_prefix_(),
producer_namespace_(),
read_callback_decrypted_(),
mtx_(),
@@ -153,9 +168,9 @@ TLSConsumerSocket::TLSConsumerSocket(int protocol, SSL *ssl)
BIO_METHOD *bio_meth =
BIO_meth_new(BIO_TYPE_CONNECT, "secure consumer socket");
- BIO_meth_set_read(bio_meth, transport::interface::readOldTLS);
- BIO_meth_set_write(bio_meth, transport::interface::writeOldTLS);
- BIO_meth_set_ctrl(bio_meth, transport::interface::ctrlTLS);
+ BIO_meth_set_read(bio_meth, readOldTLS);
+ BIO_meth_set_write(bio_meth, writeOldTLS);
+ BIO_meth_set_ctrl(bio_meth, ctrlTLS);
BIO *bio = BIO_new(bio_meth);
BIO_set_init(bio, 1);
BIO_set_data(bio, this);
@@ -176,6 +191,12 @@ TLSConsumerSocket::TLSConsumerSocket(int protocol, SSL *ssl)
this);
};
+/*
+ * The producer interface is not owned by the application, so is TLSSocket task
+ * to deallocate the memory
+ */
+TLSConsumerSocket::~TLSConsumerSocket() { delete consumer_interface_; }
+
int TLSConsumerSocket::consume(const Name &name,
std::unique_ptr<utils::MemBuf> &&buffer) {
this->payload_ = std::move(buffer);
@@ -308,12 +329,11 @@ void TLSConsumerSocket::registerPrefix(const Prefix &producer_namespace) {
producer_namespace_ = producer_namespace;
}
-int TLSConsumerSocket::setSocketOption(
- int socket_option_key, ConsumerSocket::ReadCallback *socket_option_value) {
+int TLSConsumerSocket::setSocketOption(int socket_option_key,
+ ReadCallback *socket_option_value) {
return rescheduleOnIOService(
socket_option_key, socket_option_value,
- [this](int socket_option_key,
- ConsumerSocket::ReadCallback *socket_option_value) -> int {
+ [this](int socket_option_key, ReadCallback *socket_option_value) -> int {
switch (socket_option_key) {
case ConsumerCallbacksOptions::READ_CALLBACK:
read_callback_decrypted_ = socket_option_value;
@@ -359,6 +379,6 @@ void TLSConsumerSocket::readSuccess(std::size_t total_size) noexcept {
bool TLSConsumerSocket::isBufferMovable() noexcept { return true; }
-} // namespace interface
+} // namespace implementation
} // namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/tls_socket_consumer.h b/libtransport/src/implementation/tls_socket_consumer.h
index 05f7fe6a5..2e88dc47e 100644
--- a/libtransport/src/hicn/transport/interfaces/tls_socket_consumer.h
+++ b/libtransport/src/implementation/tls_socket_consumer.h
@@ -16,14 +16,16 @@
#pragma once
#include <hicn/transport/interfaces/socket_consumer.h>
+
+#include <implementation/socket_consumer.h>
+
#include <openssl/ssl.h>
namespace transport {
-
-namespace interface {
+namespace implementation {
class TLSConsumerSocket : public ConsumerSocket,
- public ConsumerSocket::ReadCallback {
+ public interface::ConsumerSocket::ReadCallback {
/* Return the number of read bytes in readbytes */
friend int readTLS(BIO *b, char *buf, size_t size, size_t *readbytes);
@@ -39,9 +41,10 @@ class TLSConsumerSocket : public ConsumerSocket,
friend long ctrlTLS(BIO *b, int cmd, long num, void *ptr);
public:
- explicit TLSConsumerSocket(int protocol, SSL *ssl_);
+ explicit TLSConsumerSocket(interface::ConsumerSocket *consumer_socket,
+ int protocol, SSL *ssl_);
- ~TLSConsumerSocket() = default;
+ ~TLSConsumerSocket();
int consume(const Name &name, std::unique_ptr<utils::MemBuf> &&buffer);
int consume(const Name &name) override;
@@ -53,7 +56,7 @@ class TLSConsumerSocket : public ConsumerSocket,
int setSocketOption(
int socket_option_key,
- ConsumerSocket::ReadCallback *socket_option_value) override;
+ interface::ConsumerSocket::ReadCallback *socket_option_value) override;
using ConsumerSocket::getSocketOption;
using ConsumerSocket::setSocketOption;
@@ -76,7 +79,8 @@ class TLSConsumerSocket : public ConsumerSocket,
utils::ObjectPool<utils::MemBuf> buf_pool_;
std::unique_ptr<utils::MemBuf> decrypted_content_;
- /* Chain of MemBuf holding the payload to be written into interest or data */
+ /* Chain of MemBuf holding the payload to be written into interest or data
+ */
std::unique_ptr<utils::MemBuf> payload_;
/* Chain of MemBuf holding the data retrieved from the underlying layer */
@@ -92,11 +96,9 @@ class TLSConsumerSocket : public ConsumerSocket,
uint32_t random_suffix_;
- ip_address_t secure_prefix_;
-
Prefix producer_namespace_;
- ConsumerSocket::ReadCallback *read_callback_decrypted_;
+ interface::ConsumerSocket::ReadCallback *read_callback_decrypted_;
std::mutex mtx_;
@@ -105,9 +107,8 @@ class TLSConsumerSocket : public ConsumerSocket,
utils::EventThread async_downloader_tls_;
- void setInterestPayload(ConsumerSocket &c, const core::Interest &interest);
- void processPayload(ConsumerSocket &c, std::size_t bytes_transferred,
- const std::error_code &ec);
+ void setInterestPayload(interface::ConsumerSocket &c,
+ const core::Interest &interest);
virtual void getReadBuffer(uint8_t **application_buffer,
size_t *max_length) override;
@@ -127,6 +128,6 @@ class TLSConsumerSocket : public ConsumerSocket,
int download_content(const Name &name);
};
-} // namespace interface
+} // namespace implementation
} // end namespace transport \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/interfaces/tls_socket_producer.cc b/libtransport/src/implementation/tls_socket_producer.cc
index ad85ec6ea..9a5b94a1c 100644
--- a/libtransport/src/hicn/transport/interfaces/tls_socket_producer.cc
+++ b/libtransport/src/implementation/tls_socket_producer.cc
@@ -1,14 +1,29 @@
-#include <hicn/transport/core/interest.h>
-#include <hicn/transport/interfaces/p2psecure_socket_producer.h>
-#include <hicn/transport/interfaces/tls_socket_producer.h>
+/*
+ * Copyright (c) 2017-2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hicn/transport/interfaces/socket_producer.h>
+
+#include <implementation/p2psecure_socket_producer.h>
+#include <implementation/tls_socket_producer.h>
#include <openssl/bio.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
namespace transport {
-
-namespace interface {
+namespace implementation {
/* Return the number of read bytes in readbytes */
int TLSProducerSocket::read(BIO *b, char *buf, size_t size, size_t *readbytes) {
@@ -113,7 +128,8 @@ int TLSProducerSocket::writeOld(BIO *b, const char *buf, int num) {
on_content_produced_application);
if (socket->to_call_oncontentproduced_ == 0 &&
on_content_produced_application) {
- on_content_produced_application(*socket, std::error_code(), 0);
+ on_content_produced_application(*socket->getInterface(),
+ std::error_code(), 0);
}
});
}
@@ -121,9 +137,10 @@ int TLSProducerSocket::writeOld(BIO *b, const char *buf, int num) {
return num;
}
-TLSProducerSocket::TLSProducerSocket(P2PSecureProducerSocket *parent,
+TLSProducerSocket::TLSProducerSocket(interface::ProducerSocket *producer_socket,
+ P2PSecureProducerSocket *parent,
const Name &handshake_name)
- : ProducerSocket(),
+ : ProducerSocket(producer_socket),
on_content_produced_application_(),
mtx_(),
cv_(),
@@ -196,6 +213,12 @@ TLSProducerSocket::TLSProducerSocket(P2PSecureProducerSocket *parent,
std::placeholders::_2, std::placeholders::_3));
}
+/*
+ * The producer interface is not owned by the application, so is TLSSocket task
+ * to deallocate the memory
+ */
+TLSProducerSocket::~TLSProducerSocket() { delete producer_interface_; }
+
void TLSProducerSocket::accept() {
if (SSL_in_before(ssl_) || SSL_in_init(ssl_)) {
tls_chunks_ = 1;
@@ -214,7 +237,7 @@ void TLSProducerSocket::accept() {
if (on_interest_process_decrypted) {
Interest inter(std::move(packet_));
- on_interest_process_decrypted(*this, inter);
+ on_interest_process_decrypted(*getInterface(), inter);
} else {
throw errors::RuntimeException(
"On interest process unset. Unable to perform handshake");
@@ -262,10 +285,11 @@ void TLSProducerSocket::onInterest(ProducerSocket &p, Interest &interest) {
getSocketOption(ProducerCallbacksOptions::INTEREST_INPUT,
on_interest_input_decrypted);
if (on_interest_input_decrypted)
- (on_interest_input_decrypted)(*this, interest);
+ (on_interest_input_decrypted)(*getInterface(), interest);
}
-void TLSProducerSocket::cacheMiss(ProducerSocket &p, Interest &interest) {
+void TLSProducerSocket::cacheMiss(interface::ProducerSocket &p,
+ Interest &interest) {
if (SSL_in_before(ssl_) || SSL_in_init(ssl_)) {
std::unique_lock<std::mutex> lck(mtx_);
name_ = interest.getName();
@@ -286,11 +310,11 @@ void TLSProducerSocket::cacheMiss(ProducerSocket &p, Interest &interest) {
interest.getPayload()->length());
if (on_interest_process_decrypted_ != VOID_HANDLER)
- on_interest_process_decrypted_(*this, interest);
+ on_interest_process_decrypted_(*getInterface(), interest);
}
}
-void TLSProducerSocket::onContentProduced(ProducerSocket &p,
+void TLSProducerSocket::onContentProduced(interface::ProducerSocket &p,
const std::error_code &err,
uint64_t bytes_written) {}
@@ -582,6 +606,6 @@ int TLSProducerSocket::getSocketOption(
});
}
-} // namespace interface
+} // namespace implementation
} // namespace transport
diff --git a/libtransport/src/hicn/transport/interfaces/tls_socket_producer.h b/libtransport/src/implementation/tls_socket_producer.h
index 4c09ddaa5..e910c8259 100644
--- a/libtransport/src/hicn/transport/interfaces/tls_socket_producer.h
+++ b/libtransport/src/implementation/tls_socket_producer.h
@@ -15,16 +15,14 @@
#pragma once
-#include <hicn/transport/interfaces/socket_producer.h>
-#include <hicn/transport/utils/content_store.h>
+#include <implementation/socket_producer.h>
#include <openssl/ssl.h>
#include <condition_variable>
#include <mutex>
namespace transport {
-
-namespace interface {
+namespace implementation {
class P2PSecureProducerSocket;
@@ -32,9 +30,11 @@ class TLSProducerSocket : virtual public ProducerSocket {
friend class P2PSecureProducerSocket;
public:
- explicit TLSProducerSocket(P2PSecureProducerSocket *parent,
+ explicit TLSProducerSocket(interface::ProducerSocket *producer_socket,
+ P2PSecureProducerSocket *parent,
const Name &handshake_name);
- ~TLSProducerSocket() = default;
+
+ ~TLSProducerSocket();
uint32_t produce(Name content_name, const uint8_t *buffer, size_t buffer_size,
bool is_last = true, uint32_t start_offset = 0) override {
@@ -125,7 +125,7 @@ class TLSProducerSocket : virtual public ProducerSocket {
utils::EventThread encryption_thread_;
void onInterest(ProducerSocket &p, Interest &interest);
- void cacheMiss(ProducerSocket &p, Interest &interest);
+ void cacheMiss(interface::ProducerSocket &p, Interest &interest);
/* Return the number of read bytes in readbytes */
static int read(BIO *b, char *buf, size_t size, size_t *readbytes);
@@ -154,10 +154,10 @@ class TLSProducerSocket : virtual public ProducerSocket {
size_t inlen, X509 *x, size_t chainidx, int *al,
void *add_arg);
- void onContentProduced(ProducerSocket &p, const std::error_code &err,
- uint64_t bytes_written);
+ void onContentProduced(interface::ProducerSocket &p,
+ const std::error_code &err, uint64_t bytes_written);
};
-} // namespace interface
+} // namespace implementation
} // end namespace transport
diff --git a/libtransport/src/interfaces/CMakeLists.txt b/libtransport/src/interfaces/CMakeLists.txt
new file mode 100644
index 000000000..daf4b31e5
--- /dev/null
+++ b/libtransport/src/interfaces/CMakeLists.txt
@@ -0,0 +1,39 @@
+# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+
+list(APPEND SOURCE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/rtc_socket_producer.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/socket_producer.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/socket_consumer.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/callbacks.cc
+)
+
+if (${OPENSSL_VERSION} VERSION_EQUAL "1.1.1a" OR ${OPENSSL_VERSION} VERSION_GREATER "1.1.1a")
+ list(APPEND SOURCE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/p2psecure_socket_producer.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/p2psecure_socket_consumer.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/tls_rtc_socket_producer.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/tls_socket_producer.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/tls_socket_consumer.cc
+ )
+
+ list(APPEND HEADER_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/tls_rtc_socket_producer.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/tls_socket_producer.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/tls_socket_consumer.h
+ )
+endif()
+
+set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
diff --git a/libtransport/src/hicn/transport/interfaces/callbacks.cc b/libtransport/src/interfaces/callbacks.cc
index 2574e7720..6869ac3f7 100644
--- a/libtransport/src/hicn/transport/interfaces/callbacks.cc
+++ b/libtransport/src/interfaces/callbacks.cc
@@ -13,7 +13,7 @@
* limitations under the License.
*/
-#include "callbacks.h"
+#include <hicn/transport/interfaces/callbacks.h>
namespace transport {
diff --git a/libtransport/src/interfaces/p2psecure_socket_consumer.cc b/libtransport/src/interfaces/p2psecure_socket_consumer.cc
new file mode 100644
index 000000000..2fa8bb6e3
--- /dev/null
+++ b/libtransport/src/interfaces/p2psecure_socket_consumer.cc
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hicn/transport/interfaces/p2psecure_socket_consumer.h>
+
+#include <implementation/p2psecure_socket_consumer.h>
+
+namespace transport {
+namespace interface {
+
+P2PSecureConsumerSocket::P2PSecureConsumerSocket(int handshake_protocol,
+ int protocol)
+ : ConsumerSocket() {
+ socket_ = std::unique_ptr<implementation::ConsumerSocket>(
+ new implementation::P2PSecureConsumerSocket(this, handshake_protocol,
+ protocol));
+}
+
+} // namespace interface
+} // namespace transport
diff --git a/libtransport/src/interfaces/p2psecure_socket_producer.cc b/libtransport/src/interfaces/p2psecure_socket_producer.cc
new file mode 100644
index 000000000..37352259c
--- /dev/null
+++ b/libtransport/src/interfaces/p2psecure_socket_producer.cc
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hicn/transport/interfaces/p2psecure_socket_producer.h>
+
+#include <implementation/p2psecure_socket_producer.h>
+
+namespace transport {
+namespace interface {
+
+P2PSecureProducerSocket::P2PSecureProducerSocket() {
+ socket_ = std::make_unique<implementation::P2PSecureProducerSocket>(this);
+}
+
+P2PSecureProducerSocket::P2PSecureProducerSocket(
+ bool rtc, const std::shared_ptr<utils::Identity> &identity) {
+ socket_ = std::make_unique<implementation::P2PSecureProducerSocket>(this, rtc,
+ identity);
+}
+
+} // namespace interface
+} // namespace transport
diff --git a/libtransport/src/interfaces/rtc_socket_producer.cc b/libtransport/src/interfaces/rtc_socket_producer.cc
new file mode 100644
index 000000000..07d72db7e
--- /dev/null
+++ b/libtransport/src/interfaces/rtc_socket_producer.cc
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hicn/transport/interfaces/rtc_socket_producer.h>
+
+#include <implementation/rtc_socket_producer.h>
+
+namespace transport {
+namespace interface {
+
+RTCProducerSocket::RTCProducerSocket() : ProducerSocket(false) {
+ socket_ = std::make_unique<implementation::RTCProducerSocket>(this);
+}
+
+} // namespace interface
+
+} // namespace transport
diff --git a/libtransport/src/interfaces/socket_consumer.cc b/libtransport/src/interfaces/socket_consumer.cc
new file mode 100644
index 000000000..b4be16ade
--- /dev/null
+++ b/libtransport/src/interfaces/socket_consumer.cc
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hicn/transport/interfaces/socket_consumer.h>
+
+#include <implementation/socket_consumer.h>
+
+namespace transport {
+namespace interface {
+
+ConsumerSocket::ConsumerSocket(int protocol) {
+ socket_ = std::make_unique<implementation::ConsumerSocket>(this, protocol);
+}
+
+ConsumerSocket::ConsumerSocket() {}
+
+ConsumerSocket::~ConsumerSocket() { socket_->stop(); }
+
+void ConsumerSocket::connect() { socket_->connect(); }
+
+bool ConsumerSocket::isRunning() { return socket_->isRunning(); }
+
+int ConsumerSocket::consume(const Name &name) { return socket_->consume(name); }
+
+int ConsumerSocket::asyncConsume(const Name &name) {
+ return socket_->asyncConsume(name);
+}
+
+void ConsumerSocket::stop() { socket_->stop(); }
+
+void ConsumerSocket::resume() { socket_->resume(); }
+
+bool ConsumerSocket::verifyKeyPackets() { return socket_->verifyKeyPackets(); }
+
+asio::io_service &ConsumerSocket::getIoService() {
+ return socket_->getIoService();
+}
+
+int ConsumerSocket::setSocketOption(int socket_option_key,
+ ReadCallback *socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(int socket_option_key,
+ ReadCallback **socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::setSocketOption(int socket_option_key,
+ double socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::setSocketOption(int socket_option_key,
+ uint32_t socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::setSocketOption(int socket_option_key,
+ std::nullptr_t socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::setSocketOption(int socket_option_key,
+ bool socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::setSocketOption(
+ int socket_option_key, ConsumerContentObjectCallback socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::setSocketOption(
+ int socket_option_key,
+ ConsumerContentObjectVerificationCallback socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::setSocketOption(
+ int socket_option_key, ConsumerInterestCallback socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::setSocketOption(
+ int socket_option_key,
+ ConsumerContentObjectVerificationFailedCallback socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::setSocketOption(int socket_option_key,
+ IcnObserver *socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::setSocketOption(
+ int socket_option_key,
+ const std::shared_ptr<utils::Verifier> &socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::setSocketOption(int socket_option_key,
+ const std::string &socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::setSocketOption(int socket_option_key,
+ ConsumerTimerCallback socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(int socket_option_key,
+ double &socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(int socket_option_key,
+ uint32_t &socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(int socket_option_key,
+ bool &socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(int socket_option_key,
+ Name **socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(
+ int socket_option_key,
+ ConsumerContentObjectCallback **socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(
+ int socket_option_key,
+ ConsumerContentObjectVerificationCallback **socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(
+ int socket_option_key, ConsumerInterestCallback **socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(
+ int socket_option_key,
+ ConsumerContentObjectVerificationFailedCallback **socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(int socket_option_key,
+ IcnObserver **socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(
+ int socket_option_key,
+ std::shared_ptr<utils::Verifier> &socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(int socket_option_key,
+ std::string &socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(
+ int socket_option_key,
+ interface::TransportStatistics **socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ConsumerSocket::getSocketOption(
+ int socket_option_key, ConsumerTimerCallback **socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+} // namespace interface
+
+} // namespace transport
diff --git a/libtransport/src/interfaces/socket_producer.cc b/libtransport/src/interfaces/socket_producer.cc
new file mode 100644
index 000000000..679f7ccf4
--- /dev/null
+++ b/libtransport/src/interfaces/socket_producer.cc
@@ -0,0 +1,198 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hicn/transport/interfaces/socket_producer.h>
+
+#include <implementation/socket_producer.h>
+
+#include <atomic>
+#include <cmath>
+#include <condition_variable>
+#include <mutex>
+#include <queue>
+#include <thread>
+
+namespace transport {
+
+namespace interface {
+
+using namespace core;
+
+ProducerSocket::ProducerSocket(int protocol) {
+ if (protocol != 0) {
+ throw std::runtime_error("Production protocol must be 0.");
+ }
+
+ socket_ = std::make_unique<implementation::ProducerSocket>(this);
+}
+
+ProducerSocket::ProducerSocket(bool) {}
+
+ProducerSocket::~ProducerSocket() { socket_->stop(); }
+
+void ProducerSocket::connect() { socket_->connect(); }
+
+bool ProducerSocket::isRunning() { return socket_->isRunning(); }
+
+uint32_t ProducerSocket::produce(Name content_name,
+ std::unique_ptr<utils::MemBuf> &&buffer,
+ bool is_last, uint32_t start_offset) {
+ return socket_->produce(content_name, std::move(buffer), is_last,
+ start_offset);
+}
+
+void ProducerSocket::produce(ContentObject &content_object) {
+ return socket_->produce(content_object);
+}
+
+void ProducerSocket::produce(std::unique_ptr<utils::MemBuf> &&buffer) {
+ socket_->produce(std::move(buffer));
+}
+
+void ProducerSocket::asyncProduce(Name content_name,
+ std::unique_ptr<utils::MemBuf> &&buffer,
+ bool is_last, uint32_t offset,
+ uint32_t **last_segment) {
+ return socket_->asyncProduce(content_name, std::move(buffer), is_last, offset,
+ last_segment);
+}
+
+void ProducerSocket::asyncProduce(ContentObject &content_object) {
+ return socket_->asyncProduce(content_object);
+}
+
+void ProducerSocket::registerPrefix(const Prefix &producer_namespace) {
+ return socket_->registerPrefix(producer_namespace);
+}
+
+void ProducerSocket::serveForever() { return socket_->serveForever(); }
+
+void ProducerSocket::stop() { return socket_->stop(); }
+
+asio::io_service &ProducerSocket::getIoService() {
+ return socket_->getIoService();
+};
+
+int ProducerSocket::setSocketOption(int socket_option_key,
+ uint32_t socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::setSocketOption(int socket_option_key,
+ std::nullptr_t socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::setSocketOption(int socket_option_key,
+ bool socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::setSocketOption(int socket_option_key,
+ Name *socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::setSocketOption(int socket_option_key,
+ std::list<Prefix> socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::setSocketOption(
+ int socket_option_key, ProducerContentObjectCallback socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::setSocketOption(
+ int socket_option_key, ProducerInterestCallback socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::setSocketOption(
+ int socket_option_key, ProducerContentCallback socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::setSocketOption(int socket_option_key,
+ HashAlgorithm socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::setSocketOption(int socket_option_key,
+ utils::CryptoSuite socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::setSocketOption(
+ int socket_option_key,
+ const std::shared_ptr<utils::Signer> &socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::getSocketOption(int socket_option_key,
+ uint32_t &socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::setSocketOption(int socket_option_key,
+ const std::string &socket_option_value) {
+ return socket_->setSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::getSocketOption(int socket_option_key,
+ bool &socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::getSocketOption(int socket_option_key,
+ std::list<Prefix> &socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::getSocketOption(
+ int socket_option_key,
+ ProducerContentObjectCallback **socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::getSocketOption(
+ int socket_option_key, ProducerContentCallback **socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::getSocketOption(
+ int socket_option_key, ProducerInterestCallback **socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::getSocketOption(int socket_option_key,
+ HashAlgorithm &socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::getSocketOption(int socket_option_key,
+ utils::CryptoSuite &socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+int ProducerSocket::getSocketOption(
+ int socket_option_key,
+ std::shared_ptr<utils::Signer> &socket_option_value) {
+ return socket_->getSocketOption(socket_option_key, socket_option_value);
+}
+
+} // namespace interface
+
+} // namespace transport
diff --git a/libtransport/src/interfaces/tls_rtc_socket_producer.cc b/libtransport/src/interfaces/tls_rtc_socket_producer.cc
new file mode 100644
index 000000000..132f34721
--- /dev/null
+++ b/libtransport/src/interfaces/tls_rtc_socket_producer.cc
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <interfaces/tls_rtc_socket_producer.h>
+
+#include <implementation/tls_rtc_socket_producer.h>
+
+namespace transport {
+namespace interface {
+
+TLSRTCProducerSocket::TLSRTCProducerSocket(
+ implementation::TLSRTCProducerSocket *implementation) {
+ socket_ =
+ std::unique_ptr<implementation::TLSRTCProducerSocket>(implementation);
+}
+
+TLSRTCProducerSocket::~TLSRTCProducerSocket() { socket_.release(); }
+
+} // namespace interface
+} // namespace transport
diff --git a/libtransport/src/interfaces/tls_rtc_socket_producer.h b/libtransport/src/interfaces/tls_rtc_socket_producer.h
new file mode 100644
index 000000000..434edb522
--- /dev/null
+++ b/libtransport/src/interfaces/tls_rtc_socket_producer.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <hicn/transport/interfaces/socket_producer.h>
+
+namespace transport {
+
+namespace implementation {
+class TLSRTCProducerSocket;
+}
+
+namespace interface {
+
+class TLSRTCProducerSocket : public ProducerSocket {
+ public:
+ TLSRTCProducerSocket(implementation::TLSRTCProducerSocket *implementation);
+ ~TLSRTCProducerSocket();
+};
+
+} // namespace interface
+
+} // end namespace transport \ No newline at end of file
diff --git a/libtransport/src/interfaces/tls_socket_consumer.cc b/libtransport/src/interfaces/tls_socket_consumer.cc
new file mode 100644
index 000000000..d87642f73
--- /dev/null
+++ b/libtransport/src/interfaces/tls_socket_consumer.cc
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <interfaces/tls_socket_consumer.h>
+
+#include <implementation/tls_socket_consumer.h>
+
+namespace transport {
+namespace interface {
+
+TLSConsumerSocket::TLSConsumerSocket(
+ implementation::TLSConsumerSocket *implementation) {
+ socket_ = std::unique_ptr<implementation::TLSConsumerSocket>(implementation);
+}
+
+TLSConsumerSocket::~TLSConsumerSocket() { socket_.release(); }
+
+} // namespace interface
+} // namespace transport
diff --git a/libtransport/src/interfaces/tls_socket_consumer.h b/libtransport/src/interfaces/tls_socket_consumer.h
new file mode 100644
index 000000000..845a9181f
--- /dev/null
+++ b/libtransport/src/interfaces/tls_socket_consumer.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <hicn/transport/interfaces/socket_consumer.h>
+
+namespace transport {
+
+namespace implementation {
+class TLSConsumerSocket;
+}
+
+namespace interface {
+
+class TLSConsumerSocket : public ConsumerSocket {
+ public:
+ TLSConsumerSocket(implementation::TLSConsumerSocket *implementation);
+ ~TLSConsumerSocket();
+};
+
+} // namespace interface
+
+} // end namespace transport
diff --git a/libtransport/src/interfaces/tls_socket_producer.cc b/libtransport/src/interfaces/tls_socket_producer.cc
new file mode 100644
index 000000000..44aa0cf8b
--- /dev/null
+++ b/libtransport/src/interfaces/tls_socket_producer.cc
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <interfaces/tls_socket_producer.h>
+
+#include <implementation/tls_socket_producer.h>
+
+namespace transport {
+namespace interface {
+
+TLSProducerSocket::TLSProducerSocket(
+ implementation::TLSProducerSocket *implementation) {
+ socket_ = std::unique_ptr<implementation::TLSProducerSocket>(implementation);
+}
+
+TLSProducerSocket::~TLSProducerSocket() { socket_.release(); }
+
+} // namespace interface
+} // namespace transport
diff --git a/libtransport/src/interfaces/tls_socket_producer.h b/libtransport/src/interfaces/tls_socket_producer.h
new file mode 100644
index 000000000..3c662176a
--- /dev/null
+++ b/libtransport/src/interfaces/tls_socket_producer.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2020 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <hicn/transport/interfaces/socket_producer.h>
+
+namespace transport {
+
+namespace implementation {
+class TLSProducerSocket;
+}
+
+namespace interface {
+
+class TLSProducerSocket : public ProducerSocket {
+ public:
+ TLSProducerSocket(implementation::TLSProducerSocket *implementation);
+ ~TLSProducerSocket();
+};
+
+} // namespace interface
+
+} // end namespace transport
diff --git a/libtransport/src/hicn/transport/protocols/CMakeLists.txt b/libtransport/src/protocols/CMakeLists.txt
index 06515e0e2..3156d9ae9 100644
--- a/libtransport/src/hicn/transport/protocols/CMakeLists.txt
+++ b/libtransport/src/protocols/CMakeLists.txt
@@ -22,9 +22,7 @@ list(APPEND HEADER_FILES
${CMAKE_CURRENT_SOURCE_DIR}/byte_stream_reassembly.h
${CMAKE_CURRENT_SOURCE_DIR}/congestion_window_protocol.h
${CMAKE_CURRENT_SOURCE_DIR}/packet_manager.h
- ${CMAKE_CURRENT_SOURCE_DIR}/statistics.h
${CMAKE_CURRENT_SOURCE_DIR}/rate_estimation.h
- ${CMAKE_CURRENT_SOURCE_DIR}/download_observer.h
${CMAKE_CURRENT_SOURCE_DIR}/protocol.h
${CMAKE_CURRENT_SOURCE_DIR}/raaqm.h
${CMAKE_CURRENT_SOURCE_DIR}/raaqm_data_path.h
diff --git a/libtransport/src/hicn/transport/protocols/byte_stream_reassembly.cc b/libtransport/src/protocols/byte_stream_reassembly.cc
index 2f1e5d8fd..c2996ebc1 100644
--- a/libtransport/src/hicn/transport/protocols/byte_stream_reassembly.cc
+++ b/libtransport/src/protocols/byte_stream_reassembly.cc
@@ -13,20 +13,25 @@
* limitations under the License.
*/
-#include <hicn/transport/protocols/byte_stream_reassembly.h>
-
#include <hicn/transport/interfaces/socket_consumer.h>
-#include <hicn/transport/protocols/errors.h>
-#include <hicn/transport/protocols/indexer.h>
#include <hicn/transport/utils/array.h>
#include <hicn/transport/utils/membuf.h>
+#include <implementation/socket_consumer.h>
+#include <protocols/byte_stream_reassembly.h>
+#include <protocols/errors.h>
+#include <protocols/indexer.h>
+#include <protocols/protocol.h>
+
namespace transport {
namespace protocol {
+using namespace core;
+using ReadCallback = interface::ConsumerSocket::ReadCallback;
+
ByteStreamReassembly::ByteStreamReassembly(
- interface::ConsumerSocket *icn_socket,
+ implementation::ConsumerSocket *icn_socket,
TransportProtocol *transport_protocol)
: Reassembly(icn_socket, transport_protocol),
index_(IndexManager::invalid_index),
@@ -109,7 +114,7 @@ void ByteStreamReassembly::reInitialize() {
received_packets_.clear();
// reset read buffer
- interface::ConsumerSocket::ReadCallback *read_callback;
+ ReadCallback *read_callback;
reassembly_consumer_socket_->getSocketOption(
interface::ConsumerCallbacksOptions::READ_CALLBACK, &read_callback);
diff --git a/libtransport/src/hicn/transport/protocols/byte_stream_reassembly.h b/libtransport/src/protocols/byte_stream_reassembly.h
index 7c77d486f..5e5c9ec6b 100644
--- a/libtransport/src/hicn/transport/protocols/byte_stream_reassembly.h
+++ b/libtransport/src/protocols/byte_stream_reassembly.h
@@ -15,7 +15,7 @@
#pragma once
-#include <hicn/transport/protocols/reassembly.h>
+#include <protocols/reassembly.h>
namespace transport {
@@ -23,7 +23,7 @@ namespace protocol {
class ByteStreamReassembly : public Reassembly {
public:
- ByteStreamReassembly(interface::ConsumerSocket *icn_socket,
+ ByteStreamReassembly(implementation::ConsumerSocket *icn_socket,
TransportProtocol *transport_protocol);
protected:
diff --git a/libtransport/src/hicn/transport/protocols/cbr.cc b/libtransport/src/protocols/cbr.cc
index 02bc7b5e4..5df55bd5c 100644
--- a/libtransport/src/hicn/transport/protocols/cbr.cc
+++ b/libtransport/src/protocols/cbr.cc
@@ -13,8 +13,9 @@
* limitations under the License.
*/
-#include <hicn/transport/interfaces/socket_consumer.h>
-#include <hicn/transport/protocols/cbr.h>
+#include <implementation/socket_consumer.h>
+
+#include <protocols/cbr.h>
namespace transport {
@@ -23,7 +24,7 @@ namespace protocol {
using namespace interface;
CbrTransportProtocol::CbrTransportProtocol(
- interface::ConsumerSocket *icnet_socket)
+ implementation::ConsumerSocket *icnet_socket)
: RaaqmTransportProtocol(icnet_socket) {}
int CbrTransportProtocol::start() { return RaaqmTransportProtocol::start(); }
diff --git a/libtransport/src/hicn/transport/protocols/cbr.h b/libtransport/src/protocols/cbr.h
index e80da14f5..20129f6a3 100644
--- a/libtransport/src/hicn/transport/protocols/cbr.h
+++ b/libtransport/src/protocols/cbr.h
@@ -15,7 +15,7 @@
#pragma once
-#include <hicn/transport/protocols/raaqm.h>
+#include <protocols/raaqm.h>
namespace transport {
@@ -23,7 +23,7 @@ namespace protocol {
class CbrTransportProtocol : public RaaqmTransportProtocol {
public:
- CbrTransportProtocol(interface::ConsumerSocket *icnet_socket);
+ CbrTransportProtocol(implementation::ConsumerSocket *icnet_socket);
int start() override;
diff --git a/libtransport/src/hicn/transport/protocols/congestion_window_protocol.h b/libtransport/src/protocols/congestion_window_protocol.h
index 36ac6eb17..36ac6eb17 100644
--- a/libtransport/src/hicn/transport/protocols/congestion_window_protocol.h
+++ b/libtransport/src/protocols/congestion_window_protocol.h
diff --git a/libtransport/src/hicn/transport/protocols/consumer.conf b/libtransport/src/protocols/consumer.conf
index 1a366f32f..1a366f32f 100644
--- a/libtransport/src/hicn/transport/protocols/consumer.conf
+++ b/libtransport/src/protocols/consumer.conf
diff --git a/libtransport/src/hicn/transport/protocols/data_processing_events.h b/libtransport/src/protocols/data_processing_events.h
index 8975c2b4a..8975c2b4a 100644
--- a/libtransport/src/hicn/transport/protocols/data_processing_events.h
+++ b/libtransport/src/protocols/data_processing_events.h
diff --git a/libtransport/src/hicn/transport/protocols/datagram_reassembly.cc b/libtransport/src/protocols/datagram_reassembly.cc
index 7b01ad4bc..abd7e984d 100644
--- a/libtransport/src/hicn/transport/protocols/datagram_reassembly.cc
+++ b/libtransport/src/protocols/datagram_reassembly.cc
@@ -13,14 +13,15 @@
* limitations under the License.
*/
-#include <hicn/transport/protocols/datagram_reassembly.h>
+#include <protocols/datagram_reassembly.h>
namespace transport {
namespace protocol {
-DatagramReassembly::DatagramReassembly(interface::ConsumerSocket* icn_socket,
- TransportProtocol* transport_protocol)
+DatagramReassembly::DatagramReassembly(
+ implementation::ConsumerSocket* icn_socket,
+ TransportProtocol* transport_protocol)
: Reassembly(icn_socket, transport_protocol) {}
void DatagramReassembly::reassemble(core::ContentObject::Ptr&& content_object) {
diff --git a/libtransport/src/hicn/transport/protocols/datagram_reassembly.h b/libtransport/src/protocols/datagram_reassembly.h
index 923b6f2c1..2427ae62f 100644
--- a/libtransport/src/hicn/transport/protocols/datagram_reassembly.h
+++ b/libtransport/src/protocols/datagram_reassembly.h
@@ -15,7 +15,7 @@
#pragma once
-#include <hicn/transport/protocols/reassembly.h>
+#include <protocols/reassembly.h>
namespace transport {
@@ -23,7 +23,7 @@ namespace protocol {
class DatagramReassembly : public Reassembly {
public:
- DatagramReassembly(interface::ConsumerSocket *icn_socket,
+ DatagramReassembly(implementation::ConsumerSocket *icn_socket,
TransportProtocol *transport_protocol);
virtual void reassemble(core::ContentObject::Ptr &&content_object) override;
diff --git a/libtransport/src/hicn/transport/protocols/errors.cc b/libtransport/src/protocols/errors.cc
index c2249ed4a..eefb6f957 100644
--- a/libtransport/src/hicn/transport/protocols/errors.cc
+++ b/libtransport/src/protocols/errors.cc
@@ -13,7 +13,7 @@
* limitations under the License.
*/
-#include <hicn/transport/protocols/errors.h>
+#include <protocols/errors.h>
namespace transport {
namespace protocol {
diff --git a/libtransport/src/hicn/transport/protocols/errors.h b/libtransport/src/protocols/errors.h
index cb3d3474e..cb3d3474e 100644
--- a/libtransport/src/hicn/transport/protocols/errors.h
+++ b/libtransport/src/protocols/errors.h
diff --git a/libtransport/src/hicn/transport/protocols/incremental_indexer.cc b/libtransport/src/protocols/incremental_indexer.cc
index 5a8046daa..e590b4fee 100644
--- a/libtransport/src/hicn/transport/protocols/incremental_indexer.cc
+++ b/libtransport/src/protocols/incremental_indexer.cc
@@ -13,9 +13,10 @@
* limitations under the License.
*/
-#include <hicn/transport/protocols/incremental_indexer.h>
+#include <protocols/incremental_indexer.h>
#include <hicn/transport/interfaces/socket_consumer.h>
+#include <protocols/protocol.h>
namespace transport {
namespace protocol {
diff --git a/libtransport/src/hicn/transport/protocols/incremental_indexer.h b/libtransport/src/protocols/incremental_indexer.h
index b587a8332..20c5e4759 100644
--- a/libtransport/src/hicn/transport/protocols/incremental_indexer.h
+++ b/libtransport/src/protocols/incremental_indexer.h
@@ -15,14 +15,14 @@
#pragma once
-#include <hicn/transport/protocols/indexer.h>
-
#include <hicn/transport/errors/runtime_exception.h>
#include <hicn/transport/errors/unexpected_manifest_exception.h>
-#include <hicn/transport/protocols/reassembly.h>
-#include <hicn/transport/protocols/verification_manager.h>
#include <hicn/transport/utils/literals.h>
+#include <protocols/indexer.h>
+#include <protocols/reassembly.h>
+#include <protocols/verification_manager.h>
+
#include <deque>
namespace transport {
@@ -38,7 +38,7 @@ class TransportProtocol;
class IncrementalIndexer : public Indexer {
public:
- IncrementalIndexer(interface::ConsumerSocket *icn_socket,
+ IncrementalIndexer(implementation::ConsumerSocket *icn_socket,
TransportProtocol *transport, Reassembly *reassembly)
: socket_(icn_socket),
reassembly_(reassembly),
@@ -128,7 +128,7 @@ class IncrementalIndexer : public Indexer {
}
protected:
- interface::ConsumerSocket *socket_;
+ implementation::ConsumerSocket *socket_;
Reassembly *reassembly_;
TransportProtocol *transport_protocol_;
uint32_t final_suffix_;
diff --git a/libtransport/src/hicn/transport/protocols/indexer.cc b/libtransport/src/protocols/indexer.cc
index d95c10ff9..ca12330a6 100644
--- a/libtransport/src/hicn/transport/protocols/indexer.cc
+++ b/libtransport/src/protocols/indexer.cc
@@ -13,17 +13,17 @@
* limitations under the License.
*/
-#include <hicn/transport/protocols/indexer.h>
-
-#include <hicn/transport/protocols/incremental_indexer.h>
-#include <hicn/transport/protocols/manifest_incremental_indexer.h>
-#include <hicn/transport/protocols/protocol.h>
#include <hicn/transport/utils/branch_prediction.h>
+#include <protocols/incremental_indexer.h>
+#include <protocols/indexer.h>
+#include <protocols/manifest_incremental_indexer.h>
+#include <protocols/protocol.h>
+
namespace transport {
namespace protocol {
-IndexManager::IndexManager(interface::ConsumerSocket *icn_socket,
+IndexManager::IndexManager(implementation::ConsumerSocket *icn_socket,
TransportProtocol *transport, Reassembly *reassembly)
: indexer_(std::make_unique<IncrementalIndexer>(icn_socket, transport,
reassembly)),
@@ -43,7 +43,7 @@ void IndexManager::onContentObject(core::Interest::Ptr &&interest,
// Check if manifest
if (content_object->getPayloadType() == PayloadType::MANIFEST) {
IncrementalIndexer *indexer =
- static_cast<IncrementalIndexer *>(indexer_.release());
+ static_cast<IncrementalIndexer *>(indexer_.release());
indexer_ =
std::make_unique<ManifestIncrementalIndexer>(std::move(*indexer));
delete indexer;
@@ -52,20 +52,21 @@ void IndexManager::onContentObject(core::Interest::Ptr &&interest,
indexer_->onContentObject(std::move(interest), std::move(content_object));
auto it = interest_data_set_.begin();
while (it != interest_data_set_.end()) {
- indexer_->onContentObject(std::move(const_cast<core::Interest::Ptr &&>(it->first)), std::move(const_cast<core::ContentObject::Ptr &&>(it->second)));
+ indexer_->onContentObject(
+ std::move(const_cast<core::Interest::Ptr &&>(it->first)),
+ std::move(const_cast<core::ContentObject::Ptr &&>(it->second)));
it = interest_data_set_.erase(it);
}
first_segment_received_ = true;
} else {
- interest_data_set_.emplace(std::move(interest), std::move(content_object));
+ interest_data_set_.emplace(std::move(interest),
+ std::move(content_object));
}
}
}
-bool IndexManager::onKeyToVerify() {
- return indexer_->onKeyToVerify();
-}
+bool IndexManager::onKeyToVerify() { return indexer_->onKeyToVerify(); }
void IndexManager::reset(std::uint32_t offset) {
indexer_ = std::make_unique<IncrementalIndexer>(icn_socket_, transport_,
diff --git a/libtransport/src/hicn/transport/protocols/indexer.h b/libtransport/src/protocols/indexer.h
index 87cf9b307..8213a1503 100644
--- a/libtransport/src/hicn/transport/protocols/indexer.h
+++ b/libtransport/src/protocols/indexer.h
@@ -22,7 +22,7 @@
namespace transport {
-namespace interface {
+namespace implementation {
class ConsumerSocket;
}
@@ -65,7 +65,7 @@ class IndexManager : Indexer {
public:
static constexpr uint32_t invalid_index = ~0;
- IndexManager(interface::ConsumerSocket *icn_socket,
+ IndexManager(implementation::ConsumerSocket *icn_socket,
TransportProtocol *transport, Reassembly *reassembly);
uint32_t getNextSuffix() override { return indexer_->getNextSuffix(); }
@@ -96,7 +96,7 @@ class IndexManager : Indexer {
bool first_segment_received_;
std::set<std::pair<core::Interest::Ptr, core::ContentObject::Ptr>>
interest_data_set_;
- interface::ConsumerSocket *icn_socket_;
+ implementation::ConsumerSocket *icn_socket_;
TransportProtocol *transport_;
Reassembly *reassembly_;
};
diff --git a/libtransport/src/hicn/transport/protocols/manifest_incremental_indexer.cc b/libtransport/src/protocols/manifest_incremental_indexer.cc
index 592daa4d4..1a2f9dec3 100644
--- a/libtransport/src/hicn/transport/protocols/manifest_incremental_indexer.cc
+++ b/libtransport/src/protocols/manifest_incremental_indexer.cc
@@ -13,8 +13,10 @@
* limitations under the License.
*/
-#include <hicn/transport/interfaces/socket_consumer.h>
-#include <hicn/transport/protocols/manifest_incremental_indexer.h>
+#include <implementation/socket_consumer.h>
+
+#include <protocols/manifest_incremental_indexer.h>
+#include <protocols/protocol.h>
#include <cmath>
#include <deque>
@@ -26,12 +28,12 @@ namespace protocol {
using namespace interface;
ManifestIncrementalIndexer::ManifestIncrementalIndexer(
- interface::ConsumerSocket *icn_socket, TransportProtocol *transport,
+ implementation::ConsumerSocket *icn_socket, TransportProtocol *transport,
Reassembly *reassembly)
: IncrementalIndexer(icn_socket, transport, reassembly),
suffix_strategy_(utils::SuffixStrategyFactory::getSuffixStrategy(
- NextSegmentCalculationStrategy::INCREMENTAL,
- next_download_suffix_, 0)) {}
+ NextSegmentCalculationStrategy::INCREMENTAL, next_download_suffix_,
+ 0)) {}
void ManifestIncrementalIndexer::onContentObject(
core::Interest::Ptr &&interest, core::ContentObject::Ptr &&content_object) {
@@ -152,7 +154,7 @@ VerificationPolicy ManifestIncrementalIndexer::verifyContentObject(
socket_->getSocketOption(ConsumerCallbacksOptions::VERIFICATION_FAILED,
&verification_failed_callback);
ret = (*verification_failed_callback)(
- *socket_, content_object,
+ *socket_->getInterface(), content_object,
make_error_code(protocol_error::integrity_verification_failed));
}
diff --git a/libtransport/src/hicn/transport/protocols/manifest_incremental_indexer.h b/libtransport/src/protocols/manifest_incremental_indexer.h
index 6e991f86f..88ae1720b 100644
--- a/libtransport/src/hicn/transport/protocols/manifest_incremental_indexer.h
+++ b/libtransport/src/protocols/manifest_incremental_indexer.h
@@ -15,9 +15,9 @@
#pragma once
-#include <hicn/transport/interfaces/socket.h>
-#include <hicn/transport/protocols/incremental_indexer.h>
-#include <hicn/transport/utils/suffix_strategy.h>
+#include <implementation/socket.h>
+#include <protocols/incremental_indexer.h>
+#include <utils/suffix_strategy.h>
#include <list>
@@ -32,8 +32,9 @@ class ManifestIncrementalIndexer : public IncrementalIndexer {
using SuffixQueue = std::queue<uint32_t>;
using HashEntry = std::pair<std::vector<uint8_t>, core::HashAlgorithm>;
- ManifestIncrementalIndexer(interface::ConsumerSocket *icn_socket,
- TransportProtocol *transport, Reassembly *reassembly);
+ ManifestIncrementalIndexer(implementation::ConsumerSocket *icn_socket,
+ TransportProtocol *transport,
+ Reassembly *reassembly);
ManifestIncrementalIndexer(IncrementalIndexer &&indexer)
: IncrementalIndexer(std::move(indexer)),
diff --git a/libtransport/src/hicn/transport/protocols/packet_manager.h b/libtransport/src/protocols/packet_manager.h
index 4d4011ecf..a552607ea 100644
--- a/libtransport/src/hicn/transport/protocols/packet_manager.h
+++ b/libtransport/src/protocols/packet_manager.h
@@ -23,13 +23,11 @@ namespace protocol {
using namespace core;
-template <typename PacketType>
+template <typename PacketType, std::size_t packet_pool_size = 4096>
class PacketManager {
static_assert(std::is_base_of<Packet, PacketType>::value,
"The packet manager support just Interest and Data.");
- static constexpr std::size_t packet_pool_size = 4096;
-
public:
PacketManager(std::size_t size = packet_pool_size) : size_(0) {
// Create pool of interests
diff --git a/libtransport/src/hicn/transport/protocols/protocol.cc b/libtransport/src/protocols/protocol.cc
index db461a66f..aa290bef8 100644
--- a/libtransport/src/hicn/transport/protocols/protocol.cc
+++ b/libtransport/src/protocols/protocol.cc
@@ -14,7 +14,9 @@
*/
#include <hicn/transport/interfaces/socket_consumer.h>
-#include <hicn/transport/protocols/protocol.h>
+
+#include <implementation/socket_consumer.h>
+#include <protocols/protocol.h>
namespace transport {
@@ -22,7 +24,7 @@ namespace protocol {
using namespace interface;
-TransportProtocol::TransportProtocol(interface::ConsumerSocket *icn_socket,
+TransportProtocol::TransportProtocol(implementation::ConsumerSocket *icn_socket,
Reassembly *reassembly_protocol)
: socket_(icn_socket),
reassembly_protocol_(reassembly_protocol),
@@ -96,8 +98,6 @@ void TransportProtocol::onContentReassembled(std::error_code ec) {
}
stop();
-
- on_payload->afterRead();
}
} // end namespace protocol
diff --git a/libtransport/src/hicn/transport/protocols/protocol.h b/libtransport/src/protocols/protocol.h
index 4897da902..c094adaae 100644
--- a/libtransport/src/hicn/transport/protocols/protocol.h
+++ b/libtransport/src/protocols/protocol.h
@@ -17,14 +17,15 @@
#include <atomic>
-#include <hicn/transport/interfaces/socket.h>
-#include <hicn/transport/protocols/data_processing_events.h>
-#include <hicn/transport/protocols/indexer.h>
-#include <hicn/transport/protocols/packet_manager.h>
-#include <hicn/transport/protocols/reassembly.h>
-#include <hicn/transport/protocols/statistics.h>
+#include <hicn/transport/interfaces/statistics.h>
#include <hicn/transport/utils/object_pool.h>
+#include <implementation/socket.h>
+#include <protocols/data_processing_events.h>
+#include <protocols/indexer.h>
+#include <protocols/packet_manager.h>
+#include <protocols/reassembly.h>
+
namespace transport {
namespace protocol {
@@ -39,7 +40,7 @@ class TransportProtocolCallback {
virtual void onTimeout(const core::Interest &interest) = 0;
};
-class TransportProtocol : public interface::BasePortal::ConsumerCallback,
+class TransportProtocol : public implementation::BasePortal::ConsumerCallback,
public PacketManager<Interest>,
public ContentObjectProcessingEventCallback {
static constexpr std::size_t interest_pool_size = 4096;
@@ -47,7 +48,7 @@ class TransportProtocol : public interface::BasePortal::ConsumerCallback,
friend class ManifestIndexManager;
public:
- TransportProtocol(interface::ConsumerSocket *icn_socket,
+ TransportProtocol(implementation::ConsumerSocket *icn_socket,
Reassembly *reassembly_protocol);
virtual ~TransportProtocol() = default;
@@ -77,14 +78,14 @@ class TransportProtocol : public interface::BasePortal::ConsumerCallback,
virtual void onTimeout(Interest::Ptr &&i) = 0;
protected:
- interface::ConsumerSocket *socket_;
+ implementation::ConsumerSocket *socket_;
std::unique_ptr<Reassembly> reassembly_protocol_;
std::unique_ptr<IndexManager> index_manager_;
- std::shared_ptr<interface::BasePortal> portal_;
+ std::shared_ptr<implementation::BasePortal> portal_;
std::atomic<bool> is_running_;
// True if it si the first time we schedule an interest
std::atomic<bool> is_first_;
- TransportStatistics *stats_;
+ interface::TransportStatistics *stats_;
};
} // end namespace protocol
diff --git a/libtransport/src/hicn/transport/protocols/raaqm.cc b/libtransport/src/protocols/raaqm.cc
index 984470edb..8a38f8ccf 100644
--- a/libtransport/src/hicn/transport/protocols/raaqm.cc
+++ b/libtransport/src/protocols/raaqm.cc
@@ -14,9 +14,11 @@
*/
#include <hicn/transport/interfaces/socket_consumer.h>
-#include <hicn/transport/protocols/indexer.h>
-#include <hicn/transport/protocols/raaqm.h>
-#include <hicn/transport/protocols/errors.h>
+
+#include <implementation/socket_consumer.h>
+#include <protocols/errors.h>
+#include <protocols/indexer.h>
+#include <protocols/raaqm.h>
#include <cstdlib>
#include <fstream>
@@ -27,7 +29,8 @@ namespace protocol {
using namespace interface;
-RaaqmTransportProtocol::RaaqmTransportProtocol(ConsumerSocket *icn_socket)
+RaaqmTransportProtocol::RaaqmTransportProtocol(
+ implementation::ConsumerSocket *icn_socket)
: TransportProtocol(icn_socket, new ByteStreamReassembly(icn_socket, this)),
current_window_size_(1),
interests_in_flight_(0),
@@ -326,14 +329,14 @@ void RaaqmTransportProtocol::onContentObject(
socket_->getSocketOption(ConsumerCallbacksOptions::CONTENT_OBJECT_INPUT,
&callback_content_object);
if (*callback_content_object) {
- (*callback_content_object)(*socket_, *content_object);
+ (*callback_content_object)(*socket_->getInterface(), *content_object);
}
ConsumerInterestCallback *callback_interest = VOID_HANDLER;
socket_->getSocketOption(ConsumerCallbacksOptions::INTEREST_SATISFIED,
&callback_interest);
if (*callback_interest) {
- (*callback_interest)(*socket_, *interest);
+ (*callback_interest)(*socket_->getInterface(), *interest);
}
if (content_object->getPayloadType() == PayloadType::CONTENT_OBJECT) {
@@ -375,14 +378,14 @@ void RaaqmTransportProtocol::onPacketDropped(
socket_->getSocketOption(ConsumerCallbacksOptions::INTEREST_RETRANSMISSION,
&callback);
if (*callback) {
- (*callback)(*socket_, *interest);
+ (*callback)(*socket_->getInterface(), *interest);
}
callback = VOID_HANDLER;
socket_->getSocketOption(ConsumerCallbacksOptions::INTEREST_OUTPUT,
&callback);
if (*callback) {
- (*callback)(*socket_, *interest);
+ (*callback)(*socket_->getInterface(), *interest);
}
if (!is_running_) {
@@ -429,7 +432,7 @@ void RaaqmTransportProtocol::onTimeout(Interest::Ptr &&interest) {
socket_->getSocketOption(ConsumerCallbacksOptions::INTEREST_EXPIRED,
&callback);
if (*callback) {
- (*callback)(*socket_, *interest);
+ (*callback)(*socket_->getInterface(), *interest);
}
afterDataUnsatisfied(segment);
@@ -445,14 +448,14 @@ void RaaqmTransportProtocol::onTimeout(Interest::Ptr &&interest) {
socket_->getSocketOption(ConsumerCallbacksOptions::INTEREST_RETRANSMISSION,
&callback);
if (*callback) {
- (*callback)(*socket_, *interest);
+ (*callback)(*socket_->getInterface(), *interest);
}
callback = VOID_HANDLER;
socket_->getSocketOption(ConsumerCallbacksOptions::INTEREST_OUTPUT,
&callback);
if (*callback) {
- (*callback)(*socket_, *interest);
+ (*callback)(*socket_->getInterface(), *interest);
}
if (!is_running_) {
@@ -495,7 +498,6 @@ void RaaqmTransportProtocol::scheduleNextInterests() {
} else {
index = index_manager_->getNextSuffix();
if (index == IndexManager::invalid_index) {
- TRANSPORT_LOGE("INVALID INDEX %d", index);
break;
}
@@ -521,7 +523,7 @@ void RaaqmTransportProtocol::sendInterest(std::uint64_t next_suffix) {
socket_->getSocketOption(ConsumerCallbacksOptions::INTEREST_OUTPUT,
&callback);
if (*callback) {
- callback->operator()(*socket_, *interest);
+ callback->operator()(*socket_->getInterface(), *interest);
}
if (TRANSPORT_EXPECT_FALSE(!is_running_ && !is_first_)) {
@@ -603,7 +605,7 @@ void RaaqmTransportProtocol::updateStats(uint32_t suffix, uint64_t rtt,
socket_->getSocketOption(GeneralTransportOptions::STATS_INTERVAL,
timer_interval_milliseconds);
if (dt.count() > timer_interval_milliseconds) {
- (*stats_callback)(*socket_, *stats_);
+ (*stats_callback)(*socket_->getInterface(), *stats_);
t0_ = utils::SteadyClock::now();
}
}
diff --git a/libtransport/src/hicn/transport/protocols/raaqm.h b/libtransport/src/protocols/raaqm.h
index f2d819ec5..412967770 100644
--- a/libtransport/src/hicn/transport/protocols/raaqm.h
+++ b/libtransport/src/protocols/raaqm.h
@@ -15,13 +15,14 @@
#pragma once
-#include <hicn/transport/protocols/byte_stream_reassembly.h>
-#include <hicn/transport/protocols/congestion_window_protocol.h>
-#include <hicn/transport/protocols/protocol.h>
-#include <hicn/transport/protocols/raaqm_data_path.h>
-#include <hicn/transport/protocols/rate_estimation.h>
#include <hicn/transport/utils/chrono_typedefs.h>
+#include <protocols/byte_stream_reassembly.h>
+#include <protocols/congestion_window_protocol.h>
+#include <protocols/protocol.h>
+#include <protocols/raaqm_data_path.h>
+#include <protocols/rate_estimation.h>
+
#include <queue>
#include <vector>
@@ -32,7 +33,7 @@ namespace protocol {
class RaaqmTransportProtocol : public TransportProtocol,
public CWindowProtocol {
public:
- RaaqmTransportProtocol(interface::ConsumerSocket *icnet_socket);
+ RaaqmTransportProtocol(implementation::ConsumerSocket *icnet_socket);
~RaaqmTransportProtocol();
diff --git a/libtransport/src/hicn/transport/protocols/raaqm_data_path.cc b/libtransport/src/protocols/raaqm_data_path.cc
index e25646205..439549c85 100644
--- a/libtransport/src/hicn/transport/protocols/raaqm_data_path.cc
+++ b/libtransport/src/protocols/raaqm_data_path.cc
@@ -13,9 +13,10 @@
* limitations under the License.
*/
-#include <hicn/transport/protocols/raaqm_data_path.h>
#include <hicn/transport/utils/chrono_typedefs.h>
+#include <protocols/raaqm_data_path.h>
+
namespace transport {
namespace protocol {
diff --git a/libtransport/src/hicn/transport/protocols/raaqm_data_path.h b/libtransport/src/protocols/raaqm_data_path.h
index 9e4accfa5..6f2afde72 100644
--- a/libtransport/src/hicn/transport/protocols/raaqm_data_path.h
+++ b/libtransport/src/protocols/raaqm_data_path.h
@@ -16,7 +16,8 @@
#pragma once
#include <hicn/transport/utils/chrono_typedefs.h>
-#include <hicn/transport/utils/min_filter.h>
+
+#include <utils/min_filter.h>
#include <chrono>
#include <climits>
diff --git a/libtransport/src/hicn/transport/protocols/rate_estimation.cc b/libtransport/src/protocols/rate_estimation.cc
index 50306e6e5..a2cf1aefe 100644
--- a/libtransport/src/hicn/transport/protocols/rate_estimation.cc
+++ b/libtransport/src/protocols/rate_estimation.cc
@@ -14,9 +14,10 @@
*/
#include <hicn/transport/interfaces/socket_options_default_values.h>
-#include <hicn/transport/protocols/rate_estimation.h>
#include <hicn/transport/utils/log.h>
+#include <protocols/rate_estimation.h>
+
#include <thread>
namespace transport {
diff --git a/libtransport/src/hicn/transport/protocols/rate_estimation.h b/libtransport/src/protocols/rate_estimation.h
index 616501b24..17f39e0b9 100644
--- a/libtransport/src/hicn/transport/protocols/rate_estimation.h
+++ b/libtransport/src/protocols/rate_estimation.h
@@ -15,8 +15,9 @@
#pragma once
-#include <hicn/transport/protocols/download_observer.h>
-#include <hicn/transport/protocols/raaqm_data_path.h>
+#include <hicn/transport/interfaces/statistics.h>
+
+#include <protocols/raaqm_data_path.h>
#include <chrono>
@@ -45,10 +46,10 @@ class IcnRateEstimator {
virtual void onDownloadFinished(){};
- virtual void setObserver(IcnObserver *observer) {
+ virtual void setObserver(interface::IcnObserver *observer) {
this->observer_ = observer;
};
- IcnObserver *observer_;
+ interface::IcnObserver *observer_;
TimePoint start_time_;
TimePoint begin_batch_;
double base_alpha_;
diff --git a/libtransport/src/hicn/transport/protocols/reassembly.cc b/libtransport/src/protocols/reassembly.cc
index 9682d338d..c6602153c 100644
--- a/libtransport/src/hicn/transport/protocols/reassembly.cc
+++ b/libtransport/src/protocols/reassembly.cc
@@ -14,12 +14,14 @@
*/
#include <hicn/transport/interfaces/socket_consumer.h>
-#include <hicn/transport/protocols/errors.h>
-#include <hicn/transport/protocols/indexer.h>
-#include <hicn/transport/protocols/reassembly.h>
#include <hicn/transport/utils/array.h>
#include <hicn/transport/utils/membuf.h>
+#include <implementation/socket_consumer.h>
+#include <protocols/errors.h>
+#include <protocols/indexer.h>
+#include <protocols/reassembly.h>
+
namespace transport {
namespace protocol {
diff --git a/libtransport/src/hicn/transport/protocols/reassembly.h b/libtransport/src/protocols/reassembly.h
index 34af2a70a..fdc9f2a05 100644
--- a/libtransport/src/hicn/transport/protocols/reassembly.h
+++ b/libtransport/src/protocols/reassembly.h
@@ -15,14 +15,14 @@
#pragma once
-#include <hicn/transport/core/facade.h>
+#include <core/facade.h>
namespace transport {
-namespace interface {
+namespace implementation {
class ConsumerReadCallback;
class ConsumerSocket;
-} // namespace interface
+} // namespace implementation
namespace protocol {
@@ -39,7 +39,7 @@ class Reassembly {
virtual void onContentReassembled(std::error_code ec) = 0;
};
- Reassembly(interface::ConsumerSocket *icn_socket,
+ Reassembly(implementation::ConsumerSocket *icn_socket,
TransportProtocol *transport_protocol)
: reassembly_consumer_socket_(icn_socket),
transport_protocol_(transport_protocol) {}
@@ -56,7 +56,7 @@ class Reassembly {
virtual void notifyApplication();
protected:
- interface::ConsumerSocket *reassembly_consumer_socket_;
+ implementation::ConsumerSocket *reassembly_consumer_socket_;
TransportProtocol *transport_protocol_;
Indexer *index_manager_;
std::unique_ptr<utils::MemBuf> read_buffer_;
diff --git a/libtransport/src/hicn/transport/protocols/rtc.cc b/libtransport/src/protocols/rtc.cc
index fece95d03..0ac3839dd 100644
--- a/libtransport/src/hicn/transport/protocols/rtc.cc
+++ b/libtransport/src/protocols/rtc.cc
@@ -13,9 +13,10 @@
* limitations under the License.
*/
-#include <hicn/transport/protocols/rtc.h>
+#include <protocols/rtc.h>
#include <hicn/transport/interfaces/socket_consumer.h>
+#include <implementation/socket_consumer.h>
#include <math.h>
#include <random>
@@ -27,7 +28,7 @@ namespace protocol {
using namespace interface;
RTCTransportProtocol::RTCTransportProtocol(
- interface::ConsumerSocket *icn_socket)
+ implementation::ConsumerSocket *icn_socket)
: TransportProtocol(icn_socket, nullptr),
DatagramReassembly(icn_socket, this),
inflightInterests_(1 << default_values::log_2_default_buffer_size),
@@ -295,7 +296,7 @@ void RTCTransportProtocol::updateStats(uint32_t round_duration) {
stats_->updateQueuingDelay(queuingDelay_);
stats_->updateLossRatio(lossRate_);
stats_->updateAverageRtt(pathTable_[producerPathLabels_[1]]->getMinRtt());
- (*stats_callback)(*socket_, *stats_);
+ (*stats_callback)(*socket_->getInterface(), *stats_);
}
// bound also by interest lifitime* production rate
if (!gotNack_) {
@@ -456,7 +457,7 @@ void RTCTransportProtocol::sendInterest(Name *interest_name, bool rtx) {
&on_interest_output);
if (*on_interest_output) {
- (*on_interest_output)(*socket_, *interest);
+ (*on_interest_output)(*socket_->getInterface(), *interest);
}
if (TRANSPORT_EXPECT_FALSE(!is_running_ && !is_first_)) {
@@ -893,7 +894,7 @@ void RTCTransportProtocol::onContentObject(
socket_->getSocketOption(ConsumerCallbacksOptions::CONTENT_OBJECT_INPUT,
&callback_content_object);
if (*callback_content_object) {
- (*callback_content_object)(*socket_, *content_object);
+ (*callback_content_object)(*socket_->getInterface(), *content_object);
}
if (segmentNumber >= HICN_MIN_PROBE_SEQ) {
diff --git a/libtransport/src/hicn/transport/protocols/rtc.h b/libtransport/src/protocols/rtc.h
index f34afbb5f..f15cdd1eb 100644
--- a/libtransport/src/hicn/transport/protocols/rtc.h
+++ b/libtransport/src/protocols/rtc.h
@@ -15,14 +15,14 @@
#pragma once
+#include <protocols/datagram_reassembly.h>
+#include <protocols/protocol.h>
+#include <protocols/rtc_data_path.h>
+
#include <map>
#include <queue>
#include <unordered_map>
-#include <hicn/transport/protocols/datagram_reassembly.h>
-#include <hicn/transport/protocols/protocol.h>
-#include <hicn/transport/protocols/rtc_data_path.h>
-
// algorithm state
#define HICN_RTC_SYNC_STATE 0
#define HICN_RTC_NORMAL_STATE 1
@@ -81,15 +81,15 @@ typedef enum packetState packetState_t;
struct sentInterest {
uint64_t transmissionTime;
- uint32_t sequence; // sequence number of the interest sent
- // to handle seq % buffer_size
+ uint32_t sequence; // sequence number of the interest sent
+ // to handle seq % buffer_size
packetState_t state; // see packet state
};
class RTCTransportProtocol : public TransportProtocol,
public DatagramReassembly {
public:
- RTCTransportProtocol(interface::ConsumerSocket *icnet_socket);
+ RTCTransportProtocol(implementation::ConsumerSocket *icnet_socket);
~RTCTransportProtocol();
diff --git a/libtransport/src/hicn/transport/protocols/rtc_data_path.cc b/libtransport/src/protocols/rtc_data_path.cc
index 0cbff0e3c..30644e939 100644
--- a/libtransport/src/hicn/transport/protocols/rtc_data_path.cc
+++ b/libtransport/src/protocols/rtc_data_path.cc
@@ -13,11 +13,12 @@
* limitations under the License.
*/
-#include <hicn/transport/protocols/rtc_data_path.h>
-#include <chrono>
+#include <protocols/rtc_data_path.h>
+
#include <cfloat>
+#include <chrono>
-#define MAX_ROUNDS_WITHOUT_PKTS 10 //2sec
+#define MAX_ROUNDS_WITHOUT_PKTS 10 // 2sec
namespace transport {
@@ -53,62 +54,58 @@ void RTCDataPath::insertOwdSample(int64_t owd) {
// for owd we use both min and avg
if (owd < min_owd) min_owd = owd;
- if(avg_owd != DBL_MAX)
+ if (avg_owd != DBL_MAX)
avg_owd = (avg_owd * (1 - ALPHA_RTC)) + (owd * ALPHA_RTC);
else {
avg_owd = owd;
}
- //owd is computed only for valid data packets so we count only
- //this for decide if we recevie traffic or not
+ // owd is computed only for valid data packets so we count only
+ // this for decide if we recevie traffic or not
received_packets_ = true;
}
-void RTCDataPath::computeInterArrivalGap(uint32_t segmentNumber){
-
- //got packet in sequence, compute gap
- if(lastRecvSeq_ == (segmentNumber - 1)){
+void RTCDataPath::computeInterArrivalGap(uint32_t segmentNumber) {
+ // got packet in sequence, compute gap
+ if (lastRecvSeq_ == (segmentNumber - 1)) {
uint64_t now = std::chrono::duration_cast<std::chrono::milliseconds>(
- std::chrono::steady_clock::now().time_since_epoch())
- .count();
+ std::chrono::steady_clock::now().time_since_epoch())
+ .count();
uint64_t delta = now - lastRecvTime_;
lastRecvSeq_ = segmentNumber;
lastRecvTime_ = now;
- if(avg_inter_arrival_ == DBL_MAX)
+ if (avg_inter_arrival_ == DBL_MAX)
avg_inter_arrival_ = delta;
else
- avg_inter_arrival_ = (avg_inter_arrival_ * (1 -ALPHA_RTC))
- + (delta * ALPHA_RTC);
+ avg_inter_arrival_ =
+ (avg_inter_arrival_ * (1 - ALPHA_RTC)) + (delta * ALPHA_RTC);
return;
}
- //ooo packet, update the stasts if needed
- if(lastRecvSeq_ <= segmentNumber){
+ // ooo packet, update the stasts if needed
+ if (lastRecvSeq_ <= segmentNumber) {
lastRecvSeq_ = segmentNumber;
lastRecvTime_ = std::chrono::duration_cast<std::chrono::milliseconds>(
- std::chrono::steady_clock::now().time_since_epoch())
- .count();
+ std::chrono::steady_clock::now().time_since_epoch())
+ .count();
}
}
-void RTCDataPath::receivedNack(){
- received_nacks_ = true;
-}
+void RTCDataPath::receivedNack() { received_nacks_ = true; }
-double RTCDataPath::getInterArrivalGap(){
- if(avg_inter_arrival_ == DBL_MAX)
- return 0;
+double RTCDataPath::getInterArrivalGap() {
+ if (avg_inter_arrival_ == DBL_MAX) return 0;
return avg_inter_arrival_;
}
-bool RTCDataPath::isActive(){
- if(received_nacks_ && rounds_without_packets_ < MAX_ROUNDS_WITHOUT_PKTS)
+bool RTCDataPath::isActive() {
+ if (received_nacks_ && rounds_without_packets_ < MAX_ROUNDS_WITHOUT_PKTS)
return true;
return false;
}
void RTCDataPath::roundEnd() {
- // reset min_rtt and add it to the history
+ // reset min_rtt and add it to the history
if (min_rtt != UINT_MAX) {
prev_min_rtt = min_rtt;
} else {
@@ -118,8 +115,7 @@ void RTCDataPath::roundEnd() {
min_rtt = prev_min_rtt;
}
- if(min_rtt == 0)
- min_rtt = 1;
+ if (min_rtt == 0) min_rtt = 1;
RTThistory_.pushBack(min_rtt);
min_rtt = UINT_MAX;
@@ -142,7 +138,7 @@ void RTCDataPath::roundEnd() {
queuing_delay = 0.0;
}
- if(!received_packets_)
+ if (!received_packets_)
rounds_without_packets_++;
else
rounds_without_packets_ = 0;
diff --git a/libtransport/src/hicn/transport/protocols/rtc_data_path.h b/libtransport/src/protocols/rtc_data_path.h
index 48a67c525..9076b355f 100644
--- a/libtransport/src/hicn/transport/protocols/rtc_data_path.h
+++ b/libtransport/src/protocols/rtc_data_path.h
@@ -15,12 +15,13 @@
#pragma once
-#include <hicn/transport/utils/min_filter.h>
#include <stdint.h>
#include <climits>
+#include <utils/min_filter.h>
+
#define ALPHA_RTC 0.125
-#define HISTORY_LEN 20 //4 sec
+#define HISTORY_LEN 20 // 4 sec
namespace transport {
@@ -60,15 +61,15 @@ class RTCDataPath {
uint64_t lastRecvTime_;
double avg_inter_arrival_;
- //flags to check if a path is active
- //we considere a path active if it reaches a producer
+ // flags to check if a path is active
+ // we considere a path active if it reaches a producer
//(not a cache) --aka we got at least one nack on this path--
- //and if we receives packets
+ // and if we receives packets
bool received_nacks_;
bool received_packets_;
- uint8_t rounds_without_packets_; //if we don't get any packet
- //for MAX_ROUNDS_WITHOUT_PKTS
- //we consider the path inactive
+ uint8_t rounds_without_packets_; // if we don't get any packet
+ // for MAX_ROUNDS_WITHOUT_PKTS
+ // we consider the path inactive
utils::MinFilter<uint64_t> RTThistory_;
utils::MinFilter<int64_t> OWDhistory_;
diff --git a/libtransport/src/hicn/transport/protocols/test/CMakeLists.txt b/libtransport/src/protocols/test/CMakeLists.txt
index 6f9fdb9aa..6f9fdb9aa 100644
--- a/libtransport/src/hicn/transport/protocols/test/CMakeLists.txt
+++ b/libtransport/src/protocols/test/CMakeLists.txt
diff --git a/libtransport/src/hicn/transport/protocols/test/test_transport_producer.cc b/libtransport/src/protocols/test/test_transport_producer.cc
index 204f2cbe2..204f2cbe2 100644
--- a/libtransport/src/hicn/transport/protocols/test/test_transport_producer.cc
+++ b/libtransport/src/protocols/test/test_transport_producer.cc
diff --git a/libtransport/src/hicn/transport/protocols/verification_manager.cc b/libtransport/src/protocols/verification_manager.cc
index 74faf0521..8eedd6106 100644
--- a/libtransport/src/hicn/transport/protocols/verification_manager.cc
+++ b/libtransport/src/protocols/verification_manager.cc
@@ -14,7 +14,10 @@
*/
#include <hicn/transport/interfaces/socket_consumer.h>
-#include <hicn/transport/protocols/verification_manager.h>
+#include <hicn/transport/security/verifier.h>
+
+#include <implementation/socket_consumer.h>
+#include <protocols/verification_manager.h>
namespace transport {
@@ -59,14 +62,16 @@ interface::VerificationPolicy SignatureVerificationManager::onPacketToVerify(
if (TRANSPORT_EXPECT_FALSE(!verifier)) {
ret = (*verification_failed_callback)(
- *icn_socket_, dynamic_cast<const ContentObject&>(packet),
+ *icn_socket_->getInterface(),
+ dynamic_cast<const ContentObject&>(packet),
make_error_code(protocol_error::no_verifier_provided));
return ret;
}
if (!verifier->verify(packet)) {
ret = (*verification_failed_callback)(
- *icn_socket_, dynamic_cast<const ContentObject&>(packet),
+ *icn_socket_->getInterface(),
+ dynamic_cast<const ContentObject&>(packet),
make_error_code(protocol_error::signature_verification_failed));
} else {
ret = VerificationPolicy::ACCEPT_PACKET;
diff --git a/libtransport/src/hicn/transport/protocols/verification_manager.h b/libtransport/src/protocols/verification_manager.h
index 293e8103a..7d8a00a65 100644
--- a/libtransport/src/hicn/transport/protocols/verification_manager.h
+++ b/libtransport/src/protocols/verification_manager.h
@@ -17,7 +17,12 @@
#include <hicn/transport/interfaces/callbacks.h>
#include <hicn/transport/interfaces/verification_policy.h>
-#include <hicn/transport/protocols/errors.h>
+
+#include <hicn/transport/core/content_object.h>
+
+#include <protocols/errors.h>
+
+#include <queue>
namespace transport {
@@ -28,7 +33,6 @@ class ConsumerSocket;
namespace protocol {
using Packet = core::Packet;
-using interface::ConsumerSocket;
using interface::VerificationPolicy;
using ContentObjectPtr = std::shared_ptr<core::ContentObject>;
@@ -41,14 +45,14 @@ class VerificationManager {
class SignatureVerificationManager : public VerificationManager {
public:
- SignatureVerificationManager(interface::ConsumerSocket* icn_socket)
+ SignatureVerificationManager(implementation::ConsumerSocket* icn_socket)
: icn_socket_(icn_socket), key_packets_() {}
interface::VerificationPolicy onPacketToVerify(const Packet& packet) override;
bool onKeyToVerify() override;
private:
- ConsumerSocket* icn_socket_;
+ implementation::ConsumerSocket* icn_socket_;
std::queue<ContentObjectPtr> key_packets_;
ContentObjectPtr copyPacket(const Packet& packet) {
diff --git a/libtransport/src/security/CMakeLists.txt b/libtransport/src/security/CMakeLists.txt
new file mode 100644
index 000000000..0e7b5832b
--- /dev/null
+++ b/libtransport/src/security/CMakeLists.txt
@@ -0,0 +1,22 @@
+# Copyright (c) 2017-2019 Cisco and/or its affiliates.
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at:
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
+
+list(APPEND SOURCE_FILES
+ ${CMAKE_CURRENT_SOURCE_DIR}/signer.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/verifier.cc
+ ${CMAKE_CURRENT_SOURCE_DIR}/identity.cc
+)
+
+set(SOURCE_FILES ${SOURCE_FILES} PARENT_SCOPE)
diff --git a/libtransport/src/hicn/transport/utils/identity.cc b/libtransport/src/security/identity.cc
index c5ab03e44..55713245e 100644
--- a/libtransport/src/hicn/transport/utils/identity.cc
+++ b/libtransport/src/security/identity.cc
@@ -13,7 +13,7 @@
* limitations under the License.
*/
-#include <hicn/transport/utils/identity.h>
+#include <hicn/transport/security/identity.h>
extern "C" {
#include <parc/security/parc_PublicKeySigner.h>
diff --git a/libtransport/src/hicn/transport/utils/signer.cc b/libtransport/src/security/signer.cc
index 9ac9a2c45..314c3ea82 100644
--- a/libtransport/src/hicn/transport/utils/signer.cc
+++ b/libtransport/src/security/signer.cc
@@ -16,9 +16,9 @@
*/
#include <hicn/transport/errors/malformed_ahpacket_exception.h>
-#include <hicn/transport/utils/key_id.h>
+#include <hicn/transport/security/key_id.h>
+#include <hicn/transport/security/signer.h>
#include <hicn/transport/utils/membuf.h>
-#include <hicn/transport/utils/signer.h>
extern "C" {
#ifndef _WIN32
diff --git a/libtransport/src/hicn/transport/utils/verifier.cc b/libtransport/src/security/verifier.cc
index 281ee21dc..19796f718 100644
--- a/libtransport/src/hicn/transport/utils/verifier.cc
+++ b/libtransport/src/security/verifier.cc
@@ -16,9 +16,9 @@
#include <hicn/transport/core/packet.h>
#include <hicn/transport/errors/malformed_ahpacket_exception.h>
#include <hicn/transport/portability/portability.h>
-#include <hicn/transport/utils/key_id.h>
+#include <hicn/transport/security/key_id.h>
+#include <hicn/transport/security/verifier.h>
#include <hicn/transport/utils/log.h>
-#include <hicn/transport/utils/verifier.h>
extern "C" {
#ifndef _WIN32
@@ -119,6 +119,13 @@ int Verifier::verify(const Packet &packet) {
// to initialize packet.payload_head_
const_cast<Packet *>(&packet)->separateHeaderPayload();
bool valid = false;
+
+ // initialize packet.payload_head_
+ const_cast<Packet *>(&packet)->separateHeaderPayload();
+ // header chain points to the IP + TCP hicn header
+ // utils::MemBuf *header_chain = packet.header_head_;
+ // utils::MemBuf *payload_chain = packet.payload_head_;
+ // uint8_t *hicn_packet = header_chain->writableData();
Packet::Format format = packet.getFormat();
if (!(packet.format_ & HFO_AH)) {
diff --git a/libtransport/src/hicn/transport/utils/CMakeLists.txt b/libtransport/src/utils/CMakeLists.txt
index 5a7dbe9cc..88d451b6b 100644
--- a/libtransport/src/hicn/transport/utils/CMakeLists.txt
+++ b/libtransport/src/utils/CMakeLists.txt
@@ -16,9 +16,6 @@ cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
list(APPEND SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/string_tokenizer.cc
${CMAKE_CURRENT_SOURCE_DIR}/uri.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/signer.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/verifier.cc
- ${CMAKE_CURRENT_SOURCE_DIR}/identity.cc
${CMAKE_CURRENT_SOURCE_DIR}/log.cc
${CMAKE_CURRENT_SOURCE_DIR}/membuf.cc
${CMAKE_CURRENT_SOURCE_DIR}/content_store.cc
@@ -26,36 +23,13 @@ list(APPEND SOURCE_FILES
list(APPEND HEADER_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/array.h
- ${CMAKE_CURRENT_SOURCE_DIR}/string_tokenizer.h
- ${CMAKE_CURRENT_SOURCE_DIR}/hash.h
- ${CMAKE_CURRENT_SOURCE_DIR}/uri.h
- ${CMAKE_CURRENT_SOURCE_DIR}/chrono_typedefs.h
- ${CMAKE_CURRENT_SOURCE_DIR}/branch_prediction.h
- ${CMAKE_CURRENT_SOURCE_DIR}/event_reactor.h
- ${CMAKE_CURRENT_SOURCE_DIR}/deadline_timer.h
- ${CMAKE_CURRENT_SOURCE_DIR}/ring_buffer.h
${CMAKE_CURRENT_SOURCE_DIR}/event_reactor.h
${CMAKE_CURRENT_SOURCE_DIR}/min_filter.h
${CMAKE_CURRENT_SOURCE_DIR}/stream_buffer.h
- ${CMAKE_CURRENT_SOURCE_DIR}/literals.h
- ${CMAKE_CURRENT_SOURCE_DIR}/signer.h
- ${CMAKE_CURRENT_SOURCE_DIR}/verifier.h
- ${CMAKE_CURRENT_SOURCE_DIR}/crypto_hasher.h
- ${CMAKE_CURRENT_SOURCE_DIR}/crypto_suite.h
- ${CMAKE_CURRENT_SOURCE_DIR}/crypto_hash.h
- ${CMAKE_CURRENT_SOURCE_DIR}/crypto_hash_type.h
- ${CMAKE_CURRENT_SOURCE_DIR}/identity.h
${CMAKE_CURRENT_SOURCE_DIR}/suffix_strategy.h
- ${CMAKE_CURRENT_SOURCE_DIR}/conversions.h
- ${CMAKE_CURRENT_SOURCE_DIR}/linux.h
- ${CMAKE_CURRENT_SOURCE_DIR}/log.h
${CMAKE_CURRENT_SOURCE_DIR}/event_thread.h
- ${CMAKE_CURRENT_SOURCE_DIR}/object_pool.h
- ${CMAKE_CURRENT_SOURCE_DIR}/membuf.h
- ${CMAKE_CURRENT_SOURCE_DIR}/spinlock.h
${CMAKE_CURRENT_SOURCE_DIR}/content_store.h
- ${CMAKE_CURRENT_SOURCE_DIR}/key_id.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/deadline_timer.h
)
if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
@@ -70,9 +44,6 @@ if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
endif()
if(NOT WIN32)
- list(APPEND HEADER_FILES
- ${CMAKE_CURRENT_SOURCE_DIR}/daemonizator.h
- )
list(APPEND SOURCE_FILES
${CMAKE_CURRENT_SOURCE_DIR}/daemonizator.cc
)
diff --git a/libtransport/src/hicn/transport/utils/content_store.cc b/libtransport/src/utils/content_store.cc
index ba13bef41..cb3db6d94 100644
--- a/libtransport/src/hicn/transport/utils/content_store.cc
+++ b/libtransport/src/utils/content_store.cc
@@ -16,7 +16,9 @@
#include <hicn/transport/core/content_object.h>
#include <hicn/transport/core/interest.h>
#include <hicn/transport/core/name.h>
-#include <hicn/transport/utils/content_store.h>
+#include <hicn/transport/utils/log.h>
+
+#include <utils/content_store.h>
namespace utils {
@@ -65,7 +67,6 @@ const std::shared_ptr<ContentObject> ContentStore::find(
std::shared_ptr<ContentObject> ret = empty_reference_;
auto it = content_store_hash_table_.find(interest.getName());
if (it != content_store_hash_table_.end()) {
-
auto content_lifetime = it->second.first.first->getLifetime();
auto time_passed_since_creation =
std::chrono::duration_cast<std::chrono::milliseconds>(
@@ -75,8 +76,7 @@ const std::shared_ptr<ContentObject> ContentStore::find(
if (time_passed_since_creation > content_lifetime) {
fifo_list_.erase(it->second.second);
content_store_hash_table_.erase(it);
- }
- else {
+ } else {
ret = it->second.first.first;
}
}
diff --git a/libtransport/src/hicn/transport/utils/content_store.h b/libtransport/src/utils/content_store.h
index 613ffcbc2..03ce76f42 100644
--- a/libtransport/src/hicn/transport/utils/content_store.h
+++ b/libtransport/src/utils/content_store.h
@@ -15,7 +15,6 @@
#pragma once
-#include <hicn/transport/interfaces/socket.h>
#include <hicn/transport/utils/spinlock.h>
#include <mutex>
diff --git a/libtransport/src/hicn/transport/utils/daemonizator.cc b/libtransport/src/utils/daemonizator.cc
index c51a68d14..c51a68d14 100644
--- a/libtransport/src/hicn/transport/utils/daemonizator.cc
+++ b/libtransport/src/utils/daemonizator.cc
diff --git a/libtransport/src/hicn/transport/utils/deadline_timer.h b/libtransport/src/utils/deadline_timer.h
index 61f906141..5187754f0 100644
--- a/libtransport/src/hicn/transport/utils/deadline_timer.h
+++ b/libtransport/src/utils/deadline_timer.h
@@ -15,7 +15,7 @@
#pragma once
-#include <hicn/transport/utils/event_reactor.h>
+#include <utils/event_reactor.h>
#include <chrono>
#include <cstddef>
diff --git a/libtransport/src/hicn/transport/utils/epoll_event_reactor.cc b/libtransport/src/utils/epoll_event_reactor.cc
index a97e89500..0e6590d0e 100644
--- a/libtransport/src/hicn/transport/utils/epoll_event_reactor.cc
+++ b/libtransport/src/utils/epoll_event_reactor.cc
@@ -14,8 +14,9 @@
*/
#include <hicn/transport/utils/branch_prediction.h>
-#include <hicn/transport/utils/epoll_event_reactor.h>
-#include <hicn/transport/utils/fd_deadline_timer.h>
+
+#include <utils/epoll_event_reactor.h>
+#include <utils/fd_deadline_timer.h>
#include <signal.h>
#include <unistd.h>
diff --git a/libtransport/src/hicn/transport/utils/epoll_event_reactor.h b/libtransport/src/utils/epoll_event_reactor.h
index 04c10fc7e..4cb87ebd4 100644
--- a/libtransport/src/hicn/transport/utils/epoll_event_reactor.h
+++ b/libtransport/src/utils/epoll_event_reactor.h
@@ -15,8 +15,8 @@
#pragma once
-#include <hicn/transport/utils/event_reactor.h>
#include <hicn/transport/utils/spinlock.h>
+#include <utils/event_reactor.h>
#include <sys/epoll.h>
#include <atomic>
diff --git a/libtransport/src/hicn/transport/utils/event_reactor.h b/libtransport/src/utils/event_reactor.h
index 4f8b58296..4f8b58296 100644
--- a/libtransport/src/hicn/transport/utils/event_reactor.h
+++ b/libtransport/src/utils/event_reactor.h
diff --git a/libtransport/src/hicn/transport/utils/event_thread.h b/libtransport/src/utils/event_thread.h
index e50ae9648..e50ae9648 100644
--- a/libtransport/src/hicn/transport/utils/event_thread.h
+++ b/libtransport/src/utils/event_thread.h
diff --git a/libtransport/src/hicn/transport/utils/fd_deadline_timer.h b/libtransport/src/utils/fd_deadline_timer.h
index 1c14513c9..8bc3bbca3 100644
--- a/libtransport/src/hicn/transport/utils/fd_deadline_timer.h
+++ b/libtransport/src/utils/fd_deadline_timer.h
@@ -16,10 +16,11 @@
#pragma once
#include <hicn/transport/errors/runtime_exception.h>
-#include <hicn/transport/utils/deadline_timer.h>
-#include <hicn/transport/utils/epoll_event_reactor.h>
#include <hicn/transport/utils/log.h>
+#include <utils/deadline_timer.h>
+#include <utils/epoll_event_reactor.h>
+
#include <chrono>
#include <cstddef>
diff --git a/libtransport/src/hicn/transport/utils/log.cc b/libtransport/src/utils/log.cc
index 27dd3f541..27dd3f541 100644
--- a/libtransport/src/hicn/transport/utils/log.cc
+++ b/libtransport/src/utils/log.cc
diff --git a/libtransport/src/hicn/transport/utils/membuf.cc b/libtransport/src/utils/membuf.cc
index e75e85b35..e75e85b35 100644
--- a/libtransport/src/hicn/transport/utils/membuf.cc
+++ b/libtransport/src/utils/membuf.cc
diff --git a/libtransport/src/utils/memory_pool_allocator.h b/libtransport/src/utils/memory_pool_allocator.h
new file mode 100644
index 000000000..adc1443ad
--- /dev/null
+++ b/libtransport/src/utils/memory_pool_allocator.h
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2017-2019 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.sudo make instamake install
+ */
+
+#pragma once
+
+#include <memory>
+
+namespace utils {
+
+template <class T, std::size_t growSize = 1024>
+class MemoryPool {
+ struct Block {
+ Block *next;
+ };
+
+ class Buffer {
+ static const std::size_t blockSize = sizeof(T) > sizeof(Block)
+ ? sizeof(T)
+ : sizeof(Block);
+ uint8_t data[blockSize * growSize];
+
+ public:
+ Buffer *const next;
+
+ Buffer(Buffer *next) : next(next) {}
+
+ T *getBlock(std::size_t index) {
+ return reinterpret_cast<T *>(&data[blockSize * index]);
+ }
+ };
+
+ Block *firstFreeBlock = nullptr;
+ Buffer *firstBuffer = nullptr;
+ std::size_t bufferedBlocks = growSize;
+
+ public:
+ MemoryPool() = default;
+ MemoryPool(MemoryPool &&memoryPool) = delete;
+ MemoryPool(const MemoryPool &memoryPool) = delete;
+ MemoryPool operator=(MemoryPool &&memoryPool) = delete;
+ MemoryPool operator=(const MemoryPool &memoryPool) = delete;
+
+ ~MemoryPool() {
+ while (firstBuffer) {
+ Buffer *buffer = firstBuffer;
+ firstBuffer = buffer->next;
+ delete buffer;
+ }
+ }
+
+ T *allocate() {
+ if (firstFreeBlock) {
+ Block *block = firstFreeBlock;
+ firstFreeBlock = block->next;
+ return reinterpret_cast<T *>(block);
+ }
+
+ if (bufferedBlocks >= growSize) {
+ firstBuffer = new Buffer(firstBuffer);
+ bufferedBlocks = 0;
+ }
+
+ return firstBuffer->getBlock(bufferedBlocks++);
+ }
+
+ void deallocate(T *pointer) {
+ Block *block = reinterpret_cast<Block *>(pointer);
+ block->next = firstFreeBlock;
+ firstFreeBlock = block;
+ }
+};
+
+template <class T, std::size_t growSize = 1024>
+class Allocator : private MemoryPool<T, growSize> {
+#ifdef _WIN32
+ Allocator *copyAllocator;
+ std::allocator<T> *rebindAllocator = nullptr;
+#endif
+
+ public:
+ typedef std::size_t size_type;
+ typedef std::ptrdiff_t difference_type;
+ typedef T *pointer;
+ typedef const T *const_pointer;
+ typedef T &reference;
+ typedef const T &const_reference;
+ typedef T value_type;
+
+ template <class U>
+ struct rebind {
+ typedef Allocator<U, growSize> other;
+ };
+
+#ifdef _WIN32
+ Allocator() = default;
+
+ Allocator(Allocator &allocator) : copyAllocator(&allocator) {}
+
+ template <class U>
+ Allocator(const Allocator<U, growSize> &other) {
+ if (!std::is_same<T, U>::value) rebindAllocator = new std::allocator<T>();
+ }
+
+ ~Allocator() { delete rebindAllocator; }
+#endif
+
+ pointer allocate(size_type n, const void *hint = 0) {
+#ifdef _WIN32
+ if (copyAllocator) return copyAllocator->allocate(n, hint);
+
+ if (rebindAllocator) return rebindAllocator->allocate(n, hint);
+#endif
+
+ if (n != 1 || hint) throw std::bad_alloc();
+
+ return MemoryPool<T, growSize>::allocate();
+ }
+
+ void deallocate(pointer p, size_type n) {
+#ifdef _WIN32
+ if (copyAllocator) {
+ copyAllocator->deallocate(p, n);
+ return;
+ }
+
+ if (rebindAllocator) {
+ rebindAllocator->deallocate(p, n);
+ return;
+ }
+#endif
+
+ MemoryPool<T, growSize>::deallocate(p);
+ }
+
+ void construct(pointer p, const_reference val) { new (p) T(val); }
+
+ void destroy(pointer p) { p->~T(); }
+};
+
+} \ No newline at end of file
diff --git a/libtransport/src/hicn/transport/utils/min_filter.h b/libtransport/src/utils/min_filter.h
index dcfd5652d..dcfd5652d 100644
--- a/libtransport/src/hicn/transport/utils/min_filter.h
+++ b/libtransport/src/utils/min_filter.h
diff --git a/libtransport/src/hicn/transport/utils/stream_buffer.h b/libtransport/src/utils/stream_buffer.h
index adfb696f2..adfb696f2 100644
--- a/libtransport/src/hicn/transport/utils/stream_buffer.h
+++ b/libtransport/src/utils/stream_buffer.h
diff --git a/libtransport/src/hicn/transport/utils/string_tokenizer.cc b/libtransport/src/utils/string_tokenizer.cc
index a280a3c43..a280a3c43 100644
--- a/libtransport/src/hicn/transport/utils/string_tokenizer.cc
+++ b/libtransport/src/utils/string_tokenizer.cc
diff --git a/libtransport/src/hicn/transport/utils/suffix_strategy.h b/libtransport/src/utils/suffix_strategy.h
index ab9b1eff6..6c4dd2785 100644
--- a/libtransport/src/hicn/transport/utils/suffix_strategy.h
+++ b/libtransport/src/utils/suffix_strategy.h
@@ -15,8 +15,7 @@
#pragma once
-#include <hicn/transport/core/manifest_format.h>
-#include <limits>
+#include <core/manifest_format.h>
namespace utils {
diff --git a/libtransport/src/hicn/transport/utils/test.h b/libtransport/src/utils/test.h
index e3dd619ac..e3dd619ac 100644
--- a/libtransport/src/hicn/transport/utils/test.h
+++ b/libtransport/src/utils/test.h
diff --git a/libtransport/src/hicn/transport/utils/uri.cc b/libtransport/src/utils/uri.cc
index 33eb8b45b..33eb8b45b 100644
--- a/libtransport/src/hicn/transport/utils/uri.cc
+++ b/libtransport/src/utils/uri.cc
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index f52fec6c0..3e99fbae2 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -65,6 +65,7 @@ if (NOT DISABLE_EXECUTABLES)
build_executable(hiperf
SOURCES src/hiperf.cc
LINK_LIBRARIES ${LIBTRANSPORT_LIBRARIES} ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
+ INCLUDE_DIRS ${LIBTRANSPORT_INCLUDE_DIRS}
DEPENDS ${DEPENDENCIES}
COMPONENT ${HICN_UTILS}
DEFINITIONS ${COMPILER_DEFINITIONS}
@@ -74,6 +75,7 @@ if (NOT DISABLE_EXECUTABLES)
build_executable(hicn-ping-server
SOURCES src/ping_server.cc
LINK_LIBRARIES ${LIBTRANSPORT_LIBRARIES} ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
+ INCLUDE_DIRS ${LIBTRANSPORT_INCLUDE_DIRS}
DEPENDS ${DEPENDENCIES}
COMPONENT ${HICN_UTILS}
DEFINITIONS ${COMPILER_DEFINITIONS}
@@ -83,6 +85,7 @@ if (NOT DISABLE_EXECUTABLES)
build_executable(hicn-ping-client
SOURCES src/ping_client.cc
LINK_LIBRARIES ${LIBTRANSPORT_LIBRARIES} ${WSOCK32_LIBRARY} ${WS2_32_LIBRARY}
+ INCLUDE_DIRS ${LIBTRANSPORT_INCLUDE_DIRS}
DEPENDS ${DEPENDENCIES}
COMPONENT ${HICN_UTILS}
DEFINITIONS ${COMPILER_DEFINITIONS}
diff --git a/utils/src/hiperf.cc b/utils/src/hiperf.cc
index dd6ed0840..15bcb7405 100644
--- a/utils/src/hiperf.cc
+++ b/utils/src/hiperf.cc
@@ -14,12 +14,15 @@
*/
#include <hicn/transport/config.h>
+#include <hicn/transport/core/content_object.h>
+#include <hicn/transport/core/interest.h>
#include <hicn/transport/interfaces/rtc_socket_producer.h>
#include <hicn/transport/interfaces/socket_consumer.h>
#include <hicn/transport/interfaces/socket_producer.h>
+#include <hicn/transport/security/identity.h>
+#include <hicn/transport/security/signer.h>
#include <hicn/transport/utils/chrono_typedefs.h>
-#include <hicn/transport/utils/identity.h>
-#include <hicn/transport/utils/signer.h>
+#include <hicn/transport/utils/literals.h>
#ifdef SECURE_HICNTRANSPORT
#include <hicn/transport/interfaces/p2psecure_socket_consumer.h>
@@ -29,8 +32,9 @@
#ifndef _WIN32
#include <hicn/transport/utils/daemonizator.h>
#endif
-#include <hicn/transport/utils/literals.h>
+#include <asio.hpp>
+#include <cmath>
#include <fstream>
#include <iomanip>
#include <unordered_set>
@@ -294,7 +298,7 @@ class HIperfClient {
void processLeavingInterest(ConsumerSocket &c, const Interest &interest) {}
void handleTimerExpiration(ConsumerSocket &c,
- const protocol::TransportStatistics &stats) {
+ const TransportStatistics &stats) {
if (configuration_.rtc_) return;
const char separator = ' ';
@@ -642,9 +646,10 @@ class HIperfClient {
void readSuccess(std::size_t total_size) noexcept override {
std::cout << "Key size: " << total_size << " bytes" << std::endl;
+ afterRead();
}
- void afterRead() override {
+ void afterRead() {
std::shared_ptr<utils::Verifier> verifier =
std::make_shared<utils::Verifier>();
verifier->addKeyFromPassphrase(*key_, utils::CryptoSuite::HMAC_SHA256);
@@ -1355,9 +1360,6 @@ int main(int argc, char *argv[]) {
case 'B': {
auto str = std::string(optarg);
std::transform(str.begin(), str.end(), str.begin(), ::tolower);
- std::cout << "---------------------------------------------------------"
- "---------------------->"
- << str << std::endl;
server_configuration.production_rate_ = str;
options = -1;
break;
diff --git a/utils/src/ping_client.cc b/utils/src/ping_client.cc
index cdf786cba..6dea17418 100644
--- a/utils/src/ping_client.cc
+++ b/utils/src/ping_client.cc
@@ -13,8 +13,10 @@
* limitations under the License.
*/
-#include <hicn/transport/interfaces/socket.h>
-#include <hicn/transport/utils/verifier.h>
+#include <hicn/transport/core/interest.h>
+#include <hicn/transport/security/verifier.h>
+
+#include <implementation/socket_consumer.h>
// Let's make the linker happy
#if !TRANSPORT_LOG_EXTERN_GLOBAL_OUTPUT_LEVEL
@@ -81,7 +83,7 @@ class Configuration {
}
};
-class Client : interface::BasePortal::ConsumerCallback {
+class Client : implementation::BasePortal::ConsumerCallback {
public:
Client(Configuration *c)
: portal_(), signals_(portal_.getIoService(), SIGINT) {
@@ -296,7 +298,7 @@ class Client : interface::BasePortal::ConsumerCallback {
private:
SendTimeMap send_timestamps_;
- interface::BasePortal portal_;
+ implementation::BasePortal portal_;
asio::signal_set signals_;
uint64_t sequence_number_;
uint64_t last_jump_;
diff --git a/utils/src/ping_server.cc b/utils/src/ping_server.cc
index cd51ce5c3..d766e2811 100644
--- a/utils/src/ping_server.cc
+++ b/utils/src/ping_server.cc
@@ -19,10 +19,16 @@
#else
#include <openssl/applink.c>
#endif
-#include <hicn/transport/utils/identity.h>
-#include <hicn/transport/utils/signer.h>
+
+#include <hicn/transport/core/content_object.h>
+#include <hicn/transport/core/interest.h>
+#include <hicn/transport/security/identity.h>
+#include <hicn/transport/security/signer.h>
#include <hicn/transport/utils/string_tokenizer.h>
+#include <unistd.h>
+#include <asio.hpp>
+
namespace transport {
namespace interface {
@@ -81,7 +87,8 @@ class CallbackContainer {
}
}
- void processInterest(ProducerSocket &p, const Interest &interest, uint32_t lifetime) {
+ void processInterest(ProducerSocket &p, const Interest &interest,
+ uint32_t lifetime) {
if (verbose_) {
std::cout << "<<< received interest " << interest.getName()
<< " src port: " << interest.getSrcPort()
@@ -230,8 +237,8 @@ int main(int argc, char **argv) {
ttl = (uint8_t)std::stoi(optarg);
break;
case 'l':
- data_lifetime = std::stoi(optarg);
- break;
+ data_lifetime = std::stoi(optarg);
+ break;
case 'V':
verbose = true;
break;
@@ -299,10 +306,11 @@ int main(int argc, char **argv) {
p.registerPrefix(producer_namespace);
p.setSocketOption(GeneralTransportOptions::OUTPUT_BUFFER_SIZE, 0U);
- p.setSocketOption(ProducerCallbacksOptions::CACHE_MISS,
- (ProducerInterestCallback)bind(
- &CallbackContainer::processInterest, stubs,
- std::placeholders::_1, std::placeholders::_2, data_lifetime));
+ p.setSocketOption(
+ ProducerCallbacksOptions::CACHE_MISS,
+ (ProducerInterestCallback)bind(&CallbackContainer::processInterest, stubs,
+ std::placeholders::_1,
+ std::placeholders::_2, data_lifetime));
p.connect();