Search in sources :

Example 1 with P2PDataStorage

use of io.bitsquare.p2p.storage.P2PDataStorage in project bitsquare by bitsquare.

the class P2PService method init.

private void init(boolean useLocalhost, int networkId, File storageDir, String seedNodes, String myAddress, String banList) {
    if (!useLocalhost)
        FileUtil.rollingBackup(new File(Paths.get(torDir.getAbsolutePath(), "hiddenservice").toString()), "private_key", 20);
    if (banList != null && !banList.isEmpty())
        BanList.setList(Arrays.asList(banList.replace(" ", "").split(",")).stream().map(NodeAddress::new).collect(Collectors.toList()));
    if (myAddress != null && !myAddress.isEmpty())
        seedNodesRepository.setNodeAddressToExclude(new NodeAddress(myAddress));
    networkNode = useLocalhost ? new LocalhostNetworkNode(port) : new TorNetworkNode(port, torDir);
    networkNode.addConnectionListener(this);
    networkNode.addMessageListener(this);
    Set<NodeAddress> seedNodeAddresses;
    if (seedNodes != null && !seedNodes.isEmpty())
        seedNodeAddresses = Arrays.asList(seedNodes.replace(" ", "").split(",")).stream().map(NodeAddress::new).collect(Collectors.toSet());
    else
        seedNodeAddresses = seedNodesRepository.getSeedNodeAddresses(useLocalhost, networkId);
    peerManager = new PeerManager(networkNode, maxConnections, seedNodeAddresses, storageDir, clock);
    broadcaster = new Broadcaster(networkNode, peerManager);
    p2PDataStorage = new P2PDataStorage(broadcaster, networkNode, storageDir);
    p2PDataStorage.addHashMapChangedListener(this);
    requestDataManager = new RequestDataManager(networkNode, p2PDataStorage, peerManager, seedNodeAddresses, this);
    peerExchangeManager = new PeerExchangeManager(networkNode, peerManager, seedNodeAddresses);
    keepAliveManager = new KeepAliveManager(networkNode, peerManager);
    // We need to have both the initial data delivered and the hidden service published
    networkReadyBinding = EasyBind.combine(hiddenServicePublished, preliminaryDataReceived, (hiddenServicePublished, preliminaryDataReceived) -> hiddenServicePublished && preliminaryDataReceived);
    networkReadySubscription = networkReadyBinding.subscribe((observable, oldValue, newValue) -> {
        if (newValue)
            onNetworkReady();
    });
}
Also used : Clock(io.bitsquare.common.Clock) PubKeyRing(io.bitsquare.common.crypto.PubKeyRing) Inject(com.google.inject.Inject) AddDataMessage(io.bitsquare.p2p.storage.messages.AddDataMessage) ProtectedStorageEntry(io.bitsquare.p2p.storage.storageentry.ProtectedStorageEntry) LoggerFactory(org.slf4j.LoggerFactory) Socks5ProxyProvider(io.bitsquare.network.Socks5ProxyProvider) SettableFuture(com.google.common.util.concurrent.SettableFuture) CryptoException(io.bitsquare.common.crypto.CryptoException) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PeerManager(io.bitsquare.p2p.peers.PeerManager) KeyRing(io.bitsquare.common.crypto.KeyRing) RefreshTTLMessage(io.bitsquare.p2p.storage.messages.RefreshTTLMessage) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) FileUtil(io.bitsquare.storage.FileUtil) RequestDataManager(io.bitsquare.p2p.peers.getdata.RequestDataManager) ProtectedMailboxStorageEntry(io.bitsquare.p2p.storage.storageentry.ProtectedMailboxStorageEntry) EncryptionService(io.bitsquare.crypto.EncryptionService) Subscription(org.fxmisc.easybind.Subscription) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull) BanList(io.bitsquare.p2p.peers.BanList) java.util(java.util) MailboxStoragePayload(io.bitsquare.p2p.storage.payload.MailboxStoragePayload) HashMapChangedListener(io.bitsquare.p2p.storage.HashMapChangedListener) BroadcastMessage(io.bitsquare.p2p.storage.messages.BroadcastMessage) io.bitsquare.p2p.network(io.bitsquare.p2p.network) PeerExchangeManager(io.bitsquare.p2p.peers.peerexchange.PeerExchangeManager) Log(io.bitsquare.app.Log) P2PDataStorage(io.bitsquare.p2p.storage.P2PDataStorage) BroadcastHandler(io.bitsquare.p2p.peers.BroadcastHandler) javafx.beans.property(javafx.beans.property) Utilities(io.bitsquare.common.util.Utilities) Logger(org.slf4j.Logger) UserThread(io.bitsquare.common.UserThread) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) PublicKey(java.security.PublicKey) StoragePayload(io.bitsquare.p2p.storage.payload.StoragePayload) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) Futures(com.google.common.util.concurrent.Futures) SeedNodesRepository(io.bitsquare.p2p.seed.SeedNodesRepository) EasyBind(org.fxmisc.easybind.EasyBind) Broadcaster(io.bitsquare.p2p.peers.Broadcaster) Paths(java.nio.file.Paths) KeepAliveManager(io.bitsquare.p2p.peers.keepalive.KeepAliveManager) Named(com.google.inject.name.Named) Storage(io.bitsquare.storage.Storage) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DecryptedMsgWithPubKey(io.bitsquare.crypto.DecryptedMsgWithPubKey) io.bitsquare.p2p.messaging(io.bitsquare.p2p.messaging) NetworkOptionKeys(io.bitsquare.network.NetworkOptionKeys) PeerManager(io.bitsquare.p2p.peers.PeerManager) PeerExchangeManager(io.bitsquare.p2p.peers.peerexchange.PeerExchangeManager) P2PDataStorage(io.bitsquare.p2p.storage.P2PDataStorage) Broadcaster(io.bitsquare.p2p.peers.Broadcaster) RequestDataManager(io.bitsquare.p2p.peers.getdata.RequestDataManager) KeepAliveManager(io.bitsquare.p2p.peers.keepalive.KeepAliveManager) File(java.io.File)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 Futures (com.google.common.util.concurrent.Futures)1 SettableFuture (com.google.common.util.concurrent.SettableFuture)1 Inject (com.google.inject.Inject)1 Named (com.google.inject.name.Named)1 Log (io.bitsquare.app.Log)1 Clock (io.bitsquare.common.Clock)1 UserThread (io.bitsquare.common.UserThread)1 CryptoException (io.bitsquare.common.crypto.CryptoException)1 KeyRing (io.bitsquare.common.crypto.KeyRing)1 PubKeyRing (io.bitsquare.common.crypto.PubKeyRing)1 Utilities (io.bitsquare.common.util.Utilities)1 DecryptedMsgWithPubKey (io.bitsquare.crypto.DecryptedMsgWithPubKey)1 EncryptionService (io.bitsquare.crypto.EncryptionService)1 NetworkOptionKeys (io.bitsquare.network.NetworkOptionKeys)1 Socks5ProxyProvider (io.bitsquare.network.Socks5ProxyProvider)1 io.bitsquare.p2p.messaging (io.bitsquare.p2p.messaging)1