From bffd16571ee5f805e500b60e05b7592d1b61646c Mon Sep 17 00:00:00 2001 From: Minh Doan Date: Sat, 30 Jun 2018 06:33:12 -0700 Subject: [PATCH] fix kill_node.sh script and improve logic of peer.go --- kill_node.sh | 2 +- p2p/peer.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/kill_node.sh b/kill_node.sh index 9f8994133..f24623082 100755 --- a/kill_node.sh +++ b/kill_node.sh @@ -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 diff --git a/p2p/peer.go b/p2p/peer.go index 0b618a948..4cafdec17 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -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]