lokinet/include/llarp/router_contact.hpp

112 lines
2.1 KiB
C++
Raw Normal View History

2018-08-30 18:48:43 +00:00
#ifndef LLARP_RC_HPP
#define LLARP_RC_HPP
#include <llarp/address_info.hpp>
#include <llarp/crypto.h>
#include <llarp/bencode.hpp>
#include <llarp/exit_info.hpp>
2018-08-31 13:51:24 +00:00
#include <vector>
2018-08-30 18:48:43 +00:00
#define MAX_RC_SIZE (1024)
#define NICKLEN (32)
namespace llarp
{
struct RouterContact final : public IBEncodeMessage
2018-08-30 18:48:43 +00:00
{
2018-09-06 11:46:19 +00:00
RouterContact() : IBEncodeMessage()
{
Clear();
}
RouterContact(const RouterContact &other)
: IBEncodeMessage()
, addrs(other.addrs)
2018-09-06 11:46:19 +00:00
, enckey(other.enckey)
, pubkey(other.pubkey)
, exits(other.exits)
, signature(other.signature)
, nickname(other.nickname)
, last_updated(other.last_updated)
{
version = other.version;
}
2018-08-30 18:48:43 +00:00
// advertised addresses
std::vector< AddressInfo > addrs;
2018-08-30 18:48:43 +00:00
// public encryption public key
llarp::PubKey enckey;
// public signing public key
llarp::PubKey pubkey;
// advertised exits
std::vector< ExitInfo > exits;
2018-08-30 18:48:43 +00:00
// signature
llarp::Signature signature;
/// node nickname, yw kee
llarp::AlignedBuffer< NICKLEN > nickname;
uint64_t last_updated;
bool
BEncode(llarp_buffer_t *buf) const override;
2018-08-30 18:48:43 +00:00
2018-08-31 13:51:24 +00:00
void
Clear();
2018-11-14 18:02:27 +00:00
bool
IsExit() const
{
return exits.size() > 0;
}
2018-08-31 13:51:24 +00:00
bool
BDecode(llarp_buffer_t *buf) override
2018-08-31 13:51:24 +00:00
{
Clear();
return IBEncodeMessage::BDecode(buf);
}
2018-08-30 18:48:43 +00:00
bool
DecodeKey(llarp_buffer_t k, llarp_buffer_t *buf) override;
2018-08-30 18:48:43 +00:00
RouterContact &
operator=(const RouterContact &other);
bool
HasNick() const;
std::string
Nick() const;
bool
IsPublicRouter() const;
void
SetNick(const std::string &nick);
bool
2018-10-15 12:02:32 +00:00
Verify(llarp_crypto *crypto) const;
2018-08-30 18:48:43 +00:00
bool
Sign(llarp_crypto *crypto, const llarp::SecretKey &secret);
2018-09-10 17:37:28 +00:00
bool
OtherIsNewer(const RouterContact &other) const
{
return last_updated < other.last_updated;
}
2018-08-30 18:48:43 +00:00
bool
Read(const char *fname);
bool
Write(const char *fname) const;
2018-10-15 12:02:32 +00:00
private:
bool
VerifySignature(llarp_crypto *crypto) const;
2018-08-30 18:48:43 +00:00
};
} // namespace llarp
#endif