Browse Source

add channel sync debug logging

dev
Jørgen Lien Sellæg 4 months ago
parent
commit
1ff65947fe
  1. 53
      TradeSkillMaster_AuctionDB/Modules/ChannelSync.lua

53
TradeSkillMaster_AuctionDB/Modules/ChannelSync.lua

@ -33,6 +33,13 @@ local strbyte = string.byte
local libS = LibStub:GetLibrary("AceSerializer-3.0") local libS = LibStub:GetLibrary("AceSerializer-3.0")
local libD = LibStub("LibDeflate", true) local libD = LibStub("LibDeflate", true)
local warnedNoDeflate local warnedNoDeflate
local debugEnabled = true
local function DebugPrint(msg)
if debugEnabled then
TSM:Print("ChannelSync: " .. msg)
end
end
local function CanEncode() local function CanEncode()
if libD then return true end if libD then return true end
@ -89,19 +96,35 @@ end
local function EncodePayload(payload) local function EncodePayload(payload)
if not CanEncode() then return end if not CanEncode() then return end
local serialized = libS:Serialize(payload) local serialized = libS:Serialize(payload)
if not serialized then
DebugPrint("Serialize failed.")
return
end
local compressed = libD:CompressDeflate(serialized, { level = 9 }) local compressed = libD:CompressDeflate(serialized, { level = 9 })
if not compressed then return end if not compressed then
DebugPrint("CompressDeflate failed.")
return
end
return libD:EncodeForPrint(compressed) return libD:EncodeForPrint(compressed)
end end
local function DecodePayload(encoded) local function DecodePayload(encoded)
if not CanEncode() then return end if not CanEncode() then return end
local decoded = libD:DecodeForPrint(encoded) local decoded = libD:DecodeForPrint(encoded)
if not decoded then return end if not decoded then
DebugPrint("DecodeForPrint failed.")
return
end
local decompressed = libD:DecompressDeflate(decoded) local decompressed = libD:DecompressDeflate(decoded)
if not decompressed then return end if not decompressed then
DebugPrint("DecompressDeflate failed.")
return
end
local ok, payload = libS:Deserialize(decompressed) local ok, payload = libS:Deserialize(decompressed)
if not ok then return end if not ok then
DebugPrint("Deserialize failed.")
return
end
return payload return payload
end end
@ -123,10 +146,10 @@ function ChannelSync:BroadcastScanData(scanType, items)
local function QueueEncoded(encoded) local function QueueEncoded(encoded)
local hash = HashString(encoded) local hash = HashString(encoded)
if hash == private.lastBroadcastHash then return end if hash == private.lastBroadcastHash then return end
private.lastBroadcastHash = hash private.lastBroadcastHash = hash
local total = ceil(#encoded / CHUNK_SIZE) local total = ceil(#encoded / CHUNK_SIZE)
if total > MAX_TOTAL_CHUNKS then return false end if total > MAX_TOTAL_CHUNKS then return false end
tinsert(private.sendQueue, {hash = hash, encoded = encoded, total = total}) tinsert(private.sendQueue, {hash = hash, encoded = encoded, total = total})
if not private.isSending then if not private.isSending then
private.isSending = true private.isSending = true
@ -264,7 +287,9 @@ local function MergeIncomingData(payload, sender)
TSM:Serialize() TSM:Serialize()
if updated > 0 and sender then if updated == 0 and sender then
DebugPrint("No items updated from " .. sender .. ".")
elseif updated > 0 and sender then
if updated == 1 and lastItemID then if updated == 1 and lastItemID then
local link = select(2, GetItemInfo(lastItemID)) or ("item:" .. tostring(lastItemID)) local link = select(2, GetItemInfo(lastItemID)) or ("item:" .. tostring(lastItemID))
TSM:Printf("AuctionDB updated %s from %s.", link, sender) TSM:Printf("AuctionDB updated %s from %s.", link, sender)
@ -295,11 +320,15 @@ function ChannelSync:OnChannelMessage(_, msg, source, _, _, _, _, _, channelName
local bundle = private.incoming[hash] local bundle = private.incoming[hash]
if not bundle or (time() - bundle.time) > BUNDLE_TIMEOUT then if not bundle or (time() - bundle.time) > BUNDLE_TIMEOUT then
if bundle then
DebugPrint("Bundle timeout " .. format("%08x", hash) .. " (" .. bundle.received .. "/" .. bundle.total .. ").")
end
bundle = {time = time(), total = total, chunks = {}, received = 0} bundle = {time = time(), total = total, chunks = {}, received = 0}
private.incoming[hash] = bundle private.incoming[hash] = bundle
end end
if bundle.total ~= total then if bundle.total ~= total then
DebugPrint("Bundle total mismatch for " .. format("%08x", hash) .. ". Resetting.")
private.incoming[hash] = {time = time(), total = total, chunks = {}, received = 0} private.incoming[hash] = {time = time(), total = total, chunks = {}, received = 0}
bundle = private.incoming[hash] bundle = private.incoming[hash]
end end
@ -319,7 +348,10 @@ function ChannelSync:OnChannelMessage(_, msg, source, _, _, _, _, _, channelName
private.incoming[hash] = nil private.incoming[hash] = nil
local payload = DecodePayload(table.concat(parts)) local payload = DecodePayload(table.concat(parts))
if not payload then return end if not payload then
DebugPrint("Payload decode failed for bundle " .. format("%08x", hash))
return
end
MergeIncomingData(payload, source) MergeIncomingData(payload, source)
end end
@ -332,6 +364,7 @@ function ChannelSync:SendQueueThread()
SendChatMessage(msg, "CHANNEL", nil, private.channelId) SendChatMessage(msg, "CHANNEL", nil, private.channelId)
self:Sleep(SEND_INTERVAL) self:Sleep(SEND_INTERVAL)
end end
DebugPrint("Sent bundle " .. format("%08x", job.hash) .. " (" .. job.total .. " chunks).")
tremove(private.sendQueue, 1) tremove(private.sendQueue, 1)
end end
private.isSending = false private.isSending = false

Loading…
Cancel
Save