MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / SetI2P

Method SetI2P

src/netaddress.cpp:263–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

261}
262
263bool 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
290CNetAddr::CNetAddr(const struct in_addr& ipv4Addr)
291{

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected