Example #1
0
    def requestStream(self, jid, callback, sid=None, meta=None, from_=None):
        """
        Request bytestream session from another entity.

        :param jid: JID of entity we want connect to.

        :param callback: callback which will be called when data will
        be available to consume.

        :param sid: session id to use with stream. Generate one if None given.

        :param meta: metadata for this session. (Will be passed in a callback)

        :param from_: sender JID for request (if differs from myjid)
        """
        if from_ is None:
            from_ = self.dispatcher.myjid
        if sid is None:
            sid = genSID()

        streamhosts = [
            stanzas.StreamHost(rhost=iface[0], jid=from_, port=iface[1])
            for iface in self.ifaces
        ]

        for proxy_jid in self.proxies:
            proxy = self.proxies[proxy_jid]
            streamhosts.append(
                stanzas.StreamHost(rhost=proxy[0],
                                   port=proxy[1],
                                   jid=proxy_jid))

        query = stanzas.StreamHostQuery(sid=sid,
                                        streamhosts=streamhosts,
                                        parent=Iq(type_='set',
                                                  to=jid,
                                                  from_=from_))

        d = self.registerSession(sid, from_, jid, callback, meta=meta)
        try:
            result = yield self.dispatcher.send(query)
        except:
            self.unregisterSession(sid=sid)
            raise
        pjid = result.streamhost_used.jid
        if pjid in self.proxies:
            proxy = self.proxies[pjid]
            yield _startClient(self, proxy[0], proxy[1],
                               self.sessions[sid]['hash'])
            query = stanzas.ActivateQuery(jid=jid,
                                          sid=sid,
                                          parent=Iq(type_='set',
                                                    from_=from_,
                                                    to=pjid))
            yield self.dispatcher.send(query)
        else:
            yield d
        defer.returnValue(sid)
Example #2
0
    def requestStream(self, jid, callback, sid=None, meta=None, from_=None):
        """
        Request bytestream session from another entity.

        :param jid: JID of entity we want connect to.

        :param callback: callback which will be called when data will
        be available to consume.

        :param sid: session id to use with stream. Generate one if None given.

        :param meta: metadata for this session. (Will be passed in a callback)

        :param from_: sender JID for request (if differs from myjid)
        """
        if from_ is None:
            from_ = self.dispatcher.myjid
        if sid is None:
            sid = genSID()

        streamhosts = [
            stanzas.StreamHost(rhost=iface[0],
                               jid=from_,
                               port=iface[1]) for iface in self.ifaces
        ]

        for proxy_jid in self.proxies:
            proxy = self.proxies[proxy_jid]
            streamhosts.append(
                stanzas.StreamHost(rhost=proxy[0],
                                   port=proxy[1],
                                   jid=proxy_jid)
            )

        query = stanzas.StreamHostQuery(sid=sid,
                                streamhosts=streamhosts,
                                parent=Iq(type_='set', to=jid, from_=from_))

        d = self.registerSession(sid, from_, jid, callback, meta=meta)
        try:
            result = yield self.dispatcher.send(query)
        except:
            self.unregisterSession(sid=sid)
            raise
        pjid = result.streamhost_used.jid
        if pjid in self.proxies:
            proxy = self.proxies[pjid]
            yield _startClient(self, proxy[0], proxy[1], 
                               self.sessions[sid]['hash'])
            query = stanzas.ActivateQuery(jid=jid, sid=sid,
                        parent=Iq(type_='set', from_=from_,
                                  to=pjid))
            yield self.dispatcher.send(query)
        else:
            yield d
        defer.returnValue(sid)
Example #3
0
    def requestStream(self,
                      jid,
                      callback,
                      sid=None,
                      meta=None,
                      from_=None,
                      block_size=4096,
                      stanza_type='iq',
                      wait_for_result_when_send=True):
        """
        Request bytestream session from another entity.

        :param jid: JID of entity we want connect to.

        :param callback: callback which will be called when data will
        be available to consume.

        :param sid: session id to use with stream. Generate one if None given.

        :param meta: metadata for this session. (Will be passed in a callback)

        :param from_: sender JID for request (if differs from myjid)

        :param block_size: block size to use with the connection.
        """
        if from_ is None:
            from_ = self.dispatcher.myjid

        if sid is None:
            sid = genSID()
        s = self.registerSession(
            sid,
            from_,
            jid,
            callback,
            meta=meta,
            block_size=block_size,
            stanza_type=stanza_type,
            wait_for_result_when_send=wait_for_result_when_send)
        s['is_outgoing'] = True
        query = OpenQuery(block_size=block_size,
                          sid=sid,
                          stanza_type=stanza_type,
                          parent=Iq(type_='set', to=jid, from_=from_))
        try:
            yield self.dispatcher.send(query.iq)
        except:
            self.unregisterSession(sid=sid)
            raise

        s['active'] = True
        defer.returnValue(sid)
Example #4
0
    def requestStream(self, jid, callback, sid=None, meta=None, from_=None,
                      block_size=4096, stanza_type='iq',
                      wait_for_result_when_send=True):
        """
        Request bytestream session from another entity.

        :param jid: JID of entity we want connect to.

        :param callback: callback which will be called when data will
        be available to consume.

        :param sid: session id to use with stream. Generate one if None given.

        :param meta: metadata for this session. (Will be passed in a callback)

        :param from_: sender JID for request (if differs from myjid)

        :param block_size: block size to use with the connection.
        """
        if from_ is None:
            from_ = self.dispatcher.myjid

        if sid is None:
            sid = genSID()
        s = self.registerSession(sid, from_, jid, callback, meta=meta,
                             block_size=block_size, stanza_type=stanza_type,
                         wait_for_result_when_send=wait_for_result_when_send)
        s['is_outgoing'] = True
        query = OpenQuery(block_size=block_size,
                          sid=sid,
                          stanza_type=stanza_type,
                          parent=Iq(type_='set', to=jid, from_=from_))
        try:
            yield self.dispatcher.send(query.iq)
        except:
            self.unregisterSession(sid=sid)
            raise
        
        s['active'] = True
        defer.returnValue(sid)