From 0b217ddb07a9ed17f7a00174861e8d6558dff0e7 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Mon, 17 Aug 2020 17:56:05 +0100 Subject: [PATCH] Linting --- README.md | 1 + cmd/ck-client/ck-client.go | 2 +- cmd/ck-server/ck-server.go | 3 +- internal/multiplex/qos.go | 2 +- internal/server/auth.go | 1 - internal/server/dispatcher.go | 4 +- internal/server/usermanager/localmanager.go | 52 ++++++++++----------- 7 files changed, 33 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 87b391e..2cad5b9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Build Status](https://travis-ci.org/cbeuw/Cloak.svg?branch=master)](https://travis-ci.org/cbeuw/Cloak) [![codecov](https://codecov.io/gh/cbeuw/Cloak/branch/master/graph/badge.svg)](https://codecov.io/gh/cbeuw/Cloak) +[![Go Report Card](https://goreportcard.com/badge/github.com/cbeuw/Cloak)](https://goreportcard.com/report/github.com/cbeuw/Cloak) [![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SAUYKGSREP8GL&source=url) diff --git a/cmd/ck-client/ck-client.go b/cmd/ck-client/ck-client.go index 2eac843..906bb80 100644 --- a/cmd/ck-client/ck-client.go +++ b/cmd/ck-client/ck-client.go @@ -49,7 +49,7 @@ func main() { flag.StringVar(&remoteHost, "s", "", "remoteHost: IP of your proxy server") flag.StringVar(&remotePort, "p", "443", "remotePort: proxy port, should be 443") flag.BoolVar(&udp, "u", false, "udp: set this flag if the underlying proxy is using UDP protocol") - flag.StringVar(&config, "c", "ckclient.json", "config: path to the configuration file or options seperated with semicolons") + flag.StringVar(&config, "c", "ckclient.json", "config: path to the configuration file or options separated with semicolons") flag.StringVar(&proxyMethod, "proxy", "", "proxy: the proxy method's name. It must match exactly with the corresponding entry in server's ProxyBook") flag.StringVar(&b64AdminUID, "a", "", "adminUID: enter the adminUID to serve the admin api") askVersion := flag.Bool("v", false, "Print the version number") diff --git a/cmd/ck-server/ck-server.go b/cmd/ck-server/ck-server.go index 858c4fe..d1e6b2c 100644 --- a/cmd/ck-server/ck-server.go +++ b/cmd/ck-server/ck-server.go @@ -92,8 +92,7 @@ func main() { bindAddr, err := parseBindAddr(raw.BindAddr) if err != nil { - err = fmt.Errorf("unable to parse BindAddr: %v", err) - return + log.Fatalf("unable to parse BindAddr: %v", err) } if !pluginMode && len(bindAddr) == 0 { https, _ := net.ResolveTCPAddr("tcp", ":443") diff --git a/internal/multiplex/qos.go b/internal/multiplex/qos.go index 103964e..9905842 100644 --- a/internal/multiplex/qos.go +++ b/internal/multiplex/qos.go @@ -8,7 +8,7 @@ import ( // Valve needs to be universal, across all sessions that belong to a user type LimitedValve struct { - // traffic directions from the server's perspective are refered + // traffic directions from the server's perspective are referred // exclusively as rx and tx. // rx is from client to server, tx is from server to client // DO NOT use terms up or down as this is used in usermanager diff --git a/internal/server/auth.go b/internal/server/auth.go index bbbbf58..3ae5ef0 100644 --- a/internal/server/auth.go +++ b/internal/server/auth.go @@ -31,7 +31,6 @@ const ( ) var ErrTimestampOutOfWindow = errors.New("timestamp is outside of the accepting window") -var ErrUnrecognisedProtocol = errors.New("unrecognised protocol") // decryptClientInfo checks if a the authFragments are valid. It doesn't check if the UID is authorised func decryptClientInfo(fragments authFragments, serverTime time.Time) (info ClientInfo, err error) { diff --git a/internal/server/dispatcher.go b/internal/server/dispatcher.go index 1d0ca3c..378f270 100644 --- a/internal/server/dispatcher.go +++ b/internal/server/dispatcher.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/base64" "encoding/binary" + "errors" "fmt" "github.com/cbeuw/Cloak/internal/common" "github.com/cbeuw/Cloak/internal/server/usermanager" @@ -53,6 +54,8 @@ func connReadLine(conn net.Conn, buf []byte) (int, error) { return i, io.ErrShortBuffer } +var ErrUnrecognisedProtocol = errors.New("unrecognised protocol") + func readFirstPacket(conn net.Conn, buf []byte, timeout time.Duration) (int, Transport, bool, error) { conn.SetReadDeadline(time.Now().Add(timeout)) defer conn.SetReadDeadline(time.Time{}) @@ -113,7 +116,6 @@ func readFirstPacket(conn net.Conn, buf []byte, timeout time.Duration) (int, Tra } } default: - err = fmt.Errorf("unrecognised protocol signature") return bufOffset, transport, true, ErrUnrecognisedProtocol } return bufOffset, transport, true, nil diff --git a/internal/server/usermanager/localmanager.go b/internal/server/usermanager/localmanager.go index 057c159..1689595 100644 --- a/internal/server/usermanager/localmanager.go +++ b/internal/server/usermanager/localmanager.go @@ -7,8 +7,8 @@ import ( bolt "go.etcd.io/bbolt" ) -var Uint32 = binary.BigEndian.Uint32 -var Uint64 = binary.BigEndian.Uint64 +var u32 = binary.BigEndian.Uint32 +var u64 = binary.BigEndian.Uint64 func i64ToB(value int64) []byte { oct := make([]byte, 8) @@ -48,11 +48,11 @@ func (manager *localManager) AuthenticateUser(UID []byte) (int64, int64, error) if bucket == nil { return ErrUserNotFound } - upRate = int64(Uint64(bucket.Get([]byte("UpRate")))) - downRate = int64(Uint64(bucket.Get([]byte("DownRate")))) - upCredit = int64(Uint64(bucket.Get([]byte("UpCredit")))) - downCredit = int64(Uint64(bucket.Get([]byte("DownCredit")))) - expiryTime = int64(Uint64(bucket.Get([]byte("ExpiryTime")))) + upRate = int64(u64(bucket.Get([]byte("UpRate")))) + downRate = int64(u64(bucket.Get([]byte("DownRate")))) + upCredit = int64(u64(bucket.Get([]byte("UpCredit")))) + downCredit = int64(u64(bucket.Get([]byte("DownCredit")))) + expiryTime = int64(u64(bucket.Get([]byte("ExpiryTime")))) return nil }) if err != nil { @@ -83,10 +83,10 @@ func (manager *localManager) AuthoriseNewSession(UID []byte, ainfo Authorisation if bucket == nil { return ErrUserNotFound } - sessionsCap = int(Uint32(bucket.Get([]byte("SessionsCap")))) - upCredit = int64(Uint64(bucket.Get([]byte("UpCredit")))) - downCredit = int64(Uint64(bucket.Get([]byte("DownCredit")))) - expiryTime = int64(Uint64(bucket.Get([]byte("ExpiryTime")))) + sessionsCap = int(u32(bucket.Get([]byte("SessionsCap")))) + upCredit = int64(u64(bucket.Get([]byte("UpCredit")))) + downCredit = int64(u64(bucket.Get([]byte("DownCredit")))) + expiryTime = int64(u64(bucket.Get([]byte("ExpiryTime")))) return nil }) if err != nil { @@ -129,7 +129,7 @@ func (manager *localManager) UploadStatus(uploads []StatusUpdate) ([]StatusRespo responses = append(responses, resp) } - oldUp := int64(Uint64(bucket.Get([]byte("UpCredit")))) + oldUp := int64(u64(bucket.Get([]byte("UpCredit")))) newUp := oldUp - status.UpUsage if newUp <= 0 { resp = StatusResponse{ @@ -144,7 +144,7 @@ func (manager *localManager) UploadStatus(uploads []StatusUpdate) ([]StatusRespo log.Error(err) } - oldDown := int64(Uint64(bucket.Get([]byte("DownCredit")))) + oldDown := int64(u64(bucket.Get([]byte("DownCredit")))) newDown := oldDown - status.DownUsage if newDown <= 0 { resp = StatusResponse{ @@ -159,7 +159,7 @@ func (manager *localManager) UploadStatus(uploads []StatusUpdate) ([]StatusRespo log.Error(err) } - expiry := int64(Uint64(bucket.Get([]byte("ExpiryTime")))) + expiry := int64(u64(bucket.Get([]byte("ExpiryTime")))) if manager.world.Now().Unix() > expiry { resp = StatusResponse{ status.UID, @@ -179,12 +179,12 @@ func (manager *localManager) ListAllUsers() (infos []UserInfo, err error) { err = tx.ForEach(func(UID []byte, bucket *bolt.Bucket) error { var uinfo UserInfo uinfo.UID = UID - uinfo.SessionsCap = int32(Uint32(bucket.Get([]byte("SessionsCap")))) - uinfo.UpRate = int64(Uint64(bucket.Get([]byte("UpRate")))) - uinfo.DownRate = int64(Uint64(bucket.Get([]byte("DownRate")))) - uinfo.UpCredit = int64(Uint64(bucket.Get([]byte("UpCredit")))) - uinfo.DownCredit = int64(Uint64(bucket.Get([]byte("DownCredit")))) - uinfo.ExpiryTime = int64(Uint64(bucket.Get([]byte("ExpiryTime")))) + uinfo.SessionsCap = int32(u32(bucket.Get([]byte("SessionsCap")))) + uinfo.UpRate = int64(u64(bucket.Get([]byte("UpRate")))) + uinfo.DownRate = int64(u64(bucket.Get([]byte("DownRate")))) + uinfo.UpCredit = int64(u64(bucket.Get([]byte("UpCredit")))) + uinfo.DownCredit = int64(u64(bucket.Get([]byte("DownCredit")))) + uinfo.ExpiryTime = int64(u64(bucket.Get([]byte("ExpiryTime")))) infos = append(infos, uinfo) return nil }) @@ -200,12 +200,12 @@ func (manager *localManager) GetUserInfo(UID []byte) (uinfo UserInfo, err error) return ErrUserNotFound } uinfo.UID = UID - uinfo.SessionsCap = int32(Uint32(bucket.Get([]byte("SessionsCap")))) - uinfo.UpRate = int64(Uint64(bucket.Get([]byte("UpRate")))) - uinfo.DownRate = int64(Uint64(bucket.Get([]byte("DownRate")))) - uinfo.UpCredit = int64(Uint64(bucket.Get([]byte("UpCredit")))) - uinfo.DownCredit = int64(Uint64(bucket.Get([]byte("DownCredit")))) - uinfo.ExpiryTime = int64(Uint64(bucket.Get([]byte("ExpiryTime")))) + uinfo.SessionsCap = int32(u32(bucket.Get([]byte("SessionsCap")))) + uinfo.UpRate = int64(u64(bucket.Get([]byte("UpRate")))) + uinfo.DownRate = int64(u64(bucket.Get([]byte("DownRate")))) + uinfo.UpCredit = int64(u64(bucket.Get([]byte("UpCredit")))) + uinfo.DownCredit = int64(u64(bucket.Get([]byte("DownCredit")))) + uinfo.ExpiryTime = int64(u64(bucket.Get([]byte("ExpiryTime")))) return nil }) return