Merge branch 'master' of github.com:simple-rules/harmony-benchmark

pull/20/head
alok 6 years ago
commit 16620da96b
  1. 2
      appspec.yml
  2. 59
      attack/attack.go
  3. 1
      aws-scripts/run_instances.sh
  4. 1
      aws-scripts/say_bye.sh
  5. 2
      aws-scripts/say_hello.sh
  6. 1
      aws-scripts/setup_golang.sh
  7. 16
      aws-scripts/spot-instance/request-spot.sh
  8. 7
      aws-scripts/spot-instance/userdata.sh
  9. 11
      benchmark.go
  10. BIN
      harmony-benchmark
  11. 4
      p2p/peer.go

@ -17,6 +17,6 @@ hooks:
timeout: 300
runas: root
ApplicationStop:
- location: aws-scripts/say_hello.sh
- location: aws-scripts/say_bye.sh
timeout: 10
runas: root

@ -0,0 +1,59 @@
package attack
import (
"harmony-benchmark/log"
"math/rand"
"os"
"time"
)
const (
DroppingTickDuration = 2 * time.Second
AttackEnabled = false
HitRate = 10
DelayResponseDuration = 10 * time.Second
)
// AttackModel contains different models of attacking.
type Attack struct {
log log.Logger // Log utility
}
func New(log log.Logger) *Attack {
attackModel := Attack{}
// Logger
attackModel.log = log
return &attackModel
}
// Run runs all attack models in goroutine mode.
func (attack *Attack) Run() {
if !AttackEnabled {
return
}
// Adding attack model here.
go func() {
attack.NodeKilledByItSelf()
}()
}
// NodeKilledByItSelf runs killing itself attack
func (attack *Attack) NodeKilledByItSelf() {
tick := time.Tick(DroppingTickDuration)
for {
<-tick
if rand.Intn(HitRate) == 0 {
attack.log.Debug("***********************Killing myself***********************", "PID: ", os.Getpid())
os.Exit(1)
}
}
}
func DelayResponse() {
if !AttackEnabled {
return
}
if rand.Intn(HitRate) == 0 {
time.Sleep(DelayResponseDuration)
}
}

@ -1,3 +1,4 @@
#!/bin/bash -x
echo "Run Instances" >> tmplog
cd /home/ec2-user/projects/src/harmony-benchmark
./deploy_one_instance.sh global_nodes.txt

@ -0,0 +1 @@
echo "Bye" >> tmplog

@ -1 +1 @@
echo "Hi, I am in aws-scripts and its seems to have worked."
echo "Hello" >> tmplog

@ -1,4 +1,5 @@
#!/bin/bash -x
echo "Setup Golang" >> tmplog
sudo yum update -y
sudo yum install -y golang

@ -0,0 +1,16 @@
aws ec2 request-spot-instances \
--instance-count 1 \
--block-duration-minutes 60 \
--launch-specification "{ \
\"ImageId\": \"ami-f2d3638a\", \
\"InstanceType\": \"m3.medium\", \
\"SecurityGroups\": [ \
\"richard-spot-instance SSH\" \
], \
\"KeyName\": \"richard-spot-instance\", \
\"IamInstanceProfile\": { \
\"Name\": \"RichardCodeDeployInstanceRole\" \
}, \
\"UserData\": \"`base64 -w 0 userdata.sh`\" \
}" \
--dry-run # uncomment this line to send a real request.

@ -0,0 +1,7 @@
#!/bin/bash
yum -y update
yum install -y ruby
cd /home/ec2-user
curl -O https://aws-codedeploy-us-west-2.s3.amazonaws.com/latest/install
chmod +x ./install
./install auto

@ -4,12 +4,15 @@ import (
"bufio"
"flag"
"fmt"
"harmony-benchmark/attack"
"harmony-benchmark/consensus"
"harmony-benchmark/log"
"harmony-benchmark/node"
"harmony-benchmark/p2p"
"math/rand"
"os"
"strings"
"time"
)
func getShardId(myIp, myPort string, config *[][]string) string {
@ -78,6 +81,9 @@ func main() {
logFolder := flag.String("log_folder", "latest", "the folder collecting the logs of this execution")
flag.Parse()
// Set up randomization seed.
rand.Seed(int64(time.Now().Nanosecond()))
config := readConfigFile(*configFile)
shardId := getShardId(*ip, *port, &config)
peers := getPeers(*ip, *port, shardId, &config)
@ -95,6 +101,7 @@ func main() {
consensus := consensus.NewConsensus(*ip, *port, shardId, peers, leader)
node := node.NewNode(&consensus)
attack := attack.New(consensus.Log)
clientPeer := getClientPeer(&config)
// If there is a client configured in the node list.
@ -120,5 +127,9 @@ func main() {
}()
}
// TODO(minhdoan): Enable it later after done attacking.
// Run attack.
attack.Run()
node.StartServer(*port)
}

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