123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #ifndef _DNS_DNSTLSQUERYMAP_H
- #define _DNS_DNSTLSQUERYMAP_H
- #include <future>
- #include <map>
- #include <mutex>
- #include <vector>
- #include <android-base/thread_annotations.h>
- #include <netdutils/Slice.h>
- #include "DnsTlsServer.h"
- namespace android {
- namespace net {
- class DnsTlsQueryMap {
- public:
- struct Query {
-
- uint16_t newId;
-
- const netdutils::Slice query;
- };
- typedef DnsTlsServer::Response Response;
- typedef DnsTlsServer::Result Result;
- struct QueryFuture {
- QueryFuture(Query query, std::future<Result> result)
- : query(query), result(std::move(result)) {}
- Query query;
-
- std::future<Result> result;
- };
-
-
- std::unique_ptr<QueryFuture> recordQuery(const netdutils::Slice query);
-
-
- void onResponse(std::vector<uint8_t> response);
-
- void clear();
-
- std::vector<Query> getAll();
-
-
- void markTried(uint16_t newId);
- void cleanup();
-
- bool empty();
- private:
- std::mutex mLock;
- struct QueryPromise {
- QueryPromise(Query query) : query(query) {}
- Query query;
-
- int tries = 0;
-
-
- std::promise<Result> result;
- };
-
- static constexpr int kMaxTries = 3;
-
- std::map<uint16_t, QueryPromise> mQueries GUARDED_BY(mLock);
-
- int32_t getFreeId() REQUIRES(mLock);
-
- static void expire(QueryPromise* _Nonnull p);
- };
- }
- }
- #endif
|