Search in sources :

Example 1 with Content

use of de.pixart.messenger.xmpp.jingle.stanzas.Content in project Pix-Art-Messenger by kriztan.

the class JingleConnection method receiveAccept.

private boolean receiveAccept(JinglePacket packet) {
    Content content = packet.getJingleContent();
    mergeCandidates(JingleCandidate.parse(content.socks5transport().getChildren()));
    this.mJingleStatus = JINGLE_STATUS_ACCEPTED;
    mXmppConnectionService.markMessage(message, Message.STATUS_UNSEND);
    this.connectNextCandidate();
    return true;
}
Also used : Content(de.pixart.messenger.xmpp.jingle.stanzas.Content)

Example 2 with Content

use of de.pixart.messenger.xmpp.jingle.stanzas.Content in project Pix-Art-Messenger by kriztan.

the class JingleConnection method sendFallbackToIbb.

private void sendFallbackToIbb() {
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": sending fallback to ibb");
    JinglePacket packet = this.bootstrapPacket("transport-replace");
    Content content = new Content(this.contentCreator, this.contentName);
    this.transportId = this.mJingleConnectionManager.nextRandomId();
    content.setTransportId(this.transportId);
    content.ibbTransport().setAttribute("block-size", Integer.toString(this.ibbBlockSize));
    packet.setContent(content);
    this.sendJinglePacket(packet);
}
Also used : JinglePacket(de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket) Content(de.pixart.messenger.xmpp.jingle.stanzas.Content)

Example 3 with Content

use of de.pixart.messenger.xmpp.jingle.stanzas.Content in project Pix-Art-Messenger by kriztan.

the class JingleConnection method sendAccept.

private void sendAccept() {
    mJingleStatus = JINGLE_STATUS_ACCEPTED;
    this.mStatus = Transferable.STATUS_DOWNLOADING;
    this.mJingleConnectionManager.updateConversationUi(true);
    this.mJingleConnectionManager.getPrimaryCandidate(this.account, new OnPrimaryCandidateFound() {

        @Override
        public void onPrimaryCandidateFound(boolean success, final JingleCandidate candidate) {
            final JinglePacket packet = bootstrapPacket("session-accept");
            final Content content = new Content(contentCreator, contentName);
            content.setFileOffer(fileOffer, ftVersion);
            content.setTransportId(transportId);
            if (success && candidate != null && !equalCandidateExists(candidate)) {
                final JingleSocks5Transport socksConnection = new JingleSocks5Transport(JingleConnection.this, candidate);
                connections.put(candidate.getCid(), socksConnection);
                socksConnection.connect(new OnTransportConnected() {

                    @Override
                    public void failed() {
                        Log.d(Config.LOGTAG, "connection to our own primary candidate failed");
                        content.socks5transport().setChildren(getCandidatesAsElements());
                        packet.setContent(content);
                        sendJinglePacket(packet);
                        connectNextCandidate();
                    }

                    @Override
                    public void established() {
                        Log.d(Config.LOGTAG, "connected to primary candidate");
                        mergeCandidate(candidate);
                        content.socks5transport().setChildren(getCandidatesAsElements());
                        packet.setContent(content);
                        sendJinglePacket(packet);
                        connectNextCandidate();
                    }
                });
            } else {
                Log.d(Config.LOGTAG, "did not find a primary candidate for ourself");
                content.socks5transport().setChildren(getCandidatesAsElements());
                packet.setContent(content);
                sendJinglePacket(packet);
                connectNextCandidate();
            }
        }
    });
}
Also used : JinglePacket(de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket) Content(de.pixart.messenger.xmpp.jingle.stanzas.Content)

Example 4 with Content

use of de.pixart.messenger.xmpp.jingle.stanzas.Content in project Pix-Art-Messenger by kriztan.

the class JingleConnection method receiveTransportInfo.

private boolean receiveTransportInfo(JinglePacket packet) {
    Content content = packet.getJingleContent();
    if (content.hasSocks5Transport()) {
        if (content.socks5transport().hasChild("activated")) {
            if ((this.transport != null) && (this.transport instanceof JingleSocks5Transport)) {
                onProxyActivated.success();
            } else {
                String cid = content.socks5transport().findChild("activated").getAttribute("cid");
                Log.d(Config.LOGTAG, "received proxy activated (" + cid + ")prior to choosing our own transport");
                JingleSocks5Transport connection = this.connections.get(cid);
                if (connection != null) {
                    connection.setActivated(true);
                } else {
                    Log.d(Config.LOGTAG, "activated connection not found");
                    this.sendCancel();
                    this.fail();
                }
            }
            return true;
        } else if (content.socks5transport().hasChild("proxy-error")) {
            onProxyActivated.failed();
            return true;
        } else if (content.socks5transport().hasChild("candidate-error")) {
            Log.d(Config.LOGTAG, "received candidate error");
            this.receivedCandidate = true;
            if (mJingleStatus == JINGLE_STATUS_ACCEPTED && this.sentCandidate) {
                this.connect();
            }
            return true;
        } else if (content.socks5transport().hasChild("candidate-used")) {
            String cid = content.socks5transport().findChild("candidate-used").getAttribute("cid");
            if (cid != null) {
                Log.d(Config.LOGTAG, "candidate used by counterpart:" + cid);
                JingleCandidate candidate = getCandidate(cid);
                if (candidate == null) {
                    Log.d(Config.LOGTAG, "could not find candidate with cid=" + cid);
                    return false;
                }
                candidate.flagAsUsedByCounterpart();
                this.receivedCandidate = true;
                if (mJingleStatus == JINGLE_STATUS_ACCEPTED && this.sentCandidate) {
                    this.connect();
                } else {
                    Log.d(Config.LOGTAG, "ignoring because file is already in transmission or we haven't sent our candidate yet status=" + mJingleStatus + " sentCandidate=" + Boolean.toString(sentCandidate));
                }
                return true;
            } else {
                return false;
            }
        } else {
            return false;
        }
    } else {
        return true;
    }
}
Also used : Content(de.pixart.messenger.xmpp.jingle.stanzas.Content)

Example 5 with Content

use of de.pixart.messenger.xmpp.jingle.stanzas.Content in project Pix-Art-Messenger by kriztan.

the class JingleConnection method sendInitRequest.

private void sendInitRequest() {
    JinglePacket packet = this.bootstrapPacket("session-initiate");
    Content content = new Content(this.contentCreator, this.contentName);
    if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
        content.setTransportId(this.transportId);
        this.file = this.mXmppConnectionService.getFileBackend().getFile(message, false);
        Pair<InputStream, Integer> pair;
        try {
            if (message.getEncryption() == Message.ENCRYPTION_OTR) {
                Conversation conversation = this.message.getConversation();
                if (!this.mXmppConnectionService.renewSymmetricKey(conversation)) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": could not set symmetric key");
                    cancel();
                }
                this.file.setKeyAndIv(conversation.getSymmetricKey());
                pair = AbstractConnectionManager.createInputStream(this.file, false);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, true, this.ftVersion);
            } else if (message.getEncryption() == Message.ENCRYPTION_AXOLOTL) {
                this.file.setKey(mXmppAxolotlMessage.getInnerKey());
                this.file.setIv(mXmppAxolotlMessage.getIV());
                pair = AbstractConnectionManager.createInputStream(this.file, true);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, false, this.ftVersion).addChild(mXmppAxolotlMessage.toElement());
            } else {
                pair = AbstractConnectionManager.createInputStream(this.file, false);
                this.file.setExpectedSize(pair.second);
                content.setFileOffer(this.file, false, this.ftVersion);
            }
        } catch (FileNotFoundException e) {
            cancel();
            return;
        }
        message.resetFileParams();
        this.mFileInputStream = pair.first;
        content.setTransportId(this.transportId);
        content.socks5transport().setChildren(getCandidatesAsElements());
        packet.setContent(content);
        this.sendJinglePacket(packet, new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": other party received offer");
                    if (mJingleStatus == JINGLE_STATUS_OFFERED) {
                        mJingleStatus = JINGLE_STATUS_INITIATED;
                        mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED);
                    } else {
                        Log.d(Config.LOGTAG, "received ack for offer when status was " + mJingleStatus);
                    }
                } else {
                    fail(IqParser.extractErrorMessage(packet));
                }
            }
        });
    }
}
Also used : Account(de.pixart.messenger.entities.Account) JinglePacket(de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Content(de.pixart.messenger.xmpp.jingle.stanzas.Content) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Conversation(de.pixart.messenger.entities.Conversation) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Aggregations

Content (de.pixart.messenger.xmpp.jingle.stanzas.Content)10 JinglePacket (de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket)7 Account (de.pixart.messenger.entities.Account)2 Conversation (de.pixart.messenger.entities.Conversation)2 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)2 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)2 XmppAxolotlMessage (de.pixart.messenger.crypto.axolotl.XmppAxolotlMessage)1 Message (de.pixart.messenger.entities.Message)1 Element (de.pixart.messenger.xml.Element)1 Jid (de.pixart.messenger.xmpp.jid.Jid)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1