From 31c1a37b387847a506389addfe09f0fb13c1eccd Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sat, 7 Sep 2019 09:46:04 -0700 Subject: [PATCH] fix linting --- src/cli/cli.go | 2 ++ src/croc/croc.go | 8 ++++++++ src/crypt/crypt.go | 3 +++ src/models/constants.go | 3 +++ src/tcp/tcp.go | 2 ++ src/utils/utils.go | 8 +++++++- 6 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/cli/cli.go b/src/cli/cli.go index 2b88dc4e..3ccfde3c 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -21,8 +21,10 @@ import ( "github.com/urfave/cli" ) +// Version specifies the version var Version string +// Run will run the command line proram func Run() (err error) { // use all of the processors runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/src/croc/croc.go b/src/croc/croc.go index 806c2cae..4fdc1aa5 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -36,6 +36,7 @@ func init() { log.SetLevel("debug") } +// Debug toggles debug mode func Debug(debug bool) { if debug { log.SetLevel("debug") @@ -44,6 +45,7 @@ func Debug(debug bool) { } } +// Options specifies user specific options type Options struct { IsSender bool SharedSecret string @@ -55,6 +57,7 @@ type Options struct { DisableLocal bool } +// Client holds the state of the croc transfer type Client struct { Options Options Pake *pake.Pake @@ -96,11 +99,14 @@ type Client struct { quit chan bool } +// Chunk contains information about the +// needed bytes type Chunk struct { Bytes []byte `json:"b,omitempty"` Location int64 `json:"l,omitempty"` } +// FileInfo registers the information about the file type FileInfo struct { Name string `json:"n,omitempty"` FolderRemote string `json:"fr,omitempty"` @@ -112,11 +118,13 @@ type FileInfo struct { IsEncrypted bool `json:"e,omitempty"` } +// RemoteFileRequest requests specific bytes type RemoteFileRequest struct { CurrentFileChunkRanges []int64 FilesToTransferCurrentNum int } +// SenderInfo lists the files to be transfered type SenderInfo struct { FilesToTransfer []FileInfo } diff --git a/src/crypt/crypt.go b/src/crypt/crypt.go index 743eb910..65ba77c4 100644 --- a/src/crypt/crypt.go +++ b/src/crypt/crypt.go @@ -9,6 +9,8 @@ import ( "golang.org/x/crypto/pbkdf2" ) +// Encryption is the basic type for storing +// the key, passphrase and salt type Encryption struct { key []byte passphrase []byte @@ -36,6 +38,7 @@ func New(passphrase []byte, salt []byte) (e Encryption, err error) { return } +// Salt returns the salt bytes func (e Encryption) Salt() []byte { return e.salt } diff --git a/src/models/constants.go b/src/models/constants.go index acb20a7b..4c074981 100644 --- a/src/models/constants.go +++ b/src/models/constants.go @@ -1,4 +1,7 @@ package models +// TCP_BUFFER_SIZE is the maximum packet size const TCP_BUFFER_SIZE = 1024 * 64 + +// DEFAULT_RELAY is the default relay used (can be set using --relay) const DEFAULT_RELAY = "142.93.177.120:9009" diff --git a/src/tcp/tcp.go b/src/tcp/tcp.go index 74443a05..47cd082e 100644 --- a/src/tcp/tcp.go +++ b/src/tcp/tcp.go @@ -251,6 +251,8 @@ func pipe(conn1 net.Conn, conn2 net.Conn) { } } +// ConnectToTCPServer will initiate a new connection +// to the specified address, room with optional time limit func ConnectToTCPServer(address, room string, timelimit ...time.Duration) (c *comm.Comm, banner string, ipaddr string, err error) { if len(timelimit) > 0 { c, err = comm.NewConnection(address, timelimit[0]) diff --git a/src/utils/utils.go b/src/utils/utils.go index adcd017a..0784f6d3 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -44,6 +44,7 @@ func HashFile(fname string) (hash256 []byte, err error) { return IMOHashFile(fname) } +// MD5HashFile returns MD5 hash func MD5HashFile(fname string) (hash256 []byte, err error) { f, err := os.Open(fname) if err != nil { @@ -91,6 +92,7 @@ func SHA256(s string) string { return fmt.Sprintf("%x", sha.Sum(nil)) } +// PublicIP returns public ip address func PublicIP() (ip string, err error) { resp, err := http.Get("https://canhazip.com") if err != nil { @@ -108,7 +110,7 @@ func PublicIP() (ip string, err error) { return } -// Get preferred outbound ip of this machine +// LocalIP returns local ip address func LocalIP() string { conn, err := net.Dial("udp", "8.8.8.8:80") if err != nil { @@ -121,6 +123,7 @@ func LocalIP() string { return localAddr.IP.String() } +// GetRandomName returns mnemoicoded random name func GetRandomName() string { result := []string{} bs := make([]byte, 4) @@ -129,6 +132,7 @@ func GetRandomName() string { return strings.Join(result, "-") } +// ByteCountDecimal converts bytes to human readable byte string func ByteCountDecimal(b int64) string { const unit = 1000 if b < unit { @@ -196,6 +200,7 @@ func MissingChunks(fname string, fsize int64, chunkSize int) (chunkRanges []int6 return } +// ChunkRangesToChunks converts chunk ranges to list func ChunkRangesToChunks(chunkRanges []int64) (chunks []int64) { if len(chunkRanges) == 0 { return @@ -210,6 +215,7 @@ func ChunkRangesToChunks(chunkRanges []int64) (chunks []int64) { return } +// GetLocalIPs returns all local ips func GetLocalIPs() (ips []string, err error) { addrs, err := net.InterfaceAddrs() if err != nil {