2018-08-30 18:48:43 +00:00
|
|
|
#ifndef LLARP_XI_HPP
|
|
|
|
#define LLARP_XI_HPP
|
2018-12-12 02:52:51 +00:00
|
|
|
|
2019-01-13 16:30:07 +00:00
|
|
|
#include <crypto/types.hpp>
|
2019-01-11 01:42:02 +00:00
|
|
|
#include <net/net.hpp>
|
2019-01-10 19:41:51 +00:00
|
|
|
#include <util/bencode.hpp>
|
2018-12-12 02:52:51 +00:00
|
|
|
|
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
|
|
|
|
{
|
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;
|
|
|
|
|
2019-02-05 00:41:33 +00:00
|
|
|
ExitInfo(const PubKey &pk, const nuint32_t &ipv4_exit)
|
|
|
|
: IBEncodeMessage(), 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);
|
|
|
|
}
|
|
|
|
|
2018-09-06 11:46:19 +00:00
|
|
|
ExitInfo() : IBEncodeMessage()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-02-05 00:41:33 +00:00
|
|
|
ExitInfo(const ExitInfo &other)
|
|
|
|
: IBEncodeMessage(other.version), pubkey(other.pubkey)
|
2018-09-06 11:46:19 +00:00
|
|
|
{
|
|
|
|
memcpy(address.s6_addr, other.address.s6_addr, 16);
|
|
|
|
memcpy(netmask.s6_addr, other.netmask.s6_addr, 16);
|
|
|
|
}
|
|
|
|
|
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
|
2019-02-01 01:58:06 +00:00
|
|
|
DecodeKey(const 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);
|
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
|