Skip to content

Commit

Permalink
fix(responseassembler): dont hold block data reference in passed on s…
Browse files Browse the repository at this point in the history
…ubscribed block link (#268)
  • Loading branch information
hannahhoward authored Nov 2, 2021
1 parent 695492e commit 763fa44
Showing 1 changed file with 30 additions and 11 deletions.
41 changes: 30 additions & 11 deletions responsemanager/responseassembler/responseBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
}

0 comments on commit 763fa44

Please sign in to comment.