enable attack timeout and killing itself

pull/27/head
Minh Doan 6 years ago
parent 57b6fcc863
commit 283ef0b3da
  1. 17
      attack/attack.go
  2. 4
      benchmark.go
  3. 4
      consensus/consensus_validator.go
  4. 2
      p2p/peer.go

@ -29,7 +29,7 @@ const (
type Attack struct {
AttackEnabled bool
attackType AttackType
ConsensusIdThreshold int
ConsensusIdThreshold uint32
readyByConsensus bool
log log.Logger // Log utility
}
@ -37,8 +37,8 @@ type Attack struct {
var attack *Attack
var once sync.Once
// GetAttackModel returns attack model by using singleton pattern.
func GetAttackModel() *Attack {
// GetInstance returns attack model by using singleton pattern.
func GetInstance() *Attack {
once.Do(func() {
attack = &Attack{}
attack.Init()
@ -55,7 +55,7 @@ func (attack *Attack) SetAttackEnabled(AttackEnabled bool) {
attack.AttackEnabled = AttackEnabled
if AttackEnabled {
attack.attackType = AttackType(rand.Intn(3))
attack.ConsensusIdThreshold = ConsensusIdThresholdMin + rand.Intn(ConsensusIdThresholdMax-ConsensusIdThresholdMin)
attack.ConsensusIdThreshold = uint32(ConsensusIdThresholdMin + rand.Intn(ConsensusIdThresholdMax-ConsensusIdThresholdMin))
}
}
@ -63,9 +63,14 @@ func (attack *Attack) SetLogger(log log.Logger) {
attack.log = log
}
func (attack *Attack) Run() {
attack.NodeKilledByItSelf()
attack.DelayResponse()
}
// NodeKilledByItSelf runs killing itself attack
func (attack *Attack) NodeKilledByItSelf() {
if !attack.AttackEnabled || attack.attackType != DelayResponse || !attack.readyByConsensus {
if !attack.AttackEnabled || attack.attackType != KilledItself || !attack.readyByConsensus {
return
}
@ -84,7 +89,7 @@ func (attack *Attack) DelayResponse() {
}
}
func (attack *Attack) UpdateConsensusReady(consensusId int) {
func (attack *Attack) UpdateConsensusReady(consensusId uint32) {
if consensusId > attack.ConsensusIdThreshold {
attack.readyByConsensus = true
}

@ -102,7 +102,7 @@ func main() {
rand.Seed(int64(time.Now().Nanosecond()))
// Attack determination.
attack.GetAttackModel().SetAttackEnabled(attackDetermination(*attackedMode))
attack.GetInstance().SetAttackEnabled(attackDetermination(*attackedMode))
config := readConfigFile(*configFile)
shardId := getShardId(*ip, *port, &config)
@ -122,7 +122,7 @@ func main() {
node := node.NewNode(&consensus)
// Set logger to attack model.
attack.GetAttackModel().SetLogger(consensus.Log)
attack.GetInstance().SetLogger(consensus.Log)
clientPeer := getClientPeer(&config)
// If there is a client configured in the node list.

@ -4,6 +4,7 @@ import (
"bytes"
"encoding/binary"
"encoding/gob"
"harmony-benchmark/attack"
"harmony-benchmark/blockchain"
"harmony-benchmark/p2p"
"regexp"
@ -234,6 +235,9 @@ func (consensus *Consensus) processChallengeMessage(payload []byte) {
// If I received previous block (which haven't been processed. I will roll up to current block if everything checks.
}
// Update readyByConsensus for attack.
attack.GetInstance().UpdateConsensusReady(consensusId)
// TODO: verify aggregated commits with real schnor cosign verification
// TODO: return the signature(response) to leader

@ -80,7 +80,7 @@ func sendWithSocketClient(ip, port string, message []byte) (res string) {
// Send a message to another node with given port.
func send(ip, port string, message []byte) (returnMessage string) {
// Add attack code here.
attack.GetAttackModel().DelayResponse()
attack.GetInstance().Run()
sendWithSocketClient(ip, port, message)
return

Loading…
Cancel
Save