libs/common: refactor libs common 3 (#4232)

* libs/common: refactor libs common 3

- move nil.go into types folder and make private
- move service & baseservice out of common into service pkg

ref #4147

Signed-off-by: Marko Baricevic <marbar3778@yahoo.com>

* add changelog entry
This commit is contained in:
Marko
2019-12-11 09:31:25 +01:00
committed by GitHub
parent efc27ab0b9
commit 27b00cf8d1
50 changed files with 163 additions and 150 deletions
+5 -4
View File
@@ -14,6 +14,7 @@ import (
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log"
tmpubsub "github.com/tendermint/tendermint/libs/pubsub"
"github.com/tendermint/tendermint/libs/service"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
rpcclient "github.com/tendermint/tendermint/rpc/lib/client"
"github.com/tendermint/tendermint/types"
@@ -379,7 +380,7 @@ func (c *baseRPCClient) BroadcastEvidence(ev types.Evidence) (*ctypes.ResultBroa
// WSEvents
type WSEvents struct {
cmn.BaseService
service.BaseService
cdc *amino.Codec
remote string
endpoint string
@@ -398,11 +399,11 @@ func newWSEvents(cdc *amino.Codec, remote, endpoint string) *WSEvents {
subscriptions: make(map[string]chan ctypes.ResultEvent),
}
wsEvents.BaseService = *cmn.NewBaseService(nil, "WSEvents", wsEvents)
wsEvents.BaseService = *service.NewBaseService(nil, "WSEvents", wsEvents)
return wsEvents
}
// OnStart implements cmn.Service by starting WSClient and event loop.
// OnStart implements service.Service by starting WSClient and event loop.
func (w *WSEvents) OnStart() error {
w.ws = rpcclient.NewWSClient(w.remote, w.endpoint, rpcclient.OnReconnect(func() {
// resubscribe immediately
@@ -420,7 +421,7 @@ func (w *WSEvents) OnStart() error {
return nil
}
// OnStop implements cmn.Service by stopping WSClient.
// OnStop implements service.Service by stopping WSClient.
func (w *WSEvents) OnStop() {
_ = w.ws.Stop()
}
+2 -1
View File
@@ -24,6 +24,7 @@ import (
"context"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/service"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/types"
)
@@ -31,7 +32,7 @@ import (
// Client wraps most important rpc calls a client would make if you want to
// listen for events, test if it also implements events.EventSwitch.
type Client interface {
cmn.Service
service.Service
ABCIClient
EventsClient
HistoryClient
+2 -1
View File
@@ -18,6 +18,7 @@ import (
"reflect"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/service"
"github.com/tendermint/tendermint/rpc/client"
"github.com/tendermint/tendermint/rpc/core"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
@@ -38,7 +39,7 @@ type Client struct {
client.EventsClient
client.EvidenceClient
client.MempoolClient
cmn.Service
service.Service
}
var _ client.Client = Client{}
+5 -5
View File
@@ -14,8 +14,8 @@ import (
metrics "github.com/rcrowley/go-metrics"
amino "github.com/tendermint/go-amino"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/rand"
"github.com/tendermint/tendermint/libs/service"
types "github.com/tendermint/tendermint/rpc/lib/types"
)
@@ -74,7 +74,7 @@ type WSClient struct { // nolint: maligned
// Send pings to server with this period. Must be less than readWait. If 0, no pings will be sent.
pingPeriod time.Duration
cmn.BaseService
service.BaseService
// Time between sending a ping and receiving a pong. See
// https://godoc.org/github.com/rcrowley/go-metrics#Timer.
@@ -110,7 +110,7 @@ func NewWSClient(remoteAddr, endpoint string, options ...func(*WSClient)) *WSCli
// sentIDs: make(map[types.JSONRPCIntID]bool),
}
c.BaseService = *cmn.NewBaseService(nil, "WSClient", c)
c.BaseService = *service.NewBaseService(nil, "WSClient", c)
for _, option := range options {
option(c)
}
@@ -162,7 +162,7 @@ func (c *WSClient) String() string {
return fmt.Sprintf("WSClient{%s (%s)}", c.Address, c.Endpoint)
}
// OnStart implements cmn.Service by dialing a server and creating read and
// OnStart implements service.Service by dialing a server and creating read and
// write routines.
func (c *WSClient) OnStart() error {
err := c.dial()
@@ -186,7 +186,7 @@ func (c *WSClient) OnStart() error {
return nil
}
// Stop overrides cmn.Service#Stop. There is no other way to wait until Quit
// Stop overrides service.Service#Stop. There is no other way to wait until Quit
// channel is closed.
func (c *WSClient) Stop() error {
if err := c.BaseService.Stop(); err != nil {
+5 -5
View File
@@ -14,8 +14,8 @@ import (
amino "github.com/tendermint/go-amino"
cmn "github.com/tendermint/tendermint/libs/common"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/libs/service"
types "github.com/tendermint/tendermint/rpc/lib/types"
)
@@ -112,7 +112,7 @@ func (wm *WebsocketManager) WebsocketHandler(w http.ResponseWriter, r *http.Requ
//
// In case of an error, the connection is stopped.
type wsConnection struct {
cmn.BaseService
service.BaseService
remoteAddr string
baseConn *websocket.Conn
@@ -175,7 +175,7 @@ func NewWSConnection(
option(wsc)
}
wsc.baseConn.SetReadLimit(wsc.readLimit)
wsc.BaseService = *cmn.NewBaseService(nil, "wsConnection", wsc)
wsc.BaseService = *service.NewBaseService(nil, "wsConnection", wsc)
return wsc
}
@@ -227,7 +227,7 @@ func ReadLimit(readLimit int64) func(*wsConnection) {
}
}
// OnStart implements cmn.Service by starting the read and write routines. It
// OnStart implements service.Service by starting the read and write routines. It
// blocks until there's some error.
func (wsc *wsConnection) OnStart() error {
wsc.writeChan = make(chan types.RPCResponse, wsc.writeChanCapacity)
@@ -240,7 +240,7 @@ func (wsc *wsConnection) OnStart() error {
return nil
}
// OnStop implements cmn.Service by unsubscribing remoteAddr from all
// OnStop implements service.Service by unsubscribing remoteAddr from all
// subscriptions.
func (wsc *wsConnection) OnStop() {
if wsc.onDisconnect != nil {