From 97d0c20b24b7175311e7172cf6f98251877c810c Mon Sep 17 00:00:00 2001 From: Alok Kothari Date: Tue, 14 Aug 2018 17:39:56 -0700 Subject: [PATCH] wait node --- waitnode/waitNode.go | 45 +++++++++++++++++++-------------------- waitnode/waitNode_test.go | 8 +++---- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/waitnode/waitNode.go b/waitnode/waitNode.go index 18b80370d..240323141 100644 --- a/waitnode/waitNode.go +++ b/waitnode/waitNode.go @@ -1,8 +1,7 @@ package waitnode import ( - "net" - "os" + "fmt" "github.com/simple-rules/harmony-benchmark/log" ) @@ -17,34 +16,34 @@ type WaitNode struct { Address address Worker string ID int - Log log.Logger + log log.Logger } -func (node *WaitNode) doPoW(pow string) { - return "pow" +func (node *WaitNode) doPoW() { + node.log.Debug("Node with ID %d and IP %s is doing POW", node.ID, node.Address.IP) } // StartServer a server and process the request by a handler. func (node *WaitNode) StartServer(add address) { - node.log.Debug("Starting waitnode on server", "node", node.Id, "port", add.IP) - node.listenOnPort(add.Port) + node.log.Debug("Starting waitnode on server %d", "node", node.ID, "port", add.IP) + node.connectIdentityChain(add.Port) } -func (node *WaitNode) listenOnPort(port string) { - listen, err := net.Listen("tcp4", ":"+port) - defer listen.Close() - if err != nil { - node.log.Crit("Socket listen port failed", "port", port, "err", err) - os.Exit(1) - } - for { - conn, err := listen.Accept() - if err != nil { - node.log.Crit("Error listening on port. Exiting.", "port", port) - continue - } - go node.NodeHandler(conn) - } +func (node *WaitNode) connectIdentityChain(port string) { + fmt.Println("Connecting to identity chain") + // listen, err := net.Listen("tcp4", ":"+port) + // defer listen.Close() + // if err != nil { + // node.log.Crit("Socket listen port failed", "port", port, "err", err) + // os.Exit(1) + // } + // for { + // conn, err := listen.Accept() + // if err != nil { + // node.log.Crit("Error listening on port. Exiting.", "port", port) + // continue + // } + // } } // New Create a new Node @@ -53,6 +52,6 @@ func New(address *address, id int) *WaitNode { node.Address = *address node.ID = id node.Worker = "pow" - node.Log = log.new() + node.log = log.New() return &node } diff --git a/waitnode/waitNode_test.go b/waitnode/waitNode_test.go index 0bc7c66b6..bcedb06de 100644 --- a/waitnode/waitNode_test.go +++ b/waitnode/waitNode_test.go @@ -7,11 +7,11 @@ import ( ) func TestNewNode(test *testing.T) { - Address := address{IP: "1", Port: "2"} + addressNode := address{IP: "1", Port: "2"} Worker := "pow" ID := 1 - Log := log.new() - node := New(address, ID) + Log := log.New() + node := New(addressNode, ID) if node.Address == nil { test.Error("Address is not initialized for the node") } @@ -20,7 +20,7 @@ func TestNewNode(test *testing.T) { test.Error("ID is not initialized for the node") } - if node.Wroker == nil { + if node.Worker == nil { test.Error("Worker is not initialized for the node") } }