mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-07 15:20:31 +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).
73 lines
1.8 KiB
C++
73 lines
1.8 KiB
C++
#pragma once
|
|
|
|
#include <llarp/util/status.hpp>
|
|
#include <llarp/util/types.hpp>
|
|
#include <llarp/util/formattable.hpp>
|
|
|
|
#include <fmt/format.h>
|
|
|
|
#include <functional>
|
|
|
|
namespace llarp
|
|
{
|
|
struct ILinkSession;
|
|
struct RouterID;
|
|
struct RouterContact;
|
|
|
|
enum class SessionResult
|
|
{
|
|
Establish,
|
|
Timeout,
|
|
RouterNotFound,
|
|
InvalidRouter,
|
|
NoLink,
|
|
EstablishFail
|
|
};
|
|
|
|
constexpr std::string_view
|
|
ToString(SessionResult sr)
|
|
{
|
|
return sr == llarp::SessionResult::Establish ? "success"sv
|
|
: sr == llarp::SessionResult::Timeout ? "timeout"sv
|
|
: sr == llarp::SessionResult::NoLink ? "no link"sv
|
|
: sr == llarp::SessionResult::InvalidRouter ? "invalid router"sv
|
|
: sr == llarp::SessionResult::RouterNotFound ? "not found"sv
|
|
: sr == llarp::SessionResult::EstablishFail ? "establish failed"sv
|
|
: "???"sv;
|
|
}
|
|
template <>
|
|
constexpr inline bool IsToStringFormattable<SessionResult> = true;
|
|
|
|
using RouterCallback = std::function<void(const RouterID&, const SessionResult)>;
|
|
|
|
struct IOutboundSessionMaker
|
|
{
|
|
virtual ~IOutboundSessionMaker() = default;
|
|
|
|
virtual bool
|
|
OnSessionEstablished(ILinkSession* session) = 0;
|
|
|
|
virtual void
|
|
OnConnectTimeout(ILinkSession* session) = 0;
|
|
|
|
virtual void
|
|
CreateSessionTo(const RouterID& router, RouterCallback on_result) = 0;
|
|
|
|
virtual void
|
|
CreateSessionTo(const RouterContact& rc, RouterCallback on_result) = 0;
|
|
|
|
virtual bool
|
|
HavePendingSessionTo(const RouterID& router) const = 0;
|
|
|
|
virtual void
|
|
ConnectToRandomRouters(int numDesired) = 0;
|
|
|
|
virtual util::StatusObject
|
|
ExtractStatus() const = 0;
|
|
|
|
virtual bool
|
|
ShouldConnectTo(const RouterID& router) const = 0;
|
|
};
|
|
|
|
} // namespace llarp
|