From 69de9e9b270cb7d44800cc3884ee904cbb1c86e5 Mon Sep 17 00:00:00 2001 From: Alok Kothari Date: Thu, 16 Aug 2018 18:25:23 -0700 Subject: [PATCH] identity chain --- identitychain/identity.go | 47 ---------------------------------- identitychain/identitychain.go | 26 +++++++++++++++++++ 2 files changed, 26 insertions(+), 47 deletions(-) delete mode 100644 identitychain/identity.go diff --git a/identitychain/identity.go b/identitychain/identity.go deleted file mode 100644 index 88da487a3..000000000 --- a/identitychain/identity.go +++ /dev/null @@ -1,47 +0,0 @@ -package identitychain - -// IdentityChain (Blockchain) keeps Identities per epoch -type IdentityChain struct { - Identities []*IdentityBlock - PendingIdentities []*Node - Logger log -} - -// func main() { -// err := godotenv.Load() -// if err != nil { -// log.Fatal(err) -// } - -// go func() { -// t := time.Now() -// genesisBlock := Block{} -// genesisBlock = Block{0, t.String(), 0, calculateHash(genesisBlock), "", difficulty, ""} - -// mutex.Lock() -// Blockchain = append(Blockchain, genesisBlock) -// mutex.Unlock() -// }() -// log.Fatal(run()) - -// } - -// // web server -// func run() error { -// mux := makeMuxRouter() -// httpPort := os.Getenv("PORT") -// log.Println("HTTP Server Listening on port :", httpPort) -// s := &http.Server{ -// Addr: ":" + httpPort, -// Handler: mux, -// ReadTimeout: 10 * time.Second, -// WriteTimeout: 10 * time.Second, -// MaxHeaderBytes: 1 << 20, -// } - -// if err := s.ListenAndServe(); err != nil { -// return err -// } - -// return nil -// } diff --git a/identitychain/identitychain.go b/identitychain/identitychain.go index 4797f641c..38a7f7253 100644 --- a/identitychain/identitychain.go +++ b/identitychain/identitychain.go @@ -1,8 +1,12 @@ package identitychain import ( + "fmt" + "net" + "os" "sync" + "github.com/simple-rules/harmony-benchmark/log" "github.com/simple-rules/harmony-benchmark/waitnode" ) @@ -12,6 +16,7 @@ var mutex sync.Mutex type IdentityChain struct { Identities []*IdentityBlock PendingIdentities []*waitnode.WaitNode + log log.Logger } func main() { @@ -25,3 +30,24 @@ func main() { }() } + +//IdentityChainHandler handles transactions +func (IDC *IdentityChain) IdentityChainHandler(conn net.Conn) { + fmt.Println("yay") +} +func (IDC *IdentityChain) listenOnPort(port string) { + listen, err := net.Listen("tcp4", ":"+port) + defer listen.Close() + if err != nil { + IDC.log.Crit("Socket listen port failed", "port", port, "err", err) + os.Exit(1) + } + for { + conn, err := listen.Accept() + if err != nil { + IDC.log.Crit("Error listening on port. Exiting.", "port", port) + continue + } + go IDC.IdentityChainHandler(conn) + } +}