Search in sources :

Example 16 with NodeAddress

use of io.bitsquare.p2p.NodeAddress in project bitsquare by bitsquare.

the class RequestDataManager method onDisconnect.

@Override
public void onDisconnect(CloseConnectionReason closeConnectionReason, Connection connection) {
    Log.traceCall();
    closeHandler(connection);
    if (peerManager.isNodeBanned(closeConnectionReason, connection)) {
        final NodeAddress nodeAddress = connection.getPeersNodeAddressOptional().get();
        seedNodeAddresses.remove(nodeAddress);
        handlerMap.remove(nodeAddress);
    }
}
Also used : NodeAddress(io.bitsquare.p2p.NodeAddress)

Example 17 with NodeAddress

use of io.bitsquare.p2p.NodeAddress in project bitsquare by bitsquare.

the class LocalhostNetworkNode method start.

@Override
public void start(@Nullable SetupListener setupListener) {
    if (setupListener != null)
        addSetupListener(setupListener);
    createExecutorService();
    //Tor delay simulation
    createTorNode(torNode -> {
        Log.traceCall("torNode created");
        setupListeners.stream().forEach(SetupListener::onTorNodeReady);
        createHiddenService(hiddenServiceDescriptor -> {
            Log.traceCall("hiddenService created");
            try {
                startServer(new ServerSocket(servicePort));
            } catch (IOException e) {
                e.printStackTrace();
                log.error("Exception at startServer: " + e.getMessage());
            }
            nodeAddressProperty.set(new NodeAddress("localhost", servicePort));
            setupListeners.stream().forEach(SetupListener::onHiddenServicePublished);
        });
    });
}
Also used : ServerSocket(java.net.ServerSocket) NodeAddress(io.bitsquare.p2p.NodeAddress) IOException(java.io.IOException)

Example 18 with NodeAddress

use of io.bitsquare.p2p.NodeAddress in project bitsquare by bitsquare.

the class VerifyAndSignContract method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        checkNotNull(trade.getTakeOfferFeeTxId(), "TakeOfferFeeTxId must not be null");
        TradingPeer offerer = processModel.tradingPeer;
        PaymentAccountContractData offererPaymentAccountContractData = offerer.getPaymentAccountContractData();
        PaymentAccountContractData takerPaymentAccountContractData = processModel.getPaymentAccountContractData(trade);
        boolean isBuyerOffererAndSellerTaker = trade instanceof SellerAsTakerTrade;
        NodeAddress buyerNodeAddress = isBuyerOffererAndSellerTaker ? processModel.getTempTradingPeerNodeAddress() : processModel.getMyNodeAddress();
        NodeAddress sellerNodeAddress = isBuyerOffererAndSellerTaker ? processModel.getMyNodeAddress() : processModel.getTempTradingPeerNodeAddress();
        log.debug("isBuyerOffererAndSellerTaker " + isBuyerOffererAndSellerTaker);
        log.debug("buyerAddress " + buyerNodeAddress);
        log.debug("sellerAddress " + sellerNodeAddress);
        WalletService walletService = processModel.getWalletService();
        AddressEntry takerPayoutAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.TRADE_PAYOUT);
        String takerPayoutAddressString = takerPayoutAddressEntry.getAddressString();
        AddressEntry takerMultiSigAddressEntry = walletService.getOrCreateAddressEntry(processModel.getOffer().getId(), AddressEntry.Context.MULTI_SIG);
        byte[] takerMultiSigPubKey = takerMultiSigAddressEntry.getPubKey();
        Contract contract = new Contract(processModel.getOffer(), trade.getTradeAmount(), trade.getTradePrice(), trade.getTakeOfferFeeTxId(), buyerNodeAddress, sellerNodeAddress, trade.getArbitratorNodeAddress(), isBuyerOffererAndSellerTaker, offerer.getAccountId(), processModel.getAccountId(), offererPaymentAccountContractData, takerPaymentAccountContractData, offerer.getPubKeyRing(), processModel.getPubKeyRing(), offerer.getPayoutAddressString(), takerPayoutAddressString, offerer.getMultiSigPubKey(), takerMultiSigPubKey);
        String contractAsJson = Utilities.objectToJson(contract);
        String signature = Sig.sign(processModel.getKeyRing().getSignatureKeyPair().getPrivate(), contractAsJson);
        trade.setContract(contract);
        trade.setContractAsJson(contractAsJson);
        trade.setTakerContractSignature(signature);
        try {
            Sig.verify(offerer.getPubKeyRing().getSignaturePubKey(), contractAsJson, offerer.getContractSignature());
        } catch (Throwable t) {
            failed("Signature verification failed. " + t.getMessage());
        }
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : PaymentAccountContractData(io.bitsquare.payment.PaymentAccountContractData) TradingPeer(io.bitsquare.trade.protocol.trade.TradingPeer) AddressEntry(io.bitsquare.btc.AddressEntry) SellerAsTakerTrade(io.bitsquare.trade.SellerAsTakerTrade) NodeAddress(io.bitsquare.p2p.NodeAddress) Contract(io.bitsquare.trade.Contract) WalletService(io.bitsquare.btc.WalletService)

Example 19 with NodeAddress

use of io.bitsquare.p2p.NodeAddress in project bitsquare by bitsquare.

the class CreateTakeOfferFeeTx method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        User user = processModel.getUser();
        NodeAddress selectedArbitratorNodeAddress = ArbitrationSelectionRule.select(user.getAcceptedArbitratorAddresses(), processModel.getOffer());
        log.debug("selectedArbitratorAddress " + selectedArbitratorNodeAddress);
        Arbitrator selectedArbitrator = user.getAcceptedArbitratorByAddress(selectedArbitratorNodeAddress);
        checkNotNull(selectedArbitrator, "selectedArbitrator must not be null at CreateTakeOfferFeeTx");
        WalletService walletService = processModel.getWalletService();
        String id = model.getOffer().getId();
        AddressEntry addressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.OFFER_FUNDING);
        AddressEntry reservedForTradeAddressEntry = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.RESERVED_FOR_TRADE);
        AddressEntry changeAddressEntry = walletService.getOrCreateAddressEntry(AddressEntry.Context.AVAILABLE);
        Address fundingAddress = addressEntry.getAddress();
        Address reservedForTradeAddress = reservedForTradeAddressEntry.getAddress();
        Address changeAddress = changeAddressEntry.getAddress();
        Transaction createTakeOfferFeeTx = processModel.getTradeWalletService().createTradingFeeTx(fundingAddress, reservedForTradeAddress, changeAddress, processModel.getFundsNeededForTrade(), processModel.getUseSavingsWallet(), FeePolicy.getTakeOfferFee(), selectedArbitrator.getBtcAddress());
        processModel.setTakeOfferFeeTx(createTakeOfferFeeTx);
        trade.setTakeOfferFeeTxId(createTakeOfferFeeTx.getHashAsString());
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : User(io.bitsquare.user.User) NodeAddress(io.bitsquare.p2p.NodeAddress) Address(org.bitcoinj.core.Address) Transaction(org.bitcoinj.core.Transaction) AddressEntry(io.bitsquare.btc.AddressEntry) NodeAddress(io.bitsquare.p2p.NodeAddress) Arbitrator(io.bitsquare.arbitration.Arbitrator) WalletService(io.bitsquare.btc.WalletService)

Example 20 with NodeAddress

use of io.bitsquare.p2p.NodeAddress in project bitsquare by bitsquare.

the class ArbitratorService method getArbitrators.

public Map<NodeAddress, Arbitrator> getArbitrators() {
    Set<Arbitrator> arbitratorSet = p2PService.getDataMap().values().stream().filter(data -> data.getStoragePayload() instanceof Arbitrator).map(data -> (Arbitrator) data.getStoragePayload()).collect(Collectors.toSet());
    Map<NodeAddress, Arbitrator> map = new HashMap<>();
    for (Arbitrator arbitrator : arbitratorSet) {
        NodeAddress arbitratorNodeAddress = arbitrator.getArbitratorNodeAddress();
        if (!map.containsKey(arbitratorNodeAddress))
            map.put(arbitratorNodeAddress, arbitrator);
        else
            log.warn("arbitratorAddress already exist in arbitrator map. Seems an arbitrator object is already registered with the same address.");
    }
    return map;
}
Also used : Inject(javax.inject.Inject) Logger(org.slf4j.Logger) P2PService(io.bitsquare.p2p.P2PService) ErrorMessageHandler(io.bitsquare.common.handlers.ErrorMessageHandler) Map(java.util.Map) LoggerFactory(org.slf4j.LoggerFactory) NodeAddress(io.bitsquare.p2p.NodeAddress) Set(java.util.Set) ResultHandler(io.bitsquare.common.handlers.ResultHandler) HashMap(java.util.HashMap) HashMapChangedListener(io.bitsquare.p2p.storage.HashMapChangedListener) Collectors(java.util.stream.Collectors) HashMap(java.util.HashMap) NodeAddress(io.bitsquare.p2p.NodeAddress)

Aggregations

NodeAddress (io.bitsquare.p2p.NodeAddress)34 WalletService (io.bitsquare.btc.WalletService)5 Contract (io.bitsquare.trade.Contract)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 Log (io.bitsquare.app.Log)4 AddressEntry (io.bitsquare.btc.AddressEntry)4 Timer (io.bitsquare.common.Timer)4 UserThread (io.bitsquare.common.UserThread)4 PubKeyRing (io.bitsquare.common.crypto.PubKeyRing)4 P2PService (io.bitsquare.p2p.P2PService)4 SendMailboxMessageListener (io.bitsquare.p2p.messaging.SendMailboxMessageListener)4 TimeUnit (java.util.concurrent.TimeUnit)4 DummySeedNode (io.bitsquare.p2p.DummySeedNode)3 P2PServiceListener (io.bitsquare.p2p.P2PServiceListener)3 Connection (io.bitsquare.p2p.network.Connection)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Collectors (java.util.stream.Collectors)3 FutureCallback (com.google.common.util.concurrent.FutureCallback)2 Futures (com.google.common.util.concurrent.Futures)2