mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-04-20 23:56:30 -04:00
Introduce network package and Peer abstraction
Prior to this change, TomP2P's 'PeerAddress' was used heavily throughout Bitsquare, effectively tying many parts of the system to the TomP2P API when they otherwise had no need to be aware of TomP2P at all. The Peer interface (and the new 'network' package to which it belongs) is designed to provide this missing abstraction and is a step toward isolating TomP2P functionality as completely as possible--so as to make the latter easy to test (and easy to replace if necessary). A very simple TomP2PPeer implementation of the Peer interface has been provided in the new 'network.tomp2p' package. It is currently just a wrapper for an underlying PeerAddress object, but it is reasonable to expect that more functionality will find its way into this class over time.
This commit is contained in:
parent
311e15c0e5
commit
00af59aa20
@ -18,8 +18,8 @@
|
||||
package io.bitsquare.gui;
|
||||
|
||||
|
||||
import io.bitsquare.BitsquareUI;
|
||||
import io.bitsquare.Bitsquare;
|
||||
import io.bitsquare.BitsquareUI;
|
||||
import io.bitsquare.gui.util.ImageUtil;
|
||||
|
||||
import java.awt.*;
|
||||
|
@ -17,11 +17,11 @@
|
||||
|
||||
package io.bitsquare.msg;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
import io.bitsquare.network.Peer;
|
||||
|
||||
/**
|
||||
* Interface for the object handling incoming messages.
|
||||
*/
|
||||
public interface MessageBroker {
|
||||
void handleMessage(Object message, PeerAddress peerAddress);
|
||||
void handleMessage(Object message, Peer sender);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import io.bitsquare.msg.listeners.GetPeerAddressListener;
|
||||
import io.bitsquare.msg.listeners.IncomingTradeMessageListener;
|
||||
import io.bitsquare.msg.listeners.OfferBookListener;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import io.bitsquare.trade.protocol.trade.TradeMessage;
|
||||
|
||||
@ -34,11 +35,9 @@ import java.util.Locale;
|
||||
|
||||
import javafx.beans.property.LongProperty;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
public interface MessageFacade extends MessageBroker {
|
||||
|
||||
void sendTradeMessage(PeerAddress peerAddress, TradeMessage tradeMessage, OutgoingTradeMessageListener listener);
|
||||
void sendTradeMessage(Peer peer, TradeMessage tradeMessage, OutgoingTradeMessageListener listener);
|
||||
|
||||
void shutDown();
|
||||
|
||||
|
@ -25,6 +25,7 @@ import io.bitsquare.msg.listeners.GetPeerAddressListener;
|
||||
import io.bitsquare.msg.listeners.IncomingTradeMessageListener;
|
||||
import io.bitsquare.msg.listeners.OfferBookListener;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import io.bitsquare.trade.protocol.trade.TradeMessage;
|
||||
import io.bitsquare.user.User;
|
||||
@ -44,7 +45,6 @@ import javafx.beans.property.LongProperty;
|
||||
import javafx.beans.property.SimpleLongProperty;
|
||||
|
||||
import net.tomp2p.dht.PeerDHT;
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
public class NoopMessageFacade implements MessageFacade {
|
||||
|
||||
@ -61,8 +61,7 @@ public class NoopMessageFacade implements MessageFacade {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendTradeMessage(PeerAddress peerAddress, TradeMessage tradeMessage, OutgoingTradeMessageListener
|
||||
listener) {
|
||||
public void sendTradeMessage(Peer peer, TradeMessage tradeMessage, OutgoingTradeMessageListener listener) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@ -163,7 +162,7 @@ public class NoopMessageFacade implements MessageFacade {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Object message, PeerAddress peerAddress) {
|
||||
public void handleMessage(Object message, Peer sender) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@
|
||||
|
||||
package io.bitsquare.msg;
|
||||
|
||||
import io.bitsquare.network.tomp2p.TomP2PPeer;
|
||||
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
import com.google.common.util.concurrent.Futures;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
@ -139,8 +141,8 @@ public class P2PNode {
|
||||
// Generic DHT methods
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TODO remove all security features for the moment. There are some problems with a "wrong signature!" msg in
|
||||
// the logs
|
||||
// TODO remove all security features for the moment. There are some problems with a "wrong signature!" msg in
|
||||
// the logs
|
||||
public FuturePut putDomainProtectedData(Number160 locationKey, Data data) {
|
||||
log.trace("putDomainProtectedData");
|
||||
return peerDHT.put(locationKey).data(data).start();
|
||||
@ -275,7 +277,7 @@ public class P2PNode {
|
||||
//
|
||||
// return futureDirect;
|
||||
// }
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -334,7 +336,7 @@ public class P2PNode {
|
||||
|
||||
if (!sender.equals(peerDHT.peer().peerAddress()))
|
||||
if (messageBroker != null)
|
||||
messageBroker.handleMessage(request, sender);
|
||||
messageBroker.handleMessage(request, new TomP2PPeer(sender));
|
||||
else
|
||||
log.error("Received msg from myself. That should never happen.");
|
||||
return null;
|
||||
|
@ -25,10 +25,13 @@ import io.bitsquare.msg.listeners.GetPeerAddressListener;
|
||||
import io.bitsquare.msg.listeners.IncomingTradeMessageListener;
|
||||
import io.bitsquare.msg.listeners.OfferBookListener;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.network.tomp2p.TomP2PPeer;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import io.bitsquare.trade.protocol.trade.TradeMessage;
|
||||
import io.bitsquare.user.User;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.util.concurrent.FutureCallback;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -58,7 +61,6 @@ import net.tomp2p.futures.BaseFutureListener;
|
||||
import net.tomp2p.futures.FutureDirect;
|
||||
import net.tomp2p.peers.Number160;
|
||||
import net.tomp2p.peers.Number640;
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
import net.tomp2p.storage.Data;
|
||||
import net.tomp2p.utils.Utils;
|
||||
|
||||
@ -141,8 +143,8 @@ public class TomP2PMessageFacade implements MessageFacade {
|
||||
@Override
|
||||
public void operationComplete(BaseFuture baseFuture) throws Exception {
|
||||
if (baseFuture.isSuccess() && futureGet.data() != null) {
|
||||
final PeerAddress peerAddress = (PeerAddress) futureGet.data().object();
|
||||
Platform.runLater(() -> listener.onResult(peerAddress));
|
||||
final Peer peer = (Peer) futureGet.data().object();
|
||||
Platform.runLater(() -> listener.onResult(peer));
|
||||
}
|
||||
else {
|
||||
Platform.runLater(listener::onFailed);
|
||||
@ -316,9 +318,12 @@ public class TomP2PMessageFacade implements MessageFacade {
|
||||
// Trade process
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public void sendTradeMessage(PeerAddress peerAddress, TradeMessage tradeMessage,
|
||||
public void sendTradeMessage(Peer peer, TradeMessage tradeMessage,
|
||||
OutgoingTradeMessageListener listener) {
|
||||
FutureDirect futureDirect = p2pNode.sendData(peerAddress, tradeMessage);
|
||||
if (!(peer instanceof TomP2PPeer)) {
|
||||
throw new IllegalArgumentException("peer must be of type TomP2PPeer") ;
|
||||
}
|
||||
FutureDirect futureDirect = p2pNode.sendData(((TomP2PPeer)peer).getPeerAddress(), tradeMessage);
|
||||
futureDirect.addListener(new BaseFutureListener<BaseFuture>() {
|
||||
@Override
|
||||
public void operationComplete(BaseFuture future) throws Exception {
|
||||
@ -560,10 +565,10 @@ public class TomP2PMessageFacade implements MessageFacade {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@Override
|
||||
public void handleMessage(Object message, PeerAddress peerAddress) {
|
||||
public void handleMessage(Object message, Peer sender) {
|
||||
if (message instanceof TradeMessage) {
|
||||
Platform.runLater(() -> incomingTradeMessageListeners.stream().forEach(e ->
|
||||
e.onMessage((TradeMessage) message, peerAddress)));
|
||||
e.onMessage((TradeMessage) message, sender)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,10 +17,10 @@
|
||||
|
||||
package io.bitsquare.msg.listeners;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
import io.bitsquare.network.Peer;
|
||||
|
||||
public interface GetPeerAddressListener {
|
||||
void onResult(PeerAddress peerAddress);
|
||||
void onResult(Peer peer);
|
||||
|
||||
void onFailed();
|
||||
}
|
||||
|
@ -17,10 +17,9 @@
|
||||
|
||||
package io.bitsquare.msg.listeners;
|
||||
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.protocol.trade.TradeMessage;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
public interface IncomingTradeMessageListener {
|
||||
void onMessage(TradeMessage tradeMessage, PeerAddress sender);
|
||||
void onMessage(TradeMessage tradeMessage, Peer sender);
|
||||
}
|
||||
|
21
src/main/java/io/bitsquare/network/Peer.java
Normal file
21
src/main/java/io/bitsquare/network/Peer.java
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.network;
|
||||
|
||||
public interface Peer {
|
||||
}
|
43
src/main/java/io/bitsquare/network/tomp2p/TomP2PPeer.java
Normal file
43
src/main/java/io/bitsquare/network/tomp2p/TomP2PPeer.java
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.network.tomp2p;
|
||||
|
||||
import io.bitsquare.network.Peer;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
public class TomP2PPeer implements Peer {
|
||||
|
||||
private final PeerAddress peerAddress;
|
||||
|
||||
public TomP2PPeer(PeerAddress peerAddress) {
|
||||
this.peerAddress = peerAddress;
|
||||
}
|
||||
|
||||
public PeerAddress getPeerAddress() {
|
||||
return peerAddress;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("peerAddress", peerAddress)
|
||||
.toString();
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ import io.bitsquare.btc.BlockChainFacade;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.crypto.CryptoFacade;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.persistence.Persistence;
|
||||
import io.bitsquare.settings.Settings;
|
||||
import io.bitsquare.trade.handlers.ErrorMessageHandler;
|
||||
@ -55,8 +56,6 @@ import javafx.beans.property.StringProperty;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableMap;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -243,7 +242,7 @@ public class TradeManager {
|
||||
// Trading protocols
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private void createOffererAsBuyerProtocol(String offerId, PeerAddress sender) {
|
||||
private void createOffererAsBuyerProtocol(String offerId, Peer sender) {
|
||||
log.trace("createOffererAsBuyerProtocol offerId = " + offerId);
|
||||
if (offers.containsKey(offerId)) {
|
||||
Offer offer = offers.get(offerId);
|
||||
@ -387,7 +386,7 @@ public class TradeManager {
|
||||
return trade;
|
||||
}
|
||||
|
||||
//TODO we don't support interruptions yet.
|
||||
//TODO we don't support interruptions yet.
|
||||
// If the user has shut down the app we lose the offererAsBuyerProtocolMap
|
||||
// Also we don't support yet offline messaging (mail box)
|
||||
public void fiatPaymentStarted(String tradeId) {
|
||||
@ -412,7 +411,7 @@ public class TradeManager {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Routes the incoming messages to the responsible protocol
|
||||
private void onIncomingTradeMessage(TradeMessage tradeMessage, PeerAddress sender) {
|
||||
private void onIncomingTradeMessage(TradeMessage tradeMessage, Peer sender) {
|
||||
// log.trace("processTradingMessage TradeId " + tradeMessage.getTradeId());
|
||||
log.trace("onIncomingTradeMessage instance " + tradeMessage.getClass().getSimpleName());
|
||||
log.trace("onIncomingTradeMessage sender " + sender);
|
||||
|
@ -23,6 +23,7 @@ import io.bitsquare.btc.FeePolicy;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.crypto.CryptoFacade;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.Contract;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import io.bitsquare.trade.Trade;
|
||||
@ -48,8 +49,6 @@ import org.bitcoinj.core.Utils;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@ -96,7 +95,7 @@ public class BuyerAcceptsOfferProtocol {
|
||||
|
||||
// provided
|
||||
private final Trade trade;
|
||||
private final PeerAddress peerAddress;
|
||||
private final Peer peer;
|
||||
private final MessageFacade messageFacade;
|
||||
private final WalletFacade walletFacade;
|
||||
private final BlockChainFacade blockChainFacade;
|
||||
@ -139,7 +138,7 @@ public class BuyerAcceptsOfferProtocol {
|
||||
///////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public BuyerAcceptsOfferProtocol(Trade trade,
|
||||
PeerAddress peerAddress,
|
||||
Peer peer,
|
||||
MessageFacade messageFacade,
|
||||
WalletFacade walletFacade,
|
||||
BlockChainFacade blockChainFacade,
|
||||
@ -147,7 +146,7 @@ public class BuyerAcceptsOfferProtocol {
|
||||
User user,
|
||||
BuyerAcceptsOfferProtocolListener listener) {
|
||||
this.trade = trade;
|
||||
this.peerAddress = peerAddress;
|
||||
this.peer = peer;
|
||||
this.listener = listener;
|
||||
this.messageFacade = messageFacade;
|
||||
this.walletFacade = walletFacade;
|
||||
@ -173,7 +172,7 @@ public class BuyerAcceptsOfferProtocol {
|
||||
public void start() {
|
||||
log.debug("start called " + step++);
|
||||
state = State.HandleTakeOfferRequest;
|
||||
HandleTakeOfferRequest.run(this::onResultHandleTakeOfferRequest, this::onFault, peerAddress, messageFacade,
|
||||
HandleTakeOfferRequest.run(this::onResultHandleTakeOfferRequest, this::onFault, peer, messageFacade,
|
||||
trade.getState(), tradeId);
|
||||
}
|
||||
|
||||
@ -236,7 +235,7 @@ public class BuyerAcceptsOfferProtocol {
|
||||
state = State.RequestTakerDepositPayment;
|
||||
RequestTakerDepositPayment.run(this::onResultRequestTakerDepositPayment,
|
||||
this::onFault,
|
||||
peerAddress,
|
||||
peer,
|
||||
messageFacade,
|
||||
tradeId,
|
||||
bankAccount,
|
||||
@ -336,7 +335,7 @@ public class BuyerAcceptsOfferProtocol {
|
||||
listener.onDepositTxPublished(depositTransaction);
|
||||
|
||||
state = State.SendDepositTxIdToTaker;
|
||||
SendDepositTxIdToTaker.run(this::onResultSendDepositTxIdToTaker, this::onFault, peerAddress, messageFacade,
|
||||
SendDepositTxIdToTaker.run(this::onResultSendDepositTxIdToTaker, this::onFault, peer, messageFacade,
|
||||
tradeId, depositTransaction);
|
||||
}
|
||||
|
||||
@ -378,7 +377,7 @@ public class BuyerAcceptsOfferProtocol {
|
||||
state = State.SendSignedPayoutTx;
|
||||
SendSignedPayoutTx.run(this::onResultSendSignedPayoutTx,
|
||||
this::onFault,
|
||||
peerAddress,
|
||||
peer,
|
||||
messageFacade,
|
||||
walletFacade,
|
||||
tradeId,
|
||||
|
@ -19,19 +19,18 @@ package io.bitsquare.trade.protocol.trade.offerer.tasks;
|
||||
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.Trade;
|
||||
import io.bitsquare.trade.handlers.ExceptionHandler;
|
||||
import io.bitsquare.trade.protocol.trade.offerer.messages.RespondToTakeOfferRequestMessage;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class HandleTakeOfferRequest {
|
||||
private static final Logger log = LoggerFactory.getLogger(HandleTakeOfferRequest.class);
|
||||
|
||||
public static void run(ResultHandler resultHandler, ExceptionHandler exceptionHandler, PeerAddress peerAddress,
|
||||
public static void run(ResultHandler resultHandler, ExceptionHandler exceptionHandler, Peer peer,
|
||||
MessageFacade messageFacade, Trade.State tradeState, String tradeId) {
|
||||
log.trace("Run task");
|
||||
boolean takeOfferRequestAccepted = tradeState == Trade.State.OPEN;
|
||||
@ -40,7 +39,7 @@ public class HandleTakeOfferRequest {
|
||||
}
|
||||
RespondToTakeOfferRequestMessage tradeMessage =
|
||||
new RespondToTakeOfferRequestMessage(tradeId, takeOfferRequestAccepted);
|
||||
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener() {
|
||||
messageFacade.sendTradeMessage(peer, tradeMessage, new OutgoingTradeMessageListener() {
|
||||
@Override
|
||||
public void onResult() {
|
||||
log.trace("RespondToTakeOfferRequestMessage successfully arrived at peer");
|
||||
|
@ -20,12 +20,11 @@ package io.bitsquare.trade.protocol.trade.offerer.tasks;
|
||||
import io.bitsquare.bank.BankAccount;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.handlers.ExceptionHandler;
|
||||
import io.bitsquare.trade.handlers.ResultHandler;
|
||||
import io.bitsquare.trade.protocol.trade.offerer.messages.RequestTakerDepositPaymentMessage;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -34,7 +33,7 @@ public class RequestTakerDepositPayment {
|
||||
|
||||
public static void run(ResultHandler resultHandler,
|
||||
ExceptionHandler exceptionHandler,
|
||||
PeerAddress peerAddress,
|
||||
Peer peer,
|
||||
MessageFacade messageFacade,
|
||||
String tradeId,
|
||||
BankAccount bankAccount,
|
||||
@ -45,7 +44,7 @@ public class RequestTakerDepositPayment {
|
||||
log.trace("Run task");
|
||||
RequestTakerDepositPaymentMessage tradeMessage = new RequestTakerDepositPaymentMessage(
|
||||
tradeId, bankAccount, accountId, offererPubKey, preparedOffererDepositTxAsHex, offererTxOutIndex);
|
||||
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener() {
|
||||
messageFacade.sendTradeMessage(peer, tradeMessage, new OutgoingTradeMessageListener() {
|
||||
@Override
|
||||
public void onResult() {
|
||||
log.trace("RequestTakerDepositPaymentMessage successfully arrived at peer");
|
||||
|
@ -19,6 +19,7 @@ package io.bitsquare.trade.protocol.trade.offerer.tasks;
|
||||
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.handlers.ExceptionHandler;
|
||||
import io.bitsquare.trade.handlers.ResultHandler;
|
||||
import io.bitsquare.trade.protocol.trade.offerer.messages.DepositTxPublishedMessage;
|
||||
@ -26,21 +27,19 @@ import io.bitsquare.trade.protocol.trade.offerer.messages.DepositTxPublishedMess
|
||||
import org.bitcoinj.core.Transaction;
|
||||
import org.bitcoinj.core.Utils;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SendDepositTxIdToTaker {
|
||||
private static final Logger log = LoggerFactory.getLogger(SendDepositTxIdToTaker.class);
|
||||
|
||||
public static void run(ResultHandler resultHandler, ExceptionHandler exceptionHandler, PeerAddress peerAddress,
|
||||
public static void run(ResultHandler resultHandler, ExceptionHandler exceptionHandler, Peer peer,
|
||||
MessageFacade messageFacade, String tradeId, Transaction depositTransaction) {
|
||||
log.trace("Run task");
|
||||
DepositTxPublishedMessage tradeMessage =
|
||||
new DepositTxPublishedMessage(tradeId, Utils.HEX.encode(depositTransaction.bitcoinSerialize()));
|
||||
|
||||
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener() {
|
||||
messageFacade.sendTradeMessage(peer, tradeMessage, new OutgoingTradeMessageListener() {
|
||||
@Override
|
||||
public void onResult() {
|
||||
log.trace("DepositTxPublishedMessage successfully arrived at peer");
|
||||
|
@ -20,6 +20,7 @@ package io.bitsquare.trade.protocol.trade.offerer.tasks;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.handlers.ExceptionHandler;
|
||||
import io.bitsquare.trade.handlers.ResultHandler;
|
||||
import io.bitsquare.trade.protocol.trade.offerer.messages.BankTransferInitedMessage;
|
||||
@ -29,8 +30,6 @@ import org.bitcoinj.core.ECKey;
|
||||
|
||||
import javafx.util.Pair;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -39,7 +38,7 @@ public class SendSignedPayoutTx {
|
||||
|
||||
public static void run(ResultHandler resultHandler,
|
||||
ExceptionHandler exceptionHandler,
|
||||
PeerAddress peerAddress,
|
||||
Peer peer,
|
||||
MessageFacade messageFacade,
|
||||
WalletFacade walletFacade,
|
||||
String tradeId,
|
||||
@ -69,7 +68,7 @@ public class SendSignedPayoutTx {
|
||||
takerPaybackAmount,
|
||||
offererPayoutAddress);
|
||||
|
||||
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener() {
|
||||
messageFacade.sendTradeMessage(peer, tradeMessage, new OutgoingTradeMessageListener() {
|
||||
@Override
|
||||
public void onResult() {
|
||||
log.trace("BankTransferInitedMessage successfully arrived at peer");
|
||||
|
@ -22,6 +22,7 @@ import io.bitsquare.btc.BlockChainFacade;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.crypto.CryptoFacade;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.Contract;
|
||||
import io.bitsquare.trade.Offer;
|
||||
import io.bitsquare.trade.Trade;
|
||||
@ -47,8 +48,6 @@ import org.bitcoinj.core.Transaction;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -106,7 +105,7 @@ public class SellerTakesOfferProtocol {
|
||||
private final String arbitratorPubKey;
|
||||
|
||||
// written/read by task
|
||||
private PeerAddress peerAddress;
|
||||
private Peer peer;
|
||||
|
||||
// written by messages, read by tasks
|
||||
private String peersAccountId;
|
||||
@ -171,12 +170,12 @@ public class SellerTakesOfferProtocol {
|
||||
GetPeerAddress.run(this::onResultGetPeerAddress, this::onFault, messageFacade, peersMessagePublicKey);
|
||||
}
|
||||
|
||||
public void onResultGetPeerAddress(PeerAddress peerAddress) {
|
||||
public void onResultGetPeerAddress(Peer peer) {
|
||||
log.debug("onResultGetPeerAddress called " + step++);
|
||||
this.peerAddress = peerAddress;
|
||||
this.peer = peer;
|
||||
|
||||
state = State.RequestTakeOffer;
|
||||
RequestTakeOffer.run(this::onResultRequestTakeOffer, this::onFault, peerAddress, messageFacade, tradeId);
|
||||
RequestTakeOffer.run(this::onResultRequestTakeOffer, this::onFault, peer, messageFacade, tradeId);
|
||||
}
|
||||
|
||||
public void onResultRequestTakeOffer() {
|
||||
@ -211,7 +210,7 @@ public class SellerTakesOfferProtocol {
|
||||
trade.setTakeOfferFeeTxID(takeOfferFeeTxId);
|
||||
|
||||
state = State.SendTakeOfferFeePayedTxId;
|
||||
SendTakeOfferFeePayedTxId.run(this::onResultSendTakeOfferFeePayedTxId, this::onFault, peerAddress,
|
||||
SendTakeOfferFeePayedTxId.run(this::onResultSendTakeOfferFeePayedTxId, this::onFault, peer,
|
||||
messageFacade, tradeId, takeOfferFeeTxId, tradeAmount, pubKeyForThatTrade);
|
||||
}
|
||||
|
||||
@ -291,7 +290,7 @@ public class SellerTakesOfferProtocol {
|
||||
state = State.SendSignedTakerDepositTxAsHex;
|
||||
SendSignedTakerDepositTxAsHex.run(this::onResultSendSignedTakerDepositTxAsHex,
|
||||
this::onFault,
|
||||
peerAddress,
|
||||
peer,
|
||||
messageFacade,
|
||||
walletFacade,
|
||||
bankAccount,
|
||||
@ -386,7 +385,7 @@ public class SellerTakesOfferProtocol {
|
||||
listener.onPayoutTxPublished(trade, transaction);
|
||||
|
||||
state = State.SendPayoutTxToOfferer;
|
||||
SendPayoutTxToOfferer.run(this::onResultSendPayoutTxToOfferer, this::onFault, peerAddress, messageFacade,
|
||||
SendPayoutTxToOfferer.run(this::onResultSendPayoutTxToOfferer, this::onFault, peer, messageFacade,
|
||||
tradeId, payoutTxAsHex);
|
||||
}
|
||||
|
||||
|
@ -19,12 +19,11 @@ package io.bitsquare.trade.protocol.trade.taker.tasks;
|
||||
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.listeners.GetPeerAddressListener;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.handlers.ExceptionHandler;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -36,9 +35,9 @@ public class GetPeerAddress {
|
||||
log.trace("Run task");
|
||||
messageFacade.getPeerAddress(messagePublicKey, new GetPeerAddressListener() {
|
||||
@Override
|
||||
public void onResult(PeerAddress peerAddress) {
|
||||
log.trace("Received address = " + peerAddress.toString());
|
||||
resultHandler.onResult(peerAddress);
|
||||
public void onResult(Peer peer) {
|
||||
log.trace("Received peer = " + peer.toString());
|
||||
resultHandler.onResult(peer);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -50,7 +49,7 @@ public class GetPeerAddress {
|
||||
}
|
||||
|
||||
public interface ResultHandler {
|
||||
void onResult(PeerAddress peerAddress);
|
||||
void onResult(Peer peer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,22 +19,21 @@ package io.bitsquare.trade.protocol.trade.taker.tasks;
|
||||
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.handlers.ExceptionHandler;
|
||||
import io.bitsquare.trade.handlers.ResultHandler;
|
||||
import io.bitsquare.trade.protocol.trade.taker.messages.RequestTakeOfferMessage;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class RequestTakeOffer {
|
||||
private static final Logger log = LoggerFactory.getLogger(RequestTakeOffer.class);
|
||||
|
||||
public static void run(ResultHandler resultHandler, ExceptionHandler exceptionHandler, PeerAddress peerAddress,
|
||||
public static void run(ResultHandler resultHandler, ExceptionHandler exceptionHandler, Peer peer,
|
||||
MessageFacade messageFacade, String tradeId) {
|
||||
log.trace("Run task");
|
||||
messageFacade.sendTradeMessage(peerAddress, new RequestTakeOfferMessage(tradeId),
|
||||
messageFacade.sendTradeMessage(peer, new RequestTakeOfferMessage(tradeId),
|
||||
new OutgoingTradeMessageListener() {
|
||||
@Override
|
||||
public void onResult() {
|
||||
|
@ -19,23 +19,22 @@ package io.bitsquare.trade.protocol.trade.taker.tasks;
|
||||
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.handlers.ExceptionHandler;
|
||||
import io.bitsquare.trade.handlers.ResultHandler;
|
||||
import io.bitsquare.trade.protocol.trade.taker.messages.PayoutTxPublishedMessage;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SendPayoutTxToOfferer {
|
||||
private static final Logger log = LoggerFactory.getLogger(SendPayoutTxToOfferer.class);
|
||||
|
||||
public static void run(ResultHandler resultHandler, ExceptionHandler exceptionHandler, PeerAddress peerAddress,
|
||||
public static void run(ResultHandler resultHandler, ExceptionHandler exceptionHandler, Peer peer,
|
||||
MessageFacade messageFacade, String tradeId, String payoutTxAsHex) {
|
||||
log.trace("Run task");
|
||||
PayoutTxPublishedMessage tradeMessage = new PayoutTxPublishedMessage(tradeId, payoutTxAsHex);
|
||||
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener() {
|
||||
messageFacade.sendTradeMessage(peer, tradeMessage, new OutgoingTradeMessageListener() {
|
||||
@Override
|
||||
public void onResult() {
|
||||
log.trace("PayoutTxPublishedMessage successfully arrived at peer");
|
||||
|
@ -21,6 +21,7 @@ import io.bitsquare.bank.BankAccount;
|
||||
import io.bitsquare.btc.WalletFacade;
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.handlers.ExceptionHandler;
|
||||
import io.bitsquare.trade.handlers.ResultHandler;
|
||||
import io.bitsquare.trade.protocol.trade.taker.messages.RequestOffererPublishDepositTxMessage;
|
||||
@ -30,8 +31,6 @@ import org.bitcoinj.core.Utils;
|
||||
|
||||
import java.security.PublicKey;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -40,7 +39,7 @@ public class SendSignedTakerDepositTxAsHex {
|
||||
|
||||
public static void run(ResultHandler resultHandler,
|
||||
ExceptionHandler exceptionHandler,
|
||||
PeerAddress peerAddress,
|
||||
Peer peer,
|
||||
MessageFacade messageFacade,
|
||||
WalletFacade walletFacade,
|
||||
BankAccount bankAccount,
|
||||
@ -69,7 +68,7 @@ public class SendSignedTakerDepositTxAsHex {
|
||||
walletFacade.getAddressInfoByTradeID(tradeId).getAddressString(),
|
||||
takerTxOutIndex,
|
||||
offererTxOutIndex);
|
||||
messageFacade.sendTradeMessage(peerAddress, tradeMessage, new OutgoingTradeMessageListener() {
|
||||
messageFacade.sendTradeMessage(peer, tradeMessage, new OutgoingTradeMessageListener() {
|
||||
@Override
|
||||
public void onResult() {
|
||||
log.trace("RequestOffererDepositPublicationMessage successfully arrived at peer");
|
||||
|
@ -19,14 +19,13 @@ package io.bitsquare.trade.protocol.trade.taker.tasks;
|
||||
|
||||
import io.bitsquare.msg.MessageFacade;
|
||||
import io.bitsquare.msg.listeners.OutgoingTradeMessageListener;
|
||||
import io.bitsquare.network.Peer;
|
||||
import io.bitsquare.trade.handlers.ExceptionHandler;
|
||||
import io.bitsquare.trade.handlers.ResultHandler;
|
||||
import io.bitsquare.trade.protocol.trade.taker.messages.TakeOfferFeePayedMessage;
|
||||
|
||||
import org.bitcoinj.core.Coin;
|
||||
|
||||
import net.tomp2p.peers.PeerAddress;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -35,7 +34,7 @@ public class SendTakeOfferFeePayedTxId {
|
||||
|
||||
public static void run(ResultHandler resultHandler,
|
||||
ExceptionHandler exceptionHandler,
|
||||
PeerAddress peerAddress,
|
||||
Peer peer,
|
||||
MessageFacade messageFacade,
|
||||
String tradeId,
|
||||
String takeOfferFeeTxId,
|
||||
@ -45,7 +44,7 @@ public class SendTakeOfferFeePayedTxId {
|
||||
TakeOfferFeePayedMessage msg = new TakeOfferFeePayedMessage(tradeId, takeOfferFeeTxId, tradeAmount,
|
||||
pubKeyForThatTradeAsHex);
|
||||
|
||||
messageFacade.sendTradeMessage(peerAddress, msg, new OutgoingTradeMessageListener() {
|
||||
messageFacade.sendTradeMessage(peer, msg, new OutgoingTradeMessageListener() {
|
||||
@Override
|
||||
public void onResult() {
|
||||
log.trace("TakeOfferFeePayedMessage successfully arrived at peer");
|
||||
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* This file is part of Bitsquare.
|
||||
*
|
||||
* Bitsquare is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* Bitsquare is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||
* License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with Bitsquare. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package io.bitsquare.network.tomp2p;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class TomP2PPeerTest {
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
TomP2PPeer peer = new TomP2PPeer(null);
|
||||
assertThat(peer.toString(), equalTo("TomP2PPeer{peerAddress=null}"));
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user