From ede4a5026f13e5b246a5da1a14d87c5f9a31b71d Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Fri, 29 Jun 2018 16:27:39 -0700 Subject: [PATCH 1/3] first commit for loghost --- aws-code/loghost/main.go | 53 ++++++++++++++++++++++++++++++++++++++++ benchmark_main.go | 3 ++- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 aws-code/loghost/main.go diff --git a/aws-code/loghost/main.go b/aws-code/loghost/main.go new file mode 100644 index 0000000000..2f6a4f46c8 --- /dev/null +++ b/aws-code/loghost/main.go @@ -0,0 +1,53 @@ +package main + +import ( + "bufio" + "fmt" + "net" + "os" +) + +const ( + CONN_PORT = "3000" + CONN_TYPE = "tcp" +) + +func main() { + // Listen for incoming connections. + l, err := net.Listen(CONN_TYPE, ":"+CONN_PORT) + if err != nil { + fmt.Println("Error listening:", err.Error()) + os.Exit(1) + } + // Close the listener when the application closes. + defer l.Close() + fmt.Println("Listening on " + ":" + CONN_PORT) + for { + // Listen for an incoming connection. + conn, err := l.Accept() + if err != nil { + fmt.Println("Error accepting: ", err.Error()) + os.Exit(1) + } + // Handle connections in a new goroutine. + go handleRequest(conn) + } +} + +// Handles incoming requests. +func handleRequest(conn net.Conn) { + // // Make a buffer to hold incoming data. + // buf := make([]byte, 1024) + // // Read the incoming connection into the buffer. + // reqLen, err := conn.Read(buf) + status, err := bufio.NewReader(conn).ReadString('\n') + if err != nil { + fmt.Println("Error reading:", err.Error()) + } + // fmt.Printf("Received %v: %v", reqLen, buf) + fmt.Println(status) + // // Send a response back to person contacting xus. + // conn.Write([]byte("Message received.")) + // Close the connection when you're done with it. + conn.Close() +} diff --git a/benchmark_main.go b/benchmark_main.go index eb8ff25787..9ecfdba3fb 100644 --- a/benchmark_main.go +++ b/benchmark_main.go @@ -87,7 +87,8 @@ func main() { logFileName := fmt.Sprintf("./%v/%v.log", *logFolder, *port) h := log.MultiHandler( log.Must.FileHandler(logFileName, log.LogfmtFormat()), - log.StdoutHandler) + log.StdoutHandler, + log.Must.NetHandler("tcp", ":3000", log.JSONFormat())) // In cases where you just want a stdout logger, use the following one instead. // h := log.CallerFileHandler(log.StdoutHandler) log.Root().SetHandler(h) From 17724503c6d40e731cdb66770367b873e4d6710d Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Fri, 29 Jun 2018 18:26:26 -0700 Subject: [PATCH 2/3] update ordering; skip network log temporarily --- benchmark.go | 9 ++++----- client/txgen/main.go | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/benchmark.go b/benchmark.go index fed58d17e0..041205b2fe 100644 --- a/benchmark.go +++ b/benchmark.go @@ -86,11 +86,10 @@ func main() { // Setup a logger to stdout and log file. logFileName := fmt.Sprintf("./%v/%v.log", *logFolder, *port) h := log.MultiHandler( - log.Must.FileHandler(logFileName, log.LogfmtFormat()), - log.StdoutHandler, - log.Must.NetHandler("tcp", ":3000", log.JSONFormat())) - // In cases where you just want a stdout logger, use the following one instead. - // h := log.CallerFileHandler(log.StdoutHandler) + log.StdoutHandler, // Log to terminal + log.Must.FileHandler(logFileName, log.LogfmtFormat()), // Log to file + // log.Must.NetHandler("tcp", ":3000", log.JSONFormat()) // Log to remote + ) log.Root().SetHandler(h) consensus := consensus.NewConsensus(*ip, *port, shardId, peers, leader) diff --git a/client/txgen/main.go b/client/txgen/main.go index 4fbf605c7d..a60973af54 100644 --- a/client/txgen/main.go +++ b/client/txgen/main.go @@ -257,10 +257,10 @@ func main() { // Setup a logger to stdout and log file. logFileName := fmt.Sprintf("./%v/tx-generator.log", *logFolder) h := log.MultiHandler( - log.Must.FileHandler(logFileName, log.LogfmtFormat()), - log.StdoutHandler) - // In cases where you just want a stdout logger, use the following one instead. - // h := log.CallerFileHandler(log.StdoutHandler) + log.StdoutHandler, // Log to terminal + log.Must.FileHandler(logFileName, log.LogfmtFormat()), // Log to file + // log.Must.NetHandler("tcp", ":3000", log.JSONFormat()) // Log to remote + ) log.Root().SetHandler(h) // Nodes containing utxopools to mirror the shards' data in the network From 27640fa97d973f43acc10135529b80d4db3fd195 Mon Sep 17 00:00:00 2001 From: Richard Liu Date: Fri, 29 Jun 2018 18:36:42 -0700 Subject: [PATCH 3/3] workaround weird gofmt issue --- benchmark.go | 2 +- client/txgen/main.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmark.go b/benchmark.go index 041205b2fe..9a5667d2ae 100644 --- a/benchmark.go +++ b/benchmark.go @@ -86,7 +86,7 @@ func main() { // Setup a logger to stdout and log file. logFileName := fmt.Sprintf("./%v/%v.log", *logFolder, *port) h := log.MultiHandler( - log.StdoutHandler, // Log to terminal + log.StdoutHandler, log.Must.FileHandler(logFileName, log.LogfmtFormat()), // Log to file // log.Must.NetHandler("tcp", ":3000", log.JSONFormat()) // Log to remote ) diff --git a/client/txgen/main.go b/client/txgen/main.go index a60973af54..ba6f0018a8 100644 --- a/client/txgen/main.go +++ b/client/txgen/main.go @@ -257,7 +257,7 @@ func main() { // Setup a logger to stdout and log file. logFileName := fmt.Sprintf("./%v/tx-generator.log", *logFolder) h := log.MultiHandler( - log.StdoutHandler, // Log to terminal + log.StdoutHandler, log.Must.FileHandler(logFileName, log.LogfmtFormat()), // Log to file // log.Must.NetHandler("tcp", ":3000", log.JSONFormat()) // Log to remote )