aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2016-12-18 22:34:13 +0100
committerChristian Schneppe <christian@pix-art.de>2016-12-18 22:34:13 +0100
commit2434f697b0d61aacea21e0509897e0358901ed2f (patch)
tree62baf236d2b076e53100b7352a58c5b4fe15cce8 /src/main/java/de
parent57f4bea4d5709871daf1b4aa4d31775f3cc92ef0 (diff)
remove own fetch errors from device announcement
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java74
-rw-r--r--src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java1
-rw-r--r--src/main/java/de/pixart/messenger/ui/EditAccountActivity.java1
-rw-r--r--src/main/java/de/pixart/messenger/ui/OmemoActivity.java (renamed from src/main/java/de/pixart/messenger/OmemoActivity.java)6
-rw-r--r--src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java1
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java7
6 files changed, 48 insertions, 42 deletions
diff --git a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
index 84f937c4f..587e6e12e 100644
--- a/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
+++ b/src/main/java/de/pixart/messenger/crypto/axolotl/AxolotlService.java
@@ -392,7 +392,7 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
XmppAxolotlSession session = sessions.get(address);
if (session != null && session.getFingerprint() != null) {
if (!session.getTrust().isActive()) {
- Log.d(Config.LOGTAG,"reactivating device with fingprint "+session.getFingerprint());
+ Log.d(Config.LOGTAG,"reactivating device with fingerprint "+session.getFingerprint());
session.setTrust(session.getTrust().toActive());
}
}
@@ -404,7 +404,11 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
for (Integer deviceId : deviceIds) {
AxolotlAddress ownDeviceAddress = new AxolotlAddress(jid.toBareJid().toPreppedString(), deviceId);
if (sessions.get(ownDeviceAddress) == null) {
- buildSessionFromPEP(ownDeviceAddress);
+ FetchStatus status = fetchStatusMap.get(ownDeviceAddress);
+ if (status == null || status == FetchStatus.TIMEOUT) {
+ fetchStatusMap.put(ownDeviceAddress, FetchStatus.PENDING);
+ this.buildSessionFromPEP(ownDeviceAddress);
+ }
}
}
if (needsPublishing) {
@@ -459,10 +463,13 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
long diff = System.currentTimeMillis() - session.getTrust().getLastActivation();
if (diff > Config.OMEMO_AUTO_EXPIRY) {
long lastMessageDiff = System.currentTimeMillis() - mXmppConnectionService.databaseBackend.getLastTimeFingerprintUsed(account,session.getFingerprint());
+ long hours = Math.round(lastMessageDiff/(1000*60.0*60.0));
if (lastMessageDiff > Config.OMEMO_AUTO_EXPIRY) {
devices.add(session.getRemoteAddress().getDeviceId());
session.setTrust(session.getTrust().toInactive());
- Log.d(Config.LOGTAG, "added own device " + session.getFingerprint() + " to list of expired devices. Last message received "+(lastMessageDiff/1000)+"s ago");
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": added own device " + session.getFingerprint() + " to list of expired devices. Last message received "+hours+" hours ago");
+ } else {
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": own device "+session.getFingerprint()+" was active "+hours+" hours ago");
}
}
}
@@ -472,34 +479,32 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
public void publishOwnDeviceId(Set<Integer> deviceIds) {
Set<Integer> deviceIdsCopy = new HashSet<>(deviceIds);
- if (!deviceIdsCopy.contains(getOwnDeviceId())) {
- Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Own device " + getOwnDeviceId() + " not in PEP devicelist.");
- 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 + ")");
- }
+ 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 = 0;
+ numPublishTriesOnEmptyPep++;
+ Log.w(Config.LOGTAG, getLogprefix(account) + "Own device list empty, attempting to publish (try " + numPublishTriesOnEmptyPep + ")");
}
- 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"));
- }
- }
- });
+ } 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"));
+ }
+ }
+ });
}
public void publishDeviceVerificationAndBundle(final SignedPreKeyRecord signedPreKeyRecord,
@@ -793,10 +798,21 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
}
mXmppConnectionService.keyStatusUpdated(report);
}
+ Set<Integer> ownDeviceIds = new HashSet<>(getOwnDeviceIds());
+ boolean publish = false;
+ for(Map.Entry<Integer,FetchStatus> entry : own.entrySet()) {
+ if (entry.getValue() == FetchStatus.ERROR && ownDeviceIds.remove(entry.getKey())) {
+ publish = true;
+ Log.d(Config.LOGTAG,account.getJid().toBareJid()+": error fetching own device with id "+entry.getKey()+". removing from annoucement");
+ }
+ }
+ if (publish) {
+ publishOwnDeviceId(ownDeviceIds);
+ }
}
private void buildSessionFromPEP(final AxolotlAddress address) {
- Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Building new sesstion for " + address.toString());
+ Log.i(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Building new session for " + address.toString());
if (address.getDeviceId() == getOwnDeviceId()) {
throw new AssertionError("We should NEVER build a session with ourselves. What happened here?!");
}
diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
index a97ffc321..9b00b7ae9 100644
--- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
@@ -36,7 +36,6 @@ import org.openintents.openpgp.util.OpenPgpUtils;
import java.util.List;
import de.pixart.messenger.Config;
-import de.pixart.messenger.OmemoActivity;
import de.pixart.messenger.R;
import de.pixart.messenger.crypto.PgpEngine;
import de.pixart.messenger.crypto.axolotl.AxolotlService;
diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
index 7dedf693b..57c2ec806 100644
--- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java
@@ -41,7 +41,6 @@ import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import de.pixart.messenger.Config;
-import de.pixart.messenger.OmemoActivity;
import de.pixart.messenger.R;
import de.pixart.messenger.crypto.axolotl.AxolotlService;
import de.pixart.messenger.crypto.axolotl.XmppAxolotlSession;
diff --git a/src/main/java/de/pixart/messenger/OmemoActivity.java b/src/main/java/de/pixart/messenger/ui/OmemoActivity.java
index 5359e8a28..9a708bbae 100644
--- a/src/main/java/de/pixart/messenger/OmemoActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/OmemoActivity.java
@@ -1,4 +1,4 @@
-package de.pixart.messenger;
+package de.pixart.messenger.ui;
import android.app.AlertDialog;
@@ -20,11 +20,11 @@ import com.google.zxing.integration.android.IntentResult;
import java.security.cert.X509Certificate;
import java.util.Arrays;
+import de.pixart.messenger.Config;
+import de.pixart.messenger.R;
import de.pixart.messenger.crypto.axolotl.FingerprintStatus;
import de.pixart.messenger.crypto.axolotl.XmppAxolotlSession;
import de.pixart.messenger.entities.Account;
-import de.pixart.messenger.ui.TrustKeysActivity;
-import de.pixart.messenger.ui.XmppActivity;
import de.pixart.messenger.ui.widget.Switch;
import de.pixart.messenger.utils.CryptoHelper;
import de.pixart.messenger.utils.XmppUri;
diff --git a/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java b/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java
index 69e33fde9..a49162afb 100644
--- a/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/TrustKeysActivity.java
@@ -27,7 +27,6 @@ import java.util.Map;
import java.util.Set;
import de.pixart.messenger.Config;
-import de.pixart.messenger.OmemoActivity;
import de.pixart.messenger.R;
import de.pixart.messenger.crypto.axolotl.AxolotlService;
import de.pixart.messenger.crypto.axolotl.FingerprintStatus;
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index 3151e5739..17d2ed3c4 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -23,7 +23,6 @@ import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
-import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -51,18 +50,12 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
-import com.google.zxing.BarcodeFormat;
-import com.google.zxing.EncodeHintType;
-import com.google.zxing.aztec.AztecWriter;
-import com.google.zxing.common.BitMatrix;
-
import net.java.otr4j.session.SessionID;
import java.io.FileNotFoundException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.concurrent.RejectedExecutionException;