From 1673395899b242dbed716a0c93d77e01282fa56e Mon Sep 17 00:00:00 2001 From: AllanCapistrano Date: Sun, 24 Mar 2024 08:58:30 -0300 Subject: [PATCH 1/7] feat: adding useReputation property --- src/main/resources/OSGI-INF/blueprint/blueprint.xml | 2 ++ src/main/resources/br.uefs.larsid.soft_iot.reputation_node.cfg | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/resources/OSGI-INF/blueprint/blueprint.xml b/src/main/resources/OSGI-INF/blueprint/blueprint.xml index 10305fc..06cf481 100644 --- a/src/main/resources/OSGI-INF/blueprint/blueprint.xml +++ b/src/main/resources/OSGI-INF/blueprint/blueprint.xml @@ -42,6 +42,7 @@ + @@ -73,6 +74,7 @@ + diff --git a/src/main/resources/br.uefs.larsid.soft_iot.reputation_node.cfg b/src/main/resources/br.uefs.larsid.soft_iot.reputation_node.cfg index 65ec7ca..a7aa5bd 100644 --- a/src/main/resources/br.uefs.larsid.soft_iot.reputation_node.cfg +++ b/src/main/resources/br.uefs.larsid.soft_iot.reputation_node.cfg @@ -22,6 +22,8 @@ changeDisturbingNodeBehaviorTaskTime=30 useCredibility=true # Determina se é para usar (true) ou não (false) a credibilidade mais recente para o cálculo da reputação. useLatestCredibility=true +# Determina se o sistema vai usar (true) ou não (false) a reputação para a escolha do provedor de serviço. +useReputation=true # Cabeçalho do experimento de credibilidades. # Obs: Separe somente utilizando vírgula credibilityHeader=Node_ID,Type,C(n),R,Tr(n),Cr_old(n),Cr_new(n),Started_experiment_time,wrote_file_time,Node_provider_ID From 88afdc641c0ca890e76d07c6b4fe9a168770af72 Mon Sep 17 00:00:00 2001 From: AllanCapistrano Date: Sun, 24 Mar 2024 09:01:12 -0300 Subject: [PATCH 2/7] feat: allowing the system to use or not use reputation --- .../java/reputation/node/models/Node.java | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main/java/reputation/node/models/Node.java b/src/main/java/reputation/node/models/Node.java index 5ffc2b5..f4c7d5b 100644 --- a/src/main/java/reputation/node/models/Node.java +++ b/src/main/java/reputation/node/models/Node.java @@ -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; @@ -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); @@ -1368,4 +1382,12 @@ public void setChangeDisturbingNodeBehaviorFlag( ) { this.changeDisturbingNodeBehaviorFlag = changeDisturbingNodeBehaviorFlag; } + + public boolean isUseReputation() { + return useReputation; + } + + public void setUseReputation(boolean useReputation) { + this.useReputation = useReputation; + } } From f012608bb22b07b518969d99e6779999f91f14aa Mon Sep 17 00:00:00 2001 From: AllanCapistrano Date: Sun, 24 Mar 2024 09:09:59 -0300 Subject: [PATCH 3/7] feat: allowing the system to use or not use reputation to choose the device --- .../java/reputation/node/models/Node.java | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/reputation/node/models/Node.java b/src/main/java/reputation/node/models/Node.java index f4c7d5b..79ae756 100644 --- a/src/main/java/reputation/node/models/Node.java +++ b/src/main/java/reputation/node/models/Node.java @@ -427,6 +427,8 @@ private String getNodeIdWithHighestReputation() { /** * Obtém os IDs do dispositivo e do sensor, com a maior reputação. + * Obs: Se o sistema não estiver utilizando reputação, então será escolhido + * um dispositivo de maneira aleatória. * * @param deviceSensorIdList List - Lista com os IDs do * dispositivo e sensor que se deseja obter o maior. @@ -479,13 +481,20 @@ private DeviceSensorId getDeviceWithHighestReputation( final Double innerHighestReputation = Double.valueOf(highestReputation); - /** - * Verificando quais dispositivos possuem a maior reputação. - */ - List temp = devicesReputations - .stream() - .filter(nr -> nr.getReputation().equals(innerHighestReputation)) - .collect(Collectors.toList()); + List temp; + + if (this.useCredibility) { + /** + * Verificando quais dispositivos possuem a maior reputação. + */ + temp = + devicesReputations + .stream() + .filter(nr -> nr.getReputation().equals(innerHighestReputation)) + .collect(Collectors.toList()); + } else { + temp = devicesReputations; + } int index = -1; From 528645d3f33e77390a17fbda3b4192f7fcb60141 Mon Sep 17 00:00:00 2001 From: AllanCapistrano Date: Sun, 24 Mar 2024 09:15:19 -0300 Subject: [PATCH 4/7] Revert "feat: allowing the system to use or not use reputation" This reverts commit 88afdc641c0ca890e76d07c6b4fe9a168770af72. --- .../java/reputation/node/models/Node.java | 36 ++++--------------- 1 file changed, 7 insertions(+), 29 deletions(-) diff --git a/src/main/java/reputation/node/models/Node.java b/src/main/java/reputation/node/models/Node.java index 79ae756..ce69a95 100644 --- a/src/main/java/reputation/node/models/Node.java +++ b/src/main/java/reputation/node/models/Node.java @@ -81,7 +81,6 @@ 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; @@ -303,31 +302,18 @@ public void useNodeService() { this.setRequestingNodeServices(false); this.setLastNodeServiceTransactionType(null); } else { - String nodeId = null; + String highestReputationNodeId = this.getNodeIdWithHighestReputation(); - 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); + if (highestReputationNodeId != null) { + final String innerHighestReputationNodeId = String.valueOf( + highestReputationNodeId + ); /** - * Obtendo a transação do nó que prestará o serviço. + * Obtendo a transação do nó com a maior reputação. */ ReputationService nodeWithService = (ReputationService) this.nodesWithServices.stream() - .filter(nws -> nws.getSource().equals(innerNodeId)) + .filter(nws -> nws.getSource().equals(innerHighestReputationNodeId)) .collect(Collectors.toList()) .get(0); @@ -1391,12 +1377,4 @@ public void setChangeDisturbingNodeBehaviorFlag( ) { this.changeDisturbingNodeBehaviorFlag = changeDisturbingNodeBehaviorFlag; } - - public boolean isUseReputation() { - return useReputation; - } - - public void setUseReputation(boolean useReputation) { - this.useReputation = useReputation; - } } From 65cc73241f6a98c10ea80df93ad131c77e1b389c Mon Sep 17 00:00:00 2001 From: AllanCapistrano Date: Sun, 24 Mar 2024 09:17:03 -0300 Subject: [PATCH 5/7] feat: adding useReputation attribute --- src/main/java/reputation/node/models/Node.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/reputation/node/models/Node.java b/src/main/java/reputation/node/models/Node.java index ce69a95..2eaaec6 100644 --- a/src/main/java/reputation/node/models/Node.java +++ b/src/main/java/reputation/node/models/Node.java @@ -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; @@ -1377,4 +1378,12 @@ public void setChangeDisturbingNodeBehaviorFlag( ) { this.changeDisturbingNodeBehaviorFlag = changeDisturbingNodeBehaviorFlag; } + + public boolean isUseReputation() { + return useReputation; + } + + public void setUseReputation(boolean useReputation) { + this.useReputation = useReputation; + } } From fb57df6d9340d108aaa0ffbf556a5887f25f2fcd Mon Sep 17 00:00:00 2001 From: AllanCapistrano Date: Sun, 24 Mar 2024 09:19:03 -0300 Subject: [PATCH 6/7] feat: allowing the system to use or not use reputation to choose a service provider node --- .../java/reputation/node/models/Node.java | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main/java/reputation/node/models/Node.java b/src/main/java/reputation/node/models/Node.java index 2eaaec6..44d824b 100644 --- a/src/main/java/reputation/node/models/Node.java +++ b/src/main/java/reputation/node/models/Node.java @@ -388,13 +388,20 @@ private String getNodeIdWithHighestReputation() { final Double innerHighestReputation = Double.valueOf(highestReputation); - /** - * Verificando quais nós possuem a maior reputação. - */ - List temp = nodesReputations - .stream() - .filter(nr -> nr.getReputation().equals(innerHighestReputation)) - .collect(Collectors.toList()); + List temp; + + if (this.useReputation) { + /** + * Verificando quais nós possuem a maior reputação. + */ + temp = + nodesReputations + .stream() + .filter(nr -> nr.getReputation().equals(innerHighestReputation)) + .collect(Collectors.toList()); + } else { + temp = nodesReputations; + } /** * Obtendo o ID de um dos nós com a maior reputação. @@ -470,7 +477,7 @@ private DeviceSensorId getDeviceWithHighestReputation( List temp; - if (this.useCredibility) { + if (this.useReputation) { /** * Verificando quais dispositivos possuem a maior reputação. */ From 6de73bf65bece5a7ba74aeb0418f9eb2106b4bc2 Mon Sep 17 00:00:00 2001 From: AllanCapistrano Date: Sun, 24 Mar 2024 09:21:54 -0300 Subject: [PATCH 7/7] docs: improving getNodeIdWithHighestReputation docs --- src/main/java/reputation/node/models/Node.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/reputation/node/models/Node.java b/src/main/java/reputation/node/models/Node.java index 44d824b..2742e66 100644 --- a/src/main/java/reputation/node/models/Node.java +++ b/src/main/java/reputation/node/models/Node.java @@ -344,6 +344,8 @@ public void useNodeService() { /** * Obtém o ID do nó com a maior reputação dentre aqueles que reponderam a * requisição. + * Obs: Se o sistema não estiver utilizando reputação, então será escolhido um + * nó provedor de serviço de maneira aleatória. * * @return String */