| 1070 | } |
| 1071 | |
| 1072 | static void RelayAddress(const CAddress& addr, bool fReachable, CConnman* connman) |
| 1073 | { |
| 1074 | unsigned int nRelayNodes = fReachable ? 2 : 1; // limited relaying of addresses outside our network(s) |
| 1075 | |
| 1076 | // Relay to a limited number of other nodes |
| 1077 | // Use deterministic randomness to send to the same nodes for 24 hours |
| 1078 | // at a time so the addrKnowns of the chosen nodes prevent repeats |
| 1079 | uint64_t hashAddr = addr.GetHash(); |
| 1080 | const CSipHasher hasher = connman->GetDeterministicRandomizer(RANDOMIZER_ID_ADDRESS_RELAY).Write(hashAddr << 32).Write((GetTime() + hashAddr) / (24*60*60)); |
| 1081 | FastRandomContext insecure_rand; |
| 1082 | |
| 1083 | std::array<std::pair<uint64_t, CNode*>,2> best{{{0, nullptr}, {0, nullptr}}}; |
| 1084 | assert(nRelayNodes <= best.size()); |
| 1085 | |
| 1086 | auto sortfunc = [&best, &hasher, nRelayNodes](CNode* pnode) { |
| 1087 | if (pnode->nVersion >= CADDR_TIME_VERSION) { |
| 1088 | uint64_t hashKey = CSipHasher(hasher).Write(pnode->GetId()).Finalize(); |
| 1089 | for (unsigned int i = 0; i < nRelayNodes; i++) { |
| 1090 | if (hashKey > best[i].first) { |
| 1091 | std::copy(best.begin() + i, best.begin() + nRelayNodes - 1, best.begin() + i + 1); |
| 1092 | best[i] = std::make_pair(hashKey, pnode); |
| 1093 | break; |
| 1094 | } |
| 1095 | } |
| 1096 | } |
| 1097 | }; |
| 1098 | |
| 1099 | auto pushfunc = [&addr, &best, nRelayNodes, &insecure_rand] { |
| 1100 | for (unsigned int i = 0; i < nRelayNodes && best[i].first != 0; i++) { |
| 1101 | best[i].second->PushAddress(addr, insecure_rand); |
| 1102 | } |
| 1103 | }; |
| 1104 | |
| 1105 | connman->ForEachNodeThen(std::move(sortfunc), std::move(pushfunc)); |
| 1106 | } |
| 1107 | |
| 1108 | void static ProcessGetBlockData(CNode* pfrom, const CChainParams& chainparams, const CInv& inv, CConnman* connman) |
| 1109 | { |
no test coverage detected