lokinet/llarp/net/exit_info.hpp

61 lines
1.1 KiB
C++
Raw Normal View History

2018-08-30 18:48:43 +00:00
#ifndef LLARP_XI_HPP
#define LLARP_XI_HPP
#include <crypto/types.hpp>
#include <net/net.hpp>
#include <util/bencode.hpp>
2019-02-07 00:22:54 +00:00
#include <iosfwd>
2018-08-30 18:48:43 +00:00
/**
* exit_info.h
*
* utilities for handling exits on the llarp network
*/
/// Exit info model
namespace llarp
{
2019-05-24 02:01:36 +00:00
struct ExitInfo
2018-08-30 18:48:43 +00:00
{
2019-12-10 13:37:41 +00:00
in6_addr address = {};
in6_addr netmask = {};
2018-08-30 18:48:43 +00:00
PubKey pubkey;
2019-05-24 02:01:36 +00:00
uint64_t version = LLARP_PROTO_VERSION;
2018-08-30 18:48:43 +00:00
2019-07-30 23:42:13 +00:00
ExitInfo() = default;
2019-05-24 02:01:36 +00:00
ExitInfo(const PubKey &pk, const nuint32_t &ipv4_exit) : pubkey(pk)
2018-11-14 19:34:17 +00:00
{
memset(address.s6_addr, 0, 16);
address.s6_addr[11] = 0xff;
address.s6_addr[10] = 0xff;
2019-04-08 17:40:51 +00:00
memcpy(address.s6_addr + 12, &ipv4_exit.n, 4);
2018-11-14 19:34:17 +00:00
memset(netmask.s6_addr, 0xff, 16);
}
2019-05-24 02:01:36 +00:00
bool
BEncode(llarp_buffer_t *buf) const;
2018-09-06 11:46:19 +00:00
2019-05-24 02:01:36 +00:00
bool
BDecode(llarp_buffer_t *buf)
2018-09-06 11:46:19 +00:00
{
2019-05-24 02:01:36 +00:00
return bencode_decode_dict(*this, buf);
2018-09-06 11:46:19 +00:00
}
2018-08-30 18:48:43 +00:00
bool
2019-05-24 02:01:36 +00:00
DecodeKey(const llarp_buffer_t &k, llarp_buffer_t *buf);
2019-02-24 23:46:37 +00:00
std::ostream &
print(std::ostream &stream, int level, int spaces) const;
2018-08-30 18:48:43 +00:00
};
2019-02-07 00:22:54 +00:00
2019-02-24 23:46:37 +00:00
inline std::ostream &
operator<<(std::ostream &out, const ExitInfo &xi)
{
return xi.print(out, -1, -1);
}
2018-08-30 18:48:43 +00:00
} // namespace llarp
#endif