update p2p connection and message packages

remove inventor and monitor packages

Co-authored-by: Alva Swanson <alvasw@protonmail.com>
Co-authored-by: Alejandro García <117378669+alejandrogarcia83@users.noreply.github.com>
Co-authored-by: jmacxx <47253594+jmacxx@users.noreply.github.com>
Co-authored-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
woodser 2023-04-24 22:41:10 -04:00
parent 0f41c8d8b8
commit e0db4528da
79 changed files with 1332 additions and 5327 deletions

View file

@ -30,8 +30,8 @@ import haveno.common.file.FileUtil;
import haveno.common.handlers.ResultHandler;
import haveno.common.proto.persistable.PersistableEnvelope;
import haveno.common.proto.persistable.PersistenceProtoResolver;
import haveno.common.util.SingleThreadExecutorUtils;
import haveno.common.util.GcUtil;
import haveno.common.util.Utilities;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@ -86,8 +86,8 @@ public class PersistenceManager<T extends PersistableEnvelope> {
allServicesInitialized.set(true);
ALL_PERSISTENCE_MANAGERS.values().forEach(persistenceManager -> {
// In case we got a requestPersistence call before we got initialized we trigger the timer for the
// persist call
// In case we got a requestPersistence call before we got initialized we trigger
// the timer for the persist call
if (persistenceManager.persistenceRequested) {
persistenceManager.maybeStartTimerForPersistence();
}
@ -178,7 +178,6 @@ public class PersistenceManager<T extends PersistableEnvelope> {
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Enum
///////////////////////////////////////////////////////////////////////////////////////////
@ -193,7 +192,6 @@ public class PersistenceManager<T extends PersistableEnvelope> {
// For data stores which are created from private local data. Loss of that data would not have critical consequences.
PRIVATE_LOW_PRIO(4, TimeUnit.MINUTES.toMillis(1), false);
@Getter
private final int numMaxBackupFiles;
@Getter
@ -230,7 +228,6 @@ public class PersistenceManager<T extends PersistableEnvelope> {
public final AtomicBoolean initCalled = new AtomicBoolean(false);
public final AtomicBoolean readCalled = new AtomicBoolean(false);
///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
@ -297,7 +294,6 @@ public class PersistenceManager<T extends PersistableEnvelope> {
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// Reading file
///////////////////////////////////////////////////////////////////////////////////////////
@ -305,8 +301,8 @@ public class PersistenceManager<T extends PersistableEnvelope> {
/**
* Read persisted file in a thread.
*
* @param resultHandler Consumer of persisted data once it was read from disk.
* @param orElse Called if no file exists or reading of file failed.
* @param resultHandler Consumer of persisted data once it was read from disk.
* @param orElse Called if no file exists or reading of file failed.
*/
public void readPersisted(Consumer<T> resultHandler, Runnable orElse) {
readPersisted(checkNotNull(fileName), resultHandler, orElse);
@ -316,9 +312,9 @@ public class PersistenceManager<T extends PersistableEnvelope> {
* Read persisted file in a thread.
* We map result handler calls to UserThread, so clients don't need to worry about threading
*
* @param fileName File name of our persisted data.
* @param resultHandler Consumer of persisted data once it was read from disk.
* @param orElse Called if no file exists or reading of file failed.
* @param fileName File name of our persisted data.
* @param resultHandler Consumer of persisted data once it was read from disk.
* @param orElse Called if no file exists or reading of file failed.
*/
public void readPersisted(String fileName, Consumer<T> resultHandler, Runnable orElse) {
if (flushAtShutdownCalled) {
@ -404,7 +400,6 @@ public class PersistenceManager<T extends PersistableEnvelope> {
return null;
}
///////////////////////////////////////////////////////////////////////////////////////////
// Write file to disk
///////////////////////////////////////////////////////////////////////////////////////////
@ -415,11 +410,6 @@ public class PersistenceManager<T extends PersistableEnvelope> {
return;
}
if (!initCalled.get()) {
log.warn("requestPersistence() called before init. Ignoring request");
return;
}
persistenceRequested = true;
// If we have not initialized yet we postpone the start of the timer and call maybeStartTimerForPersistence at
@ -562,7 +552,7 @@ public class PersistenceManager<T extends PersistableEnvelope> {
private ExecutorService getWriteToDiskExecutor() {
if (writeToDiskExecutor == null) {
String name = "Write-" + fileName + "_to-disk";
writeToDiskExecutor = Utilities.getSingleThreadExecutor(name);
writeToDiskExecutor = SingleThreadExecutorUtils.getSingleThreadExecutor(name);
}
return writeToDiskExecutor;
}

View file

@ -0,0 +1,27 @@
/*
* This file is part of Haveno.
*
* Haveno is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Haveno is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Haveno. If not, see <http://www.gnu.org/licenses/>.
*/
package haveno.common.proto.network;
/**
* Represents priority used at truncating data set at getDataResponse if total data exceeds limits.
*/
public enum GetDataResponsePriority {
LOW,
MID,
HIGH
}

View file

@ -50,7 +50,6 @@ public abstract class NetworkEnvelope implements Envelope {
return getNetworkEnvelopeBuilder().build();
}
///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////

View file

@ -23,4 +23,7 @@ import haveno.common.Payload;
* Interface for objects used inside WireEnvelope or other WirePayloads.
*/
public interface NetworkPayload extends Payload {
default GetDataResponsePriority getGetDataResponsePriority() {
return GetDataResponsePriority.LOW;
}
}

View file

@ -0,0 +1,62 @@
/*
* This file is part of Haveno.
*
* Haveno is free software: you can redistribute it and/or modify it
* under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at
* your option) any later version.
*
* Haveno is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
* License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Haveno. If not, see <http://www.gnu.org/licenses/>.
*/
package haveno.common.util;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadFactory;
public class SingleThreadExecutorUtils {
public static ExecutorService getSingleThreadExecutor(Class<?> aClass) {
String name = aClass.getSimpleName();
return getSingleThreadExecutor(name);
}
public static ExecutorService getNonDaemonSingleThreadExecutor(Class<?> aClass) {
String name = aClass.getSimpleName();
return getSingleThreadExecutor(name, false);
}
public static ExecutorService getSingleThreadExecutor(String name) {
return getSingleThreadExecutor(name, true);
}
public static ListeningExecutorService getSingleThreadListeningExecutor(String name) {
return MoreExecutors.listeningDecorator(getSingleThreadExecutor(name));
}
public static ExecutorService getSingleThreadExecutor(ThreadFactory threadFactory) {
return Executors.newSingleThreadExecutor(threadFactory);
}
private static ExecutorService getSingleThreadExecutor(String name, boolean isDaemonThread) {
final ThreadFactory threadFactory = getThreadFactory(name, isDaemonThread);
return Executors.newSingleThreadExecutor(threadFactory);
}
private static ThreadFactory getThreadFactory(String name, boolean isDaemonThread) {
return new ThreadFactoryBuilder()
.setNameFormat(name)
.setDaemon(isDaemonThread)
.build();
}
}

View file

@ -17,33 +17,37 @@
package haveno.common.util;
import org.bitcoinj.core.Utils;
import com.google.common.base.Splitter;
import com.google.common.primitives.Ints;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DurationFormatUtils;
import javafx.scene.input.Clipboard;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.KeyEvent;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DurationFormatUtils;
import org.bitcoinj.core.Utils;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.GregorianCalendar;
@ -59,7 +63,6 @@ import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
@ -68,92 +71,79 @@ import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@Slf4j
public class Utilities {
public static ExecutorService getSingleThreadExecutor(String name) {
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat(name)
.setDaemon(true)
.build();
return Executors.newSingleThreadExecutor(threadFactory);
}
public static ListeningExecutorService getSingleThreadListeningExecutor(String name) {
return MoreExecutors.listeningDecorator(getSingleThreadExecutor(name));
public static ExecutorService getFixedThreadPoolExecutor(int nThreads, ThreadFactory threadFactory) {
return Executors.newFixedThreadPool(nThreads, threadFactory);
}
public static ListeningExecutorService getListeningExecutorService(String name,
int corePoolSize,
int maximumPoolSize,
long keepAliveTimeInSec) {
return MoreExecutors.listeningDecorator(getThreadPoolExecutor(name, corePoolSize, maximumPoolSize, keepAliveTimeInSec));
int corePoolSize,
int maximumPoolSize,
long keepAliveTimeInSec) {
return getListeningExecutorService(name, corePoolSize, maximumPoolSize, maximumPoolSize, keepAliveTimeInSec);
}
public static ListeningExecutorService getListeningExecutorService(String name,
int corePoolSize,
int maximumPoolSize,
long keepAliveTimeInSec,
BlockingQueue<Runnable> workQueue) {
int corePoolSize,
int maximumPoolSize,
int queueCapacity,
long keepAliveTimeInSec) {
return MoreExecutors.listeningDecorator(getThreadPoolExecutor(name, corePoolSize, maximumPoolSize, queueCapacity, keepAliveTimeInSec));
}
public static ListeningExecutorService getListeningExecutorService(String name,
int corePoolSize,
int maximumPoolSize,
long keepAliveTimeInSec,
BlockingQueue<Runnable> workQueue) {
return MoreExecutors.listeningDecorator(getThreadPoolExecutor(name, corePoolSize, maximumPoolSize, keepAliveTimeInSec, workQueue));
}
public static ThreadPoolExecutor getThreadPoolExecutor(String name,
int corePoolSize,
int maximumPoolSize,
long keepAliveTimeInSec) {
int corePoolSize,
int maximumPoolSize,
long keepAliveTimeInSec) {
return getThreadPoolExecutor(name, corePoolSize, maximumPoolSize, maximumPoolSize, keepAliveTimeInSec);
}
public static ThreadPoolExecutor getThreadPoolExecutor(String name,
int corePoolSize,
int maximumPoolSize,
int queueCapacity,
long keepAliveTimeInSec) {
return getThreadPoolExecutor(name, corePoolSize, maximumPoolSize, keepAliveTimeInSec,
new ArrayBlockingQueue<>(maximumPoolSize));
new ArrayBlockingQueue<>(queueCapacity));
}
private static ThreadPoolExecutor getThreadPoolExecutor(String name,
int corePoolSize,
int maximumPoolSize,
long keepAliveTimeInSec,
BlockingQueue<Runnable> workQueue) {
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat(name)
int corePoolSize,
int maximumPoolSize,
long keepAliveTimeInSec,
BlockingQueue<Runnable> workQueue) {
ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat(name + "-%d")
.setDaemon(true)
.build();
ThreadPoolExecutor executor = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTimeInSec,
TimeUnit.SECONDS, workQueue, threadFactory);
executor.allowCoreThreadTimeOut(true);
executor.setRejectedExecutionHandler((r, e) -> log.debug("RejectedExecutionHandler called"));
return executor;
}
@SuppressWarnings("SameParameterValue")
public static ScheduledThreadPoolExecutor getScheduledThreadPoolExecutor(String name,
int corePoolSize,
int maximumPoolSize,
long keepAliveTimeInSec) {
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat(name)
.setDaemon(true)
.setPriority(Thread.MIN_PRIORITY)
.build();
ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(corePoolSize, threadFactory);
executor.setKeepAliveTime(keepAliveTimeInSec, TimeUnit.SECONDS);
executor.allowCoreThreadTimeOut(true);
executor.setMaximumPoolSize(maximumPoolSize);
executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
executor.setRejectedExecutionHandler((r, e) -> log.debug("RejectedExecutionHandler called"));
return executor;
}
// TODO: Can some/all of the uses of this be replaced by guava MoreExecutors.shutdownAndAwaitTermination(..)?
public static void shutdownAndAwaitTermination(ExecutorService executor, long timeout, TimeUnit unit) {
executor.shutdown();
try {
if (!executor.awaitTermination(timeout, unit)) {
executor.shutdownNow();
}
} catch (InterruptedException e) {
executor.shutdownNow();
}
// noinspection UnstableApiUsage
MoreExecutors.shutdownAndAwaitTermination(executor, timeout, unit);
}
public static <V> FutureCallback<V> failureCallback(Consumer<Throwable> errorHandler) {
@ -175,7 +165,7 @@ public class Utilities {
public static boolean isMacMenuBarDarkMode() {
try {
// check for exit status only. Once there are more modes than "dark" and "default", we might need to analyze string contents..
Process process = Runtime.getRuntime().exec(new String[]{"defaults", "read", "-g", "AppleInterfaceStyle"});
Process process = Runtime.getRuntime().exec(new String[] { "defaults", "read", "-g", "AppleInterfaceStyle" });
process.waitFor(100, TimeUnit.MILLISECONDS);
return process.exitValue() == 0;
} catch (IOException | InterruptedException | IllegalThreadStateException ex) {
@ -294,8 +284,7 @@ public class Utilities {
System.getProperty("os.arch"),
getJVMArchitecture(),
(System.getProperty("java.runtime.version", "-") + " (" + System.getProperty("java.vendor", "-") + ")"),
(System.getProperty("java.vm.version", "-") + " (" + System.getProperty("java.vm.name", "-") + ")")
);
(System.getProperty("java.vm.version", "-") + " (" + System.getProperty("java.vm.name", "-") + ")"));
}
public static String getJVMArchitecture() {
@ -438,7 +427,6 @@ public class Utilities {
if (message == null)
return "null";
String result = StringUtils.abbreviate(message.toString(), maxLength);
if (removeLineBreaks)
return result.replace("\n", "");