remove dns resolver cache

This commit is contained in:
Martin/Geno 2019-06-08 15:57:29 +02:00 committed by genofire
parent d73cb08ec6
commit ba6266b829
No known key found for this signature in database
GPG Key ID: 9D7D3C6BFF600C6A
2 changed files with 2 additions and 60 deletions

View File

@ -55,7 +55,6 @@ import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.CursorUtils;
import eu.siacs.conversations.utils.FtsUtils;
import eu.siacs.conversations.utils.MimeUtils;
import eu.siacs.conversations.utils.Resolver;
import eu.siacs.conversations.xmpp.InvalidJid;
import eu.siacs.conversations.xmpp.mam.MamReference;
import rocks.xmpp.addr.Jid;
@ -150,19 +149,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
+ ") ON CONFLICT IGNORE"
+ ");";
private static String RESOLVER_RESULTS_TABLENAME = "resolver_results";
private static String CREATE_RESOLVER_RESULTS_TABLE = "create table " + RESOLVER_RESULTS_TABLENAME + "("
+ Resolver.Result.DOMAIN + " TEXT,"
+ Resolver.Result.HOSTNAME + " TEXT,"
+ Resolver.Result.IP + " BLOB,"
+ Resolver.Result.PRIORITY + " NUMBER,"
+ Resolver.Result.DIRECT_TLS + " NUMBER,"
+ Resolver.Result.AUTHENTICATED + " NUMBER,"
+ Resolver.Result.PORT + " NUMBER,"
+ "UNIQUE(" + Resolver.Result.DOMAIN + ") ON CONFLICT REPLACE"
+ ");";
private static String CREATE_MESSAGE_TIME_INDEX = "create INDEX message_time_index ON " + Message.TABLENAME + "(" + Message.TIME_SENT + ")";
private static String CREATE_MESSAGE_CONVERSATION_INDEX = "create INDEX message_conversation_index ON " + Message.TABLENAME + "(" + Message.CONVERSATION + ")";
private static String CREATE_MESSAGE_DELETED_INDEX = "create index message_deleted_index ON " + Message.TABLENAME + "(" + Message.DELETED + ")";
@ -257,7 +243,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.execSQL(CREATE_SIGNED_PREKEYS_STATEMENT);
db.execSQL(CREATE_IDENTITIES_STATEMENT);
db.execSQL(CREATE_PRESENCE_TEMPLATES_STATEMENT);
db.execSQL(CREATE_RESOLVER_RESULTS_TABLE);
db.execSQL(CREATE_MESSAGE_INDEX_TABLE);
db.execSQL(CREATE_MESSAGE_INSERT_TRIGGER);
db.execSQL(CREATE_MESSAGE_UPDATE_TRIGGER);
@ -513,10 +498,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
db.execSQL("ALTER TABLE " + Message.TABLENAME + " ADD COLUMN " + Message.MARKABLE + " NUMBER DEFAULT 0");
}
if (oldVersion < 39 && newVersion >= 39) {
db.execSQL(CREATE_RESOLVER_RESULTS_TABLE);
}
if (oldVersion < 41 && newVersion >= 41) {
db.execSQL(CREATE_MESSAGE_INDEX_TABLE);
db.execSQL(CREATE_MESSAGE_INSERT_TRIGGER);
@ -555,6 +536,8 @@ public class DatabaseBackend extends SQLiteOpenHelper {
final long diff = SystemClock.elapsedRealtime() - start;
Log.d(Config.LOGTAG,"deleted old edit information in "+diff+"ms");
}
db.execSQL("DROP TABLE IF EXISTS resolver_results");
}
private void canonicalizeJids(SQLiteDatabase db) {
@ -677,34 +660,6 @@ public class DatabaseBackend extends SQLiteOpenHelper {
return result;
}
public void saveResolverResult(String domain, Resolver.Result result) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = result.toContentValues();
contentValues.put(Resolver.Result.DOMAIN, domain);
db.insert(RESOLVER_RESULTS_TABLENAME, null, contentValues);
}
public synchronized Resolver.Result findResolverResult(String domain) {
SQLiteDatabase db = this.getReadableDatabase();
String where = Resolver.Result.DOMAIN + "=?";
String[] whereArgs = {domain};
final Cursor cursor = db.query(RESOLVER_RESULTS_TABLENAME, null, where, whereArgs, null, null, null);
Resolver.Result result = null;
if (cursor != null) {
try {
if (cursor.moveToFirst()) {
result = Resolver.Result.fromCursor(cursor);
}
} catch (Exception e) {
Log.d(Config.LOGTAG, "unable to find cached resolver result in database " + e.getMessage());
return null;
} finally {
cursor.close();
}
}
return result;
}
public void insertPresenceTemplate(PresenceTemplate template) {
SQLiteDatabase db = this.getWritableDatabase();
String whereToDelete = PresenceTemplate.MESSAGE + "=?";

View File

@ -306,16 +306,6 @@ public class XmppConnection implements Runnable {
Log.e(Config.LOGTAG,account.getJid().asBareJid()+": Resolver results were empty");
return;
}
final Resolver.Result storedBackupResult;
if (hardcoded) {
storedBackupResult = null;
} else {
storedBackupResult = mXmppConnectionService.databaseBackend.findResolverResult(domain);
if (storedBackupResult != null && !results.contains(storedBackupResult)) {
results.add(storedBackupResult);
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": loaded backup resolver result from db: " + storedBackupResult);
}
}
for (Iterator<Resolver.Result> iterator = results.iterator(); iterator.hasNext(); ) {
final Resolver.Result result = iterator.next();
if (Thread.currentThread().isInterrupted()) {
@ -350,9 +340,6 @@ public class XmppConnection implements Runnable {
localSocket.setSoTimeout(Config.SOCKET_TIMEOUT * 1000);
if (startXmpp(localSocket)) {
localSocket.setSoTimeout(0); //reset to 0; once the connection is established we dont want this
if (!hardcoded && !result.equals(storedBackupResult)) {
mXmppConnectionService.databaseBackend.saveResolverResult(domain, result);
}
break; // successfully connected to server that speaks xmpp
} else {
FileBackend.close(localSocket);