diff --git a/src/main/java/com/iota/iri/IRI.java b/src/main/java/com/iota/iri/IRI.java index 718c5c595e..2f86d82827 100644 --- a/src/main/java/com/iota/iri/IRI.java +++ b/src/main/java/com/iota/iri/IRI.java @@ -70,6 +70,7 @@ private static void validateParams(final String[] args) { final Option cors = parser.addStringOption('c', "enabled-cors"); final Option headless = parser.addBooleanOption("headless"); final Option debug = parser.addBooleanOption('d', "debug"); + final Option remote = parser.addBooleanOption("remote"); final Option neighbors = parser.addStringOption('n', "neighbors"); final Option experimental = parser.addBooleanOption('e', "experimental"); final Option help = parser.addBooleanOption('h', "help"); @@ -117,6 +118,11 @@ private static void validateParams(final String[] args) { if (parser.getOptionValue(headless) != null) { Configuration.put(DefaultConfSettings.HEADLESS, "true"); } + + if (parser.getOptionValue(remote) != null) { + log.info("Remote access enabled. Binding API socket to listen any interface."); + Configuration.put(DefaultConfSettings.API_HOST, "0.0.0.0"); + } if (parser.getOptionValue(debug) != null) { Configuration.put(DefaultConfSettings.DEBUG, "true"); @@ -140,7 +146,9 @@ private static void printUsage() { "[{-r,--receiver-port} 14265] " + "[{-c,--enabled-cors} *] " + "[{-h}] [{--headless}] " + - "[{-d,--debug}] [{-e,--experimental}]" + + "[{-d,--debug}] " + + "[{-e,--experimental}]" + + "[{--remote}]" + // + "[{-t,--testnet} false] " // -> TBDiscussed (!) "[{-n,--neighbors} ''] ", NAME, VERSION); System.exit(0); @@ -170,7 +178,7 @@ private static void showIotaLogo() { final Path path = Paths.get("logo.ans"); Files.readAllLines(path, Charset.forName(charset)).forEach(log::info); } catch (IOException e) { - log.error("Impossible to display logo. Charset {} not supported.", charset); + log.error("Impossible to display logo. Charset {} not supported by terminal.", charset); } } } diff --git a/src/main/java/com/iota/iri/conf/Configuration.java b/src/main/java/com/iota/iri/conf/Configuration.java index 86c2743d51..6e053c0899 100644 --- a/src/main/java/com/iota/iri/conf/Configuration.java +++ b/src/main/java/com/iota/iri/conf/Configuration.java @@ -18,6 +18,7 @@ public class Configuration { public enum DefaultConfSettings { API_PORT, + API_HOST, TANGLE_RECEIVER_PORT, CORS_ENABLED, TESTNET, // not used yet @@ -30,6 +31,7 @@ public enum DefaultConfSettings { static { // defaults conf.put(DefaultConfSettings.API_PORT.name(), "14265"); + conf.put(DefaultConfSettings.API_HOST.name(), "localhost"); conf.put(DefaultConfSettings.TANGLE_RECEIVER_PORT.name(), "14265"); conf.put(DefaultConfSettings.CORS_ENABLED.name(), "*"); conf.put(DefaultConfSettings.TESTNET.name(), "false"); diff --git a/src/main/java/com/iota/iri/service/API.java b/src/main/java/com/iota/iri/service/API.java index 06dac228c9..b6b63949cb 100644 --- a/src/main/java/com/iota/iri/service/API.java +++ b/src/main/java/com/iota/iri/service/API.java @@ -80,9 +80,12 @@ public class API { public void init() throws IOException { - int apiPort = Configuration.integer(DefaultConfSettings.API_PORT); + final int apiPort = Configuration.integer(DefaultConfSettings.API_PORT); + final String apiHost = Configuration.string(DefaultConfSettings.API_HOST); - server = Undertow.builder().addHttpListener(apiPort, "localhost") + log.debug("Binding JSON-REST API Undertown server on {}:{}" , apiHost, apiPort); + + server = Undertow.builder().addHttpListener(apiPort, apiHost) .setHandler(path().addPrefixPath("/", new HttpHandler() { @Override public void handleRequest(final HttpServerExchange exchange) throws Exception {