Commit b8c29e75 authored by Benoit Lavenier's avatar Benoit Lavenier

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

parent 0c207fd3
Pipeline #4521 passed with stage
in 25 seconds
......@@ -81,17 +81,21 @@ public class NetworkAction extends AbstractAction {
final Peer mainPeer = peerParameters.getPeer();
checkOutputFileIfNotNull(); // make sure the file (if any) is writable
// Reducing node timeout when broadcast
if (peerParameters.timeout != null) {
Configuration.instance().getApplicationConfig().setOption(ConfigurationOption.NETWORK_TIMEOUT.getKey(), peerParameters.timeout.toString());
Configuration config = Configuration.instance();
// 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());
console = new RegexAnsiConsole();
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();
......@@ -130,11 +134,14 @@ public class NetworkAction extends AbstractAction {
return;
}
Peer mainConsensusPeer = peers.iterator().next();
Peer.Stats mainConsensusStats = mainConsensusPeer.getStats();
if (mainConsensusStats.isMainConsensus()) {
Long mediantTime = mainConsensusStats.getMedianTime();
String medianTime = dateFormat.format(new Date(mediantTime * 1000));
Peer.Stats mainConsensusStats = peers.stream()
.filter(p -> p.getStats() != null && p.getStats().getMedianTime() != null && p.getStats().isMainConsensus())
.map(Peer::getStats)
.findFirst().orElse(null);
// Define color of main consensus info
if (mainConsensusStats != null) {
String medianTime = dateFormat.format(new Date(mainConsensusStats.getMedianTime() * 1000));
String mainBuid = formatBuid(mainConsensusStats);
console.reset()
......@@ -144,7 +151,7 @@ public class NetworkAction extends AbstractAction {
.fgString(medianTime, Ansi.Color.GREEN);
peers.stream()
.filter(peer -> peer.getStats().isForkConsensus())
.filter(peer -> peer.getStats() != null && peer.getStats().isForkConsensus())
.map(peer -> formatBuid(peer.getStats()))
.forEach(forkConsensusBuid -> console.fgString(Formatters.formatBuid(forkConsensusBuid), Ansi.Color.YELLOW));
......@@ -175,7 +182,7 @@ public class NetworkAction extends AbstractAction {
peer.getStats().getStatus().name(),
isUp ? formatApi(peer) : "",
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()) : ""
};
})
......@@ -253,4 +260,15 @@ public class NetworkAction extends AbstractAction {
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 {
public boolean useSsl = false;
@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;
......
......@@ -4,8 +4,8 @@ duniter4j.client.network.action=Display network peers
duniter4j.client.network.cesiumPlus=Cs+
duniter4j.client.network.error.outputFieNotWritable=Output file not writable
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.loadingPeers=Reading network 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... (timeout\: %s ms)
duniter4j.client.network.mirror=Mirror
duniter4j.client.network.noPeers=No peers found
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.fallback=Noeud Duniter (par défaut) \: [%s\:%d]
duniter4j.client.info.peer=Noeud Duniter {%s\:%s}
duniter4j.client.info.peer.fallback=Noeud Duniter par défaut {%s\:%d}
duniter4j.client.network.action=Afficher les noeuds Duniter
duniter4j.client.network.cesiumPlus=Cs+
duniter4j.client.network.error.outputFieNotWritable=Fichier de sortie non inscriptible
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.loadingPeers=Lecture des noeuds du réseau...
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... (Délai d'attente \: %s ms)
duniter4j.client.network.mirror=Mirroir
duniter4j.client.network.noPeers=Aucun noeud trouvé
duniter4j.client.network.params.continue=Continue scanning? (Will refresh on new peer/block).
......
......@@ -417,8 +417,11 @@ public class NetworkServiceImpl extends BaseRemoteServiceImpl implements Network
lockManager.unlock(PEERS_UPDATE_LOCK_NAME);
}
}
else {
log.debug("Could not acquire lock for reloading all peers. Skipping.");
}
} 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
// If new block + wait 3s for network propagation
if (isNewBlock) {
schedule(loadAllPeers, pool, 3000/*waiting block propagation*/);
schedule(loadAllPeers, pool, 3000/*waiting 3s, for block propagation*/);
}
} catch(IOException e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment