#714 Prosody Stateful Asynchronous API for sending IQ

Reporter Eugene Voityuk
Owner Zash
Stars ★ (1)
  • Milestone-0.12
  • Type-Enhancement
  • Priority-Medium
  • Status-Fixed
  1. Eugene Voityuk on

    Prosody Stateful Asynchronous API for sending IQ Code name: IQ Tracker :) Purpose Historically happened that prosody lacks an easy mechanism to send iq from server, and keep track of their result, this draft aims to solve this by introducing new API functionality. Implementation For API usage you need to create an instance of IQ Tracker, each instance takes limit and timeout as arguments. Timeout is a number of second to wait for an iq response and drop iq’s that was not responded in specified time. Limit aims to prevent different DDoS attacks, as each iq request using this api will be tracked in memory, until response will be received, or timeout will expire. API will create an instance and will return a function, that will be used to send iq’s. Function takes three arguments, first is a valid iq to send, second is callback, and the this is a key. Key is any string that will be used to keep track of limits, so if you set limit=5, each key may hold 5 open iq stanzas. Usage local send_iq = require ”util.iq_tracker”.create_tracker(limit,timeout); local generic_iq = st.iq({ from = “juliet@example.com” to = ‘romeo@example.net’, type = “set” }) send_iq(generic_iq, function(res, err) If err then module:log(“debug”, ”Failed to send stanza, error type %s, error condition %s, err.type, err.condition); end end, generic_iq.attr.from)

  2. Zash on

    Since `util.promise` was introduced recently, this can be combined with `util.cache` to produce an API like this: ``` module:send_iq(stanza [, origin]) --> promise ``` ``` local iq = st.iq{ to = someone, from = module.host, type = "get", id = random() } :tag("eg", { xmlns = "urn:example:whatever" }); module:send_iq(iq) :next(function (result) -- this is the event payload from a generated iq-result/blah/id event module:log("info", "Got result: %s", result.stanza); end, function (err) -- also an event payload from error handler module:log("error", "Got error: %s", err.stanza); end); ````

    • owner Zash
    • tags Status-Started Milestone-0.12
  3. Zash on

    Implemented in https://hg.prosody.im/trunk/rev/9ab9aabafa80

    • tags Status-Fixed

New comment

Not published. Used for spam prevention and optional update notifications.