Skip to content

Commit

Permalink
bugfix for vector sender; path methods
Browse files Browse the repository at this point in the history
- When passing an r-value reference to ::send_datagram(...), we must make the shared_ptr keep-alive prior to constructing the string_view pointing into the data
  • Loading branch information
dr7ana committed May 27, 2024
1 parent f4b75ec commit d4d9941
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 14 additions & 1 deletion include/oxen/quic/address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ namespace oxen::quic
return r <=> 0;
return oxenc::big_to_host(a.sin_port) <=> oxenc::big_to_host(b.sin_port);
}

if (is_ipv6() && other.is_ipv6())
{
auto& a = in6();
Expand All @@ -258,7 +259,6 @@ namespace oxen::quic
}

bool operator==(const Address& other) const { return (*this <=> other) == 0; }
bool operator!=(const Address& other) const { return !(*this == other); }

// Returns the size of the sockaddr
socklen_t socklen() const { return _addr.addrlen; }
Expand Down Expand Up @@ -340,6 +340,8 @@ namespace oxen::quic
return *this;
}

bool operator==(const Path& other) const { return std::tie(local, remote) == std::tie(other.local, other.remote); }

// template code to pass Path as ngtcp2_path into ngtcp2 functions
template <typename T>
requires std::same_as<T, ngtcp2_path>
Expand Down Expand Up @@ -390,4 +392,15 @@ namespace std
return h;
}
};

template <>
struct hash<oxen::quic::Path>
{
size_t operator()(const oxen::quic::Path& addr) const
{
auto h = hash<oxen::quic::Address>{}(addr.local);
h ^= hash<oxen::quic::Address>{}(addr.remote) + inverse_golden_ratio + (h << 6) + (h >> 2);
return h;
}
};
} // namespace std
6 changes: 3 additions & 3 deletions include/oxen/quic/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ namespace oxen::quic
template <oxenc::basic_char Char>
void send_datagram(std::vector<Char>&& buf)
{
send_datagram(
std::basic_string_view<Char>{buf.data(), buf.size()},
std::make_shared<std::vector<Char>>(std::move(buf)));
auto keep_alive = std::make_shared<std::vector<Char>>(std::move(buf));
std::basic_string_view<Char> view{keep_alive->data(), keep_alive->size()};
send_datagram(view, std::move(keep_alive));
}

template <oxenc::basic_char CharType>
Expand Down

0 comments on commit d4d9941

Please sign in to comment.