Example #1
0
 def __on_transport_replace(self, stanza, jingle, error, action):
     for content in jingle.iterTags('content'):
         creator = content['creator']
         name = content['name']
         if (creator, name) in self.contents:
             transport_ns = content.getTag('transport').getNamespace()
             if transport_ns == Namespace.JINGLE_ICE_UDP:
                 # FIXME: We don't manage anything else than ICE-UDP now...
                 # What was the previous transport?!?
                 # Anyway, content's transport is not modifiable yet
                 pass
             elif transport_ns == Namespace.JINGLE_IBB:
                 transport = JingleTransportIBB(node=content.getTag(
                     'transport'))
                 self.modify_content(creator, name, transport)
                 self.state = JingleStates.PENDING
                 self.contents[(creator, name)].state = State.TRANSPORT_REPLACE
                 self.__ack(stanza, jingle, error, action)
                 self.__transport_accept(transport)
             else:
                 stanza, jingle = self.__make_jingle('transport-reject')
                 content = jingle.setTag('content', attrs={'creator': creator,
                                                           'name': name})
                 content.setTag('transport', namespace=transport_ns)
                 self.connection.connection.send(stanza)
                 raise nbxmpp.NodeProcessed
         else:
             # FIXME: This resource is unknown to us, what should we do?
             # For now, reject the transport
             stanza, jingle = self.__make_jingle('transport-reject')
             content = jingle.setTag('content', attrs={'creator': creator,
                                                       'name': name})
             content.setTag('transport', namespace=transport_ns)
             self.connection.connection.send(stanza)
             raise nbxmpp.NodeProcessed
Example #2
0
 def transport_replace(self):
     transport = JingleTransportIBB()
     # For debug only, delete this and replace for a function
     # that will identify contents by its sid
     for creator, name in self.contents:
         self.modify_content(creator, name, transport)
         cont = self.contents[(creator, name)]
         cont.transport = transport
     stanza, jingle = self.__make_jingle('transport-replace')
     self.__append_contents(jingle)
     self.__broadcast(stanza, jingle, None, 'transport-replace')
     self.connection.connection.send(stanza)
     self.state = JingleStates.PENDING
Example #3
0
    def start_file_transfer(self, jid, file_props, request=False):
        logger.info("start file transfer with file: %s", file_props)
        contact = app.contacts.get_contact_with_highest_priority(
            self._account, app.get_jid_without_resource(jid))
        if app.contacts.is_gc_contact(self._account, jid):
            gcc = jid.split('/')
            if len(gcc) == 2:
                contact = app.contacts.get_gc_contact(self._account,
                                                      gcc[0],
                                                      gcc[1])
        if contact is None:
            return None
        use_security = contact.supports(Namespace.JINGLE_XTLS)
        jingle = JingleSession(self._con,
                               weinitiate=True,
                               jid=jid,
                               werequest=request)
        # this is a file transfer
        jingle.session_type_ft = True
        self._sessions[jingle.sid] = jingle
        file_props.sid = jingle.sid

        if contact.supports(Namespace.JINGLE_BYTESTREAM):
            transport = JingleTransportSocks5()
        elif contact.supports(Namespace.JINGLE_IBB):
            transport = JingleTransportIBB()
        else:
            transport = None

        senders = 'initiator'
        if request:
            senders = 'responder'
        transfer = JingleFileTransfer(jingle,
                                      transport=transport,
                                      file_props=file_props,
                                      use_security=use_security,
                                      senders=senders)
        file_props.transport_sid = transport.sid
        file_props.algo = self.__hash_support(contact)
        jingle.add_content('file' + helpers.get_random_string(), transfer)
        jingle.start_session()
        return transfer.transport.sid