From 35058cdfe0134c88f1aa8d23342d1d7b9d39e296 Mon Sep 17 00:00:00 2001 From: Alberto Compagno Date: Tue, 7 Jan 2020 11:46:02 +0100 Subject: [HICN-2] Added P2P confidential communication on hICN P2P confidential communications exploit the TLS 1.3 protocol to let a consumer to establish a secure communication on an hICN name. Currently we don't support the consumer authentication (mutual authentication in TLS) and the 0-rtt session establishment. Change-Id: I2be073847c08a17f28c837d444081920c5e57a07 Signed-off-by: Alberto Compagno Signed-off-by: Olivier Roques Signed-off-by: Mauro Sardara --- .../hicn/transport/interfaces/socket_producer.h | 140 +++++++++++++-------- 1 file changed, 89 insertions(+), 51 deletions(-) (limited to 'libtransport/src/hicn/transport/interfaces/socket_producer.h') diff --git a/libtransport/src/hicn/transport/interfaces/socket_producer.h b/libtransport/src/hicn/transport/interfaces/socket_producer.h index ff6f49723..5f360f2ce 100644 --- a/libtransport/src/hicn/transport/interfaces/socket_producer.h +++ b/libtransport/src/hicn/transport/interfaces/socket_producer.h @@ -18,10 +18,12 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -31,10 +33,6 @@ #define REGISTRATION_FAILURE 2 #define REGISTRATION_IN_PROGRESS 3 -namespace utils { -class Identity; -} - namespace transport { namespace interface { @@ -53,16 +51,19 @@ class ProducerSocket : public Socket, bool isRunning() override { return !io_service_.stopped(); }; - 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); + 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); } - uint32_t produce(Name content_name, std::unique_ptr &&buffer, - bool is_last = true, uint32_t start_offset = 0); + virtual uint32_t produce(Name content_name, + std::unique_ptr &&buffer, + bool is_last = true, uint32_t start_offset = 0); - void produce(ContentObject &content_object); + virtual void produce(ContentObject &content_object); virtual void produce(const uint8_t *buffer, size_t buffer_size) { produce(utils::MemBuf::copyBuffer(buffer, buffer_size)); @@ -74,11 +75,18 @@ class ProducerSocket : public Socket, throw errors::NotImplementedException(); } - void asyncProduce(const Name &suffix, const uint8_t *buf, size_t buffer_size); + 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); - void asyncProduce(ContentObject &content_object); + virtual void asyncProduce(Name content_name, + std::unique_ptr &&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); @@ -124,7 +132,7 @@ class ProducerSocket : public Socket, virtual int setSocketOption( int socket_option_key, - const std::shared_ptr &socket_option_value); + const std::shared_ptr &socket_option_value); virtual int setSocketOption(int socket_option_key, const std::string &socket_option_value); @@ -158,15 +166,77 @@ class ProducerSocket : public Socket, virtual int getSocketOption( int socket_option_key, - std::shared_ptr &socket_option_value); + std::shared_ptr &socket_option_value); virtual int getSocketOption(int socket_option_key, std::string &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 + int rescheduleOnIOService(int socket_option_key, arg2 socket_option_value, + Lambda lambda_func) { + // To enforce type check + std::function 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 lck(mtx); + done = true; + result = func(socket_option_key, socket_option_value); + cv.notify_all(); + }); + std::unique_lock lck(mtx); + if (!done) { + cv.wait(lck); + } + } else { + result = func(socket_option_key, socket_option_value); + } + + return result; + } + + template + int rescheduleOnIOServiceWithReference(int socket_option_key, + arg2 &socket_option_value, + Lambda lambda_func) { + // To enforce type check + std::function 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 lck(mtx); + done = true; + result = func(socket_option_key, socket_option_value); + cv.notify_all(); + }); + std::unique_lock 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_; @@ -191,8 +261,8 @@ class ProducerSocket : public Socket, std::atomic hash_algorithm_; std::atomic crypto_suite_; - utils::SpinLock identity_lock_; - std::shared_ptr identity_; + utils::SpinLock signer_lock_; + std::shared_ptr signer_; core::NextSegmentCalculationStrategy suffix_strategy_; // While manifests are being built, contents are stored in a queue @@ -213,38 +283,6 @@ class ProducerSocket : public Socket, ProducerContentCallback on_content_produced_; - // If the thread calling lambda_func is not the same of io_service, this - // function reschedule the function on it - template - int rescheduleOnIOService(int socket_option_key, arg2 socket_option_value, - Lambda lambda_func) { - // To enforce type check - std::function 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 lck(mtx); - done = true; - result = func(socket_option_key, socket_option_value); - cv.notify_all(); - }); - std::unique_lock lck(mtx); - if (!done) { - cv.wait(lck); - } - } else { - result = func(socket_option_key, socket_option_value); - } - - return result; - } - private: void listen(); -- cgit 1.2.3-korg