mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Don't store the entire node config in the httpd state
This should also fix the race condition, since we don't compare it for running the checkState fn
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import type { Node } from "@httpd-client";
|
||||
import type { HttpdNodeState } from "@app/lib/httpd";
|
||||
|
||||
import { capitalize } from "lodash";
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
import Popover from "@app/components/Popover.svelte";
|
||||
import ScopePolicyExplainer from "@app/components/ScopePolicyExplainer.svelte";
|
||||
|
||||
export let node: Node;
|
||||
export let node: HttpdNodeState;
|
||||
</script>
|
||||
|
||||
<style>
|
||||
@@ -46,23 +46,21 @@
|
||||
Your node is running and syncing with the network.
|
||||
</div>
|
||||
|
||||
{#if node.config?.scope && node.config?.policy}
|
||||
{#if node.scope && node.policy}
|
||||
<div class="scope-policy">
|
||||
<div style:display="flex">
|
||||
Seeding Policy: <span style:margin-left="auto" class="txt-semibold">
|
||||
{capitalize(node.config.policy)}
|
||||
{capitalize(node.policy)}
|
||||
</span>
|
||||
</div>
|
||||
<div style:display="flex" style:margin-bottom="1rem">
|
||||
Scope:
|
||||
<span style:margin-left="auto" class="txt-semibold">
|
||||
{capitalize(node.config.scope)}
|
||||
{capitalize(node.scope)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<ScopePolicyExplainer
|
||||
scope={node.config.scope}
|
||||
policy={node.config.policy} />
|
||||
<ScopePolicyExplainer scope={node.scope} policy={node.policy} />
|
||||
</div>
|
||||
{/if}
|
||||
<div class="label">
|
||||
|
||||
+29
-8
@@ -1,4 +1,4 @@
|
||||
import type { Node } from "@httpd-client";
|
||||
import type { Node, Policy, Scope } from "@httpd-client";
|
||||
|
||||
import { get, writable } from "svelte/store";
|
||||
import { withTimeout, Mutex, E_CANCELED, E_TIMEOUT } from "async-mutex";
|
||||
@@ -14,13 +14,23 @@ export interface Session {
|
||||
alias: string;
|
||||
}
|
||||
|
||||
export interface HttpdNodeState {
|
||||
id: Node["id"];
|
||||
state: Node["state"];
|
||||
policy: Policy | undefined;
|
||||
scope: Scope | undefined;
|
||||
}
|
||||
|
||||
export type HttpdState =
|
||||
| { state: "stopped" }
|
||||
| { state: "running"; node: Node }
|
||||
| {
|
||||
state: "running";
|
||||
node: HttpdNodeState;
|
||||
}
|
||||
| {
|
||||
state: "authenticated";
|
||||
session: Session;
|
||||
node: Node;
|
||||
node: HttpdNodeState;
|
||||
};
|
||||
|
||||
const HTTPD_STATE_STORAGE_KEY = "httpdState";
|
||||
@@ -61,7 +71,7 @@ export async function authenticate(params: {
|
||||
sig: params.signature,
|
||||
pk: params.publicKey,
|
||||
});
|
||||
const node = await api.getNode();
|
||||
const { id, state, config } = await api.getNode();
|
||||
const sess = await api.session.getById(params.id);
|
||||
update({
|
||||
state: "authenticated",
|
||||
@@ -70,7 +80,7 @@ export async function authenticate(params: {
|
||||
publicKey: params.publicKey,
|
||||
alias: sess.alias,
|
||||
},
|
||||
node,
|
||||
node: { id, state, policy: config?.policy, scope: config?.scope },
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
@@ -92,10 +102,15 @@ export async function disconnect() {
|
||||
|
||||
try {
|
||||
await api.session.delete(httpd.session.id);
|
||||
const node = await api.getNode();
|
||||
const { id, state, config } = await api.getNode();
|
||||
update({
|
||||
state: "running",
|
||||
node,
|
||||
node: {
|
||||
id,
|
||||
state,
|
||||
policy: config?.policy,
|
||||
scope: config?.scope,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@@ -127,7 +142,13 @@ async function checkState() {
|
||||
await stateMutex
|
||||
.runExclusive(async () => {
|
||||
try {
|
||||
const node = await api.getNode();
|
||||
const { id, state, config } = await api.getNode();
|
||||
const node = {
|
||||
id,
|
||||
state,
|
||||
policy: config?.policy,
|
||||
scope: config?.scope,
|
||||
};
|
||||
|
||||
// Return quickly and avoid additional fetches
|
||||
// if experimental settings aren't updated
|
||||
|
||||
Reference in New Issue
Block a user