4
4
import dlt .client .tangle .hornet .model .transactions .IndexTransaction ;
5
5
import dlt .client .tangle .hornet .model .transactions .Transaction ;
6
6
import dlt .client .tangle .hornet .model .transactions .reputation .Evaluation ;
7
+ import java .util .Random ;
7
8
import java .util .logging .Logger ;
8
9
import node .type .models .enums .ConductType ;
9
10
import node .type .models .tangle .LedgerConnector ;
12
13
* Nó do tipo perturbador.
13
14
*
14
15
* @author Allan Capistrano
15
- * @version 1.1 .0
16
+ * @version 1.2 .0
16
17
*/
17
18
public class Disturbing extends Conduct {
18
19
20
+ private final float honestyRate ;
21
+
19
22
private static final Logger logger = Logger .getLogger (
20
23
Disturbing .class .getName ()
21
24
);
@@ -27,35 +30,30 @@ public class Disturbing extends Conduct {
27
30
* Tangle.
28
31
* @param id String - Identificador único do nó.
29
32
*/
30
- public Disturbing (LedgerConnector ledgerConnector , String id , String group ) {
33
+ public Disturbing (
34
+ LedgerConnector ledgerConnector ,
35
+ String id ,
36
+ String group ,
37
+ float honestyRate
38
+ ) {
31
39
super (ledgerConnector , id , group );
32
40
this .setConductType (ConductType .HONEST );
41
+ this .honestyRate = honestyRate ;
33
42
}
34
43
35
44
/**
36
45
* Define o comportamento do nó perturbador.
37
46
*/
38
47
@ Override
39
48
public void defineConduct () {
40
- this .changeConduct ();
41
- }
42
-
43
- /**
44
- * Altera a conduta do nó:
45
- * Se ele for honesto -> muda para malicioso;
46
- * Se ele for malicioso -> muda para honesto.
47
- */
48
- private void changeConduct () {
49
- this .setConductType (
50
- this .getConductType () == ConductType .HONEST
51
- ? ConductType .MALICIOUS
52
- : ConductType .HONEST
53
- );
49
+ /* Gerando um número aleatório entre 0 e 100. */
50
+ float randomNumber = new Random ().nextFloat () * 100 ;
54
51
55
- logger .info (
56
- "Changing Disturbing node behavior to: " +
57
- this .getConductType ().toString ()
58
- );
52
+ if (randomNumber > this .honestyRate ) {
53
+ this .setConductType (ConductType .MALICIOUS );
54
+ } else {
55
+ this .setConductType (ConductType .HONEST );
56
+ }
59
57
}
60
58
61
59
/**
@@ -90,12 +88,12 @@ public void evaluateServiceProvider(
90
88
logger .info ("[" + serviceProviderId + "] Provided the service." );
91
89
break ;
92
90
default :
93
- logger .warning ("Unable to evaluate the device " );
91
+ logger .warning ("Unable to evaluate the service provider. " );
94
92
break ;
95
93
}
96
94
break ;
97
95
case MALICIOUS :
98
- logger .info ("Did not provide the service." );
96
+ logger .info ("[" + serviceProviderId + "] Did not provide the service." );
99
97
/* Alterando o valor da avaliação para 'serviço não prestado'. */
100
98
serviceEvaluation = 0 ;
101
99
value = 0 ;
@@ -119,4 +117,8 @@ public void evaluateServiceProvider(
119
117
this .getLedgerConnector ()
120
118
.put (new IndexTransaction (serviceProviderId , transactionEvaluation ));
121
119
}
120
+
121
+ public float getHonestyRate () {
122
+ return honestyRate ;
123
+ }
122
124
}
0 commit comments