Skip to content

Commit

Permalink
update p2p connection and message packages
Browse files Browse the repository at this point in the history
remove inventor and monitor packages

Co-authored-by: Alva Swanson <[email protected]>
Co-authored-by: Alejandro García <[email protected]>
Co-authored-by: jmacxx <[email protected]>
Co-authored-by: HenrikJannsen <[email protected]>
  • Loading branch information
5 people committed Apr 26, 2023
1 parent 0f41c8d commit e0db452
Show file tree
Hide file tree
Showing 79 changed files with 1,323 additions and 5,318 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
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;

Expand Down Expand Up @@ -86,8 +86,8 @@ public static void onAllServicesInitialized() {
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();
}
Expand Down Expand Up @@ -178,7 +178,6 @@ private static void onWriteCompleted(ResultHandler completeHandler,
}
}


///////////////////////////////////////////////////////////////////////////////////////////
// Enum
///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -193,7 +192,6 @@ public enum Source {
// 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
Expand Down Expand Up @@ -230,7 +228,6 @@ public enum Source {
public final AtomicBoolean initCalled = new AtomicBoolean(false);
public final AtomicBoolean readCalled = new AtomicBoolean(false);


///////////////////////////////////////////////////////////////////////////////////////////
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -297,16 +294,15 @@ public void shutdown() {
}
}


///////////////////////////////////////////////////////////////////////////////////////////
// Reading file
///////////////////////////////////////////////////////////////////////////////////////////

/**
* 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);
Expand All @@ -316,9 +312,9 @@ public void readPersisted(Consumer<T> resultHandler, Runnable orElse) {
* 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) {
Expand Down Expand Up @@ -404,7 +400,6 @@ public T getPersisted(String fileName) {
return null;
}


///////////////////////////////////////////////////////////////////////////////////////////
// Write file to disk
///////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -415,11 +410,6 @@ public void requestPersistence() {
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
Expand Down Expand Up @@ -562,7 +552,7 @@ private void writeToDisk(protobuf.PersistableEnvelope serialized, @Nullable Runn
private ExecutorService getWriteToDiskExecutor() {
if (writeToDiskExecutor == null) {
String name = "Write-" + fileName + "_to-disk";
writeToDiskExecutor = Utilities.getSingleThreadExecutor(name);
writeToDiskExecutor = SingleThreadExecutorUtils.getSingleThreadExecutor(name);
}
return writeToDiskExecutor;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public protobuf.NetworkEnvelope toProtoNetworkEnvelope() {
return getNetworkEnvelopeBuilder().build();
}


///////////////////////////////////////////////////////////////////////////////////////////
// API
///////////////////////////////////////////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@
* Interface for objects used inside WireEnvelope or other WirePayloads.
*/
public interface NetworkPayload extends Payload {
default GetDataResponsePriority getGetDataResponsePriority() {
return GetDataResponsePriority.LOW;
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading

0 comments on commit e0db452

Please sign in to comment.