mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-19 23:36:00 -04:00
Avoid getting current time on each usage on flooding avoidance computations
Also fix some log message wording.
This commit is contained in:
parent
8f7f450429
commit
9b9fd678a8
@ -167,14 +167,16 @@ public class Connection implements MessageListener {
|
||||
try {
|
||||
Log.traceCall();
|
||||
// Throttle outbound messages
|
||||
if (System.currentTimeMillis() - lastSendTimeStamp < 20) {
|
||||
log.info("We got 2 sendMessage requests in less then 20 ms. We set the thread to sleep " +
|
||||
"for 50 ms to avoid that we flood our peer. lastSendTimeStamp={}, now={}, elapsed={}",
|
||||
lastSendTimeStamp, System.currentTimeMillis(), (System.currentTimeMillis() - lastSendTimeStamp));
|
||||
long now = System.currentTimeMillis();
|
||||
long elapsed = now - lastSendTimeStamp;
|
||||
if (elapsed < 20) {
|
||||
log.info("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);
|
||||
}
|
||||
|
||||
lastSendTimeStamp = System.currentTimeMillis();
|
||||
lastSendTimeStamp = now;
|
||||
String peersNodeAddress = peersNodeAddressOptional.isPresent() ? peersNodeAddressOptional.get().toString() : "null";
|
||||
int size = ByteArrayUtils.objectToByteArray(message).length;
|
||||
|
||||
@ -629,8 +631,8 @@ public class Connection implements MessageListener {
|
||||
long now = System.currentTimeMillis();
|
||||
long elapsed = now - lastReadTimeStamp;
|
||||
if (elapsed < 10) {
|
||||
log.info("We got 2 messages received in less then 10 ms. We set the thread to sleep " +
|
||||
"for 20 ms to avoid that we get flooded from our peer. lastReadTimeStamp={}, now={}, elapsed={}",
|
||||
log.info("We got 2 messages received in less than 10 ms. We set the thread to sleep " +
|
||||
"for 20 ms to avoid getting flooded by our peer. lastReadTimeStamp={}, now={}, elapsed={}",
|
||||
lastReadTimeStamp, now, elapsed);
|
||||
Thread.sleep(20);
|
||||
}
|
||||
@ -796,4 +798,4 @@ public class Connection implements MessageListener {
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user