make sure attack_enabled default to false so that tnx client wont get attacked. also add more attack in validator

pull/34/head
Minh Doan 6 years ago
parent 3e472e8ed8
commit 9266fdc264
  1. 23
      attack/attack.go
  2. 6
      consensus/consensus_validator.go

@ -10,7 +10,6 @@ import (
const (
DroppingTickDuration = 2 * time.Second
AttackEnabled = false
HitRate = 10
DelayResponseDuration = 10 * time.Second
ConsensusIdThresholdMin = 10
@ -27,11 +26,11 @@ const (
// AttackModel contains different models of attacking.
type Attack struct {
AttackEnabled bool
attackType AttackType
ConsensusIdThreshold uint32
readyByConsensus bool
log log.Logger // Log utility
AttackEnabled bool
attackType AttackType
ConsensusIdThreshold uint32
readyByConsensusThreshold bool
log log.Logger // Log utility
}
var attack *Attack
@ -47,8 +46,8 @@ func GetInstance() *Attack {
}
func (attack *Attack) Init() {
attack.AttackEnabled = AttackEnabled
attack.readyByConsensus = false
attack.AttackEnabled = false
attack.readyByConsensusThreshold = false
}
func (attack *Attack) SetAttackEnabled(AttackEnabled bool) {
@ -70,7 +69,7 @@ func (attack *Attack) Run() {
// NodeKilledByItSelf runs killing itself attack
func (attack *Attack) NodeKilledByItSelf() {
if !attack.AttackEnabled || attack.attackType != KilledItself || !attack.readyByConsensus {
if !attack.AttackEnabled || attack.attackType != KilledItself || !attack.readyByConsensusThreshold {
return
}
@ -81,7 +80,7 @@ func (attack *Attack) NodeKilledByItSelf() {
}
func (attack *Attack) DelayResponse() {
if !attack.AttackEnabled || attack.attackType != DelayResponse || !attack.readyByConsensus {
if !attack.AttackEnabled || attack.attackType != DelayResponse || !attack.readyByConsensusThreshold {
return
}
if rand.Intn(HitRate) == 0 {
@ -91,7 +90,7 @@ func (attack *Attack) DelayResponse() {
}
func (attack *Attack) IncorrectResponse() bool {
if !attack.AttackEnabled || attack.attackType != IncorrectResponse || !attack.readyByConsensus {
if !attack.AttackEnabled || attack.attackType != IncorrectResponse || !attack.readyByConsensusThreshold {
return false
}
if rand.Intn(HitRate) == 0 {
@ -103,6 +102,6 @@ func (attack *Attack) IncorrectResponse() bool {
func (attack *Attack) UpdateConsensusReady(consensusId uint32) {
if consensusId > attack.ConsensusIdThreshold {
attack.readyByConsensus = true
attack.readyByConsensusThreshold = true
}
}

@ -101,6 +101,12 @@ func (consensus *Consensus) processAnnounceMessage(payload []byte) {
consensus.blocksReceived[consensusId] = &BlockConsensusStatus{blockHeader, consensus.state}
consensus.mutex.Unlock()
// Add attack model of IncorrectResponse.
if attack.GetInstance().IncorrectResponse() {
consensus.Log.Warn("IncorrectResponse attacked")
return
}
// check consensus Id
if consensusId != consensus.consensusId {
consensus.Log.Warn("Received message with wrong consensus Id", "myConsensusId", consensus.consensusId, "theirConsensusId", consensusId, "consensus", consensus)

Loading…
Cancel
Save