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

Method GetGroup

src/netbase.cpp:924–989  ·  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

922// get canonical identifier of an address' group
923// no two connections will be attempted to addresses with the same group
924std::vector<unsigned char> CNetAddr::GetGroup() const
925{
926 std::vector<unsigned char> vchRet;
927 int nClass = NET_IPV6;
928 int nStartByte = 0;
929 int nBits = 16;
930
931 // all local addresses belong to the same group
932 if (IsLocal())
933 {
934 nClass = 255;
935 nBits = 0;
936 }
937
938 // all unroutable addresses belong to the same group
939 if (!IsRoutable())
940 {
941 nClass = NET_UNROUTABLE;
942 nBits = 0;
943 }
944 // for IPv4 addresses, '1' + the 16 higher-order bits of the IP
945 // includes mapped IPv4, SIIT translated IPv4, and the well-known prefix
946 else if (IsIPv4() || IsRFC6145() || IsRFC6052())
947 {
948 nClass = NET_IPV4;
949 nStartByte = 12;
950 }
951 // for 6to4 tunnelled addresses, use the encapsulated IPv4 address
952 else if (IsRFC3964())
953 {
954 nClass = NET_IPV4;
955 nStartByte = 2;
956 }
957 // for Teredo-tunnelled IPv6 addresses, use the encapsulated IPv4 address
958 else if (IsRFC4380())
959 {
960 vchRet.push_back(NET_IPV4);
961 vchRet.push_back(GetByte(3) ^ 0xFF);
962 vchRet.push_back(GetByte(2) ^ 0xFF);
963 return vchRet;
964 }
965 else if (IsTor())
966 {
967 nClass = NET_TOR;
968 nStartByte = 6;
969 nBits = 4;
970 }
971 // for he.net, use /36 groups
972 else if (GetByte(15) == 0x20 && GetByte(14) == 0x01 && GetByte(13) == 0x04 && GetByte(12) == 0x70)
973 nBits = 36;
974 // for the rest of the IPv6 network, use /32 groups
975 else
976 nBits = 32;
977
978 vchRet.push_back(nClass);
979 while (nBits >= 8)
980 {
981 vchRet.push_back(GetByte(15 - nStartByte));

Callers 3

GetNewBucketMethod · 0.80
BOOST_FOREACHFunction · 0.80
ThreadOpenConnectionsFunction · 0.80

Calls 2

IsLocalFunction · 0.85
push_backMethod · 0.45

Tested by

no test coverage detected