'Send a ping request and calculate RTT.
Arguments:
jid        -- The JID that will receive the ping.
ifrom      -- Specifiy the sender JID.
timeout    -- Time in seconds to wait for a response.
Defaults to self.timeout.'

def ping(self, jid=None, ifrom=None, timeout=None):

    own_host = False
    if (not jid):
        if self.xmpp.is_component:
            jid = self.xmpp.server
        else:
            jid = self.xmpp.boundjid.host
    jid = JID(jid)
    if ((jid == self.xmpp.boundjid.host) or (self.xmpp.is_component and (jid == self.xmpp.server))):
        own_host = True
    if (not timeout):
        timeout = self.timeout
    start = time.time()
    log.debug(('Pinging    %s' % jid))
    try:
        self.send_ping(jid, ifrom=ifrom, timeout=timeout)
    except IqError as e:
        if own_host:
            rtt = (time.time() - start)
            log.debug('Pinged    %s,    RTT:    %s', jid, rtt)
            return rtt
        else:
            raise e
    else:
        rtt = (time.time() - start)
        log.debug('Pinged    %s,    RTT:    %s', jid, rtt)
        return rtt
