validate sender hostname and update address on dispute opened message

This commit is contained in:
woodser 2024-02-01 08:12:31 -05:00
parent dfaf39bab3
commit 1a0fab8c47
2 changed files with 15 additions and 12 deletions

View File

@ -468,7 +468,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
try { try {
DisputeValidation.validateDisputeData(dispute); DisputeValidation.validateDisputeData(dispute);
DisputeValidation.validateNodeAddresses(dispute, config); DisputeValidation.validateNodeAddresses(dispute, config);
DisputeValidation.validateSenderNodeAddress(dispute, message.getSenderNodeAddress()); DisputeValidation.validateSenderNodeAddress(dispute, message.getSenderNodeAddress(), config);
//DisputeValidation.testIfDisputeTriesReplay(dispute, disputeList.getList()); //DisputeValidation.testIfDisputeTriesReplay(dispute, disputeList.getList());
} catch (DisputeValidation.ValidationException e) { } catch (DisputeValidation.ValidationException e) {
e.printStackTrace(); e.printStackTrace();
@ -477,9 +477,8 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
} }
// try to validate payment account // try to validate payment account
// TODO: add field to dispute details: valid, invalid, missing
try { try {
DisputeValidation.validatePaymentAccountPayload(dispute); DisputeValidation.validatePaymentAccountPayload(dispute); // TODO: add field to dispute details: valid, invalid, missing
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
log.warn(e.getMessage()); log.warn(e.getMessage());
@ -491,6 +490,9 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
TradePeer sender = trade.getTradePeer(senderPubKeyRing); TradePeer sender = trade.getTradePeer(senderPubKeyRing);
if (sender == null) throw new RuntimeException("Pub key ring is not from arbitrator, buyer, or seller"); if (sender == null) throw new RuntimeException("Pub key ring is not from arbitrator, buyer, or seller");
// update sender node address
sender.setNodeAddress(message.getSenderNodeAddress());
// message to trader is expected from arbitrator // message to trader is expected from arbitrator
if (!trade.isArbitrator() && sender != trade.getArbitrator()) { if (!trade.isArbitrator() && sender != trade.getArbitrator()) {
throw new RuntimeException(message.getClass().getSimpleName() + " to trader is expected only from arbitrator"); throw new RuntimeException(message.getClass().getSimpleName() + " to trader is expected only from arbitrator");

View File

@ -77,20 +77,21 @@ public class DisputeValidation {
public static void validateSenderNodeAddress(Dispute dispute, public static void validateSenderNodeAddress(Dispute dispute,
NodeAddress senderNodeAddress) throws NodeAddressException { NodeAddress senderNodeAddress,
if (!senderNodeAddress.equals(dispute.getContract().getBuyerNodeAddress()) Config config) throws NodeAddressException {
&& !senderNodeAddress.equals(dispute.getContract().getSellerNodeAddress()) if (config.useLocalhostForP2P) return;
&& !senderNodeAddress.equals(dispute.getContract().getArbitratorNodeAddress())) { if (!senderNodeAddress.getHostName().equals(dispute.getContract().getBuyerNodeAddress().getHostName())
throw new NodeAddressException(dispute, "senderNodeAddress not matching any of the traders node addresses"); && !senderNodeAddress.getHostName().equals(dispute.getContract().getSellerNodeAddress().getHostName())
&& !senderNodeAddress.getHostName().equals(dispute.getContract().getArbitratorNodeAddress().getHostName())) {
throw new NodeAddressException(dispute, "senderNodeAddress not matching any of the trade node addresses");
} }
} }
public static void validateNodeAddresses(Dispute dispute, Config config) public static void validateNodeAddresses(Dispute dispute, Config config)
throws NodeAddressException { throws NodeAddressException {
if (!config.useLocalhostForP2P) { if (config.useLocalhostForP2P) return;
validateNodeAddress(dispute, dispute.getContract().getBuyerNodeAddress()); validateNodeAddress(dispute, dispute.getContract().getBuyerNodeAddress());
validateNodeAddress(dispute, dispute.getContract().getSellerNodeAddress()); validateNodeAddress(dispute, dispute.getContract().getSellerNodeAddress());
}
} }
private static void validateNodeAddress(Dispute dispute, NodeAddress nodeAddress) throws NodeAddressException { private static void validateNodeAddress(Dispute dispute, NodeAddress nodeAddress) throws NodeAddressException {