fix: announce LDP on listening interface (#5875)

* fix: make sure LDP announces are sent on the listening interface

* fix: add implementation for test mediator

* fix: set SO_REUSEADDR for send socket
This commit is contained in:
tearfur
2023-08-14 01:04:04 +08:00
committed by GitHub
parent 586cff9506
commit 27f3a5b82a
4 changed files with 29 additions and 3 deletions

View File

@@ -257,6 +257,11 @@ private:
{
}
[[nodiscard]] tr_address bind_address(tr_address_type type) const override
{
return session_.bind_address(type);
}
[[nodiscard]] tr_port port() const override
{
return session_.advertisedPeerPort();

View File

@@ -100,9 +100,7 @@ auto makeAnnounceMsg(std::string_view cookie, tr_port port, std::vector<std::str
ret += fmt::format("cookie: {:s}\r\n", cookie);
}
ret += "\r\n\r\n";
return ret;
return ret + "\r\n\r\n";
}
struct ParsedAnnounce
@@ -363,6 +361,22 @@ private:
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 */
if (setsockopt(
mcast_snd_socket_,

View File

@@ -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;

View File

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