0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

fix linting

This commit is contained in:
Zack Scholl 2019-09-07 09:46:04 -07:00
parent 0277abe5d4
commit 31c1a37b38
6 changed files with 25 additions and 1 deletions

View file

@ -21,8 +21,10 @@ import (
"github.com/urfave/cli" "github.com/urfave/cli"
) )
// Version specifies the version
var Version string var Version string
// Run will run the command line proram
func Run() (err error) { func Run() (err error) {
// use all of the processors // use all of the processors
runtime.GOMAXPROCS(runtime.NumCPU()) runtime.GOMAXPROCS(runtime.NumCPU())

View file

@ -36,6 +36,7 @@ func init() {
log.SetLevel("debug") log.SetLevel("debug")
} }
// Debug toggles debug mode
func Debug(debug bool) { func Debug(debug bool) {
if debug { if debug {
log.SetLevel("debug") log.SetLevel("debug")
@ -44,6 +45,7 @@ func Debug(debug bool) {
} }
} }
// Options specifies user specific options
type Options struct { type Options struct {
IsSender bool IsSender bool
SharedSecret string SharedSecret string
@ -55,6 +57,7 @@ type Options struct {
DisableLocal bool DisableLocal bool
} }
// Client holds the state of the croc transfer
type Client struct { type Client struct {
Options Options Options Options
Pake *pake.Pake Pake *pake.Pake
@ -96,11 +99,14 @@ type Client struct {
quit chan bool quit chan bool
} }
// Chunk contains information about the
// needed bytes
type Chunk struct { type Chunk struct {
Bytes []byte `json:"b,omitempty"` Bytes []byte `json:"b,omitempty"`
Location int64 `json:"l,omitempty"` Location int64 `json:"l,omitempty"`
} }
// FileInfo registers the information about the file
type FileInfo struct { type FileInfo struct {
Name string `json:"n,omitempty"` Name string `json:"n,omitempty"`
FolderRemote string `json:"fr,omitempty"` FolderRemote string `json:"fr,omitempty"`
@ -112,11 +118,13 @@ type FileInfo struct {
IsEncrypted bool `json:"e,omitempty"` IsEncrypted bool `json:"e,omitempty"`
} }
// RemoteFileRequest requests specific bytes
type RemoteFileRequest struct { type RemoteFileRequest struct {
CurrentFileChunkRanges []int64 CurrentFileChunkRanges []int64
FilesToTransferCurrentNum int FilesToTransferCurrentNum int
} }
// SenderInfo lists the files to be transfered
type SenderInfo struct { type SenderInfo struct {
FilesToTransfer []FileInfo FilesToTransfer []FileInfo
} }

View file

@ -9,6 +9,8 @@ import (
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
) )
// Encryption is the basic type for storing
// the key, passphrase and salt
type Encryption struct { type Encryption struct {
key []byte key []byte
passphrase []byte passphrase []byte
@ -36,6 +38,7 @@ func New(passphrase []byte, salt []byte) (e Encryption, err error) {
return return
} }
// Salt returns the salt bytes
func (e Encryption) Salt() []byte { func (e Encryption) Salt() []byte {
return e.salt return e.salt
} }

View file

@ -1,4 +1,7 @@
package models package models
// TCP_BUFFER_SIZE is the maximum packet size
const TCP_BUFFER_SIZE = 1024 * 64 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" const DEFAULT_RELAY = "142.93.177.120:9009"

View file

@ -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) { func ConnectToTCPServer(address, room string, timelimit ...time.Duration) (c *comm.Comm, banner string, ipaddr string, err error) {
if len(timelimit) > 0 { if len(timelimit) > 0 {
c, err = comm.NewConnection(address, timelimit[0]) c, err = comm.NewConnection(address, timelimit[0])

View file

@ -44,6 +44,7 @@ func HashFile(fname string) (hash256 []byte, err error) {
return IMOHashFile(fname) return IMOHashFile(fname)
} }
// MD5HashFile returns MD5 hash
func MD5HashFile(fname string) (hash256 []byte, err error) { func MD5HashFile(fname string) (hash256 []byte, err error) {
f, err := os.Open(fname) f, err := os.Open(fname)
if err != nil { if err != nil {
@ -91,6 +92,7 @@ func SHA256(s string) string {
return fmt.Sprintf("%x", sha.Sum(nil)) return fmt.Sprintf("%x", sha.Sum(nil))
} }
// PublicIP returns public ip address
func PublicIP() (ip string, err error) { func PublicIP() (ip string, err error) {
resp, err := http.Get("https://canhazip.com") resp, err := http.Get("https://canhazip.com")
if err != nil { if err != nil {
@ -108,7 +110,7 @@ func PublicIP() (ip string, err error) {
return return
} }
// Get preferred outbound ip of this machine // LocalIP returns local ip address
func LocalIP() string { func LocalIP() string {
conn, err := net.Dial("udp", "8.8.8.8:80") conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil { if err != nil {
@ -121,6 +123,7 @@ func LocalIP() string {
return localAddr.IP.String() return localAddr.IP.String()
} }
// GetRandomName returns mnemoicoded random name
func GetRandomName() string { func GetRandomName() string {
result := []string{} result := []string{}
bs := make([]byte, 4) bs := make([]byte, 4)
@ -129,6 +132,7 @@ func GetRandomName() string {
return strings.Join(result, "-") return strings.Join(result, "-")
} }
// ByteCountDecimal converts bytes to human readable byte string
func ByteCountDecimal(b int64) string { func ByteCountDecimal(b int64) string {
const unit = 1000 const unit = 1000
if b < unit { if b < unit {
@ -196,6 +200,7 @@ func MissingChunks(fname string, fsize int64, chunkSize int) (chunkRanges []int6
return return
} }
// ChunkRangesToChunks converts chunk ranges to list
func ChunkRangesToChunks(chunkRanges []int64) (chunks []int64) { func ChunkRangesToChunks(chunkRanges []int64) (chunks []int64) {
if len(chunkRanges) == 0 { if len(chunkRanges) == 0 {
return return
@ -210,6 +215,7 @@ func ChunkRangesToChunks(chunkRanges []int64) (chunks []int64) {
return return
} }
// GetLocalIPs returns all local ips
func GetLocalIPs() (ips []string, err error) { func GetLocalIPs() (ips []string, err error) {
addrs, err := net.InterfaceAddrs() addrs, err := net.InterfaceAddrs()
if err != nil { if err != nil {