Fix unexported returns (#4450)

This commit is contained in:
Erik Grinaker
2020-02-21 19:21:39 +01:00
committed by GitHub
parent c63fd32fc2
commit fe11219795
16 changed files with 69 additions and 62 deletions

View File

@@ -31,7 +31,7 @@ type grpcClient struct {
resCb func(*types.Request, *types.Response) // listens to all callbacks
}
func NewGRPCClient(addr string, mustConnect bool) *grpcClient {
func NewGRPCClient(addr string, mustConnect bool) Client {
cli := &grpcClient{
addr: addr,
mustConnect: mustConnect,

View File

@@ -21,7 +21,7 @@ type localClient struct {
Callback
}
func NewLocalClient(mtx *sync.Mutex, app types.Application) *localClient {
func NewLocalClient(mtx *sync.Mutex, app types.Application) Client {
if mtx == nil {
mtx = new(sync.Mutex)
}

View File

@@ -43,7 +43,7 @@ type socketClient struct {
}
func NewSocketClient(addr string, mustConnect bool) *socketClient {
func NewSocketClient(addr string, mustConnect bool) Client {
cli := &socketClient{
reqQueue: make(chan *ReqRes, reqQueueSize),
flushTimer: timer.NewThrottleTimer("socketClient", flushThrottleMS),

View File

@@ -16,8 +16,12 @@ import (
"github.com/tendermint/tendermint/libs/service"
)
type errorStopper interface {
StopForError(error)
}
func TestSocketClientStopForErrorDeadlock(t *testing.T) {
c := abcicli.NewSocketClient(":80", false)
c := abcicli.NewSocketClient(":80", false).(errorStopper)
err := errors.New("foo-tendermint")
// See Issue https://github.com/tendermint/abci/issues/114

View File

@@ -71,7 +71,7 @@ type validatorStub struct {
var testMinPower int64 = 10
func NewValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub {
func newValidatorStub(privValidator types.PrivValidator, valIndex int) *validatorStub {
return &validatorStub{
Index: valIndex,
PrivValidator: privValidator,
@@ -385,7 +385,7 @@ func randState(nValidators int) (*State, []*validatorStub) {
cs := newState(state, privVals[0], counter.NewApplication(true))
for i := 0; i < nValidators; i++ {
vss[i] = NewValidatorStub(privVals[i], i)
vss[i] = newValidatorStub(privVals[i], i)
}
// since cs1 starts at 1
incrementHeight(vss[1:]...)

View File

@@ -329,7 +329,7 @@ func TestSimulateValidatorsChange(t *testing.T) {
vss := make([]*validatorStub, nPeers)
for i := 0; i < nPeers; i++ {
vss[i] = NewValidatorStub(css[i].privValidator, i)
vss[i] = newValidatorStub(css[i].privValidator, i)
}
height, round := css[0].Height, css[0].Round
// start the machine

View File

@@ -78,7 +78,7 @@ type WAL interface {
// TODO: currently the wal is overwritten during replay catchup, give it a mode
// so it's either reading or appending - must read to end to start appending
// again.
type baseWAL struct {
type BaseWAL struct {
service.BaseService
group *auto.Group
@@ -89,11 +89,11 @@ type baseWAL struct {
flushInterval time.Duration
}
var _ WAL = &baseWAL{}
var _ WAL = &BaseWAL{}
// NewWAL returns a new write-ahead logger based on `baseWAL`, which implements
// WAL. It's flushed and synced to disk every 2s and once when stopped.
func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*baseWAL, error) {
func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*BaseWAL, error) {
err := tmos.EnsureDir(filepath.Dir(walFile), 0700)
if err != nil {
return nil, errors.Wrap(err, "failed to ensure WAL directory is in place")
@@ -103,7 +103,7 @@ func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*baseWAL, error)
if err != nil {
return nil, err
}
wal := &baseWAL{
wal := &BaseWAL{
group: group,
enc: NewWALEncoder(group),
flushInterval: walDefaultFlushInterval,
@@ -113,20 +113,20 @@ func NewWAL(walFile string, groupOptions ...func(*auto.Group)) (*baseWAL, error)
}
// SetFlushInterval allows us to override the periodic flush interval for the WAL.
func (wal *baseWAL) SetFlushInterval(i time.Duration) {
func (wal *BaseWAL) SetFlushInterval(i time.Duration) {
wal.flushInterval = i
}
func (wal *baseWAL) Group() *auto.Group {
func (wal *BaseWAL) Group() *auto.Group {
return wal.group
}
func (wal *baseWAL) SetLogger(l log.Logger) {
func (wal *BaseWAL) SetLogger(l log.Logger) {
wal.BaseService.Logger = l
wal.group.SetLogger(l)
}
func (wal *baseWAL) OnStart() error {
func (wal *BaseWAL) OnStart() error {
size, err := wal.group.Head.Size()
if err != nil {
return err
@@ -142,7 +142,7 @@ func (wal *baseWAL) OnStart() error {
return nil
}
func (wal *baseWAL) processFlushTicks() {
func (wal *BaseWAL) processFlushTicks() {
for {
select {
case <-wal.flushTicker.C:
@@ -157,14 +157,14 @@ func (wal *baseWAL) processFlushTicks() {
// FlushAndSync flushes and fsync's the underlying group's data to disk.
// See auto#FlushAndSync
func (wal *baseWAL) FlushAndSync() error {
func (wal *BaseWAL) FlushAndSync() error {
return wal.group.FlushAndSync()
}
// Stop the underlying autofile group.
// Use Wait() to ensure it's finished shutting down
// before cleaning up files.
func (wal *baseWAL) OnStop() {
func (wal *BaseWAL) OnStop() {
wal.flushTicker.Stop()
wal.FlushAndSync()
wal.group.Stop()
@@ -173,14 +173,14 @@ func (wal *baseWAL) OnStop() {
// Wait for the underlying autofile group to finish shutting down
// so it's safe to cleanup files.
func (wal *baseWAL) Wait() {
func (wal *BaseWAL) Wait() {
wal.group.Wait()
}
// Write is called in newStep and for each receive on the
// peerMsgQueue and the timeoutTicker.
// NOTE: does not call fsync()
func (wal *baseWAL) Write(msg WALMessage) error {
func (wal *BaseWAL) Write(msg WALMessage) error {
if wal == nil {
return nil
}
@@ -197,7 +197,7 @@ func (wal *baseWAL) Write(msg WALMessage) error {
// WriteSync is called when we receive a msg from ourselves
// so that we write to disk before sending signed messages.
// NOTE: calls fsync()
func (wal *baseWAL) WriteSync(msg WALMessage) error {
func (wal *BaseWAL) WriteSync(msg WALMessage) error {
if wal == nil {
return nil
}
@@ -227,7 +227,7 @@ type WALSearchOptions struct {
// Group reader will be nil if found equals false.
//
// CONTRACT: caller must close group reader.
func (wal *baseWAL) SearchForEndHeight(
func (wal *BaseWAL) SearchForEndHeight(
height int64,
options *WALSearchOptions) (rd io.ReadCloser, found bool, err error) {
var (

View File

@@ -16,7 +16,7 @@ type multiProvider struct {
}
// NewMultiProvider returns a new provider which wraps multiple other providers.
func NewMultiProvider(providers ...PersistentProvider) *multiProvider {
func NewMultiProvider(providers ...PersistentProvider) PersistentProvider {
return &multiProvider{
logger: log.NewNopLogger(),
providers: providers,

View File

@@ -26,7 +26,7 @@ type connSet struct {
}
// NewConnSet returns a ConnSet implementation.
func NewConnSet() *connSet {
func NewConnSet() ConnSet {
return &connSet{
conns: map[string]connSetItem{},
}

View File

@@ -102,7 +102,7 @@ type addrBook struct {
// NewAddrBook creates a new address book.
// Use Start to begin processing asynchronous address updates.
func NewAddrBook(filePath string, routabilityStrict bool) *addrBook {
func NewAddrBook(filePath string, routabilityStrict bool) AddrBook {
am := &addrBook{
rand: tmrand.NewRand(),
ourAddrs: make(map[string]struct{}),

View File

@@ -17,6 +17,8 @@ import (
"github.com/tendermint/tendermint/p2p"
)
// FIXME These tests should not rely on .(*addrBook) assertions
func TestAddrBookPickAddress(t *testing.T) {
fname := createTempFileName("addrbook_test")
defer deleteTempFile(fname)
@@ -58,11 +60,11 @@ func TestAddrBookSaveLoad(t *testing.T) {
defer deleteTempFile(fname)
// 0 addresses
book := NewAddrBook(fname, true)
book := NewAddrBook(fname, true).(*addrBook)
book.SetLogger(log.TestingLogger())
book.saveToFile(fname)
book = NewAddrBook(fname, true)
book = NewAddrBook(fname, true).(*addrBook)
book.SetLogger(log.TestingLogger())
book.loadFromFile(fname)
@@ -78,7 +80,7 @@ func TestAddrBookSaveLoad(t *testing.T) {
assert.Equal(t, 100, book.Size())
book.saveToFile(fname)
book = NewAddrBook(fname, true)
book = NewAddrBook(fname, true).(*addrBook)
book.SetLogger(log.TestingLogger())
book.loadFromFile(fname)
@@ -91,7 +93,7 @@ func TestAddrBookLookup(t *testing.T) {
randAddrs := randNetAddressPairs(t, 100)
book := NewAddrBook(fname, true)
book := NewAddrBook(fname, true).(*addrBook)
book.SetLogger(log.TestingLogger())
for _, addrSrc := range randAddrs {
addr := addrSrc.addr
@@ -575,7 +577,7 @@ func deleteTempFile(fname string) {
func createAddrBookWithMOldAndNNewAddrs(t *testing.T, nOld, nNew int) (book *addrBook, fname string) {
fname = createTempFileName("addrbook_test")
book = NewAddrBook(fname, true)
book = NewAddrBook(fname, true).(*addrBook)
book.SetLogger(log.TestingLogger())
assert.Zero(t, book.Size())

View File

@@ -74,7 +74,7 @@ func TestPEXReactorRunning(t *testing.T) {
require.Nil(t, err)
defer os.RemoveAll(dir) // nolint: errcheck
books := make([]*addrBook, N)
books := make([]AddrBook, N)
logger := log.TestingLogger()
// create switches
@@ -404,7 +404,7 @@ func TestPEXReactorSeedModeFlushStop(t *testing.T) {
require.Nil(t, err)
defer os.RemoveAll(dir) // nolint: errcheck
books := make([]*addrBook, N)
books := make([]AddrBook, N)
logger := log.TestingLogger()
// create switches
@@ -631,7 +631,7 @@ func testCreatePeerWithSeed(dir string, id int, seed *p2p.Switch) *p2p.Switch {
return testCreatePeerWithConfig(dir, id, conf)
}
func createReactor(conf *ReactorConfig) (r *Reactor, book *addrBook) {
func createReactor(conf *ReactorConfig) (r *Reactor, book AddrBook) {
// directory to store address book
dir, err := ioutil.TempDir("", "pex_reactor")
if err != nil {
@@ -645,8 +645,9 @@ func createReactor(conf *ReactorConfig) (r *Reactor, book *addrBook) {
return
}
func teardownReactor(book *addrBook) {
err := os.RemoveAll(filepath.Dir(book.FilePath()))
func teardownReactor(book AddrBook) {
// FIXME Shouldn't rely on .(*addrBook) assertion
err := os.RemoveAll(filepath.Dir(book.(*addrBook).FilePath()))
if err != nil {
panic(err)
}

View File

@@ -23,26 +23,26 @@ type timeoutError interface {
// TCP Listener
// TCPListenerOption sets an optional parameter on the tcpListener.
type TCPListenerOption func(*tcpListener)
type TCPListenerOption func(*TCPListener)
// TCPListenerTimeoutAccept sets the timeout for the listener.
// A zero time value disables the timeout.
func TCPListenerTimeoutAccept(timeout time.Duration) TCPListenerOption {
return func(tl *tcpListener) { tl.timeoutAccept = timeout }
return func(tl *TCPListener) { tl.timeoutAccept = timeout }
}
// TCPListenerTimeoutReadWrite sets the read and write timeout for connections
// from external signing processes.
func TCPListenerTimeoutReadWrite(timeout time.Duration) TCPListenerOption {
return func(tl *tcpListener) { tl.timeoutReadWrite = timeout }
return func(tl *TCPListener) { tl.timeoutReadWrite = timeout }
}
// tcpListener implements net.Listener.
var _ net.Listener = (*tcpListener)(nil)
var _ net.Listener = (*TCPListener)(nil)
// tcpListener wraps a *net.TCPListener to standardise protocol timeouts
// TCPListener wraps a *net.TCPListener to standardise protocol timeouts
// and potentially other tuning parameters. It also returns encrypted connections.
type tcpListener struct {
type TCPListener struct {
*net.TCPListener
secretConnKey ed25519.PrivKeyEd25519
@@ -53,8 +53,8 @@ type tcpListener struct {
// NewTCPListener returns a listener that accepts authenticated encrypted connections
// using the given secretConnKey and the default timeout values.
func NewTCPListener(ln net.Listener, secretConnKey ed25519.PrivKeyEd25519) *tcpListener {
return &tcpListener{
func NewTCPListener(ln net.Listener, secretConnKey ed25519.PrivKeyEd25519) *TCPListener {
return &TCPListener{
TCPListener: ln.(*net.TCPListener),
secretConnKey: secretConnKey,
timeoutAccept: time.Second * defaultTimeoutAcceptSeconds,
@@ -63,7 +63,7 @@ func NewTCPListener(ln net.Listener, secretConnKey ed25519.PrivKeyEd25519) *tcpL
}
// Accept implements net.Listener.
func (ln *tcpListener) Accept() (net.Conn, error) {
func (ln *TCPListener) Accept() (net.Conn, error) {
deadline := time.Now().Add(ln.timeoutAccept)
err := ln.SetDeadline(deadline)
if err != nil {
@@ -89,25 +89,25 @@ func (ln *tcpListener) Accept() (net.Conn, error) {
// Unix Listener
// unixListener implements net.Listener.
var _ net.Listener = (*unixListener)(nil)
var _ net.Listener = (*UnixListener)(nil)
type UnixListenerOption func(*unixListener)
type UnixListenerOption func(*UnixListener)
// UnixListenerTimeoutAccept sets the timeout for the listener.
// A zero time value disables the timeout.
func UnixListenerTimeoutAccept(timeout time.Duration) UnixListenerOption {
return func(ul *unixListener) { ul.timeoutAccept = timeout }
return func(ul *UnixListener) { ul.timeoutAccept = timeout }
}
// UnixListenerTimeoutReadWrite sets the read and write timeout for connections
// from external signing processes.
func UnixListenerTimeoutReadWrite(timeout time.Duration) UnixListenerOption {
return func(ul *unixListener) { ul.timeoutReadWrite = timeout }
return func(ul *UnixListener) { ul.timeoutReadWrite = timeout }
}
// unixListener wraps a *net.UnixListener to standardise protocol timeouts
// UnixListener wraps a *net.UnixListener to standardise protocol timeouts
// and potentially other tuning parameters. It returns unencrypted connections.
type unixListener struct {
type UnixListener struct {
*net.UnixListener
timeoutAccept time.Duration
@@ -116,8 +116,8 @@ type unixListener struct {
// NewUnixListener returns a listener that accepts unencrypted connections
// using the default timeout values.
func NewUnixListener(ln net.Listener) *unixListener {
return &unixListener{
func NewUnixListener(ln net.Listener) *UnixListener {
return &UnixListener{
UnixListener: ln.(*net.UnixListener),
timeoutAccept: time.Second * defaultTimeoutAcceptSeconds,
timeoutReadWrite: time.Second * defaultTimeoutReadWriteSeconds,
@@ -125,7 +125,7 @@ func NewUnixListener(ln net.Listener) *unixListener {
}
// Accept implements net.Listener.
func (ln *unixListener) Accept() (net.Conn, error) {
func (ln *UnixListener) Accept() (net.Conn, error) {
deadline := time.Now().Add(ln.timeoutAccept)
err := ln.SetDeadline(deadline)
if err != nil {

View File

@@ -47,7 +47,7 @@ type appConnConsensus struct {
appConn abcicli.Client
}
func NewAppConnConsensus(appConn abcicli.Client) *appConnConsensus {
func NewAppConnConsensus(appConn abcicli.Client) AppConnConsensus {
return &appConnConsensus{
appConn: appConn,
}
@@ -88,7 +88,7 @@ type appConnMempool struct {
appConn abcicli.Client
}
func NewAppConnMempool(appConn abcicli.Client) *appConnMempool {
func NewAppConnMempool(appConn abcicli.Client) AppConnMempool {
return &appConnMempool{
appConn: appConn,
}
@@ -121,7 +121,7 @@ type appConnQuery struct {
appConn abcicli.Client
}
func NewAppConnQuery(appConn abcicli.Client) *appConnQuery {
func NewAppConnQuery(appConn abcicli.Client) AppConnQuery {
return &appConnQuery{
appConn: appConn,
}

View File

@@ -30,15 +30,15 @@ func NewAppConns(clientCreator ClientCreator) AppConns {
type multiAppConn struct {
service.BaseService
mempoolConn *appConnMempool
consensusConn *appConnConsensus
queryConn *appConnQuery
mempoolConn AppConnMempool
consensusConn AppConnConsensus
queryConn AppConnQuery
clientCreator ClientCreator
}
// Make all necessary abci connections to the application
func NewMultiAppConn(clientCreator ClientCreator) *multiAppConn {
func NewMultiAppConn(clientCreator ClientCreator) AppConns {
multiAppConn := &multiAppConn{
clientCreator: clientCreator,
}

View File

@@ -92,7 +92,7 @@ func (wm *WebsocketManager) WebsocketHandler(w http.ResponseWriter, r *http.Requ
}()
// register connection
con := NewWSConnection(wsConn, wm.funcMap, wm.cdc, wm.wsConnOptions...)
con := newWSConnection(wsConn, wm.funcMap, wm.cdc, wm.wsConnOptions...)
con.SetLogger(wm.logger.With("remote", wsConn.RemoteAddr()))
wm.logger.Info("New websocket connection", "remote", con.remoteAddr)
err = con.Start() // BLOCKING
@@ -154,7 +154,7 @@ type wsConnection struct {
// description of how to configure ping period and pong wait time. NOTE: if the
// write buffer is full, pongs may be dropped, which may cause clients to
// disconnect. see https://github.com/gorilla/websocket/issues/97
func NewWSConnection(
func newWSConnection(
baseConn *websocket.Conn,
funcMap map[string]*RPCFunc,
cdc *amino.Codec,