Search in sources :

Example 16 with OnIqPacketReceived

use of de.pixart.messenger.xmpp.OnIqPacketReceived in project Pix-Art-Messenger by kriztan.

the class AxolotlService method publishOwnDeviceIdIfNeeded.

public void publishOwnDeviceIdIfNeeded() {
    if (pepBroken) {
        Log.d(Config.LOGTAG, getLogprefix(account) + "publishOwnDeviceIdIfNeeded called, but PEP is broken. Ignoring... ");
        return;
    }
    IqPacket packet = mXmppConnectionService.getIqGenerator().retrieveDeviceIds(account.getJid().toBareJid());
    mXmppConnectionService.sendIqPacket(account, packet, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.TIMEOUT) {
                Log.d(Config.LOGTAG, getLogprefix(account) + "Timeout received while retrieving own Device Ids.");
            } else {
                Element item = mXmppConnectionService.getIqParser().getItem(packet);
                Set<Integer> deviceIds = mXmppConnectionService.getIqParser().deviceIds(item);
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": retrieved own device list: " + deviceIds);
                registerDevices(account.getJid().toBareJid(), deviceIds);
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) Set(java.util.Set) HashSet(java.util.HashSet) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 17 with OnIqPacketReceived

use of de.pixart.messenger.xmpp.OnIqPacketReceived 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)

Example 18 with OnIqPacketReceived

use of de.pixart.messenger.xmpp.OnIqPacketReceived in project Pix-Art-Messenger by kriztan.

the class JingleConnection method connect.

private void connect() {
    final JingleSocks5Transport connection = chooseConnection();
    this.transport = connection;
    if (connection == null) {
        Log.d(Config.LOGTAG, "could not find suitable candidate");
        this.disconnectSocks5Connections();
        if (initiating()) {
            this.sendFallbackToIbb();
        }
    } else {
        this.mJingleStatus = JINGLE_STATUS_TRANSMITTING;
        if (connection.needsActivation()) {
            if (connection.getCandidate().isOurs()) {
                final String sid;
                if (ftVersion == Content.Version.FT_3) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": use session ID instead of transport ID to activate proxy");
                    sid = getSessionId();
                } else {
                    sid = getTransportId();
                }
                Log.d(Config.LOGTAG, "candidate " + connection.getCandidate().getCid() + " was our proxy. going to activate");
                IqPacket activation = new IqPacket(IqPacket.TYPE.SET);
                activation.setTo(connection.getCandidate().getJid());
                activation.query("http://jabber.org/protocol/bytestreams").setAttribute("sid", sid);
                activation.query().addChild("activate").setContent(this.getCounterPart().toString());
                mXmppConnectionService.sendIqPacket(account, activation, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket packet) {
                        if (packet.getType() != IqPacket.TYPE.RESULT) {
                            onProxyActivated.failed();
                        } else {
                            onProxyActivated.success();
                            sendProxyActivated(connection.getCandidate().getCid());
                        }
                    }
                });
            } else {
                Log.d(Config.LOGTAG, "candidate " + connection.getCandidate().getCid() + " was a proxy. waiting for other party to activate");
            }
        } else {
            if (initiating()) {
                Log.d(Config.LOGTAG, "we were initiating. sending file");
                connection.send(file, onFileTransmissionStatusChanged);
            } else {
                Log.d(Config.LOGTAG, "we were responding. receiving file");
                connection.receive(file, onFileTransmissionStatusChanged);
            }
        }
    }
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 19 with OnIqPacketReceived

use of de.pixart.messenger.xmpp.OnIqPacketReceived in project Pix-Art-Messenger by kriztan.

the class JingleConnection method receiveFallbackToIbb.

private boolean receiveFallbackToIbb(JinglePacket packet) {
    Log.d(Config.LOGTAG, "receiving fallack to ibb");
    String receivedBlockSize = packet.getJingleContent().ibbTransport().getAttribute("block-size");
    if (receivedBlockSize != null) {
        int bs = Integer.parseInt(receivedBlockSize);
        if (bs > this.ibbBlockSize) {
            this.ibbBlockSize = bs;
        }
    }
    this.transportId = packet.getJingleContent().getTransportId();
    this.transport = new JingleInbandTransport(this, this.transportId, this.ibbBlockSize);
    JinglePacket answer = bootstrapPacket("transport-accept");
    Content content = new Content("initiator", "a-file-offer");
    content.setTransportId(this.transportId);
    content.ibbTransport().setAttribute("block-size", this.ibbBlockSize);
    answer.setContent(content);
    if (initiating()) {
        this.sendJinglePacket(answer, new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(Account account, IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    Log.d(Config.LOGTAG, account.getJid().toBareJid() + " recipient ACKed our transport-accept. creating ibb");
                    transport.connect(onIbbTransportConnected);
                }
            }
        });
    } else {
        this.transport.receive(file, onFileTransmissionStatusChanged);
        this.sendJinglePacket(answer);
    }
    return true;
}
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) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 20 with OnIqPacketReceived

use of de.pixart.messenger.xmpp.OnIqPacketReceived in project Pix-Art-Messenger by kriztan.

the class JingleConnectionManager method getPrimaryCandidate.

public void getPrimaryCandidate(Account account, final OnPrimaryCandidateFound listener) {
    if (Config.DISABLE_PROXY_LOOKUP) {
        listener.onPrimaryCandidateFound(false, null);
        return;
    }
    if (!this.primaryCandidates.containsKey(account.getJid().toBareJid())) {
        final Jid proxy = account.getXmppConnection().findDiscoItemByFeature(Namespace.BYTE_STREAMS);
        if (proxy != null) {
            IqPacket iq = new IqPacket(IqPacket.TYPE.GET);
            iq.setTo(proxy);
            iq.query(Namespace.BYTE_STREAMS);
            account.getXmppConnection().sendIqPacket(iq, new OnIqPacketReceived() {

                @Override
                public void onIqPacketReceived(Account account, IqPacket packet) {
                    Element streamhost = packet.query().findChild("streamhost", Namespace.BYTE_STREAMS);
                    final String host = streamhost == null ? null : streamhost.getAttribute("host");
                    final String port = streamhost == null ? null : streamhost.getAttribute("port");
                    if (host != null && port != null) {
                        try {
                            JingleCandidate candidate = new JingleCandidate(nextRandomId(), true);
                            candidate.setHost(host);
                            candidate.setPort(Integer.parseInt(port));
                            candidate.setType(JingleCandidate.TYPE_PROXY);
                            candidate.setJid(proxy);
                            candidate.setPriority(655360 + 65535);
                            primaryCandidates.put(account.getJid().toBareJid(), candidate);
                            listener.onPrimaryCandidateFound(true, candidate);
                        } catch (final NumberFormatException e) {
                            listener.onPrimaryCandidateFound(false, null);
                            return;
                        }
                    } else {
                        listener.onPrimaryCandidateFound(false, null);
                    }
                }
            });
        } else {
            listener.onPrimaryCandidateFound(false, null);
        }
    } else {
        listener.onPrimaryCandidateFound(true, this.primaryCandidates.get(account.getJid().toBareJid()));
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Aggregations

Account (de.pixart.messenger.entities.Account)31 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)31 Element (de.pixart.messenger.xml.Element)17 Jid (de.pixart.messenger.xmpp.jid.Jid)8 PreKeyBundle (org.whispersystems.libsignal.state.PreKeyBundle)5 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)4 InvalidKeyException (org.whispersystems.libsignal.InvalidKeyException)4 Bundle (android.os.Bundle)3 Contact (de.pixart.messenger.entities.Contact)3 Conversation (de.pixart.messenger.entities.Conversation)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Set (java.util.Set)3 InvalidKeyIdException (org.whispersystems.libsignal.InvalidKeyIdException)3 UntrustedIdentityException (org.whispersystems.libsignal.UntrustedIdentityException)3 Pair (android.util.Pair)2 Data (de.pixart.messenger.xmpp.forms.Data)2 Content (de.pixart.messenger.xmpp.jingle.stanzas.Content)2 JinglePacket (de.pixart.messenger.xmpp.jingle.stanzas.JinglePacket)2