diff options
Diffstat (limited to 'libtransport/includes/hicn/transport/interfaces/socket_producer.h')
-rw-r--r-- | libtransport/includes/hicn/transport/interfaces/socket_producer.h | 93 |
1 files changed, 55 insertions, 38 deletions
diff --git a/libtransport/includes/hicn/transport/interfaces/socket_producer.h b/libtransport/includes/hicn/transport/interfaces/socket_producer.h index e269fb83d..2627b3138 100644 --- a/libtransport/includes/hicn/transport/interfaces/socket_producer.h +++ b/libtransport/includes/hicn/transport/interfaces/socket_producer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 Cisco and/or its affiliates. + * Copyright (c) 2021 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,16 @@ #pragma once +#include <hicn/transport/auth/signer.h> #include <hicn/transport/config.h> +#include <hicn/transport/core/asio_wrapper.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> - -#ifndef ASIO_STANDALONE -#define ASIO_STANDALONE -#endif -#include <asio/io_service.hpp> +#include <hicn/transport/utils/event_thread.h> +#include <hicn/transport/utils/noncopyable.h> namespace transport { @@ -38,9 +36,28 @@ namespace interface { using namespace core; -class ProducerSocket { +class ProducerSocket : private utils::NonCopyable { public: - explicit ProducerSocket(int protocol = 0); + /** + * @brief This class is used by the transport to notify events to the + * application. + */ + class Callback { + public: + /** + * @brief This will invoked in an error occurred in the production protocol. + * + * @param ec - An error code describing the error. + */ + virtual void produceError(const std::error_code &ec) noexcept = 0; + }; + + explicit ProducerSocket( + int protocol = ProductionProtocolAlgorithms::BYTE_STREAM); + + explicit ProducerSocket(int protocol, ::utils::EventThread &worker); + + ProducerSocket(ProducerSocket &&other) noexcept; virtual ~ProducerSocket(); @@ -48,40 +65,34 @@ class ProducerSocket { 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 registerPrefix(const Prefix &producer_namespace); - void produce(std::unique_ptr<utils::MemBuf> &&buffer); + uint32_t produceStream(const Name &content_name, const uint8_t *buffer, + size_t buffer_size, bool is_last = true, + uint32_t start_offset = 0); - void asyncProduce(const Name &suffix, const uint8_t *buf, size_t buffer_size, - bool is_last = true, uint32_t *start_offset = nullptr); + uint32_t produceStream(const Name &content_name, + std::unique_ptr<utils::MemBuf> &&buffer, + bool is_last = true, uint32_t start_offset = 0); - void asyncProduce(Name content_name, std::unique_ptr<utils::MemBuf> &&buffer, - bool is_last, uint32_t offset, - uint32_t **last_segment = nullptr); + uint32_t produceDatagram(const Name &content_name, const uint8_t *buffer, + size_t buffer_size); - void asyncProduce(ContentObject &content_object); + uint32_t produceDatagram(const Name &content_name, + std::unique_ptr<utils::MemBuf> &&buffer); - void registerPrefix(const Prefix &producer_namespace); + void produce(ContentObject &content_object); - void serveForever(); + void sendMapme(); void stop(); + void start(); + asio::io_service &getIoService(); + int setSocketOption(int socket_option_key, Callback *socket_option_value); + int setSocketOption(int socket_option_key, uint32_t socket_option_value); int setSocketOption(int socket_option_key, @@ -104,14 +115,17 @@ class ProducerSocket { ProducerContentCallback socket_option_value); int setSocketOption(int socket_option_key, - utils::CryptoHashType socket_option_value); + auth::CryptoHashType socket_option_value); int setSocketOption(int socket_option_key, - utils::CryptoSuite socket_option_value); + auth::CryptoSuite socket_option_value); + + int setSocketOption(int socket_option_key, + const std::shared_ptr<auth::Signer> &socket_option_value); int setSocketOption( int socket_option_key, - const std::shared_ptr<utils::Signer> &socket_option_value); + const std::shared_ptr<auth::Verifier> &socket_option_value); int setSocketOption(int socket_option_key, const std::string &socket_option_value); @@ -133,13 +147,16 @@ class ProducerSocket { ProducerInterestCallback **socket_option_value); int getSocketOption(int socket_option_key, - utils::CryptoHashType &socket_option_value); + auth::CryptoHashType &socket_option_value); + + int getSocketOption(int socket_option_key, + auth::CryptoSuite &socket_option_value); int getSocketOption(int socket_option_key, - utils::CryptoSuite &socket_option_value); + std::shared_ptr<auth::Signer> &socket_option_value); int getSocketOption(int socket_option_key, - std::shared_ptr<utils::Signer> &socket_option_value); + std::shared_ptr<auth::Verifier> &socket_option_value); int getSocketOption(int socket_option_key, std::string &socket_option_value); |