mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
try to maximize packet size
This commit is contained in:
parent
c5feb2f503
commit
9d84485b97
1 changed files with 25 additions and 9 deletions
|
@ -24,7 +24,8 @@ const (
|
||||||
// Must be <= 16384
|
// Must be <= 16384
|
||||||
// 8 bytes for position
|
// 8 bytes for position
|
||||||
// 3000 bytes for encryption / compression overhead
|
// 3000 bytes for encryption / compression overhead
|
||||||
senderBuffSize = 8192
|
maxPacketSize = 16384
|
||||||
|
senderBuffSize = 15000
|
||||||
bufferThreshold = 512 * 1024 // 512kB
|
bufferThreshold = 512 * 1024 // 512kB
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -204,6 +205,7 @@ func (s *Session) readFile(pathToFile string) error {
|
||||||
close(s.output)
|
close(s.output)
|
||||||
}()
|
}()
|
||||||
pos := uint64(0)
|
pos := uint64(0)
|
||||||
|
var lastBytes []byte
|
||||||
for {
|
for {
|
||||||
// Read file
|
// Read file
|
||||||
s.dataBuff = s.dataBuff[:cap(s.dataBuff)]
|
s.dataBuff = s.dataBuff[:cap(s.dataBuff)]
|
||||||
|
@ -223,14 +225,28 @@ func (s *Session) readFile(pathToFile string) error {
|
||||||
posByte := make([]byte, 8)
|
posByte := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(posByte, pos)
|
binary.LittleEndian.PutUint64(posByte, pos)
|
||||||
|
|
||||||
buff := append([]byte(nil), posByte...)
|
for i := 0; i < 10000; i += 1000 {
|
||||||
buff = append(buff, s.dataBuff...)
|
buff := append([]byte(nil), posByte...)
|
||||||
buff = compress.Compress(buff)
|
if len(lastBytes) > 0 {
|
||||||
buff = crypt.EncryptToBytes(buff, []byte{1, 2, 3, 4})
|
buff = append(buff, lastBytes...)
|
||||||
s.output <- outputMsg{
|
}
|
||||||
n: n,
|
buff = append(buff, s.dataBuff[:n-i]...)
|
||||||
// Make a copy of the buffer
|
buff = compress.Compress(buff)
|
||||||
buff: buff,
|
buff = crypt.EncryptToBytes(buff, []byte{1, 2, 3, 4})
|
||||||
|
if len(buff) < maxPacketSize {
|
||||||
|
if n-i > 0 {
|
||||||
|
lastBytes = append([]byte(nil), s.dataBuff[n-i:]...)
|
||||||
|
} else {
|
||||||
|
lastBytes = []byte{}
|
||||||
|
}
|
||||||
|
n = n - i
|
||||||
|
log.Debugf("sending packet size %d", len(buff))
|
||||||
|
s.output <- outputMsg{
|
||||||
|
n: n,
|
||||||
|
buff: buff,
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pos += uint64(n)
|
pos += uint64(n)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue