Skip to content

Commit

Permalink
refactor: changing the behavior of the disturbing node in the same wa…
Browse files Browse the repository at this point in the history
…y as the malicious node
  • Loading branch information
AllanCapistrano committed Mar 23, 2024
1 parent f14d1d7 commit 23d52ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
35 changes: 29 additions & 6 deletions src/main/java/reputation/node/models/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand Down Expand Up @@ -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 " +
Expand Down Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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();

Expand All @@ -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()
)
);
}
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 23d52ee

Please sign in to comment.