mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
resume works with websockets or tcp
This commit is contained in:
parent
e18938fb70
commit
c600b51888
2 changed files with 27 additions and 10 deletions
|
@ -160,7 +160,7 @@ func receive(forceSend int, serverAddress string, tcpPorts []string, isLocal boo
|
||||||
overwritingOrReceiving := "Receiving"
|
overwritingOrReceiving := "Receiving"
|
||||||
if utils.Exists(fstats.Name) || utils.Exists(fstats.SentName) {
|
if utils.Exists(fstats.Name) || utils.Exists(fstats.SentName) {
|
||||||
overwritingOrReceiving = "Overwriting"
|
overwritingOrReceiving = "Overwriting"
|
||||||
if utils.Exists(progressFile) && !useWebsockets {
|
if utils.Exists(progressFile) {
|
||||||
overwritingOrReceiving = "Resume receiving"
|
overwritingOrReceiving = "Resume receiving"
|
||||||
resumeFile = true
|
resumeFile = true
|
||||||
}
|
}
|
||||||
|
@ -200,8 +200,12 @@ func receive(forceSend int, serverAddress string, tcpPorts []string, isLocal boo
|
||||||
|
|
||||||
// await file
|
// await file
|
||||||
var f *os.File
|
var f *os.File
|
||||||
if utils.Exists(fstats.SentName) {
|
if utils.Exists(fstats.SentName) && resumeFile {
|
||||||
f, err = os.OpenFile(fstats.SentName, os.O_WRONLY, 0644)
|
if !useWebsockets {
|
||||||
|
f, err = os.OpenFile(fstats.SentName, os.O_WRONLY, 0644)
|
||||||
|
} else {
|
||||||
|
f, err = os.OpenFile(fstats.SentName, os.O_APPEND, 0644)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
return err
|
return err
|
||||||
|
@ -212,9 +216,11 @@ func receive(forceSend int, serverAddress string, tcpPorts []string, isLocal boo
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err = f.Truncate(fstats.Size); err != nil {
|
if !useWebsockets {
|
||||||
log.Error(err)
|
if err = f.Truncate(fstats.Size); err != nil {
|
||||||
return err
|
log.Error(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,6 +260,7 @@ func receive(forceSend int, serverAddress string, tcpPorts []string, isLocal boo
|
||||||
var progressErr error
|
var progressErr error
|
||||||
if resumeFile {
|
if resumeFile {
|
||||||
fProgress, progressErr = os.OpenFile(progressFile, os.O_APPEND, 0644)
|
fProgress, progressErr = os.OpenFile(progressFile, os.O_APPEND, 0644)
|
||||||
|
bytesWritten = len(blocks) * blockSize
|
||||||
} else {
|
} else {
|
||||||
os.Remove(progressFile)
|
os.Remove(progressFile)
|
||||||
fProgress, progressErr = os.Create(progressFile)
|
fProgress, progressErr = os.Create(progressFile)
|
||||||
|
@ -266,7 +273,7 @@ func receive(forceSend int, serverAddress string, tcpPorts []string, isLocal boo
|
||||||
blocksWritten := 0.0
|
blocksWritten := 0.0
|
||||||
blocksToWrite := float64(fstats.Size)
|
blocksToWrite := float64(fstats.Size)
|
||||||
if useWebsockets {
|
if useWebsockets {
|
||||||
blocksToWrite = blocksToWrite / float64(models.WEBSOCKET_BUFFER_SIZE/8)
|
blocksToWrite = blocksToWrite/float64(models.WEBSOCKET_BUFFER_SIZE/8) - float64(len(blocks))
|
||||||
} else {
|
} else {
|
||||||
blocksToWrite = blocksToWrite/float64(models.TCP_BUFFER_SIZE/2) - float64(len(blocks))
|
blocksToWrite = blocksToWrite/float64(models.TCP_BUFFER_SIZE/2) - float64(len(blocks))
|
||||||
}
|
}
|
||||||
|
@ -292,9 +299,8 @@ func receive(forceSend int, serverAddress string, tcpPorts []string, isLocal boo
|
||||||
pieces := bytes.SplitN(decrypted, []byte("-"), 2)
|
pieces := bytes.SplitN(decrypted, []byte("-"), 2)
|
||||||
decrypted = pieces[1]
|
decrypted = pieces[1]
|
||||||
locationToWrite, _ = strconv.Atoi(string(pieces[0]))
|
locationToWrite, _ = strconv.Atoi(string(pieces[0]))
|
||||||
log.Debugf("writing to location %d (%2.0f/%2.0f)", locationToWrite, blocksWritten, blocksToWrite)
|
|
||||||
fProgress.WriteString(fmt.Sprintf("%d\n", locationToWrite))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// do decompression
|
// do decompression
|
||||||
if fstats.IsCompressed && !fstats.IsDir {
|
if fstats.IsCompressed && !fstats.IsDir {
|
||||||
decrypted = compress.Decompress(decrypted)
|
decrypted = compress.Decompress(decrypted)
|
||||||
|
@ -307,9 +313,13 @@ func receive(forceSend int, serverAddress string, tcpPorts []string, isLocal boo
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
n, err = f.WriteAt(decrypted, int64(locationToWrite))
|
n, err = f.WriteAt(decrypted, int64(locationToWrite))
|
||||||
|
fProgress.WriteString(fmt.Sprintf("%d\n", locationToWrite))
|
||||||
|
log.Debugf("writing to location %d (%2.0f/%2.0f)", locationToWrite, blocksWritten, blocksToWrite)
|
||||||
} else {
|
} else {
|
||||||
// write to file
|
// write to file
|
||||||
n, err = f.Write(decrypted)
|
n, err = f.Write(decrypted)
|
||||||
|
log.Debugf("writing to location %d (%2.0f/%2.0f)", bytesWritten, blocksWritten, blocksToWrite)
|
||||||
|
fProgress.WriteString(fmt.Sprintf("%d\n", bytesWritten))
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -225,7 +225,6 @@ func send(forceSend int, serverAddress string, tcpPorts []string, isLocal bool,
|
||||||
var blocks []string
|
var blocks []string
|
||||||
errBlocks := json.Unmarshal(message[5:], &blocks)
|
errBlocks := json.Unmarshal(message[5:], &blocks)
|
||||||
if errBlocks == nil {
|
if errBlocks == nil {
|
||||||
log.Debugf("found blocks: %+v", blocks)
|
|
||||||
for _, block := range blocks {
|
for _, block := range blocks {
|
||||||
blockInt64, errBlock := strconv.Atoi(block)
|
blockInt64, errBlock := strconv.Atoi(block)
|
||||||
if errBlock == nil {
|
if errBlock == nil {
|
||||||
|
@ -233,6 +232,7 @@ func send(forceSend int, serverAddress string, tcpPorts []string, isLocal bool,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.Debugf("found blocks: %+v", blocksToSkip)
|
||||||
|
|
||||||
// start streaming encryption/compression
|
// start streaming encryption/compression
|
||||||
go func(dataChan chan DataChan) {
|
go func(dataChan chan DataChan) {
|
||||||
|
@ -341,12 +341,19 @@ func send(forceSend int, serverAddress string, tcpPorts []string, isLocal bool,
|
||||||
// send file, compure hash simultaneously
|
// send file, compure hash simultaneously
|
||||||
startTransfer = time.Now()
|
startTransfer = time.Now()
|
||||||
|
|
||||||
|
blockSize := 0
|
||||||
|
if useWebsockets {
|
||||||
|
blockSize = models.WEBSOCKET_BUFFER_SIZE / 8
|
||||||
|
} else {
|
||||||
|
blockSize = models.TCP_BUFFER_SIZE / 2
|
||||||
|
}
|
||||||
bar := progressbar.NewOptions(
|
bar := progressbar.NewOptions(
|
||||||
int(fstats.Size),
|
int(fstats.Size),
|
||||||
progressbar.OptionSetRenderBlankState(true),
|
progressbar.OptionSetRenderBlankState(true),
|
||||||
progressbar.OptionSetBytes(int(fstats.Size)),
|
progressbar.OptionSetBytes(int(fstats.Size)),
|
||||||
progressbar.OptionSetWriter(os.Stderr),
|
progressbar.OptionSetWriter(os.Stderr),
|
||||||
)
|
)
|
||||||
|
bar.Add(blockSize * len(blocksToSkip))
|
||||||
|
|
||||||
if useWebsockets {
|
if useWebsockets {
|
||||||
for {
|
for {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue