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 // Licensed under the License terms and conditions for use, reproduction, and
6 // distribution of 5G-MAG software (the “License”). You may not use this file
7 // except in compliance with the License. You may obtain a copy of the License at
8 // https://www.5g-mag.com/reference-tools. Unless required by applicable law or
9 // agreed to in writing, software distributed under the License is distributed on
10 // an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 // or implied.
12 //
13 // See the License for the specific language governing permissions and limitations
14 // under the License.
15 //
16 #pragma once
17 #include <boost/asio.hpp>
18 #include <boost/bind/bind.hpp>
19 #include <string>
20 #include <map>
21 #include <mutex>
22 #include "File.h"
23 #include "FileDeliveryTable.h"
24 
25 namespace LibFlute {
29  class Receiver {
30  public:
37  typedef std::function<void(std::shared_ptr<LibFlute::File>)> completion_callback_t;
47  Receiver( const std::string& iface, const std::string& address,
48  short port, uint64_t tsi,
49  boost::asio::io_context& io_context);
50 
54  virtual ~Receiver() = default;
55 
62  void enable_ipsec( uint32_t spi, const std::string& aes_key);
63 
69  std::vector<std::shared_ptr<LibFlute::File>> file_list();
70 
74  void remove_expired_files(unsigned max_age);
75 
79  void remove_file_with_content_location(const std::string& cl);
80 
86  void register_completion_callback(completion_callback_t cb) { _completion_cb = cb; };
87 
88  void stop() { _running = false; }
89  private:
90 
91  void handle_receive_from(const boost::system::error_code& error,
92  size_t bytes_recvd);
93  boost::asio::ip::udp::socket _socket;
94  boost::asio::ip::udp::endpoint _sender_endpoint;
95 
96  enum { max_length = 2048 };
97  char _data[max_length];
98  uint64_t _tsi;
99  std::unique_ptr<LibFlute::FileDeliveryTable> _fdt;
100  std::map<uint64_t, std::shared_ptr<LibFlute::File>> _files;
101  std::mutex _files_mutex;
102  std::string _mcast_address;
103 
104  completion_callback_t _completion_cb = nullptr;
105 
106  bool _running = true;
107  };
108 };
FLUTE receiver class.
Definition: Receiver.h:29
void register_completion_callback(completion_callback_t cb)
Register a callback for file reception notifications.
Definition: Receiver.h:86
virtual ~Receiver()=default
Default destructor.
void remove_file_with_content_location(const std::string &cl)
Remove a file from the list that matches the passed content location.
Definition: Receiver.cpp:173
std::vector< std::shared_ptr< LibFlute::File > > file_list()
List all current files.
Definition: Receiver.cpp:150
void enable_ipsec(uint32_t spi, const std::string &aes_key)
Enable IPSEC ESP decryption of FLUTE payloads.
Definition: Receiver.cpp:51
Receiver(const std::string &iface, const std::string &address, short port, uint64_t tsi, boost::asio::io_context &io_context)
Default constructor.
Definition: Receiver.cpp:24
void remove_expired_files(unsigned max_age)
Remove files from the list that are older than max_age seconds.
Definition: Receiver.cpp:159
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:37