From 744bbe6ad716e5f16e61f47bbfd9af0f7e62a957 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Sun, 3 Mar 2019 23:39:55 -0500 Subject: [PATCH 1/3] Use class name instead of NetworkEnvelope in messageTimeStamps - NetworkEnvelope was only used to print the class name if we exceed throttle limits. Should reduce memory footprint --- .../main/java/bisq/network/p2p/network/Connection.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/p2p/src/main/java/bisq/network/p2p/network/Connection.java b/p2p/src/main/java/bisq/network/p2p/network/Connection.java index 16c1758f992..b4bce206c54 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -148,7 +148,7 @@ public static int getPermittedMessageSize() { private volatile boolean stopped; private PeerType peerType; private final ObjectProperty peersNodeAddressProperty = new SimpleObjectProperty<>(); - private final List> messageTimeStamps = new ArrayList<>(); + private final List> messageTimeStamps = new ArrayList<>(); private final CopyOnWriteArraySet messageListeners = new CopyOnWriteArraySet<>(); private volatile long lastSendTimeStamp = 0; private final CopyOnWriteArraySet> capabilitiesListeners = new CopyOnWriteArraySet<>(); @@ -358,7 +358,7 @@ private boolean violatesThrottleLimit(NetworkEnvelope networkEnvelope) { log.error("violatesThrottleLimit MSG_THROTTLE_PER_SEC "); log.error("elapsed " + (now - compareValue)); log.error("messageTimeStamps: \n\t" + messageTimeStamps.stream() - .map(e -> "\n\tts=" + e.first.toString() + " message=" + e.second.getClass().getName()) + .map(e -> "\n\tts=" + e.first.toString() + " message=" + e.second) .collect(Collectors.toList()).toString()); } } @@ -374,7 +374,7 @@ private boolean violatesThrottleLimit(NetworkEnvelope networkEnvelope) { log.error("violatesThrottleLimit MSG_THROTTLE_PER_10_SEC "); log.error("elapsed " + (now - compareValue)); log.error("messageTimeStamps: \n\t" + messageTimeStamps.stream() - .map(e -> "\n\tts=" + e.first.toString() + " message=" + e.second.getClass().getName()) + .map(e -> "\n\tts=" + e.first.toString() + " message=" + e.second) .collect(Collectors.toList()).toString()); } } @@ -383,7 +383,7 @@ private boolean violatesThrottleLimit(NetworkEnvelope networkEnvelope) { while(messageTimeStamps.size() > MSG_THROTTLE_PER_10_SEC) messageTimeStamps.remove(0); - messageTimeStamps.add(new Tuple2<>(now, networkEnvelope)); + messageTimeStamps.add(new Tuple2<>(now, networkEnvelope.getClass().getName())); return violated; } From c65decfeafe4e1366edf28b1f39ab99a236951fd Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 4 Mar 2019 00:57:29 -0500 Subject: [PATCH 2/3] Add prog args for connection parameters - Add program args: msgThrottlePerSec, msgThrottlePer10Sec, sendMsgThrottleTrigger and sendMsgThrottleSleep - Add ConnectionConfig class with static injected field in Connection - Cleanups --- .../java/bisq/core/app/BisqEnvironment.java | 29 ++++++-- .../java/bisq/core/app/BisqExecutable.java | 22 ++++++ .../java/bisq/network/NetworkOptionKeys.java | 4 ++ .../main/java/bisq/network/p2p/P2PModule.java | 14 +++- .../bisq/network/p2p/network/Connection.java | 66 +++++++++++------- .../network/p2p/network/ConnectionConfig.java | 68 +++++++++++++++++++ 6 files changed, 168 insertions(+), 35 deletions(-) create mode 100644 p2p/src/main/java/bisq/network/p2p/network/ConnectionConfig.java diff --git a/core/src/main/java/bisq/core/app/BisqEnvironment.java b/core/src/main/java/bisq/core/app/BisqEnvironment.java index 9a3ca198c4f..93404405a2c 100644 --- a/core/src/main/java/bisq/core/app/BisqEnvironment.java +++ b/core/src/main/java/bisq/core/app/BisqEnvironment.java @@ -25,6 +25,7 @@ import bisq.core.filter.FilterManager; import bisq.network.NetworkOptionKeys; +import bisq.network.p2p.network.ConnectionConfig; import bisq.common.CommonOptionKeys; import bisq.common.app.Version; @@ -193,7 +194,8 @@ public static boolean isDaoActivated(Environment environment) { rpcPort, rpcBlockNotificationPort, dumpBlockchainData, fullDaoNode, myAddress, banList, dumpStatistics, maxMemory, socks5ProxyBtcAddress, torRcFile, torRcOptions, externalTorControlPort, externalTorPassword, externalTorCookieFile, - socks5ProxyHttpAddress, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, referralId, daoActivated; + socks5ProxyHttpAddress, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, + referralId, daoActivated, msgThrottlePerSec, msgThrottlePer10Sec, sendMsgThrottleTrigger, sendMsgThrottleSleep; protected final boolean externalTorUseSafeCookieAuthentication, torStreamIsolation; @@ -283,12 +285,20 @@ public BisqEnvironment(PropertySource commandLineProperties) { externalTorCookieFile = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE) ? (String) commandLineProperties.getProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE) : ""; - externalTorUseSafeCookieAuthentication = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE) ? - true : - false; - torStreamIsolation = commandLineProperties.containsProperty(NetworkOptionKeys.TOR_STREAM_ISOLATION) ? - true : - false; + externalTorUseSafeCookieAuthentication = commandLineProperties.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE); + torStreamIsolation = commandLineProperties.containsProperty(NetworkOptionKeys.TOR_STREAM_ISOLATION); + msgThrottlePerSec = commandLineProperties.containsProperty(NetworkOptionKeys.MSG_THROTTLE_PER_SEC) ? + (String) commandLineProperties.getProperty(NetworkOptionKeys.MSG_THROTTLE_PER_SEC) : + String.valueOf(ConnectionConfig.MSG_THROTTLE_PER_SEC); + msgThrottlePer10Sec = commandLineProperties.containsProperty(NetworkOptionKeys.MSG_THROTTLE_PER_10_SEC) ? + (String) commandLineProperties.getProperty(NetworkOptionKeys.MSG_THROTTLE_PER_10_SEC) : + String.valueOf(ConnectionConfig.MSG_THROTTLE_PER_10_SEC); + sendMsgThrottleTrigger = commandLineProperties.containsProperty(NetworkOptionKeys.SEND_MSG_THROTTLE_TRIGGER) ? + (String) commandLineProperties.getProperty(NetworkOptionKeys.SEND_MSG_THROTTLE_TRIGGER) : + String.valueOf(ConnectionConfig.SEND_MSG_THROTTLE_TRIGGER); + sendMsgThrottleSleep = commandLineProperties.containsProperty(NetworkOptionKeys.SEND_MSG_THROTTLE_SLEEP) ? + (String) commandLineProperties.getProperty(NetworkOptionKeys.SEND_MSG_THROTTLE_SLEEP) : + String.valueOf(ConnectionConfig.SEND_MSG_THROTTLE_SLEEP); //RpcOptionKeys rpcUser = commandLineProperties.containsProperty(DaoOptionKeys.RPC_USER) ? @@ -467,6 +477,11 @@ private PropertySource defaultProperties() { if (torStreamIsolation) setProperty(NetworkOptionKeys.TOR_STREAM_ISOLATION, "true"); + setProperty(NetworkOptionKeys.MSG_THROTTLE_PER_SEC, msgThrottlePerSec); + setProperty(NetworkOptionKeys.MSG_THROTTLE_PER_10_SEC, msgThrottlePer10Sec); + setProperty(NetworkOptionKeys.SEND_MSG_THROTTLE_TRIGGER, sendMsgThrottleTrigger); + setProperty(NetworkOptionKeys.SEND_MSG_THROTTLE_SLEEP, sendMsgThrottleSleep); + setProperty(AppOptionKeys.APP_DATA_DIR_KEY, appDataDir); setProperty(AppOptionKeys.DESKTOP_WITH_HTTP_API, desktopWithHttpApi); setProperty(AppOptionKeys.DESKTOP_WITH_GRPC_API, desktopWithGrpcApi); diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index 79817d835b5..9f4b5f6ac34 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -33,6 +33,7 @@ import bisq.network.NetworkOptionKeys; import bisq.network.p2p.P2PService; +import bisq.network.p2p.network.ConnectionConfig; import bisq.common.CommonOptionKeys; import bisq.common.UserThread; @@ -416,6 +417,27 @@ protected void customizeOptionParsing(OptionParser parser) { parser.accepts(NetworkOptionKeys.TOR_STREAM_ISOLATION, "Use stream isolation for Tor [experimental!]."); + parser.accepts(NetworkOptionKeys.MSG_THROTTLE_PER_SEC, + format("Message throttle per sec for connection class (default: %s)", + String.valueOf(ConnectionConfig.MSG_THROTTLE_PER_SEC))) + .withRequiredArg() + .ofType(int.class); + parser.accepts(NetworkOptionKeys.MSG_THROTTLE_PER_10_SEC, + format("Message throttle per 10 sec for connection class (default: %s)", + String.valueOf(ConnectionConfig.MSG_THROTTLE_PER_10_SEC))) + .withRequiredArg() + .ofType(int.class); + parser.accepts(NetworkOptionKeys.SEND_MSG_THROTTLE_TRIGGER, + format("Time in ms when we trigger a sleep if 2 messages are sent (default: %s)", + String.valueOf(ConnectionConfig.SEND_MSG_THROTTLE_TRIGGER))) + .withRequiredArg() + .ofType(int.class); + parser.accepts(NetworkOptionKeys.SEND_MSG_THROTTLE_SLEEP, + format("Pause in ms to sleep if we get too many messages to send (default: %s)", + String.valueOf(ConnectionConfig.SEND_MSG_THROTTLE_SLEEP))) + .withRequiredArg() + .ofType(int.class); + //AppOptionKeys parser.accepts(AppOptionKeys.USER_DATA_DIR_KEY, format("User data directory (default: %s)", BisqEnvironment.DEFAULT_USER_DATA_DIR)) diff --git a/p2p/src/main/java/bisq/network/NetworkOptionKeys.java b/p2p/src/main/java/bisq/network/NetworkOptionKeys.java index f2c96ea73f5..765a5c6b8a0 100644 --- a/p2p/src/main/java/bisq/network/NetworkOptionKeys.java +++ b/p2p/src/main/java/bisq/network/NetworkOptionKeys.java @@ -36,4 +36,8 @@ public class NetworkOptionKeys { public static final String EXTERNAL_TOR_COOKIE_FILE = "torControlCookieFile"; public static final String EXTERNAL_TOR_USE_SAFECOOKIE = "torControlUseSafeCookieAuth"; public static final String TOR_STREAM_ISOLATION = "torStreamIsolation"; + public static final String MSG_THROTTLE_PER_SEC = "msgThrottlePerSec"; + public static final String MSG_THROTTLE_PER_10_SEC = "msgThrottlePer10Sec"; + public static final String SEND_MSG_THROTTLE_TRIGGER = "sendMsgThrottleTrigger"; + public static final String SEND_MSG_THROTTLE_SLEEP = "sendMsgThrottleSleep"; } diff --git a/p2p/src/main/java/bisq/network/p2p/P2PModule.java b/p2p/src/main/java/bisq/network/p2p/P2PModule.java index ad25aa28ef1..e94260d9b82 100644 --- a/p2p/src/main/java/bisq/network/p2p/P2PModule.java +++ b/p2p/src/main/java/bisq/network/p2p/P2PModule.java @@ -19,6 +19,8 @@ import bisq.network.NetworkOptionKeys; import bisq.network.Socks5ProxyProvider; +import bisq.network.p2p.network.Connection; +import bisq.network.p2p.network.ConnectionConfig; import bisq.network.p2p.network.NetworkNode; import bisq.network.p2p.peers.BanList; import bisq.network.p2p.peers.Broadcaster; @@ -64,10 +66,12 @@ protected void configure() { bind(KeepAliveManager.class).in(Singleton.class); bind(Broadcaster.class).in(Singleton.class); bind(BanList.class).in(Singleton.class); + bind(ConnectionConfig.class).in(Singleton.class); bind(NetworkNode.class).toProvider(NetworkNodeProvider.class).in(Singleton.class); - bind(Socks5ProxyProvider.class).in(Singleton.class); + requestStaticInjection(Connection.class); + Boolean useLocalhostForP2P = environment.getProperty(NetworkOptionKeys.USE_LOCALHOST_FOR_P2P, boolean.class, false); bind(boolean.class).annotatedWith(Names.named(NetworkOptionKeys.USE_LOCALHOST_FOR_P2P)).toInstance(useLocalhostForP2P); @@ -93,7 +97,11 @@ protected void configure() { bindConstant().annotatedWith(named(NetworkOptionKeys.EXTERNAL_TOR_CONTROL_PORT)).to(environment.getRequiredProperty(NetworkOptionKeys.EXTERNAL_TOR_CONTROL_PORT)); bindConstant().annotatedWith(named(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD)).to(environment.getRequiredProperty(NetworkOptionKeys.EXTERNAL_TOR_PASSWORD)); bindConstant().annotatedWith(named(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE)).to(environment.getRequiredProperty(NetworkOptionKeys.EXTERNAL_TOR_COOKIE_FILE)); - bindConstant().annotatedWith(named(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE)).to(environment.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE) ? true : false); - bindConstant().annotatedWith(named(NetworkOptionKeys.TOR_STREAM_ISOLATION)).to(environment.containsProperty(NetworkOptionKeys.TOR_STREAM_ISOLATION) ? true : false); + bindConstant().annotatedWith(named(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE)).to(environment.containsProperty(NetworkOptionKeys.EXTERNAL_TOR_USE_SAFECOOKIE)); + bindConstant().annotatedWith(named(NetworkOptionKeys.TOR_STREAM_ISOLATION)).to(environment.containsProperty(NetworkOptionKeys.TOR_STREAM_ISOLATION)); + bindConstant().annotatedWith(named(NetworkOptionKeys.MSG_THROTTLE_PER_SEC)).to(environment.getRequiredProperty(NetworkOptionKeys.MSG_THROTTLE_PER_SEC)); + bindConstant().annotatedWith(named(NetworkOptionKeys.MSG_THROTTLE_PER_10_SEC)).to(environment.getRequiredProperty(NetworkOptionKeys.MSG_THROTTLE_PER_10_SEC)); + bindConstant().annotatedWith(named(NetworkOptionKeys.SEND_MSG_THROTTLE_TRIGGER)).to(environment.getRequiredProperty(NetworkOptionKeys.SEND_MSG_THROTTLE_TRIGGER)); + bindConstant().annotatedWith(named(NetworkOptionKeys.SEND_MSG_THROTTLE_SLEEP)).to(environment.getRequiredProperty(NetworkOptionKeys.SEND_MSG_THROTTLE_SLEEP)); } } diff --git a/p2p/src/main/java/bisq/network/p2p/network/Connection.java b/p2p/src/main/java/bisq/network/p2p/network/Connection.java index b4bce206c54..480043689f8 100644 --- a/p2p/src/main/java/bisq/network/p2p/network/Connection.java +++ b/p2p/src/main/java/bisq/network/p2p/network/Connection.java @@ -48,6 +48,8 @@ import io.bisq.generated.protobuffer.PB; +import javax.inject.Inject; + import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.Uninterruptibles; @@ -113,18 +115,20 @@ public enum PeerType { // Static /////////////////////////////////////////////////////////////////////////////////////////// + @Inject + private static ConnectionConfig connectionConfig; + // Leaving some constants package-private for tests to know limits. static final int PERMITTED_MESSAGE_SIZE = 200 * 1024; // 200 kb static final int MAX_PERMITTED_MESSAGE_SIZE = 10 * 1024 * 1024; // 10 MB (425 offers resulted in about 660 kb, mailbox msg will add more to it) offer has usually 2 kb, mailbox 3kb. //TODO decrease limits again after testing - static final int MSG_THROTTLE_PER_SEC = 200; // With MAX_MSG_SIZE of 200kb results in bandwidth of 40MB/sec or 5 mbit/sec - static final int MSG_THROTTLE_PER_10_SEC = 1000; // With MAX_MSG_SIZE of 200kb results in bandwidth of 20MB/sec or 2.5 mbit/sec private static final int SOCKET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(120); public static int getPermittedMessageSize() { return PERMITTED_MESSAGE_SIZE; } + /////////////////////////////////////////////////////////////////////////////////////////// // Class fields /////////////////////////////////////////////////////////////////////////////////////////// @@ -138,6 +142,10 @@ public static int getPermittedMessageSize() { // holder of state shared between InputHandler and Connection private final SharedModel sharedModel; private final Statistic statistic; + private final int msgThrottlePer10Sec; + private final int msgThrottlePerSec; + private final int sendMsgThrottleTrigger; + private final int sendMsgThrottleSleep; // set in init private InputHandler inputHandler; @@ -158,13 +166,21 @@ public static int getPermittedMessageSize() { // Constructor /////////////////////////////////////////////////////////////////////////////////////////// - Connection(Socket socket, MessageListener messageListener, ConnectionListener connectionListener, - @Nullable NodeAddress peersNodeAddress, NetworkProtoResolver networkProtoResolver) { + Connection(Socket socket, + MessageListener messageListener, + ConnectionListener connectionListener, + @Nullable NodeAddress peersNodeAddress, + NetworkProtoResolver networkProtoResolver) { this.socket = socket; this.connectionListener = connectionListener; uid = UUID.randomUUID().toString(); statistic = new Statistic(); + msgThrottlePerSec = connectionConfig.getMsgThrottlePerSec(); + msgThrottlePer10Sec = connectionConfig.getMsgThrottlePer10Sec(); + sendMsgThrottleTrigger = connectionConfig.getSendMsgThrottleTrigger(); + sendMsgThrottleSleep = connectionConfig.getSendMsgThrottleSleep(); + addMessageListener(messageListener); sharedModel = new SharedModel(this, socket); @@ -200,7 +216,6 @@ private void init(@Nullable NodeAddress peersNodeAddress, NetworkProtoResolver n log.trace("New connection created: " + this.toString()); UserThread.execute(() -> connectionListener.onConnection(this)); - } catch (Throwable e) { handleException(e); } @@ -228,15 +243,16 @@ public void sendMessage(NetworkEnvelope networkEnvelope) { // Throttle outbound network_messages long now = System.currentTimeMillis(); long elapsed = now - lastSendTimeStamp; - if (elapsed < 20) { - log.debug("We got 2 sendMessage requests in less than 20 ms. We set the thread to sleep " + - "for 50 ms to avoid flooding our peer. lastSendTimeStamp={}, now={}, elapsed={}", - lastSendTimeStamp, now, elapsed); - Thread.sleep(50); + if (elapsed < sendMsgThrottleTrigger) { + log.warn("We got 2 sendMessage requests in less than {} ms. We set the thread to sleep " + + "for {} ms to avoid flooding our peer. lastSendTimeStamp={}, now={}, elapsed={}, networkEnvelope={}", + sendMsgThrottleTrigger, sendMsgThrottleSleep, lastSendTimeStamp, now, elapsed, + networkEnvelope.getClass().getSimpleName()); + Thread.sleep(sendMsgThrottleSleep); } lastSendTimeStamp = now; - String peersNodeAddress = peersNodeAddressOptional.isPresent() ? peersNodeAddressOptional.get().toString() : "null"; + String peersNodeAddress = peersNodeAddressOptional.map(NodeAddress::toString).orElse("null"); PB.NetworkEnvelope proto = networkEnvelope.toProtoNetworkEnvelope(); log.debug("Sending message: {}", Utilities.toTruncatedString(proto.toString(), 10000)); @@ -349,9 +365,9 @@ private boolean violatesThrottleLimit(NetworkEnvelope networkEnvelope) { long now = System.currentTimeMillis(); boolean violated = false; //TODO remove message storage after network is tested stable - if (messageTimeStamps.size() >= MSG_THROTTLE_PER_SEC) { + if (messageTimeStamps.size() >= msgThrottlePerSec) { // check if we got more than 200 (MSG_THROTTLE_PER_SEC) msg per sec. - long compareValue = messageTimeStamps.get(messageTimeStamps.size() - MSG_THROTTLE_PER_SEC).first; + long compareValue = messageTimeStamps.get(messageTimeStamps.size() - msgThrottlePerSec).first; // if duration < 1 sec we received too much network_messages violated = now - compareValue < TimeUnit.SECONDS.toMillis(1); if (violated) { @@ -363,10 +379,10 @@ private boolean violatesThrottleLimit(NetworkEnvelope networkEnvelope) { } } - if (messageTimeStamps.size() >= MSG_THROTTLE_PER_10_SEC) { + if (messageTimeStamps.size() >= msgThrottlePer10Sec) { if (!violated) { // check if we got more than 50 msg per 10 sec. - long compareValue = messageTimeStamps.get(messageTimeStamps.size() - MSG_THROTTLE_PER_10_SEC).first; + long compareValue = messageTimeStamps.get(messageTimeStamps.size() - msgThrottlePer10Sec).first; // if duration < 10 sec we received too much network_messages violated = now - compareValue < TimeUnit.SECONDS.toMillis(10); @@ -380,7 +396,7 @@ private boolean violatesThrottleLimit(NetworkEnvelope networkEnvelope) { } } // we limit to max 1000 (MSG_THROTTLE_PER_10SEC) entries - while(messageTimeStamps.size() > MSG_THROTTLE_PER_10_SEC) + while (messageTimeStamps.size() > msgThrottlePer10Sec) messageTimeStamps.remove(0); messageTimeStamps.add(new Tuple2<>(now, networkEnvelope.getClass().getName())); @@ -395,7 +411,7 @@ private boolean violatesThrottleLimit(NetworkEnvelope networkEnvelope) { @Override public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) { checkArgument(connection.equals(this)); - UserThread.execute(() -> messageListeners.stream().forEach(e -> e.onMessage(networkEnvelope, connection))); + UserThread.execute(() -> messageListeners.forEach(e -> e.onMessage(networkEnvelope, connection))); } @@ -478,7 +494,7 @@ public void shutDown(CloseConnectionReason closeConnectionReason) { public void shutDown(CloseConnectionReason closeConnectionReason, @Nullable Runnable shutDownCompleteHandler) { log.debug("shutDown: nodeAddressOpt={}, closeConnectionReason={}", this.peersNodeAddressOptional, closeConnectionReason); if (!stopped) { - String peersNodeAddress = peersNodeAddressOptional.isPresent() ? peersNodeAddressOptional.get().toString() : "null"; + String peersNodeAddress = peersNodeAddressOptional.map(NodeAddress::toString).orElse("null"); log.debug("\n\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n" + "ShutDown connection:" + "\npeersNodeAddress=" + peersNodeAddress @@ -606,7 +622,7 @@ private static class SharedModel { private List supportedCapabilities; - public SharedModel(Connection connection, Socket socket) { + SharedModel(Connection connection, Socket socket) { this.connection = connection; this.socket = socket; } @@ -704,7 +720,7 @@ public void stop() { stopped = true; } - public RuleViolation getRuleViolation() { + RuleViolation getRuleViolation() { return ruleViolation; } @@ -743,11 +759,11 @@ private static class InputHandler implements Runnable { private long lastReadTimeStamp; private boolean threadNameSet; - public InputHandler(SharedModel sharedModel, - InputStream protoInputStream, - String portInfo, - MessageListener messageListener, - NetworkProtoResolver networkProtoResolver) { + InputHandler(SharedModel sharedModel, + InputStream protoInputStream, + String portInfo, + MessageListener messageListener, + NetworkProtoResolver networkProtoResolver) { this.sharedModel = sharedModel; this.protoInputStream = protoInputStream; this.portInfo = portInfo; diff --git a/p2p/src/main/java/bisq/network/p2p/network/ConnectionConfig.java b/p2p/src/main/java/bisq/network/p2p/network/ConnectionConfig.java new file mode 100644 index 00000000000..abf77d7a3a4 --- /dev/null +++ b/p2p/src/main/java/bisq/network/p2p/network/ConnectionConfig.java @@ -0,0 +1,68 @@ +/* + * This file is part of Bisq. + * + * Bisq 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. + * + * Bisq 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 Bisq. If not, see . + */ + +package bisq.network.p2p.network; + +import bisq.network.NetworkOptionKeys; + +import com.google.inject.name.Named; + +import javax.inject.Inject; + +import lombok.Getter; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class ConnectionConfig { + public static final int MSG_THROTTLE_PER_SEC = 200; // With MAX_MSG_SIZE of 200kb results in bandwidth of 40MB/sec or 5 mbit/sec + public static final int MSG_THROTTLE_PER_10_SEC = 1000; // With MAX_MSG_SIZE of 200kb results in bandwidth of 20MB/sec or 2.5 mbit/sec + public static final int SEND_MSG_THROTTLE_TRIGGER = 20; // Time in ms when we trigger a sleep if 2 messages are sent + public static final int SEND_MSG_THROTTLE_SLEEP = 50; // Pause in ms to sleep if we get too many messages to send + + @Getter + private int msgThrottlePerSec; + @Getter + private int msgThrottlePer10Sec; + @Getter + private int sendMsgThrottleTrigger; + @Getter + private int sendMsgThrottleSleep; + + @Inject + public ConnectionConfig(@Named(NetworkOptionKeys.MSG_THROTTLE_PER_SEC) int msgThrottlePerSec, + @Named(NetworkOptionKeys.MSG_THROTTLE_PER_10_SEC) int msgThrottlePer10Sec, + @Named(NetworkOptionKeys.SEND_MSG_THROTTLE_TRIGGER) int sendMsgThrottleTrigger, + @Named(NetworkOptionKeys.SEND_MSG_THROTTLE_SLEEP) int sendMsgThrottleSleep) { + this.msgThrottlePerSec = msgThrottlePerSec; + this.msgThrottlePer10Sec = msgThrottlePer10Sec; + this.sendMsgThrottleTrigger = sendMsgThrottleTrigger; + this.sendMsgThrottleSleep = sendMsgThrottleSleep; + + log.info(this.toString()); + } + + + @Override + public String toString() { + return "ConnectionConfig{" + + "\n msgThrottlePerSec=" + msgThrottlePerSec + + ",\n msgThrottlePer10Sec=" + msgThrottlePer10Sec + + ",\n sendMsgThrottleTrigger=" + sendMsgThrottleTrigger + + ",\n sendMsgThrottleSleep=" + sendMsgThrottleSleep + + "\n}"; + } +} From 4c4084cf6daa06a7534704244782c99ff598c1e5 Mon Sep 17 00:00:00 2001 From: Manfred Karrer Date: Mon, 4 Mar 2019 01:45:40 -0500 Subject: [PATCH 3/3] Increase offer TTL and decrease refresh interval - We get about 300 refresh msg / min. That causes quite a bit of load for the network. I think it is safe to increase TTL from 7 to 9 minutes and change REFRESH_INTERVAL from 5 to 6 min. and REPUBLISH_INTERVAL from 30 to 40 min. --- core/src/main/java/bisq/core/offer/OfferPayload.java | 2 +- core/src/main/java/bisq/core/offer/OpenOfferManager.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/OfferPayload.java b/core/src/main/java/bisq/core/offer/OfferPayload.java index 9480ee7ea5d..eb7e37cb030 100644 --- a/core/src/main/java/bisq/core/offer/OfferPayload.java +++ b/core/src/main/java/bisq/core/offer/OfferPayload.java @@ -356,7 +356,7 @@ public static OfferPayload fromProto(PB.OfferPayload proto) { @Override public long getTTL() { - return TimeUnit.MINUTES.toMillis(7); + return TimeUnit.MINUTES.toMillis(9); } @Override diff --git a/core/src/main/java/bisq/core/offer/OpenOfferManager.java b/core/src/main/java/bisq/core/offer/OpenOfferManager.java index 695dc018474..96e4c3c126c 100644 --- a/core/src/main/java/bisq/core/offer/OpenOfferManager.java +++ b/core/src/main/java/bisq/core/offer/OpenOfferManager.java @@ -90,8 +90,8 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe private static final long RETRY_REPUBLISH_DELAY_SEC = 10; private static final long REPUBLISH_AGAIN_AT_STARTUP_DELAY_SEC = 30; - private static final long REPUBLISH_INTERVAL_MS = TimeUnit.MINUTES.toMillis(30); - private static final long REFRESH_INTERVAL_MS = TimeUnit.MINUTES.toMillis(5); + private static final long REPUBLISH_INTERVAL_MS = TimeUnit.MINUTES.toMillis(40); + private static final long REFRESH_INTERVAL_MS = TimeUnit.MINUTES.toMillis(6); private final KeyRing keyRing; private final User user;