Skip to content

Commit

Permalink
alpns use ustrings now
Browse files Browse the repository at this point in the history
  • Loading branch information
dr7ana committed Dec 18, 2023
1 parent cfe2504 commit 9fe1aeb
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 28 deletions.
4 changes: 2 additions & 2 deletions include/quic/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ namespace oxen::quic
const ConnectionID& dcid,
const Path& path,
std::shared_ptr<IOContext> ctx,
const std::vector<std::string>& alpns,
const std::vector<ustring>& alpns,
std::chrono::nanoseconds handshake_timeout,
std::optional<ustring> remote_pk = std::nullopt,
ngtcp2_pkt_hd* hdr = nullptr);
Expand Down Expand Up @@ -303,7 +303,7 @@ namespace oxen::quic
const ConnectionID& dcid,
const Path& path,
std::shared_ptr<IOContext> ctx,
const std::vector<std::string>& alpns,
const std::vector<ustring>& alpns,
std::chrono::nanoseconds handshake_timeout,
std::optional<ustring> remote_pk = std::nullopt,
ngtcp2_pkt_hd* hdr = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion include/quic/crypto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace oxen::quic
class TLSCreds
{
public:
virtual std::unique_ptr<TLSSession> make_session(bool is_client, const std::vector<std::string>& alpns) = 0;
virtual std::unique_ptr<TLSSession> make_session(bool is_client, const std::vector<ustring>& alpns) = 0;
virtual ~TLSCreds() = default;
};

Expand Down
4 changes: 2 additions & 2 deletions include/quic/endpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ namespace oxen::quic
std::shared_ptr<IOContext> outbound_ctx;
std::shared_ptr<IOContext> inbound_ctx;

std::vector<std::string> outbound_alpns;
std::vector<std::string> inbound_alpns;
std::vector<ustring> outbound_alpns;
std::vector<ustring> inbound_alpns;
std::chrono::nanoseconds handshake_timeout{5s};

void _init_internals();
Expand Down
4 changes: 2 additions & 2 deletions include/quic/gnutls_crypto.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ namespace oxen::quic

static std::shared_ptr<GNUTLSCreds> make_from_ed_seckey(std::string sk);

std::unique_ptr<TLSSession> make_session(bool is_client, const std::vector<std::string>& alpns) override;
std::unique_ptr<TLSSession> make_session(bool is_client, const std::vector<ustring>& alpns) override;
};

class GNUTLSSession : public TLSSession
Expand All @@ -344,7 +344,7 @@ namespace oxen::quic
GNUTLSSession(
GNUTLSCreds& creds,
bool is_client,
const std::vector<std::string>& alpns,
const std::vector<ustring>& alpns,
std::optional<gnutls_key> expected_key = std::nullopt);

~GNUTLSSession();
Expand Down
8 changes: 4 additions & 4 deletions include/quic/opt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ namespace oxen::quic::opt
// supported ALPNs for outbound connections
struct outbound_alpns
{
std::vector<std::string> alpns;
explicit outbound_alpns(std::vector<std::string> alpns = {}) : alpns{std::move(alpns)} {}
std::vector<ustring> alpns;
explicit outbound_alpns(std::vector<ustring> alpns = {}) : alpns{std::move(alpns)} {}
};

// supported ALPNs for inbound connections
struct inbound_alpns
{
std::vector<std::string> alpns;
explicit inbound_alpns(std::vector<std::string> alpns = {}) : alpns{std::move(alpns)} {}
std::vector<ustring> alpns;
explicit inbound_alpns(std::vector<ustring> alpns = {}) : alpns{std::move(alpns)} {}
};

struct handshake_timeout
Expand Down
4 changes: 2 additions & 2 deletions src/connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1190,7 +1190,7 @@ namespace oxen::quic
const ConnectionID& dcid,
const Path& path,
std::shared_ptr<IOContext> ctx,
const std::vector<std::string>& alpns,
const std::vector<ustring>& alpns,
std::chrono::nanoseconds handshake_timeout,
std::optional<ustring> remote_pk,
ngtcp2_pkt_hd* hdr) :
Expand Down Expand Up @@ -1337,7 +1337,7 @@ namespace oxen::quic
const ConnectionID& dcid,
const Path& path,
std::shared_ptr<IOContext> ctx,
const std::vector<std::string>& alpns,
const std::vector<ustring>& alpns,
std::chrono::nanoseconds handshake_timeout,
std::optional<ustring> remote_pk,
ngtcp2_pkt_hd* hdr)
Expand Down
2 changes: 1 addition & 1 deletion src/gnutls_creds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ namespace oxen::quic
return p;
}

std::unique_ptr<TLSSession> GNUTLSCreds::make_session(bool is_client, const std::vector<std::string>& alpns)
std::unique_ptr<TLSSession> GNUTLSCreds::make_session(bool is_client, const std::vector<ustring>& alpns)
{
return std::make_unique<GNUTLSSession>(*this, is_client, alpns);
}
Expand Down
15 changes: 8 additions & 7 deletions src/gnutls_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@ namespace oxen::quic
}

GNUTLSSession::GNUTLSSession(
GNUTLSCreds& creds,
bool is_client,
const std::vector<std::string>& alpns,
std::optional<gnutls_key> expected_key) :
GNUTLSCreds& creds, bool is_client, const std::vector<ustring>& alpns, std::optional<gnutls_key> expected_key) :
creds{creds}, is_client{is_client}
{
log::trace(log_cat, "Entered {}", __PRETTY_FUNCTION__);
Expand Down Expand Up @@ -118,9 +115,13 @@ namespace oxen::quic
std::vector<gnutls_datum_t> allowed_alpns;
for (auto& s : alpns)
{
log::trace(log_cat, "GNUTLS adding \"{}\" to {} ALPNs", s, direction_string);
allowed_alpns.emplace_back(gnutls_datum_t{
reinterpret_cast<uint8_t*>(const_cast<char*>(s.data())), static_cast<uint32_t>(s.size())});
log::trace(
log_cat,
"GNUTLS adding \"{}\" to {} ALPNs",
to_sv(ustring_view{s.data(), s.size()}),
direction_string);
allowed_alpns.emplace_back(
gnutls_datum_t{const_cast<unsigned char*>(s.data()), static_cast<uint32_t>(s.size())});
}

if (auto rv =
Expand Down
14 changes: 7 additions & 7 deletions tests/009-alpns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace oxen::quic::test

SECTION("No Server ALPNs specified (defaulted)")
{
opt::outbound_alpns client_alpns{{"client"}};
opt::outbound_alpns client_alpns{{"client"_us}};

auto server_endpoint = test_net.endpoint(server_local, timeout);
REQUIRE_NOTHROW(server_endpoint->listen(server_tls));
Expand All @@ -59,7 +59,7 @@ namespace oxen::quic::test

SECTION("No Client ALPNs specified (defaulted)")
{
opt::inbound_alpns server_alpns{{"client", "relay"}};
opt::inbound_alpns server_alpns{{"client"_us, "relay"_us}};

auto server_endpoint = test_net.endpoint(server_local, server_alpns, timeout);
REQUIRE_NOTHROW(server_endpoint->listen(server_tls));
Expand All @@ -75,8 +75,8 @@ namespace oxen::quic::test

SECTION("Client ALPNs not supported")
{
opt::inbound_alpns server_alpns{{"client", "relay"}};
opt::outbound_alpns client_alpns{{"foobar"}};
opt::inbound_alpns server_alpns{{"client"_us, "relay"_us}};
opt::outbound_alpns client_alpns{{"foobar"_us}};

auto server_endpoint = test_net.endpoint(server_local, server_alpns, timeout);
REQUIRE_NOTHROW(server_endpoint->listen(server_tls));
Expand All @@ -92,9 +92,9 @@ namespace oxen::quic::test

SECTION("Select first ALPN both sides support")
{
opt::inbound_alpns server_alpns{{"client", "relay"}};
opt::outbound_alpns client_alpns{{"client"}};
opt::outbound_alpns client_alpns2{{"relay"}};
opt::inbound_alpns server_alpns{{"client"_us, "relay"_us}};
opt::outbound_alpns client_alpns{{"client"_us}};
opt::outbound_alpns client_alpns2{{"relay"_us}};

auto server_endpoint = test_net.endpoint(server_local, server_alpns, timeout);
REQUIRE_NOTHROW(server_endpoint->listen(server_tls));
Expand Down

0 comments on commit 9fe1aeb

Please sign in to comment.