From 30fbd7f76284e0fb129cc168ff3088cac0297928 Mon Sep 17 00:00:00 2001 From: hannahhoward Date: Sat, 30 Oct 2021 21:26:29 -0700 Subject: [PATCH] fix(responseassembler): dont hold block data reference in passed on subscribed block link --- .../responseassembler/responseBuilder.go | 41 ++++++++++++++----- 1 file changed, 30 insertions(+), 11 deletions(-) diff --git a/responsemanager/responseassembler/responseBuilder.go b/responsemanager/responseassembler/responseBuilder.go index 1b78d8b8..761491ad 100644 --- a/responsemanager/responseassembler/responseBuilder.go +++ b/responsemanager/responseassembler/responseBuilder.go @@ -28,7 +28,7 @@ type responseBuilder struct { func (rb *responseBuilder) SendResponse(link ipld.Link, data []byte) graphsync.BlockData { op := rb.setupBlockOperation(link, data) rb.operations = append(rb.operations, op) - return op + return op.Block() } func (rb *responseBuilder) SendExtensionData(extension graphsync.ExtensionData) { @@ -128,25 +128,44 @@ func (bo blockOperation) build(builder *gsmsg.Builder) { builder.AddLink(bo.requestID, bo.link, bo.data != nil) } -func (bo blockOperation) Link() ipld.Link { +func (bo blockOperation) size() uint64 { + if !bo.sendBlock { + return 0 + } + return uint64(len(bo.data)) +} + +func (bo blockOperation) Block() blockQueued { + return blockQueued{ + sendBlock: bo.sendBlock, + link: bo.link, + index: bo.index, + size: uint64(len(bo.data)), + } +} + +type blockQueued struct { + sendBlock bool + link ipld.Link + index int64 + size uint64 +} + +func (bo blockQueued) Link() ipld.Link { return bo.link } -func (bo blockOperation) BlockSize() uint64 { - return uint64(len(bo.data)) +func (bo blockQueued) BlockSize() uint64 { + return bo.size } -func (bo blockOperation) BlockSizeOnWire() uint64 { +func (bo blockQueued) BlockSizeOnWire() uint64 { if !bo.sendBlock { return 0 } - return bo.BlockSize() + return bo.size } -func (bo blockOperation) Index() int64 { +func (bo blockQueued) Index() int64 { return bo.index } - -func (bo blockOperation) size() uint64 { - return bo.BlockSizeOnWire() -}