| 941 | } |
| 942 | |
| 943 | void NetDb::HandleDatabaseLookupMsg (std::shared_ptr<const I2NPMessage> msg) |
| 944 | { |
| 945 | const uint8_t * buf = msg->GetPayload (); |
| 946 | IdentHash ident (buf); |
| 947 | if (ident.IsZero ()) |
| 948 | { |
| 949 | LogPrint (eLogError, "NetDb: DatabaseLookup for zero ident. Ignored"); |
| 950 | return; |
| 951 | } |
| 952 | std::string key; |
| 953 | if (CheckLogLevel (eLogInfo)) |
| 954 | key = i2p::data::ByteStreamToBase64 (buf, 32); |
| 955 | |
| 956 | IdentHash replyIdent(buf + 32); |
| 957 | uint8_t flag = buf[64]; |
| 958 | |
| 959 | LogPrint (eLogDebug, "NetDb: DatabaseLookup for ", key, " received flags=", (int)flag); |
| 960 | uint8_t lookupType = flag & DATABASE_LOOKUP_TYPE_FLAGS_MASK; |
| 961 | const uint8_t * excluded = buf + 65; |
| 962 | uint32_t replyTunnelID = 0; |
| 963 | if (flag & DATABASE_LOOKUP_DELIVERY_FLAG) //reply to tunnel |
| 964 | { |
| 965 | replyTunnelID = bufbe32toh (excluded); |
| 966 | excluded += 4; |
| 967 | } |
| 968 | uint16_t numExcluded = bufbe16toh (excluded); |
| 969 | excluded += 2; |
| 970 | if (numExcluded > 512 || (excluded - buf) + numExcluded*32 > (int)msg->GetPayloadLength ()) |
| 971 | { |
| 972 | LogPrint (eLogWarning, "NetDb: Number of excluded peers", numExcluded, " is too much"); |
| 973 | return; |
| 974 | } |
| 975 | |
| 976 | std::shared_ptr<I2NPMessage> replyMsg; |
| 977 | if (lookupType == DATABASE_LOOKUP_TYPE_EXPLORATORY_LOOKUP) |
| 978 | { |
| 979 | if (!context.IsFloodfill ()) |
| 980 | { |
| 981 | LogPrint (eLogWarning, "NetDb: Exploratory lookup to non-floodfill dropped"); |
| 982 | return; |
| 983 | } |
| 984 | LogPrint (eLogInfo, "NetDb: Exploratory close to ", key, " ", numExcluded, " excluded"); |
| 985 | std::unordered_set<IdentHash> excludedRouters; |
| 986 | const uint8_t * excluded_ident = excluded; |
| 987 | for (int i = 0; i < numExcluded; i++) |
| 988 | { |
| 989 | excludedRouters.insert (excluded_ident); |
| 990 | excluded_ident += 32; |
| 991 | } |
| 992 | replyMsg = CreateDatabaseSearchReply (ident, GetExploratoryNonFloodfill (ident, |
| 993 | NETDB_MAX_NUM_SEARCH_REPLY_PEER_HASHES, excludedRouters)); |
| 994 | } |
| 995 | else |
| 996 | { |
| 997 | if (lookupType == DATABASE_LOOKUP_TYPE_ROUTERINFO_LOOKUP || |
| 998 | lookupType == DATABASE_LOOKUP_TYPE_NORMAL_LOOKUP) |
| 999 | { |
| 1000 | // try to find router |
nothing calls this directly
no test coverage detected