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