fix: announce LDP on listening interface (#5875) (#5896)

This commit is contained in:
Charles Kerr 2023-08-13 22:02:54 -05:00 committed by GitHub
parent daff66690a
commit b8802aebb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 3 deletions

View File

@ -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 [[nodiscard]] tr_port port() const override
{ {
return session_.advertisedPeerPort(); return session_.advertisedPeerPort();

View File

@ -99,9 +99,7 @@ auto makeAnnounceMsg(std::string_view cookie, tr_port port, std::vector<std::str
ret += fmt::format("cookie: {:s}\r\n", cookie); ret += fmt::format("cookie: {:s}\r\n", cookie);
} }
ret += "\r\n\r\n"; return ret + "\r\n\r\n";
return ret;
} }
struct ParsedAnnounce struct ParsedAnnounce
@ -364,6 +362,22 @@ private:
return false; return false;
} }
if (setsockopt(
mcast_snd_socket_,
SOL_SOCKET,
SO_REUSEADDR,
reinterpret_cast<char const*>(&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<sockaddr*>(&ss), sslen) == -1)
{
return false;
}
/* configure outbound multicast TTL */ /* configure outbound multicast TTL */
if (setsockopt( if (setsockopt(
mcast_snd_socket_, mcast_snd_socket_,

View File

@ -41,6 +41,8 @@ public:
virtual ~Mediator() = default; virtual ~Mediator() = default;
[[nodiscard]] virtual tr_address bind_address(tr_address_type type) const = 0;
[[nodiscard]] virtual tr_port port() const = 0; [[nodiscard]] virtual tr_port port() const = 0;
[[nodiscard]] virtual bool allowsLPD() const = 0; [[nodiscard]] virtual bool allowsLPD() const = 0;

View File

@ -35,6 +35,11 @@ public:
{ {
} }
[[nodiscard]] tr_address bind_address(tr_address_type /* type */) const override
{
return {};
}
[[nodiscard]] tr_port port() const override [[nodiscard]] tr_port port() const override
{ {
return port_; return port_;