mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-19 14:45:08 +01:00
p2p, refactor: extract OnionToString() from CNetAddr::ToStringIp()
This commit is contained in:
parent
5f9d3c09b4
commit
8be56f0f8e
@ -594,22 +594,26 @@ static std::string IPv6ToString(Span<const uint8_t> a, uint32_t scope_id)
|
||||
return r;
|
||||
}
|
||||
|
||||
static std::string OnionToString(const Span<const uint8_t>& addr)
|
||||
{
|
||||
uint8_t checksum[torv3::CHECKSUM_LEN];
|
||||
torv3::Checksum(addr, checksum);
|
||||
// TORv3 onion_address = base32(PUBKEY | CHECKSUM | VERSION) + ".onion"
|
||||
prevector<torv3::TOTAL_LEN, uint8_t> address{addr.begin(), addr.end()};
|
||||
address.insert(address.end(), checksum, checksum + torv3::CHECKSUM_LEN);
|
||||
address.insert(address.end(), torv3::VERSION, torv3::VERSION + sizeof(torv3::VERSION));
|
||||
return EncodeBase32(address) + ".onion";
|
||||
}
|
||||
|
||||
std::string CNetAddr::ToStringIP() const
|
||||
{
|
||||
switch (m_net) {
|
||||
case NET_IPV4:
|
||||
return IPv4ToString(m_addr);
|
||||
case NET_IPV6: {
|
||||
case NET_IPV6:
|
||||
return IPv6ToString(m_addr, m_scope_id);
|
||||
}
|
||||
case NET_ONION:
|
||||
uint8_t checksum[torv3::CHECKSUM_LEN];
|
||||
torv3::Checksum(m_addr, checksum);
|
||||
// TORv3 onion_address = base32(PUBKEY | CHECKSUM | VERSION) + ".onion"
|
||||
prevector<torv3::TOTAL_LEN, uint8_t> address{m_addr.begin(), m_addr.end()};
|
||||
address.insert(address.end(), checksum, checksum + torv3::CHECKSUM_LEN);
|
||||
address.insert(address.end(), torv3::VERSION, torv3::VERSION + sizeof(torv3::VERSION));
|
||||
return EncodeBase32(address) + ".onion";
|
||||
return OnionToString(m_addr);
|
||||
case NET_I2P:
|
||||
return EncodeBase32(m_addr, false /* don't pad with = */) + ".b32.i2p";
|
||||
case NET_CJDNS:
|
||||
|
Loading…
Reference in New Issue
Block a user