From b8802aebb5b3e0e5f33241c0532380c78120aa86 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sun, 13 Aug 2023 22:02:54 -0500 Subject: [PATCH] fix: announce LDP on listening interface (#5875) (#5896) --- libtransmission/session.h | 5 +++++ libtransmission/tr-lpd.cc | 20 +++++++++++++++++--- libtransmission/tr-lpd.h | 2 ++ tests/libtransmission/lpd-test.cc | 5 +++++ 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/libtransmission/session.h b/libtransmission/session.h index ca8e64e51..b6a74a517 100644 --- a/libtransmission/session.h +++ b/libtransmission/session.h @@ -249,6 +249,11 @@ private: { } + [[nodiscard]] tr_address bind_address(tr_address_type type) const override + { + return session_.publicAddress(type).address; + } + [[nodiscard]] tr_port port() const override { return session_.advertisedPeerPort(); diff --git a/libtransmission/tr-lpd.cc b/libtransmission/tr-lpd.cc index 27e7d48ab..8710f7ba1 100644 --- a/libtransmission/tr-lpd.cc +++ b/libtransmission/tr-lpd.cc @@ -99,9 +99,7 @@ auto makeAnnounceMsg(std::string_view cookie, tr_port port, std::vector(&opt_on), + sizeof(opt_on)) == -1) + { + return false; + } + + if (auto [ss, sslen] = mediator_.bind_address(TR_AF_INET).to_sockaddr({}); + bind(mcast_snd_socket_, reinterpret_cast(&ss), sslen) == -1) + { + return false; + } + /* configure outbound multicast TTL */ if (setsockopt( mcast_snd_socket_, diff --git a/libtransmission/tr-lpd.h b/libtransmission/tr-lpd.h index 74d30a66e..ad2571ca0 100644 --- a/libtransmission/tr-lpd.h +++ b/libtransmission/tr-lpd.h @@ -41,6 +41,8 @@ public: virtual ~Mediator() = default; + [[nodiscard]] virtual tr_address bind_address(tr_address_type type) const = 0; + [[nodiscard]] virtual tr_port port() const = 0; [[nodiscard]] virtual bool allowsLPD() const = 0; diff --git a/tests/libtransmission/lpd-test.cc b/tests/libtransmission/lpd-test.cc index 28c612798..68066294c 100644 --- a/tests/libtransmission/lpd-test.cc +++ b/tests/libtransmission/lpd-test.cc @@ -35,6 +35,11 @@ public: { } + [[nodiscard]] tr_address bind_address(tr_address_type /* type */) const override + { + return {}; + } + [[nodiscard]] tr_port port() const override { return port_;