Skip to content

Commit

Permalink
Merge pull request #212 from skycoin/bug/fix-logstore-dir
Browse files Browse the repository at this point in the history
Bug/fix logstore dir
  • Loading branch information
志宇 authored Mar 7, 2019
2 parents 69f3052 + 50ba5e4 commit d0b4b54
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 17 deletions.
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
lint: ## Run linters. Use make install-linters first.
GO111MODULE=on vendorcheck ./...
# GO111MODULE=on vendorcheck ./... # TODO: fix vendor check
GO111MODULE=on golangci-lint run -c .golangci.yml ./...
# The govet version in golangci-lint is out of date and has spurious warnings, run it separately
GO111MODULE=on go vet -all ./...

install-linters: ## Install linters
go get -u github.com/FiloSottile/vendorcheck
GO111MODULE=on go get -u github.com/FiloSottile/vendorcheck
# For some reason this install method is not recommended, see https://github.com/golangci/golangci-lint#install
# However, they suggest `curl ... | bash` which we should not do
go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
GO111MODULE=on go get -u github.com/golangci/golangci-lint/cmd/golangci-lint

format: ## Formats the code. Must have goimports installed (use make install-linters).
goimports -w -local github.com/skycoin/skywire ./pkg
goimports -w -local github.com/skycoin/skywire ./cmd
goimports -w -local github.com/skycoin/skywire ./internal
GO111MODULE=on goimports -w -local github.com/skycoin/skywire ./pkg
GO111MODULE=on goimports -w -local github.com/skycoin/skywire ./cmd
GO111MODULE=on goimports -w -local github.com/skycoin/skywire ./internal

dep: ## sorts dependencies
GO111MODULE=on go mod vendor -v
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/google/uuid v1.1.0
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/kr/pretty v0.1.0 // indirect
github.com/kr/pty v1.1.3
github.com/mattn/go-colorable v0.1.0 // indirect
github.com/mattn/go-isatty v0.0.4 // indirect
Expand All @@ -21,4 +22,6 @@ require (
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd
golang.org/x/sys v0.0.0-20190220154126-629670e5acc5 // indirect
golang.org/x/text v0.3.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@ github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NH
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.3 h1:/Um6a/ZmD5tF7peoOJ5oN5KMQ0DrGVQSXLNwyckutPk=
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-colorable v0.1.0 h1:v2XXALHHh6zHfYTJ+cSkwtyffnaOyR1MXaA91mTrb8o=
github.com/mattn/go-colorable v0.1.0/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs=
Expand Down Expand Up @@ -51,3 +56,7 @@ golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190220154126-629670e5acc5 h1:3Nsfe5Xa1wTt01QxlAFIY5j9ycDtS+d7mhvI8ZY5bn0=
golang.org/x/sys v0.0.0-20190220154126-629670e5acc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4 changes: 2 additions & 2 deletions pkg/node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ func (c *Config) TransportDiscovery() (transport.DiscoveryClient, error) {
}

// TransportLogStore returns configure transport.LogStore.
func (c *Config) TransportLogStore() transport.LogStore {
func (c *Config) TransportLogStore() (transport.LogStore, error) {
if c.Transport.LogStore.Type == "file" {
return transport.FileTransportLogStore(c.Transport.LogStore.Location)
}

return transport.InMemoryTransportLogStore()
return transport.InMemoryTransportLogStore(), nil
}

// RoutingTable returns configure routing.Table.
Expand Down
16 changes: 12 additions & 4 deletions pkg/node/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -43,14 +44,21 @@ func TestTransportDiscovery(t *testing.T) {
}

func TestTransportLogStore(t *testing.T) {
dir := filepath.Join(os.TempDir(), "foo")
defer os.RemoveAll(dir)

conf := Config{}
conf.Transport.LogStore.Type = "file"
conf.Routing.Table.Location = "/foo"
require.NotNil(t, conf.TransportLogStore())
conf.Transport.LogStore.Location = dir
ls, err := conf.TransportLogStore()
require.NoError(t, err)
require.NotNil(t, ls)

conf.Transport.LogStore.Type = "memory"
conf.Routing.Table.Location = ""
require.NotNil(t, conf.TransportLogStore())
conf.Transport.LogStore.Location = ""
ls, err = conf.TransportLogStore()
require.NoError(t, err)
require.NotNil(t, ls)
}

func TestRoutingTable(t *testing.T) {
Expand Down
6 changes: 5 additions & 1 deletion pkg/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ func NewNode(config *Config) (*Node, error) {
if err != nil {
return nil, fmt.Errorf("invalid MessagingConfig: %s", err)
}
logStore, err := config.TransportLogStore()
if err != nil {
return nil, fmt.Errorf("invalid TransportLogStore: %s", err)
}
tmConfig := &transport.ManagerConfig{
PubKey: pk, SecKey: sk,
DiscoveryClient: trDiscovery,
LogStore: config.TransportLogStore(),
LogStore: logStore,
DefaultNodes: config.TrustedNodes,
}
node.tm, err = transport.NewManager(tmConfig, node.messenger)
Expand Down
7 changes: 5 additions & 2 deletions pkg/transport/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ type fileTransportLogStore struct {
}

// FileTransportLogStore implements file TransportLogStore.
func FileTransportLogStore(dir string) LogStore {
return &fileTransportLogStore{dir}
func FileTransportLogStore(dir string) (LogStore, error) {
if err := os.MkdirAll(dir, 0700); err != nil {
return nil, err
}
return &fileTransportLogStore{dir}, nil
}

func (tls *fileTransportLogStore) Entry(id uuid.UUID) (*LogEntry, error) {
Expand Down
4 changes: 3 additions & 1 deletion pkg/transport/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ func TestFileTransportLogStore(t *testing.T) {
require.NoError(t, err)
defer os.RemoveAll(dir)

testTransportLogStore(t, FileTransportLogStore(dir))
ls, err := FileTransportLogStore(dir)
require.NoError(t, err)
testTransportLogStore(t, ls)
}
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ github.com/pmezard/go-difflib/difflib
# github.com/sirupsen/logrus v1.3.0
github.com/sirupsen/logrus
# github.com/skycoin/skycoin v0.25.1
github.com/skycoin/skycoin/src/cipher
github.com/skycoin/skycoin/src/util/logging
github.com/skycoin/skycoin/src/cipher
github.com/skycoin/skycoin/src/cipher/base58
github.com/skycoin/skycoin/src/cipher/ripemd160
github.com/skycoin/skycoin/src/cipher/secp256k1-go
Expand Down

0 comments on commit d0b4b54

Please sign in to comment.