Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply code review suggestions to seednode changes #6454

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,10 @@ configure(project(':seednode')) {

dependencies {
implementation project(':common')
implementation project(':proto')
implementation project(':p2p')
implementation project(':core')
implementation libs.protobuf.java
annotationProcessor libs.lombok
compileOnly libs.lombok
implementation libs.google.guava
Expand Down
15 changes: 11 additions & 4 deletions common/src/main/java/bisq/common/util/Utilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadFactory;
Expand Down Expand Up @@ -136,10 +137,16 @@ private static ThreadPoolExecutor getThreadPoolExecutor(String name,
return executor;
}

public static ExecutorService newCachedThreadPool(int maximumPoolSize) {
return new ThreadPoolExecutor(0, maximumPoolSize,
60, TimeUnit.SECONDS,
new SynchronousQueue<>());
public static ExecutorService newCachedThreadPool(int maximumPoolSize,
long keepAliveTime,
TimeUnit timeUnit,
RejectedExecutionHandler rejectedExecutionHandler) {
return new ThreadPoolExecutor(0,
maximumPoolSize,
keepAliveTime,
timeUnit,
new SynchronousQueue<>(),
rejectedExecutionHandler);
}

@SuppressWarnings("SameParameterValue")
Expand Down
8 changes: 6 additions & 2 deletions p2p/src/main/java/bisq/network/p2p/network/NetworkNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ public SettableFuture<Connection> sendMessage(@NotNull NodeAddress peersNodeAddr
try {
socket.close();
} catch (Throwable throwable) {
log.error("Error at closing socket " + throwable);
if (!shutDownInProgress) {
log.error("Error at closing socket " + throwable);
}
}
existingConnection.sendMessage(networkEnvelope);
return existingConnection;
Expand All @@ -188,7 +190,9 @@ public void onDisconnect(CloseConnectionReason closeConnectionReason,

@Override
public void onError(Throwable throwable) {
log.error("new OutboundConnection.ConnectionListener.onError " + throwable.getMessage());
if (!shutDownInProgress) {
log.error("new OutboundConnection.ConnectionListener.onError " + throwable.getMessage());
}
connectionListeners.forEach(e -> e.onError(throwable));
}
};
Expand Down
12 changes: 6 additions & 6 deletions proto/src/main/proto/pb.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2494,20 +2494,20 @@ message ReportingItem {
string key = 1;
string group = 2;
oneof message {
StringValueItem string_value_item = 3;
LongValueItem long_value_item = 4;
DoubleValueItem double_value_item = 5;
StringValueReportingItem string_value_reporting_item = 3;
LongValueReportingItem long_value_reporting_item = 4;
DoubleValueReportingItem double_value_reporting_item = 5;
}
}
message StringValueItem {
message StringValueReportingItem {
string value = 1;
}

message LongValueItem {
message LongValueReportingItem {
uint64 value = 1;
}

message DoubleValueItem {
message DoubleValueReportingItem {
double value = 1;
}

Expand Down
2 changes: 2 additions & 0 deletions seednode/src/main/java/bisq/seednode/SeedNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package bisq.seednode;

import bisq.seednode.reporting.SeedNodeReportingService;

import bisq.core.app.misc.AppSetup;
import bisq.core.app.misc.AppSetupWithP2PAndDAO;
import bisq.core.network.p2p.inventory.GetInventoryRequestHandler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.monitor;
package bisq.seednode.reporting;

import lombok.Getter;
import lombok.Setter;


public enum DoubleValueItem implements ReportingItem {
public enum DoubleValueReportingItem implements ReportingItem {
Unspecified("", "Unspecified"),
sentBytesPerSec("network", "sentBytesPerSec"),
receivedBytesPerSec("network", "receivedBytesPerSec"),
Expand All @@ -30,32 +30,29 @@ public enum DoubleValueItem implements ReportingItem {


@Getter
@Setter
private String key;
private final String key;
@Getter
@Setter
private String group;
private final String group;
@Getter
@Setter
private double value;

DoubleValueItem(String group, String key) {
DoubleValueReportingItem(String group, String key) {
this.group = group;
this.key = key;
}

public DoubleValueItem withValue(double value) {
public DoubleValueReportingItem withValue(double value) {
setValue(value);
return this;
}

public static DoubleValueItem from(String key, double value) {
DoubleValueItem item;
public static DoubleValueReportingItem from(String key, double value) {
DoubleValueReportingItem item;
try {
item = DoubleValueItem.valueOf(key);
item = DoubleValueReportingItem.valueOf(key);
} catch (Throwable t) {
item = DoubleValueItem.Unspecified;
item.setKey(key);
item = Unspecified;
}

item.setValue(value);
Expand All @@ -64,13 +61,14 @@ public static DoubleValueItem from(String key, double value) {

@Override
public protobuf.ReportingItem toProtoMessage() {
return getBuilder().setDoubleValueItem(protobuf.DoubleValueItem.newBuilder()
return getBuilder().setDoubleValueReportingItem(protobuf.DoubleValueReportingItem.newBuilder()
.setValue(value))
.build();
}

public static DoubleValueItem fromProto(protobuf.ReportingItem baseProto, protobuf.DoubleValueItem proto) {
return DoubleValueItem.from(baseProto.getKey(), proto.getValue());
public static DoubleValueReportingItem fromProto(protobuf.ReportingItem baseProto,
protobuf.DoubleValueReportingItem proto) {
return DoubleValueReportingItem.from(baseProto.getKey(), proto.getValue());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.monitor;
package bisq.seednode.reporting;

import lombok.Getter;
import lombok.Setter;


public enum LongValueItem implements ReportingItem {
public enum LongValueReportingItem implements ReportingItem {
Unspecified("", "Unspecified"),
OfferPayload("data", "OfferPayload"),
MailboxStoragePayload("data", "MailboxStoragePayload"),
Expand Down Expand Up @@ -52,32 +52,29 @@ public enum LongValueItem implements ReportingItem {
jvmStartTimeInSec("node", "jvmStartTimeInSec");

@Getter
@Setter
private String key;
private final String key;
@Getter
@Setter
private String group;
private final String group;
@Getter
@Setter
private long value;

LongValueItem(String group, String key) {
LongValueReportingItem(String group, String key) {
this.group = group;
this.key = key;
}

public LongValueItem withValue(long value) {
public LongValueReportingItem withValue(long value) {
setValue(value);
return this;
}

public static LongValueItem from(String key, long value) {
LongValueItem item;
public static LongValueReportingItem from(String key, long value) {
LongValueReportingItem item;
try {
item = LongValueItem.valueOf(key);
item = LongValueReportingItem.valueOf(key);
} catch (Throwable t) {
item = LongValueItem.Unspecified;
item.setKey(key);
item = Unspecified;
}

item.setValue(value);
Expand All @@ -86,13 +83,14 @@ public static LongValueItem from(String key, long value) {

@Override
public protobuf.ReportingItem toProtoMessage() {
return getBuilder().setLongValueItem(protobuf.LongValueItem.newBuilder()
return getBuilder().setLongValueReportingItem(protobuf.LongValueReportingItem.newBuilder()
.setValue(value))
.build();
}

public static LongValueItem fromProto(protobuf.ReportingItem baseProto, protobuf.LongValueItem proto) {
return LongValueItem.from(baseProto.getKey(), proto.getValue());
public static LongValueReportingItem fromProto(protobuf.ReportingItem baseProto,
protobuf.LongValueReportingItem proto) {
return LongValueReportingItem.from(baseProto.getKey(), proto.getValue());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.monitor;
package bisq.seednode.reporting;

import bisq.common.proto.ProtobufferRuntimeException;
import bisq.common.proto.network.NetworkPayload;
Expand All @@ -37,12 +37,12 @@ default protobuf.ReportingItem.Builder getBuilder() {

static ReportingItem fromProto(protobuf.ReportingItem proto) {
switch (proto.getMessageCase()) {
case STRING_VALUE_ITEM:
return StringValueItem.fromProto(proto, proto.getStringValueItem());
case LONG_VALUE_ITEM:
return LongValueItem.fromProto(proto, proto.getLongValueItem());
case DOUBLE_VALUE_ITEM:
return DoubleValueItem.fromProto(proto, proto.getDoubleValueItem());
case STRING_VALUE_REPORTING_ITEM:
return StringValueReportingItem.fromProto(proto, proto.getStringValueReportingItem());
case LONG_VALUE_REPORTING_ITEM:
return LongValueReportingItem.fromProto(proto, proto.getLongValueReportingItem());
case DOUBLE_VALUE_REPORTING_ITEM:
return DoubleValueReportingItem.fromProto(proto, proto.getDoubleValueReportingItem());
case MESSAGE_NOT_SET:
default:
throw new ProtobufferRuntimeException("Unknown message case: " + proto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
*/

package bisq.core.monitor;
package bisq.seednode.reporting;

import bisq.common.proto.network.NetworkPayload;

Expand Down
Loading