add timeout attack

pull/18/head
Minh Doan 7 years ago
parent 8a276591a7
commit 1b5f6d10f4
  1. 15
      attack/attack.go
  2. 2
      benchmark.go
  3. BIN
      harmony-benchmark
  4. 4
      p2p/peer.go

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

@ -101,7 +101,7 @@ func main() {
consensus := consensus.NewConsensus(*ip, *port, shardId, peers, leader)
node := node.NewNode(&consensus)
attack := attack.New(&consensus)
attack := attack.New(consensus.Log)
clientPeer := getClientPeer(&config)
// If there is a client configured in the node list.

Binary file not shown.

@ -3,6 +3,7 @@ package p2p
import (
"bytes"
"encoding/binary"
"harmony-benchmark/attack"
"log"
"net"
"strings"
@ -77,6 +78,9 @@ 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.DelayResponse()
sendWithSocketClient(ip, port, message)
return
}

Loading…
Cancel
Save