Skip to content

Issue 197 #199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions daemon/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,19 @@ std::shared_ptr<Config> Config::parse(const std::string& filename,
config.streamer_player_buffer_files_num_ = 1;

boost::system::error_code ec;
#if BOOST_VERSION < 108700
ip::address_v4::from_string(config.rtp_mcast_base_.c_str(), ec);
#else
ip::make_address(config.rtp_mcast_base_.c_str(), ec);
#endif
if (ec) {
config.rtp_mcast_base_ = "239.1.0.1";
}
#if BOOST_VERSION < 108700
ip::address_v4::from_string(config.sap_mcast_addr_.c_str(), ec);
#else
ip::make_address(config.sap_mcast_addr_.c_str(), ec);
#endif
if (ec) {
config.sap_mcast_addr_ = "224.2.127.254";
}
Expand Down
23 changes: 23 additions & 0 deletions daemon/igmp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ class IGMP {

bool join(const std::string& interface_ip, const std::string& mcast_ip) {
uint32_t mcast_ip_addr =
#if BOOST_VERSION < 108700
ip::address_v4::from_string(mcast_ip.c_str()).to_ulong();
#else
ip::make_address(mcast_ip.c_str()).to_v4().to_uint();
#endif
std::scoped_lock<std::mutex> lock{mutex};

auto it = mcast_ref.find(mcast_ip_addr);
Expand All @@ -50,9 +54,14 @@ class IGMP {
}

error_code ec;
#if BOOST_VERSION < 108700
ip::multicast::join_group option(
ip::address::from_string(mcast_ip).to_v4(),
ip::address::from_string(interface_ip).to_v4());
#else
ip::multicast::join_group option(ip::make_address(mcast_ip).to_v4(),
ip::make_address(interface_ip).to_v4());
#endif
socket_.set_option(option, ec);
if (ec) {
BOOST_LOG_TRIVIAL(error) << "igmp:: failed to joined multicast group "
Expand All @@ -75,7 +84,11 @@ class IGMP {

bool leave(const std::string& interface_ip, const std::string& mcast_ip) {
uint32_t mcast_ip_addr =
#if BOOST_VERSION < 108700
ip::address_v4::from_string(mcast_ip.c_str()).to_ulong();
#else
ip::make_address(mcast_ip.c_str()).to_v4().to_uint();
#endif
std::scoped_lock<std::mutex> lock{mutex};

auto it = mcast_ref.find(mcast_ip_addr);
Expand All @@ -88,9 +101,15 @@ class IGMP {
}

error_code ec;

#if BOOST_VERSION < 108700
ip::multicast::leave_group option(
ip::address::from_string(mcast_ip).to_v4(),
ip::address::from_string(interface_ip).to_v4());
#else
ip::multicast::leave_group option(ip::make_address(mcast_ip).to_v4(),
ip::make_address(interface_ip).to_v4());
#endif
socket_.set_option(option, ec);
if (ec) {
BOOST_LOG_TRIVIAL(error) << "igmp:: failed to leave multicast group "
Expand All @@ -104,7 +123,11 @@ class IGMP {
}

private:
#if BOOST_VERSION < 108700
io_service io_service_;
#else
io_context io_service_;
#endif
ip::udp::socket socket_{io_service_};
udp::endpoint listen_endpoint_{udp::endpoint(address_v4::any(), 0)};
std::unordered_map<uint32_t, int> mcast_ref;
Expand Down
6 changes: 5 additions & 1 deletion daemon/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,14 @@ bool ping(const std::string& ip) {

// this requires root priv
try {
io_service io_service;
io_context io_service;
icmp::socket socket{io_service, icmp::v4()};
ip::icmp::endpoint destination(ip::icmp::v4(),
#if BOOST_VERSION < 108700
ip::address_v4::from_string(ip).to_ulong());
#else
ip::make_address(ip).to_v4().to_uint());
#endif
socket.send_to(boost::asio::buffer(buffer, sizeof buffer), destination);
} catch (...) {
BOOST_LOG_TRIVIAL(error) << "ping:: send_to() failed";
Expand Down
2 changes: 1 addition & 1 deletion daemon/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace po = boost::program_options;
namespace postyle = boost::program_options::command_line_style;
namespace logging = boost::log;

static const std::string version("bondagit-2.0.2");
static const std::string version("bondagit-2.0.3");
static std::atomic<bool> terminate = false;

void termination_handler(int signum) {
Expand Down
5 changes: 4 additions & 1 deletion daemon/netlink_client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include <boost/asio.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/asio/io_service.hpp>
#include <boost/bind/bind.hpp>
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include <cstdlib>
Expand Down Expand Up @@ -94,7 +93,11 @@ class NetlinkClient {
}

private:
#if BOOST_VERSION < 108700
boost::asio::io_service io_service_;
#else
boost::asio::io_context io_service_;
#endif
boost::asio::basic_raw_socket<nl_protocol> socket_{io_service_};
deadline_timer deadline_{io_service_};
std::string name_;
Expand Down
2 changes: 0 additions & 2 deletions daemon/rtsp_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,6 @@ std::pair<bool, RtspSource> RtspClient::process(
ss << "rtsp:" << std::hex
<< crc16(reinterpret_cast<const uint8_t*>(res.body.c_str()),
res.body.length());
/*<< std::hex <<
* ip::address_v4::from_string(address.c_str()).to_ulong();*/
rtsp_source.id = ss.str();
rtsp_source.source = "mDNS";
rtsp_source.address = address;
Expand Down
14 changes: 11 additions & 3 deletions daemon/rtsp_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ class RtspServer {
: session_manager_(session_manager),
config_(config),
acceptor_(io_service_,
tcp::endpoint(boost::asio::ip::address::from_string(
config_->get_ip_addr_str()),
config_->get_rtsp_port())) {}
tcp::endpoint(
#if BOOST_VERSION < 108700
boost::asio::ip::address::from_string(config_->get_ip_addr_str()),
#else
boost::asio::ip::make_address(config_->get_ip_addr_str()),
#endif
config_->get_rtsp_port())) {}
bool init() {
accept();
/* start rtsp server on a separate thread */
Expand Down Expand Up @@ -125,7 +129,11 @@ class RtspServer {
void accept();

std::mutex mutex_;
#if BOOST_VERSION < 108700
boost::asio::io_service io_service_;
#else
boost::asio::io_context io_service_;
#endif
std::shared_ptr<SessionManager> session_manager_;
std::shared_ptr<Config> config_;
std::vector<std::weak_ptr<RtspSession> > sessions_{session_num_max};
Expand Down
9 changes: 5 additions & 4 deletions daemon/sap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@ using namespace boost::placeholders;
using namespace boost::asio;
using namespace boost::asio::ip;

SAP::SAP(const std::string& sap_mcast_addr)
: addr_(sap_mcast_addr)
// remote_endpoint_(ip::address::from_string(addr_), port)
{
SAP::SAP(const std::string& sap_mcast_addr) : addr_(sap_mcast_addr) {
socket_.open(boost::asio::ip::udp::v4());
socket_.set_option(udp::socket::reuse_address(true));
socket_.bind(listen_endpoint_);
check_deadline();
}

bool SAP::set_multicast_interface(const std::string& interface_ip) {
#if BOOST_VERSION < 108700
ip::address_v4 local_interface = ip::address_v4::from_string(interface_ip);
#else
ip::address_v4 local_interface = ip::make_address(interface_ip).to_v4();
#endif
ip::multicast::outbound_interface oi_option(local_interface);
boost::system::error_code ec;
socket_.set_option(oi_option, ec);
Expand Down
23 changes: 19 additions & 4 deletions daemon/sap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,27 @@ class SAP {
const std::string& sdp);

std::string addr_;
#if BOOST_VERSION < 108700
io_service io_service_;
#else
io_context io_service_;
#endif
ip::udp::socket socket_{io_service_};
ip::udp::endpoint remote_endpoint_{
ip::udp::endpoint(ip::address::from_string(addr_), port)};
ip::udp::endpoint listen_endpoint_{
ip::udp::endpoint(ip::address::from_string("0.0.0.0"), port)};
ip::udp::endpoint remote_endpoint_ {
#if BOOST_VERSION < 108700
ip::udp::endpoint(ip::address::from_string(addr_), port)
#else
ip::udp::endpoint(ip::make_address(addr_), port)
#endif
};
ip::udp::endpoint listen_endpoint_ {
#if BOOST_VERSION < 108700
ip::udp::endpoint(ip::address::from_string("0.0.0.0"), port)
};
#else
ip::udp::endpoint(ip::make_address("0.0.0.0"), port)
};
#endif
deadline_timer deadline_{io_service_};
};

Expand Down
19 changes: 19 additions & 0 deletions daemon/session_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,12 @@ bool SessionManager::parse_sdp(const std::string& sdp, StreamInfo& info) const {
return false;
}
info.stream.m_ui32DestIP =
#if BOOST_VERSION < 108700
ip::address_v4::from_string(fields[2].c_str()).to_ulong();
#else

ip::make_address(fields[2].c_str()).to_v4().to_uint();
#endif
if (info.stream.m_ui32DestIP == INADDR_NONE) {
BOOST_LOG_TRIVIAL(error) << "session_manager:: invalid IPv4 "
"connection address in SDP at line "
Expand Down Expand Up @@ -524,14 +529,28 @@ std::error_code SessionManager::add_source(const StreamSource& source) {
info.stream.m_ui32RTCPSrcIP = config_->get_ip_addr();
info.stream.m_ui32SrcIP = config_->get_ip_addr(); // only for Source
boost::system::error_code ec;
#if BOOST_VERSION < 108700
ip::address_v4::from_string(source.address, ec);
#else
ip::make_address(source.address, ec);
#endif
if (!ec) {
info.stream.m_ui32DestIP =
#if BOOST_VERSION < 108700
ip::address_v4::from_string(source.address).to_ulong();
#else
ip::make_address(source.address).to_v4().to_uint();
#endif
} else {
info.stream.m_ui32DestIP =
#if BOOST_VERSION < 108700
ip::address_v4::from_string(config_->get_rtp_mcast_base().c_str())
.to_ulong() +
#else
ip::make_address(config_->get_rtp_mcast_base().c_str())
.to_v4()
.to_uint() +
#endif
source.id;
}
info.stream.m_usSrcPort = config_->get_rtp_port();
Expand Down
17 changes: 15 additions & 2 deletions daemon/tests/daemon_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ struct Client {
socket_.set_option(udp::socket::reuse_address(true));
socket_.bind(listen_endpoint_);
socket_.set_option(
#if BOOST_VERSION < 108700
multicast::join_group(address::from_string(g_sap_address).to_v4(),
address::from_string(g_daemon_address).to_v4()));

address::from_string(g_daemon_address).to_v4())
#else
multicast::join_group(make_address(g_sap_address).to_v4(),
make_address(g_daemon_address).to_v4())
#endif
);
cli_.set_connection_timeout(30);
cli_.set_read_timeout(30);
cli_.set_write_timeout(30);
Expand Down Expand Up @@ -362,10 +367,18 @@ struct Client {

private:
httplib::Client cli_{g_daemon_address, g_daemon_port};
#if BOOST_VERSION < 108700
io_service io_service_;
#else
io_context io_service_;
#endif
udp::socket socket_{io_service_};
udp::endpoint listen_endpoint_{
#if BOOST_VERSION < 108700
udp::endpoint(address::from_string("0.0.0.0"), g_sap_port)};
#else
udp::endpoint(make_address("0.0.0.0"), g_sap_port)};
#endif
};

BOOST_AUTO_TEST_CASE(is_alive) {
Expand Down