Skip to content

Commit

Permalink
Improving option name and make consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Sep 20, 2024
1 parent 1364a16 commit 639ef65
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The following emojis are used to highlight certain changes:
### Added

* `boxo/bitswap/server`:
* A new `WithReplaceHasWithBlockMaxSize(n)` option can be used with `bitswap.New`. It sets the maximum size of a block in bytes up to which we will replace a want-have with a want-block. Setting a size of 0 disables this want-have replacement and means that block sizes are not read for want-have requests.
* A new `WithWantHaveReplaceSize(n)` option can be used with `bitswap.New`. It sets the maximum size of a block in bytes up to which the bitswap server will replace a WantHave with a WantBlock response. Setting this to 0 disables this WantHave replacement and means that block sizes are not read when processing WantHave requests.

### Changed

Expand Down
12 changes: 6 additions & 6 deletions bitswap/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ func WithTaskComparator(comparator server.TaskComparator) Option {
return Option{server.WithTaskComparator(comparator)}
}

// WithReplaceHasWithBlockMaxSize sets the maximum size of a block in bytes up
// to which we will replace a want-have with a want-block. Setting a size of 0
// disables this want-have replacement and means that block sizes are not read
// for want-have requests.
func WithReplaceHasWithBlockMaxSize(maxSize int) Option {
return Option{server.WithReplaceHasWithBlockMaxSize(maxSize)}
// WithWantHaveReplaceSize sets the maximum size of a block in bytes up to
// which the bitswap server will replace a WantHave with a WantBlock response.
// Setting this to 0 disables this WantHave replacement and means that block
// sizes are not read when processing WantHave requests.
func WithWantHaveReplaceSize(size int) Option {
return Option{server.WithWantHaveReplaceSize(size)}

Check warning on line 79 in bitswap/options.go

View check run for this annotation

Codecov / codecov/patch

bitswap/options.go#L78-L79

Added lines #L78 - L79 were not covered by tests
}

func ProviderSearchDelay(newProvSearchDelay time.Duration) Option {
Expand Down
30 changes: 15 additions & 15 deletions bitswap/server/internal/decision/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ const (
// on their behalf.
queuedTagWeight = 10

// defaultReplaceHasWithBlockMaxSize is the default maximum size of the
// block in bytes up to which we will replace a want-have with a want-block
defaultReplaceHasWithBlockMaxSize = 1024
// defaultWantHave ReplaceSize is the default maximum size of the block in
// bytes up to which we will replace a WantHave with a WantBlock response.
defaultWantHaveReplaceSize = 1024
)

// Envelope contains a message for a Peer.
Expand Down Expand Up @@ -202,9 +202,9 @@ type Engine struct {

targetMessageSize int

// replaceHasWithBlockMaxSize is the maximum size of the block in
// bytes up to which we will replace a want-have with a want-block
replaceHasWithBlockMaxSize int
// wantHaveReplaceSize is the maximum size of the block in bytes up to
// which to replace a WantHave with a WantBlock.
wantHaveReplaceSize int

sendDontHaves bool

Expand Down Expand Up @@ -343,11 +343,11 @@ func WithSetSendDontHave(send bool) Option {
}
}

// WithReplaceHasWithBlockMaxSize sets the maximum size of a block in bytes up
// to which we will replace a want-have with a want-block.
func WithReplaceHasWithBlockMaxSize(maxSize int) Option {
// WithWantHaveReplaceSize sets the maximum size of a block in bytes up to
// which to replace a WantHave with a WantBlock response.
func WithWantHaveReplaceSize(size int) Option {
return func(e *Engine) {
e.replaceHasWithBlockMaxSize = maxSize
e.wantHaveReplaceSize = size
}
}

Expand Down Expand Up @@ -394,7 +394,7 @@ func NewEngine(
outbox: make(chan (<-chan *Envelope), outboxChanBuffer),
workSignal: make(chan struct{}, 1),
ticker: time.NewTicker(time.Millisecond * 100),
replaceHasWithBlockMaxSize: defaultReplaceHasWithBlockMaxSize,
wantHaveReplaceSize: defaultWantHaveReplaceSize,
taskWorkerCount: defaults.BitswapEngineTaskWorkerCount,
sendDontHaves: true,
self: self,
Expand Down Expand Up @@ -435,10 +435,10 @@ func NewEngine(

e.peerRequestQueue = peertaskqueue.New(peerTaskQueueOpts...)

if e.replaceHasWithBlockMaxSize == 0 {
if e.wantHaveReplaceSize == 0 {
log.Info("Replace WantHave with WantBlock is disabled")
} else {
log.Infow("Replace WantHave with WantBlock is enabled", "maxSize", e.replaceHasWithBlockMaxSize)
log.Infow("Replace WantHave with WantBlock is enabled", "maxSize", e.wantHaveReplaceSize)
}

return e
Expand Down Expand Up @@ -685,7 +685,7 @@ func (e *Engine) MessageReceived(ctx context.Context, p peer.ID, m bsmsg.BitSwap
return true
}

noReplace := e.replaceHasWithBlockMaxSize == 0
noReplace := e.wantHaveReplaceSize == 0

// Get block sizes for unique CIDs.
wantKs := make([]cid.Cid, 0, len(wants))
Expand Down Expand Up @@ -1084,7 +1084,7 @@ func (e *Engine) PeerDisconnected(p peer.ID) {
// If the want is a want-have, and it's below a certain size, send the full
// block (instead of sending a HAVE)
func (e *Engine) sendAsBlock(wantType pb.Message_Wantlist_WantType, blockSize int) bool {
return wantType == pb.Message_Wantlist_Block || blockSize <= e.replaceHasWithBlockMaxSize
return wantType == pb.Message_Wantlist_Block || blockSize <= e.wantHaveReplaceSize
}

func (e *Engine) numBytesSentTo(p peer.ID) uint64 {
Expand Down
4 changes: 2 additions & 2 deletions bitswap/server/internal/decision/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ func newEngineForTesting(
bs blockstore.Blockstore,
peerTagger PeerTagger,
self peer.ID,
maxReplaceSize int,
wantHaveReplaceSize int,
opts ...Option,
) *Engine {
opts = append(opts, WithReplaceHasWithBlockMaxSize(maxReplaceSize))
opts = append(opts, WithWantHaveReplaceSize(wantHaveReplaceSize))
return NewEngine(ctx, bs, peerTagger, self, opts...)
}

Expand Down
16 changes: 8 additions & 8 deletions bitswap/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,16 +251,16 @@ func HasBlockBufferSize(count int) Option {
}
}

// WithReplaceHasWithBlockMaxSize sets the maximum size of a block in bytes up
// to which we will replace a want-have with a want-block. Setting a size of 0
// disables this want-have replacement and means that block sizes are not read
// for want-have requests.
func WithReplaceHasWithBlockMaxSize(maxSize int) Option {
if maxSize < 0 {
maxSize = 0
// WithWantHaveReplaceSize sets the maximum size of a block in bytes up to
// which to replace a WantHave with a WantBlock. Setting to 0 disables this
// WantHave replacement and means that block sizes are not read when processing
// WantHave requests.
func WithWantHaveReplaceSize(size int) Option {
if size < 0 {
size = 0
}
return func(bs *Server) {
bs.engineOptions = append(bs.engineOptions, decision.WithReplaceHasWithBlockMaxSize(maxSize))
bs.engineOptions = append(bs.engineOptions, decision.WithWantHaveReplaceSize(size))
}

Check warning on line 264 in bitswap/server/server.go

View check run for this annotation

Codecov / codecov/patch

bitswap/server/server.go#L258-L264

Added lines #L258 - L264 were not covered by tests
}

Expand Down

0 comments on commit 639ef65

Please sign in to comment.