From a1541dd51b5deaf337995989988cb8e61c8297e0 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Wed, 11 Jan 2017 17:24:47 +0100 Subject: [PATCH] Updated Jabit version, improved configuration --- .gitignore | 1 + build.gradle | 4 +- .../bitmessage/server/JabitServerConfig.java | 45 ++++++++++++++++--- .../server/ProofOfWorkRequestHandler.java | 4 +- src/main/resources/application.properties | 3 ++ 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 0d42f5d..074809c 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,7 @@ config.properties ### Gradle ### .gradle build/ +classes/ # Ignore Gradle GUI config gradle-app.setting diff --git a/build.gradle b/build.gradle index b6cc1f5..ff01ea1 100644 --- a/build.gradle +++ b/build.gradle @@ -33,7 +33,7 @@ configurations { providedRuntime } -ext.jabitVersion = '1.0.0' +ext.jabitVersion = 'development-SNAPSHOT' dependencies { compile("org.springframework.boot:spring-boot-starter-hateoas") compile("org.springframework.boot:spring-boot-starter-jersey") @@ -44,7 +44,7 @@ dependencies { compile "ch.dissem.jabit:jabit-core:$jabitVersion" compile "ch.dissem.jabit:jabit-networking:$jabitVersion" compile "ch.dissem.jabit:jabit-repositories:$jabitVersion" - compile "ch.dissem.jabit:jabit-cryptography-bouncy:$jabitVersion" + compile "ch.dissem.jabit:jabit-cryptography-spongy:$jabitVersion" compile "ch.dissem.jabit:jabit-extensions:$jabitVersion" compile 'com.h2database:h2:1.4.187' diff --git a/src/main/java/ch/dissem/bitmessage/server/JabitServerConfig.java b/src/main/java/ch/dissem/bitmessage/server/JabitServerConfig.java index f234ef2..1ac3866 100644 --- a/src/main/java/ch/dissem/bitmessage/server/JabitServerConfig.java +++ b/src/main/java/ch/dissem/bitmessage/server/JabitServerConfig.java @@ -17,19 +17,23 @@ package ch.dissem.bitmessage.server; import ch.dissem.bitmessage.BitmessageContext; -import ch.dissem.bitmessage.cryptography.bc.BouncyCryptography; +import ch.dissem.bitmessage.cryptography.sc.SpongyCryptography; import ch.dissem.bitmessage.entity.BitmessageAddress; -import ch.dissem.bitmessage.networking.DefaultNetworkHandler; +import ch.dissem.bitmessage.entity.payload.Pubkey; +import ch.dissem.bitmessage.networking.nio.NioNetworkHandler; import ch.dissem.bitmessage.ports.*; import ch.dissem.bitmessage.repository.*; import ch.dissem.bitmessage.server.repository.ServerProofOfWorkRepository; import ch.dissem.bitmessage.utils.Singleton; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; +import java.util.List; import java.util.Set; import static ch.dissem.bitmessage.server.Constants.*; @@ -37,6 +41,8 @@ import static java.util.stream.Collectors.toSet; @Configuration public class JabitServerConfig { + private static final Logger LOG = LoggerFactory.getLogger(JabitServerConfig.class); + public static final int SHORTLIST_SIZE = 5; @Value("${bitmessage.port}") @@ -46,9 +52,16 @@ public class JabitServerConfig { @Value("${bitmessage.connection.limit}") private int connectionLimit; + @Value("${database.url}") + private String dbUrl; + @Value("${database.user}") + private String dbUser; + @Value("${database.password}") + private String dbPassword; + @Bean public JdbcConfig jdbcConfig() { - return new JdbcConfig("jdbc:h2:file:./jabit;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=10", "sa", null); + return new JdbcConfig(dbUrl, dbUser, dbPassword); } @Bean @@ -73,17 +86,17 @@ public class JabitServerConfig { @Bean public NodeRegistry nodeRegistry() { - return new MemoryNodeRegistry(); + return new JdbcNodeRegistry(jdbcConfig()); } @Bean public NetworkHandler networkHandler() { - return new DefaultNetworkHandler(); + return new NioNetworkHandler(); } @Bean public Cryptography cryptography() { - BouncyCryptography cryptography = new BouncyCryptography(); + Cryptography cryptography = new SpongyCryptography(); Singleton.initialize(cryptography); // needed for admins and clients return cryptography; } @@ -97,6 +110,7 @@ public class JabitServerConfig { public ServerProofOfWorkRepository serverProofOfWorkRepository() { return new ServerProofOfWorkRepository(jdbcConfig()); } + @Bean public CustomCommandHandler commandHandler() { return new ProofOfWorkRequestHandler(serverProofOfWorkRepository(), clients()); @@ -173,4 +187,23 @@ public class JabitServerConfig { .select() .build(); } + + @Bean + public BitmessageAddress identity() { + List identities = bitmessageContext().addresses().getIdentities(); + BitmessageAddress identity; + if (identities.isEmpty()) { + LOG.info("Creating new identity..."); + identity = bitmessageContext().createIdentity(false, Pubkey.Feature.DOES_ACK); + LOG.info("Identity " + identity.getAddress() + " created."); + } else { + LOG.info("Identities:"); + identities.stream().map(BitmessageAddress::getAddress).forEach(LOG::info); + identity = identities.get(0); + if (identities.size() > 1) { + LOG.info("Using " + identity); + } + } + return identity; + } } diff --git a/src/main/java/ch/dissem/bitmessage/server/ProofOfWorkRequestHandler.java b/src/main/java/ch/dissem/bitmessage/server/ProofOfWorkRequestHandler.java index ab98b10..c953e3b 100644 --- a/src/main/java/ch/dissem/bitmessage/server/ProofOfWorkRequestHandler.java +++ b/src/main/java/ch/dissem/bitmessage/server/ProofOfWorkRequestHandler.java @@ -131,8 +131,8 @@ public class ProofOfWorkRequestHandler implements CustomCommandHandler, Internal final BitmessageAddress identity = new BitmessageAddress(new PrivateKey( false, context.getStreams()[0], - context.getNetworkNonceTrialsPerByte(), - context.getNetworkExtraBytes() + InternalContext.NETWORK_NONCE_TRIALS_PER_BYTE, + InternalContext.NETWORK_EXTRA_BYTES )); context.getAddressRepository().save(identity); return identity; diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 1242dbb..815acd7 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -4,3 +4,6 @@ logging.level.ch.dissem.*=WARN bitmessage.port=8444 bitmessage.connection.ttl.hours=12 bitmessage.connection.limit=100 +database.url=jdbc:h2:file:./jabit;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=10 +database.user=sa +database.password= \ No newline at end of file