mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-15 12:13:24 +00:00
b81f7025c9
Replaces custom logging system with spdlog-based oxen logging. This commit mainly replaces the backend logging with the spdlog-based system, but doesn't (yet) convert all the existing LogWarn, etc. to use the new format-based logging. New logging statements will look like: llarp::log::warning(cat, "blah: {}", val); where `cat` should be set up in each .cpp or cluster of .cpp files, as described in the oxen-logging README. As part of spdlog we get fmt, which gives us nice format strings, where are applied generously in this commit. Making types printable now requires two steps: - add a ToString() method - add this specialization: template <> constexpr inline bool llarp::IsToStringFormattable<llarp::Whatever> = true; This will then allow the type to be printed as a "{}" value in a fmt::format string. This is applied to all our printable types here, and all of the `operator<<` are removed. This commit also: - replaces various uses of `operator<<` to ToString() - replaces various uses of std::stringstream with either fmt::format or plain std::string - Rename some to_string and toString() methods to ToString() for consistency (and to work with fmt) - Replace `stringify(...)` and `make_exception` usage with fmt::format (and remove stringify/make_exception from util/str.hpp).
94 lines
2.4 KiB
C++
94 lines
2.4 KiB
C++
#include "null_crypto.hpp"
|
|
#include <llarp/util/logging.hpp>
|
|
|
|
#include <limits>
|
|
|
|
namespace llarp::quic
|
|
{
|
|
// Cranks a value to "11", i.e. set it to its maximum
|
|
template <typename T>
|
|
void
|
|
crank_to_eleven(T& val)
|
|
{
|
|
val = std::numeric_limits<T>::max();
|
|
}
|
|
|
|
NullCrypto::NullCrypto()
|
|
{
|
|
crank_to_eleven(null_ctx.max_encryption);
|
|
crank_to_eleven(null_ctx.max_decryption_failure);
|
|
null_ctx.aead.max_overhead = 1; // Fails an assertion if 0
|
|
null_aead.max_overhead = 1; // FIXME - can this be 0?
|
|
}
|
|
|
|
void
|
|
NullCrypto::client_initial(Connection& conn)
|
|
{
|
|
ngtcp2_conn_set_initial_crypto_ctx(conn, &null_ctx);
|
|
ngtcp2_conn_install_initial_key(
|
|
conn,
|
|
&null_aead_ctx,
|
|
null_iv.data(),
|
|
&null_cipher_ctx,
|
|
&null_aead_ctx,
|
|
null_iv.data(),
|
|
&null_cipher_ctx,
|
|
null_iv.size());
|
|
ngtcp2_conn_set_retry_aead(conn, &null_aead, &null_aead_ctx);
|
|
ngtcp2_conn_set_crypto_ctx(conn, &null_ctx);
|
|
}
|
|
|
|
void
|
|
NullCrypto::server_initial(Connection& conn)
|
|
{
|
|
LogDebug("Server initial null crypto setup");
|
|
ngtcp2_conn_set_initial_crypto_ctx(conn, &null_ctx);
|
|
ngtcp2_conn_install_initial_key(
|
|
conn,
|
|
&null_aead_ctx,
|
|
null_iv.data(),
|
|
&null_cipher_ctx,
|
|
&null_aead_ctx,
|
|
null_iv.data(),
|
|
&null_cipher_ctx,
|
|
null_iv.size());
|
|
ngtcp2_conn_set_crypto_ctx(conn, &null_ctx);
|
|
}
|
|
|
|
bool
|
|
NullCrypto::install_tx_handshake_key(Connection& conn)
|
|
{
|
|
return ngtcp2_conn_install_tx_handshake_key(
|
|
conn, &null_aead_ctx, null_iv.data(), null_iv.size(), &null_cipher_ctx)
|
|
== 0;
|
|
}
|
|
bool
|
|
NullCrypto::install_rx_handshake_key(Connection& conn)
|
|
{
|
|
return ngtcp2_conn_install_rx_handshake_key(
|
|
conn, &null_aead_ctx, null_iv.data(), null_iv.size(), &null_cipher_ctx)
|
|
== 0;
|
|
}
|
|
bool
|
|
NullCrypto::install_tx_key(Connection& conn)
|
|
{
|
|
return ngtcp2_conn_install_tx_key(
|
|
conn,
|
|
null_iv.data(),
|
|
null_iv.size(),
|
|
&null_aead_ctx,
|
|
null_iv.data(),
|
|
null_iv.size(),
|
|
&null_cipher_ctx)
|
|
== 0;
|
|
}
|
|
bool
|
|
NullCrypto::install_rx_key(Connection& conn)
|
|
{
|
|
return ngtcp2_conn_install_rx_key(
|
|
conn, nullptr, 0, &null_aead_ctx, null_iv.data(), null_iv.size(), &null_cipher_ctx)
|
|
== 0;
|
|
}
|
|
|
|
} // namespace llarp::quic
|