Skip to content

Commit

Permalink
fix: discard WeekDataMessage with duplicate hash
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Jun 7, 2022
1 parent 44d5f53 commit 74d48a4
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions source/ListSync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,22 @@ end
local function handleWeekDataMessage(message, sender, distribution, stateManager, listSync)
if not listSync.authorizationHandler(sender) then
listSync.logger:Warning("Dropping week data message from unauthorized sender %s", sender)
else
local count = 0
for _, v in ipairs(message.entries) do
local entry = stateManager:createLogEntryFromList(v)
stateManager:queueRemoteEvent(entry)
count = count + 1
end
listSync.logger:Info("Enqueued %d events for week %s from remote received from %s via %s", count, message.week, sender, distribution)
return
end

if (message.hash == weekHash(listSync, message.week)) then
listSync.logger:Warning("Dropping week data message from sender %s, we have the same hash", sender)
return
end

local count = 0
for _, v in ipairs(message.entries) do
local entry = stateManager:createLogEntryFromList(v)
stateManager:queueRemoteEvent(entry)
count = count + 1
end
listSync.logger:Info("Enqueued %d events for week %s from remote received from %s via %s", count, message.week, sender, distribution)

end

local function handleBulkDataMessage(message, sender, distribution, stateManager, listSync)
Expand Down

0 comments on commit 74d48a4

Please sign in to comment.