Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions protocol/blockfetch/blockfetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type BlockFetch struct {

type Config struct {
BlockFunc BlockFunc
BatchDoneFunc BatchDoneFunc
RequestRangeFunc RequestRangeFunc
BatchStartTimeout time.Duration
BlockTimeout time.Duration
Expand All @@ -102,6 +103,7 @@ type CallbackContext struct {

// Callback function types
type BlockFunc func(CallbackContext, uint, ledger.Block) error
type BatchDoneFunc func(CallbackContext) error
type RequestRangeFunc func(CallbackContext, common.Point, common.Point) error

func New(protoOptions protocol.ProtocolOptions, cfg *Config) *BlockFetch {
Expand Down Expand Up @@ -132,6 +134,12 @@ func WithBlockFunc(blockFunc BlockFunc) BlockFetchOptionFunc {
}
}

func WithBatchDoneFunc(batchDoneFunc BatchDoneFunc) BlockFetchOptionFunc {
return func(c *Config) {
c.BatchDoneFunc = batchDoneFunc
}
}

func WithRequestRangeFunc(
requestRangeFunc RequestRangeFunc,
) BlockFetchOptionFunc {
Expand Down
6 changes: 6 additions & 0 deletions protocol/blockfetch/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ func (c *Client) handleBatchDone() error {
"role", "client",
"connection_id", c.callbackContext.ConnectionId.String(),
)
// Notify the user if requested
if c.blockUseCallback && c.config.BatchDoneFunc != nil {
if err := c.config.BatchDoneFunc(c.callbackContext); err != nil {
return err
}
}
c.busyMutex.Unlock()
return nil
}
Loading