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

FLUTE receiver class. More...

#include <Receiver.h>

Public Types

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

Public Member Functions

 Receiver (const std::string &iface, const std::string &address, short port, uint64_t tsi, boost::asio::io_context &io_context)
 Default constructor. More...
 
virtual ~Receiver ()=default
 Default destructor. More...
 
void enable_ipsec (uint32_t spi, const std::string &aes_key)
 Enable IPSEC ESP decryption of FLUTE payloads. More...
 
std::vector< std::shared_ptr< LibFlute::File > > file_list ()
 List all current files. More...
 
void remove_expired_files (unsigned max_age)
 Remove files from the list that are older than max_age seconds. More...
 
void remove_file_with_content_location (const std::string &cl)
 Remove a file from the list that matches the passed content location. More...
 
void register_completion_callback (completion_callback_t cb)
 Register a callback for file reception notifications. More...
 
void stop ()
 

Detailed Description

FLUTE receiver class.

Construct an instance of this to receive files from a FLUTE/ALC session.

Definition at line 29 of file Receiver.h.

Member Typedef Documentation

◆ completion_callback_t

typedef std::function<void(std::shared_ptr<LibFlute::File>)> LibFlute::Receiver::completion_callback_t

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

Returns
shared_ptr to the received file

Definition at line 37 of file Receiver.h.

Constructor & Destructor Documentation

◆ Receiver()

LibFlute::Receiver::Receiver ( const std::string &  iface,
const std::string &  address,
short  port,
uint64_t  tsi,
boost::asio::io_context &  io_context 
)

Default constructor.

Parameters
ifaceAddress of the (local) interface to bind the receiving socket to. 0.0.0.0 = any.
addressMulticast address
portTarget port
tsiTSI value of the session
io_contextBoost io_context to run the socket operations in (must be provided by the caller)

Definition at line 24 of file Receiver.cpp.

27  : _socket(io_context)
28  , _tsi(tsi)
29  , _mcast_address(address)
30 {
31  boost::asio::ip::udp::endpoint listen_endpoint(
32  boost::asio::ip::make_address(iface), port);
33  _socket.open(listen_endpoint.protocol());
34  _socket.set_option(boost::asio::ip::multicast::enable_loopback(true));
35  _socket.set_option(boost::asio::ip::udp::socket::reuse_address(true));
36  _socket.set_option(boost::asio::socket_base::receive_buffer_size(16*1024*1024));
37  _socket.bind(listen_endpoint);
38 
39  // Join the multicast group.
40  _socket.set_option(
41  boost::asio::ip::multicast::join_group(
42  boost::asio::ip::make_address(address)));
43 
44  _socket.async_receive_from(
45  boost::asio::buffer(_data, max_length), _sender_endpoint,
46  boost::bind(&LibFlute::Receiver::handle_receive_from, this,
47  boost::asio::placeholders::error,
48  boost::asio::placeholders::bytes_transferred));
49 }

◆ ~Receiver()

virtual LibFlute::Receiver::~Receiver ( )
virtualdefault

Default destructor.

Member Function Documentation

◆ enable_ipsec()

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

Enable IPSEC ESP decryption 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 51 of file Receiver.cpp.

52 {
54 }
void enable_esp(uint32_t spi, const std::string &dest_address, Direction direction, const std::string &key)
Definition: IpSec.cpp:124

◆ file_list()

auto LibFlute::Receiver::file_list ( )

List all current files.

Returns
Vector of all files currently in the FDT

Definition at line 150 of file Receiver.cpp.

151 {
152  std::vector<std::shared_ptr<LibFlute::File>> files;
153  for (auto& f : _files) {
154  files.push_back(f.second);
155  }
156  return files;
157 }

◆ register_completion_callback()

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

Register a callback for file reception notifications.

Parameters
cbFunction to call on file completion

Definition at line 86 of file Receiver.h.

86 { _completion_cb = cb; };

◆ remove_expired_files()

auto LibFlute::Receiver::remove_expired_files ( unsigned  max_age)

Remove files from the list that are older than max_age seconds.

Definition at line 159 of file Receiver.cpp.

160 {
161  const std::lock_guard<std::mutex> lock(_files_mutex);
162  for (auto it = _files.cbegin(); it != _files.cend();)
163  {
164  auto age = time(nullptr) - it->second->received_at();
165  if ( it->second->meta().content_location != "bootstrap.multipart" && age > max_age) {
166  it = _files.erase(it);
167  } else {
168  ++it;
169  }
170  }
171 }

◆ remove_file_with_content_location()

auto LibFlute::Receiver::remove_file_with_content_location ( const std::string &  cl)

Remove a file from the list that matches the passed content location.

Definition at line 173 of file Receiver.cpp.

174 {
175  const std::lock_guard<std::mutex> lock(_files_mutex);
176  for (auto it = _files.cbegin(); it != _files.cend();)
177  {
178  if ( it->second->meta().content_location == cl) {
179  it = _files.erase(it);
180  } else {
181  ++it;
182  }
183  }
184 }

◆ stop()

void LibFlute::Receiver::stop ( )
inline

Definition at line 88 of file Receiver.h.

88 { _running = false; }

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