fix ignored message id key for NN>3, fix longer message key check (fixes #1436), add log message on exceeded max length

This commit is contained in:
John
2025-01-12 10:11:04 +01:00
parent 0445e4412e
commit 34552eab61
3 changed files with 17 additions and 14 deletions
+4 -1
View File
@@ -408,7 +408,10 @@ int main(int argc, char* argv[], char* envp[]) {
fout.close();
}
}
if (overallResult == RESULT_OK && s_messageMap->getMaxIdLength() > 7) {
logNotice(lf_main, "max message ID length exceeded");
overallResult = RESULT_CONTINUE;
}
cleanup();
return overallResult == RESULT_OK ? EXIT_SUCCESS : EXIT_FAILURE;
}
+9 -6
View File
@@ -180,7 +180,7 @@ uint64_t Message::createKey(const vector<symbol_t>& id, bool isWrite, bool isPas
int exp = 5;
for (const auto it : id) {
key ^= (uint64_t)it << (8 * exp--);
if (exp == 0) {
if (exp < 0) {
exp = 3;
}
}
@@ -206,7 +206,7 @@ uint64_t Message::createKey(const MasterSymbolString& master, size_t maxIdLength
int exp = 3;
for (size_t i = 0; i < idLength; i++) {
key ^= (uint64_t)master.dataAt(i) << (8 * exp--);
if (exp == 0) {
if (exp < 0) {
exp = 3;
}
}
@@ -2712,13 +2712,12 @@ Message* MessageMap::find(const MasterSymbolString& master, bool anyDestination,
if (anyDestination && master.size() >= 5 && master[4] == 0 && master[2] == 0x07 && master[3] == 0x04) {
return m_scanMessage;
}
uint64_t baseKey = Message::createKey(master,
anyDestination || master[1] != BROADCAST ? m_maxIdLength : m_maxBroadcastIdLength, anyDestination);
size_t maxIdLength = anyDestination || master[1] != BROADCAST ? m_maxIdLength : m_maxBroadcastIdLength;
uint64_t baseKey = Message::createKey(master, maxIdLength, anyDestination);
if (baseKey == INVALID_KEY) {
return nullptr;
}
bool isWriteDest = isMaster(master[1]) || master[1] == BROADCAST;
size_t maxIdLength = Message::getKeyLength(baseKey);
for (size_t idLength = maxIdLength; true; idLength--) {
uint64_t key = baseKey;
if (idLength == maxIdLength) {
@@ -2728,7 +2727,7 @@ Message* MessageMap::find(const MasterSymbolString& master, bool anyDestination,
int exp = 3;
for (size_t i = 0; i < idLength; i++) {
key ^= (uint64_t)master.dataAt(i) << (8 * exp--);
if (exp == 0) {
if (exp < 0) {
exp = 3;
}
}
@@ -2907,6 +2906,10 @@ void MessageMap::dump(bool withConditions, OutputFormat outputFormat, ostream* o
*output << (m_addAll ? "[" : "{");
} else {
Message::dumpHeader(nullptr, output);
if (m_addAll) {
*output << endl << "# max ID length: " << static_cast<unsigned>(m_maxIdLength)
<< " (broadcast only: " << static_cast<unsigned>(m_maxBroadcastIdLength) << ")";
}
}
if (!(outputFormat & OF_SHORT)) {
*output << endl;
+4 -7
View File
@@ -158,13 +158,6 @@ class Message : public AttributedItem {
*/
static uint64_t createKey(symbol_t pb, symbol_t sb, bool broadcast);
/**
* Get the length field from the key.
* @param key the key.
* @return the length field from the key.
*/
static size_t getKeyLength(uint64_t key) { return (size_t)(key >> (8 * 7 + 5)); }
/**
* Parse an ID part from the input @a string.
* @param input the input @a string, hex digits optionally separated by space.
@@ -1651,6 +1644,10 @@ class MessageMap : public MappedFileReader {
*/
void dump(bool withConditions, OutputFormat outputFormat, ostream* output) const;
/**
* @return the maximum ID length used by any of the known @a Message instances.
*/
size_t getMaxIdLength() const { return m_maxIdLength; }
private:
/** empty vector for @a getLoadedFiles(). */