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
- Path comparison methods added plus hash for indexing using paths
  • Loading branch information
dr7ana committed May 17, 2024
1 parent f4b75ec commit d1962e5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions include/oxen/quic/address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ namespace oxen::quic
return *this;
}

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

bool operator!=(const Path& other) const { return !(*this == other); }

// 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 +394,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);
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 d1962e5

Please sign in to comment.