|
|
@ -1,7 +1,6 @@ |
|
|
|
package attack |
|
|
|
package attack |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"harmony-benchmark/consensus" |
|
|
|
|
|
|
|
"harmony-benchmark/log" |
|
|
|
"harmony-benchmark/log" |
|
|
|
"math/rand" |
|
|
|
"math/rand" |
|
|
|
"os" |
|
|
|
"os" |
|
|
@ -12,6 +11,7 @@ const ( |
|
|
|
DroppingTickDuration = 2 * time.Second |
|
|
|
DroppingTickDuration = 2 * time.Second |
|
|
|
AttackEnabled = false |
|
|
|
AttackEnabled = false |
|
|
|
HitRate = 10 |
|
|
|
HitRate = 10 |
|
|
|
|
|
|
|
DelayResponseDuration = 10 * time.Second |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// AttackModel contains different models of attacking.
|
|
|
|
// AttackModel contains different models of attacking.
|
|
|
@ -19,10 +19,10 @@ type Attack struct { |
|
|
|
log log.Logger // Log utility
|
|
|
|
log log.Logger // Log utility
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func New(consensus *consensus.Consensus) *Attack { |
|
|
|
func New(log log.Logger) *Attack { |
|
|
|
attackModel := Attack{} |
|
|
|
attackModel := Attack{} |
|
|
|
// Logger
|
|
|
|
// Logger
|
|
|
|
attackModel.log = consensus.Log |
|
|
|
attackModel.log = log |
|
|
|
return &attackModel |
|
|
|
return &attackModel |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -48,3 +48,12 @@ func (attack *Attack) NodeKilledByItSelf() { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func DelayResponse() { |
|
|
|
|
|
|
|
if !AttackEnabled { |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if rand.Intn(HitRate) == 0 { |
|
|
|
|
|
|
|
time.Sleep(DelayResponseDuration) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|