mirror of https://github.com/pkg/sftp.git
better debug info
This commit is contained in:
parent
8a0fc6568b
commit
9ae47f4170
33
packet.go
33
packet.go
|
@ -311,9 +311,16 @@ func recvPacket(r io.Reader, alloc *allocator, orderID uint32) (uint8, []byte, e
|
||||||
} else {
|
} else {
|
||||||
b = make([]byte, 4)
|
b = make([]byte, 4)
|
||||||
}
|
}
|
||||||
if _, err := io.ReadFull(r, b[:4]); err != nil {
|
|
||||||
|
if n, err := io.ReadFull(r, b[:4]); err != nil {
|
||||||
|
debug("recv length %d of %d bytes: err %v", n, 4, err)
|
||||||
|
if n > 0 {
|
||||||
|
debug("recv length error: bytes %x", b[:n])
|
||||||
|
}
|
||||||
|
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
length, _ := unmarshalUint32(b)
|
length, _ := unmarshalUint32(b)
|
||||||
if length > maxMsgLength {
|
if length > maxMsgLength {
|
||||||
debug("recv packet %d bytes too long", length)
|
debug("recv packet %d bytes too long", length)
|
||||||
|
@ -323,24 +330,38 @@ func recvPacket(r io.Reader, alloc *allocator, orderID uint32) (uint8, []byte, e
|
||||||
debug("recv packet of 0 bytes too short")
|
debug("recv packet of 0 bytes too short")
|
||||||
return 0, nil, errShortPacket
|
return 0, nil, errShortPacket
|
||||||
}
|
}
|
||||||
|
|
||||||
if alloc == nil {
|
if alloc == nil {
|
||||||
b = make([]byte, length)
|
b = make([]byte, length)
|
||||||
}
|
}
|
||||||
if _, err := io.ReadFull(r, b[:length]); err != nil {
|
|
||||||
|
if n, err := io.ReadFull(r, b[:length]); err != nil {
|
||||||
|
// Log this error message _before_ we potentially override it.
|
||||||
|
debug("recv packet %d of %d bytes: err %v", n, length, err)
|
||||||
|
|
||||||
// ReadFull only returns EOF if it has read no bytes.
|
// ReadFull only returns EOF if it has read no bytes.
|
||||||
// In this case, that means a partial packet, and thus unexpected.
|
// In this case, that means a partial packet, and thus unexpected.
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
err = io.ErrUnexpectedEOF
|
err = io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
debug("recv packet %d bytes: err %v", length, err)
|
|
||||||
|
if n > 0 {
|
||||||
|
n := min(32, n) // limit bytes dump to 32-bytes.
|
||||||
|
debug("recv packet error: bytes %x", b[:n])
|
||||||
|
}
|
||||||
|
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typ, payload := fxp(b[0]), b[1:length]
|
||||||
|
|
||||||
if debugDumpRxPacketBytes {
|
if debugDumpRxPacketBytes {
|
||||||
debug("recv packet: %s %d bytes %x", fxp(b[0]), length, b[1:length])
|
debug("recv packet: %s %d bytes %x", typ, length, payload)
|
||||||
} else if debugDumpRxPacket {
|
} else if debugDumpRxPacket {
|
||||||
debug("recv packet: %s %d bytes", fxp(b[0]), length)
|
debug("recv packet: %s %d bytes", typ, length)
|
||||||
}
|
}
|
||||||
return b[0], b[1:length], nil
|
|
||||||
|
return typ, payload, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type extensionPair struct {
|
type extensionPair struct {
|
||||||
|
|
Loading…
Reference in New Issue