fix kill_node.sh script and improve logic of peer.go

pull/18/head
Minh Doan 6 years ago
parent 46de346ee0
commit bffd16571e
  1. 2
      kill_node.sh
  2. 11
      p2p/peer.go

@ -1,4 +1,4 @@
for pid in `/bin/ps -fu $USER| grep "slave.go\|slave -port\|leader\|benchmark\|txgen" | grep -v "grep" | awk '{print $2}'`;
for pid in `/bin/ps -fu $USER| grep "benchmark\|txgen" | grep -v "grep" | awk '{print $2}'`;
do
echo 'Killed process: '$pid
kill -9 $pid

@ -6,6 +6,7 @@ import (
"log"
"net"
"strings"
"sync"
)
// Peer is the object for a p2p peer (node)
@ -28,10 +29,16 @@ func BroadcastMessage(peers []Peer, msg []byte) {
// Construct broadcast p2p message
content := ConstructP2pMessage(byte(17), msg)
// TODO(rj): Can optimize by calling goroutine.
var wg sync.WaitGroup
wg.Add(len(peers))
for _, peer := range peers {
send(peer.Ip, peer.Port, content)
// send(peer.Ip, peer.Port, content)
go func() {
defer wg.Done()
send(peer.Ip, peer.Port, content)
}()
}
wg.Wait()
}
// ConstructP2pMessage constructs the p2p message as [messageType, contentSize, content]

Loading…
Cancel
Save