made port configurable, 8444 default
This commit is contained in:
parent
1fc29e9916
commit
f06f7f0243
5
.gitignore
vendored
5
.gitignore
vendored
@ -1,5 +1,8 @@
|
|||||||
# Created by https://www.gitignore.io
|
# Project specific files
|
||||||
*list.conf
|
*list.conf
|
||||||
|
config.properties
|
||||||
|
|
||||||
|
# Created by https://www.gitignore.io
|
||||||
|
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
|
@ -28,6 +28,8 @@ import ch.dissem.bitmessage.repository.JdbcMessageRepository;
|
|||||||
import ch.dissem.bitmessage.security.bc.BouncySecurity;
|
import ch.dissem.bitmessage.security.bc.BouncySecurity;
|
||||||
import ch.dissem.bitmessage.server.entities.Broadcasts;
|
import ch.dissem.bitmessage.server.entities.Broadcasts;
|
||||||
import ch.dissem.bitmessage.server.entities.Message;
|
import ch.dissem.bitmessage.server.entities.Message;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||||
@ -35,15 +37,26 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@RestController
|
@RestController
|
||||||
@EnableAutoConfiguration
|
@EnableAutoConfiguration
|
||||||
public class JabitServerApplication {
|
public class JabitServerApplication {
|
||||||
|
private static final Logger LOG = LoggerFactory.getLogger(JabitServerApplication.class);
|
||||||
|
|
||||||
|
private static final String CONFIG_FILE = "config.properties";
|
||||||
|
private static final String PROPERTY_PORT = "port";
|
||||||
|
|
||||||
private static final int SHORTLIST_SIZE = 5;
|
private static final int SHORTLIST_SIZE = 5;
|
||||||
|
|
||||||
private final Set<String> whitelist;
|
private final Set<String> whitelist;
|
||||||
private final Set<String> shortlist;
|
private final Set<String> shortlist;
|
||||||
private final Set<String> blacklist;
|
private final Set<String> blacklist;
|
||||||
@ -101,7 +114,28 @@ public class JabitServerApplication {
|
|||||||
"blacklist.conf",
|
"blacklist.conf",
|
||||||
"# Bitmessage addresses in this file are being ignored and their broadcasts won't be returned.\n"
|
"# Bitmessage addresses in this file are being ignored and their broadcasts won't be returned.\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Properties properties = new Properties();
|
||||||
|
int port = 8444;
|
||||||
|
try {
|
||||||
|
properties.load(new FileInputStream(CONFIG_FILE));
|
||||||
|
String portProperty = properties.getProperty(PROPERTY_PORT);
|
||||||
|
if (portProperty != null) {
|
||||||
|
port = Integer.parseInt(portProperty);
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException ignore) {
|
||||||
|
try {
|
||||||
|
properties.setProperty(PROPERTY_PORT, String.valueOf(port));
|
||||||
|
properties.store(new FileOutputStream(CONFIG_FILE), null);
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.warn("Couldn't save default config file", e);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOG.error("Couldn't load config, using defaults", e);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
LOG.error("Couldn't read port property - is it a number?", e);
|
||||||
|
}
|
||||||
|
|
||||||
JdbcConfig config = new JdbcConfig();
|
JdbcConfig config = new JdbcConfig();
|
||||||
ctx = new BitmessageContext.Builder()
|
ctx = new BitmessageContext.Builder()
|
||||||
.addressRepo(new JdbcAddressRepository(config))
|
.addressRepo(new JdbcAddressRepository(config))
|
||||||
@ -110,7 +144,7 @@ public class JabitServerApplication {
|
|||||||
.nodeRegistry(new MemoryNodeRegistry())
|
.nodeRegistry(new MemoryNodeRegistry())
|
||||||
.networkHandler(new DefaultNetworkHandler())
|
.networkHandler(new DefaultNetworkHandler())
|
||||||
.security(new BouncySecurity())
|
.security(new BouncySecurity())
|
||||||
.port(8445)
|
.port(port)
|
||||||
.build();
|
.build();
|
||||||
ctx.startup(plaintext -> {
|
ctx.startup(plaintext -> {
|
||||||
});
|
});
|
||||||
|
@ -9,4 +9,6 @@ gulp_default.dependsOn 'installGulp'
|
|||||||
gulp_default.dependsOn 'npmInstall'
|
gulp_default.dependsOn 'npmInstall'
|
||||||
|
|
||||||
// runs "gulp build" as part of your gradle build
|
// runs "gulp build" as part of your gradle build
|
||||||
task (build, dependsOn: gulp_default) {}
|
task build {
|
||||||
|
dependsOn gulp_default
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user