mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
use single reader (#155)
* dunno * close file after finished * fix debugging statements * use single reader * update deps
This commit is contained in:
parent
fb658ccde2
commit
bc6803eeef
4 changed files with 40 additions and 28 deletions
6
go.mod
6
go.mod
|
@ -1,6 +1,6 @@
|
||||||
module github.com/schollz/croc/v6
|
module github.com/schollz/croc/v6
|
||||||
|
|
||||||
go 1.12
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/OneOfOne/xxhash v1.2.5 // indirect
|
github.com/OneOfOne/xxhash v1.2.5 // indirect
|
||||||
|
@ -20,9 +20,9 @@ require (
|
||||||
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
github.com/spaolacci/murmur3 v1.1.0 // indirect
|
||||||
github.com/stretchr/testify v1.4.0
|
github.com/stretchr/testify v1.4.0
|
||||||
github.com/urfave/cli v1.21.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/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
|
golang.org/x/text v0.3.2 // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||||
)
|
)
|
||||||
|
|
8
go.sum
8
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-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 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
|
||||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
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-20190907121410-71b5226ff739 h1:Gc7JIyxvWgD6m+QmVryY0MstDORNYididDGxgZ6Tnpk=
|
||||||
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
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 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
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-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-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 h1:aYOabOQFp6Vj6W1F80affTUvO9UxmJRx8K0gsfABByQ=
|
||||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
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-20190904154756-749cb33beabd h1:DBH9mDw0zluJT/R+nGuV3jWFWLFaHyYZWD4tOT+cjn0=
|
||||||
golang.org/x/sys v0.0.0-20190904005037-43c01164e931/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
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 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
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 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||||
|
|
|
@ -90,8 +90,10 @@ type Client struct {
|
||||||
spinner *spinner.Spinner
|
spinner *spinner.Spinner
|
||||||
firstSend bool
|
firstSend bool
|
||||||
|
|
||||||
mutex *sync.Mutex
|
mutex *sync.Mutex
|
||||||
quit chan bool
|
fread *os.File
|
||||||
|
numfinished int
|
||||||
|
quit chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Chunk struct {
|
type Chunk struct {
|
||||||
|
@ -843,6 +845,16 @@ func (c *Client) updateState() (err error) {
|
||||||
c.setBar()
|
c.setBar()
|
||||||
c.TotalSent = 0
|
c.TotalSent = 0
|
||||||
log.Debug("beginning sending comms")
|
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++ {
|
for i := 0; i < len(c.Options.RelayPorts); i++ {
|
||||||
log.Debugf("starting sending over comm %d", i)
|
log.Debugf("starting sending over comm %d", i)
|
||||||
go c.sendData(i)
|
go c.sendData(i)
|
||||||
|
@ -881,6 +893,7 @@ func (c *Client) setBar() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) receiveData(i int) {
|
func (c *Client) receiveData(i int) {
|
||||||
|
log.Debugf("%d receiving data", i)
|
||||||
for {
|
for {
|
||||||
data, err := c.conn[i+1].Receive()
|
data, err := c.conn[i+1].Receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -938,30 +951,23 @@ func (c *Client) receiveData(i int) {
|
||||||
func (c *Client) sendData(i int) {
|
func (c *Client) sendData(i int) {
|
||||||
defer func() {
|
defer func() {
|
||||||
log.Debugf("finished with %d", i)
|
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)
|
pos := uint64(0)
|
||||||
curi := float64(0)
|
curi := float64(0)
|
||||||
for {
|
for {
|
||||||
// Read file
|
// Read file
|
||||||
data := make([]byte, models.TCP_BUFFER_SIZE/2)
|
data := make([]byte, models.TCP_BUFFER_SIZE/2)
|
||||||
n, err := f.Read(data)
|
// log.Debugf("%d trying to read", i)
|
||||||
if err != nil {
|
n, errRead := c.fread.ReadAt(data, readingPos)
|
||||||
if err == io.EOF {
|
// log.Debugf("%d read %d bytes", i, n)
|
||||||
break
|
readingPos += int64(n)
|
||||||
}
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if math.Mod(curi, float64(len(c.Options.RelayPorts))) == float64(i) {
|
if math.Mod(curi, float64(len(c.Options.RelayPorts))) == float64(i) {
|
||||||
// check to see if this is a chunk that the recipient wants
|
// check to see if this is a chunk that the recipient wants
|
||||||
|
@ -1003,8 +1009,13 @@ func (c *Client) sendData(i int) {
|
||||||
|
|
||||||
curi++
|
curi++
|
||||||
pos += uint64(n)
|
pos += uint64(n)
|
||||||
}
|
|
||||||
|
|
||||||
time.Sleep(10 * time.Second)
|
if errRead != nil {
|
||||||
|
if errRead == io.EOF {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
panic(errRead)
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCroc(t *testing.T) {
|
func TestCroc(t *testing.T) {
|
||||||
|
log.SetLevel("trace")
|
||||||
defer os.Remove("README.md")
|
defer os.Remove("README.md")
|
||||||
go tcp.Run("debug", "8081", "8082,8083,8084,8085")
|
go tcp.Run("debug", "8081", "8082,8083,8084,8085")
|
||||||
go tcp.Run("debug", "8082")
|
go tcp.Run("debug", "8082")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue