pw.getHeader()->rcode == RCode::ServFail ? SyncRes::s_packetcacheservfailttl :
min(minTTL,SyncRes::s_packetcachettl),
dq.validationState,
- pbDataForCache);
+ std::move(pbDataForCache));
}
- // else cerr<<"Not putting in packet cache: "<<sr.wasVariable()<<endl;
}
else {
bool hadError = sendResponseOverTCP(dc, packet);
std::unique_ptr<pdns::ProtoZero::Message> pbMessage;
if (pbData) {
// We take the inmutable string form the cache an are appending a few values
- pbMessage = make_unique<pdns::ProtoZero::Message>(pbData->d_message, pbData->d_response, 128, 128); // The extra bytes we are going to add
+ pbMessage = make_unique<pdns::ProtoZero::Message>(pbData->d_message, pbData->d_response, 64, 10); // The extra bytes we are going to add
} else {
- pbMessage = make_unique<pdns::ProtoZero::Message>(128, 128);
+ pbMessage = make_unique<pdns::ProtoZero::Message>(64, 10);
pbMessage->setType(2); // Response
pbMessage->setServerIdentity(SyncRes::s_serverID);
}
+ // In response part
+ if (g_useKernelTimestamp && tv.tv_sec) {
+ pbMessage->setQueryTime(tv.tv_sec, tv.tv_usec);
+ }
+ else {
+ pbMessage->setQueryTime(g_now.tv_sec, g_now.tv_usec);
+ }
+ // In message part
Netmask requestorNM(source, source.sin4.sin_family == AF_INET ? luaconfsLocal->protobufMaskV4 : luaconfsLocal->protobufMaskV6);
ComboAddress requestor = requestorNM.getMaskedNetwork();
pbMessage->setMessageIdentity(uniqueId);
pbMessage->setId(dh->id);
pbMessage->setTime();
- if (g_useKernelTimestamp && tv.tv_sec) {
- pbMessage->setQueryTime(tv.tv_sec, tv.tv_usec);
- }
- else {
- pbMessage->setQueryTime(g_now.tv_sec, g_now.tv_usec);
- }
pbMessage->setEDNSSubnet(ednssubnet.source, ednssubnet.source.isIPv4() ? luaconfsLocal->protobufMaskV4 : luaconfsLocal->protobufMaskV6);
pbMessage->setRequestorId(requestorId);
pbMessage->setDeviceId(deviceId);
Message(const std::string& buf1, const std::string& buf2, std::string::size_type sz1, std::string::size_type sz2) :
d_msgbuf{buf1}, d_rspbuf{buf2}, d_message{d_msgbuf}, d_response{d_rspbuf}
{
- // We expect to grow the buffers
+ // We expect to grow the buffers, in the end the d_message will contains the (grown) d_response
// This is extra space in addition to what's already there
// Different from what string.reserve() does
- d_message.reserve(sz1);
+ d_message.reserve(sz1 + d_rspbuf.length() + sz2);
d_response.reserve(sz2);
}
const std::string& getMessageBuf() const
}
-void RecursorPacketCache::insertResponsePacket(unsigned int tag, uint32_t qhash, std::string&& query, const DNSName& qname, uint16_t qtype, uint16_t qclass, std::string&& responsePacket, time_t now, uint32_t ttl, const vState& valState, const OptPBData& pbdata)
+void RecursorPacketCache::insertResponsePacket(unsigned int tag, uint32_t qhash, std::string&& query, const DNSName& qname, uint16_t qtype, uint16_t qclass, std::string&& responsePacket, time_t now, uint32_t ttl, const vState& valState, OptPBData&& pbdata)
{
auto& idx = d_packetCache.get<HashTag>();
auto range = idx.equal_range(tie(tag,qhash));
iter->d_vstate = valState;
#ifdef HAVE_PROTOBUF
if (pbdata) {
- iter->d_pbdata = *pbdata;
+ iter->d_pbdata = std::move(*pbdata);
}
#endif
e.d_vstate = valState;
#ifdef HAVE_PROTOBUF
if (pbdata) {
- e.d_pbdata = *pbdata;
+ e.d_pbdata = std::move(*pbdata);
}
#endif
d_packetCache.insert(e);
bool getResponsePacket(unsigned int tag, const std::string& queryPacket, const DNSName& qname, uint16_t qtype, uint16_t qclass, time_t now, std::string* responsePacket, uint32_t* age, vState* valState, uint32_t* qhash, OptPBData* pbdata);
bool getResponsePacket(unsigned int tag, const std::string& queryPacket, DNSName& qname, uint16_t *qtype, uint16_t* qclass, time_t now, std::string* responsePacket, uint32_t* age, vState* valState, uint32_t* qhash, OptPBData* pbdata);
- void insertResponsePacket(unsigned int tag, uint32_t qhash, std::string&& query, const DNSName& qname, uint16_t qtype, uint16_t qclass, std::string&& responsePacket, time_t now, uint32_t ttl, const vState& valState, const OptPBData& pbdata);
+ void insertResponsePacket(unsigned int tag, uint32_t qhash, std::string&& query, const DNSName& qname, uint16_t qtype, uint16_t qclass, std::string&& responsePacket, time_t now, uint32_t ttl, const vState& valState, OptPBData&& pbdata);
void doPruneTo(size_t maxSize=250000);
uint64_t doDump(int fd);
int doWipePacketCache(const DNSName& name, uint16_t qtype=0xffff, bool subtree=false);