aboutsummaryrefslogtreecommitdiffstats
path: root/libtransport/src/protocols/fec_base.h
diff options
context:
space:
mode:
Diffstat (limited to 'libtransport/src/protocols/fec_base.h')
-rw-r--r--libtransport/src/protocols/fec_base.h85
1 files changed, 51 insertions, 34 deletions
diff --git a/libtransport/src/protocols/fec_base.h b/libtransport/src/protocols/fec_base.h
index a135c474f..a1929d85e 100644
--- a/libtransport/src/protocols/fec_base.h
+++ b/libtransport/src/protocols/fec_base.h
@@ -16,71 +16,88 @@
#pragma once
#include <hicn/transport/core/content_object.h>
+#include <hicn/transport/errors/not_implemented_exception.h>
#include <functional>
namespace transport {
namespace protocol {
-/**
- * Interface classes to integrate FEC inside any producer transport protocol
- */
-class ProducerFECBase {
+namespace fec {
+
+using buffer = typename utils::MemBuf::Ptr;
+using BufferArray = std::vector<std::pair<uint32_t, buffer>>;
+
+class FECBase {
public:
+ virtual ~FECBase() = default;
/**
- * Callback, to be called by implementations as soon as a repair packet is
- * ready.
+ * Callback to be called after the encode or the decode operations. In the
+ * former case it will contain the symbols, while in the latter the sources.
*/
- using RepairPacketsReady =
- std::function<void(std::vector<core::ContentObject::Ptr> &)>;
+ using PacketsReady = std::function<void(BufferArray &)>;
/**
- * Producers will call this function upon production of a new packet.
+ * Callback to be called when a new buffer (for encoding / decoding) needs to
+ * be allocated.
*/
- virtual void onPacketProduced(const core::ContentObject &content_object) = 0;
+ using BufferRequested = std::function<buffer(std::size_t size)>;
/**
- * Set callback to signal production protocol the repair packet is ready.
+ * @brief Get size of FEC header.
*/
- void setFECCallback(const RepairPacketsReady &on_repair_packet) {
- rep_packet_ready_callback_ = on_repair_packet;
+ virtual std::size_t getFecHeaderSize() = 0;
+
+ /**
+ * Set callback to call after packet encoding / decoding
+ */
+ template <typename Handler>
+ void setFECCallback(Handler &&callback) {
+ fec_callback_ = std::forward<Handler>(callback);
}
+ /**
+ * Set a callback to request a buffer.
+ */
+ template <typename Handler>
+ void setBufferCallback(Handler &&buffer_callback) {
+ buffer_callback_ = buffer_callback;
+ }
+
+ virtual void reset() = 0;
+
protected:
- RepairPacketsReady rep_packet_ready_callback_;
+ PacketsReady fec_callback_{0};
+ BufferRequested buffer_callback_{0};
};
/**
- * Interface classes to integrate FEC inside any consumer transport protocol
+ * Interface classes to integrate FEC inside any producer transport protocol
*/
-class ConsumerFECBase {
+class ProducerFEC : public virtual FECBase {
public:
+ virtual ~ProducerFEC() = default;
/**
- * Callback, to be called by implemrntations as soon as a packet is recovered.
+ * Producers will call this function upon production of a new packet.
*/
- using OnPacketsRecovered =
- std::function<void(std::vector<core::ContentObject::Ptr> &)>;
+ virtual void onPacketProduced(core::ContentObject &content_object,
+ uint32_t offset) = 0;
+};
- /**
- * Consumers will call this function when they receive a FEC packet.
- */
- virtual void onFECPacket(const core::ContentObject &content_object) = 0;
+/**
+ * Interface classes to integrate FEC inside any consumer transport protocol
+ */
+class ConsumerFEC : public virtual FECBase {
+ public:
+ virtual ~ConsumerFEC() = default;
/**
* Consumers will call this function when they receive a data packet
*/
- virtual void onDataPacket(const core::ContentObject &content_object) = 0;
-
- /**
- * Set callback to signal consumer protocol the repair packet is ready.
- */
- void setFECCallback(const OnPacketsRecovered &on_repair_packet) {
- packet_recovered_callback_ = on_repair_packet;
- }
-
- protected:
- OnPacketsRecovered packet_recovered_callback_;
+ virtual void onDataPacket(core::ContentObject &content_object,
+ uint32_t offset) = 0;
};
+} // namespace fec
} // namespace protocol
} // namespace transport \ No newline at end of file