diff --git a/client/client.go b/client/client.go index a54978fcc..c911dd876 100644 --- a/client/client.go +++ b/client/client.go @@ -43,15 +43,16 @@ type Client interface { //---------------------------------------- +// NewClient returns a new ABCI client of the specified transport type. +// It returns an error if the transport is not "socket" or "grpc" func NewClient(addr, transport string, mustConnect bool) (client Client, err error) { switch transport { case "socket": - client, err = NewSocketClient(addr, mustConnect) + client = NewSocketClient(addr, mustConnect) case "grpc": - client, err = NewGRPCClient(addr, mustConnect) + client = NewGRPCClient(addr, mustConnect) default: err = fmt.Errorf("Unknown abci transport %s", transport) - } return } diff --git a/client/grpc_client.go b/client/grpc_client.go index 25783101e..9743cdf62 100644 --- a/client/grpc_client.go +++ b/client/grpc_client.go @@ -27,14 +27,13 @@ type grpcClient struct { resCb func(*types.Request, *types.Response) // listens to all callbacks } -func NewGRPCClient(addr string, mustConnect bool) (*grpcClient, error) { +func NewGRPCClient(addr string, mustConnect bool) *grpcClient { cli := &grpcClient{ addr: addr, mustConnect: mustConnect, } cli.BaseService = *cmn.NewBaseService(nil, "grpcClient", cli) - _, err := cli.Start() // Just start it, it's confusing for callers to remember to start. - return cli, err + return cli } func dialerFunc(addr string, timeout time.Duration) (net.Conn, error) { diff --git a/client/socket_client.go b/client/socket_client.go index dd3e2903b..f95eac5cc 100644 --- a/client/socket_client.go +++ b/client/socket_client.go @@ -42,7 +42,7 @@ type socketClient struct { } -func NewSocketClient(addr string, mustConnect bool) (*socketClient, error) { +func NewSocketClient(addr string, mustConnect bool) *socketClient { cli := &socketClient{ reqQueue: make(chan *ReqRes, reqQueueSize), flushTimer: cmn.NewThrottleTimer("socketClient", flushThrottleMS), @@ -53,10 +53,7 @@ func NewSocketClient(addr string, mustConnect bool) (*socketClient, error) { resCb: nil, } cli.BaseService = *cmn.NewBaseService(nil, "socketClient", cli) - // FIXME we are loosing "Starting socketClient" message here - // add logger to params? - _, err := cli.Start() // Just start it, it's confusing for callers to remember to start. - return cli, err + return cli } func (cli *socketClient) OnStart() error { diff --git a/cmd/abci-cli/abci-cli.go b/cmd/abci-cli/abci-cli.go index f4fe45fee..3cf6ab894 100644 --- a/cmd/abci-cli/abci-cli.go +++ b/cmd/abci-cli/abci-cli.go @@ -139,7 +139,7 @@ func main() { func before(c *cli.Context) error { if logger == nil { - logger = log.NewTMLogger(log.NewSyncWriter(os.Stdout)) + logger = log.NewFilter(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), log.AllowError()) } if client == nil { var err error @@ -149,6 +149,9 @@ func before(c *cli.Context) error { os.Exit(1) } client.SetLogger(logger.With("module", "abci-client")) + if _, err := client.Start(); err != nil { + return err + } } return nil } diff --git a/example/block_aware/block_aware_test.go b/example/block_aware/block_aware_test.go index 6d42b876e..817deec63 100644 --- a/example/block_aware/block_aware_test.go +++ b/example/block_aware/block_aware_test.go @@ -23,8 +23,8 @@ func TestChainAware(t *testing.T) { defer srv.Stop() // Connect to the socket - client, err := abcicli.NewSocketClient("unix://test.sock", false) - if err != nil { + client := abcicli.NewSocketClient("unix://test.sock", false) + if _, err := client.Start(); err != nil { t.Fatalf("Error starting socket client: %v", err.Error()) } client.SetLogger(log.TestingLogger().With("module", "abci-client")) diff --git a/example/dummy/dummy_test.go b/example/dummy/dummy_test.go index f805dd73c..8ef36d077 100644 --- a/example/dummy/dummy_test.go +++ b/example/dummy/dummy_test.go @@ -221,8 +221,8 @@ func makeSocketClientServer(app types.Application, name string) (abcicli.Client, server.SetLogger(logger.With("module", "abci-server")) // Connect to the socket - client, err := abcicli.NewSocketClient(socket, false) - if err != nil { + client := abcicli.NewSocketClient(socket, false) + if _, err := client.Start(); err != nil { server.Stop() return nil, nil, err } @@ -244,8 +244,8 @@ func makeGRPCClientServer(app types.Application, name string) (abcicli.Client, c } server.SetLogger(logger.With("module", "abci-server")) - client, err := abcicli.NewGRPCClient(socket, true) - if err != nil { + client := abcicli.NewGRPCClient(socket, true) + if _, err := client.Start(); err != nil { server.Stop() return nil, nil, err } diff --git a/example/example_test.go b/example/example_test.go index 85c13d7d6..cdb44082f 100644 --- a/example/example_test.go +++ b/example/example_test.go @@ -46,8 +46,8 @@ func testStream(t *testing.T, app types.Application) { defer server.Stop() // Connect to the socket - client, err := abcicli.NewSocketClient("unix://test.sock", false) - if err != nil { + client := abcicli.NewSocketClient("unix://test.sock", false) + if _, err := client.Start(); err != nil { t.Fatalf("Error starting socket client: %v", err.Error()) } client.SetLogger(log.TestingLogger().With("module", "abci-client")) diff --git a/glide.lock b/glide.lock index 76fa6c5fb..55c5cdb38 100644 --- a/glide.lock +++ b/glide.lock @@ -1,12 +1,16 @@ hash: f9c2ddad16bf8652076a93bd9f398bb498eefb2f5bd2c89a77d966ebd12feec8 -updated: 2017-05-05T14:57:21.118338652-04:00 +updated: 2017-05-15T10:11:42.094564957-04:00 imports: - name: github.com/btcsuite/btcd - version: 4b348c1d33373d672edd83fc576892d0e46686d2 + version: b8df516b4b267acf2de46be593a9d948d1d2c420 subpackages: - btcec +- name: github.com/btcsuite/fastsha256 + version: 637e656429416087660c84436a2a035d69d54e2e +- name: github.com/clipperhouse/typewriter + version: c1a48da378ebb7db1db9f35981b5cc24bf2e5b85 - name: github.com/go-kit/kit - version: 0873e56b0faeae3a1d661b10d629135508ea5504 + version: d67bb4c202e3b91377d1079b110a6c9ce23ab2f8 subpackages: - log - log/level @@ -14,7 +18,7 @@ imports: - name: github.com/go-logfmt/logfmt version: 390ab7935ee28ec6b286364bba9b4dd6410cb3d5 - name: github.com/go-stack/stack - version: 7a2f19628aabfe68f0766b59e74d6315f8347d22 + version: 100eb0c0a9c5b306ca2fb4f165df21d80ada4b82 - name: github.com/golang/protobuf version: 18c9bb3261723cd5401db4d0c9fbc5c3b6c70fe8 subpackages: @@ -27,7 +31,7 @@ imports: - name: github.com/kr/logfmt version: b84e30acd515aadc4b783ad4ff83aff3299bdfe0 - name: github.com/pkg/errors - version: c605e284fe17294bda444b34710735b29d1a9d90 + version: ff09b135c25aae272398c51a07235b90a75aa4f0 - name: github.com/syndtr/goleveldb version: 8c81ea47d4c41a385645e133e15510fc6a2a74b4 subpackages: @@ -49,17 +53,17 @@ imports: - edwards25519 - extra25519 - name: github.com/tendermint/go-crypto - version: 524ba917a3a1636f21ab2c0bf76b6526903ab879 + version: a42b10e0feb465eb56fbc6bb5b71d57ef646ec57 - name: github.com/tendermint/go-wire - version: b53add0b622662731985485f3a19be7f684660b8 + version: 301a758c9d28e9f3900ff5d545403cf4e5f6e73f subpackages: - data - name: github.com/tendermint/merkleeyes - version: d0aa363fd4e015e509038c3a0ec493bc62ee0b8a + version: c722818b460381bc5b82e38c73ff6e22a9df624d subpackages: - iavl - name: github.com/tendermint/tmlibs - version: d72136da0df105944199c9e04035147fc6a4befa + version: 812d9f9b84d1dfe4cb46ce021b3a2d97b48d1292 subpackages: - common - db @@ -67,9 +71,9 @@ imports: - merkle - process - name: github.com/urfave/cli - version: ab403a54a148f2d857920810291539e1f817ee7b + version: d70f47eeca3afd795160003bc6e28b001d60c67c - name: golang.org/x/crypto - version: 5a033cc77e57eca05bdb50522851d29e03569cbe + version: c7af5bf2638a1164f2eb5467c39c6cffbd13a02e subpackages: - nacl/secretbox - openpgp/armor @@ -94,6 +98,11 @@ imports: - transform - unicode/bidi - unicode/norm +- name: golang.org/x/tools + version: 144c6642b5d832d6c44a53dad6ee61665dd432ce + subpackages: + - go/ast/astutil + - imports - name: google.golang.org/genproto version: 411e09b969b1170a9f0c467558eb4c4c110d9c77 subpackages: @@ -116,7 +125,7 @@ imports: - transport testImports: - name: github.com/davecgh/go-spew - version: 04cdfd42973bb9c8589fd6a731800cf222fde1a9 + version: 6d212800a42e8ab5c146b8ace3490ee17e5225f9 subpackages: - spew - name: github.com/pmezard/go-difflib @@ -124,7 +133,7 @@ testImports: subpackages: - difflib - name: github.com/stretchr/testify - version: 4d4bfba8f1d1027c4fdbe371823030df51419987 + version: 69483b4bd14f5845b5a1e55bca19e954e827f1d0 subpackages: - assert - require diff --git a/tests/test_app/app.go b/tests/test_app/app.go index a88a05fd6..3930957d7 100644 --- a/tests/test_app/app.go +++ b/tests/test_app/app.go @@ -36,8 +36,12 @@ func startClient(abciType string) abcicli.Client { // Start client client, err := abcicli.NewClient("tcp://127.0.0.1:46658", abciType, true) if err != nil { + panic(err.Error()) + } + if _, err := client.Start(); err != nil { panic("connecting to abci_app: " + err.Error()) } + logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout)) client.SetLogger(logger.With("module", "abcicli")) return client