This commit is contained in:
Zack Scholl 2019-04-30 06:57:45 -07:00
parent 330e76e09c
commit 000dfc15be
6 changed files with 15 additions and 31 deletions

View File

@ -86,7 +86,8 @@ func (c *Comm) Read() (buf []byte, numBytes int, bs []byte, err error) {
} }
numBytes = int(numBytesUint32) numBytes = int(numBytesUint32)
for { 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) n, errRead := c.connection.Read(tmp)
if errRead != nil { if errRead != nil {
err = errRead err = errRead

View File

@ -23,6 +23,7 @@ import (
"github.com/schollz/croc/v6/src/crypt" "github.com/schollz/croc/v6/src/crypt"
"github.com/schollz/croc/v6/src/logger" "github.com/schollz/croc/v6/src/logger"
"github.com/schollz/croc/v6/src/message" "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/tcp"
"github.com/schollz/croc/v6/src/utils" "github.com/schollz/croc/v6/src/utils"
"github.com/schollz/pake" "github.com/schollz/pake"
@ -536,10 +537,13 @@ func (c *Client) updateState() (err error) {
func (c *Client) receiveData(i int) { func (c *Client) receiveData(i int) {
for { for {
log.Debug("waiting for data")
data, err := c.conn[i].Receive() data, err := c.conn[i].Receive()
if err != nil { if err != nil {
log.Errorf("%s: %s", i, err.Error()) log.Errorf("%s: %s", i, err.Error())
continue
} }
data, err = c.Key.Decrypt(data) data, err = c.Key.Decrypt(data)
if err != nil { if err != nil {
panic(err) panic(err)
@ -563,7 +567,7 @@ func (c *Client) receiveData(i int) {
} }
c.bar.Add(len(data[8:])) c.bar.Add(len(data[8:]))
c.TotalSent += int64(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 { if c.TotalSent == c.FilesToTransfer[c.FilesToTransferCurrentNum].Size {
log.Debug("finished receiving!") log.Debug("finished receiving!")
c.CurrentFile.Close() c.CurrentFile.Close()
@ -599,11 +603,11 @@ func (c *Client) sendData(i int) {
curi := float64(0) curi := float64(0)
for { for {
// Read file // Read file
data := make([]byte, 40000) data := make([]byte, models.TCP_BUFFER_SIZE/2)
n, err := f.Read(data) n, err := f.Read(data)
if err != nil { if err != nil {
if err == io.EOF { if err == io.EOF {
return break
} }
panic(err) panic(err)
} }
@ -628,12 +632,13 @@ func (c *Client) sendData(i int) {
c.bar.Add(n) c.bar.Add(n)
c.TotalSent += int64(n) c.TotalSent += int64(n)
log.Debug(c.TotalSent) log.Debug(c.TotalSent)
// time.Sleep(10 * time.Millisecond) time.Sleep(100 * time.Millisecond)
} }
curi++ curi++
pos += uint64(n) pos += uint64(n)
} }
return
time.Sleep(10 * time.Second)
return
} }

View File

@ -1,4 +1,3 @@
package models package models
const WEBSOCKET_BUFFER_SIZE = 1024 * 1024 * 32 const TCP_BUFFER_SIZE = 1024 * 640
const TCP_BUFFER_SIZE = 1024 * 64

View File

@ -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
}

View File

@ -1,7 +0,0 @@
package models
type Initial struct {
CurveType string
IPAddress string
VersionString string
}

View File

@ -11,9 +11,9 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/schollz/croc/v6/src/comm" "github.com/schollz/croc/v6/src/comm"
"github.com/schollz/croc/v6/src/logger" "github.com/schollz/croc/v6/src/logger"
"github.com/schollz/croc/v6/src/models"
) )
const TCP_BUFFER_SIZE = 1024 * 64
type server struct { type server struct {
port string port string
@ -179,7 +179,7 @@ func chanFromConn(conn net.Conn) chan []byte {
c := make(chan []byte, 1) c := make(chan []byte, 1)
go func() { go func() {
b := make([]byte, TCP_BUFFER_SIZE) b := make([]byte, models.TCP_BUFFER_SIZE)
for { for {
n, err := conn.Read(b) n, err := conn.Read(b)