Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ability to configure bitswap wanthave replacement #165

Merged
merged 5 commits into from
Sep 30, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The following emojis are used to highlight certain changes:
## [Unreleased]

### Added
- Ability to specify the maximum blocksize that bitswap will replace WantHave with WantBlock responses, and to disable replacement when set to zero. [#165](https://github.com/ipfs/rainbow/pull/165)

### Changed

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/felixge/httpsnoop v1.0.4
github.com/ipfs-shipyard/nopfs v0.0.12
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231024163508-120e0c51ee3a
github.com/ipfs/boxo v0.23.0
github.com/ipfs/boxo v0.23.1-0.20240927234853-19a402b7dc34
github.com/ipfs/go-block-format v0.2.0
github.com/ipfs/go-cid v0.4.1
github.com/ipfs/go-datastore v0.6.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231024163508-120e0c51ee3a h1:MKG
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231024163508-120e0c51ee3a/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI=
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
github.com/ipfs/boxo v0.23.0 h1:dY1PpcvPJ//VuUQ1TUd5TZvmaGuzxJ8dOP6mXaw+ke8=
github.com/ipfs/boxo v0.23.0/go.mod h1:ulu5I6avTmgGmvjuCaBRKwsaOOKjBfQw1EiOOQp8M6E=
github.com/ipfs/boxo v0.23.1-0.20240927234853-19a402b7dc34 h1:/Etgc4IR0OUF+nIoNdqwu12EYuaSMpd7/Nc5wRLd67U=
github.com/ipfs/boxo v0.23.1-0.20240927234853-19a402b7dc34/go.mod h1:ulu5I6avTmgGmvjuCaBRKwsaOOKjBfQw1EiOOQp8M6E=
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ=
Expand Down
67 changes: 37 additions & 30 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@
EnvVars: []string{"RAINBOW_BITSWAP"},
Usage: "Controls if Bitswap is enabled (useful for testing or when remote backend is used instead)",
},
&cli.IntFlag{
Name: "bitswap-wanthave-replace-size",
Value: 1024,
EnvVars: []string{"BITSWAP_WANTHAVE_REPLACE_SIZE"},
Usage: "Replace WantHave with WantBlock responses for small blocks up to this size, 0 to disable replacement",
},
&cli.StringSliceFlag{
Name: "remote-backends",
Value: cli.NewStringSlice(),
Expand Down Expand Up @@ -424,36 +430,37 @@
}

cfg := Config{
DataDir: ddir,
BlockstoreType: cctx.String("blockstore"),
GatewayDomains: cctx.StringSlice("gateway-domains"),
SubdomainGatewayDomains: cctx.StringSlice("subdomain-gateway-domains"),
TrustlessGatewayDomains: cctx.StringSlice("trustless-gateway-domains"),
ConnMgrLow: cctx.Int("libp2p-connmgr-low"),
ConnMgrHi: cctx.Int("libp2p-connmgr-high"),
ConnMgrGrace: cctx.Duration("libp2p-connmgr-grace"),
MaxMemory: cctx.Uint64("libp2p-max-memory"),
MaxFD: cctx.Int("libp2p-max-fd"),
InMemBlockCache: cctx.Int64("inmem-block-cache"),
RoutingV1Endpoints: cctx.StringSlice("http-routers"),
DHTRouting: dhtRouting,
DHTSharedHost: cctx.Bool("dht-shared-host"),
Bitswap: bitswap,
IpnsMaxCacheTTL: cctx.Duration("ipns-max-cache-ttl"),
DenylistSubs: cctx.StringSlice("denylists"),
Peering: peeringAddrs,
PeeringSharedCache: cctx.Bool("peering-shared-cache"),
Seed: seed,
SeedIndex: index,
SeedPeering: seedPeering,
SeedPeeringMaxIndex: cctx.Int("seed-peering-max-index"),
RemoteBackends: remoteBackends,
RemoteBackendsIPNS: cctx.Bool("remote-backends-ipns"),
RemoteBackendMode: RemoteBackendMode(cctx.String("remote-backends-mode")),
GCInterval: cctx.Duration("gc-interval"),
GCThreshold: cctx.Float64("gc-threshold"),
ListenAddrs: cctx.StringSlice("libp2p-listen-addrs"),
TracingAuthToken: cctx.String("tracing-auth"),
DataDir: ddir,
BlockstoreType: cctx.String("blockstore"),
GatewayDomains: cctx.StringSlice("gateway-domains"),
SubdomainGatewayDomains: cctx.StringSlice("subdomain-gateway-domains"),
TrustlessGatewayDomains: cctx.StringSlice("trustless-gateway-domains"),
ConnMgrLow: cctx.Int("libp2p-connmgr-low"),
ConnMgrHi: cctx.Int("libp2p-connmgr-high"),
ConnMgrGrace: cctx.Duration("libp2p-connmgr-grace"),
MaxMemory: cctx.Uint64("libp2p-max-memory"),
MaxFD: cctx.Int("libp2p-max-fd"),
InMemBlockCache: cctx.Int64("inmem-block-cache"),
RoutingV1Endpoints: cctx.StringSlice("http-routers"),
DHTRouting: dhtRouting,
DHTSharedHost: cctx.Bool("dht-shared-host"),
Bitswap: bitswap,
BitswapWantHaveReplaceSize: cctx.Int("bitswap-wanthave-replace-size"),
IpnsMaxCacheTTL: cctx.Duration("ipns-max-cache-ttl"),
DenylistSubs: cctx.StringSlice("denylists"),
Peering: peeringAddrs,
PeeringSharedCache: cctx.Bool("peering-shared-cache"),
Seed: seed,
SeedIndex: index,
SeedPeering: seedPeering,
SeedPeeringMaxIndex: cctx.Int("seed-peering-max-index"),
RemoteBackends: remoteBackends,
RemoteBackendsIPNS: cctx.Bool("remote-backends-ipns"),
RemoteBackendMode: RemoteBackendMode(cctx.String("remote-backends-mode")),
GCInterval: cctx.Duration("gc-interval"),
GCThreshold: cctx.Float64("gc-threshold"),
ListenAddrs: cctx.StringSlice("libp2p-listen-addrs"),
TracingAuthToken: cctx.String("tracing-auth"),

Check warning on line 463 in main.go

View check run for this annotation

Codecov / codecov/patch

main.go#L433-L463

Added lines #L433 - L463 were not covered by tests
}

var gnd *Node
Expand Down
6 changes: 6 additions & 0 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ type Config struct {
IpnsMaxCacheTTL time.Duration
Bitswap bool

// BitswapWantHaveReplaceSize tells the bitswap server to replace WantHave
// with WantBlock responses when the block size less then or equal to this
// value. Set to zero to disable replacement and avoid block size lookup
// when processing HaveWant requests.
BitswapWantHaveReplaceSize int

DenylistSubs []string

Peering []peer.AddrInfo
Expand Down
1 change: 1 addition & 0 deletions setup_bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func setupBitswapExchange(ctx context.Context, cfg Config, h host.Host, cr routi
bitswap.ProvideEnabled(false),
// When we don't have a block, don't reply. This reduces processment.
bitswap.SetSendDontHaves(false),
bitswap.WithWantHaveReplaceSize(cfg.BitswapWantHaveReplaceSize),
)
bn.Start(bswap)
return &noNotifyExchange{bswap}
Expand Down
Loading