sync: # file upload improve
This commit is contained in:
parent
9041abd3d3
commit
e70bb0f167
6 changed files with 489 additions and 31 deletions
|
|
@ -178,6 +178,37 @@ func preflightRPCWire(id uint32, wire rpcPreflightWire) error {
|
|||
}
|
||||
}
|
||||
|
||||
// LayerRPCFlatBytesPayloadSize exposes the only two byte-heavy, flat request
|
||||
// graphs to mtprotoedge's materialization budget. Returning ok is deliberately
|
||||
// stricter than recognizing the constructor: the complete TL bytes tail,
|
||||
// per-part byte ceiling and big-file total-parts policy must all pass the same
|
||||
// allocation-free preflight used by generated exact admission. All other RPCs
|
||||
// retain the generic worst-case graph charge.
|
||||
func (r *Router) LayerRPCFlatBytesPayloadSize(wire []byte) (int, bool) {
|
||||
if r == nil || len(wire) < 4 {
|
||||
return 0, false
|
||||
}
|
||||
raw := rawRPCPreflightWire(wire)
|
||||
id := binary.LittleEndian.Uint32(wire[:4])
|
||||
bytesOffset := 0
|
||||
switch id {
|
||||
case tg.UploadSaveFilePartRequestTypeID:
|
||||
bytesOffset = 16
|
||||
case tg.UploadSaveBigFilePartRequestTypeID:
|
||||
bytesOffset = 20
|
||||
default:
|
||||
return 0, false
|
||||
}
|
||||
if err := preflightRPCWire(id, raw); err != nil {
|
||||
return 0, false
|
||||
}
|
||||
payloadBytes, encodedBytes, err := tlBytesSizeAt(raw, bytesOffset)
|
||||
if err != nil || encodedBytes != len(wire)-bytesOffset {
|
||||
return 0, false
|
||||
}
|
||||
return payloadBytes, true
|
||||
}
|
||||
|
||||
func preflightFixedVector(wire rpcPreflightWire, policy requestVectorPolicy) error {
|
||||
if policy.vectorOffset < 4 || policy.minElemBytes <= 0 || wire.WireSize() < policy.vectorOffset+8 {
|
||||
return inputRequestInvalidErr()
|
||||
|
|
@ -210,10 +241,18 @@ func preflightFixedVector(wire rpcPreflightWire, policy requestVectorPolicy) err
|
|||
}
|
||||
|
||||
func preflightUploadPart(wire rpcPreflightWire, bytesOffset int, big bool) error {
|
||||
if wire.WireSize() < bytesOffset {
|
||||
return inputRequestInvalidErr()
|
||||
}
|
||||
rawPart, err := wire.Uint32At(12)
|
||||
if err != nil {
|
||||
return inputRequestInvalidErr()
|
||||
}
|
||||
part := int32(rawPart)
|
||||
if part < 0 || part >= int32(appfiles.MaxUploadParts) {
|
||||
return filePartInvalidErr()
|
||||
}
|
||||
if big {
|
||||
if wire.WireSize() < 20 {
|
||||
return inputRequestInvalidErr()
|
||||
}
|
||||
rawTotalParts, err := wire.Uint32At(16)
|
||||
if err != nil {
|
||||
return inputRequestInvalidErr()
|
||||
|
|
@ -230,14 +269,17 @@ func preflightUploadPart(wire rpcPreflightWire, bytesOffset int, big bool) error
|
|||
if encoded != wire.WireSize()-bytesOffset {
|
||||
return inputRequestInvalidErr()
|
||||
}
|
||||
if n == 0 {
|
||||
return filePartInvalidErr()
|
||||
}
|
||||
if n > appfiles.MaxUploadPartBytes {
|
||||
return filePartTooBigErr()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// tlBytesSizeAt parses a TL bytes prefix without copying the payload. encoded includes prefix,
|
||||
// payload and 4-byte padding.
|
||||
// tlBytesSizeAt parses a TL bytes prefix without copying the payload. encoded
|
||||
// includes prefix, payload and 4-byte padding.
|
||||
func tlBytesSizeAt(wire rpcPreflightWire, offset int) (n, encoded int, err error) {
|
||||
if offset < 0 || offset >= wire.WireSize() {
|
||||
return 0, 0, fmt.Errorf("bytes prefix out of range")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue