libflute
Public Types | Public Member Functions | List of all members
LibFlute::Transmitter Class Reference

FLUTE transmitter class. More...

#include <Transmitter.h>

Public Types

typedef std::function< void(uint32_t)> completion_callback_t
 Definition of a file transmission completion callback function that can be registered through ::register_completion_callback. More...
 

Public Member Functions

 Transmitter (const std::string &address, short port, uint64_t tsi, unsigned short mtu, uint32_t rate_limit, boost::asio::io_service &io_service)
 Default constructor. More...
 
virtual ~Transmitter ()
 Default destructor. More...
 
void enable_ipsec (uint32_t spi, const std::string &aes_key)
 Enable IPSEC ESP encryption of FLUTE payloads. More...
 
uint16_t send (const std::string &content_location, const std::string &content_type, uint32_t expires, char *data, size_t length)
 Transmit a file. More...
 
uint64_t seconds_since_epoch ()
 Convenience function to get the current timestamp for expiry calculation. More...
 
void register_completion_callback (completion_callback_t cb)
 Register a callback for file transmission completion notifications. More...
 

Detailed Description

FLUTE transmitter class.

Construct an instance of this to send data through a FLUTE/ALC session.

Definition at line 34 of file Transmitter.h.

Member Typedef Documentation

◆ completion_callback_t

typedef std::function<void(uint32_t)> LibFlute::Transmitter::completion_callback_t

Definition of a file transmission completion callback function that can be registered through ::register_completion_callback.

Parameters
toiTOI of the file that has completed transmission

Definition at line 42 of file Transmitter.h.

Constructor & Destructor Documentation

◆ Transmitter()

LibFlute::Transmitter::Transmitter ( const std::string &  address,
short  port,
uint64_t  tsi,
unsigned short  mtu,
uint32_t  rate_limit,
boost::asio::io_service &  io_service 
)

Default constructor.

Parameters
addressTarget multicast address
portTarget port
tsiTSI value for the session
mtuPath MTU to size FLUTE packets for
rate_limitTransmit rate limit (in kbps)
io_serviceBoost io_service to run the socket operations in (must be provided by the caller)

Definition at line 26 of file Transmitter.cpp.

29  : _endpoint(boost::asio::ip::address::from_string(address), port)
30  , _socket(io_service, _endpoint.protocol())
31  , _fdt_timer(io_service)
32  , _send_timer(io_service)
33  , _io_service(io_service)
34  , _tsi(tsi)
35  , _mtu(mtu)
36  , _rate_limit(rate_limit)
37  , _mcast_address(address)
38 {
39  _max_payload = mtu -
40  20 - // IPv4 header
41  8 - // UDP header
42  32 - // ALC Header with EXT_FDT and EXT_FTI
43  4; // SBN and ESI for compact no-code FEC
44  uint32_t max_source_block_length = 64;
45 
46  _socket.set_option(boost::asio::ip::multicast::enable_loopback(true));
47  _socket.set_option(boost::asio::ip::udp::socket::reuse_address(true));
48 
49  _fec_oti = FecOti{FecScheme::CompactNoCode, 0, _max_payload, max_source_block_length};
50  _fdt = std::make_unique<FileDeliveryTable>(1, _fec_oti);
51 
52  _fdt_timer.expires_from_now(boost::posix_time::seconds(_fdt_repeat_interval));
53  _fdt_timer.async_wait( boost::bind(&Transmitter::fdt_send_tick, this));
54 
55  send_next_packet();
56 }

◆ ~Transmitter()

LibFlute::Transmitter::~Transmitter ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ enable_ipsec()

auto LibFlute::Transmitter::enable_ipsec ( uint32_t  spi,
const std::string &  aes_key 
)

Enable IPSEC ESP encryption of FLUTE payloads.

Parameters
spiSecurity Parameter Index value to use
keyAES key as a hex string (without leading 0x). Must be an even number of characters long.

Definition at line 60 of file Transmitter.cpp.

61 {
63 }
void enable_esp(uint32_t spi, const std::string &dest_address, Direction direction, const std::string &key)
Definition: IpSec.cpp:125

◆ register_completion_callback()

void LibFlute::Transmitter::register_completion_callback ( completion_callback_t  cb)
inline

Register a callback for file transmission completion notifications.

Parameters
cbFunction to call on file completion

Definition at line 103 of file Transmitter.h.

103 { _completion_cb = cb; };

◆ seconds_since_epoch()

auto LibFlute::Transmitter::seconds_since_epoch ( )

Convenience function to get the current timestamp for expiry calculation.

Returns
seconds since the NTP epoch

Definition at line 71 of file Transmitter.cpp.

72 {
73  return std::chrono::duration_cast<std::chrono::seconds>(
74  std::chrono::system_clock::now().time_since_epoch()).count();
75 }

◆ send()

auto LibFlute::Transmitter::send ( const std::string &  content_location,
const std::string &  content_type,
uint32_t  expires,
char *  data,
size_t  length 
)

Transmit a file.

The caller must ensure the data buffer passed here remains valid until the completion callback for this file is called.

Parameters
content_locationURI to set in the content location field of the generated FDT entry
content_typeMIME type to set in the content type field of the generated FDT entry
expiresExpiry timestamp (based on NTP epoch)
dataPointer to the data buffer (managed by caller)
lengthLength of the data buffer (in bytes)
Returns
TOI of the file

Definition at line 93 of file Transmitter.cpp.

99 {
100  auto toi = _toi;
101  _toi++;
102  if (_toi == 0) _toi = 1; // clamp to >= 1 in case it wraps
103 
104  auto file = std::make_shared<File>(
105  toi,
106  _fec_oti,
107  content_location,
108  content_type,
109  expires,
110  data,
111  length);
112 
113  _fdt->add(file->meta());
114  send_fdt();
115  _files.insert({toi, file});
116  return toi;
117 }

The documentation for this class was generated from the following files: