fix(p2p): disable browser pure P2P by default

New browser sessions use IPFS gateway mode unless the user explicitly enables pure P2P in advanced settings.
This commit is contained in:
Tommaso Casaburi
2026-06-18 18:53:33 +07:00
parent 9896c4400b
commit 1c140035b4
5 changed files with 37 additions and 20 deletions
@@ -204,15 +204,15 @@ describe('AdvancedSettings', () => {
expect(textInputs[2]?.value).toBe('/tmp/connected-node');
});
it('shows pure p2p browser mode checked by default', async () => {
it('shows pure p2p browser mode unchecked by default', async () => {
await renderSettings(false);
expect(container.textContent).not.toContain('advanced_ipfs_gateways');
expect(container.textContent).not.toContain('advanced_pubsub_providers');
expect(container.textContent).toContain('advanced_ipfs_gateways');
expect(container.textContent).toContain('advanced_pubsub_providers');
expect(container.textContent).toContain('advanced_http_routers');
expect(container.textContent).toContain('advanced_full_node_websocket_rpc');
const checkbox = container.querySelector<HTMLInputElement>('input[type="checkbox"]');
expect(checkbox?.checked).toBe(true);
expect(checkbox?.checked).toBe(false);
const nodeRpcInput = Array.from(container.querySelectorAll<HTMLInputElement>('input[type="text"]')).find(
(input) => input.placeholder === 'advanced_p2p_rpc_placeholder',
@@ -81,7 +81,26 @@ describe('useBrowserPureP2PAccountUpgrade', () => {
window.isElectron = false;
});
it('upgrades stale gateway browser accounts and reloads after saving', async () => {
it('does not upgrade stale gateway browser accounts when pure p2p is disabled by default', async () => {
testState.account = {
id: 'account-1',
name: 'Account 1',
pkcOptions: {
httpRoutersOptions: ['https://router.old.example'],
ipfsGatewayUrls: ['https://gateway.old.example'],
pubsubKuboRpcClientsOptions: ['https://pubsub.old.example/api/v0'],
},
};
testState.accounts = [testState.account];
await renderHook();
expect(testState.setAccountMock).not.toHaveBeenCalled();
expect(reloadMock).not.toHaveBeenCalled();
});
it('upgrades stale gateway browser accounts when pure p2p is enabled and reloads after saving', async () => {
localStorage.setItem('5chan:pure-p2p-browser-enabled', 'true');
testState.account = {
id: 'account-1',
name: 'Account 1',
+6 -9
View File
@@ -19,7 +19,7 @@ const createStorage = (values: Record<string, string | undefined> = {}) => ({
describe('p2p-browser-config', () => {
const defaultHttpRouters = ['https://peers.plebpubsub.xyz', 'https://routing.lol', 'https://peers.pleb.bot'];
it('configures browser PKC options for pure p2p by default', () => {
it('configures browser PKC options for gateway mode by default', () => {
const chainProviders = {
eth: { urls: ['https://eth.example'], chainId: 1 },
};
@@ -32,14 +32,11 @@ describe('p2p-browser-config', () => {
},
};
expect(shouldUsePureP2PBrowser(targetWindow)).toBe(true);
expect(configureP2PBrowserPkcOptions(targetWindow)).toBe(true);
expect(targetWindow.defaultPkcOptions).toMatchObject({
expect(shouldUsePureP2PBrowser(targetWindow)).toBe(false);
expect(configureP2PBrowserPkcOptions(targetWindow)).toBe(false);
expect(targetWindow.defaultPkcOptions).toEqual({
chainProviders,
httpRoutersOptions: defaultHttpRouters,
ipfsGatewayUrls: undefined,
libp2pJsClientsOptions: [{ key: 'libp2pjs' }],
pubsubKuboRpcClientsOptions: undefined,
...getBrowserGatewayPkcOptions(),
});
});
@@ -105,7 +102,7 @@ describe('p2p-browser-config', () => {
};
expect(getPureP2PBrowserPreference(targetWindow)).toBeUndefined();
expect(shouldUsePureP2PBrowser(targetWindow)).toBe(true);
expect(shouldUsePureP2PBrowser(targetWindow)).toBe(false);
setPureP2PBrowserPreference(false, targetWindow);
expect(getPureP2PBrowserPreference(targetWindow)).toBe(false);
+6 -5
View File
@@ -67,10 +67,10 @@ describe('p2p-runtime', () => {
expect(getP2PRuntimeMode(account, browserWindow)).toBe('full-node-rpc');
});
it('keeps browser pure p2p on by default while allowing gateway mode when configured', () => {
expect(shouldShowP2PSettingsSection(undefined, browserWindow)).toBe(true);
expect(shouldShowP2PSettingsSection({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(true);
expect(isBrowserPureP2PEnabled({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(true);
it('keeps browser pure p2p off by default while honoring explicit preference and active libp2p accounts', () => {
expect(shouldShowP2PSettingsSection(undefined, browserWindow)).toBe(false);
expect(shouldShowP2PSettingsSection({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(false);
expect(isBrowserPureP2PEnabled({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindow)).toBe(false);
expect(shouldShowP2PSettingsSection({ pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }] } }, browserWindow)).toBe(true);
expect(isBrowserPureP2PEnabled({ pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }] } }, browserWindow)).toBe(true);
expect(shouldShowP2PSettingsSection({ pkcOptions: { ipfsGatewayUrls: ['https://gateway.example'] } }, browserWindowWithEnabledPureP2P)).toBe(true);
@@ -98,7 +98,8 @@ describe('p2p-runtime', () => {
const mixedBrowserAccount = { pkcOptions: { libp2pJsClientsOptions: [{ key: 'libp2pjs' }], pubsubKuboRpcClientsOptions: ['https://pubsub.example/api/v0'] } };
const fullNodeAccount = { pkcOptions: { pkcRpcClientsOptions: ['ws://node.example'] } };
expect(shouldUpgradeBrowserPureP2PAccount(gatewayAccount, browserWindow)).toBe(true);
expect(shouldUpgradeBrowserPureP2PAccount(gatewayAccount, browserWindow)).toBe(false);
expect(shouldUpgradeBrowserPureP2PAccount(gatewayAccount, browserWindowWithEnabledPureP2P)).toBe(true);
expect(shouldUpgradeBrowserPureP2PAccount(browserAccount, browserWindow)).toBe(false);
expect(shouldUpgradeBrowserPureP2PAccount(mixedBrowserAccount, browserWindow)).toBe(true);
expect(shouldUpgradeBrowserPureP2PAccount(fullNodeAccount, browserWindow)).toBe(false);
+1 -1
View File
@@ -1,5 +1,5 @@
export const PURE_P2P_BROWSER_SETTING_KEY = '5chan:pure-p2p-browser-enabled';
export const BROWSER_PURE_P2P_DEFAULT_ENABLED = true;
export const BROWSER_PURE_P2P_DEFAULT_ENABLED = false;
const BROWSER_PUBSUB_KUBO_RPC_CLIENTS_OPTIONS = ['https://pubsubprovider.xyz/api/v0', 'https://plebpubsub.xyz/api/v0', 'https://rannithepleb.com/api/v0'];