[bisq-network/bisq] Add inventory monitor module (#4680)
sqrrm
notifications at github.com
Fri Oct 23 17:23:12 UTC 2020
@sqrrm commented on this pull request.
Looks good. Some comments that don't really have to be tended to.
> @@ -523,4 +525,11 @@ public static int byteArrayToInteger(byte[] bytes) {
return t -> map.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
+ public static String readableFileSize(long size) {
+ if (size <= 0) return "0";
Not our usual style, but I quite like this way.
> + @Named(Config.MAX_CONNECTIONS) int maxConnections) {
+ this.networkNode = networkNode;
+ this.peerManager = peerManager;
+ this.p2PDataStorage = p2PDataStorage;
+ this.daoStateService = daoStateService;
+ this.daoStateMonitoringService = daoStateMonitoringService;
+ this.proposalStateMonitoringService = proposalStateMonitoringService;
+ this.blindVoteStateMonitoringService = blindVoteStateMonitoringService;
+ this.maxConnections = maxConnections;
+
+ this.networkNode.addMessageListener(this);
+ }
+
+ @Override
+ public void onMessage(NetworkEnvelope networkEnvelope, Connection connection) {
+ if (networkEnvelope instanceof GetInventoryRequest) {
As always, prefer to return early instead of huge blocks.
> + p2PDataStorage.getMapForDataResponse(getInventoryRequest.getVersion()).values().stream()
+ .map(e -> e.getClass().getSimpleName())
+ .forEach(className -> {
+ Optional<InventoryItem> optionalEnum = Enums.getIfPresent(InventoryItem.class, className);
+ if (optionalEnum.isPresent()) {
+ InventoryItem key = optionalEnum.get();
+ dataObjects.putIfAbsent(key, 0);
+ int prev = dataObjects.get(key);
+ dataObjects.put(key, prev + 1);
+ }
+ });
+ p2PDataStorage.getMap().values().stream()
+ .map(ProtectedStorageEntry::getProtectedStoragePayload)
+ .filter(Objects::nonNull)
+ .map(e -> e.getClass().getSimpleName())
+ .forEach(className -> {
+ Optional<InventoryItem> optionalEnum = Enums.getIfPresent(InventoryItem.class, className);
+ if (optionalEnum.isPresent()) {
+ InventoryItem key = optionalEnum.get();
+ dataObjects.putIfAbsent(key, 0);
+ int prev = dataObjects.get(key);
+ dataObjects.put(key, prev + 1);
+ }
+ });
```suggestion
p2PDataStorage.getMapForDataResponse(getInventoryRequest.getVersion()).values().stream()
.map(e -> e.getClass().getSimpleName())
.forEach(className -> addItem(dataObjects, className));
p2PDataStorage.getMap().values().stream()
.map(ProtectedStorageEntry::getProtectedStoragePayload)
.filter(Objects::nonNull)
.map(e -> e.getClass().getSimpleName())
.forEach(className -> addItem(dataObjects, className));
```
With `addItem()`
```
private void addItem(Map<InventoryItem, Integer> dataObjects, String className) {
Optional<InventoryItem> optionalEnum = Enums.getIfPresent(InventoryItem.class, className);
if (optionalEnum.isPresent()) {
InventoryItem key = optionalEnum.get();
dataObjects.putIfAbsent(key, 0);
int prev = dataObjects.get(key);
dataObjects.put(key, prev + 1);
}
}
```
> + inventoryMonitor = new InventoryMonitor(appDir, useLocalhostForP2P, network, intervalSec, port);
+
+ setup(network, appDir);
+ }
+
+ private static void setup(BaseCurrencyNetwork network, File appDir) {
+ AsciiLogo.showAsciiLogo();
+ String logPath = Paths.get(appDir.getPath(), "bisq").toString();
+ Log.setup(logPath);
+ Log.setLevel(Level.INFO);
+ Version.setBaseCryptoNetworkId(network.ordinal());
+
+ Res.setup(); // Used for some formatting in the webserver
+
+ // We do not set any capabilities as we don't want to receive any network data beside our response.
+ // We also do not use capabilities for the request/response messages as we only connect to seeds nodes and
This comment is lacking a bit when it comes to the punch line.
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/bisq-network/bisq/pull/4680#pullrequestreview-515674481
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20201023/97fa6300/attachment.html>
More information about the bisq-github
mailing list