Skip to content
Snippets Groups Projects
Commit b8c29e75 authored by Benoit Lavenier's avatar Benoit Lavenier
Browse files

[fix] Network CLI: change default timeout to 300ms

parent 0c207fd3
No related branches found
No related tags found
No related merge requests found
Pipeline #4521 passed
...@@ -81,17 +81,21 @@ public class NetworkAction extends AbstractAction { ...@@ -81,17 +81,21 @@ public class NetworkAction extends AbstractAction {
final Peer mainPeer = peerParameters.getPeer(); final Peer mainPeer = peerParameters.getPeer();
checkOutputFileIfNotNull(); // make sure the file (if any) is writable checkOutputFileIfNotNull(); // make sure the file (if any) is writable
// Reducing node timeout when broadcast Configuration config = Configuration.instance();
if (peerParameters.timeout != null) {
Configuration.instance().getApplicationConfig().setOption(ConfigurationOption.NETWORK_TIMEOUT.getKey(), peerParameters.timeout.toString()); // Configure network timeout
Integer timeout = peerParameters.timeout;
if (timeout == null) {
timeout = 300; // Override default timeout to 300ms.
} }
config.getApplicationConfig().setOption(ConfigurationOption.NETWORK_TIMEOUT.getKey(), timeout.toString());
dateFormat = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.MEDIUM, I18n.getDefaultLocale()); dateFormat = SimpleDateFormat.getDateTimeInstance(SimpleDateFormat.SHORT, SimpleDateFormat.MEDIUM, I18n.getDefaultLocale());
console = new RegexAnsiConsole(); console = new RegexAnsiConsole();
System.setOut(console); System.setOut(console);
log.info(I18n.t("duniter4j.client.network.loadingPeers")); log.info(I18n.t("duniter4j.client.network.loadingPeers", timeout));
NetworkService service = ServiceLocator.instance().getNetworkService(); NetworkService service = ServiceLocator.instance().getNetworkService();
...@@ -130,11 +134,14 @@ public class NetworkAction extends AbstractAction { ...@@ -130,11 +134,14 @@ public class NetworkAction extends AbstractAction {
return; return;
} }
Peer mainConsensusPeer = peers.iterator().next(); Peer.Stats mainConsensusStats = peers.stream()
Peer.Stats mainConsensusStats = mainConsensusPeer.getStats(); .filter(p -> p.getStats() != null && p.getStats().getMedianTime() != null && p.getStats().isMainConsensus())
if (mainConsensusStats.isMainConsensus()) { .map(Peer::getStats)
Long mediantTime = mainConsensusStats.getMedianTime(); .findFirst().orElse(null);
String medianTime = dateFormat.format(new Date(mediantTime * 1000));
// Define color of main consensus info
if (mainConsensusStats != null) {
String medianTime = dateFormat.format(new Date(mainConsensusStats.getMedianTime() * 1000));
String mainBuid = formatBuid(mainConsensusStats); String mainBuid = formatBuid(mainConsensusStats);
console.reset() console.reset()
...@@ -144,7 +151,7 @@ public class NetworkAction extends AbstractAction { ...@@ -144,7 +151,7 @@ public class NetworkAction extends AbstractAction {
.fgString(medianTime, Ansi.Color.GREEN); .fgString(medianTime, Ansi.Color.GREEN);
peers.stream() peers.stream()
.filter(peer -> peer.getStats().isForkConsensus()) .filter(peer -> peer.getStats() != null && peer.getStats().isForkConsensus())
.map(peer -> formatBuid(peer.getStats())) .map(peer -> formatBuid(peer.getStats()))
.forEach(forkConsensusBuid -> console.fgString(Formatters.formatBuid(forkConsensusBuid), Ansi.Color.YELLOW)); .forEach(forkConsensusBuid -> console.fgString(Formatters.formatBuid(forkConsensusBuid), Ansi.Color.YELLOW));
...@@ -175,7 +182,7 @@ public class NetworkAction extends AbstractAction { ...@@ -175,7 +182,7 @@ public class NetworkAction extends AbstractAction {
peer.getStats().getStatus().name(), peer.getStats().getStatus().name(),
isUp ? formatApi(peer) : "", isUp ? formatApi(peer) : "",
isUp ? peer.getStats().getVersion() : "", isUp ? peer.getStats().getVersion() : "",
(isUp && peer.getStats().getHardshipLevel() != null) ? peer.getStats().getHardshipLevel() : (peer.getStats().getUid() == null ? I18n.t("duniter4j.client.network.mirror") : ""), isUp ? formatHarshipLevel(peer) : "",
isUp ? formatBuid(peer.getStats()) : "" isUp ? formatBuid(peer.getStats()) : ""
}; };
}) })
...@@ -253,4 +260,15 @@ public class NetworkAction extends AbstractAction { ...@@ -253,4 +260,15 @@ public class NetworkAction extends AbstractAction {
return peer.getApi(); return peer.getApi();
} }
protected String formatHarshipLevel(Peer peer) {
// Mirror
if (peer.getStats().getHardshipLevel() == null || peer.getStats().getUid() == null) {
return I18n.t("duniter4j.client.network.mirror");
}
if (peer.getStats().getHardshipLevel() == 0) {
return "?";
}
return peer.getStats().getHardshipLevel().toString();
}
} }
...@@ -46,7 +46,7 @@ public class PeerParameters { ...@@ -46,7 +46,7 @@ public class PeerParameters {
public boolean useSsl = false; public boolean useSsl = false;
@Parameter(names = "--timeout", description = "HTTP request timeout, in millisecond", descriptionKey = "duniter4j.client.params.peer.timeout") @Parameter(names = "--timeout", description = "HTTP request timeout, in millisecond", descriptionKey = "duniter4j.client.params.peer.timeout")
public Long timeout = null; public Integer timeout = null;
private Peer peer = null; private Peer peer = null;
......
...@@ -4,8 +4,8 @@ duniter4j.client.network.action=Display network peers ...@@ -4,8 +4,8 @@ duniter4j.client.network.action=Display network peers
duniter4j.client.network.cesiumPlus=Cs+ duniter4j.client.network.cesiumPlus=Cs+
duniter4j.client.network.error.outputFieNotWritable=Output file not writable duniter4j.client.network.error.outputFieNotWritable=Output file not writable
duniter4j.client.network.executionTime=Execution time\: %s ms duniter4j.client.network.executionTime=Execution time\: %s ms
duniter4j.client.network.header=Main block [%1$s] computed at [%2$s] validated by [%3$3.2f%%] of peers duniter4j.client.network.header=Head: block {%1$s} computed at %2$s (UTC time) validated by {%3$3.2f%%} of the peers
duniter4j.client.network.loadingPeers=Reading network peers... duniter4j.client.network.loadingPeers=Reading network peers... (timeout\: %s ms)
duniter4j.client.network.mirror=Mirror duniter4j.client.network.mirror=Mirror
duniter4j.client.network.noPeers=No peers found duniter4j.client.network.noPeers=No peers found
duniter4j.client.network.params.continue=Continue scanning? (Will refresh on new peer/block). duniter4j.client.network.params.continue=Continue scanning? (Will refresh on new peer/block).
......
duniter4j.client.info.peer=Noeud Duniter \: [%s\:%s] duniter4j.client.info.peer=Noeud Duniter {%s\:%s}
duniter4j.client.info.peer.fallback=Noeud Duniter (par défaut) \: [%s\:%d] duniter4j.client.info.peer.fallback=Noeud Duniter par défaut {%s\:%d}
duniter4j.client.network.action=Afficher les noeuds Duniter duniter4j.client.network.action=Afficher les noeuds Duniter
duniter4j.client.network.cesiumPlus=Cs+ duniter4j.client.network.cesiumPlus=Cs+
duniter4j.client.network.error.outputFieNotWritable=Fichier de sortie non inscriptible duniter4j.client.network.error.outputFieNotWritable=Fichier de sortie non inscriptible
duniter4j.client.network.executionTime=Temps d'execution \: %s ms duniter4j.client.network.executionTime=Temps d'execution \: %s ms
duniter4j.client.network.header=Bloc principal [%1$s] calculé à [%2$s] validé par [%3$3.2f%%] des noeuds duniter4j.client.network.header=Branche principale: bloc {%1$s} calculé à %2$s (heure UTC) validé par {%3$3.2f%%} des noeuds
duniter4j.client.network.loadingPeers=Lecture des noeuds du réseau... duniter4j.client.network.loadingPeers=Lecture des noeuds du réseau... (Délai d'attente \: %s ms)
duniter4j.client.network.mirror=Mirroir duniter4j.client.network.mirror=Mirroir
duniter4j.client.network.noPeers=Aucun noeud trouvé duniter4j.client.network.noPeers=Aucun noeud trouvé
duniter4j.client.network.params.continue=Continue scanning? (Will refresh on new peer/block). duniter4j.client.network.params.continue=Continue scanning? (Will refresh on new peer/block).
......
...@@ -417,8 +417,11 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network ...@@ -417,8 +417,11 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
lockManager.unlock(PEERS_UPDATE_LOCK_NAME); lockManager.unlock(PEERS_UPDATE_LOCK_NAME);
} }
} }
else {
log.debug("Could not acquire lock for reloading all peers. Skipping.");
}
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.warn("Could not acquire lock for reloading all peers. Skipping."); log.warn("Stopping reloading all peers: " + e.getMessage());
} }
}; };
...@@ -487,7 +490,7 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network ...@@ -487,7 +490,7 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
// If new block + wait 3s for network propagation // If new block + wait 3s for network propagation
if (isNewBlock) { if (isNewBlock) {
schedule(loadAllPeers, pool, 3000/*waiting block propagation*/); schedule(loadAllPeers, pool, 3000/*waiting 3s, for block propagation*/);
} }
} catch(IOException e) { } catch(IOException e) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment