-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from AllanCapistrano/feat/disturbing-behavior
Feat/disturbing behavior
- Loading branch information
Showing
5 changed files
with
113 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/reputation/node/tasks/ChangeDisturbingNodeBehaviorTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package reputation.node.tasks; | ||
|
||
import dlt.client.tangle.hornet.model.transactions.Transaction; | ||
import java.util.List; | ||
import java.util.TimerTask; | ||
import java.util.logging.Logger; | ||
import reputation.node.models.Node; | ||
import reputation.node.reputation.IReputation; | ||
|
||
/** | ||
* Task para alterar o comportamento de um nó do tipo Perturbador. | ||
* | ||
* @author Allan Capistrano | ||
* @version 1.0.0 | ||
*/ | ||
public class ChangeDisturbingNodeBehaviorTask extends TimerTask { | ||
|
||
private static final double REPUTATION_THRESHOLD = 0.9; | ||
|
||
private final Node node; | ||
private final IReputation reputation; | ||
private boolean changeBehaviorFlag = true; | ||
|
||
private static final Logger logger = Logger.getLogger( | ||
ChangeDisturbingNodeBehaviorTask.class.getName() | ||
); | ||
|
||
/** | ||
* Método construtor. | ||
* @param node Node - O nó que verificará a própria reputação. | ||
* @param reputation IReputation - Objeto para calcular a reputação. | ||
*/ | ||
public ChangeDisturbingNodeBehaviorTask(Node node, IReputation reputation) { | ||
this.node = node; | ||
this.reputation = reputation; | ||
} | ||
|
||
@Override | ||
public void run() { | ||
List<Transaction> evaluationTransactions = | ||
this.node.getLedgerConnector() | ||
.getLedgerReader() | ||
.getTransactionsByIndex(this.node.getNodeType().getNodeId(), false); | ||
|
||
double reputationValue = | ||
this.reputation.calculate( | ||
evaluationTransactions, | ||
this.node.isUseLatestCredibility(), | ||
this.node.isUseCredibility() | ||
); | ||
|
||
logger.info( | ||
String.format("Disturbing node reputation: %f", reputationValue) | ||
); | ||
|
||
if (this.changeBehaviorFlag && reputationValue > REPUTATION_THRESHOLD) { | ||
this.node.getNodeType().getNode().defineConduct(); | ||
this.changeBehaviorFlag = false; | ||
} | ||
|
||
/** | ||
* Quando o nó alcançar uma reputação negativa, ele está habilitado a | ||
* poder alterar novamente seu comportamento. | ||
*/ | ||
if (reputationValue <= 0) { | ||
this.changeBehaviorFlag = true; | ||
} | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
src/main/java/reputation/node/tasks/CheckNodeReputationTask.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters