MCPcopy Create free account
hub / github.com/ElementsProject/elements / SetI2P

Method SetI2P

src/netaddress.cpp:269–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267}
268
269bool 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
297CNetAddr::CNetAddr(const struct in_addr& ipv4Addr)
298{

Callers

nothing calls this directly

Calls 6

DecodeBase32Function · 0.85
ToLowerFunction · 0.50
sizeMethod · 0.45
assignMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected