libflute
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
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_service &io_service)
 Default constructor. More...
 
virtual ~Receiver ()
 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 register_completion_callback (completion_callback_t cb)
 Register a callback for file reception notifications. More...
 

Detailed Description

FLUTE receiver class.

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

Definition at line 32 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 40 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_service &  io_service 
)

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_serviceBoost io_service to run the socket operations in (must be provided by the caller)

Definition at line 27 of file Receiver.cpp.

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

◆ ~Receiver()

LibFlute::Receiver::~Receiver ( )
virtual

Default destructor.

Definition at line 54 of file Receiver.cpp.

55 {
56  //spdlog::debug("Closing flute receiver for ALC session {}", _alc_session_id);
57  //fcl::set_flute_session_state(_alc_session_id, fcl::SExiting);
58 }

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 60 of file Receiver.cpp.

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

◆ file_list()

auto LibFlute::Receiver::file_list ( )

List all current files.

Returns
Vector of all files currently in the FDT

Definition at line 153 of file Receiver.cpp.

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

◆ 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 84 of file Receiver.h.

84 { _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 162 of file Receiver.cpp.

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

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