From 7515c92a8be17657dbb1851ef9ec82a9417bc603 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Thu, 22 Aug 2019 13:22:31 -0700 Subject: [PATCH 01/18] update deps --- go.mod | 14 ++++++++------ go.sum | 39 +++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index b3fee5f1..257f815f 100644 --- a/go.mod +++ b/go.mod @@ -7,19 +7,21 @@ require ( github.com/cespare/xxhash v1.1.0 github.com/fatih/color v1.7.0 // indirect github.com/kalafut/imohash v1.0.0 + github.com/kr/pretty v0.1.0 // indirect github.com/mattn/go-colorable v0.1.2 // indirect + github.com/mattn/go-isatty v0.0.9 // indirect github.com/pkg/errors v0.8.1 github.com/schollz/logger v1.0.1 github.com/schollz/mnemonicode v1.0.1 github.com/schollz/pake v1.1.1 - github.com/schollz/peerdiscovery v1.4.0 + github.com/schollz/peerdiscovery v1.4.1 github.com/schollz/progressbar/v2 v2.13.2 github.com/schollz/spinner v0.0.0-20180925172146-6bbc5f7804f9 github.com/spaolacci/murmur3 v1.1.0 // indirect - github.com/stretchr/testify v1.3.0 - github.com/urfave/cli v1.20.0 - golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 - golang.org/x/net v0.0.0-20190628185345-da137c7871d7 // indirect - golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 // indirect + github.com/stretchr/testify v1.4.0 + github.com/urfave/cli v1.21.0 + golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 + golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect golang.org/x/text v0.3.2 // indirect + gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect ) diff --git a/go.sum b/go.sum index 57097ae9..f1b3c33b 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,4 @@ +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/OneOfOne/xxhash v1.2.5 h1:zl/OfRA6nftbBK9qTohYBJ5xvw6C/oNKizR7cZGl3cI= @@ -11,11 +12,17 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/kalafut/imohash v1.0.0 h1:LgCJ+p/BwM2HKpOxFopkeddpzVCfm15EtXMroXD1SYE= github.com/kalafut/imohash v1.0.0/go.mod h1:c3RHT80ZAp5C/aYgQI92ZlrOymqkZnRDprU87kg75HI= +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mitchellh/colorstring v0.0.0-20150917214807-8631ce90f286/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= +github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg= +github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2EmQ4l5rM/4FEfDWcRD+abF5XlKShorW5LRoQ= github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= @@ -28,9 +35,8 @@ github.com/schollz/mnemonicode v1.0.1 h1:LiH5hwADZwjwnfXsaD4xgnMyTAtaKHN+e5AyjRU github.com/schollz/mnemonicode v1.0.1/go.mod h1:cl4UAOhUV0mkdjMj/QYaUZbZZdF8BnOqoz8rHMzwboY= github.com/schollz/pake v1.1.1 h1:QKeojDWzdAdtRC4m89b6HAxw/8gjqrVu7r4SAOxOFg8= github.com/schollz/pake v1.1.1/go.mod h1:aWMxQ1jwqZRwk3StflHcdyzPR+CyW5W7+WIZD6Y3dEY= -github.com/schollz/peerdiscovery v1.4.0 h1:wJWiJUBSMY2io9eIG1+gauXm8WD6sJVN5M+pLd4fYZQ= -github.com/schollz/peerdiscovery v1.4.0/go.mod h1:DXj/7VvxAkUuSZNabx3q8t524uWbrhMPxeX151kvvHs= -github.com/schollz/progressbar/v2 v2.9.1/go.mod h1:l6tn6yU6ZdQoF8lwX/VoAUQ3FjhCbrcZDnl9xeWZzYw= +github.com/schollz/peerdiscovery v1.4.1 h1:xtZ/D8/4eq9O6UEhRupZZiJm4BA8+u1IVUgeHo5VPm4= +github.com/schollz/peerdiscovery v1.4.1/go.mod h1:WDdk0/JVyVHVIA/bmhzTkUg32dhJ20O4tExNqV1u6sk= github.com/schollz/progressbar/v2 v2.13.2 h1:3L9bP5KQOGEnFP8P5V8dz+U0yo5I29iY5Oa9s9EAwn0= github.com/schollz/progressbar/v2 v2.13.2/go.mod h1:6YZjqdthH6SCZKv2rqGryrxPtfmRB/DWZxSMfCXPyD8= github.com/schollz/spinner v0.0.0-20180925172146-6bbc5f7804f9 h1:y08o5oQ/slxXE/F0uh5dd8mdVvb+w4NLcNSDSq4c2F0= @@ -40,31 +46,40 @@ github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasO github.com/spaolacci/murmur3 v1.1.0 h1:7c1g84S4BPRrfL5Xrdp6fOJ206sU9y293DDHaoy0bLI= github.com/spaolacci/murmur3 v1.1.0/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/tscholl2/siec v0.0.0-20180721101609-21667da05937 h1:lhssCpSe3TjKcbvUoPzFMuv9oUyZDgI3Cmgolfw2C90= github.com/tscholl2/siec v0.0.0-20180721101609-21667da05937/go.mod h1:KL9+ubr1JZdaKjgAaHr+tCytEncXBa1pR6FjbTsOJnw= -github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw= -github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= +github.com/urfave/cli v1.21.0 h1:wYSSj06510qPIzGSua9ZqsncMmWE3Zr55KBERygyrxE= +github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVUZZQ= 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/net v0.0.0-20190206173232-65e2d4e15006/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 h1:7KByu05hhLed2MO29w7p1XfZvZ13m8mub3shuVftRs0= +golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU= -golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA= +golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7 h1:LepdCS8Gf/MVejFIt8lsiexZATdoGVyp5bcyS+rYoUI= -golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= +golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/tylerb/is.v1 v1.1.2 h1:AB/MANFml2ySf+adwcinvajyHvsYltAOD+rb/8njfSU= gopkg.in/tylerb/is.v1 v1.1.2/go.mod h1:9yQB2tyIhZ5oph6Kk5Sq7cJMd9c5Jpa1p3hr9kxzPqo= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= From 4150feddf0931b78060097515756a6123eda3422 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 27 Aug 2019 09:51:37 -0700 Subject: [PATCH 02/18] skip checking each file each time --- src/croc/croc.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/croc/croc.go b/src/croc/croc.go index 18014cef..957d2205 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -72,6 +72,7 @@ type Client struct { // send / receive information of all files FilesToTransfer []FileInfo FilesToTransferCurrentNum int + FilesHasFinished map[int]struct{} // send / receive information of current file CurrentFile *os.File @@ -121,6 +122,7 @@ type SenderInfo struct { // New establishes a new connection for transfering files between two instances. func New(ops Options) (c *Client, err error) { c = new(Client) + c.FilesHasFinished = make(map[int]struct{}) // setup basic info c.Options = ops @@ -667,6 +669,9 @@ func (c *Client) updateState() (err error) { finished := true for i, fileInfo := range c.FilesToTransfer { + if _, ok := c.FilesHasFinished[i]; ok { + continue + } log.Debugf("checking %+v", fileInfo) if i < c.FilesToTransferCurrentNum { continue @@ -733,6 +738,7 @@ func (c *Client) updateState() (err error) { panic(err) } c.SuccessfulTransfer = true + c.FilesHasFinished[c.FilesToTransferCurrentNum] = struct{}{} } // start initiating the process to receive a new file From de7a29470bc3dc6f399d21d72adee73018d670d8 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 27 Aug 2019 17:11:58 -0700 Subject: [PATCH 03/18] bump 6.1.2 --- README.md | 2 +- src/cli/cli.go | 2 +- src/install/default.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5ecea591..edb09b43 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ src="https://user-images.githubusercontent.com/6550035/46709024-9b23ad00-cbf6-11e8-9fb2-ca8b20b7dbec.jpg" width="408px" border="0" alt="croc">
-Version +Version Build
 Status diff --git a/src/cli/cli.go b/src/cli/cli.go index fd32351b..5fa0a8fa 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -30,7 +30,7 @@ func Run() (err error) { app := cli.NewApp() app.Name = "croc" if Version == "" { - Version = "v6.1.1-82f2c8c" + Version = "v6.1.2-4150fed" } app.Version = Version app.Compiled = time.Now() diff --git a/src/install/default.txt b/src/install/default.txt index d9d045b1..f483a4d2 100644 --- a/src/install/default.txt +++ b/src/install/default.txt @@ -33,7 +33,7 @@ install_croc() croc_os="unsupported" croc_arch="unknown" croc_arm="" - croc_version="6.1.1" + croc_version="6.1.2" # Termux on Android has $PREFIX set which already ends with /usr From fb658ccde21d96c75583f482a46c79f1455fe9f0 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Wed, 4 Sep 2019 09:00:29 -0700 Subject: [PATCH 04/18] update deps --- go.mod | 5 +++-- go.sum | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 257f815f..95beac76 100644 --- a/go.mod +++ b/go.mod @@ -20,8 +20,9 @@ require ( github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/stretchr/testify v1.4.0 github.com/urfave/cli v1.21.0 - golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586 - golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect + golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 + golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect + golang.org/x/sys v0.0.0-20190904005037-43c01164e931 // indirect golang.org/x/text v0.3.2 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect ) diff --git a/go.sum b/go.sum index f1b3c33b..0280c454 100644 --- a/go.sum +++ b/go.sum @@ -57,13 +57,13 @@ github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVU 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/crypto v0.0.0-20190820162420-60c769a6c586 h1:7KByu05hhLed2MO29w7p1XfZvZ13m8mub3shuVftRs0= -golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM= +golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 h1:fHDIZ2oxGnUZRN6WgWFCbYBjH9uqVPRCUVUDhs0wnbA= -golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM= +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI= @@ -71,6 +71,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904005037-43c01164e931 h1:+WYfosiOJzB4BjsISl1Rv4ZLUy+VYcF+u+0Y9jcerv8= +golang.org/x/sys v0.0.0-20190904005037-43c01164e931/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= From bc6803eeefe1bd5995137ee0c5123ea35a5b437c Mon Sep 17 00:00:00 2001 From: Zack Date: Sat, 7 Sep 2019 07:34:05 -0700 Subject: [PATCH 05/18] use single reader (#155) * dunno * close file after finished * fix debugging statements * use single reader * update deps --- go.mod | 6 ++--- go.sum | 8 +++---- src/croc/croc.go | 53 ++++++++++++++++++++++++++----------------- src/croc/croc_test.go | 1 + 4 files changed, 40 insertions(+), 28 deletions(-) diff --git a/go.mod b/go.mod index 95beac76..f7f56a33 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/schollz/croc/v6 -go 1.12 +go 1.13 require ( github.com/OneOfOne/xxhash v1.2.5 // indirect @@ -20,9 +20,9 @@ require ( github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/stretchr/testify v1.4.0 github.com/urfave/cli v1.21.0 - golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 + golang.org/x/crypto v0.0.0-20190907121410-71b5226ff739 golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 // indirect - golang.org/x/sys v0.0.0-20190904005037-43c01164e931 // indirect + golang.org/x/sys v0.0.0-20190904154756-749cb33beabd // indirect golang.org/x/text v0.3.2 // indirect gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect ) diff --git a/go.sum b/go.sum index 0280c454..d2d8b370 100644 --- a/go.sum +++ b/go.sum @@ -57,8 +57,8 @@ github.com/urfave/cli v1.21.0/go.mod h1:lxDj6qX9Q6lWQxIrbrT0nwecwUtRnhVZAJjJZrVU 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/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM= -golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190907121410-71b5226ff739 h1:Gc7JIyxvWgD6m+QmVryY0MstDORNYididDGxgZ6Tnpk= +golang.org/x/crypto v0.0.0-20190907121410-71b5226ff739/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= @@ -71,8 +71,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20190801041406-cbf593c0f2f3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ= golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190904005037-43c01164e931 h1:+WYfosiOJzB4BjsISl1Rv4ZLUy+VYcF+u+0Y9jcerv8= -golang.org/x/sys v0.0.0-20190904005037-43c01164e931/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd h1:DBH9mDw0zluJT/R+nGuV3jWFWLFaHyYZWD4tOT+cjn0= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 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/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= diff --git a/src/croc/croc.go b/src/croc/croc.go index 957d2205..806c2cae 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -90,8 +90,10 @@ type Client struct { spinner *spinner.Spinner firstSend bool - mutex *sync.Mutex - quit chan bool + mutex *sync.Mutex + fread *os.File + numfinished int + quit chan bool } type Chunk struct { @@ -843,6 +845,16 @@ func (c *Client) updateState() (err error) { c.setBar() c.TotalSent = 0 log.Debug("beginning sending comms") + pathToFile := path.Join( + c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderSource, + c.FilesToTransfer[c.FilesToTransferCurrentNum].Name, + ) + + c.fread, err = os.Open(pathToFile) + c.numfinished = 0 + if err != nil { + return + } for i := 0; i < len(c.Options.RelayPorts); i++ { log.Debugf("starting sending over comm %d", i) go c.sendData(i) @@ -881,6 +893,7 @@ func (c *Client) setBar() { } func (c *Client) receiveData(i int) { + log.Debugf("%d receiving data", i) for { data, err := c.conn[i+1].Receive() if err != nil { @@ -938,30 +951,23 @@ func (c *Client) receiveData(i int) { func (c *Client) sendData(i int) { defer func() { log.Debugf("finished with %d", i) + c.numfinished++ + if c.numfinished == len(c.Options.RelayPorts) { + log.Debug("closing file") + c.fread.Close() + } }() - pathToFile := path.Join( - c.FilesToTransfer[c.FilesToTransferCurrentNum].FolderSource, - c.FilesToTransfer[c.FilesToTransferCurrentNum].Name, - ) - log.Debugf("opening %s to read", pathToFile) - f, err := os.Open(pathToFile) - if err != nil { - panic(err) - } - defer f.Close() + var readingPos int64 pos := uint64(0) curi := float64(0) for { // Read file data := make([]byte, models.TCP_BUFFER_SIZE/2) - n, err := f.Read(data) - if err != nil { - if err == io.EOF { - break - } - panic(err) - } + // log.Debugf("%d trying to read", i) + n, errRead := c.fread.ReadAt(data, readingPos) + // log.Debugf("%d read %d bytes", i, n) + readingPos += int64(n) if math.Mod(curi, float64(len(c.Options.RelayPorts))) == float64(i) { // check to see if this is a chunk that the recipient wants @@ -1003,8 +1009,13 @@ func (c *Client) sendData(i int) { curi++ pos += uint64(n) - } - time.Sleep(10 * time.Second) + if errRead != nil { + if errRead == io.EOF { + break + } + panic(errRead) + } + } return } diff --git a/src/croc/croc_test.go b/src/croc/croc_test.go index 51563a6a..b66d9974 100644 --- a/src/croc/croc_test.go +++ b/src/croc/croc_test.go @@ -11,6 +11,7 @@ import ( ) func TestCroc(t *testing.T) { + log.SetLevel("trace") defer os.Remove("README.md") go tcp.Run("debug", "8081", "8082,8083,8084,8085") go tcp.Run("debug", "8082") From 9a70ea90d195581c4de9fe9e1f2673647c5aa769 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sat, 7 Sep 2019 07:41:03 -0700 Subject: [PATCH 06/18] bump 6.1.3 --- README.md | 2 +- src/cli/cli.go | 2 +- src/install/default.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index edb09b43..1150dc32 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ src="https://user-images.githubusercontent.com/6550035/46709024-9b23ad00-cbf6-11e8-9fb2-ca8b20b7dbec.jpg" width="408px" border="0" alt="croc">
-Version +Version Build
 Status diff --git a/src/cli/cli.go b/src/cli/cli.go index 5fa0a8fa..2b88dc4e 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -30,7 +30,7 @@ func Run() (err error) { app := cli.NewApp() app.Name = "croc" if Version == "" { - Version = "v6.1.2-4150fed" + Version = "v6.1.3-bc6803e" } app.Version = Version app.Compiled = time.Now() diff --git a/src/install/default.txt b/src/install/default.txt index f483a4d2..d32cb27a 100644 --- a/src/install/default.txt +++ b/src/install/default.txt @@ -33,7 +33,7 @@ install_croc() croc_os="unsupported" croc_arch="unknown" croc_arm="" - croc_version="6.1.2" + croc_version="6.1.3" # Termux on Android has $PREFIX set which already ends with /usr From 175b9a3f765dc5e5611835cd9414e75fb23b2b83 Mon Sep 17 00:00:00 2001 From: Zack Date: Sat, 7 Sep 2019 08:18:21 -0700 Subject: [PATCH 07/18] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1150dc32..06c6fbaf 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ Status"> - enables easy **cross-platform** transfers (Windows, Linux, Mac) - allows **multiple file** transfers - allows **resuming transfers** that are interrupted -- does *not* require a server or port-forwarding +- local server or port-forwarding **not needed** +- **faster** than [wormhole](https://github.com/warner/magic-wormhole), [rsync](https://linux.die.net/man/1/rsync), [scp](https://linux.die.net/man/1/scp) through compression and multiplexing (speedups 1.5x to 4x) For more information about `croc`, see [my blog post](https://schollz.com/software/croc6). From 0277abe5d4b1d3e573afefd3e52aed04606742ee Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sat, 7 Sep 2019 09:41:24 -0700 Subject: [PATCH 08/18] gofmt -s -w --- src/crypt/crypt_test.go | 7 +++---- src/message/message.go | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/crypt/crypt_test.go b/src/crypt/crypt_test.go index f4fc6b93..14ac6397 100644 --- a/src/crypt/crypt_test.go +++ b/src/crypt/crypt_test.go @@ -45,11 +45,10 @@ func TestEncryption(t *testing.T) { } - func TestNoEncryption(t *testing.T) { bob, err := New(nil, nil) assert.Nil(t, err) - jane, err := New(nil,nil) + jane, err := New(nil, nil) assert.Nil(t, err) enc, err := bob.Encrypt([]byte("hello, world")) assert.Nil(t, err) @@ -57,5 +56,5 @@ func TestNoEncryption(t *testing.T) { assert.Nil(t, err) assert.Equal(t, dec, []byte("hello, world")) assert.Equal(t, enc, []byte("hello, world")) - -} \ No newline at end of file + +} diff --git a/src/message/message.go b/src/message/message.go index 100456d8..2f0abb6c 100644 --- a/src/message/message.go +++ b/src/message/message.go @@ -3,10 +3,10 @@ package message import ( "encoding/json" - log "github.com/schollz/logger" "github.com/schollz/croc/v6/src/comm" "github.com/schollz/croc/v6/src/compress" "github.com/schollz/croc/v6/src/crypt" + log "github.com/schollz/logger" ) // Message is the possible payload for messaging From 31c1a37b387847a506389addfe09f0fb13c1eccd Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sat, 7 Sep 2019 09:46:04 -0700 Subject: [PATCH 09/18] 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 { From 33aa006c26e202585a394d40823d395a52e01406 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sat, 7 Sep 2019 09:49:08 -0700 Subject: [PATCH 10/18] fix spelling --- src/cli/cli.go | 2 +- src/croc/croc.go | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cli/cli.go b/src/cli/cli.go index 3ccfde3c..f69d4015 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -103,7 +103,7 @@ func getConfigDir() (homedir string, err error) { return } homedir = path.Join(homedir, ".config", "croc") - if _, err := os.Stat(homedir); os.IsNotExist(err) { + if _, err = os.Stat(homedir); os.IsNotExist(err) { log.Debugf("creating home directory %s", homedir) err = os.MkdirAll(homedir, 0700) } diff --git a/src/croc/croc.go b/src/croc/croc.go index 4fdc1aa5..9ad1ab3c 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -124,12 +124,12 @@ type RemoteFileRequest struct { FilesToTransferCurrentNum int } -// SenderInfo lists the files to be transfered +// SenderInfo lists the files to be transferred type SenderInfo struct { FilesToTransfer []FileInfo } -// New establishes a new connection for transfering files between two instances. +// New establishes a new connection for transferring files between two instances. func New(ops Options) (c *Client, err error) { c = new(Client) c.FilesHasFinished = make(map[int]struct{}) @@ -461,7 +461,7 @@ func (c *Client) transfer(options TransferOptions) (err error) { break } } - // purge errors that come from succesful transfer + // purge errors that come from successful transfer if c.SuccessfulTransfer { if err != nil { log.Debugf("purging error: %s", err) @@ -765,7 +765,7 @@ func (c *Client) updateState() (err error) { c.CurrentFile, errOpen = os.OpenFile( pathToFile, os.O_WRONLY, 0666) - truncate := false + var truncate bool // default false c.CurrentFileChunks = []int64{} c.CurrentFileChunkRanges = []int64{} if errOpen == nil { @@ -826,7 +826,7 @@ func (c *Client) updateState() (err error) { if !c.firstSend { fmt.Fprintf(os.Stderr, "\nSending (->%s)\n", c.ExternalIPConnected) c.firstSend = true - // if there are empty files, show them as already have been transfered now + // if there are empty files, show them as already have been transferred now for i := range c.FilesToTransfer { if c.FilesToTransfer[i].Size == 0 { // setup the progressbar and takedown the progress bar for empty files From a82dd2f284866fb223aae17a5587b988a62d569b Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sat, 7 Sep 2019 10:06:41 -0700 Subject: [PATCH 11/18] improve tests --- src/comm/comm_test.go | 5 +-- src/compress/compress_test.go | 7 +++++ src/croc/croc_test.go | 58 +++++++++++++++++++++++++++++++++++ src/tcp/tcp_test.go | 10 +++--- 4 files changed, 73 insertions(+), 7 deletions(-) diff --git a/src/comm/comm_test.go b/src/comm/comm_test.go index e213146d..9912f8c6 100644 --- a/src/comm/comm_test.go +++ b/src/comm/comm_test.go @@ -47,7 +47,7 @@ func TestComm(t *testing.T) { }() time.Sleep(300 * time.Millisecond) - a, err := NewConnection("localhost:" + port) + a, err := NewConnection("localhost:"+port, 10*time.Minute) assert.Nil(t, err) data, err := a.Receive() assert.Equal(t, []byte("hello, world"), data) @@ -56,5 +56,6 @@ func TestComm(t *testing.T) { assert.Nil(t, a.Send([]byte{'\x00'})) assert.Nil(t, a.Send(token)) - + _ = a.Connection() + a.Close() } diff --git a/src/compress/compress_test.go b/src/compress/compress_test.go index b8682ff6..e48ed92f 100644 --- a/src/compress/compress_test.go +++ b/src/compress/compress_test.go @@ -70,12 +70,18 @@ func TestCompress(t *testing.T) { dataRateSavings := 100 * (1.0 - float64(len(compressedB))/float64(len(fable))) fmt.Printf("Level 9: %2.0f%% percent space savings\n", dataRateSavings) assert.True(t, len(compressedB) < len(fable)) + assert.Equal(t, fable, Decompress(compressedB)) compressedB = CompressWithOption(fable, -2) dataRateSavings = 100 * (1.0 - float64(len(compressedB))/float64(len(fable))) fmt.Printf("Level -2: %2.0f%% percent space savings\n", dataRateSavings) assert.True(t, len(compressedB) < len(fable)) + compressedB = Compress(fable) + dataRateSavings = 100 * (1.0 - float64(len(compressedB))/float64(len(fable))) + fmt.Printf("Level -2: %2.0f%% percent space savings\n", dataRateSavings) + assert.True(t, len(compressedB) < len(fable)) + data := make([]byte, 4096) rand.Read(data) compressedB = CompressWithOption(data, -2) @@ -85,6 +91,7 @@ func TestCompress(t *testing.T) { rand.Read(data) compressedB = CompressWithOption(data, 9) dataRateSavings = 100 * (1.0 - float64(len(compressedB))/float64(len(data))) + fmt.Printf("random, Level 9: %2.0f%% percent space savings\n", dataRateSavings) } diff --git a/src/croc/croc_test.go b/src/croc/croc_test.go index b66d9974..8ecee42a 100644 --- a/src/croc/croc_test.go +++ b/src/croc/croc_test.go @@ -65,3 +65,61 @@ func TestCroc(t *testing.T) { wg.Wait() } + +func TestCrocLocal(t *testing.T) { + log.SetLevel("trace") + defer os.Remove("README.md") + // go tcp.Run("debug", "8081", "8082,8083,8084,8085") + // go tcp.Run("debug", "8082") + // go tcp.Run("debug", "8083") + // go tcp.Run("debug", "8084") + // go tcp.Run("debug", "8085") + time.Sleep(300 * time.Millisecond) + + log.Debug("setting up sender") + sender, err := New(Options{ + IsSender: true, + SharedSecret: "test", + Debug: true, + RelayAddress: "localhost:8181", + RelayPorts: []string{"8181", "8182"}, + Stdout: false, + NoPrompt: true, + DisableLocal: false, + }) + if err != nil { + panic(err) + } + time.Sleep(1 * time.Second) + + log.Debug("setting up receiver") + receiver, err := New(Options{ + IsSender: false, + SharedSecret: "test", + Debug: true, + RelayAddress: "localhost:8181", + Stdout: false, + NoPrompt: true, + DisableLocal: false, + }) + if err != nil { + panic(err) + } + + var wg sync.WaitGroup + wg.Add(2) + go func() { + sender.Send(TransferOptions{ + PathToFiles: []string{"../../README.md"}, + KeepPathInRemote: true, + }) + wg.Done() + }() + time.Sleep(100 * time.Millisecond) + go func() { + receiver.Receive() + wg.Done() + }() + + wg.Wait() +} diff --git a/src/tcp/tcp_test.go b/src/tcp/tcp_test.go index 46bcee1f..ea628f5b 100644 --- a/src/tcp/tcp_test.go +++ b/src/tcp/tcp_test.go @@ -8,14 +8,14 @@ import ( ) func TestTCP(t *testing.T) { - go Run("debug", "8081", "8082") + go Run("debug", "8281", "8282") time.Sleep(100 * time.Millisecond) - c1, banner, _, err := ConnectToTCPServer("localhost:8081", "testRoom") - assert.Equal(t, banner, "8082") + c1, banner, _, err := ConnectToTCPServer("localhost:8281", "testRoom") + assert.Equal(t, banner, "8282") assert.Nil(t, err) - c2, _, _, err := ConnectToTCPServer("localhost:8081", "testRoom") + c2, _, _, err := ConnectToTCPServer("localhost:8281", "testRoom") assert.Nil(t, err) - _, _, _, err = ConnectToTCPServer("localhost:8081", "testRoom") + _, _, _, err = ConnectToTCPServer("localhost:8281", "testRoom") assert.NotNil(t, err) // try sending data From 22f6a13a9fa28fdf2da95b11e1f94dd0c0b55352 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sat, 7 Sep 2019 10:31:18 -0700 Subject: [PATCH 12/18] add more tests --- go.sum | 1 + src/comm/comm_test.go | 4 +++ src/croc/croc_test.go | 17 +++++------- src/message/message_test.go | 52 +++++++++++++++++++++++++++++++++++++ src/utils/utils_test.go | 40 ++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 10 deletions(-) diff --git a/go.sum b/go.sum index d2d8b370..5c33b6c1 100644 --- a/go.sum +++ b/go.sum @@ -77,6 +77,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/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e h1:FDhOuMEY4JVRztM/gsbk+IKUQ8kj74bxZrgw87eMMVc= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= diff --git a/src/comm/comm_test.go b/src/comm/comm_test.go index 9912f8c6..6f986f4c 100644 --- a/src/comm/comm_test.go +++ b/src/comm/comm_test.go @@ -58,4 +58,8 @@ func TestComm(t *testing.T) { assert.Nil(t, a.Send(token)) _ = a.Connection() a.Close() + assert.NotNil(t, a.Send(token)) + _, err = a.Write(token) + assert.NotNil(t, err) + } diff --git a/src/croc/croc_test.go b/src/croc/croc_test.go index 8ecee42a..5bd9de61 100644 --- a/src/croc/croc_test.go +++ b/src/croc/croc_test.go @@ -68,12 +68,8 @@ func TestCroc(t *testing.T) { func TestCrocLocal(t *testing.T) { log.SetLevel("trace") - defer os.Remove("README.md") - // go tcp.Run("debug", "8081", "8082,8083,8084,8085") - // go tcp.Run("debug", "8082") - // go tcp.Run("debug", "8083") - // go tcp.Run("debug", "8084") - // go tcp.Run("debug", "8085") + defer os.Remove("LICENSE") + defer os.Remove("touched") time.Sleep(300 * time.Millisecond) log.Debug("setting up sender") @@ -83,7 +79,7 @@ func TestCrocLocal(t *testing.T) { Debug: true, RelayAddress: "localhost:8181", RelayPorts: []string{"8181", "8182"}, - Stdout: false, + Stdout: true, NoPrompt: true, DisableLocal: false, }) @@ -98,7 +94,7 @@ func TestCrocLocal(t *testing.T) { SharedSecret: "test", Debug: true, RelayAddress: "localhost:8181", - Stdout: false, + Stdout: true, NoPrompt: true, DisableLocal: false, }) @@ -107,11 +103,12 @@ func TestCrocLocal(t *testing.T) { } var wg sync.WaitGroup + os.Create("touched") wg.Add(2) go func() { sender.Send(TransferOptions{ - PathToFiles: []string{"../../README.md"}, - KeepPathInRemote: true, + PathToFiles: []string{"../../LICENSE", "touched"}, + KeepPathInRemote: false, }) wg.Done() }() diff --git a/src/message/message_test.go b/src/message/message_test.go index 861500cc..cc4772d6 100644 --- a/src/message/message_test.go +++ b/src/message/message_test.go @@ -1,10 +1,15 @@ package message import ( + "crypto/rand" "fmt" + "net" "testing" + "time" + "github.com/schollz/croc/v6/src/comm" "github.com/schollz/croc/v6/src/crypt" + log "github.com/schollz/logger" "github.com/stretchr/testify/assert" ) @@ -20,4 +25,51 @@ func TestMessage(t *testing.T) { m2, err := Decode(e, b) assert.Nil(t, err) assert.Equal(t, m, m2) + assert.Equal(t, `{"t":"message","m":"hello, world"}`, m.String()) +} + +func TestSend(t *testing.T) { + token := make([]byte, 40000000) + rand.Read(token) + + port := "8801" + go func() { + log.Debugf("starting TCP server on " + port) + server, err := net.Listen("tcp", "0.0.0.0:"+port) + if err != nil { + log.Error(err) + } + defer server.Close() + // spawn a new goroutine whenever a client connects + for { + connection, err := server.Accept() + if err != nil { + log.Error(err) + } + log.Debugf("client %s connected", connection.RemoteAddr().String()) + go func(port string, connection net.Conn) { + c := comm.New(connection) + err = c.Send([]byte("hello, world")) + assert.Nil(t, err) + data, err := c.Receive() + assert.Nil(t, err) + assert.Equal(t, []byte("hello, computer"), data) + data, err = c.Receive() + assert.Nil(t, err) + assert.Equal(t, []byte{'\x00'}, data) + data, err = c.Receive() + assert.Nil(t, err) + assert.Equal(t, token, data) + }(port, connection) + } + }() + + time.Sleep(300 * time.Millisecond) + a, err := comm.NewConnection("localhost:"+port, 10*time.Minute) + assert.Nil(t, err) + m := Message{Type: "message", Message: "hello, world"} + e, err := crypt.New(nil, nil) + assert.Nil(t, err) + + assert.Nil(t, Send(a, e, m)) } diff --git a/src/utils/utils_test.go b/src/utils/utils_test.go index e23a419e..baf266d7 100644 --- a/src/utils/utils_test.go +++ b/src/utils/utils_test.go @@ -3,8 +3,10 @@ package utils import ( "fmt" "io/ioutil" + "log" "math/rand" "os" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -112,3 +114,41 @@ func TestMissingChunks(t *testing.T) { // fmt.Println(ChunkRangesToChunks((chunkRanges))) // assert.Nil(t, nil) // } + +func TestHashFile(t *testing.T) { + content := []byte("temporary file's content") + tmpfile, err := ioutil.TempFile("", "example") + if err != nil { + log.Fatal(err) + } + + defer os.Remove(tmpfile.Name()) // clean up + + if _, err := tmpfile.Write(content); err != nil { + panic(err) + } + if err := tmpfile.Close(); err != nil { + panic(err) + } + hashed, err := HashFile(tmpfile.Name()) + assert.Nil(t, err) + assert.Equal(t, "18c9673a4bb8325d323e7f24fda9ae1e", fmt.Sprintf("%x", hashed)) +} + +func TestPublicIP(t *testing.T) { + ip, err := PublicIP() + fmt.Println(ip) + assert.True(t, strings.Contains(ip, ".")) + assert.Nil(t, err) +} + +func TestLocalIP(t *testing.T) { + ip := LocalIP() + fmt.Println(ip) + assert.True(t, strings.Contains(ip, ".")) +} + +func TestGetRandomName(t *testing.T) { + name := GetRandomName() + assert.NotEmpty(t, name) +} From 6287a7b7f7283c9bda527cdde3a816c47c4a256f Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sat, 7 Sep 2019 10:40:30 -0700 Subject: [PATCH 13/18] add coveralls link --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 06c6fbaf..f4b5ecad 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ width="408px" border="0" alt="croc">
Version +Coverage Build
 Status From f89dd01e8704926c6a751e90eec1991075b5ddc6 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 8 Sep 2019 05:53:30 -0700 Subject: [PATCH 14/18] add more tests --- src/croc/croc.go | 2 +- src/croc/croc_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/croc/croc.go b/src/croc/croc.go index 9ad1ab3c..ab15e78d 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -300,7 +300,7 @@ func (c *Client) Send(options TransferOptions) (err error) { go func() { log.Debugf("establishing connection to %s", c.Options.RelayAddress) var banner string - conn, banner, ipaddr, err := tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.SharedSecret) + conn, banner, ipaddr, err := tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.SharedSecret, 5*time.Second) log.Debugf("banner: %s", banner) if err != nil { err = errors.Wrap(err, fmt.Sprintf("could not connect to %s", c.Options.RelayAddress)) diff --git a/src/croc/croc_test.go b/src/croc/croc_test.go index 5bd9de61..823fd1bd 100644 --- a/src/croc/croc_test.go +++ b/src/croc/croc_test.go @@ -1,6 +1,7 @@ package croc import ( + "io/ioutil" "os" "sync" "testing" @@ -8,6 +9,7 @@ import ( "github.com/schollz/croc/v6/src/tcp" log "github.com/schollz/logger" + "github.com/stretchr/testify/assert" ) func TestCroc(t *testing.T) { @@ -120,3 +122,40 @@ func TestCrocLocal(t *testing.T) { wg.Wait() } + +func TestCrocError(t *testing.T) { + content := []byte("temporary file's content") + tmpfile, err := ioutil.TempFile("", "example") + if err != nil { + panic(err) + } + + defer os.Remove(tmpfile.Name()) // clean up + + if _, err := tmpfile.Write(content); err != nil { + panic(err) + } + if err := tmpfile.Close(); err != nil { + panic(err) + } + + Debug(false) + log.SetLevel("warn") + sender, _ := New(Options{ + IsSender: true, + SharedSecret: "test", + Debug: true, + RelayAddress: "doesntexistok.com:8181", + RelayPorts: []string{"8181", "8182"}, + Stdout: true, + NoPrompt: true, + DisableLocal: true, + }) + err = sender.Send(TransferOptions{ + PathToFiles: []string{tmpfile.Name()}, + KeepPathInRemote: true, + }) + log.Debug(err) + assert.NotNil(t, err) + +} From b979607c42a5914da2fbc57c70c560e419e64a8e Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 8 Sep 2019 05:56:57 -0700 Subject: [PATCH 15/18] fix --- src/croc/croc_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/croc/croc_test.go b/src/croc/croc_test.go index 823fd1bd..492a05f4 100644 --- a/src/croc/croc_test.go +++ b/src/croc/croc_test.go @@ -143,10 +143,10 @@ func TestCrocError(t *testing.T) { log.SetLevel("warn") sender, _ := New(Options{ IsSender: true, - SharedSecret: "test", + SharedSecret: "test33", Debug: true, - RelayAddress: "doesntexistok.com:8181", - RelayPorts: []string{"8181", "8182"}, + RelayAddress: "doesntexistok.com:8381", + RelayPorts: []string{"8381", "8382"}, Stdout: true, NoPrompt: true, DisableLocal: true, From cc728a11389a3f7e606b00c7d52170d0c570d32a Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 8 Sep 2019 06:07:53 -0700 Subject: [PATCH 16/18] fix minor bug --- src/utils/utils.go | 10 +++++----- src/utils/utils_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/utils/utils.go b/src/utils/utils.go index 0784f6d3..c4e288e9 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -150,17 +150,17 @@ func ByteCountDecimal(b int64) string { // If file doesn't exist, it returns an empty chunk list (all chunks). // If the file size is not the same as requested, it returns an empty chunk list (all chunks). func MissingChunks(fname string, fsize int64, chunkSize int) (chunkRanges []int64) { - fstat, err := os.Stat(fname) - if fstat.Size() != fsize || err != nil { - return - } - f, err := os.Open(fname) if err != nil { return } defer f.Close() + fstat, err := os.Stat(fname) + if fstat.Size() != fsize || err != nil { + return + } + emptyBuffer := make([]byte, chunkSize) chunkNum := 0 chunks := make([]int64, int64(math.Ceil(float64(fsize)/float64(chunkSize)))) diff --git a/src/utils/utils_test.go b/src/utils/utils_test.go index baf266d7..1e4ac707 100644 --- a/src/utils/utils_test.go +++ b/src/utils/utils_test.go @@ -56,6 +56,8 @@ func TestMD5HashFile(t *testing.T) { b, err := MD5HashFile("bigfile.test") assert.Nil(t, err) assert.Equal(t, "9fed05acbacbc6a36555c998501c21f6", fmt.Sprintf("%x", b)) + _, err = MD5HashFile("bigfile.test.nofile") + assert.NotNil(t, err) } func TestIMOHashFile(t *testing.T) { @@ -72,6 +74,8 @@ func TestXXHashFile(t *testing.T) { b, err := XXHashFile("bigfile.test") assert.Nil(t, err) assert.Equal(t, "f2da6ee7e75e8324", fmt.Sprintf("%x", b)) + _, err = XXHashFile("nofile") + assert.NotNil(t, err) } func TestSHA256(t *testing.T) { @@ -80,6 +84,8 @@ func TestSHA256(t *testing.T) { func TestByteCountDecimal(t *testing.T) { assert.Equal(t, "10.0 kB", ByteCountDecimal(10000)) + assert.Equal(t, "50 B", ByteCountDecimal(50)) + assert.Equal(t, "12.4 MB", ByteCountDecimal(12378517)) } func TestMissingChunks(t *testing.T) { @@ -106,6 +112,29 @@ func TestMissingChunks(t *testing.T) { assert.Equal(t, []int64{0, 40, 50, 70, 80, 90}, chunks) os.Remove("missing.test") + + content := []byte("temporary file's content") + tmpfile, err := ioutil.TempFile("", "example") + if err != nil { + log.Fatal(err) + } + + defer os.Remove(tmpfile.Name()) // clean up + + if _, err := tmpfile.Write(content); err != nil { + panic(err) + } + if err := tmpfile.Close(); err != nil { + panic(err) + } + chunkRanges = MissingChunks(tmpfile.Name(), int64(len(content)), chunkSize) + assert.Empty(t, chunkRanges) + chunkRanges = MissingChunks(tmpfile.Name(), int64(len(content)+10), chunkSize) + assert.Empty(t, chunkRanges) + chunkRanges = MissingChunks(tmpfile.Name()+"ok", int64(len(content)), chunkSize) + assert.Empty(t, chunkRanges) + chunks = ChunkRangesToChunks(chunkRanges) + assert.Empty(t, chunks) } // func Test1(t *testing.T) { From 5ad631e7b6e267ac6b21fd727c706131269052bf Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 8 Sep 2019 06:12:16 -0700 Subject: [PATCH 17/18] add more tests --- src/tcp/tcp.go | 4 +++- src/tcp/tcp_test.go | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tcp/tcp.go b/src/tcp/tcp.go index 47cd082e..473ed261 100644 --- a/src/tcp/tcp.go +++ b/src/tcp/tcp.go @@ -33,6 +33,8 @@ type roomMap struct { sync.Mutex } +var timeToRoomDeletion = 10 * time.Minute + // Run starts a tcp listener, run async func Run(debugLevel, port string, banner ...string) (err error) { s := new(server) @@ -53,7 +55,7 @@ func (s *server) start() (err error) { // delete old rooms go func() { for { - time.Sleep(10 * time.Minute) + time.Sleep(timeToRoomDeletion) roomsToDelete := []string{} s.rooms.Lock() for room := range s.rooms.rooms { diff --git a/src/tcp/tcp_test.go b/src/tcp/tcp_test.go index ea628f5b..8c989097 100644 --- a/src/tcp/tcp_test.go +++ b/src/tcp/tcp_test.go @@ -8,15 +8,18 @@ import ( ) func TestTCP(t *testing.T) { + timeToRoomDeletion = 100 * time.Millisecond go Run("debug", "8281", "8282") time.Sleep(100 * time.Millisecond) - c1, banner, _, err := ConnectToTCPServer("localhost:8281", "testRoom") + c1, banner, _, err := ConnectToTCPServer("localhost:8281", "testRoom", 1*time.Minute) assert.Equal(t, banner, "8282") assert.Nil(t, err) c2, _, _, err := ConnectToTCPServer("localhost:8281", "testRoom") assert.Nil(t, err) _, _, _, err = ConnectToTCPServer("localhost:8281", "testRoom") assert.NotNil(t, err) + _, _, _, err = ConnectToTCPServer("localhost:8281", "testRoom", 1*time.Nanosecond) + assert.NotNil(t, err) // try sending data assert.Nil(t, c1.Send([]byte("hello, c2"))) From 24801dfc24ac623080331c02bdb3d1b34c275075 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 8 Sep 2019 06:14:33 -0700 Subject: [PATCH 18/18] coverage improved --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f4b5ecad..a1a12bd9 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ width="408px" border="0" alt="croc">
Version -Coverage +Coverage Build
 Status