mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-30 09:40:46 +00:00
Better FS Locking.
This commit is contained in:
parent
c8757c2134
commit
79020cd33c
@ -1,3 +1,13 @@
|
|||||||
|
buildscript {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
classpath 'com.android.tools.build:gradle:0.9.+'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
apply plugin: 'android-library'
|
apply plugin: 'android-library'
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
@ -25,16 +25,17 @@ public class PreKeyEntity implements PreKey {
|
|||||||
@Expose(serialize = false)
|
@Expose(serialize = false)
|
||||||
private int deviceId;
|
private int deviceId;
|
||||||
|
|
||||||
|
@Expose(serialize = false)
|
||||||
|
private int registrationId;
|
||||||
|
|
||||||
private int keyId;
|
private int keyId;
|
||||||
private ECPublicKey publicKey;
|
private ECPublicKey publicKey;
|
||||||
private IdentityKey identityKey;
|
private IdentityKey identityKey;
|
||||||
private int registrationId;
|
|
||||||
|
|
||||||
public PreKeyEntity(int keyId, ECPublicKey publicKey, IdentityKey identityKey) {
|
public PreKeyEntity(int keyId, ECPublicKey publicKey, IdentityKey identityKey) {
|
||||||
this.keyId = keyId;
|
this.keyId = keyId;
|
||||||
this.publicKey = publicKey;
|
this.publicKey = publicKey;
|
||||||
this.identityKey = identityKey;
|
this.identityKey = identityKey;
|
||||||
this.registrationId = registrationId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDeviceId() {
|
public int getDeviceId() {
|
||||||
|
@ -22,6 +22,7 @@ public class TextSecurePreKeyStore implements PreKeyStore {
|
|||||||
|
|
||||||
public static final String PREKEY_DIRECTORY = "prekeys";
|
public static final String PREKEY_DIRECTORY = "prekeys";
|
||||||
private static final int CURRENT_VERSION_MARKER = 1;
|
private static final int CURRENT_VERSION_MARKER = 1;
|
||||||
|
private static final Object FILE_LOCK = new Object();
|
||||||
private static final String TAG = TextSecurePreKeyStore.class.getSimpleName();
|
private static final String TAG = TextSecurePreKeyStore.class.getSimpleName();
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
@ -34,6 +35,7 @@ public class TextSecurePreKeyStore implements PreKeyStore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PreKeyRecord load(int preKeyId) throws InvalidKeyIdException {
|
public PreKeyRecord load(int preKeyId) throws InvalidKeyIdException {
|
||||||
|
synchronized (FILE_LOCK) {
|
||||||
try {
|
try {
|
||||||
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
||||||
FileInputStream fin = new FileInputStream(getPreKeyFile(preKeyId));
|
FileInputStream fin = new FileInputStream(getPreKeyFile(preKeyId));
|
||||||
@ -51,9 +53,11 @@ public class TextSecurePreKeyStore implements PreKeyStore {
|
|||||||
throw new InvalidKeyIdException(e);
|
throw new InvalidKeyIdException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void store(int preKeyId, PreKeyRecord record) {
|
public void store(int preKeyId, PreKeyRecord record) {
|
||||||
|
synchronized (FILE_LOCK) {
|
||||||
try {
|
try {
|
||||||
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
||||||
RandomAccessFile recordFile = new RandomAccessFile(getPreKeyFile(preKeyId), "rw");
|
RandomAccessFile recordFile = new RandomAccessFile(getPreKeyFile(preKeyId), "rw");
|
||||||
@ -69,6 +73,7 @@ public class TextSecurePreKeyStore implements PreKeyStore {
|
|||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(int preKeyId) {
|
public boolean contains(int preKeyId) {
|
||||||
|
@ -74,6 +74,7 @@ public class TextSecureSessionStore implements SessionStore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void store(long recipientId, int deviceId, SessionRecord record) {
|
public void store(long recipientId, int deviceId, SessionRecord record) {
|
||||||
|
synchronized (FILE_LOCK) {
|
||||||
try {
|
try {
|
||||||
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
MasterCipher masterCipher = new MasterCipher(masterSecret);
|
||||||
RandomAccessFile sessionFile = new RandomAccessFile(getSessionFile(recipientId, deviceId), "rw");
|
RandomAccessFile sessionFile = new RandomAccessFile(getSessionFile(recipientId, deviceId), "rw");
|
||||||
@ -89,6 +90,7 @@ public class TextSecureSessionStore implements SessionStore {
|
|||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean contains(long recipientId, int deviceId) {
|
public boolean contains(long recipientId, int deviceId) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user