libflute
Receiver.h
Go to the documentation of this file.
1 // libflute - FLUTE/ALC library
2 //
3 // Copyright (C) 2021 Klaus Kühnhammer (Österreichische Rundfunksender GmbH & Co KG)
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Affero General Public License for more details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 //
18 
19 #pragma once
20 #include <boost/asio.hpp>
21 #include <boost/bind.hpp>
22 #include <string>
23 #include <map>
24 #include <mutex>
25 #include "File.h"
26 #include "FileDeliveryTable.h"
27 
28 namespace LibFlute {
32  class Receiver {
33  public:
40  typedef std::function<void(std::shared_ptr<LibFlute::File>)> completion_callback_t;
50  Receiver( const std::string& iface, const std::string& address,
51  short port, uint64_t tsi,
52  boost::asio::io_service& io_service);
53 
57  virtual ~Receiver();
58 
65  void enable_ipsec( uint32_t spi, const std::string& aes_key);
66 
72  std::vector<std::shared_ptr<LibFlute::File>> file_list();
73 
77  void remove_expired_files(unsigned max_age);
78 
84  void register_completion_callback(completion_callback_t cb) { _completion_cb = cb; };
85  private:
86 
87  void handle_receive_from(const boost::system::error_code& error,
88  size_t bytes_recvd);
89  boost::asio::ip::udp::socket _socket;
90  boost::asio::ip::udp::endpoint _sender_endpoint;
91 
92  enum { max_length = 2048 };
93  char _data[max_length];
94  uint64_t _tsi;
95  std::unique_ptr<LibFlute::FileDeliveryTable> _fdt;
96  std::map<uint64_t, std::shared_ptr<LibFlute::File>> _files;
97  std::mutex _files_mutex;
98  std::string _mcast_address;
99 
100  completion_callback_t _completion_cb = nullptr;
101  };
102 };
FLUTE receiver class.
Definition: Receiver.h:32
void register_completion_callback(completion_callback_t cb)
Register a callback for file reception notifications.
Definition: Receiver.h:84
Receiver(const std::string &iface, const std::string &address, short port, uint64_t tsi, boost::asio::io_service &io_service)
Default constructor.
Definition: Receiver.cpp:27
virtual ~Receiver()
Default destructor.
Definition: Receiver.cpp:54
std::vector< std::shared_ptr< LibFlute::File > > file_list()
List all current files.
Definition: Receiver.cpp:153
void enable_ipsec(uint32_t spi, const std::string &aes_key)
Enable IPSEC ESP decryption of FLUTE payloads.
Definition: Receiver.cpp:60
void remove_expired_files(unsigned max_age)
Remove files from the list that are older than max_age seconds.
Definition: Receiver.cpp:162
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...
Definition: Receiver.h:40