From fb7db3d10273cce1af228e87fae62a14d48630a6 Mon Sep 17 00:00:00 2001 From: Alok Kothari Date: Tue, 14 Aug 2018 13:59:10 -0700 Subject: [PATCH] commiting changes before change directory --- blockchain/identity.go | 1 + waitnode/waitNode.go | 58 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 blockchain/identity.go create mode 100644 waitnode/waitNode.go diff --git a/blockchain/identity.go b/blockchain/identity.go new file mode 100644 index 000000000..bcf74679d --- /dev/null +++ b/blockchain/identity.go @@ -0,0 +1 @@ +package blockchain diff --git a/waitnode/waitNode.go b/waitnode/waitNode.go new file mode 100644 index 000000000..653c8ca6f --- /dev/null +++ b/waitnode/waitNode.go @@ -0,0 +1,58 @@ +package waitnode + +import ( + "net" + "os" + "github.com/simple-rules/harmony-benchmark/log" +) + +type address struct { + IP string + Port string +} + +//WaitNode is for nodes waiting to join consensus +type WaitNode struct { + Address address + Worker string + ID int + Log log.new() +} + +func (node *WaitNode) doPoW(pow string) { + return "pow" +} + +// 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) +} + +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) + } +} + +// New Create a new Node +func New(address *address) *WaitNode { + node := WaitNode{} + + // Consensus and associated channel to communicate blocks + node.Address = *address + node.ID = 1 + node.Worker = "pow" + return &node +}