| 261 | } |
| 262 | |
| 263 | bool CNetAddr::SetI2P(std::string_view addr) |
| 264 | { |
| 265 | // I2P addresses that we support consist of 52 base32 characters + ".b32.i2p". |
| 266 | static constexpr size_t b32_len{52}; |
| 267 | static const char* suffix{".b32.i2p"}; |
| 268 | static constexpr size_t suffix_len{8}; |
| 269 | |
| 270 | if (addr.size() != b32_len + suffix_len || ToLower(addr.substr(b32_len)) != suffix) { |
| 271 | return false; |
| 272 | } |
| 273 | |
| 274 | // Remove the ".b32.i2p" suffix and pad to a multiple of 8 chars, so DecodeBase32() |
| 275 | // can decode it. |
| 276 | const std::string b32_padded{tfm::format("%s====", addr.substr(0, b32_len))}; |
| 277 | |
| 278 | auto address_bytes = DecodeBase32(b32_padded); |
| 279 | |
| 280 | if (!address_bytes || address_bytes->size() != ADDR_I2P_SIZE) { |
| 281 | return false; |
| 282 | } |
| 283 | |
| 284 | m_net = NET_I2P; |
| 285 | m_addr.assign(address_bytes->begin(), address_bytes->end()); |
| 286 | |
| 287 | return true; |
| 288 | } |
| 289 | |
| 290 | CNetAddr::CNetAddr(const struct in_addr& ipv4Addr) |
| 291 | { |