Software /
code /
verse
Diff
client.lua @ 457:73d4eb93657b
Update to use util.id for random ids instead of counters (thanks Zash)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 16 Mar 2023 11:41:52 +0000 |
parent | 452:628896d39d8e |
child | 458:6c3797c0bb44 |
line wrap: on
line diff
--- a/client.lua Fri Mar 03 12:10:54 2023 +0000 +++ b/client.lua Thu Mar 16 11:41:52 2023 +0000 @@ -4,11 +4,21 @@ local jid_split = require "util.jid".split; local adns = require "net.adns"; local st = require "util.stanza"; +local new_id = require "util.id".short; + +math.randomseed((require"socket".gettime() * 1000000) % 0x80000000); -- Shortcuts to save having to load util.stanza verse.message, verse.presence, verse.iq, verse.stanza, verse.reply, verse.error_reply = st.message, st.presence, st.iq, st.stanza, st.reply, st.error_reply; +function verse.iq(attr) + if not attr.id then + attr.id = new_id(); + end + return st.iq(attr); +end + local new_xmpp_stream = require "util.xmppstream".new; local xmlns_stream = "http://etherx.jabber.org/streams"; @@ -208,13 +218,8 @@ end function stream:send_iq(iq, callback) - local id = self:new_id(); + local id = iq.attr.id or uuid.generate(); self.tracked_iqs[id] = callback; iq.attr.id = id; self:send(iq); end - -function stream:new_id() - self.curr_id = self.curr_id + 1; - return tostring(self.curr_id); -end