From 6923f873ca08973e671acf31f0f06b85ad481521 Mon Sep 17 00:00:00 2001 From: AllanCapistrano Date: Fri, 15 Mar 2024 20:42:19 -0300 Subject: [PATCH] feat: allowing maliciously behaving node providing service incorrectly --- .../java/reputation/node/models/Node.java | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/reputation/node/models/Node.java b/src/main/java/reputation/node/models/Node.java index 96a76eb..cdcf1f3 100644 --- a/src/main/java/reputation/node/models/Node.java +++ b/src/main/java/reputation/node/models/Node.java @@ -204,14 +204,28 @@ private void publishNodeServices(String serviceType, String target) { this.mutex.unlock(); } - for (Device d : tempDevices) { - d - .getSensors() - .stream() - .filter(s -> s.getType().equals(serviceType)) - .forEach(s -> - deviceSensorIdList.add(new DeviceSensorId(d.getId(), s.getId())) - ); + /* Se o nó estiver com o comportamento malicioso, irá oferecer um + dispositivo e sensor inexistente. */ + if ( + this.getNodeType() + .getNode() + .getConductType() + .toString() + .equals("MALICIOUS") + ) { + deviceSensorIdList.add( + new DeviceSensorId("nonexistentDevice", "nonexistentSensor") + ); + } else { + for (Device d : tempDevices) { + d + .getSensors() + .stream() + .filter(s -> s.getType().equals(serviceType)) + .forEach(s -> + deviceSensorIdList.add(new DeviceSensorId(d.getId(), s.getId())) + ); + } } if (