diff options
author | Jon Atack <jon@atack.com> | 2021-05-30 12:19:10 +0200 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2021-06-03 13:36:50 +0200 |
commit | 8be56f0f8ecc54744d572e5678a3089665587b98 (patch) | |
tree | b0162ba2288080125439f6ec59073b5d365e993c | |
parent | 5f9d3c09b4c9cd026cdc7c3a81f91632280917b7 (diff) | |
download | bitcoin-8be56f0f8ecc54744d572e5678a3089665587b98.tar.xz |
p2p, refactor: extract OnionToString() from CNetAddr::ToStringIp()
-rw-r--r-- | src/netaddress.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/src/netaddress.cpp b/src/netaddress.cpp index 187507fe1f..0ae8dd0698 100644 --- a/src/netaddress.cpp +++ b/src/netaddress.cpp @@ -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: |