negentropy: fix frameSizeLimit check (was checking against the hex).

This commit is contained in:
fiatjaf 2024-09-20 20:53:57 -03:00
parent 101031b9e8
commit 4d63672462

View File

@ -205,7 +205,7 @@ func (n *Negentropy) reconcileAux(reader *StringHexReader) (string, error) {
endBound := currBound
for index, item := range n.storage.Range(lower, upper) {
if n.frameSizeLimit-200 < fullOutput.Len()+1+8+responseIds.Len() {
if n.frameSizeLimit-200 < fullOutput.Len()/2+responseIds.Len()/2 {
endBound = Bound{item}
upper = index
break
@ -227,7 +227,7 @@ func (n *Negentropy) reconcileAux(reader *StringHexReader) (string, error) {
return "", fmt.Errorf("unexpected mode %d", mode)
}
if n.frameSizeLimit-200 < fullOutput.Len()+partialOutput.Len() {
if n.frameSizeLimit-200 <= fullOutput.Len()/2+partialOutput.Len()/2 {
// frame size limit exceeded, handle by encoding a boundary and fingerprint for the remaining range
remainingFingerprint := n.storage.Fingerprint(upper, n.storage.Size())
n.writeBound(fullOutput, InfiniteBound)