mirror of https://github.com/cbeuw/Cloak
Linting
This commit is contained in:
parent
9023f3f897
commit
0b217ddb07
|
|
@ -1,5 +1,6 @@
|
|||
[](https://travis-ci.org/cbeuw/Cloak)
|
||||
[](https://codecov.io/gh/cbeuw/Cloak)
|
||||
[](https://goreportcard.com/report/github.com/cbeuw/Cloak)
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SAUYKGSREP8GL&source=url)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue