diff options
Diffstat (limited to 'libtransport/includes/hicn/transport/interfaces/portal.h')
-rw-r--r-- | libtransport/includes/hicn/transport/interfaces/portal.h | 108 |
1 files changed, 26 insertions, 82 deletions
diff --git a/libtransport/includes/hicn/transport/interfaces/portal.h b/libtransport/includes/hicn/transport/interfaces/portal.h index 66fc84256..bca78cb3b 100644 --- a/libtransport/includes/hicn/transport/interfaces/portal.h +++ b/libtransport/includes/hicn/transport/interfaces/portal.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: @@ -19,6 +19,8 @@ #include <hicn/transport/core/content_object.h> #include <hicn/transport/core/interest.h> #include <hicn/transport/core/prefix.h> +#include <hicn/transport/utils/event_thread.h> +#include <hicn/transport/utils/noncopyable.h> #include <functional> @@ -28,58 +30,18 @@ namespace transport { namespace interface { -template <typename PrefixType> -class BasicBindConfig { - static_assert(std::is_same<core::Prefix, PrefixType>::value, - "Prefix must be a Prefix type."); - - const uint32_t standard_cs_reserved = 5000; - - public: - template <typename T> - BasicBindConfig(T &&prefix) - : prefix_(std::forward<T &&>(prefix)), - content_store_reserved_(standard_cs_reserved) {} - - template <typename T> - BasicBindConfig(T &&prefix, uint32_t cs_reserved) - : prefix_(std::forward<T &&>(prefix)), - content_store_reserved_(cs_reserved) {} - - TRANSPORT_ALWAYS_INLINE const PrefixType &prefix() const { return prefix_; } - - TRANSPORT_ALWAYS_INLINE uint32_t csReserved() const { - return content_store_reserved_; - } - - private: - PrefixType prefix_; - uint32_t content_store_reserved_; -}; - -using BindConfig = BasicBindConfig<core::Prefix>; - -class Portal { +class Portal : private utils::NonCopyable { public: /** - * Consumer callback is an abstract class containing two methods to be - * implemented by a consumer application. + * Transport callback is an abstract class containing two methods to be + * implemented by a consumer/producer application. */ - class ConsumerCallback { + class TransportCallback { public: + virtual void onInterest(core::Interest &i) = 0; virtual void onContentObject(core::Interest &i, core::ContentObject &c) = 0; virtual void onTimeout(core::Interest::Ptr &i, const core::Name &n) = 0; - virtual void onError(std::error_code ec) = 0; - }; - - /** - * Producer callback is an abstract class containing two methods to be - * implemented by a producer application. - */ - class ProducerCallback { - public: - virtual void onInterest(core::Interest &i) = 0; - virtual void onError(std::error_code ec) = 0; + virtual void onError(const std::error_code &ec) = 0; }; using OnContentObjectCallback = @@ -89,21 +51,14 @@ class Portal { Portal(); - Portal(asio::io_service &io_service); + Portal(::utils::EventThread &worker); /** - * Set the consumer callback. - * - * @param consumer_callback - The pointer to the ConsumerCallback object. - */ - void setConsumerCallback(ConsumerCallback *consumer_callback); - - /** - * Set the producer callback. + * Set the transport protocl callback. * * @param producer_callback - The pointer to the ProducerCallback object. */ - void setProducerCallback(ProducerCallback *producer_callback); + void registerTransportCallback(TransportCallback *transport_callback); /** * Connect the transport to the local hicn forwarder. @@ -140,40 +95,18 @@ class Portal { * parameter. Otherwise ConsumerCallback::onTimeout will be used. */ void sendInterest( - core::Interest::Ptr &&interest, + core::Interest::Ptr &interest, uint32_t lifetime, OnContentObjectCallback &&on_content_object_callback = UNSET_CALLBACK, OnInterestTimeoutCallback &&on_interest_timeout_callback = UNSET_CALLBACK); /** - * Register a producer name to the local forwarder and optionally set the - * content store size in a per-face manner. - * - * @param config - The configuration for the local forwarder binding. - */ - void bind(const BindConfig &config); - - void runEventsLoop(); - - /** - * Run one event and return. - */ - void runOneEvent(); - - /** * Send a data packet to the local forwarder. As opposite to sendInterest, the * ownership of the content object is not transferred to the portal. * * @param content_object - The data packet. */ void sendContentObject(core::ContentObject &content_object); - /** - * Stop the event loop, canceling all the pending events in the event queue. - * - * Beware that stopping the event loop DOES NOT disconnect the transport from - * the local forwarder, the connector underneath will stay connected. - */ - void stopEventsLoop(); /** * Disconnect the transport from the local forwarder. @@ -188,15 +121,26 @@ class Portal { /** * Get a reference to the io_service object. */ - asio::io_service &getIoService(); + utils::EventThread &getThread(); /** * Register a route to the local forwarder. */ void registerRoute(core::Prefix &prefix); + /** + * Send a MAP-Me command to traverse NATs. + */ + void sendMapme(); + + /** + * Set forwarding strategy + */ + void setForwardingStrategy(core::Prefix &prefix, std::string &strategy); + private: - void *implementation_; + class Impl; + Impl *implementation_; }; } // namespace interface |