add attack package

pull/18/head
Minh Doan 7 years ago
parent 45cf34366b
commit a62de84eb0
  1. 41
      attack/attack.go
  2. 6
      benchmark.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**********************************")
}
}

@ -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)
}

Loading…
Cancel
Save