Skip to content

Commit

Permalink
Merge pull request #3061 from christophsturm/guice-core
Browse files Browse the repository at this point in the history
also fix singleton config for core module
  • Loading branch information
sqrrm authored Aug 13, 2019
2 parents e52c255 + a8494a9 commit 3cfe510
Show file tree
Hide file tree
Showing 26 changed files with 117 additions and 49 deletions.
3 changes: 3 additions & 0 deletions common/src/main/java/bisq/common/ClockWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package bisq.common;

import javax.inject.Singleton;

import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand All @@ -26,6 +28,7 @@
// Helps configure listener objects that are run by the `UserThread` each second
// and can do per second, per minute and delayed second actions. Also detects when we were in standby, and logs it.
@Slf4j
@Singleton
public class ClockWatcher {
public static final int IDLE_TOLERANCE_MS = 20000;

Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/bisq/common/crypto/KeyRing.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.common.crypto;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.bouncycastle.openpgp.PGPKeyPair;
import org.bouncycastle.openpgp.PGPPublicKey;
Expand All @@ -34,6 +35,7 @@
@Getter
@EqualsAndHashCode
@Slf4j
@Singleton
public class KeyRing {
private final KeyPair signatureKeyPair;
private final KeyPair encryptionKeyPair;
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/bisq/common/crypto/KeyStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.inject.Inject;

import javax.inject.Named;
import javax.inject.Singleton;

import org.bouncycastle.openpgp.PGPKeyPair;

Expand Down Expand Up @@ -56,6 +57,7 @@
import javax.annotation.Nullable;

// TODO: use a password protection for key storage
@Singleton
public class KeyStorage {
private static final Logger log = LoggerFactory.getLogger(KeyStorage.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.common.storage;

import javax.inject.Inject;
import javax.inject.Singleton;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -26,6 +27,7 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Singleton
public class CorruptedDatabaseFilesHandler {
private List<String> corruptedDatabaseFiles = new ArrayList<>();

Expand Down
51 changes: 4 additions & 47 deletions core/src/main/java/bisq/core/CoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,53 +19,33 @@

import bisq.core.alert.AlertModule;
import bisq.core.app.AppOptionKeys;
import bisq.core.app.AvoidStandbyModeService;
import bisq.core.app.BisqEnvironment;
import bisq.core.app.BisqSetup;
import bisq.core.app.P2PNetworkSetup;
import bisq.core.app.TorSetup;
import bisq.core.app.WalletAppSetup;
import bisq.core.arbitration.ArbitratorModule;
import bisq.core.btc.BitcoinModule;
import bisq.core.dao.DaoModule;
import bisq.core.filter.FilterModule;
import bisq.core.network.p2p.seed.DefaultSeedNodeRepository;
import bisq.core.notifications.MobileMessageEncryption;
import bisq.core.notifications.MobileModel;
import bisq.core.notifications.MobileNotificationService;
import bisq.core.notifications.MobileNotificationValidator;
import bisq.core.notifications.alerts.DisputeMsgEvents;
import bisq.core.notifications.alerts.MyOfferTakenEvents;
import bisq.core.notifications.alerts.TradeEvents;
import bisq.core.notifications.alerts.market.MarketAlerts;
import bisq.core.notifications.alerts.price.PriceAlert;
import bisq.core.offer.OfferModule;
import bisq.core.payment.TradeLimits;
import bisq.core.presentation.CorePresentationModule;
import bisq.core.proto.network.CoreNetworkProtoResolver;
import bisq.core.proto.persistable.CorePersistenceProtoResolver;
import bisq.core.trade.TradeModule;
import bisq.core.user.Preferences;
import bisq.core.user.User;

import bisq.network.crypto.EncryptionServiceModule;
import bisq.network.p2p.P2PModule;
import bisq.network.p2p.network.BridgeAddressProvider;
import bisq.network.p2p.seed.SeedNodeRepository;

import bisq.common.ClockWatcher;
import bisq.common.CommonOptionKeys;
import bisq.common.app.AppModule;
import bisq.common.crypto.KeyRing;
import bisq.common.crypto.KeyStorage;
import bisq.common.proto.network.NetworkProtoResolver;
import bisq.common.proto.persistable.PersistenceProtoResolver;
import bisq.common.storage.CorruptedDatabaseFilesHandler;
import bisq.common.storage.Storage;

import org.springframework.core.env.Environment;

import com.google.inject.Singleton;
import com.google.inject.name.Names;

import java.io.File;
Expand All @@ -80,34 +60,20 @@ public CoreModule(Environment environment) {

@Override
protected void configure() {
bind(BisqSetup.class).in(Singleton.class);
bind(TorSetup.class).in(Singleton.class);
bind(P2PNetworkSetup.class).in(Singleton.class);
bind(WalletAppSetup.class).in(Singleton.class);

bind(BisqEnvironment.class).toInstance((BisqEnvironment) environment);

bind(TradeLimits.class).in(Singleton.class);

bind(KeyStorage.class).in(Singleton.class);
bind(KeyRing.class).in(Singleton.class);
bind(User.class).in(Singleton.class);
bind(ClockWatcher.class).in(Singleton.class);
bind(Preferences.class).in(Singleton.class);
bind(BridgeAddressProvider.class).to(Preferences.class).in(Singleton.class);
bind(CorruptedDatabaseFilesHandler.class).in(Singleton.class);
bind(AvoidStandbyModeService.class).in(Singleton.class);
bind(BridgeAddressProvider.class).to(Preferences.class);

bind(SeedNodeRepository.class).to(DefaultSeedNodeRepository.class).in(Singleton.class);
bind(SeedNodeRepository.class).to(DefaultSeedNodeRepository.class);

File storageDir = new File(environment.getRequiredProperty(Storage.STORAGE_DIR));
bind(File.class).annotatedWith(named(Storage.STORAGE_DIR)).toInstance(storageDir);

File keyStorageDir = new File(environment.getRequiredProperty(KeyStorage.KEY_STORAGE_DIR));
bind(File.class).annotatedWith(named(KeyStorage.KEY_STORAGE_DIR)).toInstance(keyStorageDir);

bind(NetworkProtoResolver.class).to(CoreNetworkProtoResolver.class).in(Singleton.class);
bind(PersistenceProtoResolver.class).to(CorePersistenceProtoResolver.class).in(Singleton.class);
bind(NetworkProtoResolver.class).to(CoreNetworkProtoResolver.class);
bind(PersistenceProtoResolver.class).to(CorePersistenceProtoResolver.class);

Boolean useDevPrivilegeKeys = environment.getProperty(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS, Boolean.class, false);
bind(boolean.class).annotatedWith(Names.named(AppOptionKeys.USE_DEV_PRIVILEGE_KEYS)).toInstance(useDevPrivilegeKeys);
Expand All @@ -118,15 +84,6 @@ protected void configure() {
String referralId = environment.getProperty(AppOptionKeys.REFERRAL_ID, String.class, "");
bind(String.class).annotatedWith(Names.named(AppOptionKeys.REFERRAL_ID)).toInstance(referralId);

bind(MobileNotificationService.class).in(Singleton.class);
bind(MobileMessageEncryption.class).in(Singleton.class);
bind(MobileNotificationValidator.class).in(Singleton.class);
bind(MobileModel.class).in(Singleton.class);
bind(MyOfferTakenEvents.class).in(Singleton.class);
bind(TradeEvents.class).in(Singleton.class);
bind(DisputeMsgEvents.class).in(Singleton.class);
bind(PriceAlert.class).in(Singleton.class);
bind(MarketAlerts.class).in(Singleton.class);

// ordering is used for shut down sequence
install(tradeModule());
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/app/AvoidStandbyModeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import bisq.core.user.Preferences;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.apache.commons.io.IOUtils;

Expand All @@ -40,6 +41,7 @@
import javax.sound.sampled.SourceDataLine;

@Slf4j
@Singleton
public class AvoidStandbyModeService {
private final Preferences preferences;
private volatile boolean isStopped;
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import org.bitcoinj.core.Coin;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.google.common.net.InetAddresses;

Expand Down Expand Up @@ -109,6 +110,7 @@
import javax.annotation.Nullable;

@Slf4j
@Singleton
public class BisqSetup {
public interface BisqSetupCompleteListener {
void onSetupComplete();
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/app/P2PNetworkSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import bisq.network.p2p.network.ConnectionListener;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.monadic.MonadicBinding;
Expand All @@ -44,6 +45,7 @@

import javax.annotation.Nullable;

@Singleton
@Slf4j
public class P2PNetworkSetup {
private final PriceFeedService priceFeedService;
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/app/TorSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.google.inject.name.Named;

import javax.inject.Inject;
import javax.inject.Singleton;

import java.nio.file.Paths;

Expand All @@ -36,6 +37,7 @@
import javax.annotation.Nullable;

@Slf4j
@Singleton
public class TorSetup {
private File torDir;

Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/app/WalletAppSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.bitcoinj.store.ChainFileLockedException;

import javax.inject.Inject;
import javax.inject.Singleton;

import org.fxmisc.easybind.EasyBind;
import org.fxmisc.easybind.monadic.MonadicBinding;
Expand All @@ -50,6 +51,7 @@
import javax.annotation.Nullable;

@Slf4j
@Singleton
public class WalletAppSetup {
private final WalletsManager walletsManager;
private final WalletsSetup walletsSetup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import java.io.BufferedReader;
import java.io.InputStream;
Expand All @@ -43,6 +44,7 @@

// If a new BaseCurrencyNetwork type gets added we need to add the resource file for it as well!
@Slf4j
@Singleton
public class DefaultSeedNodeRepository implements SeedNodeRepository {
//TODO add support for localhost addresses
private static final Pattern pattern = Pattern.compile("^([a-z0-9]+\\.onion:\\d+)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.core.notifications;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.google.common.base.Charsets;

Expand All @@ -33,6 +34,7 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Singleton
public class MobileMessageEncryption {
private SecretKeySpec keySpec;
private Cipher cipher;
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/bisq/core/notifications/MobileModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package bisq.core.notifications;

import javax.inject.Inject;
import javax.inject.Singleton;

import com.google.common.annotations.VisibleForTesting;

Expand All @@ -29,6 +30,7 @@

@Data
@Slf4j
@Singleton
public class MobileModel {
public static final String PHONE_SEPARATOR_ESCAPED = "\\|"; // see https://stackoverflow.com/questions/5675704/java-string-split-not-returning-the-right-values
public static final String PHONE_SEPARATOR_WRITING = "|";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.gson.Gson;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import javax.inject.Named;

Expand All @@ -54,6 +55,7 @@
import static com.google.common.base.Preconditions.checkNotNull;

@Slf4j
@Singleton
public class MobileNotificationService {
// Used in Relay app to response of a success state. We won't want a code dependency just for that string so we keep it
// duplicated in relay and here. Must not be changed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
package bisq.core.notifications;

import javax.inject.Inject;
import javax.inject.Singleton;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Singleton
public class MobileNotificationValidator {
@Inject
public MobileNotificationValidator() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import bisq.network.p2p.P2PService;

import javax.inject.Inject;
import javax.inject.Singleton;

import javafx.collections.ListChangeListener;

Expand All @@ -36,6 +37,7 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Singleton
public class DisputeMsgEvents {
private final P2PService p2PService;
private final MobileNotificationService mobileNotificationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import bisq.core.offer.OpenOfferManager;

import javax.inject.Inject;
import javax.inject.Singleton;

import javafx.collections.ListChangeListener;

Expand All @@ -33,6 +34,7 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Singleton
public class MyOfferTakenEvents {
private final OpenOfferManager openOfferManager;
private final MobileNotificationService mobileNotificationService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import bisq.common.crypto.PubKeyRing;

import javax.inject.Inject;
import javax.inject.Singleton;

import javafx.collections.ListChangeListener;

Expand All @@ -38,6 +39,7 @@
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Singleton
public class TradeEvents {
private final PubKeyRing pubKeyRing;
private final TradeManager tradeManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@
import org.bitcoinj.utils.Fiat;

import javax.inject.Inject;
import javax.inject.Singleton;

import java.util.List;
import java.util.UUID;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Singleton
public class MarketAlerts {
private final OfferBookService offerBookService;
private final MobileNotificationService mobileNotificationService;
Expand Down
Loading

0 comments on commit 3cfe510

Please sign in to comment.