diff --git a/client/node_client.go b/client/node_client.go index b48c1f891adcb0c2ca60557069615dabedc19b84..8c3464cf09088211428a4383d6197a33f4a349cb 100644 --- a/client/node_client.go +++ b/client/node_client.go @@ -21,8 +21,8 @@ import ( "github.com/hyperledger/burrow/crypto" "github.com/hyperledger/burrow/logging" "github.com/hyperledger/burrow/rpc" + rpcClient "github.com/hyperledger/burrow/rpc/lib/client" tmClient "github.com/hyperledger/burrow/rpc/tm/client" - rpcClient "github.com/hyperledger/burrow/rpc/tm/lib/client" "github.com/hyperledger/burrow/txs" ) diff --git a/client/websocket_client.go b/client/websocket_client.go index 5d4253441abee05ed3305e8bf81965b62a38fbe2..ffc67d2c609ac3046b465f726bf4a48a0822a5fb 100644 --- a/client/websocket_client.go +++ b/client/websocket_client.go @@ -27,8 +27,8 @@ import ( "github.com/hyperledger/burrow/logging" "github.com/hyperledger/burrow/logging/structure" "github.com/hyperledger/burrow/rpc" + rpcClient "github.com/hyperledger/burrow/rpc/lib/client" "github.com/hyperledger/burrow/rpc/tm/client" - rpcClient "github.com/hyperledger/burrow/rpc/tm/lib/client" "github.com/hyperledger/burrow/txs" tmTypes "github.com/tendermint/tendermint/types" ) diff --git a/core/kernel.go b/core/kernel.go index eb60ad10283a3d74f956897bf1c644edeca1353b..c796fdea6dfab9c9e52a181ab4d838ffa1cc7605 100644 --- a/core/kernel.go +++ b/core/kernel.go @@ -115,7 +115,7 @@ func NewKernel(ctx context.Context, keyClient keys.KeyClient, privValidator tm_t launchers := []process.Launcher{ { Name: "Profiling Server", - Enabled: !rpcConfig.Profiler.Enabled, + Enabled: rpcConfig.Profiler.Enabled, Launch: func() (process.Process, error) { debugServer := &http.Server{ Addr: ":6060", @@ -178,22 +178,22 @@ func NewKernel(ctx context.Context, keyClient keys.KeyClient, privValidator tm_t Name: "RPC/tm", Enabled: rpcConfig.TM.Enabled, Launch: func() (process.Process, error) { - listener, err := tm.StartServer(service, "/websocket", rpcConfig.TM.ListenAddress, emitter, logger) + server, err := tm.StartServer(service, "/websocket", rpcConfig.TM.ListenAddress, emitter, logger) if err != nil { return nil, err } - return process.FromListeners(listener), nil + return server, nil }, }, { Name: "RPC/metrics", Enabled: rpcConfig.Metrics.Enabled, Launch: func() (process.Process, error) { - listener, err := metrics.StartServer(service, rpcConfig.Metrics.MetricsPath, rpcConfig.Metrics.ListenAddress, rpcConfig.Metrics.BlockSampleSize, logger) + server, err := metrics.StartServer(service, rpcConfig.Metrics.MetricsPath, rpcConfig.Metrics.ListenAddress, rpcConfig.Metrics.BlockSampleSize, logger) if err != nil { return nil, err } - return process.FromListeners(listener), nil + return server, nil }, }, { diff --git a/rpc/tm/lib/client/http_client.go b/rpc/lib/client/http_client.go similarity index 99% rename from rpc/tm/lib/client/http_client.go rename to rpc/lib/client/http_client.go index 46b07c48d6f6c892b0583c384ca5bf23c61454c8..58aa4f495bb64d5876ebea1579b566ea41792a9c 100644 --- a/rpc/tm/lib/client/http_client.go +++ b/rpc/lib/client/http_client.go @@ -11,7 +11,7 @@ import ( "reflect" "strings" - "github.com/hyperledger/burrow/rpc/tm/lib/types" + "github.com/hyperledger/burrow/rpc/lib/types" "github.com/pkg/errors" ) diff --git a/rpc/tm/lib/client/ws_client.go b/rpc/lib/client/ws_client.go similarity index 99% rename from rpc/tm/lib/client/ws_client.go rename to rpc/lib/client/ws_client.go index 1527d9311cd736ae85ccb137c2880e6b6c2f3a8d..e18a6cfb69108d1b7094d7178c0aaa6bdd008f6e 100644 --- a/rpc/tm/lib/client/ws_client.go +++ b/rpc/lib/client/ws_client.go @@ -10,7 +10,7 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/hyperledger/burrow/rpc/tm/lib/types" + "github.com/hyperledger/burrow/rpc/lib/types" "github.com/pkg/errors" "github.com/rcrowley/go-metrics" cmn "github.com/tendermint/tmlibs/common" diff --git a/rpc/tm/lib/lib.go b/rpc/lib/lib.go similarity index 100% rename from rpc/tm/lib/lib.go rename to rpc/lib/lib.go diff --git a/rpc/tm/lib/rpc_test.go b/rpc/lib/rpc_test.go similarity index 98% rename from rpc/tm/lib/rpc_test.go rename to rpc/lib/rpc_test.go index 0a21c0d83db84d8d504c783a4a593d65ea2f50e8..99941c88be1d16fecd584cd774427633e293a84f 100644 --- a/rpc/tm/lib/rpc_test.go +++ b/rpc/lib/rpc_test.go @@ -15,9 +15,9 @@ import ( "github.com/go-kit/kit/log/term" "github.com/hyperledger/burrow/logging/lifecycle" - "github.com/hyperledger/burrow/rpc/tm/lib/client" - "github.com/hyperledger/burrow/rpc/tm/lib/server" - "github.com/hyperledger/burrow/rpc/tm/lib/types" + "github.com/hyperledger/burrow/rpc/lib/client" + "github.com/hyperledger/burrow/rpc/lib/server" + "github.com/hyperledger/burrow/rpc/lib/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" cmn "github.com/tendermint/tmlibs/common" diff --git a/rpc/tm/lib/server/handlers.go b/rpc/lib/server/handlers.go similarity index 99% rename from rpc/tm/lib/server/handlers.go rename to rpc/lib/server/handlers.go index 8f9e103ed6820ac1a419dad80484d5c98670deb2..31892c0fcb44ea49622b27ac112593a1afae9571 100644 --- a/rpc/tm/lib/server/handlers.go +++ b/rpc/lib/server/handlers.go @@ -18,7 +18,7 @@ import ( "github.com/hyperledger/burrow/consensus/tendermint" "github.com/hyperledger/burrow/logging" "github.com/hyperledger/burrow/logging/structure" - "github.com/hyperledger/burrow/rpc/tm/lib/types" + "github.com/hyperledger/burrow/rpc/lib/types" "github.com/pkg/errors" cmn "github.com/tendermint/tmlibs/common" ) diff --git a/rpc/tm/lib/server/handlers_test.go b/rpc/lib/server/handlers_test.go similarity index 98% rename from rpc/tm/lib/server/handlers_test.go rename to rpc/lib/server/handlers_test.go index 44bebb0ec7638352e2ad6d91b62e2fe0a5b47420..be66d56ceb08b7d7a9cf15f1dd89673b44fbe792 100644 --- a/rpc/tm/lib/server/handlers_test.go +++ b/rpc/lib/server/handlers_test.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/hyperledger/burrow/logging" - "github.com/hyperledger/burrow/rpc/tm/lib/types" + "github.com/hyperledger/burrow/rpc/lib/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) diff --git a/rpc/tm/lib/server/http_params.go b/rpc/lib/server/http_params.go similarity index 100% rename from rpc/tm/lib/server/http_params.go rename to rpc/lib/server/http_params.go diff --git a/rpc/tm/lib/server/http_server.go b/rpc/lib/server/http_server.go similarity index 92% rename from rpc/tm/lib/server/http_server.go rename to rpc/lib/server/http_server.go index dfb350f9c553a83fb31f79437835bdfc7ab21002..e0734304feadf7c8f7f0f741642a8481c786d7d1 100644 --- a/rpc/tm/lib/server/http_server.go +++ b/rpc/lib/server/http_server.go @@ -13,11 +13,11 @@ import ( "github.com/hyperledger/burrow/logging" "github.com/hyperledger/burrow/logging/structure" - "github.com/hyperledger/burrow/rpc/tm/lib/types" + "github.com/hyperledger/burrow/rpc/lib/types" "github.com/pkg/errors" ) -func StartHTTPServer(listenAddr string, handler http.Handler, logger *logging.Logger) (listener net.Listener, err error) { +func StartHTTPServer(listenAddr string, handler http.Handler, logger *logging.Logger) (*http.Server, error) { var proto, addr string parts := strings.SplitN(listenAddr, "://", 2) if len(parts) != 2 { @@ -26,19 +26,18 @@ func StartHTTPServer(listenAddr string, handler http.Handler, logger *logging.Lo proto, addr = parts[0], parts[1] logger.InfoMsg("Starting RPC HTTP server", "listen_address", listenAddr) - listener, err = net.Listen(proto, addr) + listener, err := net.Listen(proto, addr) if err != nil { return nil, errors.Errorf("Failed to listen on %v: %v", listenAddr, err) } + server := &http.Server{Handler: RecoverAndLogHandler(handler, logger)} + go func() { - err := http.Serve( - listener, - RecoverAndLogHandler(handler, logger), - ) + err := server.Serve(listener) logger.TraceMsg("RPC HTTP server stopped", structure.ErrorKey, err) }() - return listener, nil + return server, nil } func WriteRPCResponseHTTP(w http.ResponseWriter, res types.RPCResponse) { diff --git a/rpc/tm/lib/server/parse_test.go b/rpc/lib/server/parse_test.go similarity index 100% rename from rpc/tm/lib/server/parse_test.go rename to rpc/lib/server/parse_test.go diff --git a/rpc/tm/lib/types/types.go b/rpc/lib/types/types.go similarity index 100% rename from rpc/tm/lib/types/types.go rename to rpc/lib/types/types.go diff --git a/rpc/tm/lib/types/types_test.go b/rpc/lib/types/types_test.go similarity index 100% rename from rpc/tm/lib/types/types_test.go rename to rpc/lib/types/types_test.go diff --git a/rpc/metrics/server.go b/rpc/metrics/server.go index d25160c19405836718c0b9ef3ab437cb0424a846..5eab0754c58a243ebb9c6c1bda12515c3ebcc71f 100644 --- a/rpc/metrics/server.go +++ b/rpc/metrics/server.go @@ -14,7 +14,6 @@ package metrics import ( - "net" "net/http" "github.com/prometheus/client_golang/prometheus" @@ -22,7 +21,7 @@ import ( "github.com/hyperledger/burrow/logging" "github.com/hyperledger/burrow/logging/structure" "github.com/hyperledger/burrow/rpc" - "github.com/hyperledger/burrow/rpc/tm/lib/server" + "github.com/hyperledger/burrow/rpc/lib/server" ) // Exporter is used to store Metrics data and embeds the config struct. @@ -32,14 +31,14 @@ type Exporter struct { burrowMetrics map[string]*prometheus.Desc service *rpc.Service logger *logging.Logger - datum *Data + datum *Datum chainID string validatorMoniker string blockSampleSize uint64 } // Datum is used to store data from all the relevant endpoints -type Data struct { +type Datum struct { LatestBlockHeight float64 UnconfirmedTxs float64 TotalPeers float64 @@ -53,13 +52,13 @@ type Data struct { } func StartServer(service *rpc.Service, pattern, listenAddress string, blockSampleSize uint64, - logger *logging.Logger) (net.Listener, error) { + logger *logging.Logger) (*http.Server, error) { // instantiate metrics and variables we do not expect to change during runtime chainStatus, _ := service.Status() exporter := Exporter{ burrowMetrics: AddMetrics(), - datum: &Data{}, + datum: &Datum{}, logger: logger.With(structure.ComponentKey, "Metrics_Exporter"), service: service, chainID: chainStatus.NodeInfo.Network, @@ -74,11 +73,11 @@ func StartServer(service *rpc.Service, pattern, listenAddress string, blockSampl mux := http.NewServeMux() mux.Handle(pattern, prometheus.Handler()) - listener, err := server.StartHTTPServer(listenAddress, mux, logger) + srv, err := server.StartHTTPServer(listenAddress, mux, logger) if err != nil { return nil, err } - return listener, nil + return srv, nil } // AddMetrics - Add's all of the metrics to a map of strings, returns the map. diff --git a/rpc/tm/client/websocket_client.go b/rpc/tm/client/websocket_client.go index 96ba127f79c409da04cbf1b9f8062b9f46f8bdf7..d07f05f1d2dbfd586f628769313c10d220fffb2d 100644 --- a/rpc/tm/client/websocket_client.go +++ b/rpc/tm/client/websocket_client.go @@ -17,8 +17,8 @@ package client import ( "context" + "github.com/hyperledger/burrow/rpc/lib/types" "github.com/hyperledger/burrow/rpc/tm" - "github.com/hyperledger/burrow/rpc/tm/lib/types" ) type WebsocketClient interface { diff --git a/rpc/tm/integration/shared.go b/rpc/tm/integration/shared.go index d01322d005a5fbcf400ae64cc7326b997eb98d62..8b33acc3be0f3a0add0f38de9c0ffcdc1a8a898c 100644 --- a/rpc/tm/integration/shared.go +++ b/rpc/tm/integration/shared.go @@ -28,8 +28,8 @@ import ( "github.com/hyperledger/burrow/crypto" "github.com/hyperledger/burrow/execution/names" "github.com/hyperledger/burrow/rpc" + rpcClient "github.com/hyperledger/burrow/rpc/lib/client" tmClient "github.com/hyperledger/burrow/rpc/tm/client" - rpcClient "github.com/hyperledger/burrow/rpc/tm/lib/client" "github.com/hyperledger/burrow/txs" "github.com/hyperledger/burrow/txs/payload" "github.com/stretchr/testify/require" diff --git a/rpc/tm/integration/websocket_helpers.go b/rpc/tm/integration/websocket_helpers.go index 9355829e4f2be8bf816040aaec8126d7cc7b7782..785c9fd3afb2126eaf29741d09b2349e0c1bf9cc 100644 --- a/rpc/tm/integration/websocket_helpers.go +++ b/rpc/tm/integration/websocket_helpers.go @@ -28,9 +28,9 @@ import ( "github.com/hyperledger/burrow/crypto" "github.com/hyperledger/burrow/execution/events" "github.com/hyperledger/burrow/rpc" + rpcClient "github.com/hyperledger/burrow/rpc/lib/client" + rpcTypes "github.com/hyperledger/burrow/rpc/lib/types" tmClient "github.com/hyperledger/burrow/rpc/tm/client" - rpcClient "github.com/hyperledger/burrow/rpc/tm/lib/client" - rpcTypes "github.com/hyperledger/burrow/rpc/tm/lib/types" "github.com/hyperledger/burrow/txs" "github.com/hyperledger/burrow/txs/payload" "github.com/stretchr/testify/require" diff --git a/rpc/tm/methods.go b/rpc/tm/methods.go index 47883f6d70e7e595e9cbf385598daead4de0a417..25be7c08cfecd5006a83566f359d311ea6b02d02 100644 --- a/rpc/tm/methods.go +++ b/rpc/tm/methods.go @@ -11,8 +11,8 @@ import ( "github.com/hyperledger/burrow/execution/names" "github.com/hyperledger/burrow/logging" "github.com/hyperledger/burrow/rpc" - "github.com/hyperledger/burrow/rpc/tm/lib/server" - "github.com/hyperledger/burrow/rpc/tm/lib/types" + "github.com/hyperledger/burrow/rpc/lib/server" + "github.com/hyperledger/burrow/rpc/lib/types" "github.com/hyperledger/burrow/txs" ) diff --git a/rpc/tm/server.go b/rpc/tm/server.go index db6cd332ddf2039c9f9f69027816495ec370b84d..2baf381b65d86a367baa7ff50a5a21c2215a5c12 100644 --- a/rpc/tm/server.go +++ b/rpc/tm/server.go @@ -15,7 +15,6 @@ package tm import ( - "net" "net/http" "github.com/hyperledger/burrow/consensus/tendermint" @@ -23,11 +22,11 @@ import ( "github.com/hyperledger/burrow/logging" "github.com/hyperledger/burrow/logging/structure" "github.com/hyperledger/burrow/rpc" - "github.com/hyperledger/burrow/rpc/tm/lib/server" + "github.com/hyperledger/burrow/rpc/lib/server" ) func StartServer(service *rpc.Service, pattern, listenAddress string, emitter event.Emitter, - logger *logging.Logger) (net.Listener, error) { + logger *logging.Logger) (*http.Server, error) { logger = logger.With(structure.ComponentKey, "RPC_TM") routes := GetRoutes(service, logger) @@ -35,9 +34,9 @@ func StartServer(service *rpc.Service, pattern, listenAddress string, emitter ev wm := server.NewWebsocketManager(routes, logger, server.EventSubscriber(tendermint.SubscribableAsEventBus(emitter))) mux.HandleFunc(pattern, wm.WebsocketHandler) server.RegisterRPCFuncs(mux, routes, logger) - listener, err := server.StartHTTPServer(listenAddress, mux, logger) + server, err := server.StartHTTPServer(listenAddress, mux, logger) if err != nil { return nil, err } - return listener, nil + return server, nil }