Changed the way Jabit Server is configured (via application.properties)
This commit is contained in:
parent
ca2bb89cee
commit
d322d09604
@ -19,29 +19,20 @@ package ch.dissem.bitmessage.server;
|
||||
import ch.dissem.bitmessage.BitmessageContext;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
import ch.dissem.bitmessage.networking.DefaultNetworkHandler;
|
||||
import ch.dissem.bitmessage.ports.MemoryNodeRegistry;
|
||||
import ch.dissem.bitmessage.repository.JdbcAddressRepository;
|
||||
import ch.dissem.bitmessage.repository.JdbcConfig;
|
||||
import ch.dissem.bitmessage.repository.JdbcInventory;
|
||||
import ch.dissem.bitmessage.repository.JdbcMessageRepository;
|
||||
import ch.dissem.bitmessage.security.bc.BouncySecurity;
|
||||
import ch.dissem.bitmessage.server.entities.Broadcasts;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.Timer;
|
||||
|
||||
@ -50,7 +41,7 @@ import static ch.dissem.bitmessage.server.Converter.message;
|
||||
|
||||
@CrossOrigin
|
||||
@RestController
|
||||
@EnableAutoConfiguration
|
||||
@SpringBootApplication
|
||||
public class JabitServerApplication {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JabitServerApplication.class);
|
||||
|
||||
@ -61,9 +52,13 @@ public class JabitServerApplication {
|
||||
|
||||
private static final int SHORTLIST_SIZE = 5;
|
||||
|
||||
private final Set<String> whitelist;
|
||||
private final Set<String> shortlist;
|
||||
private final Set<String> blacklist;
|
||||
@Resource
|
||||
private Set<String> whitelist;
|
||||
@Resource
|
||||
private Set<String> shortlist;
|
||||
@Resource
|
||||
private Set<String> blacklist;
|
||||
@Inject
|
||||
private BitmessageContext ctx;
|
||||
|
||||
@RequestMapping("status")
|
||||
@ -100,60 +95,9 @@ public class JabitServerApplication {
|
||||
return broadcasts(broadcaster, messages);
|
||||
}
|
||||
|
||||
public JabitServerApplication() {
|
||||
whitelist = Utils.readOrCreateList(
|
||||
"whitelist.conf",
|
||||
"# If there are any Bitmessage addresses in the whitelist, only those will be shown.\n" +
|
||||
"# blacklist.conf will be ignored, but shortlist.conf will be applied to whitelisted addresses.\n"
|
||||
);
|
||||
shortlist = Utils.readOrCreateList(
|
||||
"shortlist.conf",
|
||||
"# Broadcasts of these addresses will be restricted to the last " + SHORTLIST_SIZE + " entries.\n\n" +
|
||||
"# Time Service:\n" +
|
||||
"BM-BcbRqcFFSQUUmXFKsPJgVQPSiFA3Xash\n\n" +
|
||||
"# Q's Aktivlist:\n" +
|
||||
"BM-GtT7NLCCAu3HrT7dNTUTY9iDns92Z2ND\n"
|
||||
);
|
||||
blacklist = Utils.readOrCreateList(
|
||||
"blacklist.conf",
|
||||
"# 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("jdbc:h2:file:jabit;AUTO_SERVER=TRUE", "sa", null);
|
||||
ctx = new BitmessageContext.Builder()
|
||||
.addressRepo(new JdbcAddressRepository(config))
|
||||
.inventory(new JdbcInventory(config))
|
||||
.messageRepo(new JdbcMessageRepository(config))
|
||||
.nodeRegistry(new MemoryNodeRegistry())
|
||||
.networkHandler(new DefaultNetworkHandler())
|
||||
.security(new BouncySecurity())
|
||||
.port(port)
|
||||
.listener(plaintext -> {
|
||||
})
|
||||
.build();
|
||||
@PostConstruct
|
||||
public void setUp() {
|
||||
ctx.startup();
|
||||
|
||||
new Timer().scheduleAtFixedRate(new CleanupJob(ctx), 1 * HOUR, 24 * HOUR);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,74 @@
|
||||
package ch.dissem.bitmessage.server;
|
||||
|
||||
import ch.dissem.bitmessage.BitmessageContext;
|
||||
import ch.dissem.bitmessage.networking.DefaultNetworkHandler;
|
||||
import ch.dissem.bitmessage.ports.MemoryNodeRegistry;
|
||||
import ch.dissem.bitmessage.repository.JdbcAddressRepository;
|
||||
import ch.dissem.bitmessage.repository.JdbcConfig;
|
||||
import ch.dissem.bitmessage.repository.JdbcInventory;
|
||||
import ch.dissem.bitmessage.repository.JdbcMessageRepository;
|
||||
import ch.dissem.bitmessage.security.bc.BouncySecurity;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@Configuration
|
||||
public class JabitServerConfig {
|
||||
public static final int SHORTLIST_SIZE = 5;
|
||||
|
||||
@Value("${bitmessage.port}")
|
||||
private int port;
|
||||
@Value("${bitmessage.connection.ttl.hours}")
|
||||
private int connectionTTL;
|
||||
@Value("${bitmessage.connection.limit}")
|
||||
private int connectionLimit;
|
||||
|
||||
@Bean
|
||||
public BitmessageContext bitmessageContext() {
|
||||
JdbcConfig config = new JdbcConfig("jdbc:h2:file:./jabit;AUTO_SERVER=TRUE", "sa", null);
|
||||
return new BitmessageContext.Builder()
|
||||
.addressRepo(new JdbcAddressRepository(config))
|
||||
.inventory(new JdbcInventory(config))
|
||||
.messageRepo(new JdbcMessageRepository(config))
|
||||
.nodeRegistry(new MemoryNodeRegistry())
|
||||
.networkHandler(new DefaultNetworkHandler())
|
||||
.security(new BouncySecurity())
|
||||
.port(port)
|
||||
.connectionLimit(connectionLimit)
|
||||
.connectionTTL(connectionTTL)
|
||||
.listener(plaintext -> {
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Set<String> whitelist() {
|
||||
return Utils.readOrCreateList(
|
||||
"whitelist.conf",
|
||||
"# If there are any Bitmessage addresses in the whitelist, only those will be shown.\n" +
|
||||
"# blacklist.conf will be ignored, but shortlist.conf will be applied to whitelisted addresses.\n"
|
||||
);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Set<String> shortlist() {
|
||||
return Utils.readOrCreateList(
|
||||
"shortlist.conf",
|
||||
"# Broadcasts of these addresses will be restricted to the last " + SHORTLIST_SIZE + " entries.\n\n" +
|
||||
"# Time Service:\n" +
|
||||
"BM-BcbRqcFFSQUUmXFKsPJgVQPSiFA3Xash\n\n" +
|
||||
"# Q's Aktivlist:\n" +
|
||||
"BM-GtT7NLCCAu3HrT7dNTUTY9iDns92Z2ND\n"
|
||||
);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Set<String> blacklist() {
|
||||
return Utils.readOrCreateList(
|
||||
"blacklist.conf",
|
||||
"# Bitmessage addresses in this file are being ignored and their broadcasts won't be returned.\n"
|
||||
);
|
||||
}
|
||||
}
|
@ -1,3 +1,6 @@
|
||||
logging.file=jabit.log
|
||||
logging.level.*=ERROR
|
||||
logging.level.ch.dissem.*=WARN
|
||||
logging.level.ch.dissem.*=WARN
|
||||
bitmessage.port=8444
|
||||
bitmessage.connection.ttl.hours=12
|
||||
bitmessage.connection.limit=100
|
||||
|
6
src/test/resources/application.properties
Normal file
6
src/test/resources/application.properties
Normal file
@ -0,0 +1,6 @@
|
||||
logging.file=jabit.log
|
||||
logging.level.*=DEBUG
|
||||
logging.level.ch.dissem.*=WARN
|
||||
bitmessage.port=18444
|
||||
bitmessage.connection.ttl.hours=12
|
||||
bitmessage.connection.limit=100
|
Loading…
Reference in New Issue
Block a user