Search in sources :

Example 31 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

the class AxolotlService method publishOwnDeviceId.

public void publishOwnDeviceId(Set<Integer> deviceIds) {
    Set<Integer> deviceIdsCopy = new HashSet<>(deviceIds);
    Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "publishing own device ids");
    if (deviceIdsCopy.isEmpty()) {
        if (numPublishTriesOnEmptyPep >= publishTriesThreshold) {
            Log.w(Config.LOGTAG, getLogprefix(account) + "Own device publish attempt threshold exceeded, aborting...");
            pepBroken = true;
            return;
        } else {
            numPublishTriesOnEmptyPep++;
            Log.w(Config.LOGTAG, getLogprefix(account) + "Own device list empty, attempting to publish (try " + numPublishTriesOnEmptyPep + ")");
        }
    } else {
        numPublishTriesOnEmptyPep = 0;
    }
    deviceIdsCopy.add(getOwnDeviceId());
    IqPacket publish = mXmppConnectionService.getIqGenerator().publishDeviceIds(deviceIdsCopy);
    ownPushPending.set(true);
    mXmppConnectionService.sendIqPacket(account, publish, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            ownPushPending.set(false);
            if (packet.getType() == IqPacket.TYPE.ERROR) {
                pepBroken = true;
                Log.d(Config.LOGTAG, getLogprefix(account) + "Error received while publishing own device id" + packet.findChild("error"));
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) HashSet(java.util.HashSet) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 32 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

the class JingleInbandTransport method connect.

public void connect(final OnTransportConnected callback) {
    IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
    iq.setTo(this.counterpart);
    Element open = iq.addChild("open", "http://jabber.org/protocol/ibb");
    open.setAttribute("sid", this.sessionId);
    open.setAttribute("stanza", "iq");
    open.setAttribute("block-size", Integer.toString(this.blockSize));
    this.connected = true;
    this.account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() != IqPacket.TYPE.RESULT) {
                callback.failed();
            } else {
                callback.established();
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 33 with OnIqPacketReceived

use of eu.siacs.conversations.xmpp.OnIqPacketReceived in project Conversations by siacs.

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;
        }
        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");
                    mJingleStatus = JINGLE_STATUS_INITIATED;
                    mXmppConnectionService.markMessage(message, Message.STATUS_OFFERED);
                } else {
                    fail(IqParser.extractErrorMessage(packet));
                }
            }
        });
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) JinglePacket(eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Content(eu.siacs.conversations.xmpp.jingle.stanzas.Content) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Conversation(eu.siacs.conversations.entities.Conversation) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

Account (eu.siacs.conversations.entities.Account)33 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)33 Element (eu.siacs.conversations.xml.Element)16 Jid (eu.siacs.conversations.xmpp.jid.Jid)9 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)4 InvalidKeyException (org.whispersystems.libaxolotl.InvalidKeyException)4 PreKeyBundle (org.whispersystems.libaxolotl.state.PreKeyBundle)4 Conversation (eu.siacs.conversations.entities.Conversation)3 HashSet (java.util.HashSet)3 InvalidKeyIdException (org.whispersystems.libaxolotl.InvalidKeyIdException)3 UntrustedIdentityException (org.whispersystems.libaxolotl.UntrustedIdentityException)3 Bundle (android.os.Bundle)2 Pair (android.util.Pair)2 Contact (eu.siacs.conversations.entities.Contact)2 Data (eu.siacs.conversations.xmpp.forms.Data)2 Content (eu.siacs.conversations.xmpp.jingle.stanzas.Content)2 JinglePacket (eu.siacs.conversations.xmpp.jingle.stanzas.JinglePacket)2 Avatar (eu.siacs.conversations.xmpp.pep.Avatar)2 FileNotFoundException (java.io.FileNotFoundException)2