From 23d52ee7226f4db803bf684175526b9ec6b135a1 Mon Sep 17 00:00:00 2001 From: AllanCapistrano Date: Sat, 23 Mar 2024 16:20:00 -0300 Subject: [PATCH] refactor: changing the behavior of the disturbing node in the same way as the malicious node --- .../java/reputation/node/models/Node.java | 35 +++++++++++++++---- .../ChangeDisturbingNodeBehaviorTask.java | 2 +- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/reputation/node/models/Node.java b/src/main/java/reputation/node/models/Node.java index 6f94491..5ffc2b5 100644 --- a/src/main/java/reputation/node/models/Node.java +++ b/src/main/java/reputation/node/models/Node.java @@ -88,6 +88,7 @@ public class Node implements NodeTypeService, ILedgerSubscriber { private String[] csvData = new String[10]; private long startedExperiment; private boolean flagStartedExperiment = true; + private boolean changeDisturbingNodeBehaviorFlag = false; private static final Logger logger = Logger.getLogger(Node.class.getName()); public Node() {} @@ -278,8 +279,8 @@ private void publishNodeServices(String serviceType, String target) { new IndexTransaction(transactionTypeInString, transaction) ); - /* Alterando o comportamento, caso seja um nó malicioso. */ - this.changeMaliciousNodeBehavior(); + /* Alterando o comportamento, caso seja um nó malicioso ou perturbador. */ + this.changeNodeBehavior(); } catch (InterruptedException ie) { logger.warning( "Error trying to create a " + @@ -672,8 +673,8 @@ private void requestAndEvaluateNodeService( /* Escrevendo os dados no arquivo .csv. */ this.csvWriter.writeData(this.csvData); - /* Alterando o comportamento, caso seja um nó malicioso. */ - this.changeMaliciousNodeBehavior(); + /* Alterando o comportamento, caso seja um nó malicioso ou perturbador. */ + this.changeNodeBehavior(); } /** @@ -1055,9 +1056,9 @@ private int getLastEvaluation( } /** - * Altera o comportamento do nó, caso seja um nó malicioso. + * Altera o comportamento do nó, caso seja um nó malicioso ou perturbador. */ - private void changeMaliciousNodeBehavior() { + private void changeNodeBehavior() { if (this.getNodeType().getType().toString().equals("MALICIOUS")) { this.getNodeType().getNode().defineConduct(); @@ -1067,6 +1068,18 @@ private void changeMaliciousNodeBehavior() { this.getNodeType().getNode().getConductType().toString() ) ); + } else if ( + this.getNodeType().getType().toString().equals("DISTURBING") && + this.changeDisturbingNodeBehaviorFlag + ) { + this.getNodeType().getNode().defineConduct(); + + logger.info( + String.format( + "Changing Disturbing node behavior to '%s'.", + this.getNodeType().getNode().getConductType().toString() + ) + ); } } @@ -1345,4 +1358,14 @@ public String getCredibilityHeader() { public void setCredibilityHeader(String credibilityHeader) { this.credibilityHeader = credibilityHeader; } + + public boolean isChangeDisturbingNodeBehaviorFlag() { + return changeDisturbingNodeBehaviorFlag; + } + + public void setChangeDisturbingNodeBehaviorFlag( + boolean changeDisturbingNodeBehaviorFlag + ) { + this.changeDisturbingNodeBehaviorFlag = changeDisturbingNodeBehaviorFlag; + } } diff --git a/src/main/java/reputation/node/tasks/ChangeDisturbingNodeBehaviorTask.java b/src/main/java/reputation/node/tasks/ChangeDisturbingNodeBehaviorTask.java index 6300d1f..2ff5f21 100644 --- a/src/main/java/reputation/node/tasks/ChangeDisturbingNodeBehaviorTask.java +++ b/src/main/java/reputation/node/tasks/ChangeDisturbingNodeBehaviorTask.java @@ -54,7 +54,7 @@ public void run() { ); if (this.changeBehaviorFlag && reputationValue > REPUTATION_THRESHOLD) { - this.node.getNodeType().getNode().defineConduct(); + this.node.setChangeDisturbingNodeBehaviorFlag(true); this.changeBehaviorFlag = false; } }