From a62de84eb01875c65b939e99f182a42f7a683d56 Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Mon, 2 Jul 2018 15:16:42 -0700 Subject: [PATCH] add attack package --- attack/attack.go | 41 +++++++++++++++++++++++++++++++++++++++++ benchmark.go | 6 ++++++ 2 files changed, 47 insertions(+) create mode 100644 attack/attack.go diff --git a/attack/attack.go b/attack/attack.go new file mode 100644 index 000000000..38445cf3d --- /dev/null +++ b/attack/attack.go @@ -0,0 +1,41 @@ +package attack + +import ( + "harmony-benchmark/consensus" + "harmony-benchmark/log" + "time" +) + +const ( + DroppingTimerDuration = 2 * time.Second +) + +// AttackModel contains different models of attacking. +type Attack struct { + log log.Logger // Log utility +} + +func New(consensus *consensus.Consensus) *Attack { + attackModel := Attack{} + // Logger + attackModel.log = consensus.Log + return &attackModel +} + +func (attack *Attack) Run() { + // Adding attack model here. + go func() { + // TODO(minhdoan): Enable it later after done attacking. + // attack.NodeKilledByItSelf() + }() +} + +// NodeKilledByItSelf +// Attack #1 in the doc. +func (attack *Attack) NodeKilledByItSelf() { + tick := time.Tick(DroppingTimerDuration) + for { + <-tick + attack.log.Debug("**********************************killed itself**********************************") + } +} diff --git a/benchmark.go b/benchmark.go index 9a5667d2a..bc1c1f55e 100644 --- a/benchmark.go +++ b/benchmark.go @@ -4,6 +4,7 @@ import ( "bufio" "flag" "fmt" + "harmony-benchmark/attack" "harmony-benchmark/consensus" "harmony-benchmark/log" "harmony-benchmark/node" @@ -95,6 +96,7 @@ func main() { consensus := consensus.NewConsensus(*ip, *port, shardId, peers, leader) node := node.NewNode(&consensus) + attack := attack.New(&consensus) clientPeer := getClientPeer(&config) // If there is a client configured in the node list. @@ -120,5 +122,9 @@ func main() { }() } + // TODO(minhdoan): Enable it later after done attacking. + // Run attack. + attack.Run() + node.StartServer(*port) }