Sketch of businesslogic regarding EnvelopeOfEnvelopes

This commit is contained in:
Florian Reimair 2019-06-24 16:55:56 +02:00
parent 16392f5f0a
commit b101035d99
No known key found for this signature in database
GPG Key ID: 05634D8D7A7954C8
3 changed files with 27 additions and 13 deletions

View File

@ -32,5 +32,6 @@ public enum Capability {
BLIND_VOTE,
ACK_MSG,
BSQ_BLOCK,
DAO_STATE
DAO_STATE,
ENVELOPE_OF_ENVELOPES
}

View File

@ -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);

View File

@ -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);
}