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 {
DisputeValidation.validateDisputeData(dispute);
DisputeValidation.validateNodeAddresses(dispute, config);
DisputeValidation.validateSenderNodeAddress(dispute, message.getSenderNodeAddress());
DisputeValidation.validateSenderNodeAddress(dispute, message.getSenderNodeAddress(), config);
//DisputeValidation.testIfDisputeTriesReplay(dispute, disputeList.getList());
} catch (DisputeValidation.ValidationException e) {
e.printStackTrace();
@ -477,9 +477,8 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
}
// try to validate payment account
// TODO: add field to dispute details: valid, invalid, missing
try {
DisputeValidation.validatePaymentAccountPayload(dispute);
DisputeValidation.validatePaymentAccountPayload(dispute); // TODO: add field to dispute details: valid, invalid, missing
} catch (Exception e) {
e.printStackTrace();
log.warn(e.getMessage());
@ -491,6 +490,9 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
TradePeer sender = trade.getTradePeer(senderPubKeyRing);
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
if (!trade.isArbitrator() && sender != trade.getArbitrator()) {
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,
NodeAddress senderNodeAddress) throws NodeAddressException {
if (!senderNodeAddress.equals(dispute.getContract().getBuyerNodeAddress())
&& !senderNodeAddress.equals(dispute.getContract().getSellerNodeAddress())
&& !senderNodeAddress.equals(dispute.getContract().getArbitratorNodeAddress())) {
throw new NodeAddressException(dispute, "senderNodeAddress not matching any of the traders node addresses");
NodeAddress senderNodeAddress,
Config config) throws NodeAddressException {
if (config.useLocalhostForP2P) return;
if (!senderNodeAddress.getHostName().equals(dispute.getContract().getBuyerNodeAddress().getHostName())
&& !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)
throws NodeAddressException {
if (!config.useLocalhostForP2P) {
validateNodeAddress(dispute, dispute.getContract().getBuyerNodeAddress());
validateNodeAddress(dispute, dispute.getContract().getSellerNodeAddress());
}
if (config.useLocalhostForP2P) return;
validateNodeAddress(dispute, dispute.getContract().getBuyerNodeAddress());
validateNodeAddress(dispute, dispute.getContract().getSellerNodeAddress());
}
private static void validateNodeAddress(Dispute dispute, NodeAddress nodeAddress) throws NodeAddressException {