From 000dfc15bea82601369162c68b2853178d84c593 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Tue, 30 Apr 2019 06:57:45 -0700 Subject: [PATCH] fiX comm --- src/comm/comm.go | 3 ++- src/croc/croc.go | 15 ++++++++++----- src/models/constants.go | 3 +-- src/models/filestats.go | 14 -------------- src/models/initial.go | 7 ------- src/tcp/tcp.go | 4 ++-- 6 files changed, 15 insertions(+), 31 deletions(-) delete mode 100644 src/models/filestats.go delete mode 100644 src/models/initial.go diff --git a/src/comm/comm.go b/src/comm/comm.go index 607f8f6..be44855 100644 --- a/src/comm/comm.go +++ b/src/comm/comm.go @@ -86,7 +86,8 @@ func (c *Comm) Read() (buf []byte, numBytes int, bs []byte, err error) { } numBytes = int(numBytesUint32) for { - tmp := make([]byte, numBytes) + // log.Debugf("bytes: %d/%d",len(buf),numBytes) + tmp := make([]byte, numBytes-len(buf)) n, errRead := c.connection.Read(tmp) if errRead != nil { err = errRead diff --git a/src/croc/croc.go b/src/croc/croc.go index 026c30f..6e420c3 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -23,6 +23,7 @@ import ( "github.com/schollz/croc/v6/src/crypt" "github.com/schollz/croc/v6/src/logger" "github.com/schollz/croc/v6/src/message" + "github.com/schollz/croc/v6/src/models" "github.com/schollz/croc/v6/src/tcp" "github.com/schollz/croc/v6/src/utils" "github.com/schollz/pake" @@ -536,10 +537,13 @@ func (c *Client) updateState() (err error) { func (c *Client) receiveData(i int) { for { + log.Debug("waiting for data") data, err := c.conn[i].Receive() if err != nil { log.Errorf("%s: %s", i, err.Error()) + continue } + data, err = c.Key.Decrypt(data) if err != nil { panic(err) @@ -563,7 +567,7 @@ func (c *Client) receiveData(i int) { } c.bar.Add(len(data[8:])) c.TotalSent += int64(len(data[8:])) - log.Debugf("state: %+v", c.bar.State()) + log.Debugf("block: %+v", positionInt64) if c.TotalSent == c.FilesToTransfer[c.FilesToTransferCurrentNum].Size { log.Debug("finished receiving!") c.CurrentFile.Close() @@ -599,11 +603,11 @@ func (c *Client) sendData(i int) { curi := float64(0) for { // Read file - data := make([]byte, 40000) + data := make([]byte, models.TCP_BUFFER_SIZE/2) n, err := f.Read(data) if err != nil { if err == io.EOF { - return + break } panic(err) } @@ -628,12 +632,13 @@ func (c *Client) sendData(i int) { c.bar.Add(n) c.TotalSent += int64(n) log.Debug(c.TotalSent) - // time.Sleep(10 * time.Millisecond) + time.Sleep(100 * time.Millisecond) } curi++ pos += uint64(n) } - return + time.Sleep(10 * time.Second) + return } diff --git a/src/models/constants.go b/src/models/constants.go index 0c23ef9..7a985c6 100644 --- a/src/models/constants.go +++ b/src/models/constants.go @@ -1,4 +1,3 @@ package models -const WEBSOCKET_BUFFER_SIZE = 1024 * 1024 * 32 -const TCP_BUFFER_SIZE = 1024 * 64 +const TCP_BUFFER_SIZE = 1024 * 640 diff --git a/src/models/filestats.go b/src/models/filestats.go deleted file mode 100644 index 446e831..0000000 --- a/src/models/filestats.go +++ /dev/null @@ -1,14 +0,0 @@ -package models - -import "time" - -// FileStats are the file stats transfered to the other -type FileStats struct { - Name string - Size int64 - ModTime time.Time - IsDir bool - SentName string - IsCompressed bool - IsEncrypted bool -} diff --git a/src/models/initial.go b/src/models/initial.go deleted file mode 100644 index 75b0877..0000000 --- a/src/models/initial.go +++ /dev/null @@ -1,7 +0,0 @@ -package models - -type Initial struct { - CurveType string - IPAddress string - VersionString string -} diff --git a/src/tcp/tcp.go b/src/tcp/tcp.go index e69915f..02be442 100644 --- a/src/tcp/tcp.go +++ b/src/tcp/tcp.go @@ -11,9 +11,9 @@ import ( "github.com/pkg/errors" "github.com/schollz/croc/v6/src/comm" "github.com/schollz/croc/v6/src/logger" + "github.com/schollz/croc/v6/src/models" ) -const TCP_BUFFER_SIZE = 1024 * 64 type server struct { port string @@ -179,7 +179,7 @@ func chanFromConn(conn net.Conn) chan []byte { c := make(chan []byte, 1) go func() { - b := make([]byte, TCP_BUFFER_SIZE) + b := make([]byte, models.TCP_BUFFER_SIZE) for { n, err := conn.Read(b)