MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / GetGroup

Method GetGroup

src/netaddress.cpp:311–382  ·  view source on GitHub ↗

get canonical identifier of an address' group no two connections will be attempted to addresses with the same group

Source from the content-addressed store, hash-verified

309// get canonical identifier of an address' group
310// no two connections will be attempted to addresses with the same group
311std::vector<unsigned char> CNetAddr::GetGroup() const
312{
313 std::vector<unsigned char> vchRet;
314 int nClass = NET_IPV6;
315 int nStartByte = 0;
316 int nBits = 16;
317
318 // all local addresses belong to the same group
319 if (IsLocal())
320 {
321 nClass = 255;
322 nBits = 0;
323 }
324 // all internal-usage addresses get their own group
325 if (IsInternal())
326 {
327 nClass = NET_INTERNAL;
328 nStartByte = sizeof(g_internal_prefix);
329 nBits = (sizeof(ip) - sizeof(g_internal_prefix)) * 8;
330 }
331 // all other unroutable addresses belong to the same group
332 else if (!IsRoutable())
333 {
334 nClass = NET_UNROUTABLE;
335 nBits = 0;
336 }
337 // for IPv4 addresses, '1' + the 16 higher-order bits of the IP
338 // includes mapped IPv4, SIIT translated IPv4, and the well-known prefix
339 else if (IsIPv4() || IsRFC6145() || IsRFC6052())
340 {
341 nClass = NET_IPV4;
342 nStartByte = 12;
343 }
344 // for 6to4 tunnelled addresses, use the encapsulated IPv4 address
345 else if (IsRFC3964())
346 {
347 nClass = NET_IPV4;
348 nStartByte = 2;
349 }
350 // for Teredo-tunnelled IPv6 addresses, use the encapsulated IPv4 address
351 else if (IsRFC4380())
352 {
353 vchRet.push_back(NET_IPV4);
354 vchRet.push_back(GetByte(3) ^ 0xFF);
355 vchRet.push_back(GetByte(2) ^ 0xFF);
356 return vchRet;
357 }
358 else if (IsTor())
359 {
360 nClass = NET_ONION;
361 nStartByte = 6;
362 nBits = 4;
363 }
364 // for he.net, use /36 groups
365 else if (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x04 && GetByte(12) == 0x70)
366 nBits = 36;
367 // for the rest of the IPv6 network, use /32 groups
368 else

Callers 4

GetNewBucketMethod · 0.80
ThreadOpenConnectionsMethod · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80

Calls 2

IsLocalFunction · 0.85
push_backMethod · 0.45

Tested by 1

BOOST_AUTO_TEST_CASEFunction · 0.64