2018-08-30 18:48:43 +00:00
|
|
|
#ifndef LLARP_XI_HPP
|
|
|
|
#define LLARP_XI_HPP
|
2018-12-12 02:52:51 +00:00
|
|
|
|
|
|
|
#include <bencode.hpp>
|
|
|
|
#include <bits.hpp>
|
2018-12-12 00:38:58 +00:00
|
|
|
#include <crypto.hpp>
|
2018-12-12 02:52:51 +00:00
|
|
|
#include <net.hpp>
|
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* exit_info.h
|
|
|
|
*
|
|
|
|
* utilities for handling exits on the llarp network
|
|
|
|
*/
|
|
|
|
|
|
|
|
/// Exit info model
|
|
|
|
namespace llarp
|
|
|
|
{
|
2018-11-05 11:27:12 +00:00
|
|
|
struct ExitInfo final : public IBEncodeMessage
|
2018-08-30 18:48:43 +00:00
|
|
|
{
|
|
|
|
struct in6_addr address;
|
|
|
|
struct in6_addr netmask;
|
|
|
|
PubKey pubkey;
|
|
|
|
|
2018-11-14 19:34:17 +00:00
|
|
|
ExitInfo(const PubKey &pk, const nuint32_t &ipv4_exit) : IBEncodeMessage()
|
|
|
|
{
|
|
|
|
pubkey = pk;
|
|
|
|
memset(address.s6_addr, 0, 16);
|
|
|
|
address.s6_addr[11] = 0xff;
|
|
|
|
address.s6_addr[10] = 0xff;
|
|
|
|
memcpy(address.s6_addr + 12, &ipv4_exit, 4);
|
|
|
|
memset(netmask.s6_addr, 0xff, 16);
|
|
|
|
}
|
|
|
|
|
2018-09-06 11:46:19 +00:00
|
|
|
ExitInfo() : IBEncodeMessage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ExitInfo(const ExitInfo &other) : IBEncodeMessage()
|
|
|
|
{
|
|
|
|
pubkey = other.pubkey;
|
|
|
|
memcpy(address.s6_addr, other.address.s6_addr, 16);
|
|
|
|
memcpy(netmask.s6_addr, other.netmask.s6_addr, 16);
|
|
|
|
version = other.version;
|
|
|
|
}
|
|
|
|
|
2018-08-31 12:46:54 +00:00
|
|
|
~ExitInfo();
|
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
bool
|
2018-11-05 11:27:12 +00:00
|
|
|
BEncode(llarp_buffer_t *buf) const override;
|
2018-08-30 18:48:43 +00:00
|
|
|
|
|
|
|
bool
|
2018-11-05 11:27:12 +00:00
|
|
|
DecodeKey(llarp_buffer_t k, llarp_buffer_t *buf) override;
|
2018-08-30 18:48:43 +00:00
|
|
|
|
2018-08-31 13:51:24 +00:00
|
|
|
ExitInfo &
|
|
|
|
operator=(const ExitInfo &other);
|
|
|
|
|
2018-08-30 18:48:43 +00:00
|
|
|
friend std::ostream &
|
|
|
|
operator<<(std::ostream &out, const ExitInfo &xi)
|
|
|
|
{
|
|
|
|
char tmp[128] = {0};
|
2018-11-09 14:48:43 +00:00
|
|
|
if(inet_ntop(AF_INET6, (void *)&xi.address, tmp, sizeof(tmp)))
|
2018-08-30 18:48:43 +00:00
|
|
|
out << std::string(tmp);
|
|
|
|
else
|
|
|
|
return out;
|
|
|
|
out << std::string("/");
|
2018-11-08 12:31:50 +00:00
|
|
|
#if defined(ANDROID) || defined(RPI)
|
2018-11-21 21:52:35 +00:00
|
|
|
snprintf(tmp, sizeof(tmp), "%zu",
|
2018-11-06 14:06:09 +00:00
|
|
|
llarp::bits::count_array_bits(xi.netmask.s6_addr));
|
|
|
|
return out << tmp;
|
|
|
|
#else
|
2018-08-30 18:48:43 +00:00
|
|
|
return out << std::to_string(
|
|
|
|
llarp::bits::count_array_bits(xi.netmask.s6_addr));
|
2018-11-06 14:06:09 +00:00
|
|
|
#endif
|
2018-08-30 18:48:43 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
} // namespace llarp
|
|
|
|
|
|
|
|
#endif
|