Skip to content

Commit

Permalink
merge step 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kuehnhammer committed Apr 4, 2024
1 parent bef3df0 commit ee481db
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 204 deletions.
37 changes: 11 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ if(ENABLE_RAPTOR)
add_library(raptor STATIC)
target_sources(raptor
PRIVATE
raptor/bipartite.c raptor/decoder.c raptor/encoder.c raptor/galois.c raptor/gaussian.c raptor/pivoting.c raptor/random.c
${PROJECT_SOURCE_DIR}/lib/raptor/bipartite.c
${PROJECT_SOURCE_DIR}/lib/raptor/decoder.c
${PROJECT_SOURCE_DIR}/lib/raptor/encoder.c
${PROJECT_SOURCE_DIR}/lib/raptor/galois.c
${PROJECT_SOURCE_DIR}/lib/raptor/gaussian.c
${PROJECT_SOURCE_DIR}/lib/raptor/pivoting.c
${PROJECT_SOURCE_DIR}/lib/raptor/random.c
PUBLIC
raptor/raptor.h
${PROJECT_SOURCE_DIR}/lib/raptor/raptor.h
)
target_link_libraries(raptor LINK_PUBLIC m)
else()
Expand All @@ -57,18 +63,17 @@ endif()
add_library(flute "")
target_sources(flute
PRIVATE
src/Receiver.cpp src/Transmitter.cpp src/AlcPacket.cpp src/EncodingSymbol.cpp src/FileDeliveryTable.cpp src/IpSec.cpp
src/File.cpp src/File_FEC_CompactNoCode.cpp
src/Receiver.cpp src/Transmitter.cpp src/AlcPacket.cpp src/EncodingSymbol.cpp src/FileDeliveryTable.cpp src/IpSec.cpp src/File.cpp
utils/base64.cpp
PUBLIC
include/Receiver.h include/Transmitter.h include/File.h

)
target_include_directories(flute PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include/)
target_include_directories(flute PUBLIC ${PROJECT_SOURCE_DIR}/include/)

if(ENABLE_RAPTOR)
add_compile_definitions(RAPTOR_ENABLED)
target_include_directories(flute PUBLIC ${CMAKE_CURRENT_LIST_DIR}/raptor/)
target_include_directories(flute PUBLIC ${PROJECT_SOURCE_DIR}/lib/raptor/)
target_sources(flute
PRIVATE
src/RaptorFEC.cpp
Expand All @@ -87,23 +92,3 @@ target_link_libraries( flute
PkgConfig::TINYXML
PkgConfig::NETLINK
)

if (ENABLE_RAPTOR10)
add_definitions(-DENABLE_RAPTOR10)
add_subdirectory(lib/raptor10)
include_directories(
SYSTEM
${PROJECT_SOURCE_DIR}/lib/raptor10/src/libraptor
)
target_sources(flute
PRIVATE
src/File_FEC_Raptor10.cpp
)
link_directories(
${PROJECT_SOURCE_DIR}/lib/raptor10/src/libraptor
)
target_link_libraries( flute
LINK_PUBLIC
raptor
)
endif (ENABLE_RAPTOR10)
22 changes: 2 additions & 20 deletions examples/flute-receiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <filesystem>
#include <libconfig.h++>
#include <boost/asio.hpp>
#include <boost/asio/signal_set.hpp>

#include "spdlog/async.h"
#include "spdlog/spdlog.h"
Expand All @@ -40,8 +39,6 @@ using libconfig::Config;
using libconfig::FileIOException;
using libconfig::ParseException;

using namespace boost::placeholders;

static void print_version(FILE *stream, struct argp_state *state);
void (*argp_program_version_hook)(FILE *, struct argp_state *) = print_version;
const char *argp_program_bug_address = "Austrian Broadcasting Services <obeca@ors.at>";
Expand All @@ -51,9 +48,7 @@ static struct argp_option options[] = { // NOLINT
{"interface", 'i', "IF", 0, "IP address of the interface to bind flute receivers to (default: 0.0.0.0)", 0},
{"target", 'm', "IP", 0, "Multicast address to receive on (default: 238.1.1.95)", 0},
{"port", 'p', "PORT", 0, "Multicast port (default: 40085)", 0},
{"tsi", 't', "TSI", 0, "TSI to receive (default: 0)", 0},
{"ipsec-key", 'k', "KEY", 0, "To enable IPSec/ESP decryption of packets, provide a hex-encoded AES key here", 0},
{"disable-md5", '5', nullptr, 0, "Disable MD5 verification" },
{"log-level", 'l', "LEVEL", 0,
"Log verbosity: 0 = trace, 1 = debug, 2 = info, 3 = warn, 4 = error, 5 = "
"critical, 6 = none. Default: 2.",
Expand All @@ -72,8 +67,6 @@ struct ft_arguments {
const char *aes_key = {};
unsigned short mcast_port = 40085;
unsigned log_level = 2; /**< log level */
unsigned tsi = 0;
bool md5_enabled = true;
char *download_dir = nullptr;
unsigned nfiles = 0; /**< log level */
char **files;
Expand All @@ -91,9 +84,6 @@ static auto parse_opt(int key, char *arg, struct argp_state *state) -> error_t {
case 'i':
arguments->flute_interface = arg;
break;
case '5':
arguments->md5_enabled = false;
break;
case 'k':
arguments->aes_key = arg;
arguments->enable_ipsec = true;
Expand All @@ -104,8 +94,6 @@ static auto parse_opt(int key, char *arg, struct argp_state *state) -> error_t {
case 'l':
arguments->log_level = static_cast<unsigned>(strtoul(arg, nullptr, 10));
break;
case 't':
arguments->tsi = static_cast<unsigned>(strtoul(arg, nullptr, 10));
case 'd':
arguments->download_dir = arg;
break;
Expand Down Expand Up @@ -168,9 +156,8 @@ auto main(int argc, char **argv) -> int {
arguments.flute_interface,
arguments.mcast_target,
(short)arguments.mcast_port,
arguments.tsi,
io,
arguments.md5_enabled);
16,
io);

// Configure IPSEC, if enabled
if (arguments.enable_ipsec)
Expand Down Expand Up @@ -208,11 +195,6 @@ auto main(int argc, char **argv) -> int {
}
});


boost::asio::signal_set signals(io, SIGINT, SIGTERM);
signals.async_wait(
boost::bind(&boost::asio::io_service::stop, &io)); // NOLINT

// Start the IO service
io.run();
} catch (std::exception ex ) {
Expand Down
22 changes: 1 addition & 21 deletions examples/flute-transmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,17 @@ using libconfig::Config;
using libconfig::FileIOException;
using libconfig::ParseException;

using namespace boost::placeholders;

static void print_version(FILE *stream, struct argp_state *state);
void (*argp_program_version_hook)(FILE *, struct argp_state *) = print_version;
const char *argp_program_bug_address = "Austrian Broadcasting Services <obeca@ors.at>";
static char doc[] = "FLUTE/ALC transmitter demo"; // NOLINT

const char* fec_options = "FEC scheme to use: cnc (Compact No-Code [default])"
#ifdef ENABLE_RAPTOR10
", r10 (Raptor10)"
#endif
"";

static struct argp_option options[] = { // NOLINT
{"target", 'm', "IP", 0, "Target multicast address (default: 238.1.1.95)", 0},
{"fec", 'f', "FEC Scheme", 0, "Choose a scheme for Forward Error Correction. Compact No Code = 0, Raptor = 1 (default is 0)", 0},
{"port", 'p', "PORT", 0, "Target port (default: 40085)", 0},
{"mtu", 't', "BYTES", 0, "Path MTU to size ALC packets for (default: 1500)", 0},
{"rate-limit", 'r', "KBPS", 0, "Transmit rate limit (kbps), 0 = no limit, default: 1000 (1 Mbps)", 0},
{"fec", 'f', "cnc|r10", 0, fec_options, 0},
{"ipsec-key", 'k', "KEY", 0, "To enable IPSec/ESP encryption of packets, provide a hex-encoded AES key here", 0},
{"log-level", 'l', "LEVEL", 0,
"Log verbosity: 0 = trace, 1 = debug, 2 = info, 3 = warn, 4 = error, 5 = "
Expand All @@ -78,7 +69,6 @@ struct ft_arguments {
unsigned log_level = 2; /**< log level */
unsigned fec = 0; /**< log level */
char **files;
LibFlute::FecScheme fec_scheme = LibFlute::FecScheme::CompactNoCode;
};

/**
Expand All @@ -90,15 +80,6 @@ static auto parse_opt(int key, char *arg, struct argp_state *state) -> error_t {
case 'm':
arguments->mcast_target = arg;
break;
case 'f':
if (strcmp(arg, "cnc") == 0) {
arguments->fec_scheme = LibFlute::FecScheme::CompactNoCode;
} else if (strcmp(arg, "r10") == 0) {
arguments->fec_scheme = LibFlute::FecScheme::Raptor10;
} else {
argp_usage (state);
}
break;
case 'k':
arguments->aes_key = arg;
arguments->enable_ipsec = true;
Expand Down Expand Up @@ -246,8 +227,7 @@ auto main(int argc, char **argv) -> int {
"application/octet-stream",
transmitter.seconds_since_epoch() + 60, // 1 minute from now
file.buffer,
file.len,
arguments.fec_scheme
file.len
);
if (file.toi > 0) {
spdlog::info("Queued {} ({} bytes) for transmission, TOI is {}",
Expand Down
9 changes: 2 additions & 7 deletions include/EncodingSymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,12 @@ namespace LibFlute {
/**
* Decode to a buffer
*/
bool decode_to(char* buffer, size_t max_length) const;
void decode_to(char* buffer, size_t max_length) const;

/**
* Encode to a buffer
*/
size_t copy_encoded(char* buffer, size_t max_length) const;

/**
* Get a pointer to the encoded data buffer
*/
uint8_t* buffer() const { return (uint8_t*)_encoded_data; };
size_t encode_to(char* buffer, size_t max_length) const;

/**
* Get the data length
Expand Down
2 changes: 1 addition & 1 deletion include/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace LibFlute {
* while the file is being transmitted.
*/
File(uint32_t toi,
FecOti fec_oti,
const FecOti& fec_oti,
std::string content_location,
std::string content_type,
uint64_t expires,
Expand Down
3 changes: 1 addition & 2 deletions include/FileDeliveryTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include <stdint.h>
#include <string>
#include <vector>
#include <unique_ptr>
#include "flute_types.h"

namespace LibFlute {
Expand Down Expand Up @@ -65,7 +64,7 @@ namespace LibFlute {
std::string content_type;
uint64_t expires;
FecOti fec_oti;
std::unique_ptr<FecTransformer> fec_transformer = {};
FecTransformer *fec_transformer;
};

/**
Expand Down
6 changes: 1 addition & 5 deletions include/Receiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,9 @@ namespace LibFlute {
* @param port Target port
* @param tsi TSI value of the session
* @param io_service Boost io_service to run the socket operations in (must be provided by the caller)
* @param enable_md5 Enable checking of MD5 sums for received files
*/
Receiver( const std::string& iface, const std::string& address,
short port, uint64_t tsi,
boost::asio::io_service& io_service,
bool enable_md5 = true);
short port, uint64_t tsi, boost::asio::io_service& io_service);

/**
* Default destructor.
Expand Down Expand Up @@ -107,6 +104,5 @@ namespace LibFlute {
completion_callback_t _completion_cb = nullptr;

bool _running = true;
bool _enable_md5 = true;
};
};
4 changes: 2 additions & 2 deletions src/AlcPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,13 @@ LibFlute::AlcPacket::AlcPacket(uint16_t tsi, uint16_t toi, LibFlute::FecOti fec_
lct_header->half_word_flag = 1;
if (_fec_oti.encoding_id == LibFlute::FecScheme::CompactNoCode) {
lct_header->codepoint = 0;
} else if (_fec_oti.encoding_id == LibFlute::FecScheme::Raptor10) {
} else if (_fec_oti.encoding_id == LibFlute::FecScheme::Raptor) {
lct_header->codepoint = 1;
} else {
throw "Unsupported FEC scheme";
}
lct_header->lct_header_len = lct_header_len;
lct_header->codepoint = (uint8_t) fec_oti.encoding_id;
lct_header->codepoint = (uint8_t)_fec_oti.encoding_id;
auto hdr_ptr = _buffer + 4;
auto payload_ptr = _buffer + 4UL * lct_header_len;

Expand Down
5 changes: 1 addition & 4 deletions src/EncodingSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,11 @@ auto LibFlute::EncodingSymbol::to_payload(const std::vector<EncodingSymbol>& sym
}

for (const auto& symbol : symbols) {
spdlog::debug("syn len {}, data_len {}", symbol.len(), data_len);
if (symbol.len() <= data_len) {
auto symbol_len = symbol.copy_encoded(ptr, data_len);
auto symbol_len = symbol.encode_to(ptr, data_len);
data_len -= symbol_len;
ptr += symbol_len;
len += symbol_len;
spdlog::debug("enc len {}, data_len {}, encoded_data {}, len {}", symbol_len, data_len, encoded_data, len);
}
}
return len;
Expand All @@ -106,7 +104,6 @@ auto LibFlute::EncodingSymbol::decode_to(char* buffer, size_t max_length) const
throw "EncodingSymbol::decode_to() called for unknown fec scheme";
break;
}
return false;
}

auto LibFlute::EncodingSymbol::encode_to(char* buffer, size_t max_length) const -> size_t {
Expand Down
Loading

0 comments on commit ee481db

Please sign in to comment.