-
Notifications
You must be signed in to change notification settings - Fork 12
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
fix: default to bitswap-client-only #136
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/ipfs/boxo/bitswap" | ||
bsclient "github.com/ipfs/boxo/bitswap/client" | ||
wl "github.com/ipfs/boxo/bitswap/client/wantlist" | ||
bsmspb "github.com/ipfs/boxo/bitswap/message/pb" | ||
bsnet "github.com/ipfs/boxo/bitswap/network" | ||
bsserver "github.com/ipfs/boxo/bitswap/server" | ||
"github.com/ipfs/boxo/blockstore" | ||
"github.com/ipfs/boxo/exchange" | ||
blocks "github.com/ipfs/go-block-format" | ||
"github.com/ipfs/go-cid" | ||
delay "github.com/ipfs/go-ipfs-delay" | ||
metri "github.com/ipfs/go-metrics-interface" | ||
"github.com/libp2p/go-libp2p/core/host" | ||
"github.com/libp2p/go-libp2p/core/peer" | ||
"github.com/libp2p/go-libp2p/core/routing" | ||
) | ||
|
||
func setupBitswapExchange(ctx context.Context, cfg Config, h host.Host, cr routing.ContentRouting, bstore blockstore.Blockstore) exchange.Interface { | ||
bsctx := metri.CtxScope(ctx, "ipfs_bitswap") | ||
bn := bsnet.NewFromIpfsHost(h, cr) | ||
|
||
// --- Client Options | ||
// bitswap.RebroadcastDelay: default is 1 minute to search for a random | ||
// live-want (1 CID). I think we want to search for random live-wants more | ||
// often although probably it overlaps with general rebroadcasts. | ||
rebroadcastDelay := delay.Fixed(10 * time.Second) | ||
// bitswap.ProviderSearchDelay: default is 1 second. | ||
providerSearchDelay := 1 * time.Second | ||
|
||
// If peering and shared cache are both enabled, we initialize both a | ||
// Client and a Server with custom request filter and custom options. | ||
// client+server is more expensive but necessary when deployment requires | ||
// serving cached blocks to safelisted peerids | ||
if cfg.PeeringSharedCache && len(cfg.Peering) > 0 { | ||
var peerBlockRequestFilter bsserver.PeerBlockRequestFilter | ||
|
||
// Set up request filter to only respond to request for safelisted (peered) nodes | ||
peers := make(map[peer.ID]struct{}, len(cfg.Peering)) | ||
for _, a := range cfg.Peering { | ||
peers[a.ID] = struct{}{} | ||
} | ||
peerBlockRequestFilter = func(p peer.ID, c cid.Cid) bool { | ||
_, ok := peers[p] | ||
return ok | ||
} | ||
|
||
// Initialize client+server | ||
bswap := bitswap.New(bsctx, bn, bstore, | ||
// --- Client Options | ||
bitswap.RebroadcastDelay(rebroadcastDelay), | ||
bitswap.ProviderSearchDelay(providerSearchDelay), | ||
bitswap.WithoutDuplicatedBlockStats(), | ||
|
||
// ---- Server Options | ||
bitswap.WithPeerBlockRequestFilter(peerBlockRequestFilter), | ||
bitswap.ProvideEnabled(false), | ||
// Do not keep track of other peer's wantlists, we only want to reply if we | ||
// have a block. If we get it later, it's no longer relevant. | ||
bitswap.WithPeerLedger(&noopPeerLedger{}), | ||
// When we don't have a block, don't reply. This reduces processment. | ||
bitswap.SetSendDontHaves(false), | ||
) | ||
bn.Start(bswap) | ||
return &noNotifyExchange{bswap} | ||
} | ||
|
||
// By default, rainbow runs with bitswap client alone | ||
bswap := bsclient.New(bsctx, bn, bstore, | ||
// --- Client Options | ||
bsclient.RebroadcastDelay(rebroadcastDelay), | ||
bsclient.ProviderSearchDelay(providerSearchDelay), | ||
bsclient.WithoutDuplicatedBlockStats(), | ||
) | ||
bn.Start(bswap) | ||
return bswap | ||
} | ||
|
||
type noopPeerLedger struct{} | ||
|
||
func (*noopPeerLedger) Wants(p peer.ID, e wl.Entry) {} | ||
|
||
func (*noopPeerLedger) CancelWant(p peer.ID, k cid.Cid) bool { | ||
return false | ||
} | ||
|
||
func (*noopPeerLedger) CancelWantWithType(p peer.ID, k cid.Cid, typ bsmspb.Message_Wantlist_WantType) { | ||
} | ||
|
||
func (*noopPeerLedger) Peers(k cid.Cid) []bsserver.PeerEntry { | ||
return nil | ||
} | ||
|
||
func (*noopPeerLedger) CollectPeerIDs() []peer.ID { | ||
return nil | ||
} | ||
|
||
func (*noopPeerLedger) WantlistSizeForPeer(p peer.ID) int { | ||
return 0 | ||
} | ||
|
||
func (*noopPeerLedger) WantlistForPeer(p peer.ID) []wl.Entry { | ||
return nil | ||
} | ||
|
||
func (*noopPeerLedger) ClearPeerWantlist(p peer.ID) {} | ||
|
||
func (*noopPeerLedger) PeerDisconnected(p peer.ID) {} | ||
|
||
type noNotifyExchange struct { | ||
exchange.Interface | ||
} | ||
|
||
func (e *noNotifyExchange) NotifyNewBlocks(ctx context.Context, blocks ...blocks.Block) error { | ||
// Rainbow does not notify when we get new blocks in our Blockservice. | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"version": "v1.2.1" | ||
"version": "v1.2.2" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 I wonder if doing this (making
NotifyNewBlocks
no-op) has impact on the client. Just to be sure, we do not do this by default.