pull/2141/head
dan 1 year ago
parent d36a569704
commit 1f24805345

@ -1,4 +1,4 @@
CLANG_FORMAT_DESIRED_VERSION=16
CLANG_FORMAT_DESIRED_VERSION=14
CLANG_FORMAT=$(command -v clang-format-$CLANG_FORMAT_DESIRED_VERSION 2>/dev/null)
if [ $? -ne 0 ]; then

@ -267,8 +267,7 @@ namespace
GenerateDump(EXCEPTION_POINTERS* pExceptionPointers)
{
const auto flags =
(MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithFullMemoryInfo | MiniDumpWithHandleData
| MiniDumpWithUnloadedModules | MiniDumpWithThreadInfo);
(MINIDUMP_TYPE)(MiniDumpWithFullMemory | MiniDumpWithFullMemoryInfo | MiniDumpWithHandleData | MiniDumpWithUnloadedModules | MiniDumpWithThreadInfo);
std::stringstream ss;
ss << "C:\\ProgramData\\lokinet\\crash-" << llarp::time_now_ms().count() << ".dmp";

@ -105,9 +105,11 @@ namespace llarp
constexpr bool is_default_array<U&> = is_default_array<remove_cvref_t<U>>;
template <typename T, typename Option>
constexpr bool is_option = std::is_base_of_v<option_flag, remove_cvref_t<Option>>
or std::is_same_v<Comment, Option> or is_default<Option> or is_default_array<Option>
or std::is_invocable_v<remove_cvref_t<Option>, T>;
constexpr bool is_option =
std::is_base_of_v<
option_flag,
remove_cvref_t<
Option>> or std::is_same_v<Comment, Option> or is_default<Option> or is_default_array<Option> or std::is_invocable_v<remove_cvref_t<Option>, T>;
} // namespace config
/// A base class for specifying config options and their constraints. The basic to/from string

@ -128,7 +128,7 @@ namespace llarp
".snode.loki"sv, ".loki.loki"sv, ".snode.loki."sv, ".loki.loki."sv};
for (const auto& reserved : reserved_names)
{
if (ends_with(name, reserved)) // subdomain foo.loki.loki
if (ends_with(name, reserved)) // subdomain foo.loki.loki
return true;
if (name == reserved.substr(1)) // loki.loki itself
return true;

@ -335,7 +335,6 @@ struct lokinet_context
tcp_conns[res.tcp_id] = false;
active_conns[remote_addr] = lokinet_tcp_result{res};
}
};
namespace
@ -715,7 +714,8 @@ extern "C"
return;
}
auto on_open = [result, localAddr, remotehost, remoteport, open_cb](bool success, void* user_data) {
auto on_open = [result, localAddr, remotehost, remoteport, open_cb](
bool success, void* user_data) {
llarp::log::info(
logcat,
"Quic tunnel {}<->{}:{} {}.",
@ -731,8 +731,7 @@ extern "C"
};
auto on_close = [&ctx, localAddr, remote, close_cb](int rv, void* user_data) {
llarp::log::info(
logcat, "Quic tunnel {}<->{} closed.", localAddr, remote);
llarp::log::info(logcat, "Quic tunnel {}<->{} closed.", localAddr, remote);
ctx->active_conns.erase(remote);
@ -744,14 +743,14 @@ extern "C"
std::future<void> future = promise.get_future();
ctx->impl->CallSafe([&promise,
ctx,
result,
router = ctx->impl->router,
remotehost,
remoteport,
on_open = std::move(on_open),
on_close = std::move(on_close),
localAddr]() mutable {
ctx,
result,
router = ctx->impl->router,
remotehost,
remoteport,
on_open = std::move(on_open),
on_close = std::move(on_close),
localAddr]() mutable {
try
{
auto ep = ctx->endpoint();
@ -761,8 +760,8 @@ extern "C"
if (not quic)
throw std::runtime_error{"lokinet_context endpoint has no quic tunnel manager."};
auto [addr, id] = quic->open(
remotehost, remoteport, std::move(on_open), std::move(on_close), localAddr);
auto [addr, id] =
quic->open(remotehost, remoteport, std::move(on_open), std::move(on_close), localAddr);
auto [host, port] = split_host_port(addr.ToString());
result->tcp_id = id;
tcp_okay(result, host, port, id);

@ -24,7 +24,7 @@ namespace llarp
/// Empty constructor.
IpAddress() = default;
/// move construtor
IpAddress(IpAddress&&) = default;
IpAddress(IpAddress &&) = default;
/// copy construct
IpAddress(const IpAddress&);
@ -54,80 +54,64 @@ namespace llarp
/// @param addr is an SockAddr to initialize from.
IpAddress(const SockAddr& addr);
IpAddress&
operator=(const sockaddr& other);
IpAddress& operator=(const sockaddr& other);
/// move assignment
IpAddress&
operator=(IpAddress&& other);
IpAddress& operator=(IpAddress&& other);
/// copy assignment
IpAddress&
operator=(const IpAddress& other);
IpAddress& operator=(const IpAddress& other);
/// Return the port. Returns -1 if no port has been provided.
///
/// @return the port, if present
std::optional<uint16_t>
getPort() const;
std::optional<uint16_t> getPort() const;
/// Return true if we have a port set otherwise return false
bool
hasPort() const;
bool hasPort() const;
/// Set the port.
///
/// @param port
void
setPort(std::optional<uint16_t> port);
void setPort(std::optional<uint16_t> port);
/// Set the IP address. Follows the same logic as the constructor with the same signature, but
/// doesn't overwrite the port if the port isn't present in the string.
void
setAddress(std::string_view str);
void
setAddress(std::string_view str, std::optional<uint16_t> port);
void setAddress(std::string_view str);
void setAddress(std::string_view str, std::optional<uint16_t> port);
/// Returns true if this is an IPv4 address (or an IPv6 address representing an IPv4 address)
///
/// TODO: could return an int (e.g. 4 or 6) or an enum
///
/// @return true if this is an IPv4 address, false otherwise
bool
isIPv4();
bool isIPv4();
/// Returns true if this represents a valid IpAddress, false otherwise.
///
/// @return whether or not this IpAddress is empty
bool
isEmpty() const;
bool isEmpty() const;
/// Creates an instance of SockAddr representing this IpAddress.
///
/// @return an instance of a SockAddr created from this IpAddress
SockAddr
createSockAddr() const;
SockAddr createSockAddr() const;
/// Returns true if this IpAddress is a bogon, false otherwise
///
/// @return whether or not this IpAddress is a bogon
bool
isBogon() const;
bool isBogon() const;
/// Returns a string representing this IpAddress
///
/// @return string representation of this IpAddress
std::string
ToString() const;
std::string ToString() const;
std::string
toHost() const;
std::string toHost() const;
huint32_t
toIP() const;
huint32_t toIP() const;
huint128_t
toIP6() const;
huint128_t toIP6() const;
// TODO: other utility functions left over from Addr which may be useful
// IsBogon() const;
@ -135,11 +119,9 @@ namespace llarp
// std::hash
// to string / stream / etc
bool
operator<(const IpAddress& other) const;
bool operator<(const IpAddress& other) const;
bool
operator==(const IpAddress& other) const;
bool operator==(const IpAddress& other) const;
private:
bool m_empty = true;

@ -216,8 +216,7 @@ namespace llarp
operator<<=(uint64_t shift)
{
if (shift == 0)
{
}
{}
else if (shift < 64)
{
upper = upper << shift | (lower >> (64 - shift));
@ -251,8 +250,7 @@ namespace llarp
operator>>=(uint64_t shift)
{
if (shift == 0)
{
}
{}
else if (shift < 64)
{
lower = lower >> shift | upper << (64 - shift);

@ -409,7 +409,7 @@ namespace llarp::quic
for (; it != map.end(); ++it, ++start)
if (it->first != start)
return start;
if (start != 0) // `start` didn't wrap which means we found an empty slot
if (start != 0) // `start` didn't wrap which means we found an empty slot
return start;
assert(!from_zero); // There *must* be a free slot somewhere in [0, max] (otherwise the map
// would be completely full and we'd have returned nullopt).

@ -151,8 +151,9 @@ namespace llarp::rpc
typename BTConsumer,
typename T,
std::enable_if_t<
std::is_same_v<BTConsumer, oxenc::bt_dict_consumer>
|| std::is_same_v<BTConsumer, oxenc::bt_list_consumer>,
std::is_same_v<
BTConsumer,
oxenc::bt_dict_consumer> || std::is_same_v<BTConsumer, oxenc::bt_list_consumer>,
int> = 0>
void
load_value(BTConsumer& c, T& target)
@ -244,8 +245,8 @@ namespace llarp::rpc
target = current.get<std::string_view>();
}
else if constexpr (
llarp::rpc::json_is_binary<T> || is_expandable_list<T> || is_tuple_like<T>
|| is_unordered_string_map<T>)
llarp::rpc::json_is_binary<
T> || is_expandable_list<T> || is_tuple_like<T> || is_unordered_string_map<T>)
{
try
{
@ -354,8 +355,9 @@ namespace llarp::rpc
else
{
static_assert(
std::is_same_v<json_range, Input> || std::is_same_v<oxenc::bt_dict_consumer, Input>
|| std::is_same_v<std::monostate, Input>);
std::is_same_v<
json_range,
Input> || std::is_same_v<oxenc::bt_dict_consumer, Input> || std::is_same_v<std::monostate, Input>);
get_next_value(in, name, val);
if constexpr (sizeof...(More) > 0)
{

@ -31,7 +31,10 @@ namespace llarp
obj["lastPublished"] = to_json(m_LastPublish);
obj["lastPublishAttempt"] = to_json(m_LastPublishAttempt);
obj["introset"] = m_IntroSet.ExtractStatus();
static auto getSecond = [](const auto& item) -> auto { return item.second->ExtractStatus(); };
static auto getSecond = [](const auto& item) -> auto
{
return item.second->ExtractStatus();
};
std::transform(
m_DeadSessions.begin(),

@ -174,7 +174,7 @@ namespace llarp
{
if (buffer->size_left() < 2) // minimum case is 'de'
return false;
if (*buffer->cur != 'd') // ensure is a dictionary
if (*buffer->cur != 'd') // ensure is a dictionary
return false;
buffer->cur++;
while (buffer->size_left() && *buffer->cur != 'e')
@ -222,7 +222,7 @@ namespace llarp
{
if (buffer->size_left() < 2) // minimum case is 'le'
return false;
if (*buffer->cur != 'l') // ensure is a list
if (*buffer->cur != 'l') // ensure is a list
{
llarp::LogWarn("bencode::bencode_read_list - expecting list got ", *buffer->cur);
return false;

@ -36,19 +36,18 @@ struct [[deprecated("this type is stupid, use something else")]] llarp_buffer_t
/// max size of buffer
size_t sz{0};
byte_t
operator[](size_t x)
byte_t operator[](size_t x)
{
return *(this->base + x);
}
llarp_buffer_t() = default;
llarp_buffer_t(byte_t* b, byte_t* c, size_t s) : base(b), cur(c), sz(s)
llarp_buffer_t(byte_t * b, byte_t * c, size_t s) : base(b), cur(c), sz(s)
{}
llarp_buffer_t(const ManagedBuffer&) = delete;
llarp_buffer_t(ManagedBuffer&&) = delete;
llarp_buffer_t(ManagedBuffer &&) = delete;
template <typename Byte>
static constexpr bool is_basic_byte = sizeof(Byte) == 1 and std::is_trivially_copyable_v<Byte>;
@ -58,21 +57,21 @@ struct [[deprecated("this type is stupid, use something else")]] llarp_buffer_t
template <
typename Byte,
typename = std::enable_if_t<not std::is_const_v<Byte> && is_basic_byte<Byte>>>
llarp_buffer_t(Byte* buf, size_t sz) : base{reinterpret_cast<byte_t*>(buf)}, cur{base}, sz{sz}
llarp_buffer_t(Byte * buf, size_t sz) : base{reinterpret_cast<byte_t*>(buf)}, cur{base}, sz{sz}
{}
/// initialize llarp_buffer_t from vector or array of byte-like values
template <
typename Byte,
typename = std::enable_if_t<not std::is_const_v<Byte> && is_basic_byte<Byte>>>
llarp_buffer_t(std::vector<Byte>& b) : llarp_buffer_t{b.data(), b.size()}
llarp_buffer_t(std::vector<Byte> & b) : llarp_buffer_t{b.data(), b.size()}
{}
template <
typename Byte,
size_t N,
typename = std::enable_if_t<not std::is_const_v<Byte> && is_basic_byte<Byte>>>
llarp_buffer_t(std::array<Byte, N>& b) : llarp_buffer_t{b.data(), b.size()}
llarp_buffer_t(std::array<Byte, N> & b) : llarp_buffer_t{b.data(), b.size()}
{}
// These overloads, const_casting away the const, are not just gross but downright dangerous:
@ -98,32 +97,27 @@ struct [[deprecated("this type is stupid, use something else")]] llarp_buffer_t
template <
typename T,
typename = std::void_t<decltype(std::declval<T>().data() + std::declval<T>().size())>>
explicit llarp_buffer_t(T&& t) : llarp_buffer_t{t.data(), t.size()}
explicit llarp_buffer_t(T && t) : llarp_buffer_t{t.data(), t.size()}
{}
byte_t*
begin()
byte_t* begin()
{
return base;
}
const byte_t*
begin() const
const byte_t* begin() const
{
return base;
}
byte_t*
end()
byte_t* end()
{
return base + sz;
}
const byte_t*
end() const
const byte_t* end() const
{
return base + sz;
}
size_t
size_left() const
size_t size_left() const
{
size_t diff = cur - base;
assert(diff <= sz);
@ -133,66 +127,50 @@ struct [[deprecated("this type is stupid, use something else")]] llarp_buffer_t
}
template <typename OutputIt>
bool
read_into(OutputIt begin, OutputIt end);
bool read_into(OutputIt begin, OutputIt end);
template <typename InputIt>
bool
write(InputIt begin, InputIt end);
bool write(InputIt begin, InputIt end);
#ifndef _WIN32
bool
writef(const char* fmt, ...) __attribute__((format(printf, 2, 3)));
bool writef(const char* fmt, ...) __attribute__((format(printf, 2, 3)));
#elif defined(__MINGW64__) || defined(__MINGW32__)
bool
writef(const char* fmt, ...) __attribute__((__format__(__MINGW_PRINTF_FORMAT, 2, 3)));
bool writef(const char* fmt, ...) __attribute__((__format__(__MINGW_PRINTF_FORMAT, 2, 3)));
#else
bool
writef(const char* fmt, ...);
bool writef(const char* fmt, ...);
#endif
bool
put_uint16(uint16_t i);
bool
put_uint32(uint32_t i);
bool put_uint16(uint16_t i);
bool put_uint32(uint32_t i);
bool
put_uint64(uint64_t i);
bool put_uint64(uint64_t i);
bool
read_uint16(uint16_t& i);
bool
read_uint32(uint32_t& i);
bool read_uint16(uint16_t & i);
bool read_uint32(uint32_t & i);
bool
read_uint64(uint64_t& i);
bool read_uint64(uint64_t & i);
size_t
read_until(char delim, byte_t* result, size_t resultlen);
size_t read_until(char delim, byte_t* result, size_t resultlen);
/// make a copy of this buffer
std::vector<byte_t>
copy() const;
std::vector<byte_t> copy() const;
/// get a read-only view over the entire region
llarp::byte_view_t
view_all() const
llarp::byte_view_t view_all() const
{
return {base, sz};
}
/// get a read-only view over the remaining/unused region
llarp::byte_view_t
view_remaining() const
llarp::byte_view_t view_remaining() const
{
return {cur, size_left()};
}
/// Part of the curse. Returns true if the remaining buffer space starts with the given string
/// view.
bool
startswith(std::string_view prefix_str) const
bool startswith(std::string_view prefix_str) const
{
llarp::byte_view_t prefix{
reinterpret_cast<const byte_t*>(prefix_str.data()), prefix_str.size()};
@ -202,7 +180,7 @@ struct [[deprecated("this type is stupid, use something else")]] llarp_buffer_t
private:
friend struct ManagedBuffer;
llarp_buffer_t(const llarp_buffer_t&) = default;
llarp_buffer_t(llarp_buffer_t&&) = default;
llarp_buffer_t(llarp_buffer_t &&) = default;
};
template <typename OutputIt>
@ -244,7 +222,7 @@ struct [[deprecated("deprecated along with llarp_buffer_t")]] ManagedBuffer
explicit ManagedBuffer(const llarp_buffer_t& b) : underlying(b)
{}
ManagedBuffer(ManagedBuffer&&) = default;
ManagedBuffer(ManagedBuffer &&) = default;
ManagedBuffer(const ManagedBuffer&) = default;
operator const llarp_buffer_t&() const

@ -78,12 +78,12 @@ namespace llarp
char m_popPadding[Alignment - sizeof(AtomicIndex)];
const size_t m_capacity; // max size of the manager.
const size_t m_capacity; // max size of the manager.
const uint32_t m_maxGeneration; // Maximum generation for this object.
const uint32_t m_maxGeneration; // Maximum generation for this object.
const uint32_t m_maxCombinedIndex; // Maximum combined value of index and
// generation for this object.
const uint32_t m_maxCombinedIndex; // Maximum combined value of index and
// generation for this object.
std::atomic<std::uint32_t>* m_states; // Array of index states.

Loading…
Cancel
Save