-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
feat(config): ability to disable Bitswap fully or just server #10782
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
base: master
Are you sure you want to change the base?
Conversation
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.
Thank you @gystemd, this partially works, but does not fully disable the server (it is still possible for other peers to send us WANT and GET for CIDs we dont have).
See ideas (A) and (B) below, I suspect we will end up with (B) but let's see what is easier.
package config | ||
|
||
// BitswapConfig holds Bitswap configuration options | ||
type BitswapConfig struct { |
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.
nit: package is already named config, so this will be config.BitswapConfig
– please name to config.Bitswap
} | ||
bs := bitswap.New(helpers.LifecycleCtx(in.Mctx, lc), bitswapNetwork, provider, in.Bs, in.BitswapOpts...) | ||
|
||
bs := bitswap.New(helpers.LifecycleCtx(in.Mctx, lc), bitswapNetwork, provider, blockstoree, in.BitswapOpts...) |
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 am afraid this does not actually disable bitswap server, it only makes sure the server will always return "i dont have this blocks" because empty datastore is used.
The problem with this approach is that such node will still announce itself as bitswap server – you can see it by making ipfs id
→ Protocols
section will still have:
"/ipfs/bitswap",
"/ipfs/bitswap/1.0.0",
"/ipfs/bitswap/1.1.0",
"/ipfs/bitswap/1.2.0",
This is a problem because such node will still receive bitswap queries ans asks for random CIDs from other peers, and will have to respond to them, effectively wasting resources.
Desired behavior
What we want for Bitswap.ServerEnabled=false
is to completely "stop acting as bitswap server" and that means removing it from libp2p identify response (ipfs id
), so other peers won't even talk to us over bitswap on their own (and only when we connect to them, as a client).
There are two ways of doing it – not sure which one will be easier, it is fine for you to investugate before making a decision:
- (A) When server is disabled, do not initialize entire bitswap (which is wrapper for both client+server), and initialize only the client
- There is a prior art in Rainbow, which by default initializes bitswap client only: https://github.com/ipfs/rainbow/blob/1bf59f710821432bbb28c5ffe98d4028087e5c7e/setup_bitswap.go#L111 but it may not be as easy in Kubo due to bigger code surface
- (B) Initialize noop server with emty blockstore, but make sure we dont announce ourselves as
/ipfs/bitswap*
server to other peers.- If client-only approach is too complex to execute in Kubo codebase, it is sensible to keep your solution with noop server, and just finding a way to remove
/ipfs/bitswap*
from libp2p identify response (which can be inspected viaipfs id <peerid>
orvole libp2p identify
) - This may require changes to https://github.com/ipfs/boxo – perhaps adding a new configuration option for Bitswap server that disables annoucing
/ipfs/bitswap
to libp2p host
- If client-only approach is too complex to execute in Kubo codebase, it is sensible to keep your solution with noop server, and just finding a way to remove
I'd say see if (A) is easy to do, but if you find yourself being blocked by a bigger refactor (e.g. all the commands that expect bitswap server to be always present), consider (B) instead, as it would have smaller code surface, and also be easier to maintain.
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 investigated both the suggested solutions , but I got stuck in trying to prevent the node to communicate /ipfs/bitswap* as supported protocols: the identify protocol is segregated inside the go-libp2p library and I cannot manipulate its internals. I have found a way to remove the handler associated to the /ipfs/bitswap* protocol in the Host's multiplexer (Mux). This way, the protocol is effectively removed from the list of supported protocols, but it results in the client not being able to send messages anymore (I suspect it is due to this boxo function). What if we register a stream handler for that just immediately shutsdown? I mean replacing this handler with an empty method that just closes the stream. This way maybe the node will stop responding completely to other nodes bitswap requests.
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.
@gystemd thank you for looking into this.
I wonder if we could do this earlier bitswap/network/bsnet
– I'm thinking Start
instead of handleNewStream
:
- "server"
- if we add configuration option to disable calling
SetStreamHandler
here: https://github.com/ipfs/boxo/blob/dc60fe747c375c631a92fcfd6c7456f44a760d24/bitswap/network/bsnet/ipfs_impl.go#L402-L403 then the server would never register a handler
- if we add configuration option to disable calling
- "client"
- iiuc should still work because only server needs to annouce streams, and we pass expected ones here: https://github.com/ipfs/boxo/blob/dc60fe747c375c631a92fcfd6c7456f44a760d24/bitswap/network/bsnet/ipfs_impl.go#L389-90
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.
We need a test that confirms ipfs id peerid
no longer includes /ipfs/bitswap
protocols when Bitswap.ServerEnabled
is set to false
(ensuring we no longer announce ourselves as server)
This pull request introduces changes to the Bitswap configuration and functionality, including the addition of new configuration options, modifications to the Bitswap server/client behavior, and the inclusion of new tests to verify these changes.
Bitswap Configuration Enhancements:
BitswapConfig
struct inconfig/bitswap.go
to hold Bitswap configuration options, includingEnabled
andServerEnabled
flags.Config
struct inconfig/config.go
to include the newBitswapConfig
field.Bitswap Server/Client Behavior:
Bitswap
function incore/node/bitswap.go
to respect theServerEnabled
flag, using an empty blockstore when the server is disabled to prevent serving blocks to other peers.OnlineExchange
function to return a no-op exchange when Bitswap is disabled.noopExchange
struct to handle cases where Bitswap is disabled, ensuring no blocks are served or retrieved.Testing:
test/cli/bitswap_config_test.go
with multiple test cases to verify the behavior of Bitswap configuration, including scenarios where the server is enabled, disabled, or Bitswap is completely disabled.Closes #10717