Skip to content

add more static analysis tool during tests #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ jobs:

- name: Check out code into the Go module directory
uses: actions/checkout@v1


- name: Get dependencies
run: |
make getdeps

- name: Test
run: go test -v ./...

- name: Build
run: make
run: |
export PATH=/home/runner/go/bin:$PATH
make test
47 changes: 47 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,53 @@ all: client server

BUILD_FLAGS = -ldflags '-extldflags "-fno-PIC -static"' -buildmode pie -tags 'osusergo netgo static_build'


getdeps:
@echo "Installing golint" && go get -u golang.org/x/lint/golint
@echo "Installing gocyclo" && go get -u github.com/fzipp/gocyclo
@echo "Installing deadcode" && go get -u github.com/remyoudompheng/go-misc/deadcode
@echo "Installing misspell" && go get -u github.com/client9/misspell/cmd/misspell
@echo "Installing ineffassign" && go get -u github.com/gordonklaus/ineffassign

verifiers: vet fmt lint cyclo spelling static #deadcode

vet:
@echo "Running $@"
@go vet -atomic -bool -copylocks -nilfunc -printf -rangeloops -unreachable -unsafeptr -unusedresult ./...

fmt:
@echo "Running $@"
@gofmt -d .

lint:
@echo "Running $@"
golint -set_exit_status $(shell go list ./... | grep -v stubs)

ineffassign:
@echo "Running $@"
ineffassign .

cyclo:
@echo "Running $@"
gocyclo -over 100 .

deadcode:
@echo "Running $@"
deadcode -test $(shell go list ./...) || true

spelling:
misspell -i monitord -error `find .`

static:
go run honnef.co/go/tools/cmd/staticcheck -- ./...

# Builds minio, runs the verifiers then runs the tests.
check: test
test: verifiers build
go test -v ./...

build: server client

server:
mkdir -p bin
cd cmds/server && go build $(BUILD_FLAGS) -o ../../bin/trs
Expand Down
1 change: 1 addition & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/rs/zerolog/log"
)

// Client connect to a tpc router server and opens a reverse tunnel
type Client struct {
localAddr string
remoteAddr string
Expand Down
5 changes: 3 additions & 2 deletions cmds/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/signal"
"sync"
"syscall"
"time"

"github.com/cenkalti/backoff/v3"
Expand Down Expand Up @@ -45,8 +46,8 @@ func main() {
backoff := c.Int("backoff")
secret := c.String("secret")

cSig := make(chan os.Signal)
signal.Notify(cSig, os.Interrupt, os.Kill)
cSig := make(chan os.Signal, 1)
signal.Notify(cSig, os.Interrupt, syscall.SIGTERM)

wg := sync.WaitGroup{}
wg.Add(len(remotes))
Expand Down
11 changes: 5 additions & 6 deletions cmds/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"fmt"
"os/signal"
"syscall"

"github.com/BurntSushi/toml"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -34,7 +36,8 @@ func readConfig(path string) (tcprouter.Config, error) {
}
defer f.Close()

c, err := tcprouter.ParseCfg(f)
var c tcprouter.Config
_, err = toml.DecodeReader(f, &c)
if err != nil {
return c, fmt.Errorf("failed to read configuration %w", err)
}
Expand Down Expand Up @@ -62,10 +65,6 @@ func initStore(backend store.Backend, addr string) (store.Store, error) {
)
}

var (
cfgPath string
)

func main() {
app := cli.NewApp()
app.Version = "0.0.1"
Expand Down Expand Up @@ -111,7 +110,7 @@ func main() {
s := tcprouter.NewServer(serverOpts, kv, cfg.Server.Services)

cSig := make(chan os.Signal, 1)
signal.Notify(cSig, os.Interrupt, os.Kill)
signal.Notify(cSig, os.Interrupt, syscall.SIGTERM)

ctx, cancel := context.WithCancel(context.Background())
go func() {
Expand Down
15 changes: 7 additions & 8 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package tcprouter

import (
"fmt"
"io"

"github.com/BurntSushi/toml"
"github.com/abronan/valkeyrie/store"
)

Expand All @@ -14,10 +12,12 @@ var validBackends = map[string]store.Backend{
"etcd": store.ETCDV3,
}

// Config hold the server configuration
type Config struct {
Server ServerConfig `toml:"server"`
}

// ServerConfig configures the server listeners and backend
type ServerConfig struct {
Host string `toml:"addr"`
Port uint `toml:"port"`
Expand All @@ -27,17 +27,20 @@ type ServerConfig struct {
Services map[string]Service `toml:"services"`
}

// Addr returns the listenting address of the server
func (s ServerConfig) Addr() string {
return fmt.Sprintf("%s:%d", s.Host, s.Port)
}

// Service defines a proxy configuration
type Service struct {
Addr string `toml:"addr"`
ClientSecret string `toml:"clientsecret` // will forward connection to it directly instead of hitting the Addr.
TLSPort int `toml:"tlsport"`
HTTPPort int `toml:"httpport"`
}

// DbBackendConfig define the connection to a backend store
type DbBackendConfig struct {
DbType string `toml:"type"`
Host string `toml:"addr"`
Expand All @@ -49,20 +52,16 @@ type DbBackendConfig struct {
//Bucket string `toml:"bucket"`
}

// Addr returns the listenting address of the server
func (b DbBackendConfig) Addr() string {
return fmt.Sprintf("%s:%d", b.Host, b.Port)
}

// Backend return the Backend object of the b.DbType
func (b DbBackendConfig) Backend() store.Backend {
backend, ok := validBackends[b.DbType]
if !ok {
panic(fmt.Sprintf("unsupported backend type '%s'", b.DbType))
}
return backend
}

func ParseCfg(r io.Reader) (Config, error) {
var conf Config
_, err := toml.DecodeReader(r, &conf)
return conf, err
}
10 changes: 4 additions & 6 deletions examples/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@

# Require a certificate from the server. We used a self-signed certificate
# so here ca_certs must be the server certificate itself.
ssl_sock = ssl.wrap_socket(s,
ca_certs="server.crt",
cert_reqs=ssl.CERT_REQUIRED)
ssl_sock = ssl.wrap_socket(s, ca_certs="server.crt", cert_reqs=ssl.CERT_REQUIRED)

ssl_sock.connect(('localhost', 5500))
ssl_sock.connect(("localhost", 5500))
# ssl_sock.connect(('localhost', 9092))

ssl_sock.sendall(b'login superadmin password\n')
ssl_sock.sendall(b"login superadmin password\n")

while True:
time.sleep(5)
ssl_sock.sendall(b'ping null\n')
ssl_sock.sendall(b"ping null\n")
print(ssl_sock.recv(4096))

ssl_sock.close()
19 changes: 4 additions & 15 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,8 @@ import (

"github.com/abronan/valkeyrie"
"github.com/abronan/valkeyrie/store"
//"github.com/abronan/valkeyrie/store/boltdb"
//etcd "github.com/abronan/valkeyrie/store/etcd/v3"
"github.com/abronan/valkeyrie/store/redis"
)
var validBackends = map[string]store.Backend{
"redis": store.REDIS,
//"boltdb": store.BOLTDB,
//"etcd": store.ETCDV3,

}

func init() {

Expand All @@ -26,7 +18,7 @@ func init() {

}

type Service struct {
type service struct {
Addr string `json:"addr"`
SNI string `json:"sni"`
Name string `json:"bing"`
Expand All @@ -37,23 +29,20 @@ func main() {
// Initialize a new store with redis
kv, err := valkeyrie.NewStore(
store.REDIS,
[]string{"127.0.0.1:6379" },
[]string{"127.0.0.1:6379"},
&store.Config{
ConnectionTimeout: 10 * time.Second,
},
)
if err != nil {
log.Fatal("Cannot create store redis")
}
google := &Service{Addr:"172.217.19.46:443", SNI:"www.google.com", Name:"google"}
google := &service{Addr: "172.217.19.46:443", SNI: "www.google.com", Name: "google"}
encGoogle, _ := json.Marshal(google)
bing := &Service{Addr:"13.107.21.200:443", SNI:"www.bing.com", Name:"bing"}
bing := &service{Addr: "13.107.21.200:443", SNI: "www.bing.com", Name: "bing"}
encBing, _ := json.Marshal(bing)

kv.Put("/tcprouter/service/google", encGoogle, nil)
kv.Put("/tcprouter/service/bing", encBing, nil)


}


1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ require (
github.com/rs/zerolog v1.15.0
github.com/stretchr/testify v1.3.0
github.com/urfave/cli/v2 v2.1.1
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 // indirect
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ github.com/cenkalti/backoff/v3 v3.1.1 h1:UBHElAnr3ODEbpqPzX8g5sBcASjoLFtt3L/xwJ0
github.com/cenkalti/backoff/v3 v3.1.1/go.mod h1:cIeZDE3IrqwwJl6VUwCN6trj1oXrTS4rc0ij+ULvLYs=
github.com/circonus-labs/circonus-gometrics v2.3.1+incompatible/go.mod h1:nmEj6Dob7S7YxXgwXpfOuvO54S+tGdZdw9fuRZt25Ag=
github.com/circonus-labs/circonusllhist v0.1.3/go.mod h1:kMXHVDlOchFAehlya5ePtbp5jckzBHf4XRpQvBOLI+I=
github.com/client9/misspell v0.3.4 h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/coreos/bbolt v1.3.3/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.13+incompatible h1:8F3hqu9fGYLBifCmRCJsicFqDx/D68Rt3q1JMazcgBQ=
Expand Down Expand Up @@ -179,6 +180,7 @@ golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnf
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3 h1:x/bBzNauLQAlE3fLku/xy92Y8QwKX5HZymrMz2IiKFc=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -190,6 +192,8 @@ golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU=
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be h1:vEDujvNQGv4jgYKudGeI/+DAX4Jffq6hpD55MmoEvKs=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -212,6 +216,7 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc h1:N3zlSgxkefUH/ecsl37RWTkESTB026kmXzNly8TuZCI=
golang.org/x/tools v0.0.0-20190425163242-31fd60d6bfdc/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8 h1:Nw54tB0rB7hY/N0NQvRW8DG4Yk3Q6T9cu9RcFQDu1tc=
Expand All @@ -234,4 +239,5 @@ gopkg.in/yaml.v2 v2.2.1 h1:mUhvW9EsL+naU5Q3cakzfE91YhliOondGd6ZrsDBHQE=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099 h1:XJP7lxbSxWLOMNdBE4B/STaqVy6L73o0knwj2vIlxnw=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
1 change: 1 addition & 0 deletions handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
)

const (
// MagicNr is the bytes sent during handshake to identity a tcprouter client connection
// TODO: chose a valid magic number
MagicNr = 0x1111
)
Expand Down
Loading