Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • clients/cesium-grp/cesium-plus-pod
  • clients/java/duniter4j
  • ji_emme/duniter4j
  • dvermd/cesium-plus-pod
  • okayotanoka/cesium-plus-pod
  • pokapow/cesium-plus-pod
  • pini-gh/cesium-plus-pod
7 results
Show changes
Showing
with 309 additions and 295 deletions
......@@ -3,7 +3,9 @@ duniter4j.version=${project.version}
duniter4j.inceptionYear=${project.inceptionYear}
duniter4j.organizationName=${license.organizationName}
#
# Duniter node
#
duniter4j.node.host=192.168.0.5
duniter4j.node.port=10901
......
......@@ -19,12 +19,15 @@ log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %5p %c - %m%n
# Duniter4j levels
log4j.logger.org.duniter=INFO
log4j.logger.org.duniter.core=WARN
# Avoid warning on leaf not found (Duniter issue)
log4j.logger.org.duniter.core.client.service.local.NetworkServiceImpl=ERROR
# Avoid warning on leaf not found (Duniter issue ?)
#log4j.logger.org.duniter.core.client.service.local.NetworkServiceImpl=WARN
# Other frameworks levels
log4j.logger.org.apache.http=ERROR
log4j.logger.org.nuiton.util=WARN
log4j.logger.org.nuiton.config=WARN
log4j.logger.org.nuiton.converter=WARN
log4j.logger.org.nuiton.i18n=ERROR
\ No newline at end of file
log4j.logger.org.nuiton.i18n=ERROR
# Http client connection debug
#log4j.logger.org.apache.http.impl.conn=DEBUG
\ No newline at end of file
......@@ -32,7 +32,10 @@ import org.duniter.client.actions.TransactionAction;
import org.apache.commons.io.FileUtils;
import org.duniter.core.client.config.Configuration;
import org.duniter.core.client.config.ConfigurationOption;
import org.duniter.core.client.model.bma.jackson.JacksonUtils;
import org.duniter.core.client.service.DataContext;
import org.duniter.core.client.service.ServiceLocator;
import org.duniter.core.util.Preconditions;
import org.duniter.core.util.StringUtils;
import org.nuiton.i18n.I18n;
import org.nuiton.i18n.init.DefaultI18nInitializer;
......@@ -76,11 +79,11 @@ public class Main {
// Parsing args
JCommander jc = new JCommander(this);
actions.entrySet().stream().forEach(entry -> jc.addCommand(entry.getKey(), entry.getValue()));
actions.forEach(jc::addCommand);
try {
jc.parse(args);
jc.getParameters().stream().forEach(param -> {
jc.getParameters().forEach(param -> {
if (param.getParameter().password()
&& param.getParameter().required()
&& param.getParameter().echoInput()
......@@ -94,7 +97,6 @@ public class Main {
catch(ParameterException e) {
System.err.println(e.getMessage());
System.err.println("Try --help for usage");
//jc.usage();
System.exit(-1);
}
......@@ -122,7 +124,11 @@ public class Main {
}
// Set a default account id, then load cache
ServiceLocator.instance().getDataContext().setAccountId(0);
// TODO: load data context (e.g. from a data file, or from config file)
DataContext context = loadDataContext();
if (context != null) {
ServiceLocator.instance().getDataContext().copy(context);
}
// Initialize service locator
ServiceLocator.instance().init();
......@@ -196,4 +202,22 @@ public class Main {
return configArgs.toArray(new String[configArgs.size()]);
}
protected DataContext loadDataContext() {
File dataDirectory = Configuration.instance().getDataDirectory();
if (!dataDirectory.exists()) return null; // Skip if not exists
Preconditions.checkArgument(dataDirectory.isDirectory(), "Invalid directory: " + dataDirectory.getAbsolutePath());
File dataFile = new File(dataDirectory, "data.json");
if (!dataFile.exists()) return null; // Skip if not exists
Preconditions.checkArgument(dataFile.canRead(), "Cannot read data file: " + dataFile.getAbsolutePath());
try {
return JacksonUtils.getThreadObjectMapper().readValue(dataFile, DataContext.class);
} catch (Exception e) {
System.err.println(String.format("Cannot read data file: %s. Skipping.", dataFile.getAbsolutePath()));
return null;
}
}
}
......@@ -32,7 +32,9 @@ import org.duniter.client.actions.utils.Formatters;
import org.apache.commons.io.IOUtils;
import org.duniter.core.client.config.Configuration;
import org.duniter.core.client.config.ConfigurationOption;
import org.duniter.core.client.model.bma.EndpointApi;
import org.duniter.core.client.model.local.Peer;
import org.duniter.core.client.model.local.Peers;
import org.duniter.core.client.service.ServiceLocator;
import org.duniter.core.client.service.local.NetworkService;
import org.duniter.core.util.CollectionUtils;
......@@ -43,6 +45,7 @@ import org.nuiton.i18n.I18n;
import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
......@@ -78,33 +81,37 @@ 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();
if (!autoRefresh) {
Long now = System.currentTimeMillis();
List<Peer> peers = service.getPeers(mainPeer);
showPeersTable(peers, false);
log.info(I18n.t("duniter4j.client.network.executionTime", System.currentTimeMillis() - now));
}
else {
service.addPeersChangeListener(mainPeer, peers -> showPeersTable(peers, true));
try {
while(true) {
Thread.sleep(10000); // 10 s
}
while (true) Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
// end
}
}
......@@ -113,7 +120,7 @@ public class NetworkAction extends AbstractAction {
/* -- protected methods -- */
public void showPeersTable(List<Peer> peers, boolean clearConsole) {
public void showPeersTable(Collection<Peer> peers, boolean clearConsole) {
// Clearing console
if (clearConsole) {
......@@ -125,11 +132,14 @@ public class NetworkAction extends AbstractAction {
return;
}
Peer mainConsensusPeer = peers.get(0);
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()
......@@ -139,7 +149,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));
......@@ -168,9 +178,9 @@ public class NetworkAction extends AbstractAction {
Formatters.formatPubkey(peer.getPubkey()),
peer.getHost() + ":" + peer.getPort(),
peer.getStats().getStatus().name(),
isUp && peer.isUseSsl() ? I18n.t("duniter4j.client.network.ssl") : "",
isUp ? formatApi(peer) : "",
isUp ? peer.getStats().getVersion() : "",
(isUp && peer.getStats().getHardshipLevel() != null) ? peer.getStats().getHardshipLevel() : I18n.t("duniter4j.client.network.mirror"),
isUp ? formatHarshipLevel(peer) : "",
isUp ? formatBuid(peer.getStats()) : ""
};
})
......@@ -234,6 +244,29 @@ public class NetworkAction extends AbstractAction {
}
protected String formatBuid(Peer.Stats stats) {
if (stats.getBlockNumber() == null) return "";
return Formatters.formatBuid(stats.getBlockNumber() + "-" + stats.getBlockHash());
}
protected String formatApi(Peer peer) {
if (Peers.hasBmaEndpoint(peer)) {
return peer.isUseSsl() ? I18n.t("duniter4j.client.network.ssl") : "";
}
if (Peers.hasWs2pEndpoint(peer)) {
return "WS2P";
}
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();
}
}
......@@ -50,6 +50,7 @@ import org.slf4j.LoggerFactory;
import java.util.List;
/**
* Created by blavenie on 22/03/17.
*/
......@@ -100,12 +101,12 @@ public class TransactionAction extends AbstractAction {
Currency currency = ServiceLocator.instance().getBlockchainRemoteService().getCurrencyFromPeer(peer);
ServiceLocator.instance().getCurrencyService().save(currency);
peer.setCurrency(currency.getCurrencyName());
peer.setCurrency(currency.getId());
ServiceLocator.instance().getPeerService().save(peer);
// Compute keypair and wallet
KeyPair keypair = null;
KeyPair keypair;
if (authParameters.authScrypt) {
CryptoService cryptoService = ServiceLocator.instance().getCryptoService();
keypair = cryptoService.getKeyPairFromSeed(
......@@ -123,11 +124,10 @@ public class TransactionAction extends AbstractAction {
}
Wallet wallet = new Wallet(
currency.getCurrencyName(),
currency.getId(),
null,
keypair.getPubKey(),
keypair.getSecKey());
wallet.setCurrencyId(currency.getId());
// Parse TX parameters
parseTransactionParameters();
......@@ -195,10 +195,10 @@ public class TransactionAction extends AbstractAction {
peersFilter.filterType = NetworkService.FilterType.MEMBER;
peersFilter.filterStatus = Peer.PeerStatus.UP;
if (useSsl) {
peersFilter.filterEndpoints = ImmutableList.of(EndpointApi.BMAS.name());
peersFilter.filterEndpoints = ImmutableList.of(EndpointApi.BMAS.label());
}
else {
peersFilter.filterEndpoints = ImmutableList.of(EndpointApi.BASIC_MERKLED_API.name());
peersFilter.filterEndpoints = ImmutableList.of(EndpointApi.BASIC_MERKLED_API.label());
}
// Sort by [lesser difficulty first]
NetworkService.Sort sortLesserDifficulty = new NetworkService.Sort();
......@@ -219,7 +219,7 @@ public class TransactionAction extends AbstractAction {
logTxSummary(wallet);
peers.stream().forEach(peer -> {
peer.setCurrency(currency.getCurrencyName());
peer.setCurrency(currency.getId());
peerService.save(peer);
log.debug(String.format("Send TX to [%s]...", peer));
......
......@@ -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;
......@@ -59,12 +59,12 @@ public class PeerParameters {
String host = parts[0];
Integer port = parts.length == 2 ? Integer.parseInt(parts[1]) : null;
Peer.Builder peerBuilder = Peer.newBuilder().setHost(host);
Peer.Builder peerBuilder = Peer.builder().host(host);
if (port != null) {
peerBuilder.setPort(port);
peerBuilder.port(port);
}
if (useSsl){
peerBuilder.setUseSsl(useSsl);
peerBuilder.useSsl(useSsl);
}
peer = peerBuilder.build();
......@@ -72,8 +72,8 @@ public class PeerParameters {
}
else {
Configuration config = Configuration.instance();
peer = Peer.newBuilder().setHost(config.getNodeHost())
.setPort(config.getNodePort())
peer = Peer.builder().host(config.getNodeHost())
.port(config.getNodePort())
.build();
log.info(I18n.t("duniter4j.client.info.peer.fallback", peer.getHost(), peer.getPort()));
}
......
......@@ -2,12 +2,12 @@ org.duniter.core.client.service.bma.BlockchainRemoteServiceImpl
org.duniter.core.client.service.bma.NetworkRemoteServiceImpl
org.duniter.core.client.service.bma.WotRemoteServiceImpl
org.duniter.core.client.service.bma.TransactionRemoteServiceImpl
org.duniter.core.client.service.elasticsearch.CurrencyRegistryRemoteServiceImpl
org.duniter.core.client.service.elasticsearch.CurrencyPodRemoteServiceImpl
org.duniter.core.service.Ed25519CryptoServiceImpl
org.duniter.core.client.service.HttpServiceImpl
org.duniter.core.client.service.DataContext
org.duniter.core.client.service.local.PeerServiceImpl
org.duniter.core.client.service.local.CurrencyServiceImpl
org.duniter.core.client.service.local.NetworkServiceImpl
org.duniter.core.client.dao.mem.MemoryCurrencyDaoImpl
org.duniter.core.client.dao.mem.MemoryPeerDaoImpl
\ No newline at end of file
org.duniter.core.client.repositories.mem.MemoryCurrencyRepositoryImpl
org.duniter.core.client.repositories.mem.MemoryPeerRepositoryImpl
\ No newline at end of file
......@@ -3,8 +3,9 @@ duniter4j.client.info.peer.fallback=Fallback to default Duniter peer\: [%s\:%d]
duniter4j.client.network.action=Display network peers
duniter4j.client.network.cesiumPlus=Cs+
duniter4j.client.network.error.outputFieNotWritable=Output file not writable
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.executionTime=Execution time\: %s ms
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.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=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).
duniter4j.client.network.params.output=Output CSV file
duniter4j.client.network.ssl=SSL
duniter4j.client.params.authScrypt=Authentification par salage Scrypt ?
duniter4j.client.params.authScrypt.ask.passwd=Veuillez entrer votre mot de passe Scrypt (password) \:
duniter4j.client.params.authScrypt.ask.salt=Veuillez entrer votre identifiant secret Scrypt (Salt)\:
duniter4j.client.params.authScrypt.ask.scryptParams=Veuillez entrer les paramètres de Scrypt (N,r,p)\: [%d,%d,%d]
duniter4j.client.params.authScrypt.error.scryptParams=Paramètre Scrypt non valide (3 valeurs attendues - format 'N,r,p')"
duniter4j.client.params.authScrypt.passwd=Mot de passe
duniter4j.client.params.authScrypt.salt=Identifiant secret (salt)
duniter4j.client.params.authScrypt.scryptParams=Paramètre de salage Scrypt (N,r,p)
duniter4j.client.params.config=Fichier de configuration
duniter4j.client.params.debug=Activer les logs de debuggage
duniter4j.client.params.error.invalidOption=Valeur d'option [%s] invalid
duniter4j.client.params.help=Affichage de l'aide
duniter4j.client.params.peer=Noeud Duniter (hôte\:port)
duniter4j.client.params.peer.fallback=
duniter4j.client.params.peer.timeout=Délai de réponse max. d'un noeud, en millisecondes
duniter4j.client.params.peer.useSsl=Utiliser une connection SSL ?
duniter4j.client.transaction.action=Effectuer une transaction
duniter4j.client.transaction.broadcast.failed=Transaction NON envoyée. Aucun noeud n'a accepté la transaction.
duniter4j.client.transaction.broadcast.memberPeerCount=%d noeud membres trouvé, pour l'envoi multiple
duniter4j.client.transaction.broadcast.success=Transaction envoyée avec succès (à %d noeuds de la branche principale de la chaine de blocs)
duniter4j.client.transaction.broadcast.successOnForkOnly=Transaction NON envoyée sur la branche principale, mais seulement sur %d noeud d'une branche secondaire de la cheine de blocs
duniter4j.client.transaction.broadcast.summary=Envoi de la transation\:\n\t- De\: %s\n\t- A\: %s\n\t- Montant\: %s %s
duniter4j.client.transaction.error.broadcast.noMemberPeer=Aucun noeud membre trouvé \! L'option --broadcast va être ignorée
duniter4j.client.transaction.error.unknownAuth=Type d'authentification inconnue
duniter4j.client.transaction.loadingMemberPeers=Récupération des noeuds membres...
duniter4j.client.transaction.params.amount.ask=Veuillez entrer le montant (valeur entière) \:
duniter4j.client.transaction.params.output.ask=Veuillez entrer le destinataire (clef publique) \:
duniter4j.client.transaction.sent=Transaction envoyé avec succè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=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.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.executionTime=Temps d'execution \: %s ms
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).
......@@ -19,7 +20,7 @@ duniter4j.client.params.authScrypt.passwd=Mot de passe
duniter4j.client.params.authScrypt.salt=Identifiant secret (salt)
duniter4j.client.params.authScrypt.scryptParams=Paramètre de salage Scrypt (N,r,p)
duniter4j.client.params.config=Fichier de configuration
duniter4j.client.params.debug=Activer les logs de débuggage
duniter4j.client.params.debug=Activer les logs de debuggage
duniter4j.client.params.error.invalidOption=Valeur d'option [%s] invalid
duniter4j.client.params.help=Affichage de l'aide
duniter4j.client.params.peer=Noeud Duniter (hôte\:port)
......
......@@ -552,7 +552,7 @@ License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to reference or combine any covered work with a work licensed
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
......
lombok.fieldnameconstants.uppercase=true
clear lombok.log.fieldName
lombok.log.fieldName = log
\ No newline at end of file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.duniter</groupId>
<artifactId>duniter4j</artifactId>
<version>0.10.2-SNAPSHOT</version>
<version>1.6.2-SNAPSHOT</version>
</parent>
<artifactId>duniter4j-core-client</artifactId>
<packaging>jar</packaging>
<name>Duniter4j :: Core Client API</name>
<description>A useful API to communicate with a Duniter network</description>
<properties>
<i18n.bundleOutputName>duniter4j-core-client-i18n</i18n.bundleOutputName>
......@@ -26,6 +28,7 @@
<artifactId>duniter4j-core-shared</artifactId>
<version>${project.version}</version>
</dependency>
<!-- LOGGING DEPENDENCIES - SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
......@@ -42,7 +45,6 @@
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-client</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.tyrus</groupId>
<artifactId>tyrus-container-grizzly-client</artifactId>
......@@ -60,10 +62,6 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
......@@ -85,6 +83,12 @@
<artifactId>jackson-databind</artifactId>
</dependency>
<!-- Compile -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<!-- Unit test -->
<dependency>
<groupId>junit</groupId>
......@@ -96,6 +100,11 @@
<artifactId>slf4j-log4j12</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
......
# Generated by org.codehaus.mojo.license.AddThirdPartyMojo
#-------------------------------------------------------------------------------
# Already used licenses in project :
# - Apache 2.0
# - BSD License
# - BSD-3-Clause
# - CDDL
# - CDDL+GPL
# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
# - Common Development and Distribution License (CDDL) v1.0
# - Dual license consisting of the CDDL v1.1 and GPL v2
# - Eclipse Public License 1.0
# - GPLv2+CE
# - General Public License (GPL) v3
# - Indiana University Extreme! Lab Software License, vesion 1.1.1
# - Lesser General Public License (LGPL) v 3.0
# - Lesser General Public License (LPGL)
# - Lesser General Public License (LPGL) v 2.1
# - Lesser General Public License (LPGL) version 3.0
# - MIT License
# - New BSD License
# - The Apache Software License, Version 2.0
......@@ -18,5 +24,5 @@
# Please fill the missing licenses for dependencies :
#
#
#Wed Nov 16 11:35:31 CET 2016
#Tue Apr 13 11:29:47 CEST 2021
commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0
......@@ -2,7 +2,7 @@ package org.duniter.core.client.config;
/*
* #%L
* UCoin Java Client :: Core API
* Duniter4j :: Core API
* %%
* Copyright (C) 2014 - 2015 EIS
* %%
......@@ -24,6 +24,7 @@ package org.duniter.core.client.config;
import com.google.common.base.Charsets;
import lombok.extern.slf4j.Slf4j;
import org.duniter.core.exception.TechnicalException;
import org.nuiton.config.ApplicationConfig;
import org.nuiton.config.ApplicationConfigHelper;
......@@ -31,10 +32,9 @@ import org.nuiton.config.ApplicationConfigProvider;
import org.nuiton.config.ArgumentsParserException;
import org.nuiton.version.Version;
import org.nuiton.version.VersionBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;
import java.util.Set;
......@@ -46,9 +46,17 @@ import static org.nuiton.i18n.I18n.t;
* @author Benoit Lavenier <benoit.lavenier@e-is.pro>
* @since 1.0
*/
@Slf4j
public class Configuration {
/** Logger. */
private static final Logger log = LoggerFactory.getLogger(Configuration.class);
protected static String[] args = null;
/**
* <p>remember app args.</p>
*/
public static void setArgs(String[] sourceArgs) {
args = sourceArgs;
}
/**
* Delegate application config.
......@@ -250,6 +258,10 @@ public class Configuration {
return applicationConfig.getOptionAsInt(ConfigurationOption.NETWORK_TIMEOUT.getKey());
}
public int getNetworkLargerTimeout() {
return Math.max(30000, getNetworkTimeout());
}
public int getNetworkMaxTotalConnections() {
return applicationConfig.getOptionAsInt(ConfigurationOption.NETWORK_MAX_CONNECTIONS.getKey());
}
......@@ -262,14 +274,29 @@ public class Configuration {
return Integer.parseInt(ConfigurationOption.NETWORK_CACHE_TIME_IN_MILLIS.getDefaultValue());
}
public String getNodeElasticSearchHost() {
return applicationConfig.getOption(ConfigurationOption.NODE_ELASTICSEARCH_HOST.getKey());
public int getPeerUpMaxAge() {
return applicationConfig.getOptionAsInt(ConfigurationOption.NETWORK_PEER_UP_MAX_AGE.getKey());
}
public String getCesiumPlusPodHost() {
return applicationConfig.getOption(ConfigurationOption.CESIUM_PLUS_POD_HOST.getKey());
}
public int getNodeElasticSearchPort() {
return applicationConfig.getOptionAsInt(ConfigurationOption.NODE_ELASTICSEARCH_PORT.getKey());
public int getCesiumPlusPodPort() {
return applicationConfig.getOptionAsInt(ConfigurationOption.CESIUM_PLUS_POD_PORT.getKey());
}
public URL getNodeElasticSearchUrl() {
return applicationConfig.getOptionAsURL(ConfigurationOption.NODE_ELASTICSEARCH_URL.getKey());
public URL getCesiumPlusPodUrl() {
// Force SSL for 443 port
if (getCesiumPlusPodPort() == 443) {
try {
return new URL(applicationConfig.getOption(ConfigurationOption.CESIUM_PLUS_POD_URL.getKey())
.replaceAll("http://", "https://"));
} catch(MalformedURLException e) {
return applicationConfig.getOptionAsURL(ConfigurationOption.CESIUM_PLUS_POD_URL.getKey());
}
}
else {
return applicationConfig.getOptionAsURL(ConfigurationOption.CESIUM_PLUS_POD_URL.getKey());
}
}
}
......@@ -182,7 +182,6 @@ public enum ConfigurationOption implements ConfigOptionDef {
Integer.class,
false),
NETWORK_CACHE_TIME_IN_MILLIS (
"duniter4j.network.cacheTimeInMillis",
"duniter4j.config.option.network.cacheTimeInMillis.description",
......@@ -190,28 +189,35 @@ public enum ConfigurationOption implements ConfigOptionDef {
Integer.class,
false),
NODE_ELASTICSEARCH_PROTOCOL(
NETWORK_PEER_UP_MAX_AGE (
"duniter.network.peerUpMaxAge",
"duniter.config.option.network.peerUpMaxAge.description",
"600000", // = 10 min
Integer.class,
false),
CESIUM_PLUS_POD_PROTOCOL(
"duniter4j.node.elasticsearch.protocol",
n("duniter4j.config.option.node.elasticsearch.protocol.description"),
"http",
String.class,
false),
NODE_ELASTICSEARCH_HOST(
CESIUM_PLUS_POD_HOST(
"duniter4j.node.elasticsearch.host",
n("duniter4j.config.option.node.elasticsearch.host.description"),
"localhost",
String.class,
false),
NODE_ELASTICSEARCH_PORT(
CESIUM_PLUS_POD_PORT(
"duniter4j.node.elasticsearch.port",
n("duniter4j.config.option.node.elasticsearch.port.description"),
"9200",
Integer.class,
false),
NODE_ELASTICSEARCH_URL(
CESIUM_PLUS_POD_URL(
"duniter4j.node.elasticsearch.url",
n("duniter4j.config.option.node.elasticsearch.url.description"),
"${duniter4j.node.elasticsearch.protocol}://${duniter4j.node.elasticsearch.host}:${duniter4j.node.elasticsearch.port}",
......
package org.duniter.elasticsearch.dao;
package org.duniter.core.client.example;
/*-
* #%L
* Duniter4j :: ElasticSearch Core plugin
* Duniter4j :: Core Client API
* %%
* Copyright (C) 2014 - 2017 EIS
* Copyright (C) 2014 - 2017 Duniter Team
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
......@@ -22,43 +22,35 @@ package org.duniter.elasticsearch.dao;
* #L%
*/
import org.duniter.core.beans.Bean;
import org.duniter.core.client.config.Configuration;
import org.duniter.core.client.model.bma.BlockchainBlock;
import org.duniter.elasticsearch.model.BlockchainBlockStat;
import org.duniter.core.client.model.local.Peer;
import org.duniter.core.client.service.ServiceLocator;
import java.util.List;
public class Example1 {
/**
* Created by blavenie on 03/04/17.
*/
public interface BlockStatDao extends Bean, TypeDao<BlockStatDao> {
String TYPE = "blockStat";
void create(BlockchainBlockStat block, boolean wait);
/**
*
* @param currencyName
* @param number the block number
* @param json block as JSON
*/
void create(String currencyName, String id, byte[] json, boolean wait);
public static void main(String[] args) {
boolean isExists(String currencyName, String id);
// Init configuration
String configFilename = "duniter4j-config.properties";
Configuration config = new Configuration(configFilename, args);
Configuration.setInstance(config);
void update(BlockchainBlockStat block, boolean wait);
/**
*
* @param currencyName
* @param number the block number, or -1 for current
* @param json block as JSON
*/
void update(String currencyName, String id, byte[] json, boolean wait);
// Initialize service locator
ServiceLocator.instance().init();
void delete(String currency, String id, boolean wait);
// Create a peer, from configuration
Peer aPeer = Peer.builder()
.host(config.getNodeHost())
.port(config.getNodePort())
.build();
BlockchainBlockStat getById(String currencyName, String id);
// Do something fun !
BlockchainBlock currentBlock = ServiceLocator.instance()
.getBlockchainRemoteService()
.getCurrentBlock(aPeer);
System.out.println(String.format("Hello %s world !", currentBlock.getCurrency()));
}
}
......@@ -2,7 +2,7 @@ package org.duniter.core.client.model;
/*
* #%L
* UCoin Java Client :: Core API
* Duniter4j :: Core API
* %%
* Copyright (C) 2014 - 2015 EIS
* %%
......@@ -23,12 +23,16 @@ package org.duniter.core.client.model;
*/
import org.duniter.core.client.model.local.LocalEntity;
import lombok.Data;
import lombok.experimental.FieldNameConstants;
import org.duniter.core.model.IEntity;
/**
* Created by eis on 07/02/15.
*/
public class Account implements LocalEntity<Long> {
@Data
@FieldNameConstants
public class Account implements IEntity<Long> {
private Long id;
private String uid;
......@@ -36,46 +40,4 @@ public class Account implements LocalEntity<Long> {
private String salt;
private String cryptPin;
@Override
public Long getId() {
return id;
}
@Override
public void setId(Long id) {
this.id = id;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
public String getPubkey() {
return pubkey;
}
public void setPubkey(String pubkey) {
this.pubkey = pubkey;
}
public String getSalt() {
return salt;
}
public void setSalt(String salt) {
this.salt = salt;
}
public String getCryptPin() {
return cryptPin;
}
public void setCryptPin(String cryptPin) {
this.cryptPin = cryptPin;
}
}
......@@ -2,7 +2,7 @@ package org.duniter.core.client.model;
/*
* #%L
* UCoin Java Client :: Core API
* Duniter4j :: Core API
* %%
* Copyright (C) 2014 - 2015 EIS
* %%
......@@ -23,6 +23,12 @@ package org.duniter.core.client.model;
*/
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;
import java.io.Serializable;
/**
......@@ -32,48 +38,33 @@ import java.io.Serializable;
* @since 1.0
*
*/
public class BasicIdentity implements Serializable {
@Data
@FieldNameConstants
public abstract class BaseIdentity implements Serializable {
private static final long serialVersionUID = 8080689271400316984L;
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public static class Fields {}
private String pubkey;
private String signature;
private String uid;
public String getPubkey() {
return pubkey;
}
public void setPubkey(String pubkey) {
this.pubkey = pubkey;
}
public String getSignature() {
return signature;
}
public void setSignature(String signature) {
this.signature = signature;
}
@JsonIgnore
@Deprecated
public String getSelf() {
return signature;
}
@JsonIgnore
@Deprecated
public void setSelf(String signature) {
this.signature = signature;
}
public String getUid() {
return uid;
}
public void setUid(String uid) {
this.uid = uid;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder()
......
package org.duniter.core.client.model;
/*
* #%L
* UCoin Java Client :: Core API
* %%
* Copyright (C) 2014 - 2015 EIS
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/
import org.duniter.core.client.model.local.Peer;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* Created by eis on 05/02/15.
*/
public class Currency implements Serializable {
private List<Peer> peers = new ArrayList<Peer>();
private Long id;
private String currencyName;
private Integer membersCount;
private String firstBlockSignature;
private Account account;
private Long accountId;
private String[] tags;
private String senderPubkey;
private Long lastUD;
public Currency() {
}
public Currency(String currencyName,
String firstBlockSignature,
int membersCount,
List<Peer> peers) {
this.currencyName = currencyName;
this.firstBlockSignature = firstBlockSignature;
this.membersCount = membersCount;
this.peers = peers;
}
public Currency(String currencyName,
String firstBlockSignature,
List<Peer> peers) {
this.currencyName = currencyName;
this.firstBlockSignature = firstBlockSignature;
this.membersCount = null;
this.peers = peers;
}
public Long getId() {
return id;
}
public String getCurrencyName()
{
return currencyName;
}
public Integer getMembersCount() {
return membersCount;
}
public String getFirstBlockSignature() {
return firstBlockSignature;
}
public List<Peer> getPeers() {
return peers;
}
public void addPeer(Peer peer) {
this.peers.add(peer);
}
public void setPeers(List<Peer> peers) {
this.peers = peers;
}
public void setId(Long id) {
this.id = id;
}
public void setCurrencyName(String currencyName) {
this.currencyName = currencyName;
}
public void setMembersCount(Integer membersCount) {
this.membersCount = membersCount;
}
public void setFirstBlockSignature(String firstBlockSignature) {
this.firstBlockSignature = firstBlockSignature;
}
public Account getAccount() {
return account;
}
public void setAccount(Account account) {
this.account = account;
}
public Long getAccountId() {
return accountId;
}
public void setAccountId(Long accountId) {
this.accountId = accountId;
}
public String toString() {
return currencyName;
}
public String[] getTags() {
return tags;
}
public void setTags(String[] tags) {
this.tags = tags;
}
public String getSenderPubkey() {
return senderPubkey;
}
public void setSenderPubkey(String senderPubkey) {
this.senderPubkey = senderPubkey;
}
}
\ No newline at end of file