mirror of
https://github.com/bisq-network/bisq.git
synced 2024-11-19 09:52:23 +01:00
Sketch of businesslogic regarding EnvelopeOfEnvelopes
This commit is contained in:
parent
16392f5f0a
commit
b101035d99
@ -32,5 +32,6 @@ public enum Capability {
|
||||
BLIND_VOTE,
|
||||
ACK_MSG,
|
||||
BSQ_BLOCK,
|
||||
DAO_STATE
|
||||
DAO_STATE,
|
||||
ENVELOPE_OF_ENVELOPES
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class CoreNetworkCapabilities {
|
||||
public static void setSupportedCapabilities(BisqEnvironment bisqEnvironment) {
|
||||
Capabilities.app.addAll(Capability.TRADE_STATISTICS, Capability.TRADE_STATISTICS_2, Capability.ACCOUNT_AGE_WITNESS, Capability.ACK_MSG);
|
||||
Capabilities.app.addAll(Capability.ENVELOPE_OF_ENVELOPES);
|
||||
|
||||
if (BisqEnvironment.isDaoActivated(bisqEnvironment)) {
|
||||
Capabilities.app.addAll(Capability.PROPOSAL, Capability.BLIND_VOTE, Capability.BSQ_BLOCK, Capability.DAO_STATE);
|
||||
|
@ -38,6 +38,7 @@ import bisq.network.p2p.storage.payload.ProtectedStoragePayload;
|
||||
import bisq.common.Proto;
|
||||
import bisq.common.UserThread;
|
||||
import bisq.common.app.Capabilities;
|
||||
import bisq.common.app.Capability;
|
||||
import bisq.common.app.HasCapabilities;
|
||||
import bisq.common.app.Version;
|
||||
import bisq.common.proto.ProtobufferException;
|
||||
@ -239,18 +240,6 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
|
||||
if (!stopped) {
|
||||
if (noCapabilityRequiredOrCapabilityIsSupported(networkEnvelope)) {
|
||||
try {
|
||||
// Throttle outbound network_messages
|
||||
long now = System.currentTimeMillis();
|
||||
long elapsed = now - lastSendTimeStamp;
|
||||
if (elapsed < sendMsgThrottleTrigger) {
|
||||
log.debug("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.map(NodeAddress::toString).orElse("null");
|
||||
|
||||
PB.NetworkEnvelope proto = networkEnvelope.toProtoNetworkEnvelope();
|
||||
@ -280,6 +269,29 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
|
||||
peersNodeAddress, uid, Utilities.toTruncatedString(networkEnvelope), proto.getSerializedSize());
|
||||
}
|
||||
|
||||
// Throttle outbound network_messages
|
||||
long now = System.currentTimeMillis();
|
||||
long elapsed = now - lastSendTimeStamp;
|
||||
if (elapsed < sendMsgThrottleTrigger) {
|
||||
log.debug("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());
|
||||
|
||||
// check if EnvelopeOfEnvelopes is supported
|
||||
if(getCapabilities().containsAll(new Capabilities(Capability.ENVELOPE_OF_ENVELOPES))) {
|
||||
// check if a bucket is already there
|
||||
// - no? create a bucket
|
||||
// - and schedule it for sending
|
||||
// - yes? add to bucket
|
||||
return;
|
||||
}
|
||||
|
||||
Thread.sleep(sendMsgThrottleSleep);
|
||||
}
|
||||
|
||||
lastSendTimeStamp = now;
|
||||
|
||||
if (!stopped) {
|
||||
protoOutputStream.writeEnvelope(networkEnvelope);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user