2021-03-10 15:11:42 +00:00
|
|
|
#include "address.hpp"
|
2021-03-12 13:50:21 +00:00
|
|
|
#include <cstring>
|
2021-03-10 15:11:42 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace llarp::quic
|
|
|
|
{
|
|
|
|
using namespace std::literals;
|
|
|
|
|
2021-03-12 13:50:21 +00:00
|
|
|
Address::Address(service::ConvoTag tag) : saddr{tag.ToV6()}
|
|
|
|
{}
|
2021-03-10 15:11:42 +00:00
|
|
|
|
|
|
|
Address&
|
2021-03-12 13:50:21 +00:00
|
|
|
Address::operator=(const Address& other)
|
2021-03-10 15:11:42 +00:00
|
|
|
{
|
2021-03-12 13:50:21 +00:00
|
|
|
std::memmove(&saddr, &other.saddr, sizeof(saddr));
|
|
|
|
a.addrlen = other.a.addrlen;
|
2021-03-10 15:11:42 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2021-03-12 13:50:21 +00:00
|
|
|
service::ConvoTag
|
|
|
|
Address::Tag() const
|
|
|
|
{
|
|
|
|
service::ConvoTag tag{};
|
|
|
|
tag.FromV6(saddr);
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
|
2021-03-10 15:11:42 +00:00
|
|
|
std::string
|
|
|
|
Address::to_string() const
|
|
|
|
{
|
2021-03-12 13:50:21 +00:00
|
|
|
if (a.addrlen != sizeof(sockaddr_in6))
|
2021-03-10 15:11:42 +00:00
|
|
|
return "(unknown-addr)";
|
2021-03-12 13:50:21 +00:00
|
|
|
char buf[INET6_ADDRSTRLEN] = {0};
|
|
|
|
inet_ntop(AF_INET6, &saddr.sin6_addr, buf, INET6_ADDRSTRLEN);
|
|
|
|
return buf;
|
2021-03-10 15:11:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::ostream&
|
|
|
|
operator<<(std::ostream& o, const Address& a)
|
|
|
|
{
|
|
|
|
return o << a.to_string();
|
|
|
|
}
|
|
|
|
std::ostream&
|
|
|
|
operator<<(std::ostream& o, const Path& p)
|
|
|
|
{
|
|
|
|
return o << p.local << "<-" << p.remote;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace llarp::quic
|