mirror of https://gogs.blitter.com/RLabs/xs
hkexcp: fixed copy chunked payload logic (now 2*32-1 MAX_PAYLOAD_LEN w/chunking)
This commit is contained in:
parent
c842d36319
commit
7295492aa3
|
@ -42,6 +42,8 @@ const (
|
||||||
CSOChaff // Dummy packet, do not pass beyond decryption
|
CSOChaff // Dummy packet, do not pass beyond decryption
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const MAX_PAYLOAD_LEN = 4*1024*1024*1024 - 1
|
||||||
|
|
||||||
/*---------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------*/
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -376,7 +378,7 @@ func (hc Conn) Read(b []byte) (n int, err error) {
|
||||||
// (on server side) err.Error() == "<iface/addr info ...>: use of closed network connection"
|
// (on server side) err.Error() == "<iface/addr info ...>: use of closed network connection"
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if !strings.HasSuffix(err.Error(), "use of closed network connection") {
|
if !strings.HasSuffix(err.Error(), "use of closed network connection") {
|
||||||
log.Println("unexpected Read() err:", err)
|
log.Println("[1]unexpected Read() err:", err)
|
||||||
} else {
|
} else {
|
||||||
log.Println("[Client hung up]")
|
log.Println("[Client hung up]")
|
||||||
}
|
}
|
||||||
|
@ -386,7 +388,7 @@ func (hc Conn) Read(b []byte) (n int, err error) {
|
||||||
err = binary.Read(hc.c, binary.BigEndian, &payloadLen)
|
err = binary.Read(hc.c, binary.BigEndian, &payloadLen)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err.Error() != "EOF" {
|
if err.Error() != "EOF" {
|
||||||
log.Println("unexpected Read() err:", err)
|
log.Println("[2]unexpected Read() err:", err)
|
||||||
//panic(err)
|
//panic(err)
|
||||||
// Cannot just return 0, err here - client won't hang up properly
|
// Cannot just return 0, err here - client won't hang up properly
|
||||||
// when 'exit' from shell. TODO: try server sending ctrlStatOp to
|
// when 'exit' from shell. TODO: try server sending ctrlStatOp to
|
||||||
|
@ -394,7 +396,7 @@ func (hc Conn) Read(b []byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if payloadLen > 8192 {
|
if payloadLen > MAX_PAYLOAD_LEN {
|
||||||
log.Printf("[Insane payloadLen:%v]\n", payloadLen)
|
log.Printf("[Insane payloadLen:%v]\n", payloadLen)
|
||||||
hc.Close()
|
hc.Close()
|
||||||
return 1, errors.New("Insane payloadLen")
|
return 1, errors.New("Insane payloadLen")
|
||||||
|
@ -409,7 +411,7 @@ func (hc Conn) Read(b []byte) (n int, err error) {
|
||||||
// (on server side) err.Error() == "<iface/addr info ...>: use of closed network connection"
|
// (on server side) err.Error() == "<iface/addr info ...>: use of closed network connection"
|
||||||
if err != nil && err.Error() != "EOF" {
|
if err != nil && err.Error() != "EOF" {
|
||||||
if !strings.HasSuffix(err.Error(), "use of closed network connection") {
|
if !strings.HasSuffix(err.Error(), "use of closed network connection") {
|
||||||
log.Println("unexpected Read() err:", err)
|
log.Println("[3]unexpected Read() err:", err)
|
||||||
} else {
|
} else {
|
||||||
log.Println("[Client hung up]")
|
log.Println("[Client hung up]")
|
||||||
}
|
}
|
||||||
|
@ -498,11 +500,15 @@ func (hc Conn) WritePacket(b []byte, op byte) (n int, err error) {
|
||||||
//
|
//
|
||||||
// Would be nice to determine if the mutex scope
|
// Would be nice to determine if the mutex scope
|
||||||
// could be tightened.
|
// could be tightened.
|
||||||
hc.m.Lock()
|
|
||||||
for uint32(len(b)) > 0 {
|
for uint32(len(b)) > 0 {
|
||||||
|
hc.m.Lock()
|
||||||
|
fmt.Printf("--== TOTAL payloadLen (b):%d\n", len(b))
|
||||||
payloadLen = uint32(len(b))
|
payloadLen = uint32(len(b))
|
||||||
if payloadLen > 8192 {
|
if payloadLen > MAX_PAYLOAD_LEN {
|
||||||
payloadLen = 8192
|
payloadLen = MAX_PAYLOAD_LEN
|
||||||
|
//fmt.Printf("--== payloadLen:%d\n", payloadLen)
|
||||||
|
} else {
|
||||||
|
//fmt.Printf("--== payloadLen:%d\n", payloadLen)
|
||||||
}
|
}
|
||||||
log.Printf(" :>ptext:\r\n%s\r\n", hex.Dump(b[0:payloadLen]))
|
log.Printf(" :>ptext:\r\n%s\r\n", hex.Dump(b[0:payloadLen]))
|
||||||
|
|
||||||
|
@ -534,9 +540,11 @@ func (hc Conn) WritePacket(b []byte, op byte) (n int, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//Advance to next full (or final, partial) chunk of payload
|
||||||
b = b[payloadLen:]
|
b = b[payloadLen:]
|
||||||
}
|
|
||||||
hc.m.Unlock()
|
hc.m.Unlock()
|
||||||
|
time.Sleep(200 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//panic(err)
|
//panic(err)
|
||||||
|
|
|
@ -114,7 +114,7 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, rec *cmdSpec)
|
||||||
// changes to the dest dir *as it sees each one*. This enables
|
// changes to the dest dir *as it sees each one*. This enables
|
||||||
// its use below, where clients can send scattered sets of source
|
// its use below, where clients can send scattered sets of source
|
||||||
// files and dirs to be extracted to a single dest dir server-side,
|
// files and dirs to be extracted to a single dest dir server-side,
|
||||||
// whilst preserving the subtrees of dirs on the other side. :)
|
// whilst preserving the subtrees of dirs on the other side.
|
||||||
// Eg., tar -c -f /dev/stdout -C /dirA fileInA -C /some/where/dirB fileInB /foo/dirC
|
// Eg., tar -c -f /dev/stdout -C /dirA fileInA -C /some/where/dirB fileInB /foo/dirC
|
||||||
// packages fileInA, fileInB, and dirC at a single toplevel in the tar.
|
// packages fileInA, fileInB, and dirC at a single toplevel in the tar.
|
||||||
// The tar authors are/were real smarties :)
|
// The tar authors are/were real smarties :)
|
||||||
|
@ -130,7 +130,6 @@ func doCopyMode(conn *hkexnet.Conn, remoteDest bool, files string, rec *cmdSpec)
|
||||||
} else {
|
} else {
|
||||||
cmdArgs = append(cmdArgs, "-C", dirTmp, fileTmp)
|
cmdArgs = append(cmdArgs, "-C", dirTmp, fileTmp)
|
||||||
}
|
}
|
||||||
|
|
||||||
//cmdArgs = append(cmdArgs, v)
|
//cmdArgs = append(cmdArgs, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue