1
1
Fork 0
mirror of https://github.com/oxen-io/lokinet synced 2023-12-14 06:53:00 +01:00
lokinet/llarp/service/info.hpp
Thomas Winget 7caa87862e standardize include format and pragma once
All #ifndef guards on headers have been removed, I think,
in favor of #pragma once

Headers are now included as `#include "filename"` if the included file
resides in the same directory as the file including it, or any
subdirectory therein.  Otherwise they are included as
`#include <project/top/dir/relative/path/filename>`

The above does not include system/os headers.
2021-03-09 19:01:41 -05:00

111 lines
2.2 KiB
C++

#pragma once
#include <llarp/crypto/types.hpp>
#include "address.hpp"
#include "vanity.hpp"
#include <llarp/util/bencode.hpp>
#include <optional>
namespace llarp
{
namespace service
{
struct ServiceInfo
{
private:
PubKey enckey;
PubKey signkey;
mutable Address m_CachedAddr;
public:
VanityNonce vanity;
uint64_t version = LLARP_PROTO_VERSION;
void
RandomizeVanity()
{
vanity.Randomize();
}
bool
Verify(const llarp_buffer_t& payload, const Signature& sig) const;
const PubKey&
EncryptionPublicKey() const
{
if (m_CachedAddr.IsZero())
{
CalculateAddress(m_CachedAddr.as_array());
}
return enckey;
}
bool
Update(const byte_t* sign, const byte_t* enc, const std::optional<VanityNonce>& nonce = {});
bool
operator==(const ServiceInfo& other) const
{
return enckey == other.enckey && signkey == other.signkey && version == other.version
&& vanity == other.vanity;
}
bool
operator!=(const ServiceInfo& other) const
{
return !(*this == other);
}
bool
operator<(const ServiceInfo& other) const
{
return Addr() < other.Addr();
}
std::ostream&
print(std::ostream& stream, int level, int spaces) const;
/// .loki address
std::string
Name() const;
bool
UpdateAddr();
const Address&
Addr() const
{
if (m_CachedAddr.IsZero())
{
CalculateAddress(m_CachedAddr.as_array());
}
return m_CachedAddr;
}
/// calculate our address
bool
CalculateAddress(std::array<byte_t, 32>& data) const;
bool
BDecode(llarp_buffer_t* buf)
{
if (not bencode_decode_dict(*this, buf))
return false;
return UpdateAddr();
}
bool
BEncode(llarp_buffer_t* buf) const;
bool
DecodeKey(const llarp_buffer_t& key, llarp_buffer_t* buf);
};
inline std::ostream&
operator<<(std::ostream& out, const ServiceInfo& i)
{
return i.print(out, -1, -1);
}
} // namespace service
} // namespace llarp