Skip to content

Commit 3e3d0f8

Browse files
committed
[DHT] Change clear record to use zero chunks and correct null format type
1 parent c1624f1 commit 3e3d0f8

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/dht/dataheader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class CRecordHeader
122122
return *this;
123123
}
124124

125-
inline bool IsNull() const { return (nFormat == 7); }
125+
inline bool IsNull() const { return (nFormat == DHT::DataFormat::Null); }
126126
void Serialize(std::vector<unsigned char>& vchData);
127127
bool UnserializeFromData(const std::vector<unsigned char>& vchData);
128128

src/dht/datarecord.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,12 @@ bool CDataRecord::InitPut()
135135

136136
bool CDataRecord::InitClear()
137137
{
138-
std::string strNullValue = "null";
139-
uint16_t nPlacement = 1;
140-
std::string strSalt = strOperationCode + ":" + std::to_string(nPlacement);
141-
CDataChunk chunk(0, nPlacement, strSalt, strNullValue);
142-
vChunks.push_back(chunk);
143-
144138
dataHeader.nVersion = 0; // unencrypted
145-
dataHeader.nTimeStamp = 0;
146139
dataHeader.nExpireTime = 0;
147-
dataHeader.nChunks = 1;
148-
dataHeader.nChunkSize = 4;
149-
dataHeader.nDataSize = 4;
150-
dataHeader.nFormat = DHT::DataFormat::String;
140+
dataHeader.nChunks = 0;
141+
dataHeader.nChunkSize = 0;
142+
dataHeader.nDataSize = 0;
143+
dataHeader.nFormat = DHT::DataFormat::Null;
151144
dataHeader.nIndexLocation = 0;
152145
dataHeader.nTimeStamp = GetTime();
153146
return true;

src/dht/session.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,7 @@ bool CHashTableSession::SubmitGetRecord(const std::array<char, 32>& public_key,
687687
// if header matches previous entry, only get missing chunks.
688688
if (strHeaderHex == "")
689689
return false; // Header failed, so don't try to get the rest of the record.
690+
690691
nHeaderSeq = iSequence;
691692
header.LoadHex(strHeaderHex);
692693
if (!header.IsNull() && header.nChunks > 0) {
@@ -711,6 +712,12 @@ bool CHashTableSession::SubmitGetRecord(const std::array<char, 32>& public_key,
711712
nGetBytes += header.nDataSize;
712713
record = getRecord;
713714
return true;
715+
} else if (header.IsNull()) {
716+
std::vector<CDataChunk> vChunks;
717+
CDataRecord getRecord(strOperationType, 0, header, vChunks, Array32ToVector(private_seed));
718+
record = getRecord;
719+
nGetBytes += header.nDataSize;
720+
return true;
714721
}
715722
return false;
716723
}

0 commit comments

Comments
 (0)