Clean properties and add protocol version

This commit is contained in:
nicksavers 2014-10-06 11:18:15 +02:00
parent 4f901c8d16
commit ea5214912f
4 changed files with 255 additions and 192 deletions

View File

@ -13,63 +13,64 @@ import org.slf4j.LoggerFactory;
/**
* Utility class to retrieve property values from the system.properties files
*
* @author Roman Mandeleil
* @author Roman Mandeleil
* Created on: 22/05/2014 19:22
*/
public class SystemProperties {
private static Logger logger = LoggerFactory.getLogger(SystemProperties.class);
private static int DEFAULT_TX_APPROVE_TIMEOUT = 10;
private static String DEFAULT_DISCOVERY_PEER_LIST = "poc-6.ethdev.com:30303";
private static String DEFAULT_ACTIVE_PEER_IP = "poc-6.ethdev.com";
private static int DEFAULT_ACTIVE_PORT = 30303;
private static String DEFAULT_SAMPLES_DIR = "samples";
private static String DEFAULT_COINBASE_SECRET = "monkey";
private static int DEFAULT_ACTIVE_PEER_CHANNEL_TIMEOUT = 5;
private static Boolean DEFAULT_DB_RESET = false;
private static Boolean DEFAULT_DUMP_FULL = false;
private static String DEFAULT_DUMP_DIR = "dmp";
private static String DEFAULT_DUMP_STYLE = "standard+";
private static Integer DEFAULT_VMTRACE_BLOCK = 0;
private static String DEFAULT_DATABASE_DIR = System.getProperty("user.dir");
private static Boolean DEFAULT_DUMP_CLEAN_ON_RESTART = true;
private static Boolean DEFAULT_PLAY_VM = true;
private static Boolean DEFAULT_BLOCKCHAIN_ONLY = false;
private static int DEFAULT_TRACE_STARTBLOCK = -1;
private static int DEFAULT_MAX_HASHES_ASK = -1; // unlimited
private static byte DEFAULT_MAX_BLOCKS_ASK = 10;
private static int DEFAULT_MAX_BLOCKS_QUEUED = 300;
private static String DEFAULT_PROJECT_VERSION = "";
private static String DEFAULT_HELLO_PHRASE = "Dev";
private static Logger logger = LoggerFactory.getLogger(SystemProperties.class);
private static int DEFAULT_TX_APPROVE_TIMEOUT = 10;
private static int DEFAULT_PROTOCOL_VERSION = 33;
private static String DEFAULT_DISCOVERY_PEER_LIST = "poc-6.ethdev.com:30303";
private static String DEFAULT_ACTIVE_PEER_IP = "poc-6.ethdev.com";
private static int DEFAULT_ACTIVE_PORT = 30303;
private static String DEFAULT_SAMPLES_DIR = "samples";
private static String DEFAULT_COINBASE_SECRET = "monkey";
private static int DEFAULT_ACTIVE_PEER_CHANNEL_TIMEOUT = 5;
private static Boolean DEFAULT_DB_RESET = false;
private static Boolean DEFAULT_DUMP_FULL = false;
private static String DEFAULT_DUMP_DIR = "dmp";
private static String DEFAULT_DUMP_STYLE = "standard+";
private static Integer DEFAULT_VMTRACE_BLOCK = 0;
private static String DEFAULT_DATABASE_DIR = System.getProperty("user.dir");
private static Boolean DEFAULT_DUMP_CLEAN_ON_RESTART = true;
private static Boolean DEFAULT_PLAY_VM = true;
private static Boolean DEFAULT_BLOCKCHAIN_ONLY = false;
private static int DEFAULT_TRACE_STARTBLOCK = -1;
private static int DEFAULT_MAX_HASHES_ASK = -1; // unlimited
private static byte DEFAULT_MAX_BLOCKS_ASK = 10;
private static int DEFAULT_MAX_BLOCKS_QUEUED = 300;
private static String DEFAULT_PROJECT_VERSION = "";
private static String DEFAULT_HELLO_PHRASE = "Dev";
public static SystemProperties CONFIG = new SystemProperties();
private Properties prop = new Properties();
private InputStream input = null;
public SystemProperties() {
try {
String userDir = System.getProperty("user.dir");
String fileName = userDir + "/config/system.properties";
File file = new File(fileName);
private Properties prop = new Properties();
private InputStream input = null;
if (file.exists()) {
input = new FileInputStream(file);
public SystemProperties() {
try {
String userDir = System.getProperty("user.dir");
String fileName = userDir + "/config/system.properties";
File file = new File(fileName);
if (file.exists()) {
input = new FileInputStream(file);
} else {
fileName = "system.properties";
input = SystemProperties.class.getClassLoader().getResourceAsStream(fileName);
if (input == null) {
logger.error("Sorry, unable to find {}", fileName);
return;
}
}
//load a properties file from class path, inside static method
prop.load(input);
fileName = "system.properties";
input = SystemProperties.class.getClassLoader()
.getResourceAsStream(fileName);
if (input == null) {
logger.error("Sorry, unable to find {}", fileName);
return;
}
}
// load a properties file from class path, inside static method
prop.load(input);
} catch (IOException ex) {
logger.error(ex.getMessage(), ex);
} catch (IOException ex) {
logger.error(ex.getMessage(), ex);
} finally {
if (input != null) {
try {
@ -81,100 +82,143 @@ public class SystemProperties {
}
}
public int protocolVersion() {
if (prop.isEmpty()) return DEFAULT_PROTOCOL_VERSION;
return Integer.parseInt(prop.getProperty("protocol.version"));
}
public boolean peerDiscovery() {
if (prop.isEmpty())
return true;
if (prop.isEmpty()) return true;
return Boolean.parseBoolean(prop.getProperty("peer.discovery"));
}
public int peerDiscoveryWorkers() {
if(prop.isEmpty()) return 2;
public int peerDiscoveryWorkers() {
if (prop.isEmpty()) return 2;
return Integer.parseInt(prop.getProperty("peer.discovery.workers"));
}
}
public int peerConnectionTimeout() {
if (prop.isEmpty())
return 10000;
public int peerConnectionTimeout() {
if (prop.isEmpty()) return 10000;
return Integer.parseInt(prop.getProperty("peer.connection.timeout")) * 1000;
}
}
public int transactionApproveTimeout() {
if (prop.isEmpty())
return DEFAULT_TX_APPROVE_TIMEOUT;
return Integer.parseInt(prop.getProperty("transaction.approve.timeout"));
}
public int transactionApproveTimeout() {
if (prop.isEmpty()) return DEFAULT_TX_APPROVE_TIMEOUT;
return Integer.parseInt(prop.getProperty("transaction.approve.timeout"));
}
public String peerDiscoveryIPList() {
if(prop.isEmpty()) return DEFAULT_DISCOVERY_PEER_LIST;
return prop.getProperty("peer.discovery.ip.list");
}
public String peerDiscoveryIPList() {
if (prop.isEmpty()) return DEFAULT_DISCOVERY_PEER_LIST;
return prop.getProperty("peer.discovery.ip.list");
}
public boolean databaseReset() {
if(prop.isEmpty()) return DEFAULT_DB_RESET;
return Boolean.parseBoolean(prop.getProperty("database.reset"));
}
public boolean databaseReset() {
if (prop.isEmpty()) return DEFAULT_DB_RESET;
return Boolean.parseBoolean(prop.getProperty("database.reset"));
}
public String activePeerIP() {
if(prop.isEmpty()) return DEFAULT_ACTIVE_PEER_IP;
return prop.getProperty("peer.active.ip");
}
public String activePeerIP() {
if (prop.isEmpty()) return DEFAULT_ACTIVE_PEER_IP;
return prop.getProperty("peer.active.ip");
}
public int activePeerPort() {
if(prop.isEmpty()) return DEFAULT_ACTIVE_PORT;
return Integer.parseInt(prop.getProperty("peer.active.port"));
}
public int activePeerPort() {
if (prop.isEmpty()) return DEFAULT_ACTIVE_PORT;
return Integer.parseInt(prop.getProperty("peer.active.port"));
}
public String samplesDir() {
if(prop.isEmpty()) return DEFAULT_SAMPLES_DIR;
return prop.getProperty("samples.dir");
}
public String samplesDir() {
if (prop.isEmpty()) return DEFAULT_SAMPLES_DIR;
return prop.getProperty("samples.dir");
}
public String coinbaseSecret() {
if(prop.isEmpty()) return DEFAULT_COINBASE_SECRET;
return prop.getProperty("coinbase.secret");
}
public String coinbaseSecret() {
if (prop.isEmpty()) return DEFAULT_COINBASE_SECRET;
return prop.getProperty("coinbase.secret");
}
public Integer peerChannelReadTimeout() {
if(prop.isEmpty()) return DEFAULT_ACTIVE_PEER_CHANNEL_TIMEOUT;
return Integer.parseInt(prop.getProperty("peer.channel.read.timeout"));
}
public Integer peerChannelReadTimeout() {
if (prop.isEmpty()) return DEFAULT_ACTIVE_PEER_CHANNEL_TIMEOUT;
return Integer.parseInt(prop.getProperty("peer.channel.read.timeout"));
}
public Integer traceStartBlock() {
if(prop.isEmpty()) return DEFAULT_TRACE_STARTBLOCK;
return Integer.parseInt(prop.getProperty("trace.startblock"));
}
public Integer traceStartBlock() {
if (prop.isEmpty()) return DEFAULT_TRACE_STARTBLOCK;
return Integer.parseInt(prop.getProperty("trace.startblock"));
}
public Boolean dumpFull() {
if (prop.isEmpty()) return DEFAULT_DUMP_FULL;
return Boolean.parseBoolean(prop.getProperty("dump.full"));
}
public Boolean dumpFull() {
if(prop.isEmpty()) return DEFAULT_DUMP_FULL;
return Boolean.parseBoolean(prop.getProperty("dump.full"));
}
public String dumpDir() {
if (prop.isEmpty()) return DEFAULT_DUMP_DIR;
return prop.getProperty("dump.dir");
}
public String dumpDir() {
if(prop.isEmpty()) return DEFAULT_DUMP_DIR;
return prop.getProperty("dump.dir");
}
public String dumpStyle() {
if (prop.isEmpty()) return DEFAULT_DUMP_STYLE;
return prop.getProperty("dump.style");
}
public String dumpStyle() {
if(prop.isEmpty()) return DEFAULT_DUMP_STYLE;
return prop.getProperty("dump.style");
}
public Integer dumpBlock() {
if(prop.isEmpty()) return DEFAULT_VMTRACE_BLOCK;
return Integer.parseInt(prop.getProperty("dump.block"));
}
public String databaseDir() {
if(prop.isEmpty()) return DEFAULT_DATABASE_DIR;
return prop.getProperty("database.dir");
}
public Integer dumpBlock() {
if (prop.isEmpty()) return DEFAULT_VMTRACE_BLOCK;
return Integer.parseInt(prop.getProperty("dump.block"));
}
public Boolean dumpCleanOnRestart() {
if(prop.isEmpty()) return DEFAULT_DUMP_CLEAN_ON_RESTART;
public String databaseDir() {
if (prop.isEmpty()) return DEFAULT_DATABASE_DIR;
return prop.getProperty("database.dir");
}
public Boolean dumpCleanOnRestart() {
if (prop.isEmpty()) return DEFAULT_DUMP_CLEAN_ON_RESTART;
return Boolean.parseBoolean(prop.getProperty("dump.clean.on.restart"));
}
}
public Boolean playVM() {
if (prop.isEmpty()) return DEFAULT_PLAY_VM;
return Boolean.parseBoolean(prop.getProperty("play.vm"));
}
public Boolean blockChainOnly() {
if (prop.isEmpty()) return DEFAULT_BLOCKCHAIN_ONLY;
return Boolean.parseBoolean(prop.getProperty("blockchain.only"));
}
public Integer maxHashesAsk() {
if (prop.isEmpty()) return DEFAULT_MAX_HASHES_ASK;
return Integer.parseInt(prop.getProperty("max.hashes.ask"));
}
public Byte maxBlocksAsk() {
if (prop.isEmpty()) return DEFAULT_MAX_BLOCKS_ASK;
return Byte.parseByte(prop.getProperty("max.blocks.ask"));
}
public Integer maxBlocksQueued() {
if (prop.isEmpty()) return DEFAULT_MAX_BLOCKS_QUEUED;
return Integer.parseInt(prop.getProperty("max.blocks.queued"));
}
public String projectVersion() {
if (prop.isEmpty()) return DEFAULT_PROJECT_VERSION;
return prop.getProperty("project.version");
}
public String helloPhrase() {
if (prop.isEmpty()) return DEFAULT_HELLO_PHRASE;
return prop.getProperty("hello.phrase");
}
public String rootHashStart() {
if (prop.isEmpty()) return null;
String hash = prop.getProperty("root.hash.start");
if (hash == null || hash.equals("-1"))
return null;
return hash;
}
public void print() {
Enumeration<?> e = prop.propertyNames();
@ -185,52 +229,9 @@ public class SystemProperties {
logger.info("Key: " + key + ", Value: " + value);
}
}
public Boolean playVM() {
if(prop.isEmpty()) return DEFAULT_PLAY_VM;
return Boolean.parseBoolean(prop.getProperty("play.vm"));
}
public Boolean blockChainOnly() {
if(prop.isEmpty()) return DEFAULT_BLOCKCHAIN_ONLY;
return Boolean.parseBoolean(prop.getProperty("blockchain.only"));
}
public Integer maxHashesAsk() {
if(prop.isEmpty()) return DEFAULT_MAX_HASHES_ASK;
return Integer.parseInt(prop.getProperty("max.hashes.ask"));
}
public Byte maxBlocksAsk() {
if(prop.isEmpty()) return DEFAULT_MAX_BLOCKS_ASK;
return Byte.parseByte(prop.getProperty("max.blocks.ask"));
}
public Integer maxBlocksQueued() {
if(prop.isEmpty()) return DEFAULT_MAX_BLOCKS_QUEUED;
return Integer.parseInt(prop.getProperty("max.blocks.queued"));
}
public String projectVersion() {
if(prop.isEmpty()) return DEFAULT_PROJECT_VERSION;
return prop.getProperty("project.version");
}
public String helloPhrase() {
if(prop.isEmpty()) return DEFAULT_HELLO_PHRASE;
return prop.getProperty("hello.phrase");
}
public String rootHashStart() {
if(prop.isEmpty()) return null;
String hash = prop.getProperty("root.hash.start");
if (hash == null || hash.equals("-1")) return null;
return prop.getProperty("root.hash.start");
}
public static void main(String args[]) {
SystemProperties systemProperties = new SystemProperties();
systemProperties.print();
}
}
public static void main(String args[]) {
SystemProperties systemProperties = new SystemProperties();
systemProperties.print();
}
}

View File

@ -6,9 +6,8 @@ server.acceptConnections = false
# the search of the online peers
# values: [ip:port, ip:port, ip:port ...]
peer.discovery.ip.list = poc-6.ethdev.com:30303,\
54.204.10.41:30303,\
213.46.28.223:30303
54.204.10.41:30303
# Peer Server Zero (poc-6.ethdev.com)
peer.active.ip = 207.12.89.101
peer.active.port = 30303
@ -25,10 +24,17 @@ peer.active.port = 30303
#peer.active.ip = 213.46.28.223
#peer.active.port = 30303
# VM
#peer.active.ip = 192.168.1.193
#peer.active.port = 30303
# Localhost
#peer.active.ip = 127.0.0.1
#peer.active.port = 30303
# Version of Ethereum sub-protocol
protocol.version = 33
# specify if the mechanism
# to discover more and more
# peers and check the already
@ -109,10 +115,17 @@ trace.startblock = -1
# occurs anyway [true/false]
play.vm = true
# maximum blocks hashes to ask.
# sending GET_BLOCK_HASHES msg
# we specify number of block we want
# to get, recomendec value [1..1000]
# Default: unlimited
max.hashes.ask = 1000
# maximum blocks to ask,
# when downloading the chain
# sequenteally sending GET_CHAIN msg
# we specify number of block we want
# sequenteally sending GET_BLOCKS msg
# we specify number of blocks we want
# to get, recomendec value [1..100]
max.blocks.ask = 100
@ -125,11 +138,11 @@ max.blocks.ask = 100
max.blocks.queued = 300
# project version auto copied during build phase
project.version = PROJECT.VERSION
project.version = 0.6.0
# hello phrase will be included in
# the hello message of the peer
hello.phrase = RJ
hello.phrase = Dev
# this property used
# mostly for a debug purpose
@ -141,4 +154,4 @@ hello.phrase = RJ
# but any manual hash this property will help.
# values [-1] - load from db
# [hex hash 32 bytes] root hash
root.hash.start = -1
root.hash.start = -1

View File

@ -6,9 +6,8 @@ server.acceptConnections = false
# the search of the online peers
# values: [ip:port, ip:port, ip:port ...]
peer.discovery.ip.list = poc-6.ethdev.com:30303,\
54.204.10.41:30303,\
213.46.28.223:30303
54.204.10.41:30303
# Peer Server Zero (poc-6.ethdev.com)
peer.active.ip = 207.12.89.101
peer.active.port = 30303
@ -25,10 +24,17 @@ peer.active.port = 30303
#peer.active.ip = 213.46.28.223
#peer.active.port = 30303
# VM
#peer.active.ip = 192.168.1.193
#peer.active.port = 30303
# Localhost
#peer.active.ip = 127.0.0.1
#peer.active.port = 30303
# Version of Ethereum sub-protocol
protocol.version = 33
# specify if the mechanism
# to discover more and more
# peers and check the already
@ -53,7 +59,7 @@ peer.connection.timeout = 2
# transaction got approved when
# include into a transactions msg
# retrieved from the peer [seconds]
transaction.approve.timeout = 15
transaction.approve.timeout = 3
# the parameter specifies how much
# time we will wait for a message
@ -71,6 +77,9 @@ samples.dir = samples
# downloaded from peers again
database.reset = true
# place to save physical storage files
database.dir = database
# this string is computed
# to be eventually the address
# that get the miner reward
@ -80,10 +89,16 @@ coinbase.secret = monkey
# all the state will be dumped
# in JSON form to [dump.dir]
# if [dump.full] = true
# posible values [true/false]
# possible values [true/false]
dump.full = false
dump.dir = dmp
dump.block = 1501
# This defines the vmtrace dump
# to the console and the style
# -1 for no block trace
# styles: [pretty/standard+] (default: standard+)
dump.block = -1
dump.style = pretty
# clean the dump dir each start
dump.clean.on.restart = true
@ -100,10 +115,17 @@ trace.startblock = -1
# occurs anyway [true/false]
play.vm = true
# maximum blocks hashes to ask.
# sending GET_BLOCK_HASHES msg
# we specify number of block we want
# to get, recomendec value [1..1000]
# Default: unlimited
max.hashes.ask = 1000
# maximum blocks to ask,
# when downloading the chain
# sequenteally sending GET_CHAIN msg
# we specify number of block we want
# sequenteally sending GET_BLOCKS msg
# we specify number of blocks we want
# to get, recomendec value [1..100]
max.blocks.ask = 100
@ -116,8 +138,20 @@ max.blocks.ask = 100
max.blocks.queued = 300
# project version auto copied during build phase
project.version = PROJECT.VERSION
project.version = 0.6.0
# hello phrase will be included in
# the hello message of the peer
hello.phrase =
hello.phrase = Dev
# this property used
# mostly for a debug purpose
# so if you don't know exactly how
# to apply it leave to be [-1]
#
# ADVANCED: if we want to load a root hash
# for db not from the saved block chain (last block)
# but any manual hash this property will help.
# values [-1] - load from db
# [hex hash 32 bytes] root hash
root.hash.start = -1

View File

@ -9,16 +9,16 @@ peer.discovery.ip.list = poc-6.ethdev.com:30303,\
54.204.10.41:30303
# Peer Server Zero (poc-6.ethdev.com)
#peer.active.ip = 207.12.89.101
#peer.active.port = 30303
peer.active.ip = 207.12.89.101
peer.active.port = 30303
# ZeroGox
#peer.active.ip = 54.204.10.41
#peer.active.port = 30303
# Winslave
peer.active.ip = 185.43.109.23
peer.active.port = 30303
#peer.active.ip = 185.43.109.23
#peer.active.port = 30303
# Mist
#peer.active.ip = 213.46.28.223
@ -26,12 +26,15 @@ peer.active.port = 30303
# VM
#peer.active.ip = 192.168.1.193
#peer.active.port = 30305
#peer.active.port = 30303
# Localhost
#peer.active.ip = 127.0.0.1
#peer.active.port = 30303
# Version of Ethereum sub-protocol
protocol.version = 33
# specify if the mechanism
# to discover more and more
# peers and check the already
@ -139,4 +142,16 @@ project.version = 0.6.0
# hello phrase will be included in
# the hello message of the peer
hello.phrase = Dev
hello.phrase = Dev
# this property used
# mostly for a debug purpose
# so if you don't know exactly how
# to apply it leave to be [-1]
#
# ADVANCED: if we want to load a root hash
# for db not from the saved block chain (last block)
# but any manual hash this property will help.
# values [-1] - load from db
# [hex hash 32 bytes] root hash
root.hash.start = -1