mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-07-27 00:45:23 -04:00
Use PopupManager for queuing popups, improve version handling, deactivate focus requests, add popup when getting disconnection because of version conflict
This commit is contained in:
parent
ba4a228fed
commit
a264fa4e0b
94 changed files with 421 additions and 288 deletions
|
@ -28,34 +28,46 @@ public class Version {
|
|||
|
||||
// The version nr. for the objects sent over the network. A change will break the serialization of old objects.
|
||||
// If objects are used for both network and database the network version is applied.
|
||||
public static final long NETWORK_PROTOCOL_VERSION = 2;
|
||||
public static final long P2P_NETWORK_VERSION = 1;
|
||||
|
||||
// The version nr. of the serialized data stored to disc. A change will break the serialization of old objects.
|
||||
public static final long LOCAL_DB_VERSION = 2;
|
||||
public static final long LOCAL_DB_VERSION = 1;
|
||||
|
||||
// The version nr. of the current protocol. The offer holds that version.
|
||||
// A taker will check the version of the offers to see if his version is compatible.
|
||||
// TODO not used yet
|
||||
public static final long PROTOCOL_VERSION = 1;
|
||||
public static final long TRADE_PROTOCOL_VERSION = 1;
|
||||
|
||||
// The version for the bitcoin network (Mainnet = 0, TestNet = 1, Regtest = 2)
|
||||
private static int NETWORK_ID;
|
||||
|
||||
public static int getNetworkId() {
|
||||
return NETWORK_ID;
|
||||
public static int getP2PMessageVersion() {
|
||||
// A changed NETWORK_PROTOCOL_VERSION for the serialized objects does not trigger reliable a disconnect.
|
||||
// TODO investigate why, but java serialisation should be replaced anyway, so using one existing field
|
||||
// for the version is fine.
|
||||
// BTC_NETWORK_ID is 0, 1 or 2, we use for changes at NETWORK_PROTOCOL_VERSION a multiplication with 10
|
||||
// to avoid conflicts:
|
||||
// E.g. btc BTC_NETWORK_ID=1, NETWORK_PROTOCOL_VERSION=1 -> getNetworkId()=2;
|
||||
// BTC_NETWORK_ID=0, NETWORK_PROTOCOL_VERSION=2 -> getNetworkId()=2; -> wrong
|
||||
return BTC_NETWORK_ID + 10 * (int) P2P_NETWORK_VERSION;
|
||||
}
|
||||
|
||||
public static void setNetworkId(int networkId) {
|
||||
NETWORK_ID = networkId;
|
||||
// The version for the bitcoin network (Mainnet = 0, TestNet = 1, Regtest = 2)
|
||||
private static int BTC_NETWORK_ID;
|
||||
|
||||
public static void setBtcNetworkId(int btcNetworkId) {
|
||||
BTC_NETWORK_ID = btcNetworkId;
|
||||
}
|
||||
|
||||
public static int getBtcNetworkId() {
|
||||
return BTC_NETWORK_ID;
|
||||
}
|
||||
|
||||
public static void printVersion() {
|
||||
log.info("Version{" +
|
||||
"VERSION=" + VERSION +
|
||||
", NETWORK_PROTOCOL_VERSION=" + NETWORK_PROTOCOL_VERSION +
|
||||
", P2P_NETWORK_VERSION=" + P2P_NETWORK_VERSION +
|
||||
", LOCAL_DB_VERSION=" + LOCAL_DB_VERSION +
|
||||
", PROTOCOL_VERSION=" + PROTOCOL_VERSION +
|
||||
", NETWORK_ID=" + NETWORK_ID +
|
||||
", TRADE_PROTOCOL_VERSION=" + TRADE_PROTOCOL_VERSION +
|
||||
", BTC_NETWORK_ID=" + BTC_NETWORK_ID +
|
||||
", getP2PNetworkId()=" + getP2PMessageVersion() +
|
||||
'}');
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import java.util.Arrays;
|
|||
|
||||
public class ByteArray implements Serializable {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
|
||||
|
||||
public final byte[] bytes;
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ import java.security.spec.X509EncodedKeySpec;
|
|||
*/
|
||||
public class PubKeyRing implements Serializable {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(PubKeyRing.class);
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.Arrays;
|
|||
|
||||
public final class SealedAndSigned implements Serializable {
|
||||
// That object is sent over the wire, so we need to take care of version compatibility.
|
||||
private static final long serialVersionUID = Version.NETWORK_PROTOCOL_VERSION;
|
||||
private static final long serialVersionUID = Version.P2P_NETWORK_VERSION;
|
||||
|
||||
public final byte[] encryptedSecretKey;
|
||||
public final byte[] encryptedPayloadWithHmac;
|
||||
|
|
|
@ -133,14 +133,14 @@ public class FileManager<T> {
|
|||
executor.schedule(saveFileTask, delayInMilli, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public synchronized T read(File file) {
|
||||
public synchronized T read(File file) throws IOException, ClassNotFoundException {
|
||||
log.debug("read" + file);
|
||||
try (final FileInputStream fileInputStream = new FileInputStream(file);
|
||||
final ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream)) {
|
||||
return (T) objectInputStream.readObject();
|
||||
} catch (Throwable t) {
|
||||
log.error("Exception at read: " + t.getMessage());
|
||||
return null;
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,12 +176,12 @@ public class FileManager<T> {
|
|||
}
|
||||
|
||||
public synchronized void removeAndBackupFile(String fileName) throws IOException {
|
||||
File corruptedBackupDir = new File(Paths.get(dir.getAbsolutePath(), "corrupted").toString());
|
||||
File corruptedBackupDir = new File(Paths.get(dir.getAbsolutePath(), "backup_of_corrupted_data").toString());
|
||||
if (!corruptedBackupDir.exists())
|
||||
if (!corruptedBackupDir.mkdir())
|
||||
log.warn("make dir failed");
|
||||
|
||||
File corruptedFile = new File(Paths.get(dir.getAbsolutePath(), "corrupted", fileName).toString());
|
||||
File corruptedFile = new File(Paths.get(dir.getAbsolutePath(), "backup_of_corrupted_data", fileName).toString());
|
||||
renameTempFileToFile(storageFile, corruptedFile);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package io.bitsquare.storage;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -158,23 +157,20 @@ public class Storage<T extends Serializable> {
|
|||
log.trace("Backup {} completed in {}msec", storageFile, System.currentTimeMillis() - now);
|
||||
|
||||
return persistedObject;
|
||||
} catch (ClassCastException | IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error("Version of persisted class has changed. We cannot read the persisted data anymore. We make a backup and remove the inconsistent " +
|
||||
"file.");
|
||||
} catch (Throwable t) {
|
||||
log.error("Version of persisted class has changed. We cannot read the persisted data anymore. " +
|
||||
"We make a backup and remove the inconsistent file.");
|
||||
log.error(t.getMessage());
|
||||
try {
|
||||
// In case the persisted data have been critical (keys) we keep a backup which might be used for recovery
|
||||
// We keep a backup which might be used for recovery
|
||||
fileManager.removeAndBackupFile(fileName);
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
log.error(e1.getMessage());
|
||||
// We swallow Exception if backup fails
|
||||
}
|
||||
databaseCorruptionHandler.onFileCorrupted(storageFile.getName());
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
log.error(throwable.getMessage());
|
||||
Throwables.propagate(throwable);
|
||||
if (databaseCorruptionHandler != null)
|
||||
databaseCorruptionHandler.onFileCorrupted(storageFile.getName());
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue