Skip to content

Commit

Permalink
feat: allowing the system to use or not use reputation
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanCapistrano committed Mar 24, 2024
1 parent 1673395 commit 88afdc6
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/main/java/reputation/node/models/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public class Node implements NodeTypeService, ILedgerSubscriber {
private boolean isNodesCredibilityWithSourceEmpty = true;
private boolean useCredibility;
private boolean useLatestCredibility;
private boolean useReputation;
private double reputationValue;
private NodeCredibility nodeCredibility;
private CsvWriterService csvWriter;
Expand Down Expand Up @@ -302,18 +303,31 @@ public void useNodeService() {
this.setRequestingNodeServices(false);
this.setLastNodeServiceTransactionType(null);
} else {
String highestReputationNodeId = this.getNodeIdWithHighestReputation();
String nodeId = null;

if (highestReputationNodeId != null) {
final String innerHighestReputationNodeId = String.valueOf(
highestReputationNodeId
);
if (this.useReputation) {
nodeId = this.getNodeIdWithHighestReputation();
} else {
if (this.nodesWithServices.size() == 1) {
nodeId = this.nodesWithServices.get(0).getSource();
} else if (this.nodesWithServices.size() > 1) {
/* Escolhendo o provedor do serviço de maneira aleatória. */
int randomIndex = new Random().nextInt(this.nodesWithServices.size());

nodeId = this.nodesWithServices.get(randomIndex).getSource();
} else {
logger.severe("Invalid amount of service provider nodes.");
}
}

if (nodeId != null) {
final String innerNodeId = String.valueOf(nodeId);

/**
* Obtendo a transação do nó com a maior reputação.
* Obtendo a transação do nó que prestará o serviço.
*/
ReputationService nodeWithService = (ReputationService) this.nodesWithServices.stream()
.filter(nws -> nws.getSource().equals(innerHighestReputationNodeId))
.filter(nws -> nws.getSource().equals(innerNodeId))
.collect(Collectors.toList())
.get(0);

Expand Down Expand Up @@ -1368,4 +1382,12 @@ public void setChangeDisturbingNodeBehaviorFlag(
) {
this.changeDisturbingNodeBehaviorFlag = changeDisturbingNodeBehaviorFlag;
}

public boolean isUseReputation() {
return useReputation;
}

public void setUseReputation(boolean useReputation) {
this.useReputation = useReputation;
}
}

0 comments on commit 88afdc6

Please sign in to comment.