Rename peergroup

This commit is contained in:
Manfred Karrer 2015-12-31 16:17:01 +01:00
parent 7dc08b0459
commit 67fb7aa825
13 changed files with 83 additions and 72 deletions

View File

@ -36,7 +36,7 @@ public class PaymentMethod implements Serializable, Comparable {
// time in blocks (average 10 min for one block confirmation
private static final int HOUR = 6;
private static final int DAY = HOUR * 24;
private static final int DAY = HOUR * 24; // 144
public static final String OK_PAY_ID = "OK_PAY";
public static final String PERFECT_MONEY_ID = "PERFECT_MONEY";

View File

@ -39,7 +39,6 @@ import io.bitsquare.gui.main.portfolio.PortfolioView;
import io.bitsquare.gui.main.portfolio.openoffer.OpenOffersView;
import io.bitsquare.gui.popups.OfferDetailsPopup;
import io.bitsquare.gui.popups.Popup;
import io.bitsquare.gui.util.BSFormatter;
import io.bitsquare.gui.util.FormBuilder;
import io.bitsquare.gui.util.Layout;
import io.bitsquare.locale.BSResources;
@ -69,7 +68,6 @@ import static javafx.beans.binding.Bindings.createStringBinding;
public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateOfferViewModel> {
private final Navigation navigation;
private final BSFormatter formatter;
private final OfferDetailsPopup offerDetailsPopup;
private ScrollPane scrollPane;
@ -113,11 +111,10 @@ public class CreateOfferView extends ActivatableViewAndModel<AnchorPane, CreateO
///////////////////////////////////////////////////////////////////////////////////////////
@Inject
private CreateOfferView(CreateOfferViewModel model, Navigation navigation, BSFormatter formatter, OfferDetailsPopup offerDetailsPopup) {
private CreateOfferView(CreateOfferViewModel model, Navigation navigation, OfferDetailsPopup offerDetailsPopup) {
super(model);
this.navigation = navigation;
this.formatter = formatter;
this.offerDetailsPopup = offerDetailsPopup;
}

View File

@ -17,6 +17,7 @@
package io.bitsquare.gui.main.offer.createoffer;
import io.bitsquare.app.BitsquareApp;
import io.bitsquare.arbitration.Arbitrator;
import io.bitsquare.gui.common.model.ActivatableWithDataModel;
import io.bitsquare.gui.common.model.ViewModel;
@ -122,6 +123,20 @@ class CreateOfferViewModel extends ActivatableWithDataModel<CreateOfferDataModel
@Override
protected void activate() {
if (BitsquareApp.DEV_MODE) {
amount.set("0.0001");
minAmount.set(amount.get());
price.set("400");
volume.set("0.04");
setAmountToModel();
setMinAmountToModel();
setPriceToModel();
calculateVolume();
dataModel.calculateTotalToPay();
updateButtonDisableState();
}
addBindings();
addListeners();

View File

@ -18,11 +18,9 @@
package io.bitsquare.gui.main.offer.takeoffer;
import com.google.inject.Inject;
import io.bitsquare.app.BitsquareApp;
import io.bitsquare.arbitration.Arbitrator;
import io.bitsquare.btc.AddressEntry;
import io.bitsquare.btc.FeePolicy;
import io.bitsquare.btc.TradeWalletService;
import io.bitsquare.btc.WalletService;
import io.bitsquare.btc.*;
import io.bitsquare.btc.listeners.BalanceListener;
import io.bitsquare.common.handlers.ResultHandler;
import io.bitsquare.gui.common.model.ActivatableDataModel;
@ -136,6 +134,9 @@ class TakeOfferDataModel extends ActivatableDataModel {
amountAsCoin.set(offer.getAmount());
if (BitsquareApp.DEV_MODE)
amountAsCoin.set(Restrictions.MIN_TRADE_AMOUNT);
calculateVolume();
calculateTotalToPay();

View File

@ -121,20 +121,18 @@ public class SellerSubView extends TradeSubView {
break;
case WAIT_FOR_PAYOUT_TX:
if (model.getLockTime() > 0) {
waitTxInBlockchain.setCompleted();
waitPaymentStarted.setCompleted();
confirmPaymentReceived.setCompleted();
showItem(waitPayoutUnlock);
waitTxInBlockchain.setCompleted();
waitPaymentStarted.setCompleted();
confirmPaymentReceived.setCompleted();
showItem(waitPayoutUnlock);
// We don't use a wizard for that step as it only gets displayed in case the other peer is offline
tradeStepDetailsView = new WaitPayoutFinalizedView(model);
contentPane.getChildren().setAll(tradeStepDetailsView);
// We don't use a wizard for that step as it only gets displayed in case the other peer is offline
tradeStepDetailsView = new WaitPayoutFinalizedView(model);
contentPane.getChildren().setAll(tradeStepDetailsView);
((WaitPayoutFinalizedView) tradeStepDetailsView).setInfoLabelText("We requested the trading peer to sign and finalize the payout " +
"transaction.\n" +
"It might be that the other peer is offline, so we need to wait until he finalize the transaction when he goes online again.");
}
((WaitPayoutFinalizedView) tradeStepDetailsView).setInfoLabelText("We requested the trading peer to sign and finalize the payout " +
"transaction.\n" +
"It might be that the other peer is offline, so we need to wait until he finalize the transaction when he goes online again.");
break;
case WAIT_FOR_UNLOCK_PAYOUT:
waitTxInBlockchain.setCompleted();

View File

@ -16,7 +16,7 @@ import io.bitsquare.crypto.SealedAndSignedMessage;
import io.bitsquare.p2p.messaging.*;
import io.bitsquare.p2p.network.*;
import io.bitsquare.p2p.peers.AuthenticationListener;
import io.bitsquare.p2p.peers.PeerGroup;
import io.bitsquare.p2p.peers.PeerManager;
import io.bitsquare.p2p.peers.RequestDataManager;
import io.bitsquare.p2p.seed.SeedNodesRepository;
import io.bitsquare.p2p.storage.HashMapChangedListener;
@ -54,7 +54,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
// set in init
private NetworkNode networkNode;
private PeerGroup peerGroup;
private PeerManager peerManager;
private P2PDataStorage dataStorage;
private final CopyOnWriteArraySet<DecryptedMailListener> decryptedMailListeners = new CopyOnWriteArraySet<>();
@ -131,16 +131,16 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
networkNode.addMessageListener(this);
// peer group
peerGroup = new PeerGroup(networkNode);
peerGroup.setSeedNodeAddresses(seedNodeAddresses);
peerGroup.addAuthenticationListener(this);
peerManager = new PeerManager(networkNode);
peerManager.setSeedNodeAddresses(seedNodeAddresses);
peerManager.addAuthenticationListener(this);
// P2P network data storage
dataStorage = new P2PDataStorage(peerGroup, networkNode, storageDir);
dataStorage = new P2PDataStorage(peerManager, networkNode, storageDir);
dataStorage.addHashMapChangedListener(this);
// Request initial data manager
requestDataManager = new RequestDataManager(networkNode, dataStorage, peerGroup, new RequestDataManager.Listener() {
requestDataManager = new RequestDataManager(networkNode, dataStorage, peerManager, new RequestDataManager.Listener() {
@Override
public void onNoSeedNodeAvailable() {
p2pServiceListeners.stream().forEach(e -> e.onNoSeedNodeAvailable());
@ -153,7 +153,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
p2pServiceListeners.stream().forEach(e -> e.onRequestingDataCompleted());
}
});
peerGroup.addAuthenticationListener(requestDataManager);
peerManager.addAuthenticationListener(requestDataManager);
// Test multiple states to check when we are ready for authenticateSeedNode
readyForAuthentication = EasyBind.combine(hiddenServicePublished, requestingDataCompleted, firstPeerAuthenticated,
@ -177,7 +177,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
// we remove ourselves from the list of seed nodes
seedNodeAddresses.remove(mySeedNodeAddress);
peerGroup.setIsSeedNode(true);
peerManager.setIsSeedNode(true);
requestDataManager.setIsSeedNode(true);
start(listener);
@ -201,8 +201,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
if (dataStorage != null)
dataStorage.shutDown();
if (peerGroup != null)
peerGroup.shutDown();
if (peerManager != null)
peerManager.shutDown();
if (requestDataManager != null)
requestDataManager.shutDown();
@ -275,7 +275,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
private void authenticateSeedNode() {
Log.traceCall();
checkNotNull(connectedSeedNode != null, "connectedSeedNode must not be null");
peerGroup.authenticateToSeedNode(connectedSeedNode);
peerManager.authenticateToSeedNode(connectedSeedNode);
}
@ -380,7 +380,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
try {
checkAuthentication();
if (!authenticatedPeerAddresses.contains(peerAddress))
peerGroup.authenticateToDirectMessagePeer(peerAddress,
peerManager.authenticateToDirectMessagePeer(peerAddress,
() -> doSendEncryptedMailMessage(peerAddress, pubKeyRing, message, sendMailMessageListener),
() -> sendMailMessageListener.onFault());
else
@ -470,7 +470,7 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
if (authenticatedPeerAddresses.contains(peerAddress)) {
trySendEncryptedMailboxMessage(peerAddress, peersPubKeyRing, message, sendMailboxMessageListener);
} else {
peerGroup.authenticateToDirectMessagePeer(peerAddress,
peerManager.authenticateToDirectMessagePeer(peerAddress,
() -> trySendEncryptedMailboxMessage(peerAddress, peersPubKeyRing, message, sendMailboxMessageListener),
() -> {
log.info("We cannot authenticate to peer. Peer might be offline. We will store message in mailbox.");
@ -673,8 +673,8 @@ public class P2PService implements SetupListener, MessageListener, ConnectionLis
return networkNode;
}
public PeerGroup getPeerGroup() {
return peerGroup;
public PeerManager getPeerManager() {
return peerManager;
}
public Address getAddress() {

View File

@ -24,8 +24,8 @@ import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
public class PeerGroup implements MessageListener, ConnectionListener {
private static final Logger log = LoggerFactory.getLogger(PeerGroup.class);
public class PeerManager implements MessageListener, ConnectionListener {
private static final Logger log = LoggerFactory.getLogger(PeerManager.class);
///////////////////////////////////////////////////////////////////////////////////////////
// Static
@ -42,7 +42,7 @@ public class PeerGroup implements MessageListener, ConnectionListener {
}
static {
setMaxConnectionsLowPriority(6);
setMaxConnectionsLowPriority(10);
}
private static final int MAX_REPORTED_PEERS = 1000;
@ -70,7 +70,7 @@ public class PeerGroup implements MessageListener, ConnectionListener {
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
public PeerGroup(NetworkNode networkNode) {
public PeerManager(NetworkNode networkNode) {
Log.traceCall();
this.networkNode = networkNode;
@ -665,8 +665,8 @@ public class PeerGroup implements MessageListener, ConnectionListener {
if (authenticatedConnections.size() == 0) {
log.debug("There are no passive connections for closing. We check if we are exceeding " +
"MAX_CONNECTIONS_NORMAL ({}) ", PeerGroup.MAX_CONNECTIONS_NORMAL_PRIORITY);
if (size > PeerGroup.MAX_CONNECTIONS_NORMAL_PRIORITY) {
"MAX_CONNECTIONS_NORMAL ({}) ", PeerManager.MAX_CONNECTIONS_NORMAL_PRIORITY);
if (size > PeerManager.MAX_CONNECTIONS_NORMAL_PRIORITY) {
authenticatedConnections = allConnections.stream()
.filter(e -> e.isAuthenticated())
.filter(e -> e.getConnectionPriority() == ConnectionPriority.PASSIVE || e.getConnectionPriority() == ConnectionPriority.ACTIVE)
@ -675,8 +675,8 @@ public class PeerGroup implements MessageListener, ConnectionListener {
if (authenticatedConnections.size() == 0) {
log.debug("There are no passive or active connections for closing. We check if we are exceeding " +
"MAX_CONNECTIONS_HIGH ({}) ", PeerGroup.MAX_CONNECTIONS_HIGH_PRIORITY);
if (size > PeerGroup.MAX_CONNECTIONS_HIGH_PRIORITY) {
"MAX_CONNECTIONS_HIGH ({}) ", PeerManager.MAX_CONNECTIONS_HIGH_PRIORITY);
if (size > PeerManager.MAX_CONNECTIONS_HIGH_PRIORITY) {
authenticatedConnections = allConnections.stream()
.filter(e -> e.isAuthenticated())
.filter(e -> e.getConnectionPriority() != ConnectionPriority.AUTH_REQUEST)

View File

@ -42,7 +42,7 @@ public class RequestDataManager implements MessageListener, AuthenticationListen
private final NetworkNode networkNode;
private final P2PDataStorage dataStorage;
private final PeerGroup peerGroup;
private final PeerManager peerManager;
private final Listener listener;
private Optional<Address> optionalConnectedSeedNodeAddress = Optional.empty();
@ -54,10 +54,10 @@ public class RequestDataManager implements MessageListener, AuthenticationListen
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
public RequestDataManager(NetworkNode networkNode, P2PDataStorage dataStorage, PeerGroup peerGroup, Listener listener) {
public RequestDataManager(NetworkNode networkNode, P2PDataStorage dataStorage, PeerManager peerManager, Listener listener) {
this.networkNode = networkNode;
this.dataStorage = dataStorage;
this.peerGroup = peerGroup;
this.peerManager = peerManager;
this.listener = listener;
networkNode.addMessageListener(this);
@ -87,7 +87,7 @@ public class RequestDataManager implements MessageListener, AuthenticationListen
List<Address> remainingSeedNodeAddresses = new ArrayList<>(seedNodeAddresses);
Collections.shuffle(remainingSeedNodeAddresses);
Address candidate = remainingSeedNodeAddresses.get(0);
if (!peerGroup.isInAuthenticationProcess(candidate)) {
if (!peerManager.isInAuthenticationProcess(candidate)) {
// We only remove it if it is not in the process of authentication
remainingSeedNodeAddresses.remove(0);
log.info("We try to send a GetAllDataMessage request to a random seed node. " + candidate);

View File

@ -7,7 +7,7 @@ import io.bitsquare.common.UserThread;
import io.bitsquare.p2p.Address;
import io.bitsquare.p2p.P2PService;
import io.bitsquare.p2p.P2PServiceListener;
import io.bitsquare.p2p.peers.PeerGroup;
import io.bitsquare.p2p.peers.PeerManager;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -64,10 +64,10 @@ public class SeedNode {
String arg2 = args[2];
int maxConnections = Integer.parseInt(arg2);
checkArgument(maxConnections < 1000, "maxConnections seems to be a bit too high...");
PeerGroup.setMaxConnectionsLowPriority(maxConnections);
PeerManager.setMaxConnectionsLowPriority(maxConnections);
} else {
// we keep default a higher connection size for seed nodes
PeerGroup.setMaxConnectionsLowPriority(50);
PeerManager.setMaxConnectionsLowPriority(50);
}
if (args.length > 3) {
String arg3 = args[3];

View File

@ -14,7 +14,7 @@ import io.bitsquare.p2p.network.Connection;
import io.bitsquare.p2p.network.IllegalRequest;
import io.bitsquare.p2p.network.MessageListener;
import io.bitsquare.p2p.network.NetworkNode;
import io.bitsquare.p2p.peers.PeerGroup;
import io.bitsquare.p2p.peers.PeerManager;
import io.bitsquare.p2p.storage.data.*;
import io.bitsquare.p2p.storage.messages.AddDataMessage;
import io.bitsquare.p2p.storage.messages.DataBroadcastMessage;
@ -38,7 +38,7 @@ public class P2PDataStorage implements MessageListener {
@VisibleForTesting
public static int CHECK_TTL_INTERVAL = 10 * 60 * 1000;
private final PeerGroup peerGroup;
private final PeerManager peerManager;
private final Map<ByteArray, ProtectedData> map = new HashMap<>();
private final CopyOnWriteArraySet<HashMapChangedListener> hashMapChangedListeners = new CopyOnWriteArraySet<>();
private HashMap<ByteArray, Integer> sequenceNumberMap = new HashMap<>();
@ -50,9 +50,9 @@ public class P2PDataStorage implements MessageListener {
// Constructor
///////////////////////////////////////////////////////////////////////////////////////////
public P2PDataStorage(PeerGroup peerGroup, NetworkNode networkNode, File storageDir) {
public P2PDataStorage(PeerManager peerManager, NetworkNode networkNode, File storageDir) {
Log.traceCall();
this.peerGroup = peerGroup;
this.peerManager = peerManager;
networkNode.addMessageListener(this);
@ -378,7 +378,7 @@ public class P2PDataStorage implements MessageListener {
private void broadcast(DataBroadcastMessage message, @Nullable Address sender) {
Log.traceCall(message.toString());
peerGroup.broadcast(message, sender);
peerManager.broadcast(message, sender);
}
private ByteArray getHashAsByteArray(ExpirablePayload payload) {

View File

@ -8,7 +8,7 @@ import io.bitsquare.p2p.messaging.MailboxMessage;
import io.bitsquare.p2p.messaging.SendMailboxMessageListener;
import io.bitsquare.p2p.mocks.MockMailboxMessage;
import io.bitsquare.p2p.network.LocalhostNetworkNode;
import io.bitsquare.p2p.peers.PeerGroup;
import io.bitsquare.p2p.peers.PeerManager;
import io.bitsquare.p2p.seed.SeedNode;
import io.bitsquare.p2p.storage.data.DataAndSeqNr;
import io.bitsquare.p2p.storage.data.ProtectedData;
@ -59,7 +59,7 @@ public class P2PServiceTest {
LocalhostNetworkNode.setSimulateTorDelayTorNode(10);
LocalhostNetworkNode.setSimulateTorDelayHiddenService(100);
PeerGroup.setMaxConnectionsLowPriority(8);
PeerManager.setMaxConnectionsLowPriority(8);
keyRing1 = new KeyRing(new KeyStorage(dir1));
keyRing2 = new KeyRing(new KeyStorage(dir2));

View File

@ -4,7 +4,7 @@ import io.bitsquare.p2p.Address;
import io.bitsquare.p2p.P2PService;
import io.bitsquare.p2p.P2PServiceListener;
import io.bitsquare.p2p.network.LocalhostNetworkNode;
import io.bitsquare.p2p.peers.PeerGroup;
import io.bitsquare.p2p.peers.PeerManager;
import io.bitsquare.p2p.seed.SeedNode;
import org.junit.*;
import org.slf4j.Logger;
@ -20,8 +20,8 @@ import java.util.concurrent.CountDownLatch;
// need to define seed node addresses first before using tor version
@Ignore
public class PeerGroupTest {
private static final Logger log = LoggerFactory.getLogger(PeerGroupTest.class);
public class PeerManagerTest {
private static final Logger log = LoggerFactory.getLogger(PeerManagerTest.class);
boolean useLocalhost = true;
private CountDownLatch latch;
@ -33,7 +33,7 @@ public class PeerGroupTest {
public void setup() throws InterruptedException {
LocalhostNetworkNode.setSimulateTorDelayTorNode(50);
LocalhostNetworkNode.setSimulateTorDelayHiddenService(8);
PeerGroup.setMaxConnectionsLowPriority(100);
PeerManager.setMaxConnectionsLowPriority(100);
seedNodes = new HashSet<>();
if (useLocalhost) {
@ -112,7 +112,7 @@ public class PeerGroupTest {
P2PService p2PService1 = seedNode1.getP2PService();
latch.await();
Thread.sleep(500);
Assert.assertEquals(0, p2PService1.getPeerGroup().getAuthenticatedAndReportedPeers().size());
Assert.assertEquals(0, p2PService1.getPeerManager().getAuthenticatedAndReportedPeers().size());
}
@Test
@ -194,8 +194,8 @@ public class PeerGroupTest {
});
P2PService p2PService2 = seedNode2.getP2PService();
latch.await();
Assert.assertEquals(1, p2PService1.getPeerGroup().getAuthenticatedAndReportedPeers().size());
Assert.assertEquals(1, p2PService2.getPeerGroup().getAuthenticatedAndReportedPeers().size());
Assert.assertEquals(1, p2PService1.getPeerManager().getAuthenticatedAndReportedPeers().size());
Assert.assertEquals(1, p2PService2.getPeerManager().getAuthenticatedAndReportedPeers().size());
}
// @Test

View File

@ -9,7 +9,7 @@ import io.bitsquare.p2p.Address;
import io.bitsquare.p2p.TestUtils;
import io.bitsquare.p2p.mocks.MockMessage;
import io.bitsquare.p2p.network.NetworkNode;
import io.bitsquare.p2p.peers.PeerGroup;
import io.bitsquare.p2p.peers.PeerManager;
import io.bitsquare.p2p.storage.data.DataAndSeqNr;
import io.bitsquare.p2p.storage.data.ExpirableMailboxPayload;
import io.bitsquare.p2p.storage.data.ProtectedData;
@ -37,7 +37,7 @@ public class ProtectedDataStorageTest {
boolean useClearNet = true;
private Set<Address> seedNodes = new HashSet<>();
private NetworkNode networkNode1;
private PeerGroup peerGroup1;
private PeerManager peerManager1;
private EncryptionService encryptionService1, encryptionService2;
private P2PDataStorage dataStorage1;
private KeyPair storageSignatureKeyPair1, storageSignatureKeyPair2;
@ -65,8 +65,8 @@ public class ProtectedDataStorageTest {
storageSignatureKeyPair1 = keyRing1.getSignatureKeyPair();
encryptionService1 = new EncryptionService(keyRing1);
networkNode1 = TestUtils.getAndStartSeedNode(8001, useClearNet, seedNodes).getP2PService().getNetworkNode();
peerGroup1 = new PeerGroup(networkNode1);
dataStorage1 = new P2PDataStorage(peerGroup1, networkNode1, new File("dummy"));
peerManager1 = new PeerManager(networkNode1);
dataStorage1 = new P2PDataStorage(peerManager1, networkNode1, new File("dummy"));
// for mailbox
keyRing2 = new KeyRing(new KeyStorage(dir2));
@ -81,7 +81,7 @@ public class ProtectedDataStorageTest {
public void tearDown() throws InterruptedException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, CryptoException, SignatureException, InvalidKeyException {
Thread.sleep(sleepTime);
if (dataStorage1 != null) dataStorage1.shutDown();
if (peerGroup1 != null) peerGroup1.shutDown();
if (peerManager1 != null) peerManager1.shutDown();
if (networkNode1 != null) {
CountDownLatch shutDownLatch = new CountDownLatch(1);
@ -108,7 +108,7 @@ public class ProtectedDataStorageTest {
public void testExpirableData() throws InterruptedException, NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, CryptoException, SignatureException, InvalidKeyException, NoSuchProviderException {
P2PDataStorage.CHECK_TTL_INTERVAL = 10;
// CHECK_TTL_INTERVAL is used in constructor of ProtectedExpirableDataStorage so we recreate it here
dataStorage1 = new P2PDataStorage(peerGroup1, networkNode1, new File("dummy"));
dataStorage1 = new P2PDataStorage(peerManager1, networkNode1, new File("dummy"));
mockData.ttl = 50;
ProtectedData data = dataStorage1.getDataWithSignedSeqNr(mockData, storageSignatureKeyPair1);