fritzy / SleekXMPP

Python 2.6+/3.1+ XMPP Library
http://groups.google.com/group/sleekxmpp-discussion
Other
1.1k stars 299 forks source link

[XEP-0199] Ping plugin does not catch "remote-server-not-found" #196

Open Nekmo opened 12 years ago

Nekmo commented 12 years ago

If I send a ping request to a nonexistent JID, then I get the ping was sent successfully.

My Code:

    @groups('roommember')
    def ping(self, msg):
        if not msg['args']:
            msg['args'] = msg['from'].full
        t = self.xmpp.plugin['xep_0199'].send_ping(msg['args'])
        log.info('Wow! Pong in %f seconds!' % t)

Debug:

DEBUG    RECV: <message to="bot@nekmo.com/nekbot_nagisa_1343644729" from="offtopic@salas.nekmo.org/Nekmo" id="1060" type="groupchat"><body>!ping nekmo@jabber.fail</body></message>
DEBUG    Pinging nekmo@jabber.fail
DEBUG    SEND: <iq to="nekmo@jabber.fail" type="get" id="be95d949-a37a-4a6a-a8ec-4d39e303916f-11"><ping xmlns="urn:xmpp:ping" /></iq>
DEBUG    RECV: <iq id="be95d949-a37a-4a6a-a8ec-4d39e303916f-11" to="bot@nekmo.com/nekbot_nagisa_1343644729" from="nekmo@jabber.fail" xml:lang="en" type="error"><ping xmlns="urn:xmpp:ping" /><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error></iq>
['XEP-0009']._handle_error -> ERROR! Iq is '<iq to="bot@nekmo.com/nekbot_nagisa_1343644729" type="error" from="nekmo@jabber.fail" id="be95d949-a37a-4a6a-a8ec-4d39e303916f-11" xml:lang="en"><ping xmlns="urn:xmpp:ping" /><error code="404" type="cancel"><remote-server-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas" /></error></iq>'
#######################
### NOT IMPLEMENTED ###
#######################
DEBUG    Pong: nekmo@jabber.fail 0.010000
INFO     Wow! Pong in 0.010000 seconds!
legastero commented 12 years ago

I'll have to think through this one carefully to be sure to get it right.

We have two issues at play here:

1) For backwards compatibility and convenience reasons, the send_ping() method returns the ping delay instead of the Iq result (or raising IqError), unlike the convention for all other Iq based calls.

2) For pings between client and server, it doesn't matter time wise if there was an error: the time spent sending the error is the same as sending an actual ping. This allows pinging to work even with servers that don't support them.

What I'm thinking so far is to keep the current behaviour for the client to server case, but allow the exceptions to pass through in all other cases. And, in both cases, to continue returning the time difference.